forked from OSchip/llvm-project
Shrink the asm matcher tables.
- Shrink the opcode field to 16 bits. - Shrink the AsmVariantID field to 8 bits. - Store the mnemonic string in a string table, store a 16 bit index. - Store a pascal-style length byte in the string instead of a null terminator, so we can avoid calling strlen on every entry we visit during mnemonic search. Shrinks X86AsmParser.o from 434k to 201k on x86_64 and eliminates relocs from the table. llvm-svn: 151984
This commit is contained in:
parent
dbe7f3bf2e
commit
5aeee5f854
|
@ -99,6 +99,7 @@
|
|||
#include "AsmMatcherEmitter.h"
|
||||
#include "CodeGenTarget.h"
|
||||
#include "StringMatcher.h"
|
||||
#include "StringToOffsetTable.h"
|
||||
#include "llvm/ADT/OwningPtr.h"
|
||||
#include "llvm/ADT/PointerUnion.h"
|
||||
#include "llvm/ADT/SmallPtrSet.h"
|
||||
|
@ -2302,32 +2303,39 @@ void AsmMatcherEmitter::run(raw_ostream &OS) {
|
|||
// following the mnemonic.
|
||||
OS << "namespace {\n";
|
||||
OS << " struct MatchEntry {\n";
|
||||
OS << " unsigned Opcode;\n";
|
||||
OS << " const char *Mnemonic;\n";
|
||||
OS << " static const char *MnemonicTable;\n";
|
||||
OS << " uint16_t Opcode;\n";
|
||||
OS << " uint16_t Mnemonic;\n";
|
||||
OS << " " << getMinimalTypeForRange(Info.Matchables.size())
|
||||
<< " ConvertFn;\n";
|
||||
OS << " " << getMinimalTypeForRange(Info.Classes.size())
|
||||
<< " Classes[" << MaxNumOperands << "];\n";
|
||||
OS << " " << getMinimalTypeForRange(1ULL << Info.SubtargetFeatures.size())
|
||||
<< " RequiredFeatures;\n";
|
||||
OS << " unsigned AsmVariantID;\n";
|
||||
OS << " uint8_t AsmVariantID;\n\n";
|
||||
OS << " StringRef getMnemonic() const {\n";
|
||||
OS << " return StringRef(MnemonicTable + Mnemonic + 1,\n";
|
||||
OS << " MnemonicTable[Mnemonic]);\n";
|
||||
OS << " }\n";
|
||||
OS << " };\n\n";
|
||||
|
||||
OS << " // Predicate for searching for an opcode.\n";
|
||||
OS << " struct LessOpcode {\n";
|
||||
OS << " bool operator()(const MatchEntry &LHS, StringRef RHS) {\n";
|
||||
OS << " return StringRef(LHS.Mnemonic) < RHS;\n";
|
||||
OS << " return LHS.getMnemonic() < RHS;\n";
|
||||
OS << " }\n";
|
||||
OS << " bool operator()(StringRef LHS, const MatchEntry &RHS) {\n";
|
||||
OS << " return LHS < StringRef(RHS.Mnemonic);\n";
|
||||
OS << " return LHS < RHS.getMnemonic();\n";
|
||||
OS << " }\n";
|
||||
OS << " bool operator()(const MatchEntry &LHS, const MatchEntry &RHS) {\n";
|
||||
OS << " return StringRef(LHS.Mnemonic) < StringRef(RHS.Mnemonic);\n";
|
||||
OS << " return LHS.getMnemonic() < RHS.getMnemonic();\n";
|
||||
OS << " }\n";
|
||||
OS << " };\n";
|
||||
|
||||
OS << "} // end anonymous namespace.\n\n";
|
||||
|
||||
StringToOffsetTable StringTable;
|
||||
|
||||
OS << "static const MatchEntry MatchTable["
|
||||
<< Info.Matchables.size() << "] = {\n";
|
||||
|
||||
|
@ -2336,8 +2344,11 @@ void AsmMatcherEmitter::run(raw_ostream &OS) {
|
|||
it != ie; ++it) {
|
||||
MatchableInfo &II = **it;
|
||||
|
||||
// Store a pascal-style length byte in the mnemonic.
|
||||
std::string LenMnemonic = char(II.Mnemonic.size()) + II.Mnemonic.str();
|
||||
OS << " { " << Target.getName() << "::"
|
||||
<< II.getResultInst()->TheDef->getName() << ", \"" << II.Mnemonic << "\""
|
||||
<< II.getResultInst()->TheDef->getName() << ", "
|
||||
<< StringTable.GetOrAddStringOffset(LenMnemonic, false)
|
||||
<< ", " << II.ConversionFnKind << ", { ";
|
||||
for (unsigned i = 0, e = II.AsmOperands.size(); i != e; ++i) {
|
||||
MatchableInfo::AsmOperand &Op = II.AsmOperands[i];
|
||||
|
@ -2361,6 +2372,10 @@ void AsmMatcherEmitter::run(raw_ostream &OS) {
|
|||
|
||||
OS << "};\n\n";
|
||||
|
||||
OS << "const char *MatchEntry::MnemonicTable =\n";
|
||||
StringTable.EmitString(OS);
|
||||
OS << ";\n\n";
|
||||
|
||||
// A method to determine if a mnemonic is in the list.
|
||||
OS << "bool " << Target.getName() << ClassName << "::\n"
|
||||
<< "MnemonicIsValid(StringRef Mnemonic) {\n";
|
||||
|
@ -2424,7 +2439,7 @@ void AsmMatcherEmitter::run(raw_ostream &OS) {
|
|||
OS << " it != ie; ++it) {\n";
|
||||
|
||||
OS << " // equal_range guarantees that instruction mnemonic matches.\n";
|
||||
OS << " assert(Mnemonic == it->Mnemonic);\n";
|
||||
OS << " assert(Mnemonic == it->getMnemonic());\n";
|
||||
|
||||
// Emit check that the subclasses match.
|
||||
OS << " if (VariantID != it->AsmVariantID) continue;\n";
|
||||
|
|
Loading…
Reference in New Issue