1 //===-- DwarfEHPrepare - Prepare exception handling for code generation ---===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This pass mulches exception handling code into a form adapted to code
11 // generation. Required if using dwarf exception handling.
13 //===----------------------------------------------------------------------===//
15 #define DEBUG_TYPE "dwarfehprepare"
16 #include "llvm/Function.h"
17 #include "llvm/Instructions.h"
18 #include "llvm/IntrinsicInst.h"
19 #include "llvm/Module.h"
20 #include "llvm/Pass.h"
21 #include "llvm/ADT/Statistic.h"
22 #include "llvm/Analysis/Dominators.h"
23 #include "llvm/CodeGen/Passes.h"
24 #include "llvm/MC/MCAsmInfo.h"
25 #include "llvm/Support/CallSite.h"
26 #include "llvm/Target/TargetLowering.h"
27 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
28 #include "llvm/Transforms/Utils/SSAUpdater.h"
31 STATISTIC(NumLandingPadsSplit, "Number of landing pads split");
32 STATISTIC(NumUnwindsLowered, "Number of unwind instructions lowered");
33 STATISTIC(NumExceptionValuesMoved, "Number of eh.exception calls moved");
36 class DwarfEHPrepare : public FunctionPass {
37 const TargetMachine *TM;
38 const TargetLowering *TLI;
40 // The eh.exception intrinsic.
41 Function *ExceptionValueIntrinsic;
43 // The eh.selector intrinsic.
44 Function *SelectorIntrinsic;
46 // _Unwind_Resume_or_Rethrow call.
49 // The EH language-specific catch-all type.
50 GlobalVariable *EHCatchAllValue;
52 // _Unwind_Resume or the target equivalent.
53 Constant *RewindFunction;
55 // We both use and preserve dominator info.
58 // The function we are running on.
61 // The landing pads for this function.
62 typedef SmallPtrSet<BasicBlock*, 8> BBSet;
65 bool NormalizeLandingPads();
67 bool MoveExceptionValueCalls();
69 Instruction *CreateExceptionValueCall(BasicBlock *BB);
71 /// CleanupSelectors - Any remaining eh.selector intrinsic calls which still
72 /// use the "llvm.eh.catch.all.value" call need to convert to using its
73 /// initializer instead.
74 bool CleanupSelectors(SmallPtrSet<IntrinsicInst*, 32> &Sels);
76 bool HasCatchAllInSelector(IntrinsicInst *);
78 /// FindAllCleanupSelectors - Find all eh.selector calls that are clean-ups.
79 void FindAllCleanupSelectors(SmallPtrSet<IntrinsicInst*, 32> &Sels,
80 SmallPtrSet<IntrinsicInst*, 32> &CatchAllSels);
82 /// FindAllURoRInvokes - Find all URoR invokes in the function.
83 void FindAllURoRInvokes(SmallPtrSet<InvokeInst*, 32> &URoRInvokes);
85 /// HandleURoRInvokes - Handle invokes of "_Unwind_Resume_or_Rethrow"
86 /// calls. The "unwind" part of these invokes jump to a landing pad within
87 /// the current function. This is a candidate to merge the selector
88 /// associated with the URoR invoke with the one from the URoR's landing
90 bool HandleURoRInvokes();
92 /// FindSelectorAndURoR - Find the eh.selector call and URoR call associated
93 /// with the eh.exception call. This recursively looks past instructions
94 /// which don't change the EH pointer value, like casts or PHI nodes.
95 bool FindSelectorAndURoR(Instruction *Inst, bool &URoRInvoke,
96 SmallPtrSet<IntrinsicInst*, 8> &SelCalls);
99 static char ID; // Pass identification, replacement for typeid.
100 DwarfEHPrepare(const TargetMachine *tm) :
101 FunctionPass(ID), TM(tm), TLI(TM->getTargetLowering()),
102 ExceptionValueIntrinsic(0), SelectorIntrinsic(0),
103 URoR(0), EHCatchAllValue(0), RewindFunction(0) {
104 initializeDominatorTreePass(*PassRegistry::getPassRegistry());
107 virtual bool runOnFunction(Function &Fn);
109 // getAnalysisUsage - We need the dominator tree for handling URoR.
110 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
111 AU.addRequired<DominatorTree>();
112 AU.addPreserved<DominatorTree>();
115 const char *getPassName() const {
116 return "Exception handling preparation";
120 } // end anonymous namespace
122 char DwarfEHPrepare::ID = 0;
124 FunctionPass *llvm::createDwarfEHPass(const TargetMachine *tm) {
125 return new DwarfEHPrepare(tm);
128 /// HasCatchAllInSelector - Return true if the intrinsic instruction has a
130 bool DwarfEHPrepare::HasCatchAllInSelector(IntrinsicInst *II) {
131 if (!EHCatchAllValue) return false;
133 unsigned ArgIdx = II->getNumArgOperands() - 1;
134 GlobalVariable *GV = dyn_cast<GlobalVariable>(II->getArgOperand(ArgIdx));
135 return GV == EHCatchAllValue;
138 /// FindAllCleanupSelectors - Find all eh.selector calls that are clean-ups.
139 void DwarfEHPrepare::
140 FindAllCleanupSelectors(SmallPtrSet<IntrinsicInst*, 32> &Sels,
141 SmallPtrSet<IntrinsicInst*, 32> &CatchAllSels) {
142 for (Value::use_iterator
143 I = SelectorIntrinsic->use_begin(),
144 E = SelectorIntrinsic->use_end(); I != E; ++I) {
145 IntrinsicInst *II = cast<IntrinsicInst>(*I);
147 if (II->getParent()->getParent() != F)
150 if (!HasCatchAllInSelector(II))
153 CatchAllSels.insert(II);
157 /// FindAllURoRInvokes - Find all URoR invokes in the function.
158 void DwarfEHPrepare::
159 FindAllURoRInvokes(SmallPtrSet<InvokeInst*, 32> &URoRInvokes) {
160 for (Value::use_iterator
161 I = URoR->use_begin(),
162 E = URoR->use_end(); I != E; ++I) {
163 if (InvokeInst *II = dyn_cast<InvokeInst>(*I))
164 URoRInvokes.insert(II);
168 /// CleanupSelectors - Any remaining eh.selector intrinsic calls which still use
169 /// the "llvm.eh.catch.all.value" call need to convert to using its
170 /// initializer instead.
171 bool DwarfEHPrepare::CleanupSelectors(SmallPtrSet<IntrinsicInst*, 32> &Sels) {
172 if (!EHCatchAllValue) return false;
174 if (!SelectorIntrinsic) {
176 Intrinsic::getDeclaration(F->getParent(), Intrinsic::eh_selector);
177 if (!SelectorIntrinsic) return false;
180 bool Changed = false;
181 for (SmallPtrSet<IntrinsicInst*, 32>::iterator
182 I = Sels.begin(), E = Sels.end(); I != E; ++I) {
183 IntrinsicInst *Sel = *I;
185 // Index of the "llvm.eh.catch.all.value" variable.
186 unsigned OpIdx = Sel->getNumArgOperands() - 1;
187 GlobalVariable *GV = dyn_cast<GlobalVariable>(Sel->getArgOperand(OpIdx));
188 if (GV != EHCatchAllValue) continue;
189 Sel->setArgOperand(OpIdx, EHCatchAllValue->getInitializer());
196 /// FindSelectorAndURoR - Find the eh.selector call associated with the
197 /// eh.exception call. And indicate if there is a URoR "invoke" associated with
198 /// the eh.exception call. This recursively looks past instructions which don't
199 /// change the EH pointer value, like casts or PHI nodes.
201 DwarfEHPrepare::FindSelectorAndURoR(Instruction *Inst, bool &URoRInvoke,
202 SmallPtrSet<IntrinsicInst*, 8> &SelCalls) {
203 SmallPtrSet<PHINode*, 32> SeenPHIs;
204 bool Changed = false;
206 for (Value::use_iterator
207 I = Inst->use_begin(), E = Inst->use_end(); I != E; ++I) {
208 Instruction *II = dyn_cast<Instruction>(*I);
209 if (!II || II->getParent()->getParent() != F) continue;
211 if (IntrinsicInst *Sel = dyn_cast<IntrinsicInst>(II)) {
212 if (Sel->getIntrinsicID() == Intrinsic::eh_selector)
213 SelCalls.insert(Sel);
214 } else if (InvokeInst *Invoke = dyn_cast<InvokeInst>(II)) {
215 if (Invoke->getCalledFunction() == URoR)
217 } else if (CastInst *CI = dyn_cast<CastInst>(II)) {
218 Changed |= FindSelectorAndURoR(CI, URoRInvoke, SelCalls);
219 } else if (PHINode *PN = dyn_cast<PHINode>(II)) {
220 if (SeenPHIs.insert(PN))
221 // Don't process a PHI node more than once.
222 Changed |= FindSelectorAndURoR(PN, URoRInvoke, SelCalls);
229 /// HandleURoRInvokes - Handle invokes of "_Unwind_Resume_or_Rethrow" calls. The
230 /// "unwind" part of these invokes jump to a landing pad within the current
231 /// function. This is a candidate to merge the selector associated with the URoR
232 /// invoke with the one from the URoR's landing pad.
233 bool DwarfEHPrepare::HandleURoRInvokes() {
234 if (!EHCatchAllValue) {
236 F->getParent()->getNamedGlobal("llvm.eh.catch.all.value");
237 if (!EHCatchAllValue) return false;
240 if (!SelectorIntrinsic) {
242 Intrinsic::getDeclaration(F->getParent(), Intrinsic::eh_selector);
243 if (!SelectorIntrinsic) return false;
246 SmallPtrSet<IntrinsicInst*, 32> Sels;
247 SmallPtrSet<IntrinsicInst*, 32> CatchAllSels;
248 FindAllCleanupSelectors(Sels, CatchAllSels);
251 URoR = F->getParent()->getFunction("_Unwind_Resume_or_Rethrow");
252 if (!URoR) return CleanupSelectors(CatchAllSels);
255 SmallPtrSet<InvokeInst*, 32> URoRInvokes;
256 FindAllURoRInvokes(URoRInvokes);
258 SmallPtrSet<IntrinsicInst*, 32> SelsToConvert;
260 for (SmallPtrSet<IntrinsicInst*, 32>::iterator
261 SI = Sels.begin(), SE = Sels.end(); SI != SE; ++SI) {
262 const BasicBlock *SelBB = (*SI)->getParent();
263 for (SmallPtrSet<InvokeInst*, 32>::iterator
264 UI = URoRInvokes.begin(), UE = URoRInvokes.end(); UI != UE; ++UI) {
265 const BasicBlock *URoRBB = (*UI)->getParent();
266 if (DT->dominates(SelBB, URoRBB)) {
267 SelsToConvert.insert(*SI);
273 bool Changed = false;
275 if (Sels.size() != SelsToConvert.size()) {
276 // If we haven't been able to convert all of the clean-up selectors, then
277 // loop through the slow way to see if they still need to be converted.
278 if (!ExceptionValueIntrinsic) {
279 ExceptionValueIntrinsic =
280 Intrinsic::getDeclaration(F->getParent(), Intrinsic::eh_exception);
281 if (!ExceptionValueIntrinsic)
282 return CleanupSelectors(CatchAllSels);
285 for (Value::use_iterator
286 I = ExceptionValueIntrinsic->use_begin(),
287 E = ExceptionValueIntrinsic->use_end(); I != E; ++I) {
288 IntrinsicInst *EHPtr = dyn_cast<IntrinsicInst>(*I);
289 if (!EHPtr || EHPtr->getParent()->getParent() != F) continue;
291 bool URoRInvoke = false;
292 SmallPtrSet<IntrinsicInst*, 8> SelCalls;
293 Changed |= FindSelectorAndURoR(EHPtr, URoRInvoke, SelCalls);
296 // This EH pointer is being used by an invoke of an URoR instruction and
297 // an eh.selector intrinsic call. If the eh.selector is a 'clean-up', we
298 // need to convert it to a 'catch-all'.
299 for (SmallPtrSet<IntrinsicInst*, 8>::iterator
300 SI = SelCalls.begin(), SE = SelCalls.end(); SI != SE; ++SI)
301 if (!HasCatchAllInSelector(*SI))
302 SelsToConvert.insert(*SI);
307 if (!SelsToConvert.empty()) {
308 // Convert all clean-up eh.selectors, which are associated with "invokes" of
309 // URoR calls, into catch-all eh.selectors.
312 for (SmallPtrSet<IntrinsicInst*, 8>::iterator
313 SI = SelsToConvert.begin(), SE = SelsToConvert.end();
315 IntrinsicInst *II = *SI;
317 // Use the exception object pointer and the personality function
318 // from the original selector.
320 IntrinsicInst::op_iterator I = CS.arg_begin();
321 IntrinsicInst::op_iterator E = CS.arg_end();
322 IntrinsicInst::op_iterator B = prior(E);
324 // Exclude last argument if it is an integer.
325 if (isa<ConstantInt>(B)) E = B;
327 // Add exception object pointer (front).
328 // Add personality function (next).
329 // Add in any filter IDs (rest).
330 SmallVector<Value*, 8> Args(I, E);
332 Args.push_back(EHCatchAllValue->getInitializer()); // Catch-all indicator.
334 CallInst *NewSelector =
335 CallInst::Create(SelectorIntrinsic, Args.begin(), Args.end(),
336 "eh.sel.catch.all", II);
338 NewSelector->setTailCall(II->isTailCall());
339 NewSelector->setAttributes(II->getAttributes());
340 NewSelector->setCallingConv(II->getCallingConv());
342 II->replaceAllUsesWith(NewSelector);
343 II->eraseFromParent();
347 Changed |= CleanupSelectors(CatchAllSels);
351 /// NormalizeLandingPads - Normalize and discover landing pads, noting them
352 /// in the LandingPads set. A landing pad is normal if the only CFG edges
353 /// that end at it are unwind edges from invoke instructions. If we inlined
354 /// through an invoke we could have a normal branch from the previous
355 /// unwind block through to the landing pad for the original invoke.
356 /// Abnormal landing pads are fixed up by redirecting all unwind edges to
357 /// a new basic block which falls through to the original.
358 bool DwarfEHPrepare::NormalizeLandingPads() {
359 bool Changed = false;
361 const MCAsmInfo *MAI = TM->getMCAsmInfo();
362 bool usingSjLjEH = MAI->getExceptionHandlingType() == ExceptionHandling::SjLj;
364 for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
365 TerminatorInst *TI = I->getTerminator();
366 if (!isa<InvokeInst>(TI))
368 BasicBlock *LPad = TI->getSuccessor(1);
369 // Skip landing pads that have already been normalized.
370 if (LandingPads.count(LPad))
373 // Check that only invoke unwind edges end at the landing pad.
374 bool OnlyUnwoundTo = true;
375 bool SwitchOK = usingSjLjEH;
376 for (pred_iterator PI = pred_begin(LPad), PE = pred_end(LPad);
378 TerminatorInst *PT = (*PI)->getTerminator();
379 // The SjLj dispatch block uses a switch instruction. This is effectively
380 // an unwind edge, so we can disregard it here. There will only ever
381 // be one dispatch, however, so if there are multiple switches, one
382 // of them truly is a normal edge, not an unwind edge.
383 if (SwitchOK && isa<SwitchInst>(PT)) {
387 if (!isa<InvokeInst>(PT) || LPad == PT->getSuccessor(0)) {
388 OnlyUnwoundTo = false;
394 // Only unwind edges lead to the landing pad. Remember the landing pad.
395 LandingPads.insert(LPad);
399 // At least one normal edge ends at the landing pad. Redirect the unwind
400 // edges to a new basic block which falls through into this one.
402 // Create the new basic block.
403 BasicBlock *NewBB = BasicBlock::Create(F->getContext(),
404 LPad->getName() + "_unwind_edge");
406 // Insert it into the function right before the original landing pad.
407 LPad->getParent()->getBasicBlockList().insert(LPad, NewBB);
409 // Redirect unwind edges from the original landing pad to NewBB.
410 for (pred_iterator PI = pred_begin(LPad), PE = pred_end(LPad); PI != PE; ) {
411 TerminatorInst *PT = (*PI++)->getTerminator();
412 if (isa<InvokeInst>(PT) && PT->getSuccessor(1) == LPad)
413 // Unwind to the new block.
414 PT->setSuccessor(1, NewBB);
417 // If there are any PHI nodes in LPad, we need to update them so that they
418 // merge incoming values from NewBB instead.
419 for (BasicBlock::iterator II = LPad->begin(); isa<PHINode>(II); ++II) {
420 PHINode *PN = cast<PHINode>(II);
421 pred_iterator PB = pred_begin(NewBB), PE = pred_end(NewBB);
423 // Check to see if all of the values coming in via unwind edges are the
424 // same. If so, we don't need to create a new PHI node.
425 Value *InVal = PN->getIncomingValueForBlock(*PB);
426 for (pred_iterator PI = PB; PI != PE; ++PI) {
427 if (PI != PB && InVal != PN->getIncomingValueForBlock(*PI)) {
434 // Different unwind edges have different values. Create a new PHI node
436 PHINode *NewPN = PHINode::Create(PN->getType(), PN->getName()+".unwind",
438 // Add an entry for each unwind edge, using the value from the old PHI.
439 for (pred_iterator PI = PB; PI != PE; ++PI)
440 NewPN->addIncoming(PN->getIncomingValueForBlock(*PI), *PI);
442 // Now use this new PHI as the common incoming value for NewBB in PN.
446 // Revector exactly one entry in the PHI node to come from NewBB
447 // and delete all other entries that come from unwind edges. If
448 // there are both normal and unwind edges from the same predecessor,
449 // this leaves an entry for the normal edge.
450 for (pred_iterator PI = PB; PI != PE; ++PI)
451 PN->removeIncomingValue(*PI);
452 PN->addIncoming(InVal, NewBB);
455 // Add a fallthrough from NewBB to the original landing pad.
456 BranchInst::Create(LPad, NewBB);
458 // Now update DominatorTree analysis information.
459 DT->splitBlock(NewBB);
461 // Remember the newly constructed landing pad. The original landing pad
462 // LPad is no longer a landing pad now that all unwind edges have been
463 // revectored to NewBB.
464 LandingPads.insert(NewBB);
465 ++NumLandingPadsSplit;
472 /// LowerUnwinds - Turn unwind instructions into calls to _Unwind_Resume,
473 /// rethrowing any previously caught exception. This will crash horribly
474 /// at runtime if there is no such exception: using unwind to throw a new
475 /// exception is currently not supported.
476 bool DwarfEHPrepare::LowerUnwinds() {
477 SmallVector<TerminatorInst*, 16> UnwindInsts;
479 for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
480 TerminatorInst *TI = I->getTerminator();
481 if (isa<UnwindInst>(TI))
482 UnwindInsts.push_back(TI);
485 if (UnwindInsts.empty()) return false;
487 // Find the rewind function if we didn't already.
488 if (!RewindFunction) {
489 LLVMContext &Ctx = UnwindInsts[0]->getContext();
490 std::vector<const Type*>
491 Params(1, Type::getInt8PtrTy(Ctx));
492 FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx),
494 const char *RewindName = TLI->getLibcallName(RTLIB::UNWIND_RESUME);
495 RewindFunction = F->getParent()->getOrInsertFunction(RewindName, FTy);
498 bool Changed = false;
500 for (SmallVectorImpl<TerminatorInst*>::iterator
501 I = UnwindInsts.begin(), E = UnwindInsts.end(); I != E; ++I) {
502 TerminatorInst *TI = *I;
504 // Replace the unwind instruction with a call to _Unwind_Resume (or the
505 // appropriate target equivalent) followed by an UnreachableInst.
507 // Create the call...
508 CallInst *CI = CallInst::Create(RewindFunction,
509 CreateExceptionValueCall(TI->getParent()),
511 CI->setCallingConv(TLI->getLibcallCallingConv(RTLIB::UNWIND_RESUME));
512 // ...followed by an UnreachableInst.
513 new UnreachableInst(TI->getContext(), TI);
515 // Nuke the unwind instruction.
516 TI->eraseFromParent();
524 /// MoveExceptionValueCalls - Ensure that eh.exception is only ever called from
525 /// landing pads by replacing calls outside of landing pads with direct use of
526 /// a register holding the appropriate value; this requires adding calls inside
527 /// all landing pads to initialize the register. Also, move eh.exception calls
528 /// inside landing pads to the start of the landing pad (optional, but may make
529 /// things simpler for later passes).
530 bool DwarfEHPrepare::MoveExceptionValueCalls() {
531 // If the eh.exception intrinsic is not declared in the module then there is
532 // nothing to do. Speed up compilation by checking for this common case.
533 if (!ExceptionValueIntrinsic &&
534 !F->getParent()->getFunction(Intrinsic::getName(Intrinsic::eh_exception)))
537 bool Changed = false;
539 // Move calls to eh.exception that are inside a landing pad to the start of
541 for (BBSet::const_iterator LI = LandingPads.begin(), LE = LandingPads.end();
543 BasicBlock *LP = *LI;
544 for (BasicBlock::iterator II = LP->getFirstNonPHIOrDbg(), IE = LP->end();
546 if (EHExceptionInst *EI = dyn_cast<EHExceptionInst>(II++)) {
547 // Found a call to eh.exception.
548 if (!EI->use_empty()) {
549 // If there is already a call to eh.exception at the start of the
550 // landing pad, then get hold of it; otherwise create such a call.
551 Value *CallAtStart = CreateExceptionValueCall(LP);
553 // If the call was at the start of a landing pad then leave it alone.
554 if (EI == CallAtStart)
556 EI->replaceAllUsesWith(CallAtStart);
558 EI->eraseFromParent();
559 ++NumExceptionValuesMoved;
564 // Look for calls to eh.exception that are not in a landing pad. If one is
565 // found, then a register that holds the exception value will be created in
566 // each landing pad, and the SSAUpdater will be used to compute the values
567 // returned by eh.exception calls outside of landing pads.
570 // Remember where we found the eh.exception call, to avoid rescanning earlier
571 // basic blocks which we already know contain no eh.exception calls.
572 bool FoundCallOutsideLandingPad = false;
573 Function::iterator BB = F->begin();
574 for (Function::iterator BE = F->end(); BB != BE; ++BB) {
575 // Skip over landing pads.
576 if (LandingPads.count(BB))
579 for (BasicBlock::iterator II = BB->getFirstNonPHIOrDbg(), IE = BB->end();
581 if (isa<EHExceptionInst>(II)) {
582 SSA.Initialize(II->getType(), II->getName());
583 FoundCallOutsideLandingPad = true;
587 if (FoundCallOutsideLandingPad)
591 // If all calls to eh.exception are in landing pads then we are done.
592 if (!FoundCallOutsideLandingPad)
595 // Add a call to eh.exception at the start of each landing pad, and tell the
596 // SSAUpdater that this is the value produced by the landing pad.
597 for (BBSet::iterator LI = LandingPads.begin(), LE = LandingPads.end();
599 SSA.AddAvailableValue(*LI, CreateExceptionValueCall(*LI));
601 // Now turn all calls to eh.exception that are not in a landing pad into a use
602 // of the appropriate register.
603 for (Function::iterator BE = F->end(); BB != BE; ++BB) {
604 // Skip over landing pads.
605 if (LandingPads.count(BB))
608 for (BasicBlock::iterator II = BB->getFirstNonPHIOrDbg(), IE = BB->end();
610 if (EHExceptionInst *EI = dyn_cast<EHExceptionInst>(II++)) {
611 // Found a call to eh.exception, replace it with the value from any
612 // upstream landing pad(s).
613 EI->replaceAllUsesWith(SSA.GetValueAtEndOfBlock(BB));
614 EI->eraseFromParent();
615 ++NumExceptionValuesMoved;
622 /// CreateExceptionValueCall - Insert a call to the eh.exception intrinsic at
623 /// the start of the basic block (unless there already is one, in which case
624 /// the existing call is returned).
625 Instruction *DwarfEHPrepare::CreateExceptionValueCall(BasicBlock *BB) {
626 Instruction *Start = BB->getFirstNonPHIOrDbg();
627 // Is this a call to eh.exception?
628 if (IntrinsicInst *CI = dyn_cast<IntrinsicInst>(Start))
629 if (CI->getIntrinsicID() == Intrinsic::eh_exception)
630 // Reuse the existing call.
633 // Find the eh.exception intrinsic if we didn't already.
634 if (!ExceptionValueIntrinsic)
635 ExceptionValueIntrinsic = Intrinsic::getDeclaration(F->getParent(),
636 Intrinsic::eh_exception);
639 return CallInst::Create(ExceptionValueIntrinsic, "eh.value.call", Start);
642 bool DwarfEHPrepare::runOnFunction(Function &Fn) {
643 bool Changed = false;
645 // Initialize internal state.
646 DT = &getAnalysis<DominatorTree>();
649 // Ensure that only unwind edges end at landing pads (a landing pad is a
650 // basic block where an invoke unwind edge ends).
651 Changed |= NormalizeLandingPads();
653 // Turn unwind instructions into libcalls.
654 Changed |= LowerUnwinds();
656 // TODO: Move eh.selector calls to landing pads and combine them.
658 // Move eh.exception calls to landing pads.
659 Changed |= MoveExceptionValueCalls();
661 Changed |= HandleURoRInvokes();