LLVM  5.0.0
MachineModuleInfo.h
Go to the documentation of this file.
1 //===-- llvm/CodeGen/MachineModuleInfo.h ------------------------*- 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 // Collect meta information for a module. This information should be in a
11 // neutral form that can be used by different debugging and exception handling
12 // schemes.
13 //
14 // The organization of information is primarily clustered around the source
15 // compile units. The main exception is source line correspondence where
16 // inlining may interleave code from various compile units.
17 //
18 // The following information can be retrieved from the MachineModuleInfo.
19 //
20 // -- Source directories - Directories are uniqued based on their canonical
21 // string and assigned a sequential numeric ID (base 1.)
22 // -- Source files - Files are also uniqued based on their name and directory
23 // ID. A file ID is sequential number (base 1.)
24 // -- Source line correspondence - A vector of file ID, line#, column# triples.
25 // A DEBUG_LOCATION instruction is generated by the DAG Legalizer
26 // corresponding to each entry in the source line list. This allows a debug
27 // emitter to generate labels referenced by debug information tables.
28 //
29 //===----------------------------------------------------------------------===//
30 
31 #ifndef LLVM_CODEGEN_MACHINEMODULEINFO_H
32 #define LLVM_CODEGEN_MACHINEMODULEINFO_H
33 
34 #include "llvm/ADT/ArrayRef.h"
35 #include "llvm/ADT/DenseMap.h"
37 #include "llvm/MC/MCContext.h"
38 #include "llvm/MC/MCSymbol.h"
39 #include "llvm/Pass.h"
40 #include <memory>
41 #include <utility>
42 #include <vector>
43 
44 namespace llvm {
45 
46 class BasicBlock;
47 class CallInst;
48 class Function;
49 class MachineFunction;
50 class MMIAddrLabelMap;
51 class Module;
52 class TargetMachine;
53 
54 //===----------------------------------------------------------------------===//
55 /// This class can be derived from and used by targets to hold private
56 /// target-specific information for each Module. Objects of type are
57 /// accessed/created with MMI::getInfo and destroyed when the MachineModuleInfo
58 /// is destroyed.
59 ///
61 public:
63  using SymbolListTy = std::vector<std::pair<MCSymbol *, StubValueTy>>;
64 
65  virtual ~MachineModuleInfoImpl();
66 
67 protected:
68  /// Return the entries from a DenseMap in a deterministic sorted orer.
69  /// Clears the map.
71 };
72 
73 //===----------------------------------------------------------------------===//
74 /// This class contains meta information specific to a module. Queries can be
75 /// made by different debugging and exception handling schemes and reformated
76 /// for specific use.
77 ///
79  const TargetMachine &TM;
80 
81  /// This is the MCContext used for the entire code generator.
82  MCContext Context;
83 
84  /// This is the LLVM Module being worked on.
85  const Module *TheModule;
86 
87  /// This is the object-file-format-specific implementation of
88  /// MachineModuleInfoImpl, which lets targets accumulate whatever info they
89  /// want.
90  MachineModuleInfoImpl *ObjFileMMI;
91 
92  /// \name Exception Handling
93  /// \{
94 
95  /// Vector of all personality functions ever seen. Used to emit common EH
96  /// frames.
97  std::vector<const Function *> Personalities;
98 
99  /// The current call site index being processed, if any. 0 if none.
100  unsigned CurCallSite;
101 
102  /// \}
103 
104  /// This map keeps track of which symbol is being used for the specified
105  /// basic block's address of label.
106  MMIAddrLabelMap *AddrLabelSymbols;
107 
108  // TODO: Ideally, what we'd like is to have a switch that allows emitting
109  // synchronous (precise at call-sites only) CFA into .eh_frame. However,
110  // even under this switch, we'd like .debug_frame to be precise when using
111  // -g. At this moment, there's no way to specify that some CFI directives
112  // go into .eh_frame only, while others go into .debug_frame only.
113 
114  /// True if debugging information is available in this module.
115  bool DbgInfoAvailable;
116 
117  /// True if this module calls VarArg function with floating-point arguments.
118  /// This is used to emit an undefined reference to _fltused on Windows
119  /// targets.
120  bool UsesVAFloatArgument;
121 
122  /// True if the module calls the __morestack function indirectly, as is
123  /// required under the large code model on x86. This is used to emit
124  /// a definition of a symbol, __morestack_addr, containing the address. See
125  /// comments in lib/Target/X86/X86FrameLowering.cpp for more details.
126  bool UsesMorestackAddr;
127 
128  /// Maps IR Functions to their corresponding MachineFunctions.
130  /// Next unique number available for a MachineFunction.
131  unsigned NextFnNum = 0;
132  const Function *LastRequest = nullptr; ///< Used for shortcut/cache.
133  MachineFunction *LastResult = nullptr; ///< Used for shortcut/cache.
134 
135 public:
136  static char ID; // Pass identification, replacement for typeid
137 
138  explicit MachineModuleInfo(const TargetMachine *TM = nullptr);
139  ~MachineModuleInfo() override;
140 
141  // Initialization and Finalization
142  bool doInitialization(Module &) override;
143  bool doFinalization(Module &) override;
144 
145  const MCContext &getContext() const { return Context; }
146  MCContext &getContext() { return Context; }
147 
148  void setModule(const Module *M) { TheModule = M; }
149  const Module *getModule() const { return TheModule; }
150 
151  /// Returns the MachineFunction constructed for the IR function \p F.
152  /// Creates a new MachineFunction if none exists yet.
154 
155  /// \bried Returns the MachineFunction associated to IR function \p F if there
156  /// is one, otherwise nullptr.
158 
159  /// Delete the MachineFunction \p MF and reset the link in the IR Function to
160  /// Machine Function map.
162 
163  /// Keep track of various per-function pieces of information for backends
164  /// that would like to do so.
165  template<typename Ty>
167  if (ObjFileMMI == nullptr)
168  ObjFileMMI = new Ty(*this);
169  return *static_cast<Ty*>(ObjFileMMI);
170  }
171 
172  template<typename Ty>
173  const Ty &getObjFileInfo() const {
174  return const_cast<MachineModuleInfo*>(this)->getObjFileInfo<Ty>();
175  }
176 
177  /// Returns true if valid debug info is present.
178  bool hasDebugInfo() const { return DbgInfoAvailable; }
179  void setDebugInfoAvailability(bool avail) { DbgInfoAvailable = avail; }
180 
181  bool usesVAFloatArgument() const {
182  return UsesVAFloatArgument;
183  }
184 
185  void setUsesVAFloatArgument(bool b) {
186  UsesVAFloatArgument = b;
187  }
188 
189  bool usesMorestackAddr() const {
190  return UsesMorestackAddr;
191  }
192 
193  void setUsesMorestackAddr(bool b) {
194  UsesMorestackAddr = b;
195  }
196 
197  /// Return the symbol to be used for the specified basic block when its
198  /// address is taken. This cannot be its normal LBB label because the block
199  /// may be accessed outside its containing function.
201  return getAddrLabelSymbolToEmit(BB).front();
202  }
203 
204  /// Return the symbol to be used for the specified basic block when its
205  /// address is taken. If other blocks were RAUW'd to this one, we may have
206  /// to emit them as well, return the whole set.
208 
209  /// If the specified function has had any references to address-taken blocks
210  /// generated, but the block got deleted, return the symbol now so we can
211  /// emit it. This prevents emitting a reference to a symbol that has no
212  /// definition.
214  std::vector<MCSymbol*> &Result);
215 
216  /// \name Exception Handling
217  /// \{
218 
219  /// Set the call site currently being processed.
220  void setCurrentCallSite(unsigned Site) { CurCallSite = Site; }
221 
222  /// Get the call site currently being processed, if any. return zero if
223  /// none.
224  unsigned getCurrentCallSite() { return CurCallSite; }
225 
226  /// Provide the personality function for the exception information.
227  void addPersonality(const Function *Personality);
228 
229  /// Return array of personality functions ever seen.
230  const std::vector<const Function *>& getPersonalities() const {
231  return Personalities;
232  }
233  /// \}
234 }; // End class MachineModuleInfo
235 
236 //===- MMI building helpers -----------------------------------------------===//
237 
238 /// Determine if any floating-point values are being passed to this variadic
239 /// function, and set the MachineModuleInfo's usesVAFloatArgument flag if so.
240 /// This flag is used to emit an undefined reference to _fltused on Windows,
241 /// which will link in MSVCRT's floating-point support.
242 void computeUsesVAFloatArgument(const CallInst &I, MachineModuleInfo &MMI);
243 
244 } // end namespace llvm
245 
246 #endif // LLVM_CODEGEN_MACHINEMODULEINFO_H
const Ty & getObjFileInfo() const
bool doFinalization(Module &) override
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
Various leaf nodes.
Definition: ISDOpcodes.h:60
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
void deleteMachineFunctionFor(Function &F)
Delete the MachineFunction MF and reset the link in the IR Function to Machine Function map...
void computeUsesVAFloatArgument(const CallInst &I, MachineModuleInfo &MMI)
Determine if any floating-point values are being passed to this variadic function, and set the MachineModuleInfo's usesVAFloatArgument flag if so.
void setCurrentCallSite(unsigned Site)
Set the call site currently being processed.
void takeDeletedSymbolsForFunction(const Function *F, std::vector< MCSymbol * > &Result)
If the specified function has had any references to address-taken blocks generated, but the block got deleted, return the symbol now so we can emit it.
~MachineModuleInfo() override
const Module * getModule() const
MachineModuleInfo(const TargetMachine *TM=nullptr)
bool hasDebugInfo() const
Returns true if valid debug info is present.
bool usesVAFloatArgument() const
Context object for machine code objects.
Definition: MCContext.h:59
#define F(x, y, z)
Definition: MD5.cpp:55
unsigned getCurrentCallSite()
Get the call site currently being processed, if any.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
ArrayRef< MCSymbol * > getAddrLabelSymbolToEmit(const BasicBlock *BB)
Return the symbol to be used for the specified basic block when its address is taken.
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
PointerIntPair - This class implements a pair of a pointer and small integer.
void addPersonality(const Function *Personality)
Provide the personality function for the exception information.
MCSymbol * getAddrLabelSymbol(const BasicBlock *BB)
Return the symbol to be used for the specified basic block when its address is taken.
const std::vector< const Function * > & getPersonalities() const
Return array of personality functions ever seen.
Ty & getObjFileInfo()
Keep track of various per-function pieces of information for backends that would like to do so...
MachineFunction & getOrCreateMachineFunction(const Function &F)
Returns the MachineFunction constructed for the IR function F.
ImmutablePass class - This class is used to provide information that does not need to be run...
Definition: Pass.h:266
void setDebugInfoAvailability(bool avail)
const MCContext & getContext() const
std::vector< std::pair< MCSymbol *, StubValueTy >> SymbolListTy
MachineFunction * getMachineFunction(const Function &F) const
Returns the MachineFunction associated to IR function F if there is one, otherwise nullptr...
bool doInitialization(Module &) override
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
void setModule(const Module *M)
#define I(x, y, z)
Definition: MD5.cpp:58
void setUsesVAFloatArgument(bool b)
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:56
This class can be derived from and used by targets to hold private target-specific information for ea...
static SymbolListTy getSortedStubs(DenseMap< MCSymbol *, StubValueTy > &)
Return the entries from a DenseMap in a deterministic sorted orer.
This class contains meta information specific to a module.