]>
Commit | Line | Data |
---|---|---|
223e47cc LB |
1 | //===-- HexagonTargetObjectFile.cpp - Hexagon asm properties --------------===// |
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 | // This file contains the declarations of the HexagonTargetAsmInfo properties. | |
11 | // | |
12 | //===----------------------------------------------------------------------===// | |
13 | ||
14 | #include "HexagonTargetObjectFile.h" | |
15 | #include "HexagonSubtarget.h" | |
16 | #include "HexagonTargetMachine.h" | |
970d7e83 LB |
17 | #include "llvm/IR/DataLayout.h" |
18 | #include "llvm/IR/DerivedTypes.h" | |
19 | #include "llvm/IR/Function.h" | |
20 | #include "llvm/IR/GlobalVariable.h" | |
223e47cc | 21 | #include "llvm/MC/MCContext.h" |
223e47cc | 22 | #include "llvm/Support/CommandLine.h" |
970d7e83 | 23 | #include "llvm/Support/ELF.h" |
223e47cc LB |
24 | |
25 | using namespace llvm; | |
26 | ||
27 | static cl::opt<int> SmallDataThreshold("hexagon-small-data-threshold", | |
1a4d82fc JJ |
28 | cl::init(8), cl::Hidden, |
29 | cl::desc("The maximum size of an object in the sdata section")); | |
223e47cc LB |
30 | |
31 | void HexagonTargetObjectFile::Initialize(MCContext &Ctx, | |
32 | const TargetMachine &TM) { | |
33 | TargetLoweringObjectFileELF::Initialize(Ctx, TM); | |
85aaf69f | 34 | InitializeELF(TM.Options.UseInitArray); |
223e47cc LB |
35 | |
36 | SmallDataSection = | |
37 | getContext().getELFSection(".sdata", ELF::SHT_PROGBITS, | |
38 | ELF::SHF_WRITE | ELF::SHF_ALLOC, | |
39 | SectionKind::getDataRel()); | |
40 | SmallBSSSection = | |
41 | getContext().getELFSection(".sbss", ELF::SHT_NOBITS, | |
42 | ELF::SHF_WRITE | ELF::SHF_ALLOC, | |
43 | SectionKind::getBSS()); | |
44 | } | |
45 | ||
46 | // sdata/sbss support taken largely from the MIPS Backend. | |
47 | static bool IsInSmallSection(uint64_t Size) { | |
48 | return Size > 0 && Size <= (uint64_t)SmallDataThreshold; | |
49 | } | |
1a4d82fc JJ |
50 | |
51 | bool HexagonTargetObjectFile::IsSmallDataEnabled () const { | |
52 | return SmallDataThreshold > 0; | |
53 | } | |
54 | ||
223e47cc LB |
55 | /// IsGlobalInSmallSection - Return true if this global value should be |
56 | /// placed into small data/bss section. | |
57 | bool HexagonTargetObjectFile::IsGlobalInSmallSection(const GlobalValue *GV, | |
58 | const TargetMachine &TM) const { | |
59 | // If the primary definition of this global value is outside the current | |
60 | // translation unit or the global value is available for inspection but not | |
61 | // emission, then do nothing. | |
62 | if (GV->isDeclaration() || GV->hasAvailableExternallyLinkage()) | |
63 | return false; | |
64 | ||
65 | // Otherwise, Check if GV should be in sdata/sbss, when normally it would end | |
66 | // up in getKindForGlobal(GV, TM). | |
67 | return IsGlobalInSmallSection(GV, TM, getKindForGlobal(GV, TM)); | |
68 | } | |
69 | ||
70 | /// IsGlobalInSmallSection - Return true if this global value should be | |
71 | /// placed into small data/bss section. | |
72 | bool HexagonTargetObjectFile:: | |
73 | IsGlobalInSmallSection(const GlobalValue *GV, const TargetMachine &TM, | |
74 | SectionKind Kind) const { | |
75 | // Only global variables, not functions. | |
76 | const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GV); | |
77 | if (!GVA) | |
78 | return false; | |
79 | ||
80 | if (Kind.isBSS() || Kind.isDataNoRel() || Kind.isCommon()) { | |
81 | Type *Ty = GV->getType()->getElementType(); | |
1a4d82fc JJ |
82 | return IsInSmallSection( |
83 | TM.getSubtargetImpl()->getDataLayout()->getTypeAllocSize(Ty)); | |
223e47cc LB |
84 | } |
85 | ||
86 | return false; | |
87 | } | |
88 | ||
1a4d82fc JJ |
89 | const MCSection * |
90 | HexagonTargetObjectFile::SelectSectionForGlobal(const GlobalValue *GV, | |
91 | SectionKind Kind, Mangler &Mang, | |
92 | const TargetMachine &TM) const { | |
223e47cc LB |
93 | |
94 | // Handle Small Section classification here. | |
95 | if (Kind.isBSS() && IsGlobalInSmallSection(GV, TM, Kind)) | |
96 | return SmallBSSSection; | |
97 | if (Kind.isDataNoRel() && IsGlobalInSmallSection(GV, TM, Kind)) | |
98 | return SmallDataSection; | |
99 | ||
100 | // Otherwise, we work the same as ELF. | |
101 | return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, Mang,TM); | |
102 | } |