summaryrefslogtreecommitdiffstats
path: root/mlir/lib/IR
Commit message (Collapse)AuthorAgeFilesLines
...
* Print out large elementsattr's such that they are parseable.Sean Silva2019-12-041-15/+27
| | | | | | | | | | | I found that when running crash reproducers, the elided elementsattr's would prevent parsing the IR repro. I found myself manually going and replacing the "..." with some valid IR. With this change, we now print elided attrs as `opaque<"", "0xDEADBEEF">` to clearly delineate them as being elided while still being parseable. PiperOrigin-RevId: 283781806
* Verifier: Better error message in case of successor operand mismatch.Sean Silva2019-12-031-6/+9
| | | | | | In particular, print the successor number in the diagnostic. PiperOrigin-RevId: 283585084
* Add linkage support to LLVMFuncOpAlex Zinenko2019-12-031-1/+2
| | | | | | | | | A recent commit introduced the Linkage attribute to the LLVM dialect and used it in the Global Op. Also use it in LLVMFuncOp. As per LLVM Language Reference, if the linkage attribute is omitted, the function is assumed to have external linkage. PiperOrigin-RevId: 283493299
* NFC: Update std.subview op to use AttrSizedOperandSegmentsLei Zhang2019-12-021-0/+8
| | | | | | This turns a few manually written helper methods into auto-generated ones. PiperOrigin-RevId: 283339617
* Fix redundant convert and use NamedAttributeList as valueJacques Pienaar2019-11-291-6/+6
| | | | | | | | * Had leftover call that would result in converting to dictionary attr before being implicitedly converted back to NamedAttributeList; * NamedAttributeList is value typed, so don't use const reference; PiperOrigin-RevId: 283072576
* Split out FunctionLike printing/parsing into FunctionImplementation.{h,cpp}Alex Zinenko2019-11-282-3/+4
| | | | | | | | | | | Helper utilies for parsing and printing FunctionLike Ops are only relevant to the implementation of the Op, not its definition. They depend on OpImplementation.h and increase the inclusion footprint of FunctionSupport.h, and do so only to provide some utilities in the "impl" namespace. Move them to a separate files, similarly to OpDefinition/OpImplementation distinction, and make only Op implementations use them while keeping headers cleaner. NFC. PiperOrigin-RevId: 282964556
* Add create method that takes equivalent of OperationState with ↵Jacques Pienaar2019-11-261-6/+19
| | | | | | | | | | | | | NamedAttributeList This method is close to creating an OperationState first and then unpacking it but avoids creating the OperationState and takes a NamedAttributeList for attributes rather than array of NamedAttribute (to enable reusing an already created NamedAttributeList). Reuse this new method via create that takes OperationState. I'll update inferReturnTypes in follow up to also take NamedAttributeList and so a build method that uses both inferReturnTypes and create can reuse the same list. PiperOrigin-RevId: 282651642
* Add support for AttrSizedOperandSegments/AttrSizedResultSegmentsLei Zhang2019-11-251-0/+41
| | | | | | | | | | | | | | | | | Certain operations can have multiple variadic operands and their size relationship is not always known statically. For such cases, we need a per-op-instance specification to divide the operands into logical groups or segments. This can be modeled by attributes. This CL introduces C++ trait AttrSizedOperandSegments for operands and AttrSizedResultSegments for results. The C++ trait just guarantees such size attribute has the correct type (1D vector) and values (non-negative), etc. It serves as the basis for ODS sugaring that with ODS argument declarations we can further verify the number of elements match the number of ODS-declared operands and we can generate handy getter methods. PiperOrigin-RevId: 282467075
* Introduce gpu.funcAlex Zinenko2019-11-251-41/+61
| | | | | | | | | | | | | | | | | | Introduce a new function-like operation to the GPU dialect to provide a placeholder for the execution semantic description and to add support for GPU memory hierarchy. This aligns with the overall goal of the dialect to expose the common abstraction layer for GPU devices, in particular by providing an MLIR unit of semantics (i.e. an operation) for memory modeling. This proposal has been discussed in the mailing list: https://groups.google.com/a/tensorflow.org/d/msg/mlir/RfXNP7Hklsc/MBNN7KhjAgAJ As decided, the "convergence" aspect of the execution model will be factored out into a new discussion and therefore is not included in this commit. This commit only introduces the operation but does not hook it up with the remaining flow. The intention is to develop the new flow while keeping the old flow operational and do the switch in a simple, separately reversible commit. PiperOrigin-RevId: 282357599
* Make isValidSymbol more powerfulUday Bondhugula2019-11-221-0/+6
| | | | | | | | | | | | | | | | | The check in isValidSymbol, as far as a DimOp result went, checked if the dim op was on a top-level memref. However, any alloc'ed, view, or subview memref would be fine as long as the corresponding dimension of that memref is either a static one or was in turn created using a valid symbol in the case of dynamic dimensions. Reported-by: Jose Gomez Signed-off-by: Uday Bondhugula <uday@polymagelabs.com> Closes tensorflow/mlir#252 COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/252 from bondhugula:symbol 7b57dc394df9375e651f497231c6e4525a32a662 PiperOrigin-RevId: 282097114
* Don't force newline before function attributesAlex Zinenko2019-11-211-5/+1
| | | | | | | | | | | Due to legacy reasons, a newline character followed by two spaces was always inserted before the attributes of the function Op in pretty form. This breaks formatting when functions are nested in some other operations. Don't print the newline and just put the attributes on the same line, which is also more consistent with module Op. Line breaking aware of indentation can be introduced separately into the parser if deemed useful. PiperOrigin-RevId: 281721793
* Add multi-level DCE pass.Sean Silva2019-11-201-0/+15
| | | | | | | | | This is a simple multi-level DCE pass that operates pretty generically on the IR. Its key feature compared to the existing peephole dead op folding that happens during canonicalization is being able to delete recursively dead cycles of the use-def graph, including block arguments. PiperOrigin-RevId: 281568202
* Add a new OpAsmOpInterface to allow for ops to directly hook into the ↵River Riddle2019-11-202-54/+141
| | | | | | | | | | | | | | | | | | | | | | | AsmPrinter. This interface provides more fine-grained hooks into the AsmPrinter than the dialect interface, allowing for operations to define the asm name to use for results directly on the operations themselves. The hook is also expanded to enable defining named result "groups". Get a special name to use when printing the results of this operation. The given callback is invoked with a specific result value that starts a result "pack", and the name to give this result pack. To signal that a result pack should use the default naming scheme, a None can be passed in instead of the name. For example, if you have an operation that has four results and you want to split these into three distinct groups you could do the following: setNameFn(getResult(0), "first_result"); setNameFn(getResult(1), "middle_results"); setNameFn(getResult(3), ""); // use the default numbering. This would print the operation as follows: %first_result, %middle_results:2, %0 = "my.op" ... PiperOrigin-RevId: 281546873
* Do not emit aliases when printing local formJacques Pienaar2019-11-131-2/+10
| | | | | | Expand local scope printing to skip printing aliases as aliases are printed out at the top of a module and may not be part of the output generated by local scope print. PiperOrigin-RevId: 280278617
* Deprecate linalg.subview in favor of std.subviewNicolas Vasilache2019-11-131-0/+2
| | | | | | | | | | | This CL uses the now standard std.subview in linalg. Two shortcuts are currently taken to allow this port: 1. the type resulting from a view is currently degraded to fully dynamic to pass the SubViewOp verifier. 2. indexing into SubViewOp may access out of bounds since lowering to LLVM does not currently enforce it by construction. These will be fixed in subsequent commits after discussions. PiperOrigin-RevId: 280250129
* Add FuncOp::eraseArgumentSean Silva2019-11-131-0/+35
| | | | | | | | | | | | This is a quite complex operation that users are likely to attempt to write themselves and get wrong (citation: users=me). Ideally, we could pull this into FunctionLike, but for now, the FunctionType rewriting makes it FuncOp specific. We would need some hook for rewriting the function type (which for LLVM's func op, would need to rewrite the underlying LLVM type). PiperOrigin-RevId: 280234164
* Rename the current parseSymbolName to parseOptionalSymbolNameRiver Riddle2019-11-132-7/+5
| | | | | | The current implementation silently fails if the '@' identifier isn't present, making it similar to the 'optional' parse methods. This change renames the current implementation to 'Optional' and adds a new 'parseSymbolName' that emits an error. PiperOrigin-RevId: 280214610
* NFC: Change DictionaryAttr::get(StringRef) to use binary search instead of a ↵River Riddle2019-11-121-5/+7
| | | | | | | | linear scan. The elements of a DictionaryAttr are guaranteed to be sorted by name, so we can use a more efficient lookup when searching for an attribute. PiperOrigin-RevId: 280035488
* Add an option to print an operation if a diagnostic is emitted on itRiver Riddle2019-11-121-6/+40
| | | | | | It is often helpful to inspect the operation that the error/warning/remark/etc. originated from, especially in the context of debugging or in the case of a verifier failure. This change adds an option 'mlir-print-op-on-diagnostic' that attaches the operation as a note to any diagnostic that is emitted on it via Operation::emit(Error|Warning|Remark). In the case of an error, the operation is printed in the generic form. PiperOrigin-RevId: 280021438
* Add a printer flag to use local scope when printing IR.River Riddle2019-11-122-7/+21
| | | | | | This causes the AsmPrinter to use a local value numbering when printing the IR, allowing for the printer to be used safely in a local context, e.g. to ensure thread-safety when printing the IR. This means that the IR printing instrumentation can also be used during multi-threading when module-scope is disabled. Operation::dump and DiagnosticArgument(Operation*) are also updated to always print local scope, as this is the most common use case when debugging. PiperOrigin-RevId: 279988203
* Add support for nested symbol references.River Riddle2019-11-115-9/+72
| | | | | | | | | | | | | | | | | | This change allows for adding additional nested references to a SymbolRefAttr to allow for further resolving a symbol if that symbol also defines a SymbolTable. If a referenced symbol also defines a symbol table, a nested reference can be used to refer to a symbol within that table. Nested references are printed after the main reference in the following form: symbol-ref-attribute ::= symbol-ref-id (`::` symbol-ref-id)* Example: module @reference { func @nested_reference() } my_reference_op @reference::@nested_reference Given that SymbolRefAttr is now more general, the existing functionality centered around a single reference is moved to a derived class FlatSymbolRefAttr. Followup commits will add support to lookups, rauw, etc. for scoped references. PiperOrigin-RevId: 279860501
* Fix asm printer for affine exprUday Bondhugula2019-11-071-1/+4
| | | | | | | | | | | - fixes tensorflow/mlir#201 Signed-off-by: Uday Bondhugula <uday@polymagelabs.com> Closes tensorflow/mlir#204 COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/204 from bondhugula:printfix 3f8a5b65391f45598258b2735fecaa409fbde848 PiperOrigin-RevId: 279115720
* Replace some remnant uses of "inst" with "op".Sean Silva2019-11-063-29/+27
| | | | PiperOrigin-RevId: 278961676
* NFC: Remove an extra space when printing the 'attributes' prefix before a ↵River Riddle2019-11-051-1/+1
| | | | | | dictionary. PiperOrigin-RevId: 278795313
* Add (parse|print)OptionalAttrDictWithKeyword hooks to simplify parsing ↵River Riddle2019-11-053-27/+27
| | | | | | | | attribute dictionaries with regions. Many operations with regions add an additional 'attributes' prefix when printing the attribute dictionary to differentiate it from the region body. This leads to duplicated logic for detecting when to actually print the attribute dictionary. PiperOrigin-RevId: 278747681
* NFC: Rename parseOptionalAttributeDict -> parseOptionalAttrDict to match the ↵River Riddle2019-11-053-6/+6
| | | | | | name of the print method. PiperOrigin-RevId: 278696668
* Add a PatternRewriter hook to merge blocks, and use it to support for ↵River Riddle2019-11-051-0/+29
| | | | | | | | | | | | | | | | | | | folding branches. A pattern rewriter hook, mergeBlock, is added that allows for merging the operations of one block into the end of another. This is used to support a canonicalization pattern for branch operations that folds the branch when the successor has a single predecessor(the branch block). Example: ^bb0: %c0_i32 = constant 0 : i32 br ^bb1(%c0_i32 : i32) ^bb1(%x : i32): return %x : i32 becomes: ^bb0: %c0_i32 = constant 0 : i32 return %c0_i32 : i32 PiperOrigin-RevId: 278677825
* Remove the need for passing a location to parseAttribute/parseType.River Riddle2019-11-011-7/+7
| | | | | | | | Now that a proper parser is passed to these methods, there isn't a need to explicitly pass a source location. The source location can be recovered from the parser as necessary. This removes the need to explicitly decode an SMLoc in the case where we don't need to, which can be expensive. This requires adding some basic nesting support to the parser for supporting nested parsers to allow for remapping source locations of the nested parsers to the top level parser for accurate diagnostics. This is due to the fact that the attribute and type parsers use different source buffers than the top level parser, as they may be represented in string form. PiperOrigin-RevId: 278014858
* Add DialectAsmParser/Printer classes to simplify dialect attribute and type ↵River Riddle2019-11-012-27/+78
| | | | | | | | | | | | | | parsing. These classes are functionally similar to the OpAsmParser/Printer classes and provide hooks for parsing attributes/tokens/types/etc. This change merely sets up the base infrastructure and updates the parser hooks, followups will add hooks as needed to simplify existing handrolled dialect parsers. This has various different benefits: *) Attribute/Type parsing is much simpler to define. *) Dialect attributes/types that contain other attributes/types can now use aliases. *) It provides a 'spec' with which we may use in the future to auto-generate parsers/printers. *) Error messages emitted by attribute/type parsers can provide character exact locations rather than "beginning of the string" PiperOrigin-RevId: 278005322
* Add a utility accessor 'has_single_element' for ranges.River Riddle2019-10-301-1/+1
| | | | | | This provides an easy way to check if a range has a single element. PiperOrigin-RevId: 277544647
* Add support for replacing all uses of a symbol.River Riddle2019-10-241-37/+165
| | | | | | This requires reconstructing the attribute dictionary of each operation containing a use. PiperOrigin-RevId: 276520544
* Add @below and @above directives to verify-diagnostics.River Riddle2019-10-231-7/+39
| | | | | | | | | | | | | | | | | | This simplifies defining expected-* directives when there are multiple that apply to the next or previous line. @below applies the directive to the next non-designator line, i.e. the next line that does not contain an expected-* designator. @above applies to the previous non designator line. Examples: // Expect an error on the next line that does not contain a designator. // expected-remark@below {{remark on function below}} // expected-remark@below {{another remark on function below}} func @bar(%a : f32) // Expect an error on the previous line that does not contain a designator. func @baz(%a : f32) // expected-remark@above {{remark on function above}} // expected-remark@above {{another remark on function above}} PiperOrigin-RevId: 276369085
* NFC: Elide the value of a UnitAttr within nested attribute dictionaries.River Riddle2019-10-211-1/+7
| | | | | | This matches the behavior of the top level attribute dictionary. PiperOrigin-RevId: 275879828
* Add a Symbol trait to simplify defining operations that represent symbols.River Riddle2019-10-212-1/+9
| | | | | | This trait provides accessors for the name, symbol use list methods, verification, with more to be added. PiperOrigin-RevId: 275864554
* Fix minor spelling tweaks (NFC)Kazuaki Ishizaki2019-10-204-4/+4
| | | | | | Closes tensorflow/mlir#177 PiperOrigin-RevId: 275692653
* NFC: Cleanup the implementation of walkSymbolUses.River Riddle2019-10-181-66/+35
| | | | | | Refactor the implementation to be much cleaner by adding a `make_second_range` utility to walk the `second` value of a range of pairs. PiperOrigin-RevId: 275598985
* Add support for function result attributes.Sean Silva2019-10-182-15/+105
| | | | | | | | | | | | | | | | | | | | | | This allows dialect-specific attributes to be attached to func results. (or more specifically, FunctionLike ops). For example: ``` func @f() -> (i32 {my_dialect.some_attr = 3}) ``` This attaches my_dialect.some_attr with value 3 to the first result of func @f. Another more complex example: ``` func @g() -> (i32, f32 {my_dialect.some_attr = "foo", other_dialect.some_other_attr = [1,2,3]}, i1) ``` Here, the second result has two attributes attached. PiperOrigin-RevId: 275564165
* NFC: Remove trivial builder get methods.River Riddle2019-10-173-71/+5
| | | | | | These don't add any value, and some are even more restrictive than the respective static 'get' method. PiperOrigin-RevId: 275391240
* Allow '_' when pretty printing dialect symbolsLei Zhang2019-10-171-2/+2
| | | | | | | | | '_' is used frequently enough as the separator of words in symbols. We should allow it in dialect symbols when considering pretty printing. Also updated LangRef.md regarding pretty form. PiperOrigin-RevId: 275312494
* NFC: Update VectorOrTensor -> ShapedGeoffrey Martin-Noble2019-10-161-1/+1
| | | | | | This was missed when the type was renamed. PiperOrigin-RevId: 275082588
* Add support for PatternRewriter::eraseOp.River Riddle2019-10-161-0/+8
| | | | | | This hook is useful when an operation is known to be dead, and no replacement values make sense. PiperOrigin-RevId: 275052756
* AsmPrinter: avoid unused-variable warningAlex Zinenko2019-10-151-1/+1
| | | | | | | | The value defined in a loop was not being used and the function producing it re-evaluated instead. Use the value to avoid both the warning and the re-evaluation. PiperOrigin-RevId: 274794459
* NFC: Replace usages of Value::getKind with explicit isa/casts.River Riddle2019-10-142-29/+23
| | | | | | It is more idiomatic to use the llvm::cast infrastructure for checking the type of a value. PiperOrigin-RevId: 274684945
* Pre-allocate space for results from a regex match that uses 3 match strings.MLIR Team2019-10-091-1/+1
| | | | | | | That space is 4 StringRefs, not 3, because element 0 of the match always contains the entire source string. PiperOrigin-RevId: 273875606
* Assert that region is not cloned into itself.Christian Sigg2019-10-091-0/+1
| | | | PiperOrigin-RevId: 273707291
* Allow dynamic but ranked types in ops with SameOperandsAndResultShape and ↵Smit Hinsu2019-10-082-25/+39
| | | | | | | | | | SameOperandsAndResultType traits Currently SameOperandsAndResultShape trait allows operands to have tensor<*xf32> and tensor<2xf32> but doesn't allow tensor<?xf32> and tensor<10xf32>. Also, use the updated shape compatibility helper function in TensorCastOp::areCastCompatible method. PiperOrigin-RevId: 273658336
* Update the symbol utility methods to handle the case of unknown operations.River Riddle2019-10-081-24/+68
| | | | | | This enhances the symbol table utility methods to handle the case where an unknown operation may define a symbol table. When walking symbols, we now collect all symbol uses before allowing the user to iterate. This prevents the user from assuming that all symbols are actually known before performing a transformation. PiperOrigin-RevId: 273651963
* Add support for parsing/printing non bare-identifier SymbolRefs.River Riddle2019-10-083-4/+46
| | | | | | The restriction that symbols can only have identifier names is arbitrary, and artificially limits the names that a symbol may have. This change adds support for parsing and printing symbols that don't fit in the 'bare-identifier' grammar by printing the reference in quotes, e.g. @"0_my_reference" can now be used as a symbol name. PiperOrigin-RevId: 273644768
* Add a PatternRewriter hook for cloning a region into another.River Riddle2019-10-081-0/+19
| | | | | | This is similar to the `inlineRegionBefore` hook, except the original blocks are unchanged. The region to be cloned *must* not have been modified during the conversion process at the point of cloning, i.e. it must belong an operation that has yet to be converted, or the operation that is currently being converted. PiperOrigin-RevId: 273622533
* Add support for walking the uses of a symbol.River Riddle2019-10-081-0/+157
| | | | | | MLIR uses symbol references to model references to many global entities, such as functions/variables/etc. Before this change, there is no way to actually reason about the uses of such entities. This change provides a walker for symbol references(via SymbolTable::walkSymbolUses), as well as 'use_empty' support(via SymbolTable::symbol_use_empty). It also resolves some deficiencies in the LangRef definition of SymbolRefAttr, namely the restrictions on where a SymbolRefAttr can be stored, ArrayAttr and DictionaryAttr, and the relationship with operations containing the SymbolTable trait. PiperOrigin-RevId: 273549331
OpenPOWER on IntegriCloud