LLVM 17.0.0git
|
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 | addAnalysis (Function &F, AnalysisResultsForFn A) |
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 PredicateBase * | getPredicateInfoFor (Instruction *I) |
const LoopInfo & | getLoopInfo (Function &F) |
DomTreeUpdater | getDTU (Function &F) |
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. | |
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) |
bool | isBlockExecutable (BasicBlock *BB) const |
bool | isEdgeFeasible (BasicBlock *From, BasicBlock *To) const |
std::vector< ValueLatticeElement > | getStructLatticeValueFor (Value *V) const |
void | removeLatticeValueFor (Value *V) |
const ValueLatticeElement & | getLatticeValueFor (Value *V) const |
const MapVector< Function *, ValueLatticeElement > & | getTrackedRetVals () |
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. | |
bool | isStructLatticeConstant (Function *F, StructType *STy) |
Constant * | getConstant (const ValueLatticeElement &LV) const |
Helper to return a Constant if LV is either a constant or a constant range with a single element. | |
SmallPtrSetImpl< Function * > & | getArgumentTrackedFunctions () |
Return a reference to the set of argument tracked functions. | |
void | markArgInFuncSpecialization (Function *F, const SmallVectorImpl< ArgInfo > &Args) |
Mark the constant arguments of a new function specialization. | |
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 |
bool | tryToReplaceWithConstant (Value *V) |
Static Public Member Functions | |
static bool | isConstant (const ValueLatticeElement &LV) |
static bool | isOverdefined (const ValueLatticeElement &LV) |
SCCPSolver - This interface class is a general purpose solver for Sparse Conditional Constant Propagation (SCCP).
Definition at line 75 of file SCCPSolver.h.
SCCPSolver::SCCPSolver | ( | const DataLayout & | DL, |
std::function< const TargetLibraryInfo &(Function &)> | GetTLI, | ||
LLVMContext & | Ctx | ||
) |
Definition at line 1838 of file SCCPSolver.cpp.
|
default |
void SCCPSolver::addAnalysis | ( | Function & | F, |
AnalysisResultsForFn | A | ||
) |
void SCCPSolver::addArgumentTrackedFunction | ( | Function * | F | ) |
void SCCPSolver::addToMustPreserveReturnsInFunctions | ( | Function * | F | ) |
Add function to the list of functions whose return cannot be modified.
Definition at line 1872 of file SCCPSolver.cpp.
References F.
Referenced by tryToReplaceWithConstant().
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 1868 of file SCCPSolver.cpp.
References F.
Referenced by runIPSCCP().
SmallPtrSetImpl< Function * > & SCCPSolver::getArgumentTrackedFunctions | ( | ) |
Return a reference to the set of argument tracked functions.
Definition at line 1948 of file SCCPSolver.cpp.
Constant * SCCPSolver::getConstant | ( | const ValueLatticeElement & | LV | ) | const |
Helper to return a Constant if LV
is either a constant or a constant range with a single element.
Definition at line 1944 of file SCCPSolver.cpp.
Referenced by tryToReplaceWithConstant().
DomTreeUpdater SCCPSolver::getDTU | ( | Function & | F | ) |
const ValueLatticeElement & SCCPSolver::getLatticeValueFor | ( | Value * | V | ) | const |
Definition at line 1920 of file SCCPSolver.cpp.
Referenced by findReturnsToZap(), llvm::refineInstruction(), llvm::replaceSignedInst(), and tryToReplaceWithConstant().
Definition at line 1858 of file SCCPSolver.cpp.
References F.
const SmallPtrSet< Function *, 16 > SCCPSolver::getMRVFunctionsTracked | ( | ) |
getMRVFunctionsTracked - Get the set of functions which return multiple values tracked by the pass.
Definition at line 1934 of file SCCPSolver.cpp.
Referenced by runIPSCCP().
const PredicateBase * SCCPSolver::getPredicateInfoFor | ( | Instruction * | I | ) |
std::vector< ValueLatticeElement > SCCPSolver::getStructLatticeValueFor | ( | Value * | V | ) | const |
Definition at line 1912 of file SCCPSolver.cpp.
Referenced by tryToReplaceWithConstant().
const DenseMap< GlobalVariable *, ValueLatticeElement > & SCCPSolver::getTrackedGlobals | ( | ) |
getTrackedGlobals - Get and return the set of inferred initializers for global variables.
Definition at line 1930 of file SCCPSolver.cpp.
Referenced by runIPSCCP().
const MapVector< Function *, ValueLatticeElement > & SCCPSolver::getTrackedRetVals | ( | ) |
getTrackedRetVals - Get the inferred return value map.
Definition at line 1925 of file SCCPSolver.cpp.
Referenced by runIPSCCP().
Returns true if the given function is in the solver's set of argument-tracked functions.
Definition at line 1884 of file SCCPSolver.cpp.
References F.
Referenced by findReturnsToZap().
bool SCCPSolver::isBlockExecutable | ( | BasicBlock * | BB | ) | const |
Definition at line 1903 of file SCCPSolver.cpp.
Referenced by runIPSCCP(), and runSCCP().
|
static |
Definition at line 54 of file SCCPSolver.cpp.
References llvm::ValueLatticeElement::getConstantRange(), llvm::ValueLatticeElement::isConstant(), llvm::ValueLatticeElement::isConstantRange(), and llvm::ConstantRange::isSingleElement().
Referenced by isOverdefined(), llvm::SCCPInstVisitor::isStructLatticeConstant(), runIPSCCP(), and tryToReplaceWithConstant().
bool SCCPSolver::isEdgeFeasible | ( | BasicBlock * | From, |
BasicBlock * | To | ||
) | const |
Definition at line 1907 of file SCCPSolver.cpp.
References From.
Referenced by removeNonFeasibleEdges().
|
static |
Definition at line 59 of file SCCPSolver.cpp.
References isConstant(), and llvm::ValueLatticeElement::isUnknownOrUndef().
Referenced by findReturnsToZap(), runIPSCCP(), and tryToReplaceWithConstant().
bool SCCPSolver::isStructLatticeConstant | ( | Function * | F, |
StructType * | STy | ||
) |
void SCCPSolver::markArgInFuncSpecialization | ( | Function * | F, |
const SmallVectorImpl< ArgInfo > & | Args | ||
) |
Mark the constant arguments of a new function specialization.
F
points to the cloned function and Args
contains a list of constant arguments represented as pairs of {formal,actual} values (the formal argument is associated with the original function definition). All other arguments of the specialization inherit the lattice state of their corresponding values in the original function.
Definition at line 1952 of file SCCPSolver.cpp.
References F.
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 1850 of file SCCPSolver.cpp.
Referenced by runIPSCCP(), and runSCCP().
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 1957 of file SCCPSolver.cpp.
References F.
void SCCPSolver::markOverdefined | ( | Value * | V | ) |
markOverdefined - Mark the specified value overdefined.
This works with both scalars and structs.
Definition at line 1938 of file SCCPSolver.cpp.
Referenced by runIPSCCP(), and runSCCP().
Returns true if the return of the given function cannot be modified.
Definition at line 1876 of file SCCPSolver.cpp.
References F.
Referenced by findReturnsToZap().
void SCCPSolver::removeLatticeValueFor | ( | Value * | V | ) |
Definition at line 1916 of file SCCPSolver.cpp.
Referenced by llvm::replaceSignedInst().
bool llvm::SCCPSolver::removeNonFeasibleEdges | ( | BasicBlock * | BB, |
DomTreeUpdater & | DTU, | ||
BasicBlock *& | NewUnreachableBB | ||
) | const |
Definition at line 254 of file SCCPSolver.cpp.
References llvm::DomTreeUpdater::applyUpdatesPermissive(), assert(), llvm::SmallPtrSetImpl< PtrType >::begin(), llvm::SmallPtrSetImpl< PtrType >::contains(), llvm::BranchInst::Create(), llvm::BasicBlock::Create(), llvm::DominatorTreeBase< BasicBlock, false >::Delete, llvm::Instruction::eraseFromParent(), llvm::BasicBlock::getContext(), llvm::BasicBlock::getParent(), llvm::BasicBlock::getTerminator(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::DominatorTreeBase< BasicBlock, false >::Insert, isEdgeFeasible(), llvm_unreachable, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::BasicBlock::removePredecessor(), SI, llvm::SmallPtrSetImplBase::size(), and llvm::successors().
Referenced by runIPSCCP(), and runSCCP().
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 1890 of file SCCPSolver.cpp.
References F.
Referenced by runSCCP().
bool llvm::SCCPSolver::simplifyInstsInBlock | ( | BasicBlock & | BB, |
SmallPtrSetImpl< Value * > & | InsertedValues, | ||
Statistic & | InstRemovedStat, | ||
Statistic & | InstReplacedStat | ||
) |
Definition at line 230 of file SCCPSolver.cpp.
References llvm::canRemoveInstruction(), llvm::make_early_inc_range(), llvm::refineInstruction(), llvm::replaceSignedInst(), and tryToReplaceWithConstant().
Referenced by runIPSCCP(), and runSCCP().
void SCCPSolver::solve | ( | ) |
Solve - Solve for constants and executable blocks.
Definition at line 1888 of file SCCPSolver.cpp.
Referenced by runSCCP().
void SCCPSolver::solveWhileResolvedUndefsIn | ( | Module & | M | ) |
Definition at line 1894 of file SCCPSolver.cpp.
Referenced by llvm::FunctionSpecializer::run(), and runIPSCCP().
void SCCPSolver::solveWhileResolvedUndefsIn | ( | SmallVectorImpl< Function * > & | WorkList | ) |
Definition at line 1899 of file SCCPSolver.cpp.
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 1864 of file SCCPSolver.cpp.
Referenced by runIPSCCP().
Definition at line 75 of file SCCPSolver.cpp.
References addToMustPreserveReturnsInFunctions(), llvm::any_of(), assert(), llvm::canRemoveInstruction(), llvm::dbgs(), F, llvm::ConstantStruct::get(), llvm::UndefValue::get(), llvm::CallBase::getCalledFunction(), getConstant(), getLatticeValueFor(), llvm::CallBase::getOperandBundle(), getStructLatticeValueFor(), isConstant(), llvm::CallBase::isMustTailCall(), isOverdefined(), IV, LLVM_DEBUG, and llvm::LLVMContext::OB_clang_arc_attachedcall.
Referenced by runIPSCCP(), and simplifyInstsInBlock().
void SCCPSolver::visit | ( | Instruction * | I | ) |
Definition at line 1961 of file SCCPSolver.cpp.
References I.
void SCCPSolver::visitCall | ( | CallInst & | I | ) |
Definition at line 1963 of file SCCPSolver.cpp.
References I.