[PATCH] D26661: [MemorySSA] Define a restricted upward AccessList splice.

bryant via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 14 23:17:48 PST 2016


bryant created this revision.
bryant added reviewers: dberlin, george.burgess.iv, hfinkel.
bryant added a subscriber: llvm-commits.
bryant set the repository for this revision to rL LLVM.

This defines an API endpoint that allows clients to move upwards a MemoryUse/Def
*M to just before a MemoryDef *Dest, where Dest and M may reside in separate
BasicBlocks. The following conditions must hold:

- Dest must dominate M,
- All MemoryAccesses between the Dest and M, as well as Dest itself, must be no-alias with M,
- Dest is MemoryDef (this restriction could probably be lifted).

These conditions allow the splice to be carried out with simple
replaceAllUsesWith and setDefiningAccess operations. In particular, the first
and second conditions are sufficient conditions for preservation of semantics.


Repository:
  rL LLVM

https://reviews.llvm.org/D26661

Files:
  include/llvm/Transforms/Utils/MemorySSA.h
  lib/Transforms/Utils/MemorySSA.cpp


Index: lib/Transforms/Utils/MemorySSA.cpp
===================================================================
--- lib/Transforms/Utils/MemorySSA.cpp
+++ lib/Transforms/Utils/MemorySSA.cpp
@@ -1614,6 +1614,25 @@
   return NewAccess;
 }
 
+void MemorySSA::spliceMemoryAccessAbove(MemoryDef *Where,
+                                        MemoryUseOrDef *What) {
+  assert(What != getLiveOnEntryDef() &&
+         Where != getLiveOnEntryDef() && "Can't splice (above) LOE.");
+  assert(dominates(Where, What) && "Only upwards splices are permitted.");
+
+  if (Where == What)
+    return;
+  if (isa<MemoryDef>(What)) {
+    // TODO: possibly use removeMemoryAccess' more efficient RAUW
+    What->replaceAllUsesWith(What->getDefiningAccess());
+    What->setDefiningAccess(Where->getDefiningAccess());
+    Where->setDefiningAccess(What);
+  }
+  AccessList *Src = getWritableBlockAccesses(What->getBlock());
+  AccessList *Dest = getWritableBlockAccesses(Where->getBlock());
+  Dest->splice(AccessList::iterator(Where), *Src, What);
+}
+
 /// \brief Helper function to create new memory accesses
 MemoryUseOrDef *MemorySSA::createNewAccess(Instruction *I) {
   // The assume intrinsic has a control dependency which we model by claiming
Index: include/llvm/Transforms/Utils/MemorySSA.h
===================================================================
--- include/llvm/Transforms/Utils/MemorySSA.h
+++ include/llvm/Transforms/Utils/MemorySSA.h
@@ -570,6 +570,15 @@
                                           MemoryAccess *Definition,
                                           MemoryAccess *InsertPt);
 
+  // \brief Splice \p What to just before \p Where.
+  //
+  // In order to be efficient, the following conditions must be met:
+  //   - \p Where  dominates \p What,
+  //   - All memory accesses in [\p Where, \p What) are no-alias with \p What.
+  //
+  // TODO: relax the MemoryDef requirement on Where.
+  void spliceMemoryAccessAbove(MemoryDef *Where, MemoryUseOrDef *What);
+
   /// \brief Remove a MemoryAccess from MemorySSA, including updating all
   /// definitions and uses.
   /// This should be called when a memory instruction that has a MemoryAccess


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26661.77949.patch
Type: text/x-patch
Size: 2172 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161115/073b6680/attachment.bin>


More information about the llvm-commits mailing list