Index: lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp =================================================================== --- lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp +++ lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp @@ -104,7 +104,8 @@ AMDGPUTargetStreamer *TS = static_cast(OutStreamer->getTargetStreamer()); - TS->EmitDirectiveHSACodeObjectVersion(1, 0); + TS->EmitDirectiveHSACodeObjectVersion(2, 0); + AMDGPU::IsaVersion ISA = AMDGPU::getIsaVersion(STI->getFeatureBits()); TS->EmitDirectiveHSACodeObjectISA(ISA.Major, ISA.Minor, ISA.Stepping, "AMD", "AMDGPU"); @@ -132,56 +133,13 @@ AsmPrinter::EmitFunctionEntryLabel(); } -static bool isModuleLinkage(const GlobalValue *GV) { - switch (GV->getLinkage()) { - case GlobalValue::LinkOnceODRLinkage: - case GlobalValue::LinkOnceAnyLinkage: - case GlobalValue::InternalLinkage: - case GlobalValue::CommonLinkage: - return true; - case GlobalValue::ExternalLinkage: - return false; - default: llvm_unreachable("unknown linkage type"); - } -} - void AMDGPUAsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) { - if (TM.getTargetTriple().getOS() != Triple::AMDHSA) { - AsmPrinter::EmitGlobalVariable(GV); - return; - } - - if (GV->isDeclaration() || GV->getLinkage() == GlobalValue::PrivateLinkage) { - AsmPrinter::EmitGlobalVariable(GV); - return; - } - // Group segment variables aren't emitted in HSA. if (AMDGPU::isGroupSegment(GV)) return; - AMDGPUTargetStreamer *TS = - static_cast(OutStreamer->getTargetStreamer()); - if (isModuleLinkage(GV)) { - TS->EmitAMDGPUHsaModuleScopeGlobal(GV->getName()); - } else { - 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)); - const Constant *C = GV->getInitializer(); - OutStreamer->EmitLabel(GVSym); - EmitGlobalConstant(DL, C); - OutStreamer->PopSection(); + AsmPrinter::EmitGlobalVariable(GV); } bool AMDGPUAsmPrinter::runOnMachineFunction(MachineFunction &MF) { @@ -695,6 +653,8 @@ AMDGPUTargetStreamer *TS = static_cast(OutStreamer->getTargetStreamer()); + + OutStreamer->SwitchSection(getObjFileLowering().getTextSection()); TS->EmitAMDKernelCodeT(header); } Index: lib/Target/AMDGPU/AMDGPUTargetMachine.cpp =================================================================== --- lib/Target/AMDGPU/AMDGPUTargetMachine.cpp +++ lib/Target/AMDGPU/AMDGPUTargetMachine.cpp @@ -61,9 +61,6 @@ } static std::unique_ptr createTLOF(const Triple &TT) { - if (TT.getOS() == Triple::AMDHSA) - return make_unique(); - return make_unique(); } Index: lib/Target/AMDGPU/AMDGPUTargetObjectFile.h =================================================================== --- lib/Target/AMDGPU/AMDGPUTargetObjectFile.h +++ lib/Target/AMDGPU/AMDGPUTargetObjectFile.h @@ -28,24 +28,6 @@ const TargetMachine &TM) const override; }; -class AMDGPUHSATargetObjectFile final : public AMDGPUTargetObjectFile { -private: - MCSection *DataGlobalAgentSection; - MCSection *DataGlobalProgramSection; - MCSection *RodataReadonlyAgentSection; - - bool isAgentAllocationSection(const char *SectionName) const; - bool isAgentAllocation(const GlobalValue *GV) const; - bool isProgramAllocation(const GlobalValue *GV) const; - -public: - void Initialize(MCContext &Ctx, const TargetMachine &TM) override; - - MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, - Mangler &Mang, - const TargetMachine &TM) const override; -}; - } // end namespace llvm #endif Index: lib/Target/AMDGPU/AMDGPUTargetObjectFile.cpp =================================================================== --- lib/Target/AMDGPU/AMDGPUTargetObjectFile.cpp +++ lib/Target/AMDGPU/AMDGPUTargetObjectFile.cpp @@ -29,59 +29,3 @@ return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, Mang, TM); } - -//===----------------------------------------------------------------------===// -// HSA Object File -//===----------------------------------------------------------------------===// - - -void AMDGPUHSATargetObjectFile::Initialize(MCContext &Ctx, - const TargetMachine &TM){ - TargetLoweringObjectFileELF::Initialize(Ctx, TM); - InitializeELF(TM.Options.UseInitArray); - - TextSection = AMDGPU::getHSATextSection(Ctx); - - DataGlobalAgentSection = AMDGPU::getHSADataGlobalAgentSection(Ctx); - DataGlobalProgramSection = AMDGPU::getHSADataGlobalProgramSection(Ctx); - - RodataReadonlyAgentSection = AMDGPU::getHSARodataReadonlyAgentSection(Ctx); -} - -bool AMDGPUHSATargetObjectFile::isAgentAllocationSection( - const char *SectionName) const { - return cast(DataGlobalAgentSection) - ->getSectionName() - .equals(SectionName); -} - -bool AMDGPUHSATargetObjectFile::isAgentAllocation(const GlobalValue *GV) const { - // Read-only segments can only have agent allocation. - return AMDGPU::isReadOnlySegment(GV) || - (AMDGPU::isGlobalSegment(GV) && GV->hasSection() && - isAgentAllocationSection(GV->getSection())); -} - -bool AMDGPUHSATargetObjectFile::isProgramAllocation( - const GlobalValue *GV) const { - // The default for global segments is program allocation. - return AMDGPU::isGlobalSegment(GV) && !isAgentAllocation(GV); -} - -MCSection *AMDGPUHSATargetObjectFile::SelectSectionForGlobal( - const GlobalValue *GV, SectionKind Kind, - Mangler &Mang, - const TargetMachine &TM) const { - if (Kind.isText() && !GV->hasComdat()) - return getTextSection(); - - if (AMDGPU::isGlobalSegment(GV)) { - if (isAgentAllocation(GV)) - return DataGlobalAgentSection; - - if (isProgramAllocation(GV)) - return DataGlobalProgramSection; - } - - return AMDGPUTargetObjectFile::SelectSectionForGlobal(GV, Kind, Mang, TM); -} Index: lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFStreamer.h =================================================================== --- lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFStreamer.h +++ lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFStreamer.h @@ -29,7 +29,6 @@ MCCodeEmitter *Emitter) : MCELFStreamer(Context, MAB, OS, Emitter) { } - virtual void InitSections(bool NoExecStac) override; }; MCELFStreamer *createAMDGPUELFStreamer(MCContext &Context, MCAsmBackend &MAB, Index: lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFStreamer.cpp =================================================================== --- lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFStreamer.cpp +++ lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFStreamer.cpp @@ -12,11 +12,6 @@ using namespace llvm; -void AMDGPUELFStreamer::InitSections(bool NoExecStack) { - // Start with the .hsatext section by default. - SwitchSection(AMDGPU::getHSATextSection(getContext())); -} - MCELFStreamer *llvm::createAMDGPUELFStreamer(MCContext &Context, MCAsmBackend &MAB, raw_pwrite_stream &OS, Index: lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp =================================================================== --- lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp +++ lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp @@ -312,10 +312,6 @@ MCStreamer &OS = getStreamer(); OS.PushSection(); - // The MCObjectFileInfo that is available to the assembler is a generic - // implementation and not AMDGPUHSATargetObjectFile, so we can't use - // MCObjectFileInfo::getTextSection() here for fetching the HSATextSection. - OS.SwitchSection(AMDGPU::getHSATextSection(OS.getContext())); OS.EmitBytes(StringRef((const char*)&Header, sizeof(Header))); OS.PopSection(); } Index: test/CodeGen/AMDGPU/global-constant.ll =================================================================== --- test/CodeGen/AMDGPU/global-constant.ll +++ test/CodeGen/AMDGPU/global-constant.ll @@ -12,7 +12,7 @@ ; GCN-NEXT: s_add_u32 s{{[0-9]+}}, s[[PC1_LO]], readonly ; GCN: s_addc_u32 s{{[0-9]+}}, s[[PC1_HI]], 0 ; NOHSA: .text -; HSA: .hsatext +; HSA: .text ; GCN: readonly: ; GCN: readonly2: define void @main(i32 %index, float addrspace(1)* %out) { Index: test/CodeGen/AMDGPU/hsa-globals.ll =================================================================== --- test/CodeGen/AMDGPU/hsa-globals.ll +++ test/CodeGen/AMDGPU/hsa-globals.ll @@ -1,5 +1,4 @@ ; RUN: llc < %s -mtriple=amdgcn--amdhsa -mcpu=kaveri | FileCheck --check-prefix=ASM %s -; RUN: llc < %s -mtriple=amdgcn--amdhsa -mcpu=kaveri | llvm-mc -filetype=obj -triple amdgcn--amdhsa -mcpu=kaveri | llvm-readobj -symbols -s | FileCheck %s --check-prefix=ELF @linkonce_odr_global_program = linkonce_odr addrspace(1) global i32 0 @linkonce_global_program = linkonce addrspace(1) global i32 0 @@ -7,12 +6,6 @@ @common_global_program = common addrspace(1) global i32 0 @external_global_program = addrspace(1) global i32 0 -@linkonce_odr_global_agent = linkonce_odr addrspace(1) global i32 0, section ".hsadata_global_agent" -@linkonce_global_agent = linkonce addrspace(1) global i32 0, section ".hsadata_global_agent" -@internal_global_agent = internal addrspace(1) global i32 0, section ".hsadata_global_agent" -@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 @@ -20,185 +13,38 @@ ret void } -; ASM: .amdgpu_hsa_module_global linkonce_odr_global -; ASM: .size linkonce_odr_global_program, 4 -; ASM: .hsadata_global_program +; ASM: .type linkonce_odr_global_program,@object +; ASM: .section .bss,#alloc,#write +; ASM: .weak linkonce_odr_global_program ; ASM: linkonce_odr_global_program: ; ASM: .long 0 +; ASM: .size linkonce_odr_global_program, 4 -; ASM: .amdgpu_hsa_module_global linkonce_global -; ASM: .size linkonce_global_program, 4 -; ASM: .hsadata_global_program +; ASM: .type linkonce_global_program,@object +; ASM: .weak linkonce_global_program ; ASM: linkonce_global_program: ; ASM: .long 0 +; ASM: .size linkonce_global_program, 4 -; 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: .type internal_global_program,@object +; ASM: .local internal_global_program +; ASM: .comm internal_global_program,4,2 -; 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: .type common_global_program,@object +; ASM: .comm common_global_program,4,2 -; 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: .size external_global_program, 4 -; ASM: .amdgpu_hsa_module_global linkonce_odr_global -; ASM: .size linkonce_odr_global_agent, 4 -; ASM: .hsadata_global_agent -; ASM: linkonce_odr_global_agent: -; ASM: .long 0 - -; ASM: .amdgpu_hsa_module_global linkonce_global -; ASM: .size linkonce_global_agent, 4 -; ASM: .hsadata_global_agent -; ASM: linkonce_global_agent: -; 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: .type internal_readonly,@object +; ASM: .text ; ASM: internal_readonly: ; ASM: .long 0 +; ASM: .size internal_readonly, 4 -; ASM: .amdgpu_hsa_program_global external_readonly -; ASM: .size external_readonly, 4 -; ASM: .hsatext +; ASM: .type external_readonly,@object +; ASM: .globl external_readonly ; ASM: external_readonly: ; ASM: .long 0 - -; ELF: Section { -; ELF: Name: .hsadata_global_program -; ELF: Type: SHT_PROGBITS (0x1) -; ELF: Flags [ (0x100003) -; ELF: SHF_ALLOC (0x2) -; ELF: SHF_AMDGPU_HSA_GLOBAL (0x100000) -; ELF: SHF_WRITE (0x1) -; ELF: ] -; ELF: } - -; ELF: Section { -; ELF: Name: .hsadata_global_agent -; ELF: Type: SHT_PROGBITS (0x1) -; ELF: Flags [ (0x900003) -; ELF: SHF_ALLOC (0x2) -; ELF: SHF_AMDGPU_HSA_AGENT (0x800000) -; ELF: SHF_AMDGPU_HSA_GLOBAL (0x100000) -; ELF: SHF_WRITE (0x1) -; ELF: ] -; ELF: } - -; 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 -; ELF: } - -; ELF: Symbol { -; ELF: Name: internal_global_program -; ELF: Size: 4 -; ELF: Binding: Local -; ELF: Type: Object -; ELF: Section: .hsadata_global_program -; ELF: } - -; ELF: Symbol { -; ELF: Name: internal_readonly -; ELF: Size: 4 -; ELF: Binding: Local -; ELF: Type: Object -; ELF: Section: .hsatext -; ELF: } - -; ELF: Symbol { -; ELF: Name: linkonce_global_agent -; ELF: Size: 4 -; ELF: Binding: Local -; ELF: Section: .hsadata_global_agent -; ELF: } - -; ELF: Symbol { -; ELF: Name: linkonce_global_program -; ELF: Size: 4 -; ELF: Binding: Local -; ELF: Section: .hsadata_global_program -; ELF: } - -; ELF: Symbol { -; ELF: Name: linkonce_odr_global_agent -; ELF: Size: 4 -; ELF: Binding: Local -; ELF: Section: .hsadata_global_agent -; ELF: } - -; ELF: Symbol { -; ELF: Name: linkonce_odr_global_program -; ELF: Size: 4 -; ELF: Binding: Local -; ELF: Section: .hsadata_global_program -; ELF: } - -; ELF: Symbol { -; ELF: Name: external_global_agent -; ELF: Size: 4 -; ELF: Binding: Global -; ELF: Type: Object -; ELF: Section: .hsadata_global_agent -; ELF: } - -; ELF: Symbol { -; ELF: Name: external_global_program -; ELF: Size: 4 -; ELF: Binding: Global -; ELF: Type: Object -; ELF: Section: .hsadata_global_program -; ELF: } - -; ELF: Symbol { -; ELF: Name: external_readonly -; ELF: Size: 4 -; ELF: Binding: Global -; ELF: Type: Object -; ELF: Section: .hsatext -; ELF: } +; ASM: .size external_readonly, 4 Index: test/CodeGen/AMDGPU/hsa-note-no-func.ll =================================================================== --- test/CodeGen/AMDGPU/hsa-note-no-func.ll +++ test/CodeGen/AMDGPU/hsa-note-no-func.ll @@ -2,7 +2,7 @@ ; RUN: llc < %s -mtriple=amdgcn--amdhsa -mcpu=carrizo | FileCheck --check-prefix=HSA --check-prefix=HSA-VI %s ; RUN: llc < %s -mtriple=amdgcn--amdhsa -mcpu=fiji | FileCheck --check-prefix=HSA --check-prefix=HSA-FIJI %s -; HSA: .hsa_code_object_version 1,0 +; HSA: .hsa_code_object_version 2,0 ; HSA-CI: .hsa_code_object_isa 7,0,0,"AMD","AMDGPU" ; HSA-VI: .hsa_code_object_isa 8,0,1,"AMD","AMDGPU" ; HSA-FIJI: .hsa_code_object_isa 8,0,3,"AMD","AMDGPU" Index: test/CodeGen/AMDGPU/hsa.ll =================================================================== --- test/CodeGen/AMDGPU/hsa.ll +++ test/CodeGen/AMDGPU/hsa.ll @@ -9,19 +9,16 @@ ; directives. ; ELF: Section { -; ELF: Name: .hsatext +; ELF: Name: .text ; ELF: Type: SHT_PROGBITS (0x1) -; ELF: Flags [ (0xC00007) +; ELF: Flags [ (0x6) ; ELF: SHF_ALLOC (0x2) -; ELF: SHF_AMDGPU_HSA_AGENT (0x800000) -; ELF: SHF_AMDGPU_HSA_CODE (0x400000) ; ELF: SHF_EXECINSTR (0x4) -; ELF: SHF_WRITE (0x1) ; ELF: } ; ELF: SHT_NOTE ; ELF: 0000: 04000000 08000000 01000000 414D4400 -; ELF: 0010: 01000000 00000000 04000000 1B000000 +; ELF: 0010: 02000000 00000000 04000000 1B000000 ; ELF: 0020: 03000000 414D4400 04000700 07000000 ; ELF: 0030: 00000000 00000000 414D4400 414D4447 ; ELF: 0040: 50550000 @@ -32,11 +29,11 @@ ; ELF: Type: AMDGPU_HSA_KERNEL (0xA) ; ELF: } -; HSA: .hsa_code_object_version 1,0 +; HSA: .hsa_code_object_version 2,0 ; HSA-CI: .hsa_code_object_isa 7,0,0,"AMD","AMDGPU" ; HSA-VI: .hsa_code_object_isa 8,0,1,"AMD","AMDGPU" -; HSA: .hsatext +; HSA: .text ; HSA: .amdgpu_hsa_kernel simple ; HSA: {{^}}simple: