Skip to content

Commit 9ee7a18

Browse files
committed
[darwin][arm64] use the "cyclone" CPU for Darwin even when -arch
is not specified The -target option allows the user to specify the build target using LLVM triple. The triple includes the arch, and so the -arch option is redundant. This should work just as well without the -arch. However, the driver has a bug in which it doesn't target the "Cyclone" CPU for darwin if -target is used without -arch. This commit fixes this issue. rdar://46743182 Differential Revision: https://reviews.llvm.org/D55731 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349382 91177308-0d34-0410-b5e6-96231b3b80d8 (cherry picked from commit 468c31a)
1 parent 675d040 commit 9ee7a18

File tree

5 files changed

+28
-14
lines changed

5 files changed

+28
-14
lines changed

lib/Driver/ToolChains/Arch/AArch64.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,17 @@ using namespace clang::driver::tools;
1919
using namespace clang;
2020
using namespace llvm::opt;
2121

22+
/// \returns true if the given triple can determine the default CPU type even
23+
/// if -arch is not specified.
24+
static bool isCPUDeterminedByTriple(const llvm::Triple &Triple) {
25+
return Triple.isOSDarwin();
26+
}
27+
2228
/// getAArch64TargetCPU - Get the (LLVM) name of the AArch64 cpu we are
2329
/// targeting. Set \p A to the Arg corresponding to the -mcpu argument if it is
2430
/// provided, or to nullptr otherwise.
25-
std::string aarch64::getAArch64TargetCPU(const ArgList &Args, Arg *&A) {
31+
std::string aarch64::getAArch64TargetCPU(const ArgList &Args,
32+
const llvm::Triple &Triple, Arg *&A) {
2633
std::string CPU;
2734
// If we have -mcpu, use that.
2835
if ((A = Args.getLastArg(options::OPT_mcpu_EQ))) {
@@ -36,9 +43,9 @@ std::string aarch64::getAArch64TargetCPU(const ArgList &Args, Arg *&A) {
3643
else if (CPU.size())
3744
return CPU;
3845

39-
// Make sure we pick "cyclone" if -arch is used.
40-
// FIXME: Should this be picked by checking the target triple instead?
41-
if (Args.getLastArg(options::OPT_arch))
46+
// Make sure we pick "cyclone" if -arch is used or when targetting a Darwin
47+
// OS.
48+
if (Args.getLastArg(options::OPT_arch) || Triple.isOSDarwin())
4249
return "cyclone";
4350

4451
return "generic";
@@ -152,7 +159,9 @@ getAArch64MicroArchFeaturesFromMcpu(const Driver &D, StringRef Mcpu,
152159
return getAArch64MicroArchFeaturesFromMtune(D, CPU, Args, Features);
153160
}
154161

155-
void aarch64::getAArch64TargetFeatures(const Driver &D, const ArgList &Args,
162+
void aarch64::getAArch64TargetFeatures(const Driver &D,
163+
const llvm::Triple &Triple,
164+
const ArgList &Args,
156165
std::vector<StringRef> &Features) {
157166
Arg *A;
158167
bool success = true;
@@ -162,19 +171,20 @@ void aarch64::getAArch64TargetFeatures(const Driver &D, const ArgList &Args,
162171
success = getAArch64ArchFeaturesFromMarch(D, A->getValue(), Args, Features);
163172
else if ((A = Args.getLastArg(options::OPT_mcpu_EQ)))
164173
success = getAArch64ArchFeaturesFromMcpu(D, A->getValue(), Args, Features);
165-
else if (Args.hasArg(options::OPT_arch))
166-
success = getAArch64ArchFeaturesFromMcpu(D, getAArch64TargetCPU(Args, A),
167-
Args, Features);
174+
else if (Args.hasArg(options::OPT_arch) || isCPUDeterminedByTriple(Triple))
175+
success = getAArch64ArchFeaturesFromMcpu(
176+
D, getAArch64TargetCPU(Args, Triple, A), Args, Features);
168177

169178
if (success && (A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)))
170179
success =
171180
getAArch64MicroArchFeaturesFromMtune(D, A->getValue(), Args, Features);
172181
else if (success && (A = Args.getLastArg(options::OPT_mcpu_EQ)))
173182
success =
174183
getAArch64MicroArchFeaturesFromMcpu(D, A->getValue(), Args, Features);
175-
else if (success && Args.hasArg(options::OPT_arch))
184+
else if (success &&
185+
(Args.hasArg(options::OPT_arch) || isCPUDeterminedByTriple(Triple)))
176186
success = getAArch64MicroArchFeaturesFromMcpu(
177-
D, getAArch64TargetCPU(Args, A), Args, Features);
187+
D, getAArch64TargetCPU(Args, Triple, A), Args, Features);
178188

179189
if (!success)
180190
D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);

lib/Driver/ToolChains/Arch/AArch64.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ namespace driver {
2121
namespace tools {
2222
namespace aarch64 {
2323

24-
void getAArch64TargetFeatures(const Driver &D, const llvm::opt::ArgList &Args,
24+
void getAArch64TargetFeatures(const Driver &D, const llvm::Triple &Triple,
25+
const llvm::opt::ArgList &Args,
2526
std::vector<llvm::StringRef> &Features);
2627

2728
std::string getAArch64TargetCPU(const llvm::opt::ArgList &Args,
28-
llvm::opt::Arg *&A);
29+
const llvm::Triple &Triple, llvm::opt::Arg *&A);
2930

3031
} // end namespace aarch64
3132
} // end namespace target

lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ static void getTargetFeatures(const ToolChain &TC, const llvm::Triple &Triple,
341341
break;
342342
case llvm::Triple::aarch64:
343343
case llvm::Triple::aarch64_be:
344-
aarch64::getAArch64TargetFeatures(D, Args, Features);
344+
aarch64::getAArch64TargetFeatures(D, Triple, Args, Features);
345345
break;
346346
case llvm::Triple::x86:
347347
case llvm::Triple::x86_64:

lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ std::string tools::getCPUName(const ArgList &Args, const llvm::Triple &T,
270270

271271
case llvm::Triple::aarch64:
272272
case llvm::Triple::aarch64_be:
273-
return aarch64::getAArch64TargetCPU(Args, A);
273+
return aarch64::getAArch64TargetCPU(Args, T, A);
274274

275275
case llvm::Triple::arm:
276276
case llvm::Triple::armeb:

test/Driver/aarch64-cpus.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
// ARM64-NATIVE-NOT: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" "native"
2222

2323
// RUN: %clang -target arm64-apple-darwin -arch arm64 -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-DARWIN %s
24+
// RUN: %clang -target arm64-apple-darwin -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-DARWIN %s
25+
// RUN: %clang -target arm64-apple-ios12.0 -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-DARWIN %s
2426
// ARM64-DARWIN: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" "cyclone"
27+
// ARM64-DARWIN-SAME: "-target-feature" "+aes"
2528

2629
// RUN: %clang -target aarch64 -mcpu=cortex-a35 -### -c %s 2>&1 | FileCheck -check-prefix=CA35 %s
2730
// RUN: %clang -target aarch64 -mlittle-endian -mcpu=cortex-a35 -### -c %s 2>&1 | FileCheck -check-prefix=CA35 %s

0 commit comments

Comments
 (0)