LLVM  14.0.0git
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/IR/PassManager.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 LLVMTargetMachine;
50 class MMIAddrLabelMap;
51 class MachineFunction;
52 class Module;
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 MachineModuleInfo::getObjFileInfo and destroyed when
58 /// the MachineModuleInfo 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 ///
80  friend class MachineModuleAnalysis;
81 
82  const LLVMTargetMachine &TM;
83 
84  /// This is the MCContext used for the entire code generator.
86  // This is an external context, that if assigned, will be used instead of the
87  // internal context.
88  MCContext *ExternalContext = nullptr;
89 
90  /// This is the LLVM Module being worked on.
91  const Module *TheModule;
92 
93  /// This is the object-file-format-specific implementation of
94  /// MachineModuleInfoImpl, which lets targets accumulate whatever info they
95  /// want.
96  MachineModuleInfoImpl *ObjFileMMI;
97 
98  /// \name Exception Handling
99  /// \{
100 
101  /// Vector of all personality functions ever seen. Used to emit common EH
102  /// frames.
103  std::vector<const Function *> Personalities;
104 
105  /// The current call site index being processed, if any. 0 if none.
106  unsigned CurCallSite;
107 
108  /// \}
109 
110  /// This map keeps track of which symbol is being used for the specified
111  /// basic block's address of label.
112  MMIAddrLabelMap *AddrLabelSymbols;
113 
114  // TODO: Ideally, what we'd like is to have a switch that allows emitting
115  // synchronous (precise at call-sites only) CFA into .eh_frame. However,
116  // even under this switch, we'd like .debug_frame to be precise when using
117  // -g. At this moment, there's no way to specify that some CFI directives
118  // go into .eh_frame only, while others go into .debug_frame only.
119 
120  /// True if debugging information is available in this module.
121  bool DbgInfoAvailable;
122 
123  /// True if this module is being built for windows/msvc, and uses floating
124  /// point. This is used to emit an undefined reference to _fltused.
125  bool UsesMSVCFloatingPoint;
126 
127  /// True if the module calls the __morestack function indirectly, as is
128  /// required under the large code model on x86. This is used to emit
129  /// a definition of a symbol, __morestack_addr, containing the address. See
130  /// comments in lib/Target/X86/X86FrameLowering.cpp for more details.
131  bool UsesMorestackAddr;
132 
133  /// True if the module contains split-stack functions. This is used to
134  /// emit .note.GNU-split-stack section as required by the linker for
135  /// special handling split-stack function calling no-split-stack function.
136  bool HasSplitStack;
137 
138  /// True if the module contains no-split-stack functions. This is used to
139  /// emit .note.GNU-no-split-stack section when it also contains split-stack
140  /// functions.
141  bool HasNosplitStack;
142 
143  /// Maps IR Functions to their corresponding MachineFunctions.
145  /// Next unique number available for a MachineFunction.
146  unsigned NextFnNum = 0;
147  const Function *LastRequest = nullptr; ///< Used for shortcut/cache.
148  MachineFunction *LastResult = nullptr; ///< Used for shortcut/cache.
149 
150  MachineModuleInfo &operator=(MachineModuleInfo &&MMII) = delete;
151 
152 public:
153  explicit MachineModuleInfo(const LLVMTargetMachine *TM = nullptr);
154 
155  explicit MachineModuleInfo(const LLVMTargetMachine *TM,
156  MCContext *ExtContext);
157 
159 
161 
162  void initialize();
163  void finalize();
164 
165  const LLVMTargetMachine &getTarget() const { return TM; }
166 
167  const MCContext &getContext() const {
168  return ExternalContext ? *ExternalContext : Context;
169  }
171  return ExternalContext ? *ExternalContext : Context;
172  }
173 
174  const Module *getModule() const { return TheModule; }
175 
176  /// Returns the MachineFunction constructed for the IR function \p F.
177  /// Creates a new MachineFunction if none exists yet.
179 
180  /// \brief Returns the MachineFunction associated to IR function \p F if there
181  /// is one, otherwise nullptr.
183 
184  /// Delete the MachineFunction \p MF and reset the link in the IR Function to
185  /// Machine Function map.
187 
188  /// Keep track of various per-module pieces of information for backends
189  /// that would like to do so.
190  template<typename Ty>
192  if (ObjFileMMI == nullptr)
193  ObjFileMMI = new Ty(*this);
194  return *static_cast<Ty*>(ObjFileMMI);
195  }
196 
197  template<typename Ty>
198  const Ty &getObjFileInfo() const {
199  return const_cast<MachineModuleInfo*>(this)->getObjFileInfo<Ty>();
200  }
201 
202  /// Returns true if valid debug info is present.
203  bool hasDebugInfo() const { return DbgInfoAvailable; }
204  void setDebugInfoAvailability(bool avail) { DbgInfoAvailable = avail; }
205 
206  bool usesMSVCFloatingPoint() const { return UsesMSVCFloatingPoint; }
207 
208  void setUsesMSVCFloatingPoint(bool b) { UsesMSVCFloatingPoint = b; }
209 
210  bool usesMorestackAddr() const {
211  return UsesMorestackAddr;
212  }
213 
214  void setUsesMorestackAddr(bool b) {
215  UsesMorestackAddr = b;
216  }
217 
218  bool hasSplitStack() const {
219  return HasSplitStack;
220  }
221 
222  void setHasSplitStack(bool b) {
223  HasSplitStack = b;
224  }
225 
226  bool hasNosplitStack() const {
227  return HasNosplitStack;
228  }
229 
230  void setHasNosplitStack(bool b) {
231  HasNosplitStack = b;
232  }
233 
234  /// Return the symbol to be used for the specified basic block when its
235  /// address is taken. This cannot be its normal LBB label because the block
236  /// may be accessed outside its containing function.
238  return getAddrLabelSymbolToEmit(BB).front();
239  }
240 
241  /// Return the symbol to be used for the specified basic block when its
242  /// address is taken. If other blocks were RAUW'd to this one, we may have
243  /// to emit them as well, return the whole set.
245 
246  /// If the specified function has had any references to address-taken blocks
247  /// generated, but the block got deleted, return the symbol now so we can
248  /// emit it. This prevents emitting a reference to a symbol that has no
249  /// definition.
251  std::vector<MCSymbol*> &Result);
252 
253  /// \name Exception Handling
254  /// \{
255 
256  /// Set the call site currently being processed.
257  void setCurrentCallSite(unsigned Site) { CurCallSite = Site; }
258 
259  /// Get the call site currently being processed, if any. return zero if
260  /// none.
261  unsigned getCurrentCallSite() { return CurCallSite; }
262 
263  /// Provide the personality function for the exception information.
264  void addPersonality(const Function *Personality);
265 
266  /// Return array of personality functions ever seen.
267  const std::vector<const Function *>& getPersonalities() const {
268  return Personalities;
269  }
270  /// \}
271 
272  // MMI owes MCContext. It should never be invalidated.
275  return false;
276  }
277 }; // End class MachineModuleInfo
278 
280  MachineModuleInfo MMI;
281 
282 public:
283  static char ID; // Pass identification, replacement for typeid
284  explicit MachineModuleInfoWrapperPass(const LLVMTargetMachine *TM = nullptr);
285 
287  MCContext *ExtContext);
288 
289  // Initialization and Finalization
290  bool doInitialization(Module &) override;
291  bool doFinalization(Module &) override;
292 
293  MachineModuleInfo &getMMI() { return MMI; }
294  const MachineModuleInfo &getMMI() const { return MMI; }
295 };
296 
297 /// An analysis that produces \c MachineInfo for a module.
298 class MachineModuleAnalysis : public AnalysisInfoMixin<MachineModuleAnalysis> {
300  static AnalysisKey Key;
301 
302  const LLVMTargetMachine *TM;
303 
304 public:
305  /// Provide the result type for this analysis pass.
307 
309 
310  /// Run the analysis pass and produce machine module information.
312 };
313 
314 } // end namespace llvm
315 
316 #endif // LLVM_CODEGEN_MACHINEMODULEINFO_H
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:155
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::MachineModuleInfoWrapperPass::doFinalization
bool doFinalization(Module &) override
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
Definition: MachineModuleInfo.cpp:414
llvm::MachineModuleInfo::getContext
const MCContext & getContext() const
Definition: MachineModuleInfo.h:167
llvm::ImmutablePass
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition: Pass.h:269
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
llvm::Function
Definition: Function.h:61
llvm::MachineModuleAnalysis::MachineModuleAnalysis
MachineModuleAnalysis(const LLVMTargetMachine *TM)
Definition: MachineModuleInfo.h:308
Pass.h
llvm::MachineModuleInfoImpl::SymbolListTy
std::vector< std::pair< MCSymbol *, StubValueTy > > SymbolListTy
Definition: MachineModuleInfo.h:63
llvm::MachineModuleInfo::hasDebugInfo
bool hasDebugInfo() const
Returns true if valid debug info is present.
Definition: MachineModuleInfo.h:203
llvm::MachineModuleInfoImpl
This class can be derived from and used by targets to hold private target-specific information for ea...
Definition: MachineModuleInfo.h:60
llvm::MachineModuleAnalysis
An analysis that produces MachineInfo for a module.
Definition: MachineModuleInfo.h:298
DenseMap.h
llvm::MachineModuleInfo::setUsesMSVCFloatingPoint
void setUsesMSVCFloatingPoint(bool b)
Definition: MachineModuleInfo.h:208
llvm::MachineModuleInfoWrapperPass::getMMI
MachineModuleInfo & getMMI()
Definition: MachineModuleInfo.h:293
llvm::MachineModuleInfo::hasNosplitStack
bool hasNosplitStack() const
Definition: MachineModuleInfo.h:226
llvm::MachineModuleInfo::~MachineModuleInfo
~MachineModuleInfo()
Definition: MachineModuleInfo.cpp:254
llvm::MachineModuleInfo::initialize
void initialize()
Definition: MachineModuleInfo.cpp:196
llvm::MachineModuleInfoImpl::~MachineModuleInfoImpl
virtual ~MachineModuleInfoImpl()
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::MachineModuleInfo::setCurrentCallSite
void setCurrentCallSite(unsigned Site)
Set the call site currently being processed.
Definition: MachineModuleInfo.h:257
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
PointerIntPair.h
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::MachineModuleInfo::invalidate
bool invalidate(Module &, const PreservedAnalyses &, ModuleAnalysisManager::Invalidator &)
Definition: MachineModuleInfo.h:273
llvm::MachineModuleInfo::getCurrentCallSite
unsigned getCurrentCallSite()
Get the call site currently being processed, if any.
Definition: MachineModuleInfo.h:261
llvm::MachineModuleAnalysis::run
MachineModuleInfo run(Module &M, ModuleAnalysisManager &)
Run the analysis pass and produce machine module information.
Definition: MachineModuleInfo.cpp:421
llvm::MachineModuleInfo::getObjFileInfo
const Ty & getObjFileInfo() const
Definition: MachineModuleInfo.h:198
MCContext.h
MCSymbol.h
llvm::MachineModuleInfo::getTarget
const LLVMTargetMachine & getTarget() const
Definition: MachineModuleInfo.h:165
b
the resulting code requires compare and branches when and if the revised code is with conditional branches instead of More there is a byte word extend before each where there should be only and the condition codes are not remembered when the same two values are compared twice More LSR enhancements i8 and i32 load store addressing modes are identical int b
Definition: README.txt:418
llvm::MachineModuleInfo
This class contains meta information specific to a module.
Definition: MachineModuleInfo.h:78
llvm::MachineModuleInfo::MachineModuleInfo
MachineModuleInfo(const LLVMTargetMachine *TM=nullptr)
Definition: MachineModuleInfo.cpp:236
llvm::AnalysisManager::Invalidator
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:656
llvm::MachineModuleInfo::setDebugInfoAvailability
void setDebugInfoAvailability(bool avail)
Definition: MachineModuleInfo.h:204
llvm::MachineModuleInfoWrapperPass::getMMI
const MachineModuleInfo & getMMI() const
Definition: MachineModuleInfo.h:294
llvm::MachineModuleInfoImpl::getSortedStubs
static SymbolListTy getSortedStubs(DenseMap< MCSymbol *, StubValueTy > &)
Return the entries from a DenseMap in a deterministic sorted orer.
Definition: MachineModuleInfoImpls.cpp:35
llvm::MachineModuleInfo::getPersonalities
const std::vector< const Function * > & getPersonalities() const
Return array of personality functions ever seen.
Definition: MachineModuleInfo.h:267
llvm::MachineModuleInfoWrapperPass
Definition: MachineModuleInfo.h:279
llvm::MachineModuleInfo::deleteMachineFunctionFor
void deleteMachineFunctionFor(Function &F)
Delete the MachineFunction MF and reset the link in the IR Function to Machine Function map.
Definition: MachineModuleInfo.cpp:315
llvm::DenseMap
Definition: DenseMap.h:714
llvm::AnalysisKey
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:72
llvm::MachineModuleInfo::getAddrLabelSymbol
MCSymbol * getAddrLabelSymbol(const BasicBlock *BB)
Return the symbol to be used for the specified basic block when its address is taken.
Definition: MachineModuleInfo.h:237
ArrayRef.h
llvm::MachineModuleInfo::getAddrLabelSymbolToEmit
ArrayRef< MCSymbol * > getAddrLabelSymbolToEmit(const BasicBlock *BB)
Return the symbol to be used for the specified basic block when its address is taken.
Definition: MachineModuleInfo.cpp:259
llvm::ISD::BasicBlock
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
llvm::MachineModuleInfo::takeDeletedSymbolsForFunction
void takeDeletedSymbolsForFunction(const Function *F, std::vector< MCSymbol * > &Result)
If the specified function has had any references to address-taken blocks generated,...
Definition: MachineModuleInfo.cpp:267
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::AnalysisInfoMixin
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:391
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::MachineModuleInfo::setHasNosplitStack
void setHasNosplitStack(bool b)
Definition: MachineModuleInfo.h:230
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::MachineModuleInfoWrapperPass::doInitialization
bool doInitialization(Module &) override
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
Definition: MachineModuleInfo.cpp:397
llvm::MachineModuleInfo::getOrCreateMachineFunction
MachineFunction & getOrCreateMachineFunction(Function &F)
Returns the MachineFunction constructed for the IR function F.
Definition: MachineModuleInfo.cpp:291
llvm::MachineModuleInfo::hasSplitStack
bool hasSplitStack() const
Definition: MachineModuleInfo.h:218
llvm::MMIAddrLabelMap
Definition: MachineModuleInfo.cpp:65
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
llvm::MachineModuleInfoWrapperPass::ID
static char ID
Definition: MachineModuleInfo.h:283
llvm::MachineModuleInfo::getMachineFunction
MachineFunction * getMachineFunction(const Function &F) const
Returns the MachineFunction associated to IR function F if there is one, otherwise nullptr.
Definition: MachineModuleInfo.cpp:286
llvm::MachineModuleInfo::setHasSplitStack
void setHasSplitStack(bool b)
Definition: MachineModuleInfo.h:222
PassManager.h
llvm::MachineModuleInfoWrapperPass::MachineModuleInfoWrapperPass
MachineModuleInfoWrapperPass(const LLVMTargetMachine *TM=nullptr)
Definition: MachineModuleInfo.cpp:355
llvm::LLVMTargetMachine
This class describes a target machine that is implemented with the LLVM target-independent code gener...
Definition: TargetMachine.h:385
llvm::MachineModuleInfo::getContext
MCContext & getContext()
Definition: MachineModuleInfo.h:170
llvm::PointerIntPair
PointerIntPair - This class implements a pair of a pointer and small integer.
Definition: PointerIntPair.h:45
llvm::MachineModuleInfo::addPersonality
void addPersonality(const Function *Personality)
Provide the personality function for the exception information.
Definition: MachineModuleInfo.cpp:278
llvm::MachineModuleInfo::usesMorestackAddr
bool usesMorestackAddr() const
Definition: MachineModuleInfo.h:210
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:44
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
llvm::MachineModuleInfo::setUsesMorestackAddr
void setUsesMorestackAddr(bool b)
Definition: MachineModuleInfo.h:214
llvm::MachineModuleInfo::finalize
void finalize()
Definition: MachineModuleInfo.cpp:205
llvm::MachineModuleInfo::getModule
const Module * getModule() const
Definition: MachineModuleInfo.h:174
llvm::MachineModuleInfo::getObjFileInfo
Ty & getObjFileInfo()
Keep track of various per-module pieces of information for backends that would like to do so.
Definition: MachineModuleInfo.h:191
llvm::codeview::PublicSymFlags::Function
@ Function
llvm::MachineModuleInfo::usesMSVCFloatingPoint
bool usesMSVCFloatingPoint() const
Definition: MachineModuleInfo.h:206