[PATCH] D15693: [Polly] Take a PHI's incoming block as value user

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 21 08:45:38 PST 2015


Meinersbur created this revision.
Meinersbur added reviewers: grosser, jdoerfert.
Meinersbur added subscribers: llvm-commits, pollydev.
Meinersbur added a project: Polly.

Before this patch, we determine whether a value escapes the SCoP by checking whether it the instruction itself is within the scop. This is wrong for PHINodes because the value must be available in the incoming block instead of of where the PHI is.

To fix this, we introduce a function "getUseBlock" to determine the location of a value's use for PHIs and other instructions. It will also be used in subsequent patches.

I could not produce a test case because of region simplification and loop versioning which adds additional block between the PHIs and the SCoP region. Nonetheless, it happend during debugging of preliminary code and is in general the correct way.

http://reviews.llvm.org/D15693

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

Index: lib/Support/ScopHelper.cpp
===================================================================
--- lib/Support/ScopHelper.cpp
+++ lib/Support/ScopHelper.cpp
@@ -453,3 +453,14 @@
 
   return false;
 }
+
+llvm::BasicBlock *polly::getUseBlock(llvm::Use &U) {
+  Instruction *UI = dyn_cast<Instruction>(U.getUser());
+  if (!UI)
+    return nullptr;
+
+  if (PHINode *PHI = dyn_cast<PHINode>(UI))
+    return PHI->getIncomingBlock(U);
+
+  return UI->getParent();
+}
Index: lib/CodeGen/BlockGenerators.cpp
===================================================================
--- lib/CodeGen/BlockGenerators.cpp
+++ lib/CodeGen/BlockGenerators.cpp
@@ -365,14 +365,14 @@
     return;
 
   EscapeUserVectorTy EscapeUsers;
-  for (User *U : Inst->users()) {
+  for (Use &U : Inst->uses()) {
 
     // Non-instruction user will never escape.
-    Instruction *UI = dyn_cast<Instruction>(U);
+    Instruction *UI = dyn_cast<Instruction>(U.getUser());
     if (!UI)
       continue;
 
-    if (R.contains(UI))
+    if (R.contains(getUseBlock(U)))
       continue;
 
     EscapeUsers.push_back(UI);
Index: include/polly/Support/ScopHelper.h
===================================================================
--- include/polly/Support/ScopHelper.h
+++ include/polly/Support/ScopHelper.h
@@ -164,5 +164,14 @@
 ///         otherwise return false.
 bool canSynthesize(const llvm::Value *V, const llvm::LoopInfo *LI,
                    llvm::ScalarEvolution *SE, const llvm::Region *R);
+
+/// @brief Return the block in which a value is used.
+///
+/// For normal instructions, this is the instruction's parent block. For PHI
+/// nodes, this is the incoming block of that use, because this is where the
+/// operand must be defined (i.e. its definition dominates this block).
+/// Non-instructions do not use operands at a specific point such that in this
+/// case this function returns nullptr.
+llvm::BasicBlock *getUseBlock(llvm::Use &U);
 }
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15693.43380.patch
Type: text/x-patch
Size: 1947 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151221/a69bfdcb/attachment.bin>


More information about the llvm-commits mailing list