[Mlir-commits] [mlir] 42eb658 - [OpaquePtrs] Remove some uses of type-less CreateGEP() (NFC)
Nikita Popov
llvmlistbot at llvm.org
Fri Mar 12 12:01:29 PST 2021
Author: Nikita Popov
Date: 2021-03-12T21:01:16+01:00
New Revision: 42eb658f656c43ee63e25222f32abbbbcb86ad7b
URL: https://github.com/llvm/llvm-project/commit/42eb658f656c43ee63e25222f32abbbbcb86ad7b
DIFF: https://github.com/llvm/llvm-project/commit/42eb658f656c43ee63e25222f32abbbbcb86ad7b.diff
LOG: [OpaquePtrs] Remove some uses of type-less CreateGEP() (NFC)
This removes some (but not all) uses of type-less CreateGEP()
and CreateInBoundsGEP() APIs, which are incompatible with opaque
pointers.
There are a still a number of tricky uses left, as well as many
more variation APIs for CreateGEP.
Added:
Modified:
clang/lib/CodeGen/CGBuilder.h
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGClass.cpp
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGExprCXX.cpp
clang/lib/CodeGen/CGNonTrivialStruct.cpp
clang/lib/CodeGen/CGObjCRuntime.cpp
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/CodeGen/MicrosoftCXXABI.cpp
clang/lib/CodeGen/TargetInfo.cpp
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/lib/Transforms/Scalar/SROA.cpp
mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
polly/lib/CodeGen/RuntimeDebugBuilder.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGBuilder.h b/clang/lib/CodeGen/CGBuilder.h
index 4e22db67c57e..e79d72885e54 100644
--- a/clang/lib/CodeGen/CGBuilder.h
+++ b/clang/lib/CodeGen/CGBuilder.h
@@ -213,7 +213,7 @@ class CGBuilderTy : public CGBuilderBaseTy {
CharUnits::fromQuantity(DL.getTypeAllocSize(ElTy->getElementType()));
return Address(
- CreateInBoundsGEP(Addr.getPointer(),
+ CreateInBoundsGEP(Addr.getElementType(), Addr.getPointer(),
{getSize(CharUnits::Zero()), getSize(Index)}, Name),
Addr.getAlignment().alignmentAtOffset(Index * EltSize));
}
@@ -254,7 +254,8 @@ class CGBuilderTy : public CGBuilderBaseTy {
Address CreateConstInBoundsByteGEP(Address Addr, CharUnits Offset,
const llvm::Twine &Name = "") {
assert(Addr.getElementType() == TypeCache.Int8Ty);
- return Address(CreateInBoundsGEP(Addr.getPointer(), getSize(Offset), Name),
+ return Address(CreateInBoundsGEP(Addr.getElementType(), Addr.getPointer(),
+ getSize(Offset), Name),
Addr.getAlignment().alignmentAtOffset(Offset));
}
Address CreateConstByteGEP(Address Addr, CharUnits Offset,
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a3a33e46583b..ed43e5fd091f 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3251,7 +3251,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
Builder.CreateMemCpy(Dest, Src, SizeVal, false);
if (BuiltinID == Builtin::BImempcpy ||
BuiltinID == Builtin::BI__builtin_mempcpy)
- return RValue::get(Builder.CreateInBoundsGEP(Dest.getPointer(), SizeVal));
+ return RValue::get(Builder.CreateInBoundsGEP(Dest.getElementType(),
+ Dest.getPointer(), SizeVal));
else
return RValue::get(Dest.getPointer());
}
@@ -4682,7 +4683,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
auto *Zero = llvm::ConstantInt::get(IntTy, 0);
for (unsigned I = First; I < NumArgs; ++I) {
auto *Index = llvm::ConstantInt::get(IntTy, I - First);
- auto *GEP = Builder.CreateGEP(TmpPtr, {Zero, Index});
+ auto *GEP = Builder.CreateGEP(Tmp.getElementType(), TmpPtr,
+ {Zero, Index});
if (I == First)
ElemPtr = GEP;
auto *V =
@@ -8984,7 +8986,7 @@ Value *CodeGenFunction::EmitAArch64SVEBuiltinExpr(unsigned BuiltinID,
for (unsigned I = 0; I < NumOpnds; ++I)
Builder.CreateDefaultAlignedStore(
IsBoolTy ? Builder.CreateZExt(Ops[I], EltTy) : Ops[I],
- Builder.CreateGEP(Alloca.getPointer(),
+ Builder.CreateGEP(Alloca.getElementType(), Alloca.getPointer(),
{Builder.getInt64(0), Builder.getInt64(I)}));
SVETypeFlags TypeFlags(Builtin->TypeModifier);
@@ -8993,7 +8995,8 @@ Value *CodeGenFunction::EmitAArch64SVEBuiltinExpr(unsigned BuiltinID,
llvm::Type *OverloadedTy = getSVEVectorForElementType(EltTy);
Function *F = CGM.getIntrinsic(Intrinsic::aarch64_sve_ld1rq, OverloadedTy);
Value *Alloca0 = Builder.CreateGEP(
- Alloca.getPointer(), {Builder.getInt64(0), Builder.getInt64(0)});
+ Alloca.getElementType(), Alloca.getPointer(),
+ {Builder.getInt64(0), Builder.getInt64(0)});
Value *LD1RQ = Builder.CreateCall(F, {Pred, Alloca0});
if (!IsBoolTy)
@@ -15237,7 +15240,7 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID,
for (unsigned i=0; i<NumVecs; i++) {
Value *Vec = Builder.CreateExtractValue(Call, i);
llvm::ConstantInt* Index = llvm::ConstantInt::get(IntTy, i);
- Value *GEP = Builder.CreateInBoundsGEP(Ptr, Index);
+ Value *GEP = Builder.CreateInBoundsGEP(VTy, Ptr, Index);
Builder.CreateAlignedStore(Vec, GEP, MaybeAlign(16));
}
return Call;
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index e687a0d25430..7fcc84bc7a09 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -272,7 +272,7 @@ ApplyNonVirtualAndVirtualOffset(CodeGenFunction &CGF, Address addr,
llvm::Value *ptr = addr.getPointer();
unsigned AddrSpace = ptr->getType()->getPointerAddressSpace();
ptr = CGF.Builder.CreateBitCast(ptr, CGF.Int8Ty->getPointerTo(AddrSpace));
- ptr = CGF.Builder.CreateInBoundsGEP(ptr, baseOffset, "add.ptr");
+ ptr = CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, ptr, baseOffset, "add.ptr");
// If we have a virtual component, the alignment of the result will
// be relative only to the known alignment of that vbase.
@@ -434,8 +434,8 @@ CodeGenFunction::GetAddressOfDerivedClass(Address BaseAddr,
// Apply the offset.
llvm::Value *Value = Builder.CreateBitCast(BaseAddr.getPointer(), Int8PtrTy);
- Value = Builder.CreateInBoundsGEP(Value, Builder.CreateNeg(NonVirtualOffset),
- "sub.ptr");
+ Value = Builder.CreateInBoundsGEP(
+ Int8Ty, Value, Builder.CreateNeg(NonVirtualOffset), "sub.ptr");
// Just cast.
Value = Builder.CreateBitCast(Value, DerivedPtrTy);
@@ -1963,9 +1963,10 @@ void CodeGenFunction::EmitCXXAggrConstructorCall(const CXXConstructorDecl *ctor,
}
// Find the end of the array.
+ llvm::Type *elementType = arrayBase.getElementType();
llvm::Value *arrayBegin = arrayBase.getPointer();
- llvm::Value *arrayEnd = Builder.CreateInBoundsGEP(arrayBegin, numElements,
- "arrayctor.end");
+ llvm::Value *arrayEnd = Builder.CreateInBoundsGEP(
+ elementType, arrayBegin, numElements, "arrayctor.end");
// Enter the loop, setting up a phi for the current location to initialize.
llvm::BasicBlock *entryBB = Builder.GetInsertBlock();
@@ -2023,9 +2024,8 @@ void CodeGenFunction::EmitCXXAggrConstructorCall(const CXXConstructorDecl *ctor,
}
// Go to the next element.
- llvm::Value *next =
- Builder.CreateInBoundsGEP(cur, llvm::ConstantInt::get(SizeTy, 1),
- "arrayctor.next");
+ llvm::Value *next = Builder.CreateInBoundsGEP(
+ elementType, cur, llvm::ConstantInt::get(SizeTy, 1), "arrayctor.next");
cur->addIncoming(next, Builder.GetInsertBlock());
// Check whether that's the end of the loop.
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 5a691ee303e4..243d93a8c165 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -1767,8 +1767,8 @@ void CodeGenFunction::emitZeroOrPatternForAutoVarInit(QualType type,
llvm::Value *BaseSizeInChars =
llvm::ConstantInt::get(IntPtrTy, EltSize.getQuantity());
Address Begin = Builder.CreateElementBitCast(Loc, Int8Ty, "vla.begin");
- llvm::Value *End =
- Builder.CreateInBoundsGEP(Begin.getPointer(), SizeVal, "vla.end");
+ llvm::Value *End = Builder.CreateInBoundsGEP(
+ Begin.getElementType(), Begin.getPointer(), SizeVal, "vla.end");
llvm::BasicBlock *OriginBB = Builder.GetInsertBlock();
EmitBlock(LoopBB);
llvm::PHINode *Cur = Builder.CreatePHI(Begin.getType(), 2, "vla.cur");
@@ -2196,7 +2196,8 @@ void CodeGenFunction::emitDestroy(Address addr, QualType type,
}
llvm::Value *begin = addr.getPointer();
- llvm::Value *end = Builder.CreateInBoundsGEP(begin, length);
+ llvm::Value *end =
+ Builder.CreateInBoundsGEP(addr.getElementType(), begin, length);
emitArrayDestroy(begin, end, type, elementAlign, destroyer,
checkZeroLength, useEHCleanupForArray);
}
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index b5bfae914ba4..18f1468dcb86 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -851,10 +851,9 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc,
llvm::ConstantInt::get(IntPtrTy,
CacheSize-1));
llvm::Value *Indices[] = { Builder.getInt32(0), Slot };
- llvm::Value *CacheVal =
- Builder.CreateAlignedLoad(IntPtrTy,
- Builder.CreateInBoundsGEP(Cache, Indices),
- getPointerAlign());
+ llvm::Value *CacheVal = Builder.CreateAlignedLoad(
+ IntPtrTy, Builder.CreateInBoundsGEP(HashTable, Cache, Indices),
+ getPointerAlign());
// If the hash isn't in the cache, call a runtime handler to perform the
// hard work of checking whether the vptr is for an object of the right
@@ -3569,6 +3568,7 @@ static const Expr *isSimpleArrayDecayOperand(const Expr *E) {
}
static llvm::Value *emitArraySubscriptGEP(CodeGenFunction &CGF,
+ llvm::Type *elemType,
llvm::Value *ptr,
ArrayRef<llvm::Value*> indices,
bool inbounds,
@@ -3580,7 +3580,7 @@ static llvm::Value *emitArraySubscriptGEP(CodeGenFunction &CGF,
CodeGenFunction::NotSubtraction, loc,
name);
} else {
- return CGF.Builder.CreateGEP(ptr, indices, name);
+ return CGF.Builder.CreateGEP(elemType, ptr, indices, name);
}
}
@@ -3674,8 +3674,8 @@ static Address emitArraySubscriptGEP(CodeGenFunction &CGF, Address addr,
if (!LastIndex ||
(!CGF.IsInPreservedAIRegion && !IsPreserveAIArrayBase(CGF, Base))) {
eltPtr = emitArraySubscriptGEP(
- CGF, addr.getPointer(), indices, inbounds, signedIndices,
- loc, name);
+ CGF, addr.getElementType(), addr.getPointer(), indices, inbounds,
+ signedIndices, loc, name);
} else {
// Remember the original array subscript for bpf target
unsigned idx = LastIndex->getZExtValue();
@@ -3800,8 +3800,8 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E,
CharUnits EltAlign =
getArrayElementAlign(Addr.getAlignment(), Idx, InterfaceSize);
llvm::Value *EltPtr =
- emitArraySubscriptGEP(*this, Addr.getPointer(), ScaledIdx, false,
- SignedIndices, E->getExprLoc());
+ emitArraySubscriptGEP(*this, Addr.getElementType(), Addr.getPointer(),
+ ScaledIdx, false, SignedIndices, E->getExprLoc());
Addr = Address(EltPtr, EltAlign);
// Cast back.
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index e1907a6f0680..b8608911edb2 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -1048,7 +1048,8 @@ void CodeGenFunction::EmitNewArrayInitializer(
cast<ConstantArrayType>(ILE->getType()->getAsArrayTypeUnsafe())
->getSize().getZExtValue();
CurPtr =
- Address(Builder.CreateInBoundsGEP(CurPtr.getPointer(),
+ Address(Builder.CreateInBoundsGEP(CurPtr.getElementType(),
+ CurPtr.getPointer(),
Builder.getSize(InitListElements),
"string.init.end"),
CurPtr.getAlignment().alignmentAtOffset(InitListElements *
@@ -1107,7 +1108,8 @@ void CodeGenFunction::EmitNewArrayInitializer(
StoreAnyExprIntoOneUnit(*this, ILE->getInit(i),
ILE->getInit(i)->getType(), CurPtr,
AggValueSlot::DoesNotOverlap);
- CurPtr = Address(Builder.CreateInBoundsGEP(CurPtr.getPointer(),
+ CurPtr = Address(Builder.CreateInBoundsGEP(CurPtr.getElementType(),
+ CurPtr.getPointer(),
Builder.getSize(1),
"array.exp.next"),
StartAlign.alignmentAtOffset((i + 1) * ElementSize));
@@ -1226,7 +1228,8 @@ void CodeGenFunction::EmitNewArrayInitializer(
// Find the end of the array, hoisted out of the loop.
llvm::Value *EndPtr =
- Builder.CreateInBoundsGEP(BeginPtr.getPointer(), NumElements, "array.end");
+ Builder.CreateInBoundsGEP(BeginPtr.getElementType(), BeginPtr.getPointer(),
+ NumElements, "array.end");
// If the number of elements isn't constant, we have to now check if there is
// anything left to initialize.
@@ -2034,8 +2037,8 @@ static void EmitArrayDelete(CodeGenFunction &CGF,
deletedPtr.getAlignment().alignmentOfArrayElement(elementSize);
llvm::Value *arrayBegin = deletedPtr.getPointer();
- llvm::Value *arrayEnd =
- CGF.Builder.CreateInBoundsGEP(arrayBegin, numElements, "delete.end");
+ llvm::Value *arrayEnd = CGF.Builder.CreateInBoundsGEP(
+ deletedPtr.getElementType(), arrayBegin, numElements, "delete.end");
// Note that it is legal to allocate a zero-length array, and we
// can never fold the check away because the length should always
@@ -2098,7 +2101,8 @@ void CodeGenFunction::EmitCXXDeleteExpr(const CXXDeleteExpr *E) {
GEP.push_back(Zero);
}
- Ptr = Address(Builder.CreateInBoundsGEP(Ptr.getPointer(), GEP, "del.first"),
+ Ptr = Address(Builder.CreateInBoundsGEP(Ptr.getElementType(),
+ Ptr.getPointer(), GEP, "del.first"),
Ptr.getAlignment());
}
diff --git a/clang/lib/CodeGen/CGNonTrivialStruct.cpp b/clang/lib/CodeGen/CGNonTrivialStruct.cpp
index bf164d242c7d..41915df7cb21 100644
--- a/clang/lib/CodeGen/CGNonTrivialStruct.cpp
+++ b/clang/lib/CodeGen/CGNonTrivialStruct.cpp
@@ -368,7 +368,7 @@ template <class Derived> struct GenFuncBase {
CGF.Builder.CreateNUWMul(BaseEltSizeVal, NumElts);
Address BC = CGF.Builder.CreateBitCast(DstAddr, CGF.CGM.Int8PtrTy);
llvm::Value *DstArrayEnd =
- CGF.Builder.CreateInBoundsGEP(BC.getPointer(), SizeInBytes);
+ CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, BC.getPointer(), SizeInBytes);
DstArrayEnd = CGF.Builder.CreateBitCast(DstArrayEnd, CGF.CGM.Int8PtrPtrTy,
"dstarray.end");
llvm::BasicBlock *PreheaderBB = CGF.Builder.GetInsertBlock();
diff --git a/clang/lib/CodeGen/CGObjCRuntime.cpp b/clang/lib/CodeGen/CGObjCRuntime.cpp
index 9bf4d83f9bc4..108f6fc7ba60 100644
--- a/clang/lib/CodeGen/CGObjCRuntime.cpp
+++ b/clang/lib/CodeGen/CGObjCRuntime.cpp
@@ -64,7 +64,7 @@ LValue CGObjCRuntime::EmitValueForIvarAtOffset(CodeGen::CodeGenFunction &CGF,
Ivar->getUsageType(ObjectPtrTy).withCVRQualifiers(CVRQualifiers);
llvm::Type *LTy = CGF.CGM.getTypes().ConvertTypeForMem(IvarTy);
llvm::Value *V = CGF.Builder.CreateBitCast(BaseValue, CGF.Int8PtrTy);
- V = CGF.Builder.CreateInBoundsGEP(V, Offset, "add.ptr");
+ V = CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, V, Offset, "add.ptr");
if (!Ivar->isBitField()) {
V = CGF.Builder.CreateBitCast(V, llvm::PointerType::getUnqual(LTy));
diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index 8e22f49aa119..0cef4f0a5684 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -1912,8 +1912,9 @@ void CGOpenMPRuntimeGPU::emitGenericVarsProlog(CodeGenFunction &CGF,
if (Rec.second.IsOnePerTeam) {
VarTy = Rec.second.FD->getType();
} else {
+ Address Addr = VarAddr.getAddress(CGF);
llvm::Value *Ptr = CGF.Builder.CreateInBoundsGEP(
- VarAddr.getAddress(CGF).getPointer(),
+ Addr.getElementType(), Addr.getPointer(),
{Bld.getInt32(0), getNVPTXLaneID(CGF)});
VarTy =
Rec.second.FD->getType()->castAsArrayTypeUnsafe()->getElementType();
@@ -2943,7 +2944,8 @@ static llvm::Value *emitInterWarpCopyFunction(CodeGenModule &CGM,
// Get pointer to location in transfer medium.
// MediumPtr = &medium[warp_id]
llvm::Value *MediumPtrVal = Bld.CreateInBoundsGEP(
- TransferMedium, {llvm::Constant::getNullValue(CGM.Int64Ty), WarpID});
+ TransferMedium->getValueType(), TransferMedium,
+ {llvm::Constant::getNullValue(CGM.Int64Ty), WarpID});
Address MediumPtr(MediumPtrVal, Align);
// Casting to actual data type.
// MediumPtr = (CopyType*)MediumPtrAddr;
@@ -2991,7 +2993,7 @@ static llvm::Value *emitInterWarpCopyFunction(CodeGenModule &CGM,
// SrcMediumPtr = &medium[tid]
llvm::Value *SrcMediumPtrVal = Bld.CreateInBoundsGEP(
- TransferMedium,
+ TransferMedium->getValueType(), TransferMedium,
{llvm::Constant::getNullValue(CGM.Int64Ty), ThreadID});
Address SrcMediumPtr(SrcMediumPtrVal, Align);
// SrcMediumVal = *SrcMediumPtr;
@@ -3327,9 +3329,10 @@ static llvm::Value *emitListToGlobalCopyFunction(
const FieldDecl *FD = VarFieldMap.lookup(VD);
LValue GlobLVal = CGF.EmitLValueForField(
CGF.MakeNaturalAlignAddrLValue(BufferArrPtr, StaticTy), FD);
- llvm::Value *BufferPtr =
- Bld.CreateInBoundsGEP(GlobLVal.getPointer(CGF), Idxs);
- GlobLVal.setAddress(Address(BufferPtr, GlobLVal.getAlignment()));
+ Address GlobAddr = GlobLVal.getAddress(CGF);
+ llvm::Value *BufferPtr = Bld.CreateInBoundsGEP(
+ GlobAddr.getElementType(), GlobAddr.getPointer(), Idxs);
+ GlobLVal.setAddress(Address(BufferPtr, GlobAddr.getAlignment()));
switch (CGF.getEvaluationKind(Private->getType())) {
case TEK_Scalar: {
llvm::Value *V = CGF.EmitLoadOfScalar(
@@ -3426,8 +3429,9 @@ static llvm::Value *emitListToGlobalReduceFunction(
const FieldDecl *FD = VarFieldMap.lookup(VD);
LValue GlobLVal = CGF.EmitLValueForField(
CGF.MakeNaturalAlignAddrLValue(BufferArrPtr, StaticTy), FD);
- llvm::Value *BufferPtr =
- Bld.CreateInBoundsGEP(GlobLVal.getPointer(CGF), Idxs);
+ Address GlobAddr = GlobLVal.getAddress(CGF);
+ llvm::Value *BufferPtr = Bld.CreateInBoundsGEP(
+ GlobAddr.getElementType(), GlobAddr.getPointer(), Idxs);
llvm::Value *Ptr = CGF.EmitCastToVoidPtr(BufferPtr);
CGF.EmitStoreOfScalar(Ptr, Elem, /*Volatile=*/false, C.VoidPtrTy);
if ((*IPriv)->getType()->isVariablyModifiedType()) {
@@ -3531,9 +3535,10 @@ static llvm::Value *emitGlobalToListCopyFunction(
const FieldDecl *FD = VarFieldMap.lookup(VD);
LValue GlobLVal = CGF.EmitLValueForField(
CGF.MakeNaturalAlignAddrLValue(BufferArrPtr, StaticTy), FD);
- llvm::Value *BufferPtr =
- Bld.CreateInBoundsGEP(GlobLVal.getPointer(CGF), Idxs);
- GlobLVal.setAddress(Address(BufferPtr, GlobLVal.getAlignment()));
+ Address GlobAddr = GlobLVal.getAddress(CGF);
+ llvm::Value *BufferPtr = Bld.CreateInBoundsGEP(
+ GlobAddr.getElementType(), GlobAddr.getPointer(), Idxs);
+ GlobLVal.setAddress(Address(BufferPtr, GlobAddr.getAlignment()));
switch (CGF.getEvaluationKind(Private->getType())) {
case TEK_Scalar: {
llvm::Value *V = CGF.EmitLoadOfScalar(GlobLVal, Loc);
@@ -3630,8 +3635,9 @@ static llvm::Value *emitGlobalToListReduceFunction(
const FieldDecl *FD = VarFieldMap.lookup(VD);
LValue GlobLVal = CGF.EmitLValueForField(
CGF.MakeNaturalAlignAddrLValue(BufferArrPtr, StaticTy), FD);
- llvm::Value *BufferPtr =
- Bld.CreateInBoundsGEP(GlobLVal.getPointer(CGF), Idxs);
+ Address GlobAddr = GlobLVal.getAddress(CGF);
+ llvm::Value *BufferPtr = Bld.CreateInBoundsGEP(
+ GlobAddr.getElementType(), GlobAddr.getPointer(), Idxs);
llvm::Value *Ptr = CGF.EmitCastToVoidPtr(BufferPtr);
CGF.EmitStoreOfScalar(Ptr, Elem, /*Volatile=*/false, C.VoidPtrTy);
if ((*IPriv)->getType()->isVariablyModifiedType()) {
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index 3a7d1ab03e68..a00ae74fa165 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1816,8 +1816,8 @@ static void emitNonZeroVLAInit(CodeGenFunction &CGF, QualType baseType,
Address begin =
Builder.CreateElementBitCast(dest, CGF.Int8Ty, "vla.begin");
- llvm::Value *end =
- Builder.CreateInBoundsGEP(begin.getPointer(), sizeInChars, "vla.end");
+ llvm::Value *end = Builder.CreateInBoundsGEP(
+ begin.getElementType(), begin.getPointer(), sizeInChars, "vla.end");
llvm::BasicBlock *originBB = CGF.Builder.GetInsertBlock();
llvm::BasicBlock *loopBB = CGF.createBasicBlock("vla-init.loop");
@@ -2024,9 +2024,9 @@ llvm::Value *CodeGenFunction::emitArrayLength(const ArrayType *origArrayType,
addr = Builder.CreateElementBitCast(addr, baseType, "array.begin");
} else {
// Create the actual GEP.
- addr = Address(Builder.CreateInBoundsGEP(addr.getPointer(),
- gepIndices, "array.begin"),
- addr.getAlignment());
+ addr = Address(Builder.CreateInBoundsGEP(
+ addr.getElementType(), addr.getPointer(), gepIndices, "array.begin"),
+ addr.getAlignment());
}
baseType = eltType;
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 2a6a07e91ce1..e0cbcb238d1c 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -651,7 +651,7 @@ CGCallee ItaniumCXXABI::EmitLoadOfMemberFunctionPointer(
// for consistency.
llvm::Value *This = ThisAddr.getPointer();
llvm::Value *Ptr = Builder.CreateBitCast(This, Builder.getInt8PtrTy());
- Ptr = Builder.CreateInBoundsGEP(Ptr, Adj);
+ Ptr = Builder.CreateInBoundsGEP(Builder.getInt8Ty(), Ptr, Adj);
This = Builder.CreateBitCast(Ptr, This->getType(), "this.adjusted");
ThisPtrForCall = This;
@@ -859,8 +859,8 @@ llvm::Value *ItaniumCXXABI::EmitMemberDataPointerAddress(
Base = Builder.CreateElementBitCast(Base, CGF.Int8Ty);
// Apply the offset, which we assume is non-null.
- llvm::Value *Addr =
- Builder.CreateInBoundsGEP(Base.getPointer(), MemPtr, "memptr.offset");
+ llvm::Value *Addr = Builder.CreateInBoundsGEP(
+ Base.getElementType(), Base.getPointer(), MemPtr, "memptr.offset");
// Cast the address to the appropriate pointer type, adopting the
// address space of the base pointer.
@@ -1260,7 +1260,8 @@ void ItaniumCXXABI::emitVirtualObjectDelete(CodeGenFunction &CGF,
// Apply the offset.
llvm::Value *CompletePtr =
CGF.Builder.CreateBitCast(Ptr.getPointer(), CGF.Int8PtrTy);
- CompletePtr = CGF.Builder.CreateInBoundsGEP(CompletePtr, Offset);
+ CompletePtr =
+ CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, CompletePtr, Offset);
// If we're supposed to call the global delete, make sure we do so
// even if the destructor throws.
@@ -1553,7 +1554,7 @@ llvm::Value *ItaniumCXXABI::EmitDynamicCastToVoid(CodeGenFunction &CGF,
// Finally, add the offset to the pointer.
llvm::Value *Value = ThisAddr.getPointer();
Value = CGF.EmitCastToVoidPtr(Value);
- Value = CGF.Builder.CreateInBoundsGEP(Value, OffsetToTop);
+ Value = CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, Value, OffsetToTop);
return CGF.Builder.CreateBitCast(Value, DestLTy);
}
@@ -2086,7 +2087,8 @@ static llvm::Value *performTypeAdjustment(CodeGenFunction &CGF,
CGF.getPointerAlign());
}
// Adjust our pointer.
- ResultPtr = CGF.Builder.CreateInBoundsGEP(V.getPointer(), Offset);
+ ResultPtr = CGF.Builder.CreateInBoundsGEP(
+ V.getElementType(), V.getPointer(), Offset);
} else {
ResultPtr = V.getPointer();
}
diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index 2c7dfee5ead4..f2a350cf9087 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -937,7 +937,8 @@ MicrosoftCXXABI::performBaseAdjustment(CodeGenFunction &CGF, Address Value,
llvm::Value *Offset =
GetVirtualBaseClassOffset(CGF, Value, SrcDecl, PolymorphicBase);
- llvm::Value *Ptr = CGF.Builder.CreateInBoundsGEP(Value.getPointer(), Offset);
+ llvm::Value *Ptr = CGF.Builder.CreateInBoundsGEP(
+ Value.getElementType(), Value.getPointer(), Offset);
CharUnits VBaseAlign =
CGF.CGM.getVBaseAlignment(Value.getAlignment(), SrcDecl, PolymorphicBase);
return std::make_tuple(Address(Ptr, VBaseAlign), Offset, PolymorphicBase);
@@ -1219,7 +1220,8 @@ void MicrosoftCXXABI::initializeHiddenVirtualInheritanceMembers(
if (!Int8This)
Int8This = Builder.CreateBitCast(getThisValue(CGF),
CGF.Int8Ty->getPointerTo(AS));
- llvm::Value *VtorDispPtr = Builder.CreateInBoundsGEP(Int8This, VBaseOffset);
+ llvm::Value *VtorDispPtr =
+ Builder.CreateInBoundsGEP(CGF.Int8Ty, Int8This, VBaseOffset);
// vtorDisp is always the 32-bits before the vbase in the class layout.
VtorDispPtr = Builder.CreateConstGEP1_32(VtorDispPtr, -4);
VtorDispPtr = Builder.CreateBitCast(
@@ -1457,8 +1459,8 @@ Address MicrosoftCXXABI::adjustThisArgumentForVirtualFunctionCall(
const CXXRecordDecl *VBase = ML.VBase;
llvm::Value *VBaseOffset =
GetVirtualBaseClassOffset(CGF, Result, Derived, VBase);
- llvm::Value *VBasePtr =
- CGF.Builder.CreateInBoundsGEP(Result.getPointer(), VBaseOffset);
+ llvm::Value *VBasePtr = CGF.Builder.CreateInBoundsGEP(
+ Result.getElementType(), Result.getPointer(), VBaseOffset);
CharUnits VBaseAlign =
CGF.CGM.getVBaseAlignment(Result.getAlignment(), Derived, VBase);
Result = Address(VBasePtr, VBaseAlign);
@@ -2213,7 +2215,7 @@ llvm::Value *MicrosoftCXXABI::performThisAdjustment(CodeGenFunction &CGF,
GetVBaseOffsetFromVBPtr(CGF, Address(V, CGF.getPointerAlign()),
-TA.Virtual.Microsoft.VBPtrOffset,
TA.Virtual.Microsoft.VBOffsetOffset, &VBPtr);
- V = CGF.Builder.CreateInBoundsGEP(VBPtr, VBaseOffset);
+ V = CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, VBPtr, VBaseOffset);
}
}
@@ -2245,7 +2247,7 @@ MicrosoftCXXABI::performReturnAdjustment(CodeGenFunction &CGF, Address Ret,
llvm::Value *VBaseOffset =
GetVBaseOffsetFromVBPtr(CGF, Ret, RA.Virtual.Microsoft.VBPtrOffset,
IntSize * RA.Virtual.Microsoft.VBIndex, &VBPtr);
- V = CGF.Builder.CreateInBoundsGEP(VBPtr, VBaseOffset);
+ V = CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, VBPtr, VBaseOffset);
}
if (RA.NonVirtual)
@@ -3010,8 +3012,8 @@ MicrosoftCXXABI::GetVBaseOffsetFromVBPtr(CodeGenFunction &CGF,
CGBuilderTy &Builder = CGF.Builder;
// Load the vbtable pointer from the vbptr in the instance.
This = Builder.CreateElementBitCast(This, CGM.Int8Ty);
- llvm::Value *VBPtr =
- Builder.CreateInBoundsGEP(This.getPointer(), VBPtrOffset, "vbptr");
+ llvm::Value *VBPtr = Builder.CreateInBoundsGEP(
+ This.getElementType(), This.getPointer(), VBPtrOffset, "vbptr");
if (VBPtrOut) *VBPtrOut = VBPtr;
VBPtr = Builder.CreateBitCast(VBPtr,
CGM.Int32Ty->getPointerTo(0)->getPointerTo(This.getAddressSpace()));
@@ -3033,7 +3035,8 @@ MicrosoftCXXABI::GetVBaseOffsetFromVBPtr(CodeGenFunction &CGF,
"vbtindex", /*isExact=*/true);
// Load an i32 offset from the vb-table.
- llvm::Value *VBaseOffs = Builder.CreateInBoundsGEP(VBTable, VBTableIndex);
+ llvm::Value *VBaseOffs =
+ Builder.CreateInBoundsGEP(CGM.Int32Ty, VBTable, VBTableIndex);
VBaseOffs = Builder.CreateBitCast(VBaseOffs, CGM.Int32Ty->getPointerTo(0));
return Builder.CreateAlignedLoad(CGM.Int32Ty, VBaseOffs,
CharUnits::fromQuantity(4), "vbase_offs");
@@ -3083,7 +3086,8 @@ llvm::Value *MicrosoftCXXABI::AdjustVirtualBase(
llvm::Value *VBPtr = nullptr;
llvm::Value *VBaseOffs =
GetVBaseOffsetFromVBPtr(CGF, Base, VBPtrOffset, VBTableOffset, &VBPtr);
- llvm::Value *AdjustedBase = Builder.CreateInBoundsGEP(VBPtr, VBaseOffs);
+ llvm::Value *AdjustedBase =
+ Builder.CreateInBoundsGEP(CGM.Int8Ty, VBPtr, VBaseOffs);
// Merge control flow with the case where we didn't have to adjust.
if (VBaseAdjustBB) {
@@ -3135,7 +3139,8 @@ llvm::Value *MicrosoftCXXABI::EmitMemberDataPointerAddress(
Addr = Builder.CreateBitCast(Addr, CGF.Int8Ty->getPointerTo(AS));
// Apply the offset, which we assume is non-null.
- Addr = Builder.CreateInBoundsGEP(Addr, FieldOffset, "memptr.offset");
+ Addr = Builder.CreateInBoundsGEP(CGF.Int8Ty, Addr, FieldOffset,
+ "memptr.offset");
// Cast the address to the appropriate pointer type, adopting the address
// space of the base pointer.
@@ -3297,10 +3302,10 @@ llvm::Value *MicrosoftCXXABI::EmitNonNullMemberPointerConversion(
Mapping->getAggregateElement(cast<llvm::Constant>(VBIndex));
} else {
llvm::Value *Idxs[] = {getZeroInt(), VBIndex};
- VirtualBaseAdjustmentOffset =
- Builder.CreateAlignedLoad(CGM.IntTy,
- Builder.CreateInBoundsGEP(VDispMap, Idxs),
- CharUnits::fromQuantity(4));
+ VirtualBaseAdjustmentOffset = Builder.CreateAlignedLoad(
+ CGM.IntTy, Builder.CreateInBoundsGEP(VDispMap->getValueType(),
+ VDispMap, Idxs),
+ CharUnits::fromQuantity(4));
}
DstVBIndexEqZero =
@@ -3430,7 +3435,7 @@ CGCallee MicrosoftCXXABI::EmitLoadOfMemberFunctionPointer(
if (NonVirtualBaseAdjustment) {
// Apply the adjustment and cast back to the original struct type.
llvm::Value *Ptr = Builder.CreateBitCast(ThisPtrForCall, CGF.Int8PtrTy);
- Ptr = Builder.CreateInBoundsGEP(Ptr, NonVirtualBaseAdjustment);
+ Ptr = Builder.CreateInBoundsGEP(CGF.Int8Ty, Ptr, NonVirtualBaseAdjustment);
ThisPtrForCall = Builder.CreateBitCast(Ptr, ThisPtrForCall->getType(),
"this.adjusted");
}
diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp
index f4427967da9f..4f5b928f1fe6 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -5946,7 +5946,7 @@ Address AArch64ABIInfo::EmitAAPCSVAArg(Address VAListAddr,
Address reg_top_p =
CGF.Builder.CreateStructGEP(VAListAddr, reg_top_index, "reg_top_p");
reg_top = CGF.Builder.CreateLoad(reg_top_p, "reg_top");
- Address BaseAddr(CGF.Builder.CreateInBoundsGEP(reg_top, reg_offs),
+ Address BaseAddr(CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, reg_top, reg_offs),
CharUnits::fromQuantity(IsFPR ? 16 : 8));
Address RegAddr = Address::invalid();
llvm::Type *MemTy = CGF.ConvertTypeForMem(Ty);
@@ -6044,8 +6044,8 @@ Address AArch64ABIInfo::EmitAAPCSVAArg(Address VAListAddr,
StackSize = TySize.alignTo(StackSlotSize);
llvm::Value *StackSizeC = CGF.Builder.getSize(StackSize);
- llvm::Value *NewStack =
- CGF.Builder.CreateInBoundsGEP(OnStackPtr, StackSizeC, "new_stack");
+ llvm::Value *NewStack = CGF.Builder.CreateInBoundsGEP(
+ CGF.Int8Ty, OnStackPtr, StackSizeC, "new_stack");
// Write the new value of __stack for the next call to va_arg
CGF.Builder.CreateStore(NewStack, stack_p);
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 9de4261f25c6..0f698dd3b190 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -5526,12 +5526,14 @@ bool CodeGenPrepare::optimizeGatherScatterInst(Instruction *MemoryInst,
IRBuilder<> Builder(MemoryInst);
+ Type *SourceTy = GEP->getSourceElementType();
Type *ScalarIndexTy = DL->getIndexType(Ops[0]->getType()->getScalarType());
// If the final index isn't a vector, emit a scalar GEP containing all ops
// and a vector GEP with all zeroes final index.
if (!Ops[FinalIndex]->getType()->isVectorTy()) {
- NewAddr = Builder.CreateGEP(Ops[0], makeArrayRef(Ops).drop_front());
+ NewAddr = Builder.CreateGEP(SourceTy, Ops[0],
+ makeArrayRef(Ops).drop_front());
auto *IndexTy = VectorType::get(ScalarIndexTy, NumElts);
NewAddr = Builder.CreateGEP(NewAddr, Constant::getNullValue(IndexTy));
} else {
@@ -5542,7 +5544,8 @@ bool CodeGenPrepare::optimizeGatherScatterInst(Instruction *MemoryInst,
if (Ops.size() != 2) {
// Replace the last index with 0.
Ops[FinalIndex] = Constant::getNullValue(ScalarIndexTy);
- Base = Builder.CreateGEP(Base, makeArrayRef(Ops).drop_front());
+ Base = Builder.CreateGEP(SourceTy, Base,
+ makeArrayRef(Ops).drop_front());
}
// Now create the GEP with scalar pointer and vector index.
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 975ace6799d1..6bc12fa3b5f1 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -1842,10 +1842,11 @@ static Instruction *foldSelectGEP(GetElementPtrInst &GEP,
// Note: using IRBuilder to create the constants for efficiency.
SmallVector<Value *, 4> IndexC(GEP.indices());
bool IsInBounds = GEP.isInBounds();
- Value *NewTrueC = IsInBounds ? Builder.CreateInBoundsGEP(TrueC, IndexC)
- : Builder.CreateGEP(TrueC, IndexC);
- Value *NewFalseC = IsInBounds ? Builder.CreateInBoundsGEP(FalseC, IndexC)
- : Builder.CreateGEP(FalseC, IndexC);
+ Type *Ty = GEP.getSourceElementType();
+ Value *NewTrueC = IsInBounds ? Builder.CreateInBoundsGEP(Ty, TrueC, IndexC)
+ : Builder.CreateGEP(Ty, TrueC, IndexC);
+ Value *NewFalseC = IsInBounds ? Builder.CreateInBoundsGEP(Ty, FalseC, IndexC)
+ : Builder.CreateGEP(Ty, FalseC, IndexC);
return SelectInst::Create(Cond, NewTrueC, NewFalseC, "", nullptr, Sel);
}
diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp
index af510f1a84bf..b36458012aa9 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -3488,20 +3488,22 @@ class AggLoadStoreRewriter : public InstVisitor<AggLoadStoreRewriter, bool> {
SmallVector<Value *, 4> Index(GEPI.indices());
bool IsInBounds = GEPI.isInBounds();
+ Type *Ty = GEPI.getSourceElementType();
Value *True = Sel->getTrueValue();
Value *NTrue =
IsInBounds
- ? Builder.CreateInBoundsGEP(True, Index,
+ ? Builder.CreateInBoundsGEP(Ty, True, Index,
True->getName() + ".sroa.gep")
- : Builder.CreateGEP(True, Index, True->getName() + ".sroa.gep");
+ : Builder.CreateGEP(Ty, True, Index, True->getName() + ".sroa.gep");
Value *False = Sel->getFalseValue();
Value *NFalse =
IsInBounds
- ? Builder.CreateInBoundsGEP(False, Index,
+ ? Builder.CreateInBoundsGEP(Ty, False, Index,
False->getName() + ".sroa.gep")
- : Builder.CreateGEP(False, Index, False->getName() + ".sroa.gep");
+ : Builder.CreateGEP(Ty, False, Index,
+ False->getName() + ".sroa.gep");
Value *NSel = Builder.CreateSelect(Sel->getCondition(), NTrue, NFalse,
Sel->getName() + ".sroa.sel");
@@ -3555,9 +3557,10 @@ class AggLoadStoreRewriter : public InstVisitor<AggLoadStoreRewriter, bool> {
Instruction *In = cast<Instruction>(PHI->getIncomingValue(I));
IRBuilderTy B(In->getParent(), std::next(In->getIterator()));
+ Type *Ty = GEPI.getSourceElementType();
NewVal = IsInBounds
- ? B.CreateInBoundsGEP(In, Index, In->getName() + ".sroa.gep")
- : B.CreateGEP(In, Index, In->getName() + ".sroa.gep");
+ ? B.CreateInBoundsGEP(Ty, In, Index, In->getName() + ".sroa.gep")
+ : B.CreateGEP(Ty, In, Index, In->getName() + ".sroa.gep");
}
NewPN->addIncoming(NewVal, B);
}
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index e118d5365a0b..ddc0ed32fd7a 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -320,8 +320,11 @@ def LLVM_AllocaOp : LLVM_Op<"alloca">, MemoryOpWithAlignmentBase {
let printer = [{ printAllocaOp(p, *this); }];
}
-def LLVM_GEPOp : LLVM_Op<"getelementptr", [NoSideEffect]>,
- LLVM_Builder<"$res = builder.CreateGEP($base, $indices);"> {
+def LLVM_GEPOp
+ : LLVM_Op<"getelementptr", [NoSideEffect]>,
+ LLVM_Builder<
+ "$res = builder.CreateGEP("
+ " $base->getType()->getPointerElementType(), $base, $indices);"> {
let arguments = (ins LLVM_ScalarOrVectorOf<LLVM_AnyPointer>:$base,
Variadic<LLVM_ScalarOrVectorOf<LLVM_AnyInteger>>:$indices);
let results = (outs LLVM_ScalarOrVectorOf<LLVM_AnyPointer>:$res);
diff --git a/polly/lib/CodeGen/RuntimeDebugBuilder.cpp b/polly/lib/CodeGen/RuntimeDebugBuilder.cpp
index 2a349fe0f2b9..d7d8348f113f 100644
--- a/polly/lib/CodeGen/RuntimeDebugBuilder.cpp
+++ b/polly/lib/CodeGen/RuntimeDebugBuilder.cpp
@@ -188,7 +188,7 @@ void RuntimeDebugBuilder::createGPUPrinterT(PollyIRBuilder &Builder,
Value *Data = new AllocaInst(
T, DL.getAllocaAddrSpace(), "polly.vprint.buffer",
&Builder.GetInsertBlock()->getParent()->getEntryBlock().front());
- auto *DataPtr = Builder.CreateGEP(Data, {Zero, Zero});
+ auto *DataPtr = Builder.CreateGEP(T, Data, {Zero, Zero});
int Offset = 0;
for (auto Val : ToPrint) {
More information about the Mlir-commits
mailing list