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

via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 19 01:23:45 PDT 2024


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

None

>From 1ef0b65fd7adc7a588de6d818eb1e6ab532a3869 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 |  2 ++
 clang/include/clang/Driver/Options.td        |  8 ++++++--
 clang/lib/CodeGen/BackendUtil.cpp            |  2 ++
 clang/lib/Driver/ToolChains/Clang.cpp        |  4 ++++
 clang/tools/driver/cc1as_main.cpp            | 10 ++++++++++
 llvm/include/llvm/MC/MCTargetOptions.h       |  3 +++
 6 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def
index f671b780bcbeb..1d84be7520422 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -178,6 +178,8 @@ 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(Msa               , 1, 0) ///< Set when -Wa,-mmsa is enabled.
+CODEGENOPT(NoMsa             , 1, 0) ///< Set when -Wa,-mno-msa 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/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 12b20fe04675b..0d5c68fc3a0d0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5337,9 +5337,13 @@ 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, CC1AsOption]>,
+  HelpText<"Enable MSA ASE (MIPS only)">,
+  MarshallingInfoFlag<CodeGenOpts<"Msa">>;
 def mno_msa : Flag<["-"], "mno-msa">, Group<m_mips_Features_Group>,
-  HelpText<"Disable MSA ASE (MIPS only)">;
+  Visibility<[ClangOption, CC1AsOption]>,
+  HelpText<"Disable MSA ASE (MIPS only)">,
+  MarshallingInfoFlag<CodeGenOpts<"NoMsa">>;
 def mmt : Flag<["-"], "mmt">, Group<m_mips_Features_Group>,
   HelpText<"Enable MT ASE (MIPS only)">;
 def mno_mt : Flag<["-"], "mno-mt">, Group<m_mips_Features_Group>,
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index e765bbf637a66..6901a6d88313f 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -463,6 +463,8 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
           ? llvm::MCTargetOptions::DisableDwarfDirectory
           : llvm::MCTargetOptions::EnableDwarfDirectory;
   Options.MCOptions.MCNoExecStack = CodeGenOpts.NoExecStack;
+  Options.MCOptions.MCMsa = CodeGenOpts.Msa;
+  Options.MCOptions.MCNoMsa = CodeGenOpts.NoMsa;
   Options.MCOptions.MCIncrementalLinkerCompatible =
       CodeGenOpts.IncrementalLinkerCompatible;
   Options.MCOptions.MCFatalWarnings = CodeGenOpts.FatalWarnings;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 1fd6fba210042..e4a2d4e84bdca 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2630,6 +2630,10 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
         CmdArgs.push_back("-massembler-no-warn");
       } else if (Value == "--noexecstack") {
         UseNoExecStack = true;
+      } else if (Value == "-mmsa") {
+        CmdArgs.push_back("-mmsa");
+      } else if (Value == "-mno-msa") {
+        CmdArgs.push_back("-mno-msa");
       } else if (Value.starts_with("-compress-debug-sections") ||
                  Value.starts_with("--compress-debug-sections") ||
                  Value == "-nocompress-debug-sections" ||
diff --git a/clang/tools/driver/cc1as_main.cpp b/clang/tools/driver/cc1as_main.cpp
index ec93f092713f5..4bca886714a63 100644
--- a/clang/tools/driver/cc1as_main.cpp
+++ b/clang/tools/driver/cc1as_main.cpp
@@ -168,6 +168,10 @@ struct AssemblerInvocation {
 
   LLVM_PREFERRED_TYPE(bool)
   unsigned Crel : 1;
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned Msa : 1;
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned NoMsa : 1;
 
   /// The name of the relocation model to use.
   std::string RelocationModel;
@@ -211,6 +215,8 @@ struct AssemblerInvocation {
     EmitDwarfUnwind = EmitDwarfUnwindType::Default;
     EmitCompactUnwindNonCanonical = false;
     Crel = false;
+    Msa = 0;
+    NoMsa = 0;
   }
 
   static bool CreateFromArgs(AssemblerInvocation &Res,
@@ -382,6 +388,8 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
   Opts.EmitCompactUnwindNonCanonical =
       Args.hasArg(OPT_femit_compact_unwind_non_canonical);
   Opts.Crel = Args.hasArg(OPT_crel);
+  Opts.Msa = Args.hasArg(OPT_mmsa);
+  Opts.NoMsa = Args.hasArg(OPT_mno_msa);
 
   Opts.AsSecureLogFile = Args.getLastArgValue(OPT_as_secure_log_file);
 
@@ -444,6 +452,8 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
   MCOptions.X86Sse2Avx = Opts.SSE2AVX;
   MCOptions.CompressDebugSections = Opts.CompressDebugSections;
   MCOptions.AsSecureLogFile = Opts.AsSecureLogFile;
+  MCOptions.MCMsa = Opts.Msa;
+  MCOptions.MCNoMsa = Opts.NoMsa;
 
   std::unique_ptr<MCAsmInfo> MAI(
       TheTarget->createMCAsmInfo(*MRI, Opts.Triple, MCOptions));
diff --git a/llvm/include/llvm/MC/MCTargetOptions.h b/llvm/include/llvm/MC/MCTargetOptions.h
index 899299fd15246..fddd9dff8da3a 100644
--- a/llvm/include/llvm/MC/MCTargetOptions.h
+++ b/llvm/include/llvm/MC/MCTargetOptions.h
@@ -107,6 +107,9 @@ class MCTargetOptions {
   // Whether or not to use full register names on PowerPC.
   bool PPCUseFullRegisterNames : 1;
 
+  bool MCMsa : 1;
+  bool MCNoMsa : 1;
+
   MCTargetOptions();
 
   /// getABIName - If this returns a non-empty string this represents the



More information about the cfe-commits mailing list