[PATCH] D154285: [clang] Remove CGBuilderTy::CreateElementBitCast

2023-07-02 Thread Youngsuk Kim via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6f986bffc51a: [clang] Remove 
CGBuilderTy::CreateElementBitCast (authored by JOE1994).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154285/new/

https://reviews.llvm.org/D154285

Files:
  clang/lib/CodeGen/CGBuilder.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/CGObjCRuntime.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/Targets/CSKY.cpp
  clang/lib/CodeGen/Targets/RISCV.cpp

Index: clang/lib/CodeGen/Targets/RISCV.cpp
===
--- clang/lib/CodeGen/Targets/RISCV.cpp
+++ clang/lib/CodeGen/Targets/RISCV.cpp
@@ -462,10 +462,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;
+return Address(CGF.Builder.CreateLoad(VAListAddr),
+   CGF.ConvertTypeForMem(Ty), SlotSize);
   }
 
   auto TInfo = getContext().getTypeInfoInChars(Ty);
Index: clang/lib/CodeGen/Targets/CSKY.cpp
===
--- clang/lib/CodeGen/Targets/CSKY.cpp
+++ clang/lib/CodeGen/Targets/CSKY.cpp
@@ -63,10 +63,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;
+return Address(CGF.Builder.CreateLoad(VAListAddr),
+   CGF.ConvertTypeForMem(Ty), SlotSize);
   }
 
   auto TInfo = getContext().getTypeInfoInChars(Ty);
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -809,12 +809,9 @@
 
   CGBuilderTy &Builder = CGF.Builder;
 
-  // Cast to char*.
-  Base = Builder.CreateElementBitCast(Base, CGF.Int8Ty);
-
   // Apply the offset, which we assume is non-null.
-  return Builder.CreateInBoundsGEP(Base.getElementType(), Base.getPointer(),
-   MemPtr, "memptr.offset");
+  return Builder.CreateInBoundsGEP(CGF.Int8Ty, Base.getPointer(), MemPtr,
+   "memptr.offset");
 }
 
 /// Perform a bitcast, derived-to-base, or base-to-derived member pointer
@@ -2043,7 +2040,7 @@
   if (!NonVirtualAdjustment && !VirtualAdjustment)
 return InitialPtr.getPointer();
 
-  Address V = CGF.Builder.CreateElementBitCast(InitialPtr, CGF.Int8Ty);
+  Address V = InitialPtr.withElementType(CGF.Int8Ty);
 
   // In a base-to-derived cast, the non-virtual adjustment is applied first.
   if (NonVirtualAdjustment && !IsReturnAdjustment) {
@@ -2054,7 +2051,7 @@
   // Perform the virtual adjustment if we have one.
   llvm::Value *ResultPtr;
   if (VirtualAdjustment) {
-Address VTablePtrPtr = CGF.Builder.CreateElementBitCast(V, CGF.Int8PtrTy);
+Address VTablePtrPtr = V.withElementType(CGF.Int8PtrTy);
 llvm::Value *VTablePtr = CGF.Builder.CreateLoad(VTablePtrPtr);
 
 llvm::Value *Offset;
@@ -2151,8 +2148,7 @@
 CookiePtr = CGF.Builder.CreateConstInBoundsByteGEP(CookiePtr, CookieOffset);
 
   // Write the number of elements into the appropriate slot.
-  Address NumElementsPtr =
-  CGF.Builder.CreateElementBitCast(CookiePtr, CGF.SizeTy);
+  Address NumElementsPtr = CookiePtr.withElementType(CGF.SizeTy);
   llvm::Instruction *SI = CGF.Builder.CreateStore(NumElements, NumElementsPtr);
 
   // Handle the array cookie specially in ASan.
@@ -2184,7 +2180,7 @@
   CGF.Builder.CreateConstInBoundsByteGEP(numElementsPtr, numElementsOffset);
 
   unsigned AS = allocPtr.getAddressSpace();
-  numElementsPtr = CGF.Builder.CreateElementBitCast(numElementsPtr, CGF.SizeTy);
+  numElementsPtr = numElementsPtr.withElementType(CGF.SizeTy);
   if (!CGM.getLangOpts().Sanitize.has(SanitizerKind::Address) || AS != 0)
 return CGF.Builder.CreateLoad(numElementsPtr);
   // In asan mode emit a function call instead of a regular load and let the
@@ -2223,7 +2219,7 @@
   Address cookie = newPtr;
 
   // The first element is the element size.
-  cookie = CGF.Builder.CreateElementBitCast(cookie, CGF.SizeTy);
+  cookie = cookie.withElementType(CGF.SizeTy);
   llvm::Value *elementSize = llvm::ConstantInt::get(CGF.SizeTy,
  getContext().getTypeSizeInChars(elementType).getQuantity());
   CGF.Builder.CreateStore(elementSize, cookie);
@@ -22

[PATCH] D154285: [clang] Remove CGBuilderTy::CreateElementBitCast

2023-07-02 Thread Nikita Popov via Phabricator via cfe-commits
nikic accepted this revision.
nikic added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154285/new/

https://reviews.llvm.org/D154285

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154285: [clang] Remove CGBuilderTy::CreateElementBitCast

2023-07-01 Thread Youngsuk Kim via Phabricator via cfe-commits
JOE1994 updated this revision to Diff 536554.
JOE1994 added a comment.

- Add back in refactorings that either drop existing calls to 
CreateElementBitCast, or merge to Address creation.

- Update commit message to clarify that we're employing 3 different methods to 
remove existing calls to CreateElementBitCast


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154285/new/

https://reviews.llvm.org/D154285

Files:
  clang/lib/CodeGen/CGBuilder.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/CGObjCRuntime.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/Targets/CSKY.cpp
  clang/lib/CodeGen/Targets/RISCV.cpp

Index: clang/lib/CodeGen/Targets/RISCV.cpp
===
--- clang/lib/CodeGen/Targets/RISCV.cpp
+++ clang/lib/CodeGen/Targets/RISCV.cpp
@@ -462,10 +462,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;
+return Address(CGF.Builder.CreateLoad(VAListAddr),
+   CGF.ConvertTypeForMem(Ty), SlotSize);
   }
 
   auto TInfo = getContext().getTypeInfoInChars(Ty);
Index: clang/lib/CodeGen/Targets/CSKY.cpp
===
--- clang/lib/CodeGen/Targets/CSKY.cpp
+++ clang/lib/CodeGen/Targets/CSKY.cpp
@@ -63,10 +63,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;
+return Address(CGF.Builder.CreateLoad(VAListAddr),
+   CGF.ConvertTypeForMem(Ty), SlotSize);
   }
 
   auto TInfo = getContext().getTypeInfoInChars(Ty);
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -809,12 +809,9 @@
 
   CGBuilderTy &Builder = CGF.Builder;
 
-  // Cast to char*.
-  Base = Builder.CreateElementBitCast(Base, CGF.Int8Ty);
-
   // Apply the offset, which we assume is non-null.
-  return Builder.CreateInBoundsGEP(Base.getElementType(), Base.getPointer(),
-   MemPtr, "memptr.offset");
+  return Builder.CreateInBoundsGEP(CGF.Int8Ty, Base.getPointer(), MemPtr,
+   "memptr.offset");
 }
 
 /// Perform a bitcast, derived-to-base, or base-to-derived member pointer
@@ -2043,7 +2040,7 @@
   if (!NonVirtualAdjustment && !VirtualAdjustment)
 return InitialPtr.getPointer();
 
-  Address V = CGF.Builder.CreateElementBitCast(InitialPtr, CGF.Int8Ty);
+  Address V = InitialPtr.withElementType(CGF.Int8Ty);
 
   // In a base-to-derived cast, the non-virtual adjustment is applied first.
   if (NonVirtualAdjustment && !IsReturnAdjustment) {
@@ -2054,7 +2051,7 @@
   // Perform the virtual adjustment if we have one.
   llvm::Value *ResultPtr;
   if (VirtualAdjustment) {
-Address VTablePtrPtr = CGF.Builder.CreateElementBitCast(V, CGF.Int8PtrTy);
+Address VTablePtrPtr = V.withElementType(CGF.Int8PtrTy);
 llvm::Value *VTablePtr = CGF.Builder.CreateLoad(VTablePtrPtr);
 
 llvm::Value *Offset;
@@ -2151,8 +2148,7 @@
 CookiePtr = CGF.Builder.CreateConstInBoundsByteGEP(CookiePtr, CookieOffset);
 
   // Write the number of elements into the appropriate slot.
-  Address NumElementsPtr =
-  CGF.Builder.CreateElementBitCast(CookiePtr, CGF.SizeTy);
+  Address NumElementsPtr = CookiePtr.withElementType(CGF.SizeTy);
   llvm::Instruction *SI = CGF.Builder.CreateStore(NumElements, NumElementsPtr);
 
   // Handle the array cookie specially in ASan.
@@ -2184,7 +2180,7 @@
   CGF.Builder.CreateConstInBoundsByteGEP(numElementsPtr, numElementsOffset);
 
   unsigned AS = allocPtr.getAddressSpace();
-  numElementsPtr = CGF.Builder.CreateElementBitCast(numElementsPtr, CGF.SizeTy);
+  numElementsPtr = numElementsPtr.withElementType(CGF.SizeTy);
   if (!CGM.getLangOpts().Sanitize.has(SanitizerKind::Address) || AS != 0)
 return CGF.Builder.CreateLoad(numElementsPtr);
   // In asan mode emit a function call instead of a regular load and let the
@@ -2223,7 +2219,7 @@
   Address cookie = newPtr;
 
   // The first element is the element size.
-  cookie = CGF.Builder.CreateElementBitCast(cookie, CGF.SizeTy);
+  cookie = cookie.withElementType(CGF.SizeTy);
   llvm::Value *elementSize = llvm::ConstantInt::get(CGF.SizeTy,
  getContext().getTypeSizeInChars(eleme

[PATCH] D154285: [clang] Remove CGBuilderTy::CreateElementBitCast

2023-07-01 Thread Nikita Popov via Phabricator via cfe-commits
nikic requested changes to this revision.
nikic added a comment.
This revision now requires changes to proceed.

The entire change is NFC cleanup, it makes no sense to separate it. Please 
revert to previous patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154285/new/

https://reviews.llvm.org/D154285

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154285: [clang] Remove CGBuilderTy::CreateElementBitCast

2023-07-01 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 accepted this revision.
jrtc27 added a comment.

Thanks for the updated diff (would have also been happy with having a new 
commit *before* this one that does the non-trivial changes, but this works too 
and can be followed up with the cleanups you were making if you want to)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154285/new/

https://reviews.llvm.org/D154285

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154285: [clang] Remove CGBuilderTy::CreateElementBitCast

2023-07-01 Thread Youngsuk Kim via Phabricator via cfe-commits
JOE1994 added inline comments.



Comment at: clang/lib/CodeGen/CGBuilder.h:158
 
   /// This method is to be deprecated. Use `Address::withElementType` instead.
+  [[deprecated("Use `Address::withElementType` instead.")]]

jrtc27 wrote:
> jrtc27 wrote:
> > JOE1994 wrote:
> > > nikic wrote:
> > > > JOE1994 wrote:
> > > > > 
> > > > This is a private method, so simply delete it instead of deprecating.
> > > It seems like this method is listed as "public" member functions in 
> > > https://clang.llvm.org/doxygen/classclang_1_1CodeGen_1_1CGBuilderTy.html .
> > > 
> > > I see the `public` specifier on line 50.
> > It's public in the sense of its access specifier, i.e. that it can be used 
> > outside of CGBuiltin, but it's private in the sense that this header is in 
> > clang/lib/CodeGen and thus only used within Clang itself, not exposed as a 
> > Clang API, so if Clang isn't using it any more, nothing is.
> Uh, CGBuilderTy, not CGBuiltin
Thanks for the clarification! I got rid of the method in the updated revision.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154285/new/

https://reviews.llvm.org/D154285

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits