SjLjEHPrepare.cpp (208954) | SjLjEHPrepare.cpp (210299) |
---|---|
1//===- SjLjEHPass.cpp - Eliminate Invoke & Unwind instructions -----------===// 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//===----------------------------------------------------------------------===// --- 32 unchanged lines hidden (view full) --- 41 42 const TargetLowering *TLI; 43 44 const Type *FunctionContextTy; 45 Constant *RegisterFn; 46 Constant *UnregisterFn; 47 Constant *BuiltinSetjmpFn; 48 Constant *FrameAddrFn; | 1//===- SjLjEHPass.cpp - Eliminate Invoke & Unwind instructions -----------===// 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//===----------------------------------------------------------------------===// --- 32 unchanged lines hidden (view full) --- 41 42 const TargetLowering *TLI; 43 44 const Type *FunctionContextTy; 45 Constant *RegisterFn; 46 Constant *UnregisterFn; 47 Constant *BuiltinSetjmpFn; 48 Constant *FrameAddrFn; |
49 Constant *StackAddrFn; 50 Constant *StackRestoreFn; |
|
49 Constant *LSDAAddrFn; 50 Value *PersonalityFn; 51 Constant *SelectorFn; 52 Constant *ExceptionFn; 53 Constant *CallSiteFn; 54 55 Value *CallSite; 56 public: --- 7 unchanged lines hidden (view full) --- 64 const char *getPassName() const { 65 return "SJLJ Exception Handling preparation"; 66 } 67 68 private: 69 void insertCallSiteStore(Instruction *I, int Number, Value *CallSite); 70 void markInvokeCallSite(InvokeInst *II, int InvokeNo, Value *CallSite, 71 SwitchInst *CatchSwitch); | 51 Constant *LSDAAddrFn; 52 Value *PersonalityFn; 53 Constant *SelectorFn; 54 Constant *ExceptionFn; 55 Constant *CallSiteFn; 56 57 Value *CallSite; 58 public: --- 7 unchanged lines hidden (view full) --- 66 const char *getPassName() const { 67 return "SJLJ Exception Handling preparation"; 68 } 69 70 private: 71 void insertCallSiteStore(Instruction *I, int Number, Value *CallSite); 72 void markInvokeCallSite(InvokeInst *II, int InvokeNo, Value *CallSite, 73 SwitchInst *CatchSwitch); |
72 void splitLiveRangesLiveAcrossInvokes(SmallVector<InvokeInst*,16> &Invokes); | 74 void splitLiveRangesAcrossInvokes(SmallVector |
73 bool insertSjLjEHSupport(Function &F); 74 }; 75} // end anonymous namespace 76 77char SjLjEHPass::ID = 0; 78 79// Public Interface To the SjLjEHPass pass. 80FunctionPass *llvm::createSjLjEHPass(const TargetLowering *TLI) { --- 21 unchanged lines hidden (view full) --- 102 PointerType::getUnqual(FunctionContextTy), 103 (Type *)0); 104 UnregisterFn = 105 M.getOrInsertFunction("_Unwind_SjLj_Unregister", 106 Type::getVoidTy(M.getContext()), 107 PointerType::getUnqual(FunctionContextTy), 108 (Type *)0); 109 FrameAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::frameaddress); | 75 bool insertSjLjEHSupport(Function &F); 76 }; 77} // end anonymous namespace 78 79char SjLjEHPass::ID = 0; 80 81// Public Interface To the SjLjEHPass pass. 82FunctionPass *llvm::createSjLjEHPass(const TargetLowering *TLI) { --- 21 unchanged lines hidden (view full) --- 104 PointerType::getUnqual(FunctionContextTy), 105 (Type *)0); 106 UnregisterFn = 107 M.getOrInsertFunction("_Unwind_SjLj_Unregister", 108 Type::getVoidTy(M.getContext()), 109 PointerType::getUnqual(FunctionContextTy), 110 (Type *)0); 111 FrameAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::frameaddress); |
112 StackAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::stacksave); 113 StackRestoreFn = Intrinsic::getDeclaration(&M, Intrinsic::stackrestore); |
|
110 BuiltinSetjmpFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_setjmp); 111 LSDAAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_lsda); 112 SelectorFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_selector); 113 ExceptionFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_exception); 114 CallSiteFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_callsite); 115 PersonalityFn = 0; 116 117 return true; --- 52 unchanged lines hidden (view full) --- 170 for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) 171 MarkBlocksLiveIn(*PI, LiveBBs); 172} 173 174/// splitLiveRangesAcrossInvokes - Each value that is live across an unwind edge 175/// we spill into a stack location, guaranteeing that there is nothing live 176/// across the unwind edge. This process also splits all critical edges 177/// coming out of invoke's. | 114 BuiltinSetjmpFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_setjmp); 115 LSDAAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_lsda); 116 SelectorFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_selector); 117 ExceptionFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_exception); 118 CallSiteFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_callsite); 119 PersonalityFn = 0; 120 121 return true; --- 52 unchanged lines hidden (view full) --- 174 for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) 175 MarkBlocksLiveIn(*PI, LiveBBs); 176} 177 178/// splitLiveRangesAcrossInvokes - Each value that is live across an unwind edge 179/// we spill into a stack location, guaranteeing that there is nothing live 180/// across the unwind edge. This process also splits all critical edges 181/// coming out of invoke's. |
182/// FIXME: Move this function to a common utility file (Local.cpp?) so 183/// both SjLj and LowerInvoke can use it. |
|
178void SjLjEHPass:: | 184void SjLjEHPass:: |
179splitLiveRangesLiveAcrossInvokes(SmallVector<InvokeInst*,16> &Invokes) { | 185splitLiveRangesAcrossInvokes(SmallVector |
180 // First step, split all critical edges from invoke instructions. 181 for (unsigned i = 0, e = Invokes.size(); i != e; ++i) { 182 InvokeInst *II = Invokes[i]; 183 SplitCriticalEdge(II, 0, this); 184 SplitCriticalEdge(II, 1, this); 185 assert(!isa<PHINode>(II->getNormalDest()) && 186 !isa<PHINode>(II->getUnwindDest()) && 187 "critical edge splitting left single entry phi nodes?"); --- 5 unchanged lines hidden (view full) --- 193 // to a copy instruction in the entry block. This ensures that the argument 194 // value itself cannot be live across the entry block. 195 BasicBlock::iterator AfterAllocaInsertPt = F->begin()->begin(); 196 while (isa<AllocaInst>(AfterAllocaInsertPt) && 197 isa<ConstantInt>(cast<AllocaInst>(AfterAllocaInsertPt)->getArraySize())) 198 ++AfterAllocaInsertPt; 199 for (Function::arg_iterator AI = F->arg_begin(), E = F->arg_end(); 200 AI != E; ++AI) { | 186 // First step, split all critical edges from invoke instructions. 187 for (unsigned i = 0, e = Invokes.size(); i != e; ++i) { 188 InvokeInst *II = Invokes[i]; 189 SplitCriticalEdge(II, 0, this); 190 SplitCriticalEdge(II, 1, this); 191 assert(!isa<PHINode>(II->getNormalDest()) && 192 !isa<PHINode>(II->getUnwindDest()) && 193 "critical edge splitting left single entry phi nodes?"); --- 5 unchanged lines hidden (view full) --- 199 // to a copy instruction in the entry block. This ensures that the argument 200 // value itself cannot be live across the entry block. 201 BasicBlock::iterator AfterAllocaInsertPt = F->begin()->begin(); 202 while (isa<AllocaInst>(AfterAllocaInsertPt) && 203 isa<ConstantInt>(cast<AllocaInst>(AfterAllocaInsertPt)->getArraySize())) 204 ++AfterAllocaInsertPt; 205 for (Function::arg_iterator AI = F->arg_begin(), E = F->arg_end(); 206 AI != E; ++AI) { |
201 // This is always a no-op cast because we're casting AI to AI->getType() so 202 // src and destination types are identical. BitCast is the only possibility. 203 CastInst *NC = new BitCastInst( 204 AI, AI->getType(), AI->getName()+".tmp", AfterAllocaInsertPt); 205 AI->replaceAllUsesWith(NC); 206 // Normally its is forbidden to replace a CastInst's operand because it 207 // could cause the opcode to reflect an illegal conversion. However, we're 208 // replacing it here with the same value it was constructed with to simply 209 // make NC its user. 210 NC->setOperand(0, AI); | 207 const Type *Ty = AI->getType(); 208 // Aggregate types can't be cast, but are legal argument types, so we have 209 // to handle them differently. We use an extract/insert pair as a 210 // lightweight method to achieve the same goal. 211 if (isa<StructType>(Ty) || isa<ArrayType>(Ty) || isa<VectorType>(Ty)) { 212 Instruction *EI = ExtractValueInst::Create(AI, 0, "",AfterAllocaInsertPt); 213 Instruction *NI = InsertValueInst::Create(AI, EI, 0); 214 NI->insertAfter(EI); 215 AI->replaceAllUsesWith(NI); 216 // Set the operand of the instructions back to the AllocaInst. 217 EI->setOperand(0, AI); 218 NI->setOperand(0, AI); 219 } else { 220 // This is always a no-op cast because we're casting AI to AI->getType() 221 // so src and destination types are identical. BitCast is the only 222 // possibility. 223 CastInst *NC = new BitCastInst( 224 AI, AI->getType(), AI->getName()+".tmp", AfterAllocaInsertPt); 225 AI->replaceAllUsesWith(NC); 226 // Set the operand of the cast instruction back to the AllocaInst. 227 // Normally it's forbidden to replace a CastInst's operand because it 228 // could cause the opcode to reflect an illegal conversion. However, 229 // we're replacing it here with the same value it was constructed with. 230 // We do this because the above replaceAllUsesWith() clobbered the 231 // operand, but we want this one to remain. 232 NC->setOperand(0, AI); 233 } |
211 } 212 213 // Finally, scan the code looking for instructions with bad live ranges. 214 for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) 215 for (BasicBlock::iterator II = BB->begin(), E = BB->end(); II != E; ++II) { 216 // Ignore obvious cases we don't have to handle. In particular, most 217 // instructions either have no uses or only have a single use inside the 218 // current block. Ignore them quickly. --- 42 unchanged lines hidden (view full) --- 261 for (unsigned i = 0, e = Invokes.size(); i != e; ++i) { 262 BasicBlock *UnwindBlock = Invokes[i]->getUnwindDest(); 263 if (UnwindBlock != BB && LiveBBs.count(UnwindBlock)) { 264 NeedsSpill = true; 265 } 266 } 267 268 // If we decided we need a spill, do it. | 234 } 235 236 // Finally, scan the code looking for instructions with bad live ranges. 237 for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) 238 for (BasicBlock::iterator II = BB->begin(), E = BB->end(); II != E; ++II) { 239 // Ignore obvious cases we don't have to handle. In particular, most 240 // instructions either have no uses or only have a single use inside the 241 // current block. Ignore them quickly. --- 42 unchanged lines hidden (view full) --- 284 for (unsigned i = 0, e = Invokes.size(); i != e; ++i) { 285 BasicBlock *UnwindBlock = Invokes[i]->getUnwindDest(); 286 if (UnwindBlock != BB && LiveBBs.count(UnwindBlock)) { 287 NeedsSpill = true; 288 } 289 } 290 291 // If we decided we need a spill, do it. |
292 // FIXME: Spilling this way is overkill, as it forces all uses of 293 // the value to be reloaded from the stack slot, even those that aren't 294 // in the unwind blocks. We should be more selective. |
|
269 if (NeedsSpill) { 270 ++NumSpilled; 271 DemoteRegToStack(*Inst, true); 272 } 273 } 274} 275 276bool SjLjEHPass::insertSjLjEHSupport(Function &F) { --- 12 unchanged lines hidden (view full) --- 289 Invokes.push_back(II); 290 } else if (UnwindInst *UI = dyn_cast<UnwindInst>(BB->getTerminator())) { 291 Unwinds.push_back(UI); 292 } 293 } 294 // If we don't have any invokes or unwinds, there's nothing to do. 295 if (Unwinds.empty() && Invokes.empty()) return false; 296 | 295 if (NeedsSpill) { 296 ++NumSpilled; 297 DemoteRegToStack(*Inst, true); 298 } 299 } 300} 301 302bool SjLjEHPass::insertSjLjEHSupport(Function &F) { --- 12 unchanged lines hidden (view full) --- 315 Invokes.push_back(II); 316 } else if (UnwindInst *UI = dyn_cast<UnwindInst>(BB->getTerminator())) { 317 Unwinds.push_back(UI); 318 } 319 } 320 // If we don't have any invokes or unwinds, there's nothing to do. 321 if (Unwinds.empty() && Invokes.empty()) return false; 322 |
297 // Find the eh.selector.* and eh.exception calls. We'll use the first 298 // eh.selector to determine the right personality function to use. For 299 // SJLJ, we always use the same personality for the whole function, 300 // not on a per-selector basis. | 323 // Find the eh.selector.*, eh.exception and alloca calls. 324 // 325 // Remember any allocas() that aren't in the entry block, as the 326 // jmpbuf saved SP will need to be updated for them. 327 // 328 // We'll use the first eh.selector to determine the right personality 329 // function to use. For SJLJ, we always use the same personality for the 330 // whole function, not on a per-selector basis. |
301 // FIXME: That's a bit ugly. Better way? 302 SmallVector<CallInst*,16> EH_Selectors; 303 SmallVector<CallInst*,16> EH_Exceptions; | 331 // FIXME: That's a bit ugly. Better way? 332 SmallVector<CallInst*,16> EH_Selectors; 333 SmallVector<CallInst*,16> EH_Exceptions; |
304 for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { | 334 SmallVector<Instruction*,16> JmpbufUpdatePoints; 335 // Note: Skip the entry block since there's nothing there that interests 336 // us. eh.selector and eh.exception shouldn't ever be there, and we 337 // want to disregard any allocas that are there. 338 for (Function::iterator BB = F.begin(), E = F.end(); ++BB != E;) { |
305 for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) { 306 if (CallInst *CI = dyn_cast<CallInst>(I)) { 307 if (CI->getCalledFunction() == SelectorFn) { | 339 for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) { 340 if (CallInst *CI = dyn_cast<CallInst>(I)) { 341 if (CI->getCalledFunction() == SelectorFn) { |
308 if (!PersonalityFn) PersonalityFn = CI->getOperand(2); | 342 if (!PersonalityFn) PersonalityFn = CI->getArgOperand(1); |
309 EH_Selectors.push_back(CI); 310 } else if (CI->getCalledFunction() == ExceptionFn) { 311 EH_Exceptions.push_back(CI); | 343 EH_Selectors.push_back(CI); 344 } else if (CI->getCalledFunction() == ExceptionFn) { 345 EH_Exceptions.push_back(CI); |
346 } else if (CI->getCalledFunction() == StackRestoreFn) { 347 JmpbufUpdatePoints.push_back(CI); |
|
312 } | 348 } |
349 } else if (AllocaInst *AI = dyn_cast<AllocaInst>(I)) { 350 JmpbufUpdatePoints.push_back(AI); |
|
313 } 314 } 315 } 316 // If we don't have any eh.selector calls, we can't determine the personality 317 // function. Without a personality function, we can't process exceptions. 318 if (!PersonalityFn) return false; 319 320 NumInvokes += Invokes.size(); 321 NumUnwinds += Unwinds.size(); 322 323 if (!Invokes.empty()) { 324 // We have invokes, so we need to add register/unregister calls to get 325 // this function onto the global unwind stack. 326 // 327 // First thing we need to do is scan the whole function for values that are 328 // live across unwind edges. Each value that is live across an unwind edge 329 // we spill into a stack location, guaranteeing that there is nothing live 330 // across the unwind edge. This process also splits all critical edges 331 // coming out of invoke's. | 351 } 352 } 353 } 354 // If we don't have any eh.selector calls, we can't determine the personality 355 // function. Without a personality function, we can't process exceptions. 356 if (!PersonalityFn) return false; 357 358 NumInvokes += Invokes.size(); 359 NumUnwinds += Unwinds.size(); 360 361 if (!Invokes.empty()) { 362 // We have invokes, so we need to add register/unregister calls to get 363 // this function onto the global unwind stack. 364 // 365 // First thing we need to do is scan the whole function for values that are 366 // live across unwind edges. Each value that is live across an unwind edge 367 // we spill into a stack location, guaranteeing that there is nothing live 368 // across the unwind edge. This process also splits all critical edges 369 // coming out of invoke's. |
332 splitLiveRangesLiveAcrossInvokes(Invokes); | 370 splitLiveRangesAcrossInvokes(Invokes); |
333 334 BasicBlock *EntryBB = F.begin(); 335 // Create an alloca for the incoming jump buffer ptr and the new jump buffer 336 // that needs to be restored on all exits from the function. This is an 337 // alloca because the value needs to be added to the global context list. 338 unsigned Align = 4; // FIXME: Should be a TLI check? 339 AllocaInst *FunctionContext = 340 new AllocaInst(FunctionContextTy, 0, Align, --- 73 unchanged lines hidden (view full) --- 414 DispatchBlock); 415 // Split the entry block to insert the conditional branch for the setjmp. 416 BasicBlock *ContBlock = EntryBB->splitBasicBlock(EntryBB->getTerminator(), 417 "eh.sjlj.setjmp.cont"); 418 419 // Populate the Function Context 420 // 1. LSDA address 421 // 2. Personality function address | 371 372 BasicBlock *EntryBB = F.begin(); 373 // Create an alloca for the incoming jump buffer ptr and the new jump buffer 374 // that needs to be restored on all exits from the function. This is an 375 // alloca because the value needs to be added to the global context list. 376 unsigned Align = 4; // FIXME: Should be a TLI check? 377 AllocaInst *FunctionContext = 378 new AllocaInst(FunctionContextTy, 0, Align, --- 73 unchanged lines hidden (view full) --- 452 DispatchBlock); 453 // Split the entry block to insert the conditional branch for the setjmp. 454 BasicBlock *ContBlock = EntryBB->splitBasicBlock(EntryBB->getTerminator(), 455 "eh.sjlj.setjmp.cont"); 456 457 // Populate the Function Context 458 // 1. LSDA address 459 // 2. Personality function address |
422 // 3. jmpbuf (save FP and call eh.sjlj.setjmp) | 460 // 3. jmpbuf (save SP, FP and call eh.sjlj.setjmp) |
423 424 // LSDA address 425 Idxs[0] = Zero; 426 Idxs[1] = ConstantInt::get(Int32Ty, 4); 427 Value *LSDAFieldPtr = 428 GetElementPtrInst::Create(FunctionContext, Idxs, Idxs+2, 429 "lsda_gep", 430 EntryBB->getTerminator()); --- 4 unchanged lines hidden (view full) --- 435 Idxs[1] = ConstantInt::get(Int32Ty, 3); 436 Value *PersonalityFieldPtr = 437 GetElementPtrInst::Create(FunctionContext, Idxs, Idxs+2, 438 "lsda_gep", 439 EntryBB->getTerminator()); 440 new StoreInst(PersonalityFn, PersonalityFieldPtr, true, 441 EntryBB->getTerminator()); 442 | 461 462 // LSDA address 463 Idxs[0] = Zero; 464 Idxs[1] = ConstantInt::get(Int32Ty, 4); 465 Value *LSDAFieldPtr = 466 GetElementPtrInst::Create(FunctionContext, Idxs, Idxs+2, 467 "lsda_gep", 468 EntryBB->getTerminator()); --- 4 unchanged lines hidden (view full) --- 473 Idxs[1] = ConstantInt::get(Int32Ty, 3); 474 Value *PersonalityFieldPtr = 475 GetElementPtrInst::Create(FunctionContext, Idxs, Idxs+2, 476 "lsda_gep", 477 EntryBB->getTerminator()); 478 new StoreInst(PersonalityFn, PersonalityFieldPtr, true, 479 EntryBB->getTerminator()); 480 |
443 // Save the frame pointer. | 481 // Save the frame pointer. |
444 Idxs[1] = ConstantInt::get(Int32Ty, 5); | 482 Idxs[1] = ConstantInt::get(Int32Ty, 5); |
445 Value *FieldPtr | 483 Value *JBufPtr |
446 = GetElementPtrInst::Create(FunctionContext, Idxs, Idxs+2, 447 "jbuf_gep", 448 EntryBB->getTerminator()); 449 Idxs[1] = ConstantInt::get(Int32Ty, 0); | 484 = GetElementPtrInst::Create(FunctionContext, Idxs, Idxs+2, 485 "jbuf_gep", 486 EntryBB->getTerminator()); 487 Idxs[1] = ConstantInt::get(Int32Ty, 0); |
450 Value *ElemPtr = 451 GetElementPtrInst::Create(FieldPtr, Idxs, Idxs+2, "jbuf_fp_gep", | 488 Value *FramePtr = 489 GetElementPtrInst::Create(JBufPtr, Idxs, Idxs+2, "jbuf_fp_gep", |
452 EntryBB->getTerminator()); 453 454 Value *Val = CallInst::Create(FrameAddrFn, 455 ConstantInt::get(Int32Ty, 0), 456 "fp", 457 EntryBB->getTerminator()); | 490 EntryBB->getTerminator()); 491 492 Value *Val = CallInst::Create(FrameAddrFn, 493 ConstantInt::get(Int32Ty, 0), 494 "fp", 495 EntryBB->getTerminator()); |
458 new StoreInst(Val, ElemPtr, true, EntryBB->getTerminator()); 459 // Call the setjmp instrinsic. It fills in the rest of the jmpbuf | 496 new StoreInst(Val, FramePtr, true, EntryBB->getTerminator()); 497 498 // Save the stack pointer. 499 Idxs[1] = ConstantInt::get(Int32Ty, 2); 500 Value *StackPtr = 501 GetElementPtrInst::Create(JBufPtr, Idxs, Idxs+2, "jbuf_sp_gep", 502 EntryBB->getTerminator()); 503 504 Val = CallInst::Create(StackAddrFn, "sp", EntryBB->getTerminator()); 505 new StoreInst(Val, StackPtr, true, EntryBB->getTerminator()); 506 507 // Call the setjmp instrinsic. It fills in the rest of the jmpbuf. |
460 Value *SetjmpArg = | 508 Value *SetjmpArg = |
461 CastInst::Create(Instruction::BitCast, FieldPtr, | 509 CastInst::Create(Instruction::BitCast, JBufPtr, |
462 Type::getInt8PtrTy(F.getContext()), "", 463 EntryBB->getTerminator()); 464 Value *DispatchVal = CallInst::Create(BuiltinSetjmpFn, SetjmpArg, 465 "dispatch", 466 EntryBB->getTerminator()); | 510 Type::getInt8PtrTy(F.getContext()), "", 511 EntryBB->getTerminator()); 512 Value *DispatchVal = CallInst::Create(BuiltinSetjmpFn, SetjmpArg, 513 "dispatch", 514 EntryBB->getTerminator()); |
467 // check the return value of the setjmp. non-zero goes to dispatcher | 515 // check the return value of the setjmp. non-zero goes to dispatcher. |
468 Value *IsNormal = new ICmpInst(EntryBB->getTerminator(), 469 ICmpInst::ICMP_EQ, DispatchVal, Zero, 470 "notunwind"); 471 // Nuke the uncond branch. 472 EntryBB->getTerminator()->eraseFromParent(); 473 474 // Put in a new condbranch in its place. 475 BranchInst::Create(ContBlock, DispatchBlock, IsNormal, EntryBB); --- 28 unchanged lines hidden (view full) --- 504 505 // Replace all unwinds with a branch to the unwind handler. 506 // ??? Should this ever happen with sjlj exceptions? 507 for (unsigned i = 0, e = Unwinds.size(); i != e; ++i) { 508 BranchInst::Create(UnwindBlock, Unwinds[i]); 509 Unwinds[i]->eraseFromParent(); 510 } 511 | 516 Value *IsNormal = new ICmpInst(EntryBB->getTerminator(), 517 ICmpInst::ICMP_EQ, DispatchVal, Zero, 518 "notunwind"); 519 // Nuke the uncond branch. 520 EntryBB->getTerminator()->eraseFromParent(); 521 522 // Put in a new condbranch in its place. 523 BranchInst::Create(ContBlock, DispatchBlock, IsNormal, EntryBB); --- 28 unchanged lines hidden (view full) --- 552 553 // Replace all unwinds with a branch to the unwind handler. 554 // ??? Should this ever happen with sjlj exceptions? 555 for (unsigned i = 0, e = Unwinds.size(); i != e; ++i) { 556 BranchInst::Create(UnwindBlock, Unwinds[i]); 557 Unwinds[i]->eraseFromParent(); 558 } 559 |
560 // Following any allocas not in the entry block, update the saved SP 561 // in the jmpbuf to the new value. 562 for (unsigned i = 0, e = JmpbufUpdatePoints.size(); i != e; ++i) { 563 Instruction *AI = JmpbufUpdatePoints[i]; 564 Instruction *StackAddr = CallInst::Create(StackAddrFn, "sp"); 565 StackAddr->insertAfter(AI); 566 Instruction *StoreStackAddr = new StoreInst(StackAddr, StackPtr, true); 567 StoreStackAddr->insertAfter(StackAddr); 568 } 569 |
|
512 // Finally, for any returns from this function, if this function contains an 513 // invoke, add a call to unregister the function context. 514 for (unsigned i = 0, e = Returns.size(); i != e; ++i) 515 CallInst::Create(UnregisterFn, FunctionContext, "", Returns[i]); 516 } 517 518 return true; 519} 520 521bool SjLjEHPass::runOnFunction(Function &F) { 522 bool Res = insertSjLjEHSupport(F); 523 return Res; 524} | 570 // Finally, for any returns from this function, if this function contains an 571 // invoke, add a call to unregister the function context. 572 for (unsigned i = 0, e = Returns.size(); i != e; ++i) 573 CallInst::Create(UnregisterFn, FunctionContext, "", Returns[i]); 574 } 575 576 return true; 577} 578 579bool SjLjEHPass::runOnFunction(Function &F) { 580 bool Res = insertSjLjEHSupport(F); 581 return Res; 582} |