llvm.org GIT mirror llvm / b6f73f8
[TableGen] Use SmallMapVector to simplify some code that was trying to keep a vector unique Summary: This code previously had a SmallVector of std::pairs containing an unsigned and another SmallVector. The outer vector was using the unsigned effectively as a key to decide which SmallVector to add into. So each time something new needed to be added the out vector needed to be scanned. If it wasn't found a new entry needed to be added to be added. This sounds very much like a map, but the next loop iterates over the outer vector to get a deterministic order. We can simplify this code greatly if use SmallMapVector instead. This uses more stack space since we now have a vector and a map, but the searching and creating new entries all happens behind the scenes. It should also make the search more efficient though usually there are only a few entries so that doesn't matter much. We could probably get determinism by just using std::map which would iterate over the unsigned key, but that would generate different output from what we get with the current implementation. Reviewers: RKSimon, dblaikie Reviewed By: dblaikie Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D44711 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328070 91177308-0d34-0410-b5e6-96231b3b80d8 Craig Topper 2 years ago
1 changed file(s) with 6 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
1414 #include "CodeGenSchedule.h"
1515 #include "CodeGenInstruction.h"
1616 #include "CodeGenTarget.h"
17 #include "llvm/ADT/MapVector.h"
1718 #include "llvm/ADT/STLExtras.h"
1819 #include "llvm/ADT/SmallPtrSet.h"
1920 #include "llvm/ADT/SmallSet.h"
742743 // intersects with an existing class via a previous InstRWDef. Instrs that do
743744 // not intersect with an existing class refer back to their former class as
744745 // determined from ItinDef or SchedRW.
745 SmallVector>, 4> ClassInstrs;
746 SmallMapVector>, 4> ClassInstrs;
746747 // Sort Instrs into sets.
747748 const RecVec *InstDefs = Sets.expand(InstRWDef);
748749 if (InstDefs->empty())
753754 if (Pos == InstrClassMap.end())
754755 PrintFatalError(InstDef->getLoc(), "No sched class for instruction.");
755756 unsigned SCIdx = Pos->second;
756 unsigned CIdx = 0, CEnd = ClassInstrs.size();
757 for (; CIdx != CEnd; ++CIdx) {
758 if (ClassInstrs[CIdx].first == SCIdx)
759 break;
760 }
761 if (CIdx == CEnd) {
762 ClassInstrs.resize(CEnd + 1);
763 ClassInstrs[CIdx].first = SCIdx;
764 }
765 ClassInstrs[CIdx].second.push_back(InstDef);
757 ClassInstrs[SCIdx].push_back(InstDef);
766758 }
767759 // For each set of Instrs, create a new class if necessary, and map or remap
768760 // the Instrs to it.
769 for (unsigned CIdx = 0, CEnd = ClassInstrs.size(); CIdx != CEnd; ++CIdx) {
770 unsigned OldSCIdx = ClassInstrs[CIdx].first;
771 ArrayRef InstDefs = ClassInstrs[CIdx].second;
761 for (auto &Entry : ClassInstrs) {
762 unsigned OldSCIdx = Entry.first;
763 ArrayRef InstDefs = Entry.second;
772764 // If the all instrs in the current class are accounted for, then leave
773765 // them mapped to their old class.
774766 if (OldSCIdx) {