[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-18 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 created 
https://github.com/llvm/llvm-project/pull/66715

Enables summary descriptions along with the names of the feature.
Descriptions here are simply looked up via the available llvm tablegen data.

The full prints from CLI are here: 
[aarch64-info.txt.gz](https://github.com/llvm/llvm-project/files/12653941/aarch64-info.txt.gz)
 , 
[arm-info.txt.gz](https://github.com/llvm/llvm-project/files/12653942/arm-info.txt.gz)
 , 
[riscv-info.txt.gz](https://github.com/llvm/llvm-project/files/12653943/riscv-info.txt.gz)

---

Cc @DavidSpickett
As a discussion: 
https://github.com/llvm/llvm-project/pull/66586#issuecomment-1723311672

>From f81597b89207a534deec926c7af8ec64dd81c118 Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Tue, 19 Sep 2023 01:26:28 +0300
Subject: [PATCH] [clang] Enable descriptions for --print-supported-extensions

---
 clang/tools/driver/cc1_main.cpp   | 14 ++---
 llvm/include/llvm/MC/MCSubtargetInfo.h|  7 +++
 llvm/include/llvm/Support/RISCVISAInfo.h  |  2 +-
 .../llvm/TargetParser/AArch64TargetParser.h   |  3 ++-
 .../llvm/TargetParser/ARMTargetParser.h   |  3 ++-
 llvm/lib/Support/RISCVISAInfo.cpp | 21 +--
 llvm/lib/TargetParser/AArch64TargetParser.cpp | 13 
 llvm/lib/TargetParser/ARMTargetParser.cpp | 12 +++
 llvm/unittests/Support/RISCVISAInfoTest.cpp   |  4 +++-
 .../TargetParser/TargetParserTest.cpp |  7 +--
 10 files changed, 63 insertions(+), 23 deletions(-)

diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index f0d7b5c3889dc1f..923e43491a06842 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -28,6 +28,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/LinkAllPasses.h"
+#include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -198,13 +199,20 @@ static int PrintSupportedExtensions(std::string 
TargetStr) {
   std::unique_ptr TheTargetMachine(
   TheTarget->createTargetMachine(TargetStr, "", "", Options, 
std::nullopt));
   const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
 
+  std::map llvmDescMap;
+  for (const llvm::SubtargetFeatureKV &feature : Features) {
+llvmDescMap.insert(std::make_pair(feature.Key, feature.Desc));
+  }
   if (MachineTriple.isRISCV())
-llvm::riscvExtensionsHelp();
+llvm::riscvExtensionsHelp(llvmDescMap);
   else if (MachineTriple.isAArch64())
-llvm::AArch64::PrintSupportedExtensions();
+llvm::AArch64::PrintSupportedExtensions(llvmDescMap);
   else if (MachineTriple.isARM())
-llvm::ARM::PrintSupportedExtensions();
+llvm::ARM::PrintSupportedExtensions(llvmDescMap);
   else {
 // The option was already checked in Driver::HandleImmediateArgs,
 // so we do not expect to get here if we are not a supported architecture.
diff --git a/llvm/include/llvm/MC/MCSubtargetInfo.h 
b/llvm/include/llvm/MC/MCSubtargetInfo.h
index c1533ac8d0059f5..45c58988985e638 100644
--- a/llvm/include/llvm/MC/MCSubtargetInfo.h
+++ b/llvm/include/llvm/MC/MCSubtargetInfo.h
@@ -230,10 +230,17 @@ class MCSubtargetInfo {
 return Found != ProcDesc.end() && StringRef(Found->Key) == CPU;
   }
 
+  /// Return processor descriptions.
   ArrayRef getAllProcessorDescriptions() const {
 return ProcDesc;
   }
 
+  /// Return processor features.
+  ArrayRef getAllProcessorFeatures() const {
+return ProcFeatures;
+  }
+
+
   virtual unsigned getHwMode() const { return 0; }
 
   /// Return the cache size in bytes for the given level of cache.
diff --git a/llvm/include/llvm/Support/RISCVISAInfo.h 
b/llvm/include/llvm/Support/RISCVISAInfo.h
index 9092fe5c272a994..98c2cd84fd3230b 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -22,7 +22,7 @@ struct RISCVExtensionInfo {
   unsigned MinorVersion;
 };
 
-void riscvExtensionsHelp();
+void riscvExtensionsHelp(std::map llvmDescMap);
 
 class RISCVISAInfo {
 public:
diff --git a/llvm/include/llvm/TargetParser/AArch64TargetParser.h 
b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
index 190f482044083c0..e050f840fd0a483 100644
--- a/llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -19,6 +19,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/VersionTuple.h"
 #include 
+#include 
 #include 
 
 namespace llvm {
@@ -663,7 +664,7 @@ bool isX18ReservedByDefault(const Triple &TT);
 // themselves, they are sequential (0, 1, 2, 3, ...).
 uint64_t getCpuSupportsMask(ArrayRef FeatureStrs);
 
-void PrintSupportedExtensions();
+void PrintSupportedExtensions(std::map  llvmDescMap);
 
 } // namesp

[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-18 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66715

>From 671cbe3bbb0d201d6d938dbc0e2993b074dd1001 Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Tue, 19 Sep 2023 02:13:19 +0300
Subject: [PATCH] [clang] Enable descriptions for --print-supported-extensions

---
 clang/tools/driver/cc1_main.cpp   | 15 ++---
 llvm/include/llvm/MC/MCSubtargetInfo.h|  7 +++
 llvm/include/llvm/Support/RISCVISAInfo.h  |  2 +-
 .../llvm/TargetParser/AArch64TargetParser.h   |  3 ++-
 .../llvm/TargetParser/ARMTargetParser.h   |  3 ++-
 llvm/lib/Support/RISCVISAInfo.cpp | 21 +--
 llvm/lib/TargetParser/AArch64TargetParser.cpp | 16 ++
 llvm/lib/TargetParser/ARMTargetParser.cpp | 15 +
 llvm/unittests/Support/RISCVISAInfoTest.cpp   |  4 +++-
 .../TargetParser/TargetParserTest.cpp |  7 +--
 10 files changed, 70 insertions(+), 23 deletions(-)

diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index f0d7b5c3889dc1f..a963324705db92d 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -28,6 +28,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/LinkAllPasses.h"
+#include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -198,13 +199,21 @@ static int PrintSupportedExtensions(std::string 
TargetStr) {
   std::unique_ptr TheTargetMachine(
   TheTarget->createTargetMachine(TargetStr, "", "", Options, 
std::nullopt));
   const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  std::map llvmDescMap;
+  for (const llvm::SubtargetFeatureKV &feature : Features) {
+llvmDescMap.insert(std::make_pair(feature.Key, feature.Desc));
+  }
 
   if (MachineTriple.isRISCV())
-llvm::riscvExtensionsHelp();
+llvm::riscvExtensionsHelp(llvmDescMap);
   else if (MachineTriple.isAArch64())
-llvm::AArch64::PrintSupportedExtensions();
+llvm::AArch64::PrintSupportedExtensions(llvmDescMap);
   else if (MachineTriple.isARM())
-llvm::ARM::PrintSupportedExtensions();
+llvm::ARM::PrintSupportedExtensions(llvmDescMap);
   else {
 // The option was already checked in Driver::HandleImmediateArgs,
 // so we do not expect to get here if we are not a supported architecture.
diff --git a/llvm/include/llvm/MC/MCSubtargetInfo.h 
b/llvm/include/llvm/MC/MCSubtargetInfo.h
index c1533ac8d0059f5..45c58988985e638 100644
--- a/llvm/include/llvm/MC/MCSubtargetInfo.h
+++ b/llvm/include/llvm/MC/MCSubtargetInfo.h
@@ -230,10 +230,17 @@ class MCSubtargetInfo {
 return Found != ProcDesc.end() && StringRef(Found->Key) == CPU;
   }
 
+  /// Return processor descriptions.
   ArrayRef getAllProcessorDescriptions() const {
 return ProcDesc;
   }
 
+  /// Return processor features.
+  ArrayRef getAllProcessorFeatures() const {
+return ProcFeatures;
+  }
+
+
   virtual unsigned getHwMode() const { return 0; }
 
   /// Return the cache size in bytes for the given level of cache.
diff --git a/llvm/include/llvm/Support/RISCVISAInfo.h 
b/llvm/include/llvm/Support/RISCVISAInfo.h
index 9092fe5c272a994..1555f2f9909983e 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -22,7 +22,7 @@ struct RISCVExtensionInfo {
   unsigned MinorVersion;
 };
 
-void riscvExtensionsHelp();
+void riscvExtensionsHelp(std::map llvmDescMap);
 
 class RISCVISAInfo {
 public:
diff --git a/llvm/include/llvm/TargetParser/AArch64TargetParser.h 
b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
index 190f482044083c0..e050f840fd0a483 100644
--- a/llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -19,6 +19,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/VersionTuple.h"
 #include 
+#include 
 #include 
 
 namespace llvm {
@@ -663,7 +664,7 @@ bool isX18ReservedByDefault(const Triple &TT);
 // themselves, they are sequential (0, 1, 2, 3, ...).
 uint64_t getCpuSupportsMask(ArrayRef FeatureStrs);
 
-void PrintSupportedExtensions();
+void PrintSupportedExtensions(std::map  llvmDescMap);
 
 } // namespace AArch64
 } // namespace llvm
diff --git a/llvm/include/llvm/TargetParser/ARMTargetParser.h 
b/llvm/include/llvm/TargetParser/ARMTargetParser.h
index 37a358d1fa415c9..dbc10c8e28c076c 100644
--- a/llvm/include/llvm/TargetParser/ARMTargetParser.h
+++ b/llvm/include/llvm/TargetParser/ARMTargetParser.h
@@ -17,6 +17,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/ARMBuildAttributes.h"
 #include "llvm/TargetParser/ARMTargetParserCommon.h"
+#include 
 #include 
 
 namespace llvm {
@@ -259,7 +260,7 @@ StringRef computeDefaultTargetABI(const Triple &TT, 
S

[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-18 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66715

>From 231c93881e7719b447db3f15a37ad6cecede3be3 Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Tue, 19 Sep 2023 02:59:40 +0300
Subject: [PATCH] [clang] Enable descriptions for --print-supported-extensions

---
 clang/tools/driver/cc1_main.cpp   | 15 ++---
 llvm/include/llvm/MC/MCSubtargetInfo.h|  7 +++
 llvm/include/llvm/Support/RISCVISAInfo.h  |  2 +-
 .../llvm/TargetParser/AArch64TargetParser.h   |  3 ++-
 .../llvm/TargetParser/ARMTargetParser.h   |  3 ++-
 llvm/lib/Support/RISCVISAInfo.cpp | 21 +--
 llvm/lib/TargetParser/AArch64TargetParser.cpp | 16 ++
 llvm/lib/TargetParser/ARMTargetParser.cpp | 15 +
 llvm/unittests/Support/RISCVISAInfoTest.cpp   |  4 +++-
 .../TargetParser/TargetParserTest.cpp |  7 +--
 10 files changed, 70 insertions(+), 23 deletions(-)

diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index f0d7b5c3889dc1f..a963324705db92d 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -28,6 +28,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/LinkAllPasses.h"
+#include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -198,13 +199,21 @@ static int PrintSupportedExtensions(std::string 
TargetStr) {
   std::unique_ptr TheTargetMachine(
   TheTarget->createTargetMachine(TargetStr, "", "", Options, 
std::nullopt));
   const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  std::map llvmDescMap;
+  for (const llvm::SubtargetFeatureKV &feature : Features) {
+llvmDescMap.insert(std::make_pair(feature.Key, feature.Desc));
+  }
 
   if (MachineTriple.isRISCV())
-llvm::riscvExtensionsHelp();
+llvm::riscvExtensionsHelp(llvmDescMap);
   else if (MachineTriple.isAArch64())
-llvm::AArch64::PrintSupportedExtensions();
+llvm::AArch64::PrintSupportedExtensions(llvmDescMap);
   else if (MachineTriple.isARM())
-llvm::ARM::PrintSupportedExtensions();
+llvm::ARM::PrintSupportedExtensions(llvmDescMap);
   else {
 // The option was already checked in Driver::HandleImmediateArgs,
 // so we do not expect to get here if we are not a supported architecture.
diff --git a/llvm/include/llvm/MC/MCSubtargetInfo.h 
b/llvm/include/llvm/MC/MCSubtargetInfo.h
index c1533ac8d0059f5..45c58988985e638 100644
--- a/llvm/include/llvm/MC/MCSubtargetInfo.h
+++ b/llvm/include/llvm/MC/MCSubtargetInfo.h
@@ -230,10 +230,17 @@ class MCSubtargetInfo {
 return Found != ProcDesc.end() && StringRef(Found->Key) == CPU;
   }
 
+  /// Return processor descriptions.
   ArrayRef getAllProcessorDescriptions() const {
 return ProcDesc;
   }
 
+  /// Return processor features.
+  ArrayRef getAllProcessorFeatures() const {
+return ProcFeatures;
+  }
+
+
   virtual unsigned getHwMode() const { return 0; }
 
   /// Return the cache size in bytes for the given level of cache.
diff --git a/llvm/include/llvm/Support/RISCVISAInfo.h 
b/llvm/include/llvm/Support/RISCVISAInfo.h
index 9092fe5c272a994..1555f2f9909983e 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -22,7 +22,7 @@ struct RISCVExtensionInfo {
   unsigned MinorVersion;
 };
 
-void riscvExtensionsHelp();
+void riscvExtensionsHelp(std::map llvmDescMap);
 
 class RISCVISAInfo {
 public:
diff --git a/llvm/include/llvm/TargetParser/AArch64TargetParser.h 
b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
index 190f482044083c0..0d4b5e5a18458c7 100644
--- a/llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -19,6 +19,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/VersionTuple.h"
 #include 
+#include 
 #include 
 
 namespace llvm {
@@ -663,7 +664,7 @@ bool isX18ReservedByDefault(const Triple &TT);
 // themselves, they are sequential (0, 1, 2, 3, ...).
 uint64_t getCpuSupportsMask(ArrayRef FeatureStrs);
 
-void PrintSupportedExtensions();
+void PrintSupportedExtensions(std::map llvmDescMap);
 
 } // namespace AArch64
 } // namespace llvm
diff --git a/llvm/include/llvm/TargetParser/ARMTargetParser.h 
b/llvm/include/llvm/TargetParser/ARMTargetParser.h
index 37a358d1fa415c9..f3472b1e68233ee 100644
--- a/llvm/include/llvm/TargetParser/ARMTargetParser.h
+++ b/llvm/include/llvm/TargetParser/ARMTargetParser.h
@@ -17,6 +17,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/ARMBuildAttributes.h"
 #include "llvm/TargetParser/ARMTargetParserCommon.h"
+#include 
 #include 
 
 namespace llvm {
@@ -259,7 +260,7 @@ StringRef computeDefaultTargetABI(const Triple &TT, 
St

[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits


@@ -210,24 +210,33 @@ static void verifyTables() {
 #endif
 }
 
-void llvm::riscvExtensionsHelp() {
+void llvm::riscvExtensionsHelp(std::map llvmDescMap) {
+
   outs() << "All available -march extensions for RISC-V\n\n";
-  outs() << '\t' << left_justify("Name", 20) << "Version\n";
+  outs() << '\t' << left_justify("Name", 20) << "Version";
+  outs() << (llvmDescMap.empty() ? "\n" : "\tDescription\n");
 
   RISCVISAInfo::OrderedExtensionMap ExtMap;
   for (const auto &E : SupportedExtensions)
 ExtMap[E.Name] = {E.Version.Major, E.Version.Minor};
-  for (const auto &E : ExtMap)
-outs() << format("\t%-20s%d.%d\n", E.first.c_str(), E.second.MajorVersion,
+  for (const auto &E : ExtMap) {
+outs() << format("\t%-20s%d.%d", E.first.c_str(), E.second.MajorVersion,
  E.second.MinorVersion);
+outs() << (llvmDescMap.empty() ? "\n"

cbalint13 wrote:

> In general I don't think we should assume that all named frontend features 
> will be in the backend by the same name, and then also have a description.

Yes, there are misses already, very few ones (less then five for all the 3 
arches).
But this will encourage us to a better house-keeping in tablegen (backend) vs. 
here (frontend).

> Practically, that means I'd prefer we do a lookup for each name, expecting 
> that it might fail. Instead of checking if the map is empty and if not doing 
> an unconditional lookup.

The ```llvmDescMap.empty()``` is for other reason, I was thinking to make the 
whole ```Description``` column optional. It is useful for unit-test to bypass 
the whole target-machine creation saga and just look at the essential mandatory 
two columns (without descriptions column in test-mode).

* See in ```llvm/unittests/Support/RISCVISAInfoTest.cpp```
```
  std::map EmptyMap;
  llvm::riscvExtensionsHelp(EmptyMap);
```
Basically with this feature we have an option to skip "Description" column at 
all.


> In 99.9% of cases, the name probably matches. Maybe even has to match, but I 
> know we've bent that rule in AArch64 in the past, and it wouldn't cost that 
> much in terms of cpu time to do it that way. This is not a hot path, and 
> we're spending time building a map already.

The features amount per arch is less than a hundred, this is a user-help-menu 
anyway guiding the user.






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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits


@@ -11,11 +11,13 @@
 //
 
//===--===//
 
-#include "llvm/TargetParser/AArch64TargetParser.h"
+#include "llvm/Support/Error.h"

cbalint13 wrote:

It was for format()```, will double-check to see for a closer header for 
```llvm::format()```.

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits


@@ -11,11 +11,13 @@
 //
 
//===--===//
 
-#include "llvm/TargetParser/AArch64TargetParser.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/TargetParser/AArch64TargetParser.h"
 #include "llvm/TargetParser/ARMTargetParserCommon.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
+#include 

cbalint13 wrote:

> Probably don't need to include map if `AArch64TargetParser.h` already 
> references it.

It was included before, i just re-arrange in alphabetical (clang-format).

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits


@@ -600,11 +601,17 @@ StringRef ARM::getARMCPUForArch(const llvm::Triple 
&Triple, StringRef MArch) {
   llvm_unreachable("invalid arch name");
 }
 
-void ARM::PrintSupportedExtensions() {
+void ARM::PrintSupportedExtensions(std::map llvmDescMap) 
{
   outs() << "All available -march extensions for ARM\n\n";
   for (const auto &Ext : ARCHExtNames) {
 // Extensions without a feature cannot be used with -march.
-if (!Ext.Feature.empty())
-  outs() << '\t' << Ext.Name << "\n";
+if (!Ext.Feature.empty()) {
+  if (llvmDescMap.empty()) {
+outs() << '\t' << Ext.Name << "\n";
+  } else {
+outs() << format("\t%-20s", Ext.Name.str().c_str());
+outs() << "\t\t" << llvmDescMap[Ext.Name] << "\n";

cbalint13 wrote:

> This can be one call to outs().

The ```if-else``` It is due to separation of "Description" column as optional.
To compress the 2*outs (inside else) format then will be quite long expansion: 
```llvmDescMap["experimental-"+Ext.Name].str().c_str() ```

Will try again, but spent quite some time on this very estetic part.


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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits


@@ -1016,7 +1017,8 @@ TEST(TargetParserTest, ARMPrintSupportedExtensions) {
 
   outs().flush();
   testing::internal::CaptureStdout();
-  ARM::PrintSupportedExtensions();
+  std::map EmptyMap;

cbalint13 wrote:

Will address this, even by adding a dummy description (to skip whole 
target-machine creation +feature-query).


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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits

cbalint13 wrote:

@DavidSpickett 


Thank you for the review time, will address all the concerns and be back with a 
re-review request.


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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66715

>From d3072f481595d1840551a9f8ed322fa64d336a10 Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Wed, 20 Sep 2023 05:59:32 +0300
Subject: [PATCH] [clang] Enable descriptions for --print-supported-extensions

---
 .../test/Driver/print-supported-extensions.c  |   3 +
 clang/tools/driver/cc1_main.cpp   |  14 +-
 llvm/include/llvm/MC/MCSubtargetInfo.h|   7 +
 llvm/include/llvm/Support/RISCVISAInfo.h  |   4 +-
 .../llvm/TargetParser/AArch64TargetParser.h   |   3 +-
 .../llvm/TargetParser/ARMTargetParser.h   |   3 +-
 llvm/lib/Support/RISCVISAInfo.cpp |  35 ++-
 llvm/lib/TargetParser/AArch64TargetParser.cpp |  18 +-
 llvm/lib/TargetParser/ARMTargetParser.cpp |  17 +-
 llvm/unittests/Support/RISCVISAInfoTest.cpp   | 244 +-
 .../TargetParser/TargetParserTest.cpp |  22 +-
 11 files changed, 222 insertions(+), 148 deletions(-)

diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..af731a5db202055 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -4,14 +4,17 @@
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
 // AARCH64: All available -march extensions for AArch64
+// AARCH64: NameDescription
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
 // RISCV: All available -march extensions for RISC-V
+// RISCV: NameVersion   Description
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
 // ARM: All available -march extensions for ARM
+// ARM: NameDescription
 
 // RUN: %if x86-registered-target %{ not %clang --target=x86_64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index f0d7b5c3889dc1f..3b49dc414c2bd6a 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -28,6 +28,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/LinkAllPasses.h"
+#include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -198,13 +199,20 @@ static int PrintSupportedExtensions(std::string 
TargetStr) {
   std::unique_ptr TheTargetMachine(
   TheTarget->createTargetMachine(TargetStr, "", "", Options, 
std::nullopt));
   const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap llvmDescMap;
+  for (const llvm::SubtargetFeatureKV &feature : Features)
+llvmDescMap.insert({feature.Key, feature.Desc});
 
   if (MachineTriple.isRISCV())
-llvm::riscvExtensionsHelp();
+llvm::riscvExtensionsHelp(llvmDescMap);
   else if (MachineTriple.isAArch64())
-llvm::AArch64::PrintSupportedExtensions();
+llvm::AArch64::PrintSupportedExtensions(llvmDescMap);
   else if (MachineTriple.isARM())
-llvm::ARM::PrintSupportedExtensions();
+llvm::ARM::PrintSupportedExtensions(llvmDescMap);
   else {
 // The option was already checked in Driver::HandleImmediateArgs,
 // so we do not expect to get here if we are not a supported architecture.
diff --git a/llvm/include/llvm/MC/MCSubtargetInfo.h 
b/llvm/include/llvm/MC/MCSubtargetInfo.h
index c1533ac8d0059f5..45c58988985e638 100644
--- a/llvm/include/llvm/MC/MCSubtargetInfo.h
+++ b/llvm/include/llvm/MC/MCSubtargetInfo.h
@@ -230,10 +230,17 @@ class MCSubtargetInfo {
 return Found != ProcDesc.end() && StringRef(Found->Key) == CPU;
   }
 
+  /// Return processor descriptions.
   ArrayRef getAllProcessorDescriptions() const {
 return ProcDesc;
   }
 
+  /// Return processor features.
+  ArrayRef getAllProcessorFeatures() const {
+return ProcFeatures;
+  }
+
+
   virtual unsigned getHwMode() const { return 0; }
 
   /// Return the cache size in bytes for the given level of cache.
diff --git a/llvm/include/llvm/Support/RISCVISAInfo.h 
b/llvm/include/llvm/Support/RISCVISAInfo.h
index 9092fe5c272a994..87fbc7f6fcaf9f6 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_SUPPORT_RISCVISAINFO_H
 #define LLVM_SUPPORT_RISCVISAINFO_H
 
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
 
@@ -22,7 +23,8 @@ struct RISCVExten

[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66715

>From 3e744b6e80f5074613a01d17ad9125ac79fdf83f Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Wed, 20 Sep 2023 06:07:43 +0300
Subject: [PATCH] [clang] Enable descriptions for --print-supported-extensions

---
 .../test/Driver/print-supported-extensions.c  |   3 +
 clang/tools/driver/cc1_main.cpp   |  14 +-
 llvm/include/llvm/MC/MCSubtargetInfo.h|   7 +
 llvm/include/llvm/Support/RISCVISAInfo.h  |   4 +-
 .../llvm/TargetParser/AArch64TargetParser.h   |   3 +-
 .../llvm/TargetParser/ARMTargetParser.h   |   3 +-
 llvm/lib/Support/RISCVISAInfo.cpp |  35 ++-
 llvm/lib/TargetParser/AArch64TargetParser.cpp |  18 +-
 llvm/lib/TargetParser/ARMTargetParser.cpp |  17 +-
 llvm/unittests/Support/RISCVISAInfoTest.cpp   | 244 +-
 .../TargetParser/TargetParserTest.cpp |  23 +-
 11 files changed, 223 insertions(+), 148 deletions(-)

diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..af731a5db202055 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -4,14 +4,17 @@
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
 // AARCH64: All available -march extensions for AArch64
+// AARCH64: NameDescription
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
 // RISCV: All available -march extensions for RISC-V
+// RISCV: NameVersion   Description
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
 // ARM: All available -march extensions for ARM
+// ARM: NameDescription
 
 // RUN: %if x86-registered-target %{ not %clang --target=x86_64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index f0d7b5c3889dc1f..3b49dc414c2bd6a 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -28,6 +28,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/LinkAllPasses.h"
+#include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -198,13 +199,20 @@ static int PrintSupportedExtensions(std::string 
TargetStr) {
   std::unique_ptr TheTargetMachine(
   TheTarget->createTargetMachine(TargetStr, "", "", Options, 
std::nullopt));
   const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap llvmDescMap;
+  for (const llvm::SubtargetFeatureKV &feature : Features)
+llvmDescMap.insert({feature.Key, feature.Desc});
 
   if (MachineTriple.isRISCV())
-llvm::riscvExtensionsHelp();
+llvm::riscvExtensionsHelp(llvmDescMap);
   else if (MachineTriple.isAArch64())
-llvm::AArch64::PrintSupportedExtensions();
+llvm::AArch64::PrintSupportedExtensions(llvmDescMap);
   else if (MachineTriple.isARM())
-llvm::ARM::PrintSupportedExtensions();
+llvm::ARM::PrintSupportedExtensions(llvmDescMap);
   else {
 // The option was already checked in Driver::HandleImmediateArgs,
 // so we do not expect to get here if we are not a supported architecture.
diff --git a/llvm/include/llvm/MC/MCSubtargetInfo.h 
b/llvm/include/llvm/MC/MCSubtargetInfo.h
index c1533ac8d0059f5..45c58988985e638 100644
--- a/llvm/include/llvm/MC/MCSubtargetInfo.h
+++ b/llvm/include/llvm/MC/MCSubtargetInfo.h
@@ -230,10 +230,17 @@ class MCSubtargetInfo {
 return Found != ProcDesc.end() && StringRef(Found->Key) == CPU;
   }
 
+  /// Return processor descriptions.
   ArrayRef getAllProcessorDescriptions() const {
 return ProcDesc;
   }
 
+  /// Return processor features.
+  ArrayRef getAllProcessorFeatures() const {
+return ProcFeatures;
+  }
+
+
   virtual unsigned getHwMode() const { return 0; }
 
   /// Return the cache size in bytes for the given level of cache.
diff --git a/llvm/include/llvm/Support/RISCVISAInfo.h 
b/llvm/include/llvm/Support/RISCVISAInfo.h
index 9092fe5c272a994..87fbc7f6fcaf9f6 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_SUPPORT_RISCVISAINFO_H
 #define LLVM_SUPPORT_RISCVISAINFO_H
 
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
 
@@ -22,7 +23,8 @@ struct RISCVExten

[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66715

>From 4ef7b54508b7ff3f17f29d1763b90b963a8f390e Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Wed, 20 Sep 2023 06:12:52 +0300
Subject: [PATCH] [clang] Enable descriptions for --print-supported-extensions

---
 .../test/Driver/print-supported-extensions.c  |   3 +
 clang/tools/driver/cc1_main.cpp   |  14 +-
 llvm/include/llvm/MC/MCSubtargetInfo.h|   7 +
 llvm/include/llvm/Support/RISCVISAInfo.h  |   4 +-
 .../llvm/TargetParser/AArch64TargetParser.h   |   3 +-
 .../llvm/TargetParser/ARMTargetParser.h   |   3 +-
 llvm/lib/Support/RISCVISAInfo.cpp |  36 ++-
 llvm/lib/TargetParser/AArch64TargetParser.cpp |  18 +-
 llvm/lib/TargetParser/ARMTargetParser.cpp |  17 +-
 llvm/unittests/Support/RISCVISAInfoTest.cpp   | 244 +-
 .../TargetParser/TargetParserTest.cpp |  23 +-
 11 files changed, 224 insertions(+), 148 deletions(-)

diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..af731a5db202055 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -4,14 +4,17 @@
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
 // AARCH64: All available -march extensions for AArch64
+// AARCH64: NameDescription
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
 // RISCV: All available -march extensions for RISC-V
+// RISCV: NameVersion   Description
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
 // ARM: All available -march extensions for ARM
+// ARM: NameDescription
 
 // RUN: %if x86-registered-target %{ not %clang --target=x86_64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index f0d7b5c3889dc1f..3b49dc414c2bd6a 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -28,6 +28,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/LinkAllPasses.h"
+#include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -198,13 +199,20 @@ static int PrintSupportedExtensions(std::string 
TargetStr) {
   std::unique_ptr TheTargetMachine(
   TheTarget->createTargetMachine(TargetStr, "", "", Options, 
std::nullopt));
   const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap llvmDescMap;
+  for (const llvm::SubtargetFeatureKV &feature : Features)
+llvmDescMap.insert({feature.Key, feature.Desc});
 
   if (MachineTriple.isRISCV())
-llvm::riscvExtensionsHelp();
+llvm::riscvExtensionsHelp(llvmDescMap);
   else if (MachineTriple.isAArch64())
-llvm::AArch64::PrintSupportedExtensions();
+llvm::AArch64::PrintSupportedExtensions(llvmDescMap);
   else if (MachineTriple.isARM())
-llvm::ARM::PrintSupportedExtensions();
+llvm::ARM::PrintSupportedExtensions(llvmDescMap);
   else {
 // The option was already checked in Driver::HandleImmediateArgs,
 // so we do not expect to get here if we are not a supported architecture.
diff --git a/llvm/include/llvm/MC/MCSubtargetInfo.h 
b/llvm/include/llvm/MC/MCSubtargetInfo.h
index c1533ac8d0059f5..45c58988985e638 100644
--- a/llvm/include/llvm/MC/MCSubtargetInfo.h
+++ b/llvm/include/llvm/MC/MCSubtargetInfo.h
@@ -230,10 +230,17 @@ class MCSubtargetInfo {
 return Found != ProcDesc.end() && StringRef(Found->Key) == CPU;
   }
 
+  /// Return processor descriptions.
   ArrayRef getAllProcessorDescriptions() const {
 return ProcDesc;
   }
 
+  /// Return processor features.
+  ArrayRef getAllProcessorFeatures() const {
+return ProcFeatures;
+  }
+
+
   virtual unsigned getHwMode() const { return 0; }
 
   /// Return the cache size in bytes for the given level of cache.
diff --git a/llvm/include/llvm/Support/RISCVISAInfo.h 
b/llvm/include/llvm/Support/RISCVISAInfo.h
index 9092fe5c272a994..87fbc7f6fcaf9f6 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_SUPPORT_RISCVISAINFO_H
 #define LLVM_SUPPORT_RISCVISAINFO_H
 
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
 
@@ -22,7 +23,8 @@ struct RISCVExten

[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66715

>From 2e51ca182adac1dca22d390a6494dd8b9ffba7cd Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Wed, 20 Sep 2023 06:15:04 +0300
Subject: [PATCH] [clang] Enable descriptions for --print-supported-extensions

---
 .../test/Driver/print-supported-extensions.c  |   3 +
 clang/tools/driver/cc1_main.cpp   |  14 +-
 llvm/include/llvm/MC/MCSubtargetInfo.h|   6 +
 llvm/include/llvm/Support/RISCVISAInfo.h  |   4 +-
 .../llvm/TargetParser/AArch64TargetParser.h   |   3 +-
 .../llvm/TargetParser/ARMTargetParser.h   |   3 +-
 llvm/lib/Support/RISCVISAInfo.cpp |  36 ++-
 llvm/lib/TargetParser/AArch64TargetParser.cpp |  18 +-
 llvm/lib/TargetParser/ARMTargetParser.cpp |  17 +-
 llvm/unittests/Support/RISCVISAInfoTest.cpp   | 244 +-
 .../TargetParser/TargetParserTest.cpp |  23 +-
 11 files changed, 223 insertions(+), 148 deletions(-)

diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..af731a5db202055 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -4,14 +4,17 @@
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
 // AARCH64: All available -march extensions for AArch64
+// AARCH64: NameDescription
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
 // RISCV: All available -march extensions for RISC-V
+// RISCV: NameVersion   Description
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
 // ARM: All available -march extensions for ARM
+// ARM: NameDescription
 
 // RUN: %if x86-registered-target %{ not %clang --target=x86_64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index f0d7b5c3889dc1f..3b49dc414c2bd6a 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -28,6 +28,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/LinkAllPasses.h"
+#include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -198,13 +199,20 @@ static int PrintSupportedExtensions(std::string 
TargetStr) {
   std::unique_ptr TheTargetMachine(
   TheTarget->createTargetMachine(TargetStr, "", "", Options, 
std::nullopt));
   const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap llvmDescMap;
+  for (const llvm::SubtargetFeatureKV &feature : Features)
+llvmDescMap.insert({feature.Key, feature.Desc});
 
   if (MachineTriple.isRISCV())
-llvm::riscvExtensionsHelp();
+llvm::riscvExtensionsHelp(llvmDescMap);
   else if (MachineTriple.isAArch64())
-llvm::AArch64::PrintSupportedExtensions();
+llvm::AArch64::PrintSupportedExtensions(llvmDescMap);
   else if (MachineTriple.isARM())
-llvm::ARM::PrintSupportedExtensions();
+llvm::ARM::PrintSupportedExtensions(llvmDescMap);
   else {
 // The option was already checked in Driver::HandleImmediateArgs,
 // so we do not expect to get here if we are not a supported architecture.
diff --git a/llvm/include/llvm/MC/MCSubtargetInfo.h 
b/llvm/include/llvm/MC/MCSubtargetInfo.h
index c1533ac8d0059f5..f172a799aa3331c 100644
--- a/llvm/include/llvm/MC/MCSubtargetInfo.h
+++ b/llvm/include/llvm/MC/MCSubtargetInfo.h
@@ -230,10 +230,16 @@ class MCSubtargetInfo {
 return Found != ProcDesc.end() && StringRef(Found->Key) == CPU;
   }
 
+  /// Return processor descriptions.
   ArrayRef getAllProcessorDescriptions() const {
 return ProcDesc;
   }
 
+  /// Return processor features.
+  ArrayRef getAllProcessorFeatures() const {
+return ProcFeatures;
+  }
+
   virtual unsigned getHwMode() const { return 0; }
 
   /// Return the cache size in bytes for the given level of cache.
diff --git a/llvm/include/llvm/Support/RISCVISAInfo.h 
b/llvm/include/llvm/Support/RISCVISAInfo.h
index 9092fe5c272a994..87fbc7f6fcaf9f6 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_SUPPORT_RISCVISAINFO_H
 #define LLVM_SUPPORT_RISCVISAINFO_H
 
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
 
@@ -22,7 +23,8 @@ struct RISCVExtensi

[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66715

>From 371b465939f86990edbe16f19e7d5a4b2db09a00 Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Wed, 20 Sep 2023 06:26:11 +0300
Subject: [PATCH] [clang] Enable descriptions for --print-supported-extensions

---
 .../test/Driver/print-supported-extensions.c  |   3 +
 clang/tools/driver/cc1_main.cpp   |  14 +-
 llvm/include/llvm/MC/MCSubtargetInfo.h|   6 +
 llvm/include/llvm/Support/RISCVISAInfo.h  |   4 +-
 .../llvm/TargetParser/AArch64TargetParser.h   |   3 +-
 .../llvm/TargetParser/ARMTargetParser.h   |   3 +-
 llvm/lib/Support/RISCVISAInfo.cpp |  36 ++-
 llvm/lib/TargetParser/AArch64TargetParser.cpp |  18 +-
 llvm/lib/TargetParser/ARMTargetParser.cpp |  17 +-
 llvm/unittests/Support/RISCVISAInfoTest.cpp   | 244 +-
 .../TargetParser/TargetParserTest.cpp |  23 +-
 11 files changed, 223 insertions(+), 148 deletions(-)

diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..af731a5db202055 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -4,14 +4,17 @@
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
 // AARCH64: All available -march extensions for AArch64
+// AARCH64: NameDescription
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
 // RISCV: All available -march extensions for RISC-V
+// RISCV: NameVersion   Description
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
 // ARM: All available -march extensions for ARM
+// ARM: NameDescription
 
 // RUN: %if x86-registered-target %{ not %clang --target=x86_64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index f0d7b5c3889dc1f..3b49dc414c2bd6a 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -28,6 +28,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/LinkAllPasses.h"
+#include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -198,13 +199,20 @@ static int PrintSupportedExtensions(std::string 
TargetStr) {
   std::unique_ptr TheTargetMachine(
   TheTarget->createTargetMachine(TargetStr, "", "", Options, 
std::nullopt));
   const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap llvmDescMap;
+  for (const llvm::SubtargetFeatureKV &feature : Features)
+llvmDescMap.insert({feature.Key, feature.Desc});
 
   if (MachineTriple.isRISCV())
-llvm::riscvExtensionsHelp();
+llvm::riscvExtensionsHelp(llvmDescMap);
   else if (MachineTriple.isAArch64())
-llvm::AArch64::PrintSupportedExtensions();
+llvm::AArch64::PrintSupportedExtensions(llvmDescMap);
   else if (MachineTriple.isARM())
-llvm::ARM::PrintSupportedExtensions();
+llvm::ARM::PrintSupportedExtensions(llvmDescMap);
   else {
 // The option was already checked in Driver::HandleImmediateArgs,
 // so we do not expect to get here if we are not a supported architecture.
diff --git a/llvm/include/llvm/MC/MCSubtargetInfo.h 
b/llvm/include/llvm/MC/MCSubtargetInfo.h
index c1533ac8d0059f5..f172a799aa3331c 100644
--- a/llvm/include/llvm/MC/MCSubtargetInfo.h
+++ b/llvm/include/llvm/MC/MCSubtargetInfo.h
@@ -230,10 +230,16 @@ class MCSubtargetInfo {
 return Found != ProcDesc.end() && StringRef(Found->Key) == CPU;
   }
 
+  /// Return processor descriptions.
   ArrayRef getAllProcessorDescriptions() const {
 return ProcDesc;
   }
 
+  /// Return processor features.
+  ArrayRef getAllProcessorFeatures() const {
+return ProcFeatures;
+  }
+
   virtual unsigned getHwMode() const { return 0; }
 
   /// Return the cache size in bytes for the given level of cache.
diff --git a/llvm/include/llvm/Support/RISCVISAInfo.h 
b/llvm/include/llvm/Support/RISCVISAInfo.h
index 9092fe5c272a994..f63fa20e0c649e1 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_SUPPORT_RISCVISAINFO_H
 #define LLVM_SUPPORT_RISCVISAINFO_H
 
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
 
@@ -22,7 +23,8 @@ struct RISCVExtensi

[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66715

>From 468f86f2c856f163d4d1b9abdb2ef7d98934fd5f Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Wed, 20 Sep 2023 06:39:19 +0300
Subject: [PATCH] [clang] Enable descriptions for --print-supported-extensions

---
 .../test/Driver/print-supported-extensions.c  |   3 +
 clang/tools/driver/cc1_main.cpp   |  14 +-
 llvm/include/llvm/MC/MCSubtargetInfo.h|   6 +
 llvm/include/llvm/Support/RISCVISAInfo.h  |   4 +-
 .../llvm/TargetParser/AArch64TargetParser.h   |   3 +-
 .../llvm/TargetParser/ARMTargetParser.h   |   3 +-
 llvm/lib/Support/RISCVISAInfo.cpp |  36 ++-
 llvm/lib/TargetParser/AArch64TargetParser.cpp |  18 +-
 llvm/lib/TargetParser/ARMTargetParser.cpp |  17 +-
 llvm/unittests/Support/RISCVISAInfoTest.cpp   | 246 +-
 .../TargetParser/TargetParserTest.cpp |  23 +-
 11 files changed, 224 insertions(+), 149 deletions(-)

diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..af731a5db202055 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -4,14 +4,17 @@
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
 // AARCH64: All available -march extensions for AArch64
+// AARCH64: NameDescription
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
 // RISCV: All available -march extensions for RISC-V
+// RISCV: NameVersion   Description
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
 // ARM: All available -march extensions for ARM
+// ARM: NameDescription
 
 // RUN: %if x86-registered-target %{ not %clang --target=x86_64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index f0d7b5c3889dc1f..3b49dc414c2bd6a 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -28,6 +28,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/LinkAllPasses.h"
+#include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -198,13 +199,20 @@ static int PrintSupportedExtensions(std::string 
TargetStr) {
   std::unique_ptr TheTargetMachine(
   TheTarget->createTargetMachine(TargetStr, "", "", Options, 
std::nullopt));
   const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap llvmDescMap;
+  for (const llvm::SubtargetFeatureKV &feature : Features)
+llvmDescMap.insert({feature.Key, feature.Desc});
 
   if (MachineTriple.isRISCV())
-llvm::riscvExtensionsHelp();
+llvm::riscvExtensionsHelp(llvmDescMap);
   else if (MachineTriple.isAArch64())
-llvm::AArch64::PrintSupportedExtensions();
+llvm::AArch64::PrintSupportedExtensions(llvmDescMap);
   else if (MachineTriple.isARM())
-llvm::ARM::PrintSupportedExtensions();
+llvm::ARM::PrintSupportedExtensions(llvmDescMap);
   else {
 // The option was already checked in Driver::HandleImmediateArgs,
 // so we do not expect to get here if we are not a supported architecture.
diff --git a/llvm/include/llvm/MC/MCSubtargetInfo.h 
b/llvm/include/llvm/MC/MCSubtargetInfo.h
index c1533ac8d0059f5..f172a799aa3331c 100644
--- a/llvm/include/llvm/MC/MCSubtargetInfo.h
+++ b/llvm/include/llvm/MC/MCSubtargetInfo.h
@@ -230,10 +230,16 @@ class MCSubtargetInfo {
 return Found != ProcDesc.end() && StringRef(Found->Key) == CPU;
   }
 
+  /// Return processor descriptions.
   ArrayRef getAllProcessorDescriptions() const {
 return ProcDesc;
   }
 
+  /// Return processor features.
+  ArrayRef getAllProcessorFeatures() const {
+return ProcFeatures;
+  }
+
   virtual unsigned getHwMode() const { return 0; }
 
   /// Return the cache size in bytes for the given level of cache.
diff --git a/llvm/include/llvm/Support/RISCVISAInfo.h 
b/llvm/include/llvm/Support/RISCVISAInfo.h
index 9092fe5c272a994..f63fa20e0c649e1 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_SUPPORT_RISCVISAINFO_H
 #define LLVM_SUPPORT_RISCVISAINFO_H
 
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
 
@@ -22,7 +23,8 @@ struct RISCVExtensi

[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66715

>From ccd3e5f62af208af38f02f76ca018724712f1d5a Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Wed, 20 Sep 2023 06:51:33 +0300
Subject: [PATCH] [clang] Enable descriptions for --print-supported-extensions

---
 .../test/Driver/print-supported-extensions.c  |   3 +
 clang/tools/driver/cc1_main.cpp   |  14 +-
 llvm/include/llvm/MC/MCSubtargetInfo.h|   6 +
 llvm/include/llvm/Support/RISCVISAInfo.h  |   4 +-
 .../llvm/TargetParser/AArch64TargetParser.h   |   3 +-
 .../llvm/TargetParser/ARMTargetParser.h   |   3 +-
 llvm/lib/Support/RISCVISAInfo.cpp |  36 ++-
 llvm/lib/TargetParser/AArch64TargetParser.cpp |  18 +-
 llvm/lib/TargetParser/ARMTargetParser.cpp |  17 +-
 llvm/unittests/Support/RISCVISAInfoTest.cpp   | 246 +-
 .../TargetParser/TargetParserTest.cpp |  23 +-
 11 files changed, 222 insertions(+), 151 deletions(-)

diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..af731a5db202055 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -4,14 +4,17 @@
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
 // AARCH64: All available -march extensions for AArch64
+// AARCH64: NameDescription
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
 // RISCV: All available -march extensions for RISC-V
+// RISCV: NameVersion   Description
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
 // ARM: All available -march extensions for ARM
+// ARM: NameDescription
 
 // RUN: %if x86-registered-target %{ not %clang --target=x86_64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index f0d7b5c3889dc1f..3b49dc414c2bd6a 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -28,6 +28,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/LinkAllPasses.h"
+#include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -198,13 +199,20 @@ static int PrintSupportedExtensions(std::string 
TargetStr) {
   std::unique_ptr TheTargetMachine(
   TheTarget->createTargetMachine(TargetStr, "", "", Options, 
std::nullopt));
   const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap llvmDescMap;
+  for (const llvm::SubtargetFeatureKV &feature : Features)
+llvmDescMap.insert({feature.Key, feature.Desc});
 
   if (MachineTriple.isRISCV())
-llvm::riscvExtensionsHelp();
+llvm::riscvExtensionsHelp(llvmDescMap);
   else if (MachineTriple.isAArch64())
-llvm::AArch64::PrintSupportedExtensions();
+llvm::AArch64::PrintSupportedExtensions(llvmDescMap);
   else if (MachineTriple.isARM())
-llvm::ARM::PrintSupportedExtensions();
+llvm::ARM::PrintSupportedExtensions(llvmDescMap);
   else {
 // The option was already checked in Driver::HandleImmediateArgs,
 // so we do not expect to get here if we are not a supported architecture.
diff --git a/llvm/include/llvm/MC/MCSubtargetInfo.h 
b/llvm/include/llvm/MC/MCSubtargetInfo.h
index c1533ac8d0059f5..f172a799aa3331c 100644
--- a/llvm/include/llvm/MC/MCSubtargetInfo.h
+++ b/llvm/include/llvm/MC/MCSubtargetInfo.h
@@ -230,10 +230,16 @@ class MCSubtargetInfo {
 return Found != ProcDesc.end() && StringRef(Found->Key) == CPU;
   }
 
+  /// Return processor descriptions.
   ArrayRef getAllProcessorDescriptions() const {
 return ProcDesc;
   }
 
+  /// Return processor features.
+  ArrayRef getAllProcessorFeatures() const {
+return ProcFeatures;
+  }
+
   virtual unsigned getHwMode() const { return 0; }
 
   /// Return the cache size in bytes for the given level of cache.
diff --git a/llvm/include/llvm/Support/RISCVISAInfo.h 
b/llvm/include/llvm/Support/RISCVISAInfo.h
index 9092fe5c272a994..f63fa20e0c649e1 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_SUPPORT_RISCVISAINFO_H
 #define LLVM_SUPPORT_RISCVISAINFO_H
 
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
 
@@ -22,7 +23,8 @@ struct RISCVExtensi

[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66715

>From 13527e78686e18d020cefe1a88e0f9c37887b7c5 Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Wed, 20 Sep 2023 06:54:14 +0300
Subject: [PATCH] [clang] Enable descriptions for --print-supported-extensions

---
 .../test/Driver/print-supported-extensions.c  |   3 +
 clang/tools/driver/cc1_main.cpp   |  14 +-
 llvm/include/llvm/MC/MCSubtargetInfo.h|   6 +
 llvm/include/llvm/Support/RISCVISAInfo.h  |   4 +-
 .../llvm/TargetParser/AArch64TargetParser.h   |   3 +-
 .../llvm/TargetParser/ARMTargetParser.h   |   3 +-
 llvm/lib/Support/RISCVISAInfo.cpp |  36 ++-
 llvm/lib/TargetParser/AArch64TargetParser.cpp |  15 +-
 llvm/lib/TargetParser/ARMTargetParser.cpp |  14 +-
 llvm/unittests/Support/RISCVISAInfoTest.cpp   | 246 +-
 .../TargetParser/TargetParserTest.cpp |  23 +-
 11 files changed, 220 insertions(+), 147 deletions(-)

diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..af731a5db202055 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -4,14 +4,17 @@
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
 // AARCH64: All available -march extensions for AArch64
+// AARCH64: NameDescription
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
 // RISCV: All available -march extensions for RISC-V
+// RISCV: NameVersion   Description
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
 // ARM: All available -march extensions for ARM
+// ARM: NameDescription
 
 // RUN: %if x86-registered-target %{ not %clang --target=x86_64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index f0d7b5c3889dc1f..3b49dc414c2bd6a 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -28,6 +28,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/LinkAllPasses.h"
+#include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -198,13 +199,20 @@ static int PrintSupportedExtensions(std::string 
TargetStr) {
   std::unique_ptr TheTargetMachine(
   TheTarget->createTargetMachine(TargetStr, "", "", Options, 
std::nullopt));
   const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap llvmDescMap;
+  for (const llvm::SubtargetFeatureKV &feature : Features)
+llvmDescMap.insert({feature.Key, feature.Desc});
 
   if (MachineTriple.isRISCV())
-llvm::riscvExtensionsHelp();
+llvm::riscvExtensionsHelp(llvmDescMap);
   else if (MachineTriple.isAArch64())
-llvm::AArch64::PrintSupportedExtensions();
+llvm::AArch64::PrintSupportedExtensions(llvmDescMap);
   else if (MachineTriple.isARM())
-llvm::ARM::PrintSupportedExtensions();
+llvm::ARM::PrintSupportedExtensions(llvmDescMap);
   else {
 // The option was already checked in Driver::HandleImmediateArgs,
 // so we do not expect to get here if we are not a supported architecture.
diff --git a/llvm/include/llvm/MC/MCSubtargetInfo.h 
b/llvm/include/llvm/MC/MCSubtargetInfo.h
index c1533ac8d0059f5..f172a799aa3331c 100644
--- a/llvm/include/llvm/MC/MCSubtargetInfo.h
+++ b/llvm/include/llvm/MC/MCSubtargetInfo.h
@@ -230,10 +230,16 @@ class MCSubtargetInfo {
 return Found != ProcDesc.end() && StringRef(Found->Key) == CPU;
   }
 
+  /// Return processor descriptions.
   ArrayRef getAllProcessorDescriptions() const {
 return ProcDesc;
   }
 
+  /// Return processor features.
+  ArrayRef getAllProcessorFeatures() const {
+return ProcFeatures;
+  }
+
   virtual unsigned getHwMode() const { return 0; }
 
   /// Return the cache size in bytes for the given level of cache.
diff --git a/llvm/include/llvm/Support/RISCVISAInfo.h 
b/llvm/include/llvm/Support/RISCVISAInfo.h
index 9092fe5c272a994..f63fa20e0c649e1 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_SUPPORT_RISCVISAINFO_H
 #define LLVM_SUPPORT_RISCVISAINFO_H
 
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
 
@@ -22,7 +23,8 @@ struct RISCVExtensi

[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-19 Thread Balint Cristian via cfe-commits

cbalint13 wrote:

@DavidSpickett ,


The new output: 
[console-output.txt.gz](https://github.com/llvm/llvm-project/files/12668489/console-output.txt.gz)
```
$ zcat console-output.txt.gz | grep 'print'
$ ./bin/clang --target=arm-unknown-linux-gnu --print-supported-extensions
$ ./bin/clang --target=aarch64-unknown-linux-gnu --print-supported-extensions
$ ./bin/clang --target=riscv64-unknown-linux-gnu --print-supported-extensions
```

Addressed all requests, let me know if still spot something.
Re-formatted the print without any '\t', but using spaces with precise 
justifiers.



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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66715

>From ef28607fec310ca190a41bc6cba25b9ba80dd75b Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Wed, 20 Sep 2023 10:23:08 +0300
Subject: [PATCH] [clang] Enable descriptions for --print-supported-extensions

---
 .../test/Driver/print-supported-extensions.c  |   3 +
 clang/tools/driver/cc1_main.cpp   |  14 +-
 llvm/include/llvm/MC/MCSubtargetInfo.h|   6 +
 llvm/include/llvm/Support/RISCVISAInfo.h  |   4 +-
 .../llvm/TargetParser/AArch64TargetParser.h   |   3 +-
 .../llvm/TargetParser/ARMTargetParser.h   |   3 +-
 llvm/lib/Support/RISCVISAInfo.cpp |  36 ++-
 llvm/lib/TargetParser/AArch64TargetParser.cpp |  15 +-
 llvm/lib/TargetParser/ARMTargetParser.cpp |  14 +-
 llvm/unittests/Support/RISCVISAInfoTest.cpp   | 246 +-
 .../TargetParser/TargetParserTest.cpp |  23 +-
 11 files changed, 220 insertions(+), 147 deletions(-)

diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..af731a5db202055 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -4,14 +4,17 @@
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
 // AARCH64: All available -march extensions for AArch64
+// AARCH64: NameDescription
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
 // RISCV: All available -march extensions for RISC-V
+// RISCV: NameVersion   Description
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
 // ARM: All available -march extensions for ARM
+// ARM: NameDescription
 
 // RUN: %if x86-registered-target %{ not %clang --target=x86_64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index f0d7b5c3889dc1f..3b49dc414c2bd6a 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -28,6 +28,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/LinkAllPasses.h"
+#include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -198,13 +199,20 @@ static int PrintSupportedExtensions(std::string 
TargetStr) {
   std::unique_ptr TheTargetMachine(
   TheTarget->createTargetMachine(TargetStr, "", "", Options, 
std::nullopt));
   const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap llvmDescMap;
+  for (const llvm::SubtargetFeatureKV &feature : Features)
+llvmDescMap.insert({feature.Key, feature.Desc});
 
   if (MachineTriple.isRISCV())
-llvm::riscvExtensionsHelp();
+llvm::riscvExtensionsHelp(llvmDescMap);
   else if (MachineTriple.isAArch64())
-llvm::AArch64::PrintSupportedExtensions();
+llvm::AArch64::PrintSupportedExtensions(llvmDescMap);
   else if (MachineTriple.isARM())
-llvm::ARM::PrintSupportedExtensions();
+llvm::ARM::PrintSupportedExtensions(llvmDescMap);
   else {
 // The option was already checked in Driver::HandleImmediateArgs,
 // so we do not expect to get here if we are not a supported architecture.
diff --git a/llvm/include/llvm/MC/MCSubtargetInfo.h 
b/llvm/include/llvm/MC/MCSubtargetInfo.h
index c1533ac8d0059f5..f172a799aa3331c 100644
--- a/llvm/include/llvm/MC/MCSubtargetInfo.h
+++ b/llvm/include/llvm/MC/MCSubtargetInfo.h
@@ -230,10 +230,16 @@ class MCSubtargetInfo {
 return Found != ProcDesc.end() && StringRef(Found->Key) == CPU;
   }
 
+  /// Return processor descriptions.
   ArrayRef getAllProcessorDescriptions() const {
 return ProcDesc;
   }
 
+  /// Return processor features.
+  ArrayRef getAllProcessorFeatures() const {
+return ProcFeatures;
+  }
+
   virtual unsigned getHwMode() const { return 0; }
 
   /// Return the cache size in bytes for the given level of cache.
diff --git a/llvm/include/llvm/Support/RISCVISAInfo.h 
b/llvm/include/llvm/Support/RISCVISAInfo.h
index 9092fe5c272a994..f63fa20e0c649e1 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_SUPPORT_RISCVISAINFO_H
 #define LLVM_SUPPORT_RISCVISAINFO_H
 
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
 
@@ -22,7 +23,8 @@ struct RISCVExtensi

[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66715

>From 5ee5580985ca83ef8399e1912c87b24df8b2b85e Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Wed, 20 Sep 2023 10:25:33 +0300
Subject: [PATCH] [clang] Enable descriptions for --print-supported-extensions

---
 .../test/Driver/print-supported-extensions.c  |   3 +
 clang/tools/driver/cc1_main.cpp   |  14 +-
 llvm/include/llvm/MC/MCSubtargetInfo.h|   6 +
 llvm/include/llvm/Support/RISCVISAInfo.h  |   4 +-
 .../llvm/TargetParser/AArch64TargetParser.h   |   3 +-
 .../llvm/TargetParser/ARMTargetParser.h   |   3 +-
 llvm/lib/Support/RISCVISAInfo.cpp |  36 ++-
 llvm/lib/TargetParser/AArch64TargetParser.cpp |  15 +-
 llvm/lib/TargetParser/ARMTargetParser.cpp |  14 +-
 llvm/unittests/Support/RISCVISAInfoTest.cpp   | 246 +-
 .../TargetParser/TargetParserTest.cpp |  23 +-
 11 files changed, 220 insertions(+), 147 deletions(-)

diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..af731a5db202055 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -4,14 +4,17 @@
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
 // AARCH64: All available -march extensions for AArch64
+// AARCH64: NameDescription
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
 // RISCV: All available -march extensions for RISC-V
+// RISCV: NameVersion   Description
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
 // ARM: All available -march extensions for ARM
+// ARM: NameDescription
 
 // RUN: %if x86-registered-target %{ not %clang --target=x86_64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index f0d7b5c3889dc1f..3b49dc414c2bd6a 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -28,6 +28,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/LinkAllPasses.h"
+#include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -198,13 +199,20 @@ static int PrintSupportedExtensions(std::string 
TargetStr) {
   std::unique_ptr TheTargetMachine(
   TheTarget->createTargetMachine(TargetStr, "", "", Options, 
std::nullopt));
   const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap llvmDescMap;
+  for (const llvm::SubtargetFeatureKV &feature : Features)
+llvmDescMap.insert({feature.Key, feature.Desc});
 
   if (MachineTriple.isRISCV())
-llvm::riscvExtensionsHelp();
+llvm::riscvExtensionsHelp(llvmDescMap);
   else if (MachineTriple.isAArch64())
-llvm::AArch64::PrintSupportedExtensions();
+llvm::AArch64::PrintSupportedExtensions(llvmDescMap);
   else if (MachineTriple.isARM())
-llvm::ARM::PrintSupportedExtensions();
+llvm::ARM::PrintSupportedExtensions(llvmDescMap);
   else {
 // The option was already checked in Driver::HandleImmediateArgs,
 // so we do not expect to get here if we are not a supported architecture.
diff --git a/llvm/include/llvm/MC/MCSubtargetInfo.h 
b/llvm/include/llvm/MC/MCSubtargetInfo.h
index c1533ac8d0059f5..f172a799aa3331c 100644
--- a/llvm/include/llvm/MC/MCSubtargetInfo.h
+++ b/llvm/include/llvm/MC/MCSubtargetInfo.h
@@ -230,10 +230,16 @@ class MCSubtargetInfo {
 return Found != ProcDesc.end() && StringRef(Found->Key) == CPU;
   }
 
+  /// Return processor descriptions.
   ArrayRef getAllProcessorDescriptions() const {
 return ProcDesc;
   }
 
+  /// Return processor features.
+  ArrayRef getAllProcessorFeatures() const {
+return ProcFeatures;
+  }
+
   virtual unsigned getHwMode() const { return 0; }
 
   /// Return the cache size in bytes for the given level of cache.
diff --git a/llvm/include/llvm/Support/RISCVISAInfo.h 
b/llvm/include/llvm/Support/RISCVISAInfo.h
index 9092fe5c272a994..f63fa20e0c649e1 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_SUPPORT_RISCVISAINFO_H
 #define LLVM_SUPPORT_RISCVISAINFO_H
 
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
 
@@ -22,7 +23,8 @@ struct RISCVExtensi

[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits


@@ -4,14 +4,17 @@
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
 // AARCH64: All available -march extensions for AArch64
+// AARCH64: NameDescription
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
 // RISCV: All available -march extensions for RISC-V
+// RISCV: NameVersion   Description
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
 // ARM: All available -march extensions for ARM
+// ARM: NameDescription

cbalint13 wrote:

This was covered in unit-test already.

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits


@@ -1012,11 +1013,18 @@ TEST(TargetParserTest, getARMCPUForArch) {
 
 TEST(TargetParserTest, ARMPrintSupportedExtensions) {
   std::string expected = "All available -march extensions for ARM\n\n"
- "\tcrc\n\tcrypto\n\tsha2";
+ "NameDescription\n"
+ "crc This is a long dummy 
description\n"
+ "crypto  This is a long dummy 
description\n"
+ "sha2This is a long dummy 
description\n";
+
+  llvm::StringMap DummyMap;
+  for (const auto &E : llvm::ARM::ARCHExtNames)
+DummyMap.insert({E.Name, "This is a long dummy description"});

cbalint13 wrote:

The way you tested RISCV previously in unittest (in full-test) require to fill 
up all fields.
I don't see harm to go for all fields.

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits


@@ -22,7 +23,8 @@ struct RISCVExtensionInfo {
   unsigned MinorVersion;
 };
 
-void riscvExtensionsHelp();
+void getAllExtensions(StringMap &Features);

cbalint13 wrote:

I would leave it.

It's fine for endusers to have an API with an accessor to the *full* list of 
what RISCV have.
Whole mine effort here started with lack of accessor to exactly such thing: 
https://github.com/llvm/llvm-project/pull/66582



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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits


@@ -198,13 +199,20 @@ static int PrintSupportedExtensions(std::string 
TargetStr) {
   std::unique_ptr TheTargetMachine(
   TheTarget->createTargetMachine(TargetStr, "", "", Options, 
std::nullopt));
   const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap llvmDescMap;

cbalint13 wrote:

It indicate the origin from llvm backend.

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits


@@ -22,7 +23,8 @@ struct RISCVExtensionInfo {
   unsigned MinorVersion;
 };
 
-void riscvExtensionsHelp();
+void getAllExtensions(StringMap &Features);

cbalint13 wrote:

Regarding accesors see [these lines]
(https://github.com/cbalint13/tvm/blob/4c17af1a187dee450ab89107df18623e8edadede/src/target/llvm/llvm_module.cc#L90-L107)
 in an external project.

--

The info desired there would be usefull in super simple queries like: "Is true 
that user desired CPU X have feature X", e.g. a concrete example, a user have a 
```casadelake``` and check up if it is ```avx512bw``` capable, and also LLVM 
backend have it implemented or not (if it is older).

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits


@@ -4,14 +4,17 @@
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
 // AARCH64: All available -march extensions for AArch64
+// AARCH64: NameDescription
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
 // RISCV: All available -march extensions for RISC-V
+// RISCV: NameVersion   Description
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
 // ARM: All available -march extensions for ARM
+// ARM: NameDescription

cbalint13 wrote:

I'll add the extra checks.

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits


@@ -198,13 +199,20 @@ static int PrintSupportedExtensions(std::string 
TargetStr) {
   std::unique_ptr TheTargetMachine(
   TheTarget->createTargetMachine(TargetStr, "", "", Options, 
std::nullopt));
   const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap llvmDescMap;

cbalint13 wrote:

I'll leve it as sugessted ```DescMap```.

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits


@@ -22,7 +23,8 @@ struct RISCVExtensionInfo {
   unsigned MinorVersion;
 };
 
-void riscvExtensionsHelp();
+void getAllExtensions(StringMap &Features);

cbalint13 wrote:

It was men't as example. Anyway, prior certain versions (in our case 18) that 
accessor is still needed, won't go anywhere soon for compatibility.

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits


@@ -22,7 +23,8 @@ struct RISCVExtensionInfo {
   unsigned MinorVersion;
 };
 
-void riscvExtensionsHelp();
+void getAllExtensions(StringMap &Features);

cbalint13 wrote:

I remove it (all), and add only partial fillers.

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits


@@ -210,24 +210,42 @@ static void verifyTables() {
 #endif
 }
 
-void llvm::riscvExtensionsHelp() {
-  outs() << "All available -march extensions for RISC-V\n\n";
-  outs() << '\t' << left_justify("Name", 20) << "Version\n";
+void llvm::getAllExtensions(StringMap &ExtMap) {
+  for (const auto &E : SupportedExtensions)
+ExtMap[E.Name] = {E.Version.Major, E.Version.Minor};
+  for (const auto &E : SupportedExperimentalExtensions)
+ExtMap[(StringRef("experimental-") + E.Name).str().c_str()] = {
+E.Version.Major, E.Version.Minor};
+}
+
+void llvm::riscvExtensionsHelp(StringMap llvmDescMap) {
+
+  outs() << "All available -march extensions for RISC-V\n\n"
+ << "" << left_justify("Name", 20) << left_justify("Version", 10)
+ << (llvmDescMap.empty() ? "\n" : "Description\n");
 
   RISCVISAInfo::OrderedExtensionMap ExtMap;
   for (const auto &E : SupportedExtensions)
 ExtMap[E.Name] = {E.Version.Major, E.Version.Minor};
-  for (const auto &E : ExtMap)
-outs() << format("\t%-20s%d.%d\n", E.first.c_str(), E.second.MajorVersion,
- E.second.MinorVersion);
+  for (const auto &E : ExtMap) {
+std::string Version = std::to_string(E.second.MajorVersion) + "." +
+  std::to_string(E.second.MinorVersion);
+outs() << format("%-20s%-10s", E.first.c_str(), Version.c_str())
+   << format(llvmDescMap.empty() ? "\n" : "%s\n",
+ llvmDescMap[E.first].str().c_str());
+  }

cbalint13 wrote:

Not sure, does it worth ?

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits


@@ -11,9 +11,10 @@
 //
 
//===--===//
 
-#include "llvm/TargetParser/ARMTargetParser.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/Format.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/TargetParser/ARMTargetParser.h"

cbalint13 wrote:

Will revert.

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66715

>From 3ab99383074e775da3b25a3be68780ed437e91d0 Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Wed, 20 Sep 2023 13:36:13 +0300
Subject: [PATCH] [clang] Enable descriptions for --print-supported-extensions

---
 .../test/Driver/print-supported-extensions.c  |   8 +
 clang/tools/driver/cc1_main.cpp   |  14 +-
 llvm/include/llvm/MC/MCSubtargetInfo.h|   6 +
 llvm/include/llvm/Support/RISCVISAInfo.h  |   4 +-
 .../llvm/TargetParser/AArch64TargetParser.h   |   3 +-
 .../llvm/TargetParser/ARMTargetParser.h   |   3 +-
 llvm/lib/Support/RISCVISAInfo.cpp |  36 ++-
 llvm/lib/TargetParser/AArch64TargetParser.cpp |  15 +-
 llvm/lib/TargetParser/ARMTargetParser.cpp |  12 +-
 llvm/unittests/Support/RISCVISAInfoTest.cpp   | 246 +-
 .../TargetParser/TargetParserTest.cpp |  23 +-
 11 files changed, 224 insertions(+), 146 deletions(-)

diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..cdef3c37d86a30a 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -4,14 +4,22 @@
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
 // AARCH64: All available -march extensions for AArch64
+// AARCH64: NameDescription
+// AARCH64: aes Enable AES support (FEAT_AES, FEAT_PMULL)
+
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
 // RISCV: All available -march extensions for RISC-V
+// RISCV: NameVersion   Description
+// RISCV: i   2.1
+
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
 // ARM: All available -march extensions for ARM
+// ARM: NameDescription
+// ARM: crc Enable support for CRC instructions
 
 // RUN: %if x86-registered-target %{ not %clang --target=x86_64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index f0d7b5c3889dc1f..e9d2c6aad371dbb 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -28,6 +28,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/LinkAllPasses.h"
+#include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -198,13 +199,20 @@ static int PrintSupportedExtensions(std::string 
TargetStr) {
   std::unique_ptr TheTargetMachine(
   TheTarget->createTargetMachine(TargetStr, "", "", Options, 
std::nullopt));
   const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap DescMap;
+  for (const llvm::SubtargetFeatureKV &feature : Features)
+DescMap.insert({feature.Key, feature.Desc});
 
   if (MachineTriple.isRISCV())
-llvm::riscvExtensionsHelp();
+llvm::riscvExtensionsHelp(DescMap);
   else if (MachineTriple.isAArch64())
-llvm::AArch64::PrintSupportedExtensions();
+llvm::AArch64::PrintSupportedExtensions(DescMap);
   else if (MachineTriple.isARM())
-llvm::ARM::PrintSupportedExtensions();
+llvm::ARM::PrintSupportedExtensions(DescMap);
   else {
 // The option was already checked in Driver::HandleImmediateArgs,
 // so we do not expect to get here if we are not a supported architecture.
diff --git a/llvm/include/llvm/MC/MCSubtargetInfo.h 
b/llvm/include/llvm/MC/MCSubtargetInfo.h
index c1533ac8d0059f5..f172a799aa3331c 100644
--- a/llvm/include/llvm/MC/MCSubtargetInfo.h
+++ b/llvm/include/llvm/MC/MCSubtargetInfo.h
@@ -230,10 +230,16 @@ class MCSubtargetInfo {
 return Found != ProcDesc.end() && StringRef(Found->Key) == CPU;
   }
 
+  /// Return processor descriptions.
   ArrayRef getAllProcessorDescriptions() const {
 return ProcDesc;
   }
 
+  /// Return processor features.
+  ArrayRef getAllProcessorFeatures() const {
+return ProcFeatures;
+  }
+
   virtual unsigned getHwMode() const { return 0; }
 
   /// Return the cache size in bytes for the given level of cache.
diff --git a/llvm/include/llvm/Support/RISCVISAInfo.h 
b/llvm/include/llvm/Support/RISCVISAInfo.h
index 9092fe5c272a994..4075db44743297f 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_SUPPORT_RISCVISAINFO_H
 #defi

[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits


@@ -1012,11 +1013,18 @@ TEST(TargetParserTest, getARMCPUForArch) {
 
 TEST(TargetParserTest, ARMPrintSupportedExtensions) {
   std::string expected = "All available -march extensions for ARM\n\n"
- "\tcrc\n\tcrypto\n\tsha2";
+ "NameDescription\n"
+ "crc This is a long dummy 
description\n"
+ "crypto  This is a long dummy 
description\n"
+ "sha2This is a long dummy 
description\n";
+
+  llvm::StringMap DummyMap;
+  for (const auto &E : llvm::ARM::ARCHExtNames)
+DummyMap.insert({E.Name, "This is a long dummy description"});

cbalint13 wrote:

As method, isn't straight possible in the way this RISCV class is now.



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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66715

>From 707106f0a42f9682af5354aa46f28155471fd5f2 Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Thu, 21 Sep 2023 00:56:09 +0300
Subject: [PATCH] [clang] Enable descriptions for --print-supported-extensions

---
 .../test/Driver/print-supported-extensions.c  |   8 +
 clang/tools/driver/cc1_main.cpp   |  14 +-
 llvm/include/llvm/MC/MCSubtargetInfo.h|   6 +
 llvm/include/llvm/Support/RISCVISAInfo.h  |   3 +-
 .../llvm/TargetParser/AArch64TargetParser.h   |   3 +-
 .../llvm/TargetParser/ARMTargetParser.h   |   3 +-
 llvm/lib/Support/RISCVISAInfo.cpp |  28 +-
 llvm/lib/TargetParser/AArch64TargetParser.cpp |  15 +-
 llvm/lib/TargetParser/ARMTargetParser.cpp |  15 +-
 llvm/unittests/Support/RISCVISAInfoTest.cpp   | 244 +-
 .../TargetParser/TargetParserTest.cpp |  21 +-
 11 files changed, 214 insertions(+), 146 deletions(-)

diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..cdef3c37d86a30a 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -4,14 +4,22 @@
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
 // AARCH64: All available -march extensions for AArch64
+// AARCH64: NameDescription
+// AARCH64: aes Enable AES support (FEAT_AES, FEAT_PMULL)
+
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
 // RISCV: All available -march extensions for RISC-V
+// RISCV: NameVersion   Description
+// RISCV: i   2.1
+
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
 // ARM: All available -march extensions for ARM
+// ARM: NameDescription
+// ARM: crc Enable support for CRC instructions
 
 // RUN: %if x86-registered-target %{ not %clang --target=x86_64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index f0d7b5c3889dc1f..e9d2c6aad371dbb 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -28,6 +28,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/LinkAllPasses.h"
+#include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -198,13 +199,20 @@ static int PrintSupportedExtensions(std::string 
TargetStr) {
   std::unique_ptr TheTargetMachine(
   TheTarget->createTargetMachine(TargetStr, "", "", Options, 
std::nullopt));
   const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap DescMap;
+  for (const llvm::SubtargetFeatureKV &feature : Features)
+DescMap.insert({feature.Key, feature.Desc});
 
   if (MachineTriple.isRISCV())
-llvm::riscvExtensionsHelp();
+llvm::riscvExtensionsHelp(DescMap);
   else if (MachineTriple.isAArch64())
-llvm::AArch64::PrintSupportedExtensions();
+llvm::AArch64::PrintSupportedExtensions(DescMap);
   else if (MachineTriple.isARM())
-llvm::ARM::PrintSupportedExtensions();
+llvm::ARM::PrintSupportedExtensions(DescMap);
   else {
 // The option was already checked in Driver::HandleImmediateArgs,
 // so we do not expect to get here if we are not a supported architecture.
diff --git a/llvm/include/llvm/MC/MCSubtargetInfo.h 
b/llvm/include/llvm/MC/MCSubtargetInfo.h
index c1533ac8d0059f5..f172a799aa3331c 100644
--- a/llvm/include/llvm/MC/MCSubtargetInfo.h
+++ b/llvm/include/llvm/MC/MCSubtargetInfo.h
@@ -230,10 +230,16 @@ class MCSubtargetInfo {
 return Found != ProcDesc.end() && StringRef(Found->Key) == CPU;
   }
 
+  /// Return processor descriptions.
   ArrayRef getAllProcessorDescriptions() const {
 return ProcDesc;
   }
 
+  /// Return processor features.
+  ArrayRef getAllProcessorFeatures() const {
+return ProcFeatures;
+  }
+
   virtual unsigned getHwMode() const { return 0; }
 
   /// Return the cache size in bytes for the given level of cache.
diff --git a/llvm/include/llvm/Support/RISCVISAInfo.h 
b/llvm/include/llvm/Support/RISCVISAInfo.h
index 9092fe5c272a994..09c4edd6df60e92 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_SUPPORT_RISCVISAINFO_H
 #defin

[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

cbalint13 wrote:

@DavidSpickett ,

Addressed all requests.
* Here is the console output: 
[console-output.txt.gz](https://github.com/llvm/llvm-project/files/12677908/console-output.txt.gz)
```
$ zcat ~/console-output.txt.gz | grep 'print'
$ ./bin/clang --target=arm-unknown-linux-gnu --print-supported-extensions
$ ./bin/clang --target=aarch64-unknown-linux-gnu --print-supported-extensions
$ ./bin/clang --target=riscv64-unknown-linux-gnu --print-supported-extensions
```

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits


@@ -198,13 +199,20 @@ static int PrintSupportedExtensions(std::string 
TargetStr) {
   std::unique_ptr TheTargetMachine(
   TheTarget->createTargetMachine(TargetStr, "", "", Options, 
std::nullopt));
   const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();

cbalint13 wrote:

On my side on this topic I already checked this situation, yes looks protected 
well.

@DavidSpickett 

As sidenote here, on this topic opened by you: 

* In case of ```createTargetMachine```, notice the -mcpu="" (second argument), 
it will force to **return all target information**. If you specify i.e. 
"sandybridge" than you can only access list of features and descriptions only 
related to "sandybridge" subarchtecture / subset .

* I really hope LLVM will keep this (-mcpu="" => ALL) , and not cut it out 
(some developer will think is a "safer" API), otherwise it will be impossible 
to query LLVM features of **a whole target**.

LLVM looks (to humble me) very dynamic with frequent API changes, my point here 
is a "utilitarian view" as external user I would like to take benefits and 
features through API.


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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66715

>From 4d7d748be3f1d7db94094c00c9ae0d07ecaf6b7e Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Thu, 21 Sep 2023 01:46:13 +0300
Subject: [PATCH] [clang] Enable descriptions for --print-supported-extensions

---
 .../test/Driver/print-supported-extensions.c  |   6 +
 clang/tools/driver/cc1_main.cpp   |  14 +-
 llvm/include/llvm/MC/MCSubtargetInfo.h|   6 +
 llvm/include/llvm/Support/RISCVISAInfo.h  |   3 +-
 .../llvm/TargetParser/AArch64TargetParser.h   |   3 +-
 .../llvm/TargetParser/ARMTargetParser.h   |   3 +-
 llvm/lib/Support/RISCVISAInfo.cpp |  28 +-
 llvm/lib/TargetParser/AArch64TargetParser.cpp |  15 +-
 llvm/lib/TargetParser/ARMTargetParser.cpp |  15 +-
 llvm/unittests/Support/RISCVISAInfoTest.cpp   | 244 +-
 .../TargetParser/TargetParserTest.cpp |  21 +-
 11 files changed, 212 insertions(+), 146 deletions(-)

diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..17894fc0f7ee0b4 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -4,14 +4,20 @@
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
 // AARCH64: All available -march extensions for AArch64
+// AARCH64: NameDescription
+// AARCH64: aes Enable AES support (FEAT_AES, FEAT_PMULL)
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
 // RISCV: All available -march extensions for RISC-V
+// RISCV: NameVersion   Description
+// RISCV: i   2.1
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
 // ARM: All available -march extensions for ARM
+// ARM: NameDescription
+// ARM: crc Enable support for CRC instructions
 
 // RUN: %if x86-registered-target %{ not %clang --target=x86_64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index f0d7b5c3889dc1f..e9d2c6aad371dbb 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -28,6 +28,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/LinkAllPasses.h"
+#include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -198,13 +199,20 @@ static int PrintSupportedExtensions(std::string 
TargetStr) {
   std::unique_ptr TheTargetMachine(
   TheTarget->createTargetMachine(TargetStr, "", "", Options, 
std::nullopt));
   const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap DescMap;
+  for (const llvm::SubtargetFeatureKV &feature : Features)
+DescMap.insert({feature.Key, feature.Desc});
 
   if (MachineTriple.isRISCV())
-llvm::riscvExtensionsHelp();
+llvm::riscvExtensionsHelp(DescMap);
   else if (MachineTriple.isAArch64())
-llvm::AArch64::PrintSupportedExtensions();
+llvm::AArch64::PrintSupportedExtensions(DescMap);
   else if (MachineTriple.isARM())
-llvm::ARM::PrintSupportedExtensions();
+llvm::ARM::PrintSupportedExtensions(DescMap);
   else {
 // The option was already checked in Driver::HandleImmediateArgs,
 // so we do not expect to get here if we are not a supported architecture.
diff --git a/llvm/include/llvm/MC/MCSubtargetInfo.h 
b/llvm/include/llvm/MC/MCSubtargetInfo.h
index c1533ac8d0059f5..f172a799aa3331c 100644
--- a/llvm/include/llvm/MC/MCSubtargetInfo.h
+++ b/llvm/include/llvm/MC/MCSubtargetInfo.h
@@ -230,10 +230,16 @@ class MCSubtargetInfo {
 return Found != ProcDesc.end() && StringRef(Found->Key) == CPU;
   }
 
+  /// Return processor descriptions.
   ArrayRef getAllProcessorDescriptions() const {
 return ProcDesc;
   }
 
+  /// Return processor features.
+  ArrayRef getAllProcessorFeatures() const {
+return ProcFeatures;
+  }
+
   virtual unsigned getHwMode() const { return 0; }
 
   /// Return the cache size in bytes for the given level of cache.
diff --git a/llvm/include/llvm/Support/RISCVISAInfo.h 
b/llvm/include/llvm/Support/RISCVISAInfo.h
index 9092fe5c272a994..09c4edd6df60e92 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_SUPPORT_RISCVISAINFO_H
 #define LL

[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-20 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-21 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable descriptions for --print-supported-extensions (PR #66715)

2023-09-21 Thread Balint Cristian via cfe-commits

cbalint13 wrote:

@DavidSpickett ,

> Looks good to me, thanks for working on this.

Thank you very much for the time !

> I'm not sure if you'll have permissions to click the merge button but if you 
> do, go ahead. 

* No, don't, I am outside contributor.

>Please remember to edit the  final commit message to remove the links to the 
>output files.

* Done.






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


[clang] [clang] Enable --print-supported-extensions for all targets (PR #66586)

2023-09-16 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 created 
https://github.com/llvm/llvm-project/pull/66586

This uses MCSubtargetInfo instead to cover all the architectures. This now also 
list descriptions along with the names.

The advantage fetching from MCSubtargetInfo is that we rely on tablegen 
architecture descriptions for all architectures.

---

* Output from `hexagon`:
```
$ ./bin/clang -target hexagon-linux-gnu --print-supported-extensions
clang version 18.0.0 (https://github.com/cbalint13/llvm-project 
8049db0990d1695a40de57f136af20ce5340b4a6)
Target: hexagon-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/cbalint/work/GITHUB/llvm-project/build/./bin
All available -march extensions for hexagon

  audio(Hexagon Audio extension 
instructions)
  cabac(Emit the CABAC instruction)
  compound (Use compound instructions)
  duplex   (Enable generation of duplex 
instruction)
  hvx  (Hexagon HVX instructions)
  hvx-ieee-fp  (Hexagon HVX IEEE floating point 
instructions)
  hvx-length128b   (Hexagon HVX 128B instructions)
  hvx-length64b(Hexagon HVX 64B instructions)
  hvx-qfloat   (Hexagon HVX QFloating point 
instructions)
  hvxv60   (Hexagon HVX instructions)
  hvxv62   (Hexagon HVX instructions)
  hvxv65   (Hexagon HVX instructions)
{...}
```

* Output from `x86_64`:
```
$ ./bin/clang -target x86_64-linux-gnu --print-supported-extensions
clang version 18.0.0 (https://github.com/cbalint13/llvm-project 
8049db0990d1695a40de57f136af20ce5340b4a6)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/cbalint/work/GITHUB/llvm-project/build/./bin
All available -march extensions for x86-64

  16bit-mode   (16-bit mode (i8086))
  32bit-mode   (32-bit mode (80386))
  3dnow(Enable 3DNow! instructions)
  3dnowa   (Enable 3DNow! Athlon instructions)
  64bit(Support 64-bit instructions)
  64bit-mode   (64-bit mode (x86_64))
  adx  (Support ADX instructions)
  aes  (Enable AES instructions)
  allow-light-256-bit  (Enable generation of 256-bit 
load/stores even 
  amx-bf16 (Support AMX-BF16 instructions)
  amx-complex  (Support AMX-COMPLEX instructions)
  amx-fp16 (Support AMX amx-fp16 instructions)
  amx-int8 (Support AMX-INT8 instructions)
  amx-tile (Support AMX-TILE instructions)
  avx  (Enable AVX instructions)
  avx2 (Enable AVX2 instructions)
  avx512bf16   (Support bfloat16 floating point)
  avx512bitalg (Enable AVX-512 Bit Algorithms)
  avx512bw (Enable AVX-512 Byte and Word 
Instructions)
  avx512cd (Enable AVX-512 Conflict Detection 
Instructions)
{...}
```

---

Cc @DavidSpickett ,  @DanielKristofKiss , @MaskRay 

I also reference here #66582 for past comments on extracting information from 
MCSubtargetInfo .


>From 09197ec356dec013d47c4938c942082f0acce3cf Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Sun, 17 Sep 2023 01:59:36 +0300
Subject: [PATCH] [clang] Enable --print-supported-extensions for all targets

Signed-off-by: Balint Cristian 
---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/Driver.cpp   |  9 ---
 .../test/Driver/print-supported-extensions.c  |  4 ---
 clang/tools/driver/cc1_main.cpp   | 25 +++
 llvm/include/llvm/MC/MCSubtargetInfo.h|  6 +
 5 files changed, 16 insertions(+), 30 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 553c7928c4f949e..431f2f5c4109232 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5277,7 +5277,7 @@ def print_supported_cpus : Flag<["-", "--"], 
"print-supported-cpus">,
   MarshallingInfoFlag>;
 def print_supported_extensions : Flag<["-", "--"], 
"print-supported-extensions">,
   Visibility<[ClangOption, CC1Option, CLOption]>,
-  HelpText<"Print supported -march extensions (RISC-V, AArch64 and ARM only)">,
+  HelpText<"Print supported -march extensions">,
   MarshallingInfoFlag>;
 def : Flag<["-"], "mcpu=help">, Alias;
 def : Flag<["-"], "mtune=help">, Alias;
dif

[clang] [clang] Enable --print-supported-extensions for all targets (PR #66586)

2023-09-16 Thread Balint Cristian via cfe-commits

cbalint13 wrote:

@DavidSpickett ,

This PR list all flags for a specific target.

---

Additionally, beyond this PR:

* We can limit to list flags only for a desired e.g. -mcpu=XYZ, e.g. the user 
can query like:
```./bin/clang -target x86_64-linux-gnu -mcpu=sandybridge 
--print-supported-extensions```

* The cost for this would be simply iterating through 
```MCInfo->checkFeatures()``` for a specific ```-mcpu```.

Let me know if it would be interesting future, I'll be happy doing it in a 
subsecvent PR.

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


[clang] [clang] Enable --print-supported-extensions for all targets (PR #66586)

2023-09-16 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66586

>From 87c21561e1c087caeb6105f5824e809da85e67ac Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Sun, 17 Sep 2023 02:36:45 +0300
Subject: [PATCH] [clang] Enable --print-supported-extensions for all targets

Signed-off-by: Balint Cristian 
---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/Driver.cpp   |  9 ---
 .../test/Driver/print-supported-extensions.c  | 10 +++-
 clang/tools/driver/cc1_main.cpp   | 25 +++
 llvm/include/llvm/MC/MCSubtargetInfo.h|  6 +
 5 files changed, 19 insertions(+), 33 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 553c7928c4f949e..431f2f5c4109232 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5277,7 +5277,7 @@ def print_supported_cpus : Flag<["-", "--"], 
"print-supported-cpus">,
   MarshallingInfoFlag>;
 def print_supported_extensions : Flag<["-", "--"], 
"print-supported-extensions">,
   Visibility<[ClangOption, CC1Option, CLOption]>,
-  HelpText<"Print supported -march extensions (RISC-V, AArch64 and ARM only)">,
+  HelpText<"Print supported -march extensions">,
   MarshallingInfoFlag>;
 def : Flag<["-"], "mcpu=help">, Alias;
 def : Flag<["-"], "mtune=help">, Alias;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 84b8fc7685fed42..8b73618fdc87a39 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4283,15 +4283,6 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 // RISCVMarchHelp in RISCVISAInfo.cpp that prints out supported extensions
 // and quits.
 if (Arg *A = Args.getLastArg(Opt)) {
-  if (Opt == options::OPT_print_supported_extensions &&
-  !C.getDefaultToolChain().getTriple().isRISCV() &&
-  !C.getDefaultToolChain().getTriple().isAArch64() &&
-  !C.getDefaultToolChain().getTriple().isARM()) {
-C.getDriver().Diag(diag::err_opt_not_valid_on_target)
-<< "--print-supported-extensions";
-return;
-  }
-
   // Use the -mcpu=? flag as the dummy input to cc1.
   Actions.clear();
   Action *InputAc = C.MakeAction(*A, types::TY_C);
diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..d52c4a51281c95f 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -3,16 +3,12 @@
 
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
-// AARCH64: All available -march extensions for AArch64
+// AARCH64: All available -march extensions for aarch64
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
-// RISCV: All available -march extensions for RISC-V
+// RISCV: All available -march extensions for riscv64
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
-// ARM: All available -march extensions for ARM
-
-// RUN: %if x86-registered-target %{ not %clang --target=x86_64-linux-gnu \
-// RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
-// X86: error: option '--print-supported-extensions' cannot be specified on 
this target
\ No newline at end of file
+// ARM: All available -march extensions for arm
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index f0d7b5c3889dc1f..25c435054b6927b 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -28,6 +28,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/LinkAllPasses.h"
+#include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -38,15 +39,12 @@
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/Timer.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetMachine.h"
-#include "llvm/TargetParser/AArch64TargetParser.h"
-#include "llvm/TargetParser/ARMTargetParser.h"
 #include 
 
 #ifdef CLANG_HAVE_RLIMITS
@@ -197,19 +195,14 @@ static int PrintSupportedExtensions(std::string 
TargetStr) {
   llvm::TargetOptions Options;
   std::unique_ptr TheTargetMachine(
   TheTarget->createTargetMachine(TargetStr, "", "", Options, 
std::nullopt));
-  const llvm::Triple &MachineTriple = TheTargetMachine

[clang] [clang] Enable --print-supported-extensions for all targets (PR #66586)

2023-09-16 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable --print-supported-extensions for all targets (PR #66586)

2023-09-16 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66586

>From 47422fc341cc2a830aa7abec6d105018271f13bd Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Sun, 17 Sep 2023 03:00:59 +0300
Subject: [PATCH] [clang] Enable --print-supported-extensions for all targets

Signed-off-by: Balint Cristian 
---
 clang/docs/ReleaseNotes.rst   |  6 ++---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/Driver.cpp   |  9 ---
 .../test/Driver/print-supported-extensions.c  | 10 +++-
 clang/tools/driver/cc1_main.cpp   | 25 +++
 llvm/include/llvm/MC/MCSubtargetInfo.h|  6 +
 6 files changed, 22 insertions(+), 36 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e9bfefd40bbbf82..40c0077f4bb51ca 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -283,10 +283,10 @@ Bug Fixes to C++ Support
 - Clang now properly handles out of line template specializations when there is
   a non-template inner-class between the function and the class template.
   (`#65810 `_)
-  
-- Clang now properly converts static lambda call operator to function 
+
+- Clang now properly converts static lambda call operator to function
   pointer on win32.
-  (`#62594 `_)  
+  (`#62594 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 553c7928c4f949e..431f2f5c4109232 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5277,7 +5277,7 @@ def print_supported_cpus : Flag<["-", "--"], 
"print-supported-cpus">,
   MarshallingInfoFlag>;
 def print_supported_extensions : Flag<["-", "--"], 
"print-supported-extensions">,
   Visibility<[ClangOption, CC1Option, CLOption]>,
-  HelpText<"Print supported -march extensions (RISC-V, AArch64 and ARM only)">,
+  HelpText<"Print supported -march extensions">,
   MarshallingInfoFlag>;
 def : Flag<["-"], "mcpu=help">, Alias;
 def : Flag<["-"], "mtune=help">, Alias;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 84b8fc7685fed42..8b73618fdc87a39 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4283,15 +4283,6 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 // RISCVMarchHelp in RISCVISAInfo.cpp that prints out supported extensions
 // and quits.
 if (Arg *A = Args.getLastArg(Opt)) {
-  if (Opt == options::OPT_print_supported_extensions &&
-  !C.getDefaultToolChain().getTriple().isRISCV() &&
-  !C.getDefaultToolChain().getTriple().isAArch64() &&
-  !C.getDefaultToolChain().getTriple().isARM()) {
-C.getDriver().Diag(diag::err_opt_not_valid_on_target)
-<< "--print-supported-extensions";
-return;
-  }
-
   // Use the -mcpu=? flag as the dummy input to cc1.
   Actions.clear();
   Action *InputAc = C.MakeAction(*A, types::TY_C);
diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..d52c4a51281c95f 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -3,16 +3,12 @@
 
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
-// AARCH64: All available -march extensions for AArch64
+// AARCH64: All available -march extensions for aarch64
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
-// RISCV: All available -march extensions for RISC-V
+// RISCV: All available -march extensions for riscv64
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
-// ARM: All available -march extensions for ARM
-
-// RUN: %if x86-registered-target %{ not %clang --target=x86_64-linux-gnu \
-// RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
-// X86: error: option '--print-supported-extensions' cannot be specified on 
this target
\ No newline at end of file
+// ARM: All available -march extensions for arm
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index f0d7b5c3889dc1f..25c435054b6927b 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -28,6 +28,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/LinkAllPasses.h"
+#include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm

[clang] [clang] Enable --print-supported-extensions for all targets (PR #66586)

2023-09-17 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66586

>From fbbc72c2f3d0cbcbb34eca2c9dcb6214076d38de Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Sun, 17 Sep 2023 14:06:05 +0300
Subject: [PATCH] [clang] Enable --print-supported-extensions for all targets

Signed-off-by: Balint Cristian 
---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/Driver.cpp   | 14 +--
 clang/lib/Driver/ToolChains/Clang.cpp |  7 
 .../test/Driver/print-supported-extensions.c  | 18 +---
 clang/tools/driver/cc1_main.cpp   | 42 ++-
 llvm/include/llvm/MC/MCSubtargetInfo.h|  6 +++
 6 files changed, 51 insertions(+), 38 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 553c7928c4f949e..431f2f5c4109232 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5277,7 +5277,7 @@ def print_supported_cpus : Flag<["-", "--"], 
"print-supported-cpus">,
   MarshallingInfoFlag>;
 def print_supported_extensions : Flag<["-", "--"], 
"print-supported-extensions">,
   Visibility<[ClangOption, CC1Option, CLOption]>,
-  HelpText<"Print supported -march extensions (RISC-V, AArch64 and ARM only)">,
+  HelpText<"Print supported -march extensions">,
   MarshallingInfoFlag>;
 def : Flag<["-"], "mcpu=help">, Alias;
 def : Flag<["-"], "mtune=help">, Alias;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 84b8fc7685fed42..5b6b14d175f5299 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4279,19 +4279,9 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 // If --print-supported-cpus, -mcpu=? or -mtune=? is specified, build a
 // custom Compile phase that prints out supported cpu models and quits.
 //
-// If --print-supported-extensions is specified, call the helper function
-// RISCVMarchHelp in RISCVISAInfo.cpp that prints out supported extensions
-// and quits.
+// If --print-supported-extensions is specified, list all supported flags
+// within the target and quit.
 if (Arg *A = Args.getLastArg(Opt)) {
-  if (Opt == options::OPT_print_supported_extensions &&
-  !C.getDefaultToolChain().getTriple().isRISCV() &&
-  !C.getDefaultToolChain().getTriple().isAArch64() &&
-  !C.getDefaultToolChain().getTriple().isARM()) {
-C.getDriver().Diag(diag::err_opt_not_valid_on_target)
-<< "--print-supported-extensions";
-return;
-  }
-
   // Use the -mcpu=? flag as the dummy input to cc1.
   Actions.clear();
   Action *InputAc = C.MakeAction(*A, types::TY_C);
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 40e60585a8b8d6e..ed756ed7ea785c5 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5733,6 +5733,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back(Args.MakeArgString(CPU));
   }
 
+  // Track -mcpu presence
+  // it's absence marks -target-cpu generic
+  if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
+CmdArgs.push_back("-mcpu");
+CmdArgs.push_back(A->getValue());
+  }
+
   RenderTargetOptions(Triple, Args, KernelOrKext, CmdArgs);
 
   // Add clang-cl arguments.
diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..d85d5bc50347144 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -3,16 +3,24 @@
 
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
-// AARCH64: All available -march extensions for AArch64
+// AARCH64: All available -march extensions for aarch64
+
+// RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu 
-mcpu=cortex-a55 \
+// RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
+// AARCH64: All available -march extensions for aarch64 and -mcpu cortex-a55
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
-// RISCV: All available -march extensions for RISC-V
+// RISCV: All available -march extensions for riscv64
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
-// ARM: All available -march extensions for ARM
+// ARM: All available -march extensions for arm
+
+// RUN: %if aarch64-registered-target %{ %clang --target=x86_64-linux-gnu \
+// RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
+// X86: All available -march extensions for x86-64
 
-// RUN: 

[clang] [clang] Enable --print-supported-extensions for all targets (PR #66586)

2023-09-17 Thread Balint Cristian via cfe-commits

cbalint13 wrote:

@DavidSpickett ,

> * We can limit to list flags only for a desired e.g. -mcpu=XYZ, so the user 
> can query like:
> Let me know if it would be another interesting command-line feature, I'll be 
> happy doing it in a subsecvent PR.

Implemented the -mcpu filter option too.
```
$ ./bin/clang --target=x86_64-unknown-linux-gnu -mcpu=sandybridge 
--print-supported-extensions
clang version 18.0.0 (https://github.com/cbalint13/llvm-project 
4a1fe09b189f100e2fb53105bbcd7b15b8adf4f8)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/cbalint/work/GITHUB/llvm-project/build/./bin
All available -march extensions for x86-64 and -mcpu sandybridge

  64bitSupport 64-bit instructions
  64bit-mode   64-bit mode (x86_64)
  avx  Enable AVX instructions
  cmov Enable conditional move instructions
  crc32Enable SSE 4.2 CRC32 instruction 
(used when SSE4.2 is ...
  cx16 64-bit with cmpxchg16b (this is true 
for most x86-64 chips ...
  cx8  Support CMPXCHG8B instructions
  false-deps-popcntPOPCNT has a false dependency on 
dest register
  fast-15bytenop   Target can quickly decode up to 15 
byte NOPs
  fast-scalar-fsqrtScalar SQRT is fast (disable 
Newton-Raphson)
  fast-shld-rotate SHLD can be used as a faster rotate
  fxsr Support fxsave/fxrestore instructions
  idivq-to-divlUse 32-bit divide for positive 
values less than 2^32
  macrofusion  Various instructions can be fused 
with conditional branches
  mmx  Enable MMX instructions
  no-bypass-delay-mov  Has no bypass delay when using the 
'wrong' mov type
  nopl Enable NOPL instruction (generally 
pentium pro+)
  pclmul   Enable packed carry-less 
multiplication instructions
  popcnt   Support POPCNT instruction
  sahf Support LAHF and SAHF instructions 
in 64-bit mode
  slow-3ops-leaLEA instruction with 3 ops or 
certain registers is slow
  slow-unaligned-mem-32Slow unaligned 32-byte memory access
  sse  Enable SSE instructions
  sse2 Enable SSE2 instructions
  sse3 Enable SSE3 instructions
  sse4.1   Enable SSE 4.1 instructions
  sse4.2   Enable SSE 4.2 instructions
  ssse3Enable SSSE3 instructions
  vzeroupper   Should insert vzeroupper instructions
  x87  Enable X87 float instructions
  xsaveSupport xsave instructions
  xsaveopt Support xsaveopt instructions
```


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


[clang] [clang] Enable --print-supported-extensions for all targets (PR #66586)

2023-09-17 Thread Balint Cristian via cfe-commits

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


[clang] [clang] Enable --print-supported-extensions for all targets (PR #66586)

2023-09-17 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66586

>From 633e258d41bf15e77f592f4e95eda729e6da5a4b Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Sun, 17 Sep 2023 14:16:13 +0300
Subject: [PATCH] [clang] Enable --print-supported-extensions for all targets

Signed-off-by: Balint Cristian 
---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/Driver.cpp   | 14 +--
 clang/lib/Driver/ToolChains/Clang.cpp |  7 
 .../test/Driver/print-supported-extensions.c  | 18 +---
 clang/tools/driver/cc1_main.cpp   | 42 ++-
 llvm/include/llvm/MC/MCSubtargetInfo.h|  6 +++
 6 files changed, 51 insertions(+), 38 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 553c7928c4f949e..431f2f5c4109232 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5277,7 +5277,7 @@ def print_supported_cpus : Flag<["-", "--"], 
"print-supported-cpus">,
   MarshallingInfoFlag>;
 def print_supported_extensions : Flag<["-", "--"], 
"print-supported-extensions">,
   Visibility<[ClangOption, CC1Option, CLOption]>,
-  HelpText<"Print supported -march extensions (RISC-V, AArch64 and ARM only)">,
+  HelpText<"Print supported -march extensions">,
   MarshallingInfoFlag>;
 def : Flag<["-"], "mcpu=help">, Alias;
 def : Flag<["-"], "mtune=help">, Alias;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 84b8fc7685fed42..5b6b14d175f5299 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4279,19 +4279,9 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 // If --print-supported-cpus, -mcpu=? or -mtune=? is specified, build a
 // custom Compile phase that prints out supported cpu models and quits.
 //
-// If --print-supported-extensions is specified, call the helper function
-// RISCVMarchHelp in RISCVISAInfo.cpp that prints out supported extensions
-// and quits.
+// If --print-supported-extensions is specified, list all supported flags
+// within the target and quit.
 if (Arg *A = Args.getLastArg(Opt)) {
-  if (Opt == options::OPT_print_supported_extensions &&
-  !C.getDefaultToolChain().getTriple().isRISCV() &&
-  !C.getDefaultToolChain().getTriple().isAArch64() &&
-  !C.getDefaultToolChain().getTriple().isARM()) {
-C.getDriver().Diag(diag::err_opt_not_valid_on_target)
-<< "--print-supported-extensions";
-return;
-  }
-
   // Use the -mcpu=? flag as the dummy input to cc1.
   Actions.clear();
   Action *InputAc = C.MakeAction(*A, types::TY_C);
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 40e60585a8b8d6e..ed756ed7ea785c5 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5733,6 +5733,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back(Args.MakeArgString(CPU));
   }
 
+  // Track -mcpu presence
+  // it's absence marks -target-cpu generic
+  if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
+CmdArgs.push_back("-mcpu");
+CmdArgs.push_back(A->getValue());
+  }
+
   RenderTargetOptions(Triple, Args, KernelOrKext, CmdArgs);
 
   // Add clang-cl arguments.
diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..d85d5bc50347144 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -3,16 +3,24 @@
 
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
-// AARCH64: All available -march extensions for AArch64
+// AARCH64: All available -march extensions for aarch64
+
+// RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu 
-mcpu=cortex-a55 \
+// RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
+// AARCH64: All available -march extensions for aarch64 and -mcpu cortex-a55
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
-// RISCV: All available -march extensions for RISC-V
+// RISCV: All available -march extensions for riscv64
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
-// ARM: All available -march extensions for ARM
+// ARM: All available -march extensions for arm
+
+// RUN: %if aarch64-registered-target %{ %clang --target=x86_64-linux-gnu \
+// RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
+// X86: All available -march extensions for x86-64
 
-// RUN: 

[clang] [clang] Enable --print-supported-extensions for all targets (PR #66586)

2023-09-17 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66586

>From ac90fe17df0f7212e675ddf38dbce5b608933b8e Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Sun, 17 Sep 2023 14:20:10 +0300
Subject: [PATCH] [clang] Enable --print-supported-extensions for all targets

Signed-off-by: Balint Cristian 
---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/Driver.cpp   | 14 +--
 clang/lib/Driver/ToolChains/Clang.cpp |  7 
 .../test/Driver/print-supported-extensions.c  | 18 +---
 clang/tools/driver/cc1_main.cpp   | 42 ++-
 llvm/include/llvm/MC/MCSubtargetInfo.h|  6 +++
 6 files changed, 51 insertions(+), 38 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 553c7928c4f949e..431f2f5c4109232 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5277,7 +5277,7 @@ def print_supported_cpus : Flag<["-", "--"], 
"print-supported-cpus">,
   MarshallingInfoFlag>;
 def print_supported_extensions : Flag<["-", "--"], 
"print-supported-extensions">,
   Visibility<[ClangOption, CC1Option, CLOption]>,
-  HelpText<"Print supported -march extensions (RISC-V, AArch64 and ARM only)">,
+  HelpText<"Print supported -march extensions">,
   MarshallingInfoFlag>;
 def : Flag<["-"], "mcpu=help">, Alias;
 def : Flag<["-"], "mtune=help">, Alias;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 84b8fc7685fed42..5b6b14d175f5299 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4279,19 +4279,9 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 // If --print-supported-cpus, -mcpu=? or -mtune=? is specified, build a
 // custom Compile phase that prints out supported cpu models and quits.
 //
-// If --print-supported-extensions is specified, call the helper function
-// RISCVMarchHelp in RISCVISAInfo.cpp that prints out supported extensions
-// and quits.
+// If --print-supported-extensions is specified, list all supported flags
+// within the target and quit.
 if (Arg *A = Args.getLastArg(Opt)) {
-  if (Opt == options::OPT_print_supported_extensions &&
-  !C.getDefaultToolChain().getTriple().isRISCV() &&
-  !C.getDefaultToolChain().getTriple().isAArch64() &&
-  !C.getDefaultToolChain().getTriple().isARM()) {
-C.getDriver().Diag(diag::err_opt_not_valid_on_target)
-<< "--print-supported-extensions";
-return;
-  }
-
   // Use the -mcpu=? flag as the dummy input to cc1.
   Actions.clear();
   Action *InputAc = C.MakeAction(*A, types::TY_C);
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 40e60585a8b8d6e..ed756ed7ea785c5 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5733,6 +5733,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back(Args.MakeArgString(CPU));
   }
 
+  // Track -mcpu presence
+  // it's absence marks -target-cpu generic
+  if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
+CmdArgs.push_back("-mcpu");
+CmdArgs.push_back(A->getValue());
+  }
+
   RenderTargetOptions(Triple, Args, KernelOrKext, CmdArgs);
 
   // Add clang-cl arguments.
diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..b4b5350ed86e27d 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -3,16 +3,24 @@
 
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
-// AARCH64: All available -march extensions for AArch64
+// AARCH64: All available -march extensions for aarch64
+
+// RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu 
-mcpu=cortex-a55 \
+// RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
+// AARCH64: All available -march extensions for aarch64 and -mcpu cortex-a55
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
-// RISCV: All available -march extensions for RISC-V
+// RISCV: All available -march extensions for riscv64
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
-// ARM: All available -march extensions for ARM
+// ARM: All available -march extensions for arm
+
+// RUN: %if x86-registered-target %{ %clang --target=x86_64-linux-gnu \
+// RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
+// X86: All available -march extensions for x86-64
 
-// RUN: %if 

[clang] [clang] Enable --print-supported-extensions for all targets (PR #66586)

2023-09-17 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66586

>From 6111b800196cee9ee45ebb5c800e17e56b843152 Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Sun, 17 Sep 2023 15:24:23 +0300
Subject: [PATCH] [clang] Enable --print-supported-extensions for all targets

Signed-off-by: Balint Cristian 
---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/Driver.cpp   | 14 ++-
 .../test/Driver/print-supported-extensions.c  |  8 +++---
 clang/tools/driver/cc1_main.cpp   | 25 +++
 llvm/include/llvm/MC/MCSubtargetInfo.h|  6 +
 5 files changed, 22 insertions(+), 33 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 553c7928c4f949e..431f2f5c4109232 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5277,7 +5277,7 @@ def print_supported_cpus : Flag<["-", "--"], 
"print-supported-cpus">,
   MarshallingInfoFlag>;
 def print_supported_extensions : Flag<["-", "--"], 
"print-supported-extensions">,
   Visibility<[ClangOption, CC1Option, CLOption]>,
-  HelpText<"Print supported -march extensions (RISC-V, AArch64 and ARM only)">,
+  HelpText<"Print supported -march extensions">,
   MarshallingInfoFlag>;
 def : Flag<["-"], "mcpu=help">, Alias;
 def : Flag<["-"], "mtune=help">, Alias;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 84b8fc7685fed42..5b6b14d175f5299 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4279,19 +4279,9 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 // If --print-supported-cpus, -mcpu=? or -mtune=? is specified, build a
 // custom Compile phase that prints out supported cpu models and quits.
 //
-// If --print-supported-extensions is specified, call the helper function
-// RISCVMarchHelp in RISCVISAInfo.cpp that prints out supported extensions
-// and quits.
+// If --print-supported-extensions is specified, list all supported flags
+// within the target and quit.
 if (Arg *A = Args.getLastArg(Opt)) {
-  if (Opt == options::OPT_print_supported_extensions &&
-  !C.getDefaultToolChain().getTriple().isRISCV() &&
-  !C.getDefaultToolChain().getTriple().isAArch64() &&
-  !C.getDefaultToolChain().getTriple().isARM()) {
-C.getDriver().Diag(diag::err_opt_not_valid_on_target)
-<< "--print-supported-extensions";
-return;
-  }
-
   // Use the -mcpu=? flag as the dummy input to cc1.
   Actions.clear();
   Action *InputAc = C.MakeAction(*A, types::TY_C);
diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..9be228765a0f28c 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -3,16 +3,16 @@
 
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
-// AARCH64: All available -march extensions for AArch64
+// AARCH64: All available -march extensions for aarch64
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
-// RISCV: All available -march extensions for RISC-V
+// RISCV: All available -march extensions for riscv64
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
-// ARM: All available -march extensions for ARM
+// ARM: All available -march extensions for arm
 
 // RUN: %if x86-registered-target %{ not %clang --target=x86_64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
-// X86: error: option '--print-supported-extensions' cannot be specified on 
this target
\ No newline at end of file
+// X86: All available -march extensions for x86-64
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index f0d7b5c3889dc1f..20542cb9aa7a913 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -38,16 +38,14 @@
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/Timer.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetMachine.h"
-#include "llvm/TargetParser/AArch64TargetParser.h"
-#include "llvm/TargetParser/ARMTargetParser.h"
 #include 
+#include 
 
 #ifdef CLANG_HAVE_RLIMITS
 #include 
@@ -197,19 +195,14 @@ static int PrintSupportedExtensions(std::string 
TargetStr) {
   llvm::TargetOptions Options;
   s

[clang] [clang] Enable --print-supported-extensions for all targets (PR #66586)

2023-09-17 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66586

>From 17f855f12757ee66ff99cf24abe4be0dcffc3532 Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Sun, 17 Sep 2023 15:42:27 +0300
Subject: [PATCH] [clang] Enable --print-supported-extensions for all targets

Signed-off-by: Balint Cristian 
---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/Driver.cpp   | 14 ++-
 .../test/Driver/print-supported-extensions.c  | 10 
 clang/tools/driver/cc1_main.cpp   | 25 +++
 llvm/include/llvm/MC/MCSubtargetInfo.h|  6 +
 5 files changed, 23 insertions(+), 34 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 553c7928c4f949e..431f2f5c4109232 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5277,7 +5277,7 @@ def print_supported_cpus : Flag<["-", "--"], 
"print-supported-cpus">,
   MarshallingInfoFlag>;
 def print_supported_extensions : Flag<["-", "--"], 
"print-supported-extensions">,
   Visibility<[ClangOption, CC1Option, CLOption]>,
-  HelpText<"Print supported -march extensions (RISC-V, AArch64 and ARM only)">,
+  HelpText<"Print supported -march extensions">,
   MarshallingInfoFlag>;
 def : Flag<["-"], "mcpu=help">, Alias;
 def : Flag<["-"], "mtune=help">, Alias;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 84b8fc7685fed42..5b6b14d175f5299 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4279,19 +4279,9 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 // If --print-supported-cpus, -mcpu=? or -mtune=? is specified, build a
 // custom Compile phase that prints out supported cpu models and quits.
 //
-// If --print-supported-extensions is specified, call the helper function
-// RISCVMarchHelp in RISCVISAInfo.cpp that prints out supported extensions
-// and quits.
+// If --print-supported-extensions is specified, list all supported flags
+// within the target and quit.
 if (Arg *A = Args.getLastArg(Opt)) {
-  if (Opt == options::OPT_print_supported_extensions &&
-  !C.getDefaultToolChain().getTriple().isRISCV() &&
-  !C.getDefaultToolChain().getTriple().isAArch64() &&
-  !C.getDefaultToolChain().getTriple().isARM()) {
-C.getDriver().Diag(diag::err_opt_not_valid_on_target)
-<< "--print-supported-extensions";
-return;
-  }
-
   // Use the -mcpu=? flag as the dummy input to cc1.
   Actions.clear();
   Action *InputAc = C.MakeAction(*A, types::TY_C);
diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..d233e9fb783e2e2 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -3,16 +3,16 @@
 
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
-// AARCH64: All available -march extensions for AArch64
+// AARCH64: All available -march extensions for aarch64
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
-// RISCV: All available -march extensions for RISC-V
+// RISCV: All available -march extensions for riscv64
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
-// ARM: All available -march extensions for ARM
+// ARM: All available -march extensions for arm
 
-// RUN: %if x86-registered-target %{ not %clang --target=x86_64-linux-gnu \
+// RUN: %if x86-registered-target %{ %clang --target=x86_64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
-// X86: error: option '--print-supported-extensions' cannot be specified on 
this target
\ No newline at end of file
+// X86: All available -march extensions for x86-64
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index f0d7b5c3889dc1f..20542cb9aa7a913 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -38,16 +38,14 @@
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/Timer.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetMachine.h"
-#include "llvm/TargetParser/AArch64TargetParser.h"
-#include "llvm/TargetParser/ARMTargetParser.h"
 #include 
+#include 
 
 #ifdef CLANG_HAVE_RLIMITS
 #include 
@@ -197,19 +195,14 @@ static int PrintSupport

[clang] [clang] Enable --print-supported-extensions for all targets (PR #66586)

2023-09-17 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66586

>From 7bbe54c0649c2abd29d51e538d2b0bf77359d0f8 Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Sun, 17 Sep 2023 16:16:40 +0300
Subject: [PATCH] [clang] Enable --print-supported-extensions for all targets

Signed-off-by: Balint Cristian 
---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/Driver.cpp   | 14 ++-
 .../test/Driver/print-supported-extensions.c  | 10 
 clang/tools/driver/cc1_main.cpp   | 25 +++
 llvm/include/llvm/MC/MCSubtargetInfo.h|  6 +
 5 files changed, 23 insertions(+), 34 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 553c7928c4f949e..431f2f5c4109232 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5277,7 +5277,7 @@ def print_supported_cpus : Flag<["-", "--"], 
"print-supported-cpus">,
   MarshallingInfoFlag>;
 def print_supported_extensions : Flag<["-", "--"], 
"print-supported-extensions">,
   Visibility<[ClangOption, CC1Option, CLOption]>,
-  HelpText<"Print supported -march extensions (RISC-V, AArch64 and ARM only)">,
+  HelpText<"Print supported -march extensions">,
   MarshallingInfoFlag>;
 def : Flag<["-"], "mcpu=help">, Alias;
 def : Flag<["-"], "mtune=help">, Alias;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 84b8fc7685fed42..5b6b14d175f5299 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4279,19 +4279,9 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 // If --print-supported-cpus, -mcpu=? or -mtune=? is specified, build a
 // custom Compile phase that prints out supported cpu models and quits.
 //
-// If --print-supported-extensions is specified, call the helper function
-// RISCVMarchHelp in RISCVISAInfo.cpp that prints out supported extensions
-// and quits.
+// If --print-supported-extensions is specified, list all supported flags
+// within the target and quit.
 if (Arg *A = Args.getLastArg(Opt)) {
-  if (Opt == options::OPT_print_supported_extensions &&
-  !C.getDefaultToolChain().getTriple().isRISCV() &&
-  !C.getDefaultToolChain().getTriple().isAArch64() &&
-  !C.getDefaultToolChain().getTriple().isARM()) {
-C.getDriver().Diag(diag::err_opt_not_valid_on_target)
-<< "--print-supported-extensions";
-return;
-  }
-
   // Use the -mcpu=? flag as the dummy input to cc1.
   Actions.clear();
   Action *InputAc = C.MakeAction(*A, types::TY_C);
diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..d233e9fb783e2e2 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -3,16 +3,16 @@
 
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
-// AARCH64: All available -march extensions for AArch64
+// AARCH64: All available -march extensions for aarch64
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
-// RISCV: All available -march extensions for RISC-V
+// RISCV: All available -march extensions for riscv64
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
-// ARM: All available -march extensions for ARM
+// ARM: All available -march extensions for arm
 
-// RUN: %if x86-registered-target %{ not %clang --target=x86_64-linux-gnu \
+// RUN: %if x86-registered-target %{ %clang --target=x86_64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
-// X86: error: option '--print-supported-extensions' cannot be specified on 
this target
\ No newline at end of file
+// X86: All available -march extensions for x86-64
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index f0d7b5c3889dc1f..20542cb9aa7a913 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -38,16 +38,14 @@
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/Timer.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetMachine.h"
-#include "llvm/TargetParser/AArch64TargetParser.h"
-#include "llvm/TargetParser/ARMTargetParser.h"
 #include 
+#include 
 
 #ifdef CLANG_HAVE_RLIMITS
 #include 
@@ -197,19 +195,14 @@ static int PrintSupport

[clang] [clang] Enable --print-supported-extensions for all targets (PR #66586)

2023-09-17 Thread Balint Cristian via cfe-commits

https://github.com/cbalint13 updated 
https://github.com/llvm/llvm-project/pull/66586

>From 689b322408caff8340ffef4dd526d3640958ea03 Mon Sep 17 00:00:00 2001
From: Balint Cristian 
Date: Sun, 17 Sep 2023 16:52:15 +0300
Subject: [PATCH] [clang] Enable --print-supported-extensions for all targets

Signed-off-by: Balint Cristian 
---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/Driver.cpp   | 14 ++-
 .../test/Driver/print-supported-extensions.c  | 10 
 clang/tools/driver/cc1_main.cpp   | 25 +++
 llvm/include/llvm/MC/MCSubtargetInfo.h|  6 +
 5 files changed, 23 insertions(+), 34 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 553c7928c4f949e..431f2f5c4109232 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5277,7 +5277,7 @@ def print_supported_cpus : Flag<["-", "--"], 
"print-supported-cpus">,
   MarshallingInfoFlag>;
 def print_supported_extensions : Flag<["-", "--"], 
"print-supported-extensions">,
   Visibility<[ClangOption, CC1Option, CLOption]>,
-  HelpText<"Print supported -march extensions (RISC-V, AArch64 and ARM only)">,
+  HelpText<"Print supported -march extensions">,
   MarshallingInfoFlag>;
 def : Flag<["-"], "mcpu=help">, Alias;
 def : Flag<["-"], "mtune=help">, Alias;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 84b8fc7685fed42..5b6b14d175f5299 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4279,19 +4279,9 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 // If --print-supported-cpus, -mcpu=? or -mtune=? is specified, build a
 // custom Compile phase that prints out supported cpu models and quits.
 //
-// If --print-supported-extensions is specified, call the helper function
-// RISCVMarchHelp in RISCVISAInfo.cpp that prints out supported extensions
-// and quits.
+// If --print-supported-extensions is specified, list all supported flags
+// within the target and quit.
 if (Arg *A = Args.getLastArg(Opt)) {
-  if (Opt == options::OPT_print_supported_extensions &&
-  !C.getDefaultToolChain().getTriple().isRISCV() &&
-  !C.getDefaultToolChain().getTriple().isAArch64() &&
-  !C.getDefaultToolChain().getTriple().isARM()) {
-C.getDriver().Diag(diag::err_opt_not_valid_on_target)
-<< "--print-supported-extensions";
-return;
-  }
-
   // Use the -mcpu=? flag as the dummy input to cc1.
   Actions.clear();
   Action *InputAc = C.MakeAction(*A, types::TY_C);
diff --git a/clang/test/Driver/print-supported-extensions.c 
b/clang/test/Driver/print-supported-extensions.c
index 8daf4d8a34b8a60..d233e9fb783e2e2 100644
--- a/clang/test/Driver/print-supported-extensions.c
+++ b/clang/test/Driver/print-supported-extensions.c
@@ -3,16 +3,16 @@
 
 // RUN: %if aarch64-registered-target %{ %clang --target=aarch64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
AARCH64 %}
-// AARCH64: All available -march extensions for AArch64
+// AARCH64: All available -march extensions for aarch64
 
 // RUN: %if riscv-registered-target %{ %clang --target=riscv64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix 
RISCV %}
-// RISCV: All available -march extensions for RISC-V
+// RISCV: All available -march extensions for riscv64
 
 // RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM 
%}
-// ARM: All available -march extensions for ARM
+// ARM: All available -march extensions for arm
 
-// RUN: %if x86-registered-target %{ not %clang --target=x86_64-linux-gnu \
+// RUN: %if x86-registered-target %{ %clang --target=x86_64-linux-gnu \
 // RUN:   --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 
%}
-// X86: error: option '--print-supported-extensions' cannot be specified on 
this target
\ No newline at end of file
+// X86: All available -march extensions for x86-64
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index f0d7b5c3889dc1f..eabc2beaf04f2fb 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -28,6 +28,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/LinkAllPasses.h"
+#include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
@@ -38,15 +39,12 @@
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
-#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/Timer.h"
 #include "llvm/Support/r

[clang] [clang] Enable --print-supported-extensions for all targets (PR #66586)

2023-09-18 Thread Balint Cristian via cfe-commits

cbalint13 wrote:


@DavidSpickett 

Hi David, 

> Thankyou for looking into this, if it can work it's much cleaner than an ever 
> expanding if.
> 
> I think that `getAllProcessorFeatures` may include things that are rejected 
> by `-march`. I will check that for Arm and AArch64. Since the list of 
> features in the target parser may be different than the backend (it's not 
> good but it is what it is).


* I see the important point of ```-march```. 

   To be accurate , we can filter/validate through llvm 
```MCInfo->checkFeatures()``` with respect to the -mcpu (if user provides it, 
otherwise return a full list just like now).

   Something like:
   ```
   $ zcat sample-outputs.log.gz | grep print
   $ ./bin/clang --target=riscv64-unknown-linux-gnu  
--print-supported-extensions
   $ ./bin/clang --target=riscv64-unknown-linux-gnu -mcpu=sifive-x280 
--print-supported-extensions
   $ ./bin/clang --target=x86_64-unknown-linux-gnu --print-supported-extensions
   $ ./bin/clang --target=x86_64-unknown-linux-gnu -mcpu=sandybridge 
--print-supported-extensions
   $ ./bin/clang --target=x86_64-unknown-linux-gnu -mcpu=cascadelake 
--print-supported-extensions
   $ ./bin/clang --target=aarch64-unknown-linux-gnu --print-supported-extensions
   $ ./bin/clang --target=aarch64-unknown-linux-gnu  -mcpu=cortex-a55 
--print-supported-extensions
   ```
   The file with the full log outputs is here: 
[sample-outputs.log.gz](https://github.com/llvm/llvm-project/files/12646975/sample-outputs.log.gz)



> Does this change RISC-V's output? They are (I assume) unique in printing 
> version numbers and ratification status, etc. Assuming it doesn't (which it 
> probably does), it would likely make a few methods in RSIC-V ABI info unused, 
> but deal with that later if so.

* If user provides ```-mcpu``` we can narrow the flags the only to validated 
ones for that target+mcpu, see:

```
$ ./bin/clang --target=riscv64-unknown-linux-gnu -mcpu=sifive-x280 
--print-supported-extensions
All available -march extensions for riscv64 and -mcpu sifive-x280

  64bitImplements RV64
  a'A' (Atomic Instructions)
  c'C' (Compressed Instructions)
  d'D' (Double-Precision Floating-Point)
  dlen-factor-2Vector unit DLEN(data path width) is 
half of VLEN
  f'F' (Single-Precision Floating-Point)
  m'M' (Integer Multiplication and 
Division)
  no-default-unrollDisable default unroll preference.
  short-forward-branch-opt Enable short forward branch 
optimization
  sifive7  SiFive 7-Series processors
  v'V' (Vector Extension for 
Application Processors)
  zba  'Zba' (Address Generation 
Instructions)
  zbb  'Zbb' (Basic Bit-Manipulation)
  zfh  'Zfh' (Half-Precision Floating-Point)
  zfhmin   'Zfhmin' (Half-Precision 
Floating-Point Minimal)
  zicsr'zicsr' (CSRs)
  zifencei 'Zifencei' (fence.i)
  zve32f   'Zve32f' (Vector Extensions for 
Embedded Processors with maximal 32 EEW and F extension)
  zve32x   'Zve32x' (Vector Extensions for 
Embedded Processors with maximal 32 EEW)
  zve64d   'Zve64d' (Vector Extensions for 
Embedded Processors with maximal 64 EEW, F and D extension)
  zve64f   'Zve64f' (Vector Extensions for 
Embedded Processors with maximal 64 EEW and F extension)
  zve64x   'Zve64x' (Vector Extensions for 
Embedded Processors with maximal 64 EEW)
  zvfh 'Zvfh' (Vector Half-Precision 
Floating-Point)
  zvl128b  'Zvl' (Minimum Vector Length) 128
  zvl256b  'Zvl' (Minimum Vector Length) 256
  zvl32b   'Zvl' (Minimum Vector Length) 32
  zvl512b  'Zvl' (Minimum Vector Length) 512
  zvl64b   'Zvl' (Minimum Vector Length) 64

```





In current state this PR prints _all_ flags of target, it is not mcpu aware.
I don't know how to drag into 
[cc1_main()](https://github.com/llvm/llvm-project/blob/08d2ea372ff63156939a439dfb30766d83686764/clang/tools/driver/cc1_main.cpp#L218)
 the user's -mcpu flag from clang's main().

An attempt to do it is here, but propagading down the ```-mcpu``` fails many 
unittests: 
[clang-print-mcpu-aware.patch.gz](https://github.com/llvm/llvm-project/files/12646535/clang-print-mcpu-aware.patch.g

[clang] [clang] Enable --print-supported-extensions for all targets (PR #66586)

2023-09-18 Thread Balint Cristian via cfe-commits

cbalint13 wrote:

> Put `-mcpu` aside for now, that's nice, but it's only going to be viable in a 
> world where the backend (tablegen) and frontend (target parsers/ABI info) 
> agree on what is valid and can also be passed to clang.

> So what your patch produces is kinda like `./bin/clang --target  
> -mllvm -mattr=+unknown_name` and getting `Don't understand unknown_name, you 
> could have passed . (and we have had customers ask for exactly that sort of 
> option, but there's a reason some can't be passed to clang)
 
> Unfortunately the information of what is valid to be passed to clang is not 
> in the same tablegen you're pulling from. It would be nice, and it's not as 
> far off a goal as it used to be, but we aren't there yet.

@DavidSpickett ,

I see the point with the curated lists vs tablegen backend, thank you much for 
the explanations.
I was only able to check intel's one (w.r.t to -mcpu), without being aware on 
aarch64 / riscv world's detail.

---

My last (potential) idea that might have a purposeful end out of this effort 
here:

1. For each curated/legit features printed via ```riscvExtensionsHelp()```, 
```AArch64::PrintSupportedExtensions()```,   
```ARM::PrintSupportedExtensions()``` could be there a lookup  within 
getAllProcessorFeatures() for the human-readable description counterpart ?

---

Thanks a lot for your time !







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


[clang] [clang] Enable --print-supported-extensions for all targets (PR #66586)

2023-09-18 Thread Balint Cristian via cfe-commits

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