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

5 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

5 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

5 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

5 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

5 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

5 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

5 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

5 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

5 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

5 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

5 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

5 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

5 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

5 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

5 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

5 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

5 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

5 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

5 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

5 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

5 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

5 years agoWrap ODS to 80 lines and remove const qualifier for local `int` variable (NFC)
Alexander Belyaev [Thu, 24 Oct 2019 05:18:58 +0000 (22:18 -0700)]
Wrap ODS to 80 lines and remove const qualifier for local `int` variable (NFC)

This addresses post-submit comments on 00d2a37e32

PiperOrigin-RevId: 276419770

5 years agoAdd @below and @above directives to verify-diagnostics.
River Riddle [Wed, 23 Oct 2019 22:56:02 +0000 (15:56 -0700)]
Add @below and @above directives to verify-diagnostics.

This simplifies defining expected-* directives when there are multiple that apply to the next or previous line. @below applies the directive to the next non-designator line, i.e. the next line that does not contain an expected-* designator. @above applies to the previous non designator line.

Examples:

// Expect an error on the next line that does not contain a designator.
// expected-remark@below {{remark on function below}}
// expected-remark@below {{another remark on function below}}
func @bar(%a : f32)

// Expect an error on the previous line that does not contain a designator.
func @baz(%a : f32)
// expected-remark@above {{remark on function above}}
// expected-remark@above {{another remark on function above}}

PiperOrigin-RevId: 276369085

5 years agoFix "set-but-unused" warning in DialectConversion
Alex Zinenko [Wed, 23 Oct 2019 21:31:44 +0000 (14:31 -0700)]
Fix "set-but-unused" warning in DialectConversion

The variable in question is only used in an assertion,
leading to a warning in opt builds.

PiperOrigin-RevId: 276352259

5 years agoNFC: Remove references to the toy.generic attribute.
River Riddle [Wed, 23 Oct 2019 21:30:01 +0000 (14:30 -0700)]
NFC: Remove references to the toy.generic attribute.

This was used for shape inference in the previous tutorial flow.

PiperOrigin-RevId: 276351916

5 years agoDrop MemRefUtils from the ExecutionEngine
Alex Zinenko [Wed, 23 Oct 2019 14:42:37 +0000 (07:42 -0700)]
Drop MemRefUtils from the ExecutionEngine

The ExecutionEngine was updated recently to only take the LLVM dialect as
input. Memrefs are no longer expected in the signature of the entry point
function by the executor so there is no need to allocate and free them. The
code in MemRefUtils is therefore dead and furthermore out of sync with the
recent evolution of memref type to support strides. Drop it.

PiperOrigin-RevId: 276272302

5 years agoUpdate chapter 3 code snippet to match the actual output of the code
MLIR Team [Tue, 22 Oct 2019 19:17:59 +0000 (12:17 -0700)]
Update chapter 3 code snippet to match the actual output of the code

PiperOrigin-RevId: 276117540

5 years agoUpdate loop.for verifier message
Uday Bondhugula [Tue, 22 Oct 2019 14:34:24 +0000 (07:34 -0700)]
Update loop.for verifier message

fix: nonnegative -> positive

Closes tensorflow/mlir#206

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/206 from bondhugula:bondhugula-patch-1 9a47ca7dfd230180a9df33e9a64b33d02252d30a
PiperOrigin-RevId: 276060885

5 years agoExpose optimizations flags in Python bindings
Alex Zinenko [Tue, 22 Oct 2019 14:31:18 +0000 (07:31 -0700)]
Expose optimizations flags in Python bindings

ExecutionEngine currently supports additional parameters that can be used to
run LLVM transformations during JIT compilation. Expose this to Python
bindings. When the ExecutionEngine functionality is moved to LLVM, the
bindings-specific code can be updated to interact with LLVM.

PiperOrigin-RevId: 276060475

5 years agoNFC: Remove a right parenthesis from comment.
Hanhan Wang [Tue, 22 Oct 2019 05:44:16 +0000 (22:44 -0700)]
NFC: Remove a right parenthesis from comment.
PiperOrigin-RevId: 275998781

5 years agoNFC: Add support for parsing attributes programmatically via mlir::parseAttribute.
River Riddle [Tue, 22 Oct 2019 04:34:21 +0000 (21:34 -0700)]
NFC: Add support for parsing attributes programmatically via mlir::parseAttribute.

This matches the behavior of the public mlir::parseType, and even uses the internal implementation.

PiperOrigin-RevId: 275989777

5 years ago[DRR] Allow interleaved operands and attributes
Lei Zhang [Tue, 22 Oct 2019 03:47:49 +0000 (20:47 -0700)]
[DRR] Allow interleaved operands and attributes

Previously DRR assumes attributes to appear after operands. This was the
previous requirements on ODS, but that has changed some time ago. Fix
DRR to also support interleaved operands and attributes.

PiperOrigin-RevId: 275983485

5 years ago[spirv] Allow block arguments on spv.Branch(Conditional)
Lei Zhang [Tue, 22 Oct 2019 00:31:32 +0000 (17:31 -0700)]
[spirv] Allow block arguments on spv.Branch(Conditional)

We will use block arguments as the way to model SPIR-V OpPhi in
the SPIR-V dialect.

This CL also adds a few useful helper methods to both ops to
get the block arguments.

Also added tests for branch weight (de)serialization.

PiperOrigin-RevId: 275960797

5 years agoUse LLVM_Type instead of AnyType in the definition of LLVM_CallOp
Alex Zinenko [Mon, 21 Oct 2019 21:11:50 +0000 (14:11 -0700)]
Use LLVM_Type instead of AnyType in the definition of LLVM_CallOp

The type constraint had to be relaxed due to the order of lowering passes in
the examples, that since has been fixed. The relaxed version was still used by
the CUDA lowering for launch sizes of `index` type. This is not necessary since
the GPU dialect does not restrict the type of the launch size operands. Use an
LLVM type instead and restore the check in the LLVM_CallOp definition.

PiperOrigin-RevId: 275920109

5 years agoCleanup and rewrite Ch-4.md.
River Riddle [Mon, 21 Oct 2019 18:31:59 +0000 (11:31 -0700)]
Cleanup and rewrite Ch-4.md.

This change rewrites Ch-4.md to introduced interfaces in a detailed step-by-step manner, adds examples, and fixes some errors.

PiperOrigin-RevId: 275887017

5 years agoNFC: Fix remaining usages of MulOp as matrix multiplication.
River Riddle [Mon, 21 Oct 2019 18:30:58 +0000 (11:30 -0700)]
NFC: Fix remaining usages of MulOp as matrix multiplication.

MulOp now represents an element-wise multiplication instead of a matrix multiplication.

PiperOrigin-RevId: 275886774

5 years agoUnify GPU op definition names with other dialects.
Christian Sigg [Mon, 21 Oct 2019 18:10:13 +0000 (11:10 -0700)]
Unify GPU op definition names with other dialects.

Rename GPU op names from gpu_Foo to GPU_FooOp.

PiperOrigin-RevId: 275882232

5 years agoNFC: Elide the value of a UnitAttr within nested attribute dictionaries.
River Riddle [Mon, 21 Oct 2019 18:01:38 +0000 (11:01 -0700)]
NFC: Elide the value of a UnitAttr within nested attribute dictionaries.

This matches the behavior of the top level attribute dictionary.

PiperOrigin-RevId: 275879828

5 years agoAdd a Symbol trait to simplify defining operations that represent symbols.
River Riddle [Mon, 21 Oct 2019 16:58:22 +0000 (09:58 -0700)]
Add a Symbol trait to simplify defining operations that represent symbols.

This trait provides accessors for the name, symbol use list methods, verification, with more to be added.

PiperOrigin-RevId: 275864554

5 years agoNFC: Fix typo : Retur -> Return
River Riddle [Sun, 20 Oct 2019 22:12:45 +0000 (15:12 -0700)]
NFC: Fix typo : Retur -> Return
PiperOrigin-RevId: 275745931

5 years agoUpdate Ch1 to reflect new changes in the tutorial.
River Riddle [Sun, 20 Oct 2019 21:59:59 +0000 (14:59 -0700)]
Update Ch1 to reflect new changes in the tutorial.

The chapter list is out of date, as well as mentions of matrix multiplication(now element-wise multiplication).

PiperOrigin-RevId: 275744911

5 years ago[DRR] Address GCC warning by wrapping for statement body with {}
Lei Zhang [Sun, 20 Oct 2019 19:23:38 +0000 (12:23 -0700)]
[DRR] Address GCC warning by wrapping for statement body with {}

Otherwise, we'll see the following warning when compiling with GCC 8:

warning: this ?for? clause does not guard... [-Wmisleading-indentation]
PiperOrigin-RevId: 275735925

5 years agoFix minor spelling tweaks (NFC)
Kazuaki Ishizaki [Sun, 20 Oct 2019 16:44:06 +0000 (09:44 -0700)]
Fix minor spelling tweaks (NFC)

Closes tensorflow/mlir#175

PiperOrigin-RevId: 275726876

5 years agoFix minor spelling tweaks (NFC)
Kazuaki Ishizaki [Sun, 20 Oct 2019 07:11:03 +0000 (00:11 -0700)]
Fix minor spelling tweaks (NFC)

Closes tensorflow/mlir#177

PiperOrigin-RevId: 275692653

5 years agoAdd SourceMgrDiagnosticHandler to toy
Jacques Pienaar [Sat, 19 Oct 2019 21:36:07 +0000 (14:36 -0700)]
Add SourceMgrDiagnosticHandler to toy

PiperOrigin-RevId: 275659433

5 years agoAdd missing include to StringMap in Verifier and DialectConversion.
Jacques Pienaar [Sat, 19 Oct 2019 20:38:31 +0000 (13:38 -0700)]
Add missing include to StringMap in Verifier and DialectConversion.

PiperOrigin-RevId: 275656416

5 years agoAdd missing include to llvm Allocator.h
Mehdi Amini [Sat, 19 Oct 2019 19:10:34 +0000 (12:10 -0700)]
Add missing include to llvm Allocator.h

This header is not self-contained otherwise.

PiperOrigin-RevId: 275651582

5 years agoSlight rewording in toy ch2 to make persistence of name clearer
Jacques Pienaar [Sat, 19 Oct 2019 18:59:31 +0000 (11:59 -0700)]
Slight rewording in toy ch2 to make persistence of name clearer

PiperOrigin-RevId: 275650756

5 years agoUse new eraseOp instead of replaceOp with empty values
Geoffrey Martin-Noble [Sat, 19 Oct 2019 13:03:50 +0000 (06:03 -0700)]
Use new eraseOp instead of replaceOp with empty values

PiperOrigin-RevId: 275631166

5 years agoGet active source lane predicate from shuffle instruction.
Christian Sigg [Sat, 19 Oct 2019 08:52:51 +0000 (01:52 -0700)]
Get active source lane predicate from shuffle instruction.

nvvm.shfl.sync.bfly optionally returns a predicate whether source lane was active. Support for this was added to clang in https://reviews.llvm.org/D68892.

Add an optional 'pred' unit attribute to the instruction to return this predicate. Specify this attribute in the partial warp reduction so we don't need to manually compute the predicate.

PiperOrigin-RevId: 275616564

5 years agoNFC: Cleanup the implementation of walkSymbolUses.
River Riddle [Sat, 19 Oct 2019 04:28:47 +0000 (21:28 -0700)]
NFC: Cleanup the implementation of walkSymbolUses.

Refactor the implementation to be much cleaner by adding a `make_second_range` utility to walk the `second` value of a range of pairs.

PiperOrigin-RevId: 275598985

5 years agoNFC: Add missing include for StringMap.
River Riddle [Sat, 19 Oct 2019 02:20:29 +0000 (19:20 -0700)]
NFC: Add missing include for StringMap.
PiperOrigin-RevId: 275588019

5 years agoNFC: Rename SPIR-V serializer find*ID() to get*ID() to be consistent
Lei Zhang [Sat, 19 Oct 2019 01:15:28 +0000 (18:15 -0700)]
NFC: Rename SPIR-V serializer find*ID() to get*ID() to be consistent

We use get*() in deserizer and other places across the codebase.

PiperOrigin-RevId: 275582390

5 years agoAdd support for function result attributes.
Sean Silva [Fri, 18 Oct 2019 23:02:56 +0000 (16:02 -0700)]
Add support for function result attributes.

This allows dialect-specific attributes to be attached to func results. (or more specifically, FunctionLike ops).

For example:

```
func @f() -> (i32 {my_dialect.some_attr = 3})
```

This attaches my_dialect.some_attr with value 3 to the first result of func @f.

Another more complex example:

```
func @g() -> (i32, f32 {my_dialect.some_attr = "foo", other_dialect.some_other_attr = [1,2,3]}, i1)
```

Here, the second result has two attributes attached.

PiperOrigin-RevId: 275564165

5 years agoLower vector transfer ops to loop.for operations.
Nicolas Vasilache [Fri, 18 Oct 2019 21:09:42 +0000 (14:09 -0700)]
Lower vector transfer ops to loop.for operations.

This allows mixing linalg operations with vector transfer operations (with additional modifications to affine ops) and is a step towards solving tensorflow/mlir#189.

PiperOrigin-RevId: 275543361

5 years agoImplement lowering of VectorTypeCastOp to LLVM
Nicolas Vasilache [Fri, 18 Oct 2019 20:48:26 +0000 (13:48 -0700)]
Implement lowering of VectorTypeCastOp to LLVM

A VectorTypeCastOp can only be used to lower between statically sized contiguous memrefs of scalar and matching vector type. The sizes and strides are thus fully static and easy to determine.

A relevant test is added.

This is a step towards solving tensorflow/mlir#189.

PiperOrigin-RevId: 275538981

5 years agoSlightly rephrase a difficult-to-parse sentence.
reinerp [Fri, 18 Oct 2019 17:28:02 +0000 (10:28 -0700)]
Slightly rephrase a difficult-to-parse sentence.

PiperOrigin-RevId: 275499524

5 years ago[DRR] Use eraseOp() to replace no-result ops
Lei Zhang [Fri, 18 Oct 2019 15:19:54 +0000 (08:19 -0700)]
[DRR] Use eraseOp() to replace no-result ops

PiperOrigin-RevId: 275475229

5 years agoAutomated rollback of commit 575405f4d6762830c1c4520569de4e4ed3c8eed5
Nicolas Vasilache [Fri, 18 Oct 2019 13:44:41 +0000 (06:44 -0700)]
Automated rollback of commit 575405f4d6762830c1c4520569de4e4ed3c8eed5

PiperOrigin-RevId: 275461067

5 years agoFix OSS target name GPUtoNVVMTransforms -> MLIRGPUtoNVVMTransforms
Nicolas Vasilache [Fri, 18 Oct 2019 12:22:12 +0000 (05:22 -0700)]
Fix OSS target name GPUtoNVVMTransforms -> MLIRGPUtoNVVMTransforms

This unbreaks the `cmake -G Ninja ../llvm -DLLVM_BUILD_EXAMPLES=ON -DLLVM_TARGETS_TO_BUILD="host"`
 in my local OSS build

PiperOrigin-RevId: 275452330

5 years agoUse StrEnumAttr for gpu.allreduce op instead of StringAttr to better encode constraints.
Stephan Herhut [Fri, 18 Oct 2019 11:44:15 +0000 (04:44 -0700)]
Use StrEnumAttr for gpu.allreduce op instead of StringAttr to better encode constraints.

PiperOrigin-RevId: 275448372

5 years agoAdd documentation on restrictions to dialect conversion rewrites
Geoffrey Martin-Noble [Fri, 18 Oct 2019 09:40:06 +0000 (02:40 -0700)]
Add documentation on restrictions to dialect conversion rewrites

PiperOrigin-RevId: 275435593

5 years agoAdd gpu.barrier op to synchronize invocations of a local workgroup.
Christian Sigg [Fri, 18 Oct 2019 07:30:14 +0000 (00:30 -0700)]
Add gpu.barrier op to synchronize invocations of a local workgroup.

Adding gen table for rewrite patterns from GPU to NVVM dialect.

Copy missing op documentation from GPUOps.td to GPU.md.

PiperOrigin-RevId: 275419588

5 years agoNFC: Remove trivial builder get methods.
River Riddle [Fri, 18 Oct 2019 03:08:01 +0000 (20:08 -0700)]
NFC: Remove trivial builder get methods.

These don't add any value, and some are even more restrictive than the respective static 'get' method.

PiperOrigin-RevId: 275391240

5 years agoAutomated rollback of commit b65c8bb5d6ab418bb3fcd0302aee19d3615d90f1
River Riddle [Fri, 18 Oct 2019 00:11:06 +0000 (17:11 -0700)]
Automated rollback of commit b65c8bb5d6ab418bb3fcd0302aee19d3615d90f1

PiperOrigin-RevId: 275370861

5 years agoIntroduce a wrapper around ConversionPattern that operates on the derived class
Geoffrey Martin-Noble [Thu, 17 Oct 2019 22:18:31 +0000 (15:18 -0700)]
Introduce a wrapper around ConversionPattern that operates on the derived class

Analogous to OpRewritePattern, this makes writing conversion patterns more convenient.

PiperOrigin-RevId: 275349854

5 years agoAdd EDSC support for loop.for operations
Nicolas Vasilache [Thu, 17 Oct 2019 22:18:07 +0000 (15:18 -0700)]
Add EDSC support for loop.for operations

This CL adds support for loop.for operations in EDSC and adds a test.
This will be used in a followup commit to implement lowering of vector_transfer ops so that it works more generally and is not subject to affine constraints.

PiperOrigin-RevId: 275349796

5 years agoNFC: Delete the Linalg tutorial.
River Riddle [Thu, 17 Oct 2019 21:27:08 +0000 (14:27 -0700)]
NFC: Delete the Linalg tutorial.

This part of the tutorial is now covered by a new flow in Toy. This also removes a point of confusion as there is also a proper Linalg dialect.

PiperOrigin-RevId: 275338933

5 years agoAdd Ch.6 of the Toy tutorial.
River Riddle [Thu, 17 Oct 2019 21:21:44 +0000 (14:21 -0700)]
Add Ch.6 of the Toy tutorial.

This chapters introduces the notion of a full conversion, and adds support for lowering down to the LLVM dialect, LLVM IR, and thus code generation.

PiperOrigin-RevId: 275337786

5 years agoDecouple Linalg promotion from Linalg tiling - NFC
Nicolas Vasilache [Thu, 17 Oct 2019 20:40:48 +0000 (13:40 -0700)]
Decouple Linalg promotion from Linalg tiling - NFC

This CL creates a new Linalg promotion pass that operates on SubViewOp and decouples it from Linalg tiling. This is mostly moving code around.

PiperOrigin-RevId: 275329213

5 years ago[spirv] Add a canonicalization pattern for spv.selection.
Denis Khalikov [Thu, 17 Oct 2019 19:25:14 +0000 (12:25 -0700)]
[spirv] Add a canonicalization pattern for spv.selection.

Add a canonicalization pattern for spv.selection operation.
Convert spv.selection operation to spv.Select based on
simple pattern.

Closes tensorflow/mlir#183

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/183 from denis0x0D:sandbox/canon_select 43d04d923272dd60b9da39f70bdbc51a5168db62
PiperOrigin-RevId: 275312748

5 years agoAllow '_' when pretty printing dialect symbols
Lei Zhang [Thu, 17 Oct 2019 19:23:47 +0000 (12:23 -0700)]
Allow '_' when pretty printing dialect symbols

'_' is used frequently enough as the separator of words in symbols.
We should allow it in dialect symbols when considering pretty printing.

Also updated LangRef.md regarding pretty form.

PiperOrigin-RevId: 275312494

5 years agoRename LoopNestBuilder to AffineLoopNestBuilder - NFC
Nicolas Vasilache [Thu, 17 Oct 2019 19:13:25 +0000 (12:13 -0700)]
Rename LoopNestBuilder to AffineLoopNestBuilder - NFC

PiperOrigin-RevId: 275310747

5 years agoUse a SmallVector instead of an ArrayRef to materialize a temporary local array
Mehdi Amini [Thu, 17 Oct 2019 16:58:58 +0000 (09:58 -0700)]
Use a SmallVector instead of an ArrayRef to materialize a temporary local array

This pattern is error prone and unfortunately none of the sanitizer is catching
it at the moment.

Fixes tensorflow/mlir#192

Closes tensorflow/mlir#193

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/193 from joker-eph:fix_array_ref 8092252e64c426c6a8a790b7638f847bea4818b1
PiperOrigin-RevId: 275280201

5 years ago[DRR] Allow capturing and referencing no-result ops
Lei Zhang [Thu, 17 Oct 2019 16:01:56 +0000 (09:01 -0700)]
[DRR] Allow capturing and referencing no-result ops

Previously when we bind a symbol to an op in DRR, it means to capture
the op's result(s) and later references will be expanded to result(s).
This means for ops without result, we are replacing the symbol with
nothing. This CL treats non-result op capturing and referencing as a
special case to mean the op itself.

PiperOrigin-RevId: 275269702

5 years agoFix RewriterGen to support using NativeCodeCall as auxiliary pattern
Lei Zhang [Thu, 17 Oct 2019 15:39:13 +0000 (08:39 -0700)]
Fix RewriterGen to support using NativeCodeCall as auxiliary pattern

NativeCodeCall is handled differently than normal op creation in RewriterGen
(because its flexibility). It will only be materialized to output stream if
it is used. But when using it for auxiliary patterns, we still want the side
effect even if it is not replacing matched root op's results.

PiperOrigin-RevId: 275265467

5 years agoAdd LLVM_DEBUG in RewritersGen.cpp and Pattern.cpp
Lei Zhang [Thu, 17 Oct 2019 14:25:50 +0000 (07:25 -0700)]
Add LLVM_DEBUG in RewritersGen.cpp and Pattern.cpp

It's usually hard to understand what went wrong if mlir-tblgen
crashes on some input. This CL adds a few useful LLVM_DEBUG
statements so that we can use mlir-tblegn -debug to figure
out the culprit for a crash.

PiperOrigin-RevId: 275253532

5 years agoFix invalid transpose in example and add proper verification.
River Riddle [Thu, 17 Oct 2019 05:25:23 +0000 (22:25 -0700)]
Fix invalid transpose in example and add proper verification.

The transpose in the example had the same result type as its input, which is incorrect.

PiperOrigin-RevId: 275186568

5 years ago[spirv] Implement inliner interface
Lei Zhang [Thu, 17 Oct 2019 00:36:58 +0000 (17:36 -0700)]
[spirv] Implement inliner interface

We just need to implement a few interface hooks to DialectInlinerInterface
and CallOpInterface to gain the benefits of an inliner. :)

Right now only supports some trivial cases:
* Inlining single block with spv.Return/spv.ReturnValue
* Inlining multi block with spv.Return
* Inlining spv.selection/spv.loop without return ops

More advanced cases will require block argument and Phi support.

PiperOrigin-RevId: 275151132

5 years agoAdd Ch.5 of the toy tutorial.
River Riddle [Thu, 17 Oct 2019 00:33:34 +0000 (17:33 -0700)]
Add Ch.5 of the toy tutorial.

This chapter adds a partial lowering of toy operations, all but PrintOp, to a combination of the Affine and Std dialects. This chapter focuses on introducing the conversion framework, the benefits of partial lowering, and how easily dialects may co-exist in the IR.

PiperOrigin-RevId: 275150649

5 years agoAdd support for inlining toy call operations.
River Riddle [Thu, 17 Oct 2019 00:32:30 +0000 (17:32 -0700)]
Add support for inlining toy call operations.

The GenericCallOp needed to have the CallOpInterface to be picked up by the inliner. This also adds a CastOp to perform shape casts that are generated during inlining. The casts generated by the inliner will be folded away after shape inference.

PiperOrigin-RevId: 275150438

5 years agoFix typo in tutorial.
reinerp [Thu, 17 Oct 2019 00:14:56 +0000 (17:14 -0700)]
Fix typo in tutorial.

PiperOrigin-RevId: 275147795

5 years agoAdd ComplexType to TableGen with Tensor support
Rob Suderman [Wed, 16 Oct 2019 23:58:42 +0000 (16:58 -0700)]
Add ComplexType to TableGen with Tensor support

Create a ComplexType for table gen references. Include an AnyComplex type
to check whether the resulting tensor can be complex. Expand tensors to
allow complex types.

PiperOrigin-RevId: 275144804

5 years agoCode cleanups on Ch.4
River Riddle [Wed, 16 Oct 2019 19:33:55 +0000 (12:33 -0700)]
Code cleanups on Ch.4

This change performs general cleanups of the implementation of ch.4 and fixes some bugs. For example, the operations currently don't inherit from the shape inference interface.

PiperOrigin-RevId: 275089914

5 years agoUpdate Chapter 4 of the Toy tutorial
Sana Damani [Wed, 16 Oct 2019 19:08:55 +0000 (12:08 -0700)]
Update Chapter 4 of the Toy tutorial

This Chapter now introduces and makes use of the Interface concept
in MLIR to demonstrate ShapeInference.
END_PUBLIC

Closes tensorflow/mlir#191

PiperOrigin-RevId: 275085151

5 years agoUpdate comments in ast.toy
Jacques Pienaar [Wed, 16 Oct 2019 19:07:56 +0000 (12:07 -0700)]
Update comments in ast.toy

PiperOrigin-RevId: 275084969

5 years agoNFC: Update VectorOrTensor -> Shaped
Geoffrey Martin-Noble [Wed, 16 Oct 2019 18:57:50 +0000 (11:57 -0700)]
NFC: Update VectorOrTensor -> Shaped

This was missed when the type was renamed.

PiperOrigin-RevId: 275082588

5 years agoMakes spv.module generated by GPU->SPIRV conversion spec compliant
Mahesh Ravishankar [Wed, 16 Oct 2019 18:52:33 +0000 (11:52 -0700)]
Makes spv.module generated by GPU->SPIRV conversion spec compliant

Makes the spv.module generated by the GPU to SPIR-V conversion SPIR-V
spec compliant (validated using spirv-val from Vulkan tools).

1) Separate out the VulkanLayoutUtils from
DecorateSPIRVCompositeTypeLayoutPass to make it reusable within the
Type converter in SPIR-V lowering infrastructure. This is used to
compute the layout of the !spv.struct used in global variable type
description.
2) Set the capabilities of the spv.module to Shader (needed for use of
Logical Memory Model, and the extensions to
SPV_KHR_storage_buffer_storage_class for use of Storage Buffer)

PiperOrigin-RevId: 275081486

5 years agoSupport custom accumulator provided as region to gpu.all_reduce.
Christian Sigg [Wed, 16 Oct 2019 17:43:12 +0000 (10:43 -0700)]
Support custom accumulator provided as region to gpu.all_reduce.

In addition to specifying the type of accumulation through the 'op' attribute, the accumulation can now also be specified as arbitrary code region.

Adds a gpu.yield op to specify the result of the accumulation.

Also support more types (integers) and accumulations (mul).

PiperOrigin-RevId: 275065447

5 years agoAllow for remapping argument to a Value in SignatureConversion.
Mahesh Ravishankar [Wed, 16 Oct 2019 17:20:31 +0000 (10:20 -0700)]
Allow for remapping argument to a Value in SignatureConversion.

The current SignatureConversion framework (part of DialectConversion)
allows remapping input arguments to a function from 1->0, 1->1 or
1->many arguments during conversion. Another case is where the
argument itself is dropped, but it's use are remapped to another
Value*.

An example of this is: The Vulkan/SPIR-V spec requires entry functions
to be of type void(void). The GPU -> SPIR-V conversion implemented
this without having the DialectConversion framework track the
remapping that lead to some undefined behavior. The changes here
addresses that.

PiperOrigin-RevId: 275059656

5 years agoAdd support for PatternRewriter::eraseOp.
River Riddle [Wed, 16 Oct 2019 16:50:28 +0000 (09:50 -0700)]
Add support for PatternRewriter::eraseOp.

This hook is useful when an operation is known to be dead, and no replacement values make sense.

PiperOrigin-RevId: 275052756

5 years agoFix CMake configuration after introduction of LICM and LoopLikeInterface
Mehdi Amini [Wed, 16 Oct 2019 15:36:51 +0000 (08:36 -0700)]
Fix CMake configuration after introduction of LICM and LoopLikeInterface

b843cc5d5a introduced a new op LICM transformation and a LoopLike interface,
but missed the CMake aspects of it. This should fix the build.

PiperOrigin-RevId: 275038533

5 years agoFix typo in VectorOps.td
Nicolas Vasilache [Wed, 16 Oct 2019 14:14:06 +0000 (07:14 -0700)]
Fix typo in VectorOps.td

PiperOrigin-RevId: 275025323

5 years agoImplement simple loop-invariant-code-motion based on dialect interfaces.
Stephan Herhut [Wed, 16 Oct 2019 11:28:13 +0000 (04:28 -0700)]
Implement simple loop-invariant-code-motion based on dialect interfaces.

PiperOrigin-RevId: 275004258

5 years agoNFC: Remove NoSideEffect traits from all ops except for ConstantOp.
River Riddle [Wed, 16 Oct 2019 07:35:07 +0000 (00:35 -0700)]
NFC: Remove NoSideEffect traits from all ops except for ConstantOp.

These traits are added in chapter 3 when we begin discussion optimization on the toy operations.

PiperOrigin-RevId: 274974010

5 years agoNFC: Various code cleanups for Ch3.
River Riddle [Wed, 16 Oct 2019 07:33:43 +0000 (00:33 -0700)]
NFC: Various code cleanups for Ch3.

This change refactors the toyc driver to be much cleaner and easier to extend. It also cleans up a few comments in the combiner.

PiperOrigin-RevId: 274973808

5 years agoAdd support for OpBitwiseOr, OpBitwiseXor, and OpBitwiseAnd in SPIR-V dialect.
Hanhan Wang [Wed, 16 Oct 2019 01:42:10 +0000 (18:42 -0700)]
Add support for OpBitwiseOr, OpBitwiseXor, and OpBitwiseAnd in SPIR-V dialect.

PiperOrigin-RevId: 274935374

5 years agoFix typo
MLIR Team [Tue, 15 Oct 2019 22:44:56 +0000 (15:44 -0700)]
Fix typo

PiperOrigin-RevId: 274905193

5 years agoFix typos
MLIR Team [Tue, 15 Oct 2019 22:34:13 +0000 (15:34 -0700)]
Fix typos

PiperOrigin-RevId: 274902838