Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 1 | //===-- LowerGC.cpp - Provide GC support for targets that don't -----------===// |
| 2 | // |
| 3 | // 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. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements lowering for the llvm.gc* intrinsics for targets that do |
| 11 | // not natively support them (which includes the C backend). Note that the code |
| 12 | // generated is not as efficient as it would be for targets that natively |
| 13 | // support the GC intrinsics, but it is useful for getting new targets |
| 14 | // up-and-running quickly. |
| 15 | // |
| 16 | // This pass implements the code transformation described in this paper: |
| 17 | // "Accurate Garbage Collection in an Uncooperative Environment" |
Chris Lattner | f52988a | 2004-05-23 21:27:29 +0000 | [diff] [blame] | 18 | // Fergus Henderson, ISMM, 2002 |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 19 | // |
| 20 | //===----------------------------------------------------------------------===// |
| 21 | |
| 22 | #define DEBUG_TYPE "lowergc" |
| 23 | #include "llvm/Transforms/Scalar.h" |
| 24 | #include "llvm/Constants.h" |
| 25 | #include "llvm/DerivedTypes.h" |
| 26 | #include "llvm/Instructions.h" |
| 27 | #include "llvm/Module.h" |
| 28 | #include "llvm/Pass.h" |
Chris Lattner | a4f0b3a | 2006-08-27 12:54:02 +0000 | [diff] [blame] | 29 | #include "llvm/Support/Compiler.h" |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 30 | using namespace llvm; |
| 31 | |
| 32 | namespace { |
Chris Lattner | f4b5461 | 2006-06-28 22:08:15 +0000 | [diff] [blame] | 33 | class VISIBILITY_HIDDEN LowerGC : public FunctionPass { |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 34 | /// GCRootInt, GCReadInt, GCWriteInt - The function prototypes for the |
| 35 | /// llvm.gcread/llvm.gcwrite/llvm.gcroot intrinsics. |
| 36 | Function *GCRootInt, *GCReadInt, *GCWriteInt; |
| 37 | |
| 38 | /// GCRead/GCWrite - These are the functions provided by the garbage |
| 39 | /// collector for read/write barriers. |
Chris Lattner | 9214196 | 2007-01-07 06:58:05 +0000 | [diff] [blame^] | 40 | Constant *GCRead, *GCWrite; |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 41 | |
| 42 | /// RootChain - This is the global linked-list that contains the chain of GC |
| 43 | /// roots. |
| 44 | GlobalVariable *RootChain; |
| 45 | |
| 46 | /// MainRootRecordType - This is the type for a function root entry if it |
| 47 | /// had zero roots. |
| 48 | const Type *MainRootRecordType; |
| 49 | public: |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 50 | LowerGC() : GCRootInt(0), GCReadInt(0), GCWriteInt(0), |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 51 | GCRead(0), GCWrite(0), RootChain(0), MainRootRecordType(0) {} |
| 52 | virtual bool doInitialization(Module &M); |
| 53 | virtual bool runOnFunction(Function &F); |
| 54 | |
| 55 | private: |
| 56 | const StructType *getRootRecordType(unsigned NumRoots); |
| 57 | }; |
| 58 | |
Chris Lattner | 7f8897f | 2006-08-27 22:42:52 +0000 | [diff] [blame] | 59 | RegisterPass<LowerGC> |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 60 | X("lowergc", "Lower GC intrinsics, for GCless code generators"); |
| 61 | } |
| 62 | |
| 63 | /// createLowerGCPass - This function returns an instance of the "lowergc" |
| 64 | /// pass, which lowers garbage collection intrinsics to normal LLVM code. |
| 65 | FunctionPass *llvm::createLowerGCPass() { |
| 66 | return new LowerGC(); |
| 67 | } |
| 68 | |
| 69 | /// getRootRecordType - This function creates and returns the type for a root |
| 70 | /// record containing 'NumRoots' roots. |
| 71 | const StructType *LowerGC::getRootRecordType(unsigned NumRoots) { |
| 72 | // Build a struct that is a type used for meta-data/root pairs. |
| 73 | std::vector<const Type *> ST; |
| 74 | ST.push_back(GCRootInt->getFunctionType()->getParamType(0)); |
| 75 | ST.push_back(GCRootInt->getFunctionType()->getParamType(1)); |
| 76 | StructType *PairTy = StructType::get(ST); |
| 77 | |
| 78 | // Build the array of pairs. |
| 79 | ArrayType *PairArrTy = ArrayType::get(PairTy, NumRoots); |
| 80 | |
| 81 | // Now build the recursive list type. |
| 82 | PATypeHolder RootListH = |
| 83 | MainRootRecordType ? (Type*)MainRootRecordType : (Type*)OpaqueType::get(); |
| 84 | ST.clear(); |
| 85 | ST.push_back(PointerType::get(RootListH)); // Prev pointer |
Reid Spencer | c5b206b | 2006-12-31 05:48:39 +0000 | [diff] [blame] | 86 | ST.push_back(Type::Int32Ty); // NumElements in array |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 87 | ST.push_back(PairArrTy); // The pairs |
| 88 | StructType *RootList = StructType::get(ST); |
| 89 | if (MainRootRecordType) |
| 90 | return RootList; |
| 91 | |
| 92 | assert(NumRoots == 0 && "The main struct type should have zero entries!"); |
| 93 | cast<OpaqueType>((Type*)RootListH.get())->refineAbstractTypeTo(RootList); |
| 94 | MainRootRecordType = RootListH; |
| 95 | return cast<StructType>(RootListH.get()); |
| 96 | } |
| 97 | |
| 98 | /// doInitialization - If this module uses the GC intrinsics, find them now. If |
| 99 | /// not, this pass does not do anything. |
| 100 | bool LowerGC::doInitialization(Module &M) { |
| 101 | GCRootInt = M.getNamedFunction("llvm.gcroot"); |
| 102 | GCReadInt = M.getNamedFunction("llvm.gcread"); |
| 103 | GCWriteInt = M.getNamedFunction("llvm.gcwrite"); |
| 104 | if (!GCRootInt && !GCReadInt && !GCWriteInt) return false; |
| 105 | |
Reid Spencer | c5b206b | 2006-12-31 05:48:39 +0000 | [diff] [blame] | 106 | PointerType *VoidPtr = PointerType::get(Type::Int8Ty); |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 107 | PointerType *VoidPtrPtr = PointerType::get(VoidPtr); |
| 108 | |
| 109 | // If the program is using read/write barriers, find the implementations of |
| 110 | // them from the GC runtime library. |
| 111 | if (GCReadInt) // Make: sbyte* %llvm_gc_read(sbyte**) |
Jeff Cohen | 66c5fd6 | 2005-10-23 04:37:20 +0000 | [diff] [blame] | 112 | GCRead = M.getOrInsertFunction("llvm_gc_read", VoidPtr, VoidPtr, VoidPtrPtr, |
| 113 | (Type *)0); |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 114 | if (GCWriteInt) // Make: void %llvm_gc_write(sbyte*, sbyte**) |
| 115 | GCWrite = M.getOrInsertFunction("llvm_gc_write", Type::VoidTy, |
Jeff Cohen | 66c5fd6 | 2005-10-23 04:37:20 +0000 | [diff] [blame] | 116 | VoidPtr, VoidPtr, VoidPtrPtr, (Type *)0); |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 117 | |
| 118 | // If the program has GC roots, get or create the global root list. |
| 119 | if (GCRootInt) { |
| 120 | const StructType *RootListTy = getRootRecordType(0); |
| 121 | const Type *PRLTy = PointerType::get(RootListTy); |
| 122 | M.addTypeName("llvm_gc_root_ty", RootListTy); |
| 123 | |
| 124 | // Get the root chain if it already exists. |
| 125 | RootChain = M.getGlobalVariable("llvm_gc_root_chain", PRLTy); |
| 126 | if (RootChain == 0) { |
| 127 | // If the root chain does not exist, insert a new one with linkonce |
| 128 | // linkage! |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 129 | RootChain = new GlobalVariable(PRLTy, false, |
Chris Lattner | 2f48686 | 2004-10-27 03:55:24 +0000 | [diff] [blame] | 130 | GlobalValue::LinkOnceLinkage, |
| 131 | Constant::getNullValue(PRLTy), |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 132 | "llvm_gc_root_chain", &M); |
| 133 | } else if (RootChain->hasExternalLinkage() && RootChain->isExternal()) { |
| 134 | RootChain->setInitializer(Constant::getNullValue(PRLTy)); |
| 135 | RootChain->setLinkage(GlobalValue::LinkOnceLinkage); |
| 136 | } |
| 137 | } |
| 138 | return true; |
| 139 | } |
| 140 | |
| 141 | /// Coerce - If the specified operand number of the specified instruction does |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 142 | /// not have the specified type, insert a cast. Note that this only uses BitCast |
| 143 | /// because the types involved are all pointers. |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 144 | static void Coerce(Instruction *I, unsigned OpNum, Type *Ty) { |
| 145 | if (I->getOperand(OpNum)->getType() != Ty) { |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 146 | if (Constant *C = dyn_cast<Constant>(I->getOperand(OpNum))) |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 147 | I->setOperand(OpNum, ConstantExpr::getBitCast(C, Ty)); |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 148 | else { |
Reid Spencer | 7b06bd5 | 2006-12-13 00:50:17 +0000 | [diff] [blame] | 149 | CastInst *CI = new BitCastInst(I->getOperand(OpNum), Ty, "", I); |
Reid Spencer | 17e6e44 | 2004-10-18 14:38:48 +0000 | [diff] [blame] | 150 | I->setOperand(OpNum, CI); |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | /// runOnFunction - If the program is using GC intrinsics, replace any |
| 156 | /// read/write intrinsics with the appropriate read/write barrier calls, then |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 157 | /// inline them. Finally, build the data structures for |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 158 | bool LowerGC::runOnFunction(Function &F) { |
| 159 | // Quick exit for programs that are not using GC mechanisms. |
| 160 | if (!GCRootInt && !GCReadInt && !GCWriteInt) return false; |
| 161 | |
Reid Spencer | c5b206b | 2006-12-31 05:48:39 +0000 | [diff] [blame] | 162 | PointerType *VoidPtr = PointerType::get(Type::Int8Ty); |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 163 | PointerType *VoidPtrPtr = PointerType::get(VoidPtr); |
| 164 | |
| 165 | // If there are read/write barriers in the program, perform a quick pass over |
| 166 | // the function eliminating them. While we are at it, remember where we see |
| 167 | // calls to llvm.gcroot. |
| 168 | std::vector<CallInst*> GCRoots; |
| 169 | std::vector<CallInst*> NormalCalls; |
| 170 | |
| 171 | bool MadeChange = false; |
| 172 | for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) |
| 173 | for (BasicBlock::iterator II = BB->begin(), E = BB->end(); II != E;) |
| 174 | if (CallInst *CI = dyn_cast<CallInst>(II++)) { |
| 175 | if (!CI->getCalledFunction() || |
| 176 | !CI->getCalledFunction()->getIntrinsicID()) |
| 177 | NormalCalls.push_back(CI); // Remember all normal function calls. |
| 178 | |
| 179 | if (Function *F = CI->getCalledFunction()) |
| 180 | if (F == GCRootInt) |
| 181 | GCRoots.push_back(CI); |
| 182 | else if (F == GCReadInt || F == GCWriteInt) { |
| 183 | if (F == GCWriteInt) { |
| 184 | // Change a llvm.gcwrite call to call llvm_gc_write instead. |
| 185 | CI->setOperand(0, GCWrite); |
| 186 | // Insert casts of the operands as needed. |
| 187 | Coerce(CI, 1, VoidPtr); |
Chris Lattner | 93c9587 | 2004-07-22 05:51:13 +0000 | [diff] [blame] | 188 | Coerce(CI, 2, VoidPtr); |
| 189 | Coerce(CI, 3, VoidPtrPtr); |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 190 | } else { |
Chris Lattner | 93c9587 | 2004-07-22 05:51:13 +0000 | [diff] [blame] | 191 | Coerce(CI, 1, VoidPtr); |
| 192 | Coerce(CI, 2, VoidPtrPtr); |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 193 | if (CI->getType() == VoidPtr) { |
| 194 | CI->setOperand(0, GCRead); |
| 195 | } else { |
| 196 | // Create a whole new call to replace the old one. |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 197 | CallInst *NC = new CallInst(GCRead, CI->getOperand(1), |
Chris Lattner | 93c9587 | 2004-07-22 05:51:13 +0000 | [diff] [blame] | 198 | CI->getOperand(2), |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 199 | CI->getName(), CI); |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 200 | // These functions only deal with ptr type results so BitCast |
| 201 | // is the correct kind of cast (no-op cast). |
| 202 | Value *NV = new BitCastInst(NC, CI->getType(), "", CI); |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 203 | CI->replaceAllUsesWith(NV); |
| 204 | BB->getInstList().erase(CI); |
| 205 | CI = NC; |
| 206 | } |
| 207 | } |
| 208 | |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 209 | MadeChange = true; |
| 210 | } |
| 211 | } |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 212 | |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 213 | // If there are no GC roots in this function, then there is no need to create |
| 214 | // a GC list record for it. |
| 215 | if (GCRoots.empty()) return MadeChange; |
| 216 | |
| 217 | // Okay, there are GC roots in this function. On entry to the function, add a |
| 218 | // record to the llvm_gc_root_chain, and remove it on exit. |
| 219 | |
| 220 | // Create the alloca, and zero it out. |
| 221 | const StructType *RootListTy = getRootRecordType(GCRoots.size()); |
| 222 | AllocaInst *AI = new AllocaInst(RootListTy, 0, "gcroots", F.begin()->begin()); |
| 223 | |
| 224 | // Insert the memset call after all of the allocas in the function. |
| 225 | BasicBlock::iterator IP = AI; |
| 226 | while (isa<AllocaInst>(IP)) ++IP; |
| 227 | |
Reid Spencer | c5b206b | 2006-12-31 05:48:39 +0000 | [diff] [blame] | 228 | Constant *Zero = ConstantInt::get(Type::Int32Ty, 0); |
| 229 | Constant *One = ConstantInt::get(Type::Int32Ty, 1); |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 230 | |
| 231 | // Get a pointer to the prev pointer. |
| 232 | std::vector<Value*> Par; |
| 233 | Par.push_back(Zero); |
| 234 | Par.push_back(Zero); |
| 235 | Value *PrevPtrPtr = new GetElementPtrInst(AI, Par, "prevptrptr", IP); |
| 236 | |
| 237 | // Load the previous pointer. |
| 238 | Value *PrevPtr = new LoadInst(RootChain, "prevptr", IP); |
| 239 | // Store the previous pointer into the prevptrptr |
| 240 | new StoreInst(PrevPtr, PrevPtrPtr, IP); |
| 241 | |
| 242 | // Set the number of elements in this record. |
Reid Spencer | c5b206b | 2006-12-31 05:48:39 +0000 | [diff] [blame] | 243 | Par[1] = ConstantInt::get(Type::Int32Ty, 1); |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 244 | Value *NumEltsPtr = new GetElementPtrInst(AI, Par, "numeltsptr", IP); |
Reid Spencer | c5b206b | 2006-12-31 05:48:39 +0000 | [diff] [blame] | 245 | new StoreInst(ConstantInt::get(Type::Int32Ty, GCRoots.size()), NumEltsPtr,IP); |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 246 | |
Reid Spencer | c5b206b | 2006-12-31 05:48:39 +0000 | [diff] [blame] | 247 | Par[1] = ConstantInt::get(Type::Int32Ty, 2); |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 248 | Par.resize(4); |
| 249 | |
| 250 | const PointerType *PtrLocTy = |
| 251 | cast<PointerType>(GCRootInt->getFunctionType()->getParamType(0)); |
| 252 | Constant *Null = ConstantPointerNull::get(PtrLocTy); |
| 253 | |
| 254 | // Initialize all of the gcroot records now, and eliminate them as we go. |
| 255 | for (unsigned i = 0, e = GCRoots.size(); i != e; ++i) { |
| 256 | // Initialize the meta-data pointer. |
Reid Spencer | c5b206b | 2006-12-31 05:48:39 +0000 | [diff] [blame] | 257 | Par[2] = ConstantInt::get(Type::Int32Ty, i); |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 258 | Par[3] = One; |
| 259 | Value *MetaDataPtr = new GetElementPtrInst(AI, Par, "MetaDataPtr", IP); |
Reid Spencer | 48dc46a | 2004-07-18 00:29:57 +0000 | [diff] [blame] | 260 | assert(isa<Constant>(GCRoots[i]->getOperand(2)) && "Must be a constant"); |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 261 | new StoreInst(GCRoots[i]->getOperand(2), MetaDataPtr, IP); |
| 262 | |
| 263 | // Initialize the root pointer to null on entry to the function. |
| 264 | Par[3] = Zero; |
| 265 | Value *RootPtrPtr = new GetElementPtrInst(AI, Par, "RootEntPtr", IP); |
| 266 | new StoreInst(Null, RootPtrPtr, IP); |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 267 | |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 268 | // Each occurrance of the llvm.gcroot intrinsic now turns into an |
| 269 | // initialization of the slot with the address and a zeroing out of the |
| 270 | // address specified. |
| 271 | new StoreInst(Constant::getNullValue(PtrLocTy->getElementType()), |
| 272 | GCRoots[i]->getOperand(1), GCRoots[i]); |
| 273 | new StoreInst(GCRoots[i]->getOperand(1), RootPtrPtr, GCRoots[i]); |
| 274 | GCRoots[i]->getParent()->getInstList().erase(GCRoots[i]); |
| 275 | } |
| 276 | |
| 277 | // Now that the record is all initialized, store the pointer into the global |
| 278 | // pointer. |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 279 | Value *C = new BitCastInst(AI, PointerType::get(MainRootRecordType), "", IP); |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 280 | new StoreInst(C, RootChain, IP); |
| 281 | |
| 282 | // On exit from the function we have to remove the entry from the GC root |
| 283 | // chain. Doing this is straight-forward for return and unwind instructions: |
| 284 | // just insert the appropriate copy. |
| 285 | for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) |
| 286 | if (isa<UnwindInst>(BB->getTerminator()) || |
| 287 | isa<ReturnInst>(BB->getTerminator())) { |
| 288 | // We could reuse the PrevPtr loaded on entry to the function, but this |
| 289 | // would make the value live for the whole function, which is probably a |
| 290 | // bad idea. Just reload the value out of our stack entry. |
| 291 | PrevPtr = new LoadInst(PrevPtrPtr, "prevptr", BB->getTerminator()); |
| 292 | new StoreInst(PrevPtr, RootChain, BB->getTerminator()); |
| 293 | } |
| 294 | |
| 295 | // If an exception is thrown from a callee we have to make sure to |
| 296 | // unconditionally take the record off the stack. For this reason, we turn |
| 297 | // all call instructions into invoke whose cleanup pops the entry off the |
| 298 | // stack. We only insert one cleanup block, which is shared by all invokes. |
| 299 | if (!NormalCalls.empty()) { |
| 300 | // Create the shared cleanup block. |
| 301 | BasicBlock *Cleanup = new BasicBlock("gc_cleanup", &F); |
| 302 | UnwindInst *UI = new UnwindInst(Cleanup); |
| 303 | PrevPtr = new LoadInst(PrevPtrPtr, "prevptr", UI); |
| 304 | new StoreInst(PrevPtr, RootChain, UI); |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 305 | |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 306 | // Loop over all of the function calls, turning them into invokes. |
| 307 | while (!NormalCalls.empty()) { |
| 308 | CallInst *CI = NormalCalls.back(); |
| 309 | BasicBlock *CBB = CI->getParent(); |
| 310 | NormalCalls.pop_back(); |
| 311 | |
| 312 | // Split the basic block containing the function call. |
| 313 | BasicBlock *NewBB = CBB->splitBasicBlock(CI, CBB->getName()+".cont"); |
| 314 | |
| 315 | // Remove the unconditional branch inserted at the end of the CBB. |
| 316 | CBB->getInstList().pop_back(); |
| 317 | NewBB->getInstList().remove(CI); |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 318 | |
Chris Lattner | 08005df | 2004-05-23 21:19:22 +0000 | [diff] [blame] | 319 | // Create a new invoke instruction. |
| 320 | Value *II = new InvokeInst(CI->getCalledValue(), NewBB, Cleanup, |
| 321 | std::vector<Value*>(CI->op_begin()+1, |
| 322 | CI->op_end()), |
| 323 | CI->getName(), CBB); |
| 324 | CI->replaceAllUsesWith(II); |
| 325 | delete CI; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | return true; |
| 330 | } |