LLVM  13.0.0git
Public Member Functions | Static Public Attributes | List of all members
llvm::ReachingDefAnalysis Class Reference

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

#include "llvm/CodeGen/ReachingDefAnalysis.h"

Inheritance diagram for llvm::ReachingDefAnalysis:
Inheritance graph
[legend]
Collaboration diagram for llvm::ReachingDefAnalysis:
Collaboration graph
[legend]

Public Member Functions

 ReachingDefAnalysis ()
 
void releaseMemory () override
 releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memory when it is no longer needed. More...
 
void getAnalysisUsage (AnalysisUsage &AU) const override
 getAnalysisUsage - Subclasses that override getAnalysisUsage must call this. More...
 
bool runOnMachineFunction (MachineFunction &MF) override
 runOnMachineFunction - This method must be overloaded to perform the desired machine code transformation or analysis. More...
 
MachineFunctionProperties getRequiredProperties () const override
 
void reset ()
 Re-run the analysis. More...
 
void init ()
 Initialize data structures. More...
 
void traverse ()
 Traverse the machine function, mapping definitions. More...
 
int getReachingDef (MachineInstr *MI, MCRegister PhysReg) const
 Provides the instruction id of the closest reaching def instruction of PhysReg that reaches MI, relative to the begining of MI's basic block. More...
 
bool hasSameReachingDef (MachineInstr *A, MachineInstr *B, MCRegister PhysReg) const
 Return whether A and B use the same def of PhysReg. More...
 
bool isReachingDefLiveOut (MachineInstr *MI, MCRegister PhysReg) const
 Return whether the reaching def for MI also is live out of its parent block. More...
 
MachineInstrgetLocalLiveOutMIDef (MachineBasicBlock *MBB, MCRegister PhysReg) const
 Return the local MI that produces the live out value for PhysReg, or nullptr for a non-live out or non-local def. More...
 
MachineInstrgetUniqueReachingMIDef (MachineInstr *MI, MCRegister PhysReg) const
 If a single MachineInstr creates the reaching definition, then return it. More...
 
MachineInstrgetMIOperand (MachineInstr *MI, unsigned Idx) const
 If a single MachineInstr creates the reaching definition, for MIs operand at Idx, then return it. More...
 
MachineInstrgetMIOperand (MachineInstr *MI, MachineOperand &MO) const
 If a single MachineInstr creates the reaching definition, for MIs MO, then return it. More...
 
bool hasLocalDefBefore (MachineInstr *MI, MCRegister PhysReg) const
 Provide whether the register has been defined in the same basic block as, and before, MI. More...
 
bool isRegUsedAfter (MachineInstr *MI, MCRegister PhysReg) const
 Return whether the given register is used after MI, whether it's a local use or a live out. More...
 
bool isRegDefinedAfter (MachineInstr *MI, MCRegister PhysReg) const
 Return whether the given register is defined after MI. More...
 
int getClearance (MachineInstr *MI, MCRegister PhysReg) const
 Provides the clearance - the number of instructions since the closest reaching def instuction of PhysReg that reaches MI. More...
 
void getReachingLocalUses (MachineInstr *MI, MCRegister PhysReg, InstSet &Uses) const
 Provides the uses, in the same block as MI, of register that MI defines. More...
 
void getLiveOuts (MachineBasicBlock *MBB, MCRegister PhysReg, InstSet &Defs, BlockSet &VisitedBBs) const
 Search MBB for a definition of PhysReg and insert it into Defs. More...
 
void getLiveOuts (MachineBasicBlock *MBB, MCRegister PhysReg, InstSet &Defs) const
 
bool getLiveInUses (MachineBasicBlock *MBB, MCRegister PhysReg, InstSet &Uses) const
 For the given block, collect the instructions that use the live-in value of the provided register. More...
 
void getGlobalUses (MachineInstr *MI, MCRegister PhysReg, InstSet &Uses) const
 Collect the users of the value stored in PhysReg, which is defined by MI. More...
 
void getGlobalReachingDefs (MachineInstr *MI, MCRegister PhysReg, InstSet &Defs) const
 Collect all possible definitions of the value stored in PhysReg, which is used by MI. More...
 
bool isSafeToMoveForwards (MachineInstr *From, MachineInstr *To) const
 Return whether From can be moved forwards to just before To. More...
 
bool isSafeToMoveBackwards (MachineInstr *From, MachineInstr *To) const
 Return whether From can be moved backwards to just after To. More...
 
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. More...
 
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. More...
 
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. More...
 
bool isSafeToDefRegAt (MachineInstr *MI, MCRegister PhysReg) const
 Return whether a MachineInstr could be inserted at MI and safely define the given register without affecting the program. More...
 
bool isSafeToDefRegAt (MachineInstr *MI, MCRegister PhysReg, 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. More...
 
- Public Member Functions inherited from llvm::MachineFunctionPass
bool doInitialization (Module &) override
 doInitialization - Virtual method overridden by subclasses to do any necessary initialization before any pass is run. More...
 
- Public Member Functions inherited from llvm::FunctionPass
 FunctionPass (char &pid)
 
PasscreatePrinterPass (raw_ostream &OS, const std::string &Banner) const override
 createPrinterPass - Get a function printer pass. More...
 
void assignPassManager (PMStack &PMS, PassManagerType T) override
 Find appropriate Function Pass Manager or Call Graph Pass Manager in the PM Stack and add self into that manager. More...
 
PassManagerType getPotentialPassManagerType () const override
 Return what kind of Pass Manager can manage this pass. More...
 
- Public Member Functions inherited from llvm::Pass
 Pass (PassKind K, char &pid)
 
 Pass (const Pass &)=delete
 
Passoperator= (const Pass &)=delete
 
virtual ~Pass ()
 
PassKind getPassKind () const
 
virtual StringRef getPassName () const
 getPassName - Return a nice clean name for a pass. More...
 
AnalysisID getPassID () const
 getPassID - Return the PassID number that corresponds to this pass. More...
 
virtual bool doFinalization (Module &)
 doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes have run. More...
 
virtual void print (raw_ostream &OS, const Module *M) const
 print - Print out the internal state of the pass. More...
 
void dump () const
 
virtual void preparePassManager (PMStack &)
 Check if available pass managers are suitable for this pass or not. More...
 
void setResolver (AnalysisResolver *AR)
 
AnalysisResolvergetResolver () const
 
virtual void * getAdjustedAnalysisPointer (AnalysisID ID)
 getAdjustedAnalysisPointer - This method is used when a pass implements an analysis interface through multiple inheritance. More...
 
virtual ImmutablePassgetAsImmutablePass ()
 
virtual PMDataManagergetAsPMDataManager ()
 
virtual void verifyAnalysis () const
 verifyAnalysis() - This member can be implemented by a analysis pass to check state of analysis information. More...
 
virtual void dumpPassStructure (unsigned Offset=0)
 
template<typename AnalysisType >
AnalysisType * getAnalysisIfAvailable () const
 getAnalysisIfAvailable<AnalysisType>() - Subclasses use this function to get analysis information that might be around, for example to update it. More...
 
bool mustPreserveAnalysisID (char &AID) const
 mustPreserveAnalysisID - This method serves the same function as getAnalysisIfAvailable, but works if you just have an AnalysisID. More...
 
template<typename AnalysisType >
AnalysisType & getAnalysis () const
 getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information that they claim to use by overriding the getAnalysisUsage function. More...
 
template<typename AnalysisType >
AnalysisType & getAnalysis (Function &F, bool *Changed=nullptr)
 getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information that they claim to use by overriding the getAnalysisUsage function. More...
 
template<typename AnalysisType >
AnalysisType & getAnalysisID (AnalysisID PI) const
 
template<typename AnalysisType >
AnalysisType & getAnalysisID (AnalysisID PI, Function &F, bool *Changed=nullptr)
 

Static Public Attributes

static char ID = 0
 

Additional Inherited Members

- Static Public Member Functions inherited from llvm::Pass
static const PassInfolookupPassInfo (const void *TI)
 
static const PassInfolookupPassInfo (StringRef Arg)
 
static PasscreatePass (AnalysisID ID)
 
- Protected Member Functions inherited from llvm::MachineFunctionPass
 MachineFunctionPass (char &ID)
 
virtual MachineFunctionProperties getSetProperties () const
 
virtual MachineFunctionProperties getClearedProperties () const
 
- Protected Member Functions inherited from llvm::FunctionPass
bool skipFunction (const Function &F) const
 Optional passes call this function to check whether the pass should be skipped. More...
 

Detailed Description

This class provides the reaching def analysis.

Definition at line 69 of file ReachingDefAnalysis.h.

Constructor & Destructor Documentation

◆ ReachingDefAnalysis()

llvm::ReachingDefAnalysis::ReachingDefAnalysis ( )
inline

Member Function Documentation

◆ collectKilledOperands()

void ReachingDefAnalysis::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 644 of file ReachingDefAnalysis.cpp.

References llvm::RegState::Dead, llvm::tgtok::Def, getGlobalUses(), getMIOperand(), IsDead, isValidRegDef(), isValidRegUse(), mayHaveSideEffects(), MI, llvm::set_is_subset(), and Uses.

Referenced by if().

◆ getAnalysisUsage()

void llvm::ReachingDefAnalysis::getAnalysisUsage ( AnalysisUsage AU) const
inlineoverridevirtual

getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.

For MachineFunctionPasses, calling AU.preservesCFG() indicates that the pass does not modify the MachineBasicBlock CFG.

Reimplemented from llvm::MachineFunctionPass.

Definition at line 118 of file ReachingDefAnalysis.h.

References llvm::MachineFunctionPass::getAnalysisUsage(), and llvm::AnalysisUsage::setPreservesAll().

◆ getClearance()

int ReachingDefAnalysis::getClearance ( MachineInstr MI,
MCRegister  PhysReg 
) const

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

Definition at line 314 of file ReachingDefAnalysis.cpp.

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

◆ getGlobalReachingDefs()

void ReachingDefAnalysis::getGlobalReachingDefs ( MachineInstr MI,
MCRegister  PhysReg,
InstSet Defs 
) const

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

Definition at line 395 of file ReachingDefAnalysis.cpp.

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

Referenced by producesFalseLanesZero().

◆ getGlobalUses()

void ReachingDefAnalysis::getGlobalUses ( MachineInstr MI,
MCRegister  PhysReg,
InstSet Uses 
) const

◆ getLiveInUses()

bool ReachingDefAnalysis::getLiveInUses ( MachineBasicBlock MBB,
MCRegister  PhysReg,
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 350 of file ReachingDefAnalysis.cpp.

References llvm::MachineBasicBlock::end(), llvm::MachineBasicBlock::getLastNonDebugInstr(), getReachingDef(), llvm::MachineBasicBlock::instr_begin(), llvm::MachineBasicBlock::instr_end(), llvm::instructionsWithoutDebug(), isReachingDefLiveOut(), isValidRegUseOf(), MBB, MI, and Uses.

Referenced by getGlobalUses().

◆ getLiveOuts() [1/2]

void ReachingDefAnalysis::getLiveOuts ( MachineBasicBlock MBB,
MCRegister  PhysReg,
InstSet Defs 
) const

Definition at line 407 of file ReachingDefAnalysis.cpp.

References getLiveOuts(), and MBB.

◆ getLiveOuts() [2/2]

void ReachingDefAnalysis::getLiveOuts ( MachineBasicBlock MBB,
MCRegister  PhysReg,
InstSet Defs,
BlockSet VisitedBBs 
) const

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

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

Definition at line 413 of file ReachingDefAnalysis.cpp.

References llvm::LivePhysRegs::addLiveOuts(), llvm::LivePhysRegs::contains(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::tgtok::Def, getLocalLiveOutMIDef(), llvm::SmallPtrSetImpl< PtrType >::insert(), MBB, and llvm::MachineBasicBlock::predecessors().

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

◆ getLocalLiveOutMIDef()

MachineInstr * ReachingDefAnalysis::getLocalLiveOutMIDef ( MachineBasicBlock MBB,
MCRegister  PhysReg 
) const

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

Definition at line 522 of file ReachingDefAnalysis.cpp.

References llvm::LivePhysRegs::addLiveOuts(), llvm::LivePhysRegs::contains(), llvm::tgtok::Def, llvm::MachineBasicBlock::end(), llvm::MachineBasicBlock::getLastNonDebugInstr(), getReachingDef(), isValidRegDefOf(), and MBB.

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

◆ getMIOperand() [1/2]

MachineInstr * ReachingDefAnalysis::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 459 of file ReachingDefAnalysis.cpp.

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

◆ getMIOperand() [2/2]

MachineInstr * ReachingDefAnalysis::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 453 of file ReachingDefAnalysis.cpp.

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

Referenced by collectKilledOperands().

◆ getReachingDef()

int ReachingDefAnalysis::getReachingDef ( MachineInstr MI,
MCRegister  PhysReg 
) const

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

Definition at line 257 of file ReachingDefAnalysis.cpp.

References assert(), llvm::tgtok::Def, llvm::max(), and MI.

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

◆ getReachingLocalUses()

void ReachingDefAnalysis::getReachingLocalUses ( MachineInstr MI,
MCRegister  PhysReg,
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 325 of file ReachingDefAnalysis.cpp.

References llvm::tgtok::Def, llvm::MachineBasicBlock::end(), isValidRegUseOf(), MBB, MI, and Uses.

Referenced by getGlobalUses().

◆ getRequiredProperties()

MachineFunctionProperties llvm::ReachingDefAnalysis::getRequiredProperties ( ) const
inlineoverridevirtual

◆ getUniqueReachingMIDef()

MachineInstr * ReachingDefAnalysis::getUniqueReachingMIDef ( MachineInstr MI,
MCRegister  PhysReg 
) const

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

Otherwise return null.

Definition at line 433 of file ReachingDefAnalysis.cpp.

References llvm::SmallPtrSetImpl< PtrType >::begin(), getLiveOuts(), MI, llvm::MachineBasicBlock::predecessors(), and llvm::SmallPtrSetImplBase::size().

Referenced by getGlobalReachingDefs(), and getMIOperand().

◆ hasLocalDefBefore()

bool ReachingDefAnalysis::hasLocalDefBefore ( MachineInstr MI,
MCRegister  PhysReg 
) const

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

Definition at line 320 of file ReachingDefAnalysis.cpp.

References getReachingDef(), and MI.

◆ hasSameReachingDef()

bool ReachingDefAnalysis::hasSameReachingDef ( MachineInstr A,
MachineInstr B,
MCRegister  PhysReg 
) const

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

Definition at line 285 of file ReachingDefAnalysis.cpp.

References B, and getReachingDef().

◆ init()

void ReachingDefAnalysis::init ( )

◆ isReachingDefLiveOut()

bool ReachingDefAnalysis::isReachingDefLiveOut ( MachineInstr MI,
MCRegister  PhysReg 
) const

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

Definition at line 500 of file ReachingDefAnalysis.cpp.

References llvm::LivePhysRegs::addLiveOuts(), llvm::LivePhysRegs::contains(), llvm::tgtok::Def, llvm::MachineBasicBlock::end(), llvm::MachineBasicBlock::getLastNonDebugInstr(), getReachingDef(), isValidRegDefOf(), MBB, and MI.

Referenced by getLiveInUses().

◆ isRegDefinedAfter()

bool ReachingDefAnalysis::isRegDefinedAfter ( MachineInstr MI,
MCRegister  PhysReg 
) const

Return whether the given register is defined after MI.

Definition at line 486 of file ReachingDefAnalysis.cpp.

References llvm::tgtok::Def, llvm::MachineBasicBlock::end(), llvm::MachineBasicBlock::getLastNonDebugInstr(), getLocalLiveOutMIDef(), getReachingDef(), MBB, and MI.

Referenced by isSafeToDefRegAt().

◆ isRegUsedAfter()

bool ReachingDefAnalysis::isRegUsedAfter ( MachineInstr MI,
MCRegister  PhysReg 
) const

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

Definition at line 465 of file ReachingDefAnalysis.cpp.

References llvm::LivePhysRegs::addLiveOuts(), llvm::LivePhysRegs::contains(), llvm::MachineBasicBlock::instr_rbegin(), llvm::MachineBasicBlock::instr_rend(), llvm::instructionsWithoutDebug(), MBB, MI, and llvm::LivePhysRegs::stepBackward().

Referenced by isSafeToDefRegAt().

◆ isSafeToDefRegAt() [1/2]

bool ReachingDefAnalysis::isSafeToDefRegAt ( MachineInstr MI,
MCRegister  PhysReg 
) const

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

Definition at line 676 of file ReachingDefAnalysis.cpp.

References Ignore, and MI.

◆ isSafeToDefRegAt() [2/2]

bool ReachingDefAnalysis::isSafeToDefRegAt ( MachineInstr MI,
MCRegister  PhysReg,
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 682 of file ReachingDefAnalysis.cpp.

References llvm::tgtok::Def, E, llvm::MachineBasicBlock::end(), getGlobalUses(), I, Ignore, isRegDefinedAfter(), isRegUsedAfter(), isValidRegDefOf(), MBB, MI, llvm::set_is_subset(), and Uses.

◆ isSafeToMoveBackwards()

bool ReachingDefAnalysis::isSafeToMoveBackwards ( MachineInstr From,
MachineInstr To 
) const

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

Definition at line 590 of file ReachingDefAnalysis.cpp.

References E, From, and I.

◆ isSafeToMoveForwards()

bool ReachingDefAnalysis::isSafeToMoveForwards ( MachineInstr From,
MachineInstr To 
) const

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

Definition at line 580 of file ReachingDefAnalysis.cpp.

References E, From, and I.

◆ isSafeToRemove() [1/2]

bool ReachingDefAnalysis::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 600 of file ReachingDefAnalysis.cpp.

References Ignore, MI, and ToRemove.

Referenced by isSafeToRemove().

◆ isSafeToRemove() [2/2]

bool ReachingDefAnalysis::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 608 of file ReachingDefAnalysis.cpp.

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

◆ releaseMemory()

void ReachingDefAnalysis::releaseMemory ( )
overridevirtual

releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memory when it is no longer needed.

The default behavior of passes is to hold onto memory for the entire duration of their lifetime (which is the entire compile time). For pipelined passes, this is not a big deal because that memory gets recycled every time the pass is invoked on another program unit. For IP passes, it is more important to free memory when it is unused.

Optionally implement this function to release pass memory when it is no longer used.

Reimplemented from llvm::Pass.

Definition at line 216 of file ReachingDefAnalysis.cpp.

References llvm::SmallVectorImpl< T >::clear().

Referenced by reset().

◆ reset()

void ReachingDefAnalysis::reset ( )

Re-run the analysis.

Definition at line 224 of file ReachingDefAnalysis.cpp.

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

◆ runOnMachineFunction()

bool ReachingDefAnalysis::runOnMachineFunction ( MachineFunction MF)
overridevirtual

runOnMachineFunction - This method must be overloaded to perform the desired machine code transformation or analysis.

Implements llvm::MachineFunctionPass.

Definition at line 207 of file ReachingDefAnalysis.cpp.

References llvm::dbgs(), llvm::TargetSubtargetInfo::getRegisterInfo(), llvm::MachineFunction::getSubtarget(), init(), LLVM_DEBUG, and traverse().

◆ traverse()

void ReachingDefAnalysis::traverse ( )

Traverse the machine function, mapping definitions.

Definition at line 239 of file ReachingDefAnalysis.cpp.

References assert(), and llvm::tgtok::Def.

Referenced by reset(), and runOnMachineFunction().

Member Data Documentation

◆ ID

char ReachingDefAnalysis::ID = 0
static

Definition at line 111 of file ReachingDefAnalysis.h.


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