[llvm] r351122 - [opaque pointer types] Update InvokeInst creation APIs to consistently
James Y Knight via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 14 13:37:48 PST 2019
Author: jyknight
Date: Mon Jan 14 13:37:48 2019
New Revision: 351122
URL: http://llvm.org/viewvc/llvm-project?rev=351122&view=rev
Log:
[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
Modified:
llvm/trunk/include/llvm-c/Core.h
llvm/trunk/include/llvm/IR/IRBuilder.h
llvm/trunk/include/llvm/IR/Instructions.h
llvm/trunk/lib/IR/Core.cpp
Modified: llvm/trunk/include/llvm-c/Core.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Core.h?rev=351122&r1=351121&r2=351122&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/Core.h (original)
+++ llvm/trunk/include/llvm-c/Core.h Mon Jan 14 13:37:48 2019
@@ -3398,10 +3398,16 @@ LLVMValueRef LLVMBuildSwitch(LLVMBuilder
LLVMBasicBlockRef Else, unsigned NumCases);
LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
unsigned NumDests);
+// LLVMBuildInvoke is deprecated in favor of LLVMBuildInvoke2, in preparation
+// for opaque pointer types.
LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
LLVMValueRef *Args, unsigned NumArgs,
LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
const char *Name);
+LLVMValueRef LLVMBuildInvoke2(LLVMBuilderRef, LLVMTypeRef Ty, LLVMValueRef Fn,
+ LLVMValueRef *Args, unsigned NumArgs,
+ LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
+ const char *Name);
LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
/* Exception Handling */
Modified: llvm/trunk/include/llvm/IR/IRBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/IRBuilder.h?rev=351122&r1=351121&r2=351122&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/IRBuilder.h (original)
+++ llvm/trunk/include/llvm/IR/IRBuilder.h Mon Jan 14 13:37:48 2019
@@ -889,19 +889,59 @@ public:
}
/// Create an invoke instruction.
- InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
- BasicBlock *UnwindDest,
+ InvokeInst *CreateInvoke(FunctionType *Ty, Value *Callee,
+ BasicBlock *NormalDest, BasicBlock *UnwindDest,
+ ArrayRef<Value *> Args,
+ ArrayRef<OperandBundleDef> OpBundles,
+ const Twine &Name = "") {
+ return Insert(
+ InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args, OpBundles),
+ Name);
+ }
+ InvokeInst *CreateInvoke(FunctionType *Ty, Value *Callee,
+ BasicBlock *NormalDest, BasicBlock *UnwindDest,
ArrayRef<Value *> Args = None,
const Twine &Name = "") {
- return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Args),
+ return Insert(InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args),
Name);
}
+
+ InvokeInst *CreateInvoke(Function *Callee, BasicBlock *NormalDest,
+ BasicBlock *UnwindDest, ArrayRef<Value *> Args,
+ ArrayRef<OperandBundleDef> OpBundles,
+ const Twine &Name = "") {
+ return CreateInvoke(Callee->getFunctionType(), Callee, NormalDest,
+ UnwindDest, Args, OpBundles, Name);
+ }
+
+ InvokeInst *CreateInvoke(Function *Callee, BasicBlock *NormalDest,
+ BasicBlock *UnwindDest,
+ ArrayRef<Value *> Args = None,
+ const Twine &Name = "") {
+ return CreateInvoke(Callee->getFunctionType(), Callee, NormalDest,
+ UnwindDest, Args, Name);
+ }
+
+ // Deprecated [opaque pointer types]
InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
BasicBlock *UnwindDest, ArrayRef<Value *> Args,
ArrayRef<OperandBundleDef> OpBundles,
const Twine &Name = "") {
- return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Args,
- OpBundles), Name);
+ return CreateInvoke(
+ cast<FunctionType>(
+ cast<PointerType>(Callee->getType())->getElementType()),
+ Callee, NormalDest, UnwindDest, Args, OpBundles, Name);
+ }
+
+ // Deprecated [opaque pointer types]
+ InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
+ BasicBlock *UnwindDest,
+ ArrayRef<Value *> Args = None,
+ const Twine &Name = "") {
+ return CreateInvoke(
+ cast<FunctionType>(
+ cast<PointerType>(Callee->getType())->getElementType()),
+ Callee, NormalDest, UnwindDest, Args, Name);
}
ResumeInst *CreateResume(Value *Exn) {
Modified: llvm/trunk/include/llvm/IR/Instructions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Instructions.h?rev=351122&r1=351121&r2=351122&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Instructions.h (original)
+++ llvm/trunk/include/llvm/IR/Instructions.h Mon Jan 14 13:37:48 2019
@@ -3603,36 +3603,17 @@ class InvokeInst : public CallBase {
/// Construct an InvokeInst given a range of arguments.
///
/// Construct an InvokeInst from a range of arguments
- inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
- ArrayRef<Value *> Args, ArrayRef<OperandBundleDef> Bundles,
- int NumOperands, const Twine &NameStr,
- Instruction *InsertBefore)
- : InvokeInst(cast<FunctionType>(
- cast<PointerType>(Func->getType())->getElementType()),
- Func, IfNormal, IfException, Args, Bundles, NumOperands,
- NameStr, InsertBefore) {}
-
inline InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
BasicBlock *IfException, ArrayRef<Value *> Args,
ArrayRef<OperandBundleDef> Bundles, int NumOperands,
const Twine &NameStr, Instruction *InsertBefore);
- /// Construct an InvokeInst given a range of arguments.
- ///
- /// Construct an InvokeInst from a range of arguments
- inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
- ArrayRef<Value *> Args, ArrayRef<OperandBundleDef> Bundles,
- int NumOperands, const Twine &NameStr,
- BasicBlock *InsertAtEnd);
-
- void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
- ArrayRef<Value *> Args, ArrayRef<OperandBundleDef> Bundles,
- const Twine &NameStr) {
- init(cast<FunctionType>(
- cast<PointerType>(Func->getType())->getElementType()),
- Func, IfNormal, IfException, Args, Bundles, NameStr);
- }
- void init(FunctionType *FTy, Value *Func, BasicBlock *IfNormal,
+ inline InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
+ BasicBlock *IfException, ArrayRef<Value *> Args,
+ ArrayRef<OperandBundleDef> Bundles, int NumOperands,
+ const Twine &NameStr, BasicBlock *InsertAtEnd);
+
+ void init(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
BasicBlock *IfException, ArrayRef<Value *> Args,
ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr);
@@ -3650,27 +3631,6 @@ protected:
InvokeInst *cloneImpl() const;
public:
- static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
- BasicBlock *IfException, ArrayRef<Value *> Args,
- const Twine &NameStr,
- Instruction *InsertBefore = nullptr) {
- return Create(cast<FunctionType>(
- cast<PointerType>(Func->getType())->getElementType()),
- Func, IfNormal, IfException, Args, None, NameStr,
- InsertBefore);
- }
-
- static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
- BasicBlock *IfException, ArrayRef<Value *> Args,
- ArrayRef<OperandBundleDef> Bundles = None,
- const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr) {
- return Create(cast<FunctionType>(
- cast<PointerType>(Func->getType())->getElementType()),
- Func, IfNormal, IfException, Args, Bundles, NameStr,
- InsertBefore);
- }
-
static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
BasicBlock *IfException, ArrayRef<Value *> Args,
const Twine &NameStr,
@@ -3695,16 +3655,16 @@ public:
NameStr, InsertBefore);
}
- static InvokeInst *Create(Value *Func,
- BasicBlock *IfNormal, BasicBlock *IfException,
- ArrayRef<Value *> Args, const Twine &NameStr,
- BasicBlock *InsertAtEnd) {
+ static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
+ BasicBlock *IfException, ArrayRef<Value *> Args,
+ const Twine &NameStr, BasicBlock *InsertAtEnd) {
int NumOperands = ComputeNumOperands(Args.size());
- return new (NumOperands) InvokeInst(Func, IfNormal, IfException, Args, None,
- NumOperands, NameStr, InsertAtEnd);
+ return new (NumOperands)
+ InvokeInst(Ty, Func, IfNormal, IfException, Args, None, NumOperands,
+ NameStr, InsertAtEnd);
}
- static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
+ static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
BasicBlock *IfException, ArrayRef<Value *> Args,
ArrayRef<OperandBundleDef> Bundles,
const Twine &NameStr, BasicBlock *InsertAtEnd) {
@@ -3713,10 +3673,85 @@ public:
unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
return new (NumOperands, DescriptorBytes)
- InvokeInst(Func, IfNormal, IfException, Args, Bundles, NumOperands,
+ InvokeInst(Ty, Func, IfNormal, IfException, Args, Bundles, NumOperands,
NameStr, InsertAtEnd);
}
+ static InvokeInst *Create(Function *Func, BasicBlock *IfNormal,
+ BasicBlock *IfException, ArrayRef<Value *> Args,
+ const Twine &NameStr,
+ Instruction *InsertBefore = nullptr) {
+ return Create(Func->getFunctionType(), Func, IfNormal, IfException, Args,
+ None, NameStr, InsertBefore);
+ }
+
+ static InvokeInst *Create(Function *Func, BasicBlock *IfNormal,
+ BasicBlock *IfException, ArrayRef<Value *> Args,
+ ArrayRef<OperandBundleDef> Bundles = None,
+ const Twine &NameStr = "",
+ Instruction *InsertBefore = nullptr) {
+ return Create(Func->getFunctionType(), Func, IfNormal, IfException, Args,
+ Bundles, NameStr, InsertBefore);
+ }
+
+ static InvokeInst *Create(Function *Func, BasicBlock *IfNormal,
+ BasicBlock *IfException, ArrayRef<Value *> Args,
+ const Twine &NameStr, BasicBlock *InsertAtEnd) {
+ return Create(Func->getFunctionType(), Func, IfNormal, IfException, Args,
+ NameStr, InsertAtEnd);
+ }
+
+ static InvokeInst *Create(Function *Func, BasicBlock *IfNormal,
+ BasicBlock *IfException, ArrayRef<Value *> Args,
+ ArrayRef<OperandBundleDef> Bundles,
+ const Twine &NameStr, BasicBlock *InsertAtEnd) {
+ return Create(Func->getFunctionType(), Func, IfNormal, IfException, Args,
+ Bundles, NameStr, InsertAtEnd);
+ }
+
+ // Deprecated [opaque pointer types]
+ static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
+ BasicBlock *IfException, ArrayRef<Value *> Args,
+ const Twine &NameStr,
+ Instruction *InsertBefore = nullptr) {
+ return Create(cast<FunctionType>(
+ cast<PointerType>(Func->getType())->getElementType()),
+ Func, IfNormal, IfException, Args, None, NameStr,
+ InsertBefore);
+ }
+
+ // Deprecated [opaque pointer types]
+ static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
+ BasicBlock *IfException, ArrayRef<Value *> Args,
+ ArrayRef<OperandBundleDef> Bundles = None,
+ const Twine &NameStr = "",
+ Instruction *InsertBefore = nullptr) {
+ return Create(cast<FunctionType>(
+ cast<PointerType>(Func->getType())->getElementType()),
+ Func, IfNormal, IfException, Args, Bundles, NameStr,
+ InsertBefore);
+ }
+
+ // Deprecated [opaque pointer types]
+ static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
+ BasicBlock *IfException, ArrayRef<Value *> Args,
+ const Twine &NameStr, BasicBlock *InsertAtEnd) {
+ return Create(cast<FunctionType>(
+ cast<PointerType>(Func->getType())->getElementType()),
+ Func, IfNormal, IfException, Args, NameStr, InsertAtEnd);
+ }
+
+ // Deprecated [opaque pointer types]
+ static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
+ BasicBlock *IfException, ArrayRef<Value *> Args,
+ ArrayRef<OperandBundleDef> Bundles,
+ const Twine &NameStr, BasicBlock *InsertAtEnd) {
+ return Create(cast<FunctionType>(
+ cast<PointerType>(Func->getType())->getElementType()),
+ Func, IfNormal, IfException, Args, Bundles, NameStr,
+ InsertAtEnd);
+ }
+
/// Create a clone of \p II with a different set of operand bundles and
/// insert it before \p InsertPt.
///
@@ -3795,17 +3830,14 @@ InvokeInst::InvokeInst(FunctionType *Ty,
init(Ty, Func, IfNormal, IfException, Args, Bundles, NameStr);
}
-InvokeInst::InvokeInst(Value *Func, BasicBlock *IfNormal,
+InvokeInst::InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
BasicBlock *IfException, ArrayRef<Value *> Args,
ArrayRef<OperandBundleDef> Bundles, int NumOperands,
const Twine &NameStr, BasicBlock *InsertAtEnd)
- : CallBase(cast<FunctionType>(
- cast<PointerType>(Func->getType())->getElementType())
- ->getReturnType(),
- Instruction::Invoke,
+ : CallBase(Ty->getReturnType(), Instruction::Invoke,
OperandTraits<CallBase>::op_end(this) - NumOperands, NumOperands,
InsertAtEnd) {
- init(Func, IfNormal, IfException, Args, Bundles, NameStr);
+ init(Ty, Func, IfNormal, IfException, Args, Bundles, NameStr);
}
//===----------------------------------------------------------------------===//
Modified: llvm/trunk/lib/IR/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Core.cpp?rev=351122&r1=351121&r2=351122&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Core.cpp (original)
+++ llvm/trunk/lib/IR/Core.cpp Mon Jan 14 13:37:48 2019
@@ -2975,9 +2975,22 @@ LLVMValueRef LLVMBuildInvoke(LLVMBuilder
LLVMValueRef *Args, unsigned NumArgs,
LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
const char *Name) {
- return wrap(unwrap(B)->CreateInvoke(unwrap(Fn), unwrap(Then), unwrap(Catch),
- makeArrayRef(unwrap(Args), NumArgs),
- Name));
+ Value *V = unwrap(Fn);
+ FunctionType *FnT =
+ cast<FunctionType>(cast<PointerType>(V->getType())->getElementType());
+
+ return wrap(
+ unwrap(B)->CreateInvoke(FnT, unwrap(Fn), unwrap(Then), unwrap(Catch),
+ makeArrayRef(unwrap(Args), NumArgs), Name));
+}
+
+LLVMValueRef LLVMBuildInvoke2(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Fn,
+ LLVMValueRef *Args, unsigned NumArgs,
+ LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
+ const char *Name) {
+ return wrap(unwrap(B)->CreateInvoke(
+ unwrap<FunctionType>(Ty), unwrap(Fn), unwrap(Then), unwrap(Catch),
+ makeArrayRef(unwrap(Args), NumArgs), Name));
}
LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
More information about the llvm-commits
mailing list