[PATCH] D36591: [PredicateInfo] Add a helper routine to remove SSA copies from a Function.

Chad Rosier via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 10 14:11:46 PDT 2017


mcrosier created this revision.
Herald added a subscriber: Prazek.

Also make it configurable so when PredicateInfo is destroyed the SSA copies are automatically removed if requested by the user.

While NewGVN takes care of these copies on the fly the expectation is that most passes will clean up after the fact.  Doing this directly in PredicateInfo is much easier and faster.

Just looking for some feedback to see if I'm going in the right direction here..

Chad


https://reviews.llvm.org/D36591

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


Index: lib/Transforms/Utils/PredicateInfo.cpp
===================================================================
--- lib/Transforms/Utils/PredicateInfo.cpp
+++ lib/Transforms/Utils/PredicateInfo.cpp
@@ -478,6 +478,19 @@
   renameUses(OpsToRename);
 }
 
+// Remove all SSA copies from function F.
+void PredicateInfo::removeSSACopies() {
+  for (DenseMap<const Value *, const PredicateBase *>::iterator
+           I = PredicateMap.begin(),
+           E = PredicateMap.end();
+       I != E; ++I) {
+    IntrinsicInst *Copy =
+        const_cast<IntrinsicInst *>(cast<IntrinsicInst>(I->first));
+    Copy->replaceAllUsesWith(Copy->getReturnedArgOperand());
+    Copy->eraseFromParent();
+  }
+}
+
 // Given the renaming stack, make all the operands currently on the stack real
 // by inserting them into the IR.  Return the last operation's value.
 Value *PredicateInfo::materializeStack(unsigned int &Counter,
@@ -689,14 +702,18 @@
 }
 
 PredicateInfo::PredicateInfo(Function &F, DominatorTree &DT,
-                             AssumptionCache &AC)
+                             AssumptionCache &AC, bool RemoveCopies)
     : F(F), DT(DT), AC(AC), OI(&DT) {
   // Push an empty operand info so that we can detect 0 as not finding one
   ValueInfos.resize(1);
   buildPredicateInfo();
+  RemoveSSACopies = RemoveCopies;
 }
 
-PredicateInfo::~PredicateInfo() {}
+PredicateInfo::~PredicateInfo() {
+  if (RemoveSSACopies)
+    removeSSACopies();
+}
 
 void PredicateInfo::verifyPredicateInfo() const {}
 
Index: include/llvm/Transforms/Utils/PredicateInfo.h
===================================================================
--- include/llvm/Transforms/Utils/PredicateInfo.h
+++ include/llvm/Transforms/Utils/PredicateInfo.h
@@ -209,7 +209,7 @@
   iplist<PredicateBase> AllInfos;
 
 public:
-  PredicateInfo(Function &, DominatorTree &, AssumptionCache &);
+  PredicateInfo(Function &, DominatorTree &, AssumptionCache &, bool = false);
   ~PredicateInfo();
 
   void verifyPredicateInfo() const;
@@ -228,6 +228,7 @@
 
 private:
   void buildPredicateInfo();
+  void removeSSACopies();
   void processAssume(IntrinsicInst *, BasicBlock *, SmallPtrSetImpl<Value *> &);
   void processBranch(BranchInst *, BasicBlock *, SmallPtrSetImpl<Value *> &);
   void processSwitch(SwitchInst *, BasicBlock *, SmallPtrSetImpl<Value *> &);
@@ -246,6 +247,7 @@
   DominatorTree &DT;
   AssumptionCache &AC;
   OrderedInstructions OI;
+  bool RemoveSSACopies;
   // This maps from copy operands to Predicate Info. Note that it does not own
   // the Predicate Info, they belong to the ValueInfo structs in the ValueInfos
   // vector.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36591.110631.patch
Type: text/x-patch
Size: 2620 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170810/87dbb5e9/attachment.bin>


More information about the llvm-commits mailing list