platform/upstream/llvm.git
4 years agoAdd a convenient `clone()` method on the `Op` class that forward to the underlying...
Mehdi Amini [Sun, 1 Sep 2019 23:15:14 +0000 (16:15 -0700)]
Add a convenient `clone()` method on the `Op` class that forward to the underlying `Operation` (NFC)

PiperOrigin-RevId: 266685852

4 years agoAdd missing lowering to CFG in mlir-cpu-runner + related cleanup
Mehdi Amini [Sun, 1 Sep 2019 18:32:52 +0000 (11:32 -0700)]
Add missing lowering to CFG in mlir-cpu-runner + related cleanup

- the list of passes run by mlir-cpu-runner included -lower-affine and
  -lower-to-llvm but was missing -lower-to-cfg (because -lower-affine at
  some point used to lower straight to CFG); add -lower-to-cfg in
  between. IR with affine ops can now be run by mlir-cpu-runner.

- update -lower-to-cfg to be consistent with other passes (create*Pass methods
  were changed to return unique ptrs, but -lower-to-cfg appears to have been
  missed).

- mlir-cpu-runner was unable to parse custom form of affine op's - fix
  link options

- drop unnecessary run options from test/mlir-cpu-runner/simple.mlir
  (none of the test cases had loops)

- -convert-to-llvmir was changed to -lower-to-llvm at some point, but the
  create pass method name wasn't updated (this pass converts/lowers to LLVM
  dialect as opposed to LLVM IR). Fix this.

(If we prefer "convert", the cmd-line options could be changed to
"-convert-to-llvm/cfg" then.)

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

PiperOrigin-RevId: 266666909

4 years agoAdd a link to the rational on lack of const for IR units in the developer guide
Mehdi Amini [Sat, 31 Aug 2019 22:23:31 +0000 (15:23 -0700)]
Add a link to the rational on lack of const for IR units in the developer guide

PiperOrigin-RevId: 266583374

4 years agoDocument that non-IR units are passed by non-const reference instead of pointer in...
Mehdi Amini [Sat, 31 Aug 2019 22:17:42 +0000 (15:17 -0700)]
Document that non-IR units are passed by non-const reference instead of pointer in general

PiperOrigin-RevId: 266583029

4 years agoAdd floating-point comparison operations to SPIR-V dialect.
Mahesh Ravishankar [Sat, 31 Aug 2019 16:52:18 +0000 (09:52 -0700)]
Add floating-point comparison operations to SPIR-V dialect.

Use the existing SPV_LogicalOp specification to add the floating-point
comparison operations (both ordered and unordered versions).
To make it easier to import the op-definitions automatically modify
the dialect generation script to update the different .td files based
on whether the operation is an arithmetic op, logical op, etc. Also
allow specification of multiple opcodes with define_inst.sh.
Since this reuses the SPV_LogicalOp framework, no tests specific to
the floating point comparison ops are added with this CL.

PiperOrigin-RevId: 266561634

4 years agoAdd missing link dependency to MLIRTableGenTests
Lei Zhang [Sat, 31 Aug 2019 16:50:02 +0000 (09:50 -0700)]
Add missing link dependency to MLIRTableGenTests

PiperOrigin-RevId: 266561495

4 years agoupdate vim syntax file
Uday Bondhugula [Sat, 31 Aug 2019 00:38:36 +0000 (17:38 -0700)]
update vim syntax file

- more highlighting: numbers, elemental types inside shaped types
- add some more keywords

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

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/110 from bondhugula:vim 029777db0ecb95bfc6453c0869af1c233d84d521
PiperOrigin-RevId: 266487768

4 years agoAdd a canonicalization to erase empty AffineForOps.
River Riddle [Fri, 30 Aug 2019 23:49:01 +0000 (16:49 -0700)]
Add a canonicalization to erase empty AffineForOps.

AffineForOp themselves are pure and can be removed if there are no internal operations.

PiperOrigin-RevId: 266481293

4 years agoSplits DictionaryAttr into DictionaryAttrBase and DictionaryAttr.
MLIR Team [Fri, 30 Aug 2019 22:40:51 +0000 (15:40 -0700)]
Splits DictionaryAttr into DictionaryAttrBase and DictionaryAttr.
This maintains consistency with other *AttrBase/Attr splits.

PiperOrigin-RevId: 266469869

4 years agoAdd TensorRankOf for ranked tensor types with specific ranks
Logan Chien [Fri, 30 Aug 2019 21:53:28 +0000 (14:53 -0700)]
Add TensorRankOf for ranked tensor types with specific ranks

This commit adds `TensorRankOf<types, typeNames, ranks>` to specify ranked
tensor types with the specified types and ranks.  For example,
`TensorRankOf<[I32, F32], ["i32", "F32"], [0, 1]>` matches `tensor<i32>`,
`tensor<?xi32>`, `tensor<f32>`, or `tensor<?xf32>`.

PiperOrigin-RevId: 266461256

4 years agoFix StructsGenTest.cpp CMakeFile build error
Rob Suderman [Fri, 30 Aug 2019 21:09:46 +0000 (14:09 -0700)]
Fix StructsGenTest.cpp CMakeFile build error

PiperOrigin-RevId: 266452719

4 years agoGeneralize the pass hierarchy by adding a general OpPass<PassT, OpT>.
River Riddle [Fri, 30 Aug 2019 20:16:13 +0000 (13:16 -0700)]
Generalize the pass hierarchy by adding a general OpPass<PassT, OpT>.

This pass class generalizes the current functionality between FunctionPass and ModulePass, and allows for operating on any operation type. The pass manager currently only supports OpPasses operating on FuncOp and ModuleOp, but this restriction will be relaxed in follow-up changes. A utility class OpPassBase<OpT> allows for generically referring to operation specific passes: e.g. FunctionPassBase == OpPassBase<FuncOp>.

PiperOrigin-RevId: 266442239

4 years agoAdd mechanism to dump JIT-compiled objects to files
Jacques Pienaar [Fri, 30 Aug 2019 20:01:34 +0000 (13:01 -0700)]
Add mechanism to dump JIT-compiled objects to files

This commit introduces the bits to be able to dump JIT-compile
objects to external files by passing an object cache to OrcJit.
The new functionality is tested in mlir-cpu-runner under the flag
`dump-object-file`.

Closes tensorflow/mlir#95

PiperOrigin-RevId: 266439265

4 years agoAdded a TableGen generator for structured data
Rob Suderman [Fri, 30 Aug 2019 19:51:31 +0000 (12:51 -0700)]
Added a TableGen generator for structured data

Similar to enum, added a generator for structured data. This provide Dictionary that stores a fixed set of values and guarantees the values are valid. It is intended to store a fixed number of values by a given name.

PiperOrigin-RevId: 266437460

4 years agoAdd support for early exit walk methods.
River Riddle [Fri, 30 Aug 2019 19:47:24 +0000 (12:47 -0700)]
Add support for early exit walk methods.

This is done by providing a walk callback that returns a WalkResult. This result is either `advance` or `interrupt`. `advance` means that the walk should continue, whereas `interrupt` signals that the walk should stop immediately. An example is shown below:

auto result = op->walk([](Operation *op) {
  if (some_invariant)
    return WalkResult::interrupt();
  return WalkResult::advance();
});

if (result.wasInterrupted())
  ...;

PiperOrigin-RevId: 266436700

4 years agoAdd spv.Branch and spv.BranchConditional
Lei Zhang [Fri, 30 Aug 2019 19:17:21 +0000 (12:17 -0700)]
Add spv.Branch and spv.BranchConditional

This CL just covers the op definition, its parsing, printing,
and verification. (De)serialization is to be implemented
in a subsequent CL.

PiperOrigin-RevId: 266431077

5 years agoChange the parseSource* methods to return OwningModuleRef instead of ModuleOp.
River Riddle [Fri, 30 Aug 2019 05:19:29 +0000 (22:19 -0700)]
Change the parseSource* methods to return OwningModuleRef instead of ModuleOp.

This avoids potential memory leaks from misuse of the API.

PiperOrigin-RevId: 266305750

5 years agoRefactor the 'walk' methods for operations.
River Riddle [Thu, 29 Aug 2019 20:04:22 +0000 (13:04 -0700)]
Refactor the 'walk' methods for operations.

This change refactors and cleans up the implementation of the operation walk methods. After this refactoring is that the explicit template parameter for the operation type is no longer needed for the explicit op walks. For example:

    op->walk<AffineForOp>([](AffineForOp op) { ... });

is now accomplished via:

    op->walk([](AffineForOp op) { ... });

PiperOrigin-RevId: 266209552

5 years agoMake dumping using generic form more robust when IR ill-formed
Jacques Pienaar [Thu, 29 Aug 2019 19:14:02 +0000 (12:14 -0700)]
Make dumping using generic form more robust when IR ill-formed

PiperOrigin-RevId: 266198057

5 years agoAdd tests to verify 0.0 is quantized correctly
Feng Liu [Thu, 29 Aug 2019 17:08:46 +0000 (10:08 -0700)]
Add tests to verify 0.0 is quantized correctly

We should consider both signed and narrow_range cases.

PiperOrigin-RevId: 266167366

5 years agoExtend map canonicalization to propagate constant operands
Uday Bondhugula [Thu, 29 Aug 2019 08:13:01 +0000 (01:13 -0700)]
Extend map canonicalization to propagate constant operands

- extend canonicalizeMapAndOperands to propagate constant operands into
  the map's expressions (and thus drop those operands).
- canonicalizeMapAndOperands previously only dropped duplicate and
  unused operands; however, operands that were constants were
  retained.

This change makes IR maps/expressions generated by various
utilities/passes even simpler; also makes some of the test checks more
accurate and simpler -- for eg., 0' instead of symbol(%{{.*}}).

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

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/107 from bondhugula:canonicalize-maps c889a51486d14fbf7db489f224f881e7e1ff7d72
PiperOrigin-RevId: 266085289

5 years agofix loop unroll and jam - operand mapping - imperfect nest case
Uday Bondhugula [Thu, 29 Aug 2019 06:42:17 +0000 (23:42 -0700)]
fix loop unroll and jam - operand mapping - imperfect nest case

- fix operand mapping while cloning sub-blocks to jam - was incorrect
  for imperfect nests where def/use was across sub-blocks
- strengthen/generalize the first test case to cover the previously
  missed scenario
- clean up the other cases while on this.

Previously, unroll-jamming the following nest
```
    affine.for %arg0 = 0 to 2048 {
      %0 = alloc() : memref<512x10xf32>
      affine.for %arg1 = 0 to 10 {
        %1 = affine.load %0[%arg0, %arg1] : memref<512x10xf32>
      }
      dealloc %0 : memref<512x10xf32>
    }
```

would yield

```
      %0 = alloc() : memref<512x10xf32>
      %1 = affine.apply #map0(%arg0)
      %2 = alloc() : memref<512x10xf32>
      affine.for %arg1 = 0 to 10 {
        %4 = affine.load %0[%arg0, %arg1] : memref<512x10xf32>
        %5 = affine.apply #map0(%arg0)
        %6 = affine.load %0[%5, %arg1] : memref<512x10xf32>
      }
      dealloc %0 : memref<512x10xf32>
      %3 = affine.apply #map0(%arg0)
      dealloc %0 : memref<512x10xf32>

```

instead of

```

module {
    affine.for %arg0 = 0 to 2048 step 2 {
      %0 = alloc() : memref<512x10xf32>
      %1 = affine.apply #map0(%arg0)
      %2 = alloc() : memref<512x10xf32>
      affine.for %arg1 = 0 to 10 {
        %4 = affine.load %0[%arg0, %arg1] : memref<512x10xf32>
        %5 = affine.apply #map0(%arg0)
        %6 = affine.load %2[%5, %arg1] : memref<512x10xf32>
      }
      dealloc %0 : memref<512x10xf32>
      %3 = affine.apply #map0(%arg0)
      dealloc %2 : memref<512x10xf32>
    }
```

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

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/98 from bondhugula:ujam ddbc853f69b5608b3e8ff9b5ac1f6a5a0bb315a4
PiperOrigin-RevId: 266073460

5 years agoAdd verification for dimension attribute on GPUDialect index operations.
Stephan Herhut [Thu, 29 Aug 2019 06:39:20 +0000 (23:39 -0700)]
Add verification for dimension attribute on GPUDialect index operations.

PiperOrigin-RevId: 266073204

5 years agoAdd vim scripts for indent/syntax
Uday Bondhugula [Thu, 29 Aug 2019 06:22:39 +0000 (23:22 -0700)]
Add vim scripts for indent/syntax

- some of it has been adapted from LLVM's vim utils

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

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/90 from bondhugula:vim 22b1c958818c4b09de0ec8e1d7a4893171a03dbf
PiperOrigin-RevId: 266071752

5 years agoFix the equality check of two floating point values
Feng Liu [Wed, 28 Aug 2019 23:39:18 +0000 (16:39 -0700)]
Fix the equality check of two floating point values

PiperOrigin-RevId: 266022088

5 years agoGeneralize the analysis manager framework to work on any operation at any nesting.
River Riddle [Wed, 28 Aug 2019 22:10:37 +0000 (15:10 -0700)]
Generalize the analysis manager framework to work on any operation at any nesting.

The pass manager is moving towards being able to run on operations at arbitrary nesting. An operation may have both parent and child operations, and the AnalysisManager must be able to handle this generalization. The AnalysisManager class now contains generic 'getCachedParentAnalysis' and 'getChildAnalysis/getCachedChildAnalysis' functions to query analyses on parent/child operations. This removes the hard coded nesting relationship between Module/Function.

PiperOrigin-RevId: 266003636

5 years agoTweak to the pretty type parser to recognize that `->` is a special token.
Eric Schweitz [Wed, 28 Aug 2019 20:55:11 +0000 (13:55 -0700)]
Tweak to the pretty type parser to recognize that `->` is a special token.

Tweak to the pretty type parser to recognize that `->` is a special token that
shouldn't be split into two characters.  This change allows dialect
types to wrap function types as in `!my.ptr_type<(i32) -> i32>`.

Closes tensorflow/mlir#105

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/105 from schweitzpgi:parse-arrow 8b2d768053f419daae5a1a864121a44c4319acbe
PiperOrigin-RevId: 265986240

5 years agoAdd implementation for tensor_load and tensor_store operations.
Stephan Herhut [Wed, 28 Aug 2019 18:25:19 +0000 (11:25 -0700)]
Add implementation for tensor_load and tensor_store operations.

This change adds definitions, parsing and verification for both ops.

PiperOrigin-RevId: 265954051

5 years agoPort mlir-cuda-runner to use dialect conversion framework.
Stephan Herhut [Wed, 28 Aug 2019 08:50:28 +0000 (01:50 -0700)]
Port mlir-cuda-runner to use dialect conversion framework.

Instead of lowering the program in two steps (Standard->LLVM followed
by GPU->NVVM), leading to invalid IR inbetween, the runner now uses
one pattern based rewrite step to go directly from Standard+GPU to
LLVM+NVVM.

PiperOrigin-RevId: 265861934

5 years agoRefactor / improve replaceAllMemRefUsesWith
Uday Bondhugula [Wed, 28 Aug 2019 00:56:25 +0000 (17:56 -0700)]
Refactor / improve replaceAllMemRefUsesWith

Refactor replaceAllMemRefUsesWith to split it into two methods: the new
method does the replacement on a single op, and is used by the existing
one.

- make the methods return LogicalResult instead of bool

- Earlier, when replacement failed (due to non-deferencing uses of the
  memref), the set of ops that had already been processed would have
  been replaced leaving the IR in an inconsistent state. Now, a
  pass is made over all ops to first check for non-deferencing
  uses, and then replacement is performed. No test cases were affected
  because all clients of this method were first checking for
  non-deferencing uses before calling this method (for other reasons).
  This isn't true for a use case in another upcoming PR (scalar
  replacement); clients can now bail out with consistent IR on failure
  of replaceAllMemRefUsesWith. Add test case.

- multiple deferencing uses of the same memref in a single op is
  possible (we have no such use cases/scenarios), and this has always
  remained unsupported. Add an assertion for this.

- minor fix to another test pipeline-data-transfer case.

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

PiperOrigin-RevId: 265808183

5 years agoUpdate Ch.2 of the Toy tutorial.
River Riddle [Tue, 27 Aug 2019 19:43:55 +0000 (12:43 -0700)]
Update Ch.2 of the Toy tutorial.

The code and documentation for this chapter of the tutorial have been updated to follow the new flow. The toy 'array' type has been replaced by usages of the MLIR tensor type. The code has also been cleaned up and modernized.

Closes tensorflow/mlir#101

PiperOrigin-RevId: 265744086

5 years agoAdd 3 additional intrinsic ops to NVVM dialect, in preparation to implement block...
MLIR Team [Tue, 27 Aug 2019 17:55:47 +0000 (10:55 -0700)]
Add 3 additional intrinsic ops to NVVM dialect, in preparation to implement block-wide reduce.

PiperOrigin-RevId: 265720077

5 years ago[spirv] Fix the entry block to start with OpLabel
Lei Zhang [Tue, 27 Aug 2019 17:50:58 +0000 (10:50 -0700)]
[spirv] Fix the entry block to start with OpLabel

Each basic block in SPIR-V must start with an OpLabel instruction.
We don't support control flow yet, so this CL just makes sure that
the entry block follows this rule and is valid.

PiperOrigin-RevId: 265718841

5 years agoEnhance GPU To SPIR-V conversion to support builtins and load/store ops.
Mahesh Ravishankar [Tue, 27 Aug 2019 17:49:53 +0000 (10:49 -0700)]
Enhance GPU To SPIR-V conversion to support builtins and load/store ops.

To support a conversion of a simple load-compute-store kernel from GPU
dialect to SPIR-V dialect, the conversion of operations like
"gpu.block_dim", "gpu.thread_id" which allow threads to get the launch
conversion is needed. In SPIR-V these are specified as global
variables with builin attributes. This CL adds support to specify
builtin variables in SPIR-V conversion framework. This is used to
convert the relevant operations from GPU dialect to SPIR-V dialect.
Also add support for conversion of load/store operation in Standard
dialect to SPIR-V dialect.
To simplify the conversion add a method to build a spv.AccessChain
operation that automatically determines the return type based on the
base pointer type and the indices provided.

PiperOrigin-RevId: 265718525

5 years ago[spirv] Add Block decoration for spv.struct.
Denis Khalikov [Tue, 27 Aug 2019 17:41:07 +0000 (10:41 -0700)]
[spirv] Add Block decoration for spv.struct.

Add Block decoration for top-level spv.struct.

Closes tensorflow/mlir#102

PiperOrigin-RevId: 265716241

5 years agoNFC: Remove the explicit context from Operation::create and OperationState.
River Riddle [Tue, 27 Aug 2019 00:34:06 +0000 (17:34 -0700)]
NFC: Remove the explicit context from Operation::create and OperationState.

The context can easily be recovered from the Location in these situations.

PiperOrigin-RevId: 265578574

5 years agoAdd FPToSI/FPExt/FPTrunc cast ops to the LLVM dialect.
Eric Schweitz [Mon, 26 Aug 2019 21:18:47 +0000 (14:18 -0700)]
Add FPToSI/FPExt/FPTrunc cast ops to the LLVM dialect.

Closes tensorflow/mlir#99

PiperOrigin-RevId: 265538731

5 years agoNFC: Remove unnecessary context parameters from several Location getters.
River Riddle [Mon, 26 Aug 2019 20:53:22 +0000 (13:53 -0700)]
NFC: Remove unnecessary context parameters from several Location getters.

The context can be recovered by other means in these methods and doesn't need to be passed explicitly.

PiperOrigin-RevId: 265532956

5 years agoUpdate documentation for custom rewrite specs.
MLIR Team [Mon, 26 Aug 2019 17:27:38 +0000 (10:27 -0700)]
Update documentation for custom rewrite specs.

PiperOrigin-RevId: 265485862

5 years agoSupport folding of ops with inner ops in GreedyPatternRewriteDriver.
Andy Ly [Mon, 26 Aug 2019 16:44:09 +0000 (09:44 -0700)]
Support folding of ops with inner ops in GreedyPatternRewriteDriver.

This fixes a bug when folding ops with inner ops and inner ops are still being visited.

PiperOrigin-RevId: 265475780

5 years agoNFC: Add doc for id-punct
Alina Sbirlea [Sat, 24 Aug 2019 04:00:40 +0000 (21:00 -0700)]
NFC: Add doc for id-punct
PiperOrigin-RevId: 265190168

5 years agoNFC: Update Ch.1 of the Toy tutorial.
River Riddle [Sat, 24 Aug 2019 01:11:29 +0000 (18:11 -0700)]
NFC: Update Ch.1 of the Toy tutorial.

Change the use of 'array' to 'tensor' to reflect the new flow that the tutorial will follow. Also tidy up some of the documentation, code comments, and fix a few out-dated links.

PiperOrigin-RevId: 265174676

5 years agoLower linalg.copy to LLVM dialect in the presence of transposes.
Nicolas Vasilache [Sat, 24 Aug 2019 00:44:55 +0000 (17:44 -0700)]
Lower linalg.copy to LLVM dialect in the presence of transposes.

Add an extra RewritePattern that does not convert types to rewrite a CopyOp that has non-identity permutations into a sequence of TransposeOp followed by a CopyOp without such permutations.

This RewitePattern is made to fail in the non-permutation case so that the conversion pattern can kick in to lower to LLVM.

This is an instance of A->A->B lowering where A->A is done by a RewritePattern in case_1 and A->B is done by a ConversionPatternRewriter when not(case_1).

PiperOrigin-RevId: 265171380

5 years agoLower linalg.transpose to LLVM dialect
Nicolas Vasilache [Sat, 24 Aug 2019 00:28:51 +0000 (17:28 -0700)]
Lower linalg.transpose to LLVM dialect

Add a conversion pattern that transforms a linalg.transpose op into:
   1. A function entry `alloca` operation to allocate a ViewDescriptor.
   2. A load of the ViewDescriptor from the pointer allocated in 1.
   3. Updates to the ViewDescriptor to introduce the data ptr, offset, size
      and stride. Size and stride are permutations of the original values.
   4. A store of the resulting ViewDescriptor to the alloca'ed pointer.
The linalg.transpose op is replaced by the alloca'ed pointer.

PiperOrigin-RevId: 265169112

5 years agoAdd a linalg.transpose op
Nicolas Vasilache [Fri, 23 Aug 2019 21:47:46 +0000 (14:47 -0700)]
Add a linalg.transpose op

A linalg.transpose op is a pure metadata operation that takes a view + permutation map and produces
another view of the same underlying data, with a different reindexing. This is a
pure metadata operation that does not touch the underlying data.

Example:

```
  %t = linalg.transpose %v (i, j) -> (j, i) : !linalg.view<?x?xf32>
```

PiperOrigin-RevId: 265139429

5 years agoNFC: Add a note to 'applyPatternsGreedily' that it also performs folding/dce.
River Riddle [Fri, 23 Aug 2019 18:28:19 +0000 (11:28 -0700)]
NFC: Add a note to 'applyPatternsGreedily' that it also performs folding/dce.

Fixes tensorflow/mlir#72

PiperOrigin-RevId: 265097597

5 years agoAdd lowering of linalg.copy to an external C++ library and a test.
Nicolas Vasilache [Fri, 23 Aug 2019 18:08:59 +0000 (11:08 -0700)]
Add lowering of linalg.copy to an external C++ library and a test.

This CL extends support for lowering of linalg to external C++ libraries with CopyOp. Currently this can only work when the permutation maps in the copies are identity. Future support for permutations will be added later.

PiperOrigin-RevId: 265093025

5 years agoUpdate Linalg slice and subview documentation - NFC
Nicolas Vasilache [Fri, 23 Aug 2019 18:08:33 +0000 (11:08 -0700)]
Update Linalg slice and subview documentation - NFC

PiperOrigin-RevId: 265092922

5 years ago[spirv] NFC: move SPIR-V control flow ops to a separate file
Lei Zhang [Fri, 23 Aug 2019 18:07:13 +0000 (11:07 -0700)]
[spirv] NFC: move SPIR-V control flow ops to a separate file

This CL is also purely moving code around for better file organization.

PiperOrigin-RevId: 265092566

5 years agoIntroduce the ability for "isolated from above" ops to introduce shadowing
Chris Lattner [Fri, 23 Aug 2019 17:35:24 +0000 (10:35 -0700)]
Introduce the ability for "isolated from above" ops to introduce shadowing
names for the basic block arguments in their body.

PiperOrigin-RevId: 265084627

5 years agoNFC: Update in-code documentation. Make the two grammar definitions of static-dimensi...
MLIR Team [Fri, 23 Aug 2019 17:34:04 +0000 (10:34 -0700)]
NFC: Update in-code documentation. Make the two grammar definitions of static-dimension-list consistent.
PiperOrigin-RevId: 265084348

5 years ago[spirv] NFC: move arithmetic and logical ops to separate files
Lei Zhang [Fri, 23 Aug 2019 17:26:13 +0000 (10:26 -0700)]
[spirv] NFC: move arithmetic and logical ops to separate files

This is purely moving code around for better file organization.

PiperOrigin-RevId: 265082517

5 years agoFix BufferAllocOp builder.
Nicolas Vasilache [Fri, 23 Aug 2019 17:15:29 +0000 (10:15 -0700)]
Fix BufferAllocOp builder.

One of the BufferAllocOp builders was improperly specified which triggered infinite recursion. This CL fixes it.

PiperOrigin-RevId: 265080371

5 years agoNFC: Move the operation, region, and block sections to after the dialect section.
River Riddle [Fri, 23 Aug 2019 17:08:42 +0000 (10:08 -0700)]
NFC: Move the operation, region, and block sections to after the dialect section.

Operations/Regions/Blocks represent the core IR building blocks and should be introduced before types and attributes.

PiperOrigin-RevId: 265079103

5 years agoAdd I32ElementsAttr to OpBase
MLIR Team [Fri, 23 Aug 2019 02:05:07 +0000 (19:05 -0700)]
Add I32ElementsAttr to OpBase

PiperOrigin-RevId: 264969142

5 years agoAdd iterator support to ElementsAttr and SparseElementsAttr.
River Riddle [Fri, 23 Aug 2019 01:58:51 +0000 (18:58 -0700)]
Add iterator support to ElementsAttr and SparseElementsAttr.

This will allow iterating the values of a non-opaque ElementsAttr, with all of the types currently supported by DenseElementsAttr. This should help reduce the amount of specialization on DenseElementsAttr.

PiperOrigin-RevId: 264968151

5 years agoNFC: Cleanup the Attribute section in the LangRef.
River Riddle [Fri, 23 Aug 2019 00:51:06 +0000 (17:51 -0700)]
NFC: Cleanup the Attribute section in the LangRef.

* Add a section on dialect attribute values and attribute aliases
* Move FloatAttr into its alphabetically correct place
* Add a "Standard Attribute Values" section

PiperOrigin-RevId: 264959306

5 years agoNFC: Cleanup the type system section of the LangRef.
River Riddle [Thu, 22 Aug 2019 23:43:06 +0000 (16:43 -0700)]
NFC: Cleanup the type system section of the LangRef.

* Alphabetize the type definitions
* Make 'Dialect specific types' a type-system subsection
* Merge Builtin types and Standard types

PiperOrigin-RevId: 264947721

5 years ago[spirv] Add support for extension (de)serialization
Lei Zhang [Thu, 22 Aug 2019 23:01:13 +0000 (16:01 -0700)]
[spirv] Add support for extension (de)serialization

Only a few important KHR extensions are registered to the
SPIR-V dialect for now.

PiperOrigin-RevId: 264939428

5 years agoNFC: Rework and cleanup the High-Level structure and Dialect sections.
River Riddle [Thu, 22 Aug 2019 22:53:41 +0000 (15:53 -0700)]
NFC: Rework and cleanup the High-Level structure and Dialect sections.

Both sections are out-of-date and need to be updated. The dialect section is particularly bad in that it never actually mentions what a 'Dialect' is.

PiperOrigin-RevId: 264937905

5 years agoNFC: Remove mentions of the TensorFlow dialect from the langref.
River Riddle [Thu, 22 Aug 2019 20:20:28 +0000 (13:20 -0700)]
NFC: Remove mentions of the TensorFlow dialect from the langref.
PiperOrigin-RevId: 264904489

5 years agoAvoid overflow when lowering linalg.slice
Nicolas Vasilache [Thu, 22 Aug 2019 19:46:30 +0000 (12:46 -0700)]
Avoid overflow when lowering linalg.slice

linalg.subview used to lower to a slice with a bounded range resulting in correct bounded accesses. However linalg.slice could still index out of bounds. This CL moves the bounding to linalg.slice.

LLVM select and cmp ops gain a more idiomatic builder.

PiperOrigin-RevId: 264897125

5 years agoNFC: Avoid reconstructing the OpInterface methods.
River Riddle [Thu, 22 Aug 2019 18:31:01 +0000 (11:31 -0700)]
NFC: Avoid reconstructing the OpInterface methods.
PiperOrigin-RevId: 264881293

5 years ago[spirv] Add support for capability (de)serialization
Lei Zhang [Thu, 22 Aug 2019 18:15:05 +0000 (11:15 -0700)]
[spirv] Add support for capability (de)serialization

This CL pulls in capabilities defined in the spec and adds
support for (de)serialize capabilities of a spv.module.

PiperOrigin-RevId: 264877413

5 years agoAdd Positive{I32,I64}Attr and HasAnyRankOfPred
Logan Chien [Thu, 22 Aug 2019 17:36:01 +0000 (10:36 -0700)]
Add Positive{I32,I64}Attr and HasAnyRankOfPred

This commit adds `PositiveI32Attr` and `PositiveI64Attr` to match positive
integers but not zero nor negative integers.  This commit also adds
`HasAnyRankOfPred` to match tensors with the specified ranks.

PiperOrigin-RevId: 264867046

5 years agoSplit out parsing location into separate functions per instance
Jacques Pienaar [Thu, 22 Aug 2019 16:45:04 +0000 (09:45 -0700)]
Split out parsing location into separate functions per instance

Split out method into specialized instances + add an early exit. Should be NFC, but simplifies reading the logic slightly IMHO.

PiperOrigin-RevId: 264855529

5 years agoLet LLVMOpLowering specify a PatternBenefit - NFC
Nicolas Vasilache [Thu, 22 Aug 2019 16:38:16 +0000 (09:38 -0700)]
Let LLVMOpLowering specify a PatternBenefit - NFC

Currently the benefit is always set to 1 which limits the ability to do A->B->C lowering

PiperOrigin-RevId: 264854146

5 years agoNFC: Fix path of LinalgLibraryOpInterfaces inc files.
River Riddle [Thu, 22 Aug 2019 14:15:09 +0000 (07:15 -0700)]
NFC: Fix path of LinalgLibraryOpInterfaces inc files.
PiperOrigin-RevId: 264827908

5 years agoAdd support for generating operation interfaces from the ODS framework.
River Riddle [Thu, 22 Aug 2019 03:57:23 +0000 (20:57 -0700)]
Add support for generating operation interfaces from the ODS framework.

Operation interfaces generally require a bit of boilerplate code to connect all of the pieces together. This cl introduces mechanisms in the ODS to allow for generating operation interfaces via the 'OpInterface' class.

Providing a definition of the `OpInterface` class will auto-generate the c++
classes for the interface. An `OpInterface` includes a name, for the c++ class,
along with a list of interface methods. There are two types of methods that can be used with an interface, `InterfaceMethod` and `StaticInterfaceMethod`. They are both comprised of the same core components, with the distinction that `StaticInterfaceMethod` models a static method on the derived operation.

An `InterfaceMethod` is comprised of the following components:
    * ReturnType
      - A string corresponding to the c++ return type of the method.
    * MethodName
      - A string corresponding to the desired name of the method.
    * Arguments
      - A dag of strings that correspond to a c++ type and variable name
        respectively.
    * MethodBody (Optional)
      - An optional explicit implementation of the interface method.

def MyInterface : OpInterface<"MyInterface"> {
  let methods = [
    // A simple non-static method with no inputs.
    InterfaceMethod<"unsigned", "foo">,

    // A new non-static method accepting an input argument.
    InterfaceMethod<"Value *", "bar", (ins "unsigned":$i)>,

    // Query a static property of the derived operation.
    StaticInterfaceMethod<"unsigned", "fooStatic">,

    // Provide the definition of a static interface method.
    // Note: `ConcreteOp` corresponds to the derived operation typename.
    StaticInterfaceMethod<"Operation *", "create",
      (ins "OpBuilder &":$builder, "Location":$loc), [{
        return builder.create<ConcreteOp>(loc);
    }]>,

    // Provide a definition of the non-static method.
    // Note: `op` corresponds to the derived operation variable.
    InterfaceMethod<"unsigned", "getNumInputsAndOutputs", (ins), [{
      return op.getNumInputs() + op.getNumOutputs();
    }]>,
  ];

PiperOrigin-RevId: 264754898

5 years agoAvoid assigning to an unchecked Error.
River Riddle [Thu, 22 Aug 2019 02:03:13 +0000 (19:03 -0700)]
Avoid assigning to an unchecked Error.

Fixes tensorflow/mlir#97

PiperOrigin-RevId: 264743395

5 years agoPoint to spv.AccessChain when reporting spv.AccessChain errors
Lei Zhang [Thu, 22 Aug 2019 01:53:32 +0000 (18:53 -0700)]
Point to spv.AccessChain when reporting spv.AccessChain errors

PiperOrigin-RevId: 264742130

5 years agoRemove dead getLLVMLibraryCallImplDefinition in Linalg's LowerToLLVMDialect.cpp ...
Nicolas Vasilache [Thu, 22 Aug 2019 01:36:15 +0000 (18:36 -0700)]
Remove dead getLLVMLibraryCallImplDefinition in Linalg's LowerToLLVMDialect.cpp - NFC

PiperOrigin-RevId: 264740014

5 years agoReduce reliance on custom grown Jit implementation - NFC
Nicolas Vasilache [Thu, 22 Aug 2019 01:15:39 +0000 (18:15 -0700)]
Reduce reliance on custom grown Jit implementation - NFC

This CL makes use of the standard LLVM LLJIT and removes the need for a custom JIT implementation within MLIR.

To achieve this, one needs to clone (i.e. serde) the produced llvm::Module into a new LLVMContext. This is currently necessary because the llvm::LLVMContext is owned by the LLVMDialect, somewhat deep in the call hierarchy.

In the future we should remove the reliance of serding the llvm::Module by allowing the injection of an LLVMContext from the top-level. Unfortunately this will require deeper API changes and impact multiple places. It is therefore left for future work.

PiperOrigin-RevId: 264737459

5 years agoRemove the wrapping function in SPIR-V (de)serialization
Lei Zhang [Thu, 22 Aug 2019 01:04:56 +0000 (18:04 -0700)]
Remove the wrapping function in SPIR-V (de)serialization

Previously Module and Function are builtinn constructs in MLIR.
Due to the structural requirements we must wrap the SPIR-V
module inside a Function inside a Module. Now the requirement
is lifted and we can remove the wrapping function! :)

PiperOrigin-RevId: 264736051

5 years agoNFC: Update in-code documentation for type.
MLIR Team [Thu, 22 Aug 2019 00:51:27 +0000 (17:51 -0700)]
NFC: Update in-code documentation for type.
PiperOrigin-RevId: 264734014

5 years agoFix minor typos in TestingGuide and OpDefinitions.
Chintan Kaur [Thu, 22 Aug 2019 00:45:06 +0000 (17:45 -0700)]
Fix minor typos in TestingGuide and OpDefinitions.

PiperOrigin-RevId: 264733092

5 years agoNFC: Update in-code documentation for function-type.
MLIR Team [Wed, 21 Aug 2019 23:50:55 +0000 (16:50 -0700)]
NFC: Update in-code documentation for function-type.
PiperOrigin-RevId: 264723462

5 years agoAdd a hook to the OpAsmDialectInterface to allow providing a special name for the...
River Riddle [Wed, 21 Aug 2019 23:50:30 +0000 (16:50 -0700)]
Add a hook to the OpAsmDialectInterface to allow providing a special name for the operation result.

This generalizes the current special handling for constant operations(they get named 'cst'/'true'/'false'/etc.)

PiperOrigin-RevId: 264723379

5 years ago[TableGen] Add a `StaticShapeMemRefOf` trait.
MLIR Team [Wed, 21 Aug 2019 21:28:10 +0000 (14:28 -0700)]
[TableGen] Add a `StaticShapeMemRefOf` trait.

The trait specifies that the `MemRefOf` has to have a static shape.

PiperOrigin-RevId: 264692758

5 years agoAutomated rollback of commit b9dc2e481818315f2f0d87455349f497f6118a4c
River Riddle [Wed, 21 Aug 2019 20:00:30 +0000 (13:00 -0700)]
Automated rollback of commit b9dc2e481818315f2f0d87455349f497f6118a4c

PiperOrigin-RevId: 264672975

5 years agoNFC: Make the ModuleState field in the ModulePrinter optional.
River Riddle [Wed, 21 Aug 2019 19:16:23 +0000 (12:16 -0700)]
NFC: Make the ModuleState field in the ModulePrinter optional.

The ModuleState is only used for printing aliases, which is only done when printing the top-level module.

PiperOrigin-RevId: 264664138

5 years agoAdd iterator support to ElementsAttr and SparseElementsAttr.
River Riddle [Wed, 21 Aug 2019 17:23:14 +0000 (10:23 -0700)]
Add iterator support to ElementsAttr and SparseElementsAttr.

This will allow iterating the values of a non-opaque ElementsAttr, with all of the types currently supported by DenseElementsAttr. This should help reduce the amount of specialization on DenseElementsAttr.

PiperOrigin-RevId: 264637293

5 years agoMove the parser extensions for aliases currently on Dialect to a new OpAsmDialectInte...
River Riddle [Wed, 21 Aug 2019 16:41:37 +0000 (09:41 -0700)]
Move the parser extensions for aliases currently on Dialect to a new OpAsmDialectInterface.

This will allow for adding more hooks for controlling parser behavior without bloating Dialect in the common case. This cl also adds iteration support to the DialectInterfaceCollection.

PiperOrigin-RevId: 264627846

5 years ago[spirv] Support i1 as bool type
Lei Zhang [Wed, 21 Aug 2019 15:17:19 +0000 (08:17 -0700)]
[spirv] Support i1 as bool type

PiperOrigin-RevId: 264612014

5 years agoSupport variadic ops in declarative rewrite rules
Lei Zhang [Wed, 21 Aug 2019 12:35:07 +0000 (05:35 -0700)]
Support variadic ops in declarative rewrite rules

This CL extends declarative rewrite rules to support matching and
generating ops with variadic operands/results. For this, the
generated `matchAndRewrite()` method for each pattern now are
changed to

* Use "range" types for the local variables used to store captured
  values (`operand_range` for operands, `ArrayRef<Value *>` for
  values, *Op for results). This allows us to have a unified way
  of handling both single values and value ranges.
* Create local variables for each operand for op creation. If the
  operand is variadic, then a `SmallVector<Value*>` will be created
  to collect all values for that operand; otherwise a `Value*` will
  be created.
* Use a collective result type builder. All result types are
  specified via a single parameter to the builder.

We can use one result pattern to replace multiple results of the
matched root op. When that happens, it will require specifying
types for multiple results. Add a new collective-type builder.

PiperOrigin-RevId: 264588559

5 years agoMaterialize spv.constants at use sites
Lei Zhang [Wed, 21 Aug 2019 11:45:23 +0000 (04:45 -0700)]
Materialize spv.constants at use sites

In SPIR-V binary format, constants are placed at the module level
and referenced by instructions inside functions using their result
<id>s. To model this natively (using SSA values for result <id>s),
it means we need to have implicit capturing functions. We will
lose the ability to have function passes if going down that path.

Instead, this CL changes to materialize constants at their use
sites in deserialization. It's cheap to copy constants in MLIR
given that attributes is uniqued to MLIRContext. By localizing
constants into functions, we can preserve isolated functions.

PiperOrigin-RevId: 264582532

5 years agoNFC: Keep the dialect list in the context sorted by namespace.
River Riddle [Wed, 21 Aug 2019 02:58:35 +0000 (19:58 -0700)]
NFC: Keep the dialect list in the context sorted by namespace.

Most dialects are initialized statically, which does not have a guaranteed initialization order. By keeping the dialect list sorted, we can guarantee a deterministic iteration order of dialects.

PiperOrigin-RevId: 264522875

5 years agoNFC: Use a DenseSet instead of a DenseMap for DialectInterfaceCollection.
River Riddle [Wed, 21 Aug 2019 01:49:08 +0000 (18:49 -0700)]
NFC: Use a DenseSet instead of a DenseMap for DialectInterfaceCollection.

The interfaces are looked up by dialect, which can always be retrieved from an interface instance.

PiperOrigin-RevId: 264516023

5 years agoNFC: Move the LangRef documentation on StandardOps to a new document.
River Riddle [Wed, 21 Aug 2019 01:41:38 +0000 (18:41 -0700)]
NFC: Move the LangRef documentation on StandardOps to a new document.

The LangRef should contain documentation about the core system, and standard ops is a dialect just like any other. This will also simplify the transition when StandardOps is eventually split apart.

PiperOrigin-RevId: 264514988

5 years agoNFC: Move AffineOps dialect to the Dialect sub-directory.
River Riddle [Tue, 20 Aug 2019 22:36:08 +0000 (15:36 -0700)]
NFC: Move AffineOps dialect to the Dialect sub-directory.
PiperOrigin-RevId: 264482571

5 years agoAdd spv.specConstant and spv._reference_of
Lei Zhang [Tue, 20 Aug 2019 20:33:41 +0000 (13:33 -0700)]
Add spv.specConstant and spv._reference_of

Similar to global variables, specialization constants also live
in the module scope and can be referenced by instructions in
functions in native SPIR-V. A direct modelling would be to allow
functions in the SPIR-V dialect to implicit capture, but it means
we are losing the ability to write passes for Functions. While
in SPIR-V normally we want to process the module as a whole,
it's not common to see multiple functions get used so we'd like
to leave the door open for those cases. Therefore, similar to
global variables, we introduce spv.specConstant to model three
SPIR-V instructions: OpSpecConstantTrue, OpSpecConstantFalse,
and OpSpecConstant. They do not return SSA value results;
instead they have symbols and can only be referenced by the
symbols. To use it in a function, we need to have another op
spv._reference_of to turn the symbol into an SSA value. This
breaks the tie and makes functions still explicit capture.
Previously specialization constants were handled similarly as
normal constants. That is incorrect given that specialization
constant actually acts more like variable (without need to
load and store). E.g., they cannot be de-duplicated like normal
constants.

This CL also refines various documents and comments.

PiperOrigin-RevId: 264455172

5 years ago[spirv] Support (de)serialization of spv.struct
Denis Khalikov [Tue, 20 Aug 2019 18:02:57 +0000 (11:02 -0700)]
[spirv] Support (de)serialization of spv.struct

Support (de)serialization of spv.struct with offset decorations.

Closes tensorflow/mlir#94

PiperOrigin-RevId: 264421427

5 years agoFix build of affine load/store with empty map
Diego Caballero [Tue, 20 Aug 2019 17:43:45 +0000 (10:43 -0700)]
Fix build of affine load/store with empty map

tensorflow/mlir#58 fixed and exercised
verification of load/store ops using empty affine maps. Unfortunately,
it didn't exercise the creation of them. This PR addresses that aspect.
It removes the assumption of AffineMap having at least one result and
stores a pointer to MLIRContext as member of AffineMap.

* Add empty map support to affine.store + test
* Move MLIRContext to AffineMapStorage

Closes tensorflow/mlir#74

PiperOrigin-RevId: 264416260

5 years agoUpdate MLIR code examples in Passes.md doc to use new affine.load/store dma_start...
Andy Davis [Tue, 20 Aug 2019 17:38:27 +0000 (10:38 -0700)]
Update MLIR code examples in Passes.md doc to use new affine.load/store dma_start/wait operations.

PiperOrigin-RevId: 264415037

5 years agoUpdate Ch-2.md
Zhang [Tue, 20 Aug 2019 15:53:02 +0000 (08:53 -0700)]
Update Ch-2.md
--
406f1e8211f8f5017f44f46af750dec061e707a2 by Zhang <5205699+Naville@users.noreply.github.com>:

Update Ch-2.md

Closes tensorflow/mlir#93

PiperOrigin-RevId: 264392995

5 years agoConvertLaunchFuncToCudaCalls: use LLVM dialect globals
Alex Zinenko [Tue, 20 Aug 2019 14:51:32 +0000 (07:51 -0700)]
ConvertLaunchFuncToCudaCalls: use LLVM dialect globals

This conversion has been using a stack-allocated array of i8 to store the
null-terminated kernel name in order to pass it to the CUDA wrappers expecting
a C string because the LLVM dialect was missing support for globals.  Now that
the suport is introduced, use a global instead.

Refactor global string construction from GenerateCubinAccessors into a common
utility function living in the LLVM namespace.

PiperOrigin-RevId: 264382489

5 years agoJitRunner: support entry functions returning void
Alex Zinenko [Tue, 20 Aug 2019 14:45:47 +0000 (07:45 -0700)]
JitRunner: support entry functions returning void

JitRunner can use as entry points functions that produce either a single
'!llvm.f32' value or a list of memrefs.  Memref support is legacy and was
introduced before MLIR could lower memref allocation and deallocation to
malloc/free calls so as to allocate the memory externally, and is likely to be
dropped in the future since it unconditionally runs affine+standard-to-llvm
lowering on the module instead of accepting the LLVM dialect.  CUDA runner
relies on memref-based flow in the runner without actually returning anything.
Introduce a runner flow to use functions that return void as entry points.

PiperOrigin-RevId: 264381686

5 years agoLLVM dialect: prefix operations that correspond to intrinsics with "intr."
Alex Zinenko [Tue, 20 Aug 2019 13:38:28 +0000 (06:38 -0700)]
LLVM dialect: prefix operations that correspond to intrinsics with "intr."

LLVM intrinsics have an open name space and their names can potentially overlap
with names of LLVM instructions (LLVM intrinsics are functions, not
instructions).  In MLIR, LLVM intrinsics are modeled as operations, so it needs
to make sure their names cannot clash with the instructions.  Use the "intr."
prefix for intrinsics in the LLVM dialect.

PiperOrigin-RevId: 264372173

5 years agoAdd support for LLVM lowering of binary ops on n-D vector types
Nicolas Vasilache [Tue, 20 Aug 2019 08:59:58 +0000 (01:59 -0700)]
Add support for LLVM lowering of binary ops on n-D vector types

This CL allows binary operations on n-D vector types to be lowered to LLVMIR by performing an (n-1)-D extractvalue, 1-D vector operation and an (n-1)-D insertvalue.

PiperOrigin-RevId: 264339118

5 years agoFix AffineExpr::simplifyAdd bug
Uday Bondhugula [Tue, 20 Aug 2019 08:52:39 +0000 (01:52 -0700)]
Fix AffineExpr::simplifyAdd bug

- fix missing check while simplifying an expression with floordiv to a
  mod
- fixes issue tensorflow/mlir#82

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

PiperOrigin-RevId: 264338353