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/SmallString.h>
25#include <llvm/ADT/StringRef.h>
33 return OpClass::getOperationName();
40 if (OpClass self = llvm::dyn_cast<OpClass>(op)) {
43 if (OpClass parent = op->getParentOfType<OpClass>()) {
53 if (OpClass p = op->getParentOfType<OpClass>()) {
63 while ((op = op->getParentOp())) {
64 if (llvm::isa<OpTys...>(op)) {
72template <
typename TypeClass>
76 :
public mlir::OpTrait::TraitBase<TypeClass, LLZKSymbolTableImplTrait> {
82 while ((op = op->getParentWithTrait<mlir::OpTrait::SymbolTable>())) {
83 if (mlir::failed(mlir::detail::verifySymbolTable(op))) {
84 return mlir::failure();
87 return mlir::success();
93 template <
typename ConcreteType>
99 diag <<
'\'' << ConcreteType::getOperationName() <<
'\'';
102 template <
typename ConcreteType>
105 struct Impl :
public mlir::OpTrait::TraitBase<ConcreteType, Impl> {
108 return mlir::success();
110 auto diag = op->emitOpError();
112 if constexpr (
sizeof...(Ancestors) == 1) {
113 diag <<
"must have an ancestor of type ";
115 diag <<
"must have an ancestor of one of the following types: ";
129 template <
typename TypeClass>
class Impl :
public mlir::OpTrait::TraitBase<TypeClass, Impl> {
130 inline static mlir::LogicalResult verifyHelper(mlir::Operation *op, int32_t segmentSize) {
131 TypeClass c = llvm::cast<TypeClass>(op);
133 op, segmentSize, c.getMapOpGroupSizesAttr(), c.getMapOperands(), c.getNumDimsPerMapAttr()
139 if (TypeClass::template hasTrait<mlir::OpTrait::AttrSizedOperandSegments>()) {
142 OperandSegmentIndex >= 0,
143 "When the `AttrSizedOperandSegments` trait is present, the index of `$mapOperands` "
144 "within the `operandSegmentSizes` attribute must be specified."
146 mlir::DenseI32ArrayAttr segmentSizes = op->getAttrOfType<mlir::DenseI32ArrayAttr>(
147 mlir::OpTrait::AttrSizedOperandSegments<TypeClass>::getOperandSegmentSizeAttr()
150 OperandSegmentIndex < segmentSizes.size() &&
151 "Parameter of `VerifySizesForMultiAffineOps` exceeds the number of ODS-declared "
154 return verifyHelper(op, segmentSizes[OperandSegmentIndex]);
158 return verifyHelper(op, -1);
166 mlir::OpAsmParser &parser,
167 mlir::SmallVector<mlir::OpAsmParser::UnresolvedOperand, N> &mapOperands,
168 mlir::IntegerAttr &numDims
174 mlir::OpAsmPrinter &printer, mlir::Operation *op, mlir::OperandRange mapOperands,
175 mlir::IntegerAttr numDims
181 mlir::OpAsmParser &parser,
182 mlir::SmallVector<mlir::SmallVector<mlir::OpAsmParser::UnresolvedOperand>> &multiMapOperands,
183 mlir::DenseI32ArrayAttr &numDimsPerMap
189 mlir::OpAsmPrinter &printer, mlir::Operation *op, mlir::OperandRangeRange multiMapOperands,
190 mlir::DenseI32ArrayAttr numDimsPerMap
196 mlir::OpAsmParser &parser, mlir::NamedAttrList &extraAttrs, mlir::OperationState &state
201template <
typename ConcreteOp>
203 mlir::OpAsmPrinter &printer, ConcreteOp op, mlir::DictionaryAttr extraAttrs,
204 typename mlir::PropertiesSelector<ConcreteOp>::type state
210 mlir::SmallVector<mlir::Attribute> elements;
211 auto parseElement = [&]() -> mlir::ParseResult {
213 if (mlir::succeeded(parser.parseOptionalQuestion())) {
214 elements.push_back(parser.getBuilder().getIndexAttr(mlir::ShapedType::kDynamic));
215 return mlir::success();
218 if (mlir::failed(attrParseResult)) {
219 return parser.emitError(
220 parser.getCurrentLocation(),
"failed to parse template parameter attribute"
223 auto emitError = [&parser] {
226 mlir::FailureOr<mlir::Attribute> forced =
forceIntAttrType(*attrParseResult, emitError);
227 if (mlir::failed(forced)) {
228 return mlir::failure();
230 elements.push_back(*forced);
231 return mlir::success();
233 auto res = parser.parseCommaSeparatedList(mlir::AsmParser::Delimiter::Square, parseElement);
234 if (mlir::failed(res)) {
237 value = parser.getBuilder().getArrayAttr(elements);
238 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.
static void appendTypeName(mlir::InFlightDiagnostic &diag, bool &first)