diff options
| author | Rong Xu <xur@google.com> | 2016-03-02 20:59:36 +0000 |
|---|---|---|
| committer | Rong Xu <xur@google.com> | 2016-03-02 20:59:36 +0000 |
| commit | 9c6f1538cc0f70fe43d47cf818ad797c82b61d5f (patch) | |
| tree | b86604baa3284b38067401726b173344be8ceb75 /clang/lib | |
| parent | 783fb1f6426f32e5bb7731d57cd517a90fa7bccd (diff) | |
| download | bcm5719-llvm-9c6f1538cc0f70fe43d47cf818ad797c82b61d5f.tar.gz bcm5719-llvm-9c6f1538cc0f70fe43d47cf818ad797c82b61d5f.zip | |
[PGO] Change profile use cc1 option to handle IR level profiles
This patch changes cc1 option for PGO profile use from
-fprofile-instr-use=<path> to -fprofile-instrument-use-path=<path>.
-fprofile-instr-use=<path> is now a driver only option.
In addition to decouple the cc1 option from the driver level option, this patch
also enables IR level profile use. cc1 option handling now reads the profile
header and sets CodeGenOpt ProfileUse (valid values are {None, Clang, LLVM}
-- this is a common enum for -fprofile-instrument={}, for the profile
instrumentation), and invoke the pipeline to enable the respective PGO use pass.
Reviewers: silvas, davidxl
Differential Revision: http://reviews.llvm.org/D17737
llvm-svn: 262515
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/CodeGen/BackendUtil.cpp | 2 | ||||
| -rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 8 | ||||
| -rw-r--r-- | clang/lib/Driver/Tools.cpp | 5 | ||||
| -rw-r--r-- | clang/lib/Frontend/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 73 |
5 files changed, 57 insertions, 32 deletions
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 8af9c30dca7..6c957cdd355 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -443,6 +443,8 @@ void EmitAssemblyHelper::CreatePasses(FunctionInfoIndex *FunctionIndex) { else PMBuilder.PGOInstrGen = "default.profraw"; } + if (CodeGenOpts.hasProfileIRUse()) + PMBuilder.PGOInstrUse = CodeGenOpts.ProfileInstrumentUsePath; if (!CodeGenOpts.SampleProfileFile.empty()) MPM->add(createSampleProfileLoaderPass(CodeGenOpts.SampleProfileFile)); diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index cf9e29d46b7..7df90346571 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -149,13 +149,13 @@ CodeGenModule::CodeGenModule(ASTContext &C, const HeaderSearchOptions &HSO, if (C.getLangOpts().ObjC1) ObjCData = new ObjCEntrypoints(); - if (!CodeGenOpts.InstrProfileInput.empty()) { - auto ReaderOrErr = - llvm::IndexedInstrProfReader::create(CodeGenOpts.InstrProfileInput); + if (CodeGenOpts.hasProfileClangUse()) { + auto ReaderOrErr = llvm::IndexedInstrProfReader::create( + CodeGenOpts.ProfileInstrumentUsePath); if (std::error_code EC = ReaderOrErr.getError()) { unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, "Could not read profile %0: %1"); - getDiags().Report(DiagID) << CodeGenOpts.InstrProfileInput + getDiags().Report(DiagID) << CodeGenOpts.ProfileInstrumentUsePath << EC.message(); } else PGOReader = std::move(ReaderOrErr.get()); diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 0f5c700ce61..6e97183da1c 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -3301,7 +3301,8 @@ static void addPGOAndCoverageFlags(Compilation &C, const Driver &D, if (ProfileUseArg) { if (ProfileUseArg->getOption().matches(options::OPT_fprofile_instr_use_EQ)) - ProfileUseArg->render(Args, CmdArgs); + CmdArgs.push_back(Args.MakeArgString( + Twine("-fprofile-instrument-use-path=") + ProfileUseArg->getValue())); else if ((ProfileUseArg->getOption().matches( options::OPT_fprofile_use_EQ) || ProfileUseArg->getOption().matches( @@ -3311,7 +3312,7 @@ static void addPGOAndCoverageFlags(Compilation &C, const Driver &D, if (Path.empty() || llvm::sys::fs::is_directory(Path)) llvm::sys::path::append(Path, "default.profdata"); CmdArgs.push_back( - Args.MakeArgString(Twine("-fprofile-instr-use=") + Path)); + Args.MakeArgString(Twine("-fprofile-instrument-use-path=") + Path)); } } diff --git a/clang/lib/Frontend/CMakeLists.txt b/clang/lib/Frontend/CMakeLists.txt index 47681204624..5c19cea028b 100644 --- a/clang/lib/Frontend/CMakeLists.txt +++ b/clang/lib/Frontend/CMakeLists.txt @@ -3,6 +3,7 @@ add_subdirectory(Rewrite) set(LLVM_LINK_COMPONENTS BitReader Option + ProfileData Support ) diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 9bb33e7a766..bf845b299f2 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -33,6 +33,7 @@ #include "llvm/Option/ArgList.h" #include "llvm/Option/OptTable.h" #include "llvm/Option/Option.h" +#include "llvm/ProfileData/InstrProfReader.h" #include "llvm/Support/CodeGen.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" @@ -375,6 +376,45 @@ static void parseSanitizerKinds(StringRef FlagName, } } +// Set the profile kind for fprofile-instrument. +static void setPGOInstrumentor(CodeGenOptions &Opts, ArgList &Args, + DiagnosticsEngine &Diags) { + Arg *A = Args.getLastArg(OPT_fprofile_instrument_EQ); + if (A == nullptr) + return; + StringRef S = A->getValue(); + unsigned I = llvm::StringSwitch<unsigned>(S) + .Case("none", CodeGenOptions::ProfileNone) + .Case("clang", CodeGenOptions::ProfileClangInstr) + .Case("llvm", CodeGenOptions::ProfileIRInstr) + .Default(~0U); + if (I == ~0U) { + Diags.Report(diag::err_drv_invalid_pgo_instrumentor) << A->getAsString(Args) + << S; + return; + } + CodeGenOptions::ProfileInstrKind Instrumentor = + static_cast<CodeGenOptions::ProfileInstrKind>(I); + Opts.setProfileInstr(Instrumentor); +} + +// Set the profile kind using fprofile-instrument-use-path. +static void setPGOUseInstrumentor(CodeGenOptions &Opts, + const std::string ProfileName) { + auto ReaderOrErr = llvm::IndexedInstrProfReader::create(ProfileName); + // In error, return silently and let Clang PGOUse report the error message. + if (ReaderOrErr.getError()) { + Opts.setProfileUse(CodeGenOptions::ProfileClangInstr); + return; + } + std::unique_ptr<llvm::IndexedInstrProfReader> PGOReader = + std::move(ReaderOrErr.get()); + if (PGOReader->isIRLevelProfile()) + Opts.setProfileUse(CodeGenOptions::ProfileIRInstr); + else + Opts.setProfileUse(CodeGenOptions::ProfileClangInstr); +} + static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, DiagnosticsEngine &Diags, const TargetOptions &TargetOpts) { @@ -481,33 +521,14 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Opts.Autolink = !Args.hasArg(OPT_fno_autolink); Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ); - 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("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) - << A->getAsString(Args) << Value; - break; - } - } + setPGOInstrumentor(Opts, Args, Diags); + Opts.InstrProfileOutput = + Args.getLastArgValue(OPT_fprofile_instrument_path_EQ); + Opts.ProfileInstrumentUsePath = + Args.getLastArgValue(OPT_fprofile_instrument_use_path_EQ); + if (!Opts.ProfileInstrumentUsePath.empty()) + setPGOUseInstrumentor(Opts, Opts.ProfileInstrumentUsePath); - Opts.InstrProfileOutput = Args.getLastArgValue(OPT_fprofile_instrument_path_EQ); - Opts.InstrProfileInput = Args.getLastArgValue(OPT_fprofile_instr_use_EQ); Opts.CoverageMapping = Args.hasFlag(OPT_fcoverage_mapping, OPT_fno_coverage_mapping, false); Opts.DumpCoverageMapping = Args.hasArg(OPT_dump_coverage_mapping); |

