llvm.org GIT mirror llvm / 7a5d864
[opaque pointer types] Update InvokeInst creation APIs to consistently accept a callee-type argument. Note: this also adds a new C API and soft-deprecates the old C API. Differential Revision: https://reviews.llvm.org/D56557 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351122 91177308-0d34-0410-b5e6-96231b3b80d8 James Y Knight 8 months ago
4 changed file(s) with 174 addition(s) and 83 deletion(s). Raw diff Collapse all Expand all
888888 }
889889
890890 /// Create an invoke instruction.
891 InvokeInst *CreateInvoke(FunctionType *Ty, Value *Callee,
892 BasicBlock *NormalDest, BasicBlock *UnwindDest,
893 ArrayRef Args,
894 ArrayRef OpBundles,
895 const Twine &Name = "") {
896 return Insert(
897 InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args, OpBundles),
898 Name);
899 }
900 InvokeInst *CreateInvoke(FunctionType *Ty, Value *Callee,
901 BasicBlock *NormalDest, BasicBlock *UnwindDest,
902 ArrayRef Args = None,
903 const Twine &Name = "") {
904 return Insert(InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args),
905 Name);
906 }
907
908 InvokeInst *CreateInvoke(Function *Callee, BasicBlock *NormalDest,
909 BasicBlock *UnwindDest, ArrayRef Args,
910 ArrayRef OpBundles,
911 const Twine &Name = "") {
912 return CreateInvoke(Callee->getFunctionType(), Callee, NormalDest,
913 UnwindDest, Args, OpBundles, Name);
914 }
915
916 InvokeInst *CreateInvoke(Function *Callee, BasicBlock *NormalDest,
917 BasicBlock *UnwindDest,
918 ArrayRef Args = None,
919 const Twine &Name = "") {
920 return CreateInvoke(Callee->getFunctionType(), Callee, NormalDest,
921 UnwindDest, Args, Name);
922 }
923
924 // Deprecated [opaque pointer types]
925 InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
926 BasicBlock *UnwindDest, ArrayRef Args,
927 ArrayRef OpBundles,
928 const Twine &Name = "") {
929 return CreateInvoke(
930 cast(
931 cast(Callee->getType())->getElementType()),
932 Callee, NormalDest, UnwindDest, Args, OpBundles, Name);
933 }
934
935 // Deprecated [opaque pointer types]
891936 InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
892937 BasicBlock *UnwindDest,
893938 ArrayRef Args = None,
894939 const Twine &Name = "") {
895 return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Args),
896 Name);
897 }
898 InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
899 BasicBlock *UnwindDest, ArrayRef Args,
900 ArrayRef OpBundles,
901 const Twine &Name = "") {
902 return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Args,
903 OpBundles), Name);
940 return CreateInvoke(
941 cast(
942 cast(Callee->getType())->getElementType()),
943 Callee, NormalDest, UnwindDest, Args, Name);
904944 }
905945
906946 ResumeInst *CreateResume(Value *Exn) {
36023602 /// Construct an InvokeInst given a range of arguments.
36033603 ///
36043604 /// Construct an InvokeInst from a range of arguments
3605 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
3606 ArrayRef Args, ArrayRef Bundles,
3607 int NumOperands, const Twine &NameStr,
3608 Instruction *InsertBefore)
3609 : InvokeInst(cast(
3610 cast(Func->getType())->getElementType()),
3611 Func, IfNormal, IfException, Args, Bundles, NumOperands,
3612 NameStr, InsertBefore) {}
3613
36143605 inline InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
36153606 BasicBlock *IfException, ArrayRef Args,
36163607 ArrayRef Bundles, int NumOperands,
36173608 const Twine &NameStr, Instruction *InsertBefore);
3618 /// Construct an InvokeInst given a range of arguments.
3619 ///
3620 /// Construct an InvokeInst from a range of arguments
3621 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
3622 ArrayRef Args, ArrayRef Bundles,
3623 int NumOperands, const Twine &NameStr,
3624 BasicBlock *InsertAtEnd);
3625
3626 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
3627 ArrayRef Args, ArrayRef Bundles,
3628 const Twine &NameStr) {
3629 init(cast(
3630 cast(Func->getType())->getElementType()),
3631 Func, IfNormal, IfException, Args, Bundles, NameStr);
3632 }
3633
3634 void init(FunctionType *FTy, Value *Func, BasicBlock *IfNormal,
3609
3610 inline InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3611 BasicBlock *IfException, ArrayRef Args,
3612 ArrayRef Bundles, int NumOperands,
3613 const Twine &NameStr, BasicBlock *InsertAtEnd);
3614
3615 void init(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
36353616 BasicBlock *IfException, ArrayRef Args,
36363617 ArrayRef Bundles, const Twine &NameStr);
36373618
36493630 InvokeInst *cloneImpl() const;
36503631
36513632 public:
3633 static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3634 BasicBlock *IfException, ArrayRef Args,
3635 const Twine &NameStr,
3636 Instruction *InsertBefore = nullptr) {
3637 int NumOperands = ComputeNumOperands(Args.size());
3638 return new (NumOperands)
3639 InvokeInst(Ty, Func, IfNormal, IfException, Args, None, NumOperands,
3640 NameStr, InsertBefore);
3641 }
3642
3643 static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3644 BasicBlock *IfException, ArrayRef Args,
3645 ArrayRef Bundles = None,
3646 const Twine &NameStr = "",
3647 Instruction *InsertBefore = nullptr) {
3648 int NumOperands =
3649 ComputeNumOperands(Args.size(), CountBundleInputs(Bundles));
3650 unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
3651
3652 return new (NumOperands, DescriptorBytes)
3653 InvokeInst(Ty, Func, IfNormal, IfException, Args, Bundles, NumOperands,
3654 NameStr, InsertBefore);
3655 }
3656
3657 static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3658 BasicBlock *IfException, ArrayRef Args,
3659 const Twine &NameStr, BasicBlock *InsertAtEnd) {
3660 int NumOperands = ComputeNumOperands(Args.size());
3661 return new (NumOperands)
3662 InvokeInst(Ty, Func, IfNormal, IfException, Args, None, NumOperands,
3663 NameStr, InsertAtEnd);
3664 }
3665
3666 static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3667 BasicBlock *IfException, ArrayRef Args,
3668 ArrayRef Bundles,
3669 const Twine &NameStr, BasicBlock *InsertAtEnd) {
3670 int NumOperands =
3671 ComputeNumOperands(Args.size(), CountBundleInputs(Bundles));
3672 unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
3673
3674 return new (NumOperands, DescriptorBytes)
3675 InvokeInst(Ty, Func, IfNormal, IfException, Args, Bundles, NumOperands,
3676 NameStr, InsertAtEnd);
3677 }
3678
3679 static InvokeInst *Create(Function *Func, BasicBlock *IfNormal,
3680 BasicBlock *IfException, ArrayRef Args,
3681 const Twine &NameStr,
3682 Instruction *InsertBefore = nullptr) {
3683 return Create(Func->getFunctionType(), Func, IfNormal, IfException, Args,
3684 None, NameStr, InsertBefore);
3685 }
3686
3687 static InvokeInst *Create(Function *Func, BasicBlock *IfNormal,
3688 BasicBlock *IfException, ArrayRef Args,
3689 ArrayRef Bundles = None,
3690 const Twine &NameStr = "",
3691 Instruction *InsertBefore = nullptr) {
3692 return Create(Func->getFunctionType(), Func, IfNormal, IfException, Args,
3693 Bundles, NameStr, InsertBefore);
3694 }
3695
3696 static InvokeInst *Create(Function *Func, BasicBlock *IfNormal,
3697 BasicBlock *IfException, ArrayRef Args,
3698 const Twine &NameStr, BasicBlock *InsertAtEnd) {
3699 return Create(Func->getFunctionType(), Func, IfNormal, IfException, Args,
3700 NameStr, InsertAtEnd);
3701 }
3702
3703 static InvokeInst *Create(Function *Func, BasicBlock *IfNormal,
3704 BasicBlock *IfException, ArrayRef Args,
3705 ArrayRef Bundles,
3706 const Twine &NameStr, BasicBlock *InsertAtEnd) {
3707 return Create(Func->getFunctionType(), Func, IfNormal, IfException, Args,
3708 Bundles, NameStr, InsertAtEnd);
3709 }
3710
3711 // Deprecated [opaque pointer types]
36523712 static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
36533713 BasicBlock *IfException, ArrayRef Args,
36543714 const Twine &NameStr,
36593719 InsertBefore);
36603720 }
36613721
3722 // Deprecated [opaque pointer types]
36623723 static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
36633724 BasicBlock *IfException, ArrayRef Args,
36643725 ArrayRef Bundles = None,
36703731 InsertBefore);
36713732 }
36723733
3673 static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3734 // Deprecated [opaque pointer types]
3735 static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
36743736 BasicBlock *IfException, ArrayRef Args,
3675 const Twine &NameStr,
3676 Instruction *InsertBefore = nullptr) {
3677 int NumOperands = ComputeNumOperands(Args.size());
3678 return new (NumOperands)
3679 InvokeInst(Ty, Func, IfNormal, IfException, Args, None, NumOperands,
3680 NameStr, InsertBefore);
3681 }
3682
3683 static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3684 BasicBlock *IfException, ArrayRef Args,
3685 ArrayRef Bundles = None,
3686 const Twine &NameStr = "",
3687 Instruction *InsertBefore = nullptr) {
3688 int NumOperands =
3689 ComputeNumOperands(Args.size(), CountBundleInputs(Bundles));
3690 unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
3691
3692 return new (NumOperands, DescriptorBytes)
3693 InvokeInst(Ty, Func, IfNormal, IfException, Args, Bundles, NumOperands,
3694 NameStr, InsertBefore);
3695 }
3696
3697 static InvokeInst *Create(Value *Func,
3698 BasicBlock *IfNormal, BasicBlock *IfException,
3699 ArrayRef Args, const Twine &NameStr,
3700 BasicBlock *InsertAtEnd) {
3701 int NumOperands = ComputeNumOperands(Args.size());
3702 return new (NumOperands) InvokeInst(Func, IfNormal, IfException, Args, None,
3703 NumOperands, NameStr, InsertAtEnd);
3704 }
3705
3737 const Twine &NameStr, BasicBlock *InsertAtEnd) {
3738 return Create(cast(
3739 cast(Func->getType())->getElementType()),
3740 Func, IfNormal, IfException, Args, NameStr, InsertAtEnd);
3741 }
3742
3743 // Deprecated [opaque pointer types]
37063744 static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
37073745 BasicBlock *IfException, ArrayRef Args,
37083746 ArrayRef Bundles,
37093747 const Twine &NameStr, BasicBlock *InsertAtEnd) {
3710 int NumOperands =
3711 ComputeNumOperands(Args.size(), CountBundleInputs(Bundles));
3712 unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
3713
3714 return new (NumOperands, DescriptorBytes)
3715 InvokeInst(Func, IfNormal, IfException, Args, Bundles, NumOperands,
3716 NameStr, InsertAtEnd);
3748 return Create(cast(
3749 cast(Func->getType())->getElementType()),
3750 Func, IfNormal, IfException, Args, Bundles, NameStr,
3751 InsertAtEnd);
37173752 }
37183753
37193754 /// Create a clone of \p II with a different set of operand bundles and
37943829 init(Ty, Func, IfNormal, IfException, Args, Bundles, NameStr);
37953830 }
37963831
3797 InvokeInst::InvokeInst(Value *Func, BasicBlock *IfNormal,
3832 InvokeInst::InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
37983833 BasicBlock *IfException, ArrayRef Args,
37993834 ArrayRef Bundles, int NumOperands,
38003835 const Twine &NameStr, BasicBlock *InsertAtEnd)
3801 : CallBase(cast(
3802 cast(Func->getType())->getElementType())
3803 ->getReturnType(),
3804 Instruction::Invoke,
3836 : CallBase(Ty->getReturnType(), Instruction::Invoke,
38053837 OperandTraits::op_end(this) - NumOperands, NumOperands,
38063838 InsertAtEnd) {
3807 init(Func, IfNormal, IfException, Args, Bundles, NameStr);
3839 init(Ty, Func, IfNormal, IfException, Args, Bundles, NameStr);
38083840 }
38093841
38103842 //===----------------------------------------------------------------------===//
33973397 LLVMBasicBlockRef Else, unsigned NumCases);
33983398 LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
33993399 unsigned NumDests);
3400 // LLVMBuildInvoke is deprecated in favor of LLVMBuildInvoke2, in preparation
3401 // for opaque pointer types.
34003402 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
34013403 LLVMValueRef *Args, unsigned NumArgs,
34023404 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
34033405 const char *Name);
3406 LLVMValueRef LLVMBuildInvoke2(LLVMBuilderRef, LLVMTypeRef Ty, LLVMValueRef Fn,
3407 LLVMValueRef *Args, unsigned NumArgs,
3408 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
3409 const char *Name);
34043410 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
34053411
34063412 /* Exception Handling */
29742974 LLVMValueRef *Args, unsigned NumArgs,
29752975 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
29762976 const char *Name) {
2977 return wrap(unwrap(B)->CreateInvoke(unwrap(Fn), unwrap(Then), unwrap(Catch),
2978 makeArrayRef(unwrap(Args), NumArgs),
2979 Name));
2977 Value *V = unwrap(Fn);
2978 FunctionType *FnT =
2979 cast(cast(V->getType())->getElementType());
2980
2981 return wrap(
2982 unwrap(B)->CreateInvoke(FnT, unwrap(Fn), unwrap(Then), unwrap(Catch),
2983 makeArrayRef(unwrap(Args), NumArgs), Name));
2984 }
2985
2986 LLVMValueRef LLVMBuildInvoke2(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Fn,
2987 LLVMValueRef *Args, unsigned NumArgs,
2988 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2989 const char *Name) {
2990 return wrap(unwrap(B)->CreateInvoke(
2991 unwrap(Ty), unwrap(Fn), unwrap(Then), unwrap(Catch),
2992 makeArrayRef(unwrap(Args), NumArgs), Name));
29802993 }
29812994
29822995 LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,