Skip to content

Commit e15b26f

Browse files
committed
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
1 parent 9d93893 commit e15b26f

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5218,6 +5218,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
52185218
if (A) {
52195219
CmdArgs.push_back(A->getValue());
52205220
} else {
5221+
bool hasMultipleArchs =
5222+
Triple.isOSDarwin() && // Only supported on Darwin platforms.
5223+
Args.getAllArgValues(options::OPT_arch).size() > 1;
52215224
SmallString<128> F;
52225225

52235226
if (Args.hasArg(options::OPT_c) || Args.hasArg(options::OPT_S)) {
@@ -5242,6 +5245,22 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
52425245
}
52435246
}
52445247

5248+
// If we're having more than one "-arch", we should name the files
5249+
// differently so that every cc1 invocation writes to a different file.
5250+
// We're doing that by appending "-<arch>" with "<arch>" being the arch
5251+
// name from the triple.
5252+
if (hasMultipleArchs) {
5253+
// First, remember the extension.
5254+
SmallString<64> OldExtension = llvm::sys::path::extension(F);
5255+
// then, remove it.
5256+
llvm::sys::path::replace_extension(F, "");
5257+
// attach -<arch> to it.
5258+
F += "-";
5259+
F += Triple.getArchName();
5260+
// put back the extension.
5261+
llvm::sys::path::replace_extension(F, OldExtension);
5262+
}
5263+
52455264
std::string Extension = "opt.";
52465265
if (const Arg *A =
52475266
Args.getLastArg(options::OPT_fsave_optimization_record_EQ))

clang/test/Driver/darwin-opt-record.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// REQUIRES: system-darwin
2+
3+
// RUN: %clang -### -S -o FOO -fsave-optimization-record -arch x86_64 -arch x86_64h %s 2>&1 | FileCheck %s --check-prefix=CHECK-MULTIPLE-ARCH
4+
//
5+
// CHECK-MULTIPLE-ARCH: "-cc1"
6+
// CHECK-MULTIPLE-ARCH: "-opt-record-file" "FOO-x86_64.opt.yaml"
7+
// CHECK-MULTIPLE-ARCH: "-cc1"
8+
// CHECK-MULTIPLE-ARCH: "-opt-record-file" "FOO-x86_64h.opt.yaml"

0 commit comments

Comments
 (0)