Skip to content

Commit 45af8b7

Browse files
pratlucasarsenm
authored andcommitted
[AArch64] Add ability to list extensions enabled for a target (#95805)
This introduces the new `--print-enabled-extensions` command line option to AArch64, which prints the list of extensions that are enabled for the target specified by the combination of `--target`/`-march`/`-mcpu` values. The goal of the this option is both to enable the manual inspection of the enabled extensions by users and to enhance the testability of architecture versions and CPU targets implemented in the compiler. As part of this change, a new field for `FEAT_*` architecture feature names was added to the TableGen entries. The output of the existing `--print-supported-extensions` option was updated accordingly to show these in a separate column.
1 parent f27377e commit 45af8b7

35 files changed

+1302
-422
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5710,6 +5710,11 @@ def print_supported_extensions : Flag<["-", "--"], "print-supported-extensions">
57105710
Visibility<[ClangOption, CC1Option, CLOption]>,
57115711
HelpText<"Print supported -march extensions (RISC-V, AArch64 and ARM only)">,
57125712
MarshallingInfoFlag<FrontendOpts<"PrintSupportedExtensions">>;
5713+
def print_enabled_extensions : Flag<["-", "--"], "print-enabled-extensions">,
5714+
Visibility<[ClangOption, CC1Option, CLOption]>,
5715+
HelpText<"Print the extensions enabled by the given target and -march/-mcpu options."
5716+
" (AArch64 only)">,
5717+
MarshallingInfoFlag<FrontendOpts<"PrintEnabledExtensions">>;
57135718
def : Flag<["-"], "mcpu=help">, Alias<print_supported_cpus>;
57145719
def : Flag<["-"], "mtune=help">, Alias<print_supported_cpus>;
57155720
def time : Flag<["-"], "time">,

clang/include/clang/Frontend/FrontendOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,10 @@ class FrontendOptions {
306306
LLVM_PREFERRED_TYPE(bool)
307307
unsigned PrintSupportedExtensions : 1;
308308

309+
/// Print the extensions enabled for the current target.
310+
LLVM_PREFERRED_TYPE(bool)
311+
unsigned PrintEnabledExtensions : 1;
312+
309313
/// Show the -version text.
310314
LLVM_PREFERRED_TYPE(bool)
311315
unsigned ShowVersion : 1;

clang/lib/Driver/Driver.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ phases::ID Driver::getFinalPhase(const DerivedArgList &DAL,
363363
// -{fsyntax-only,-analyze,emit-ast} only run up to the compiler.
364364
} else if ((PhaseArg = DAL.getLastArg(options::OPT_fsyntax_only)) ||
365365
(PhaseArg = DAL.getLastArg(options::OPT_print_supported_cpus)) ||
366+
(PhaseArg = DAL.getLastArg(options::OPT_print_enabled_extensions)) ||
366367
(PhaseArg = DAL.getLastArg(options::OPT_module_file_info)) ||
367368
(PhaseArg = DAL.getLastArg(options::OPT_verify_pch)) ||
368369
(PhaseArg = DAL.getLastArg(options::OPT_rewrite_objc)) ||
@@ -2163,7 +2164,8 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
21632164
if (C.getArgs().hasArg(options::OPT_v) ||
21642165
C.getArgs().hasArg(options::OPT__HASH_HASH_HASH) ||
21652166
C.getArgs().hasArg(options::OPT_print_supported_cpus) ||
2166-
C.getArgs().hasArg(options::OPT_print_supported_extensions)) {
2167+
C.getArgs().hasArg(options::OPT_print_supported_extensions) ||
2168+
C.getArgs().hasArg(options::OPT_print_enabled_extensions)) {
21672169
PrintVersion(C, llvm::errs());
21682170
SuppressMissingInputWarning = true;
21692171
}
@@ -4347,13 +4349,14 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
43474349
}
43484350

43494351
for (auto Opt : {options::OPT_print_supported_cpus,
4350-
options::OPT_print_supported_extensions}) {
4352+
options::OPT_print_supported_extensions,
4353+
options::OPT_print_enabled_extensions}) {
43514354
// If --print-supported-cpus, -mcpu=? or -mtune=? is specified, build a
43524355
// custom Compile phase that prints out supported cpu models and quits.
43534356
//
4354-
// If --print-supported-extensions is specified, call the helper function
4355-
// RISCVMarchHelp in RISCVISAInfo.cpp that prints out supported extensions
4356-
// and quits.
4357+
// If either --print-supported-extensions or --print-enabled-extensions is
4358+
// specified, call the corresponding helper function that prints out the
4359+
// supported/enabled extensions and quits.
43574360
if (Arg *A = Args.getLastArg(Opt)) {
43584361
if (Opt == options::OPT_print_supported_extensions &&
43594362
!C.getDefaultToolChain().getTriple().isRISCV() &&
@@ -4363,6 +4366,12 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
43634366
<< "--print-supported-extensions";
43644367
return;
43654368
}
4369+
if (Opt == options::OPT_print_enabled_extensions &&
4370+
!C.getDefaultToolChain().getTriple().isAArch64()) {
4371+
C.getDriver().Diag(diag::err_opt_not_valid_on_target)
4372+
<< "--print-enabled-extensions";
4373+
return;
4374+
}
43664375

43674376
// Use the -mcpu=? flag as the dummy input to cc1.
43684377
Actions.clear();

clang/lib/Driver/ToolChain.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ static void getAArch64MultilibFlags(const Driver &D,
195195
UnifiedFeatures.end());
196196
std::vector<std::string> MArch;
197197
for (const auto &Ext : AArch64::Extensions)
198-
if (FeatureSet.contains(Ext.Feature))
199-
MArch.push_back(Ext.Name.str());
198+
if (FeatureSet.contains(Ext.PosTargetFeature))
199+
MArch.push_back(Ext.UserVisibleName.str());
200200
for (const auto &Ext : AArch64::Extensions)
201-
if (FeatureSet.contains(Ext.NegFeature))
202-
MArch.push_back(("no" + Ext.Name).str());
201+
if (FeatureSet.contains(Ext.NegTargetFeature))
202+
MArch.push_back(("no" + Ext.UserVisibleName).str());
203203
StringRef ArchName;
204204
for (const auto &ArchInfo : AArch64::ArchInfos)
205205
if (FeatureSet.contains(ArchInfo->ArchFeature))

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,7 @@ static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args,
15241524
auto isPAuthLR = [](const char *member) {
15251525
llvm::AArch64::ExtensionInfo pauthlr_extension =
15261526
llvm::AArch64::getExtensionByID(llvm::AArch64::AEK_PAUTHLR);
1527-
return pauthlr_extension.Feature == member;
1527+
return pauthlr_extension.PosTargetFeature == member;
15281528
};
15291529

15301530
if (std::any_of(CmdArgs.begin(), CmdArgs.end(), isPAuthLR))

clang/test/CodeGen/aarch64-targetattr.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,14 @@ void minusarch() {}
196196
// CHECK: attributes #[[ATTR1]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+v8.1a,+v8.2a,+v8a" }
197197
// CHECK: attributes #[[ATTR2]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8a" }
198198
// CHECK: attributes #[[ATTR3]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+complxnum,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+neon,+pauth,+ras,+rcpc,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a" }
199-
// CHECK: attributes #[[ATTR4]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="cortex-a710" "target-features"="+bf16,+complxnum,+crc,+dotprod,+flagm,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+mte,+neon,+pauth,+perfmon,+ras,+rcpc,+rdm,+sb,+sve,+sve2,+sve2-bitperm,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8a,+v9a" }
199+
// CHECK: attributes #[[ATTR4]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="cortex-a710" "target-features"="+bf16,+complxnum,+crc,+dotprod,+ete,+flagm,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+mte,+neon,+pauth,+perfmon,+ras,+rcpc,+rdm,+sb,+sve,+sve2,+sve2-bitperm,+trbe,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8a,+v9a" }
200200
// CHECK: attributes #[[ATTR5]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "tune-cpu"="cortex-a710" }
201-
// CHECK: attributes #[[ATTR6]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="generic" "target-features"="+fp-armv8,+neon,+v8a" }
201+
// CHECK: attributes #[[ATTR6]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="generic" "target-features"="+ete,+fp-armv8,+neon,+trbe,+v8a" }
202202
// CHECK: attributes #[[ATTR7]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "tune-cpu"="generic" }
203203
// CHECK: attributes #[[ATTR8]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="neoverse-n1" "target-features"="+aes,+crc,+dotprod,+fp-armv8,+fullfp16,+lse,+neon,+perfmon,+ras,+rcpc,+rdm,+sha2,+spe,+ssbs,+v8.1a,+v8.2a,+v8a" "tune-cpu"="cortex-a710" }
204204
// CHECK: attributes #[[ATTR9]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+fp-armv8,+fullfp16,+sve" "tune-cpu"="cortex-a710" }
205-
// CHECK: attributes #[[ATTR10]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="neoverse-v1" "target-features"="+aes,+bf16,+complxnum,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+neon,+pauth,+perfmon,+rand,+ras,+rcpc,+rdm,+sha2,+sha3,+sm4,+spe,+ssbs,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8a" }
206-
// CHECK: attributes #[[ATTR11]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="neoverse-v1" "target-features"="+aes,+bf16,+complxnum,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+neon,+pauth,+perfmon,+rand,+ras,+rcpc,+rdm,+sha2,+sha3,+sm4,+spe,+ssbs,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8a,-sve" }
205+
// CHECK: attributes #[[ATTR10]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="neoverse-v1" "target-features"="+aes,+bf16,+ccdp,+complxnum,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+neon,+pauth,+perfmon,+rand,+ras,+rcpc,+rdm,+sha2,+sha3,+sm4,+spe,+ssbs,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8a" }
206+
// CHECK: attributes #[[ATTR11]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="neoverse-v1" "target-features"="+aes,+bf16,+ccdp,+complxnum,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+neon,+pauth,+perfmon,+rand,+ras,+rcpc,+rdm,+sha2,+sha3,+sm4,+spe,+ssbs,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8a,-sve" }
207207
// CHECK: attributes #[[ATTR12]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+fp-armv8,+fullfp16,+sve" }
208208
// CHECK: attributes #[[ATTR13]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+fp-armv8,+fullfp16" }
209209
// CHECK: attributes #[[ATTR14]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="neoverse-n1" "target-features"="+aes,+bf16,+complxnum,+crc,+dotprod,+fp-armv8,+fullfp16,+i8mm,+jsconv,+lse,+neon,+pauth,+perfmon,+ras,+rcpc,+rdm,+sha2,+spe,+ssbs,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a" "tune-cpu"="cortex-a710" }

0 commit comments

Comments
 (0)