forked from OSchip/llvm-project
[TableGen] Cache the vectors of records returned by getAllDerivedDefinitions().
Differential Revision: https://reviews.llvm.org/D92674
This commit is contained in:
parent
b2ef264096
commit
6266f36226
|
@ -1703,6 +1703,7 @@ class RecordKeeper {
|
||||||
|
|
||||||
std::string InputFilename;
|
std::string InputFilename;
|
||||||
RecordMap Classes, Defs;
|
RecordMap Classes, Defs;
|
||||||
|
mutable StringMap<std::vector<Record *>> ClassRecordsMap;
|
||||||
FoldingSet<RecordRecTy> RecordTypePool;
|
FoldingSet<RecordRecTy> RecordTypePool;
|
||||||
std::map<std::string, Init *, std::less<>> ExtraGlobals;
|
std::map<std::string, Init *, std::less<>> ExtraGlobals;
|
||||||
unsigned AnonCounter = 0;
|
unsigned AnonCounter = 0;
|
||||||
|
@ -1801,17 +1802,14 @@ public:
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
// High-level helper methods, useful for tablegen backends.
|
// High-level helper methods, useful for tablegen backends.
|
||||||
|
|
||||||
|
/// Get all the concrete records that inherit from the one specified
|
||||||
|
/// class. The class must be defined.
|
||||||
|
std::vector<Record *> getAllDerivedDefinitions(StringRef ClassName) const;
|
||||||
|
|
||||||
/// Get all the concrete records that inherit from all the specified
|
/// Get all the concrete records that inherit from all the specified
|
||||||
/// classes. The classes must be defined.
|
/// classes. The classes must be defined.
|
||||||
std::vector<Record *> getAllDerivedDefinitions(
|
std::vector<Record *> getAllDerivedDefinitions(
|
||||||
const ArrayRef<StringRef> ClassNames) const;
|
ArrayRef<StringRef> ClassNames) const;
|
||||||
|
|
||||||
/// Get all the concrete records that inherit from the one specified
|
|
||||||
/// class. The class must be defined.
|
|
||||||
std::vector<Record *> getAllDerivedDefinitions(StringRef ClassName) const {
|
|
||||||
|
|
||||||
return getAllDerivedDefinitions(makeArrayRef(ClassName));
|
|
||||||
}
|
|
||||||
|
|
||||||
void dump() const;
|
void dump() const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -2595,8 +2595,20 @@ void RecordKeeper::stopBackendTimer() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We cache the record vectors for single classes. Many backends request
|
||||||
|
// the same vectors multiple times.
|
||||||
std::vector<Record *> RecordKeeper::getAllDerivedDefinitions(
|
std::vector<Record *> RecordKeeper::getAllDerivedDefinitions(
|
||||||
const ArrayRef<StringRef> ClassNames) const {
|
StringRef ClassName) const {
|
||||||
|
|
||||||
|
auto Pair = ClassRecordsMap.try_emplace(ClassName);
|
||||||
|
if (Pair.second)
|
||||||
|
Pair.first->second = getAllDerivedDefinitions(makeArrayRef(ClassName));
|
||||||
|
|
||||||
|
return Pair.first->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Record *> RecordKeeper::getAllDerivedDefinitions(
|
||||||
|
ArrayRef<StringRef> ClassNames) const {
|
||||||
SmallVector<Record *, 2> ClassRecs;
|
SmallVector<Record *, 2> ClassRecs;
|
||||||
std::vector<Record *> Defs;
|
std::vector<Record *> Defs;
|
||||||
|
|
||||||
|
|
|
@ -532,6 +532,7 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
|
||||||
unsigned ListNumber = 0;
|
unsigned ListNumber = 0;
|
||||||
|
|
||||||
// Emit all of the instruction's implicit uses and defs.
|
// Emit all of the instruction's implicit uses and defs.
|
||||||
|
Records.startTimer("Emit uses/defs");
|
||||||
for (const CodeGenInstruction *II : Target.getInstructionsByEnumValue()) {
|
for (const CodeGenInstruction *II : Target.getInstructionsByEnumValue()) {
|
||||||
Record *Inst = II->TheDef;
|
Record *Inst = II->TheDef;
|
||||||
std::vector<Record*> Uses = Inst->getValueAsListOfDefs("Uses");
|
std::vector<Record*> Uses = Inst->getValueAsListOfDefs("Uses");
|
||||||
|
@ -549,10 +550,12 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
|
||||||
OperandInfoMapTy OperandInfoIDs;
|
OperandInfoMapTy OperandInfoIDs;
|
||||||
|
|
||||||
// Emit all of the operand info records.
|
// Emit all of the operand info records.
|
||||||
|
Records.startTimer("Emit operand info");
|
||||||
EmitOperandInfo(OS, OperandInfoIDs);
|
EmitOperandInfo(OS, OperandInfoIDs);
|
||||||
|
|
||||||
// Emit all of the MCInstrDesc records in their ENUM ordering.
|
// Emit all of the MCInstrDesc records in their ENUM ordering.
|
||||||
//
|
//
|
||||||
|
Records.startTimer("Emit InstrDesc records");
|
||||||
OS << "\nextern const MCInstrDesc " << TargetName << "Insts[] = {\n";
|
OS << "\nextern const MCInstrDesc " << TargetName << "Insts[] = {\n";
|
||||||
ArrayRef<const CodeGenInstruction*> NumberedInstructions =
|
ArrayRef<const CodeGenInstruction*> NumberedInstructions =
|
||||||
Target.getInstructionsByEnumValue();
|
Target.getInstructionsByEnumValue();
|
||||||
|
@ -568,6 +571,7 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
|
||||||
OS << "};\n\n";
|
OS << "};\n\n";
|
||||||
|
|
||||||
// Emit the array of instruction names.
|
// Emit the array of instruction names.
|
||||||
|
Records.startTimer("Emit instruction names");
|
||||||
InstrNames.layout();
|
InstrNames.layout();
|
||||||
InstrNames.emitStringLiteralDef(OS, Twine("extern const char ") + TargetName +
|
InstrNames.emitStringLiteralDef(OS, Twine("extern const char ") + TargetName +
|
||||||
"InstrNameData[]");
|
"InstrNameData[]");
|
||||||
|
@ -628,6 +632,7 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// MCInstrInfo initialization routine.
|
// MCInstrInfo initialization routine.
|
||||||
|
Records.startTimer("Emit initialization routine");
|
||||||
OS << "static inline void Init" << TargetName
|
OS << "static inline void Init" << TargetName
|
||||||
<< "MCInstrInfo(MCInstrInfo *II) {\n";
|
<< "MCInstrInfo(MCInstrInfo *II) {\n";
|
||||||
OS << " II->InitMCInstrInfo(" << TargetName << "Insts, " << TargetName
|
OS << " II->InitMCInstrInfo(" << TargetName << "Insts, " << TargetName
|
||||||
|
@ -706,10 +711,13 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
|
||||||
|
|
||||||
OS << "#endif // GET_INSTRINFO_CTOR_DTOR\n\n";
|
OS << "#endif // GET_INSTRINFO_CTOR_DTOR\n\n";
|
||||||
|
|
||||||
|
Records.startTimer("Emit operand name mappings");
|
||||||
emitOperandNameMappings(OS, Target, NumberedInstructions);
|
emitOperandNameMappings(OS, Target, NumberedInstructions);
|
||||||
|
|
||||||
|
Records.startTimer("Emit operand type mappings");
|
||||||
emitOperandTypeMappings(OS, Target, NumberedInstructions);
|
emitOperandTypeMappings(OS, Target, NumberedInstructions);
|
||||||
|
|
||||||
|
Records.startTimer("Emit helper methods");
|
||||||
emitMCIIHelperMethods(OS, TargetName);
|
emitMCIIHelperMethods(OS, TargetName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -862,7 +870,9 @@ void InstrInfoEmitter::emitEnums(raw_ostream &OS) {
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
void EmitInstrInfo(RecordKeeper &RK, raw_ostream &OS) {
|
void EmitInstrInfo(RecordKeeper &RK, raw_ostream &OS) {
|
||||||
|
RK.startTimer("Analyze DAG patterns");
|
||||||
InstrInfoEmitter(RK).run(OS);
|
InstrInfoEmitter(RK).run(OS);
|
||||||
|
RK.startTimer("Emit map table");
|
||||||
EmitMapTable(RK, OS);
|
EmitMapTable(RK, OS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue