Commit Graph

2830 Commits

Author SHA1 Message Date
Mehdi Amini f1f9e3b8d1 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
2019-10-16 08:37:39 -07:00
Nicolas Vasilache 2c533e29c2 Fix typo in VectorOps.td
PiperOrigin-RevId: 275025323
2019-10-16 07:14:37 -07:00
Stephan Herhut b843cc5d5a Implement simple loop-invariant-code-motion based on dialect interfaces.
PiperOrigin-RevId: 275004258
2019-10-16 04:28:38 -07:00
River Riddle 98f64b4da1 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
2019-10-16 00:35:43 -07:00
River Riddle a08482c1ad 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
2019-10-16 00:34:09 -07:00
Hanhan Wang 950979745a Add support for OpBitwiseOr, OpBitwiseXor, and OpBitwiseAnd in SPIR-V dialect.
PiperOrigin-RevId: 274935374
2019-10-15 18:42:40 -07:00
MLIR Team 2fc29f1eab Fix typo
PiperOrigin-RevId: 274905193
2019-10-15 15:45:28 -07:00
MLIR Team c0b11f5cf4 Fix typos
PiperOrigin-RevId: 274902838
2019-10-15 15:34:39 -07:00
River Riddle 050241ed3d 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
2019-10-15 15:10:14 -07:00
MLIR Team 1f83316a6b Fix typo
PiperOrigin-RevId: 274894550
2019-10-15 14:56:55 -07:00
Lei Zhang e03e151983 [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
2019-10-15 14:53:30 -07:00
MLIR Team 2903594635 Fix minor typos
PiperOrigin-RevId: 274892763
2019-10-15 14:48:55 -07:00
Jacques Pienaar f16e89f841 Fix typos in InferTypeOpInterface.
PiperOrigin-RevId: 274866986
2019-10-15 12:51:25 -07:00
Sana Damani cd45b0c8d9 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
2019-10-15 11:40:44 -07:00
Jacques Pienaar 4e85dafedd Fix typos in LangRef and OpDefinitions
PiperOrigin-RevId: 274848361
2019-10-15 11:23:25 -07:00
Nicolas Vasilache 31c5a41a30 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
2019-10-15 11:04:45 -07:00
Nicolas Vasilache abf5c60af9 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
2019-10-15 06:53:08 -07:00
Alex Zinenko c50e53c109 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
2019-10-15 06:52:04 -07:00
Alex Zinenko 98815cfdd9 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
2019-10-15 06:51:01 -07:00
River Riddle 300112e135 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
2019-10-14 21:13:45 -07:00
River Riddle f29731d17f 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
2019-10-14 16:21:51 -07:00
River Riddle 96de7091bc 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
2019-10-14 10:01:59 -07:00
Mehdi Amini 24c392f21c 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
2019-10-14 09:05:34 -07:00
Nicolas Vasilache 5c5d83afb4 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
2019-10-14 08:43:53 -07:00
Nicolas Vasilache c2285b619d 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
2019-10-14 08:43:26 -07:00
Eric Schweitz a3d084848d 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
2019-10-11 18:35:33 -07:00
Alex Zinenko 8c2ea32072 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
2019-10-11 06:33:26 -07:00
Alex Zinenko 71b82bcbf6 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
2019-10-11 06:32:24 -07:00
Uday Bondhugula 47596f5345 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
2019-10-11 06:31:18 -07:00
Alexander Belyaev 7301ac72bc Rename LLVM::exp and LLVM::fmuladd to LLVM::ExpOP and LLVM::FMulAddOp.
PiperOrigin-RevId: 274154655
2019-10-11 05:38:37 -07:00
Alexander Belyaev 00d2a37e32 Add unary ops and ExpOp to Standard Dialect.
PiperOrigin-RevId: 274152154
2019-10-11 05:13:55 -07:00
Alex Zinenko 304e44a6b0 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
2019-10-11 01:36:38 -07:00
River Riddle 978b209d38 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
2019-10-10 21:57:50 -07:00
River Riddle 7a7dcc171d 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
2019-10-10 19:36:54 -07:00
River Riddle b245e9519c NFC: Initialize pass manager option fields inline instead of the class constructor.
PiperOrigin-RevId: 274087577
2019-10-10 19:35:55 -07:00
Alex Zinenko 08a2ce8a14 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
2019-10-10 17:19:57 -07:00
Alex Zinenko 4dde19f024 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
2019-10-10 17:19:57 -07:00
Mahesh Ravishankar 28d7f9c052 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
2019-10-10 17:19:57 -07:00
Geoffrey Martin-Noble 736f80d0dd Add trait for specified shapes matching
PiperOrigin-RevId: 274046434
2019-10-10 17:19:57 -07:00
River Riddle 6b1cc3c6ea 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
2019-10-10 17:06:33 -07:00
River Riddle 438dc176b1 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
2019-10-10 17:06:25 -07:00
Alex Zinenko ea34c2a7a4 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
2019-10-10 10:27:04 -07:00
Christian Sigg 82dc6c4492 Mark GPU dialect as illegal when lowering to NVVM.
PiperOrigin-RevId: 273948293
2019-10-10 06:32:12 -07:00
Geoffrey Martin-Noble cc145706aa 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
2019-10-10 02:31:53 -07:00
Alex Zinenko 5e7959a353 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
2019-10-10 01:34:06 -07:00
Parker Schuh 309b4556d0 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
2019-10-09 20:44:30 -07:00
Kazuaki Ishizaki f5813ff8e1 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
2019-10-09 20:32:47 -07:00
MLIR Team 221e661e91 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
2019-10-09 20:07:46 -07:00
Kazuaki Ishizaki 27f400c813 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
2019-10-09 15:07:25 -07:00
MLIR Team ae6946ec11 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
2019-10-09 13:49:17 -07:00