1//===- llvm/CodeGen/MachineBasicBlock.h -------------------------*- C++ -*-===//
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
7//===----------------------------------------------------------------------===//
9// Collect the sequence of machine instructions for a basic block.
11//===----------------------------------------------------------------------===//
13#ifndef LLVM_CODEGEN_MACHINEBASICBLOCK_H
14#define LLVM_CODEGEN_MACHINEBASICBLOCK_H
53// This structure uniquely identifies a basic block section.
55// {Type: Default, Number: (unsigned)} (These are regular section IDs)
56// {Type: Exception, Number: 0} (ExceptionSectionID)
57// {Type: Cold, Number: 0} (ColdSectionID)
60 Default = 0,
// Regular section (these sections are distinguished by the
62 Exception,
// Special section type for exception handling blocks
63 Cold,
// Special section type for cold blocks
69 // Special unique sections for cold and exception blocks.
80 // This is only used to construct the special cold and exception sections.
96 NumberInfo::getHashValue(SecID.
Number));
109 using instr_iterator =
116 instr_iterator
First,
117 instr_iterator
Last);
121 class MachineBasicBlock
124 /// Pair of physical register and lane mask.
125 /// This is not simply a std::pair typedef because the members should be named
126 /// clearly as they both have an integer type.
146 /// The call frame size on entry to this basic block due to call frame setup
147 /// instructions in a predecessor. This is usually zero, unless basic blocks
148 /// are split in the middle of a call sequence.
150 /// This information is only maintained until PrologEpilogInserter eliminates
151 /// call frame pseudos.
152 unsigned CallFrameSize = 0;
157 /// Keep track of the predecessor / successor basic blocks.
161 /// Keep track of the probabilities to the successors. This vector has the
162 /// same order as Successors, or it is empty if we don't use it (disable
164 std::vector<BranchProbability> Probs;
165 using probability_iterator = std::vector<BranchProbability>::iterator;
166 using const_probability_iterator =
167 std::vector<BranchProbability>::const_iterator;
169 std::optional<uint64_t> IrrLoopHeaderWeight;
171 /// Keep track of the physical registers that are livein of the basicblock.
172 using LiveInVector = std::vector<RegisterMaskPair>;
173 LiveInVector LiveIns;
175 /// Alignment of the basic block. One if the basic block does not need to be
178 /// Maximum amount of bytes that can be added to align the basic block. If the
179 /// alignment cannot be reached in this many bytes, no bytes are emitted.
180 /// Zero to represent no maximum.
181 unsigned MaxBytesForAlignment = 0;
183 /// Indicate that this basic block is entered via an exception handler.
184 bool IsEHPad =
false;
186 /// Indicate that this MachineBasicBlock is referenced somewhere other than
187 /// as predecessor/successor, a terminator MachineInstr, or a jump table.
188 bool MachineBlockAddressTaken =
false;
190 /// If this MachineBasicBlock corresponds to an IR-level "blockaddress"
191 /// constant, this contains a pointer to that block.
194 /// Indicate that this basic block needs its symbol be emitted regardless of
195 /// whether the flow just falls-through to it.
196 bool LabelMustBeEmitted =
false;
198 /// Indicate that this basic block is the entry block of an EH scope, i.e.,
199 /// the block that used to have a catchpad or cleanuppad instruction in the
201 bool IsEHScopeEntry =
false;
203 /// Indicates if this is a target of Windows EH Continuation Guard.
204 bool IsEHContTarget =
false;
206 /// Indicate that this basic block is the entry block of an EH funclet.
207 bool IsEHFuncletEntry =
false;
209 /// Indicate that this basic block is the entry block of a cleanup funclet.
210 bool IsCleanupFuncletEntry =
false;
212 /// Fixed unique ID assigned to this basic block upon creation. Used with
213 /// basic block sections and basic block labels.
214 std::optional<UniqueBBID> BBID;
216 /// With basic block sections, this stores the Section ID of the basic block.
219 // Indicate that this basic block begins a section.
220 bool IsBeginSection =
false;
222 // Indicate that this basic block ends a section.
223 bool IsEndSection =
false;
225 /// Indicate that this basic block is the indirect dest of an INLINEASM_BR.
226 bool IsInlineAsmBrIndirectTarget =
false;
228 /// since getSymbol is a relatively heavy-weight operation, the symbol
229 /// is only computed once and is cached.
230 mutable MCSymbol *CachedMCSymbol =
nullptr;
232 /// Cached MCSymbol for this block (used if IsEHContTarget).
233 mutable MCSymbol *CachedEHContMCSymbol =
nullptr;
235 /// Marks the end of the basic block. Used during basic block sections to
236 /// calculate the size of the basic block, or the BB section ending with it.
237 mutable MCSymbol *CachedEndMCSymbol =
nullptr;
239 // Intrusive list support
240 MachineBasicBlock() =
default;
244 ~MachineBasicBlock();
246 // MachineBasicBlocks are allocated and owned by MachineFunction.
250 /// Return the LLVM basic block that this instance corresponded to originally.
251 /// Note that this may be NULL if this instance does not correspond directly
252 /// to an LLVM basic block.
255 /// Remove the reference to the underlying IR BasicBlock. This is for
256 /// reduction tools and should generally not be used.
261 /// Check if there is a name of corresponding LLVM basic block.
264 /// Return the name of the corresponding LLVM basic block, or an empty string.
267 /// Return a formatted string to identify this block and its parent function.
270 /// Test whether this block is used as something other than the target
271 /// of a terminator, exception-handling target, or jump table. This is
272 /// either the result of an IR-level "blockaddress", or some form
273 /// of target-specific branch lowering.
275 /// The name of this function `hasAddressTaken` implies that the address of
276 /// the block is known and used in a general sense, but not necessarily that
277 /// the address is used by an indirect branch instruction. So branch target
278 /// enforcement need not put a BTI instruction (or equivalent) at the start
279 /// of a block just because this function returns true. The decision about
280 /// whether to add a BTI can be more subtle than that, and depends on the
281 /// more detailed checks that this function aggregates together.
283 return MachineBlockAddressTaken || AddressTakenIRBlock ||
284 IsInlineAsmBrIndirectTarget;
287 /// Test whether this block is used as something other than the target of a
288 /// terminator, exception-handling target, jump table, or IR blockaddress.
289 /// For example, its address might be loaded into a register, or
290 /// stored in some branch table that isn't part of MachineJumpTableInfo.
292 /// If this function returns true, it _does_ mean that branch target
293 /// enforcement needs to put a BTI or equivalent at the start of the block.
296 /// Test whether this block is the target of an IR BlockAddress. (There can
297 /// more than one MBB associated with an IR BB where the address is taken.)
299 /// If this function returns true, it _does_ mean that branch target
300 /// enforcement needs to put a BTI or equivalent at the start of the block.
303 /// Retrieves the BasicBlock which corresponds to this MachineBasicBlock.
306 /// Set this block to indicate that its address is used as something other
307 /// than the target of a terminator, exception-handling target, jump table,
308 /// or IR-level "blockaddress".
311 /// Set this block to reflect that it corresponds to an IR-level basic block
312 /// with a BlockAddress.
315 /// Test whether this block must have its label emitted.
318 /// Set this block to reflect that, regardless how we flow to it, we need
319 /// its label be emitted.
322 /// Return the MachineFunction containing this basic block.
326 /// Returns true if the original IR terminator is an `indirectbr` with
327 /// successor blocks. This typically corresponds to a `goto` in C, rather than
347 unsigned size()
const {
return (
unsigned)Insts.size(); }
349 bool empty()
const {
return Insts.empty(); }
392 /// Support for MachineInstr::getNextNode().
394 return &MachineBasicBlock::Insts;
404 /// Returns a range that iterates over the phis in the basic block.
409 return const_cast<MachineBasicBlock *
>(
this)->
phis();
412 // Machine-CFG iterators
432 {
return Predecessors.rbegin();}
434{
return Predecessors.rbegin();}
436 {
return Predecessors.rend(); }
438{
return Predecessors.rend(); }
440 return (
unsigned)Predecessors.size();
448 {
return Successors.rbegin(); }
450{
return Successors.rbegin(); }
452 {
return Successors.rend(); }
454{
return Successors.rend(); }
456 return (
unsigned)Successors.size();
473 // LiveIn management methods.
475 /// Adds the specified register as a live in. Note that it is an error to add
476 /// the same register to the same set more than once unless the intention is
477 /// to call sortUniqueLiveIns after all registers are added.
483 LiveIns.push_back(RegMaskPair);
486 /// Sorts and uniques the LiveIns vector. It can be significantly faster to do
487 /// this than repeatedly calling isLiveIn before calling addLiveIn for every
488 /// LiveIn insertion.
491 /// Clear live in list.
494 /// Clear the live in list, and return the removed live in's in \p OldLiveIns.
495 /// Requires that the vector \p OldLiveIns is empty.
498 /// Add PhysReg as live in to this block, and ensure that there is a copy of
499 /// PhysReg to a virtual register of class RC. Return the virtual register
500 /// that is a copy of the live in PhysReg.
504 /// Remove the specified register from the live in set.
508 /// Remove the specified register from any overlapped live in. The method is
509 /// subreg-aware and removes Reg and its subregs from the live in set. It also
510 /// clears the corresponding bitmask from its live-in super registers.
513 /// Return true if the specified register is in the live in set.
517 // Iteration support for live in sets. These sets are kept in sorted
518 // order by their register number.
521 /// Unlike livein_begin, this method does not check that the liveness
522 /// information is accurate. Still for debug purposes it may be useful
523 /// to have iterators that won't assert if the liveness information
537 /// Remove entry from the livein set and return iterator to the next.
540 const std::vector<RegisterMaskPair> &
getLiveIns()
const {
return LiveIns; }
552 : ExceptionPointer(ExceptionPointer),
553 ExceptionSelector(ExceptionSelector), BlockI(
MBB.
succ_begin()),
557 else if (BlockI != BlockEnd) {
558 LiveRegI = (*BlockI)->livein_begin();
559 if (!advanceToValidPosition())
561 if ((*BlockI)->isEHPad() && (LiveRegI->PhysReg == ExceptionPointer ||
562 LiveRegI->PhysReg == ExceptionSelector))
570 if (!advanceToValidPosition())
572 }
while ((*BlockI)->isEHPad() &&
573 (LiveRegI->PhysReg == ExceptionPointer ||
574 LiveRegI->PhysReg == ExceptionSelector));
593 if (BlockI != BlockEnd)
594 return BlockI ==
RHS.BlockI && LiveRegI ==
RHS.LiveRegI;
595 return RHS.BlockI == BlockEnd;
599 return !(*
this ==
RHS);
602 bool advanceToValidPosition() {
603 if (LiveRegI != (*BlockI)->livein_end())
608 }
while (BlockI != BlockEnd && (*BlockI)->livein_empty());
609 if (BlockI == BlockEnd)
612 LiveRegI = (*BlockI)->livein_begin();
616 MCPhysReg ExceptionPointer, ExceptionSelector;
622 /// Iterator scanning successor basic blocks' liveins to determine the
623 /// registers potentially live at the end of this block. There may be
624 /// duplicates or overlapping registers in the list returned.
633 /// Get the clobber mask for the start of this basic block. Funclets use this
634 /// to prevent register allocation across funclet transitions.
638 /// Get the clobber mask for the end of the basic block.
639 /// \see getBeginClobberMask()
643 /// Return alignment of the basic block.
646 /// Set alignment of the basic block.
654 /// Return the maximum amount of padding allowed for aligning the basic block.
657 /// Set the maximum amount of padding allowed for aligning the basic block
659 MaxBytesForAlignment = MaxBytes;
662 /// Returns true if the block is a landing pad. That is this basic block is
663 /// entered via an exception handler.
666 /// Indicates the block is a landing pad. That is this basic block is entered
667 /// via an exception handler.
672 /// Returns true if this is the entry block of the function.
675 /// Returns true if this is the entry block of an EH scope, i.e., the block
676 /// that used to have a catchpad or cleanuppad instruction in the LLVM IR.
679 /// Indicates if this is the entry block of an EH scope, i.e., the block that
680 /// that used to have a catchpad or cleanuppad instruction in the LLVM IR.
683 /// Returns true if this is a target of Windows EH Continuation Guard.
686 /// Indicates if this is a target of Windows EH Continuation Guard.
689 /// Returns true if this is the entry block of an EH funclet.
692 /// Indicates if this is the entry block of an EH funclet.
695 /// Returns true if this is the entry block of a cleanup funclet.
698 /// Indicates if this is the entry block of a cleanup funclet.
701 /// Returns true if this block begins any section.
704 /// Returns true if this block ends any section.
711 std::optional<UniqueBBID>
getBBID()
const {
return BBID; }
713 /// Returns the section ID of this basic block.
716 /// Sets the fixed BBID of this basic block.
718 assert(!BBID.has_value() &&
"Cannot change BBID.");
722 /// Sets the section ID for this basic block.
725 /// Returns the MCSymbol marking the end of this basic block.
728 /// Returns true if this block may have an INLINEASM_BR (overestimate, by
729 /// checking if any of the successors are indirect targets of any inlineasm_br
730 /// in the function).
733 /// Returns true if this is the indirect dest of an INLINEASM_BR.
735 return IsInlineAsmBrIndirectTarget;
738 /// Indicates if this is the indirect dest of an INLINEASM_BR.
740 IsInlineAsmBrIndirectTarget = V;
743 /// Returns true if it is legal to hoist instructions into this block.
746 // Code Layout methods.
748 /// Move 'this' block before or after the specified block. This only moves
749 /// the block, it does not modify the CFG or adjust potential fall-throughs at
750 /// the end of the block.
754 /// Returns true if this and MBB belong to the same section.
759 /// Update the terminator instructions in block to account for changes to
760 /// block layout which may have been made. PreviousLayoutSuccessor should be
761 /// set to the block which may have been used as fallthrough before the block
762 /// layout was modified. If the block previously fell through to that block,
763 /// it may now need a branch. If it previously branched to another block, it
764 /// may now be able to fallthrough to the current layout successor.
767 // Machine-CFG mutators
769 /// Add Succ as a successor of this MachineBasicBlock. The Predecessors list
770 /// of Succ is automatically updated. PROB parameter is stored in
771 /// Probabilities list. The default probability is set as unknown. Mixing
772 /// known and unknown probabilities in successor list is not allowed. When all
773 /// successors have unknown probabilities, 1 / N is returned as the
774 /// probability for each successor, where N is the number of successors.
776 /// Note that duplicate Machine CFG edges are not allowed.
781 /// Add Succ as a successor of this MachineBasicBlock. The Predecessors list
782 /// of Succ is automatically updated. The probability is not provided because
783 /// BPI is not available (e.g. -O0 is used), in which case edge probabilities
784 /// won't be used. Using this interface can save some space.
787 /// Set successor probability of a given iterator.
790 /// Normalize probabilities of all successors so that the sum of them becomes
791 /// one. This is usually done when the current update on this MBB is done, and
792 /// the sum of its successors' probabilities is not guaranteed to be one. The
793 /// user is responsible for the correct use of this function.
794 /// MBB::removeSuccessor() has an option to do this automatically.
799 /// Validate successors' probabilities and check if the sum of them is
800 /// approximate one. This only works in DEBUG mode.
803 /// Remove successor from the successors list of this MachineBasicBlock. The
804 /// Predecessors list of Succ is automatically updated.
805 /// If NormalizeSuccProbs is true, then normalize successors' probabilities
806 /// after the successor is removed.
808 bool NormalizeSuccProbs =
false);
810 /// Remove specified successor from the successors list of this
811 /// MachineBasicBlock. The Predecessors list of Succ is automatically updated.
812 /// If NormalizeSuccProbs is true, then normalize successors' probabilities
813 /// after the successor is removed.
814 /// Return the iterator to the element after the one removed.
816 bool NormalizeSuccProbs =
false);
818 /// Replace successor OLD with NEW and update probability info.
822 /// Copy a successor (and any probability info) from original block to this
823 /// block's. Uses an iterator into the original blocks successors.
825 /// This is useful when doing a partial clone of successors. Afterward, the
826 /// probabilities may need to be normalized.
829 /// Split the old successor into old plus new and updates the probability
832 bool NormalizeSuccProbs =
false);
834 /// Transfers all the successors from MBB to this machine basic block (i.e.,
835 /// copies all the successors FromMBB and remove all the successors from
839 /// Transfers all the successors, as in transferSuccessors, and update PHI
840 /// operands in the successor blocks which refer to FromMBB to refer to this.
843 /// Return true if any of the successors have probabilities attached to them.
846 /// Return true if the specified MBB is a predecessor of this block.
849 /// Return true if the specified MBB is a successor of this block.
852 /// Return true if the specified MBB will be emitted immediately after this
853 /// block, such that if this block exits by falling through, control will
854 /// transfer to the specified MBB. Note that MBB need not be a successor at
855 /// all, for example if this block ends with an unconditional branch to some
859 /// Return the successor of this block if it has a single successor.
860 /// Otherwise return a null pointer.
864 return const_cast<MachineBasicBlock *
>(
865 static_cast<const MachineBasicBlock *
>(
this)->getSingleSuccessor());
868 /// Return the predecessor of this block if it has a single predecessor.
869 /// Otherwise return a null pointer.
873 return const_cast<MachineBasicBlock *
>(
874 static_cast<const MachineBasicBlock *
>(
this)->getSinglePredecessor());
877 /// Return the fallthrough block if the block can implicitly
878 /// transfer control to the block after it by falling off the end of
879 /// it. If an explicit branch to the fallthrough block is not allowed,
880 /// set JumpToFallThrough to be false. Non-null return is a conservative
884 /// Return the fallthrough block if the block can implicitly
885 /// transfer control to it's successor, whether by a branch or
886 /// a fallthrough. Non-null return is a conservative answer.
889 /// Return true if the block can implicitly transfer control to the
890 /// block after it by falling off the end of it. This should return
891 /// false if it can reach the block after it, but it uses an
892 /// explicit branch to do so (e.g., a table jump). True is a
893 /// conservative answer.
896 /// Returns a pointer to the first instruction in this block that is not a
897 /// PHINode instruction. When adding instructions to the beginning of the
898 /// basic block, they should be added before the returned value, not before
899 /// the first instruction, which might be PHI.
900 /// Returns end() is there's no non-PHI instruction.
906 /// Return the first instruction in MBB after I that is not a PHI or a label.
907 /// This is the correct point to insert lowered copies at the beginning of a
908 /// basic block that must be before any debugging information.
911 /// Return the first instruction in MBB after I that is not a PHI, label or
912 /// debug. This is the correct point to insert copies at the beginning of a
913 /// basic block. \p Reg is the register being used by a spill or defined for a
914 /// restore/split during register allocation.
917 bool SkipPseudoOp =
true);
919 /// Returns an iterator to the first terminator instruction of this basic
920 /// block. If a terminator does not exist, it returns end().
926 /// Same getFirstTerminator but it ignores bundles and return an
927 /// instr_iterator instead.
930 /// Finds the first terminator in a block by scanning forward. This can handle
931 /// cases in GlobalISel where there may be non-terminator instructions between
932 /// terminators, for which getFirstTerminator() will not work correctly.
935 /// Returns an iterator to the first non-debug instruction in the basic block,
936 /// or end(). Skip any pseudo probe operation if \c SkipPseudoOp is true.
937 /// Pseudo probes are like debug instructions which do not turn into real
938 /// machine code. We try to use the function to skip both debug instructions
939 /// and pseudo probe operations to avoid API proliferation. This should work
940 /// most of the time when considering optimizing the rest of code in the
941 /// block, except for certain cases where pseudo probes are designed to block
942 /// the optimizations. For example, code merge like optimizations are supposed
943 /// to be blocked by pseudo probes for better AutoFDO profile quality.
944 /// Therefore, they should be considered as a valid instruction when this
945 /// function is called in a context of such optimizations. On the other hand,
946 /// \c SkipPseudoOp should be true when it's used in optimizations that
947 /// unlikely hurt profile quality, e.g., without block merging. The default
948 /// value of \c SkipPseudoOp is set to true to maximize code quality in
949 /// general, with an explict false value passed in in a few places like branch
950 /// folding and if-conversion to favor profile quality.
957 /// Returns an iterator to the last non-debug instruction in the basic block,
958 /// or end(). Skip any pseudo operation if \c SkipPseudoOp is true.
959 /// Pseudo probes are like debug instructions which do not turn into real
960 /// machine code. We try to use the function to skip both debug instructions
961 /// and pseudo probe operations to avoid API proliferation. This should work
962 /// most of the time when considering optimizing the rest of code in the
963 /// block, except for certain cases where pseudo probes are designed to block
964 /// the optimizations. For example, code merge like optimizations are supposed
965 /// to be blocked by pseudo probes for better AutoFDO profile quality.
966 /// Therefore, they should be considered as a valid instruction when this
967 /// function is called in a context of such optimizations. On the other hand,
968 /// \c SkipPseudoOp should be true when it's used in optimizations that
969 /// unlikely hurt profile quality, e.g., without block merging. The default
970 /// value of \c SkipPseudoOp is set to true to maximize code quality in
971 /// general, with an explict false value passed in in a few places like branch
972 /// folding and if-conversion to favor profile quality.
979 /// Convenience function that returns true if the block ends in a return
985 /// Convenience function that returns true if the bock ends in a EH scope
986 /// return instruction.
991 /// Split a basic block into 2 pieces at \p SplitPoint. A new block will be
992 /// inserted after this block, and all instructions after \p SplitInst moved
993 /// to it (\p SplitInst will be in the original block). If \p LIS is provided,
994 /// LiveIntervals will be appropriately updated. \return the newly inserted
997 /// If \p UpdateLiveIns is true, this will ensure the live ins list is
998 /// accurate, including for physreg uses/defs in the original block.
1000 bool UpdateLiveIns =
true,
1003 /// Split the critical edge from this block to the given successor block, and
1004 /// return the newly created block, or null if splitting is not possible.
1006 /// This function updates LiveVariables, MachineDominatorTree, and
1007 /// MachineLoopInfo, as applicable.
1030 // Helper method for new pass manager migration.
1039 /// Check if the edge between this block and the given successor \p
1040 /// Succ, can be split. If this returns true a subsequent call to
1041 /// SplitCriticalEdge is guaranteed to return a valid basic block if
1042 /// no changes occurred in the meantime.
1051 /// Insert MI into the instruction list before I, possibly inside a bundle.
1053 /// If the insertion point is inside a bundle, MI will be added to the bundle,
1054 /// otherwise MI will not be added to any bundle. That means this function
1055 /// alone can't be used to prepend or append instructions to bundles. See
1056 /// MIBundleBuilder::insert() for a more reliable way of doing that.
1059 /// Insert a range of instructions into the instruction list before I.
1060 template<
typename IT>
1063 "iterator points outside of basic block");
1064 Insts.insert(
I.getInstrIterator(), S,
E);
1067 /// Insert MI into the instruction list before I.
1070 "iterator points outside of basic block");
1071 assert(!
MI->isBundledWithPred() && !
MI->isBundledWithSucc() &&
1072 "Cannot insert instruction with bundle flags");
1073 return Insts.insert(
I.getInstrIterator(),
MI);
1076 /// Insert MI into the instruction list after I.
1079 "iterator points outside of basic block");
1080 assert(!
MI->isBundledWithPred() && !
MI->isBundledWithSucc() &&
1081 "Cannot insert instruction with bundle flags");
1082 return Insts.insertAfter(
I.getInstrIterator(),
MI);
1085 /// If I is bundled then insert MI into the instruction list after the end of
1086 /// the bundle, otherwise insert MI immediately after I.
1089 "iterator points outside of basic block");
1090 assert(!
MI->isBundledWithPred() && !
MI->isBundledWithSucc() &&
1091 "Cannot insert instruction with bundle flags");
1092 while (
I->isBundledWithSucc())
1094 return Insts.insertAfter(
I,
MI);
1097 /// Remove an instruction from the instruction list and delete it.
1099 /// If the instruction is part of a bundle, the other instructions in the
1100 /// bundle will still be bundled after removing the single instruction.
1103 /// Remove an instruction from the instruction list and delete it.
1105 /// If the instruction is part of a bundle, the other instructions in the
1106 /// bundle will still be bundled after removing the single instruction.
1111 /// Remove a range of instructions from the instruction list and delete them.
1113 return Insts.erase(
I.getInstrIterator(),
E.getInstrIterator());
1116 /// Remove an instruction or bundle from the instruction list and delete it.
1118 /// If I points to a bundle of instructions, they are all erased.
1120 return erase(
I, std::next(
I));
1123 /// Remove an instruction from the instruction list and delete it.
1125 /// If I is the head of a bundle of instructions, the whole bundle will be
1131 /// Remove the unbundled instruction from the instruction list without
1134 /// This function can not be used to remove bundled instructions, use
1135 /// remove_instr to remove individual instructions from a bundle.
1137 assert(!
I->isBundled() &&
"Cannot remove bundled instructions");
1141 /// Remove the possibly bundled instruction from the instruction list
1142 /// without deleting it.
1144 /// If the instruction is part of a bundle, the other instructions in the
1145 /// bundle will still be bundled after removing the single instruction.
1152 /// Take an instruction from MBB 'Other' at the position From, and insert it
1153 /// into this MBB right before 'Where'.
1155 /// If From points to a bundle of instructions, the whole bundle is moved.
1157 // The range splice() doesn't allow noop moves, but this one does.
1162 /// Take a block of instructions from MBB 'Other' in the range [From, To),
1163 /// and insert them into this MBB right before 'Where'.
1165 /// The instruction at 'Where' must not be included in the range of
1166 /// instructions to move.
1173 /// This method unlinks 'this' from the containing function, and returns it,
1174 /// but does not delete it.
1177 /// This method unlinks 'this' from the containing function and deletes it.
1180 /// Given a machine basic block that branched to 'Old', change the code and
1181 /// CFG so that it branches to 'New' instead.
1185 /// Update all phi nodes in this basic block to refer to basic block \p New
1186 /// instead of basic block \p Old.
1190 /// Find the next valid DebugLoc starting at MBBI, skipping any debug
1191 /// instructions. Return UnknownLoc if there is none.
1197 /// Has exact same behavior as @ref findDebugLoc (it also searches towards the
1198 /// end of this MBB) except that this function takes a reverse iterator to
1199 /// identify the starting MI.
1205 /// Find the previous valid DebugLoc preceding MBBI, skipping any debug
1206 /// instructions. It is possible to find the last DebugLoc in the MBB using
1207 /// findPrevDebugLoc(instr_end()). Return UnknownLoc if there is none.
1213 /// Has exact same behavior as @ref findPrevDebugLoc (it also searches towards
1214 /// the beginning of this MBB) except that this function takes reverse
1215 /// iterator to identify the starting MI. A minor difference compared to
1216 /// findPrevDebugLoc is that we can't start scanning at "instr_end".
1222 /// Find and return the merged DebugLoc of the branch instructions of the
1223 /// block. Return UnknownLoc if there is none.
1226 /// Possible outcome of a register liveness query to computeRegisterLiveness()
1228 LQR_Live,
///< Register is known to be (at least partially) live.
1230 LQR_Unknown ///< Register liveness not decidable from local neighborhood.
1233 /// Return whether (physical) register \p Reg has been defined and not
1234 /// killed as of just before \p Before.
1236 /// Search is localised to a neighborhood of \p Neighborhood instructions
1237 /// before (searching for defs or kills) and \p Neighborhood instructions
1238 /// after (searching just for defs) \p Before.
1240 /// \p Reg must be a physical register.
1243 unsigned Neighborhood = 10)
const;
1245 // Debugging methods.
1248 bool IsStandalone =
true)
const;
1251 bool IsStandalone =
true)
const;
1262 // Printing method used by LoopInfo.
1265 /// MachineBasicBlocks are uniquely numbered at the function level, unless
1266 /// they're not in a MachineFunction yet, in which case this will return -1.
1270 /// Return the call frame size on entry to this basic block.
1272 /// Set the call frame size on entry to this basic block.
1275 /// Return the MCSymbol for this basic block.
1278 /// Return the Windows EH Continuation Symbol for this basic block.
1282 return IrrLoopHeaderWeight;
1286 IrrLoopHeaderWeight = Weight;
1289 /// Return probability of the edge from this block to MBB. This method should
1290 /// NOT be called directly, but by using getEdgeProbability method from
1291 /// MachineBranchProbabilityInfo class.
1294 // Helper function for MIRPrinter.
1297 /// Iterate over block PHI instructions and remove all incoming values for
1300 /// Method does not erase PHI instructions even if they have single income or
1301 /// do not have incoming values ar all. It is a caller responsibility to make
1302 /// decision how to process PHI instructions after incoming values removal.
1307 /// Return probability iterator corresponding to the I successor iterator.
1309 const_probability_iterator
1314 // Methods used to maintain doubly linked list of blocks...
1317 // Machine-CFG mutators
1319 /// Add Pred as a predecessor of this MachineBasicBlock. Don't do this
1320 /// unless you know what you're doing, because it doesn't update Pred's
1321 /// successors list. Use Pred->addSuccessor instead.
1322 void addPredecessor(MachineBasicBlock *Pred);
1324 /// Remove Pred as a predecessor of this MachineBasicBlock. Don't do this
1325 /// unless you know what you're doing, because it doesn't update Pred's
1326 /// successors list. Use Pred->removeSuccessor instead.
1327 void removePredecessor(MachineBasicBlock *Pred);
1332/// Prints a machine basic block reference.
1335/// %bb.5 - a machine basic block with MBB.getNumber() == 5.
1337/// Usage: OS << printMBBReference(MBB) << '\n';
1340// This is useful when building IndexedMaps keyed on basic block pointers.
1344 return MBB->getNumber();
1348//===--------------------------------------------------------------------===//
1349// GraphTraits specializations for machine basic block graphs (machine-CFGs)
1350//===--------------------------------------------------------------------===//
1352// Provide specializations of GraphTraits to be able to treat a
1353// MachineFunction as a graph of MachineBasicBlocks.
1371 "GraphTraits getNumber() not detected");
1388 "GraphTraits getNumber() not detected");
1390// Provide specializations of GraphTraits to be able to treat a
1391// MachineFunction as a graph of MachineBasicBlocks and to walk it
1392// in inverse order. Inverse order for a function is considered
1393// to be when traversing the predecessor edges of a MBB
1394// instead of the successor edges.
1414 "GraphTraits getNumber() not detected");
1434 "GraphTraits getNumber() not detected");
1436// These accessors are handy for sharing templated code between IR and MIR.
1448/// MachineInstrSpan provides an interface to get an iteration range
1449/// containing the instruction it was initialized with, along with all
1450/// those instructions inserted prior to or following that instruction
1451/// at some point after the MachineInstrSpan is constructed.
1458 : MBB(*BB), I(I), B(I == MBB.
begin() ? MBB.
end() :
std::prev(I)),
1460 assert(I == BB->
end() || I->getParent() == BB);
1464 return B == MBB.end() ? MBB.begin() : std::next(B);
1472/// Increment \p It until it points to a non-debug instruction or to \p End
1473/// and return the resulting iterator. This function should only be used
1474/// MachineBasicBlock::{iterator, const_iterator, instr_iterator,
1475/// const_instr_iterator} and the respective reverse iterators.
1476template <
typename IterT>
1478 bool SkipPseudoOp =
true) {
1480 (It->isDebugInstr() || (SkipPseudoOp && It->isPseudoProbe())))
1485/// Decrement \p It until it points to a non-debug instruction or to \p Begin
1486/// and return the resulting iterator. This function should only be used
1487/// MachineBasicBlock::{iterator, const_iterator, instr_iterator,
1488/// const_instr_iterator} and the respective reverse iterators.
1489template <
class IterT>
1491 bool SkipPseudoOp =
true) {
1492 while (It != Begin &&
1493 (It->isDebugInstr() || (SkipPseudoOp && It->isPseudoProbe())))
1498/// Increment \p It, then continue incrementing it while it points to a debug
1499/// instruction. A replacement for std::next.
1500template <
typename IterT>
1501 inline IterT
next_nodbg(IterT It, IterT End,
bool SkipPseudoOp =
true) {
1505/// Decrement \p It, then continue decrementing it while it points to a debug
1506/// instruction. A replacement for std::prev.
1507template <
typename IterT>
1508 inline IterT
prev_nodbg(IterT It, IterT Begin,
bool SkipPseudoOp =
true) {
1512/// Construct a range iterator which begins at \p It and moves forwards until
1513/// \p End is reached, skipping any debug instructions.
1514template <
typename IterT>
1516 bool SkipPseudoOp =
true) {
1518 return !
MI.isDebugInstr() && !(SkipPseudoOp &&
MI.isPseudoProbe());
1522}
// end namespace llvm
1524#endif // LLVM_CODEGEN_MACHINEBASICBLOCK_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator MBBI
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::values(clEnumValN(DefaultIT, "arm-default-it", "Generate any type of IT block"), clEnumValN(RestrictedIT, "arm-restrict-it", "Disallow complex IT blocks")))
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines DenseMapInfo traits for DenseMap.
This file defines the little GraphTraits<X> template class that should be specialized by classes that...
A common definition of LaneBitmask for use in TableGen and CodeGen.
Register const TargetRegisterInfo * TRI
Promote Memory to Register
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
This file defines the SparseBitVector class.
LLVM Basic Block Representation.
static BranchProbability getUnknown()
static void normalizeProbabilities(ProbabilityIter Begin, ProbabilityIter End)
Wrapper class representing physical registers. Should be passed by value.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
liveout_iterator(const MachineBasicBlock &MBB, MCPhysReg ExceptionPointer, MCPhysReg ExceptionSelector, bool End)
liveout_iterator & operator++()
std::ptrdiff_t difference_type
const RegisterMaskPair & reference
reference operator*() const
const RegisterMaskPair * pointer
std::input_iterator_tag iterator_category
liveout_iterator operator++(int)
bool operator==(const liveout_iterator &RHS) const
RegisterMaskPair value_type
pointer operator->() const
bool operator!=(const liveout_iterator &RHS) const
const MachineInstr & instr_front() const
bool isInlineAsmBrIndirectTarget() const
Returns true if this is the indirect dest of an INLINEASM_BR.
LLVM_ABI DebugLoc rfindPrevDebugLoc(reverse_instr_iterator MBBI)
Has exact same behavior as findPrevDebugLoc (it also searches towards the beginning of this MBB) exce...
Instructions::const_reverse_iterator const_reverse_instr_iterator
unsigned pred_size() const
LLVM_ABI void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *FromMBB)
Transfers all the successors, as in transferSuccessors, and update PHI operands in the successor bloc...
LLVM_ABI bool hasEHPadSuccessor() const
void setBBID(const UniqueBBID &V)
Sets the fixed BBID of this basic block.
iterator erase(MachineInstr *I)
Remove an instruction from the instruction list and delete it.
void normalizeSuccProbs()
Normalize probabilities of all successors so that the sum of them becomes one.
void setAddressTakenIRBlock(BasicBlock *BB)
Set this block to reflect that it corresponds to an IR-level basic block with a BlockAddress.
livein_iterator livein_end() const
LLVM_ABI iterator getFirstTerminatorForward()
Finds the first terminator in a block by scanning forward.
bool isEHPad() const
Returns true if the block is a landing pad.
iterator_range< liveout_iterator > liveouts() const
const MachineInstr & back() const
LLVM_ABI void replacePhiUsesWith(MachineBasicBlock *Old, MachineBasicBlock *New)
Update all phi nodes in this basic block to refer to basic block New instead of basic block Old.
LLVM_ABI MachineInstr * remove_instr(MachineInstr *I)
Remove the possibly bundled instruction from the instruction list without deleting it.
instr_iterator instr_begin()
void setIsEndSection(bool V=true)
MachineInstrBundleIterator< const MachineInstr > const_iterator
void setIrrLoopHeaderWeight(uint64_t Weight)
MachineBasicBlock * getLogicalFallThrough()
Return the fallthrough block if the block can implicitly transfer control to it's successor,...
LLVM_ABI MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
void setIsCleanupFuncletEntry(bool V=true)
Indicates if this is the entry block of a cleanup funclet.
DebugLoc rfindPrevDebugLoc(reverse_iterator MBBI)
const_pred_iterator pred_end() const
LLVM_ABI void moveBefore(MachineBasicBlock *NewAfter)
Move 'this' block before or after the specified block.
void setLabelMustBeEmitted()
Set this block to reflect that, regardless how we flow to it, we need its label be emitted.
LLVM_ABI void replaceSuccessor(MachineBasicBlock *Old, MachineBasicBlock *New)
Replace successor OLD with NEW and update probability info.
SmallVectorImpl< MachineBasicBlock * >::reverse_iterator succ_reverse_iterator
const_pred_reverse_iterator pred_rend() const
LLVM_ABI MachineBasicBlock * getFallThrough(bool JumpToFallThrough=true)
Return the fallthrough block if the block can implicitly transfer control to the block after it by fa...
LLVM_ABI void transferSuccessors(MachineBasicBlock *FromMBB)
Transfers all the successors from MBB to this machine basic block (i.e., copies all the successors Fr...
MachineBasicBlock * SplitCriticalEdge(MachineBasicBlock *Succ, Pass &P, std::vector< SparseBitVector<> > *LiveInSets=nullptr, MachineDomTreeUpdater *MDTU=nullptr)
bool hasLabelMustBeEmitted() const
Test whether this block must have its label emitted.
const_iterator getFirstNonDebugInstr(bool SkipPseudoOp=true) const
LLVM_ABI instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
LLVM_ABI BranchProbability getSuccProbability(const_succ_iterator Succ) const
Return probability of the edge from this block to MBB.
const_reverse_instr_iterator instr_rend() const
iterator_range< livein_iterator > liveins() const
void setAlignment(Align A, unsigned MaxBytes)
iterator_range< iterator > phis()
Returns a range that iterates over the phis in the basic block.
reverse_instr_iterator instr_rbegin()
instr_iterator erase_instr(MachineInstr *I)
Remove an instruction from the instruction list and delete it.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
void push_back(MachineInstr *MI)
LLVM_ABI iterator SkipPHIsAndLabels(iterator I)
Return the first instruction in MBB after I that is not a PHI or a label.
pred_reverse_iterator pred_rbegin()
LLVM_ABI void addSuccessorWithoutProb(MachineBasicBlock *Succ)
Add Succ as a successor of this MachineBasicBlock.
SmallVectorImpl< MachineBasicBlock * >::const_iterator const_succ_iterator
SmallVectorImpl< MachineBasicBlock * >::const_reverse_iterator const_pred_reverse_iterator
LLVM_ABI bool hasName() const
Check if there is a name of corresponding LLVM basic block.
MachineBasicBlock * getSinglePredecessor()
void setCallFrameSize(unsigned N)
Set the call frame size on entry to this basic block.
std::optional< UniqueBBID > getBBID() const
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
LLVM_ABI MCSymbol * getEHContSymbol() const
Return the Windows EH Continuation Symbol for this basic block.
LLVM_ABI void splitSuccessor(MachineBasicBlock *Old, MachineBasicBlock *New, bool NormalizeSuccProbs=false)
Split the old successor into old plus new and updates the probability info.
liveout_iterator liveout_end() const
const_instr_iterator instr_begin() const
const_succ_iterator succ_begin() const
const_succ_reverse_iterator succ_rbegin() const
pred_reverse_iterator pred_rend()
@ PrintNameIr
Add IR name where available.
@ PrintNameAttributes
Print attributes.
LLVM_ABI void updateTerminator(MachineBasicBlock *PreviousLayoutSuccessor)
Update the terminator instructions in block to account for changes to block layout which may have bee...
LLVM_ABI const MachineBasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor.
LLVM_ABI iterator SkipPHIsLabelsAndDebug(iterator I, Register Reg=Register(), bool SkipPseudoOp=true)
Return the first instruction in MBB after I that is not a PHI, label or debug.
LLVM_ABI bool canFallThrough()
Return true if the block can implicitly transfer control to the block after it by falling off the end...
LLVM_ABI void setSuccProbability(succ_iterator I, BranchProbability Prob)
Set successor probability of a given iterator.
LLVM_ABI iterator getFirstNonDebugInstr(bool SkipPseudoOp=true)
Returns an iterator to the first non-debug instruction in the basic block, or end().
succ_iterator succ_begin()
DebugLoc rfindDebugLoc(reverse_iterator MBBI)
bool livein_empty() const
bool terminatorIsComputedGotoWithSuccessors() const
Returns true if the original IR terminator is an indirectbr with successor blocks.
LLVM_ABI void removeLiveIn(MCRegister Reg, LaneBitmask LaneMask=LaneBitmask::getAll())
Remove the specified register from the live in set.
iterator erase(iterator I, iterator E)
Remove a range of instructions from the instruction list and delete them.
const MachineInstr & front() const
LLVM_ABI void printAsOperand(raw_ostream &OS, bool PrintType=true) const
MachineInstr * remove(MachineInstr *I)
Remove the unbundled instruction from the instruction list without deleting it.
const_instr_range instrs() const
const_reverse_iterator rbegin() const
void clearBasicBlock()
Remove the reference to the underlying IR BasicBlock.
unsigned getMaxBytesForAlignment() const
Return the maximum amount of padding allowed for aligning the basic block.
void setMaxBytesForAlignment(unsigned MaxBytes)
Set the maximum amount of padding allowed for aligning the basic block.
LLVM_ABI void validateSuccProbs() const
Validate successors' probabilities and check if the sum of them is approximate one.
iterator_range< const_pred_iterator > predecessors() const
const MachineInstr & instr_back() const
bool isIRBlockAddressTaken() const
Test whether this block is the target of an IR BlockAddress.
LiveInVector::const_iterator livein_iterator
LLVM_ABI MCSymbol * getEndSymbol() const
Returns the MCSymbol marking the end of this basic block.
void splice(iterator Where, MachineBasicBlock *Other, iterator From, iterator To)
Take a block of instructions from MBB 'Other' in the range [From, To), and insert them into this MBB ...
LLVM_ABI void clearLiveIns()
Clear live in list.
bool isEHFuncletEntry() const
Returns true if this is the entry block of an EH funclet.
const_iterator getLastNonDebugInstr(bool SkipPseudoOp=true) const
LLVM_ABI LivenessQueryResult computeRegisterLiveness(const TargetRegisterInfo *TRI, MCRegister Reg, const_iterator Before, unsigned Neighborhood=10) const
Return whether (physical) register Reg has been defined and not killed as of just before Before.
LLVM_ABI iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
bool sameSection(const MachineBasicBlock *MBB) const
Returns true if this and MBB belong to the same section.
const std::vector< RegisterMaskPair > & getLiveIns() const
iterator insert(iterator I, MachineInstr *MI)
Insert MI into the instruction list before I.
LLVM_ABI livein_iterator livein_begin() const
unsigned succ_size() const
bool isReturnBlock() const
Convenience function that returns true if the block ends in a return instruction.
iterator_range< livein_iterator > liveins_dbg() const
LLVM_ABI const uint32_t * getBeginClobberMask(const TargetRegisterInfo *TRI) const
Get the clobber mask for the start of this basic block.
LLVM_ABI void removePHIsIncomingValuesForPredecessor(const MachineBasicBlock &PredMBB)
Iterate over block PHI instructions and remove all incoming values for PredMBB.
bool hasAddressTaken() const
Test whether this block is used as something other than the target of a terminator,...
MBBSectionID getSectionID() const
Returns the section ID of this basic block.
void setAlignment(Align A)
Set alignment of the basic block.
LLVM_ABI void dump() const
bool isEHScopeEntry() const
Returns true if this is the entry block of an EH scope, i.e., the block that used to have a catchpad ...
MachineInstr & instr_back()
LLVM_ABI bool isEntryBlock() const
Returns true if this is the entry block of the function.
iterator_range< const_instr_iterator > const_instr_range
LLVM_ABI void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
SmallVectorImpl< MachineBasicBlock * >::const_reverse_iterator const_succ_reverse_iterator
LLVM_ABI void copySuccessor(const MachineBasicBlock *Orig, succ_iterator I)
Copy a successor (and any probability info) from original block to this block's.
SmallVectorImpl< MachineBasicBlock * >::iterator succ_iterator
const_pred_reverse_iterator pred_rbegin() const
void addLiveIn(const RegisterMaskPair &RegMaskPair)
MachineBasicBlock * SplitCriticalEdge(MachineBasicBlock *Succ, MachineFunctionAnalysisManager &MFAM, std::vector< SparseBitVector<> > *LiveInSets=nullptr, MachineDomTreeUpdater *MDTU=nullptr)
MachineBasicBlock * getSingleSuccessor()
BasicBlock * getAddressTakenIRBlock() const
Retrieves the BasicBlock which corresponds to this MachineBasicBlock.
const_iterator getFirstNonPHI() const
LLVM_ABI void sortUniqueLiveIns()
Sorts and uniques the LiveIns vector.
LLVM_ABI const MachineBasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
iterator_range< const_iterator > phis() const
const_instr_iterator instr_end() const
LLVM_ABI liveout_iterator liveout_begin() const
Iterator scanning successor basic blocks' liveins to determine the registers potentially live at the ...
DebugLoc findDebugLoc(iterator MBBI)
SmallVectorImpl< MachineBasicBlock * >::iterator pred_iterator
LLVM_ABI void removeSuccessor(MachineBasicBlock *Succ, bool NormalizeSuccProbs=false)
Remove successor from the successors list of this MachineBasicBlock.
const_succ_iterator succ_end() const
LLVM_ABI iterator getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
const_iterator begin() const
LLVM_ABI bool isPredecessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a predecessor of this block.
bool hasSuccessorProbabilities() const
Return true if any of the successors have probabilities attached to them.
void setSectionID(MBBSectionID V)
Sets the section ID for this basic block.
iterator_range< const_iterator > terminators() const
livein_iterator livein_begin_dbg() const
Unlike livein_begin, this method does not check that the liveness information is accurate.
LLVM_ABI DebugLoc rfindDebugLoc(reverse_instr_iterator MBBI)
Has exact same behavior as findDebugLoc (it also searches towards the end of this MBB) except that th...
const_pred_iterator pred_begin() const
LLVM_ABI void print(raw_ostream &OS, const SlotIndexes *=nullptr, bool IsStandalone=true) const
reverse_instr_iterator instr_rend()
const_reverse_iterator rend() const
LLVM_ABI DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any debug instructions.
Instructions::iterator instr_iterator
pred_iterator pred_begin()
LLVM_ABI iterator getLastNonDebugInstr(bool SkipPseudoOp=true)
Returns an iterator to the last non-debug instruction in the basic block, or end().
LLVM_ABI void ReplaceUsesOfBlockWith(MachineBasicBlock *Old, MachineBasicBlock *New)
Given a machine basic block that branched to 'Old', change the code and CFG so that it branches to 'N...
MachineInstrBundleIterator< MachineInstr, true > reverse_iterator
succ_reverse_iterator succ_rbegin()
LLVM_ABI bool isLayoutSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB will be emitted immediately after this block, such that if this bloc...
static Instructions MachineBasicBlock::* getSublistAccess(MachineInstr *)
Support for MachineInstr::getNextNode().
LLVM_ABI DebugLoc findPrevDebugLoc(instr_iterator MBBI)
Find the previous valid DebugLoc preceding MBBI, skipping any debug instructions.
LLVM_ABI MachineBasicBlock * splitAt(MachineInstr &SplitInst, bool UpdateLiveIns=true, LiveIntervals *LIS=nullptr)
Split a basic block into 2 pieces at SplitPoint.
MachineFunction * getParent()
LLVM_ABI bool canSplitCriticalEdge(const MachineBasicBlock *Succ, const MachineLoopInfo *MLI=nullptr) const
Check if the edge between this block and the given successor Succ, can be split.
LLVM_ABI void eraseFromParent()
This method unlinks 'this' from the containing function and deletes it.
friend class MachineFunction
LLVM_ABI void removeLiveInOverlappedWith(MCRegister Reg)
Remove the specified register from any overlapped live in.
void setIsInlineAsmBrIndirectTarget(bool V=true)
Indicates if this is the indirect dest of an INLINEASM_BR.
instr_iterator instr_end()
Instructions::const_iterator const_instr_iterator
iterator_range< const_succ_iterator > successors() const
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
const_iterator getFirstTerminator() const
const_succ_reverse_iterator succ_rend() const
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
void setIsEHContTarget(bool V=true)
Indicates if this is a target of Windows EH Continuation Guard.
LLVM_ABI instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
LLVM_ABI std::string getFullName() const
Return a formatted string to identify this block and its parent function.
bool isBeginSection() const
Returns true if this block begins any section.
DebugLoc findPrevDebugLoc(iterator MBBI)
iterator_range< iterator > terminators()
bool isEHContTarget() const
Returns true if this is a target of Windows EH Continuation Guard.
unsigned getCallFrameSize() const
Return the call frame size on entry to this basic block.
void setIsEHFuncletEntry(bool V=true)
Indicates if this is the entry block of an EH funclet.
friend class MachineBranchProbabilityInfo
LLVM_ABI DebugLoc findBranchDebugLoc()
Find and return the merged DebugLoc of the branch instructions of the block.
iterator_range< succ_iterator > successors()
LLVM_ABI instr_iterator getFirstInstrTerminator()
Same getFirstTerminator but it ignores bundles and return an instr_iterator instead.
reverse_iterator rbegin()
bool isMachineBlockAddressTaken() const
Test whether this block is used as something other than the target of a terminator,...
LLVM_ABI void printName(raw_ostream &os, unsigned printNameFlags=PrintNameIr, ModuleSlotTracker *moduleSlotTracker=nullptr) const
Print the basic block's name as:
iterator insertAfter(iterator I, MachineInstr *MI)
Insert MI into the instruction list after I.
SmallVectorImpl< MachineBasicBlock * >::reverse_iterator pred_reverse_iterator
LLVM_ABI bool isSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a successor of this block.
iterator_range< pred_iterator > predecessors()
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
bool isEHScopeReturnBlock() const
Convenience function that returns true if the bock ends in a EH scope return instruction.
bool isEndSection() const
Returns true if this block ends any section.
Align getAlignment() const
Return alignment of the basic block.
MachineInstrBundleIterator< MachineInstr > iterator
LLVM_ABI bool isLegalToHoistInto() const
Returns true if it is legal to hoist instructions into this block.
MachineInstr & instr_front()
LLVM_ABI bool canPredictBranchProbabilities() const
const_reverse_instr_iterator instr_rbegin() const
iterator erase(iterator I)
Remove an instruction or bundle from the instruction list and delete it.
instr_iterator insertAfterBundle(instr_iterator I, MachineInstr *MI)
If I is bundled then insert MI into the instruction list after the end of the bundle,...
const_iterator end() const
LLVM_ABI StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
LLVM_ABI bool mayHaveInlineAsmBr() const
Returns true if this block may have an INLINEASM_BR (overestimate, by checking if any of the successo...
LivenessQueryResult
Possible outcome of a register liveness query to computeRegisterLiveness()
@ LQR_Dead
Register is known to be fully dead.
@ LQR_Live
Register is known to be (at least partially) live.
@ LQR_Unknown
Register liveness not decidable from local neighborhood.
MachineInstrBundleIterator< const MachineInstr, true > const_reverse_iterator
SmallVectorImpl< MachineBasicBlock * >::const_iterator const_pred_iterator
void setIsEHScopeEntry(bool V=true)
Indicates if this is the entry block of an EH scope, i.e., the block that that used to have a catchpa...
LLVM_ABI void moveAfter(MachineBasicBlock *NewBefore)
succ_reverse_iterator succ_rend()
void setMachineBlockAddressTaken()
Set this block to indicate that its address is used as something other than the target of a terminato...
std::optional< uint64_t > getIrrLoopHeaderWeight() const
LLVM_ABI const uint32_t * getEndClobberMask(const TargetRegisterInfo *TRI) const
Get the clobber mask for the end of the basic block.
void setIsBeginSection(bool V=true)
LLVM_ABI bool sizeWithoutDebugLargerThan(unsigned Limit) const
iterator_range< instr_iterator > instr_range
LLVM_ABI bool isLiveIn(MCRegister Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const
Return true if the specified register is in the live in set.
LLVM_ABI MachineBasicBlock * removeFromParent()
This method unlinks 'this' from the containing function, and returns it, but does not delete it.
void insert(iterator I, IT S, IT E)
Insert a range of instructions into the instruction list before I.
void setIsEHPad(bool V=true)
Indicates the block is a landing pad.
Instructions::reverse_iterator reverse_instr_iterator
bool isCleanupFuncletEntry() const
Returns true if this is the entry block of a cleanup funclet.
MachineBasicBlock iterator that automatically skips over MIs that are inside bundles (i....
instr_iterator getInstrIterator() const
static MachineInstrBundleIterator getAtBundleBegin(instr_iterator MI)
MachineBasicBlock::iterator getInitial()
MachineInstrSpan(MachineBasicBlock::iterator I, MachineBasicBlock *BB)
MachineBasicBlock::iterator begin()
MachineBasicBlock::iterator end()
Representation of each machine instruction.
bool isReturn(QueryType Type=AnyInBundle) const
bool isEHScopeReturn(QueryType Type=AnyInBundle) const
Return true if this is an instruction that marks the end of an EH scope, i.e., a catchpad or a cleanu...
bool isIndirectBranch(QueryType Type=AnyInBundle) const
Return true if this is an indirect branch, such as a branch through a register.
Manage lifetime of a slot tracker for printing IR.
Pass interface - Implemented by all 'passes'.
Simple wrapper around std::function<void(raw_ostream&)>.
Wrapper class representing virtual and physical registers.
typename SuperClass::const_iterator const_iterator
typename SuperClass::iterator iterator
std::reverse_iterator< const_iterator > const_reverse_iterator
std::reverse_iterator< iterator > reverse_iterator
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
The instances of the Type class are immutable: once they are created, they are never changed.
ilist_node_with_parent()=default
typename base_list_type::const_reverse_iterator const_reverse_iterator
typename base_list_type::reverse_iterator reverse_iterator
typename base_list_type::iterator iterator
typename base_list_type::const_iterator const_iterator
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
A simple intrusive list implementation.
This file defines classes to implement an intrusive doubly linked list class (i.e.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
unsigned combineHashValue(unsigned a, unsigned b)
Simplistic combination of 32-bit hash values into 32-bit hash values.
This is an optimization pass for GlobalISel generic memory operations.
IterT next_nodbg(IterT It, IterT End, bool SkipPseudoOp=true)
Increment It, then continue incrementing it while it points to a debug instruction.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
auto pred_end(const MachineBasicBlock *BB)
auto successors(const MachineBasicBlock *BB)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
constexpr bool GraphHasNodeNumbers
Indicate whether a GraphTraits<NodeT>::getNumber() is supported.
auto pred_size(const MachineBasicBlock *BB)
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
IterT skipDebugInstructionsForward(IterT It, IterT End, bool SkipPseudoOp=true)
Increment It until it points to a non-debug instruction or to End and return the resulting iterator.
iplist< T, Options... > ilist
auto succ_size(const MachineBasicBlock *BB)
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
auto instructionsWithoutDebug(IterT It, IterT End, bool SkipPseudoOp=true)
Construct a range iterator which begins at It and moves forwards until End is reached,...
IterT skipDebugInstructionsBackward(IterT It, IterT Begin, bool SkipPseudoOp=true)
Decrement It until it points to a non-debug instruction or to Begin and return the resulting iterator...
RNSuccIterator< NodeRef, BlockT, RegionT > succ_begin(NodeRef Node)
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
RNSuccIterator< NodeRef, BlockT, RegionT > succ_end(NodeRef Node)
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
auto pred_begin(const MachineBasicBlock *BB)
auto predecessors(const MachineBasicBlock *BB)
SuccIterator< Instruction, BasicBlock > succ_iterator
SuccIterator< const Instruction, const BasicBlock > const_succ_iterator
IterT prev_nodbg(IterT It, IterT Begin, bool SkipPseudoOp=true)
Decrement It, then continue decrementing it while it points to a debug instruction.
LLVM_ABI Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
Implement std::hash so that hash_code can be used in STL containers.
This struct is a compact representation of a valid (non-zero power of two) alignment.
DenseMapInfo< unsigned > NumberInfo
static MBBSectionID getEmptyKey()
static unsigned getHashValue(const MBBSectionID &SecID)
DenseMapInfo< MBBSectionID::SectionType > TypeInfo
static bool isEqual(const MBBSectionID &LHS, const MBBSectionID &RHS)
static MBBSectionID getTombstoneKey()
An information struct used to provide DenseMap with the various necessary components for a given valu...
static ChildIteratorType child_end(NodeRef N)
static NodeRef getEntryNode(Inverse< MachineBasicBlock * > G)
MachineBasicBlock * NodeRef
MachineBasicBlock::pred_iterator ChildIteratorType
static unsigned getNumber(MachineBasicBlock *BB)
static ChildIteratorType child_begin(NodeRef N)
static ChildIteratorType child_end(NodeRef N)
static unsigned getNumber(const MachineBasicBlock *BB)
const MachineBasicBlock * NodeRef
static NodeRef getEntryNode(Inverse< const MachineBasicBlock * > G)
static ChildIteratorType child_begin(NodeRef N)
MachineBasicBlock::const_pred_iterator ChildIteratorType
static unsigned getNumber(MachineBasicBlock *BB)
MachineBasicBlock * NodeRef
MachineBasicBlock::succ_iterator ChildIteratorType
static NodeRef getEntryNode(MachineBasicBlock *BB)
static ChildIteratorType child_end(NodeRef N)
static ChildIteratorType child_begin(NodeRef N)
MachineBasicBlock::const_succ_iterator ChildIteratorType
static ChildIteratorType child_begin(NodeRef N)
static unsigned getNumber(const MachineBasicBlock *BB)
static NodeRef getEntryNode(const MachineBasicBlock *BB)
static ChildIteratorType child_end(NodeRef N)
const MachineBasicBlock * NodeRef
static constexpr LaneBitmask getAll()
unsigned operator()(const MachineBasicBlock *MBB) const
const MachineBasicBlock * argument_type
bool operator!=(const MBBSectionID &Other) const
LLVM_ABI static const MBBSectionID ExceptionSectionID
LLVM_ABI static const MBBSectionID ColdSectionID
enum llvm::MBBSectionID::SectionType Type
bool operator==(const MBBSectionID &Other) const
Pair of physical register and lane mask.
RegisterMaskPair(MCPhysReg PhysReg, LaneBitmask LaneMask)
bool operator==(const RegisterMaskPair &other) const
Split the critical edge from this block to the given successor block, and return the newly created bl...
Callbacks do nothing by default in iplist and ilist.
friend class MachineBasicBlock
LLVM_ABI void addNodeToList(MachineInstr *N)
LLVM_ABI void transferNodesFromList(ilist_traits &FromList, instr_iterator First, instr_iterator Last)
LLVM_ABI void removeNodeFromList(MachineInstr *N)
LLVM_ABI void deleteNode(MachineInstr *MI)
Template traits for intrusive list.