[clang] 07b8f8e - [Remarks][Driver] Place temporary remark files next to temporary object files
Francis Visoiu Mistrih via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 18 16:43:52 PST 2019
Author: Francis Visoiu Mistrih
Date: 2019-12-18T16:42:02-08:00
New Revision: 07b8f8e5f5cad9c4d92c39a4bea50e21e9f0e9f1
URL: https://github.com/llvm/llvm-project/commit/07b8f8e5f5cad9c4d92c39a4bea50e21e9f0e9f1
DIFF: https://github.com/llvm/llvm-project/commit/07b8f8e5f5cad9c4d92c39a4bea50e21e9f0e9f1.diff
LOG: [Remarks][Driver] Place temporary remark files next to temporary object files
On Darwin, when used for generating a linked binary from a source file
(through an intermediate object file), the driver will invoke `cc1` to
generate a temporary object file. The temporary remark file will now be
emitted next to the object file, which will then be picked up by
`dsymutil` and emitted in the .dSYM bundle.
This is available for all formats except YAML since by default, YAML
doesn't need a section and the remark file will be lost.
Added:
Modified:
clang/docs/UsersManual.rst
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/darwin-opt-record.c
Removed:
################################################################################
diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 307507388ff6..07201f0d8616 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -355,21 +355,14 @@ output format of the diagnostics that it generates.
where ``<base>`` is based on the output file of the compilation (whether
it's explicitly specified through `-o` or not) when used with `-c` or `-S`.
- In other cases, it's based on the input file's stem. For example:
+ For example:
* ``clang -fsave-optimization-record -c in.c -o out.o`` will generate
``out.opt.yaml``
- * ``clang -fsave-optimization-record in.c -o out`` will generate
+ * ``clang -fsave-optimization-record -c in.c `` will generate
``in.opt.yaml``
- Compiling for multiple architectures will use the following scheme:
-
- ``<base>-<arch>.opt.<format>``
-
- Note that this is only allowed on Darwin platforms and is incompatible with
- passing multiple ``-arch <arch>`` options.
-
When targeting (Thin)LTO, the base is derived from the output filename, and
the extension is not dropped.
@@ -377,6 +370,32 @@ output format of the diagnostics that it generates.
``<base>.opt.<format>.thin.<num>.<format>``
+ Darwin-only: when used for generating a linked binary from a source file
+ (through an intermediate object file), the driver will invoke `cc1` to
+ generate a temporary object file. The temporary remark file will be emitted
+ next to the object file, which will then be picked up by `dsymutil` and
+ emitted in the .dSYM bundle. This is available for all formats except YAML.
+
+ For example:
+
+ ``clang -fsave-optimization-record=bitstream in.c -o out`` will generate
+
+ * ``/var/folders/43/9y164hh52tv_2nrdxrj31nyw0000gn/T/a-9be59b.o``
+
+ * ``/var/folders/43/9y164hh52tv_2nrdxrj31nyw0000gn/T/a-9be59b.opt.bitstream``
+
+ * ``out``
+
+ * ``out.dSYM/Contents/Resources/Remarks/out``
+
+ Darwin-only: compiling for multiple architectures will use the following
+ scheme:
+
+ ``<base>-<arch>.opt.<format>``
+
+ Note that this is incompatible with passing the
+ :ref:`-foptimization-record-file <opt_foptimization-record-file>` option.
+
.. _opt_foptimization-record-file:
**-foptimization-record-file**
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 9840acafd6ea..5c7572fb12be 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1444,7 +1444,12 @@ static bool checkRemarksOptions(const Driver &D, const ArgList &Args,
static void renderRemarksOptions(const ArgList &Args, ArgStringList &CmdArgs,
const llvm::Triple &Triple,
- const InputInfo &Input, const JobAction &JA) {
+ const InputInfo &Input,
+ const InputInfo &Output, const JobAction &JA) {
+ StringRef Format = "yaml";
+ if (const Arg *A = Args.getLastArg(options::OPT_fsave_optimization_record_EQ))
+ Format = A->getValue();
+
CmdArgs.push_back("-opt-record-file");
const Arg *A = Args.getLastArg(options::OPT_foptimization_record_file_EQ);
@@ -1454,11 +1459,17 @@ static void renderRemarksOptions(const ArgList &Args, ArgStringList &CmdArgs,
bool hasMultipleArchs =
Triple.isOSDarwin() && // Only supported on Darwin platforms.
Args.getAllArgValues(options::OPT_arch).size() > 1;
+
SmallString<128> F;
if (Args.hasArg(options::OPT_c) || Args.hasArg(options::OPT_S)) {
if (Arg *FinalOutput = Args.getLastArg(options::OPT_o))
F = FinalOutput->getValue();
+ } else {
+ if (Format != "yaml" && // For YAML, keep the original behavior.
+ Triple.isOSDarwin() && // Enable this only on darwin, since it's the only platform supporting .dSYM bundles.
+ Output.isFilename())
+ F = Output.getFilename();
}
if (F.empty()) {
@@ -1494,12 +1505,9 @@ static void renderRemarksOptions(const ArgList &Args, ArgStringList &CmdArgs,
llvm::sys::path::replace_extension(F, OldExtension);
}
- std::string Extension = "opt.";
- if (const Arg *A =
- Args.getLastArg(options::OPT_fsave_optimization_record_EQ))
- Extension += A->getValue();
- else
- Extension += "yaml";
+ SmallString<32> Extension;
+ Extension += "opt.";
+ Extension += Format;
llvm::sys::path::replace_extension(F, Extension);
CmdArgs.push_back(Args.MakeArgString(F));
@@ -1511,10 +1519,9 @@ static void renderRemarksOptions(const ArgList &Args, ArgStringList &CmdArgs,
CmdArgs.push_back(A->getValue());
}
- if (const Arg *A =
- Args.getLastArg(options::OPT_fsave_optimization_record_EQ)) {
+ if (!Format.empty()) {
CmdArgs.push_back("-opt-record-format");
- CmdArgs.push_back(A->getValue());
+ CmdArgs.push_back(Format.data());
}
}
@@ -5524,7 +5531,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
// Remarks can be enabled with any of the `-f.*optimization-record.*` flags.
if (willEmitRemarks(Args) && checkRemarksOptions(D, Args, Triple))
- renderRemarksOptions(Args, CmdArgs, Triple, Input, JA);
+ renderRemarksOptions(Args, CmdArgs, Triple, Input, Output, JA);
bool RewriteImports = Args.hasFlag(options::OPT_frewrite_imports,
options::OPT_fno_rewrite_imports, false);
diff --git a/clang/test/Driver/darwin-opt-record.c b/clang/test/Driver/darwin-opt-record.c
index 477307c8022f..4a61932bc32e 100644
--- a/clang/test/Driver/darwin-opt-record.c
+++ b/clang/test/Driver/darwin-opt-record.c
@@ -4,6 +4,7 @@
// RUN: %clang -target x86_64-apple-darwin10 -### -c -o FOO -foptimization-record-file=tmp -arch x86_64 -arch x86_64h %s 2>&1 | FileCheck %s --check-prefix=CHECK-MULTIPLE-ARCH-ERROR
// RUN: %clang -target x86_64-apple-darwin10 -### -o FOO -fsave-optimization-record %s 2>&1 | FileCheck %s --check-prefix=CHECK-DSYMUTIL-NO-G
// RUN: %clang -target x86_64-apple-darwin10 -### -o FOO -g0 -fsave-optimization-record %s 2>&1 | FileCheck %s --check-prefix=CHECK-DSYMUTIL-G0
+// RUN: %clang -target x86_64-apple-darwin10 -### -o FOO -fsave-optimization-record=bitstream %s 2>&1 | FileCheck %s --check-prefix=CHECK-NO-G-PATH-BITSTREAM
//
// CHECK-MULTIPLE-ARCH: "-cc1"
// CHECK-MULTIPLE-ARCH: "-opt-record-file" "FOO-x86_64.opt.yaml"
@@ -22,3 +23,9 @@
// CHECK-DSYMUTIL-G0: "-cc1"
// CHECK-DSYMUTIL-G0: ld
// CHECK-DSYMUTIL-G0: dsymutil
+//
+// CHECK-NO-G-PATH-BITSTREAM: "-cc1"
+// CHECK-NO-G-PATH-BITSTREAM: "-opt-record-file" "[[OUTPATH:.*]].opt.bitstream"
+// CHECK-NO-G-PATH-BITSTREAM: "-o" "[[OUTPATH:.*]].o"
+// CHECK-NO-G-PATH-BITSTREAM: ld
+// CHECK-NO-G-PATH-BITSTREAM: dsymutil
More information about the cfe-commits
mailing list