aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/SjLjEHPrepare.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/CodeGen/SjLjEHPrepare.cpp')
-rw-r--r--lib/CodeGen/SjLjEHPrepare.cpp35
1 files changed, 10 insertions, 25 deletions
diff --git a/lib/CodeGen/SjLjEHPrepare.cpp b/lib/CodeGen/SjLjEHPrepare.cpp
index 17a3a84ecda5..5d2669f5ae92 100644
--- a/lib/CodeGen/SjLjEHPrepare.cpp
+++ b/lib/CodeGen/SjLjEHPrepare.cpp
@@ -16,6 +16,7 @@
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
+#include "llvm/Transforms/Utils/Local.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
@@ -27,7 +28,6 @@
#include "llvm/Pass.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
-#include "llvm/Transforms/Utils/Local.h"
using namespace llvm;
#define DEBUG_TYPE "sjljehprepare"
@@ -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.
@@ -301,8 +307,8 @@ void SjLjEHPrepare::lowerAcrossUnwindEdges(Function &F,
for (InvokeInst *Invoke : Invokes) {
BasicBlock *UnwindBlock = Invoke->getUnwindDest();
if (UnwindBlock != &BB && LiveBBs.count(UnwindBlock)) {
- DEBUG(dbgs() << "SJLJ Spill: " << Inst << " around "
- << UnwindBlock->getName() << "\n");
+ LLVM_DEBUG(dbgs() << "SJLJ Spill: " << Inst << " around "
+ << UnwindBlock->getName() << "\n");
NeedsSpill = true;
break;
}
@@ -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;
}