Skip to content

Commit 443721c

Browse files
committed
[NFC][AArch64] Make extension descriptions available in TargetParser
This introduces a new field to AArch64TargetParser's ExtensionInfo struct that contains the extension description from the TableGen record. This allows us to simplify the information flow for functionality such as '--print-supported-extensions'.
1 parent 8a26772 commit 443721c

File tree

5 files changed

+12
-16
lines changed

5 files changed

+12
-16
lines changed

clang/tools/driver/cc1_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ static int PrintSupportedExtensions(std::string TargetStr) {
148148
if (MachineTriple.isRISCV())
149149
llvm::riscvExtensionsHelp(DescMap);
150150
else if (MachineTriple.isAArch64())
151-
llvm::AArch64::PrintSupportedExtensions(DescMap);
151+
llvm::AArch64::PrintSupportedExtensions();
152152
else if (MachineTriple.isARM())
153153
llvm::ARM::PrintSupportedExtensions(DescMap);
154154
else {

llvm/include/llvm/TargetParser/AArch64TargetParser.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ struct ExtensionInfo {
118118
std::optional<StringRef> Alias; // An alias for this extension, if one exists.
119119
ArchExtKind ID; // Corresponding to the ArchExtKind, this
120120
// extensions representation in the bitfield.
121+
StringRef Description; // The textual description of the extension
121122
StringRef TargetFeature; // -target-feature/-mattr enable string, e.g. "+spe"
122123
StringRef NegTargetFeature; // -target-feature/-mattr disable string, e.g. "-spe"
123124
CPUFeatures CPUFeature; // Function Multi Versioning (FMV) bitfield value
@@ -639,7 +640,7 @@ bool isX18ReservedByDefault(const Triple &TT);
639640
// themselves, they are sequential (0, 1, 2, 3, ...).
640641
uint64_t getCpuSupportsMask(ArrayRef<StringRef> FeatureStrs);
641642

642-
void PrintSupportedExtensions(StringMap<StringRef> DescMap);
643+
void PrintSupportedExtensions();
643644

644645
} // namespace AArch64
645646
} // namespace llvm

llvm/lib/TargetParser/AArch64TargetParser.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,17 @@ std::optional<AArch64::CpuInfo> AArch64::parseCpu(StringRef Name) {
136136
return {};
137137
}
138138

139-
void AArch64::PrintSupportedExtensions(StringMap<StringRef> DescMap) {
139+
void AArch64::PrintSupportedExtensions() {
140140
outs() << "All available -march extensions for AArch64\n\n"
141141
<< " " << left_justify("Name", 20)
142-
<< (DescMap.empty() ? "\n" : "Description\n");
142+
<< "Description\n";
143143
for (const auto &Ext : Extensions) {
144144
// Extensions without a feature cannot be used with -march.
145145
if (!Ext.UserVisibleName.empty() && !Ext.TargetFeature.empty()) {
146-
std::string Description = DescMap[Ext.UserVisibleName].str();
147146
outs() << " "
148-
<< format(Description.empty() ? "%s\n" : "%-20s%s\n",
149-
Ext.UserVisibleName.str().c_str(), Description.c_str());
147+
<< format(Ext.Description.empty() ? "%s\n" : "%-20s%s\n",
148+
Ext.UserVisibleName.str().c_str(),
149+
Ext.Description.str().c_str());
150150
}
151151
}
152152
}

llvm/unittests/TargetParser/TargetParserTest.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,17 +2316,11 @@ TEST(TargetParserTest, AArch64ArchExtFeature) {
23162316
TEST(TargetParserTest, AArch64PrintSupportedExtensions) {
23172317
std::string expected =
23182318
"All available -march extensions for AArch64\n\n"
2319-
" Name Description\n"
2320-
" aes This is a long dummy description\n"
2321-
" b16b16\n"
2322-
" bf16\n";
2323-
2324-
StringMap<StringRef> DummyMap;
2325-
DummyMap["aes"] = "This is a long dummy description";
2319+
" Name Description\n";
23262320

23272321
outs().flush();
23282322
testing::internal::CaptureStdout();
2329-
AArch64::PrintSupportedExtensions(DummyMap);
2323+
AArch64::PrintSupportedExtensions();
23302324
outs().flush();
23312325
std::string captured = testing::internal::GetCapturedStdout();
23322326

llvm/utils/TableGen/ARMTargetDefEmitter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ static void EmitARMTargetDef(RecordKeeper &RK, raw_ostream &OS) {
9797
else
9898
OS << ", \"" << Alias << "\"";
9999
OS << ", AArch64::" << AEK;
100+
OS << ", \"" << Rec->getValueAsString("Desc") << "\"";
100101
if (AEK == "AEK_NONE") {
101102
// HACK: don't emit posfeat/negfeat strings for FMVOnlyExtensions.
102103
OS << ", {}, {}";
@@ -109,7 +110,7 @@ static void EmitARMTargetDef(RecordKeeper &RK, raw_ostream &OS) {
109110
OS << ", " << (uint64_t)Rec->getValueAsInt("FMVPriority");
110111
OS << "},\n";
111112
};
112-
OS << " {\"none\", {}, AArch64::AEK_NONE, {}, {}, FEAT_INIT, \"\", "
113+
OS << " {\"none\", {}, AArch64::AEK_NONE, {}, {}, {}, FEAT_INIT, \"\", "
113114
"ExtensionInfo::MaxFMVPriority},\n";
114115
OS << "};\n"
115116
<< "#undef EMIT_EXTENSIONS\n"

0 commit comments

Comments
 (0)