Skip to content

Commit b4e2b11

Browse files
committed
[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
1 parent 1689ad2 commit b4e2b11

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5403,6 +5403,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
54035403
if (A) {
54045404
CmdArgs.push_back(A->getValue());
54055405
} else {
5406+
bool hasMultipleArchs =
5407+
Args.getAllArgValues(options::OPT_arch).size() > 1;
54065408
SmallString<128> F;
54075409

54085410
if (Args.hasArg(options::OPT_c) || Args.hasArg(options::OPT_S)) {
@@ -5427,6 +5429,22 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
54275429
}
54285430
}
54295431

5432+
// If we're having more than one "-arch", we should name the files
5433+
// differently so that every cc1 invocation writes to a different file.
5434+
// We're doing that by appending "-<arch>" with "<arch>" being the arch
5435+
// name from the triple.
5436+
if (hasMultipleArchs) {
5437+
// First, remember the extension.
5438+
SmallString<64> OldExtension = llvm::sys::path::extension(F);
5439+
// then, remove it.
5440+
llvm::sys::path::replace_extension(F, "");
5441+
// attach -<arch> to it.
5442+
F += "-";
5443+
F += Triple.getArchName();
5444+
// put back the extension.
5445+
llvm::sys::path::replace_extension(F, OldExtension);
5446+
}
5447+
54305448
std::string Extension = "opt.";
54315449
if (const Arg *A =
54325450
Args.getLastArg(options::OPT_fsave_optimization_record_EQ))

clang/test/Driver/opt-record.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// RUN: %clang -### -S -o FOO -fsave-optimization-record -fsave-optimization-record=some-format %s 2>&1 | FileCheck %s -check-prefix=CHECK-EQ-FORMAT
1919
// RUN: %clang -### -S -o FOO -fsave-optimization-record=some-format %s 2>&1 | FileCheck %s -check-prefix=CHECK-EQ-FORMAT
2020
// RUN: %clang -### -S -o FOO -fsave-optimization-record=some-format -fno-save-optimization-record %s 2>&1 | FileCheck %s --check-prefix=CHECK-FOPT-DISABLE-FORMAT
21+
// RUN: %clang -### -S -o FOO -fsave-optimization-record -arch x86_64 -arch x86_64h %s 2>&1 | FileCheck %s --check-prefix=CHECK-MULTIPLE-ARCH
2122
//
2223
// CHECK: "-cc1"
2324
// CHECK: "-opt-record-file" "FOO.opt.yaml"
@@ -41,3 +42,8 @@
4142
// CHECK-EQ-FORMAT: "-opt-record-format" "some-format"
4243

4344
// CHECK-FOPT-DISABLE-FORMAT-NOT: "-fno-save-optimization-record"
45+
46+
// CHECK-MULTIPLE-ARCH: "-cc1"
47+
// CHECK-MULTIPLE-ARCH: "-opt-record-file" "FOO-x86_64.opt.yaml"
48+
// CHECK-MULTIPLE-ARCH: "-cc1"
49+
// CHECK-MULTIPLE-ARCH: "-opt-record-file" "FOO-x86_64h.opt.yaml"

0 commit comments

Comments
 (0)