[clang] 474ec69 - [clang] Replace uses of CGBuilderTy::CreateElementBitCast (NFC)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 27 07:40:08 PDT 2023
Author: Youngsuk Kim
Date: 2023-06-27T10:38:54-04:00
New Revision: 474ec694191a51d7f30a11f8b03dee911c8ef346
URL: https://github.com/llvm/llvm-project/commit/474ec694191a51d7f30a11f8b03dee911c8ef346
DIFF: https://github.com/llvm/llvm-project/commit/474ec694191a51d7f30a11f8b03dee911c8ef346.diff
LOG: [clang] Replace uses of CGBuilderTy::CreateElementBitCast (NFC)
Partial progress towards replacing `CreateElementBitCast`, as it no
longer does what its name suggests. Either replace its uses with
`Address::withElementType()`, or remove them if no longer needed.
Reviewed By: barannikov88, nikic
Differential Revision: https://reviews.llvm.org/D153314
Added:
Modified:
clang/lib/CodeGen/CGAtomic.cpp
clang/lib/CodeGen/CGCXXABI.cpp
clang/lib/CodeGen/CGNonTrivialStruct.cpp
clang/lib/CodeGen/MicrosoftCXXABI.cpp
clang/lib/CodeGen/Targets/AArch64.cpp
clang/lib/CodeGen/Targets/ARM.cpp
clang/lib/CodeGen/Targets/Hexagon.cpp
clang/lib/CodeGen/Targets/LoongArch.cpp
clang/lib/CodeGen/Targets/PPC.cpp
clang/lib/CodeGen/Targets/X86.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index 6740df8270b3d..f191829b41552 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -162,7 +162,7 @@ namespace {
}
Address getAtomicAddressAsAtomicIntPointer() const {
- return emitCastToAtomicIntPointer(getAtomicAddress());
+ return castToAtomicIntPointer(getAtomicAddress());
}
/// Is the atomic size larger than the underlying value type?
@@ -184,7 +184,7 @@ namespace {
/// Cast the given pointer to an integer pointer suitable for atomic
/// operations if the source.
- Address emitCastToAtomicIntPointer(Address Addr) const;
+ Address castToAtomicIntPointer(Address Addr) const;
/// If Addr is compatible with the iN that will be used for an atomic
/// operation, bitcast it. Otherwise, create a temporary that is suitable
@@ -979,7 +979,7 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
AtomicInfo Atomics(*this, AtomicVal);
if (ShouldCastToIntPtrTy) {
- Ptr = Atomics.emitCastToAtomicIntPointer(Ptr);
+ Ptr = Atomics.castToAtomicIntPointer(Ptr);
if (Val1.isValid())
Val1 = Atomics.convertToAtomicIntPointer(Val1);
if (Val2.isValid())
@@ -987,13 +987,13 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
}
if (Dest.isValid()) {
if (ShouldCastToIntPtrTy)
- Dest = Atomics.emitCastToAtomicIntPointer(Dest);
+ Dest = Atomics.castToAtomicIntPointer(Dest);
} else if (E->isCmpXChg())
Dest = CreateMemTemp(RValTy, "cmpxchg.bool");
else if (!RValTy->isVoidType()) {
Dest = Atomics.CreateTempAlloca();
if (ShouldCastToIntPtrTy)
- Dest = Atomics.emitCastToAtomicIntPointer(Dest);
+ Dest = Atomics.castToAtomicIntPointer(Dest);
}
// Use a library call. See: http://gcc.gnu.org/wiki/Atomic/GCCMM/LIbrary .
@@ -1338,16 +1338,14 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
if (E->getOp() == AtomicExpr::AO__atomic_nand_fetch)
ResVal = Builder.CreateNot(ResVal);
- Builder.CreateStore(
- ResVal, Builder.CreateElementBitCast(Dest, ResVal->getType()));
+ Builder.CreateStore(ResVal, Dest.withElementType(ResVal->getType()));
}
if (RValTy->isVoidType())
return RValue::get(nullptr);
- return convertTempToRValue(
- Builder.CreateElementBitCast(Dest, ConvertTypeForMem(RValTy)),
- RValTy, E->getExprLoc());
+ return convertTempToRValue(Dest.withElementType(ConvertTypeForMem(RValTy)),
+ RValTy, E->getExprLoc());
}
bool IsStore = E->getOp() == AtomicExpr::AO__c11_atomic_store ||
@@ -1398,9 +1396,8 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
if (RValTy->isVoidType())
return RValue::get(nullptr);
- return convertTempToRValue(
- Builder.CreateElementBitCast(Dest, ConvertTypeForMem(RValTy)),
- RValTy, E->getExprLoc());
+ return convertTempToRValue(Dest.withElementType(ConvertTypeForMem(RValTy)),
+ RValTy, E->getExprLoc());
}
// Long case, when Order isn't obviously constant.
@@ -1470,15 +1467,14 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
return RValue::get(nullptr);
assert(Atomics.getValueSizeInBits() <= Atomics.getAtomicSizeInBits());
- return convertTempToRValue(
- Builder.CreateElementBitCast(Dest, ConvertTypeForMem(RValTy)),
- RValTy, E->getExprLoc());
+ return convertTempToRValue(Dest.withElementType(ConvertTypeForMem(RValTy)),
+ RValTy, E->getExprLoc());
}
-Address AtomicInfo::emitCastToAtomicIntPointer(Address addr) const {
+Address AtomicInfo::castToAtomicIntPointer(Address addr) const {
llvm::IntegerType *ty =
llvm::IntegerType::get(CGF.getLLVMContext(), AtomicSizeInBits);
- return CGF.Builder.CreateElementBitCast(addr, ty);
+ return addr.withElementType(ty);
}
Address AtomicInfo::convertToAtomicIntPointer(Address Addr) const {
@@ -1491,7 +1487,7 @@ Address AtomicInfo::convertToAtomicIntPointer(Address Addr) const {
Addr = Tmp;
}
- return emitCastToAtomicIntPointer(Addr);
+ return castToAtomicIntPointer(Addr);
}
RValue AtomicInfo::convertAtomicTempToRValue(Address addr,
@@ -1563,7 +1559,7 @@ RValue AtomicInfo::ConvertIntToValueOrAtomic(llvm::Value *IntVal,
}
// Slam the integer into the temporary.
- Address CastTemp = emitCastToAtomicIntPointer(Temp);
+ Address CastTemp = castToAtomicIntPointer(Temp);
CGF.Builder.CreateStore(IntVal, CastTemp)
->setVolatile(TempIsVolatile);
@@ -1741,7 +1737,7 @@ llvm::Value *AtomicInfo::convertRValueToInt(RValue RVal) const {
Address Addr = materializeRValue(RVal);
// Cast the temporary to the atomic int type and pull a value out.
- Addr = emitCastToAtomicIntPointer(Addr);
+ Addr = castToAtomicIntPointer(Addr);
return CGF.Builder.CreateLoad(Addr);
}
@@ -1919,7 +1915,7 @@ void AtomicInfo::EmitAtomicUpdateOp(
/*NumReservedValues=*/2);
PHI->addIncoming(OldVal, CurBB);
Address NewAtomicAddr = CreateTempAlloca();
- Address NewAtomicIntAddr = emitCastToAtomicIntPointer(NewAtomicAddr);
+ Address NewAtomicIntAddr = castToAtomicIntPointer(NewAtomicAddr);
if ((LVal.isBitField() && BFI.Size != ValueSizeInBits) ||
requiresMemSetZero(getAtomicAddress().getElementType())) {
CGF.Builder.CreateStore(PHI, NewAtomicIntAddr);
@@ -2001,7 +1997,7 @@ void AtomicInfo::EmitAtomicUpdateOp(llvm::AtomicOrdering AO, RValue UpdateRVal,
/*NumReservedValues=*/2);
PHI->addIncoming(OldVal, CurBB);
Address NewAtomicAddr = CreateTempAlloca();
- Address NewAtomicIntAddr = emitCastToAtomicIntPointer(NewAtomicAddr);
+ Address NewAtomicIntAddr = castToAtomicIntPointer(NewAtomicAddr);
if ((LVal.isBitField() && BFI.Size != ValueSizeInBits) ||
requiresMemSetZero(getAtomicAddress().getElementType())) {
CGF.Builder.CreateStore(PHI, NewAtomicIntAddr);
@@ -2095,8 +2091,7 @@ void CodeGenFunction::EmitAtomicStore(RValue rvalue, LValue dest,
llvm::Value *intValue = atomics.convertRValueToInt(rvalue);
// Do the atomic store.
- Address addr =
- atomics.emitCastToAtomicIntPointer(atomics.getAtomicAddress());
+ Address addr = atomics.castToAtomicIntPointer(atomics.getAtomicAddress());
intValue = Builder.CreateIntCast(
intValue, addr.getElementType(), /*isSigned=*/false);
llvm::StoreInst *store = Builder.CreateStore(intValue, addr);
diff --git a/clang/lib/CodeGen/CGCXXABI.cpp b/clang/lib/CodeGen/CGCXXABI.cpp
index 1ce8100193b15..7b77dd7875bc6 100644
--- a/clang/lib/CodeGen/CGCXXABI.cpp
+++ b/clang/lib/CodeGen/CGCXXABI.cpp
@@ -247,7 +247,7 @@ void CGCXXABI::ReadArrayCookie(CodeGenFunction &CGF, Address ptr,
llvm::Value *&numElements,
llvm::Value *&allocPtr, CharUnits &cookieSize) {
// Derive a char* in the same address space as the pointer.
- ptr = CGF.Builder.CreateElementBitCast(ptr, CGF.Int8Ty);
+ ptr = ptr.withElementType(CGF.Int8Ty);
// If we don't need an array cookie, bail out early.
if (!requiresArrayCookie(expr, eltTy)) {
diff --git a/clang/lib/CodeGen/CGNonTrivialStruct.cpp b/clang/lib/CodeGen/CGNonTrivialStruct.cpp
index 98378e1386414..3d2b1b8b2f78d 100644
--- a/clang/lib/CodeGen/CGNonTrivialStruct.cpp
+++ b/clang/lib/CodeGen/CGNonTrivialStruct.cpp
@@ -365,9 +365,8 @@ template <class Derived> struct GenFuncBase {
llvm::ConstantInt::get(NumElts->getType(), BaseEltSize);
llvm::Value *SizeInBytes =
CGF.Builder.CreateNUWMul(BaseEltSizeVal, NumElts);
- Address BC = CGF.Builder.CreateElementBitCast(DstAddr, CGF.CGM.Int8Ty);
- llvm::Value *DstArrayEnd =
- CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, BC.getPointer(), SizeInBytes);
+ llvm::Value *DstArrayEnd = CGF.Builder.CreateInBoundsGEP(
+ CGF.Int8Ty, DstAddr.getPointer(), SizeInBytes);
DstArrayEnd = CGF.Builder.CreateBitCast(
DstArrayEnd, CGF.CGM.Int8PtrPtrTy, "dstarray.end");
llvm::BasicBlock *PreheaderBB = CGF.Builder.GetInsertBlock();
@@ -426,9 +425,9 @@ template <class Derived> struct GenFuncBase {
assert(Addr.isValid() && "invalid address");
if (Offset.getQuantity() == 0)
return Addr;
- Addr = CGF->Builder.CreateElementBitCast(Addr, CGF->CGM.Int8Ty);
+ Addr = Addr.withElementType(CGF->CGM.Int8Ty);
Addr = CGF->Builder.CreateConstInBoundsGEP(Addr, Offset.getQuantity());
- return CGF->Builder.CreateElementBitCast(Addr, CGF->CGM.Int8PtrTy);
+ return Addr.withElementType(CGF->CGM.Int8PtrTy);
}
Address getAddrWithOffset(Address Addr, CharUnits StructFieldOffset,
@@ -491,8 +490,7 @@ template <class Derived> struct GenFuncBase {
for (unsigned I = 0; I < N; ++I) {
Alignments[I] = Addrs[I].getAlignment();
- Ptrs[I] = CallerCGF.Builder.CreateElementBitCast(
- Addrs[I], CallerCGF.CGM.Int8PtrTy).getPointer();
+ Ptrs[I] = Addrs[I].getPointer();
}
if (llvm::Function *F =
@@ -526,17 +524,15 @@ struct GenBinaryFunc : CopyStructVisitor<Derived, IsMove>,
!llvm::has_single_bit<uint32_t>(Size.getQuantity())) {
llvm::Value *SizeVal =
llvm::ConstantInt::get(this->CGF->SizeTy, Size.getQuantity());
- DstAddr =
- this->CGF->Builder.CreateElementBitCast(DstAddr, this->CGF->Int8Ty);
- SrcAddr =
- this->CGF->Builder.CreateElementBitCast(SrcAddr, this->CGF->Int8Ty);
+ DstAddr = DstAddr.withElementType(this->CGF->Int8Ty);
+ SrcAddr = SrcAddr.withElementType(this->CGF->Int8Ty);
this->CGF->Builder.CreateMemCpy(DstAddr, SrcAddr, SizeVal, false);
} else {
llvm::Type *Ty = llvm::Type::getIntNTy(
this->CGF->getLLVMContext(),
Size.getQuantity() * this->CGF->getContext().getCharWidth());
- DstAddr = this->CGF->Builder.CreateElementBitCast(DstAddr, Ty);
- SrcAddr = this->CGF->Builder.CreateElementBitCast(SrcAddr, Ty);
+ DstAddr = DstAddr.withElementType(Ty);
+ SrcAddr = SrcAddr.withElementType(Ty);
llvm::Value *SrcVal = this->CGF->Builder.CreateLoad(SrcAddr, false);
this->CGF->Builder.CreateStore(SrcVal, DstAddr, false);
}
@@ -556,19 +552,17 @@ struct GenBinaryFunc : CopyStructVisitor<Derived, IsMove>,
QualType RT = QualType(FD->getParent()->getTypeForDecl(), 0);
llvm::Type *Ty = this->CGF->ConvertType(RT);
Address DstAddr = this->getAddrWithOffset(Addrs[DstIdx], Offset);
- LValue DstBase = this->CGF->MakeAddrLValue(
- this->CGF->Builder.CreateElementBitCast(DstAddr, Ty), FT);
+ LValue DstBase =
+ this->CGF->MakeAddrLValue(DstAddr.withElementType(Ty), FT);
DstLV = this->CGF->EmitLValueForField(DstBase, FD);
Address SrcAddr = this->getAddrWithOffset(Addrs[SrcIdx], Offset);
- LValue SrcBase = this->CGF->MakeAddrLValue(
- this->CGF->Builder.CreateElementBitCast(SrcAddr, Ty), FT);
+ LValue SrcBase =
+ this->CGF->MakeAddrLValue(SrcAddr.withElementType(Ty), FT);
SrcLV = this->CGF->EmitLValueForField(SrcBase, FD);
} else {
llvm::Type *Ty = this->CGF->ConvertTypeForMem(FT);
- Address DstAddr =
- this->CGF->Builder.CreateElementBitCast(Addrs[DstIdx], Ty);
- Address SrcAddr =
- this->CGF->Builder.CreateElementBitCast(Addrs[SrcIdx], Ty);
+ Address DstAddr = Addrs[DstIdx].withElementType(Ty);
+ Address SrcAddr = Addrs[SrcIdx].withElementType(Ty);
DstLV = this->CGF->MakeAddrLValue(DstAddr, FT);
SrcLV = this->CGF->MakeAddrLValue(SrcAddr, FT);
}
@@ -666,7 +660,7 @@ struct GenDefaultInitialize
llvm::Constant *SizeVal = CGF->Builder.getInt64(Size.getQuantity());
Address DstAddr = getAddrWithOffset(Addrs[DstIdx], CurStructOffset, FD);
- Address Loc = CGF->Builder.CreateElementBitCast(DstAddr, CGF->Int8Ty);
+ Address Loc = DstAddr.withElementType(CGF->Int8Ty);
CGF->Builder.CreateMemSet(Loc, CGF->Builder.getInt8(0), SizeVal,
IsVolatile);
}
@@ -818,8 +812,7 @@ void CodeGenFunction::destroyNonTrivialCStruct(CodeGenFunction &CGF,
// such structure.
void CodeGenFunction::defaultInitNonTrivialCStructVar(LValue Dst) {
GenDefaultInitialize Gen(getContext());
- Address DstPtr =
- Builder.CreateElementBitCast(Dst.getAddress(*this), CGM.Int8PtrTy);
+ Address DstPtr = Dst.getAddress(*this).withElementType(CGM.Int8PtrTy);
Gen.setCGF(this);
QualType QT = Dst.getType();
QT = Dst.isVolatile() ? QT.withVolatile() : QT;
@@ -832,7 +825,7 @@ static void callSpecialFunction(G &&Gen, StringRef FuncName, QualType QT,
std::array<Address, N> Addrs) {
auto SetArtificialLoc = ApplyDebugLocation::CreateArtificial(CGF);
for (unsigned I = 0; I < N; ++I)
- Addrs[I] = CGF.Builder.CreateElementBitCast(Addrs[I], CGF.CGM.Int8PtrTy);
+ Addrs[I] = Addrs[I].withElementType(CGF.CGM.Int8PtrTy);
QT = IsVolatile ? QT.withVolatile() : QT;
Gen.callFunc(FuncName, QT, Addrs, CGF);
}
diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index 5ae455dd29f75..4786e6ef019e6 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -937,7 +937,7 @@ void MicrosoftCXXABI::emitBeginCatch(CodeGenFunction &CGF,
std::tuple<Address, llvm::Value *, const CXXRecordDecl *>
MicrosoftCXXABI::performBaseAdjustment(CodeGenFunction &CGF, Address Value,
QualType SrcRecordTy) {
- Value = CGF.Builder.CreateElementBitCast(Value, CGF.Int8Ty);
+ Value = Value.withElementType(CGF.Int8Ty);
const CXXRecordDecl *SrcDecl = SrcRecordTy->getAsCXXRecordDecl();
const ASTContext &Context = getContext();
@@ -1452,7 +1452,7 @@ Address MicrosoftCXXABI::adjustThisArgumentForVirtualFunctionCall(
if (Adjustment.isZero())
return This;
- This = CGF.Builder.CreateElementBitCast(This, CGF.Int8Ty);
+ This = This.withElementType(CGF.Int8Ty);
assert(Adjustment.isPositive());
return CGF.Builder.CreateConstByteGEP(This, Adjustment);
}
@@ -1483,7 +1483,7 @@ Address MicrosoftCXXABI::adjustThisArgumentForVirtualFunctionCall(
Address Result = This;
if (ML.VBase) {
- Result = CGF.Builder.CreateElementBitCast(Result, CGF.Int8Ty);
+ Result = Result.withElementType(CGF.Int8Ty);
const CXXRecordDecl *Derived = MD->getParent();
const CXXRecordDecl *VBase = ML.VBase;
@@ -1497,7 +1497,7 @@ Address MicrosoftCXXABI::adjustThisArgumentForVirtualFunctionCall(
}
if (!StaticOffset.isZero()) {
assert(StaticOffset.isPositive());
- Result = CGF.Builder.CreateElementBitCast(Result, CGF.Int8Ty);
+ Result = Result.withElementType(CGF.Int8Ty);
if (ML.VBase) {
// Non-virtual adjustment might result in a pointer outside the allocated
// object, e.g. if the final overrider class is laid out after the virtual
@@ -2217,7 +2217,7 @@ llvm::Value *MicrosoftCXXABI::performThisAdjustment(CodeGenFunction &CGF,
if (TA.isEmpty())
return This.getPointer();
- This = CGF.Builder.CreateElementBitCast(This, CGF.Int8Ty);
+ This = This.withElementType(CGF.Int8Ty);
llvm::Value *V;
if (TA.Virtual.isEmpty()) {
@@ -2228,7 +2228,7 @@ llvm::Value *MicrosoftCXXABI::performThisAdjustment(CodeGenFunction &CGF,
Address VtorDispPtr =
CGF.Builder.CreateConstInBoundsByteGEP(This,
CharUnits::fromQuantity(TA.Virtual.Microsoft.VtordispOffset));
- VtorDispPtr = CGF.Builder.CreateElementBitCast(VtorDispPtr, CGF.Int32Ty);
+ VtorDispPtr = VtorDispPtr.withElementType(CGF.Int32Ty);
llvm::Value *VtorDisp = CGF.Builder.CreateLoad(VtorDispPtr, "vtordisp");
V = CGF.Builder.CreateGEP(This.getElementType(), This.getPointer(),
CGF.Builder.CreateNeg(VtorDisp));
@@ -2270,7 +2270,7 @@ MicrosoftCXXABI::performReturnAdjustment(CodeGenFunction &CGF, Address Ret,
return Ret.getPointer();
auto OrigTy = Ret.getType();
- Ret = CGF.Builder.CreateElementBitCast(Ret, CGF.Int8Ty);
+ Ret = Ret.withElementType(CGF.Int8Ty);
llvm::Value *V = Ret.getPointer();
if (RA.Virtual.Microsoft.VBIndex) {
@@ -2314,8 +2314,7 @@ CharUnits MicrosoftCXXABI::getArrayCookieSizeImpl(QualType type) {
llvm::Value *MicrosoftCXXABI::readArrayCookieImpl(CodeGenFunction &CGF,
Address allocPtr,
CharUnits cookieSize) {
- Address numElementsPtr =
- CGF.Builder.CreateElementBitCast(allocPtr, CGF.SizeTy);
+ Address numElementsPtr = allocPtr.withElementType(CGF.SizeTy);
return CGF.Builder.CreateLoad(numElementsPtr);
}
@@ -2333,8 +2332,7 @@ Address MicrosoftCXXABI::InitializeArrayCookie(CodeGenFunction &CGF,
Address cookiePtr = newPtr;
// Write the number of elements into the appropriate slot.
- Address numElementsPtr
- = CGF.Builder.CreateElementBitCast(cookiePtr, CGF.SizeTy);
+ Address numElementsPtr = cookiePtr.withElementType(CGF.SizeTy);
CGF.Builder.CreateStore(numElements, numElementsPtr);
// Finally, compute a pointer to the actual data buffer by skipping
@@ -3134,12 +3132,10 @@ MicrosoftCXXABI::GetVBaseOffsetFromVBPtr(CodeGenFunction &CGF,
llvm::Value **VBPtrOut) {
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.getElementType(), This.getPointer(), VBPtrOffset, "vbptr");
- if (VBPtrOut) *VBPtrOut = VBPtr;
- VBPtr = Builder.CreateBitCast(VBPtr,
- CGM.Int32Ty->getPointerTo(0)->getPointerTo(This.getAddressSpace()));
+ llvm::Value *VBPtr = Builder.CreateInBoundsGEP(CGM.Int8Ty, This.getPointer(),
+ VBPtrOffset, "vbptr");
+ if (VBPtrOut)
+ *VBPtrOut = VBPtr;
CharUnits VBPtrAlign;
if (auto CI = dyn_cast<llvm::ConstantInt>(VBPtrOffset)) {
@@ -3160,7 +3156,6 @@ MicrosoftCXXABI::GetVBaseOffsetFromVBPtr(CodeGenFunction &CGF,
// Load an i32 offset from the vb-table.
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");
}
@@ -3171,7 +3166,7 @@ llvm::Value *MicrosoftCXXABI::AdjustVirtualBase(
CodeGenFunction &CGF, const Expr *E, const CXXRecordDecl *RD,
Address Base, llvm::Value *VBTableOffset, llvm::Value *VBPtrOffset) {
CGBuilderTy &Builder = CGF.Builder;
- Base = Builder.CreateElementBitCast(Base, CGM.Int8Ty);
+ Base = Base.withElementType(CGM.Int8Ty);
llvm::BasicBlock *OriginalBB = nullptr;
llvm::BasicBlock *SkipAdjustBB = nullptr;
llvm::BasicBlock *VBaseAdjustBB = nullptr;
diff --git a/clang/lib/CodeGen/Targets/AArch64.cpp b/clang/lib/CodeGen/Targets/AArch64.cpp
index f244c00715150..561110ff8c0d8 100644
--- a/clang/lib/CodeGen/Targets/AArch64.cpp
+++ b/clang/lib/CodeGen/Targets/AArch64.cpp
@@ -517,10 +517,9 @@ Address AArch64ABIInfo::EmitAAPCSVAArg(Address VAListAddr, QualType Ty,
if (AI.isIgnore()) {
uint64_t PointerSize = getTarget().getPointerWidth(LangAS::Default) / 8;
CharUnits SlotSize = CharUnits::fromQuantity(PointerSize);
- VAListAddr = CGF.Builder.CreateElementBitCast(VAListAddr, CGF.Int8PtrTy);
+ VAListAddr = VAListAddr.withElementType(CGF.Int8PtrTy);
auto *Load = CGF.Builder.CreateLoad(VAListAddr);
- Address Addr = Address(Load, CGF.Int8Ty, SlotSize);
- return CGF.Builder.CreateElementBitCast(Addr, CGF.ConvertTypeForMem(Ty));
+ return Address(Load, CGF.ConvertTypeForMem(Ty), SlotSize);
}
bool IsIndirect = AI.isIndirect();
@@ -672,7 +671,7 @@ Address AArch64ABIInfo::EmitAAPCSVAArg(Address VAListAddr, QualType Ty,
CharUnits BaseOffset = CharUnits::fromQuantity(16 * i + Offset);
Address LoadAddr =
CGF.Builder.CreateConstInBoundsByteGEP(BaseAddr, BaseOffset);
- LoadAddr = CGF.Builder.CreateElementBitCast(LoadAddr, BaseTy);
+ LoadAddr = LoadAddr.withElementType(BaseTy);
Address StoreAddr = CGF.Builder.CreateConstArrayGEP(Tmp, i);
@@ -680,7 +679,7 @@ Address AArch64ABIInfo::EmitAAPCSVAArg(Address VAListAddr, QualType Ty,
CGF.Builder.CreateStore(Elem, StoreAddr);
}
- RegAddr = CGF.Builder.CreateElementBitCast(Tmp, MemTy);
+ RegAddr = Tmp.withElementType(MemTy);
} else {
// Otherwise the object is contiguous in memory.
@@ -693,7 +692,7 @@ Address AArch64ABIInfo::EmitAAPCSVAArg(Address VAListAddr, QualType Ty,
BaseAddr = CGF.Builder.CreateConstInBoundsByteGEP(BaseAddr, Offset);
}
- RegAddr = CGF.Builder.CreateElementBitCast(BaseAddr, MemTy);
+ RegAddr = BaseAddr.withElementType(MemTy);
}
CGF.EmitBranch(ContBlock);
@@ -746,7 +745,7 @@ Address AArch64ABIInfo::EmitAAPCSVAArg(Address VAListAddr, QualType Ty,
OnStackAddr = CGF.Builder.CreateConstInBoundsByteGEP(OnStackAddr, Offset);
}
- OnStackAddr = CGF.Builder.CreateElementBitCast(OnStackAddr, MemTy);
+ OnStackAddr = OnStackAddr.withElementType(MemTy);
CGF.EmitBranch(ContBlock);
@@ -777,12 +776,9 @@ Address AArch64ABIInfo::EmitDarwinVAArg(Address VAListAddr, QualType Ty,
CharUnits SlotSize = CharUnits::fromQuantity(PointerSize);
// Empty records are ignored for parameter passing purposes.
- if (isEmptyRecord(getContext(), Ty, true)) {
- Address Addr = Address(CGF.Builder.CreateLoad(VAListAddr, "ap.cur"),
- getVAListElementType(CGF), SlotSize);
- Addr = CGF.Builder.CreateElementBitCast(Addr, CGF.ConvertTypeForMem(Ty));
- return Addr;
- }
+ if (isEmptyRecord(getContext(), Ty, true))
+ return Address(CGF.Builder.CreateLoad(VAListAddr, "ap.cur"),
+ CGF.ConvertTypeForMem(Ty), SlotSize);
// The size of the actual thing passed, which might end up just
// being a pointer for indirect types.
diff --git a/clang/lib/CodeGen/Targets/ARM.cpp b/clang/lib/CodeGen/Targets/ARM.cpp
index 7a7be3cd7c9de..d7d175ff1724f 100644
--- a/clang/lib/CodeGen/Targets/ARM.cpp
+++ b/clang/lib/CodeGen/Targets/ARM.cpp
@@ -765,10 +765,9 @@ Address ARMABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
// Empty records are ignored for parameter passing purposes.
if (isEmptyRecord(getContext(), Ty, true)) {
- VAListAddr = CGF.Builder.CreateElementBitCast(VAListAddr, CGF.Int8PtrTy);
+ VAListAddr = VAListAddr.withElementType(CGF.Int8PtrTy);
auto *Load = CGF.Builder.CreateLoad(VAListAddr);
- Address Addr = Address(Load, CGF.Int8Ty, SlotSize);
- return CGF.Builder.CreateElementBitCast(Addr, CGF.ConvertTypeForMem(Ty));
+ return Address(Load, CGF.ConvertTypeForMem(Ty), SlotSize);
}
CharUnits TySize = getContext().getTypeSizeInChars(Ty);
diff --git a/clang/lib/CodeGen/Targets/Hexagon.cpp b/clang/lib/CodeGen/Targets/Hexagon.cpp
index 09a32cca78d68..944a8d002ecfc 100644
--- a/clang/lib/CodeGen/Targets/Hexagon.cpp
+++ b/clang/lib/CodeGen/Targets/Hexagon.cpp
@@ -213,10 +213,8 @@ Address HexagonABIInfo::EmitVAArgFromMemory(CodeGenFunction &CGF,
// Get the type of the argument from memory and bitcast
// overflow area pointer to the argument type.
llvm::Type *PTy = CGF.ConvertTypeForMem(Ty);
- Address AddrTyped = CGF.Builder.CreateElementBitCast(
- Address(__overflow_area_pointer, CGF.Int8Ty,
- CharUnits::fromQuantity(Align)),
- PTy);
+ Address AddrTyped =
+ Address(__overflow_area_pointer, PTy, CharUnits::fromQuantity(Align));
// Round up to the minimum stack alignment for varargs which is 4 bytes.
uint64_t Offset = llvm::alignTo(CGF.getContext().getTypeSize(Ty) / 8, 4);
@@ -247,9 +245,8 @@ Address HexagonABIInfo::EmitVAArgForHexagon(CodeGenFunction &CGF,
AddrAsInt = Builder.CreateAnd(AddrAsInt, Builder.getInt32(~(TyAlign - 1)));
Addr = Builder.CreateIntToPtr(AddrAsInt, BP);
}
- Address AddrTyped = Builder.CreateElementBitCast(
- Address(Addr, CGF.Int8Ty, CharUnits::fromQuantity(TyAlign)),
- CGF.ConvertType(Ty));
+ Address AddrTyped =
+ Address(Addr, CGF.ConvertType(Ty), CharUnits::fromQuantity(TyAlign));
uint64_t Offset = llvm::alignTo(CGF.getContext().getTypeSize(Ty) / 8, 4);
llvm::Value *NextAddr = Builder.CreateGEP(
diff --git a/clang/lib/CodeGen/Targets/LoongArch.cpp b/clang/lib/CodeGen/Targets/LoongArch.cpp
index 4abf281c54d99..6391a8aeaa67c 100644
--- a/clang/lib/CodeGen/Targets/LoongArch.cpp
+++ b/clang/lib/CodeGen/Targets/LoongArch.cpp
@@ -410,12 +410,9 @@ Address LoongArchABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
CharUnits SlotSize = CharUnits::fromQuantity(GRLen / 8);
// Empty records are ignored for parameter passing purposes.
- if (isEmptyRecord(getContext(), Ty, true)) {
- Address Addr = Address(CGF.Builder.CreateLoad(VAListAddr),
- getVAListElementType(CGF), SlotSize);
- Addr = CGF.Builder.CreateElementBitCast(Addr, CGF.ConvertTypeForMem(Ty));
- return Addr;
- }
+ if (isEmptyRecord(getContext(), Ty, true))
+ return Address(CGF.Builder.CreateLoad(VAListAddr),
+ CGF.ConvertTypeForMem(Ty), SlotSize);
auto TInfo = getContext().getTypeInfoInChars(Ty);
diff --git a/clang/lib/CodeGen/Targets/PPC.cpp b/clang/lib/CodeGen/Targets/PPC.cpp
index 1fea52fbaa4e2..9cdd2aa07791d 100644
--- a/clang/lib/CodeGen/Targets/PPC.cpp
+++ b/clang/lib/CodeGen/Targets/PPC.cpp
@@ -31,8 +31,8 @@ static Address complexTempStructure(CodeGenFunction &CGF, Address VAListAddr,
}
llvm::Type *EltTy = CGF.ConvertTypeForMem(CTy->getElementType());
- RealAddr = CGF.Builder.CreateElementBitCast(RealAddr, EltTy);
- ImagAddr = CGF.Builder.CreateElementBitCast(ImagAddr, EltTy);
+ RealAddr = RealAddr.withElementType(EltTy);
+ ImagAddr = ImagAddr.withElementType(EltTy);
llvm::Value *Real = CGF.Builder.CreateLoad(RealAddr, ".vareal");
llvm::Value *Imag = CGF.Builder.CreateLoad(ImagAddr, ".vaimag");
@@ -456,8 +456,7 @@ Address PPC32_SVR4_ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAList,
Builder.CreateMul(NumRegs, Builder.getInt8(RegSize.getQuantity()));
RegAddr = Address(
Builder.CreateInBoundsGEP(CGF.Int8Ty, RegAddr.getPointer(), RegOffset),
- CGF.Int8Ty, RegAddr.getAlignment().alignmentOfArrayElement(RegSize));
- RegAddr = Builder.CreateElementBitCast(RegAddr, DirectTy);
+ DirectTy, RegAddr.getAlignment().alignmentOfArrayElement(RegSize));
// Increase the used-register count.
NumRegs =
@@ -498,7 +497,7 @@ Address PPC32_SVR4_ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAList,
OverflowArea.getElementType(), Align);
}
- MemAddr = Builder.CreateElementBitCast(OverflowArea, DirectTy);
+ MemAddr = OverflowArea.withElementType(DirectTy);
// Increase the overflow area.
OverflowArea = Builder.CreateConstInBoundsByteGEP(OverflowArea, Size);
diff --git a/clang/lib/CodeGen/Targets/X86.cpp b/clang/lib/CodeGen/Targets/X86.cpp
index d08e7cef5bce4..31679d899a440 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -318,8 +318,7 @@ void X86_32TargetCodeGenInfo::addReturnRegisterOutputs(
ResultTruncRegTypes.push_back(CoerceTy);
// Coerce the integer by bitcasting the return slot pointer.
- ReturnSlot.setAddress(
- CGF.Builder.CreateElementBitCast(ReturnSlot.getAddress(CGF), CoerceTy));
+ ReturnSlot.setAddress(ReturnSlot.getAddress(CGF).withElementType(CoerceTy));
ResultRegDests.push_back(ReturnSlot);
rewriteInputConstraintReferences(NumOutputs, 1, AsmString);
@@ -3048,7 +3047,7 @@ Address X86_64ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
assert(AI.isDirect() && "Unexpected ABI info for mixed regs");
llvm::StructType *ST = cast<llvm::StructType>(AI.getCoerceToType());
Address Tmp = CGF.CreateMemTemp(Ty);
- Tmp = CGF.Builder.CreateElementBitCast(Tmp, ST);
+ Tmp = Tmp.withElementType(ST);
assert(ST->getNumElements() == 2 && "Unexpected ABI info for mixed regs");
llvm::Type *TyLo = ST->getElementType(0);
llvm::Type *TyHi = ST->getElementType(1);
@@ -3076,11 +3075,10 @@ Address X86_64ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
CharUnits::fromQuantity(getDataLayout().getABITypeAlign(TyHi)));
CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 1));
- RegAddr = CGF.Builder.CreateElementBitCast(Tmp, LTy);
+ RegAddr = Tmp.withElementType(LTy);
} else if (neededInt) {
RegAddr = Address(CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, gp_offset),
- CGF.Int8Ty, CharUnits::fromQuantity(8));
- RegAddr = CGF.Builder.CreateElementBitCast(RegAddr, LTy);
+ LTy, CharUnits::fromQuantity(8));
// Copy to a temporary if necessary to ensure the appropriate alignment.
auto TInfo = getContext().getTypeInfoInChars(Ty);
@@ -3097,8 +3095,7 @@ Address X86_64ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
} else if (neededSSE == 1) {
RegAddr = Address(CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, fp_offset),
- CGF.Int8Ty, CharUnits::fromQuantity(16));
- RegAddr = CGF.Builder.CreateElementBitCast(RegAddr, LTy);
+ LTy, CharUnits::fromQuantity(16));
} else {
assert(neededSSE == 2 && "Invalid number of needed registers!");
// SSE registers are spaced 16 bytes apart in the register save
@@ -3118,15 +3115,15 @@ Address X86_64ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
: llvm::StructType::get(CGF.DoubleTy, CGF.DoubleTy);
llvm::Value *V;
Address Tmp = CGF.CreateMemTemp(Ty);
- Tmp = CGF.Builder.CreateElementBitCast(Tmp, ST);
- V = CGF.Builder.CreateLoad(CGF.Builder.CreateElementBitCast(
- RegAddrLo, ST->getStructElementType(0)));
+ Tmp = Tmp.withElementType(ST);
+ V = CGF.Builder.CreateLoad(
+ RegAddrLo.withElementType(ST->getStructElementType(0)));
CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 0));
- V = CGF.Builder.CreateLoad(CGF.Builder.CreateElementBitCast(
- RegAddrHi, ST->getStructElementType(1)));
+ V = CGF.Builder.CreateLoad(
+ RegAddrHi.withElementType(ST->getStructElementType(1)));
CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 1));
- RegAddr = CGF.Builder.CreateElementBitCast(Tmp, LTy);
+ RegAddr = Tmp.withElementType(LTy);
}
// AMD64-ABI 3.5.7p5: Step 5. Set:
More information about the cfe-commits
mailing list