13 #include "llvm/Support/ScopedPrinter.h"
14 #include "llvm/Support/raw_ostream.h"
29 std::unique_ptr<AttributeConstraint> &constraint = attributeConstraints[name];
33 assert(constraint->getCppClass() == cppClass &&
34 constraint->getSummary() == summary &&
35 "constraint with the same name was already registered with a "
44 std::unique_ptr<TypeConstraint> &constraint = typeConstraints[name];
51 std::unique_ptr<Dialect> &dialect = dialects[name];
53 dialect.reset(
new Dialect(name));
58 auto it = dialects.find(name);
59 return it == dialects.end() ? nullptr : &*it->second;
62 std::pair<Operation *, bool>
64 StringRef nativeClassName,
65 bool supportsResultTypeInferrence, SMLoc loc) {
66 std::pair<StringRef, StringRef> dialectAndName = name.split(
'.');
69 supportsResultTypeInferrence, loc);
73 std::pair<StringRef, StringRef> dialectAndName = name.split(
'.');
75 return dialect->lookupOperation(name);
82 for (
auto &entry : map)
83 storage.push_back(entry.second.get());
84 llvm::sort(storage, [](
const auto &lhs,
const auto &rhs) {
85 return lhs->getName() < rhs->getName();
94 os <<
"Optional<" << cst <<
">";
100 os <<
"Variadic<" << cst <<
">";
105 llvm::ScopedPrinter printer(os);
106 llvm::DictScope odsScope(printer,
"ODSContext");
108 printer.startLine() <<
"Dialect `" << dialect->getName() <<
"` {\n";
112 printer.startLine() <<
"Operation `" << op->getName() <<
"` {\n";
117 if (!attributes.empty()) {
118 printer.startLine() <<
"Attributes { ";
119 llvm::interleaveComma(attributes, os, [&](
const Attribute &attr) {
131 if (!operands.empty()) {
132 printer.startLine() <<
"Operands { ";
133 llvm::interleaveComma(
135 os << operand.
getName() <<
" : ";
144 if (!results.empty()) {
145 printer.startLine() <<
"Results { ";
146 llvm::interleaveComma(results, os, [&](
const OperandOrResult &result) {
147 os << result.
getName() <<
" : ";
159 printer.startLine() <<
"AttributeConstraint `" << cst->getDemangledName()
163 printer.startLine() <<
"Summary: " << cst->getSummary() <<
"\n";
164 printer.startLine() <<
"CppClass: " << cst->getCppClass() <<
"\n";
168 printer.startLine() <<
"TypeConstraint `" << cst->getDemangledName()
172 printer.startLine() <<
"Summary: " << cst->getSummary() <<
"\n";
173 printer.startLine() <<
"CppClass: " << cst->getCppClass() <<
"\n";
union mlir::linalg::@1244::ArityGroupAndKind::Kind kind
SmallVector< T * > sortMapByName(const llvm::StringMap< std::unique_ptr< T >> &map)
This class represents a generic ODS Attribute constraint.
This class provides an ODS representation of a specific operation attribute.
StringRef getName() const
Return the name of this operand.
const AttributeConstraint & getConstraint() const
Return the constraint of this attribute.
bool isOptional() const
Return true if this attribute is optional.
StringRef getDemangledName() const
Return the demangled name of this constraint.
std::pair< Operation *, bool > insertOperation(StringRef name, StringRef summary, StringRef desc, StringRef nativeClassName, bool supportsResultTypeInferrence, SMLoc loc)
Insert a new operation with the context.
const TypeConstraint & insertTypeConstraint(StringRef name, StringRef summary, StringRef cppClass)
Insert a new type constraint with the context.
Dialect & insertDialect(StringRef name)
Insert a new dialect with the context.
const Dialect * lookupDialect(StringRef name) const
Lookup a dialect registered with the given name, or null if no dialect with that name was inserted.
const AttributeConstraint & insertAttributeConstraint(StringRef name, StringRef summary, StringRef cppClass)
Insert a new attribute constraint with the context.
const Operation * lookupOperation(StringRef name) const
Lookup an operation registered with the given name, or null if no operation with that name is registe...
void print(raw_ostream &os) const
Print the contents of this context to the provided stream.
This class represents an ODS dialect, and contains information on the constructs held within the dial...
std::pair< Operation *, bool > insertOperation(StringRef name, StringRef summary, StringRef desc, StringRef nativeClassName, bool supportsResultTypeInferrence, SMLoc loc)
Insert a new operation with the dialect.
This class provides an ODS representation of a specific operation operand or result.
const TypeConstraint & getConstraint() const
Return the constraint of this value.
VariableLengthKind getVariableLengthKind() const
Returns the variable length kind of this value.
StringRef getName() const
Return the name of this value.
This class provides an ODS representation of a specific operation.
This class represents a generic ODS Type constraint.
Include the generated interface declarations.