diff --git a/clang/lib/Driver/ToolChains/Arch/ARM.h b/clang/lib/Driver/ToolChains/Arch/ARM.h --- a/clang/lib/Driver/ToolChains/Arch/ARM.h +++ b/clang/lib/Driver/ToolChains/Arch/ARM.h @@ -51,6 +51,7 @@ void getARMArchCPUFromArgs(const llvm::opt::ArgList &Args, llvm::StringRef &Arch, llvm::StringRef &CPU, bool FromAs = false); +std::string getDefaultFPUName(const llvm::Triple &Triple); void getARMTargetFeatures(const ToolChain &TC, const llvm::Triple &Triple, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, diff --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp b/clang/lib/Driver/ToolChains/Arch/ARM.cpp --- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp +++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp @@ -270,6 +270,13 @@ return ABI; } +std::string arm::getDefaultFPUName(const llvm::Triple &Triple) { + if (Triple.isAndroid() && getARMSubArchVersionNumber(Triple) >= 7) { + return "neon"; + } + return ""; +} + void arm::getARMTargetFeatures(const ToolChain &TC, const llvm::Triple &Triple, const ArgList &Args, @@ -377,11 +384,13 @@ Features); } else if (FPUArg) { getARMFPUFeatures(D, FPUArg, Args, FPUArg->getValue(), Features); - } else if (Triple.isAndroid() && getARMSubArchVersionNumber(Triple) >= 7) { - const char *AndroidFPU = "neon"; - if (!llvm::ARM::getFPUFeatures(llvm::ARM::parseFPU(AndroidFPU), Features)) - D.Diag(clang::diag::err_drv_clang_unsupported) - << std::string("-mfpu=") + AndroidFPU; + } else { + std::string DefaultFPU = getDefaultFPUName(Triple); + if (DefaultFPU != "") { + if (!llvm::ARM::getFPUFeatures(llvm::ARM::parseFPU(DefaultFPU), Features)) + D.Diag(clang::diag::err_drv_clang_unsupported) + << std::string("-mfpu=") + DefaultFPU; + } } // Honor -mhwdiv=. ClangAs gives preference to -Wa,-mhwdiv=. diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -58,6 +58,23 @@ } } +static bool hasMOrWaMArg(const ArgList &Args, const options::ID &Opt, + const StringRef &AssemblerOpt) { + if (Args.getLastArg(Opt)) { + return true; + } + + for (const Arg *A : + Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler)) { + StringRef Value = A->getValue(); + if (Value.startswith(AssemblerOpt)) { + return true; + } + } + + return false; +} + void tools::gcc::Common::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, @@ -666,17 +683,18 @@ case llvm::Triple::armeb: case llvm::Triple::thumb: case llvm::Triple::thumbeb: { - const llvm::Triple &Triple2 = getToolChain().getTriple(); - CmdArgs.push_back(isArmBigEndian(Triple2, Args) ? "-EB" : "-EL"); - switch (Triple2.getSubArch()) { - case llvm::Triple::ARMSubArch_v7: - CmdArgs.push_back("-mfpu=neon"); - break; - case llvm::Triple::ARMSubArch_v8: - CmdArgs.push_back("-mfpu=crypto-neon-fp-armv8"); - break; - default: - break; + const llvm::Triple &Triple = getToolChain().getEffectiveTriple(); + CmdArgs.push_back(isArmBigEndian(Triple, Args) ? "-EB" : "-EL"); + if (!hasMOrWaMArg(Args, options::OPT_march_EQ, "-march=")) { + CmdArgs.push_back( + Args.MakeArgString(std::string("-march=") + Triple.getArchName())); + } + if (!hasMOrWaMArg(Args, options::OPT_mfpu_EQ, "-mfpu=")) { + std::string DefaultFPU = arm::getDefaultFPUName(Triple); + if (DefaultFPU != "") { + CmdArgs.push_back( + Args.MakeArgString(std::string("-mfpu=") + DefaultFPU)); + } } switch (arm::getARMFloatABI(getToolChain(), Args)) { diff --git a/clang/test/Driver/linux-as.c b/clang/test/Driver/linux-as.c --- a/clang/test/Driver/linux-as.c +++ b/clang/test/Driver/linux-as.c @@ -3,17 +3,17 @@ // RUN: %clang -target arm-linux -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARM %s -// CHECK-ARM: as{{(.exe)?}}" "-EL" "-mfloat-abi=soft" +// CHECK-ARM: as{{(.exe)?}}" "-EL" "-march=armv4t" "-mfloat-abi=soft" // // RUN: %clang -target arm-linux -mcpu=cortex-a8 -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARM-MCPU %s -// CHECK-ARM-MCPU: as{{(.exe)?}}" "-EL" "-mfloat-abi=soft" "-mcpu=cortex-a8" +// CHECK-ARM-MCPU: as{{(.exe)?}}" "-EL" "-march=armv7" "-mfloat-abi=soft" "-mcpu=cortex-a8" // // RUN: %clang -target arm-linux -mfpu=neon -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARM-MFPU %s -// CHECK-ARM-MFPU: as{{(.exe)?}}" "-EL" "-mfloat-abi=soft" "-mfpu=neon" +// CHECK-ARM-MFPU: as{{(.exe)?}}" "-EL" "-march=armv4t" "-mfloat-abi=soft" "-mfpu=neon" // // RUN: %clang -target arm-linux -march=armv7-a -### \ // RUN: -no-integrated-as -c %s 2>&1 \ @@ -63,62 +63,72 @@ // RUN: %clang -target armv7-linux -mcpu=cortex-a8 -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARM-TARGET %s -// CHECK-ARM-TARGET: as{{(.exe)?}}" "-EL" "-mfpu=neon" "-mfloat-abi=soft" "-mcpu=cortex-a8" +// CHECK-ARM-TARGET: as{{(.exe)?}}" "-EL" "-march=armv7" "-mfloat-abi=soft" "-mcpu=cortex-a8" // // RUN: %clang -target armebv7-linux -mcpu=cortex-a8 -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARMEB-TARGET %s -// CHECK-ARMEB-TARGET: as{{(.exe)?}}" "-EB" "-mfpu=neon" "-mfloat-abi=soft" "-mcpu=cortex-a8" +// CHECK-ARMEB-TARGET: as{{(.exe)?}}" "-EB" "-march=armebv7" "-mfloat-abi=soft" "-mcpu=cortex-a8" // // RUN: %clang -target thumbv7-linux -mcpu=cortex-a8 -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-THUMB-TARGET %s -// CHECK-THUMB-TARGET: as{{(.exe)?}}" "-EL" "-mfpu=neon" "-mfloat-abi=soft" "-mcpu=cortex-a8" +// CHECK-THUMB-TARGET: as{{(.exe)?}}" "-EL" "-march=armv7" "-mfloat-abi=soft" "-mcpu=cortex-a8" // // RUN: %clang -target thumbebv7-linux -mcpu=cortex-a8 -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-THUMBEB-TARGET %s -// CHECK-THUMBEB-TARGET: as{{(.exe)?}}" "-EB" "-mfpu=neon" "-mfloat-abi=soft" "-mcpu=cortex-a8" +// CHECK-THUMBEB-TARGET: as{{(.exe)?}}" "-EB" "-march=armebv7" "-mfloat-abi=soft" "-mcpu=cortex-a8" // // RUN: %clang -target armv8-linux -mcpu=cortex-a53 -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARM-TARGET-V8 %s -// CHECK-ARM-TARGET-V8: as{{(.exe)?}}" "-EL" "-mfpu=crypto-neon-fp-armv8" "-mfloat-abi=soft" "-mcpu=cortex-a53" +// CHECK-ARM-TARGET-V8: as{{(.exe)?}}" "-EL" "-march=armv8" "-mfloat-abi=soft" "-mcpu=cortex-a53" // // RUN: %clang -target armebv8-linux -mcpu=cortex-a53 -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARMEB-TARGET-V8 %s -// CHECK-ARMEB-TARGET-V8: as{{(.exe)?}}" "-EB" "-mfpu=crypto-neon-fp-armv8" "-mfloat-abi=soft" "-mcpu=cortex-a53" +// CHECK-ARMEB-TARGET-V8: as{{(.exe)?}}" "-EB" "-march=armebv8" "-mfloat-abi=soft" "-mcpu=cortex-a53" // // RUN: %clang -target thumbv8-linux -mcpu=cortex-a53 -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-THUMB-TARGET-V8 %s -// CHECK-THUMB-TARGET-V8: as{{(.exe)?}}" "-EL" "-mfpu=crypto-neon-fp-armv8" "-mfloat-abi=soft" "-mcpu=cortex-a53" +// CHECK-THUMB-TARGET-V8: as{{(.exe)?}}" "-EL" "-march=armv8" "-mfloat-abi=soft" "-mcpu=cortex-a53" // // RUN: %clang -target thumbebv8-linux -mcpu=cortex-a53 -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-THUMBEB-TARGET-V8 %s -// CHECK-THUMBEB-TARGET-V8: as{{(.exe)?}}" "-EB" "-mfpu=crypto-neon-fp-armv8" "-mfloat-abi=soft" "-mcpu=cortex-a53" +// CHECK-THUMBEB-TARGET-V8: as{{(.exe)?}}" "-EB" "-march=armebv8" "-mfloat-abi=soft" "-mcpu=cortex-a53" // // RUN: %clang -target arm-linux -mfloat-abi=hard -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARM-MFLOAT-ABI %s -// CHECK-ARM-MFLOAT-ABI: as{{(.exe)?}}" "-EL" "-mfloat-abi=hard" +// CHECK-ARM-MFLOAT-ABI: as{{(.exe)?}}" "-EL" "-march=armv4t" "-mfloat-abi=hard" // -// RUN: %clang -target arm-linux-androideabi -### \ +// RUN: %clang -target arm-linux-androideabi16 -### \ // RUN: -no-integrated-as -c %s 2>&1 \ -// RUN: | FileCheck -check-prefix=CHECK-ARM-ANDROID %s -// CHECK-ARM-ANDROID: as{{(.exe)?}}" "-EL" "-mfloat-abi=soft" +// RUN: | FileCheck -check-prefix=CHECK-ARM5-ANDROID %s +// CHECK-ARM5-ANDROID: as{{(.exe)?}}" "-EL" "-march=armv4t" "-mfloat-abi=soft" // -// RUN: %clang -target arm-linux-androideabi -march=armv7-a -### \ +// RUN: %clang -target arm-linux-androideabi16 -march=armv7-a -### \ // RUN: -no-integrated-as -c %s 2>&1 \ -// RUN: | FileCheck -check-prefix=CHECK-ARM-ANDROID-SOFTFP %s -// CHECK-ARM-ANDROID-SOFTFP: as{{(.exe)?}}" "-EL" "-mfloat-abi=softfp" "-march=armv7-a" +// RUN: | FileCheck -check-prefix=CHECK-MARCH-ARM7-ANDROID %s +// CHECK-MARCH-ARM7-ANDROID: as{{(.exe)?}}" "-EL" "-mfpu=neon" "-mfloat-abi=softfp" "-march=armv7-a" +// +// RUN: %clang -target armv7a-linux-androideabi16 -### \ +// RUN: -no-integrated-as -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-ARM7-ANDROID %s +// CHECK-ARM7-ANDROID: as{{(.exe)?}}" "-EL" "-march=armv7" "-mfpu=neon" "-mfloat-abi=softfp" +// +// RUN: %clang -target armv7a-linux-androideabi16 -mfpu=vfp3-d16 -### \ +// RUN: -no-integrated-as -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-ARM7-ANDROID-MFPU %s +// CHECK-ARM7-ANDROID-MFPU: as{{(.exe)?}}" "-EL" "-march=armv7" "-mfloat-abi=softfp" "-mfpu=vfp3-d16" // // RUN: %clang -target arm-linux-eabi -mhard-float -### \ // RUN: -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ARM-HARDFP %s -// CHECK-ARM-HARDFP: as{{(.exe)?}}" "-EL" "-mfloat-abi=hard" +// CHECK-ARM-HARDFP: as{{(.exe)?}}" "-EL" "-march=armv4t" "-mfloat-abi=hard" // // RUN: %clang -target aarch64-linux-gnu -mcpu=cortex-a53 -### \ // RUN: -no-integrated-as -c %s 2>&1 \