Coverage Report

Created: 2019-07-24 05:18

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