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.
``<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**
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);
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()) {
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));
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());
}
}
// 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);
// 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"
// 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