-
Notifications
You must be signed in to change notification settings - Fork 15.4k
MetaRenamer: replaced command line options with pass parameters #133975
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
ca8115a
21e2a36
61327d7
bbfaafc
e1c3ba7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -176,6 +176,7 @@ | |||||
| #include "llvm/Passes/OptimizationLevel.h" | ||||||
| #include "llvm/Support/CommandLine.h" | ||||||
| #include "llvm/Support/Debug.h" | ||||||
| #include "llvm/Support/Error.h" | ||||||
| #include "llvm/Support/ErrorHandling.h" | ||||||
| #include "llvm/Support/FormatVariadic.h" | ||||||
| #include "llvm/Support/Regex.h" | ||||||
|
|
@@ -947,6 +948,32 @@ parseLowerAllowCheckPassOptions(StringRef Params) { | |||||
| return Result; | ||||||
| } | ||||||
|
|
||||||
| Expected<MetaRenamerOptions> parseMetaRenamerPassOptions(StringRef Params) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should unify the syntax to handle the case
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||||||
| MetaRenamerOptions Result; | ||||||
| while (!Params.empty()) { | ||||||
| StringRef ParamName; | ||||||
| std::tie(ParamName, Params) = Params.split(';'); | ||||||
| bool Enable = !ParamName.consume_front("no-"); | ||||||
| if (ParamName == "rename-only-inst") { | ||||||
| Result.RenameOnlyInst = Enable; | ||||||
| } else if (ParamName.consume_front("rename-exclude-struct-prefixes=")) { | ||||||
| Result.RenameExcludeStructPrefixes = ParamName; | ||||||
| } else if (ParamName.consume_front("rename-exclude-global-prefixes=")) { | ||||||
| Result.RenameExcludeGlobalPrefixes = ParamName; | ||||||
| } else if (ParamName.consume_front("rename-exclude-alias-prefixes=")) { | ||||||
| Result.RenameExcludeAliasPrefixes = ParamName; | ||||||
| } else if (ParamName.consume_front("rename-exclude-function-prefixes=")) { | ||||||
| Result.RenameExcludeFunctionPrefixes = ParamName; | ||||||
| } else { | ||||||
| return make_error<StringError>( | ||||||
| formatv("invalid MetaRenamer pass parameter '{0}' ", ParamName) | ||||||
|
||||||
| formatv("invalid MetaRenamer pass parameter '{0}' ", ParamName) | |
| formatv("invalid metarenamer pass parameter '{0}' ", ParamName) |
These should probably refer to the form used in the passes format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,7 +103,6 @@ MODULE_PASS("pgo-force-function-attrs", PGOForceFunctionAttrsPass(PGOOpt ? PGOOp | |
| MODULE_PASS("memprof-context-disambiguation", MemProfContextDisambiguation()) | ||
| MODULE_PASS("memprof-module", ModuleMemProfilerPass()) | ||
| MODULE_PASS("mergefunc", MergeFunctionsPass()) | ||
| MODULE_PASS("metarenamer", MetaRenamerPass()) | ||
| MODULE_PASS("module-inline", ModuleInlinerPass()) | ||
| MODULE_PASS("name-anon-globals", NameAnonGlobalPass()) | ||
| MODULE_PASS("no-op-module", NoOpModulePass()) | ||
|
|
@@ -233,7 +232,12 @@ MODULE_PASS_WITH_PARAMS( | |
| return StructuralHashPrinterPass(errs(), Options); | ||
| }, | ||
| parseStructuralHashPrinterPassOptions, "detailed;call-target-ignored") | ||
|
|
||
| MODULE_PASS_WITH_PARAMS("metarenamer", "MetaRenamerPass", | ||
| [](MetaRenamerOptions Options) { | ||
| return MetaRenamerPass(Options); | ||
| }, | ||
| parseMetaRenamerPassOptions, | ||
| "rename-exclude-function-prefixes=S;rename-exclude-alias-prefixes=S;rename-exclude-global-prefixes=S;rename-exclude-struct-prefixes=S;no-rename-only-inst;rename-only-inst") | ||
|
||
| #undef MODULE_PASS_WITH_PARAMS | ||
|
|
||
| #ifndef CGSCC_ANALYSIS | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -35,36 +35,6 @@ | |||||
|
|
||||||
| using namespace llvm; | ||||||
|
|
||||||
| static cl::opt<std::string> RenameExcludeFunctionPrefixes( | ||||||
| "rename-exclude-function-prefixes", | ||||||
| cl::desc("Prefixes for functions that don't need to be renamed, separated " | ||||||
| "by a comma"), | ||||||
| cl::Hidden); | ||||||
|
|
||||||
| static cl::opt<std::string> RenameExcludeAliasPrefixes( | ||||||
| "rename-exclude-alias-prefixes", | ||||||
| cl::desc("Prefixes for aliases that don't need to be renamed, separated " | ||||||
| "by a comma"), | ||||||
| cl::Hidden); | ||||||
|
|
||||||
| static cl::opt<std::string> RenameExcludeGlobalPrefixes( | ||||||
| "rename-exclude-global-prefixes", | ||||||
| cl::desc( | ||||||
| "Prefixes for global values that don't need to be renamed, separated " | ||||||
| "by a comma"), | ||||||
| cl::Hidden); | ||||||
|
|
||||||
| static cl::opt<std::string> RenameExcludeStructPrefixes( | ||||||
| "rename-exclude-struct-prefixes", | ||||||
| cl::desc("Prefixes for structs that don't need to be renamed, separated " | ||||||
| "by a comma"), | ||||||
| cl::Hidden); | ||||||
|
|
||||||
| static cl::opt<bool> | ||||||
| RenameOnlyInst("rename-only-inst", cl::init(false), | ||||||
| cl::desc("only rename the instructions in the function"), | ||||||
| cl::Hidden); | ||||||
|
|
||||||
| static const char *const metaNames[] = { | ||||||
| // See http://en.wikipedia.org/wiki/Metasyntactic_variable | ||||||
| "foo", "bar", "baz", "quux", "barney", "snork", "zot", "blam", "hoge", | ||||||
|
|
@@ -129,7 +99,8 @@ void MetaRename(Function &F) { | |||||
| } | ||||||
|
|
||||||
| void MetaRename(Module &M, | ||||||
| function_ref<TargetLibraryInfo &(Function &)> GetTLI) { | ||||||
| function_ref<TargetLibraryInfo &(Function &)> GetTLI, | ||||||
| MetaRenamerOptions const& Options) { | ||||||
|
||||||
| MetaRenamerOptions const& Options) { | |
| const MetaRenamerOptions &Options) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| ; RUN: opt -passes=metarenamer -rename-exclude-function-prefixes=my_func -rename-exclude-global-prefixes=my_global -rename-exclude-struct-prefixes=my_struct -rename-exclude-alias-prefixes=my_alias -S %s | FileCheck %s | ||
| ; RUN: opt -passes='metarenamer<rename-exclude-function-prefixes=my_func;rename-exclude-global-prefixes=my_global;rename-exclude-struct-prefixes=my_struct;rename-exclude-alias-prefixes=my_alias>' -S %s | FileCheck %s | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The existing test coverage for all the options is lacking. Can you add a new test to make sure all the options parse? In particular, check the failed to parse case. Bonus points for a test which shows they work Also these are somewhat unique in that the content is also a string, so there may be escape hazards to consider. Not sure there is any precedent for this in the existing options. Can you add some tests where the string value is quoted, and contains a ;?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added invalid-pass-parameter test and semicolon-substr test |
||
|
|
||
| ; Check that excluded names don't get renamed while all the other ones do | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume all of these can be StringRef. The options shouldn't really need ownership over the string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed