llvm-project/mlir
Markus Böck 37da2a141c [mlir][LLVM] Rework the API of GEPOp
The implementation and API of GEP Op has gotten a bit convoluted over the time. Issues with it are:
* Misleading naming: `indices` actually only contains the dynamic indices, not all of them. To get the amount of indices you need to query the size of `structIndices`
* Very difficult to iterate over all indices properly: One had to iterate over `structIndices`, check whether it contains the magic constant `kDynamicIndex`, if it does, access the next value in `index` etc.
* Inconvenient to build: One either has create lots of constant ops for every index or have an odd split of passing both a `ValueRange` as well as a `ArrayRef<int32_t>` filled with `kDynamicIndex` at the correct places.
* Implementation doing verification in the build method
and more.

This patch attempts to address all these issues via convenience classes and reworking the way GEP Op works:
* Adds `GEPArg` class which is a sum type of a `int32_t` and `Value` and is used to have a single convenient easy to use `ArrayRef<GEPArg>` in the builders instead of the previous `ValueRange` + `ArrayRef<int32_t>` builders.
* Adds `GEPIndicesAdapter` which is a class used for easy random access and iteration over the indices of a GEP. It is generic and flexible enough to also instead return eg. a corresponding `Attribute` for an operand inside of `fold`.
*  Rename `structIndices` to `rawConstantIndices` and `indices` to `dynamicIndices`: `rawConstantIndices` signifies one shouldn't access it directly as it is encoded, and `dynamicIndices` is more accurate and also frees up the `indices` name.
* Add `getIndices` returning a `GEPIndicesAdapter` to easily iterate over the GEP Ops indices.
* Move the verification/asserts out of the build method and into the `verify` method emitting op error messages.
* Add convenient builder methods making use of `GEPArg`.
* Add canonicalizer turning dynamic indices with constant values into constant indices to have a canonical representation.

The only breaking change is for any users building GEPOps that have so far used the old `ValueRange` + `ArrayRef<int32_t>` builder as well as those using the generic syntax.

Another follow up patch then goes through upstream and makes use of the new `ArrayRef<GEPArg>` builder to remove a lot of code building constants for GEP indices.

Differential Revision: https://reviews.llvm.org/D130730
2022-07-29 18:22:54 +02:00
..
benchmark/python [NFC] Remove obsolete all_passes_registration from integration tests. 2022-07-16 18:18:43 -07:00
cmake/modules [CMake] Fix add_subdirectory llvm builds 2022-07-26 11:24:23 +02:00
docs [MLIR] Generic 'malloc', 'aligned_alloc' and 'free' functions 2022-07-25 15:52:51 +02:00
examples [mlir][toy] Replace Optional::getValue with value. NFC 2022-07-29 01:10:51 -07:00
include [mlir][LLVM] Rework the API of GEPOp 2022-07-29 18:22:54 +02:00
lib [mlir][LLVM] Rework the API of GEPOp 2022-07-29 18:22:54 +02:00
python Adding a new variant of DepthwiseConv2D 2022-07-21 14:36:57 -04:00
test [mlir][LLVM] Rework the API of GEPOp 2022-07-29 18:22:54 +02:00
tools [mlir] Refactor the Parser library in preparation for an MLIR binary format 2022-07-25 16:33:01 -07:00
unittests [mlir] Delete most of the ops from the quant dialect. 2022-07-27 17:50:42 -07:00
utils [mlir][spirv] Rename spv.ocl to spv.cl. NFC. 2022-07-20 17:46:45 -04:00
.clang-format [mlir] Add missing newline at end of .clang-format file 2022-06-14 23:59:00 -07:00
.clang-tidy Enable readability-redundant-smartptr-get in MLIR local clang-tidy config 2022-01-08 20:07:11 +00:00
CMakeLists.txt [cmake] Don't export `LLVM_TOOLS_INSTALL_DIR` anymore 2022-07-21 19:04:00 +00:00
LICENSE.TXT
README.md

README.md

Multi-Level Intermediate Representation

See https://mlir.llvm.org/ for more information.