LLVM  3.7.0
TargetLoweringObjectFile.h
Go to the documentation of this file.
1 //===-- llvm/Target/TargetLoweringObjectFile.h - Object Info ----*- C++ -*-===//
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 implements classes used to handle lowerings specific to common
11 // object file formats.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
16 #define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
17 
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/IR/Module.h"
21 #include "llvm/MC/SectionKind.h"
22 
23 namespace llvm {
24  class MachineModuleInfo;
25  class Mangler;
26  class MCContext;
27  class MCExpr;
28  class MCSection;
29  class MCSymbol;
30  class MCSymbolRefExpr;
31  class MCStreamer;
32  class MCValue;
33  class ConstantExpr;
34  class GlobalValue;
35  class TargetMachine;
36 
38  MCContext *Ctx;
39 
41  const TargetLoweringObjectFile&) = delete;
42  void operator=(const TargetLoweringObjectFile&) = delete;
43 
44 protected:
45  const DataLayout *DL;
48 
49 public:
50  MCContext &getContext() const { return *Ctx; }
51 
52  TargetLoweringObjectFile() : MCObjectFileInfo(), Ctx(nullptr), DL(nullptr),
55 
56  virtual ~TargetLoweringObjectFile();
57 
58  /// This method must be called before any actual lowering is done. This
59  /// specifies the current context for codegen, and gives the lowering
60  /// implementations a chance to set up their default sections.
61  virtual void Initialize(MCContext &ctx, const TargetMachine &TM);
62 
63  virtual void emitPersonalityValue(MCStreamer &Streamer,
64  const TargetMachine &TM,
65  const MCSymbol *Sym) const;
66 
67  /// Emit the module flags that the platform cares about.
68  virtual void emitModuleFlags(MCStreamer &Streamer,
70  Mangler &Mang, const TargetMachine &TM) const {}
71 
72  /// Given a constant with the SectionKind, return a section that it should be
73  /// placed in.
75  const Constant *C) const;
76 
77  /// Classify the specified global variable into a set of target independent
78  /// categories embodied in SectionKind.
79  static SectionKind getKindForGlobal(const GlobalValue *GV,
80  const TargetMachine &TM);
81 
82  /// This method computes the appropriate section to emit the specified global
83  /// variable or function definition. This should not be passed external (or
84  /// available externally) globals.
86  Mangler &Mang, const TargetMachine &TM) const;
87 
88  /// This method computes the appropriate section to emit the specified global
89  /// variable or function definition. This should not be passed external (or
90  /// available externally) globals.
92  const TargetMachine &TM) const {
93  return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
94  }
95 
96  virtual void getNameWithPrefix(SmallVectorImpl<char> &OutName,
97  const GlobalValue *GV,
98  bool CannotUsePrivateLabel, Mangler &Mang,
99  const TargetMachine &TM) const;
100 
101  virtual MCSection *getSectionForJumpTable(const Function &F, Mangler &Mang,
102  const TargetMachine &TM) const;
103 
104  virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
105  const Function &F) const;
106 
107  /// Targets should implement this method to assign a section to globals with
108  /// an explicit section specfied. The implementation of this method can
109  /// assume that GV->hasSection() is true.
110  virtual MCSection *
112  Mangler &Mang, const TargetMachine &TM) const = 0;
113 
114  /// Allow the target to completely override section assignment of a global.
117  Mangler &Mang) const {
118  return nullptr;
119  }
120 
121  /// Return an MCExpr to use for a reference to the specified global variable
122  /// from exception handling information.
123  virtual const MCExpr *
124  getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
125  Mangler &Mang, const TargetMachine &TM,
126  MachineModuleInfo *MMI, MCStreamer &Streamer) const;
127 
128  /// Return the MCSymbol for a private symbol with global value name as its
129  /// base, with the specified suffix.
131  StringRef Suffix, Mangler &Mang,
132  const TargetMachine &TM) const;
133 
134  // The symbol that gets passed to .cfi_personality.
135  virtual MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
136  Mangler &Mang,
137  const TargetMachine &TM,
138  MachineModuleInfo *MMI) const;
139 
140  const MCExpr *
141  getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
142  MCStreamer &Streamer) const;
143 
144  virtual MCSection *getStaticCtorSection(unsigned Priority,
145  const MCSymbol *KeySym) const {
146  return StaticCtorSection;
147  }
148 
149  virtual MCSection *getStaticDtorSection(unsigned Priority,
150  const MCSymbol *KeySym) const {
151  return StaticDtorSection;
152  }
153 
154  /// \brief Create a symbol reference to describe the given TLS variable when
155  /// emitting the address in debug info.
156  virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
157 
158  virtual const MCExpr *
160  const TargetMachine &TM) const {
161  return nullptr;
162  }
163 
164  /// \brief Target supports replacing a data "PC"-relative access to a symbol
165  /// through another symbol, by accessing the later via a GOT entry instead?
168  }
169 
170  /// \brief Target GOT "PC"-relative relocation supports encoding an additional
171  /// binary expression with an offset?
174  }
175 
176  /// \brief Get the target specific PC relative GOT entry relocation
177  virtual const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym,
178  const MCValue &MV,
179  int64_t Offset,
180  MachineModuleInfo *MMI,
181  MCStreamer &Streamer) const {
182  return nullptr;
183  }
184 
185  virtual void emitLinkerFlagsForGlobal(raw_ostream &OS, const GlobalValue *GV,
186  const Mangler &Mang) const {}
187 
188 protected:
189  virtual MCSection *SelectSectionForGlobal(const GlobalValue *GV,
190  SectionKind Kind, Mangler &Mang,
191  const TargetMachine &TM) const = 0;
192 };
193 
194 } // end namespace llvm
195 
196 #endif
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:48
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:104
virtual void emitModuleFlags(MCStreamer &Streamer, ArrayRef< Module::ModuleFlagEntry > Flags, Mangler &Mang, const TargetMachine &TM) const
Emit the module flags that the platform cares about.
static SectionKind getKindForGlobal(const GlobalValue *GV, const TargetMachine &TM)
Classify the specified global variable into a set of target independent categories embodied in Sectio...
virtual MCSection * getSectionForJumpTable(const Function &F, Mangler &Mang, const TargetMachine &TM) const
This represents an "assembler immediate".
Definition: MCValue.h:44
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:39
virtual void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, bool CannotUsePrivateLabel, Mangler &Mang, const TargetMachine &TM) const
F(f)
bool supportGOTPCRelWithOffset() const
Target GOT "PC"-relative relocation supports encoding an additional binary expression with an offset...
virtual MCSection * SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang, const TargetMachine &TM) const =0
virtual const MCSection * getSpecialCasedSectionGlobals(const GlobalValue *GV, SectionKind Kind, Mangler &Mang) const
Allow the target to completely override section assignment of a global.
virtual void Initialize(MCContext &ctx, const TargetMachine &TM)
This method must be called before any actual lowering is done.
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:33
const MCExpr * getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding, MCStreamer &Streamer) const
MCSection * StaticDtorSection
This section contains the static destructor pointer list.
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:159
#define false
Definition: ConvertUTF.c:65
Context object for machine code objects.
Definition: MCContext.h:48
ConstantExpr - a constant value that is initialized with an expression using other constant values...
Definition: Constants.h:852
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:31
virtual const MCExpr * getDebugThreadLocalSymbol(const MCSymbol *Sym) const
Create a symbol reference to describe the given TLS variable when emitting the address in debug info...
MCSymbol * getSymbolWithGlobalValueBase(const GlobalValue *GV, StringRef Suffix, Mangler &Mang, const TargetMachine &TM) const
Return the MCSymbol for a private symbol with global value name as its base, with the specified suffi...
virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const
#define true
Definition: ConvertUTF.c:66
Streaming machine code generation interface.
Definition: MCStreamer.h:157
virtual MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const
virtual const MCExpr * getIndirectSymViaGOTPCRel(const MCSymbol *Sym, const MCValue &MV, int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const
Get the target specific PC relative GOT entry relocation.
MCSection * SectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang, const TargetMachine &TM) const
This method computes the appropriate section to emit the specified global variable or function defini...
This is an important base class in LLVM.
Definition: Constant.h:41
virtual MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const
MCSection * SectionForGlobal(const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM) const
This method computes the appropriate section to emit the specified global variable or function defini...
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:28
virtual MCSection * getSectionForConstant(SectionKind Kind, const Constant *C) const
Given a constant with the SectionKind, return a section that it should be placed in.
bool supportIndirectSymViaGOTPCRel() const
Target supports replacing a data "PC"-relative access to a symbol through another symbol...
MCSection * StaticCtorSection
This section contains the static constructor pointer list.
Module.h This file contains the declarations for the Module class.
virtual void emitPersonalityValue(MCStreamer &Streamer, const TargetMachine &TM, const MCSymbol *Sym) const
virtual const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, Mangler &Mang, const TargetMachine &TM, MachineModuleInfo *MMI, MCStreamer &Streamer) const
Return an MCExpr to use for a reference to the specified global variable from exception handling info...
virtual const MCExpr * getExecutableRelativeSymbol(const ConstantExpr *CE, Mangler &Mang, const TargetMachine &TM) const
const ARM::ArchExtKind Kind
virtual MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM, MachineModuleInfo *MMI) const
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38
Primary interface to the complete machine description for the target machine.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
virtual MCSection * getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang, const TargetMachine &TM) const =0
Targets should implement this method to assign a section to globals with an explicit section specfied...
virtual void emitLinkerFlagsForGlobal(raw_ostream &OS, const GlobalValue *GV, const Mangler &Mang) const
MachineModuleInfo - This class contains meta information specific to a module.