summaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGAtomic.cpp
diff options
context:
space:
mode:
authorYoungsuk Kim <youngsuk.kim@hpe.com>2023-06-27 10:17:29 -0400
committerJOE1994 <joseph942010@gmail.com>2023-06-27 10:38:54 -0400
commit474ec694191a51d7f30a11f8b03dee911c8ef346 (patch)
tree04bc0a6d6893df8d810b6baec2498f976e64c89c /clang/lib/CodeGen/CGAtomic.cpp
parent2325e0112ae7ef47244277da81920ba90ffadd89 (diff)
[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
Diffstat (limited to 'clang/lib/CodeGen/CGAtomic.cpp')
-rw-r--r--clang/lib/CodeGen/CGAtomic.cpp45
1 files changed, 20 insertions, 25 deletions
diff --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index 6740df8270b3..f191829b4155 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);