LLVM  3.7.0
HexagonTargetObjectFile.cpp
Go to the documentation of this file.
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 
15 #include "HexagonSubtarget.h"
16 #include "HexagonTargetMachine.h"
17 #include "llvm/IR/DataLayout.h"
18 #include "llvm/IR/DerivedTypes.h"
19 #include "llvm/IR/Function.h"
20 #include "llvm/IR/GlobalVariable.h"
21 #include "llvm/MC/MCContext.h"
23 #include "llvm/Support/ELF.h"
24 
25 using namespace llvm;
26 
27 static cl::opt<int> SmallDataThreshold("hexagon-small-data-threshold",
28  cl::init(8), cl::Hidden,
29  cl::desc("The maximum size of an object in the sdata section"));
30 
32  const TargetMachine &TM) {
35 
36  SmallDataSection = getContext().getELFSection(
38  SmallBSSSection = getContext().getELFSection(".sbss", ELF::SHT_NOBITS,
40 }
41 
42 // sdata/sbss support taken largely from the MIPS Backend.
43 static bool IsInSmallSection(uint64_t Size) {
44  return Size > 0 && Size <= (uint64_t)SmallDataThreshold;
45 }
46 
48  return SmallDataThreshold > 0;
49 }
50 
51 /// IsGlobalInSmallSection - Return true if this global value should be
52 /// placed into small data/bss section.
54  const TargetMachine &TM) const {
55  // If the primary definition of this global value is outside the current
56  // translation unit or the global value is available for inspection but not
57  // emission, then do nothing.
59  return false;
60 
61  // Otherwise, Check if GV should be in sdata/sbss, when normally it would end
62  // up in getKindForGlobal(GV, TM).
63  return IsGlobalInSmallSection(GV, TM, getKindForGlobal(GV, TM));
64 }
65 
66 /// IsGlobalInSmallSection - Return true if this global value should be
67 /// placed into small data/bss section.
70  SectionKind Kind) const {
71  // Only global variables, not functions.
72  const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GV);
73  if (!GVA)
74  return false;
75 
76  if (Kind.isBSS() || Kind.isDataNoRel() || Kind.isCommon()) {
77  Type *Ty = GV->getType()->getElementType();
79  }
80 
81  return false;
82 }
83 
84 MCSection *
86  SectionKind Kind, Mangler &Mang,
87  const TargetMachine &TM) const {
88 
89  // Handle Small Section classification here.
90  if (Kind.isBSS() && IsGlobalInSmallSection(GV, TM, Kind))
91  return SmallBSSSection;
92  if (Kind.isDataNoRel() && IsGlobalInSmallSection(GV, TM, Kind))
93  return SmallDataSection;
94 
95  // Otherwise, we work the same as ELF.
97 }
bool IsGlobalInSmallSection(const GlobalValue *GV, const TargetMachine &TM, SectionKind Kind) const
IsGlobalInSmallSection - Return true if this global address should be placed into small data/bss sect...
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:48
static SectionKind getKindForGlobal(const GlobalValue *GV, const TargetMachine &TM)
Classify the specified global variable into a set of target independent categories embodied in Sectio...
MCSectionELF * getELFSection(StringRef Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:311
bool isBSS() const
Definition: SectionKind.h:175
bool hasAvailableExternallyLinkage() const
Definition: GlobalValue.h:261
virtual void Initialize(MCContext &ctx, const TargetMachine &TM)
This method must be called before any actual lowering is done.
Context object for machine code objects.
Definition: MCContext.h:48
Type * getElementType() const
Definition: DerivedTypes.h:323
bool isDataNoRel() const
Definition: SectionKind.h:189
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:325
MCSection * SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang, const TargetMachine &TM) const override
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
MCSection * SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang, const TargetMachine &TM) const override
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:28
static bool IsInSmallSection(uint64_t Size)
static cl::opt< int > SmallDataThreshold("hexagon-small-data-threshold", cl::init(8), cl::Hidden, cl::desc("The maximum size of an object in the sdata section"))
unsigned UseInitArray
UseInitArray - Use .init_array instead of .ctors for static constructors.
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:388
const DataLayout * getDataLayout() const
Deprecated in 3.7, will be removed in 3.8.
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:285
PointerType * getType() const
Global values are always pointers.
Definition: GlobalValue.h:185
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:128
bool isCommon() const
Definition: SectionKind.h:179
const ARM::ArchExtKind Kind
Primary interface to the complete machine description for the target machine.