File indexing completed on 2026-05-10 08:44:44
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_TRANSFORMS_UTILS_SCCPSOLVER_H
0015 #define LLVM_TRANSFORMS_UTILS_SCCPSOLVER_H
0016
0017 #include "llvm/ADT/MapVector.h"
0018 #include "llvm/ADT/SmallPtrSet.h"
0019 #include "llvm/ADT/Statistic.h"
0020 #include "llvm/Analysis/DomTreeUpdater.h"
0021 #include "llvm/Transforms/Utils/PredicateInfo.h"
0022 #include <vector>
0023
0024 namespace llvm {
0025 class Argument;
0026 class BasicBlock;
0027 class CallInst;
0028 class Constant;
0029 class DataLayout;
0030 class DominatorTree;
0031 class Function;
0032 class GlobalVariable;
0033 class Instruction;
0034 class LLVMContext;
0035 class StructType;
0036 class TargetLibraryInfo;
0037 class Value;
0038 class ValueLatticeElement;
0039
0040
0041 struct ArgInfo {
0042 Argument *Formal;
0043 Constant *Actual;
0044
0045 ArgInfo(Argument *F, Constant *A) : Formal(F), Actual(A) {}
0046
0047 bool operator==(const ArgInfo &Other) const {
0048 return Formal == Other.Formal && Actual == Other.Actual;
0049 }
0050
0051 bool operator!=(const ArgInfo &Other) const { return !(*this == Other); }
0052
0053 friend hash_code hash_value(const ArgInfo &A) {
0054 return hash_combine(hash_value(A.Formal), hash_value(A.Actual));
0055 }
0056 };
0057
0058 class SCCPInstVisitor;
0059
0060
0061
0062
0063
0064
0065 class SCCPSolver {
0066 std::unique_ptr<SCCPInstVisitor> Visitor;
0067
0068 public:
0069 SCCPSolver(const DataLayout &DL,
0070 std::function<const TargetLibraryInfo &(Function &)> GetTLI,
0071 LLVMContext &Ctx);
0072
0073 ~SCCPSolver();
0074
0075 void addPredicateInfo(Function &F, DominatorTree &DT, AssumptionCache &AC);
0076
0077
0078
0079
0080 bool markBlockExecutable(BasicBlock *BB);
0081
0082 const PredicateBase *getPredicateInfoFor(Instruction *I);
0083
0084
0085
0086
0087
0088 void trackValueOfGlobalVariable(GlobalVariable *GV);
0089
0090
0091
0092
0093 void addTrackedFunction(Function *F);
0094
0095
0096 void addToMustPreserveReturnsInFunctions(Function *F);
0097
0098
0099 bool mustPreserveReturn(Function *F);
0100
0101 void addArgumentTrackedFunction(Function *F);
0102
0103
0104
0105 bool isArgumentTrackedFunction(Function *F);
0106
0107 const SmallPtrSetImpl<Function *> &getArgumentTrackedFunctions() const;
0108
0109
0110 void solve();
0111
0112
0113
0114
0115
0116
0117 bool resolvedUndefsIn(Function &F);
0118
0119 void solveWhileResolvedUndefsIn(Module &M);
0120
0121 void solveWhileResolvedUndefsIn(SmallVectorImpl<Function *> &WorkList);
0122
0123 void solveWhileResolvedUndefs();
0124
0125 bool isBlockExecutable(BasicBlock *BB) const;
0126
0127
0128
0129 bool isEdgeFeasible(BasicBlock *From, BasicBlock *To) const;
0130
0131 std::vector<ValueLatticeElement> getStructLatticeValueFor(Value *V) const;
0132
0133 void removeLatticeValueFor(Value *V);
0134
0135
0136
0137 void resetLatticeValueFor(CallBase *Call);
0138
0139 const ValueLatticeElement &getLatticeValueFor(Value *V) const;
0140
0141
0142 const MapVector<Function *, ValueLatticeElement> &getTrackedRetVals() const;
0143
0144
0145
0146 const DenseMap<GlobalVariable *, ValueLatticeElement> &getTrackedGlobals();
0147
0148
0149
0150 const SmallPtrSet<Function *, 16> getMRVFunctionsTracked();
0151
0152
0153
0154 void markOverdefined(Value *V);
0155
0156
0157
0158 void trackValueOfArgument(Argument *V);
0159
0160
0161
0162
0163 bool isStructLatticeConstant(Function *F, StructType *STy);
0164
0165
0166
0167 Constant *getConstant(const ValueLatticeElement &LV, Type *Ty) const;
0168
0169
0170 Constant *getConstantOrNull(Value *V) const;
0171
0172
0173
0174
0175
0176 void setLatticeValueForSpecializationArguments(Function *F,
0177 const SmallVectorImpl<ArgInfo> &Args);
0178
0179
0180
0181
0182 void markFunctionUnreachable(Function *F);
0183
0184 void visit(Instruction *I);
0185 void visitCall(CallInst &I);
0186
0187 bool simplifyInstsInBlock(BasicBlock &BB,
0188 SmallPtrSetImpl<Value *> &InsertedValues,
0189 Statistic &InstRemovedStat,
0190 Statistic &InstReplacedStat);
0191
0192 bool removeNonFeasibleEdges(BasicBlock *BB, DomTreeUpdater &DTU,
0193 BasicBlock *&NewUnreachableBB) const;
0194
0195 void inferReturnAttributes() const;
0196 void inferArgAttributes() const;
0197
0198 bool tryToReplaceWithConstant(Value *V);
0199
0200
0201
0202
0203
0204 static bool isConstant(const ValueLatticeElement &LV);
0205
0206
0207
0208
0209
0210 static bool isOverdefined(const ValueLatticeElement &LV);
0211 };
0212 }
0213
0214 #endif