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