MLIR  21.0.0git
Pattern.h
Go to the documentation of this file.
1 //===- Pattern.h - Pattern wrapper class ------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Pattern wrapper class to simplify using TableGen Record defining a MLIR
10 // Pattern.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef MLIR_TABLEGEN_PATTERN_H_
15 #define MLIR_TABLEGEN_PATTERN_H_
16 
17 #include "mlir/Support/LLVM.h"
18 #include "mlir/TableGen/Argument.h"
19 #include "mlir/TableGen/EnumInfo.h"
20 #include "mlir/TableGen/Operator.h"
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/ADT/Hashing.h"
23 #include "llvm/ADT/StringMap.h"
24 #include "llvm/ADT/StringSet.h"
25 
26 #include <optional>
27 #include <unordered_map>
28 
29 namespace llvm {
30 class DagInit;
31 class Init;
32 class Record;
33 } // namespace llvm
34 
35 namespace mlir {
36 namespace tblgen {
37 
38 // Mapping from TableGen Record to Operator wrapper object.
39 //
40 // We allocate each wrapper object in heap to make sure the pointer to it is
41 // valid throughout the lifetime of this map. This is important because this map
42 // is shared among multiple patterns to avoid creating the wrapper object for
43 // the same op again and again. But this map will continuously grow.
46 
47 class Pattern;
48 
49 // Wrapper class providing helper methods for accessing TableGen DAG leaves
50 // used inside Patterns. This class is lightweight and designed to be used like
51 // values.
52 //
53 // A TableGen DAG construct is of the syntax
54 // `(operator, arg0, arg1, ...)`.
55 //
56 // This class provides getters to retrieve `arg*` as tblgen:: wrapper objects
57 // for handy helper methods. It only works on `arg*`s that are not nested DAG
58 // constructs.
59 class DagLeaf {
60 public:
61  explicit DagLeaf(const llvm::Init *def) : def(def) {}
62 
63  // Returns true if this DAG leaf is not specified in the pattern. That is, it
64  // places no further constraints/transforms and just carries over the original
65  // value.
66  bool isUnspecified() const;
67 
68  // Returns true if this DAG leaf is matching an operand. That is, it specifies
69  // a type constraint.
70  bool isOperandMatcher() const;
71 
72  // Returns true if this DAG leaf is matching an attribute. That is, it
73  // specifies an attribute constraint.
74  bool isAttrMatcher() const;
75 
76  // Returns true if this DAG leaf is wrapping native code call.
77  bool isNativeCodeCall() const;
78 
79  // Returns true if this DAG leaf is specifying a constant attribute.
80  bool isConstantAttr() const;
81 
82  // Returns true if this DAG leaf is specifying an enum case.
83  bool isEnumCase() const;
84 
85  // Returns true if this DAG leaf is specifying a string attribute.
86  bool isStringAttr() const;
87 
88  // Returns this DAG leaf as a constraint. Asserts if fails.
90 
91  // Returns this DAG leaf as an constant attribute. Asserts if fails.
93 
94  // Returns this DAG leaf as an enum case.
95  // Precondition: isEnumCase()
96  EnumCase getAsEnumCase() const;
97 
98  // Returns the matching condition template inside this DAG leaf. Assumes the
99  // leaf is an operand/attribute matcher and asserts otherwise.
100  std::string getConditionTemplate() const;
101 
102  // Returns the native code call template inside this DAG leaf.
103  // Precondition: isNativeCodeCall()
104  StringRef getNativeCodeTemplate() const;
105 
106  // Returns the number of values will be returned by the native helper
107  // function.
108  // Precondition: isNativeCodeCall()
109  int getNumReturnsOfNativeCode() const;
110 
111  // Returns the string associated with the leaf.
112  // Precondition: isStringAttr()
113  std::string getStringAttr() const;
114 
115  void print(raw_ostream &os) const;
116 
117 private:
119  const void *getAsOpaquePointer() const { return def; }
120 
121  // Returns true if the TableGen Init `def` in this DagLeaf is a DefInit and
122  // also a subclass of the given `superclass`.
123  bool isSubClassOf(StringRef superclass) const;
124 
125  const llvm::Init *def;
126 };
127 
128 // Wrapper class providing helper methods for accessing TableGen DAG constructs
129 // used inside Patterns. This class is lightweight and designed to be used like
130 // values.
131 //
132 // A TableGen DAG construct is of the syntax
133 // `(operator, arg0, arg1, ...)`.
134 //
135 // When used inside Patterns, `operator` corresponds to some dialect op, or
136 // a known list of verbs that defines special transformation actions. This
137 // `arg*` can be a nested DAG construct. This class provides getters to
138 // retrieve `operator` and `arg*` as tblgen:: wrapper objects for handy helper
139 // methods.
140 //
141 // A null DagNode contains a nullptr and converts to false implicitly.
142 class DagNode {
143 public:
144  explicit DagNode(const llvm::DagInit *node) : node(node) {}
145 
146  // Implicit bool converter that returns true if this DagNode is not a null
147  // DagNode.
148  operator bool() const { return node != nullptr; }
149 
150  // Returns the symbol bound to this DAG node.
151  StringRef getSymbol() const;
152 
153  // Returns the operator wrapper object corresponding to the dialect op matched
154  // by this DAG. The operator wrapper will be queried from the given `mapper`
155  // and created in it if not existing.
156  Operator &getDialectOp(RecordOperatorMap *mapper) const;
157 
158  // Returns the number of operations recursively involved in the DAG tree
159  // rooted from this node.
160  int getNumOps() const;
161 
162  // Returns the number of immediate arguments to this DAG node.
163  int getNumArgs() const;
164 
165  // Returns true if the `index`-th argument is a nested DAG construct.
166  bool isNestedDagArg(unsigned index) const;
167 
168  // Gets the `index`-th argument as a nested DAG construct if possible. Returns
169  // null DagNode otherwise.
170  DagNode getArgAsNestedDag(unsigned index) const;
171 
172  // Gets the `index`-th argument as a DAG leaf.
173  DagLeaf getArgAsLeaf(unsigned index) const;
174 
175  // Returns the specified name of the `index`-th argument.
176  StringRef getArgName(unsigned index) const;
177 
178  // Returns true if this DAG construct means to replace with an existing SSA
179  // value.
180  bool isReplaceWithValue() const;
181 
182  // Returns whether this DAG represents the location of an op creation.
183  bool isLocationDirective() const;
184 
185  // Returns whether this DAG is a return type specifier.
186  bool isReturnTypeDirective() const;
187 
188  // Returns true if this DAG node is wrapping native code call.
189  bool isNativeCodeCall() const;
190 
191  // Returns whether this DAG is an `either` specifier.
192  bool isEither() const;
193 
194  // Returns whether this DAG is an `variadic` specifier.
195  bool isVariadic() const;
196 
197  // Returns true if this DAG node is an operation.
198  bool isOperation() const;
199 
200  // Returns the native code call template inside this DAG node.
201  // Precondition: isNativeCodeCall()
202  StringRef getNativeCodeTemplate() const;
203 
204  // Returns the number of values will be returned by the native helper
205  // function.
206  // Precondition: isNativeCodeCall()
207  int getNumReturnsOfNativeCode() const;
208 
209  void print(raw_ostream &os) const;
210 
211 private:
212  friend class SymbolInfoMap;
214  const void *getAsOpaquePointer() const { return node; }
215 
216  const llvm::DagInit *node; // nullptr means null DagNode
217 };
218 
219 // A class for maintaining information for symbols bound in patterns and
220 // provides methods for resolving them according to specific use cases.
221 //
222 // Symbols can be bound to
223 //
224 // * Op arguments and op results in the source pattern and
225 // * Op results in result patterns.
226 //
227 // Symbols can be referenced in result patterns and additional constraints to
228 // the pattern.
229 //
230 // For example, in
231 //
232 // ```
233 // def : Pattern<
234 // (SrcOp:$results1 $arg0, %arg1),
235 // [(ResOp1:$results2), (ResOp2 $results2 (ResOp3 $arg0, $arg1))]>;
236 // ```
237 //
238 // `$argN` is bound to the `SrcOp`'s N-th argument. `$results1` is bound to
239 // `SrcOp`. `$results2` is bound to `ResOp1`. $result2 is referenced to build
240 // `ResOp2`. `$arg0` and `$arg1` are referenced to build `ResOp3`.
241 //
242 // If a symbol binds to a multi-result op and it does not have the `__N`
243 // suffix, the symbol is expanded to represent all results generated by the
244 // multi-result op. If the symbol has a `__N` suffix, then it will expand to
245 // only the N-th *static* result as declared in ODS, and that can still
246 // corresponds to multiple *dynamic* values if the N-th *static* result is
247 // variadic.
248 //
249 // This class keeps track of such symbols and resolves them into their bound
250 // values in a suitable way.
252 public:
253  explicit SymbolInfoMap(ArrayRef<SMLoc> loc) : loc(loc) {}
254 
255  // Class for information regarding a symbol.
256  class SymbolInfo {
257  public:
258  // Returns a type string of a variable.
259  std::string getVarTypeStr(StringRef name) const;
260 
261  // Returns a string for defining a variable named as `name` to store the
262  // value bound by this symbol.
263  std::string getVarDecl(StringRef name) const;
264 
265  // Returns a string for defining an argument which passes the reference of
266  // the variable.
267  std::string getArgDecl(StringRef name) const;
268 
269  // Returns a variable name for the symbol named as `name`.
270  std::string getVarName(StringRef name) const;
271 
272  private:
273  // Allow SymbolInfoMap to access private methods.
274  friend class SymbolInfoMap;
275 
276  // Structure to uniquely distinguish different locations of the symbols.
277  //
278  // * If a symbol is defined as an operand of an operation, `dag` specifies
279  // the DAG of the operation, `operandIndexOrNumValues` specifies the
280  // operand index, and `variadicSubIndex` must be set to `std::nullopt`.
281  //
282  // * If a symbol is defined in a `variadic` DAG, `dag` specifies the DAG
283  // of the parent operation, `operandIndexOrNumValues` specifies the
284  // declared operand index of the variadic operand in the parent
285  // operation.
286  //
287  // - If the symbol is defined as a result of `variadic` DAG, the
288  // `variadicSubIndex` must be set to `std::nullopt`, which means that
289  // the symbol binds to the full operand range.
290  //
291  // - If the symbol is defined as a operand, the `variadicSubIndex` must
292  // be set to the index within the variadic sub-operand list.
293  //
294  // * If a symbol is defined in a `either` DAG, `dag` specifies the DAG
295  // of the parent operation, `operandIndexOrNumValues` specifies the
296  // operand index in the parent operation (not necessary the index in the
297  // DAG).
298  //
299  // * If a symbol is defined as a result, specifies the number of returning
300  // value.
301  //
302  // Example 1:
303  //
304  // def : Pat<(OpA $input0, $input1), ...>;
305  //
306  // $input0: (OpA, 0, nullopt)
307  // $input1: (OpA, 1, nullopt)
308  //
309  // Example 2:
310  //
311  // def : Pat<(OpB (variadic:$input0 $input0a, $input0b),
312  // (variadic:$input1 $input1a, $input1b, $input1c)),
313  // ...>;
314  //
315  // $input0: (OpB, 0, nullopt)
316  // $input0a: (OpB, 0, 0)
317  // $input0b: (OpB, 0, 1)
318  // $input1: (OpB, 1, nullopt)
319  // $input1a: (OpB, 1, 0)
320  // $input1b: (OpB, 1, 1)
321  // $input1c: (OpB, 1, 2)
322  //
323  // Example 3:
324  //
325  // def : Pat<(OpC $input0, (either $input1, $input2)), ...>;
326  //
327  // $input0: (OpC, 0, nullopt)
328  // $input1: (OpC, 1, nullopt)
329  // $input2: (OpC, 2, nullopt)
330  //
331  // Example 4:
332  //
333  // def ThreeResultOp : TEST_Op<...> {
334  // let results = (outs
335  // AnyType:$result1,
336  // AnyType:$result2,
337  // AnyType:$result3
338  // );
339  // }
340  //
341  // def : Pat<...,
342  // (ThreeResultOp:$result ...)>;
343  //
344  // $result: (nullptr, 3, nullopt)
345  //
346  struct DagAndConstant {
347  // DagNode and DagLeaf are accessed by value which means it can't be used
348  // as identifier here. Use an opaque pointer type instead.
349  const void *dag;
350  int operandIndexOrNumValues;
351  std::optional<int> variadicSubIndex;
352 
353  DagAndConstant(const void *dag, int operandIndexOrNumValues,
354  std::optional<int> variadicSubIndex)
355  : dag(dag), operandIndexOrNumValues(operandIndexOrNumValues),
356  variadicSubIndex(variadicSubIndex) {}
357 
358  bool operator==(const DagAndConstant &rhs) const {
359  return dag == rhs.dag &&
360  operandIndexOrNumValues == rhs.operandIndexOrNumValues &&
361  variadicSubIndex == rhs.variadicSubIndex;
362  }
363  };
364 
365  // What kind of entity this symbol represents:
366  // * Attr: op attribute
367  // * Operand: op operand
368  // * Result: op result
369  // * Value: a value not attached to an op (e.g., from NativeCodeCall)
370  // * MultipleValues: a pack of values not attached to an op (e.g., from
371  // NativeCodeCall). This kind supports indexing.
372  enum class Kind : uint8_t { Attr, Operand, Result, Value, MultipleValues };
373 
374  // Creates a SymbolInfo instance. `dagAndConstant` is only used for `Attr`
375  // and `Operand` so should be std::nullopt for `Result` and `Value` kind.
376  SymbolInfo(const Operator *op, Kind kind,
377  std::optional<DagAndConstant> dagAndConstant);
378 
379  // Static methods for creating SymbolInfo.
380  static SymbolInfo getAttr(const Operator *op, int index) {
381  return SymbolInfo(op, Kind::Attr,
382  DagAndConstant(nullptr, index, std::nullopt));
383  }
384  static SymbolInfo getAttr() {
385  return SymbolInfo(nullptr, Kind::Attr, std::nullopt);
386  }
387  static SymbolInfo
388  getOperand(DagNode node, const Operator *op, int operandIndex,
389  std::optional<int> variadicSubIndex = std::nullopt) {
390  return SymbolInfo(op, Kind::Operand,
391  DagAndConstant(node.getAsOpaquePointer(), operandIndex,
392  variadicSubIndex));
393  }
394  static SymbolInfo getResult(const Operator *op) {
395  return SymbolInfo(op, Kind::Result, std::nullopt);
396  }
397  static SymbolInfo getValue() {
398  return SymbolInfo(nullptr, Kind::Value, std::nullopt);
399  }
400  static SymbolInfo getMultipleValues(int numValues) {
401  return SymbolInfo(nullptr, Kind::MultipleValues,
402  DagAndConstant(nullptr, numValues, std::nullopt));
403  }
404 
405  // Returns the number of static values this symbol corresponds to.
406  // A static value is an operand/result declared in ODS. Normally a symbol
407  // only represents one static value, but symbols bound to op results can
408  // represent more than one if the op is a multi-result op.
409  int getStaticValueCount() const;
410 
411  // Returns a string containing the C++ expression for referencing this
412  // symbol as a value (if this symbol represents one static value) or a value
413  // range (if this symbol represents multiple static values). `name` is the
414  // name of the C++ variable that this symbol bounds to. `index` should only
415  // be used for indexing results. `fmt` is used to format each value.
416  // `separator` is used to separate values if this is a value range.
417  std::string getValueAndRangeUse(StringRef name, int index, const char *fmt,
418  const char *separator) const;
419 
420  // Returns a string containing the C++ expression for referencing this
421  // symbol as a value range regardless of how many static values this symbol
422  // represents. `name` is the name of the C++ variable that this symbol
423  // bounds to. `index` should only be used for indexing results. `fmt` is
424  // used to format each value. `separator` is used to separate values in the
425  // range.
426  std::string getAllRangeUse(StringRef name, int index, const char *fmt,
427  const char *separator) const;
428 
429  // The argument index (for `Attr` and `Operand` only)
430  int getArgIndex() const { return dagAndConstant->operandIndexOrNumValues; }
431 
432  // The number of values in the MultipleValue
433  int getSize() const { return dagAndConstant->operandIndexOrNumValues; }
434 
435  // The variadic sub-operands index (for variadic `Operand` only)
436  std::optional<int> getVariadicSubIndex() const {
437  return dagAndConstant->variadicSubIndex;
438  }
439 
440  const Operator *op; // The op where the bound entity belongs
441  Kind kind; // The kind of the bound entity
442 
443  // The tuple of DagNode pointer and two constant values (for `Attr`,
444  // `Operand` and the size of MultipleValue symbol). Note that operands may
445  // be bound to the same symbol, use the DagNode and index to distinguish
446  // them. For `Attr` and MultipleValue, the Dag part will be nullptr.
447  std::optional<DagAndConstant> dagAndConstant;
448 
449  // Alternative name for the symbol. It is used in case the name
450  // is not unique. Applicable for `Operand` only.
451  std::optional<std::string> alternativeName;
452  };
453 
454  using BaseT = std::unordered_multimap<std::string, SymbolInfo>;
455 
456  // Iterators for accessing all symbols.
457  using iterator = BaseT::iterator;
458  iterator begin() { return symbolInfoMap.begin(); }
459  iterator end() { return symbolInfoMap.end(); }
460 
461  // Const iterators for accessing all symbols.
462  using const_iterator = BaseT::const_iterator;
463  const_iterator begin() const { return symbolInfoMap.begin(); }
464  const_iterator end() const { return symbolInfoMap.end(); }
465 
466  // Binds the given `symbol` to the `argIndex`-th argument to the given `op`.
467  // Returns false if `symbol` is already bound and symbols are not operands.
468  bool bindOpArgument(DagNode node, StringRef symbol, const Operator &op,
469  int argIndex,
470  std::optional<int> variadicSubIndex = std::nullopt);
471 
472  // Binds the given `symbol` to the results the given `op`. Returns false if
473  // `symbol` is already bound.
474  bool bindOpResult(StringRef symbol, const Operator &op);
475 
476  // A helper function for dispatching target value binding functions.
477  bool bindValues(StringRef symbol, int numValues = 1);
478 
479  // Registers the given `symbol` as bound to the Value(s). Returns false if
480  // `symbol` is already bound.
481  bool bindValue(StringRef symbol);
482 
483  // Registers the given `symbol` as bound to a MultipleValue. Return false if
484  // `symbol` is already bound.
485  bool bindMultipleValues(StringRef symbol, int numValues);
486 
487  // Registers the given `symbol` as bound to an attr. Returns false if `symbol`
488  // is already bound.
489  bool bindAttr(StringRef symbol);
490 
491  // Returns true if the given `symbol` is bound.
492  bool contains(StringRef symbol) const;
493 
494  // Returns an iterator to the information of the given symbol named as `key`.
495  const_iterator find(StringRef key) const;
496 
497  // Returns an iterator to the information of the given symbol named as `key`,
498  // with index `argIndex` for operator `op`.
499  const_iterator findBoundSymbol(StringRef key, DagNode node,
500  const Operator &op, int argIndex,
501  std::optional<int> variadicSubIndex) const;
502  const_iterator findBoundSymbol(StringRef key,
503  const SymbolInfo &symbolInfo) const;
504 
505  // Returns the bounds of a range that includes all the elements which
506  // bind to the `key`.
507  std::pair<iterator, iterator> getRangeOfEqualElements(StringRef key);
508 
509  // Returns number of times symbol named as `key` was used.
510  int count(StringRef key) const;
511 
512  // Returns the number of static values of the given `symbol` corresponds to.
513  // A static value is an operand/result declared in ODS. Normally a symbol only
514  // represents one static value, but symbols bound to op results can represent
515  // more than one if the op is a multi-result op.
516  int getStaticValueCount(StringRef symbol) const;
517 
518  // Returns a string containing the C++ expression for referencing this
519  // symbol as a value (if this symbol represents one static value) or a value
520  // range (if this symbol represents multiple static values). `fmt` is used to
521  // format each value. `separator` is used to separate values if `symbol`
522  // represents a value range.
523  std::string getValueAndRangeUse(StringRef symbol, const char *fmt = "{0}",
524  const char *separator = ", ") const;
525 
526  // Returns a string containing the C++ expression for referencing this
527  // symbol as a value range regardless of how many static values this symbol
528  // represents. `fmt` is used to format each value. `separator` is used to
529  // separate values in the range.
530  std::string getAllRangeUse(StringRef symbol, const char *fmt = "{0}",
531  const char *separator = ", ") const;
532 
533  // Assign alternative unique names to Operands that have equal names.
535 
536  // Splits the given `symbol` into a value pack name and an index. Returns the
537  // value pack name and writes the index to `index` on success. Returns
538  // `symbol` itself if it does not contain an index.
539  //
540  // We can use `name__N` to access the `N`-th value in the value pack bound to
541  // `name`. `name` is typically the results of an multi-result op.
542  static StringRef getValuePackName(StringRef symbol, int *index = nullptr);
543 
544 private:
545  BaseT symbolInfoMap;
546 
547  // Pattern instantiation location. This is intended to be used as parameter
548  // to PrintFatalError() to report errors.
549  ArrayRef<SMLoc> loc;
550 };
551 
552 // Wrapper class providing helper methods for accessing MLIR Pattern defined
553 // in TableGen. This class should closely reflect what is defined as class
554 // `Pattern` in TableGen. This class contains maps so it is not intended to be
555 // used as values.
556 class Pattern {
557 public:
558  explicit Pattern(const llvm::Record *def, RecordOperatorMap *mapper);
559 
560  // Returns the source pattern to match.
561  DagNode getSourcePattern() const;
562 
563  // Returns the number of result patterns generated by applying this rewrite
564  // rule.
565  int getNumResultPatterns() const;
566 
567  // Returns the DAG tree root node of the `index`-th result pattern.
568  DagNode getResultPattern(unsigned index) const;
569 
570  // Collects all symbols bound in the source pattern into `infoMap`.
572 
573  // Collects all symbols bound in result patterns into `infoMap`.
575 
576  // Returns the op that the root node of the source pattern matches.
577  const Operator &getSourceRootOp();
578 
579  // Returns the operator wrapper object corresponding to the given `node`'s DAG
580  // operator.
582 
583  // Returns the constraints.
584  std::vector<AppliedConstraint> getConstraints() const;
585 
586  // Returns the number of supplemental auxiliary patterns generated by applying
587  // this rewrite rule.
588  int getNumSupplementalPatterns() const;
589 
590  // Returns the DAG tree root node of the `index`-th supplemental result
591  // pattern.
592  DagNode getSupplementalPattern(unsigned index) const;
593 
594  // Returns the benefit score of the pattern.
595  int getBenefit() const;
596 
597  using IdentifierLine = std::pair<StringRef, unsigned>;
598 
599  // Returns the file location of the pattern (buffer identifier + line number
600  // pair).
601  std::vector<IdentifierLine> getLocation() const;
602 
603  // Recursively collects all bound symbols inside the DAG tree rooted
604  // at `tree` and updates the given `infoMap`.
605  void collectBoundSymbols(DagNode tree, SymbolInfoMap &infoMap,
606  bool isSrcPattern);
607 
608 private:
609  // Helper function to verify variable binding.
610  void verifyBind(bool result, StringRef symbolName);
611 
612  // The TableGen definition of this pattern.
613  const llvm::Record &def;
614 
615  // All operators.
616  // TODO: we need a proper context manager, like MLIRContext, for managing the
617  // lifetime of shared entities.
618  RecordOperatorMap *recordOpMap;
619 };
620 
621 } // namespace tblgen
622 } // namespace mlir
623 
624 namespace llvm {
625 template <>
626 struct DenseMapInfo<mlir::tblgen::DagNode> {
628  return mlir::tblgen::DagNode(
630  }
632  return mlir::tblgen::DagNode(
634  }
635  static unsigned getHashValue(mlir::tblgen::DagNode node) {
636  return llvm::hash_value(node.getAsOpaquePointer());
637  }
639  return lhs.node == rhs.node;
640  }
641 };
642 
643 template <>
644 struct DenseMapInfo<mlir::tblgen::DagLeaf> {
646  return mlir::tblgen::DagLeaf(
648  }
650  return mlir::tblgen::DagLeaf(
652  }
653  static unsigned getHashValue(mlir::tblgen::DagLeaf leaf) {
654  return llvm::hash_value(leaf.getAsOpaquePointer());
655  }
657  return lhs.def == rhs.def;
658  }
659 };
660 } // namespace llvm
661 
662 #endif // MLIR_TABLEGEN_PATTERN_H_
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:96
Constraint getAsConstraint() const
Definition: Pattern.cpp:64
bool isNativeCodeCall() const
Definition: Pattern.cpp:54
int getNumReturnsOfNativeCode() const
Definition: Pattern.cpp:89
ConstantAttr getAsConstantAttr() const
Definition: Pattern.cpp:70
void print(raw_ostream &os) const
Definition: Pattern.cpp:104
std::string getStringAttr() const
Definition: Pattern.cpp:94
bool isEnumCase() const
Definition: Pattern.cpp:60
StringRef getNativeCodeTemplate() const
Definition: Pattern.cpp:84
DagLeaf(const llvm::Init *def)
Definition: Pattern.h:61
std::string getConditionTemplate() const
Definition: Pattern.cpp:80
bool isUnspecified() const
Definition: Pattern.cpp:40
EnumCase getAsEnumCase() const
Definition: Pattern.cpp:75
bool isAttrMatcher() const
Definition: Pattern.cpp:49
bool isOperandMatcher() const
Definition: Pattern.cpp:44
bool isConstantAttr() const
Definition: Pattern.cpp:58
bool isStringAttr() const
Definition: Pattern.cpp:62
bool isReturnTypeDirective() const
Definition: Pattern.cpp:189
bool isLocationDirective() const
Definition: Pattern.cpp:184
bool isReplaceWithValue() const
Definition: Pattern.cpp:179
DagNode getArgAsNestedDag(unsigned index) const
Definition: Pattern.cpp:166
bool isOperation() const
Definition: Pattern.cpp:119
DagLeaf getArgAsLeaf(unsigned index) const
Definition: Pattern.cpp:170
int getNumReturnsOfNativeCode() const
Definition: Pattern.cpp:132
StringRef getNativeCodeTemplate() const
Definition: Pattern.cpp:125
void print(raw_ostream &os) const
Definition: Pattern.cpp:204
int getNumOps() const
Definition: Pattern.cpp:149
Operator & getDialectOp(RecordOperatorMap *mapper) const
Definition: Pattern.cpp:141
bool isVariadic() const
Definition: Pattern.cpp:199
bool isNativeCodeCall() const
Definition: Pattern.cpp:113
bool isEither() const
Definition: Pattern.cpp:194
bool isNestedDagArg(unsigned index) const
Definition: Pattern.cpp:162
StringRef getSymbol() const
Definition: Pattern.cpp:139
int getNumArgs() const
Definition: Pattern.cpp:160
DagNode(const llvm::DagInit *node)
Definition: Pattern.h:144
StringRef getArgName(unsigned index) const
Definition: Pattern.cpp:175
Wrapper class that contains a MLIR op's information (e.g., operands, attributes) defined in TableGen ...
Definition: Operator.h:77
int getBenefit() const
int getNumResultPatterns() const
Definition: Pattern.cpp:625
std::vector< IdentifierLine > getLocation() const
Definition: Pattern.cpp:712
DagNode getSourcePattern() const
Definition: Pattern.cpp:621
const Operator & getSourceRootOp()
Definition: Pattern.cpp:654
std::vector< AppliedConstraint > getConstraints() const
Definition: Pattern.cpp:662
DagNode getResultPattern(unsigned index) const
Definition: Pattern.cpp:630
void collectBoundSymbols(DagNode tree, SymbolInfoMap &infoMap, bool isSrcPattern)
Definition: Pattern.cpp:732
Pattern(const llvm::Record *def, RecordOperatorMap *mapper)
Operator & getDialectOp(DagNode node)
Definition: Pattern.cpp:658
DagNode getSupplementalPattern(unsigned index) const
Definition: Pattern.cpp:695
void collectSourcePatternBoundSymbols(SymbolInfoMap &infoMap)
Definition: Pattern.cpp:635
void collectResultPatternBoundSymbols(SymbolInfoMap &infoMap)
Definition: Pattern.cpp:645
int getNumSupplementalPatterns() const
Definition: Pattern.cpp:690
std::pair< StringRef, unsigned > IdentifierLine
Definition: Pattern.h:597
std::string getArgDecl(StringRef name) const
Definition: Pattern.cpp:287
std::string getVarName(StringRef name) const
Definition: Pattern.cpp:246
std::string getVarTypeStr(StringRef name) const
Definition: Pattern.cpp:250
std::string getVarDecl(StringRef name) const
Definition: Pattern.cpp:280
BaseT::iterator iterator
Definition: Pattern.h:457
static StringRef getValuePackName(StringRef symbol, int *index=nullptr)
Definition: Pattern.cpp:213
const_iterator begin() const
Definition: Pattern.h:463
int count(StringRef key) const
Definition: Pattern.cpp:538
const_iterator find(StringRef key) const
Definition: Pattern.cpp:504
bool bindMultipleValues(StringRef symbol, int numValues)
Definition: Pattern.cpp:488
bool bindOpArgument(DagNode node, StringRef symbol, const Operator &op, int argIndex, std::optional< int > variadicSubIndex=std::nullopt)
Definition: Pattern.cpp:436
std::string getAllRangeUse(StringRef symbol, const char *fmt="{0}", const char *separator=", ") const
Definition: Pattern.cpp:569
bool bindValues(StringRef symbol, int numValues=1)
Definition: Pattern.cpp:476
bool bindAttr(StringRef symbol)
Definition: Pattern.cpp:495
SymbolInfoMap(ArrayRef< SMLoc > loc)
Definition: Pattern.h:253
bool bindValue(StringRef symbol)
Definition: Pattern.cpp:483
const_iterator findBoundSymbol(StringRef key, DagNode node, const Operator &op, int argIndex, std::optional< int > variadicSubIndex) const
Definition: Pattern.cpp:511
std::pair< iterator, iterator > getRangeOfEqualElements(StringRef key)
Definition: Pattern.cpp:532
int getStaticValueCount(StringRef symbol) const
Definition: Pattern.cpp:543
bool contains(StringRef symbol) const
Definition: Pattern.cpp:500
BaseT::const_iterator const_iterator
Definition: Pattern.h:462
bool bindOpResult(StringRef symbol, const Operator &op)
Definition: Pattern.cpp:469
std::string getValueAndRangeUse(StringRef symbol, const char *fmt="{0}", const char *separator=", ") const
Definition: Pattern.cpp:554
const_iterator end() const
Definition: Pattern.h:464
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition: CallGraph.h:229
Kind
An enumeration of the kinds of predicates.
Definition: Predicate.h:44
inline ::llvm::hash_code hash_value(const PolynomialBase< D, T > &arg)
Definition: Polynomial.h:262
Include the generated interface declarations.
bool operator==(StringAttr lhs, std::nullptr_t)
Define comparisons for StringAttr against nullptr and itself to avoid the StringRef overloads from be...
static bool isEqual(mlir::tblgen::DagLeaf lhs, mlir::tblgen::DagLeaf rhs)
Definition: Pattern.h:656
static mlir::tblgen::DagLeaf getEmptyKey()
Definition: Pattern.h:645
static mlir::tblgen::DagLeaf getTombstoneKey()
Definition: Pattern.h:649
static unsigned getHashValue(mlir::tblgen::DagLeaf leaf)
Definition: Pattern.h:653
static bool isEqual(mlir::tblgen::DagNode lhs, mlir::tblgen::DagNode rhs)
Definition: Pattern.h:638
static mlir::tblgen::DagNode getEmptyKey()
Definition: Pattern.h:627
static mlir::tblgen::DagNode getTombstoneKey()
Definition: Pattern.h:631
static unsigned getHashValue(mlir::tblgen::DagNode node)
Definition: Pattern.h:635