LLVM  8.0.0svn
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_CODEGEN_TARGETLOWERINGOBJECTFILE_H
16 #define LLVM_CODEGEN_TARGETLOWERINGOBJECTFILE_H
17 
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/IR/Module.h"
22 #include "llvm/MC/SectionKind.h"
23 #include <cstdint>
24 
25 namespace llvm {
26 
27 class GlobalValue;
28 class MachineModuleInfo;
29 class Mangler;
30 class MCContext;
31 class MCExpr;
32 class MCSection;
33 class MCSymbol;
34 class MCSymbolRefExpr;
35 class MCStreamer;
36 class MCValue;
37 class TargetMachine;
38 
40  MCContext *Ctx = nullptr;
41 
42  /// Name-mangler for global names.
43  Mangler *Mang = nullptr;
44 
45 protected:
49 
50  /// PersonalityEncoding, LSDAEncoding, TTypeEncoding - Some encoding values
51  /// for EH.
52  unsigned PersonalityEncoding = 0;
53  unsigned LSDAEncoding = 0;
54  unsigned TTypeEncoding = 0;
55 
56  /// This section contains the static constructor pointer list.
58 
59  /// This section contains the static destructor pointer list.
61 
62 public:
63  TargetLoweringObjectFile() = default;
66  operator=(const TargetLoweringObjectFile &) = delete;
67  virtual ~TargetLoweringObjectFile();
68 
69  MCContext &getContext() const { return *Ctx; }
70  Mangler &getMangler() const { return *Mang; }
71 
72  /// This method must be called before any actual lowering is done. This
73  /// specifies the current context for codegen, and gives the lowering
74  /// implementations a chance to set up their default sections.
75  virtual void Initialize(MCContext &ctx, const TargetMachine &TM);
76 
77  virtual void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM,
78  const MCSymbol *Sym) const;
79 
80  /// Emit the module-level metadata that the platform cares about.
81  virtual void emitModuleMetadata(MCStreamer &Streamer, Module &M) const {}
82 
83  /// Given a constant with the SectionKind, return a section that it should be
84  /// placed in.
85  virtual MCSection *getSectionForConstant(const DataLayout &DL,
87  const Constant *C,
88  unsigned &Align) const;
89 
90  /// Classify the specified global variable into a set of target independent
91  /// categories embodied in SectionKind.
92  static SectionKind getKindForGlobal(const GlobalObject *GO,
93  const TargetMachine &TM);
94 
95  /// This method computes the appropriate section to emit the specified global
96  /// variable or function definition. This should not be passed external (or
97  /// available externally) globals.
99  const TargetMachine &TM) const;
100 
101  /// This method computes the appropriate section to emit the specified global
102  /// variable or function definition. This should not be passed external (or
103  /// available externally) globals.
105  const TargetMachine &TM) const {
106  return SectionForGlobal(GO, getKindForGlobal(GO, TM), TM);
107  }
108 
109  virtual void getNameWithPrefix(SmallVectorImpl<char> &OutName,
110  const GlobalValue *GV,
111  const TargetMachine &TM) const;
112 
113  virtual MCSection *getSectionForJumpTable(const Function &F,
114  const TargetMachine &TM) const;
115 
116  virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
117  const Function &F) const;
118 
119  /// Targets should implement this method to assign a section to globals with
120  /// an explicit section specfied. The implementation of this method can
121  /// assume that GO->hasSection() is true.
122  virtual MCSection *
124  const TargetMachine &TM) const = 0;
125 
126  /// Return an MCExpr to use for a reference to the specified global variable
127  /// from exception handling information.
128  virtual const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
129  unsigned Encoding,
130  const TargetMachine &TM,
131  MachineModuleInfo *MMI,
132  MCStreamer &Streamer) const;
133 
134  /// Return the MCSymbol for a private symbol with global value name as its
135  /// base, with the specified suffix.
137  StringRef Suffix,
138  const TargetMachine &TM) const;
139 
140  // The symbol that gets passed to .cfi_personality.
141  virtual MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
142  const TargetMachine &TM,
143  MachineModuleInfo *MMI) const;
144 
145  unsigned getPersonalityEncoding() const { return PersonalityEncoding; }
146  unsigned getLSDAEncoding() const { return LSDAEncoding; }
147  unsigned getTTypeEncoding() const { return TTypeEncoding; }
148 
149  const MCExpr *getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
150  MCStreamer &Streamer) const;
151 
152  virtual MCSection *getStaticCtorSection(unsigned Priority,
153  const MCSymbol *KeySym) const {
154  return StaticCtorSection;
155  }
156 
157  virtual MCSection *getStaticDtorSection(unsigned Priority,
158  const MCSymbol *KeySym) const {
159  return StaticDtorSection;
160  }
161 
162  /// Create a symbol reference to describe the given TLS variable when
163  /// emitting the address in debug info.
164  virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
165 
166  virtual const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
167  const GlobalValue *RHS,
168  const TargetMachine &TM) const {
169  return nullptr;
170  }
171 
172  /// Target supports replacing a data "PC"-relative access to a symbol
173  /// through another symbol, by accessing the later via a GOT entry instead?
176  }
177 
178  /// Target GOT "PC"-relative relocation supports encoding an additional
179  /// binary expression with an offset?
182  }
183 
184  /// Target supports TLS offset relocation in debug section?
187  }
188 
189  /// Get the target specific PC relative GOT entry relocation
190  virtual const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym,
191  const MCValue &MV,
192  int64_t Offset,
193  MachineModuleInfo *MMI,
194  MCStreamer &Streamer) const {
195  return nullptr;
196  }
197 
199  const GlobalValue *GV) const {}
200 
202  const GlobalValue *GV) const {}
203 
204 protected:
205  virtual MCSection *SelectSectionForGlobal(const GlobalObject *GO,
206  SectionKind Kind,
207  const TargetMachine &TM) const = 0;
208 };
209 
210 } // end namespace llvm
211 
212 #endif // LLVM_CODEGEN_TARGETLOWERINGOBJECTFILE_H
uint64_t CallInst * C
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
bool supportDebugThreadLocalLocation() const
Target supports TLS offset relocation in debug section?
virtual MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
virtual void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM, const MCSymbol *Sym) const
MCSection * SectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const
This method computes the appropriate section to emit the specified global variable or function defini...
This represents an "assembler immediate".
Definition: MCValue.h:40
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
MCSection * StaticCtorSection
This section contains the static constructor pointer list.
const MCExpr * getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding, MCStreamer &Streamer) const
F(f)
virtual void emitLinkerFlagsForUsed(raw_ostream &OS, const GlobalValue *GV) const
virtual MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const
unsigned PersonalityEncoding
PersonalityEncoding, LSDAEncoding, TTypeEncoding - Some encoding values for EH.
virtual void Initialize(MCContext &ctx, const TargetMachine &TM)
This method must be called before any actual lowering is done.
virtual void emitModuleMetadata(MCStreamer &Streamer, Module &M) const
Emit the module-level metadata that the platform cares about.
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:166
Context object for machine code objects.
Definition: MCContext.h:63
bool supportGOTPCRelWithOffset() const
Target GOT "PC"-relative relocation supports encoding an additional binary expression with an offset...
MCSection * StaticDtorSection
This section contains the static destructor pointer list.
Streaming machine code generation interface.
Definition: MCStreamer.h:183
MCSection * SectionForGlobal(const GlobalObject *GO, const TargetMachine &TM) const
This method computes the appropriate section to emit the specified global variable or function defini...
virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const
virtual void emitLinkerFlagsForGlobal(raw_ostream &OS, const GlobalValue *GV) const
This is an important base class in LLVM.
Definition: Constant.h:42
virtual MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, unsigned &Align) const
Given a constant with the SectionKind, return a section that it should be placed in.
MCSymbol * getSymbolWithGlobalValueBase(const GlobalValue *GV, StringRef Suffix, const TargetMachine &TM) const
Return the MCSymbol for a private symbol with global value name as its base, with the specified suffi...
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:23
virtual const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, 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 * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, const TargetMachine &TM) 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.
Module.h This file contains the declarations for the Module class.
TargetLoweringObjectFile & operator=(const TargetLoweringObjectFile &)=delete
virtual void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const
virtual MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const =0
Targets should implement this method to assign a section to globals with an explicit section specfied...
const unsigned Kind
virtual MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const =0
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:59
virtual MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
static SectionKind getKindForGlobal(const GlobalObject *GO, const TargetMachine &TM)
Classify the specified global variable into a set of target independent categories embodied in Sectio...
virtual MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, const TargetMachine &TM, MachineModuleInfo *MMI) const
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...
bool supportIndirectSymViaGOTPCRel() const
Target supports replacing a data "PC"-relative access to a symbol through another symbol...
This class contains meta information specific to a module.