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

4 years agoAdd Conversion to lower loop::ForOp to spirv::LoopOp.
Mahesh Ravishankar [Tue, 12 Nov 2019 19:32:54 +0000 (11:32 -0800)]
Add Conversion to lower loop::ForOp to spirv::LoopOp.

loop::ForOp can be lowered to the structured control flow represented
by spirv::LoopOp by making the continue block of the spirv::LoopOp the
loop latch and the merge block the exit block. The resulting
spirv::LoopOp has a single back edge from the continue to header
block, and a single exit from header to merge.
PiperOrigin-RevId: 280015614

4 years ago[spirv] Properly return when finding error in serialization
Lei Zhang [Tue, 12 Nov 2019 18:33:36 +0000 (10:33 -0800)]
[spirv] Properly return when finding error in serialization

PiperOrigin-RevId: 280001339

4 years agoAdd a printer flag to use local scope when printing IR.
River Riddle [Tue, 12 Nov 2019 17:36:40 +0000 (09:36 -0800)]
Add a printer flag to use local scope when printing IR.

This causes the AsmPrinter to use a local value numbering when printing the IR, allowing for the printer to be used safely in a local context, e.g. to ensure thread-safety when printing the IR. This means that the IR printing instrumentation can also be used during multi-threading when module-scope is disabled. Operation::dump and DiagnosticArgument(Operation*) are also updated to always print local scope, as this is the most common use case when debugging.

PiperOrigin-RevId: 279988203

4 years agoUpdate textmate syntax file
Jacques Pienaar [Tue, 12 Nov 2019 17:30:08 +0000 (09:30 -0800)]
Update textmate syntax file

Allow comments in more places and fix function params.

PiperOrigin-RevId: 279986797

4 years agoUpdate outdated comment for NativeCodeCall
Lei Zhang [Tue, 12 Nov 2019 17:25:41 +0000 (09:25 -0800)]
Update outdated comment for NativeCodeCall

PiperOrigin-RevId: 279986050

4 years agoAdd LLVM lowering of std.subview
Nicolas Vasilache [Tue, 12 Nov 2019 15:22:51 +0000 (07:22 -0800)]
Add LLVM lowering of std.subview

A followup CL will replace usage of linalg.subview by std.subview.

PiperOrigin-RevId: 279961981

4 years agoAdds affine.min operation which returns the minimum value from a multi-result affine...
Andy Davis [Tue, 12 Nov 2019 15:08:23 +0000 (07:08 -0800)]
Adds affine.min operation which returns the minimum value from a multi-result affine map. This operation is useful for things like computing the dynamic value of affine loop bounds, and is trivial to constant fold.

PiperOrigin-RevId: 279959714

4 years agoAdd support for alignment attribute in std.alloc.
Nicolas Vasilache [Tue, 12 Nov 2019 15:06:18 +0000 (07:06 -0800)]
Add support for alignment attribute in std.alloc.

This CL adds an extra pointer to the memref descriptor to allow specifying alignment.

In a previous implementation, we used 2 types: `linalg.buffer` and `view` where the buffer type was the unit of allocation/deallocation/alignment and `view` was the unit of indexing.

After multiple discussions it was decided to use a single type, which conflates both, so the memref descriptor now needs to carry both pointers.

This is consistent with the [RFC-Proposed Changes to MemRef and Tensor MLIR Types](https://groups.google.com/a/tensorflow.org/forum/#!searchin/mlir/std.view%7Csort:date/mlir/-wKHANzDNTg/4K6nUAp8AAAJ).

PiperOrigin-RevId: 279959463

4 years agoRestructure comment lexing to not recurse.
River Riddle [Tue, 12 Nov 2019 03:14:43 +0000 (19:14 -0800)]
Restructure comment lexing to not recurse.

In some files that have large amounts of comments, this can lead to a stack overflow.

PiperOrigin-RevId: 279867330

4 years agoAdd support for nested symbol references.
River Riddle [Tue, 12 Nov 2019 02:18:02 +0000 (18:18 -0800)]
Add support for nested symbol references.

This change allows for adding additional nested references to a SymbolRefAttr to allow for further resolving a symbol if that symbol also defines a SymbolTable. If a referenced symbol also defines a symbol table, a nested reference can be used to refer to a symbol within that table. Nested references are printed after the main reference in the following form:

  symbol-ref-attribute ::= symbol-ref-id (`::` symbol-ref-id)*

Example:

  module @reference {
    func @nested_reference()
  }

  my_reference_op @reference::@nested_reference

Given that SymbolRefAttr is now more general, the existing functionality centered around a single reference is moved to a derived class FlatSymbolRefAttr. Followup commits will add support to lookups, rauw, etc. for scoped references.

PiperOrigin-RevId: 279860501

4 years agoAdds std.subview operation which takes dynamic offsets, sizes and strides and returns...
Andy Davis [Mon, 11 Nov 2019 18:32:52 +0000 (10:32 -0800)]
Adds std.subview operation which takes dynamic offsets, sizes and strides and returns a memref type which represents sub/reduced-size view of its memref argument.
This operation is a companion operation to the std.view operation added as proposed in "Updates to the MLIR MemRefType" RFC.

PiperOrigin-RevId: 279766410

4 years agoAlso consider index constants when folding integer arithmetics with constants.
Stephan Herhut [Mon, 11 Nov 2019 10:33:49 +0000 (02:33 -0800)]
Also consider index constants when folding integer arithmetics with constants.

PiperOrigin-RevId: 279698088

4 years agoFix segfault (nullptr dereference) when passing a non-existent file to the Toy tutori...
Mehdi Amini [Sun, 10 Nov 2019 05:30:42 +0000 (21:30 -0800)]
Fix segfault (nullptr dereference) when passing a non-existent file to the Toy tutorial compiler

Fix tensorflow/mlir#229

PiperOrigin-RevId: 279557863

4 years agoAdd a short TableGen HowTo to tutorial chapter 2.
Manuel Freiberger [Sat, 9 Nov 2019 20:14:39 +0000 (12:14 -0800)]
Add a short TableGen HowTo to tutorial chapter 2.

Add a note to chapter 2 of the Toy tutorial stating how to invoke
mlir-tblgen to check the generated C++ code. IMHO this is incredibly
useful when getting acquainted with TableGen/ODS.

Closes tensorflow/mlir#228

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/228 from ombre5733:toy-ch2-howto-mlir-tblgen a051a3734ca8bbf4f12027fe737aca07c64ca59d
PiperOrigin-RevId: 279518989

4 years agoLook for SymbolRefAttr in KernelOutlining instead of hard-coding CallOp
MLIR Team [Sat, 9 Nov 2019 03:12:40 +0000 (19:12 -0800)]
Look for SymbolRefAttr in KernelOutlining instead of hard-coding CallOp

This code should be exercised using the existing kernel outlining unit test, but
let me know if I should add a dedicated unit test using a fake call instruction
as well.

PiperOrigin-RevId: 279436321

4 years agoExplicitly initialize isRecursivelyLegal
Jacques Pienaar [Fri, 8 Nov 2019 23:06:03 +0000 (15:06 -0800)]
Explicitly initialize isRecursivelyLegal

This also previously triggered the warning:

warning: missing field 'isRecursivelyLegal' initializer [-Wmissing-field-initializers]
  legalOperations[op] = {action};
                               ^
PiperOrigin-RevId: 279399175

4 years ago[spirv] Add bit ops
Denis Khalikov [Fri, 8 Nov 2019 19:05:32 +0000 (11:05 -0800)]
[spirv] Add bit ops

This CL added op definitions for a few bit operations:

* OpShiftLeftLogical
* OpShiftRightArithmetic
* OpShiftRightLogical
* OpBitCount
* OpBitReverse
* OpNot

Also moved the definition of spv.BitwiseAnd to follow the
lexicographical order.

Closes tensorflow/mlir#215

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/215 from denis0x0D:sandbox/bit_ops d9b0852b689ac6c4879a9740b1740a2357f44d24
PiperOrigin-RevId: 279350470

4 years agoMove description from GenericOpBase to linalg.(indexed_)generic.
Alexander Belyaev [Thu, 7 Nov 2019 22:50:25 +0000 (14:50 -0800)]
Move description from GenericOpBase to linalg.(indexed_)generic.

PiperOrigin-RevId: 279173284

4 years agomlir-translate: support -verify-diagnostics
Alex Zinenko [Thu, 7 Nov 2019 19:42:11 +0000 (11:42 -0800)]
mlir-translate: support -verify-diagnostics

MLIR translation tools can emit diagnostics and we want to be able to check if
it is indeed the case in tests. Reuse the source manager error handlers
provided for mlir-opt to support the verification in mlir-translate. This
requires us to change the signature of the functions that are registered to
translate sources to MLIR: it now takes a source manager instead of a memory
buffer.

PiperOrigin-RevId: 279132972

4 years agoFix asm printer for affine expr
Uday Bondhugula [Thu, 7 Nov 2019 18:26:51 +0000 (10:26 -0800)]
Fix asm printer for affine expr

- fixes tensorflow/mlir#201

Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>
Closes tensorflow/mlir#204

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/204 from bondhugula:printfix 3f8a5b65391f45598258b2735fecaa409fbde848
PiperOrigin-RevId: 279115720

4 years agoSwap operand order in std.view operation so that offset appears before dynamic sizes...
Andy Davis [Thu, 7 Nov 2019 18:19:54 +0000 (10:19 -0800)]
Swap operand order in std.view operation so that offset appears before dynamic sizes in the operand list.

PiperOrigin-RevId: 279114236

4 years agoAdd Ch-7 of the toy tutorial detailing how to define new types.
River Riddle [Thu, 7 Nov 2019 17:53:27 +0000 (09:53 -0800)]
Add Ch-7 of the toy tutorial detailing how to define new types.

This chapter adds a new composite type to Toy, and shows the process of adding a new type to the IR, adding and updating operations to use it, and constant folding operations producing it.

PiperOrigin-RevId: 279107885

4 years agoAdd canonicalizer for ViewOp which folds constants into the ViewOp memref shape and...
Andy Davis [Thu, 7 Nov 2019 16:04:33 +0000 (08:04 -0800)]
Add canonicalizer for ViewOp which folds constants into the ViewOp memref shape and layout map strides and offset.

PiperOrigin-RevId: 279088023

4 years agoFix parameter name and document option in linalg::promoteSubViews
Nicolas Vasilache [Thu, 7 Nov 2019 15:55:49 +0000 (07:55 -0800)]
Fix parameter name and document option in linalg::promoteSubViews

PiperOrigin-RevId: 279086352

4 years agoAdd compatible query method to infer type interface
Jacques Pienaar [Thu, 7 Nov 2019 15:51:12 +0000 (07:51 -0800)]
Add compatible query method to infer type interface

A return type that differs from the inferred return type need not indicate that an operation is invalid (e.g., tensor<*xf32> vs tensor<10xf32>) but they should be compatible for the operation to be considered valid. Add method to query if inferred type is compatible with return type.

Also add InferTypeOpIntefaceDefault trait that considers equality and compatibility as the same. Currently an op has to opt in to using it explicitly.

PiperOrigin-RevId: 279085639

4 years agoUpdate Linalg to use std.view
Nicolas Vasilache [Thu, 7 Nov 2019 14:32:39 +0000 (06:32 -0800)]
Update Linalg to use std.view

Now that a view op has graduated to the std dialect, we can update Linalg to use it and remove ops that have become obsolete. As a byproduct, the linalg buffer and associated ops can also disappear.

PiperOrigin-RevId: 279073591

4 years agoAdd IndexedGenericOp to Linalg.
Alexander Belyaev [Thu, 7 Nov 2019 06:35:51 +0000 (22:35 -0800)]
Add IndexedGenericOp to Linalg.

PiperOrigin-RevId: 279013404

4 years agoNFC: Tidy up the implementation of operations in the Toy tutorial
River Riddle [Thu, 7 Nov 2019 02:21:04 +0000 (18:21 -0800)]
NFC: Tidy up the implementation of operations in the Toy tutorial

Use header blocks to separate operation implementations, and switch the build methods to be out-of-line when possible.

PiperOrigin-RevId: 278982913

4 years agoNFC: Uniformize parser naming scheme in Toy tutorial to camelCase and tidy a bit...
River Riddle [Thu, 7 Nov 2019 02:20:24 +0000 (18:20 -0800)]
NFC: Uniformize parser naming scheme in Toy tutorial to camelCase and tidy a bit of the implementation.
PiperOrigin-RevId: 278982817

4 years agoReplace some remnant uses of "inst" with "op".
Sean Silva [Thu, 7 Nov 2019 00:08:51 +0000 (16:08 -0800)]
Replace some remnant uses of "inst" with "op".

PiperOrigin-RevId: 278961676

4 years agoDrop spurious test file
Nicolas Vasilache [Thu, 7 Nov 2019 00:00:22 +0000 (16:00 -0800)]
Drop spurious test file

PiperOrigin-RevId: 278959717

4 years agoAdd lowering of std.view to LLVM
Nicolas Vasilache [Wed, 6 Nov 2019 23:05:47 +0000 (15:05 -0800)]
Add lowering of std.view to LLVM

This CL ports the lowering of linalg.view to the newly introduced std.view.
Differences in implementation relate to std.view having slightly different semantics:
1. a static or dynamic offset can be specified.
2. the size of the (contiguous) shape is passed instead of a range.
3. static size and stride information is extracted from the memref type rather than the range.

Besides these differences, lowering behaves the same.
A future CL will update Linalg to use this unified infrastructure.

PiperOrigin-RevId: 278948853

4 years agoAdd affine load/store/dma_start/dma_wait to dialect doc.
Andy Davis [Wed, 6 Nov 2019 22:31:02 +0000 (14:31 -0800)]
Add affine load/store/dma_start/dma_wait to dialect doc.

PiperOrigin-RevId: 278941483

4 years agoAdding an m_NonZero constant integer matcher.
Ben Vanik [Wed, 6 Nov 2019 21:51:19 +0000 (13:51 -0800)]
Adding an m_NonZero constant integer matcher.

This is useful for making matching cases where a non-zero value is required more readable, such as the results of a constant comparison that are expected to be equal.

PiperOrigin-RevId: 278932874

4 years agoAdd ViewOp verification for dynamic strides, and address some comments from previous...
Andy Davis [Wed, 6 Nov 2019 19:25:16 +0000 (11:25 -0800)]
Add ViewOp verification for dynamic strides, and address some comments from previous change.

PiperOrigin-RevId: 278903187

4 years ago[DRR] List some limitations clearly in the doc
Lei Zhang [Wed, 6 Nov 2019 17:56:01 +0000 (09:56 -0800)]
[DRR] List some limitations clearly in the doc

PiperOrigin-RevId: 278882517

4 years agoAdd ViewOp to the StandardOps dialect, which casts a 1D/i8 element type memref type...
Andy Davis [Wed, 6 Nov 2019 16:53:39 +0000 (08:53 -0800)]
Add ViewOp to the StandardOps dialect, which casts a 1D/i8 element type memref type to an N-D memref type.

Proposed in RFC: https://groups.google.com/a/tensorflow.org/forum/#!searchin/mlir/std.view%7Csort:date/mlir/-wKHANzDNTg/4K6nUAp8AAAJ

Supports creating the N-D memref type with dynamic sizes and at a dynamic offset within the 1D base memref.
This change contains op definition/parsing/printing and tests. Follow up changes will handle constant shape/layout map folding and llvm lowering.

PiperOrigin-RevId: 278869990

4 years agoAdd support for the LLVM FNeg instruction
Eric Schweitz [Wed, 6 Nov 2019 07:39:25 +0000 (23:39 -0800)]
Add support for the LLVM FNeg instruction

Closes tensorflow/mlir#216

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/216 from schweitzpgi:llvmir-fneg-op f9b5f185845d671b745ab6fc213d5d9aff044b34
PiperOrigin-RevId: 278795325

4 years agoNFC: Remove an extra space when printing the 'attributes' prefix before a dictionary.
River Riddle [Wed, 6 Nov 2019 07:39:21 +0000 (23:39 -0800)]
NFC: Remove an extra space when printing the 'attributes' prefix before a dictionary.
PiperOrigin-RevId: 278795313

4 years agoAdd (parse|print)OptionalAttrDictWithKeyword hooks to simplify parsing attribute...
River Riddle [Wed, 6 Nov 2019 01:58:16 +0000 (17:58 -0800)]
Add (parse|print)OptionalAttrDictWithKeyword hooks to simplify parsing attribute dictionaries with regions.

Many operations with regions add an additional 'attributes' prefix when printing the attribute dictionary to differentiate it from the region body. This leads to duplicated logic for detecting when to actually print the attribute dictionary.

PiperOrigin-RevId: 278747681

4 years agoFix typos in the Standard Dialect documentation
Roberto Rosmaninho [Wed, 6 Nov 2019 01:41:29 +0000 (17:41 -0800)]
Fix typos in the Standard Dialect documentation

"sgt" and "ult" used twice
the second "slt" should be "sge" for signed greater than or equal
the second "ult" should be "ule" unsigned less than or equal

Closes tensorflow/mlir#223

PiperOrigin-RevId: 278745410

4 years ago[llvm] Allow GlobalOp to take a region for complex initializers
James Molloy [Tue, 5 Nov 2019 23:10:28 +0000 (15:10 -0800)]
[llvm] Allow GlobalOp to take a region for complex initializers

This allows GlobalOp to either take a value attribute (for simple constants) or a region that can
contain IR instructions (that must be constant-foldable) to create a ConstantExpr initializer.

Example:
  // A complex initializer is constructed with an initializer region.
  llvm.mlir.global constant @int_gep() : !llvm<"i32*"> {
    %0 = llvm.mlir.addressof @g2 : !llvm<"i32*">
    %1 = llvm.mlir.constant(2 : i32) : !llvm.i32
    %2 = llvm.getelementptr %0[%1] : (!llvm<"i32*">, !llvm.i32) -> !llvm<"i32*">
    llvm.return %2 : !llvm<"i32*">
  }
PiperOrigin-RevId: 278717836

4 years ago[llvm] Add initial import of LLVM modules to mlir-translate
James Molloy [Tue, 5 Nov 2019 22:41:08 +0000 (14:41 -0800)]
[llvm] Add initial import of LLVM modules to mlir-translate

This adds an importer from LLVM IR or bitcode to the LLVM dialect. The importer is registered with mlir-translate.

Known issues exposed by this patch but not yet fixed:
  * Globals' initializers are attributes, which makes it impossible to represent a ConstantExpr. This will be fixed in a followup.
  * icmp returns i32 rather than i1.
  * select and a couple of other instructions aren't implemented.
  * llvm.cond_br takes its successors in a weird order.

The testing here is known to be non-exhaustive.

I'd appreciate feedback on where this functionality should live. It looks like the translator *from MLIR to LLVM* lives in Target/, but the SPIR-V deserializer lives in Dialect/ which is why I've put this here too.

PiperOrigin-RevId: 278711683

4 years agoNFC: Rename parseOptionalAttributeDict -> parseOptionalAttrDict to match the name...
River Riddle [Tue, 5 Nov 2019 21:32:07 +0000 (13:32 -0800)]
NFC: Rename parseOptionalAttributeDict -> parseOptionalAttrDict to match the name of the print method.
PiperOrigin-RevId: 278696668

4 years agoAdd a PatternRewriter hook to merge blocks, and use it to support for folding branches.
River Riddle [Tue, 5 Nov 2019 19:57:03 +0000 (11:57 -0800)]
Add a PatternRewriter hook to merge blocks, and use it to support for folding branches.

A pattern rewriter hook, mergeBlock, is added that allows for merging the operations of one block into the end of another. This is used to support a canonicalization pattern for branch operations that folds the branch when the successor has a single predecessor(the branch block).

Example:
  ^bb0:
    %c0_i32 = constant 0 : i32
    br ^bb1(%c0_i32 : i32)
  ^bb1(%x : i32):
    return %x : i32

becomes:
  ^bb0:
    %c0_i32 = constant 0 : i32
    return %c0_i32 : i32
PiperOrigin-RevId: 278677825

4 years agoEmit empty lines after headers when generating op docs
Lei Zhang [Tue, 5 Nov 2019 17:31:35 +0000 (09:31 -0800)]
Emit empty lines after headers when generating op docs

This makes the generated doc easier to read and it is also
more friendly to certain markdown parsers like kramdown.

Fixes tensorflow/mlir#221

PiperOrigin-RevId: 278643469

4 years agoRename Region::RegionType to Region::BlockListType
Sean Silva [Tue, 5 Nov 2019 16:34:44 +0000 (08:34 -0800)]
Rename Region::RegionType to Region::BlockListType

Region::RegionType doesn't make much sense when reading it. It's just a
list of blocks. So call it that.
PiperOrigin-RevId: 278632500

4 years ago[NVVM] Add mma.sync operation.
MLIR Team [Mon, 4 Nov 2019 20:36:04 +0000 (12:36 -0800)]
[NVVM] Add mma.sync operation.

PiperOrigin-RevId: 278440547

4 years agoUpdate the SPV dialect type parser to use the methods on DialectAsmParser directly.
River Riddle [Fri, 1 Nov 2019 23:54:48 +0000 (16:54 -0700)]
Update the SPV dialect type parser to use the methods on DialectAsmParser directly.

This simplifies the implementation quite a bit, and removes the need for explicit string munging. One change is made to some of the enum elements of SPV_DimAttr to ensure that they are proper identifiers; The string form is now prefixed with 'Dim'.

PiperOrigin-RevId: 278027132

4 years agoDrop spurious debug spew.
Nicolas Vasilache [Fri, 1 Nov 2019 23:31:30 +0000 (16:31 -0700)]
Drop spurious debug spew.

PiperOrigin-RevId: 278023371

4 years agoRefactor LinalgDialect::parseType to use the DialectAsmParser methods directly.
River Riddle [Fri, 1 Nov 2019 23:13:37 +0000 (16:13 -0700)]
Refactor LinalgDialect::parseType to use the DialectAsmParser methods directly.

This simplifies the implementation, and removes the need to do explicit string manipulation. A utility method 'parseDimensionList' is added to the DialectAsmParser to simplify defining types and attributes that contain shapes.

PiperOrigin-RevId: 278020604

4 years agoRefactor QuantOps TypeParser to use the DialectAsmParser methods directly.
River Riddle [Fri, 1 Nov 2019 22:46:28 +0000 (15:46 -0700)]
Refactor QuantOps TypeParser to use the DialectAsmParser methods directly.

This greatly simplifies the implementation and removes custom parser functionality. The necessary methods are added to the DialectAsmParser.

PiperOrigin-RevId: 278015983

4 years agoRemove the need for passing a location to parseAttribute/parseType.
River Riddle [Fri, 1 Nov 2019 22:39:30 +0000 (15:39 -0700)]
Remove the need for passing a location to parseAttribute/parseType.

Now that a proper parser is passed to these methods, there isn't a need to explicitly pass a source location. The source location can be recovered from the parser as necessary. This removes the need to explicitly decode an SMLoc in the case where we don't need to, which can be expensive.

This requires adding some basic nesting support to the parser for supporting nested parsers to allow for remapping source locations of the nested parsers to the top level parser for accurate diagnostics. This is due to the fact that the attribute and type parsers use different source buffers than the top level parser, as they may be represented in string form.

PiperOrigin-RevId: 278014858

4 years agoAdd DialectAsmParser/Printer classes to simplify dialect attribute and type parsing.
River Riddle [Fri, 1 Nov 2019 21:47:42 +0000 (14:47 -0700)]
Add DialectAsmParser/Printer classes to simplify dialect attribute and type parsing.

These classes are functionally similar to the OpAsmParser/Printer classes and provide hooks for parsing attributes/tokens/types/etc. This change merely sets up the base infrastructure and updates the parser hooks, followups will add hooks as needed to simplify existing handrolled dialect parsers.

This has various different benefits:
*) Attribute/Type parsing is much simpler to define.
*) Dialect attributes/types that contain other attributes/types can now use aliases.
*) It provides a 'spec' with which we may use in the future to auto-generate parsers/printers.
*) Error messages emitted by attribute/type parsers can provide character exact locations rather than "beginning of the string"

PiperOrigin-RevId: 278005322

4 years agoAdd ReferToOp attribute constraint for SymbolRefAttr
Lei Zhang [Fri, 1 Nov 2019 21:26:10 +0000 (14:26 -0700)]
Add ReferToOp attribute constraint for SymbolRefAttr

This constraint can be used to limit a SymbolRefAttr to point
to a specific kind of op in the closest parent with a symbol table.

PiperOrigin-RevId: 278001364

4 years agoDelete spurious file
Nicolas Vasilache [Fri, 1 Nov 2019 18:27:41 +0000 (11:27 -0700)]
Delete spurious file

PiperOrigin-RevId: 277967079

4 years agoMove BitEnumAttr from SPIRVBase.td to OpBase.td
Lei Zhang [Fri, 1 Nov 2019 18:17:23 +0000 (11:17 -0700)]
Move BitEnumAttr from SPIRVBase.td to OpBase.td

BitEnumAttr is a mechanism for modelling attributes whose value is
a bitfield. It should not be scoped to the SPIR-V dialect and can
be used by other dialects too.

This CL is mostly shuffling code around and adding tests and docs.
Functionality changes are:

* Fixed to use `getZExtValue()` instead of `getSExtValue()` when
  getting the value from the underlying IntegerAttr for a case.
* Changed to auto-detect whether there is a case whose value is
  all bits unset (i.e., zero). If so handle it specially in all
  helper methods.

PiperOrigin-RevId: 277964926

4 years agoSupport lowering of imperfectly nested loops into GPU dialect.
Mahesh Ravishankar [Fri, 1 Nov 2019 17:51:33 +0000 (10:51 -0700)]
Support lowering of imperfectly nested loops into GPU dialect.

The current lowering of loops to GPU only supports lowering of loop
nests where the loops mapped to workgroups and workitems are perfectly
nested. Here a new lowering is added to handle lowering of imperfectly
nested loop body with the following properties
1) The loops partitioned to workgroups are perfectly nested.
2) The loop body of the inner most loop partitioned to workgroups can
contain one or more loop nests that are to be partitioned across
workitems. Each individual loops nests partitioned to workitems should
also be perfectly nested.
3) The number of workgroups and workitems are not deduced from the
loop bounds but are passed in by the caller of the lowering as values.
4) For statements within the perfectly nested loop nest partitioned
across workgroups that are not loops, it is valid to have all threads
execute that statement. This is NOT verified.

PiperOrigin-RevId: 277958868

4 years agoAdd Linalg pattern for producer-consumer fusion
Nicolas Vasilache [Fri, 1 Nov 2019 15:29:42 +0000 (08:29 -0700)]
Add Linalg pattern for producer-consumer fusion

This CL adds a simple pattern for specifying producer-consumer fusion on Linalg operations.

Implementing such an extension reveals some interesting properties.
Since Linalg operates on a buffer abstraction, the output buffers are specified as in/out parameters to the ops. As a consequence, there are no SSA use-def chains and one cannot specify complex dag input patterns with the current infrastructure.

Instead this CL uses constraints based on the existing linalg dependence analysis to focus the pattern and refine patterns based on the type of op that last wrote in a buffer.

This is a very local property and is less powerful than the generic dag specification based on SSA use-def chains.

This will be generalized in the future.

PiperOrigin-RevId: 277931503

4 years ago[mlir][llvm] Add missing cast ops
James Molloy [Fri, 1 Nov 2019 14:31:33 +0000 (07:31 -0700)]
[mlir][llvm] Add missing cast ops

Also adds a builder method for fcmp, identical to that for icmp.

PiperOrigin-RevId: 277923158

4 years agoNFC: Use #ifndef in various .td files instead of #ifdef and #else
Lei Zhang [Thu, 31 Oct 2019 20:29:14 +0000 (13:29 -0700)]
NFC: Use #ifndef in various .td files instead of #ifdef and #else

Upstream LLVM gained support for #ifndef with https://reviews.llvm.org/D61888

This is changed mechanically via the following command:

find . -name "*.td" -exec sed -i -e ':a' -e 'N' -e '$!ba' -e 's/#ifdef \([A-Z_]*\)\n#else/#ifndef \1/g' {} \;

PiperOrigin-RevId: 277789427

4 years agoAdd a test for lowering GPU ops that cover cases where the symbol table isn't held...
Mehdi Amini [Thu, 31 Oct 2019 17:34:39 +0000 (10:34 -0700)]
Add a test for lowering GPU ops that cover cases where the symbol table isn't held by a ModuleOp (NFC)

PiperOrigin-RevId: 277752004

4 years agoAdd a test.symbol_scope operation that has the SymbolTable Traits to the Test dialect
Mehdi Amini [Thu, 31 Oct 2019 16:49:16 +0000 (09:49 -0700)]
Add a test.symbol_scope operation that has the SymbolTable Traits to the Test dialect

PiperOrigin-RevId: 277741687

4 years agoLinalgDependenceGraph: add const modifiers to accessors
Alex Zinenko [Thu, 31 Oct 2019 15:58:34 +0000 (08:58 -0700)]
LinalgDependenceGraph: add const modifiers to accessors

MLIR const-correctness policy is to avoid having `const` on IR objects.
LinalgDependenceGraph is not an IR object but an auxiliary data structure.
Furthermore, it is not updated once constructed unlike IR objects. Add const
qualifiers to get* and find* methods of LinalgDependenceGraph since they are
not modifying the graph. This allows transformation functions that require the
dependence graph to take it by const-reference, clearly indicating that they
are not modifying it (and that the graph may have to be recomputed after the
transformation).

PiperOrigin-RevId: 277731608

4 years agoNFC: Simplify UseRange::iterator to just be a std::vector::const_iterator.
River Riddle [Wed, 30 Oct 2019 22:25:35 +0000 (15:25 -0700)]
NFC: Simplify UseRange::iterator to just be a std::vector::const_iterator.

At some point the implementation of UseRange was more complex, but now it is just a simple wrapper around a std::vector<SymbolUse>.

PiperOrigin-RevId: 277597294

4 years ago[spirv] Add cast operations
Denis Khalikov [Wed, 30 Oct 2019 21:41:26 +0000 (14:41 -0700)]
[spirv] Add cast operations

This CL added op definitions for a few cast operations:

* OpConvertFToU
* OpConvertFToS
* OpConvertSToF
* OpConvertUToF
* OpUConvert
* OpSConvert
* OpFConvert

Also moved the definition of spv.Bitcast to the new file.

Closes tensorflow/mlir#208 and tensorflow/mlir#174

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/208 from denis0x0D:sandbox/cast_ops 79bc9b37398aafddee6cf6beb301807988fe67f9
PiperOrigin-RevId: 277587891

4 years agoUse `not` to invert return code in expected to fail tests
Lei Zhang [Wed, 30 Oct 2019 21:37:45 +0000 (14:37 -0700)]
Use `not` to invert return code in expected to fail tests

Windows does not like the RUN command of `(... || true) | ...`.

PiperOrigin-RevId: 277587031

4 years agoDump op location in createPrintOpGraphPass for easier debugging.
Jing Pu [Wed, 30 Oct 2019 18:21:54 +0000 (11:21 -0700)]
Dump op location in createPrintOpGraphPass for easier debugging.

PiperOrigin-RevId: 277546527

4 years agoAdd support to GreedyPatternRewriter for erasing unreachable blocks.
River Riddle [Wed, 30 Oct 2019 18:18:51 +0000 (11:18 -0700)]
Add support to GreedyPatternRewriter for erasing unreachable blocks.

Rewrite patterns may make modifications to the CFG, including dropping edges between blocks. This change adds a simple unreachable block elimination run at the end of each iteration to ensure that the CFG remains valid.

PiperOrigin-RevId: 277545805

4 years agoAdd a utility accessor 'has_single_element' for ranges.
River Riddle [Wed, 30 Oct 2019 18:13:52 +0000 (11:13 -0700)]
Add a utility accessor 'has_single_element' for ranges.

This provides an easy way to check if a range has a single element.

PiperOrigin-RevId: 277544647

4 years agoFix segfault when no symbol is given to an constraint operand
Lei Zhang [Wed, 30 Oct 2019 18:12:21 +0000 (11:12 -0700)]
Fix segfault when no symbol is given to an constraint operand

This fixed the segfault when we see the following pattern:
  Pat<(...), (...), [(... 1, 2, 3), ...]>

PiperOrigin-RevId: 277544300

4 years agoAdd basic support for declarative Linalg transformations
Nicolas Vasilache [Wed, 30 Oct 2019 14:12:07 +0000 (07:12 -0700)]
Add basic support for declarative Linalg transformations

Linalg ops provide a good anchor for pattern matching/rewriting transformations.
This CL adds a simple example of how multi-level tiling may be specified by attaching a simple StringAttr to ops as they are transformed so we can easily specify partial lowering to control transformation application.

This is a first stab at taking advantage of higher-level information contained in Linalg ops and will evolve in the future.

PiperOrigin-RevId: 277497958

4 years ago[spirv] Fix gen_spirv_dialect.py and add spv.Unreachable
Lei Zhang [Wed, 30 Oct 2019 12:40:47 +0000 (05:40 -0700)]
[spirv] Fix gen_spirv_dialect.py and add spv.Unreachable

This CL fixed gen_spirv_dialect.py to support nested delimiters when
chunking existing ODS entries in .td files and to allow ops without
correspondence in the spec. This is needed to pull in the definition
of OpUnreachable.

PiperOrigin-RevId: 277486465

4 years ago[spirv] Mark control flow ops as InFunctionScope
Lei Zhang [Tue, 29 Oct 2019 22:06:10 +0000 (15:06 -0700)]
[spirv] Mark control flow ops as InFunctionScope

PiperOrigin-RevId: 277373473

4 years agoAdd "[TOC]" to generated documentation
MLIR Team [Tue, 29 Oct 2019 20:38:32 +0000 (13:38 -0700)]
Add "[TOC]" to generated documentation

PiperOrigin-RevId: 277354482

4 years agoBugfix: Keep worklistMap in sync with worklist in GreedyPatternRewriter
Diego Caballero [Tue, 29 Oct 2019 17:57:56 +0000 (10:57 -0700)]
Bugfix: Keep worklistMap in sync with worklist in GreedyPatternRewriter

When we removed a pattern, we removed it from worklist but not from
worklistMap. Then, when we tried to add a new pattern on the same Operation
again, the pattern wasn't added since it already existed in the
worklistMap (but not in the worklist).

Closes tensorflow/mlir#211

PiperOrigin-RevId: 277319669

4 years ago[spirv] Use LLVM graph traversal utility for PrettyBlockOrderVisitor
Lei Zhang [Tue, 29 Oct 2019 14:03:26 +0000 (07:03 -0700)]
[spirv] Use LLVM graph traversal utility for PrettyBlockOrderVisitor

This removes a bunch of special tailored DFS code in favor of the common
LLVM utility. Besides, we avoid recursion with system stack given that
llvm::depth_first_ext is iterator based and maintains its own stack.
PiperOrigin-RevId: 277272961

4 years agoAdd a convenient operation build method for spirv::SelectOp
Mahesh Ravishankar [Tue, 29 Oct 2019 06:03:54 +0000 (23:03 -0700)]
Add a convenient operation build method for spirv::SelectOp

The SelectOp always has the same result type as its true/false
value. Add a builder method that uses the operand type to get the
result type.

PiperOrigin-RevId: 277217978

4 years ago[spirv] Support OpPhi using block arguments
Lei Zhang [Mon, 28 Oct 2019 22:58:11 +0000 (15:58 -0700)]
[spirv] Support OpPhi using block arguments

This CL adds another control flow instruction in SPIR-V: OpPhi.
It is modelled as block arguments to be idiomatic with MLIR.
See the rationale.md doc for "Block Arguments vs PHI nodes".
Serialization and deserialization is updated to convert between
block arguments and SPIR-V OpPhi instructions.

PiperOrigin-RevId: 277161545

4 years agoParse locations in parseGenericOperation
Sean Silva [Mon, 28 Oct 2019 22:11:00 +0000 (15:11 -0700)]
Parse locations in parseGenericOperation

For ops that recursively re-enter the parser to parse an operation (such as
ops with a "wraps" pretty form), this ensures that the wrapped op will parse
its location, which can then be used for the locations of the wrapping op
and any other implicit ops.

PiperOrigin-RevId: 277152636

4 years agoStandardize Linalg transformations to take an OpBuilder and an OperationFolder - NFC
Nicolas Vasilache [Mon, 28 Oct 2019 21:55:43 +0000 (14:55 -0700)]
Standardize Linalg transformations to take an OpBuilder and an OperationFolder - NFC

This will be used to specify declarative Linalg transformations in a followup CL. In particular, the PatternRewrite mechanism does not allow folding and has its own way of tracking erasure.

PiperOrigin-RevId: 277149158

4 years agoAdd support for marking an operation as recursively legal.
River Riddle [Mon, 28 Oct 2019 17:03:57 +0000 (10:03 -0700)]
Add support for marking an operation as recursively legal.

In some cases, it may be desirable to mark entire regions of operations as legal. This provides an additional granularity of context to the concept of "legal". The `ConversionTarget` supports marking operations, that were previously added as `Legal` or `Dynamic`, as `recursively` legal. Recursive legality means that if an operation instance is legal, either statically or dynamically, all of the operations nested within are also considered legal. An operation can be marked via `markOpRecursivelyLegal<>`:

```c++
ConversionTarget &target = ...;

/// The operation must first be marked as `Legal` or `Dynamic`.
target.addLegalOp<MyOp>(...);
target.addDynamicallyLegalOp<MySecondOp>(...);

/// Mark the operation as always recursively legal.
target.markOpRecursivelyLegal<MyOp>();
/// Mark optionally with a callback to allow selective marking.
target.markOpRecursivelyLegal<MyOp, MySecondOp>([](Operation *op) { ... });
/// Mark optionally with a callback to allow selective marking.
target.markOpRecursivelyLegal<MyOp>([](MyOp op) { ... });
```

PiperOrigin-RevId: 277086382

4 years agoPrint reason why dynamic library could not be loaded during execution.
Christian Sigg [Mon, 28 Oct 2019 11:24:43 +0000 (04:24 -0700)]
Print reason why dynamic library could not be loaded during execution.

PiperOrigin-RevId: 277037138

4 years agoLookup function declaration in SymbolTable not ModuleOp.
Alexander Belyaev [Mon, 28 Oct 2019 10:45:00 +0000 (03:45 -0700)]
Lookup function declaration in SymbolTable not ModuleOp.

PiperOrigin-RevId: 277033167

4 years agoFix include guards and add tests for OpToFuncCallLowering.
Alexander Belyaev [Sat, 26 Oct 2019 15:20:59 +0000 (08:20 -0700)]
Fix include guards and add tests for OpToFuncCallLowering.

PiperOrigin-RevId: 276859463

4 years agoDefine AnyRankedTensor Type in TableGen
Smit Hinsu [Fri, 25 Oct 2019 17:31:26 +0000 (10:31 -0700)]
Define AnyRankedTensor Type in TableGen

PiperOrigin-RevId: 276714649

4 years agoAdd support for parsing multiple result name groups.
River Riddle [Fri, 25 Oct 2019 16:33:32 +0000 (09:33 -0700)]
Add support for parsing multiple result name groups.

This allows for parsing things like:

%name_1, %name_2:5, %name_3:2 = "my.op" ...

This is useful for operations that have groups of variadic result values. The
total number of results is expected to match the number of results defined by
the operation.

PiperOrigin-RevId: 276703280

4 years ago[spirv] AccessChainOp canonicalization.
Denis Khalikov [Fri, 25 Oct 2019 01:40:38 +0000 (18:40 -0700)]
[spirv] AccessChainOp canonicalization.

Combine chained `spirv::AccessChainOp` operations into one
`spirv::AccessChainOp` operation.

Closes tensorflow/mlir#198

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/198 from denis0x0D:sandbox/canon_access_chain 0cb87955a85511071143d62637ff939d0dabc2bd
PiperOrigin-RevId: 276609345

4 years agoConvert the Canonicalize and CSE passes to generic Operation Passes.
River Riddle [Thu, 24 Oct 2019 22:00:36 +0000 (15:00 -0700)]
Convert the Canonicalize and CSE passes to generic Operation Passes.

This allows for them to be used on other non-function, or even other function-like, operations. The algorithms are already generic, so this is simply changing the derived pass type. The majority of this change is just ensuring that the nesting of these passes remains the same, as the pass manager won't auto-nest them anymore.

PiperOrigin-RevId: 276573038

4 years agoAdd support for replacing all uses of a symbol.
River Riddle [Thu, 24 Oct 2019 17:46:47 +0000 (10:46 -0700)]
Add support for replacing all uses of a symbol.

This requires reconstructing the attribute dictionary of each operation containing a use.

PiperOrigin-RevId: 276520544

4 years agoAdd missing dependency on MLIRIR on MLIREDSCInterface
Mehdi Amini [Thu, 24 Oct 2019 17:37:18 +0000 (10:37 -0700)]
Add missing dependency on MLIRIR on MLIREDSCInterface

MLIRIR includes generated header for interfaces, including these headers require
an extra dependency to ensure these headers are generated before we attempt to
build MLIREDSCInterface.

PiperOrigin-RevId: 276518255

4 years agoAdd custom lowering of ExpOp for NVVM and ROCM.
Alexander Belyaev [Thu, 24 Oct 2019 08:41:25 +0000 (01:41 -0700)]
Add custom lowering of ExpOp for NVVM and ROCM.

PiperOrigin-RevId: 276440911