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

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

PiperOrigin-RevId: 275253532

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

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

PiperOrigin-RevId: 275186568

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

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

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

More advanced cases will require block argument and Phi support.

PiperOrigin-RevId: 275151132

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

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

PiperOrigin-RevId: 275150649

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

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

PiperOrigin-RevId: 275150438

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

PiperOrigin-RevId: 275147795

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

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

PiperOrigin-RevId: 275144804

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

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

PiperOrigin-RevId: 275089914

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

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

Closes tensorflow/mlir#191

PiperOrigin-RevId: 275085151

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

PiperOrigin-RevId: 275084969

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

This was missed when the type was renamed.

PiperOrigin-RevId: 275082588

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

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

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

PiperOrigin-RevId: 275081486

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

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

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

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

PiperOrigin-RevId: 275065447

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

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

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

PiperOrigin-RevId: 275059656

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

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

PiperOrigin-RevId: 275052756

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

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

PiperOrigin-RevId: 275038533

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

PiperOrigin-RevId: 275025323

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

PiperOrigin-RevId: 275004258

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

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

PiperOrigin-RevId: 274974010

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

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

PiperOrigin-RevId: 274973808

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

PiperOrigin-RevId: 274935374

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

PiperOrigin-RevId: 274905193

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

PiperOrigin-RevId: 274902838

4 years agoNFC: Split out ToyOpsIncGen into a separate CMakeLists.txt.
River Riddle [Tue, 15 Oct 2019 22:09:45 +0000 (15:09 -0700)]
NFC: Split out ToyOpsIncGen into a separate CMakeLists.txt.

This fixes an issue with make where it fails to properly handle the dependency ordering.

PiperOrigin-RevId: 274897702

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

PiperOrigin-RevId: 274894550

4 years ago[spirv] Add support for SpecId decoration on spv.specConstant
Lei Zhang [Tue, 15 Oct 2019 21:53:01 +0000 (14:53 -0700)]
[spirv] Add support for SpecId decoration on spv.specConstant

The SpecId decoration is the handle for providing external specialization.
Similar to descriptor set and binding on global variables, we directly
bake it into assembly parsing and printing.

PiperOrigin-RevId: 274893879

4 years agoFix minor typos
MLIR Team [Tue, 15 Oct 2019 21:48:21 +0000 (14:48 -0700)]
Fix minor typos

PiperOrigin-RevId: 274892763

4 years agoFix typos in InferTypeOpInterface.
Jacques Pienaar [Tue, 15 Oct 2019 19:50:51 +0000 (12:50 -0700)]
Fix typos in InferTypeOpInterface.

PiperOrigin-RevId: 274866986

4 years agoUpdate Chapter 3 to demonstrate pattern match and rewrite optimizations
Sana Damani [Tue, 15 Oct 2019 18:40:12 +0000 (11:40 -0700)]
Update Chapter 3 to demonstrate pattern match and rewrite optimizations

This is using Table-driven Declarative Rewrite Rules (DRR), the previous
version of the tutorial only showed the C++ patterns.

Closes tensorflow/mlir#187

PiperOrigin-RevId: 274852321

4 years agoFix typos in LangRef and OpDefinitions
Jacques Pienaar [Tue, 15 Oct 2019 18:22:53 +0000 (11:22 -0700)]
Fix typos in LangRef and OpDefinitions

PiperOrigin-RevId: 274848361

4 years agoConsistent use of int in mlir_runner_utils.cpp
Nicolas Vasilache [Tue, 15 Oct 2019 18:03:54 +0000 (11:03 -0700)]
Consistent use of int in mlir_runner_utils.cpp

This should fix the OSS build by only using int in template types.

PiperOrigin-RevId: 274843584

4 years agoAdd conversion for splat of vectors of 2+D
Nicolas Vasilache [Tue, 15 Oct 2019 13:52:24 +0000 (06:52 -0700)]
Add conversion for splat of vectors of 2+D

This CL adds a missing lowering for splat of multi-dimensional vectors.
Additional support is also added to the runtime utils library to allow printing memrefs with such vectors.

PiperOrigin-RevId: 274794723

4 years agoExpose mlir::parseType to bindings
Alex Zinenko [Tue, 15 Oct 2019 13:50:56 +0000 (06:50 -0700)]
Expose mlir::parseType to bindings

Python bindings currently currently provide a makeScalarType function that
constructs one of the predefined types. It was implemented in the bindings
directly to circumvent the absence of standalone type parsing function. Now
that mlir::parseType has been made available, rely on the core parsing
procedure to construct types from strings in the bindings.

This changes includes a library reshuffling that splits out "CoreAPIs"
implementing the binding helper APIs into a separate library and makes that
dependent on the Parser library.

PiperOrigin-RevId: 274794516

4 years agoAsmPrinter: avoid unused-variable warning
Alex Zinenko [Tue, 15 Oct 2019 13:50:34 +0000 (06:50 -0700)]
AsmPrinter: avoid unused-variable warning

The value defined in a loop was not being used and the function producing it
re-evaluated instead. Use the value to avoid both the warning and the
re-evaluation.

PiperOrigin-RevId: 274794459

4 years agoMerge Ch3 of the Toy tutorial into chapter 2.
River Riddle [Tue, 15 Oct 2019 04:12:50 +0000 (21:12 -0700)]
Merge Ch3 of the Toy tutorial into chapter 2.

This effectively rewrites Ch.2 to introduce dialects, operations, and registration instead of deferring to Ch.3. This allows for introducing the best practices up front(using ODS, registering operations, etc.), and limits the opaque API to the chapter document instead of the code.

PiperOrigin-RevId: 274724289

4 years agoNFC: Replace usages of Value::getKind with explicit isa/casts.
River Riddle [Mon, 14 Oct 2019 23:21:17 +0000 (16:21 -0700)]
NFC: Replace usages of Value::getKind with explicit isa/casts.

It is more idiomatic to use the llvm::cast infrastructure for checking the type of a value.

PiperOrigin-RevId: 274684945

4 years agoAllowing replacing non-root operations in DialectConversion.
River Riddle [Mon, 14 Oct 2019 16:50:54 +0000 (09:50 -0700)]
Allowing replacing non-root operations in DialectConversion.

When dealing with regions, or other patterns that need to generate temporary operations, it is useful to be able to replace other operations than the root op being matched. Before this PR, these operations would still be considered for legalization meaning that the conversion would either fail, erroneously need to mark these ops as legal, or add unnecessary patterns.

PiperOrigin-RevId: 274598513

4 years agoUse single quotes to wrap '@HOST_LDFLAGS@' in LIT config file
Mehdi Amini [Mon, 14 Oct 2019 15:18:23 +0000 (08:18 -0700)]
Use single quotes to wrap '@HOST_LDFLAGS@' in LIT config file

ldflags can contain double-quoted paths, so must use single quotes here.

PiperOrigin-RevId: 274581983

4 years agoFix linalg.subview behavior in (partially) static cases.
Nicolas Vasilache [Mon, 14 Oct 2019 14:58:54 +0000 (07:58 -0700)]
Fix linalg.subview behavior in (partially) static cases.

When the implementation of the strided memref [RFC](https://groups.google.com/a/tensorflow.org/forum/#!msg/mlir/MaL8m2nXuio/1scRqZa6AQAJ) landed, linalg started using this type instead of the now retired !linalg.view.

As static and partially static cases appear, the stride information needs to be maintained properly. In particular, the result type of the subview op was generally incorrect.

This CL fixes the issue by computing a return type that:
1. always has dynamic sizes, which is generally the only correct way to construct a subview in the absence of data padding and/or code versioning.
2. has the same strides as the base strided memref.

Point 1. above can be further refined but will needs further analysis and canonicalization to optimize the particular case where:
1. The base memref has static size along a given dimension.
2. The subview size can be statically derived (e.g. after canonicalization).
3. *And* the subview size is an even divisor of the base memref.

This 3rd constraint is well-known in the case of tiled layouts that don't assume implicit padding: the boundary tile may be only partial and has size given by `problem_size % tile_size`.

Tests are updated as appropriate.

PiperOrigin-RevId: 274578624

4 years agoAdd lowering of VectorOps dialect to LLVM to the Linalg LLVM lowering pass
Nicolas Vasilache [Mon, 14 Oct 2019 14:48:29 +0000 (07:48 -0700)]
Add lowering of VectorOps dialect to LLVM to the Linalg LLVM lowering pass

This fixes an omission that prevents Linalg to lower generic ops regions operating on ops in the VectorOps dialect.
To achieve this we simply need to `populateVectorToLLVMConversionPatterns` in the conversion.

Relevant tests are added.

PiperOrigin-RevId: 274577325

4 years agoAdd LLVM IR dialect hooks for FP128 and X86_FP80 types
Eric Schweitz [Sat, 12 Oct 2019 01:35:02 +0000 (18:35 -0700)]
Add LLVM IR dialect hooks for FP128 and X86_FP80 types

Closes tensorflow/mlir#184

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/184 from schweitzpgi:more-float-types ca27d00510a86ffc9c79c65fb3a0193b5ea097a0
PiperOrigin-RevId: 274288813

4 years agoEmit LLVM IR equivalent of sizeof when lowering alloc operations
Alex Zinenko [Fri, 11 Oct 2019 13:22:40 +0000 (06:22 -0700)]
Emit LLVM IR equivalent of sizeof when lowering alloc operations

Originally, the lowering of `alloc` operations has been computing the number of
bytes to allocate when lowering based on the properties of MLIR type. This does
not take into account type legalization that happens when compiling LLVM IR
down to target assembly. This legalization can widen the type, potentially
leading to out-of-bounds accesses to `alloc`ed data due to mismatches between
address computation that takes the widening into account and allocation that
does not. Use the LLVM IR's equivalent of `sizeof` to compute the number of
bytes to be allocated:
  %0 = getelementptr %type* null, %indexType 0
  %1 = ptrtoint %type* %0 to %indexType
adapted from
http://nondot.org/sabre/LLVMNotes/SizeOf-OffsetOf-VariableSizedStructs.txt

PiperOrigin-RevId: 274159900

4 years agoLLVM Dialect: introduce llvm.mlir.null operation
Alex Zinenko [Fri, 11 Oct 2019 13:13:25 +0000 (06:13 -0700)]
LLVM Dialect: introduce llvm.mlir.null operation

Similarly to `llvm.mlir.undef`, this auxiliary operation creates an SSA value
that corresponds to `null` in LLVM IR.  This operation is necessary to model
sizeof(<...>) behavior when allocating memory.

PiperOrigin-RevId: 274158760

4 years agoDrop obsolete code from std to llvm memref lowering
Uday Bondhugula [Fri, 11 Oct 2019 13:08:24 +0000 (06:08 -0700)]
Drop obsolete code from std to llvm memref lowering

- dropping what looks like outdated code post some of the previous
  updates

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

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/179 from bondhugula:llfix 2a72ea441fe1b3924802273ffbe9870afeb90f91
PiperOrigin-RevId: 274158273

4 years agoRename LLVM::exp and LLVM::fmuladd to LLVM::ExpOP and LLVM::FMulAddOp.
Alexander Belyaev [Fri, 11 Oct 2019 12:38:10 +0000 (05:38 -0700)]
Rename LLVM::exp and LLVM::fmuladd to LLVM::ExpOP and LLVM::FMulAddOp.

PiperOrigin-RevId: 274154655

4 years agoAdd unary ops and ExpOp to Standard Dialect.
Alexander Belyaev [Fri, 11 Oct 2019 12:13:18 +0000 (05:13 -0700)]
Add unary ops and ExpOp to Standard Dialect.

PiperOrigin-RevId: 274152154

4 years agoLLVM conversion: harden a test to check for LLVM funcs rather than any funcs
Alex Zinenko [Fri, 11 Oct 2019 08:35:58 +0000 (01:35 -0700)]
LLVM conversion: harden a test to check for LLVM funcs rather than any funcs

This test was not updated in the original commit that switched to using LLVM
functions since it wasn't broken by that change. FileCheck was able to match
the `func` part of `llvm.func` to the expected pattern and continue as usual.
Make sure the `llvm.` dialect prefix is included in the expected output.

PiperOrigin-RevId: 274127281

4 years agoNFC: Print the generic op form after pass failure.
River Riddle [Fri, 11 Oct 2019 04:57:24 +0000 (21:57 -0700)]
NFC: Print the generic op form after pass failure.

On failure, the IR is likely to be in an invalid state, meaning the custom printer for some operations may now crash. Using the generic op form prevents this from happening.

PiperOrigin-RevId: 274104146

4 years agoAdd support for generating reproducers on pass crash and failure.
River Riddle [Fri, 11 Oct 2019 02:19:11 +0000 (19:19 -0700)]
Add support for generating reproducers on pass crash and failure.

This cl adds support for generating a .mlir file containing a reproducer for crashes and failures that happen during pass execution. The reproducer contains a comment detailing the configuration of the pass manager(e.g. the textual description of the pass pipeline that the pass manager was executing), along with the original input module.

Example Output:

// configuration: -pass-pipeline='func(cse, canonicalize), inline'
// note: verifyPasses=false

module {
  ...
}

PiperOrigin-RevId: 274088134

4 years agoNFC: Initialize pass manager option fields inline instead of the class constructor.
River Riddle [Fri, 11 Oct 2019 02:13:44 +0000 (19:13 -0700)]
NFC: Initialize pass manager option fields inline instead of the class constructor.
PiperOrigin-RevId: 274087577

4 years agoStandard-to-LLVM conversion: check that operands have LLVM types
Alex Zinenko [Thu, 10 Oct 2019 23:25:11 +0000 (16:25 -0700)]
Standard-to-LLVM conversion: check that operands have LLVM types

In Standard to LLVM dialect conversion, the binary op conversion pattern
implicitly assumed some operands were of LLVM IR dialect type. This is not
necessarily true, for example if the Ops that produce those operands did not
match the existing convresion patterns. Check if all operands are of LLVM IR
dialect type and if not, fail to patch the binary op pattern.

Closes tensorflow/mlir#168

PiperOrigin-RevId: 274063207

4 years agoTranslation to LLVM: check the validity of module-level Ops
Alex Zinenko [Thu, 10 Oct 2019 23:01:41 +0000 (16:01 -0700)]
Translation to LLVM: check the validity of module-level Ops

Translation to LLVM expects the entry module to have only specific types of ops
that correspond to LLVM IR entities allowed in a module. Currently those are
restricted to functions and globals. Introduce an additional check at the
module level. Inside individual functions, the check for supported Ops is
already performed, but it accepts all LLVM dialect Ops and wouldn't be
immediately applicable at the module level.

PiperOrigin-RevId: 274058651

4 years agoAdd lowering of constant ops to SPIR-V.
Mahesh Ravishankar [Thu, 10 Oct 2019 22:51:35 +0000 (15:51 -0700)]
Add lowering of constant ops to SPIR-V.

The lowering is specified as a pattern and is done only if the result
is a SPIR-V scalar type or vector type.
Handling ConstantOp with index return type needs special handling
since SPIR-V dialect does not have index types. Based on the bitwidth
of the attribute value, either i32 or i64 is chosen.
Other constant lowerings are left as a TODO.

PiperOrigin-RevId: 274056805

4 years agoAdd trait for specified shapes matching
Geoffrey Martin-Noble [Thu, 10 Oct 2019 22:01:34 +0000 (15:01 -0700)]
Add trait for specified shapes matching

PiperOrigin-RevId: 274046434

4 years agoAdd support for canonicalizing callable regions during inlining.
River Riddle [Thu, 10 Oct 2019 19:12:39 +0000 (12:12 -0700)]
Add support for canonicalizing callable regions during inlining.

This will allow for inlining newly devirtualized calls, as well as give a more accurate cost model(when we have one). Currently canonicalization will only run for nodes that have no child edges, as the child nodes may be erased during canonicalization. We can support this in the future, but it requires more intricate deletion tracking.

PiperOrigin-RevId: 274011386

4 years agoRemove the need to convert operations in regions of operations that have been replaced.
River Riddle [Thu, 10 Oct 2019 19:01:45 +0000 (12:01 -0700)]
Remove the need to convert operations in regions of operations that have been replaced.

When an operation with regions gets replaced, we currently require that all of the remaining nested operations are still converted even though they are going to be replaced when the rewrite is finished. This cl adds a tracking for a minimal set of operations that are known to be "dead". This allows for ignoring the legalization of operations that are won't survive after conversion.

PiperOrigin-RevId: 274009003

4 years agoPython bindings: export index_cast
Alex Zinenko [Thu, 10 Oct 2019 17:25:46 +0000 (10:25 -0700)]
Python bindings: export index_cast

We are now properly enforcing the absence of index elements in memrefs and
tensors. Instead, users are expected to store sized integers and cast them to
index type if necessary. Expose the respective operation to Python bindings.

PiperOrigin-RevId: 273985856

4 years agoMark GPU dialect as illegal when lowering to NVVM.
Christian Sigg [Thu, 10 Oct 2019 13:31:39 +0000 (06:31 -0700)]
Mark GPU dialect as illegal when lowering to NVVM.

PiperOrigin-RevId: 273948293

4 years agoNFC: Cleanup of type checking tests
Geoffrey Martin-Noble [Thu, 10 Oct 2019 09:31:21 +0000 (02:31 -0700)]
NFC: Cleanup of type checking tests

1. Rename test ops referencing operand to index from 0 consistent with how we index elsewhere.
2. Don't limit type checking that functions for all shaped types to only tensors.
3. Don't limit (element) type checking functions and add tests for scalars.
4. Remove SSA values that don't do anything.

PiperOrigin-RevId: 273917608

4 years agoUse llvm.func to define functions with wrapped LLVM IR function type
Alex Zinenko [Thu, 10 Oct 2019 08:33:33 +0000 (01:33 -0700)]
Use llvm.func to define functions with wrapped LLVM IR function type

This function-like operation allows one to define functions that have wrapped
LLVM IR function type, in particular variadic functions. The operation was
added in parallel to the existing lowering flow, this commit only switches the
flow to use it.

Using a custom function type makes the LLVM IR dialect type system more
consistent and avoids complex conversion rules for functions that previously
had to use the built-in function type instead of a wrapped LLVM IR dialect type
and perform conversions during the analysis.

PiperOrigin-RevId: 273910855

4 years agoAdd test for fix to tablegen for custom folders for ops that return a single
Parker Schuh [Thu, 10 Oct 2019 03:42:32 +0000 (20:42 -0700)]
Add test for fix to tablegen for custom folders for ops that return a single
variadic result.

Add missing test for single line fix to `void OpEmitter::genFolderDecls()`
entitled "Fold away reduction over 0 dimensions."

PiperOrigin-RevId: 273880337

4 years agoFix typo in QuantizedType method names
Kazuaki Ishizaki [Thu, 10 Oct 2019 03:32:12 +0000 (20:32 -0700)]
Fix typo in QuantizedType method names

Closes tensorflow/mlir#172

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/172 from kiszk:quantops e27b57eac8f4c6ef7ee6a6f7b497d3e2f56f6798
PiperOrigin-RevId: 273879164

4 years agoPre-allocate space for results from a regex match that uses 3 match strings.
MLIR Team [Thu, 10 Oct 2019 02:57:02 +0000 (19:57 -0700)]
Pre-allocate space for results from a regex match that uses 3 match strings.

That space is 4 StringRefs, not 3, because element 0 of the match always
contains the entire source string.

PiperOrigin-RevId: 273875606

4 years agominor spelling tweaks
Kazuaki Ishizaki [Wed, 9 Oct 2019 22:06:54 +0000 (15:06 -0700)]
minor spelling tweaks

--
f93661f2c25aab6cc5bf439606b0a1312998a575 by Kazuaki Ishizaki <ishizaki@jp.ibm.com>:

address @River707's comment

Closes tensorflow/mlir#176

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/176 from kiszk:spelling_tweaks_include_tools f93661f2c25aab6cc5bf439606b0a1312998a575
PiperOrigin-RevId: 273830689

4 years agoAdd ::printAsTextualPipeline to Pass and OpPassManager.
MLIR Team [Wed, 9 Oct 2019 20:48:38 +0000 (13:48 -0700)]
Add ::printAsTextualPipeline to Pass and OpPassManager.

Allow printing out pipelines in a format that is as close as possible to the
textual pass pipeline format. Individual passes can override the print function
in order to format any options that may have been used to construct that pass.

PiperOrigin-RevId: 273813627

4 years agoGuard rewriter insertion point during signature conversion.
Christian Sigg [Wed, 9 Oct 2019 18:32:54 +0000 (11:32 -0700)]
Guard rewriter insertion point during signature conversion.

Avoid unexpected side effect in rewriter insertion point.

PiperOrigin-RevId: 273785794

4 years agoMake SPIR-V lowering infrastructure follow Vulkan SPIR-V validation.
Mahesh Ravishankar [Wed, 9 Oct 2019 18:25:25 +0000 (11:25 -0700)]
Make SPIR-V lowering infrastructure follow Vulkan SPIR-V validation.

The lowering infrastructure needs to be enhanced to lower into a
spv.Module that is consistent with the SPIR-V spec. The following
changes are needed
1) The Vulkan/SPIR-V validation rules dictates entry functions to have
signature of void(void). This requires changes to the function
signature conversion infrastructure within the dialect conversion
framework. When an argument is dropped from the original function
signature, a function can be specified that when invoked will return
the value to use as a replacement for the argument from the original
function.
2) Some changes to the type converter to make the converted type
consistent with the Vulkan/SPIR-V validation rules,
   a) Add support for converting dynamically shaped tensors to
   spv.rtarray type.
   b) Make the global variable of type !spv.ptr<!spv.struct<...>>
3) Generate the entry point operation for the kernel functions and
automatically compute all the interface variables needed

PiperOrigin-RevId: 273784229

4 years agoFix Windows linkage error
Nicolas Vasilache [Wed, 9 Oct 2019 17:36:59 +0000 (10:36 -0700)]
Fix Windows linkage error

This CL fixes bad macro names usage in mlir_runner_utils.h.
The macro mlir_runner_utils_EXPORTS now matches what is defined in CMakeLists.txt.

PiperOrigin-RevId: 273773931

4 years agoAdd support for some multi-store cases in affine fusion
Diego Caballero [Wed, 9 Oct 2019 17:36:54 +0000 (10:36 -0700)]
Add support for some multi-store cases in affine fusion

This PR is a stepping stone towards supporting generic multi-store
source loop nests in affine loop fusion. It extends the algorithm to
support fusion of multi-store loop nests that:
 1. have only one store that writes to a function-local live out, and
 2. the remaining stores are involved in loop nest self dependences
    or no dependences within the function.

Closes tensorflow/mlir#162

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/162 from dcaballe:dcaballe/multi-output-fusion 7fb7dec6fe8b45f5ce176f018bfe37b256420c45
PiperOrigin-RevId: 273773907

4 years agoUpdate the usage and comments in define_inst.sh.
MLIR Team [Wed, 9 Oct 2019 12:01:07 +0000 (05:01 -0700)]
Update the usage and comments in define_inst.sh.

PiperOrigin-RevId: 273723108

4 years agoAdd exp operation to LLVMOPs.td.
Alexander Belyaev [Wed, 9 Oct 2019 11:19:06 +0000 (04:19 -0700)]
Add exp operation to LLVMOPs.td.

PiperOrigin-RevId: 273718958

4 years agoChange to doxygen comments. NFC.
Christian Sigg [Wed, 9 Oct 2019 09:46:04 +0000 (02:46 -0700)]
Change to doxygen comments. NFC.

PiperOrigin-RevId: 273707610

4 years agoAssert that region is not cloned into itself.
Christian Sigg [Wed, 9 Oct 2019 09:43:18 +0000 (02:43 -0700)]
Assert that region is not cloned into itself.

PiperOrigin-RevId: 273707291

4 years agoNFC: Fully qualify use of std::string.
River Riddle [Wed, 9 Oct 2019 04:15:49 +0000 (21:15 -0700)]
NFC: Fully qualify use of std::string.
PiperOrigin-RevId: 273668957

4 years agoAllow dynamic but ranked types in ops with SameOperandsAndResultShape and SameOperand...
Smit Hinsu [Wed, 9 Oct 2019 02:36:37 +0000 (19:36 -0700)]
Allow dynamic but ranked types in ops with SameOperandsAndResultShape and SameOperandsAndResultType traits

Currently SameOperandsAndResultShape trait allows operands to have tensor<*xf32> and tensor<2xf32> but doesn't allow tensor<?xf32> and tensor<10xf32>.

Also, use the updated shape compatibility helper function in TensorCastOp::areCastCompatible method.

PiperOrigin-RevId: 273658336

4 years agoUpdate the symbol utility methods to handle the case of unknown operations.
River Riddle [Wed, 9 Oct 2019 01:38:05 +0000 (18:38 -0700)]
Update the symbol utility methods to handle the case of unknown operations.

This enhances the symbol table utility methods to handle the case where an unknown operation may define a symbol table. When walking symbols, we now collect all symbol uses before allowing the user to iterate. This prevents the user from assuming that all symbols are actually known before performing a transformation.

PiperOrigin-RevId: 273651963

4 years agoAdd Instance Specific Pass Options.
MLIR Team [Wed, 9 Oct 2019 01:23:13 +0000 (18:23 -0700)]
Add Instance Specific Pass Options.

This allows individual passes to define options structs and for these options to be parsed per instance of the pass while building the pass pipeline from the command line provided textual specification.

The user can specify these per-instance pipeline options like so:
```
struct MyPassOptions : public PassOptions<MyPassOptions> {
  Option<int> exampleOption{*this, "flag-name", llvm::cl::desc("...")};
  List<int> exampleListOption{*this, "list-flag-name", llvm::cl::desc("...")};
};

static PassRegistration<MyPass, MyPassOptions> pass("my-pass", "description");
```

PiperOrigin-RevId: 273650140

4 years agoAdd support for parsing/printing non bare-identifier SymbolRefs.
River Riddle [Wed, 9 Oct 2019 00:44:39 +0000 (17:44 -0700)]
Add support for parsing/printing non bare-identifier SymbolRefs.

The restriction that symbols can only have identifier names is arbitrary, and artificially limits the names that a symbol may have. This change adds support for parsing and printing symbols that don't fit in the 'bare-identifier' grammar by printing the reference in quotes, e.g. @"0_my_reference" can now be used as a symbol name.

PiperOrigin-RevId: 273644768

4 years ago[ROCm] Fix the return type for the device function calls from i32 to i64.
Deven Desai [Wed, 9 Oct 2019 00:19:03 +0000 (17:19 -0700)]
[ROCm] Fix the return type for the device function calls from i32 to i64.

This is matching what the runtime library is expecting.

Closes tensorflow/mlir#171

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/171 from deven-amd:deven-rocdl-device-func-i64 80762629a8c34e844ebdc542b34dd783990db9db
PiperOrigin-RevId: 273640767

4 years ago[spirv] Add a pass to decorate the composite types with layout info.
Denis Khalikov [Tue, 8 Oct 2019 23:42:38 +0000 (16:42 -0700)]
[spirv] Add a pass to decorate the composite types with layout info.

Add a pass to decorate the composite types used by
composite objects in the StorageBuffer, PhysicalStorageBuffer,
Uniform, and PushConstant storage classes with layout information.

Closes tensorflow/mlir#156

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/156 from denis0x0D:sandbox/layout_info_decoration 7c50840fd38ca169a2da7ce9886b52b50c868b84
PiperOrigin-RevId: 273634140

4 years agoAdd a PatternRewriter hook for cloning a region into another.
River Riddle [Tue, 8 Oct 2019 22:44:34 +0000 (15:44 -0700)]
Add a PatternRewriter hook for cloning a region into another.

This is similar to the `inlineRegionBefore` hook, except the original blocks are unchanged. The region to be cloned *must* not have been modified during the conversion process at the point of cloning, i.e. it must belong an operation that has yet to be converted, or the operation that is currently being converted.

PiperOrigin-RevId: 273622533

4 years agounroll and jam: fix order of jammed bodies
Uday Bondhugula [Tue, 8 Oct 2019 22:01:35 +0000 (15:01 -0700)]
unroll and jam: fix order of jammed bodies

- bodies would earlier appear in the order (i, i+3, i+2, i+1) instead of
  (i, i+1, i+2, i+3) for example for factor 4.

- clean up hardcoded test cases

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

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/170 from bondhugula:ujam b66b405b2b1894a03b376952e32a9d0292042665
PiperOrigin-RevId: 273613131

4 years agoAdd support for walking the uses of a symbol.
River Riddle [Tue, 8 Oct 2019 17:21:26 +0000 (10:21 -0700)]
Add support for walking the uses of a symbol.

MLIR uses symbol references to model references to many global entities, such as functions/variables/etc. Before this change, there is no way to actually reason about the uses of such entities. This change provides a walker for symbol references(via SymbolTable::walkSymbolUses), as well as 'use_empty' support(via SymbolTable::symbol_use_empty). It also resolves some deficiencies in the LangRef definition of SymbolRefAttr, namely the restrictions on where a SymbolRefAttr can be stored, ArrayAttr and DictionaryAttr, and the relationship with operations containing the SymbolTable trait.

PiperOrigin-RevId: 273549331

4 years agoNFC: Remove unused default cl::opt value.
River Riddle [Tue, 8 Oct 2019 17:03:54 +0000 (10:03 -0700)]
NFC: Remove unused default cl::opt value.

The default value is never used as the value of the elide option is only used if it has an occurrence.

PiperOrigin-RevId: 273545143

4 years agoLinalg to LLVM lowering: decrease the reliance on symbol lookup in a module
Alex Zinenko [Tue, 8 Oct 2019 13:54:53 +0000 (06:54 -0700)]
Linalg to LLVM lowering: decrease the reliance on symbol lookup in a module

During the conversion, both the original and the converted function may coexist
in the module and have the same symbol name. There is no guarantee which of the
two will be found by the symbol lookup. Avoid returning the result of the
library function lookup when lowering Linalg to Standard or LLVM. Use the
symbol reference instead. After the conversion completes, only one symbol will
remain and the Ops using SymbolRefAttrs will be referring to the correct one.

PiperOrigin-RevId: 273510079

4 years agoGPUToCUDA: attach CUBIN to the nested module rather than to the function
Alex Zinenko [Tue, 8 Oct 2019 12:11:00 +0000 (05:11 -0700)]
GPUToCUDA: attach CUBIN to the nested module rather than to the function

Originally, we were attaching attributes containing CUBIN blobs to the kernel
function called by `gpu.launch_func`. This kernel is now contained in a nested
module that is used as a compilation unit. Attach compiled CUBIN blobs to the
module rather than to the function since we were compiling the module. This
also avoids duplication of the attribute on multiple kernels within the same
module.

PiperOrigin-RevId: 273497303

4 years agoGPUToCUDA: emit addressof directly instead of wrapping it into a getter function
Alex Zinenko [Tue, 8 Oct 2019 12:03:09 +0000 (05:03 -0700)]
GPUToCUDA: emit addressof directly instead of wrapping it into a getter function

Originally, the CUBIN getter function was introduced as a mechanism to
circumvent the absence of globals in the LLVM dialect. It would allocate memory
and populate it with the CUBIN data. LLVM dialect now supports globals and they
are already used to store CUBIN data, making the getter function a trivial
address computation of a global. Emit the address computation directly at the
place of `gpu.launch_func` instead of putting it in a function and calling it.
This simplifies the conversion flow and prepares it for using the
DialectConversion infrastructure.

PiperOrigin-RevId: 273496221

4 years agoFuse GenerateCubinAccessors pass into LaunchFunctToCuda
Alex Zinenko [Tue, 8 Oct 2019 11:35:04 +0000 (04:35 -0700)]
Fuse GenerateCubinAccessors pass into LaunchFunctToCuda

Now that the accessor function is a trivial getter of the global variable, it
makes less sense to have the getter generation as a separate pass. Move the
getter generation into the lowering of `gpu.launch_func` to CUDA calls. This
change is mostly code motion, but the process can be simplified further by
generating the addressof inplace instead of using a call. This is will be done
in a follow-up.

PiperOrigin-RevId: 273492517

4 years agoUse named modules for gpu.launch_func
Alex Zinenko [Tue, 8 Oct 2019 11:29:58 +0000 (04:29 -0700)]
Use named modules for gpu.launch_func

The kernel function called by gpu.launch_func is now placed into an isolated
nested module during the outlining stage to simplify separate compilation.
Until recently, modules did not have names and could not be referenced. This
limitation was circumvented by introducing a stub kernel at the same name at
the same nesting level as the module containing the actual kernel. This
relation is only effective in one direction: from actual kernel function to its
launch_func "caller".

Leverage the recently introduced symbol name attributes on modules to refer to
a specific nested module from `gpu.launch_func`. This removes the implicit
connection between the identically named stub and kernel functions. It also
enables support for `gpu.launch_func`s to call different kernels located in the
same module.

PiperOrigin-RevId: 273491891

4 years agoUpdate upgrade some uses of mlir::interleave API to take container argument directly.
Jing Pu [Tue, 8 Oct 2019 04:52:36 +0000 (21:52 -0700)]
Update upgrade some uses of mlir::interleave API to take container argument directly.

PiperOrigin-RevId: 273446814

4 years agoAdd a flag to the AsmPrinter for eliding large ElementsAttrs.
River Riddle [Tue, 8 Oct 2019 00:18:54 +0000 (17:18 -0700)]
Add a flag to the AsmPrinter for eliding large ElementsAttrs.

Some modules may have extremely large ElementsAttrs, which makes debugging involving IR dumping extremely slow and painful. This change adds a flag that will elide ElementsAttrs with a "large"(as defined by the user) number of elements by printing "..." instead of the element data.

PiperOrigin-RevId: 273413100

4 years agoPrint result types when dumping graphviz.
Jing Pu [Mon, 7 Oct 2019 23:45:26 +0000 (16:45 -0700)]
Print result types when dumping graphviz.

PiperOrigin-RevId: 273406833

4 years agoExpose `fuseProducerOf` in Linalg/Utils/Utils.h.
MLIR Team [Mon, 7 Oct 2019 22:00:35 +0000 (15:00 -0700)]
Expose `fuseProducerOf` in Linalg/Utils/Utils.h.

PiperOrigin-RevId: 273384063

4 years agoDo not add spirv::BitcastOp for cast from signed to unsigned type.
Mahesh Ravishankar [Mon, 7 Oct 2019 21:51:31 +0000 (14:51 -0700)]
Do not add spirv::BitcastOp for cast from signed to unsigned type.

Since MLIR integer types don't make a distinction between signed vs
unsigned integers, during deserialization of SPIR-V binaries, the
OpBitcast might result in a cast from/to the same type. Do not add a
spv.Bitcast operation to the spv.module in these cases.

PiperOrigin-RevId: 273381887

4 years ago[spirv] Disable a crashing spv.loop test
Lei Zhang [Mon, 7 Oct 2019 21:40:18 +0000 (14:40 -0700)]
[spirv] Disable a crashing spv.loop test

PiperOrigin-RevId: 273379318

4 years agoAdd a new class, OpPrintingFlags, to enable programmatic control of Operation::print...
River Riddle [Mon, 7 Oct 2019 20:54:16 +0000 (13:54 -0700)]
Add a new class, OpPrintingFlags, to enable programmatic control of Operation::print behavior.

This allows for controlling the behavior of the AsmPrinter programmatically, instead of relying exclusively on cl::opt flags. This will also allow for more fine-tuned control of printing behavior per callsite, instead of being applied globally.

PiperOrigin-RevId: 273368361

4 years agoUpdate UndefOp (de)serialization to generate OpUndef at module level.
Mahesh Ravishankar [Mon, 7 Oct 2019 19:56:08 +0000 (12:56 -0700)]
Update UndefOp (de)serialization to generate OpUndef at module level.

The SPIR-V spec recommends all OpUndef instructions be generated at
module level. For the SPIR-V dialect its better for UndefOp to produce
an SSA value for use with other instructions. If UndefOp is to be used
at module level, it cannot produce an SSA value (use of this SSA value
within FuncOp would need implicit capture). To satisfy needs of the
SPIR-V spec while making it simpler to represent UndefOp in the SPIR-V
dialect, the serialization is updated to create OpUndef instruction
at module scope.

PiperOrigin-RevId: 273355526

4 years ago[spirv] Fix function entry block erase after moving to spv.selection
Lei Zhang [Mon, 7 Oct 2019 19:36:39 +0000 (12:36 -0700)]
[spirv] Fix function entry block erase after moving to spv.selection

The structured selection/loop's entry block does not have arguments.
If the function's header block is also part of the structured control
flow, we cannot just simply erase it because it may contain arguments
matching the function signature and used by the cloned blocks. Instead,
turn it into a block only containing a spv.Branch op.

Also, we can directly emit instructions for the spv.selection header
block to the block containing the spv.selection op. This eliminates
unnecessary branches in the SPIR-V blob.

Added a test for nested spv.loop.

PiperOrigin-RevId: 273351424

4 years agofix simplify-affine-structures bug
Uday Bondhugula [Mon, 7 Oct 2019 17:03:38 +0000 (10:03 -0700)]
fix simplify-affine-structures bug

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

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/157 from bondhugula:quickfix bd1fcd79825fc0bd5b4a3e688153fa0993ab703d
PiperOrigin-RevId: 273316498

4 years agoChange Block::getParent() to be a const function. This is only necessary because...
Christian Sigg [Mon, 7 Oct 2019 17:02:44 +0000 (10:02 -0700)]
Change Block::getParent() to be a const function. This is only necessary because ilist_node_with_parent specifically requires a 'getParent() const' method. If/When ilist_node removes this constraint we should drop the const to fit the rest of the MLIR const model.

PiperOrigin-RevId: 273316153