Coverage Report

Created: 2018-09-23 16:00

/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 MachineConstantPool;
62
class MachineFrameInfo;
63
class MachineFunction;
64
class MachineJumpTableInfo;
65
class MachineModuleInfo;
66
class MachineRegisterInfo;
67
class MCContext;
68
class MCInstrDesc;
69
class Pass;
70
class PseudoSourceValueManager;
71
class raw_ostream;
72
class SlotIndexes;
73
class TargetMachine;
74
class TargetRegisterClass;
75
class TargetSubtargetInfo;
76
struct 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
467k
  static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) {
106
467k
    return new (Allocator.Allocate<Ty>()) Ty(MF);
107
467k
  }
llvm::AArch64FunctionInfo* llvm::MachineFunctionInfo::create<llvm::AArch64FunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&)
Line
Count
Source
105
254k
  static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) {
106
254k
    return new (Allocator.Allocate<Ty>()) Ty(MF);
107
254k
  }
llvm::SIMachineFunctionInfo* llvm::MachineFunctionInfo::create<llvm::SIMachineFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&)
Line
Count
Source
105
20.3k
  static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) {
106
20.3k
    return new (Allocator.Allocate<Ty>()) Ty(MF);
107
20.3k
  }
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.4k
  static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) {
106
24.4k
    return new (Allocator.Allocate<Ty>()) Ty(MF);
107
24.4k
  }
llvm::HexagonMachineFunctionInfo* llvm::MachineFunctionInfo::create<llvm::HexagonMachineFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&)
Line
Count
Source
105
4.92k
  static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) {
106
4.92k
    return new (Allocator.Allocate<Ty>()) Ty(MF);
107
4.92k
  }
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.66k
  static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) {
106
9.66k
    return new (Allocator.Allocate<Ty>()) Ty(MF);
107
9.66k
  }
llvm::SparcMachineFunctionInfo* llvm::MachineFunctionInfo::create<llvm::SparcMachineFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&)
Line
Count
Source
105
692
  static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) {
106
692
    return new (Allocator.Allocate<Ty>()) Ty(MF);
107
692
  }
llvm::SystemZMachineFunctionInfo* llvm::MachineFunctionInfo::create<llvm::SystemZMachineFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&)
Line
Count
Source
105
7.12k
  static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) {
106
7.12k
    return new (Allocator.Allocate<Ty>()) Ty(MF);
107
7.12k
  }
llvm::X86MachineFunctionInfo* llvm::MachineFunctionInfo::create<llvm::X86MachineFunctionInfo>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::MachineFunction&)
Line
Count
Source
105
129k
  static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) {
106
129k
    return new (Allocator.Allocate<Ty>()) Ty(MF);
107
129k
  }
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
160M
  bool hasProperty(Property P) const {
162
160M
    return Properties[static_cast<unsigned>(P)];
163
160M
  }
164
165
2.48M
  MachineFunctionProperties &set(Property P) {
166
2.48M
    Properties.set(static_cast<unsigned>(P));
167
2.48M
    return *this;
168
2.48M
  }
169
170
978k
  MachineFunctionProperties &reset(Property P) {
171
978k
    Properties.reset(static_cast<unsigned>(P));
172
978k
    return *this;
173
978k
  }
174
175
  /// Reset all the properties.
176
512k
  MachineFunctionProperties &reset() {
177
512k
    Properties.reset();
178
512k
    return *this;
179
512k
  }
180
181
46.2M
  MachineFunctionProperties &set(const MachineFunctionProperties &MFP) {
182
46.2M
    Properties |= MFP.Properties;
183
46.2M
    return *this;
184
46.2M
  }
185
186
46.2M
  MachineFunctionProperties &reset(const MachineFunctionProperties &MFP) {
187
46.2M
    Properties.reset(MFP.Properties);
188
46.2M
    return *this;
189
46.2M
  }
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
28.4k
      : LandingPadBlock(MBB) {}
224
};
225
226
class MachineFunction {
227
  const Function &F;
228
  const TargetMachine &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 of invoke call site index values to associated begin EH_LABEL.
320
  DenseMap<MCSymbol*, unsigned> CallSiteMap;
321
322
  /// CodeView label annotations.
323
  std::vector<std::pair<MCSymbol *, MDNode *>> CodeViewAnnotations;
324
325
  bool CallsEHReturn = false;
326
  bool CallsUnwindInit = false;
327
  bool HasEHScopes = false;
328
  bool HasEHFunclets = false;
329
330
  /// List of C++ TypeInfo used.
331
  std::vector<const GlobalValue *> TypeInfos;
332
333
  /// List of typeids encoding filters used.
334
  std::vector<unsigned> FilterIds;
335
336
  /// List of the indices in FilterIds corresponding to filter terminators.
337
  std::vector<unsigned> FilterEnds;
338
339
  EHPersonality PersonalityTypeCache = EHPersonality::Unknown;
340
341
  /// \}
342
343
  /// Clear all the members of this MachineFunction, but the ones used
344
  /// to initialize again the MachineFunction.
345
  /// More specifically, this deallocates all the dynamically allocated
346
  /// objects and get rid of all the XXXInfo data structure, but keep
347
  /// unchanged the references to Fn, Target, MMI, and FunctionNumber.
348
  void clear();
349
  /// Allocate and initialize the different members.
350
  /// In particular, the XXXInfo data structure.
351
  /// \pre Fn, Target, MMI, and FunctionNumber are properly set.
352
  void init();
353
354
public:
355
  struct VariableDbgInfo {
356
    const DILocalVariable *Var;
357
    const DIExpression *Expr;
358
    // The Slot can be negative for fixed stack objects.
359
    int Slot;
360
    const DILocation *Loc;
361
362
    VariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr,
363
                    int Slot, const DILocation *Loc)
364
703
        : Var(Var), Expr(Expr), Slot(Slot), Loc(Loc) {}
365
  };
366
367
  class Delegate {
368
    virtual void anchor();
369
370
  public:
371
    virtual ~Delegate() = default;
372
    virtual void MF_HandleInsertion(const MachineInstr &MI) = 0;
373
    virtual void MF_HandleRemoval(const MachineInstr &MI) = 0;
374
  };
375
376
private:
377
  Delegate *TheDelegate = nullptr;
378
379
  // Callbacks for insertion and removal.
380
  void handleInsertion(const MachineInstr &MI);
381
  void handleRemoval(const MachineInstr &MI);
382
  friend struct ilist_traits<MachineInstr>;
383
384
public:
385
  using VariableDbgInfoMapTy = SmallVector<VariableDbgInfo, 4>;
386
  VariableDbgInfoMapTy VariableDbgInfos;
387
388
  MachineFunction(const Function &F, const TargetMachine &Target,
389
                  const TargetSubtargetInfo &STI, unsigned FunctionNum,
390
                  MachineModuleInfo &MMI);
391
  MachineFunction(const MachineFunction &) = delete;
392
  MachineFunction &operator=(const MachineFunction &) = delete;
393
  ~MachineFunction();
394
395
  /// Reset the instance as if it was just created.
396
42.4k
  void reset() {
397
42.4k
    clear();
398
42.4k
    init();
399
42.4k
  }
400
401
  /// Reset the currently registered delegate - otherwise assert.
402
0
  void resetDelegate(Delegate *delegate) {
403
0
    assert(TheDelegate == delegate &&
404
0
           "Only the current delegate can perform reset!");
405
0
    TheDelegate = nullptr;
406
0
  }
407
408
  /// Set the delegate. resetDelegate must be called before attempting
409
  /// to set.
410
0
  void setDelegate(Delegate *delegate) {
411
0
    assert(delegate && !TheDelegate &&
412
0
           "Attempted to set delegate to null, or to change it without "
413
0
           "first resetting it!");
414
0
415
0
    TheDelegate = delegate;
416
0
  }
417
418
4.94M
  MachineModuleInfo &getMMI() const { return MMI; }
419
3.86M
  MCContext &getContext() const { return Ctx; }
420
421
3.82M
  PseudoSourceValueManager &getPSVManager() const { return *PSVManager; }
422
423
  /// Return the DataLayout attached to the Module associated to this MF.
424
  const DataLayout &getDataLayout() const;
425
426
  /// Return the LLVM function that this machine code represents
427
148M
  const Function &getFunction() const { return F; }
428
429
  /// getName - Return the name of the corresponding LLVM function.
430
  StringRef getName() const;
431
432
  /// getFunctionNumber - Return a unique ID for the current function.
433
1.56M
  unsigned getFunctionNumber() const { return FunctionNumber; }
434
435
  /// getTarget - Return the target machine this machine code is compiled with
436
65.4M
  const TargetMachine &getTarget() const { return Target; }
437
438
  /// getSubtarget - Return the subtarget for which this machine code is being
439
  /// compiled.
440
482M
  const TargetSubtargetInfo &getSubtarget() const { return *STI; }
441
12.6k
  void setSubtarget(const TargetSubtargetInfo *ST) { STI = ST; }
442
443
  /// getSubtarget - This method returns a pointer to the specified type of
444
  /// TargetSubtargetInfo.  In debug builds, it verifies that the object being
445
  /// returned is of the correct type.
446
615M
  template<typename STC> const STC &getSubtarget() const {
447
615M
    return *static_cast<const STC *>(STI);
448
615M
  }
llvm::AArch64Subtarget const& llvm::MachineFunction::getSubtarget<llvm::AArch64Subtarget>() const
Line
Count
Source
446
569M
  template<typename STC> const STC &getSubtarget() const {
447
569M
    return *static_cast<const STC *>(STI);
448
569M
  }
llvm::GCNSubtarget const& llvm::MachineFunction::getSubtarget<llvm::GCNSubtarget>() const
Line
Count
Source
446
2.54M
  template<typename STC> const STC &getSubtarget() const {
447
2.54M
    return *static_cast<const STC *>(STI);
448
2.54M
  }
llvm::R600Subtarget const& llvm::MachineFunction::getSubtarget<llvm::R600Subtarget>() const
Line
Count
Source
446
123k
  template<typename STC> const STC &getSubtarget() const {
447
123k
    return *static_cast<const STC *>(STI);
448
123k
  }
llvm::MCSubtargetInfo const& llvm::MachineFunction::getSubtarget<llvm::MCSubtargetInfo>() const
Line
Count
Source
446
21.5M
  template<typename STC> const STC &getSubtarget() const {
447
21.5M
    return *static_cast<const STC *>(STI);
448
21.5M
  }
llvm::ARMSubtarget const& llvm::MachineFunction::getSubtarget<llvm::ARMSubtarget>() const
Line
Count
Source
446
9.58M
  template<typename STC> const STC &getSubtarget() const {
447
9.58M
    return *static_cast<const STC *>(STI);
448
9.58M
  }
llvm::BPFSubtarget const& llvm::MachineFunction::getSubtarget<llvm::BPFSubtarget>() const
Line
Count
Source
446
507
  template<typename STC> const STC &getSubtarget() const {
447
507
    return *static_cast<const STC *>(STI);
448
507
  }
llvm::HexagonSubtarget const& llvm::MachineFunction::getSubtarget<llvm::HexagonSubtarget>() const
Line
Count
Source
446
670k
  template<typename STC> const STC &getSubtarget() const {
447
670k
    return *static_cast<const STC *>(STI);
448
670k
  }
llvm::LanaiSubtarget const& llvm::MachineFunction::getSubtarget<llvm::LanaiSubtarget>() const
Line
Count
Source
446
177
  template<typename STC> const STC &getSubtarget() const {
447
177
    return *static_cast<const STC *>(STI);
448
177
  }
llvm::MipsSubtarget const& llvm::MachineFunction::getSubtarget<llvm::MipsSubtarget>() const
Line
Count
Source
446
358k
  template<typename STC> const STC &getSubtarget() const {
447
358k
    return *static_cast<const STC *>(STI);
448
358k
  }
llvm::NVPTXSubtarget const& llvm::MachineFunction::getSubtarget<llvm::NVPTXSubtarget>() const
Line
Count
Source
446
1.64k
  template<typename STC> const STC &getSubtarget() const {
447
1.64k
    return *static_cast<const STC *>(STI);
448
1.64k
  }
llvm::PPCSubtarget const& llvm::MachineFunction::getSubtarget<llvm::PPCSubtarget>() const
Line
Count
Source
446
466k
  template<typename STC> const STC &getSubtarget() const {
447
466k
    return *static_cast<const STC *>(STI);
448
466k
  }
llvm::SparcSubtarget const& llvm::MachineFunction::getSubtarget<llvm::SparcSubtarget>() const
Line
Count
Source
446
14.4k
  template<typename STC> const STC &getSubtarget() const {
447
14.4k
    return *static_cast<const STC *>(STI);
448
14.4k
  }
llvm::SystemZSubtarget const& llvm::MachineFunction::getSubtarget<llvm::SystemZSubtarget>() const
Line
Count
Source
446
84.7k
  template<typename STC> const STC &getSubtarget() const {
447
84.7k
    return *static_cast<const STC *>(STI);
448
84.7k
  }
llvm::X86Subtarget const& llvm::MachineFunction::getSubtarget<llvm::X86Subtarget>() const
Line
Count
Source
446
10.0M
  template<typename STC> const STC &getSubtarget() const {
447
10.0M
    return *static_cast<const STC *>(STI);
448
10.0M
  }
llvm::XCoreSubtarget const& llvm::MachineFunction::getSubtarget<llvm::XCoreSubtarget>() const
Line
Count
Source
446
736
  template<typename STC> const STC &getSubtarget() const {
447
736
    return *static_cast<const STC *>(STI);
448
736
  }
llvm::TargetSubtargetInfo const& llvm::MachineFunction::getSubtarget<llvm::TargetSubtargetInfo>() const
Line
Count
Source
446
191
  template<typename STC> const STC &getSubtarget() const {
447
191
    return *static_cast<const STC *>(STI);
448
191
  }
449
450
  /// getRegInfo - Return information about the registers currently in use.
451
372M
  MachineRegisterInfo &getRegInfo() { return *RegInfo; }
452
98.5M
  const MachineRegisterInfo &getRegInfo() const { return *RegInfo; }
453
454
  /// getFrameInfo - Return the frame info object for the current function.
455
  /// This object contains information about objects allocated on the stack
456
  /// frame of the current function in an abstract way.
457
23.0M
  MachineFrameInfo &getFrameInfo() { return *FrameInfo; }
458
97.4M
  const MachineFrameInfo &getFrameInfo() const { return *FrameInfo; }
459
460
  /// getJumpTableInfo - Return the jump table info object for the current
461
  /// function.  This object contains information about jump tables in the
462
  /// current function.  If the current function has no jump tables, this will
463
  /// return null.
464
4.58k
  const MachineJumpTableInfo *getJumpTableInfo() const { return JumpTableInfo; }
465
1.35M
  MachineJumpTableInfo *getJumpTableInfo() { return JumpTableInfo; }
466
467
  /// getOrCreateJumpTableInfo - Get the JumpTableInfo for this function, if it
468
  /// does already exist, allocate one.
469
  MachineJumpTableInfo *getOrCreateJumpTableInfo(unsigned JTEntryKind);
470
471
  /// getConstantPool - Return the constant pool object for the current
472
  /// function.
473
669k
  MachineConstantPool *getConstantPool() { return ConstantPool; }
474
16.3k
  const MachineConstantPool *getConstantPool() const { return ConstantPool; }
475
476
  /// getWasmEHFuncInfo - Return information about how the current function uses
477
  /// Wasm exception handling. Returns null for functions that don't use wasm
478
  /// exception handling.
479
0
  const WasmEHFuncInfo *getWasmEHFuncInfo() const { return WasmEHInfo; }
480
0
  WasmEHFuncInfo *getWasmEHFuncInfo() { return WasmEHInfo; }
481
482
  /// getWinEHFuncInfo - Return information about how the current function uses
483
  /// Windows exception handling. Returns null for functions that don't use
484
  /// funclets for exception handling.
485
145
  const WinEHFuncInfo *getWinEHFuncInfo() const { return WinEHInfo; }
486
618k
  WinEHFuncInfo *getWinEHFuncInfo() { return WinEHInfo; }
487
488
  /// getAlignment - Return the alignment (log2, not bytes) of the function.
489
503k
  unsigned getAlignment() const { return Alignment; }
490
491
  /// setAlignment - Set the alignment (log2, not bytes) of the function.
492
21.2k
  void setAlignment(unsigned A) { Alignment = A; }
493
494
  /// ensureAlignment - Make sure the function is at least 1 << A bytes aligned.
495
4.74k
  void ensureAlignment(unsigned A) {
496
4.74k
    if (Alignment < A) 
Alignment = A3.90k
;
497
4.74k
  }
498
499
  /// exposesReturnsTwice - Returns true if the function calls setjmp or
500
  /// any other similar functions with attribute "returns twice" without
501
  /// having the attribute itself.
502
28.6k
  bool exposesReturnsTwice() const {
503
28.6k
    return ExposesReturnsTwice;
504
28.6k
  }
505
506
  /// setCallsSetJmp - Set a flag that indicates if there's a call to
507
  /// a "returns twice" function.
508
277k
  void setExposesReturnsTwice(bool B) {
509
277k
    ExposesReturnsTwice = B;
510
277k
  }
511
512
  /// Returns true if the function contains any inline assembly.
513
6.49M
  bool hasInlineAsm() const {
514
6.49M
    return HasInlineAsm;
515
6.49M
  }
516
517
  /// Set a flag that indicates that the function contains inline assembly.
518
298k
  void setHasInlineAsm(bool B) {
519
298k
    HasInlineAsm = B;
520
298k
  }
521
522
1.70k
  bool hasWinCFI() const {
523
1.70k
    return HasWinCFI;
524
1.70k
  }
525
256k
  void setHasWinCFI(bool v) { HasWinCFI = v; }
526
527
  /// Get the function properties
528
3.73M
  const MachineFunctionProperties &getProperties() const { return Properties; }
529
204M
  MachineFunctionProperties &getProperties() { return Properties; }
530
531
  /// getInfo - Keep track of various per-function pieces of information for
532
  /// backends that would like to do so.
533
  ///
534
  template<typename Ty>
535
10.7M
  Ty *getInfo() {
536
10.7M
    if (!MFInfo)
537
467k
      MFInfo = Ty::template create<Ty>(Allocator, *this);
538
10.7M
    return static_cast<Ty*>(MFInfo);
539
10.7M
  }
llvm::AArch64FunctionInfo* llvm::MachineFunction::getInfo<llvm::AArch64FunctionInfo>()
Line
Count
Source
535
3.76M
  Ty *getInfo() {
536
3.76M
    if (!MFInfo)
537
254k
      MFInfo = Ty::template create<Ty>(Allocator, *this);
538
3.76M
    return static_cast<Ty*>(MFInfo);
539
3.76M
  }
llvm::SIMachineFunctionInfo* llvm::MachineFunction::getInfo<llvm::SIMachineFunctionInfo>()
Line
Count
Source
535
1.22M
  Ty *getInfo() {
536
1.22M
    if (!MFInfo)
537
20.3k
      MFInfo = Ty::template create<Ty>(Allocator, *this);
538
1.22M
    return static_cast<Ty*>(MFInfo);
539
1.22M
  }
llvm::AMDGPUMachineFunction* llvm::MachineFunction::getInfo<llvm::AMDGPUMachineFunction>()
Line
Count
Source
535
19.4k
  Ty *getInfo() {
536
19.4k
    if (!MFInfo)
537
0
      MFInfo = Ty::template create<Ty>(Allocator, *this);
538
19.4k
    return static_cast<Ty*>(MFInfo);
539
19.4k
  }
llvm::R600MachineFunctionInfo* llvm::MachineFunction::getInfo<llvm::R600MachineFunctionInfo>()
Line
Count
Source
535
107k
  Ty *getInfo() {
536
107k
    if (!MFInfo)
537
2.29k
      MFInfo = Ty::template create<Ty>(Allocator, *this);
538
107k
    return static_cast<Ty*>(MFInfo);
539
107k
  }
llvm::ARMFunctionInfo* llvm::MachineFunction::getInfo<llvm::ARMFunctionInfo>()
Line
Count
Source
535
1.53M
  Ty *getInfo() {
536
1.53M
    if (!MFInfo)
537
24.4k
      MFInfo = Ty::template create<Ty>(Allocator, *this);
538
1.53M
    return static_cast<Ty*>(MFInfo);
539
1.53M
  }
llvm::HexagonMachineFunctionInfo* llvm::MachineFunction::getInfo<llvm::HexagonMachineFunctionInfo>()
Line
Count
Source
535
83.7k
  Ty *getInfo() {
536
83.7k
    if (!MFInfo)
537
4.92k
      MFInfo = Ty::template create<Ty>(Allocator, *this);
538
83.7k
    return static_cast<Ty*>(MFInfo);
539
83.7k
  }
llvm::LanaiMachineFunctionInfo* llvm::MachineFunction::getInfo<llvm::LanaiMachineFunctionInfo>()
Line
Count
Source
535
89
  Ty *getInfo() {
536
89
    if (!MFInfo)
537
89
      MFInfo = Ty::template create<Ty>(Allocator, *this);
538
89
    return static_cast<Ty*>(MFInfo);
539
89
  }
llvm::MipsFunctionInfo* llvm::MachineFunction::getInfo<llvm::MipsFunctionInfo>()
Line
Count
Source
535
107k
  Ty *getInfo() {
536
107k
    if (!MFInfo)
537
12.7k
      MFInfo = Ty::template create<Ty>(Allocator, *this);
538
107k
    return static_cast<Ty*>(MFInfo);
539
107k
  }
llvm::MSP430MachineFunctionInfo* llvm::MachineFunction::getInfo<llvm::MSP430MachineFunctionInfo>()
Line
Count
Source
535
887
  Ty *getInfo() {
536
887
    if (!MFInfo)
537
288
      MFInfo = Ty::template create<Ty>(Allocator, *this);
538
887
    return static_cast<Ty*>(MFInfo);
539
887
  }
llvm::NVPTXMachineFunctionInfo* llvm::MachineFunction::getInfo<llvm::NVPTXMachineFunctionInfo>()
Line
Count
Source
535
29
  Ty *getInfo() {
536
29
    if (!MFInfo)
537
17
      MFInfo = Ty::template create<Ty>(Allocator, *this);
538
29
    return static_cast<Ty*>(MFInfo);
539
29
  }
llvm::PPCFunctionInfo* llvm::MachineFunction::getInfo<llvm::PPCFunctionInfo>()
Line
Count
Source
535
330k
  Ty *getInfo() {
536
330k
    if (!MFInfo)
537
9.66k
      MFInfo = Ty::template create<Ty>(Allocator, *this);
538
330k
    return static_cast<Ty*>(MFInfo);
539
330k
  }
llvm::SparcMachineFunctionInfo* llvm::MachineFunction::getInfo<llvm::SparcMachineFunctionInfo>()
Line
Count
Source
535
3.75k
  Ty *getInfo() {
536
3.75k
    if (!MFInfo)
537
692
      MFInfo = Ty::template create<Ty>(Allocator, *this);
538
3.75k
    return static_cast<Ty*>(MFInfo);
539
3.75k
  }
llvm::SystemZMachineFunctionInfo* llvm::MachineFunction::getInfo<llvm::SystemZMachineFunctionInfo>()
Line
Count
Source
535
75.6k
  Ty *getInfo() {
536
75.6k
    if (!MFInfo)
537
7.12k
      MFInfo = Ty::template create<Ty>(Allocator, *this);
538
75.6k
    return static_cast<Ty*>(MFInfo);
539
75.6k
  }
llvm::X86MachineFunctionInfo* llvm::MachineFunction::getInfo<llvm::X86MachineFunctionInfo>()
Line
Count
Source
535
3.53M
  Ty *getInfo() {
536
3.53M
    if (!MFInfo)
537
129k
      MFInfo = Ty::template create<Ty>(Allocator, *this);
538
3.53M
    return static_cast<Ty*>(MFInfo);
539
3.53M
  }
llvm::XCoreFunctionInfo* llvm::MachineFunction::getInfo<llvm::XCoreFunctionInfo>()
Line
Count
Source
535
1.76k
  Ty *getInfo() {
536
1.76k
    if (!MFInfo)
537
277
      MFInfo = Ty::template create<Ty>(Allocator, *this);
538
1.76k
    return static_cast<Ty*>(MFInfo);
539
1.76k
  }
540
541
  template<typename Ty>
542
4.41M
  const Ty *getInfo() const {
543
4.41M
     return const_cast<MachineFunction*>(this)->getInfo<Ty>();
544
4.41M
  }
llvm::AArch64FunctionInfo const* llvm::MachineFunction::getInfo<llvm::AArch64FunctionInfo>() const
Line
Count
Source
542
689k
  const Ty *getInfo() const {
543
689k
     return const_cast<MachineFunction*>(this)->getInfo<Ty>();
544
689k
  }
llvm::SIMachineFunctionInfo const* llvm::MachineFunction::getInfo<llvm::SIMachineFunctionInfo>() const
Line
Count
Source
542
542k
  const Ty *getInfo() const {
543
542k
     return const_cast<MachineFunction*>(this)->getInfo<Ty>();
544
542k
  }
llvm::AMDGPUMachineFunction const* llvm::MachineFunction::getInfo<llvm::AMDGPUMachineFunction>() const
Line
Count
Source
542
44
  const Ty *getInfo() const {
543
44
     return const_cast<MachineFunction*>(this)->getInfo<Ty>();
544
44
  }
llvm::R600MachineFunctionInfo const* llvm::MachineFunction::getInfo<llvm::R600MachineFunctionInfo>() const
Line
Count
Source
542
2.29k
  const Ty *getInfo() const {
543
2.29k
     return const_cast<MachineFunction*>(this)->getInfo<Ty>();
544
2.29k
  }
llvm::ARMFunctionInfo const* llvm::MachineFunction::getInfo<llvm::ARMFunctionInfo>() const
Line
Count
Source
542
476k
  const Ty *getInfo() const {
543
476k
     return const_cast<MachineFunction*>(this)->getInfo<Ty>();
544
476k
  }
llvm::HexagonMachineFunctionInfo const* llvm::MachineFunction::getInfo<llvm::HexagonMachineFunctionInfo>() const
Line
Count
Source
542
73.8k
  const Ty *getInfo() const {
543
73.8k
     return const_cast<MachineFunction*>(this)->getInfo<Ty>();
544
73.8k
  }
llvm::MipsFunctionInfo const* llvm::MachineFunction::getInfo<llvm::MipsFunctionInfo>() const
Line
Count
Source
542
1.63k
  const Ty *getInfo() const {
543
1.63k
     return const_cast<MachineFunction*>(this)->getInfo<Ty>();
544
1.63k
  }
llvm::PPCFunctionInfo const* llvm::MachineFunction::getInfo<llvm::PPCFunctionInfo>() const
Line
Count
Source
542
267k
  const Ty *getInfo() const {
543
267k
     return const_cast<MachineFunction*>(this)->getInfo<Ty>();
544
267k
  }
llvm::SparcMachineFunctionInfo const* llvm::MachineFunction::getInfo<llvm::SparcMachineFunctionInfo>() const
Line
Count
Source
542
1.52k
  const Ty *getInfo() const {
543
1.52k
     return const_cast<MachineFunction*>(this)->getInfo<Ty>();
544
1.52k
  }
llvm::SystemZMachineFunctionInfo const* llvm::MachineFunction::getInfo<llvm::SystemZMachineFunctionInfo>() const
Line
Count
Source
542
38.8k
  const Ty *getInfo() const {
543
38.8k
     return const_cast<MachineFunction*>(this)->getInfo<Ty>();
544
38.8k
  }
llvm::X86MachineFunctionInfo const* llvm::MachineFunction::getInfo<llvm::X86MachineFunctionInfo>() const
Line
Count
Source
542
2.31M
  const Ty *getInfo() const {
543
2.31M
     return const_cast<MachineFunction*>(this)->getInfo<Ty>();
544
2.31M
  }
545
546
  /// getBlockNumbered - MachineBasicBlocks are automatically numbered when they
547
  /// are inserted into the machine function.  The block number for a machine
548
  /// basic block can be found by using the MBB::getNumber method, this method
549
  /// provides the inverse mapping.
550
116M
  MachineBasicBlock *getBlockNumbered(unsigned N) const {
551
116M
    assert(N < MBBNumbering.size() && "Illegal block number");
552
116M
    assert(MBBNumbering[N] && "Block was removed from the machine function!");
553
116M
    return MBBNumbering[N];
554
116M
  }
555
556
  /// Should we be emitting segmented stack stuff for the function
557
  bool shouldSplitStack() const;
558
559
  /// getNumBlockIDs - Return the number of MBB ID's allocated.
560
42.4M
  unsigned getNumBlockIDs() const { return (unsigned)MBBNumbering.size(); }
561
562
  /// RenumberBlocks - This discards all of the MachineBasicBlock numbers and
563
  /// recomputes them.  This guarantees that the MBB numbers are sequential,
564
  /// dense, and match the ordering of the blocks within the function.  If a
565
  /// specific MachineBasicBlock is specified, only that block and those after
566
  /// it are renumbered.
567
  void RenumberBlocks(MachineBasicBlock *MBBFrom = nullptr);
568
569
  /// print - Print out the MachineFunction in a format suitable for debugging
570
  /// to the specified stream.
571
  void print(raw_ostream &OS, const SlotIndexes* = nullptr) const;
572
573
  /// viewCFG - This function is meant for use from the debugger.  You can just
574
  /// say 'call F->viewCFG()' and a ghostview window should pop up from the
575
  /// program, displaying the CFG of the current function with the code for each
576
  /// basic block inside.  This depends on there being a 'dot' and 'gv' program
577
  /// in your path.
578
  void viewCFG() const;
579
580
  /// viewCFGOnly - This function is meant for use from the debugger.  It works
581
  /// just like viewCFG, but it does not include the contents of basic blocks
582
  /// into the nodes, just the label.  If you are only interested in the CFG
583
  /// this can make the graph smaller.
584
  ///
585
  void viewCFGOnly() const;
586
587
  /// dump - Print the current MachineFunction to cerr, useful for debugger use.
588
  void dump() const;
589
590
  /// Run the current MachineFunction through the machine code verifier, useful
591
  /// for debugger use.
592
  /// \returns true if no problems were found.
593
  bool verify(Pass *p = nullptr, const char *Banner = nullptr,
594
              bool AbortOnError = true) const;
595
596
  // Provide accessors for the MachineBasicBlock list...
597
  using iterator = BasicBlockListType::iterator;
598
  using const_iterator = BasicBlockListType::const_iterator;
599
  using const_reverse_iterator = BasicBlockListType::const_reverse_iterator;
600
  using reverse_iterator = BasicBlockListType::reverse_iterator;
601
602
  /// Support for MachineBasicBlock::getNextNode().
603
  static BasicBlockListType MachineFunction::*
604
23.2M
  getSublistAccess(MachineBasicBlock *) {
605
23.2M
    return &MachineFunction::BasicBlocks;
606
23.2M
  }
607
608
  /// addLiveIn - Add the specified physical register as a live-in value and
609
  /// create a corresponding virtual register for it.
610
  unsigned addLiveIn(unsigned PReg, const TargetRegisterClass *RC);
611
612
  //===--------------------------------------------------------------------===//
613
  // BasicBlock accessor functions.
614
  //
615
32.6M
  iterator                 begin()       { return BasicBlocks.begin(); }
616
11.7M
  const_iterator           begin() const { return BasicBlocks.begin(); }
617
103M
  iterator                 end  ()       { return BasicBlocks.end();   }
618
10.4M
  const_iterator           end  () const { return BasicBlocks.end();   }
619
620
965k
  reverse_iterator        rbegin()       { return BasicBlocks.rbegin(); }
621
57
  const_reverse_iterator  rbegin() const { return BasicBlocks.rbegin(); }
622
961k
  reverse_iterator        rend  ()       { return BasicBlocks.rend();   }
623
0
  const_reverse_iterator  rend  () const { return BasicBlocks.rend();   }
624
625
4.34M
  unsigned                  size() const { return (unsigned)BasicBlocks.size();}
626
6.86M
  bool                     empty() const { return BasicBlocks.empty(); }
627
6.74M
  const MachineBasicBlock &front() const { return BasicBlocks.front(); }
628
10.5M
        MachineBasicBlock &front()       { return BasicBlocks.front(); }
629
398k
  const MachineBasicBlock & back() const { return BasicBlocks.back(); }
630
280k
        MachineBasicBlock & back()       { return BasicBlocks.back(); }
631
632
3.88M
  void push_back (MachineBasicBlock *MBB) { BasicBlocks.push_back (MBB); }
633
314
  void push_front(MachineBasicBlock *MBB) { BasicBlocks.push_front(MBB); }
634
474k
  void insert(iterator MBBI, MachineBasicBlock *MBB) {
635
474k
    BasicBlocks.insert(MBBI, MBB);
636
474k
  }
637
316k
  void splice(iterator InsertPt, iterator MBBI) {
638
316k
    BasicBlocks.splice(InsertPt, BasicBlocks, MBBI);
639
316k
  }
640
1.13M
  void splice(iterator InsertPt, MachineBasicBlock *MBB) {
641
1.13M
    BasicBlocks.splice(InsertPt, BasicBlocks, MBB);
642
1.13M
  }
643
0
  void splice(iterator InsertPt, iterator MBBI, iterator MBBE) {
644
0
    BasicBlocks.splice(InsertPt, BasicBlocks, MBBI, MBBE);
645
0
  }
646
647
0
  void remove(iterator MBBI) { BasicBlocks.remove(MBBI); }
648
234k
  void remove(MachineBasicBlock *MBBI) { BasicBlocks.remove(MBBI); }
649
67
  void erase(iterator MBBI) { BasicBlocks.erase(MBBI); }
650
349k
  void erase(MachineBasicBlock *MBBI) { BasicBlocks.erase(MBBI); }
651
652
  template <typename Comp>
653
70
  void sort(Comp comp) {
654
70
    BasicBlocks.sort(comp);
655
70
  }
656
657
  /// Return the number of \p MachineInstrs in this \p MachineFunction.
658
221
  unsigned getInstructionCount() const {
659
221
    unsigned InstrCount = 0;
660
221
    for (const MachineBasicBlock &MBB : BasicBlocks)
661
240
      InstrCount += MBB.size();
662
221
    return InstrCount;
663
221
  }
664
665
  //===--------------------------------------------------------------------===//
666
  // Internal functions used to automatically number MachineBasicBlocks
667
668
  /// Adds the MBB to the internal numbering. Returns the unique number
669
  /// assigned to the MBB.
670
4.36M
  unsigned addToMBBNumbering(MachineBasicBlock *MBB) {
671
4.36M
    MBBNumbering.push_back(MBB);
672
4.36M
    return (unsigned)MBBNumbering.size()-1;
673
4.36M
  }
674
675
  /// removeFromMBBNumbering - Remove the specific machine basic block from our
676
  /// tracker, this is only really to be used by the MachineBasicBlock
677
  /// implementation.
678
4.36M
  void removeFromMBBNumbering(unsigned N) {
679
4.36M
    assert(N < MBBNumbering.size() && "Illegal basic block #");
680
4.36M
    MBBNumbering[N] = nullptr;
681
4.36M
  }
682
683
  /// CreateMachineInstr - Allocate a new MachineInstr. Use this instead
684
  /// of `new MachineInstr'.
685
  MachineInstr *CreateMachineInstr(const MCInstrDesc &MCID, const DebugLoc &DL,
686
                                   bool NoImp = false);
687
688
  /// Create a new MachineInstr which is a copy of \p Orig, identical in all
689
  /// ways except the instruction has no parent, prev, or next. Bundling flags
690
  /// are reset.
691
  ///
692
  /// Note: Clones a single instruction, not whole instruction bundles.
693
  /// Does not perform target specific adjustments; consider using
694
  /// TargetInstrInfo::duplicate() instead.
695
  MachineInstr *CloneMachineInstr(const MachineInstr *Orig);
696
697
  /// Clones instruction or the whole instruction bundle \p Orig and insert
698
  /// into \p MBB before \p InsertBefore.
699
  ///
700
  /// Note: Does not perform target specific adjustments; consider using
701
  /// TargetInstrInfo::duplicate() intead.
702
  MachineInstr &CloneMachineInstrBundle(MachineBasicBlock &MBB,
703
      MachineBasicBlock::iterator InsertBefore, const MachineInstr &Orig);
704
705
  /// DeleteMachineInstr - Delete the given MachineInstr.
706
  void DeleteMachineInstr(MachineInstr *MI);
707
708
  /// CreateMachineBasicBlock - Allocate a new MachineBasicBlock. Use this
709
  /// instead of `new MachineBasicBlock'.
710
  MachineBasicBlock *CreateMachineBasicBlock(const BasicBlock *bb = nullptr);
711
712
  /// DeleteMachineBasicBlock - Delete the given MachineBasicBlock.
713
  void DeleteMachineBasicBlock(MachineBasicBlock *MBB);
714
715
  /// getMachineMemOperand - Allocate a new MachineMemOperand.
716
  /// MachineMemOperands are owned by the MachineFunction and need not be
717
  /// explicitly deallocated.
718
  MachineMemOperand *getMachineMemOperand(
719
      MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s,
720
      unsigned base_alignment, const AAMDNodes &AAInfo = AAMDNodes(),
721
      const MDNode *Ranges = nullptr,
722
      SyncScope::ID SSID = SyncScope::System,
723
      AtomicOrdering Ordering = AtomicOrdering::NotAtomic,
724
      AtomicOrdering FailureOrdering = AtomicOrdering::NotAtomic);
725
726
  /// getMachineMemOperand - Allocate a new MachineMemOperand by copying
727
  /// an existing one, adjusting by an offset and using the given size.
728
  /// MachineMemOperands are owned by the MachineFunction and need not be
729
  /// explicitly deallocated.
730
  MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
731
                                          int64_t Offset, uint64_t Size);
732
733
  /// Allocate a new MachineMemOperand by copying an existing one,
734
  /// replacing only AliasAnalysis information. MachineMemOperands are owned
735
  /// by the MachineFunction and need not be explicitly deallocated.
736
  MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
737
                                          const AAMDNodes &AAInfo);
738
739
  using OperandCapacity = ArrayRecycler<MachineOperand>::Capacity;
740
741
  /// Allocate an array of MachineOperands. This is only intended for use by
742
  /// internal MachineInstr functions.
743
78.9M
  MachineOperand *allocateOperandArray(OperandCapacity Cap) {
744
78.9M
    return OperandRecycler.allocate(Cap, Allocator);
745
78.9M
  }
746
747
  /// Dellocate an array of MachineOperands and recycle the memory. This is
748
  /// only intended for use by internal MachineInstr functions.
749
  /// Cap must be the same capacity that was used to allocate the array.
750
47.5M
  void deallocateOperandArray(OperandCapacity Cap, MachineOperand *Array) {
751
47.5M
    OperandRecycler.deallocate(Cap, Array);
752
47.5M
  }
753
754
  /// Allocate and initialize a register mask with @p NumRegister bits.
755
  uint32_t *allocateRegMask();
756
757
  /// Allocate and construct an extra info structure for a `MachineInstr`.
758
  ///
759
  /// This is allocated on the function's allocator and so lives the life of
760
  /// the function.
761
  MachineInstr::ExtraInfo *
762
  createMIExtraInfo(ArrayRef<MachineMemOperand *> MMOs,
763
                    MCSymbol *PreInstrSymbol = nullptr,
764
                    MCSymbol *PostInstrSymbol = nullptr);
765
766
  /// Allocate a string and populate it with the given external symbol name.
767
  const char *createExternalSymbolName(StringRef Name);
768
769
  //===--------------------------------------------------------------------===//
770
  // Label Manipulation.
771
772
  /// getJTISymbol - Return the MCSymbol for the specified non-empty jump table.
773
  /// If isLinkerPrivate is specified, an 'l' label is returned, otherwise a
774
  /// normal 'L' label is returned.
775
  MCSymbol *getJTISymbol(unsigned JTI, MCContext &Ctx,
776
                         bool isLinkerPrivate = false) const;
777
778
  /// getPICBaseSymbol - Return a function-local symbol to represent the PIC
779
  /// base.
780
  MCSymbol *getPICBaseSymbol() const;
781
782
  /// Returns a reference to a list of cfi instructions in the function's
783
  /// prologue.  Used to construct frame maps for debug and exception handling
784
  /// comsumers.
785
495k
  const std::vector<MCCFIInstruction> &getFrameInstructions() const {
786
495k
    return FrameInstructions;
787
495k
  }
788
789
482k
  LLVM_NODISCARD unsigned addFrameInst(const MCCFIInstruction &Inst) {
790
482k
    FrameInstructions.push_back(Inst);
791
482k
    return FrameInstructions.size() - 1;
792
482k
  }
793
794
  /// \name Exception Handling
795
  /// \{
796
797
2.93M
  bool callsEHReturn() const { return CallsEHReturn; }
798
29
  void setCallsEHReturn(bool b) { CallsEHReturn = b; }
799
800
1.83M
  bool callsUnwindInit() const { return CallsUnwindInit; }
801
15
  void setCallsUnwindInit(bool b) { CallsUnwindInit = b; }
802
803
1.71M
  bool hasEHScopes() const { return HasEHScopes; }
804
242
  void setHasEHScopes(bool V) { HasEHScopes = V; }
805
806
2.50M
  bool hasEHFunclets() const { return HasEHFunclets; }
807
242
  void setHasEHFunclets(bool V) { HasEHFunclets = V; }
808
809
  /// Find or create an LandingPadInfo for the specified MachineBasicBlock.
810
  LandingPadInfo &getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad);
811
812
  /// Remap landing pad labels and remove any deleted landing pads.
813
  void tidyLandingPads(DenseMap<MCSymbol*, uintptr_t> *LPMap = nullptr);
814
815
  /// Return a reference to the landing pad info for the current function.
816
1.98M
  const std::vector<LandingPadInfo> &getLandingPads() const {
817
1.98M
    return LandingPads;
818
1.98M
  }
819
820
  /// Provide the begin and end labels of an invoke style call and associate it
821
  /// with a try landing pad block.
822
  void addInvoke(MachineBasicBlock *LandingPad,
823
                 MCSymbol *BeginLabel, MCSymbol *EndLabel);
824
825
  /// Add a new panding pad.  Returns the label ID for the landing pad entry.
826
  MCSymbol *addLandingPad(MachineBasicBlock *LandingPad);
827
828
  /// Provide the catch typeinfo for a landing pad.
829
  void addCatchTypeInfo(MachineBasicBlock *LandingPad,
830
                        ArrayRef<const GlobalValue *> TyInfo);
831
832
  /// Provide the filter typeinfo for a landing pad.
833
  void addFilterTypeInfo(MachineBasicBlock *LandingPad,
834
                         ArrayRef<const GlobalValue *> TyInfo);
835
836
  /// Add a cleanup action for a landing pad.
837
  void addCleanup(MachineBasicBlock *LandingPad);
838
839
  void addSEHCatchHandler(MachineBasicBlock *LandingPad, const Function *Filter,
840
                          const BlockAddress *RecoverBA);
841
842
  void addSEHCleanupHandler(MachineBasicBlock *LandingPad,
843
                            const Function *Cleanup);
844
845
  /// Return the type id for the specified typeinfo.  This is function wide.
846
  unsigned getTypeIDFor(const GlobalValue *TI);
847
848
  /// Return the id of the filter encoded by TyIds.  This is function wide.
849
  int getFilterIDFor(std::vector<unsigned> &TyIds);
850
851
  /// Map the landing pad's EH symbol to the call site indexes.
852
  void setCallSiteLandingPad(MCSymbol *Sym, ArrayRef<unsigned> Sites);
853
854
  /// Get the call site indexes for a landing pad EH symbol.
855
128
  SmallVectorImpl<unsigned> &getCallSiteLandingPad(MCSymbol *Sym) {
856
128
    assert(hasCallSiteLandingPad(Sym) &&
857
128
           "missing call site number for landing pad!");
858
128
    return LPadToCallSiteMap[Sym];
859
128
  }
860
861
  /// Return true if the landing pad Eh symbol has an associated call site.
862
128
  bool hasCallSiteLandingPad(MCSymbol *Sym) {
863
128
    return !LPadToCallSiteMap[Sym].empty();
864
128
  }
865
866
  /// Map the begin label for a call site.
867
175
  void setCallSiteBeginLabel(MCSymbol *BeginLabel, unsigned Site) {
868
175
    CallSiteMap[BeginLabel] = Site;
869
175
  }
870
871
  /// Get the call site number for a begin label.
872
175
  unsigned getCallSiteBeginLabel(MCSymbol *BeginLabel) const {
873
175
    assert(hasCallSiteBeginLabel(BeginLabel) &&
874
175
           "Missing call site number for EH_LABEL!");
875
175
    return CallSiteMap.lookup(BeginLabel);
876
175
  }
877
878
  /// Return true if the begin label has a call site number associated with it.
879
0
  bool hasCallSiteBeginLabel(MCSymbol *BeginLabel) const {
880
0
    return CallSiteMap.count(BeginLabel);
881
0
  }
882
883
  /// Record annotations associated with a particular label.
884
1
  void addCodeViewAnnotation(MCSymbol *Label, MDNode *MD) {
885
1
    CodeViewAnnotations.push_back({Label, MD});
886
1
  }
887
888
207
  ArrayRef<std::pair<MCSymbol *, MDNode *>> getCodeViewAnnotations() const {
889
207
    return CodeViewAnnotations;
890
207
  }
891
892
  /// Return a reference to the C++ typeinfo for the current function.
893
5.34k
  const std::vector<const GlobalValue *> &getTypeInfos() const {
894
5.34k
    return TypeInfos;
895
5.34k
  }
896
897
  /// Return a reference to the typeids encoding filters used in the current
898
  /// function.
899
8.90k
  const std::vector<unsigned> &getFilterIds() const {
900
8.90k
    return FilterIds;
901
8.90k
  }
902
903
  /// \}
904
905
  /// Collect information used to emit debugging information of a variable.
906
  void setVariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr,
907
703
                          int Slot, const DILocation *Loc) {
908
703
    VariableDbgInfos.emplace_back(Var, Expr, Slot, Loc);
909
703
  }
910
911
332k
  VariableDbgInfoMapTy &getVariableDbgInfo() { return VariableDbgInfos; }
912
4.79k
  const VariableDbgInfoMapTy &getVariableDbgInfo() const {
913
4.79k
    return VariableDbgInfos;
914
4.79k
  }
915
};
916
917
/// \name Exception Handling
918
/// \{
919
920
/// Extract the exception handling information from the landingpad instruction
921
/// and add them to the specified machine module info.
922
void addLandingPadInfo(const LandingPadInst &I, MachineBasicBlock &MBB);
923
924
/// \}
925
926
//===--------------------------------------------------------------------===//
927
// GraphTraits specializations for function basic block graphs (CFGs)
928
//===--------------------------------------------------------------------===//
929
930
// Provide specializations of GraphTraits to be able to treat a
931
// machine function as a graph of machine basic blocks... these are
932
// the same as the machine basic block iterators, except that the root
933
// node is implicitly the first node of the function.
934
//
935
template <> struct GraphTraits<MachineFunction*> :
936
  public GraphTraits<MachineBasicBlock*> {
937
4.17M
  static NodeRef getEntryNode(MachineFunction *F) { return &F->front(); }
938
939
  // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
940
  using nodes_iterator = pointer_iterator<MachineFunction::iterator>;
941
942
1.39M
  static nodes_iterator nodes_begin(MachineFunction *F) {
943
1.39M
    return nodes_iterator(F->begin());
944
1.39M
  }
945
946
1.38M
  static nodes_iterator nodes_end(MachineFunction *F) {
947
1.38M
    return nodes_iterator(F->end());
948
1.38M
  }
949
950
  static unsigned       size       (MachineFunction *F) { return F->size(); }
951
};
952
template <> struct GraphTraits<const MachineFunction*> :
953
  public GraphTraits<const MachineBasicBlock*> {
954
1.61M
  static NodeRef getEntryNode(const MachineFunction *F) { return &F->front(); }
955
956
  // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
957
  using nodes_iterator = pointer_iterator<MachineFunction::const_iterator>;
958
959
  static nodes_iterator nodes_begin(const MachineFunction *F) {
960
    return nodes_iterator(F->begin());
961
  }
962
963
  static nodes_iterator nodes_end  (const MachineFunction *F) {
964
    return nodes_iterator(F->end());
965
  }
966
967
  static unsigned       size       (const MachineFunction *F)  {
968
    return F->size();
969
  }
970
};
971
972
// Provide specializations of GraphTraits to be able to treat a function as a
973
// graph of basic blocks... and to walk it in inverse order.  Inverse order for
974
// a function is considered to be when traversing the predecessor edges of a BB
975
// instead of the successor edges.
976
//
977
template <> struct GraphTraits<Inverse<MachineFunction*>> :
978
  public GraphTraits<Inverse<MachineBasicBlock*>> {
979
  static NodeRef getEntryNode(Inverse<MachineFunction *> G) {
980
    return &G.Graph->front();
981
  }
982
};
983
template <> struct GraphTraits<Inverse<const MachineFunction*>> :
984
  public GraphTraits<Inverse<const MachineBasicBlock*>> {
985
  static NodeRef getEntryNode(Inverse<const MachineFunction *> G) {
986
    return &G.Graph->front();
987
  }
988
};
989
990
} // end namespace llvm
991
992
#endif // LLVM_CODEGEN_MACHINEFUNCTION_H