diff options
author | James Y Knight <jyknight@google.com> | 2019-01-14 21:37:53 +0000 |
---|---|---|
committer | James Y Knight <jyknight@google.com> | 2019-01-14 21:37:53 +0000 |
commit | 84c1dbde08f477fe40d722a82c3dec0586d65670 (patch) | |
tree | 33707a96c8062f67899097a60db8d9e986332e06 /llvm/lib | |
parent | eb2c4af1bf8e4872b40d3e5cab2e1c5bc22eb3ef (diff) | |
download | bcm5719-llvm-84c1dbde08f477fe40d722a82c3dec0586d65670.tar.gz bcm5719-llvm-84c1dbde08f477fe40d722a82c3dec0586d65670.zip |
[opaque pointer types] Update LoadInst creation APIs to consistently
accept a return-type argument.
Note: this also adds a new C API and soft-deprecates the old C API.
Differential Revision: https://reviews.llvm.org/D56558
llvm-svn: 351123
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/IR/Core.cpp | 10 | ||||
-rw-r--r-- | llvm/lib/IR/Instructions.cpp | 71 |
2 files changed, 24 insertions, 57 deletions
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp index 8916d47841b..37303ff6431 100644 --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -3346,7 +3346,15 @@ LLVMValueRef LLVMBuildFree(LLVMBuilderRef B, LLVMValueRef PointerVal) { LLVMValueRef LLVMBuildLoad(LLVMBuilderRef B, LLVMValueRef PointerVal, const char *Name) { - return wrap(unwrap(B)->CreateLoad(unwrap(PointerVal), Name)); + Value *V = unwrap(PointerVal); + PointerType *Ty = cast<PointerType>(V->getType()); + + return wrap(unwrap(B)->CreateLoad(Ty->getElementType(), V, Name)); +} + +LLVMValueRef LLVMBuildLoad2(LLVMBuilderRef B, LLVMTypeRef Ty, + LLVMValueRef PointerVal, const char *Name) { + return wrap(unwrap(B)->CreateLoad(unwrap(Ty), unwrap(PointerVal), Name)); } LLVMValueRef LLVMBuildStore(LLVMBuilderRef B, LLVMValueRef Val, diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp index d88779bae73..06b46724a87 100644 --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -1138,28 +1138,30 @@ void LoadInst::AssertOK() { "Alignment required for atomic load"); } -LoadInst::LoadInst(Value *Ptr, const Twine &Name, Instruction *InsertBef) - : LoadInst(Ptr, Name, /*isVolatile=*/false, InsertBef) {} +LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, + Instruction *InsertBef) + : LoadInst(Ty, Ptr, Name, /*isVolatile=*/false, InsertBef) {} -LoadInst::LoadInst(Value *Ptr, const Twine &Name, BasicBlock *InsertAE) - : LoadInst(Ptr, Name, /*isVolatile=*/false, InsertAE) {} +LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, + BasicBlock *InsertAE) + : LoadInst(Ty, Ptr, Name, /*isVolatile=*/false, InsertAE) {} LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile, Instruction *InsertBef) : LoadInst(Ty, Ptr, Name, isVolatile, /*Align=*/0, InsertBef) {} -LoadInst::LoadInst(Value *Ptr, const Twine &Name, bool isVolatile, +LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile, BasicBlock *InsertAE) - : LoadInst(Ptr, Name, isVolatile, /*Align=*/0, InsertAE) {} + : LoadInst(Ty, Ptr, Name, isVolatile, /*Align=*/0, InsertAE) {} LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile, unsigned Align, Instruction *InsertBef) : LoadInst(Ty, Ptr, Name, isVolatile, Align, AtomicOrdering::NotAtomic, SyncScope::System, InsertBef) {} -LoadInst::LoadInst(Value *Ptr, const Twine &Name, bool isVolatile, +LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile, unsigned Align, BasicBlock *InsertAE) - : LoadInst(Ptr, Name, isVolatile, Align, AtomicOrdering::NotAtomic, + : LoadInst(Ty, Ptr, Name, isVolatile, Align, AtomicOrdering::NotAtomic, SyncScope::System, InsertAE) {} LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile, @@ -1174,12 +1176,11 @@ LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile, setName(Name); } -LoadInst::LoadInst(Value *Ptr, const Twine &Name, bool isVolatile, - unsigned Align, AtomicOrdering Order, - SyncScope::ID SSID, +LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile, + unsigned Align, AtomicOrdering Order, SyncScope::ID SSID, BasicBlock *InsertAE) - : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(), - Load, Ptr, InsertAE) { + : UnaryInstruction(Ty, Load, Ptr, InsertAE) { + assert(Ty == cast<PointerType>(Ptr->getType())->getElementType()); setVolatile(isVolatile); setAlignment(Align); setAtomic(Order, SSID); @@ -1187,48 +1188,6 @@ LoadInst::LoadInst(Value *Ptr, const Twine &Name, bool isVolatile, setName(Name); } -LoadInst::LoadInst(Value *Ptr, const char *Name, Instruction *InsertBef) - : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(), - Load, Ptr, InsertBef) { - setVolatile(false); - setAlignment(0); - setAtomic(AtomicOrdering::NotAtomic); - AssertOK(); - if (Name && Name[0]) setName(Name); -} - -LoadInst::LoadInst(Value *Ptr, const char *Name, BasicBlock *InsertAE) - : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(), - Load, Ptr, InsertAE) { - setVolatile(false); - setAlignment(0); - setAtomic(AtomicOrdering::NotAtomic); - AssertOK(); - if (Name && Name[0]) setName(Name); -} - -LoadInst::LoadInst(Type *Ty, Value *Ptr, const char *Name, bool isVolatile, - Instruction *InsertBef) - : UnaryInstruction(Ty, Load, Ptr, InsertBef) { - assert(Ty == cast<PointerType>(Ptr->getType())->getElementType()); - setVolatile(isVolatile); - setAlignment(0); - setAtomic(AtomicOrdering::NotAtomic); - AssertOK(); - if (Name && Name[0]) setName(Name); -} - -LoadInst::LoadInst(Value *Ptr, const char *Name, bool isVolatile, - BasicBlock *InsertAE) - : UnaryInstruction(cast<PointerType>(Ptr->getType())->getElementType(), - Load, Ptr, InsertAE) { - setVolatile(isVolatile); - setAlignment(0); - setAtomic(AtomicOrdering::NotAtomic); - AssertOK(); - if (Name && Name[0]) setName(Name); -} - void LoadInst::setAlignment(unsigned Align) { assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!"); assert(Align <= MaximumAlignment && @@ -3879,7 +3838,7 @@ AllocaInst *AllocaInst::cloneImpl() const { } LoadInst *LoadInst::cloneImpl() const { - return new LoadInst(getOperand(0), Twine(), isVolatile(), + return new LoadInst(getType(), getOperand(0), Twine(), isVolatile(), getAlignment(), getOrdering(), getSyncScopeID()); } |