14 #ifndef MLIR_TABLEGEN_PATTERN_H_
15 #define MLIR_TABLEGEN_PATTERN_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"
27 #include <unordered_map>
61 explicit DagLeaf(
const llvm::Init *def) : def(def) {}
115 void print(raw_ostream &os)
const;
119 const void *getAsOpaquePointer()
const {
return def; }
123 bool isSubClassOf(StringRef superclass)
const;
125 const llvm::Init *def;
144 explicit DagNode(
const llvm::DagInit *node) : node(node) {}
148 operator bool()
const {
return node !=
nullptr; }
209 void print(raw_ostream &os)
const;
214 const void *getAsOpaquePointer()
const {
return node; }
216 const llvm::DagInit *node;
346 struct DagAndConstant {
350 int operandIndexOrNumValues;
351 std::optional<int> variadicSubIndex;
353 DagAndConstant(
const void *dag,
int operandIndexOrNumValues,
354 std::optional<int> variadicSubIndex)
355 : dag(dag), operandIndexOrNumValues(operandIndexOrNumValues),
356 variadicSubIndex(variadicSubIndex) {}
358 bool operator==(
const DagAndConstant &rhs)
const {
359 return dag == rhs.dag &&
360 operandIndexOrNumValues == rhs.operandIndexOrNumValues &&
361 variadicSubIndex == rhs.variadicSubIndex;
372 enum class Kind : uint8_t { Attr, Operand, Result,
Value, MultipleValues };
376 SymbolInfo(
const Operator *op, Kind kind,
377 std::optional<DagAndConstant> dagAndConstant);
380 static SymbolInfo getAttr(
const Operator *op,
int index) {
381 return SymbolInfo(op, Kind::Attr,
382 DagAndConstant(
nullptr, index, std::nullopt));
384 static SymbolInfo getAttr() {
385 return SymbolInfo(
nullptr, Kind::Attr, std::nullopt);
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,
394 static SymbolInfo getResult(
const Operator *op) {
395 return SymbolInfo(op, Kind::Result, std::nullopt);
397 static SymbolInfo getValue() {
398 return SymbolInfo(
nullptr, Kind::Value, std::nullopt);
400 static SymbolInfo getMultipleValues(
int numValues) {
401 return SymbolInfo(
nullptr, Kind::MultipleValues,
402 DagAndConstant(
nullptr, numValues, std::nullopt));
409 int getStaticValueCount()
const;
417 std::string getValueAndRangeUse(StringRef name,
int index,
const char *fmt,
418 const char *separator)
const;
426 std::string getAllRangeUse(StringRef name,
int index,
const char *fmt,
427 const char *separator)
const;
430 int getArgIndex()
const {
return dagAndConstant->operandIndexOrNumValues; }
433 int getSize()
const {
return dagAndConstant->operandIndexOrNumValues; }
436 std::optional<int> getVariadicSubIndex()
const {
437 return dagAndConstant->variadicSubIndex;
447 std::optional<DagAndConstant> dagAndConstant;
451 std::optional<std::string> alternativeName;
454 using BaseT = std::unordered_multimap<std::string, SymbolInfo>;
470 std::optional<int> variadicSubIndex = std::nullopt);
477 bool bindValues(StringRef symbol,
int numValues = 1);
492 bool contains(StringRef symbol)
const;
501 std::optional<int> variadicSubIndex)
const;
503 const SymbolInfo &symbolInfo)
const;
510 int count(StringRef key)
const;
524 const char *separator =
", ")
const;
530 std::string
getAllRangeUse(StringRef symbol,
const char *fmt =
"{0}",
531 const char *separator =
", ")
const;
610 void verifyBind(
bool result, StringRef symbolName);
613 const llvm::Record &def;
639 return lhs.node == rhs.node;
657 return lhs.def == rhs.def;
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Constraint getAsConstraint() const
bool isNativeCodeCall() const
int getNumReturnsOfNativeCode() const
ConstantAttr getAsConstantAttr() const
void print(raw_ostream &os) const
std::string getStringAttr() const
StringRef getNativeCodeTemplate() const
DagLeaf(const llvm::Init *def)
std::string getConditionTemplate() const
bool isUnspecified() const
EnumCase getAsEnumCase() const
bool isAttrMatcher() const
bool isOperandMatcher() const
bool isConstantAttr() const
bool isStringAttr() const
bool isReturnTypeDirective() const
bool isLocationDirective() const
bool isReplaceWithValue() const
DagNode getArgAsNestedDag(unsigned index) const
DagLeaf getArgAsLeaf(unsigned index) const
int getNumReturnsOfNativeCode() const
StringRef getNativeCodeTemplate() const
void print(raw_ostream &os) const
Operator & getDialectOp(RecordOperatorMap *mapper) const
bool isNativeCodeCall() const
bool isNestedDagArg(unsigned index) const
StringRef getSymbol() const
DagNode(const llvm::DagInit *node)
StringRef getArgName(unsigned index) const
Wrapper class that contains a MLIR op's information (e.g., operands, attributes) defined in TableGen ...
int getNumResultPatterns() const
std::vector< IdentifierLine > getLocation() const
DagNode getSourcePattern() const
const Operator & getSourceRootOp()
std::vector< AppliedConstraint > getConstraints() const
DagNode getResultPattern(unsigned index) const
void collectBoundSymbols(DagNode tree, SymbolInfoMap &infoMap, bool isSrcPattern)
Pattern(const llvm::Record *def, RecordOperatorMap *mapper)
Operator & getDialectOp(DagNode node)
DagNode getSupplementalPattern(unsigned index) const
void collectSourcePatternBoundSymbols(SymbolInfoMap &infoMap)
void collectResultPatternBoundSymbols(SymbolInfoMap &infoMap)
int getNumSupplementalPatterns() const
std::pair< StringRef, unsigned > IdentifierLine
std::string getArgDecl(StringRef name) const
std::string getVarName(StringRef name) const
std::string getVarTypeStr(StringRef name) const
std::string getVarDecl(StringRef name) const
static StringRef getValuePackName(StringRef symbol, int *index=nullptr)
const_iterator begin() const
int count(StringRef key) const
const_iterator find(StringRef key) const
void assignUniqueAlternativeNames()
bool bindMultipleValues(StringRef symbol, int numValues)
bool bindOpArgument(DagNode node, StringRef symbol, const Operator &op, int argIndex, std::optional< int > variadicSubIndex=std::nullopt)
std::string getAllRangeUse(StringRef symbol, const char *fmt="{0}", const char *separator=", ") const
bool bindValues(StringRef symbol, int numValues=1)
bool bindAttr(StringRef symbol)
SymbolInfoMap(ArrayRef< SMLoc > loc)
bool bindValue(StringRef symbol)
const_iterator findBoundSymbol(StringRef key, DagNode node, const Operator &op, int argIndex, std::optional< int > variadicSubIndex) const
std::pair< iterator, iterator > getRangeOfEqualElements(StringRef key)
int getStaticValueCount(StringRef symbol) const
bool contains(StringRef symbol) const
BaseT::const_iterator const_iterator
bool bindOpResult(StringRef symbol, const Operator &op)
std::string getValueAndRangeUse(StringRef symbol, const char *fmt="{0}", const char *separator=", ") const
const_iterator end() const
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Kind
An enumeration of the kinds of predicates.
inline ::llvm::hash_code hash_value(const PolynomialBase< D, T > &arg)
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)
static mlir::tblgen::DagLeaf getEmptyKey()
static mlir::tblgen::DagLeaf getTombstoneKey()
static unsigned getHashValue(mlir::tblgen::DagLeaf leaf)
static bool isEqual(mlir::tblgen::DagNode lhs, mlir::tblgen::DagNode rhs)
static mlir::tblgen::DagNode getEmptyKey()
static mlir::tblgen::DagNode getTombstoneKey()
static unsigned getHashValue(mlir::tblgen::DagNode node)