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