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