llvm.org GIT mirror llvm / 14bebff
[opaque pointer types] Update GetElementPtr creation APIs to consistently accept a pointee-type argument. Note: this also adds a new C API and soft-deprecates the old C API. Differential Revision: https://reviews.llvm.org/D56559 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351124 91177308-0d34-0410-b5e6-96231b3b80d8 James Y Knight 8 months ago
3 changed file(s) with 100 addition(s) and 31 deletion(s). Raw diff Collapse all Expand all
15621562 return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idxs), Name);
15631563 }
15641564
1565 Value *CreateConstGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0,
1566 const Twine &Name = "") {
1567 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
1568
1569 if (auto *PC = dyn_cast(Ptr))
1570 return Insert(Folder.CreateGetElementPtr(Ty, PC, Idx), Name);
1571
1572 return Insert(GetElementPtrInst::Create(Ty, Ptr, Idx), Name);
1573 }
1574
15651575 Value *CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const Twine &Name = "") {
1576 return CreateConstGEP1_64(nullptr, Ptr, Idx0, Name);
1577 }
1578
1579 Value *CreateConstInBoundsGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0,
1580 const Twine &Name = "") {
15661581 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
15671582
15681583 if (auto *PC = dyn_cast(Ptr))
1569 return Insert(Folder.CreateGetElementPtr(nullptr, PC, Idx), Name);
1570
1571 return Insert(GetElementPtrInst::Create(nullptr, Ptr, Idx), Name);
1584 return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, Idx), Name);
1585
1586 return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idx), Name);
15721587 }
15731588
15741589 Value *CreateConstInBoundsGEP1_64(Value *Ptr, uint64_t Idx0,
15751590 const Twine &Name = "") {
1576 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
1577
1578 if (auto *PC = dyn_cast(Ptr))
1579 return Insert(Folder.CreateInBoundsGetElementPtr(nullptr, PC, Idx), Name);
1580
1581 return Insert(GetElementPtrInst::CreateInBounds(nullptr, Ptr, Idx), Name);
1582 }
1583
1584 Value *CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
1585 const Twine &Name = "") {
1591 return CreateConstInBoundsGEP1_64(nullptr, Ptr, Idx0, Name);
1592 }
1593
1594 Value *CreateConstGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1,
1595 const Twine &Name = "") {
15861596 Value *Idxs[] = {
15871597 ConstantInt::get(Type::getInt64Ty(Context), Idx0),
15881598 ConstantInt::get(Type::getInt64Ty(Context), Idx1)
15891599 };
15901600
15911601 if (auto *PC = dyn_cast(Ptr))
1592 return Insert(Folder.CreateGetElementPtr(nullptr, PC, Idxs), Name);
1593
1594 return Insert(GetElementPtrInst::Create(nullptr, Ptr, Idxs), Name);
1595 }
1596
1597 Value *CreateConstInBoundsGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
1598 const Twine &Name = "") {
1602 return Insert(Folder.CreateGetElementPtr(Ty, PC, Idxs), Name);
1603
1604 return Insert(GetElementPtrInst::Create(Ty, Ptr, Idxs), Name);
1605 }
1606
1607 Value *CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
1608 const Twine &Name = "") {
1609 return CreateConstGEP2_64(nullptr, Ptr, Idx0, Idx1, Name);
1610 }
1611
1612 Value *CreateConstInBoundsGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0,
1613 uint64_t Idx1, const Twine &Name = "") {
15991614 Value *Idxs[] = {
16001615 ConstantInt::get(Type::getInt64Ty(Context), Idx0),
16011616 ConstantInt::get(Type::getInt64Ty(Context), Idx1)
16021617 };
16031618
16041619 if (auto *PC = dyn_cast(Ptr))
1605 return Insert(Folder.CreateInBoundsGetElementPtr(nullptr, PC, Idxs),
1606 Name);
1607
1608 return Insert(GetElementPtrInst::CreateInBounds(nullptr, Ptr, Idxs), Name);
1620 return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, Idxs), Name);
1621
1622 return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idxs), Name);
1623 }
1624
1625 Value *CreateConstInBoundsGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
1626 const Twine &Name = "") {
1627 return CreateConstInBoundsGEP2_64(nullptr, Ptr, Idx0, Idx1, Name);
16091628 }
16101629
16111630 Value *CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx,
20842084 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
20852085 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
20862086 LLVMValueRef *ConstantIndices, unsigned NumIndices);
2087 LLVMValueRef LLVMConstGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
2088 LLVMValueRef *ConstantIndices, unsigned NumIndices);
20872089 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
20882090 LLVMValueRef *ConstantIndices,
20892091 unsigned NumIndices);
2092 LLVMValueRef LLVMConstInBoundsGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
2093 LLVMValueRef *ConstantIndices,
2094 unsigned NumIndices);
20902095 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
20912096 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
20922097 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
36033608 LLVMValueRef LLVMBuildLoad2(LLVMBuilderRef, LLVMTypeRef Ty,
36043609 LLVMValueRef PointerVal, const char *Name);
36053610 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
3611 // LLVMBuildGEP, LLVMBuildInBoundsGEP, and LLVMBuildStructGEP are deprecated in
3612 // favor of LLVMBuild*GEP2, in preparation for opaque pointer types.
36063613 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
36073614 LLVMValueRef *Indices, unsigned NumIndices,
36083615 const char *Name);
36113618 const char *Name);
36123619 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
36133620 unsigned Idx, const char *Name);
3621 LLVMValueRef LLVMBuildGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
3622 LLVMValueRef Pointer, LLVMValueRef *Indices,
3623 unsigned NumIndices, const char *Name);
3624 LLVMValueRef LLVMBuildInBoundsGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
3625 LLVMValueRef Pointer, LLVMValueRef *Indices,
3626 unsigned NumIndices, const char *Name);
3627 LLVMValueRef LLVMBuildStructGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
3628 LLVMValueRef Pointer, unsigned Idx,
3629 const char *Name);
36143630 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
36153631 const char *Name);
36163632 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
16161616 LLVMValueRef *ConstantIndices, unsigned NumIndices) {
16171617 ArrayRef IdxList(unwrap(ConstantIndices, NumIndices),
16181618 NumIndices);
1619 return wrap(ConstantExpr::getGetElementPtr(
1620 nullptr, unwrap(ConstantVal), IdxList));
1619 Constant *Val = unwrap(ConstantVal);
1620 Type *Ty =
1621 cast(Val->getType()->getScalarType())->getElementType();
1622 return wrap(ConstantExpr::getGetElementPtr(Ty, Val, IdxList));
16211623 }
16221624
16231625 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
16241626 LLVMValueRef *ConstantIndices,
16251627 unsigned NumIndices) {
1626 Constant* Val = unwrap(ConstantVal);
16271628 ArrayRef IdxList(unwrap(ConstantIndices, NumIndices),
16281629 NumIndices);
1629 return wrap(ConstantExpr::getInBoundsGetElementPtr(nullptr, Val, IdxList));
1630 Constant *Val = unwrap(ConstantVal);
1631 Type *Ty =
1632 cast(Val->getType()->getScalarType())->getElementType();
1633 return wrap(ConstantExpr::getInBoundsGetElementPtr(Ty, Val, IdxList));
16301634 }
16311635
16321636 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
34083412 LLVMValueRef *Indices, unsigned NumIndices,
34093413 const char *Name) {
34103414 ArrayRef IdxList(unwrap(Indices), NumIndices);
3411 return wrap(unwrap(B)->CreateGEP(nullptr, unwrap(Pointer), IdxList, Name));
3415 Value *Val = unwrap(Pointer);
3416 Type *Ty =
3417 cast(Val->getType()->getScalarType())->getElementType();
3418 return wrap(unwrap(B)->CreateGEP(Ty, Val, IdxList, Name));
3419 }
3420
3421 LLVMValueRef LLVMBuildGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
3422 LLVMValueRef Pointer, LLVMValueRef *Indices,
3423 unsigned NumIndices, const char *Name) {
3424 ArrayRef IdxList(unwrap(Indices), NumIndices);
3425 return wrap(unwrap(B)->CreateGEP(unwrap(Ty), unwrap(Pointer), IdxList, Name));
34123426 }
34133427
34143428 LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
34153429 LLVMValueRef *Indices, unsigned NumIndices,
34163430 const char *Name) {
34173431 ArrayRef IdxList(unwrap(Indices), NumIndices);
3432 Value *Val = unwrap(Pointer);
3433 Type *Ty =
3434 cast(Val->getType()->getScalarType())->getElementType();
3435 return wrap(unwrap(B)->CreateInBoundsGEP(Ty, Val, IdxList, Name));
3436 }
3437
3438 LLVMValueRef LLVMBuildInBoundsGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
3439 LLVMValueRef Pointer, LLVMValueRef *Indices,
3440 unsigned NumIndices, const char *Name) {
3441 ArrayRef IdxList(unwrap(Indices), NumIndices);
34183442 return wrap(
3419 unwrap(B)->CreateInBoundsGEP(nullptr, unwrap(Pointer), IdxList, Name));
3443 unwrap(B)->CreateInBoundsGEP(unwrap(Ty), unwrap(Pointer), IdxList, Name));
34203444 }
34213445
34223446 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
34233447 unsigned Idx, const char *Name) {
3424 return wrap(unwrap(B)->CreateStructGEP(nullptr, unwrap(Pointer), Idx, Name));
3448 Value *Val = unwrap(Pointer);
3449 Type *Ty =
3450 cast(Val->getType()->getScalarType())->getElementType();
3451 return wrap(unwrap(B)->CreateStructGEP(Ty, Val, Idx, Name));
3452 }
3453
3454 LLVMValueRef LLVMBuildStructGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
3455 LLVMValueRef Pointer, unsigned Idx,
3456 const char *Name) {
3457 return wrap(
3458 unwrap(B)->CreateStructGEP(unwrap(Ty), unwrap(Pointer), Idx, Name));
34253459 }
34263460
34273461 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,