Author: Min-Yih Hsu Date: 2021-03-08T12:30:57-08:00 New Revision: 5509748f2ce5e06bda7da754297d09a0e68a1f30
URL: https://github.com/llvm/llvm-project/commit/5509748f2ce5e06bda7da754297d09a0e68a1f30 DIFF: https://github.com/llvm/llvm-project/commit/5509748f2ce5e06bda7da754297d09a0e68a1f30.diff LOG: [cfe][driver][M68k](8/8) Clang driver support Add M68k-specific toolchain and driver configurations / options. Authors: myhsu, m4yers, glaubitz Differential Revision: https://reviews.llvm.org/D88394 Added: clang/lib/Driver/ToolChains/Arch/M68k.cpp clang/lib/Driver/ToolChains/Arch/M68k.h clang/test/Driver/m68k-features.cpp clang/test/Driver/m68k-sub-archs.cpp Modified: clang/include/clang/Driver/Options.td clang/lib/Driver/CMakeLists.txt clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Driver/ToolChains/CommonArgs.cpp clang/lib/Driver/ToolChains/Gnu.cpp clang/lib/Driver/ToolChains/Linux.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 9172215bc512..8e71aff2e96d 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -160,6 +160,8 @@ def m_hexagon_Features_Group : OptionGroup<"<hexagon features group>">, // These are explicitly handled. def m_hexagon_Features_HVX_Group : OptionGroup<"<hexagon features group>">, Group<m_Group>, DocName<"Hexagon">; +def m_m68k_Features_Group: OptionGroup<"<m68k features group>">, + Group<m_Group>, DocName<"M68k">; def m_mips_Features_Group : OptionGroup<"<mips features group>">, Group<m_Group>, DocName<"MIPS">; def m_ppc_Features_Group : OptionGroup<"<ppc features group>">, @@ -3895,6 +3897,13 @@ def mnvs : Flag<["-"], "mnvs">, Group<m_hexagon_Features_Group>, def mno_nvs : Flag<["-"], "mno-nvs">, Group<m_hexagon_Features_Group>, Flags<[CC1Option]>, HelpText<"Disable generation of new-value stores">; +// M68k features flags +def m68000 : Flag<["-"], "m68000">, Group<m_m68k_Features_Group>; +def m68010 : Flag<["-"], "m68010">, Group<m_m68k_Features_Group>; +def m68020 : Flag<["-"], "m68020">, Group<m_m68k_Features_Group>; +def m68030 : Flag<["-"], "m68030">, Group<m_m68k_Features_Group>; +def m68040 : Flag<["-"], "m68040">, Group<m_m68k_Features_Group>; +def m68060 : Flag<["-"], "m68060">, Group<m_m68k_Features_Group>; // X86 feature flags def mx87 : Flag<["-"], "mx87">, Group<m_x86_Features_Group>; diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt index 7542daf3b8f7..f59141f9e19f 100644 --- a/clang/lib/Driver/CMakeLists.txt +++ b/clang/lib/Driver/CMakeLists.txt @@ -26,6 +26,7 @@ add_clang_library(clangDriver ToolChain.cpp ToolChains/Arch/AArch64.cpp ToolChains/Arch/ARM.cpp + ToolChains/Arch/M68k.cpp ToolChains/Arch/Mips.cpp ToolChains/Arch/PPC.cpp ToolChains/Arch/RISCV.cpp diff --git a/clang/lib/Driver/ToolChains/Arch/M68k.cpp b/clang/lib/Driver/ToolChains/Arch/M68k.cpp new file mode 100644 index 000000000000..66c9f5c87bfb --- /dev/null +++ b/clang/lib/Driver/ToolChains/Arch/M68k.cpp @@ -0,0 +1,93 @@ +//===--- M68k.cpp - M68k Helpers for Tools -------------------*- C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "M68k.h" +#include "ToolChains/CommonArgs.h" +#include "clang/Driver/Driver.h" +#include "clang/Driver/DriverDiagnostic.h" +#include "clang/Driver/Options.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringSwitch.h" +#include "llvm/Option/ArgList.h" +#include "llvm/Support/Host.h" +#include "llvm/Support/Regex.h" +#include <sstream> + +using namespace clang::driver; +using namespace clang::driver::tools; +using namespace clang; +using namespace llvm::opt; + +/// getM68kTargetCPU - Get the (LLVM) name of the 68000 cpu we are targeting. +std::string m68k::getM68kTargetCPU(const ArgList &Args) { + if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) { + // The canonical CPU name is captalize. However, we allow + // starting with lower case or numbers only + StringRef CPUName = A->getValue(); + + if (CPUName == "native") { + std::string CPU = std::string(llvm::sys::getHostCPUName()); + if (!CPU.empty() && CPU != "generic") + return CPU; + } + + if (CPUName == "common") + return "generic"; + + return llvm::StringSwitch<std::string>(CPUName) + .Cases("m68000", "68000", "M68000") + .Cases("m68010", "68010", "M68010") + .Cases("m68020", "68020", "M68020") + .Cases("m68030", "68030", "M68030") + .Cases("m68040", "68040", "M68040") + .Cases("m68060", "68060", "M68060") + .Default(CPUName.str()); + } + // FIXME: Throw error when multiple sub-architecture flag exist + if (Args.hasArg(clang::driver::options::OPT_m68000)) + return "M68000"; + if (Args.hasArg(clang::driver::options::OPT_m68010)) + return "M68010"; + if (Args.hasArg(clang::driver::options::OPT_m68020)) + return "M68020"; + if (Args.hasArg(clang::driver::options::OPT_m68030)) + return "M68030"; + if (Args.hasArg(clang::driver::options::OPT_m68040)) + return "M68040"; + if (Args.hasArg(clang::driver::options::OPT_m68060)) + return "M68060"; + + return ""; +} + +void m68k::getM68kTargetFeatures(const Driver &D, const llvm::Triple &Triple, + const ArgList &Args, + std::vector<StringRef> &Features) { + + m68k::FloatABI FloatABI = m68k::getM68kFloatABI(D, Args); + if (FloatABI == m68k::FloatABI::Soft) + Features.push_back("-hard-float"); +} + +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; +} diff --git a/clang/lib/Driver/ToolChains/Arch/M68k.h b/clang/lib/Driver/ToolChains/Arch/M68k.h new file mode 100644 index 000000000000..41d53efb940b --- /dev/null +++ b/clang/lib/Driver/ToolChains/Arch/M68k.h @@ -0,0 +1,42 @@ +//===--- M68k.h - M68k-specific Tool Helpers -----------------*- C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_ARCH_M680X0_H +#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_ARCH_M680X0_H + +#include "clang/Driver/Driver.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Option/Option.h" +#include <string> +#include <vector> + +namespace clang { +namespace driver { +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, + const llvm::opt::ArgList &Args, + std::vector<llvm::StringRef> &Features); + +} // end namespace m68k +} // end namespace tools +} // end namespace driver +} // end namespace clang + +#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_ARCH_M680X0_H diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 28ac00e970c4..4995ce9021bf 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -10,6 +10,7 @@ #include "AMDGPU.h" #include "Arch/AArch64.h" #include "Arch/ARM.h" +#include "Arch/M68k.h" #include "Arch/Mips.h" #include "Arch/PPC.h" #include "Arch/RISCV.h" @@ -365,6 +366,9 @@ static void getTargetFeatures(const Driver &D, const llvm::Triple &Triple, case llvm::Triple::amdgcn: amdgpu::getAMDGPUTargetFeatures(D, Triple, Args, Features); break; + case llvm::Triple::m68k: + m68k::getM68kTargetFeatures(D, Triple, Args, Features); + break; case llvm::Triple::msp430: msp430::getMSP430TargetFeatures(D, Args, Features); break; diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 5afb213a178b..62432b5b7576 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -9,6 +9,7 @@ #include "CommonArgs.h" #include "Arch/AArch64.h" #include "Arch/ARM.h" +#include "Arch/M68k.h" #include "Arch/Mips.h" #include "Arch/PPC.h" #include "Arch/SystemZ.h" @@ -372,6 +373,9 @@ std::string tools::getCPUName(const ArgList &Args, const llvm::Triple &T, return A->getValue(); return ""; + case llvm::Triple::m68k: + return m68k::getM68kTargetCPU(Args); + case llvm::Triple::mips: case llvm::Triple::mipsel: case llvm::Triple::mips64: diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index 1d8a3cdce92a..3d88053c6b08 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -254,6 +254,8 @@ static const char *getLDMOption(const llvm::Triple &T, const ArgList &Args) { case llvm::Triple::armeb: case llvm::Triple::thumbeb: return isArmBigEndian(T, Args) ? "armelfb_linux_eabi" : "armelf_linux_eabi"; + case llvm::Triple::m68k: + return "m68kelf"; case llvm::Triple::ppc: if (T.isOSLinux()) return "elf32ppclinux"; @@ -2114,6 +2116,10 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes( "i686-linux-android", "i386-gnu", "i486-gnu", "i586-gnu", "i686-gnu"}; + static const char *const M68kLibDirs[] = {"/lib"}; + static const char *const M68kTriples[] = { + "m68k-linux-gnu", "m68k-unknown-linux-gnu", "m68k-suse-linux"}; + static const char *const MIPSLibDirs[] = {"/lib"}; static const char *const MIPSTriples[] = { "mips-linux-gnu", "mips-mti-linux", "mips-mti-linux-gnu", @@ -2353,6 +2359,10 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes( BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples)); } break; + case llvm::Triple::m68k: + LibDirs.append(begin(M68kLibDirs), end(M68kLibDirs)); + TripleAliases.append(begin(M68kTriples), end(M68kTriples)); + break; case llvm::Triple::mips: LibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs)); TripleAliases.append(begin(MIPSTriples), end(MIPSTriples)); @@ -2760,6 +2770,7 @@ bool Generic_GCC::IsIntegratedAssemblerDefault() const { case llvm::Triple::mips64: case llvm::Triple::mips64el: case llvm::Triple::msp430: + case llvm::Triple::m68k: return true; case llvm::Triple::sparc: case llvm::Triple::sparcel: diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp index b7b992124d30..93a56be6a7a4 100644 --- a/clang/lib/Driver/ToolChains/Linux.cpp +++ b/clang/lib/Driver/ToolChains/Linux.cpp @@ -102,6 +102,12 @@ std::string Linux::getMultiarchTriple(const Driver &D, if (D.getVFS().exists(SysRoot + "/lib/aarch64_be-linux-gnu")) return "aarch64_be-linux-gnu"; break; + + case llvm::Triple::m68k: + if (D.getVFS().exists(SysRoot + "/lib/m68k-linux-gnu")) + return "m68k-linux-gnu"; + break; + case llvm::Triple::mips: { std::string MT = IsMipsR6 ? "mipsisa32r6-linux-gnu" : "mips-linux-gnu"; if (D.getVFS().exists(SysRoot + "/lib/" + MT)) @@ -476,6 +482,10 @@ std::string Linux::getDynamicLinker(const ArgList &Args) const { Loader = HF ? "ld-linux-armhf.so.3" : "ld-linux.so.3"; break; } + case llvm::Triple::m68k: + LibDir = "lib"; + Loader = "ld.so.1"; + break; case llvm::Triple::mips: case llvm::Triple::mipsel: case llvm::Triple::mips64: @@ -624,6 +634,7 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, "/usr/include/armeb-linux-gnueabi"}; const StringRef ARMEBHFMultiarchIncludeDirs[] = { "/usr/include/armeb-linux-gnueabihf"}; + const StringRef M68kMultiarchIncludeDirs[] = {"/usr/include/m68k-linux-gnu"}; const StringRef MIPSMultiarchIncludeDirs[] = {"/usr/include/mips-linux-gnu"}; const StringRef MIPSELMultiarchIncludeDirs[] = { "/usr/include/mipsel-linux-gnu"}; @@ -688,6 +699,9 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs, else MultiarchIncludeDirs = ARMEBMultiarchIncludeDirs; break; + case llvm::Triple::m68k: + MultiarchIncludeDirs = M68kMultiarchIncludeDirs; + break; case llvm::Triple::mips: if (getTriple().getSubArch() == llvm::Triple::MipsSubArch_r6) MultiarchIncludeDirs = MIPSR6MultiarchIncludeDirs; diff --git a/clang/test/Driver/m68k-features.cpp b/clang/test/Driver/m68k-features.cpp new file mode 100644 index 000000000000..8f85815e7552 --- /dev/null +++ b/clang/test/Driver/m68k-features.cpp @@ -0,0 +1,45 @@ +// Check macro definitions +// RUN: %clang -target m68k-unknown-linux -m68000 -dM -E %s | FileCheck --check-prefix=CHECK-MX %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 +// CHECK-MX10: #define __mc68000 1 +// CHECK-MX10: #define __mc68000__ 1 +// CHECK-MX10: #define __mc68010 1 +// CHECK-MX10: #define __mc68010__ 1 +// 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 +// CHECK-MX20: #define __mc68000 1 +// CHECK-MX20: #define __mc68000__ 1 +// CHECK-MX20: #define __mc68020 1 +// CHECK-MX20: #define __mc68020__ 1 +// 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 +// CHECK-MX30: #define __mc68000 1 +// CHECK-MX30: #define __mc68000__ 1 +// CHECK-MX30: #define __mc68030 1 +// CHECK-MX30: #define __mc68030__ 1 +// 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 +// CHECK-MX40: #define __mc68000 1 +// CHECK-MX40: #define __mc68000__ 1 +// CHECK-MX40: #define __mc68040 1 +// CHECK-MX40: #define __mc68040__ 1 +// 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 +// CHECK-MX60: #define __mc68000 1 +// CHECK-MX60: #define __mc68000__ 1 +// CHECK-MX60: #define __mc68060 1 +// CHECK-MX60: #define __mc68060__ 1 +// CHECK-MX60: #define mc68000 1 +// CHECK-MX60: #define mc68060 1 diff --git a/clang/test/Driver/m68k-sub-archs.cpp b/clang/test/Driver/m68k-sub-archs.cpp new file mode 100644 index 000000000000..e5517d237cdd --- /dev/null +++ b/clang/test/Driver/m68k-sub-archs.cpp @@ -0,0 +1,35 @@ +// RUN: %clang -### -target m68k-unknown-linux -mcpu=68000 %s 2>&1 | FileCheck --check-prefix=CHECK-M00 %s +// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68000 %s 2>&1 | FileCheck --check-prefix=CHECK-M00 %s +// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68000 %s 2>&1 | FileCheck --check-prefix=CHECK-M00 %s +// RUN: %clang -### -target m68k-unknown-linux -m68000 %s 2>&1 | FileCheck --check-prefix=CHECK-M00 %s +// CHECK-M00: "-target-cpu" "M68000" + +// RUN: %clang -### -target m68k-unknown-linux -mcpu=68010 %s 2>&1 | FileCheck --check-prefix=CHECK-M10 %s +// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68010 %s 2>&1 | FileCheck --check-prefix=CHECK-M10 %s +// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68010 %s 2>&1 | FileCheck --check-prefix=CHECK-M10 %s +// RUN: %clang -### -target m68k-unknown-linux -m68010 %s 2>&1 | FileCheck --check-prefix=CHECK-M10 %s +// CHECK-M10: "-target-cpu" "M68010" + +// RUN: %clang -### -target m68k-unknown-linux -mcpu=68020 %s 2>&1 | FileCheck --check-prefix=CHECK-M20 %s +// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68020 %s 2>&1 | FileCheck --check-prefix=CHECK-M20 %s +// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68020 %s 2>&1 | FileCheck --check-prefix=CHECK-M20 %s +// RUN: %clang -### -target m68k-unknown-linux -m68020 %s 2>&1 | FileCheck --check-prefix=CHECK-M20 %s +// CHECK-M20: "-target-cpu" "M68020" + +// RUN: %clang -### -target m68k-unknown-linux -mcpu=68030 %s 2>&1 | FileCheck --check-prefix=CHECK-M30 %s +// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68030 %s 2>&1 | FileCheck --check-prefix=CHECK-M30 %s +// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68030 %s 2>&1 | FileCheck --check-prefix=CHECK-M30 %s +// RUN: %clang -### -target m68k-unknown-linux -m68030 %s 2>&1 | FileCheck --check-prefix=CHECK-M30 %s +// CHECK-M30: "-target-cpu" "M68030" + +// RUN: %clang -### -target m68k-unknown-linux -mcpu=68040 %s 2>&1 | FileCheck --check-prefix=CHECK-M40 %s +// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68040 %s 2>&1 | FileCheck --check-prefix=CHECK-M40 %s +// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68040 %s 2>&1 | FileCheck --check-prefix=CHECK-M40 %s +// RUN: %clang -### -target m68k-unknown-linux -m68040 %s 2>&1 | FileCheck --check-prefix=CHECK-M40 %s +// CHECK-M40: "-target-cpu" "M68040" + +// RUN: %clang -### -target m68k-unknown-linux -mcpu=68060 %s 2>&1 | FileCheck --check-prefix=CHECK-M60 %s +// RUN: %clang -### -target m68k-unknown-linux -mcpu=m68060 %s 2>&1 | FileCheck --check-prefix=CHECK-M60 %s +// RUN: %clang -### -target m68k-unknown-linux -mcpu=M68060 %s 2>&1 | FileCheck --check-prefix=CHECK-M60 %s +// RUN: %clang -### -target m68k-unknown-linux -m68060 %s 2>&1 | FileCheck --check-prefix=CHECK-M60 %s +// CHECK-M60: "-target-cpu" "M68060" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits