diff options
author | James Y Knight <jyknight@google.com> | 2019-02-09 22:22:28 +0000 |
---|---|---|
committer | James Y Knight <jyknight@google.com> | 2019-02-09 22:22:28 +0000 |
commit | 937984b3a98c5c2a3eef78d0b1d6573287ae97a6 (patch) | |
tree | 7242de678314e3deac9e7aebbc073279c7baab71 /lib/CodeGen/CGBuilder.h | |
parent | 1fa8b1fbd40d147ef9fa0fe73fbd44977250989f (diff) |
[opaque pointer types] Cleanup CGBuilder's Create*GEP.
The various EltSize, Offset, DataLayout, and StructLayout arguments
are all computable from the Address's element type and the DataLayout
which the CGBuilder already has access to.
After having previously asserted that the computed values are the same
as those passed in, now remove the redundant arguments from
CGBuilder's Create*GEP functions.
Differential Revision: https://reviews.llvm.org/D57767
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@353629 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGBuilder.h')
-rw-r--r-- | lib/CodeGen/CGBuilder.h | 74 |
1 files changed, 18 insertions, 56 deletions
diff --git a/lib/CodeGen/CGBuilder.h b/lib/CodeGen/CGBuilder.h index 7528000227..50ef853b83 100644 --- a/lib/CodeGen/CGBuilder.h +++ b/lib/CodeGen/CGBuilder.h @@ -167,33 +167,25 @@ public: return Address(Ptr, Addr.getAlignment()); } + /// Given + /// %addr = {T1, T2...}* ... + /// produce + /// %name = getelementptr inbounds %addr, i32 0, i32 index + /// + /// This API assumes that drilling into a struct like this is always an + /// inbounds operation. using CGBuilderBaseTy::CreateStructGEP; - Address CreateStructGEP(Address Addr, unsigned Index, CharUnits Offset, + Address CreateStructGEP(Address Addr, unsigned Index, const llvm::Twine &Name = "") { -#ifndef NDEBUG llvm::StructType *ElTy = cast<llvm::StructType>(Addr.getElementType()); const llvm::DataLayout &DL = BB->getParent()->getParent()->getDataLayout(); - const llvm::StructLayout *SL = DL.getStructLayout(ElTy); - assert(SL->getElementOffset(Index) == (uint64_t)Offset.getQuantity()); -#endif + const llvm::StructLayout *Layout = DL.getStructLayout(ElTy); + auto Offset = CharUnits::fromQuantity(Layout->getElementOffset(Index)); return Address(CreateStructGEP(Addr.getElementType(), Addr.getPointer(), Index, Name), Addr.getAlignment().alignmentAtOffset(Offset)); } - Address CreateStructGEP(Address Addr, unsigned Index, - const llvm::StructLayout *Layout, - const llvm::Twine &Name = "") { -#ifndef NDEBUG - llvm::StructType *ElTy = cast<llvm::StructType>(Addr.getElementType()); - const llvm::DataLayout &DL = BB->getParent()->getParent()->getDataLayout(); - const llvm::StructLayout *SL = DL.getStructLayout(ElTy); - assert(Layout == SL); -#endif - - auto Offset = CharUnits::fromQuantity(Layout->getElementOffset(Index)); - return CreateStructGEP(Addr, Index, Offset, Name); - } /// Given /// %addr = [n x T]* ... @@ -203,24 +195,6 @@ public: /// /// This API assumes that drilling into an array like this is always /// an inbounds operation. - /// - /// \param EltSize - the size of the type T in bytes - Address CreateConstArrayGEP(Address Addr, uint64_t Index, CharUnits EltSize, - const llvm::Twine &Name = "") { -#ifndef NDEBUG - llvm::ArrayType *ElTy = cast<llvm::ArrayType>(Addr.getElementType()); - const llvm::DataLayout &DL = BB->getParent()->getParent()->getDataLayout(); - assert(DL.getTypeAllocSize(ElTy->getElementType()) == - (uint64_t)EltSize.getQuantity()); -#endif - - return Address(CreateInBoundsGEP(Addr.getPointer(), - {getSize(CharUnits::Zero()), - getSize(Index)}, - Name), - Addr.getAlignment().alignmentAtOffset(Index * EltSize)); - } - Address CreateConstArrayGEP(Address Addr, uint64_t Index, const llvm::Twine &Name = "") { llvm::ArrayType *ElTy = cast<llvm::ArrayType>(Addr.getElementType()); @@ -239,16 +213,11 @@ public: /// produce /// %name = getelementptr inbounds %addr, i64 index /// where i64 is actually the target word size. - /// - /// \param EltSize - the size of the type T in bytes Address CreateConstInBoundsGEP(Address Addr, uint64_t Index, - CharUnits EltSize, const llvm::Twine &Name = "") { -#ifndef NDEBUG llvm::Type *ElTy = Addr.getElementType(); const llvm::DataLayout &DL = BB->getParent()->getParent()->getDataLayout(); - assert(DL.getTypeAllocSize(ElTy) == (uint64_t)EltSize.getQuantity()); -#endif + CharUnits EltSize = CharUnits::fromQuantity(DL.getTypeAllocSize(ElTy)); return Address(CreateInBoundsGEP(Addr.getElementType(), Addr.getPointer(), getSize(Index), Name), @@ -260,15 +229,12 @@ public: /// produce /// %name = getelementptr inbounds %addr, i64 index /// where i64 is actually the target word size. - /// - /// \param EltSize - the size of the type T in bytes - Address CreateConstGEP(Address Addr, uint64_t Index, CharUnits EltSize, + Address CreateConstGEP(Address Addr, uint64_t Index, const llvm::Twine &Name = "") { -#ifndef NDEBUG const llvm::DataLayout &DL = BB->getParent()->getParent()->getDataLayout(); - assert(DL.getTypeAllocSize(Addr.getElementType()) == - (uint64_t)EltSize.getQuantity()); -#endif + CharUnits EltSize = + CharUnits::fromQuantity(DL.getTypeAllocSize(Addr.getElementType())); + return Address(CreateGEP(Addr.getElementType(), Addr.getPointer(), getSize(Index), Name), Addr.getAlignment().alignmentAtOffset(Index * EltSize)); @@ -289,13 +255,9 @@ public: } using CGBuilderBaseTy::CreateConstInBoundsGEP2_32; - Address CreateConstInBoundsGEP2_32(Address Addr, unsigned Idx0, - unsigned Idx1, const llvm::DataLayout &DL, - const llvm::Twine &Name = "") { -#ifndef NDEBUG - const llvm::DataLayout &DL2 = BB->getParent()->getParent()->getDataLayout(); - assert(DL == DL2); -#endif + Address CreateConstInBoundsGEP2_32(Address Addr, unsigned Idx0, unsigned Idx1, + const llvm::Twine &Name = "") { + const llvm::DataLayout &DL = BB->getParent()->getParent()->getDataLayout(); auto *GEP = cast<llvm::GetElementPtrInst>(CreateConstInBoundsGEP2_32( Addr.getElementType(), Addr.getPointer(), Idx0, Idx1, Name)); |