https://github.com/JOE1994 updated https://github.com/llvm/llvm-project/pull/68277
>From 2c3fb032e7fdefa553ed4833bbeed8852eb6a410 Mon Sep 17 00:00:00 2001 From: Youngsuk Kim <joseph942...@gmail.com> Date: Mon, 2 Oct 2023 12:28:33 -0400 Subject: [PATCH 1/3] [clang] Replace uses of CreatePointerBitCastOrAddrSpaceCast (NFC) With opaque pointers, CreatePointerBitCastOrAddrSpaceCast is same as CreateAddrSpaceCast. Replace or remove uses of CreatePointerBitCastOrAddrSpaceCast. Opaque pointer cleanup effort. --- clang/lib/CodeGen/CGCall.cpp | 2 +- clang/lib/CodeGen/CodeGenFunction.cpp | 4 +--- clang/lib/CodeGen/ItaniumCXXABI.cpp | 3 --- clang/lib/CodeGen/TargetInfo.cpp | 2 +- llvm/include/llvm/IR/IRBuilder.h | 2 ++ 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 93e16575042c4da..b0d1fcd26a5f413 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -1376,7 +1376,7 @@ static void CreateCoercedStore(llvm::Value *Src, llvm::PointerType *DstPtrTy = llvm::dyn_cast<llvm::PointerType>(DstTy); if (SrcPtrTy && DstPtrTy && SrcPtrTy->getAddressSpace() != DstPtrTy->getAddressSpace()) { - Src = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(Src, DstTy); + Src = CGF.Builder.CreateAddrSpaceCast(Src, DstTy); CGF.Builder.CreateStore(Src, Dst, DstIsVolatile); return; } diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 9b21f428b0af7f5..2f1954fad80f159 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -1123,9 +1123,7 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (!CurFnInfo->getReturnInfo().getIndirectByVal()) { ReturnValuePointer = CreateDefaultAlignTempAlloca(Int8PtrTy, "result.ptr"); - Builder.CreateStore(Builder.CreatePointerBitCastOrAddrSpaceCast( - ReturnValue.getPointer(), Int8PtrTy), - ReturnValuePointer); + Builder.CreateStore(ReturnValue.getPointer(), ReturnValuePointer); } } else if (CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::InAlloca && !hasScalarEvaluationKind(CurFnInfo->getReturnType())) { diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp index 0c89871420bdd3d..f7ef9503aa61033 100644 --- a/clang/lib/CodeGen/ItaniumCXXABI.cpp +++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -3088,9 +3088,6 @@ void ItaniumCXXABI::EmitThreadLocalInitFuncs( CharUnits Align = CGM.getContext().getDeclAlign(VD); Val = Builder.CreateAlignedLoad(Var->getValueType(), Val, Align); } - if (Val->getType() != Wrapper->getReturnType()) - Val = Builder.CreatePointerBitCastOrAddrSpaceCast( - Val, Wrapper->getReturnType(), ""); Builder.CreateRet(Val); } diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp index 3d79f92137abc79..60224d458f6a262 100644 --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -137,7 +137,7 @@ llvm::Value *TargetCodeGenInfo::performAddrSpaceCast( if (auto *C = dyn_cast<llvm::Constant>(Src)) return performAddrSpaceCast(CGF.CGM, C, SrcAddr, DestAddr, DestTy); // Try to preserve the source's name to make IR more readable. - return CGF.Builder.CreatePointerBitCastOrAddrSpaceCast( + return CGF.Builder.CreateAddrSpaceCast( Src, DestTy, Src->hasName() ? Src->getName() + ".ascast" : ""); } diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h index c9f243fdb12e404..a32ec9a66fedfa8 100644 --- a/llvm/include/llvm/IR/IRBuilder.h +++ b/llvm/include/llvm/IR/IRBuilder.h @@ -2138,6 +2138,8 @@ class IRBuilderBase { return Insert(CastInst::CreatePointerCast(V, DestTy), Name); } + // With opaque pointers enabled, this is same as CreateAddressSpaceCast. + // TODO: Replace uses of this method and remove the method itself. Value *CreatePointerBitCastOrAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name = "") { if (V->getType() == DestTy) >From 578bc43ac6bd066052803e76e1f3eb38b9798994 Mon Sep 17 00:00:00 2001 From: Youngsuk Kim <joseph942...@gmail.com> Date: Thu, 5 Oct 2023 21:46:26 -0400 Subject: [PATCH 2/3] Update comment for CreatePointerBitCastOrAddrSpaceCast --- llvm/include/llvm/IR/IRBuilder.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h index a32ec9a66fedfa8..a2fab842b1d0355 100644 --- a/llvm/include/llvm/IR/IRBuilder.h +++ b/llvm/include/llvm/IR/IRBuilder.h @@ -2138,7 +2138,7 @@ class IRBuilderBase { return Insert(CastInst::CreatePointerCast(V, DestTy), Name); } - // With opaque pointers enabled, this is same as CreateAddressSpaceCast. + // With opaque pointers enabled, this can be substituted with CreateAddrSpaceCast. // TODO: Replace uses of this method and remove the method itself. Value *CreatePointerBitCastOrAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name = "") { >From c5d41cdd2cb7d10661484932aab3ac1720d27f3b Mon Sep 17 00:00:00 2001 From: JOE1994 <joseph942...@gmail.com> Date: Thu, 5 Oct 2023 21:59:10 -0400 Subject: [PATCH 3/3] git clang-format --- llvm/include/llvm/IR/IRBuilder.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h index a2fab842b1d0355..7f842a733cf7198 100644 --- a/llvm/include/llvm/IR/IRBuilder.h +++ b/llvm/include/llvm/IR/IRBuilder.h @@ -2138,7 +2138,8 @@ class IRBuilderBase { return Insert(CastInst::CreatePointerCast(V, DestTy), Name); } - // With opaque pointers enabled, this can be substituted with CreateAddrSpaceCast. + // With opaque pointers enabled, this can be substituted with + // CreateAddrSpaceCast. // TODO: Replace uses of this method and remove the method itself. Value *CreatePointerBitCastOrAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name = "") { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits