Skip to content

Commit 64dba81

Browse files
authored
[TableGen][DecoderEmitter] Add a few DecoderTableInfo helpers (NFC) (#158776)
1 parent 14f2531 commit 64dba81

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>>;
@@ -1087,13 +1107,8 @@ unsigned DecoderTableBuilder::getDecoderIndex(unsigned EncodingID) const {
10871107
// performance concern, we can implement a mangling of the predicate
10881108
// data easily enough with a map back to the actual string. That's
10891109
// overkill for now, though.
1090-
1091-
// Make sure the predicate is in the table.
1092-
DecoderSet &Decoders = TableInfo.Decoders;
1093-
Decoders.insert(CachedHashString(Decoder));
1094-
// Now figure out the index for when we write out the table.
1095-
DecoderSet::const_iterator P = find(Decoders, Decoder.str());
1096-
return std::distance(Decoders.begin(), P);
1110+
TableInfo.insertDecoder(Decoder);
1111+
return TableInfo.getDecoderIndex(Decoder);
10971112
}
10981113

10991114
// Returns true if there was any predicate emitted.
@@ -1117,12 +1132,8 @@ unsigned DecoderTableBuilder::getPredicateIndex(StringRef Predicate) const {
11171132
// performance concern, we can implement a mangling of the predicate
11181133
// data easily enough with a map back to the actual string. That's
11191134
// overkill for now, though.
1120-
1121-
// Make sure the predicate is in the table.
1122-
TableInfo.Predicates.insert(CachedHashString(Predicate));
1123-
// Now figure out the index for when we write out the table.
1124-
PredicateSet::const_iterator P = find(TableInfo.Predicates, Predicate);
1125-
return (unsigned)(P - TableInfo.Predicates.begin());
1135+
TableInfo.insertPredicate(Predicate);
1136+
return TableInfo.getPredicateIndex(Predicate);
11261137
}
11271138

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

0 commit comments

Comments
 (0)