Commit Graph

4181 Commits

Author SHA1 Message Date
Nicolas Vasilache 2d32ee0d7a [mlir][Vector] Update lowering of vector ops to llvm intrinsics to use row-major.
Summary:
LLVM matrix intrinsics recently introduced an option to support row-major mode.
This matches the MLIR vector model, this revision switches to row-major.

A corner case related to degenerate sizes was also fixed upstream.
This revision removes the guard against this corner case.

A bug was uncovered on the output vector construction which this revision also fixes.

Lastly, this has been tested on a small size and benchmarked independently: no visible performance regression is observed.

In the future, when matrix intrinsics support per op attribute, we can more aggressively translate to that and avoid inserting MLIR-level transposes.

This has been tested independently to work on small matrices.

Differential Revision: https://reviews.llvm.org/D77761
2020-04-09 16:37:28 -04:00
Eli Friedman 133049d0ed [opaque pointers] Fix uses of deprecated CreateCall/CreateInvoke. 2020-04-09 13:24:55 -07:00
Nicolas Vasilache 8345b86d9a [mlir][Vector] Add lowering of 1-D vector transfer_read/write to masked load/store
Summary:
This revision adds support to lower 1-D vector transfers to LLVM.
A mask of the vector length is created that compares the base offset + linear index to the dim of the vector.
In each position where this does not overflow (i.e. offset + vector index < dim), the mask is set to 1.

A notable fact is that the lowering uses llvm.dialect_cast to allow writing code in the simplest form by targeting the simplest mix of vector and LLVM dialects and
letting other conversions kick in.

Differential Revision: https://reviews.llvm.org/D77703
2020-04-09 16:17:05 -04:00
Nicolas Vasilache 4408e6a96a [mlir][test] NFC - Rename cblas to mlir_test_cblas
The "cblas" lib under mlir/test is meant as a simple integration demonstration.
However it is installed and ends up conflicting with external projects who want to
define the real cblas.
Rename to avoid conflicts.

Differential revision: https://reviews.llvm.org/D76615
2020-04-09 16:13:33 -04:00
River Riddle bd1ccfe6df [mlir] Add a new RewritePattern::hasBoundedRewriteRecursion hook.
Summary: Some pattern rewriters, like dialect conversion, prohibit the unbounded recursion(or reapplication) of patterns on generated IR. Most patterns are not written with recursive application in mind, so will generally explode the stack if uncaught. This revision adds a hook to RewritePattern, `hasBoundedRewriteRecursion`, to signal that the pattern can safely be applied to the generated IR of a previous application of the same pattern. This allows for establishing a contract between the pattern and rewriter that the pattern knows and can handle the potential recursive application.

Differential Revision: https://reviews.llvm.org/D77782
2020-04-09 12:42:28 -07:00
Uday Bondhugula d314b7d5ca [MLIR] ShapedType accessor minor fixes + add isDynamicDim accessor
Minor fixes and cleanup for ShapedType accessors, use
ShapedType::kDynamicSize, add ShapedType::isDynamicDim.

Differential Revision: https://reviews.llvm.org/D77710
2020-04-09 08:47:50 +05:30
River Riddle 293c5210ec [mlir][NFC] Wrap the cl::opts in JitRunner within a struct to avoid global initializers.
Summary: This avoids the need for having global static initializers within the JITRunner support library, and only constructs the options when the runner is invoked.

Differential Revision: https://reviews.llvm.org/D77760
2020-04-08 18:33:37 -07:00
River Riddle 21605a1207 [mlir] Mark ClassID::getID as LLVM_EXTERNAL_VISIBILITY to ensure only one version exists
Summary: ClassID is used as a type id and must be unique in the face of shared libraries to ensure correctness. This fixes failures related to BUILD_SHARED_LIBs on macos.

Differential Revision: https://reviews.llvm.org/D77764
2020-04-08 16:51:48 -07:00
Jonathan Roelofs 223154d267 [mlir] Remove need for static global ctors from mlir-translate
Summary: https://bugs.llvm.org/show_bug.cgi?id=45436

Reviewers: mehdi_amini, mravishankar, antiagainst, rriddle, stephenneuendorffer

Reviewed By: mehdi_amini, rriddle, stephenneuendorffer

Subscribers: frgossen, stephenneuendorffer, jholewinski, mgorny, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, Joonsoo, bader, grosul1, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D77515
2020-04-08 16:52:33 -06:00
River Riddle 67bdda6350 [mlir][NFC] Wrap static DenseMap inside of a function to avoid the need for a global static initializer
This also helps to abstract away the exact implementation details of the loopup method if we wish to change it in the future.
2020-04-08 14:18:35 -07:00
Nicolas Vasilache 6fb6a4d7f9 [mlir][Linalg] Add a test for a fused Linalg pass based on DRR to go from matmul to vectors
This revision builds a simple "fused pass" consisting of 2 levels of tiling, memory promotion and vectorization using linalg transformations written as composable pattern rewrites.
2020-04-08 16:54:40 -04:00
River Riddle c6e917d2d3 [mlir][NFC] Remove cl::opts for LoopUnroll now that the pass uses PassOptions
instead.

These were missed when the opts were replaced, and are unused.
2020-04-08 13:24:09 -07:00
River Riddle 400ad6f95d [mlir] Eliminate the remaining usages of cl::opt instead of PassOption.
Summary: Pass options are a better choice for various reasons and avoid the need for static constructors.

Differential Revision: https://reviews.llvm.org/D77707
2020-04-08 13:05:08 -07:00
Uday Bondhugula ae8ebeca51 [MLIR] Fix test case typos in unroll.mlir
Fix check line typos in test/Dialect/Affine/unroll.mlir.

Differential Revision: https://reviews.llvm.org/D77738
2020-04-08 22:21:07 +05:30
Andy Davis 7006daa548 [MLIR][Vector] Update ShapeCastOp folder to use producer-consumer value forwarding.
Summary:
Update ShapeCastOp folder to use producer-consumer value forwarding.
Support is added for tracking sub-vectors through trivial shape cast operations,
where the sub-vector shape is preserved across shape cast operations and only
leading ones are added or removed.
Support is preserved for cancelling shape cast operations.
One unit test is added and two are updated.

Reviewers: aartbik, nicolasvasilache

Reviewed By: aartbik, nicolasvasilache

Subscribers: frgossen, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, grosul1, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D77253
2020-04-08 08:55:37 -07:00
Uday Bondhugula 3156b5422e [MLIR] Fix more gcc-5 build issues from D77528
820c420d4e1c630b5ead285917c6ecdd2f5092ad did not really fix all build
issues by D77528. This gets rid of two unnecessary 'using' declarations.

Differential Revision: https://reviews.llvm.org/D77726
2020-04-08 19:21:50 +05:30
Uday Bondhugula a59008a3a5 [MLIR] Fix gcc-5 build failure cause by D77528
Fix gcc-5 build failure cause by D77528

Differential Revision: https://reviews.llvm.org/D77719
2020-04-08 17:27:12 +05:30
Uday Bondhugula 01d97a3549 [MLIR] Add support to use aligned_alloc to lower AllocOp from std to llvm
Support to recognize and deal with aligned_alloc was recently added to
LLVM's TLI/MemoryBuiltins and its various optimization passes. This
revision adds support for generation of aligned_alloc's when lowering
AllocOp from std to LLVM. Setting 'use-aligned_alloc=1' will lead to
aligned_alloc being used for all heap allocations. An alignment and size
that works with the constraints of aligned_alloc is chosen.

Using aligned_alloc is preferable to "using malloc and adjusting the
allocated pointer to align for indexing" because the pointer access
arithmetic done for the latter only makes it harder for LLVM passes to
deal with for analysis, optimization, attribute deduction, and rewrites.

Differential Revision: https://reviews.llvm.org/D77528
2020-04-08 15:10:19 +05:30
Christian Sigg 06ddb7946b [MLIR] Add missing colon after CHECKs.
Reviewers: herhut

Reviewed By: herhut

Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, grosul1, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D77709
2020-04-08 11:16:06 +02:00
Nicolas Vasilache 3cb1f35df2 [mlir][Linalg] Use subview instead of linalg.slice in Promotion.cpp
This revision removes the reliance of Promotion on `linalg.slice` which is meant
for the rank-reducing case.

Differential Revision: https://reviews.llvm.org/D77676
2020-04-07 23:52:31 -04:00
Lukas Sommer d86ece13d9 Keep output file after successful execution of mlir-opt
Invoke `keep()` on the output file of `mlir-opt` in case the invocation of `MlirOptMain` was successful, to make sure the output file is not deleted on exit from `mlir-opt`.
Fixes a similar problem in `standalone-opt` from the example for an out-of-tree, standalone MLIR dialect.

This revision also adds a missing parameter to the invocation of `MlirOptMain` in `standalone-opt`.

Differential Revision: https://reviews.llvm.org/D77643
2020-04-08 03:37:45 +00:00
River Riddle 8b7e669e68 [mlir][AsmFormat] Avoid invalidating the iterator when verifying attributes
Summary: 'it' may get invalidated when recursing into optional groups. This revision refactors the inner loop to avoid the need to compare the iterator after invalidation.

Differential Revision: https://reviews.llvm.org/D77686
2020-04-07 15:54:56 -07:00
Stephen Neuendorffer 19fec004e2 [MLIR] Add note for file-line numbers in tablegen errors for assembly formats
Error messages for the custom assembly format are difficult to understand
because there are no line numbers.  This happens because the assembly format
is parsed as a standalone line, separate from it's parent file, with no useful
location information.  Fixing this properly probably requires quite a bit
of invasive plumbing through the SourceMgr, similar to how included files
are handled

This proposal is a less invasive short term solution.  When generating an
error message we generate an additional note which at least properly describes
the operation definition the error occured in, if not the actual line number
of the assemblyFormat definition.

A typical message is like:

error: type of operand #0, named 'operand', is not buildable and a buildable type cannot be inferred
  $operand type($result) attr-dict
  ^
/src/llvm-project/mlir/test/mlir-tblgen/op-format-spec.td:296:1: note: in custom assembly format for this operation
def ZCoverageInvalidC : TestFormat_Op<"variable_invalid_c", [{
^
note: suggest adding a type constraint to the operation or adding a 'type($operand)' directive to the custom assembly format
  $operand type($result) attr-dict
  ^

Differential Revision: https://reviews.llvm.org/D77488
2020-04-07 15:06:51 -07:00
Stephen Neuendorffer 75f60c698f [MLIR] Cleanup mlir-tblgen error messages for custom assembly formats.
The messages are somewhat cryptic, since they are not complete sentences,
include lots of ambiguous words, like 'format' which are hard to parse,
and include names from the users code which may, or may not make sense in
the context of the message.  Start to clean this up and provide some
guidance for fixes.

Also, add a test for one of the messages which didn't have a test at all.

Differential Revision: https://reviews.llvm.org/D77449
2020-04-07 15:06:50 -07:00
River Riddle 5fee925beb [mlir][Pass] Update the documentation for the declarative pass specification
The pass tablegen backend now generates base classes instead of utilities, so this revision updates the documentation to reflect that.
2020-04-07 14:21:32 -07:00
River Riddle 1834ad4a69 [mlir][Pass] Update the PassGen to generate base classes instead of utilities
Summary:
This is much cleaner, and fits the same structure as many other tablegen backends. This was not done originally as the CRTP in the pass classes made it overly verbose/complex.

Differential Revision: https://reviews.llvm.org/D77367
2020-04-07 14:08:52 -07:00
River Riddle 80aca1eaf7 [mlir][Pass] Remove the use of CRTP from the Pass classes
This revision removes all of the CRTP from the pass hierarchy in preparation for using the tablegen backend instead. This creates a much cleaner interface in the C++ code, and naturally fits with the rest of the infrastructure. A new utility class, PassWrapper, is added to replicate the existing behavior for passes not suitable for using the tablegen backend.

Differential Revision: https://reviews.llvm.org/D77350
2020-04-07 14:08:52 -07:00
River Riddle 722f909f7a [mlir][Pass][NFC] Replace usages of ModulePass with OperationPass<ModuleOp>
ModulePass doesn't provide any special utilities and thus doesn't give enough benefit to warrant a special pass class. This revision replaces all usages with the more general OperationPass.

Differential Revision: https://reviews.llvm.org/D77339
2020-04-07 14:08:52 -07:00
Jacques Pienaar 3f7439b280 [mlir][DRR] Add location directive
Summary:
Add directive to indicate the location to give to op being created. This
directive is optional and if unused the location will still be the fused
location of all source operations.

Currently this directive only works with other op locations, reusing an
existing op location or a fusion of op locations. But doesn't yet support
supplying metadata for the FusedLoc.

Based off initial revision by antiagainst@ and effectively mirrors GlobalIsel
debug_locations directive.

Differential Revision: https://reviews.llvm.org/D77649
2020-04-07 13:38:25 -07:00
Stella Laurenzo f5deb0878d Remove FxpMathOps dialect and Quantizer tool.
Summary:
* Removal of FxpMathOps was discussed on the mailing list.
* Will send a courtesy note about also removing the Quantizer (which had some dependencies on FxpMathOps).
* These were only ever used for experimental purposes and we know how to get them back from history as needed.
* There is a new proposal for more generalized quantization tooling, so moving these older experiments out of the way helps clean things up.

Subscribers: mgorny, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, grosul1, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D77479
2020-04-07 13:22:39 -07:00
River Riddle c0a33aaa80 [mlir][Diagnostic] Don't store Operation arguments as a DiagnosticArgument
Summary: Diagnostics may be cached in the parallel diagnostic handler to preserve proper ordering. Storing the Operation as a DiagnosticArgument is problematic as the operation may be erased or changed before it finally gets printed.

Differential Revision: https://reviews.llvm.org/D77675
2020-04-07 12:49:06 -07:00
Lei Zhang 47b234944d [mlir][spirv] Fix wrong Phi parent block for back-to-back loops
If we have two back-to-back loops with block arguments, the OpPhi
instructions generated for the second loop's block arguments should
have use the merge block of the first SPIR-V loop structure as
their incoming parent block.

Differential Revision: https://reviews.llvm.org/D77543
2020-04-07 12:54:54 -04:00
Lei Zhang 2d3eb493d4 [mlir][vulkan-runner] Fix createLowerToLLVMPass interface
createLowerToLLVMPass() now requires a struct for passing in arguments
after 7023f4b4cb.
2020-04-07 12:54:54 -04:00
Uday Bondhugula 7023f4b4cb [MLIR] Introduce std.alloca op
Introduce the alloca op for stack memory allocation. When converting to the
LLVM dialect, this is lowered to an llvm.alloca. Refactor the std to
llvm conversion for alloc op to reuse with alloca. Drop useAlloca option
with alloc op lowering.

Differential Revision: https://reviews.llvm.org/D76602
2020-04-07 15:45:07 +05:30
Uday Bondhugula 70da33bf30 [MLIR] fix/update affine data copy utility for max/min bounds
Fix point-wise copy generation to work with bounds that have max/min.
Change structure of copy loop nest to use absolute loop indices and
subtracting base from the indexes of the fast buffers. Update supporting
utilities: Fix FlatAffineConstraints::getLowerAndUpperBound to look at
equalities as well and for a missing division. Update unionBoundingBox
to not discard common constraints (leads to a tighter system). Update
MemRefRegion::getConstantBoundingSizeAndShape to add memref dimension
constraints. Run removeTrivialRedundancy at the end of
MemRefRegion::compute.  Run single iteration loop promotion and
load/store canonicalization after affine data copy (in its test pass as
well).

Differential Revision: https://reviews.llvm.org/D77320
2020-04-07 13:55:42 +05:30
Eli Friedman 68b03aee1a Remove SequentialType from the type heirarchy.
Now that we have scalable vectors, there's a distinction that isn't
getting captured in the original SequentialType: some vectors don't have
a known element count, so counting the number of elements doesn't make
sense.

In some cases, there's a better way to express the commonality using
other methods. If we're dealing with GEPs, there's GEP methods; if we're
dealing with a ConstantDataSequential, we can query its element type
directly.

In the relatively few remaining cases, I just decided to write out
the type checks. We're talking about relatively few places, and I think
the abstraction doesn't really carry its weight. (See thread "[RFC]
Refactor class hierarchy of VectorType in the IR" on llvmdev.)

Differential Revision: https://reviews.llvm.org/D75661
2020-04-06 17:03:49 -07:00
Jacques Pienaar d3a31c4db4 Remove case in rewritergen unmatched opdefgen side
The rewriter generates a call to build that is not handled by opdef generator
and so will fail to compile. Also if this is a root node being replaced
(depth 0) then using the more generic build method in the rewrite suffices.
2020-04-06 16:03:49 -07:00
Chris Lattner 8ba7a2d5df Minor typo improvements in documentation, NFC. 2020-04-06 13:18:49 -07:00
River Riddle ae9edbcea2 [mlir][AsmPrinter] Change value numbering for local scope to be the next isolated operation.
Summary: This revision updates the value numbering when printing to number from the next parent operation that is isolated from above. This is the highest level to number from that still ensures thread-safety. This revision also changes the behavior of Operator::operator<< to use local scope to avoid thread races when numbering operations.

Differential Revision: https://reviews.llvm.org/D77525
2020-04-06 11:09:29 -07:00
Jean-Michel Gorius d3df2da4a9 [mlir] Fix typo in docs/DefiningAttributesAndTypes.md 2020-04-06 19:38:34 +02:00
Nicolas Vasilache 8f229989d5 [mlir][Linalg] Add a linalg.tensor_reshape to operate on tensors
Summary:
This revision adds a tensor_reshape operation that operates on tensors.
In the tensor world the constraints are less stringent and we can allow more
arbitrary dynamic reshapes, as long as they are contractions.

The expansion of a dynamic dimension into multiple dynamic dimensions is under-specified and is punted on for now.

Differential Revision: https://reviews.llvm.org/D77360
2020-04-06 11:19:17 -04:00
Djordje Todorovic da5fe23e84 [mlir][LowerToAffineLoops] Handle tensors of rank 0
This will fix the case:

  $ toyc -emit=jit test.toy
  $ cat test.toy
  def main() {
    var a = 1;
    print(a);
  }

Without this patch it would trigger an assertion.

Differential Revision: https://reviews.llvm.org/D77464
2020-04-06 14:51:03 +02:00
Alexander Belyaev c2d03e4ef1 [MLIR] Change return type of ParallelOp::getInductionVars to ValueRange.
The current return type sometimes leads to code like
to_vector<2>(ValueRange(loop.getInductionIvs())). It would be nice to
shorten it. Users who need access to Block::BlockArgListType (if there
are any), can always call getBody()->getArguments(); if needed.

Also remove getNumInductionVars(), since there is getNumLoops().

Differential Revision: https://reviews.llvm.org/D77526
2020-04-06 10:11:02 +02:00
Lei Zhang 322c235a52 [mlir][spirv] NFC: remove uncessary return after llvm_unreachable 2020-04-05 20:00:56 -04:00
River Riddle 74d44c43e8 [mlir] Refactor and cleanup the translation facilities.
Summary:
This revision performs several cleanups on the translation infra:
* Removes the TranslateCLParser library and consolidates into Translation
  - This was a weird library that existed in Support, and didn't really justify being a standalone library.
* Cleans up the internal registration and consolidates all of the translation functions within one registry.

Differential Revision: https://reviews.llvm.org/D77514
2020-04-05 16:21:21 -07:00
River Riddle c9da04d660 [mlir] Only number the parent operation in Block::printAsOperand
Summary: Blocks are numbered locally within a region, so numbering above the parent region is unnecessary.

Differential Revision: https://reviews.llvm.org/D77510
2020-04-05 16:17:13 -07:00
Uday Bondhugula 34392b518f [MLIR][NFC] Make AsmPrinter messages on null structures consistent
Make AsmPrinter messages on null structures consistent: use <<NULL ...>>.

Differential Revision: https://reviews.llvm.org/D77509
2020-04-06 01:14:36 +05:30
River Riddle 8d0bc03482 [mlir] Update the documentation on Canonicalization
Summary: This updates the canonicalization documentation, and properly documents the different ways of canonicalizing operations.

Differential Revision: https://reviews.llvm.org/D77490
2020-04-05 12:12:25 -07:00
River Riddle c7b83a4fe5 [mlir][Pass] Add documentation for the declarative pass specification
Summary:
This revision adds a section to WritingAPass to document the declarative specification, and how to use it.

Differential Revision: https://reviews.llvm.org/D77102
2020-04-05 11:52:00 -07:00
Mehdi Amini 96eb38418b Make the AsmPrinter print "<<NULL TYPE>>" instead of crashing on null types
Even if this indicates in general a problem at call sites, the printer
is used for debugging and avoiding crashing is friendlier for example
when used in diagnostics or other printer.

Differential Revision: https://reviews.llvm.org/D77481
2020-04-05 18:36:18 +00:00