Commit Graph

251 Commits

Author SHA1 Message Date
Eric Schweitz 2225411690 Tweak to the pretty type parser to recognize that `->` is a special token.
Tweak to the pretty type parser to recognize that `->` is a special token that
shouldn't be split into two characters.  This change allows dialect
types to wrap function types as in `!my.ptr_type<(i32) -> i32>`.

Closes tensorflow/mlir#105

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/105 from schweitzpgi:parse-arrow 8b2d768053f419daae5a1a864121a44c4319acbe
PiperOrigin-RevId: 265986240
2019-08-28 13:55:42 -07:00
Chris Lattner 31a003dc3c Introduce the ability for "isolated from above" ops to introduce shadowing
names for the basic block arguments in their body.

PiperOrigin-RevId: 265084627
2019-08-23 10:35:49 -07:00
River Riddle c400c9a1ec Add a hook to the OpAsmDialectInterface to allow providing a special name for the operation result.
This generalizes the current special handling for constant operations(they get named 'cst'/'true'/'false'/etc.)

PiperOrigin-RevId: 264723379
2019-08-21 16:50:59 -07:00
River Riddle 2e59b86541 NFC: Make the ModuleState field in the ModulePrinter optional.
The ModuleState is only used for printing aliases, which is only done when printing the top-level module.

PiperOrigin-RevId: 264664138
2019-08-21 12:16:49 -07:00
River Riddle 7e1af594d2 Move the parser extensions for aliases currently on Dialect to a new OpAsmDialectInterface.
This will allow for adding more hooks for controlling parser behavior without bloating Dialect in the common case. This cl also adds iteration support to the DialectInterfaceCollection.

PiperOrigin-RevId: 264627846
2019-08-21 09:42:02 -07:00
Diego Caballero 9e6cf0d025 Fix build of affine load/store with empty map
tensorflow/mlir#58 fixed and exercised
verification of load/store ops using empty affine maps. Unfortunately,
it didn't exercise the creation of them. This PR addresses that aspect.
It removes the assumption of AffineMap having at least one result and
stores a pointer to MLIRContext as member of AffineMap.

* Add empty map support to affine.store + test
* Move MLIRContext to AffineMapStorage

Closes tensorflow/mlir#74

PiperOrigin-RevId: 264416260
2019-08-20 10:44:18 -07:00
River Riddle 300a2bda34 Refactor DenseElementAttr::getValues methods to return full ranges for splats.
The current implementation only returns one element for the splat case, which often comes as a surprise; leading to subtle/confusing bugs. The new behavior will include an iterate over the full range of elements, as defined by the shaped type, by providing the splat value for each iterator index.

PiperOrigin-RevId: 262756780
2019-08-11 18:17:28 -07:00
River Riddle 1e42954032 NFC: Standardize the terminology used for parent ops/regions/etc.
There are currently several different terms used to refer to a parent IR unit in 'get' methods: getParent/getEnclosing/getContaining. This cl standardizes all of these methods to use 'getParent*'.

PiperOrigin-RevId: 262680287
2019-08-09 20:07:52 -07:00
Alex Zinenko 3b207d3691 Add support for hexadecimal float literals
MLIR does not have support for parsing special floating point values such as
infinities and NaNs.  If programmatically constructed, these values are printed
as NaN and (+-)Inf and cannot be parsed back.  Add parser support for
hexadecimal literals in float attributes, following LLVM IR.  The literal
corresponds to the in-memory representation of the floating point value.
IEEE 754 defines a range of possible values for NaNs, storing the bitwise
representation allows MLIR to properly roundtrip NaNs with different bit values
of significands.

The initial version of this commit was missing support for float literals that
used to be printed in decimal notation as a fallback, but ended up being
printed in hexadecimal format which became the fallback for special values.
The decimal fallback behavior was not exercised by tests.  It is currently
reinstated and tested by the newly added test @f32_potential_precision_loss in
parser.mlir.

PiperOrigin-RevId: 260790900
2019-07-30 14:06:26 -07:00
Mehdi Amini 387638f9c2 Automated rollback of commit fc194a4f22
PiperOrigin-RevId: 260037115
2019-07-25 19:48:17 -07:00
Alex Zinenko fc194a4f22 Add support for hexadecimal float literals
MLIR does not have support for parsing special floating point values such as
infinities and NaNs.  If programmatically constructed, these values are printed
as NaN and (+-)Inf and cannot be parsed back.  Add parser support for
hexadecimal literals in float attributes, following LLVM IR.  The literal
corresponds to the in-memory representation of the floating point value.
IEEE 754 defines a range of possible values for NaNs, storing the bitwise
representation allows MLIR to properly roundtrip NaNs with different bit values
of significands.

PiperOrigin-RevId: 260018802
2019-07-25 14:16:02 -07:00
Lei Zhang 9f498f921b Print boolean values in ElementsAttr as "true"/"false"
We already parse boolean "true"/"false" as ElementsAttr elements.
This CL makes it round-trippable that we are printing the same way.

PiperOrigin-RevId: 258784962
2019-07-19 11:39:35 -07:00
River Riddle 9dbef0bf96 Rename FunctionAttr to SymbolRefAttr.
This allows for the attribute to hold symbolic references to other operations than FuncOp. This also allows for removing the dependence on FuncOp from the base Builder.

PiperOrigin-RevId: 257650017
2019-07-12 08:43:42 -07:00
River Riddle 122cab6770 Refactor the parsing/printing of the top-level module.
This changes the top-level module parser to handle the case where the top-level module is defined with the module operation syntax, i.e:
  module ... {
  }

The printer is also updated to always print the top-level module in this form. This allows for cleanly round-tripping the location and attributes of the top-level module.

PiperOrigin-RevId: 257492069
2019-07-12 08:42:56 -07:00
River Riddle 1b247a1247 Drop the trailing newline from the FuncOp syntax.
The ModulePrinter prints the newline now for children of the top-level module. This also fixes the location printing for functions as the location used to be printed on a different line.

PiperOrigin-RevId: 257447633
2019-07-12 08:42:35 -07:00
River Riddle e0dd5f98c4 Relax the restriction that Modules cannot contain operations producing results.
This was an arbitrary restriction caused by the way that modules were printed. Now that that has been fixed, this restriction can be removed.

PiperOrigin-RevId: 257240329
2019-07-09 11:50:13 -07:00
River Riddle 89bc449cee Standardize the value numbering in the AsmPrinter.
Change the AsmPrinter to number values breadth-first so that values in adjacent regions can have the same name. This allows for ModuleOp to contain operations that produce results. This also standardizes the special name of region entry arguments to "arg[0-9+]" now that Functions are also operations.

PiperOrigin-RevId: 257225069
2019-07-09 10:41:00 -07:00
River Riddle ce502af9cd NFC: Remove the various "::getFunction" methods.
These methods assume that a function is a valid builtin top-level operation, and removing these methods allows for decoupling FuncOp and IR/. Utility "getParentOfType" methods have been added to Operation/OpState to allow for querying the first parent operation of a given type.

PiperOrigin-RevId: 257018913
2019-07-08 12:40:08 -07:00
Jacques Pienaar b3e7bb0498 Add missing overrides.
PiperOrigin-RevId: 256995548
2019-07-08 12:39:28 -07:00
River Riddle 474e354179 NFC: Remove Region::getContainingFunction as Functions are now Operations.
PiperOrigin-RevId: 256579717
2019-07-04 13:23:10 -07:00
River Riddle e7d594bb1c Replace the implementation of Function and Module with FuncOp and ModuleOp.
This is an important step in allowing for the top-level of the IR to be extensible. FuncOp and ModuleOp contain all of the necessary functionality, while using the existing operation infrastructure. As an interim step, many of the usages of Function and Module, including the name, will remain the same. In the future, many of these will be relaxed to allow for many different types of top-level operations to co-exist.

PiperOrigin-RevId: 256427100
2019-07-03 14:37:18 -07:00
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