Coverage Report

Created: 2019-02-20 00:17

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/CodeGen/MachineFunction.h
Line
Count
Source (jump to first uncovered line)
1
//===- llvm/CodeGen/MachineFunction.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 native machine code for a function.  This class contains a list of
10
// MachineBasicBlock instances that make up the current compiled function.
11
//
12
// This class also contains pointers to various classes which hold
13
// target-specific information about the generated code.
14
//
15
//===----------------------------------------------------------------------===//
16
17
#ifndef LLVM_CODEGEN_MACHINEFUNCTION_H
18
#define LLVM_CODEGEN_MACHINEFUNCTION_H
19
20
#include "llvm/ADT/ArrayRef.h"
21
#include "llvm/ADT/BitVector.h"
22
#include "llvm/ADT/DenseMap.h"
23
#include "llvm/ADT/GraphTraits.h"
24
#include "llvm/ADT/Optional.h"
25
#include "llvm/ADT/SmallVector.h"
26
#include "llvm/ADT/StringRef.h"
27
#include "llvm/ADT/ilist.h"
28
#include "llvm/ADT/iterator.h"
29
#include "llvm/Analysis/EHPersonalities.h"
30
#include "llvm/CodeGen/MachineBasicBlock.h"
31
#include "llvm/CodeGen/MachineInstr.h"
32
#include "llvm/CodeGen/MachineMemOperand.h"
33
#include "llvm/IR/DebugLoc.h"
34
#include "llvm/IR/Instructions.h"
35
#include "llvm/IR/Metadata.h"
36
#include "llvm/MC/MCDwarf.h"
37
#include "llvm/MC/MCSymbol.h"
38
#include "llvm/Support/Allocator.h"
39
#include "llvm/Support/ArrayRecycler.h"
40
#include "llvm/Support/AtomicOrdering.h"
41
#include "llvm/Support/Compiler.h"
42
#include "llvm/Support/ErrorHandling.h"
43
#include "llvm/Support/Recycler.h"
44
#include <cassert>
45
#include <cstdint>
46
#include <memory>
47
#include <utility>
48
#include <vector>
49
50
namespace llvm {
51
52
class BasicBlock;
53
class BlockAddress;
54
class DataLayout;
55
class DIExpression;
56
class DILocalVariable;
57
class DILocation;
58
class Function;
59
class GlobalValue;
60
class LLVMTargetMachine;
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 TargetRegisterClass;
74
class TargetSubtargetInfo;
75
struct WasmEHFuncInfo;
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* N);
84
  void removeNodeFromList(MachineBasicBlock* N);
85
86
  template <class Iterator>
87
1.42M
  void transferNodesFromList(ilist_callback_traits &OldList, Iterator, Iterator) {
88
1.42M
    assert(this == &OldList && "never transfer MBBs between functions");
89
1.42M
  }
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
  /// 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
478k
  static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) {
105
478k
    return new (Allocator.Allocate<Ty>()) Ty(MF);
106
478k
  }
llvm::AArch64FunctionInfo* llvm::MachineFunctionInfo::create<llvm::AArch64FunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&)
Line
Count
Source
104
256k
  static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) {
105
256k
    return new (Allocator.Allocate<Ty>()) Ty(MF);
106
256k
  }
llvm::SIMachineFunctionInfo* llvm::MachineFunctionInfo::create<llvm::SIMachineFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&)
Line
Count
Source
104
23.9k
  static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) {
105
23.9k
    return new (Allocator.Allocate<Ty>()) Ty(MF);
106
23.9k
  }
Unexecuted instantiation: llvm::AMDGPUMachineFunction* llvm::MachineFunctionInfo::create<llvm::AMDGPUMachineFunction>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&)
llvm::R600MachineFunctionInfo* llvm::MachineFunctionInfo::create<llvm::R600MachineFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&)
Line
Count
Source
104
2.27k
  static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) {
105
2.27k
    return new (Allocator.Allocate<Ty>()) Ty(MF);
106
2.27k
  }
llvm::ARMFunctionInfo* llvm::MachineFunctionInfo::create<llvm::ARMFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&)
Line
Count
Source
104
25.3k
  static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) {
105
25.3k
    return new (Allocator.Allocate<Ty>()) Ty(MF);
106
25.3k
  }
llvm::HexagonMachineFunctionInfo* llvm::MachineFunctionInfo::create<llvm::HexagonMachineFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&)
Line
Count
Source
104
4.97k
  static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) {
105
4.97k
    return new (Allocator.Allocate<Ty>()) Ty(MF);
106
4.97k
  }
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::MipsFunctionInfo* llvm::MachineFunctionInfo::create<llvm::MipsFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&)
Line
Count
Source
104
12.9k
  static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) {
105
12.9k
    return new (Allocator.Allocate<Ty>()) Ty(MF);
106
12.9k
  }
llvm::MSP430MachineFunctionInfo* llvm::MachineFunctionInfo::create<llvm::MSP430MachineFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&)
Line
Count
Source
104
315
  static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) {
105
315
    return new (Allocator.Allocate<Ty>()) Ty(MF);
106
315
  }
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::PPCFunctionInfo* llvm::MachineFunctionInfo::create<llvm::PPCFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&)
Line
Count
Source
104
10.6k
  static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) {
105
10.6k
    return new (Allocator.Allocate<Ty>()) Ty(MF);
106
10.6k
  }
llvm::SparcMachineFunctionInfo* llvm::MachineFunctionInfo::create<llvm::SparcMachineFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&)
Line
Count
Source
104
685
  static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) {
105
685
    return new (Allocator.Allocate<Ty>()) Ty(MF);
106
685
  }
llvm::SystemZMachineFunctionInfo* llvm::MachineFunctionInfo::create<llvm::SystemZMachineFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&)
Line
Count
Source
104
7.27k
  static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) {
105
7.27k
    return new (Allocator.Allocate<Ty>()) Ty(MF);
106
7.27k
  }
llvm::WebAssemblyFunctionInfo* llvm::MachineFunctionInfo::create<llvm::WebAssemblyFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&)
Line
Count
Source
104
3.61k
  static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) {
105
3.61k
    return new (Allocator.Allocate<Ty>()) Ty(MF);
106
3.61k
  }
llvm::X86MachineFunctionInfo* llvm::MachineFunctionInfo::create<llvm::X86MachineFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&)
Line
Count
Source
104
129k
  static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) {
105
129k
    return new (Allocator.Allocate<Ty>()) Ty(MF);
106
129k
  }
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
  }
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
0
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
188M
  bool hasProperty(Property P) const {
161
188M
    return Properties[static_cast<unsigned>(P)];
162
188M
  }
163
164
2.49M
  MachineFunctionProperties &set(Property P) {
165
2.49M
    Properties.set(static_cast<unsigned>(P));
166
2.49M
    return *this;
167
2.49M
  }
168
169
1.02M
  MachineFunctionProperties &reset(Property P) {
170
1.02M
    Properties.reset(static_cast<unsigned>(P));
171
1.02M
    return *this;
172
1.02M
  }
173
174
  /// Reset all the properties.
175
502k
  MachineFunctionProperties &reset() {
176
502k
    Properties.reset();
177
502k
    return *this;
178
502k
  }
179
180
49.3M
  MachineFunctionProperties &set(const MachineFunctionProperties &MFP) {
181
49.3M
    Properties |= MFP.Properties;
182
49.3M
    return *this;
183
49.3M
  }
184
185
49.3M
  MachineFunctionProperties &reset(const MachineFunctionProperties &MFP) {
186
49.3M
    Properties.reset(MFP.Properties);
187
49.3M
    return *this;
188
49.3M
  }
189
190
  // Returns true if all properties set in V (i.e. required by a pass) are set
191
  // in this.
192
  bool verifyRequiredProperties(const MachineFunctionProperties &V) const {
193
    return !V.Properties.test(Properties);
194
  }
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
20.2k
      : LandingPadBlock(MBB) {}
223
};
224
225
class MachineFunction {
226
  const Function &F;
227
  const LLVMTargetMachine &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 Wasm exception handling related data. This will be null for
249
  // functions that aren't using a wasm EH personality.
250
  WasmEHFuncInfo *WasmEHInfo = nullptr;
251
252
  // Keeps track of Windows exception handling related data. This will be null
253
  // for functions that aren't using a funclet-based EH personality.
254
  WinEHFuncInfo *WinEHInfo = nullptr;
255
256
  // Function-level unique numbering for MachineBasicBlocks.  When a
257
  // MachineBasicBlock is inserted into a MachineFunction is it automatically
258
  // numbered and this vector keeps track of the mapping from ID's to MBB's.
259
  std::vector<MachineBasicBlock*> MBBNumbering;
260
261
  // Pool-allocate MachineFunction-lifetime and IR objects.
262
  BumpPtrAllocator Allocator;
263
264
  // Allocation management for instructions in function.
265
  Recycler<MachineInstr> InstructionRecycler;
266
267
  // Allocation management for operand arrays on instructions.
268
  ArrayRecycler<MachineOperand> OperandRecycler;
269
270
  // Allocation management for basic blocks in function.
271
  Recycler<MachineBasicBlock> BasicBlockRecycler;
272
273
  // List of machine basic blocks in function
274
  using BasicBlockListType = ilist<MachineBasicBlock>;
275
  BasicBlockListType BasicBlocks;
276
277
  /// FunctionNumber - This provides a unique ID for each function emitted in
278
  /// this translation unit.
279
  ///
280
  unsigned FunctionNumber;
281
282
  /// Alignment - The alignment of the function.
283
  unsigned Alignment;
284
285
  /// ExposesReturnsTwice - True if the function calls setjmp or related
286
  /// functions with attribute "returns twice", but doesn't have
287
  /// the attribute itself.
288
  /// This is used to limit optimizations which cannot reason
289
  /// about the control flow of such functions.
290
  bool ExposesReturnsTwice = false;
291
292
  /// True if the function includes any inline assembly.
293
  bool HasInlineAsm = false;
294
295
  /// True if any WinCFI instruction have been emitted in this function.
296
  bool HasWinCFI = false;
297
298
  /// Current high-level properties of the IR of the function (e.g. is in SSA
299
  /// form or whether registers have been allocated)
300
  MachineFunctionProperties Properties;
301
302
  // Allocation management for pseudo source values.
303
  std::unique_ptr<PseudoSourceValueManager> PSVManager;
304
305
  /// List of moves done by a function's prolog.  Used to construct frame maps
306
  /// by debug and exception handling consumers.
307
  std::vector<MCCFIInstruction> FrameInstructions;
308
309
  /// \name Exception Handling
310
  /// \{
311
312
  /// List of LandingPadInfo describing the landing pad information.
313
  std::vector<LandingPadInfo> LandingPads;
314
315
  /// Map a landing pad's EH symbol to the call site indexes.
316
  DenseMap<MCSymbol*, SmallVector<unsigned, 4>> LPadToCallSiteMap;
317
318
  /// Map a landing pad to its index.
319
  DenseMap<const MachineBasicBlock *, unsigned> WasmLPadToIndexMap;
320
321
  /// Map of invoke call site index values to associated begin EH_LABEL.
322
  DenseMap<MCSymbol*, unsigned> CallSiteMap;
323
324
  /// CodeView label annotations.
325
  std::vector<std::pair<MCSymbol *, MDNode *>> CodeViewAnnotations;
326
327
  bool CallsEHReturn = false;
328
  bool CallsUnwindInit = false;
329
  bool HasEHScopes = false;
330
  bool HasEHFunclets = false;
331
332
  /// List of C++ TypeInfo used.
333
  std::vector<const GlobalValue *> TypeInfos;
334
335
  /// List of typeids encoding filters used.
336
  std::vector<unsigned> FilterIds;
337
338
  /// List of the indices in FilterIds corresponding to filter terminators.
339
  std::vector<unsigned> FilterEnds;
340
341
  EHPersonality PersonalityTypeCache = EHPersonality::Unknown;
342
343
  /// \}
344
345
  /// Clear all the members of this MachineFunction, but the ones used
346
  /// to initialize again the MachineFunction.
347
  /// More specifically, this deallocates all the dynamically allocated
348
  /// objects and get rid of all the XXXInfo data structure, but keep
349
  /// unchanged the references to Fn, Target, MMI, and FunctionNumber.
350
  void clear();
351
  /// Allocate and initialize the different members.
352
  /// In particular, the XXXInfo data structure.
353
  /// \pre Fn, Target, MMI, and FunctionNumber are properly set.
354
  void init();
355
356
public:
357
  struct VariableDbgInfo {
358
    const DILocalVariable *Var;
359
    const DIExpression *Expr;
360
    // The Slot can be negative for fixed stack objects.
361
    int Slot;
362
    const DILocation *Loc;
363
364
    VariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr,
365
                    int Slot, const DILocation *Loc)
366
758
        : Var(Var), Expr(Expr), Slot(Slot), Loc(Loc) {}
367
  };
368
369
  class Delegate {
370
    virtual void anchor();
371
372
  public:
373
734k
    virtual ~Delegate() = default;
374
    /// Callback after an insertion. This should not modify the MI directly.
375
    virtual void MF_HandleInsertion(MachineInstr &MI) = 0;
376
    /// Callback before a removal. This should not modify the MI directly.
377
    virtual void MF_HandleRemoval(MachineInstr &MI) = 0;
378
  };
379
380
private:
381
  Delegate *TheDelegate = nullptr;
382
383
  // Callbacks for insertion and removal.
384
  void handleInsertion(MachineInstr &MI);
385
  void handleRemoval(MachineInstr &MI);
386
  friend struct ilist_traits<MachineInstr>;
387
388
public:
389
  using VariableDbgInfoMapTy = SmallVector<VariableDbgInfo, 4>;
390
  VariableDbgInfoMapTy VariableDbgInfos;
391
392
  MachineFunction(const Function &F, const LLVMTargetMachine &Target,
393
                  const TargetSubtargetInfo &STI, unsigned FunctionNum,
394
                  MachineModuleInfo &MMI);
395
  MachineFunction(const MachineFunction &) = delete;
396
  MachineFunction &operator=(const MachineFunction &) = delete;
397
  ~MachineFunction();
398
399
  /// Reset the instance as if it was just created.
400
19.9k
  void reset() {
401
19.9k
    clear();
402
19.9k
    init();
403
19.9k
  }
404
405
  /// Reset the currently registered delegate - otherwise assert.
406
734k
  void resetDelegate(Delegate *delegate) {
407
734k
    assert(TheDelegate == delegate &&
408
734k
           "Only the current delegate can perform reset!");
409
734k
    TheDelegate = nullptr;
410
734k
  }
411
412
  /// Set the delegate. resetDelegate must be called before attempting
413
  /// to set.
414
734k
  void setDelegate(Delegate *delegate) {
415
734k
    assert(delegate && !TheDelegate &&
416
734k
           "Attempted to set delegate to null, or to change it without "
417
734k
           "first resetting it!");
418
734k
419
734k
    TheDelegate = delegate;
420
734k
  }
421
422
3.83M
  MachineModuleInfo &getMMI() const { return MMI; }
423
3.79M
  MCContext &getContext() const { return Ctx; }
424
425
3.94M
  PseudoSourceValueManager &getPSVManager() const { return *PSVManager; }
426
427
  /// Return the DataLayout attached to the Module associated to this MF.
428
  const DataLayout &getDataLayout() const;
429
430
  /// Return the LLVM function that this machine code represents
431
177M
  const Function &getFunction() const { return F; }
432
433
  /// getName - Return the name of the corresponding LLVM function.
434
  StringRef getName() const;
435
436
  /// getFunctionNumber - Return a unique ID for the current function.
437
1.49M
  unsigned getFunctionNumber() const { return FunctionNumber; }
438
439
  /// getTarget - Return the target machine this machine code is compiled with
440
98.5M
  const LLVMTargetMachine &getTarget() const { return Target; }
441
442
  /// getSubtarget - Return the subtarget for which this machine code is being
443
  /// compiled.
444
514M
  const TargetSubtargetInfo &getSubtarget() const { return *STI; }
445
12.7k
  void setSubtarget(const TargetSubtargetInfo *ST) { STI = ST; }
446
447
  /// getSubtarget - This method returns a pointer to the specified type of
448
  /// TargetSubtargetInfo.  In debug builds, it verifies that the object being
449
  /// returned is of the correct type.
450
541M
  template<typename STC> const STC &getSubtarget() const {
451
541M
    return *static_cast<const STC *>(STI);
452
541M
  }
llvm::AArch64Subtarget const& llvm::MachineFunction::getSubtarget<llvm::AArch64Subtarget>() const
Line
Count
Source
450
495M
  template<typename STC> const STC &getSubtarget() const {
451
495M
    return *static_cast<const STC *>(STI);
452
495M
  }
llvm::GCNSubtarget const& llvm::MachineFunction::getSubtarget<llvm::GCNSubtarget>() const
Line
Count
Source
450
2.33M
  template<typename STC> const STC &getSubtarget() const {
451
2.33M
    return *static_cast<const STC *>(STI);
452
2.33M
  }
llvm::R600Subtarget const& llvm::MachineFunction::getSubtarget<llvm::R600Subtarget>() const
Line
Count
Source
450
122k
  template<typename STC> const STC &getSubtarget() const {
451
122k
    return *static_cast<const STC *>(STI);
452
122k
  }
llvm::MCSubtargetInfo const& llvm::MachineFunction::getSubtarget<llvm::MCSubtargetInfo>() const
Line
Count
Source
450
22.1M
  template<typename STC> const STC &getSubtarget() const {
451
22.1M
    return *static_cast<const STC *>(STI);
452
22.1M
  }
llvm::ARMSubtarget const& llvm::MachineFunction::getSubtarget<llvm::ARMSubtarget>() const
Line
Count
Source
450
10.8M
  template<typename STC> const STC &getSubtarget() const {
451
10.8M
    return *static_cast<const STC *>(STI);
452
10.8M
  }
llvm::BPFSubtarget const& llvm::MachineFunction::getSubtarget<llvm::BPFSubtarget>() const
Line
Count
Source
450
541
  template<typename STC> const STC &getSubtarget() const {
451
541
    return *static_cast<const STC *>(STI);
452
541
  }
llvm::HexagonSubtarget const& llvm::MachineFunction::getSubtarget<llvm::HexagonSubtarget>() const
Line
Count
Source
450
712k
  template<typename STC> const STC &getSubtarget() const {
451
712k
    return *static_cast<const STC *>(STI);
452
712k
  }
llvm::LanaiSubtarget const& llvm::MachineFunction::getSubtarget<llvm::LanaiSubtarget>() const
Line
Count
Source
450
177
  template<typename STC> const STC &getSubtarget() const {
451
177
    return *static_cast<const STC *>(STI);
452
177
  }
llvm::MipsSubtarget const& llvm::MachineFunction::getSubtarget<llvm::MipsSubtarget>() const
Line
Count
Source
450
363k
  template<typename STC> const STC &getSubtarget() const {
451
363k
    return *static_cast<const STC *>(STI);
452
363k
  }
llvm::NVPTXSubtarget const& llvm::MachineFunction::getSubtarget<llvm::NVPTXSubtarget>() const
Line
Count
Source
450
13.2k
  template<typename STC> const STC &getSubtarget() const {
451
13.2k
    return *static_cast<const STC *>(STI);
452
13.2k
  }
llvm::PPCSubtarget const& llvm::MachineFunction::getSubtarget<llvm::PPCSubtarget>() const
Line
Count
Source
450
528k
  template<typename STC> const STC &getSubtarget() const {
451
528k
    return *static_cast<const STC *>(STI);
452
528k
  }
llvm::SparcSubtarget const& llvm::MachineFunction::getSubtarget<llvm::SparcSubtarget>() const
Line
Count
Source
450
14.3k
  template<typename STC> const STC &getSubtarget() const {
451
14.3k
    return *static_cast<const STC *>(STI);
452
14.3k
  }
llvm::SystemZSubtarget const& llvm::MachineFunction::getSubtarget<llvm::SystemZSubtarget>() const
Line
Count
Source
450
86.4k
  template<typename STC> const STC &getSubtarget() const {
451
86.4k
    return *static_cast<const STC *>(STI);
452
86.4k
  }
llvm::WebAssemblySubtarget const& llvm::MachineFunction::getSubtarget<llvm::WebAssemblySubtarget>() const
Line
Count
Source
450
69.5k
  template<typename STC> const STC &getSubtarget() const {
451
69.5k
    return *static_cast<const STC *>(STI);
452
69.5k
  }
llvm::X86Subtarget const& llvm::MachineFunction::getSubtarget<llvm::X86Subtarget>() const
Line
Count
Source
450
8.71M
  template<typename STC> const STC &getSubtarget() const {
451
8.71M
    return *static_cast<const STC *>(STI);
452
8.71M
  }
llvm::XCoreSubtarget const& llvm::MachineFunction::getSubtarget<llvm::XCoreSubtarget>() const
Line
Count
Source
450
736
  template<typename STC> const STC &getSubtarget() const {
451
736
    return *static_cast<const STC *>(STI);
452
736
  }
llvm::TargetSubtargetInfo const& llvm::MachineFunction::getSubtarget<llvm::TargetSubtargetInfo>() const
Line
Count
Source
450
188
  template<typename STC> const STC &getSubtarget() const {
451
188
    return *static_cast<const STC *>(STI);
452
188
  }
453
454
  /// getRegInfo - Return information about the registers currently in use.
455
425M
  MachineRegisterInfo &getRegInfo() { return *RegInfo; }
456
116M
  const MachineRegisterInfo &getRegInfo() const { return *RegInfo; }
457
458
  /// getFrameInfo - Return the frame info object for the current function.
459
  /// This object contains information about objects allocated on the stack
460
  /// frame of the current function in an abstract way.
461
20.9M
  MachineFrameInfo &getFrameInfo() { return *FrameInfo; }
462
94.2M
  const MachineFrameInfo &getFrameInfo() const { return *FrameInfo; }
463
464
  /// getJumpTableInfo - Return the jump table info object for the current
465
  /// function.  This object contains information about jump tables in the
466
  /// current function.  If the current function has no jump tables, this will
467
  /// return null.
468
7.26k
  const MachineJumpTableInfo *getJumpTableInfo() const { return JumpTableInfo; }
469
1.36M
  MachineJumpTableInfo *getJumpTableInfo() { return JumpTableInfo; }
470
471
  /// getOrCreateJumpTableInfo - Get the JumpTableInfo for this function, if it
472
  /// does already exist, allocate one.
473
  MachineJumpTableInfo *getOrCreateJumpTableInfo(unsigned JTEntryKind);
474
475
  /// getConstantPool - Return the constant pool object for the current
476
  /// function.
477
655k
  MachineConstantPool *getConstantPool() { return ConstantPool; }
478
22.3k
  const MachineConstantPool *getConstantPool() const { return ConstantPool; }
479
480
  /// getWasmEHFuncInfo - Return information about how the current function uses
481
  /// Wasm exception handling. Returns null for functions that don't use wasm
482
  /// exception handling.
483
0
  const WasmEHFuncInfo *getWasmEHFuncInfo() const { return WasmEHInfo; }
484
45
  WasmEHFuncInfo *getWasmEHFuncInfo() { return WasmEHInfo; }
485
486
  /// getWinEHFuncInfo - Return information about how the current function uses
487
  /// Windows exception handling. Returns null for functions that don't use
488
  /// funclets for exception handling.
489
162
  const WinEHFuncInfo *getWinEHFuncInfo() const { return WinEHInfo; }
490
612k
  WinEHFuncInfo *getWinEHFuncInfo() { return WinEHInfo; }
491
492
  /// getAlignment - Return the alignment (log2, not bytes) of the function.
493
516k
  unsigned getAlignment() const { return Alignment; }
494
495
  /// setAlignment - Set the alignment (log2, not bytes) of the function.
496
23.3k
  void setAlignment(unsigned A) { Alignment = A; }
497
498
  /// ensureAlignment - Make sure the function is at least 1 << A bytes aligned.
499
4.74k
  void ensureAlignment(unsigned A) {
500
4.74k
    if (Alignment < A) 
Alignment = A3.91k
;
501
4.74k
  }
502
503
  /// exposesReturnsTwice - Returns true if the function calls setjmp or
504
  /// any other similar functions with attribute "returns twice" without
505
  /// having the attribute itself.
506
36.9k
  bool exposesReturnsTwice() const {
507
36.9k
    return ExposesReturnsTwice;
508
36.9k
  }
509
510
  /// setCallsSetJmp - Set a flag that indicates if there's a call to
511
  /// a "returns twice" function.
512
265k
  void setExposesReturnsTwice(bool B) {
513
265k
    ExposesReturnsTwice = B;
514
265k
  }
515
516
  /// Returns true if the function contains any inline assembly.
517
6.15M
  bool hasInlineAsm() const {
518
6.15M
    return HasInlineAsm;
519
6.15M
  }
520
521
  /// Set a flag that indicates that the function contains inline assembly.
522
283k
  void setHasInlineAsm(bool B) {
523
283k
    HasInlineAsm = B;
524
283k
  }
525
526
9.12k
  bool hasWinCFI() const {
527
9.12k
    return HasWinCFI;
528
9.12k
  }
529
519k
  void setHasWinCFI(bool v) { HasWinCFI = v; }
530
531
  /// Get the function properties
532
4.40M
  const MachineFunctionProperties &getProperties() const { return Properties; }
533
235M
  MachineFunctionProperties &getProperties() { return Properties; }
534
535
  /// getInfo - Keep track of various per-function pieces of information for
536
  /// backends that would like to do so.
537
  ///
538
  template<typename Ty>
539
11.6M
  Ty *getInfo() {
540
11.6M
    if (!MFInfo)
541
478k
      MFInfo = Ty::template create<Ty>(Allocator, *this);
542
11.6M
    return static_cast<Ty*>(MFInfo);
543
11.6M
  }
llvm::AArch64FunctionInfo* llvm::MachineFunction::getInfo<llvm::AArch64FunctionInfo>()
Line
Count
Source
539
4.21M
  Ty *getInfo() {
540
4.21M
    if (!MFInfo)
541
256k
      MFInfo = Ty::template create<Ty>(Allocator, *this);
542
4.21M
    return static_cast<Ty*>(MFInfo);
543
4.21M
  }
llvm::SIMachineFunctionInfo* llvm::MachineFunction::getInfo<llvm::SIMachineFunctionInfo>()
Line
Count
Source
539
1.33M
  Ty *getInfo() {
540
1.33M
    if (!MFInfo)
541
23.9k
      MFInfo = Ty::template create<Ty>(Allocator, *this);
542
1.33M
    return static_cast<Ty*>(MFInfo);
543
1.33M
  }
llvm::AMDGPUMachineFunction* llvm::MachineFunction::getInfo<llvm::AMDGPUMachineFunction>()
Line
Count
Source
539
21.2k
  Ty *getInfo() {
540
21.2k
    if (!MFInfo)
541
0
      MFInfo = Ty::template create<Ty>(Allocator, *this);
542
21.2k
    return static_cast<Ty*>(MFInfo);
543
21.2k
  }
llvm::R600MachineFunctionInfo* llvm::MachineFunction::getInfo<llvm::R600MachineFunctionInfo>()
Line
Count
Source
539
104k
  Ty *getInfo() {
540
104k
    if (!MFInfo)
541
2.27k
      MFInfo = Ty::template create<Ty>(Allocator, *this);
542
104k
    return static_cast<Ty*>(MFInfo);
543
104k
  }
llvm::ARMFunctionInfo* llvm::MachineFunction::getInfo<llvm::ARMFunctionInfo>()
Line
Count
Source
539
1.78M
  Ty *getInfo() {
540
1.78M
    if (!MFInfo)
541
25.3k
      MFInfo = Ty::template create<Ty>(Allocator, *this);
542
1.78M
    return static_cast<Ty*>(MFInfo);
543
1.78M
  }
llvm::HexagonMachineFunctionInfo* llvm::MachineFunction::getInfo<llvm::HexagonMachineFunctionInfo>()
Line
Count
Source
539
84.6k
  Ty *getInfo() {
540
84.6k
    if (!MFInfo)
541
4.97k
      MFInfo = Ty::template create<Ty>(Allocator, *this);
542
84.6k
    return static_cast<Ty*>(MFInfo);
543
84.6k
  }
llvm::LanaiMachineFunctionInfo* llvm::MachineFunction::getInfo<llvm::LanaiMachineFunctionInfo>()
Line
Count
Source
539
89
  Ty *getInfo() {
540
89
    if (!MFInfo)
541
89
      MFInfo = Ty::template create<Ty>(Allocator, *this);
542
89
    return static_cast<Ty*>(MFInfo);
543
89
  }
llvm::MipsFunctionInfo* llvm::MachineFunction::getInfo<llvm::MipsFunctionInfo>()
Line
Count
Source
539
108k
  Ty *getInfo() {
540
108k
    if (!MFInfo)
541
12.9k
      MFInfo = Ty::template create<Ty>(Allocator, *this);
542
108k
    return static_cast<Ty*>(MFInfo);
543
108k
  }
llvm::MSP430MachineFunctionInfo* llvm::MachineFunction::getInfo<llvm::MSP430MachineFunctionInfo>()
Line
Count
Source
539
971
  Ty *getInfo() {
540
971
    if (!MFInfo)
541
315
      MFInfo = Ty::template create<Ty>(Allocator, *this);
542
971
    return static_cast<Ty*>(MFInfo);
543
971
  }
llvm::NVPTXMachineFunctionInfo* llvm::MachineFunction::getInfo<llvm::NVPTXMachineFunctionInfo>()
Line
Count
Source
539
29
  Ty *getInfo() {
540
29
    if (!MFInfo)
541
17
      MFInfo = Ty::template create<Ty>(Allocator, *this);
542
29
    return static_cast<Ty*>(MFInfo);
543
29
  }
llvm::PPCFunctionInfo* llvm::MachineFunction::getInfo<llvm::PPCFunctionInfo>()
Line
Count
Source
539
375k
  Ty *getInfo() {
540
375k
    if (!MFInfo)
541
10.6k
      MFInfo = Ty::template create<Ty>(Allocator, *this);
542
375k
    return static_cast<Ty*>(MFInfo);
543
375k
  }
llvm::SparcMachineFunctionInfo* llvm::MachineFunction::getInfo<llvm::SparcMachineFunctionInfo>()
Line
Count
Source
539
3.72k
  Ty *getInfo() {
540
3.72k
    if (!MFInfo)
541
685
      MFInfo = Ty::template create<Ty>(Allocator, *this);
542
3.72k
    return static_cast<Ty*>(MFInfo);
543
3.72k
  }
llvm::SystemZMachineFunctionInfo* llvm::MachineFunction::getInfo<llvm::SystemZMachineFunctionInfo>()
Line
Count
Source
539
77.1k
  Ty *getInfo() {
540
77.1k
    if (!MFInfo)
541
7.27k
      MFInfo = Ty::template create<Ty>(Allocator, *this);
542
77.1k
    return static_cast<Ty*>(MFInfo);
543
77.1k
  }
llvm::WebAssemblyFunctionInfo* llvm::MachineFunction::getInfo<llvm::WebAssemblyFunctionInfo>()
Line
Count
Source
539
109k
  Ty *getInfo() {
540
109k
    if (!MFInfo)
541
3.61k
      MFInfo = Ty::template create<Ty>(Allocator, *this);
542
109k
    return static_cast<Ty*>(MFInfo);
543
109k
  }
llvm::X86MachineFunctionInfo* llvm::MachineFunction::getInfo<llvm::X86MachineFunctionInfo>()
Line
Count
Source
539
3.46M
  Ty *getInfo() {
540
3.46M
    if (!MFInfo)
541
129k
      MFInfo = Ty::template create<Ty>(Allocator, *this);
542
3.46M
    return static_cast<Ty*>(MFInfo);
543
3.46M
  }
llvm::XCoreFunctionInfo* llvm::MachineFunction::getInfo<llvm::XCoreFunctionInfo>()
Line
Count
Source
539
1.76k
  Ty *getInfo() {
540
1.76k
    if (!MFInfo)
541
277
      MFInfo = Ty::template create<Ty>(Allocator, *this);
542
1.76k
    return static_cast<Ty*>(MFInfo);
543
1.76k
  }
544
545
  template<typename Ty>
546
5.42M
  const Ty *getInfo() const {
547
5.42M
     return const_cast<MachineFunction*>(this)->getInfo<Ty>();
548
5.42M
  }
llvm::AArch64FunctionInfo const* llvm::MachineFunction::getInfo<llvm::AArch64FunctionInfo>() const
Line
Count
Source
546
1.36M
  const Ty *getInfo() const {
547
1.36M
     return const_cast<MachineFunction*>(this)->getInfo<Ty>();
548
1.36M
  }
llvm::SIMachineFunctionInfo const* llvm::MachineFunction::getInfo<llvm::SIMachineFunctionInfo>() const
Line
Count
Source
546
600k
  const Ty *getInfo() const {
547
600k
     return const_cast<MachineFunction*>(this)->getInfo<Ty>();
548
600k
  }
llvm::AMDGPUMachineFunction const* llvm::MachineFunction::getInfo<llvm::AMDGPUMachineFunction>() const
Line
Count
Source
546
44
  const Ty *getInfo() const {
547
44
     return const_cast<MachineFunction*>(this)->getInfo<Ty>();
548
44
  }
llvm::R600MachineFunctionInfo const* llvm::MachineFunction::getInfo<llvm::R600MachineFunctionInfo>() const
Line
Count
Source
546
2.27k
  const Ty *getInfo() const {
547
2.27k
     return const_cast<MachineFunction*>(this)->getInfo<Ty>();
548
2.27k
  }
llvm::ARMFunctionInfo const* llvm::MachineFunction::getInfo<llvm::ARMFunctionInfo>() const
Line
Count
Source
546
675k
  const Ty *getInfo() const {
547
675k
     return const_cast<MachineFunction*>(this)->getInfo<Ty>();
548
675k
  }
llvm::HexagonMachineFunctionInfo const* llvm::MachineFunction::getInfo<llvm::HexagonMachineFunctionInfo>() const
Line
Count
Source
546
74.6k
  const Ty *getInfo() const {
547
74.6k
     return const_cast<MachineFunction*>(this)->getInfo<Ty>();
548
74.6k
  }
llvm::MipsFunctionInfo const* llvm::MachineFunction::getInfo<llvm::MipsFunctionInfo>() const
Line
Count
Source
546
1.63k
  const Ty *getInfo() const {
547
1.63k
     return const_cast<MachineFunction*>(this)->getInfo<Ty>();
548
1.63k
  }
llvm::PPCFunctionInfo const* llvm::MachineFunction::getInfo<llvm::PPCFunctionInfo>() const
Line
Count
Source
546
307k
  const Ty *getInfo() const {
547
307k
     return const_cast<MachineFunction*>(this)->getInfo<Ty>();
548
307k
  }
llvm::SparcMachineFunctionInfo const* llvm::MachineFunction::getInfo<llvm::SparcMachineFunctionInfo>() const
Line
Count
Source
546
1.50k
  const Ty *getInfo() const {
547
1.50k
     return const_cast<MachineFunction*>(this)->getInfo<Ty>();
548
1.50k
  }
llvm::SystemZMachineFunctionInfo const* llvm::MachineFunction::getInfo<llvm::SystemZMachineFunctionInfo>() const
Line
Count
Source
546
39.6k
  const Ty *getInfo() const {
547
39.6k
     return const_cast<MachineFunction*>(this)->getInfo<Ty>();
548
39.6k
  }
llvm::WebAssemblyFunctionInfo const* llvm::MachineFunction::getInfo<llvm::WebAssemblyFunctionInfo>() const
Line
Count
Source
546
65.3k
  const Ty *getInfo() const {
547
65.3k
     return const_cast<MachineFunction*>(this)->getInfo<Ty>();
548
65.3k
  }
llvm::X86MachineFunctionInfo const* llvm::MachineFunction::getInfo<llvm::X86MachineFunctionInfo>() const
Line
Count
Source
546
2.28M
  const Ty *getInfo() const {
547
2.28M
     return const_cast<MachineFunction*>(this)->getInfo<Ty>();
548
2.28M
  }
549
550
  /// getBlockNumbered - MachineBasicBlocks are automatically numbered when they
551
  /// are inserted into the machine function.  The block number for a machine
552
  /// basic block can be found by using the MBB::getNumber method, this method
553
  /// provides the inverse mapping.
554
191M
  MachineBasicBlock *getBlockNumbered(unsigned N) const {
555
191M
    assert(N < MBBNumbering.size() && "Illegal block number");
556
191M
    assert(MBBNumbering[N] && "Block was removed from the machine function!");
557
191M
    return MBBNumbering[N];
558
191M
  }
559
560
  /// Should we be emitting segmented stack stuff for the function
561
  bool shouldSplitStack() const;
562
563
  /// getNumBlockIDs - Return the number of MBB ID's allocated.
564
44.8M
  unsigned getNumBlockIDs() const { return (unsigned)MBBNumbering.size(); }
565
566
  /// RenumberBlocks - This discards all of the MachineBasicBlock numbers and
567
  /// recomputes them.  This guarantees that the MBB numbers are sequential,
568
  /// dense, and match the ordering of the blocks within the function.  If a
569
  /// specific MachineBasicBlock is specified, only that block and those after
570
  /// it are renumbered.
571
  void RenumberBlocks(MachineBasicBlock *MBBFrom = nullptr);
572
573
  /// print - Print out the MachineFunction in a format suitable for debugging
574
  /// to the specified stream.
575
  void print(raw_ostream &OS, const SlotIndexes* = nullptr) const;
576
577
  /// viewCFG - This function is meant for use from the debugger.  You can just
578
  /// say 'call F->viewCFG()' and a ghostview window should pop up from the
579
  /// program, displaying the CFG of the current function with the code for each
580
  /// basic block inside.  This depends on there being a 'dot' and 'gv' program
581
  /// in your path.
582
  void viewCFG() const;
583
584
  /// viewCFGOnly - This function is meant for use from the debugger.  It works
585
  /// just like viewCFG, but it does not include the contents of basic blocks
586
  /// into the nodes, just the label.  If you are only interested in the CFG
587
  /// this can make the graph smaller.
588
  ///
589
  void viewCFGOnly() const;
590
591
  /// dump - Print the current MachineFunction to cerr, useful for debugger use.
592
  void dump() const;
593
594
  /// Run the current MachineFunction through the machine code verifier, useful
595
  /// for debugger use.
596
  /// \returns true if no problems were found.
597
  bool verify(Pass *p = nullptr, const char *Banner = nullptr,
598
              bool AbortOnError = true) const;
599
600
  // Provide accessors for the MachineBasicBlock list...
601
  using iterator = BasicBlockListType::iterator;
602
  using const_iterator = BasicBlockListType::const_iterator;
603
  using const_reverse_iterator = BasicBlockListType::const_reverse_iterator;
604
  using reverse_iterator = BasicBlockListType::reverse_iterator;
605
606
  /// Support for MachineBasicBlock::getNextNode().
607
  static BasicBlockListType MachineFunction::*
608
22.9M
  getSublistAccess(MachineBasicBlock *) {
609
22.9M
    return &MachineFunction::BasicBlocks;
610
22.9M
  }
611
612
  /// addLiveIn - Add the specified physical register as a live-in value and
613
  /// create a corresponding virtual register for it.
614
  unsigned addLiveIn(unsigned PReg, const TargetRegisterClass *RC);
615
616
  //===--------------------------------------------------------------------===//
617
  // BasicBlock accessor functions.
618
  //
619
34.8M
  iterator                 begin()       { return BasicBlocks.begin(); }
620
13.2M
  const_iterator           begin() const { return BasicBlocks.begin(); }
621
113M
  iterator                 end  ()       { return BasicBlocks.end();   }
622
11.8M
  const_iterator           end  () const { return BasicBlocks.end();   }
623
624
994k
  reverse_iterator        rbegin()       { return BasicBlocks.rbegin(); }
625
58
  const_reverse_iterator  rbegin() const { return BasicBlocks.rbegin(); }
626
989k
  reverse_iterator        rend  ()       { return BasicBlocks.rend();   }
627
0
  const_reverse_iterator  rend  () const { return BasicBlocks.rend();   }
628
629
4.45M
  unsigned                  size() const { return (unsigned)BasicBlocks.size();}
630
7.71M
  bool                     empty() const { return BasicBlocks.empty(); }
631
7.59M
  const MachineBasicBlock &front() const { return BasicBlocks.front(); }
632
10.8M
        MachineBasicBlock &front()       { return BasicBlocks.front(); }
633
390k
  const MachineBasicBlock & back() const { return BasicBlocks.back(); }
634
292k
        MachineBasicBlock & back()       { return BasicBlocks.back(); }
635
636
3.51M
  void push_back (MachineBasicBlock *MBB) { BasicBlocks.push_back (MBB); }
637
314
  void push_front(MachineBasicBlock *MBB) { BasicBlocks.push_front(MBB); }
638
455k
  void insert(iterator MBBI, MachineBasicBlock *MBB) {
639
455k
    BasicBlocks.insert(MBBI, MBB);
640
455k
  }
641
318k
  void splice(iterator InsertPt, iterator MBBI) {
642
318k
    BasicBlocks.splice(InsertPt, BasicBlocks, MBBI);
643
318k
  }
644
1.10M
  void splice(iterator InsertPt, MachineBasicBlock *MBB) {
645
1.10M
    BasicBlocks.splice(InsertPt, BasicBlocks, MBB);
646
1.10M
  }
647
0
  void splice(iterator InsertPt, iterator MBBI, iterator MBBE) {
648
0
    BasicBlocks.splice(InsertPt, BasicBlocks, MBBI, MBBE);
649
0
  }
650
651
0
  void remove(iterator MBBI) { BasicBlocks.remove(MBBI); }
652
235k
  void remove(MachineBasicBlock *MBBI) { BasicBlocks.remove(MBBI); }
653
72
  void erase(iterator MBBI) { BasicBlocks.erase(MBBI); }
654
341k
  void erase(MachineBasicBlock *MBBI) { BasicBlocks.erase(MBBI); }
655
656
  template <typename Comp>
657
83
  void sort(Comp comp) {
658
83
    BasicBlocks.sort(comp);
659
83
  }
660
661
  /// Return the number of \p MachineInstrs in this \p MachineFunction.
662
225
  unsigned getInstructionCount() const {
663
225
    unsigned InstrCount = 0;
664
225
    for (const MachineBasicBlock &MBB : BasicBlocks)
665
244
      InstrCount += MBB.size();
666
225
    return InstrCount;
667
225
  }
668
669
  //===--------------------------------------------------------------------===//
670
  // Internal functions used to automatically number MachineBasicBlocks
671
672
  /// Adds the MBB to the internal numbering. Returns the unique number
673
  /// assigned to the MBB.
674
3.97M
  unsigned addToMBBNumbering(MachineBasicBlock *MBB) {
675
3.97M
    MBBNumbering.push_back(MBB);
676
3.97M
    return (unsigned)MBBNumbering.size()-1;
677
3.97M
  }
678
679
  /// removeFromMBBNumbering - Remove the specific machine basic block from our
680
  /// tracker, this is only really to be used by the MachineBasicBlock
681
  /// implementation.
682
3.97M
  void removeFromMBBNumbering(unsigned N) {
683
3.97M
    assert(N < MBBNumbering.size() && "Illegal basic block #");
684
3.97M
    MBBNumbering[N] = nullptr;
685
3.97M
  }
686
687
  /// CreateMachineInstr - Allocate a new MachineInstr. Use this instead
688
  /// of `new MachineInstr'.
689
  MachineInstr *CreateMachineInstr(const MCInstrDesc &MCID, const DebugLoc &DL,
690
                                   bool NoImp = false);
691
692
  /// Create a new MachineInstr which is a copy of \p Orig, identical in all
693
  /// ways except the instruction has no parent, prev, or next. Bundling flags
694
  /// are reset.
695
  ///
696
  /// Note: Clones a single instruction, not whole instruction bundles.
697
  /// Does not perform target specific adjustments; consider using
698
  /// TargetInstrInfo::duplicate() instead.
699
  MachineInstr *CloneMachineInstr(const MachineInstr *Orig);
700
701
  /// Clones instruction or the whole instruction bundle \p Orig and insert
702
  /// into \p MBB before \p InsertBefore.
703
  ///
704
  /// Note: Does not perform target specific adjustments; consider using
705
  /// TargetInstrInfo::duplicate() intead.
706
  MachineInstr &CloneMachineInstrBundle(MachineBasicBlock &MBB,
707
      MachineBasicBlock::iterator InsertBefore, const MachineInstr &Orig);
708
709
  /// DeleteMachineInstr - Delete the given MachineInstr.
710
  void DeleteMachineInstr(MachineInstr *MI);
711
712
  /// CreateMachineBasicBlock - Allocate a new MachineBasicBlock. Use this
713
  /// instead of `new MachineBasicBlock'.
714
  MachineBasicBlock *CreateMachineBasicBlock(const BasicBlock *bb = nullptr);
715
716
  /// DeleteMachineBasicBlock - Delete the given MachineBasicBlock.
717
  void DeleteMachineBasicBlock(MachineBasicBlock *MBB);
718
719
  /// getMachineMemOperand - Allocate a new MachineMemOperand.
720
  /// MachineMemOperands are owned by the MachineFunction and need not be
721
  /// explicitly deallocated.
722
  MachineMemOperand *getMachineMemOperand(
723
      MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s,
724
      unsigned base_alignment, const AAMDNodes &AAInfo = AAMDNodes(),
725
      const MDNode *Ranges = nullptr,
726
      SyncScope::ID SSID = SyncScope::System,
727
      AtomicOrdering Ordering = AtomicOrdering::NotAtomic,
728
      AtomicOrdering FailureOrdering = AtomicOrdering::NotAtomic);
729
730
  /// getMachineMemOperand - Allocate a new MachineMemOperand by copying
731
  /// an existing one, adjusting by an offset and using the given size.
732
  /// MachineMemOperands are owned by the MachineFunction and need not be
733
  /// explicitly deallocated.
734
  MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
735
                                          int64_t Offset, uint64_t Size);
736
737
  /// Allocate a new MachineMemOperand by copying an existing one,
738
  /// replacing only AliasAnalysis information. MachineMemOperands are owned
739
  /// by the MachineFunction and need not be explicitly deallocated.
740
  MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
741
                                          const AAMDNodes &AAInfo);
742
743
  using OperandCapacity = ArrayRecycler<MachineOperand>::Capacity;
744
745
  /// Allocate an array of MachineOperands. This is only intended for use by
746
  /// internal MachineInstr functions.
747
77.2M
  MachineOperand *allocateOperandArray(OperandCapacity Cap) {
748
77.2M
    return OperandRecycler.allocate(Cap, Allocator);
749
77.2M
  }
750
751
  /// Dellocate an array of MachineOperands and recycle the memory. This is
752
  /// only intended for use by internal MachineInstr functions.
753
  /// Cap must be the same capacity that was used to allocate the array.
754
49.8M
  void deallocateOperandArray(OperandCapacity Cap, MachineOperand *Array) {
755
49.8M
    OperandRecycler.deallocate(Cap, Array);
756
49.8M
  }
757
758
  /// Allocate and initialize a register mask with @p NumRegister bits.
759
  uint32_t *allocateRegMask();
760
761
  /// Allocate and construct an extra info structure for a `MachineInstr`.
762
  ///
763
  /// This is allocated on the function's allocator and so lives the life of
764
  /// the function.
765
  MachineInstr::ExtraInfo *
766
  createMIExtraInfo(ArrayRef<MachineMemOperand *> MMOs,
767
                    MCSymbol *PreInstrSymbol = nullptr,
768
                    MCSymbol *PostInstrSymbol = nullptr);
769
770
  /// Allocate a string and populate it with the given external symbol name.
771
  const char *createExternalSymbolName(StringRef Name);
772
773
  //===--------------------------------------------------------------------===//
774
  // Label Manipulation.
775
776
  /// getJTISymbol - Return the MCSymbol for the specified non-empty jump table.
777
  /// If isLinkerPrivate is specified, an 'l' label is returned, otherwise a
778
  /// normal 'L' label is returned.
779
  MCSymbol *getJTISymbol(unsigned JTI, MCContext &Ctx,
780
                         bool isLinkerPrivate = false) const;
781
782
  /// getPICBaseSymbol - Return a function-local symbol to represent the PIC
783
  /// base.
784
  MCSymbol *getPICBaseSymbol() const;
785
786
  /// Returns a reference to a list of cfi instructions in the function's
787
  /// prologue.  Used to construct frame maps for debug and exception handling
788
  /// comsumers.
789
501k
  const std::vector<MCCFIInstruction> &getFrameInstructions() const {
790
501k
    return FrameInstructions;
791
501k
  }
792
793
491k
  LLVM_NODISCARD unsigned addFrameInst(const MCCFIInstruction &Inst) {
794
491k
    FrameInstructions.push_back(Inst);
795
491k
    return FrameInstructions.size() - 1;
796
491k
  }
797
798
  /// \name Exception Handling
799
  /// \{
800
801
2.98M
  bool callsEHReturn() const { return CallsEHReturn; }
802
29
  void setCallsEHReturn(bool b) { CallsEHReturn = b; }
803
804
1.86M
  bool callsUnwindInit() const { return CallsUnwindInit; }
805
15
  void setCallsUnwindInit(bool b) { CallsUnwindInit = b; }
806
807
1.73M
  bool hasEHScopes() const { return HasEHScopes; }
808
316
  void setHasEHScopes(bool V) { HasEHScopes = V; }
809
810
38.0M
  bool hasEHFunclets() const { return HasEHFunclets; }
811
316
  void setHasEHFunclets(bool V) { HasEHFunclets = V; }
812
813
  /// Find or create an LandingPadInfo for the specified MachineBasicBlock.
814
  LandingPadInfo &getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad);
815
816
  /// Remap landing pad labels and remove any deleted landing pads.
817
  void tidyLandingPads(DenseMap<MCSymbol *, uintptr_t> *LPMap = nullptr,
818
                       bool TidyIfNoBeginLabels = true);
819
820
  /// Return a reference to the landing pad info for the current function.
821
1.98M
  const std::vector<LandingPadInfo> &getLandingPads() const {
822
1.98M
    return LandingPads;
823
1.98M
  }
824
825
  /// Provide the begin and end labels of an invoke style call and associate it
826
  /// with a try landing pad block.
827
  void addInvoke(MachineBasicBlock *LandingPad,
828
                 MCSymbol *BeginLabel, MCSymbol *EndLabel);
829
830
  /// Add a new panding pad, and extract the exception handling information from
831
  /// the landingpad instruction. Returns the label ID for the landing pad
832
  /// entry.
833
  MCSymbol *addLandingPad(MachineBasicBlock *LandingPad);
834
835
  /// Provide the catch typeinfo for a landing pad.
836
  void addCatchTypeInfo(MachineBasicBlock *LandingPad,
837
                        ArrayRef<const GlobalValue *> TyInfo);
838
839
  /// Provide the filter typeinfo for a landing pad.
840
  void addFilterTypeInfo(MachineBasicBlock *LandingPad,
841
                         ArrayRef<const GlobalValue *> TyInfo);
842
843
  /// Add a cleanup action for a landing pad.
844
  void addCleanup(MachineBasicBlock *LandingPad);
845
846
  void addSEHCatchHandler(MachineBasicBlock *LandingPad, const Function *Filter,
847
                          const BlockAddress *RecoverBA);
848
849
  void addSEHCleanupHandler(MachineBasicBlock *LandingPad,
850
                            const Function *Cleanup);
851
852
  /// Return the type id for the specified typeinfo.  This is function wide.
853
  unsigned getTypeIDFor(const GlobalValue *TI);
854
855
  /// Return the id of the filter encoded by TyIds.  This is function wide.
856
  int getFilterIDFor(std::vector<unsigned> &TyIds);
857
858
  /// Map the landing pad's EH symbol to the call site indexes.
859
  void setCallSiteLandingPad(MCSymbol *Sym, ArrayRef<unsigned> Sites);
860
861
  /// Map the landing pad to its index. Used for Wasm exception handling.
862
10
  void setWasmLandingPadIndex(const MachineBasicBlock *LPad, unsigned Index) {
863
10
    WasmLPadToIndexMap[LPad] = Index;
864
10
  }
865
866
  /// Returns true if the landing pad has an associate index in wasm EH.
867
35
  bool hasWasmLandingPadIndex(const MachineBasicBlock *LPad) const {
868
35
    return WasmLPadToIndexMap.count(LPad);
869
35
  }
870
871
  /// Get the index in wasm EH for a given landing pad.
872
10
  unsigned getWasmLandingPadIndex(const MachineBasicBlock *LPad) const {
873
10
    assert(hasWasmLandingPadIndex(LPad));
874
10
    return WasmLPadToIndexMap.lookup(LPad);
875
10
  }
876
877
  /// Get the call site indexes for a landing pad EH symbol.
878
128
  SmallVectorImpl<unsigned> &getCallSiteLandingPad(MCSymbol *Sym) {
879
128
    assert(hasCallSiteLandingPad(Sym) &&
880
128
           "missing call site number for landing pad!");
881
128
    return LPadToCallSiteMap[Sym];
882
128
  }
883
884
  /// Return true if the landing pad Eh symbol has an associated call site.
885
128
  bool hasCallSiteLandingPad(MCSymbol *Sym) {
886
128
    return !LPadToCallSiteMap[Sym].empty();
887
128
  }
888
889
  /// Map the begin label for a call site.
890
175
  void setCallSiteBeginLabel(MCSymbol *BeginLabel, unsigned Site) {
891
175
    CallSiteMap[BeginLabel] = Site;
892
175
  }
893
894
  /// Get the call site number for a begin label.
895
175
  unsigned getCallSiteBeginLabel(MCSymbol *BeginLabel) const {
896
175
    assert(hasCallSiteBeginLabel(BeginLabel) &&
897
175
           "Missing call site number for EH_LABEL!");
898
175
    return CallSiteMap.lookup(BeginLabel);
899
175
  }
900
901
  /// Return true if the begin label has a call site number associated with it.
902
0
  bool hasCallSiteBeginLabel(MCSymbol *BeginLabel) const {
903
0
    return CallSiteMap.count(BeginLabel);
904
0
  }
905
906
  /// Record annotations associated with a particular label.
907
1
  void addCodeViewAnnotation(MCSymbol *Label, MDNode *MD) {
908
1
    CodeViewAnnotations.push_back({Label, MD});
909
1
  }
910
911
243
  ArrayRef<std::pair<MCSymbol *, MDNode *>> getCodeViewAnnotations() const {
912
243
    return CodeViewAnnotations;
913
243
  }
914
915
  /// Return a reference to the C++ typeinfo for the current function.
916
5.22k
  const std::vector<const GlobalValue *> &getTypeInfos() const {
917
5.22k
    return TypeInfos;
918
5.22k
  }
919
920
  /// Return a reference to the typeids encoding filters used in the current
921
  /// function.
922
8.65k
  const std::vector<unsigned> &getFilterIds() const {
923
8.65k
    return FilterIds;
924
8.65k
  }
925
926
  /// \}
927
928
  /// Collect information used to emit debugging information of a variable.
929
  void setVariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr,
930
758
                          int Slot, const DILocation *Loc) {
931
758
    VariableDbgInfos.emplace_back(Var, Expr, Slot, Loc);
932
758
  }
933
934
302k
  VariableDbgInfoMapTy &getVariableDbgInfo() { return VariableDbgInfos; }
935
7.50k
  const VariableDbgInfoMapTy &getVariableDbgInfo() const {
936
7.50k
    return VariableDbgInfos;
937
7.50k
  }
938
};
939
940
//===--------------------------------------------------------------------===//
941
// GraphTraits specializations for function basic block graphs (CFGs)
942
//===--------------------------------------------------------------------===//
943
944
// Provide specializations of GraphTraits to be able to treat a
945
// machine function as a graph of machine basic blocks... these are
946
// the same as the machine basic block iterators, except that the root
947
// node is implicitly the first node of the function.
948
//
949
template <> struct GraphTraits<MachineFunction*> :
950
  public GraphTraits<MachineBasicBlock*> {
951
4.48M
  static NodeRef getEntryNode(MachineFunction *F) { return &F->front(); }
952
953
  // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
954
  using nodes_iterator = pointer_iterator<MachineFunction::iterator>;
955
956
1.43M
  static nodes_iterator nodes_begin(MachineFunction *F) {
957
1.43M
    return nodes_iterator(F->begin());
958
1.43M
  }
959
960
1.43M
  static nodes_iterator nodes_end(MachineFunction *F) {
961
1.43M
    return nodes_iterator(F->end());
962
1.43M
  }
963
964
  static unsigned       size       (MachineFunction *F) { return F->size(); }
965
};
966
template <> struct GraphTraits<const MachineFunction*> :
967
  public GraphTraits<const MachineBasicBlock*> {
968
1.88M
  static NodeRef getEntryNode(const MachineFunction *F) { return &F->front(); }
969
970
  // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
971
  using nodes_iterator = pointer_iterator<MachineFunction::const_iterator>;
972
973
  static nodes_iterator nodes_begin(const MachineFunction *F) {
974
    return nodes_iterator(F->begin());
975
  }
976
977
  static nodes_iterator nodes_end  (const MachineFunction *F) {
978
    return nodes_iterator(F->end());
979
  }
980
981
  static unsigned       size       (const MachineFunction *F)  {
982
    return F->size();
983
  }
984
};
985
986
// Provide specializations of GraphTraits to be able to treat a function as a
987
// graph of basic blocks... and to walk it in inverse order.  Inverse order for
988
// a function is considered to be when traversing the predecessor edges of a BB
989
// instead of the successor edges.
990
//
991
template <> struct GraphTraits<Inverse<MachineFunction*>> :
992
  public GraphTraits<Inverse<MachineBasicBlock*>> {
993
  static NodeRef getEntryNode(Inverse<MachineFunction *> G) {
994
    return &G.Graph->front();
995
  }
996
};
997
template <> struct GraphTraits<Inverse<const MachineFunction*>> :
998
  public GraphTraits<Inverse<const MachineBasicBlock*>> {
999
  static NodeRef getEntryNode(Inverse<const MachineFunction *> G) {
1000
    return &G.Graph->front();
1001
  }
1002
};
1003
1004
} // end namespace llvm
1005
1006
#endif // LLVM_CODEGEN_MACHINEFUNCTION_H