From: Xinliang David Li Date: Sat, 22 Apr 2017 19:24:19 +0000 (+0000) Subject: [PartialInlining] Using existing hasAddressTaken interface to legality check/NFC X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=db0b3ce4eb3e9b614a8702d8bc8ed5904820e21a;p=llvm [PartialInlining] Using existing hasAddressTaken interface to legality check/NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301090 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/IPO/PartialInlining.cpp b/lib/Transforms/IPO/PartialInlining.cpp index d8111688d1d..f5e5775da55 100644 --- a/lib/Transforms/IPO/PartialInlining.cpp +++ b/lib/Transforms/IPO/PartialInlining.cpp @@ -66,6 +66,9 @@ struct PartialInlinerLegacyPass : public ModulePass { Function *PartialInlinerImpl::unswitchFunction(Function *F) { // First, verify that this function is an unswitching candidate... + if (F->hasAddressTaken()) + return nullptr; + BasicBlock *EntryBlock = &F->front(); BranchInst *BR = dyn_cast(EntryBlock->getTerminator()); if (!BR || BR->isUnconditional()) @@ -85,25 +88,6 @@ Function *PartialInlinerImpl::unswitchFunction(Function *F) { if (ReturnCount != 1) return nullptr; - auto canAllUsesBeReplaced = [](Function *F) { - std::vector Users(F->user_begin(), F->user_end()); - for (User *User : Users) { - Function *Callee = nullptr; - if (CallInst *CI = dyn_cast(User)) - Callee = CallSite(CI).getCalledFunction(); - else if (InvokeInst *II = dyn_cast(User)) - Callee = CallSite(II).getCalledFunction(); - - if (Callee != F) - return false; - } - - return true; - }; - - if (!canAllUsesBeReplaced(F)) - return nullptr; - // Clone the function, so that we can hack away on it. ValueToValueMapTy VMap; Function *DuplicateFunction = CloneFunction(F, VMap);