Skip to content

Commit eb2c4af

Browse files
committedJan 14, 2019
[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 llvm-svn: 351122
1 parent f956390 commit eb2c4af

File tree

4 files changed

+158
-67
lines changed

4 files changed

+158
-67
lines changed
 

‎llvm/include/llvm-c/Core.h

+6
Original file line numberDiff line numberDiff line change
@@ -3398,10 +3398,16 @@ LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
33983398
LLVMBasicBlockRef Else, unsigned NumCases);
33993399
LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
34003400
unsigned NumDests);
3401+
// LLVMBuildInvoke is deprecated in favor of LLVMBuildInvoke2, in preparation
3402+
// for opaque pointer types.
34013403
LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
34023404
LLVMValueRef *Args, unsigned NumArgs,
34033405
LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
34043406
const char *Name);
3407+
LLVMValueRef LLVMBuildInvoke2(LLVMBuilderRef, LLVMTypeRef Ty, LLVMValueRef Fn,
3408+
LLVMValueRef *Args, unsigned NumArgs,
3409+
LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
3410+
const char *Name);
34053411
LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
34063412

34073413
/* Exception Handling */

‎llvm/include/llvm/IR/IRBuilder.h

+45-5
Original file line numberDiff line numberDiff line change
@@ -889,19 +889,59 @@ class IRBuilder : public IRBuilderBase, public Inserter {
889889
}
890890

891891
/// Create an invoke instruction.
892-
InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
893-
BasicBlock *UnwindDest,
892+
InvokeInst *CreateInvoke(FunctionType *Ty, Value *Callee,
893+
BasicBlock *NormalDest, BasicBlock *UnwindDest,
894+
ArrayRef<Value *> Args,
895+
ArrayRef<OperandBundleDef> OpBundles,
896+
const Twine &Name = "") {
897+
return Insert(
898+
InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args, OpBundles),
899+
Name);
900+
}
901+
InvokeInst *CreateInvoke(FunctionType *Ty, Value *Callee,
902+
BasicBlock *NormalDest, BasicBlock *UnwindDest,
894903
ArrayRef<Value *> Args = None,
895904
const Twine &Name = "") {
896-
return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Args),
905+
return Insert(InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args),
897906
Name);
898907
}
908+
909+
InvokeInst *CreateInvoke(Function *Callee, BasicBlock *NormalDest,
910+
BasicBlock *UnwindDest, ArrayRef<Value *> Args,
911+
ArrayRef<OperandBundleDef> OpBundles,
912+
const Twine &Name = "") {
913+
return CreateInvoke(Callee->getFunctionType(), Callee, NormalDest,
914+
UnwindDest, Args, OpBundles, Name);
915+
}
916+
917+
InvokeInst *CreateInvoke(Function *Callee, BasicBlock *NormalDest,
918+
BasicBlock *UnwindDest,
919+
ArrayRef<Value *> Args = None,
920+
const Twine &Name = "") {
921+
return CreateInvoke(Callee->getFunctionType(), Callee, NormalDest,
922+
UnwindDest, Args, Name);
923+
}
924+
925+
// Deprecated [opaque pointer types]
899926
InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
900927
BasicBlock *UnwindDest, ArrayRef<Value *> Args,
901928
ArrayRef<OperandBundleDef> OpBundles,
902929
const Twine &Name = "") {
903-
return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Args,
904-
OpBundles), Name);
930+
return CreateInvoke(
931+
cast<FunctionType>(
932+
cast<PointerType>(Callee->getType())->getElementType()),
933+
Callee, NormalDest, UnwindDest, Args, OpBundles, Name);
934+
}
935+
936+
// Deprecated [opaque pointer types]
937+
InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
938+
BasicBlock *UnwindDest,
939+
ArrayRef<Value *> Args = None,
940+
const Twine &Name = "") {
941+
return CreateInvoke(
942+
cast<FunctionType>(
943+
cast<PointerType>(Callee->getType())->getElementType()),
944+
Callee, NormalDest, UnwindDest, Args, Name);
905945
}
906946

907947
ResumeInst *CreateResume(Value *Exn) {

‎llvm/include/llvm/IR/Instructions.h

+91-59
Original file line numberDiff line numberDiff line change
@@ -3603,36 +3603,17 @@ class InvokeInst : public CallBase {
36033603
/// Construct an InvokeInst given a range of arguments.
36043604
///
36053605
/// Construct an InvokeInst from a range of arguments
3606-
inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
3607-
ArrayRef<Value *> Args, ArrayRef<OperandBundleDef> Bundles,
3608-
int NumOperands, const Twine &NameStr,
3609-
Instruction *InsertBefore)
3610-
: InvokeInst(cast<FunctionType>(
3611-
cast<PointerType>(Func->getType())->getElementType()),
3612-
Func, IfNormal, IfException, Args, Bundles, NumOperands,
3613-
NameStr, InsertBefore) {}
3614-
36153606
inline InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
36163607
BasicBlock *IfException, ArrayRef<Value *> Args,
36173608
ArrayRef<OperandBundleDef> Bundles, int NumOperands,
36183609
const Twine &NameStr, Instruction *InsertBefore);
3619-
/// Construct an InvokeInst given a range of arguments.
3620-
///
3621-
/// Construct an InvokeInst from a range of arguments
3622-
inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
3623-
ArrayRef<Value *> Args, ArrayRef<OperandBundleDef> Bundles,
3624-
int NumOperands, const Twine &NameStr,
3625-
BasicBlock *InsertAtEnd);
36263610

3627-
void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
3628-
ArrayRef<Value *> Args, ArrayRef<OperandBundleDef> Bundles,
3629-
const Twine &NameStr) {
3630-
init(cast<FunctionType>(
3631-
cast<PointerType>(Func->getType())->getElementType()),
3632-
Func, IfNormal, IfException, Args, Bundles, NameStr);
3633-
}
3611+
inline InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3612+
BasicBlock *IfException, ArrayRef<Value *> Args,
3613+
ArrayRef<OperandBundleDef> Bundles, int NumOperands,
3614+
const Twine &NameStr, BasicBlock *InsertAtEnd);
36343615

3635-
void init(FunctionType *FTy, Value *Func, BasicBlock *IfNormal,
3616+
void init(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
36363617
BasicBlock *IfException, ArrayRef<Value *> Args,
36373618
ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr);
36383619

@@ -3650,27 +3631,6 @@ class InvokeInst : public CallBase {
36503631
InvokeInst *cloneImpl() const;
36513632

36523633
public:
3653-
static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
3654-
BasicBlock *IfException, ArrayRef<Value *> Args,
3655-
const Twine &NameStr,
3656-
Instruction *InsertBefore = nullptr) {
3657-
return Create(cast<FunctionType>(
3658-
cast<PointerType>(Func->getType())->getElementType()),
3659-
Func, IfNormal, IfException, Args, None, NameStr,
3660-
InsertBefore);
3661-
}
3662-
3663-
static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
3664-
BasicBlock *IfException, ArrayRef<Value *> Args,
3665-
ArrayRef<OperandBundleDef> Bundles = None,
3666-
const Twine &NameStr = "",
3667-
Instruction *InsertBefore = nullptr) {
3668-
return Create(cast<FunctionType>(
3669-
cast<PointerType>(Func->getType())->getElementType()),
3670-
Func, IfNormal, IfException, Args, Bundles, NameStr,
3671-
InsertBefore);
3672-
}
3673-
36743634
static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
36753635
BasicBlock *IfException, ArrayRef<Value *> Args,
36763636
const Twine &NameStr,
@@ -3695,16 +3655,16 @@ class InvokeInst : public CallBase {
36953655
NameStr, InsertBefore);
36963656
}
36973657

3698-
static InvokeInst *Create(Value *Func,
3699-
BasicBlock *IfNormal, BasicBlock *IfException,
3700-
ArrayRef<Value *> Args, const Twine &NameStr,
3701-
BasicBlock *InsertAtEnd) {
3658+
static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3659+
BasicBlock *IfException, ArrayRef<Value *> Args,
3660+
const Twine &NameStr, BasicBlock *InsertAtEnd) {
37023661
int NumOperands = ComputeNumOperands(Args.size());
3703-
return new (NumOperands) InvokeInst(Func, IfNormal, IfException, Args, None,
3704-
NumOperands, NameStr, InsertAtEnd);
3662+
return new (NumOperands)
3663+
InvokeInst(Ty, Func, IfNormal, IfException, Args, None, NumOperands,
3664+
NameStr, InsertAtEnd);
37053665
}
37063666

3707-
static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
3667+
static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
37083668
BasicBlock *IfException, ArrayRef<Value *> Args,
37093669
ArrayRef<OperandBundleDef> Bundles,
37103670
const Twine &NameStr, BasicBlock *InsertAtEnd) {
@@ -3713,10 +3673,85 @@ class InvokeInst : public CallBase {
37133673
unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
37143674

37153675
return new (NumOperands, DescriptorBytes)
3716-
InvokeInst(Func, IfNormal, IfException, Args, Bundles, NumOperands,
3676+
InvokeInst(Ty, Func, IfNormal, IfException, Args, Bundles, NumOperands,
37173677
NameStr, InsertAtEnd);
37183678
}
37193679

3680+
static InvokeInst *Create(Function *Func, BasicBlock *IfNormal,
3681+
BasicBlock *IfException, ArrayRef<Value *> Args,
3682+
const Twine &NameStr,
3683+
Instruction *InsertBefore = nullptr) {
3684+
return Create(Func->getFunctionType(), Func, IfNormal, IfException, Args,
3685+
None, NameStr, InsertBefore);
3686+
}
3687+
3688+
static InvokeInst *Create(Function *Func, BasicBlock *IfNormal,
3689+
BasicBlock *IfException, ArrayRef<Value *> Args,
3690+
ArrayRef<OperandBundleDef> Bundles = None,
3691+
const Twine &NameStr = "",
3692+
Instruction *InsertBefore = nullptr) {
3693+
return Create(Func->getFunctionType(), Func, IfNormal, IfException, Args,
3694+
Bundles, NameStr, InsertBefore);
3695+
}
3696+
3697+
static InvokeInst *Create(Function *Func, BasicBlock *IfNormal,
3698+
BasicBlock *IfException, ArrayRef<Value *> Args,
3699+
const Twine &NameStr, BasicBlock *InsertAtEnd) {
3700+
return Create(Func->getFunctionType(), Func, IfNormal, IfException, Args,
3701+
NameStr, InsertAtEnd);
3702+
}
3703+
3704+
static InvokeInst *Create(Function *Func, BasicBlock *IfNormal,
3705+
BasicBlock *IfException, ArrayRef<Value *> Args,
3706+
ArrayRef<OperandBundleDef> Bundles,
3707+
const Twine &NameStr, BasicBlock *InsertAtEnd) {
3708+
return Create(Func->getFunctionType(), Func, IfNormal, IfException, Args,
3709+
Bundles, NameStr, InsertAtEnd);
3710+
}
3711+
3712+
// Deprecated [opaque pointer types]
3713+
static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
3714+
BasicBlock *IfException, ArrayRef<Value *> Args,
3715+
const Twine &NameStr,
3716+
Instruction *InsertBefore = nullptr) {
3717+
return Create(cast<FunctionType>(
3718+
cast<PointerType>(Func->getType())->getElementType()),
3719+
Func, IfNormal, IfException, Args, None, NameStr,
3720+
InsertBefore);
3721+
}
3722+
3723+
// Deprecated [opaque pointer types]
3724+
static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
3725+
BasicBlock *IfException, ArrayRef<Value *> Args,
3726+
ArrayRef<OperandBundleDef> Bundles = None,
3727+
const Twine &NameStr = "",
3728+
Instruction *InsertBefore = nullptr) {
3729+
return Create(cast<FunctionType>(
3730+
cast<PointerType>(Func->getType())->getElementType()),
3731+
Func, IfNormal, IfException, Args, Bundles, NameStr,
3732+
InsertBefore);
3733+
}
3734+
3735+
// Deprecated [opaque pointer types]
3736+
static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
3737+
BasicBlock *IfException, ArrayRef<Value *> Args,
3738+
const Twine &NameStr, BasicBlock *InsertAtEnd) {
3739+
return Create(cast<FunctionType>(
3740+
cast<PointerType>(Func->getType())->getElementType()),
3741+
Func, IfNormal, IfException, Args, NameStr, InsertAtEnd);
3742+
}
3743+
3744+
// Deprecated [opaque pointer types]
3745+
static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
3746+
BasicBlock *IfException, ArrayRef<Value *> Args,
3747+
ArrayRef<OperandBundleDef> Bundles,
3748+
const Twine &NameStr, BasicBlock *InsertAtEnd) {
3749+
return Create(cast<FunctionType>(
3750+
cast<PointerType>(Func->getType())->getElementType()),
3751+
Func, IfNormal, IfException, Args, Bundles, NameStr,
3752+
InsertAtEnd);
3753+
}
3754+
37203755
/// Create a clone of \p II with a different set of operand bundles and
37213756
/// insert it before \p InsertPt.
37223757
///
@@ -3795,17 +3830,14 @@ InvokeInst::InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
37953830
init(Ty, Func, IfNormal, IfException, Args, Bundles, NameStr);
37963831
}
37973832

3798-
InvokeInst::InvokeInst(Value *Func, BasicBlock *IfNormal,
3833+
InvokeInst::InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
37993834
BasicBlock *IfException, ArrayRef<Value *> Args,
38003835
ArrayRef<OperandBundleDef> Bundles, int NumOperands,
38013836
const Twine &NameStr, BasicBlock *InsertAtEnd)
3802-
: CallBase(cast<FunctionType>(
3803-
cast<PointerType>(Func->getType())->getElementType())
3804-
->getReturnType(),
3805-
Instruction::Invoke,
3837+
: CallBase(Ty->getReturnType(), Instruction::Invoke,
38063838
OperandTraits<CallBase>::op_end(this) - NumOperands, NumOperands,
38073839
InsertAtEnd) {
3808-
init(Func, IfNormal, IfException, Args, Bundles, NameStr);
3840+
init(Ty, Func, IfNormal, IfException, Args, Bundles, NameStr);
38093841
}
38103842

38113843
//===----------------------------------------------------------------------===//

‎llvm/lib/IR/Core.cpp

+16-3
Original file line numberDiff line numberDiff line change
@@ -2975,9 +2975,22 @@ LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef B, LLVMValueRef Fn,
29752975
LLVMValueRef *Args, unsigned NumArgs,
29762976
LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
29772977
const char *Name) {
2978-
return wrap(unwrap(B)->CreateInvoke(unwrap(Fn), unwrap(Then), unwrap(Catch),
2979-
makeArrayRef(unwrap(Args), NumArgs),
2980-
Name));
2978+
Value *V = unwrap(Fn);
2979+
FunctionType *FnT =
2980+
cast<FunctionType>(cast<PointerType>(V->getType())->getElementType());
2981+
2982+
return wrap(
2983+
unwrap(B)->CreateInvoke(FnT, unwrap(Fn), unwrap(Then), unwrap(Catch),
2984+
makeArrayRef(unwrap(Args), NumArgs), Name));
2985+
}
2986+
2987+
LLVMValueRef LLVMBuildInvoke2(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Fn,
2988+
LLVMValueRef *Args, unsigned NumArgs,
2989+
LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2990+
const char *Name) {
2991+
return wrap(unwrap(B)->CreateInvoke(
2992+
unwrap<FunctionType>(Ty), unwrap(Fn), unwrap(Then), unwrap(Catch),
2993+
makeArrayRef(unwrap(Args), NumArgs), Name));
29812994
}
29822995

29832996
LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,

0 commit comments

Comments
 (0)
Please sign in to comment.