Page MenuHomePhabricator

Add clang-llvm-rename tool.
Needs ReviewPublic

Authored by ruiu on Jul 3 2019, 1:25 AM.
This revision needs review, but there are no reviewers specified.



Currently, this tool can rename variables in lld's source tree
without breaking it, but it is very unlikely that it will work
on any other LLVM subdirectories. I hand-tuned some renaming rules
to adopt it to lld's codebase.

This patch is not intended to be submitted, since this is a special-
purpose tool.

Event Timeline

ruiu created this revision.Jul 3 2019, 1:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 3 2019, 1:25 AM
ruiu planned changes to this revision.Jul 3 2019, 1:25 AM

There is clang-rename already. May be new functionality should be added there?

ruiu updated this revision to Diff 207937.Jul 3 2019, 5:26 PM
  • removed a special rule for E
  • do not lowercase global variables whose name is all uppercase
  • OSec -> osec
ruiu planned changes to this revision.Jul 3 2019, 5:26 PM
ruiu added a comment.Jul 3 2019, 5:35 PM

There is clang-rename already. May be new functionality should be added there?

clang-rename seems to focus on renaming a variable in a selected region with the interactive use in mind. I.e. a user selects a variable on an IDE and rename its definition and all references.

I actually tried to create this tool based on clang-rename but failed because clang-rename was too slow for my purpose. It takes a non-negligible amount of time even for renaming a single variable, and I wanted to rename thousands or tens of thousands variables.

There are a few other significant differences between this tool and clang-rename as shown below:

  • this tool renames a variable only when it can see the definition of the variable, while clang-rename renames a specified variable unconditionally
  • clang-rename is an interactive tool, and you need to specify a new name by hand. On the other hand, this tool automatically generates a new name for each variable
  • the core part of my tool is to find variables to rename, while clang-rename doesn't do anything for that

Overall, this tool is I think significantly different from clang-rename.

ruiu updated this revision to Diff 208116.Jul 4 2019, 9:30 PM
  • updated a few special mappings

Hi @ruiu,
Can you comment on how this compares to clang-tidy? I had assumed that the readability-identifier-naming clang-tidy rule would largely do the trick.

ruiu added a comment.Jul 9 2019, 12:03 AM

I wasn't aware that clang-tidy had a such feature. readability-identifier-naming rule doesn't seem to work for this purpose out of the box. That being said, in hindsight, maybe I should have written this as a patch to clang-tidy instead of a new tool (which should have saved my time!)

ychen added a subscriber: ychen.Jul 9 2019, 11:00 PM
ruiu updated this revision to Diff 208883.Jul 9 2019, 11:53 PM
  • Add a comment as to how to build and run clang-llvm-rename tool