summaryrefslogtreecommitdiffstats
path: root/mlir/lib/TableGen/Pattern.cpp
Commit message (Collapse)AuthorAgeFilesLines
* NFC: Replace ValuePtr with Value and remove it now that Value is value-typed.River Riddle2019-12-231-1/+1
| | | | | | 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-1/+1
| | | | | | | | | | 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
* [DRR] Introduce `$_` to ignore op argument matchLei Zhang2019-12-021-1/+2
| | | | | | | | 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
* [ODS] Fix operation argument population to avoid crashLei Zhang2019-11-141-0/+1
| | | | | | | | | | The `Operator` class keeps an `arguments` field, which contains pointers to `operands` and `attributes` elements. Thus it must be populated after `operands` and `attributes` are finalized so to have stable pointers. SmallVector may re-allocate when still having new elements added, which will invalidate pointers. PiperOrigin-RevId: 280466896
* Fix segfault when no symbol is given to an constraint operandLei Zhang2019-10-301-1/+7
| | | | | | | This fixed the segfault when we see the following pattern: Pat<(...), (...), [(... 1, 2, 3), ...]> PiperOrigin-RevId: 277544300
* Fix minor spelling tweaks (NFC)Kazuaki Ishizaki2019-10-201-1/+1
| | | | | | Closes tensorflow/mlir#177 PiperOrigin-RevId: 275692653
* [DRR] Allow capturing and referencing no-result opsLei Zhang2019-10-171-0/+7
| | | | | | | | | | Previously when we bind a symbol to an op in DRR, it means to capture the op's result(s) and later references will be expanded to result(s). This means for ops without result, we are replacing the symbol with nothing. This CL treats non-result op capturing and referencing as a special case to mean the op itself. PiperOrigin-RevId: 275269702
* Add LLVM_DEBUG in RewritersGen.cpp and Pattern.cppLei Zhang2019-10-171-10/+53
| | | | | | | | | 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
* Remove unused variables and methods to address compiler warningsLei Zhang2019-09-251-0/+1
| | | | PiperOrigin-RevId: 271256784
* Support variadic ops in declarative rewrite rulesLei Zhang2019-08-211-16/+87
| | | | | | | | | | | | | | | | | | | | | | | | 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
* Change from llvm::make_unique to std::make_uniqueJacques Pienaar2019-08-171-1/+1
| | | | | | | | Switch to C++14 standard method as llvm::make_unique has been removed ( https://reviews.llvm.org/D66259). Also mark some targets as c++14 to ease next integrates. PiperOrigin-RevId: 263953918
* Add unreachable to avoid GCC -Wreturn-type warningjpienaar2019-08-131-0/+3
| | | | | | | | GCC warns of control reaching end of non-void function (-Wreturn-type). Closes tensorflow/mlir#75 PiperOrigin-RevId: 263214601
* NFC: Refactoring PatternSymbolResolver into SymbolInfoMapLei Zhang2019-08-091-35/+184
| | | | | | | | | | | | | | | 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
* Replace the verifyUnusedValue directive with HasNoUseOf constraintLei Zhang2019-08-011-7/+2
| | | | | | | | | 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-14/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Support referencing a single value generated by a matched multi-result opLei Zhang2019-07-261-2/+3
| | | | | | | | 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
* [ODS] Introduce IntEnumAttrLei Zhang2019-07-011-1/+1
| | | | | | | | | | | | | | | | | | | 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
* Add support to RewritePattern for specifying the potential operations ↵River Riddle2019-06-011-0/+4
| | | | | | | | 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
* Add pattern file location to generated code to trace origin of pattern.Jacques Pienaar2019-06-011-0/+14
| | | | | | -- PiperOrigin-RevId: 249734666
* Remove unnecessary C++ specifier in CPP files. NFC.Jacques Pienaar2019-05-201-1/+1
| | | | | | | | These are only required in .h files to disambiguate between C and C++ header files. -- PiperOrigin-RevId: 248219135
* Fix up some mixed sign warnings.Jacques Pienaar2019-05-061-6/+6
| | | | | | -- PiperOrigin-RevId: 246614498
* Add Dialect in op definition to capture prefix and documentation.Jacques Pienaar2019-05-061-0/+1
| | | | | | | | | | | | Enables specifying the documentation for dialect along with defining the ops of the dialect. The doc generator will be expanded in follow up to emit the documentation in the autogenerated files. This is precursor to allowing common base for all ops in a dialect. All the dialect documentation is super sparse and just added as placeholder. I was tempted (and started) to move ConstantOp to be generated too, but this will be easier post adding extra_methods, so deferring until then. -- PiperOrigin-RevId: 245759984
* [TableGen] Unify cOp and tAttr into NativeCodeCallLei Zhang2019-04-231-28/+12
| | | | | | | | | 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-14/+6
| | | | | | | | | | | | 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
* [TableGen] Allocate `Operator` object on heap in `RecordOperatorMap`Lei Zhang2019-04-181-1/+5
| | | | | | | | | | | | | | | | Iterators for a `llvm::DenseMap` can be invalidated when an insertion occurs. In Pattern's `collectBoundArguments()`, we recursively handle all nested DAG nodes and grow the the `RecordOperatorMap`, while retaining a reference. This can cause the reference to be invalid and the program to behave randomly. Allocate each `Operator` object specifically to solve this issue. Also, `llvm::DenseMap` is a great way to map pointers to pointers, or map other small types to each other. This avoids placing the `Operator` object directly into the map. -- PiperOrigin-RevId: 243281486
* [TableGen] Make sure op in pattern has the same number of arguments as ↵Lei Zhang2019-04-081-31/+33
| | | | | | | | | | | | definition When an op in the source pattern specifies more arguments than its definition, we will have out-of-bound query for op arguments from the definition. That will cause crashes. This change fixes it. -- PiperOrigin-RevId: 242548415
* Minor fixes on the typo/naming/style in the Pattern.cpp fileFeng Liu2019-04-011-5/+7
| | | | | | -- PiperOrigin-RevId: 241341334
* [TableGen] Add EnumAttrCase and EnumAttrLei Zhang2019-04-011-13/+20
| | | | | | | | | | This CL adds EnumAttr as a general mechanism for modelling enum attributes. Right now it is using StringAttr under the hood since MLIR does not have native support for enum attributes. -- PiperOrigin-RevId: 241334043
* remove the const quantifier before temp variableFeng Liu2019-03-291-1/+1
| | | | PiperOrigin-RevId: 240997262
* [TableGen] Support benefit score in pattern definition.Feng Liu2019-03-291-0/+10
| | | | | | | | A integer number can be specified in the pattern definition and used as the adjustment to the default benefit score in the generated rewrite pattern C++ definition. PiperOrigin-RevId: 240994192
* [TableGen] Consolidate constraint related conceptsLei Zhang2019-03-291-71/+24
| | | | | | | | | | | | | | | | | | | Previously we have multiple mechanisms to specify op definition and match constraints: TypeConstraint, AttributeConstraint, Type, Attr, mAttr, mAttrAnyOf, mPat. These variants are not added because there are so many distinct cases we need to model; essentially, they are all carrying a predicate. It's just an artifact of implementation. It's quite confusing for users to grasp these variants and choose among them. Instead, as the OpBase TableGen file, we need to strike to provide an unified mechanism. Each dialect has the flexibility to define its own aliases if wanted. This CL removes mAttr, mAttrAnyOf, mPat. A new base class, Constraint, is added. Now TypeConstraint and AttrConstraint derive from Constraint. Type and Attr further derive from TypeConstraint and AttrConstraint, respectively. Comments are revised and examples are added to make it clear how to use constraints. PiperOrigin-RevId: 240125076
* [TableGen] Support nested dag attributes arguments in the result patternFeng Liu2019-03-291-1/+16
| | | | | | | | | | Add support to create a new attribute from multiple attributes. It extended the DagNode class to represent attribute creation dag. It also changed the RewriterGen::emitOpCreate method to support this nested dag emit. An unit test is added. PiperOrigin-RevId: 238090229
* [TableGen] Support multiple result patternsLei Zhang2019-03-291-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | This CL added the ability to generate multiple ops using multiple result patterns, with each of them replacing one result of the matched source op. Specifically, the syntax is ``` def : Pattern<(SourceOp ...), [(ResultOp1 ...), (ResultOp2 ...), (ResultOp3 ...)]>; ``` Assuming `SourceOp` has three results. Currently we require that each result op must generate one result, which can be lifted later when use cases arise. To help with cases that certain output is unused and we don't care about it, this CL also introduces a new directive: `verifyUnusedValue`. Checks will be emitted in the `match()` method to make sure if the corresponding output is not unused, `match()` returns with `matchFailure()`. PiperOrigin-RevId: 237513904
* Add pattern constraints.Jacques Pienaar2019-03-291-3/+81
| | | | | | Enable matching pattern only if constraint is met. Start with type constraints and more general C++ constraints. PiperOrigin-RevId: 233830768
* [TableGen] Assign created ops to variables and rewrite with ↵Lei Zhang2019-03-291-1/+5
| | | | | | | | | | | | | PatternRewriter::replaceOp() Previously we were using PatternRewrite::replaceOpWithNewOp() to both create the new op inline and rewrite the matched op. That does not work well if we want to generate multiple ops in a sequence. To support that, this CL changed to assign each newly created op to a separate variable. This CL also refactors how PatternEmitter performs the directive dispatch logic. PiperOrigin-RevId: 233206819
* [TableGen] Use tblgen::DagLeaf to model DAG argumentsLei Zhang2019-03-291-6/+66
| | | | | | | | | | This CL added a tblgen::DagLeaf wrapper class with several helper methods for handling DAG arguments. It helps to refactor the rewriter generation logic to be more higher level. This CL also added a tblgen::ConstantAttr wrapper class for constant attributes. PiperOrigin-RevId: 232050683
* Add fallback to native code op builder specification for patterns.Jacques Pienaar2019-03-291-0/+11
| | | | | | | | This allow for arbitrarily complex builder patterns which is meant to cover initial cases while the modelling is improved and long tail cases/cases for which expanding the DSL would result in worst overall system. NFC just sorting the emit replace methods alphabetical in the class and file body. PiperOrigin-RevId: 231890352
* Add tblgen::Pattern to model Patterns defined in TableGenLei Zhang2019-03-291-0/+133
Similar to other tblgen:: abstractions, tblgen::Pattern hides the native TableGen API and provides a nicer API that is more coherent with the TableGen definitions. PiperOrigin-RevId: 231285143
OpenPOWER on IntegriCloud