llvm.org GIT mirror llvm / 09ebf7a
[TI removal] Remove `TerminatorInst` from the IR type system! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@344769 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth a year ago
3 changed file(s) with 84 addition(s) and 131 deletion(s). Raw diff Collapse all Expand all
4343 #include
4444
4545 namespace llvm {
46
47 //===----------------------------------------------------------------------===//
48 // TerminatorInst Class
49 //===----------------------------------------------------------------------===//
50
51 /// Subclasses of this class are all able to terminate a basic
52 /// block. Thus, these are all the flow control type of operations.
53 ///
54 class TerminatorInst : public Instruction {
55 protected:
56 TerminatorInst(Type *Ty, Instruction::TermOps iType,
57 Use *Ops, unsigned NumOps,
58 Instruction *InsertBefore = nullptr)
59 : Instruction(Ty, iType, Ops, NumOps, InsertBefore) {}
60
61 TerminatorInst(Type *Ty, Instruction::TermOps iType,
62 Use *Ops, unsigned NumOps, BasicBlock *InsertAtEnd)
63 : Instruction(Ty, iType, Ops, NumOps, InsertAtEnd) {}
64
65 public:
66 // Methods for support type inquiry through isa, cast, and dyn_cast:
67 static bool classof(const Instruction *I) {
68 return I->isTerminator();
69 }
70 static bool classof(const Value *V) {
71 return isa(V) && classof(cast(V));
72 }
73 };
7446
7547 //===----------------------------------------------------------------------===//
7648 // UnaryInstruction Class
13561356
13571357 template struct CallBaseParent { using type = Instruction; };
13581358
1359 template <> struct CallBaseParent { using type = TerminatorInst; };
1360
13611359 //===----------------------------------------------------------------------===//
13621360 /// Base class for all callable instructions (InvokeInst and CallInst)
13631361 /// Holds everything related to calling a function, abstracting from the base
32643262 /// Return a value (possibly void), from a function. Execution
32653263 /// does not continue in this function any longer.
32663264 ///
3267 class ReturnInst : public TerminatorInst {
3265 class ReturnInst : public Instruction {
32683266 ReturnInst(const ReturnInst &RI);
32693267
32703268 private:
33243322 }
33253323
33263324 private:
3327 friend TerminatorInst;
3328
33293325 BasicBlock *getSuccessor(unsigned idx) const {
33303326 llvm_unreachable("ReturnInst has no successors!");
33313327 }
33483344 //===---------------------------------------------------------------------------
33493345 /// Conditional or Unconditional Branch instruction.
33503346 ///
3351 class BranchInst : public TerminatorInst {
3347 class BranchInst : public Instruction {
33523348 /// Ops list - Branches are strange. The operands are ordered:
33533349 /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
33543350 /// they don't have to check for cond/uncond branchness. These are mostly
34923488 //===---------------------------------------------------------------------------
34933489 /// Multiway switch
34943490 ///
3495 class SwitchInst : public TerminatorInst {
3491 class SwitchInst : public Instruction {
34963492 unsigned ReservedSpace;
34973493
34983494 // Operand[0] = Value to switch on
35753571 /// Returns number of current case.
35763572 unsigned getCaseIndex() const { return Index; }
35773573
3578 /// Returns TerminatorInst's successor index for current case successor.
3574 /// Returns successor index for current case successor.
35793575 unsigned getSuccessorIndex() const {
35803576 assert(((unsigned)Index == DefaultPseudoIndex ||
35813577 (unsigned)Index < SI->getNumCases()) &&
36313627 CaseIteratorImpl(SwitchInstT *SI, unsigned CaseNum) : Case(SI, CaseNum) {}
36323628
36333629 /// Initializes case iterator for given SwitchInst and for given
3634 /// TerminatorInst's successor index.
3630 /// successor index.
36353631 static CaseIteratorImpl fromSuccessorIndex(SwitchInstT *SI,
36363632 unsigned SuccessorIndex) {
36373633 assert(SuccessorIndex < SI->getNumSuccessors() &&
38493845 //===---------------------------------------------------------------------------
38503846 /// Indirect Branch Instruction.
38513847 ///
3852 class IndirectBrInst : public TerminatorInst {
3848 class IndirectBrInst : public Instruction {
38533849 unsigned ReservedSpace;
38543850
38553851 // Operand[0] = Address to jump to
42254221 //===---------------------------------------------------------------------------
42264222 /// Resume the propagation of an exception.
42274223 ///
4228 class ResumeInst : public TerminatorInst {
4224 class ResumeInst : public Instruction {
42294225 ResumeInst(const ResumeInst &RI);
42304226
42314227 explicit ResumeInst(Value *Exn, Instruction *InsertBefore=nullptr);
42634259 }
42644260
42654261 private:
4266 friend TerminatorInst;
4267
42684262 BasicBlock *getSuccessor(unsigned idx) const {
42694263 llvm_unreachable("ResumeInst has no successors!");
42704264 }
42844278 //===----------------------------------------------------------------------===//
42854279 // CatchSwitchInst Class
42864280 //===----------------------------------------------------------------------===//
4287 class CatchSwitchInst : public TerminatorInst {
4281 class CatchSwitchInst : public Instruction {
42884282 /// The number of operands actually allocated. NumOperands is
42894283 /// the number actually in use.
42904284 unsigned ReservedSpace;
45504544 // CatchReturnInst Class
45514545 //===----------------------------------------------------------------------===//
45524546
4553 class CatchReturnInst : public TerminatorInst {
4547 class CatchReturnInst : public Instruction {
45544548 CatchReturnInst(const CatchReturnInst &RI);
45554549 CatchReturnInst(Value *CatchPad, BasicBlock *BB, Instruction *InsertBefore);
45564550 CatchReturnInst(Value *CatchPad, BasicBlock *BB, BasicBlock *InsertAtEnd);
46104604 }
46114605
46124606 private:
4613 friend TerminatorInst;
4614
46154607 BasicBlock *getSuccessor(unsigned Idx) const {
46164608 assert(Idx < getNumSuccessors() && "Successor # out of range for catchret!");
46174609 return getSuccessor();
46334625 // CleanupReturnInst Class
46344626 //===----------------------------------------------------------------------===//
46354627
4636 class CleanupReturnInst : public TerminatorInst {
4628 class CleanupReturnInst : public Instruction {
46374629 private:
46384630 CleanupReturnInst(const CleanupReturnInst &RI);
46394631 CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB, unsigned Values,
47064698 }
47074699
47084700 private:
4709 friend TerminatorInst;
4710
47114701 BasicBlock *getSuccessor(unsigned Idx) const {
47124702 assert(Idx == 0);
47134703 return getUnwindDest();
47404730 /// presence of this instruction indicates some higher level knowledge that the
47414731 /// end of the block cannot be reached.
47424732 ///
4743 class UnreachableInst : public TerminatorInst {
4733 class UnreachableInst : public Instruction {
47444734 protected:
47454735 // Note: Instruction needs to be a friend here to call cloneImpl.
47464736 friend class Instruction;
47674757 }
47684758
47694759 private:
4770 friend TerminatorInst;
4771
47724760 BasicBlock *getSuccessor(unsigned idx) const {
47734761 llvm_unreachable("UnreachableInst has no successors!");
47744762 }
621621 //===----------------------------------------------------------------------===//
622622
623623 ReturnInst::ReturnInst(const ReturnInst &RI)
624 : TerminatorInst(Type::getVoidTy(RI.getContext()), Instruction::Ret,
625 OperandTraits::op_end(this) -
626 RI.getNumOperands(),
627 RI.getNumOperands()) {
624 : Instruction(Type::getVoidTy(RI.getContext()), Instruction::Ret,
625 OperandTraits::op_end(this) - RI.getNumOperands(),
626 RI.getNumOperands()) {
628627 if (RI.getNumOperands())
629628 Op<0>() = RI.Op<0>();
630629 SubclassOptionalData = RI.SubclassOptionalData;
631630 }
632631
633632 ReturnInst::ReturnInst(LLVMContext &C, Value *retVal, Instruction *InsertBefore)
634 : TerminatorInst(Type::getVoidTy(C), Instruction::Ret,
635 OperandTraits::op_end(this) - !!retVal, !!retVal,
636 InsertBefore) {
633 : Instruction(Type::getVoidTy(C), Instruction::Ret,
634 OperandTraits::op_end(this) - !!retVal, !!retVal,
635 InsertBefore) {
637636 if (retVal)
638637 Op<0>() = retVal;
639638 }
640639
641640 ReturnInst::ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd)
642 : TerminatorInst(Type::getVoidTy(C), Instruction::Ret,
643 OperandTraits::op_end(this) - !!retVal, !!retVal,
644 InsertAtEnd) {
641 : Instruction(Type::getVoidTy(C), Instruction::Ret,
642 OperandTraits::op_end(this) - !!retVal, !!retVal,
643 InsertAtEnd) {
645644 if (retVal)
646645 Op<0>() = retVal;
647646 }
648647
649648 ReturnInst::ReturnInst(LLVMContext &Context, BasicBlock *InsertAtEnd)
650 : TerminatorInst(Type::getVoidTy(Context), Instruction::Ret,
651 OperandTraits::op_end(this), 0, InsertAtEnd) {
652 }
649 : Instruction(Type::getVoidTy(Context), Instruction::Ret,
650 OperandTraits::op_end(this), 0, InsertAtEnd) {}
653651
654652 //===----------------------------------------------------------------------===//
655653 // ResumeInst Implementation
656654 //===----------------------------------------------------------------------===//
657655
658656 ResumeInst::ResumeInst(const ResumeInst &RI)
659 : TerminatorInst(Type::getVoidTy(RI.getContext()), Instruction::Resume,
660 OperandTraits::op_begin(this), 1) {
657 : Instruction(Type::getVoidTy(RI.getContext()), Instruction::Resume,
658 OperandTraits::op_begin(this), 1) {
661659 Op<0>() = RI.Op<0>();
662660 }
663661
664662 ResumeInst::ResumeInst(Value *Exn, Instruction *InsertBefore)
665 : TerminatorInst(Type::getVoidTy(Exn->getContext()), Instruction::Resume,
666 OperandTraits::op_begin(this), 1, InsertBefore) {
663 : Instruction(Type::getVoidTy(Exn->getContext()), Instruction::Resume,
664 OperandTraits::op_begin(this), 1, InsertBefore) {
667665 Op<0>() = Exn;
668666 }
669667
670668 ResumeInst::ResumeInst(Value *Exn, BasicBlock *InsertAtEnd)
671 : TerminatorInst(Type::getVoidTy(Exn->getContext()), Instruction::Resume,
672 OperandTraits::op_begin(this), 1, InsertAtEnd) {
669 : Instruction(Type::getVoidTy(Exn->getContext()), Instruction::Resume,
670 OperandTraits::op_begin(this), 1, InsertAtEnd) {
673671 Op<0>() = Exn;
674672 }
675673
678676 //===----------------------------------------------------------------------===//
679677
680678 CleanupReturnInst::CleanupReturnInst(const CleanupReturnInst &CRI)
681 : TerminatorInst(CRI.getType(), Instruction::CleanupRet,
682 OperandTraits::op_end(this) -
683 CRI.getNumOperands(),
684 CRI.getNumOperands()) {
679 : Instruction(CRI.getType(), Instruction::CleanupRet,
680 OperandTraits::op_end(this) -
681 CRI.getNumOperands(),
682 CRI.getNumOperands()) {
685683 setInstructionSubclassData(CRI.getSubclassDataFromInstruction());
686684 Op<0>() = CRI.Op<0>();
687685 if (CRI.hasUnwindDest())
699697
700698 CleanupReturnInst::CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB,
701699 unsigned Values, Instruction *InsertBefore)
702 : TerminatorInst(Type::getVoidTy(CleanupPad->getContext()),
703 Instruction::CleanupRet,
704 OperandTraits::op_end(this) - Values,
705 Values, InsertBefore) {
700 : Instruction(Type::getVoidTy(CleanupPad->getContext()),
701 Instruction::CleanupRet,
702 OperandTraits::op_end(this) - Values,
703 Values, InsertBefore) {
706704 init(CleanupPad, UnwindBB);
707705 }
708706
709707 CleanupReturnInst::CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB,
710708 unsigned Values, BasicBlock *InsertAtEnd)
711 : TerminatorInst(Type::getVoidTy(CleanupPad->getContext()),
712 Instruction::CleanupRet,
713 OperandTraits::op_end(this) - Values,
714 Values, InsertAtEnd) {
709 : Instruction(Type::getVoidTy(CleanupPad->getContext()),
710 Instruction::CleanupRet,
711 OperandTraits::op_end(this) - Values,
712 Values, InsertAtEnd) {
715713 init(CleanupPad, UnwindBB);
716714 }
717715
724722 }
725723
726724 CatchReturnInst::CatchReturnInst(const CatchReturnInst &CRI)
727 : TerminatorInst(Type::getVoidTy(CRI.getContext()), Instruction::CatchRet,
728 OperandTraits::op_begin(this), 2) {
725 : Instruction(Type::getVoidTy(CRI.getContext()), Instruction::CatchRet,
726 OperandTraits::op_begin(this), 2) {
729727 Op<0>() = CRI.Op<0>();
730728 Op<1>() = CRI.Op<1>();
731729 }
732730
733731 CatchReturnInst::CatchReturnInst(Value *CatchPad, BasicBlock *BB,
734732 Instruction *InsertBefore)
735 : TerminatorInst(Type::getVoidTy(BB->getContext()), Instruction::CatchRet,
736 OperandTraits::op_begin(this), 2,
737 InsertBefore) {
733 : Instruction(Type::getVoidTy(BB->getContext()), Instruction::CatchRet,
734 OperandTraits::op_begin(this), 2,
735 InsertBefore) {
738736 init(CatchPad, BB);
739737 }
740738
741739 CatchReturnInst::CatchReturnInst(Value *CatchPad, BasicBlock *BB,
742740 BasicBlock *InsertAtEnd)
743 : TerminatorInst(Type::getVoidTy(BB->getContext()), Instruction::CatchRet,
744 OperandTraits::op_begin(this), 2,
745 InsertAtEnd) {
741 : Instruction(Type::getVoidTy(BB->getContext()), Instruction::CatchRet,
742 OperandTraits::op_begin(this), 2,
743 InsertAtEnd) {
746744 init(CatchPad, BB);
747745 }
748746
754752 unsigned NumReservedValues,
755753 const Twine &NameStr,
756754 Instruction *InsertBefore)
757 : TerminatorInst(ParentPad->getType(), Instruction::CatchSwitch, nullptr, 0,
758 InsertBefore) {
755 : Instruction(ParentPad->getType(), Instruction::CatchSwitch, nullptr, 0,
756 InsertBefore) {
759757 if (UnwindDest)
760758 ++NumReservedValues;
761759 init(ParentPad, UnwindDest, NumReservedValues + 1);
765763 CatchSwitchInst::CatchSwitchInst(Value *ParentPad, BasicBlock *UnwindDest,
766764 unsigned NumReservedValues,
767765 const Twine &NameStr, BasicBlock *InsertAtEnd)
768 : TerminatorInst(ParentPad->getType(), Instruction::CatchSwitch, nullptr, 0,
769 InsertAtEnd) {
766 : Instruction(ParentPad->getType(), Instruction::CatchSwitch, nullptr, 0,
767 InsertAtEnd) {
770768 if (UnwindDest)
771769 ++NumReservedValues;
772770 init(ParentPad, UnwindDest, NumReservedValues + 1);
774772 }
775773
776774 CatchSwitchInst::CatchSwitchInst(const CatchSwitchInst &CSI)
777 : TerminatorInst(CSI.getType(), Instruction::CatchSwitch, nullptr,
778 CSI.getNumOperands()) {
775 : Instruction(CSI.getType(), Instruction::CatchSwitch, nullptr,
776 CSI.getNumOperands()) {
779777 init(CSI.getParentPad(), CSI.getUnwindDest(), CSI.getNumOperands());
780778 setNumHungOffUseOperands(ReservedSpace);
781779 Use *OL = getOperandList();
873871
874872 UnreachableInst::UnreachableInst(LLVMContext &Context,
875873 Instruction *InsertBefore)
876 : TerminatorInst(Type::getVoidTy(Context), Instruction::Unreachable,
877 nullptr, 0, InsertBefore) {
878 }
874 : Instruction(Type::getVoidTy(Context), Instruction::Unreachable, nullptr,
875 0, InsertBefore) {}
879876 UnreachableInst::UnreachableInst(LLVMContext &Context, BasicBlock *InsertAtEnd)
880 : TerminatorInst(Type::getVoidTy(Context), Instruction::Unreachable,
881 nullptr, 0, InsertAtEnd) {
882 }
877 : Instruction(Type::getVoidTy(Context), Instruction::Unreachable, nullptr,
878 0, InsertAtEnd) {}
883879
884880 //===----------------------------------------------------------------------===//
885881 // BranchInst Implementation
892888 }
893889
894890 BranchInst::BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore)
895 : TerminatorInst(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
896 OperandTraits::op_end(this) - 1,
897 1, InsertBefore) {
891 : Instruction(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
892 OperandTraits::op_end(this) - 1, 1,
893 InsertBefore) {
898894 assert(IfTrue && "Branch destination may not be null!");
899895 Op<-1>() = IfTrue;
900896 }
901897
902898 BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
903899 Instruction *InsertBefore)
904 : TerminatorInst(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
905 OperandTraits::op_end(this) - 3,
906 3, InsertBefore) {
900 : Instruction(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
901 OperandTraits::op_end(this) - 3, 3,
902 InsertBefore) {
907903 Op<-1>() = IfTrue;
908904 Op<-2>() = IfFalse;
909905 Op<-3>() = Cond;
913909 }
914910
915911 BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd)
916 : TerminatorInst(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
917 OperandTraits::op_end(this) - 1,
918 1, InsertAtEnd) {
912 : Instruction(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
913 OperandTraits::op_end(this) - 1, 1, InsertAtEnd) {
919914 assert(IfTrue && "Branch destination may not be null!");
920915 Op<-1>() = IfTrue;
921916 }
922917
923918 BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
924 BasicBlock *InsertAtEnd)
925 : TerminatorInst(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
926 OperandTraits::op_end(this) - 3,
927 3, InsertAtEnd) {
919 BasicBlock *InsertAtEnd)
920 : Instruction(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
921 OperandTraits::op_end(this) - 3, 3, InsertAtEnd) {
928922 Op<-1>() = IfTrue;
929923 Op<-2>() = IfFalse;
930924 Op<-3>() = Cond;
933927 #endif
934928 }
935929
936 BranchInst::BranchInst(const BranchInst &BI) :
937 TerminatorInst(Type::getVoidTy(BI.getContext()), Instruction::Br,
938 OperandTraits::op_end(this) - BI.getNumOperands(),
939 BI.getNumOperands()) {
930 BranchInst::BranchInst(const BranchInst &BI)
931 : Instruction(Type::getVoidTy(BI.getContext()), Instruction::Br,
932 OperandTraits::op_end(this) - BI.getNumOperands(),
933 BI.getNumOperands()) {
940934 Op<-1>() = BI.Op<-1>();
941935 if (BI.getNumOperands() != 1) {
942936 assert(BI.getNumOperands() == 3 && "BR can have 1 or 3 operands!");
35663560 /// constructor can also autoinsert before another instruction.
35673561 SwitchInst::SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
35683562 Instruction *InsertBefore)
3569 : TerminatorInst(Type::getVoidTy(Value->getContext()), Instruction::Switch,
3570 nullptr, 0, InsertBefore) {
3563 : Instruction(Type::getVoidTy(Value->getContext()), Instruction::Switch,
3564 nullptr, 0, InsertBefore) {
35713565 init(Value, Default, 2+NumCases*2);
35723566 }
35733567
35773571 /// constructor also autoinserts at the end of the specified BasicBlock.
35783572 SwitchInst::SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
35793573 BasicBlock *InsertAtEnd)
3580 : TerminatorInst(Type::getVoidTy(Value->getContext()), Instruction::Switch,
3581 nullptr, 0, InsertAtEnd) {
3574 : Instruction(Type::getVoidTy(Value->getContext()), Instruction::Switch,
3575 nullptr, 0, InsertAtEnd) {
35823576 init(Value, Default, 2+NumCases*2);
35833577 }
35843578
35853579 SwitchInst::SwitchInst(const SwitchInst &SI)
3586 : TerminatorInst(SI.getType(), Instruction::Switch, nullptr, 0) {
3580 : Instruction(SI.getType(), Instruction::Switch, nullptr, 0) {
35873581 init(SI.getCondition(), SI.getDefaultDest(), SI.getNumOperands());
35883582 setNumHungOffUseOperands(SI.getNumOperands());
35893583 Use *OL = getOperandList();
35943588 }
35953589 SubclassOptionalData = SI.SubclassOptionalData;
35963590 }
3597
35983591
35993592 /// addCase - Add an entry to the switch instruction...
36003593 ///
36743667
36753668 IndirectBrInst::IndirectBrInst(Value *Address, unsigned NumCases,
36763669 Instruction *InsertBefore)
3677 : TerminatorInst(Type::getVoidTy(Address->getContext()),Instruction::IndirectBr,
3678 nullptr, 0, InsertBefore) {
3670 : Instruction(Type::getVoidTy(Address->getContext()),
3671 Instruction::IndirectBr, nullptr, 0, InsertBefore) {
36793672 init(Address, NumCases);
36803673 }
36813674
36823675 IndirectBrInst::IndirectBrInst(Value *Address, unsigned NumCases,
36833676 BasicBlock *InsertAtEnd)
3684 : TerminatorInst(Type::getVoidTy(Address->getContext()),Instruction::IndirectBr,
3685 nullptr, 0, InsertAtEnd) {
3677 : Instruction(Type::getVoidTy(Address->getContext()),
3678 Instruction::IndirectBr, nullptr, 0, InsertAtEnd) {
36863679 init(Address, NumCases);
36873680 }
36883681
36893682 IndirectBrInst::IndirectBrInst(const IndirectBrInst &IBI)
3690 : TerminatorInst(Type::getVoidTy(IBI.getContext()), Instruction::IndirectBr,
3691 nullptr, IBI.getNumOperands()) {
3683 : Instruction(Type::getVoidTy(IBI.getContext()), Instruction::IndirectBr,
3684 nullptr, IBI.getNumOperands()) {
36923685 allocHungoffUses(IBI.getNumOperands());
36933686 Use *OL = getOperandList();
36943687 const Use *InOL = IBI.getOperandList();