diff options
author | Florian Hahn <florian.hahn@arm.com> | 2018-04-20 12:50:10 +0000 |
---|---|---|
committer | Florian Hahn <florian.hahn@arm.com> | 2018-04-20 12:50:10 +0000 |
commit | 2e081d1cba97bdf7d3fb1890e0f66d6b0775d338 (patch) | |
tree | 459a0b2267f248059e71b2bfab8fe14ef9a503ad /clang/lib/Driver/ToolChains/CommonArgs.cpp | |
parent | 5c709eda073c78b81d9bbb5d24e5412409031bd5 (diff) | |
download | bcm5719-llvm-2e081d1cba97bdf7d3fb1890e0f66d6b0775d338.tar.gz bcm5719-llvm-2e081d1cba97bdf7d3fb1890e0f66d6b0775d338.zip |
[Driver] Support for -save-stats in AddGoldPlugin.
This patch updates AddGoldPlugin to pass stats-file to the Gold plugin,
if -save-stats is passed. It also moves the save-stats option handling
to a helper function tools::getStatsFileName.
Reviewers: tejohnson, mehdi_amini, compnerd
Reviewed By: tejohnson, compnerd
Differential Revision: https://reviews.llvm.org/D45771
llvm-svn: 330422
Diffstat (limited to 'clang/lib/Driver/ToolChains/CommonArgs.cpp')
-rw-r--r-- | clang/lib/Driver/ToolChains/CommonArgs.cpp | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 1527238c663..c2583dd6fbf 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -8,14 +8,14 @@ //===----------------------------------------------------------------------===// #include "CommonArgs.h" -#include "InputInfo.h" -#include "Hexagon.h" #include "Arch/AArch64.h" #include "Arch/ARM.h" #include "Arch/Mips.h" #include "Arch/PPC.h" #include "Arch/SystemZ.h" #include "Arch/X86.h" +#include "Hexagon.h" +#include "InputInfo.h" #include "clang/Basic/CharInfo.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/ObjCRuntime.h" @@ -42,6 +42,7 @@ #include "llvm/Option/Option.h" #include "llvm/Support/CodeGen.h" #include "llvm/Support/Compression.h" +#include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Host.h" @@ -370,8 +371,8 @@ bool tools::isUseSeparateSections(const llvm::Triple &Triple) { } void tools::AddGoldPlugin(const ToolChain &ToolChain, const ArgList &Args, - ArgStringList &CmdArgs, bool IsThinLTO, - const Driver &D) { + ArgStringList &CmdArgs, const InputInfo &Output, + const InputInfo &Input, bool IsThinLTO) { // Tell the linker to load the plugin. This has to come before AddLinkerInputs // as gold requires -plugin to come before any -plugin-opt that -Wl might // forward. @@ -416,7 +417,7 @@ void tools::AddGoldPlugin(const ToolChain &ToolChain, const ArgList &Args, if (IsThinLTO) CmdArgs.push_back("-plugin-opt=thinlto"); - if (unsigned Parallelism = getLTOParallelism(Args, D)) + if (unsigned Parallelism = getLTOParallelism(Args, ToolChain.getDriver())) CmdArgs.push_back( Args.MakeArgString("-plugin-opt=jobs=" + Twine(Parallelism))); @@ -447,7 +448,7 @@ void tools::AddGoldPlugin(const ToolChain &ToolChain, const ArgList &Args, if (Arg *A = getLastProfileSampleUseArg(Args)) { StringRef FName = A->getValue(); if (!llvm::sys::fs::exists(FName)) - D.Diag(diag::err_drv_no_such_file) << FName; + ToolChain.getDriver().Diag(diag::err_drv_no_such_file) << FName; else CmdArgs.push_back( Args.MakeArgString(Twine("-plugin-opt=sample-profile=") + FName)); @@ -460,6 +461,12 @@ void tools::AddGoldPlugin(const ToolChain &ToolChain, const ArgList &Args, CmdArgs.push_back("-plugin-opt=new-pass-manager"); } + // Setup statistics file output. + SmallString<128> StatsFile = + getStatsFileName(Args, Output, Input, ToolChain.getDriver()); + if (!StatsFile.empty()) + CmdArgs.push_back( + Args.MakeArgString(Twine("-plugin-opt=stats-file=") + StatsFile)); } void tools::addArchSpecificRPath(const ToolChain &TC, const ArgList &Args, @@ -1267,3 +1274,27 @@ void tools::AddOpenMPLinkerScript(const ToolChain &TC, Compilation &C, Lksf << LksBuffer; } + +SmallString<128> tools::getStatsFileName(const llvm::opt::ArgList &Args, + const InputInfo &Output, + const InputInfo &Input, + const Driver &D) { + const Arg *A = Args.getLastArg(options::OPT_save_stats_EQ); + if (!A) + return {}; + + StringRef SaveStats = A->getValue(); + SmallString<128> StatsFile; + if (SaveStats == "obj" && Output.isFilename()) { + StatsFile.assign(Output.getFilename()); + llvm::sys::path::remove_filename(StatsFile); + } else if (SaveStats != "cwd") { + D.Diag(diag::err_drv_invalid_value) << A->getAsString(Args) << SaveStats; + return {}; + } + + StringRef BaseName = llvm::sys::path::filename(Input.getBaseInput()); + llvm::sys::path::append(StatsFile, BaseName); + llvm::sys::path::replace_extension(StatsFile, "stats"); + return StatsFile; +} |