Author: Fangrui Song Date: 2026-10-09T23:24:05-07:00 New Revision: 53310c92e86e1c285b1fe3aaf76158addd0a2036
URL: https://github.com/llvm/llvm-project/commit/53310c92e86e1c285b1fe3aaf76158addd0a2036 DIFF: https://github.com/llvm/llvm-project/commit/53310c92e86e1c285b1fe3aaf76158addd0a2036.diff LOG: [Instrumentation] Stop exporting cl::opts. NFC (#230725) Replace the `extern cl::opt` declarations of -profile-correlate in FrontendDriver and -pgo-instrument-cold-function-only in Passes with getters, and delete clang's unused declaration of the former. This prepares for moving Instrumentation's options into TableGen. Aided by Opus 5.5 Added: Modified: clang/lib/CodeGen/BackendUtil.cpp llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h llvm/lib/Frontend/Driver/CodeGenOptions.cpp llvm/lib/Passes/PassBuilderPipelines.cpp llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 1803c7943b326c..f07e4ee84b9b65 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -129,9 +129,6 @@ static cl::opt<PGOOptions::ColdFuncOpt> ClPGOColdFuncAttr( "Mark cold functions with minsize."), clEnumValN(PGOOptions::ColdFuncOpt::OptNone, "optnone", "Mark cold functions with optnone."))); - -LLVM_ABI extern cl::opt<InstrProfCorrelator::ProfCorrelatorKind> - ProfileCorrelate; } // namespace llvm namespace clang { extern llvm::cl::opt<bool> ClSanitizeGuardChecks; diff --git a/llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h b/llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h index a31bb1711e7845..9d4c40b25cd19a 100644 --- a/llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h +++ b/llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h @@ -36,6 +36,9 @@ class InstrProfilingLoweringPass LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); }; + +/// Return true if -profile-correlate is set. +LLVM_ABI bool isProfileCorrelationEnabled(); } // end namespace llvm #endif // LLVM_TRANSFORMS_INSTRUMENTATION_INSTRPROFILING_H diff --git a/llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h b/llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h index 0ae67576ed07a4..8f5c9d57d02d9d 100644 --- a/llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h +++ b/llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h @@ -111,6 +111,9 @@ LLVM_ABI void setProfMetadata(Instruction *TI, ArrayRef<uint64_t> EdgeCounts, LLVM_ABI void setIrrLoopHeaderMetadata(Module *M, Instruction *TI, uint64_t Count); +/// Return the value of -pgo-instrument-cold-function-only. +LLVM_ABI bool isPGOInstrumentColdFunctionOnly(); + } // end namespace llvm #endif // LLVM_TRANSFORMS_INSTRUMENTATION_PGOINSTRUMENTATION_H diff --git a/llvm/lib/Frontend/Driver/CodeGenOptions.cpp b/llvm/lib/Frontend/Driver/CodeGenOptions.cpp index d22202598a28dd..e4d5317d68fc85 100644 --- a/llvm/lib/Frontend/Driver/CodeGenOptions.cpp +++ b/llvm/lib/Frontend/Driver/CodeGenOptions.cpp @@ -9,13 +9,8 @@ #include "llvm/Frontend/Driver/CodeGenOptions.h" #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/IR/SystemLibraries.h" -#include "llvm/ProfileData/InstrProfCorrelator.h" #include "llvm/TargetParser/Triple.h" - -namespace llvm { -extern llvm::cl::opt<llvm::InstrProfCorrelator::ProfCorrelatorKind> - ProfileCorrelate; -} // namespace llvm +#include "llvm/Transforms/Instrumentation/InstrProfiling.h" namespace llvm::driver { @@ -51,8 +46,7 @@ TargetLibraryInfoImpl *createTLII(const llvm::Triple &TargetTriple, } std::string getDefaultProfileGenName() { - return llvm::ProfileCorrelate != InstrProfCorrelator::NONE - ? "default_%m.proflite" - : "default_%m.profraw"; + return isProfileCorrelationEnabled() ? "default_%m.proflite" + : "default_%m.profraw"; } } // namespace llvm::driver diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp index 4e7184f663a4df..699e4acec28ce9 100644 --- a/llvm/lib/Passes/PassBuilderPipelines.cpp +++ b/llvm/lib/Passes/PassBuilderPipelines.cpp @@ -162,7 +162,6 @@ using namespace llvm; namespace llvm { extern cl::opt<std::string> UseCtxProfile; -extern cl::opt<bool> PGOInstrumentColdFunctionOnly; extern cl::opt<bool> EnableMemProfContextDisambiguation; } // namespace llvm @@ -1118,11 +1117,11 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level, const bool IsCtxProfUse = !UseCtxProfile.empty() && isThinLTOPreLink(Phase); assert((Opts.instrument_cold_function_only_path.empty() || - PGOInstrumentColdFunctionOnly) && + isPGOInstrumentColdFunctionOnly()) && "--instrument-cold-function-only-path is provided but " "--pgo-instrument-cold-function-only is not enabled"); const bool IsColdFuncOnlyInstrGen = - PGOInstrumentColdFunctionOnly && IsPGOPreLink && + isPGOInstrumentColdFunctionOnly() && IsPGOPreLink && !Opts.instrument_cold_function_only_path.empty(); if (IsPGOInstrGen || IsPGOInstrUse || IsMemprofUse || IsCtxProfGen || diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp index e51d9b89c4e8fd..695e0c994a84cd 100644 --- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp +++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp @@ -73,7 +73,7 @@ namespace llvm { // Command line option to enable vtable value profiling. Defined in // ProfileData/InstrProf.cpp: -enable-vtable-value-profiling= extern cl::opt<bool> EnableVTableValueProfiling; -LLVM_ABI cl::opt<InstrProfCorrelator::ProfCorrelatorKind> ProfileCorrelate( +cl::opt<InstrProfCorrelator::ProfCorrelatorKind> ProfileCorrelate( "profile-correlate", cl::desc("Use debug info or binary file to correlate profiles."), cl::init(InstrProfCorrelator::NONE), @@ -85,6 +85,10 @@ LLVM_ABI cl::opt<InstrProfCorrelator::ProfCorrelatorKind> ProfileCorrelate( "Use binary to correlate"))); } // namespace llvm +bool llvm::isProfileCorrelationEnabled() { + return ProfileCorrelate != InstrProfCorrelator::NONE; +} + namespace { cl::opt<bool> DoHashBasedCounterSplit( diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp index b4c91c85d03419..173bcd0f52515d 100644 --- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -358,10 +358,13 @@ extern cl::opt<std::string> ViewBlockFreqFuncName; // ProfileData/InstrProf.cpp: -enable-vtable-value-profiling= extern cl::opt<bool> EnableVTableValueProfiling; extern cl::opt<bool> EnableVTableProfileUse; -LLVM_ABI extern cl::opt<InstrProfCorrelator::ProfCorrelatorKind> - ProfileCorrelate; +extern cl::opt<InstrProfCorrelator::ProfCorrelatorKind> ProfileCorrelate; } // namespace llvm +bool llvm::isPGOInstrumentColdFunctionOnly() { + return PGOInstrumentColdFunctionOnly; +} + namespace { class FunctionInstrumenter final { Module &M; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
