diff options
author | Shoaib Meenai <smeenai@fb.com> | 2018-03-20 20:45:41 +0000 |
---|---|---|
committer | Shoaib Meenai <smeenai@fb.com> | 2018-03-20 20:45:41 +0000 |
commit | 3f689c86323981117b318c618510f7b4bed909e0 (patch) | |
tree | 68f09fcfe1f362106915fb877db0e146f1b3bca3 /llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp | |
parent | 8ef820a6ede43802172161d2477c2cf9cd066790 (diff) | |
download | bcm5719-llvm-3f689c86323981117b318c618510f7b4bed909e0.tar.gz bcm5719-llvm-3f689c86323981117b318c618510f7b4bed909e0.zip |
[ObjCARC] Add funclet token to ARC marker
The inline assembly generated for the ARC autorelease elision marker
must have a funclet token if it's emitted inside a funclet, otherwise
the inline assembly (and all subsequent code in the funclet) will be
marked unreachable by WinEHPrepare.
Note that this only applies for the non-O0 case, since at O0, clang
emits the autorelease elision marker itself rather than deferring to the
backend. The fix for clang is handled in a separate change.
Differential Revision: https://reviews.llvm.org/D44641
llvm-svn: 328042
Diffstat (limited to 'llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp')
-rw-r--r-- | llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp index 5deb39449e9..9898c131c1f 100644 --- a/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp +++ b/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp @@ -31,6 +31,7 @@ #include "ObjCARC.h" #include "ProvenanceAnalysis.h" #include "llvm/ADT/Statistic.h" +#include "llvm/Analysis/EHPersonalities.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/InlineAsm.h" #include "llvm/IR/Operator.h" @@ -74,11 +75,13 @@ namespace { SmallPtrSet<CallInst *, 8> StoreStrongCalls; /// Returns true if we eliminated Inst. - bool tryToPeepholeInstruction(Function &F, Instruction *Inst, - inst_iterator &Iter, - SmallPtrSetImpl<Instruction *> &DepInsts, - SmallPtrSetImpl<const BasicBlock *> &Visited, - bool &TailOkForStoreStrong); + bool + tryToPeepholeInstruction(Function &F, Instruction *Inst, + inst_iterator &Iter, + SmallPtrSetImpl<Instruction *> &DepInsts, + SmallPtrSetImpl<const BasicBlock *> &Visited, + bool &TailOkForStoreStrong, + DenseMap<BasicBlock *, ColorVector> &BlockColors); bool optimizeRetainCall(Function &F, Instruction *Retain); @@ -407,7 +410,8 @@ bool ObjCARCContract::tryToPeepholeInstruction( Function &F, Instruction *Inst, inst_iterator &Iter, SmallPtrSetImpl<Instruction *> &DependingInsts, SmallPtrSetImpl<const BasicBlock *> &Visited, - bool &TailOkForStoreStrongs) { + bool &TailOkForStoreStrongs, + DenseMap<BasicBlock *, ColorVector> &BlockColors) { // Only these library routines return their argument. In particular, // objc_retainBlock does not necessarily return its argument. ARCInstKind Class = GetBasicARCInstKind(Inst); @@ -457,7 +461,17 @@ bool ObjCARCContract::tryToPeepholeInstruction( /*isVarArg=*/false), RVInstMarker->getString(), /*Constraints=*/"", /*hasSideEffects=*/true); - CallInst::Create(IA, "", Inst); + + SmallVector<OperandBundleDef, 1> OpBundles; + if (!BlockColors.empty()) { + const ColorVector &CV = BlockColors.find(Inst->getParent())->second; + assert(CV.size() == 1 && "non-unique color for block!"); + Instruction *EHPad = CV.front()->getFirstNonPHI(); + if (EHPad->isEHPad()) + OpBundles.emplace_back("funclet", EHPad); + } + + CallInst::Create(IA, None, OpBundles, "", Inst); } decline_rv_optimization: return false; @@ -518,6 +532,11 @@ bool ObjCARCContract::runOnFunction(Function &F) { PA.setAA(&getAnalysis<AAResultsWrapperPass>().getAAResults()); + DenseMap<BasicBlock *, ColorVector> BlockColors; + if (F.hasPersonalityFn() && + isFuncletEHPersonality(classifyEHPersonality(F.getPersonalityFn()))) + BlockColors = colorEHFunclets(F); + DEBUG(llvm::dbgs() << "**** ObjCARC Contract ****\n"); // Track whether it's ok to mark objc_storeStrong calls with the "tail" @@ -541,7 +560,7 @@ bool ObjCARCContract::runOnFunction(Function &F) { // First try to peephole Inst. If there is nothing further we can do in // terms of undoing objc-arc-expand, process the next inst. if (tryToPeepholeInstruction(F, Inst, I, DependingInstructions, Visited, - TailOkForStoreStrongs)) + TailOkForStoreStrongs, BlockColors)) continue; // Otherwise, try to undo objc-arc-expand. |