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) {}
136 void print(raw_ostream &os)
const;
140 const void *getAsOpaquePointer()
const {
return def; }
144 bool isSubClassOf(StringRef superclass)
const;
146 const llvm::Init *def;
165 explicit DagNode(
const llvm::DagInit *node) : node(node) {}
169 operator bool()
const {
return node !=
nullptr; }
230 void print(raw_ostream &os)
const;
235 const void *getAsOpaquePointer()
const {
return node; }
237 const llvm::DagInit *node;
371 struct DagAndConstant {
375 int operandIndexOrNumValues;
376 std::optional<int> variadicSubIndex;
378 DagAndConstant(
const void *dag,
int operandIndexOrNumValues,
379 std::optional<int> variadicSubIndex)
380 : dag(dag), operandIndexOrNumValues(operandIndexOrNumValues),
381 variadicSubIndex(variadicSubIndex) {}
383 bool operator==(
const DagAndConstant &rhs)
const {
384 return dag == rhs.dag &&
385 operandIndexOrNumValues == rhs.operandIndexOrNumValues &&
386 variadicSubIndex == rhs.variadicSubIndex;
398 enum class Kind : uint8_t {
409 SymbolInfo(
const Operator *op, Kind kind,
410 std::optional<DagAndConstant> dagAndConstant);
413 static SymbolInfo getAttr(
const Operator *op,
int index) {
414 return SymbolInfo(op, Kind::Attr,
415 DagAndConstant(
nullptr, index, std::nullopt));
417 static SymbolInfo getAttr() {
418 return SymbolInfo(
nullptr, Kind::Attr, std::nullopt);
420 static SymbolInfo getProp(
const Operator *op,
int index) {
421 return SymbolInfo(op, Kind::Prop,
422 DagAndConstant(
nullptr, index, std::nullopt));
424 static SymbolInfo getProp(
const PropConstraint *constraint) {
426 return SymbolInfo(
nullptr, Kind::Prop,
427 DagAndConstant(constraint, -1, std::nullopt));
430 getOperand(DagNode node,
const Operator *op,
int operandIndex,
431 std::optional<int> variadicSubIndex = std::nullopt) {
432 return SymbolInfo(op, Kind::Operand,
433 DagAndConstant(node.getAsOpaquePointer(), operandIndex,
436 static SymbolInfo getResult(
const Operator *op) {
437 return SymbolInfo(op, Kind::Result, std::nullopt);
439 static SymbolInfo getValue() {
440 return SymbolInfo(
nullptr, Kind::Value, std::nullopt);
442 static SymbolInfo getMultipleValues(
int numValues) {
443 return SymbolInfo(
nullptr, Kind::MultipleValues,
444 DagAndConstant(
nullptr, numValues, std::nullopt));
451 int getStaticValueCount()
const;
459 std::string getValueAndRangeUse(StringRef name,
int index,
const char *fmt,
460 const char *separator)
const;
468 std::string getAllRangeUse(StringRef name,
int index,
const char *fmt,
469 const char *separator)
const;
472 int getArgIndex()
const {
return dagAndConstant->operandIndexOrNumValues; }
475 int getSize()
const {
return dagAndConstant->operandIndexOrNumValues; }
478 std::optional<int> getVariadicSubIndex()
const {
479 return dagAndConstant->variadicSubIndex;
489 std::optional<DagAndConstant> dagAndConstant;
493 std::optional<std::string> alternativeName;
496 using BaseT = std::unordered_multimap<std::string, SymbolInfo>;
512 std::optional<int> variadicSubIndex = std::nullopt);
519 bool bindValues(StringRef symbol,
int numValues = 1);
538 bool contains(StringRef symbol)
const;
547 std::optional<int> variadicSubIndex)
const;
549 const SymbolInfo &symbolInfo)
const;
556 int count(StringRef key)
const;
570 const char *separator =
", ")
const;
576 std::string
getAllRangeUse(StringRef symbol,
const char *fmt =
"{0}",
577 const char *separator =
", ")
const;
656 void verifyBind(
bool result, StringRef symbolName);
659 const llvm::Record &def;
685 return lhs.node == rhs.node;
703 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 isPropMatcher() const
int getNumReturnsOfNativeCode() const
ConstantAttr getAsConstantAttr() const
void print(raw_ostream &os) const
std::string getStringAttr() const
Property getAsProperty() const
StringRef getNativeCodeTemplate() const
DagLeaf(const llvm::Init *def)
std::string getConditionTemplate() const
bool isConstantProp() const
PropConstraint getAsPropConstraint() const
ConstantProp getAsConstantProp() const
bool isUnspecified() const
EnumCase getAsEnumCase() const
bool isAttrMatcher() const
bool isOperandMatcher() const
bool isPropDefinition() 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)
bool bindProp(StringRef symbol, const PropConstraint &constraint)
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.
llvm::hash_code hash_value(const StructType::MemberDecorationInfo &memberDecorationInfo)
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)