Revert "Remove references to AssumptionCache. NFC."
The AssumptionCache removal of r289756 has been reverted in
r290086/r290087. A different solution has been implemented in r291671
which keeps the AssumptionCache. We can therefore use it again in Polly.
This reverts r289791.
llvm-svn: 298089
diff --git a/polly/lib/Analysis/ScopInfo.cpp b/polly/lib/Analysis/ScopInfo.cpp
index dc80dc1..49c086f 100644
--- a/polly/lib/Analysis/ScopInfo.cpp
+++ b/polly/lib/Analysis/ScopInfo.cpp
@@ -29,10 +29,10 @@
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
-#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Analysis/AliasAnalysis.h"
+#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/Loads.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/LoopIterator.h"
@@ -1946,82 +1946,76 @@
return DT.dominates(BB, getEntry());
}
-void Scop::addUserAssumptions(DominatorTree &DT, LoopInfo &LI) {
+void Scop::addUserAssumptions(AssumptionCache &AC, DominatorTree &DT,
+ LoopInfo &LI) {
auto &F = getFunction();
-
- // TODO: Walk the DominatorTree from getRegion().getExit() to its root in
- // order to not iterate over blocks we skip anyways.
- for (auto &BB : F) {
- bool InScop = contains(&BB);
- if (!InScop && !isDominatedBy(DT, &BB))
+ for (auto &Assumption : AC.assumptions()) {
+ auto *CI = dyn_cast_or_null<CallInst>(Assumption);
+ if (!CI || CI->getNumArgOperands() != 1)
continue;
- for (auto &Assumption : BB) {
- auto *CI = dyn_cast_or_null<IntrinsicInst>(&Assumption);
- if (!CI || CI->getNumArgOperands() != 1 ||
- CI->getIntrinsicID() != Intrinsic::assume)
- continue;
+ bool InScop = contains(CI);
+ if (!InScop && !isDominatedBy(DT, CI->getParent()))
+ continue;
- auto *L = LI.getLoopFor(CI->getParent());
- auto *Val = CI->getArgOperand(0);
- ParameterSetTy DetectedParams;
- if (!isAffineConstraint(Val, &R, L, *SE, DetectedParams)) {
- emitOptimizationRemarkAnalysis(F.getContext(), DEBUG_TYPE, F,
- CI->getDebugLoc(),
- "Non-affine user assumption ignored.");
- continue;
- }
-
- // Collect all newly introduced parameters.
- ParameterSetTy NewParams;
- for (auto *Param : DetectedParams) {
- Param = extractConstantFactor(Param, *SE).second;
- Param = getRepresentingInvariantLoadSCEV(Param);
- if (Parameters.count(Param))
- continue;
- NewParams.insert(Param);
- }
-
- SmallVector<isl_set *, 2> ConditionSets;
- auto *TI = InScop ? CI->getParent()->getTerminator() : nullptr;
- auto &Stmt = InScop ? *getStmtFor(CI->getParent()) : *Stmts.begin();
- auto *Dom = InScop ? getDomainConditions(&Stmt) : isl_set_copy(Context);
- bool Valid = buildConditionSets(Stmt, Val, TI, L, Dom, ConditionSets);
- isl_set_free(Dom);
-
- if (!Valid)
- continue;
-
- isl_set *AssumptionCtx = nullptr;
- if (InScop) {
- AssumptionCtx = isl_set_complement(isl_set_params(ConditionSets[1]));
- isl_set_free(ConditionSets[0]);
- } else {
- AssumptionCtx = isl_set_complement(ConditionSets[1]);
- AssumptionCtx = isl_set_intersect(AssumptionCtx, ConditionSets[0]);
- }
-
- // Project out newly introduced parameters as they are not otherwise
- // useful.
- if (!NewParams.empty()) {
- for (unsigned u = 0; u < isl_set_n_param(AssumptionCtx); u++) {
- auto *Id = isl_set_get_dim_id(AssumptionCtx, isl_dim_param, u);
- auto *Param = static_cast<const SCEV *>(isl_id_get_user(Id));
- isl_id_free(Id);
-
- if (!NewParams.count(Param))
- continue;
-
- AssumptionCtx =
- isl_set_project_out(AssumptionCtx, isl_dim_param, u--, 1);
- }
- }
-
- emitOptimizationRemarkAnalysis(
- F.getContext(), DEBUG_TYPE, F, CI->getDebugLoc(),
- "Use user assumption: " + stringFromIslObj(AssumptionCtx));
- Context = isl_set_intersect(Context, AssumptionCtx);
+ auto *L = LI.getLoopFor(CI->getParent());
+ auto *Val = CI->getArgOperand(0);
+ ParameterSetTy DetectedParams;
+ if (!isAffineConstraint(Val, &R, L, *SE, DetectedParams)) {
+ emitOptimizationRemarkAnalysis(F.getContext(), DEBUG_TYPE, F,
+ CI->getDebugLoc(),
+ "Non-affine user assumption ignored.");
+ continue;
}
+
+ // Collect all newly introduced parameters.
+ ParameterSetTy NewParams;
+ for (auto *Param : DetectedParams) {
+ Param = extractConstantFactor(Param, *SE).second;
+ Param = getRepresentingInvariantLoadSCEV(Param);
+ if (Parameters.count(Param))
+ continue;
+ NewParams.insert(Param);
+ }
+
+ SmallVector<isl_set *, 2> ConditionSets;
+ auto *TI = InScop ? CI->getParent()->getTerminator() : nullptr;
+ auto &Stmt = InScop ? *getStmtFor(CI->getParent()) : *Stmts.begin();
+ auto *Dom = InScop ? getDomainConditions(&Stmt) : isl_set_copy(Context);
+ bool Valid = buildConditionSets(Stmt, Val, TI, L, Dom, ConditionSets);
+ isl_set_free(Dom);
+
+ if (!Valid)
+ continue;
+
+ isl_set *AssumptionCtx = nullptr;
+ if (InScop) {
+ AssumptionCtx = isl_set_complement(isl_set_params(ConditionSets[1]));
+ isl_set_free(ConditionSets[0]);
+ } else {
+ AssumptionCtx = isl_set_complement(ConditionSets[1]);
+ AssumptionCtx = isl_set_intersect(AssumptionCtx, ConditionSets[0]);
+ }
+
+ // Project out newly introduced parameters as they are not otherwise useful.
+ if (!NewParams.empty()) {
+ for (unsigned u = 0; u < isl_set_n_param(AssumptionCtx); u++) {
+ auto *Id = isl_set_get_dim_id(AssumptionCtx, isl_dim_param, u);
+ auto *Param = static_cast<const SCEV *>(isl_id_get_user(Id));
+ isl_id_free(Id);
+
+ if (!NewParams.count(Param))
+ continue;
+
+ AssumptionCtx =
+ isl_set_project_out(AssumptionCtx, isl_dim_param, u--, 1);
+ }
+ }
+
+ emitOptimizationRemarkAnalysis(
+ F.getContext(), DEBUG_TYPE, F, CI->getDebugLoc(),
+ "Use user assumption: " + stringFromIslObj(AssumptionCtx));
+ Context = isl_set_intersect(Context, AssumptionCtx);
}
}
@@ -3363,13 +3357,14 @@
assumeNoOutOfBounds();
}
-void Scop::init(AliasAnalysis &AA, DominatorTree &DT, LoopInfo &LI) {
+void Scop::init(AliasAnalysis &AA, AssumptionCache &AC, DominatorTree &DT,
+ LoopInfo &LI) {
buildInvariantEquivalenceClasses();
if (!buildDomains(&R, DT, LI))
return;
- addUserAssumptions(DT, LI);
+ addUserAssumptions(AC, DT, LI);
// Remove empty statements.
// Exit early in case there are no executable statements left in this scop.
@@ -4649,6 +4644,7 @@
AU.addRequiredTransitive<ScalarEvolutionWrapperPass>();
AU.addRequiredTransitive<ScopDetection>();
AU.addRequired<AAResultsWrapperPass>();
+ AU.addRequired<AssumptionCacheTracker>();
AU.setPreservesAll();
}
@@ -4683,8 +4679,9 @@
auto &AA = getAnalysis<AAResultsWrapperPass>().getAAResults();
auto const &DL = F->getParent()->getDataLayout();
auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
+ auto &AC = getAnalysis<AssumptionCacheTracker>().getAssumptionCache(*F);
- ScopBuilder SB(R, AA, DL, DT, LI, SD, SE);
+ ScopBuilder SB(R, AC, AA, DL, DT, LI, SD, SE);
S = SB.getScop(); // take ownership of scop object
if (S) {
@@ -4711,6 +4708,7 @@
"Polly - Create polyhedral description of Scops", false,
false);
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass);
+INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker);
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass);
INITIALIZE_PASS_DEPENDENCY(RegionInfoPass);
INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass);
@@ -4728,6 +4726,7 @@
AU.addRequiredTransitive<ScalarEvolutionWrapperPass>();
AU.addRequiredTransitive<ScopDetection>();
AU.addRequired<AAResultsWrapperPass>();
+ AU.addRequired<AssumptionCacheTracker>();
AU.setPreservesAll();
}
@@ -4739,6 +4738,7 @@
auto &AA = getAnalysis<AAResultsWrapperPass>().getAAResults();
auto const &DL = F.getParent()->getDataLayout();
auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
+ auto &AC = getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
/// Create polyhedral descripton of scops for all the valid regions of a
/// function.
@@ -4747,7 +4747,7 @@
if (!SD.isMaxRegionInScop(*R))
continue;
- ScopBuilder SB(R, AA, DL, DT, LI, SD, SE);
+ ScopBuilder SB(R, AC, AA, DL, DT, LI, SD, SE);
std::unique_ptr<Scop> S = SB.getScop();
if (!S)
continue;
@@ -4779,6 +4779,7 @@
"Polly - Create polyhedral description of all Scops of a function", false,
false);
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass);
+INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker);
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass);
INITIALIZE_PASS_DEPENDENCY(RegionInfoPass);
INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass);