aboutsummaryrefslogtreecommitdiff
path: root/clang/tools/driver/cc1_main.cpp
diff options
context:
space:
mode:
authorDavid Spickett <david.spickett@linaro.org>2023-09-11 08:25:02 +0100
committerGitHub <noreply@github.com>2023-09-11 08:25:02 +0100
commit90db4193f82937bff68c8f8a1481320f245f04ff (patch)
treeb45bea510b141d12b9b4a68fca671a7cce0fe19d /clang/tools/driver/cc1_main.cpp
parent00add6ed24a0f625f28c1cc27bb8579001d5fa7a (diff)
downloadllvm-90db4193f82937bff68c8f8a1481320f245f04ff.zip
llvm-90db4193f82937bff68c8f8a1481320f245f04ff.tar.gz
llvm-90db4193f82937bff68c8f8a1481320f245f04ff.tar.bz2
[clang][AArch64] Add --print-supported-extensions support (#65466)
This follows the RISC-V work done in 4b40ced4e5ba10b841516b3970e7699ba8ded572. This uses AArch64's target parser instead. We just list the names, without the "+" on them, which matches RISC-V's format. ``` $ ./bin/clang -target aarch64-linux-gnu --print-supported-extensions clang version 18.0.0 (https://github.com/llvm/llvm-project.git 154da8aec20719c82235a6957aa6e461f5a5e030) Target: aarch64-unknown-linux-gnu Thread model: posix InstalledDir: <...> All available -march extensions for AArch64 aes b16b16 bf16 brbe crc crypto cssc <...> ``` Since our extensions don't have versions in the same way there's just one column with the name in. Any extension without a feature name (including the special "none") is not listed as those cannot be passed to -march, they're just for the backend. For example the MTE extension can be added with "+memtag" but MTE2 and MTE3 do not have feature names so they cannot be added to -march. This does not attempt to tackle the fact that clang allows invalid combinations of AArch64 extensions, it simply lists the possible options. It's still up to the user to ask for something sensible. Equally, this has no context of what CPU is being selected. Neither does the RISC-V option, the user has to be aware of that. I've added a target parser test, and a high level clang test that checks RISC-V and AArch64 work and that Intel, that doesn't support this, shows the correct error.
Diffstat (limited to 'clang/tools/driver/cc1_main.cpp')
-rw-r--r--clang/tools/driver/cc1_main.cpp31
1 files changed, 30 insertions, 1 deletions
diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index ab886d0..ed68a11 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -45,6 +45,7 @@
#include "llvm/Support/Timer.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
+#include "llvm/TargetParser/AArch64TargetParser.h"
#include <cstdio>
#ifdef CLANG_HAVE_RLIMITS
@@ -183,6 +184,34 @@ static int PrintSupportedCPUs(std::string TargetStr) {
return 0;
}
+static int PrintSupportedExtensions(std::string TargetStr) {
+ std::string Error;
+ const llvm::Target *TheTarget =
+ llvm::TargetRegistry::lookupTarget(TargetStr, Error);
+ if (!TheTarget) {
+ llvm::errs() << Error;
+ return 1;
+ }
+
+ llvm::TargetOptions Options;
+ std::unique_ptr<llvm::TargetMachine> TheTargetMachine(
+ TheTarget->createTargetMachine(TargetStr, "", "", Options, std::nullopt));
+ const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
+
+ if (MachineTriple.isRISCV())
+ llvm::riscvExtensionsHelp();
+ else if (MachineTriple.isAArch64())
+ llvm::AArch64::PrintSupportedExtensions();
+ else {
+ // The option was already checked in Driver::HandleImmediateArgs,
+ // so we do not expect to get here if we are not a supported architecture.
+ assert(0 && "Unhandled triple for --print-supported-extensions option.");
+ return 1;
+ }
+
+ return 0;
+}
+
int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
ensureSufficientStack();
@@ -224,7 +253,7 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
// --print-supported-extensions takes priority over the actual compilation.
if (Clang->getFrontendOpts().PrintSupportedExtensions)
- return llvm::riscvExtensionsHelp(), 0;
+ return PrintSupportedExtensions(Clang->getTargetOpts().Triple);
// Infer the builtin include path if unspecified.
if (Clang->getHeaderSearchOpts().UseBuiltinIncludes &&