aboutsummaryrefslogtreecommitdiff
path: root/mlir/lib/Bytecode
AgeCommit message (Collapse)AuthorFilesLines
2026-01-09[mlir][Bytecode] Fix infinite loop by tracking type/attribute in deferred ↵Hideto Ueno1-22/+47
worklist (#174874) The bytecode reader could enter an infinite loop when parsing deeply nested attributes containing type references. The deferred worklist stored only indices without distinguishing between attributes and types, causing type indexes to be misinterpreted as attributes. This patch changes the deferred worklist to store pairs of (index, kind) to track whether each deferred entry is a type or attribute. The worklist processing logic is updated to resolve the correct entry type.
2026-01-02[LLVM][ADT] Migrate users of `make_scope_exit` to CTAD (#174030)Victor Chernyakin1-6/+5
This is a followup to #173131, which introduced the CTAD functionality.
2025-12-19[mlir][bytecode] fix on macos after #172901 (#173084)Maksim Levental1-2/+3
`uint64_t` != `size_t` on macos (use `uint64_t` to match other uses in this impl)
2025-12-19[mlir][bytecode] Add support for deferred attribute/type parsing (#172901)Jacques Pienaar1-53/+239
Add ability to defer parsing and re-enqueueing oneself. This enables changing CallSiteLoc parsing to not recurse as deeply: previously this could fail (especially on large inputs in debug mode the recursion could overflow). Add a default depth cutoff, this could be a parameter later if needed. Roll-forward of #170993 with relatively direct change such that if processing while not resolving/when parsing property it eagerly resolves.
2025-12-17Revert "[mlir][bytecode] Add support for deferred attribute/type parsing. ↵Mehdi Amini1-206/+54
(#170993)" This reverts commit 93d2ef105703254769a8f182300b329dad5ed976. A regression was found. See: https://github.com/llvm/llvm-project/pull/170993#issuecomment-3666792469
2025-12-09[MLIR][Bytecode] Use consistent types for resolveEntry (#171502)Aiden Grossman1-2/+3
uint64_t and size_t are not the same across all platforms. This was causing build failures when building this file for wasm: llvm-project/mlir/lib/Bytecode/Reader/BytecodeReader.cpp:1323:19: error: out-of-line definition of 'resolveEntry' does not match any declaration in '(anonymous namespace)::AttrTypeReader' 1323 | T AttrTypeReader::resolveEntry(SmallVectorImpl<Entry<T>> &entries, size_t index, | ^~~~~~~~~~~~ third_party/llvm/llvm-project/mlir/lib/Bytecode/Reader/BytecodeReader.cpp:851:7: note: AttrTypeReader defined here 851 | class AttrTypeReader { | ^~~~~~~~~~~~~~ 1 error generated. Use uint64_t everywhere to ensure portability.
2025-12-09[mlir][bytecode] Add support for deferred attribute/type parsing. (#170993)Jacques Pienaar1-53/+204
Add ability to defer parsing and re-enqueueing oneself. This enables changing CallSiteLoc parsing to not recurse as deeply: previously this could fail (especially on large inputs in debug mode the recursion could overflow). Add a default depth cutoff, this could be a parameter later if needed.
2025-09-11[MLIR][Bytecode] Followup 8106c81 (#157136)Nikhil Kalra1-7/+31
Addressed code review feedback: - Fixed some issues in the unit test - Adjusted line wrapping in the docs - Clarified comments in the bytecode reader
2025-09-04[MLIR][Bytecode] Enforce alignment requirements (#157004)Nikhil Kalra1-5/+70
Adds a check that the bytecode buffer is aligned to any section alignment requirements. Without this check, if the source buffer is not sufficiently aligned, we may return early when aligning the data pointer. In that case, we may end up trying to read successive sections from an incorrect offset, giving the appearance of invalid bytecode. This requirement is documented in the bytecode unit tests, but is not otherwise documented in the code or bytecode reference.
2025-08-25Revert "[MLIR] Fix duplicated attribute nodes in MLIR bytecode ↵Christian Ulmann1-5/+1
deserialization (#151267) (#155214) This reverts commit c075fb8c37856365fb76d986ad3aefa2400b3240. This commit introduces a caching bug that causes undesired collisions.
2025-08-20[MLIR] Adopt LDBG() debug macro in BytecodeWriter.cpp (NFC) (#154642)Mehdi Amini1-9/+6
2025-08-20[MLIR] Fix duplicated attribute nodes in MLIR bytecode deserialization (#151267)Hank1-1/+5
Fixes #150163 MLIR bytecode does not preserve alias definitions, so each attribute encountered during deserialization is treated as a new one. This can generate duplicate `DISubprogram` nodes during deserialization. The patch adds a `StringMap` cache that records attributes and fetches them when encountered again.
2025-06-09[mlir] Use *Map::try_emplace (NFC) (#143341)Kazu Hirata1-2/+2
- try_emplace(Key) is shorter than insert({Key, nullptr}). - try_emplace performs value initialization without value parameters. - We overwrite values on successful insertion anyway.
2025-05-30[mlir][Value] Add getNumUses, hasNUses, and hasNUsesOrMore to Value (#142084)Michael Maitland1-2/+1
We already have hasOneUse. Like llvm::Value we provide helper methods to query the number of uses of a Value. Add unittests for Value, because that was missing. --------- Co-authored-by: Michael Maitland <michaelmaitland@meta.com>
2025-04-15[mlir] Use llvm::make_first_range (NFC) (#135900)Kazu Hirata1-2/+1
2025-04-14[mlir] Use llvm::append_range (NFC) (#135722)Kazu Hirata1-3/+2
2025-03-31[MLIR][NFC] Fix incomplete boundary comments. (#133516)Han-Chung Wang2-0/+11
I observed that we have the boundary comments in the codebase like: ``` //===----------------------------------------------------------------------===// // ... //===----------------------------------------------------------------------===// ``` I also observed that there are incomplete boundary comments. The revision is generated by a script that completes the boundary comments. ``` //===----------------------------------------------------------------------===// // ... ... ``` Signed-off-by: hanhanW <hanhan0912@gmail.com>
2025-02-12[mlir] BytecodeWriter: invoke `reserveExtraSpace` (#126953)Nikhil Kalra1-0/+3
Update `BytecodeWriter` to invoke `reserveExtraSpace` on the stream before writing to it. This will give clients implementing custom output streams the opportunity to allocate an appropriately sized buffer for the write.
2025-02-06[MLIR] Add move constructor to BytecodeWriterConfig (#126130)Karim Nosseir1-0/+3
The config is currently not movable and because there are constructors the default move won't be generated, which prevents it from being moved. Also, it is not copyable because of the unique_ptr. This PR adds move constructor to allow moving it.
2025-01-11[mlir] Migrate away from PointerUnion::{is,get} (NFC) (#122591)Kazu Hirata1-2/+2
Note that PointerUnion::{is,get} have been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with // isa<T>, cast<T> and the llvm::dyn_cast<T> I'm not touching PointerUnion::dyn_cast for now because it's a bit complicated; we could blindly migrate it to dyn_cast_if_present, but we should probably use dyn_cast when the operand is known to be non-null.
2024-11-01[llvm][NFC] Fix typos: replace “avaliable” with “available” across ↵Wang Qiang1-1/+1
various files (#114524) This pull request corrects multiple occurrences of the typo "avaliable" to "available" across the LLVM and Clang codebase. These changes improve the clarity and accuracy of comments and documentation. Specific modifications are in the following files: 1. clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp: Updated comments in readability checks for cognitive complexity. 2. llvm/include/llvm/ExecutionEngine/Orc/ExecutionUtils.h: Corrected documentation for JITDylib responsibilities. 3. llvm/include/llvm/Target/TargetMacroFusion.td: Fixed descriptions for FusionPredicate variables. 4. llvm/lib/CodeGen/SafeStack.cpp: Improved comments on DominatorTree availability. 5. llvm/lib/Target/RISCV/RISCVSchedSiFive7.td: Enhanced resource usage descriptions for vector units. 6. llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp: Updated invariant description in shift-detect idiom logic. 7. llvm/test/MC/ARM/mve-fp-registers.s: Amended ARM MVE register availability notes. 8. mlir/lib/Bytecode/Reader/BytecodeReader.cpp: Adjusted forward reference descriptions for bytecode reader operations. These changes have no impact on code functionality, focusing solely on documentation clarity. Co-authored-by: wangqiang <wangqiang1@kylinos.cn>
2024-09-12[Bytecode] Avoid repeated hash lookups (NFC) (#108320)Kazu Hirata1-2/+1
2024-07-20Add logging for emit functions in BytecodeWriter.cpp (#99558)Kevin Gleason1-113/+153
Recently there was a change to materializing unrealized conversion casts, which inserted conversion that previously did not exist during legalization (https://github.com/llvm/llvm-project/pull/97903), after these cases are inserted and then washed away after transformation completes, it caused the use-list ordering of an op to change in some cases: `my.add %arg0(use1), %arg0(use2) --> my.add %arg0(use2), %arg0(use1)`, which subtly changes the bytecode emitted since this is considered a custom use-list. When investigating why the bytecode had changed I added the following logging which helped track down the difference, in my case it showed extra bytes with "use-list section". With `-debug-only=mlir-bytecode-writer` emits logs like the following, detailing the source of written bytes: ``` emitBytes(4b) bytecode header emitVarInt(6) bytecode version emitByte(13) bytecode version emitBytes(17b) bytecode producer emitByte(0) null terminator emitVarInt(2) dialects count ... emitByte(5) dialect version emitVarInt(4) op names count emitByte(9) op names count emitVarInt(0) dialect number ... emitVarInt(2) dialect writer emitByte(5) dialect writer emitVarInt(9259963783827161088) dialect APInt ... emitVarInt(3) attr/type offset emitByte(7) attr/type offset emitByte(3) section code emitVarInt(18) section size ... ``` Note: this uses string constants and `StringLiteral`, I'm not sure if these are washed away during compilation / OK to have these around for debuggin, or if there's a better way to do this? Alternative was adding many braces and `LLVM_DEBUG` calls at each callsite, but this felt more error prone / likely to miss some callsites.
2024-07-18[mlir][BytecodeReader] Const qualify *SectionReader, NFC (#99376)Hideto Ueno1-13/+13
`StringSectionReader`, `ResourceSectionReader` and `PropertiesSectionReader` are immutable after `initialize` so this PR adds const to their parsing functions and references in `AttrTypeReader` and `DialectReader`.
2024-07-15[mlir] Remove bytecode reader & writer header from interface. (#98920)Jacques Pienaar1-0/+1
Flagged some additional headers missing in process. Inspired by #98676
2024-07-03[mlir][bytecode] Fix external resource bytecode parsing (#97650)Jeff Niu1-1/+1
The key was being dropped for external resources because they aren't present in the dialect resource name mapper.
2024-07-02mlir/LogicalResult: move into llvm (#97309)Ramkumar Ramachandra2-2/+0
This patch is part of a project to move the Presburger library into LLVM.
2024-04-10[mlir] Slightly optimize bytecode op numbering (#88310)Jeff Niu1-7/+7
If the bytecode encoding supports properties, then the dictionary attribute is always the raw dictionary attribute of the operation, regardless of what it contains. Otherwise, get the dictionary attribute from the op: if the op does not have properties, then it returns the raw dictionary, otherwise it returns the combined inherent and discardable attributes.
2024-02-25Fix bytecode roundtrip of unregistered ops (#82932)Matteo Franciolini1-9/+5
When roundtripping to bytecode an unregistered operation name that does not contain any '.' separator, the bytecode writer will emit an op encoding without a proper opName. In this case, the string just becomes a possibly unknown dialect name. At parsing, this dialect name is used as a proper operation name. However, when the unregistered operation name coincidentally matches that of a dialect, the parser would fail. That means we can't roundtrip an unregistered op with a name that matches one of the registered dialect names. For example, ``` "index"() : () -> () ``` can be emitted but cannot be parsed, because its name is coincidentally the same as that of the Index dialect. The patch removes such inconsistency. This patch specifically fixes the bytecode roundtrip of `mlir/test/IR/parser.mlir`.
2024-02-20Fix pipeline-invalid.mlir bytecode roundtrip test (#82366)Matteo Franciolini1-2/+5
If an op was not contained in a region when was written to bytecode, we don't have an initialized valueScope with forward references to define.
2024-01-04[mlir] don't use magic numbers in IRNumbering.cppAlex Zinenko1-5/+9
Bytecode versions have named constants that should be used instead of magic numbers.
2024-01-04[mlir] fix bytecode writer after c1eab57673ef3eb28Alex Zinenko2-5/+9
The change in c1eab57 fixed the behavior of `getDiscardableAttrDictionary` for ops that are not using properties to only return discardable attributes. Bytecode writer was relying on the wrong behavior and would assume all attributes are discardable, without appropriate testing. Fix that and add a test.
2023-12-13[mlir] Use StringRef::{starts,ends}_with (NFC)Kazu Hirata1-1/+1
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
2023-11-13[mlir][bytecode] Add bytecode writer config API to skip serialization of ↵Matteo Franciolini1-6/+20
resources (#71991) When serializing to bytecode, users can select the option to elide resources from the bytecode file. This will instruct the bytecode writer to serialize only the key and resource kind, while skipping serialization of the data buffer. At parsing, the IR is built in memory with valid (but empty) resource handlers.
2023-10-31[mlir][bytecode] Implements back deployment capability for MLIR dialects ↵Matteo Franciolini2-12/+57
(#70724) When emitting bytecode, clients can specify a target dialect version to emit in `BytecodeWriterConfig`. This exposes a target dialect version to the DialectBytecodeWriter, which can be queried by name and used to back-deploy attributes, types, and properties.
2023-10-21Apply clang-tidy fixes for llvm-qualified-auto in IRNumbering.cpp (NFC)Mehdi Amini1-1/+1
2023-09-29[mlir] Fix bytecode reading of resource sectionsMogball1-8/+2
This partially reverts #66380. The assertion that the underlying buffer of an EncodingReader is aligned to any required alignments for resource sections. Resources know their own alignment and pad their buffers accordingly, but the bytecode reader doesn't know that ahead of time. Consequently, it cannot give the resource EncodingReader a base buffer aligned to the maximum required alignment. A simple example from the test fails without this: ```mlir module @TestDialectResources attributes { bytecode.test = dense_resource<resource> : tensor<4xi32> } {} {-# dialect_resources: { builtin: { resource: "0x2000000001000000020000000300000004000000", resource_2: "0x2000000001000000020000000300000004000000" } } ```
2023-09-17[mlir][bytecode] Check that bytecode source buffer is sufficiently aligned. ↵Christian Sigg1-11/+22
(#66380) Before this change, the `ByteCode` test failed on CentOS 7 with devtoolset-9, because strings happen to be only 8 byte aligned. In general though, strings have no alignment guarantee. Increase resource alignment in test to 32 bytes. Adjust test to sufficiently align buffer. Add test to check error when buffer is insufficiently aligned.
2023-08-07[mlir] Apply ClangTidy fix (NFC)Adrian Kuegel1-1/+1
redundant get() call on smart pointer.
2023-08-02[MLIR][Bytecode] Add missing field initializer in constructor initializer listMehdi Amini1-2/+2
Leaving this field unitialized could led to crashes when it'll diverge from the IRNumbering phase. Differential Revision: https://reviews.llvm.org/D156965
2023-07-28Expose callbacks for encoding of types/attributesMatteo Franciolini3-93/+219
[mlir] Expose a mechanism to provide a callback for encoding types and attributes in MLIR bytecode. Two callbacks are exposed, respectively, to the BytecodeWriterConfig and to the ParserConfig. At bytecode parsing/printing, clients have the ability to specify a callback to be used to optionally read/write the encoding. On failure, fallback path will execute the default parsers and printers for the dialect. Testing shows how to leverage this functionality to support back-deployment and backward-compatibility usecases when roundtripping to bytecode a client dialect with type/attributes dependencies on upstream. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D153383
2023-07-28Revert "Expose callbacks for encoding of types/attributes"Mehdi Amini3-219/+93
This reverts commit b299ec16661f653df66cdaf161cdc5441bc9803c. The authorship informations were incorrect.
2023-07-28Expose callbacks for encoding of types/attributesMehdi Amini3-93/+219
[mlir] Expose a mechanism to provide a callback for encoding types and attributes in MLIR bytecode. Two callbacks are exposed, respectively, to the BytecodeWriterConfig and to the ParserConfig. At bytecode parsing/printing, clients have the ability to specify a callback to be used to optionally read/write the encoding. On failure, fallback path will execute the default parsers and printers for the dialect. Testing shows how to leverage this functionality to support back-deployment and backward-compatibility usecases when roundtripping to bytecode a client dialect with type/attributes dependencies on upstream. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D153383
2023-07-25[mlir:bytecode] Only visit the all regions path if the op has regionsRiver Riddle1-1/+1
Zero region operations return true for both isBeforeAllRegions and isAfterAllRegions when using WalkStage. The bytecode walk only expects region holding operations in the after regions path, so guard against that.
2023-07-25[mlir:bytecode] Support lazy loading dynamically isolated regionsRiver Riddle3-22/+162
We currently only support lazy loading for regions that statically implement the IsolatedFromAbove trait, but that limits the amount of operations that can be lazily loaded. This review lifts that restriction by computing which operations have isolated regions when numbering, allowing any operation to be lazily loaded as long as it doesn't use values defined above. Differential Revision: https://reviews.llvm.org/D156199
2023-07-25[mlir:bytecode] Fix bytecode lazy loading for ops with multiple regionsRiver Riddle1-11/+15
We currently encode each region as a separate section, but the reader expects all of the regions to be in the same section. This updates the writer to match the behavior that the reader expects. Differential Revision: https://reviews.llvm.org/D156198
2023-07-24Update ODS variadic segments "magic" attributes to use native PropertiesMehdi Amini3-11/+28
The operand_segment_sizes and result_segment_sizes Attributes are now inlined in the operation as native propertie. We continue to support building an Attribute on the fly for `getAttr("operand_segment_sizes")` and setting the property from an attribute with `setAttr("operand_segment_sizes", attr)`. A new bytecode version is introduced to support backward compatibility and backdeployments. Differential Revision: https://reviews.llvm.org/D155919
2023-07-24Revert "Update ODS variadic segments "magic" attributes to use native ↵Mehdi Amini3-28/+11
Properties" This reverts commit 20b93abca6516bbb23689c3777536fea04e46e14. One python test is broken, WIP.
2023-07-24Update ODS variadic segments "magic" attributes to use native PropertiesMehdi Amini3-11/+28
The operand_segment_sizes and result_segment_sizes Attributes are now inlined in the operation as native propertie. We continue to support building an Attribute on the fly for `getAttr("operand_segment_sizes")` and setting the property from an attribute with `setAttr("operand_segment_sizes", attr)`. A new bytecode version is introduced to support backward compatibility and backdeployments. Differential Revision: https://reviews.llvm.org/D155919
2023-06-27[mlir][VectorType] Allow arbitrary dimensions to be scalableAndrzej Warzynski3-0/+7
At the moment, only the trailing dimensions in the vector type can be scalable, i.e. this is supported: vector<2x[4]xf32> and this is not allowed: vector<[2]x4xf32> This patch extends the vector type so that arbitrary dimensions can be scalable. To this end, an array of bool values is added to every vector type to denote whether the corresponding dimensions are scalable or not. For example, for this vector: vector<[2]x[3]x4xf32> the following array would be created: {true, true, false}. Additionally, the current syntax: vector<[2x3]x4xf32> is replaced with: vector<[2]x[3]x4xf32> This is primarily to simplify parsing (this way, the parser can easily process one dimension at a time rather than e.g. tracking whether "scalable block" has been entered/left). NOTE: The `isScalableDim` parameter of `VectorType` (introduced in this patch) makes `numScalableDims` redundant. For the time being, `numScalableDims` is preserved to facilitate the transition between the two parameters. `numScalableDims` will be removed in one of the subsequent patches. This change is a part of a larger effort to enable scalable vectorisation in Linalg. See this RFC for more context: * https://discourse.llvm.org/t/rfc-scalable-vectorisation-in-linalg/ Differential Revision: https://reviews.llvm.org/D153372