[clang] [clang] Support -Wa, options -mmsa and -mno-msa (PR #99615)

via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 12 01:53:05 PDT 2024


https://github.com/yingopq updated https://github.com/llvm/llvm-project/pull/99615

>From f8a34c8015269cfc53666e9e28a2cb1290e96e70 Mon Sep 17 00:00:00 2001
From: Ying Huang <ying.huang at oss.cipunited.com>
Date: Fri, 19 Jul 2024 04:19:09 -0400
Subject: [PATCH] [clang] Support -Wa, options -mmsa and -mno-msa

---
 clang/include/clang/Basic/CodeGenOptions.def  |  1 +
 .../clang/Basic/DiagnosticDriverKinds.td      |  3 +++
 clang/include/clang/Driver/Options.td         |  4 +++-
 clang/lib/Driver/ToolChains/Clang.cpp         | 16 +++++++++++++++
 clang/test/Driver/mips-msa.c                  | 20 +++++++++++++++++++
 5 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Driver/mips-msa.c

diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def
index f671b780bcbeb1..898fbcd8e47fde 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -178,6 +178,7 @@ CODEGENOPT(MergeAllConstants , 1, 1) ///< Merge identical constants.
 CODEGENOPT(MergeFunctions    , 1, 0) ///< Set when -fmerge-functions is enabled.
 CODEGENOPT(NoCommon          , 1, 0) ///< Set when -fno-common or C++ is enabled.
 CODEGENOPT(NoExecStack       , 1, 0) ///< Set when -Wa,--noexecstack is enabled.
+CODEGENOPT(MipsMsa           , 1, 0) ///< Set when -Wa,-mmsa is enabled.
 CODEGENOPT(FatalWarnings     , 1, 0) ///< Set when -Wa,--fatal-warnings is
                                      ///< enabled.
 CODEGENOPT(NoWarn            , 1, 0) ///< Set when -Wa,--no-warn is enabled.
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 26a9792e6a6087..04d128d8272955 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -827,4 +827,7 @@ def err_drv_triple_version_invalid : Error<
 
 def warn_missing_include_dirs : Warning<
   "no such include directory: '%0'">, InGroup<MissingIncludeDirs>, DefaultIgnore;
+
+def err_drv_msa_and_nomsa : Error<
+  "-Wa,-mmsa,-mno-msa is meaningless">;
 }
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 12b20fe04675bf..c96338264dc82e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5337,7 +5337,9 @@ def mmadd4 : Flag<["-"], "mmadd4">, Group<m_mips_Features_Group>,
 def mno_madd4 : Flag<["-"], "mno-madd4">, Group<m_mips_Features_Group>,
   HelpText<"Disable the generation of 4-operand madd.s, madd.d and related instructions.">;
 def mmsa : Flag<["-"], "mmsa">, Group<m_mips_Features_Group>,
-  HelpText<"Enable MSA ASE (MIPS only)">;
+  Visibility<[ClangOption, CC1Option, CC1AsOption]>,
+  HelpText<"Enable MSA ASE (MIPS only)">,
+  MarshallingInfoFlag<CodeGenOpts<"MipsMsa">>;
 def mno_msa : Flag<["-"], "mno-msa">, Group<m_mips_Features_Group>,
   HelpText<"Disable MSA ASE (MIPS only)">;
 def mmt : Flag<["-"], "mmt">, Group<m_mips_Features_Group>,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 1fd6fba2100426..277fce65a6799d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2507,6 +2507,8 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
   bool Crel = false, ExperimentalCrel = false;
   bool UseRelaxRelocations = C.getDefaultToolChain().useRelaxRelocations();
   bool UseNoExecStack = false;
+  bool Msa = false;
+  bool NoMsa = false;
   const char *MipsTargetFeature = nullptr;
   StringRef ImplicitIt;
   for (const Arg *A :
@@ -2630,6 +2632,10 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
         CmdArgs.push_back("-massembler-no-warn");
       } else if (Value == "--noexecstack") {
         UseNoExecStack = true;
+      } else if (Value == "-mmsa") {
+        Msa = true;
+      } else if (Value == "-mno-msa") {
+        NoMsa = true;
       } else if (Value.starts_with("-compress-debug-sections") ||
                  Value.starts_with("--compress-debug-sections") ||
                  Value == "-nocompress-debug-sections" ||
@@ -2716,6 +2722,16 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
           << "-Wa,--crel" << D.getTargetTriple();
     }
   }
+  if (Msa) {
+    if (NoMsa)
+      D.Diag(diag::err_drv_msa_and_nomsa);
+    else if (Triple.isMIPS())
+      CmdArgs.push_back("-mmsa");
+    else {
+      D.Diag(diag::err_drv_unsupported_opt_for_target)
+          << "-Wa,-mmsa" << D.getTargetTriple();
+    }
+  }
   if (!UseRelaxRelocations)
     CmdArgs.push_back("-mrelax-relocations=no");
   if (UseNoExecStack)
diff --git a/clang/test/Driver/mips-msa.c b/clang/test/Driver/mips-msa.c
new file mode 100644
index 00000000000000..7d803e8a9fab2c
--- /dev/null
+++ b/clang/test/Driver/mips-msa.c
@@ -0,0 +1,20 @@
+// RUN: %clang -### -c --target=mips64el-unknown-linux-gnuabi64 \
+// RUN:     -Wa,-mmsa %s -Werror 2>&1 | FileCheck %s --check-prefix=CHECK-MMSA
+// CHECK-MMSA: "-cc1" {{.*}}"-mmsa"
+
+// RUN: not %clang -### -c --target=mips64el-unknown-linux-gnuabi64 \
+// RUN:     -Wa,-mmsa,-mno-msa %s -Werror 2>&1 | FileCheck %s --check-prefix=ERR-MSA-AND-NOMSA
+// ERR-MSA-AND-NOMSA: error: -Wa,-mmsa,-mno-msa is meaningless
+
+// RUN: %clang -### -c --target=mips64el-unknown-linux-gnuabi64 \
+// RUN:    -fno-integrated-as -Wa,-mmsa %s -Werror 2>&1 | FileCheck %s --check-prefix=MIPS-MSA
+// MIPS-MSA: as{{(.exe)?}}" "-march" "mips64r2" "-mabi" "64" "-EL" "-KPIC" "-mmsa"
+
+// RUN: %clang -### -c --target=mips64el-unknown-linux-gnuabi64 \
+// RUN:    -fno-integrated-as -Wa,-mno-msa %s -Werror 2>&1 | FileCheck %s --check-prefix=MIPS-NOMSA
+// MIPS-NOMSA: as{{(.exe)?}}"
+// MIPS-NOMSA-NOT: "-mmsa"
+
+// RUN: not %clang -### -c --target=x86_64-unknown-linux-gnu \
+// RUN:     -Wa,-mmsa %s -Werror 2>&1 | FileCheck %s --check-prefix=ERR-MSA
+// ERR-MSA: error: unsupported option '-Wa,-mmsa' for target '{{.*}}'



More information about the cfe-commits mailing list