Coverage Report

Created: 2018-11-12 17:33

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