Commit Graph

146 Commits

Author SHA1 Message Date
Smit Hinsu c9b0540b9c Make identity cast operations with the same operand and result types legal
Instead, fold such operations. This way callers don't need to conditionally create cast operations depending on if a value already has the target type.

    Also, introduce areCastCompatible to allow cast users to verify that the generated op will be valid before creating the operation.

    TESTED with unit tests

--

PiperOrigin-RevId: 245606133
2019-05-06 08:19:37 -07:00
River Riddle 1316db3baa Add support for a NoneType.
none-type ::= `none`

    The `none` type is a unit type, i.e. a type with exactly one possible value, where its value does not have a defined dynamic representation.

--

PiperOrigin-RevId: 245599248
2019-05-06 08:19:20 -07:00
River Riddle a8ef8fa182 Update the wording of a comment in the LangRef now that multi-threading is no longer an anticipated feature.
--

PiperOrigin-RevId: 245586656
2019-05-06 08:19:03 -07:00
Alex Zinenko 54ee709e88 Add LLVM Conversion Tutorial
Add a tutorial document explaining how to define a conversion from the Linalg
    dialect to the LLVM IR dialect, bypassing the Affine dialect.  It defines a
    dynamic representation for a range and a view for the sake of type conversion.
    Operation conversion becomes straightforward given the dynamic representation.
    The code in the tutorial is better structured and better document that what we
    currently have in the example, which will be updated separately.

--

PiperOrigin-RevId: 245498394
2019-05-06 08:18:47 -07:00
River Riddle 22ad45a7aa Add support for Unit Attributes.
A unit attribute is an attribute that represents a value of `unit` type. The
    `unit` type allows only one value forming a singleton set. This attribute value
    is used to represent attributes that only have meaning from their existence.

    One example of such an attribute could be the `swift.self` attribute. This attribute indicates that a function parameter is the self/context
    parameter. It could be represented as a boolean attribute(true or false), but a
    value of false doesn't really bring any value. The parameter either is the
    self/context or it isn't.

    ```mlir {.mlir}
    // A unit attribute defined with the `unit` value specifier.
    func @verbose_form(i1 {unitAttr : unit})

    // A unit attribute can also be defined without the `unit` value specifier.
    func @simple_form(i1 {unitAttr})
    ```

--

PiperOrigin-RevId: 245254045
2019-05-06 08:16:39 -07:00
Rob Suderman 69cdceae73 GetMemRefType failed on 0-D tensors. Loosened check to allow tensors with shape
{}.

--

PiperOrigin-RevId: 245104548
2019-05-06 08:16:23 -07:00
MLIR Team ff6804c045 Minor typo in integer type definition.
--

PiperOrigin-RevId: 244854008
2019-04-23 22:02:58 -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
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
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
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
Nicolas Vasilache dfd98764f7 Start a Linalg doc
--

PiperOrigin-RevId: 242622278
2019-04-11 10:51:34 -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
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
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
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
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 465ef55088 Tidy up the links in the documents and fix any broken ones.
--

PiperOrigin-RevId: 242127863
2019-04-07 18:19:46 -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
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
Mehdi Amini f0a328b6d5 Chapter 3 for Toy tutorial: introduction of a dialect
--

PiperOrigin-RevId: 241849162
2019-04-03 19:22:32 -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
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
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
Mehdi Amini c2e9ab8ef1 Fix path for the examples in Toy tutorial Ch1
PiperOrigin-RevId: 241643625
2019-04-02 18:15:38 -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 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
Mehdi Amini 38b71d6b84 Initial version for chapter 1 of the Toy tutorial
--

PiperOrigin-RevId: 241549247
2019-04-02 13:40:06 -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
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
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 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
River Riddle 213b8d4d3b Rename InstOperand to OpOperand.
PiperOrigin-RevId: 240814651
2019-03-29 17:50:41 -07:00
MLIR Team b8874c679f Small edit for clarity. ("Zero dimensions" reads to me as "rank of zero.")
PiperOrigin-RevId: 240664300
2019-03-29 17:48:44 -07:00
River Riddle 3a845be7d1 Add support for multi-threaded pass timing.
When multi-threading is enabled in the pass manager the meaning of the display
slightly changes. First, a new timing column is added, `User Time`, that
displays the total time spent across all threads. Secondly, the `Wall Time`
column displays the longest individual time spent amongst all of the threads.
This means that the `Wall Time` column will continue to give an indicator on the
perceived time, or clock time, whereas the `User Time` will display the total
cpu time.

Example:

$ mlir-opt foo.mlir -experimental-mt-pm -cse -canonicalize -convert-to-llvmir -pass-timing

===-------------------------------------------------------------------------===
                      ... Pass execution timing report ...
===-------------------------------------------------------------------------===
  Total Execution Time: 0.0078 seconds

   ---User Time---   ---Wall Time---  --- Name ---
   0.0175 ( 88.3%)     0.0055 ( 70.4%)  Function Pipeline
   0.0018 (  9.3%)     0.0006 (  8.1%)    CSE
   0.0013 (  6.3%)     0.0004 (  5.8%)      (A) DominanceInfo
   0.0017 (  8.7%)     0.0006 (  7.1%)    FunctionVerifier
   0.0128 ( 64.6%)     0.0039 ( 50.5%)    Canonicalizer
   0.0011 (  5.7%)     0.0004 (  4.7%)    FunctionVerifier
   0.0004 (  2.1%)     0.0004 (  5.2%)  ModuleVerifier
   0.0010 (  5.3%)     0.0010 ( 13.4%)  LLVMLowering
   0.0009 (  4.3%)     0.0009 ( 11.0%)  ModuleVerifier
   0.0198 (100.0%)     0.0078 (100.0%)  Total

PiperOrigin-RevId: 240636269
2019-03-29 17:47:41 -07:00
Alex Zinenko e2f9079a71 LLVM IR Conversion: support zero-dimensional memrefs
The spec allows zero-dimensional memrefs to exist and treats them essentially
as single-element buffers.  Unlike single-dimensional memrefs of static shape
<1xTy>, zero-dimensional memrefs do not require indices to access the only
element they store.  Add support of zero-dimensional memrefs to the LLVM IR
conversion.  In particular, such memrefs are converted into bare pointers, and
accesses to them are converted to bare loads and stores, without the overhead
of `getelementptr %buffer, 0`.

PiperOrigin-RevId: 240579456
2019-03-29 17:45:26 -07:00
Alex Zinenko 5c285f228c LLVM IR Conversion: keep LLVM dialect types as is during conversion
When converting to the LLVM IR Dialect, it is possible for the input IR to
contain LLVM IR Dialect operation and/or types, for example, some functions may
have been coverted to the LLVM IR Dialect already, or may have been created
using this dialect directly.  Make sure that type conversion keeps LLVM IR
Dialect types unmodified and does not error out.  Operations are already kept
as is.

PiperOrigin-RevId: 240574972
2019-03-29 17:45:11 -07:00
Alex Zinenko 5a5bba0279 Introduce affine terminator
Due to legacy reasons (ML/CFG function separation), regions in affine control
flow operations require contained blocks not to have terminators.  This is
inconsistent with the notion of the block and may complicate code motion
between regions of affine control operations and other regions.

Introduce `affine.terminator`, a special terminator operation that must be used
to terminate blocks inside affine operations and transfers the control back to
he region enclosing the affine operation.  For brevity and readability reasons,
allow `affine.for` and `affine.if` to omit the `affine.terminator` in their
regions when using custom printing and parsing format.  The custom parser
injects the `affine.terminator` if it is missing so as to always have it
present in constructed operations.

Update transformations to account for the presence of terminator.  In
particular, most code motion transformation between loops should leave the
terminator in place, and code motion between loops and non-affine blocks should
drop the terminator.

PiperOrigin-RevId: 240536998
2019-03-29 17:44:24 -07:00
River Riddle 832567b379 NFC: Rename the 'for' operation in the AffineOps dialect to 'affine.for' and set the namespace of the AffineOps dialect to 'affine'.
PiperOrigin-RevId: 240165792
2019-03-29 17:39:03 -07:00
River Riddle 9c6e92360c NFC: Rename the 'if' operation in the AffineOps dialect to 'affine.if'.
PiperOrigin-RevId: 240071154
2019-03-29 17:36:53 -07:00
Chris Lattner 5246bceee0 Now that ConstOpPointer is gone, we can change the various methods generated by
tblgen be non-const.  This requires introducing some const_cast's at the
moment, but those (and lots more stuff) will disappear in subsequent patches.

This significantly simplifies those patches because the various tblgen op emitters
get adjusted.

PiperOrigin-RevId: 239954566
2019-03-29 17:33:45 -07:00