Coverage Report

Created: 2018-07-19 03:59

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