Bill Wendling | 12e5adb | 2012-03-13 20:04:21 +0000 | [diff] [blame] | 1 | //===- SjLjEHPrepare.cpp - Eliminate Invoke & Unwind instructions ---------===// |
Jim Grosbach | 486be66 | 2009-08-17 16:41:22 +0000 | [diff] [blame] | 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 transformation is designed for use by code generators which use SjLj |
| 11 | // based exception handling. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 15 | #include "llvm/CodeGen/Passes.h" |
| 16 | #include "llvm/ADT/DenseMap.h" |
| 17 | #include "llvm/ADT/SetVector.h" |
| 18 | #include "llvm/ADT/SmallPtrSet.h" |
| 19 | #include "llvm/ADT/SmallVector.h" |
| 20 | #include "llvm/ADT/Statistic.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 21 | #include "llvm/IR/Constants.h" |
| 22 | #include "llvm/IR/DataLayout.h" |
| 23 | #include "llvm/IR/DerivedTypes.h" |
| 24 | #include "llvm/IR/IRBuilder.h" |
| 25 | #include "llvm/IR/Instructions.h" |
| 26 | #include "llvm/IR/Intrinsics.h" |
| 27 | #include "llvm/IR/LLVMContext.h" |
| 28 | #include "llvm/IR/Module.h" |
Jim Grosbach | 486be66 | 2009-08-17 16:41:22 +0000 | [diff] [blame] | 29 | #include "llvm/Pass.h" |
Chandler Carruth | aafe091 | 2012-06-29 12:38:19 +0000 | [diff] [blame] | 30 | #include "llvm/Support/CommandLine.h" |
| 31 | #include "llvm/Support/Debug.h" |
| 32 | #include "llvm/Support/raw_ostream.h" |
Chandler Carruth | aafe091 | 2012-06-29 12:38:19 +0000 | [diff] [blame] | 33 | #include "llvm/Target/TargetLowering.h" |
Eric Christopher | d913448 | 2014-08-04 21:25:23 +0000 | [diff] [blame] | 34 | #include "llvm/Target/TargetSubtargetInfo.h" |
Chandler Carruth | aafe091 | 2012-06-29 12:38:19 +0000 | [diff] [blame] | 35 | #include "llvm/Transforms/Scalar.h" |
| 36 | #include "llvm/Transforms/Utils/BasicBlockUtils.h" |
| 37 | #include "llvm/Transforms/Utils/Local.h" |
Benjamin Kramer | 63abc84 | 2010-11-06 11:45:59 +0000 | [diff] [blame] | 38 | #include <set> |
Jim Grosbach | 486be66 | 2009-08-17 16:41:22 +0000 | [diff] [blame] | 39 | using namespace llvm; |
| 40 | |
Chandler Carruth | 1b9dde0 | 2014-04-22 02:02:50 +0000 | [diff] [blame] | 41 | #define DEBUG_TYPE "sjljehprepare" |
| 42 | |
Jim Grosbach | 486be66 | 2009-08-17 16:41:22 +0000 | [diff] [blame] | 43 | STATISTIC(NumInvokes, "Number of invokes replaced"); |
Jim Grosbach | 486be66 | 2009-08-17 16:41:22 +0000 | [diff] [blame] | 44 | STATISTIC(NumSpilled, "Number of registers live across unwind edges"); |
| 45 | |
| 46 | namespace { |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 47 | class SjLjEHPrepare : public FunctionPass { |
| 48 | const TargetMachine *TM; |
David Blaikie | 4e5d47f4 | 2015-04-04 21:07:10 +0000 | [diff] [blame^] | 49 | Type *doubleUnderDataTy; |
| 50 | Type *doubleUnderJBufTy; |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 51 | Type *FunctionContextTy; |
| 52 | Constant *RegisterFn; |
| 53 | Constant *UnregisterFn; |
| 54 | Constant *BuiltinSetjmpFn; |
| 55 | Constant *FrameAddrFn; |
| 56 | Constant *StackAddrFn; |
| 57 | Constant *StackRestoreFn; |
| 58 | Constant *LSDAAddrFn; |
| 59 | Value *PersonalityFn; |
| 60 | Constant *CallSiteFn; |
| 61 | Constant *FuncCtxFn; |
| 62 | AllocaInst *FuncCtx; |
Jim Grosbach | 486be66 | 2009-08-17 16:41:22 +0000 | [diff] [blame] | 63 | |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 64 | public: |
| 65 | static char ID; // Pass identification, replacement for typeid |
| 66 | explicit SjLjEHPrepare(const TargetMachine *TM) : FunctionPass(ID), TM(TM) {} |
Craig Topper | 4584cd5 | 2014-03-07 09:26:03 +0000 | [diff] [blame] | 67 | bool doInitialization(Module &M) override; |
| 68 | bool runOnFunction(Function &F) override; |
Jim Grosbach | 486be66 | 2009-08-17 16:41:22 +0000 | [diff] [blame] | 69 | |
Craig Topper | 4584cd5 | 2014-03-07 09:26:03 +0000 | [diff] [blame] | 70 | void getAnalysisUsage(AnalysisUsage &AU) const override {} |
| 71 | const char *getPassName() const override { |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 72 | return "SJLJ Exception Handling preparation"; |
| 73 | } |
| 74 | |
| 75 | private: |
| 76 | bool setupEntryBlockAndCallSites(Function &F); |
| 77 | void substituteLPadValues(LandingPadInst *LPI, Value *ExnVal, Value *SelVal); |
| 78 | Value *setupFunctionContext(Function &F, ArrayRef<LandingPadInst *> LPads); |
| 79 | void lowerIncomingArguments(Function &F); |
| 80 | void lowerAcrossUnwindEdges(Function &F, ArrayRef<InvokeInst *> Invokes); |
| 81 | void insertCallSiteStore(Instruction *I, int Number); |
| 82 | }; |
Jim Grosbach | 486be66 | 2009-08-17 16:41:22 +0000 | [diff] [blame] | 83 | } // end anonymous namespace |
| 84 | |
Bill Wendling | 12e5adb | 2012-03-13 20:04:21 +0000 | [diff] [blame] | 85 | char SjLjEHPrepare::ID = 0; |
Jim Grosbach | 486be66 | 2009-08-17 16:41:22 +0000 | [diff] [blame] | 86 | |
Bill Wendling | 12e5adb | 2012-03-13 20:04:21 +0000 | [diff] [blame] | 87 | // Public Interface To the SjLjEHPrepare pass. |
Bill Wendling | afc1036 | 2013-06-19 20:51:24 +0000 | [diff] [blame] | 88 | FunctionPass *llvm::createSjLjEHPreparePass(const TargetMachine *TM) { |
| 89 | return new SjLjEHPrepare(TM); |
Jim Grosbach | 486be66 | 2009-08-17 16:41:22 +0000 | [diff] [blame] | 90 | } |
Jim Grosbach | 1b0436b | 2009-08-23 18:13:48 +0000 | [diff] [blame] | 91 | // doInitialization - Set up decalarations and types needed to process |
| 92 | // exceptions. |
Bill Wendling | 12e5adb | 2012-03-13 20:04:21 +0000 | [diff] [blame] | 93 | bool SjLjEHPrepare::doInitialization(Module &M) { |
Jim Grosbach | 486be66 | 2009-08-17 16:41:22 +0000 | [diff] [blame] | 94 | // Build the function context structure. |
| 95 | // builtin_setjmp uses a five word jbuf |
Jay Foad | b804a2b | 2011-07-12 14:06:48 +0000 | [diff] [blame] | 96 | Type *VoidPtrTy = Type::getInt8PtrTy(M.getContext()); |
| 97 | Type *Int32Ty = Type::getInt32Ty(M.getContext()); |
David Blaikie | 4e5d47f4 | 2015-04-04 21:07:10 +0000 | [diff] [blame^] | 98 | doubleUnderDataTy = ArrayType::get(Int32Ty, 4); |
| 99 | doubleUnderJBufTy = ArrayType::get(VoidPtrTy, 5); |
| 100 | FunctionContextTy = StructType::get(VoidPtrTy, // __prev |
| 101 | Int32Ty, // call_site |
| 102 | doubleUnderDataTy, // __data |
| 103 | VoidPtrTy, // __personality |
| 104 | VoidPtrTy, // __lsda |
| 105 | doubleUnderJBufTy, // __jbuf |
Reid Kleckner | 971c3ea | 2014-11-13 22:55:19 +0000 | [diff] [blame] | 106 | nullptr); |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 107 | RegisterFn = M.getOrInsertFunction( |
| 108 | "_Unwind_SjLj_Register", Type::getVoidTy(M.getContext()), |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 109 | PointerType::getUnqual(FunctionContextTy), (Type *)nullptr); |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 110 | UnregisterFn = M.getOrInsertFunction( |
| 111 | "_Unwind_SjLj_Unregister", Type::getVoidTy(M.getContext()), |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 112 | PointerType::getUnqual(FunctionContextTy), (Type *)nullptr); |
Jim Grosbach | 486be66 | 2009-08-17 16:41:22 +0000 | [diff] [blame] | 113 | FrameAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::frameaddress); |
Jim Grosbach | faa3abb | 2010-05-27 23:49:24 +0000 | [diff] [blame] | 114 | StackAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::stacksave); |
Bob Wilson | 643e63c | 2011-11-16 07:12:00 +0000 | [diff] [blame] | 115 | StackRestoreFn = Intrinsic::getDeclaration(&M, Intrinsic::stackrestore); |
Jim Grosbach | 486be66 | 2009-08-17 16:41:22 +0000 | [diff] [blame] | 116 | BuiltinSetjmpFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_setjmp); |
| 117 | LSDAAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_lsda); |
Jim Grosbach | 54c0530 | 2010-01-28 01:45:32 +0000 | [diff] [blame] | 118 | CallSiteFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_callsite); |
Bill Wendling | 899da52 | 2011-09-28 21:56:53 +0000 | [diff] [blame] | 119 | FuncCtxFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_functioncontext); |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 120 | PersonalityFn = nullptr; |
Jim Grosbach | 486be66 | 2009-08-17 16:41:22 +0000 | [diff] [blame] | 121 | |
| 122 | return true; |
| 123 | } |
| 124 | |
Jim Grosbach | 1201f29 | 2010-03-04 22:07:46 +0000 | [diff] [blame] | 125 | /// insertCallSiteStore - Insert a store of the call-site value to the |
| 126 | /// function context |
Bill Wendling | 12e5adb | 2012-03-13 20:04:21 +0000 | [diff] [blame] | 127 | void SjLjEHPrepare::insertCallSiteStore(Instruction *I, int Number) { |
Bill Wendling | 7717e9f | 2012-01-27 02:02:24 +0000 | [diff] [blame] | 128 | IRBuilder<> Builder(I); |
| 129 | |
| 130 | // Get a reference to the call_site field. |
| 131 | Type *Int32Ty = Type::getInt32Ty(I->getContext()); |
| 132 | Value *Zero = ConstantInt::get(Int32Ty, 0); |
| 133 | Value *One = ConstantInt::get(Int32Ty, 1); |
| 134 | Value *Idxs[2] = { Zero, One }; |
David Blaikie | 68d535c | 2015-03-24 22:38:16 +0000 | [diff] [blame] | 135 | Value *CallSite = |
| 136 | Builder.CreateGEP(FunctionContextTy, FuncCtx, Idxs, "call_site"); |
Bill Wendling | 7717e9f | 2012-01-27 02:02:24 +0000 | [diff] [blame] | 137 | |
| 138 | // Insert a store of the call-site number |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 139 | ConstantInt *CallSiteNoC = |
| 140 | ConstantInt::get(Type::getInt32Ty(I->getContext()), Number); |
| 141 | Builder.CreateStore(CallSiteNoC, CallSite, true /*volatile*/); |
Jim Grosbach | 1201f29 | 2010-03-04 22:07:46 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Chad Rosier | 1a9c17e | 2012-03-16 01:04:00 +0000 | [diff] [blame] | 144 | /// MarkBlocksLiveIn - Insert BB and all of its predescessors into LiveBBs until |
Jim Grosbach | 486be66 | 2009-08-17 16:41:22 +0000 | [diff] [blame] | 145 | /// we reach blocks we've already seen. |
Chad Rosier | 1a9c17e | 2012-03-16 01:04:00 +0000 | [diff] [blame] | 146 | static void MarkBlocksLiveIn(BasicBlock *BB, |
Craig Topper | 71b7b68 | 2014-08-21 05:55:13 +0000 | [diff] [blame] | 147 | SmallPtrSetImpl<BasicBlock *> &LiveBBs) { |
David Blaikie | 70573dc | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 148 | if (!LiveBBs.insert(BB).second) |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 149 | return; // already been here. |
Jim Grosbach | 486be66 | 2009-08-17 16:41:22 +0000 | [diff] [blame] | 150 | |
Duncan P. N. Exon Smith | 6c99015 | 2014-07-21 17:06:51 +0000 | [diff] [blame] | 151 | for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) |
| 152 | MarkBlocksLiveIn(*PI, LiveBBs); |
Jim Grosbach | 486be66 | 2009-08-17 16:41:22 +0000 | [diff] [blame] | 153 | } |
| 154 | |
Bill Wendling | b108aae | 2011-12-14 22:45:33 +0000 | [diff] [blame] | 155 | /// substituteLPadValues - Substitute the values returned by the landingpad |
| 156 | /// instruction with those returned by the personality function. |
Bill Wendling | 12e5adb | 2012-03-13 20:04:21 +0000 | [diff] [blame] | 157 | void SjLjEHPrepare::substituteLPadValues(LandingPadInst *LPI, Value *ExnVal, |
| 158 | Value *SelVal) { |
Chandler Carruth | cdf4788 | 2014-03-09 03:16:01 +0000 | [diff] [blame] | 159 | SmallVector<Value *, 8> UseWorkList(LPI->user_begin(), LPI->user_end()); |
Bill Wendling | b108aae | 2011-12-14 22:45:33 +0000 | [diff] [blame] | 160 | while (!UseWorkList.empty()) { |
| 161 | Value *Val = UseWorkList.pop_back_val(); |
| 162 | ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(Val); |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 163 | if (!EVI) |
| 164 | continue; |
| 165 | if (EVI->getNumIndices() != 1) |
| 166 | continue; |
Bill Wendling | b108aae | 2011-12-14 22:45:33 +0000 | [diff] [blame] | 167 | if (*EVI->idx_begin() == 0) |
| 168 | EVI->replaceAllUsesWith(ExnVal); |
| 169 | else if (*EVI->idx_begin() == 1) |
| 170 | EVI->replaceAllUsesWith(SelVal); |
| 171 | if (EVI->getNumUses() == 0) |
| 172 | EVI->eraseFromParent(); |
| 173 | } |
| 174 | |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 175 | if (LPI->getNumUses() == 0) |
| 176 | return; |
Bill Wendling | b108aae | 2011-12-14 22:45:33 +0000 | [diff] [blame] | 177 | |
| 178 | // There are still some uses of LPI. Construct an aggregate with the exception |
| 179 | // values and replace the LPI with that aggregate. |
| 180 | Type *LPadType = LPI->getType(); |
| 181 | Value *LPadVal = UndefValue::get(LPadType); |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 182 | IRBuilder<> Builder( |
Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 183 | std::next(BasicBlock::iterator(cast<Instruction>(SelVal)))); |
Bill Wendling | b108aae | 2011-12-14 22:45:33 +0000 | [diff] [blame] | 184 | LPadVal = Builder.CreateInsertValue(LPadVal, ExnVal, 0, "lpad.val"); |
| 185 | LPadVal = Builder.CreateInsertValue(LPadVal, SelVal, 1, "lpad.val"); |
| 186 | |
| 187 | LPI->replaceAllUsesWith(LPadVal); |
| 188 | } |
| 189 | |
Bill Wendling | 2e76ca9 | 2011-09-28 03:14:05 +0000 | [diff] [blame] | 190 | /// setupFunctionContext - Allocate the function context on the stack and fill |
| 191 | /// it with all of the data that we know at this point. |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 192 | Value *SjLjEHPrepare::setupFunctionContext(Function &F, |
| 193 | ArrayRef<LandingPadInst *> LPads) { |
Bill Wendling | 2e76ca9 | 2011-09-28 03:14:05 +0000 | [diff] [blame] | 194 | BasicBlock *EntryBB = F.begin(); |
| 195 | |
| 196 | // Create an alloca for the incoming jump buffer ptr and the new jump buffer |
| 197 | // that needs to be restored on all exits from the function. This is an alloca |
| 198 | // because the value needs to be added to the global context list. |
Eric Christopher | 3372620 | 2015-01-27 08:48:42 +0000 | [diff] [blame] | 199 | const TargetLowering *TLI = TM->getSubtargetImpl(F)->getTargetLowering(); |
Bill Wendling | 2e76ca9 | 2011-09-28 03:14:05 +0000 | [diff] [blame] | 200 | unsigned Align = |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 201 | TLI->getDataLayout()->getPrefTypeAlignment(FunctionContextTy); |
Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 202 | FuncCtx = new AllocaInst(FunctionContextTy, nullptr, Align, "fn_context", |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 203 | EntryBB->begin()); |
Bill Wendling | 2e76ca9 | 2011-09-28 03:14:05 +0000 | [diff] [blame] | 204 | |
| 205 | // Fill in the function context structure. |
Bill Wendling | 2e76ca9 | 2011-09-28 03:14:05 +0000 | [diff] [blame] | 206 | for (unsigned I = 0, E = LPads.size(); I != E; ++I) { |
| 207 | LandingPadInst *LPI = LPads[I]; |
| 208 | IRBuilder<> Builder(LPI->getParent()->getFirstInsertionPt()); |
| 209 | |
Bill Wendling | 7717e9f | 2012-01-27 02:02:24 +0000 | [diff] [blame] | 210 | // Reference the __data field. |
David Blaikie | 4e5d47f4 | 2015-04-04 21:07:10 +0000 | [diff] [blame^] | 211 | Value *FCData = |
| 212 | Builder.CreateConstGEP2_32(FunctionContextTy, FuncCtx, 0, 2, "__data"); |
Bill Wendling | 7717e9f | 2012-01-27 02:02:24 +0000 | [diff] [blame] | 213 | |
| 214 | // The exception values come back in context->__data[0]. |
David Blaikie | 4e5d47f4 | 2015-04-04 21:07:10 +0000 | [diff] [blame^] | 215 | Value *ExceptionAddr = Builder.CreateConstGEP2_32(doubleUnderDataTy, FCData, |
| 216 | 0, 0, "exception_gep"); |
Bill Wendling | 2e76ca9 | 2011-09-28 03:14:05 +0000 | [diff] [blame] | 217 | Value *ExnVal = Builder.CreateLoad(ExceptionAddr, true, "exn_val"); |
Benjamin Kramer | 8d9890a | 2012-09-03 12:27:43 +0000 | [diff] [blame] | 218 | ExnVal = Builder.CreateIntToPtr(ExnVal, Builder.getInt8PtrTy()); |
Bill Wendling | 7717e9f | 2012-01-27 02:02:24 +0000 | [diff] [blame] | 219 | |
David Blaikie | 4e5d47f4 | 2015-04-04 21:07:10 +0000 | [diff] [blame^] | 220 | Value *SelectorAddr = Builder.CreateConstGEP2_32(doubleUnderDataTy, FCData, |
| 221 | 0, 1, "exn_selector_gep"); |
Bill Wendling | 2e76ca9 | 2011-09-28 03:14:05 +0000 | [diff] [blame] | 222 | Value *SelVal = Builder.CreateLoad(SelectorAddr, true, "exn_selector_val"); |
| 223 | |
Bill Wendling | b108aae | 2011-12-14 22:45:33 +0000 | [diff] [blame] | 224 | substituteLPadValues(LPI, ExnVal, SelVal); |
Bill Wendling | 2e76ca9 | 2011-09-28 03:14:05 +0000 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | // Personality function |
Benjamin Kramer | 8d9890a | 2012-09-03 12:27:43 +0000 | [diff] [blame] | 228 | IRBuilder<> Builder(EntryBB->getTerminator()); |
Bill Wendling | 2e76ca9 | 2011-09-28 03:14:05 +0000 | [diff] [blame] | 229 | if (!PersonalityFn) |
| 230 | PersonalityFn = LPads[0]->getPersonalityFn(); |
David Blaikie | 4e5d47f4 | 2015-04-04 21:07:10 +0000 | [diff] [blame^] | 231 | Value *PersonalityFieldPtr = Builder.CreateConstGEP2_32( |
| 232 | FunctionContextTy, FuncCtx, 0, 3, "pers_fn_gep"); |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 233 | Builder.CreateStore( |
| 234 | Builder.CreateBitCast(PersonalityFn, Builder.getInt8PtrTy()), |
| 235 | PersonalityFieldPtr, /*isVolatile=*/true); |
Bill Wendling | 2e76ca9 | 2011-09-28 03:14:05 +0000 | [diff] [blame] | 236 | |
| 237 | // LSDA address |
Benjamin Kramer | 8d9890a | 2012-09-03 12:27:43 +0000 | [diff] [blame] | 238 | Value *LSDA = Builder.CreateCall(LSDAAddrFn, "lsda_addr"); |
David Blaikie | 4e5d47f4 | 2015-04-04 21:07:10 +0000 | [diff] [blame^] | 239 | Value *LSDAFieldPtr = |
| 240 | Builder.CreateConstGEP2_32(FunctionContextTy, FuncCtx, 0, 4, "lsda_gep"); |
Benjamin Kramer | 8d9890a | 2012-09-03 12:27:43 +0000 | [diff] [blame] | 241 | Builder.CreateStore(LSDA, LSDAFieldPtr, /*isVolatile=*/true); |
Bill Wendling | 2e76ca9 | 2011-09-28 03:14:05 +0000 | [diff] [blame] | 242 | |
Bill Wendling | 6f3e73d | 2011-10-03 21:15:28 +0000 | [diff] [blame] | 243 | return FuncCtx; |
Bill Wendling | 899da52 | 2011-09-28 21:56:53 +0000 | [diff] [blame] | 244 | } |
| 245 | |
Bill Wendling | e9574be | 2011-10-08 00:56:47 +0000 | [diff] [blame] | 246 | /// lowerIncomingArguments - To avoid having to handle incoming arguments |
| 247 | /// specially, we lower each arg to a copy instruction in the entry block. This |
| 248 | /// ensures that the argument value itself cannot be live out of the entry |
| 249 | /// block. |
Bill Wendling | 12e5adb | 2012-03-13 20:04:21 +0000 | [diff] [blame] | 250 | void SjLjEHPrepare::lowerIncomingArguments(Function &F) { |
Bill Wendling | e9574be | 2011-10-08 00:56:47 +0000 | [diff] [blame] | 251 | BasicBlock::iterator AfterAllocaInsPt = F.begin()->begin(); |
| 252 | while (isa<AllocaInst>(AfterAllocaInsPt) && |
| 253 | isa<ConstantInt>(cast<AllocaInst>(AfterAllocaInsPt)->getArraySize())) |
| 254 | ++AfterAllocaInsPt; |
| 255 | |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 256 | for (Function::arg_iterator AI = F.arg_begin(), AE = F.arg_end(); AI != AE; |
| 257 | ++AI) { |
Bill Wendling | e9574be | 2011-10-08 00:56:47 +0000 | [diff] [blame] | 258 | Type *Ty = AI->getType(); |
| 259 | |
Bill Wendling | c80b6c9 | 2014-07-14 18:21:11 +0000 | [diff] [blame] | 260 | // Use 'select i8 true, %arg, undef' to simulate a 'no-op' instruction. |
| 261 | Value *TrueValue = ConstantInt::getTrue(F.getContext()); |
| 262 | Value *UndefValue = UndefValue::get(Ty); |
| 263 | Instruction *SI = SelectInst::Create(TrueValue, AI, UndefValue, |
| 264 | AI->getName() + ".tmp", |
| 265 | AfterAllocaInsPt); |
| 266 | AI->replaceAllUsesWith(SI); |
Bill Wendling | e9574be | 2011-10-08 00:56:47 +0000 | [diff] [blame] | 267 | |
Bill Wendling | c80b6c9 | 2014-07-14 18:21:11 +0000 | [diff] [blame] | 268 | // Reset the operand, because it was clobbered by the RAUW above. |
| 269 | SI->setOperand(1, AI); |
Bill Wendling | e9574be | 2011-10-08 00:56:47 +0000 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | |
| 273 | /// lowerAcrossUnwindEdges - Find all variables which are alive across an unwind |
| 274 | /// edge and spill them. |
Bill Wendling | 12e5adb | 2012-03-13 20:04:21 +0000 | [diff] [blame] | 275 | void SjLjEHPrepare::lowerAcrossUnwindEdges(Function &F, |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 276 | ArrayRef<InvokeInst *> Invokes) { |
Bill Wendling | e9574be | 2011-10-08 00:56:47 +0000 | [diff] [blame] | 277 | // Finally, scan the code looking for instructions with bad live ranges. |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 278 | for (Function::iterator BB = F.begin(), BBE = F.end(); BB != BBE; ++BB) { |
| 279 | for (BasicBlock::iterator II = BB->begin(), IIE = BB->end(); II != IIE; |
| 280 | ++II) { |
Bill Wendling | e9574be | 2011-10-08 00:56:47 +0000 | [diff] [blame] | 281 | // Ignore obvious cases we don't have to handle. In particular, most |
| 282 | // instructions either have no uses or only have a single use inside the |
| 283 | // current block. Ignore them quickly. |
| 284 | Instruction *Inst = II; |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 285 | if (Inst->use_empty()) |
| 286 | continue; |
Bill Wendling | e9574be | 2011-10-08 00:56:47 +0000 | [diff] [blame] | 287 | if (Inst->hasOneUse() && |
Chandler Carruth | cdf4788 | 2014-03-09 03:16:01 +0000 | [diff] [blame] | 288 | cast<Instruction>(Inst->user_back())->getParent() == BB && |
| 289 | !isa<PHINode>(Inst->user_back())) |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 290 | continue; |
Bill Wendling | e9574be | 2011-10-08 00:56:47 +0000 | [diff] [blame] | 291 | |
| 292 | // If this is an alloca in the entry block, it's not a real register |
| 293 | // value. |
| 294 | if (AllocaInst *AI = dyn_cast<AllocaInst>(Inst)) |
| 295 | if (isa<ConstantInt>(AI->getArraySize()) && BB == F.begin()) |
| 296 | continue; |
| 297 | |
| 298 | // Avoid iterator invalidation by copying users to a temporary vector. |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 299 | SmallVector<Instruction *, 16> Users; |
Chandler Carruth | cdf4788 | 2014-03-09 03:16:01 +0000 | [diff] [blame] | 300 | for (User *U : Inst->users()) { |
| 301 | Instruction *UI = cast<Instruction>(U); |
| 302 | if (UI->getParent() != BB || isa<PHINode>(UI)) |
| 303 | Users.push_back(UI); |
Bill Wendling | e9574be | 2011-10-08 00:56:47 +0000 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | // Find all of the blocks that this value is live in. |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 307 | SmallPtrSet<BasicBlock *, 64> LiveBBs; |
Chad Rosier | 1a9c17e | 2012-03-16 01:04:00 +0000 | [diff] [blame] | 308 | LiveBBs.insert(Inst->getParent()); |
Bill Wendling | e9574be | 2011-10-08 00:56:47 +0000 | [diff] [blame] | 309 | while (!Users.empty()) { |
Chad Rosier | 1a9c17e | 2012-03-16 01:04:00 +0000 | [diff] [blame] | 310 | Instruction *U = Users.back(); |
| 311 | Users.pop_back(); |
Bill Wendling | e9574be | 2011-10-08 00:56:47 +0000 | [diff] [blame] | 312 | |
Chad Rosier | 1a9c17e | 2012-03-16 01:04:00 +0000 | [diff] [blame] | 313 | if (!isa<PHINode>(U)) { |
| 314 | MarkBlocksLiveIn(U->getParent(), LiveBBs); |
| 315 | } else { |
Bill Wendling | e9574be | 2011-10-08 00:56:47 +0000 | [diff] [blame] | 316 | // Uses for a PHI node occur in their predecessor block. |
Chad Rosier | 1a9c17e | 2012-03-16 01:04:00 +0000 | [diff] [blame] | 317 | PHINode *PN = cast<PHINode>(U); |
Bill Wendling | e9574be | 2011-10-08 00:56:47 +0000 | [diff] [blame] | 318 | for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) |
| 319 | if (PN->getIncomingValue(i) == Inst) |
Chad Rosier | 1a9c17e | 2012-03-16 01:04:00 +0000 | [diff] [blame] | 320 | MarkBlocksLiveIn(PN->getIncomingBlock(i), LiveBBs); |
Bill Wendling | e9574be | 2011-10-08 00:56:47 +0000 | [diff] [blame] | 321 | } |
| 322 | } |
| 323 | |
Chad Rosier | 1a9c17e | 2012-03-16 01:04:00 +0000 | [diff] [blame] | 324 | // Now that we know all of the blocks that this thing is live in, see if |
| 325 | // it includes any of the unwind locations. |
| 326 | bool NeedsSpill = false; |
| 327 | for (unsigned i = 0, e = Invokes.size(); i != e; ++i) { |
| 328 | BasicBlock *UnwindBlock = Invokes[i]->getUnwindDest(); |
| 329 | if (UnwindBlock != BB && LiveBBs.count(UnwindBlock)) { |
| 330 | DEBUG(dbgs() << "SJLJ Spill: " << *Inst << " around " |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 331 | << UnwindBlock->getName() << "\n"); |
Chad Rosier | 1a9c17e | 2012-03-16 01:04:00 +0000 | [diff] [blame] | 332 | NeedsSpill = true; |
| 333 | break; |
Bill Wendling | d7c0aae | 2012-03-14 07:28:01 +0000 | [diff] [blame] | 334 | } |
Bill Wendling | 5ad9140 | 2012-03-12 20:19:41 +0000 | [diff] [blame] | 335 | } |
Bill Wendling | b1c4308 | 2011-10-21 22:08:56 +0000 | [diff] [blame] | 336 | |
Chad Rosier | 1a9c17e | 2012-03-16 01:04:00 +0000 | [diff] [blame] | 337 | // If we decided we need a spill, do it. |
| 338 | // FIXME: Spilling this way is overkill, as it forces all uses of |
| 339 | // the value to be reloaded from the stack slot, even those that aren't |
| 340 | // in the unwind blocks. We should be more selective. |
| 341 | if (NeedsSpill) { |
| 342 | DemoteRegToStack(*Inst, true); |
| 343 | ++NumSpilled; |
| 344 | } |
Bill Wendling | d7c0aae | 2012-03-14 07:28:01 +0000 | [diff] [blame] | 345 | } |
| 346 | } |
| 347 | |
Bill Wendling | b1c4308 | 2011-10-21 22:08:56 +0000 | [diff] [blame] | 348 | // Go through the landing pads and remove any PHIs there. |
| 349 | for (unsigned i = 0, e = Invokes.size(); i != e; ++i) { |
| 350 | BasicBlock *UnwindBlock = Invokes[i]->getUnwindDest(); |
| 351 | LandingPadInst *LPI = UnwindBlock->getLandingPadInst(); |
| 352 | |
| 353 | // Place PHIs into a set to avoid invalidating the iterator. |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 354 | SmallPtrSet<PHINode *, 8> PHIsToDemote; |
| 355 | for (BasicBlock::iterator PN = UnwindBlock->begin(); isa<PHINode>(PN); ++PN) |
Bill Wendling | b1c4308 | 2011-10-21 22:08:56 +0000 | [diff] [blame] | 356 | PHIsToDemote.insert(cast<PHINode>(PN)); |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 357 | if (PHIsToDemote.empty()) |
| 358 | continue; |
Bill Wendling | b1c4308 | 2011-10-21 22:08:56 +0000 | [diff] [blame] | 359 | |
| 360 | // Demote the PHIs to the stack. |
Craig Topper | 4627679 | 2014-08-24 23:23:06 +0000 | [diff] [blame] | 361 | for (PHINode *PN : PHIsToDemote) |
| 362 | DemotePHIToStack(PN); |
Bill Wendling | b1c4308 | 2011-10-21 22:08:56 +0000 | [diff] [blame] | 363 | |
| 364 | // Move the landingpad instruction back to the top of the landing pad block. |
| 365 | LPI->moveBefore(UnwindBlock->begin()); |
| 366 | } |
Bill Wendling | e9574be | 2011-10-08 00:56:47 +0000 | [diff] [blame] | 367 | } |
| 368 | |
Bill Wendling | 899da52 | 2011-09-28 21:56:53 +0000 | [diff] [blame] | 369 | /// setupEntryBlockAndCallSites - Setup the entry block by creating and filling |
| 370 | /// the function context and marking the call sites with the appropriate |
| 371 | /// values. These values are used by the DWARF EH emitter. |
Bill Wendling | 12e5adb | 2012-03-13 20:04:21 +0000 | [diff] [blame] | 372 | bool SjLjEHPrepare::setupEntryBlockAndCallSites(Function &F) { |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 373 | SmallVector<ReturnInst *, 16> Returns; |
| 374 | SmallVector<InvokeInst *, 16> Invokes; |
| 375 | SmallSetVector<LandingPadInst *, 16> LPads; |
Bill Wendling | 899da52 | 2011-09-28 21:56:53 +0000 | [diff] [blame] | 376 | |
| 377 | // Look through the terminators of the basic blocks to find invokes. |
| 378 | for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) |
| 379 | if (InvokeInst *II = dyn_cast<InvokeInst>(BB->getTerminator())) { |
Bill Wendling | 2d915e2 | 2013-03-08 02:21:08 +0000 | [diff] [blame] | 380 | if (Function *Callee = II->getCalledFunction()) |
| 381 | if (Callee->isIntrinsic() && |
| 382 | Callee->getIntrinsicID() == Intrinsic::donothing) { |
| 383 | // Remove the NOP invoke. |
| 384 | BranchInst::Create(II->getNormalDest(), II); |
| 385 | II->eraseFromParent(); |
| 386 | continue; |
| 387 | } |
| 388 | |
Bill Wendling | 899da52 | 2011-09-28 21:56:53 +0000 | [diff] [blame] | 389 | Invokes.push_back(II); |
Bob Wilson | cca9aa5 | 2011-11-16 07:57:21 +0000 | [diff] [blame] | 390 | LPads.insert(II->getUnwindDest()->getLandingPadInst()); |
Bill Wendling | 899da52 | 2011-09-28 21:56:53 +0000 | [diff] [blame] | 391 | } else if (ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator())) { |
| 392 | Returns.push_back(RI); |
| 393 | } |
| 394 | |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 395 | if (Invokes.empty()) |
| 396 | return false; |
Bill Wendling | 899da52 | 2011-09-28 21:56:53 +0000 | [diff] [blame] | 397 | |
Bill Wendling | 38f86c5 | 2011-10-24 17:12:36 +0000 | [diff] [blame] | 398 | NumInvokes += Invokes.size(); |
| 399 | |
Bill Wendling | e9574be | 2011-10-08 00:56:47 +0000 | [diff] [blame] | 400 | lowerIncomingArguments(F); |
| 401 | lowerAcrossUnwindEdges(F, Invokes); |
| 402 | |
Bob Wilson | cca9aa5 | 2011-11-16 07:57:21 +0000 | [diff] [blame] | 403 | Value *FuncCtx = |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 404 | setupFunctionContext(F, makeArrayRef(LPads.begin(), LPads.end())); |
Bill Wendling | 899da52 | 2011-09-28 21:56:53 +0000 | [diff] [blame] | 405 | BasicBlock *EntryBB = F.begin(); |
Benjamin Kramer | 8d9890a | 2012-09-03 12:27:43 +0000 | [diff] [blame] | 406 | IRBuilder<> Builder(EntryBB->getTerminator()); |
Bill Wendling | 6f3e73d | 2011-10-03 21:15:28 +0000 | [diff] [blame] | 407 | |
| 408 | // Get a reference to the jump buffer. |
David Blaikie | 4e5d47f4 | 2015-04-04 21:07:10 +0000 | [diff] [blame^] | 409 | Value *JBufPtr = |
| 410 | Builder.CreateConstGEP2_32(FunctionContextTy, FuncCtx, 0, 5, "jbuf_gep"); |
Bill Wendling | 2e76ca9 | 2011-09-28 03:14:05 +0000 | [diff] [blame] | 411 | |
Bill Wendling | 6f3e73d | 2011-10-03 21:15:28 +0000 | [diff] [blame] | 412 | // Save the frame pointer. |
David Blaikie | 4e5d47f4 | 2015-04-04 21:07:10 +0000 | [diff] [blame^] | 413 | Value *FramePtr = Builder.CreateConstGEP2_32(doubleUnderJBufTy, JBufPtr, 0, 0, |
| 414 | "jbuf_fp_gep"); |
Bill Wendling | 6f3e73d | 2011-10-03 21:15:28 +0000 | [diff] [blame] | 415 | |
Benjamin Kramer | 8d9890a | 2012-09-03 12:27:43 +0000 | [diff] [blame] | 416 | Value *Val = Builder.CreateCall(FrameAddrFn, Builder.getInt32(0), "fp"); |
| 417 | Builder.CreateStore(Val, FramePtr, /*isVolatile=*/true); |
Bill Wendling | 6f3e73d | 2011-10-03 21:15:28 +0000 | [diff] [blame] | 418 | |
| 419 | // Save the stack pointer. |
David Blaikie | 4e5d47f4 | 2015-04-04 21:07:10 +0000 | [diff] [blame^] | 420 | Value *StackPtr = Builder.CreateConstGEP2_32(doubleUnderJBufTy, JBufPtr, 0, 2, |
| 421 | "jbuf_sp_gep"); |
Bill Wendling | 6f3e73d | 2011-10-03 21:15:28 +0000 | [diff] [blame] | 422 | |
Benjamin Kramer | 8d9890a | 2012-09-03 12:27:43 +0000 | [diff] [blame] | 423 | Val = Builder.CreateCall(StackAddrFn, "sp"); |
| 424 | Builder.CreateStore(Val, StackPtr, /*isVolatile=*/true); |
Bill Wendling | 2e76ca9 | 2011-09-28 03:14:05 +0000 | [diff] [blame] | 425 | |
| 426 | // Call the setjmp instrinsic. It fills in the rest of the jmpbuf. |
Benjamin Kramer | 8d9890a | 2012-09-03 12:27:43 +0000 | [diff] [blame] | 427 | Value *SetjmpArg = Builder.CreateBitCast(JBufPtr, Builder.getInt8PtrTy()); |
| 428 | Builder.CreateCall(BuiltinSetjmpFn, SetjmpArg); |
Bill Wendling | 2e76ca9 | 2011-09-28 03:14:05 +0000 | [diff] [blame] | 429 | |
Bill Wendling | 899da52 | 2011-09-28 21:56:53 +0000 | [diff] [blame] | 430 | // Store a pointer to the function context so that the back-end will know |
| 431 | // where to look for it. |
Benjamin Kramer | 8d9890a | 2012-09-03 12:27:43 +0000 | [diff] [blame] | 432 | Value *FuncCtxArg = Builder.CreateBitCast(FuncCtx, Builder.getInt8PtrTy()); |
| 433 | Builder.CreateCall(FuncCtxFn, FuncCtxArg); |
Bill Wendling | 2e76ca9 | 2011-09-28 03:14:05 +0000 | [diff] [blame] | 434 | |
| 435 | // At this point, we are all set up, update the invoke instructions to mark |
Bill Wendling | db16335 | 2011-10-05 22:04:08 +0000 | [diff] [blame] | 436 | // their call_site values. |
Bill Wendling | 2e76ca9 | 2011-09-28 03:14:05 +0000 | [diff] [blame] | 437 | for (unsigned I = 0, E = Invokes.size(); I != E; ++I) { |
Bill Wendling | 7717e9f | 2012-01-27 02:02:24 +0000 | [diff] [blame] | 438 | insertCallSiteStore(Invokes[I], I + 1); |
Bill Wendling | 2e76ca9 | 2011-09-28 03:14:05 +0000 | [diff] [blame] | 439 | |
| 440 | ConstantInt *CallSiteNum = |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 441 | ConstantInt::get(Type::getInt32Ty(F.getContext()), I + 1); |
Bill Wendling | 2e76ca9 | 2011-09-28 03:14:05 +0000 | [diff] [blame] | 442 | |
| 443 | // Record the call site value for the back end so it stays associated with |
| 444 | // the invoke. |
| 445 | CallInst::Create(CallSiteFn, CallSiteNum, "", Invokes[I]); |
| 446 | } |
| 447 | |
| 448 | // Mark call instructions that aren't nounwind as no-action (call_site == |
| 449 | // -1). Skip the entry block, as prior to then, no function context has been |
| 450 | // created for this function and any unexpected exceptions thrown will go |
| 451 | // directly to the caller's context, which is what we want anyway, so no need |
| 452 | // to do anything here. |
Bill Wendling | ac3fb4c | 2011-10-04 00:16:40 +0000 | [diff] [blame] | 453 | for (Function::iterator BB = F.begin(), E = F.end(); ++BB != E;) |
Bill Wendling | 2e76ca9 | 2011-09-28 03:14:05 +0000 | [diff] [blame] | 454 | for (BasicBlock::iterator I = BB->begin(), end = BB->end(); I != end; ++I) |
| 455 | if (CallInst *CI = dyn_cast<CallInst>(I)) { |
| 456 | if (!CI->doesNotThrow()) |
Bill Wendling | 7717e9f | 2012-01-27 02:02:24 +0000 | [diff] [blame] | 457 | insertCallSiteStore(CI, -1); |
Bill Wendling | 2e76ca9 | 2011-09-28 03:14:05 +0000 | [diff] [blame] | 458 | } else if (ResumeInst *RI = dyn_cast<ResumeInst>(I)) { |
Bill Wendling | 7717e9f | 2012-01-27 02:02:24 +0000 | [diff] [blame] | 459 | insertCallSiteStore(RI, -1); |
Bill Wendling | 2e76ca9 | 2011-09-28 03:14:05 +0000 | [diff] [blame] | 460 | } |
Bill Wendling | 2e76ca9 | 2011-09-28 03:14:05 +0000 | [diff] [blame] | 461 | |
Bill Wendling | 899da52 | 2011-09-28 21:56:53 +0000 | [diff] [blame] | 462 | // Register the function context and make sure it's known to not throw |
Bill Wendling | 8faa30e | 2013-09-23 20:57:47 +0000 | [diff] [blame] | 463 | CallInst *Register = |
| 464 | CallInst::Create(RegisterFn, FuncCtx, "", EntryBB->getTerminator()); |
Bill Wendling | 899da52 | 2011-09-28 21:56:53 +0000 | [diff] [blame] | 465 | Register->setDoesNotThrow(); |
| 466 | |
Bob Wilson | 643e63c | 2011-11-16 07:12:00 +0000 | [diff] [blame] | 467 | // Following any allocas not in the entry block, update the saved SP in the |
| 468 | // jmpbuf to the new value. |
| 469 | for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { |
| 470 | if (BB == F.begin()) |
| 471 | continue; |
| 472 | for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) { |
| 473 | if (CallInst *CI = dyn_cast<CallInst>(I)) { |
| 474 | if (CI->getCalledFunction() != StackRestoreFn) |
| 475 | continue; |
| 476 | } else if (!isa<AllocaInst>(I)) { |
| 477 | continue; |
| 478 | } |
| 479 | Instruction *StackAddr = CallInst::Create(StackAddrFn, "sp"); |
| 480 | StackAddr->insertAfter(I); |
| 481 | Instruction *StoreStackAddr = new StoreInst(StackAddr, StackPtr, true); |
| 482 | StoreStackAddr->insertAfter(StackAddr); |
| 483 | } |
| 484 | } |
| 485 | |
Bill Wendling | 899da52 | 2011-09-28 21:56:53 +0000 | [diff] [blame] | 486 | // Finally, for any returns from this function, if this function contains an |
| 487 | // invoke, add a call to unregister the function context. |
| 488 | for (unsigned I = 0, E = Returns.size(); I != E; ++I) |
Bill Wendling | 6f3e73d | 2011-10-03 21:15:28 +0000 | [diff] [blame] | 489 | CallInst::Create(UnregisterFn, FuncCtx, "", Returns[I]); |
Bill Wendling | 899da52 | 2011-09-28 21:56:53 +0000 | [diff] [blame] | 490 | |
Bill Wendling | 2e76ca9 | 2011-09-28 03:14:05 +0000 | [diff] [blame] | 491 | return true; |
| 492 | } |
| 493 | |
Bill Wendling | 12e5adb | 2012-03-13 20:04:21 +0000 | [diff] [blame] | 494 | bool SjLjEHPrepare::runOnFunction(Function &F) { |
Bill Wendling | 38f86c5 | 2011-10-24 17:12:36 +0000 | [diff] [blame] | 495 | bool Res = setupEntryBlockAndCallSites(F); |
Jim Grosbach | 486be66 | 2009-08-17 16:41:22 +0000 | [diff] [blame] | 496 | return Res; |
| 497 | } |