[PATCH] D83778: MIPS: add build time option to disable madd.fmt

YunQiang Su via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 14 08:16:05 PDT 2020


wzssyqa created this revision.
wzssyqa added a reviewer: atanasyan.
Herald added subscribers: llvm-commits, jrtc27, hiraditya, arichardson, mgorny, sdardis.
Herald added a project: LLVM.

MIPS: add build time option to disable madd.fmt

      

Some of MIPS CPU has a buggy madd.fmt/msub.fmt insns, Loongson is
an example.

To support all CPUs for a binary Linux distribution - like Debian,
the only choice is to disable madd.fmt/msub.fmt.

      

So here we add a build time option -DLLVM_DISABLE_MIPS_MADD4.
It does the same thing as the gcc build time option: --with(out)-madd4.

      

If llvm is built with this option, users can still enable/disable
madd.fmt/msub.fmt by runtime option -mmadd4/-mno-madd4.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83778

Files:
  llvm/CMakeLists.txt
  llvm/include/llvm/Config/llvm-config.h.cmake
  llvm/lib/Target/Mips/MipsSubtarget.cpp


Index: llvm/lib/Target/Mips/MipsSubtarget.cpp
===================================================================
--- llvm/lib/Target/Mips/MipsSubtarget.cpp
+++ llvm/lib/Target/Mips/MipsSubtarget.cpp
@@ -91,6 +91,9 @@
   if (MipsArchVersion == MipsDefault)
     MipsArchVersion = Mips32;
 
+  if (hasMips32r6() || hasMips64r6())
+    DisableMadd4 = false;
+
   // Don't even attempt to generate code for MIPS-I and MIPS-V. They have not
   // been tested and currently exist for the integrated assembler only.
   if (MipsArchVersion == Mips1)
@@ -238,6 +241,7 @@
 MipsSubtarget::initializeSubtargetDependencies(StringRef CPU, StringRef FS,
                                                const TargetMachine &TM) {
   StringRef CPUName = MIPS_MC::selectMipsCPU(TM.getTargetTriple(), CPU);
+  SubtargetFeatures Features(FS);
 
   // Parse features string.
   ParseSubtargetFeatures(CPUName, FS);
@@ -260,6 +264,16 @@
     report_fatal_error("64-bit code requested on a subtarget that doesn't "
                        "support it!");
 
+#if LLVM_DISABLE_MIPS_MADD4
+  DisableMadd4 = true;
+#endif
+  for (const std::string &Feature : Features.getFeatures()) {
+    if (Feature == "+nomadd4")
+      DisableMadd4 = true;
+    else if (Feature == "-nomadd4")
+      DisableMadd4 = false;
+  }
+
   return *this;
 }
 
Index: llvm/include/llvm/Config/llvm-config.h.cmake
===================================================================
--- llvm/include/llvm/Config/llvm-config.h.cmake
+++ llvm/include/llvm/Config/llvm-config.h.cmake
@@ -56,6 +56,9 @@
 /* Define if we have the Intel JIT API runtime support library */
 #cmakedefine01 LLVM_USE_INTEL_JITEVENTS
 
+/* Define if wish disable MIPS madd.fmt/msub.fmt instructions by default. */
+#cmakedefine01 LLVM_DISABLE_MIPS_MADD4
+
 /* Define if we have the oprofile JIT-support library */
 #cmakedefine01 LLVM_USE_OPROFILE
 
Index: llvm/CMakeLists.txt
===================================================================
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -462,6 +462,12 @@
   endif()
 endif( LLVM_USE_INTEL_JITEVENTS )
 
+# Loongson has bug on madd.fmt/msub.fmt instructions. gcc has a buildtime option: --without-madd4/--with-madd4
+# Users can still enable/disable madd.fmt/msub.fmt when runtime with option: -mmadd4/-mno-madd4
+option(LLVM_DISABLE_MIPS_MADD4
+	"Disable MIPS madd.fmt/msub.fmt instructions by default."
+  OFF)
+
 option(LLVM_USE_OPROFILE
   "Use opagent JIT interface to inform OProfile about JIT code" OFF)
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83778.277837.patch
Type: text/x-patch
Size: 2495 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200714/779711df/attachment.bin>


More information about the llvm-commits mailing list