platform/upstream/llvm.git
5 years agoNFC: Uniformize the return of the LocationAttr 'get' methods to 'Location'.
River Riddle [Tue, 25 Jun 2019 23:57:32 +0000 (16:57 -0700)]
NFC: Uniformize the return of the LocationAttr 'get' methods to 'Location'.

PiperOrigin-RevId: 255078768

5 years agoModify the syntax of the the ElementsAttrs to print the type as a colon type.
River Riddle [Tue, 25 Jun 2019 23:06:13 +0000 (16:06 -0700)]
Modify the syntax of the the ElementsAttrs to print the type as a colon type.

This is the standard syntax for types on operations, and is also already used by IntegerAttr and FloatAttr.

Example:
  dense<5> : tensor<i32>
  dense<[3]> : tensor<1xi32>
PiperOrigin-RevId: 255069157

5 years agoFix typo in Toy tutorial documentation
Rasmus Munk Larsen [Tue, 25 Jun 2019 21:59:40 +0000 (14:59 -0700)]
Fix typo in Toy tutorial documentation

PiperOrigin-RevId: 255054639

5 years agoFix unclear sentence.
Rasmus Munk Larsen [Tue, 25 Jun 2019 19:23:28 +0000 (12:23 -0700)]
Fix unclear sentence.

PiperOrigin-RevId: 255022564

5 years agoMove the IndexedAccessorIterator to STLExtras to allow for reuse.
River Riddle [Tue, 25 Jun 2019 19:10:46 +0000 (12:10 -0700)]
Move the IndexedAccessorIterator to STLExtras to allow for reuse.

This iterator is useful for implementing random access iterators based upon an index and an object pointer. Moving it to STLExtras allows for reuse elsewhere throughout the codebase, e.g. simplifying the DenseElementsAttr iterators.

PiperOrigin-RevId: 255020377

5 years agoInternal change
Nicolas Vasilache [Tue, 25 Jun 2019 19:02:56 +0000 (12:02 -0700)]
Internal change

PiperOrigin-RevId: 255018853

5 years agoSupport printing SSA ids in affine.load/store which do not have special names.
Andy Davis [Tue, 25 Jun 2019 17:29:53 +0000 (10:29 -0700)]
Support printing SSA ids in affine.load/store which do not have special names.

PiperOrigin-RevId: 254997746

5 years agoUpdate the OperationFolder to find a valid insertion point when materializing constants.
River Riddle [Tue, 25 Jun 2019 16:42:52 +0000 (09:42 -0700)]
Update the OperationFolder to find a valid insertion point when materializing constants.

The OperationFolder currently just inserts into the entry block of a Function, but regions may be isolated above, i.e. explicit capture only, and blindly inserting constants may break the invariants of these regions.

PiperOrigin-RevId: 254987796

5 years agoGPUtoNVVM: adjust integer bitwidth when lowering special register ops
Alex Zinenko [Tue, 25 Jun 2019 16:04:13 +0000 (09:04 -0700)]
GPUtoNVVM: adjust integer bitwidth when lowering special register ops

GPU dialect operations (launch and launch_func) use `index` type for thread and
block index values inside the kernel, for compatibility with affine loops.
NVVM dialect operations, following the NVVM intrinsics, use `!llvm.i32` type,
which does not necessarily have the same bit width as the lowered `index` type.
Optionally sign-extend (indices are signed) or truncate the result of the NVVM
dialect operation to the bit width of the lowered `index` type before passing
it to other operations.  This behavior is consistent with `std.index_cast`.  We
cannot use the latter since we are targeting LLVM dialect types directly,
rather than standard integer types.

PiperOrigin-RevId: 254980868

5 years agoAdd gpu::GPUDialect::isKernel helper.
Stephan Herhut [Tue, 25 Jun 2019 13:44:58 +0000 (06:44 -0700)]
Add gpu::GPUDialect::isKernel helper.

Also some mild cleanup of the kernel to cubin conversion pass.

PiperOrigin-RevId: 254959303

5 years agoAdd missing dependence to MLIRLLVMIR
Nicolas Vasilache [Tue, 25 Jun 2019 13:35:28 +0000 (06:35 -0700)]
Add missing dependence to MLIRLLVMIR

PiperOrigin-RevId: 254957980

5 years agoNVVM target: emit nvvm.annotations for kernel functions
Alex Zinenko [Tue, 25 Jun 2019 13:30:32 +0000 (06:30 -0700)]
NVVM target: emit nvvm.annotations for kernel functions

PTX backend in LLVM expects additional module-level metadata
`!nvvm.annotations` that lists functions that can be used as GPU kernels.
Generate this metadata based on the `gpu.kernel` attribute attached to
functions.  This attribute is added automatically by the kernel outlining pass
in the GPU dialect lowering flow.

PiperOrigin-RevId: 254957345

5 years agogpu.launch_func: add accessors to grid configuration operands
Alex Zinenko [Tue, 25 Jun 2019 11:21:10 +0000 (04:21 -0700)]
gpu.launch_func: add accessors to grid configuration operands

Add accessor functions that return `gpu::KernelDim3` containing the respective
operands for grid and block size accepted by `gpu.launch_func`.  Use the same
signature as for `gpu.launch`.

PiperOrigin-RevId: 254942674

5 years agoPrint both type in diagnostic emitted on mismatch between def/use of SSA Values ...
Mehdi Amini [Tue, 25 Jun 2019 00:51:44 +0000 (17:51 -0700)]
Print both type in diagnostic emitted on mismatch between def/use of SSA Values (NFC)

The error would look like:

  path/filename.mlir:32:23: error: use of value '%28' expects different type than prior uses: ''i32'' vs ''!_tf.control''

PiperOrigin-RevId: 254874859

5 years agoNFC: Move the ArgConverter methods out-of-line to improve readability.
River Riddle [Tue, 25 Jun 2019 00:36:05 +0000 (17:36 -0700)]
NFC: Move the ArgConverter methods out-of-line to improve readability.

PiperOrigin-RevId: 254872695

5 years agoFix OSS build
Nicolas Vasilache [Mon, 24 Jun 2019 22:23:26 +0000 (15:23 -0700)]
Fix OSS build

PiperOrigin-RevId: 254847773

5 years agoSplit test-specific passes out of mlir-opt
Nicolas Vasilache [Mon, 24 Jun 2019 21:35:21 +0000 (14:35 -0700)]
Split test-specific passes out of mlir-opt

Instead put their impl in test/lib and link them into mlir-test-opt

PiperOrigin-RevId: 254837439

5 years agoCache several common LLVMTypes in the LLVMDialect.
River Riddle [Mon, 24 Jun 2019 19:03:44 +0000 (12:03 -0700)]
Cache several common LLVMTypes in the LLVMDialect.

LLVM is not thread-safe which means that several of the 'get' methods for LLVMType must be double locked to ensure thread-safety. This cl adds static caching, i.e. no lookups or locking, for several simple LLVM types(i1, half, void, etc.). It also cleans up the implementation of the double locking that is required for some types. In the future we could add a form of dynamic caching to only need to lock one mutex in the best case, but that requires analysis on the memory overhead/vs time lost to taking two locks.

PiperOrigin-RevId: 254806747

5 years agoAdd SPIR-V Load/Store operations. Currently this only support memory
Mahesh Ravishankar [Mon, 24 Jun 2019 17:59:05 +0000 (10:59 -0700)]
Add SPIR-V Load/Store operations. Currently this only support memory
operands being None, Volatile, Aligned and Nontemporal

PiperOrigin-RevId: 254792353

5 years agoNFC: Simplify Operation::getContext to use the context within the location.
River Riddle [Mon, 24 Jun 2019 16:22:07 +0000 (09:22 -0700)]
NFC: Simplify Operation::getContext to use the context within the location.

PiperOrigin-RevId: 254771979

5 years agoCleanup test following bad merge
Nicolas Vasilache [Mon, 24 Jun 2019 16:12:47 +0000 (09:12 -0700)]
Cleanup test following bad merge

PiperOrigin-RevId: 254770395

5 years agoUse linalg.view_slice in tiling and fusion
Nicolas Vasilache [Mon, 24 Jun 2019 16:00:06 +0000 (09:00 -0700)]
Use linalg.view_slice in tiling and fusion

This CL makes use of view_slice in tiling and fusion.
Using a higher level IR element greatly simplifies the IR produced during tiling and fusion.
Lowering to LLVM is updated to first translate view_slice into a sequence of dim, range and cmpi.
This level will also be useful when lowering to affine.

PiperOrigin-RevId: 254767814

5 years agoRemove leftover change from splitting mlir-opt change.
Jacques Pienaar [Mon, 24 Jun 2019 15:56:57 +0000 (08:56 -0700)]
Remove leftover change from splitting mlir-opt change.

PiperOrigin-RevId: 254767366

5 years agoSplit out mlir-opt main into separate file.
Jacques Pienaar [Mon, 24 Jun 2019 15:41:52 +0000 (08:41 -0700)]
Split out mlir-opt main into separate file.

Enable reusing the real mlir-opt main from unit tests and in case where
additional initialization needs to happen before main is invoked (e.g., when
using different command line flag libraries).

PiperOrigin-RevId: 254764575

5 years agoAdd higher-level linalg.view_slice operation.
Nicolas Vasilache [Mon, 24 Jun 2019 14:59:59 +0000 (07:59 -0700)]
Add higher-level linalg.view_slice operation.

This will be useful to simplify the IR emitted during transformations as well as lowering to affine.

PiperOrigin-RevId: 254757641

5 years agoAdd parsing/printing for new affine.load and affine.store operations.
Andy Davis [Mon, 24 Jun 2019 14:31:52 +0000 (07:31 -0700)]
Add parsing/printing for new affine.load and affine.store operations.
The new operations affine.load and affine.store will take composed affine maps by construction.
These operations will eventually replace load and store operations currently used in affine regions and operated on by affine transformation and analysis passes.

PiperOrigin-RevId: 254754048

5 years agoUpdate CSE to respect nested regions that are isolated from above. This cl also remov...
River Riddle [Mon, 24 Jun 2019 08:27:22 +0000 (01:27 -0700)]
Update CSE to respect nested regions that are isolated from above. This cl also removes the unused 'NthRegionIsIsolatedFromAbove' trait as it was replaced with a more general 'IsIsolatedFromAbove'.

PiperOrigin-RevId: 254709704

5 years agoChange string to std::string.
Jacques Pienaar [Sat, 22 Jun 2019 22:06:17 +0000 (15:06 -0700)]
Change string to std::string.

PiperOrigin-RevId: 254580672

5 years agoAllow converting Diagnostic to LogicalResult::Failure. This matches the behavior...
River Riddle [Sat, 22 Jun 2019 21:39:16 +0000 (14:39 -0700)]
Allow converting Diagnostic to LogicalResult::Failure. This matches the behavior of InFlightDiagnostic and enables notes to be converted to failure.

PiperOrigin-RevId: 254579098

5 years agoLinalg1LLVMConversion should depend on MLIRLLVMIR to ensure ops generated.
Jacques Pienaar [Sat, 22 Jun 2019 21:29:23 +0000 (14:29 -0700)]
Linalg1LLVMConversion should depend on MLIRLLVMIR to ensure ops generated.

PiperOrigin-RevId: 254578530

5 years agoAdd a new dialect hook 'materializeConstant' to create a constant operation that...
River Riddle [Sat, 22 Jun 2019 18:48:43 +0000 (11:48 -0700)]
Add a new dialect hook 'materializeConstant' to create a constant operation that materializes an attribute value with the given type. This effectively adds support for dialect specific constant values that have different invariants than std.constant. 'OperationFolder' is updated to use this new hook, or attempt to default to std.constant when legal.

PiperOrigin-RevId: 254570153

5 years agoNFC: Remove the 'context' parameter from OperationState.
River Riddle [Sat, 22 Jun 2019 18:08:52 +0000 (11:08 -0700)]
NFC: Remove the 'context' parameter from OperationState.

Now that Locations are Attributes they contain a direct reference to the MLIRContext, i.e. the context can be directly accessed from the given location instead of being explicitly passed in.

PiperOrigin-RevId: 254568329

5 years agoAdd missing build dep.
Jacques Pienaar [Sat, 22 Jun 2019 15:02:00 +0000 (08:02 -0700)]
Add missing build dep.

PiperOrigin-RevId: 254557652

5 years agoAdd int8 predicates to the tf lite ops
Feng Liu [Sat, 22 Jun 2019 04:43:49 +0000 (21:43 -0700)]
Add int8 predicates to the tf lite ops

PiperOrigin-RevId: 254519710

5 years agoDefine a ModuleOp that represents a Module as an Operation.
River Riddle [Sat, 22 Jun 2019 03:20:27 +0000 (20:20 -0700)]
Define a ModuleOp that represents a Module as an Operation.

The ModuleOp contains a single region that must contain a single block. This block must be terminated by a new pseudo operation 'module_terminator'. The syntax for this operations is as follows:

  `module` (`attributes` attr-dict)? region

Example:

  module {
    ...
  }

  module attributes { ... } {
    ...
  }

PiperOrigin-RevId: 254513752

5 years agoRemove dead function
Nicolas Vasilache [Sat, 22 Jun 2019 01:55:02 +0000 (18:55 -0700)]
Remove dead function

PiperOrigin-RevId: 254507641

5 years agoAdd a Linalg convolution op.
Nicolas Vasilache [Sat, 22 Jun 2019 01:31:52 +0000 (18:31 -0700)]
Add a Linalg convolution op.

This CL adds a conv op that corresponds to the TF description along with its lowering to loops (https://www.tensorflow.org/api_docs/python/tf/nn/convolution).

The dimension of the convolution is inferred from the rank of the views. The other logical
dimensions correspond to the TF description.

The computation of tiled views need to be updated to work for the input tensor. This is left for a future CL.

PiperOrigin-RevId: 254505644

5 years agoRefactor the location classes to be attributes instead of separate IR classes.
River Riddle [Sat, 22 Jun 2019 01:27:49 +0000 (18:27 -0700)]
Refactor the location classes to be attributes instead of separate IR classes.

This will allow for locations to be used in the same contexts as attributes. Given that attributes are nullable types, the 'Location' class now represents a non-nullable wrapper around a 'LocationAttr'. This preserves the desired semantics we have for non-optional locations.

PiperOrigin-RevId: 254505278

5 years agoSimplify PredecessorIterator by using mapped_iterator.
River Riddle [Sat, 22 Jun 2019 00:00:01 +0000 (17:00 -0700)]
Simplify PredecessorIterator by using mapped_iterator.

PiperOrigin-RevId: 254495164

5 years ago[spirv] Basic serializer and deserializer
Lei Zhang [Fri, 21 Jun 2019 21:51:58 +0000 (14:51 -0700)]
[spirv] Basic serializer and deserializer

This CL adds the basic SPIR-V serializer and deserializer for converting
SPIR-V module into the binary format and back. Right now only an empty
module with addressing model and memory model is supported; (de)serialize
other components will be added gradually with subsequent CLs.

The purpose of this library is to enable importing SPIR-V binary modules
to run transformations on them and exporting SPIR-V modules to be consumed
by execution environments. The focus is transformations, which inevitably
means changes to the binary module; so it is not designed to be a general
tool for investigating the SPIR-V binary module and does not guarantee
roundtrip equivalence (at least for now).

PiperOrigin-RevId: 254473019

5 years agoNFC: Drop the unnecessary dependence on TransformsUtils from Parser. This is a histor...
River Riddle [Fri, 21 Jun 2019 20:45:21 +0000 (13:45 -0700)]
NFC: Drop the unnecessary dependence on TransformsUtils from Parser. This is a historical dependency that is no longer needed.

PiperOrigin-RevId: 254460518

5 years agoDefine the 'reference' type for the remaining value-typed iterators. This allows...
River Riddle [Fri, 21 Jun 2019 20:43:38 +0000 (13:43 -0700)]
Define the 'reference' type for the remaining value-typed iterators. This allows for them to be used with llvm::enumerate and other various iterator utilities.

PiperOrigin-RevId: 254460201

5 years agoDefine the 'reference' type for the OperandType and ResultType iterators so that...
River Riddle [Fri, 21 Jun 2019 17:26:57 +0000 (10:26 -0700)]
Define the 'reference' type for the OperandType and ResultType iterators so that they can be used with llvm::enumerate.

PiperOrigin-RevId: 254422623

5 years agoClarify documentation for MLIR to indicate that the build instructions run the test...
Krzysztof Drewniak [Fri, 21 Jun 2019 17:23:18 +0000 (10:23 -0700)]
Clarify documentation for MLIR to indicate that the build instructions run the test suite.

PiperOrigin-RevId: 254421795

5 years agoAdd support for 1->N type mappings in the dialect conversion infrastructure. To suppo...
River Riddle [Fri, 21 Jun 2019 16:29:46 +0000 (09:29 -0700)]
Add support for 1->N type mappings in the dialect conversion infrastructure. To support these mappings a hook must be overridden on the type converter: 'materializeConversion' :to generate a cast operation from the new types to the old type. This operation is automatically erased if all uses are removed, otherwise it remains in the IR for the user to handle.

PiperOrigin-RevId: 254411383

5 years agoCache instances of several common attributes(e.g. BoolAttr, UnitAttr) and types(I1...
River Riddle [Fri, 21 Jun 2019 16:20:42 +0000 (09:20 -0700)]
Cache instances of several common attributes(e.g. BoolAttr, UnitAttr) and types(I1/I16/I32/etc.) when creating the MLIRContext. This allows for these symbols to be accessed without the need to perform any lookups/locking.

PiperOrigin-RevId: 254410080

5 years agoSupport for 0-D case in Linalg ops
Nicolas Vasilache [Fri, 21 Jun 2019 12:34:58 +0000 (05:34 -0700)]
Support for 0-D case in Linalg ops

This CL adds support for O-D ops in Linalg ops by:
1. making the CopyOp maps optional instead of default valued
2. allowing certain map operations to accept and return empty maps
3. making linalg::LowerToLoops aware of these changes
4. providing a proper 0-D impl for CopyOp and FillOp
5. adding the relevant tests

PiperOrigin-RevId: 254381908

5 years agoAdd an overload to 'PatternRewriter::inlineRegionBefore' that accepts a parent region...
River Riddle [Fri, 21 Jun 2019 10:26:39 +0000 (03:26 -0700)]
Add an overload to 'PatternRewriter::inlineRegionBefore' that accepts a parent region for the insertion position. This allows for inlining the given region into the end of another region.

PiperOrigin-RevId: 254367375

5 years agoAdd missing override on overridden virtual method (NFC)
Mehdi Amini [Fri, 21 Jun 2019 07:44:11 +0000 (00:44 -0700)]
Add missing override on overridden virtual method (NFC)

PiperOrigin-RevId: 254349019

5 years agoUniformize usage of OpBuilder& (NFC)
Nicolas Vasilache [Thu, 20 Jun 2019 22:10:35 +0000 (15:10 -0700)]
Uniformize usage of OpBuilder& (NFC)

Historically the pointer-based version of builders was used.
This CL uniformizes to OpBuilder &

PiperOrigin-RevId: 254280885

5 years agoFix a warning in enum value ecoding for SPIRV image types. Instead of
Mahesh Ravishankar [Thu, 20 Jun 2019 20:19:41 +0000 (13:19 -0700)]
Fix a warning in enum value ecoding for SPIRV image types. Instead of
using the enum class in the packed struct, use unsigned value for
encoding and convert it lazily

PiperOrigin-RevId: 254258341

5 years agoTensorFlow operands can be broadcasted with each other and with the result, relax...
Mehdi Amini [Thu, 20 Jun 2019 15:58:24 +0000 (08:58 -0700)]
TensorFlow operands can be broadcasted with each other and with the result, relax the verifier.

PiperOrigin-RevId: 254206814

5 years agoAdd definition for OperandElementTypeIterator and ResultElementTypeIterator
Lei Zhang [Thu, 20 Jun 2019 12:59:19 +0000 (05:59 -0700)]
Add definition for OperandElementTypeIterator and ResultElementTypeIterator

These are useful utility iterators helping use to get the element types of
operands/results of shaped types.

Also defined ranges for these iterators.

PiperOrigin-RevId: 254180888

5 years agoRename ConversionTarget::isLegal to isDynamicallyLegal to better represent what the...
River Riddle [Thu, 20 Jun 2019 06:39:06 +0000 (23:39 -0700)]
Rename ConversionTarget::isLegal to isDynamicallyLegal to better represent what the function is actually checking.

PiperOrigin-RevId: 254141073

5 years agoAdd SPIRV Image Type according to the spec described here :
Mahesh Ravishankar [Wed, 19 Jun 2019 23:09:57 +0000 (16:09 -0700)]
Add SPIRV Image Type according to the spec described here :
https://www.khronos.org/registry/spir-v/specs/1.0/SPIRV.html#OpTypeImage.

Add new enums to describe Image dimensionality, Image Depth, Arrayed
information, Sampling, Sampler User information, and Image format.
Doesn's support the Optional Access qualifier at this stage

Fix Enum generator for tblgen to add "_" at the beginning if the enum
starts with a number.

PiperOrigin-RevId: 254091423

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