summaryrefslogtreecommitdiff
path: root/mlir/lib/Tools/PDLL/Parser/Parser.cpp
AgeCommit message (Collapse)Author
2025-10-15[support] Use VFS in `SourceMgr` for loading includes (#162903)Jan Svoboda
Most `SourceMgr` clients don't make use of include files, but those that do might want to specify the file system to use. This patch enables that by making it possible to pass a `vfs::FileSystem` instance into `SourceMgr`.
2025-08-25[mlir] Fix bug in PDLL Parser (#155243)Youngsuk Kim
This reverts changes made to `mlir/lib/Tools/PDLL/Parser/Parser.cpp` in 095b41c6eedb3acc908dc63ee91ff77944c07d75 . `raw_indented_ostream::printReindented()` reads from a string to which it also concurrently writes to, causing unintended behavior. Credits to @jackalcooper for finding the issue.
2025-07-15[mlir] Remove unused includes (NFC) (#148872)Kazu Hirata
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-06-26[mlir] Migrate away from std::nullopt (NFC) (#145842)Kazu Hirata
ArrayRef has a constructor that accepts std::nullopt. This constructor dates back to the days when we still had llvm::Optional. Since the use of std::nullopt outside the context of std::optional is kind of abuse and not intuitive to new comers, I would like to move away from the constructor and eventually remove it. This patch replaces {} with std::nullopt.
2025-06-21[mlir] Migrate away from ArrayRef(std::nullopt) (NFC) (#145140)Kazu Hirata
ArrayRef has a constructor that accepts std::nullopt. This constructor dates back to the days when we still had llvm::Optional. Since the use of std::nullopt outside the context of std::optional is kind of abuse and not intuitive to new comers, I would like to move away from the constructor and eventually remove it. This patch takes care of the mlir side of the migration, starting with straightforward places like "return std::nullopt;" and ternally expressions involving std::nullopt.
2025-03-31[MLIR][NFC] Fix incomplete boundary comments. (#133516)Han-Chung Wang
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-09-15[mlir] Reland 5a6e52d6ef96d2bcab6dc50bdb369662ff17d2a0 with update (NFC)JOE1994
Excluded updates to mlir/lib/AsmParser/Parser.cpp , which caused LIT failure "FAIL: MLIR::completion.test" on multiple buildbots.
2024-09-15Revert "[mlir] Nits on uses of llvm::raw_string_ostream (NFC)"JOE1994
This reverts commit 5a6e52d6ef96d2bcab6dc50bdb369662ff17d2a0. "FAIL: MLIR::completion.test" on multiple buildbots.
2024-09-15[mlir] Nits on uses of llvm::raw_string_ostream (NFC)JOE1994
* Strip calls to raw_string_ostream::flush(), which is essentially a no-op * Strip unneeded calls to raw_string_ostream::str(), to avoid excess indirection.
2024-09-07[MLIR][TableGen] Migrate MLIR backends to use const RecordKeeper (#107505)Rahul Joshi
- Migrate MLIR backends to use a const RecordKeeper reference.
2024-08-09[mlir][ODS] Consistent `cppType` / `cppClassName` usage (#102657)Matthias Springer
Make sure that the usage of `cppType` and `cppClassName` of type and attribute definitions/constraints is consistent in TableGen. - `cppClassName`: The C++ class name of the type or attribute. - `cppType`: The fully qualified C++ class name: C++ namespace and C++ class name. Basically, we should always use the fully qualified C++ class name for parameter types, return types or template arguments. Also some minor cleanups. Fixes #57279.
2024-07-02mlir/LogicalResult: move into llvm (#97309)Ramkumar Ramachandra
This patch is part of a project to move the Presburger library into LLVM.
2024-04-30[mlir][NFC] update code to use `mlir::dyn_cast/cast/isa` (#90633)Peiming Liu
Fix compiler warning caused by using deprecated interface (https://github.com/llvm/llvm-project/pull/90413)
2024-03-08[PDLL]: Fix crash when negation doesn't apply to native constraint (#84331)Matthias Gehre
Fixes that ``` Pattern { let tuple = (attr<"3 : i34">); not tuple.0; erase _; } ``` would crash the PDLL parser because it expected a native constraint after `not`.
2024-03-02Reapply "[mlir][PDL] Add support for native constraints with results (#82760)"Matthias Gehre
with a small stack-use-after-scope fix in getConstraintPredicates() This reverts commit c80e6edba4a9593f0587e27fa0ac825ebe174afd.
2024-03-01Revert "[mlir][PDL] Add support for native constraints with results (#82760)"Matthias Gehre
Due to buildbot failure https://lab.llvm.org/buildbot/#/builders/88/builds/72130 This reverts commit dca32a3b594b3c91f9766a9312b5d82534910fa1.
2024-03-01[mlir][PDL] Add support for native constraints with results (#82760)Matthias Gehre
From https://reviews.llvm.org/D153245 This adds support for native PDL (and PDLL) C++ constraints to return results. This is useful for situations where a pattern checks for certain constraints of multiple interdependent attributes and computes a new attribute value based on them. Currently, for such an example it is required to escape to C++ during matching to perform the check and after a successful match again escape to native C++ to perform the computation during the rewriting part of the pattern. With this work we can do the computation in C++ during matching and use the result in the rewriting part of the pattern. Effectively this enables a choice in the trade-off of memory consumption during matching vs recomputation of values. This is an example of a situation where this is useful: We have two operations with certain attributes that have interdependent constraints. For instance `attr_foo: one_of [0, 2, 4, 8], attr_bar: one_of [0, 2, 4, 8]` and `attr_foo == attr_bar`. The pattern should only match if all conditions are true. The new operation should be created with a new attribute which is computed from the two matched attributes e.g. `attr_baz = attr_foo * attr_bar`. For the check we already escape to native C++ and have all values at hand so it makes sense to directly compute the new attribute value as well: ``` Constraint checkAndCompute(attr0: Attr, attr1: Attr) -> Attr; Pattern example with benefit(1) { let foo = op<test.foo>() {attr = attr_foo : Attr}; let bar = op<test.bar>(foo) {attr = attr_bar : Attr}; let attr_baz = checkAndCompute(attr_foo, attr_bar); rewrite bar with { let baz = op<test.baz> {attr=attr_baz}; replace bar with baz; }; } ``` To achieve this the following notable changes were necessary: PDLL: - Remove check in PDLL parser that prevented native constraints from returning results PDL: - Change PDL definition of pdl.apply_native_constraint to allow variadic results PDL_interp: - Change PDL_interp definition of pdl_interp.apply_constraint to allow variadic results PDLToPDLInterp Pass: The input to the pass is an arbitrary number of PDL patterns. The pass collects the predicates that are required to match all of the pdl patterns and establishes an ordering that allows creation of a single efficient matcher function to match all of them. Values that are matched and possibly used in the rewriting part of a pattern are represented as positions. This allows fusion and thus reusing a single position for multiple matching patterns. Accordingly, we introduce ConstraintPosition, which records the type and index of the result of the constraint. The problem is for the corresponding value to be used in the rewriting part of a pattern it has to be an input to the pdl_interp.record_match operation, which is generated early during the pass such that its surrounding block can be referred to by branching operations. In consequence the value has to be materialized after the original pdl.apply_native_constraint has been deleted but before we get the chance to generate the corresponding pdl_interp.apply_constraint operation. We solve this by emitting a placeholder value when a ConstraintPosition is evaluated. These placeholder values (due to fusion there may be multiple for one constraint result) are replaced later when the actual pdl_interp.apply_constraint operation is created. Changes since the phabricator review: - Addressed all comments - In particular, removed registerConstraintFunctionWithResults and instead changed registerConstraintFunction so that contraint functions always have results (empty by default) - Thus we don't need to reuse `rewriteFunctions` to store constraint functions with results anymore, and can instead use `constraintFunctions` - Perform a stable sort of ConstraintQuestion, so that ConstraintQuestion appear before other ConstraintQuestion that use their results. - Don't create placeholders for pdl_interp::ApplyConstraintOp. Instead generate the `pdl_interp::ApplyConstraintOp` before generating the successor block. - Fixed a test failure in the pdl python bindings Original code by @martin-luecke Co-authored-by: martin-luecke <martinpaul.luecke@amd.com>
2024-02-16Apply clang-tidy fixes for llvm-include-order in Parser.cpp (NFC)Mehdi Amini
2023-12-13[mlir] Use StringRef::{starts,ends}_with (NFC)Kazu Hirata
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-01[MLIR][PDL] Add PDLL support for negated native constraintsMogball
This commit enables the expression of negated native constraints in PDLL: If a constraint is prefixed with "not" it is parsed as a negated constraint and hence the attribute `isNegated` of the emitted `pdl.apply_native_constraint` operation is set to `true`. In first instance this is only supported for the calling of external native C++ constraints and generation of PDL patterns. Previously, negating a native constraint would have been handled by creating an additional native call, e.g. ```PDLL Constraint checkA(input: Attr); Constarint checkNotA(input: Attr); ``` or by including an explicit additional operand for negation, e.g. `Constraint checkA(input: Attr, negated: Attr);` With this a constraint can simply be negated by prefixing it with `not`. e.g. ```PDLL Constraint simpleConstraint(op: Op); Pattern example { let inputOp = op<test.bar>() ->(type: Type); let root = op<test.foo>(inputOp.0) -> (); not simpleConstraint(inputOp); simpleConstraint(root); erase root; } ``` Depends on [[ https://reviews.llvm.org/D153871 | D153871 ]] Reviewed By: Mogball Differential Revision: https://reviews.llvm.org/D153959
2023-08-30fix unused variable warnings in conditionalsMikhail Goncharov
warning was updated in 92023b15099012a657da07ebf49dd7d94a260f84
2023-01-14[mlir] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata
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-13[mlir] Add #include <optional> (NFC)Kazu Hirata
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with std::optional. 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
2022-12-03[mlir] Use std::nullopt instead of None (NFC)Kazu Hirata
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. 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
2022-12-02Use CTAD on llvm::SaveAndRestoreJan Svoboda
Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D139229
2022-11-08[mlir:PDLL] Allow complex constraints on Rewrite arguments/resultsRiver Riddle
The documentation already has examples of this, and it allows for using nicer C++ types when defining native Rewrites. Differential Revision: https://reviews.llvm.org/D133989
2022-11-08[mlir:PDLL] Don't require users to provide operands/results when all are ↵River Riddle
variadic When all operands or results are variadic, zero values is a perfectly valid behavior to expect, and we shouldn't force the user to provide values in this case. For example, when creating a call or a return operation we often don't want/need to provide return values. Differential Revision: https://reviews.llvm.org/D133721
2022-11-08[mlir:PDLL] Add support for building a range from a tuple within a rewriteRiver Riddle
This allows for constructing type and value ranges from various sub elements, which makes it easier to construct operations that take a range as an operand or result type. Range construction is currently limited to within rewrites, to match the current constraint on the PDL side. Differential Revision: https://reviews.llvm.org/D133720
2022-08-09[mlir] Use C++17 structured bindings instead of std::tie where applicable. NFCIBenjamin Kramer
2022-07-07[mlir][ods] Make Type- and AttrInterfaces also `Type`s and `Attr`sMarkus Böck
By making TypeInterfaces and AttrInterfaces, Types and Attrs respectively it'd then be possible to use them anywhere where a Type or Attr may go. That is within the arguments and results of an Op definition, in a RewritePattern etc. Prior to this change users had to separately define a Type or Attr, with a predicate to check whether a type or attribute implements a given interface. Such code will be redundant now. Removing such occurrences in upstream dialects will be part of a separate patch. As part of implementing this patch, slight refactoring had to be done. In particular, Interfaces cppClassName field was renamed to cppInterfaceName as it "clashed" with TypeConstraints cppClassName. In particular Interfaces cppClassName expected just the class name, without any namespaces, while TypeConstraints cppClassName expected a fully qualified class name. Differential Revision: https://reviews.llvm.org/D129209
2022-06-02[mlir:PDLL] Add better support for providing Constraint/Pattern/Rewrite ↵River Riddle
documentation This commit enables providing long-form documentation more seamlessly to the LSP by revamping decl documentation. For ODS imported constructs, we now also import descriptions and attach them to decls when possible. For PDLL constructs, the LSP will now try to provide documentation by parsing the comments directly above the decls location within the source file. This commit also adds a new parser flag `enableDocumentation` that gates the import and attachment of ODS documentation, which is unnecessary in the normal build process (i.e. it should only be used/consumed by tools). Differential Revision: https://reviews.llvm.org/D124881
2022-05-30[mlir:PDLL] Rework the C++ generation of native Constraint/Rewrite arguments ↵River Riddle
and results The current translation uses the old "ugly"/"raw" form which used PDLValue for the arguments and results. This commit updates the C++ generation to use the recently added sugar that allows for directly using the desired types for the arguments and result of PDL functions. In addition, this commit also properly imports the C++ class for ODS operations, constraints, and interfaces. This allows for a much more convienent C++ API than previously granted with the raw/low-level types. Differential Revision: https://reviews.llvm.org/D124817
2022-05-30[mlir:PDLL] Fix signature help for operation operandsRiver Riddle
We were currently only completing on the first operand because the completion check was outside of the parse loop. Differential Revision: https://reviews.llvm.org/D124784
2022-05-30[mlir:PDLL] Add proper support for operation result type inferenceRiver Riddle
This allows for the results of operations to be inferred in certain contexts, and matches the support in PDL for result type inference. The main two initial circumstances are when used as a replacement of another operation, or when the operation being created implements InferTypeOpInterface. Differential Revision: https://reviews.llvm.org/D124782
2022-05-25[mlir][PDLL] Allow numeric result indexing for unregistered opChia-hung Duan
If we don't specify the result index while matching operand with the result of certain operation, it's supposed to match all the results of the operation with the operand. For registered op, it's easy to do that by either indexing with number or name. For unregistered op, this commit enables the numeric result indexing for this use case. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D126330
2022-05-18[mlir:PDLL] Improve the location ranges of several expressions during parsingRiver Riddle
This allows for the range to encompass more of the source associated with the full expression, making diagnostics easier to see/tooling easier/etc.
2022-05-11[TableGen] Refactor TableGenParseFile to no longer use a callbackRiver Riddle
Now that TableGen no longer relies on global Record state, we can allow for the client to own the RecordKeeper and SourceMgr. Given that TableGen internally still relies on the global llvm::SrcMgr, this method unfortunately still isn't thread-safe. Differential Revision: https://reviews.llvm.org/D125277
2022-04-28[mlir:PDLL] Fix the import of native constraints from ODSRiver Riddle
We weren't properly returning the result of the constraint, which leads to errors when actually trying to use the generated C++. Differential Revision: https://reviews.llvm.org/D124586
2022-04-28[mlir:PDLL] Fix error handling of eof within a string literalRiver Riddle
We currently aren't handling this properly, and in the case of a string block just crash. This commit adds proper error handling and detection for eof. Differential Revision: https://reviews.llvm.org/D124585
2022-04-26[mlir][PDLL-LSP] Add code completion for include file pathsRiver Riddle
This allows for providing completion results for include directive file paths by searching the set of include directories for the current file. Differential Revision: https://reviews.llvm.org/D124112
2022-04-26[mlir][PDLL] Add document link and hover support to mlir-pdll-lsp-serverRiver Riddle
This allows for navigating to included files on click, and also provides hover information about the include file (similarly to clangd). Differential Revision: https://reviews.llvm.org/D124077
2022-04-26[mlir][PDLL] Don't use the result of `Constraint::getDefName()` when uniquingRiver Riddle
In the case of anonymous defs this may return the name of the base def class, which can lead to two different defs with the same name (which hits an assert). This commit adds a new `getUniqueDefName` method that returns a unique name for the constraint. Differential Revision: https://reviews.llvm.org/D124074
2022-03-19[mlir][PDLL] Add signature help to the PDLL language serverRiver Riddle
This commit adds signature support to the language server, and initially supports providing help for: operation operands and results, and constraint/rewrite calls. Differential Revision: https://reviews.llvm.org/D121545
2022-03-19[mlir][PDLL] Add code completion to the PDLL language serverRiver Riddle
This commit adds code completion support to the language server, and initially supports providing completions for: Member access, attributes/constraint/dialect/operation names, and pattern metadata. Differential Revision: https://reviews.llvm.org/D121544
2022-03-07Apply clang-tidy fixes for modernize-use-default-member-init to MLIR (NFC)Mehdi Amini
2022-03-03[PDLL] Add support for tablegen includes and importing ODS informationRiver Riddle
This commit adds support for processing tablegen include files, and importing various information from ODS. This includes operations, attribute+type constraints, attribute/operation/type interfaces, etc. This will allow for much more robust tooling, and also allows for referencing ODS constructs directly within PDLL (imported interfaces can be used as constraints, operation result names can be used for member access, etc). Differential Revision: https://reviews.llvm.org/D119900
2022-02-26[PDLL] Properly error out on returning results from native constraintsRiver Riddle
PDL currently doesn't support result values from constraints, meaning we need to error out until this is actually supported to avoid crashes. Differential Revision: https://reviews.llvm.org/D119782
2022-02-26[mlir:PDLL] Fix handling of unspecified operands/results on operation ↵River Riddle
expressions If the operand list or result list of an operation expression is not specified, we interpret this as meaning that the operands/results are "unconstraint" (i.e. "could be anything"). We currently don't properly handle differentiating this case from the case of "no operands/results". This commit adds the insertion of implicit value/type range variables when these lists are unspecified. This allows for adding proper support for when zero operands or results are expected. Differential Revision: https://reviews.llvm.org/D119780
2022-02-10[PDLL] Attempt to fix the gcc5 build by adding this-> to auto lambdaRiver Riddle
2022-02-10[PDLL] Add support for user defined constraint and rewrite functionsRiver Riddle
These functions allow for defining pattern fragments usable within the `match` and `rewrite` sections of a pattern. The main structure of Constraints and Rewrites functions are the same, and are similar to functions in other languages; they contain a signature (i.e. name, argument list, result list) and a body: ```pdll // Constraint that takes a value as an input, and produces a value: Constraint Cst(arg: Value) -> Value { ... } // Constraint that returns multiple values: Constraint Cst() -> (result1: Value, result2: ValueRange); ``` When returning multiple results, each result can be optionally be named (the result of a Constraint/Rewrite in the case of multiple results is a tuple). These body of a Constraint/Rewrite functions can be specified in several ways: * Externally In this case we are importing an external function (registered by the user outside of PDLL): ```pdll Constraint Foo(op: Op); Rewrite Bar(); ``` * In PDLL (using PDLL constructs) In this case, the body is defined using PDLL constructs: ```pdll Rewrite BuildFooOp() { // The result type of the Rewrite is inferred from the return. return op<my_dialect.foo>; } // Constraints/Rewrites can also implement a lambda/expression // body for simple one line bodies. Rewrite BuildFooOp() => op<my_dialect.foo>; ``` * In PDLL (using a native/C++ code block) In this case the body is specified using a C++(or potentially other language at some point) code block. When building PDLL in AOT mode this will generate a native constraint/rewrite and register it with the PDL bytecode. ```pdll Rewrite BuildFooOp() -> Op<my_dialect.foo> [{ return rewriter.create<my_dialect::FooOp>(...); }]; ``` Differential Revision: https://reviews.llvm.org/D115836