LLVM  15.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/DenseMap.h"
35 #include "llvm/IR/PassManager.h"
36 #include "llvm/MC/MCContext.h"
37 #include "llvm/Pass.h"
38 #include <memory>
39 #include <utility>
40 #include <vector>
41 
42 namespace llvm {
43 
44 class BasicBlock;
45 class Function;
46 class LLVMTargetMachine;
47 class MachineFunction;
48 class Module;
49 class MCSymbol;
50 
51 //===----------------------------------------------------------------------===//
52 /// This class can be derived from and used by targets to hold private
53 /// target-specific information for each Module. Objects of type are
54 /// accessed/created with MachineModuleInfo::getObjFileInfo and destroyed when
55 /// the MachineModuleInfo is destroyed.
56 ///
58 public:
60  using SymbolListTy = std::vector<std::pair<MCSymbol *, StubValueTy>>;
61 
62  virtual ~MachineModuleInfoImpl();
63 
64 protected:
65  /// Return the entries from a DenseMap in a deterministic sorted orer.
66  /// Clears the map.
68 };
69 
70 //===----------------------------------------------------------------------===//
71 /// This class contains meta information specific to a module. Queries can be
72 /// made by different debugging and exception handling schemes and reformated
73 /// for specific use.
74 ///
77  friend class MachineModuleAnalysis;
78 
79  const LLVMTargetMachine &TM;
80 
81  /// This is the MCContext used for the entire code generator.
83  // This is an external context, that if assigned, will be used instead of the
84  // internal context.
85  MCContext *ExternalContext = nullptr;
86 
87  /// This is the LLVM Module being worked on.
88  const Module *TheModule;
89 
90  /// This is the object-file-format-specific implementation of
91  /// MachineModuleInfoImpl, which lets targets accumulate whatever info they
92  /// want.
93  MachineModuleInfoImpl *ObjFileMMI;
94 
95  /// \name Exception Handling
96  /// \{
97 
98  /// Vector of all personality functions ever seen. Used to emit common EH
99  /// frames.
100  std::vector<const Function *> Personalities;
101 
102  /// The current call site index being processed, if any. 0 if none.
103  unsigned CurCallSite;
104 
105  /// \}
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 is being built for windows/msvc, and uses floating
117  /// point. This is used to emit an undefined reference to _fltused.
118  bool UsesMSVCFloatingPoint;
119 
120  /// Maps IR Functions to their corresponding MachineFunctions.
122  /// Next unique number available for a MachineFunction.
123  unsigned NextFnNum = 0;
124  const Function *LastRequest = nullptr; ///< Used for shortcut/cache.
125  MachineFunction *LastResult = nullptr; ///< Used for shortcut/cache.
126 
127  MachineModuleInfo &operator=(MachineModuleInfo &&MMII) = delete;
128 
129 public:
130  explicit MachineModuleInfo(const LLVMTargetMachine *TM = nullptr);
131 
132  explicit MachineModuleInfo(const LLVMTargetMachine *TM,
133  MCContext *ExtContext);
134 
136 
138 
139  void initialize();
140  void finalize();
141 
142  const LLVMTargetMachine &getTarget() const { return TM; }
143 
144  const MCContext &getContext() const {
145  return ExternalContext ? *ExternalContext : Context;
146  }
148  return ExternalContext ? *ExternalContext : Context;
149  }
150 
151  const Module *getModule() const { return TheModule; }
152 
153  /// Returns the MachineFunction constructed for the IR function \p F.
154  /// Creates a new MachineFunction if none exists yet.
156 
157  /// \brief Returns the MachineFunction associated to IR function \p F if there
158  /// is one, otherwise nullptr.
160 
161  /// Delete the MachineFunction \p MF and reset the link in the IR Function to
162  /// Machine Function map.
164 
165  /// Add an externally created MachineFunction \p MF for \p F.
166  void insertFunction(const Function &F, std::unique_ptr<MachineFunction> &&MF);
167 
168  /// Keep track of various per-module pieces of information for backends
169  /// that would like to do so.
170  template<typename Ty>
172  if (ObjFileMMI == nullptr)
173  ObjFileMMI = new Ty(*this);
174  return *static_cast<Ty*>(ObjFileMMI);
175  }
176 
177  template<typename Ty>
178  const Ty &getObjFileInfo() const {
179  return const_cast<MachineModuleInfo*>(this)->getObjFileInfo<Ty>();
180  }
181 
182  /// Returns true if valid debug info is present.
183  bool hasDebugInfo() const { return DbgInfoAvailable; }
184 
185  bool usesMSVCFloatingPoint() const { return UsesMSVCFloatingPoint; }
186 
187  void setUsesMSVCFloatingPoint(bool b) { UsesMSVCFloatingPoint = b; }
188 
189  /// \name Exception Handling
190  /// \{
191 
192  /// Set the call site currently being processed.
193  void setCurrentCallSite(unsigned Site) { CurCallSite = Site; }
194 
195  /// Get the call site currently being processed, if any. return zero if
196  /// none.
197  unsigned getCurrentCallSite() { return CurCallSite; }
198 
199  /// Provide the personality function for the exception information.
200  void addPersonality(const Function *Personality);
201 
202  /// Return array of personality functions ever seen.
203  const std::vector<const Function *>& getPersonalities() const {
204  return Personalities;
205  }
206  /// \}
207 
208  // MMI owes MCContext. It should never be invalidated.
211  return false;
212  }
213 }; // End class MachineModuleInfo
214 
216  MachineModuleInfo MMI;
217 
218 public:
219  static char ID; // Pass identification, replacement for typeid
220  explicit MachineModuleInfoWrapperPass(const LLVMTargetMachine *TM = nullptr);
221 
223  MCContext *ExtContext);
224 
225  // Initialization and Finalization
226  bool doInitialization(Module &) override;
227  bool doFinalization(Module &) override;
228 
229  MachineModuleInfo &getMMI() { return MMI; }
230  const MachineModuleInfo &getMMI() const { return MMI; }
231 };
232 
233 /// An analysis that produces \c MachineInfo for a module.
234 class MachineModuleAnalysis : public AnalysisInfoMixin<MachineModuleAnalysis> {
236  static AnalysisKey Key;
237 
238  const LLVMTargetMachine *TM;
239 
240 public:
241  /// Provide the result type for this analysis pass.
243 
245 
246  /// Run the analysis pass and produce machine module information.
248 };
249 
250 } // end namespace llvm
251 
252 #endif // LLVM_CODEGEN_MACHINEMODULEINFO_H
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:152
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
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:241
llvm::MachineModuleInfo::getContext
const MCContext & getContext() const
Definition: MachineModuleInfo.h:144
llvm::ImmutablePass
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition: Pass.h:279
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:74
llvm::Function
Definition: Function.h:60
llvm::MachineModuleAnalysis::MachineModuleAnalysis
MachineModuleAnalysis(const LLVMTargetMachine *TM)
Definition: MachineModuleInfo.h:244
Pass.h
llvm::MachineModuleInfo::insertFunction
void insertFunction(const Function &F, std::unique_ptr< MachineFunction > &&MF)
Add an externally created MachineFunction MF for F.
Definition: MachineModuleInfo.cpp:138
llvm::MachineModuleInfoImpl::SymbolListTy
std::vector< std::pair< MCSymbol *, StubValueTy > > SymbolListTy
Definition: MachineModuleInfo.h:60
llvm::MachineModuleInfo::hasDebugInfo
bool hasDebugInfo() const
Returns true if valid debug info is present.
Definition: MachineModuleInfo.h:183
llvm::MachineModuleInfoImpl
This class can be derived from and used by targets to hold private target-specific information for ea...
Definition: MachineModuleInfo.h:57
llvm::MachineModuleAnalysis
An analysis that produces MachineInfo for a module.
Definition: MachineModuleInfo.h:234
DenseMap.h
llvm::MachineModuleInfo::setUsesMSVCFloatingPoint
void setUsesMSVCFloatingPoint(bool b)
Definition: MachineModuleInfo.h:187
llvm::MachineModuleInfoWrapperPass::getMMI
MachineModuleInfo & getMMI()
Definition: MachineModuleInfo.h:229
llvm::MachineModuleInfo::~MachineModuleInfo
~MachineModuleInfo()
Definition: MachineModuleInfo.cpp:90
llvm::MachineModuleInfo::initialize
void initialize()
Definition: MachineModuleInfo.cpp:41
llvm::MachineModuleInfoImpl::~MachineModuleInfoImpl
virtual ~MachineModuleInfoImpl()
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::MachineModuleInfo::setCurrentCallSite
void setCurrentCallSite(unsigned Site)
Set the call site currently being processed.
Definition: MachineModuleInfo.h:193
PointerIntPair.h
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::MachineModuleInfo::invalidate
bool invalidate(Module &, const PreservedAnalyses &, ModuleAnalysisManager::Invalidator &)
Definition: MachineModuleInfo.h:209
llvm::MachineModuleInfo::getCurrentCallSite
unsigned getCurrentCallSite()
Get the call site currently being processed, if any.
Definition: MachineModuleInfo.h:197
llvm::MachineModuleAnalysis::run
MachineModuleInfo run(Module &M, ModuleAnalysisManager &)
Run the analysis pass and produce machine module information.
Definition: MachineModuleInfo.cpp:248
llvm::MachineModuleInfo::getObjFileInfo
const Ty & getObjFileInfo() const
Definition: MachineModuleInfo.h:178
MCContext.h
llvm::MachineModuleInfo::getTarget
const LLVMTargetMachine & getTarget() const
Definition: MachineModuleInfo.h:142
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:75
llvm::MachineModuleInfo::MachineModuleInfo
MachineModuleInfo(const LLVMTargetMachine *TM=nullptr)
Definition: MachineModuleInfo.cpp:72
llvm::AnalysisManager::Invalidator
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:667
llvm::MachineModuleInfoWrapperPass::getMMI
const MachineModuleInfo & getMMI() const
Definition: MachineModuleInfo.h:230
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:203
llvm::MachineModuleInfoWrapperPass
Definition: MachineModuleInfo.h:215
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:132
llvm::DenseMap
Definition: DenseMap.h:716
llvm::AnalysisKey
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:69
llvm::ISD::BasicBlock
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::AnalysisInfoMixin
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:394
llvm::MachineFunction
Definition: MachineFunction.h:241
llvm::MachineModuleInfoWrapperPass::doInitialization
bool doInitialization(Module &) override
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
Definition: MachineModuleInfo.cpp:221
llvm::MachineModuleInfo::getOrCreateMachineFunction
MachineFunction & getOrCreateMachineFunction(Function &F)
Returns the MachineFunction constructed for the IR function F.
Definition: MachineModuleInfo.cpp:108
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
llvm::MachineModuleInfoWrapperPass::ID
static char ID
Definition: MachineModuleInfo.h:219
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:103
PassManager.h
llvm::MachineModuleInfoWrapperPass::MachineModuleInfoWrapperPass
MachineModuleInfoWrapperPass(const LLVMTargetMachine *TM=nullptr)
Definition: MachineModuleInfo.cpp:179
llvm::LLVMTargetMachine
This class describes a target machine that is implemented with the LLVM target-independent code gener...
Definition: TargetMachine.h:405
llvm::MachineModuleInfo::getContext
MCContext & getContext()
Definition: MachineModuleInfo.h:147
llvm::PointerIntPair
PointerIntPair - This class implements a pair of a pointer and small integer.
Definition: PointerIntPair.h:46
llvm::MachineModuleInfo::addPersonality
void addPersonality(const Function *Personality)
Provide the personality function for the exception information.
Definition: MachineModuleInfo.cpp:95
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:42
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::MachineModuleInfo::finalize
void finalize()
Definition: MachineModuleInfo.cpp:49
llvm::MachineModuleInfo::getModule
const Module * getModule() const
Definition: MachineModuleInfo.h:151
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:171
llvm::codeview::PublicSymFlags::Function
@ Function
llvm::ISD::MCSymbol
@ MCSymbol
Definition: ISDOpcodes.h:172
llvm::MachineModuleInfo::usesMSVCFloatingPoint
bool usesMSVCFloatingPoint() const
Definition: MachineModuleInfo.h:185