[polly] r250608 - BlockGenerator: Register outside users of scalars directly

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 17 01:54:13 PDT 2015


Author: grosser
Date: Sat Oct 17 03:54:13 2015
New Revision: 250608

URL: http://llvm.org/viewvc/llvm-project?rev=250608&view=rev
Log:
BlockGenerator: Register outside users of scalars directly

Instead of checking at code generation time for each ScopStmt if a scalar has
external uses, we just iterate over the ScopArrayInfo descriptions we have and
check each of these for possible external uses.

Besides being somehow clearer, this approach has the benefit that we will always
create valid LLVM-IR even in case we disable the code generation of ScopStmt
bodies e.g. for testing purposes.

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=250608&r1=250607&r2=250608&view=diff
==============================================================================
--- polly/trunk/include/polly/CodeGen/BlockGenerators.h (original)
+++ polly/trunk/include/polly/CodeGen/BlockGenerators.h Sat Oct 17 03:54:13 2015
@@ -373,6 +373,16 @@ protected:
   void handleOutsideUsers(const Region &R, Instruction *Inst,
                           Value *Address = nullptr);
 
+  /// @brief Find scalar statements that have outside users.
+  ///
+  /// We register these scalar values to later update subsequent scalar uses of
+  /// these values to either use the newly computed value from within the scop
+  /// (if the scop was executed) or the unchanged original code (if the run-time
+  /// check failed).
+  ///
+  /// @param S The scop for which to find the outside users.
+  void findOutsideUsers(Scop &S);
+
   /// @brief Initialize the memory of demoted scalars.
   ///
   /// @param S The scop for which to generate the scalar initializers.

Modified: polly/trunk/lib/CodeGen/BlockGenerators.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/BlockGenerators.cpp?rev=250608&r1=250607&r2=250608&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/BlockGenerators.cpp (original)
+++ polly/trunk/lib/CodeGen/BlockGenerators.cpp Sat Oct 17 03:54:13 2015
@@ -312,10 +312,6 @@ void BlockGenerator::copyBB(ScopStmt &St
   // in their alloca. First the scalars that have dependences inside the SCoP,
   // then the ones that might escape the SCoP.
   generateScalarStores(Stmt, BB, LTS, BBMap);
-
-  const Region &R = Stmt.getParent()->getRegion();
-  for (Instruction &Inst : *BB)
-    handleOutsideUsers(R, &Inst);
 }
 
 Value *BlockGenerator::getOrCreateAlloca(Value *ScalarBase,
@@ -572,7 +568,8 @@ void BlockGenerator::createScalarFinaliz
   }
 }
 
-void BlockGenerator::finalizeSCoP(Scop &S) {
+void BlockGenerator::findOutsideUsers(Scop &S) {
+  auto &R = S.getRegion();
 
   // Handle PHI nodes that were in the original exit and are now
   // moved into the region exiting block.
@@ -589,6 +586,32 @@ void BlockGenerator::finalizeSCoP(Scop &
     }
   }
 
+  for (auto &Pair : S.arrays()) {
+    auto &Array = Pair.second;
+
+    if (Array->getNumberOfDimensions() != 0)
+      continue;
+
+    if (Array->isPHI())
+      continue;
+
+    auto *Inst = dyn_cast<Instruction>(Array->getBasePtr());
+
+    if (!Inst)
+      continue;
+
+    // Scop invariant hoisting moves some of the base pointers out of the scop.
+    // We can ignore these, as the invariant load hoisting already registers the
+    // relevant outside users.
+    if (!R.contains(Inst))
+      continue;
+
+    handleOutsideUsers(R, Inst, nullptr);
+  }
+}
+
+void BlockGenerator::finalizeSCoP(Scop &S) {
+  findOutsideUsers(S);
   createScalarInitialization(S);
   createScalarFinalization(S.getRegion());
 }




More information about the llvm-commits mailing list