summaryrefslogtreecommitdiffstats
path: root/mlir/lib/TableGen/Predicate.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Adjust License.txt file to use the LLVM licenseMehdi Amini2019-12-231-13/+4
| | | | PiperOrigin-RevId: 286906740
* Fix minor spelling tweaks (NFC)Kazuaki Ishizaki2019-10-201-2/+2
| | | | | | Closes tensorflow/mlir#177 PiperOrigin-RevId: 275692653
* [TableGen] Support array attribute subclasses and constraintsLei Zhang2019-04-051-1/+26
| | | | | | | | | | To support automatically constraint composition of ArrayAttr, a new predicate combiner, Concat, is introduced. It prepends a prefix and appends a postfix to a child predicate's final predicate string. -- PiperOrigin-RevId: 242121186
* [TableGen] Consolidate constraint related conceptsLei Zhang2019-03-291-1/+1
| | | | | | | | | | | | | | | | | | | 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] Fix infinite loop in SubstLeaves substitutionLei Zhang2019-03-291-4/+7
| | | | | | | | | | | Previously we have `auto pos = std::string::find(...) != std::string::npos` as if condition to control substring substitution. Instead of the position for the found substring, `pos` will be a boolean value indicating found nor not. Then used as the replace start position, we were always replacing starting from 0 or 1. If the replaced substring also has the pattern to be matched, we'll see an infinite loop. PiperOrigin-RevId: 235504681
* TableGen: implement predicate tree and basic simplificationAlex Zinenko2019-03-291-3/+302
| | | | | | | | | | | | | | | | | | | | | | A recent change in TableGen definitions allowed arbitrary AND/OR predicate compositions at the cost of removing known-true predicate simplification. Introduce a more advanced simplification mechanism instead. In particular, instead of folding predicate C++ expressions directly in TableGen, keep them as is and build a predicate tree in TableGen C++ library. The predicate expression-substitution mechanism, necessary to implement complex predicates for nested classes such as `ContainerType`, is replaced by a dedicated predicate. This predicate appears in the predicate tree and can be used for tree matching and separation. More specifically, subtrees defined below such predicate may be subject to different transformations than those that appear above. For example, a subtree known to be true above the substitution predicate is not necessarily true below it. Use the predicate tree structure to eliminate known-true and known-false predicates before code emission, as well as to collapse AND and OR predicates if their value can be deduced based on the value of one child. PiperOrigin-RevId: 229605997
* TableGen: extract TypeConstraints from TypeAlex Zinenko2019-03-291-50/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | MLIR has support for type-polymorphic instructions, i.e. instructions that may take arguments of different types. For example, standard arithmetic operands take scalars, vectors or tensors. In order to express such instructions in TableGen, we need to be able to verify that a type object satisfies certain constraints, but we don't need to construct an instance of this type. The existing TableGen definition of Type requires both. Extract out a TypeConstraint TableGen class to define restrictions on types. Define the Type TableGen class as a subclass of TypeConstraint for consistency. Accept records of the TypeConstraint class instead of the Type class as values in the Arguments class when defining operators. Replace the predicate logic TableGen class based on conjunctive normal form with the predicate logic classes allowing for abitrary combinations of predicates using Boolean operators (AND/OR/NOT). The combination is implemented using simple string rewriting of C++ expressions and, therefore, respects the short-circuit evaluation order. No logic simplification is performed at the TableGen level so all expressions must be valid C++. Maintaining CNF using TableGen only would have been complicated when one needed to introduce top-level disjunction. It is also unclear if it could lead to a significantly simpler emitted C++ code. In the future, we may replace inplace predicate string combination with a tree structure that can be simplified in TableGen's C++ driver. Combined, these changes allow one to express traits like ArgumentsAreFloatLike directly in TableGen instead of relying on C++ trait classes. PiperOrigin-RevId: 229398247
* Avoid redundant predicate checking in type matching.Jacques Pienaar2019-03-291-1/+18
| | | | | | | | Expand type matcher template generator to consider a set of predicates that are known to hold. This avoids inserting redundant checking for trivially true predicates (for example predicate that hold according to the op definition). This only targets predicates that trivially holds and does not attempt any logic equivalence proof. PiperOrigin-RevId: 228880468
* Put Operator and PredCNF into the tblgen namespaceLei Zhang2019-03-291-3/+3
| | | | PiperOrigin-RevId: 228429130
* Add tblgen::Type to wrap around TableGen Type defsLei Zhang2019-03-291-2/+20
| | | | | | | | | | This CL added a tblgen::Type class to wrap around raw TableGen Record getValue*() calls on Type defs, which will provide a nicer API for handling TableGen Record. The PredCNF class is also updated to work together with tblgen::Type. PiperOrigin-RevId: 228429090
* Verify type of operands match those specifed in op registry.Jacques Pienaar2019-03-291-0/+50
Expand type to include matcher predicates. Use CNF form to allow specifying combinations of constraints for type. The matching call for the type is used to verify the construction of the operation as well as in rewrite pattern generation. The matching initially includes redundant checks (e.g., even if the operand of the op is guaranteed to satisfy some requirement, it is still checked during matcher generation for now). As well as some of the traits specified now check what the generated code already checks. Some of the traits can be removed in future as the verify method will include the relevant checks based on the op definition already. More work is needed for variadic operands. CNF form is used so that in the follow up redundant checks in the rewrite patterns could be omitted (e.g., when matching a F32Tensor, one does not need to verify that op X's operand 0 is a Tensor if that is guaranteed by op X's definition). The alternative was to have single matcher function specified, but this would not allow for reasoning about what attributes already hold (at the level of PredAtoms). Use this new operand type restrictions to rewrite BiasAdd with floating point operands as declarative pattern. PiperOrigin-RevId: 227991412
OpenPOWER on IntegriCloud