summaryrefslogtreecommitdiff
path: root/mlir/unittests
Commit message (Collapse)AuthorAgeFilesLines
* [mlir] Update method cast calls to function callsTres Popp2023-05-121-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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. 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 follows a previous patch that updated calls `op.cast<T>()-> cast<T>(op)`. However some cases could not handle an unprefixed `cast` call due to occurrences of variables named cast, or occurring inside of class definitions which would resolve to the method. All C++ files that did not work automatically with `cast<T>()` are updated here to `llvm::cast` and similar with the intention that they can be easily updated after the methods are removed through a find-replace. See https://github.com/llvm/llvm-project/compare/main...tpopp:llvm-project:tidy-cast-check for the clang-tidy check that is used and then update printed occurrences of the function to include `llvm::` before. One can then run the following: ``` ninja -C $BUILD_DIR clang-tidy run-clang-tidy -clang-tidy-binary=$BUILD_DIR/bin/clang-tidy -checks='-*,misc-cast-functions'\ -export-fixes /tmp/cast/casts.yaml mlir/*\ -header-filter=mlir/ -fix rm -rf $BUILD_DIR/tools/mlir/**/*.inc ``` Differential Revision: https://reviews.llvm.org/D150348
* [mlir] Move casting calls from methods to function callsTres Popp2023-05-125-45/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Introduce MLIR Op PropertiesMehdi Amini2023-05-016-14/+374
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This new features enabled to dedicate custom storage inline within operations. This storage can be used as an alternative to attributes to store data that is specific to an operation. Attribute can also be stored inside the properties storage if desired, but any kind of data can be present as well. This offers a way to store and mutate data without uniquing in the Context like Attribute. See the OpPropertiesTest.cpp for an example where a struct with a std::vector<> is attached to an operation and mutated in-place: struct TestProperties { int a = -1; float b = -1.; std::vector<int64_t> array = {-33}; }; More complex scheme (including reference-counting) are also possible. The only constraint to enable storing a C++ object as "properties" on an operation is to implement three functions: - convert from the candidate object to an Attribute - convert from the Attribute to the candidate object - hash the object Optional the parsing and printing can also be customized with 2 extra functions. A new options is introduced to ODS to allow dialects to specify: let usePropertiesForAttributes = 1; When set to true, the inherent attributes for all the ops in this dialect will be using properties instead of being stored alongside discardable attributes. The TestDialect showcases this feature. Another change is that we introduce new APIs on the Operation class to access separately the inherent attributes from the discardable ones. We envision deprecating and removing the `getAttr()`, `getAttrsDictionary()`, and other similar method which don't make the distinction explicit, leading to an entirely separate namespace for discardable attributes. Recommit d572cd1b067f after fixing python bindings build. Differential Revision: https://reviews.llvm.org/D141742
* Revert "Introduce MLIR Op Properties"Mehdi Amini2023-05-016-374/+14
| | | | | | This reverts commit d572cd1b067f1177a981a4711bf2e501eaa8117b. Some bots are broken and investigation is needed before relanding.
* Introduce MLIR Op PropertiesMehdi Amini2023-05-016-14/+374
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This new features enabled to dedicate custom storage inline within operations. This storage can be used as an alternative to attributes to store data that is specific to an operation. Attribute can also be stored inside the properties storage if desired, but any kind of data can be present as well. This offers a way to store and mutate data without uniquing in the Context like Attribute. See the OpPropertiesTest.cpp for an example where a struct with a std::vector<> is attached to an operation and mutated in-place: struct TestProperties { int a = -1; float b = -1.; std::vector<int64_t> array = {-33}; }; More complex scheme (including reference-counting) are also possible. The only constraint to enable storing a C++ object as "properties" on an operation is to implement three functions: - convert from the candidate object to an Attribute - convert from the Attribute to the candidate object - hash the object Optional the parsing and printing can also be customized with 2 extra functions. A new options is introduced to ODS to allow dialects to specify: let usePropertiesForAttributes = 1; When set to true, the inherent attributes for all the ops in this dialect will be using properties instead of being stored alongside discardable attributes. The TestDialect showcases this feature. Another change is that we introduce new APIs on the Operation class to access separately the inherent attributes from the discardable ones. We envision deprecating and removing the `getAttr()`, `getAttrsDictionary()`, and other similar method which don't make the distinction explicit, leading to an entirely separate namespace for discardable attributes. Differential Revision: https://reviews.llvm.org/D141742
* [mlir][test] Remove unused lambda capture 'this' in UtilsTest.cpp (NFC)Jie Fu2023-04-271-2/+2
| | | | | | | | | | /data/llvm-project/mlir/unittests/Analysis/Presburger/UtilsTest.cpp:39:17: error: lambda capture 'this' is not used [-Werror,-Wunused-lambda-capture] auto merge = [this](unsigned i, unsigned j) -> bool { return true; }; ^~~~ /data/llvm-project/mlir/unittests/Analysis/Presburger/UtilsTest.cpp:52:17: error: lambda capture 'this' is not used [-Werror,-Wunused-lambda-capture] auto merge = [this](unsigned i, unsigned j) -> bool { return true; }; ^~~~ 2 errors generated.
* [MLIR][presburger] normalize divisionreprgilsaia2023-04-272-0/+69
| | | | | | | | | Added a simple normalize function to divisionrepr and added a simple unittest. Added a normalizediv call to divisionrepr's removeDuplicateDivs function, which now eliminates divs that are consistent after gcd's normalize Reviewed By: Groverkss Differential Revision: https://reviews.llvm.org/D147381
* Add a breakpoint manager that matches based on File/Line/Col LocationsMehdi Amini2023-04-212-0/+233
| | | | | | | | | This will match the locations attached to the IRunits passed in as context with an action. This is a recommit of d09c80515d0e after fixing the test on Windows. Differential Revision: https://reviews.llvm.org/D144815
* Revert "Add a breakpoint manager that matches based on File/Line/Col Locations"Mehdi Amini2023-04-212-233/+0
| | | | | | This reverts commit d09c80515d0e7b1f1a81d3f18a3e799565f5e969. This is broken on Windows
* Add a breakpoint manager that matches based on File/Line/Col LocationsMehdi Amini2023-04-212-0/+233
| | | | | | | This will match the locations attached to the IRunits passed in as context with an action. Differential Revision: https://reviews.llvm.org/D144815
* [mlir][Affine][NFC] Wrap dialect in "affine" namespaceMatthias Springer2023-04-201-1/+1
| | | | | | This cleanup aligns the affine dialect with all the other dialects. Differential Revision: https://reviews.llvm.org/D148687
* [mlir] Add stack alignment to the data layout dialect.Tobias Gysi2023-04-031-1/+11
| | | | | | | | | | | | | | | | | The revision adds the stack alignment to the data layout dialect and it extends the LLVM dialect import and export to support the new data layout entry. One possible use case for the flag is the LLVM dialect inliner. The LLVM inliner queries the flag to determine if it is safe to update the alignment of an existing alloca. We may want to perform the same optimization inside of MLIR. Reviewed By: Dinistro Differential Revision: https://reviews.llvm.org/D147332
* [mlir][sparse] Preliminary code changes for ExprId, LatPointId, LatSetId ↵wren romano2023-03-291-13/+5
| | | | | | | | | | | | newtypes This commit contains several code changes which are ultimately required for converting the varions `Merger` identifiers from typedefs to newtypes. The actual implementation of the newtypes themselves has been split off into separate commits, in hopes of simplifying the review process. Depends On D146561 Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D146684
* [mlir][sparse] Fixing -Wignored-reference-qualifiers in MergerTest.cppwren romano2023-03-281-23/+23
| | | | | | | | These warnings were introduced by D146561. Reviewed By: aartbik, Peiming Differential Revision: https://reviews.llvm.org/D147090
* [mlir][sparse] Removing shared_ptr from the MergerTest.cpp unit testwren romano2023-03-281-243/+231
| | | | | | | | | | This is a preliminary change to make way for converting the Merger's identifier types from mere typedefs to actual types (which causes some issues that this patch fixes). Depends On D146676 Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D146561
* [mlir] Fix unit tests after LLVM commit 8b1771bd9f3.Lang Hames2023-03-271-1/+2
|
* [mlir] Add missing cast functions to mlir namespaceRahul Kayaith2023-03-271-4/+3
| | | | | | Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D146843
* [mlir][ClangTidy] Remove redundant return (NFC).Adrian Kuegel2023-03-271-1/+1
|
* [mlir][Analysis][NFC] Make BoundType a top-level enumMatthias Springer2023-03-231-4/+4
| | | | | | | | `BoundType` is no longer a nested member of `IntegerRelation` but a top-level enum in the `presburger` namespace. This allows `BoundType` to be predeclared in header files. Nested members cannot be predeclared. Differential Revision: https://reviews.llvm.org/D146210
* [mlir][sparse] fix crash when using pure constant index in indexing mapping ↵Peiming Liu2023-03-211-1/+2
| | | | | | | | | | (fixes #61530) To address https://github.com/llvm/llvm-project/issues/61530 Reviewed By: aartbik, wrengr Differential Revision: https://reviews.llvm.org/D146563
* [mlir] Add alloca address space handling to the data layout subsystemJan Sjodin2023-03-211-1/+25
| | | | | | | | | | This patch adds alloca address space information to the data layout interface and implementation in the DLTI dialect. This is needed for targets that use separate address spaces for local/stack data. Reviewed By: ftynse, krzysz00 Differential Revision: https://reviews.llvm.org/D144657
* [mlir] Support lowering of dialect attributes attached to top-level modulesSergio Afonso2023-03-211-0/+7
| | | | | | | | | | | | | | | | | | | | | | | This patch supports the processing of dialect attributes attached to top-level module-type operations during MLIR-to-LLVMIR lowering. This approach modifies the `mlir::translateModuleToLLVMIR()` function to call `ModuleTranslation::convertOperation()` on the top-level operation, after its body has been lowered. This, in turn, will get the `LLVMTranslationDialectInterface` object associated to that operation's dialect before trying to use it for lowering prior to processing dialect attributes attached to the operation. Since there are no `LLVMTranslationDialectInterface`s for the builtin and GPU dialects, which define their own module-type operations, this patch also adds and registers them. The requirement for always calling `mlir::registerBuiltinDialectTranslation()` before any translation of MLIR to LLVM IR where builtin module operations are present is introduced. The purpose of these new translation interfaces is to succeed when processing module-type operations, allowing the lowering process to continue and to prevent the introduction of failures related to not finding such interfaces. Differential Revision: https://reviews.llvm.org/D145932
* [mlir][sparse] Making `TensorExp::Kind` a nested enum-classwren romano2023-03-201-92/+93
| | | | | | | | This improves namespacing, and follows the pattern used for "Kind" enums elsewhere in MLIR. Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D146086
* [mlir][sparse] Cleaning up names in {Merger,LoopEmitter,CodegenEnv}.{h,cpp}wren romano2023-03-141-18/+18
| | | | | | | | | | | | | | | | | | This change does a bunch of renaming to clear up confusions in these files. In particular, this change: * Renames variables and methods to clarify the "dim"/"lvl" distinction, and changes them to use the `Dimension`/`Level` types as appropriate. * Introduces new typedefs * `ExprId`, `LatPointId`, `LatSetId`: to clarify the interning design of the Merger. * `LoopId`, `LoopOrd`: to clarify the distinction between arbitrary names for loop-variables, vs numeric identifiers based on the actual order of loop generation. * `TensorId` * (Future CLs will change these from typedefs to structs/classes, so that the typechecker can help avoid mixups.) * Updates documentation to match the new terminology * Adds additional assertions * Adds `const` to local variables along the way Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D145756
* Introduce mlir::tracing::ExecutionContextMehdi Amini2023-03-122-0/+353
| | | | | | | | | | | | | | | | | | This component acts as an action handler that can be registered in the MLIRContext. It is the main orchestration of the infrastructure, and implements support for clients to hook there and snoop on or control the execution. This is the basis to build tracing as well as a "gdb-like" control of the compilation flow. The ExecutionContext acts as a handler in the MLIRContext for executing an Action. When an action is dispatched, it'll query its set of Breakpoints managers for a breakpoint matching this action. If a breakpoint is hit, it passes the action and the breakpoint information to a callback. The callback is responsible for controlling the execution of the action through an enum value it returns. Optionally, observers can be registered to be notified before and after the callback is executed. Differential Revision: https://reviews.llvm.org/D144812
* Delete ActionManager and replace it with a simple callback on the ContextMehdi Amini2023-03-073-147/+18
| | | | | | | | | | | | | The concept of the ActionManager acts as a sort of "Hub" that can receive various types of action and dispatch them to a set of registered handlers. One handler will handle the action or it'll cascade to other handlers. This model does not really fit the current evolution of the Action tracing and debugging: we can't foresee a good case where this behavior compose with the use-case behind the handlers. Instead we simplify it with a single callback installed on the Context. Differential Revision: https://reviews.llvm.org/D144811
* Rename DebugAction to tracing::Action and move related code from lib/Support ↵Mehdi Amini2023-03-066-34/+35
| | | | | | | | | | | | | | to lib/IR and lib/Debug This is a preparation for adding support for more infrastructure around the concept of Action and make tracing Action more of a first class concept. The doc will be updated later in a subsequent revision after the changes are completed. Action belongs to IR because of circular dependency: Actions are dispatched through the MLIRContext but Action will learn to encapsulate IR construct. Differential Revision: https://reviews.llvm.org/D144809
* Change the DebugAction paradigm to delegate the control to the handlerMehdi Amini2023-03-062-35/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | At the moment, we invoke `shouldExecute()` that way: ``` if (manager.shouldExecute<DebugAction>(currentOp) { // apply a transformation … } ``` In this sequence, the manager isn’t involved in the actual execution of the action and can’t develop rich instrumentations. Instead the API could let the control to the handler itself: ``` // Execute the action under the control of the manager manager.execute<DebugAction>(currentOp, [&]() { // apply the transformation in this callback … }); ``` This inversion of control (by injecting a callback) allows handlers to implement potentially new interesting features: for example, snapshot the IR before and after the action, or record an action execution time. More importantly, it will allow to capture the nesting execution of actions. On the other side: handlers receives now a DebugAction object that wraps generic information (tag and description especially) as well as action-specific data. Finally, the DebugActionManager is now enabled in release builds as well. Differential Revision: https://reviews.llvm.org/D144808
* [mlir][Parser] Make parse{Attribute,Type} null-terminate inputRahul Kayaith2023-03-031-0/+5
| | | | | | | | | | | | | | `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
* [mlir][AsmParser] Improve parse{Attribute,Type} error handlingRahul Kayaith2023-03-011-0/+41
| | | | | | | | | | | | | | 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
* [mlir] Require explicit casts when using TypedValueRahul Kayaith2023-02-011-1/+1
| | | | | | | | | | | | | | | | | | | | | Currently `TypedValue` can be constructed directly from `Value`, hiding errors that could be caught at compile time. For example the following will compile, but crash/assert at runtime: ``` void foo(TypedValue<IntegerType>); void bar(TypedValue<FloatType> v) { foo(v); } ``` This change removes the constructors and replaces them with explicit llvm casts. Depends on D142852 Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D142855
* [mlir] Adjust AttributeTest to show skip behavior.Adrian Kuegel2023-01-311-1/+3
| | | | | | | walk() skips identical sub-attributes. Adjust the unit test to show this. Differential Revision: https://reviews.llvm.org/D142956
* [mlir] Promote the SubElementInterfaces to a core Attribute/Type constructRiver Riddle2023-01-275-73/+29
| | | | | | | | | | | | | | | | This commit restructures the sub element infrastructure to be a core part of attributes and types, instead of being relegated to an interface. This establishes sub element walking/replacement as something "always there", which makes it easier to rely on for correctness/etc (which various bits of infrastructure want, such as Symbols). Attribute/Type now have `walk` and `replace` methods directly accessible, which provide power API for interacting with sub elements. As part of this, a new AttrTypeWalker class is introduced that supports caching walked attributes/types, and a friendlier API (see the simplification of symbol walking in SymbolTable.cpp). Differential Revision: https://reviews.llvm.org/D142272
* [mlir][Conversion] Rename the MemRefToLLVM passQuentin Colombet2023-01-271-1/+1
| | | | | | | | | | | | | | | | | | | | Since the recent MemRef refactoring that centralizes the lowering of complex MemRef operations outside of the conversion framework, the MemRefToLLVM pass doesn't directly convert these complex operations. Instead, to fully convert the whole MemRef dialect space, MemRefToLLVM needs to run after `expand-strided-metadata`. Make this more obvious by changing the name of the pass and the option associated with it from `convert-memref-to-llvm` to `finalize-memref-to-llvm`. The word "finalize" conveys that this pass needs to run after something else and that something else is documented in its tablegen description. This is a follow-up patch related to the conversation at: https://discourse.llvm.org/t/psa-you-need-to-run-expand-strided-metadata-before-memref-to-llvm-now/66956/14 Differential Revision: https://reviews.llvm.org/D142463
* [mlir][Pass] Make PassManager default to op-agnosticrkayaith2023-01-252-4/+7
| | | | | | | | | | | | | | | Currently `PassManager` defaults to being anchored on `builtin.module`. Switching the default makes `PassManager` consistent with `OpPassManager` and avoids the implicit dependency on `builtin.module`. Specifying the anchor op type isn't strictly necessary when using explicit nesting (existing pipelines will continue to work), but I've updated most call sites to specify the anchor since it allows for better error-checking during pipeline construction. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D137731
* [MLIR][Presburger] Support divisions in union of two PWMAFunctionGroverkss2023-01-191-0/+41
| | | | | | | | | | | | This patch adds support for divisions in the union of two PWMAFunction. This is now possible because of previous patches, which made divisions explicitly stored in MultiAffineFunction (MAF). This patch also refactors the previous implementation, moving the implementation for obtaining a set of points where a MAF is lexicographically "better" than the other to MAF. Reviewed By: arjunp Differential Revision: https://reviews.llvm.org/D138118
* [mlir] Move SymbolOpInterfaces "classof" check to a proper "extraClassOf" ↵River Riddle2023-01-181-6/+0
| | | | | | | | | | | | | interface field SymbolOpInterface overrides the base classof to provide support for optionally implementing the interface. This is currently placed in the extraClassDeclarations, but that is kind of awkard given that it requires underlying knowledge of how the base classof is implemented. This commit adds a proper "extraClassOf" field to allow interfaces to implement this, which abstracts away the default classof logic. Differential Revision: https://reviews.llvm.org/D140197
* Revert "Revert "Refactor OperationName to use virtual tables for dispatch ↵Mehdi Amini2023-01-161-0/+1
| | | | | | | | | | | | | | | | (NFC)"" This streamlines the implementation and makes it so that the virtual tables are in the binary instead of dynamically assembled during initialization. The dynamic allocation size of op registration is also smaller with this change. This reverts commit 7bf1e441da6b59a25495fde8e34939f93548cc6d and re-introduce e055aad5ffb348472c65dfcbede85f39efe8f906 after fixing the windows crash by making ParseAssemblyFn a unique_function again Differential Revision: https://reviews.llvm.org/D141492
* Revert "Refactor OperationName to use virtual tables for dispatch (NFC)"Mehdi Amini2023-01-161-1/+0
| | | | | | This reverts commit e055aad5ffb348472c65dfcbede85f39efe8f906. This crashes on Windows at the moment for some reasons.
* [mlir] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata2023-01-145-16/+16
| | | | | | | | | | 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
* [mlir] Add #include <optional> (NFC)Kazu Hirata2023-01-135-0/+5
| | | | | | | | | | | | | 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
* Refactor OperationName to use virtual tables for dispatch (NFC)Mehdi Amini2023-01-141-0/+1
| | | | | | | | This streamlines the implementation and makes it so that the virtual tables are in the binary instead of dynamically assembled during initialization. The dynamic allocation size of op registration is also smaller with this change. Differential Revision: https://reviews.llvm.org/D141492
* [mlir] Add operations to BlockAndValueMapping and rename it to IRMappingJeff Niu2023-01-122-6/+25
| | | | | | | | | | | | | | | | | | | | The patch adds operations to `BlockAndValueMapping` and renames it to `IRMapping`. When operations are cloned, old operations are mapped to the cloned operations. This allows mapping from an operation to a cloned operation. Example: ``` Operation *opWithRegion = ... Operation *opInsideRegion = &opWithRegion->front().front(); IRMapping map Operation *newOpWithRegion = opWithRegion->clone(map); Operation *newOpInsideRegion = map.lookupOrNull(opInsideRegion); ``` Migration instructions: All includes to `mlir/IR/BlockAndValueMapping.h` should be replaced with `mlir/IR/IRMapping.h`. All uses of `BlockAndValueMapping` need to be renamed to `IRMapping`. Reviewed By: rriddle, mehdi_amini Differential Revision: https://reviews.llvm.org/D139665
* [mlir][tblgen] Generate generic adaptors for OpsMarkus Böck2023-01-112-0/+64
| | | | | | | | | | | | | | | | | This is part of the RFC for a better fold API: https://discourse.llvm.org/t/rfc-a-better-fold-api-using-more-generic-adaptors/67374 This patch implements the generation of generic adaptors through TableGen. These are essentially a generalization of Adaptors, as implemented previously, but instead of indexing into a `mlir::ValueRange`, they may index into any container, regardless of the element type. This allows the use of the convenient getter methods of Adaptors to be reused on ranges that are the result of some kind of mapping functions of an ops operands. In the case of the fold API in the RFC, this would be `ArrayRef<Attribute>`, which is a mapping of the operands to their possibly-constant values. Implementation wise, some special care was taken to not cause a compile time regression, nor to break any kind of source compatibility. For that purpose, the current adaptor class was split into three: * A generic adaptor base class, within the detail namespace as it is an implementation detail, which implements all APIs independent of the range type used for the operands. This is all the attribute and region related code. Since it is not templated, its implementation does not have to be inline and can be put into the cpp source file * The actual generic adaptor, which has a template parameter for the range that should be indexed into for retrieving operands. It implements all the getters for operands, as they are dependent on the range type. It publicly inherits from the generic adaptor base class * A class named as adaptors have been named so far, inheriting from the generic adaptor class with `mlir::ValueRange` as range to index into. It implements the rest of the API, specific to `mlir::ValueRange` adaptors, which have previously been part of the adaptor. This boils down to a constructor from the Op type as well as the verify function. The last class having the exact same API surface and name as Adaptors did previously leads to full source compatibility. Differential Revision: https://reviews.llvm.org/D140660
* Move from llvm::makeArrayRef to ArrayRef deduction guides - last partserge-sans-paille2023-01-102-9/+9
| | | | | | | 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
* [mlir] Fix warningsKazu Hirata2022-12-221-2/+2
| | | | | | | | This patch fixes: third-party/unittest/googletest/include/gtest/gtest.h:1526:11: error: comparison of integers of different signs: 'const unsigned long' and 'const int' [-Werror,-Wsign-compare]
* [mlir] Allow specifying benefit for C func ptr style patterns.Chenguang Wang2022-12-221-0/+19
| | | | | | Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D139234
* mlir/DialectConversion: use std::optional (NFC)Ramkumar Ramachandra2022-12-191-11/+13
| | | | | | | | | | | | This is part of an effort to migrate from llvm::Optional to std::optional. This patch touches DialectConversion, and modifies existing conversions and tests appropriately. See also: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716 Signed-off-by: Ramkumar Ramachandra <r@artagnon.com> Differential Revision: https://reviews.llvm.org/D140303
* mlir/tblgen: use std::optional in generationRamkumar Ramachandra2022-12-172-6/+6
| | | | | | | | | | | | | | | | | This is part of an effort to migrate from llvm::Optional to std::optional. This patch changes the way mlir-tblgen generates .inc files, and modifies tests and documentation appropriately. It is a "no compromises" patch, and doesn't leave the user with an unpleasant mix of llvm::Optional and std::optional. A non-trivial change has been made to ControlFlowInterfaces to split one constructor into two, relating to a build failure on Windows. See also: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716 Signed-off-by: Ramkumar Ramachandra <r@artagnon.com> Differential Revision: https://reviews.llvm.org/D138934
* [mlir] Use llvm::transformOptional (NFC)Kazu Hirata2022-12-141-3/+3
| | | | | | | 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