platform/upstream/llvm.git
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

4 years agoExtend kernel outlining to also consider dim worth inlining.
Stephan Herhut [Wed, 20 Nov 2019 10:59:02 +0000 (02:59 -0800)]
Extend kernel outlining to also consider dim worth inlining.

PiperOrigin-RevId: 281483447

4 years agoAdd some CMake rules for installing headers, mlir-tblgen, and mlir-opt
Eric Schweitz [Wed, 20 Nov 2019 05:04:45 +0000 (21:04 -0800)]
Add some CMake rules for installing headers, mlir-tblgen, and mlir-opt

Closes tensorflow/mlir#246

PiperOrigin-RevId: 281442685

4 years agoMake type and rank explicit in mcuMemHostRegister function.
Christian Sigg [Tue, 19 Nov 2019 21:12:19 +0000 (13:12 -0800)]
Make type and rank explicit in mcuMemHostRegister function.

Fix registered size of indirect MemRefType kernel arguments.

PiperOrigin-RevId: 281362940

4 years agoAdd VectorOps.StridedSliceOp
Nicolas Vasilache [Tue, 19 Nov 2019 20:22:00 +0000 (12:22 -0800)]
Add VectorOps.StridedSliceOp

The `vector.strided_slice` takes an n-D vector, k-D `offsets` integer array attribute, a
k-D `sizes` integer array attribute, a k-D `strides` integer array attribute and extracts
the n-D subvector at the proper offset.

Returns an n-D vector where the first k-D dimensions match the `sizes` attribute.
The returned subvector contains the elements starting at offset `offsets` and ending at
`offsets + sizes`.

Example:
```
  %1 = vector.strided_slice %0
      {offsets : [0, 2], sizes : [2, 4], strides : [1, 1]}:
    vector<4x8x16xf32> // returns a vector<2x4x16xf32>
```

This op will be useful for progressive lowering within the VectorOp dialect.

PiperOrigin-RevId: 281352749

4 years agoFix pretty printer corner case in mlir_runner_utils.cpp.
Nicolas Vasilache [Tue, 19 Nov 2019 19:51:53 +0000 (11:51 -0800)]
Fix pretty printer corner case in mlir_runner_utils.cpp.

In the particular case where the size of a memref dimension is 1, double printing would happen because printLast was called unconditionally.
This CL fixes the print and updates an incorrect test that should have caught this in the first place.

PiperOrigin-RevId: 281345142

4 years agoAdd a note on commit messages to our developer guide
Mehdi Amini [Tue, 19 Nov 2019 19:26:45 +0000 (11:26 -0800)]
Add a note on commit messages to our developer guide

PiperOrigin-RevId: 281338738

4 years agoAdd mention to avoid cl::opt for MLIR passes in the developer guide
Mehdi Amini [Tue, 19 Nov 2019 19:25:37 +0000 (11:25 -0800)]
Add mention to avoid cl::opt for MLIR passes in the developer guide

PiperOrigin-RevId: 281338448

4 years agoAdd getRemappedValue to ConversionPatternRewriter
Diego Caballero [Tue, 19 Nov 2019 18:15:36 +0000 (10:15 -0800)]
Add getRemappedValue to ConversionPatternRewriter

This method is needed for N->1 conversion patterns to retrieve remapped
Values used in the original N operations.

Closes tensorflow/mlir#237

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/237 from dcaballe:dcaballe/getRemappedValue 1f64fadcf2b203f7b336ff0c5838b116ae3625db
PiperOrigin-RevId: 281321881

4 years agoAdd '*' and '?' and optional brace parse calls to the Parser
Eric Schweitz [Tue, 19 Nov 2019 18:13:33 +0000 (10:13 -0800)]
Add '*' and '?' and optional brace parse calls to the Parser

Closes tensorflow/mlir#245

PiperOrigin-RevId: 281321459

4 years agoChange conversion CLI flag from -lower-to-llvm to -convert-std-to-llvm
Alex Zinenko [Tue, 19 Nov 2019 08:34:20 +0000 (00:34 -0800)]
Change conversion CLI flag from -lower-to-llvm to -convert-std-to-llvm

The command-line flag name `lower-to-llvm` for the pass performing dialect
conversion from the Standard dialect to the LLVM dialect is misleading and
inconsistent with most of the conversion passses. It leads the user to believe
that there are no restrictions on what can be converted, while in fact only a
subset of the Standard dialect can be converted (with operations from other
dialects converted by separate passes). Use `convert-std-to-llvm` that better
reflects what the pass does and is consistent with most other conversions.

PiperOrigin-RevId: 281238797

4 years agoAdd dialect-attribute-entry requirement to docs
Logan Chien [Tue, 19 Nov 2019 06:49:49 +0000 (22:49 -0800)]
Add dialect-attribute-entry requirement to docs

This commit add `dialect-attribute-entry` requirements on function arguments,
function results, and function attributes to the documentation.

PiperOrigin-RevId: 281227740

4 years agoFix the shape of the outcome in the example code.
Manuel Freiberger [Tue, 19 Nov 2019 05:51:48 +0000 (21:51 -0800)]
Fix the shape of the outcome in the example code.

The toy language uses element-wise multiplication. Transposing and multiplying
two tensors with shape <2, 3> gives a tensor with shape <3, 2>.

Closes tensorflow/mlir#227

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/227 from ombre5733:toy-ch1-docu-fix d79e5d3f9e3d5150a7ac8aac28b899df5a0d10a0
PiperOrigin-RevId: 281221671

4 years agoSupport SPIR-V constant op to take DenseElementsAttr as input.
Hanhan Wang [Tue, 19 Nov 2019 04:01:28 +0000 (20:01 -0800)]
Support SPIR-V constant op to take DenseElementsAttr as input.

Iterates each element to build the array. This includes a little refactor to
combine bool/int/float into a function, since they are similar. The only
difference is calling different function in the end.

PiperOrigin-RevId: 281210288

4 years agoUse SmallVectorImpl instead of SmallVector for function parameters (NFC)
Tian Jin [Tue, 19 Nov 2019 00:58:32 +0000 (16:58 -0800)]
Use SmallVectorImpl instead of SmallVector for function parameters (NFC)

Closes tensorflow/mlir#247

PiperOrigin-RevId: 281185661

4 years agoLower linalg.indexed_generic to loops.
Alexander Belyaev [Mon, 18 Nov 2019 23:39:56 +0000 (15:39 -0800)]
Lower linalg.indexed_generic to loops.

PiperOrigin-RevId: 281169885

4 years agoDrop unnecessary dependences from mlir-translate
Uday Bondhugula [Mon, 18 Nov 2019 23:30:57 +0000 (15:30 -0800)]
Drop unnecessary dependences from mlir-translate

Closes tensorflow/mlir#243

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/243 from bondhugula:patch-2 fb682996efde001189414a4c7aa59ce42ace7831
PiperOrigin-RevId: 281167834

4 years agoFix SubViewOp stride calculation in constant folding.
Andy Davis [Mon, 18 Nov 2019 23:00:34 +0000 (15:00 -0800)]
Fix SubViewOp stride calculation in constant folding.
Adds unit tests for subview offset and stride argument constant folding.

PiperOrigin-RevId: 281161041

4 years agoAdd a parseAttribute<AttrType> overload for the non-type case.
River Riddle [Mon, 18 Nov 2019 21:11:00 +0000 (13:11 -0800)]
Add a parseAttribute<AttrType> overload for the non-type case.

The variant that accepts a type will check that the parsed attribute is a valid instance of AttrType. The non-type variant would silently fail in this case, leading to garbage attribute values.

PiperOrigin-RevId: 281136528

4 years agoFix gen_spirv_dialect.py regarding 1D/2D/3D Dim symbol name
Lei Zhang [Mon, 18 Nov 2019 20:47:54 +0000 (12:47 -0800)]
Fix gen_spirv_dialect.py regarding 1D/2D/3D Dim symbol name

PiperOrigin-RevId: 281131561

4 years ago[spirv] Add a canonicalizer for BitcastOp.
Denis Khalikov [Mon, 18 Nov 2019 20:36:16 +0000 (12:36 -0800)]
[spirv] Add a canonicalizer for BitcastOp.

Convert chained `spirv::BitcastOp` operations into
one `spirv::BitcastOp` operation.

Closes tensorflow/mlir#238

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/238 from denis0x0D:sandbox/canon_bitcast 4352ed4f81b959ec92f849c599e733b62a99c010
PiperOrigin-RevId: 281129234

4 years agoAlso elide large array attribute in OpGraph Dump
Jing Pu [Mon, 18 Nov 2019 19:27:08 +0000 (11:27 -0800)]
Also elide large array attribute in OpGraph Dump

PiperOrigin-RevId: 281114034

4 years agoConvertStandardToLLVM: replace assertion with graceful failure
Alex Zinenko [Mon, 18 Nov 2019 19:25:52 +0000 (11:25 -0800)]
ConvertStandardToLLVM: replace assertion with graceful failure

The assertion was introduced in the early days of dialect conversion
infrastructure when we had the matching function separate from the rewriting
function. The infrastructure evolved to have a common matchAndRewrite function
and the separate matching function was dropped without chaning the rewriting
that became matchAndRewrite. This has led to assertion being triggered. Return
a matchFailure instead of failing an assertion on unsupported types.

Closes tensorflow/mlir#230

PiperOrigin-RevId: 281113741

4 years agoFix Affine Loop Fusion test case reported on github.
Andy Davis [Mon, 18 Nov 2019 19:20:03 +0000 (11:20 -0800)]
Fix Affine Loop Fusion test case reported on github.
This CL utilizies the more robust fusion feasibility analysis being built out in LoopFusionUtils, which will eventually be used to replace the current affine loop fusion pass.

PiperOrigin-RevId: 281112340

4 years agoStandardize all VectorOps class names to be prefixed by Vector - NFC
Nicolas Vasilache [Mon, 18 Nov 2019 18:38:35 +0000 (10:38 -0800)]
Standardize all VectorOps class names to be prefixed by Vector - NFC

This improves consistency and will concretely avoid collisions between VectorExtractElementOp and ExtractElementOp when they are included in the same transforms / rewrites.

PiperOrigin-RevId: 281101588

4 years agoImplement folding of pattern dim(subview(_)[...][s1, ..., sn][...], i) -> si.
Stephan Herhut [Mon, 18 Nov 2019 12:31:02 +0000 (04:31 -0800)]
Implement folding of pattern dim(subview(_)[...][s1, ..., sn][...], i) -> si.

PiperOrigin-RevId: 281042016

4 years agoRename CLI flags -lower-gpu-ops-to-*-ops to -convert-gpu-to-*
Alex Zinenko [Mon, 18 Nov 2019 10:42:39 +0000 (02:42 -0800)]
Rename CLI flags -lower-gpu-ops-to-*-ops to -convert-gpu-to-*

This makes the flags consistent with the naming scheme used elsewhere in the
codebase for dialect conversions.

PiperOrigin-RevId: 281027517

4 years agoFix mismatched-tags warning
Jacques Pienaar [Sun, 17 Nov 2019 05:13:19 +0000 (21:13 -0800)]
Fix mismatched-tags warning

PiperOrigin-RevId: 280888290

4 years agoFix attribute dict syntax in the docs
Logan Chien [Fri, 15 Nov 2019 21:40:33 +0000 (13:40 -0800)]
Fix attribute dict syntax in the docs

This commit fixes several attribute dict syntax errors in the documentation.

PiperOrigin-RevId: 280726269

4 years ago[spirv] Add bit ops
Denis Khalikov [Fri, 15 Nov 2019 18:51:42 +0000 (10:51 -0800)]
[spirv] Add bit ops

This CL added op definitions for a few bit operations:

* OpBitFieldInsert
* OpBitFieldSExtract
* OpBitFieldUExtract

Closes tensorflow/mlir#233

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/233 from denis0x0D:sandbox/bit_field_ops e7fd85b00d72d483d7992dc42b9cc4d673903455
PiperOrigin-RevId: 280691816

4 years agoClarify that identity maps are discarded from the MemRef type
Alex Zinenko [Fri, 15 Nov 2019 18:19:26 +0000 (10:19 -0800)]
Clarify that identity maps are discarded from the MemRef type

Update LangRef to explicitly mention the type canonicalization rule applied to
MemRef types: identity maps do not contribute to type identification.

PiperOrigin-RevId: 280684904

4 years agoNFC: Convert CmpIPredicate in StandardOps to use EnumAttr
Lei Zhang [Fri, 15 Nov 2019 18:16:33 +0000 (10:16 -0800)]
NFC: Convert CmpIPredicate in StandardOps to use EnumAttr

This turns several hand-written functions to auto-generated ones.

PiperOrigin-RevId: 280684326

4 years agoModify tutorial and other documentation for consistency, clarity, and correctness.
Lucy Fox [Fri, 15 Nov 2019 17:48:54 +0000 (09:48 -0800)]
Modify tutorial and other documentation for consistency, clarity, and correctness.

PiperOrigin-RevId: 280678392

4 years agoUse simpler highlighting textmate syntax
Jacques Pienaar [Fri, 15 Nov 2019 17:29:10 +0000 (09:29 -0800)]
Use simpler highlighting textmate syntax

Changes from:
https://github-lightshow.herokuapp.com/?utf8=%E2%9C%93&scope=from-url&grammar_format=auto&grammar_url=https%3A%2F%2Fraw.githubusercontent.com%2Fjpienaar%2Fmlir-grammar%2Fmaster%2Fgrammars%2Fmlir.json&grammar_text=&code_source=from-url&code_url=https%3A%2F%2Fraw.githubusercontent.com%2Fjpienaar%2Fmlir-grammar%2Fmaster%2Fsample.mlir&code=

To:
https://github-lightshow.herokuapp.com/?utf8=%E2%9C%93&scope=from-url&grammar_format=auto&grammar_url=https%3A%2F%2Fraw.githubusercontent.com%2Fjpienaar%2Fmlir-grammar%2Fsimpler%2Fgrammars%2Fmlir.json&grammar_text=&code_source=from-url&code_url=https%3A%2F%2Fraw.githubusercontent.com%2Fjpienaar%2Fmlir-grammar%2Fmaster%2Fsample.mlir&code=

Which I think is an improvement.

PiperOrigin-RevId: 280674770

4 years agoFix build warnings
Nicolas Vasilache [Fri, 15 Nov 2019 17:05:35 +0000 (09:05 -0800)]
Fix build warnings

Delete unused constexpr ints in LowerToLLVMDialect.
Add (void)toStringRef for non-debug builds.

Fixes tensorflow/mlir#232.

PiperOrigin-RevId: 280671014

4 years agoUse aggregate-parameter builder for ops having autogen type-deduction builder
Lei Zhang [Fri, 15 Nov 2019 15:33:21 +0000 (07:33 -0800)]
Use aggregate-parameter builder for ops having autogen type-deduction builder

Thus far DRR always invokes the separate-parameter builder (i.e., requiring
a separate parameter for each result-type/operand/attribute) for creating
ops, no matter whether we can auto-generate a builder with type-deduction
ability or not.

This CL changes the path for ops that we can auto-generate type-deduction
builders, i.e., with SameOperandsAndResultType/FirstAttrDerivedResultType
traits. Now they are going through a aggregate-parameter builder (i.e.,
requiring one parameter for all result-types/operands/attributes).
attributes.)

It is expected this approach will be more friendly for future shape inference
function autogen and calling those autogen'd shape inference function without
excessive packing and repacking operand/attribute lists.
Also, it would enable better support for creating ops with optional attributes
because we are not required to provide an Attribute() as placeholder for
an optional attribute anymore.

PiperOrigin-RevId: 280654800

4 years agoTemplatize linalg::LowerToLoops - NFC
Nicolas Vasilache [Fri, 15 Nov 2019 15:12:17 +0000 (07:12 -0800)]
Templatize linalg::LowerToLoops - NFC

This modification will allow to easily plug lowering of linalg ops to different types of loops (affine, loop.for and other future constructs).
This is purely NFC for now.

PiperOrigin-RevId: 280652186

4 years agoMark std.view as no-sideeffect.
Stephan Herhut [Fri, 15 Nov 2019 13:27:57 +0000 (05:27 -0800)]
Mark std.view as no-sideeffect.

The same reasoning as for std.subview applies.

PiperOrigin-RevId: 280639308

4 years agoMark std.subview as no-sideeffect.
Stephan Herhut [Fri, 15 Nov 2019 11:59:57 +0000 (03:59 -0800)]
Mark std.subview as no-sideeffect.

In essence, std.subview is just an abstract indexing transformation (somewhat
akin to a gep in llvm) and by itself has no effect. From a practical perspective
this helps, as it allows to remove dead subview operations.

PiperOrigin-RevId: 280630046

4 years agoAdd more navigation to the MLIR toy tutorial.
MLIR Team [Fri, 15 Nov 2019 10:17:09 +0000 (02:17 -0800)]
Add more navigation to the MLIR toy tutorial.

This comes in the form of:
1. Missing links to next chapters.
2. Table of contents for each page.

PiperOrigin-RevId: 280619053

4 years agoExpand on operation definition to clarify the difference between operation and op.
Lucy Fox [Fri, 15 Nov 2019 01:54:10 +0000 (17:54 -0800)]
Expand on operation definition to clarify the difference between operation and op.

PiperOrigin-RevId: 280555742

4 years agoRefactor the LowerVectorTransfers pass to use the RewritePattern infra - NFC
Nicolas Vasilache [Thu, 14 Nov 2019 23:39:36 +0000 (15:39 -0800)]
Refactor the LowerVectorTransfers pass to use the RewritePattern infra - NFC

This is step 1/n in refactoring infrastructure along the Vector dialect to make it ready for retargetability and composable progressive lowering.

PiperOrigin-RevId: 280529784

4 years agoNFC: Refactor Dialect Conversion targeting SPIR-V.
Mahesh Ravishankar [Thu, 14 Nov 2019 20:31:32 +0000 (12:31 -0800)]
NFC: Refactor Dialect Conversion targeting SPIR-V.

Refactoring the conversion from StandardOps/GPU dialect to SPIR-V
dialect:
1) Move the SPIRVTypeConversion and SPIRVOpLowering class into SPIR-V
   dialect.
2) Add header files that expose functions to add patterns for the
   dialects to SPIR-V lowering, as well as a pass that does the
   dialect to SPIR-V lowering.
3) Make SPIRVOpLowering derive from OpLowering class.
PiperOrigin-RevId: 280486871

4 years agoAdds canonicalizer to SubViewOp which folds constants from base memref and operands...
Andy Davis [Thu, 14 Nov 2019 20:22:28 +0000 (12:22 -0800)]
Adds canonicalizer to SubViewOp which folds constants from base memref and operands into the subview result memref type.
Changes SubViewOp to support zero operands case, when offset, strides and sizes are all constant.

PiperOrigin-RevId: 280485075

4 years agoAdd CMakeLists.txt for AffineToStandard conversion
Alex Zinenko [Thu, 14 Nov 2019 19:16:47 +0000 (11:16 -0800)]
Add CMakeLists.txt for AffineToStandard conversion

PiperOrigin-RevId: 280470142

4 years ago[ODS] Fix operation argument population to avoid crash
Lei Zhang [Thu, 14 Nov 2019 19:02:52 +0000 (11:02 -0800)]
[ODS] Fix operation argument population to avoid crash

The `Operator` class keeps an `arguments` field, which contains pointers
to `operands` and `attributes` elements. Thus it must be populated after
`operands` and `attributes` are finalized so to have stable pointers.
SmallVector may re-allocate when still having new elements added, which
will invalidate pointers.

PiperOrigin-RevId: 280466896

4 years agoMove Affine to Standard conversion to lib/Conversion
Alex Zinenko [Thu, 14 Nov 2019 18:34:46 +0000 (10:34 -0800)]
Move Affine to Standard conversion to lib/Conversion

This is essentially a dialect conversion and conceptually belongs to
conversions.

PiperOrigin-RevId: 280460034

4 years agoMake positions of elements in MemRef descriptor private
Alex Zinenko [Thu, 14 Nov 2019 17:10:27 +0000 (09:10 -0800)]
Make positions of elements in MemRef descriptor private

Previous commits removed all uses of LLVMTypeConverter::k*PosInMemRefDescriptor
outside of the MemRefDescriptor class. These numbers are an implementation
detail and can be hidden under a layer of more semantic APIs.

PiperOrigin-RevId: 280442444

4 years agoUse MemRefDescriptor in Vector-to-LLVM convresion
Alex Zinenko [Thu, 14 Nov 2019 17:05:11 +0000 (09:05 -0800)]
Use MemRefDescriptor in Vector-to-LLVM convresion

Following up on the consolidation of MemRef descriptor conversion, update
Vector-to-LLVM conversion to use the helper class that abstracts away the
implementation details of the MemRef descriptor. This also makes the types of
the attributes in emitted llvm.insert/extractelement operations consistently
i64 instead of a mix of index and i64.

PiperOrigin-RevId: 280441451

4 years agoAdapt code to LLVM API updates.
MLIR Team [Thu, 14 Nov 2019 16:15:25 +0000 (08:15 -0800)]
Adapt code to LLVM API updates.

PiperOrigin-RevId: 280431812

4 years agoMove VectorOps to Tablegen - (almost) NFC
Nicolas Vasilache [Thu, 14 Nov 2019 16:10:36 +0000 (08:10 -0800)]
Move VectorOps to Tablegen - (almost) NFC

This CL moves VectorOps to Tablegen and cleans up the implementation.

This is almost NFC but 2 changes occur:
  1. an interface change occurs in the padding value specification in vector_transfer_read:
     the value becomes non-optional. As a shortcut we currently use %f0 for all paddings.
     This should become an OpInterface for vectorization in the future.
  2. the return type of vector.type_cast is trivial and simplified to `memref<vector<...>>`

Relevant roundtrip and invalid tests that used to sit in core are moved to the vector dialect.

The op documentation is moved to the .td file.

PiperOrigin-RevId: 280430869

4 years agoUse MemRefDescriptor in Linalg-to-LLVM conversion
Alex Zinenko [Thu, 14 Nov 2019 16:03:39 +0000 (08:03 -0800)]
Use MemRefDescriptor in Linalg-to-LLVM conversion

Following up on the consolidation of MemRef descriptor conversion, update
Linalg-to-LLVM conversion to use the helper class that abstracts away the
implementation details of the MemRef descriptor. This required MemRefDescriptor
to become publicly visible. Since this conversion is heavily EDSC-based,
introduce locally an additional wrapper that uses builder and location pointed
to by the EDSC context while emitting descriptor manipulation operations.

PiperOrigin-RevId: 280429228

4 years ago[doc] Add debugging tips in ODS and DRR doc regarding mlir-tblgen
Lei Zhang [Thu, 14 Nov 2019 12:25:56 +0000 (04:25 -0800)]
[doc] Add debugging tips in ODS and DRR doc regarding mlir-tblgen

PiperOrigin-RevId: 280398956

4 years agoConcentrate memref descriptor manipulation logic in one place
Alex Zinenko [Thu, 14 Nov 2019 08:48:41 +0000 (00:48 -0800)]
Concentrate memref descriptor manipulation logic in one place

Memref descriptor is becoming increasingly complex. Memrefs are manipulated by
multiple standard instructions, each of which has a non-trivial lowering to the
LLVM dialect. This leads to verbose code that manipulates the descriptors
exposing the internals of insert/extractelement opreations. Implement a wrapper
class that contains a memref descriptor and provides semantically named methods
that build the primitive IR operations instead.

PiperOrigin-RevId: 280371225

4 years agoDo not emit aliases when printing local form
Jacques Pienaar [Wed, 13 Nov 2019 22:21:16 +0000 (14:21 -0800)]
Do not emit aliases when printing local form

Expand local scope printing to skip printing aliases as aliases are printed out at the top of a module and may not be part of the output generated by local scope print.

PiperOrigin-RevId: 280278617

4 years agoReplace explicit concatenation by llvm::concat
Nicolas Vasilache [Wed, 13 Nov 2019 20:54:02 +0000 (12:54 -0800)]
Replace explicit concatenation by llvm::concat

PiperOrigin-RevId: 280258938

4 years agoDeprecate linalg.subview in favor of std.subview
Nicolas Vasilache [Wed, 13 Nov 2019 20:09:40 +0000 (12:09 -0800)]
Deprecate linalg.subview in favor of std.subview

This CL uses the now standard std.subview in linalg.
Two shortcuts are currently taken to allow this port:
1. the type resulting from a view is currently degraded to fully dynamic to pass the SubViewOp verifier.
2. indexing into SubViewOp may access out of bounds since lowering to LLVM does not currently enforce it by construction.

These will be fixed in subsequent commits after discussions.

PiperOrigin-RevId: 280250129

4 years agoFix glossary formatting.
Lucy Fox [Wed, 13 Nov 2019 19:09:10 +0000 (11:09 -0800)]
Fix glossary formatting.

PiperOrigin-RevId: 280236761

4 years agoAdd FuncOp::eraseArgument
Sean Silva [Wed, 13 Nov 2019 18:59:24 +0000 (10:59 -0800)]
Add FuncOp::eraseArgument

This is a quite complex operation that users are likely to attempt to write
themselves and get wrong (citation: users=me).

Ideally, we could pull this into FunctionLike, but for now, the
FunctionType rewriting makes it FuncOp specific. We would need some hook
for rewriting the function type (which for LLVM's func op, would need to
rewrite the underlying LLVM type).

PiperOrigin-RevId: 280234164

4 years agoNFC: Refactor block signature conversion to not erase the original arguments.
River Riddle [Wed, 13 Nov 2019 18:27:21 +0000 (10:27 -0800)]
NFC: Refactor block signature conversion to not erase the original arguments.

This refactors the implementation of block signature(type) conversion to not insert fake cast operations to perform the type conversion, but to instead create a new block containing the proper signature. This has the benefit of enabling the use of pre-computed analyses that rely on mapping values. It also leads to a much cleaner implementation overall. The major user facing change is that applySignatureConversion will now replace the entry block of the region, meaning that blocks generally shouldn't be cached over calls to applySignatureConversion.

PiperOrigin-RevId: 280226936

4 years agoCreate and begin writing glossary.
Lucy Fox [Wed, 13 Nov 2019 17:58:53 +0000 (09:58 -0800)]
Create and begin writing glossary.

This creates a central place in the documentation where MLIR-specific terminology is defined. See discussion on the MLIR forum (https://groups.google.com/a/tensorflow.org/g/mlir/c/5YXDSdu76Hk).

PiperOrigin-RevId: 280220365

4 years agoRename the current parseSymbolName to parseOptionalSymbolName
River Riddle [Wed, 13 Nov 2019 17:31:45 +0000 (09:31 -0800)]
Rename the current parseSymbolName to parseOptionalSymbolName

The current implementation silently fails if the '@' identifier isn't present, making it similar to the 'optional' parse methods. This change renames the current implementation to 'Optional' and adds a new 'parseSymbolName' that emits an error.

PiperOrigin-RevId: 280214610

4 years agoMake VariableOp instructions be in the first block in the function.
Hanhan Wang [Wed, 13 Nov 2019 02:58:36 +0000 (18:58 -0800)]
Make VariableOp instructions be in the first block in the function.

Since VariableOp is serialized during processBlock, we add two more fields,
`functionHeader` and `functionBody`, to collect instructions for a function.
After all the blocks have been processed, we append them to the `functions`.

Also, fix a bug in processGlobalVariableOp. The global variables should be
encoded into `typesGlobalValues`.

PiperOrigin-RevId: 280105366

4 years agoAdd operations needed to support lowering of AffineExpr to SPIR-V.
Mahesh Ravishankar [Tue, 12 Nov 2019 21:19:33 +0000 (13:19 -0800)]
Add operations needed to support lowering of AffineExpr to SPIR-V.

Lowering of CmpIOp, DivISOp, RemISOp, SubIOp and SelectOp to SPIR-V
dialect enables the lowering of operations generated by AffineExpr ->
StandardOps conversion into the SPIR-V dialect.

PiperOrigin-RevId: 280039204

4 years agoNFC: Change DictionaryAttr::get(StringRef) to use binary search instead of a linear...
River Riddle [Tue, 12 Nov 2019 21:03:39 +0000 (13:03 -0800)]
NFC: Change DictionaryAttr::get(StringRef) to use binary search instead of a linear scan.

The elements of a DictionaryAttr are guaranteed to be sorted by name, so we can use a more efficient lookup when searching for an attribute.

PiperOrigin-RevId: 280035488

4 years agoMake legality check in GPU->SPIR-V lowering of FuncOp kernel specific.
Mahesh Ravishankar [Tue, 12 Nov 2019 20:52:18 +0000 (12:52 -0800)]
Make legality check in GPU->SPIR-V lowering of FuncOp kernel specific.

Existing check that sets FuncOp to be dynamically legal was just
checking that the types of the argument are SPIR-V compatible. Since
the current conversion from GPU to SPIR-V does not handle lowering
non-kernel functions, change the legality check to verify that the
FuncOp has the gpu.kernel attribute and has void(void) return type.

PiperOrigin-RevId: 280032782

4 years agoAdd support for OpPhi in loop header block
Lei Zhang [Tue, 12 Nov 2019 19:59:34 +0000 (11:59 -0800)]
Add support for OpPhi in loop header block

During deserialization, the loop header block will be moved into the
spv.loop's region. If the loop header block has block arguments,
we need to make sure it is correctly carried over to the block where
the new spv.loop resides.

During serialization, we need to make sure block arguments from the
spv.loop's entry block are not silently dropped.

PiperOrigin-RevId: 280021777

4 years agoAdd an option to print an operation if a diagnostic is emitted on it
River Riddle [Tue, 12 Nov 2019 19:57:47 +0000 (11:57 -0800)]
Add an option to print an operation if a diagnostic is emitted on it

It is often helpful to inspect the operation that the error/warning/remark/etc. originated from, especially in the context of debugging or in the case of a verifier failure. This change adds an option 'mlir-print-op-on-diagnostic' that attaches the operation as a note to any diagnostic that is emitted on it via Operation::emit(Error|Warning|Remark). In the case of an error, the operation is printed in the generic form.

PiperOrigin-RevId: 280021438

4 years agoExpose an isSubclassOf() method on AttrConstraint
Lei Zhang [Tue, 12 Nov 2019 19:57:40 +0000 (11:57 -0800)]
Expose an isSubclassOf() method on AttrConstraint

PiperOrigin-RevId: 280021408