[polly] r187114 - BlockGenerator: Split getNewValue.

Hongbin Zheng etherzhhb at gmail.com
Thu Jul 25 02:12:08 PDT 2013


Author: ether
Date: Thu Jul 25 04:12:07 2013
New Revision: 187114

URL: http://llvm.org/viewvc/llvm-project?rev=187114&view=rev
Log:
BlockGenerator: Split getNewValue.

Split the old getNewValue into two parts:

1. The function "lookupAvailableValue" that return the new version of
the instruction which is already available.

2. The function calls "lookupAvailableValue", and tries to generate
the new version if it is not available yet.

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=187114&r1=187113&r2=187114&view=diff
==============================================================================
--- polly/trunk/include/polly/CodeGen/BlockGenerators.h (original)
+++ polly/trunk/include/polly/CodeGen/BlockGenerators.h Thu Jul 25 04:12:07 2013
@@ -106,6 +106,19 @@ protected:
   Value *getNewValue(const Value *Old, ValueMapT &BBMap, ValueMapT &GlobalMap,
                      LoopToScevMapT &LTS, Loop *L);
 
+  /// @brief Get the new version of a Value if it is available.
+  ///
+  /// @param Old       The old Value.
+  /// @param BBMap     A mapping from old values to their new values
+  ///                  (for values recalculated within this basic block).
+  /// @param GlobalMap A mapping from old values to their new values
+  ///                  (for values recalculated in the new ScoP, but not
+  ///                   within this basic block).
+  ///
+  /// @returns  The new value, if available.
+  Value *lookupAvailableValue(const Value *Old, ValueMapT &BBMap,
+                              ValueMapT &GlobalMap) const;
+
   void copyInstScalar(const Instruction *Inst, ValueMapT &BBMap,
                       ValueMapT &GlobalMap, LoopToScevMapT &LTS);
 

Modified: polly/trunk/lib/CodeGen/BlockGenerators.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/BlockGenerators.cpp?rev=187114&r1=187113&r2=187114&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/BlockGenerators.cpp (original)
+++ polly/trunk/lib/CodeGen/BlockGenerators.cpp Thu Jul 25 04:12:07 2013
@@ -158,9 +158,8 @@ BlockGenerator::BlockGenerator(IRBuilder
     : Builder(B), Statement(Stmt), P(P), SE(P->getAnalysis<ScalarEvolution>()) {
 }
 
-Value *BlockGenerator::getNewValue(const Value *Old, ValueMapT &BBMap,
-                                   ValueMapT &GlobalMap, LoopToScevMapT &LTS,
-                                   Loop *L) {
+Value *BlockGenerator::lookupAvailableValue(const Value *Old, ValueMapT &BBMap,
+                                            ValueMapT &GlobalMap) const {
   // We assume constants never change.
   // This avoids map lookups for many calls to this function.
   if (isa<Constant>(Old))
@@ -174,9 +173,27 @@ Value *BlockGenerator::getNewValue(const
     return New;
   }
 
+  // Or it is probably a scop-constant value defined as global, function
+  // parameter or an instruction not within the scop.
+  if (isa<GlobalValue>(Old) || isa<Argument>(Old))
+    return const_cast<Value *>(Old);
+
+  if (const Instruction *Inst = dyn_cast<Instruction>(Old))
+    if (!Statement.getParent()->getRegion().contains(Inst->getParent()))
+      return const_cast<Value *>(Old);
+
   if (Value *New = BBMap.lookup(Old))
     return New;
 
+  return NULL;
+}
+
+Value *BlockGenerator::getNewValue(const Value *Old, ValueMapT &BBMap,
+                                   ValueMapT &GlobalMap, LoopToScevMapT &LTS,
+                                   Loop *L) {
+  if (Value *New = lookupAvailableValue(Old, BBMap, GlobalMap))
+    return New;
+
   if (SCEVCodegen && SE.isSCEVable(Old->getType()))
     if (const SCEV *Scev = SE.getSCEVAtScope(const_cast<Value *>(Old), L)) {
       if (!isa<SCEVCouldNotCompute>(Scev)) {
@@ -194,15 +211,10 @@ Value *BlockGenerator::getNewValue(const
       }
     }
 
-  if (const Instruction *Inst = dyn_cast<Instruction>(Old)) {
-    (void)Inst;
-    assert(!Statement.getParent()->getRegion().contains(Inst->getParent()) &&
-           "unexpected scalar dependence in region");
-  }
-
-  // Everything else is probably a scop-constant value defined as global,
-  // function parameter or an instruction not within the scop.
-  return const_cast<Value *>(Old);
+  // Now the scalar dependence is neither available nor SCEVCodegenable, this
+  // should never happen in the current code generator.
+  llvm_unreachable("Unexpected scalar dependence in region!");
+  return NULL;
 }
 
 void BlockGenerator::copyInstScalar(const Instruction *Inst, ValueMapT &BBMap,





More information about the llvm-commits mailing list