[PATCH] D35585: [ScopInfo] Introduce tryGetValueStored

Tobias Grosser via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 18 15:18:33 PDT 2017


grosser created this revision.
grosser added a project: Polly.

This makes code more readable and allows to reuse this functionality in
the future at other places.

Suggested-by Michael Kruse in post-commit review of r307660.


https://reviews.llvm.org/D35585

Files:
  include/polly/ScopInfo.h
  lib/Transform/Simplify.cpp


Index: lib/Transform/Simplify.cpp
===================================================================
--- lib/Transform/Simplify.cpp
+++ lib/Transform/Simplify.cpp
@@ -238,13 +238,7 @@
         if (!isa<StoreInst>(WA->getAccessInstruction()) && !WA->isPHIKind())
           continue;
 
-        auto ReadingValue = WA->getAccessValue();
-
-        if (WA->isPHIKind()) {
-          PHINode *PHI = cast<PHINode>(WA->getAccessValue());
-          BasicBlock *BB = Stmt.getBasicBlock();
-          ReadingValue = PHI->getIncomingValueForBlock(BB);
-        }
+        llvm::Value *ReadingValue = WA->tryGetValueStored();
 
         if (!ReadingValue)
           continue;
Index: include/polly/ScopInfo.h
===================================================================
--- include/polly/ScopInfo.h
+++ include/polly/ScopInfo.h
@@ -889,6 +889,21 @@
   /// Return the access value of this memory access.
   Value *getAccessValue() const { return AccessValue; }
 
+  /// Return llvm::Value that is stored by this access, if available.
+  ///
+  /// PHI nodes may not have a unique value available that is stored, as in
+  /// case of region statements one out of possibly several llvm::Values
+  /// might be stored. In this case nullptr is returned.
+  Value *tryGetValueStored() {
+    assert(isWrite() && "Only write statement store values");
+    if (isPHIKind()) {
+      if (Incoming.size() == 1)
+        return Incoming[0].second;
+      return nullptr;
+    }
+    return AccessValue;
+  }
+
   /// Return the access instruction of this memory access.
   Instruction *getAccessInstruction() const { return AccessInstruction; }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35585.107189.patch
Type: text/x-patch
Size: 1635 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170718/3bfae4ce/attachment.bin>


More information about the llvm-commits mailing list