summaryrefslogtreecommitdiffstats
path: root/mlir/tools/mlir-tblgen/RewriterGen.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [mlir] NFC: Remove Value::operator* and Value::operator-> now that Value is ↵River Riddle2020-01-111-5/+5
| | | | | | | | | | properly value-typed. Summary: These were temporary methods used to simplify the transition. Reviewed By: antiagainst Differential Revision: https://reviews.llvm.org/D72548
* [mlir] Compilation fix: use LLVM_ATTRIBUTE_UNUSED following ↵Alexandre Ganea2020-01-031-6/+2
| | | | | | 6656e961c08393c3949412ef945ade0272b66fca Differential Revision: https://reviews.llvm.org/D72124
* [mlir][Linalg] Extend generic ops to allow tensorsNicolas Vasilache2020-01-021-3/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This diff adds support to allow `linalg.generic` and `linalg.indexed_generic` to take tensor input and output arguments. The subset of output tensor operand types must appear verbatim in the result types after an arrow. The parser, printer and verifier are extended to accomodate this behavior. The Linalg operations now support variadic ranked tensor return values. This extension exhibited issues with the current handling of NativeCall in RewriterGen.cpp. As a consequence, an explicit cast to `SmallVector<Value, 4>` is added in the proper place to support the new behavior (better suggestions are welcome). Relevant cleanups and name uniformization are applied. Relevant invalid and roundtrip test are added. Reviewers: mehdi_amini, rriddle, jpienaar, antiagainst, ftynse Subscribers: burmako, shauheen, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D72022
* [mlir] Fix compilation warningsAlexandre Ganea2020-01-011-2/+5
| | | | | | Fixes: - (MSVC) F:\llvm-project\mlir\lib\Dialect\Linalg\Analysis\DependenceAnalysis.cpp(103): warning C4551: function call missing argument list - (Clang) tools\mlir\lib\Dialect\SPIRV\SPIRVCanonicalization.inc(232,1): warning: unused function 'populateWithGenerated' [-Wunused-function]
* Add an __attribute__((unused)) to populateWithGenerated since it mightEric Christopher2019-12-261-1/+2
| | | | not be used where defined and is autogenerated.
* NFC: Replace ValuePtr with Value and remove it now that Value is value-typed.River Riddle2019-12-231-4/+4
| | | | | | ValuePtr was a temporary typedef during the transition to a value-typed Value. PiperOrigin-RevId: 286945714
* Adjust License.txt file to use the LLVM licenseMehdi Amini2019-12-231-13/+4
| | | | PiperOrigin-RevId: 286906740
* NFC: Introduce new ValuePtr/ValueRef typedefs to simplify the transition to ↵River Riddle2019-12-221-10/+10
| | | | | | | | | | Value being value-typed. This is an initial step to refactoring the representation of OpResult as proposed in: https://groups.google.com/a/tensorflow.org/g/mlir/c/XXzzKhqqF_0/m/v6bKb08WCgAJ This change will make it much simpler to incrementally transition all of the existing code to use value-typed semantics. PiperOrigin-RevId: 286844725
* Remove unused variable (fix warning) NFCMehdi Amini2019-12-161-2/+1
| | | | PiperOrigin-RevId: 285799680
* minor spelling tweaksKazuaki Ishizaki2019-12-061-3/+3
| | | | | | | Closes tensorflow/mlir#290 COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/290 from kiszk:spelling_tweaks_201912 9d9afd16a723dd65754a04698b3976f150a6054a PiperOrigin-RevId: 284169681
* [ODS] Generate builders taking unwrapped value and defaults for attributesLei Zhang2019-12-021-2/+2
| | | | | | | | | | | | | | | | | | Existing builders generated by ODS require attributes to be passed in as mlir::Attribute or its subclasses. This is okay foraggregate- parameter builders, which is primarily to be used by programmatic C++ code generation; it is inconvenient for separate-parameter builders meant to be called in manually written C++ code because it requires developers to wrap raw values into mlir::Attribute by themselves. This CL extends to generate additional builder methods that take raw values for attributes and handles the wrapping in the builder implementation. Additionally, if an attribute appears late in the arguments list and has a default value, the default value is supplied in the declaration if possible. PiperOrigin-RevId: 283355919
* [DRR] Introduce `$_` to ignore op argument matchLei Zhang2019-12-021-2/+5
| | | | | | | | Right now op argument matching in DRR is position-based, meaning we need to specify N arguments for an op with N ODS-declared argument. This can be annoying when we don't want to capture all the arguments. `$_` is to remedy the situation. PiperOrigin-RevId: 283339992
* Add support for AttrSizedOperandSegments/AttrSizedResultSegmentsLei Zhang2019-11-251-3/+3
| | | | | | | | | | | | | | | | | 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
* Use aggregate-parameter builder for ops having autogen type-deduction builderLei Zhang2019-11-151-62/+182
| | | | | | | | | | | | | | | | | | | | | | Thus far DRR always invokes the separate-parameter builder (i.e., requiring a separate parameter for each result-type/operand/attribute) for creating ops, no matter whether we can auto-generate a builder with type-deduction ability or not. This CL changes the path for ops that we can auto-generate type-deduction builders, i.e., with SameOperandsAndResultType/FirstAttrDerivedResultType traits. Now they are going through a aggregate-parameter builder (i.e., requiring one parameter for all result-types/operands/attributes). attributes.) It is expected this approach will be more friendly for future shape inference function autogen and calling those autogen'd shape inference function without excessive packing and repacking operand/attribute lists. Also, it would enable better support for creating ops with optional attributes because we are not required to provide an Attribute() as placeholder for an optional attribute anymore. PiperOrigin-RevId: 280654800
* [DRR] Allow interleaved operands and attributesLei Zhang2019-10-211-38/+51
| | | | | | | | Previously DRR assumes attributes to appear after operands. This was the previous requirements on ODS, but that has changed some time ago. Fix DRR to also support interleaved operands and attributes. PiperOrigin-RevId: 275983485
* [DRR] Address GCC warning by wrapping for statement body with {}Lei Zhang2019-10-201-1/+2
| | | | | | | Otherwise, we'll see the following warning when compiling with GCC 8: warning: this ?for? clause does not guard... [-Wmisleading-indentation] PiperOrigin-RevId: 275735925
* [DRR] Use eraseOp() to replace no-result opsLei Zhang2019-10-181-10/+18
| | | | PiperOrigin-RevId: 275475229
* Fix RewriterGen to support using NativeCodeCall as auxiliary patternLei Zhang2019-10-171-7/+13
| | | | | | | | | NativeCodeCall is handled differently than normal op creation in RewriterGen (because its flexibility). It will only be materialized to output stream if it is used. But when using it for auxiliary patterns, we still want the side effect even if it is not replacing matched root op's results. PiperOrigin-RevId: 275265467
* Add LLVM_DEBUG in RewritersGen.cpp and Pattern.cppLei Zhang2019-10-171-4/+48
| | | | | | | | | It's usually hard to understand what went wrong if mlir-tblgen crashes on some input. This CL adds a few useful LLVM_DEBUG statements so that we can use mlir-tblegn -debug to figure out the culprit for a crash. PiperOrigin-RevId: 275253532
* Fix typos, NFC.Christian Sigg2019-10-041-2/+2
| | | | PiperOrigin-RevId: 272851237
* Make result ops generated output deterministicJacques Pienaar2019-09-261-1/+7
| | | | | | Sort the result ops reported in lexographical order. PiperOrigin-RevId: 271426258
* Support variadic ops in declarative rewrite rulesLei Zhang2019-08-211-91/+151
| | | | | | | | | | | | | | | | | | | | | | | | This CL extends declarative rewrite rules to support matching and generating ops with variadic operands/results. For this, the generated `matchAndRewrite()` method for each pattern now are changed to * Use "range" types for the local variables used to store captured values (`operand_range` for operands, `ArrayRef<Value *>` for values, *Op for results). This allows us to have a unified way of handling both single values and value ranges. * Create local variables for each operand for op creation. If the operand is variadic, then a `SmallVector<Value*>` will be created to collect all values for that operand; otherwise a `Value*` will be created. * Use a collective result type builder. All result types are specified via a single parameter to the builder. We can use one result pattern to replace multiple results of the matched root op. When that happens, it will require specifying types for multiple results. Add a new collective-type builder. PiperOrigin-RevId: 264588559
* NFC: Don't assume that all operation traits are within the 'OpTrait::' ↵River Riddle2019-08-191-3/+4
| | | | | | | | namespace. This places an unnecessary restriction that all traits are within this namespace. PiperOrigin-RevId: 264212000
* NFC: Refactoring PatternSymbolResolver into SymbolInfoMapLei Zhang2019-08-091-247/+91
| | | | | | | | | | | | | | | In declarative rewrite rules, a symbol can be bound to op arguments or results in the source pattern, and it can be bound to op results in the result pattern. This means given a symbol in the pattern, it can stands for different things: op operand, op attribute, single op result, op result pack. We need a better way to model this complexity so that we can handle according to the specific kind a symbol corresponds to. Created SymbolInfo class for maintaining the information regarding a symbol. Also created a companion SymbolInfoMap class for a map of such symbols, providing insertion and querying depending on use cases. PiperOrigin-RevId: 262675515
* Emit matchAndRewrite() for declarative rewrite rulesLei Zhang2019-08-061-115/+107
| | | | | | | | | Previously we are emitting separate match() and rewrite() methods, which requires conveying a match state struct in a unique_ptr across these two methods. Changing to emit matchAndRewrite() simplifies the picture. PiperOrigin-RevId: 261906804
* NFC: Implement OwningRewritePatternList as a class instead of a using directive.River Riddle2019-08-051-2/+1
| | | | | | This allows for proper forward declaration, as opposed to leaking the internal implementation via a using directive. This also allows for all pattern building to go through 'insert' methods on the OwningRewritePatternList, replacing uses of 'push_back' and 'RewriteListBuilder'. PiperOrigin-RevId: 261816316
* Replace the verifyUnusedValue directive with HasNoUseOf constraintLei Zhang2019-08-011-44/+9
| | | | | | | | | verifyUnusedValue is a bit strange given that it is specified in a result pattern but used to generate match statements. Now we are able to support multi-result ops better, we can retire it and replace it with a HasNoUseOf constraint. This reduces the number of mechanisms. PiperOrigin-RevId: 261166863
* Fix support for auxiliary ops in declarative rewrite rulesLei Zhang2019-07-311-48/+110
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We allow to generate more ops than what are needed for replacing the matched root op. Only the last N static values generated are used as replacement; the others serve as auxiliary ops/values for building the replacement. With the introduction of multi-result op support, an op, if used as a whole, may be used to replace multiple static values of the matched root op. We need to consider this when calculating the result range an generated op is to replace. For example, we can have the following pattern: ```tblgen def : Pattern<(ThreeResultOp ...), [(OneResultOp ...), (OneResultOp ...), (OneResultOp ...)]>; // Two op to replace all three results def : Pattern<(ThreeResultOp ...), [(TwoResultOp ...), (OneResultOp ...)]>; // One op to replace all three results def : Pat<(ThreeResultOp ...), (ThreeResultOp ...)>; def : Pattern<(ThreeResultOp ...), [(AuxiliaryOp ...), (ThreeResultOp ...)]>; ``` PiperOrigin-RevId: 261017235
* RewriterGen: properly handle zero-result opsAlex Zinenko2019-07-301-3/+3
| | | | | | | | | RewriterGen was emitting invalid C++ code if the pattern required to create a zero-result operation due to the absence of a special case that would avoid generating a spurious comma. Handle this case. Also add rewriter tests for zero-argument operations. PiperOrigin-RevId: 260576998
* Support referencing a single value generated by a matched multi-result opLei Zhang2019-07-261-18/+22
| | | | | | | | It's quite common that we want to put further constraints on the matched multi-result op's specific results. This CL enables referencing symbols bound to source op with the `__N` syntax. PiperOrigin-RevId: 260122401
* [TableGen] Support creating multi-result ops in result patternsLei Zhang2019-07-031-30/+93
| | | | | | | | | | This CL introduces a new syntax for creating multi-result ops and access their results in result patterns. Specifically, if a multi-result op is unbound or bound to a name without a trailing `__N` suffix, it will act as a value pack and expand to all its values. If a multi-result op is bound to a symbol with `__N` suffix, only the N-th result will be extracted and used. PiperOrigin-RevId: 256465208
* [ODS] Introduce IntEnumAttrLei Zhang2019-07-011-1/+6
| | | | | | | | | | | | | | | | | | | In ODS, right now we use StringAttrs to emulate enum attributes. It is suboptimal if the op actually can and wants to store the enum as a single integer value; we are paying extra cost on storing and comparing the attribute value. This CL introduces a new enum attribute subclass that are backed by IntegerAttr. The downside with IntegerAttr-backed enum attributes is that the assembly form now uses integer values, which is less obvious than the StringAttr-backed ones. However, that can be remedied by defining custom assembly form with the help of the conversion utility functions generated via EnumsGen. Choices are given to the dialect writers to decide which one to use for their enum attributes. PiperOrigin-RevId: 255935542
* Parenthesize match expression to avoid operator precedence issuesMLIR Team2019-06-271-1/+1
| | | | PiperOrigin-RevId: 255435454
* Print proper message saying variadic ops are not supported in RewriterGenLei Zhang2019-06-191-10/+17
| | | | | | | | Support for ops with variadic operands/results will come later; but right now a proper message helps to avoid deciphering confusing error messages later in the compilation stage. PiperOrigin-RevId: 254071820
* Fix correspondence between trait names in ODS and C++ class names.Jacques Pienaar2019-06-011-2/+4
| | | | | | | | Make the correspondence between the ODS and C++ side clearer. -- PiperOrigin-RevId: 250211194
* Use fused location for rewritten ops in generated rewrites.Jacques Pienaar2019-06-011-2/+18
| | | | | | | | This does tracks the location by recording all the ops in the source pattern and using the fused location for the transformed op. Track the locations via the rewrite state which is a bit heavy weight, in follow up to change to matchAndRewrite this will be addressed (and need for extra array go away). -- PiperOrigin-RevId: 249986555
* Add support to RewritePattern for specifying the potential operations ↵River Riddle2019-06-011-3/+26
| | | | | | | | that can be generated during a rewrite. This will enable analyses to start understanding the possible effects of applying a rewrite pattern. -- PiperOrigin-RevId: 249936309
* Fix incorrect result type inference for nested tuples & remove hacky ↵Jacques Pienaar2019-06-011-7/+3
| | | | | | | | | | const case. Builders can be further refined but wanted to address bug where the result type was used beyond the first depth. -- PiperOrigin-RevId: 249936004
* Add pattern file location to generated code to trace origin of pattern.Jacques Pienaar2019-06-011-0/+13
| | | | | | -- PiperOrigin-RevId: 249734666
* Replace Operation::isa with llvm::isa.River Riddle2019-05-201-1/+1
| | | | | | -- PiperOrigin-RevId: 247789235
* [TableGen] Return base attribute's name for anonymous ↵Lei Zhang2019-05-101-1/+1
| | | | | | | | OptionalAttr/DefaultValuedAttr -- PiperOrigin-RevId: 247693280
* Replace dyn_cast<> with isa<> when the returned value is unused (NFC)Mehdi Amini2019-05-101-2/+2
| | | | | | | | Fix a gcc warning. -- PiperOrigin-RevId: 247669360
* Fix up some mixed sign warnings.Jacques Pienaar2019-05-061-6/+6
| | | | | | -- PiperOrigin-RevId: 246614498
* [TableGen] Support multiple variadic operands/resultsLei Zhang2019-05-061-1/+1
| | | | | | | | | | | | | | | | Certain ops can have multiple variadic operands/results, e.g., `tf.DynamicStitch`. Even if an op has only one variadic operand/result, it is not necessarily the very last one, e.g., `tf.RaggedGather`. This CL enhances TableGen subsystem to be able to represent such cases. In order to deduce the operand/result value range for each variadic operand, currently we only support variadic operands/results all of the same size. So two new traits, `SameVariadicOperandSize` and `SameVariadicResultSize` are introduced. -- PiperOrigin-RevId: 245310628
* [TableGen] Clean up comments regarding op and resultLei Zhang2019-04-231-3/+3
| | | | | | | | | | 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
* [TableGen] Unify cOp and tAttr into NativeCodeCallLei Zhang2019-04-231-52/+25
| | | | | | | | | 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
* [TableGen] Capture bound source ops in PatternStateLei Zhang2019-04-231-32/+24
| | | | | | | | | | | | 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
* NFC: Simplify named attribute in TableGen generatorsSmit Hinsu2019-04-181-1/+1
| | | | | | | | | | | 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
* [TableGen] Use `tgfmt` to format various predicates and rewrite rulesLei Zhang2019-04-181-21/+31
| | | | | | | | | | 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
* [TableGen] Support naming rewrite rulesLei Zhang2019-04-111-8/+21
| | | | | | -- PiperOrigin-RevId: 242909061
OpenPOWER on IntegriCloud