[llvm] 6445d5b - [TableGen] Allow mnemonics aliases with uppercase
Paul C. Anagnostopoulos via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 16 06:58:47 PDT 2021
Author: paperchalice
Date: 2021-04-16T09:58:20-04:00
New Revision: 6445d5ba8496d22b72b156c5dcb59d951379cebf
URL: https://github.com/llvm/llvm-project/commit/6445d5ba8496d22b72b156c5dcb59d951379cebf
DIFF: https://github.com/llvm/llvm-project/commit/6445d5ba8496d22b72b156c5dcb59d951379cebf.diff
LOG: [TableGen] Allow mnemonics aliases with uppercase
Differential Revision: https://reviews.llvm.org/D96691
Added:
Modified:
llvm/test/TableGen/MixedCasedMnemonic.td
llvm/utils/TableGen/AsmMatcherEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/test/TableGen/MixedCasedMnemonic.td b/llvm/test/TableGen/MixedCasedMnemonic.td
index b1604716e2b94..3dd6a210aa622 100644
--- a/llvm/test/TableGen/MixedCasedMnemonic.td
+++ b/llvm/test/TableGen/MixedCasedMnemonic.td
@@ -1,5 +1,6 @@
// RUN: llvm-tblgen -gen-asm-matcher -I %p/../../include %s | FileCheck %s --check-prefix=MATCHER
// RUN: llvm-tblgen -gen-asm-writer -I %p/../../include %s | FileCheck %s --check-prefix=WRITER
+// RUN: llvm-tblgen -gen-asm-matcher -I %p/../../include %s | FileCheck %s --check-prefix=ALIAS
// Check that an instruction that uses mixed upper/lower case in its mnemonic
// is printed as-is, and is parsed in its "canonicalized" lowercase form.
@@ -35,6 +36,9 @@ def AlphabeticallyFirstInst : Instruction {
let AsmString = "aInst";
}
+def :MnemonicAlias<"Insta", "aInst">;
+def :MnemonicAlias<"InstB", "BInst">;
+
// Check that the matcher lower()s the mnemonics it matches.
// MATCHER: static const char *const MnemonicTable =
// MATCHER-NEXT: "\005ainst\005binst";
@@ -53,3 +57,20 @@ def AlphabeticallyFirstInst : Instruction {
// WRITER-NEXT: "aInst\0"
// WRITER-NEXT: };
+// ALIAS: static void applyMnemonicAliases(StringRef &Mnemonic, const FeatureBitset &Features, unsigned VariantID) {
+// ALIAS-NEXT switch (VariantID) {
+// ALIAS-NEXT case 0:
+// ALIAS-NEXT switch (Mnemonic.size()) {
+// ALIAS-NEXT default: break;
+// ALIAS-NEXT case 5: // 2 strings to match.
+// ALIAS-NEXT if (memcmp(Mnemonic.data()+0, "inst", 4) != 0)
+// ALIAS-NEXT break;
+// ALIAS-NEXT switch (Mnemonic[4]) {
+// ALIAS-NEXT default: break;
+// ALIAS-NEXT case 'a': // 1 string to match.
+// ALIAS-NEXT Mnemonic = "ainst"; // "insta"
+// ALIAS-NEXT return;
+// ALIAS-NEXT case 'b': // 1 string to match.
+// ALIAS-NEXT Mnemonic = "binst"; // "instb"
+// ALIAS-NEXT return;
+
diff --git a/llvm/utils/TableGen/AsmMatcherEmitter.cpp b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
index e9aa9cdad5e50..818aed2ad939e 100644
--- a/llvm/utils/TableGen/AsmMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
@@ -2726,7 +2726,7 @@ static void emitMnemonicAliasVariant(raw_ostream &OS,const AsmMatcherInfo &Info,
StringRef AsmVariantName = R->getValueAsString("AsmVariantName");
if (AsmVariantName != AsmParserVariantName)
continue;
- AliasesFromMnemonic[std::string(R->getValueAsString("FromMnemonic"))]
+ AliasesFromMnemonic[R->getValueAsString("FromMnemonic").lower()]
.push_back(R);
}
if (AliasesFromMnemonic.empty())
@@ -2768,7 +2768,7 @@ static void emitMnemonicAliasVariant(raw_ostream &OS,const AsmMatcherInfo &Info,
MatchCode += "else ";
MatchCode += "if (" + FeatureMask + ")\n";
MatchCode += " Mnemonic = \"";
- MatchCode += R->getValueAsString("ToMnemonic");
+ MatchCode += R->getValueAsString("ToMnemonic").lower();
MatchCode += "\";\n";
}
@@ -2777,7 +2777,7 @@ static void emitMnemonicAliasVariant(raw_ostream &OS,const AsmMatcherInfo &Info,
if (!MatchCode.empty())
MatchCode += "else\n ";
MatchCode += "Mnemonic = \"";
- MatchCode += R->getValueAsString("ToMnemonic");
+ MatchCode += R->getValueAsString("ToMnemonic").lower();
MatchCode += "\";\n";
}
More information about the llvm-commits
mailing list