[llvm] [TableGen][DecoderEmitter] Fix decoder reading bytes past instruction (PR #154916)

Sergei Barannikov via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 22 04:50:26 PDT 2025


================
@@ -475,8 +488,9 @@ class FilterChooser {
   // Vector of encodings to choose our filter.
   ArrayRef<InstructionEncoding> Encodings;
 
-  // Vector of encoding IDs for this filter chooser to work on.
-  ArrayRef<unsigned> EncodingIDs;
+  /// Encoding IDs for this filter chooser to work on.
+  /// Sorted by non-decreasing encoding width.
+  SmallVector<unsigned, 0> EncodingIDs;
----------------
s-barannikov wrote:

> Can this sorting be done at the top-level when we construct the `EncodingIDsByHwMode` in `DecoderEmitter::constructor`?

Good question.

That idea crossed my mind as well, but I declined it because it would make the user (DecoderEmitter) dependent on an implementation detail of FilterChooser. This can be a problem. For example, DecoderEmitter might want to sort it differently, such as by instruction ID.

> Then we don't need to sort again individually and can keep using the ArrayRef here?

I couldn't add vector here and remove it elsewhere (from Filter) due to lifetime issues. I'll do it in a future patch.
(The overhead is rather small, sizeof(uint32) x number of encodings, must be a few KB in the worst case.)


https://github.com/llvm/llvm-project/pull/154916


More information about the llvm-commits mailing list