summaryrefslogtreecommitdiffstats
path: root/polly/lib/Support
diff options
context:
space:
mode:
Diffstat (limited to 'polly/lib/Support')
-rw-r--r--polly/lib/Support/SCEVValidator.cpp25
-rw-r--r--polly/lib/Support/ScopHelper.cpp23
2 files changed, 36 insertions, 12 deletions
diff --git a/polly/lib/Support/SCEVValidator.cpp b/polly/lib/Support/SCEVValidator.cpp
index 85bda185ec3..9b3ce1860d5 100644
--- a/polly/lib/Support/SCEVValidator.cpp
+++ b/polly/lib/Support/SCEVValidator.cpp
@@ -8,6 +8,7 @@
#include <vector>
using namespace llvm;
+using namespace polly;
#define DEBUG_TYPE "polly-scev-validator"
@@ -125,10 +126,12 @@ private:
const Region *R;
ScalarEvolution &SE;
const Value *BaseAddress;
+ InvariantLoadsSetTy *ILS;
public:
- SCEVValidator(const Region *R, ScalarEvolution &SE, const Value *BaseAddress)
- : R(R), SE(SE), BaseAddress(BaseAddress) {}
+ SCEVValidator(const Region *R, ScalarEvolution &SE, const Value *BaseAddress,
+ InvariantLoadsSetTy *ILS)
+ : R(R), SE(SE), BaseAddress(BaseAddress), ILS(ILS) {}
class ValidatorResult visitConstant(const SCEVConstant *Constant) {
return ValidatorResult(SCEVType::INT);
@@ -335,6 +338,15 @@ public:
return ValidatorResult(SCEVType::PARAM, S);
}
+ ValidatorResult visitLoadInstruction(Instruction *I, const SCEV *S) {
+ if (R->contains(I) && ILS) {
+ ILS->insert(cast<LoadInst>(I));
+ return ValidatorResult(SCEVType::PARAM, S);
+ }
+
+ return visitGenericInst(I, S);
+ }
+
ValidatorResult visitSDivInstruction(Instruction *SDiv, const SCEV *S) {
assert(SDiv->getOpcode() == Instruction::SDiv &&
"Assumed SDiv instruction!");
@@ -391,6 +403,8 @@ public:
if (Instruction *I = dyn_cast<Instruction>(Expr->getValue())) {
switch (I->getOpcode()) {
+ case Instruction::Load:
+ return visitLoadInstruction(I, Expr);
case Instruction::SDiv:
return visitSDivInstruction(I, Expr);
case Instruction::SRem:
@@ -550,11 +564,11 @@ bool hasScalarDepsInsideRegion(const SCEV *Expr, const Region *R) {
}
bool isAffineExpr(const Region *R, const SCEV *Expr, ScalarEvolution &SE,
- const Value *BaseAddress) {
+ const Value *BaseAddress, InvariantLoadsSetTy *ILS) {
if (isa<SCEVCouldNotCompute>(Expr))
return false;
- SCEVValidator Validator(R, SE, BaseAddress);
+ SCEVValidator Validator(R, SE, BaseAddress, ILS);
DEBUG({
dbgs() << "\n";
dbgs() << "Expr: " << *Expr << "\n";
@@ -580,7 +594,8 @@ std::vector<const SCEV *> getParamsInAffineExpr(const Region *R,
if (isa<SCEVCouldNotCompute>(Expr))
return std::vector<const SCEV *>();
- SCEVValidator Validator(R, SE, BaseAddress);
+ InvariantLoadsSetTy ILS;
+ SCEVValidator Validator(R, SE, BaseAddress, &ILS);
ValidatorResult Result = Validator.visit(Expr);
assert(Result.isValid() && "Requested parameters for an invalid SCEV!");
diff --git a/polly/lib/Support/ScopHelper.cpp b/polly/lib/Support/ScopHelper.cpp
index cc41d4812f7..d2123bd69eb 100644
--- a/polly/lib/Support/ScopHelper.cpp
+++ b/polly/lib/Support/ScopHelper.cpp
@@ -14,7 +14,6 @@
#include "polly/Support/ScopHelper.h"
#include "polly/Options.h"
#include "polly/ScopInfo.h"
-#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/RegionInfo.h"
#include "llvm/Analysis/ScalarEvolution.h"
@@ -240,8 +239,6 @@ void polly::splitEntryBlockForAlloca(BasicBlock *EntryBlock, Pass *P) {
struct ScopExpander : SCEVVisitor<ScopExpander, const SCEV *> {
friend struct SCEVVisitor<ScopExpander, const SCEV *>;
- typedef llvm::DenseMap<const llvm::Value *, llvm::Value *> ValueMapT;
-
explicit ScopExpander(const Region &R, ScalarEvolution &SE,
const DataLayout &DL, const char *Name, ValueMapT *VMap)
: Expander(SCEVExpander(SE, DL, Name)), SE(SE), Name(Name), R(R),
@@ -342,10 +339,9 @@ private:
///}
};
-Value *
-polly::expandCodeFor(Scop &S, ScalarEvolution &SE, const DataLayout &DL,
- const char *Name, const SCEV *E, Type *Ty, Instruction *IP,
- llvm::DenseMap<const llvm::Value *, llvm::Value *> *VMap) {
+Value *polly::expandCodeFor(Scop &S, ScalarEvolution &SE, const DataLayout &DL,
+ const char *Name, const SCEV *E, Type *Ty,
+ Instruction *IP, ValueMapT *VMap) {
ScopExpander Expander(S.getRegion(), SE, DL, Name, VMap);
return Expander.expandCodeFor(E, Ty, IP);
}
@@ -383,3 +379,16 @@ Value *polly::getConditionFromTerminator(TerminatorInst *TI) {
return nullptr;
}
+
+bool polly::isHoistableLoad(LoadInst *LInst, Region &R, LoopInfo &LI,
+ ScalarEvolution &SE) {
+ Loop *L = LI.getLoopFor(LInst->getParent());
+ const SCEV *PtrSCEV = SE.getSCEVAtScope(LInst->getPointerOperand(), L);
+ while (L && R.contains(L)) {
+ if (!SE.isLoopInvariant(PtrSCEV, L))
+ return false;
+ L = L->getParentLoop();
+ }
+
+ return true;
+}
OpenPOWER on IntegriCloud