Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -4648,6 +4648,8 @@ def m68040 : Flag<["-"], "m68040">, Group; def m68060 : Flag<["-"], "m68060">, Group; +def m68881 : Flag<["-"], "m68881">, Group; + foreach i = {0-6} in def ffixed_a#i : Flag<["-"], "ffixed-a"#i>, Group, HelpText<"Reserve the a"#i#" register (M68k only)">; Index: clang/lib/Basic/Targets/M68k.h =================================================================== --- clang/lib/Basic/Targets/M68k.h +++ clang/lib/Basic/Targets/M68k.h @@ -36,6 +36,8 @@ CK_68060 } CPU = CK_Unknown; + const TargetOptions &TargetOpts; + public: M68kTargetInfo(const llvm::Triple &Triple, const TargetOptions &); Index: clang/lib/Basic/Targets/M68k.cpp =================================================================== --- clang/lib/Basic/Targets/M68k.cpp +++ clang/lib/Basic/Targets/M68k.cpp @@ -27,8 +27,8 @@ namespace targets { M68kTargetInfo::M68kTargetInfo(const llvm::Triple &Triple, - const TargetOptions &) - : TargetInfo(Triple) { + const TargetOptions &Opts) + : TargetInfo(Triple), TargetOpts(Opts) { std::string Layout; @@ -120,6 +120,11 @@ Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2"); Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4"); } + + // Floating point + if (TargetOpts.FeatureMap.lookup("isa-68881") || + TargetOpts.FeatureMap.lookup("isa-68882")) + Builder.defineMacro("__HAVE_68881__"); } ArrayRef M68kTargetInfo::getTargetBuiltins() const { Index: clang/lib/Driver/ToolChains/Arch/M68k.h =================================================================== --- clang/lib/Driver/ToolChains/Arch/M68k.h +++ clang/lib/Driver/ToolChains/Arch/M68k.h @@ -20,14 +20,6 @@ namespace tools { namespace m68k { -enum class FloatABI { - Invalid, - Soft, - Hard, -}; - -FloatABI getM68kFloatABI(const Driver &D, const llvm::opt::ArgList &Args); - std::string getM68kTargetCPU(const llvm::opt::ArgList &Args); void getM68kTargetFeatures(const Driver &D, const llvm::Triple &Triple, Index: clang/lib/Driver/ToolChains/Arch/M68k.cpp =================================================================== --- clang/lib/Driver/ToolChains/Arch/M68k.cpp +++ clang/lib/Driver/ToolChains/Arch/M68k.cpp @@ -65,13 +65,35 @@ return ""; } +static void addFloatABIFeatures(const llvm::opt::ArgList &Args, + std::vector &Features) { + Arg *A = Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float, + options::OPT_m68881); + // Opt out FPU even for newer CPUs. + if (A && A->getOption().matches(options::OPT_msoft_float)) { + Features.push_back("-isa-68881"); + Features.push_back("-isa-68882"); + return; + } + + std::string CPU = m68k::getM68kTargetCPU(Args); + // Only enable M68881 for CPU < 68020 if the related flags are present. + if ((A && (CPU == "M68000" || CPU == "M68010")) || + // Otherwise, by default we assume newer CPUs have M68881/2. + CPU == "M68020") + Features.push_back("+isa-68881"); + else if (CPU == "M68030" || CPU == "M68040" || CPU == "M68060") + // Note that although CPU >= M68040 imply M68882, we still add `isa-68882` + // anyway so that it's easier to add or not add the corresponding macro + // definitions later, in case we want to disable 68881/2 in newer CPUs + // (with -msoft-float, for instance). + Features.push_back("+isa-68882"); +} + void m68k::getM68kTargetFeatures(const Driver &D, const llvm::Triple &Triple, const ArgList &Args, std::vector &Features) { - - m68k::FloatABI FloatABI = m68k::getM68kFloatABI(D, Args); - if (FloatABI == m68k::FloatABI::Soft) - Features.push_back("-hard-float"); + addFloatABIFeatures(Args, Features); // Handle '-ffixed-' flags if (Args.hasArg(options::OPT_ffixed_a0)) @@ -105,21 +127,3 @@ if (Args.hasArg(options::OPT_ffixed_d7)) Features.push_back("+reserve-d7"); } - -m68k::FloatABI m68k::getM68kFloatABI(const Driver &D, const ArgList &Args) { - m68k::FloatABI ABI = m68k::FloatABI::Invalid; - if (Arg *A = - Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float)) { - - if (A->getOption().matches(options::OPT_msoft_float)) - ABI = m68k::FloatABI::Soft; - else if (A->getOption().matches(options::OPT_mhard_float)) - ABI = m68k::FloatABI::Hard; - } - - // If unspecified, choose the default based on the platform. - if (ABI == m68k::FloatABI::Invalid) - ABI = m68k::FloatABI::Hard; - - return ABI; -} Index: clang/test/Driver/m68k-features.cpp =================================================================== --- clang/test/Driver/m68k-features.cpp +++ clang/test/Driver/m68k-features.cpp @@ -59,3 +59,23 @@ // RUN: FileCheck --check-prefix=CHECK-FIXED-D7 < %t %s // CHECK-FIXED-D7: "-target-feature" "+reserve-d7" +// ==== Floating point ==== +// RUN: %clang -target m68k -m68000 -mhard-float -### %s 2> %t +// RUN: FileCheck --check-prefix=CHECK-MX881 < %t %s +// RUN: %clang -target m68k -m68000 -m68881 -### %s 2> %t +// RUN: FileCheck --check-prefix=CHECK-MX881 < %t %s + +// RUN: %clang -target m68k -m68010 -mhard-float -### %s 2> %t +// RUN: FileCheck --check-prefix=CHECK-MX881 < %t %s +// RUN: %clang -target m68k -m68010 -m68881 -### %s 2> %t +// RUN: FileCheck --check-prefix=CHECK-MX881 < %t %s + +// RUN: %clang -target m68k -m68020 -### %s 2> %t +// RUN: FileCheck --check-prefix=CHECK-MX881 < %t %s + +// RUN: %clang -target m68k -m68030 -### %s 2> %t +// RUN: FileCheck --check-prefix=CHECK-MX882 < %t %s + +// CHECK-MX881: "-target-feature" "+isa-68881" +// CHECK-MX882: "-target-feature" "+isa-68882" + Index: clang/test/Driver/m68k-macros.cpp =================================================================== --- clang/test/Driver/m68k-macros.cpp +++ clang/test/Driver/m68k-macros.cpp @@ -1,10 +1,19 @@ // Check macro definitions -// RUN: %clang -target m68k-unknown-linux -m68000 -dM -E %s | FileCheck --check-prefix=CHECK-MX %s + +// Since '__HAVE_68881__' sorted before most of the 'mc680x0' macros, we need to put it here. +// CHECK-MX881: #define __HAVE_68881__ 1 +// CHECK-NOMX881-NOT: #define __HAVE_68881__ 1 + +// RUN: %clang -target m68k-unknown-linux -m68000 -dM -E %s | FileCheck --check-prefixes=CHECK-MX,CHECK-NOMX881 %s +// RUN: %clang -target m68k-unknown-linux -m68000 -mhard-float -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s +// RUN: %clang -target m68k-unknown-linux -m68000 -m68881 -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s // CHECK-MX: #define __mc68000 1 // CHECK-MX: #define __mc68000__ 1 // CHECK-MX: #define mc68000 1 -// RUN: %clang -target m68k-unknown-linux -m68010 -dM -E %s | FileCheck --check-prefix=CHECK-MX10 %s +// RUN: %clang -target m68k-unknown-linux -m68010 -dM -E %s | FileCheck --check-prefixes=CHECK-MX10,CHECK-NOMX881 %s +// RUN: %clang -target m68k-unknown-linux -m68010 -mhard-float -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s +// RUN: %clang -target m68k-unknown-linux -m68010 -m68881 -dM -E %s | FileCheck --check-prefix=CHECK-MX881 %s // CHECK-MX10: #define __mc68000 1 // CHECK-MX10: #define __mc68000__ 1 // CHECK-MX10: #define __mc68010 1 @@ -12,7 +21,8 @@ // CHECK-MX10: #define mc68000 1 // CHECK-MX10: #define mc68010 1 -// RUN: %clang -target m68k-unknown-linux -m68020 -dM -E %s | FileCheck --check-prefix=CHECK-MX20 %s +// RUN: %clang -target m68k-unknown-linux -m68020 -dM -E %s | FileCheck --check-prefixes=CHECK-MX20,CHECK-MX881 %s +// RUN: %clang -target m68k-unknown-linux -m68020 -msoft-float -dM -E %s | FileCheck --check-prefix=CHECK-NOMX881 %s // CHECK-MX20: #define __mc68000 1 // CHECK-MX20: #define __mc68000__ 1 // CHECK-MX20: #define __mc68020 1 @@ -20,7 +30,8 @@ // CHECK-MX20: #define mc68000 1 // CHECK-MX20: #define mc68020 1 -// RUN: %clang -target m68k-unknown-linux -m68030 -dM -E %s | FileCheck --check-prefix=CHECK-MX30 %s +// RUN: %clang -target m68k-unknown-linux -m68030 -dM -E %s | FileCheck --check-prefixes=CHECK-MX30,CHECK-MX881 %s +// RUN: %clang -target m68k-unknown-linux -m68030 -msoft-float -dM -E %s | FileCheck --check-prefix=CHECK-NOMX881 %s // CHECK-MX30: #define __mc68000 1 // CHECK-MX30: #define __mc68000__ 1 // CHECK-MX30: #define __mc68030 1 @@ -28,7 +39,8 @@ // CHECK-MX30: #define mc68000 1 // CHECK-MX30: #define mc68030 1 -// RUN: %clang -target m68k-unknown-linux -m68040 -dM -E %s | FileCheck --check-prefix=CHECK-MX40 %s +// RUN: %clang -target m68k-unknown-linux -m68040 -dM -E %s | FileCheck --check-prefixes=CHECK-MX40,CHECK-MX881 %s +// RUN: %clang -target m68k-unknown-linux -m68040 -msoft-float -dM -E %s | FileCheck --check-prefix=CHECK-NOMX881 %s // CHECK-MX40: #define __mc68000 1 // CHECK-MX40: #define __mc68000__ 1 // CHECK-MX40: #define __mc68040 1 @@ -36,7 +48,8 @@ // CHECK-MX40: #define mc68000 1 // CHECK-MX40: #define mc68040 1 -// RUN: %clang -target m68k-unknown-linux -m68060 -dM -E %s | FileCheck --check-prefix=CHECK-MX60 %s +// RUN: %clang -target m68k-unknown-linux -m68060 -dM -E %s | FileCheck --check-prefixes=CHECK-MX60,CHECK-MX881 %s +// RUN: %clang -target m68k-unknown-linux -m68060 -msoft-float -dM -E %s | FileCheck --check-prefix=CHECK-NOMX881 %s // CHECK-MX60: #define __mc68000 1 // CHECK-MX60: #define __mc68000__ 1 // CHECK-MX60: #define __mc68060 1