From 038fff3f249a25ae3f598f3e4951d9f57b30fbce Mon Sep 17 00:00:00 2001 From: chrisPyr <32153107+chrisPyr@users.noreply.github.com> Date: Thu, 6 Mar 2025 14:11:05 +0800 Subject: [PATCH] [NFC][BOLT] Make file-local cl::opt global variables static (#126472) #125983 --- bolt/lib/Core/BinaryContext.cpp | 7 +++--- bolt/lib/Core/BinaryData.cpp | 2 +- bolt/lib/Core/BinaryFunction.cpp | 15 +++++-------- bolt/lib/Passes/Aligner.cpp | 27 +++++++++-------------- bolt/lib/Passes/FrameOptimizer.cpp | 2 +- bolt/lib/Passes/PLTCall.cpp | 26 +++++++++------------- bolt/lib/Passes/ProfileQualityStats.cpp | 4 ++-- bolt/lib/Passes/RetpolineInsertion.cpp | 20 ++++++++--------- bolt/lib/Passes/StokeInfo.cpp | 2 +- bolt/lib/Passes/TailDuplication.cpp | 2 +- bolt/lib/Profile/StaleProfileMatching.cpp | 24 ++++++++++---------- bolt/lib/Profile/YAMLProfileReader.cpp | 6 ++--- bolt/lib/Rewrite/RewriteInstance.cpp | 25 +++++++++++---------- bolt/tools/bat-dump/bat-dump.cpp | 2 +- bolt/tools/driver/llvm-bolt.cpp | 2 +- bolt/tools/merge-fdata/merge-fdata.cpp | 2 +- 16 files changed, 77 insertions(+), 91 deletions(-) diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp index 8fa1e367c685..2045b9bd5d8a 100644 --- a/bolt/lib/Core/BinaryContext.cpp +++ b/bolt/lib/Core/BinaryContext.cpp @@ -46,9 +46,10 @@ using namespace llvm; namespace opts { -cl::opt<bool> NoHugePages("no-huge-pages", - cl::desc("use regular size pages for code alignment"), - cl::Hidden, cl::cat(BoltCategory)); +static cl::opt<bool> + NoHugePages("no-huge-pages", + cl::desc("use regular size pages for code alignment"), + cl::Hidden, cl::cat(BoltCategory)); static cl::opt<bool> PrintDebugInfo("print-debug-info", diff --git a/bolt/lib/Core/BinaryData.cpp b/bolt/lib/Core/BinaryData.cpp index e9ddf08d8695..88f13eafd614 100644 --- a/bolt/lib/Core/BinaryData.cpp +++ b/bolt/lib/Core/BinaryData.cpp @@ -24,7 +24,7 @@ namespace opts { extern cl::OptionCategory BoltCategory; extern cl::opt<unsigned> Verbosity; -cl::opt<bool> +static cl::opt<bool> PrintSymbolAliases("print-aliases", cl::desc("print aliases when printing objects"), cl::Hidden, cl::cat(BoltCategory)); diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp index b46ba1a0d1a8..35617a92c1b2 100644 --- a/bolt/lib/Core/BinaryFunction.cpp +++ b/bolt/lib/Core/BinaryFunction.cpp @@ -67,7 +67,7 @@ extern cl::opt<unsigned> Verbosity; extern bool processAllFunctions(); -cl::opt<bool> CheckEncoding( +static cl::opt<bool> CheckEncoding( "check-encoding", cl::desc("perform verification of LLVM instruction encoding/decoding. " "Every instruction in the input is decoded and re-encoded. " @@ -144,14 +144,11 @@ cl::opt<bool> cl::desc("print time spent constructing binary functions"), cl::Hidden, cl::cat(BoltCategory)); -cl::opt<bool> -TrapOnAVX512("trap-avx512", - cl::desc("in relocation mode trap upon entry to any function that uses " - "AVX-512 instructions"), - cl::init(false), - cl::ZeroOrMore, - cl::Hidden, - cl::cat(BoltCategory)); +static cl::opt<bool> TrapOnAVX512( + "trap-avx512", + cl::desc("in relocation mode trap upon entry to any function that uses " + "AVX-512 instructions"), + cl::init(false), cl::ZeroOrMore, cl::Hidden, cl::cat(BoltCategory)); bool shouldPrint(const BinaryFunction &Function) { if (Function.isIgnored()) diff --git a/bolt/lib/Passes/Aligner.cpp b/bolt/lib/Passes/Aligner.cpp index 555f82a5a817..c3ddedaaa146 100644 --- a/bolt/lib/Passes/Aligner.cpp +++ b/bolt/lib/Passes/Aligner.cpp @@ -25,15 +25,12 @@ extern cl::opt<bool> AlignBlocks; extern cl::opt<bool> PreserveBlocksAlignment; extern cl::opt<unsigned> AlignFunctions; -cl::opt<unsigned> -AlignBlocksMinSize("align-blocks-min-size", - cl::desc("minimal size of the basic block that should be aligned"), - cl::init(0), - cl::ZeroOrMore, - cl::Hidden, - cl::cat(BoltOptCategory)); +static cl::opt<unsigned> AlignBlocksMinSize( + "align-blocks-min-size", + cl::desc("minimal size of the basic block that should be aligned"), + cl::init(0), cl::ZeroOrMore, cl::Hidden, cl::cat(BoltOptCategory)); -cl::opt<unsigned> AlignBlocksThreshold( +static cl::opt<unsigned> AlignBlocksThreshold( "align-blocks-threshold", cl::desc( "align only blocks with frequency larger than containing function " @@ -42,19 +39,17 @@ cl::opt<unsigned> AlignBlocksThreshold( "containing function."), cl::init(800), cl::Hidden, cl::cat(BoltOptCategory)); -cl::opt<unsigned> AlignFunctionsMaxBytes( +static cl::opt<unsigned> AlignFunctionsMaxBytes( "align-functions-max-bytes", cl::desc("maximum number of bytes to use to align functions"), cl::init(32), cl::cat(BoltOptCategory)); -cl::opt<unsigned> -BlockAlignment("block-alignment", - cl::desc("boundary to use for alignment of basic blocks"), - cl::init(16), - cl::ZeroOrMore, - cl::cat(BoltOptCategory)); +static cl::opt<unsigned> + BlockAlignment("block-alignment", + cl::desc("boundary to use for alignment of basic blocks"), + cl::init(16), cl::ZeroOrMore, cl::cat(BoltOptCategory)); -cl::opt<bool> +static cl::opt<bool> UseCompactAligner("use-compact-aligner", cl::desc("Use compact approach for aligning functions"), cl::init(true), cl::cat(BoltOptCategory)); diff --git a/bolt/lib/Passes/FrameOptimizer.cpp b/bolt/lib/Passes/FrameOptimizer.cpp index 1c0f9555f9eb..81d4d9367f58 100644 --- a/bolt/lib/Passes/FrameOptimizer.cpp +++ b/bolt/lib/Passes/FrameOptimizer.cpp @@ -43,7 +43,7 @@ FrameOptimization("frame-opt", cl::ZeroOrMore, cl::cat(BoltOptCategory)); -cl::opt<bool> RemoveStores( +static cl::opt<bool> RemoveStores( "frame-opt-rm-stores", cl::init(FOP_NONE), cl::desc("apply additional analysis to remove stores (experimental)"), cl::cat(BoltOptCategory)); diff --git a/bolt/lib/Passes/PLTCall.cpp b/bolt/lib/Passes/PLTCall.cpp index 31c2d92ebc20..90b5f586a7ba 100644 --- a/bolt/lib/Passes/PLTCall.cpp +++ b/bolt/lib/Passes/PLTCall.cpp @@ -22,22 +22,16 @@ namespace opts { extern cl::OptionCategory BoltOptCategory; -cl::opt<bolt::PLTCall::OptType> -PLT("plt", - cl::desc("optimize PLT calls (requires linking with -znow)"), - cl::init(bolt::PLTCall::OT_NONE), - cl::values(clEnumValN(bolt::PLTCall::OT_NONE, - "none", - "do not optimize PLT calls"), - clEnumValN(bolt::PLTCall::OT_HOT, - "hot", - "optimize executed (hot) PLT calls"), - clEnumValN(bolt::PLTCall::OT_ALL, - "all", - "optimize all PLT calls")), - cl::ZeroOrMore, - cl::cat(BoltOptCategory)); - +static cl::opt<bolt::PLTCall::OptType> + PLT("plt", cl::desc("optimize PLT calls (requires linking with -znow)"), + cl::init(bolt::PLTCall::OT_NONE), + cl::values(clEnumValN(bolt::PLTCall::OT_NONE, "none", + "do not optimize PLT calls"), + clEnumValN(bolt::PLTCall::OT_HOT, "hot", + "optimize executed (hot) PLT calls"), + clEnumValN(bolt::PLTCall::OT_ALL, "all", + "optimize all PLT calls")), + cl::ZeroOrMore, cl::cat(BoltOptCategory)); } namespace llvm { diff --git a/bolt/lib/Passes/ProfileQualityStats.cpp b/bolt/lib/Passes/ProfileQualityStats.cpp index 78e6412f56ba..332c78da8a1e 100644 --- a/bolt/lib/Passes/ProfileQualityStats.cpp +++ b/bolt/lib/Passes/ProfileQualityStats.cpp @@ -24,12 +24,12 @@ using namespace bolt; namespace opts { extern cl::opt<unsigned> Verbosity; -cl::opt<unsigned> TopFunctionsForProfileQualityCheck( +static cl::opt<unsigned> TopFunctionsForProfileQualityCheck( "top-functions-for-profile-quality-check", cl::desc("number of hottest functions to print aggregated " "profile quality stats of."), cl::init(1000), cl::ZeroOrMore, cl::Hidden, cl::cat(BoltOptCategory)); -cl::opt<unsigned> PercentileForProfileQualityCheck( +static cl::opt<unsigned> PercentileForProfileQualityCheck( "percentile-for-profile-quality-check", cl::desc("Percentile of profile quality distributions over hottest " "functions to report."), diff --git a/bolt/lib/Passes/RetpolineInsertion.cpp b/bolt/lib/Passes/RetpolineInsertion.cpp index 171177d9e933..f8702893a222 100644 --- a/bolt/lib/Passes/RetpolineInsertion.cpp +++ b/bolt/lib/Passes/RetpolineInsertion.cpp @@ -33,19 +33,17 @@ namespace opts { extern cl::OptionCategory BoltCategory; -llvm::cl::opt<bool> InsertRetpolines("insert-retpolines", - cl::desc("run retpoline insertion pass"), - cl::cat(BoltCategory)); +static llvm::cl::opt<bool> + InsertRetpolines("insert-retpolines", + cl::desc("run retpoline insertion pass"), + cl::cat(BoltCategory)); -llvm::cl::opt<bool> -RetpolineLfence("retpoline-lfence", - cl::desc("determine if lfence instruction should exist in the retpoline"), - cl::init(true), - cl::ZeroOrMore, - cl::Hidden, - cl::cat(BoltCategory)); +static llvm::cl::opt<bool> RetpolineLfence( + "retpoline-lfence", + cl::desc("determine if lfence instruction should exist in the retpoline"), + cl::init(true), cl::ZeroOrMore, cl::Hidden, cl::cat(BoltCategory)); -cl::opt<RetpolineInsertion::AvailabilityOptions> R11Availability( +static cl::opt<RetpolineInsertion::AvailabilityOptions> R11Availability( "r11-availability", cl::desc("determine the availability of r11 before indirect branches"), cl::init(RetpolineInsertion::AvailabilityOptions::NEVER), diff --git a/bolt/lib/Passes/StokeInfo.cpp b/bolt/lib/Passes/StokeInfo.cpp index dd033508d200..9da460a2877c 100644 --- a/bolt/lib/Passes/StokeInfo.cpp +++ b/bolt/lib/Passes/StokeInfo.cpp @@ -21,7 +21,7 @@ using namespace llvm; using namespace bolt; namespace opts { -cl::OptionCategory StokeOptCategory("STOKE pass options"); +static cl::OptionCategory StokeOptCategory("STOKE pass options"); static cl::opt<std::string> StokeOutputDataFilename("stoke-out", diff --git a/bolt/lib/Passes/TailDuplication.cpp b/bolt/lib/Passes/TailDuplication.cpp index 463ea49527fa..354f9b78830c 100644 --- a/bolt/lib/Passes/TailDuplication.cpp +++ b/bolt/lib/Passes/TailDuplication.cpp @@ -26,7 +26,7 @@ namespace opts { extern cl::OptionCategory BoltOptCategory; extern cl::opt<bool> NoThreads; -cl::opt<bolt::TailDuplication::DuplicationMode> TailDuplicationMode( +static cl::opt<bolt::TailDuplication::DuplicationMode> TailDuplicationMode( "tail-duplication", cl::desc("duplicate unconditional branches that cross a cache line"), cl::init(bolt::TailDuplication::TD_NONE), diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp index b66a3f478f1a..1a61949d7747 100644 --- a/bolt/lib/Profile/StaleProfileMatching.cpp +++ b/bolt/lib/Profile/StaleProfileMatching.cpp @@ -52,66 +52,66 @@ cl::opt<bool> cl::desc("Infer counts from stale profile data."), cl::init(false), cl::Hidden, cl::cat(BoltOptCategory)); -cl::opt<unsigned> StaleMatchingMinMatchedBlock( +static cl::opt<unsigned> StaleMatchingMinMatchedBlock( "stale-matching-min-matched-block", cl::desc("Percentage threshold of matched basic blocks at which stale " "profile inference is executed."), cl::init(0), cl::Hidden, cl::cat(BoltOptCategory)); -cl::opt<unsigned> StaleMatchingMaxFuncSize( +static cl::opt<unsigned> StaleMatchingMaxFuncSize( "stale-matching-max-func-size", cl::desc("The maximum size of a function to consider for inference."), cl::init(10000), cl::Hidden, cl::cat(BoltOptCategory)); // Parameters of the profile inference algorithm. The default values are tuned // on several benchmarks. -cl::opt<bool> StaleMatchingEvenFlowDistribution( +static cl::opt<bool> StaleMatchingEvenFlowDistribution( "stale-matching-even-flow-distribution", cl::desc("Try to evenly distribute flow when there are multiple equally " "likely options."), cl::init(true), cl::ReallyHidden, cl::cat(BoltOptCategory)); -cl::opt<bool> StaleMatchingRebalanceUnknown( +static cl::opt<bool> StaleMatchingRebalanceUnknown( "stale-matching-rebalance-unknown", cl::desc("Evenly re-distribute flow among unknown subgraphs."), cl::init(false), cl::ReallyHidden, cl::cat(BoltOptCategory)); -cl::opt<bool> StaleMatchingJoinIslands( +static cl::opt<bool> StaleMatchingJoinIslands( "stale-matching-join-islands", cl::desc("Join isolated components having positive flow."), cl::init(true), cl::ReallyHidden, cl::cat(BoltOptCategory)); -cl::opt<unsigned> StaleMatchingCostBlockInc( +static cl::opt<unsigned> StaleMatchingCostBlockInc( "stale-matching-cost-block-inc", cl::desc("The cost of increasing a block count by one."), cl::init(150), cl::ReallyHidden, cl::cat(BoltOptCategory)); -cl::opt<unsigned> StaleMatchingCostBlockDec( +static cl::opt<unsigned> StaleMatchingCostBlockDec( "stale-matching-cost-block-dec", cl::desc("The cost of decreasing a block count by one."), cl::init(150), cl::ReallyHidden, cl::cat(BoltOptCategory)); -cl::opt<unsigned> StaleMatchingCostJumpInc( +static cl::opt<unsigned> StaleMatchingCostJumpInc( "stale-matching-cost-jump-inc", cl::desc("The cost of increasing a jump count by one."), cl::init(150), cl::ReallyHidden, cl::cat(BoltOptCategory)); -cl::opt<unsigned> StaleMatchingCostJumpDec( +static cl::opt<unsigned> StaleMatchingCostJumpDec( "stale-matching-cost-jump-dec", cl::desc("The cost of decreasing a jump count by one."), cl::init(150), cl::ReallyHidden, cl::cat(BoltOptCategory)); -cl::opt<unsigned> StaleMatchingCostBlockUnknownInc( +static cl::opt<unsigned> StaleMatchingCostBlockUnknownInc( "stale-matching-cost-block-unknown-inc", cl::desc("The cost of increasing an unknown block count by one."), cl::init(1), cl::ReallyHidden, cl::cat(BoltOptCategory)); -cl::opt<unsigned> StaleMatchingCostJumpUnknownInc( +static cl::opt<unsigned> StaleMatchingCostJumpUnknownInc( "stale-matching-cost-jump-unknown-inc", cl::desc("The cost of increasing an unknown jump count by one."), cl::init(140), cl::ReallyHidden, cl::cat(BoltOptCategory)); -cl::opt<unsigned> StaleMatchingCostJumpUnknownFTInc( +static cl::opt<unsigned> StaleMatchingCostJumpUnknownFTInc( "stale-matching-cost-jump-unknown-ft-inc", cl::desc( "The cost of increasing an unknown fall-through jump count by one."), diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp index e3872b373f41..f5636bfe3e1f 100644 --- a/bolt/lib/Profile/YAMLProfileReader.cpp +++ b/bolt/lib/Profile/YAMLProfileReader.cpp @@ -28,7 +28,7 @@ extern cl::OptionCategory BoltOptCategory; extern cl::opt<bool> InferStaleProfile; extern cl::opt<bool> Lite; -cl::opt<unsigned> NameSimilarityFunctionMatchingThreshold( +static cl::opt<unsigned> NameSimilarityFunctionMatchingThreshold( "name-similarity-function-matching-threshold", cl::desc("Match functions using namespace and edit distance"), cl::init(0), cl::Hidden, cl::cat(BoltOptCategory)); @@ -38,11 +38,11 @@ static llvm::cl::opt<bool> cl::desc("ignore hash while reading function profile"), cl::Hidden, cl::cat(BoltOptCategory)); -llvm::cl::opt<bool> +static llvm::cl::opt<bool> MatchProfileWithFunctionHash("match-profile-with-function-hash", cl::desc("Match profile with function hash"), cl::Hidden, cl::cat(BoltOptCategory)); -llvm::cl::opt<bool> +static llvm::cl::opt<bool> MatchWithCallGraph("match-with-call-graph", cl::desc("Match functions with call graph"), cl::Hidden, cl::cat(BoltOptCategory)); diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp index a97762063eb1..9a2d22871828 100644 --- a/bolt/lib/Rewrite/RewriteInstance.cpp +++ b/bolt/lib/Rewrite/RewriteInstance.cpp @@ -91,9 +91,10 @@ extern cl::opt<bolt::IdenticalCodeFolding::ICFLevel, false, llvm::bolt::DeprecatedICFNumericOptionParser> ICF; -cl::opt<bool> AllowStripped("allow-stripped", - cl::desc("allow processing of stripped binaries"), - cl::Hidden, cl::cat(BoltCategory)); +static cl::opt<bool> + AllowStripped("allow-stripped", + cl::desc("allow processing of stripped binaries"), cl::Hidden, + cl::cat(BoltCategory)); static cl::opt<bool> ForceToDataRelocations( "force-data-relocations", @@ -101,7 +102,7 @@ static cl::opt<bool> ForceToDataRelocations( cl::Hidden, cl::cat(BoltCategory)); -cl::opt<std::string> +static cl::opt<std::string> BoltID("bolt-id", cl::desc("add any string to tag this execution in the " "output binary via bolt info section"), @@ -175,9 +176,10 @@ cl::opt<bool> PrintAll("print-all", cl::desc("print functions after each stage"), cl::Hidden, cl::cat(BoltCategory)); -cl::opt<bool> PrintProfile("print-profile", - cl::desc("print functions after attaching profile"), - cl::Hidden, cl::cat(BoltCategory)); +static cl::opt<bool> + PrintProfile("print-profile", + cl::desc("print functions after attaching profile"), + cl::Hidden, cl::cat(BoltCategory)); cl::opt<bool> PrintCFG("print-cfg", cl::desc("print functions after CFG construction"), @@ -218,11 +220,10 @@ SkipFunctionNamesFile("skip-funcs-file", cl::Hidden, cl::cat(BoltCategory)); -cl::opt<bool> -TrapOldCode("trap-old-code", - cl::desc("insert traps in old function bodies (relocation mode)"), - cl::Hidden, - cl::cat(BoltCategory)); +static cl::opt<bool> TrapOldCode( + "trap-old-code", + cl::desc("insert traps in old function bodies (relocation mode)"), + cl::Hidden, cl::cat(BoltCategory)); static cl::opt<std::string> DWPPathName("dwp", cl::desc("Path and name to DWP file."), diff --git a/bolt/tools/bat-dump/bat-dump.cpp b/bolt/tools/bat-dump/bat-dump.cpp index 709eb076bca2..8a743cba1754 100644 --- a/bolt/tools/bat-dump/bat-dump.cpp +++ b/bolt/tools/bat-dump/bat-dump.cpp @@ -39,7 +39,7 @@ using namespace bolt; namespace opts { -cl::OptionCategory BatDumpCategory("BAT dump options"); +static cl::OptionCategory BatDumpCategory("BAT dump options"); static cl::OptionCategory *BatDumpCategories[] = {&BatDumpCategory}; diff --git a/bolt/tools/driver/llvm-bolt.cpp b/bolt/tools/driver/llvm-bolt.cpp index 6b6714723fa3..b9836c2397b6 100644 --- a/bolt/tools/driver/llvm-bolt.cpp +++ b/bolt/tools/driver/llvm-bolt.cpp @@ -63,7 +63,7 @@ BoltProfile("b", cl::aliasopt(InputDataFilename), cl::cat(BoltCategory)); -cl::opt<std::string> +static cl::opt<std::string> LogFile("log-file", cl::desc("redirect journaling to a file instead of stdout/stderr"), cl::Hidden, cl::cat(BoltCategory)); diff --git a/bolt/tools/merge-fdata/merge-fdata.cpp b/bolt/tools/merge-fdata/merge-fdata.cpp index 74a5f8ca2d47..864aa6747419 100644 --- a/bolt/tools/merge-fdata/merge-fdata.cpp +++ b/bolt/tools/merge-fdata/merge-fdata.cpp @@ -31,7 +31,7 @@ using namespace llvm::yaml::bolt; namespace opts { -cl::OptionCategory MergeFdataCategory("merge-fdata options"); +static cl::OptionCategory MergeFdataCategory("merge-fdata options"); enum SortType : char { ST_NONE,