diff options
| author | James Y Knight <jyknight@google.com> | 2019-01-14 21:39:35 +0000 |
|---|---|---|
| committer | James Y Knight <jyknight@google.com> | 2019-01-14 21:39:35 +0000 |
| commit | 544fa425c98d60042214bd78ee90abf0a46fa2ff (patch) | |
| tree | 397a7542cd1b1d1f829fe9ad2eab98f72436a099 /llvm/lib | |
| parent | 84c1dbde08f477fe40d722a82c3dec0586d65670 (diff) | |
| download | bcm5719-llvm-544fa425c98d60042214bd78ee90abf0a46fa2ff.tar.gz bcm5719-llvm-544fa425c98d60042214bd78ee90abf0a46fa2ff.zip | |
[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
llvm-svn: 351124
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/IR/Core.cpp | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp index 37303ff6431..815797f4b7e 100644 --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -1617,17 +1617,21 @@ LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal, LLVMValueRef *ConstantIndices, unsigned NumIndices) { ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices), NumIndices); - return wrap(ConstantExpr::getGetElementPtr( - nullptr, unwrap<Constant>(ConstantVal), IdxList)); + Constant *Val = unwrap<Constant>(ConstantVal); + Type *Ty = + cast<PointerType>(Val->getType()->getScalarType())->getElementType(); + return wrap(ConstantExpr::getGetElementPtr(Ty, Val, IdxList)); } LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal, LLVMValueRef *ConstantIndices, unsigned NumIndices) { - Constant* Val = unwrap<Constant>(ConstantVal); ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices), NumIndices); - return wrap(ConstantExpr::getInBoundsGetElementPtr(nullptr, Val, IdxList)); + Constant *Val = unwrap<Constant>(ConstantVal); + Type *Ty = + cast<PointerType>(Val->getType()->getScalarType())->getElementType(); + return wrap(ConstantExpr::getInBoundsGetElementPtr(Ty, Val, IdxList)); } LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { @@ -3409,20 +3413,50 @@ LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer, LLVMValueRef *Indices, unsigned NumIndices, const char *Name) { ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices); - return wrap(unwrap(B)->CreateGEP(nullptr, unwrap(Pointer), IdxList, Name)); + Value *Val = unwrap(Pointer); + Type *Ty = + cast<PointerType>(Val->getType()->getScalarType())->getElementType(); + return wrap(unwrap(B)->CreateGEP(Ty, Val, IdxList, Name)); +} + +LLVMValueRef LLVMBuildGEP2(LLVMBuilderRef B, LLVMTypeRef Ty, + LLVMValueRef Pointer, LLVMValueRef *Indices, + unsigned NumIndices, const char *Name) { + ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices); + return wrap(unwrap(B)->CreateGEP(unwrap(Ty), unwrap(Pointer), IdxList, Name)); } LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer, LLVMValueRef *Indices, unsigned NumIndices, const char *Name) { ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices); + Value *Val = unwrap(Pointer); + Type *Ty = + cast<PointerType>(Val->getType()->getScalarType())->getElementType(); + return wrap(unwrap(B)->CreateInBoundsGEP(Ty, Val, IdxList, Name)); +} + +LLVMValueRef LLVMBuildInBoundsGEP2(LLVMBuilderRef B, LLVMTypeRef Ty, + LLVMValueRef Pointer, LLVMValueRef *Indices, + unsigned NumIndices, const char *Name) { + ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices); return wrap( - unwrap(B)->CreateInBoundsGEP(nullptr, unwrap(Pointer), IdxList, Name)); + unwrap(B)->CreateInBoundsGEP(unwrap(Ty), unwrap(Pointer), IdxList, Name)); } LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer, unsigned Idx, const char *Name) { - return wrap(unwrap(B)->CreateStructGEP(nullptr, unwrap(Pointer), Idx, Name)); + Value *Val = unwrap(Pointer); + Type *Ty = + cast<PointerType>(Val->getType()->getScalarType())->getElementType(); + return wrap(unwrap(B)->CreateStructGEP(Ty, Val, Idx, Name)); +} + +LLVMValueRef LLVMBuildStructGEP2(LLVMBuilderRef B, LLVMTypeRef Ty, + LLVMValueRef Pointer, unsigned Idx, + const char *Name) { + return wrap( + unwrap(B)->CreateStructGEP(unwrap(Ty), unwrap(Pointer), Idx, Name)); } LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str, |

