Skip to content

Commit 5c91b28

Browse files
authored
[clang] Replace uses of CreatePointerBitCastOrAddrSpaceCast (NFC) (#68277)
With opaque pointers, `CreatePointerBitCastOrAddrSpaceCast` can be replaced with `CreateAddrSpaceCast`. Replace or remove uses of `CreatePointerBitCastOrAddrSpaceCast`. Opaque pointer cleanup effort.
1 parent 167b598 commit 5c91b28

File tree

5 files changed

+8
-10
lines changed

5 files changed

+8
-10
lines changed

clang/lib/CodeGen/CGCall.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,7 @@ static void CreateCoercedStore(llvm::Value *Src,
13801380
llvm::PointerType *DstPtrTy = llvm::dyn_cast<llvm::PointerType>(DstTy);
13811381
if (SrcPtrTy && DstPtrTy &&
13821382
SrcPtrTy->getAddressSpace() != DstPtrTy->getAddressSpace()) {
1383-
Src = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(Src, DstTy);
1383+
Src = CGF.Builder.CreateAddrSpaceCast(Src, DstTy);
13841384
CGF.Builder.CreateStore(Src, Dst, DstIsVolatile);
13851385
return;
13861386
}

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,11 +1121,9 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
11211121
Address(&*AI, ConvertType(RetTy),
11221122
CurFnInfo->getReturnInfo().getIndirectAlign(), KnownNonNull);
11231123
if (!CurFnInfo->getReturnInfo().getIndirectByVal()) {
1124-
ReturnValuePointer =
1125-
CreateDefaultAlignTempAlloca(Int8PtrTy, "result.ptr");
1126-
Builder.CreateStore(Builder.CreatePointerBitCastOrAddrSpaceCast(
1127-
ReturnValue.getPointer(), Int8PtrTy),
1128-
ReturnValuePointer);
1124+
ReturnValuePointer = CreateDefaultAlignTempAlloca(
1125+
ReturnValue.getPointer()->getType(), "result.ptr");
1126+
Builder.CreateStore(ReturnValue.getPointer(), ReturnValuePointer);
11291127
}
11301128
} else if (CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::InAlloca &&
11311129
!hasScalarEvaluationKind(CurFnInfo->getReturnType())) {

clang/lib/CodeGen/ItaniumCXXABI.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3095,9 +3095,6 @@ void ItaniumCXXABI::EmitThreadLocalInitFuncs(
30953095
CharUnits Align = CGM.getContext().getDeclAlign(VD);
30963096
Val = Builder.CreateAlignedLoad(Var->getValueType(), Val, Align);
30973097
}
3098-
if (Val->getType() != Wrapper->getReturnType())
3099-
Val = Builder.CreatePointerBitCastOrAddrSpaceCast(
3100-
Val, Wrapper->getReturnType(), "");
31013098

31023099
Builder.CreateRet(Val);
31033100
}

clang/lib/CodeGen/TargetInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ llvm::Value *TargetCodeGenInfo::performAddrSpaceCast(
137137
if (auto *C = dyn_cast<llvm::Constant>(Src))
138138
return performAddrSpaceCast(CGF.CGM, C, SrcAddr, DestAddr, DestTy);
139139
// Try to preserve the source's name to make IR more readable.
140-
return CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
140+
return CGF.Builder.CreateAddrSpaceCast(
141141
Src, DestTy, Src->hasName() ? Src->getName() + ".ascast" : "");
142142
}
143143

llvm/include/llvm/IR/IRBuilder.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,6 +2146,9 @@ class IRBuilderBase {
21462146
return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
21472147
}
21482148

2149+
// With opaque pointers enabled, this can be substituted with
2150+
// CreateAddrSpaceCast.
2151+
// TODO: Replace uses of this method and remove the method itself.
21492152
Value *CreatePointerBitCastOrAddrSpaceCast(Value *V, Type *DestTy,
21502153
const Twine &Name = "") {
21512154
if (V->getType() == DestTy)

0 commit comments

Comments
 (0)