[clang] [clang] Support -Wa, options -mmsa and -mno-msa (PR #99615)
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 20 12:03:31 PDT 2024
https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/99615
>From cab152b6306bf486daf478709fe5eaa3a0bb79d2 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 1/2] [clang] Support -Wa, options -mmsa and -mno-msa
---
clang/include/clang/Basic/CodeGenOptions.def | 1 +
clang/include/clang/Driver/Options.td | 4 +++-
clang/lib/Driver/ToolChains/Clang.cpp | 13 ++++++++++++-
clang/test/Driver/mips-msa.c | 19 +++++++++++++++++++
4 files changed, 35 insertions(+), 2 deletions(-)
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 09e892d6d4defe..ecea476abe3232 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -176,6 +176,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/Driver/Options.td b/clang/include/clang/Driver/Options.td
index c66e035a259b3f..625a8303b9bf15 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5383,7 +5383,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 6180c6eeb6f07a..9fd8a0fcf50270 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2556,6 +2556,7 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
bool Crel = false, ExperimentalCrel = false;
bool UseRelaxRelocations = C.getDefaultToolChain().useRelaxRelocations();
bool UseNoExecStack = false;
+ std::optional<bool> Msa;
const char *MipsTargetFeature = nullptr;
StringRef ImplicitIt;
for (const Arg *A :
@@ -2665,7 +2666,14 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
CmdArgs.push_back("-soft-float");
continue;
}
-
+ if (Value == "-mmsa") {
+ Msa = true;
+ continue;
+ }
+ if (Value == "-mno-msa") {
+ Msa = false;
+ continue;
+ }
MipsTargetFeature = llvm::StringSwitch<const char *>(Value)
.Case("-mips1", "+mips1")
.Case("-mips2", "+mips2")
@@ -2685,6 +2693,7 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
.Default(nullptr);
if (MipsTargetFeature)
continue;
+ break;
}
if (Value == "-force_cpusubtype_ALL") {
@@ -2777,6 +2786,8 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
<< "-Wa,--crel" << D.getTargetTriple();
}
}
+ if (Msa && *Msa)
+ CmdArgs.push_back("-mmsa");
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..78ff58288bd8a8
--- /dev/null
+++ b/clang/test/Driver/mips-msa.c
@@ -0,0 +1,19 @@
+// 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: %clang -### -c --target=mips64el-unknown-linux-gnuabi64 \
+// RUN: -Wa,-mno-msa,-mmsa %s -Werror 2>&1 | FileCheck %s --check-prefix=CHECK-MMSA
+
+// RUN: %clang -### -c --target=mips64el-unknown-linux-gnuabi64 \
+// RUN: -Wa,-mmsa,-mno-msa %s -Werror 2>&1 | FileCheck %s --check-prefix=CHECK-NOMMSA
+// CHECK-NOMMSA: "-cc1"
+
+// 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"
>From 6dc51e2f42e3759492c5494c860bc7e1d1a91ea3 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Tue, 20 Aug 2024 12:02:58 -0700
Subject: [PATCH 2/2] Simplify code and test
---
clang/lib/Driver/ToolChains/Clang.cpp | 4 ++--
clang/test/Driver/mips-msa.c | 19 ++++---------------
2 files changed, 6 insertions(+), 17 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 9fd8a0fcf50270..04ef50585f2002 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2556,7 +2556,7 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
bool Crel = false, ExperimentalCrel = false;
bool UseRelaxRelocations = C.getDefaultToolChain().useRelaxRelocations();
bool UseNoExecStack = false;
- std::optional<bool> Msa;
+ bool Msa = false;
const char *MipsTargetFeature = nullptr;
StringRef ImplicitIt;
for (const Arg *A :
@@ -2786,7 +2786,7 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
<< "-Wa,--crel" << D.getTargetTriple();
}
}
- if (Msa && *Msa)
+ if (Msa)
CmdArgs.push_back("-mmsa");
if (!UseRelaxRelocations)
CmdArgs.push_back("-mrelax-relocations=no");
diff --git a/clang/test/Driver/mips-msa.c b/clang/test/Driver/mips-msa.c
index 78ff58288bd8a8..f5f9c228e21294 100644
--- a/clang/test/Driver/mips-msa.c
+++ b/clang/test/Driver/mips-msa.c
@@ -1,19 +1,8 @@
// RUN: %clang -### -c --target=mips64el-unknown-linux-gnuabi64 \
-// RUN: -Wa,-mmsa %s -Werror 2>&1 | FileCheck %s --check-prefix=CHECK-MMSA
+// RUN: -Wa,-mmsa %s -Werror 2>&1 | FileCheck %s --check-prefix=CHECK-MMSA
// CHECK-MMSA: "-cc1" {{.*}}"-mmsa"
// RUN: %clang -### -c --target=mips64el-unknown-linux-gnuabi64 \
-// RUN: -Wa,-mno-msa,-mmsa %s -Werror 2>&1 | FileCheck %s --check-prefix=CHECK-MMSA
-
-// RUN: %clang -### -c --target=mips64el-unknown-linux-gnuabi64 \
-// RUN: -Wa,-mmsa,-mno-msa %s -Werror 2>&1 | FileCheck %s --check-prefix=CHECK-NOMMSA
-// CHECK-NOMMSA: "-cc1"
-
-// 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: -Wa,-mmsa,-mno-msa %s -Werror 2>&1 | FileCheck %s --check-prefix=CHECK-NOMMSA
+// CHECK-NOMMSA: "-cc1"
+// CHECK-NOMMSA-NOT: "-mssa"
More information about the cfe-commits
mailing list