14 #ifndef MLIR_TABLEGEN_PATTERN_H_
15 #define MLIR_TABLEGEN_PATTERN_H_
20 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/ADT/Hashing.h"
22 #include "llvm/ADT/StringMap.h"
23 #include "llvm/ADT/StringSet.h"
26 #include <unordered_map>
60 explicit DagLeaf(
const llvm::Init *def) : def(def) {}
114 void print(raw_ostream &os)
const;
118 const void *getAsOpaquePointer()
const {
return def; }
122 bool isSubClassOf(StringRef superclass)
const;
124 const llvm::Init *def;
143 explicit DagNode(
const llvm::DagInit *node) : node(node) {}
147 operator bool()
const {
return node !=
nullptr; }
208 void print(raw_ostream &os)
const;
213 const void *getAsOpaquePointer()
const {
return node; }
215 const llvm::DagInit *node;
345 struct DagAndConstant {
349 int operandIndexOrNumValues;
350 std::optional<int> variadicSubIndex;
352 DagAndConstant(
const void *dag,
int operandIndexOrNumValues,
353 std::optional<int> variadicSubIndex)
354 : dag(dag), operandIndexOrNumValues(operandIndexOrNumValues),
355 variadicSubIndex(variadicSubIndex) {}
357 bool operator==(
const DagAndConstant &rhs)
const {
358 return dag == rhs.dag &&
359 operandIndexOrNumValues == rhs.operandIndexOrNumValues &&
360 variadicSubIndex == rhs.variadicSubIndex;
371 enum class Kind : uint8_t { Attr, Operand, Result,
Value, MultipleValues };
375 SymbolInfo(
const Operator *op, Kind kind,
376 std::optional<DagAndConstant> dagAndConstant);
379 static SymbolInfo getAttr(
const Operator *op,
int index) {
380 return SymbolInfo(op, Kind::Attr,
381 DagAndConstant(
nullptr, index, std::nullopt));
383 static SymbolInfo getAttr() {
384 return SymbolInfo(
nullptr, Kind::Attr, std::nullopt);
387 getOperand(DagNode node,
const Operator *op,
int operandIndex,
388 std::optional<int> variadicSubIndex = std::nullopt) {
389 return SymbolInfo(op, Kind::Operand,
390 DagAndConstant(node.getAsOpaquePointer(), operandIndex,
393 static SymbolInfo getResult(
const Operator *op) {
394 return SymbolInfo(op, Kind::Result, std::nullopt);
396 static SymbolInfo getValue() {
397 return SymbolInfo(
nullptr, Kind::Value, std::nullopt);
399 static SymbolInfo getMultipleValues(
int numValues) {
400 return SymbolInfo(
nullptr, Kind::MultipleValues,
401 DagAndConstant(
nullptr, numValues, std::nullopt));
408 int getStaticValueCount()
const;
416 std::string getValueAndRangeUse(StringRef name,
int index,
const char *fmt,
417 const char *separator)
const;
425 std::string getAllRangeUse(StringRef name,
int index,
const char *fmt,
426 const char *separator)
const;
429 int getArgIndex()
const {
return dagAndConstant->operandIndexOrNumValues; }
432 int getSize()
const {
return dagAndConstant->operandIndexOrNumValues; }
435 std::optional<int> getVariadicSubIndex()
const {
436 return dagAndConstant->variadicSubIndex;
446 std::optional<DagAndConstant> dagAndConstant;
450 std::optional<std::string> alternativeName;
453 using BaseT = std::unordered_multimap<std::string, SymbolInfo>;
469 std::optional<int> variadicSubIndex = std::nullopt);
476 bool bindValues(StringRef symbol,
int numValues = 1);
491 bool contains(StringRef symbol)
const;
500 std::optional<int> variadicSubIndex)
const;
502 const SymbolInfo &symbolInfo)
const;
509 int count(StringRef key)
const;
523 const char *separator =
", ")
const;
529 std::string
getAllRangeUse(StringRef symbol,
const char *fmt =
"{0}",
530 const char *separator =
", ")
const;
609 void verifyBind(
bool result, StringRef symbolName);
612 const llvm::Record &def;
638 return lhs.node == rhs.node;
656 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
bool isEnumAttrCase() 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
bool isAttrMatcher() const
EnumAttrCase getAsEnumAttrCase() 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)