[polly] r248916 - Move remapping functionality in the ScopExpander

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 30 09:52:04 PDT 2015


Author: jdoerfert
Date: Wed Sep 30 11:52:03 2015
New Revision: 248916

URL: http://llvm.org/viewvc/llvm-project?rev=248916&view=rev
Log:
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.

Modified:
    polly/trunk/include/polly/CodeGen/BlockGenerators.h
    polly/trunk/include/polly/Support/ScopHelper.h
    polly/trunk/lib/CodeGen/BlockGenerators.cpp
    polly/trunk/lib/Support/ScopHelper.cpp

Modified: polly/trunk/include/polly/CodeGen/BlockGenerators.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/CodeGen/BlockGenerators.h?rev=248916&r1=248915&r2=248916&view=diff
==============================================================================
--- polly/trunk/include/polly/CodeGen/BlockGenerators.h (original)
+++ polly/trunk/include/polly/CodeGen/BlockGenerators.h Wed Sep 30 11:52:03 2015
@@ -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 <vector>
 
 struct isl_ast_build;
 struct isl_id_to_ast_expr;
@@ -37,9 +37,6 @@ class ScopStmt;
 class MemoryAccess;
 class IslExprBuilder;
 
-typedef DenseMap<const Value *, Value *> ValueMapT;
-typedef std::vector<ValueMapT> 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

Modified: polly/trunk/include/polly/Support/ScopHelper.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/Support/ScopHelper.h?rev=248916&r1=248915&r2=248916&view=diff
==============================================================================
--- polly/trunk/include/polly/Support/ScopHelper.h (original)
+++ polly/trunk/include/polly/Support/ScopHelper.h Wed Sep 30 11:52:03 2015
@@ -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<const llvm::Value *, llvm::Value *> ValueMapT;
+typedef llvm::SmallVector<ValueMapT, 8> VectorValueMapT;
+
 /// Temporary Hack for extended regiontree.
 ///
 /// @brief Cast the region to loop.
@@ -99,7 +107,7 @@ void splitEntryBlockForAlloca(llvm::Basi
 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.
 ///

Modified: polly/trunk/lib/CodeGen/BlockGenerators.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/BlockGenerators.cpp?rev=248916&r1=248915&r2=248916&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/BlockGenerators.cpp (original)
+++ polly/trunk/lib/CodeGen/BlockGenerators.cpp Wed Sep 30 11:52:03 2015
@@ -110,7 +110,6 @@ Value *BlockGenerator::trySynthesizeNewV
         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::trySynthesizeNewV
 
         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;

Modified: polly/trunk/lib/Support/ScopHelper.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Support/ScopHelper.cpp?rev=248916&r1=248915&r2=248916&view=diff
==============================================================================
--- polly/trunk/lib/Support/ScopHelper.cpp (original)
+++ polly/trunk/lib/Support/ScopHelper.cpp Wed Sep 30 11:52:03 2015
@@ -235,8 +235,9 @@ struct ScopExpander : SCEVVisitor<ScopEx
   friend struct SCEVVisitor<ScopExpander, const SCEV *>;
 
   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<Instruction>(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);
 }
 




More information about the llvm-commits mailing list