forked from OSchip/llvm-project
AMDGPU/SI: Emit HSA kernels with symbol type STT_AMDGPU_HSA_KERNEL
Reviewers: arsenm Subscribers: arsenm, llvm-commits Differential Revision: http://reviews.llvm.org/D13804 llvm-svn: 252291
This commit is contained in:
parent
22b4164e7d
commit
1e1b05db24
|
@ -110,6 +110,19 @@ void AMDGPUAsmPrinter::EmitEndOfAsmFile(Module &M) {
|
|||
OutStreamer->EmitLabel(EndOfTextLabel);
|
||||
}
|
||||
|
||||
void AMDGPUAsmPrinter::EmitFunctionEntryLabel() {
|
||||
const SIMachineFunctionInfo *MFI = MF->getInfo<SIMachineFunctionInfo>();
|
||||
const AMDGPUSubtarget &STM = MF->getSubtarget<AMDGPUSubtarget>();
|
||||
if (MFI->isKernel() && STM.isAmdHsaOS()) {
|
||||
AMDGPUTargetStreamer *TS =
|
||||
static_cast<AMDGPUTargetStreamer *>(OutStreamer->getTargetStreamer());
|
||||
TS->EmitAMDGPUSymbolType(CurrentFnSym->getName(),
|
||||
ELF::STT_AMDGPU_HSA_KERNEL);
|
||||
}
|
||||
|
||||
AsmPrinter::EmitFunctionEntryLabel();
|
||||
}
|
||||
|
||||
bool AMDGPUAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
||||
|
||||
// The starting address of all shader programs must be 256 bytes aligned.
|
||||
|
|
|
@ -101,6 +101,8 @@ public:
|
|||
|
||||
void EmitEndOfAsmFile(Module &M) override;
|
||||
|
||||
void EmitFunctionEntryLabel() override;
|
||||
|
||||
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
|
||||
unsigned AsmVariant, const char *ExtraCode,
|
||||
raw_ostream &O) override;
|
||||
|
|
|
@ -37,6 +37,11 @@ public:
|
|||
return ShaderType;
|
||||
}
|
||||
|
||||
bool isKernel() const {
|
||||
// FIXME: Assume everything is a kernel until function calls are supported.
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned ScratchSize;
|
||||
bool IsKernel;
|
||||
};
|
||||
|
|
|
@ -28,7 +28,9 @@
|
|||
#include "llvm/MC/MCRegisterInfo.h"
|
||||
#include "llvm/MC/MCStreamer.h"
|
||||
#include "llvm/MC/MCSubtargetInfo.h"
|
||||
#include "llvm/MC/MCSymbolELF.h"
|
||||
#include "llvm/MC/MCTargetAsmParser.h"
|
||||
#include "llvm/Support/ELF.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
#include "llvm/Support/TargetRegistry.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
@ -355,6 +357,7 @@ private:
|
|||
bool ParseDirectiveAMDKernelCodeT();
|
||||
bool ParseSectionDirectiveHSAText();
|
||||
bool subtargetHasRegister(const MCRegisterInfo &MRI, unsigned RegNo) const;
|
||||
bool ParseDirectiveAMDGPUHsaKernel();
|
||||
|
||||
public:
|
||||
public:
|
||||
|
@ -942,6 +945,18 @@ bool AMDGPUAsmParser::ParseSectionDirectiveHSAText() {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool AMDGPUAsmParser::ParseDirectiveAMDGPUHsaKernel() {
|
||||
if (getLexer().isNot(AsmToken::Identifier))
|
||||
return TokError("expected symbol name");
|
||||
|
||||
StringRef KernelName = Parser.getTok().getString();
|
||||
|
||||
getTargetStreamer().EmitAMDGPUSymbolType(KernelName,
|
||||
ELF::STT_AMDGPU_HSA_KERNEL);
|
||||
Lex();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AMDGPUAsmParser::ParseDirective(AsmToken DirectiveID) {
|
||||
StringRef IDVal = DirectiveID.getString();
|
||||
|
||||
|
@ -957,6 +972,9 @@ bool AMDGPUAsmParser::ParseDirective(AsmToken DirectiveID) {
|
|||
if (IDVal == ".hsatext" || IDVal == ".text")
|
||||
return ParseSectionDirectiveHSAText();
|
||||
|
||||
if (IDVal == ".amdgpu_hsa_kernel")
|
||||
return ParseDirectiveAMDGPUHsaKernel();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -221,6 +221,16 @@ AMDGPUTargetAsmStreamer::EmitAMDKernelCodeT(const amd_kernel_code_t &Header) {
|
|||
|
||||
}
|
||||
|
||||
void AMDGPUTargetAsmStreamer::EmitAMDGPUSymbolType(StringRef SymbolName,
|
||||
unsigned Type) {
|
||||
switch (Type) {
|
||||
default: llvm_unreachable("Invalid AMDGPU symbol type");
|
||||
case ELF::STT_AMDGPU_HSA_KERNEL:
|
||||
OS << "\t.amdgpu_hsa_kernel " << SymbolName << '\n' ;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// AMDGPUTargetELFStreamer
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@ -299,3 +309,10 @@ AMDGPUTargetELFStreamer::EmitAMDKernelCodeT(const amd_kernel_code_t &Header) {
|
|||
OS.EmitBytes(StringRef((const char*)&Header, sizeof(Header)));
|
||||
OS.PopSection();
|
||||
}
|
||||
|
||||
void AMDGPUTargetELFStreamer::EmitAMDGPUSymbolType(StringRef SymbolName,
|
||||
unsigned Type) {
|
||||
MCSymbolELF *Symbol = cast<MCSymbolELF>(
|
||||
getStreamer().getContext().getOrCreateSymbol(SymbolName));
|
||||
Symbol->setType(ELF::STT_AMDGPU_HSA_KERNEL);
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@ public:
|
|||
StringRef ArchName) = 0;
|
||||
|
||||
virtual void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) = 0;
|
||||
|
||||
virtual void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) = 0;
|
||||
};
|
||||
|
||||
class AMDGPUTargetAsmStreamer : public AMDGPUTargetStreamer {
|
||||
|
@ -44,6 +46,8 @@ public:
|
|||
StringRef ArchName) override;
|
||||
|
||||
void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override;
|
||||
|
||||
void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
|
||||
};
|
||||
|
||||
class AMDGPUTargetELFStreamer : public AMDGPUTargetStreamer {
|
||||
|
@ -75,6 +79,7 @@ public:
|
|||
|
||||
void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override;
|
||||
|
||||
void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
; RUN: llc < %s -mtriple=amdgcn--amdhsa -mcpu=kaveri | FileCheck --check-prefix=HSA-CI --check-prefix=HSA %s
|
||||
; RUN: llc < %s -mtriple=amdgcn--amdhsa -mcpu=carrizo | FileCheck --check-prefix=HSA-VI --check-prefix=HSA %s
|
||||
; RUN: llc < %s -mtriple=amdgcn--amdhsa -mcpu=kaveri -filetype=obj | llvm-readobj -s -sd | FileCheck --check-prefix=ELF %s
|
||||
; RUN: llc < %s -mtriple=amdgcn--amdhsa -mcpu=kaveri | llvm-mc -filetype=obj -triple amdgcn--amdhsa -mcpu=kaveri | llvm-readobj -s -sd | FileCheck %s --check-prefix=ELF
|
||||
; RUN: llc < %s -mtriple=amdgcn--amdhsa -mcpu=kaveri -filetype=obj | llvm-readobj -symbols -s -sd | FileCheck --check-prefix=ELF %s
|
||||
; RUN: llc < %s -mtriple=amdgcn--amdhsa -mcpu=kaveri | llvm-mc -filetype=obj -triple amdgcn--amdhsa -mcpu=kaveri | llvm-readobj -symbols -s -sd | FileCheck %s --check-prefix=ELF
|
||||
|
||||
; The SHT_NOTE section contains the output from the .hsa_code_object_*
|
||||
; directives.
|
||||
|
@ -24,12 +24,18 @@
|
|||
; ELF: 0030: 00000000 00000000 414D4400 414D4447
|
||||
; ELF: 0040: 50550000
|
||||
|
||||
; ELF: Symbol {
|
||||
; ELF: Name: simple
|
||||
; ELF: Type: AMDGPU_HSA_KERNEL (0xA)
|
||||
; ELF: }
|
||||
|
||||
; HSA: .hsa_code_object_version 1,0
|
||||
; HSA-CI: .hsa_code_object_isa 7,0,0,"AMD","AMDGPU"
|
||||
; HSA-VI: .hsa_code_object_isa 8,0,1,"AMD","AMDGPU"
|
||||
|
||||
; HSA: .hsatext
|
||||
|
||||
; HSA: .amdgpu_hsa_kernel simple
|
||||
; HSA: {{^}}simple:
|
||||
; HSA: .amd_kernel_code_t
|
||||
; HSA: .end_amd_kernel_code_t
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// RUN: llvm-mc -triple amdgcn--amdhsa -mcpu=kaveri -show-encoding %s | FileCheck %s --check-prefix=ASM
|
||||
// RUN: llvm-mc -filetype=obj -triple amdgcn--amdhsa -mcpu=kaveri -show-encoding %s | llvm-readobj -s -sd | FileCheck %s --check-prefix=ELF
|
||||
// RUN: llvm-mc -filetype=obj -triple amdgcn--amdhsa -mcpu=kaveri -show-encoding %s | llvm-readobj -symbols -s -sd | FileCheck %s --check-prefix=ELF
|
||||
|
||||
// ELF: Section {
|
||||
// ELF: Name: .hsatext
|
||||
|
@ -10,7 +10,6 @@
|
|||
// ELF: SHF_AMDGPU_HSA_CODE (0x400000)
|
||||
// ELF: SHF_EXECINSTR (0x4)
|
||||
// ELF: SHF_WRITE (0x1)
|
||||
// ELF: }
|
||||
|
||||
// ELF: SHT_NOTE
|
||||
// ELF: 0000: 04000000 08000000 01000000 414D4400
|
||||
|
@ -19,12 +18,27 @@
|
|||
// ELF: 0030: 00000000 00000000 414D4400 414D4447
|
||||
// ELF: 0040: 50550000
|
||||
|
||||
// ELF: Symbol {
|
||||
// ELF: Name: amd_kernel_code_t_minimal
|
||||
// ELF: Type: AMDGPU_HSA_KERNEL (0xA)
|
||||
// ELF: Section: .hsatext
|
||||
// ELF: }
|
||||
// ELF: Symbol {
|
||||
// ELF: Name: amd_kernel_code_t_test_all
|
||||
// ELF: Type: AMDGPU_HSA_KERNEL (0xA)
|
||||
// ELF: Section: .hsatext
|
||||
// ELF: }
|
||||
|
||||
|
||||
.hsa_code_object_version 1,0
|
||||
// ASM: .hsa_code_object_version 1,0
|
||||
|
||||
.hsa_code_object_isa 7,0,0,"AMD","AMDGPU"
|
||||
// ASM: .hsa_code_object_isa 7,0,0,"AMD","AMDGPU"
|
||||
|
||||
.amdgpu_hsa_kernel amd_kernel_code_t_test_all
|
||||
.amdgpu_hsa_kernel amd_kernel_code_t_minimal
|
||||
|
||||
.hsatext
|
||||
// ASM: .hsatext
|
||||
|
||||
|
|
Loading…
Reference in New Issue