Skip to content

Commit 9bbf74e

Browse files
aschwaighoferhamishknight
authored andcommitted
Run instruction profiling pass at the start of the pipeline
rdar://77217762
1 parent 149e57a commit 9bbf74e

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

lib/IRGen/IRGen.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,20 @@ performOptimizationsUsingLegacyPassManger(const IRGenOptions &Opts,
245245
// Set up a pipeline.
246246
PassManagerBuilderWrapper PMBuilder(Opts);
247247

248+
// If we're generating a profile, add the lowering pass now.
249+
if (Opts.GenerateProfile) {
250+
// TODO: Surface the option to emit atomic profile counter increments at
251+
// the driver level.
252+
// Configure the module passes.
253+
legacy::PassManager ModulePasses;
254+
ModulePasses.add(createTargetTransformInfoWrapperPass(
255+
TargetMachine->getTargetIRAnalysis()));
256+
InstrProfOptions Options;
257+
Options.Atomic = bool(Opts.Sanitizers & SanitizerKind::Thread);
258+
ModulePasses.add(createInstrProfilingLegacyPass(Options));
259+
ModulePasses.run(*Module);
260+
}
261+
248262
if (Opts.shouldOptimize() && !Opts.DisableLLVMOptzns) {
249263
PMBuilder.OptLevel = 2; // -Os
250264
PMBuilder.SizeLevel = 1; // -Os
@@ -355,15 +369,6 @@ performOptimizationsUsingLegacyPassManger(const IRGenOptions &Opts,
355369
ModulePasses.add(createTargetTransformInfoWrapperPass(
356370
TargetMachine->getTargetIRAnalysis()));
357371

358-
// If we're generating a profile, add the lowering pass now.
359-
if (Opts.GenerateProfile) {
360-
// TODO: Surface the option to emit atomic profile counter increments at
361-
// the driver level.
362-
InstrProfOptions Options;
363-
Options.Atomic = bool(Opts.Sanitizers & SanitizerKind::Thread);
364-
ModulePasses.add(createInstrProfilingLegacyPass(Options));
365-
}
366-
367372
PMBuilder.populateModulePassManager(ModulePasses);
368373

369374
// The PMBuilder only knows about LLVM AA passes. We should explicitly add

0 commit comments

Comments
 (0)