-class WinEHCloningDirectorBase : public CloningDirector {
-public:
- WinEHCloningDirectorBase(Function *HandlerFn, Value *ParentFP,
- FrameVarInfoMap &VarInfo, LandingPadMap &LPadMap)
- : Materializer(HandlerFn, ParentFP, VarInfo),
- SelectorIDType(Type::getInt32Ty(HandlerFn->getContext())),
- Int8PtrType(Type::getInt8PtrTy(HandlerFn->getContext())),
- LPadMap(LPadMap), ParentFP(ParentFP) {}
-
- CloningAction handleInstruction(ValueToValueMapTy &VMap,
- const Instruction *Inst,
- BasicBlock *NewBB) override;
-
- virtual CloningAction handleBeginCatch(ValueToValueMapTy &VMap,
- const Instruction *Inst,
- BasicBlock *NewBB) = 0;
- virtual CloningAction handleEndCatch(ValueToValueMapTy &VMap,
- const Instruction *Inst,
- BasicBlock *NewBB) = 0;
- virtual CloningAction handleTypeIdFor(ValueToValueMapTy &VMap,
- const Instruction *Inst,
- BasicBlock *NewBB) = 0;
- virtual CloningAction handleInvoke(ValueToValueMapTy &VMap,
- const InvokeInst *Invoke,
- BasicBlock *NewBB) = 0;
- virtual CloningAction handleResume(ValueToValueMapTy &VMap,
- const ResumeInst *Resume,
- BasicBlock *NewBB) = 0;
- virtual CloningAction handleCompare(ValueToValueMapTy &VMap,
- const CmpInst *Compare,
- BasicBlock *NewBB) = 0;
- virtual CloningAction handleLandingPad(ValueToValueMapTy &VMap,
- const LandingPadInst *LPad,
- BasicBlock *NewBB) = 0;
-
- ValueMaterializer *getValueMaterializer() override { return &Materializer; }
-
-protected:
- WinEHFrameVariableMaterializer Materializer;
- Type *SelectorIDType;
- Type *Int8PtrType;
- LandingPadMap &LPadMap;
-
- /// The value representing the parent frame pointer.
- Value *ParentFP;
-};
-
-class WinEHCatchDirector : public WinEHCloningDirectorBase {
-public:
- WinEHCatchDirector(
- Function *CatchFn, Value *ParentFP, Value *Selector,
- FrameVarInfoMap &VarInfo, LandingPadMap &LPadMap,
- DenseMap<LandingPadInst *, const LandingPadInst *> &NestedLPads)
- : WinEHCloningDirectorBase(CatchFn, ParentFP, VarInfo, LPadMap),
- CurrentSelector(Selector->stripPointerCasts()),
- ExceptionObjectVar(nullptr), NestedLPtoOriginalLP(NestedLPads) {}
-
- CloningAction handleBeginCatch(ValueToValueMapTy &VMap,
- const Instruction *Inst,
- BasicBlock *NewBB) override;
- CloningAction handleEndCatch(ValueToValueMapTy &VMap, const Instruction *Inst,
- BasicBlock *NewBB) override;
- CloningAction handleTypeIdFor(ValueToValueMapTy &VMap,
- const Instruction *Inst,
- BasicBlock *NewBB) override;
- CloningAction handleInvoke(ValueToValueMapTy &VMap, const InvokeInst *Invoke,
- BasicBlock *NewBB) override;
- CloningAction handleResume(ValueToValueMapTy &VMap, const ResumeInst *Resume,
- BasicBlock *NewBB) override;
- CloningAction handleCompare(ValueToValueMapTy &VMap, const CmpInst *Compare,
- BasicBlock *NewBB) override;
- CloningAction handleLandingPad(ValueToValueMapTy &VMap,
- const LandingPadInst *LPad,
- BasicBlock *NewBB) override;
-
- Value *getExceptionVar() { return ExceptionObjectVar; }
- TinyPtrVector<BasicBlock *> &getReturnTargets() { return ReturnTargets; }
-
-private:
- Value *CurrentSelector;
-
- Value *ExceptionObjectVar;
- TinyPtrVector<BasicBlock *> ReturnTargets;
-
- // This will be a reference to the field of the same name in the WinEHPrepare
- // object which instantiates this WinEHCatchDirector object.
- DenseMap<LandingPadInst *, const LandingPadInst *> &NestedLPtoOriginalLP;
-};
-
-class WinEHCleanupDirector : public WinEHCloningDirectorBase {
-public:
- WinEHCleanupDirector(Function *CleanupFn, Value *ParentFP,
- FrameVarInfoMap &VarInfo, LandingPadMap &LPadMap)
- : WinEHCloningDirectorBase(CleanupFn, ParentFP, VarInfo,
- LPadMap) {}
-
- CloningAction handleBeginCatch(ValueToValueMapTy &VMap,
- const Instruction *Inst,
- BasicBlock *NewBB) override;
- CloningAction handleEndCatch(ValueToValueMapTy &VMap, const Instruction *Inst,
- BasicBlock *NewBB) override;
- CloningAction handleTypeIdFor(ValueToValueMapTy &VMap,
- const Instruction *Inst,
- BasicBlock *NewBB) override;
- CloningAction handleInvoke(ValueToValueMapTy &VMap, const InvokeInst *Invoke,
- BasicBlock *NewBB) override;
- CloningAction handleResume(ValueToValueMapTy &VMap, const ResumeInst *Resume,
- BasicBlock *NewBB) override;
- CloningAction handleCompare(ValueToValueMapTy &VMap, const CmpInst *Compare,
- BasicBlock *NewBB) override;
- CloningAction handleLandingPad(ValueToValueMapTy &VMap,
- const LandingPadInst *LPad,
- BasicBlock *NewBB) override;
-};
-
-class LandingPadActions {
-public:
- LandingPadActions() : HasCleanupHandlers(false) {}
-
- void insertCatchHandler(CatchHandler *Action) { Actions.push_back(Action); }
- void insertCleanupHandler(CleanupHandler *Action) {
- Actions.push_back(Action);
- HasCleanupHandlers = true;
- }
-
- bool includesCleanup() const { return HasCleanupHandlers; }
-
- SmallVectorImpl<ActionHandler *> &actions() { return Actions; }
- SmallVectorImpl<ActionHandler *>::iterator begin() { return Actions.begin(); }
- SmallVectorImpl<ActionHandler *>::iterator end() { return Actions.end(); }
-
-private:
- // Note that this class does not own the ActionHandler objects in this vector.
- // The ActionHandlers are owned by the CatchHandlerMap and CleanupHandlerMap
- // in the WinEHPrepare class.
- SmallVector<ActionHandler *, 4> Actions;
- bool HasCleanupHandlers;