From c0729a3216dfcb230d44f72155f458fba6702ce5 Mon Sep 17 00:00:00 2001 From: Johannes Doerfert Date: Wed, 30 Sep 2015 16:52:03 +0000 Subject: [PATCH] Move remapping functionality in the ScopExpander Because we handle more than SCEV does it is not possible to rewrite an expression on the top-level using the SCEVParameterRewriter only. With this patch we will do the rewriting on demand only and also recursively, thus not only on the top-level. llvm-svn: 248916 --- polly/include/polly/CodeGen/BlockGenerators.h | 5 +---- polly/include/polly/Support/ScopHelper.h | 10 +++++++++- polly/lib/CodeGen/BlockGenerators.cpp | 5 ++--- polly/lib/Support/ScopHelper.cpp | 16 ++++++++++++---- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/polly/include/polly/CodeGen/BlockGenerators.h b/polly/include/polly/CodeGen/BlockGenerators.h index 0b6885761a5d..77375ea3e8d5 100644 --- a/polly/include/polly/CodeGen/BlockGenerators.h +++ b/polly/include/polly/CodeGen/BlockGenerators.h @@ -17,10 +17,10 @@ #define POLLY_BLOCK_GENERATORS_H #include "polly/CodeGen/IRBuilder.h" +#include "polly/Support/ScopHelper.h" #include "llvm/ADT/DenseMap.h" #include "llvm/Analysis/ScalarEvolutionExpressions.h" #include "isl/map.h" -#include struct isl_ast_build; struct isl_id_to_ast_expr; @@ -37,9 +37,6 @@ class ScopStmt; class MemoryAccess; class IslExprBuilder; -typedef DenseMap ValueMapT; -typedef std::vector VectorValueMapT; - /// @brief Check whether a value an be synthesized by the code generator. /// /// Some value will be recalculated only from information that is code generated diff --git a/polly/include/polly/Support/ScopHelper.h b/polly/include/polly/Support/ScopHelper.h index 01e0857417bd..a698ace07517 100644 --- a/polly/include/polly/Support/ScopHelper.h +++ b/polly/include/polly/Support/ScopHelper.h @@ -14,6 +14,11 @@ #ifndef POLLY_SUPPORT_IRHELPER_H #define POLLY_SUPPORT_IRHELPER_H +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/Analysis/AliasAnalysis.h" + namespace llvm { class Type; class Instruction; @@ -36,6 +41,9 @@ class ScalarEvolution; namespace polly { class Scop; +typedef llvm::DenseMap ValueMapT; +typedef llvm::SmallVector VectorValueMapT; + /// Temporary Hack for extended regiontree. /// /// @brief Cast the region to loop. @@ -99,7 +107,7 @@ void splitEntryBlockForAlloca(llvm::BasicBlock *EntryBlock, llvm::Pass *P); llvm::Value *expandCodeFor(Scop &S, llvm::ScalarEvolution &SE, const llvm::DataLayout &DL, const char *Name, const llvm::SCEV *E, llvm::Type *Ty, - llvm::Instruction *IP); + llvm::Instruction *IP, ValueMapT *VMap = nullptr); /// @brief Check if the block is a error block. /// diff --git a/polly/lib/CodeGen/BlockGenerators.cpp b/polly/lib/CodeGen/BlockGenerators.cpp index 94163c3c4bce..5cec72c7652b 100644 --- a/polly/lib/CodeGen/BlockGenerators.cpp +++ b/polly/lib/CodeGen/BlockGenerators.cpp @@ -110,7 +110,6 @@ Value *BlockGenerator::trySynthesizeNewValue(ScopStmt &Stmt, const Value *Old, ValueToValueMap VTV; VTV.insert(BBMap.begin(), BBMap.end()); VTV.insert(GlobalMap.begin(), GlobalMap.end()); - NewScev = SCEVParameterRewriter::rewrite(NewScev, SE, VTV); Scop &S = *Stmt.getParent(); const DataLayout &DL = @@ -119,8 +118,8 @@ Value *BlockGenerator::trySynthesizeNewValue(ScopStmt &Stmt, const Value *Old, assert(IP != Builder.GetInsertBlock()->end() && "Only instructions can be insert points for SCEVExpander"); - Value *Expanded = - expandCodeFor(S, SE, DL, "polly", NewScev, Old->getType(), IP); + Value *Expanded = expandCodeFor(S, SE, DL, "polly", NewScev, + Old->getType(), IP, &VTV); BBMap[Old] = Expanded; return Expanded; diff --git a/polly/lib/Support/ScopHelper.cpp b/polly/lib/Support/ScopHelper.cpp index c55a4749314c..70c1f13047e7 100644 --- a/polly/lib/Support/ScopHelper.cpp +++ b/polly/lib/Support/ScopHelper.cpp @@ -235,8 +235,9 @@ struct ScopExpander : SCEVVisitor { friend struct SCEVVisitor; explicit ScopExpander(const Region &R, ScalarEvolution &SE, - const DataLayout &DL, const char *Name) - : Expander(SCEVExpander(SE, DL, Name)), SE(SE), Name(Name), R(R) {} + const DataLayout &DL, const char *Name, ValueMapT *VMap) + : Expander(SCEVExpander(SE, DL, Name)), SE(SE), Name(Name), R(R), + VMap(VMap) {} Value *expandCodeFor(const SCEV *E, Type *Ty, Instruction *I) { // If we generate code in the region we will immediately fall back to the @@ -252,8 +253,15 @@ private: ScalarEvolution &SE; const char *Name; const Region &R; + ValueMapT *VMap; const SCEV *visitUnknown(const SCEVUnknown *E) { + + // If a value mapping was given try if the underlying value is remapped. + if (VMap) + if (Value *NewVal = VMap->lookup(E->getValue())) + return visit(SE.getSCEV(NewVal)); + Instruction *Inst = dyn_cast(E->getValue()); if (!Inst || (Inst->getOpcode() != Instruction::SRem && Inst->getOpcode() != Instruction::SDiv)) @@ -327,8 +335,8 @@ private: Value *polly::expandCodeFor(Scop &S, ScalarEvolution &SE, const DataLayout &DL, const char *Name, const SCEV *E, Type *Ty, - Instruction *IP) { - ScopExpander Expander(S.getRegion(), SE, DL, Name); + Instruction *IP, ValueMapT *VMap) { + ScopExpander Expander(S.getRegion(), SE, DL, Name, VMap); return Expander.expandCodeFor(E, Ty, IP); }