Skip to content

Commit 170f491

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 0a95ea6 commit 170f491

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
@@ -325,7 +326,7 @@ bool isX18ReservedByDefault(const Triple &TT);
325326
// themselves, they are sequential (0, 1, 2, 3, ...).
326327
uint64_t getCpuSupportsMask(ArrayRef<StringRef> FeatureStrs);
327328

328-
void PrintSupportedExtensions(StringMap<StringRef> DescMap);
329+
void PrintSupportedExtensions();
329330

330331
} // namespace AArch64
331332
} // namespace llvm

llvm/lib/TargetParser/AArch64TargetParser.cpp

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

144-
void AArch64::PrintSupportedExtensions(StringMap<StringRef> DescMap) {
144+
void AArch64::PrintSupportedExtensions() {
145145
outs() << "All available -march extensions for AArch64\n\n"
146146
<< " " << left_justify("Name", 20)
147-
<< (DescMap.empty() ? "\n" : "Description\n");
147+
<< "Description\n";
148148
for (const auto &Ext : Extensions) {
149149
// Extensions without a feature cannot be used with -march.
150150
if (!Ext.UserVisibleName.empty() && !Ext.TargetFeature.empty()) {
151-
std::string Description = DescMap[Ext.UserVisibleName].str();
152151
outs() << " "
153-
<< format(Description.empty() ? "%s\n" : "%-20s%s\n",
154-
Ext.UserVisibleName.str().c_str(), Description.c_str());
152+
<< format(Ext.Description.empty() ? "%s\n" : "%-20s%s\n",
153+
Ext.UserVisibleName.str().c_str(),
154+
Ext.Description.str().c_str());
155155
}
156156
}
157157
}

llvm/unittests/TargetParser/TargetParserTest.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,17 +2353,11 @@ TEST(TargetParserTest, AArch64ArchExtFeature) {
23532353
TEST(TargetParserTest, AArch64PrintSupportedExtensions) {
23542354
std::string expected =
23552355
"All available -march extensions for AArch64\n\n"
2356-
" Name Description\n"
2357-
" aes This is a long dummy description\n"
2358-
" b16b16\n"
2359-
" bf16\n";
2360-
2361-
StringMap<StringRef> DummyMap;
2362-
DummyMap["aes"] = "This is a long dummy description";
2356+
" Name Description\n";
23632357

23642358
outs().flush();
23652359
testing::internal::CaptureStdout();
2366-
AArch64::PrintSupportedExtensions(DummyMap);
2360+
AArch64::PrintSupportedExtensions();
23672361
outs().flush();
23682362
std::string captured = testing::internal::GetCapturedStdout();
23692363

llvm/utils/TableGen/ARMTargetDefEmitter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ static void EmitARMTargetDef(RecordKeeper &RK, raw_ostream &OS) {
101101
else
102102
OS << ", \"" << Alias << "\"";
103103
OS << ", AArch64::" << AEK;
104+
OS << ", \"" << Rec->getValueAsString("Desc") << "\"";
104105
if (AEK == "AEK_NONE") {
105106
// HACK: don't emit posfeat/negfeat strings for FMVOnlyExtensions.
106107
OS << ", {}, {}";
@@ -113,7 +114,7 @@ static void EmitARMTargetDef(RecordKeeper &RK, raw_ostream &OS) {
113114
OS << ", " << (uint64_t)Rec->getValueAsInt("FMVPriority");
114115
OS << "},\n";
115116
};
116-
OS << " {\"none\", {}, AArch64::AEK_NONE, {}, {}, FEAT_INIT, \"\", "
117+
OS << " {\"none\", {}, AArch64::AEK_NONE, {}, {}, {}, FEAT_INIT, \"\", "
117118
"ExtensionInfo::MaxFMVPriority},\n";
118119
OS << "};\n"
119120
<< "#undef EMIT_EXTENSIONS\n"

0 commit comments

Comments
 (0)