Skip to content

Commit 6266f36

Browse files
author
Paul C. Anagnostopoulos
committed
[TableGen] Cache the vectors of records returned by getAllDerivedDefinitions().
Differential Revision: https://reviews.llvm.org/D92674
1 parent b2ef264 commit 6266f36

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

llvm/include/llvm/TableGen/Record.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,7 @@ class RecordKeeper {
17031703

17041704
std::string InputFilename;
17051705
RecordMap Classes, Defs;
1706+
mutable StringMap<std::vector<Record *>> ClassRecordsMap;
17061707
FoldingSet<RecordRecTy> RecordTypePool;
17071708
std::map<std::string, Init *, std::less<>> ExtraGlobals;
17081709
unsigned AnonCounter = 0;
@@ -1801,17 +1802,14 @@ class RecordKeeper {
18011802
//===--------------------------------------------------------------------===//
18021803
// High-level helper methods, useful for tablegen backends.
18031804

1804-
/// Get all the concrete records that inherit from all the specified
1805-
/// classes. The classes must be defined.
1806-
std::vector<Record *> getAllDerivedDefinitions(
1807-
const ArrayRef<StringRef> ClassNames) const;
1808-
18091805
/// Get all the concrete records that inherit from the one specified
18101806
/// class. The class must be defined.
1811-
std::vector<Record *> getAllDerivedDefinitions(StringRef ClassName) const {
1807+
std::vector<Record *> getAllDerivedDefinitions(StringRef ClassName) const;
18121808

1813-
return getAllDerivedDefinitions(makeArrayRef(ClassName));
1814-
}
1809+
/// Get all the concrete records that inherit from all the specified
1810+
/// classes. The classes must be defined.
1811+
std::vector<Record *> getAllDerivedDefinitions(
1812+
ArrayRef<StringRef> ClassNames) const;
18151813

18161814
void dump() const;
18171815
};

llvm/lib/TableGen/Record.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2595,8 +2595,20 @@ void RecordKeeper::stopBackendTimer() {
25952595
}
25962596
}
25972597

2598+
// We cache the record vectors for single classes. Many backends request
2599+
// the same vectors multiple times.
25982600
std::vector<Record *> RecordKeeper::getAllDerivedDefinitions(
2599-
const ArrayRef<StringRef> ClassNames) const {
2601+
StringRef ClassName) const {
2602+
2603+
auto Pair = ClassRecordsMap.try_emplace(ClassName);
2604+
if (Pair.second)
2605+
Pair.first->second = getAllDerivedDefinitions(makeArrayRef(ClassName));
2606+
2607+
return Pair.first->second;
2608+
}
2609+
2610+
std::vector<Record *> RecordKeeper::getAllDerivedDefinitions(
2611+
ArrayRef<StringRef> ClassNames) const {
26002612
SmallVector<Record *, 2> ClassRecs;
26012613
std::vector<Record *> Defs;
26022614

llvm/utils/TableGen/InstrInfoEmitter.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
532532
unsigned ListNumber = 0;
533533

534534
// Emit all of the instruction's implicit uses and defs.
535+
Records.startTimer("Emit uses/defs");
535536
for (const CodeGenInstruction *II : Target.getInstructionsByEnumValue()) {
536537
Record *Inst = II->TheDef;
537538
std::vector<Record*> Uses = Inst->getValueAsListOfDefs("Uses");
@@ -549,10 +550,12 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
549550
OperandInfoMapTy OperandInfoIDs;
550551

551552
// Emit all of the operand info records.
553+
Records.startTimer("Emit operand info");
552554
EmitOperandInfo(OS, OperandInfoIDs);
553555

554556
// Emit all of the MCInstrDesc records in their ENUM ordering.
555557
//
558+
Records.startTimer("Emit InstrDesc records");
556559
OS << "\nextern const MCInstrDesc " << TargetName << "Insts[] = {\n";
557560
ArrayRef<const CodeGenInstruction*> NumberedInstructions =
558561
Target.getInstructionsByEnumValue();
@@ -568,6 +571,7 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
568571
OS << "};\n\n";
569572

570573
// Emit the array of instruction names.
574+
Records.startTimer("Emit instruction names");
571575
InstrNames.layout();
572576
InstrNames.emitStringLiteralDef(OS, Twine("extern const char ") + TargetName +
573577
"InstrNameData[]");
@@ -628,6 +632,7 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
628632
}
629633

630634
// MCInstrInfo initialization routine.
635+
Records.startTimer("Emit initialization routine");
631636
OS << "static inline void Init" << TargetName
632637
<< "MCInstrInfo(MCInstrInfo *II) {\n";
633638
OS << " II->InitMCInstrInfo(" << TargetName << "Insts, " << TargetName
@@ -706,10 +711,13 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
706711

707712
OS << "#endif // GET_INSTRINFO_CTOR_DTOR\n\n";
708713

714+
Records.startTimer("Emit operand name mappings");
709715
emitOperandNameMappings(OS, Target, NumberedInstructions);
710716

717+
Records.startTimer("Emit operand type mappings");
711718
emitOperandTypeMappings(OS, Target, NumberedInstructions);
712719

720+
Records.startTimer("Emit helper methods");
713721
emitMCIIHelperMethods(OS, TargetName);
714722
}
715723

@@ -862,7 +870,9 @@ void InstrInfoEmitter::emitEnums(raw_ostream &OS) {
862870
namespace llvm {
863871

864872
void EmitInstrInfo(RecordKeeper &RK, raw_ostream &OS) {
873+
RK.startTimer("Analyze DAG patterns");
865874
InstrInfoEmitter(RK).run(OS);
875+
RK.startTimer("Emit map table");
866876
EmitMapTable(RK, OS);
867877
}
868878

0 commit comments

Comments
 (0)