diff options
author | Arnold Schwaighofer <aschwaighofer@apple.com> | 2018-03-14 15:44:07 +0000 |
---|---|---|
committer | Arnold Schwaighofer <aschwaighofer@apple.com> | 2018-03-14 15:44:07 +0000 |
commit | bf1638daa81cca23073649ec57b21f94c8a57533 (patch) | |
tree | be0c076681f3286afaa111c65eb17e0a1d296c7c /llvm/lib | |
parent | 86ef9ab28f1cb73b792b38a0613823450dbdfe4e (diff) | |
download | bcm5719-llvm-bf1638daa81cca23073649ec57b21f94c8a57533.tar.gz bcm5719-llvm-bf1638daa81cca23073649ec57b21f94c8a57533.zip |
SjLjEHPrepare: Don't reg-to-mem swifterror values
swifterror llvm values model the swifterror register as memory at the
LLVM IR level. ISel will perform adhoc mem-to-reg on them. swifterror
values are constraint in how they can be used. Spilling them to memory
is not allowed.
SjLjEHPrepare tried to lower swifterror values to memory which is
unecessary since the back-end will spill and reload the register as
neccessary (as long as clobbering calls are marked as such which is the
case here) and further leads to invalid IR because swifterror values
can't be stored to memory.
rdar://38164004
llvm-svn: 327521
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/SjLjEHPrepare.cpp | 29 |
1 files changed, 7 insertions, 22 deletions
diff --git a/llvm/lib/CodeGen/SjLjEHPrepare.cpp b/llvm/lib/CodeGen/SjLjEHPrepare.cpp index 17a3a84ecda..539bbb6ba88 100644 --- a/llvm/lib/CodeGen/SjLjEHPrepare.cpp +++ b/llvm/lib/CodeGen/SjLjEHPrepare.cpp @@ -64,7 +64,6 @@ public: private: bool setupEntryBlockAndCallSites(Function &F); - bool undoSwiftErrorSelect(Function &F); void substituteLPadValues(LandingPadInst *LPI, Value *ExnVal, Value *SelVal); Value *setupFunctionContext(Function &F, ArrayRef<LandingPadInst *> LPads); void lowerIncomingArguments(Function &F); @@ -233,6 +232,13 @@ void SjLjEHPrepare::lowerIncomingArguments(Function &F) { assert(AfterAllocaInsPt != F.front().end()); for (auto &AI : F.args()) { + // Swift error really is a register that we model as memory -- instruction + // selection will perform mem-to-reg for us and spill/reload appropriately + // around calls that clobber it. There is no need to spill this + // value to the stack and doing so would not be allowed. + if (AI.isSwiftError()) + continue; + Type *Ty = AI.getType(); // Use 'select i8 true, %arg, undef' to simulate a 'no-op' instruction. @@ -462,25 +468,6 @@ bool SjLjEHPrepare::setupEntryBlockAndCallSites(Function &F) { return true; } -bool SjLjEHPrepare::undoSwiftErrorSelect(Function &F) { - // We have inserted dummy copies 'select true, arg, undef' in the entry block - // for arguments to simplify this pass. - // swifterror arguments cannot be used in this way. Undo the select for the - // swifterror argument. - for (auto &AI : F.args()) { - if (AI.isSwiftError()) { - assert(AI.hasOneUse() && "Must have converted the argument to a select"); - auto *Select = dyn_cast<SelectInst>(AI.use_begin()->getUser()); - assert(Select && "There must be single select user"); - auto *OrigSwiftError = cast<Argument>(Select->getTrueValue()); - Select->replaceAllUsesWith(OrigSwiftError); - Select->eraseFromParent(); - return true; - } - } - return false; -} - bool SjLjEHPrepare::runOnFunction(Function &F) { Module &M = *F.getParent(); RegisterFn = M.getOrInsertFunction( @@ -499,7 +486,5 @@ bool SjLjEHPrepare::runOnFunction(Function &F) { FuncCtxFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_functioncontext); bool Res = setupEntryBlockAndCallSites(F); - if (Res) - Res |= undoSwiftErrorSelect(F); return Res; } |