LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) {
34 
35 
36  SmallDataSection =
37  getContext().getELFSection(".sdata", ELF::SHT_PROGBITS,
38  ELF::SHF_WRITE | ELF::SHF_ALLOC,
40  SmallBSSSection =
41  getContext().getELFSection(".sbss", ELF::SHT_NOBITS,
42  ELF::SHF_WRITE | ELF::SHF_ALLOC,
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 }
50 
52  return SmallDataThreshold > 0;
53 }
54 
55 /// IsGlobalInSmallSection - Return true if this global value should be
56 /// placed into small data/bss section.
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.
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.
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();
83  }
84 
85  return false;
86 }
87 
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.
100 }
bool IsGlobalInSmallSection(const GlobalValue *GV, const TargetMachine &TM, SectionKind Kind) const
static SectionKind getKindForGlobal(const GlobalValue *GV, const TargetMachine &TM)
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:266
const MCSectionELF * getELFSection(StringRef Section, unsigned Type, unsigned Flags, SectionKind Kind)
Definition: MCContext.cpp:244
static SectionKind getDataRel()
Definition: SectionKind.h:229
bool isBSS() const
Definition: SectionKind.h:176
bool hasAvailableExternallyLinkage() const
Definition: GlobalValue.h:195
static SectionKind getBSS()
Definition: SectionKind.h:225
virtual void Initialize(MCContext &ctx, const TargetMachine &TM)
Type * getElementType() const
Definition: DerivedTypes.h:319
bool isDataNoRel() const
Definition: SectionKind.h:190
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:314
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"))
uint64_t getTypeAllocSize(Type *Ty) const
Definition: DataLayout.h:326
const MCSection * SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler *Mang, const TargetMachine &TM) const
PointerType * getType() const
getType - Global values are always pointers.
Definition: GlobalValue.h:107
virtual const MCSection * SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler *Mang, const TargetMachine &TM) const
bool isDeclaration() const
Definition: Globals.cpp:66
virtual const DataLayout * getDataLayout() const
virtual void Initialize(MCContext &Ctx, const TargetMachine &TM)
bool isCommon() const
Definition: SectionKind.h:180