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>()) {
63template <
typename TypeClass>
67 :
public mlir::OpTrait::TraitBase<TypeClass, LLZKSymbolTableImplTrait> {
73 while ((op = op->getParentWithTrait<mlir::OpTrait::SymbolTable>())) {
74 if (mlir::failed(mlir::detail::verifySymbolTable(op))) {
75 return mlir::failure();
78 return mlir::success();
85 template <
typename TypeClass>
class Impl :
public mlir::OpTrait::TraitBase<TypeClass, Impl> {
86 inline static mlir::LogicalResult verifyHelper(mlir::Operation *op, int32_t segmentSize) {
87 TypeClass c = llvm::cast<TypeClass>(op);
89 op, segmentSize, c.getMapOpGroupSizesAttr(), c.getMapOperands(), c.getNumDimsPerMapAttr()
95 if (TypeClass::template hasTrait<mlir::OpTrait::AttrSizedOperandSegments>()) {
98 OperandSegmentIndex >= 0,
99 "When the `AttrSizedOperandSegments` trait is present, the index of `$mapOperands` "
100 "within the `operandSegmentSizes` attribute must be specified."
102 mlir::DenseI32ArrayAttr segmentSizes = op->getAttrOfType<mlir::DenseI32ArrayAttr>(
103 mlir::OpTrait::AttrSizedOperandSegments<TypeClass>::getOperandSegmentSizeAttr()
106 OperandSegmentIndex < segmentSizes.size() &&
107 "Parameter of `VerifySizesForMultiAffineOps` exceeds the number of ODS-declared "
110 return verifyHelper(op, segmentSizes[OperandSegmentIndex]);
114 return verifyHelper(op, -1);
122 mlir::OpAsmParser &parser,
123 mlir::SmallVector<mlir::OpAsmParser::UnresolvedOperand, N> &mapOperands,
124 mlir::IntegerAttr &numDims
130 mlir::OpAsmPrinter &printer, mlir::Operation *op, mlir::OperandRange mapOperands,
131 mlir::IntegerAttr numDims
137 mlir::OpAsmParser &parser,
138 mlir::SmallVector<mlir::SmallVector<mlir::OpAsmParser::UnresolvedOperand>> &multiMapOperands,
139 mlir::DenseI32ArrayAttr &numDimsPerMap
145 mlir::OpAsmPrinter &printer, mlir::Operation *op, mlir::OperandRangeRange multiMapOperands,
146 mlir::DenseI32ArrayAttr numDimsPerMap
152 mlir::OpAsmParser &parser, mlir::NamedAttrList &extraAttrs, mlir::OperationState &state
157template <
typename ConcreteOp>
159 mlir::OpAsmPrinter &printer, ConcreteOp op, mlir::DictionaryAttr extraAttrs,
160 typename mlir::PropertiesSelector<ConcreteOp>::type state
166 mlir::SmallVector<mlir::Attribute> elements;
167 auto parseElement = [&]() -> mlir::ParseResult {
169 if (mlir::succeeded(parser.parseOptionalQuestion())) {
170 elements.push_back(parser.getBuilder().getIndexAttr(mlir::ShapedType::kDynamic));
171 return mlir::success();
174 if (mlir::failed(attrParseResult)) {
175 return parser.emitError(
176 parser.getCurrentLocation(),
"failed to parse template parameter attribute"
179 auto emitError = [&parser] {
182 mlir::FailureOr<mlir::Attribute> forced =
forceIntAttrType(*attrParseResult, emitError);
183 if (mlir::failed(forced)) {
184 return mlir::failure();
186 elements.push_back(*forced);
187 return mlir::success();
189 auto res = parser.parseCommaSeparatedList(mlir::AsmParser::Delimiter::Square, parseElement);
190 if (mlir::failed(res)) {
193 value = parser.getBuilder().getArrayAttr(elements);
194 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.
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)