Skip to content

Commit

Permalink
[WinEH] Handle nested landing pads in outlined catch handlers
Browse files Browse the repository at this point in the history
Differential Revision: http://reviews.llvm.org/D8596



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234041 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
andykaylor committed Apr 3, 2015
1 parent f4f021c commit 675e22e
Show file tree
Hide file tree
Showing 7 changed files with 281 additions and 91 deletions.
18 changes: 17 additions & 1 deletion include/llvm/CodeGen/WinEHFuncInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class BasicBlock;
class Constant;
class Function;
class GlobalValue;
class IntrinsicInst;
class LandingPadInst;
class MCSymbol;
class Value;
Expand Down Expand Up @@ -58,7 +59,8 @@ class CatchHandler : public ActionHandler {
public:
CatchHandler(BasicBlock *BB, Constant *Selector, BasicBlock *NextBB)
: ActionHandler(BB, ActionType::Catch), Selector(Selector),
NextBB(NextBB), ExceptionObjectVar(nullptr) {}
NextBB(NextBB), ExceptionObjectVar(nullptr),
ExceptionObjectIndex(-1) {}

// Method for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ActionHandler *H) {
Expand All @@ -72,14 +74,24 @@ class CatchHandler : public ActionHandler {
TinyPtrVector<BasicBlock *> &getReturnTargets() { return ReturnTargets; }

void setExceptionVar(const Value *Val) { ExceptionObjectVar = Val; }
void setExceptionVarIndex(int Index) { ExceptionObjectIndex = Index; }
void setReturnTargets(TinyPtrVector<BasicBlock *> &Targets) {
ReturnTargets = Targets;
}

private:
Constant *Selector;
BasicBlock *NextBB;
// While catch handlers are being outlined the ExceptionObjectVar field will
// be populated with the instruction in the parent frame that corresponds
// to the exception object (or nullptr if the catch does not use an
// exception object) and the ExceptionObjectIndex field will be -1.
// When the parseEHActions function is called to populate a vector of
// instances of this class, the ExceptionObjectVar field will be nullptr
// and the ExceptionObjectIndex will be the index of the exception object in
// the parent function's frameescape block.
const Value *ExceptionObjectVar;
int ExceptionObjectIndex;
TinyPtrVector<BasicBlock *> ReturnTargets;
};

Expand All @@ -93,6 +105,10 @@ class CleanupHandler : public ActionHandler {
}
};

void parseEHActions(const IntrinsicInst *II,
SmallVectorImpl<ActionHandler *> &Actions);


// The following structs respresent the .xdata for functions using C++
// exceptions on Windows.

Expand Down
28 changes: 0 additions & 28 deletions lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ struct WinEHNumbering {
return HandlerStack.empty() ? -1 : HandlerStack.back()->getEHState();
}

void parseEHActions(const IntrinsicInst *II,
SmallVectorImpl<ActionHandler *> &Actions);
void createUnwindMapEntry(int ToState, ActionHandler *AH);
void createTryBlockMapEntry(int TryLow, int TryHigh,
ArrayRef<CatchHandler *> Handlers);
Expand Down Expand Up @@ -287,32 +285,6 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
}
}

void WinEHNumbering::parseEHActions(const IntrinsicInst *II,
SmallVectorImpl<ActionHandler *> &Actions) {
for (unsigned I = 0, E = II->getNumArgOperands(); I != E;) {
uint64_t ActionKind =
cast<ConstantInt>(II->getArgOperand(I))->getZExtValue();
if (ActionKind == /*catch=*/1) {
auto *Selector = cast<Constant>(II->getArgOperand(I + 1));
Value *CatchObject = II->getArgOperand(I + 2);
Constant *Handler = cast<Constant>(II->getArgOperand(I + 3));
I += 4;
auto *CH = new CatchHandler(/*BB=*/nullptr, Selector, /*NextBB=*/nullptr);
CH->setExceptionVar(CatchObject);
CH->setHandlerBlockOrFunc(Handler);
Actions.push_back(CH);
} else {
assert(ActionKind == 0 && "expected a cleanup or a catch action!");
Constant *Handler = cast<Constant>(II->getArgOperand(I + 1));
I += 2;
auto *CH = new CleanupHandler(/*BB=*/nullptr);
CH->setHandlerBlockOrFunc(Handler);
Actions.push_back(CH);
}
}
std::reverse(Actions.begin(), Actions.end());
}

void WinEHNumbering::createUnwindMapEntry(int ToState, ActionHandler *AH) {
WinEHUnwindMapEntry UME;
UME.ToState = ToState;
Expand Down
Loading

0 comments on commit 675e22e

Please sign in to comment.