[CodeGen] Avoid some uses of deprecated Address constructor

Explicitly pass in the element type instead.
This commit is contained in:
Nikita Popov 2021-12-15 11:03:58 +01:00
parent 3425b1bcb4
commit 834c8ff587
2 changed files with 25 additions and 14 deletions

View File

@ -197,6 +197,7 @@ public:
return Address(CreateStructGEP(Addr.getElementType(), return Address(CreateStructGEP(Addr.getElementType(),
Addr.getPointer(), Index, Name), Addr.getPointer(), Index, Name),
ElTy->getElementType(Index),
Addr.getAlignment().alignmentAtOffset(Offset)); Addr.getAlignment().alignmentAtOffset(Offset));
} }
@ -218,6 +219,7 @@ public:
return Address( return Address(
CreateInBoundsGEP(Addr.getElementType(), Addr.getPointer(), CreateInBoundsGEP(Addr.getElementType(), Addr.getPointer(),
{getSize(CharUnits::Zero()), getSize(Index)}, Name), {getSize(CharUnits::Zero()), getSize(Index)}, Name),
ElTy->getElementType(),
Addr.getAlignment().alignmentAtOffset(Index * EltSize)); Addr.getAlignment().alignmentAtOffset(Index * EltSize));
} }
@ -234,6 +236,7 @@ public:
return Address(CreateInBoundsGEP(Addr.getElementType(), Addr.getPointer(), return Address(CreateInBoundsGEP(Addr.getElementType(), Addr.getPointer(),
getSize(Index), Name), getSize(Index), Name),
ElTy,
Addr.getAlignment().alignmentAtOffset(Index * EltSize)); Addr.getAlignment().alignmentAtOffset(Index * EltSize));
} }
@ -250,6 +253,7 @@ public:
return Address(CreateGEP(Addr.getElementType(), Addr.getPointer(), return Address(CreateGEP(Addr.getElementType(), Addr.getPointer(),
getSize(Index), Name), getSize(Index), Name),
Addr.getElementType(),
Addr.getAlignment().alignmentAtOffset(Index * EltSize)); Addr.getAlignment().alignmentAtOffset(Index * EltSize));
} }
@ -259,6 +263,7 @@ public:
assert(Addr.getElementType() == TypeCache.Int8Ty); assert(Addr.getElementType() == TypeCache.Int8Ty);
return Address(CreateInBoundsGEP(Addr.getElementType(), Addr.getPointer(), return Address(CreateInBoundsGEP(Addr.getElementType(), Addr.getPointer(),
getSize(Offset), Name), getSize(Offset), Name),
Addr.getElementType(),
Addr.getAlignment().alignmentAtOffset(Offset)); Addr.getAlignment().alignmentAtOffset(Offset));
} }
Address CreateConstByteGEP(Address Addr, CharUnits Offset, Address CreateConstByteGEP(Address Addr, CharUnits Offset,
@ -266,6 +271,7 @@ public:
assert(Addr.getElementType() == TypeCache.Int8Ty); assert(Addr.getElementType() == TypeCache.Int8Ty);
return Address(CreateGEP(Addr.getElementType(), Addr.getPointer(), return Address(CreateGEP(Addr.getElementType(), Addr.getPointer(),
getSize(Offset), Name), getSize(Offset), Name),
Addr.getElementType(),
Addr.getAlignment().alignmentAtOffset(Offset)); Addr.getAlignment().alignmentAtOffset(Offset));
} }
@ -281,8 +287,9 @@ public:
/*isSigned=*/true); /*isSigned=*/true);
if (!GEP->accumulateConstantOffset(DL, Offset)) if (!GEP->accumulateConstantOffset(DL, Offset))
llvm_unreachable("offset of GEP with constants is always computable"); llvm_unreachable("offset of GEP with constants is always computable");
return Address(GEP, Addr.getAlignment().alignmentAtOffset( return Address(GEP, GEP->getResultElementType(),
CharUnits::fromQuantity(Offset.getSExtValue()))); Addr.getAlignment().alignmentAtOffset(
CharUnits::fromQuantity(Offset.getSExtValue())));
} }
using CGBuilderBaseTy::CreateMemCpy; using CGBuilderBaseTy::CreateMemCpy;
@ -333,6 +340,7 @@ public:
return Address(CreatePreserveStructAccessIndex(ElTy, Addr.getPointer(), return Address(CreatePreserveStructAccessIndex(ElTy, Addr.getPointer(),
Index, FieldIndex, DbgInfo), Index, FieldIndex, DbgInfo),
ElTy->getElementType(Index),
Addr.getAlignment().alignmentAtOffset(Offset)); Addr.getAlignment().alignmentAtOffset(Offset));
} }
}; };

View File

@ -5246,9 +5246,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
llvm::Type *BPP = Int8PtrPtrTy; llvm::Type *BPP = Int8PtrPtrTy;
DestAddr = Address(Builder.CreateBitCast(DestAddr.getPointer(), BPP, "cp"), DestAddr = Address(Builder.CreateBitCast(DestAddr.getPointer(), BPP, "cp"),
DestAddr.getAlignment()); Int8PtrTy, DestAddr.getAlignment());
SrcAddr = Address(Builder.CreateBitCast(SrcAddr.getPointer(), BPP, "ap"), SrcAddr = Address(Builder.CreateBitCast(SrcAddr.getPointer(), BPP, "ap"),
SrcAddr.getAlignment()); Int8PtrTy, SrcAddr.getAlignment());
Value *ArgPtr = Builder.CreateLoad(SrcAddr, "ap.val"); Value *ArgPtr = Builder.CreateLoad(SrcAddr, "ap.val");
return RValue::get(Builder.CreateStore(ArgPtr, DestAddr)); return RValue::get(Builder.CreateStore(ArgPtr, DestAddr));
@ -15405,7 +15405,8 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID,
// If the user wants the entire vector, just load the entire vector. // If the user wants the entire vector, just load the entire vector.
if (NumBytes == 16) { if (NumBytes == 16) {
Value *BC = Builder.CreateBitCast(Ops[0], ResTy->getPointerTo()); Value *BC = Builder.CreateBitCast(Ops[0], ResTy->getPointerTo());
Value *LD = Builder.CreateLoad(Address(BC, CharUnits::fromQuantity(1))); Value *LD =
Builder.CreateLoad(Address(BC, ResTy, CharUnits::fromQuantity(1)));
if (!IsLE) if (!IsLE)
return LD; return LD;
@ -15466,8 +15467,8 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID,
RevMask.push_back(15 - Idx); RevMask.push_back(15 - Idx);
StVec = Builder.CreateShuffleVector(Ops[2], Ops[2], RevMask); StVec = Builder.CreateShuffleVector(Ops[2], Ops[2], RevMask);
} }
return Builder.CreateStore(StVec, return Builder.CreateStore(
Address(BC, CharUnits::fromQuantity(1))); StVec, Address(BC, Ops[2]->getType(), CharUnits::fromQuantity(1)));
} }
auto *ConvTy = Int64Ty; auto *ConvTy = Int64Ty;
unsigned NumElts = 0; unsigned NumElts = 0;
@ -15501,8 +15502,8 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID,
Function *F = CGM.getIntrinsic(Intrinsic::bswap, ConvTy); Function *F = CGM.getIntrinsic(Intrinsic::bswap, ConvTy);
Elt = Builder.CreateCall(F, Elt); Elt = Builder.CreateCall(F, Elt);
} }
return Builder.CreateStore(Elt, return Builder.CreateStore(
Address(PtrBC, CharUnits::fromQuantity(1))); Elt, Address(PtrBC, ConvTy, CharUnits::fromQuantity(1)));
}; };
unsigned Stored = 0; unsigned Stored = 0;
unsigned RemainingBytes = NumBytes; unsigned RemainingBytes = NumBytes;
@ -16296,7 +16297,8 @@ Value *EmitAMDGPUWorkGroupSize(CodeGenFunction &CGF, unsigned Index) {
auto *DstTy = auto *DstTy =
CGF.Int16Ty->getPointerTo(GEP->getType()->getPointerAddressSpace()); CGF.Int16Ty->getPointerTo(GEP->getType()->getPointerAddressSpace());
auto *Cast = CGF.Builder.CreateBitCast(GEP, DstTy); auto *Cast = CGF.Builder.CreateBitCast(GEP, DstTy);
auto *LD = CGF.Builder.CreateLoad(Address(Cast, CharUnits::fromQuantity(2))); auto *LD = CGF.Builder.CreateLoad(
Address(Cast, CGF.Int16Ty, CharUnits::fromQuantity(2)));
llvm::MDBuilder MDHelper(CGF.getLLVMContext()); llvm::MDBuilder MDHelper(CGF.getLLVMContext());
llvm::MDNode *RNode = MDHelper.createRange(APInt(16, 1), llvm::MDNode *RNode = MDHelper.createRange(APInt(16, 1),
APInt(16, CGF.getTarget().getMaxOpenCLWorkGroupSize() + 1)); APInt(16, CGF.getTarget().getMaxOpenCLWorkGroupSize() + 1));
@ -16316,7 +16318,8 @@ Value *EmitAMDGPUGridSize(CodeGenFunction &CGF, unsigned Index) {
auto *DstTy = auto *DstTy =
CGF.Int32Ty->getPointerTo(GEP->getType()->getPointerAddressSpace()); CGF.Int32Ty->getPointerTo(GEP->getType()->getPointerAddressSpace());
auto *Cast = CGF.Builder.CreateBitCast(GEP, DstTy); auto *Cast = CGF.Builder.CreateBitCast(GEP, DstTy);
auto *LD = CGF.Builder.CreateLoad(Address(Cast, CharUnits::fromQuantity(4))); auto *LD = CGF.Builder.CreateLoad(
Address(Cast, CGF.Int32Ty, CharUnits::fromQuantity(4)));
LD->setMetadata(llvm::LLVMContext::MD_invariant_load, LD->setMetadata(llvm::LLVMContext::MD_invariant_load,
llvm::MDNode::get(CGF.getLLVMContext(), None)); llvm::MDNode::get(CGF.getLLVMContext(), None));
return LD; return LD;
@ -18616,8 +18619,8 @@ Value *CodeGenFunction::EmitHexagonBuiltinExpr(unsigned BuiltinID,
auto MakeCircOp = [this, E](unsigned IntID, bool IsLoad) { auto MakeCircOp = [this, E](unsigned IntID, bool IsLoad) {
// The base pointer is passed by address, so it needs to be loaded. // The base pointer is passed by address, so it needs to be loaded.
Address A = EmitPointerWithAlignment(E->getArg(0)); Address A = EmitPointerWithAlignment(E->getArg(0));
Address BP = Address( Address BP = Address(Builder.CreateBitCast(
Builder.CreateBitCast(A.getPointer(), Int8PtrPtrTy), A.getAlignment()); A.getPointer(), Int8PtrPtrTy), Int8PtrTy, A.getAlignment());
llvm::Value *Base = Builder.CreateLoad(BP); llvm::Value *Base = Builder.CreateLoad(BP);
// The treatment of both loads and stores is the same: the arguments for // The treatment of both loads and stores is the same: the arguments for
// the builtin are the same as the arguments for the intrinsic. // the builtin are the same as the arguments for the intrinsic.
@ -18661,7 +18664,7 @@ Value *CodeGenFunction::EmitHexagonBuiltinExpr(unsigned BuiltinID,
// per call. // per call.
Address DestAddr = EmitPointerWithAlignment(E->getArg(1)); Address DestAddr = EmitPointerWithAlignment(E->getArg(1));
DestAddr = Address(Builder.CreateBitCast(DestAddr.getPointer(), Int8PtrTy), DestAddr = Address(Builder.CreateBitCast(DestAddr.getPointer(), Int8PtrTy),
DestAddr.getAlignment()); Int8Ty, DestAddr.getAlignment());
llvm::Value *DestAddress = DestAddr.getPointer(); llvm::Value *DestAddress = DestAddr.getPointer();
// Operands are Base, Dest, Modifier. // Operands are Base, Dest, Modifier.