Debian Codegraph @

suite/synctools/tablegen/include/llvm/CodeGen/MachineFunction.h

raw symbols SCIP
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/SmallVector.h"
25 #include "llvm/ADT/ilist.h"
26 #include "llvm/ADT/iterator.h"
27 #include "llvm/Analysis/EHPersonalities.h"
28 #include "llvm/CodeGen/MachineBasicBlock.h"
29 #include "llvm/CodeGen/MachineInstr.h"
30 #include "llvm/CodeGen/MachineMemOperand.h"
31 #include "llvm/Support/Allocator.h"
32 #include "llvm/Support/ArrayRecycler.h"
33 #include "llvm/Support/AtomicOrdering.h"
34 #include "llvm/Support/Compiler.h"
35 #include "llvm/Support/Recycler.h"
36 #include "llvm/Target/TargetOptions.h"
37 #include <cassert>
38 #include <cstdint>
39 #include <memory>
40 #include <utility>
41 #include <vector>
42
43 namespace llvm {
44
45 class BasicBlock;
46 class BlockAddress;
47 class DataLayout;
48 class DebugLoc;
49 struct DenormalMode;
50 class DIExpression;
51 class DILocalVariable;
52 class DILocation;
53 class Function;
54 class GISelChangeObserver;
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 MCSection;
67 class Pass;
68 class PseudoSourceValueManager;
69 class raw_ostream;
70 class SlotIndexes;
71 class StringRef;
72 class TargetRegisterClass;
73 class TargetSubtargetInfo;
74 struct WasmEHFuncInfo;
75 struct WinEHFuncInfo;
76
77 template <> struct ilist_alloc_traits<MachineBasicBlock> {
78 void deleteNode(MachineBasicBlock *MBB);
79 };
80
81 template <> struct ilist_callback_traits<MachineBasicBlock> {
82 void addNodeToList(MachineBasicBlock* N);
83 void removeNodeFromList(MachineBasicBlock* N);
84
85 template <class Iterator>
86 void transferNodesFromList(ilist_callback_traits &OldList, Iterator, Iterator) {
87 assert(this == &OldList && "never transfer MBBs between functions");
88 }
89 };
90
91 /// MachineFunctionInfo - This class can be derived from and used by targets to
92 /// hold private target-specific information for each MachineFunction. Objects
93 /// of type are accessed/created with MF::getInfo and destroyed when the
94 /// MachineFunction is destroyed.
95 struct MachineFunctionInfo {
96 virtual ~MachineFunctionInfo();
97
98 /// Factory function: default behavior is to call new using the
99 /// supplied allocator.
100 ///
101 /// This function can be overridden in a derive class.
102 template<typename Ty>
103 static Ty *create(BumpPtrAllocator &Allocator, MachineFunction &MF) {
104 return new (Allocator.Allocate<Ty>()) Ty(MF);
105 }
106 };
107
108 /// Properties which a MachineFunction may have at a given point in time.
109 /// Each of these has checking code in the MachineVerifier, and passes can
110 /// require that a property be set.
111 class MachineFunctionProperties {
112 // Possible TODO: Allow targets to extend this (perhaps by allowing the
113 // constructor to specify the size of the bit vector)
114 // Possible TODO: Allow requiring the negative (e.g. VRegsAllocated could be
115 // stated as the negative of "has vregs"
116
117 public:
118 // The properties are stated in "positive" form; i.e. a pass could require
119 // that the property hold, but not that it does not hold.
120
121 // Property descriptions:
122 // IsSSA: True when the machine function is in SSA form and virtual registers
123 // have a single def.
124 // NoPHIs: The machine function does not contain any PHI instruction.
125 // TracksLiveness: True when tracking register liveness accurately.
126 // While this property is set, register liveness information in basic block
127 // live-in lists and machine instruction operands (e.g. implicit defs) is
128 // accurate, kill flags are conservatively accurate (kill flag correctly
129 // indicates the last use of a register, an operand without kill flag may or
130 // may not be the last use of a register). This means it can be used to
131 // change the code in ways that affect the values in registers, for example
132 // by the register scavenger.
133 // When this property is cleared at a very late time, liveness is no longer
134 // reliable.
135 // NoVRegs: The machine function does not use any virtual registers.
136 // Legalized: In GlobalISel: the MachineLegalizer ran and all pre-isel generic
137 // instructions have been legalized; i.e., all instructions are now one of:
138 // - generic and always legal (e.g., COPY)
139 // - target-specific
140 // - legal pre-isel generic instructions.
141 // RegBankSelected: In GlobalISel: the RegBankSelect pass ran and all generic
142 // virtual registers have been assigned to a register bank.
143 // Selected: In GlobalISel: the InstructionSelect pass ran and all pre-isel
144 // generic instructions have been eliminated; i.e., all instructions are now
145 // target-specific or non-pre-isel generic instructions (e.g., COPY).
146 // Since only pre-isel generic instructions can have generic virtual register
147 // operands, this also means that all generic virtual registers have been
148 // constrained to virtual registers (assigned to register classes) and that
149 // all sizes attached to them have been eliminated.
150 // TiedOpsRewritten: The twoaddressinstruction pass will set this flag, it
151 // means that tied-def have been rewritten to meet the RegConstraint.
152 // FailsVerification: Means that the function is not expected to pass machine
153 // verification. This can be set by passes that introduce known problems that
154 // have not been fixed yet.
155 // TracksDebugUserValues: Without this property enabled, debug instructions
156 // such as DBG_VALUE are allowed to reference virtual registers even if those
157 // registers do not have a definition. With the property enabled virtual
158 // registers must only be used if they have a definition. This property
159 // allows earlier passes in the pipeline to skip updates of `DBG_VALUE`
160 // instructions to save compile time.
161 enum class Property : unsigned {
162 IsSSA,
163 NoPHIs,
164 TracksLiveness,
165 NoVRegs,
166 FailedISel,
167 Legalized,
168 RegBankSelected,
169 Selected,
170 TiedOpsRewritten,
171 FailsVerification,
172 TracksDebugUserValues,
173 LastProperty = TracksDebugUserValues,
174 };
175
176 bool hasProperty(Property P) const {
177 return Properties[static_cast<unsigned>(P)];
178 }
179
180 MachineFunctionProperties &set(Property P) {
181 Properties.set(static_cast<unsigned>(P));
182 return *this;
183 }
184
185 MachineFunctionProperties &reset(Property P) {
186 Properties.reset(static_cast<unsigned>(P));
187 return *this;
188 }
189
190 /// Reset all the properties.
191 MachineFunctionProperties &reset() {
192 Properties.reset();
193 return *this;
194 }
195
196 MachineFunctionProperties &set(const MachineFunctionProperties &MFP) {
197 Properties |= MFP.Properties;
198 return *this;
199 }
200
201 MachineFunctionProperties &reset(const MachineFunctionProperties &MFP) {
202 Properties.reset(MFP.Properties);
203 return *this;
204 }
205
206 // Returns true if all properties set in V (i.e. required by a pass) are set
207 // in this.
208 bool verifyRequiredProperties(const MachineFunctionProperties &V) const {
209 return !V.Properties.test(Properties);
210 }
211
212 /// Print the MachineFunctionProperties in human-readable form.
213 void print(raw_ostream &OS) const;
214
215 private:
216 BitVector Properties =
217 BitVector(static_cast<unsigned>(Property::LastProperty)+1);
218 };
219
220 struct SEHHandler {
221 /// Filter or finally function. Null indicates a catch-all.
222 const Function *FilterOrFinally;
223
224 /// Address of block to recover at. Null for a finally handler.
225 const BlockAddress *RecoverBA;
226 };
227
228 /// This structure is used to retain landing pad info for the current function.
229 struct LandingPadInfo {
230 MachineBasicBlock *LandingPadBlock; // Landing pad block.
231 SmallVector<MCSymbol *, 1> BeginLabels; // Labels prior to invoke.
232 SmallVector<MCSymbol *, 1> EndLabels; // Labels after invoke.
233 SmallVector<SEHHandler, 1> SEHHandlers; // SEH handlers active at this lpad.
234 MCSymbol *LandingPadLabel = nullptr; // Label at beginning of landing pad.
235 std::vector<int> TypeIds; // List of type ids (filters negative).
236
237 explicit LandingPadInfo(MachineBasicBlock *MBB)
238 : LandingPadBlock(MBB) {}
239 };
240
241 class LLVM_EXTERNAL_VISIBILITY MachineFunction {
242 Function &F;
243 const LLVMTargetMachine &Target;
244 const TargetSubtargetInfo *STI;
245 MCContext &Ctx;
246 MachineModuleInfo &MMI;
247
248 // RegInfo - Information about each register in use in the function.
249 MachineRegisterInfo *RegInfo;
250
251 // Used to keep track of target-specific per-machine function information for
252 // the target implementation.
253 MachineFunctionInfo *MFInfo;
254
255 // Keep track of objects allocated on the stack.
256 MachineFrameInfo *FrameInfo;
257
258 // Keep track of constants which are spilled to memory
259 MachineConstantPool *ConstantPool;
260
261 // Keep track of jump tables for switch instructions
262 MachineJumpTableInfo *JumpTableInfo;
263
264 // Keep track of the function section.
265 MCSection *Section = nullptr;
266
267 // Keeps track of Wasm exception handling related data. This will be null for
268 // functions that aren't using a wasm EH personality.
269 WasmEHFuncInfo *WasmEHInfo = nullptr;
270
271 // Keeps track of Windows exception handling related data. This will be null
272 // for functions that aren't using a funclet-based EH personality.
273 WinEHFuncInfo *WinEHInfo = nullptr;
274
275 // Function-level unique numbering for MachineBasicBlocks. When a
276 // MachineBasicBlock is inserted into a MachineFunction is it automatically
277 // numbered and this vector keeps track of the mapping from ID's to MBB's.
278 std::vector<MachineBasicBlock*> MBBNumbering;
279
280 // Unary encoding of basic block symbols is used to reduce size of ".strtab".
281 // Basic block number 'i' gets a prefix of length 'i'. The ith character also
282 // denotes the type of basic block number 'i'. Return blocks are marked with
283 // 'r', landing pads with 'l' and regular blocks with 'a'.
284 std::vector<char> BBSectionsSymbolPrefix;
285
286 // Pool-allocate MachineFunction-lifetime and IR objects.
287 BumpPtrAllocator Allocator;
288
289 // Allocation management for instructions in function.
290 Recycler<MachineInstr> InstructionRecycler;
291
292 // Allocation management for operand arrays on instructions.
293 ArrayRecycler<MachineOperand> OperandRecycler;
294
295 // Allocation management for basic blocks in function.
296 Recycler<MachineBasicBlock> BasicBlockRecycler;
297
298 // List of machine basic blocks in function
299 using BasicBlockListType = ilist<MachineBasicBlock>;
300 BasicBlockListType BasicBlocks;
301
302 /// FunctionNumber - This provides a unique ID for each function emitted in
303 /// this translation unit.
304 ///
305 unsigned FunctionNumber;
306
307 /// Alignment - The alignment of the function.
308 Align Alignment;
309
310 /// ExposesReturnsTwice - True if the function calls setjmp or related
311 /// functions with attribute "returns twice", but doesn't have
312 /// the attribute itself.
313 /// This is used to limit optimizations which cannot reason
314 /// about the control flow of such functions.
315 bool ExposesReturnsTwice = false;
316
317 /// True if the function includes any inline assembly.
318 bool HasInlineAsm = false;
319
320 /// True if any WinCFI instruction have been emitted in this function.
321 bool HasWinCFI = false;
322
323 /// Current high-level properties of the IR of the function (e.g. is in SSA
324 /// form or whether registers have been allocated)
325 MachineFunctionProperties Properties;
326
327 // Allocation management for pseudo source values.
328 std::unique_ptr<PseudoSourceValueManager> PSVManager;
329
330 /// List of moves done by a function's prolog. Used to construct frame maps
331 /// by debug and exception handling consumers.
332 std::vector<MCCFIInstruction> FrameInstructions;
333
334 /// List of basic blocks immediately following calls to _setjmp. Used to
335 /// construct a table of valid longjmp targets for Windows Control Flow Guard.
336 std::vector<MCSymbol *> LongjmpTargets;
337
338 /// List of basic blocks that are the target of catchrets. Used to construct
339 /// a table of valid targets for Windows EHCont Guard.
340 std::vector<MCSymbol *> CatchretTargets;
341
342 /// \name Exception Handling
343 /// \{
344
345 /// List of LandingPadInfo describing the landing pad information.
346 std::vector<LandingPadInfo> LandingPads;
347
348 /// Map a landing pad's EH symbol to the call site indexes.
349 DenseMap<MCSymbol*, SmallVector<unsigned, 4>> LPadToCallSiteMap;
350
351 /// Map a landing pad to its index.
352 DenseMap<const MachineBasicBlock *, unsigned> WasmLPadToIndexMap;
353
354 /// Map of invoke call site index values to associated begin EH_LABEL.
355 DenseMap<MCSymbol*, unsigned> CallSiteMap;
356
357 /// CodeView label annotations.
358 std::vector<std::pair<MCSymbol *, MDNode *>> CodeViewAnnotations;
359
360 bool CallsEHReturn = false;
361 bool CallsUnwindInit = false;
362 bool HasEHCatchret = false;
363 bool HasEHScopes = false;
364 bool HasEHFunclets = false;
365
366 /// Section Type for basic blocks, only relevant with basic block sections.
367 BasicBlockSection BBSectionsType = BasicBlockSection::None;
368
369 /// List of C++ TypeInfo used.
370 std::vector<const GlobalValue *> TypeInfos;
371
372 /// List of typeids encoding filters used.
373 std::vector<unsigned> FilterIds;
374
375 /// List of the indices in FilterIds corresponding to filter terminators.
376 std::vector<unsigned> FilterEnds;
377
378 EHPersonality PersonalityTypeCache = EHPersonality::Unknown;
379
380 /// \}
381
382 /// Clear all the members of this MachineFunction, but the ones used
383 /// to initialize again the MachineFunction.
384 /// More specifically, this deallocates all the dynamically allocated
385 /// objects and get rid of all the XXXInfo data structure, but keep
386 /// unchanged the references to Fn, Target, MMI, and FunctionNumber.
387 void clear();
388 /// Allocate and initialize the different members.
389 /// In particular, the XXXInfo data structure.
390 /// \pre Fn, Target, MMI, and FunctionNumber are properly set.
391 void init();
392
393 public:
394 struct VariableDbgInfo {
395 const DILocalVariable *Var;
396 const DIExpression *Expr;
397 // The Slot can be negative for fixed stack objects.
398 int Slot;
399 const DILocation *Loc;
400
401 VariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr,
402 int Slot, const DILocation *Loc)
403 : Var(Var), Expr(Expr), Slot(Slot), Loc(Loc) {}
404 };
405
406 class Delegate {
407 virtual void anchor();
408
409 public:
410 virtual ~Delegate() = default;
411 /// Callback after an insertion. This should not modify the MI directly.
412 virtual void MF_HandleInsertion(MachineInstr &MI) = 0;
413 /// Callback before a removal. This should not modify the MI directly.
414 virtual void MF_HandleRemoval(MachineInstr &MI) = 0;
415 };
416
417 /// Structure used to represent pair of argument number after call lowering
418 /// and register used to transfer that argument.
419 /// For now we support only cases when argument is transferred through one
420 /// register.
421 struct ArgRegPair {
422 Register Reg;
423 uint16_t ArgNo;
424 ArgRegPair(Register R, unsigned Arg) : Reg(R), ArgNo(Arg) {
425 assert(Arg < (1 << 16) && "Arg out of range");
426 }
427 };
428 /// Vector of call argument and its forwarding register.
429 using CallSiteInfo = SmallVector<ArgRegPair, 1>;
430 using CallSiteInfoImpl = SmallVectorImpl<ArgRegPair>;
431
432 private:
433 Delegate *TheDelegate = nullptr;
434 GISelChangeObserver *Observer = nullptr;
435
436 using CallSiteInfoMap = DenseMap<const MachineInstr *, CallSiteInfo>;
437 /// Map a call instruction to call site arguments forwarding info.
438 CallSiteInfoMap CallSitesInfo;
439
440 /// A helper function that returns call site info for a give call
441 /// instruction if debug entry value support is enabled.
442 CallSiteInfoMap::iterator getCallSiteInfo(const MachineInstr *MI);
443
444 // Callbacks for insertion and removal.
445 void handleInsertion(MachineInstr &MI);
446 void handleRemoval(MachineInstr &MI);
447 friend struct ilist_traits<MachineInstr>;
448
449 public:
450 using VariableDbgInfoMapTy = SmallVector<VariableDbgInfo, 4>;
451 VariableDbgInfoMapTy VariableDbgInfos;
452
453 /// A count of how many instructions in the function have had numbers
454 /// assigned to them. Used for debug value tracking, to determine the
455 /// next instruction number.
456 unsigned DebugInstrNumberingCount = 0;
457
458 /// Set value of DebugInstrNumberingCount field. Avoid using this unless
459 /// you're deserializing this data.
460 void setDebugInstrNumberingCount(unsigned Num);
461
462 /// Pair of instruction number and operand number.
463 using DebugInstrOperandPair = std::pair<unsigned, unsigned>;
464
465 /// Replacement definition for a debug instruction reference. Made up of a
466 /// source instruction / operand pair, destination pair, and a qualifying
467 /// subregister indicating what bits in the operand make up the substitution.
468 // For example, a debug user
469 /// of %1:
470 /// %0:gr32 = someinst, debug-instr-number 1
471 /// %1:gr16 = %0.some_16_bit_subreg, debug-instr-number 2
472 /// Would receive the substitution {{2, 0}, {1, 0}, $subreg}, where $subreg is
473 /// the subregister number for some_16_bit_subreg.
474 class DebugSubstitution {
475 public:
476 DebugInstrOperandPair Src; ///< Source instruction / operand pair.
477 DebugInstrOperandPair Dest; ///< Replacement instruction / operand pair.
478 unsigned Subreg; ///< Qualifier for which part of Dest is read.
479
480 DebugSubstitution(const DebugInstrOperandPair &Src,
481 const DebugInstrOperandPair &Dest, unsigned Subreg)
482 : Src(Src), Dest(Dest), Subreg(Subreg) {}
483
484 /// Order only by source instruction / operand pair: there should never
485 /// be duplicate entries for the same source in any collection.
486 bool operator<(const DebugSubstitution &Other) const {
487 return Src < Other.Src;
488 }
489 };
490
491 /// Debug value substitutions: a collection of DebugSubstitution objects,
492 /// recording changes in where a value is defined. For example, when one
493 /// instruction is substituted for another. Keeping a record allows recovery
494 /// of variable locations after compilation finishes.
495 SmallVector<DebugSubstitution, 8> DebugValueSubstitutions;
496
497 /// Location of a PHI instruction that is also a debug-info variable value,
498 /// for the duration of register allocation. Loaded by the PHI-elimination
499 /// pass, and emitted as DBG_PHI instructions during VirtRegRewriter, with
500 /// maintenance applied by intermediate passes that edit registers (such as
501 /// coalescing and the allocator passes).
502 class DebugPHIRegallocPos {
503 public:
504 MachineBasicBlock *MBB; ///< Block where this PHI was originally located.
505 Register Reg; ///< VReg where the control-flow-merge happens.
506 unsigned SubReg; ///< Optional subreg qualifier within Reg.
507 DebugPHIRegallocPos(MachineBasicBlock *MBB, Register Reg, unsigned SubReg)
508 : MBB(MBB), Reg(Reg), SubReg(SubReg) {}
509 };
510
511 /// Map of debug instruction numbers to the position of their PHI instructions
512 /// during register allocation. See DebugPHIRegallocPos.
513 DenseMap<unsigned, DebugPHIRegallocPos> DebugPHIPositions;
514
515 /// Create a substitution between one <instr,operand> value to a different,
516 /// new value.
517 void makeDebugValueSubstitution(DebugInstrOperandPair, DebugInstrOperandPair,
518 unsigned SubReg = 0);
519
520 /// Create substitutions for any tracked values in \p Old, to point at
521 /// \p New. Needed when we re-create an instruction during optimization,
522 /// which has the same signature (i.e., def operands in the same place) but
523 /// a modified instruction type, flags, or otherwise. An example: X86 moves
524 /// are sometimes transformed into equivalent LEAs.
525 /// If the two instructions are not the same opcode, limit which operands to
526 /// examine for substitutions to the first N operands by setting
527 /// \p MaxOperand.
528 void substituteDebugValuesForInst(const MachineInstr &Old, MachineInstr &New,
529 unsigned MaxOperand = UINT_MAX);
530
531 /// Find the underlying defining instruction / operand for a COPY instruction
532 /// while in SSA form. Copies do not actually define values -- they move them
533 /// between registers. Labelling a COPY-like instruction with an instruction
534 /// number is to be avoided as it makes value numbers non-unique later in
535 /// compilation. This method follows the definition chain for any sequence of
536 /// COPY-like instructions to find whatever non-COPY-like instruction defines
537 /// the copied value; or for parameters, creates a DBG_PHI on entry.
538 /// May insert instructions into the entry block!
539 /// \p MI The copy-like instruction to salvage.
540 /// \returns An instruction/operand pair identifying the defining value.
541 DebugInstrOperandPair salvageCopySSA(MachineInstr &MI);
542
543 /// Finalise any partially emitted debug instructions. These are DBG_INSTR_REF
544 /// instructions where we only knew the vreg of the value they use, not the
545 /// instruction that defines that vreg. Once isel finishes, we should have
546 /// enough information for every DBG_INSTR_REF to point at an instruction
547 /// (or DBG_PHI).
548 void finalizeDebugInstrRefs();
549
550 /// Returns true if the function's variable locations should be tracked with
551 /// instruction referencing.
552 bool useDebugInstrRef() const;
553
554 /// A reserved operand number representing the instructions memory operand,
555 /// for instructions that have a stack spill fused into them.
556 const static unsigned int DebugOperandMemNumber;
557
558 MachineFunction(Function &F, const LLVMTargetMachine &Target,
559 const TargetSubtargetInfo &STI, unsigned FunctionNum,
560 MachineModuleInfo &MMI);
561 MachineFunction(const MachineFunction &) = delete;
562 MachineFunction &operator=(const MachineFunction &) = delete;
563 ~MachineFunction();
564
565 /// Reset the instance as if it was just created.
566 void reset() {
567 clear();
568 init();
569 }
570
571 /// Reset the currently registered delegate - otherwise assert.
572 void resetDelegate(Delegate *delegate) {
573 assert(TheDelegate == delegate &&
574 "Only the current delegate can perform reset!");
575 TheDelegate = nullptr;
576 }
577
578 /// Set the delegate. resetDelegate must be called before attempting
579 /// to set.
580 void setDelegate(Delegate *delegate) {
581 assert(delegate && !TheDelegate &&
582 "Attempted to set delegate to null, or to change it without "
583 "first resetting it!");
584
585 TheDelegate = delegate;
586 }
587
588 void setObserver(GISelChangeObserver *O) { Observer = O; }
589
590 GISelChangeObserver *getObserver() const { return Observer; }
591
592 MachineModuleInfo &getMMI() const { return MMI; }
593 MCContext &getContext() const { return Ctx; }
594
595 /// Returns the Section this function belongs to.
596 MCSection *getSection() const { return Section; }
597
598 /// Indicates the Section this function belongs to.
599 void setSection(MCSection *S) { Section = S; }
600
601 PseudoSourceValueManager &getPSVManager() const { return *PSVManager; }
602
603 /// Return the DataLayout attached to the Module associated to this MF.
604 const DataLayout &getDataLayout() const;
605
606 /// Return the LLVM function that this machine code represents
607 Function &getFunction() { return F; }
608
609 /// Return the LLVM function that this machine code represents
610 const Function &getFunction() const { return F; }
611
612 /// getName - Return the name of the corresponding LLVM function.
613 StringRef getName() const;
614
615 /// getFunctionNumber - Return a unique ID for the current function.
616 unsigned getFunctionNumber() const { return FunctionNumber; }
617
618 /// Returns true if this function has basic block sections enabled.
619 bool hasBBSections() const {
620 return (BBSectionsType == BasicBlockSection::All ||
621 BBSectionsType == BasicBlockSection::List ||
622 BBSectionsType == BasicBlockSection::Preset);
623 }
624
625 /// Returns true if basic block labels are to be generated for this function.
626 bool hasBBLabels() const {
627 return BBSectionsType == BasicBlockSection::Labels;
628 }
629
630 void setBBSectionsType(BasicBlockSection V) { BBSectionsType = V; }
631
632 /// Assign IsBeginSection IsEndSection fields for basic blocks in this
633 /// function.
634 void assignBeginEndSections();
635
636 /// getTarget - Return the target machine this machine code is compiled with
637 const LLVMTargetMachine &getTarget() const { return Target; }
638
639 /// getSubtarget - Return the subtarget for which this machine code is being
640 /// compiled.
641 const TargetSubtargetInfo &getSubtarget() const { return *STI; }
642
643 /// getSubtarget - This method returns a pointer to the specified type of
644 /// TargetSubtargetInfo. In debug builds, it verifies that the object being
645 /// returned is of the correct type.
646 template<typename STC> const STC &getSubtarget() const {
647 return *static_cast<const STC *>(STI);
648 }
649
650 /// getRegInfo - Return information about the registers currently in use.
651 MachineRegisterInfo &getRegInfo() { return *RegInfo; }
652 const MachineRegisterInfo &getRegInfo() const { return *RegInfo; }
653
654 /// getFrameInfo - Return the frame info object for the current function.
655 /// This object contains information about objects allocated on the stack
656 /// frame of the current function in an abstract way.
657 MachineFrameInfo &getFrameInfo() { return *FrameInfo; }
658 const MachineFrameInfo &getFrameInfo() const { return *FrameInfo; }
659
660 /// getJumpTableInfo - Return the jump table info object for the current
661 /// function. This object contains information about jump tables in the
662 /// current function. If the current function has no jump tables, this will
663 /// return null.
664 const MachineJumpTableInfo *getJumpTableInfo() const { return JumpTableInfo; }
665 MachineJumpTableInfo *getJumpTableInfo() { return JumpTableInfo; }
666
667 /// getOrCreateJumpTableInfo - Get the JumpTableInfo for this function, if it
668 /// does already exist, allocate one.
669 MachineJumpTableInfo *getOrCreateJumpTableInfo(unsigned JTEntryKind);
670
671 /// getConstantPool - Return the constant pool object for the current
672 /// function.
673 MachineConstantPool *getConstantPool() { return ConstantPool; }
674 const MachineConstantPool *getConstantPool() const { return ConstantPool; }
675
676 /// getWasmEHFuncInfo - Return information about how the current function uses
677 /// Wasm exception handling. Returns null for functions that don't use wasm
678 /// exception handling.
679 const WasmEHFuncInfo *getWasmEHFuncInfo() const { return WasmEHInfo; }
680 WasmEHFuncInfo *getWasmEHFuncInfo() { return WasmEHInfo; }
681
682 /// getWinEHFuncInfo - Return information about how the current function uses
683 /// Windows exception handling. Returns null for functions that don't use
684 /// funclets for exception handling.
685 const WinEHFuncInfo *getWinEHFuncInfo() const { return WinEHInfo; }
686 WinEHFuncInfo *getWinEHFuncInfo() { return WinEHInfo; }
687
688 /// getAlignment - Return the alignment of the function.
689 Align getAlignment() const { return Alignment; }
690
691 /// setAlignment - Set the alignment of the function.
692 void setAlignment(Align A) { Alignment = A; }
693
694 /// ensureAlignment - Make sure the function is at least A bytes aligned.
695 void ensureAlignment(Align A) {
696 if (Alignment < A)
697 Alignment = A;
698 }
699
700 /// exposesReturnsTwice - Returns true if the function calls setjmp or
701 /// any other similar functions with attribute "returns twice" without
702 /// having the attribute itself.
703 bool exposesReturnsTwice() const {
704 return ExposesReturnsTwice;
705 }
706
707 /// setCallsSetJmp - Set a flag that indicates if there's a call to
708 /// a "returns twice" function.
709 void setExposesReturnsTwice(bool B) {
710 ExposesReturnsTwice = B;
711 }
712
713 /// Returns true if the function contains any inline assembly.
714 bool hasInlineAsm() const {
715 return HasInlineAsm;
716 }
717
718 /// Set a flag that indicates that the function contains inline assembly.
719 void setHasInlineAsm(bool B) {
720 HasInlineAsm = B;
721 }
722
723 bool hasWinCFI() const {
724 return HasWinCFI;
725 }
726 void setHasWinCFI(bool v) { HasWinCFI = v; }
727
728 /// True if this function needs frame moves for debug or exceptions.
729 bool needsFrameMoves() const;
730
731 /// Get the function properties
732 const MachineFunctionProperties &getProperties() const { return Properties; }
733 MachineFunctionProperties &getProperties() { return Properties; }
734
735 /// getInfo - Keep track of various per-function pieces of information for
736 /// backends that would like to do so.
737 ///
738 template<typename Ty>
739 Ty *getInfo() {
740 if (!MFInfo)
741 MFInfo = Ty::template create<Ty>(Allocator, *this);
742 return static_cast<Ty*>(MFInfo);
743 }
744
745 template<typename Ty>
746 const Ty *getInfo() const {
747 return const_cast<MachineFunction*>(this)->getInfo<Ty>();
748 }
749
750 /// Returns the denormal handling type for the default rounding mode of the
751 /// function.
752 DenormalMode getDenormalMode(const fltSemantics &FPType) const;
753
754 /// getBlockNumbered - MachineBasicBlocks are automatically numbered when they
755 /// are inserted into the machine function. The block number for a machine
756 /// basic block can be found by using the MBB::getNumber method, this method
757 /// provides the inverse mapping.
758 MachineBasicBlock *getBlockNumbered(unsigned N) const {
759 assert(N < MBBNumbering.size() && "Illegal block number");
760 assert(MBBNumbering[N] && "Block was removed from the machine function!");
761 return MBBNumbering[N];
762 }
763
764 /// Should we be emitting segmented stack stuff for the function
765 bool shouldSplitStack() const;
766
767 /// getNumBlockIDs - Return the number of MBB ID's allocated.
768 unsigned getNumBlockIDs() const { return (unsigned)MBBNumbering.size(); }
769
770 /// RenumberBlocks - This discards all of the MachineBasicBlock numbers and
771 /// recomputes them. This guarantees that the MBB numbers are sequential,
772 /// dense, and match the ordering of the blocks within the function. If a
773 /// specific MachineBasicBlock is specified, only that block and those after
774 /// it are renumbered.
775 void RenumberBlocks(MachineBasicBlock *MBBFrom = nullptr);
776
777 /// print - Print out the MachineFunction in a format suitable for debugging
778 /// to the specified stream.
779 void print(raw_ostream &OS, const SlotIndexes* = nullptr) const;
780
781 /// viewCFG - This function is meant for use from the debugger. You can just
782 /// say 'call F->viewCFG()' and a ghostview window should pop up from the
783 /// program, displaying the CFG of the current function with the code for each
784 /// basic block inside. This depends on there being a 'dot' and 'gv' program
785 /// in your path.
786 void viewCFG() const;
787
788 /// viewCFGOnly - This function is meant for use from the debugger. It works
789 /// just like viewCFG, but it does not include the contents of basic blocks
790 /// into the nodes, just the label. If you are only interested in the CFG
791 /// this can make the graph smaller.
792 ///
793 void viewCFGOnly() const;
794
795 /// dump - Print the current MachineFunction to cerr, useful for debugger use.
796 void dump() const;
797
798 /// Run the current MachineFunction through the machine code verifier, useful
799 /// for debugger use.
800 /// \returns true if no problems were found.
801 bool verify(Pass *p = nullptr, const char *Banner = nullptr,
802 bool AbortOnError = true) const;
803
804 // Provide accessors for the MachineBasicBlock list...
805 using iterator = BasicBlockListType::iterator;
806 using const_iterator = BasicBlockListType::const_iterator;
807 using const_reverse_iterator = BasicBlockListType::const_reverse_iterator;
808 using reverse_iterator = BasicBlockListType::reverse_iterator;
809
810 /// Support for MachineBasicBlock::getNextNode().
811 static BasicBlockListType MachineFunction::*
812 getSublistAccess(MachineBasicBlock *) {
813 return &MachineFunction::BasicBlocks;
814 }
815
816 /// addLiveIn - Add the specified physical register as a live-in value and
817 /// create a corresponding virtual register for it.
818 Register addLiveIn(MCRegister PReg, const TargetRegisterClass *RC);
819
820 //===--------------------------------------------------------------------===//
821 // BasicBlock accessor functions.
822 //
823 iterator begin() { return BasicBlocks.begin(); }
824 const_iterator begin() const { return BasicBlocks.begin(); }
825 iterator end () { return BasicBlocks.end(); }
826 const_iterator end () const { return BasicBlocks.end(); }
827
828 reverse_iterator rbegin() { return BasicBlocks.rbegin(); }
829 const_reverse_iterator rbegin() const { return BasicBlocks.rbegin(); }
830 reverse_iterator rend () { return BasicBlocks.rend(); }
831 const_reverse_iterator rend () const { return BasicBlocks.rend(); }
832
833 unsigned size() const { return (unsigned)BasicBlocks.size();}
834 bool empty() const { return BasicBlocks.empty(); }
835 const MachineBasicBlock &front() const { return BasicBlocks.front(); }
836 MachineBasicBlock &front() { return BasicBlocks.front(); }
837 const MachineBasicBlock & back() const { return BasicBlocks.back(); }
838 MachineBasicBlock & back() { return BasicBlocks.back(); }
839
840 void push_back (MachineBasicBlock *MBB) { BasicBlocks.push_back (MBB); }
841 void push_front(MachineBasicBlock *MBB) { BasicBlocks.push_front(MBB); }
842 void insert(iterator MBBI, MachineBasicBlock *MBB) {
843 BasicBlocks.insert(MBBI, MBB);
844 }
845 void splice(iterator InsertPt, iterator MBBI) {
846 BasicBlocks.splice(InsertPt, BasicBlocks, MBBI);
847 }
848 void splice(iterator InsertPt, MachineBasicBlock *MBB) {
849 BasicBlocks.splice(InsertPt, BasicBlocks, MBB);
850 }
851 void splice(iterator InsertPt, iterator MBBI, iterator MBBE) {
852 BasicBlocks.splice(InsertPt, BasicBlocks, MBBI, MBBE);
853 }
854
855 void remove(iterator MBBI) { BasicBlocks.remove(MBBI); }
856 void remove(MachineBasicBlock *MBBI) { BasicBlocks.remove(MBBI); }
857 void erase(iterator MBBI) { BasicBlocks.erase(MBBI); }
858 void erase(MachineBasicBlock *MBBI) { BasicBlocks.erase(MBBI); }
859
860 template <typename Comp>
861 void sort(Comp comp) {
862 BasicBlocks.sort(comp);
863 }
864
865 /// Return the number of \p MachineInstrs in this \p MachineFunction.
866 unsigned getInstructionCount() const {
867 unsigned InstrCount = 0;
868 for (const MachineBasicBlock &MBB : BasicBlocks)
869 InstrCount += MBB.size();
870 return InstrCount;
871 }
872
873 //===--------------------------------------------------------------------===//
874 // Internal functions used to automatically number MachineBasicBlocks
875
876 /// Adds the MBB to the internal numbering. Returns the unique number
877 /// assigned to the MBB.
878 unsigned addToMBBNumbering(MachineBasicBlock *MBB) {
879 MBBNumbering.push_back(MBB);
880 return (unsigned)MBBNumbering.size()-1;
881 }
882
883 /// removeFromMBBNumbering - Remove the specific machine basic block from our
884 /// tracker, this is only really to be used by the MachineBasicBlock
885 /// implementation.
886 void removeFromMBBNumbering(unsigned N) {
887 assert(N < MBBNumbering.size() && "Illegal basic block #");
888 MBBNumbering[N] = nullptr;
889 }
890
891 /// CreateMachineInstr - Allocate a new MachineInstr. Use this instead
892 /// of `new MachineInstr'.
893 MachineInstr *CreateMachineInstr(const MCInstrDesc &MCID, DebugLoc DL,
894 bool NoImplicit = false);
895
896 /// Create a new MachineInstr which is a copy of \p Orig, identical in all
897 /// ways except the instruction has no parent, prev, or next. Bundling flags
898 /// are reset.
899 ///
900 /// Note: Clones a single instruction, not whole instruction bundles.
901 /// Does not perform target specific adjustments; consider using
902 /// TargetInstrInfo::duplicate() instead.
903 MachineInstr *CloneMachineInstr(const MachineInstr *Orig);
904
905 /// Clones instruction or the whole instruction bundle \p Orig and insert
906 /// into \p MBB before \p InsertBefore.
907 ///
908 /// Note: Does not perform target specific adjustments; consider using
909 /// TargetInstrInfo::duplicate() intead.
910 MachineInstr &
911 cloneMachineInstrBundle(MachineBasicBlock &MBB,
912 MachineBasicBlock::iterator InsertBefore,
913 const MachineInstr &Orig);
914
915 /// DeleteMachineInstr - Delete the given MachineInstr.
916 void deleteMachineInstr(MachineInstr *MI);
917
918 /// CreateMachineBasicBlock - Allocate a new MachineBasicBlock. Use this
919 /// instead of `new MachineBasicBlock'.
920 MachineBasicBlock *CreateMachineBasicBlock(const BasicBlock *bb = nullptr);
921
922 /// DeleteMachineBasicBlock - Delete the given MachineBasicBlock.
923 void deleteMachineBasicBlock(MachineBasicBlock *MBB);
924
925 /// getMachineMemOperand - Allocate a new MachineMemOperand.
926 /// MachineMemOperands are owned by the MachineFunction and need not be
927 /// explicitly deallocated.
928 MachineMemOperand *getMachineMemOperand(
929 MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s,
930 Align base_alignment, const AAMDNodes &AAInfo = AAMDNodes(),
931 const MDNode *Ranges = nullptr, SyncScope::ID SSID = SyncScope::System,
932 AtomicOrdering Ordering = AtomicOrdering::NotAtomic,
933 AtomicOrdering FailureOrdering = AtomicOrdering::NotAtomic);
934
935 MachineMemOperand *getMachineMemOperand(
936 MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, LLT MemTy,
937 Align base_alignment, const AAMDNodes &AAInfo = AAMDNodes(),
938 const MDNode *Ranges = nullptr, SyncScope::ID SSID = SyncScope::System,
939 AtomicOrdering Ordering = AtomicOrdering::NotAtomic,
940 AtomicOrdering FailureOrdering = AtomicOrdering::NotAtomic);
941
942 /// getMachineMemOperand - Allocate a new MachineMemOperand by copying
943 /// an existing one, adjusting by an offset and using the given size.
944 /// MachineMemOperands are owned by the MachineFunction and need not be
945 /// explicitly deallocated.
946 MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
947 int64_t Offset, LLT Ty);
948 MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
949 int64_t Offset, uint64_t Size) {
950 return getMachineMemOperand(
951 MMO, Offset, Size == ~UINT64_C(0) ? LLT() : LLT::scalar(8 * Size));
952 }
953
954 /// getMachineMemOperand - Allocate a new MachineMemOperand by copying
955 /// an existing one, replacing only the MachinePointerInfo and size.
956 /// MachineMemOperands are owned by the MachineFunction and need not be
957 /// explicitly deallocated.
958 MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
959 const MachinePointerInfo &PtrInfo,
960 uint64_t Size);
961 MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
962 const MachinePointerInfo &PtrInfo,
963 LLT Ty);
964
965 /// Allocate a new MachineMemOperand by copying an existing one,
966 /// replacing only AliasAnalysis information. MachineMemOperands are owned
967 /// by the MachineFunction and need not be explicitly deallocated.
968 MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
969 const AAMDNodes &AAInfo);
970
971 /// Allocate a new MachineMemOperand by copying an existing one,
972 /// replacing the flags. MachineMemOperands are owned
973 /// by the MachineFunction and need not be explicitly deallocated.
974 MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
975 MachineMemOperand::Flags Flags);
976
977 using OperandCapacity = ArrayRecycler<MachineOperand>::Capacity;
978
979 /// Allocate an array of MachineOperands. This is only intended for use by
980 /// internal MachineInstr functions.
981 MachineOperand *allocateOperandArray(OperandCapacity Cap) {
982 return OperandRecycler.allocate(Cap, Allocator);
983 }
984
985 /// Dellocate an array of MachineOperands and recycle the memory. This is
986 /// only intended for use by internal MachineInstr functions.
987 /// Cap must be the same capacity that was used to allocate the array.
988 void deallocateOperandArray(OperandCapacity Cap, MachineOperand *Array) {
989 OperandRecycler.deallocate(Cap, Array);
990 }
991
992 /// Allocate and initialize a register mask with @p NumRegister bits.
993 uint32_t *allocateRegMask();
994
995 ArrayRef<int> allocateShuffleMask(ArrayRef<int> Mask);
996
997 /// Allocate and construct an extra info structure for a `MachineInstr`.
998 ///
999 /// This is allocated on the function's allocator and so lives the life of
1000 /// the function.
1001 MachineInstr::ExtraInfo *createMIExtraInfo(
1002 ArrayRef<MachineMemOperand *> MMOs, MCSymbol *PreInstrSymbol = nullptr,
1003 MCSymbol *PostInstrSymbol = nullptr, MDNode *HeapAllocMarker = nullptr);
1004
1005 /// Allocate a string and populate it with the given external symbol name.
1006 const char *createExternalSymbolName(StringRef Name);
1007
1008 //===--------------------------------------------------------------------===//
1009 // Label Manipulation.
1010
1011 /// getJTISymbol - Return the MCSymbol for the specified non-empty jump table.
1012 /// If isLinkerPrivate is specified, an 'l' label is returned, otherwise a
1013 /// normal 'L' label is returned.
1014 MCSymbol *getJTISymbol(unsigned JTI, MCContext &Ctx,
1015 bool isLinkerPrivate = false) const;
1016
1017 /// getPICBaseSymbol - Return a function-local symbol to represent the PIC
1018 /// base.
1019 MCSymbol *getPICBaseSymbol() const;
1020
1021 /// Returns a reference to a list of cfi instructions in the function's
1022 /// prologue. Used to construct frame maps for debug and exception handling
1023 /// comsumers.
1024 const std::vector<MCCFIInstruction> &getFrameInstructions() const {
1025 return FrameInstructions;
1026 }
1027
1028 LLVM_NODISCARD unsigned addFrameInst(const MCCFIInstruction &Inst);
1029
1030 /// Returns a reference to a list of symbols immediately following calls to
1031 /// _setjmp in the function. Used to construct the longjmp target table used
1032 /// by Windows Control Flow Guard.
1033 const std::vector<MCSymbol *> &getLongjmpTargets() const {
1034 return LongjmpTargets;
1035 }
1036
1037 /// Add the specified symbol to the list of valid longjmp targets for Windows
1038 /// Control Flow Guard.
1039 void addLongjmpTarget(MCSymbol *Target) { LongjmpTargets.push_back(Target); }
1040
1041 /// Returns a reference to a list of symbols that we have catchrets.
1042 /// Used to construct the catchret target table used by Windows EHCont Guard.
1043 const std::vector<MCSymbol *> &getCatchretTargets() const {
1044 return CatchretTargets;
1045 }
1046
1047 /// Add the specified symbol to the list of valid catchret targets for Windows
1048 /// EHCont Guard.
1049 void addCatchretTarget(MCSymbol *Target) {
1050 CatchretTargets.push_back(Target);
1051 }
1052
1053 /// \name Exception Handling
1054 /// \{
1055
1056 bool callsEHReturn() const { return CallsEHReturn; }
1057 void setCallsEHReturn(bool b) { CallsEHReturn = b; }
1058
1059 bool callsUnwindInit() const { return CallsUnwindInit; }
1060 void setCallsUnwindInit(bool b) { CallsUnwindInit = b; }
1061
1062 bool hasEHCatchret() const { return HasEHCatchret; }
1063 void setHasEHCatchret(bool V) { HasEHCatchret = V; }
1064
1065 bool hasEHScopes() const { return HasEHScopes; }
1066 void setHasEHScopes(bool V) { HasEHScopes = V; }
1067
1068 bool hasEHFunclets() const { return HasEHFunclets; }
1069 void setHasEHFunclets(bool V) { HasEHFunclets = V; }
1070
1071 /// Find or create an LandingPadInfo for the specified MachineBasicBlock.
1072 LandingPadInfo &getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad);
1073
1074 /// Remap landing pad labels and remove any deleted landing pads.
1075 void tidyLandingPads(DenseMap<MCSymbol *, uintptr_t> *LPMap = nullptr,
1076 bool TidyIfNoBeginLabels = true);
1077
1078 /// Return a reference to the landing pad info for the current function.
1079 const std::vector<LandingPadInfo> &getLandingPads() const {
1080 return LandingPads;
1081 }
1082
1083 /// Provide the begin and end labels of an invoke style call and associate it
1084 /// with a try landing pad block.
1085 void addInvoke(MachineBasicBlock *LandingPad,
1086 MCSymbol *BeginLabel, MCSymbol *EndLabel);
1087
1088 /// Add a new panding pad, and extract the exception handling information from
1089 /// the landingpad instruction. Returns the label ID for the landing pad
1090 /// entry.
1091 MCSymbol *addLandingPad(MachineBasicBlock *LandingPad);
1092
1093 /// Provide the catch typeinfo for a landing pad.
1094 void addCatchTypeInfo(MachineBasicBlock *LandingPad,
1095 ArrayRef<const GlobalValue *> TyInfo);
1096
1097 /// Provide the filter typeinfo for a landing pad.
1098 void addFilterTypeInfo(MachineBasicBlock *LandingPad,
1099 ArrayRef<const GlobalValue *> TyInfo);
1100
1101 /// Add a cleanup action for a landing pad.
1102 void addCleanup(MachineBasicBlock *LandingPad);
1103
1104 void addSEHCatchHandler(MachineBasicBlock *LandingPad, const Function *Filter,
1105 const BlockAddress *RecoverBA);
1106
1107 void addSEHCleanupHandler(MachineBasicBlock *LandingPad,
1108 const Function *Cleanup);
1109
1110 /// Return the type id for the specified typeinfo. This is function wide.
1111 unsigned getTypeIDFor(const GlobalValue *TI);
1112
1113 /// Return the id of the filter encoded by TyIds. This is function wide.
1114 int getFilterIDFor(std::vector<unsigned> &TyIds);
1115
1116 /// Map the landing pad's EH symbol to the call site indexes.
1117 void setCallSiteLandingPad(MCSymbol *Sym, ArrayRef<unsigned> Sites);
1118
1119 /// Map the landing pad to its index. Used for Wasm exception handling.
1120 void setWasmLandingPadIndex(const MachineBasicBlock *LPad, unsigned Index) {
1121 WasmLPadToIndexMap[LPad] = Index;
1122 }
1123
1124 /// Returns true if the landing pad has an associate index in wasm EH.
1125 bool hasWasmLandingPadIndex(const MachineBasicBlock *LPad) const {
1126 return WasmLPadToIndexMap.count(LPad);
1127 }
1128
1129 /// Get the index in wasm EH for a given landing pad.
1130 unsigned getWasmLandingPadIndex(const MachineBasicBlock *LPad) const {
1131 assert(hasWasmLandingPadIndex(LPad));
1132 return WasmLPadToIndexMap.lookup(LPad);
1133 }
1134
1135 /// Get the call site indexes for a landing pad EH symbol.
1136 SmallVectorImpl<unsigned> &getCallSiteLandingPad(MCSymbol *Sym) {
1137 assert(hasCallSiteLandingPad(Sym) &&
1138 "missing call site number for landing pad!");
1139 return LPadToCallSiteMap[Sym];
1140 }
1141
1142 /// Return true if the landing pad Eh symbol has an associated call site.
1143 bool hasCallSiteLandingPad(MCSymbol *Sym) {
1144 return !LPadToCallSiteMap[Sym].empty();
1145 }
1146
1147 /// Map the begin label for a call site.
1148 void setCallSiteBeginLabel(MCSymbol *BeginLabel, unsigned Site) {
1149 CallSiteMap[BeginLabel] = Site;
1150 }
1151
1152 /// Get the call site number for a begin label.
1153 unsigned getCallSiteBeginLabel(MCSymbol *BeginLabel) const {
1154 assert(hasCallSiteBeginLabel(BeginLabel) &&
1155 "Missing call site number for EH_LABEL!");
1156 return CallSiteMap.lookup(BeginLabel);
1157 }
1158
1159 /// Return true if the begin label has a call site number associated with it.
1160 bool hasCallSiteBeginLabel(MCSymbol *BeginLabel) const {
1161 return CallSiteMap.count(BeginLabel);
1162 }
1163
1164 /// Record annotations associated with a particular label.
1165 void addCodeViewAnnotation(MCSymbol *Label, MDNode *MD) {
1166 CodeViewAnnotations.push_back({Label, MD});
1167 }
1168
1169 ArrayRef<std::pair<MCSymbol *, MDNode *>> getCodeViewAnnotations() const {
1170 return CodeViewAnnotations;
1171 }
1172
1173 /// Return a reference to the C++ typeinfo for the current function.
1174 const std::vector<const GlobalValue *> &getTypeInfos() const {
1175 return TypeInfos;
1176 }
1177
1178 /// Return a reference to the typeids encoding filters used in the current
1179 /// function.
1180 const std::vector<unsigned> &getFilterIds() const {
1181 return FilterIds;
1182 }
1183
1184 /// \}
1185
1186 /// Collect information used to emit debugging information of a variable.
1187 void setVariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr,
1188 int Slot, const DILocation *Loc) {
1189 VariableDbgInfos.emplace_back(Var, Expr, Slot, Loc);
1190 }
1191
1192 VariableDbgInfoMapTy &getVariableDbgInfo() { return VariableDbgInfos; }
1193 const VariableDbgInfoMapTy &getVariableDbgInfo() const {
1194 return VariableDbgInfos;
1195 }
1196
1197 /// Start tracking the arguments passed to the call \p CallI.
1198 void addCallArgsForwardingRegs(const MachineInstr *CallI,
1199 CallSiteInfoImpl &&CallInfo) {
1200 assert(CallI->isCandidateForCallSiteEntry());
1201 bool Inserted =
1202 CallSitesInfo.try_emplace(CallI, std::move(CallInfo)).second;
1203 (void)Inserted;
1204 assert(Inserted && "Call site info not unique");
1205 }
1206
1207 const CallSiteInfoMap &getCallSitesInfo() const {
1208 return CallSitesInfo;
1209 }
1210
1211 /// Following functions update call site info. They should be called before
1212 /// removing, replacing or copying call instruction.
1213
1214 /// Erase the call site info for \p MI. It is used to remove a call
1215 /// instruction from the instruction stream.
1216 void eraseCallSiteInfo(const MachineInstr *MI);
1217 /// Copy the call site info from \p Old to \ New. Its usage is when we are
1218 /// making a copy of the instruction that will be inserted at different point
1219 /// of the instruction stream.
1220 void copyCallSiteInfo(const MachineInstr *Old,
1221 const MachineInstr *New);
1222
1223 const std::vector<char> &getBBSectionsSymbolPrefix() const {
1224 return BBSectionsSymbolPrefix;
1225 }
1226
1227 /// Move the call site info from \p Old to \New call site info. This function
1228 /// is used when we are replacing one call instruction with another one to
1229 /// the same callee.
1230 void moveCallSiteInfo(const MachineInstr *Old,
1231 const MachineInstr *New);
1232
1233 unsigned getNewDebugInstrNum() {
1234 return ++DebugInstrNumberingCount;
1235 }
1236 };
1237
1238 //===--------------------------------------------------------------------===//
1239 // GraphTraits specializations for function basic block graphs (CFGs)
1240 //===--------------------------------------------------------------------===//
1241
1242 // Provide specializations of GraphTraits to be able to treat a
1243 // machine function as a graph of machine basic blocks... these are
1244 // the same as the machine basic block iterators, except that the root
1245 // node is implicitly the first node of the function.
1246 //
1247 template <> struct GraphTraits<MachineFunction*> :
1248 public GraphTraits<MachineBasicBlock*> {
1249 static NodeRef getEntryNode(MachineFunction *F) { return &F->front(); }
1250
1251 // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
1252 using nodes_iterator = pointer_iterator<MachineFunction::iterator>;
1253
1254 static nodes_iterator nodes_begin(MachineFunction *F) {
1255 return nodes_iterator(F->begin());
1256 }
1257
1258 static nodes_iterator nodes_end(MachineFunction *F) {
1259 return nodes_iterator(F->end());
1260 }
1261
1262 static unsigned size (MachineFunction *F) { return F->size(); }
1263 };
1264 template <> struct GraphTraits<const MachineFunction*> :
1265 public GraphTraits<const MachineBasicBlock*> {
1266 static NodeRef getEntryNode(const MachineFunction *F) { return &F->front(); }
1267
1268 // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
1269 using nodes_iterator = pointer_iterator<MachineFunction::const_iterator>;
1270
1271 static nodes_iterator nodes_begin(const MachineFunction *F) {
1272 return nodes_iterator(F->begin());
1273 }
1274
1275 static nodes_iterator nodes_end (const MachineFunction *F) {
1276 return nodes_iterator(F->end());
1277 }
1278
1279 static unsigned size (const MachineFunction *F) {
1280 return F->size();
1281 }
1282 };
1283
1284 // Provide specializations of GraphTraits to be able to treat a function as a
1285 // graph of basic blocks... and to walk it in inverse order. Inverse order for
1286 // a function is considered to be when traversing the predecessor edges of a BB
1287 // instead of the successor edges.
1288 //
1289 template <> struct GraphTraits<Inverse<MachineFunction*>> :
1290 public GraphTraits<Inverse<MachineBasicBlock*>> {
1291 static NodeRef getEntryNode(Inverse<MachineFunction *> G) {
1292 return &G.Graph->front();
1293 }
1294 };
1295 template <> struct GraphTraits<Inverse<const MachineFunction*>> :
1296 public GraphTraits<Inverse<const MachineBasicBlock*>> {
1297 static NodeRef getEntryNode(Inverse<const MachineFunction *> G) {
1298 return &G.Graph->front();
1299 }
1300 };
1301
1302 class MachineFunctionAnalysisManager;
1303 void verifyMachineFunction(MachineFunctionAnalysisManager *,
1304 const std::string &Banner,
1305 const MachineFunction &MF);
1306
1307 } // end namespace llvm
1308
1309 #endif // LLVM_CODEGEN_MACHINEFUNCTION_H