21#include "llvm/Config/llvm-config.h"
44 OS <<
"Machine loop info for machine function '" << MF.
getName() <<
"':\n";
55 "Machine Natural Loop Construction",
true,
true)
63 LI.calculate(getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree());
73 return !PAC.preserved() &&
132 if (
const BasicBlock *PHeadBB = PHeadMBB->getBasicBlock())
133 if (
DebugLoc DL = PHeadBB->getTerminator()->getDebugLoc())
139 if (
const BasicBlock *HeadBB = HeadMBB->getBasicBlock())
140 return HeadBB->getTerminator()->getDebugLoc();
147 bool FindMultiLoopPreheader)
const {
151 if (!SpeculativePreheader)
170 if (!FindMultiLoopPreheader) {
175 if (
T &&
T->getHeader() == S)
190 if (
const auto *TI = BB->getTerminator())
191 LoopID = TI->getMetadata(LLVMContext::MD_loop);
208 if (Succ == Header) {
210 MD = TI->getMetadata(LLVMContext::MD_loop);
218 else if (MD != LoopID)
229bool MachineLoop::isLoopInvariantImplicitPhysReg(
Register Reg)
const {
233 if (
MRI->isConstantPhysReg(Reg))
242 MRI->def_instructions(Reg),
260 if (Reg == 0)
continue;
262 if (ExcludeReg == Reg)
267 if (Reg.isPhysical()) {
274 if (!isLoopInvariantImplicitPhysReg(Reg) &&
275 !(
TRI->isCallerPreservedPhysReg(Reg.asMCReg(), *
I.getMF())) &&
276 !
TII->isIgnorableUse(MO))
280 }
else if (!MO.isDead()) {
294 "Machine instr not mapped for this vreg?!");
306#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
unsigned const MachineRegisterInfo * MRI
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
COFF::MachineTypes Machine
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Dominance Frontier Construction
const HexagonInstrInfo * TII
unsigned const TargetRegisterInfo * TRI
PassBuilder PB(Machine, PassOpts->PTO, std::nullopt, &PIC)
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This templated class represents "all analyses that operate over <a particular IR unit>" (e....
API to communicate dependencies between analyses during invalidation.
A container for analyses that lazily runs them and caches their results.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
LLVM Basic Block Representation.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Represents analyses that only rely on functions' control flow.
Instances of this class are used to represent loops that are detected in the flow graph.
bool contains(const MachineLoop *L) const
Return true if the specified loop is contained within in this loop.
MachineBasicBlock * getLoopLatch() const
If there is a single latch block for this loop, return it.
MachineBasicBlock * getHeader() const
void print(raw_ostream &OS, bool Verbose=false, bool PrintNested=true, unsigned Depth=0) const
Print loop with all the BBs inside it.
iterator_range< block_iterator > blocks() const
MachineBasicBlock * getLoopPreheader() const
If there is a preheader for this loop, return it.
MachineBasicBlock * getExitingBlock() const
If getExitingBlocks would return exactly one block, return that block.
bool isLoopExiting(const MachineBasicBlock *BB) const
True if terminator in the block can branch to another block that is outside of the current loop.
This class builds and contains all of the top-level loop structures in the specified function.
void analyze(const DominatorTreeBase< MachineBasicBlock, false > &DomTree)
Create the loop forest using a stable algorithm.
MachineLoop * getLoopFor(const MachineBasicBlock *BB) const
Return the inner most loop that BB lives in.
Represents a single loop in the control flow graph.
const MDOperand & getOperand(unsigned I) const
unsigned getNumOperands() const
Return number of MDNode operands.
unsigned pred_size() const
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
bool hasAddressTaken() const
Test whether this block is used as something other than the target of a terminator,...
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
iterator_range< succ_iterator > successors()
iterator_range< pred_iterator > predecessors()
Analysis pass which computes a MachineDominatorTree.
Analysis pass which computes a MachineDominatorTree.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
MachineDominatorTree & getBase()
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Representation of each machine instruction.
Analysis pass that exposes the MachineLoopInfo for a machine function.
Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
MachineLoopInfoWrapperPass()
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
void calculate(MachineDominatorTree &MDT)
Calculate the natural loop information.
bool invalidate(MachineFunction &, const PreservedAnalyses &PA, MachineFunctionAnalysisManager::Invalidator &)
Handle invalidation explicitly.
MachineBasicBlock * findLoopPreheader(MachineLoop *L, bool SpeculativePreheader=false, bool FindMultiLoopPreheader=false) const
Find the block that either is the loop preheader, or could speculatively be used as the preheader.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
MachineBasicBlock * findLoopControlBlock() const
Find the block that contains the loop control variable and the loop test.
MDNode * getLoopID() const
Find the llvm.loop metadata for this loop.
DebugLoc getStartLoc() const
Return the debug location of the start of this loop.
MachineBasicBlock * getBottomBlock()
Return the "bottom" block in the loop, which is the last block in the linear layout,...
bool isLoopInvariant(MachineInstr &I, const Register ExcludeReg=0) const
Returns true if the instruction is loop invariant.
MachineBasicBlock * getTopBlock()
Return the "top" block in the loop, which is the first block in the linear layout,...
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
Wrapper class representing virtual and physical registers.
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual bool shouldAnalyzePhysregInMachineLoopInfo(MCRegister R) const
Returns true if MachineLoopInfo should analyze the given physreg for loop invariance.
TargetSubtargetInfo - Generic base class for all target subtargets.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
self_iterator getIterator()
This is an optimization pass for GlobalISel generic memory operations.
auto successors(const MachineBasicBlock *BB)
void initializeMachineLoopInfoWrapperPassPass(PassRegistry &)
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr)
char & MachineLoopInfoID
MachineLoopInfo - This pass is a loop analysis pass.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
A special type used by analysis passes to provide an address that identifies that particular analysis...