Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIR][CIRGen] Change buildX functions to emitX #1093

Merged
merged 3 commits into from
Nov 9, 2024

Conversation

smeenai
Copy link
Collaborator

@smeenai smeenai commented Nov 8, 2024

The buildX naming convention originated when the CIRGen implementation
was planned to be substantially different from original CodeGen. CIRGen
is now a much closer adaption of CodeGen, and the emitX to buildX
renaming just makes things more confusing, since CodeGen also has some
helper functions whose names start with build or Build, so it's not
immediately clear which CodeGen function corresponds to a CIRGen buildX
function. Rename the buildX functions back to emitX to fix this.

This diff was generated mostly mechanically. I searched for all buildX
functions in CIRGen and all emitX or buildX functions in CodeGen:

rg '\b[Bb]uild[A-Z][A-Za-z0-9_]*\b' clang/lib/CIR/CodeGen -Io | sort -u -o /tmp/buildfuncs
rg '\b([Ee]mit|[Bb]uild)[A-Z][A-Za-z0-9_]*\b' clang/lib/CodeGen -Io | sort -u -o /tmp/emitfuncs

I used a simple Python script to find corresponding functions:
https://gist.github.com/smeenai/02be7ced8564cef5518df72606ec7b19.
https://gist.github.com/smeenai/6ffd67be4249c8cebdd7fa99cfa4f13c is the
resulting list of correspondences. This isn't 100% accurate because it's
not accounting for the files that the functions are present in, but
that's pretty unlikely to matter here, so I kept it simple.

The buildX functions in CIRGen which correspond to an emitX function in
CodeGen should be changed, and the ones which correspond to a BuildX
function in CodeGen should not be changed. That leaves some functions
without any correspondences, which required a judgement call. I scanned
through all those functions, and buildVirtualMethodAttr was the only one
that seemed like it shouldn't be changed to emit. I performed the
replacement as follows:

funcs="$(awk '(/-> [Ee]/ || !/->/) && !/buildVirtualMethodAttr/ { print substr($1, 6) }' /tmp/corrfuncs | paste -sd '|')"
find clang/include/clang/CIR clang/lib/CIR/{CodeGen,FrontendAction} \( -name '*.h' -o -name '*.cpp' \) -print0 | \
  xargs -0 perl -pi -e "s/\bbuild($funcs)\\b/emit\\1/g"

The mechanical changes are in the first commit of this PR. There was a
manual fixup required for a token pasting macro in CIRGenExprScalar.cpp,
which is the second commit. I then ran git clang-format, which is the
third commit. (They'll be squashed together when the PR is committed.)

@smeenai smeenai merged commit 5e91e4f into llvm:main Nov 9, 2024
6 checks passed
@smeenai smeenai deleted the build-to-emit branch November 9, 2024 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants