LLVM  4.0.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 
40  /// Name-mangler for global names.
41  Mangler *Mang = nullptr;
42 
44  const TargetLoweringObjectFile&) = delete;
45  void operator=(const TargetLoweringObjectFile&) = delete;
46 
47 protected:
50 
51  /// This section contains the static constructor pointer list.
53 
54  /// This section contains the static destructor pointer list.
56 
57 public:
58  MCContext &getContext() const { return *Ctx; }
59  Mangler &getMangler() const { return *Mang; }
60 
62  : MCObjectFileInfo(), Ctx(nullptr), Mang(nullptr),
64 
65  virtual ~TargetLoweringObjectFile();
66 
67  /// This method must be called before any actual lowering is done. This
68  /// specifies the current context for codegen, and gives the lowering
69  /// implementations a chance to set up their default sections.
70  virtual void Initialize(MCContext &ctx, const TargetMachine &TM);
71 
72  virtual void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM,
73  const MCSymbol *Sym) const;
74 
75  /// Emit the module flags that the platform cares about.
76  virtual void emitModuleFlags(MCStreamer &Streamer,
78  const TargetMachine &TM) const {}
79 
80  /// Given a constant with the SectionKind, return a section that it should be
81  /// placed in.
82  virtual MCSection *getSectionForConstant(const DataLayout &DL,
84  const Constant *C,
85  unsigned &Align) const;
86 
87  /// Classify the specified global variable into a set of target independent
88  /// categories embodied in SectionKind.
89  static SectionKind getKindForGlobal(const GlobalObject *GO,
90  const TargetMachine &TM);
91 
92  /// This method computes the appropriate section to emit the specified global
93  /// variable or function definition. This should not be passed external (or
94  /// available externally) globals.
96  const TargetMachine &TM) const;
97 
98  /// This method computes the appropriate section to emit the specified global
99  /// variable or function definition. This should not be passed external (or
100  /// available externally) globals.
102  const TargetMachine &TM) const {
103  return SectionForGlobal(GO, getKindForGlobal(GO, TM), TM);
104  }
105 
106  virtual void getNameWithPrefix(SmallVectorImpl<char> &OutName,
107  const GlobalValue *GV,
108  const TargetMachine &TM) const;
109 
110  virtual MCSection *getSectionForJumpTable(const Function &F,
111  const TargetMachine &TM) const;
112 
113  virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
114  const Function &F) const;
115 
116  /// Targets should implement this method to assign a section to globals with
117  /// an explicit section specfied. The implementation of this method can
118  /// assume that GO->hasSection() is true.
119  virtual MCSection *
121  const TargetMachine &TM) const = 0;
122 
123  /// Return an MCExpr to use for a reference to the specified global variable
124  /// from exception handling information.
125  virtual const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
126  unsigned Encoding,
127  const TargetMachine &TM,
128  MachineModuleInfo *MMI,
129  MCStreamer &Streamer) const;
130 
131  /// Return the MCSymbol for a private symbol with global value name as its
132  /// base, with the specified suffix.
134  StringRef Suffix,
135  const TargetMachine &TM) const;
136 
137  // The symbol that gets passed to .cfi_personality.
138  virtual MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
139  const TargetMachine &TM,
140  MachineModuleInfo *MMI) const;
141 
142  const MCExpr *getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
143  MCStreamer &Streamer) const;
144 
145  virtual MCSection *getStaticCtorSection(unsigned Priority,
146  const MCSymbol *KeySym) const {
147  return StaticCtorSection;
148  }
149 
150  virtual MCSection *getStaticDtorSection(unsigned Priority,
151  const MCSymbol *KeySym) const {
152  return StaticDtorSection;
153  }
154 
155  /// \brief Create a symbol reference to describe the given TLS variable when
156  /// emitting the address in debug info.
157  virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
158 
159  virtual const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
160  const GlobalValue *RHS,
161  const TargetMachine &TM) const {
162  return nullptr;
163  }
164 
165  /// \brief Target supports replacing a data "PC"-relative access to a symbol
166  /// through another symbol, by accessing the later via a GOT entry instead?
169  }
170 
171  /// \brief Target GOT "PC"-relative relocation supports encoding an additional
172  /// binary expression with an offset?
175  }
176 
177  /// \brief Get the target specific PC relative GOT entry relocation
178  virtual const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym,
179  const MCValue &MV,
180  int64_t Offset,
181  MachineModuleInfo *MMI,
182  MCStreamer &Streamer) const {
183  return nullptr;
184  }
185 
187  const GlobalValue *GV) const {}
188 
189 protected:
190  virtual MCSection *SelectSectionForGlobal(const GlobalObject *GO,
192  const TargetMachine &TM) const = 0;
193 };
194 
195 } // end namespace llvm
196 
197 #endif
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:40
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:102
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:39
MCSection * StaticCtorSection
This section contains the static constructor pointer list.
virtual void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM, const MCSymbol *Sym) const
bool supportGOTPCRelWithOffset() const
Target GOT "PC"-relative relocation supports encoding an additional binary expression with an offset...
struct fuzzer::@269 Flags
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...
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:34
const MCExpr * getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding, MCStreamer &Streamer) const
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:161
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 void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const
Context object for machine code objects.
Definition: MCContext.h:51
#define F(x, y, z)
Definition: MD5.cpp:51
MCSection * StaticDtorSection
This section contains the static destructor pointer list.
Function Alias Analysis false
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
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...
virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const
Streaming machine code generation interface.
Definition: MCStreamer.h:161
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.
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.
virtual MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const
uint32_t Offset
virtual void emitLinkerFlagsForGlobal(raw_ostream &OS, const GlobalValue *GV) const
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:23
bool supportIndirectSymViaGOTPCRel() const
Target supports replacing a data "PC"-relative access to a symbol through another symbol...
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 MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const
Module.h This file contains the declarations for the Module class.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
virtual const MCExpr * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, const TargetMachine &TM) const
virtual void emitModuleFlags(MCStreamer &Streamer, ArrayRef< Module::ModuleFlagEntry > Flags, const TargetMachine &TM) const
Emit the module flags that the platform cares about.
Basic Alias true
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...
virtual MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, const TargetMachine &TM, MachineModuleInfo *MMI) const
const unsigned Kind
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...
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:44
Primary interface to the complete machine description for the target machine.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
static SectionKind getKindForGlobal(const GlobalObject *GO, const TargetMachine &TM)
Classify the specified global variable into a set of target independent categories embodied in Sectio...
This class contains meta information specific to a module.