summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Nemet <anemet@apple.com>2016-12-02 17:54:34 +0000
committerAdam Nemet <anemet@apple.com>2016-12-02 17:54:34 +0000
commitd0cab3401199d4d112c52969df80b84470e685f5 (patch)
tree41969b48a1bc76c3e14a2d91cb7fa22b2e47d246
parent0a6cca54cd6d0ff024be0186f420efdbee8d2902 (diff)
With LTO and profile-use, enable hotness info in opt remarks
This is to match the behavior of non-LTO; when -fsave-optimization-record is passed and PGO is available we enable the generation of hotness information in the optimization records. Differential Revision: https://reviews.llvm.org/D27332 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@288520 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Driver/Tools.cpp26
-rw-r--r--test/Driver/darwin-ld.c5
2 files changed, 24 insertions, 7 deletions
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 40e6dd8cc2..e3cb9622a9 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -3644,6 +3644,19 @@ VersionTuple visualstudio::getMSVCVersion(const Driver *D, const ToolChain &TC,
return VersionTuple();
}
+static Arg *getLastProfileUseArg(const ArgList &Args) {
+ auto *ProfileUseArg = Args.getLastArg(
+ options::OPT_fprofile_instr_use, options::OPT_fprofile_instr_use_EQ,
+ options::OPT_fprofile_use, options::OPT_fprofile_use_EQ,
+ options::OPT_fno_profile_instr_use);
+
+ if (ProfileUseArg &&
+ ProfileUseArg->getOption().matches(options::OPT_fno_profile_instr_use))
+ ProfileUseArg = nullptr;
+
+ return ProfileUseArg;
+}
+
static void addPGOAndCoverageFlags(Compilation &C, const Driver &D,
const InputInfo &Output, const ArgList &Args,
ArgStringList &CmdArgs) {
@@ -3668,13 +3681,7 @@ static void addPGOAndCoverageFlags(Compilation &C, const Driver &D,
D.Diag(diag::err_drv_argument_not_allowed_with)
<< PGOGenerateArg->getSpelling() << ProfileGenerateArg->getSpelling();
- auto *ProfileUseArg = Args.getLastArg(
- options::OPT_fprofile_instr_use, options::OPT_fprofile_instr_use_EQ,
- options::OPT_fprofile_use, options::OPT_fprofile_use_EQ,
- options::OPT_fno_profile_instr_use);
- if (ProfileUseArg &&
- ProfileUseArg->getOption().matches(options::OPT_fno_profile_instr_use))
- ProfileUseArg = nullptr;
+ auto *ProfileUseArg = getLastProfileUseArg(Args);
if (PGOGenerateArg && ProfileUseArg)
D.Diag(diag::err_drv_argument_not_allowed_with)
@@ -8436,6 +8443,11 @@ void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA,
F = Output.getFilename();
F += ".opt.yaml";
CmdArgs.push_back(Args.MakeArgString(F));
+
+ if (getLastProfileUseArg(Args)) {
+ CmdArgs.push_back("-mllvm");
+ CmdArgs.push_back("-lto-pass-remarks-with-hotness");
+ }
}
// It seems that the 'e' option is completely ignored for dynamic executables
diff --git a/test/Driver/darwin-ld.c b/test/Driver/darwin-ld.c
index 8bd86af6c5..36e7ee5355 100644
--- a/test/Driver/darwin-ld.c
+++ b/test/Driver/darwin-ld.c
@@ -332,7 +332,12 @@
// RUN: %clang -target x86_64-apple-darwin12 %t.o -fsave-optimization-record -### -o foo/bar.out 2> %t.log
// RUN: FileCheck -check-prefix=PASS_REMARKS_OUTPUT %s < %t.log
// PASS_REMARKS_OUTPUT: "-mllvm" "-lto-pass-remarks-output" "-mllvm" "foo/bar.out.opt.yaml"
+// PASS_REMARKS_OUTPUT-NOT: -lto-pass-remarks-with-hotness
// RUN: %clang -target x86_64-apple-darwin12 %t.o -fsave-optimization-record -### 2> %t.log
// RUN: FileCheck -check-prefix=PASS_REMARKS_OUTPUT_NO_O %s < %t.log
// PASS_REMARKS_OUTPUT_NO_O: "-mllvm" "-lto-pass-remarks-output" "-mllvm" "a.out.opt.yaml"
+
+// RUN: %clang -target x86_64-apple-darwin12 %t.o -fsave-optimization-record -fprofile-instr-use=blah -### -o foo/bar.out 2> %t.log
+// RUN: FileCheck -check-prefix=PASS_REMARKS_WITH_HOTNESS %s < %t.log
+// PASS_REMARKS_WITH_HOTNESS: "-mllvm" "-lto-pass-remarks-output" "-mllvm" "foo/bar.out.opt.yaml" "-mllvm" "-lto-pass-remarks-with-hotness"