18#include <mlir/IR/BuiltinTypes.h>
19#include <mlir/IR/OpImplementation.h>
20#include <mlir/IR/Operation.h>
21#include <mlir/IR/SymbolTable.h>
22#include <mlir/Support/LogicalResult.h>
24#include <llvm/ADT/STLExtras.h>
25#include <llvm/ADT/SmallString.h>
26#include <llvm/ADT/StringRef.h>
27#include <llvm/Support/Debug.h>
35 return OpClass::getOperationName();
42 if (OpClass self = llvm::dyn_cast<OpClass>(op)) {
45 if (OpClass parent = op->getParentOfType<OpClass>()) {
55 if (OpClass p = op->getParentOfType<OpClass>()) {
65 while ((op = op->getParentOp())) {
66 if (llvm::isa<OpTys...>(op)) {
74template <
typename TypeClass>
78 :
public mlir::OpTrait::TraitBase<TypeClass, LLZKSymbolTableImplTrait> {
84 while ((op = op->getParentWithTrait<mlir::OpTrait::SymbolTable>())) {
85 if (mlir::failed(mlir::detail::verifySymbolTable(op))) {
86 return mlir::failure();
89 return mlir::success();
94template <
typename Ancestor,
typename... Ancestors>
struct HasAncestor {
95 template <
typename ConcreteType>
98 struct Impl :
public mlir::OpTrait::TraitBase<ConcreteType, Impl> {
101 return mlir::success();
103 auto diag = op->emitOpError();
105 if constexpr (
sizeof...(Ancestors) == 0) {
106 diag <<
"must have an ancestor of type '" << Ancestor::getOperationName() <<
'\'';
108 diag <<
"must have an ancestor of one of the following types: ";
109 llvm::interleaveComma(
110 llvm::ArrayRef<llvm::StringLiteral>(
111 {Ancestor::getOperationName(), Ancestors::getOperationName()...}
113 diag, [&diag](
auto name) { diag <<
'\'' << name <<
'\''; }
125 template <
typename TypeClass>
class Impl :
public mlir::OpTrait::TraitBase<TypeClass, Impl> {
126 inline static mlir::LogicalResult verifyHelper(mlir::Operation *op, int32_t segmentSize) {
127 TypeClass c = llvm::cast<TypeClass>(op);
129 op, segmentSize, c.getMapOpGroupSizesAttr(), c.getMapOperands(), c.getNumDimsPerMapAttr()
135 if (TypeClass::template hasTrait<mlir::OpTrait::AttrSizedOperandSegments>()) {
138 OperandSegmentIndex >= 0,
139 "When the `AttrSizedOperandSegments` trait is present, the index of `$mapOperands` "
140 "within the `operandSegmentSizes` attribute must be specified."
142 mlir::DenseI32ArrayAttr segmentSizes = op->getAttrOfType<mlir::DenseI32ArrayAttr>(
143 mlir::OpTrait::AttrSizedOperandSegments<TypeClass>::getOperandSegmentSizeAttr()
146 OperandSegmentIndex < segmentSizes.size() &&
147 "Parameter of `VerifySizesForMultiAffineOps` exceeds the number of ODS-declared "
150 return verifyHelper(op, segmentSizes[OperandSegmentIndex]);
154 return verifyHelper(op, -1);
162 mlir::OpAsmParser &parser,
163 mlir::SmallVector<mlir::OpAsmParser::UnresolvedOperand, N> &mapOperands,
164 mlir::IntegerAttr &numDims
170 mlir::OpAsmPrinter &printer, mlir::Operation *op, mlir::OperandRange mapOperands,
171 mlir::IntegerAttr numDims
177 mlir::OpAsmParser &parser,
178 mlir::SmallVector<mlir::SmallVector<mlir::OpAsmParser::UnresolvedOperand>> &multiMapOperands,
179 mlir::DenseI32ArrayAttr &numDimsPerMap
185 mlir::OpAsmPrinter &printer, mlir::Operation *op, mlir::OperandRangeRange multiMapOperands,
186 mlir::DenseI32ArrayAttr numDimsPerMap
192 mlir::OpAsmParser &parser, mlir::NamedAttrList &extraAttrs, mlir::OperationState &state
197template <
typename ConcreteOp>
199 mlir::OpAsmPrinter &printer, ConcreteOp op, mlir::DictionaryAttr extraAttrs,
200 typename mlir::PropertiesSelector<ConcreteOp>::type state
206 mlir::SmallVector<mlir::Attribute> elements;
207 auto parseElement = [&]() -> mlir::ParseResult {
209 if (mlir::succeeded(parser.parseOptionalQuestion())) {
210 elements.push_back(parser.getBuilder().getIndexAttr(mlir::ShapedType::kDynamic));
211 return mlir::success();
214 if (mlir::failed(attrParseResult)) {
215 return parser.emitError(
216 parser.getCurrentLocation(),
"failed to parse template parameter attribute"
219 auto emitError = [&parser] {
222 mlir::FailureOr<mlir::Attribute> forced =
forceIntAttrType(*attrParseResult, emitError);
223 if (mlir::failed(forced)) {
224 return mlir::failure();
226 elements.push_back(*forced);
227 return mlir::success();
229 auto res = parser.parseCommaSeparatedList(mlir::AsmParser::Delimiter::Square, parseElement);
230 if (mlir::failed(res)) {
233 value = parser.getBuilder().getArrayAttr(elements);
234 return mlir::success();
Wrapper around InFlightDiagnostic that can either be a regular InFlightDiagnostic or a special versio...
See LLZKSymbolTable ODS documentation for details.
static mlir::LogicalResult verifyRegionTrait(mlir::Operation *op)
LogicalResult verifySizesForMultiAffineOps(Operation *op, int32_t segmentSize, ArrayRef< int32_t > mapOpGroupSizes, OperandRangeRange mapOperands, ArrayRef< int32_t > numDimsPerMap)
ParseResult parseMultiDimAndSymbolList(OpAsmParser &parser, SmallVectorImpl< SmallVector< OpAsmParser::UnresolvedOperand > > &multiMapOperands, DenseI32ArrayAttr &numDimsPerMap)
ParseResult parseDimAndSymbolList(OpAsmParser &parser, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &mapOperands, IntegerAttr &numDims)
ParseResult parseAttrDictWithWarnings(OpAsmParser &parser, NamedAttrList &extraAttrs, OperationState &state)
void printMultiDimAndSymbolList(OpAsmPrinter &printer, Operation *, OperandRangeRange multiMapOperands, DenseI32ArrayAttr numDimsPerMap)
void printDimAndSymbolList(OpAsmPrinter &printer, Operation *, OperandRange mapOperands, IntegerAttr numDims)
void printAttrDictWithWarnings(mlir::OpAsmPrinter &printer, ConcreteOp, mlir::DictionaryAttr extraAttrs, typename ConcreteOp::Properties)
FailureOr< Attribute > forceIntAttrType(Attribute attr, EmitErrorFn emitError)
void printTemplateParams(mlir::AsmPrinter &printer, mlir::ArrayAttr value)
void printDimAndSymbolList(mlir::OpAsmPrinter &printer, mlir::Operation *op, mlir::OperandRange mapOperands, mlir::IntegerAttr numDims)
void printAttrs(AsmPrinter &printer, ArrayRef< Attribute > attrs, const StringRef &separator)
OpClass getParentOfType(mlir::Operation *op)
Return the closest surrounding parent/ancestor operation that is of type 'OpClass'.
mlir::ParseResult parseAttrDictWithWarnings(mlir::OpAsmParser &parser, mlir::NamedAttrList &extraAttrs, mlir::OperationState &state)
void printMultiDimAndSymbolList(mlir::OpAsmPrinter &printer, mlir::Operation *op, mlir::OperandRangeRange multiMapOperands, mlir::DenseI32ArrayAttr numDimsPerMap)
void printAttrDictWithWarnings(mlir::OpAsmPrinter &printer, ConcreteOp op, mlir::DictionaryAttr extraAttrs, typename mlir::PropertiesSelector< ConcreteOp >::type state)
mlir::ParseResult parseTemplateParams(mlir::AsmParser &parser, mlir::ArrayAttr &value)
mlir::ParseResult parseMultiDimAndSymbolList(mlir::OpAsmParser &parser, mlir::SmallVector< mlir::SmallVector< mlir::OpAsmParser::UnresolvedOperand > > &multiMapOperands, mlir::DenseI32ArrayAttr &numDimsPerMap)
llvm::StringLiteral getOperationName()
Get the operation name, like "constrain.eq" for the given OpClass.
bool hasParentThatIsa(mlir::Operation *op)
Return true if the parameter has a parent/ancestor op that is an instance of one of the template type...
OpClass getSelfOrParentOfType(mlir::Operation *op)
Return the closest surrounding parent/ancestor operation that is of type 'OpClass',...
mlir::ParseResult parseDimAndSymbolList(mlir::OpAsmParser &parser, mlir::SmallVector< mlir::OpAsmParser::UnresolvedOperand, N > &mapOperands, mlir::IntegerAttr &numDims)
static mlir::LogicalResult verifyRegionTrait(mlir::Operation *op)
See HasAncestor ODS documentation for details.