//===- llvm/CodeGen/MachineBasicBlock.h -------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // Collect the sequence of machine instructions for a basic block. // //===----------------------------------------------------------------------===// #ifndef LLVM_CODEGEN_MACHINEBASICBLOCK_H #define LLVM_CODEGEN_MACHINEBASICBLOCK_H #include "llvm/ADT/DenseMapInfo.h" #include "llvm/ADT/GraphTraits.h" #include "llvm/ADT/SparseBitVector.h" #include "llvm/ADT/ilist.h" #include "llvm/ADT/iterator_range.h" #include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineInstrBundleIterator.h" #include "llvm/IR/DebugLoc.h" #include "llvm/MC/LaneBitmask.h" #include "llvm/Support/BranchProbability.h" #include <cassert> #include <cstdint> #include <iterator> #include <string> #include <vector> namespace llvm { class BasicBlock; class MachineFunction; class MCSymbol; class ModuleSlotTracker; class Pass; class Printable; class SlotIndexes; class StringRef; class raw_ostream; class LiveIntervals; class TargetRegisterClass; class TargetRegisterInfo; template <typename IRUnitT, typename... ExtraArgTs> class AnalysisManager; MachineFunctionAnalysisManager; // This structure uniquely identifies a basic block section. // Possible values are // {Type: Default, Number: (unsigned)} (These are regular section IDs) // {Type: Exception, Number: 0} (ExceptionSectionID) // {Type: Cold, Number: 0} (ColdSectionID) struct MBBSectionID { … }; template <> struct DenseMapInfo<MBBSectionID> { … }; // This structure represents the information for a basic block pertaining to // the basic block sections profile. struct UniqueBBID { … }; template <> struct ilist_traits<MachineInstr> { … }; class MachineBasicBlock : public ilist_node_with_parent<MachineBasicBlock, MachineFunction> { … }; raw_ostream& operator<<(raw_ostream &OS, const MachineBasicBlock &MBB); /// Prints a machine basic block reference. /// /// The format is: /// %bb.5 - a machine basic block with MBB.getNumber() == 5. /// /// Usage: OS << printMBBReference(MBB) << '\n'; Printable printMBBReference(const MachineBasicBlock &MBB); // This is useful when building IndexedMaps keyed on basic block pointers. struct MBB2NumberFunctor { … }; //===--------------------------------------------------------------------===// // GraphTraits specializations for machine basic block graphs (machine-CFGs) //===--------------------------------------------------------------------===// // Provide specializations of GraphTraits to be able to treat a // MachineFunction as a graph of MachineBasicBlocks. // template <> struct GraphTraits<MachineBasicBlock *> { … }; static_assert …; template <> struct GraphTraits<const MachineBasicBlock *> { … }; static_assert …; // Provide specializations of GraphTraits to be able to treat a // MachineFunction as a graph of MachineBasicBlocks and to walk it // in inverse order. Inverse order for a function is considered // to be when traversing the predecessor edges of a MBB // instead of the successor edges. // template <> struct GraphTraits<Inverse<MachineBasicBlock*>> { … }; static_assert …; template <> struct GraphTraits<Inverse<const MachineBasicBlock*>> { … }; static_assert …; // These accessors are handy for sharing templated code between IR and MIR. inline auto successors(const MachineBasicBlock *BB) { … } inline auto predecessors(const MachineBasicBlock *BB) { … } /// MachineInstrSpan provides an interface to get an iteration range /// containing the instruction it was initialized with, along with all /// those instructions inserted prior to or following that instruction /// at some point after the MachineInstrSpan is constructed. class MachineInstrSpan { … }; /// Increment \p It until it points to a non-debug instruction or to \p End /// and return the resulting iterator. This function should only be used /// MachineBasicBlock::{iterator, const_iterator, instr_iterator, /// const_instr_iterator} and the respective reverse iterators. template <typename IterT> inline IterT skipDebugInstructionsForward(IterT It, IterT End, bool SkipPseudoOp = true) { … } /// Decrement \p It until it points to a non-debug instruction or to \p Begin /// and return the resulting iterator. This function should only be used /// MachineBasicBlock::{iterator, const_iterator, instr_iterator, /// const_instr_iterator} and the respective reverse iterators. template <class IterT> inline IterT skipDebugInstructionsBackward(IterT It, IterT Begin, bool SkipPseudoOp = true) { … } /// Increment \p It, then continue incrementing it while it points to a debug /// instruction. A replacement for std::next. template <typename IterT> inline IterT next_nodbg(IterT It, IterT End, bool SkipPseudoOp = true) { … } /// Decrement \p It, then continue decrementing it while it points to a debug /// instruction. A replacement for std::prev. template <typename IterT> inline IterT prev_nodbg(IterT It, IterT Begin, bool SkipPseudoOp = true) { … } /// Construct a range iterator which begins at \p It and moves forwards until /// \p End is reached, skipping any debug instructions. template <typename IterT> inline auto instructionsWithoutDebug(IterT It, IterT End, bool SkipPseudoOp = true) { … } } // end namespace llvm #endif // LLVM_CODEGEN_MACHINEBASICBLOCK_H