37#define DEBUG_TYPE "sccp"
39STATISTIC(NumInstRemoved,
"Number of instructions removed");
40STATISTIC(NumArgsElimed ,
"Number of arguments constant propagated");
41STATISTIC(NumGlobalConst,
"Number of globals found to be constant");
42STATISTIC(NumDeadBlocks ,
"Number of basic blocks unreachable");
44 "Number of instructions replaced with (simpler) instruction");
56 <<
"Can't zap returns of the function : " <<
F.getName()
57 <<
" due to present musttail or \"clang.arc.attachedcall\" call of "
65 if (isa<Instruction>(U) &&
66 !Solver.isBlockExecutable(cast<Instruction>(U)->getParent()))
72 if (!isa<CallBase>(U))
74 if (U->getType()->isStructTy()) {
75 return none_of(Solver.getStructLatticeValueFor(U),
76 SCCPSolver::isOverdefined);
82 if (
II->isAssumeLikeIntrinsic())
88 "We can only zap functions where all live users have a concrete value");
91 if (
CallInst *CI = BB.getTerminatingMustTailCall()) {
92 LLVM_DEBUG(
dbgs() <<
"Can't zap return of the block due to present "
93 <<
"musttail call : " << *CI <<
"\n");
100 ReturnsToZap.push_back(RI);
111 bool IsFuncSpecEnabled) {
119 if (
F.isDeclaration())
149 G.removeDeadConstantUsers();
157 if (IsFuncSpecEnabled) {
159 for (
unsigned Iters = 0; Iters < MaxIters && Specializer.
run(); ++Iters)
165 bool MadeChanges =
false;
167 if (
F.isDeclaration())
180 bool ReplacedPointerArg =
false;
183 ReplacedPointerArg |= Arg.getType()->isPointerTy();
190 if (ReplacedPointerArg) {
200 return AL.addFnAttribute(
205 F.setAttributes(UpdateAttrs(
F.getAttributes()));
206 for (
User *U :
F.users()) {
208 if (!CB || CB->getCalledFunction() != &
F)
211 CB->setAttributes(UpdateAttrs(CB->getAttributes()));
214 MadeChanges |= ReplacedPointerArg;
225 if (&BB != &
F.front())
231 BB, InsertedValues, NumInstRemoved, NumInstReplaced);
236 DomTreeUpdater DTU(DT, PDT, DomTreeUpdater::UpdateStrategy::Lazy);
254 if (!DeadBB->hasAddressTaken())
255 DTU.deleteBB(DeadBB);
275 assert(!
F->getReturnType()->isVoidTy() &&
276 "should not track void functions");
278 ReturnValue.isUnknownOrUndef())
283 assert(
F->getReturnType()->isStructTy() &&
284 "The return type should be a struct");
293 Function *
F = RI->getParent()->getParent();
304 AttributeFuncs::getUBImplyingAttributes();
307 F->removeParamAttr(
A.getArgNo(), Attribute::Returned);
308 F->removeRetAttrs(UBImplyingAttributes);
309 for (
Use &U :
F->uses()) {
313 all_of(U.getUser()->users(), [](
const User *UserUser) {
314 return cast<IntrinsicInst>(UserUser)->isAssumeLikeIntrinsic();
333 <<
"' is constant!\n");
338 "Only Store|Load Instruction can be user of GlobalVariable at "
343 I->eraseFromParent();
349 GV->getDebugInfo(GVEs);
350 if (GVEs.
size() == 1) {
353 DIB, *GV->getInitializer(), *GV->getValueType()))
354 GVEs[0]->replaceOperandWith(1, InitExpr);
358 M.eraseGlobalVariable(GV);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static void findReturnsToZap(Function &F, SmallVector< ReturnInst *, 8 > &ReturnsToZap, SCCPSolver &Solver)
static bool runIPSCCP(Module &M, const DataLayout &DL, FunctionAnalysisManager *FAM, std::function< const TargetLibraryInfo &(Function &)> GetTLI, std::function< TargetTransformInfo &(Function &)> GetTTI, std::function< AssumptionCache &(Function &)> GetAC, std::function< DominatorTree &(Function &)> GetDT, std::function< BlockFrequencyInfo &(Function &)> GetBFI, bool IsFuncSpecEnabled)
uint64_t IntrinsicInst * II
FunctionAnalysisManager FAM
This file implements a set that has insertion order iteration characteristics.
#define STATISTIC(VARNAME, DESC)
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
This class represents an incoming formal argument to a Function.
A function analysis which provides an AssumptionCache.
A cache of @llvm.assume calls within a function.
This class stores enough information to efficiently remove some attributes from an existing AttrBuild...
static LLVM_ABI Attribute getWithMemoryEffects(LLVMContext &Context, MemoryEffects ME)
LLVM Basic Block Representation.
Analysis pass which computes BlockFrequencyInfo.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Removes the attribute from the given argument.
void removeRetAttrs(const AttributeMask &AttrsToRemove)
Removes the attributes from the return value.
iterator_range< User::op_iterator > args()
Iteration adapter for range-for loops.
unsigned getArgOperandNo(const Use *U) const
Given a use for a arg operand, get the arg operand number that corresponds to it.
This class represents a function call, abstracting a target machine's calling convention.
A parsed version of the target data layout string in and methods for querying it.
Analysis pass which computes a DominatorTree.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
LLVM_ABI bool run()
Attempt to specialize functions in the module to enable constant propagation across function boundari...
bool isDeadFunction(Function *F)
bool isFuncSpecEnabled() const
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
ModRefInfo getModRef(Location Loc) const
Get ModRefInfo for the given Location.
static MemoryEffectsBase unknown()
A Module instance is used to store all the information related to an LLVM module.
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Analysis pass which computes a PostDominatorTree.
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
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.
PreservedAnalyses & preserve()
Mark an analysis as preserved.
Return a value (possibly void), from a function.
SCCPSolver - This interface class is a general purpose solver for Sparse Conditional Constant Propaga...
LLVM_ABI void trackValueOfGlobalVariable(GlobalVariable *GV)
trackValueOfGlobalVariable - Clients can use this method to inform the SCCPSolver that it should trac...
LLVM_ABI bool tryToReplaceWithConstant(Value *V)
LLVM_ABI void inferArgAttributes() const
LLVM_ABI bool isStructLatticeConstant(Function *F, StructType *STy)
LLVM_ABI void addPredicateInfo(Function &F, DominatorTree &DT, AssumptionCache &AC)
LLVM_ABI void trackValueOfArgument(Argument *V)
trackValueOfArgument - Mark the specified argument overdefined unless it have range attribute.
LLVM_ABI const DenseMap< GlobalVariable *, ValueLatticeElement > & getTrackedGlobals() const
getTrackedGlobals - Get and return the set of inferred initializers for global variables.
LLVM_ABI void addTrackedFunction(Function *F)
addTrackedFunction - If the SCCP solver is supposed to track calls into and out of the specified func...
LLVM_ABI void solveWhileResolvedUndefsIn(Module &M)
LLVM_ABI const SmallPtrSet< Function *, 16 > & getMRVFunctionsTracked() const
getMRVFunctionsTracked - Get the set of functions which return multiple values tracked by the pass.
LLVM_ABI void addArgumentTrackedFunction(Function *F)
static LLVM_ABI bool isReplaceableConstant(const ValueLatticeElement &LV)
LLVM_ABI bool simplifyInstsInBlock(BasicBlock &BB, SmallPtrSetImpl< Value * > &InsertedValues, Statistic &InstRemovedStat, Statistic &InstReplacedStat)
LLVM_ABI const ValueLatticeElement & getLatticeValueFor(Value *V) const
LLVM_ABI bool removeNonFeasibleEdges(BasicBlock *BB, DomTreeUpdater &DTU, BasicBlock *&NewUnreachableBB) const
LLVM_ABI bool isBlockExecutable(BasicBlock *BB) const
LLVM_ABI void inferReturnAttributes() const
LLVM_ABI bool markBlockExecutable(BasicBlock *BB)
markBlockExecutable - This method can be used by clients to mark all of the blocks that are known to ...
LLVM_ABI const MapVector< Function *, ValueLatticeElement > & getTrackedRetVals() const
getTrackedRetVals - Get the inferred return value map.
LLVM_ABI bool mustPreserveReturn(Function *F)
Returns true if the return of the given function cannot be modified.
static LLVM_ABI bool isOverdefined(const ValueLatticeElement &LV)
LLVM_ABI bool isArgumentTrackedFunction(Function *F)
Returns true if the given function is in the solver's set of argument-tracked functions.
LLVM_ABI void removeSSACopies(Function &F)
bool insert(const value_type &X)
Insert a new element into the SetVector.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
A SetVector that performs no allocations if smaller than a certain size.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Class to represent struct types.
Analysis pass providing the TargetTransformInfo.
Analysis pass providing the TargetLibraryInfo.
Provides information about what library functions are available for the current target.
A Use represents the edge between a Value definition and its users.
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy
Provide the FunctionAnalysisManager to Module proxy.
MemoryEffectsBase< IRMemLocation > MemoryEffects
Summary of how a function affects memory in the program.
const IPOOptions & getIPOOptions(const LLVMContext &C)
LLVM_ABI bool canTrackGlobalVariableInterprocedurally(GlobalVariable *GV)
Determine if the value maintained in the given global variable can be tracked interprocedurally.
LLVM_ABI DIExpression * getExpressionForConstant(DIBuilder &DIB, const Constant &C, Type &Ty)
Given a constant, create a debug information expression.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI unsigned changeToUnreachable(Instruction *I, bool PreserveLCSSA=false, DomTreeUpdater *DTU=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Insert an unreachable instruction before the specified instruction, making it and the rest of the cod...
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
@ ArgMem
Access to memory via argument pointers.
LLVM_ABI bool canTrackReturnsInterprocedurally(Function *F)
Determine if the values of the given function's returns can be tracked interprocedurally.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
LLVM_ABI bool canTrackArgumentsInterprocedurally(Function *F)
Determine if the values of the given function's arguments can be tracked interprocedurally.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.