From fac07b1dcaa81300ac688280749b10e49883b0ab Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 29 Aug 2010 04:54:06 +0000 Subject: [PATCH] implement SSAUpdater::RewriteUseAfterInsertions, a helpful form of RewriteUse. llvm-svn: 112409 --- include/llvm/Transforms/Utils/SSAUpdater.h | 6 ++++++ lib/Transforms/Utils/SSAUpdater.cpp | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/llvm/Transforms/Utils/SSAUpdater.h b/include/llvm/Transforms/Utils/SSAUpdater.h index ca98466b345..86ecb73df69 100644 --- a/include/llvm/Transforms/Utils/SSAUpdater.h +++ b/include/llvm/Transforms/Utils/SSAUpdater.h @@ -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); diff --git a/lib/Transforms/Utils/SSAUpdater.cpp b/lib/Transforms/Utils/SSAUpdater.cpp index f4bdb527655..9dc2a1ed38e 100644 --- a/lib/Transforms/Utils/SSAUpdater.cpp +++ b/lib/Transforms/Utils/SSAUpdater.cpp @@ -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(U.getUser()); + + Value *V; + if (PHINode *UserPN = dyn_cast(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 {