Index: lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp =================================================================== --- lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp +++ lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp @@ -138,7 +138,7 @@ const Module *M = GV->getParent(); if (TM.getTargetTriple().getOS() != Triple::AMDHSA || - GV->isDeclaration() || AMDGPU::isReadOnlySegment(GV)) { + GV->isDeclaration()) { AsmPrinter::EmitGlobalVariable(GV); return; } Index: lib/Target/AMDGPU/AMDGPUHSATargetObjectFile.h =================================================================== --- lib/Target/AMDGPU/AMDGPUHSATargetObjectFile.h +++ lib/Target/AMDGPU/AMDGPUHSATargetObjectFile.h @@ -25,6 +25,7 @@ private: MCSection *DataGlobalAgentSection; MCSection *DataGlobalProgramSection; + MCSection *RodataReadonlyAgentSection; bool isAgentAllocationSection(const char *SectionName) const; bool isAgentAllocation(const GlobalValue *GV) const; Index: lib/Target/AMDGPU/AMDGPUHSATargetObjectFile.cpp =================================================================== --- lib/Target/AMDGPU/AMDGPUHSATargetObjectFile.cpp +++ lib/Target/AMDGPU/AMDGPUHSATargetObjectFile.cpp @@ -26,6 +26,7 @@ DataGlobalAgentSection = AMDGPU::getHSADataGlobalAgentSection(Ctx); DataGlobalProgramSection = AMDGPU::getHSADataGlobalProgramSection(Ctx); + RodataReadonlyAgentSection = AMDGPU::getHSARodataReadonlyAgentSection(Ctx); } bool AMDGPUHSATargetObjectFile::isAgentAllocationSection( @@ -63,5 +64,8 @@ return DataGlobalProgramSection; } + if (Kind.isReadOnly() && AMDGPU::isReadOnlySegment(GV)) + return RodataReadonlyAgentSection; + return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, Mang, TM); } Index: lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp =================================================================== --- lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp +++ lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp @@ -362,6 +362,7 @@ bool ParseDirectiveAMDGPUHsaProgramGlobal(); bool ParseSectionDirectiveHSADataGlobalAgent(); bool ParseSectionDirectiveHSADataGlobalProgram(); + bool ParseSectionDirectiveHSARodataReadonlyAgent(); public: public: @@ -995,6 +996,12 @@ return false; } +bool AMDGPUAsmParser::ParseSectionDirectiveHSARodataReadonlyAgent() { + getParser().getStreamer().SwitchSection( + AMDGPU::getHSARodataReadonlyAgentSection(getContext())); + return false; +} + bool AMDGPUAsmParser::ParseDirective(AsmToken DirectiveID) { StringRef IDVal = DirectiveID.getString(); @@ -1025,6 +1032,9 @@ if (IDVal == ".hsadata_global_program") return ParseSectionDirectiveHSADataGlobalProgram(); + if (IDVal == ".hsarodata_readonly_agent") + return ParseSectionDirectiveHSARodataReadonlyAgent(); + return true; } Index: lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCAsmInfo.cpp =================================================================== --- lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCAsmInfo.cpp +++ lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCAsmInfo.cpp @@ -38,5 +38,6 @@ bool AMDGPUMCAsmInfo::shouldOmitSectionDirective(StringRef SectionName) const { return SectionName == ".hsatext" || SectionName == ".hsadata_global_agent" || SectionName == ".hsadata_global_program" || + SectionName == ".hsarodata_readonly_agent" || MCAsmInfo::shouldOmitSectionDirective(SectionName); } Index: lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h =================================================================== --- lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h +++ lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h @@ -36,6 +36,8 @@ MCSection *getHSADataGlobalProgramSection(MCContext &Ctx); +MCSection *getHSARodataReadonlyAgentSection(MCContext &Ctx); + bool isGroupSegment(const GlobalValue *GV); bool isGlobalSegment(const GlobalValue *GV); bool isReadOnlySegment(const GlobalValue *GV); Index: lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp =================================================================== --- lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp +++ lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp @@ -81,6 +81,12 @@ 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; } Index: test/CodeGen/AMDGPU/hsa-globals.ll =================================================================== --- test/CodeGen/AMDGPU/hsa-globals.ll +++ test/CodeGen/AMDGPU/hsa-globals.ll @@ -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 @@ ; 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 @@ ; 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 @@ -91,6 +113,13 @@ ; 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 @@ -103,3 +132,10 @@ ; 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: }