-//===----------------------------------------------------------------------===//
-// CleanupReturnInst Class
-//===----------------------------------------------------------------------===//
-
-class CleanupReturnInst : public TerminatorInst {
- CleanupReturnInst(const CleanupReturnInst &RI);
-
-private:
- void init(Value *RetVal, BasicBlock *UnwindBB);
- CleanupReturnInst(LLVMContext &C, Value *RetVal, BasicBlock *UnwindBB,
- unsigned Values, Instruction *InsertBefore = nullptr);
- CleanupReturnInst(LLVMContext &C, Value *RetVal, BasicBlock *UnwindBB,
- unsigned Values, BasicBlock *InsertAtEnd);
-
- int getUnwindLabelOpIdx() const {
- assert(hasUnwindDest());
- return 0;
- }
-
- int getRetValOpIdx() const {
- assert(hasReturnValue());
- if (hasUnwindDest())
- return 1;
- return 0;
- }
-
-protected:
- // Note: Instruction needs to be a friend here to call cloneImpl.
- friend class Instruction;
- CleanupReturnInst *cloneImpl() const;
-
-public:
- static CleanupReturnInst *Create(LLVMContext &C,
- Value *RetVal = nullptr,
- BasicBlock *UnwindBB = nullptr,
- Instruction *InsertBefore = nullptr) {
- unsigned Values = 0;
- if (RetVal)
- ++Values;
- if (UnwindBB)
- ++Values;
- return new (Values)
- CleanupReturnInst(C, RetVal, UnwindBB, Values, InsertBefore);
- }
- static CleanupReturnInst *Create(LLVMContext &C, Value *RetVal,
- BasicBlock *UnwindBB,
- BasicBlock *InsertAtEnd) {
- unsigned Values = 0;
- if (RetVal)
- ++Values;
- if (UnwindBB)
- ++Values;
- return new (Values)
- CleanupReturnInst(C, RetVal, UnwindBB, Values, InsertAtEnd);
- }
-
- /// Provide fast operand accessors
- DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
-
- bool hasUnwindDest() const { return getSubclassDataFromInstruction() & 1; }
- bool unwindsToCaller() const { return !hasUnwindDest(); }
- bool hasReturnValue() const { return getSubclassDataFromInstruction() & 2; }
-
- /// Convenience accessor. Returns null if there is no return value.
- Value *getReturnValue() const {
- if (!hasReturnValue())
- return nullptr;
- return getOperand(getRetValOpIdx());
- }
- void setReturnValue(Value *RetVal) {
- assert(hasReturnValue());
- setOperand(getRetValOpIdx(), RetVal);
- }
-
- unsigned getNumSuccessors() const { return hasUnwindDest() ? 1 : 0; }
-
- BasicBlock *getUnwindDest() const;
- void setUnwindDest(BasicBlock *NewDest);
-
- // Methods for support type inquiry through isa, cast, and dyn_cast:
- static inline bool classof(const Instruction *I) {
- return (I->getOpcode() == Instruction::CleanupRet);
- }
- static inline bool classof(const Value *V) {
- return isa<Instruction>(V) && classof(cast<Instruction>(V));
- }
-
-private:
- BasicBlock *getSuccessorV(unsigned Idx) const override;
- unsigned getNumSuccessorsV() const override;
- void setSuccessorV(unsigned Idx, BasicBlock *B) override;
-
- // Shadow Instruction::setInstructionSubclassData with a private forwarding
- // method so that subclasses cannot accidentally use it.
- void setInstructionSubclassData(unsigned short D) {
- Instruction::setInstructionSubclassData(D);
- }
-};
-
-template <>
-struct OperandTraits<CleanupReturnInst>
- : public VariadicOperandTraits<CleanupReturnInst> {};
-
-DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CleanupReturnInst, Value)
-