1 //===-- AMDGPUHSATargetObjectFile.cpp - AMDGPU Object Files ---------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "AMDGPUTargetObjectFile.h"
12 #include "Utils/AMDGPUBaseInfo.h"
13 #include "llvm/MC/MCContext.h"
14 #include "llvm/MC/MCSectionELF.h"
15 #include "llvm/Support/ELF.h"
19 //===----------------------------------------------------------------------===//
20 // Generic Object File
21 //===----------------------------------------------------------------------===//
23 MCSection *AMDGPUTargetObjectFile::SelectSectionForGlobal(const GlobalValue *GV,
26 const TargetMachine &TM) const {
27 if (Kind.isReadOnly() && AMDGPU::isReadOnlySegment(GV))
30 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, Mang, TM);
33 //===----------------------------------------------------------------------===//
35 //===----------------------------------------------------------------------===//
38 void AMDGPUHSATargetObjectFile::Initialize(MCContext &Ctx,
39 const TargetMachine &TM){
40 TargetLoweringObjectFileELF::Initialize(Ctx, TM);
41 InitializeELF(TM.Options.UseInitArray);
43 TextSection = AMDGPU::getHSATextSection(Ctx);
45 DataGlobalAgentSection = AMDGPU::getHSADataGlobalAgentSection(Ctx);
46 DataGlobalProgramSection = AMDGPU::getHSADataGlobalProgramSection(Ctx);
48 RodataReadonlyAgentSection = AMDGPU::getHSARodataReadonlyAgentSection(Ctx);
51 bool AMDGPUHSATargetObjectFile::isAgentAllocationSection(
52 const char *SectionName) const {
53 return cast<MCSectionELF>(DataGlobalAgentSection)
58 bool AMDGPUHSATargetObjectFile::isAgentAllocation(const GlobalValue *GV) const {
59 // Read-only segments can only have agent allocation.
60 return AMDGPU::isReadOnlySegment(GV) ||
61 (AMDGPU::isGlobalSegment(GV) && GV->hasSection() &&
62 isAgentAllocationSection(GV->getSection()));
65 bool AMDGPUHSATargetObjectFile::isProgramAllocation(
66 const GlobalValue *GV) const {
67 // The default for global segments is program allocation.
68 return AMDGPU::isGlobalSegment(GV) && !isAgentAllocation(GV);
71 MCSection *AMDGPUHSATargetObjectFile::SelectSectionForGlobal(
72 const GlobalValue *GV, SectionKind Kind,
74 const TargetMachine &TM) const {
75 if (Kind.isText() && !GV->hasComdat())
76 return getTextSection();
78 if (AMDGPU::isGlobalSegment(GV)) {
79 if (isAgentAllocation(GV))
80 return DataGlobalAgentSection;
82 if (isProgramAllocation(GV))
83 return DataGlobalProgramSection;
86 if (Kind.isReadOnly() && AMDGPU::isReadOnlySegment(GV))
87 return RodataReadonlyAgentSection;
89 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, Mang, TM);