platform/upstream/llvm.git
5 years agoPrint proper message saying variadic ops are not supported in RewriterGen
Lei Zhang [Wed, 19 Jun 2019 21:32:07 +0000 (14:32 -0700)]
Print proper message saying variadic ops are not supported in RewriterGen

Support for ops with variadic operands/results will come later; but right now
a proper message helps to avoid deciphering confusing error messages later in
the compilation stage.

PiperOrigin-RevId: 254071820

5 years agoAdd missing MLIRStandardOps dependency for MLIRGPU
Lei Zhang [Wed, 19 Jun 2019 21:28:19 +0000 (14:28 -0700)]
Add missing MLIRStandardOps dependency for MLIRGPU

PiperOrigin-RevId: 254070969

5 years agoRefactor the TypeConverter to support more robust type conversions:
River Riddle [Wed, 19 Jun 2019 20:58:31 +0000 (13:58 -0700)]
Refactor the TypeConverter to support more robust type conversions:
* Support for 1->0 type mappings, i.e. when the argument is being removed.
* Reordering types when converting a type signature.
* Adding new inputs when converting a type signature.

This cl also lays down the initial foundation for supporting 1->N type mappings, but full support will come in a followup.

Moving forward, function signature changes will be driven by populating a SignatureConversion instance. This class contains all of the necessary information for adding/removing/remapping function signatures; e.g. addInputs, addResults, remapInputs, etc.

PiperOrigin-RevId: 254064665

5 years agoExtract the function symbol table functionality, i.e. mapping and name uniquing,...
River Riddle [Wed, 19 Jun 2019 18:55:27 +0000 (11:55 -0700)]
Extract the function symbol table functionality, i.e. mapping and name uniquing, out of Module and into a new class SymbolTable. As modules become operations it is necessary to extract out this functionality that cannot be represented with a generic operation.

PiperOrigin-RevId: 254041734

5 years agoRemove unnecessary -verify-diagnostics
Geoffrey Martin-Noble [Wed, 19 Jun 2019 18:30:16 +0000 (11:30 -0700)]
Remove unnecessary -verify-diagnostics

These were likely added in error because of confusion about the flag when it was just called "-verify". The extra flag doesn't cause much harm, but it does make mlir-opt do more work and clutter the RUN line

PiperOrigin-RevId: 254037016

5 years agoRename -verify mlir-opt flag to -verify-expected-diagnostics
Geoffrey Martin-Noble [Wed, 19 Jun 2019 18:21:41 +0000 (11:21 -0700)]
Rename -verify mlir-opt flag to -verify-expected-diagnostics

This name has caused some confusion because it suggests that it's running op verification (and that this verification isn't getting run by default).

PiperOrigin-RevId: 254035268

5 years agoExport symbols in cpu runner cblas library
Lei Zhang [Wed, 19 Jun 2019 18:13:36 +0000 (11:13 -0700)]
Export symbols in cpu runner cblas library

By default MSVC does not export any symbol and does not create a companion
.lib for a .dll. This will cause problems when trying to link against the
library.

PiperOrigin-RevId: 254033454

5 years agoAdd a pass that translates GPU.launch_func into a series of runtime calls.
Stephan Herhut [Wed, 19 Jun 2019 13:22:36 +0000 (06:22 -0700)]
Add a pass that translates GPU.launch_func into a series of runtime calls.

This does not map the calls to the CUDA libary directly but uses a slim wrapper
ABI on top that has more convenient types for code generation and is stable. Such
ABI is expected to be provided by the actual runner.

PiperOrigin-RevId: 253983833

5 years agoSimplify usages of SplatElementsAttr now that it inherits from DenseElementsAttr.
River Riddle [Wed, 19 Jun 2019 01:26:26 +0000 (18:26 -0700)]
Simplify usages of SplatElementsAttr now that it inherits from DenseElementsAttr.

PiperOrigin-RevId: 253910543

5 years agoNFC: Reorder the attribute classes alphabetically to improve readability.
River Riddle [Tue, 18 Jun 2019 23:41:00 +0000 (16:41 -0700)]
NFC: Reorder the attribute classes alphabetically to improve readability.

PiperOrigin-RevId: 253894445

5 years agoNFC: Append 'Location' to the end of each the location kinds. This is in preparation...
River Riddle [Tue, 18 Jun 2019 20:56:54 +0000 (13:56 -0700)]
NFC: Append 'Location' to the end of each the location kinds. This is in preparation for making the location classes attributes instead of separate IR types.

PiperOrigin-RevId: 253860058

5 years agoReplace usages of 'UniquedFilename' with 'Identifier' and remove it. Identifier alrea...
River Riddle [Tue, 18 Jun 2019 20:35:02 +0000 (13:35 -0700)]
Replace usages of 'UniquedFilename' with 'Identifier' and remove it. Identifier already contains all of the necessary functionality/verification, so having a separate class for filenames is unnecessary.

PiperOrigin-RevId: 253855505

5 years ago[spirv] Add spv.Variable
Lei Zhang [Tue, 18 Jun 2019 18:15:55 +0000 (11:15 -0700)]
[spirv] Add spv.Variable

This is a direct modelling of SPIR-V's OpVariable. The custom assembly format
parsers/prints descriptor in a nicer way if presents. There are other common
decorations that can appear on variables like builtin, which can be supported
later.

This CL additionally deduplicates the parser/printer/verifier declaration
in op definitions by adding defaults to SPV_Op base.
by adding

PiperOrigin-RevId: 253828254

5 years agoAdd a setAttrList() method on mlir::Operation
Mehdi Amini [Tue, 18 Jun 2019 16:38:16 +0000 (09:38 -0700)]
Add a setAttrList() method on mlir::Operation

This is an efficient method to copy attributes from one operation to
another.

PiperOrigin-RevId: 253806004

5 years agoFix GPUToNVVM naming: NNVM should have been NVVM
Alex Zinenko [Tue, 18 Jun 2019 16:12:32 +0000 (09:12 -0700)]
Fix GPUToNVVM naming: NNVM should have been NVVM

Rename `createLowerGpuOpsToNNVMOpsPass` to `createLowerGpuOpsToNVVMOpsPass`.

PiperOrigin-RevId: 253801577

5 years agoFactor fusion compute cost calculation out of LoopFusion and into LoopFusionUtils...
Andy Davis [Tue, 18 Jun 2019 15:52:09 +0000 (08:52 -0700)]
Factor fusion compute cost calculation out of LoopFusion and into LoopFusionUtils (NFC).

PiperOrigin-RevId: 253797886

5 years agoAdd missing cmake dependency from Linalg to MLIRStandardToLLVM.
Jacques Pienaar [Tue, 18 Jun 2019 14:50:40 +0000 (07:50 -0700)]
Add missing cmake dependency from Linalg to MLIRStandardToLLVM.

PiperOrigin-RevId: 253788170

5 years agoPut createGpuKernelOutliningPass in MLIR namespace
Alex Zinenko [Tue, 18 Jun 2019 14:19:38 +0000 (07:19 -0700)]
Put createGpuKernelOutliningPass in MLIR namespace

This function was declared in the `mlir` namespace but defined in the global
namespace, leading to linking errors when used.

PiperOrigin-RevId: 253784410

5 years agoMake examples/Linalg3 depend on the new standard to LLVM conversion library.
Alex Zinenko [Tue, 18 Jun 2019 12:01:30 +0000 (05:01 -0700)]
Make examples/Linalg3 depend on the new standard to LLVM conversion library.

PiperOrigin-RevId: 253767820

5 years agoUse llvm::StringSwitch in lowering of GPU ops to NVVM ops.
Stephan Herhut [Tue, 18 Jun 2019 12:00:13 +0000 (05:00 -0700)]
Use llvm::StringSwitch in lowering of GPU ops to NVVM ops.

PiperOrigin-RevId: 253767688

5 years agoAdd a pass that translates a CUDA kernel function (tagged with nvvm.kernel) to
Stephan Herhut [Tue, 18 Jun 2019 10:26:31 +0000 (03:26 -0700)]
Add a pass that translates a CUDA kernel function (tagged with nvvm.kernel) to
a CUBIN blob for execution on CUDA GPUs.

This is a first in a series of patches to build a simple CUDA runner to allow
experimenting with MLIR code on GPUs.

PiperOrigin-RevId: 253758915

5 years agoAdd mlir::Function::eraseBody helper to remove the body of a function.
Stephan Herhut [Tue, 18 Jun 2019 09:24:16 +0000 (02:24 -0700)]
Add mlir::Function::eraseBody helper to remove the body of a function.

This does not add any new functionality but gives clearing the blocks of the
body region a more obvious name.

PiperOrigin-RevId: 253751382

5 years agoFix the detection of boolean splat values in DenseElementsAttr for arrays with <...
River Riddle [Tue, 18 Jun 2019 02:46:31 +0000 (19:46 -0700)]
Fix the detection of boolean splat values in DenseElementsAttr for arrays with <=15 values.

PiperOrigin-RevId: 253711372

5 years agoAdd a TableGen Type predicate to check that an operand type can be broadcasted to...
Mehdi Amini [Tue, 18 Jun 2019 00:24:51 +0000 (17:24 -0700)]
Add a TableGen Type predicate to check that an operand type can be broadcasted to a particular output type

PiperOrigin-RevId: 253694397

5 years agoRefactor generic op printing: extract a public printFunctionalType() on OpAsmPrinter...
Mehdi Amini [Mon, 17 Jun 2019 22:31:53 +0000 (15:31 -0700)]
Refactor generic op printing: extract a public printFunctionalType() on OpAsmPrinter (NFC)

PiperOrigin-RevId: 253674584

5 years ago[spirv] Add spv.constant
Lei Zhang [Mon, 17 Jun 2019 21:47:22 +0000 (14:47 -0700)]
[spirv] Add spv.constant

This CL defines a single `spv.constant` op to represent various
flavors of SPIR-V constant instructions.

PiperOrigin-RevId: 253665716

5 years ago[spirv] Define common types using op definition spec
Lei Zhang [Mon, 17 Jun 2019 20:29:06 +0000 (13:29 -0700)]
[spirv] Define common types using op definition spec

This CL also tightens spv.FMul to only accept 16/32/64-bit floats.

PiperOrigin-RevId: 253649352

5 years agoVerification for gpu.launch_func should rely on function type and not on the
Stephan Herhut [Mon, 17 Jun 2019 19:47:09 +0000 (12:47 -0700)]
Verification for gpu.launch_func should rely on function type and not on the
actual body of a kernel function. This enables using gpu.launch_func with
external kernel declarations.

PiperOrigin-RevId: 253639770

5 years agoAlso consider attributes when getting context for Operation
Lei Zhang [Mon, 17 Jun 2019 18:50:16 +0000 (11:50 -0700)]
Also consider attributes when getting context for Operation

This CL also updates to use containing region as a fallback way to find
context since functions will eventually become ops with regions.

PiperOrigin-RevId: 253627322

5 years ago[spirv] Add doc regarding the SPIR-V dialect
Lei Zhang [Mon, 17 Jun 2019 18:42:37 +0000 (11:42 -0700)]
[spirv] Add doc regarding the SPIR-V dialect

* Add basic design philosophy
* Add type syntax to both the doc and type parser comments

PiperOrigin-RevId: 253625782

5 years agoIntroduce std.index_cast and its lowering+translation to LLVM
Alex Zinenko [Mon, 17 Jun 2019 18:35:05 +0000 (11:35 -0700)]
Introduce std.index_cast and its lowering+translation to LLVM

Index types integers of platform-specific bit width.  They are used to index
memrefs and as loop induction variables, however they could not be obtained
from an integer until now, making it virtually impossible to express indirect
accesses (given that memrefs of indices are not allowed) or data-dependent
loops.  Introduce `std.index_cast` to transform indices into integers and vice
versa.  The semantics of this cast is to sign-extend when casting to a wider
integer, and to truncate when casting to a narrower integer.  It belongs to
StandardOps because both types it operates on are standard types, and because
its results are likely to be used in std.load and std.store.

Introduce llvm.sext, llvm.zext and llvm.trunc operations to the LLVM dialect.
Provide the conversion of `std.index_cast` to llvm.sext or llvm.trunc,
depending on the actual bitwidth of `index` known during the conversion.

PiperOrigin-RevId: 253624100

5 years agoFactor Region::getUsedValuesDefinedAbove into Transforms/RegionUtils
Alex Zinenko [Mon, 17 Jun 2019 18:30:16 +0000 (11:30 -0700)]
Factor Region::getUsedValuesDefinedAbove into Transforms/RegionUtils

Arguably, this function is only useful for transformations and should not
pollute the main IR.  Also make sure it accepts a the resulting container
by-reference instead of returning it.

PiperOrigin-RevId: 253622981

5 years agoLoopFusion: adds support for computing forward computation slices, which will enable...
Andy Davis [Mon, 17 Jun 2019 16:59:35 +0000 (09:59 -0700)]
LoopFusion: adds support for computing forward computation slices, which will enable fusion of consumer loop nests into their producers in subsequent CLs.

PiperOrigin-RevId: 253601994

5 years agoAdd lowering pass from GPU dialect operations to LLVM/NVVM intrinsics.
Stephan Herhut [Mon, 17 Jun 2019 10:56:20 +0000 (03:56 -0700)]
Add lowering pass from GPU dialect operations to LLVM/NVVM intrinsics.

PiperOrigin-RevId: 253551452

5 years agoMove the Region type out to its own .h/.cpp file instead of putting it into
Chris Lattner [Sun, 16 Jun 2019 03:19:36 +0000 (20:19 -0700)]
Move the Region type out to its own .h/.cpp file instead of putting it into
Block.h/cpp.

This doesn't change much but makes it easier to find.

PiperOrigin-RevId: 253423041

5 years agoUse braces when building an 'llvm_return' via EDSC intrinsics. This fixes a build...
River Riddle [Sat, 15 Jun 2019 02:54:56 +0000 (19:54 -0700)]
Use braces when building an 'llvm_return' via EDSC intrinsics. This fixes a build error on MSVC where it is unable to properly handled template type aliases.

PiperOrigin-RevId: 253339204

5 years agoRemove dead code.
Jing Pu [Fri, 14 Jun 2019 23:06:49 +0000 (16:06 -0700)]
Remove dead code.

PiperOrigin-RevId: 253314416

5 years agoStart moving conversions to {lib,include/mlir}/Conversion
Alex Zinenko [Fri, 14 Jun 2019 22:54:21 +0000 (15:54 -0700)]
Start moving conversions to {lib,include/mlir}/Conversion

Conversions from dialect A to dialect B depend on both A and B.  Therefore, it
is reasonable for them to live in a separate library that depends on both
DialectA and DialectB library, and does not forces dependees of DialectA or
DialectB to also link in the conversion.  Create the directory layout for the
conversions and move the Standard to LLVM dialect conversion as the first
example.

PiperOrigin-RevId: 253312252

5 years agoDisallow using NOperands/NResults when N < 2. We have special traits for the case...
River Riddle [Fri, 14 Jun 2019 18:56:41 +0000 (11:56 -0700)]
Disallow using NOperands/NResults when N < 2. We have special traits for the case of 0/1 that we explicitly check for throughout the codebase. This also fixes weird build failures in MSVC where it doesn't properly handle template type aliases.

PiperOrigin-RevId: 253269936

5 years agoAdd Linalg CopyOp
Nicolas Vasilache [Fri, 14 Jun 2019 17:18:08 +0000 (10:18 -0700)]
Add Linalg CopyOp

This CL adds a generic CopyOp to Linalg and its lowering to loops.
The CopyOp supports input and output permutation maps.
When combined with tiling and allocating a new local buffer, this should provide basic support for implementing simple memory transfers with coalescing.

At the moment, lowering copies to a library call is not supported.

PiperOrigin-RevId: 253250497

5 years agoAdd an overloaded 'get' method to DenseElementsAttr that accepts an initializer_list.
River Riddle [Fri, 14 Jun 2019 15:41:32 +0000 (08:41 -0700)]
Add an overloaded 'get' method to DenseElementsAttr that accepts an initializer_list.

PiperOrigin-RevId: 253234385

5 years agoExplicitly construct ArrayRef in AttributeTest.cpp
Alex Zinenko [Fri, 14 Jun 2019 14:28:41 +0000 (07:28 -0700)]
Explicitly construct ArrayRef in AttributeTest.cpp

Some compilers find initializer list constructors from boolean literals
ambiguous between ArrayRef<bool> and ArrayRef<Attribute>.  Call the
ArrayRef<bool> constructor explicitly to disambiguate.

PiperOrigin-RevId: 253224859

5 years agoConvert a nest affine loops to a GPU kernel
Alex Zinenko [Fri, 14 Jun 2019 08:56:19 +0000 (01:56 -0700)]
Convert a nest affine loops to a GPU kernel

This converts entire loops into threads/blocks.  No check on the size of the
block or grid, or on the validity of parallelization is performed, it is under
the responsibility of the caller to strip-mine the loops and to perform the
dependence analysis before calling the conversion.

PiperOrigin-RevId: 253189268

5 years agoRefactor SplatElementsAttr to inherit from DenseElementsAttr as opposed to being...
River Riddle [Fri, 14 Jun 2019 00:24:33 +0000 (17:24 -0700)]
Refactor SplatElementsAttr to inherit from DenseElementsAttr as opposed to being a separate Attribute type. DenseElementsAttr provides a better internal representation for splat values as well as better API for accessing elements.

PiperOrigin-RevId: 253138287

5 years agoNFC: Fix a narrowing conversion from size_t to int64_t when constructing a VectorType.
River Riddle [Thu, 13 Jun 2019 23:09:56 +0000 (16:09 -0700)]
NFC: Fix a narrowing conversion from size_t to int64_t when constructing a VectorType.

PiperOrigin-RevId: 253125435

5 years agoNFC: Fix a warning for casting away const qualifiers.
River Riddle [Thu, 13 Jun 2019 23:02:36 +0000 (16:02 -0700)]
NFC: Fix a warning for casting away const qualifiers.

PiperOrigin-RevId: 253124057

5 years agoAdd ability to verify type matching between operands/results
Geoffrey Martin-Noble [Thu, 13 Jun 2019 21:52:29 +0000 (14:52 -0700)]
Add ability to verify type matching between operands/results

This extends and generalizes the functionality for checking that element types match

PiperOrigin-RevId: 253110512

5 years agoAdd a definition of the library function to use when Linalg ops are
Mahesh Ravishankar [Thu, 13 Jun 2019 20:47:08 +0000 (13:47 -0700)]
Add a definition of the library function to use when Linalg ops are
lowered to LLVM, instead of expecting one to exist in the Module

PiperOrigin-RevId: 253097382

5 years agoAdd several utility 'getValues<T>' functions to DenseElementsAttr that return ranges...
River Riddle [Thu, 13 Jun 2019 20:22:32 +0000 (13:22 -0700)]
Add several utility 'getValues<T>' functions to DenseElementsAttr that return ranges as opposed to filling a SmallVector. This is much more efficient for the general case and allows for avoiding constructing APInt/APFloat/Attribute when possible.

PiperOrigin-RevId: 253092550

5 years agoDisallow non-index operands and results in affine.apply
Alex Zinenko [Thu, 13 Jun 2019 14:08:46 +0000 (07:08 -0700)]
Disallow non-index operands and results in affine.apply

`affine.apply` is supposed to operate on values of index types in context of
affine loops.  It is possible to programmatically constuct an `affine.apply`
that takes values of other types as operands or returns them, but it would not
be parseable.  Disallow such cases in the verifier.

PiperOrigin-RevId: 253021704

5 years agoGPU Dialect: introduce gpu.return
Alex Zinenko [Thu, 13 Jun 2019 08:49:44 +0000 (01:49 -0700)]
GPU Dialect: introduce gpu.return

This terminator operation should appear at the end of the blocks in the body
region of `gpu.launch` when the control flow needs to be returned from the
kernel.  Using `std.return` in this place is ambiguous: it may exit the body
region or the enclosing function.  Furthermore, this allows the GPU dialect to
impose the absence of return values as required by the underlying kernel
execution models.

Update outlining transformation from `gpu.launch` to `gpu.launch_func` so that
it replaces `gpu.return` with `std.return`.

PiperOrigin-RevId: 252985992

5 years ago[spirv] Add SPV_StorageClassAttr and PointerType
Lei Zhang [Thu, 13 Jun 2019 00:39:33 +0000 (17:39 -0700)]
[spirv] Add SPV_StorageClassAttr and PointerType

Pointer types need to specify the storage class. We use the utility functions
generated from SPV_StorageClassAttr to parse and print the storage classes.

Also improved the case that no element type is provided for (runtime) array.

PiperOrigin-RevId: 252935599

5 years agoUpdate the Parser to support parsing/printing DenseElementAttrs with a splat value...
River Riddle [Wed, 12 Jun 2019 22:05:45 +0000 (15:05 -0700)]
Update the Parser to support parsing/printing DenseElementAttrs with a splat value. The syntax for this is the same as 0-D tensors:

  dense<tensor<100x100x100xi32>, 10>
  dense<tensor<1x1x1xi64>, -5>

PiperOrigin-RevId: 252907880

5 years ago[spirv] Use mlir::parseType in type parsers and add more checks
Lei Zhang [Wed, 12 Jun 2019 19:16:05 +0000 (12:16 -0700)]
[spirv] Use mlir::parseType in type parsers and add more checks

PiperOrigin-RevId: 252874386

5 years ago[ODG] Fix value indices in verification error messages
Lei Zhang [Wed, 12 Jun 2019 19:08:13 +0000 (12:08 -0700)]
[ODG] Fix value indices in verification error messages

we should use the dynamic index for the specific value instead
of the static one for ODS-declared values.

PiperOrigin-RevId: 252873052

5 years agoAdd Linalg FillOp
Nicolas Vasilache [Wed, 12 Jun 2019 18:50:19 +0000 (11:50 -0700)]
Add Linalg FillOp

This CL adds a generic FillOp to Linalg and its lowering to loops.
This is achieved by avoiding to specify the static NLoopTypes and ViewRanks type traits but instead defines the relevant methods as `extraClassDeclaration`.
The relevant AffineMap and scalar emission code are added, with relevant tests.

This gives us a first rank-agnostic Linalg op with its generic lowering to loops that should compose with view-based tiling and fusion.

PiperOrigin-RevId: 252869205

5 years agoFix static assertion in AttributeDetail.h
Alex Zinenko [Wed, 12 Jun 2019 15:17:13 +0000 (08:17 -0700)]
Fix static assertion in AttributeDetail.h

llvm::maskTrailingOnes<char> runs into a static assertion on the type not being
unsigned.  Use `unsigned char` instead of `char`.
PiperOrigin-RevId: 252827214

5 years agoUpdate 2 instances of isa<BlockArgument>
Nicolas Vasilache [Wed, 12 Jun 2019 01:16:17 +0000 (18:16 -0700)]
Update 2 instances of isa<BlockArgument>

PiperOrigin-RevId: 252739405

5 years agoFix OSS build
Nicolas Vasilache [Wed, 12 Jun 2019 01:06:43 +0000 (18:06 -0700)]
Fix OSS build

Missing a spot with std::make_pair causes a compiler error in OSS.
Also fixes the warning:
```
warning: suggest parentheses around â€˜&&’ within â€˜||’ [-Wparentheses]
            it->getSecond()->getType().isa<BufferType>() &&
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
                "Buffer or block argument expected");
```
PiperOrigin-RevId: 252738323

5 years agoRefactor DenseElementsAttr to support auto-splatting the dense data on construction...
River Riddle [Tue, 11 Jun 2019 23:14:17 +0000 (16:14 -0700)]
Refactor DenseElementsAttr to support auto-splatting the dense data on construction. This essentially means that we always auto-detect splat data and only store the minimum amount of data necessary. Support for parsing dense splats, and removing SplatElementsAttr(now that it is redundant) will come in followup cls

PiperOrigin-RevId: 252720561

5 years agoAdd basic cost modeling to the dialect conversion infrastructure. This initial cost...
River Riddle [Tue, 11 Jun 2019 22:38:13 +0000 (15:38 -0700)]
Add basic cost modeling to the dialect conversion infrastructure. This initial cost model favors specific patterns based upon two criteria:
1) Lowest minimum pattern stack depth when legalizing.
  - This leads the system to favor patterns that have lower legalization stacks, i.e. represent a more direct mapping to the target.

2)  Pattern benefit.
  - When considering multiple patterns with the same legalization depth, this favors patterns with a larger specified benefit.

PiperOrigin-RevId: 252713470

5 years agoAdd a Linalg fusion pass.
Nicolas Vasilache [Tue, 11 Jun 2019 21:09:17 +0000 (14:09 -0700)]
Add a Linalg fusion pass.

This CL adds a fusion pass for the Linalg dialect.
Fusion is backed by a simple analysis on SSA values and proceeds as follows:
1. A dependence and alias analyses are performed on views.
2. A Linalg op is tiled by a particular tile size. This creates a new Linalg op operating on tiled loops and tiled views.
3. The dependence analysis is used to obtain ops that produce views that are consumed by the original Linalg op.
4. Dependence analysis is used to determine whether op-level fusion would violate any dependence.
5. If fusion is safe, matching tiled views are sliced for the producing op.
6. A tiled clone of the producer op is written before the tiled consumer op.

If a producer is fused, its entire output view has been computed in tiled form.
The original producer op is then erased.

PiperOrigin-RevId: 252695194

5 years agoAdd a lowering for Linalg matmul to LLVM
Nicolas Vasilache [Tue, 11 Jun 2019 19:09:50 +0000 (12:09 -0700)]
Add a lowering for Linalg matmul to LLVM

This CL adds a lowering to LLVM for MamulOp and a corresponding integration test.

View descriptor manipulation is moved from MLIR's LLVM dialect to C++ code compiled on the side. To this end a separation is introduced between `cblas.cpp` and `cblas_interface.cpp`, the latter operating on view types whose ABI correspond to the LLVM signature generated by MLIR.

An intermediary step is introduced that allocates a new descriptor on the MLIR side for the purpose of passing it to LLVM. The reason for this extra step is that the ABI for by-value ViewType objects wants aligned descriptors, e.g.:
```
extern "C" void linalg_dot_impl(ViewType<float, 1> X, ViewType<float, 1> Y,
                                BaseViewType<float> Z) {
   ...
}
```
produces LLVM IR with the signature:
```
%struct.ViewType = type { %struct.BaseViewType, [1 x i64], [1 x i64] }
%struct.BaseViewType = type { float*, i64 }

define void @linalg_dot_impl(%struct.ViewType* byval align 8, %struct.ViewType* byval align 8, float*, i64) tensorflow/mlir#0 {
...
}
```

We don't seem to be able to make such aligned  allocations in the MLIR -> LLVM converter atm.
Going through a level of indirection allows the test to pass.
The temporary tradeoff is that the MLIR shims have to be written by hand.
They will disappear in the future.

PiperOrigin-RevId: 252670672

5 years agoSimplify trait naming for verifying argument/result constraints.
Jacques Pienaar [Tue, 11 Jun 2019 18:30:56 +0000 (11:30 -0700)]
Simplify trait naming for verifying argument/result constraints.

Improve the naming to something more intuitive.

PiperOrigin-RevId: 252662347

5 years ago[spirv] Add a skeleton to translate standard ops into SPIR-V dialect
Mahesh Ravishankar [Tue, 11 Jun 2019 17:47:06 +0000 (10:47 -0700)]
[spirv] Add a skeleton to translate standard ops into SPIR-V dialect

PiperOrigin-RevId: 252651994

5 years agoAdd a utility to OpAsmPrinter for printing an optional trailing arrow type list....
River Riddle [Tue, 11 Jun 2019 17:26:21 +0000 (10:26 -0700)]
Add a utility to OpAsmPrinter for printing an optional trailing arrow type list. This is useful for any operation that wants to print a set of types in the same format as a FunctionType/Operation signature.

PiperOrigin-RevId: 252647152

5 years agoNFC: Cleanup the naming scheme for registering legalization actions to be consistent...
River Riddle [Tue, 11 Jun 2019 16:51:05 +0000 (09:51 -0700)]
NFC: Cleanup the naming scheme for registering legalization actions to be consistent, and move a file functions to the source file.

PiperOrigin-RevId: 252639629

5 years agoUse DialectConversion to lower the Affine dialect to the Standard dialect
Alex Zinenko [Tue, 11 Jun 2019 15:33:18 +0000 (08:33 -0700)]
Use DialectConversion to lower the Affine dialect to the Standard dialect

This introduces the support for region-containing operations to the dialect
conversion framework in order to support the conversion of affine control-flow
operations into the standard control flow with branches.  Regions that belong
to an operation are converted before the operation itself.  The
DialectConversionPattern can therefore access the converted regions of the
original operation and process them further if necessary.  In particular, the
conversion is allowed to move the blocks from the original region to other
regions and to split blocks into multiple blocks.  All block manipulations must
be performed through the PatternRewriter to ensure they will be undone if the
conversion fails.

Port the pass converting from the affine dialect (loops and ifs with bodies as
regions) to the standard dialect (branch-based cfg) to use DialectConversion in
order to exercise this new functionality.  The modification to the lowering
functions are minor and are focused on using the PatterRewriter instead of
directly modifying the IR.

PiperOrigin-RevId: 252625169

5 years ago[spirv] Include SPIRVStructureOps.td in SPIRVOps.td
Lei Zhang [Tue, 11 Jun 2019 13:48:37 +0000 (06:48 -0700)]
[spirv] Include SPIRVStructureOps.td in SPIRVOps.td

This allows us to have SPIRVOps.td as the single entry point for
all SPIR-V ops, which simplifies downstream users and build rules.

PiperOrigin-RevId: 252609258

5 years ago[ODG] Add support for private methods in class writers
Lei Zhang [Tue, 11 Jun 2019 12:56:31 +0000 (05:56 -0700)]
[ODG] Add support for private methods in class writers

PiperOrigin-RevId: 252602093

5 years ago[spirv] Add missing CMake rules for enum utility generation
Lei Zhang [Tue, 11 Jun 2019 12:48:30 +0000 (05:48 -0700)]
[spirv] Add missing CMake rules for enum utility generation

PiperOrigin-RevId: 252601308

5 years agoAdd bool constant attributes.
Jacques Pienaar [Tue, 11 Jun 2019 05:13:57 +0000 (22:13 -0700)]
Add bool constant attributes.

PiperOrigin-RevId: 252551030

5 years agoFix MSVC 2019 missing <string> include (NFC)
Mehdi Amini [Tue, 11 Jun 2019 04:30:29 +0000 (21:30 -0700)]
Fix MSVC 2019 missing <string> include (NFC)

Fix tensorflow/mlir#31.

PiperOrigin-RevId: 252547010

5 years agoChange a call to FloatAttr::getChecked to FloatAttr::get inside of 'parseFloatAttr...
River Riddle [Tue, 11 Jun 2019 04:15:23 +0000 (21:15 -0700)]
Change a call to FloatAttr::getChecked to FloatAttr::get inside of 'parseFloatAttr'. The invariants of FloatAttr are already checked before construction. This also removes an unnecessary materialization of a mlir::Location which becomes expensive when parsing dense element literals.

PiperOrigin-RevId: 252545776

5 years agoAdd a general Operation::verify that verifies an operation instance and the dominance...
River Riddle [Tue, 11 Jun 2019 01:37:09 +0000 (18:37 -0700)]
Add a general Operation::verify that verifies an operation instance and the dominance of operations in any nested regions.

PiperOrigin-RevId: 252529850

5 years ago[spirv] Add values for enum cases and generate the enum utilities
Lei Zhang [Mon, 10 Jun 2019 22:12:04 +0000 (15:12 -0700)]
[spirv] Add values for enum cases and generate the enum utilities

PiperOrigin-RevId: 252494957

5 years ago[spirv] NFC: use two spaces for indentation in gen_spirv_dialect.py
Lei Zhang [Mon, 10 Jun 2019 20:15:52 +0000 (13:15 -0700)]
[spirv] NFC: use two spaces for indentation in gen_spirv_dialect.py

PiperOrigin-RevId: 252469663

5 years agoExpose a minimal type parser to dialects.
Nicolas Vasilache [Mon, 10 Jun 2019 20:12:32 +0000 (13:12 -0700)]
Expose a minimal type parser to dialects.

This CL exposes a parseType method which allows standalone reuse of the MLIR type parsing mechanism. This is a free function for now because the underlying MLIR parser is not guaranteed to receive a StringRef which lives in the proper MemBuffer. This requires building a new MemBuffer/SourceMgr and modifying the Parser constructor to not require an mlir::Module.

The error diagnostic emitted by parseType has context limited to the local string.
For now the dialect has the additional option to emit its own extra error that has the FileLineColLoc context.

In the future, both error messages should be combined into a single error.

PiperOrigin-RevId: 252468911

5 years ago[spirv] Add array and run-time array types
Lei Zhang [Mon, 10 Jun 2019 19:21:44 +0000 (12:21 -0700)]
[spirv] Add array and run-time array types

PiperOrigin-RevId: 252458108

5 years ago[ODG] Address compiler warnings of comparing signed and unsigned integer expressions
Lei Zhang [Mon, 10 Jun 2019 18:08:52 +0000 (11:08 -0700)]
[ODG] Address compiler warnings of comparing signed and unsigned integer expressions

PiperOrigin-RevId: 252442613

5 years agoReturn dependence result enum to distiguish between dependence result and error cases...
Andy Davis [Mon, 10 Jun 2019 17:50:08 +0000 (10:50 -0700)]
Return dependence result enum to distiguish between dependence result and error cases (NFC).

PiperOrigin-RevId: 252437616

5 years ago[ODS] Support variadic operand/result verification
Lei Zhang [Sun, 9 Jun 2019 14:00:09 +0000 (07:00 -0700)]
[ODS] Support variadic operand/result verification

This CL enables verification code generation for variadic operands and results.
In verify(), we use fallback getter methods to access all the dynamic values
belonging to one static variadic operand/result to reuse the value range
calculation there.

PiperOrigin-RevId: 252288219

5 years ago[ODG] Use getODSOperands() and getODSResults() to back accessors
Lei Zhang [Sun, 9 Jun 2019 12:50:09 +0000 (05:50 -0700)]
[ODG] Use getODSOperands() and getODSResults() to back accessors

This CL added getODSOperands() and getODSResults() as fallback getter methods for
getting all the dynamic values corresponding to a static operand/result (which
can be variadic). It should provide a uniform way of calculating the value ranges.
All named getter methods are layered on top of these methods now.

PiperOrigin-RevId: 252284270

5 years ago[TableGen] Generating enum definitions and utility functions
Lei Zhang [Sat, 8 Jun 2019 15:39:07 +0000 (08:39 -0700)]
[TableGen] Generating enum definitions and utility functions

Enum attributes can be defined using `EnumAttr`, which requires all its cases
to be defined with `EnumAttrCase`. To facilitate the interaction between
`EnumAttr`s and their C++ consumers, add a new EnumsGen TableGen backend
to generate a few common utilities, including an enum class, `llvm::DenseMapInfo`
for the enum class, conversion functions from/to strings.

This is controlled via the `-gen-enum-decls` and `-gen-enum-defs` command-line
options of `mlir-tblgen`.

PiperOrigin-RevId: 252209623

5 years agoUpdate function comment, since we added FP16 support for getZeroAttr.
MLIR Team [Fri, 7 Jun 2019 20:44:09 +0000 (13:44 -0700)]
Update function comment, since we added FP16 support for getZeroAttr.

PiperOrigin-RevId: 252110998

5 years agoNFC: Cleanup the grouping of DenseElementsAttr 'get' methods, and move the bit write...
River Riddle [Fri, 7 Jun 2019 19:08:36 +0000 (12:08 -0700)]
NFC: Cleanup the grouping of DenseElementsAttr 'get' methods, and move the bit write/read functions to static functions in Attributes.cpp.

PiperOrigin-RevId: 252094145

5 years agoRemove the ability to directly construct a DenseElementsAttr with a raw character...
River Riddle [Fri, 7 Jun 2019 16:57:29 +0000 (09:57 -0700)]
Remove the ability to directly construct a DenseElementsAttr with a raw character buffer. This made assumptions about how DenseElementsAttr structured its internal storage, which may change in the future. To replace the existing use cases, a few utility methods have been added:

* 'get' methods that allow constructing from an ArrayRef of integer or floating point values.
* A 'reshape' method to allow for changing the shape without changing the underlying data.

PiperOrigin-RevId: 252067898

5 years agoNFC: Cleanup FuncVerifier and refactor it into a general OperationVerifier. The funct...
River Riddle [Fri, 7 Jun 2019 16:46:13 +0000 (09:46 -0700)]
NFC: Cleanup FuncVerifier and refactor it into a general OperationVerifier. The function specific verification has been moved into Function::verify. This is in preparation for adding a general Operation::verify method.

PiperOrigin-RevId: 252065646

5 years agoRemove unnecessary StandardOps dependency
Geoffrey Martin-Noble [Fri, 7 Jun 2019 12:30:35 +0000 (05:30 -0700)]
Remove unnecessary StandardOps dependency

PiperOrigin-RevId: 252032386

5 years agoAdd a convenient getDialect() accessor on Op<> class
Mehdi Amini [Fri, 7 Jun 2019 04:50:13 +0000 (21:50 -0700)]
Add a convenient getDialect() accessor on Op<> class

PiperOrigin-RevId: 251988464

5 years agoNFC: Replace typelist_contains with llvm::is_one_of. This should also fix weird build...
River Riddle [Fri, 7 Jun 2019 04:39:36 +0000 (21:39 -0700)]
NFC: Replace typelist_contains with llvm::is_one_of. This should also fix weird build failures on MSVC related to typelist_contains for missing template arguments.

PiperOrigin-RevId: 251987621

5 years agoAdd free standing getElementTypeOrSelf member.
Jacques Pienaar [Fri, 7 Jun 2019 02:53:49 +0000 (19:53 -0700)]
Add free standing getElementTypeOrSelf member.

This function returns the element type of the underlying type or the input type itself. This removes some of the casting and code from ODS and into C++ code.

I've not converted all the call sites (as this requires a new include and target) and wanted to run it past folks first.

PiperOrigin-RevId: 251978156

5 years agoInternal change
Mehdi Amini [Fri, 7 Jun 2019 01:52:29 +0000 (18:52 -0700)]
Internal change

PiperOrigin-RevId: 251972430

5 years agoAdd the getDialectNamespace static utility method to the Linalg dialect.
MLIR Team [Thu, 6 Jun 2019 23:42:36 +0000 (16:42 -0700)]
Add the getDialectNamespace static utility method to the Linalg dialect.

PiperOrigin-RevId: 251953766

5 years agoRemove the explicit attribute kinds for DenseIntElementsAttr and DenseFPElementsAttr...
River Riddle [Thu, 6 Jun 2019 23:15:42 +0000 (16:15 -0700)]
Remove the explicit attribute kinds for DenseIntElementsAttr and DenseFPElementsAttr in favor of just one DenseElementsAttr. Now that attribute has the ability to define 'classof(Attribute attr)' methods, these derived classes can just be specializations of the main attribute class.

PiperOrigin-RevId: 251948820

5 years agoAdding utility to parse optional colon-type-lists.
Ben Vanik [Thu, 6 Jun 2019 22:58:47 +0000 (15:58 -0700)]
Adding utility to parse optional colon-type-lists.

PiperOrigin-RevId: 251945512

5 years agoSimplify DenseElementsAttr by rounding up the storage of odd bit widths to 8-bits...
River Riddle [Thu, 6 Jun 2019 22:55:17 +0000 (15:55 -0700)]
Simplify DenseElementsAttr by rounding up the storage of odd bit widths to 8-bits. This removes the requirement that the underlying buffer be aligned to 64 bits which opens the door for several optimizations in the future, e.g. detecting splat.

PiperOrigin-RevId: 251944922

5 years agoAdd support to ConversionTarget for storing legalization actions for entire dialects...
River Riddle [Thu, 6 Jun 2019 22:48:14 +0000 (15:48 -0700)]
Add support to ConversionTarget for storing legalization actions for entire dialects as opposed to individual operations. This allows for better support of unregistered operations, as well as removing the need to collect all of the operations for a given dialect(which may be very expensive).

PiperOrigin-RevId: 251943590

5 years agoAdd support for matchAndRewrite to the DialectConversion patterns. This also drops...
River Riddle [Thu, 6 Jun 2019 22:38:08 +0000 (15:38 -0700)]
Add support for matchAndRewrite to the DialectConversion patterns. This also drops the default "always succeed" match override to better align with RewritePattern.

PiperOrigin-RevId: 251941625

5 years agoAdd a general operation property 'IsolatedFromAbove' that guarantees that all regions...
River Riddle [Thu, 6 Jun 2019 21:28:13 +0000 (14:28 -0700)]
Add a general operation property 'IsolatedFromAbove' that guarantees that all regions of a given operation are explicit capture only and will not reference values defined above the enclosing operation. This trait will be useful for applying some of the properties currently attached to Functions to operations, e.g. verifying dominance within a specific operation, enabling multi-threading of certain transformations between different instances, etc.

PiperOrigin-RevId: 251927466