implement SSAUpdater::RewriteUseAfterInsertions, a helpful form of RewriteUse.
authorChris Lattner <sabre@nondot.org>
Sun, 29 Aug 2010 04:54:06 +0000 (04:54 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 29 Aug 2010 04:54:06 +0000 (04:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112409 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Transforms/Utils/SSAUpdater.h
lib/Transforms/Utils/SSAUpdater.cpp

index ca98466b3456e056e91af29c83746c9628c7f496..86ecb73df6968e849503b46c51ed72defebb111e 100644 (file)
@@ -94,6 +94,12 @@ public:
   /// for the use's block will be considered to be below it.
   void RewriteUse(Use &U);
 
+  /// RewriteUseAfterInsertions - Rewrite a use, just like RewriteUse.  However,
+  /// this version of the method can rewrite uses in the same block as a
+  /// definition, because it assumes that all uses of a value are below any
+  /// inserted values.
+  void RewriteUseAfterInsertions(Use &U);
+
 private:
   Value *GetValueAtEndOfBlockInternal(BasicBlock *BB);
 
index f4bdb527655abe8ab646a2202c0608ae25b73023..9dc2a1ed38e9a63fcd5c766b042cfef0da8b2200 100644 (file)
@@ -205,6 +205,22 @@ void SSAUpdater::RewriteUse(Use &U) {
   U.set(V);
 }
 
+/// RewriteUseAfterInsertions - Rewrite a use, just like RewriteUse.  However,
+/// this version of the method can rewrite uses in the same block as a
+/// definition, because it assumes that all uses of a value are below any
+/// inserted values.
+void SSAUpdater::RewriteUseAfterInsertions(Use &U) {
+  Instruction *User = cast<Instruction>(U.getUser());
+  
+  Value *V;
+  if (PHINode *UserPN = dyn_cast<PHINode>(User))
+    V = GetValueAtEndOfBlock(UserPN->getIncomingBlock(U));
+  else
+    V = GetValueAtEndOfBlock(User->getParent());
+  
+  U.set(V);
+}
+
 /// PHIiter - Iterator for PHI operands.  This is used for the PHI_iterator
 /// in the SSAUpdaterImpl template.
 namespace {