LLVM 23.0.0git
MachineBasicBlock.h
Go to the documentation of this file.
1//===- llvm/CodeGen/MachineBasicBlock.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 the sequence of machine instructions for a basic block.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CODEGEN_MACHINEBASICBLOCK_H
14#define LLVM_CODEGEN_MACHINEBASICBLOCK_H
15
19#include "llvm/ADT/ilist.h"
24#include "llvm/IR/DebugLoc.h"
25#include "llvm/MC/LaneBitmask.h"
29#include <cassert>
30#include <cstdint>
31#include <iterator>
32#include <string>
33#include <vector>
34
35namespace llvm {
36
37class BasicBlock;
39class MachineFunction;
40class MachineLoopInfo;
41class MCSymbol;
43class Pass;
44class Printable;
45class SlotIndexes;
46class StringRef;
47class raw_ostream;
48class LiveIntervals;
49class LiveVariables;
52
53// This structure uniquely identifies a basic block section.
54// Possible values are
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
61 // Number field).
62 Exception, // Special section type for exception handling blocks
63 Cold, // Special section type for cold blocks
65 unsigned Number;
66
67 MBBSectionID(unsigned N) : Type(Default), Number(N) {}
68
69 // Special unique sections for cold and exception blocks.
72
73 bool operator==(const MBBSectionID &Other) const {
74 return Type == Other.Type && Number == Other.Number;
75 }
76
77 bool operator!=(const MBBSectionID &Other) const { return !(*this == Other); }
78
79private:
80 // This is only used to construct the special cold and exception sections.
81 MBBSectionID(SectionType T) : Type(T), Number(0) {}
82};
83
84template <> struct DenseMapInfo<MBBSectionID> {
87
88 static inline MBBSectionID getEmptyKey() {
89 return MBBSectionID(NumberInfo::getEmptyKey());
90 }
91 static inline MBBSectionID getTombstoneKey() {
92 return MBBSectionID(NumberInfo::getTombstoneKey());
93 }
94 static unsigned getHashValue(const MBBSectionID &SecID) {
95 return detail::combineHashValue(TypeInfo::getHashValue(SecID.Type),
96 NumberInfo::getHashValue(SecID.Number));
97 }
98 static bool isEqual(const MBBSectionID &LHS, const MBBSectionID &RHS) {
99 return LHS == RHS;
100 }
101};
102
103template <> struct ilist_traits<MachineInstr> {
104private:
105 friend class MachineBasicBlock; // Set by the owning MachineBasicBlock.
106
107 MachineBasicBlock *Parent;
108
109 using instr_iterator =
111
112public:
116 instr_iterator First,
117 instr_iterator Last);
119};
120
121class MachineBasicBlock
122 : public ilist_node_with_parent<MachineBasicBlock, MachineFunction> {
123public:
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.
128 public:
131
136
137 bool operator==(const RegisterMaskPair &other) const {
138 return PhysReg == other.PhysReg && LaneMask == other.LaneMask;
139 }
140 };
141
142private:
144
145 const BasicBlock *BB;
146 int Number;
147
148 /// The call frame size on entry to this basic block due to call frame setup
149 /// instructions in a predecessor. This is usually zero, unless basic blocks
150 /// are split in the middle of a call sequence.
151 ///
152 /// This information is only maintained until PrologEpilogInserter eliminates
153 /// call frame pseudos.
154 unsigned CallFrameSize = 0;
155
156 MachineFunction *xParent;
157 Instructions Insts;
158
159 /// Keep track of the predecessor / successor basic blocks.
162
163 /// Keep track of the probabilities to the successors. This vector has the
164 /// same order as Successors, or it is empty if we don't use it (disable
165 /// optimization).
166 std::vector<BranchProbability> Probs;
167 using probability_iterator = std::vector<BranchProbability>::iterator;
168 using const_probability_iterator =
169 std::vector<BranchProbability>::const_iterator;
170
171 std::optional<uint64_t> IrrLoopHeaderWeight;
172
173 /// Keep track of the physical registers that are livein of the basicblock.
174 using LiveInVector = std::vector<RegisterMaskPair>;
175 LiveInVector LiveIns;
176
177 /// Alignment of the basic block. One if the basic block does not need to be
178 /// aligned.
179 Align Alignment;
180 /// Maximum amount of bytes that can be added to align the basic block. If the
181 /// alignment cannot be reached in this many bytes, no bytes are emitted.
182 /// Zero to represent no maximum.
183 unsigned MaxBytesForAlignment = 0;
184
185 /// Indicate that this basic block is entered via an exception handler.
186 bool IsEHPad = false;
187
188 /// Indicate that this MachineBasicBlock is referenced somewhere other than
189 /// as predecessor/successor, a terminator MachineInstr, or a jump table.
190 bool MachineBlockAddressTaken = false;
191
192 /// Relatively stable number used for analyses.
193 unsigned AnalysisNumber = 0;
194
195 /// If this MachineBasicBlock corresponds to an IR-level "blockaddress"
196 /// constant, this contains a pointer to that block.
197 BasicBlock *AddressTakenIRBlock = nullptr;
198
199 /// Indicate that this basic block needs its symbol be emitted regardless of
200 /// whether the flow just falls-through to it.
201 bool LabelMustBeEmitted = false;
202
203 /// Indicate that this basic block is the entry block of an EH scope, i.e.,
204 /// the block that used to have a catchpad or cleanuppad instruction in the
205 /// LLVM IR.
206 bool IsEHScopeEntry = false;
207
208 /// Indicates if this is a target of Windows EH Continuation Guard.
209 bool IsEHContTarget = false;
210
211 /// Indicate that this basic block is the entry block of an EH funclet.
212 bool IsEHFuncletEntry = false;
213
214 /// Indicate that this basic block is the entry block of a cleanup funclet.
215 bool IsCleanupFuncletEntry = false;
216
217 /// Fixed unique ID assigned to this basic block upon creation. Used with
218 /// basic block sections and basic block labels.
219 std::optional<UniqueBBID> BBID;
220
221 SmallVector<unsigned> PrefetchTargets;
222
223 /// With basic block sections, this stores the Section ID of the basic block.
224 MBBSectionID SectionID{0};
225
226 // Indicate that this basic block begins a section.
227 bool IsBeginSection = false;
228
229 // Indicate that this basic block ends a section.
230 bool IsEndSection = false;
231
232 /// Indicate that this basic block is the indirect dest of an INLINEASM_BR.
233 bool IsInlineAsmBrIndirectTarget = false;
234
235 /// since getSymbol is a relatively heavy-weight operation, the symbol
236 /// is only computed once and is cached.
237 mutable MCSymbol *CachedMCSymbol = nullptr;
238
239 /// Cached MCSymbol for this block (used if IsEHContTarget).
240 mutable MCSymbol *CachedEHContMCSymbol = nullptr;
241
242 /// Marks the end of the basic block. Used during basic block sections to
243 /// calculate the size of the basic block, or the BB section ending with it.
244 mutable MCSymbol *CachedEndMCSymbol = nullptr;
245
246 // Intrusive list support
247 MachineBasicBlock() = default;
248
249 explicit MachineBasicBlock(MachineFunction &MF, const BasicBlock *BB);
250
251 ~MachineBasicBlock();
252
253 // MachineBasicBlocks are allocated and owned by MachineFunction.
254 friend class MachineFunction;
255
256public:
257 /// Return the LLVM basic block that this instance corresponded to originally.
258 /// Note that this may be NULL if this instance does not correspond directly
259 /// to an LLVM basic block.
260 const BasicBlock *getBasicBlock() const { return BB; }
261
262 /// Remove the reference to the underlying IR BasicBlock. This is for
263 /// reduction tools and should generally not be used.
265 BB = nullptr;
266 }
267
268 /// Check if there is a name of corresponding LLVM basic block.
269 LLVM_ABI bool hasName() const;
270
271 /// Return the name of the corresponding LLVM basic block, or an empty string.
272 LLVM_ABI StringRef getName() const;
273
274 /// Return a formatted string to identify this block and its parent function.
275 LLVM_ABI std::string getFullName() const;
276
277 /// Test whether this block is used as something other than the target
278 /// of a terminator, exception-handling target, or jump table. This is
279 /// either the result of an IR-level "blockaddress", or some form
280 /// of target-specific branch lowering.
281 ///
282 /// The name of this function `hasAddressTaken` implies that the address of
283 /// the block is known and used in a general sense, but not necessarily that
284 /// the address is used by an indirect branch instruction. So branch target
285 /// enforcement need not put a BTI instruction (or equivalent) at the start
286 /// of a block just because this function returns true. The decision about
287 /// whether to add a BTI can be more subtle than that, and depends on the
288 /// more detailed checks that this function aggregates together.
289 bool hasAddressTaken() const {
290 return MachineBlockAddressTaken || AddressTakenIRBlock ||
291 IsInlineAsmBrIndirectTarget;
292 }
293
294 /// Test whether this block is used as something other than the target of a
295 /// terminator, exception-handling target, jump table, or IR blockaddress.
296 /// For example, its address might be loaded into a register, or
297 /// stored in some branch table that isn't part of MachineJumpTableInfo.
298 ///
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.
301 bool isMachineBlockAddressTaken() const { return MachineBlockAddressTaken; }
302
303 /// Test whether this block is the target of an IR BlockAddress. (There can
304 /// more than one MBB associated with an IR BB where the address is taken.)
305 ///
306 /// If this function returns true, it _does_ mean that branch target
307 /// enforcement needs to put a BTI or equivalent at the start of the block.
308 bool isIRBlockAddressTaken() const { return AddressTakenIRBlock; }
309
310 /// Retrieves the BasicBlock which corresponds to this MachineBasicBlock.
311 BasicBlock *getAddressTakenIRBlock() const { return AddressTakenIRBlock; }
312
313 /// Set this block to indicate that its address is used as something other
314 /// than the target of a terminator, exception-handling target, jump table,
315 /// or IR-level "blockaddress".
316 void setMachineBlockAddressTaken() { MachineBlockAddressTaken = true; }
317
318 /// Set this block to reflect that it corresponds to an IR-level basic block
319 /// with a BlockAddress.
320 void setAddressTakenIRBlock(BasicBlock *BB) { AddressTakenIRBlock = BB; }
321
322 /// Test whether this block must have its label emitted.
323 bool hasLabelMustBeEmitted() const { return LabelMustBeEmitted; }
324
325 /// Set this block to reflect that, regardless how we flow to it, we need
326 /// its label be emitted.
327 void setLabelMustBeEmitted() { LabelMustBeEmitted = true; }
328
329 /// Return the MachineFunction containing this basic block.
330 const MachineFunction *getParent() const { return xParent; }
331 MachineFunction *getParent() { return xParent; }
332
333 /// Returns true if the original IR terminator is an `indirectbr` with
334 /// successor blocks. This typically corresponds to a `goto` in C, rather than
335 /// jump tables.
337 return back().isIndirectBranch() && !succ_empty() &&
338 llvm::all_of(successors(), [](const MachineBasicBlock *Succ) {
339 return Succ->isIRBlockAddressTaken();
340 });
341 }
342
347
353
354 unsigned size() const { return (unsigned)Insts.size(); }
355 LLVM_ABI bool sizeWithoutDebugLargerThan(unsigned Limit) const;
356 bool empty() const { return Insts.empty(); }
357
358 MachineInstr &instr_front() { return Insts.front(); }
359 MachineInstr &instr_back() { return Insts.back(); }
360 const MachineInstr &instr_front() const { return Insts.front(); }
361 const MachineInstr &instr_back() const { return Insts.back(); }
362
363 MachineInstr &front() { return Insts.front(); }
364 MachineInstr &back() { return *--end(); }
365 const MachineInstr &front() const { return Insts.front(); }
366 const MachineInstr &back() const { return *--end(); }
367
368 instr_iterator instr_begin() { return Insts.begin(); }
369 const_instr_iterator instr_begin() const { return Insts.begin(); }
370 instr_iterator instr_end() { return Insts.end(); }
371 const_instr_iterator instr_end() const { return Insts.end(); }
372 reverse_instr_iterator instr_rbegin() { return Insts.rbegin(); }
373 const_reverse_instr_iterator instr_rbegin() const { return Insts.rbegin(); }
374 reverse_instr_iterator instr_rend () { return Insts.rend(); }
375 const_reverse_instr_iterator instr_rend () const { return Insts.rend(); }
376
383
384 iterator begin() { return instr_begin(); }
385 const_iterator begin() const { return instr_begin(); }
386 iterator end () { return instr_end(); }
387 const_iterator end () const { return instr_end(); }
398
399 /// Support for MachineInstr::getNextNode().
400 static Instructions MachineBasicBlock::*getSublistAccess(MachineInstr *) {
401 return &MachineBasicBlock::Insts;
402 }
403
410
411 /// Returns a range that iterates over the phis in the basic block.
413 return make_range(begin(), getFirstNonPHI());
414 }
416 return const_cast<MachineBasicBlock *>(this)->phis();
417 }
418
419 // Machine-CFG iterators
434 pred_iterator pred_begin() { return Predecessors.begin(); }
435 const_pred_iterator pred_begin() const { return Predecessors.begin(); }
436 pred_iterator pred_end() { return Predecessors.end(); }
437 const_pred_iterator pred_end() const { return Predecessors.end(); }
439 { return Predecessors.rbegin();}
441 { return Predecessors.rbegin();}
443 { return Predecessors.rend(); }
445 { return Predecessors.rend(); }
446 unsigned pred_size() const {
447 return (unsigned)Predecessors.size();
448 }
449 bool pred_empty() const { return Predecessors.empty(); }
450 succ_iterator succ_begin() { return Successors.begin(); }
451 const_succ_iterator succ_begin() const { return Successors.begin(); }
452 succ_iterator succ_end() { return Successors.end(); }
453 const_succ_iterator succ_end() const { return Successors.end(); }
455 { return Successors.rbegin(); }
457 { return Successors.rbegin(); }
459 { return Successors.rend(); }
461 { return Successors.rend(); }
462 unsigned succ_size() const {
463 return (unsigned)Successors.size();
464 }
465 bool succ_empty() const { return Successors.empty(); }
466
479
480 // LiveIn management methods.
481
482 /// Adds the specified register as a live in. Note that it is an error to add
483 /// the same register to the same set more than once unless the intention is
484 /// to call sortUniqueLiveIns after all registers are added.
485 void addLiveIn(MCRegister PhysReg,
486 LaneBitmask LaneMask = LaneBitmask::getAll()) {
487 LiveIns.push_back(RegisterMaskPair(PhysReg, LaneMask));
488 }
489 void addLiveIn(const RegisterMaskPair &RegMaskPair) {
490 LiveIns.push_back(RegMaskPair);
491 }
492
493 /// Sorts and uniques the LiveIns vector. It can be significantly faster to do
494 /// this than repeatedly calling isLiveIn before calling addLiveIn for every
495 /// LiveIn insertion.
497
498 /// Clear live in list.
499 LLVM_ABI void clearLiveIns();
500
501 /// Clear the live in list, and return the removed live in's in \p OldLiveIns.
502 /// Requires that the vector \p OldLiveIns is empty.
503 LLVM_ABI void clearLiveIns(std::vector<RegisterMaskPair> &OldLiveIns);
504
505 /// Add PhysReg as live in to this block, and ensure that there is a copy of
506 /// PhysReg to a virtual register of class RC. Return the virtual register
507 /// that is a copy of the live in PhysReg.
509 const TargetRegisterClass *RC);
510
511 /// Remove the specified register from the live in set.
513 LaneBitmask LaneMask = LaneBitmask::getAll());
514
515 /// Remove the specified register from any overlapped live in. The method is
516 /// subreg-aware and removes Reg and its subregs from the live in set. It also
517 /// clears the corresponding bitmask from its live-in super registers.
519
520 /// Return true if the specified register is in the live in set.
522 LaneBitmask LaneMask = LaneBitmask::getAll()) const;
523
524 // Iteration support for live in sets. These sets are kept in sorted
525 // order by their register number.
526 using livein_iterator = LiveInVector::const_iterator;
527
528 /// Unlike livein_begin, this method does not check that the liveness
529 /// information is accurate. Still for debug purposes it may be useful
530 /// to have iterators that won't assert if the liveness information
531 /// is not current.
532 livein_iterator livein_begin_dbg() const { return LiveIns.begin(); }
536
538 livein_iterator livein_end() const { return LiveIns.end(); }
539 bool livein_empty() const { return LiveIns.empty(); }
543
544 /// Remove entry from the livein set and return iterator to the next.
546
547 const std::vector<RegisterMaskPair> &getLiveIns() const { return LiveIns; }
548
550 public:
551 using iterator_category = std::input_iterator_tag;
552 using difference_type = std::ptrdiff_t;
554 using pointer = const RegisterMaskPair *;
556
557 liveout_iterator(const MachineBasicBlock &MBB, MCRegister ExceptionPointer,
558 MCRegister ExceptionSelector, bool End)
559 : ExceptionPointer(ExceptionPointer),
560 ExceptionSelector(ExceptionSelector), BlockI(MBB.succ_begin()),
561 BlockEnd(MBB.succ_end()) {
562 if (End)
563 BlockI = BlockEnd;
564 else if (BlockI != BlockEnd) {
565 LiveRegI = (*BlockI)->livein_begin();
566 if (!advanceToValidPosition())
567 return;
568 if ((*BlockI)->isEHPad() && (LiveRegI->PhysReg == ExceptionPointer ||
569 LiveRegI->PhysReg == ExceptionSelector))
570 ++(*this);
571 }
572 }
573
575 do {
576 ++LiveRegI;
577 if (!advanceToValidPosition())
578 return *this;
579 } while ((*BlockI)->isEHPad() &&
580 (LiveRegI->PhysReg == ExceptionPointer ||
581 LiveRegI->PhysReg == ExceptionSelector));
582 return *this;
583 }
584
586 liveout_iterator Tmp = *this;
587 ++(*this);
588 return Tmp;
589 }
590
592 return *LiveRegI;
593 }
594
596 return &*LiveRegI;
597 }
598
599 bool operator==(const liveout_iterator &RHS) const {
600 if (BlockI != BlockEnd)
601 return BlockI == RHS.BlockI && LiveRegI == RHS.LiveRegI;
602 return RHS.BlockI == BlockEnd;
603 }
604
605 bool operator!=(const liveout_iterator &RHS) const {
606 return !(*this == RHS);
607 }
608 private:
609 bool advanceToValidPosition() {
610 if (LiveRegI != (*BlockI)->livein_end())
611 return true;
612
613 do {
614 ++BlockI;
615 } while (BlockI != BlockEnd && (*BlockI)->livein_empty());
616 if (BlockI == BlockEnd)
617 return false;
618
619 LiveRegI = (*BlockI)->livein_begin();
620 return true;
621 }
622
623 MCRegister ExceptionPointer, ExceptionSelector;
624 const_succ_iterator BlockI;
625 const_succ_iterator BlockEnd;
626 livein_iterator LiveRegI;
627 };
628
629 /// Iterator scanning successor basic blocks' liveins to determine the
630 /// registers potentially live at the end of this block. There may be
631 /// duplicates or overlapping registers in the list returned.
634 return liveout_iterator(*this, 0, 0, true);
635 }
639
640 /// Get the clobber mask for the start of this basic block. Funclets use this
641 /// to prevent register allocation across funclet transitions.
642 LLVM_ABI const uint32_t *
644
645 /// Get the clobber mask for the end of the basic block.
646 /// \see getBeginClobberMask()
647 LLVM_ABI const uint32_t *
649
650 /// Return alignment of the basic block.
651 Align getAlignment() const { return Alignment; }
652
653 /// Set alignment of the basic block.
654 void setAlignment(Align A) { Alignment = A; }
655
656 void setAlignment(Align A, unsigned MaxBytes) {
658 setMaxBytesForAlignment(MaxBytes);
659 }
660
661 /// Return the maximum amount of padding allowed for aligning the basic block.
662 unsigned getMaxBytesForAlignment() const { return MaxBytesForAlignment; }
663
664 /// Set the maximum amount of padding allowed for aligning the basic block
665 void setMaxBytesForAlignment(unsigned MaxBytes) {
666 MaxBytesForAlignment = MaxBytes;
667 }
668
669 /// Returns true if the block is a landing pad. That is this basic block is
670 /// entered via an exception handler.
671 bool isEHPad() const { return IsEHPad; }
672
673 /// Indicates the block is a landing pad. That is this basic block is entered
674 /// via an exception handler.
675 void setIsEHPad(bool V = true) { IsEHPad = V; }
676
677 LLVM_ABI bool hasEHPadSuccessor() const;
678
679 /// Returns true if this is the entry block of the function.
680 LLVM_ABI bool isEntryBlock() const;
681
682 /// Returns true if this is the entry block of an EH scope, i.e., the block
683 /// that used to have a catchpad or cleanuppad instruction in the LLVM IR.
684 bool isEHScopeEntry() const { return IsEHScopeEntry; }
685
686 /// Indicates if this is the entry block of an EH scope, i.e., the block that
687 /// that used to have a catchpad or cleanuppad instruction in the LLVM IR.
688 void setIsEHScopeEntry(bool V = true) { IsEHScopeEntry = V; }
689
690 /// Returns true if this is a target of Windows EH Continuation Guard.
691 bool isEHContTarget() const { return IsEHContTarget; }
692
693 /// Indicates if this is a target of Windows EH Continuation Guard.
694 void setIsEHContTarget(bool V = true) { IsEHContTarget = V; }
695
696 /// Returns true if this is the entry block of an EH funclet.
697 bool isEHFuncletEntry() const { return IsEHFuncletEntry; }
698
699 /// Indicates if this is the entry block of an EH funclet.
700 void setIsEHFuncletEntry(bool V = true) { IsEHFuncletEntry = V; }
701
702 /// Returns true if this is the entry block of a cleanup funclet.
703 bool isCleanupFuncletEntry() const { return IsCleanupFuncletEntry; }
704
705 /// Indicates if this is the entry block of a cleanup funclet.
706 void setIsCleanupFuncletEntry(bool V = true) { IsCleanupFuncletEntry = V; }
707
708 /// Returns true if this block begins any section.
709 bool isBeginSection() const { return IsBeginSection; }
710
711 /// Returns true if this block ends any section.
712 bool isEndSection() const { return IsEndSection; }
713
714 void setIsBeginSection(bool V = true) { IsBeginSection = V; }
715
716 void setIsEndSection(bool V = true) { IsEndSection = V; }
717
718 std::optional<UniqueBBID> getBBID() const { return BBID; }
719
720 /// Returns the section ID of this basic block.
721 MBBSectionID getSectionID() const { return SectionID; }
722
723 /// Sets the fixed BBID of this basic block.
724 void setBBID(const UniqueBBID &V) {
725 assert(!BBID.has_value() && "Cannot change BBID.");
726 BBID = V;
727 }
728
729 /// Sets the section ID for this basic block.
730 void setSectionID(MBBSectionID V) { SectionID = V; }
731
732 /// Returns the MCSymbol marking the end of this basic block.
734
735 /// Returns true if this block may have an INLINEASM_BR (overestimate, by
736 /// checking if any of the successors are indirect targets of any inlineasm_br
737 /// in the function).
738 LLVM_ABI bool mayHaveInlineAsmBr() const;
739
740 /// Returns true if this is the indirect dest of an INLINEASM_BR.
742 return IsInlineAsmBrIndirectTarget;
743 }
744
745 /// Indicates if this is the indirect dest of an INLINEASM_BR.
746 void setIsInlineAsmBrIndirectTarget(bool V = true) {
747 IsInlineAsmBrIndirectTarget = V;
748 }
749
750 /// Returns true if it is legal to hoist instructions into this block.
751 LLVM_ABI bool isLegalToHoistInto() const;
752
753 // Code Layout methods.
754
755 /// Move 'this' block before or after the specified block. This only moves
756 /// the block, it does not modify the CFG or adjust potential fall-throughs at
757 /// the end of the block.
758 LLVM_ABI void moveBefore(MachineBasicBlock *NewAfter);
759 LLVM_ABI void moveAfter(MachineBasicBlock *NewBefore);
760
761 /// Returns true if this and MBB belong to the same section.
762 bool sameSection(const MachineBasicBlock *MBB) const {
763 return getSectionID() == MBB->getSectionID();
764 }
765
766 /// Update the terminator instructions in block to account for changes to
767 /// block layout which may have been made. PreviousLayoutSuccessor should be
768 /// set to the block which may have been used as fallthrough before the block
769 /// layout was modified. If the block previously fell through to that block,
770 /// it may now need a branch. If it previously branched to another block, it
771 /// may now be able to fallthrough to the current layout successor.
772 LLVM_ABI void updateTerminator(MachineBasicBlock *PreviousLayoutSuccessor);
773
774 // Machine-CFG mutators
775
776 /// Add Succ as a successor of this MachineBasicBlock. The Predecessors list
777 /// of Succ is automatically updated. PROB parameter is stored in
778 /// Probabilities list. The default probability is set as unknown. Mixing
779 /// known and unknown probabilities in successor list is not allowed. When all
780 /// successors have unknown probabilities, 1 / N is returned as the
781 /// probability for each successor, where N is the number of successors.
782 ///
783 /// Note that duplicate Machine CFG edges are not allowed.
784 LLVM_ABI void
787
788 /// Add Succ as a successor of this MachineBasicBlock. The Predecessors list
789 /// of Succ is automatically updated. The probability is not provided because
790 /// BPI is not available (e.g. -O0 is used), in which case edge probabilities
791 /// won't be used. Using this interface can save some space.
793
794 /// Set successor probability of a given iterator.
796
797 /// Normalize probabilities of all successors so that the sum of them becomes
798 /// one. This is usually done when the current update on this MBB is done, and
799 /// the sum of its successors' probabilities is not guaranteed to be one. The
800 /// user is responsible for the correct use of this function.
801 /// MBB::removeSuccessor() has an option to do this automatically.
803 BranchProbability::normalizeProbabilities(Probs.begin(), Probs.end());
804 }
805
806 /// Validate successors' probabilities and check if the sum of them is
807 /// approximate one. This only works in DEBUG mode.
808 LLVM_ABI void validateSuccProbs() const;
809
810 /// Remove successor from the successors list of this MachineBasicBlock. The
811 /// Predecessors list of Succ is automatically updated.
812 /// If NormalizeSuccProbs is true, then normalize successors' probabilities
813 /// after the successor is removed.
815 bool NormalizeSuccProbs = false);
816
817 /// Remove specified successor from the successors list of this
818 /// MachineBasicBlock. The Predecessors list of Succ is automatically updated.
819 /// If NormalizeSuccProbs is true, then normalize successors' probabilities
820 /// after the successor is removed.
821 /// Return the iterator to the element after the one removed.
823 bool NormalizeSuccProbs = false);
824
825 /// Replace successor OLD with NEW and update probability info.
827 MachineBasicBlock *New);
828
829 /// Copy a successor (and any probability info) from original block to this
830 /// block's. Uses an iterator into the original blocks successors.
831 ///
832 /// This is useful when doing a partial clone of successors. Afterward, the
833 /// probabilities may need to be normalized.
835
836 /// Split the old successor into old plus new and updates the probability
837 /// info.
839 bool NormalizeSuccProbs = false);
840
841 /// Transfers all the successors from MBB to this machine basic block (i.e.,
842 /// copies all the successors FromMBB and remove all the successors from
843 /// FromMBB).
845
846 /// Transfers all the successors, as in transferSuccessors, and update PHI
847 /// operands in the successor blocks which refer to FromMBB to refer to this.
849
850 /// Return true if any of the successors have probabilities attached to them.
851 bool hasSuccessorProbabilities() const { return !Probs.empty(); }
852
853 /// Return true if the specified MBB is a predecessor of this block.
854 LLVM_ABI bool isPredecessor(const MachineBasicBlock *MBB) const;
855
856 /// Return true if the specified MBB is a successor of this block.
857 LLVM_ABI bool isSuccessor(const MachineBasicBlock *MBB) const;
858
859 /// Return true if the specified MBB will be emitted immediately after this
860 /// block, such that if this block exits by falling through, control will
861 /// transfer to the specified MBB. Note that MBB need not be a successor at
862 /// all, for example if this block ends with an unconditional branch to some
863 /// other block.
865
866 /// Return the successor of this block if it has a single successor.
867 /// Otherwise return a null pointer.
868 ///
870 MachineBasicBlock *getSingleSuccessor() {
871 return const_cast<MachineBasicBlock *>(
872 static_cast<const MachineBasicBlock *>(this)->getSingleSuccessor());
873 }
874
875 /// Return the predecessor of this block if it has a single predecessor.
876 /// Otherwise return a null pointer.
877 ///
879 MachineBasicBlock *getSinglePredecessor() {
880 return const_cast<MachineBasicBlock *>(
881 static_cast<const MachineBasicBlock *>(this)->getSinglePredecessor());
882 }
883
884 /// Return the fallthrough block if the block can implicitly
885 /// transfer control to the block after it by falling off the end of
886 /// it. If an explicit branch to the fallthrough block is not allowed,
887 /// set JumpToFallThrough to be false. Non-null return is a conservative
888 /// answer.
889 LLVM_ABI MachineBasicBlock *getFallThrough(bool JumpToFallThrough = true);
890
891 /// Return the fallthrough block if the block can implicitly
892 /// transfer control to it's successor, whether by a branch or
893 /// a fallthrough. Non-null return is a conservative answer.
894 MachineBasicBlock *getLogicalFallThrough() { return getFallThrough(false); }
895
896 /// Return true if the block can implicitly transfer control to the
897 /// block after it by falling off the end of it. This should return
898 /// false if it can reach the block after it, but it uses an
899 /// explicit branch to do so (e.g., a table jump). True is a
900 /// conservative answer.
902
903 /// Returns a pointer to the first instruction in this block that is not a
904 /// PHINode instruction. When adding instructions to the beginning of the
905 /// basic block, they should be added before the returned value, not before
906 /// the first instruction, which might be PHI.
907 /// Returns end() is there's no non-PHI instruction.
910 return const_cast<MachineBasicBlock *>(this)->getFirstNonPHI();
911 }
912
913 /// Return the first instruction in MBB after I that is not a PHI or a label.
914 /// This is the correct point to insert lowered copies at the beginning of a
915 /// basic block that must be before any debugging information.
917
918 /// Return the first instruction in MBB after I that is not a PHI, label or
919 /// debug. This is the correct point to insert copies at the beginning of a
920 /// basic block. \p Reg is the register being used by a spill or defined for a
921 /// restore/split during register allocation.
924 bool SkipPseudoOp = true);
925
926 /// Returns an iterator to the first terminator instruction of this basic
927 /// block. If a terminator does not exist, it returns end().
930 return const_cast<MachineBasicBlock *>(this)->getFirstTerminator();
931 }
932
933 /// Same getFirstTerminator but it ignores bundles and return an
934 /// instr_iterator instead.
935 LLVM_ABI instr_iterator getFirstInstrTerminator();
936
937 /// Finds the first terminator in a block by scanning forward. This can handle
938 /// cases in GlobalISel where there may be non-terminator instructions between
939 /// terminators, for which getFirstTerminator() will not work correctly.
941
942 /// Returns an iterator to the first non-debug instruction in the basic block,
943 /// or end(). Skip any pseudo probe operation if \c SkipPseudoOp is true.
944 /// Pseudo probes are like debug instructions which do not turn into real
945 /// machine code. We try to use the function to skip both debug instructions
946 /// and pseudo probe operations to avoid API proliferation. This should work
947 /// most of the time when considering optimizing the rest of code in the
948 /// block, except for certain cases where pseudo probes are designed to block
949 /// the optimizations. For example, code merge like optimizations are supposed
950 /// to be blocked by pseudo probes for better AutoFDO profile quality.
951 /// Therefore, they should be considered as a valid instruction when this
952 /// function is called in a context of such optimizations. On the other hand,
953 /// \c SkipPseudoOp should be true when it's used in optimizations that
954 /// unlikely hurt profile quality, e.g., without block merging. The default
955 /// value of \c SkipPseudoOp is set to true to maximize code quality in
956 /// general, with an explict false value passed in in a few places like branch
957 /// folding and if-conversion to favor profile quality.
958 LLVM_ABI iterator getFirstNonDebugInstr(bool SkipPseudoOp = true);
959 const_iterator getFirstNonDebugInstr(bool SkipPseudoOp = true) const {
960 return const_cast<MachineBasicBlock *>(this)->getFirstNonDebugInstr(
961 SkipPseudoOp);
962 }
963
964 /// Returns an iterator to the last non-debug instruction in the basic block,
965 /// or end(). Skip any pseudo operation if \c SkipPseudoOp is true.
966 /// Pseudo probes are like debug instructions which do not turn into real
967 /// machine code. We try to use the function to skip both debug instructions
968 /// and pseudo probe operations to avoid API proliferation. This should work
969 /// most of the time when considering optimizing the rest of code in the
970 /// block, except for certain cases where pseudo probes are designed to block
971 /// the optimizations. For example, code merge like optimizations are supposed
972 /// to be blocked by pseudo probes for better AutoFDO profile quality.
973 /// Therefore, they should be considered as a valid instruction when this
974 /// function is called in a context of such optimizations. On the other hand,
975 /// \c SkipPseudoOp should be true when it's used in optimizations that
976 /// unlikely hurt profile quality, e.g., without block merging. The default
977 /// value of \c SkipPseudoOp is set to true to maximize code quality in
978 /// general, with an explict false value passed in in a few places like branch
979 /// folding and if-conversion to favor profile quality.
980 LLVM_ABI iterator getLastNonDebugInstr(bool SkipPseudoOp = true);
981 const_iterator getLastNonDebugInstr(bool SkipPseudoOp = true) const {
982 return const_cast<MachineBasicBlock *>(this)->getLastNonDebugInstr(
983 SkipPseudoOp);
984 }
985
986 /// Convenience function that returns true if the block ends in a return
987 /// instruction.
988 bool isReturnBlock() const {
989 return !empty() && back().isReturn();
990 }
991
992 /// Convenience function that returns true if the bock ends in a EH scope
993 /// return instruction.
994 bool isEHScopeReturnBlock() const {
995 return !empty() && back().isEHScopeReturn();
996 }
997
998 /// Split a basic block into 2 pieces at \p SplitPoint. A new block will be
999 /// inserted after this block, and all instructions after \p SplitInst moved
1000 /// to it (\p SplitInst will be in the original block). If \p LIS is provided,
1001 /// LiveIntervals will be appropriately updated. \return the newly inserted
1002 /// block.
1003 ///
1004 /// If \p UpdateLiveIns is true, this will ensure the live ins list is
1005 /// accurate, including for physreg uses/defs in the original block.
1007 bool UpdateLiveIns = true,
1008 LiveIntervals *LIS = nullptr);
1009
1010 /// Split the critical edge from this block to the given successor block, and
1011 /// return the newly created block, or null if splitting is not possible.
1012 ///
1013 /// This function updates LiveVariables, MachineDominatorTree, and
1014 /// MachineLoopInfo, as applicable.
1021
1022 MachineBasicBlock *
1023 SplitCriticalEdge(MachineBasicBlock *Succ, Pass &P,
1024 std::vector<SparseBitVector<>> *LiveInSets = nullptr,
1025 MachineDomTreeUpdater *MDTU = nullptr) {
1026 return SplitCriticalEdge(Succ, &P, nullptr, LiveInSets, MDTU);
1027 }
1028
1030 SplitCriticalEdge(MachineBasicBlock *Succ,
1032 std::vector<SparseBitVector<>> *LiveInSets = nullptr,
1033 MachineDomTreeUpdater *MDTU = nullptr) {
1034 return SplitCriticalEdge(Succ, nullptr, &MFAM, LiveInSets, MDTU);
1035 }
1036
1037 // Helper method for new pass manager migration.
1039 MachineBasicBlock *Succ, const SplitCriticalEdgeAnalyses &Analyses,
1040 std::vector<SparseBitVector<>> *LiveInSets, MachineDomTreeUpdater *MDTU);
1041
1044 std::vector<SparseBitVector<>> *LiveInSets, MachineDomTreeUpdater *MDTU);
1045
1046 /// Check if the edge between this block and the given successor \p
1047 /// Succ, can be split. If this returns true a subsequent call to
1048 /// SplitCriticalEdge is guaranteed to return a valid basic block if
1049 /// no changes occurred in the meantime.
1050 LLVM_ABI bool
1052 const MachineLoopInfo *MLI = nullptr) const;
1053
1054 void pop_front() { Insts.pop_front(); }
1055 void pop_back() { Insts.pop_back(); }
1056 void push_back(MachineInstr *MI) { Insts.push_back(MI); }
1057
1058 /// Insert MI into the instruction list before I, possibly inside a bundle.
1059 ///
1060 /// If the insertion point is inside a bundle, MI will be added to the bundle,
1061 /// otherwise MI will not be added to any bundle. That means this function
1062 /// alone can't be used to prepend or append instructions to bundles. See
1063 /// MIBundleBuilder::insert() for a more reliable way of doing that.
1064 LLVM_ABI instr_iterator insert(instr_iterator I, MachineInstr *M);
1065
1066 /// Insert a range of instructions into the instruction list before I.
1067 template<typename IT>
1068 void insert(iterator I, IT S, IT E) {
1069 assert((I == end() || I->getParent() == this) &&
1070 "iterator points outside of basic block");
1071 Insts.insert(I.getInstrIterator(), S, E);
1072 }
1073
1074 /// Insert MI into the instruction list before I.
1076 assert((I == end() || I->getParent() == this) &&
1077 "iterator points outside of basic block");
1078 assert(!MI->isBundledWithPred() && !MI->isBundledWithSucc() &&
1079 "Cannot insert instruction with bundle flags");
1080 return Insts.insert(I.getInstrIterator(), MI);
1081 }
1082
1083 /// Insert MI into the instruction list after I.
1085 assert((I == end() || I->getParent() == this) &&
1086 "iterator points outside of basic block");
1087 assert(!MI->isBundledWithPred() && !MI->isBundledWithSucc() &&
1088 "Cannot insert instruction with bundle flags");
1089 return Insts.insertAfter(I.getInstrIterator(), MI);
1090 }
1091
1092 /// If I is bundled then insert MI into the instruction list after the end of
1093 /// the bundle, otherwise insert MI immediately after I.
1095 assert((I == instr_end() || I->getParent() == this) &&
1096 "iterator points outside of basic block");
1097 assert(!MI->isBundledWithPred() && !MI->isBundledWithSucc() &&
1098 "Cannot insert instruction with bundle flags");
1099 while (I->isBundledWithSucc())
1100 ++I;
1101 return Insts.insertAfter(I, MI);
1102 }
1103
1104 /// Remove an instruction from the instruction list and delete it.
1105 ///
1106 /// If the instruction is part of a bundle, the other instructions in the
1107 /// bundle will still be bundled after removing the single instruction.
1108 LLVM_ABI instr_iterator erase(instr_iterator I);
1109
1110 /// Remove an instruction from the instruction list and delete it.
1111 ///
1112 /// If the instruction is part of a bundle, the other instructions in the
1113 /// bundle will still be bundled after removing the single instruction.
1117
1118 /// Remove a range of instructions from the instruction list and delete them.
1120 return Insts.erase(I.getInstrIterator(), E.getInstrIterator());
1121 }
1122
1123 /// Remove an instruction or bundle from the instruction list and delete it.
1124 ///
1125 /// If I points to a bundle of instructions, they are all erased.
1127 return erase(I, std::next(I));
1128 }
1129
1130 /// Remove an instruction from the instruction list and delete it.
1131 ///
1132 /// If I is the head of a bundle of instructions, the whole bundle will be
1133 /// erased.
1135 return erase(iterator(I));
1136 }
1137
1138 /// Remove the unbundled instruction from the instruction list without
1139 /// deleting it.
1140 ///
1141 /// This function can not be used to remove bundled instructions, use
1142 /// remove_instr to remove individual instructions from a bundle.
1144 assert(!I->isBundled() && "Cannot remove bundled instructions");
1145 return Insts.remove(instr_iterator(I));
1146 }
1147
1148 /// Remove the possibly bundled instruction from the instruction list
1149 /// without deleting it.
1150 ///
1151 /// If the instruction is part of a bundle, the other instructions in the
1152 /// bundle will still be bundled after removing the single instruction.
1154
1155 void clear() {
1156 Insts.clear();
1157 }
1158
1159 /// Take an instruction from MBB 'Other' at the position From, and insert it
1160 /// into this MBB right before 'Where'.
1161 ///
1162 /// If From points to a bundle of instructions, the whole bundle is moved.
1163 void splice(iterator Where, MachineBasicBlock *Other, iterator From) {
1164 // The range splice() doesn't allow noop moves, but this one does.
1165 if (Where != From)
1166 splice(Where, Other, From, std::next(From));
1167 }
1168
1169 /// Take a block of instructions from MBB 'Other' in the range [From, To),
1170 /// and insert them into this MBB right before 'Where'.
1171 ///
1172 /// The instruction at 'Where' must not be included in the range of
1173 /// instructions to move.
1174 void splice(iterator Where, MachineBasicBlock *Other,
1175 iterator From, iterator To) {
1176 Insts.splice(Where.getInstrIterator(), Other->Insts,
1177 From.getInstrIterator(), To.getInstrIterator());
1178 }
1179
1180 /// This method unlinks 'this' from the containing function, and returns it,
1181 /// but does not delete it.
1183
1184 /// This method unlinks 'this' from the containing function and deletes it.
1186
1187 /// Given a machine basic block that branched to 'Old', change the code and
1188 /// CFG so that it branches to 'New' instead.
1190 MachineBasicBlock *New);
1191
1192 /// Update all phi nodes in this basic block to refer to basic block \p New
1193 /// instead of basic block \p Old.
1195 MachineBasicBlock *New);
1196
1197 /// Find the next valid DebugLoc starting at MBBI, skipping any debug
1198 /// instructions. Return UnknownLoc if there is none.
1199 LLVM_ABI DebugLoc findDebugLoc(instr_iterator MBBI);
1201 return findDebugLoc(MBBI.getInstrIterator());
1202 }
1203
1204 /// Has exact same behavior as @ref findDebugLoc (it also searches towards the
1205 /// end of this MBB) except that this function takes a reverse iterator to
1206 /// identify the starting MI.
1209 return rfindDebugLoc(MBBI.getInstrIterator());
1210 }
1211
1212 /// Find the previous valid DebugLoc preceding MBBI, skipping any debug
1213 /// instructions. It is possible to find the last DebugLoc in the MBB using
1214 /// findPrevDebugLoc(instr_end()). Return UnknownLoc if there is none.
1215 LLVM_ABI DebugLoc findPrevDebugLoc(instr_iterator MBBI);
1217 return findPrevDebugLoc(MBBI.getInstrIterator());
1218 }
1219
1220 /// Has exact same behavior as @ref findPrevDebugLoc (it also searches towards
1221 /// the beginning of this MBB) except that this function takes reverse
1222 /// iterator to identify the starting MI. A minor difference compared to
1223 /// findPrevDebugLoc is that we can't start scanning at "instr_end".
1226 return rfindPrevDebugLoc(MBBI.getInstrIterator());
1227 }
1228
1229 /// Find and return the merged DebugLoc of the branch instructions of the
1230 /// block. Return UnknownLoc if there is none.
1232
1233 /// Possible outcome of a register liveness query to computeRegisterLiveness()
1235 LQR_Live, ///< Register is known to be (at least partially) live.
1236 LQR_Dead, ///< Register is known to be fully dead.
1237 LQR_Unknown ///< Register liveness not decidable from local neighborhood.
1238 };
1239
1240 /// Return whether (physical) register \p Reg has been defined and not
1241 /// killed as of just before \p Before.
1242 ///
1243 /// Search is localised to a neighborhood of \p Neighborhood instructions
1244 /// before (searching for defs or kills) and \p Neighborhood instructions
1245 /// after (searching just for defs) \p Before.
1246 ///
1247 /// \p Reg must be a physical register.
1250 unsigned Neighborhood = 10) const;
1251
1252 // Debugging methods.
1253 LLVM_ABI void dump() const;
1254 LLVM_ABI void print(raw_ostream &OS, const SlotIndexes * = nullptr,
1255 bool IsStandalone = true) const;
1257 const SlotIndexes * = nullptr,
1258 bool IsStandalone = true) const;
1259
1261 PrintNameIr = (1 << 0), ///< Add IR name where available
1262 PrintNameAttributes = (1 << 1), ///< Print attributes
1263 };
1264
1266 unsigned printNameFlags = PrintNameIr,
1267 ModuleSlotTracker *moduleSlotTracker = nullptr) const;
1268
1269 // Printing method used by LoopInfo.
1270 LLVM_ABI void printAsOperand(raw_ostream &OS, bool PrintType = true) const;
1271
1272 /// MachineBasicBlocks are uniquely numbered at the function level, unless
1273 /// they're not in a MachineFunction yet, in which case this will return -1.
1274 int getNumber() const { return Number; }
1275 void setNumber(int N) { Number = N; }
1276
1277 /// For analyses, blocks have a more stable number.
1278 int getAnalysisNumber() const { return AnalysisNumber; }
1279 void setAnalysisNumber(int N) { AnalysisNumber = N; }
1280
1281 /// Return the call frame size on entry to this basic block.
1282 unsigned getCallFrameSize() const { return CallFrameSize; }
1283 /// Set the call frame size on entry to this basic block.
1284 void setCallFrameSize(unsigned N) { CallFrameSize = N; }
1285
1286 /// Return the MCSymbol for this basic block.
1287 LLVM_ABI MCSymbol *getSymbol() const;
1288
1289 /// Return the Windows EH Continuation Symbol for this basic block.
1291
1292 std::optional<uint64_t> getIrrLoopHeaderWeight() const {
1293 return IrrLoopHeaderWeight;
1294 }
1295
1297 IrrLoopHeaderWeight = Weight;
1298 }
1299
1300 /// Return probability of the edge from this block to MBB. This method should
1301 /// NOT be called directly, but by using getEdgeProbability method from
1302 /// MachineBranchProbabilityInfo class.
1304
1305 // Helper function for MIRPrinter.
1307
1308 /// Iterate over block PHI instructions and remove all incoming values for
1309 /// PredMBB.
1310 ///
1311 /// Method does not erase PHI instructions even if they have single income or
1312 /// do not have incoming values ar all. It is a caller responsibility to make
1313 /// decision how to process PHI instructions after incoming values removal.
1314 LLVM_ABI void
1316
1317private:
1318 /// Return probability iterator corresponding to the I successor iterator.
1319 probability_iterator getProbabilityIterator(succ_iterator I);
1320 const_probability_iterator
1321 getProbabilityIterator(const_succ_iterator I) const;
1322
1324
1325 // Methods used to maintain doubly linked list of blocks...
1326 friend struct ilist_callback_traits<MachineBasicBlock>;
1327
1328 // Machine-CFG mutators
1329
1330 /// Add Pred as a predecessor of this MachineBasicBlock. Don't do this
1331 /// unless you know what you're doing, because it doesn't update Pred's
1332 /// successors list. Use Pred->addSuccessor instead.
1333 void addPredecessor(MachineBasicBlock *Pred);
1334
1335 /// Remove Pred as a predecessor of this MachineBasicBlock. Don't do this
1336 /// unless you know what you're doing, because it doesn't update Pred's
1337 /// successors list. Use Pred->removeSuccessor instead.
1338 void removePredecessor(MachineBasicBlock *Pred);
1339};
1340
1342
1343/// Prints a machine basic block reference.
1344///
1345/// The format is:
1346/// %bb.5 - a machine basic block with MBB.getNumber() == 5.
1347///
1348/// Usage: OS << printMBBReference(MBB) << '\n';
1350
1351// This is useful when building IndexedMaps keyed on basic block pointers.
1354 unsigned operator()(const MachineBasicBlock *MBB) const {
1355 return MBB->getNumber();
1356 }
1357};
1358
1359//===--------------------------------------------------------------------===//
1360// GraphTraits specializations for machine basic block graphs (machine-CFGs)
1361//===--------------------------------------------------------------------===//
1362
1363// Provide specializations of GraphTraits to be able to treat a
1364// MachineFunction as a graph of MachineBasicBlocks.
1365//
1366
1367template <> struct GraphTraits<MachineBasicBlock *> {
1370
1371 static NodeRef getEntryNode(MachineBasicBlock *BB) { return BB; }
1372 static ChildIteratorType child_begin(NodeRef N) { return N->succ_begin(); }
1373 static ChildIteratorType child_end(NodeRef N) { return N->succ_end(); }
1374
1375 static unsigned getNumber(MachineBasicBlock *BB) {
1376 assert(BB->getAnalysisNumber() >= 0 && "negative block number");
1377 return BB->getAnalysisNumber();
1378 }
1379};
1380
1382 "GraphTraits getNumber() not detected");
1383
1384template <> struct GraphTraits<const MachineBasicBlock *> {
1387
1388 static NodeRef getEntryNode(const MachineBasicBlock *BB) { return BB; }
1389 static ChildIteratorType child_begin(NodeRef N) { return N->succ_begin(); }
1390 static ChildIteratorType child_end(NodeRef N) { return N->succ_end(); }
1391
1392 static unsigned getNumber(const MachineBasicBlock *BB) {
1393 assert(BB->getAnalysisNumber() >= 0 && "negative block number");
1394 return BB->getAnalysisNumber();
1395 }
1396};
1397
1399 "GraphTraits getNumber() not detected");
1400
1401// Provide specializations of GraphTraits to be able to treat a
1402// MachineFunction as a graph of MachineBasicBlocks and to walk it
1403// in inverse order. Inverse order for a function is considered
1404// to be when traversing the predecessor edges of a MBB
1405// instead of the successor edges.
1406//
1410
1412 return G.Graph;
1413 }
1414
1415 static ChildIteratorType child_begin(NodeRef N) { return N->pred_begin(); }
1416 static ChildIteratorType child_end(NodeRef N) { return N->pred_end(); }
1417
1418 static unsigned getNumber(MachineBasicBlock *BB) {
1419 assert(BB->getAnalysisNumber() >= 0 && "negative block number");
1420 return BB->getAnalysisNumber();
1421 }
1422};
1423
1425 "GraphTraits getNumber() not detected");
1426
1430
1432 return G.Graph;
1433 }
1434
1435 static ChildIteratorType child_begin(NodeRef N) { return N->pred_begin(); }
1436 static ChildIteratorType child_end(NodeRef N) { return N->pred_end(); }
1437
1438 static unsigned getNumber(const MachineBasicBlock *BB) {
1439 assert(BB->getAnalysisNumber() >= 0 && "negative block number");
1440 return BB->getAnalysisNumber();
1441 }
1442};
1443
1445 "GraphTraits getNumber() not detected");
1446
1447// These accessors are handy for sharing templated code between IR and MIR.
1448inline auto successors(const MachineBasicBlock *BB) { return BB->successors(); }
1449inline auto predecessors(const MachineBasicBlock *BB) {
1450 return BB->predecessors();
1451}
1452inline auto succ_size(const MachineBasicBlock *BB) { return BB->succ_size(); }
1453inline auto pred_size(const MachineBasicBlock *BB) { return BB->pred_size(); }
1454inline auto succ_begin(const MachineBasicBlock *BB) { return BB->succ_begin(); }
1455inline auto pred_begin(const MachineBasicBlock *BB) { return BB->pred_begin(); }
1456inline auto succ_end(const MachineBasicBlock *BB) { return BB->succ_end(); }
1457inline auto pred_end(const MachineBasicBlock *BB) { return BB->pred_end(); }
1458
1459/// MachineInstrSpan provides an interface to get an iteration range
1460/// containing the instruction it was initialized with, along with all
1461/// those instructions inserted prior to or following that instruction
1462/// at some point after the MachineInstrSpan is constructed.
1464 MachineBasicBlock &MBB;
1466
1467public:
1469 : MBB(*BB), I(I), B(I == MBB.begin() ? MBB.end() : std::prev(I)),
1470 E(std::next(I)) {
1471 assert(I == BB->end() || I->getParent() == BB);
1472 }
1473
1475 return B == MBB.end() ? MBB.begin() : std::next(B);
1476 }
1478 bool empty() { return begin() == end(); }
1479
1481};
1482
1483/// Increment \p It until it points to a non-debug instruction or to \p End
1484/// and return the resulting iterator. This function should only be used
1485/// MachineBasicBlock::{iterator, const_iterator, instr_iterator,
1486/// const_instr_iterator} and the respective reverse iterators.
1487template <typename IterT>
1488inline IterT skipDebugInstructionsForward(IterT It, IterT End,
1489 bool SkipPseudoOp = true) {
1490 while (It != End &&
1491 (It->isDebugInstr() || (SkipPseudoOp && It->isPseudoProbe())))
1492 ++It;
1493 return It;
1494}
1495
1496/// Decrement \p It until it points to a non-debug instruction or to \p Begin
1497/// and return the resulting iterator. This function should only be used
1498/// MachineBasicBlock::{iterator, const_iterator, instr_iterator,
1499/// const_instr_iterator} and the respective reverse iterators.
1500template <class IterT>
1501inline IterT skipDebugInstructionsBackward(IterT It, IterT Begin,
1502 bool SkipPseudoOp = true) {
1503 while (It != Begin &&
1504 (It->isDebugInstr() || (SkipPseudoOp && It->isPseudoProbe())))
1505 --It;
1506 return It;
1507}
1508
1509/// Increment \p It, then continue incrementing it while it points to a debug
1510/// instruction. A replacement for std::next.
1511template <typename IterT>
1512inline IterT next_nodbg(IterT It, IterT End, bool SkipPseudoOp = true) {
1513 return skipDebugInstructionsForward(std::next(It), End, SkipPseudoOp);
1514}
1515
1516/// Decrement \p It, then continue decrementing it while it points to a debug
1517/// instruction. A replacement for std::prev.
1518template <typename IterT>
1519inline IterT prev_nodbg(IterT It, IterT Begin, bool SkipPseudoOp = true) {
1520 return skipDebugInstructionsBackward(std::prev(It), Begin, SkipPseudoOp);
1521}
1522
1523/// Construct a range iterator which begins at \p It and moves forwards until
1524/// \p End is reached, skipping any debug instructions.
1525template <typename IterT>
1526inline auto instructionsWithoutDebug(IterT It, IterT End,
1527 bool SkipPseudoOp = true) {
1528 return make_filter_range(make_range(It, End), [=](const MachineInstr &MI) {
1529 return !MI.isDebugInstr() && !(SkipPseudoOp && MI.isPseudoProbe());
1530 });
1531}
1532
1533} // end namespace llvm
1534
1535#endif // LLVM_CODEGEN_MACHINEBASICBLOCK_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
MachineBasicBlock & MBB
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")
#define LLVM_ABI
Definition Compiler.h:213
This file defines DenseMapInfo traits for DenseMap.
This file defines the little GraphTraits<X> template class that should be specialized by classes that...
IRTranslator LLVM IR MI
A common definition of LaneBitmask for use in TableGen and CodeGen.
#define I(x, y, z)
Definition MD5.cpp:57
#define G(x, y, z)
Definition MD5.cpp:55
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
#define T
#define P(N)
This file defines the SparseBitVector class.
Value * RHS
Value * LHS
LLVM Basic Block Representation.
Definition BasicBlock.h:62
static BranchProbability getUnknown()
static void normalizeProbabilities(ProbabilityIter Begin, ProbabilityIter End)
A debug info location.
Definition DebugLoc.h:123
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
liveout_iterator(const MachineBasicBlock &MBB, MCRegister ExceptionPointer, MCRegister ExceptionSelector, bool End)
bool operator==(const liveout_iterator &RHS) 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
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.
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()
int getAnalysisNumber() const
For analyses, blocks have a more stable number.
@ 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().
DebugLoc rfindDebugLoc(reverse_iterator MBBI)
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
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 ...
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
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.
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.
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.
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....
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'.
Definition Pass.h:99
Simple wrapper around std::function<void(raw_ostream&)>.
Definition Printable.h:38
Wrapper class representing virtual and physical registers.
Definition Register.h:20
SlotIndexes pass.
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.
Definition StringRef.h:55
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.
Definition Type.h:46
typename base_list_type::const_reverse_iterator const_reverse_iterator
Definition ilist.h:124
typename base_list_type::reverse_iterator reverse_iterator
Definition ilist.h:123
typename base_list_type::const_iterator const_iterator
Definition ilist.h:122
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
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.
Definition STLExtras.h:1739
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
Definition ilist.h:344
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...
Definition STLExtras.h:552
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)
@ Other
Any other memory.
Definition ModRef.h:68
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
Definition ModRef.h:74
RNSuccIterator< NodeRef, BlockT, RegionT > succ_end(NodeRef Node)
Instruction::succ_iterator succ_iterator
Definition CFG.h:138
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
auto pred_begin(const MachineBasicBlock *BB)
auto predecessors(const MachineBasicBlock *BB)
Instruction::const_succ_iterator const_succ_iterator
Definition CFG.h:139
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.
Definition BitVector.h:870
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
DenseMapInfo< unsigned > NumberInfo
static unsigned getHashValue(const MBBSectionID &SecID)
DenseMapInfo< MBBSectionID::SectionType > TypeInfo
static bool isEqual(const MBBSectionID &LHS, const MBBSectionID &RHS)
An information struct used to provide DenseMap with the various necessary components for a given valu...
static NodeRef getEntryNode(Inverse< MachineBasicBlock * > G)
static unsigned getNumber(MachineBasicBlock *BB)
static unsigned getNumber(const MachineBasicBlock *BB)
static NodeRef getEntryNode(Inverse< const MachineBasicBlock * > G)
MachineBasicBlock::const_pred_iterator ChildIteratorType
static unsigned getNumber(MachineBasicBlock *BB)
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)
static constexpr LaneBitmask getAll()
Definition LaneBitmask.h:82
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(MCRegister 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.
Definition ilist.h:65
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.
Definition ilist.h:90