Commit Graph

4396 Commits

Author SHA1 Message Date
River Riddle 56a698510f [mlir][Pass][NFC] Merge OpToOpPassAdaptor and OpToOpPassAdaptorParallel
This moves the threading check to runOnOperation. This produces a much cleaner interface for the adaptor pass, and will allow for the ability to enable/disable threading in a much cleaner way in the future.

Differential Revision: https://reviews.llvm.org/D78313
2020-04-29 15:23:10 -07:00
Jacques Pienaar 5439582781 Rename NamedAttributeList to MutableDictionaryAttr
Makes the relationship and function clearer. Accordingly rename getAttrList to getMutableAttrDict.

Differential Revision: https://reviews.llvm.org/D79125
2020-04-29 14:58:02 -07:00
Jacques Pienaar 87324ac33e [mlir] Extract DictionaryAttr sort method
Enable calling the sort, as expected by getWithSorted, into static member function so that callers can get same sorting behavior.

Differential Revision: https://reviews.llvm.org/D79011
2020-04-29 13:09:11 -07:00
MaheshRavishankar 1c12a95d9c [mlir][StandardToSPIRV] Handle conversion of cmpi operation with i1
type operands.

The instructions used to convert std.cmpi cannot have i1 types
according to SPIR-V specification. A different set of operations are
specified in the SPIR-V spec for comparing boolean types. Enhance the
StandardToSPIRV lowering to target these instructions when operands to
std.cmpi operation are of i1 type.

Differential Revision: https://reviews.llvm.org/D79049
2020-04-29 10:09:03 -07:00
Wen-Heng (Jack) Chung f2b505a459 [mlir][std] allow subview take memrefs from non-zero addrspaces.
On certain targets std.subview should be able to take memrefs from non-zero
addrspaces. Improve lowering logic to llvm dialect and amend the tests.

Differential Revision: https://reviews.llvm.org/D79024
2020-04-29 17:19:27 +02:00
Wen-Heng (Jack) Chung be16075bfc [mlir][vector] let transfer_read and transfer_write take non-zero addrspace.
Enhance lowering logic and tests so vector.transfer_read and
vector.transfer_write take memrefs on non-zero addrspaces.

Differential Revision: https://reviews.llvm.org/D79023
2020-04-29 17:11:48 +02:00
Uday Bondhugula 480345381a [MLIR] Introduce op trait PolyhedralScope (revised)
(A previous version of this, dd2c639c3c, was
reverted.)

Introduce op trait PolyhedralScope for ops to define a new scope for
polyhedral optimization / affine dialect purposes, thus generalizing
such scopes beyond FuncOp. Ops to which this trait is attached will
define a new scope for the consideration of SSA values as valid symbols
for the purposes of polyhedral analysis and optimization. Update methods
that check for dim/symbol validity to work based on this trait.

Differential Revision: https://reviews.llvm.org/D79060
2020-04-29 16:08:23 +05:30
Kazuaki Ishizaki b2f5fd84e8 [mlir] NFC: fix trivial typo
Differential Revision: https://reviews.llvm.org/D79065
2020-04-29 14:47:56 +09:00
Nicolas Vasilache 0c02106058 [mlir][EDSC] Retire OperationHandle
OperationHandle mostly existed to mirror the behavior of ValueHandle.
This has become unnecessary and can be retired.

Differential Revision: https://reviews.llvm.org/D78692
2020-04-29 00:32:44 -04:00
Sean Silva 9c9f479a7d Make ops with StructAttr's actually verify `isa<TheStruct>`.
Previously, they would only only verify `isa<DictionaryAttr>` on such attrs
which resulted in crashes down the line from code assuming that the
verifier was doing the more thorough check introduced in this patch.
The key change here is for StructAttr to use
`CPred<"$_self.isa<" # name # ">()">` instead of `isa<DictionaryAttr>`.

To test this, introduce struct attrs to the test dialect. Previously,
StructAttr was only being tested by unittests/, which didn't verify how
StructAttr interacted with ODS.

Differential Revision: https://reviews.llvm.org/D78975
2020-04-28 14:00:18 -07:00
Martin Erhart edb77864ef [mlir][assemblyFormat] Fix bug when using AttrSizedOperandSegments trait with only non-buildable operand types
Summary:
When creating an operation with
* `AttrSizedOperandSegments` trait
* Variadic operands of only non-buildable types
* assemblyFormat to automatically generate the parser
the `builder` local variable is used, but never declared.
This adds a fix as well as a test for this case as existing ones use buildable types only.

Reviewers: rriddle, Kayjukh, grosser

Reviewed By: Kayjukh

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

Tags: #mlir, #llvm

Differential Revision: https://reviews.llvm.org/D79004
2020-04-28 18:27:05 +02:00
Tres Popp f66c87637a [MLIR] Give AffineStoreOp and AffineLoadOp Memory SideEffects.
Summary:
This change results in tests also being changed to prevent dead
affine.load operations from being folded away during rewrites.

Also move AffineStoreOp and AffineLoadOp to an ODS file.

Differential Revision: https://reviews.llvm.org/D78930
2020-04-28 15:45:25 +02:00
Dmitri Gribenko ef06016d73 Revert "[MLIR] Introduce op trait PolyhedralScope"
This reverts commit dd2c639c3c. It broke a
few things -- the explanation will be posted to the review thread.
2020-04-28 14:50:57 +02:00
Alex Zinenko bb1d976feb [mlir][flang] use OpBuilder& instead of Builder* in <Op>::build methods
As we start defining more complex Ops, we increasingly see the need for
Ops-with-regions to be able to construct Ops within their regions in
their ::build methods. However, these methods only have access to
Builder, and not OpBuilder. Creating a local instance of OpBuilder
inside ::build and using it fails to trigger the operation creation
hooks in derived builders (e.g., ConversionPatternRewriter). In this
case, we risk breaking the logic of the derived builder. At the same
time, OpBuilder::create, which is by far the largest user of ::build
already passes "this" as the first argument, so an OpBuilder instance is
already available.

Update all ::build methods in all Ops in MLIR and Flang to take
"OpBuilder &" instead of "Builder *". Note the change from pointer and
to reference to comply with the common style in MLIR, this also ensures
all other users must change their ::build methods.

Differential Revision: https://reviews.llvm.org/D78713
2020-04-28 10:42:08 +02:00
Ehsan Toosi 5c352e69e7 Providing buffer assignment for MLIR
We have provided a generic buffer assignment transformation ported from
TensorFlow. This generic transformation pass automatically analyzes the values
and their aliases (also in other blocks) and returns the valid positions for
Alloc and Dealloc operations. To find these positions, the algorithm uses the
block Dominator and Post-Dominator analyses. In our proposed algorithm, we have
considered aliasing, liveness, nested regions, branches, conditional branches,
critical edges, and independency to custom block terminators. This
implementation doesn't support block loops. However, we have considered this in
our design. For this purpose, it is only required to have a loop analysis to
insert Alloc and Dealloc operations outside of these loops in some special
cases.

Differential Revision: https://reviews.llvm.org/D78484
2020-04-28 10:17:59 +02:00
Craig Topper a58b62b4a2 [IR] Replace all uses of CallBase::getCalledValue() with getCalledOperand().
This method has been commented as deprecated for a while. Remove
it and replace all uses with the equivalent getCalledOperand().

I also made a few cleanups in here. For example, to removes use
of getElementType on a pointer when we could just use getFunctionType
from the call.

Differential Revision: https://reviews.llvm.org/D78882
2020-04-27 22:17:03 -07:00
Uday Bondhugula dd2c639c3c [MLIR] Introduce op trait PolyhedralScope
Introduce op trait `PolyhedralScope` for ops to define a new scope for
polyhedral optimization / affine dialect purposes, thus generalizing
such scopes beyond FuncOp. Ops to which this trait is attached will
define a new scope for the consideration of SSA values as valid symbols
for the purposes of polyhedral analysis and optimization. Update methods
that check for dim/symbol validity to work based on this trait.

Differential Revision: https://reviews.llvm.org/D78863
2020-04-28 09:55:31 +05:30
Mehdi Amini f65a3f7c83 Make MLIR Pass Timing output configurable through injection
This makes it possible for the client to control where the pass timings will
be printed.

Differential Revision: https://reviews.llvm.org/D78891
2020-04-28 01:39:25 +00:00
River Riddle 6fab33b20a [mlir][LLVMDebugTranslation] Only insert the location mapping after translation
This fixes an iteration invalidation bug when the map grows beyond capacity and the iterator for the location to translate becomes invalid.
2020-04-27 16:49:18 -07:00
Phoenix Meadowlark 622aac6a0a Add a folder for division by one.
- Adds a folder for integer division by one with the `divi_signed` and `divi_unsigned` ops.
- Creates tests for scalar and tensor versions of these ops.
- Modifies the test in `parallel-loop-collapsing.mlir` so that it doesn't assume division by one will be in the output.

Differential Revision: https://reviews.llvm.org/D78518
2020-04-27 22:35:10 +00:00
Sean Silva 15fcdac498 Don't crash on duplicate keys in dictionary attrs.
Differential Revision: https://reviews.llvm.org/D78966
2020-04-27 15:23:49 -07:00
River Riddle a90151d67e [mlir][SCCP] Add support for propagating across symbol based calls
This revision adds support for propagating constants across symbol-based callgraph edges. It uses the existing Call/CallableOpInterfaces to detect the dataflow edges, and propagates constants through arguments and out of returns.

Differential Revision: https://reviews.llvm.org/D78592
2020-04-27 13:04:49 -07:00
River Riddle 7c221a7d4f [mlir][Symbol] Change Symbol from a Trait into an OpInterface.
This provides a much cleaner interface into Symbols, and allows for users to start injecting op-specific information. For example, derived op can now inject when a symbol can be discarded if use_empty. This would let us drop unused external functions, which generally have public visibility.

This revision also adds a new `extraTraitClassDeclaration` field to ODS OpInterface to allow for injecting declarations into the trait class that gets attached to the operations.

Differential Revision: https://reviews.llvm.org/D78522
2020-04-27 13:04:49 -07:00
Alexander Belyaev ed5363a674 [MLIR] Add getBody() method to SingleImplicitBlockTerminator op trait.
Many ops with this trait have `getBody()` and `getBodyBuilder()` methods defined in `extraClassDeclaration` in tablegen. `getBody()` implementation is the same accross all these ops, but `getBodyBuilder()` can return builders with varying insertion points set. In this PR, `getBody()` is moved into `SingleImplicitBlockTerminator` struct and `getBodyBuilder()` is replaced with `OpBuilder::atBlock(End|Terminator)(op.getBody);`.

Differential Revision: https://reviews.llvm.org/D78864
2020-04-27 21:48:52 +02:00
Lei Zhang 9fc51d23db [mlir][spirv] Fix SPIR-V translation registration
'From' and 'To' should be reversed. And now we must explicitly
call the registration function given that MLIR moved away from
static registration.

Differential Revision: https://reviews.llvm.org/D78934
2020-04-27 13:23:32 -04:00
Lei Zhang a5bfd32c07 [mlir][linalg] Fix crash in tileAndFuseLinalgOpToParallelLoopsAndSetMarker
Instead of using llvm_unreachable to guard against fusing linalg.conv,
reject fusing linalg.conv in isFusableInto.

tileLinalgOpImpl is a templated function now and it can operate on
loop.parellel. So we should avoid calling into getForInductionVarOwner
which always assumes loop.for.

Differential Revision: https://reviews.llvm.org/D78936
2020-04-27 13:21:07 -04:00
Lei Zhang f5b1301ce8 [mlir][doc] Add missing ` that breaks rendering 2020-04-27 11:25:32 -04:00
Nicolas Vasilache b2c79c50ed [mlir][VectorOps] Extend VectorTransfer lowering to n-D memref with minor identity map
Summary: This revision extends the lowering of vector transfers to work with n-D memref and 1-D vector where the permutation map is an identity on the most minor dimensions (1 for now).

Differential Revision: https://reviews.llvm.org/D78925
2020-04-27 11:20:55 -04:00
Tres Popp 9dc168b37c [MLIR][NFC] Organize the ordering in LLVM.h
Summary:
Order classes by purpose and alphabetically to make it slightly easier
to read through the file.

Reviewers: ftynse!

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

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D78914
2020-04-27 17:05:43 +02:00
Marcel Koester 8e640ca5a8 [mlir] Fixed warning related to unused variable in Liveness.
The latest changes of the Liveness analysis caused a warning related to an
unused variable. This commit solves this warning.

Differential Revision: https://reviews.llvm.org/D78912
2020-04-27 14:02:33 +02:00
Julian Gross 262108e12e [mlir] Extended Alloc and Dealloc operations with memory-effect traits.
Extended standard Alloc and Dealloc operations with memory-effect traits.

Differential Revision: https://reviews.llvm.org/D78619
2020-04-27 12:17:18 +02:00
Tres Popp 2d2d696137 [MLIR] Propagate input side effect information
Summary:
Previously operations like std.load created methods for obtaining their
effects but did not inherit from the SideEffect interfaces when their
parameters were decorated with the information. The resulting situation
was that passes had no information on the SideEffects of std.load/store
and had to treat them more cautiously. This adds the inheritance
information when creating the methods.

As a side effect, many tests are modified, as they were using std.load
for testing and this oepration would be folded away as part of pattern
rewriting. Tests are modified to use store or to reutn the result of the
std.load.

Reviewers: mravishankar, antiagainst, nicolasvasilache, herhut, aartbik, ftynse!

Subscribers: mehdi_amini, rriddle, jpienaar, shauheen, antiagainst, nicolasvasilache, csigg, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, bader, grosul1, frgossen, Kayjukh, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D78802
2020-04-27 11:35:52 +02:00
Tres Popp 49d8625aef [MLIR] Remove document references to gpu.kernel_module and gpu.kernel.
Summary:
These have been replaced from attributes to operations gpu.module and
gpu.func respectively.

Differential Revision: https://reviews.llvm.org/D78803
2020-04-27 10:00:15 +02:00
River Riddle 1956a8a7cb [mlir] Don't allocate an operand storage if the operation is known to never have operands
Certain classes of operations, such as FuncOp, are known to never have operands. This revision adds a bit to operation to detect this case and avoid allocating the unnecessary operand storage. This saves 1 word for each instance of these operations.

Differential Revision: https://reviews.llvm.org/D78876
2020-04-26 21:34:02 -07:00
River Riddle 4dfd1b5fcb [mlir] Optimize operand storage such that all operations can have resizable operand lists
This revision refactors the structure of the operand storage such that there is no additional memory cost for resizable operand lists until it is required. This is done by using two different internal representations for the operand storage:
* One using trailing operands
* One using a dynamically allocated std::vector<OpOperand>

This allows for removing the resizable operand list bit, and will free up APIs from needing to workaround non-resizable operand lists.

Differential Revision: https://reviews.llvm.org/D78875
2020-04-26 21:34:01 -07:00
River Riddle 8da0f85ea5 [mlir] Optimize the allocation of resizable operand lists
This revision optimizes resizable operand lists by allocating them in the same location as the trailing operands. This has numerous benefits:
* If the operation has at least one operand at construction time, there is 0 additional memory overhead to the resizable storage.
* There is less pointer arithmetic necessary as the resizable storage is now only used when the operands are dynamically allocated.

Differential Revision: https://reviews.llvm.org/D78854
2020-04-26 21:34:01 -07:00
River Riddle 910fff1c1d [mlir][DenseStringAttr] Fix support for splat detection and iteration
This revision also adds proper tests for splat detection.
2020-04-26 13:53:57 -07:00
Chris Lattner 969e7edd88 [SourceMgr/MLIR diagnostics] Introduce a new method to speed things up
Summary:
This introduces a new SourceMgr::FindLocForLineAndColumn method that
uses the OffsetCache in SourceMgr::SrcBuffer to do do a constant time
lookup for the line number (once the cache is populated).

Use this method in MLIR's SourceMgrDiagnosticHandler::convertLocToSMLoc,
replacing the O(n) scanning logic.  This resolves a long standing TODO
in MLIR, and makes one of my usecases go dramatically faster (which is
currently producing many diagnostics in a 40MB SourceBuffer).

NFC, this is just a performance speedup and cleanup.

Reviewers: rriddle!, ftynse!

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

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D78868
2020-04-25 14:06:44 -07:00
Benjamin Kramer a0a55b7903 Adjust namespace to make GCC 6 happy
LinalgOps.cpp:232:71: error: specialization of 'template<class GenericOpType> static mlir::LogicalResult {anonymous}::BlockArgsVerifier<GenericOpType>::verify(GenericOpType, mlir::Block&)' in different namespace [-fpermissive]
2020-04-25 22:43:17 +02:00
Alexander Belyaev f31db760b3 [MLIR] Replace splitBlock() with createBlock in GenericAtomicRMWOp lowering.
`addArgument()` is not undoable and should not be used in
ConversionPattern, therefore replacing `splitBlock()` with
`createBlock()`, that creates a block with specified args.

Differential Revision: https://reviews.llvm.org/D78731
2020-04-25 17:42:45 +02:00
Benjamin Kramer 1d42764df7 Give helpers internal linkage. NFC. 2020-04-25 11:50:52 +02:00
Rob Suderman 72af0bf176 Memory corruption issure for DenseStringElementsAttr
Summary: There was a memory corruption issue where the lifespan of the ArrayRef<StringRef> would fail. Directly passing the data will avoid the issue.

Reviewers: rriddle

Reviewed By: rriddle

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

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D78850
2020-04-25 01:23:43 -07:00
Rob Suderman fb674e3329 [mlir] Add support for sparse DenseStringElements.
Summary: Added support for sparse strings elements. This is a follow up from the original DenseStringElements.

Differential Revision: https://reviews.llvm.org/D78844
2020-04-25 01:21:40 -07:00
Uday Bondhugula 81bed2a9a2 [MLIR]][DOC] Fix dimension validity constraint in affine dialect doc
Fix affine dialect documentation on valid dimensional values: they also
include affine.parallel IVs.

Differential Revision: https://reviews.llvm.org/D78855
2020-04-25 12:22:39 +05:30
Stella Laurenzo 485cf19651 Define SDBM key methods in its own cpp file.
Summary:
* Follows the convention of the tablegen-generated dialects.
* Ensures that vague linkage rules place the definitions in the dialect's object files.
* Allows code that uses RTTI to include MLIR headers (compiled without RTTI) without
  type_info link errors.

Reviewers: rriddle

Reviewed By: rriddle

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

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D78039
2020-04-24 19:05:55 -07:00
Sean Silva 57a7cd7a13 [shape] Add inferReturnTypes to a couple ops.
- ShapeOfOp
- BroadcastOp

Differential Revision: https://reviews.llvm.org/D78822
2020-04-24 16:10:20 -07:00
Sean Silva 5fff169daa [shape] More constant folding
- shape split_at
- shape.broadcast
- shape.concat
- shape.to_extent_tensor

Differential Revision: https://reviews.llvm.org/D78821
2020-04-24 16:10:19 -07:00
Sean Silva d1ad267a56 [shape] Basic constant folding.
- Implement a first constant fold for shape.shape_of (more ops coming in subsequent patches)
- Implement the right builder interfaces for ShapeType and other types
- Splits shape.constant into shape.const_size and shape.const_shape which plays better with dyn_cast and building vs one polymorphic op.

Also, fix the RUN line in ops.mlir to properly verify round-tripping.
2020-04-24 15:49:35 -07:00
Stephen Neuendorffer fef4ddf2f4 [MLIR] Fix typo in lib/Interfaces
This broke BUILD_SHARED_LIBS=on
2020-04-24 15:39:19 -07:00
River Riddle 0816de167a [mlir][DialectConversion] Add support for properly tracking replaceUsesOfBlockArgument
The current implementation of this method performs the replacement directly, and thus doesn't support proper back tracking.

Differential Revision: https://reviews.llvm.org/D78790
2020-04-24 12:37:32 -07:00