Commit Graph

3893 Commits

Author SHA1 Message Date
Alexander Belyaev 3147342ae7 [MLIR] Change custom printer/parser for loop.parallel and loop.reduce. 2020-03-09 15:11:48 +01:00
Uday Bondhugula 5e080dff75 [MLIR] NFC: modernize affine loop fusion test cases
- update test case for readability, avoid unnecessary matches

Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>

Differential Revision: https://reviews.llvm.org/D75823
2020-03-09 04:27:51 +00:00
Uday Bondhugula 82e9160aab [MLIR][Affine] NFC: add convenience method for affine data copy for a loop body
add convenience method for affine data copy generation for a loop body

Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>

Differential Revision: https://reviews.llvm.org/D75822
2020-03-09 04:23:54 +00:00
Mehdi Amini 8c70c42be2 Fix MLIR clang-tidy: when tweaking it does not inherit from the parent
It is almost identical to the top-level .clang-tidy, except that
{Member,Parameter,Variable}Case use camelBack.
2020-03-07 17:44:21 +00:00
River Riddle 320f0b0036 [mlir] Change EffectKind in unsigned for bitfield to avoid miscompile in
MSVC

MSVC has problems if the type of the bitfield is different, leading to
invalid code generation.
2020-03-06 23:01:49 -08:00
Mason Remy c3108404c1 [mlir][nfc] Fix building mlir_c_runner_utils for Windows
Summary:
On Windows, building `mlir_c_runner_utils` doesn't properly export
symbols, thus resulting in an implib not being created, which causes
an error when consuming LLVM from external projects.

Differential Revision: https://reviews.llvm.org/D75769
2020-03-06 22:44:45 -08:00
Uday Bondhugula 91153e0624 [mlir][NFC] remove stray decl of toAffineExpr, rename for readability
Summary:
- remove stray toAffineExpr decl in affine analysis (name duplicate of
  mlir::toAffineExpr)

- rename mlir::toAffineExpr for better readability

- related NFC changes

Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>

Differential Revision: https://reviews.llvm.org/D75694
2020-03-06 22:38:47 -08:00
River Riddle f240d303c2 [mlir] Explicitly qualify Effect to avoid MSVC build failure
MSVC qualifies the Effect reference contextually depending on where the
template is instantiated, leading to compiler failures if there is a
different Effect class defined.
2020-03-06 19:18:13 -08:00
Stephen Neuendorffer d774fbc350 [MLIR] Add document about creating a dialect.
Goal is also to document best naming practices from here:
https://llvm.discourse.group/t/rfc-canonical-file-paths-to-dialects/621

Differential Revision: https://reviews.llvm.org/D75762
2020-03-06 16:37:57 -08:00
Stephen Neuendorffer 7264cf4e45 [MLIR] Add missing DEPENDS line for MLIRSPIRV
This line was inadvertantly left off, which results in missing dependencies
and a potentially broken build
2020-03-06 15:10:14 -08:00
River Riddle 20dca52288 [mlir][SideEffects] Enable specifying side effects directly on the arguments/results of an operation.
Summary:
New classes are added to ODS to enable specifying additional information on the arguments and results of an operation. These classes, `Arg` and `Res` allow for adding a description and a set of 'decorators' along with the constraint. This enables specifying the side effects of an operation directly on the arguments and results themselves.

Example:
```
def LoadOp : Std_Op<"load"> {
  let arguments = (ins Arg<AnyMemRef, "the MemRef to load from",
                           [MemRead]>:$memref,
                       Variadic<Index>:$indices);
}
```

Differential Revision: https://reviews.llvm.org/D74440
2020-03-06 14:04:36 -08:00
River Riddle f8923584da [mlir][SideEffects] Define a set of interfaces and traits for defining side effects
This revision introduces the infrastructure for defining side-effects and attaching them to operations. This infrastructure allows for defining different types of side effects, that don't interact with each other, but use the same internal mechanisms. At the base of this is an interface that allows operations to specify the different effect instances that are exhibited by a specific operation instance. An effect instance is comprised of the following:

* Effect: The specific effect being applied.
  For memory related effects this may be reading from memory, storing to memory, etc.

* Value: A specific value, either operand/result/region argument, the effect pertains to.

* Resource: This is a global entity that represents the domain within which the effect is being applied.

MLIR serves many different abstractions, which cover many different domains. Simple effects are may have very different context, for example writing to an in-memory buffer vs a database. This revision defines uses this infrastructure to define a set of initial MemoryEffects. The are effects that generally correspond to memory of some kind; Allocate, Free, Read, Write.

This set of memory effects will be used in follow revisions to generalize various parts of the compiler, and make others more powerful(e.g. DCE).

This infrastructure was originally proposed here:
https://groups.google.com/a/tensorflow.org/g/mlir/c/v2mNl4vFCUM

Differential Revision: https://reviews.llvm.org/D74439
2020-03-06 14:04:36 -08:00
Stephen Neuendorffer 9f979d7ad5 [MLIR] Fixes for BUILD_SHARED_LIBS=on
Differential Revision: https://reviews.llvm.org/D75308
2020-03-06 13:25:18 -08:00
Valentin Churavy 7c64f6bf52 [MLIR] Add support for libMLIR.so
Putting this up mainly for discussion on
how this should be done. I am interested in MLIR from
the Julia side and we currently have a strong preference
to dynamically linking against the LLVM shared library,
and would like to have a MLIR shared library.

This patch adds a new cmake function add_mlir_library()
which accumulates a list of targets to be compiled into
libMLIR.so.  Note that not all libraries make sense to
be compiled into libMLIR.so.  In particular, we want
to avoid libraries which primarily exist to support
certain tools (such as mlir-opt and mlir-cpu-runner).

Note that the resulting libMLIR.so depends on LLVM, but
does not contain any LLVM components.  As a result, it
is necessary to link with libLLVM.so to avoid linkage
errors. So, libMLIR.so requires LLVM_BUILD_LLVM_DYLIB=on

FYI, Currently it appears that LLVM_LINK_LLVM_DYLIB is broken
because mlir-tblgen is linked against libLLVM.so and
and independent LLVM components.

Previous version of this patch broke depencies on TableGen
targets.  This appears to be because it compiled all
libraries to OBJECT libraries (probably because cmake
is generating different target names).  Avoiding object
libraries results in correct dependencies.

(updated by Stephen Neuendorffer)

Differential Revision: https://reviews.llvm.org/D73130
2020-03-06 13:25:18 -08:00
Stephen Neuendorffer 4594d0e943 [MLIR] Move from add_dependencies() to DEPENDS
add_llvm_library and add_llvm_executable may need to create new targets with
appropriate dependencies.  As a result, it is not sufficient in some
configurations (namely LLVM_BUILD_LLVM_DYLIB=on) to only call
add_dependencies().  Instead, the explicit TableGen dependencies must
be passed to add_llvm_library() or add_llvm_executable() using the DEPENDS
keyword.

Differential Revision: https://reviews.llvm.org/D74930
2020-03-06 13:25:17 -08:00
Stephen Neuendorffer 2488016bae [MLIR] Remove redundant library dependencies
In cmake, it is redundant to have a target list under target_link_libraries()
and add_dependency().  This patch removes the redundant dependency from
add_dependency().

Differential Revision: https://reviews.llvm.org/D74929
2020-03-06 10:12:31 -08:00
Stephen Neuendorffer 1c82dd39f9 [MLIR] Ensure that target_link_libraries() always has a keyword.
CMake allows calling target_link_libraries() without a keyword,
but this usage is not preferred when also called with a keyword,
and has surprising behavior.  This patch explicitly specifies a
keyword when using target_link_libraries().

Differential Revision: https://reviews.llvm.org/D75725
2020-03-06 09:14:01 -08:00
Adrian Kuegel 86306df7dd Extract common code to deal with multidimensional vectors.
Summary: Also replace dyn_cast_or_null with dyn_cast when possible.

Differential Revision: https://reviews.llvm.org/D75733
2020-03-06 13:54:54 +01:00
Nicolas Vasilache cac1ed1f4b [mlir] Introduce an intrinsic for llvm.matrix.multiply
This revision adds the first intrinsic for llvm.matrix.multiply.
This uses the more general `LLVM_OneResultOp` for now since the goal is
to use the
specific Matrix builders that @fhahn has created recently.

When piped through:
```
opt -O3 -enable-matrix | llc -O3 -march=x86-64 -mcpu=skylake-avx512
```
this has been verified to generate ymm instructions.

Additional function attribute support will be needed to generate proper
zmm instructions but at least things run end to end.

Benchmarking will be provided separately with the experimental
metaprogramming
[ModelBuilder](https://github.com/google/iree/tree/master/experimental/ModelBuilder)
tool when ready.
2020-03-05 17:31:41 -05:00
aartbik 0d924700a6 [mlir] [VectorOps] Merge VectorReduction/VectorReductionV2 into one Op
Summary:
Paying off some technical debt in VectorOps, where I introduced a special
op for a fused accumulator into reduction to avoid some issues around
printing and parsing an optional accumulator. This CL merges the two
into one op again and does things the right way (still would be nice
to have "assemblyFormat" for optional operands though....).

Reviewers: nicolasvasilache, andydavis1, ftynse, rriddle

Reviewed By: nicolasvasilache

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

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D75699
2020-03-05 13:07:31 -08:00
River Riddle cb1777127c [mlir] Remove successor operands from the Operation class
Summary:
This revision removes all of the functionality related to successor operands on the core Operation class. This greatly simplifies a lot of handling of operands, as well as successors. For example, DialectConversion no longer needs a special "matchAndRewrite" for branching terminator operations.(Note, the existing method was also broken for operations with variadic successors!!)

This also enables terminator operations to define their own relationships with successor arguments, instead of the hardcoded "pass-through" behavior that exists today.

Differential Revision: https://reviews.llvm.org/D75318
2020-03-05 12:53:02 -08:00
River Riddle c98cff5ae4 [mlir] Automatically populate `operand_segment_sizes` in the auto-generated build methods.
This greatly simplifies the requirements for builders using this mechanism for managing variadic operands.

Differential Revision: https://reviews.llvm.org/D75317
2020-03-05 12:52:22 -08:00
River Riddle 988249a506 [mlir] Refactor a few users to no longer rely on the successor operand API of Operation.
The existing API for successor operands on operations is in the process of being removed. This revision simplifies a later one that completely removes the existing API.

Differential Revision: https://reviews.llvm.org/D75316
2020-03-05 12:51:59 -08:00
River Riddle 01f7431b5b [mlir][DeclarativeParser] Add support for formatting operations with AttrSizedOperandSegments.
This attribute details the segment sizes for operand groups within the operation. This revision add support for automatically populating this attribute in the declarative parser.

Differential Revision: https://reviews.llvm.org/D75315
2020-03-05 12:51:28 -08:00
River Riddle 621d7cca37 [mlir] Add a new BranchOpInterface to allow for opaquely interfacing with branching terminator operations.
This interface contains the necessary components to provide the same builtin behavior that terminators have. This will be used in future revisions to remove many of the hardcoded constraints placed on successors and successor operands. The interface initially contains three methods:

```c++
// Return a set of values corresponding to the operands for successor 'index', or None if the operands do not correspond to materialized values.
Optional<OperandRange> getSuccessorOperands(unsigned index);

// Return true if this terminator can have it's successor operands erased.
bool canEraseSuccessorOperand();

// Erase the operand of a successor. This is only valid to call if 'canEraseSuccessorOperand' returns true.
void eraseSuccessorOperand(unsigned succIdx, unsigned opIdx);
```

Differential Revision: https://reviews.llvm.org/D75314
2020-03-05 12:50:35 -08:00
River Riddle c0fd5e657e [mlir] Add traits for verifying the number of successors and providing relevant accessors.
This allows for simplifying OpDefGen, as well providing specializing accessors for the different successor counts. This mirrors the existing traits for operands and results.

Differential Revision: https://reviews.llvm.org/D75313
2020-03-05 12:49:59 -08:00
MaheshRavishankar 3f44495dfd [mlir][GPU] Expose the functionality to create a GPUFuncOp from a LaunchOp
The current setup of the GPU dialect is to model both the host and
device side codegen. For cases (like IREE) the host side modeling
might not directly fit its use case, but device-side codegen is still
valuable. First step in accessing just the device-side functionality
of the GPU dialect is to allow just creating a gpu.func operation from
a gpu.launch operation. In addition this change also "inlines"
operations into the gpu.func op at time of creation instead of this
being a later step.

Differential Revision: https://reviews.llvm.org/D75287
2020-03-05 11:03:51 -08:00
Benjamin Kramer 2773c692e8 Fix pessimizing move. NFC. 2020-03-05 18:20:14 +01:00
Chris Lattner c2b2472ca8 Fix a warning about an unreachable default in a switch statement.
Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D75663
2020-03-05 08:36:28 -08:00
Kiran Chandramohan 92a295eb39 [MLIR, OpenMP] Translation of OpenMP barrier construct to LLVM IR
Summary:
This patch adds support for translation of the OpenMP barrier construct to LLVM
IR. The OpenMP IRBuilder is used for this translation. In this patch the code
for translation is added to the existing LLVM dialect translation to LLVM IR.

The patch includes code changes and a testcase.

Reviewers: jdoerfert, nicolasvasilache, ftynse, rriddle, mehdi_amini

Reviewed By: ftynse, rriddle, mehdi_amini

Differential Revision: https://reviews.llvm.org/D72962
2020-03-05 11:59:36 +00:00
MaheshRavishankar 755c050200 [mlir][Linalg] Fix load/store operations generated while lower loops when
output has zero rank.

While lowering to loops, no indices should be used in the load/store
operation if the buffer is zero-rank.

Differential Revision: https://reviews.llvm.org/D75391
2020-03-04 17:04:30 -08:00
Frank Laub cdc5cba721 [MLIR][Affine][NFC] Expose expandAffineMap
Summary:
Expose expandAffineMap so that it can be used by lowerings defined outside of
MLIR core.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D75589
2020-03-04 14:17:17 -08:00
Lei Zhang f6981ac595 [mlir][vulkan-runner] Add basic timing for compute pipeline
This commit adds timestamp query commands in Vulkan runner's
compute pipeline to gain insights into how long it takes to
run the compute shader. This commit also adds timing from CPU
side for VkQueueSubmit and vkQueueWaitIdle.

Differential Revision: https://reviews.llvm.org/D75531
2020-03-04 17:13:28 -05:00
Frank Laub c4119a5b90 [MLIR][Affine][NFC] Remove obsolete and ambiguous definitions
Summary:
Looks like a refactor that was never completed.

This change removes some unused and ambiguous definitions.

Reviewed By: bondhugula, nicolasvasilache, rriddle

Differential Revision: https://reviews.llvm.org/D75586
2020-03-04 13:14:25 -08:00
Lei Zhang 9600b55ac8 [mlir][spirv] Support integer signedness
This commit updates SPIR-V dialect to support integer signedness
by relaxing various checks for signless to just normal integers.

The hack for spv.Bitcast can now be removed.

Differential Revision: https://reviews.llvm.org/D75611
2020-03-04 15:14:11 -05:00
Lei Zhang 5b2cc6c3d0 [mlir][ods] Improve integer signedness modelling
A previous commit added support for integer signedness in C++
IntegerType. This change introduces ODS definitions for
integer types and integer (element) attributes w.r.t. signedness.

This commit also updates various existing definitions' descriptions
to mention signless where suitable to make it more clear.

Positive and non-negative integer attributes are removed to avoid
the explosion of subclasses. Instead, one should use more atmoic
constraints together with Confined to model that. For example,
`Confined<..., [IntPositive]>`.

Differential Revision: https://reviews.llvm.org/D75610
2020-03-04 15:05:42 -05:00
Lei Zhang 440ef33073 [mlir][spirv] Add get() method to TargetEnvAttr taking raw values
Also make the getResourceLimits() method more explicit about its return type.

Differential Revision: https://reviews.llvm.org/D75484
2020-03-04 14:01:26 -05:00
River Riddle d09d0bd7a0 [mlir][NFC] Sort the operations alphabetically and add header blocks
Summary:
The order of the operations has fallen out of sync as operations have been renamed and new ones have been added.

Differential Revision: https://reviews.llvm.org/D75540
2020-03-04 09:48:55 -08:00
Alex Zinenko aff6bf4ff8 [mlir] support conversion of parallel reduction loops to std
Recently introduced support for converting sequential reduction loops to
CFG of basic blocks in the Standard dialect makes it possible to perform
a staged conversion of parallel reduction loops into a similar CFG by
using sequential loops as an intermediate step. This is already the case
for parallel loops without reduction, so extend the pattern to support
an additional use case.

Differential Revision: https://reviews.llvm.org/D75599
2020-03-04 16:37:17 +01:00
Alexander Belyaev ffcb492327 [MLIR] Add a comment to `requiredOperandCount` arg in LoopOps.cpp.
Differential Revision: https://reviews.llvm.org/D75578
2020-03-04 15:48:23 +01:00
Adrian Kuegel 91acb5b3e1 Add rsqrt op to Standard dialect and lower it to LLVM dialect.
Summary:
This adds an rsqrt op to the standard dialect, and lowers
it as 1 / sqrt to the LLVM dialect.

Differential Revision: https://reviews.llvm.org/D75353
2020-03-04 13:13:31 +01:00
Frank Laub 216ef5b9ab [MLIR][NFC] Fix for VS2017 bug.
Apparently there is a bug in VS2017 concerning compile-time constant
expressions.
https://developercommunityapi.westus.cloudapp.azure.com/content/problem/110435/not-compile-time-constant-expression.html

This change works with any C++11 compiler (including VS2017) and is a little bit
easier to read.

Reviewers: stella.stamenova, nicolasvasilache

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D75584
2020-03-03 17:06:22 -08:00
Alexander Belyaev e0ce852277 [MLIR] Expose makeCanonicalStridedLayoutExpr in StandardTypes.h.
Differential Revision: https://reviews.llvm.org/D75575
2020-03-04 00:40:33 +01:00
Matthias Kramm cb530ec8b8 [mlir][Tutorial] Make parsing an empty file print a better error.
Summary:
Previously, we would, for an empty file, print the somewhat confusing
  Assertion `tok == curTok [...]' failed.
With this change, we now print
  Parse error [...]: expected 'def' [...]

This only affects the parser from chapters 1-6, since the more advanced
chapter 7 parser is actually able to generate an empty module from an
empty file.  Nonetheless, this commit also adds the additional check to
the chapter 7 parser, for consistency.

Differential Revision: https://reviews.llvm.org/D75534
2020-03-03 13:21:05 -08:00
River Riddle c10896682d [mlir] Generate CmpFPredicate as an EnumAttr in tablegen
Summary: This allows for attaching the attribute to CmpF as a proper argument, and thus enables the removal of a bunch of c++ code.

Differential Revision: https://reviews.llvm.org/D75539
2020-03-03 13:19:25 -08:00
Alex Zinenko 8fc3e5c488 [mlir] Format AffineOps.td. NFC
Drop trailing spaces and reflow text to fit 80 columns.
2020-03-03 21:30:17 +01:00
Jacques Pienaar 1bedb23407 [mlir][ods] Add query for derived attribute
For ODS generated operations enable querying whether there is a derived
attribute with a given name.

Rollforward of commit 5aa57c2 without using llvm::is_contained.
2020-03-03 12:04:16 -08:00
Alex Zinenko 8ba8ab8c95 [mlir] support reductions in loop to std conversion
Summary:
Introduce support for converting loop.for operations with loop-carried values
to a CFG in the standard dialect. This is achieved by passing loop-carried
values as block arguments to the loop condition block. This block dominates
both the loop body and the block immediately following the loop, so the
arguments of this block are remain visible there.

Differential Revision: https://reviews.llvm.org/D75513
2020-03-03 18:21:13 +01:00
Alex Zinenko d7fbfbb171 [mlir] ExecutionEngine: fix assertion on the error path
MLIR ExecutionEngine and derived tools (e.g., mlir-cpu-runner) would trigger an
assertion inside ORC JIT while ExecutionEngine is being destructed after a
failed linking due to a missing function definition. The reason for this is the
JIT lookup that may return an Error referring to strings stored internally by
the JIT. If the Error outlives the ExecutionEngine, it would want have a
dangling reference, which is currently caught by an assertion inside JIT thanks
to hand-rolled reference counting. Rewrap the error message into a string
before returning.

Differential Revision: https://reviews.llvm.org/D75508
2020-03-03 17:10:54 +01:00
Alex Zinenko efa2d53377 [mlir] error out on unsupported attribute kinds in LLVM global translation
Some attribute kinds are not supported as "value" attributes of
`llvm.mlir.constant` when translating to LLVM IR. We were correctly reporting
an error, but continuing the translation using an "undef" value instead,
leading to a surprising mix of error messages and output IR. Abort the
translation after the error is reported.

Differential Revision: https://reviews.llvm.org/D75450
2020-03-03 17:08:28 +01:00