Skip to content

Commit fc5da53

Browse files
authored
Merge pull request swiftlang#72603 from compnerd/target-cpu
ClangImporter: handle `-target-cpu` for x86 targets
2 parents 3119a47 + e89bfcf commit fc5da53

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,8 +799,19 @@ importer::addCommonInvocationArguments(
799799
}
800800

801801
if (!importerOpts.TargetCPU.empty()) {
802-
invocationArgStrs.push_back("-mcpu=" + importerOpts.TargetCPU);
803-
802+
switch (triple.getArch()) {
803+
case llvm::Triple::x86:
804+
case llvm::Triple::x86_64:
805+
// `-mcpu` is deprecated and an alias for `-mtune`. We need to pass
806+
// `-march` and `-mtune` to behave identically to the `apple-a\d+` cases
807+
// below.
808+
invocationArgStrs.push_back("-march=" + importerOpts.TargetCPU);
809+
invocationArgStrs.push_back("-mtune=" + importerOpts.TargetCPU);
810+
break;
811+
default:
812+
invocationArgStrs.push_back("-mcpu=" + importerOpts.TargetCPU);
813+
break;
814+
}
804815
} else if (triple.isOSDarwin()) {
805816
// Special case CPU based on known deployments:
806817
// - arm64 deploys to apple-a7

test/Misc/target-cpu.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@
4040
// RUN: not %swift -typecheck -target s390x-unknown-linux-gnu -Xcc -### %s 2>&1 | %FileCheck -check-prefix=S390X_CPU %s
4141
// S390X_CPU: "-target-cpu" "z13"
4242

43+
// RUN: not %swiftc -typecheck -target x86_64-unknown-windows-msvc -target-cpu haswell -Xcc -### %s 2>&1 | %FileCheck -check-prefix X86_64 %s
44+
// X86_64: "-target-cpu" "haswell"
45+
// X86_64: "-tune-cpu" "haswell"

0 commit comments

Comments
 (0)