Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,8 @@ static void addSanitizers(const Triple &TargetTriple,
HWASanPass(SanitizerKind::KernelHWAddress, true);

if (LangOpts.Sanitize.has(SanitizerKind::DataFlow)) {
MPM.addPass(DataFlowSanitizerPass(LangOpts.NoSanitizeFiles));
MPM.addPass(DataFlowSanitizerPass(LangOpts.NoSanitizeFiles,
PB.getVirtualFileSystemPtr()));
}
};
if (ClSanitizeOnOptimizerEarlyEP) {
Expand Down Expand Up @@ -837,9 +838,9 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
if (CodeGenOpts.hasProfileIRInstr())
// -fprofile-generate.
PGOOpt = PGOOptions(getProfileGenName(CodeGenOpts), "", "",
CodeGenOpts.MemoryProfileUsePath, nullptr,
PGOOptions::IRInstr, PGOOptions::NoCSAction,
ClPGOColdFuncAttr, CodeGenOpts.DebugInfoForProfiling,
CodeGenOpts.MemoryProfileUsePath, PGOOptions::IRInstr,
PGOOptions::NoCSAction, ClPGOColdFuncAttr,
CodeGenOpts.DebugInfoForProfiling,
/*PseudoProbeForProfiling=*/false,
CodeGenOpts.AtomicProfileUpdate);
else if (CodeGenOpts.hasProfileIRUse()) {
Expand All @@ -848,32 +849,30 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
: PGOOptions::NoCSAction;
PGOOpt = PGOOptions(CodeGenOpts.ProfileInstrumentUsePath, "",
CodeGenOpts.ProfileRemappingFile,
CodeGenOpts.MemoryProfileUsePath, VFS,
PGOOptions::IRUse, CSAction, ClPGOColdFuncAttr,
CodeGenOpts.MemoryProfileUsePath, PGOOptions::IRUse,
CSAction, ClPGOColdFuncAttr,
CodeGenOpts.DebugInfoForProfiling);
} else if (!CodeGenOpts.SampleProfileFile.empty())
// -fprofile-sample-use
PGOOpt = PGOOptions(
CodeGenOpts.SampleProfileFile, "", CodeGenOpts.ProfileRemappingFile,
CodeGenOpts.MemoryProfileUsePath, VFS, PGOOptions::SampleUse,
CodeGenOpts.MemoryProfileUsePath, PGOOptions::SampleUse,
PGOOptions::NoCSAction, ClPGOColdFuncAttr,
CodeGenOpts.DebugInfoForProfiling, CodeGenOpts.PseudoProbeForProfiling);
else if (!CodeGenOpts.MemoryProfileUsePath.empty())
// -fmemory-profile-use (without any of the above options)
PGOOpt = PGOOptions("", "", "", CodeGenOpts.MemoryProfileUsePath, VFS,
PGOOpt = PGOOptions("", "", "", CodeGenOpts.MemoryProfileUsePath,
PGOOptions::NoAction, PGOOptions::NoCSAction,
ClPGOColdFuncAttr, CodeGenOpts.DebugInfoForProfiling);
else if (CodeGenOpts.PseudoProbeForProfiling)
// -fpseudo-probe-for-profiling
PGOOpt =
PGOOptions("", "", "", /*MemoryProfile=*/"", nullptr,
PGOOptions::NoAction, PGOOptions::NoCSAction,
ClPGOColdFuncAttr, CodeGenOpts.DebugInfoForProfiling, true);
PGOOpt = PGOOptions("", "", "", /*MemoryProfile=*/"", PGOOptions::NoAction,
PGOOptions::NoCSAction, ClPGOColdFuncAttr,
CodeGenOpts.DebugInfoForProfiling, true);
else if (CodeGenOpts.DebugInfoForProfiling)
// -fdebug-info-for-profiling
PGOOpt = PGOOptions("", "", "", /*MemoryProfile=*/"", nullptr,
PGOOptions::NoAction, PGOOptions::NoCSAction,
ClPGOColdFuncAttr, true);
PGOOpt = PGOOptions("", "", "", /*MemoryProfile=*/"", PGOOptions::NoAction,
PGOOptions::NoCSAction, ClPGOColdFuncAttr, true);

// Check to see if we want to generate a CS profile.
if (CodeGenOpts.hasProfileCSIRInstr()) {
Expand All @@ -889,7 +888,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
PGOOpt->CSAction = PGOOptions::CSIRInstr;
} else
PGOOpt = PGOOptions("", getProfileGenName(CodeGenOpts), "",
/*MemoryProfile=*/"", nullptr, PGOOptions::NoAction,
/*MemoryProfile=*/"", PGOOptions::NoAction,
PGOOptions::CSIRInstr, ClPGOColdFuncAttr,
CodeGenOpts.DebugInfoForProfiling);
}
Expand Down Expand Up @@ -926,7 +925,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
(CodeGenOpts.DebugPassManager || DebugPassStructure),
CodeGenOpts.VerifyEach, PrintPassOpts);
SI.registerCallbacks(PIC, &MAM);
PassBuilder PB(TM.get(), PTO, PGOOpt, &PIC);
PassBuilder PB(TM.get(), PTO, PGOOpt, &PIC, CI.getVirtualFileSystemPtr());

// Handle the assignment tracking feature options.
switch (CodeGenOpts.getAssignmentTrackingMode()) {
Expand Down
6 changes: 2 additions & 4 deletions flang/lib/Frontend/FrontendActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,20 +936,18 @@ void CodeGenAction::runOptimizationPipeline(llvm::raw_pwrite_stream &os) {
pgoOpt = llvm::PGOOptions(opts.InstrProfileOutput.empty()
? llvm::driver::getDefaultProfileGenName()
: opts.InstrProfileOutput,
"", "", opts.MemoryProfileUsePath, nullptr,
"", "", opts.MemoryProfileUsePath,
llvm::PGOOptions::IRInstr,
llvm::PGOOptions::NoCSAction,
llvm::PGOOptions::ColdFuncOpt::Default, false,
/*PseudoProbeForProfiling=*/false, false);
} else if (opts.hasProfileIRUse()) {
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS =
llvm::vfs::getRealFileSystem();
// -fprofile-use.
auto CSAction = opts.hasProfileCSIRUse() ? llvm::PGOOptions::CSIRUse
: llvm::PGOOptions::NoCSAction;
pgoOpt = llvm::PGOOptions(
opts.ProfileInstrumentUsePath, "", opts.ProfileRemappingFile,
opts.MemoryProfileUsePath, VFS, llvm::PGOOptions::IRUse, CSAction,
opts.MemoryProfileUsePath, llvm::PGOOptions::IRUse, CSAction,
llvm::PGOOptions::ColdFuncOpt::Default, false);
}

Expand Down
20 changes: 11 additions & 9 deletions llvm/include/llvm/Passes/PassBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/PGOOptions.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/IPO/Inliner.h"
#include "llvm/Transforms/IPO/ModuleInliner.h"
Expand All @@ -35,10 +36,6 @@ class StringRef;
class AAManager;
class TargetMachine;
class ModuleSummaryIndex;
template <typename T> class IntrusiveRefCntPtr;
namespace vfs {
class FileSystem;
} // namespace vfs

/// Tunable parameters for passes in the default pipelines.
class PipelineTuningOptions {
Expand Down Expand Up @@ -115,6 +112,7 @@ class PassBuilder {
PipelineTuningOptions PTO;
std::optional<PGOOptions> PGOOpt;
PassInstrumentationCallbacks *PIC;
IntrusiveRefCntPtr<vfs::FileSystem> FS;

public:
/// A struct to capture parsed pass pipeline names.
Expand All @@ -134,7 +132,8 @@ class PassBuilder {
TargetMachine *TM = nullptr,
PipelineTuningOptions PTO = PipelineTuningOptions(),
std::optional<PGOOptions> PGOOpt = std::nullopt,
PassInstrumentationCallbacks *PIC = nullptr);
PassInstrumentationCallbacks *PIC = nullptr,
IntrusiveRefCntPtr<vfs::FileSystem> FS = vfs::getRealFileSystem());

/// Cross register the analysis managers through their proxies.
///
Expand Down Expand Up @@ -632,15 +631,19 @@ class PassBuilder {
bool RunProfileGen, bool IsCS,
bool AtomicCounterUpdate,
std::string ProfileFile,
std::string ProfileRemappingFile,
IntrusiveRefCntPtr<vfs::FileSystem> FS);
std::string ProfileRemappingFile);

/// Returns PIC. External libraries can use this to register pass
/// instrumentation callbacks.
PassInstrumentationCallbacks *getPassInstrumentationCallbacks() const {
return PIC;
}

/// Returns the virtual file system.
IntrusiveRefCntPtr<vfs::FileSystem> getVirtualFileSystemPtr() const {
return FS;
}

// Invoke the callbacks registered for the various extension points.
// Custom pipelines should use these to invoke the callbacks registered
// by TargetMachines and other clients.
Expand Down Expand Up @@ -772,8 +775,7 @@ class PassBuilder {
void addPGOInstrPasses(ModulePassManager &MPM, OptimizationLevel Level,
bool RunProfileGen, bool IsCS,
bool AtomicCounterUpdate, std::string ProfileFile,
std::string ProfileRemappingFile,
IntrusiveRefCntPtr<vfs::FileSystem> FS);
std::string ProfileRemappingFile);
void addPostPGOLoopRotation(ModulePassManager &MPM, OptimizationLevel Level);

bool isInstrumentedPGOUse() const;
Expand Down
11 changes: 1 addition & 10 deletions llvm/include/llvm/Support/PGOOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,18 @@
#ifndef LLVM_SUPPORT_PGOOPTIONS_H
#define LLVM_SUPPORT_PGOOPTIONS_H

#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Error.h"

namespace llvm {

namespace vfs {
class FileSystem;
} // namespace vfs

/// A struct capturing PGO tunables.
struct PGOOptions {
enum PGOAction { NoAction, IRInstr, IRUse, SampleUse };
enum CSPGOAction { NoCSAction, CSIRInstr, CSIRUse };
enum class ColdFuncOpt { Default, OptSize, MinSize, OptNone };
LLVM_ABI PGOOptions(std::string ProfileFile, std::string CSProfileGenFile,
std::string ProfileRemappingFile,
std::string MemoryProfile,
IntrusiveRefCntPtr<vfs::FileSystem> FS,
PGOAction Action = NoAction,
std::string MemoryProfile, PGOAction Action = NoAction,
CSPGOAction CSAction = NoCSAction,
ColdFuncOpt ColdType = ColdFuncOpt::Default,
bool DebugInfoForProfiling = false,
Expand All @@ -53,7 +45,6 @@ struct PGOOptions {
bool DebugInfoForProfiling;
bool PseudoProbeForProfiling;
bool AtomicCounterUpdate;
IntrusiveRefCntPtr<vfs::FileSystem> FS;
};
} // namespace llvm

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "llvm/IR/PassManager.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/VirtualFileSystem.h"
#include <string>
#include <vector>

Expand All @@ -19,11 +20,13 @@ class Module;
class DataFlowSanitizerPass : public PassInfoMixin<DataFlowSanitizerPass> {
private:
std::vector<std::string> ABIListFiles;
IntrusiveRefCntPtr<vfs::FileSystem> FS;

public:
DataFlowSanitizerPass(
const std::vector<std::string> &ABIListFiles = std::vector<std::string>())
: ABIListFiles(ABIListFiles) {}
const std::vector<std::string> &ABIListFiles = std::vector<std::string>(),
IntrusiveRefCntPtr<vfs::FileSystem> FS = vfs::getRealFileSystem())
: ABIListFiles(ABIListFiles), FS(std::move(FS)) {}
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
static bool isRequired() { return true; }
};
Expand Down
17 changes: 8 additions & 9 deletions llvm/lib/LTO/LTOBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,27 +240,26 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
unsigned OptLevel, bool IsThinLTO,
ModuleSummaryIndex *ExportSummary,
const ModuleSummaryIndex *ImportSummary) {
auto FS = vfs::getRealFileSystem();
std::optional<PGOOptions> PGOOpt;
if (!Conf.SampleProfile.empty())
PGOOpt = PGOOptions(Conf.SampleProfile, "", Conf.ProfileRemapping,
/*MemoryProfile=*/"", FS, PGOOptions::SampleUse,
/*MemoryProfile=*/"", PGOOptions::SampleUse,
PGOOptions::NoCSAction,
PGOOptions::ColdFuncOpt::Default, true);
else if (Conf.RunCSIRInstr) {
PGOOpt = PGOOptions("", Conf.CSIRProfile, Conf.ProfileRemapping,
/*MemoryProfile=*/"", FS, PGOOptions::IRUse,
/*MemoryProfile=*/"", PGOOptions::IRUse,
PGOOptions::CSIRInstr, PGOOptions::ColdFuncOpt::Default,
Conf.AddFSDiscriminator);
} else if (!Conf.CSIRProfile.empty()) {
PGOOpt = PGOOptions(Conf.CSIRProfile, "", Conf.ProfileRemapping,
/*MemoryProfile=*/"", FS, PGOOptions::IRUse,
PGOOptions::CSIRUse, PGOOptions::ColdFuncOpt::Default,
Conf.AddFSDiscriminator);
PGOOpt =
PGOOptions(Conf.CSIRProfile, "", Conf.ProfileRemapping,
/*MemoryProfile=*/"", PGOOptions::IRUse, PGOOptions::CSIRUse,
PGOOptions::ColdFuncOpt::Default, Conf.AddFSDiscriminator);
NoPGOWarnMismatch = !Conf.PGOWarnMismatch;
} else if (Conf.AddFSDiscriminator) {
PGOOpt = PGOOptions("", "", "", /*MemoryProfile=*/"", nullptr,
PGOOptions::NoAction, PGOOptions::NoCSAction,
PGOOpt = PGOOptions("", "", "", /*MemoryProfile=*/"", PGOOptions::NoAction,
PGOOptions::NoCSAction,
PGOOptions::ColdFuncOpt::Default, true);
}
TM->setPGOOption(PGOOpt);
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Passes/PassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,9 @@ static Expected<OptimizationLevel> parseOptLevelParam(StringRef S) {

PassBuilder::PassBuilder(TargetMachine *TM, PipelineTuningOptions PTO,
std::optional<PGOOptions> PGOOpt,
PassInstrumentationCallbacks *PIC)
: TM(TM), PTO(PTO), PGOOpt(PGOOpt), PIC(PIC) {
PassInstrumentationCallbacks *PIC,
IntrusiveRefCntPtr<vfs::FileSystem> FS)
: TM(TM), PTO(PTO), PGOOpt(PGOOpt), PIC(PIC), FS(std::move(FS)) {
if (TM)
TM->registerPassBuilderCallbacks(*this);
if (PIC) {
Expand Down
43 changes: 19 additions & 24 deletions llvm/lib/Passes/PassBuilderPipelines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,8 +848,7 @@ void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM,
OptimizationLevel Level, bool RunProfileGen,
bool IsCS, bool AtomicCounterUpdate,
std::string ProfileFile,
std::string ProfileRemappingFile,
IntrusiveRefCntPtr<vfs::FileSystem> FS) {
std::string ProfileRemappingFile) {
assert(Level != OptimizationLevel::O0 && "Not expecting O0 here!");

if (!RunProfileGen) {
Expand Down Expand Up @@ -884,10 +883,11 @@ void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM,
MPM.addPass(InstrProfilingLoweringPass(Options, IsCS));
}

void PassBuilder::addPGOInstrPassesForO0(
ModulePassManager &MPM, bool RunProfileGen, bool IsCS,
bool AtomicCounterUpdate, std::string ProfileFile,
std::string ProfileRemappingFile, IntrusiveRefCntPtr<vfs::FileSystem> FS) {
void PassBuilder::addPGOInstrPassesForO0(ModulePassManager &MPM,
bool RunProfileGen, bool IsCS,
bool AtomicCounterUpdate,
std::string ProfileFile,
std::string ProfileRemappingFile) {
if (!RunProfileGen) {
assert(!ProfileFile.empty() && "Profile use expecting a profile file!");
MPM.addPass(
Expand Down Expand Up @@ -1133,8 +1133,8 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
if (LoadSampleProfile) {
// Annotate sample profile right after early FPM to ensure freshness of
// the debug info.
MPM.addPass(SampleProfileLoaderPass(PGOOpt->ProfileFile,
PGOOpt->ProfileRemappingFile, Phase));
MPM.addPass(SampleProfileLoaderPass(
PGOOpt->ProfileFile, PGOOpt->ProfileRemappingFile, Phase, FS));
// Cache ProfileSummaryAnalysis once to avoid the potential need to insert
// RequireAnalysisPass for PSI before subsequent non-module passes.
MPM.addPass(RequireAnalysisPass<ProfileSummaryAnalysis, Module>());
Expand Down Expand Up @@ -1230,8 +1230,7 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
addPGOInstrPasses(MPM, Level,
/*RunProfileGen=*/IsPGOInstrGen,
/*IsCS=*/false, PGOOpt->AtomicCounterUpdate,
PGOOpt->ProfileFile, PGOOpt->ProfileRemappingFile,
PGOOpt->FS);
PGOOpt->ProfileFile, PGOOpt->ProfileRemappingFile);
} else if (IsCtxProfGen || IsCtxProfUse) {
MPM.addPass(PGOInstrumentationGen(PGOInstrumentationType::CTXPROF));
// In pre-link, we just want the instrumented IR. We use the contextual
Expand All @@ -1254,10 +1253,10 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
addPostPGOLoopRotation(MPM, Level);
MPM.addPass(PGOCtxProfLoweringPass());
} else if (IsColdFuncOnlyInstrGen) {
addPGOInstrPasses(
MPM, Level, /* RunProfileGen */ true, /* IsCS */ false,
/* AtomicCounterUpdate */ false, InstrumentColdFuncOnlyPath,
/* ProfileRemappingFile */ "", IntrusiveRefCntPtr<vfs::FileSystem>());
addPGOInstrPasses(MPM, Level, /* RunProfileGen */ true, /* IsCS */ false,
/* AtomicCounterUpdate */ false,
InstrumentColdFuncOnlyPath,
/* ProfileRemappingFile */ "");
}

if (IsPGOInstrGen || IsPGOInstrUse || IsCtxProfGen)
Expand All @@ -1268,7 +1267,7 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
EnableSampledInstr));

if (IsMemprofUse)
MPM.addPass(MemProfUsePass(PGOOpt->MemoryProfile, PGOOpt->FS));
MPM.addPass(MemProfUsePass(PGOOpt->MemoryProfile, FS));

if (PGOOpt && (PGOOpt->Action == PGOOptions::IRUse ||
PGOOpt->Action == PGOOptions::SampleUse))
Expand Down Expand Up @@ -1477,13 +1476,11 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
if (PGOOpt->CSAction == PGOOptions::CSIRInstr)
addPGOInstrPasses(MPM, Level, /*RunProfileGen=*/true,
/*IsCS=*/true, PGOOpt->AtomicCounterUpdate,
PGOOpt->CSProfileGenFile, PGOOpt->ProfileRemappingFile,
PGOOpt->FS);
PGOOpt->CSProfileGenFile, PGOOpt->ProfileRemappingFile);
else if (PGOOpt->CSAction == PGOOptions::CSIRUse)
addPGOInstrPasses(MPM, Level, /*RunProfileGen=*/false,
/*IsCS=*/true, PGOOpt->AtomicCounterUpdate,
PGOOpt->ProfileFile, PGOOpt->ProfileRemappingFile,
PGOOpt->FS);
PGOOpt->ProfileFile, PGOOpt->ProfileRemappingFile);
}

// Re-compute GlobalsAA here prior to function passes. This is particularly
Expand Down Expand Up @@ -2070,13 +2067,11 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
if (PGOOpt->CSAction == PGOOptions::CSIRInstr)
addPGOInstrPasses(MPM, Level, /*RunProfileGen=*/true,
/*IsCS=*/true, PGOOpt->AtomicCounterUpdate,
PGOOpt->CSProfileGenFile, PGOOpt->ProfileRemappingFile,
PGOOpt->FS);
PGOOpt->CSProfileGenFile, PGOOpt->ProfileRemappingFile);
else if (PGOOpt->CSAction == PGOOptions::CSIRUse)
addPGOInstrPasses(MPM, Level, /*RunProfileGen=*/false,
/*IsCS=*/true, PGOOpt->AtomicCounterUpdate,
PGOOpt->ProfileFile, PGOOpt->ProfileRemappingFile,
PGOOpt->FS);
PGOOpt->ProfileFile, PGOOpt->ProfileRemappingFile);
}

// Break up allocas
Expand Down Expand Up @@ -2236,7 +2231,7 @@ PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level,
MPM,
/*RunProfileGen=*/(PGOOpt->Action == PGOOptions::IRInstr),
/*IsCS=*/false, PGOOpt->AtomicCounterUpdate, PGOOpt->ProfileFile,
PGOOpt->ProfileRemappingFile, PGOOpt->FS);
PGOOpt->ProfileRemappingFile);

// Instrument function entry and exit before all inlining.
MPM.addPass(createModuleToFunctionPassAdaptor(
Expand Down
Loading