blob: 40d02ab4bc92cae72c79f2ec86283fe05084bfa7 [file] [log] [blame]
Chris Lattner530d4bf2003-05-29 15:11:31 +00001//===- InlineFunction.cpp - Code to perform function inlining -------------===//
Misha Brukmanb1c93172005-04-21 23:48:37 +00002//
John Criswell482202a2003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
Misha Brukmanb1c93172005-04-21 23:48:37 +00007//
John Criswell482202a2003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner530d4bf2003-05-29 15:11:31 +00009//
10// This file implements inlining of a function into a call site, resolving
11// parameters and the return value as appropriate.
12//
Chris Lattner530d4bf2003-05-29 15:11:31 +000013//===----------------------------------------------------------------------===//
14
15#include "llvm/Transforms/Utils/Cloning.h"
Chris Lattner6e79e552004-10-17 23:21:07 +000016#include "llvm/Constants.h"
Chris Lattnerfc3fe5c2003-08-24 04:06:56 +000017#include "llvm/DerivedTypes.h"
Chris Lattner530d4bf2003-05-29 15:11:31 +000018#include "llvm/Module.h"
Chris Lattner0cc265e2003-08-24 06:59:16 +000019#include "llvm/Instructions.h"
20#include "llvm/Intrinsics.h"
21#include "llvm/Support/CallSite.h"
Chris Lattnerdf3c3422004-01-09 06:12:26 +000022using namespace llvm;
Chris Lattner530d4bf2003-05-29 15:11:31 +000023
Chris Lattnerdf3c3422004-01-09 06:12:26 +000024bool llvm::InlineFunction(CallInst *CI) { return InlineFunction(CallSite(CI)); }
25bool llvm::InlineFunction(InvokeInst *II) {return InlineFunction(CallSite(II));}
Chris Lattner0cc265e2003-08-24 06:59:16 +000026
Chris Lattner530d4bf2003-05-29 15:11:31 +000027// InlineFunction - This function inlines the called function into the basic
28// block of the caller. This returns false if it is not possible to inline this
29// call. The program is still in a well defined state if this occurs though.
30//
Misha Brukmanb1c93172005-04-21 23:48:37 +000031// Note that this only does one level of inlining. For example, if the
32// instruction 'call B' is inlined, and 'B' calls 'C', then the call to 'C' now
Chris Lattner530d4bf2003-05-29 15:11:31 +000033// exists in the instruction stream. Similiarly this will inline a recursive
34// function by one level.
35//
Chris Lattnerdf3c3422004-01-09 06:12:26 +000036bool llvm::InlineFunction(CallSite CS) {
Chris Lattner0cc265e2003-08-24 06:59:16 +000037 Instruction *TheCall = CS.getInstruction();
38 assert(TheCall->getParent() && TheCall->getParent()->getParent() &&
39 "Instruction not in function!");
Chris Lattner530d4bf2003-05-29 15:11:31 +000040
Chris Lattner0cc265e2003-08-24 06:59:16 +000041 const Function *CalledFunc = CS.getCalledFunction();
Chris Lattner530d4bf2003-05-29 15:11:31 +000042 if (CalledFunc == 0 || // Can't inline external function or indirect
43 CalledFunc->isExternal() || // call, or call to a vararg function!
44 CalledFunc->getFunctionType()->isVarArg()) return false;
45
Chris Lattner9f3dced2005-05-06 06:47:52 +000046
47 // If the call to the callee is a non-tail call, we must clear the 'tail'
48 // flags on any calls that we inline.
49 bool MustClearTailCallFlags =
Chris Lattner7effa0e2005-05-06 17:13:16 +000050 isa<CallInst>(TheCall) && !cast<CallInst>(TheCall)->isTailCall();
Chris Lattner9f3dced2005-05-06 06:47:52 +000051
Chris Lattner0cc265e2003-08-24 06:59:16 +000052 BasicBlock *OrigBB = TheCall->getParent();
Chris Lattner530d4bf2003-05-29 15:11:31 +000053 Function *Caller = OrigBB->getParent();
54
Chris Lattner9fc977e2004-02-04 01:41:09 +000055 // Get an iterator to the last basic block in the function, which will have
56 // the new function inlined after it.
57 //
58 Function::iterator LastBlock = &Caller->back();
59
Chris Lattner18ef3fd2004-02-04 02:51:48 +000060 // Make sure to capture all of the return instructions from the cloned
Chris Lattner530d4bf2003-05-29 15:11:31 +000061 // function.
Chris Lattner18ef3fd2004-02-04 02:51:48 +000062 std::vector<ReturnInst*> Returns;
63 { // Scope to destroy ValueMap after cloning.
64 // Calculate the vector of arguments to pass into the function cloner...
65 std::map<const Value*, Value*> ValueMap;
Misha Brukmanb1c93172005-04-21 23:48:37 +000066 assert(std::distance(CalledFunc->arg_begin(), CalledFunc->arg_end()) ==
Chris Lattner18ef3fd2004-02-04 02:51:48 +000067 std::distance(CS.arg_begin(), CS.arg_end()) &&
68 "No varargs calls can be inlined!");
Misha Brukmanb1c93172005-04-21 23:48:37 +000069
Chris Lattner18ef3fd2004-02-04 02:51:48 +000070 CallSite::arg_iterator AI = CS.arg_begin();
Chris Lattner531f9e92005-03-15 04:54:21 +000071 for (Function::const_arg_iterator I = CalledFunc->arg_begin(),
72 E = CalledFunc->arg_end(); I != E; ++I, ++AI)
Chris Lattner18ef3fd2004-02-04 02:51:48 +000073 ValueMap[I] = *AI;
Misha Brukmanb1c93172005-04-21 23:48:37 +000074
75 // Clone the entire body of the callee into the caller.
Chris Lattner18ef3fd2004-02-04 02:51:48 +000076 CloneFunctionInto(Caller, CalledFunc, ValueMap, Returns, ".i");
Misha Brukmanb1c93172005-04-21 23:48:37 +000077 }
Chris Lattner6f8865b2004-02-04 21:33:42 +000078
Chris Lattner18ef3fd2004-02-04 02:51:48 +000079 // Remember the first block that is newly cloned over.
80 Function::iterator FirstNewBlock = LastBlock; ++FirstNewBlock;
Chris Lattner530d4bf2003-05-29 15:11:31 +000081
82 // If there are any alloca instructions in the block that used to be the entry
83 // block for the callee, move them to the entry block of the caller. First
84 // calculate which instruction they should be inserted before. We insert the
85 // instructions at the end of the current alloca list.
86 //
Chris Lattner257492c2006-01-13 18:16:48 +000087 {
Chris Lattner0cc265e2003-08-24 06:59:16 +000088 BasicBlock::iterator InsertPoint = Caller->begin()->begin();
Chris Lattner18ef3fd2004-02-04 02:51:48 +000089 for (BasicBlock::iterator I = FirstNewBlock->begin(),
90 E = FirstNewBlock->end(); I != E; )
Chris Lattnerb4778c72003-10-14 01:11:07 +000091 if (AllocaInst *AI = dyn_cast<AllocaInst>(I++))
92 if (isa<Constant>(AI->getArraySize())) {
Chris Lattner257492c2006-01-13 18:16:48 +000093 // Scan for the block of allocas that we can move over, and move them
94 // all at once.
Chris Lattner6f8865b2004-02-04 21:33:42 +000095 while (isa<AllocaInst>(I) &&
96 isa<Constant>(cast<AllocaInst>(I)->getArraySize()))
97 ++I;
98
99 // Transfer all of the allocas over in a block. Using splice means
100 // that they instructions aren't removed from the symbol table, then
101 // reinserted.
102 Caller->front().getInstList().splice(InsertPoint,
103 FirstNewBlock->getInstList(),
104 AI, I);
Chris Lattnerb4778c72003-10-14 01:11:07 +0000105 }
Chris Lattner0cc265e2003-08-24 06:59:16 +0000106 }
Chris Lattner530d4bf2003-05-29 15:11:31 +0000107
Jeff Cohen5f4ef3c2005-07-27 06:12:32 +0000108 // If we are inlining tail call instruction through an invoke or
Chris Lattner9f3dced2005-05-06 06:47:52 +0000109 if (MustClearTailCallFlags) {
110 for (Function::iterator BB = FirstNewBlock, E = Caller->end();
111 BB != E; ++BB)
112 for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
113 if (CallInst *CI = dyn_cast<CallInst>(I))
114 CI->setTailCall(false);
115 }
116
Chris Lattner18ef3fd2004-02-04 02:51:48 +0000117 // If we are inlining for an invoke instruction, we must make sure to rewrite
118 // any inlined 'unwind' instructions into branches to the invoke exception
119 // destination, and call instructions into invoke instructions.
120 if (InvokeInst *II = dyn_cast<InvokeInst>(TheCall)) {
Chris Lattnerfae8ab32004-02-08 21:44:31 +0000121 BasicBlock *InvokeDest = II->getUnwindDest();
Chris Lattner18ef3fd2004-02-04 02:51:48 +0000122 std::vector<Value*> InvokeDestPHIValues;
123
124 // If there are PHI nodes in the exceptional destination block, we need to
125 // keep track of which values came into them from this invoke, then remove
126 // the entry for this block.
Reid Spencer66149462004-09-15 17:06:42 +0000127 for (BasicBlock::iterator I = InvokeDest->begin(); isa<PHINode>(I); ++I) {
128 PHINode *PN = cast<PHINode>(I);
Chris Lattner18ef3fd2004-02-04 02:51:48 +0000129 // Save the value to use for this edge...
130 InvokeDestPHIValues.push_back(PN->getIncomingValueForBlock(OrigBB));
Reid Spencer66149462004-09-15 17:06:42 +0000131 }
Chris Lattner18ef3fd2004-02-04 02:51:48 +0000132
133 for (Function::iterator BB = FirstNewBlock, E = Caller->end();
134 BB != E; ++BB) {
Chris Lattner0cc265e2003-08-24 06:59:16 +0000135 for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) {
136 // We only need to check for function calls: inlined invoke instructions
137 // require no special handling...
138 if (CallInst *CI = dyn_cast<CallInst>(I)) {
Chris Lattner283ffdf2004-02-13 16:47:35 +0000139 // Convert this function call into an invoke instruction... if it's
Chris Lattner9f3dced2005-05-06 06:47:52 +0000140 // not an intrinsic function call (which are known to not unwind).
Chris Lattner283ffdf2004-02-13 16:47:35 +0000141 if (CI->getCalledFunction() &&
142 CI->getCalledFunction()->getIntrinsicID()) {
143 ++I;
144 } else {
145 // First, split the basic block...
146 BasicBlock *Split = BB->splitBasicBlock(CI, CI->getName()+".noexc");
Misha Brukmanb1c93172005-04-21 23:48:37 +0000147
Chris Lattner283ffdf2004-02-13 16:47:35 +0000148 // Next, create the new invoke instruction, inserting it at the end
149 // of the old basic block.
150 InvokeInst *II =
Misha Brukmanb1c93172005-04-21 23:48:37 +0000151 new InvokeInst(CI->getCalledValue(), Split, InvokeDest,
Chris Lattner283ffdf2004-02-13 16:47:35 +0000152 std::vector<Value*>(CI->op_begin()+1, CI->op_end()),
153 CI->getName(), BB->getTerminator());
Chris Lattner21d1dde2005-05-09 01:04:34 +0000154 II->setCallingConv(CI->getCallingConv());
Chris Lattner0cc265e2003-08-24 06:59:16 +0000155
Chris Lattner283ffdf2004-02-13 16:47:35 +0000156 // Make sure that anything using the call now uses the invoke!
157 CI->replaceAllUsesWith(II);
Misha Brukmanb1c93172005-04-21 23:48:37 +0000158
Chris Lattner283ffdf2004-02-13 16:47:35 +0000159 // Delete the unconditional branch inserted by splitBasicBlock
160 BB->getInstList().pop_back();
161 Split->getInstList().pop_front(); // Delete the original call
Misha Brukmanb1c93172005-04-21 23:48:37 +0000162
Chris Lattner283ffdf2004-02-13 16:47:35 +0000163 // Update any PHI nodes in the exceptional block to indicate that
164 // there is now a new entry in them.
165 unsigned i = 0;
166 for (BasicBlock::iterator I = InvokeDest->begin();
Reid Spencer66149462004-09-15 17:06:42 +0000167 isa<PHINode>(I); ++I, ++i) {
168 PHINode *PN = cast<PHINode>(I);
Chris Lattner283ffdf2004-02-13 16:47:35 +0000169 PN->addIncoming(InvokeDestPHIValues[i], BB);
Reid Spencer66149462004-09-15 17:06:42 +0000170 }
Misha Brukmanb1c93172005-04-21 23:48:37 +0000171
Chris Lattner283ffdf2004-02-13 16:47:35 +0000172 // This basic block is now complete, start scanning the next one.
173 break;
174 }
Chris Lattner0cc265e2003-08-24 06:59:16 +0000175 } else {
176 ++I;
177 }
178 }
Chris Lattner530d4bf2003-05-29 15:11:31 +0000179
Chris Lattner04ecefe2003-09-08 19:44:26 +0000180 if (UnwindInst *UI = dyn_cast<UnwindInst>(BB->getTerminator())) {
181 // An UnwindInst requires special handling when it gets inlined into an
182 // invoke site. Once this happens, we know that the unwind would cause
183 // a control transfer to the invoke exception destination, so we can
184 // transform it into a direct branch to the exception destination.
Chris Lattner2af51722003-11-20 18:25:24 +0000185 new BranchInst(InvokeDest, UI);
Chris Lattner04ecefe2003-09-08 19:44:26 +0000186
187 // Delete the unwind instruction!
188 UI->getParent()->getInstList().pop_back();
Chris Lattnerd9f4ffd2003-10-27 05:33:09 +0000189
190 // Update any PHI nodes in the exceptional block to indicate that
191 // there is now a new entry in them.
192 unsigned i = 0;
193 for (BasicBlock::iterator I = InvokeDest->begin();
Reid Spencer66149462004-09-15 17:06:42 +0000194 isa<PHINode>(I); ++I, ++i) {
195 PHINode *PN = cast<PHINode>(I);
Chris Lattnerd9f4ffd2003-10-27 05:33:09 +0000196 PN->addIncoming(InvokeDestPHIValues[i], BB);
Reid Spencer66149462004-09-15 17:06:42 +0000197 }
Chris Lattner04ecefe2003-09-08 19:44:26 +0000198 }
199 }
200
Chris Lattner0178d262003-09-22 21:59:27 +0000201 // Now that everything is happy, we have one final detail. The PHI nodes in
202 // the exception destination block still have entries due to the original
203 // invoke instruction. Eliminate these entries (which might even delete the
204 // PHI node) now.
Chris Lattner18ef3fd2004-02-04 02:51:48 +0000205 InvokeDest->removePredecessor(II->getParent());
Chris Lattner0178d262003-09-22 21:59:27 +0000206 }
Chris Lattner18ef3fd2004-02-04 02:51:48 +0000207
Chris Lattner0fa8c7c2004-02-04 04:17:06 +0000208 // If we cloned in _exactly one_ basic block, and if that block ends in a
209 // return instruction, we splice the body of the inlined callee directly into
210 // the calling basic block.
211 if (Returns.size() == 1 && std::distance(FirstNewBlock, Caller->end()) == 1) {
212 // Move all of the instructions right before the call.
213 OrigBB->getInstList().splice(TheCall, FirstNewBlock->getInstList(),
214 FirstNewBlock->begin(), FirstNewBlock->end());
215 // Remove the cloned basic block.
216 Caller->getBasicBlockList().pop_back();
Misha Brukmanb1c93172005-04-21 23:48:37 +0000217
Chris Lattner0fa8c7c2004-02-04 04:17:06 +0000218 // If the call site was an invoke instruction, add a branch to the normal
219 // destination.
220 if (InvokeInst *II = dyn_cast<InvokeInst>(TheCall))
221 new BranchInst(II->getNormalDest(), TheCall);
222
223 // If the return instruction returned a value, replace uses of the call with
224 // uses of the returned value.
225 if (!TheCall->use_empty())
226 TheCall->replaceAllUsesWith(Returns[0]->getReturnValue());
227
228 // Since we are now done with the Call/Invoke, we can delete it.
229 TheCall->getParent()->getInstList().erase(TheCall);
230
231 // Since we are now done with the return instruction, delete it also.
232 Returns[0]->getParent()->getInstList().erase(Returns[0]);
233
234 // We are now done with the inlining.
235 return true;
236 }
237
238 // Otherwise, we have the normal case, of more than one block to inline or
239 // multiple return sites.
240
Chris Lattner18ef3fd2004-02-04 02:51:48 +0000241 // We want to clone the entire callee function into the hole between the
242 // "starter" and "ender" blocks. How we accomplish this depends on whether
243 // this is an invoke instruction or a call instruction.
244 BasicBlock *AfterCallBB;
245 if (InvokeInst *II = dyn_cast<InvokeInst>(TheCall)) {
Misha Brukmanb1c93172005-04-21 23:48:37 +0000246
Chris Lattner18ef3fd2004-02-04 02:51:48 +0000247 // Add an unconditional branch to make this look like the CallInst case...
248 BranchInst *NewBr = new BranchInst(II->getNormalDest(), TheCall);
Misha Brukmanb1c93172005-04-21 23:48:37 +0000249
Chris Lattner18ef3fd2004-02-04 02:51:48 +0000250 // Split the basic block. This guarantees that no PHI nodes will have to be
251 // updated due to new incoming edges, and make the invoke case more
252 // symmetric to the call case.
253 AfterCallBB = OrigBB->splitBasicBlock(NewBr,
Chris Lattnerffefea02004-12-11 16:59:54 +0000254 CalledFunc->getName()+".exit");
Misha Brukmanb1c93172005-04-21 23:48:37 +0000255
Chris Lattner18ef3fd2004-02-04 02:51:48 +0000256 } else { // It's a call
Chris Lattner0fa8c7c2004-02-04 04:17:06 +0000257 // If this is a call instruction, we need to split the basic block that
258 // the call lives in.
Chris Lattner18ef3fd2004-02-04 02:51:48 +0000259 //
260 AfterCallBB = OrigBB->splitBasicBlock(TheCall,
Chris Lattnerffefea02004-12-11 16:59:54 +0000261 CalledFunc->getName()+".exit");
Chris Lattner18ef3fd2004-02-04 02:51:48 +0000262 }
263
Chris Lattner0fa8c7c2004-02-04 04:17:06 +0000264 // Change the branch that used to go to AfterCallBB to branch to the first
265 // basic block of the inlined function.
266 //
267 TerminatorInst *Br = OrigBB->getTerminator();
Misha Brukmanb1c93172005-04-21 23:48:37 +0000268 assert(Br && Br->getOpcode() == Instruction::Br &&
Chris Lattner0fa8c7c2004-02-04 04:17:06 +0000269 "splitBasicBlock broken!");
270 Br->setOperand(0, FirstNewBlock);
271
272
273 // Now that the function is correct, make it a little bit nicer. In
274 // particular, move the basic blocks inserted from the end of the function
275 // into the space made by splitting the source basic block.
276 //
277 Caller->getBasicBlockList().splice(AfterCallBB, Caller->getBasicBlockList(),
278 FirstNewBlock, Caller->end());
279
Chris Lattner18ef3fd2004-02-04 02:51:48 +0000280 // Handle all of the return instructions that we just cloned in, and eliminate
281 // any users of the original call/invoke instruction.
282 if (Returns.size() > 1) {
283 // The PHI node should go at the front of the new basic block to merge all
284 // possible incoming values.
285 //
286 PHINode *PHI = 0;
287 if (!TheCall->use_empty()) {
288 PHI = new PHINode(CalledFunc->getReturnType(),
289 TheCall->getName(), AfterCallBB->begin());
Misha Brukmanb1c93172005-04-21 23:48:37 +0000290
Chris Lattner18ef3fd2004-02-04 02:51:48 +0000291 // Anything that used the result of the function call should now use the
292 // PHI node as their operand.
293 //
294 TheCall->replaceAllUsesWith(PHI);
295 }
Misha Brukmanb1c93172005-04-21 23:48:37 +0000296
Chris Lattner18ef3fd2004-02-04 02:51:48 +0000297 // Loop over all of the return instructions, turning them into unconditional
298 // branches to the merge point now, and adding entries to the PHI node as
299 // appropriate.
300 for (unsigned i = 0, e = Returns.size(); i != e; ++i) {
301 ReturnInst *RI = Returns[i];
Misha Brukmanb1c93172005-04-21 23:48:37 +0000302
Chris Lattner18ef3fd2004-02-04 02:51:48 +0000303 if (PHI) {
304 assert(RI->getReturnValue() && "Ret should have value!");
Misha Brukmanb1c93172005-04-21 23:48:37 +0000305 assert(RI->getReturnValue()->getType() == PHI->getType() &&
Chris Lattner18ef3fd2004-02-04 02:51:48 +0000306 "Ret value not consistent in function!");
307 PHI->addIncoming(RI->getReturnValue(), RI->getParent());
308 }
Misha Brukmanb1c93172005-04-21 23:48:37 +0000309
Chris Lattner18ef3fd2004-02-04 02:51:48 +0000310 // Add a branch to the merge point where the PHI node lives if it exists.
311 new BranchInst(AfterCallBB, RI);
Misha Brukmanb1c93172005-04-21 23:48:37 +0000312
Chris Lattner18ef3fd2004-02-04 02:51:48 +0000313 // Delete the return instruction now
314 RI->getParent()->getInstList().erase(RI);
315 }
Misha Brukmanb1c93172005-04-21 23:48:37 +0000316
Chris Lattner18ef3fd2004-02-04 02:51:48 +0000317 } else if (!Returns.empty()) {
318 // Otherwise, if there is exactly one return value, just replace anything
319 // using the return value of the call with the computed value.
320 if (!TheCall->use_empty())
321 TheCall->replaceAllUsesWith(Returns[0]->getReturnValue());
Misha Brukmanb1c93172005-04-21 23:48:37 +0000322
Chris Lattner0328d752004-04-16 05:17:59 +0000323 // Splice the code from the return block into the block that it will return
324 // to, which contains the code that was after the call.
325 BasicBlock *ReturnBB = Returns[0]->getParent();
Chris Lattner45b50d12004-07-20 05:45:24 +0000326 AfterCallBB->getInstList().splice(AfterCallBB->begin(),
327 ReturnBB->getInstList());
Chris Lattner0328d752004-04-16 05:17:59 +0000328
Chris Lattner45b50d12004-07-20 05:45:24 +0000329 // Update PHI nodes that use the ReturnBB to use the AfterCallBB.
330 ReturnBB->replaceAllUsesWith(AfterCallBB);
Misha Brukmanb1c93172005-04-21 23:48:37 +0000331
Chris Lattner45b50d12004-07-20 05:45:24 +0000332 // Delete the return instruction now and empty ReturnBB now.
Chris Lattner6e79e552004-10-17 23:21:07 +0000333 Returns[0]->eraseFromParent();
334 ReturnBB->eraseFromParent();
335 } else if (!TheCall->use_empty()) {
336 // No returns, but something is using the return value of the call. Just
337 // nuke the result.
338 TheCall->replaceAllUsesWith(UndefValue::get(TheCall->getType()));
Chris Lattner18ef3fd2004-02-04 02:51:48 +0000339 }
Misha Brukmanb1c93172005-04-21 23:48:37 +0000340
Chris Lattner18ef3fd2004-02-04 02:51:48 +0000341 // Since we are now done with the Call/Invoke, we can delete it.
Chris Lattner6e79e552004-10-17 23:21:07 +0000342 TheCall->eraseFromParent();
Chris Lattner530d4bf2003-05-29 15:11:31 +0000343
Chris Lattnerfc3fe5c2003-08-24 04:06:56 +0000344 // We should always be able to fold the entry block of the function into the
345 // single predecessor of the block...
Chris Lattner0328d752004-04-16 05:17:59 +0000346 assert(cast<BranchInst>(Br)->isUnconditional() && "splitBasicBlock broken!");
Chris Lattnerfc3fe5c2003-08-24 04:06:56 +0000347 BasicBlock *CalleeEntry = cast<BranchInst>(Br)->getSuccessor(0);
Chris Lattner0fa8c7c2004-02-04 04:17:06 +0000348
Chris Lattner0328d752004-04-16 05:17:59 +0000349 // Splice the code entry block into calling block, right before the
350 // unconditional branch.
351 OrigBB->getInstList().splice(Br, CalleeEntry->getInstList());
352 CalleeEntry->replaceAllUsesWith(OrigBB); // Update PHI nodes
353
354 // Remove the unconditional branch.
355 OrigBB->getInstList().erase(Br);
356
357 // Now we can remove the CalleeEntry block, which is now empty.
358 Caller->getBasicBlockList().erase(CalleeEntry);
Chris Lattner530d4bf2003-05-29 15:11:31 +0000359 return true;
360}