[llvm] [TableGen] Remove duplicate code in applyMnemonicAliases when target uses DefaultAsmParserVariant. (PR #108494)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 12 22:30:08 PDT 2024
https://github.com/topperc created https://github.com/llvm/llvm-project/pull/108494
The DefaultAsmParserVariant has an empty name. MnemonicAliases use an empty string to mean the aliases 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.
>From cbb772d509d54e51e4b6261b40f6a7559bc4011d Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Thu, 12 Sep 2024 22:12:47 -0700
Subject: [PATCH] [TableGen] Remove duplicate code in applyMnemonicAliases when
target uses DefaultAsmParserVariant.
The DefaultAsmParserVariant has an empty name. MnemonicAliases
use an empty string to mean the aliases 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.
---
llvm/utils/TableGen/AsmMatcherEmitter.cpp | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/llvm/utils/TableGen/AsmMatcherEmitter.cpp b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
index ef5186451b9eae..654b21dd4aaffe 100644
--- a/llvm/utils/TableGen/AsmMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
@@ -2849,18 +2849,29 @@ static bool emitMnemonicAliases(raw_ostream &OS, const AsmMatcherInfo &Info,
OS << "static void applyMnemonicAliases(StringRef &Mnemonic, "
"const FeatureBitset &Features, unsigned VariantID) {\n";
- OS << " switch (VariantID) {\n";
unsigned VariantCount = Target.getAsmParserVariantCount();
for (unsigned VC = 0; VC != VariantCount; ++VC) {
Record *AsmVariant = Target.getAsmParserVariant(VC);
int AsmParserVariantNo = AsmVariant->getValueAsInt("Variant");
StringRef AsmParserVariantName = AsmVariant->getValueAsString("Name");
+
+ // If the variant doesn't have a name, defer to the emitMnemonicAliasVariant
+ // call after the loop.
+ if (AsmParserVariantName.empty()) {
+ assert(VariantCount == 1 && "Multiple variants should each be named");
+ continue;
+ }
+
+ if (VC == 0)
+ OS << " switch (VariantID) {\n";
OS << " case " << AsmParserVariantNo << ":\n";
emitMnemonicAliasVariant(OS, Info, Aliases, /*Indent=*/2,
AsmParserVariantName);
OS << " break;\n";
+
+ if (VC == VariantCount - 1)
+ OS << " }\n";
}
- OS << " }\n";
// Emit aliases that apply to all variants.
emitMnemonicAliasVariant(OS, Info, Aliases);
More information about the llvm-commits
mailing list