Skip to content

Commit e076ecc

Browse files
committed
[AMDGPU] Use directive for kernarg preload header padding
1 parent 1d296ec commit e076ecc

File tree

3 files changed

+326
-8757
lines changed

3 files changed

+326
-8757
lines changed

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,16 @@ bool AMDGPUTargetAsmStreamer::EmitHSAMetadata(
283283
return true;
284284
}
285285

286+
bool AMDGPUTargetAsmStreamer::EmitKernargPreloadHeader(
287+
const MCSubtargetInfo &STI, bool TrapEnabled) {
288+
const char *TrapInstr = TrapEnabled ? "\ts_trap 2" : "\ts_endpgm";
289+
OS << TrapInstr
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+
286296
bool AMDGPUTargetAsmStreamer::EmitCodeEnd(const MCSubtargetInfo &STI) {
287297
const uint32_t Encoded_s_code_end = 0xbf9f0000;
288298
const uint32_t Encoded_s_nop = 0xbf800000;
@@ -781,18 +791,6 @@ bool AMDGPUTargetELFStreamer::EmitHSAMetadata(msgpack::Document &HSAMetadataDoc,
781791
return true;
782792
}
783793

784-
bool AMDGPUTargetAsmStreamer::EmitKernargPreloadHeader(
785-
const MCSubtargetInfo &STI, bool TrapEnabled) {
786-
const char *TrapInstr = TrapEnabled ? "\ts_trap 2" : "\ts_endpgm";
787-
OS << TrapInstr
788-
<< " ; Trap with incompatible firmware that doesn't "
789-
"support preloading kernel arguments.\n";
790-
for (int i = 0; i < 63; ++i) {
791-
OS << "\ts_nop 0\n";
792-
}
793-
return true;
794-
}
795-
796794
bool AMDGPUTargetELFStreamer::EmitKernargPreloadHeader(
797795
const MCSubtargetInfo &STI, bool TrapEnabled) {
798796
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)