[llvm] e13faa4 - [X86][tablgen] Add interface getMnemonic to namespace X86Disassembler, NFCI
Shengchen Kan via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 25 18:56:38 PDT 2022
Author: Shengchen Kan
Date: 2022-03-26T09:55:54+08:00
New Revision: e13faa40cf0a727a76e395ab4123b9d2ca527b49
URL: https://github.com/llvm/llvm-project/commit/e13faa40cf0a727a76e395ab4123b9d2ca527b49
DIFF: https://github.com/llvm/llvm-project/commit/e13faa40cf0a727a76e395ab4123b9d2ca527b49.diff
LOG: [X86][tablgen] Add interface getMnemonic to namespace X86Disassembler, NFCI
Address comments in D122477 b/c `getMnemonic` is common to X86 and may be
used in more than one place.
Added:
Modified:
llvm/utils/TableGen/X86MnemonicTables.cpp
llvm/utils/TableGen/X86RecognizableInstr.cpp
llvm/utils/TableGen/X86RecognizableInstr.h
Removed:
################################################################################
diff --git a/llvm/utils/TableGen/X86MnemonicTables.cpp b/llvm/utils/TableGen/X86MnemonicTables.cpp
index 0b3f20ebc6c2f..8c899a3e57c13 100644
--- a/llvm/utils/TableGen/X86MnemonicTables.cpp
+++ b/llvm/utils/TableGen/X86MnemonicTables.cpp
@@ -59,21 +59,8 @@ void X86MnemonicTablesEmitter::run(raw_ostream &OS) {
// Skip CodeGenInstructions that are not real standalone instructions
RI.Form == X86Local::PrefixByte || RI.Form == X86Local::Pseudo)
continue;
- // Flatten an instruction assembly string.
- std::string AsmString = I->FlattenAsmStringVariants(I->AsmString, Variant);
- StringRef Mnemonic(AsmString);
- // Extract a mnemonic assuming it's separated by \t
- Mnemonic = Mnemonic.take_until([](char C) { return C == '\t'; });
-
- // Special case: CMOVCC, JCC, SETCC have "${cond}" in mnemonic.
- // Replace it with "CC" in-place.
- size_t CondPos = Mnemonic.find("${cond}");
- if (CondPos != StringRef::npos)
- Mnemonic = AsmString.replace(CondPos, StringRef::npos, "CC");
-
- // It's intentional that we put a std::string to the map (StringRef::upper
- // returns a string) as AsmString is deallocated at the end of the iteration
- MnemonicToCGInstrMap[Mnemonic.upper()].push_back(I);
+ std::string Mnemonic = X86Disassembler::getMnemonic(I, Variant);
+ MnemonicToCGInstrMap[Mnemonic].push_back(I);
}
OS << "#ifdef GET_X86_MNEMONIC_TABLES_H\n";
diff --git a/llvm/utils/TableGen/X86RecognizableInstr.cpp b/llvm/utils/TableGen/X86RecognizableInstr.cpp
index 1ae90d888a7dc..e9a9f8faf4233 100644
--- a/llvm/utils/TableGen/X86RecognizableInstr.cpp
+++ b/llvm/utils/TableGen/X86RecognizableInstr.cpp
@@ -24,6 +24,20 @@
using namespace llvm;
using namespace X86Disassembler;
+std::string X86Disassembler::getMnemonic(const CodeGenInstruction *I, unsigned Variant) {
+ std::string AsmString = I->FlattenAsmStringVariants(I->AsmString, Variant);
+ StringRef Mnemonic(AsmString);
+ // Extract a mnemonic assuming it's separated by \t
+ Mnemonic = Mnemonic.take_until([](char C) { return C == '\t'; });
+
+ // Special case: CMOVCC, JCC, SETCC have "${cond}" in mnemonic.
+ // Replace it with "CC" in-place.
+ size_t CondPos = Mnemonic.find("${cond}");
+ if (CondPos != StringRef::npos)
+ Mnemonic = AsmString.replace(CondPos, StringRef::npos, "CC");
+ return Mnemonic.upper();
+}
+
/// byteFromBitsInit - Extracts a value at most 8 bits in width from a BitsInit.
/// Useful for switch statements and the like.
///
diff --git a/llvm/utils/TableGen/X86RecognizableInstr.h b/llvm/utils/TableGen/X86RecognizableInstr.h
index debc6c516ab16..1c151511f4b5c 100644
--- a/llvm/utils/TableGen/X86RecognizableInstr.h
+++ b/llvm/utils/TableGen/X86RecognizableInstr.h
@@ -363,6 +363,7 @@ class RecognizableInstr {
InstrUID uid);
};
+std::string getMnemonic(const CodeGenInstruction *I, unsigned Variant);
} // namespace X86Disassembler
} // namespace llvm
More information about the llvm-commits
mailing list