[clang] e15b26f - Reland: [Remarks][Driver] Use different remark files when targeting multiple architectures
Francis Visoiu Mistrih via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 18 11:17:51 PST 2019
Author: Francis Visoiu Mistrih
Date: 2019-11-18T11:17:38-08:00
New Revision: e15b26fbbd901315a1402f97e83abf29bdce9a9f
URL: https://github.com/llvm/llvm-project/commit/e15b26fbbd901315a1402f97e83abf29bdce9a9f
DIFF: https://github.com/llvm/llvm-project/commit/e15b26fbbd901315a1402f97e83abf29bdce9a9f.diff
LOG: Reland: [Remarks][Driver] Use different remark files when targeting multiple architectures
When the driver is targeting multiple architectures at once, for things
like Universal Mach-Os, we need to emit different remark files for each
cc1 invocation to avoid overwriting the files from a different
invocation.
For example:
$ clang -c -o foo.o -fsave-optimization-record -arch x86_64 -arch x86_64h
will create two remark files:
* foo-x86_64.opt.yaml
* foo-x86_64h.opt.yaml
Added:
clang/test/Driver/darwin-opt-record.c
Modified:
clang/lib/Driver/ToolChains/Clang.cpp
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 6f25eea243ad..3e00c323fc65 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5218,6 +5218,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
if (A) {
CmdArgs.push_back(A->getValue());
} else {
+ 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)) {
@@ -5242,6 +5245,22 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
}
}
+ // If we're having more than one "-arch", we should name the files
+ //
diff erently so that every cc1 invocation writes to a
diff erent file.
+ // We're doing that by appending "-<arch>" with "<arch>" being the arch
+ // name from the triple.
+ if (hasMultipleArchs) {
+ // First, remember the extension.
+ SmallString<64> OldExtension = llvm::sys::path::extension(F);
+ // then, remove it.
+ llvm::sys::path::replace_extension(F, "");
+ // attach -<arch> to it.
+ F += "-";
+ F += Triple.getArchName();
+ // put back the extension.
+ llvm::sys::path::replace_extension(F, OldExtension);
+ }
+
std::string Extension = "opt.";
if (const Arg *A =
Args.getLastArg(options::OPT_fsave_optimization_record_EQ))
diff --git a/clang/test/Driver/darwin-opt-record.c b/clang/test/Driver/darwin-opt-record.c
new file mode 100644
index 000000000000..ca0fad7ee16d
--- /dev/null
+++ b/clang/test/Driver/darwin-opt-record.c
@@ -0,0 +1,8 @@
+// REQUIRES: system-darwin
+
+// RUN: %clang -### -S -o FOO -fsave-optimization-record -arch x86_64 -arch x86_64h %s 2>&1 | FileCheck %s --check-prefix=CHECK-MULTIPLE-ARCH
+//
+// CHECK-MULTIPLE-ARCH: "-cc1"
+// CHECK-MULTIPLE-ARCH: "-opt-record-file" "FOO-x86_64.opt.yaml"
+// CHECK-MULTIPLE-ARCH: "-cc1"
+// CHECK-MULTIPLE-ARCH: "-opt-record-file" "FOO-x86_64h.opt.yaml"
More information about the cfe-commits
mailing list