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

2023-09-22 Thread David Spickett via cfe-commits

DavidSpickett wrote:

If you are doing more contributions you can get commit access by doing 
https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access. Though with 
the switch to Github it's super easy to ask the reviewer to click the merge 
button, so it's not required.

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-22 Thread David Spickett via cfe-commits

https://github.com/DavidSpickett closed 
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 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 David Spickett via cfe-commits

DavidSpickett wrote:

Looks good to me, thanks for working on this.

I'm not sure if you'll have permissions to click the merge button but if you 
do, go ahead. Please remember to edit the final commit message to remove the 
links to the output files.

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 David Spickett via cfe-commits

https://github.com/DavidSpickett approved this pull 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-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 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  = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap DescMap;
+  for (const llvm::SubtargetFeatureKV  : 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 

[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 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


@@ -198,13 +199,20 @@ static int PrintSupportedExtensions(std::string 
TargetStr) {
   std::unique_ptr TheTargetMachine(
   TheTarget->createTargetMachine(TargetStr, "", "", Options, 
std::nullopt));
   const llvm::Triple  = 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 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

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  = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap DescMap;
+  for (const llvm::SubtargetFeatureKV  : 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 

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

2023-09-20 Thread David Spickett via cfe-commits

https://github.com/DavidSpickett 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 David Spickett via cfe-commits

https://github.com/DavidSpickett 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 David Spickett 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  = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();

DavidSpickett wrote:

I was wrong, clang doesn't recognise the triple if it wasn't enabled:
```
$ ./bin/clang --target=riscv64-linux-gnu --print-support
clang version 18.0.0 (https://github.com/llvm/llvm-project.git 
ebefe83c092e41d243829ab812bb650674e2f3d2)
Target: riscv64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/david.spickett/build-llvm-aarch64/./bin
No available targets are compatible with triple "riscv64-unknown-linux-gnu"
```

So we won't get to this code if the target backend is missing. No worries :)

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 David Spickett 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  = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();

DavidSpickett wrote:

It's possible `TheTargetMachine` is already null in this situation, and this is 
best fixed outside of this change.

I'll check that.

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 David Spickett 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  = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();

DavidSpickett wrote:

I just thought of one more thing. What happens here if the build was configured 
without the target backend enabled?

For example if CMake was configred with `-DLLVM_TARGETS_TO_BUILD=ARM`, and you 
ask for the RISC-V extensions, does clang crash?

Though that is an unusual thing to do, but it is possible since clang knows 
about all possible triples even without a target backend. And besides that, 
clang shouldn't crash anyway. Simplest solution is to pass an empty description 
map I think, and add a test for that situation.

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 David Spickett via cfe-commits

https://github.com/DavidSpickett 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 David Spickett 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  : llvm::ARM::ARCHExtNames)
+DummyMap.insert({E.Name, "This is a long dummy description"});

DavidSpickett wrote:

Not sure what you mean.
```
DummyMap["crc"] = "This is a long dummy description";
```
Is what I am suggesting. Adjust the expected output as needed.

Do that for RISC-V and AArch64 too and there's no need for an extra method in 
RISC-V to get all the extension names.


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 David Spickett via cfe-commits

https://github.com/DavidSpickett 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

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  : 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 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  = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap DescMap;
+  for (const llvm::SubtargetFeatureKV  : 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
 #define 

[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 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 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


@@ -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 David Spickett via cfe-commits

https://github.com/DavidSpickett 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 David Spickett via cfe-commits

https://github.com/DavidSpickett 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 David Spickett 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 ) {
+  for (const auto  : SupportedExtensions)
+ExtMap[E.Name] = {E.Version.Major, E.Version.Minor};
+  for (const auto  : 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  : SupportedExtensions)
 ExtMap[E.Name] = {E.Version.Major, E.Version.Minor};
-  for (const auto  : ExtMap)
-outs() << format("\t%-20s%d.%d\n", E.first.c_str(), E.second.MajorVersion,
- E.second.MinorVersion);
+  for (const auto  : 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());
+  }

DavidSpickett wrote:

I would given that a reader has to parse the formatting specifiers, a few ifs 
and a lookup or two. If they only need to do that once that's nice.

But the two loops are visually identical apart from the "experimental-" so it's 
a close decision.

Go with what you think is best.

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 ) {
+  for (const auto  : SupportedExtensions)
+ExtMap[E.Name] = {E.Version.Major, E.Version.Minor};
+  for (const auto  : 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  : SupportedExtensions)
 ExtMap[E.Name] = {E.Version.Major, E.Version.Minor};
-  for (const auto  : ExtMap)
-outs() << format("\t%-20s%d.%d\n", E.first.c_str(), E.second.MajorVersion,
- E.second.MinorVersion);
+  for (const auto  : 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

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


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

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


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

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

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  = 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


@@ -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 David Spickett via cfe-commits


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

DavidSpickett wrote:

An external project needing something is not a reason to add methods in tree. 
It could be part of an argument to do so but in the context of this patch, this 
new RISC-V method is not needed and should be removed.

If you want to ease TVM's pain by upstreaming their changes you can do so, in a 
PR focused on that, with some in tree use case and testing.

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 David Spickett via cfe-commits


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

DavidSpickett wrote:

Ok but I'll refer you to MaskRay's comment there:
```
We need justification to have this API, ideally tested by an in-tree target, 
otherwise this is prone to be removed by another contributor as an unused 
function.
```

There is no need to add a dummy description to every extension just for the 
test. Just pick one that already exists. Then there's no in tree use for this 
function and MaskRay's logic applies again.

The fact that you were able to add such a method without much trouble also 
tells us that carrying it in tree, unused, isn't going to save anyone much 
effort when it finally is needed.

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


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

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 David Spickett 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  = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap llvmDescMap;

DavidSpickett wrote:

Sure that's got some logic to it, but the code is clearly building a map with 
data from MCInfo, so it's implicit that it came from the llvm backend. And 
there isn't another source of data, so it's not like we have an llvm 
description map and a clang description map and need to know the difference.

Do as you wish it's not a big deal, but if you keep it I think the name should 
be `LLVMDescMap` to match 
https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly.

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 David Spickett 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

DavidSpickett wrote:

It is, and that's great, but, if someone decides to refactor this one day and 
suddenly they aren't using those functions anymore, we could miss it. It's 
unlikely but it's cheap to add a few lines here as well to cover that 
possibility.

Also, it's far easier for someone who is trying to understand the option to 
read this test file than it is to know that it calls 3 different methods in the 
background. So from a documentation point of view it also helps.

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  = 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 David Spickett 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  : llvm::ARM::ARCHExtNames)
+DummyMap.insert({E.Name, "This is a long dummy description"});

DavidSpickett wrote:

Also it saves you adding a method to RISC-V just to get the list of extensions. 
Which we did for AArch64 but it was a hack there too that I would love to also 
remove one day.

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 David Spickett 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  : llvm::ARM::ARCHExtNames)
+DummyMap.insert({E.Name, "This is a long dummy description"});

DavidSpickett wrote:

The harm is we aren't testing what happens if an extension has no description. 
If the underlying implementation changes in the future to something that does 
fault on a missing description, no one will know until a user tries the option.

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 );

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

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


@@ -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  : 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


@@ -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 David Spickett 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 ) {
+  for (const auto  : SupportedExtensions)
+ExtMap[E.Name] = {E.Version.Major, E.Version.Minor};
+  for (const auto  : 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  : SupportedExtensions)
 ExtMap[E.Name] = {E.Version.Major, E.Version.Minor};
-  for (const auto  : ExtMap)
-outs() << format("\t%-20s%d.%d\n", E.first.c_str(), E.second.MajorVersion,
- E.second.MinorVersion);
+  for (const auto  : 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());
+  }

DavidSpickett wrote:

Given that this loop is almost the same for normal and experimental extensions, 
you could move this out into a static function `static void PrintExtensions` 
that takes a prefix that's either `""` or `"experimental-"`.

This would make it clear that both format in the same way, same padding etc.

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 David Spickett 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  : llvm::ARM::ARCHExtNames)
+DummyMap.insert({E.Name, "This is a long dummy description"});

DavidSpickett wrote:

This is ok but what I meant specifically was, add a dummy description for just 
one extension. Then these tests are covering the case where we do and don't 
have an extension.

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 David Spickett 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  = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap llvmDescMap;

DavidSpickett wrote:

I don't see the need for the `llvm` prefix here, I guess you're saying that 
these come from llvm as in the backend, which is true but not really useful 
information here.

`DescMap` would be fine instead.

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 David Spickett 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 ) {
+  for (const auto  : SupportedExtensions)
+ExtMap[E.Name] = {E.Version.Major, E.Version.Minor};
+  for (const auto  : SupportedExperimentalExtensions)
+ExtMap[(StringRef("experimental-") + E.Name).str().c_str()] = {
+E.Version.Major, E.Version.Minor};
+}

DavidSpickett wrote:

Given that you don't need to add dummy descriptions to *all* extensions in the 
tests, this method becomes unused.

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 David Spickett via cfe-commits

https://github.com/DavidSpickett 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 David Spickett via cfe-commits


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

DavidSpickett wrote:

This can go if you just set the description of only one extension in the tests.

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 David Spickett via cfe-commits


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

DavidSpickett wrote:

I was about to say this crashes if the lookup fails, it might in asserts 
builds, but given this is a map it'll default construct the value which in this 
case is empty string. Which is fine.

So leave this as is and ignore my earlier comments about the lookup, I forgot 
that maps have this quirk to them.

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 David Spickett 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

DavidSpickett wrote:

E.g.
```
ARM: crc Enable support for CRC instructions
```
Then if we ever added `arc` it wouldn't matter if it came first, we're still 
checking the important things.

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 David Spickett 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"

DavidSpickett wrote:

Again, if you're manually re-ordering these please don't.

If clang-format is doing this, well that's a bit odd but I guess I'll yield to 
the robot on that one.

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 David Spickett 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

DavidSpickett wrote:

Include the first line of the output as well, so we know it lines up (for all 3 
architectures).

Don't use a `-NEXT:` check, just `ARM:` again. Since the extensions may get 
reordered later and we have no need to be strict.

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 David Spickett via cfe-commits

https://github.com/DavidSpickett requested changes to this pull 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-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  = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap llvmDescMap;
+  for (const llvm::SubtargetFeatureKV  : 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 RISCVExtensionInfo {
   unsigned 

[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  = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap llvmDescMap;
+  for (const llvm::SubtargetFeatureKV  : 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 RISCVExtensionInfo {
   unsigned 

[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-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

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  = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap llvmDescMap;
+  for (const llvm::SubtargetFeatureKV  : 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 RISCVExtensionInfo {
   unsigned 

[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  = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap llvmDescMap;
+  for (const llvm::SubtargetFeatureKV  : 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 RISCVExtensionInfo {
   unsigned 

[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  = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap llvmDescMap;
+  for (const llvm::SubtargetFeatureKV  : 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 RISCVExtensionInfo {
   unsigned 

[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  = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap llvmDescMap;
+  for (const llvm::SubtargetFeatureKV  : 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 RISCVExtensionInfo {
   unsigned 

[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  = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap llvmDescMap;
+  for (const llvm::SubtargetFeatureKV  : 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 RISCVExtensionInfo {
   unsigned 

[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  = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap llvmDescMap;
+  for (const llvm::SubtargetFeatureKV  : 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 RISCVExtensionInfo {
   

[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  = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap llvmDescMap;
+  for (const llvm::SubtargetFeatureKV  : 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 RISCVExtensionInfo {
   

[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  = TheTargetMachine->getTargetTriple();
+  const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+  const llvm::ArrayRef Features =
+MCInfo->getAllProcessorFeatures();
+
+  llvm::StringMap llvmDescMap;
+  for (const llvm::SubtargetFeatureKV  : 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 RISCVExtensionInfo {
   

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

2023-09-19 Thread David Spickett 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  : SupportedExtensions)
 ExtMap[E.Name] = {E.Version.Major, E.Version.Minor};
-  for (const auto  : ExtMap)
-outs() << format("\t%-20s%d.%d\n", E.first.c_str(), E.second.MajorVersion,
+  for (const auto  : ExtMap) {
+outs() << format("\t%-20s%d.%d", E.first.c_str(), E.second.MajorVersion,
  E.second.MinorVersion);
+outs() << (llvmDescMap.empty() ? "\n"

DavidSpickett wrote:

> Basically with this feature we have an option to skip "Description" column at 
> all.

I see what you mean now. Yes I agree, if there's some architecture that 
provides 0 descriptions then having it doesn't make any sense.

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 David Spickett via cfe-commits


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

DavidSpickett wrote:

Yeah that's fine. All it should check is that there's no path where a lookup 
(successful or not) causes an exception.

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 David Spickett via cfe-commits


@@ -600,11 +601,17 @@ StringRef ARM::getARMCPUForArch(const llvm::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  : 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";

DavidSpickett wrote:

Sorry, I think I wasn't clear, I meant this could be one call:
```
outs() << format("\t%-20s", Ext.Name.str().c_str());
outs() << "\t\t" << llvmDescMap[Ext.Name] << "\n";
```
As in:
```
outs() << format("\t%-20s", Ext.Name.str().c_str())
  << "\t\t" << llvmDescMap[Ext.Name] << "\n";
```

I didn't mean that having an if/else was a bad idea.

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


  1   2   >