r262239 - [PGO] clang cc1 option change to enable IR level instrumentation
Rong Xu via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 29 10:54:59 PST 2016
Author: xur
Date: Mon Feb 29 12:54:59 2016
New Revision: 262239
URL: http://llvm.org/viewvc/llvm-project?rev=262239&view=rev
Log:
[PGO] clang cc1 option change to enable IR level instrumentation
This patch expands cc1 option -fprofile-instrument= with a new value: -fprofile-instrument=llvm
which enables IR level PGO instrumentation.
Reviewers: davidxl, silvas
Differential Revision: http://reviews.llvm.org/D17622
Added:
cfe/trunk/test/CodeGen/pgo-instrumentation.c
Modified:
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/include/clang/Frontend/CodeGenOptions.h
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=262239&r1=262238&r2=262239&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Mon Feb 29 12:54:59 2016
@@ -274,8 +274,8 @@ def fsanitize_coverage_trace_pc
: Flag<["-"], "fsanitize-coverage-trace-pc">,
HelpText<"Enable PC tracing in sanitizer coverage">;
def fprofile_instrument_EQ : Joined<["-"], "fprofile-instrument=">,
- HelpText<"Enable PGO instrumentation. The accepted values is clang or "
- "none">;
+ HelpText<"Enable PGO instrumentation. The accepted value is clang, llvm, "
+ "or none">;
def fprofile_instrument_path_EQ : Joined<["-"], "fprofile-instrument-path=">,
HelpText<"Generate instrumented code to collect execution counts into "
"<file> (overridden by LLVM_PROFILE_FILE env var)">;
Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=262239&r1=262238&r2=262239&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Mon Feb 29 12:54:59 2016
@@ -104,7 +104,7 @@ VALUE_CODEGENOPT(OptimizationLevel, 2, 0
VALUE_CODEGENOPT(OptimizeSize, 2, 0) ///< If -Os (==1) or -Oz (==2) is specified.
/// \brief Choose profile instrumenation kind or no instrumentation.
-ENUM_CODEGENOPT(ProfileInstr, ProfileInstrKind, 2, ProfileNoInstr)
+ENUM_CODEGENOPT(ProfileInstr, ProfileInstrKind, 2, ProfileNone)
CODEGENOPT(CoverageMapping , 1, 0) ///< Generate coverage mapping regions to
///< enable code coverage analysis.
CODEGENOPT(DumpCoverageMapping , 1, 0) ///< Dump the generated coverage mapping
Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.h?rev=262239&r1=262238&r2=262239&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.h Mon Feb 29 12:54:59 2016
@@ -80,9 +80,10 @@ public:
};
enum ProfileInstrKind {
- ProfileNoInstr, // No instrumentation.
- ProfileClangInstr // Clang instrumentation to generate execution counts
+ ProfileNone, // Profile instrumentation is turned off.
+ ProfileClangInstr, // Clang instrumentation to generate execution counts
// to use with PGO.
+ ProfileIRInstr, // IR level PGO instrumentation in LLVM.
};
/// The code model to use (-mcmodel).
@@ -226,6 +227,11 @@ public:
bool hasProfileClangInstr() const {
return getProfileInstr() == ProfileClangInstr;
}
+
+ /// \brief Check if IR level profile instrumentation is on.
+ bool hasProfileIRInstr() const {
+ return getProfileInstr() == ProfileIRInstr;
+ }
};
} // end namespace clang
Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=262239&r1=262238&r2=262239&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Mon Feb 29 12:54:59 2016
@@ -437,6 +437,12 @@ void EmitAssemblyHelper::CreatePasses(Fu
Options.InstrProfileOutput = CodeGenOpts.InstrProfileOutput;
MPM->add(createInstrProfilingPass(Options));
}
+ if (CodeGenOpts.hasProfileIRInstr()) {
+ if (!CodeGenOpts.InstrProfileOutput.empty())
+ PMBuilder.PGOInstrGen = CodeGenOpts.InstrProfileOutput;
+ else
+ PMBuilder.PGOInstrGen = "default.profraw";
+ }
if (!CodeGenOpts.SampleProfileFile.empty())
MPM->add(createSampleProfileLoaderPass(CodeGenOpts.SampleProfileFile));
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=262239&r1=262238&r2=262239&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Mon Feb 29 12:54:59 2016
@@ -481,18 +481,23 @@ static bool ParseCodeGenArgs(CodeGenOpti
Opts.Autolink = !Args.hasArg(OPT_fno_autolink);
Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ);
- enum PGOInstrumentor { Unknown, None, Clang };
+ enum PGOInstrumentor { Unknown, None, Clang, LLVM };
if (Arg *A = Args.getLastArg(OPT_fprofile_instrument_EQ)) {
StringRef Value = A->getValue();
PGOInstrumentor Method = llvm::StringSwitch<PGOInstrumentor>(Value)
- .Case("clang", Clang)
.Case("none", None)
+ .Case("clang", Clang)
+ .Case("llvm", LLVM)
.Default(Unknown);
switch (Method) {
+ case LLVM:
+ Opts.setProfileInstr(CodeGenOptions::ProfileIRInstr);
+ break;
case Clang:
Opts.setProfileInstr(CodeGenOptions::ProfileClangInstr);
break;
case None:
+ // Null operation -- The default is ProfileNone.
break;
case Unknown:
Diags.Report(diag::err_drv_invalid_pgo_instrumentor)
Added: cfe/trunk/test/CodeGen/pgo-instrumentation.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/pgo-instrumentation.c?rev=262239&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/pgo-instrumentation.c (added)
+++ cfe/trunk/test/CodeGen/pgo-instrumentation.c Mon Feb 29 12:54:59 2016
@@ -0,0 +1,9 @@
+// Test if PGO instrumentation and use pass are 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
+// CHECK-PGOGENPASS-INVOKED-INSTR-GEN: PGOInstrumentationGenPass
+//
+// 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
+// CHECK-PGOGENPASS-INVOKED-INSTR-GEN-CLANG-NOT: PGOInstrumentationGenPass
More information about the cfe-commits
mailing list