This is an archive of the discontinued LLVM Phabricator instance.

[clang] Remove CGBuilderTy::CreateElementBitCast
ClosedPublic

Authored by JOE1994 on Jul 1 2023, 11:23 AM.

Details

Summary

CGBuilderTy::CreateElementBitCast() no longer does what its name suggests.

Remove remaining in-tree uses by one of the following methods.

  • drop the call entirely
  • fold it to an Address construction
  • replace it with Address::withElementType()

This is a NFC cleanup effort.

Diff Detail

Event Timeline

JOE1994 created this revision.Jul 1 2023, 11:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 1 2023, 11:23 AM
JOE1994 requested review of this revision.Jul 1 2023, 11:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 1 2023, 11:23 AM
JOE1994 added inline comments.Jul 1 2023, 11:24 AM
clang/lib/CodeGen/CGBuilder.h
157–158
jrtc27 added inline comments.Jul 1 2023, 11:28 AM
clang/lib/CodeGen/CGBuiltin.cpp
3954

Missed Buf = Buf.withElementType(Int8Ty);? According to the comment above, Buf is a void ** not a void */char *.

clang/lib/CodeGen/CGExpr.cpp
3896

This one isn't a direct substitution, although appears to be refactoring the code to not need withElementType in the first place? Probably best to separate that change out from the very mechanical substitution.

clang/lib/CodeGen/CGObjCRuntime.cpp
111

Ditto

clang/lib/CodeGen/ItaniumCXXABI.cpp
813

Ditto

clang/lib/CodeGen/Targets/CSKY.cpp
66–67

Ditto

clang/lib/CodeGen/Targets/RISCV.cpp
465–466

Ditto

nikic accepted this revision.Jul 1 2023, 11:35 AM

LGTM

clang/lib/CodeGen/CGBuilder.h
157–158

This is a private method, so simply delete it instead of deprecating.

This revision is now accepted and ready to land.Jul 1 2023, 11:35 AM
barannikov88 accepted this revision.Jul 1 2023, 11:51 AM
barannikov88 added inline comments.
clang/lib/CodeGen/CGBuiltin.cpp
3954

It would be a dead code because only the pointer is used down below.

clang/lib/CodeGen/CGExpr.cpp
3896

It will be difficult to find all such places later.

JOE1994 added inline comments.Jul 1 2023, 12:18 PM
clang/lib/CodeGen/CGBuiltin.cpp
3954

ElementType associated with Buf is never referenced,
so I intentionally omitted Buf = Buf.withElementType(Int8Ty);.

JOE1994 added inline comments.Jul 1 2023, 12:39 PM
clang/lib/CodeGen/CGExpr.cpp
3896

@jrtc27 Thank you for taking the time to review this revision.

This isn't a direct substitution.
In this revision overall, I did refactoring to get rid of unnecessary calls to withElementType() when possible.

Since these are relatively small & local refactorings, I'd prefer to keep them in this revision.
But if you're strongly against including such refactorings in this revision, I can separate them out to a new revision.

jrtc27 added inline comments.Jul 1 2023, 1:06 PM
clang/lib/CodeGen/CGExpr.cpp
3896

It's easier to review when the non-trivial changes (direct substitution) are kept separate from the trivial ones. That way it's also extremely clear what's intended to be different vs what was accidentally made different. You *at least* need to fix the commit message to say that you're not just replacing the in-tree uses, you're also refactoring some uses to not need it (currently your commit message is in direct contradiction with the diff), but the fact that the commit then does two things that can be reasonably separated out suggests that they should be. And I would much rather see that happen, especially from the perspective of maintaining a significant downstream fork.

JOE1994 added inline comments.Jul 1 2023, 1:43 PM
clang/lib/CodeGen/CGBuilder.h
157–158

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.

jrtc27 added inline comments.Jul 1 2023, 1:50 PM
clang/lib/CodeGen/CGBuilder.h
157–158

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.

157–158

Uh, CGBuilderTy, not CGBuiltin

JOE1994 updated this revision to Diff 536552.Jul 1 2023, 1:58 PM
  • Undo some refactorings to make the diff more consistent with commit message (following feedback from @jrtc27)
  • Remove method CreateElementBitCast (following feedback from @nikic)
JOE1994 retitled this revision from [clang] Deprecate CGBuilderTy::CreateElementBitCast to [clang] Remove CGBuilderTy::CreateElementBitCast.Jul 1 2023, 1:58 PM
JOE1994 edited the summary of this revision. (Show Details)
JOE1994 added inline comments.
clang/lib/CodeGen/CGBuilder.h
157–158

Thanks for the clarification! I got rid of the method in the updated revision.

jrtc27 accepted this revision.Jul 1 2023, 2:07 PM

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)

nikic requested changes to this revision.EditedJul 1 2023, 2:14 PM

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

To provide context for drive-by reviewers: This is the last part of a longer series of changes to eliminate unnecessary uses of CreateElementBitCast. Each use needs to be reviewed and replaced appropriately -- typically either by dropping it completely, folding it into an Address construction, or replacing it with a withElementType() call. We do not want a blind replacement to withElementType() everywhere.

This revision now requires changes to proceed.Jul 1 2023, 2:14 PM
JOE1994 updated this revision to Diff 536554.Jul 1 2023, 2:51 PM
  • 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
JOE1994 edited the summary of this revision. (Show Details)Jul 1 2023, 2:53 PM
nikic accepted this revision.Jul 2 2023, 12:23 AM

LGTM

This revision is now accepted and ready to land.Jul 2 2023, 12:23 AM
This revision was landed with ongoing or failed builds.Jul 2 2023, 7:41 AM
This revision was automatically updated to reflect the committed changes.