llvm.org GIT mirror llvm / f806f42
[opaque pointer types] Update CallInst 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/D56556 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351121 91177308-0d34-0410-b5e6-96231b3b80d8 James Y Knight 8 months ago
6 changed file(s) with 200 addition(s) and 114 deletion(s). Raw diff Collapse all Expand all
18791879 return Insert(PHINode::Create(Ty, NumReservedValues), Name);
18801880 }
18811881
1882 CallInst *CreateCall(Value *Callee, ArrayRef Args = None,
1883 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
1884 auto *PTy = cast(Callee->getType());
1885 auto *FTy = cast(PTy->getElementType());
1886 return CreateCall(FTy, Callee, Args, Name, FPMathTag);
1887 }
1888
18891882 CallInst *CreateCall(FunctionType *FTy, Value *Callee,
1890 ArrayRef Args, const Twine &Name = "",
1883 ArrayRef Args = None, const Twine &Name = "",
18911884 MDNode *FPMathTag = nullptr) {
18921885 CallInst *CI = CallInst::Create(FTy, Callee, Args, DefaultOperandBundles);
18931886 if (isa(CI))
18951888 return Insert(CI, Name);
18961889 }
18971890
1891 CallInst *CreateCall(FunctionType *FTy, Value *Callee, ArrayRef Args,
1892 ArrayRef OpBundles,
1893 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
1894 CallInst *CI = CallInst::Create(FTy, Callee, Args, OpBundles);
1895 if (isa(CI))
1896 CI = cast(setFPAttrs(CI, FPMathTag, FMF));
1897 return Insert(CI, Name);
1898 }
1899
1900 CallInst *CreateCall(Function *Callee, ArrayRef Args = None,
1901 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
1902 return CreateCall(Callee->getFunctionType(), Callee, Args, Name, FPMathTag);
1903 }
1904
1905 CallInst *CreateCall(Function *Callee, ArrayRef Args,
1906 ArrayRef OpBundles,
1907 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
1908 return CreateCall(Callee->getFunctionType(), Callee, Args, OpBundles, Name,
1909 FPMathTag);
1910 }
1911
1912 // Deprecated [opaque pointer types]
1913 CallInst *CreateCall(Value *Callee, ArrayRef Args = None,
1914 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
1915 return CreateCall(
1916 cast(Callee->getType()->getPointerElementType()), Callee,
1917 Args, Name, FPMathTag);
1918 }
1919
1920 // Deprecated [opaque pointer types]
18981921 CallInst *CreateCall(Value *Callee, ArrayRef Args,
18991922 ArrayRef OpBundles,
19001923 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
1901 CallInst *CI = CallInst::Create(Callee, Args, OpBundles);
1902 if (isa(CI))
1903 CI = cast(setFPAttrs(CI, FPMathTag, FMF));
1904 return Insert(CI, Name);
1905 }
1906
1907 CallInst *CreateCall(Function *Callee, ArrayRef Args,
1908 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
1909 return CreateCall(Callee->getFunctionType(), Callee, Args, Name, FPMathTag);
1924 return CreateCall(
1925 cast(Callee->getType()->getPointerElementType()), Callee,
1926 Args, OpBundles, Name, FPMathTag);
19101927 }
19111928
19121929 Value *CreateSelect(Value *C, Value *True, Value *False,
14321432 ArrayRef Bundles, const Twine &NameStr,
14331433 Instruction *InsertBefore);
14341434
1435 inline CallInst(Value *Func, ArrayRef Args,
1436 ArrayRef Bundles, const Twine &NameStr,
1437 Instruction *InsertBefore)
1438 : CallInst(cast(
1439 cast(Func->getType())->getElementType()),
1440 Func, Args, Bundles, NameStr, InsertBefore) {}
1441
1442 inline CallInst(Value *Func, ArrayRef Args, const Twine &NameStr,
1443 Instruction *InsertBefore)
1444 : CallInst(Func, Args, None, NameStr, InsertBefore) {}
1435 inline CallInst(FunctionType *Ty, Value *Func, ArrayRef Args,
1436 const Twine &NameStr, Instruction *InsertBefore)
1437 : CallInst(Ty, Func, Args, None, NameStr, InsertBefore) {}
14451438
14461439 /// Construct a CallInst given a range of arguments.
14471440 /// Construct a CallInst from a range of arguments
1448 inline CallInst(Value *Func, ArrayRef Args,
1441 inline CallInst(FunctionType *Ty, Value *Func, ArrayRef Args,
14491442 ArrayRef Bundles, const Twine &NameStr,
14501443 BasicBlock *InsertAtEnd);
14511444
1452 explicit CallInst(Value *F, const Twine &NameStr, Instruction *InsertBefore);
1453
1454 CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
1455
1456 void init(Value *Func, ArrayRef Args,
1457 ArrayRef Bundles, const Twine &NameStr) {
1458 init(cast(
1459 cast(Func->getType())->getElementType()),
1460 Func, Args, Bundles, NameStr);
1461 }
1445 explicit CallInst(FunctionType *Ty, Value *F, const Twine &NameStr,
1446 Instruction *InsertBefore);
1447
1448 CallInst(FunctionType *ty, Value *F, const Twine &NameStr,
1449 BasicBlock *InsertAtEnd);
1450
14621451 void init(FunctionType *FTy, Value *Func, ArrayRef Args,
14631452 ArrayRef Bundles, const Twine &NameStr);
1464 void init(Value *Func, const Twine &NameStr);
1453 void init(FunctionType *FTy, Value *Func, const Twine &NameStr);
14651454
14661455 /// Compute the number of operands to allocate.
14671456 static int ComputeNumOperands(int NumArgs, int NumBundleInputs = 0) {
14771466 CallInst *cloneImpl() const;
14781467
14791468 public:
1469 static CallInst *Create(FunctionType *Ty, Value *F, const Twine &NameStr = "",
1470 Instruction *InsertBefore = nullptr) {
1471 return new (ComputeNumOperands(0)) CallInst(Ty, F, NameStr, InsertBefore);
1472 }
1473
1474 static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef Args,
1475 const Twine &NameStr,
1476 Instruction *InsertBefore = nullptr) {
1477 return new (ComputeNumOperands(Args.size()))
1478 CallInst(Ty, Func, Args, None, NameStr, InsertBefore);
1479 }
1480
1481 static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef Args,
1482 ArrayRef Bundles = None,
1483 const Twine &NameStr = "",
1484 Instruction *InsertBefore = nullptr) {
1485 const int NumOperands =
1486 ComputeNumOperands(Args.size(), CountBundleInputs(Bundles));
1487 const unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
1488
1489 return new (NumOperands, DescriptorBytes)
1490 CallInst(Ty, Func, Args, Bundles, NameStr, InsertBefore);
1491 }
1492
1493 static CallInst *Create(FunctionType *Ty, Value *F, const Twine &NameStr,
1494 BasicBlock *InsertAtEnd) {
1495 return new (ComputeNumOperands(0)) CallInst(Ty, F, NameStr, InsertAtEnd);
1496 }
1497
1498 static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef Args,
1499 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1500 return new (ComputeNumOperands(Args.size()))
1501 CallInst(Ty, Func, Args, None, NameStr, InsertAtEnd);
1502 }
1503
1504 static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef Args,
1505 ArrayRef Bundles,
1506 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1507 const int NumOperands =
1508 ComputeNumOperands(Args.size(), CountBundleInputs(Bundles));
1509 const unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
1510
1511 return new (NumOperands, DescriptorBytes)
1512 CallInst(Ty, Func, Args, Bundles, NameStr, InsertAtEnd);
1513 }
1514
1515 static CallInst *Create(Function *Func, const Twine &NameStr = "",
1516 Instruction *InsertBefore = nullptr) {
1517 return Create(Func->getFunctionType(), Func, NameStr, InsertBefore);
1518 }
1519
1520 static CallInst *Create(Function *Func, ArrayRef Args,
1521 const Twine &NameStr = "",
1522 Instruction *InsertBefore = nullptr) {
1523 return Create(Func->getFunctionType(), Func, Args, NameStr, InsertBefore);
1524 }
1525
1526 static CallInst *Create(Function *Func, const Twine &NameStr,
1527 BasicBlock *InsertAtEnd) {
1528 return Create(Func->getFunctionType(), Func, NameStr, InsertAtEnd);
1529 }
1530
1531 static CallInst *Create(Function *Func, ArrayRef Args,
1532 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1533 return Create(Func->getFunctionType(), Func, Args, NameStr, InsertAtEnd);
1534 }
1535
1536 // Deprecated [opaque pointer types]
1537 static CallInst *Create(Value *Func, const Twine &NameStr = "",
1538 Instruction *InsertBefore = nullptr) {
1539 return Create(cast(
1540 cast(Func->getType())->getElementType()),
1541 Func, NameStr, InsertBefore);
1542 }
1543
1544 // Deprecated [opaque pointer types]
1545 static CallInst *Create(Value *Func, ArrayRef Args,
1546 const Twine &NameStr,
1547 Instruction *InsertBefore = nullptr) {
1548 return Create(cast(
1549 cast(Func->getType())->getElementType()),
1550 Func, Args, NameStr, InsertBefore);
1551 }
1552
1553 // Deprecated [opaque pointer types]
14801554 static CallInst *Create(Value *Func, ArrayRef Args,
14811555 ArrayRef Bundles = None,
14821556 const Twine &NameStr = "",
14861560 Func, Args, Bundles, NameStr, InsertBefore);
14871561 }
14881562
1489 static CallInst *Create(Value *Func, ArrayRef Args,
1490 const Twine &NameStr,
1491 Instruction *InsertBefore = nullptr) {
1563 // Deprecated [opaque pointer types]
1564 static CallInst *Create(Value *Func, const Twine &NameStr,
1565 BasicBlock *InsertAtEnd) {
14921566 return Create(cast(
14931567 cast(Func->getType())->getElementType()),
1494 Func, Args, None, NameStr, InsertBefore);
1495 }
1496
1497 static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef Args,
1498 const Twine &NameStr,
1499 Instruction *InsertBefore = nullptr) {
1500 return new (ComputeNumOperands(Args.size()))
1501 CallInst(Ty, Func, Args, None, NameStr, InsertBefore);
1502 }
1503
1504 static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef Args,
1505 ArrayRef Bundles = None,
1506 const Twine &NameStr = "",
1507 Instruction *InsertBefore = nullptr) {
1508 const int NumOperands =
1509 ComputeNumOperands(Args.size(), CountBundleInputs(Bundles));
1510 const unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
1511
1512 return new (NumOperands, DescriptorBytes)
1513 CallInst(Ty, Func, Args, Bundles, NameStr, InsertBefore);
1514 }
1515
1568 Func, NameStr, InsertAtEnd);
1569 }
1570
1571 // Deprecated [opaque pointer types]
1572 static CallInst *Create(Value *Func, ArrayRef Args,
1573 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1574 return Create(cast(
1575 cast(Func->getType())->getElementType()),
1576 Func, Args, NameStr, InsertAtEnd);
1577 }
1578
1579 // Deprecated [opaque pointer types]
15161580 static CallInst *Create(Value *Func, ArrayRef Args,
15171581 ArrayRef Bundles,
15181582 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1519 const int NumOperands =
1520 ComputeNumOperands(Args.size(), CountBundleInputs(Bundles));
1521 const unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
1522
1523 return new (NumOperands, DescriptorBytes)
1524 CallInst(Func, Args, Bundles, NameStr, InsertAtEnd);
1525 }
1526
1527 static CallInst *Create(Value *Func, ArrayRef Args,
1528 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1529 return new (ComputeNumOperands(Args.size()))
1530 CallInst(Func, Args, None, NameStr, InsertAtEnd);
1531 }
1532
1533 static CallInst *Create(Value *F, const Twine &NameStr = "",
1534 Instruction *InsertBefore = nullptr) {
1535 return new (ComputeNumOperands(0)) CallInst(F, NameStr, InsertBefore);
1536 }
1537
1538 static CallInst *Create(Value *F, const Twine &NameStr,
1539 BasicBlock *InsertAtEnd) {
1540 return new (ComputeNumOperands(0)) CallInst(F, NameStr, InsertAtEnd);
1583 return Create(cast(
1584 cast(Func->getType())->getElementType()),
1585 Func, Args, Bundles, NameStr, InsertAtEnd);
15411586 }
15421587
15431588 /// Create a clone of \p CI with a different set of operand bundles and
16461691 }
16471692 };
16481693
1649 CallInst::CallInst(Value *Func, ArrayRef Args,
1694 CallInst::CallInst(FunctionType *Ty, Value *Func, ArrayRef Args,
16501695 ArrayRef Bundles, const Twine &NameStr,
16511696 BasicBlock *InsertAtEnd)
1652 : CallBase(cast(
1653 cast(Func->getType())->getElementType())
1654 ->getReturnType(),
1655 Instruction::Call,
1697 : CallBase(Ty->getReturnType(), Instruction::Call,
16561698 OperandTraits::op_end(this) -
16571699 (Args.size() + CountBundleInputs(Bundles) + 1),
16581700 unsigned(Args.size() + CountBundleInputs(Bundles) + 1),
16591701 InsertAtEnd) {
1660 init(Func, Args, Bundles, NameStr);
1702 init(Ty, Func, Args, Bundles, NameStr);
16611703 }
16621704
16631705 CallInst::CallInst(FunctionType *Ty, Value *Func, ArrayRef Args,
366366 return getOrInsertFunction(Name, AttributeList{}, RetTy, Args...);
367367 }
368368
369 // Avoid an incorrect ordering that'd otherwise compile incorrectly.
370 template
371 Constant *getOrInsertFunction(StringRef Name, AttributeList AttributeList,
372 FunctionType *Invalid, ArgsTy... Args) = delete;
373
369374 /// Look up the specified function in the module symbol table. If it does not
370375 /// exist, return null.
371376 Function *getFunction(StringRef Name) const;
30993099 const char *K, unsigned KLen);
31003100
31013101 /**
3102 * Obtain the function type called by this instruction.
3103 *
3104 * @see llvm::CallBase::getFunctionType()
3105 */
3106 LLVMTypeRef LLVMGetCalledFunctionType(LLVMValueRef C);
3107
3108 /**
31023109 * Obtain the pointer to the function invoked by this instruction.
31033110 *
31043111 * This expects an LLVMValueRef that corresponds to a llvm::CallInst or
36603667
36613668 /* Miscellaneous instructions */
36623669 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
3670 // LLVMBuildCall is deprecated in favor of LLVMBuildCall2, in preparation for
3671 // opaque pointer types.
36633672 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
36643673 LLVMValueRef *Args, unsigned NumArgs,
36653674 const char *Name);
3675 LLVMValueRef LLVMBuildCall2(LLVMBuilderRef, LLVMTypeRef, LLVMValueRef Fn,
3676 LLVMValueRef *Args, unsigned NumArgs,
3677 const char *Name);
36663678 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
36673679 LLVMValueRef Then, LLVMValueRef Else,
36683680 const char *Name);
27272727 return wrap(unwrap(Instr)->getCalledValue());
27282728 }
27292729
2730 LLVMTypeRef LLVMGetCalledFunctionType(LLVMValueRef Instr) {
2731 return wrap(unwrap(Instr)->getFunctionType());
2732 }
2733
27302734 /*--.. Operations on call instructions (only) ..............................--*/
27312735
27322736 LLVMBool LLVMIsTailCall(LLVMValueRef Call) {
35813585 LLVMValueRef LLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn,
35823586 LLVMValueRef *Args, unsigned NumArgs,
35833587 const char *Name) {
3584 return wrap(unwrap(B)->CreateCall(unwrap(Fn),
3585 makeArrayRef(unwrap(Args), NumArgs),
3586 Name));
3588 Value *V = unwrap(Fn);
3589 FunctionType *FnT =
3590 cast(cast(V->getType())->getElementType());
3591
3592 return wrap(unwrap(B)->CreateCall(FnT, unwrap(Fn),
3593 makeArrayRef(unwrap(Args), NumArgs), Name));
3594 }
3595
3596 LLVMValueRef LLVMBuildCall2(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Fn,
3597 LLVMValueRef *Args, unsigned NumArgs,
3598 const char *Name) {
3599 FunctionType *FTy = unwrap(Ty);
3600 return wrap(unwrap(B)->CreateCall(FTy, unwrap(Fn),
3601 makeArrayRef(unwrap(Args), NumArgs), Name));
35873602 }
35883603
35893604 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef B, LLVMValueRef If,
387387 setName(NameStr);
388388 }
389389
390 void CallInst::init(Value *Func, const Twine &NameStr) {
391 FTy =
392 cast(cast(Func->getType())->getElementType());
390 void CallInst::init(FunctionType *FTy, Value *Func, const Twine &NameStr) {
391 this->FTy = FTy;
393392 assert(getNumOperands() == 1 && "NumOperands not set up?");
394393 setCalledOperand(Func);
395394
398397 setName(NameStr);
399398 }
400399
401 CallInst::CallInst(Value *Func, const Twine &Name, Instruction *InsertBefore)
402 : CallBase(cast(
403 cast(Func->getType())->getElementType())
404 ->getReturnType(),
405 Instruction::Call, OperandTraits::op_end(this) - 1, 1,
406 InsertBefore) {
407 init(Func, Name);
408 }
409
410 CallInst::CallInst(Value *Func, const Twine &Name, BasicBlock *InsertAtEnd)
411 : CallBase(cast(
412 cast(Func->getType())->getElementType())
413 ->getReturnType(),
414 Instruction::Call, OperandTraits::op_end(this) - 1, 1,
415 InsertAtEnd) {
416 init(Func, Name);
400 CallInst::CallInst(FunctionType *Ty, Value *Func, const Twine &Name,
401 Instruction *InsertBefore)
402 : CallBase(Ty->getReturnType(), Instruction::Call,
403 OperandTraits::op_end(this) - 1, 1, InsertBefore) {
404 init(Ty, Func, Name);
405 }
406
407 CallInst::CallInst(FunctionType *Ty, Value *Func, const Twine &Name,
408 BasicBlock *InsertAtEnd)
409 : CallBase(Ty->getReturnType(), Instruction::Call,
410 OperandTraits::op_end(this) - 1, 1, InsertAtEnd) {
411 init(Ty, Func, Name);
417412 }
418413
419414 CallInst::CallInst(const CallInst &CI)