diff options
author | Kai Nacke <kai@redstar.de> | 2022-08-24 06:19:31 -0400 |
---|---|---|
committer | Kai Nacke <kai@redstar.de> | 2022-11-13 11:07:52 -0500 |
commit | 5b9635ec7d9a84f2f783285c65a3b3b412d0330b (patch) | |
tree | 060734ccbbc4de452cedfa7d1921694ae23c8724 | |
parent | 58c1247efd1776c8ab1b3f46f516d57556461e17 (diff) | |
download | llvm-5b9635ec7d9a84f2f783285c65a3b3b412d0330b.zip llvm-5b9635ec7d9a84f2f783285c65a3b3b412d0330b.tar.gz llvm-5b9635ec7d9a84f2f783285c65a3b3b412d0330b.tar.bz2 |
[m88k] Add support for -m88000 option
- Adds mc88000 as generic m88k cpu
- Makes sure that -mcpu= and -mtune= work correctly
-rw-r--r-- | clang/lib/Basic/Targets/M88k.cpp | 18 | ||||
-rw-r--r-- | clang/lib/Basic/Targets/M88k.h | 2 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/Arch/M88k.cpp | 60 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/Arch/M88k.h | 3 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/Clang.cpp | 9 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/CommonArgs.cpp | 2 | ||||
-rw-r--r-- | clang/test/Driver/m88k-mcpu.c | 21 | ||||
-rw-r--r-- | clang/test/Driver/m88k-mtune.c | 21 | ||||
-rw-r--r-- | llvm/lib/Target/M88k/M88k.td | 3 | ||||
-rw-r--r-- | llvm/lib/Target/M88k/M88kSubtarget.h | 1 |
10 files changed, 103 insertions, 37 deletions
diff --git a/clang/lib/Basic/Targets/M88k.cpp b/clang/lib/Basic/Targets/M88k.cpp index a2674b1..a3496f9 100644 --- a/clang/lib/Basic/Targets/M88k.cpp +++ b/clang/lib/Basic/Targets/M88k.cpp @@ -63,13 +63,25 @@ bool M88kTargetInfo::setCPU(const std::string &Name) { StringRef N = Name; CPU = llvm::StringSwitch<CPUKind>(N) .Case("generic", CK_88000) - .Case("M88000", CK_88000) - .Case("M88100", CK_88100) - .Case("M88110", CK_88110) + .Case("mc88000", CK_88000) + .Case("mc88100", CK_88100) + .Case("mc88110", CK_88110) .Default(CK_Unknown); return CPU != CK_Unknown; } +static constexpr llvm::StringLiteral ValidCPUNames[] = { + {"generic"}, {"mc88000"}, {"mc88100"}, {"mc88110"}}; + +void M88kTargetInfo::fillValidCPUList( + SmallVectorImpl<StringRef> &Values) const { + Values.append(std::begin(ValidCPUNames), std::end(ValidCPUNames)); +} + +bool M88kTargetInfo::isValidCPUName(StringRef Name) const { + return llvm::is_contained(ValidCPUNames, Name); +} + void M88kTargetInfo::getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const { using llvm::Twine; diff --git a/clang/lib/Basic/Targets/M88k.h b/clang/lib/Basic/Targets/M88k.h index 763ca78..566ae07 100644 --- a/clang/lib/Basic/Targets/M88k.h +++ b/clang/lib/Basic/Targets/M88k.h @@ -45,6 +45,8 @@ public: } bool setCPU(const std::string &Name) override; + void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override; + bool isValidCPUName(StringRef Name) const override; }; } // namespace targets diff --git a/clang/lib/Driver/ToolChains/Arch/M88k.cpp b/clang/lib/Driver/ToolChains/Arch/M88k.cpp index 1d74d12..0d4e785 100644 --- a/clang/lib/Driver/ToolChains/Arch/M88k.cpp +++ b/clang/lib/Driver/ToolChains/Arch/M88k.cpp @@ -23,37 +23,45 @@ using namespace clang::driver::tools; using namespace clang; using namespace llvm::opt; -/// getM88KTargetCPU - Get the (LLVM) name of the 88000 cpu we are targeting. -std::string m88k::getM88kTargetCPU(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(); +static StringRef normalizeCPU(StringRef CPUName) { + if (CPUName == "native") { + StringRef CPU = std::string(llvm::sys::getHostCPUName()); + if (!CPU.empty() && CPU != "generic") + return CPU; + } - if (CPUName == "native") { - std::string CPU = std::string(llvm::sys::getHostCPUName()); - if (!CPU.empty() && CPU != "generic") - return CPU; - } + return llvm::StringSwitch<StringRef>(CPUName) + .Cases("mc88000", "m88000", "88000", "generic", "mc88000") + .Cases("mc88100", "m88100", "88100", "mc88100") + .Cases("mc88110", "m88110", "88110", "mc88110") + .Default(CPUName); +} - if (CPUName == "common") - return "generic"; +/// getM88KTargetCPU - Get the (LLVM) name of the 88000 cpu we are targeting. +StringRef m88k::getM88kTargetCPU(const ArgList &Args) { + Arg *A = Args.getLastArg(options::OPT_m88000, options::OPT_m88100, + options::OPT_m88110, options::OPT_mcpu_EQ); + if (!A) + return StringRef(); - return llvm::StringSwitch<std::string>(CPUName) - .Cases("m88000", "88000", "M88000") - .Cases("m88100", "88100", "M88100") - .Cases("m88110", "88110", "M88110") - .Default(CPUName.str()); + switch (A->getOption().getID()) { + case options::OPT_m88000: + return "mc88000"; + case options::OPT_m88100: + return "mc88100"; + case options::OPT_m88110: + return "mc88110"; + case options::OPT_mcpu_EQ: + return normalizeCPU(A->getValue()); + default: + llvm_unreachable("Impossible option ID"); } - // FIXME: Throw error when multiple sub-architecture flag exist - if (Args.hasArg(clang::driver::options::OPT_m88000)) - return "M88000"; - if (Args.hasArg(clang::driver::options::OPT_m88100)) - return "M88100"; - if (Args.hasArg(clang::driver::options::OPT_m88110)) - return "M88110"; +} - return ""; +StringRef m88k::getM88kTuneCPU(const ArgList &Args) { + if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) + return normalizeCPU(A->getValue()); + return StringRef(); } void m88k::getM88kTargetFeatures(const Driver &D, const llvm::Triple &Triple, diff --git a/clang/lib/Driver/ToolChains/Arch/M88k.h b/clang/lib/Driver/ToolChains/Arch/M88k.h index 05c67fa..5312c8d 100644 --- a/clang/lib/Driver/ToolChains/Arch/M88k.h +++ b/clang/lib/Driver/ToolChains/Arch/M88k.h @@ -28,7 +28,8 @@ enum class FloatABI { FloatABI getM88kFloatABI(const Driver &D, const llvm::opt::ArgList &Args); -std::string getM88kTargetCPU(const llvm::opt::ArgList &Args); +StringRef getM88kTargetCPU(const llvm::opt::ArgList &Args); +StringRef getM88kTuneCPU(const llvm::opt::ArgList &Args); void getM88kTargetFeatures(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args, diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 4075ba4..5f2f77d 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -1935,13 +1935,10 @@ void Clang::AddLoongArchTargetArgs(const ArgList &Args, } void Clang::AddM88kTargetArgs(const ArgList &Args, - ArgStringList &CmdArgs) const { - if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) { + ArgStringList &CmdArgs) const { + if (StringRef TuneCPU = m88k::getM88kTuneCPU(Args); !TuneCPU.empty()) { CmdArgs.push_back("-tune-cpu"); - if (strcmp(A->getValue(), "native") == 0) - CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName())); - else - CmdArgs.push_back(A->getValue()); + CmdArgs.push_back(TuneCPU.data()); } if (Arg *A = Args.getLastArg(options::OPT_mcheck_zero_division, diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index c71e194..1019acb 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -388,7 +388,7 @@ std::string tools::getCPUName(const Driver &D, const ArgList &Args, return m68k::getM68kTargetCPU(Args); case llvm::Triple::m88k: - return m88k::getM88kTargetCPU(Args); + return std::string(m88k::getM88kTargetCPU(Args)); case llvm::Triple::mips: case llvm::Triple::mipsel: diff --git a/clang/test/Driver/m88k-mcpu.c b/clang/test/Driver/m88k-mcpu.c new file mode 100644 index 0000000..2dea5cf --- /dev/null +++ b/clang/test/Driver/m88k-mcpu.c @@ -0,0 +1,21 @@ +// RUN: %clang -target m88k-openbsd -mcpu=generic -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-GENERIC %s
+// CHECK-GENERIC: "-cc1"{{.*}} "-triple" "m88k-{{.*}} "-target-cpu" "mc88000"
+
+// RUN: %clang -target m88k-openbsd -mcpu=mc88000 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-MC88000 %s
+// CHECK-MC88000: "-cc1"{{.*}} "-triple" "m88k-{{.*}} "-target-cpu" "mc88000"
+
+// RUN: %clang -target m88k-openbsd -m88000 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-M88000 %s
+// CHECK-M88000: "-cc1"{{.*}} "-triple" "m88k-{{.*}} "-target-cpu" "mc88000"
+
+// RUN: %clang -target m88k-openbsd -mcpu=mc88100 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-MC88100 %s
+// CHECK-MC88100: "-cc1"{{.*}} "-triple" "m88k-{{.*}} "-target-cpu" "mc88100"
+
+// RUN: %clang -target m88k-openbsd -m88100 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-M88100 %s
+// CHECK-M88100: "-cc1"{{.*}} "-triple" "m88k-{{.*}} "-target-cpu" "mc88100"
+
+// RUN: %clang -target m88k-openbsd -mcpu=mc88110 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-MC88110 %s
+// CHECK-MC88110: "-cc1"{{.*}} "-triple" "m88k-{{.*}} "-target-cpu" "mc88110"
+
+// RUN: %clang -target m88k-openbsd -m88110 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-M88110 %s
+// CHECK-M88110: "-cc1"{{.*}} "-triple" "m88k-{{.*}} "-target-cpu" "mc88110"
+
diff --git a/clang/test/Driver/m88k-mtune.c b/clang/test/Driver/m88k-mtune.c new file mode 100644 index 0000000..788cd08 --- /dev/null +++ b/clang/test/Driver/m88k-mtune.c @@ -0,0 +1,21 @@ +// RUN: %clang -target m88k-openbsd -mtune=generic -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-GENERIC %s
+// CHECK-GENERIC: "-cc1"{{.*}} "-triple" "m88k-{{.*}} "-tune-cpu" "mc88000"
+
+// RUN: %clang -target m88k-openbsd -mtune=mc88000 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-MC88000 %s
+// CHECK-MC88000: "-cc1"{{.*}} "-triple" "m88k-{{.*}} "-tune-cpu" "mc88000"
+
+// RUN: %clang -target m88k-openbsd -mtune=m88000 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-M88000 %s
+// CHECK-M88000: "-cc1"{{.*}} "-triple" "m88k-{{.*}} "-tune-cpu" "mc88000"
+
+// RUN: %clang -target m88k-openbsd -mtune=mc88100 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-MC88100 %s
+// CHECK-MC88100: "-cc1"{{.*}} "-triple" "m88k-{{.*}} "-tune-cpu" "mc88100"
+
+// RUN: %clang -target m88k-openbsd -mtune=m88100 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-M88100 %s
+// CHECK-M88100: "-cc1"{{.*}} "-triple" "m88k-{{.*}} "-tune-cpu" "mc88100"
+
+// RUN: %clang -target m88k-openbsd -mtune=mc88110 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-MC88110 %s
+// CHECK-MC88110: "-cc1"{{.*}} "-triple" "m88k-{{.*}} "-tune-cpu" "mc88110"
+
+// RUN: %clang -target m88k-openbsd -mtune=m88110 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-M88110 %s
+// CHECK-M88110: "-cc1"{{.*}} "-triple" "m88k-{{.*}} "-tune-cpu" "mc88110"
+
diff --git a/llvm/lib/Target/M88k/M88k.td b/llvm/lib/Target/M88k/M88k.td index 487e533..80c7dd8 100644 --- a/llvm/lib/Target/M88k/M88k.td +++ b/llvm/lib/Target/M88k/M88k.td @@ -22,6 +22,8 @@ include "llvm/Target/Target.td" def FeatureGraphics : SubtargetFeature<"graphics", "HasGraphics", "true", "has graphics instructions", []>; +def Proc88000 : SubtargetFeature<"mc88000", "M88kProc", "MC88000", + "Generic 88000 processor", []>; def Proc88100 : SubtargetFeature<"mc88100", "M88kProc", "MC88100", "Motorola 88100 processor", []>; def Proc88110 : SubtargetFeature<"mc88110", "M88kProc", "MC88110", @@ -44,6 +46,7 @@ include "M88kSchedule.td" // M88k processors supported. //===----------------------------------------------------------------------===// +def : ProcessorModel<"mc88000", M88100SchedModel, [Proc88000]>; def : ProcessorModel<"mc88100", M88100SchedModel, [Proc88100]>; def : ProcessorModel<"mc88110", M88110SchedModel, [Proc88110]>; diff --git a/llvm/lib/Target/M88k/M88kSubtarget.h b/llvm/lib/Target/M88k/M88kSubtarget.h index 64cbebe..1585973 100644 --- a/llvm/lib/Target/M88k/M88kSubtarget.h +++ b/llvm/lib/Target/M88k/M88kSubtarget.h @@ -37,6 +37,7 @@ class StringRef; class M88kSubtarget : public M88kGenSubtargetInfo { enum M88kProcEnum { None, + MC88000, MC88100, MC88110, }; |