From: Tom Stellard Date: Fri, 8 Jan 2016 14:50:28 +0000 (+0000) Subject: AMDGPU/SI: Emit global variable sizes when targeting HSA X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=d7ef3dae862793fd92c9eadb587bc108ac122d56;p=oota-llvm.git AMDGPU/SI: Emit global variable sizes when targeting HSA Reviewers: arsenm Subscribers: arsenm, llvm-commits Differential Revision: http://reviews.llvm.org/D15952 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257173 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp b/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp index 9844fc67199..89e7c1bd180 100644 --- a/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp +++ b/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp @@ -148,11 +148,15 @@ void AMDGPUAsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) { TS->EmitAMDGPUHsaProgramScopeGlobal(GV->getName()); } + MCSymbolELF *GVSym = cast(getSymbol(GV)); const DataLayout &DL = getDataLayout(); + + // Emit the size + uint64_t Size = DL.getTypeAllocSize(GV->getType()->getElementType()); + OutStreamer->emitELFSize(GVSym, MCConstantExpr::create(Size, OutContext)); OutStreamer->PushSection(); OutStreamer->SwitchSection( getObjFileLowering().SectionForGlobal(GV, *Mang, TM)); - MCSymbol *GVSym = getSymbol(GV); const Constant *C = GV->getInitializer(); OutStreamer->EmitLabel(GVSym); EmitGlobalConstant(DL, C); diff --git a/test/CodeGen/AMDGPU/hsa-globals.ll b/test/CodeGen/AMDGPU/hsa-globals.ll index 1d76c40c042..90322ac3dc0 100644 --- a/test/CodeGen/AMDGPU/hsa-globals.ll +++ b/test/CodeGen/AMDGPU/hsa-globals.ll @@ -17,41 +17,49 @@ define void @test() { } ; ASM: .amdgpu_hsa_module_global internal_global +; ASM: .size internal_global_program, 4 ; ASM: .hsadata_global_program ; ASM: internal_global_program: ; ASM: .long 0 ; ASM: .amdgpu_hsa_module_global common_global +; ASM: .size common_global_program, 4 ; ASM: .hsadata_global_program ; ASM: common_global_program: ; ASM: .long 0 ; ASM: .amdgpu_hsa_program_global external_global +; ASM: .size external_global_program, 4 ; ASM: .hsadata_global_program ; ASM: external_global_program: ; ASM: .long 0 ; ASM: .amdgpu_hsa_module_global internal_global +; ASM: .size internal_global_agent, 4 ; ASM: .hsadata_global_agent ; ASM: internal_global_agent: ; ASM: .long 0 ; ASM: .amdgpu_hsa_module_global common_global +; ASM: .size common_global_agent, 4 ; ASM: .hsadata_global_agent ; ASM: common_global_agent: ; ASM: .long 0 ; ASM: .amdgpu_hsa_program_global external_global +; ASM: .size external_global_agent, 4 ; ASM: .hsadata_global_agent ; ASM: external_global_agent: ; ASM: .long 0 ; ASM: .amdgpu_hsa_module_global internal_readonly +; ASM: .size internal_readonly, 4 ; ASM: .hsatext ; ASM: internal_readonly: ; ASM: .long 0 ; ASM: .amdgpu_hsa_program_global external_readonly +; ASM: .size external_readonly, 4 ; ASM: .hsatext ; ASM: external_readonly: ; ASM: .long 0 @@ -79,18 +87,21 @@ define void @test() { ; ELF: Symbol { ; ELF: Name: common_global_agent +; ELF: Size: 4 ; ELF: Binding: Local ; ELF: Section: .hsadata_global_agent ; ELF: } ; ELF: Symbol { ; ELF: Name: common_global_program +; ELF: Size: 4 ; ELF: Binding: Local ; ELF: Section: .hsadata_global_program ; ELF: } ; ELF: Symbol { ; ELF: Name: internal_global_agent +; ELF: Size: 4 ; ELF: Binding: Local ; ELF: Type: Object ; ELF: Section: .hsadata_global_agent @@ -98,6 +109,7 @@ define void @test() { ; ELF: Symbol { ; ELF: Name: internal_global_program +; ELF: Size: 4 ; ELF: Binding: Local ; ELF: Type: Object ; ELF: Section: .hsadata_global_program @@ -105,6 +117,7 @@ define void @test() { ; ELF: Symbol { ; ELF: Name: internal_readonly +; ELF: Size: 4 ; ELF: Binding: Local ; ELF: Type: Object ; ELF: Section: .hsatext @@ -112,6 +125,7 @@ define void @test() { ; ELF: Symbol { ; ELF: Name: external_global_agent +; ELF: Size: 4 ; ELF: Binding: Global ; ELF: Type: Object ; ELF: Section: .hsadata_global_agent @@ -119,6 +133,7 @@ define void @test() { ; ELF: Symbol { ; ELF: Name: external_global_program +; ELF: Size: 4 ; ELF: Binding: Global ; ELF: Type: Object ; ELF: Section: .hsadata_global_program @@ -126,6 +141,7 @@ define void @test() { ; ELF: Symbol { ; ELF: Name: external_readonly +; ELF: Size: 4 ; ELF: Binding: Global ; ELF: Type: Object ; ELF: Section: .hsatext