1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00

AMDGPU/SI: Emit constant arrays in the .hsrodata_readonly_agent section

Summary: This is done only when targeting HSA.

Reviewers: arsenm

Subscribers: arsenm, llvm-commits

Differential Revision: http://reviews.llvm.org/D13807

llvm-svn: 254587
This commit is contained in:
Tom Stellard 2015-12-03 03:34:32 +00:00
parent 809ea1300c
commit 6db0d97887
8 changed files with 61 additions and 1 deletions

View File

@ -137,7 +137,7 @@ static bool isModuleLinkage(const GlobalValue *GV) {
void AMDGPUAsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
if (TM.getTargetTriple().getOS() != Triple::AMDHSA ||
GV->isDeclaration() || AMDGPU::isReadOnlySegment(GV)) {
GV->isDeclaration()) {
AsmPrinter::EmitGlobalVariable(GV);
return;
}

View File

@ -26,6 +26,7 @@ void AMDGPUHSATargetObjectFile::Initialize(MCContext &Ctx,
DataGlobalAgentSection = AMDGPU::getHSADataGlobalAgentSection(Ctx);
DataGlobalProgramSection = AMDGPU::getHSADataGlobalProgramSection(Ctx);
RodataReadonlyAgentSection = AMDGPU::getHSARodataReadonlyAgentSection(Ctx);
}
bool AMDGPUHSATargetObjectFile::isAgentAllocationSection(
@ -63,5 +64,8 @@ MCSection *AMDGPUHSATargetObjectFile::SelectSectionForGlobal(
return DataGlobalProgramSection;
}
if (Kind.isReadOnly() && AMDGPU::isReadOnlySegment(GV))
return RodataReadonlyAgentSection;
return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, Mang, TM);
}

View File

@ -25,6 +25,7 @@ class AMDGPUHSATargetObjectFile final : public TargetLoweringObjectFileELF {
private:
MCSection *DataGlobalAgentSection;
MCSection *DataGlobalProgramSection;
MCSection *RodataReadonlyAgentSection;
bool isAgentAllocationSection(const char *SectionName) const;
bool isAgentAllocation(const GlobalValue *GV) const;

View File

@ -369,6 +369,7 @@ private:
bool ParseDirectiveAMDGPUHsaProgramGlobal();
bool ParseSectionDirectiveHSADataGlobalAgent();
bool ParseSectionDirectiveHSADataGlobalProgram();
bool ParseSectionDirectiveHSARodataReadonlyAgent();
public:
public:
@ -1004,6 +1005,12 @@ bool AMDGPUAsmParser::ParseSectionDirectiveHSADataGlobalProgram() {
return false;
}
bool AMDGPUAsmParser::ParseSectionDirectiveHSARodataReadonlyAgent() {
getParser().getStreamer().SwitchSection(
AMDGPU::getHSARodataReadonlyAgentSection(getContext()));
return false;
}
bool AMDGPUAsmParser::ParseDirective(AsmToken DirectiveID) {
StringRef IDVal = DirectiveID.getString();
@ -1034,6 +1041,9 @@ bool AMDGPUAsmParser::ParseDirective(AsmToken DirectiveID) {
if (IDVal == ".hsadata_global_program")
return ParseSectionDirectiveHSADataGlobalProgram();
if (IDVal == ".hsarodata_readonly_agent")
return ParseSectionDirectiveHSARodataReadonlyAgent();
return true;
}

View File

@ -38,5 +38,6 @@ AMDGPUMCAsmInfo::AMDGPUMCAsmInfo(const Triple &TT) : MCAsmInfoELF() {
bool AMDGPUMCAsmInfo::shouldOmitSectionDirective(StringRef SectionName) const {
return SectionName == ".hsatext" || SectionName == ".hsadata_global_agent" ||
SectionName == ".hsadata_global_program" ||
SectionName == ".hsarodata_readonly_agent" ||
MCAsmInfo::shouldOmitSectionDirective(SectionName);
}

View File

@ -81,6 +81,12 @@ MCSection *getHSADataGlobalProgramSection(MCContext &Ctx) {
ELF::SHF_AMDGPU_HSA_GLOBAL);
}
MCSection *getHSARodataReadonlyAgentSection(MCContext &Ctx) {
return Ctx.getELFSection(".hsarodata_readonly_agent", ELF::SHT_PROGBITS,
ELF::SHF_ALLOC | ELF::SHF_AMDGPU_HSA_READONLY |
ELF::SHF_AMDGPU_HSA_AGENT);
}
bool isGroupSegment(const GlobalValue *GV) {
return GV->getType()->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
}

View File

@ -36,6 +36,8 @@ MCSection *getHSADataGlobalAgentSection(MCContext &Ctx);
MCSection *getHSADataGlobalProgramSection(MCContext &Ctx);
MCSection *getHSARodataReadonlyAgentSection(MCContext &Ctx);
bool isGroupSegment(const GlobalValue *GV);
bool isGlobalSegment(const GlobalValue *GV);
bool isReadOnlySegment(const GlobalValue *GV);

View File

@ -9,6 +9,9 @@
@common_global_agent = common addrspace(1) global i32 0, section ".hsadata_global_agent"
@external_global_agent = addrspace(1) global i32 0, section ".hsadata_global_agent"
@internal_readonly = internal unnamed_addr addrspace(2) constant i32 0
@external_readonly = unnamed_addr addrspace(2) constant i32 0
define void @test() {
ret void
}
@ -43,6 +46,16 @@ define void @test() {
; ASM: external_global_agent:
; ASM: .long 0
; ASM: .amdgpu_hsa_module_global internal_readonly
; ASM: .hsarodata_readonly_agent
; ASM: internal_readonly:
; ASM: .long 0
; ASM: .amdgpu_hsa_program_global external_readonly
; ASM: .hsarodata_readonly_agent
; ASM: external_readonly:
; ASM: .long 0
; ELF: Section {
; ELF: Name: .hsadata_global_program
; ELF: Type: SHT_PROGBITS (0x1)
@ -64,6 +77,15 @@ define void @test() {
; ELF: ]
; ELF: }
; ELF: Section {
; ELF: Name: .hsarodata_readonly_agent
; ELF: Type: SHT_PROGBITS (0x1)
; ELF: Flags [ (0xA00002)
; ELF: SHF_ALLOC (0x2)
; ELF: SHF_AMDGPU_HSA_AGENT (0x800000)
; ELF: SHF_AMDGPU_HSA_READONLY (0x200000)
; ELF: ]
; ELF: Symbol {
; ELF: Name: common_global_agent
; ELF: Binding: Local
@ -90,6 +112,13 @@ define void @test() {
; ELF: Section: .hsadata_global_program
; ELF: }
; ELF: Symbol {
; ELF: Name: internal_readonly
; ELF: Binding: Local
; ELF: Type: Object
; ELF: Section: .hsarodata_readonly_agent
; ELF: }
; ELF: Symbol {
; ELF: Name: external_global_agent
; ELF: Binding: Global
@ -103,3 +132,10 @@ define void @test() {
; ELF: Type: Object
; ELF: Section: .hsadata_global_program
; ELF: }
; ELF: Symbol {
; ELF: Name: external_readonly
; ELF: Binding: Global
; ELF: Type: Object
; ELF: Section: .hsarodata_readonly_agent
; ELF: }