Skip to content

Commit 9e03afe

Browse files
DavidSpickettZijunZhaoCCK
authored andcommitted
[clang][ARM] Enable --print-supported-extensions for ARM (llvm#66083)
``` $ ./bin/clang --target=arm-linux-gnueabihf --print-supported-extensions <...> All available -march extensions for ARM crc crypto sha2 aes dotprod <...> ``` This follows the format set by RISC-V and AArch64. As for AArch64, ARM doesn't have versioned extensions like RISC-V does. So there is only 1 column, which contains the name. Any extension without a "feature" is hidden as these cannot be used with -march.
1 parent b24cd6c commit 9e03afe

File tree

7 files changed

+45
-2
lines changed

7 files changed

+45
-2
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5271,7 +5271,7 @@ def print_supported_cpus : Flag<["-", "--"], "print-supported-cpus">,
52715271
MarshallingInfoFlag<FrontendOpts<"PrintSupportedCPUs">>;
52725272
def print_supported_extensions : Flag<["-", "--"], "print-supported-extensions">,
52735273
Visibility<[ClangOption, CC1Option, CLOption]>,
5274-
HelpText<"Print supported -march extensions (RISC-V and AArch64 only)">,
5274+
HelpText<"Print supported -march extensions (RISC-V, AArch64 and ARM only)">,
52755275
MarshallingInfoFlag<FrontendOpts<"PrintSupportedExtensions">>;
52765276
def : Flag<["-"], "mcpu=help">, Alias<print_supported_cpus>;
52775277
def : Flag<["-"], "mtune=help">, Alias<print_supported_cpus>;

clang/lib/Driver/Driver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4285,7 +4285,8 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
42854285
if (Arg *A = Args.getLastArg(Opt)) {
42864286
if (Opt == options::OPT_print_supported_extensions &&
42874287
!C.getDefaultToolChain().getTriple().isRISCV() &&
4288-
!C.getDefaultToolChain().getTriple().isAArch64()) {
4288+
!C.getDefaultToolChain().getTriple().isAArch64() &&
4289+
!C.getDefaultToolChain().getTriple().isARM()) {
42894290
C.getDriver().Diag(diag::err_opt_not_valid_on_target)
42904291
<< "--print-supported-extensions";
42914292
return;

clang/test/Driver/print-supported-extensions.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
// RUN: --print-supported-extensions 2>&1 | FileCheck %s --check-prefix RISCV %}
1010
// RISCV: All available -march extensions for RISC-V
1111

12+
// RUN: %if arm-registered-target %{ %clang --target=arm-linux-gnu \
13+
// RUN: --print-supported-extensions 2>&1 | FileCheck %s --check-prefix ARM %}
14+
// ARM: All available -march extensions for ARM
15+
1216
// RUN: %if x86-registered-target %{ not %clang --target=x86_64-linux-gnu \
1317
// RUN: --print-supported-extensions 2>&1 | FileCheck %s --check-prefix X86 %}
1418
// X86: error: option '--print-supported-extensions' cannot be specified on this target

clang/tools/driver/cc1_main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "llvm/Support/raw_ostream.h"
4747
#include "llvm/Target/TargetMachine.h"
4848
#include "llvm/TargetParser/AArch64TargetParser.h"
49+
#include "llvm/TargetParser/ARMTargetParser.h"
4950
#include <cstdio>
5051

5152
#ifdef CLANG_HAVE_RLIMITS
@@ -202,6 +203,8 @@ static int PrintSupportedExtensions(std::string TargetStr) {
202203
llvm::riscvExtensionsHelp();
203204
else if (MachineTriple.isAArch64())
204205
llvm::AArch64::PrintSupportedExtensions();
206+
else if (MachineTriple.isARM())
207+
llvm::ARM::PrintSupportedExtensions();
205208
else {
206209
// The option was already checked in Driver::HandleImmediateArgs,
207210
// so we do not expect to get here if we are not a supported architecture.

llvm/include/llvm/TargetParser/ARMTargetParser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ StringRef computeDefaultTargetABI(const Triple &TT, StringRef CPU);
259259
/// string then the triple's arch name is used.
260260
StringRef getARMCPUForArch(const llvm::Triple &Triple, StringRef MArch = {});
261261

262+
void PrintSupportedExtensions();
263+
262264
} // namespace ARM
263265
} // namespace llvm
264266

llvm/lib/TargetParser/ARMTargetParser.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "llvm/TargetParser/ARMTargetParser.h"
1515
#include "llvm/ADT/StringSwitch.h"
16+
#include "llvm/Support/raw_ostream.h"
1617
#include "llvm/TargetParser/ARMTargetParserCommon.h"
1718
#include "llvm/TargetParser/Triple.h"
1819
#include <cctype>
@@ -598,3 +599,12 @@ StringRef ARM::getARMCPUForArch(const llvm::Triple &Triple, StringRef MArch) {
598599

599600
llvm_unreachable("invalid arch name");
600601
}
602+
603+
void ARM::PrintSupportedExtensions() {
604+
outs() << "All available -march extensions for ARM\n\n";
605+
for (const auto &Ext : ARCHExtNames) {
606+
// Extensions without a feature cannot be used with -march.
607+
if (!Ext.Feature.empty())
608+
outs() << '\t' << Ext.Name << "\n";
609+
}
610+
}

llvm/unittests/TargetParser/TargetParserTest.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,29 @@ TEST(TargetParserTest, getARMCPUForArch) {
10101010
}
10111011
}
10121012

1013+
TEST(TargetParserTest, ARMPrintSupportedExtensions) {
1014+
std::string expected = "All available -march extensions for ARM\n\n"
1015+
"\tcrc\n\tcrypto\n\tsha2";
1016+
1017+
outs().flush();
1018+
testing::internal::CaptureStdout();
1019+
ARM::PrintSupportedExtensions();
1020+
outs().flush();
1021+
std::string captured = testing::internal::GetCapturedStdout();
1022+
1023+
// Check that the start of the output is as expected.
1024+
EXPECT_EQ(0ULL, captured.find(expected));
1025+
1026+
// Should not include "none" or "invalid".
1027+
EXPECT_EQ(std::string::npos, captured.find("none"));
1028+
EXPECT_EQ(std::string::npos, captured.find("invalid"));
1029+
// Should not include anything that lacks a feature name. Checking a few here
1030+
// but not all as if one is hidden correctly the rest should be.
1031+
EXPECT_EQ(std::string::npos, captured.find("simd"));
1032+
EXPECT_EQ(std::string::npos, captured.find("maverick"));
1033+
EXPECT_EQ(std::string::npos, captured.find("xscale"));
1034+
}
1035+
10131036
class AArch64CPUTestFixture
10141037
: public ::testing::TestWithParam<
10151038
ARMCPUTestParams<AArch64::ExtensionBitset>> {};

0 commit comments

Comments
 (0)