[polly] r248893 - BlockGenerator: Extract value synthesis into its own function [NFC]

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 30 04:56:19 PDT 2015


Author: grosser
Date: Wed Sep 30 06:56:19 2015
New Revision: 248893

URL: http://llvm.org/viewvc/llvm-project?rev=248893&view=rev
Log:
BlockGenerator: Extract value synthesis into its own function [NFC]

This will allow us to reuse this code in a subsequent commit.

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

Modified: polly/trunk/include/polly/CodeGen/BlockGenerators.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/CodeGen/BlockGenerators.h?rev=248893&r1=248892&r2=248893&view=diff
==============================================================================
--- polly/trunk/include/polly/CodeGen/BlockGenerators.h (original)
+++ polly/trunk/include/polly/CodeGen/BlockGenerators.h Wed Sep 30 06:56:19 2015
@@ -404,6 +404,31 @@ protected:
   /// the original value in the non-optimized SCoP.
   void createScalarFinalization(Region &R);
 
+  /// @brief Try to synthesize a new value
+  ///
+  /// Given an old value, we try to synthesize it in a new context from its
+  /// original SCEV expression. We start from the original SCEV expression,
+  /// then replace outdated parameter and loop references, and finally
+  /// expand it to code that computes this updated expression.
+  ///
+  /// @param Stmt      The statement to code generate
+  /// @param Old       The old Value
+  /// @param BBMap     A mapping from old values to their new values
+  ///                  (for values recalculated within this basic block)
+  /// @param LTS       A mapping from loops virtual canonical induction
+  ///                  variable to their new values
+  ///                  (for values recalculated in the new ScoP, but not
+  ///                   within this basic block)
+  /// @param L         The loop that surrounded the instruction that referenced
+  ///                  this value in the original code. This loop is used to
+  ///                  evaluate the scalar evolution at the right scope.
+  ///
+  /// @returns  o A newly synthesized value.
+  ///           o NULL, if synthesizing the value failed.
+  Value *trySynthesizeNewValue(ScopStmt &Stmt, const Value *Old,
+                               ValueMapT &BBMap, LoopToScevMapT &LTS,
+                               Loop *L) const;
+
   /// @brief Get the new version of a value.
   ///
   /// Given an old value, we first check if a new version of this value is

Modified: polly/trunk/lib/CodeGen/BlockGenerators.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/BlockGenerators.cpp?rev=248893&r1=248892&r2=248893&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/BlockGenerators.cpp (original)
+++ polly/trunk/lib/CodeGen/BlockGenerators.cpp Wed Sep 30 06:56:19 2015
@@ -99,27 +99,10 @@ BlockGenerator::BlockGenerator(PollyIRBu
       EntryBB(nullptr), PHIOpMap(PHIOpMap), ScalarMap(ScalarMap),
       EscapeMap(EscapeMap), GlobalMap(GlobalMap) {}
 
-Value *BlockGenerator::getNewValue(ScopStmt &Stmt, const Value *Old,
-                                   ValueMapT &BBMap, LoopToScevMapT &LTS,
-                                   Loop *L) const {
-  // We assume constants never change.
-  // This avoids map lookups for many calls to this function.
-  if (isa<Constant>(Old))
-    return const_cast<Value *>(Old);
-
-  if (Value *New = GlobalMap.lookup(Old)) {
-    if (Value *NewRemapped = GlobalMap.lookup(New))
-      New = NewRemapped;
-    if (Old->getType()->getScalarSizeInBits() <
-        New->getType()->getScalarSizeInBits())
-      New = Builder.CreateTruncOrBitCast(New, Old->getType());
-
-    return New;
-  }
-
-  if (Value *New = BBMap.lookup(Old))
-    return New;
-
+Value *BlockGenerator::trySynthesizeNewValue(ScopStmt &Stmt, const Value *Old,
+                                             ValueMapT &BBMap,
+                                             LoopToScevMapT &LTS,
+                                             Loop *L) const {
   if (SE.isSCEVable(Old->getType()))
     if (const SCEV *Scev = SE.getSCEVAtScope(const_cast<Value *>(Old), L)) {
       if (!isa<SCEVCouldNotCompute>(Scev)) {
@@ -144,6 +127,33 @@ Value *BlockGenerator::getNewValue(ScopS
       }
     }
 
+  return nullptr;
+}
+
+Value *BlockGenerator::getNewValue(ScopStmt &Stmt, const Value *Old,
+                                   ValueMapT &BBMap, LoopToScevMapT &LTS,
+                                   Loop *L) const {
+  // We assume constants never change.
+  // This avoids map lookups for many calls to this function.
+  if (isa<Constant>(Old))
+    return const_cast<Value *>(Old);
+
+  if (Value *New = GlobalMap.lookup(Old)) {
+    if (Value *NewRemapped = GlobalMap.lookup(New))
+      New = NewRemapped;
+    if (Old->getType()->getScalarSizeInBits() <
+        New->getType()->getScalarSizeInBits())
+      New = Builder.CreateTruncOrBitCast(New, Old->getType());
+
+    return New;
+  }
+
+  if (Value *New = BBMap.lookup(Old))
+    return New;
+
+  if (Value *New = trySynthesizeNewValue(Stmt, Old, BBMap, LTS, L))
+    return New;
+
   // A scop-constant value defined by a global or a function parameter.
   if (isa<GlobalValue>(Old) || isa<Argument>(Old))
     return const_cast<Value *>(Old);




More information about the llvm-commits mailing list