@@ -60,7 +60,6 @@ class MatcherTableEmitter {
60
60
// all the patterns with "identical" predicates.
61
61
StringMap<TinyPtrVector<TreePattern *>> NodePredicatesByCodeToRun;
62
62
63
- StringMap<unsigned > PatternPredicateMap;
64
63
std::vector<std::string> PatternPredicates;
65
64
66
65
std::vector<const ComplexPattern*> ComplexPatterns;
@@ -87,6 +86,8 @@ class MatcherTableEmitter {
87
86
: CGP(cgp), OpcodeCounts(Matcher::HighestKind + 1 , 0 ) {
88
87
// Record the usage of ComplexPattern.
89
88
DenseMap<const ComplexPattern *, unsigned > ComplexPatternUsage;
89
+ // Record the usage of PatternPredicate.
90
+ std::map<StringRef, unsigned > PatternPredicateUsage;
90
91
91
92
// Iterate the whole MatcherTable once and do some statistics.
92
93
std::function<void (const Matcher *)> Statistic = [&](const Matcher *N) {
@@ -102,6 +103,8 @@ class MatcherTableEmitter {
102
103
Statistic (STM->getCaseMatcher (I));
103
104
else if (auto *CPM = dyn_cast<CheckComplexPatMatcher>(N))
104
105
++ComplexPatternUsage[&CPM->getPattern ()];
106
+ else if (auto *CPPM = dyn_cast<CheckPatternPredicateMatcher>(N))
107
+ ++PatternPredicateUsage[CPPM->getPredicate ()];
105
108
N = N->getNext ();
106
109
}
107
110
};
@@ -114,6 +117,14 @@ class MatcherTableEmitter {
114
117
[](const auto &A, const auto &B) { return A.second > B.second ; });
115
118
for (const auto &ComplexPattern : ComplexPatternList)
116
119
ComplexPatterns.push_back (ComplexPattern.first );
120
+
121
+ // Sort PatternPredicates by usage.
122
+ std::vector<std::pair<std::string, unsigned >> PatternPredicateList (
123
+ PatternPredicateUsage.begin (), PatternPredicateUsage.end ());
124
+ sort (PatternPredicateList,
125
+ [](const auto &A, const auto &B) { return A.second > B.second ; });
126
+ for (const auto &PatternPredicate : PatternPredicateList)
127
+ PatternPredicates.push_back (PatternPredicate.first );
117
128
}
118
129
119
130
unsigned EmitMatcherList (const Matcher *N, const unsigned Indent,
@@ -167,12 +178,7 @@ class MatcherTableEmitter {
167
178
}
168
179
169
180
unsigned getPatternPredicate (StringRef PredName) {
170
- unsigned &Entry = PatternPredicateMap[PredName];
171
- if (Entry == 0 ) {
172
- PatternPredicates.push_back (PredName.str ());
173
- Entry = PatternPredicates.size ();
174
- }
175
- return Entry-1 ;
181
+ return llvm::find (PatternPredicates, PredName) - PatternPredicates.begin ();
176
182
}
177
183
unsigned getComplexPat (const ComplexPattern &P) {
178
184
return llvm::find (ComplexPatterns, &P) - ComplexPatterns.begin ();
@@ -510,13 +516,15 @@ EmitMatcher(const Matcher *N, const unsigned Indent, unsigned CurrentIdx,
510
516
StringRef Pred = cast<CheckPatternPredicateMatcher>(N)->getPredicate ();
511
517
unsigned PredNo = getPatternPredicate (Pred);
512
518
if (PredNo > 255 )
513
- OS << " OPC_CheckPatternPredicate2, TARGET_VAL(" << PredNo << " )," ;
519
+ OS << " OPC_CheckPatternPredicateTwoByte, TARGET_VAL(" << PredNo << " )," ;
520
+ else if (PredNo < 8 )
521
+ OS << " OPC_CheckPatternPredicate" << PredNo << ' ,' ;
514
522
else
515
523
OS << " OPC_CheckPatternPredicate, " << PredNo << ' ,' ;
516
524
if (!OmitComments)
517
525
OS << " // " << Pred;
518
526
OS << ' \n ' ;
519
- return 2 + (PredNo > 255 );
527
+ return 2 + (PredNo > 255 ) - (PredNo < 8 ) ;
520
528
}
521
529
case Matcher::CheckPredicate: {
522
530
TreePredicateFn Pred = cast<CheckPredicateMatcher>(N)->getPredicate ();
0 commit comments