llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-lld Author: Fangrui Song (MaskRay) <details> <summary>Changes</summary> Follow-up to #<!-- -->232365: drop `perContext = false` from PassesOptions, ScalarOptions, InstrumentationOptions, and CGDataOptions. * IR passes read their LLVMContext's options in run(). Legacy passes that chose analyses from an option now always require them (ConstantHoisting, StructurizeCFG, GVN). * Pass parameters that an option overrides are combined in run(), so -print-pipeline-passes no longer folds such options (e.g. -bonus-inst-threshold) into the printed parameters. * PipelineTuningOptions carries the library options to PassBuilder, which falls back to the TargetMachine's. opt, clang, flang, and Polly pass their module's. * The CodeGenData singleton is configured by its first caller. lld and llvm-cgdata pass an empty context. * GCOVOptions::getDefault is removed. LLM-aided --- Patch is 222.08 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/232599.diff 115 Files Affected: - (modified) clang/lib/CodeGen/BackendUtil.cpp (+29-19) - (modified) flang/lib/Frontend/FrontendActions.cpp (+4-2) - (modified) lld/MachO/Driver.cpp (+2-1) - (modified) llvm/include/llvm/CGData/CodeGenData.h (+33-16) - (modified) llvm/include/llvm/CGData/CodeGenDataReader.h (+9-4) - (modified) llvm/include/llvm/CGData/StableFunctionMap.h (+6-1) - (modified) llvm/include/llvm/CGData/StableFunctionMapRecord.h (+4-1) - (modified) llvm/include/llvm/Frontend/Driver/CodeGenOptions.h (+5-1) - (modified) llvm/include/llvm/Passes/PassBuilder.h (+22-3) - (modified) llvm/include/llvm/Passes/StandardInstrumentations.h (+24-7) - (modified) llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerCommon.h (+2-1) - (modified) llvm/include/llvm/Transforms/Instrumentation/ControlHeightReduction.h (+7-1) - (modified) llvm/include/llvm/Transforms/Instrumentation/GCOVProfiler.h (+3-2) - (modified) llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h (+5-1) - (modified) llvm/include/llvm/Transforms/Instrumentation/LowerAllowCheckPass.h (+6-1) - (modified) llvm/include/llvm/Transforms/Instrumentation/MemorySanitizer.h (+6) - (modified) llvm/include/llvm/Transforms/Instrumentation/PGOCtxProfLowering.h (+5-1) - (modified) llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h (+4-2) - (modified) llvm/include/llvm/Transforms/Scalar/ConstantHoisting.h (+2) - (modified) llvm/include/llvm/Transforms/Scalar/LICM.h (+17-11) - (modified) llvm/include/llvm/Transforms/Scalar/LoopUnrollPass.h (+8-2) - (modified) llvm/include/llvm/Transforms/Scalar/Reassociate.h (+1) - (modified) llvm/include/llvm/Transforms/Scalar/SpeculativeExecution.h (+3) - (modified) llvm/include/llvm/Transforms/Utils/Instrumentation.h (-2) - (modified) llvm/lib/CGData/CGDataOptions.td (+1-1) - (modified) llvm/lib/CGData/CodeGenData.cpp (+17-12) - (modified) llvm/lib/CGData/CodeGenDataReader.cpp (+11-7) - (modified) llvm/lib/CGData/StableFunctionMap.cpp (+6-4) - (modified) llvm/lib/CodeGen/GlobalMergeFunctions.cpp (+8-4) - (modified) llvm/lib/CodeGen/MachineOutliner.cpp (+8-4) - (modified) llvm/lib/Frontend/Driver/CodeGenOptions.cpp (+4-3) - (modified) llvm/lib/LTO/LTO.cpp (+3-2) - (modified) llvm/lib/Passes/PassBuilder.cpp (+11-6) - (modified) llvm/lib/Passes/PassBuilderPipelines.cpp (+15-9) - (modified) llvm/lib/Passes/PassesOptions.td (+1-1) - (modified) llvm/lib/Passes/RunCodeGen.cpp (+4-3) - (modified) llvm/lib/Passes/StandardInstrumentations.cpp (+38-44) - (modified) llvm/lib/Target/AMDGPU/AMDGPUSwLowerLDS.cpp (+2-2) - (modified) llvm/lib/Target/X86/X86MCInstLower.cpp (+2-1) - (modified) llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp (+7-4) - (modified) llvm/lib/Transforms/Instrumentation/AllocToken.cpp (+3-1) - (modified) llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp (+8-7) - (modified) llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp (+25-17) - (modified) llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp (+3-2) - (modified) llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp (+4-5) - (modified) llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp (+2-1) - (modified) llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp (+2-1) - (modified) llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp (+10-6) - (modified) llvm/lib/Transforms/Instrumentation/InstrumentationOptions.td (+1-1) - (modified) llvm/lib/Transforms/Instrumentation/LowerAllowCheckPass.cpp (+6-3) - (modified) llvm/lib/Transforms/Instrumentation/MemProfInstrumentation.cpp (+5-2) - (modified) llvm/lib/Transforms/Instrumentation/MemProfUse.cpp (+6-3) - (modified) llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp (+37-14) - (modified) llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp (+3-1) - (modified) llvm/lib/Transforms/Instrumentation/PGOCtxProfLowering.cpp (+7-3) - (modified) llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp (+27-17) - (modified) llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp (+3-2) - (modified) llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp (+3-2) - (modified) llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp (+2-1) - (modified) llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp (+2-1) - (modified) llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp (+2-1) - (modified) llvm/lib/Transforms/Instrumentation/ValueProfilePlugins.inc (+4-2) - (modified) llvm/lib/Transforms/Scalar/ADCE.cpp (+7-5) - (modified) llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp (+9-6) - (modified) llvm/lib/Transforms/Scalar/ConstantHoisting.cpp (+10-7) - (modified) llvm/lib/Transforms/Scalar/ConstraintElimination.cpp (+2-1) - (modified) llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp (+7-5) - (modified) llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp (+2-1) - (modified) llvm/lib/Transforms/Scalar/EarlyCSE.cpp (+20-9) - (modified) llvm/lib/Transforms/Scalar/ExpandMemCmp.cpp (+7-6) - (modified) llvm/lib/Transforms/Scalar/Float2Int.cpp (+2-1) - (modified) llvm/lib/Transforms/Scalar/GVN.cpp (+38-44) - (modified) llvm/lib/Transforms/Scalar/GVNHoist.cpp (+6-4) - (modified) llvm/lib/Transforms/Scalar/GuardWidening.cpp (+17-11) - (modified) llvm/lib/Transforms/Scalar/IndVarSimplify.cpp (+2-1) - (modified) llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp (+2-1) - (modified) llvm/lib/Transforms/Scalar/JumpTableToSwitch.cpp (+5-3) - (modified) llvm/lib/Transforms/Scalar/JumpThreading.cpp (+1-1) - (modified) llvm/lib/Transforms/Scalar/LICM.cpp (+40-38) - (modified) llvm/lib/Transforms/Scalar/LoopDataPrefetch.cpp (+10-6) - (modified) llvm/lib/Transforms/Scalar/LoopDeletion.cpp (+5-1) - (modified) llvm/lib/Transforms/Scalar/LoopDistribute.cpp (+2-1) - (modified) llvm/lib/Transforms/Scalar/LoopFlatten.cpp (+5-3) - (modified) llvm/lib/Transforms/Scalar/LoopFuse.cpp (+3-1) - (modified) llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp (+8-6) - (modified) llvm/lib/Transforms/Scalar/LoopInterchange.cpp (+7-5) - (modified) llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp (+2-1) - (modified) llvm/lib/Transforms/Scalar/LoopPredication.cpp (+7-5) - (modified) llvm/lib/Transforms/Scalar/LoopRotation.cpp (+2-1) - (modified) llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp (+6-3) - (modified) llvm/lib/Transforms/Scalar/LoopSink.cpp (+2-1) - (modified) llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp (+2-1) - (modified) llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp (+2-1) - (modified) llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp (+16-6) - (modified) llvm/lib/Transforms/Scalar/LoopVersioningLICM.cpp (+3-2) - (modified) llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp (+17-13) - (modified) llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp (+54-53) - (modified) llvm/lib/Transforms/Scalar/NewGVN.cpp (+7-7) - (modified) llvm/lib/Transforms/Scalar/PlaceSafepoints.cpp (+7-6) - (modified) llvm/lib/Transforms/Scalar/Reassociate.cpp (+5-1) - (modified) llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp (+2-1) - (modified) llvm/lib/Transforms/Scalar/SROA.cpp (+1-1) - (modified) llvm/lib/Transforms/Scalar/ScalarOptions.td (+1-1) - (modified) llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp (+2-1) - (modified) llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp (+2-1) - (modified) llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp (+10-13) - (modified) llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp (+7-11) - (modified) llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp (+12-6) - (modified) llvm/lib/Transforms/Scalar/StructurizeCFG.cpp (+20-19) - (modified) llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp (+2-1) - (modified) llvm/tools/llvm-cgdata/llvm-cgdata.cpp (+6-3) - (modified) llvm/tools/opt/NewPMDriver.cpp (+1-1) - (modified) llvm/unittests/CGData/StableFunctionMapTest.cpp (+4-3) - (modified) polly/lib/Support/RegisterPasses.cpp (+25-18) - (modified) polly/lib/Transform/ScopInliner.cpp (+1-1) ``````````diff diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 77c53c612df8f1..1ffcf7d7f6b0a7 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -144,10 +144,13 @@ extern llvm::cl::opt<bool> ClSanitizeGuardChecks; } // Path and name of file used for profile generation -static std::string getProfileGenName(const CodeGenOptions &CodeGenOpts) { - std::string FileName = CodeGenOpts.InstrProfileOutput.empty() - ? llvm::driver::getDefaultProfileGenName() - : CodeGenOpts.InstrProfileOutput; +static std::string +getProfileGenName(const cl::LibraryOptionsContext &LibraryOptions, + const CodeGenOptions &CodeGenOpts) { + std::string FileName = + CodeGenOpts.InstrProfileOutput.empty() + ? llvm::driver::getDefaultProfileGenName(LibraryOptions) + : CodeGenOpts.InstrProfileOutput; if (CodeGenOpts.ContinuousProfileSync) FileName = "%c" + FileName; return FileName; @@ -529,8 +532,8 @@ getGCOVOptions(const CodeGenOptions &CodeGenOpts, const LangOptions &LangOpts) { if (CodeGenOpts.CoverageNotesFile.empty() && CodeGenOpts.CoverageDataFile.empty()) return std::nullopt; - // Not using 'GCOVOptions::getDefault' allows us to avoid exiting if - // LLVM's -default-gcov-version flag is set to something invalid. + // Not using GCOVProfilerPass's default options allows us to avoid exiting + // if LLVM's -default-gcov-version flag is set to something invalid. GCOVOptions Options; Options.EmitNotes = !CodeGenOpts.CoverageNotesFile.empty(); Options.EmitData = !CodeGenOpts.CoverageDataFile.empty(); @@ -773,7 +776,8 @@ static void addSanitizers(const Triple &TargetTriple, } } -void addLowerAllowCheckPass(const CodeGenOptions &CodeGenOpts, +void addLowerAllowCheckPass(const cl::LibraryOptionsContext &LibraryOptions, + const CodeGenOptions &CodeGenOpts, const LangOptions &LangOpts, PassBuilder &PB) { // SanitizeSkipHotCutoffs: doubles with range [0, 1] // Opts.cutoffs: unsigned ints with range [0, 1000000] @@ -788,8 +792,9 @@ void addLowerAllowCheckPass(const CodeGenOptions &CodeGenOpts, SanitizerKind::KernelMemory | SanitizerKind::HWAddress | SanitizerKind::KernelHWAddress); - // TODO: remove IsRequested() - if (LowerAllowCheckPass::IsRequested() || ScaledCutoffs.has_value() || + // TODO: remove isRequested() + if (LowerAllowCheckPass::isRequested(LibraryOptions) || + ScaledCutoffs.has_value() || CodeGenOpts.AllowRuntimeCheckSkipHotCutoff.has_value() || LowerAllowSanitize) { // We want to call it after inline, which is about OptimizerEarlyEPCallback. @@ -798,7 +803,7 @@ void addLowerAllowCheckPass(const CodeGenOptions &CodeGenOpts, ModulePassManager &MPM, OptimizationLevel Level, ThinOrFullLTOPhase Phase) { LowerAllowCheckPass::Options Opts; - // TODO: after removing IsRequested(), make this unconditional + // TODO: after removing isRequested(), make this unconditional if (ScaledCutoffs.has_value()) Opts.cutoffs = ScaledCutoffs.value(); Opts.runtime_check = AllowRuntimeCheckSkipHotCutoff; @@ -843,11 +848,13 @@ static void addAMDGCNSPIRVSizeOptimizationPasses(ModulePassManager &MPM) { void EmitAssemblyHelper::RunOptimizationPipeline( BackendAction Action, std::unique_ptr<raw_pwrite_stream> &OS, std::unique_ptr<llvm::ToolOutputFile> &ThinLinkOS, BackendConsumer *BC) { + const cl::LibraryOptionsContext &LibraryOptions = + TheModule->getContext().getLibraryOptions(); std::optional<PGOOptions> PGOOpt; if (CodeGenOpts.hasProfileIRInstr()) // -fprofile-generate. - PGOOpt = PGOOptions(getProfileGenName(CodeGenOpts), "", "", + PGOOpt = PGOOptions(getProfileGenName(LibraryOptions, CodeGenOpts), "", "", CodeGenOpts.MemoryProfileUsePath, PGOOptions::IRInstr, PGOOptions::NoCSAction, ClPGOColdFuncAttr, CodeGenOpts.DebugInfoForProfiling, @@ -894,18 +901,18 @@ void EmitAssemblyHelper::RunOptimizationPipeline( PGOOpt->Action != PGOOptions::SampleUse && "Cannot run CSProfileGen pass with ProfileGen or SampleUse " " pass"); - PGOOpt->CSProfileGenFile = getProfileGenName(CodeGenOpts); + PGOOpt->CSProfileGenFile = getProfileGenName(LibraryOptions, CodeGenOpts); PGOOpt->CSAction = PGOOptions::CSIRInstr; } else - PGOOpt = PGOOptions("", getProfileGenName(CodeGenOpts), "", - /*MemoryProfile=*/"", PGOOptions::NoAction, - PGOOptions::CSIRInstr, ClPGOColdFuncAttr, - CodeGenOpts.DebugInfoForProfiling); + PGOOpt = PGOOptions( + "", getProfileGenName(LibraryOptions, CodeGenOpts), "", + /*MemoryProfile=*/"", PGOOptions::NoAction, PGOOptions::CSIRInstr, + ClPGOColdFuncAttr, CodeGenOpts.DebugInfoForProfiling); } if (TM) TM->setPGOOption(PGOOpt); - PipelineTuningOptions PTO; + PipelineTuningOptions PTO(&LibraryOptions); PTO.LoopUnrolling = CodeGenOpts.UnrollLoops; PTO.LoopInterchange = CodeGenOpts.InterchangeLoops; PTO.LoopFusion = CodeGenOpts.FuseLoops; @@ -1086,7 +1093,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline( // Most sanitizers only run during PreLink stage. addSanitizers(TargetTriple, CodeGenOpts, LangOpts, PB); addKCFIPass(TargetTriple, LangOpts, PB); - addLowerAllowCheckPass(CodeGenOpts, LangOpts, PB); + addLowerAllowCheckPass(LibraryOptions, CodeGenOpts, LangOpts, PB); PB.registerPipelineStartEPCallback( [&](ModulePassManager &MPM, OptimizationLevel Level) { @@ -1378,6 +1385,9 @@ runThinLTOBackend(CompilerInstance &CI, ModuleSummaryIndex *CombinedIndex, Conf.OptLevel = CGOpts.OptimizationLevel; initTargetOptions(CI, Diags, Conf.Options); Conf.SampleProfile = std::move(SampleProfile); + const cl::LibraryOptionsContext &LibraryOptions = + M->getContext().getLibraryOptions(); + Conf.PTO = PipelineTuningOptions(&LibraryOptions); Conf.PTO.LoopUnrolling = CGOpts.UnrollLoops; Conf.PTO.LoopInterchange = CGOpts.InterchangeLoops; Conf.PTO.LoopFusion = CGOpts.FuseLoops; @@ -1393,7 +1403,7 @@ runThinLTOBackend(CompilerInstance &CI, ModuleSummaryIndex *CombinedIndex, // Context sensitive profile. if (CGOpts.hasProfileCSIRInstr()) { Conf.RunCSIRInstr = true; - Conf.CSIRProfile = getProfileGenName(CGOpts); + Conf.CSIRProfile = getProfileGenName(LibraryOptions, CGOpts); } else if (CGOpts.hasProfileCSIRUse()) { Conf.RunCSIRInstr = false; Conf.CSIRProfile = std::move(CGOpts.ProfileInstrumentUsePath); diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp index b8b8b426dfe86d..21170893e6e898 100644 --- a/flang/lib/Frontend/FrontendActions.cpp +++ b/flang/lib/Frontend/FrontendActions.cpp @@ -974,14 +974,16 @@ void CodeGenAction::runOptimizationPipeline(llvm::raw_pwrite_stream &os) { // Create the pass manager builder. llvm::PassInstrumentationCallbacks pic; - llvm::PipelineTuningOptions pto; + const llvm::cl::LibraryOptionsContext &libraryOptions = + llvmModule->getContext().getLibraryOptions(); + llvm::PipelineTuningOptions pto(&libraryOptions); std::optional<llvm::PGOOptions> pgoOpt; if (opts.hasProfileIRInstr()) { // -fprofile-generate. pgoOpt = llvm::PGOOptions( opts.InstrProfileOutput.empty() - ? llvm::driver::getDefaultProfileGenName() + ? llvm::driver::getDefaultProfileGenName(libraryOptions) : opts.InstrProfileOutput, "", "", opts.MemoryProfileUsePath, llvm::PGOOptions::IRInstr, llvm::PGOOptions::NoCSAction, llvm::PGOOptions::ColdFuncOpt::Default, diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp index 0dfced91c511dd..5f2c541bdd2fd9 100644 --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -45,6 +45,7 @@ #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/FileSystem.h" +#include "llvm/Support/LibraryOptionsContext.h" #include "llvm/Support/Parallel.h" #include "llvm/Support/Path.h" #include "llvm/Support/Process.h" @@ -1562,7 +1563,7 @@ static void codegenDataGenerate() { } } - globalMergeRecord.finalize(); + globalMergeRecord.finalize(cl::LibraryOptionsContext()); CodeGenDataWriter Writer; if (!globalOutlineRecord.empty()) diff --git a/llvm/include/llvm/CGData/CodeGenData.h b/llvm/include/llvm/CGData/CodeGenData.h index cd1d849fdc1551..c1919428fa1d07 100644 --- a/llvm/include/llvm/CGData/CodeGenData.h +++ b/llvm/include/llvm/CGData/CodeGenData.h @@ -30,6 +30,10 @@ namespace llvm { +namespace cl { +class LibraryOptionsContext; +} // namespace cl + enum CGDataSectKind { #define CG_DATA_SECT_ENTRY(Kind, SectNameCommon, SectNameCoff, Prefix) Kind, #include "llvm/CGData/CodeGenData.inc" @@ -131,7 +135,9 @@ class CodeGenData { public: ~CodeGenData() = default; - LLVM_ABI static CodeGenData &getInstance(); + /// The first call's \p LibraryOptions configure the singleton. + LLVM_ABI static CodeGenData & + getInstance(const cl::LibraryOptionsContext &LibraryOptions); /// Returns true if we have a valid outlined hash tree. bool hasOutlinedHashTree() { @@ -169,32 +175,42 @@ class CodeGenData { namespace cgdata { -inline bool hasOutlinedHashTree() { - return CodeGenData::getInstance().hasOutlinedHashTree(); +inline bool +hasOutlinedHashTree(const cl::LibraryOptionsContext &LibraryOptions) { + return CodeGenData::getInstance(LibraryOptions).hasOutlinedHashTree(); } -inline bool hasStableFunctionMap() { - return CodeGenData::getInstance().hasStableFunctionMap(); +inline bool +hasStableFunctionMap(const cl::LibraryOptionsContext &LibraryOptions) { + return CodeGenData::getInstance(LibraryOptions).hasStableFunctionMap(); } -inline const OutlinedHashTree *getOutlinedHashTree() { - return CodeGenData::getInstance().getOutlinedHashTree(); +inline const OutlinedHashTree * +getOutlinedHashTree(const cl::LibraryOptionsContext &LibraryOptions) { + return CodeGenData::getInstance(LibraryOptions).getOutlinedHashTree(); } -inline const StableFunctionMap *getStableFunctionMap() { - return CodeGenData::getInstance().getStableFunctionMap(); +inline const StableFunctionMap * +getStableFunctionMap(const cl::LibraryOptionsContext &LibraryOptions) { + return CodeGenData::getInstance(LibraryOptions).getStableFunctionMap(); } -inline bool emitCGData() { return CodeGenData::getInstance().emitCGData(); } +inline bool emitCGData(const cl::LibraryOptionsContext &LibraryOptions) { + return CodeGenData::getInstance(LibraryOptions).emitCGData(); +} inline void -publishOutlinedHashTree(std::unique_ptr<OutlinedHashTree> HashTree) { - CodeGenData::getInstance().publishOutlinedHashTree(std::move(HashTree)); +publishOutlinedHashTree(const cl::LibraryOptionsContext &LibraryOptions, + std::unique_ptr<OutlinedHashTree> HashTree) { + CodeGenData::getInstance(LibraryOptions) + .publishOutlinedHashTree(std::move(HashTree)); } inline void -publishStableFunctionMap(std::unique_ptr<StableFunctionMap> FunctionMap) { - CodeGenData::getInstance().publishStableFunctionMap(std::move(FunctionMap)); +publishStableFunctionMap(const cl::LibraryOptionsContext &LibraryOptions, + std::unique_ptr<StableFunctionMap> FunctionMap) { + CodeGenData::getInstance(LibraryOptions) + .publishStableFunctionMap(std::move(FunctionMap)); } struct StreamCacheData { @@ -244,7 +260,7 @@ struct StreamCacheData { /// Returns whether ThinLTO runs two rounds of code generation /// (-codegen-data-thinlto-two-rounds). -LLVM_ABI bool thinLTOTwoRounds(); +LLVM_ABI bool thinLTOTwoRounds(const cl::LibraryOptionsContext &LibraryOptions); /// Save \p TheModule before the first codegen round. /// \p Task represents the partition number in the parallel code generation @@ -267,7 +283,8 @@ loadModuleForTwoRounds(BitcodeModule &OrigModule, unsigned Task, /// first codegen round. /// \return the combined hash of the merged codegen data. LLVM_ABI Expected<stable_hash> -mergeCodeGenData(ArrayRef<StringRef> ObjectFiles); +mergeCodeGenData(const cl::LibraryOptionsContext &LibraryOptions, + ArrayRef<StringRef> ObjectFiles); LLVM_ABI void warn(Error E, StringRef Whence = ""); LLVM_ABI void warn(Twine Message, StringRef Whence = "", StringRef Hint = ""); diff --git a/llvm/include/llvm/CGData/CodeGenDataReader.h b/llvm/include/llvm/CGData/CodeGenDataReader.h index 94f7af2de17012..0b827cd97c08b5 100644 --- a/llvm/include/llvm/CGData/CodeGenDataReader.h +++ b/llvm/include/llvm/CGData/CodeGenDataReader.h @@ -52,12 +52,14 @@ class CodeGenDataReader { /// codegen data file path and file system. \p LazyLoading defers /// deserializing the stable function map of indexed codegen data. LLVM_ABI static Expected<std::unique_ptr<CodeGenDataReader>> - create(const Twine &Path, vfs::FileSystem &FS, bool LazyLoading = false); + create(const cl::LibraryOptionsContext &LibraryOptions, const Twine &Path, + vfs::FileSystem &FS, bool LazyLoading = false); /// Factory method to create an appropriately typed reader for the given /// memory buffer. LLVM_ABI static Expected<std::unique_ptr<CodeGenDataReader>> - create(std::unique_ptr<MemoryBuffer> Buffer, bool LazyLoading = false); + create(const cl::LibraryOptionsContext &LibraryOptions, + std::unique_ptr<MemoryBuffer> Buffer, bool LazyLoading = false); /// Extract the cgdata embedded in sections from the given object file and /// merge them into the GlobalOutlineRecord. This is a static helper that @@ -101,6 +103,7 @@ class CodeGenDataReader { }; class LLVM_ABI IndexedCodeGenDataReader : public CodeGenDataReader { + bool ReadStableFunctionMapNames; /// The codegen data file contents. std::unique_ptr<MemoryBuffer> DataBuffer; /// The header @@ -108,9 +111,11 @@ class LLVM_ABI IndexedCodeGenDataReader : public CodeGenDataReader { bool LazyLoading; public: - IndexedCodeGenDataReader(std::unique_ptr<MemoryBuffer> DataBuffer, + IndexedCodeGenDataReader(bool ReadStableFunctionMapNames, + std::unique_ptr<MemoryBuffer> DataBuffer, bool LazyLoading = false) - : DataBuffer(std::move(DataBuffer)), LazyLoading(LazyLoading) {} + : ReadStableFunctionMapNames(ReadStableFunctionMapNames), + DataBuffer(std::move(DataBuffer)), LazyLoading(LazyLoading) {} IndexedCodeGenDataReader(const IndexedCodeGenDataReader &) = delete; IndexedCodeGenDataReader & operator=(const IndexedCodeGenDataReader &) = delete; diff --git a/llvm/include/llvm/CGData/StableFunctionMap.h b/llvm/include/llvm/CGData/StableFunctionMap.h index 909d0e1debe7e6..b9be47177c9a31 100644 --- a/llvm/include/llvm/CGData/StableFunctionMap.h +++ b/llvm/include/llvm/CGData/StableFunctionMap.h @@ -26,6 +26,10 @@ namespace llvm { +namespace cl { +class LibraryOptionsContext; +} // namespace cl + using IndexPairHash = std::pair<IndexPair, stable_hash>; using IndexOperandHashVecType = SmallVector<IndexPairHash>; @@ -153,7 +157,8 @@ struct StableFunctionMap { LLVM_ABI size_t size(SizeType Type = UniqueHashCount) const; /// Finalize the stable function map by trimming content. - LLVM_ABI void finalize(bool SkipTrim = false); + LLVM_ABI void finalize(const cl::LibraryOptionsContext &LibraryOptions, + bool SkipTrim = false); private: /// Insert a `StableFunctionEntry` into the function map directly. This diff --git a/llvm/include/llvm/CGData/StableFunctionMapRecord.h b/llvm/include/llvm/CGData/StableFunctionMapRecord.h index 2d8b573a3cb467..24e7ef1af2ea81 100644 --- a/llvm/include/llvm/CGData/StableFunctionMapRecord.h +++ b/llvm/include/llvm/CGData/StableFunctionMapRecord.h @@ -87,7 +87,10 @@ struct StableFunctionMapRecord { LLVM_ABI void deserializeYAML(yaml::Input &YIS); /// Finalize the stable function map by trimming content. - void finalize(bool SkipTrim = false) { FunctionMap->finalize(SkipTrim); } + void finalize(const cl::LibraryOptionsContext &LibraryOptions, + bool SkipTrim = false) { + FunctionMap->finalize(LibraryOptions, SkipTrim); + } /// Merge the stable function map into this one. void merge(const StableFunctionMapRecord &Other) { diff --git a/llvm/include/llvm/Frontend/Driver/CodeGenOptions.h b/llvm/include/llvm/Frontend/Driver/CodeGenOptions.h index 77ab477986d31c..3d292139cb7d06 100644 --- a/llvm/include/llvm/Frontend/Driver/CodeGenOptions.h +++ b/llvm/include/llvm/Frontend/Driver/CodeGenOptions.h @@ -20,6 +20,9 @@ namespace llvm { class Triple; class TargetLibraryInfoImpl; enum class VectorLibrary; +namespace cl { +class LibraryOptionsContext; +} // namespace cl } // namespace llvm namespace llvm::driver { @@ -67,7 +70,8 @@ enum ProfileInstrKind { }; // Default filename used for profile generation. -LLVM_ABI std::string getDefaultProfileGenName(); +LLVM_ABI std::string +getDefaultProfileGenName(const cl::LibraryOptionsContext &LibraryOptions); } // end namespace llvm::driver #endif diff --git a/llvm/include/llvm/Passes/PassBuilder.h b/llvm/include/llvm/Passes/PassBuilder.h index 502dfd93842bea..2dd74624b424e3 100644 --- a/llvm/include/llvm/Passes/PassBuilder.h +++ b/llvm/include/llvm/Passes/PassBuilder.h @@ -37,13 +37,24 @@ class AAManager; class TargetMachine; class ModuleSummaryIndex; struct PassesOptions; +namespace cl { +class LibraryOptionsContext; +} // namespace cl /// Tunable parameters for passes in the default pipelines. class PipelineTuningOptions { public: - /// Constructor sets pipeline tuning defaults based on cl::opts. Each option - /// can be set in the PassBuilder when using a LLVM as a library. - LLVM_ABI PipelineTuningOptions(); + /// Constructor sets pipeline tuning defaults based on the global values of + /// the library options. Each option can be set in the PassBuilder when using + /// a LLVM as a library. + PipelineTuningOptions() : PipelineTuningOptions(nullptr) {} + + /// Reads the defaults from \p LibraryOptions, or their global values if + /// null. + LLVM_ABI explicit PipelineTuningOptions( + const cl::LibraryOptionsContext *LibraryOptions); + + const cl::LibraryOptionsContext *LibraryOptions; /// Tuning option to set loop interleaving on/off, set based on opt level. bool LoopInterleaving; @@ -118,6 +129,7 @@ enum class PrintPipelinePassesFormat { /// of the built-in passes, and those may reference these members during /// construction. class PassBuilder { + const cl::LibraryOptionsContext *LibraryOptions; const PassesOptions &Opts; TargetMachine *TM; PipelineTuningOptions PTO; @@ -674,6 +686,13 @@ class PassBuilder { return PIC; } + /// Returns the library options the pipelines read: the + /// PipelineTuningOptions', else the TargetMachine's, else null for the global + /// values. + const cl::LibraryOptionsContext *getLibraryOptions() const { + return LibraryOptions; + } + /// Returns the virtual file system. IntrusiveRefCntPtr<vfs::FileSystem> getVirtualFileSystemPtr() const { return FS; diff --git a/llvm/include/llvm/Passes/StandardInstrumentations.h b/llvm/include/llvm/Passes/StandardInstrumentations.h index d485ea78f462a1..1c378941cc1259 100644 --- a/llvm/include/llvm/Passes/StandardInstrumentations.h +++ b/llvm/include/llvm/Passes/StandardInstrumentations.h @@ -43,6 +43,7 @@ class Function; class MachineFunction; class PassInstrumentationCallbacks; struct ExtendedIRContext; +struct PassesOptions; /// Instrumentation to print IR before/after passes. /// @@ -50,6 +51,7 @@ struct ExtendedIRContext; /// (typically Loop or SCC). class PrintIRInstrumentation { public: + explicit PrintIRInstrumentation(const PassesOptions &Opts) : Opts(Opts) {} LLVM_ABI ~PrintIRInstrumentation(); LLVM_ABI void registerCallbacks(PassInstrumentationCallbacks &PIC, @@ -98,6 +100,7 @@ class PrintIRInstrumentation { unsigned PassNumber, IRDumpFileSuffixType SuffixType); + const PassesOptions ... [truncated] `````````` </details> https://github.com/llvm/llvm-project/pull/232599 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
