Skip to content

Commit b5b34db

Browse files
authored
[AMDGPU] Use directive for kernarg preload header padding (#86004)
1 parent 0234d90 commit b5b34db

File tree

3 files changed

+325
-8757
lines changed

3 files changed

+325
-8757
lines changed

llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,15 @@ bool AMDGPUTargetAsmStreamer::EmitHSAMetadata(
284284
return true;
285285
}
286286

287+
bool AMDGPUTargetAsmStreamer::EmitKernargPreloadHeader(
288+
const MCSubtargetInfo &STI, bool TrapEnabled) {
289+
OS << (TrapEnabled ? "\ts_trap 2" : "\ts_endpgm")
290+
<< " ; Kernarg preload header. Trap with incompatible firmware that "
291+
"doesn't support preloading kernel arguments.\n";
292+
OS << "\t.fill 63, 4, 0xbf800000 ; s_nop 0\n";
293+
return true;
294+
}
295+
287296
bool AMDGPUTargetAsmStreamer::EmitCodeEnd(const MCSubtargetInfo &STI) {
288297
const uint32_t Encoded_s_code_end = 0xbf9f0000;
289298
const uint32_t Encoded_s_nop = 0xbf800000;
@@ -861,18 +870,6 @@ bool AMDGPUTargetELFStreamer::EmitHSAMetadata(msgpack::Document &HSAMetadataDoc,
861870
return true;
862871
}
863872

864-
bool AMDGPUTargetAsmStreamer::EmitKernargPreloadHeader(
865-
const MCSubtargetInfo &STI, bool TrapEnabled) {
866-
const char *TrapInstr = TrapEnabled ? "\ts_trap 2" : "\ts_endpgm";
867-
OS << TrapInstr
868-
<< " ; Trap with incompatible firmware that doesn't "
869-
"support preloading kernel arguments.\n";
870-
for (int i = 0; i < 63; ++i) {
871-
OS << "\ts_nop 0\n";
872-
}
873-
return true;
874-
}
875-
876873
bool AMDGPUTargetELFStreamer::EmitKernargPreloadHeader(
877874
const MCSubtargetInfo &STI, bool TrapEnabled) {
878875
const uint32_t Encoded_s_nop = 0xbf800000;

llvm/test/CodeGen/AMDGPU/preload-kernarg-header.ll

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx940 -amdgpu-kernarg-preload-count=1 -asm-verbose=0 < %s | FileCheck -check-prefixes=GCN,HSA %s
2-
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx940 -amdgpu-kernarg-preload-count=1 -filetype=obj < %s | llvm-objdump --arch=amdgcn --mcpu=gfx940 --disassemble - | FileCheck -check-prefixes=GCN,HSA %s
3-
; RUN: llc -mtriple=amdgcn -mcpu=gfx940 -amdgpu-kernarg-preload-count=1 -filetype=obj < %s | llvm-objdump --arch=amdgcn --mcpu=gfx940 --disassemble - | FileCheck -check-prefixes=GCN,NON-HSA %s
1+
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx940 -amdgpu-kernarg-preload-count=1 -asm-verbose=0 < %s | FileCheck -check-prefixes=GCN,HSA,ASM %s
2+
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx940 -amdgpu-kernarg-preload-count=1 -filetype=obj < %s | llvm-objdump --arch=amdgcn --mcpu=gfx940 --disassemble - | FileCheck -check-prefixes=GCN,HSA,OBJ %s
3+
; RUN: llc -mtriple=amdgcn -mcpu=gfx940 -amdgpu-kernarg-preload-count=1 -filetype=obj < %s | llvm-objdump --arch=amdgcn --mcpu=gfx940 --disassemble - | FileCheck -check-prefixes=GCN,NON-HSA,OBJ %s
4+
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx940 -amdgpu-kernarg-preload-count=1 -asm-verbose=0 < %s | llvm-mc -triple amdgcn-amd-amdhsa -mcpu=gfx940 -filetype=obj | llvm-objdump --arch=amdgcn --mcpu=gfx940 --disassemble - | FileCheck -check-prefixes=GCN,HSA,OBJ %s
45

56
; GCN: preload_kernarg_header
67
; HSA: s_trap 2
78
; NON-HSA: s_endpgm
8-
; GCN-COUNT-63: s_nop 0
9+
; ASM: .fill 63, 4, 0xbf800000 ; s_nop 0
10+
; OBJ-COUNT-63: s_nop 0
911
define amdgpu_kernel void @preload_kernarg_header(ptr %arg) {
1012
store ptr %arg, ptr %arg
1113
ret void
1214
}
1315

1416
; GCN: non_kernel_function
17+
; GCN-NOT: s_trap 2
1518
; GCN-NOT: s_nop 0
1619
; GCN: flat_store
1720
define void @non_kernel_function(ptr %arg) {

0 commit comments

Comments
 (0)