mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-30 17:21:10 +00:00
[PGO] Enable -fprofile-update
for -fprofile-generate
Currently, the `-fprofile-udpate` is ignored when `-fprofile-generate` is in effect. This patch enables `-fprofile-update` for `-fprofile-generate`. This patch continues the work from https://reviews.llvm.org/D87737, which added `-fprofile-update` in the first place. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D157280
This commit is contained in:
parent
b7fcf51515
commit
611ce24114
@ -2759,9 +2759,6 @@ programs using the same instrumentation method as ``-fprofile-generate``.
|
|||||||
overhead. ``prefer-atomic`` will be transformed to ``atomic`` when supported
|
overhead. ``prefer-atomic`` will be transformed to ``atomic`` when supported
|
||||||
by the target, or ``single`` otherwise.
|
by the target, or ``single`` otherwise.
|
||||||
|
|
||||||
This option currently works with ``-fprofile-arcs`` and ``-fprofile-instr-generate``,
|
|
||||||
but not with ``-fprofile-generate``.
|
|
||||||
|
|
||||||
Disabling Instrumentation
|
Disabling Instrumentation
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
@ -768,7 +768,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
|
|||||||
CodeGenOpts.InstrProfileOutput.empty() ? getDefaultProfileGenName()
|
CodeGenOpts.InstrProfileOutput.empty() ? getDefaultProfileGenName()
|
||||||
: CodeGenOpts.InstrProfileOutput,
|
: CodeGenOpts.InstrProfileOutput,
|
||||||
"", "", CodeGenOpts.MemoryProfileUsePath, nullptr, PGOOptions::IRInstr,
|
"", "", CodeGenOpts.MemoryProfileUsePath, nullptr, PGOOptions::IRInstr,
|
||||||
PGOOptions::NoCSAction, CodeGenOpts.DebugInfoForProfiling);
|
PGOOptions::NoCSAction, CodeGenOpts.DebugInfoForProfiling,
|
||||||
|
/*PseudoProbeForProfiling=*/false, CodeGenOpts.AtomicProfileUpdate);
|
||||||
else if (CodeGenOpts.hasProfileIRUse()) {
|
else if (CodeGenOpts.hasProfileIRUse()) {
|
||||||
// -fprofile-use.
|
// -fprofile-use.
|
||||||
auto CSAction = CodeGenOpts.hasProfileCSIRUse() ? PGOOptions::CSIRUse
|
auto CSAction = CodeGenOpts.hasProfileCSIRUse() ? PGOOptions::CSIRUse
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
// RUN: %clang_cc1 %s -emit-llvm -fprofile-instrument=clang -fprofile-update=atomic -o - | FileCheck %s
|
// RUN: %clang_cc1 %s -emit-llvm -fprofile-instrument=clang -fprofile-update=atomic -o - | FileCheck %s
|
||||||
|
// RUN: %clang %s -S -emit-llvm -fprofile-generate -fprofile-update=atomic -o - | FileCheck %s
|
||||||
|
// RUN: %clang -O3 %s -S -emit-llvm -fprofile-generate -fprofile-update=atomic -o - | FileCheck %s
|
||||||
|
|
||||||
// CHECK: define {{.*}}@foo
|
// CHECK: define {{.*}}@foo
|
||||||
// CHECK-NOT: load {{.*}}foo
|
// CHECK-NOT: load {{.*}}foo
|
||||||
|
@ -560,7 +560,8 @@ public:
|
|||||||
|
|
||||||
/// Add PGOInstrumenation passes for O0 only.
|
/// Add PGOInstrumenation passes for O0 only.
|
||||||
void addPGOInstrPassesForO0(ModulePassManager &MPM, bool RunProfileGen,
|
void addPGOInstrPassesForO0(ModulePassManager &MPM, bool RunProfileGen,
|
||||||
bool IsCS, std::string ProfileFile,
|
bool IsCS, bool AtomicCounterUpdate,
|
||||||
|
std::string ProfileFile,
|
||||||
std::string ProfileRemappingFile,
|
std::string ProfileRemappingFile,
|
||||||
IntrusiveRefCntPtr<vfs::FileSystem> FS);
|
IntrusiveRefCntPtr<vfs::FileSystem> FS);
|
||||||
|
|
||||||
@ -628,7 +629,8 @@ private:
|
|||||||
ArrayRef<PipelineElement> Pipeline);
|
ArrayRef<PipelineElement> Pipeline);
|
||||||
|
|
||||||
void addPGOInstrPasses(ModulePassManager &MPM, OptimizationLevel Level,
|
void addPGOInstrPasses(ModulePassManager &MPM, OptimizationLevel Level,
|
||||||
bool RunProfileGen, bool IsCS, std::string ProfileFile,
|
bool RunProfileGen, bool IsCS,
|
||||||
|
bool AtomicCounterUpdate, std::string ProfileFile,
|
||||||
std::string ProfileRemappingFile,
|
std::string ProfileRemappingFile,
|
||||||
ThinOrFullLTOPhase LTOPhase,
|
ThinOrFullLTOPhase LTOPhase,
|
||||||
IntrusiveRefCntPtr<vfs::FileSystem> FS);
|
IntrusiveRefCntPtr<vfs::FileSystem> FS);
|
||||||
|
@ -32,7 +32,8 @@ struct PGOOptions {
|
|||||||
IntrusiveRefCntPtr<vfs::FileSystem> FS,
|
IntrusiveRefCntPtr<vfs::FileSystem> FS,
|
||||||
PGOAction Action = NoAction, CSPGOAction CSAction = NoCSAction,
|
PGOAction Action = NoAction, CSPGOAction CSAction = NoCSAction,
|
||||||
bool DebugInfoForProfiling = false,
|
bool DebugInfoForProfiling = false,
|
||||||
bool PseudoProbeForProfiling = false);
|
bool PseudoProbeForProfiling = false,
|
||||||
|
bool AtomicCounterUpdate = false);
|
||||||
PGOOptions(const PGOOptions &);
|
PGOOptions(const PGOOptions &);
|
||||||
~PGOOptions();
|
~PGOOptions();
|
||||||
PGOOptions &operator=(const PGOOptions &);
|
PGOOptions &operator=(const PGOOptions &);
|
||||||
@ -45,6 +46,7 @@ struct PGOOptions {
|
|||||||
CSPGOAction CSAction;
|
CSPGOAction CSAction;
|
||||||
bool DebugInfoForProfiling;
|
bool DebugInfoForProfiling;
|
||||||
bool PseudoProbeForProfiling;
|
bool PseudoProbeForProfiling;
|
||||||
|
bool AtomicCounterUpdate;
|
||||||
IntrusiveRefCntPtr<vfs::FileSystem> FS;
|
IntrusiveRefCntPtr<vfs::FileSystem> FS;
|
||||||
};
|
};
|
||||||
} // namespace llvm
|
} // namespace llvm
|
||||||
|
@ -724,7 +724,8 @@ void PassBuilder::addRequiredLTOPreLinkPasses(ModulePassManager &MPM) {
|
|||||||
|
|
||||||
void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM,
|
void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM,
|
||||||
OptimizationLevel Level, bool RunProfileGen,
|
OptimizationLevel Level, bool RunProfileGen,
|
||||||
bool IsCS, std::string ProfileFile,
|
bool IsCS, bool AtomicCounterUpdate,
|
||||||
|
std::string ProfileFile,
|
||||||
std::string ProfileRemappingFile,
|
std::string ProfileRemappingFile,
|
||||||
ThinOrFullLTOPhase LTOPhase,
|
ThinOrFullLTOPhase LTOPhase,
|
||||||
IntrusiveRefCntPtr<vfs::FileSystem> FS) {
|
IntrusiveRefCntPtr<vfs::FileSystem> FS) {
|
||||||
@ -793,13 +794,14 @@ void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM,
|
|||||||
// Do counter promotion at Level greater than O0.
|
// Do counter promotion at Level greater than O0.
|
||||||
Options.DoCounterPromotion = true;
|
Options.DoCounterPromotion = true;
|
||||||
Options.UseBFIInPromotion = IsCS;
|
Options.UseBFIInPromotion = IsCS;
|
||||||
|
Options.Atomic = AtomicCounterUpdate;
|
||||||
MPM.addPass(InstrProfiling(Options, IsCS));
|
MPM.addPass(InstrProfiling(Options, IsCS));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PassBuilder::addPGOInstrPassesForO0(
|
void PassBuilder::addPGOInstrPassesForO0(
|
||||||
ModulePassManager &MPM, bool RunProfileGen, bool IsCS,
|
ModulePassManager &MPM, bool RunProfileGen, bool IsCS,
|
||||||
std::string ProfileFile, std::string ProfileRemappingFile,
|
bool AtomicCounterUpdate, std::string ProfileFile,
|
||||||
IntrusiveRefCntPtr<vfs::FileSystem> FS) {
|
std::string ProfileRemappingFile, IntrusiveRefCntPtr<vfs::FileSystem> FS) {
|
||||||
if (!RunProfileGen) {
|
if (!RunProfileGen) {
|
||||||
assert(!ProfileFile.empty() && "Profile use expecting a profile file!");
|
assert(!ProfileFile.empty() && "Profile use expecting a profile file!");
|
||||||
MPM.addPass(
|
MPM.addPass(
|
||||||
@ -819,6 +821,7 @@ void PassBuilder::addPGOInstrPassesForO0(
|
|||||||
// Do not do counter promotion at O0.
|
// Do not do counter promotion at O0.
|
||||||
Options.DoCounterPromotion = false;
|
Options.DoCounterPromotion = false;
|
||||||
Options.UseBFIInPromotion = IsCS;
|
Options.UseBFIInPromotion = IsCS;
|
||||||
|
Options.Atomic = AtomicCounterUpdate;
|
||||||
MPM.addPass(InstrProfiling(Options, IsCS));
|
MPM.addPass(InstrProfiling(Options, IsCS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1093,9 +1096,10 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
|
|||||||
(PGOOpt->Action == PGOOptions::IRInstr ||
|
(PGOOpt->Action == PGOOptions::IRInstr ||
|
||||||
PGOOpt->Action == PGOOptions::IRUse)) {
|
PGOOpt->Action == PGOOptions::IRUse)) {
|
||||||
addPGOInstrPasses(MPM, Level,
|
addPGOInstrPasses(MPM, Level,
|
||||||
/* RunProfileGen */ PGOOpt->Action == PGOOptions::IRInstr,
|
/*RunProfileGen=*/PGOOpt->Action == PGOOptions::IRInstr,
|
||||||
/* IsCS */ false, PGOOpt->ProfileFile,
|
/*IsCS=*/false, PGOOpt->AtomicCounterUpdate,
|
||||||
PGOOpt->ProfileRemappingFile, Phase, PGOOpt->FS);
|
PGOOpt->ProfileFile, PGOOpt->ProfileRemappingFile, Phase,
|
||||||
|
PGOOpt->FS);
|
||||||
MPM.addPass(PGOIndirectCallPromotion(false, false));
|
MPM.addPass(PGOIndirectCallPromotion(false, false));
|
||||||
}
|
}
|
||||||
if (PGOOpt && Phase != ThinOrFullLTOPhase::ThinLTOPostLink &&
|
if (PGOOpt && Phase != ThinOrFullLTOPhase::ThinLTOPostLink &&
|
||||||
@ -1306,13 +1310,15 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
|
|||||||
// instrumentation is after all the inlines are done.
|
// instrumentation is after all the inlines are done.
|
||||||
if (!LTOPreLink && PGOOpt) {
|
if (!LTOPreLink && PGOOpt) {
|
||||||
if (PGOOpt->CSAction == PGOOptions::CSIRInstr)
|
if (PGOOpt->CSAction == PGOOptions::CSIRInstr)
|
||||||
addPGOInstrPasses(MPM, Level, /* RunProfileGen */ true,
|
addPGOInstrPasses(MPM, Level, /*RunProfileGen=*/true,
|
||||||
/* IsCS */ true, PGOOpt->CSProfileGenFile,
|
/*IsCS=*/true, PGOOpt->AtomicCounterUpdate,
|
||||||
PGOOpt->ProfileRemappingFile, LTOPhase, PGOOpt->FS);
|
PGOOpt->CSProfileGenFile, PGOOpt->ProfileRemappingFile,
|
||||||
|
LTOPhase, PGOOpt->FS);
|
||||||
else if (PGOOpt->CSAction == PGOOptions::CSIRUse)
|
else if (PGOOpt->CSAction == PGOOptions::CSIRUse)
|
||||||
addPGOInstrPasses(MPM, Level, /* RunProfileGen */ false,
|
addPGOInstrPasses(MPM, Level, /*RunProfileGen=*/false,
|
||||||
/* IsCS */ true, PGOOpt->ProfileFile,
|
/*IsCS=*/true, PGOOpt->AtomicCounterUpdate,
|
||||||
PGOOpt->ProfileRemappingFile, LTOPhase, PGOOpt->FS);
|
PGOOpt->ProfileFile, PGOOpt->ProfileRemappingFile,
|
||||||
|
LTOPhase, PGOOpt->FS);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-compute GlobalsAA here prior to function passes. This is particularly
|
// Re-compute GlobalsAA here prior to function passes. This is particularly
|
||||||
@ -1787,14 +1793,14 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
|
|||||||
// sensitive PGO pass.
|
// sensitive PGO pass.
|
||||||
if (PGOOpt) {
|
if (PGOOpt) {
|
||||||
if (PGOOpt->CSAction == PGOOptions::CSIRInstr)
|
if (PGOOpt->CSAction == PGOOptions::CSIRInstr)
|
||||||
addPGOInstrPasses(MPM, Level, /* RunProfileGen */ true,
|
addPGOInstrPasses(MPM, Level, /*RunProfileGen=*/true,
|
||||||
/* IsCS */ true, PGOOpt->CSProfileGenFile,
|
/*IsCS=*/true, PGOOpt->AtomicCounterUpdate,
|
||||||
PGOOpt->ProfileRemappingFile,
|
PGOOpt->CSProfileGenFile, PGOOpt->ProfileRemappingFile,
|
||||||
ThinOrFullLTOPhase::FullLTOPostLink, PGOOpt->FS);
|
ThinOrFullLTOPhase::FullLTOPostLink, PGOOpt->FS);
|
||||||
else if (PGOOpt->CSAction == PGOOptions::CSIRUse)
|
else if (PGOOpt->CSAction == PGOOptions::CSIRUse)
|
||||||
addPGOInstrPasses(MPM, Level, /* RunProfileGen */ false,
|
addPGOInstrPasses(MPM, Level, /*RunProfileGen=*/false,
|
||||||
/* IsCS */ true, PGOOpt->ProfileFile,
|
/*IsCS=*/true, PGOOpt->AtomicCounterUpdate,
|
||||||
PGOOpt->ProfileRemappingFile,
|
PGOOpt->ProfileFile, PGOOpt->ProfileRemappingFile,
|
||||||
ThinOrFullLTOPhase::FullLTOPostLink, PGOOpt->FS);
|
ThinOrFullLTOPhase::FullLTOPostLink, PGOOpt->FS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1939,9 +1945,9 @@ ModulePassManager PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level,
|
|||||||
PGOOpt->Action == PGOOptions::IRUse))
|
PGOOpt->Action == PGOOptions::IRUse))
|
||||||
addPGOInstrPassesForO0(
|
addPGOInstrPassesForO0(
|
||||||
MPM,
|
MPM,
|
||||||
/* RunProfileGen */ (PGOOpt->Action == PGOOptions::IRInstr),
|
/*RunProfileGen=*/(PGOOpt->Action == PGOOptions::IRInstr),
|
||||||
/* IsCS */ false, PGOOpt->ProfileFile, PGOOpt->ProfileRemappingFile,
|
/*IsCS=*/false, PGOOpt->AtomicCounterUpdate, PGOOpt->ProfileFile,
|
||||||
PGOOpt->FS);
|
PGOOpt->ProfileRemappingFile, PGOOpt->FS);
|
||||||
|
|
||||||
invokePipelineStartEPCallbacks(MPM, Level);
|
invokePipelineStartEPCallbacks(MPM, Level);
|
||||||
|
|
||||||
|
@ -16,13 +16,14 @@ PGOOptions::PGOOptions(std::string ProfileFile, std::string CSProfileGenFile,
|
|||||||
std::string MemoryProfile,
|
std::string MemoryProfile,
|
||||||
IntrusiveRefCntPtr<vfs::FileSystem> FS, PGOAction Action,
|
IntrusiveRefCntPtr<vfs::FileSystem> FS, PGOAction Action,
|
||||||
CSPGOAction CSAction, bool DebugInfoForProfiling,
|
CSPGOAction CSAction, bool DebugInfoForProfiling,
|
||||||
bool PseudoProbeForProfiling)
|
bool PseudoProbeForProfiling, bool AtomicCounterUpdate)
|
||||||
: ProfileFile(ProfileFile), CSProfileGenFile(CSProfileGenFile),
|
: ProfileFile(ProfileFile), CSProfileGenFile(CSProfileGenFile),
|
||||||
ProfileRemappingFile(ProfileRemappingFile), MemoryProfile(MemoryProfile),
|
ProfileRemappingFile(ProfileRemappingFile), MemoryProfile(MemoryProfile),
|
||||||
Action(Action), CSAction(CSAction),
|
Action(Action), CSAction(CSAction),
|
||||||
DebugInfoForProfiling(DebugInfoForProfiling ||
|
DebugInfoForProfiling(DebugInfoForProfiling ||
|
||||||
(Action == SampleUse && !PseudoProbeForProfiling)),
|
(Action == SampleUse && !PseudoProbeForProfiling)),
|
||||||
PseudoProbeForProfiling(PseudoProbeForProfiling), FS(std::move(FS)) {
|
PseudoProbeForProfiling(PseudoProbeForProfiling),
|
||||||
|
AtomicCounterUpdate(AtomicCounterUpdate), FS(std::move(FS)) {
|
||||||
// Note, we do allow ProfileFile.empty() for Action=IRUse LTO can
|
// Note, we do allow ProfileFile.empty() for Action=IRUse LTO can
|
||||||
// callback with IRUse action without ProfileFile.
|
// callback with IRUse action without ProfileFile.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user