@@ -245,6 +245,20 @@ performOptimizationsUsingLegacyPassManger(const IRGenOptions &Opts,
245
245
// Set up a pipeline.
246
246
PassManagerBuilderWrapper PMBuilder (Opts);
247
247
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
+
248
262
if (Opts.shouldOptimize () && !Opts.DisableLLVMOptzns ) {
249
263
PMBuilder.OptLevel = 2 ; // -Os
250
264
PMBuilder.SizeLevel = 1 ; // -Os
@@ -355,15 +369,6 @@ performOptimizationsUsingLegacyPassManger(const IRGenOptions &Opts,
355
369
ModulePasses.add (createTargetTransformInfoWrapperPass (
356
370
TargetMachine->getTargetIRAnalysis ()));
357
371
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
-
367
372
PMBuilder.populateModulePassManager (ModulePasses);
368
373
369
374
// The PMBuilder only knows about LLVM AA passes. We should explicitly add
0 commit comments