Skip to content

Commit 520ddf2

Browse files
authored
[TableGen] Remove duplicate code in applyMnemonicAliases when target uses DefaultAsmParserVariant. (#108494)
The DefaultAsmParserVariant has an empty name. MnemonicAlias uses an empty string to mean the alias applies to all variants. Targets that uses DefaultAsmParserVariant were emitting the same code inside the variant loop and after the variant loop because an empty string got passed to emitMnemonicAliasVariant in both places. This patch detects the empty variant name in the loop and skips the emission.
1 parent 57aaf5e commit 520ddf2

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

llvm/utils/TableGen/AsmMatcherEmitter.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2849,18 +2849,29 @@ static bool emitMnemonicAliases(raw_ostream &OS, const AsmMatcherInfo &Info,
28492849

28502850
OS << "static void applyMnemonicAliases(StringRef &Mnemonic, "
28512851
"const FeatureBitset &Features, unsigned VariantID) {\n";
2852-
OS << " switch (VariantID) {\n";
28532852
unsigned VariantCount = Target.getAsmParserVariantCount();
28542853
for (unsigned VC = 0; VC != VariantCount; ++VC) {
28552854
Record *AsmVariant = Target.getAsmParserVariant(VC);
28562855
int AsmParserVariantNo = AsmVariant->getValueAsInt("Variant");
28572856
StringRef AsmParserVariantName = AsmVariant->getValueAsString("Name");
2857+
2858+
// If the variant doesn't have a name, defer to the emitMnemonicAliasVariant
2859+
// call after the loop.
2860+
if (AsmParserVariantName.empty()) {
2861+
assert(VariantCount == 1 && "Multiple variants should each be named");
2862+
continue;
2863+
}
2864+
2865+
if (VC == 0)
2866+
OS << " switch (VariantID) {\n";
28582867
OS << " case " << AsmParserVariantNo << ":\n";
28592868
emitMnemonicAliasVariant(OS, Info, Aliases, /*Indent=*/2,
28602869
AsmParserVariantName);
28612870
OS << " break;\n";
2871+
2872+
if (VC == VariantCount - 1)
2873+
OS << " }\n";
28622874
}
2863-
OS << " }\n";
28642875

28652876
// Emit aliases that apply to all variants.
28662877
emitMnemonicAliasVariant(OS, Info, Aliases);

0 commit comments

Comments
 (0)