[clang] [lld] [llvm] [RISCV] Split code that tablegen needs out of RISCVISAInfo. (PR #89684)

2024-04-23 Thread Francesco Petrogalli via cfe-commits

https://github.com/fpetrogalli approved this pull request.


https://github.com/llvm/llvm-project/pull/89684
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lld] [llvm] [RISCV] Split code that tablegen needs out of RISCVISAInfo. (PR #89684)

2024-04-22 Thread Craig Topper via cfe-commits

https://github.com/topperc updated 
https://github.com/llvm/llvm-project/pull/89684

>From c28f21fb93f31661f8313259f0103dc1af44f4a7 Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Mon, 22 Apr 2024 13:19:26 -0700
Subject: [PATCH] [RISCV] Split code that tablegen needs out of RISCVISAInfo.

This introduces a new file, RISCVISAUtils.cpp and moves the
reset of RISCVISAInfo to the TargetParser library.

This will allow us to generate part of RISCVISAInfo.cpp using
tablegen.
---
 clang/lib/Basic/Targets/RISCV.h   |  2 +-
 clang/lib/CodeGen/CodeGenModule.cpp   |  2 +-
 clang/lib/Driver/Driver.cpp   |  2 +-
 clang/lib/Driver/ToolChains/Arch/RISCV.cpp|  2 +-
 clang/lib/Driver/ToolChains/Clang.cpp |  2 +-
 clang/lib/Driver/ToolChains/Flang.cpp |  2 +-
 clang/lib/Driver/ToolChains/Gnu.cpp   |  2 +-
 clang/tools/driver/cc1_main.cpp   |  2 +-
 lld/ELF/Arch/RISCV.cpp|  2 +-
 llvm/include/llvm/Support/RISCVISAUtils.h | 42 
 .../{Support => TargetParser}/RISCVISAInfo.h  | 21 +---
 llvm/lib/Object/ELFObjectFile.cpp |  2 +-
 llvm/lib/Support/CMakeLists.txt   |  2 +-
 llvm/lib/Support/RISCVISAUtils.cpp| 88 +
 .../Target/RISCV/AsmParser/RISCVAsmParser.cpp |  2 +-
 .../RISCV/MCTargetDesc/RISCVBaseInfo.cpp  |  1 -
 .../Target/RISCV/MCTargetDesc/RISCVBaseInfo.h |  2 +-
 .../MCTargetDesc/RISCVTargetStreamer.cpp  |  2 +-
 llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp |  2 +-
 llvm/lib/TargetParser/CMakeLists.txt  |  1 +
 .../RISCVISAInfo.cpp  | 96 +++
 llvm/lib/TargetParser/RISCVTargetParser.cpp   |  2 +-
 llvm/unittests/Support/CMakeLists.txt |  1 -
 llvm/unittests/TargetParser/CMakeLists.txt|  1 +
 .../RISCVISAInfoTest.cpp  | 76 +++
 llvm/utils/TableGen/RISCVTargetDefEmitter.cpp |  6 +-
 26 files changed, 204 insertions(+), 161 deletions(-)
 create mode 100644 llvm/include/llvm/Support/RISCVISAUtils.h
 rename llvm/include/llvm/{Support => TargetParser}/RISCVISAInfo.h (86%)
 create mode 100644 llvm/lib/Support/RISCVISAUtils.cpp
 rename llvm/lib/{Support => TargetParser}/RISCVISAInfo.cpp (93%)
 rename llvm/unittests/{Support => TargetParser}/RISCVISAInfoTest.cpp (93%)

diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h
index 78580b5b1c1063..9fa42e75bbfd14 100644
--- a/clang/lib/Basic/Targets/RISCV.h
+++ b/clang/lib/Basic/Targets/RISCV.h
@@ -16,7 +16,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/Support/Compiler.h"
-#include "llvm/Support/RISCVISAInfo.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 0c447b20cef40d..d085e735ecb443 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -68,9 +68,9 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/xxhash.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/Triple.h"
 #include "llvm/TargetParser/X86TargetParser.h"
 #include 
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 0da92001e08c27..76b7b9fdfb4f9b 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -87,12 +87,12 @@
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Program.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/StringSaver.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Host.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include  // ::getenv
 #include 
 #include 
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 96b3cc3bb8ffb1..2e2bce8494672f 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -15,9 +15,9 @@
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Error.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Host.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
 
 using namespace clang::driver;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 5894a48e0e378b..dc407fd0596f59 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -54,11 +54,11 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "

[clang] [lld] [llvm] [RISCV] Split code that tablegen needs out of RISCVISAInfo. (PR #89684)

2024-04-22 Thread Pengcheng Wang via cfe-commits

https://github.com/wangpc-pp approved this pull request.

LGTM.

https://github.com/llvm/llvm-project/pull/89684
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lld] [llvm] [RISCV] Split code that tablegen needs out of RISCVISAInfo. (PR #89684)

2024-04-22 Thread Craig Topper via cfe-commits

https://github.com/topperc updated 
https://github.com/llvm/llvm-project/pull/89684

>From 7171df42d62ec510627f1fd6526c39c340f2e425 Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Mon, 22 Apr 2024 13:19:26 -0700
Subject: [PATCH 1/2] [RISCV] Split code that tablegen needs out of
 RISCVISAInfo.

This introduces a new file, RISCVISAUtils.cpp and moves the
reset of RISCVISAInfo to the TargetParser library.

This will allow us to generate part of RISCVISAInfo.cpp using
tablegen.
---
 clang/lib/Basic/Targets/RISCV.h   |  2 +-
 clang/lib/CodeGen/CodeGenModule.cpp   |  2 +-
 clang/lib/Driver/Driver.cpp   |  2 +-
 clang/lib/Driver/ToolChains/Arch/RISCV.cpp|  2 +-
 clang/lib/Driver/ToolChains/Clang.cpp |  2 +-
 clang/lib/Driver/ToolChains/Flang.cpp |  2 +-
 clang/lib/Driver/ToolChains/Gnu.cpp   |  2 +-
 clang/tools/driver/cc1_main.cpp   |  2 +-
 lld/ELF/Arch/RISCV.cpp|  2 +-
 llvm/include/llvm/Support/RISCVISAUtils.h | 42 
 .../{Support => TargetParser}/RISCVISAInfo.h  | 21 +---
 llvm/lib/Object/ELFObjectFile.cpp |  2 +-
 llvm/lib/Support/CMakeLists.txt   |  2 +-
 llvm/lib/Support/RISCVISAUtils.cpp| 88 +
 .../Target/RISCV/AsmParser/RISCVAsmParser.cpp |  2 +-
 .../RISCV/MCTargetDesc/RISCVBaseInfo.cpp  |  1 -
 .../Target/RISCV/MCTargetDesc/RISCVBaseInfo.h |  2 +-
 .../MCTargetDesc/RISCVTargetStreamer.cpp  |  2 +-
 llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp |  2 +-
 llvm/lib/TargetParser/CMakeLists.txt  |  1 +
 .../RISCVISAInfo.cpp  | 96 +++
 llvm/lib/TargetParser/RISCVTargetParser.cpp   |  2 +-
 llvm/unittests/Support/RISCVISAInfoTest.cpp   | 74 +++---
 llvm/utils/TableGen/RISCVTargetDefEmitter.cpp |  6 +-
 24 files changed, 202 insertions(+), 159 deletions(-)
 create mode 100644 llvm/include/llvm/Support/RISCVISAUtils.h
 rename llvm/include/llvm/{Support => TargetParser}/RISCVISAInfo.h (86%)
 create mode 100644 llvm/lib/Support/RISCVISAUtils.cpp
 rename llvm/lib/{Support => TargetParser}/RISCVISAInfo.cpp (93%)

diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h
index 78580b5b1c1063..9fa42e75bbfd14 100644
--- a/clang/lib/Basic/Targets/RISCV.h
+++ b/clang/lib/Basic/Targets/RISCV.h
@@ -16,7 +16,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/Support/Compiler.h"
-#include "llvm/Support/RISCVISAInfo.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 0c447b20cef40d..d085e735ecb443 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -68,9 +68,9 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/xxhash.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/Triple.h"
 #include "llvm/TargetParser/X86TargetParser.h"
 #include 
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 0da92001e08c27..76b7b9fdfb4f9b 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -87,12 +87,12 @@
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Program.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/StringSaver.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Host.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include  // ::getenv
 #include 
 #include 
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 96b3cc3bb8ffb1..2e2bce8494672f 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -15,9 +15,9 @@
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Error.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Host.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
 
 using namespace clang::driver;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 5894a48e0e378b..dc407fd0596f59 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -54,11 +54,11 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/YAMLParser.h"
 #include "llvm/TargetParser/ARMTargetParserCommon.h"
 #include "llvm/TargetPa

[clang] [lld] [llvm] [RISCV] Split code that tablegen needs out of RISCVISAInfo. (PR #89684)

2024-04-22 Thread Craig Topper via cfe-commits


@@ -1,12 +1,12 @@
-//===-- RISCVISAInfo.cpp - RISC-V Arch String Parser *- C++ 
-*-===//

topperc wrote:

Only header files usually have this comment

https://github.com/llvm/llvm-project/pull/89684
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lld] [llvm] [RISCV] Split code that tablegen needs out of RISCVISAInfo. (PR #89684)

2024-04-22 Thread Pengcheng Wang via cfe-commits

https://github.com/wangpc-pp commented:

I think this patch doesn't need to be stacked on #89335.

https://github.com/llvm/llvm-project/pull/89684
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lld] [llvm] [RISCV] Split code that tablegen needs out of RISCVISAInfo. (PR #89684)

2024-04-22 Thread Pengcheng Wang via cfe-commits


@@ -1,12 +1,12 @@
-//===-- RISCVISAInfo.cpp - RISC-V Arch String Parser *- C++ 
-*-===//

wangpc-pp wrote:

We shouldn't remove `*- C++ -*` here I think, it's for editors like Emacs.

https://github.com/llvm/llvm-project/pull/89684
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lld] [llvm] [RISCV] Split code that tablegen needs out of RISCVISAInfo. (PR #89684)

2024-04-22 Thread Pengcheng Wang via cfe-commits

https://github.com/wangpc-pp edited 
https://github.com/llvm/llvm-project/pull/89684
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lld] [llvm] [RISCV] Split code that tablegen needs out of RISCVISAInfo. (PR #89684)

2024-04-22 Thread Craig Topper via cfe-commits

https://github.com/topperc updated 
https://github.com/llvm/llvm-project/pull/89684

>From fc51e3821787f1ae8dcb344d4def0ef342ae473b Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Thu, 18 Apr 2024 16:47:31 -0700
Subject: [PATCH 1/8] [RISCV][TableGen] Generate RISCVTargetParser.inc from the
 new RISCVExtension tblgen information.

Instead of using RISCVISAInfo's extension information, use the
extension found in tblgen after #89326.

We still need to use RISCVISAInfo code to get the sorting rules for
the ISA string.

The ISA string we generate now is not quite the same extension we
had before. No implied extensions are included in the generate string
unless they are explicitly listed in RISCVProcessors.td. This primarily
affects Zicsr being implied by F, V implying Zve*, and Zvl*b implying a
smaller Zvl*b. All of these implication should be picked up when the
string is used by the frontend.

The benefit is that we get a more manageable ISA string for humans to
deal with.

This is a step towards generating RISCVISAInfo's extension list from
tblgen.
---
 llvm/utils/TableGen/RISCVTargetDefEmitter.cpp | 43 ++-
 1 file changed, 23 insertions(+), 20 deletions(-)

diff --git a/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp 
b/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
index 62916bd62c0119..4f840b4227e45b 100644
--- a/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
+++ b/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
@@ -17,34 +17,34 @@
 
 using namespace llvm;
 
-using ISAInfoTy = llvm::Expected>;
-
 // We can generate march string from target features as what has been described
 // in RISC-V ISA specification (version 20191213) 'Chapter 27. ISA Extension
 // Naming Conventions'.
 //
 // This is almost the same as RISCVFeatures::parseFeatureBits, except that we
 // get feature name from feature records instead of feature bits.
-static std::string getMArch(const Record &Rec) {
-  std::vector FeatureVector;
+static void printMArch(raw_ostream &OS, const Record &Rec) {
+  std::map,
+   RISCVISAInfo::ExtensionComparator>
+  Extensions;
   unsigned XLen = 32;
 
   // Convert features to FeatureVector.
   for (auto *Feature : Rec.getValueAsListOfDefs("Features")) {
 StringRef FeatureName = Feature->getValueAsString("Name");
-if (llvm::RISCVISAInfo::isSupportedExtensionFeature(FeatureName))
-  FeatureVector.push_back((Twine("+") + FeatureName).str());
-else if (FeatureName == "64bit")
+if (Feature->isSubClassOf("RISCVExtension")) {
+  unsigned Major = Feature->getValueAsInt("MajorVersion");
+  unsigned Minor = Feature->getValueAsInt("MinorVersion");
+  Extensions.try_emplace(FeatureName.str(), Major, Minor);
+} else if (FeatureName == "64bit")
   XLen = 64;
   }
 
-  ISAInfoTy ISAInfo = llvm::RISCVISAInfo::parseFeatures(XLen, FeatureVector);
-  if (!ISAInfo)
-report_fatal_error("Invalid features");
+  OS << "rv" << XLen;
 
-  // RISCVISAInfo::toString will generate a march string with all the 
extensions
-  // we have added to it.
-  return (*ISAInfo)->toString();
+  ListSeparator LS("_");
+  for (auto const &Ext : Extensions)
+OS << LS << Ext.first << Ext.second.first << 'p' << Ext.second.second;
 }
 
 static void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream &OS) {
@@ -54,12 +54,6 @@ static void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream 
&OS) {
 
   // Iterate on all definition records.
   for (const Record *Rec : RK.getAllDerivedDefinitions("RISCVProcessorModel")) 
{
-std::string MArch = Rec->getValueAsString("DefaultMarch").str();
-
-// Compute MArch from features if we don't specify it.
-if (MArch.empty())
-  MArch = getMArch(*Rec);
-
 bool FastScalarUnalignedAccess =
 any_of(Rec->getValueAsListOfDefs("Features"), [&](auto &Feature) {
   return Feature->getValueAsString("Name") == "unaligned-scalar-mem";
@@ -75,7 +69,16 @@ static void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream 
&OS) {
 
 OS << "PROC(" << Rec->getName() << ", "
<< "{\"" << Rec->getValueAsString("Name") << "\"}, "
-   << "{\"" << MArch << "\"}, " << FastUnalignedAccess << ")\n";
+   << "{\"";
+
+StringRef MArch = Rec->getValueAsString("DefaultMarch");
+
+// Compute MArch from features if we don't specify it.
+if (MArch.empty())
+  printMArch(OS, *Rec);
+else
+  OS << MArch;
+OS << "\"}, " << FastUnalignedAccess << ")\n";
   }
   OS << "\n#undef PROC\n";
   OS << "\n";

>From 815a63b99de61b8b1fde5a8c831f63d8810134db Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Thu, 18 Apr 2024 17:10:50 -0700
Subject: [PATCH 2/8] fixup! clang-format

---
 llvm/utils/TableGen/RISCVTargetDefEmitter.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp 
b/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
index 4f840b4227e45b..9862a610bab4d7 100644
--- a/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
+++ b/llvm/utils/TableGen/RISC

[clang] [lld] [llvm] [RISCV] Split code that tablegen needs out of RISCVISAInfo. (PR #89684)

2024-04-22 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 92631a4824a91f3268a5716dd3459df8dc6bfb63 
ee9180aff45af55797d2e97c1b65f9c35b5c8a24 -- 
llvm/include/llvm/Support/RISCVISAUtils.h llvm/lib/Support/RISCVISAUtils.cpp 
clang/lib/Basic/Targets/RISCV.h clang/lib/CodeGen/CodeGenModule.cpp 
clang/lib/Driver/Driver.cpp clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Driver/ToolChains/Flang.cpp 
clang/lib/Driver/ToolChains/Gnu.cpp clang/tools/driver/cc1_main.cpp 
lld/ELF/Arch/RISCV.cpp llvm/lib/Object/ELFObjectFile.cpp 
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp 
llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp 
llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h 
llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp 
llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp 
llvm/lib/TargetParser/RISCVTargetParser.cpp 
llvm/unittests/Support/RISCVISAInfoTest.cpp 
llvm/utils/TableGen/RISCVTargetDefEmitter.cpp 
llvm/include/llvm/TargetParser/RISCVISAInfo.h 
llvm/lib/TargetParser/RISCVISAInfo.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp 
b/llvm/lib/TargetParser/RISCVISAInfo.cpp
index c103449f80..30fb35ce70 100644
--- a/llvm/lib/TargetParser/RISCVISAInfo.cpp
+++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp
@@ -43,9 +43,8 @@ struct RISCVProfile {
 
 } // end anonymous namespace
 
-static const char *RISCVGImplications[] = {
-  "i", "m", "a", "f", "d", "zicsr", "zifencei"
-};
+static const char *RISCVGImplications[] = {"i", "m", "a",   "f",
+   "d", "zicsr", "zifencei"};
 
 // NOTE: This table should be sorted alphabetically by extension name.
 static const RISCVSupportedExtension SupportedExtensions[] = {
@@ -1018,11 +1017,11 @@ Error RISCVISAInfo::checkDependency() {
 
   if ((HasZcmt || Exts.count("zcmp")) && Exts.count("d") &&
   (HasC || Exts.count("zcd")))
-return createStringError(
-errc::invalid_argument,
-Twine("'") + (HasZcmt ? "zcmt" : "zcmp") +
-"' extension is incompatible with '" + (HasC ? "c" : "zcd") +
-"' extension when 'd' extension is enabled");
+return createStringError(errc::invalid_argument,
+ Twine("'") + (HasZcmt ? "zcmt" : "zcmp") +
+ "' extension is incompatible with '" +
+ (HasC ? "c" : "zcd") +
+ "' extension when 'd' extension is enabled");
 
   if (XLen != 32 && Exts.count("zcf"))
 return createStringError(errc::invalid_argument,
@@ -1217,14 +1216,10 @@ struct CombinedExtsEntry {
 };
 
 static constexpr CombinedExtsEntry CombineIntoExts[] = {
-{{"zk"}, {ImpliedExtsZk}},
-{{"zkn"}, {ImpliedExtsZkn}},
-{{"zks"}, {ImpliedExtsZks}},
-{{"zvkn"}, {ImpliedExtsZvkn}},
-{{"zvknc"}, {ImpliedExtsZvknc}},
-{{"zvkng"}, {ImpliedExtsZvkng}},
-{{"zvks"}, {ImpliedExtsZvks}},
-{{"zvksc"}, {ImpliedExtsZvksc}},
+{{"zk"}, {ImpliedExtsZk}},   {{"zkn"}, {ImpliedExtsZkn}},
+{{"zks"}, {ImpliedExtsZks}}, {{"zvkn"}, {ImpliedExtsZvkn}},
+{{"zvknc"}, {ImpliedExtsZvknc}}, {{"zvkng"}, {ImpliedExtsZvkng}},
+{{"zvks"}, {ImpliedExtsZvks}},   {{"zvksc"}, {ImpliedExtsZvksc}},
 {{"zvksg"}, {ImpliedExtsZvksg}},
 };
 

``




https://github.com/llvm/llvm-project/pull/89684
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lld] [llvm] [RISCV] Split code that tablegen needs out of RISCVISAInfo. (PR #89684)

2024-04-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-lld-elf

Author: Craig Topper (topperc)


Changes

This introduces a new file, RISCVISAUtils.cpp and moves the rest of 
RISCVISAInfo to the TargetParser library.

This will allow us to generate part of RISCVISAInfo.cpp using tablegen.

---

Patch is 43.02 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/89684.diff


25 Files Affected:

- (modified) clang/lib/Basic/Targets/RISCV.h (+1-1) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+1-1) 
- (modified) clang/lib/Driver/Driver.cpp (+1-1) 
- (modified) clang/lib/Driver/ToolChains/Arch/RISCV.cpp (+1-1) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+1-1) 
- (modified) clang/lib/Driver/ToolChains/Flang.cpp (+1-1) 
- (modified) clang/lib/Driver/ToolChains/Gnu.cpp (+1-1) 
- (modified) clang/tools/driver/cc1_main.cpp (+1-1) 
- (modified) lld/ELF/Arch/RISCV.cpp (+1-1) 
- (added) llvm/include/llvm/Support/RISCVISAUtils.h (+42) 
- (renamed) llvm/include/llvm/TargetParser/RISCVISAInfo.h (+4-17) 
- (modified) llvm/lib/Object/ELFObjectFile.cpp (+1-1) 
- (modified) llvm/lib/Support/CMakeLists.txt (+1-1) 
- (added) llvm/lib/Support/RISCVISAUtils.cpp (+88) 
- (modified) llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp (+1-1) 
- (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp (-1) 
- (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h (+1-1) 
- (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp (+1-1) 
- (modified) llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp (+1-1) 
- (modified) llvm/lib/TargetParser/CMakeLists.txt (+1) 
- (renamed) llvm/lib/TargetParser/RISCVISAInfo.cpp (+11-85) 
- (modified) llvm/lib/TargetParser/RISCVTargetParser.cpp (+1-1) 
- (added) llvm/test/TableGen/riscv-target-def.td (+96) 
- (modified) llvm/unittests/Support/RISCVISAInfoTest.cpp (+37-37) 
- (modified) llvm/utils/TableGen/RISCVTargetDefEmitter.cpp (+33-24) 


``diff
diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h
index 78580b5b1c1063..9fa42e75bbfd14 100644
--- a/clang/lib/Basic/Targets/RISCV.h
+++ b/clang/lib/Basic/Targets/RISCV.h
@@ -16,7 +16,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/Support/Compiler.h"
-#include "llvm/Support/RISCVISAInfo.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 0c447b20cef40d..d085e735ecb443 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -68,9 +68,9 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/xxhash.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/Triple.h"
 #include "llvm/TargetParser/X86TargetParser.h"
 #include 
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 0da92001e08c27..76b7b9fdfb4f9b 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -87,12 +87,12 @@
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Program.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/StringSaver.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Host.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include  // ::getenv
 #include 
 #include 
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 96b3cc3bb8ffb1..2e2bce8494672f 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -15,9 +15,9 @@
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Error.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Host.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
 
 using namespace clang::driver;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index f8a81ee8ab56bc..e43da1e78d9ef5 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -54,11 +54,11 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/YAMLParser.h"
 #include "llvm/TargetParser/ARMTargetParserCommon.h"
 #include "llvm/TargetParser/Host.h"
 #include "llvm/TargetParser/LoongArchTargetParser.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
 #include 
 
diff --git a/clang/lib/Driver/ToolCha

[clang] [lld] [llvm] [RISCV] Split code that tablegen needs out of RISCVISAInfo. (PR #89684)

2024-04-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Craig Topper (topperc)


Changes

This introduces a new file, RISCVISAUtils.cpp and moves the rest of 
RISCVISAInfo to the TargetParser library.

This will allow us to generate part of RISCVISAInfo.cpp using tablegen.

---

Patch is 43.02 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/89684.diff


25 Files Affected:

- (modified) clang/lib/Basic/Targets/RISCV.h (+1-1) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+1-1) 
- (modified) clang/lib/Driver/Driver.cpp (+1-1) 
- (modified) clang/lib/Driver/ToolChains/Arch/RISCV.cpp (+1-1) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+1-1) 
- (modified) clang/lib/Driver/ToolChains/Flang.cpp (+1-1) 
- (modified) clang/lib/Driver/ToolChains/Gnu.cpp (+1-1) 
- (modified) clang/tools/driver/cc1_main.cpp (+1-1) 
- (modified) lld/ELF/Arch/RISCV.cpp (+1-1) 
- (added) llvm/include/llvm/Support/RISCVISAUtils.h (+42) 
- (renamed) llvm/include/llvm/TargetParser/RISCVISAInfo.h (+4-17) 
- (modified) llvm/lib/Object/ELFObjectFile.cpp (+1-1) 
- (modified) llvm/lib/Support/CMakeLists.txt (+1-1) 
- (added) llvm/lib/Support/RISCVISAUtils.cpp (+88) 
- (modified) llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp (+1-1) 
- (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp (-1) 
- (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h (+1-1) 
- (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp (+1-1) 
- (modified) llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp (+1-1) 
- (modified) llvm/lib/TargetParser/CMakeLists.txt (+1) 
- (renamed) llvm/lib/TargetParser/RISCVISAInfo.cpp (+11-85) 
- (modified) llvm/lib/TargetParser/RISCVTargetParser.cpp (+1-1) 
- (added) llvm/test/TableGen/riscv-target-def.td (+96) 
- (modified) llvm/unittests/Support/RISCVISAInfoTest.cpp (+37-37) 
- (modified) llvm/utils/TableGen/RISCVTargetDefEmitter.cpp (+33-24) 


``diff
diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h
index 78580b5b1c1063..9fa42e75bbfd14 100644
--- a/clang/lib/Basic/Targets/RISCV.h
+++ b/clang/lib/Basic/Targets/RISCV.h
@@ -16,7 +16,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/Support/Compiler.h"
-#include "llvm/Support/RISCVISAInfo.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 0c447b20cef40d..d085e735ecb443 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -68,9 +68,9 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/xxhash.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/Triple.h"
 #include "llvm/TargetParser/X86TargetParser.h"
 #include 
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 0da92001e08c27..76b7b9fdfb4f9b 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -87,12 +87,12 @@
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Program.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/StringSaver.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Host.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include  // ::getenv
 #include 
 #include 
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 96b3cc3bb8ffb1..2e2bce8494672f 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -15,9 +15,9 @@
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Error.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Host.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
 
 using namespace clang::driver;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index f8a81ee8ab56bc..e43da1e78d9ef5 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -54,11 +54,11 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/YAMLParser.h"
 #include "llvm/TargetParser/ARMTargetParserCommon.h"
 #include "llvm/TargetParser/Host.h"
 #include "llvm/TargetParser/LoongArchTargetParser.h"
+#include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
 #include 
 
diff --git a/clang/lib/Driver/ToolChain

[clang] [lld] [llvm] [RISCV] Split code that tablegen needs out of RISCVISAInfo. (PR #89684)

2024-04-22 Thread Craig Topper via cfe-commits

https://github.com/topperc created 
https://github.com/llvm/llvm-project/pull/89684

This introduces a new file, RISCVISAUtils.cpp and moves the rest of 
RISCVISAInfo to the TargetParser library.

This will allow us to generate part of RISCVISAInfo.cpp using tablegen.

>From fc51e3821787f1ae8dcb344d4def0ef342ae473b Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Thu, 18 Apr 2024 16:47:31 -0700
Subject: [PATCH 1/7] [RISCV][TableGen] Generate RISCVTargetParser.inc from the
 new RISCVExtension tblgen information.

Instead of using RISCVISAInfo's extension information, use the
extension found in tblgen after #89326.

We still need to use RISCVISAInfo code to get the sorting rules for
the ISA string.

The ISA string we generate now is not quite the same extension we
had before. No implied extensions are included in the generate string
unless they are explicitly listed in RISCVProcessors.td. This primarily
affects Zicsr being implied by F, V implying Zve*, and Zvl*b implying a
smaller Zvl*b. All of these implication should be picked up when the
string is used by the frontend.

The benefit is that we get a more manageable ISA string for humans to
deal with.

This is a step towards generating RISCVISAInfo's extension list from
tblgen.
---
 llvm/utils/TableGen/RISCVTargetDefEmitter.cpp | 43 ++-
 1 file changed, 23 insertions(+), 20 deletions(-)

diff --git a/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp 
b/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
index 62916bd62c0119..4f840b4227e45b 100644
--- a/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
+++ b/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
@@ -17,34 +17,34 @@
 
 using namespace llvm;
 
-using ISAInfoTy = llvm::Expected>;
-
 // We can generate march string from target features as what has been described
 // in RISC-V ISA specification (version 20191213) 'Chapter 27. ISA Extension
 // Naming Conventions'.
 //
 // This is almost the same as RISCVFeatures::parseFeatureBits, except that we
 // get feature name from feature records instead of feature bits.
-static std::string getMArch(const Record &Rec) {
-  std::vector FeatureVector;
+static void printMArch(raw_ostream &OS, const Record &Rec) {
+  std::map,
+   RISCVISAInfo::ExtensionComparator>
+  Extensions;
   unsigned XLen = 32;
 
   // Convert features to FeatureVector.
   for (auto *Feature : Rec.getValueAsListOfDefs("Features")) {
 StringRef FeatureName = Feature->getValueAsString("Name");
-if (llvm::RISCVISAInfo::isSupportedExtensionFeature(FeatureName))
-  FeatureVector.push_back((Twine("+") + FeatureName).str());
-else if (FeatureName == "64bit")
+if (Feature->isSubClassOf("RISCVExtension")) {
+  unsigned Major = Feature->getValueAsInt("MajorVersion");
+  unsigned Minor = Feature->getValueAsInt("MinorVersion");
+  Extensions.try_emplace(FeatureName.str(), Major, Minor);
+} else if (FeatureName == "64bit")
   XLen = 64;
   }
 
-  ISAInfoTy ISAInfo = llvm::RISCVISAInfo::parseFeatures(XLen, FeatureVector);
-  if (!ISAInfo)
-report_fatal_error("Invalid features");
+  OS << "rv" << XLen;
 
-  // RISCVISAInfo::toString will generate a march string with all the 
extensions
-  // we have added to it.
-  return (*ISAInfo)->toString();
+  ListSeparator LS("_");
+  for (auto const &Ext : Extensions)
+OS << LS << Ext.first << Ext.second.first << 'p' << Ext.second.second;
 }
 
 static void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream &OS) {
@@ -54,12 +54,6 @@ static void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream 
&OS) {
 
   // Iterate on all definition records.
   for (const Record *Rec : RK.getAllDerivedDefinitions("RISCVProcessorModel")) 
{
-std::string MArch = Rec->getValueAsString("DefaultMarch").str();
-
-// Compute MArch from features if we don't specify it.
-if (MArch.empty())
-  MArch = getMArch(*Rec);
-
 bool FastScalarUnalignedAccess =
 any_of(Rec->getValueAsListOfDefs("Features"), [&](auto &Feature) {
   return Feature->getValueAsString("Name") == "unaligned-scalar-mem";
@@ -75,7 +69,16 @@ static void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream 
&OS) {
 
 OS << "PROC(" << Rec->getName() << ", "
<< "{\"" << Rec->getValueAsString("Name") << "\"}, "
-   << "{\"" << MArch << "\"}, " << FastUnalignedAccess << ")\n";
+   << "{\"";
+
+StringRef MArch = Rec->getValueAsString("DefaultMarch");
+
+// Compute MArch from features if we don't specify it.
+if (MArch.empty())
+  printMArch(OS, *Rec);
+else
+  OS << MArch;
+OS << "\"}, " << FastUnalignedAccess << ")\n";
   }
   OS << "\n#undef PROC\n";
   OS << "\n";

>From 815a63b99de61b8b1fde5a8c831f63d8810134db Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Thu, 18 Apr 2024 17:10:50 -0700
Subject: [PATCH 2/7] fixup! clang-format

---
 llvm/utils/TableGen/RISCVTargetDefEmitter.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/llvm/utils/TableGen/RISCVTargetD