Thanks to visit codestin.com
Credit goes to llvm.org

LLVM 22.0.0git
llvm::ReachingDefInfo Class Reference

This class provides the reaching def analysis. More...

#include "llvm/CodeGen/ReachingDefAnalysis.h"

Public Member Functions

 ReachingDefInfo ()
 ReachingDefInfo (ReachingDefInfo &&)
 ~ReachingDefInfo ()
bool invalidate (MachineFunction &F, const PreservedAnalyses &PA, MachineFunctionAnalysisManager::Invalidator &)
 Handle invalidation explicitly.
void run (MachineFunction &mf)
void print (raw_ostream &OS)
void releaseMemory ()
void reset ()
 Re-run the analysis.
void init ()
 Initialize data structures.
void traverse ()
 Traverse the machine function, mapping definitions.
int getReachingDef (MachineInstr *MI, Register Reg) const
 Provides the instruction id of the closest reaching def instruction of Reg that reaches MI, relative to the begining of MI's basic block.
bool hasSameReachingDef (MachineInstr *A, MachineInstr *B, Register Reg) const
 Return whether A and B use the same def of Reg.
bool isReachingDefLiveOut (MachineInstr *MI, Register Reg) const
 Return whether the reaching def for MI also is live out of its parent block.
MachineInstrgetLocalLiveOutMIDef (MachineBasicBlock *MBB, Register Reg) const
 Return the local MI that produces the live out value for Reg, or nullptr for a non-live out or non-local def.
MachineInstrgetUniqueReachingMIDef (MachineInstr *MI, Register Reg) const
 If a single MachineInstr creates the reaching definition, then return it.
MachineInstrgetMIOperand (MachineInstr *MI, unsigned Idx) const
 If a single MachineInstr creates the reaching definition, for MIs operand at Idx, then return it.
MachineInstrgetMIOperand (MachineInstr *MI, MachineOperand &MO) const
 If a single MachineInstr creates the reaching definition, for MIs MO, then return it.
bool hasLocalDefBefore (MachineInstr *MI, Register Reg) const
 Provide whether the register has been defined in the same basic block as, and before, MI.
bool isRegUsedAfter (MachineInstr *MI, Register Reg) const
 Return whether the given register is used after MI, whether it's a local use or a live out.
bool isRegDefinedAfter (MachineInstr *MI, Register Reg) const
 Return whether the given register is defined after MI.
int getClearance (MachineInstr *MI, Register Reg) const
 Provides the clearance - the number of instructions since the closest reaching def instuction of Reg that reaches MI.
void getReachingLocalUses (MachineInstr *MI, Register Reg, InstSet &Uses) const
 Provides the uses, in the same block as MI, of register that MI defines.
void getLiveOuts (MachineBasicBlock *MBB, Register Reg, InstSet &Defs, BlockSet &VisitedBBs) const
 Search MBB for a definition of Reg and insert it into Defs.
void getLiveOuts (MachineBasicBlock *MBB, Register Reg, InstSet &Defs) const
bool getLiveInUses (MachineBasicBlock *MBB, Register Reg, InstSet &Uses) const
 For the given block, collect the instructions that use the live-in value of the provided register.
void getGlobalUses (MachineInstr *MI, Register Reg, InstSet &Uses) const
 Collect the users of the value stored in Reg, which is defined by MI.
void getGlobalReachingDefs (MachineInstr *MI, Register Reg, InstSet &Defs) const
 Collect all possible definitions of the value stored in Reg, which is used by MI.
bool isSafeToMoveForwards (MachineInstr *From, MachineInstr *To) const
 Return whether From can be moved forwards to just before To.
bool isSafeToMoveBackwards (MachineInstr *From, MachineInstr *To) const
 Return whether From can be moved backwards to just after To.
void collectKilledOperands (MachineInstr *MI, InstSet &Dead) const
 Assuming MI is dead, recursively search the incoming operands which are killed by MI and collect those that would become dead.
bool isSafeToRemove (MachineInstr *MI, InstSet &ToRemove) const
 Return whether removing this instruction will have no effect on the program, returning the redundant use-def chain.
bool isSafeToRemove (MachineInstr *MI, InstSet &ToRemove, InstSet &Ignore) const
 Return whether removing this instruction will have no effect on the program, ignoring the possible effects on some instructions, returning the redundant use-def chain.
bool isSafeToDefRegAt (MachineInstr *MI, Register Reg) const
 Return whether a MachineInstr could be inserted at MI and safely define the given register without affecting the program.
bool isSafeToDefRegAt (MachineInstr *MI, Register Reg, InstSet &Ignore) const
 Return whether a MachineInstr could be inserted at MI and safely define the given register without affecting the program, ignoring any effects on the provided instructions.

Detailed Description

This class provides the reaching def analysis.

Definition at line 114 of file ReachingDefAnalysis.h.

Constructor & Destructor Documentation

◆ ReachingDefInfo() [1/2]

ReachingDefInfo::ReachingDefInfo ( )
default

Referenced by ReachingDefInfo().

◆ ReachingDefInfo() [2/2]

ReachingDefInfo::ReachingDefInfo ( ReachingDefInfo && )
default

References ReachingDefInfo().

◆ ~ReachingDefInfo()

ReachingDefInfo::~ReachingDefInfo ( )
default

References A(), B(), F, Ignore, MBB, MI, Reg, ToRemove, and Uses.

Member Function Documentation

◆ collectKilledOperands()

void ReachingDefInfo::collectKilledOperands ( MachineInstr * MI,
InstSet & Dead ) const

Assuming MI is dead, recursively search the incoming operands which are killed by MI and collect those that would become dead.

Definition at line 781 of file ReachingDefAnalysis.cpp.

References collectKilledOperands(), getGlobalUses(), getMIOperand(), IsDead, isValidRegDef(), isValidRegUse(), mayHaveSideEffects(), MI, llvm::set_is_subset(), and Uses.

Referenced by collectKilledOperands().

◆ getClearance()

int ReachingDefInfo::getClearance ( MachineInstr * MI,
Register Reg ) const

Provides the clearance - the number of instructions since the closest reaching def instuction of Reg that reaches MI.

Definition at line 458 of file ReachingDefAnalysis.cpp.

References assert(), getReachingDef(), and MI.

◆ getGlobalReachingDefs()

void ReachingDefInfo::getGlobalReachingDefs ( MachineInstr * MI,
Register Reg,
InstSet & Defs ) const

Collect all possible definitions of the value stored in Reg, which is used by MI.

Definition at line 534 of file ReachingDefAnalysis.cpp.

References getLiveOuts(), getUniqueReachingMIDef(), llvm::SmallPtrSetImpl< PtrType >::insert(), MBB, and MI.

Referenced by print().

◆ getGlobalUses()

◆ getLiveInUses()

bool ReachingDefInfo::getLiveInUses ( MachineBasicBlock * MBB,
Register Reg,
InstSet & Uses ) const

For the given block, collect the instructions that use the live-in value of the provided register.

Return whether the value is still live on exit.

Definition at line 491 of file ReachingDefAnalysis.cpp.

References getReachingDef(), llvm::instructionsWithoutDebug(), isReachingDefLiveOut(), isValidRegUseOf(), llvm::Last, MBB, MI, and Uses.

Referenced by getGlobalUses().

◆ getLiveOuts() [1/2]

void ReachingDefInfo::getLiveOuts ( MachineBasicBlock * MBB,
Register Reg,
InstSet & Defs ) const

Definition at line 545 of file ReachingDefAnalysis.cpp.

References getLiveOuts(), and MBB.

◆ getLiveOuts() [2/2]

void ReachingDefInfo::getLiveOuts ( MachineBasicBlock * MBB,
Register Reg,
InstSet & Defs,
BlockSet & VisitedBBs ) const

Search MBB for a definition of Reg and insert it into Defs.

If no definition is found, recursively search the predecessor blocks for them.

Definition at line 551 of file ReachingDefAnalysis.cpp.

References llvm::SmallPtrSetImpl< PtrType >::count(), getLiveOuts(), getLocalLiveOutMIDef(), llvm::SmallPtrSetImpl< PtrType >::insert(), and MBB.

Referenced by getGlobalReachingDefs(), getLiveOuts(), getLiveOuts(), and getUniqueReachingMIDef().

◆ getLocalLiveOutMIDef()

MachineInstr * ReachingDefInfo::getLocalLiveOutMIDef ( MachineBasicBlock * MBB,
Register Reg ) const

Return the local MI that produces the live out value for Reg, or nullptr for a non-live out or non-local def.

Definition at line 655 of file ReachingDefAnalysis.cpp.

References getReachingDef(), isFIDef(), isValidRegDefOf(), llvm::Last, and MBB.

Referenced by getGlobalUses(), getLiveOuts(), and isRegDefinedAfter().

◆ getMIOperand() [1/2]

MachineInstr * ReachingDefInfo::getMIOperand ( MachineInstr * MI,
MachineOperand & MO ) const

If a single MachineInstr creates the reaching definition, for MIs MO, then return it.

Otherwise return null.

Definition at line 595 of file ReachingDefAnalysis.cpp.

References assert(), llvm::MachineOperand::getReg(), getUniqueReachingMIDef(), llvm::MachineOperand::isReg(), and MI.

◆ getMIOperand() [2/2]

MachineInstr * ReachingDefInfo::getMIOperand ( MachineInstr * MI,
unsigned Idx ) const

If a single MachineInstr creates the reaching definition, for MIs operand at Idx, then return it.

Otherwise return null.

Definition at line 589 of file ReachingDefAnalysis.cpp.

References assert(), getUniqueReachingMIDef(), and MI.

Referenced by collectKilledOperands().

◆ getReachingDef()

int ReachingDefInfo::getReachingDef ( MachineInstr * MI,
Register Reg ) const

Provides the instruction id of the closest reaching def instruction of Reg that reaches MI, relative to the begining of MI's basic block.

Note that Reg may represent a stack slot.

Definition at line 385 of file ReachingDefAnalysis.cpp.

References assert(), Lookup(), and MI.

Referenced by getClearance(), getLiveInUses(), getLocalLiveOutMIDef(), hasLocalDefBefore(), hasSameReachingDef(), isReachingDefLiveOut(), and isRegDefinedAfter().

◆ getReachingLocalUses()

void ReachingDefInfo::getReachingLocalUses ( MachineInstr * MI,
Register Reg,
InstSet & Uses ) const

Provides the uses, in the same block as MI, of register that MI defines.

This does not consider live-outs.

Definition at line 467 of file ReachingDefAnalysis.cpp.

References isValidRegUseOf(), MBB, MI, and Uses.

Referenced by getGlobalUses().

◆ getUniqueReachingMIDef()

MachineInstr * ReachingDefInfo::getUniqueReachingMIDef ( MachineInstr * MI,
Register Reg ) const

If a single MachineInstr creates the reaching definition, then return it.

Otherwise return null.

Definition at line 569 of file ReachingDefAnalysis.cpp.

References getLiveOuts(), MI, and llvm::MachineBasicBlock::predecessors().

Referenced by getGlobalReachingDefs(), getMIOperand(), and getMIOperand().

◆ hasLocalDefBefore()

bool ReachingDefInfo::hasLocalDefBefore ( MachineInstr * MI,
Register Reg ) const

Provide whether the register has been defined in the same basic block as, and before, MI.

Definition at line 463 of file ReachingDefAnalysis.cpp.

References getReachingDef(), and MI.

◆ hasSameReachingDef()

bool ReachingDefInfo::hasSameReachingDef ( MachineInstr * A,
MachineInstr * B,
Register Reg ) const

Return whether A and B use the same def of Reg.

Definition at line 428 of file ReachingDefAnalysis.cpp.

References A(), B(), and getReachingDef().

◆ init()

void ReachingDefInfo::init ( )

Initialize data structures.

Definition at line 355 of file ReachingDefAnalysis.cpp.

References llvm::LoopTraversal::traverse().

Referenced by reset(), and run().

◆ invalidate()

bool ReachingDefInfo::invalidate ( MachineFunction & F,
const PreservedAnalyses & PA,
MachineFunctionAnalysisManager::Invalidator &  )

Handle invalidation explicitly.

Definition at line 59 of file ReachingDefAnalysis.cpp.

References llvm::PreservedAnalyses::getChecker().

◆ isReachingDefLiveOut()

bool ReachingDefInfo::isReachingDefLiveOut ( MachineInstr * MI,
Register Reg ) const

Return whether the reaching def for MI also is live out of its parent block.

Definition at line 634 of file ReachingDefAnalysis.cpp.

References getReachingDef(), isValidRegDefOf(), llvm::Last, MBB, and MI.

Referenced by getLiveInUses().

◆ isRegDefinedAfter()

bool ReachingDefInfo::isRegDefinedAfter ( MachineInstr * MI,
Register Reg ) const

Return whether the given register is defined after MI.

Definition at line 621 of file ReachingDefAnalysis.cpp.

References getLocalLiveOutMIDef(), getReachingDef(), llvm::Last, MBB, and MI.

Referenced by isSafeToDefRegAt().

◆ isRegUsedAfter()

bool ReachingDefInfo::isRegUsedAfter ( MachineInstr * MI,
Register Reg ) const

Return whether the given register is used after MI, whether it's a local use or a live out.

Definition at line 601 of file ReachingDefAnalysis.cpp.

References llvm::instructionsWithoutDebug(), llvm::Last, MBB, and MI.

Referenced by isSafeToDefRegAt().

◆ isSafeToDefRegAt() [1/2]

bool ReachingDefInfo::isSafeToDefRegAt ( MachineInstr * MI,
Register Reg ) const

Return whether a MachineInstr could be inserted at MI and safely define the given register without affecting the program.

Definition at line 813 of file ReachingDefAnalysis.cpp.

References Ignore, isSafeToDefRegAt(), and MI.

Referenced by isSafeToDefRegAt().

◆ isSafeToDefRegAt() [2/2]

bool ReachingDefInfo::isSafeToDefRegAt ( MachineInstr * MI,
Register Reg,
InstSet & Ignore ) const

Return whether a MachineInstr could be inserted at MI and safely define the given register without affecting the program, ignoring any effects on the provided instructions.

Definition at line 818 of file ReachingDefAnalysis.cpp.

References getGlobalUses(), I, Ignore, isRegDefinedAfter(), isRegUsedAfter(), isValidRegDefOf(), MBB, MI, llvm::set_is_subset(), and Uses.

◆ isSafeToMoveBackwards()

bool ReachingDefInfo::isSafeToMoveBackwards ( MachineInstr * From,
MachineInstr * To ) const

Return whether From can be moved backwards to just after To.

Definition at line 729 of file ReachingDefAnalysis.cpp.

References llvm::MachineInstr::getParent(), I, and llvm::MachineBasicBlock::rend().

◆ isSafeToMoveForwards()

bool ReachingDefInfo::isSafeToMoveForwards ( MachineInstr * From,
MachineInstr * To ) const

Return whether From can be moved forwards to just before To.

Definition at line 719 of file ReachingDefAnalysis.cpp.

References llvm::MachineBasicBlock::end(), llvm::MachineInstr::getParent(), and I.

◆ isSafeToRemove() [1/2]

bool ReachingDefInfo::isSafeToRemove ( MachineInstr * MI,
InstSet & ToRemove ) const

Return whether removing this instruction will have no effect on the program, returning the redundant use-def chain.

Definition at line 739 of file ReachingDefAnalysis.cpp.

References Ignore, isSafeToRemove(), MI, and ToRemove.

Referenced by isSafeToRemove(), and isSafeToRemove().

◆ isSafeToRemove() [2/2]

bool ReachingDefInfo::isSafeToRemove ( MachineInstr * MI,
InstSet & ToRemove,
InstSet & Ignore ) const

Return whether removing this instruction will have no effect on the program, ignoring the possible effects on some instructions, returning the redundant use-def chain.

Definition at line 746 of file ReachingDefAnalysis.cpp.

References Ignore, isSafeToRemove(), MI, and ToRemove.

◆ print()

◆ releaseMemory()

void ReachingDefInfo::releaseMemory ( )

Definition at line 340 of file ReachingDefAnalysis.cpp.

Referenced by reset().

◆ reset()

void ReachingDefInfo::reset ( )

Re-run the analysis.

Definition at line 349 of file ReachingDefAnalysis.cpp.

References init(), releaseMemory(), and traverse().

◆ run()

◆ traverse()

void ReachingDefInfo::traverse ( )

Traverse the machine function, mapping definitions.

Definition at line 366 of file ReachingDefAnalysis.cpp.

References assert().

Referenced by reset(), and run().


The documentation for this class was generated from the following files: