platform/upstream/llvm.git
4 years agoAdds support for unrolling single-result vector operations with iterator type lists...
Andy Davis [Wed, 4 Dec 2019 14:53:07 +0000 (06:53 -0800)]
Adds support for unrolling single-result vector operations with iterator type lists and indexing maps to a target vector size.
Adds unit tests for unrolling the vector ContractionOp with different iteration orders.

PiperOrigin-RevId: 283747503

4 years agominor spelling tweaks
Kazuaki Ishizaki [Wed, 4 Dec 2019 12:58:12 +0000 (04:58 -0800)]
minor spelling tweaks

Closes tensorflow/mlir#250

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/250 from kiszk:spelling_tweaks_201911 50fc04443723190b764e824b6fcd2469fecb56e6
PiperOrigin-RevId: 283733032

4 years agoAvoid variable name conflict in MLIR tutorial code snippet
Smit Hinsu [Wed, 4 Dec 2019 05:25:02 +0000 (21:25 -0800)]
Avoid variable name conflict in MLIR tutorial code snippet

PiperOrigin-RevId: 283682865

4 years agoRefactor dependencies to expose Vector transformations as patterns - NFC
Nicolas Vasilache [Wed, 4 Dec 2019 01:51:34 +0000 (17:51 -0800)]
Refactor dependencies to expose Vector transformations as patterns - NFC

This CL refactors some of the MLIR vector dependencies to allow decoupling VectorOps, vector analysis, vector transformations and vector conversions from each other.
This makes the system more modular and allows extracting VectorToVector into VectorTransforms that do not depend on vector conversions.

This refactoring exhibited a bunch of cyclic library dependencies that have been cleaned up.

PiperOrigin-RevId: 283660308

4 years ago[spirv] Add spv.GroupNonUniformBallot
Lei Zhang [Wed, 4 Dec 2019 00:43:40 +0000 (16:43 -0800)]
[spirv] Add spv.GroupNonUniformBallot

This CL also did the following cleanup:
- Moved the test for spv.SubgroupBallotKHR to its own file
- Wrapped generated canonicalization patterns in anonymous namespace
- Updated header comments in SPVOps.td

PiperOrigin-RevId: 283650091

4 years agoAdd a pass to legalize operations before lowering to SPIR-V.
Mahesh Ravishankar [Wed, 4 Dec 2019 00:05:46 +0000 (16:05 -0800)]
Add a pass to legalize operations before lowering to SPIR-V.

Not all StandardOps can be lowered to SPIR-V. For example, subview op
implementation requires use of pointer bitcasts which is not valid
according to SPIR-V spec (or at least is ambiguous about it). Such ops
need to be removed/transformed before lowering to SPIR-V. The
SPIRVLegalizationPass is added a place where such legalizations can be
added. Current implementation folds the subview ops with load/stores
so that the lowering itself does not have to convert a subview op.

PiperOrigin-RevId: 283642981

4 years agoMake diagnostic a bit clearer.
Sean Silva [Tue, 3 Dec 2019 22:00:36 +0000 (14:00 -0800)]
Make diagnostic a bit clearer.

This prints out in case of any pass failure. Not just a crash.

PiperOrigin-RevId: 283616719

4 years agoAdd CreateMaskOp to the VectorOps dialect.
Andy Davis [Tue, 3 Dec 2019 19:55:09 +0000 (11:55 -0800)]
Add CreateMaskOp to the VectorOps dialect.

PiperOrigin-RevId: 283591888

4 years agoVerifier: Better error message in case of successor operand mismatch.
Sean Silva [Tue, 3 Dec 2019 19:23:48 +0000 (11:23 -0800)]
Verifier: Better error message in case of successor operand mismatch.

In particular, print the successor number in the diagnostic.

PiperOrigin-RevId: 283585084

4 years agoAllow analyses to provide a hook 'isInvalidated' to determine if they are truly inval...
River Riddle [Tue, 3 Dec 2019 19:13:39 +0000 (11:13 -0800)]
Allow analyses to provide a hook 'isInvalidated' to determine if they are truly invalidated.

The hook has the following form:
*   `bool isInvalidated(const AnalysisManager::PreservedAnalyses &)`

Given a preserved analysis set, the analysis returns true if it should truly be
invalidated. This allows for more fine-tuned invalidation in cases where an
analysis wasn't explicitly marked preserved, but may be preserved(or
invalidated) based upon other properties; such as analyses sets.

PiperOrigin-RevId: 283582889

4 years agoConvert MemRefType to a linearized array in SPIR-V lowering.
Mahesh Ravishankar [Tue, 3 Dec 2019 18:20:37 +0000 (10:20 -0800)]
Convert MemRefType to a linearized array in SPIR-V lowering.

The SPIR-V lowering used nested !spv.arrays to represented
multi-dimensional arrays, with the hope that in-conjunction with the
layout annotations, the shape and layout of memref can be represented
directly. It is unclear though how portable this representation will
end up being. It will rely on driver compilers implementing complex
index computations faithfully. A more portable approach is to use
linearized arrays to represent memrefs and explicitly instantiate all
the index computation in SPIR-V. This gives added benefit that we can
further optimize the generated code in MLIR before generating the
SPIR-V binary.

PiperOrigin-RevId: 283571167

4 years agoAdd Python bindings for affine expressions with binary operators.
MLIR Team [Tue, 3 Dec 2019 18:11:40 +0000 (10:11 -0800)]
Add Python bindings for affine expressions with binary operators.

PiperOrigin-RevId: 283569325

4 years agoAdd python bindings for ArrayAttr, AffineMapAttr.
MLIR Team [Tue, 3 Dec 2019 17:32:16 +0000 (09:32 -0800)]
Add python bindings for ArrayAttr, AffineMapAttr.

PiperOrigin-RevId: 283561252

4 years agoFix ViewOp to have at most one offset operand
Alex Zinenko [Tue, 3 Dec 2019 14:22:31 +0000 (06:22 -0800)]
Fix ViewOp to have at most one offset operand

As described in the documentation, ViewOp is expected to take an optional
dynamic offset followed by a list of dynamic sizes. However, the ViewOp parser
did not include a check for the offset being a single value and accepeted a
list of values instead.

Furthermore, several tests have been exercising the wrong syntax of a ViewOp,
passing multiple values to the dyanmic stride list, which was not caught by the
parser. The trailing values could have been erronously interpreted as dynamic
sizes. This is likely due to resyntaxing of the ViewOp, with the previous
syntax taking the list of sizes before the offset. Update the tests to use the
syntax with the offset preceding the sizes.

Worse, the conversion of ViewOp to the LLVM dialect assumed the wrong order of
operands with offset in the trailing position, and erronously relied on the
permissive parsing that interpreted trailing dynamic offset values as leading
dynamic sizes. Fix the lowering to use the correct order of operands.

PiperOrigin-RevId: 283532506

4 years agoAffineLoopFusion: Prevent fusion of multi-out-edge producer loops
Diego Caballero [Tue, 3 Dec 2019 14:09:21 +0000 (06:09 -0800)]
AffineLoopFusion: Prevent fusion of multi-out-edge producer loops

tensorflow/mlir#162 introduced a bug that
incorrectly allowed fusion of producer loops with multiple outgoing
edges. This commit fixes that problem. It also introduces a new flag to
disable sibling loop fusion so that we can test producer-consumer fusion
in isolation.

Closes tensorflow/mlir#259

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/259 from dcaballe:dcaballe/fix_multi_out_edge_producer_fusion 578d5661705fd5c56c555832d5e0528df88c5282
PiperOrigin-RevId: 283531105

4 years agoExtend conversion of SubViewOp to llvm to also support cases where size and stride
Stephan Herhut [Tue, 3 Dec 2019 13:11:20 +0000 (05:11 -0800)]
Extend conversion of SubViewOp to llvm to also support cases where size and stride
are constant (i.e., there are no size and stride operands).

We recently added canonicalization that rewrites constant size and stride operands to
SubViewOp into static information in the type, so these patterns now occur during code
generation.

PiperOrigin-RevId: 283524688

4 years ago[spirv] Add spv.SubgroupBallotKHROp
Lei Zhang [Tue, 3 Dec 2019 12:49:20 +0000 (04:49 -0800)]
[spirv] Add spv.SubgroupBallotKHROp

PiperOrigin-RevId: 283522284

4 years ago[Linalg] Update/fix documentation for linalg.indexed_generic.
Alexander Belyaev [Tue, 3 Dec 2019 09:55:18 +0000 (01:55 -0800)]
[Linalg] Update/fix documentation for linalg.indexed_generic.

PiperOrigin-RevId: 283503642

4 years agoAdd linkage support to LLVMFuncOp
Alex Zinenko [Tue, 3 Dec 2019 08:26:13 +0000 (00:26 -0800)]
Add linkage support to LLVMFuncOp

A recent commit introduced the Linkage attribute to the LLVM dialect and used
it in the Global Op. Also use it in LLVMFuncOp. As per LLVM Language Reference,
if the linkage attribute is omitted, the function is assumed to have external
linkage.

PiperOrigin-RevId: 283493299

4 years ago[spirv] NFC: reorder sections in SPIRVBase.td
Lei Zhang [Mon, 2 Dec 2019 22:21:42 +0000 (14:21 -0800)]
[spirv] NFC: reorder sections in SPIRVBase.td

Put extensions and capabilities at the very beginning because
they will be referenced later by other definitions.

PiperOrigin-RevId: 283416972

4 years agoNFC: use `&&` instead of `and`
Lei Zhang [Mon, 2 Dec 2019 20:26:34 +0000 (12:26 -0800)]
NFC: use `&&` instead of `and`
PiperOrigin-RevId: 283392575

4 years ago[VectorOps] Add legality rules to broadcast
Aart Bik [Mon, 2 Dec 2019 17:56:58 +0000 (09:56 -0800)]
[VectorOps] Add legality rules to broadcast

PiperOrigin-RevId: 283360101

4 years ago[ODS] Generate builders taking unwrapped value and defaults for attributes
Lei Zhang [Mon, 2 Dec 2019 17:33:24 +0000 (09:33 -0800)]
[ODS] Generate builders taking unwrapped value and defaults for attributes

Existing builders generated by ODS require attributes to be passed
in as mlir::Attribute or its subclasses. This is okay foraggregate-
parameter builders, which is primarily to be used by programmatic
C++ code generation; it is inconvenient for separate-parameter
builders meant to be called in manually written C++ code because
it requires developers to wrap raw values into mlir::Attribute by
themselves.

This CL extends to generate additional builder methods that
take raw values for attributes and handles the wrapping in the
builder implementation. Additionally, if an attribute appears
late in the arguments list and has a default value, the default
value is supplied in the declaration if possible.

PiperOrigin-RevId: 283355919

4 years agoGenerate dialect documentations in the doc folder for every dialect
Mehdi Amini [Mon, 2 Dec 2019 17:17:51 +0000 (09:17 -0800)]
Generate dialect documentations in the doc folder for every dialect

Also add a mlir-doc build target to general all the docs

PiperOrigin-RevId: 283353529

4 years agodocs: minor spelling tweaks
brett koonce [Mon, 2 Dec 2019 17:12:48 +0000 (09:12 -0800)]
docs: minor spelling tweaks

Closes tensorflow/mlir#262

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/262 from brettkoonce:docs-sp 6833fc8aa41edd02d8bc7c3cbb84211cb8b0334c
PiperOrigin-RevId: 283352765

4 years agoAdd missing `>` to the description of std.view.
Denis Khalikov [Mon, 2 Dec 2019 15:58:38 +0000 (07:58 -0800)]
Add missing `>` to the description of std.view.

Closes tensorflow/mlir#266

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/266 from denis0x0D:sandbox/miss_char a5f662e1bf103b5009da67d045ee2fcebf822ab0
PiperOrigin-RevId: 283340486

4 years ago[DRR] Introduce `$_` to ignore op argument match
Lei Zhang [Mon, 2 Dec 2019 15:54:23 +0000 (07:54 -0800)]
[DRR] Introduce `$_` to ignore op argument match

Right now op argument matching in DRR is position-based, meaning we need to
specify N arguments for an op with N ODS-declared argument. This can be annoying
when we don't want to capture all the arguments. `$_` is to remedy the situation.

PiperOrigin-RevId: 283339992

4 years agoNFC: Update std.subview op to use AttrSizedOperandSegments
Lei Zhang [Mon, 2 Dec 2019 15:51:27 +0000 (07:51 -0800)]
NFC: Update std.subview op to use AttrSizedOperandSegments

This turns a few manually written helper methods into auto-generated ones.

PiperOrigin-RevId: 283339617

4 years agoadd missing '>' in Ch-2
JKIsaacLee [Mon, 2 Dec 2019 15:08:31 +0000 (07:08 -0800)]
add missing '>' in Ch-2

add missing '>' in Ch-2
(tensor<2x3xf64)->(tensor<2x3xf64>)

Closes tensorflow/mlir#283

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/283 from JKIsaacLee:patch-1 b69fe8d51e2a540f7efaded159d35b88778ad159
PiperOrigin-RevId: 283333807

4 years agoLower linalg.indexed_generic with libcall to LLVM.
Alexander Belyaev [Mon, 2 Dec 2019 14:30:19 +0000 (06:30 -0800)]
Lower linalg.indexed_generic with libcall to LLVM.

PiperOrigin-RevId: 283328994

4 years agoIntroduce Linkage attribute to the LLVM dialect
Alex Zinenko [Mon, 2 Dec 2019 11:27:38 +0000 (03:27 -0800)]
Introduce Linkage attribute to the LLVM dialect

LLVM IR supports linkage on global objects such as global variables and
functions. Introduce the Linkage attribute into the LLVM dialect, backed by an
integer storage. Use this attribute on LLVM::GlobalOp and make it mandatory.
Implement parsing/printing of the attribute and conversion to LLVM IR.

See tensorflow/mlir#277.

PiperOrigin-RevId: 283309328

4 years agomlir-tblgen: Dump input records when no generator is set
Jacques Pienaar [Fri, 29 Nov 2019 18:43:24 +0000 (10:43 -0800)]
mlir-tblgen: Dump input records when no generator is set

Follow LLVM's tblgen convention when no generator is set instead of asserting.

PiperOrigin-RevId: 283073690

4 years agoFix redundant convert and use NamedAttributeList as value
Jacques Pienaar [Fri, 29 Nov 2019 18:26:23 +0000 (10:26 -0800)]
Fix redundant convert and use NamedAttributeList as value

* Had leftover call that would result in converting to dictionary attr before
  being implicitedly converted back to NamedAttributeList;
* NamedAttributeList is value typed, so don't use const reference;

PiperOrigin-RevId: 283072576

4 years agoFixed typo in Ch-1 of Toy tutorial
JKIsaacLee [Fri, 29 Nov 2019 16:48:22 +0000 (08:48 -0800)]
Fixed typo in Ch-1 of Toy tutorial

Closes tensorflow/mlir#282

PiperOrigin-RevId: 283064785

4 years ago[spirv] Check that operand of `spirv::CompositeExtractOp` is constant while folding.
Denis Khalikov [Thu, 28 Nov 2019 21:27:26 +0000 (13:27 -0800)]
[spirv] Check that operand of `spirv::CompositeExtractOp` is constant while folding.

Closes tensorflow/mlir#281

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/281 from denis0x0D:sandbox/composite_ex_fold d02d73658bd1b9eaa515eb4e0aee34bc41d4252b
PiperOrigin-RevId: 282971563

4 years agoSplit out FunctionLike printing/parsing into FunctionImplementation.{h,cpp}
Alex Zinenko [Thu, 28 Nov 2019 19:50:47 +0000 (11:50 -0800)]
Split out FunctionLike printing/parsing into FunctionImplementation.{h,cpp}

Helper utilies for parsing and printing FunctionLike Ops are only relevant to
the implementation of the Op, not its definition. They depend on
OpImplementation.h and increase the inclusion footprint of FunctionSupport.h,
and do so only to provide some utilities in the "impl" namespace. Move them to
a separate files, similarly to OpDefinition/OpImplementation distinction, and
make only Op implementations use them while keeping headers cleaner. NFC.

PiperOrigin-RevId: 282964556

4 years ago[Linalg] Change attribute n_loop_types to iterator
Jose Ignacio Gomez [Thu, 28 Nov 2019 09:59:22 +0000 (01:59 -0800)]
[Linalg] Change attribute n_loop_types to iterator

This addresses issue tensorflow/mlir#270. Linalg is updated to take the same form
of iterator_types than vector contraction.

Closes tensorflow/mlir#280

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/280 from tetuante:PRissue270 d26d88d090d3765d3b9884bfabdd023143f27287
PiperOrigin-RevId: 282905396

4 years agoNFC: A few cleanups for SPIRVLowering
Lei Zhang [Wed, 27 Nov 2019 23:55:07 +0000 (15:55 -0800)]
NFC: A few cleanups for SPIRVLowering

Updated comments and used static instead of anonymous namspace
to hide functions to be consistent with the existing codebase.

PiperOrigin-RevId: 282847784

4 years ago[spirv] NFC: Add getZero() and getOne() static method to ConstantOp
Lei Zhang [Wed, 27 Nov 2019 22:12:32 +0000 (14:12 -0800)]
[spirv] NFC: Add getZero() and getOne() static method to ConstantOp

Getting constant zero or one is very common so it merits a special handy
method on spirv::ConstantOp itself.

PiperOrigin-RevId: 282832572

4 years ago[spirv] Add folders for spv.IAdd and spv.IMul
Lei Zhang [Wed, 27 Nov 2019 21:46:20 +0000 (13:46 -0800)]
[spirv] Add folders for spv.IAdd and spv.IMul

Adding zero and multiplying one can be common when generating code
for index calculation.

This CL also sorted canonicalize.mlir to alphabetical order.

PiperOrigin-RevId: 282828055

4 years agoFixed typo in Toy tutorial (second var e -> var f)
Aart Bik [Wed, 27 Nov 2019 19:58:08 +0000 (11:58 -0800)]
Fixed typo in Toy tutorial (second var e -> var f)

PiperOrigin-RevId: 282810649

4 years agoImplement Linalg to loops lowering as a pattern
Nicolas Vasilache [Wed, 27 Nov 2019 15:31:41 +0000 (07:31 -0800)]
Implement Linalg to loops lowering as a pattern

This CL rewrites the linalg ops to loops transformations as patterns that can be targeted directly from Tablegen. Reliance on OpFolder is removed and to cope with it we introduce local folding patterns that are applied greedily.

PiperOrigin-RevId: 282765550

4 years ago[VectorOps] Refine BroadcastOp in VectorOps dialect
Aart Bik [Wed, 27 Nov 2019 03:52:02 +0000 (19:52 -0800)]
[VectorOps] Refine BroadcastOp in VectorOps dialect

Since second argument is always fully overwritten and
shape is define in "to" clause, it is not needed.
Also renamed "into" to "to" now that arg is dropped.

PiperOrigin-RevId: 282686475

4 years agoAdd create method that takes equivalent of OperationState with NamedAttributeList
Jacques Pienaar [Tue, 26 Nov 2019 23:30:04 +0000 (15:30 -0800)]
Add create method that takes equivalent of OperationState with NamedAttributeList

This method is close to creating an OperationState first and then unpacking it
but avoids creating the OperationState and takes a NamedAttributeList for
attributes rather than array of NamedAttribute (to enable reusing an already
created NamedAttributeList).

Reuse this new method via create that takes OperationState. I'll update inferReturnTypes in follow up to also take NamedAttributeList and so a build method that uses both inferReturnTypes and create can reuse the same list.

PiperOrigin-RevId: 282651642

4 years ago[VectorOps] Add a BroadcastOp to the VectorOps dialect
Aart Bik [Tue, 26 Nov 2019 22:43:03 +0000 (14:43 -0800)]
[VectorOps] Add a BroadcastOp to the VectorOps dialect

PiperOrigin-RevId: 282643305

4 years agoAdd OpenMP dialect to the dialect registry
David Truby [Tue, 26 Nov 2019 19:37:46 +0000 (11:37 -0800)]
Add OpenMP dialect to the dialect registry

Closes tensorflow/mlir#244

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/244 from DavidTruby:openmp 30e2638ee678188575dd5aeb3f7fa51d93369f5f
PiperOrigin-RevId: 282607397

4 years agoMisc changes to lowering to SPIR-V.
Mahesh Ravishankar [Tue, 26 Nov 2019 18:10:59 +0000 (10:10 -0800)]
Misc changes to lowering to SPIR-V.

These changes to SPIR-V lowering while adding support for lowering
SUbViewOp, but are not directly related.
- Change the lowering of MemRefType to
  !spv.ptr<!spv.struct<!spv.array<...>[offset]>, ..>
  This is consistent with the Vulkan spec.
- To enable testing a simple pattern of lowering functions is added to
  ConvertStandardToSPIRVPass. This is just used to convert the type of
  the arguments of the function. The added function lowering itself is
  not meant to be the way functions are eventually lowered into SPIR-V
  dialect.

PiperOrigin-RevId: 282589644

4 years agoAutomated rollback of commit d60133f89bb08341718bb3132b19bc891f7d4f4d
Nicolas Vasilache [Tue, 26 Nov 2019 16:47:14 +0000 (08:47 -0800)]
Automated rollback of commit d60133f89bb08341718bb3132b19bc891f7d4f4d

PiperOrigin-RevId: 282574110

4 years agoRelax restriction on affine_apply dim and symbol operands
Nicolas Vasilache [Tue, 26 Nov 2019 15:38:33 +0000 (07:38 -0800)]
Relax restriction on affine_apply dim and symbol operands

The affine_apply operation is currently "doubly" affine and conflates two things:
1. it applies an affine map to a list of values of type `index` that are defined as either dim or symbol
2. it restricts (and propagates constraints on) the provenance of dims and symbols to a small subset of ops for which more restrictive polyhedral constraints apply.

Point 2. is related to the ability to form so-called static control parts and is related to dependence analysis and legality of transformations.

Point 1. however is completely independent, the only local implication of dims and symbol for affine_apply is that dims compose while symbols concatenate as well as the structural constraint that dims may not be multiplied.

The properties of composition and canonicalization in affine_apply are more generally useful. This CL relaxes the verifier on affine_apply so it can be used more generally.

The relevant affine.for/if/load/store op verifiers already implement the dim and symbol checking.

See this thread for the related discussion: https://groups.google.com/a/tensorflow.org/g/mlir/c/HkwCbV8D9N0/m/8srUNrX6CAAJ

PiperOrigin-RevId: 282562517

4 years agoSome minor corrections and improvements to LangRef
Andrew Anderson [Tue, 26 Nov 2019 01:53:20 +0000 (17:53 -0800)]
Some minor corrections and improvements to LangRef

Some productions in the LangRef were using undefined terminals and non-terminals, which have been added to the EBNF.
The dialect type and dialect attribute productions matched precisely the same structure and have been deduplicated.
The production for ssa-id was ambiguous but the fix is trivial (merging the leading '%') and has been applied.

Closes tensorflow/mlir#265

PiperOrigin-RevId: 282470892

4 years agoAdd support for AttrSizedOperandSegments/AttrSizedResultSegments
Lei Zhang [Tue, 26 Nov 2019 01:26:16 +0000 (17:26 -0800)]
Add support for AttrSizedOperandSegments/AttrSizedResultSegments

Certain operations can have multiple variadic operands and their size
relationship is not always known statically. For such cases, we need
a per-op-instance specification to divide the operands into logical
groups or segments. This can be modeled by attributes.

This CL introduces C++ trait AttrSizedOperandSegments for operands and
AttrSizedResultSegments for results. The C++ trait just guarantees
such size attribute has the correct type (1D vector) and values
(non-negative), etc. It serves as the basis for ODS sugaring that
with ODS argument declarations we can further verify the number of
elements match the number of ODS-declared operands and we can generate
handy getter methods.

PiperOrigin-RevId: 282467075

4 years agoUse vector.InsertStridedSlice in Vector -> Vector unrolling
Nicolas Vasilache [Mon, 25 Nov 2019 23:56:06 +0000 (15:56 -0800)]
Use vector.InsertStridedSlice in Vector -> Vector unrolling

This CL uses the recently added op to finish the implementation of Vector -> Vector unrolling by replacing the "fake join op" by a series of InsertStridedSliceOp.

Test is updated accordingly

PiperOrigin-RevId: 282451126

4 years agoAdd a vector.InsertStridedSliceOp
Nicolas Vasilache [Mon, 25 Nov 2019 23:36:45 +0000 (15:36 -0800)]
Add a vector.InsertStridedSliceOp

This new op is the counterpart of vector.StridedSliceOp and will be used for in the pattern rewrites for vector unrolling.

PiperOrigin-RevId: 282447414

4 years agoAllow LLVM::ExtractElementOp to have non-i32 indices.
MLIR Team [Mon, 25 Nov 2019 22:44:20 +0000 (14:44 -0800)]
Allow LLVM::ExtractElementOp to have non-i32 indices.

Also change the text format a bit, so that indices are braced by squares.

PiperOrigin-RevId: 282437095

4 years agoMake std.divis and std.diviu support ElementsAttr folding.
Ben Vanik [Mon, 25 Nov 2019 22:31:12 +0000 (14:31 -0800)]
Make std.divis and std.diviu support ElementsAttr folding.

PiperOrigin-RevId: 282434465

4 years agoNFC: Actually expose the implementation of createGPUToSPIRVLoweringPass.
Mahesh Ravishankar [Mon, 25 Nov 2019 21:19:19 +0000 (13:19 -0800)]
NFC: Actually expose the implementation of createGPUToSPIRVLoweringPass.

A mismatch in the function declaration and function definition,
prevented the implementation of the createGPUToSPIRVLoweringPass from
being exposed.

PiperOrigin-RevId: 282419815

4 years agoAdd missing rule to generate SPIR-V ABI Attribute using tblgen to CMake.
Mahesh Ravishankar [Mon, 25 Nov 2019 20:56:46 +0000 (12:56 -0800)]
Add missing rule to generate SPIR-V ABI Attribute using tblgen to CMake.

PiperOrigin-RevId: 282415592

4 years agoUpdate VectorContractionOp to take iterator types and index mapping attributes compat...
Andy Davis [Mon, 25 Nov 2019 20:39:30 +0000 (12:39 -0800)]
Update VectorContractionOp to take iterator types and index mapping attributes compatible with linalg ops.

PiperOrigin-RevId: 282412311

4 years agoChanging directory shortcut for CPU/GPU runner utils.
Christian Sigg [Mon, 25 Nov 2019 20:30:22 +0000 (12:30 -0800)]
Changing directory shortcut for CPU/GPU runner utils.

Moving cuda-runtime-wrappers.so into subdirectory to match libmlir_runner_utils.so.
Provide parent directory when running test and load .so from subdirectory.

PiperOrigin-RevId: 282410749

4 years agoDe-duplicate EnumAttr overrides by defining defaults
Lei Zhang [Mon, 25 Nov 2019 19:29:21 +0000 (11:29 -0800)]
De-duplicate EnumAttr overrides by defining defaults

EnumAttr should provide meaningful defaults so concrete instances
do not need to duplicate the fields.

PiperOrigin-RevId: 282398431

4 years agoIntroduce attributes that specify the final ABI for a spirv::ModuleOp.
Mahesh Ravishankar [Mon, 25 Nov 2019 18:38:31 +0000 (10:38 -0800)]
Introduce attributes that specify the final ABI for a spirv::ModuleOp.

To simplify the lowering into SPIR-V, while still respecting the ABI
requirements of SPIR-V/Vulkan, split the process into two
1) While lowering a function to SPIR-V (when the function is an entry
   point function), allow specifying attributes on arguments and
   function itself that describe the ABI of the function.
2) Add a pass that materializes the ABI described in the function.

Two attributes are needed.
1) Attribute on arguments of the entry point function that describe
   the descriptor_set, binding, storage class, etc, of the
   spv.globalVariable this argument will be replaced by
2) Attribute on function that specifies workgroup size, etc. (for now
   only workgroup size).

Add the pass -spirv-lower-abi-attrs to materialize the ABI described
by the attributes.

This change makes the SPIRVBasicTypeConverter class unnecessary and is
removed, further simplifying the SPIR-V lowering path.

PiperOrigin-RevId: 282387587

4 years agoAllow memref_cast from static strides to dynamic strides.
Mahesh Ravishankar [Mon, 25 Nov 2019 18:10:58 +0000 (10:10 -0800)]
Allow memref_cast from static strides to dynamic strides.

Memref_cast supports cast from static shape to dynamic shape
memrefs. The same should be true for strides as well, i.e a memref
with static strides can be casted to a memref with dynamic strides.

PiperOrigin-RevId: 282381862

4 years agoAdd vector.insertelement op
Nicolas Vasilache [Mon, 25 Nov 2019 16:46:37 +0000 (08:46 -0800)]
Add vector.insertelement op

This is the counterpart of vector.extractelement op and has the same
limitations at the moment (static I64IntegerArrayAttr to express position).
This restriction will be filterd in the future.
LLVM lowering will be added in a subsequent commit.

PiperOrigin-RevId: 282365760

4 years agoIntroduce gpu.func
Alex Zinenko [Mon, 25 Nov 2019 15:59:52 +0000 (07:59 -0800)]
Introduce gpu.func

Introduce a new function-like operation to the GPU dialect to provide a
placeholder for the execution semantic description and to add support for GPU
memory hierarchy.  This aligns with the overall goal of the dialect to expose
the common abstraction layer for GPU devices, in particular by providing an
MLIR unit of semantics (i.e. an operation) for memory modeling.

This proposal has been discussed in the mailing list:
https://groups.google.com/a/tensorflow.org/d/msg/mlir/RfXNP7Hklsc/MBNN7KhjAgAJ
As decided, the "convergence" aspect of the execution model will be factored
out into a new discussion and therefore is not included in this commit. This
commit only introduces the operation but does not hook it up with the remaining
flow. The intention is to develop the new flow while keeping the old flow
operational and do the switch in a simple, separately reversible commit.

PiperOrigin-RevId: 282357599

4 years agoSupport folding of StandardOps with DenseElementsAttr.
Ben Vanik [Mon, 25 Nov 2019 02:50:54 +0000 (18:50 -0800)]
Support folding of StandardOps with DenseElementsAttr.

PiperOrigin-RevId: 282270243

4 years agoNFC: Wire up DRR settings for SPIR-V canonicalization patterns
Lei Zhang [Sat, 23 Nov 2019 14:08:50 +0000 (06:08 -0800)]
NFC: Wire up DRR settings for SPIR-V canonicalization patterns

This CL added necessary files and settings for using DRR to
write SPIR-V canonicalization patterns and also converted the
patterns for spv.Bitcast and spv.LogicalNot.

PiperOrigin-RevId: 282132786

4 years ago[spirv] NFC: rename test files and sort tests inside
Lei Zhang [Sat, 23 Nov 2019 14:03:40 +0000 (06:03 -0800)]
[spirv] NFC: rename test files and sort tests inside

PiperOrigin-RevId: 282132339

4 years agoMake isValidSymbol more powerful
Uday Bondhugula [Sat, 23 Nov 2019 05:47:47 +0000 (21:47 -0800)]
Make isValidSymbol more powerful

The check in isValidSymbol, as far as a DimOp result went, checked if
the dim op was on a top-level memref. However, any alloc'ed, view, or
subview memref would be fine as long as the corresponding dimension of
that memref is either a static one or was in turn created using a valid
symbol in the case of dynamic dimensions.

Reported-by: Jose Gomez
Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>
Closes tensorflow/mlir#252

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/252 from bondhugula:symbol 7b57dc394df9375e651f497231c6e4525a32a662
PiperOrigin-RevId: 282097114

4 years agoNFC: Remove unnecessarily guarded tablegen includes.
River Riddle [Sat, 23 Nov 2019 01:51:23 +0000 (17:51 -0800)]
NFC: Remove unnecessarily guarded tablegen includes.

Support for including a file multiple times was added in tablegen, removing the need for these extra guards. This is because we already insert c/c++ style header guards within each of the specific .td files.

PiperOrigin-RevId: 282076728

4 years agoFix Windows Build
Nicolas Vasilache [Fri, 22 Nov 2019 22:56:36 +0000 (14:56 -0800)]
Fix Windows Build

PiperOrigin-RevId: 282048102

4 years ago[spirv] Add a canonicalizer for `spirv::LogicalNotOp`.
Denis Khalikov [Fri, 22 Nov 2019 19:49:22 +0000 (11:49 -0800)]
[spirv] Add a canonicalizer for `spirv::LogicalNotOp`.

Add a canonicalizer for `spirv::LogicalNotOp`.
Converts:
* spv.LogicalNot(spv.IEqual(...)) -> spv.INotEqual(...)
* spv.LogicalNot(spv.INotEqual(...)) -> spv.IEqual(...)
* spv.LogicalNot(spv.LogicalEqual(...)) -> spv.LogicalNotEqual(...)
* spv.LogicalNot(spv.LogicalNotEqual(...)) -> spv.LogicalEqual(...)

Also moved the test for spv.IMul to arithemtic tests.

Closes tensorflow/mlir#256

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/256 from denis0x0D:sandbox/canon_logical_not 76ab5787b2c777f948c8978db061d99e76453d44
PiperOrigin-RevId: 282012356

4 years agoAdd more canonicalizations for SubViewOp.
Mahesh Ravishankar [Fri, 22 Nov 2019 19:41:29 +0000 (11:41 -0800)]
Add more canonicalizations for SubViewOp.

Depending on which of the offsets, sizes, or strides are constant, the
subview op can be canonicalized in different ways. Add such
canonicalizations, which generalize the existing approach of
canonicalizing subview op only if all of offsets, sizes and shapes are
constants.

PiperOrigin-RevId: 282010703

4 years agoSmall formatting fix in Tutorial Ch2.
Lucy Fox [Fri, 22 Nov 2019 18:42:57 +0000 (10:42 -0800)]
Small formatting fix in Tutorial Ch2.

PiperOrigin-RevId: 281998069

4 years agoUnify vector op names with other dialects.
Jean-Michel Gorius [Fri, 22 Nov 2019 15:52:02 +0000 (07:52 -0800)]
Unify vector op names with other dialects.

Change vector op names from VectorFooOp to Vector_FooOp and from
vector::VectorFooOp to vector::FooOp.

Closes tensorflow/mlir#257

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/257 from Kayjukh:master dfc3a0e04114885aaec8740d5951d6984d6e1577
PiperOrigin-RevId: 281967461

4 years agoAdd more detail about locations in Chapter 2 of tutorial.
Lucy Fox [Fri, 22 Nov 2019 01:15:24 +0000 (17:15 -0800)]
Add more detail about locations in Chapter 2 of tutorial.

Resolves issue 241 (tensorflow/mlir#241).

PiperOrigin-RevId: 281867192

4 years agoMove Linalg Transforms that are actually Conversions - NFC
Nicolas Vasilache [Thu, 21 Nov 2019 23:19:52 +0000 (15:19 -0800)]
Move Linalg Transforms that are actually Conversions - NFC

PiperOrigin-RevId: 281844602

4 years agoAdd support for using the ODS result names as the Asm result names for multi-result...
River Riddle [Thu, 21 Nov 2019 22:34:03 +0000 (14:34 -0800)]
Add support for using the ODS result names as the Asm result names for multi-result operations.

This changes changes the OpDefinitionsGen to automatically add the OpAsmOpInterface for operations with multiple result groups using the provided ODS names. We currently just limit the generation to multi-result ops as most single result operations don't have an interesting name(result/output/etc.). An example is shown below:
// The following operation:
def MyOp : ... {
  let results = (outs AnyType:$first, Variadic<AnyType>:$middle, AnyType);
}

// May now be printed as:
%first, %middle:2, %0 = "my.op" ...

PiperOrigin-RevId: 281834156

4 years agoChange CUDA tests to use print_memref.
Christian Sigg [Thu, 21 Nov 2019 19:16:02 +0000 (11:16 -0800)]
Change CUDA tests to use print_memref.

Swap dimensions in all-reduce-op test.

PiperOrigin-RevId: 281791744

4 years agoNFC: Add wrappers around DenseIntElementsAttr/DenseFPElementsAttr::get to avoid the...
River Riddle [Thu, 21 Nov 2019 17:57:43 +0000 (09:57 -0800)]
NFC: Add wrappers around DenseIntElementsAttr/DenseFPElementsAttr::get to avoid the need to cast.

This avoids the need to cast back to the derived type when calling get, i.e. removes the need to do DenseIntElementsAttr::get(...).cast<DenseIntElementsAttr>().

PiperOrigin-RevId: 281772163

4 years agoFix OSS builds - NFC
Nicolas Vasilache [Thu, 21 Nov 2019 16:46:14 +0000 (08:46 -0800)]
Fix OSS builds - NFC

PiperOrigin-RevId: 281757979

4 years agoDrop unused function - NFC
Nicolas Vasilache [Thu, 21 Nov 2019 15:08:41 +0000 (07:08 -0800)]
Drop unused function - NFC

PiperOrigin-RevId: 281741923

4 years agoSplit Linalg declarative patterns from specific test patterns - NFC
Nicolas Vasilache [Thu, 21 Nov 2019 14:29:41 +0000 (06:29 -0800)]
Split Linalg declarative patterns from specific test patterns - NFC

This will make it easier to scale out test patterns and build specific passes that do not interfere with independent testing.

PiperOrigin-RevId: 281736335

4 years agoAdd missing include after LLVM 049043b598ef5b12a5894c0c22db8608be70f517
Benjamin Kramer [Thu, 21 Nov 2019 14:01:35 +0000 (06:01 -0800)]
Add missing include after LLVM 049043b598ef5b12a5894c0c22db8608be70f517

PiperOrigin-RevId: 281732683

4 years agoDon't force newline before function attributes
Alex Zinenko [Thu, 21 Nov 2019 12:24:52 +0000 (04:24 -0800)]
Don't force newline before function attributes

Due to legacy reasons, a newline character followed by two spaces was always
inserted before the attributes of the function Op in pretty form. This breaks
formatting when functions are nested in some other operations. Don't print the
newline and just put the attributes on the same line, which is also more
consistent with module Op. Line breaking aware of indentation can be introduced
separately into the parser if deemed useful.

PiperOrigin-RevId: 281721793

4 years agoFix OSS build
Nicolas Vasilache [Thu, 21 Nov 2019 12:24:13 +0000 (04:24 -0800)]
Fix OSS build

Add include of ADT/SmallVector.h.
Fixes tensorflow/mlir#254.

PiperOrigin-RevId: 281721705

4 years agoFixed typo in 2-d tiled layout
Aart Bik [Thu, 21 Nov 2019 05:22:13 +0000 (21:22 -0800)]
Fixed typo in 2-d tiled layout

PiperOrigin-RevId: 281671097

4 years agoNFC: Use Region::getBlocks to fix build failure with drop_begin.
River Riddle [Thu, 21 Nov 2019 03:20:04 +0000 (19:20 -0800)]
NFC: Use Region::getBlocks to fix build failure with drop_begin.
PiperOrigin-RevId: 281656603

4 years agoAdd a document detailing operation traits, how to define them, and the current list.
River Riddle [Thu, 21 Nov 2019 02:19:38 +0000 (18:19 -0800)]
Add a document detailing operation traits, how to define them, and the current list.

Traits are an important piece of operation definition, but don't really have a good documentation presence at the moment.

PiperOrigin-RevId: 281649025

4 years agoCorrectly parse empty affine maps.
MLIR Team [Thu, 21 Nov 2019 00:30:14 +0000 (16:30 -0800)]
Correctly parse empty affine maps.

Previously the test case crashes / produces an error.

PiperOrigin-RevId: 281630540

4 years agoMerge DCE and unreachable block elimination into a new utility 'simplifyRegions'.
River Riddle [Wed, 20 Nov 2019 23:23:52 +0000 (15:23 -0800)]
Merge DCE and unreachable block elimination into a new utility 'simplifyRegions'.

This moves the different canonicalizations of regions into one place and invokes them in the fixed-point iteration of the canonicalizer.

PiperOrigin-RevId: 281617072

4 years agoAdd VectorContractionOp to the VectorOps dialect.
Andy Davis [Wed, 20 Nov 2019 22:43:15 +0000 (14:43 -0800)]
Add VectorContractionOp to the VectorOps dialect.

PiperOrigin-RevId: 281605471

4 years agoVerify subview op result has dynamic shape, when sizes are specified.
Mahesh Ravishankar [Wed, 20 Nov 2019 21:43:20 +0000 (13:43 -0800)]
Verify subview op result has dynamic shape, when sizes are specified.

If the sizes are specified as arguments to the subview op, then the
shape must be dynamic as well.

PiperOrigin-RevId: 281591608

4 years agomissing outer index %i in search_body
MLIR Team [Wed, 20 Nov 2019 20:46:54 +0000 (12:46 -0800)]
missing outer index %i in search_body

PiperOrigin-RevId: 281580028

4 years agoAdd multi-level DCE pass.
Sean Silva [Wed, 20 Nov 2019 19:48:57 +0000 (11:48 -0800)]
Add multi-level DCE pass.

This is a simple multi-level DCE pass that operates pretty generically on
the IR. Its key feature compared to the existing peephole dead op folding
that happens during canonicalization is being able to delete recursively
dead cycles of the use-def graph, including block arguments.

PiperOrigin-RevId: 281568202

4 years agoChanges to SubViewOp to make it more amenable to canonicalization.
Mahesh Ravishankar [Wed, 20 Nov 2019 19:16:37 +0000 (11:16 -0800)]
Changes to SubViewOp to make it more amenable to canonicalization.

The current SubViewOp specification allows for either all offsets,
shape and stride to be dynamic or all of them to be static. There are
opportunities for more fine-grained canonicalization based on which of
these are static. For example, if the sizes are static, the result
memref is of static shape. The specification of SubViewOp is modified
to allow on or more of offsets, shapes and strides to be statically
specified. The verification is updated to ensure that the result type
of the subview op is consistent with which of these are static and
which are dynamic.

PiperOrigin-RevId: 281560457

4 years agoImplement unrolling of vector ops to finer-grained vector ops as a pattern.
Nicolas Vasilache [Wed, 20 Nov 2019 18:54:45 +0000 (10:54 -0800)]
Implement unrolling of vector ops to finer-grained vector ops as a pattern.

This CL uses the pattern rewrite infrastructure to implement a simple VectorOps -> VectorOps legalization strategy to unroll coarse-grained vector operations into finer grained ones.
The transformation is written using local pattern rewrites to allow composition with other rewrites. It proceeds by iteratively introducing fake cast ops and cleaning canonicalizing or lowering them away where appropriate.

This is an example of writing transformations as compositions of local pattern rewrites that should enable us to make them significantly more declarative.

PiperOrigin-RevId: 281555100

4 years agoAdd a new OpAsmOpInterface to allow for ops to directly hook into the AsmPrinter.
River Riddle [Wed, 20 Nov 2019 18:19:01 +0000 (10:19 -0800)]
Add a new OpAsmOpInterface to allow for ops to directly hook into the AsmPrinter.

This interface provides more fine-grained hooks into the AsmPrinter than the dialect interface, allowing for operations to define the asm name to use for results directly on the operations themselves. The hook is also expanded to enable defining named result "groups". Get a special name to use when printing the results of this operation.
The given callback is invoked with a specific result value that starts a
result "pack", and the name to give this result pack. To signal that a
result pack should use the default naming scheme, a None can be passed
in instead of the name.

For example, if you have an operation that has four results and you want
to split these into three distinct groups you could do the following:

  setNameFn(getResult(0), "first_result");
  setNameFn(getResult(1), "middle_results");
  setNameFn(getResult(3), ""); // use the default numbering.

This would print the operation as follows:

  %first_result, %middle_results:2, %0 = "my.op" ...

PiperOrigin-RevId: 281546873

4 years agoAdd StridedMemRef<>::operator[] - NFC
Nicolas Vasilache [Wed, 20 Nov 2019 18:06:35 +0000 (10:06 -0800)]
Add StridedMemRef<>::operator[] - NFC

This operator is used for internal debugging purposes.

PiperOrigin-RevId: 281544152

4 years agoFix the comment to Region block iterators.
Alexander Belyaev [Wed, 20 Nov 2019 14:20:08 +0000 (06:20 -0800)]
Fix the comment to Region block iterators.

PiperOrigin-RevId: 281506693

4 years agoFix 'the the' typo.
Alexander Belyaev [Wed, 20 Nov 2019 13:37:49 +0000 (05:37 -0800)]
Fix 'the the' typo.

PiperOrigin-RevId: 281501234