LLVM 20.0.0git
Public Member Functions | Static Public Member Functions | List of all members
llvm::SCCPSolver Class Reference

SCCPSolver - This interface class is a general purpose solver for Sparse Conditional Constant Propagation (SCCP). More...

#include "llvm/Transforms/Utils/SCCPSolver.h"

Public Member Functions

 SCCPSolver (const DataLayout &DL, std::function< const TargetLibraryInfo &(Function &)> GetTLI, LLVMContext &Ctx)
 
 ~SCCPSolver ()
 
void addPredicateInfo (Function &F, DominatorTree &DT, AssumptionCache &AC)
 
bool markBlockExecutable (BasicBlock *BB)
 markBlockExecutable - This method can be used by clients to mark all of the blocks that are known to be intrinsically live in the processed unit.
 
const PredicateBasegetPredicateInfoFor (Instruction *I)
 
void trackValueOfGlobalVariable (GlobalVariable *GV)
 trackValueOfGlobalVariable - Clients can use this method to inform the SCCPSolver that it should track loads and stores to the specified global variable if it can.
 
void addTrackedFunction (Function *F)
 addTrackedFunction - If the SCCP solver is supposed to track calls into and out of the specified function (which cannot have its address taken), this method must be called.
 
void addToMustPreserveReturnsInFunctions (Function *F)
 Add function to the list of functions whose return cannot be modified.
 
bool mustPreserveReturn (Function *F)
 Returns true if the return of the given function cannot be modified.
 
void addArgumentTrackedFunction (Function *F)
 
bool isArgumentTrackedFunction (Function *F)
 Returns true if the given function is in the solver's set of argument-tracked functions.
 
const SmallPtrSetImpl< Function * > & getArgumentTrackedFunctions () const
 
void solve ()
 Solve - Solve for constants and executable blocks.
 
bool resolvedUndefsIn (Function &F)
 resolvedUndefsIn - While solving the dataflow for a function, we assume that branches on undef values cannot reach any of their successors.
 
void solveWhileResolvedUndefsIn (Module &M)
 
void solveWhileResolvedUndefsIn (SmallVectorImpl< Function * > &WorkList)
 
void solveWhileResolvedUndefs ()
 
bool isBlockExecutable (BasicBlock *BB) const
 
bool isEdgeFeasible (BasicBlock *From, BasicBlock *To) const
 
std::vector< ValueLatticeElementgetStructLatticeValueFor (Value *V) const
 
void removeLatticeValueFor (Value *V)
 
void resetLatticeValueFor (CallBase *Call)
 Invalidate the Lattice Value of Call and its users after specializing the call.
 
const ValueLatticeElementgetLatticeValueFor (Value *V) const
 
const MapVector< Function *, ValueLatticeElement > & getTrackedRetVals () const
 getTrackedRetVals - Get the inferred return value map.
 
const DenseMap< GlobalVariable *, ValueLatticeElement > & getTrackedGlobals ()
 getTrackedGlobals - Get and return the set of inferred initializers for global variables.
 
const SmallPtrSet< Function *, 16 > getMRVFunctionsTracked ()
 getMRVFunctionsTracked - Get the set of functions which return multiple values tracked by the pass.
 
void markOverdefined (Value *V)
 markOverdefined - Mark the specified value overdefined.
 
void trackValueOfArgument (Argument *V)
 trackValueOfArgument - Mark the specified argument overdefined unless it have range attribute.
 
bool isStructLatticeConstant (Function *F, StructType *STy)
 
ConstantgetConstant (const ValueLatticeElement &LV, Type *Ty) const
 Helper to return a Constant if LV is either a constant or a constant range with a single element.
 
ConstantgetConstantOrNull (Value *V) const
 Return either a Constant or nullptr for a given Value.
 
void setLatticeValueForSpecializationArguments (Function *F, const SmallVectorImpl< ArgInfo > &Args)
 Set the Lattice Value for the arguments of a specialization F.
 
void markFunctionUnreachable (Function *F)
 Mark all of the blocks in function F non-executable.
 
void visit (Instruction *I)
 
void visitCall (CallInst &I)
 
bool simplifyInstsInBlock (BasicBlock &BB, SmallPtrSetImpl< Value * > &InsertedValues, Statistic &InstRemovedStat, Statistic &InstReplacedStat)
 
bool removeNonFeasibleEdges (BasicBlock *BB, DomTreeUpdater &DTU, BasicBlock *&NewUnreachableBB) const
 
void inferReturnAttributes () const
 
void inferArgAttributes () const
 
bool tryToReplaceWithConstant (Value *V)
 

Static Public Member Functions

static bool isConstant (const ValueLatticeElement &LV)
 
static bool isOverdefined (const ValueLatticeElement &LV)
 

Detailed Description

SCCPSolver - This interface class is a general purpose solver for Sparse Conditional Constant Propagation (SCCP).

Definition at line 65 of file SCCPSolver.h.

Constructor & Destructor Documentation

◆ SCCPSolver()

SCCPSolver::SCCPSolver ( const DataLayout DL,
std::function< const TargetLibraryInfo &(Function &)>  GetTLI,
LLVMContext Ctx 
)

Definition at line 2129 of file SCCPSolver.cpp.

◆ ~SCCPSolver()

SCCPSolver::~SCCPSolver ( )
default

Member Function Documentation

◆ addArgumentTrackedFunction()

void SCCPSolver::addArgumentTrackedFunction ( Function F)

Definition at line 2166 of file SCCPSolver.cpp.

References F.

Referenced by runIPSCCP().

◆ addPredicateInfo()

void SCCPSolver::addPredicateInfo ( Function F,
DominatorTree DT,
AssumptionCache AC 
)

Definition at line 2137 of file SCCPSolver.cpp.

References F.

Referenced by runIPSCCP().

◆ addToMustPreserveReturnsInFunctions()

void SCCPSolver::addToMustPreserveReturnsInFunctions ( Function F)

Add function to the list of functions whose return cannot be modified.

Definition at line 2158 of file SCCPSolver.cpp.

References F.

Referenced by tryToReplaceWithConstant().

◆ addTrackedFunction()

void SCCPSolver::addTrackedFunction ( Function F)

addTrackedFunction - If the SCCP solver is supposed to track calls into and out of the specified function (which cannot have its address taken), this method must be called.

Definition at line 2154 of file SCCPSolver.cpp.

References F.

Referenced by runIPSCCP(), and runSCCP().

◆ getArgumentTrackedFunctions()

const SmallPtrSetImpl< Function * > & SCCPSolver::getArgumentTrackedFunctions ( ) const

Definition at line 2175 of file SCCPSolver.cpp.

Referenced by inferArgAttributes().

◆ getConstant()

Constant * SCCPSolver::getConstant ( const ValueLatticeElement LV,
Type Ty 
) const

Helper to return a Constant if LV is either a constant or a constant range with a single element.

Definition at line 2247 of file SCCPSolver.cpp.

◆ getConstantOrNull()

Constant * SCCPSolver::getConstantOrNull ( Value V) const

Return either a Constant or nullptr for a given Value.

Definition at line 2252 of file SCCPSolver.cpp.

Referenced by tryToReplaceWithConstant().

◆ getLatticeValueFor()

const ValueLatticeElement & SCCPSolver::getLatticeValueFor ( Value V) const

◆ getMRVFunctionsTracked()

const SmallPtrSet< Function *, 16 > SCCPSolver::getMRVFunctionsTracked ( )

getMRVFunctionsTracked - Get the set of functions which return multiple values tracked by the pass.

Definition at line 2233 of file SCCPSolver.cpp.

Referenced by runIPSCCP().

◆ getPredicateInfoFor()

const PredicateBase * SCCPSolver::getPredicateInfoFor ( Instruction I)

Definition at line 2146 of file SCCPSolver.cpp.

References I.

Referenced by runIPSCCP().

◆ getStructLatticeValueFor()

std::vector< ValueLatticeElement > SCCPSolver::getStructLatticeValueFor ( Value V) const

Definition at line 2207 of file SCCPSolver.cpp.

◆ getTrackedGlobals()

const DenseMap< GlobalVariable *, ValueLatticeElement > & SCCPSolver::getTrackedGlobals ( )

getTrackedGlobals - Get and return the set of inferred initializers for global variables.

Definition at line 2229 of file SCCPSolver.cpp.

Referenced by runIPSCCP().

◆ getTrackedRetVals()

const MapVector< Function *, ValueLatticeElement > & SCCPSolver::getTrackedRetVals ( ) const

getTrackedRetVals - Get the inferred return value map.

Definition at line 2224 of file SCCPSolver.cpp.

Referenced by inferReturnAttributes(), llvm::FunctionSpecializer::run(), and runIPSCCP().

◆ inferArgAttributes()

void llvm::SCCPSolver::inferArgAttributes ( ) const

◆ inferReturnAttributes()

void llvm::SCCPSolver::inferReturnAttributes ( ) const

Definition at line 380 of file SCCPSolver.cpp.

References F, getTrackedRetVals(), llvm::inferAttribute(), and llvm::AttributeList::ReturnIndex.

Referenced by runIPSCCP(), and runSCCP().

◆ isArgumentTrackedFunction()

bool SCCPSolver::isArgumentTrackedFunction ( Function F)

Returns true if the given function is in the solver's set of argument-tracked functions.

Definition at line 2170 of file SCCPSolver.cpp.

References F.

Referenced by findReturnsToZap().

◆ isBlockExecutable()

bool SCCPSolver::isBlockExecutable ( BasicBlock BB) const

◆ isConstant()

bool llvm::SCCPSolver::isConstant ( const ValueLatticeElement LV)
static

◆ isEdgeFeasible()

bool SCCPSolver::isEdgeFeasible ( BasicBlock From,
BasicBlock To 
) const

Definition at line 2202 of file SCCPSolver.cpp.

References From.

Referenced by removeNonFeasibleEdges().

◆ isOverdefined()

bool llvm::SCCPSolver::isOverdefined ( const ValueLatticeElement LV)
static

◆ isStructLatticeConstant()

bool SCCPSolver::isStructLatticeConstant ( Function F,
StructType STy 
)

Definition at line 2243 of file SCCPSolver.cpp.

References F.

Referenced by llvm::FunctionSpecializer::run(), and runIPSCCP().

◆ markBlockExecutable()

bool SCCPSolver::markBlockExecutable ( BasicBlock BB)

markBlockExecutable - This method can be used by clients to mark all of the blocks that are known to be intrinsically live in the processed unit.

This returns true if the block was not considered live before.

Definition at line 2142 of file SCCPSolver.cpp.

Referenced by runIPSCCP(), and runSCCP().

◆ markFunctionUnreachable()

void SCCPSolver::markFunctionUnreachable ( Function F)

Mark all of the blocks in function F non-executable.

Clients can used this method to erase a function from the module (e.g., if it has been completely specialized and is no longer needed).

Definition at line 2261 of file SCCPSolver.cpp.

References F.

◆ markOverdefined()

void SCCPSolver::markOverdefined ( Value V)

markOverdefined - Mark the specified value overdefined.

This works with both scalars and structs.

Definition at line 2237 of file SCCPSolver.cpp.

◆ mustPreserveReturn()

bool SCCPSolver::mustPreserveReturn ( Function F)

Returns true if the return of the given function cannot be modified.

Definition at line 2162 of file SCCPSolver.cpp.

References F.

Referenced by findReturnsToZap().

◆ removeLatticeValueFor()

void SCCPSolver::removeLatticeValueFor ( Value V)

Definition at line 2211 of file SCCPSolver.cpp.

Referenced by llvm::replaceSignedInst().

◆ removeNonFeasibleEdges()

bool llvm::SCCPSolver::removeNonFeasibleEdges ( BasicBlock BB,
DomTreeUpdater DTU,
BasicBlock *&  NewUnreachableBB 
) const

◆ resetLatticeValueFor()

void SCCPSolver::resetLatticeValueFor ( CallBase Call)

Invalidate the Lattice Value of Call and its users after specializing the call.

Then recompute it.

Definition at line 2215 of file SCCPSolver.cpp.

Referenced by llvm::FunctionSpecializer::run().

◆ resolvedUndefsIn()

bool SCCPSolver::resolvedUndefsIn ( Function F)

resolvedUndefsIn - While solving the dataflow for a function, we assume that branches on undef values cannot reach any of their successors.

However, this is not a safe assumption. After we solve dataflow, this method should be use to handle this. If this returns true, the solver should be rerun.

Definition at line 2181 of file SCCPSolver.cpp.

References F.

Referenced by runSCCP().

◆ setLatticeValueForSpecializationArguments()

void SCCPSolver::setLatticeValueForSpecializationArguments ( Function F,
const SmallVectorImpl< ArgInfo > &  Args 
)

Set the Lattice Value for the arguments of a specialization F.

If an argument is Constant then its lattice value is marked with the corresponding actual argument in Args. Otherwise, its lattice value is inherited (copied) from the corresponding formal argument in Args.

Definition at line 2256 of file SCCPSolver.cpp.

References F.

◆ simplifyInstsInBlock()

bool llvm::SCCPSolver::simplifyInstsInBlock ( BasicBlock BB,
SmallPtrSetImpl< Value * > &  InsertedValues,
Statistic InstRemovedStat,
Statistic InstReplacedStat 
)

◆ solve()

void SCCPSolver::solve ( )

Solve - Solve for constants and executable blocks.

Definition at line 2179 of file SCCPSolver.cpp.

Referenced by runSCCP().

◆ solveWhileResolvedUndefs()

void SCCPSolver::solveWhileResolvedUndefs ( )

Definition at line 2194 of file SCCPSolver.cpp.

Referenced by llvm::FunctionSpecializer::run().

◆ solveWhileResolvedUndefsIn() [1/2]

void SCCPSolver::solveWhileResolvedUndefsIn ( Module M)

Definition at line 2185 of file SCCPSolver.cpp.

Referenced by llvm::FunctionSpecializer::run(), and runIPSCCP().

◆ solveWhileResolvedUndefsIn() [2/2]

void SCCPSolver::solveWhileResolvedUndefsIn ( SmallVectorImpl< Function * > &  WorkList)

Definition at line 2190 of file SCCPSolver.cpp.

◆ trackValueOfArgument()

void SCCPSolver::trackValueOfArgument ( Argument V)

trackValueOfArgument - Mark the specified argument overdefined unless it have range attribute.

This works with both scalars and structs.

Definition at line 2239 of file SCCPSolver.cpp.

Referenced by runIPSCCP(), and runSCCP().

◆ trackValueOfGlobalVariable()

void SCCPSolver::trackValueOfGlobalVariable ( GlobalVariable GV)

trackValueOfGlobalVariable - Clients can use this method to inform the SCCPSolver that it should track loads and stores to the specified global variable if it can.

This is only legal to call if performing Interprocedural SCCP.

Definition at line 2150 of file SCCPSolver.cpp.

Referenced by runIPSCCP().

◆ tryToReplaceWithConstant()

bool llvm::SCCPSolver::tryToReplaceWithConstant ( Value V)

◆ visit()

void SCCPSolver::visit ( Instruction I)

Definition at line 2265 of file SCCPSolver.cpp.

References I.

◆ visitCall()

void SCCPSolver::visitCall ( CallInst I)

Definition at line 2267 of file SCCPSolver.cpp.

References I.


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