]> granicus.if.org Git - llvm/commitdiff
[MemorySSA] Refactor removing multiple trivial phis [NFC].
authorAlina Sbirlea <asbirlea@google.com>
Thu, 2 May 2019 23:12:49 +0000 (23:12 +0000)
committerAlina Sbirlea <asbirlea@google.com>
Thu, 2 May 2019 23:12:49 +0000 (23:12 +0000)
Summary: Create a method to clean up multiple potentially trivial phis, since we will need this often.

Reviewers: george.burgess.iv

Subscribers: jlebar, Prazek, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D61471

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359842 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 58cf1cc6b5dccb5897cbebabafb80327ff4cdf7e..451f06f39d00be9f2edb8f7eca4a9ac9851476f3 100644 (file)
@@ -261,6 +261,7 @@ private:
   MemoryAccess *recursePhi(MemoryAccess *Phi);
   template <class RangeType>
   MemoryAccess *tryRemoveTrivialPhi(MemoryPhi *Phi, RangeType &Operands);
+  void tryRemoveTrivialPhis(ArrayRef<WeakVH> UpdatedPHIs);
   void fixupDefs(const SmallVectorImpl<WeakVH> &);
   // Clone all uses and defs from BB to NewBB given a 1:1 map of all
   // instructions and blocks cloned, and a map of MemoryPhi : Definition
index 3f3fd998d5cc4bd9aa8f65079d98bfe243a21eb0..7c675b7a34aa32e72c128081f55582b15ce41abd 100644 (file)
@@ -355,12 +355,9 @@ void MemorySSAUpdater::insertDef(MemoryDef *MD, bool RenameUses) {
   }
 
   // Optimize potentially non-minimal phis added in this method.
-  for (unsigned Idx = NewPhiIndex; Idx < NewPhiIndexEnd; ++Idx) {
-    if (auto *MPhi = cast_or_null<MemoryPhi>(InsertedPHIs[Idx])) {
-      auto OperRange = MPhi->operands();
-      tryRemoveTrivialPhi(MPhi, OperRange);
-    }
-  }
+  unsigned NewPhiSize = NewPhiIndexEnd - NewPhiIndex;
+  if (NewPhiSize)
+    tryRemoveTrivialPhis(ArrayRef<WeakVH>(&InsertedPHIs[NewPhiIndex], NewPhiSize));
 
   // Now that all fixups are done, rename all uses if we are asked.
   if (RenameUses) {
@@ -1215,6 +1212,14 @@ void MemorySSAUpdater::removeBlocks(
   }
 }
 
+void MemorySSAUpdater::tryRemoveTrivialPhis(ArrayRef<WeakVH> UpdatedPHIs) {
+  for (auto &VH : UpdatedPHIs)
+    if (auto *MPhi = cast_or_null<MemoryPhi>(VH)) {
+      auto OperRange = MPhi->operands();
+      tryRemoveTrivialPhi(MPhi, OperRange);
+    }
+}
+
 MemoryAccess *MemorySSAUpdater::createMemoryAccessInBB(
     Instruction *I, MemoryAccess *Definition, const BasicBlock *BB,
     MemorySSA::InsertionPlace Point) {