//===- InlineFunction.cpp - Code to perform function inlining -------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
//
// This file implements inlining of a function into a call site, resolving
// parameters and the return value as appropriate.
#include "llvm/Support/CallSite.h"
#include "llvm/Transforms/Utils/Local.h"
+namespace llvm {
+
bool InlineFunction(CallInst *CI) { return InlineFunction(CallSite(CI)); }
bool InlineFunction(InvokeInst *II) { return InlineFunction(CallSite(II)); }
if (InvokeInst *II = dyn_cast<InvokeInst>(TheCall)) {
InvokeDest = II->getExceptionalDest();
+ // If there are PHI nodes in the exceptional destination block, we need to
+ // keep track of which values came into them from this invoke, then remove
+ // the entry for this block.
+ for (BasicBlock::iterator I = InvokeDest->begin();
+ PHINode *PN = dyn_cast<PHINode>(I); ++I) {
+ // Save the value to use for this edge...
+ InvokeDestPHIValues.push_back(PN->getIncomingValueForBlock(OrigBB));
+ }
+
// Add an unconditional branch to make this look like the CallInst case...
BranchInst *NewBr = new BranchInst(II->getNormalDest(), TheCall);
AfterCallBB = OrigBB->splitBasicBlock(NewBr,
CalledFunc->getName()+".entry");
- // If there are PHI nodes in the exceptional destination block, we need to
- // keep track of which values came into them from this invoke, then remove
- // the entry for this block.
- for (BasicBlock::iterator I = InvokeDest->begin();
- PHINode *PN = dyn_cast<PHINode>(I); ++I) {
- // Save the value to use for this edge...
- InvokeDestPHIValues.push_back(PN->getIncomingValueForBlock(AfterCallBB));
- }
-
// Remove (unlink) the InvokeInst from the function...
OrigBB->getInstList().remove(TheCall);
// invoke site. Once this happens, we know that the unwind would cause
// a control transfer to the invoke exception destination, so we can
// transform it into a direct branch to the exception destination.
- BranchInst *BI = new BranchInst(InvokeDest, UI);
+ new BranchInst(InvokeDest, UI);
// Delete the unwind instruction!
UI->getParent()->getInstList().pop_back();
+
+ // Update any PHI nodes in the exceptional block to indicate that
+ // there is now a new entry in them.
+ unsigned i = 0;
+ for (BasicBlock::iterator I = InvokeDest->begin();
+ PHINode *PN = dyn_cast<PHINode>(I); ++I, ++i)
+ PN->addIncoming(InvokeDestPHIValues[i], BB);
}
}
SimplifyCFG(AfterCallBB);
return true;
}
+
+} // End llvm namespace