aboutsummaryrefslogtreecommitdiff
path: root/mlir/lib/Bytecode/Reader/BytecodeReader.cpp
AgeCommit message (Collapse)AuthorFilesLines
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] 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-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-03-31[MLIR][NFC] Fix incomplete boundary comments. (#133516)Han-Chung Wang1-0/+5
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>
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-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-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 Ramachandra1-1/+0
This patch is part of a project to move the Presburger library into LLVM.
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.
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-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-07-28Expose callbacks for encoding of types/attributesMatteo Franciolini1-61/+120
[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 Amini1-120/+61
This reverts commit b299ec16661f653df66cdaf161cdc5441bc9803c. The authorship informations were incorrect.
2023-07-28Expose callbacks for encoding of types/attributesMehdi Amini1-61/+120
[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-24Update ODS variadic segments "magic" attributes to use native PropertiesMehdi Amini1-10/+20
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 Amini1-20/+10
Properties" This reverts commit 20b93abca6516bbb23689c3777536fea04e46e14. One python test is broken, WIP.
2023-07-24Update ODS variadic segments "magic" attributes to use native PropertiesMehdi Amini1-10/+20
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 Warzynski1-0/+4
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
2023-06-26[mlir][bytecode] Fix lazy loading of non-isolated regionsRiver Riddle1-12/+9
The bytecode reader currently assumes all regions can be lazy loaded, which breaks reading any non-isolated region. This patch fixes that by properly handling nested non-lazy regions, and only considers isolated regions as lazy. Differential Revision: https://reviews.llvm.org/D153795
2023-06-23Fix bytecode reader/writer on big-endian platformsUlrich Weigand1-6/+12
This makes the bytecode reader/writer work on big-endian platforms. The only problem was related to encoding of multi-byte integers, where both reader and writer code make implicit assumptions about endianness of the host platform. This fixes the current test failures on s390x, and in addition allows to remove the UNSUPPORTED markers from all other bytecode-related test cases - they now also all pass on s390x. Also adding a GFAIL_SKIP to the MultiModuleWithResource unit test, as this still fails due to an unrelated endian bug regarding decoding of external resources. Differential Revision: https://reviews.llvm.org/D153567 Reviewed By: mehdi_amini, jpienaar, rriddle
2023-06-06Use symbolic name for previous MLIR Bytecode versionsMehdi Amini1-16/+17
Reviewed By: jpienaar, burmako Differential Revision: https://reviews.llvm.org/D151621
2023-05-27[mlir] Fix non-const lvalue reference to type 'uint64_t' cannot bind to type ↵Jie Fu1-2/+2
'size_t' error (NFC) /Users/jiefu/llvm-project/mlir/lib/Bytecode/Reader/BytecodeReader.cpp:1007:39: error: non-const lvalue reference to type 'uint64_t' (aka 'unsigned long long') cannot bind to a value of unrelated type 'size_t' (aka 'unsigned long') if (failed(propReader.parseVarInt(count))) ^~~~~ /Users/jiefu/llvm-project/mlir/lib/Bytecode/Reader/BytecodeReader.cpp:191:39: note: passing argument to parameter 'result' here LogicalResult parseVarInt(uint64_t &result) { ^ /Users/jiefu/llvm-project/mlir/lib/Bytecode/Reader/BytecodeReader.cpp:1020:44: error: non-const lvalue reference to type 'uint64_t' (aka 'unsigned long long') cannot bind to a value of unrelated type 'size_t' (aka 'unsigned long') if (failed(offsetsReader.parseVarInt(dataSize)) || ^~~~~~~~ /Users/jiefu/llvm-project/mlir/lib/Bytecode/Reader/BytecodeReader.cpp:191:39: note: passing argument to parameter 'result' here LogicalResult parseVarInt(uint64_t &result) { ^ 2 errors generated.
2023-05-26[MLIR] Add native Bytecode support for propertiesMehdi Amini1-14/+184
This is adding a new interface (`BytecodeOpInterface`) to allow operations to opt-in skipping conversion to attribute and serializing properties to native bytecode. The scheme relies on a new section where properties are stored in sequence { size, serialize_properties }, ... The operations are storing the index of a properties, a table of offset is built when loading the properties section the first time. This is a re-commit of 837d1ce0dc which conflicted with another patch upgrading the bytecode and the collision wasn't properly resolved before. Differential Revision: https://reviews.llvm.org/D151065
2023-05-25Revert "[MLIR] Add native Bytecode support for properties"Mehdi Amini1-168/+13
This reverts commit ca5a12fd69d4acf70c08f797cbffd714dd548348 and follow-up fixes: df34c288c428eb4b867c8075def48b3d1727d60b 07dc906883af660780cf6d0cc1044f7e74dab83e ab80ad0095083fda062c23ac90df84c40b4332c8 837d1ce0dc8eec5b17255291b3462e6296cb369b The first commit was incomplete and broken, I'll prepare a new version later, in the meantime pull this work out of tree.
2023-05-26[mlir] Fix non-const lvalue reference to type 'uint64_t' cannot bind to type ↵Jie Fu1-2/+2
'size_t' error (NFC) /Users/jiefu/llvm-project/mlir/lib/Bytecode/Reader/BytecodeReader.cpp:1007:39: error: non-const lvalue reference to type 'uint64_t' (aka 'unsigned long long') cannot bind to a value of unrelated type 'size_t' (aka 'unsigned long') if (failed(propReader.parseVarInt(count))) ^~~~~ /Users/jiefu/llvm-project/mlir/lib/Bytecode/Reader/BytecodeReader.cpp:191:39: note: passing argument to parameter 'result' here LogicalResult parseVarInt(uint64_t &result) { ^ /Users/jiefu/llvm-project/mlir/lib/Bytecode/Reader/BytecodeReader.cpp:1033:41: error: non-const lvalue reference to type 'uint64_t' (aka 'unsigned long long') cannot bind to a value of unrelated type 'size_t' (aka 'unsigned long') if (failed(dialectReader.readVarInt(propertiesIdx))) ^~~~~~~~~~~~~ /Users/jiefu/llvm-project/mlir/lib/Bytecode/Reader/BytecodeReader.cpp:926:38: note: passing argument to parameter 'result' here LogicalResult readVarInt(uint64_t &result) override { ^ 2 errors generated. /Users/jiefu/llvm-project/mlir/lib/Bytecode/Reader/BytecodeReader.cpp:1033:41: error: non-const lvalue reference to type 'uint64_t' (aka 'unsigned long long') cannot bind to a value of unrelated type 'size_t' (aka 'unsigned long') if (failed(dialectReader.readVarInt(propertiesIdx))) ^~~~~~~~~~~~~ /Users/jiefu/llvm-project/mlir/lib/Bytecode/Reader/BytecodeReader.cpp:926:38: note: passing argument to parameter 'result' here LogicalResult readVarInt(uint64_t &result) override { ^ 1 error generated.
2023-05-25[MLIR] Add native Bytecode support for propertiesMehdi Amini1-13/+168
This is adding a new interface (`BytecodeOpInterface`) to allow operations to opt-in skipping conversion to attribute and serializing properties to native bytecode. The scheme relies on a new section where properties are stored in sequence { size, serialize_properties }, ... The operations are storing the index of a properties, a table of offset is built when loading the properties section the first time. Back-deployment to version prior to 4 are relying on getAttrDictionnary() which we intend to deprecate and remove: that is putting a de-factor end-of-support horizon for supporting deployments to version older than 4. Differential Revision: https://reviews.llvm.org/D151065
2023-05-25[mlir][bytecode] Avoid recording null arglocs & realloc opnames.Jacques Pienaar1-5/+25
For block arg locs a common case is no/uknown location (where the producer signifies they don't care about blockarg location). Also avoid needing to dynamically resize opnames during parsing. Assumed to be post lazy loading change, so chose version 3. Differential Revision: https://reviews.llvm.org/D151038
2023-05-25Fix MLIR bytecode loading of resourcesMehdi Amini1-1/+14
The bytecode reader didn't handle properly the case where resource names conflicted and were renamed, leading to orphan handles in the IR as well as overwriting the exiting resources. Differential Revision: https://reviews.llvm.org/D151408
2023-05-25Fix MLIR bytecode reader for unregistered dialectsMehdi Amini1-2/+15
At the moment we accept (in tests) unregistered dialects and in particular: "new_processor_id_and_range"() where there is no `.` separator. We probably will remove support for this from the parser, but for now we're adding compatibility support in the reader. Differential Revision: https://reviews.llvm.org/D151386
2023-05-21Preserve use-list orders in mlir bytecodeMatteo Franciolini1-2/+255
This patch implements a mechanism to read/write use-list orders from/to the mlir bytecode format. When producing bytecode, use-list orders are appended to each value of the IR. When reading bytecode, use-lists orders are loaded in memory and used at the end of parsing to sort the existing use-list chains. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D149755
2023-05-20Add support for Lazyloading to the MLIR bytecodeMehdi Amini1-54/+230
IsolatedRegions are emitted in sections in order for the reader to be able to skip over them. A new class is exposed to manage the state and allow the readers to load these IsolatedRegions on-demand. Differential Revision: https://reviews.llvm.org/D149515
2023-05-12[mlir] Move casting calls from methods to function callsTres Popp1-1/+1
The MLIR classes Type/Attribute/Operation/Op/Value support cast/dyn_cast/isa/dyn_cast_or_null functionality through llvm's doCast functionality in addition to defining methods with the same name. This change begins the migration of uses of the method to the corresponding function call as has been decided as more consistent. Note that there still exist classes that only define methods directly, such as AffineExpr, and this does not include work currently to support a functional cast/isa call. Caveats include: - This clang-tidy script probably has more problems. - This only touches C++ code, so nothing that is being generated. Context: - https://mlir.llvm.org/deprecation/ at "Use the free function variants for dyn_cast/cast/isa/…" - Original discussion at https://discourse.llvm.org/t/preferred-casting-style-going-forward/68443 Implementation: This first patch was created with the following steps. The intention is to only do automated changes at first, so I waste less time if it's reverted, and so the first mass change is more clear as an example to other teams that will need to follow similar steps. Steps are described per line, as comments are removed by git: 0. Retrieve the change from the following to build clang-tidy with an additional check: https://github.com/llvm/llvm-project/compare/main...tpopp:llvm-project:tidy-cast-check 1. Build clang-tidy 2. Run clang-tidy over your entire codebase while disabling all checks and enabling the one relevant one. Run on all header files also. 3. Delete .inc files that were also modified, so the next build rebuilds them to a pure state. 4. Some changes have been deleted for the following reasons: - Some files had a variable also named cast - Some files had not included a header file that defines the cast functions - Some files are definitions of the classes that have the casting methods, so the code still refers to the method instead of the function without adding a prefix or removing the method declaration at the same time. ``` ninja -C $BUILD_DIR clang-tidy run-clang-tidy -clang-tidy-binary=$BUILD_DIR/bin/clang-tidy -checks='-*,misc-cast-functions'\ -header-filter=mlir/ mlir/* -fix rm -rf $BUILD_DIR/tools/mlir/**/*.inc git restore mlir/lib/IR mlir/lib/Dialect/DLTI/DLTI.cpp\ mlir/lib/Dialect/Complex/IR/ComplexDialect.cpp\ mlir/lib/**/IR/\ mlir/lib/Dialect/SparseTensor/Transforms/SparseVectorization.cpp\ mlir/lib/Dialect/Vector/Transforms/LowerVectorMultiReduction.cpp\ mlir/test/lib/Dialect/Test/TestTypes.cpp\ mlir/test/lib/Dialect/Transform/TestTransformDialectExtension.cpp\ mlir/test/lib/Dialect/Test/TestAttributes.cpp\ mlir/unittests/TableGen/EnumsGenTest.cpp\ mlir/test/python/lib/PythonTestCAPI.cpp\ mlir/include/mlir/IR/ ``` Differential Revision: https://reviews.llvm.org/D150123
2023-05-11[mlir][bytecode] Fix dialect version parsing.Jacques Pienaar1-4/+13
We were querying the wrong EncReader along some paths that resulted in failures depending on if one encountered an Attribute from an unloaded dialect before encountering an operation from that dialect. Also fix error where we were able to emit "custom" form for an attribute without custom form in TestDialect. Differential Revision: https://reviews.llvm.org/D150260
2023-03-10Implements MLIR Bytecode versioning capabilityMatteo Franciolini1-37/+123
A dialect can opt-in to handle versioning through the `BytecodeDialectInterface`. Few hooks are exposed to the dialect to allow managing a version encoded into the bytecode file. The version is loaded lazily and allows to retrieve the version information while parsing the input IR, and gives an opportunity to each dialect for which a version is present to perform IR upgrades post-parsing through the `upgradeFromVersion` method. Custom Attribute and Type encodings can also be upgraded according to the dialect version using readAttribute and readType methods. There is no restriction on what kind of information a dialect is allowed to encode to model its versioning. Currently, versioning is supported only for bytecode formats. Reviewed By: rriddle, mehdi_amini Differential Revision: https://reviews.llvm.org/D143647
2023-03-03[mlir][Parser] Make parse{Attribute,Type} null-terminate inputRahul Kayaith1-2/+4
`parseAttribute` and `parseType` require null-terminated strings as input, but this isn't great considering the argument type is `StringRef`. This changes them to copy to a null-terminated buffer by default, with a `isKnownNullTerminated` flag added to disable the copying. closes #58964 Reviewed By: rriddle, kuhar, lattner Differential Revision: https://reviews.llvm.org/D145182
2023-03-01[mlir][AsmParser] Improve parse{Attribute,Type} error handlingRahul Kayaith1-2/+2
Currently these functions report errors directly to stderr, this updates them to use diagnostics instead. This also makes partially-consumed strings an error if the `numRead` parameter isn't provided (the docstrings already claimed this happened, but it didn't.) While here I also tried to reduce the number of overloads by switching to using default parameters. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D144804
2023-01-28Use llvm::count{lr}_{zero,one} (NFC)Kazu Hirata1-1/+1
2023-01-18Drop the ZeroBehavior parameter from countLeadingZeros and the like (NFC)Kazu Hirata1-2/+1
This patch drops the ZeroBehavior parameter from bit counting functions like countLeadingZeros. ZeroBehavior specifies the behavior when the input to count{Leading,Trailing}Zeros is zero and when the input to count{Leading,Trailing}Ones is all ones. ZeroBehavior was first introduced on May 24, 2013 in commit eb91eac9fb866ab1243366d2e238b9961895612d. While that patch did not state the intention, I would guess ZeroBehavior was for performance reasons. The x86 machines around that time required a conditional branch to implement countLeadingZero<uint32_t> that returns the 32 on zero: test edi, edi je .LBB0_2 bsr eax, edi xor eax, 31 .LBB1_2: mov eax, 32 That is, we can remove the conditional branch if we don't care about the behavior on zero. IIUC, Intel's Haswell architecture, launched on June 4, 2013, introduced several bit manipulation instructions, including lzcnt and tzcnt, which eliminated the need for the conditional branch. I think it's time to retire ZeroBehavior as its utility is very limited. If you care about compilation speed, you should build LLVM with an appropriate -march= to take advantage of lzcnt and tzcnt. Even if not, modern host compilers should be able to optimize away quite a few conditional branches because the input is often known to be nonzero from dominating conditional branches. Differential Revision: https://reviews.llvm.org/D141798
2023-01-14[mlir] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata1-5/+6
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to remove #include "llvm/ADT/Optional.h". This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-10Move from llvm::makeArrayRef to ArrayRef deduction guides - last partserge-sans-paille1-2/+2
This is a follow-up to https://reviews.llvm.org/D140896, split into several parts as it touches a lot of files. Differential Revision: https://reviews.llvm.org/D141298
2022-12-11[mlir:Bytecode] Add shared_ptr<SourceMgr> overloads to allow safe mmap of dataRiver Riddle1-24/+66
The bytecode reader currently has no mechanism that allows for directly referencing data from the input buffer safely. This commit adds shared_ptr<SourceMgr> overloads that provide an explicit and safe way of extending the lifetime of the input. The usage of these new overloads is adopted in all of our tooling, and is implicitly used in the filename only parser methods. Differential Revision: https://reviews.llvm.org/D139366