diff options
author | Sergei Barannikov <barannikov88@gmail.com> | 2025-09-16 08:36:10 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-09-16 05:36:10 +0000 |
commit | 64dba812a3a8fc86b4ddbf34ad5bc5b5329cfca8 (patch) | |
tree | 16cf3fbb944faa33a22f914f1214d219013e451b /llvm/utils/TableGen/DecoderEmitter.cpp | |
parent | 14f2531894edd7f13ebf22891055c0ae1e1df451 (diff) | |
download | llvm-64dba812a3a8fc86b4ddbf34ad5bc5b5329cfca8.zip llvm-64dba812a3a8fc86b4ddbf34ad5bc5b5329cfca8.tar.gz llvm-64dba812a3a8fc86b4ddbf34ad5bc5b5329cfca8.tar.bz2 |
[TableGen][DecoderEmitter] Add a few DecoderTableInfo helpers (NFC) (#158776)
Diffstat (limited to 'llvm/utils/TableGen/DecoderEmitter.cpp')
-rw-r--r-- | llvm/utils/TableGen/DecoderEmitter.cpp | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp index a54e6d0..393a318 100644 --- a/llvm/utils/TableGen/DecoderEmitter.cpp +++ b/llvm/utils/TableGen/DecoderEmitter.cpp @@ -226,6 +226,26 @@ struct DecoderTableInfo { DecoderTable Table; PredicateSet Predicates; DecoderSet Decoders; + + void insertPredicate(StringRef Predicate) { + Predicates.insert(CachedHashString(Predicate)); + } + + void insertDecoder(StringRef Decoder) { + Decoders.insert(CachedHashString(Decoder)); + } + + unsigned getPredicateIndex(StringRef Predicate) const { + auto I = find(Predicates, Predicate); + assert(I != Predicates.end()); + return std::distance(Predicates.begin(), I); + } + + unsigned getDecoderIndex(StringRef Decoder) const { + auto I = find(Decoders, Decoder); + assert(I != Decoders.end()); + return std::distance(Decoders.begin(), I); + } }; using NamespacesHwModesMap = std::map<StringRef, std::set<unsigned>>; @@ -1087,13 +1107,8 @@ unsigned DecoderTableBuilder::getDecoderIndex(unsigned EncodingID) const { // performance concern, we can implement a mangling of the predicate // data easily enough with a map back to the actual string. That's // overkill for now, though. - - // Make sure the predicate is in the table. - DecoderSet &Decoders = TableInfo.Decoders; - Decoders.insert(CachedHashString(Decoder)); - // Now figure out the index for when we write out the table. - DecoderSet::const_iterator P = find(Decoders, Decoder.str()); - return std::distance(Decoders.begin(), P); + TableInfo.insertDecoder(Decoder); + return TableInfo.getDecoderIndex(Decoder); } // Returns true if there was any predicate emitted. @@ -1117,12 +1132,8 @@ unsigned DecoderTableBuilder::getPredicateIndex(StringRef Predicate) const { // performance concern, we can implement a mangling of the predicate // data easily enough with a map back to the actual string. That's // overkill for now, though. - - // Make sure the predicate is in the table. - TableInfo.Predicates.insert(CachedHashString(Predicate)); - // Now figure out the index for when we write out the table. - PredicateSet::const_iterator P = find(TableInfo.Predicates, Predicate); - return (unsigned)(P - TableInfo.Predicates.begin()); + TableInfo.insertPredicate(Predicate); + return TableInfo.getPredicateIndex(Predicate); } void DecoderTableBuilder::emitPredicateTableEntry(unsigned EncodingID) const { |