Commit Graph

6445 Commits

Author SHA1 Message Date
Jacques Pienaar 8c1f553844 Avoid using /dev/null in test
Windows build bot was not happy with this
(http://lab.llvm.org:8011/#/builders/13/builds/3327/steps/7/logs/FAIL__MLIR__run-reproducer_mlir)
2020-12-30 14:16:13 -08:00
Jacques Pienaar 453b6aadce [mlir] Add option to read reproducer options from file
Add command line option to read the configuration dumped by the MLIR crash
reproducer and adds those to the other command line options parsed by mlir-opt.

Simple convenience that enables `mlir-opt --run-reproducer /tmp/repro.mlir`
instead of needing to copy&paste the configuration.

Differential Revision: https://reviews.llvm.org/D93924
2020-12-30 10:46:01 -08:00
Nicolas Vasilache 9b5a3d67b4 [mlir] Fix indexing of first offset operand in ops that implement OffsetSizeAndStrideOpInterface
OffsetSizeAndStrideOpInterface ops may have a varying number of operands before the first
offset operand. This revision adds a method that such ops much implement to properly specify
the position of the first offset operand.

Differential Revision: https://reviews.llvm.org/D93947
2020-12-30 16:44:26 +00:00
Nicolas Vasilache ed507bc4d5 [mlir] NFC - Fix SubViewOp printing
Avoid casting the source operand type allows better debugging when conversion patterns
fail to produce a proper MemRefType.
2020-12-30 16:34:37 +00:00
Alexander Belyaev e47e313d64 [mlir] Fix a typo MemRefType -> UnrankedMemRefType 2020-12-30 14:35:25 +01:00
zhanghb97 abb4cd3e74 [mlir][Python] Initial Affine Map Python Bindings.
- Add `PyAffineMap` to wrap around `MlirAffineMap`.
- Add `mlirPythonAffineMapToCapsule` and `mlirPythonCapsuleToAffineMap` to interoperate with python capsule.
- Add and test some simple bindings of `PyAffineMap`.

Differential Revision: https://reviews.llvm.org/D93200
2020-12-30 17:36:39 +08:00
Stella Laurenzo 11f41cd445 [mlir][python] Install generated dialect sources.
Differential Revision: https://reviews.llvm.org/D93928
2020-12-29 20:15:07 -08:00
Stella Laurenzo 8a1f1a100c [mlir][python] Aggressively avoid name collisions in generated python ODS code.
* When porting npcomp to use these bindings, I ran into enough patterns of collisions that I decided to be somewhat draconian about not polluting the namespace.
* With these changes all of the npcomp dialects generate and pass what tests we have.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D93920
2020-12-29 17:43:04 -08:00
Mehdi Amini 58ce477676 Fix DRR pattern when attributes and operands are interleaved and a dag subtree appears in the rewrite
This fixes an incorrect fatal error in TableGen. This code probably comes
from before attributes were allowed to interleave with operands in ODS.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D93915
2020-12-30 00:19:38 +00:00
Chris Morin 2c8f5bd539 [MLIR] Make ComplexType buildable if its element type is buildable
If a ComplexType's element type is buildable, then that ComplexType should be
buildable. This is accomplished by the introduction of a new ODS class called
`SameBuildabilityAs`. This can be used by other types that are conditionally
buildable.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D93892
2020-12-29 23:31:42 +00:00
Jacques Pienaar 5fd2b3a124 [mlir] Add error message when failing to add pass
Ran into failure without any error message previously here.

Differential Revision: https://reviews.llvm.org/D93910
2020-12-29 14:20:19 -08:00
Siddharth Krishna 14056c88d6 [mlir][Python] Add an Operation.name property
Reviewed By: stellaraccident, mehdi_amini

Differential Revision: https://reviews.llvm.org/D93474
2020-12-29 14:14:32 -08:00
Stella Laurenzo f5665a2486 [mlir][python] Add Operation.verify().
Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D93913
2020-12-29 14:10:31 -08:00
Jacques Pienaar e03266994a [mlir] Skip empty op-pipelines in inliner textual opt parsing
Avoids failing on cases like

inline{default-pipeline=canonicalize max-iterations=4 op-pipelines=},

as produced by crash reproducer.
2020-12-29 13:59:53 -08:00
Stella Laurenzo df7ddeea66 [mlir][python] Add FlatSymbolRef attribute.
Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D93909
2020-12-29 12:24:28 -08:00
Thomas Raoux cf216670a0 [mlir][linalg] Add vectorization for linalg on tensor ops
Support vectorization of linalg ops using tensor inputs/outputs.

Differential Revision: https://reviews.llvm.org/D93890
2020-12-29 09:02:23 -08:00
Rahul Joshi 25007b4d7e [MLIR][NFC] Change FunctionLike::setAllArgAttrs/setAllResultAttrs to do a one-shot attribute update.
- Change FunctionLike::setAllArgAttrs() and setAllResultAttrs() to rebuild the new list of
  function attributes locally and call setAttr() just once instead of calling
  setArgAttr()/setResultAttrs() for each argument which incrementally build the
  attribute dictionary and can end up creating a lot of unused DictionaryAttr's (which are
  uniqued and nor garbage collected).

Differential Revision: https://reviews.llvm.org/D93870
2020-12-28 14:15:47 -08:00
Chris Lattner 87c032f7b4 [IR] Make Value::getType() work better with invalid IR.
The asmprinter would crash when dumping IR objects that had their
operands dropped.  With this change, we now get this output, which
makes op->dump() style debugging more useful.

%5 = "firrtl.eq"(<<NULL>>, <<NULL>>) : (<<NULL TYPE>>, <<NULL TYPE>>) -> !firrtl.uint<1>

Previously the asmprinter would crash getting the types of the null operands.

Differential Revision: https://reviews.llvm.org/D93869
2020-12-28 12:37:01 -08:00
Chris Lattner 9eb3e564d3 [ODS] Make the getType() method on a OneResult instruction return a specific type.
Implement Bug 46698, making ODS synthesize a getType() method that returns a
specific C++ class for OneResult methods where we know that class.  This eliminates
a common source of casts in things like:

   myOp.getType().cast<FIRRTLType>().getPassive()

because we know that myOp always returns a FIRRTLType.  This also encourages
op authors to type their results more tightly (which is also good for
verification).

I chose to implement this by splitting the OneResult trait into itself plus a
OneTypedResult trait, given that many things are using `hasTrait<OneResult>`
to conditionalize various logic.

While this changes makes many many ops get more specific getType() results, it
is generally drop-in compatible with the previous behavior because 'x.cast<T>()'
is allowed when x is already known to be a T.  The one exception to this is that
we need declarations of the types used by ops, which is why a couple headers
needed additional #includes.

I updated a few things in tree to remove the now-redundant `.cast<>`'s, but there
are probably many more than can be removed.

Differential Revision: https://reviews.llvm.org/D93790
2020-12-26 13:52:40 -08:00
Eugene Zhulenev 61422c8b66 [mlir] Async: add support for lowering async value operands to LLVM
Depends On D93592

Add support for `async.execute` async value unwrapping operands:

```
%token = async.execute(%async_value as %unwrapped : !async.value<!my.type>) {
  ...
  async.yield
}
```

Reviewed By: csigg

Differential Revision: https://reviews.llvm.org/D93598
2020-12-25 02:25:20 -08:00
Eugene Zhulenev 621ad468d9 [mlir] Async: lowering async.value to LLVM
1. Add new methods to Async runtime API to support yielding async values
2. Add lowering from `async.yield` with value payload to the new runtime API calls

`async.value` lowering requires that payload type is convertible to LLVM and supported by `llvm.mlir.cast` (DialectCast) operation.

Reviewed By: csigg

Differential Revision: https://reviews.llvm.org/D93592
2020-12-25 02:23:48 -08:00
Jacques Pienaar ca1ab0c66d [mlir] Add tensor passes to passes.md 2020-12-23 16:13:03 -08:00
Lei Zhang fc41777702 [mlir][spirv] De-template serialization
Previously for each op we generate a separate serialization
method for it. Those serialization methods duplicate the logic
of parsing operands/results/attributes and such.

This commit creates a generic method and let suitable op-specific
serialization method to call into it.

wc -l SPIRVSerialization.inc: before 8304; after: 5597 (So -2707)

Reviewed By: hanchung, ThomasRaoux

Differential Revision: https://reviews.llvm.org/D93535
2020-12-23 14:54:26 -05:00
Lei Zhang ae895ac4b9 [mlir][spirv] De-template deserialization
Previously for each op we generate a separate deserialization
method for it. Those deserialization methods duplicate the logic
of parsing operands/results/attributes and such.

This commit creates a generic method and let suitable op-specific
deserialization method to call into it.

wc -l SPIRVSerialization.inc: before 13290; after: 8304 (So -4986)

Reviewed By: hanchung, ThomasRaoux

Differential Revision: https://reviews.llvm.org/D93504
2020-12-23 14:45:46 -05:00
Lei Zhang 930c74f12d [mlir][spirv] NFC: rename SPIR-V conversion files for consistency
This commit renames various SPIR-V related conversion files for
consistency. It drops the "Convert" prefix to various files and
fixes various comment headers.

Reviewed By: hanchung, ThomasRaoux

Differential Revision: https://reviews.llvm.org/D93489
2020-12-23 14:36:46 -05:00
Lei Zhang a16fbff17d [mlir][spirv] Create a pass for testing SCFToSPIRV patterns
Previously all SCF to SPIR-V conversion patterns were tested as
the -convert-gpu-to-spirv pass. That obscured the structure we
want. This commit fixed it.

Reviewed By: ThomasRaoux, hanchung

Differential Revision: https://reviews.llvm.org/D93488
2020-12-23 14:31:55 -05:00
Thomas Raoux 74186880ba [mlir][vector] Add more vector Ops canonicalization
Add canonicalization for BroadcastOp, ExtractStrideSlicesOp and ShapeCastOp

Differential Revision: https://reviews.llvm.org/D93120
2020-12-23 11:25:01 -08:00
Lei Zhang 42980a789d [mlir][spirv] Convert functions returning one value
Reviewed By: hanchung, ThomasRaoux

Differential Revision: https://reviews.llvm.org/D93468
2020-12-23 13:27:31 -05:00
ergawy 1d0dc9be6d [MLIR][SPIRV] Add rewrite pattern to convert select+cmp into GLSL clamp.
Adds rewrite patterns to convert select+cmp instructions into clamp
instructions whenever possible. Support is added to convert:

- FOrdLessThan, FOrdLessThanEqual to GLSLFClampOp.
- SLessThan, SLessThanEqual to GLSLSClampOp.
- ULessThan, ULessThanEqual to GLSLUClampOp.

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D93618
2020-12-23 15:47:19 +01:00
Alex Zinenko 7ed9cfc7b1 [mlir] Remove static constructors from LLVMType
LLVMType contains numerous static constructors that were initially introduced
for API compatibility with LLVM. Most of these merely forward to arguments to
`SpecificType::get` (MLIR defines classes for all types, unlike LLVM IR), while
some introduce subtle semantics differences due to different modeling of MLIR
types (e.g., structs are not auto-renamed in case of conflicts). Furthermore,
these constructors don't match MLIR idioms and actively prevent us from making
the LLVM dialect type system more open. Remove them and use `SpecificType::get`
instead.

Depends On D93680

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D93681
2020-12-23 13:12:47 +01:00
Christian Sigg 19a0d0a40c [mlir] Rename ConvertToLLVMPattern::isSupportedMemRefType() to isConvertibleAndHasIdentityMaps().
Reviewed By: ftynse, herhut

Differential Revision: https://reviews.llvm.org/D93752
2020-12-23 12:23:29 +01:00
Alex Zinenko 32a884c9c5 [mlir] Add translation of omp.wsloop to LLVM IR
Introduce a translation of OpenMP workshare loop construct to LLVM IR. This is
a minimalist version to enable the pipeline and currently only supports static
loop schedule (default in the specification) on non-collapsed loops. Other
features will be added on per-need basis.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D92055
2020-12-23 11:52:28 +01:00
Christian Sigg 8451d4872e [mlir] NFC: Remove ConvertToLLVMPattern::getDataPtr(). All call sites use getStridedElementPtr() now.
Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D93751
2020-12-23 11:35:01 +01:00
Alex Zinenko 65ba0cd395 [mlir] Modernize std-to-llvm operation conversion doc
This was long overdue. Replace the outdated type syntax with the new syntax,
and update the description of how memref load/stores are handled to reflect the
latest changes in the implementation.

Reviewed By: herhut

Differential Revision: https://reviews.llvm.org/D93555
2020-12-23 11:19:58 +01:00
Chris Lattner 75a3f326c3 [IR] Add an ImplicitLocOpBuilder helper class for building IR with the same loc.
One common situation is to create a lot of IR at a well known location,
e.g. when doing a big rewrite from one dialect to another where you're expanding
ops out into lots of other ops.

For these sorts of situations, it is annoying to pass the location into
every create call.  As we discused in a few threads on the forum, a way to help
with this is to produce a new sort of builder that holds a location and provides
it to each of the create<> calls automatically.

This patch implements an ImplicitLocOpBuilder class that does this.  We've had
good experience with this in the CIRCT project, and it makes sense to upstream to
MLIR.

I picked a random pass to adopt it to show the impact, but I don't think there is
any particular need to force adopt it in the codebase.

Differential Revision: https://reviews.llvm.org/D93717
2020-12-22 14:47:33 -08:00
Alex Zinenko 8de43b926f [mlir] Remove instance methods from LLVMType
LLVMType contains multiple instance methods that were introduced initially for
compatibility with LLVM API. These methods boil down to `cast` followed by
type-specific call. Arguably, they are mostly used in an LLVM cast-follows-isa
anti-pattern. This doesn't connect nicely to the rest of the MLIR
infrastructure and actively prevents it from making the LLVM dialect type
system more open, e.g., reusing built-in types when appropriate. Remove such
instance methods and replaces their uses with apporpriate casts and methods on
derived classes. In some cases, the result may look slightly more verbose, but
most cases should actually use a stricter subtype of LLVMType anyway and avoid
the isa/cast.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D93680
2020-12-22 23:34:54 +01:00
Christian Sigg df6cbd37f5 [mlir] Lower gpu.memcpy to GPU runtime calls.
Reviewed By: herhut

Differential Revision: https://reviews.llvm.org/D93204
2020-12-22 22:49:19 +01:00
Christian Sigg 0955d8df06 [mlir] Add gpu.memcpy op.
Reviewed By: herhut

Differential Revision: https://reviews.llvm.org/D93197
2020-12-22 17:39:55 +01:00
Prateek Gupta 3e07b0b9d3 [MLIR] Fix lowering of affine operations with return values
This commit addresses the issue of lowering affine.for and
affine.parallel having return values. Relevant test cases are also
added.

Signed-off-by: Prateek Gupta <prateek@polymagelabs.com>

Differential Revision: https://reviews.llvm.org/D93090
2020-12-22 21:44:31 +05:30
Alex Zinenko 2f5569f6f6 [mlir] remove deprecated string-based OpBuilder from ODS
It has been deprecated with a warning for two months, removing.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D93623
2020-12-22 09:57:49 +01:00
Tres Popp 6e2af4d604 Revert "[mlir] Add SmallVector sizes"
This reverts commit 83274a0773.

Fixed in a555ca8b3d
2020-12-22 02:33:14 +01:00
Tres Popp 83274a0773 [mlir] Add SmallVector sizes
This is a temporary fix until figuring out how to correct the forward
declare in mlir/include/mlir/Support/LLVM.h

Differential Revision: https://reviews.llvm.org/D93666
2020-12-22 00:48:41 +01:00
George Mitenkov be96137461 [MLIR][SPIRVToLLVM] Updated documentation on spirv-cpu-runner
This patch adds documentation for the `mlir-spirv-cpu-runner`.
It provides an overview of applied transformations and passes, as
well as an example walk-through.

Some typos in the documentation have been fixed as well.

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D93620
2020-12-22 01:47:43 +03:00
Aart Bik 9a8cab8bac [mlir][sparse] adjust output tensor to synthetic tensor
Fixes a merge conflict with previous two CLs.

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D93664
2020-12-21 14:13:54 -08:00
Thomas Raoux 7c7b55b985 [mlir][vector] Extend vector unroll to all element-wise ops
Extend unroll to support all element-wise ops and allow unrolling for ops with
vector operands of with the same shape as the destination but different element
type (like Cmp or Select).

Differential Revision: https://reviews.llvm.org/D93121
2020-12-21 13:31:22 -08:00
ergawy 9d2529a38b [MLIR][Docs] Fix a small typo in documentation.
Just fixes a tiny typo in a link between 2 pages.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D93616
2020-12-21 22:30:22 +01:00
nicolasvasilache b7ae1d3d2b [mlir][Linalg] Revisit the Linalg on tensors abstraction
This revision drops init_tensor arguments from Linalg on tensors and instead uniformizes the output buffers and output tensors to be consistent.
This significantly simplifies the usage of Linalg on tensors and is a stepping stone for
its evolution towards a mixed tensor and shape abstraction discussed in https://llvm.discourse.group/t/linalg-and-shapes/2421/19.

Differential Revision: https://reviews.llvm.org/D93469
2020-12-21 12:29:10 -08:00
Thomas Raoux 26c8f9081b [mlir[[vector] Extend Transfer read/write ops to support tensor types.
Transfer_ops can now work on both buffers and tensor. Right now, lowering of
the tensor case is not supported yet.

Differential Revision: https://reviews.llvm.org/D93500
2020-12-21 08:55:04 -08:00
George Mitenkov f6c7ebe76a [MLIR][SPIRVToLLVM] Updated documentation on entry points and not supported ops
This patch addresses two issues:
1. Not supported ops are updated to pick up the changes in the
SPIR-V dialect.

2. Conversion on `spv.ExecutionMode` is updated.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D91881
2020-12-21 11:20:40 +03:00
Gnimuc c1d6de41a9 [mlir][CAPI] Add the missing <stdbool.h> in Support.h
This was likely an oversight in https://reviews.llvm.org/D92292

Reviewed By: stellaraccident

Differential Revision: https://reviews.llvm.org/D93588
2020-12-20 05:01:49 +00:00
Nicolas Vasilache b88ed4ec8e [mlir][Linlag] Reflow Linalg.md - NFC
Markdown formatting seems to now be available, reflowing the doc without changing any content.
2020-12-18 16:15:58 +00:00
River Riddle fc5cf50e89 [mlir] Remove the MutableDictionaryAttr class
This class used to serve a few useful purposes:
* Allowed containing a null DictionaryAttr
* Provided some simple mutable API around a DictionaryAttr

The first of which is no longer an issue now that there is much better caching support for attributes in general, and a cache in the context for empty dictionaries. The second results in more trouble than it's worth because it mutates the internal dictionary on every action, leading to a potentially large number of dictionary copies. NamedAttrList is a much better alternative for the second use case, and should be modified as needed to better fit it's usage as a DictionaryAttrBuilder.

Differential Revision: https://reviews.llvm.org/D93442
2020-12-17 17:18:42 -08:00
Aart Bik 14da25b4b2 [mlir][sparse] scalarize reductions in for-loops during sparse codegen
Reductions in innermost loops become harder for the backend to disambiguate
after bufferization into memrefs, resulting in less efficient load-update-store
cycles. By scalarizing innermost reductions, the backend is more likely to assign
a register to perform the reduction (also prepares vectorization). Even though
we could scalarize reductions for more outer loops and while-loops as well,
currently scalarization is only done for chains of innermost for-loops, where
it matters most, to avoid complicating codegen unnecessary (viz. adding lots
of yield instructions).

This CL also refactors condition simplification into the merger class,
where it belongs, so that conditions are simplified only once per loop
nest and not repeatedly as was currently done. This CL also fixes a few
minor bugs, some layout issues, and comments.

Reviewed By: penpornk

Differential Revision: https://reviews.llvm.org/D93143
2020-12-17 16:12:21 -08:00
Mehdi Amini 9887097d80 Remove unneeded header include (NFC) 2020-12-18 00:10:26 +00:00
Sean Silva 129d6e554e [mlir] Move `std.tensor_cast` -> `tensor.cast`.
This is almost entirely mechanical.

Differential Revision: https://reviews.llvm.org/D93357
2020-12-17 16:06:56 -08:00
Mehdi Amini a555ca8b3d Workaround around clang 5.0 bug by including SmallVector.h in LLVM.h (PR41549)
The forward declaration for SmallVector does not play well with clang-5.

Differential Revision: https://reviews.llvm.org/D93498
2020-12-18 00:00:36 +00:00
MaheshRavishankar 118a715654 [mlir][Linalg] Define a linalg.init_tensor operation.
This operation is used to materialize a tensor of a particular
shape. The shape could be specified as a mix of static and dynamic
values.

The use of this operation is to be an `init` tensor for Linalg
structured operation on tensors where the bounds of the computation
depends on the shape of the output of the linalg operation. The result
of this operation will be used as the `init` tensor of such Linalg
operations. To note,

1) The values in the tensor materialized is not used. Any operation to
   which this is an init tensor is expected to overwrite the entire
   tensor.
2) The tensor is materialized only for the shape of the output and to
   make the loop bounds depend only on operands of the structured
   operation.

Based on (1) and (2) it is assumed that these operations eventually go
away since they are only used in `dim` operations that can be
canonicalized to make this operation dead. Such canonicalization are
added here too.

Differential Revision: https://reviews.llvm.org/D93374
2020-12-17 14:45:51 -08:00
MaheshRavishankar de031216bf [mlir] Add canonicalization from `tensor_cast` to `dim` op.
Fold a `tensor_cast` -> `dim` to take the `dim` of the original tensor.

Differential Revision: https://reviews.llvm.org/D93492
2020-12-17 14:45:51 -08:00
River Riddle 1b97cdf885 [mlir][IR][NFC] Move context/location parameters of builtin Type::get methods to the start of the parameter list
This better matches the rest of the infrastructure, is much simpler, and makes it easier to move these types to being declaratively specified.

Differential Revision: https://reviews.llvm.org/D93432
2020-12-17 13:01:36 -08:00
Alex Zinenko 0efb0dd978 [mlir] Partially update the conversion-to-llvm document
This document was not updated after the LLVM dialect type system had been
reimplemented and was using an outdated syntax. Rewrite the part of the
document that concerns type conversion and prepare the ground for splitting it
into a document that explains how built-in types are converted and a separate
document that explains how standard types and functions are converted, which
will better correspond to the fact that built-in types do not belong to the
standard dialect.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D93486
2020-12-17 22:00:09 +01:00
Javier Setoain 106e66f3f5 [mlir][ArmSVE] Add documentation generation
Adds missing cmake command to generate documentation for ArmSVE
Dialect.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D93465
2020-12-17 12:22:48 -08:00
Christian Sigg 58f2b765eb Fix NDEBUG build after https://reviews.llvm.org/D93005.
Differential Revision: https://reviews.llvm.org/D93480
2020-12-17 20:38:21 +01:00
Brian Gesiak 14f24155a5 [mlir][LLVMIR] Add 'llvm.switch' op
The LLVM IR 'switch' instruction allows control flow to be transferred
to one of any number of branches depending on an integer control value,
or a default value if the control does not match any branch values. This patch
adds `llvm.switch` to the MLIR LLVMIR dialect, as well as translation routines
for lowering it to LLVM IR.

To store a variable number of operands for a variable number of branch
destinations, the new op makes use of the `AttrSizedOperandSegments`
trait. It stores its default branch operands as one segment, and all
remaining case branches' operands as another. It also stores pairs of
begin and end offset values to delineate the sub-range of each case branch's
operands. There's probably a better way to implement this, since the
offset computation complicates several parts of the op definition. This is the
approach I settled on because in doing so I was able to delegate to the default
op builder member functions. However, it may be preferable to instead specify
`skipDefaultBuilders` in the op's ODS, or use a completely separate
approach; feedback is welcome!

Another contentious part of this patch may be the custom printer and
parser functions for the op. Ideally I would have liked the MLIR to be
printed in this way:

```
llvm.switch %0, ^bb1(%1 : !llvm.i32) [
  1: ^bb2,
  2: ^bb3(%2, %3 : !llvm.i32, !llvm.i32)
]
```

The above would resemble how LLVM IR is formatted for the 'switch'
instruction. But I found it difficult to print and parse something like
this, whether I used the declarative assembly format or custom functions.
I also was not sure a multi-line format would be welcome -- it seems
like most MLIR ops do not use newlines. Again, I'd be happy to hear any
feedback here as well, or on any other aspect of the patch.

Differential Revision: https://reviews.llvm.org/D93005
2020-12-17 14:11:21 -05:00
Richard Uhler a48172cf1c Add brief description of dialects doc section.
Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D93466
2020-12-17 18:37:34 +00:00
George 4a327bd252 Add call site location getter to C API
Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D93334
2020-12-17 09:55:21 -08:00
Lei Zhang 0117865412 [mlir][spirv] NFC: Shuffle code around to better follow convention
This commit shuffles SPIR-V code around to better follow MLIR
convention. Specifically,

* Created IR/, Transforms/, Linking/, and Utils/ subdirectories and
  moved suitable code inside.
* Created SPIRVEnums.{h|cpp} for SPIR-V C/C++ enums generated from
  SPIR-V spec. Previously they are cluttered inside SPIRVTypes.{h|cpp}.
* Fixed include guards in various header files (both .h and .td).
* Moved serialization tests under test/Target/SPIRV.
* Renamed TableGen backend -gen-spirv-op-utils into -gen-spirv-attr-utils
  as it is only generating utility functions for attributes.

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D93407
2020-12-17 11:03:26 -05:00
Alex Zinenko eb4917d121 [mlir] Fix syntax error in markdown documentation 2020-12-17 14:09:31 +01:00
Alex Zinenko ccdd8c7759 [mlir] Move LLVM Dialect Op documentation to ODS
This was long overdue. The initial documentation for the LLVM dialect was
introduced before ODS had support for long descriptions. This is now possible,
so the documentation is moved to ODS, which can serve as a single source of
truth. The high-level description of the dialect structure is updated to
reflect that.

Depends On: D93315

Reviewed By: rriddle, mehdi_amini

Differential Revision: https://reviews.llvm.org/D93425
2020-12-17 12:32:35 +01:00
Alex Zinenko c2751250f3 [mlir] partially update LLVM dialect documentation
Rewrite the parts of the documentation that became stale: context/module
handling and type system. Expand the type system description.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D93315
2020-12-17 12:32:34 +01:00
Alex Zinenko 96076a2edb [mlir] Support index and memref types in llvm.mlir.cast
This operation is designed to support partial conversion, more specifically the
IR state in which some operations expect or produce built-in types and some
operations produce and expect LLVM dialect types. It is reasonable for it to
support cast between built-in types and any equivalent that could be produced
by the type conversion. (At the same time, we don't want the dialect to depend
on the type conversion as it could lead to a dependency cycle). Introduce
support for casting from index to any integer type and back, and from memref to
bare pointer or memref descriptor type and back.

Contrary to what the TODO in the code stated, there are no particular
precautions necessary to handle the bare pointer conversion for memerfs. This
conversion applies exclusively to statically-shaped memrefs, so we can always
recover the full descriptor contents from the type.

This patch simultaneously tightens the verification for other types to only
accept matching pairs of types, e.g., i64 and !llvm.i64, as opposed to the
previous implementation that only checked if the types were generally allowed
byt not for matching, e.g. i64 could be "casted" to !llvm.bfloat, which is not
the intended semantics.

Move the relevant test under test/Dialect/LLVMIR because it is not specific to
the conversion pass, but rather exercises an op in the dialect. If we decide
this op does not belong to the LLVM dialect, both the dialect and the op should
move together.

Reviewed By: silvas, ezhulenev

Differential Revision: https://reviews.llvm.org/D93405
2020-12-17 09:21:42 +01:00
River Riddle fce9dd6b25 [mlir][NFC] Remove StandardTypes.h now that all usages point to BuiltinTypes.h
Differential Revision: https://reviews.llvm.org/D93430
2020-12-16 20:41:42 -08:00
Tres Popp b17a181563 [mlir] Modify linalg loops test to have nested regions
Differential Revision: https://reviews.llvm.org/D93418
2020-12-17 01:19:46 +01:00
Alexander Belyaev 9ca67d7f44 Revert "[mlir] Lookup the latest value with a legal type when remapping values."
This reverts commit f8184d4c44.
2020-12-16 23:09:04 +01:00
Mehdi Amini c21ee1a942 Improve the verifier diagnostic on dominance error
Address PR47937

Differential Revision: https://reviews.llvm.org/D93361
2020-12-16 22:05:17 +00:00
Eugene Zhulenev 900d71a851 [mlir] Async: re-enable tests after fixing fkakines
Test flakiness was fixed by: 9edcedf7f2

Runs these tests to verify that all parts of the lowering work correctly.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D93384
2020-12-16 11:07:03 -08:00
Eugene Zhulenev 11f1027b4d [mlir] AsyncRuntime: mode runtime declarations to mlir::runtime namespace
Define Async runtime related typedefs in the `mlir::runtime` namespace.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D93391
2020-12-16 11:05:21 -08:00
Christian Sigg a79b26db0e [mlir] Fix for gpu-async-region pass.
- the !gpu.async.token is the second result of 'gpu.alloc async', not the first.
- async.execute construction takes operand types not yet wrapped in !async.value.
- fix typo

Reviewed By: herhut

Differential Revision: https://reviews.llvm.org/D93156
2020-12-16 19:08:10 +01:00
Mehdi Amini 4bd9e62422 Remove spurious MLIRLLVMConversionsIncGen dependency from LLVM Dialect (NFC)
Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D93335
2020-12-16 17:32:49 +00:00
ergawy 6551c9ac36 [mlir][spirv] Add parsing and printing support for SpecConstantOperation
Adds more support for `SpecConstantOperation` by defining a custom
syntax for the op and implementing its parsing and printing.

Reviewed By: mravishankar, antiagainst

Differential Revision: https://reviews.llvm.org/D92919
2020-12-16 08:26:48 -05:00
Alexander Belyaev f8184d4c44 [mlir] Lookup the latest value with a legal type when remapping values.
The current condition implies that the target materialization will be
called even if the type is the new operand type is legal, but slightly
different. For example, if there is a bufferization pattern that changes
memref layout, then target materialization for an illegal type
(TensorType) would be called.

Differential Revision: https://reviews.llvm.org/D93126
2020-12-16 09:53:19 +01:00
Tres Popp f43e67cc6c [mlir] Allow SymbolTable to update existing symbols
Previous behavior would fail if inserting an operation that already
existed. Now SymbolTable::insert can also be used as a way to make a
symbol's name unique even after insertion.

Further TODOs have been left over naming and consistent behavior
considerations.

Differential Revision: https://reviews.llvm.org/D93349
2020-12-16 00:44:40 +01:00
River Riddle e9cda7c5a0 [mlir][Pass] Add a new PassNameCLParser specifically for parsing lists of pass names
This parser does not include the general `pass_pipeline` option, the pass pipeline entries, or the options of pass entries. This is useful for cases such as `print-ir-after` that just want the user to select specific pass types. This revision greatly reduces the amount of text in --help for several MLIR based tools.

Fixes PR#45495

Differential Revision: https://reviews.llvm.org/D92987
2020-12-15 14:56:09 -08:00
Alex Zinenko 02220f3204 [mlir] NFC: retire LLVM_Zero/OneResultOp from LLVM dialect ODS
These classes were initially introduced to factor out two common parts of LLVM
op definitions: the fact that they have no results or a single result of
LLVM_Type, and the default builders. Neither of the two parts is really
common anymore: many ops have more specific on the result type, and many ops
provide custom builders. The TableGen classes only add conceptual complexity
and make LLVM dialect definition dissimilar to other dialects. Remove them in
favor of explicitly specified builders (results are already specified).

Depends On D93329

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D93330
2020-12-15 23:50:03 +01:00
Alex Zinenko 20d0cbd3fa [mlir] Tighten type verifiers for LLVM dialect ops results
Now that we have predicates for LLVM dialect types in ODS, we can use them to
restrict the types allowed in results of LLVM dialect operations. This also
serves as additional documentation for these operations.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D93329
2020-12-15 23:50:02 +01:00
River Riddle 95019de8a1 [mlir][IR] Define the singleton builtin types in ODS instead of C++
This exposes several issues with the current generation that this revision also fixes.
 * TypeDef now allows specifying the base class to use when generating.
 * TypeDef now inherits from DialectType, which allows for using it as a TypeConstraint
 * Parser/Printers are now no longer generated in the header(removing duplicate symbols), and are now only generated when necessary.
    - Now that generatedTypeParser/Printer are only generated in the definition file,
      existing users will need to manually expose this functionality when necessary.
 * ::get() is no longer generated for singleton types, because it isn't necessary.

Differential Revision: https://reviews.llvm.org/D93270
2020-12-15 13:42:19 -08:00
Sean Silva caf4f2e372 [mlir] Handle unknown ops in dynamic_tensor_from_elements bufferization
Due to how the conversion infra works, the "clone" call that this
pattern was using required all the cloned ops to be immediately
legalized as part of this dialect conversion invocation.

That was previously working due to a couple factors:

- In the test case, there was scf.if, which we happen to mark as legal
  as part of marking the entire SCF dialect as legal for the scf.parallel
  we generate here.

- Originally, this test case had std.extract_element in the body, which
  we happened to have a pattern for in this pass. After I migrated that to
  `tensor.extract` (which removed the tensor.extract bufferization from
  here), I hacked this up to use `std.dim` which we still have patterns
  for in this pass.

This patch updates the test case to use a truly opaque op `test.source`
that properly stresses this aspect of the pattern.

(this also removes a stray dependency on the `tensor` dialect that I
must have left behind as part of my hacking this pass up when migrating
to `tensor.extract`)

Differential Revision: https://reviews.llvm.org/D93262
2020-12-15 12:50:56 -08:00
Tres Popp 922d3d5522 [mlir] Allow nested regions in inlineRegionAndEmitStore
This is useful for scalar code that uses for/while loops.
This has also been confirmed to work for representing std.pow as an
scf.for loop on gpus.

Differential Revision: https://reviews.llvm.org/D93308
2020-12-15 21:02:57 +01:00
Tres Popp c77ea40528 [mlir] Add std.pow lowering to LLVMIR
Differential Revision: https://reviews.llvm.org/D93311
2020-12-15 18:54:29 +01:00
Tres Popp 9adc64539f [mlir] Add std.powf to ROCDL lowering.
Differential Revision: https://reviews.llvm.org/D93313
2020-12-15 18:47:49 +01:00
Tres Popp f3e8f27ca1 [mlir] Fix GPUToNVVM test 2020-12-15 18:41:16 +01:00
Tres Popp e04785b131 [mlir] Add NVVM lowering for std.pow
Differential Revision: https://reviews.llvm.org/D93303
2020-12-15 18:28:23 +01:00
Tres Popp 73c580405f [mlir] Add std op for X raised to the power of Y
Proposal:
https://llvm.discourse.group/t/rfc-standard-add-powop-to-std-dialect/2377

Differential Revision: https://reviews.llvm.org/D93119
2020-12-15 17:06:26 +01:00
River Riddle d7eba20052 [mlir][Inliner] Refactor the inliner to use nested pass pipelines instead of just canonicalization
Now that passes have support for running nested pipelines, the inliner can now allow for users to provide proper nested pipelines to use for optimization during inlining. This revision also changes the behavior of optimization during inlining to optimize before attempting to inline, which should lead to a more accurate cost model and prevents the need for users to schedule additional duplicate cleanup passes before/after the inliner that would already be run during inlining.

Differential Revision: https://reviews.llvm.org/D91211
2020-12-14 18:09:47 -08:00
Eugene Zhulenev 0b510e79ce [mlir] Fix opaque struct typedef in AsyncRuntime header
Differential Revision: https://reviews.llvm.org/D93250
2020-12-14 15:04:59 -08:00
Richard Uhler ee43dcaad7 [mlir] Add section page for Rationale docs.
With a brief overview and summary of each of the Rationale docs.

Differential Revision: https://reviews.llvm.org/D93245
2020-12-14 14:49:30 -08:00
River Riddle b3ee7f1f31 [mlir][OpDefGen] Add support for generating local functions for shared utilities
This revision adds a new `StaticVerifierFunctionEmitter` class that emits local static functions in the .cpp file for shared operation verification. This class deduplicates shared operation verification code by emitting static functions alongside the op definitions. These methods are local to the definition file, and are invoked within the operation verify methods. The first bit of shared verification is for the type constraints used when verifying operands and results. An example is shown below:

```
static LogicalResult localVerify(...) {
  ...
}

LogicalResult OpA::verify(...) {
  if (failed(localVerify(...)))
    return failure();
  ...
}

LogicalResult OpB::verify(...) {
  if (failed(localVerify(...)))
    return failure();
  ...
}
```

This allowed for saving >400kb of code size from a downstream TensorFlow project (~15% of MLIR code size).

Differential Revision: https://reviews.llvm.org/D91381
2020-12-14 14:21:30 -08:00
Christian Sigg 0cf7e4b252 Revert "[mlir] Remove methods from mlir::OpState that just forward to mlir::Operation."
This reverts commit 6f271e921b.

Differential Revision: https://reviews.llvm.org/D93242
2020-12-14 22:47:17 +01:00
Javier Setoain aece4e2793 [mlir][ArmSVE][RFC] Add an ArmSVE dialect
This revision starts an Arm-specific ArmSVE dialect discussed in the discourse RFC thread:

https://llvm.discourse.group/t/rfc-vector-dialects-neon-and-sve/2284

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D92172
2020-12-14 21:35:01 +00:00
River Riddle 6af2c4ca9b [mlir] Change the internal representation of FrozenRewritePatternList to use shared_ptr
This will allow for caching pattern lists across multiple pass instances, such as when multithreading. This is an extremely important invariant for PDL patterns, which are compiled at runtime when the FrozenRewritePatternList is built.

Differential Revision: https://reviews.llvm.org/D93146
2020-12-14 12:32:44 -08:00
Christian Sigg 6f271e921b [mlir] Remove methods from mlir::OpState that just forward to mlir::Operation.
All call sites have been converted in previous changes.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D93176
2020-12-14 21:26:14 +01:00
River Riddle 6bc9439f59 [mlir][OpAsmParser] Add support for parsing integer literals without going through IntegerAttr
Some operations use integer literals as part of their custom format that don't necessarily map to an internal IntegerAttr. This revision exposes the same `parseInteger` functions as the DialectAsmParser to allow for these operations to parse integer literals without incurring the otherwise unnecessary roundtrip through IntegerAttr.

Differential Revision: https://reviews.llvm.org/D93152
2020-12-14 12:00:43 -08:00
River Riddle c234b65cef [mlir][OpFormat] Add support for emitting newlines from the custom format of an operation
This revision adds a new `printNewline` hook to OpAsmPrinter that allows for printing a newline within the custom format of an operation, that is then indented to the start of the operation. Support for the declarative assembly format is also added, in the form of a `\n` literal.

Differential Revision: https://reviews.llvm.org/D93151
2020-12-14 12:00:43 -08:00
Christian Sigg a1eb154421 [flang] Use mlir::OpState::operator->() to get to methods of mlir::Operation.
This is a preparation step to remove those methods from OpState.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D93194
2020-12-14 20:04:53 +01:00
Thomas Raoux 8955e9f6b7 [mlir][linalg] Fix bug in elementwise vectorization
Fix a bug causing to pick the wrong vector size to broadcast to when the source
vectors have different ranks.

Differential Revision: https://reviews.llvm.org/D93118
2020-12-14 10:44:36 -08:00
ergawy ecab63894b [MLIR][SPIRV] Refactoring serialization and deserialization
This commit splits SPIR-V's serialization and deserialization code
into separate libraries. The motiviation being that the serializer
is used more often the deserializer and therefore lumping them
together unnecessarily increases binary size for the most common
case.

This commit also moves these libraries into the Target/ directory
to follow MLIR convention.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D91548
2020-12-14 12:28:16 -05:00
Frederik Gossen 75d9a46090 [MLIR] Add atan and atan2 lowerings to CUDA intrinsics
Differential Revision: https://reviews.llvm.org/D93124
2020-12-14 10:45:28 +01:00
Frederik Gossen 1c6bc2c0b5 [MLIR] Add lowerings for atan and atan2 to ROCDL intrinsics
Differential Revision: https://reviews.llvm.org/D93123
2020-12-14 10:43:19 +01:00
Jacques Pienaar 9c3fa3d84d Don't emit on op diagnostic in reproducer emission
This avoids dumping the module post emitting a reproducer, which results in
many MB logs where a reproducer has already been neatly generated.

Differential Revision: https://reviews.llvm.org/D93165
2020-12-13 07:21:32 -08:00
ergawy 076f87a867 [MLIR][SPIRV] Add support for GLSL F/U/SClamp.
Adds support for 3 ternary ops from SPIR-V extended instructions for
GLSL. Namely, adds support for FClamp, UClamp, and SClamp.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D92859
2020-12-13 09:56:46 -05:00
Christian Sigg 1ffc1aaa09 [mlir] Use mlir::OpState::operator->() to get to methods of mlir::Operation.
This is a preparation step to remove those methods from OpState.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D93098
2020-12-13 09:58:16 +01:00
Chris Lattner a44e630353 [AsmParser] Fix support for zero bit integer types.
Zero bit integer types are supported by IntegerType for consistency,
but the asmparser never got updated. Allow them to be parsed, as
required to fix CIRCT issue #316

Differential Revision: https://reviews.llvm.org/D93089
2020-12-12 21:24:18 -08:00
kweisamx c84b53ca9b [mlir] Add Python binding for MLIR Dict Attribute
Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D93004
2020-12-13 04:30:35 +00:00
Brian Gesiak 09b0e0884a [mlir] Print bad size in AttrSizedOperandSegments
When printing verification errors for ops with the incorrect number of
operand segments, print the required number as well as the actual
number. Split off from D93005.

Differential Revision: https://reviews.llvm.org/D93145
2020-12-12 13:12:31 -05:00
River Riddle e9987ad878 [mlir][docs] Tidy up the pass infrastructure documentation
The doc has grown stale and is missing some recent changes to the infrastructure.

Differential Revision: https://reviews.llvm.org/D93081
2020-12-11 17:53:33 -08:00
Mehdi Amini aadcb26ee1 Store a MlirIdentifier instead of a MlirStringRef in MlirNameAttribute
This mirror the C++ API for NamedAttribute, and has the advantage or
internalizing earlier in the Context and not requiring the caller to
keep the StringRef alive beyong this call.

Differential Revision: https://reviews.llvm.org/D93133
2020-12-11 22:38:48 +00:00
Sean Silva 444822d77a Revert "Revert "[mlir] Start splitting the `tensor` dialect out of `std`.""
This reverts commit 0d48d265db.

This reapplies the following commit, with a fix for CAPI/ir.c:

[mlir] Start splitting the `tensor` dialect out of `std`.

This starts by moving `std.extract_element` to `tensor.extract` (this
mirrors the naming of `vector.extract`).

Curiously, `std.extract_element` supposedly works on vectors as well,
and this patch removes that functionality. I would tend to do that in
separate patch, but I couldn't find any downstream users relying on
this, and the fact that we have `vector.extract` made it seem safe
enough to lump in here.

This also sets up the `tensor` dialect as a dependency of the `std`
dialect, as some ops that currently live in `std` depend on
`tensor.extract` via their canonicalization patterns.

Part of RFC: https://llvm.discourse.group/t/rfc-split-the-tensor-dialect-from-std/2347/2

Differential Revision: https://reviews.llvm.org/D92991
2020-12-11 14:30:50 -08:00
Sean Silva 0d48d265db Revert "[mlir] Start splitting the `tensor` dialect out of `std`."
This reverts commit cab8dda90f.

I mistakenly thought that CAPI/ir.c failure was unrelated to this
change. Need to debug it.
2020-12-11 14:15:41 -08:00
Sean Silva cab8dda90f [mlir] Start splitting the `tensor` dialect out of `std`.
This starts by moving `std.extract_element` to `tensor.extract` (this
mirrors the naming of `vector.extract`).

Curiously, `std.extract_element` supposedly works on vectors as well,
and this patch removes that functionality. I would tend to do that in
separate patch, but I couldn't find any downstream users relying on
this, and the fact that we have `vector.extract` made it seem safe
enough to lump in here.

This also sets up the `tensor` dialect as a dependency of the `std`
dialect, as some ops that currently live in `std` depend on
`tensor.extract` via their canonicalization patterns.

Part of RFC: https://llvm.discourse.group/t/rfc-split-the-tensor-dialect-from-std/2347/2

Differential Revision: https://reviews.llvm.org/D92991
2020-12-11 13:50:55 -08:00
Alex Zinenko dacfb24b30 [mlir] Support inlining into affine operations
Introduce support for inlining into affine operations. This uses the generic
inline infrastructure and boils down to checking that, if applied, the inlining
doesn't violate the affine dimension/symbol value categorization. Given valid
IR, only the values that are valid dimensions/symbols thanks to being top-level
in their affine scope need special handling.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D92770
2020-12-11 16:24:27 +01:00
Nicolas Vasilache 7310501f74 [mlir][ArmNeon][RFC] Add a Neon dialect
This revision starts an Arm-specific ArmNeon dialect discussed in the [discourse RFC thread](https://llvm.discourse.group/t/rfc-vector-dialects-neon-and-sve/2284).

Differential Revision: https://reviews.llvm.org/D92171
2020-12-11 13:49:40 +00:00
Adrian Kuegel 9122070563 [mlir] Expose target configuration for lowering to ROCDL.
Differential Revision: https://reviews.llvm.org/D93028
2020-12-11 13:20:53 +01:00
Adrian Kuegel ada4c7a351 Add rsqrt lowering from standard to ROCDL.
Add a lowering for rsqrt from standard dialect to ROCDL.

Differential Revision: https://reviews.llvm.org/D93011
2020-12-11 13:18:57 +01:00
River Riddle 186c154991 [mlir] Remove the dependency on StandardOps from FoldUtils
OperationFolder currently uses ConstantOp as a backup when trying to materialize a constant after an operation is folded. This dependency isn't really useful or necessary given that dialects can/should provide a `materializeConstant` implementation.

Fixes PR#44866

Differential Revision: https://reviews.llvm.org/D92980
2020-12-10 14:13:57 -08:00
River Riddle c24f88b4db [mlir][SCCP] Don't visit private callables unless they are used when tracking interprocedural arguments/results
This fixes a subtle bug where SCCP could incorrectly optimize a private callable while waiting for its arguments to be resolved.

Fixes PR#48457

Differential Revision: https://reviews.llvm.org/D92976
2020-12-10 12:53:27 -08:00
Mehdi Amini 285c0aa262 Add MLIR Python binding for Array Attribute
Differential Revision: https://reviews.llvm.org/D92948
2020-12-10 20:51:34 +00:00
River Riddle 75eca67c1c [mlir][Parser] Fix crash in DenseElementsAttr parser when no elements are parsed
This fixes a crash when no elements are parsed, but the type expects at least one.

Fixes PR#47763

Differential Revision: https://reviews.llvm.org/D92982
2020-12-10 12:48:37 -08:00
River Riddle 1f5f006d9d [mlir][StandardOps] Verify that the result of an integer constant is signless
This was missed when supported for unsigned/signed integer types was first added, and results in crashes if a user tries to create/print a constant with the incorrect integer type.

Fixes PR#46222

Differential Revision: https://reviews.llvm.org/D92981
2020-12-10 12:40:10 -08:00
Rahul Joshi 563879b6f9 [NFC] Use ConvertOpToLLVMPattern instead of ConvertToLLVMPattern.
- use ConvertOpToLLVMPattern to avoid explicit casting and in most cases the
  constructor can be reused to save a few lines of code.

Differential Revision: https://reviews.llvm.org/D92989
2020-12-10 09:33:43 -08:00
Alex Zinenko db884dafb7 [mlir] Explicitly track branch instructions in translation to LLVM IR
The current implementation of the translation to LLVM IR relies on the
existence of a one-to-one mapping between MLIR blocks and LLVM IR basic blocks
in order to configure PHI nodes with appropriate source blocks. The one-to-one
mapping model is broken in presence of OpenMP operations that use LLVM's
OpenMPIRBuilder, which produces multiple blocks under the hood. This can lead
to invalid LLVM IR being emitted if OpenMPIRBuilder moved the branch operation
into a basic block different from the one it was originally created in;
specifically, a block that is not a direct predecessor could be used in the PHI
node. Instead, keep track of the mapping between MLIR LLVM dialect branch
operations and their LLVM IR counterparts and take the parent basic block of
the LLVM IR instruction at the moment of connecting the PHI nodes to
predecessors.

This behavior cannot be triggered as of now, but will be once we introduce the
conversion of OpenMP workshare loops.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D92845
2020-12-10 11:08:58 +01:00
Benjamin Kramer 1d00508c5b [mlir][Shape] Make sure tensor_cast(constant_shape) folding uses the correct type
This is still subtle, but I think the test cases are sufficient to show
that it works.

Differential Revision: https://reviews.llvm.org/D92927
2020-12-10 10:49:25 +01:00
Adrian Kuegel 09f717b929 Add sqrt lowering from standard to ROCDL
Add a lowering for sqrt from standard dialect to ROCDL.

Differential Revision: https://reviews.llvm.org/D92921
2020-12-10 09:47:37 +01:00
River Riddle d1e0545445 [mlir][Interfaces] Tidy up the documentation for interfaces
The documentation has become a bit stale with age, and doesn't include great documentation for some newer concepts. This revision tidies up a majority of it, with some more cleanup to come in the future. The documentation for the declarative specification is also moved from OpDefinitions.md to Interfaces.md, which is a much more logical place for it to live.

Differential Revision: https://reviews.llvm.org/D92895
2020-12-09 15:34:07 -08:00
Rahul Joshi b0d02b698b [MLIR] Minor cleanup for Shape dialect.
- Remove some unused types from the Shape dialect
- Fix from_extent_tensor to only allow 1D index tensors
- Fix assuming_yield to only allow shape.assuming as the parent op.
- Fix some documentation typos and reword some things.

Differential Revision: https://reviews.llvm.org/D92901
2020-12-09 14:21:35 -08:00
Tres Popp 7ea94922fa [mlir] Allow RegionBranchOps in dependence analysis
This is to prevent assertion failures on scf.if and shape.assuming
operations where this is not enough information currently to handle any
aliasing information.

Differential Revision: https://reviews.llvm.org/D92963
2020-12-09 22:32:04 +01:00
Sergei Grechanik 2d3b9fdc19 [mlir][Affine] Fix vectorizability check for multiple load/stores
This patch fixes a bug that allowed vectorizing of loops with loads and
stores having indexing functions varying along different memory
dimensions.

Reviewed By: aartbik, dcaballe

Differential Revision: https://reviews.llvm.org/D92702
2020-12-09 12:19:34 -08:00
Christian Sigg 0bf4a82a5a [mlir] Use mlir::OpState::operator->() to get to methods of mlir::Operation. This is a preparation step to remove the corresponding methods from OpState.
Reviewed By: silvas, rriddle

Differential Revision: https://reviews.llvm.org/D92878
2020-12-09 12:11:32 +01:00
Frederik Gossen d536569009 [MLIR] Expose target configuration for lowering to NVVM
Differential Revision: https://reviews.llvm.org/D92871
2020-12-09 10:29:38 +01:00
Mehdi Amini ac6ada4d3e Fix MLIR Python bindings build after changes to the C API to use StringRef (NFC) 2020-12-09 03:27:37 +00:00
Valentin Clement d553243fe4 [flang][openacc] Update reference to OpenACC 3.1 specification
Update all reference from the specification to the new OpenACC 3.1
document.

Reviewed By: SouraVX

Differential Revision: https://reviews.llvm.org/D92120
2020-12-08 14:36:38 -05:00
Eugene Zhulenev 94e645f9cc [mlir] Async: Add numWorkerThreads argument to createAsyncParallelForPass
Add an option to pass the number of worker threads to select the number of async regions for parallel for transformation.
```
std::unique_ptr<OperationPass<FuncOp>> createAsyncParallelForPass(int numWorkerThreads);
```

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D92835
2020-12-08 10:30:14 -08:00
Christian Sigg 2a9840900c [mlir] Revert "Tighten access of RewritePattern methods."
This reverts commit 02c9050155.
Painted myself into a corner with -Wvirtual_overload, private access, and final.

Differential Revision: https://reviews.llvm.org/D92855
2020-12-08 17:40:44 +01:00
Tres Popp 111ae220a3 [mlir] Use rewriting infrastructure in AsyncToLLVM
This is needed so a listener hears all changes during the dialect
conversion to allow correct rollbacks upon failure.

Differential Revision: https://reviews.llvm.org/D92685
2020-12-08 17:30:01 +01:00
Frederik Gossen b4750f58d8 Add sqrt lowering from standard to NVVM
Differential Revision: https://reviews.llvm.org/D92850
2020-12-08 17:08:27 +01:00
Benjamin Kramer 5844bc540c [mlir][Shape] Canonicalize assume_all with one input and tensor_cast of constant_shape
This allows simplifying some more complicated shape expressions

Differential Revision: https://reviews.llvm.org/D92843
2020-12-08 17:07:24 +01:00
Christian Sigg 02c9050155 [mlir] Tighten access of RewritePattern methods.
In RewritePattern, only expose `matchAndRewrite` as a public function. `match` can be protected (but needs to be protected because we want to call it from an override of `matchAndRewrite`). `rewrite` can be private.

For classes deriving from RewritePattern, all 3 functions can be private.

Side note: I didn't understand the need for the `using RewritePattern::matchAndRewrite` in derived classes, and started poking around. They are gone now, and I think the result is (only very slightly) cleaner.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D92670
2020-12-08 16:44:51 +01:00
ergawy 6c69d3d68e [MLIR][SPIRV] Add initial support for OpSpecConstantOp.
This commit adds initial support for SPIR-V OpSpecConstantOp
instruction. The following is introdcued:

- A new `spv.specConstantOperation` operation consisting of a single
region and of 2 operations within that regions (more details in the
docs of the op itself).
- A new `spv.yield` instruction that acts a terminator for
`spv.specConstantOperation`.

For now, the generic form of the new op is supported (i.e. no custom
parsing or printing). This will be done in a follow up patch.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D92232
2020-12-08 09:07:52 -05:00
Frederik Gossen bb7d43e7d5 Add rsqrt lowering from standard to NVVM
Differential Revision: https://reviews.llvm.org/D92838
2020-12-08 14:33:58 +01:00
Alex Zinenko 80766ecc65 [mlir] Add an option to control the number of loops in affine parallelizer
Add a pass option to control the number of nested parallel loops produced by
the parallelization passes. This is useful to build end-to-end passes targeting
systems that don't need multiple parallel dimensions (e.g., CPUs typically need
only one).

Reviewed By: wsmoses, chelini

Differential Revision: https://reviews.llvm.org/D92765
2020-12-08 10:44:37 +01:00
Alex Zinenko 2fe30a3534 [mlir] properly support min/max in affine parallelization
The existing implementation of the affine parallelization silently copies over
the lower and upper bound maps from affine.for to affine.parallel. However, the
semantics of these maps differ between these two ops: in affine.for, a max(min)
of results is taken for the lower(upper) bound; in affine.parallel, multiple
induction variables can be defined an each result corresponds to one induction
variable. Thus the existing implementation could generate invalid IR or IR that
passes the verifier but has different semantics than the original code. Fix the
parallelization utility to emit dedicated min/max operations before the
affine.parallel in such cases. Disallow parallelization if min/max would have
been in an operation without the AffineScope trait, e.g., in another loop,
since the result of these operations is not considered a valid affine dimension
identifier and may not be properly handled by the affine analyses.

Reviewed By: wsmoses

Differential Revision: https://reviews.llvm.org/D92763
2020-12-08 10:43:35 +01:00
Mehdi Amini e56f398dd3 Add Python binding for MLIR Type Attribute
Differential Revision: https://reviews.llvm.org/D92711
2020-12-07 23:06:58 +00:00