Skip to content

Commit 276d9a4

Browse files
committed
[TableGen][DecoderEmitter] Add a few DecoderTableInfo helpers (NFC)
1 parent e2040f5 commit 276d9a4

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,26 @@ struct DecoderTableInfo {
226226
DecoderTable Table;
227227
PredicateSet Predicates;
228228
DecoderSet Decoders;
229+
230+
void insertPredicate(StringRef Predicate) {
231+
Predicates.insert(CachedHashString(Predicate));
232+
}
233+
234+
void insertDecoder(StringRef Decoder) {
235+
Decoders.insert(CachedHashString(Decoder));
236+
}
237+
238+
unsigned getPredicateIndex(StringRef Predicate) const {
239+
auto I = find(Predicates, Predicate);
240+
assert(I != Predicates.end());
241+
return std::distance(Predicates.begin(), I);
242+
}
243+
244+
unsigned getDecoderIndex(StringRef Decoder) const {
245+
auto I = find(Decoders, Decoder);
246+
assert(I != Decoders.end());
247+
return std::distance(Decoders.begin(), I);
248+
}
229249
};
230250

231251
using NamespacesHwModesMap = std::map<StringRef, std::set<unsigned>>;
@@ -1090,13 +1110,8 @@ unsigned DecoderTableBuilder::getDecoderIndex(unsigned EncodingID) const {
10901110
// performance concern, we can implement a mangling of the predicate
10911111
// data easily enough with a map back to the actual string. That's
10921112
// overkill for now, though.
1093-
1094-
// Make sure the predicate is in the table.
1095-
DecoderSet &Decoders = TableInfo.Decoders;
1096-
Decoders.insert(CachedHashString(Decoder));
1097-
// Now figure out the index for when we write out the table.
1098-
DecoderSet::const_iterator P = find(Decoders, Decoder.str());
1099-
return std::distance(Decoders.begin(), P);
1113+
TableInfo.insertDecoder(Decoder);
1114+
return TableInfo.getDecoderIndex(Decoder);
11001115
}
11011116

11021117
// If ParenIfBinOp is true, print a surrounding () if Val uses && or ||.
@@ -1154,12 +1169,8 @@ unsigned DecoderTableBuilder::getPredicateIndex(StringRef Predicate) const {
11541169
// performance concern, we can implement a mangling of the predicate
11551170
// data easily enough with a map back to the actual string. That's
11561171
// overkill for now, though.
1157-
1158-
// Make sure the predicate is in the table.
1159-
TableInfo.Predicates.insert(CachedHashString(Predicate));
1160-
// Now figure out the index for when we write out the table.
1161-
PredicateSet::const_iterator P = find(TableInfo.Predicates, Predicate);
1162-
return (unsigned)(P - TableInfo.Predicates.begin());
1172+
TableInfo.insertPredicate(Predicate);
1173+
return TableInfo.getPredicateIndex(Predicate);
11631174
}
11641175

11651176
void DecoderTableBuilder::emitPredicateTableEntry(unsigned EncodingID) const {

0 commit comments

Comments
 (0)