LLVM API Documentation
00001 //===- LowerSetJmp.cpp - Code pertaining to lowering set/long jumps -------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements the lowering of setjmp and longjmp to use the 00011 // LLVM invoke and unwind instructions as necessary. 00012 // 00013 // Lowering of longjmp is fairly trivial. We replace the call with a 00014 // call to the LLVM library function "__llvm_sjljeh_throw_longjmp()". 00015 // This unwinds the stack for us calling all of the destructors for 00016 // objects allocated on the stack. 00017 // 00018 // At a setjmp call, the basic block is split and the setjmp removed. 00019 // The calls in a function that have a setjmp are converted to invoke 00020 // where the except part checks to see if it's a longjmp exception and, 00021 // if so, if it's handled in the function. If it is, then it gets the 00022 // value returned by the longjmp and goes to where the basic block was 00023 // split. Invoke instructions are handled in a similar fashion with the 00024 // original except block being executed if it isn't a longjmp except 00025 // that is handled by that function. 00026 // 00027 //===----------------------------------------------------------------------===// 00028 00029 //===----------------------------------------------------------------------===// 00030 // FIXME: This pass doesn't deal with PHI statements just yet. That is, 00031 // we expect this to occur before SSAification is done. This would seem 00032 // to make sense, but in general, it might be a good idea to make this 00033 // pass invokable via the "opt" command at will. 00034 //===----------------------------------------------------------------------===// 00035 00036 #include "llvm/Transforms/IPO.h" 00037 #include "llvm/Constants.h" 00038 #include "llvm/DerivedTypes.h" 00039 #include "llvm/Instructions.h" 00040 #include "llvm/Intrinsics.h" 00041 #include "llvm/Module.h" 00042 #include "llvm/Pass.h" 00043 #include "llvm/Support/CFG.h" 00044 #include "llvm/Support/InstVisitor.h" 00045 #include "llvm/Transforms/Utils/Local.h" 00046 #include "llvm/ADT/DepthFirstIterator.h" 00047 #include "llvm/ADT/Statistic.h" 00048 #include "llvm/ADT/StringExtras.h" 00049 #include "llvm/ADT/VectorExtras.h" 00050 using namespace llvm; 00051 00052 namespace { 00053 Statistic<> LongJmpsTransformed("lowersetjmp", 00054 "Number of longjmps transformed"); 00055 Statistic<> SetJmpsTransformed("lowersetjmp", 00056 "Number of setjmps transformed"); 00057 Statistic<> CallsTransformed("lowersetjmp", 00058 "Number of calls invokified"); 00059 Statistic<> InvokesTransformed("lowersetjmp", 00060 "Number of invokes modified"); 00061 00062 //===--------------------------------------------------------------------===// 00063 // LowerSetJmp pass implementation. 00064 class LowerSetJmp : public ModulePass, 00065 public InstVisitor<LowerSetJmp> { 00066 // LLVM library functions... 00067 Function* InitSJMap; // __llvm_sjljeh_init_setjmpmap 00068 Function* DestroySJMap; // __llvm_sjljeh_destroy_setjmpmap 00069 Function* AddSJToMap; // __llvm_sjljeh_add_setjmp_to_map 00070 Function* ThrowLongJmp; // __llvm_sjljeh_throw_longjmp 00071 Function* TryCatchLJ; // __llvm_sjljeh_try_catching_longjmp_exception 00072 Function* IsLJException; // __llvm_sjljeh_is_longjmp_exception 00073 Function* GetLJValue; // __llvm_sjljeh_get_longjmp_value 00074 00075 typedef std::pair<SwitchInst*, CallInst*> SwitchValuePair; 00076 00077 // Keep track of those basic blocks reachable via a depth-first search of 00078 // the CFG from a setjmp call. We only need to transform those "call" and 00079 // "invoke" instructions that are reachable from the setjmp call site. 00080 std::set<BasicBlock*> DFSBlocks; 00081 00082 // The setjmp map is going to hold information about which setjmps 00083 // were called (each setjmp gets its own number) and with which 00084 // buffer it was called. 00085 std::map<Function*, AllocaInst*> SJMap; 00086 00087 // The rethrow basic block map holds the basic block to branch to if 00088 // the exception isn't handled in the current function and needs to 00089 // be rethrown. 00090 std::map<const Function*, BasicBlock*> RethrowBBMap; 00091 00092 // The preliminary basic block map holds a basic block that grabs the 00093 // exception and determines if it's handled by the current function. 00094 std::map<const Function*, BasicBlock*> PrelimBBMap; 00095 00096 // The switch/value map holds a switch inst/call inst pair. The 00097 // switch inst controls which handler (if any) gets called and the 00098 // value is the value returned to that handler by the call to 00099 // __llvm_sjljeh_get_longjmp_value. 00100 std::map<const Function*, SwitchValuePair> SwitchValMap; 00101 00102 // A map of which setjmps we've seen so far in a function. 00103 std::map<const Function*, unsigned> SetJmpIDMap; 00104 00105 AllocaInst* GetSetJmpMap(Function* Func); 00106 BasicBlock* GetRethrowBB(Function* Func); 00107 SwitchValuePair GetSJSwitch(Function* Func, BasicBlock* Rethrow); 00108 00109 void TransformLongJmpCall(CallInst* Inst); 00110 void TransformSetJmpCall(CallInst* Inst); 00111 00112 bool IsTransformableFunction(const std::string& Name); 00113 public: 00114 void visitCallInst(CallInst& CI); 00115 void visitInvokeInst(InvokeInst& II); 00116 void visitReturnInst(ReturnInst& RI); 00117 void visitUnwindInst(UnwindInst& UI); 00118 00119 bool runOnModule(Module& M); 00120 bool doInitialization(Module& M); 00121 }; 00122 00123 RegisterOpt<LowerSetJmp> X("lowersetjmp", "Lower Set Jump"); 00124 } // end anonymous namespace 00125 00126 // run - Run the transformation on the program. We grab the function 00127 // prototypes for longjmp and setjmp. If they are used in the program, 00128 // then we can go directly to the places they're at and transform them. 00129 bool LowerSetJmp::runOnModule(Module& M) { 00130 bool Changed = false; 00131 00132 // These are what the functions are called. 00133 Function* SetJmp = M.getNamedFunction("llvm.setjmp"); 00134 Function* LongJmp = M.getNamedFunction("llvm.longjmp"); 00135 00136 // This program doesn't have longjmp and setjmp calls. 00137 if ((!LongJmp || LongJmp->use_empty()) && 00138 (!SetJmp || SetJmp->use_empty())) return false; 00139 00140 // Initialize some values and functions we'll need to transform the 00141 // setjmp/longjmp functions. 00142 doInitialization(M); 00143 00144 if (SetJmp) { 00145 for (Value::use_iterator B = SetJmp->use_begin(), E = SetJmp->use_end(); 00146 B != E; ++B) { 00147 BasicBlock* BB = cast<Instruction>(*B)->getParent(); 00148 for (df_ext_iterator<BasicBlock*> I = df_ext_begin(BB, DFSBlocks), 00149 E = df_ext_end(BB, DFSBlocks); I != E; ++I) 00150 /* empty */; 00151 } 00152 00153 while (!SetJmp->use_empty()) { 00154 assert(isa<CallInst>(SetJmp->use_back()) && 00155 "User of setjmp intrinsic not a call?"); 00156 TransformSetJmpCall(cast<CallInst>(SetJmp->use_back())); 00157 Changed = true; 00158 } 00159 } 00160 00161 if (LongJmp) 00162 while (!LongJmp->use_empty()) { 00163 assert(isa<CallInst>(LongJmp->use_back()) && 00164 "User of longjmp intrinsic not a call?"); 00165 TransformLongJmpCall(cast<CallInst>(LongJmp->use_back())); 00166 Changed = true; 00167 } 00168 00169 // Now go through the affected functions and convert calls and invokes 00170 // to new invokes... 00171 for (std::map<Function*, AllocaInst*>::iterator 00172 B = SJMap.begin(), E = SJMap.end(); B != E; ++B) { 00173 Function* F = B->first; 00174 for (Function::iterator BB = F->begin(), BE = F->end(); BB != BE; ++BB) 00175 for (BasicBlock::iterator IB = BB->begin(), IE = BB->end(); IB != IE; ) { 00176 visit(*IB++); 00177 if (IB != BB->end() && IB->getParent() != BB) 00178 break; // The next instruction got moved to a different block! 00179 } 00180 } 00181 00182 DFSBlocks.clear(); 00183 SJMap.clear(); 00184 RethrowBBMap.clear(); 00185 PrelimBBMap.clear(); 00186 SwitchValMap.clear(); 00187 SetJmpIDMap.clear(); 00188 00189 return Changed; 00190 } 00191 00192 // doInitialization - For the lower long/setjmp pass, this ensures that a 00193 // module contains a declaration for the intrisic functions we are going 00194 // to call to convert longjmp and setjmp calls. 00195 // 00196 // This function is always successful, unless it isn't. 00197 bool LowerSetJmp::doInitialization(Module& M) 00198 { 00199 const Type *SBPTy = PointerType::get(Type::SByteTy); 00200 const Type *SBPPTy = PointerType::get(SBPTy); 00201 00202 // N.B. See llvm/runtime/GCCLibraries/libexception/SJLJ-Exception.h for 00203 // a description of the following library functions. 00204 00205 // void __llvm_sjljeh_init_setjmpmap(void**) 00206 InitSJMap = M.getOrInsertFunction("__llvm_sjljeh_init_setjmpmap", 00207 Type::VoidTy, SBPPTy, (Type *)0); 00208 // void __llvm_sjljeh_destroy_setjmpmap(void**) 00209 DestroySJMap = M.getOrInsertFunction("__llvm_sjljeh_destroy_setjmpmap", 00210 Type::VoidTy, SBPPTy, (Type *)0); 00211 00212 // void __llvm_sjljeh_add_setjmp_to_map(void**, void*, unsigned) 00213 AddSJToMap = M.getOrInsertFunction("__llvm_sjljeh_add_setjmp_to_map", 00214 Type::VoidTy, SBPPTy, SBPTy, 00215 Type::UIntTy, (Type *)0); 00216 00217 // void __llvm_sjljeh_throw_longjmp(int*, int) 00218 ThrowLongJmp = M.getOrInsertFunction("__llvm_sjljeh_throw_longjmp", 00219 Type::VoidTy, SBPTy, Type::IntTy, 00220 (Type *)0); 00221 00222 // unsigned __llvm_sjljeh_try_catching_longjmp_exception(void **) 00223 TryCatchLJ = 00224 M.getOrInsertFunction("__llvm_sjljeh_try_catching_longjmp_exception", 00225 Type::UIntTy, SBPPTy, (Type *)0); 00226 00227 // bool __llvm_sjljeh_is_longjmp_exception() 00228 IsLJException = M.getOrInsertFunction("__llvm_sjljeh_is_longjmp_exception", 00229 Type::BoolTy, (Type *)0); 00230 00231 // int __llvm_sjljeh_get_longjmp_value() 00232 GetLJValue = M.getOrInsertFunction("__llvm_sjljeh_get_longjmp_value", 00233 Type::IntTy, (Type *)0); 00234 return true; 00235 } 00236 00237 // IsTransformableFunction - Return true if the function name isn't one 00238 // of the ones we don't want transformed. Currently, don't transform any 00239 // "llvm.{setjmp,longjmp}" functions and none of the setjmp/longjmp error 00240 // handling functions (beginning with __llvm_sjljeh_...they don't throw 00241 // exceptions). 00242 bool LowerSetJmp::IsTransformableFunction(const std::string& Name) { 00243 std::string SJLJEh("__llvm_sjljeh"); 00244 00245 if (Name.size() > SJLJEh.size()) 00246 return std::string(Name.begin(), Name.begin() + SJLJEh.size()) != SJLJEh; 00247 00248 return true; 00249 } 00250 00251 // TransformLongJmpCall - Transform a longjmp call into a call to the 00252 // internal __llvm_sjljeh_throw_longjmp function. It then takes care of 00253 // throwing the exception for us. 00254 void LowerSetJmp::TransformLongJmpCall(CallInst* Inst) 00255 { 00256 const Type* SBPTy = PointerType::get(Type::SByteTy); 00257 00258 // Create the call to "__llvm_sjljeh_throw_longjmp". This takes the 00259 // same parameters as "longjmp", except that the buffer is cast to a 00260 // char*. It returns "void", so it doesn't need to replace any of 00261 // Inst's uses and doesn't get a name. 00262 CastInst* CI = new CastInst(Inst->getOperand(1), SBPTy, "LJBuf", Inst); 00263 new CallInst(ThrowLongJmp, make_vector<Value*>(CI, Inst->getOperand(2), 0), 00264 "", Inst); 00265 00266 SwitchValuePair& SVP = SwitchValMap[Inst->getParent()->getParent()]; 00267 00268 // If the function has a setjmp call in it (they are transformed first) 00269 // we should branch to the basic block that determines if this longjmp 00270 // is applicable here. Otherwise, issue an unwind. 00271 if (SVP.first) 00272 new BranchInst(SVP.first->getParent(), Inst); 00273 else 00274 new UnwindInst(Inst); 00275 00276 // Remove all insts after the branch/unwind inst. Go from back to front to 00277 // avoid replaceAllUsesWith if possible. 00278 BasicBlock *BB = Inst->getParent(); 00279 Instruction *Removed; 00280 do { 00281 Removed = &BB->back(); 00282 // If the removed instructions have any users, replace them now. 00283 if (!Removed->use_empty()) 00284 Removed->replaceAllUsesWith(UndefValue::get(Removed->getType())); 00285 Removed->eraseFromParent(); 00286 } while (Removed != Inst); 00287 00288 ++LongJmpsTransformed; 00289 } 00290 00291 // GetSetJmpMap - Retrieve (create and initialize, if necessary) the 00292 // setjmp map. This map is going to hold information about which setjmps 00293 // were called (each setjmp gets its own number) and with which buffer it 00294 // was called. There can be only one! 00295 AllocaInst* LowerSetJmp::GetSetJmpMap(Function* Func) 00296 { 00297 if (SJMap[Func]) return SJMap[Func]; 00298 00299 // Insert the setjmp map initialization before the first instruction in 00300 // the function. 00301 Instruction* Inst = Func->getEntryBlock().begin(); 00302 assert(Inst && "Couldn't find even ONE instruction in entry block!"); 00303 00304 // Fill in the alloca and call to initialize the SJ map. 00305 const Type *SBPTy = PointerType::get(Type::SByteTy); 00306 AllocaInst* Map = new AllocaInst(SBPTy, 0, "SJMap", Inst); 00307 new CallInst(InitSJMap, make_vector<Value*>(Map, 0), "", Inst); 00308 return SJMap[Func] = Map; 00309 } 00310 00311 // GetRethrowBB - Only one rethrow basic block is needed per function. 00312 // If this is a longjmp exception but not handled in this block, this BB 00313 // performs the rethrow. 00314 BasicBlock* LowerSetJmp::GetRethrowBB(Function* Func) 00315 { 00316 if (RethrowBBMap[Func]) return RethrowBBMap[Func]; 00317 00318 // The basic block we're going to jump to if we need to rethrow the 00319 // exception. 00320 BasicBlock* Rethrow = new BasicBlock("RethrowExcept", Func); 00321 00322 // Fill in the "Rethrow" BB with a call to rethrow the exception. This 00323 // is the last instruction in the BB since at this point the runtime 00324 // should exit this function and go to the next function. 00325 new UnwindInst(Rethrow); 00326 return RethrowBBMap[Func] = Rethrow; 00327 } 00328 00329 // GetSJSwitch - Return the switch statement that controls which handler 00330 // (if any) gets called and the value returned to that handler. 00331 LowerSetJmp::SwitchValuePair LowerSetJmp::GetSJSwitch(Function* Func, 00332 BasicBlock* Rethrow) 00333 { 00334 if (SwitchValMap[Func].first) return SwitchValMap[Func]; 00335 00336 BasicBlock* LongJmpPre = new BasicBlock("LongJmpBlkPre", Func); 00337 BasicBlock::InstListType& LongJmpPreIL = LongJmpPre->getInstList(); 00338 00339 // Keep track of the preliminary basic block for some of the other 00340 // transformations. 00341 PrelimBBMap[Func] = LongJmpPre; 00342 00343 // Grab the exception. 00344 CallInst* Cond = new 00345 CallInst(IsLJException, std::vector<Value*>(), "IsLJExcept"); 00346 LongJmpPreIL.push_back(Cond); 00347 00348 // The "decision basic block" gets the number associated with the 00349 // setjmp call returning to switch on and the value returned by 00350 // longjmp. 00351 BasicBlock* DecisionBB = new BasicBlock("LJDecisionBB", Func); 00352 BasicBlock::InstListType& DecisionBBIL = DecisionBB->getInstList(); 00353 00354 new BranchInst(DecisionBB, Rethrow, Cond, LongJmpPre); 00355 00356 // Fill in the "decision" basic block. 00357 CallInst* LJVal = new CallInst(GetLJValue, std::vector<Value*>(), "LJVal"); 00358 DecisionBBIL.push_back(LJVal); 00359 CallInst* SJNum = new 00360 CallInst(TryCatchLJ, make_vector<Value*>(GetSetJmpMap(Func), 0), "SJNum"); 00361 DecisionBBIL.push_back(SJNum); 00362 00363 SwitchInst* SI = new SwitchInst(SJNum, Rethrow, 0, DecisionBB); 00364 return SwitchValMap[Func] = SwitchValuePair(SI, LJVal); 00365 } 00366 00367 // TransformSetJmpCall - The setjmp call is a bit trickier to transform. 00368 // We're going to convert all setjmp calls to nops. Then all "call" and 00369 // "invoke" instructions in the function are converted to "invoke" where 00370 // the "except" branch is used when returning from a longjmp call. 00371 void LowerSetJmp::TransformSetJmpCall(CallInst* Inst) 00372 { 00373 BasicBlock* ABlock = Inst->getParent(); 00374 Function* Func = ABlock->getParent(); 00375 00376 // Add this setjmp to the setjmp map. 00377 const Type* SBPTy = PointerType::get(Type::SByteTy); 00378 CastInst* BufPtr = new CastInst(Inst->getOperand(1), SBPTy, "SBJmpBuf", Inst); 00379 new CallInst(AddSJToMap, 00380 make_vector<Value*>(GetSetJmpMap(Func), BufPtr, 00381 ConstantUInt::get(Type::UIntTy, 00382 SetJmpIDMap[Func]++), 0), 00383 "", Inst); 00384 00385 // We are guaranteed that there are no values live across basic blocks 00386 // (because we are "not in SSA form" yet), but there can still be values live 00387 // in basic blocks. Because of this, splitting the setjmp block can cause 00388 // values above the setjmp to not dominate uses which are after the setjmp 00389 // call. For all of these occasions, we must spill the value to the stack. 00390 // 00391 std::set<Instruction*> InstrsAfterCall; 00392 00393 // The call is probably very close to the end of the basic block, for the 00394 // common usage pattern of: 'if (setjmp(...))', so keep track of the 00395 // instructions after the call. 00396 for (BasicBlock::iterator I = ++BasicBlock::iterator(Inst), E = ABlock->end(); 00397 I != E; ++I) 00398 InstrsAfterCall.insert(I); 00399 00400 for (BasicBlock::iterator II = ABlock->begin(); 00401 II != BasicBlock::iterator(Inst); ++II) 00402 // Loop over all of the uses of instruction. If any of them are after the 00403 // call, "spill" the value to the stack. 00404 for (Value::use_iterator UI = II->use_begin(), E = II->use_end(); 00405 UI != E; ++UI) 00406 if (cast<Instruction>(*UI)->getParent() != ABlock || 00407 InstrsAfterCall.count(cast<Instruction>(*UI))) { 00408 DemoteRegToStack(*II); 00409 break; 00410 } 00411 InstrsAfterCall.clear(); 00412 00413 // Change the setjmp call into a branch statement. We'll remove the 00414 // setjmp call in a little bit. No worries. 00415 BasicBlock* SetJmpContBlock = ABlock->splitBasicBlock(Inst); 00416 assert(SetJmpContBlock && "Couldn't split setjmp BB!!"); 00417 00418 SetJmpContBlock->setName(ABlock->getName()+"SetJmpCont"); 00419 00420 // Add the SetJmpContBlock to the set of blocks reachable from a setjmp. 00421 DFSBlocks.insert(SetJmpContBlock); 00422 00423 // This PHI node will be in the new block created from the 00424 // splitBasicBlock call. 00425 PHINode* PHI = new PHINode(Type::IntTy, "SetJmpReturn", Inst); 00426 00427 // Coming from a call to setjmp, the return is 0. 00428 PHI->addIncoming(ConstantInt::getNullValue(Type::IntTy), ABlock); 00429 00430 // Add the case for this setjmp's number... 00431 SwitchValuePair SVP = GetSJSwitch(Func, GetRethrowBB(Func)); 00432 SVP.first->addCase(ConstantUInt::get(Type::UIntTy, SetJmpIDMap[Func] - 1), 00433 SetJmpContBlock); 00434 00435 // Value coming from the handling of the exception. 00436 PHI->addIncoming(SVP.second, SVP.second->getParent()); 00437 00438 // Replace all uses of this instruction with the PHI node created by 00439 // the eradication of setjmp. 00440 Inst->replaceAllUsesWith(PHI); 00441 Inst->getParent()->getInstList().erase(Inst); 00442 00443 ++SetJmpsTransformed; 00444 } 00445 00446 // visitCallInst - This converts all LLVM call instructions into invoke 00447 // instructions. The except part of the invoke goes to the "LongJmpBlkPre" 00448 // that grabs the exception and proceeds to determine if it's a longjmp 00449 // exception or not. 00450 void LowerSetJmp::visitCallInst(CallInst& CI) 00451 { 00452 if (CI.getCalledFunction()) 00453 if (!IsTransformableFunction(CI.getCalledFunction()->getName()) || 00454 CI.getCalledFunction()->isIntrinsic()) return; 00455 00456 BasicBlock* OldBB = CI.getParent(); 00457 00458 // If not reachable from a setjmp call, don't transform. 00459 if (!DFSBlocks.count(OldBB)) return; 00460 00461 BasicBlock* NewBB = OldBB->splitBasicBlock(CI); 00462 assert(NewBB && "Couldn't split BB of \"call\" instruction!!"); 00463 DFSBlocks.insert(NewBB); 00464 NewBB->setName("Call2Invoke"); 00465 00466 Function* Func = OldBB->getParent(); 00467 00468 // Construct the new "invoke" instruction. 00469 TerminatorInst* Term = OldBB->getTerminator(); 00470 std::vector<Value*> Params(CI.op_begin() + 1, CI.op_end()); 00471 InvokeInst* II = new 00472 InvokeInst(CI.getCalledValue(), NewBB, PrelimBBMap[Func], 00473 Params, CI.getName(), Term); 00474 00475 // Replace the old call inst with the invoke inst and remove the call. 00476 CI.replaceAllUsesWith(II); 00477 CI.getParent()->getInstList().erase(&CI); 00478 00479 // The old terminator is useless now that we have the invoke inst. 00480 Term->getParent()->getInstList().erase(Term); 00481 ++CallsTransformed; 00482 } 00483 00484 // visitInvokeInst - Converting the "invoke" instruction is fairly 00485 // straight-forward. The old exception part is replaced by a query asking 00486 // if this is a longjmp exception. If it is, then it goes to the longjmp 00487 // exception blocks. Otherwise, control is passed the old exception. 00488 void LowerSetJmp::visitInvokeInst(InvokeInst& II) 00489 { 00490 if (II.getCalledFunction()) 00491 if (!IsTransformableFunction(II.getCalledFunction()->getName()) || 00492 II.getCalledFunction()->isIntrinsic()) return; 00493 00494 BasicBlock* BB = II.getParent(); 00495 00496 // If not reachable from a setjmp call, don't transform. 00497 if (!DFSBlocks.count(BB)) return; 00498 00499 BasicBlock* NormalBB = II.getNormalDest(); 00500 BasicBlock* ExceptBB = II.getUnwindDest(); 00501 00502 Function* Func = BB->getParent(); 00503 BasicBlock* NewExceptBB = new BasicBlock("InvokeExcept", Func); 00504 BasicBlock::InstListType& InstList = NewExceptBB->getInstList(); 00505 00506 // If this is a longjmp exception, then branch to the preliminary BB of 00507 // the longjmp exception handling. Otherwise, go to the old exception. 00508 CallInst* IsLJExcept = new 00509 CallInst(IsLJException, std::vector<Value*>(), "IsLJExcept"); 00510 InstList.push_back(IsLJExcept); 00511 00512 new BranchInst(PrelimBBMap[Func], ExceptBB, IsLJExcept, NewExceptBB); 00513 00514 II.setUnwindDest(NewExceptBB); 00515 ++InvokesTransformed; 00516 } 00517 00518 // visitReturnInst - We want to destroy the setjmp map upon exit from the 00519 // function. 00520 void LowerSetJmp::visitReturnInst(ReturnInst &RI) { 00521 Function* Func = RI.getParent()->getParent(); 00522 new CallInst(DestroySJMap, make_vector<Value*>(GetSetJmpMap(Func), 0), 00523 "", &RI); 00524 } 00525 00526 // visitUnwindInst - We want to destroy the setjmp map upon exit from the 00527 // function. 00528 void LowerSetJmp::visitUnwindInst(UnwindInst &UI) { 00529 Function* Func = UI.getParent()->getParent(); 00530 new CallInst(DestroySJMap, make_vector<Value*>(GetSetJmpMap(Func), 0), 00531 "", &UI); 00532 } 00533 00534 ModulePass *llvm::createLowerSetJmpPass() { 00535 return new LowerSetJmp(); 00536 } 00537