Commit Graph

230 Commits

Author SHA1 Message Date
River Riddle 206e55cc16 NFC: Refactor Module to be value typed.
As with Functions, Module will soon become an operation, which are value-typed. This eases the transition from Module to ModuleOp. A new class, OwningModuleRef is provided to allow for owning a reference to a Module, and will auto-delete the held module on destruction.

PiperOrigin-RevId: 256196193
2019-07-02 16:43:36 -07:00
River Riddle 694975ddbc Standardize the definition and usage of getAllArgAttrs between FuncOp and Function.
PiperOrigin-RevId: 255988352
2019-07-01 11:39:12 -07:00
River Riddle 54cd6a7e97 NFC: Refactor Function to be value typed.
Move the data members out of Function and into a new impl storage class 'FunctionStorage'. This allows for Function to become value typed, which will greatly simplify the transition of Function to FuncOp(given that FuncOp is also value typed).

PiperOrigin-RevId: 255983022
2019-07-01 11:39:00 -07:00
River Riddle 260d3e39ad Standardize and refactor Attribute type printing.
Remove the ability to print an attribute without a type, but allow for attributes to elide the type under certain circumstances. This fixes a bug where attributes within ArrayAttr, and other collection attributes, would never print the type.

PiperOrigin-RevId: 255306974
2019-06-26 18:29:54 -07:00
River Riddle 679a3b4191 Change the attribute dictionary syntax to separate name and value with '='.
The current syntax separates the name and value with ':', but ':' is already overloaded by several other things(e.g. trailing types). This makes the syntax difficult to parse in some situtations:

Old:
  "foo: 10 : i32"

New:
  "foo = 10 : i32"
PiperOrigin-RevId: 255097928
2019-06-25 19:06:34 -07:00
River Riddle 4842b2d42e Modify the syntax of the the ElementsAttrs to print the type as a colon type.
This is the standard syntax for types on operations, and is also already used by IntegerAttr and FloatAttr.

Example:
  dense<5> : tensor<i32>
  dense<[3]> : tensor<1xi32>
PiperOrigin-RevId: 255069157
2019-06-25 16:06:58 -07:00
Andy Davis 91f27d025b Support printing SSA ids in affine.load/store which do not have special names.
PiperOrigin-RevId: 254997746
2019-06-25 10:30:26 -07:00
Andy Davis 3df510bf42 Add parsing/printing for new affine.load and affine.store operations.
The new operations affine.load and affine.store will take composed affine maps by construction.
These operations will eventually replace load and store operations currently used in affine regions and operated on by affine transformation and analysis passes.

PiperOrigin-RevId: 254754048
2019-06-24 13:45:09 -07:00
River Riddle 36b7c2da1d Refactor the location classes to be attributes instead of separate IR classes.
This will allow for locations to be used in the same contexts as attributes. Given that attributes are nullable types, the 'Location' class now represents a non-nullable wrapper around a 'LocationAttr'. This preserves the desired semantics we have for non-optional locations.

PiperOrigin-RevId: 254505278
2019-06-22 09:17:51 -07:00
River Riddle 34cb51743d NFC: Append 'Location' to the end of each the location kinds. This is in preparation for making the location classes attributes instead of separate IR types.
PiperOrigin-RevId: 253860058
2019-06-19 23:07:15 -07:00
Mehdi Amini 74df13fdda Refactor generic op printing: extract a public printFunctionalType() on OpAsmPrinter (NFC)
PiperOrigin-RevId: 253674584
2019-06-19 23:04:59 -07:00
River Riddle 6a0555a875 Refactor SplatElementsAttr to inherit from DenseElementsAttr as opposed to being a separate Attribute type. DenseElementsAttr provides a better internal representation for splat values as well as better API for accessing elements.
PiperOrigin-RevId: 253138287
2019-06-19 23:01:52 -07:00
River Riddle b5a34406a8 Update the Parser to support parsing/printing DenseElementAttrs with a splat value. The syntax for this is the same as 0-D tensors:
dense<tensor<100x100x100xi32>, 10>
  dense<tensor<1x1x1xi64>, -5>

PiperOrigin-RevId: 252907880
2019-06-19 23:00:24 -07:00
River Riddle d8cd96bc8b Refactor DenseElementsAttr to support auto-splatting the dense data on construction. This essentially means that we always auto-detect splat data and only store the minimum amount of data necessary. Support for parsing dense splats, and removing SplatElementsAttr(now that it is redundant) will come in followup cls
PiperOrigin-RevId: 252720561
2019-06-19 22:59:15 -07:00
River Riddle b790a2f396 Remove the explicit attribute kinds for DenseIntElementsAttr and DenseFPElementsAttr in favor of just one DenseElementsAttr. Now that attribute has the ability to define 'classof(Attribute attr)' methods, these derived classes can just be specializations of the main attribute class.
PiperOrigin-RevId: 251948820
2019-06-09 16:22:05 -07:00
Geoffrey Martin-Noble 32de860a09 Make MemRefType subclass ShapedType
MemRefs have the same notion of shape, rank, and fixed element type. This allows us to reuse utilities based on shape for memref.

    All dyn_cast and isa calls for ShapedType have been checked and either modified to explicitly check for vector or tensor, or confirmed to not depend on the result being a vector or tensor.

    Discussion in https://groups.google.com/a/tensorflow.org/forum/#!topic/mlir/cHLoyfGu8y8

--

PiperOrigin-RevId: 250945184
2019-06-01 20:12:40 -07:00
River Riddle 94541563dc Abstract the internal storage of the NamedAttributeList into a new attribute, DictionaryAttr. This attribute maintains a sorted list of NamedAttributes. This will allow for operations/functions to maintain sub dictionaries of attributes.
The syntax is the same as top level attribute dictionaries:
       {sub_dictionary: {fn: @someFn, boolAttr: true}}

--

PiperOrigin-RevId: 250898950
2019-06-01 20:12:01 -07:00
MLIR Team 5a91b9896c Remove "size" property of affine maps.
--

PiperOrigin-RevId: 250572818
2019-06-01 20:09:02 -07:00
River Riddle 1fd1c7a8bb Replace the Function reference methods from the OpAsmParser/OpAsmPrinter with usages of FunctionAttr.
--

PiperOrigin-RevId: 250555680
2019-06-01 20:08:03 -07:00
River Riddle 06734badbc Add operand type iterators to Operation and cleanup usages of operand->getType. This also simplifies some lingering usages of result->getType.
--

PiperOrigin-RevId: 249889174
2019-06-01 20:00:43 -07:00
River Riddle c33862b0ed Refactor FunctionAttr to hold the internal function reference by name instead of pointer. The one downside to this is that the function reference held by a FunctionAttr needs to be explicitly looked up from the parent module. This provides several benefits though:
* There is no longer a need to explicitly remap function attrs.
      - This removes a potentially expensive call from the destructor of Function.
      - This will enable some interprocedural transformations to now run intraprocedurally.
      - This wasn't scalable and forces dialect defined attributes to override
        a virtual function.
    * Replacing a function is now a trivial operation.
    * This is a necessary first step to representing functions as operations.

--

PiperOrigin-RevId: 249510802
2019-06-01 19:56:54 -07:00
Geoffrey Martin-Noble e095f9e72a Also visit memref element type in AsmPrinter
--

PiperOrigin-RevId: 248797935
2019-05-20 13:46:17 -07:00
Geoffrey Martin-Noble 090662c5f3 Rename VectorOrTensorType to ShapedType
This is in preparation for making it also support/be a parent class of MemRefType. MemRefs have similar shape/rank/element semantics and it would be useful to be able to use these same utilities for them.

    This CL should not change any semantics and only change variables, types, string literals, and comments. In follow-up CLs I will prepare all callers to handle MemRef types or remove their dependence on ShapedType.

    Discussion/Rationale in https://groups.google.com/a/tensorflow.org/forum/#!topic/mlir/cHLoyfGu8y8

--

PiperOrigin-RevId: 248476449
2019-05-20 13:43:58 -07:00
River Riddle 8d5bd823b0 Add support for parsing/printing dialect defined attributes. This also adds support for a pretty syntax for dialects attributes that is synonymous with the pretty syntax for dialect types. This cl also adds a new attribute 'OpaqueAttr' that allows for roundtripping attributes attached to unregistered dialects.
Dialect attributes have the following syntax:
       dialect-attribute  ::= `#` dialect-namespace `<` `"` attr-data `"` `>`
       dialect-attribute  ::= `#` alias-name pretty-dialect-sym-body?

--

PiperOrigin-RevId: 248344416
2019-05-20 13:43:05 -07:00
Chris Lattner 9ec6b5b749 Remove some extraneous const qualifiers on Type, and 0b1 -> 1 in tblgen files. (NFC)
--

PiperOrigin-RevId: 248332674
2019-05-20 13:42:56 -07:00
River Riddle cad382406f Refactor NameLoc so that it also holds a child location. This removes the awkward use of CallSiteLoc as a variable usage location.
--

PiperOrigin-RevId: 248014642
2019-05-20 13:40:52 -07:00
River Riddle d39a30626e Use the DialectSymbolRegistry to reserve space in the Attribute::Kind enum to allow for dialects to define attribute kinds. The currently defined attributes kinds have now been moved to StandardAttributes.
--

PiperOrigin-RevId: 247988373
2019-05-20 13:40:03 -07:00
Mehdi Amini 211ceb9fd5 Add override keyword on overidden virtual method (NFC)
Fix clang warnings

--

PiperOrigin-RevId: 247556495
2019-05-10 19:26:59 -07:00
Nicolas Vasilache 07f777f6cd Fix OSS build (Linux)
--

PiperOrigin-RevId: 247472005
2019-05-10 19:26:10 -07:00
River Riddle e088f93f0d Simplify the parser/printer of ConstantOp now that all attributes have types. This has the added benefit of removing type redundancy from the pretty form. As a consequence, IntegerAttr/FloatAttr will now always print the type even if it is i64/f64.
--

PiperOrigin-RevId: 247295828
2019-05-10 19:24:30 -07:00
River Riddle 94afc426e2 Refactor the support for AffineMap and IntegerSet aliases in the parser into more general support for attribute aliases.
`#` alias `=` attribute-value

    This also allows for dialects to define aliases for attributes in the AsmPrinter. The printer supports two types of attribute aliases, 'direct' and 'kind'.

    * Direct aliases are synonymous with the current support for type aliases, i.e. this maps an alias to a specific instance of an attribute.

    // A direct alias ("foo_str") for the string attribute "foo".
    #foo_str = "foo"

    * Kind aliases generates unique names for all instances of a given attribute kind. The generated aliases are of the form: `alias[0-9]+`.

    // A kind alias ("strattr") for all string attributes could generate.
    #strattr0 = "foo"
    #strattr1 = "bar"
    ...
    #strattrN = "baz"

--

PiperOrigin-RevId: 246851916
2019-05-10 19:22:32 -07:00
Alex Zinenko d3380a504f Change syntax of regions in the generic form of operations
The generic form of operations currently supports optional regions to be
    located after the operation type.  As we are going to add a type to each
    region in a leading position in the region syntax, similarly to functions, it
    becomes ambiguous to have regions immediately after the operation type.  Put
    regions between operands the optional list of successors in the generic
    operation syntax and wrap them in parentheses.  The effect on the exisitng IR
    syntax is minimal since only three operations (`affine.for`, `affine.if` and
    `gpu.kernel`) currently use regions.

--

PiperOrigin-RevId: 246787087
2019-05-06 08:29:48 -07:00
Jacques Pienaar 2fe8ae4f6c Fix up some mixed sign warnings.
--

PiperOrigin-RevId: 246614498
2019-05-06 08:28:20 -07:00
River Riddle b2806e197e Remove the ability to directly print affine structures from the OpAsmPrinter. These should go through attributes like most everything else.
--

PiperOrigin-RevId: 246589682
2019-05-06 08:27:32 -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 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
Lei Zhang 82a586e658 Use StringRef::drop_while() to simplify a while loop
--

PiperOrigin-RevId: 244488612
2019-04-23 22:01:35 -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
MLIR Team ee7bdddfb3 Add NewLine for Attribute dump()
--

PiperOrigin-RevId: 243904869
2019-04-18 11:49:06 -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 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
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
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
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 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 af9760fe18 Replace remaining usages of the Instruction class with Operation.
PiperOrigin-RevId: 240777521
2019-03-29 17:50:04 -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 f9d91531df Replace usages of Instruction with Operation in the /IR directory.
This is step 2/N to renaming Instruction to Operation.

PiperOrigin-RevId: 240459216
2019-03-29 17:43:37 -07:00
River Riddle 9ffdc930c0 Rename the Instruction class to Operation. This just renames the class, usages of Instruction will still refer to a typedef in the interim.
This is step 1/N to renaming Instruction to Operation.

PiperOrigin-RevId: 240431520
2019-03-29 17:42:50 -07:00
Chris Lattner e510de0305 Various small cleanups to the code, mostly removing const_cast's.
PiperOrigin-RevId: 240083489
2019-03-29 17:37:58 -07:00