Use SequenceToOffsetTable to create instruction name table. Saves space particularly on X86 where AVX instructions just add a 'v' to the front of other instructions.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153841 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Craig Topper 2012-04-01 18:14:14 +00:00
parent 243018ffcf
commit 413b2e7539

View File

@ -14,7 +14,7 @@
#include "InstrInfoEmitter.h"
#include "CodeGenTarget.h"
#include "StringToOffsetTable.h"
#include "SequenceToOffsetTable.h"
#include "llvm/TableGen/Record.h"
#include "llvm/ADT/StringExtras.h"
#include <algorithm>
@ -214,21 +214,28 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
OperandInfoIDs, OS);
OS << "};\n\n";
OS << "extern const unsigned " << TargetName <<"InstrNameIndices[] = {\n ";
StringToOffsetTable StringTable;
// Build an array of instruction names
SequenceToOffsetTable<std::string> InstrNames;
for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
const CodeGenInstruction *Instr = NumberedInstructions[i];
OS << StringTable.GetOrAddStringOffset(Instr->TheDef->getName()) << "U, ";
InstrNames.add(Instr->TheDef->getName());
}
InstrNames.layout();
OS << "extern const char " << TargetName << "InstrNameData[] = {\n";
InstrNames.emit(OS, printChar);
OS << "};\n\n";
OS << "extern const unsigned " << TargetName <<"InstrNameIndices[] = {";
for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
if (i % 8 == 0)
OS << "\n ";
const CodeGenInstruction *Instr = NumberedInstructions[i];
OS << InstrNames.get(Instr->TheDef->getName()) << "U, ";
}
OS << "\n};\n\n";
OS << "const char *" << TargetName << "InstrNameData =\n";
StringTable.EmitString(OS);
OS << ";\n\n";
// MCInstrInfo initialization routine.
OS << "static inline void Init" << TargetName
<< "MCInstrInfo(MCInstrInfo *II) {\n";
@ -259,7 +266,7 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
OS << "namespace llvm {\n";
OS << "extern const MCInstrDesc " << TargetName << "Insts[];\n";
OS << "extern const unsigned " << TargetName << "InstrNameIndices[];\n";
OS << "extern const char *" << TargetName << "InstrNameData;\n";
OS << "extern const char " << TargetName << "InstrNameData[];\n";
OS << ClassName << "::" << ClassName << "(int SO, int DO)\n"
<< " : TargetInstrInfoImpl(SO, DO) {\n"
<< " InitMCInstrInfo(" << TargetName << "Insts, "