| Duncan Sands | d6fb650 | 2009-05-22 20:36:31 +0000 | [diff] [blame] | 1 | //===-- DwarfEHPrepare - Prepare exception handling for code generation ---===// | 
|  | 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 | //===----------------------------------------------------------------------===// | 
|  | 9 | // | 
|  | 10 | // This pass mulches exception handling code into a form adapted to code | 
| Bill Wendling | d1aa77c | 2010-03-26 23:41:30 +0000 | [diff] [blame] | 11 | // generation. Required if using dwarf exception handling. | 
| Duncan Sands | d6fb650 | 2009-05-22 20:36:31 +0000 | [diff] [blame] | 12 | // | 
|  | 13 | //===----------------------------------------------------------------------===// | 
|  | 14 |  | 
| Reid Kleckner | be0a050 | 2015-03-09 22:45:16 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/BitVector.h" | 
| Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/Statistic.h" | 
| Reid Kleckner | be0a050 | 2015-03-09 22:45:16 +0000 | [diff] [blame] | 17 | #include "llvm/Analysis/CFG.h" | 
| David Majnemer | 70497c6 | 2015-12-02 23:06:39 +0000 | [diff] [blame] | 18 | #include "llvm/Analysis/EHPersonalities.h" | 
| Reid Kleckner | be0a050 | 2015-03-09 22:45:16 +0000 | [diff] [blame] | 19 | #include "llvm/Analysis/TargetTransformInfo.h" | 
| Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/Passes.h" | 
|  | 21 | #include "llvm/CodeGen/TargetPassConfig.h" | 
| Reid Kleckner | be0a050 | 2015-03-09 22:45:16 +0000 | [diff] [blame] | 22 | #include "llvm/IR/Dominators.h" | 
| Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 23 | #include "llvm/IR/Function.h" | 
|  | 24 | #include "llvm/IR/Instructions.h" | 
| Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 25 | #include "llvm/IR/Module.h" | 
| Duncan Sands | d6fb650 | 2009-05-22 20:36:31 +0000 | [diff] [blame] | 26 | #include "llvm/Pass.h" | 
| Duncan Sands | d6fb650 | 2009-05-22 20:36:31 +0000 | [diff] [blame] | 27 | #include "llvm/Target/TargetLowering.h" | 
| Eric Christopher | d913448 | 2014-08-04 21:25:23 +0000 | [diff] [blame] | 28 | #include "llvm/Target/TargetSubtargetInfo.h" | 
| Reid Kleckner | be0a050 | 2015-03-09 22:45:16 +0000 | [diff] [blame] | 29 | #include "llvm/Transforms/Utils/Local.h" | 
| Duncan Sands | d6fb650 | 2009-05-22 20:36:31 +0000 | [diff] [blame] | 30 | using namespace llvm; | 
|  | 31 |  | 
| Chandler Carruth | 1b9dde0 | 2014-04-22 02:02:50 +0000 | [diff] [blame] | 32 | #define DEBUG_TYPE "dwarfehprepare" | 
|  | 33 |  | 
| Bill Wendling | 478f58c | 2011-11-07 23:36:48 +0000 | [diff] [blame] | 34 | STATISTIC(NumResumesLowered, "Number of resume calls lowered"); | 
| Duncan Sands | d6fb650 | 2009-05-22 20:36:31 +0000 | [diff] [blame] | 35 |  | 
|  | 36 | namespace { | 
| Nick Lewycky | 02d5f77 | 2009-10-25 06:33:48 +0000 | [diff] [blame] | 37 | class DwarfEHPrepare : public FunctionPass { | 
| Bill Wendling | 478f58c | 2011-11-07 23:36:48 +0000 | [diff] [blame] | 38 | // RewindFunction - _Unwind_Resume or the target equivalent. | 
| Duncan Sands | d6fb650 | 2009-05-22 20:36:31 +0000 | [diff] [blame] | 39 | Constant *RewindFunction; | 
|  | 40 |  | 
| Reid Kleckner | be0a050 | 2015-03-09 22:45:16 +0000 | [diff] [blame] | 41 | DominatorTree *DT; | 
|  | 42 | const TargetLowering *TLI; | 
|  | 43 |  | 
| Bill Wendling | 478f58c | 2011-11-07 23:36:48 +0000 | [diff] [blame] | 44 | bool InsertUnwindResumeCalls(Function &Fn); | 
| Bill Wendling | 27489fe | 2012-05-17 17:59:51 +0000 | [diff] [blame] | 45 | Value *GetExceptionObject(ResumeInst *RI); | 
| Reid Kleckner | be0a050 | 2015-03-09 22:45:16 +0000 | [diff] [blame] | 46 | size_t | 
|  | 47 | pruneUnreachableResumes(Function &Fn, | 
|  | 48 | SmallVectorImpl<ResumeInst *> &Resumes, | 
|  | 49 | SmallVectorImpl<LandingPadInst *> &CleanupLPads); | 
| Duncan Sands | d6fb650 | 2009-05-22 20:36:31 +0000 | [diff] [blame] | 50 |  | 
| Duncan Sands | d6fb650 | 2009-05-22 20:36:31 +0000 | [diff] [blame] | 51 | public: | 
|  | 52 | static char ID; // Pass identification, replacement for typeid. | 
| Reid Kleckner | 7bb0738 | 2015-02-18 23:17:41 +0000 | [diff] [blame] | 53 |  | 
| Reid Kleckner | be0a050 | 2015-03-09 22:45:16 +0000 | [diff] [blame] | 54 | DwarfEHPrepare() | 
| Francis Visoiu Mistrih | 8b61764 | 2017-05-18 17:21:13 +0000 | [diff] [blame] | 55 | : FunctionPass(ID), RewindFunction(nullptr), DT(nullptr), TLI(nullptr) { | 
|  | 56 | } | 
| Duncan Sands | d6fb650 | 2009-05-22 20:36:31 +0000 | [diff] [blame] | 57 |  | 
| Craig Topper | 4584cd5 | 2014-03-07 09:26:03 +0000 | [diff] [blame] | 58 | bool runOnFunction(Function &Fn) override; | 
| Duncan Sands | d6fb650 | 2009-05-22 20:36:31 +0000 | [diff] [blame] | 59 |  | 
| Yaron Keren | 66b0ceb | 2014-09-14 20:36:28 +0000 | [diff] [blame] | 60 | bool doFinalization(Module &M) override { | 
|  | 61 | RewindFunction = nullptr; | 
|  | 62 | return false; | 
|  | 63 | } | 
|  | 64 |  | 
| Reid Kleckner | be0a050 | 2015-03-09 22:45:16 +0000 | [diff] [blame] | 65 | void getAnalysisUsage(AnalysisUsage &AU) const override; | 
|  | 66 |  | 
| Mehdi Amini | 117296c | 2016-10-01 02:56:57 +0000 | [diff] [blame] | 67 | StringRef getPassName() const override { | 
| Duncan Sands | d6fb650 | 2009-05-22 20:36:31 +0000 | [diff] [blame] | 68 | return "Exception handling preparation"; | 
|  | 69 | } | 
| Duncan Sands | d6fb650 | 2009-05-22 20:36:31 +0000 | [diff] [blame] | 70 | }; | 
|  | 71 | } // end anonymous namespace | 
|  | 72 |  | 
|  | 73 | char DwarfEHPrepare::ID = 0; | 
| Matthias Braun | 1527baa | 2017-05-25 21:26:32 +0000 | [diff] [blame] | 74 | INITIALIZE_PASS_BEGIN(DwarfEHPrepare, DEBUG_TYPE, | 
| Francis Visoiu Mistrih | 8b61764 | 2017-05-18 17:21:13 +0000 | [diff] [blame] | 75 | "Prepare DWARF exceptions", false, false) | 
| Reid Kleckner | be0a050 | 2015-03-09 22:45:16 +0000 | [diff] [blame] | 76 | INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) | 
| Francis Visoiu Mistrih | 8b61764 | 2017-05-18 17:21:13 +0000 | [diff] [blame] | 77 | INITIALIZE_PASS_DEPENDENCY(TargetPassConfig) | 
| Reid Kleckner | be0a050 | 2015-03-09 22:45:16 +0000 | [diff] [blame] | 78 | INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass) | 
| Matthias Braun | 1527baa | 2017-05-25 21:26:32 +0000 | [diff] [blame] | 79 | INITIALIZE_PASS_END(DwarfEHPrepare, DEBUG_TYPE, | 
| Francis Visoiu Mistrih | 8b61764 | 2017-05-18 17:21:13 +0000 | [diff] [blame] | 80 | "Prepare DWARF exceptions", false, false) | 
| Duncan Sands | d6fb650 | 2009-05-22 20:36:31 +0000 | [diff] [blame] | 81 |  | 
| Francis Visoiu Mistrih | 8b61764 | 2017-05-18 17:21:13 +0000 | [diff] [blame] | 82 | FunctionPass *llvm::createDwarfEHPass() { return new DwarfEHPrepare(); } | 
| Duncan Sands | d6fb650 | 2009-05-22 20:36:31 +0000 | [diff] [blame] | 83 |  | 
| Reid Kleckner | be0a050 | 2015-03-09 22:45:16 +0000 | [diff] [blame] | 84 | void DwarfEHPrepare::getAnalysisUsage(AnalysisUsage &AU) const { | 
| Francis Visoiu Mistrih | 8b61764 | 2017-05-18 17:21:13 +0000 | [diff] [blame] | 85 | AU.addRequired<TargetPassConfig>(); | 
| Reid Kleckner | be0a050 | 2015-03-09 22:45:16 +0000 | [diff] [blame] | 86 | AU.addRequired<TargetTransformInfoWrapperPass>(); | 
|  | 87 | AU.addRequired<DominatorTreeWrapperPass>(); | 
|  | 88 | } | 
|  | 89 |  | 
| Bill Wendling | 8c09040 | 2012-01-28 01:17:56 +0000 | [diff] [blame] | 90 | /// GetExceptionObject - Return the exception object from the value passed into | 
|  | 91 | /// the 'resume' instruction (typically an aggregate). Clean up any dead | 
|  | 92 | /// instructions, including the 'resume' instruction. | 
| Bill Wendling | 27489fe | 2012-05-17 17:59:51 +0000 | [diff] [blame] | 93 | Value *DwarfEHPrepare::GetExceptionObject(ResumeInst *RI) { | 
| Bill Wendling | 8c09040 | 2012-01-28 01:17:56 +0000 | [diff] [blame] | 94 | Value *V = RI->getOperand(0); | 
| Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 95 | Value *ExnObj = nullptr; | 
| Bill Wendling | 8c09040 | 2012-01-28 01:17:56 +0000 | [diff] [blame] | 96 | InsertValueInst *SelIVI = dyn_cast<InsertValueInst>(V); | 
| Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 97 | LoadInst *SelLoad = nullptr; | 
|  | 98 | InsertValueInst *ExcIVI = nullptr; | 
| Bill Wendling | 8c09040 | 2012-01-28 01:17:56 +0000 | [diff] [blame] | 99 | bool EraseIVIs = false; | 
|  | 100 |  | 
|  | 101 | if (SelIVI) { | 
|  | 102 | if (SelIVI->getNumIndices() == 1 && *SelIVI->idx_begin() == 1) { | 
|  | 103 | ExcIVI = dyn_cast<InsertValueInst>(SelIVI->getOperand(0)); | 
|  | 104 | if (ExcIVI && isa<UndefValue>(ExcIVI->getOperand(0)) && | 
|  | 105 | ExcIVI->getNumIndices() == 1 && *ExcIVI->idx_begin() == 0) { | 
| Bill Wendling | 27489fe | 2012-05-17 17:59:51 +0000 | [diff] [blame] | 106 | ExnObj = ExcIVI->getOperand(1); | 
| Bill Wendling | 8c09040 | 2012-01-28 01:17:56 +0000 | [diff] [blame] | 107 | SelLoad = dyn_cast<LoadInst>(SelIVI->getOperand(1)); | 
|  | 108 | EraseIVIs = true; | 
|  | 109 | } | 
|  | 110 | } | 
|  | 111 | } | 
|  | 112 |  | 
|  | 113 | if (!ExnObj) | 
|  | 114 | ExnObj = ExtractValueInst::Create(RI->getOperand(0), 0, "exn.obj", RI); | 
|  | 115 |  | 
|  | 116 | RI->eraseFromParent(); | 
|  | 117 |  | 
|  | 118 | if (EraseIVIs) { | 
| Benjamin Kramer | eb63e4d | 2015-01-29 13:26:50 +0000 | [diff] [blame] | 119 | if (SelIVI->use_empty()) | 
| Bill Wendling | 8c09040 | 2012-01-28 01:17:56 +0000 | [diff] [blame] | 120 | SelIVI->eraseFromParent(); | 
| Benjamin Kramer | eb63e4d | 2015-01-29 13:26:50 +0000 | [diff] [blame] | 121 | if (ExcIVI->use_empty()) | 
| Bill Wendling | 8c09040 | 2012-01-28 01:17:56 +0000 | [diff] [blame] | 122 | ExcIVI->eraseFromParent(); | 
| Benjamin Kramer | eb63e4d | 2015-01-29 13:26:50 +0000 | [diff] [blame] | 123 | if (SelLoad && SelLoad->use_empty()) | 
| Bill Wendling | 8c09040 | 2012-01-28 01:17:56 +0000 | [diff] [blame] | 124 | SelLoad->eraseFromParent(); | 
|  | 125 | } | 
|  | 126 |  | 
|  | 127 | return ExnObj; | 
|  | 128 | } | 
|  | 129 |  | 
| Reid Kleckner | be0a050 | 2015-03-09 22:45:16 +0000 | [diff] [blame] | 130 | /// Replace resumes that are not reachable from a cleanup landing pad with | 
|  | 131 | /// unreachable and then simplify those blocks. | 
|  | 132 | size_t DwarfEHPrepare::pruneUnreachableResumes( | 
|  | 133 | Function &Fn, SmallVectorImpl<ResumeInst *> &Resumes, | 
|  | 134 | SmallVectorImpl<LandingPadInst *> &CleanupLPads) { | 
|  | 135 | BitVector ResumeReachable(Resumes.size()); | 
|  | 136 | size_t ResumeIndex = 0; | 
|  | 137 | for (auto *RI : Resumes) { | 
|  | 138 | for (auto *LP : CleanupLPads) { | 
|  | 139 | if (isPotentiallyReachable(LP, RI, DT)) { | 
|  | 140 | ResumeReachable.set(ResumeIndex); | 
|  | 141 | break; | 
|  | 142 | } | 
|  | 143 | } | 
|  | 144 | ++ResumeIndex; | 
|  | 145 | } | 
|  | 146 |  | 
|  | 147 | // If everything is reachable, there is no change. | 
|  | 148 | if (ResumeReachable.all()) | 
|  | 149 | return Resumes.size(); | 
|  | 150 |  | 
|  | 151 | const TargetTransformInfo &TTI = | 
|  | 152 | getAnalysis<TargetTransformInfoWrapperPass>().getTTI(Fn); | 
|  | 153 | LLVMContext &Ctx = Fn.getContext(); | 
|  | 154 |  | 
|  | 155 | // Otherwise, insert unreachable instructions and call simplifycfg. | 
|  | 156 | size_t ResumesLeft = 0; | 
|  | 157 | for (size_t I = 0, E = Resumes.size(); I < E; ++I) { | 
|  | 158 | ResumeInst *RI = Resumes[I]; | 
|  | 159 | if (ResumeReachable[I]) { | 
|  | 160 | Resumes[ResumesLeft++] = RI; | 
|  | 161 | } else { | 
|  | 162 | BasicBlock *BB = RI->getParent(); | 
|  | 163 | new UnreachableInst(Ctx, RI); | 
|  | 164 | RI->eraseFromParent(); | 
| Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 165 | SimplifyCFG(BB, TTI, 1); | 
| Reid Kleckner | be0a050 | 2015-03-09 22:45:16 +0000 | [diff] [blame] | 166 | } | 
|  | 167 | } | 
|  | 168 | Resumes.resize(ResumesLeft); | 
|  | 169 | return ResumesLeft; | 
|  | 170 | } | 
|  | 171 |  | 
| Bill Wendling | 1cdd7fd | 2011-08-17 19:48:49 +0000 | [diff] [blame] | 172 | /// InsertUnwindResumeCalls - Convert the ResumeInsts that are still present | 
|  | 173 | /// into calls to the appropriate _Unwind_Resume function. | 
| Bill Wendling | 478f58c | 2011-11-07 23:36:48 +0000 | [diff] [blame] | 174 | bool DwarfEHPrepare::InsertUnwindResumeCalls(Function &Fn) { | 
| Bill Wendling | 1cdd7fd | 2011-08-17 19:48:49 +0000 | [diff] [blame] | 175 | SmallVector<ResumeInst*, 16> Resumes; | 
| Reid Kleckner | be0a050 | 2015-03-09 22:45:16 +0000 | [diff] [blame] | 176 | SmallVector<LandingPadInst*, 16> CleanupLPads; | 
| Benjamin Kramer | eb63e4d | 2015-01-29 13:26:50 +0000 | [diff] [blame] | 177 | for (BasicBlock &BB : Fn) { | 
|  | 178 | if (auto *RI = dyn_cast<ResumeInst>(BB.getTerminator())) | 
| Bill Wendling | 8ac2041 | 2011-08-25 23:48:11 +0000 | [diff] [blame] | 179 | Resumes.push_back(RI); | 
| David Majnemer | 7fddecc | 2015-06-17 20:52:32 +0000 | [diff] [blame] | 180 | if (auto *LP = BB.getLandingPadInst()) | 
| Reid Kleckner | be0a050 | 2015-03-09 22:45:16 +0000 | [diff] [blame] | 181 | if (LP->isCleanup()) | 
|  | 182 | CleanupLPads.push_back(LP); | 
| Bill Wendling | 8ac2041 | 2011-08-25 23:48:11 +0000 | [diff] [blame] | 183 | } | 
| Bill Wendling | 1cdd7fd | 2011-08-17 19:48:49 +0000 | [diff] [blame] | 184 |  | 
|  | 185 | if (Resumes.empty()) | 
| Kai Nacke | e1823b6 | 2013-05-31 16:30:36 +0000 | [diff] [blame] | 186 | return false; | 
| Bill Wendling | 1cdd7fd | 2011-08-17 19:48:49 +0000 | [diff] [blame] | 187 |  | 
| Joseph Tremoulet | 2afea54 | 2015-10-06 20:28:16 +0000 | [diff] [blame] | 188 | // Check the personality, don't do anything if it's funclet-based. | 
| David Majnemer | 7fddecc | 2015-06-17 20:52:32 +0000 | [diff] [blame] | 189 | EHPersonality Pers = classifyEHPersonality(Fn.getPersonalityFn()); | 
| Joseph Tremoulet | 2afea54 | 2015-10-06 20:28:16 +0000 | [diff] [blame] | 190 | if (isFuncletEHPersonality(Pers)) | 
| David Majnemer | 7fddecc | 2015-06-17 20:52:32 +0000 | [diff] [blame] | 191 | return false; | 
|  | 192 |  | 
| Chandler Carruth | 301ed0c | 2015-02-20 02:15:36 +0000 | [diff] [blame] | 193 | LLVMContext &Ctx = Fn.getContext(); | 
| Reid Kleckner | be0a050 | 2015-03-09 22:45:16 +0000 | [diff] [blame] | 194 |  | 
|  | 195 | size_t ResumesLeft = pruneUnreachableResumes(Fn, Resumes, CleanupLPads); | 
|  | 196 | if (ResumesLeft == 0) | 
|  | 197 | return true; // We pruned them all. | 
|  | 198 |  | 
|  | 199 | // Find the rewind function if we didn't already. | 
| Bill Wendling | 1cdd7fd | 2011-08-17 19:48:49 +0000 | [diff] [blame] | 200 | if (!RewindFunction) { | 
| Bill Wendling | 1cdd7fd | 2011-08-17 19:48:49 +0000 | [diff] [blame] | 201 | FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx), | 
|  | 202 | Type::getInt8PtrTy(Ctx), false); | 
|  | 203 | const char *RewindName = TLI->getLibcallName(RTLIB::UNWIND_RESUME); | 
| Bill Wendling | 478f58c | 2011-11-07 23:36:48 +0000 | [diff] [blame] | 204 | RewindFunction = Fn.getParent()->getOrInsertFunction(RewindName, FTy); | 
| Bill Wendling | 1cdd7fd | 2011-08-17 19:48:49 +0000 | [diff] [blame] | 205 | } | 
|  | 206 |  | 
|  | 207 | // Create the basic block where the _Unwind_Resume call will live. | 
| Reid Kleckner | be0a050 | 2015-03-09 22:45:16 +0000 | [diff] [blame] | 208 | if (ResumesLeft == 1) { | 
| Bill Wendling | 8c09040 | 2012-01-28 01:17:56 +0000 | [diff] [blame] | 209 | // Instead of creating a new BB and PHI node, just append the call to | 
|  | 210 | // _Unwind_Resume to the end of the single resume block. | 
|  | 211 | ResumeInst *RI = Resumes.front(); | 
|  | 212 | BasicBlock *UnwindBB = RI->getParent(); | 
| Bill Wendling | 27489fe | 2012-05-17 17:59:51 +0000 | [diff] [blame] | 213 | Value *ExnObj = GetExceptionObject(RI); | 
| Bill Wendling | 8c09040 | 2012-01-28 01:17:56 +0000 | [diff] [blame] | 214 |  | 
|  | 215 | // Call the _Unwind_Resume function. | 
|  | 216 | CallInst *CI = CallInst::Create(RewindFunction, ExnObj, "", UnwindBB); | 
|  | 217 | CI->setCallingConv(TLI->getLibcallCallingConv(RTLIB::UNWIND_RESUME)); | 
|  | 218 |  | 
|  | 219 | // We never expect _Unwind_Resume to return. | 
|  | 220 | new UnreachableInst(Ctx, UnwindBB); | 
|  | 221 | return true; | 
|  | 222 | } | 
|  | 223 |  | 
| Bill Wendling | 478f58c | 2011-11-07 23:36:48 +0000 | [diff] [blame] | 224 | BasicBlock *UnwindBB = BasicBlock::Create(Ctx, "unwind_resume", &Fn); | 
| Reid Kleckner | be0a050 | 2015-03-09 22:45:16 +0000 | [diff] [blame] | 225 | PHINode *PN = PHINode::Create(Type::getInt8PtrTy(Ctx), ResumesLeft, | 
| Bill Wendling | 1cdd7fd | 2011-08-17 19:48:49 +0000 | [diff] [blame] | 226 | "exn.obj", UnwindBB); | 
|  | 227 |  | 
|  | 228 | // Extract the exception object from the ResumeInst and add it to the PHI node | 
|  | 229 | // that feeds the _Unwind_Resume call. | 
| Benjamin Kramer | eb63e4d | 2015-01-29 13:26:50 +0000 | [diff] [blame] | 230 | for (ResumeInst *RI : Resumes) { | 
| Bill Wendling | 8c09040 | 2012-01-28 01:17:56 +0000 | [diff] [blame] | 231 | BasicBlock *Parent = RI->getParent(); | 
|  | 232 | BranchInst::Create(UnwindBB, Parent); | 
| Bill Wendling | 9249261 | 2012-01-20 00:53:28 +0000 | [diff] [blame] | 233 |  | 
| Bill Wendling | 27489fe | 2012-05-17 17:59:51 +0000 | [diff] [blame] | 234 | Value *ExnObj = GetExceptionObject(RI); | 
| Bill Wendling | 8c09040 | 2012-01-28 01:17:56 +0000 | [diff] [blame] | 235 | PN->addIncoming(ExnObj, Parent); | 
| Bill Wendling | 9249261 | 2012-01-20 00:53:28 +0000 | [diff] [blame] | 236 |  | 
| Bill Wendling | 478f58c | 2011-11-07 23:36:48 +0000 | [diff] [blame] | 237 | ++NumResumesLowered; | 
| Bill Wendling | 1cdd7fd | 2011-08-17 19:48:49 +0000 | [diff] [blame] | 238 | } | 
|  | 239 |  | 
|  | 240 | // Call the function. | 
|  | 241 | CallInst *CI = CallInst::Create(RewindFunction, PN, "", UnwindBB); | 
|  | 242 | CI->setCallingConv(TLI->getLibcallCallingConv(RTLIB::UNWIND_RESUME)); | 
|  | 243 |  | 
|  | 244 | // We never expect _Unwind_Resume to return. | 
|  | 245 | new UnreachableInst(Ctx, UnwindBB); | 
|  | 246 | return true; | 
|  | 247 | } | 
|  | 248 |  | 
| Duncan Sands | d6fb650 | 2009-05-22 20:36:31 +0000 | [diff] [blame] | 249 | bool DwarfEHPrepare::runOnFunction(Function &Fn) { | 
| Francis Visoiu Mistrih | 8b61764 | 2017-05-18 17:21:13 +0000 | [diff] [blame] | 250 | const TargetMachine &TM = | 
|  | 251 | getAnalysis<TargetPassConfig>().getTM<TargetMachine>(); | 
| Reid Kleckner | be0a050 | 2015-03-09 22:45:16 +0000 | [diff] [blame] | 252 | DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree(); | 
| Francis Visoiu Mistrih | 8b61764 | 2017-05-18 17:21:13 +0000 | [diff] [blame] | 253 | TLI = TM.getSubtargetImpl(Fn)->getTargetLowering(); | 
| Bill Wendling | 478f58c | 2011-11-07 23:36:48 +0000 | [diff] [blame] | 254 | bool Changed = InsertUnwindResumeCalls(Fn); | 
| Reid Kleckner | be0a050 | 2015-03-09 22:45:16 +0000 | [diff] [blame] | 255 | DT = nullptr; | 
|  | 256 | TLI = nullptr; | 
| Duncan Sands | d6fb650 | 2009-05-22 20:36:31 +0000 | [diff] [blame] | 257 | return Changed; | 
|  | 258 | } |