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) {}
105
virtual bool runOnFunction(Function &Fn);
107
// getAnalysisUsage - We need the dominator tree for handling URoR.
108
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
109
AU.addRequired<DominatorTree>();
110
AU.addPreserved<DominatorTree>();
113
const char *getPassName() const {
114
return "Exception handling preparation";
118
} // end anonymous namespace
120
char DwarfEHPrepare::ID = 0;
122
FunctionPass *llvm::createDwarfEHPass(const TargetMachine *tm) {
123
return new DwarfEHPrepare(tm);
126
/// HasCatchAllInSelector - Return true if the intrinsic instruction has a
128
bool DwarfEHPrepare::HasCatchAllInSelector(IntrinsicInst *II) {
129
if (!EHCatchAllValue) return false;
131
unsigned ArgIdx = II->getNumArgOperands() - 1;
132
GlobalVariable *GV = dyn_cast<GlobalVariable>(II->getArgOperand(ArgIdx));
133
return GV == EHCatchAllValue;
136
/// FindAllCleanupSelectors - Find all eh.selector calls that are clean-ups.
137
void DwarfEHPrepare::
138
FindAllCleanupSelectors(SmallPtrSet<IntrinsicInst*, 32> &Sels,
139
SmallPtrSet<IntrinsicInst*, 32> &CatchAllSels) {
140
for (Value::use_iterator
141
I = SelectorIntrinsic->use_begin(),
142
E = SelectorIntrinsic->use_end(); I != E; ++I) {
143
IntrinsicInst *II = cast<IntrinsicInst>(*I);
145
if (II->getParent()->getParent() != F)
148
if (!HasCatchAllInSelector(II))
151
CatchAllSels.insert(II);
155
/// FindAllURoRInvokes - Find all URoR invokes in the function.
156
void DwarfEHPrepare::
157
FindAllURoRInvokes(SmallPtrSet<InvokeInst*, 32> &URoRInvokes) {
158
for (Value::use_iterator
159
I = URoR->use_begin(),
160
E = URoR->use_end(); I != E; ++I) {
161
if (InvokeInst *II = dyn_cast<InvokeInst>(*I))
162
URoRInvokes.insert(II);
166
/// CleanupSelectors - Any remaining eh.selector intrinsic calls which still use
167
/// the "llvm.eh.catch.all.value" call need to convert to using its
168
/// initializer instead.
169
bool DwarfEHPrepare::CleanupSelectors(SmallPtrSet<IntrinsicInst*, 32> &Sels) {
170
if (!EHCatchAllValue) return false;
172
if (!SelectorIntrinsic) {
174
Intrinsic::getDeclaration(F->getParent(), Intrinsic::eh_selector);
175
if (!SelectorIntrinsic) return false;
178
bool Changed = false;
179
for (SmallPtrSet<IntrinsicInst*, 32>::iterator
180
I = Sels.begin(), E = Sels.end(); I != E; ++I) {
181
IntrinsicInst *Sel = *I;
183
// Index of the "llvm.eh.catch.all.value" variable.
184
unsigned OpIdx = Sel->getNumArgOperands() - 1;
185
GlobalVariable *GV = dyn_cast<GlobalVariable>(Sel->getArgOperand(OpIdx));
186
if (GV != EHCatchAllValue) continue;
187
Sel->setArgOperand(OpIdx, EHCatchAllValue->getInitializer());
194
/// FindSelectorAndURoR - Find the eh.selector call associated with the
195
/// eh.exception call. And indicate if there is a URoR "invoke" associated with
196
/// the eh.exception call. This recursively looks past instructions which don't
197
/// change the EH pointer value, like casts or PHI nodes.
199
DwarfEHPrepare::FindSelectorAndURoR(Instruction *Inst, bool &URoRInvoke,
200
SmallPtrSet<IntrinsicInst*, 8> &SelCalls) {
201
SmallPtrSet<PHINode*, 32> SeenPHIs;
202
bool Changed = false;
204
for (Value::use_iterator
205
I = Inst->use_begin(), E = Inst->use_end(); I != E; ++I) {
206
Instruction *II = dyn_cast<Instruction>(*I);
207
if (!II || II->getParent()->getParent() != F) continue;
209
if (IntrinsicInst *Sel = dyn_cast<IntrinsicInst>(II)) {
210
if (Sel->getIntrinsicID() == Intrinsic::eh_selector)
211
SelCalls.insert(Sel);
212
} else if (InvokeInst *Invoke = dyn_cast<InvokeInst>(II)) {
213
if (Invoke->getCalledFunction() == URoR)
215
} else if (CastInst *CI = dyn_cast<CastInst>(II)) {
216
Changed |= FindSelectorAndURoR(CI, URoRInvoke, SelCalls);
217
} else if (PHINode *PN = dyn_cast<PHINode>(II)) {
218
if (SeenPHIs.insert(PN))
219
// Don't process a PHI node more than once.
220
Changed |= FindSelectorAndURoR(PN, URoRInvoke, SelCalls);
227
/// HandleURoRInvokes - Handle invokes of "_Unwind_Resume_or_Rethrow" calls. The
228
/// "unwind" part of these invokes jump to a landing pad within the current
229
/// function. This is a candidate to merge the selector associated with the URoR
230
/// invoke with the one from the URoR's landing pad.
231
bool DwarfEHPrepare::HandleURoRInvokes() {
232
if (!EHCatchAllValue) {
234
F->getParent()->getNamedGlobal("llvm.eh.catch.all.value");
235
if (!EHCatchAllValue) return false;
238
if (!SelectorIntrinsic) {
240
Intrinsic::getDeclaration(F->getParent(), Intrinsic::eh_selector);
241
if (!SelectorIntrinsic) return false;
244
SmallPtrSet<IntrinsicInst*, 32> Sels;
245
SmallPtrSet<IntrinsicInst*, 32> CatchAllSels;
246
FindAllCleanupSelectors(Sels, CatchAllSels);
249
URoR = F->getParent()->getFunction("_Unwind_Resume_or_Rethrow");
250
if (!URoR) return CleanupSelectors(CatchAllSels);
253
SmallPtrSet<InvokeInst*, 32> URoRInvokes;
254
FindAllURoRInvokes(URoRInvokes);
256
SmallPtrSet<IntrinsicInst*, 32> SelsToConvert;
258
for (SmallPtrSet<IntrinsicInst*, 32>::iterator
259
SI = Sels.begin(), SE = Sels.end(); SI != SE; ++SI) {
260
const BasicBlock *SelBB = (*SI)->getParent();
261
for (SmallPtrSet<InvokeInst*, 32>::iterator
262
UI = URoRInvokes.begin(), UE = URoRInvokes.end(); UI != UE; ++UI) {
263
const BasicBlock *URoRBB = (*UI)->getParent();
264
if (DT->dominates(SelBB, URoRBB)) {
265
SelsToConvert.insert(*SI);
271
bool Changed = false;
273
if (Sels.size() != SelsToConvert.size()) {
274
// If we haven't been able to convert all of the clean-up selectors, then
275
// loop through the slow way to see if they still need to be converted.
276
if (!ExceptionValueIntrinsic) {
277
ExceptionValueIntrinsic =
278
Intrinsic::getDeclaration(F->getParent(), Intrinsic::eh_exception);
279
if (!ExceptionValueIntrinsic)
280
return CleanupSelectors(CatchAllSels);
283
for (Value::use_iterator
284
I = ExceptionValueIntrinsic->use_begin(),
285
E = ExceptionValueIntrinsic->use_end(); I != E; ++I) {
286
IntrinsicInst *EHPtr = dyn_cast<IntrinsicInst>(*I);
287
if (!EHPtr || EHPtr->getParent()->getParent() != F) continue;
289
bool URoRInvoke = false;
290
SmallPtrSet<IntrinsicInst*, 8> SelCalls;
291
Changed |= FindSelectorAndURoR(EHPtr, URoRInvoke, SelCalls);
294
// This EH pointer is being used by an invoke of an URoR instruction and
295
// an eh.selector intrinsic call. If the eh.selector is a 'clean-up', we
296
// need to convert it to a 'catch-all'.
297
for (SmallPtrSet<IntrinsicInst*, 8>::iterator
298
SI = SelCalls.begin(), SE = SelCalls.end(); SI != SE; ++SI)
299
if (!HasCatchAllInSelector(*SI))
300
SelsToConvert.insert(*SI);
305
if (!SelsToConvert.empty()) {
306
// Convert all clean-up eh.selectors, which are associated with "invokes" of
307
// URoR calls, into catch-all eh.selectors.
310
for (SmallPtrSet<IntrinsicInst*, 8>::iterator
311
SI = SelsToConvert.begin(), SE = SelsToConvert.end();
313
IntrinsicInst *II = *SI;
315
// Use the exception object pointer and the personality function
316
// from the original selector.
318
IntrinsicInst::op_iterator I = CS.arg_begin();
319
IntrinsicInst::op_iterator E = CS.arg_end();
320
IntrinsicInst::op_iterator B = prior(E);
322
// Exclude last argument if it is an integer.
323
if (isa<ConstantInt>(B)) E = B;
325
// Add exception object pointer (front).
326
// Add personality function (next).
327
// Add in any filter IDs (rest).
328
SmallVector<Value*, 8> Args(I, E);
330
Args.push_back(EHCatchAllValue->getInitializer()); // Catch-all indicator.
332
CallInst *NewSelector =
333
CallInst::Create(SelectorIntrinsic, Args.begin(), Args.end(),
334
"eh.sel.catch.all", II);
336
NewSelector->setTailCall(II->isTailCall());
337
NewSelector->setAttributes(II->getAttributes());
338
NewSelector->setCallingConv(II->getCallingConv());
340
II->replaceAllUsesWith(NewSelector);
341
II->eraseFromParent();
345
Changed |= CleanupSelectors(CatchAllSels);
349
/// NormalizeLandingPads - Normalize and discover landing pads, noting them
350
/// in the LandingPads set. A landing pad is normal if the only CFG edges
351
/// that end at it are unwind edges from invoke instructions. If we inlined
352
/// through an invoke we could have a normal branch from the previous
353
/// unwind block through to the landing pad for the original invoke.
354
/// Abnormal landing pads are fixed up by redirecting all unwind edges to
355
/// a new basic block which falls through to the original.
356
bool DwarfEHPrepare::NormalizeLandingPads() {
357
bool Changed = false;
359
const MCAsmInfo *MAI = TM->getMCAsmInfo();
360
bool usingSjLjEH = MAI->getExceptionHandlingType() == ExceptionHandling::SjLj;
362
for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
363
TerminatorInst *TI = I->getTerminator();
364
if (!isa<InvokeInst>(TI))
366
BasicBlock *LPad = TI->getSuccessor(1);
367
// Skip landing pads that have already been normalized.
368
if (LandingPads.count(LPad))
371
// Check that only invoke unwind edges end at the landing pad.
372
bool OnlyUnwoundTo = true;
373
bool SwitchOK = usingSjLjEH;
374
for (pred_iterator PI = pred_begin(LPad), PE = pred_end(LPad);
376
TerminatorInst *PT = (*PI)->getTerminator();
377
// The SjLj dispatch block uses a switch instruction. This is effectively
378
// an unwind edge, so we can disregard it here. There will only ever
379
// be one dispatch, however, so if there are multiple switches, one
380
// of them truly is a normal edge, not an unwind edge.
381
if (SwitchOK && isa<SwitchInst>(PT)) {
385
if (!isa<InvokeInst>(PT) || LPad == PT->getSuccessor(0)) {
386
OnlyUnwoundTo = false;
392
// Only unwind edges lead to the landing pad. Remember the landing pad.
393
LandingPads.insert(LPad);
397
// At least one normal edge ends at the landing pad. Redirect the unwind
398
// edges to a new basic block which falls through into this one.
400
// Create the new basic block.
401
BasicBlock *NewBB = BasicBlock::Create(F->getContext(),
402
LPad->getName() + "_unwind_edge");
404
// Insert it into the function right before the original landing pad.
405
LPad->getParent()->getBasicBlockList().insert(LPad, NewBB);
407
// Redirect unwind edges from the original landing pad to NewBB.
408
for (pred_iterator PI = pred_begin(LPad), PE = pred_end(LPad); PI != PE; ) {
409
TerminatorInst *PT = (*PI++)->getTerminator();
410
if (isa<InvokeInst>(PT) && PT->getSuccessor(1) == LPad)
411
// Unwind to the new block.
412
PT->setSuccessor(1, NewBB);
415
// If there are any PHI nodes in LPad, we need to update them so that they
416
// merge incoming values from NewBB instead.
417
for (BasicBlock::iterator II = LPad->begin(); isa<PHINode>(II); ++II) {
418
PHINode *PN = cast<PHINode>(II);
419
pred_iterator PB = pred_begin(NewBB), PE = pred_end(NewBB);
421
// Check to see if all of the values coming in via unwind edges are the
422
// same. If so, we don't need to create a new PHI node.
423
Value *InVal = PN->getIncomingValueForBlock(*PB);
424
for (pred_iterator PI = PB; PI != PE; ++PI) {
425
if (PI != PB && InVal != PN->getIncomingValueForBlock(*PI)) {
432
// Different unwind edges have different values. Create a new PHI node
434
PHINode *NewPN = PHINode::Create(PN->getType(), PN->getName()+".unwind",
436
// Add an entry for each unwind edge, using the value from the old PHI.
437
for (pred_iterator PI = PB; PI != PE; ++PI)
438
NewPN->addIncoming(PN->getIncomingValueForBlock(*PI), *PI);
440
// Now use this new PHI as the common incoming value for NewBB in PN.
444
// Revector exactly one entry in the PHI node to come from NewBB
445
// and delete all other entries that come from unwind edges. If
446
// there are both normal and unwind edges from the same predecessor,
447
// this leaves an entry for the normal edge.
448
for (pred_iterator PI = PB; PI != PE; ++PI)
449
PN->removeIncomingValue(*PI);
450
PN->addIncoming(InVal, NewBB);
453
// Add a fallthrough from NewBB to the original landing pad.
454
BranchInst::Create(LPad, NewBB);
456
// Now update DominatorTree analysis information.
457
DT->splitBlock(NewBB);
459
// Remember the newly constructed landing pad. The original landing pad
460
// LPad is no longer a landing pad now that all unwind edges have been
461
// revectored to NewBB.
462
LandingPads.insert(NewBB);
463
++NumLandingPadsSplit;
470
/// LowerUnwinds - Turn unwind instructions into calls to _Unwind_Resume,
471
/// rethrowing any previously caught exception. This will crash horribly
472
/// at runtime if there is no such exception: using unwind to throw a new
473
/// exception is currently not supported.
474
bool DwarfEHPrepare::LowerUnwinds() {
475
SmallVector<TerminatorInst*, 16> UnwindInsts;
477
for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
478
TerminatorInst *TI = I->getTerminator();
479
if (isa<UnwindInst>(TI))
480
UnwindInsts.push_back(TI);
483
if (UnwindInsts.empty()) return false;
485
// Find the rewind function if we didn't already.
486
if (!RewindFunction) {
487
LLVMContext &Ctx = UnwindInsts[0]->getContext();
488
std::vector<const Type*>
489
Params(1, Type::getInt8PtrTy(Ctx));
490
FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx),
492
const char *RewindName = TLI->getLibcallName(RTLIB::UNWIND_RESUME);
493
RewindFunction = F->getParent()->getOrInsertFunction(RewindName, FTy);
496
bool Changed = false;
498
for (SmallVectorImpl<TerminatorInst*>::iterator
499
I = UnwindInsts.begin(), E = UnwindInsts.end(); I != E; ++I) {
500
TerminatorInst *TI = *I;
502
// Replace the unwind instruction with a call to _Unwind_Resume (or the
503
// appropriate target equivalent) followed by an UnreachableInst.
505
// Create the call...
506
CallInst *CI = CallInst::Create(RewindFunction,
507
CreateExceptionValueCall(TI->getParent()),
509
CI->setCallingConv(TLI->getLibcallCallingConv(RTLIB::UNWIND_RESUME));
510
// ...followed by an UnreachableInst.
511
new UnreachableInst(TI->getContext(), TI);
513
// Nuke the unwind instruction.
514
TI->eraseFromParent();
522
/// MoveExceptionValueCalls - Ensure that eh.exception is only ever called from
523
/// landing pads by replacing calls outside of landing pads with direct use of
524
/// a register holding the appropriate value; this requires adding calls inside
525
/// all landing pads to initialize the register. Also, move eh.exception calls
526
/// inside landing pads to the start of the landing pad (optional, but may make
527
/// things simpler for later passes).
528
bool DwarfEHPrepare::MoveExceptionValueCalls() {
529
// If the eh.exception intrinsic is not declared in the module then there is
530
// nothing to do. Speed up compilation by checking for this common case.
531
if (!ExceptionValueIntrinsic &&
532
!F->getParent()->getFunction(Intrinsic::getName(Intrinsic::eh_exception)))
535
bool Changed = false;
537
// Move calls to eh.exception that are inside a landing pad to the start of
539
for (BBSet::const_iterator LI = LandingPads.begin(), LE = LandingPads.end();
541
BasicBlock *LP = *LI;
542
for (BasicBlock::iterator II = LP->getFirstNonPHIOrDbg(), IE = LP->end();
544
if (EHExceptionInst *EI = dyn_cast<EHExceptionInst>(II++)) {
545
// Found a call to eh.exception.
546
if (!EI->use_empty()) {
547
// If there is already a call to eh.exception at the start of the
548
// landing pad, then get hold of it; otherwise create such a call.
549
Value *CallAtStart = CreateExceptionValueCall(LP);
551
// If the call was at the start of a landing pad then leave it alone.
552
if (EI == CallAtStart)
554
EI->replaceAllUsesWith(CallAtStart);
556
EI->eraseFromParent();
557
++NumExceptionValuesMoved;
562
// Look for calls to eh.exception that are not in a landing pad. If one is
563
// found, then a register that holds the exception value will be created in
564
// each landing pad, and the SSAUpdater will be used to compute the values
565
// returned by eh.exception calls outside of landing pads.
568
// Remember where we found the eh.exception call, to avoid rescanning earlier
569
// basic blocks which we already know contain no eh.exception calls.
570
bool FoundCallOutsideLandingPad = false;
571
Function::iterator BB = F->begin();
572
for (Function::iterator BE = F->end(); BB != BE; ++BB) {
573
// Skip over landing pads.
574
if (LandingPads.count(BB))
577
for (BasicBlock::iterator II = BB->getFirstNonPHIOrDbg(), IE = BB->end();
579
if (isa<EHExceptionInst>(II)) {
580
SSA.Initialize(II->getType(), II->getName());
581
FoundCallOutsideLandingPad = true;
585
if (FoundCallOutsideLandingPad)
589
// If all calls to eh.exception are in landing pads then we are done.
590
if (!FoundCallOutsideLandingPad)
593
// Add a call to eh.exception at the start of each landing pad, and tell the
594
// SSAUpdater that this is the value produced by the landing pad.
595
for (BBSet::iterator LI = LandingPads.begin(), LE = LandingPads.end();
597
SSA.AddAvailableValue(*LI, CreateExceptionValueCall(*LI));
599
// Now turn all calls to eh.exception that are not in a landing pad into a use
600
// of the appropriate register.
601
for (Function::iterator BE = F->end(); BB != BE; ++BB) {
602
// Skip over landing pads.
603
if (LandingPads.count(BB))
606
for (BasicBlock::iterator II = BB->getFirstNonPHIOrDbg(), IE = BB->end();
608
if (EHExceptionInst *EI = dyn_cast<EHExceptionInst>(II++)) {
609
// Found a call to eh.exception, replace it with the value from any
610
// upstream landing pad(s).
611
EI->replaceAllUsesWith(SSA.GetValueAtEndOfBlock(BB));
612
EI->eraseFromParent();
613
++NumExceptionValuesMoved;
620
/// CreateExceptionValueCall - Insert a call to the eh.exception intrinsic at
621
/// the start of the basic block (unless there already is one, in which case
622
/// the existing call is returned).
623
Instruction *DwarfEHPrepare::CreateExceptionValueCall(BasicBlock *BB) {
624
Instruction *Start = BB->getFirstNonPHIOrDbg();
625
// Is this a call to eh.exception?
626
if (IntrinsicInst *CI = dyn_cast<IntrinsicInst>(Start))
627
if (CI->getIntrinsicID() == Intrinsic::eh_exception)
628
// Reuse the existing call.
631
// Find the eh.exception intrinsic if we didn't already.
632
if (!ExceptionValueIntrinsic)
633
ExceptionValueIntrinsic = Intrinsic::getDeclaration(F->getParent(),
634
Intrinsic::eh_exception);
637
return CallInst::Create(ExceptionValueIntrinsic, "eh.value.call", Start);
640
bool DwarfEHPrepare::runOnFunction(Function &Fn) {
641
bool Changed = false;
643
// Initialize internal state.
644
DT = &getAnalysis<DominatorTree>();
647
// Ensure that only unwind edges end at landing pads (a landing pad is a
648
// basic block where an invoke unwind edge ends).
649
Changed |= NormalizeLandingPads();
651
// Turn unwind instructions into libcalls.
652
Changed |= LowerUnwinds();
654
// TODO: Move eh.selector calls to landing pads and combine them.
656
// Move eh.exception calls to landing pads.
657
Changed |= MoveExceptionValueCalls();
659
Changed |= HandleURoRInvokes();