From 5361b841848e8f4851ed9a6f935f31276e89d263 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Sun, 2 Jan 2011 19:16:44 +0000 Subject: Also remove functions that use complex constant expressions in terms of another function. llvm-svn: 122705 --- llvm/lib/Transforms/IPO/MergeFunctions.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'llvm/lib/Transforms') diff --git a/llvm/lib/Transforms/IPO/MergeFunctions.cpp b/llvm/lib/Transforms/IPO/MergeFunctions.cpp index 74d41051516..c678db85900 100644 --- a/llvm/lib/Transforms/IPO/MergeFunctions.cpp +++ b/llvm/lib/Transforms/IPO/MergeFunctions.cpp @@ -696,11 +696,24 @@ void MergeFunctions::Remove(Function *F) { // RemoveUsers - For each instruction used by the value, Remove() the function // that contains the instruction. This should happen right before a call to RAUW. void MergeFunctions::RemoveUsers(Value *V) { - for (Value::use_iterator UI = V->use_begin(), UE = V->use_end(); - UI != UE; ++UI) { - Use &U = UI.getUse(); - if (Instruction *I = dyn_cast(U.getUser())) { - Remove(I->getParent()->getParent()); + std::vector Worklist; + Worklist.push_back(V); + while (!Worklist.empty()) { + Value *V = Worklist.back(); + Worklist.pop_back(); + + for (Value::use_iterator UI = V->use_begin(), UE = V->use_end(); + UI != UE; ++UI) { + Use &U = UI.getUse(); + if (Instruction *I = dyn_cast(U.getUser())) { + Remove(I->getParent()->getParent()); + } else if (isa(U.getUser())) { + // do nothing + } else if (Constant *C = dyn_cast(U.getUser())) { + for (Value::use_iterator CUI = C->use_begin(), CUE = C->use_end(); + CUI != CUE; ++CUI) + Worklist.push_back(*CUI); + } } } } -- cgit v1.2.3