[clang] [Sparc] Add flags to enable errata workaround pass for GR712RC and UT700 (PR #104742)

Daniel Cederman via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 20 00:50:42 PDT 2024


https://github.com/doac updated https://github.com/llvm/llvm-project/pull/104742

>From a68dec7b074afdc003c63e721cd384c9c6721610 Mon Sep 17 00:00:00 2001
From: Daniel Cederman <cederman at gaisler.com>
Date: Mon, 19 Aug 2024 08:17:36 +0200
Subject: [PATCH 1/3] [Sparc] Add flags to enable errata workaround pass for
 GR712RC and UT700

This adds the flags -mfix-gr712rc and -mfix-ut700 which enables the
necessary errata workarounds for the GR712RC and UT700 processors.
The functionality enabled by the flag is the same as the functionality
provided by the corresponding GCC flag.
---
 clang/include/clang/Driver/Options.td      |  4 ++++
 clang/lib/Driver/ToolChains/Arch/Sparc.cpp | 13 +++++++++++++
 clang/test/Driver/sparc-fix.c              | 12 ++++++++++++
 3 files changed, 29 insertions(+)
 create mode 100644 clang/test/Driver/sparc-fix.c

diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index cfd9e595c55178..0ef3a2dbd69ae3 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6148,6 +6148,10 @@ def mv8plus : Flag<["-"], "mv8plus">, Group<m_sparc_Features_Group>,
   HelpText<"Enable V8+ mode, allowing use of 64-bit V9 instructions in 32-bit code">;
 def mno_v8plus : Flag<["-"], "mno-v8plus">, Group<m_sparc_Features_Group>,
   HelpText<"Disable V8+ mode">;
+def mfix_gr712rc : Flag<["-"], "mfix-gr712rc">, Group<m_sparc_Features_Group>,
+  HelpText<"Enable workarounds for GR712RC errata">;
+def mfix_ut700 : Flag<["-"], "mfix-ut700">, Group<m_sparc_Features_Group>,
+  HelpText<"Enable workarounds for UT700 errata">;
 foreach i = 1 ... 7 in
   def ffixed_g#i : Flag<["-"], "ffixed-g"#i>, Group<m_sparc_Features_Group>,
     HelpText<"Reserve the G"#i#" register (SPARC only)">;
diff --git a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
index 5a1fedbec06adf..f7f0a265fef68b 100644
--- a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
@@ -264,4 +264,17 @@ void sparc::getSparcTargetFeatures(const Driver &D, const ArgList &Args,
 
   if (Args.hasArg(options::OPT_ffixed_i5))
     Features.push_back("+reserve-i5");
+
+  if (Args.hasArg(options::OPT_mfix_gr712rc)) {
+    Features.push_back("+fix-tn0009");
+    Features.push_back("+fix-tn0011");
+    Features.push_back("+fix-tn0012");
+    Features.push_back("+fix-tn0013");
+  }
+
+  if (Args.hasArg(options::OPT_mfix_ut700)) {
+    Features.push_back("+fix-tn0009");
+    Features.push_back("+fix-tn0010");
+    Features.push_back("+fix-tn0013");
+  }
 }
diff --git a/clang/test/Driver/sparc-fix.c b/clang/test/Driver/sparc-fix.c
new file mode 100644
index 00000000000000..2b4bc4117adb68
--- /dev/null
+++ b/clang/test/Driver/sparc-fix.c
@@ -0,0 +1,12 @@
+// RUN: %clang -target sparc -mfix-gr712rc -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-FIX-GR712RC < %t %s
+// CHECK-FIX-GR712RC: "-target-feature" "+fix-tn0009"
+// CHECK-FIX-GR712RC: "-target-feature" "+fix-tn0011"
+// CHECK-FIX-GR712RC: "-target-feature" "+fix-tn0012"
+// CHECK-FIX-GR712RC: "-target-feature" "+fix-tn0013"
+
+// RUN: %clang -target sparc -mfix-ut700 -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-FIX-UT700 < %t %s
+// CHECK-FIX-UT700: "-target-feature" "+fix-tn0009"
+// CHECK-FIX-UT700: "-target-feature" "+fix-tn0010"
+// CHECK-FIX-UT700: "-target-feature" "+fix-tn0013"

>From a4ee7ebd69db218a1084e44fee35832a169f7c7e Mon Sep 17 00:00:00 2001
From: Daniel Cederman <cederman at gaisler.com>
Date: Tue, 20 Aug 2024 09:46:53 +0200
Subject: [PATCH 2/3] [Sparc] Use --target= instead of -target

---
 clang/test/Driver/sparc-fix.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/test/Driver/sparc-fix.c b/clang/test/Driver/sparc-fix.c
index 2b4bc4117adb68..f2815c721db9b8 100644
--- a/clang/test/Driver/sparc-fix.c
+++ b/clang/test/Driver/sparc-fix.c
@@ -1,11 +1,11 @@
-// RUN: %clang -target sparc -mfix-gr712rc -### %s 2> %t
+// RUN: %clang --target=sparc -mfix-gr712rc -### %s 2> %t
 // RUN: FileCheck --check-prefix=CHECK-FIX-GR712RC < %t %s
 // CHECK-FIX-GR712RC: "-target-feature" "+fix-tn0009"
 // CHECK-FIX-GR712RC: "-target-feature" "+fix-tn0011"
 // CHECK-FIX-GR712RC: "-target-feature" "+fix-tn0012"
 // CHECK-FIX-GR712RC: "-target-feature" "+fix-tn0013"
 
-// RUN: %clang -target sparc -mfix-ut700 -### %s 2> %t
+// RUN: %clang --target=sparc -mfix-ut700 -### %s 2> %t
 // RUN: FileCheck --check-prefix=CHECK-FIX-UT700 < %t %s
 // CHECK-FIX-UT700: "-target-feature" "+fix-tn0009"
 // CHECK-FIX-UT700: "-target-feature" "+fix-tn0010"

>From 2a3d7aa43733908a5e4d498f6b6e1c7f73e5deb7 Mon Sep 17 00:00:00 2001
From: Daniel Cederman <cederman at gaisler.com>
Date: Tue, 20 Aug 2024 09:48:33 +0200
Subject: [PATCH 3/3] [Sparc] Place checks for same target on same line

---
 clang/test/Driver/sparc-fix.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/clang/test/Driver/sparc-fix.c b/clang/test/Driver/sparc-fix.c
index f2815c721db9b8..1f034399ce2245 100644
--- a/clang/test/Driver/sparc-fix.c
+++ b/clang/test/Driver/sparc-fix.c
@@ -1,12 +1,5 @@
-// RUN: %clang --target=sparc -mfix-gr712rc -### %s 2> %t
-// RUN: FileCheck --check-prefix=CHECK-FIX-GR712RC < %t %s
-// CHECK-FIX-GR712RC: "-target-feature" "+fix-tn0009"
-// CHECK-FIX-GR712RC: "-target-feature" "+fix-tn0011"
-// CHECK-FIX-GR712RC: "-target-feature" "+fix-tn0012"
-// CHECK-FIX-GR712RC: "-target-feature" "+fix-tn0013"
+// RUN: %clang --target=sparc -mfix-gr712rc -### %s 2>&1 | FileCheck --check-prefix=GR712RC %s
+// GR712RC: "-target-feature" "+fix-tn0009" "-target-feature" "+fix-tn0011" "-target-feature" "+fix-tn0012" "-target-feature" "+fix-tn0013"
 
-// RUN: %clang --target=sparc -mfix-ut700 -### %s 2> %t
-// RUN: FileCheck --check-prefix=CHECK-FIX-UT700 < %t %s
-// CHECK-FIX-UT700: "-target-feature" "+fix-tn0009"
-// CHECK-FIX-UT700: "-target-feature" "+fix-tn0010"
-// CHECK-FIX-UT700: "-target-feature" "+fix-tn0013"
+// RUN: %clang --target=sparc -mfix-ut700 -### %s 2>&1 | FileCheck --check-prefix=UT700 %s
+// UT700: "-target-feature" "+fix-tn0009" "-target-feature" "+fix-tn0010" "-target-feature" "+fix-tn0013"



More information about the cfe-commits mailing list