AMDGPU/SI: Emit constant arrays in the .hsrodata_readonly_agent section
authorTom Stellard <thomas.stellard@amd.com>
Thu, 3 Dec 2015 03:34:32 +0000 (03:34 +0000)
committerTom Stellard <thomas.stellard@amd.com>
Thu, 3 Dec 2015 03:34:32 +0000 (03:34 +0000)
Summary: This is done only when targeting HSA.

Reviewers: arsenm

Subscribers: arsenm, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254587 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
lib/Target/AMDGPU/AMDGPUHSATargetObjectFile.cpp
lib/Target/AMDGPU/AMDGPUHSATargetObjectFile.h
lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCAsmInfo.cpp
lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
test/CodeGen/AMDGPU/hsa-globals.ll

index 1c438b24e6a4f0d6bedffb10001397afa8628028..b677caa6c2c6c8c33a6f5751a5345723e4f3381d 100644 (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;
   }
index ee42eaacf546fb4e087994f59fdcc6d02ad6a804..32f53edeb770b7cc9de8a6a0e3fd1fc9ae622de3 100644 (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);
 }
index 3697a96ffaf2dd84df3cde859a01ae07d8b54327..9ea51ec9b29ee0e386e0e41f1740b1c0793307e3 100644 (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;
index b360f2de0cb388edc4d2c79a34f491e37c0adcae..7359cfee7f277443a0612006f679ca37e08339b3 100644 (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;
 }
 
index 89fa212de9560dbb13675a6f0413daa77006e3a0..68b1d1ae83cc7ae29119bd67a856d353784c0a68 100644 (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);
 }
index e3c93384bd8ee9fb4d392a8fa1de65ba3f5c4a2a..441baed9b4342e9715ee52b288b65e2795bcc57b 100644 (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;
 }
index cc70064dbc0f632dcf621bb543a38c76c2972eed..7b3c858e7c3630dd4a032d91c6fba91575daa3ec 100644 (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);
index c73ca3b0079a3c40ba79296aa3b0765c8da96681..b6483f0970b0097cf11f1260d4aa08d7d246616c 100644 (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: }