Index: lib/Target/AMDGPU/AMDGPUHSATargetObjectFile.h =================================================================== --- lib/Target/AMDGPU/AMDGPUHSATargetObjectFile.h +++ lib/Target/AMDGPU/AMDGPUHSATargetObjectFile.h @@ -24,6 +24,7 @@ class AMDGPUHSATargetObjectFile final : public TargetLoweringObjectFileELF { private: MCSection *DataGlobalAgentSection; + MCSection *RodataReadonlyAgentSection; public: void Initialize(MCContext &Ctx, const TargetMachine &TM) override; Index: lib/Target/AMDGPU/AMDGPUHSATargetObjectFile.cpp =================================================================== --- lib/Target/AMDGPU/AMDGPUHSATargetObjectFile.cpp +++ lib/Target/AMDGPU/AMDGPUHSATargetObjectFile.cpp @@ -23,6 +23,12 @@ TextSection = AMDGPU::getHSATextSection(Ctx); DataGlobalAgentSection = AMDGPU::getHSADataGlobalAgentSection(Ctx); + + RodataReadonlyAgentSection = Ctx.getELFSection(".hsarodata_readonly_agent", + ELF::SHT_PROGBITS, + ELF::SHF_ALLOC | + ELF::SHF_AMDGPU_HSA_READONLY | + ELF::SHF_AMDGPU_HSA_AGENT); } @@ -38,6 +44,9 @@ if (Kind.isText() && !GV->hasComdat()) return getTextSection(); + if (Kind.isReadOnly() && isModuleLinkage(GV)) + return RodataReadonlyAgentSection; + // isCommon means globally writeable with a zero initializer. if (isModuleLinkage(GV)) return DataGlobalAgentSection; Index: test/CodeGen/AMDGPU/hsa-globals.ll =================================================================== --- /dev/null +++ test/CodeGen/AMDGPU/hsa-globals.ll @@ -0,0 +1,39 @@ +; 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 -symbols -s -sd | FileCheck --check-prefix=ELF %s + +; FIXME: Add assembler support for globals +; FIXME-XUN: 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 + +@const_array = internal unnamed_addr addrspace(2) constant [64 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789<>", align 1 + +; 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: const_array +; ELF: Binding: Local (0x0) +; ELF: Type: Object (0x1) +; ELF: Section: .hsarodata_readonly_agent (0x6) +; ELF: } + +; HSA: .amdgpu_hsa_module_global const_array +; HSA: .hsarodata_readonly_agent +; HSA: const_array: +; HSA: .ascii "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789<>" + + +define void @test(i8 addrspace(1) *%out, i32 %offset) { +entry: + %ptr = getelementptr [64 x i8], [64 x i8] addrspace(2)* @const_array, i32 0, i32 %offset +; %0 = getelementptr inbounds [2 x i32], [2 x i32] addrspace(3)* @local_mem, i32 0, i32 %index + %val = load i8, i8 addrspace(2)* %ptr + store i8 %val, i8 addrspace(1)* %out + ret void +}