[PATCH] D49156: [MemorySSA] Add API to update MemoryPhis, following CFG changes.

Alina Sbirlea via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 10 14:39:13 PDT 2018


asbirlea created this revision.
asbirlea added a reviewer: george.burgess.iv.
Herald added subscribers: Prazek, jlebar, sanjoy.

When splitting predecessors in BasicBlockUtils, we create a new block as an immediate predecessor of the original BB, then we connect a given set of predecessors to the new block.
The API in this patch will be used to update MemoryPhis for this CFG change.
If all predecessors are being moved, we move the MemoryPhi directly. Otherwise we create a new MemoryPhi in the NewBB and populate its incoming values, while deleting them from BB's Phi.
[Split from https://reviews.llvm.org/D45299 for easier review]


Repository:
  rL LLVM

https://reviews.llvm.org/D49156

Files:
  include/llvm/Analysis/MemorySSAUpdater.h
  lib/Analysis/MemorySSAUpdater.cpp


Index: lib/Analysis/MemorySSAUpdater.cpp
===================================================================
--- lib/Analysis/MemorySSAUpdater.cpp
+++ lib/Analysis/MemorySSAUpdater.cpp
@@ -494,6 +494,32 @@
   return MA;
 }
 
+void MemorySSAUpdater::wireOldPredecessorsToNewImmediatePredecessor(BasicBlock *Old,
+                                                        BasicBlock *New,
+                                                        ArrayRef<BasicBlock *>Preds) {
+  assert(MSSA->getWritableBlockAccesses(New) == nullptr &&
+         "Access list should be null for a new block.");
+  MemoryPhi *Phi = MSSA->getMemoryAccess(Old);
+  if (!Phi)
+    return;
+  if (pred_size(Old) == 1 && pred_size(New) == Preds.size())
+    MSSA->moveTo(Phi, New, MemorySSA::Beginning);
+  else {
+    assert (Preds.size() > 0 &&
+            "Must be moving at least one predecessor to the new immediate predecessor.");
+    MemoryPhi *NewPhi = MSSA->createMemoryPhi(New);
+    for (auto *Pred : Preds) {
+      int Idx = Phi->getBasicBlockIndex(Pred);
+      assert (Idx >=0 && "Predecessor must have an incoming value in Phi.");
+      NewPhi->addIncoming(Phi->getIncomingValue(Idx), Pred);
+      Phi->unorderedDeleteIncoming(Idx);
+    }
+    Phi->addIncoming(NewPhi, New);
+    if (onlySingleValue(NewPhi))
+      removeMemoryAccess(NewPhi);
+  }
+}
+
 void MemorySSAUpdater::removeMemoryAccess(MemoryAccess *MA) {
   assert(!MSSA->isLiveOnEntryDef(MA) &&
          "Trying to remove the live on entry def");
Index: include/llvm/Analysis/MemorySSAUpdater.h
===================================================================
--- include/llvm/Analysis/MemorySSAUpdater.h
+++ include/llvm/Analysis/MemorySSAUpdater.h
@@ -120,6 +120,14 @@
   /// |------|        |------|
   void moveAllAfterMergeBlocks(BasicBlock *From, BasicBlock *To,
                                Instruction *Start);
+  /// BasicBlock Old had New, an empty BasicBlock, added directly before it,
+  /// and the predecessors in Preds that used to point to Old, now point to
+  /// New. If New is the only predecessor, move Old's Phi, if present, to New.
+  /// Otherwise, add a new Phi in New with appropriate incoming values, and
+  /// update the incoming values in Old's Phi node too, if present.
+  void wireOldPredecessorsToNewImmediatePredecessor(BasicBlock *Old,
+                                                    BasicBlock *New,
+                                                    ArrayRef<BasicBlock *>Preds);
 
   // The below are utility functions. Other than creation of accesses to pass
   // to insertDef, and removeAccess to remove accesses, you should generally


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49156.154886.patch
Type: text/x-patch
Size: 2647 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180710/6fd52d57/attachment.bin>


More information about the llvm-commits mailing list