void AMDGPUAsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
if (TM.getTargetTriple().getOS() != Triple::AMDHSA ||
- GV->isDeclaration() || AMDGPU::isReadOnlySegment(GV)) {
+ GV->isDeclaration()) {
AsmPrinter::EmitGlobalVariable(GV);
return;
}
DataGlobalAgentSection = AMDGPU::getHSADataGlobalAgentSection(Ctx);
DataGlobalProgramSection = AMDGPU::getHSADataGlobalProgramSection(Ctx);
+ RodataReadonlyAgentSection = AMDGPU::getHSARodataReadonlyAgentSection(Ctx);
}
bool AMDGPUHSATargetObjectFile::isAgentAllocationSection(
return DataGlobalProgramSection;
}
+ if (Kind.isReadOnly() && AMDGPU::isReadOnlySegment(GV))
+ return RodataReadonlyAgentSection;
+
return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, Mang, TM);
}
private:
MCSection *DataGlobalAgentSection;
MCSection *DataGlobalProgramSection;
+ MCSection *RodataReadonlyAgentSection;
bool isAgentAllocationSection(const char *SectionName) const;
bool isAgentAllocation(const GlobalValue *GV) const;
bool ParseDirectiveAMDGPUHsaProgramGlobal();
bool ParseSectionDirectiveHSADataGlobalAgent();
bool ParseSectionDirectiveHSADataGlobalProgram();
+ bool ParseSectionDirectiveHSARodataReadonlyAgent();
public:
public:
return false;
}
+bool AMDGPUAsmParser::ParseSectionDirectiveHSARodataReadonlyAgent() {
+ getParser().getStreamer().SwitchSection(
+ AMDGPU::getHSARodataReadonlyAgentSection(getContext()));
+ return false;
+}
+
bool AMDGPUAsmParser::ParseDirective(AsmToken DirectiveID) {
StringRef IDVal = DirectiveID.getString();
if (IDVal == ".hsadata_global_program")
return ParseSectionDirectiveHSADataGlobalProgram();
+ if (IDVal == ".hsarodata_readonly_agent")
+ return ParseSectionDirectiveHSARodataReadonlyAgent();
+
return true;
}
bool AMDGPUMCAsmInfo::shouldOmitSectionDirective(StringRef SectionName) const {
return SectionName == ".hsatext" || SectionName == ".hsadata_global_agent" ||
SectionName == ".hsadata_global_program" ||
+ SectionName == ".hsarodata_readonly_agent" ||
MCAsmInfo::shouldOmitSectionDirective(SectionName);
}
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;
}
MCSection *getHSADataGlobalProgramSection(MCContext &Ctx);
+MCSection *getHSARodataReadonlyAgentSection(MCContext &Ctx);
+
bool isGroupSegment(const GlobalValue *GV);
bool isGlobalSegment(const GlobalValue *GV);
bool isReadOnlySegment(const GlobalValue *GV);
@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
}
; 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)
; 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
; 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
; 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: }