Tom Stellard | e135ffd | 2015-09-25 21:41:28 +0000 | [diff] [blame] | 1 | //===-- AMDGPUHSATargetObjectFile.cpp - AMDGPU Object Files ---------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "AMDGPUHSATargetObjectFile.h" |
Tom Stellard | 00f2f91 | 2015-12-02 19:47:57 +0000 | [diff] [blame] | 11 | #include "AMDGPU.h" |
Tom Stellard | e135ffd | 2015-09-25 21:41:28 +0000 | [diff] [blame] | 12 | #include "Utils/AMDGPUBaseInfo.h" |
| 13 | #include "llvm/MC/MCContext.h" |
| 14 | #include "llvm/MC/MCSectionELF.h" |
| 15 | #include "llvm/Support/ELF.h" |
| 16 | |
| 17 | using namespace llvm; |
| 18 | |
| 19 | void AMDGPUHSATargetObjectFile::Initialize(MCContext &Ctx, |
| 20 | const TargetMachine &TM){ |
| 21 | TargetLoweringObjectFileELF::Initialize(Ctx, TM); |
| 22 | InitializeELF(TM.Options.UseInitArray); |
| 23 | |
| 24 | TextSection = AMDGPU::getHSATextSection(Ctx); |
| 25 | |
Tom Stellard | 00f2f91 | 2015-12-02 19:47:57 +0000 | [diff] [blame] | 26 | DataGlobalAgentSection = AMDGPU::getHSADataGlobalAgentSection(Ctx); |
| 27 | DataGlobalProgramSection = AMDGPU::getHSADataGlobalProgramSection(Ctx); |
| 28 | |
Tom Stellard | 9760f03 | 2015-12-03 03:34:32 +0000 | [diff] [blame] | 29 | RodataReadonlyAgentSection = AMDGPU::getHSARodataReadonlyAgentSection(Ctx); |
Tom Stellard | 00f2f91 | 2015-12-02 19:47:57 +0000 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | bool AMDGPUHSATargetObjectFile::isAgentAllocationSection( |
| 33 | const char *SectionName) const { |
| 34 | return cast<MCSectionELF>(DataGlobalAgentSection) |
| 35 | ->getSectionName() |
| 36 | .equals(SectionName); |
| 37 | } |
| 38 | |
| 39 | bool AMDGPUHSATargetObjectFile::isAgentAllocation(const GlobalValue *GV) const { |
| 40 | // Read-only segments can only have agent allocation. |
| 41 | return AMDGPU::isReadOnlySegment(GV) || |
| 42 | (AMDGPU::isGlobalSegment(GV) && GV->hasSection() && |
| 43 | isAgentAllocationSection(GV->getSection())); |
| 44 | } |
| 45 | |
| 46 | bool AMDGPUHSATargetObjectFile::isProgramAllocation( |
| 47 | const GlobalValue *GV) const { |
| 48 | // The default for global segments is program allocation. |
| 49 | return AMDGPU::isGlobalSegment(GV) && !isAgentAllocation(GV); |
Tom Stellard | e135ffd | 2015-09-25 21:41:28 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | MCSection *AMDGPUHSATargetObjectFile::SelectSectionForGlobal( |
| 53 | const GlobalValue *GV, SectionKind Kind, |
| 54 | Mangler &Mang, |
| 55 | const TargetMachine &TM) const { |
| 56 | if (Kind.isText() && !GV->hasComdat()) |
| 57 | return getTextSection(); |
| 58 | |
Tom Stellard | 00f2f91 | 2015-12-02 19:47:57 +0000 | [diff] [blame] | 59 | if (AMDGPU::isGlobalSegment(GV)) { |
| 60 | if (isAgentAllocation(GV)) |
| 61 | return DataGlobalAgentSection; |
| 62 | |
| 63 | if (isProgramAllocation(GV)) |
| 64 | return DataGlobalProgramSection; |
| 65 | } |
| 66 | |
Tom Stellard | 9760f03 | 2015-12-03 03:34:32 +0000 | [diff] [blame] | 67 | if (Kind.isReadOnly() && AMDGPU::isReadOnlySegment(GV)) |
| 68 | return RodataReadonlyAgentSection; |
| 69 | |
Tom Stellard | e135ffd | 2015-09-25 21:41:28 +0000 | [diff] [blame] | 70 | return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, Mang, TM); |
| 71 | } |