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