|
@@ -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;
|
|
|
+}
|