LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

LowerSetJmp.cpp

Go to the documentation of this file.
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, 0); 
00208   // void __llvm_sjljeh_destroy_setjmpmap(void**)
00209   DestroySJMap = M.getOrInsertFunction("__llvm_sjljeh_destroy_setjmpmap",
00210                                        Type::VoidTy, SBPPTy, 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, 0);
00216 
00217   // void __llvm_sjljeh_throw_longjmp(int*, int)
00218   ThrowLongJmp = M.getOrInsertFunction("__llvm_sjljeh_throw_longjmp",
00219                                        Type::VoidTy, SBPTy, Type::IntTy, 0);
00220 
00221   // unsigned __llvm_sjljeh_try_catching_longjmp_exception(void **)
00222   TryCatchLJ =
00223     M.getOrInsertFunction("__llvm_sjljeh_try_catching_longjmp_exception",
00224                           Type::UIntTy, SBPPTy, 0);
00225 
00226   // bool __llvm_sjljeh_is_longjmp_exception()
00227   IsLJException = M.getOrInsertFunction("__llvm_sjljeh_is_longjmp_exception",
00228                                         Type::BoolTy, 0);
00229 
00230   // int __llvm_sjljeh_get_longjmp_value()
00231   GetLJValue = M.getOrInsertFunction("__llvm_sjljeh_get_longjmp_value",
00232                                      Type::IntTy, 0);
00233   return true;
00234 }
00235 
00236 // IsTransformableFunction - Return true if the function name isn't one
00237 // of the ones we don't want transformed. Currently, don't transform any
00238 // "llvm.{setjmp,longjmp}" functions and none of the setjmp/longjmp error
00239 // handling functions (beginning with __llvm_sjljeh_...they don't throw
00240 // exceptions).
00241 bool LowerSetJmp::IsTransformableFunction(const std::string& Name)
00242 {
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.
00277   Inst->getParent()->getInstList().erase(Inst,
00278                                        Inst->getParent()->getInstList().end());
00279 
00280   ++LongJmpsTransformed;
00281 }
00282 
00283 // GetSetJmpMap - Retrieve (create and initialize, if necessary) the
00284 // setjmp map. This map is going to hold information about which setjmps
00285 // were called (each setjmp gets its own number) and with which buffer it
00286 // was called. There can be only one!
00287 AllocaInst* LowerSetJmp::GetSetJmpMap(Function* Func)
00288 {
00289   if (SJMap[Func]) return SJMap[Func];
00290 
00291   // Insert the setjmp map initialization before the first instruction in
00292   // the function.
00293   Instruction* Inst = Func->getEntryBlock().begin();
00294   assert(Inst && "Couldn't find even ONE instruction in entry block!");
00295 
00296   // Fill in the alloca and call to initialize the SJ map.
00297   const Type *SBPTy = PointerType::get(Type::SByteTy);
00298   AllocaInst* Map = new AllocaInst(SBPTy, 0, "SJMap", Inst);
00299   new CallInst(InitSJMap, make_vector<Value*>(Map, 0), "", Inst);
00300   return SJMap[Func] = Map;
00301 }
00302 
00303 // GetRethrowBB - Only one rethrow basic block is needed per function.
00304 // If this is a longjmp exception but not handled in this block, this BB
00305 // performs the rethrow.
00306 BasicBlock* LowerSetJmp::GetRethrowBB(Function* Func)
00307 {
00308   if (RethrowBBMap[Func]) return RethrowBBMap[Func];
00309 
00310   // The basic block we're going to jump to if we need to rethrow the
00311   // exception.
00312   BasicBlock* Rethrow = new BasicBlock("RethrowExcept", Func);
00313 
00314   // Fill in the "Rethrow" BB with a call to rethrow the exception. This
00315   // is the last instruction in the BB since at this point the runtime
00316   // should exit this function and go to the next function.
00317   new UnwindInst(Rethrow);
00318   return RethrowBBMap[Func] = Rethrow;
00319 }
00320 
00321 // GetSJSwitch - Return the switch statement that controls which handler
00322 // (if any) gets called and the value returned to that handler.
00323 LowerSetJmp::SwitchValuePair LowerSetJmp::GetSJSwitch(Function* Func,
00324                                                       BasicBlock* Rethrow)
00325 {
00326   if (SwitchValMap[Func].first) return SwitchValMap[Func];
00327 
00328   BasicBlock* LongJmpPre = new BasicBlock("LongJmpBlkPre", Func);
00329   BasicBlock::InstListType& LongJmpPreIL = LongJmpPre->getInstList();
00330 
00331   // Keep track of the preliminary basic block for some of the other
00332   // transformations.
00333   PrelimBBMap[Func] = LongJmpPre;
00334 
00335   // Grab the exception.
00336   CallInst* Cond = new
00337     CallInst(IsLJException, std::vector<Value*>(), "IsLJExcept");
00338   LongJmpPreIL.push_back(Cond);
00339 
00340   // The "decision basic block" gets the number associated with the
00341   // setjmp call returning to switch on and the value returned by
00342   // longjmp.
00343   BasicBlock* DecisionBB = new BasicBlock("LJDecisionBB", Func);
00344   BasicBlock::InstListType& DecisionBBIL = DecisionBB->getInstList();
00345 
00346   new BranchInst(DecisionBB, Rethrow, Cond, LongJmpPre);
00347 
00348   // Fill in the "decision" basic block.
00349   CallInst* LJVal = new CallInst(GetLJValue, std::vector<Value*>(), "LJVal");
00350   DecisionBBIL.push_back(LJVal);
00351   CallInst* SJNum = new
00352     CallInst(TryCatchLJ, make_vector<Value*>(GetSetJmpMap(Func), 0), "SJNum");
00353   DecisionBBIL.push_back(SJNum);
00354 
00355   SwitchInst* SI = new SwitchInst(SJNum, Rethrow, DecisionBB);
00356   return SwitchValMap[Func] = SwitchValuePair(SI, LJVal);
00357 }
00358 
00359 // TransformSetJmpCall - The setjmp call is a bit trickier to transform.
00360 // We're going to convert all setjmp calls to nops. Then all "call" and
00361 // "invoke" instructions in the function are converted to "invoke" where
00362 // the "except" branch is used when returning from a longjmp call.
00363 void LowerSetJmp::TransformSetJmpCall(CallInst* Inst)
00364 {
00365   BasicBlock* ABlock = Inst->getParent();
00366   Function* Func = ABlock->getParent();
00367 
00368   // Add this setjmp to the setjmp map.
00369   const Type* SBPTy = PointerType::get(Type::SByteTy);
00370   CastInst* BufPtr = new CastInst(Inst->getOperand(1), SBPTy, "SBJmpBuf", Inst);
00371   new CallInst(AddSJToMap,
00372                make_vector<Value*>(GetSetJmpMap(Func), BufPtr,
00373                                    ConstantUInt::get(Type::UIntTy,
00374                                                      SetJmpIDMap[Func]++), 0),
00375                "", Inst);
00376 
00377   // We are guaranteed that there are no values live across basic blocks
00378   // (because we are "not in SSA form" yet), but there can still be values live
00379   // in basic blocks.  Because of this, splitting the setjmp block can cause
00380   // values above the setjmp to not dominate uses which are after the setjmp
00381   // call.  For all of these occasions, we must spill the value to the stack.
00382   //
00383   std::set<Instruction*> InstrsAfterCall;
00384 
00385   // The call is probably very close to the end of the basic block, for the
00386   // common usage pattern of: 'if (setjmp(...))', so keep track of the
00387   // instructions after the call.
00388   for (BasicBlock::iterator I = ++BasicBlock::iterator(Inst), E = ABlock->end();
00389        I != E; ++I)
00390     InstrsAfterCall.insert(I);    
00391 
00392   for (BasicBlock::iterator II = ABlock->begin();
00393        II != BasicBlock::iterator(Inst); ++II)
00394     // Loop over all of the uses of instruction.  If any of them are after the
00395     // call, "spill" the value to the stack.
00396     for (Value::use_iterator UI = II->use_begin(), E = II->use_end();
00397          UI != E; ++UI)
00398       if (cast<Instruction>(*UI)->getParent() != ABlock ||
00399           InstrsAfterCall.count(cast<Instruction>(*UI))) {
00400         DemoteRegToStack(*II);
00401         break;
00402       }
00403   InstrsAfterCall.clear();
00404 
00405   // Change the setjmp call into a branch statement. We'll remove the
00406   // setjmp call in a little bit. No worries.
00407   BasicBlock* SetJmpContBlock = ABlock->splitBasicBlock(Inst);
00408   assert(SetJmpContBlock && "Couldn't split setjmp BB!!");
00409 
00410   SetJmpContBlock->setName("SetJmpContBlock");
00411 
00412   // This PHI node will be in the new block created from the
00413   // splitBasicBlock call.
00414   PHINode* PHI = new PHINode(Type::IntTy, "SetJmpReturn", Inst);
00415 
00416   // Coming from a call to setjmp, the return is 0.
00417   PHI->addIncoming(ConstantInt::getNullValue(Type::IntTy), ABlock);
00418 
00419   // Add the case for this setjmp's number...
00420   SwitchValuePair SVP = GetSJSwitch(Func, GetRethrowBB(Func));
00421   SVP.first->addCase(ConstantUInt::get(Type::UIntTy, SetJmpIDMap[Func] - 1),
00422                      SetJmpContBlock);
00423 
00424   // Value coming from the handling of the exception.
00425   PHI->addIncoming(SVP.second, SVP.second->getParent());
00426 
00427   // Replace all uses of this instruction with the PHI node created by
00428   // the eradication of setjmp.
00429   Inst->replaceAllUsesWith(PHI);
00430   Inst->getParent()->getInstList().erase(Inst);
00431 
00432   ++SetJmpsTransformed;
00433 }
00434 
00435 // visitCallInst - This converts all LLVM call instructions into invoke
00436 // instructions. The except part of the invoke goes to the "LongJmpBlkPre"
00437 // that grabs the exception and proceeds to determine if it's a longjmp
00438 // exception or not.
00439 void LowerSetJmp::visitCallInst(CallInst& CI)
00440 {
00441   if (CI.getCalledFunction())
00442     if (!IsTransformableFunction(CI.getCalledFunction()->getName()) ||
00443         CI.getCalledFunction()->isIntrinsic()) return;
00444 
00445   BasicBlock* OldBB = CI.getParent();
00446 
00447   // If not reachable from a setjmp call, don't transform.
00448   if (!DFSBlocks.count(OldBB)) return;
00449 
00450   BasicBlock* NewBB = OldBB->splitBasicBlock(CI);
00451   assert(NewBB && "Couldn't split BB of \"call\" instruction!!");
00452   NewBB->setName("Call2Invoke");
00453 
00454   Function* Func = OldBB->getParent();
00455 
00456   // Construct the new "invoke" instruction.
00457   TerminatorInst* Term = OldBB->getTerminator();
00458   std::vector<Value*> Params(CI.op_begin() + 1, CI.op_end());
00459   InvokeInst* II = new
00460     InvokeInst(CI.getCalledValue(), NewBB, PrelimBBMap[Func],
00461                Params, CI.getName(), Term); 
00462 
00463   // Replace the old call inst with the invoke inst and remove the call.
00464   CI.replaceAllUsesWith(II);
00465   CI.getParent()->getInstList().erase(&CI);
00466 
00467   // The old terminator is useless now that we have the invoke inst.
00468   Term->getParent()->getInstList().erase(Term);
00469   ++CallsTransformed;
00470 }
00471 
00472 // visitInvokeInst - Converting the "invoke" instruction is fairly
00473 // straight-forward. The old exception part is replaced by a query asking
00474 // if this is a longjmp exception. If it is, then it goes to the longjmp
00475 // exception blocks. Otherwise, control is passed the old exception.
00476 void LowerSetJmp::visitInvokeInst(InvokeInst& II)
00477 {
00478   if (II.getCalledFunction())
00479     if (!IsTransformableFunction(II.getCalledFunction()->getName()) ||
00480         II.getCalledFunction()->isIntrinsic()) return;
00481 
00482   BasicBlock* BB = II.getParent();
00483 
00484   // If not reachable from a setjmp call, don't transform.
00485   if (!DFSBlocks.count(BB)) return;
00486 
00487   BasicBlock* NormalBB = II.getNormalDest();
00488   BasicBlock* ExceptBB = II.getUnwindDest();
00489 
00490   Function* Func = BB->getParent();
00491   BasicBlock* NewExceptBB = new BasicBlock("InvokeExcept", Func);
00492   BasicBlock::InstListType& InstList = NewExceptBB->getInstList();
00493 
00494   // If this is a longjmp exception, then branch to the preliminary BB of
00495   // the longjmp exception handling. Otherwise, go to the old exception.
00496   CallInst* IsLJExcept = new
00497     CallInst(IsLJException, std::vector<Value*>(), "IsLJExcept");
00498   InstList.push_back(IsLJExcept);
00499 
00500   new BranchInst(PrelimBBMap[Func], ExceptBB, IsLJExcept, NewExceptBB);
00501 
00502   II.setUnwindDest(NewExceptBB);
00503   ++InvokesTransformed;
00504 }
00505 
00506 // visitReturnInst - We want to destroy the setjmp map upon exit from the
00507 // function.
00508 void LowerSetJmp::visitReturnInst(ReturnInst &RI) {
00509   Function* Func = RI.getParent()->getParent();
00510   new CallInst(DestroySJMap, make_vector<Value*>(GetSetJmpMap(Func), 0),
00511                "", &RI);
00512 }
00513 
00514 // visitUnwindInst - We want to destroy the setjmp map upon exit from the
00515 // function.
00516 void LowerSetJmp::visitUnwindInst(UnwindInst &UI) {
00517   Function* Func = UI.getParent()->getParent();
00518   new CallInst(DestroySJMap, make_vector<Value*>(GetSetJmpMap(Func), 0),
00519                "", &UI);
00520 }
00521 
00522 ModulePass *llvm::createLowerSetJmpPass() {
00523   return new LowerSetJmp();
00524 }
00525