}
SpecializationInfo &S = Specializations.back().second;
- S.Gain += getSpecializationBonus(A, C);
+ S.Gain += getSpecializationBonus(A, C, Solver.getLoopInfo(*F));
S.Args.push_back({A, C});
}
Added = false;
}
InstructionCost getUserBonus(User *U, llvm::TargetTransformInfo &TTI,
- LoopInfo &LI) {
+ const LoopInfo &LI) {
auto *I = dyn_cast_or_null<Instruction>(U);
// If not an instruction we do not know how to evaluate.
// Keep minimum possible cost for now so that it doesnt affect
}
/// Compute a bonus for replacing argument \p A with constant \p C.
- InstructionCost getSpecializationBonus(Argument *A, Constant *C) {
+ InstructionCost getSpecializationBonus(Argument *A, Constant *C,
+ const LoopInfo &LI) {
Function *F = A->getParent();
- DominatorTree DT(*F);
- LoopInfo LI(DT);
auto &TTI = (GetTTI)(*F);
LLVM_DEBUG(dbgs() << "FnSpecialization: Analysing bonus for constant: "
<< C->getNameOrAsOperand() << "\n");
#include "llvm/Transforms/IPO/SCCP.h"
#include "llvm/Analysis/AssumptionCache.h"
+#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/PostDominators.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
DominatorTree &DT = FAM.getResult<DominatorTreeAnalysis>(F);
return {
std::make_unique<PredicateInfo>(F, DT, FAM.getResult<AssumptionAnalysis>(F)),
- &DT, FAM.getCachedResult<PostDominatorTreeAnalysis>(F)};
+ &DT, FAM.getCachedResult<PostDominatorTreeAnalysis>(F),
+ nullptr};
};
if (!runIPSCCP(M, DL, GetTLI, getAnalysis))
F, DT,
this->getAnalysis<AssumptionCacheTracker>().getAssumptionCache(
F)),
- nullptr, // We cannot preserve the DT or PDT with the legacy pass
- nullptr}; // manager, so set them to nullptr.
+ nullptr, // We cannot preserve the LI, DT or PDT with the legacy pass
+ nullptr, // manager, so set them to nullptr.
+ nullptr};
};
return runIPSCCP(M, DL, GetTLI, getAnalysis);
DominatorTree &DT = FAM.getResult<DominatorTreeAnalysis>(F);
return {std::make_unique<PredicateInfo>(
F, DT, FAM.getResult<AssumptionAnalysis>(F)),
- &DT, FAM.getCachedResult<PostDominatorTreeAnalysis>(F)};
+ &DT, FAM.getCachedResult<PostDominatorTreeAnalysis>(F),
+ &FAM.getResult<LoopAnalysis>(F)};
};
if (!runFunctionSpecialization(M, DL, GetTLI, GetTTI, GetAC, GetAnalysis))
F, DT,
this->getAnalysis<AssumptionCacheTracker>().getAssumptionCache(
F)),
- nullptr, // We cannot preserve the DT or PDT with the legacy pass
- nullptr}; // manager, so set them to nullptr.
+ nullptr, // We cannot preserve the LI, DT, or PDT with the legacy pass
+ nullptr, // manager, so set them to nullptr.
+ nullptr};
};
return runFunctionSpecialization(M, DL, GetTLI, GetTTI, GetAC, GetAnalysis);
}
return A->second.PredInfo->getPredicateInfoFor(I);
}
+ const LoopInfo &getLoopInfo(Function &F) {
+ auto A = AnalysisResults.find(&F);
+ assert(A != AnalysisResults.end() && A->second.LI &&
+ "Need LoopInfo analysis results for function.");
+ return *A->second.LI;
+ }
+
DomTreeUpdater getDTU(Function &F) {
auto A = AnalysisResults.find(&F);
assert(A != AnalysisResults.end() && "Need analysis results for function.");
return Visitor->getPredicateInfoFor(I);
}
+const LoopInfo &SCCPSolver::getLoopInfo(Function &F) {
+ return Visitor->getLoopInfo(F);
+}
+
DomTreeUpdater SCCPSolver::getDTU(Function &F) { return Visitor->getDTU(F); }
void SCCPSolver::trackValueOfGlobalVariable(GlobalVariable *GV) {