Undo a change made in r140254.
[oota-llvm.git] / lib / VMCore / AutoUpgrade.cpp
1 //===-- AutoUpgrade.cpp - Implement auto-upgrade helper functions ---------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the auto-upgrade helper functions 
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/AutoUpgrade.h"
15 #include "llvm/Constants.h"
16 #include "llvm/Function.h"
17 #include "llvm/Instruction.h"
18 #include "llvm/LLVMContext.h"
19 #include "llvm/Module.h"
20 #include "llvm/IntrinsicInst.h"
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/ADT/SmallPtrSet.h"
23 #include "llvm/ADT/SmallVector.h"
24 #include "llvm/Support/CallSite.h"
25 #include "llvm/Support/CFG.h"
26 #include "llvm/Support/ErrorHandling.h"
27 #include "llvm/Support/IRBuilder.h"
28 #include <cstring>
29 using namespace llvm;
30
31
32 static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
33   assert(F && "Illegal to upgrade a non-existent Function.");
34
35   // Quickly eliminate it, if it's not a candidate.
36   StringRef Name = F->getName();
37   if (Name.size() <= 8 || !Name.startswith("llvm."))
38     return false;
39   Name = Name.substr(5); // Strip off "llvm."
40
41   FunctionType *FTy = F->getFunctionType();
42   Module *M = F->getParent();
43   
44   switch (Name[0]) {
45   default: break;
46   case 'i':
47     //  This upgrades the old llvm.init.trampoline to the new
48     //  llvm.init.trampoline and llvm.adjust.trampoline pair.
49     if (Name == "init.trampoline") {
50       // The new llvm.init.trampoline returns nothing.
51       if (FTy->getReturnType()->isVoidTy())
52         break;
53
54       assert(FTy->getNumParams() == 3 && "old init.trampoline takes 3 args!");
55
56       // Change the name of the old intrinsic so that we can play with its type.
57       std::string NameTmp = F->getName();
58       F->setName("");
59       NewFn = cast<Function>(M->getOrInsertFunction(
60                                NameTmp,
61                                Type::getVoidTy(M->getContext()),
62                                FTy->getParamType(0), FTy->getParamType(1),
63                                FTy->getParamType(2), (Type *)0));
64       return true;
65     }
66   case 'p':
67     //  This upgrades the llvm.prefetch intrinsic to accept one more parameter,
68     //  which is a instruction / data cache identifier. The old version only
69     //  implicitly accepted the data version.
70     if (Name == "prefetch") {
71       // Don't do anything if it has the correct number of arguments already
72       if (FTy->getNumParams() == 4)
73         break;
74
75       assert(FTy->getNumParams() == 3 && "old prefetch takes 3 args!");
76       //  We first need to change the name of the old (bad) intrinsic, because
77       //  its type is incorrect, but we cannot overload that name. We
78       //  arbitrarily unique it here allowing us to construct a correctly named
79       //  and typed function below.
80       std::string NameTmp = F->getName();
81       F->setName("");
82       NewFn = cast<Function>(M->getOrInsertFunction(NameTmp,
83                                                     FTy->getReturnType(),
84                                                     FTy->getParamType(0),
85                                                     FTy->getParamType(1),
86                                                     FTy->getParamType(2),
87                                                     FTy->getParamType(2),
88                                                     (Type*)0));
89       return true;
90     }
91
92     break;
93   case 'x': {
94     const char *NewFnName = NULL;
95     // This fixes the poorly named crc32 intrinsics.
96     if (Name == "x86.sse42.crc32.8")
97       NewFnName = "llvm.x86.sse42.crc32.32.8";
98     else if (Name == "x86.sse42.crc32.16")
99       NewFnName = "llvm.x86.sse42.crc32.32.16";
100     else if (Name == "x86.sse42.crc32.32")
101       NewFnName = "llvm.x86.sse42.crc32.32.32";
102     else if (Name == "x86.sse42.crc64.8")
103       NewFnName = "llvm.x86.sse42.crc32.64.8";
104     else if (Name == "x86.sse42.crc64.64")
105       NewFnName = "llvm.x86.sse42.crc32.64.64";
106     
107     if (NewFnName) {
108       F->setName(NewFnName);
109       NewFn = F;
110       return true;
111     }
112
113     // Calls to these instructions are transformed into unaligned loads.
114     if (Name == "x86.sse.loadu.ps" || Name == "x86.sse2.loadu.dq" ||
115         Name == "x86.sse2.loadu.pd")
116       return true;
117       
118     // Calls to these instructions are transformed into nontemporal stores.
119     if (Name == "x86.sse.movnt.ps"  || Name == "x86.sse2.movnt.dq" ||
120         Name == "x86.sse2.movnt.pd" || Name == "x86.sse2.movnt.i")
121       return true;
122
123     break;
124   }
125   }
126
127   //  This may not belong here. This function is effectively being overloaded 
128   //  to both detect an intrinsic which needs upgrading, and to provide the 
129   //  upgraded form of the intrinsic. We should perhaps have two separate 
130   //  functions for this.
131   return false;
132 }
133
134 bool llvm::UpgradeIntrinsicFunction(Function *F, Function *&NewFn) {
135   NewFn = 0;
136   bool Upgraded = UpgradeIntrinsicFunction1(F, NewFn);
137
138   // Upgrade intrinsic attributes.  This does not change the function.
139   if (NewFn)
140     F = NewFn;
141   if (unsigned id = F->getIntrinsicID())
142     F->setAttributes(Intrinsic::getAttributes((Intrinsic::ID)id));
143   return Upgraded;
144 }
145
146 bool llvm::UpgradeGlobalVariable(GlobalVariable *GV) {
147   // Nothing to do yet.
148   return false;
149 }
150
151 // UpgradeIntrinsicCall - Upgrade a call to an old intrinsic to be a call the 
152 // upgraded intrinsic. All argument and return casting must be provided in 
153 // order to seamlessly integrate with existing context.
154 void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
155   Function *F = CI->getCalledFunction();
156   LLVMContext &C = CI->getContext();
157   ImmutableCallSite CS(CI);
158
159   assert(F && "CallInst has no function associated with it.");
160
161   if (!NewFn) {
162     if (F->getName() == "llvm.x86.sse.loadu.ps" ||
163         F->getName() == "llvm.x86.sse2.loadu.dq" ||
164         F->getName() == "llvm.x86.sse2.loadu.pd") {
165       // Convert to a native, unaligned load.
166       Type *VecTy = CI->getType();
167       Type *IntTy = IntegerType::get(C, 128);
168       IRBuilder<> Builder(C);
169       Builder.SetInsertPoint(CI->getParent(), CI);
170
171       Value *BC = Builder.CreateBitCast(CI->getArgOperand(0),
172                                         PointerType::getUnqual(IntTy),
173                                         "cast");
174       LoadInst *LI = Builder.CreateLoad(BC, CI->getName());
175       LI->setAlignment(1);      // Unaligned load.
176       BC = Builder.CreateBitCast(LI, VecTy, "new.cast");
177
178       // Fix up all the uses with our new load.
179       if (!CI->use_empty())
180         CI->replaceAllUsesWith(BC);
181
182       // Remove intrinsic.
183       CI->eraseFromParent();
184     } else if (F->getName() == "llvm.x86.sse.movnt.ps" ||
185                F->getName() == "llvm.x86.sse2.movnt.dq" ||
186                F->getName() == "llvm.x86.sse2.movnt.pd" ||
187                F->getName() == "llvm.x86.sse2.movnt.i") {
188       IRBuilder<> Builder(C);
189       Builder.SetInsertPoint(CI->getParent(), CI);
190
191       Module *M = F->getParent();
192       SmallVector<Value *, 1> Elts;
193       Elts.push_back(ConstantInt::get(Type::getInt32Ty(C), 1));
194       MDNode *Node = MDNode::get(C, Elts);
195
196       Value *Arg0 = CI->getArgOperand(0);
197       Value *Arg1 = CI->getArgOperand(1);
198
199       // Convert the type of the pointer to a pointer to the stored type.
200       Value *BC = Builder.CreateBitCast(Arg0,
201                                         PointerType::getUnqual(Arg1->getType()),
202                                         "cast");
203       StoreInst *SI = Builder.CreateStore(Arg1, BC);
204       SI->setMetadata(M->getMDKindID("nontemporal"), Node);
205       SI->setAlignment(16);
206
207       // Remove intrinsic.
208       CI->eraseFromParent();
209     } else {
210       llvm_unreachable("Unknown function for CallInst upgrade.");
211     }
212     return;
213   }
214
215   switch (NewFn->getIntrinsicID()) {
216   case Intrinsic::prefetch: {
217     IRBuilder<> Builder(C);
218     Builder.SetInsertPoint(CI->getParent(), CI);
219     llvm::Type *I32Ty = llvm::Type::getInt32Ty(CI->getContext());
220
221     // Add the extra "data cache" argument
222     Value *Operands[4] = { CI->getArgOperand(0), CI->getArgOperand(1),
223                            CI->getArgOperand(2),
224                            llvm::ConstantInt::get(I32Ty, 1) };
225     CallInst *NewCI = CallInst::Create(NewFn, Operands,
226                                        CI->getName(), CI);
227     NewCI->setTailCall(CI->isTailCall());
228     NewCI->setCallingConv(CI->getCallingConv());
229     //  Handle any uses of the old CallInst.
230     if (!CI->use_empty())
231       //  Replace all uses of the old call with the new cast which has the
232       //  correct type.
233       CI->replaceAllUsesWith(NewCI);
234
235     //  Clean up the old call now that it has been completely upgraded.
236     CI->eraseFromParent();
237     break;
238   }
239   case Intrinsic::init_trampoline: {
240
241     //  Transform
242     //    %tramp = call i8* llvm.init.trampoline (i8* x, i8* y, i8* z)
243     //  to
244     //    call void llvm.init.trampoline (i8* %x, i8* %y, i8* %z)
245     //    %tramp = call i8* llvm.adjust.trampoline (i8* %x)
246
247     Function *AdjustTrampolineFn =
248       cast<Function>(Intrinsic::getDeclaration(F->getParent(),
249                                                Intrinsic::adjust_trampoline));
250
251     IRBuilder<> Builder(C);
252     Builder.SetInsertPoint(CI);
253
254     Builder.CreateCall3(NewFn, CI->getArgOperand(0), CI->getArgOperand(1),
255                         CI->getArgOperand(2));
256
257     CallInst *AdjustCall = Builder.CreateCall(AdjustTrampolineFn,
258                                               CI->getArgOperand(0),
259                                               CI->getName());
260     if (!CI->use_empty())
261       CI->replaceAllUsesWith(AdjustCall);
262     CI->eraseFromParent();
263     break;
264   }
265   }
266 }
267
268 // This tests each Function to determine if it needs upgrading. When we find 
269 // one we are interested in, we then upgrade all calls to reflect the new 
270 // function.
271 void llvm::UpgradeCallsToIntrinsic(Function* F) {
272   assert(F && "Illegal attempt to upgrade a non-existent intrinsic.");
273
274   // Upgrade the function and check if it is a totaly new function.
275   Function *NewFn;
276   if (UpgradeIntrinsicFunction(F, NewFn)) {
277     if (NewFn != F) {
278       // Replace all uses to the old function with the new one if necessary.
279       for (Value::use_iterator UI = F->use_begin(), UE = F->use_end();
280            UI != UE; ) {
281         if (CallInst *CI = dyn_cast<CallInst>(*UI++))
282           UpgradeIntrinsicCall(CI, NewFn);
283       }
284       // Remove old function, no longer used, from the module.
285       F->eraseFromParent();
286     }
287   }
288 }
289
290 /// This function strips all debug info intrinsics, except for llvm.dbg.declare.
291 /// If an llvm.dbg.declare intrinsic is invalid, then this function simply
292 /// strips that use.
293 void llvm::CheckDebugInfoIntrinsics(Module *M) {
294   if (Function *FuncStart = M->getFunction("llvm.dbg.func.start")) {
295     while (!FuncStart->use_empty())
296       cast<CallInst>(FuncStart->use_back())->eraseFromParent();
297     FuncStart->eraseFromParent();
298   }
299   
300   if (Function *StopPoint = M->getFunction("llvm.dbg.stoppoint")) {
301     while (!StopPoint->use_empty())
302       cast<CallInst>(StopPoint->use_back())->eraseFromParent();
303     StopPoint->eraseFromParent();
304   }
305
306   if (Function *RegionStart = M->getFunction("llvm.dbg.region.start")) {
307     while (!RegionStart->use_empty())
308       cast<CallInst>(RegionStart->use_back())->eraseFromParent();
309     RegionStart->eraseFromParent();
310   }
311
312   if (Function *RegionEnd = M->getFunction("llvm.dbg.region.end")) {
313     while (!RegionEnd->use_empty())
314       cast<CallInst>(RegionEnd->use_back())->eraseFromParent();
315     RegionEnd->eraseFromParent();
316   }
317   
318   if (Function *Declare = M->getFunction("llvm.dbg.declare")) {
319     if (!Declare->use_empty()) {
320       DbgDeclareInst *DDI = cast<DbgDeclareInst>(Declare->use_back());
321       if (!isa<MDNode>(DDI->getArgOperand(0)) ||
322           !isa<MDNode>(DDI->getArgOperand(1))) {
323         while (!Declare->use_empty()) {
324           CallInst *CI = cast<CallInst>(Declare->use_back());
325           CI->eraseFromParent();
326         }
327         Declare->eraseFromParent();
328       }
329     }
330   }
331 }
332
333 /// FindExnAndSelIntrinsics - Find the eh_exception and eh_selector intrinsic
334 /// calls reachable from the unwind basic block.
335 static void FindExnAndSelIntrinsics(BasicBlock *BB, CallInst *&Exn,
336                                     CallInst *&Sel,
337                                     SmallPtrSet<BasicBlock*, 8> &Visited) {
338   if (!Visited.insert(BB)) return;
339
340   for (BasicBlock::iterator
341          I = BB->begin(), E = BB->end(); I != E; ++I) {
342     if (CallInst *CI = dyn_cast<CallInst>(I)) {
343       switch (CI->getCalledFunction()->getIntrinsicID()) {
344       default: break;
345       case Intrinsic::eh_exception:
346         assert(!Exn && "Found more than one eh.exception call!");
347         Exn = CI;
348         break;
349       case Intrinsic::eh_selector:
350         assert(!Sel && "Found more than one eh.selector call!");
351         Sel = CI;
352         break;
353       }
354
355       if (Exn && Sel) return;
356     }
357   }
358
359   if (Exn && Sel) return;
360
361   for (succ_iterator I = succ_begin(BB), E = succ_end(BB); I != E; ++I) {
362     FindExnAndSelIntrinsics(*I, Exn, Sel, Visited);
363     if (Exn && Sel) return;
364   }
365 }
366
367 /// TransferClausesToLandingPadInst - Transfer the exception handling clauses
368 /// from the eh_selector call to the new landingpad instruction.
369 static void TransferClausesToLandingPadInst(LandingPadInst *LPI,
370                                             CallInst *EHSel) {
371   LLVMContext &Context = LPI->getContext();
372   unsigned N = EHSel->getNumArgOperands();
373
374   for (unsigned i = N - 1; i > 1; --i) {
375     if (const ConstantInt *CI = dyn_cast<ConstantInt>(EHSel->getArgOperand(i))){
376       unsigned FilterLength = CI->getZExtValue();
377       unsigned FirstCatch = i + FilterLength + !FilterLength;
378       assert(FirstCatch <= N && "Invalid filter length");
379
380       if (FirstCatch < N)
381         for (unsigned j = FirstCatch; j < N; ++j) {
382           Value *Val = EHSel->getArgOperand(j);
383           if (!Val->hasName() || Val->getName() != "llvm.eh.catch.all.value") {
384             LPI->addClause(EHSel->getArgOperand(j));
385           } else {
386             GlobalVariable *GV = cast<GlobalVariable>(Val);
387             LPI->addClause(GV->getInitializer());
388           }
389         }
390
391       if (!FilterLength) {
392         // Cleanup.
393         LPI->setCleanup(true);
394       } else {
395         // Filter.
396         SmallVector<Constant *, 4> TyInfo;
397         TyInfo.reserve(FilterLength - 1);
398         for (unsigned j = i + 1; j < FirstCatch; ++j)
399           TyInfo.push_back(cast<Constant>(EHSel->getArgOperand(j)));
400         ArrayType *AType =
401           ArrayType::get(!TyInfo.empty() ? TyInfo[0]->getType() :
402                          PointerType::getUnqual(Type::getInt8Ty(Context)),
403                          TyInfo.size());
404         LPI->addClause(ConstantArray::get(AType, TyInfo));
405       }
406
407       N = i;
408     }
409   }
410
411   if (N > 2)
412     for (unsigned j = 2; j < N; ++j) {
413       Value *Val = EHSel->getArgOperand(j);
414       if (!Val->hasName() || Val->getName() != "llvm.eh.catch.all.value") {
415         LPI->addClause(EHSel->getArgOperand(j));
416       } else {
417         GlobalVariable *GV = cast<GlobalVariable>(Val);
418         LPI->addClause(GV->getInitializer());
419       }
420     }
421 }
422
423 /// This function upgrades the old pre-3.0 exception handling system to the new
424 /// one. N.B. This will be removed in 3.1.
425 void llvm::UpgradeExceptionHandling(Module *M) {
426   Function *EHException = M->getFunction("llvm.eh.exception");
427   Function *EHSelector = M->getFunction("llvm.eh.selector");
428   if (!EHException || !EHSelector)
429     return;
430
431   LLVMContext &Context = M->getContext();
432   Type *ExnTy = PointerType::getUnqual(Type::getInt8Ty(Context));
433   Type *SelTy = Type::getInt32Ty(Context);
434   Type *LPadSlotTy = StructType::get(ExnTy, SelTy, NULL);
435
436   // This map links the invoke instruction with the eh.exception and eh.selector
437   // calls associated with it.
438   DenseMap<InvokeInst*, std::pair<Value*, Value*> > InvokeToIntrinsicsMap;
439   for (Module::iterator
440          I = M->begin(), E = M->end(); I != E; ++I) {
441     Function &F = *I;
442
443     for (Function::iterator
444            II = F.begin(), IE = F.end(); II != IE; ++II) {
445       BasicBlock *BB = &*II;
446       InvokeInst *Inst = dyn_cast<InvokeInst>(BB->getTerminator());
447       if (!Inst) continue;
448       BasicBlock *UnwindDest = Inst->getUnwindDest();
449       if (UnwindDest->isLandingPad()) continue; // Already converted.
450
451       SmallPtrSet<BasicBlock*, 8> Visited;
452       CallInst *Exn = 0;
453       CallInst *Sel = 0;
454       FindExnAndSelIntrinsics(UnwindDest, Exn, Sel, Visited);
455       assert(Exn && Sel && "Cannot find eh.exception and eh.selector calls!");
456       InvokeToIntrinsicsMap[Inst] = std::make_pair(Exn, Sel);
457     }
458   }
459
460   // This map stores the slots where the exception object and selector value are
461   // stored within a function.
462   DenseMap<Function*, std::pair<Value*, Value*> > FnToLPadSlotMap;
463   SmallPtrSet<Instruction*, 32> DeadInsts;
464   for (DenseMap<InvokeInst*, std::pair<Value*, Value*> >::iterator
465          I = InvokeToIntrinsicsMap.begin(), E = InvokeToIntrinsicsMap.end();
466        I != E; ++I) {
467     InvokeInst *Invoke = I->first;
468     BasicBlock *UnwindDest = Invoke->getUnwindDest();
469     Function *F = UnwindDest->getParent();
470     std::pair<Value*, Value*> EHIntrinsics = I->second;
471     CallInst *Exn = cast<CallInst>(EHIntrinsics.first);
472     CallInst *Sel = cast<CallInst>(EHIntrinsics.second);
473
474     // Store the exception object and selector value in the entry block.
475     Value *ExnSlot = 0;
476     Value *SelSlot = 0;
477     if (!FnToLPadSlotMap[F].first) {
478       BasicBlock *Entry = &F->front();
479       ExnSlot = new AllocaInst(ExnTy, "exn", Entry->getTerminator());
480       SelSlot = new AllocaInst(SelTy, "sel", Entry->getTerminator());
481       FnToLPadSlotMap[F] = std::make_pair(ExnSlot, SelSlot);
482     } else {
483       ExnSlot = FnToLPadSlotMap[F].first;
484       SelSlot = FnToLPadSlotMap[F].second;
485     }
486
487     if (!UnwindDest->getSinglePredecessor()) {
488       // The unwind destination doesn't have a single predecessor. Create an
489       // unwind destination which has only one predecessor.
490       BasicBlock *NewBB = BasicBlock::Create(Context, "new.lpad",
491                                              UnwindDest->getParent());
492       BranchInst::Create(UnwindDest, NewBB);
493       Invoke->setUnwindDest(NewBB);
494
495       // Fix up any PHIs in the original unwind destination block.
496       for (BasicBlock::iterator
497              II = UnwindDest->begin(); isa<PHINode>(II); ++II) {
498         PHINode *PN = cast<PHINode>(II);
499         int Idx = PN->getBasicBlockIndex(Invoke->getParent());
500         if (Idx == -1) continue;
501         PN->setIncomingBlock(Idx, NewBB);
502       }
503
504       UnwindDest = NewBB;
505     }
506
507     IRBuilder<> Builder(Context);
508     Builder.SetInsertPoint(UnwindDest, UnwindDest->getFirstInsertionPt());
509
510     Value *PersFn = Sel->getArgOperand(1);
511     LandingPadInst *LPI = Builder.CreateLandingPad(LPadSlotTy, PersFn, 0);
512     Value *LPExn = Builder.CreateExtractValue(LPI, 0);
513     Value *LPSel = Builder.CreateExtractValue(LPI, 1);
514     Builder.CreateStore(LPExn, ExnSlot);
515     Builder.CreateStore(LPSel, SelSlot);
516
517     TransferClausesToLandingPadInst(LPI, Sel);
518
519     DeadInsts.insert(Exn);
520     DeadInsts.insert(Sel);
521   }
522
523   // Replace the old intrinsic calls with the values from the landingpad
524   // instruction(s). These values were stored in allocas for us to use here.
525   for (DenseMap<InvokeInst*, std::pair<Value*, Value*> >::iterator
526          I = InvokeToIntrinsicsMap.begin(), E = InvokeToIntrinsicsMap.end();
527        I != E; ++I) {
528     std::pair<Value*, Value*> EHIntrinsics = I->second;
529     CallInst *Exn = cast<CallInst>(EHIntrinsics.first);
530     CallInst *Sel = cast<CallInst>(EHIntrinsics.second);
531     BasicBlock *Parent = Exn->getParent();
532
533     std::pair<Value*,Value*> ExnSelSlots = FnToLPadSlotMap[Parent->getParent()];
534
535     IRBuilder<> Builder(Context);
536     Builder.SetInsertPoint(Parent, Exn);
537     LoadInst *LPExn = Builder.CreateLoad(ExnSelSlots.first, "exn.load");
538     LoadInst *LPSel = Builder.CreateLoad(ExnSelSlots.second, "sel.load");
539
540     Exn->replaceAllUsesWith(LPExn);
541     Sel->replaceAllUsesWith(LPSel);
542   }
543
544   // Remove the dead instructions.
545   for (SmallPtrSet<Instruction*, 32>::iterator
546          I = DeadInsts.begin(), E = DeadInsts.end(); I != E; ++I) {
547     Instruction *Inst = *I;
548     Inst->eraseFromParent();
549   }
550
551   // Replace calls to "llvm.eh.resume" with the 'resume' instruction. Load the
552   // exception and selector values from the stored place.
553   Function *EHResume = M->getFunction("llvm.eh.resume");
554   if (!EHResume) return;
555
556   while (!EHResume->use_empty()) {
557     CallInst *Resume = cast<CallInst>(EHResume->use_back());
558     BasicBlock *BB = Resume->getParent();
559
560     IRBuilder<> Builder(Context);
561     Builder.SetInsertPoint(BB, Resume);
562
563     Value *LPadVal =
564       Builder.CreateInsertValue(UndefValue::get(LPadSlotTy),
565                                 Resume->getArgOperand(0), 0, "lpad.val");
566     LPadVal = Builder.CreateInsertValue(LPadVal, Resume->getArgOperand(1),
567                                         1, "lpad.val");
568     Builder.CreateResume(LPadVal);
569
570     // Remove all instructions after the 'resume.'
571     BasicBlock::iterator I = Resume;
572     while (I != BB->end()) {
573       Instruction *Inst = &*I++;
574       Inst->eraseFromParent();
575     }
576   }
577 }