[polly] r323283 - [VirtualInst] Derive correct use kind of PHI operands. NFC.

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 23 15:56:25 PST 2018


Author: meinersbur
Date: Tue Jan 23 15:56:25 2018
New Revision: 323283

URL: http://llvm.org/viewvc/llvm-project?rev=323283&view=rev
Log:
[VirtualInst] Derive correct use kind of PHI operands. NFC.

VirtualUse::create is only called for MemoryKind::Value, but its
consistency nonetheless checked in verifyUses(). PHI uses are always
inter-stmt dependencies, which was not considered by the constructor
method. The virtual and non-virtual execution paths were the same, such
that verifyUses did not encounter any inconsistencies.

Modified:
    polly/trunk/include/polly/Support/VirtualInstruction.h
    polly/trunk/lib/Support/VirtualInstruction.cpp

Modified: polly/trunk/include/polly/Support/VirtualInstruction.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/Support/VirtualInstruction.h?rev=323283&r1=323282&r2=323283&view=diff
==============================================================================
--- polly/trunk/include/polly/Support/VirtualInstruction.h (original)
+++ polly/trunk/include/polly/Support/VirtualInstruction.h Tue Jan 23 15:56:25 2018
@@ -99,7 +99,10 @@ public:
   /// @return The VirtualUse representing the same use as @p U.
   static VirtualUse create(Scop *S, const Use &U, LoopInfo *LI, bool Virtual);
 
-  /// Get a VirtualUse for any kind of use of a value within a statement.
+  /// Get a VirtualUse for uses within statements.
+  ///
+  /// It is assumed that the user is not a PHINode. Such uses are always
+  /// VirtualUse::Inter unless in a regions statement.
   ///
   /// @param S         The Scop object.
   /// @param UserStmt  The statement in which @p Val is used. Can be nullptr, in

Modified: polly/trunk/lib/Support/VirtualInstruction.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Support/VirtualInstruction.cpp?rev=323283&r1=323282&r2=323283&view=diff
==============================================================================
--- polly/trunk/lib/Support/VirtualInstruction.cpp (original)
+++ polly/trunk/lib/Support/VirtualInstruction.cpp Tue Jan 23 15:56:25 2018
@@ -21,13 +21,33 @@ using namespace llvm;
 VirtualUse VirtualUse ::create(Scop *S, const Use &U, LoopInfo *LI,
                                bool Virtual) {
   auto *UserBB = getUseBlock(U);
+  Loop *UserScope = LI->getLoopFor(UserBB);
   Instruction *UI = dyn_cast<Instruction>(U.getUser());
-  ScopStmt *UserStmt = nullptr;
-  if (PHINode *PHI = dyn_cast<PHINode>(UI))
-    UserStmt = S->getLastStmtFor(PHI->getIncomingBlock(U));
-  else
-    UserStmt = S->getStmtFor(UI);
-  auto *UserScope = LI->getLoopFor(UserBB);
+  ScopStmt *UserStmt = S->getStmtFor(UI);
+
+  // Uses by PHI nodes are always reading values written by other statements,
+  // except it is within a region statement.
+  if (PHINode *PHI = dyn_cast<PHINode>(UI)) {
+    // Handle PHI in exit block.
+    if (S->getRegion().getExit() == PHI->getParent())
+      return VirtualUse(UserStmt, U.get(), Inter, nullptr, nullptr);
+
+    if (UserStmt->getEntryBlock() != PHI->getParent())
+      return VirtualUse(UserStmt, U.get(), Intra, nullptr, nullptr);
+
+    // The MemoryAccess is expected to be set if @p Virtual is true.
+    MemoryAccess *IncomingMA = nullptr;
+    if (Virtual) {
+      if (const ScopArrayInfo *SAI =
+              S->getScopArrayInfoOrNull(PHI, MemoryKind::PHI)) {
+        IncomingMA = S->getPHIRead(SAI);
+        assert(IncomingMA->getStatement() == UserStmt);
+      }
+    }
+
+    return VirtualUse(UserStmt, U.get(), Inter, nullptr, IncomingMA);
+  }
+
   return create(S, UserStmt, UserScope, U.get(), Virtual);
 }
 




More information about the llvm-commits mailing list