Enable arithmetics for index types.
authorAlex Zinenko <zinenko@google.com>
Thu, 8 Nov 2018 12:04:32 +0000 (04:04 -0800)
committerjpienaar <jpienaar@google.com>
Fri, 29 Mar 2019 20:51:19 +0000 (13:51 -0700)
commitac2a655e87064dc236f5ee289c2be2e8ed9b49a0
tree2f0c66adcc4e36ae12c684973464f71ef4ce0a26
parentcc82a94aff47fdbaeef4e36b1db4d9f1ed69830c
Enable arithmetics for index types.

Arithmetic and comparison instructions are necessary to implement, e.g.,
control flow when lowering MLFunctions to CFGFunctions.  (While it is possible
to replace some of the arithmetics by affine_apply instructions for loop
bounds, it is still necessary for loop bounds checking, steps, if-conditions,
non-trivial memref subscripts, etc.)  Furthermore, working with indirect
accesses in, e.g., lookup tables for large embeddings, may require operating on
tensors of indexes.  For example, the equivalents to C code "LUT[Index[i]]" or
"ResultIndex[i] = i + j" where i, j are loop induction variables require the
arithmetics on indices as well as the possibility to operate on tensors
thereof.  Allow arithmetic and comparison operations to apply to index types by
declaring them integer-like.  Allow tensors whose element type is index for
indirection purposes.

The absence of vectors with "index" element type is explicitly tested, but the
only justification for this restriction in the CL introducing the test is
"because we don't need them".  Do NOT enable vectors of index types, although
it makes vector and tensor types inconsistent with respect to allowed element
types.

PiperOrigin-RevId: 220614055
mlir/g3doc/LangRef.md
mlir/include/mlir/IR/OpDefinition.h
mlir/include/mlir/IR/Types.h
mlir/lib/IR/MLIRContext.cpp
mlir/lib/IR/Operation.cpp
mlir/lib/Parser/Parser.cpp
mlir/lib/StandardOps/StandardOps.cpp
mlir/test/IR/core-ops.mlir
mlir/test/IR/invalid-ops.mlir