From: Jack Carter <jack.carter@imgtec.com>
Date: Mon, 12 Aug 2013 17:20:29 +0000 (+0000)
Subject: [Mips] MSA frontend option support
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c613b67f4f3e5d11d6af6426fd9b8b6a197d2b6b;p=clang

[Mips] MSA frontend option support

This patch adds -mmsa and -mno-msa to the options supported by
clang to enable and disable support for MSA.

When MSA is enabled, a predefined macro '__mips_msa' is defined to 1.

Patch by Daniel Sanders


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188184 91177308-0d34-0410-b5e6-96231b3b80d8
---

diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td
index ff48369d08..ffe30a862b 100644
--- a/include/clang/Driver/Options.td
+++ b/include/clang/Driver/Options.td
@@ -1042,6 +1042,10 @@ def mdspr2 : Flag<["-"], "mdspr2">, Group<m_Group>;
 def mno_dspr2 : Flag<["-"], "mno-dspr2">, Group<m_Group>;
 def msingle_float : Flag<["-"], "msingle-float">, Group<m_Group>;
 def mdouble_float : Flag<["-"], "mdouble-float">, Group<m_Group>;
+def mmsa : Flag<["-"], "mmsa">, Group<m_Group>,
+  HelpText<"Enable MSA ASE on MIPS processors">, Flags<[HelpHidden]>;
+def mno_msa : Flag<["-"], "mno-msa">, Group<m_Group>,
+  HelpText<"Disable MSA ASE on MIPS processors">, Flags<[HelpHidden]>;
 def mips32 : Flag<["-"], "mips32">, Group<mips_CPUs_Group>,
   HelpText<"Equivalent to -march=mips32">, Flags<[HelpHidden]>;
 def mips32r2 : Flag<["-"], "mips32r2">, Group<mips_CPUs_Group>,
diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp
index 718f3bb223..4537717da0 100644
--- a/lib/Basic/Targets.cpp
+++ b/lib/Basic/Targets.cpp
@@ -4530,6 +4530,7 @@ class MipsTargetInfoBase : public TargetInfo {
   enum DspRevEnum {
     NoDSP, DSP1, DSP2
   } DspRev;
+  bool HasMSA;
 
 protected:
   std::string ABI;
@@ -4538,7 +4539,8 @@ public:
   MipsTargetInfoBase(const llvm::Triple &Triple, const std::string &ABIStr,
                      const std::string &CPUStr)
       : TargetInfo(Triple), CPU(CPUStr), IsMips16(false), IsMicromips(false),
-        IsSingleFloat(false), FloatABI(HardFloat), DspRev(NoDSP), ABI(ABIStr) {}
+        IsSingleFloat(false), FloatABI(HardFloat), DspRev(NoDSP),
+        HasMSA(false), ABI(ABIStr) {}
 
   virtual const char *getABI() const { return ABI.c_str(); }
   virtual bool setABI(const std::string &Name) = 0;
@@ -4589,6 +4591,9 @@ public:
       break;
     }
 
+    if (HasMSA)
+      Builder.defineMacro("__mips_msa", Twine(1));
+
     Builder.defineMacro("_MIPS_SZPTR", Twine(getPointerWidth(0)));
     Builder.defineMacro("_MIPS_SZINT", Twine(getIntWidth()));
     Builder.defineMacro("_MIPS_SZLONG", Twine(getLongWidth()));
@@ -4665,7 +4670,8 @@ public:
         Name == "mips32" || Name == "mips32r2" ||
         Name == "mips64" || Name == "mips64r2" ||
         Name == "mips16" || Name == "micromips" ||
-        Name == "dsp" || Name == "dspr2") {
+        Name == "dsp" || Name == "dspr2" ||
+        Name == "msa") {
       Features[Name] = Enabled;
       return true;
     } else if (Name == "32") {
@@ -4699,6 +4705,8 @@ public:
         DspRev = std::max(DspRev, DSP1);
       else if (*it == "+dspr2")
         DspRev = std::max(DspRev, DSP2);
+      else if (*it == "+msa")
+        HasMSA = true;
     }
 
     // Remove front-end specific option.
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 510575b395..ee75635f45 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -1023,6 +1023,9 @@ void Clang::AddMIPSTargetArgs(const ArgList &Args,
   AddTargetFeature(Args, CmdArgs,
                    options::OPT_mdspr2, options::OPT_mno_dspr2,
                    "dspr2");
+  AddTargetFeature(Args, CmdArgs,
+                   options::OPT_mmsa, options::OPT_mno_msa,
+                   "msa");
 
   if (Arg *A = Args.getLastArg(options::OPT_mxgot, options::OPT_mno_xgot)) {
     if (A->getOption().matches(options::OPT_mxgot)) {
diff --git a/test/Driver/mips-features.c b/test/Driver/mips-features.c
index ffa4dcd5aa..8de26d4cbc 100644
--- a/test/Driver/mips-features.c
+++ b/test/Driver/mips-features.c
@@ -48,6 +48,18 @@
 // RUN:   | FileCheck --check-prefix=CHECK-NOMDSPR2 %s
 // CHECK-NOMDSPR2: "-target-feature" "-dspr2"
 //
+// -mmsa
+// RUN: %clang -target mips-linux-gnu -### -c %s \
+// RUN:     -mno-msa -mmsa 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MMSA %s
+// CHECK-MMSA: "-target-feature" "+msa"
+//
+// -mno-msa
+// RUN: %clang -target mips-linux-gnu -### -c %s \
+// RUN:     -mmsa -mno-msa 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOMMSA %s
+// CHECK-NOMMSA: "-target-feature" "-msa"
+//
 // -mxgot
 // RUN: %clang -target mips-linux-gnu -### -c %s \
 // RUN:     -mno-xgot -mxgot 2>&1 \
diff --git a/test/Preprocessor/init.c b/test/Preprocessor/init.c
index fa5589c935..f25f3cdd92 100644
--- a/test/Preprocessor/init.c
+++ b/test/Preprocessor/init.c
@@ -1224,6 +1224,11 @@
 // MIPS-DSPR2:#define __mips_dsp_rev 2
 // MIPS-DSPR2:#define __mips_dspr2 1
 //
+// RUN: %clang_cc1 -target-feature +msa \
+// RUN:   -E -dM -triple=mips-none-none < /dev/null \
+// RUN:   | FileCheck -check-prefix MIPS-MSA %s
+// MIPS-MSA:#define __mips_msa 1
+//
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=msp430-none-none < /dev/null | FileCheck -check-prefix MSP430 %s
 //
 // MSP430:#define MSP430 1