HexagonTargetObjectFile.cpp revision 261991
1343171Sdim//===-- HexagonTargetObjectFile.cpp - Hexagon asm properties --------------===// 2343171Sdim// 3353358Sdim// The LLVM Compiler Infrastructure 4353358Sdim// 5353358Sdim// This file is distributed under the University of Illinois Open Source 6343171Sdim// License. See LICENSE.TXT for details. 7343171Sdim// 8343171Sdim//===----------------------------------------------------------------------===// 9343171Sdim// 10343171Sdim// This file contains the declarations of the HexagonTargetAsmInfo properties. 11343171Sdim// 12343171Sdim//===----------------------------------------------------------------------===// 13343171Sdim 14343171Sdim#include "HexagonTargetObjectFile.h" 15343171Sdim#include "HexagonSubtarget.h" 16343171Sdim#include "HexagonTargetMachine.h" 17343171Sdim#include "llvm/IR/DataLayout.h" 18343171Sdim#include "llvm/IR/DerivedTypes.h" 19343171Sdim#include "llvm/IR/Function.h" 20343171Sdim#include "llvm/IR/GlobalVariable.h" 21343171Sdim#include "llvm/MC/MCContext.h" 22343171Sdim#include "llvm/Support/CommandLine.h" 23343171Sdim#include "llvm/Support/ELF.h" 24343171Sdim 25343171Sdimusing namespace llvm; 26343171Sdim 27343171Sdimstatic cl::opt<int> SmallDataThreshold("hexagon-small-data-threshold", 28343171Sdim cl::init(8), cl::Hidden, 29343171Sdim cl::desc("The maximum size of an object in the sdata section")); 30343171Sdim 31343171Sdimvoid HexagonTargetObjectFile::Initialize(MCContext &Ctx, 32343171Sdim const TargetMachine &TM) { 33343171Sdim TargetLoweringObjectFileELF::Initialize(Ctx, TM); 34343171Sdim 35343171Sdim 36343171Sdim SmallDataSection = 37343171Sdim 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. 47static bool IsInSmallSection(uint64_t Size) { 48 return Size > 0 && Size <= (uint64_t)SmallDataThreshold; 49} 50 51bool HexagonTargetObjectFile::IsSmallDataEnabled () const { 52 return SmallDataThreshold > 0; 53} 54 55/// IsGlobalInSmallSection - Return true if this global value should be 56/// placed into small data/bss section. 57bool 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. 72bool HexagonTargetObjectFile:: 73IsGlobalInSmallSection(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(); 82 return IsInSmallSection(TM.getDataLayout()->getTypeAllocSize(Ty)); 83 } 84 85 return false; 86} 87 88const MCSection *HexagonTargetObjectFile:: 89SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, 90 Mangler *Mang, const TargetMachine &TM) const { 91 92 // Handle Small Section classification here. 93 if (Kind.isBSS() && IsGlobalInSmallSection(GV, TM, Kind)) 94 return SmallBSSSection; 95 if (Kind.isDataNoRel() && IsGlobalInSmallSection(GV, TM, Kind)) 96 return SmallDataSection; 97 98 // Otherwise, we work the same as ELF. 99 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, Mang,TM); 100} 101