forked from OSchip/llvm-project
[PGO] Enable InstrProf lowering for Clang PGO instrumentation in the new pass manager
Currently InstrProf lowering is not enabled for Clang PGO instrumentation in the new pass manager. The following command "-fprofile-instr-generate -fexperimental-new-pass-manager ..." is broken. This CL enables InstrProf lowering pass for Clang PGO instrumentation in the new pass manager. Differential Revision: https://reviews.llvm.org/D61138 llvm-svn: 359215
This commit is contained in:
parent
e3559eee63
commit
4059e143dc
|
@ -57,6 +57,7 @@
|
||||||
#include "llvm/Transforms/Instrumentation/AddressSanitizer.h"
|
#include "llvm/Transforms/Instrumentation/AddressSanitizer.h"
|
||||||
#include "llvm/Transforms/Instrumentation/BoundsChecking.h"
|
#include "llvm/Transforms/Instrumentation/BoundsChecking.h"
|
||||||
#include "llvm/Transforms/Instrumentation/GCOVProfiler.h"
|
#include "llvm/Transforms/Instrumentation/GCOVProfiler.h"
|
||||||
|
#include "llvm/Transforms/Instrumentation/InstrProfiling.h"
|
||||||
#include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
|
#include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
|
||||||
#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
|
#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
|
||||||
#include "llvm/Transforms/ObjCARC.h"
|
#include "llvm/Transforms/ObjCARC.h"
|
||||||
|
@ -505,6 +506,21 @@ static Optional<GCOVOptions> getGCOVOptions(const CodeGenOptions &CodeGenOpts) {
|
||||||
return Options;
|
return Options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Optional<InstrProfOptions>
|
||||||
|
getInstrProfOptions(const CodeGenOptions &CodeGenOpts,
|
||||||
|
const LangOptions &LangOpts) {
|
||||||
|
if (!CodeGenOpts.hasProfileClangInstr())
|
||||||
|
return None;
|
||||||
|
InstrProfOptions Options;
|
||||||
|
Options.NoRedZone = CodeGenOpts.DisableRedZone;
|
||||||
|
Options.InstrProfileOutput = CodeGenOpts.InstrProfileOutput;
|
||||||
|
|
||||||
|
// TODO: Surface the option to emit atomic profile counter increments at
|
||||||
|
// the driver level.
|
||||||
|
Options.Atomic = LangOpts.Sanitize.has(SanitizerKind::Thread);
|
||||||
|
return Options;
|
||||||
|
}
|
||||||
|
|
||||||
void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM,
|
void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM,
|
||||||
legacy::FunctionPassManager &FPM) {
|
legacy::FunctionPassManager &FPM) {
|
||||||
// Handle disabling of all LLVM passes, where we want to preserve the
|
// Handle disabling of all LLVM passes, where we want to preserve the
|
||||||
|
@ -659,17 +675,10 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM,
|
||||||
MPM.add(createStripSymbolsPass(true));
|
MPM.add(createStripSymbolsPass(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CodeGenOpts.hasProfileClangInstr()) {
|
if (Optional<InstrProfOptions> Options =
|
||||||
InstrProfOptions Options;
|
getInstrProfOptions(CodeGenOpts, LangOpts))
|
||||||
Options.NoRedZone = CodeGenOpts.DisableRedZone;
|
MPM.add(createInstrProfilingLegacyPass(*Options, false));
|
||||||
Options.InstrProfileOutput = CodeGenOpts.InstrProfileOutput;
|
|
||||||
|
|
||||||
// TODO: Surface the option to emit atomic profile counter increments at
|
|
||||||
// the driver level.
|
|
||||||
Options.Atomic = LangOpts.Sanitize.has(SanitizerKind::Thread);
|
|
||||||
|
|
||||||
MPM.add(createInstrProfilingLegacyPass(Options, false));
|
|
||||||
}
|
|
||||||
bool hasIRInstr = false;
|
bool hasIRInstr = false;
|
||||||
if (CodeGenOpts.hasProfileIRInstr()) {
|
if (CodeGenOpts.hasProfileIRInstr()) {
|
||||||
PMBuilder.EnablePGOInstrGen = true;
|
PMBuilder.EnablePGOInstrGen = true;
|
||||||
|
@ -1056,6 +1065,9 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
|
||||||
if (CodeGenOpts.OptimizationLevel == 0) {
|
if (CodeGenOpts.OptimizationLevel == 0) {
|
||||||
if (Optional<GCOVOptions> Options = getGCOVOptions(CodeGenOpts))
|
if (Optional<GCOVOptions> Options = getGCOVOptions(CodeGenOpts))
|
||||||
MPM.addPass(GCOVProfilerPass(*Options));
|
MPM.addPass(GCOVProfilerPass(*Options));
|
||||||
|
if (Optional<InstrProfOptions> Options =
|
||||||
|
getInstrProfOptions(CodeGenOpts, LangOpts))
|
||||||
|
MPM.addPass(InstrProfiling(*Options, false));
|
||||||
|
|
||||||
// Build a minimal pipeline based on the semantics required by Clang,
|
// Build a minimal pipeline based on the semantics required by Clang,
|
||||||
// which is just that always inlining occurs.
|
// which is just that always inlining occurs.
|
||||||
|
@ -1120,6 +1132,11 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
|
||||||
PB.registerPipelineStartEPCallback([Options](ModulePassManager &MPM) {
|
PB.registerPipelineStartEPCallback([Options](ModulePassManager &MPM) {
|
||||||
MPM.addPass(GCOVProfilerPass(*Options));
|
MPM.addPass(GCOVProfilerPass(*Options));
|
||||||
});
|
});
|
||||||
|
if (Optional<InstrProfOptions> Options =
|
||||||
|
getInstrProfOptions(CodeGenOpts, LangOpts))
|
||||||
|
PB.registerPipelineStartEPCallback([Options](ModulePassManager &MPM) {
|
||||||
|
MPM.addPass(InstrProfiling(*Options, false));
|
||||||
|
});
|
||||||
|
|
||||||
if (IsThinLTO) {
|
if (IsThinLTO) {
|
||||||
MPM = PB.buildThinLTOPreLinkDefaultPipeline(
|
MPM = PB.buildThinLTOPreLinkDefaultPipeline(
|
||||||
|
|
|
@ -1,20 +1,36 @@
|
||||||
// Test if PGO instrumentation and use pass are invoked.
|
// Test if PGO instrumentation and use pass are invoked.
|
||||||
//
|
//
|
||||||
// Ensure Pass PGOInstrumentationGenPass is invoked.
|
// Ensure Pass PGOInstrumentationGenPass is invoked.
|
||||||
// RUN: %clang_cc1 -O2 -fprofile-instrument=llvm %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=CHECK-PGOGENPASS-INVOKED-INSTR-GEN
|
// RUN: %clang_cc1 -O2 -fprofile-instrument=llvm %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=CHECK-PGOGENPASS-INVOKED-INSTR-GEN --check-prefix=CHECK-INSTRPROF
|
||||||
|
// RUN: %clang_cc1 -O2 -fprofile-instrument=llvm %s -fexperimental-new-pass-manager -fdebug-pass-manager -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=CHECK-PGOGENPASS-INVOKED-INSTR-GEN-NEWPM --check-prefix=CHECK-INSTRPROF-NEWPM
|
||||||
// CHECK-PGOGENPASS-INVOKED-INSTR-GEN: PGOInstrumentationGenPass
|
// CHECK-PGOGENPASS-INVOKED-INSTR-GEN: PGOInstrumentationGenPass
|
||||||
|
// CHECK-INSTRPROF: Frontend instrumentation-based coverage lowering
|
||||||
|
// CHECK-PGOGENPASS-INVOKED-INSTR-GEN-NEWPM: Running pass: PGOInstrumentationGen on
|
||||||
|
// CHECK-INSTRPROF-NEWPM: Running pass: InstrProfiling on
|
||||||
//
|
//
|
||||||
// Ensure Pass PGOInstrumentationGenPass is not invoked.
|
// Ensure Pass PGOInstrumentationGenPass is not invoked.
|
||||||
// RUN: %clang_cc1 -O2 -fprofile-instrument=clang %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=CHECK-PGOGENPASS-INVOKED-INSTR-GEN-CLANG
|
// RUN: %clang_cc1 -O2 -fprofile-instrument=clang %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=CHECK-PGOGENPASS-INVOKED-INSTR-GEN-CLANG
|
||||||
|
// RUN: %clang_cc1 -O2 -fprofile-instrument=clang %s -fexperimental-new-pass-manager -fdebug-pass-manager -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=CHECK-PGOGENPASS-INVOKED-INSTR-GEN-CLANG-NEWPM
|
||||||
// CHECK-PGOGENPASS-INVOKED-INSTR-GEN-CLANG-NOT: PGOInstrumentationGenPass
|
// CHECK-PGOGENPASS-INVOKED-INSTR-GEN-CLANG-NOT: PGOInstrumentationGenPass
|
||||||
|
// CHECK-PGOGENPASS-INVOKED-INSTR-GEN-CLANG-NEWPM-NOT: Running pass: PGOInstrumentationGen on
|
||||||
|
|
||||||
|
// RUN: %clang_cc1 -O2 -fprofile-instrument=clang %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-CLANG-INSTRPROF
|
||||||
|
// RUN: %clang_cc1 -O2 -fprofile-instrument=clang %s -fexperimental-new-pass-manager -fdebug-pass-manager -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-CLANG-INSTRPROF-NEWPM
|
||||||
|
// RUN: %clang_cc1 -O0 -fprofile-instrument=clang %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-CLANG-INSTRPROF
|
||||||
|
// RUN: %clang_cc1 -O0 -fprofile-instrument=clang %s -fexperimental-new-pass-manager -fdebug-pass-manager -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-CLANG-INSTRPROF-NEWPM
|
||||||
|
// CHECK-CLANG-INSTRPROF: Frontend instrumentation-based coverage lowering
|
||||||
|
// CHECK-CLANG-INSTRPROF-NEWPM: Running pass: InstrProfiling on
|
||||||
|
|
||||||
// Ensure Pass PGOInstrumentationUsePass is invoked.
|
// Ensure Pass PGOInstrumentationUsePass is invoked.
|
||||||
// RUN: llvm-profdata merge -o %t.profdata %S/Inputs/pgotestir.profraw
|
// RUN: llvm-profdata merge -o %t.profdata %S/Inputs/pgotestir.profraw
|
||||||
// RUN: %clang_cc1 -O2 -fprofile-instrument-use-path=%t.profdata %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=CHECK-PGOUSEPASS-INVOKED-INSTR-USE
|
// RUN: %clang_cc1 -O2 -fprofile-instrument-use-path=%t.profdata %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=CHECK-PGOUSEPASS-INVOKED-INSTR-USE
|
||||||
|
// RUN: %clang_cc1 -O2 -fprofile-instrument-use-path=%t.profdata %s -fexperimental-new-pass-manager -fdebug-pass-manager -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=CHECK-PGOUSEPASS-INVOKED-INSTR-USE-NEWPM
|
||||||
// CHECK-PGOUSEPASS-INVOKED-INSTR-USE: PGOInstrumentationUsePass
|
// CHECK-PGOUSEPASS-INVOKED-INSTR-USE: PGOInstrumentationUsePass
|
||||||
|
// CHECK-PGOUSEPASS-INVOKED-INSTR-USE-NEWPM: Running pass: PGOInstrumentationUse on
|
||||||
//
|
//
|
||||||
// Ensure Pass PGOInstrumentationUsePass is not invoked.
|
// Ensure Pass PGOInstrumentationUsePass is not invoked.
|
||||||
// RUN: llvm-profdata merge -o %t.profdata %S/Inputs/pgotestclang.profraw
|
// RUN: llvm-profdata merge -o %t.profdata %S/Inputs/pgotestclang.profraw
|
||||||
// RUN: %clang_cc1 -O2 -fprofile-instrument-use-path=%t.profdata %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=CHECK-PGOUSEPASS-INVOKED-USE-CLANG
|
// RUN: %clang_cc1 -O2 -fprofile-instrument-use-path=%t.profdata %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=CHECK-PGOUSEPASS-INVOKED-USE-CLANG
|
||||||
|
// RUN: %clang_cc1 -O2 -fprofile-instrument-use-path=%t.profdata %s -fexperimental-new-pass-manager -fdebug-pass-manager -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=CHECK-PGOUSEPASS-INVOKED-USE-CLANG-NEWPM
|
||||||
// CHECK-PGOUSEPASS-INVOKED-USE-CLANG-NOT: PGOInstrumentationUsePass
|
// CHECK-PGOUSEPASS-INVOKED-USE-CLANG-NOT: PGOInstrumentationUsePass
|
||||||
|
// CHECK-PGOUSEPASS-INVOKED-USE-CLANG-NEWPM-NOT: Running pass: PGOInstrumentationUse on
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
// Test instrumentation of general constructs in C.
|
// Test instrumentation of general constructs in C.
|
||||||
|
|
||||||
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument=clang | FileCheck -allow-deprecated-dag-overlap -check-prefix=PGOGEN %s
|
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument=clang | FileCheck -allow-deprecated-dag-overlap -check-prefix=PGOGEN %s
|
||||||
|
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument=clang -fexperimental-new-pass-manager | FileCheck -allow-deprecated-dag-overlap -check-prefix=PGOGEN %s
|
||||||
|
|
||||||
// RUN: llvm-profdata merge %S/Inputs/c-general.proftext -o %t.profdata
|
// RUN: llvm-profdata merge %S/Inputs/c-general.proftext -o %t.profdata
|
||||||
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata | FileCheck -allow-deprecated-dag-overlap -check-prefix=PGOUSE %s
|
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata | FileCheck -allow-deprecated-dag-overlap -check-prefix=PGOUSE %s
|
||||||
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%S/Inputs/c-general.profdata.v3 | FileCheck -allow-deprecated-dag-overlap -check-prefix=PGOUSE %s
|
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%S/Inputs/c-general.profdata.v3 | FileCheck -allow-deprecated-dag-overlap -check-prefix=PGOUSE %s
|
||||||
|
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%S/Inputs/c-general.profdata.v3 -fexperimental-new-pass-manager | FileCheck -allow-deprecated-dag-overlap -check-prefix=PGOUSE %s
|
||||||
// Also check compatibility with older profiles.
|
// Also check compatibility with older profiles.
|
||||||
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%S/Inputs/c-general.profdata.v1 | FileCheck -allow-deprecated-dag-overlap -check-prefix=PGOUSE %s
|
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%S/Inputs/c-general.profdata.v1 | FileCheck -allow-deprecated-dag-overlap -check-prefix=PGOUSE %s
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue