/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/include/llvm/CodeGen/MachineFunction.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===- llvm/CodeGen/MachineFunction.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 native machine code for a function. This class contains a list of |
11 | | // MachineBasicBlock instances that make up the current compiled function. |
12 | | // |
13 | | // This class also contains pointers to various classes which hold |
14 | | // target-specific information about the generated code. |
15 | | // |
16 | | //===----------------------------------------------------------------------===// |
17 | | |
18 | | #ifndef LLVM_CODEGEN_MACHINEFUNCTION_H |
19 | | #define LLVM_CODEGEN_MACHINEFUNCTION_H |
20 | | |
21 | | #include "llvm/ADT/ArrayRef.h" |
22 | | #include "llvm/ADT/BitVector.h" |
23 | | #include "llvm/ADT/DenseMap.h" |
24 | | #include "llvm/ADT/GraphTraits.h" |
25 | | #include "llvm/ADT/Optional.h" |
26 | | #include "llvm/ADT/SmallVector.h" |
27 | | #include "llvm/ADT/StringRef.h" |
28 | | #include "llvm/ADT/ilist.h" |
29 | | #include "llvm/ADT/iterator.h" |
30 | | #include "llvm/Analysis/EHPersonalities.h" |
31 | | #include "llvm/CodeGen/MachineBasicBlock.h" |
32 | | #include "llvm/CodeGen/MachineInstr.h" |
33 | | #include "llvm/CodeGen/MachineMemOperand.h" |
34 | | #include "llvm/IR/DebugLoc.h" |
35 | | #include "llvm/IR/Instructions.h" |
36 | | #include "llvm/IR/Metadata.h" |
37 | | #include "llvm/MC/MCDwarf.h" |
38 | | #include "llvm/MC/MCSymbol.h" |
39 | | #include "llvm/Support/Allocator.h" |
40 | | #include "llvm/Support/ArrayRecycler.h" |
41 | | #include "llvm/Support/AtomicOrdering.h" |
42 | | #include "llvm/Support/Compiler.h" |
43 | | #include "llvm/Support/ErrorHandling.h" |
44 | | #include "llvm/Support/Recycler.h" |
45 | | #include <cassert> |
46 | | #include <cstdint> |
47 | | #include <memory> |
48 | | #include <utility> |
49 | | #include <vector> |
50 | | |
51 | | namespace llvm { |
52 | | |
53 | | class BasicBlock; |
54 | | class BlockAddress; |
55 | | class DataLayout; |
56 | | class DIExpression; |
57 | | class DILocalVariable; |
58 | | class DILocation; |
59 | | class Function; |
60 | | class GlobalValue; |
61 | | class MachineConstantPool; |
62 | | class MachineFrameInfo; |
63 | | class MachineFunction; |
64 | | class MachineJumpTableInfo; |
65 | | class MachineModuleInfo; |
66 | | class MachineRegisterInfo; |
67 | | class MCContext; |
68 | | class MCInstrDesc; |
69 | | class Pass; |
70 | | class PseudoSourceValueManager; |
71 | | class raw_ostream; |
72 | | class SlotIndexes; |
73 | | class TargetMachine; |
74 | | class TargetRegisterClass; |
75 | | class TargetSubtargetInfo; |
76 | | struct WinEHFuncInfo; |
77 | | |
78 | | template <> struct ilist_alloc_traits<MachineBasicBlock> { |
79 | | void deleteNode(MachineBasicBlock *MBB); |
80 | | }; |
81 | | |
82 | | template <> struct ilist_callback_traits<MachineBasicBlock> { |
83 | | void addNodeToList(MachineBasicBlock* MBB); |
84 | | void removeNodeFromList(MachineBasicBlock* MBB); |
85 | | |
86 | | template <class Iterator> |
87 | 0 | void transferNodesFromList(ilist_callback_traits &OldList, Iterator, Iterator) { |
88 | 0 | llvm_unreachable("Never transfer between lists"); |
89 | 0 | } |
90 | | }; |
91 | | |
92 | | /// MachineFunctionInfo - This class can be derived from and used by targets to |
93 | | /// hold private target-specific information for each MachineFunction. Objects |
94 | | /// of type are accessed/created with MF::getInfo and destroyed when the |
95 | | /// MachineFunction is destroyed. |
96 | | struct MachineFunctionInfo { |
97 | | virtual ~MachineFunctionInfo(); |
98 | | |
99 | | /// \brief Factory function: default behavior is to call new using the |
100 | | /// supplied allocator. |
101 | | /// |
102 | | /// This function can be overridden in a derive class. |
103 | | template<typename Ty> |
104 | 595k | static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) { |
105 | 595k | return new (Allocator.Allocate<Ty>()) Ty(MF); |
106 | 595k | } llvm::R600MachineFunctionInfo* llvm::MachineFunctionInfo::create<llvm::R600MachineFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&) Line | Count | Source | 104 | 2.06k | static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) { | 105 | 2.06k | return new (Allocator.Allocate<Ty>()) Ty(MF); | 106 | 2.06k | } |
llvm::XCoreFunctionInfo* llvm::MachineFunctionInfo::create<llvm::XCoreFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&) Line | Count | Source | 104 | 277 | static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) { | 105 | 277 | return new (Allocator.Allocate<Ty>()) Ty(MF); | 106 | 277 | } |
llvm::X86MachineFunctionInfo* llvm::MachineFunctionInfo::create<llvm::X86MachineFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&) Line | Count | Source | 104 | 73.7k | static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) { | 105 | 73.7k | return new (Allocator.Allocate<Ty>()) Ty(MF); | 106 | 73.7k | } |
llvm::SystemZMachineFunctionInfo* llvm::MachineFunctionInfo::create<llvm::SystemZMachineFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&) Line | Count | Source | 104 | 6.59k | static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) { | 105 | 6.59k | return new (Allocator.Allocate<Ty>()) Ty(MF); | 106 | 6.59k | } |
llvm::SparcMachineFunctionInfo* llvm::MachineFunctionInfo::create<llvm::SparcMachineFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&) Line | Count | Source | 104 | 645 | static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) { | 105 | 645 | return new (Allocator.Allocate<Ty>()) Ty(MF); | 106 | 645 | } |
llvm::PPCFunctionInfo* llvm::MachineFunctionInfo::create<llvm::PPCFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&) Line | Count | Source | 104 | 7.51k | static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) { | 105 | 7.51k | return new (Allocator.Allocate<Ty>()) Ty(MF); | 106 | 7.51k | } |
llvm::NVPTXMachineFunctionInfo* llvm::MachineFunctionInfo::create<llvm::NVPTXMachineFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&) Line | Count | Source | 104 | 17 | static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) { | 105 | 17 | return new (Allocator.Allocate<Ty>()) Ty(MF); | 106 | 17 | } |
llvm::MSP430MachineFunctionInfo* llvm::MachineFunctionInfo::create<llvm::MSP430MachineFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&) Line | Count | Source | 104 | 288 | static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) { | 105 | 288 | return new (Allocator.Allocate<Ty>()) Ty(MF); | 106 | 288 | } |
llvm::MipsFunctionInfo* llvm::MachineFunctionInfo::create<llvm::MipsFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&) Line | Count | Source | 104 | 12.3k | static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) { | 105 | 12.3k | return new (Allocator.Allocate<Ty>()) Ty(MF); | 106 | 12.3k | } |
llvm::LanaiMachineFunctionInfo* llvm::MachineFunctionInfo::create<llvm::LanaiMachineFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&) Line | Count | Source | 104 | 89 | static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) { | 105 | 89 | return new (Allocator.Allocate<Ty>()) Ty(MF); | 106 | 89 | } |
llvm::HexagonMachineFunctionInfo* llvm::MachineFunctionInfo::create<llvm::HexagonMachineFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&) Line | Count | Source | 104 | 2.41k | static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) { | 105 | 2.41k | return new (Allocator.Allocate<Ty>()) Ty(MF); | 106 | 2.41k | } |
llvm::ARMFunctionInfo* llvm::MachineFunctionInfo::create<llvm::ARMFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&) Line | Count | Source | 104 | 17.5k | static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) { | 105 | 17.5k | return new (Allocator.Allocate<Ty>()) Ty(MF); | 106 | 17.5k | } |
llvm::AArch64FunctionInfo* llvm::MachineFunctionInfo::create<llvm::AArch64FunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&) Line | Count | Source | 104 | 456k | static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) { | 105 | 456k | return new (Allocator.Allocate<Ty>()) Ty(MF); | 106 | 456k | } |
llvm::SIMachineFunctionInfo* llvm::MachineFunctionInfo::create<llvm::SIMachineFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&) Line | Count | Source | 104 | 15.3k | static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) { | 105 | 15.3k | return new (Allocator.Allocate<Ty>()) Ty(MF); | 106 | 15.3k | } |
Unexecuted instantiation: llvm::AMDGPUMachineFunction* llvm::MachineFunctionInfo::create<llvm::AMDGPUMachineFunction>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&) |
107 | | }; |
108 | | |
109 | | /// Properties which a MachineFunction may have at a given point in time. |
110 | | /// Each of these has checking code in the MachineVerifier, and passes can |
111 | | /// require that a property be set. |
112 | | class MachineFunctionProperties { |
113 | | // Possible TODO: Allow targets to extend this (perhaps by allowing the |
114 | | // constructor to specify the size of the bit vector) |
115 | | // Possible TODO: Allow requiring the negative (e.g. VRegsAllocated could be |
116 | | // stated as the negative of "has vregs" |
117 | | |
118 | | public: |
119 | | // The properties are stated in "positive" form; i.e. a pass could require |
120 | | // that the property hold, but not that it does not hold. |
121 | | |
122 | | // Property descriptions: |
123 | | // IsSSA: True when the machine function is in SSA form and virtual registers |
124 | | // have a single def. |
125 | | // NoPHIs: The machine function does not contain any PHI instruction. |
126 | | // TracksLiveness: True when tracking register liveness accurately. |
127 | | // While this property is set, register liveness information in basic block |
128 | | // live-in lists and machine instruction operands (e.g. kill flags, implicit |
129 | | // defs) is accurate. This means it can be used to change the code in ways |
130 | | // that affect the values in registers, for example by the register |
131 | | // scavenger. |
132 | | // When this property is clear, liveness is no longer reliable. |
133 | | // NoVRegs: The machine function does not use any virtual registers. |
134 | | // Legalized: In GlobalISel: the MachineLegalizer ran and all pre-isel generic |
135 | | // instructions have been legalized; i.e., all instructions are now one of: |
136 | | // - generic and always legal (e.g., COPY) |
137 | | // - target-specific |
138 | | // - legal pre-isel generic instructions. |
139 | | // RegBankSelected: In GlobalISel: the RegBankSelect pass ran and all generic |
140 | | // virtual registers have been assigned to a register bank. |
141 | | // Selected: In GlobalISel: the InstructionSelect pass ran and all pre-isel |
142 | | // generic instructions have been eliminated; i.e., all instructions are now |
143 | | // target-specific or non-pre-isel generic instructions (e.g., COPY). |
144 | | // Since only pre-isel generic instructions can have generic virtual register |
145 | | // operands, this also means that all generic virtual registers have been |
146 | | // constrained to virtual registers (assigned to register classes) and that |
147 | | // all sizes attached to them have been eliminated. |
148 | | enum class Property : unsigned { |
149 | | IsSSA, |
150 | | NoPHIs, |
151 | | TracksLiveness, |
152 | | NoVRegs, |
153 | | FailedISel, |
154 | | Legalized, |
155 | | RegBankSelected, |
156 | | Selected, |
157 | | LastProperty = Selected, |
158 | | }; |
159 | | |
160 | 122M | bool hasProperty(Property P) const { |
161 | 122M | return Properties[static_cast<unsigned>(P)]; |
162 | 122M | } |
163 | | |
164 | 2.98M | MachineFunctionProperties &set(Property P) { |
165 | 2.98M | Properties.set(static_cast<unsigned>(P)); |
166 | 2.98M | return *this; |
167 | 2.98M | } |
168 | | |
169 | 1.22M | MachineFunctionProperties &reset(Property P) { |
170 | 1.22M | Properties.reset(static_cast<unsigned>(P)); |
171 | 1.22M | return *this; |
172 | 1.22M | } |
173 | | |
174 | | /// Reset all the properties. |
175 | 661k | MachineFunctionProperties &reset() { |
176 | 661k | Properties.reset(); |
177 | 661k | return *this; |
178 | 661k | } |
179 | | |
180 | 56.7M | MachineFunctionProperties &set(const MachineFunctionProperties &MFP) { |
181 | 56.7M | Properties |= MFP.Properties; |
182 | 56.7M | return *this; |
183 | 56.7M | } |
184 | | |
185 | 56.7M | MachineFunctionProperties &reset(const MachineFunctionProperties &MFP) { |
186 | 56.7M | Properties.reset(MFP.Properties); |
187 | 56.7M | return *this; |
188 | 56.7M | } |
189 | | |
190 | | // Returns true if all properties set in V (i.e. required by a pass) are set |
191 | | // in this. |
192 | 0 | bool verifyRequiredProperties(const MachineFunctionProperties &V) const { |
193 | 0 | return !V.Properties.test(Properties); |
194 | 0 | } |
195 | | |
196 | | /// Print the MachineFunctionProperties in human-readable form. |
197 | | void print(raw_ostream &OS) const; |
198 | | |
199 | | private: |
200 | | BitVector Properties = |
201 | | BitVector(static_cast<unsigned>(Property::LastProperty)+1); |
202 | | }; |
203 | | |
204 | | struct SEHHandler { |
205 | | /// Filter or finally function. Null indicates a catch-all. |
206 | | const Function *FilterOrFinally; |
207 | | |
208 | | /// Address of block to recover at. Null for a finally handler. |
209 | | const BlockAddress *RecoverBA; |
210 | | }; |
211 | | |
212 | | /// This structure is used to retain landing pad info for the current function. |
213 | | struct LandingPadInfo { |
214 | | MachineBasicBlock *LandingPadBlock; // Landing pad block. |
215 | | SmallVector<MCSymbol *, 1> BeginLabels; // Labels prior to invoke. |
216 | | SmallVector<MCSymbol *, 1> EndLabels; // Labels after invoke. |
217 | | SmallVector<SEHHandler, 1> SEHHandlers; // SEH handlers active at this lpad. |
218 | | MCSymbol *LandingPadLabel = nullptr; // Label at beginning of landing pad. |
219 | | std::vector<int> TypeIds; // List of type ids (filters negative). |
220 | | |
221 | | explicit LandingPadInfo(MachineBasicBlock *MBB) |
222 | 18.6k | : LandingPadBlock(MBB) {} |
223 | | }; |
224 | | |
225 | | class MachineFunction { |
226 | | const Function *Fn; |
227 | | const TargetMachine &Target; |
228 | | const TargetSubtargetInfo *STI; |
229 | | MCContext &Ctx; |
230 | | MachineModuleInfo &MMI; |
231 | | |
232 | | // RegInfo - Information about each register in use in the function. |
233 | | MachineRegisterInfo *RegInfo; |
234 | | |
235 | | // Used to keep track of target-specific per-machine function information for |
236 | | // the target implementation. |
237 | | MachineFunctionInfo *MFInfo; |
238 | | |
239 | | // Keep track of objects allocated on the stack. |
240 | | MachineFrameInfo *FrameInfo; |
241 | | |
242 | | // Keep track of constants which are spilled to memory |
243 | | MachineConstantPool *ConstantPool; |
244 | | |
245 | | // Keep track of jump tables for switch instructions |
246 | | MachineJumpTableInfo *JumpTableInfo; |
247 | | |
248 | | // Keeps track of Windows exception handling related data. This will be null |
249 | | // for functions that aren't using a funclet-based EH personality. |
250 | | WinEHFuncInfo *WinEHInfo = nullptr; |
251 | | |
252 | | // Function-level unique numbering for MachineBasicBlocks. When a |
253 | | // MachineBasicBlock is inserted into a MachineFunction is it automatically |
254 | | // numbered and this vector keeps track of the mapping from ID's to MBB's. |
255 | | std::vector<MachineBasicBlock*> MBBNumbering; |
256 | | |
257 | | // Pool-allocate MachineFunction-lifetime and IR objects. |
258 | | BumpPtrAllocator Allocator; |
259 | | |
260 | | // Allocation management for instructions in function. |
261 | | Recycler<MachineInstr> InstructionRecycler; |
262 | | |
263 | | // Allocation management for operand arrays on instructions. |
264 | | ArrayRecycler<MachineOperand> OperandRecycler; |
265 | | |
266 | | // Allocation management for basic blocks in function. |
267 | | Recycler<MachineBasicBlock> BasicBlockRecycler; |
268 | | |
269 | | // List of machine basic blocks in function |
270 | | using BasicBlockListType = ilist<MachineBasicBlock>; |
271 | | BasicBlockListType BasicBlocks; |
272 | | |
273 | | /// FunctionNumber - This provides a unique ID for each function emitted in |
274 | | /// this translation unit. |
275 | | /// |
276 | | unsigned FunctionNumber; |
277 | | |
278 | | /// Alignment - The alignment of the function. |
279 | | unsigned Alignment; |
280 | | |
281 | | /// ExposesReturnsTwice - True if the function calls setjmp or related |
282 | | /// functions with attribute "returns twice", but doesn't have |
283 | | /// the attribute itself. |
284 | | /// This is used to limit optimizations which cannot reason |
285 | | /// about the control flow of such functions. |
286 | | bool ExposesReturnsTwice = false; |
287 | | |
288 | | /// True if the function includes any inline assembly. |
289 | | bool HasInlineAsm = false; |
290 | | |
291 | | /// True if any WinCFI instruction have been emitted in this function. |
292 | | Optional<bool> HasWinCFI; |
293 | | |
294 | | /// Current high-level properties of the IR of the function (e.g. is in SSA |
295 | | /// form or whether registers have been allocated) |
296 | | MachineFunctionProperties Properties; |
297 | | |
298 | | // Allocation management for pseudo source values. |
299 | | std::unique_ptr<PseudoSourceValueManager> PSVManager; |
300 | | |
301 | | /// List of moves done by a function's prolog. Used to construct frame maps |
302 | | /// by debug and exception handling consumers. |
303 | | std::vector<MCCFIInstruction> FrameInstructions; |
304 | | |
305 | | /// \name Exception Handling |
306 | | /// \{ |
307 | | |
308 | | /// List of LandingPadInfo describing the landing pad information. |
309 | | std::vector<LandingPadInfo> LandingPads; |
310 | | |
311 | | /// Map a landing pad's EH symbol to the call site indexes. |
312 | | DenseMap<MCSymbol*, SmallVector<unsigned, 4>> LPadToCallSiteMap; |
313 | | |
314 | | /// Map of invoke call site index values to associated begin EH_LABEL. |
315 | | DenseMap<MCSymbol*, unsigned> CallSiteMap; |
316 | | |
317 | | /// CodeView label annotations. |
318 | | std::vector<std::pair<MCSymbol *, MDNode *>> CodeViewAnnotations; |
319 | | |
320 | | bool CallsEHReturn = false; |
321 | | bool CallsUnwindInit = false; |
322 | | bool HasEHFunclets = false; |
323 | | |
324 | | /// List of C++ TypeInfo used. |
325 | | std::vector<const GlobalValue *> TypeInfos; |
326 | | |
327 | | /// List of typeids encoding filters used. |
328 | | std::vector<unsigned> FilterIds; |
329 | | |
330 | | /// List of the indices in FilterIds corresponding to filter terminators. |
331 | | std::vector<unsigned> FilterEnds; |
332 | | |
333 | | EHPersonality PersonalityTypeCache = EHPersonality::Unknown; |
334 | | |
335 | | /// \} |
336 | | |
337 | | /// Clear all the members of this MachineFunction, but the ones used |
338 | | /// to initialize again the MachineFunction. |
339 | | /// More specifically, this deallocates all the dynamically allocated |
340 | | /// objects and get rid of all the XXXInfo data structure, but keep |
341 | | /// unchanged the references to Fn, Target, MMI, and FunctionNumber. |
342 | | void clear(); |
343 | | /// Allocate and initialize the different members. |
344 | | /// In particular, the XXXInfo data structure. |
345 | | /// \pre Fn, Target, MMI, and FunctionNumber are properly set. |
346 | | void init(); |
347 | | |
348 | | public: |
349 | | struct VariableDbgInfo { |
350 | | const DILocalVariable *Var; |
351 | | const DIExpression *Expr; |
352 | | unsigned Slot; |
353 | | const DILocation *Loc; |
354 | | |
355 | | VariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr, |
356 | | unsigned Slot, const DILocation *Loc) |
357 | 637 | : Var(Var), Expr(Expr), Slot(Slot), Loc(Loc) {} |
358 | | }; |
359 | | using VariableDbgInfoMapTy = SmallVector<VariableDbgInfo, 4>; |
360 | | VariableDbgInfoMapTy VariableDbgInfos; |
361 | | |
362 | | MachineFunction(const Function *Fn, const TargetMachine &TM, |
363 | | unsigned FunctionNum, MachineModuleInfo &MMI); |
364 | | MachineFunction(const MachineFunction &) = delete; |
365 | | MachineFunction &operator=(const MachineFunction &) = delete; |
366 | | ~MachineFunction(); |
367 | | |
368 | | /// Reset the instance as if it was just created. |
369 | 63.6k | void reset() { |
370 | 63.6k | clear(); |
371 | 63.6k | init(); |
372 | 63.6k | } |
373 | | |
374 | 7.14M | MachineModuleInfo &getMMI() const { return MMI; } |
375 | 2.79M | MCContext &getContext() const { return Ctx; } |
376 | | |
377 | 5.28M | PseudoSourceValueManager &getPSVManager() const { return *PSVManager; } |
378 | | |
379 | | /// Return the DataLayout attached to the Module associated to this MF. |
380 | | const DataLayout &getDataLayout() const; |
381 | | |
382 | | /// getFunction - Return the LLVM function that this machine code represents |
383 | 148M | const Function *getFunction() const { return Fn; } |
384 | | |
385 | | /// getName - Return the name of the corresponding LLVM function. |
386 | | StringRef getName() const; |
387 | | |
388 | | /// getFunctionNumber - Return a unique ID for the current function. |
389 | 2.20M | unsigned getFunctionNumber() const { return FunctionNumber; } |
390 | | |
391 | | /// getTarget - Return the target machine this machine code is compiled with |
392 | 58.5M | const TargetMachine &getTarget() const { return Target; } |
393 | | |
394 | | /// getSubtarget - Return the subtarget for which this machine code is being |
395 | | /// compiled. |
396 | 546M | const TargetSubtargetInfo &getSubtarget() const { return *STI; } |
397 | 12.3k | void setSubtarget(const TargetSubtargetInfo *ST) { STI = ST; } |
398 | | |
399 | | /// getSubtarget - This method returns a pointer to the specified type of |
400 | | /// TargetSubtargetInfo. In debug builds, it verifies that the object being |
401 | | /// returned is of the correct type. |
402 | 86.7M | template<typename STC> const STC &getSubtarget() const { |
403 | 86.7M | return *static_cast<const STC *>(STI); |
404 | 86.7M | } llvm::AMDGPUSubtarget const& llvm::MachineFunction::getSubtarget<llvm::AMDGPUSubtarget>() const Line | Count | Source | 402 | 451k | template<typename STC> const STC &getSubtarget() const { | 403 | 451k | return *static_cast<const STC *>(STI); | 404 | 451k | } |
llvm::ARMSubtarget const& llvm::MachineFunction::getSubtarget<llvm::ARMSubtarget>() const Line | Count | Source | 402 | 4.82M | template<typename STC> const STC &getSubtarget() const { | 403 | 4.82M | return *static_cast<const STC *>(STI); | 404 | 4.82M | } |
llvm::HexagonSubtarget const& llvm::MachineFunction::getSubtarget<llvm::HexagonSubtarget>() const Line | Count | Source | 402 | 476k | template<typename STC> const STC &getSubtarget() const { | 403 | 476k | return *static_cast<const STC *>(STI); | 404 | 476k | } |
llvm::LanaiSubtarget const& llvm::MachineFunction::getSubtarget<llvm::LanaiSubtarget>() const Line | Count | Source | 402 | 177 | template<typename STC> const STC &getSubtarget() const { | 403 | 177 | return *static_cast<const STC *>(STI); | 404 | 177 | } |
llvm::MipsSubtarget const& llvm::MachineFunction::getSubtarget<llvm::MipsSubtarget>() const Line | Count | Source | 402 | 282k | template<typename STC> const STC &getSubtarget() const { | 403 | 282k | return *static_cast<const STC *>(STI); | 404 | 282k | } |
llvm::NVPTXSubtarget const& llvm::MachineFunction::getSubtarget<llvm::NVPTXSubtarget>() const Line | Count | Source | 402 | 1.49k | template<typename STC> const STC &getSubtarget() const { | 403 | 1.49k | return *static_cast<const STC *>(STI); | 404 | 1.49k | } |
llvm::PPCSubtarget const& llvm::MachineFunction::getSubtarget<llvm::PPCSubtarget>() const Line | Count | Source | 402 | 381k | template<typename STC> const STC &getSubtarget() const { | 403 | 381k | return *static_cast<const STC *>(STI); | 404 | 381k | } |
llvm::SparcSubtarget const& llvm::MachineFunction::getSubtarget<llvm::SparcSubtarget>() const Line | Count | Source | 402 | 12.8k | template<typename STC> const STC &getSubtarget() const { | 403 | 12.8k | return *static_cast<const STC *>(STI); | 404 | 12.8k | } |
llvm::SystemZSubtarget const& llvm::MachineFunction::getSubtarget<llvm::SystemZSubtarget>() const Line | Count | Source | 402 | 13.1k | template<typename STC> const STC &getSubtarget() const { | 403 | 13.1k | return *static_cast<const STC *>(STI); | 404 | 13.1k | } |
llvm::X86Subtarget const& llvm::MachineFunction::getSubtarget<llvm::X86Subtarget>() const Line | Count | Source | 402 | 3.53M | template<typename STC> const STC &getSubtarget() const { | 403 | 3.53M | return *static_cast<const STC *>(STI); | 404 | 3.53M | } |
llvm::XCoreSubtarget const& llvm::MachineFunction::getSubtarget<llvm::XCoreSubtarget>() const Line | Count | Source | 402 | 738 | template<typename STC> const STC &getSubtarget() const { | 403 | 738 | return *static_cast<const STC *>(STI); | 404 | 738 | } |
llvm::TargetSubtargetInfo const& llvm::MachineFunction::getSubtarget<llvm::TargetSubtargetInfo>() const Line | Count | Source | 402 | 113 | template<typename STC> const STC &getSubtarget() const { | 403 | 113 | return *static_cast<const STC *>(STI); | 404 | 113 | } |
llvm::AArch64Subtarget const& llvm::MachineFunction::getSubtarget<llvm::AArch64Subtarget>() const Line | Count | Source | 402 | 49.0M | template<typename STC> const STC &getSubtarget() const { | 403 | 49.0M | return *static_cast<const STC *>(STI); | 404 | 49.0M | } |
llvm::SISubtarget const& llvm::MachineFunction::getSubtarget<llvm::SISubtarget>() const Line | Count | Source | 402 | 1.10M | template<typename STC> const STC &getSubtarget() const { | 403 | 1.10M | return *static_cast<const STC *>(STI); | 404 | 1.10M | } |
llvm::MCSubtargetInfo const& llvm::MachineFunction::getSubtarget<llvm::MCSubtargetInfo>() const Line | Count | Source | 402 | 26.5M | template<typename STC> const STC &getSubtarget() const { | 403 | 26.5M | return *static_cast<const STC *>(STI); | 404 | 26.5M | } |
llvm::R600Subtarget const& llvm::MachineFunction::getSubtarget<llvm::R600Subtarget>() const Line | Count | Source | 402 | 29.9k | template<typename STC> const STC &getSubtarget() const { | 403 | 29.9k | return *static_cast<const STC *>(STI); | 404 | 29.9k | } |
|
405 | | |
406 | | /// getRegInfo - Return information about the registers currently in use. |
407 | 458M | MachineRegisterInfo &getRegInfo() { return *RegInfo; } |
408 | 111M | const MachineRegisterInfo &getRegInfo() const { return *RegInfo; } |
409 | | |
410 | | /// getFrameInfo - Return the frame info object for the current function. |
411 | | /// This object contains information about objects allocated on the stack |
412 | | /// frame of the current function in an abstract way. |
413 | 27.4M | MachineFrameInfo &getFrameInfo() { return *FrameInfo; } |
414 | 74.6M | const MachineFrameInfo &getFrameInfo() const { return *FrameInfo; } |
415 | | |
416 | | /// getJumpTableInfo - Return the jump table info object for the current |
417 | | /// function. This object contains information about jump tables in the |
418 | | /// current function. If the current function has no jump tables, this will |
419 | | /// return null. |
420 | 598k | const MachineJumpTableInfo *getJumpTableInfo() const { return JumpTableInfo; } |
421 | 1.17M | MachineJumpTableInfo *getJumpTableInfo() { return JumpTableInfo; } |
422 | | |
423 | | /// getOrCreateJumpTableInfo - Get the JumpTableInfo for this function, if it |
424 | | /// does already exist, allocate one. |
425 | | MachineJumpTableInfo *getOrCreateJumpTableInfo(unsigned JTEntryKind); |
426 | | |
427 | | /// getConstantPool - Return the constant pool object for the current |
428 | | /// function. |
429 | 243k | MachineConstantPool *getConstantPool() { return ConstantPool; } |
430 | 589k | const MachineConstantPool *getConstantPool() const { return ConstantPool; } |
431 | | |
432 | | /// getWinEHFuncInfo - Return information about how the current function uses |
433 | | /// Windows exception handling. Returns null for functions that don't use |
434 | | /// funclets for exception handling. |
435 | 143 | const WinEHFuncInfo *getWinEHFuncInfo() const { return WinEHInfo; } |
436 | 698k | WinEHFuncInfo *getWinEHFuncInfo() { return WinEHInfo; } |
437 | | |
438 | | /// getAlignment - Return the alignment (log2, not bytes) of the function. |
439 | 624k | unsigned getAlignment() const { return Alignment; } |
440 | | |
441 | | /// setAlignment - Set the alignment (log2, not bytes) of the function. |
442 | 17.9k | void setAlignment(unsigned A) { Alignment = A; } |
443 | | |
444 | | /// ensureAlignment - Make sure the function is at least 1 << A bytes aligned. |
445 | 2.19k | void ensureAlignment(unsigned A) { |
446 | 2.19k | if (Alignment < A2.19k ) Alignment = A1.62k ; |
447 | 2.19k | } |
448 | | |
449 | | /// exposesReturnsTwice - Returns true if the function calls setjmp or |
450 | | /// any other similar functions with attribute "returns twice" without |
451 | | /// having the attribute itself. |
452 | 29.2k | bool exposesReturnsTwice() const { |
453 | 29.2k | return ExposesReturnsTwice; |
454 | 29.2k | } |
455 | | |
456 | | /// setCallsSetJmp - Set a flag that indicates if there's a call to |
457 | | /// a "returns twice" function. |
458 | 439k | void setExposesReturnsTwice(bool B) { |
459 | 439k | ExposesReturnsTwice = B; |
460 | 439k | } |
461 | | |
462 | | /// Returns true if the function contains any inline assembly. |
463 | 2.17M | bool hasInlineAsm() const { |
464 | 2.17M | return HasInlineAsm; |
465 | 2.17M | } |
466 | | |
467 | | /// Set a flag that indicates that the function contains inline assembly. |
468 | 450k | void setHasInlineAsm(bool B) { |
469 | 450k | HasInlineAsm = B; |
470 | 450k | } |
471 | | |
472 | 1.06k | bool hasWinCFI() const { |
473 | 1.06k | assert(HasWinCFI.hasValue() && "HasWinCFI not set yet!"); |
474 | 1.06k | return *HasWinCFI; |
475 | 1.06k | } |
476 | 145k | void setHasWinCFI(bool v) { HasWinCFI = v; } |
477 | | |
478 | | /// Get the function properties |
479 | 2.68M | const MachineFunctionProperties &getProperties() const { return Properties; } |
480 | 178M | MachineFunctionProperties &getProperties() { return Properties; } |
481 | | |
482 | | /// getInfo - Keep track of various per-function pieces of information for |
483 | | /// backends that would like to do so. |
484 | | /// |
485 | | template<typename Ty> |
486 | 11.6M | Ty *getInfo() { |
487 | 11.6M | if (!MFInfo) |
488 | 595k | MFInfo = Ty::template create<Ty>(Allocator, *this); |
489 | 11.6M | return static_cast<Ty*>(MFInfo); |
490 | 11.6M | } llvm::XCoreFunctionInfo* llvm::MachineFunction::getInfo<llvm::XCoreFunctionInfo>() Line | Count | Source | 486 | 1.76k | Ty *getInfo() { | 487 | 1.76k | if (!MFInfo) | 488 | 277 | MFInfo = Ty::template create<Ty>(Allocator, *this); | 489 | 1.76k | return static_cast<Ty*>(MFInfo); | 490 | 1.76k | } |
llvm::AMDGPUMachineFunction* llvm::MachineFunction::getInfo<llvm::AMDGPUMachineFunction>() Line | Count | Source | 486 | 71.5k | Ty *getInfo() { | 487 | 71.5k | if (!MFInfo) | 488 | 0 | MFInfo = Ty::template create<Ty>(Allocator, *this); | 489 | 71.5k | return static_cast<Ty*>(MFInfo); | 490 | 71.5k | } |
llvm::X86MachineFunctionInfo* llvm::MachineFunction::getInfo<llvm::X86MachineFunctionInfo>() Line | Count | Source | 486 | 1.76M | Ty *getInfo() { | 487 | 1.76M | if (!MFInfo) | 488 | 73.7k | MFInfo = Ty::template create<Ty>(Allocator, *this); | 489 | 1.76M | return static_cast<Ty*>(MFInfo); | 490 | 1.76M | } |
llvm::SystemZMachineFunctionInfo* llvm::MachineFunction::getInfo<llvm::SystemZMachineFunctionInfo>() Line | Count | Source | 486 | 70.4k | Ty *getInfo() { | 487 | 70.4k | if (!MFInfo) | 488 | 6.59k | MFInfo = Ty::template create<Ty>(Allocator, *this); | 489 | 70.4k | return static_cast<Ty*>(MFInfo); | 490 | 70.4k | } |
llvm::SparcMachineFunctionInfo* llvm::MachineFunction::getInfo<llvm::SparcMachineFunctionInfo>() Line | Count | Source | 486 | 3.54k | Ty *getInfo() { | 487 | 3.54k | if (!MFInfo) | 488 | 645 | MFInfo = Ty::template create<Ty>(Allocator, *this); | 489 | 3.54k | return static_cast<Ty*>(MFInfo); | 490 | 3.54k | } |
llvm::PPCFunctionInfo* llvm::MachineFunction::getInfo<llvm::PPCFunctionInfo>() Line | Count | Source | 486 | 272k | Ty *getInfo() { | 487 | 272k | if (!MFInfo) | 488 | 7.51k | MFInfo = Ty::template create<Ty>(Allocator, *this); | 489 | 272k | return static_cast<Ty*>(MFInfo); | 490 | 272k | } |
llvm::NVPTXMachineFunctionInfo* llvm::MachineFunction::getInfo<llvm::NVPTXMachineFunctionInfo>() Line | Count | Source | 486 | 29 | Ty *getInfo() { | 487 | 29 | if (!MFInfo) | 488 | 17 | MFInfo = Ty::template create<Ty>(Allocator, *this); | 489 | 29 | return static_cast<Ty*>(MFInfo); | 490 | 29 | } |
llvm::MSP430MachineFunctionInfo* llvm::MachineFunction::getInfo<llvm::MSP430MachineFunctionInfo>() Line | Count | Source | 486 | 886 | Ty *getInfo() { | 487 | 886 | if (!MFInfo) | 488 | 288 | MFInfo = Ty::template create<Ty>(Allocator, *this); | 489 | 886 | return static_cast<Ty*>(MFInfo); | 490 | 886 | } |
llvm::MipsFunctionInfo* llvm::MachineFunction::getInfo<llvm::MipsFunctionInfo>() Line | Count | Source | 486 | 115k | Ty *getInfo() { | 487 | 115k | if (!MFInfo) | 488 | 12.3k | MFInfo = Ty::template create<Ty>(Allocator, *this); | 489 | 115k | return static_cast<Ty*>(MFInfo); | 490 | 115k | } |
llvm::LanaiMachineFunctionInfo* llvm::MachineFunction::getInfo<llvm::LanaiMachineFunctionInfo>() Line | Count | Source | 486 | 89 | Ty *getInfo() { | 487 | 89 | if (!MFInfo) | 488 | 89 | MFInfo = Ty::template create<Ty>(Allocator, *this); | 489 | 89 | return static_cast<Ty*>(MFInfo); | 490 | 89 | } |
llvm::HexagonMachineFunctionInfo* llvm::MachineFunction::getInfo<llvm::HexagonMachineFunctionInfo>() Line | Count | Source | 486 | 35.1k | Ty *getInfo() { | 487 | 35.1k | if (!MFInfo) | 488 | 2.41k | MFInfo = Ty::template create<Ty>(Allocator, *this); | 489 | 35.1k | return static_cast<Ty*>(MFInfo); | 490 | 35.1k | } |
llvm::ARMFunctionInfo* llvm::MachineFunction::getInfo<llvm::ARMFunctionInfo>() Line | Count | Source | 486 | 771k | Ty *getInfo() { | 487 | 771k | if (!MFInfo) | 488 | 17.5k | MFInfo = Ty::template create<Ty>(Allocator, *this); | 489 | 771k | return static_cast<Ty*>(MFInfo); | 490 | 771k | } |
llvm::AArch64FunctionInfo* llvm::MachineFunction::getInfo<llvm::AArch64FunctionInfo>() Line | Count | Source | 486 | 7.49M | Ty *getInfo() { | 487 | 7.49M | if (!MFInfo) | 488 | 456k | MFInfo = Ty::template create<Ty>(Allocator, *this); | 489 | 7.49M | return static_cast<Ty*>(MFInfo); | 490 | 7.49M | } |
llvm::SIMachineFunctionInfo* llvm::MachineFunction::getInfo<llvm::SIMachineFunctionInfo>() Line | Count | Source | 486 | 912k | Ty *getInfo() { | 487 | 912k | if (!MFInfo) | 488 | 15.3k | MFInfo = Ty::template create<Ty>(Allocator, *this); | 489 | 912k | return static_cast<Ty*>(MFInfo); | 490 | 912k | } |
llvm::R600MachineFunctionInfo* llvm::MachineFunction::getInfo<llvm::R600MachineFunctionInfo>() Line | Count | Source | 486 | 108k | Ty *getInfo() { | 487 | 108k | if (!MFInfo) | 488 | 2.06k | MFInfo = Ty::template create<Ty>(Allocator, *this); | 489 | 108k | return static_cast<Ty*>(MFInfo); | 490 | 108k | } |
|
491 | | |
492 | | template<typename Ty> |
493 | 3.02M | const Ty *getInfo() const { |
494 | 3.02M | return const_cast<MachineFunction*>(this)->getInfo<Ty>(); |
495 | 3.02M | } llvm::X86MachineFunctionInfo const* llvm::MachineFunction::getInfo<llvm::X86MachineFunctionInfo>() const Line | Count | Source | 493 | 1.08M | const Ty *getInfo() const { | 494 | 1.08M | return const_cast<MachineFunction*>(this)->getInfo<Ty>(); | 495 | 1.08M | } |
llvm::SIMachineFunctionInfo const* llvm::MachineFunction::getInfo<llvm::SIMachineFunctionInfo>() const Line | Count | Source | 493 | 435k | const Ty *getInfo() const { | 494 | 435k | return const_cast<MachineFunction*>(this)->getInfo<Ty>(); | 495 | 435k | } |
llvm::AMDGPUMachineFunction const* llvm::MachineFunction::getInfo<llvm::AMDGPUMachineFunction>() const Line | Count | Source | 493 | 17.1k | const Ty *getInfo() const { | 494 | 17.1k | return const_cast<MachineFunction*>(this)->getInfo<Ty>(); | 495 | 17.1k | } |
llvm::R600MachineFunctionInfo const* llvm::MachineFunction::getInfo<llvm::R600MachineFunctionInfo>() const Line | Count | Source | 493 | 2.05k | const Ty *getInfo() const { | 494 | 2.05k | return const_cast<MachineFunction*>(this)->getInfo<Ty>(); | 495 | 2.05k | } |
llvm::ARMFunctionInfo const* llvm::MachineFunction::getInfo<llvm::ARMFunctionInfo>() const Line | Count | Source | 493 | 245k | const Ty *getInfo() const { | 494 | 245k | return const_cast<MachineFunction*>(this)->getInfo<Ty>(); | 495 | 245k | } |
llvm::HexagonMachineFunctionInfo const* llvm::MachineFunction::getInfo<llvm::HexagonMachineFunctionInfo>() const Line | Count | Source | 493 | 30.3k | const Ty *getInfo() const { | 494 | 30.3k | return const_cast<MachineFunction*>(this)->getInfo<Ty>(); | 495 | 30.3k | } |
llvm::MipsFunctionInfo const* llvm::MachineFunction::getInfo<llvm::MipsFunctionInfo>() const Line | Count | Source | 493 | 1.62k | const Ty *getInfo() const { | 494 | 1.62k | return const_cast<MachineFunction*>(this)->getInfo<Ty>(); | 495 | 1.62k | } |
llvm::NVPTXMachineFunctionInfo const* llvm::MachineFunction::getInfo<llvm::NVPTXMachineFunctionInfo>() const Line | Count | Source | 493 | 11 | const Ty *getInfo() const { | 494 | 11 | return const_cast<MachineFunction*>(this)->getInfo<Ty>(); | 495 | 11 | } |
llvm::PPCFunctionInfo const* llvm::MachineFunction::getInfo<llvm::PPCFunctionInfo>() const Line | Count | Source | 493 | 225k | const Ty *getInfo() const { | 494 | 225k | return const_cast<MachineFunction*>(this)->getInfo<Ty>(); | 495 | 225k | } |
llvm::SparcMachineFunctionInfo const* llvm::MachineFunction::getInfo<llvm::SparcMachineFunctionInfo>() const Line | Count | Source | 493 | 1.47k | const Ty *getInfo() const { | 494 | 1.47k | return const_cast<MachineFunction*>(this)->getInfo<Ty>(); | 495 | 1.47k | } |
llvm::SystemZMachineFunctionInfo const* llvm::MachineFunction::getInfo<llvm::SystemZMachineFunctionInfo>() const Line | Count | Source | 493 | 36.5k | const Ty *getInfo() const { | 494 | 36.5k | return const_cast<MachineFunction*>(this)->getInfo<Ty>(); | 495 | 36.5k | } |
llvm::AArch64FunctionInfo const* llvm::MachineFunction::getInfo<llvm::AArch64FunctionInfo>() const Line | Count | Source | 493 | 944k | const Ty *getInfo() const { | 494 | 944k | return const_cast<MachineFunction*>(this)->getInfo<Ty>(); | 495 | 944k | } |
|
496 | | |
497 | | /// getBlockNumbered - MachineBasicBlocks are automatically numbered when they |
498 | | /// are inserted into the machine function. The block number for a machine |
499 | | /// basic block can be found by using the MBB::getNumber method, this method |
500 | | /// provides the inverse mapping. |
501 | 151M | MachineBasicBlock *getBlockNumbered(unsigned N) const { |
502 | 151M | assert(N < MBBNumbering.size() && "Illegal block number"); |
503 | 151M | assert(MBBNumbering[N] && "Block was removed from the machine function!"); |
504 | 151M | return MBBNumbering[N]; |
505 | 151M | } |
506 | | |
507 | | /// Should we be emitting segmented stack stuff for the function |
508 | | bool shouldSplitStack() const; |
509 | | |
510 | | /// getNumBlockIDs - Return the number of MBB ID's allocated. |
511 | 54.9M | unsigned getNumBlockIDs() const { return (unsigned)MBBNumbering.size(); } |
512 | | |
513 | | /// RenumberBlocks - This discards all of the MachineBasicBlock numbers and |
514 | | /// recomputes them. This guarantees that the MBB numbers are sequential, |
515 | | /// dense, and match the ordering of the blocks within the function. If a |
516 | | /// specific MachineBasicBlock is specified, only that block and those after |
517 | | /// it are renumbered. |
518 | | void RenumberBlocks(MachineBasicBlock *MBBFrom = nullptr); |
519 | | |
520 | | /// print - Print out the MachineFunction in a format suitable for debugging |
521 | | /// to the specified stream. |
522 | | void print(raw_ostream &OS, const SlotIndexes* = nullptr) const; |
523 | | |
524 | | /// viewCFG - This function is meant for use from the debugger. You can just |
525 | | /// say 'call F->viewCFG()' and a ghostview window should pop up from the |
526 | | /// program, displaying the CFG of the current function with the code for each |
527 | | /// basic block inside. This depends on there being a 'dot' and 'gv' program |
528 | | /// in your path. |
529 | | void viewCFG() const; |
530 | | |
531 | | /// viewCFGOnly - This function is meant for use from the debugger. It works |
532 | | /// just like viewCFG, but it does not include the contents of basic blocks |
533 | | /// into the nodes, just the label. If you are only interested in the CFG |
534 | | /// this can make the graph smaller. |
535 | | /// |
536 | | void viewCFGOnly() const; |
537 | | |
538 | | /// dump - Print the current MachineFunction to cerr, useful for debugger use. |
539 | | void dump() const; |
540 | | |
541 | | /// Run the current MachineFunction through the machine code verifier, useful |
542 | | /// for debugger use. |
543 | | /// \returns true if no problems were found. |
544 | | bool verify(Pass *p = nullptr, const char *Banner = nullptr, |
545 | | bool AbortOnError = true) const; |
546 | | |
547 | | // Provide accessors for the MachineBasicBlock list... |
548 | | using iterator = BasicBlockListType::iterator; |
549 | | using const_iterator = BasicBlockListType::const_iterator; |
550 | | using const_reverse_iterator = BasicBlockListType::const_reverse_iterator; |
551 | | using reverse_iterator = BasicBlockListType::reverse_iterator; |
552 | | |
553 | | /// Support for MachineBasicBlock::getNextNode(). |
554 | | static BasicBlockListType MachineFunction::* |
555 | 26.3M | getSublistAccess(MachineBasicBlock *) { |
556 | 26.3M | return &MachineFunction::BasicBlocks; |
557 | 26.3M | } |
558 | | |
559 | | /// addLiveIn - Add the specified physical register as a live-in value and |
560 | | /// create a corresponding virtual register for it. |
561 | | unsigned addLiveIn(unsigned PReg, const TargetRegisterClass *RC); |
562 | | |
563 | | //===--------------------------------------------------------------------===// |
564 | | // BasicBlock accessor functions. |
565 | | // |
566 | 38.6M | iterator begin() { return BasicBlocks.begin(); } |
567 | 10.0M | const_iterator begin() const { return BasicBlocks.begin(); } |
568 | 147M | iterator end () { return BasicBlocks.end(); } |
569 | 8.52M | const_iterator end () const { return BasicBlocks.end(); } |
570 | | |
571 | 1.21M | reverse_iterator rbegin() { return BasicBlocks.rbegin(); } |
572 | 50 | const_reverse_iterator rbegin() const { return BasicBlocks.rbegin(); } |
573 | 1.21M | reverse_iterator rend () { return BasicBlocks.rend(); } |
574 | 0 | const_reverse_iterator rend () const { return BasicBlocks.rend(); } |
575 | | |
576 | 4.76M | unsigned size() const { return (unsigned)BasicBlocks.size();} |
577 | 6.06M | bool empty() const { return BasicBlocks.empty(); } |
578 | 6.45M | const MachineBasicBlock &front() const { return BasicBlocks.front(); } |
579 | 13.9M | MachineBasicBlock &front() { return BasicBlocks.front(); } |
580 | 65.6k | const MachineBasicBlock & back() const { return BasicBlocks.back(); } |
581 | 429k | MachineBasicBlock & back() { return BasicBlocks.back(); } |
582 | | |
583 | 5.26M | void push_back (MachineBasicBlock *MBB) { BasicBlocks.push_back (MBB); } |
584 | 272 | void push_front(MachineBasicBlock *MBB) { BasicBlocks.push_front(MBB); } |
585 | 729k | void insert(iterator MBBI, MachineBasicBlock *MBB) { |
586 | 729k | BasicBlocks.insert(MBBI, MBB); |
587 | 729k | } |
588 | 467k | void splice(iterator InsertPt, iterator MBBI) { |
589 | 467k | BasicBlocks.splice(InsertPt, BasicBlocks, MBBI); |
590 | 467k | } |
591 | 1.67M | void splice(iterator InsertPt, MachineBasicBlock *MBB) { |
592 | 1.67M | BasicBlocks.splice(InsertPt, BasicBlocks, MBB); |
593 | 1.67M | } |
594 | 0 | void splice(iterator InsertPt, iterator MBBI, iterator MBBE) { |
595 | 0 | BasicBlocks.splice(InsertPt, BasicBlocks, MBBI, MBBE); |
596 | 0 | } |
597 | | |
598 | 0 | void remove(iterator MBBI) { BasicBlocks.remove(MBBI); } |
599 | 221k | void remove(MachineBasicBlock *MBBI) { BasicBlocks.remove(MBBI); } |
600 | 50 | void erase(iterator MBBI) { BasicBlocks.erase(MBBI); } |
601 | 521k | void erase(MachineBasicBlock *MBBI) { BasicBlocks.erase(MBBI); } |
602 | | |
603 | | template <typename Comp> |
604 | 67 | void sort(Comp comp) { |
605 | 67 | BasicBlocks.sort(comp); |
606 | 67 | } |
607 | | |
608 | | //===--------------------------------------------------------------------===// |
609 | | // Internal functions used to automatically number MachineBasicBlocks |
610 | | |
611 | | /// \brief Adds the MBB to the internal numbering. Returns the unique number |
612 | | /// assigned to the MBB. |
613 | 5.99M | unsigned addToMBBNumbering(MachineBasicBlock *MBB) { |
614 | 5.99M | MBBNumbering.push_back(MBB); |
615 | 5.99M | return (unsigned)MBBNumbering.size()-1; |
616 | 5.99M | } |
617 | | |
618 | | /// removeFromMBBNumbering - Remove the specific machine basic block from our |
619 | | /// tracker, this is only really to be used by the MachineBasicBlock |
620 | | /// implementation. |
621 | 5.99M | void removeFromMBBNumbering(unsigned N) { |
622 | 5.99M | assert(N < MBBNumbering.size() && "Illegal basic block #"); |
623 | 5.99M | MBBNumbering[N] = nullptr; |
624 | 5.99M | } |
625 | | |
626 | | /// CreateMachineInstr - Allocate a new MachineInstr. Use this instead |
627 | | /// of `new MachineInstr'. |
628 | | MachineInstr *CreateMachineInstr(const MCInstrDesc &MCID, const DebugLoc &DL, |
629 | | bool NoImp = false); |
630 | | |
631 | | /// Create a new MachineInstr which is a copy of \p Orig, identical in all |
632 | | /// ways except the instruction has no parent, prev, or next. Bundling flags |
633 | | /// are reset. |
634 | | /// |
635 | | /// Note: Clones a single instruction, not whole instruction bundles. |
636 | | /// Does not perform target specific adjustments; consider using |
637 | | /// TargetInstrInfo::duplicate() instead. |
638 | | MachineInstr *CloneMachineInstr(const MachineInstr *Orig); |
639 | | |
640 | | /// Clones instruction or the whole instruction bundle \p Orig and insert |
641 | | /// into \p MBB before \p InsertBefore. |
642 | | /// |
643 | | /// Note: Does not perform target specific adjustments; consider using |
644 | | /// TargetInstrInfo::duplicate() intead. |
645 | | MachineInstr &CloneMachineInstrBundle(MachineBasicBlock &MBB, |
646 | | MachineBasicBlock::iterator InsertBefore, const MachineInstr &Orig); |
647 | | |
648 | | /// DeleteMachineInstr - Delete the given MachineInstr. |
649 | | void DeleteMachineInstr(MachineInstr *MI); |
650 | | |
651 | | /// CreateMachineBasicBlock - Allocate a new MachineBasicBlock. Use this |
652 | | /// instead of `new MachineBasicBlock'. |
653 | | MachineBasicBlock *CreateMachineBasicBlock(const BasicBlock *bb = nullptr); |
654 | | |
655 | | /// DeleteMachineBasicBlock - Delete the given MachineBasicBlock. |
656 | | void DeleteMachineBasicBlock(MachineBasicBlock *MBB); |
657 | | |
658 | | /// getMachineMemOperand - Allocate a new MachineMemOperand. |
659 | | /// MachineMemOperands are owned by the MachineFunction and need not be |
660 | | /// explicitly deallocated. |
661 | | MachineMemOperand *getMachineMemOperand( |
662 | | MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s, |
663 | | unsigned base_alignment, const AAMDNodes &AAInfo = AAMDNodes(), |
664 | | const MDNode *Ranges = nullptr, |
665 | | SyncScope::ID SSID = SyncScope::System, |
666 | | AtomicOrdering Ordering = AtomicOrdering::NotAtomic, |
667 | | AtomicOrdering FailureOrdering = AtomicOrdering::NotAtomic); |
668 | | |
669 | | /// getMachineMemOperand - Allocate a new MachineMemOperand by copying |
670 | | /// an existing one, adjusting by an offset and using the given size. |
671 | | /// MachineMemOperands are owned by the MachineFunction and need not be |
672 | | /// explicitly deallocated. |
673 | | MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO, |
674 | | int64_t Offset, uint64_t Size); |
675 | | |
676 | | /// Allocate a new MachineMemOperand by copying an existing one, |
677 | | /// replacing only AliasAnalysis information. MachineMemOperands are owned |
678 | | /// by the MachineFunction and need not be explicitly deallocated. |
679 | | MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO, |
680 | | const AAMDNodes &AAInfo); |
681 | | |
682 | | using OperandCapacity = ArrayRecycler<MachineOperand>::Capacity; |
683 | | |
684 | | /// Allocate an array of MachineOperands. This is only intended for use by |
685 | | /// internal MachineInstr functions. |
686 | 103M | MachineOperand *allocateOperandArray(OperandCapacity Cap) { |
687 | 103M | return OperandRecycler.allocate(Cap, Allocator); |
688 | 103M | } |
689 | | |
690 | | /// Dellocate an array of MachineOperands and recycle the memory. This is |
691 | | /// only intended for use by internal MachineInstr functions. |
692 | | /// Cap must be the same capacity that was used to allocate the array. |
693 | 63.8M | void deallocateOperandArray(OperandCapacity Cap, MachineOperand *Array) { |
694 | 63.8M | OperandRecycler.deallocate(Cap, Array); |
695 | 63.8M | } |
696 | | |
697 | | /// \brief Allocate and initialize a register mask with @p NumRegister bits. |
698 | 220 | uint32_t *allocateRegisterMask(unsigned NumRegister) { |
699 | 220 | unsigned Size = (NumRegister + 31) / 32; |
700 | 220 | uint32_t *Mask = Allocator.Allocate<uint32_t>(Size); |
701 | 2.42k | for (unsigned i = 0; i != Size2.42k ; ++i2.20k ) |
702 | 2.20k | Mask[i] = 0; |
703 | 220 | return Mask; |
704 | 220 | } |
705 | | |
706 | | /// allocateMemRefsArray - Allocate an array to hold MachineMemOperand |
707 | | /// pointers. This array is owned by the MachineFunction. |
708 | | MachineInstr::mmo_iterator allocateMemRefsArray(unsigned long Num); |
709 | | |
710 | | /// extractLoadMemRefs - Allocate an array and populate it with just the |
711 | | /// load information from the given MachineMemOperand sequence. |
712 | | std::pair<MachineInstr::mmo_iterator, |
713 | | MachineInstr::mmo_iterator> |
714 | | extractLoadMemRefs(MachineInstr::mmo_iterator Begin, |
715 | | MachineInstr::mmo_iterator End); |
716 | | |
717 | | /// extractStoreMemRefs - Allocate an array and populate it with just the |
718 | | /// store information from the given MachineMemOperand sequence. |
719 | | std::pair<MachineInstr::mmo_iterator, |
720 | | MachineInstr::mmo_iterator> |
721 | | extractStoreMemRefs(MachineInstr::mmo_iterator Begin, |
722 | | MachineInstr::mmo_iterator End); |
723 | | |
724 | | /// Allocate a string and populate it with the given external symbol name. |
725 | | const char *createExternalSymbolName(StringRef Name); |
726 | | |
727 | | //===--------------------------------------------------------------------===// |
728 | | // Label Manipulation. |
729 | | |
730 | | /// getJTISymbol - Return the MCSymbol for the specified non-empty jump table. |
731 | | /// If isLinkerPrivate is specified, an 'l' label is returned, otherwise a |
732 | | /// normal 'L' label is returned. |
733 | | MCSymbol *getJTISymbol(unsigned JTI, MCContext &Ctx, |
734 | | bool isLinkerPrivate = false) const; |
735 | | |
736 | | /// getPICBaseSymbol - Return a function-local symbol to represent the PIC |
737 | | /// base. |
738 | | MCSymbol *getPICBaseSymbol() const; |
739 | | |
740 | | /// Returns a reference to a list of cfi instructions in the function's |
741 | | /// prologue. Used to construct frame maps for debug and exception handling |
742 | | /// comsumers. |
743 | 330k | const std::vector<MCCFIInstruction> &getFrameInstructions() const { |
744 | 330k | return FrameInstructions; |
745 | 330k | } |
746 | | |
747 | 368k | LLVM_NODISCARD unsigned addFrameInst(const MCCFIInstruction &Inst) { |
748 | 368k | FrameInstructions.push_back(Inst); |
749 | 368k | return FrameInstructions.size() - 1; |
750 | 368k | } |
751 | | |
752 | | /// \name Exception Handling |
753 | | /// \{ |
754 | | |
755 | 1.62M | bool callsEHReturn() const { return CallsEHReturn; } |
756 | 29 | void setCallsEHReturn(bool b) { CallsEHReturn = b; } |
757 | | |
758 | 1.52M | bool callsUnwindInit() const { return CallsUnwindInit; } |
759 | 15 | void setCallsUnwindInit(bool b) { CallsUnwindInit = b; } |
760 | | |
761 | 4.38M | bool hasEHFunclets() const { return HasEHFunclets; } |
762 | 238 | void setHasEHFunclets(bool V) { HasEHFunclets = V; } |
763 | | |
764 | | /// Find or create an LandingPadInfo for the specified MachineBasicBlock. |
765 | | LandingPadInfo &getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad); |
766 | | |
767 | | /// Remap landing pad labels and remove any deleted landing pads. |
768 | | void tidyLandingPads(DenseMap<MCSymbol*, uintptr_t> *LPMap = nullptr); |
769 | | |
770 | | /// Return a reference to the landing pad info for the current function. |
771 | 2.38M | const std::vector<LandingPadInfo> &getLandingPads() const { |
772 | 2.38M | return LandingPads; |
773 | 2.38M | } |
774 | | |
775 | | /// Provide the begin and end labels of an invoke style call and associate it |
776 | | /// with a try landing pad block. |
777 | | void addInvoke(MachineBasicBlock *LandingPad, |
778 | | MCSymbol *BeginLabel, MCSymbol *EndLabel); |
779 | | |
780 | | /// Add a new panding pad. Returns the label ID for the landing pad entry. |
781 | | MCSymbol *addLandingPad(MachineBasicBlock *LandingPad); |
782 | | |
783 | | /// Provide the catch typeinfo for a landing pad. |
784 | | void addCatchTypeInfo(MachineBasicBlock *LandingPad, |
785 | | ArrayRef<const GlobalValue *> TyInfo); |
786 | | |
787 | | /// Provide the filter typeinfo for a landing pad. |
788 | | void addFilterTypeInfo(MachineBasicBlock *LandingPad, |
789 | | ArrayRef<const GlobalValue *> TyInfo); |
790 | | |
791 | | /// Add a cleanup action for a landing pad. |
792 | | void addCleanup(MachineBasicBlock *LandingPad); |
793 | | |
794 | | void addSEHCatchHandler(MachineBasicBlock *LandingPad, const Function *Filter, |
795 | | const BlockAddress *RecoverLabel); |
796 | | |
797 | | void addSEHCleanupHandler(MachineBasicBlock *LandingPad, |
798 | | const Function *Cleanup); |
799 | | |
800 | | /// Return the type id for the specified typeinfo. This is function wide. |
801 | | unsigned getTypeIDFor(const GlobalValue *TI); |
802 | | |
803 | | /// Return the id of the filter encoded by TyIds. This is function wide. |
804 | | int getFilterIDFor(std::vector<unsigned> &TyIds); |
805 | | |
806 | | /// Map the landing pad's EH symbol to the call site indexes. |
807 | | void setCallSiteLandingPad(MCSymbol *Sym, ArrayRef<unsigned> Sites); |
808 | | |
809 | | /// Get the call site indexes for a landing pad EH symbol. |
810 | 125 | SmallVectorImpl<unsigned> &getCallSiteLandingPad(MCSymbol *Sym) { |
811 | 125 | assert(hasCallSiteLandingPad(Sym) && |
812 | 125 | "missing call site number for landing pad!"); |
813 | 125 | return LPadToCallSiteMap[Sym]; |
814 | 125 | } |
815 | | |
816 | | /// Return true if the landing pad Eh symbol has an associated call site. |
817 | 125 | bool hasCallSiteLandingPad(MCSymbol *Sym) { |
818 | 125 | return !LPadToCallSiteMap[Sym].empty(); |
819 | 125 | } |
820 | | |
821 | | /// Map the begin label for a call site. |
822 | 169 | void setCallSiteBeginLabel(MCSymbol *BeginLabel, unsigned Site) { |
823 | 169 | CallSiteMap[BeginLabel] = Site; |
824 | 169 | } |
825 | | |
826 | | /// Get the call site number for a begin label. |
827 | 169 | unsigned getCallSiteBeginLabel(MCSymbol *BeginLabel) const { |
828 | 169 | assert(hasCallSiteBeginLabel(BeginLabel) && |
829 | 169 | "Missing call site number for EH_LABEL!"); |
830 | 169 | return CallSiteMap.lookup(BeginLabel); |
831 | 169 | } |
832 | | |
833 | | /// Return true if the begin label has a call site number associated with it. |
834 | 0 | bool hasCallSiteBeginLabel(MCSymbol *BeginLabel) const { |
835 | 0 | return CallSiteMap.count(BeginLabel); |
836 | 0 | } |
837 | | |
838 | | /// Record annotations associated with a particular label. |
839 | 1 | void addCodeViewAnnotation(MCSymbol *Label, MDNode *MD) { |
840 | 1 | CodeViewAnnotations.push_back({Label, MD}); |
841 | 1 | } |
842 | | |
843 | 132 | ArrayRef<std::pair<MCSymbol *, MDNode *>> getCodeViewAnnotations() const { |
844 | 132 | return CodeViewAnnotations; |
845 | 132 | } |
846 | | |
847 | | /// Return a reference to the C++ typeinfo for the current function. |
848 | 5.90k | const std::vector<const GlobalValue *> &getTypeInfos() const { |
849 | 5.90k | return TypeInfos; |
850 | 5.90k | } |
851 | | |
852 | | /// Return a reference to the typeids encoding filters used in the current |
853 | | /// function. |
854 | 8.85k | const std::vector<unsigned> &getFilterIds() const { |
855 | 8.85k | return FilterIds; |
856 | 8.85k | } |
857 | | |
858 | | /// \} |
859 | | |
860 | | /// Collect information used to emit debugging information of a variable. |
861 | | void setVariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr, |
862 | 637 | unsigned Slot, const DILocation *Loc) { |
863 | 637 | VariableDbgInfos.emplace_back(Var, Expr, Slot, Loc); |
864 | 637 | } |
865 | | |
866 | 466k | VariableDbgInfoMapTy &getVariableDbgInfo() { return VariableDbgInfos; } |
867 | 12.0k | const VariableDbgInfoMapTy &getVariableDbgInfo() const { |
868 | 12.0k | return VariableDbgInfos; |
869 | 12.0k | } |
870 | | }; |
871 | | |
872 | | /// \name Exception Handling |
873 | | /// \{ |
874 | | |
875 | | /// Extract the exception handling information from the landingpad instruction |
876 | | /// and add them to the specified machine module info. |
877 | | void addLandingPadInfo(const LandingPadInst &I, MachineBasicBlock &MBB); |
878 | | |
879 | | /// \} |
880 | | |
881 | | //===--------------------------------------------------------------------===// |
882 | | // GraphTraits specializations for function basic block graphs (CFGs) |
883 | | //===--------------------------------------------------------------------===// |
884 | | |
885 | | // Provide specializations of GraphTraits to be able to treat a |
886 | | // machine function as a graph of machine basic blocks... these are |
887 | | // the same as the machine basic block iterators, except that the root |
888 | | // node is implicitly the first node of the function. |
889 | | // |
890 | | template <> struct GraphTraits<MachineFunction*> : |
891 | | public GraphTraits<MachineBasicBlock*> { |
892 | 5.15M | static NodeRef getEntryNode(MachineFunction *F) { return &F->front(); } |
893 | | |
894 | | // nodes_iterator/begin/end - Allow iteration over all nodes in the graph |
895 | | using nodes_iterator = pointer_iterator<MachineFunction::iterator>; |
896 | | |
897 | 1.78M | static nodes_iterator nodes_begin(MachineFunction *F) { |
898 | 1.78M | return nodes_iterator(F->begin()); |
899 | 1.78M | } |
900 | | |
901 | 1.78M | static nodes_iterator nodes_end(MachineFunction *F) { |
902 | 1.78M | return nodes_iterator(F->end()); |
903 | 1.78M | } |
904 | | |
905 | 0 | static unsigned size (MachineFunction *F) { return F->size(); } |
906 | | }; |
907 | | template <> struct GraphTraits<const MachineFunction*> : |
908 | | public GraphTraits<const MachineBasicBlock*> { |
909 | 1.15M | static NodeRef getEntryNode(const MachineFunction *F) { return &F->front(); } |
910 | | |
911 | | // nodes_iterator/begin/end - Allow iteration over all nodes in the graph |
912 | | using nodes_iterator = pointer_iterator<MachineFunction::const_iterator>; |
913 | | |
914 | 0 | static nodes_iterator nodes_begin(const MachineFunction *F) { |
915 | 0 | return nodes_iterator(F->begin()); |
916 | 0 | } |
917 | | |
918 | 0 | static nodes_iterator nodes_end (const MachineFunction *F) { |
919 | 0 | return nodes_iterator(F->end()); |
920 | 0 | } |
921 | | |
922 | 0 | static unsigned size (const MachineFunction *F) { |
923 | 0 | return F->size(); |
924 | 0 | } |
925 | | }; |
926 | | |
927 | | // Provide specializations of GraphTraits to be able to treat a function as a |
928 | | // graph of basic blocks... and to walk it in inverse order. Inverse order for |
929 | | // a function is considered to be when traversing the predecessor edges of a BB |
930 | | // instead of the successor edges. |
931 | | // |
932 | | template <> struct GraphTraits<Inverse<MachineFunction*>> : |
933 | | public GraphTraits<Inverse<MachineBasicBlock*>> { |
934 | 0 | static NodeRef getEntryNode(Inverse<MachineFunction *> G) { |
935 | 0 | return &G.Graph->front(); |
936 | 0 | } |
937 | | }; |
938 | | template <> struct GraphTraits<Inverse<const MachineFunction*>> : |
939 | | public GraphTraits<Inverse<const MachineBasicBlock*>> { |
940 | 0 | static NodeRef getEntryNode(Inverse<const MachineFunction *> G) { |
941 | 0 | return &G.Graph->front(); |
942 | 0 | } |
943 | | }; |
944 | | |
945 | | } // end namespace llvm |
946 | | |
947 | | #endif // LLVM_CODEGEN_MACHINEFUNCTION_H |