Commit Graph

1597 Commits

Author SHA1 Message Date
MLIR Team ff6804c045 Minor typo in integer type definition.
--

PiperOrigin-RevId: 244854008
2019-04-23 22:02:58 -07:00
Alex Zinenko 06ca99530d Factor out thread-safe uniqu'ing backed by vector in MLIRcontext
Extract common code from getAffineSymbolExpr and getAffineConstantExpr into a
    utility function safeGetOrCreate, similarly to the existing overloads for sets
    and maps.  The position in the vector is used as indexing key.  NFC.

--

PiperOrigin-RevId: 244820859
2019-04-23 22:02:50 -07:00
Alex Zinenko ea86e7652e ExecutionEngine: update to reflect LLVM API changes
LLVM Orc JIT changed the API for DynamicLibrarySearchGenerator::
    GetForCurrentProcess to only take one value of the DataLayout that it actually
    uses instead of the whole data layout.  Update MLIR ExecutionEngine call to
    this function accordingly.

--

PiperOrigin-RevId: 244820235
2019-04-23 22:02:41 -07:00
Smit Hinsu 017cf6c7b8 Fix unused variable warning in opt build
TESTED with existing tests

--

PiperOrigin-RevId: 244808731
2019-04-23 22:02:33 -07:00
Stella Laurenzo 8189e6ef90 Implement lowering of quant.dcast to the fxpmathops and standard dialect.
Note that I broke this out as a separate pass because intermediate transformations often produce qcast/dcast ops that are integral to the transformation, and it is typical to want to lower any remaining, unmatched casts at the end of quantization. If this flexibility ends up not being needed, they can be collapsed into the same pass. This is included in the same cpp file because all of the math ops will need to defer to emitting quantize/dequantize logic for cases that they cannot be fully lowered to fixed-point math.

    Also, the new convertistof op needs to be evaluated for inclusion in StandardOps.

--

PiperOrigin-RevId: 244768679
2019-04-23 22:02:25 -07:00
Feng Liu 5c757087c7 Apply patterns repeatly if the function is modified
During the pattern rewrite, if the function is changed, i.e. ops created,
    deleted or swapped, the pattern rewriter needs to re-scan the function entirely
    and apply the patterns again, so the patterns whose root ops have been popped
    out from the working list nor an immediate users of the changed ops can be
    reconsidered.

    A command line flag is added to set the max number of iterations rescanning the
    function for pattern match. If the rewrite doesn' converge after this number,
    this compiling will continue and the result can be sub-optimal.

    One unit test is updated because this change fixed the missing optimization opportunities.

--

PiperOrigin-RevId: 244754190
2019-04-23 22:02:16 -07:00
Lei Zhang 10bcc34a68 [TableGen] Clean up comments regarding op and result
An op can have multiple results. Being explicit that we are binding to the
    whole op instead of one of the results. A way to bind to a specific result
    is yet to come.

--

PiperOrigin-RevId: 244741137
2019-04-23 22:02:08 -07:00
Lei Zhang d0e2019d39 [TableGen] Unify cOp and tAttr into NativeCodeCall
Both cOp and tAttr were used to perform some native C++ code expression.
    Unifying them simplifies the concepts and reduces cognitive burden.

--

PiperOrigin-RevId: 244731946
2019-04-23 22:02:00 -07:00
Lei Zhang 09b623aa93 [TableGen] Capture bound source ops in PatternState
This allows accessing those bound source ops in result patterns, which can be
    useful for invoking native C++ op creation.

    We bind the op entirely here because ops can have multiple results. Design a
    approach to bind to a specific result is not the concern of this commit.

--

PiperOrigin-RevId: 244724750
2019-04-23 22:01:52 -07:00
Jacques Pienaar f7f2760c30 Update lib path in whole_archive_link.
The added library path is now specified explicitly wrt top-level build directory.

--

PiperOrigin-RevId: 244507187
2019-04-23 22:01:44 -07:00
Lei Zhang 82a586e658 Use StringRef::drop_while() to simplify a while loop
--

PiperOrigin-RevId: 244488612
2019-04-23 22:01:35 -07:00
Mehdi Amini 159d07254e Add references to the EuroLLVM talks in the README
--

PiperOrigin-RevId: 244433092
2019-04-23 22:01:26 -07:00
Stella Laurenzo 4292294a65 Simplify and enable pretty-parsing/printing of the uniform quantized types.
The per-layer format is now like:
      !quant.uniform<i8<-8:7>:f32, 9.987200e-01:127>
    and per-axis is:
      !quant.uniform<i8:f32:1, {2.0e+2,0.99872:120}>

    I used the following sed script to update the unit tests (invoked with commands like `sed -i -r -f fix_quant.sed $(find . -name '*.mlir')`).
    ---
    # Per-layer
    s|\!quant<"uniform\[([iu][0-9]+):([fb]+[0-9]+)\]\{([^\}]+)\}\s*">|!quant.uniform<\1:\2, \3>|g
    s|\!quant<"uniform\[([iu][0-9]+)\(([^\)]+)\):([fb]+[0-9]+)\]\{([^\}]+)\}\s*">|!quant.uniform<\1<\2>:\3, \4>|g

    # Per-axis
    s|\!quant<"uniform\[([iu][0-9]+):([fb]+[0-9]+)(:[0-9]+)?\]\{([^\}]+)\}\s*">|!quant.uniform<\1:\2\3, {\4}>|g
    s|\!quant<"uniform\[([iu][0-9]+)\(([^\)]+)\):([fb]+[0-9]+)(:[0-9]+)?\]\{([^\}]+)\}\s*">|!quant.uniform<\1<\2>:\3\4, {\5}>|g
    ---
    I fixed up the one file of error cases manually.
    Since this is a one time syntax fix, I am not persisting the script anywhere.

--

PiperOrigin-RevId: 244425331
2019-04-23 22:01:18 -07:00
Nicolas Vasilache 0b47f74037 [Linalg] Add a slice op
This CL adds a linalg.slice op with the proper roundtripping test.
    A slice op allows taking subviews that may be rank-reducing (if some indexing is of index type) or not (if all indexings are of linalg.range type).

    A slice must be constructed directly from a base view (no chains of slices may exist in the IR). Helper functions that fold will be provided for construction if/when necessary.

    This also renames base_view to view.

--

PiperOrigin-RevId: 244406827
2019-04-23 22:01:10 -07:00
Nicolas Vasilache 1d5dc840e7 [Linalg] Add a view type with base_view op
This CL adds a linalg.view<?x?xf32> type and base_view op with the proper roundtripping test. The parser will be improved in a subsequent CL once portions of the mlir::Parser are exposed.

    For now this only supports dynamic views, static views will be introduced at a later time when they are needed.

--

PiperOrigin-RevId: 244374180
2019-04-23 22:01:02 -07:00
Stella Laurenzo e8d551e2bd Implement lowering of element-wise fixed point add and mul to the standard dialect.
This also does the following:
      - Removes the poc POT add implementation in favor of a version that does not rescale.
      - Adds a handful of FxpMathOps which are needed (these are for comment and we may want to move them to the StandardOps dialect).
      - Adds a canonicalizer to the StorageCastOp, which removes some cruft once conversions have been done.
      - Adds a couple of predicates to OpBase.

--

PiperOrigin-RevId: 244287706
2019-04-23 22:00:53 -07:00
Guangda Lai 7977e62b96 Fix typo (transpose -> reshape).
--

PiperOrigin-RevId: 244270801
2019-04-23 22:00:45 -07:00
Nicolas Vasilache 75be1fe82b [Linalg] Add a simple buffer type with alloc/dealloc ops
This CL adds a linalg.buffer<f32> type and buffer_alloc / buffer_dealloc ops with the proper roundtripping test.

--

PiperOrigin-RevId: 244252306
2019-04-23 22:00:36 -07:00
Nicolas Vasilache 8370cc7492 Start a Linalg dialect
This CL starts implementing a Linalg dialect with the objective of supporting
    optimizing compilation of loops and library calls for a subset of common linear
    algebra operations.

    This CL starts by simply adding a linalg.range type and an operation with the
    proper roundtripping test.

--

PiperOrigin-RevId: 244189468
2019-04-18 11:50:27 -07:00
Lei Zhang 05dfb1c7e0 Fix MLIRTableGenTests target_link_libraries typo
--

PiperOrigin-RevId: 244168112
2019-04-18 11:50:19 -07:00
Lei Zhang 13285ee907 [TableGen] Simplify NOperands trait generation
--

PiperOrigin-RevId: 244162515
2019-04-18 11:50:11 -07:00
Jacques Pienaar 2d79bcb7cd Simplify build instructions.
--

PiperOrigin-RevId: 244120877
2019-04-18 11:50:03 -07:00
Nicolas Vasilache 5b0c2420f7 Use proper C++ casts in Types.h
This CL reduces the amount of warning spew when compiling with CMake on Linux.

--

PiperOrigin-RevId: 244070668
2019-04-18 11:49:55 -07:00
Nicolas Vasilache cfdffd90a0 Use proper C++ casts in Location.h
This CL reduces the amount of warning spew when compiling with CMake on Linux.

--

PiperOrigin-RevId: 244070052
2019-04-18 11:49:47 -07:00
Amit Sabne 4aa9235ae0 Fix LLVM_DEBUG instances
--

PiperOrigin-RevId: 244058051
2019-04-18 11:49:39 -07:00
Amit Sabne 7905da656e Loop invariant code motion.
--

PiperOrigin-RevId: 244043679
2019-04-18 11:49:31 -07:00
Feng Liu c9f21cf355 Move QuantTypes out of QuantOps to match the file structures of other dialects
This CL also moved the UniformSupport.cpp and FakeQuantSupport.cpp into utils because they are not really the core of the IR.

--

PiperOrigin-RevId: 244001666
2019-04-18 11:49:22 -07:00
Stella Laurenzo a2e08eb384 Bring naming of some quant ops in alignment with docs and introduce a few necessary additional ops (stats_ref, stats, coupled_ref).
--

PiperOrigin-RevId: 243919195
2019-04-18 11:49:14 -07:00
MLIR Team ee7bdddfb3 Add NewLine for Attribute dump()
--

PiperOrigin-RevId: 243904869
2019-04-18 11:49:06 -07:00
Yanan Cao e01260bf75 Add DebugStringHelper, which makes it easier to get a string from a dump method
--

PiperOrigin-RevId: 243899072
2019-04-18 11:48:58 -07:00
Nicolas Vasilache 0fe2f009f2 Fix SliceAnalysis comment
The description of the backward slice analysis behavior describes what would happen when creating a backward slice from node 9, not 8.

--

PiperOrigin-RevId: 243876599
2019-04-18 11:48:50 -07:00
Lei Zhang b8dc04a005 [TableGen] Fix builder for ops with one variadic input and SameValueType
For ops with the SameValueType trait, we generate a builder without requiring
    result type; we get the result type from the operand. However, if the operand
    is variadic, we need to index into the first value in the pack.

--

PiperOrigin-RevId: 243866647
2019-04-18 11:48:42 -07:00
Jacques Pienaar 5d783ab3bd Abort via report_fatal_error if dialect has been registered.
Fixes test in opt mode.

    Closes: tensorflow/mlir#17.

--

PiperOrigin-RevId: 243711043
2019-04-18 11:48:33 -07:00
Geoffrey Martin-Noble 6288503975 TypedTuple: Add support for tuples with type constraints on the elements.
--

PiperOrigin-RevId: 243685631
2019-04-18 11:48:25 -07:00
Lei Zhang 8bb8351710 [TableGen] Fix support for ops whose names have a leading underscore
TensorFlow ops have the convention to use leading underscore to denote
    internal ops.

--

PiperOrigin-RevId: 243627723
2019-04-18 11:48:17 -07:00
Chris Lattner 09c053bfd0 Expand the pretty dialect type system to support arbitrary punctuation and
other characters within the <>'s now that we can.  This will allow quantized
    types to use the pretty syntax (among others) after a few changes.

--

PiperOrigin-RevId: 243521268
2019-04-18 11:48:09 -07:00
Smit Hinsu 074cb4292f Fix CHECK-EMPTY directives without trailing colon
There are no empty lines in output for three of these directives so removed
them and replaced the remaining one with 'CHECK-NOT:' as otherwise it is
failing with the following error.

error: found 'CHECK-EMPTY' without previous 'CHECK: line

TESTED = n/a
PiperOrigin-RevId: 243288605
2019-04-18 11:48:01 -07:00
Smit Hinsu 0047ef9765 NFC: Simplify named attribute in TableGen generators
Now, op attribute names don't have '.' in their names so the special handling for it
    can be removed. Attributes for functions still have dialect prefix with '.' as separator but TableGen does not deal with functions.

    TESTED with existing unit tests

--

PiperOrigin-RevId: 243287462
2019-04-18 11:47:52 -07:00
Lei Zhang 2dc6d205ac [TableGen] Allocate `Operator` object on heap in `RecordOperatorMap`
Iterators for a `llvm::DenseMap` can be invalidated when an insertion occurs.
    In Pattern's `collectBoundArguments()`, we recursively handle all nested DAG
    nodes and grow the the `RecordOperatorMap`, while retaining a reference.
    This can cause the reference to be invalid and the program to behave randomly.
    Allocate each `Operator` object specifically to solve this issue.

    Also, `llvm::DenseMap` is a great way to map pointers to pointers, or map
    other small types to each other. This avoids placing the `Operator` object
    directly into the map.

--

PiperOrigin-RevId: 243281486
2019-04-18 11:47:43 -07:00
Lei Zhang 138c972d11 [TableGen] Use `tgfmt` to format various predicates and rewrite rules
This CL changes various predicates and rewrite rules to use $-placeholders and
    `tgfmt` as the driver for substitution. This will make the predicates and rewrite
    rules more consistent regarding their arguments and more readable.

--

PiperOrigin-RevId: 243250739
2019-04-18 11:47:35 -07:00
Lei Zhang 48a6aa6c51 [TableGen] Better support for predicate and rewrite rule specification
Currently predicates are written with positional placeholders `{N}` and rely on
    `formatv` as the engine to do substitution. The problem with this approach is that
    the definitions of those positional placeholders are not consistent; they are
    entirely up to the defining predicate of question. For example, `{0}` in various
    attribute constraints is used to mean the attribute, while it is used to main the
    builder for certain attribute transformations. This can become very confusing.

    This CL introduces `tgfmt` as a new mechanism to better support for predicate and
    rewrite rule specification. Instead of entirely relying on positional placeholders,
    `tgfmt` support both positional and special placeholders. The former is used for
    DAG operands. The latter, including $_builder, $_op, $_self, are used as special
    "hooks" to entities in the context. With this, the predicate and rewrite rules
    specification can be more consistent is more readable.

--

PiperOrigin-RevId: 243249671
2019-04-18 11:47:27 -07:00
Chris Lattner 4d243f138a Update the Rationale's description about signed/unsigned and int/fp types to be more specific about the fact that this only refers to std operations. Move these sections closer together.
--

PiperOrigin-RevId: 243204948
2019-04-18 11:47:18 -07:00
Mehdi Amini e552a63aa1 Update documentation for the DialectOpconversion class: overriding `match()` is optional
Recently a default implementation for `match()` was provided (cl/242285885), but the class documentation wasn't updated appropriately.

--

PiperOrigin-RevId: 243128738
2019-04-18 11:47:10 -07:00
Lei Zhang 0836f670f1 Add missing dependencies for EDSC and linalg libraries
This solves the missing "mlir/StandardOps/Ops.h.inc" issue when building
    a fresh checkout on macOS.

--

PiperOrigin-RevId: 243120388
2019-04-11 12:35:29 -07:00
Geoffrey Martin-Noble fe59ba19af Add support for statically shaped and typed tensors
--

PiperOrigin-RevId: 242972594
2019-04-11 10:53:09 -07:00
Stella Laurenzo d468eaccfc Update custom rewrite example, which seems to have drifted a bit from the implementation.
PiperOrigin-RevId: 242968685
2019-04-11 10:53:01 -07:00
Stella Laurenzo b0055ab5c3 Update the FxpMathOps to better reflect what is needed to legalize from XLA.
--

PiperOrigin-RevId: 242919924
2019-04-11 10:52:51 -07:00
Lei Zhang dfcc02b111 [TableGen] Support naming rewrite rules
--

PiperOrigin-RevId: 242909061
2019-04-11 10:52:43 -07:00
Lei Zhang bdd56eca49 Remove checks guaranteed to be true by the type
This addresses the compiler wraning of "comparison of unsigned expression
    >= 0 is always true [-Wtype-limits]".

--

PiperOrigin-RevId: 242868703
2019-04-11 10:52:33 -07:00
Lei Zhang 2e7895d5f1 Add parentheses in various asserts to group predicates
This addresses the "suggest parentheses around ‘&&’ within ‘||’
    [-Wparentheses]" compiler warnings.

--

PiperOrigin-RevId: 242868670
2019-04-11 10:52:21 -07:00
Lei Zhang 9ec5fcf1fa Use hexadecimal constants instead of binary constants
This addresses the "binary constants are a C++14 feature or GCC
    extension" compiler warnings.

--

PiperOrigin-RevId: 242868639
2019-04-11 10:52:12 -07:00
Stephan Herhut d6037276af Add conversion of StandardOps and, or and xor to LLVM dialect.
--

PiperOrigin-RevId: 242831203
2019-04-11 10:52:02 -07:00
Andy Davis 44f6dffbf8 Factor code to compute dependence components out of loop fusion pass, and into a reusable utility function (NFC).
--

PiperOrigin-RevId: 242716259
2019-04-11 10:51:53 -07:00
Amit Sabne 70a416de14 Fix typos in LoopFusion
--

PiperOrigin-RevId: 242679298
2019-04-11 10:51:43 -07:00
Nicolas Vasilache dfd98764f7 Start a Linalg doc
--

PiperOrigin-RevId: 242622278
2019-04-11 10:51:34 -07:00
Mehdi Amini 6c6ed466a6 Expose `setupTargetTriple` as a public static method on ExecutionEngine
This allows client to be able to reuse the same logic to setup a module
    for the ExecutionEngine without instanciating one. One use case is running
    the optimization pipeline but not JIT-ing.

--

PiperOrigin-RevId: 242614380
2019-04-11 10:51:24 -07:00
Mehdi Amini c4dee61c0e Fix Toy cmake build: add missing includes
--

PiperOrigin-RevId: 242609231
2019-04-08 23:27:02 -07:00
Mehdi Amini c39592b09c Toy tutorial Chapter 5: Lowering to Linalg and LLVM
--

PiperOrigin-RevId: 242606796
2019-04-08 23:26:54 -07:00
Mehdi Amini a43f216fd5 Automated rollback of changelist 242546977.
PiperOrigin-RevId: 242604949
2019-04-08 23:26:46 -07:00
Mehdi Amini 6b18e34de4 Use c++14 for building with CMake
This is getting rid of some warnings, and C++14 is supposed to be
    the default soon anyway.

--

PiperOrigin-RevId: 242587219
2019-04-08 23:26:38 -07:00
Lei Zhang 04b6d2f3c1 [TableGen] Make sure op in pattern has the same number of arguments as definition
When an op in the source pattern specifies more arguments than its definition, we
    will have out-of-bound query for op arguments from the definition. That will cause
    crashes. This change fixes it.

--

PiperOrigin-RevId: 242548415
2019-04-08 19:17:56 -07:00
Nicolas Vasilache 1ee07e7fde De-templatize TensorContractionBase (Linalg example/tutorial)
TensorContractionBase has become too unwieldy with all the CRTP manipulation once less trivial transformations are implemented.
    This CL drops CRTP for inheritance and uses the same name comparison trick to figure out what to cast into.
    As a byproduct, all the -inl.h files disappear.
    To maintain the separation between directories, a LINALG_STEP variable is introduced

--

PiperOrigin-RevId: 242546977
2019-04-08 19:17:56 -07:00
Ashwin Murthy 70546104ff Add TabelGen support to logically AND a list of attribute constraints.
This is the AllOf version for AttrConstraint and allows specifying the combined constraint during pattern match.

--

PiperOrigin-RevId: 242540243
2019-04-08 19:17:56 -07:00
Nicolas Vasilache 046a993967 Add CMakeLists rules for Linalg
--

PiperOrigin-RevId: 242454319
2019-04-08 19:17:56 -07:00
Stephan Herhut af016ba7a4 Add xor bitwise operation to StandardOps.
This adds parsing, printing and some folding/canonicalization.

    Also extends rewriting of subi %0, %0 to handle vectors and tensors.

--

PiperOrigin-RevId: 242448164
2019-04-08 19:17:56 -07:00
Nicolas Vasilache ca89e7167d Fix build for the Linalg example dialect with MacOS
--

PiperOrigin-RevId: 242443831
2019-04-08 19:17:56 -07:00
Alex Zinenko adb0ca0732 Example Linalg3: manually register the Linalg dialect
This dialect does not have a global constructor and has to be registered
    manually in `main`.  Also fix the way it is exercised in the test.

--

PiperOrigin-RevId: 242434886
2019-04-08 19:17:56 -07:00
Alex Zinenko 8e193e617c Change initialization syntax for ScopedContext in examples
For some reason, the OSS build on macOS was not happy with the initialization
    syntax and was attempting to call a copy constructor.  Hotfix it to use a
    different syntax pending further investigation.

--

PiperOrigin-RevId: 242432634
2019-04-08 19:17:56 -07:00
Stephan Herhut a8a5c06961 Add and and or bitwise operations to StandardOps.
This adds parsing, printing and some folding/canonicalization.

--

PiperOrigin-RevId: 242409840
2019-04-08 19:17:50 -07:00
Mehdi Amini 89d5d36964 Fix bug in Toy tutorial where IR emission stopped after any `print`
--

PiperOrigin-RevId: 242407970
2019-04-08 18:54:25 -07:00
Mehdi Amini 7286d43920 Introduce std.varargs attribute to mark variadic arguments functions
This is only teaching the LLVM converter to propagate the attribute onto
    the function type. MLIR will not recognize this arguments, so it would only
    be useful when calling for example `printf` with the same arguments across
    a module. Since varargs is part of the ABI lowering, this is not NFC.

--

PiperOrigin-RevId: 242382427
2019-04-07 18:22:56 -07:00
Mehdi Amini f9c4c60320 Do not mark llvm.return, llvm.br, llvm.cond_br operations as having no side effects.
The canonicalizer is taking advantage of this to kill them.

--

PiperOrigin-RevId: 242374166
2019-04-07 18:22:46 -07:00
Mehdi Amini fea0560816 Fix Linalg3 lowering to use the floating point element type matching the view
It used to be hardcoded to f32, but Toy tutorial is using f64.

--

PiperOrigin-RevId: 242370172
2019-04-07 18:22:34 -07:00
Mehdi Amini 364b7e624e Add support for f64 type conversion for Linalg dialect to LLVM lowering
--

PiperOrigin-RevId: 242345259
2019-04-07 18:22:22 -07:00
Tatiana Shpeisman 6271e7a758 Fix cond_br example.
PiperOrigin-RevId: 242314071
2019-04-07 18:22:11 -07:00
Tatiana Shpeisman de2a119451 Documentation fix - use '_' instead of '.' in the type alias example.
PiperOrigin-RevId: 242313674
2019-04-07 18:22:00 -07:00
Tatiana Shpeisman 85bc5d0776 Documentation fix - complex type is a standard type
PiperOrigin-RevId: 242313280
2019-04-07 18:21:48 -07:00
Mehdi Amini f40634ef3a Filter DialectConversion pattern to be considered only if the root kind matches the operation.
This is the same logic as the PatterRewriter.

--

PiperOrigin-RevId: 242287241
2019-04-07 18:21:34 -07:00
Mehdi Amini ed84d7000c Provide a default implementation for matching: most DialectOpConversion implementations are unconditionally matching.
This will help removing boilerplate.

--

PiperOrigin-RevId: 242285885
2019-04-07 18:21:23 -07:00
Chris Lattner 72441fcbf2 Change the asmprinter to use pretty syntax for dialect types when it can,
making the IR dumps much nicer.

    This is part 2/3 of the path to making dialect types more nice.  Part 3/3 will
    slightly generalize the set of characters allowed in pretty types and make it
    more principled.

--

PiperOrigin-RevId: 242249955
2019-04-07 18:21:13 -07:00
Chris Lattner 3f93d93367 Introduce support for parsing pretty dialect types, currently with a very
restricted grammar.  This will make certain common types much easier to read.

    This is part tensorflow/mlir#1 of 2, which allows us to accept the new syntax.  Part 2 will
    change the asmprinter to automatically use it when appropriate, which will
    require updating a bunch of tests.

    This is motivated by the EuroLLVM tutorial and cleaning up the LLVM dialect aesthetics a bit more.

--

PiperOrigin-RevId: 242234821
2019-04-07 18:21:02 -07:00
Andy Davis 637eb2fc76 Remove/replace TPU-specific instruction references and memref spaces in LangRef.md
Remove undesigned/unimplemented operations: reshape and view.
Add new LangRefDeletions.md file in /experimental to store things removed from public LangRef.md

PiperOrigin-RevId: 242230200
2019-04-07 18:20:50 -07:00
River Riddle 67653d9881 Add iterator support to DenseIntElementsAttr and DenseFPElementsAttr. This avoids the need to load all of the values from a DenseElementsAttr inorder to process them.
--

PiperOrigin-RevId: 242212741
2019-04-07 18:20:40 -07:00
Ashwin Murthy fe1211edf2 Add attr constraint support to constrain IntegerArray attribute values at a specified index.
--

PiperOrigin-RevId: 242209394
2019-04-07 18:20:29 -07:00
Nicolas Vasilache a1b4cae30a Post commit cleanups to the Linalg dialect
--

PiperOrigin-RevId: 242181687
2019-04-07 18:20:19 -07:00
River Riddle e4628b79fb Add new utilities for RTTI Operation casting: dyn_cast_or_null and isa_nonnull
* dyn_cast_or_null
      - This will first check if the operation is null before trying to 'dyn_cast':

        Value *v = ...;
        if (auto forOp = dyn_cast_or_null<AffineForOp>(v->getDefiningOp()))
          ...
    * isa_nonnull
      - This will first check if the pointer is null before trying to 'isa':

        Value *v = ...;
        if (isa_nonnull<AffineForOp>(v->getDefiningOp());
          ...

--

PiperOrigin-RevId: 242171343
2019-04-07 18:20:07 -07:00
Lei Zhang 4cda344e7b Add methods for building array attributes in Builder
I32/I64/F32/F64/Str array attributes are commonly used in ops. It helps
    to have handy methods for them.

--

PiperOrigin-RevId: 242170569
2019-04-07 18:19:56 -07:00
River Riddle 465ef55088 Tidy up the links in the documents and fix any broken ones.
--

PiperOrigin-RevId: 242127863
2019-04-07 18:19:46 -07:00
Alex Zinenko 6196c8a9fd Linalg3 example: implement JIT-compilation and execution
Use MLIR's ExecutionEngine to demonstrate how one can implement a simple
    JIT-compiler and executor after fully lowering the Linalg dialect to the LLVM
    IR dialect, using the direct conversion (not going through standard
    loads/stores).

--

PiperOrigin-RevId: 242127690
2019-04-07 18:19:35 -07:00
Alex Zinenko 33285de937 ExecutionEngine: allow for running MLIR passes during JIT-compilation
The existing implementation of the ExecutionEngine unconditionally runs a list
    of "default" MLIR passes on the module upon creation.  These passes include,
    among others, dialect conversions from affine to standard and from standard to
    LLVM IR dialects.  In some cases, these conversions might have been performed
    before ExecutionEngine is created.  More advanced use cases may be performing
    additional transformations that the "default" passes will conflict with.
    Provide an overload for ExecutionEngine::create that takes a PassManager
    configured with the passes to run on the module.  If it is not provided, do not
    run any passes.  The engine will not be created if the input module, after the
    pass manager, has any other dialect than the LLVM IR dialect.

--

PiperOrigin-RevId: 242127393
2019-04-07 18:19:23 -07:00
Mehdi Amini 7a640e65e9 Fix CMake build: reflect that a new file Utils/ConstantFoldUtils.cpp was added
--

PiperOrigin-RevId: 242123122
2019-04-05 07:43:50 -07:00
Mehdi Amini 7d60cd898c Add mentions of requirements before the build instructions
The `Getting Started` instructions requires git, ninja, and a working C++ host toolchain.

--

PiperOrigin-RevId: 242121953
2019-04-05 07:43:41 -07:00
Lei Zhang b5235d1a9c [TableGen] Support array attribute subclasses and constraints
To support automatically constraint composition of ArrayAttr, a new
    predicate combiner, Concat, is introduced. It prepends a prefix and
    appends a postfix to a child predicate's final predicate string.

--

PiperOrigin-RevId: 242121186
2019-04-05 07:43:32 -07:00
Mehdi Amini 01e8ec94c3 Fix CMake build: account for renamed files and add missing include on MacOS
--

PiperOrigin-RevId: 242101364
2019-04-05 07:43:23 -07:00
Nicolas Vasilache 92df395068 Linalg portion of the tutorial - part 4
This CL adds declarative tiling support in the linalg dialect by providing:
    1. loop tiling on linalg ops by simply calling into mlir::tile
    2. view tiling on linalg ops by:
      a. computing the subview between for each tile dimension based on the loop tile size and the mapping of loops to operand ranges.
      b. declaring that the tiled form of a tensorcontraction is the same tensorcontraction on subviews, which essentially gives us a recursive form.

    Point 2.b is potentially subject to change in the future.

--

PiperOrigin-RevId: 242058658
2019-04-05 07:43:14 -07:00
River Riddle fde21c6faf NFC: Fix a few typos in the tutorials and one in the comment of FunctionAttr::dropFunctionReference.
--

PiperOrigin-RevId: 242050934
2019-04-05 07:43:05 -07:00
Mehdi Amini d33a9dcc73 Add Chapter 4 for the Toy tutorial: shape inference, function specialization, and basic combines
--

PiperOrigin-RevId: 242050514
2019-04-05 07:42:56 -07:00
Mehdi Amini 0a6cb91615 Add mention that we don't (yet) accept contributions in the README
--

PiperOrigin-RevId: 242049527
2019-04-05 07:42:47 -07:00
Nicolas Vasilache 623e4b9711 Linalg portion of the tutorial - part 3-3
This CL adds the last bit to convert from linalg.LoadOp and linalg.StoreOp to the affine dialect, as well as a unit test to exercise the conversion.

--

PiperOrigin-RevId: 242045826
2019-04-05 07:42:38 -07:00
River Riddle c4a5386e48 NFC: Replace usages of iterator_range<operand_iterator> with operand_range.
--

PiperOrigin-RevId: 242031201
2019-04-05 07:42:29 -07:00
River Riddle 64f10da5ee Introduce a new class, MultiOperandTraitBase, to deduplicate the operand accessors for traits with multiple operands.
As part of this cleanup, NOperands<0>::Impl and NOperands<1>::Impl are typedef'd to ZeroOperands and OneOperand respectively.

--

PiperOrigin-RevId: 242027189
2019-04-05 07:42:20 -07:00
River Riddle a83181cd20 NFC: Fix erroneous use of 'OpaqueType' with 'Type' when setting the ToyTypeKind, as well as a few mistakes in Chapter 2 of the Toy tutorial.
--

PiperOrigin-RevId: 242021477
2019-04-05 07:42:10 -07:00
MLIR Team 0cd589c337 Create a LoopUtil function to return perfectly nested loop set
--

PiperOrigin-RevId: 242019230
2019-04-05 07:42:01 -07:00
River Riddle a8f4b9eeeb Iterate on the operations to fold in TestConstantFold in reverse to remove the need for ConstantFoldHelper to have a flag for insertion at the head of the entry block. This also fixes an asan bug in TestConstantFold due to the iteration order of operations and ConstantFoldHelper's constant insertion placement.
Note: This now means that we cannot fold chains of operations, i.e. where constant foldable operations feed into each other. Given that this is a testing pass solely for constant folding, this isn't really something that we want anyways. Constant fold tests should be simple and direct, with more advanced folding/feeding being tested with the canonicalizer.

--

PiperOrigin-RevId: 242011744
2019-04-05 07:41:52 -07:00
River Riddle dca21299cb Fix a few warnings for missing parentheses around '||' and extra semicolons.
--

PiperOrigin-RevId: 241994767
2019-04-05 07:41:43 -07:00
Lei Zhang 4e40c83291 Deduplicate constant folding logic in ConstantFold and GreedyPatternRewriteDriver
There are two places containing constant folding logic right now: the ConstantFold
    pass and the GreedyPatternRewriteDriver. The logic was not shared and started to
    drift apart. We were testing constant folding logic using the ConstantFold pass,
    but lagged behind the GreedyPatternRewriteDriver, where we really want the constant
    folding to happen.

    This CL pulled the logic into utility functions and classes for sharing between
    these two places. A new ConstantFoldHelper class is created to help constant fold
    and de-duplication.

    Also, renamed the ConstantFold pass to TestConstantFold to make it clear that it is
    intended for testing purpose.

--

PiperOrigin-RevId: 241971681
2019-04-05 07:41:32 -07:00
River Riddle 6fa3181329 Remove the non-postorder walk functions from Function/Block/Instruction and rename walkPostOrder to walk.
--

PiperOrigin-RevId: 241965239
2019-04-05 07:41:23 -07:00
Andy Davis d0d1b2a30d Fix bug in LoopTiling where creation of tile-space loop upper bound did not handle symbol operands correctly.
--

PiperOrigin-RevId: 241958502
2019-04-05 07:41:12 -07:00
Andy Davis 55014813e3 Adds dependence analysis support for iteration domains with local variables (enables dependence analysis of loops with non-unit step).
--

PiperOrigin-RevId: 241957023
2019-04-05 07:41:02 -07:00
Lei Zhang 76cb205326 [TableGen] Enforce constraints on attributes
Previously, attribute constraints are basically unused: we set true for almost
    anything. This CL refactors common attribute kinds and sets constraints on
    them properly. And fixed verification failures found by this change.

    A noticeable one is that certain TF ops' attributes are required to be 64-bit
    integer, but the corresponding TFLite ops expect 32-bit integer attributes.
    Added bitwidth converters to handle this difference.

--

PiperOrigin-RevId: 241944008
2019-04-05 07:40:50 -07:00
Lei Zhang c7790df2ed [TableGen] Add PatternSymbolResolver for resolving symbols bound in patterns
We can bind symbols to op arguments/results in source pattern and op results in
    result pattern. Previously resolving these symbols is scattered across
    RewriterGen.cpp. This CL aggregated them into a `PatternSymbolResolver` class.

    While we are here, this CL also cleans up tests for patterns to make them more
    focused. Specifically, one-op-one-result.td is superseded by pattern.td;
    pattern-tAttr.td is simplified; pattern-bound-symbol.td is added for the change
    in this CL.

--

PiperOrigin-RevId: 241913973
2019-04-05 07:40:41 -07:00
Lei Zhang 3c833344c8 [TableGen] Rework verifier generation and error messages
Previously we bundle the existence check and the MLIR attribute kind check
    in one call. Further constraints (like element bitwidth) have to be split
    into following checks. That is not a nice separation given that we have more
    checks for constraints. Instead, this CL changes to generate a local variable
    for every attribute, check its existence first, then check the constraints.

    Creating a local variable for each attribute also avoids querying it multiple
    times using the raw getAttr() API. This is a win for both performance the
    readability of the generated code.

    This CL also changed the error message to be more greppable by delimiting
    the error message from constraints with boilerplate part with colon.

--

PiperOrigin-RevId: 241906132
2019-04-05 07:40:31 -07:00
Alex Zinenko 8b790434e5 Example Linalg3: support Load/Store conversion from Linalg to LLVM IR dialect
Load and Store Linalg operations are converter to their LLVM IR counterparts
    preceded by a sequence of operations that recover the effective address of the
    accessed element.  The address is computed given the subscripts and the view
    descriptor as

        base_pointer + base_offset + SUM_i subscript_i * stride_i.

    Manual testing shows that the resulting LLVM IR for the matrix multiplication
    example can be compiled and executed, producing correct results.

--

PiperOrigin-RevId: 241889003
2019-04-05 07:40:21 -07:00
Mehdi Amini 092f3facad Fix Toy Ch3 testing with CMake
Mainly a missing dependency caused the tests to pass if one already built
    the repo, but not from a clean (or incremental) build.

--

PiperOrigin-RevId: 241852313
2019-04-03 19:22:42 -07:00
Mehdi Amini f0a328b6d5 Chapter 3 for Toy tutorial: introduction of a dialect
--

PiperOrigin-RevId: 241849162
2019-04-03 19:22:32 -07:00
Dan Zheng 393c77c5da [README] Fix links, minor edits.
Fix links without breaking g3doc.
    Minor stylistic edits.

--

PiperOrigin-RevId: 241846985
2019-04-03 19:22:23 -07:00
Dan Zheng 0737776200 [README] Minor edits.
Minor stylistic edits.
    Use standard "TensorFlow" spelling.

--

PiperOrigin-RevId: 241842272
2019-04-03 19:22:14 -07:00
Stella Laurenzo 7ce55ff7c2 Add CMakeLists.txt for Quantization and FxpMathOps dialects (and misc fixes to build with OSS setup).
Tested:
      cmake -G Ninja ../llvm/ -DLLVM_BUILD_EXAMPLES=ON
      ninja check-mlir

--

PiperOrigin-RevId: 241841296
2019-04-03 19:22:05 -07:00
Mehdi Amini 3a2955fa1f Rename UnknownType to OpaqueType (NFC)
This came up in a review of the tutorial, it was suggested that "opaque" is more
    descriptive than "unknown" here.

--

PiperOrigin-RevId: 241832927
2019-04-03 19:21:47 -07:00
Mehdi Amini a261ce5b40 Move the top-level `tutorial` as `Linalg` nested in the examples folder
--

PiperOrigin-RevId: 241831176
2019-04-03 19:21:38 -07:00
Stella Laurenzo 288bf2b5b9 Split the Quantization dialect.
- Retains Quantization types and predicates.
    - Retains utilities and example (testable) passes/ops.
    - Retains unit tests for example passes/ops.
    - Moves fixed point ops (and corresponding real ops) to FxpMathOps.
    - Moves real -> fixed point pass to FxpMathOps.
    - Sever the dependency on the TF dialect from Quantization. These dialects should now be open-sourcable.

--

PiperOrigin-RevId: 241825598
2019-04-03 19:21:28 -07:00
Feng Liu 1b56ce3087 Fix the alignment issue in the DenseElementsAttr buffer allocation
Currently, we only make the initial address aligned with 64-bit address but
    allocate the buffer with the real size. This can cause issue when we extract
    the value by the `readBits` method, which needs to read the memory in the
    granularity of APINT_WORD_SIZE. In this CL, we rounded the allocation size to
    the multiplies of APINT_WORD_SIZE to fix the issue.

--

PiperOrigin-RevId: 241816656
2019-04-03 19:21:18 -07:00
Rob Suderman 8d40302b34 Added memref to OpBase.td as specific memref types should be supported by default.
--

PiperOrigin-RevId: 241806461
2019-04-03 19:21:09 -07:00
Smit Hinsu f504b63f6f Remove links to internal google docs, updating them to point to GitHub.
PiperOrigin-RevId: 241801638
2019-04-03 19:21:00 -07:00
Chris Lattner 7bf06e6038 Remove links to internal google docs, updating them to point to GitHub.
--

PiperOrigin-RevId: 241800478
2019-04-03 19:20:50 -07:00
Stella Laurenzo c833d8a19d Refactor Quantization.md to separate TFLite native quantization scheme from the more experimental, generalized scheme.
PiperOrigin-RevId: 241785572
2019-04-03 19:20:40 -07:00
Nicolas Vasilache 50df91745d Linalg portion of the tutorial - part 3-2
This CL adds support for lowering tensor contractions to loops declaratively.
    This is done thanks to two properties of the such operations:
    1. the definition of an AffineMap getLoopsToOperandRangesMap for each op which maps iteration space dimensions to ranges of the view operands, in their order of occurrence;
    2. the definition of a scalar implementation for each op which creates the computation inside the loops given enclosing parallel and reduction loops,

    All the other properties are derived in a generic fashion from these 2 properties and a few analyses.

    A lowerToLoops transformation is added as well as a test that exercises it.

--

PiperOrigin-RevId: 241783992
2019-04-03 19:20:31 -07:00
Lei Zhang b9e3b2107b [TableGen] Allow additional result patterns not directly used for replacement
This CL looses the requirement that all result patterns in a rewrite rule must
    replace a result of the root op in the source pattern. Now only the last N
    result pattern-generated ops are used to replace a N-result source op.

    This allows to generate additional ops to aid building up final ops used to
    replace the source op.

--

PiperOrigin-RevId: 241783192
2019-04-03 19:20:22 -07:00
Stella Laurenzo 13bb8f491a Initial release of the Quantization dialect
Includes a draft of documentation for the quantization setup.

Given how many comments such docs have garnered in the past, I've biased towards a lightly edited first-draft so that people can argue about terminology, approach and structure without having spent too much time on it.

Note that the sections under "Uniform quantization" were cribbed nearly verbatim from internal documentation that Daniel wrote.

PiperOrigin-RevId: 241768668
2019-04-03 19:20:12 -07:00
Lei Zhang 3522c65d3b [TableGen] Fix convertFromStorage for OptionalAttr
OptionalAttr is just wrapping around the actual attribute; so it should just use
    the actual attribute's `convertFromStorage` to read the value and wrap it around
    with `Optional<>` to return. Previously it was mandating how the actual attribute
    reads the value with `{0}.getValue()`.

--

PiperOrigin-RevId: 241762355
2019-04-03 18:36:19 -07:00
Alex Zinenko 5fb62b47c3 Tutorial Linalg1: implement conversion to the LLVM Dialect
Implement conversion from the Linalg dialect to the LLVM dialect using a simple
    set of DialectOpConverters and by plugging them into the dialect conversion
    infrastructure.  View and Range Linalg types are converted into descriptors
    that store the dynamic values in an LLVM aggregate type, similarly to memrefs.
    Slice operations create new descriptors based on the original descriptors and
    thus remove the constraint on ViewTypes not being acceptable as function
    arguments.

--

PiperOrigin-RevId: 241760189
2019-04-03 18:36:09 -07:00
Mehdi Amini 4e972bd5a5 Add mention of the TensorFlow Code of Conduct in the Readme
PiperOrigin-RevId: 241748009
2019-04-03 09:44:41 -07:00
Mehdi Amini 8806745436 Add missing source file in CMakeLists.txt
--

PiperOrigin-RevId: 241746122
2019-04-03 09:31:06 -07:00
Lei Zhang 1ac49ce0bd [TableGen] Remove asserts for attributes in aggregate builders
Attributes can have default values or be optional. Checking the validity of
    attributes in aggregate builder should consider that. And to be accurate,
    we should check all required attributes are indeed provided in the list.
    This is actually duplicating the work done by verifier. Checking the validity
    of attributes should be the responsiblity of verifiers. This CL removes
    the assertion for attributes in aggregate builders for the above reason.
    (Assertions for operands/results are still kept since they are trivial.)

    Also added more tests for aggregate builders.

--

PiperOrigin-RevId: 241746059
2019-04-03 09:30:49 -07:00
Mehdi Amini 0e28cea4d4 Fix CMake build
Some files were not built anymore internally but still referenced
    from CMake. Delete them and unreference them in the CMake files.

--

PiperOrigin-RevId: 241744718
2019-04-03 09:21:46 -07:00
Mehdi Amini 67f49eed9a Update Readme to mention that the TensorFlow specific will be upstreamed later
--

PiperOrigin-RevId: 241735845
2019-04-03 08:30:54 -07:00
Alex Zinenko f50edc65cd Drop MLIREmitter-based version of the EDSC
This version has been deprecated and can now be removed completely since the
    last remaining user (Python bindings) migrated to declarative builders.
    Several functions in lib/EDSC/Types.cpp construct core IR objects for the C
    bindings.  Move these functions into lib/EDSC/CoreAPIs.cpp until we decide
    where they should live.

    This completes the migration from the delayed-construction EDSC to Declarative
    Builders.

--

PiperOrigin-RevId: 241716729
2019-04-03 08:30:38 -07:00
Alex Zinenko 7a30ac97c8 Python bindings: drop MLIREmitter and related functionality
This completes the transition of Python bindings to use the declarative
    builders infrastructure instead of the now-deprecated EDSC emitter
    infrastructure.  The relevant unit tests have been replicated using the new
    functionality and the remaining end-to-end compilation tests have been updated
    accordingly.  The latter show an improvement in brevity and readability.

--

PiperOrigin-RevId: 241713489
2019-04-03 08:30:24 -07:00
Alex Zinenko 509619829d Python bindings: support __floordiv__ for index types
The original reimplementation of EDSC as declarative builders and the
    subsequent rework of Python bindings forbade to use the (true) division
    operator for values of the index types without providing an alternative.  Index
    types only support floor and ceil division through affine maps.  Expose this to
    Python bindings through a `__floordiv__` function on `ValueHandle`s.

--

PiperOrigin-RevId: 241713093
2019-04-03 08:30:07 -07:00
Mehdi Amini 1e021cfbd7 Remove section of the README copied from the Rationale document, it does not fit here.
--

PiperOrigin-RevId: 241687723
2019-04-03 08:29:47 -07:00
Nicolas Vasilache f1b12f5a64 Fix test that fails on non-determinism in LowerVectorTransfers
This CL fixes the non-determinism across compilers in an edsc::select expression used in LowerVectorTransfers. This is achieved by factoring the expression out of the function call to ensure a deterministic order of evaluation.
    Since the expression is now factored out, fewer IR is generated and the test is updated accordingly.

--

PiperOrigin-RevId: 241679962
2019-04-03 01:09:13 -07:00
Mehdi Amini c2e9ab8ef1 Fix path for the examples in Toy tutorial Ch1
PiperOrigin-RevId: 241643625
2019-04-02 18:15:38 -07:00
Mehdi Amini 607b8851a8 Add link to the Toy tutorial in the Readme
--

PiperOrigin-RevId: 241642739
2019-04-02 18:09:14 -07:00
River Riddle e97ca1227a Add fake-use for variable in LLVMDialect.cpp to fix opt build.
--

PiperOrigin-RevId: 241620442
2019-04-02 16:32:34 -07:00
Mehdi Amini e01cccf34a Fix minor typo (triggered a GCC warning, NFC)
--

PiperOrigin-RevId: 241618796
2019-04-02 16:32:18 -07:00
Alex Zinenko 736bef7386 Introduce custom format for the LLVM IR Dialect
Historically, the LLVM IR dialect has been using the generic form of MLIR
    operation syntax.  It is verbose and often redundant.  Introduce the custom
    printing and parsing for all existing operations in the LLVM IR dialect.
    Update the relevant documentation and tests.

--

PiperOrigin-RevId: 241617393
2019-04-02 16:31:58 -07:00
Mehdi Amini 04f766c2ed Add -DLLVM_BUILD_EXAMPLES to the mlir build instruction: this enables the tutorial examples
Seems like a better default for getting started.

--

PiperOrigin-RevId: 241614043
2019-04-02 15:16:45 -07:00
Mehdi Amini 5854fb9b94 Fix Toy tutorial gcc 7 build (NFC)
--

PiperOrigin-RevId: 241613710
2019-04-02 15:16:30 -07:00
Nicolas Vasilache 72ccfcee1e Linalg portion of the tutorial - part 3
This CL starts the third part of the Linalg tutorial by adding support for ops to declare how they lower themselves to other ops.
    Tests are added that demonstrate matmul lowering to a loop over matvec and matvec lowering to a loop over dot.

    This is part of a list of CLs that add new Transforms and Analyses to Linalg3: it iseasier to integrate in small chunks.

    As part of working with the TensorContractionBase template class and in an effort to add pieces incrementally without copying code, it is easiest to define operations ahead of time in Linalg2/TensorOps.h and gradually implement them as needed. This CL performs the necessary refactoring for this to happen.

--

PiperOrigin-RevId: 241605869
2019-04-02 15:16:14 -07:00
River Riddle 7fa2864954 Update the dialect attribute verification hooks to return LogicalResult instead of bool. This updates Function::emitError to return LogicalResult as well.
--

PiperOrigin-RevId: 241598892
2019-04-02 15:15:56 -07:00
Mehdi Amini f457ab7fc9 Provide default `affineMapComposition` and memory space on `MemRefType::get()` (NFC)
This matches the builder API.

--

PiperOrigin-RevId: 241592869
2019-04-02 13:41:15 -07:00
Mehdi Amini 213dda687b Chapter 2 of the Toy tutorial
This introduces a basic MLIRGen through straight AST traversal,
    without dialect registration at this point.

--

PiperOrigin-RevId: 241588354
2019-04-02 13:41:00 -07:00
River Riddle 67a52c44b1 Rewrite the verify hooks on operations to use LogicalResult instead of bool. This also changes the return of Operation::emitError/emitOpError to LogicalResult as well.
--

PiperOrigin-RevId: 241588075
2019-04-02 13:40:47 -07:00
Nicolas Vasilache 8affb783a8 Linalg portion of the tutorial - part 2
The second part of the Linalg tutorial introduces:
    1. the TensorContractionBase type from which all tensor contractions derive;
    2. a basic set of operations DotOp, MatvecOp and MatmulOp;
    3. a helper function `createFullyComposedView` that walks the producers of a SliceOp up until the root ViewOp and returns a single ViewOp;
    4. programmatic examples to test MLIR construction involving these types.

    This CL also refactors file organization so that:
    1. clients only need to include Ops.h and Types.h while keeping independent small files separate for the purpose of the tutorial;
    2. each step of the tutorial has its own linalgxxx include directory and each include explicitly states in which part of the tutorial a particular concept was introduced.

    Lastly the following cleanups are applied:
    1. ValueOrSliceOp is removed in favor of simpler helper function.
    2. methods that walk back the chain of ops are removed from the core ops and added to a separate Analysis.
    3. various additional cleanups.

--

PiperOrigin-RevId: 241555769
2019-04-02 13:40:33 -07:00
River Riddle 0be6369176 Update the Function and Module verifiers to return LogicalResult instead of bool.
--

PiperOrigin-RevId: 241553930
2019-04-02 13:40:20 -07:00
Mehdi Amini 38b71d6b84 Initial version for chapter 1 of the Toy tutorial
--

PiperOrigin-RevId: 241549247
2019-04-02 13:40:06 -07:00
Andy Davis 7c1fc9e795 Enable producer-consumer fusion for liveout memrefs if consumer read region matches producer write region.
--

PiperOrigin-RevId: 241517207
2019-04-02 13:39:50 -07:00
River Riddle 0451403066 Update the pass ir-printing test to not rely on rtti type pretty printing.
--

PiperOrigin-RevId: 241498090
2019-04-02 13:39:31 -07:00
River Riddle 084669e005 Remove MLPatternLoweringPass and rewrite LowerVectorTransfers to use RewritePattern instead.
--

PiperOrigin-RevId: 241455472
2019-04-02 13:39:17 -07:00
Lei Zhang bae95d25e5 [TableGen] Add Confined, IntMinValue, and ArrayMinCount for attribute constraints
This CL introduces Confined as a general mechanism to compose complex attribute
    constraints out of more primitive ones. It's particularly useful for automatically
    generating op definitions from some external source, where we can have random
    combinations of primitive constraints and it would be impractical to define a case
    for each of such combination.

    Two primitive attribute constraints, IntMinValue and ArrayMinCount, are added to be
    used together with Confined.

--

PiperOrigin-RevId: 241435955
2019-04-02 13:39:03 -07:00
Nicolas Vasilache d7296a4ae3 Linalg portion of the tutorial - part 1
The first part of the Linalg tutorial introduces:
    1. the RangeType and ViewType;
    2. operations on those, namely RangeOp, ViewOp and SliceOp;
    3. programmatic examples to test MLIR construction involving these types, ops and affine.for loops (with a mock custom op called "some_consumer").

--

PiperOrigin-RevId: 241409949
2019-04-02 13:38:44 -07:00
Mehdi Amini 9089911daa Use `this->` to access inherited member from dependent type (Fix GCC7 build, NFC)
--

PiperOrigin-RevId: 241364505
2019-04-01 11:29:18 -07:00
Mehdi Amini be4f48d1e1 Minor fixes to README.md (NFC)
In particular fix the links to work on GitHub, and do not include RTTI to build.

--

PiperOrigin-RevId: 241362244
2019-04-01 11:19:58 -07:00
Mehdi Amini 51f6c0ea60 Add a getLoc() method on mlir::Value that returns the loc of the defining Operations if any, otherwise an unknown location
--

PiperOrigin-RevId: 241354085
2019-04-01 11:00:58 -07:00
Mehdi Amini 005d54329e Add a getContext() convenient accessor on mlir::Value (NFC)
--

PiperOrigin-RevId: 241352789
2019-04-01 11:00:43 -07:00
Mehdi Amini b3a407fa68 Fix MacOS build
This is making up for some differences in standard library and linker flags.
    It also get rid of the requirement to build with RTTI.

--

PiperOrigin-RevId: 241348845
2019-04-01 11:00:30 -07:00
River Riddle 62cd7511f3 Rewrite ResultTypeIterator to be a mapped_iterator instead of an IndexedAccessorIterator. IndexedAccessorIterator makes some assumptions about the element type that do not hold for the result type, i.e. pointer elements. A mapped_iterator also better models the behavior of a ResultTypeIterator.
--

PiperOrigin-RevId: 241345949
2019-04-01 11:00:15 -07:00
Feng Liu 191aaa82ef Support 0-d tensor type attributes
This CL fixes the parser and printer to support the 0-d tensor type attributes.

--

PiperOrigin-RevId: 241345329
2019-04-01 10:59:59 -07:00
Feng Liu a0606ca717 Minor fixes on the typo/naming/style in the Pattern.cpp file
--

PiperOrigin-RevId: 241341334
2019-04-01 10:59:45 -07:00
Lei Zhang b9e38a7972 [TableGen] Add EnumAttrCase and EnumAttr
This CL adds EnumAttr as a general mechanism for modelling enum attributes. Right now
    it is using StringAttr under the hood since MLIR does not have native support for enum
    attributes.

--

PiperOrigin-RevId: 241334043
2019-04-01 10:59:31 -07:00
River Riddle 082016d43a Add a flag to Dialect that allows for dialects to enable support for unregistered operations. This flag is off by default and can be toggled via the 'allowUnknownOperations(...)' method. This means that moving forward an error will be emitted for unknown operations if the dialect does not explicitly allow it.
Example:

    func @unknown_std_op() {
      %0 = "std.foo_bar_op"() : () -> index
      return
    }

    Will result in:

    error: unregistered operation 'std.foo_bar_op' found in dialect ('std') that does not allow unknown operations

--

PiperOrigin-RevId: 241266009
2019-04-01 10:59:17 -07:00
River Riddle ff05e9da19 Update variable in PassTiming to refer to system_clock instead of high_resolution_clock.
--

PiperOrigin-RevId: 241260071
2019-04-01 10:58:59 -07:00
River Riddle dfc58742a2 Rename the 'namePrefix' field in the Dialect class to 'name' and tidy some comments to make it clear that 'name' refers to the dialect namespace.
--

PiperOrigin-RevId: 241103116
2019-03-30 11:23:55 -07:00
Chris Lattner 0fb905c070 Implement basic IR support for a builtin complex<> type. As with tuples, we
have no standard ops for working with these yet, this is simply enough to
    represent and round trip them in the printer and parser.

--

PiperOrigin-RevId: 241102728
2019-03-30 11:23:39 -07:00
Jacques Pienaar 1273af232c Add build files and update README.
* Add initial version of build files;
    * Update README with instructions to download and build MLIR from github;

--

PiperOrigin-RevId: 241102092
2019-03-30 11:23:22 -07:00
River Riddle 6f24bf82f9 Assert that registered dialects have unique names. This creates a guarantee that the namespace of a dialect can be used a unique key.
--

PiperOrigin-RevId: 241049578
2019-03-29 17:57:41 -07:00
River Riddle 0ae68a3ccf Remove the MLIRContext parameter from Dialect::parseType. Dialects already have access to the context via Dialect::getContext.
--

PiperOrigin-RevId: 241047077
2019-03-29 17:57:27 -07:00
River Riddle 258dbdafa8 Update TypeBase::verifyConstructionInvariants to use a LogicalResult return instead of bool.
--

PiperOrigin-RevId: 241045568
2019-03-29 17:57:12 -07:00
River Riddle 90d2e16e63 Replace usages of instruction with operation in the g3 documents.
PiperOrigin-RevId: 241037784
2019-03-29 17:56:57 -07:00
Nicolas Vasilache c9d5f3418a Cleanup SuperVectorization dialect printing and parsing.
On the read side,
```
%3 = vector_transfer_read %arg0, %i2, %i1, %i0 {permutation_map: (d0, d1, d2)->(d2, d0)} : (memref<?x?x?xf32>, index, index, index) -> vector<32x256xf32>
```

becomes:

```
%3 = vector_transfer_read %arg0[%i2, %i1, %i0] {permutation_map: (d0, d1, d2)->(d2, d0)} : memref<?x?x?xf32>, vector<32x256xf32>
```

On the write side,

```
vector_transfer_write %0, %arg0, %c3, %c3 {permutation_map: (d0, d1)->(d0)} : vector<128xf32>, memref<?x?xf32>, index, index
```

becomes

```
vector_transfer_write %0, %arg0[%c3, %c3] {permutation_map: (d0, d1)->(d0)} : vector<128xf32>, memref<?x?xf32>
```

Documentation will be cleaned up in a followup commit that also extracts a proper .md from the top of the file comments.

PiperOrigin-RevId: 241021879
2019-03-29 17:56:42 -07:00
Feng Liu a38792f7d1 remove the const quantifier before temp variable
PiperOrigin-RevId: 240997262
2019-03-29 17:56:27 -07:00
Nicolas Vasilache f93a5be65f Make createMaterializeVectorsPass take a vectorSize parameter - NFC
This CL allows the programmatic control of the target hardware vector size when creating a MaterializeVectorsPass.
This is useful for registering passes for the tutorial.

PiperOrigin-RevId: 240996136
2019-03-29 17:56:12 -07:00
Feng Liu 5303587448 [TableGen] Support benefit score in pattern definition.
A integer number can be specified in the pattern definition and used as the
adjustment to the default benefit score in the generated rewrite pattern C++
definition.

PiperOrigin-RevId: 240994192
2019-03-29 17:55:55 -07:00
Nicolas Vasilache 094ca64ab0 Refactor vectorization patterns
This CL removes the reliance of the vectorize pass on the specification of a `fastestVaryingDim` parameter. This parameter is a restriction meant to more easily target a particular loop/memref combination for vectorization and is mainly used for testing.

This also had the side-effect of restricting vectorization patterns to only the ones in which all memrefs were contiguous along the same loop dimension. This simple restriction prevented matmul to vectorize in 2-D.

this CL removes the restriction and adds the matmul test which vectorizes in 2-D along the parallel loops. Support for reduction loops is left for future work.

PiperOrigin-RevId: 240993827
2019-03-29 17:55:36 -07:00
River Riddle 3ddd0411d0 Slight rewording of TupleType rationale.
PiperOrigin-RevId: 240991400
2019-03-29 17:55:21 -07:00
River Riddle d16213bf66 Update the QuickstartRewrites document to include information about the new 'matchAndRewrite' functionality in RewritePatterns.
PiperOrigin-RevId: 240987764
2019-03-29 17:55:05 -07:00
River Riddle 8a0622c986 [PassManager] Add a utility class, PrettyStackTraceParallelDiagnosticEntry, to emit any queued up diagnostics in the event of a crash when multi-threading.
PiperOrigin-RevId: 240986566
2019-03-29 17:54:51 -07:00
MLIR Team 9d30b36aaf Enable input-reuse fusion to search function arguments for fusion candidates (takes care of a TODO, enables another tutorial test case).
PiperOrigin-RevId: 240979894
2019-03-29 17:54:36 -07:00
River Riddle 106dd08e99 Change the vectorizer test pass to output via diagnostics instead of llvm::outs. This allows for the output to be deterministic when multi-threading is enabled.
PiperOrigin-RevId: 240905858
2019-03-29 17:54:21 -07:00
MLIR Team dd0029e4f6 Support for type constraints across operand and results
--

PiperOrigin-RevId: 240905555
2019-03-29 17:54:06 -07:00
Tatiana Shpeisman 65a5f73ab3 Fixed a few instances of inconsistent grammar.
PiperOrigin-RevId: 240896336
2019-03-29 17:53:50 -07:00
Jacques Pienaar e7111fd62c Address some errors from g++
These fail with:

could not convert ‘module’ from ‘llvm::orc::ThreadSafeModule’ to
 ‘llvm::Expected<llvm::orc::ThreadSafeModule>’

PiperOrigin-RevId: 240892583
2019-03-29 17:53:36 -07:00
Jacques Pienaar b633fcf9c0 Add README file for MLIR.
PiperOrigin-RevId: 240889350
2019-03-29 17:53:21 -07:00
River Riddle 76181a7b38 Remove the LowerEDSCTestPass.
Most of the tests have been ported to be unit-tests and this pass is problematic in the way it depends on TableGen-generated files. This pass is also non-deterministic during multi-threading and a blocker to turning it on by default.

PiperOrigin-RevId: 240889154
2019-03-29 17:53:05 -07:00
River Riddle 909a63d8bf Tidy up a few comments and error messages related to parsing multi-result operations.
PiperOrigin-RevId: 240876306
2019-03-29 17:52:51 -07:00
Jacques Pienaar cd0b925dc2 Remove extra qualification
PiperOrigin-RevId: 240875432
2019-03-29 17:52:36 -07:00
Alex Zinenko 85bbde483d LLVM IR Dialect: separate the conversion tool from the conversion pass
Originally, the conversion to the LLVM IR dialect had been implemented as pass.
The common conversion infrastructure was factored into DialectConversion from
which the conversion pass inherited.  The conversion being a pass is
undesirable for callers that only need the conversion done, for example as a
part of sequence of conversions or outside the pass manager infrastructure.
Split the LLVM IR Dialect conversion into the conversion proper and the
conversion pass, where the latter contains the former instead of inheriting.
NFC.

PiperOrigin-RevId: 240874740
2019-03-29 17:52:20 -07:00
Alex Zinenko 3173a63f3f Dialect Conversion: convert regions of operations when cloning them
Dialect conversion currently clones the operations that did not match any
pattern.  This includes cloning any regions that belong to these operations.
Instead, apply conversion recursively to the nested regions.

Note that if an operation matched one of the conversion patterns, it is up to
the pattern rewriter to fill in the regions of the converted operation.  This
may require calling back to the converter and is left for future work.

PiperOrigin-RevId: 240872410
2019-03-29 17:52:04 -07:00
Nicolas Vasilache abe881d565 NFC - Handle IndexedValue corner case
Implicit conversion don't play nicely in expressions such as:
`C() = A(i) * B(i)`.

Make `C()` return an IndexedValue instead of casting to ValueHandle.
This prevents double capture errors and is useful for the tutorial.

PiperOrigin-RevId: 240863223
2019-03-29 17:51:48 -07:00
River Riddle 01140bd137 Change the muli-return syntax for operations. The name of the operation result now contains the number of results that it refers to if the number of results is greater than 1.
Example:
    %call:2 = call @multi_return() : () -> (f32, i32)
    use(%calltensorflow/mlir#0, %calltensorflow/mlir#1)

This cl also adds parser support for uniquely named result values. This means that a test writer can now write something like:
    %foo, %bar = call @multi_return() : () -> (f32, i32)
    use(%foo, %bar)

Note: The printer will still print the collapsed form.
PiperOrigin-RevId: 240860058
2019-03-29 17:51:32 -07:00