/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ |* *| |* Op Definitions *| |* *| |* Automatically generated file, do not edit! *| |* From: PDLOps.td *| |* *| \*===----------------------------------------------------------------------===*/ #ifdef GET_OP_LIST #undef GET_OP_LIST ::mlir::pdl::ApplyNativeConstraintOp, ::mlir::pdl::ApplyNativeRewriteOp, ::mlir::pdl::AttributeOp, ::mlir::pdl::EraseOp, ::mlir::pdl::OperandOp, ::mlir::pdl::OperandsOp, ::mlir::pdl::OperationOp, ::mlir::pdl::PatternOp, ::mlir::pdl::RangeOp, ::mlir::pdl::ReplaceOp, ::mlir::pdl::ResultOp, ::mlir::pdl::ResultsOp, ::mlir::pdl::RewriteOp, ::mlir::pdl::TypeOp, ::mlir::pdl::TypesOp #endif // GET_OP_LIST #ifdef GET_OP_CLASSES #undef GET_OP_CLASSES //===----------------------------------------------------------------------===// // Local Utility Method Definitions //===----------------------------------------------------------------------===// static ::llvm::LogicalResult __mlir_ods_local_type_constraint_PDLOps1( ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, unsigned valueIndex) { if (!((::llvm::isa<::mlir::pdl::PDLType>(type)))) { return op->emitOpError(valueKind) << " #" << valueIndex << " must be variadic of pdl type, but got " << type; } return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_type_constraint_PDLOps2( ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, unsigned valueIndex) { if (!((::llvm::isa<::mlir::pdl::TypeType>(type)))) { return op->emitOpError(valueKind) << " #" << valueIndex << " must be PDL handle to an `mlir::Type`, but got " << type; } return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_type_constraint_PDLOps3( ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, unsigned valueIndex) { if (!((::llvm::isa<::mlir::pdl::AttributeType>(type)))) { return op->emitOpError(valueKind) << " #" << valueIndex << " must be PDL handle to an `mlir::Attribute`, but got " << type; } return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_type_constraint_PDLOps4( ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, unsigned valueIndex) { if (!((::llvm::isa<::mlir::pdl::OperationType>(type)))) { return op->emitOpError(valueKind) << " #" << valueIndex << " must be PDL handle to an `mlir::Operation *`, but got " << type; } return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_type_constraint_PDLOps5( ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, unsigned valueIndex) { if (!((::llvm::isa<::mlir::pdl::ValueType>(type)))) { return op->emitOpError(valueKind) << " #" << valueIndex << " must be PDL handle for an `mlir::Value`, but got " << type; } return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_type_constraint_PDLOps6( ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, unsigned valueIndex) { if (!(((::llvm::isa<::mlir::pdl::RangeType>(type))) && ((::llvm::isa<::mlir::pdl::TypeType>(::llvm::cast<::mlir::pdl::RangeType>(type).getElementType()))))) { return op->emitOpError(valueKind) << " #" << valueIndex << " must be range of PDL handle to an `mlir::Type` values, but got " << type; } return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_type_constraint_PDLOps7( ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, unsigned valueIndex) { if (!(((::llvm::isa<::mlir::pdl::RangeType>(type))) && ((::llvm::isa<::mlir::pdl::ValueType>(::llvm::cast<::mlir::pdl::RangeType>(type).getElementType()))))) { return op->emitOpError(valueKind) << " #" << valueIndex << " must be range of PDL handle for an `mlir::Value` values, but got " << type; } return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_type_constraint_PDLOps8( ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, unsigned valueIndex) { if (!(((::llvm::isa<::mlir::pdl::ValueType>(type))) || (((::llvm::isa<::mlir::pdl::RangeType>(type))) && ((::llvm::isa<::mlir::pdl::ValueType>(::llvm::cast<::mlir::pdl::RangeType>(type).getElementType())))))) { return op->emitOpError(valueKind) << " #" << valueIndex << " must be variadic of single element or range of PDL handle for an `mlir::Value`, but got " << type; } return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_type_constraint_PDLOps9( ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, unsigned valueIndex) { if (!((::llvm::isa<::mlir::pdl::AttributeType>(type)))) { return op->emitOpError(valueKind) << " #" << valueIndex << " must be variadic of PDL handle to an `mlir::Attribute`, but got " << type; } return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_type_constraint_PDLOps10( ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, unsigned valueIndex) { if (!(((::llvm::isa<::mlir::pdl::TypeType>(type))) || (((::llvm::isa<::mlir::pdl::RangeType>(type))) && ((::llvm::isa<::mlir::pdl::TypeType>(::llvm::cast<::mlir::pdl::RangeType>(type).getElementType())))))) { return op->emitOpError(valueKind) << " #" << valueIndex << " must be variadic of single element or range of PDL handle to an `mlir::Type`, but got " << type; } return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_type_constraint_PDLOps11( ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, unsigned valueIndex) { if (!(((::llvm::isa<::mlir::pdl::RangeType>(type))) && (((::llvm::isa<::mlir::pdl::TypeType>(::llvm::cast<::mlir::pdl::RangeType>(type).getElementType()))) || ((::llvm::isa<::mlir::pdl::ValueType>(::llvm::cast<::mlir::pdl::RangeType>(type).getElementType())))))) { return op->emitOpError(valueKind) << " #" << valueIndex << " must be range of PDL handle to an `mlir::Type` or PDL handle for an `mlir::Value` values, but got " << type; } return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_type_constraint_PDLOps12( ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, unsigned valueIndex) { if (!(((::llvm::isa<::mlir::pdl::ValueType>(type))) || (((::llvm::isa<::mlir::pdl::RangeType>(type))) && ((::llvm::isa<::mlir::pdl::ValueType>(::llvm::cast<::mlir::pdl::RangeType>(type).getElementType())))))) { return op->emitOpError(valueKind) << " #" << valueIndex << " must be single element or range of PDL handle for an `mlir::Value`, but got " << type; } return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_PDLOps1( ::mlir::Attribute attr, ::llvm::StringRef attrName, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { if (attr && !((::llvm::isa<::mlir::StringAttr>(attr)))) return emitError() << "attribute '" << attrName << "' failed to satisfy constraint: string attribute"; return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_PDLOps1( ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { return __mlir_ods_local_attr_constraint_PDLOps1(attr, attrName, [op]() { return op->emitOpError(); }); } static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_PDLOps2( ::mlir::Attribute attr, ::llvm::StringRef attrName, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { if (attr && !((::llvm::isa<::mlir::BoolAttr>(attr)))) return emitError() << "attribute '" << attrName << "' failed to satisfy constraint: bool attribute"; return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_PDLOps2( ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { return __mlir_ods_local_attr_constraint_PDLOps2(attr, attrName, [op]() { return op->emitOpError(); }); } static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_PDLOps3( ::mlir::Attribute attr, ::llvm::StringRef attrName, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { if (attr && !((true))) return emitError() << "attribute '" << attrName << "' failed to satisfy constraint: any attribute"; return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_PDLOps3( ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { return __mlir_ods_local_attr_constraint_PDLOps3(attr, attrName, [op]() { return op->emitOpError(); }); } static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_PDLOps4( ::mlir::Attribute attr, ::llvm::StringRef attrName, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { if (attr && !(((::llvm::isa<::mlir::ArrayAttr>(attr))) && (::llvm::all_of(::llvm::cast<::mlir::ArrayAttr>(attr), [&](::mlir::Attribute attr) { return attr && ((::llvm::isa<::mlir::StringAttr>(attr))); })))) return emitError() << "attribute '" << attrName << "' failed to satisfy constraint: string array attribute"; return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_PDLOps4( ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { return __mlir_ods_local_attr_constraint_PDLOps4(attr, attrName, [op]() { return op->emitOpError(); }); } static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_PDLOps5( ::mlir::Attribute attr, ::llvm::StringRef attrName, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { if (attr && !((((::llvm::isa<::mlir::IntegerAttr>(attr))) && ((::llvm::cast<::mlir::IntegerAttr>(attr).getType().isSignlessInteger(16)))) && ((!::llvm::cast<::mlir::IntegerAttr>(attr).getValue().isNegative())))) return emitError() << "attribute '" << attrName << "' failed to satisfy constraint: 16-bit signless integer attribute whose value is non-negative"; return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_PDLOps5( ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { return __mlir_ods_local_attr_constraint_PDLOps5(attr, attrName, [op]() { return op->emitOpError(); }); } static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_PDLOps6( ::mlir::Attribute attr, ::llvm::StringRef attrName, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { if (attr && !(((::llvm::isa<::mlir::IntegerAttr>(attr))) && ((::llvm::cast<::mlir::IntegerAttr>(attr).getType().isSignlessInteger(32))))) return emitError() << "attribute '" << attrName << "' failed to satisfy constraint: 32-bit signless integer attribute"; return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_PDLOps6( ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { return __mlir_ods_local_attr_constraint_PDLOps6(attr, attrName, [op]() { return op->emitOpError(); }); } static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_PDLOps7( ::mlir::Attribute attr, ::llvm::StringRef attrName, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { if (attr && !(((::llvm::isa<::mlir::TypeAttr>(attr))) && ((::llvm::isa<::mlir::Type>(::llvm::cast<::mlir::TypeAttr>(attr).getValue()))) && ((true)))) return emitError() << "attribute '" << attrName << "' failed to satisfy constraint: any type attribute"; return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_PDLOps7( ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { return __mlir_ods_local_attr_constraint_PDLOps7(attr, attrName, [op]() { return op->emitOpError(); }); } static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_PDLOps8( ::mlir::Attribute attr, ::llvm::StringRef attrName, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { if (attr && !(((::llvm::isa<::mlir::ArrayAttr>(attr))) && (::llvm::all_of(::llvm::cast<::mlir::ArrayAttr>(attr), [&](::mlir::Attribute attr) { return attr && (((::llvm::isa<::mlir::TypeAttr>(attr))) && ((::llvm::isa<::mlir::Type>(::llvm::cast<::mlir::TypeAttr>(attr).getValue()))) && ((true))); })))) return emitError() << "attribute '" << attrName << "' failed to satisfy constraint: type array attribute"; return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_PDLOps8( ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { return __mlir_ods_local_attr_constraint_PDLOps8(attr, attrName, [op]() { return op->emitOpError(); }); } static ::llvm::LogicalResult __mlir_ods_local_region_constraint_PDLOps1( ::mlir::Operation *op, ::mlir::Region ®ion, ::llvm::StringRef regionName, unsigned regionIndex) { if (!((::llvm::hasNItems(region, 1)))) { return op->emitOpError("region #") << regionIndex << (regionName.empty() ? " " : " ('" + regionName + "') ") << "failed to verify constraint: region with 1 blocks"; } return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_region_constraint_PDLOps2( ::mlir::Operation *op, ::mlir::Region ®ion, ::llvm::StringRef regionName, unsigned regionIndex) { if (!((true))) { return op->emitOpError("region #") << regionIndex << (regionName.empty() ? " " : " ('" + regionName + "') ") << "failed to verify constraint: any region"; } return ::mlir::success(); } namespace mlir::pdl { //===----------------------------------------------------------------------===// // ::mlir::pdl::ApplyNativeConstraintOp definitions //===----------------------------------------------------------------------===// namespace detail { ApplyNativeConstraintOpGenericAdaptorBase::ApplyNativeConstraintOpGenericAdaptorBase(ApplyNativeConstraintOp op) : odsAttrs(op->getRawDictionaryAttrs()), odsOpName(op->getName()), properties(op.getProperties()), odsRegions(op->getRegions()) {} std::pair ApplyNativeConstraintOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { bool isVariadic[] = {true}; int prevVariadicCount = 0; for (unsigned i = 0; i < index; ++i) if (isVariadic[i]) ++prevVariadicCount; // Calculate how many dynamic values a static variadic operand corresponds to. // This assumes all static variadic operands have the same dynamic value count. int variadicSize = (odsOperandsSize - 0) / 1; // `index` passed in as the parameter is the static index which counts each // operand (variadic or not) as size 1. So here for each previous static variadic // operand, we need to offset by (variadicSize - 1) to get where the dynamic // value pack for this static operand starts. int start = index + (variadicSize - 1) * prevVariadicCount; int size = isVariadic[index] ? variadicSize : 1; return {start, size}; } ::llvm::StringRef ApplyNativeConstraintOpGenericAdaptorBase::getName() { auto attr = getNameAttr(); return attr.getValue(); } ::mlir::BoolAttr ApplyNativeConstraintOpGenericAdaptorBase::getIsNegatedAttr() { auto attr = ::llvm::dyn_cast_or_null<::mlir::BoolAttr>(getProperties().isNegated); return attr; } bool ApplyNativeConstraintOpGenericAdaptorBase::getIsNegated() { auto attr = getIsNegatedAttr(); return attr.getValue(); } } // namespace detail ApplyNativeConstraintOpAdaptor::ApplyNativeConstraintOpAdaptor(ApplyNativeConstraintOp op) : ApplyNativeConstraintOpGenericAdaptor(op->getOperands(), op) {} ::llvm::LogicalResult ApplyNativeConstraintOpAdaptor::verify(::mlir::Location loc) { auto tblgen_isNegated = getProperties().isNegated; (void)tblgen_isNegated; auto tblgen_name = getProperties().name; (void)tblgen_name; if (!tblgen_name) return emitError(loc, "'pdl.apply_native_constraint' op requires attribute 'name'"); if (tblgen_name && !((::llvm::isa<::mlir::StringAttr>(tblgen_name)))) return emitError(loc, "'pdl.apply_native_constraint' op attribute 'name' failed to satisfy constraint: string attribute"); if (tblgen_isNegated && !((::llvm::isa<::mlir::BoolAttr>(tblgen_isNegated)))) return emitError(loc, "'pdl.apply_native_constraint' op attribute 'isNegated' failed to satisfy constraint: bool attribute"); return ::mlir::success(); } std::pair ApplyNativeConstraintOp::getODSOperandIndexAndLength(unsigned index) { bool isVariadic[] = {true}; int prevVariadicCount = 0; for (unsigned i = 0; i < index; ++i) if (isVariadic[i]) ++prevVariadicCount; // Calculate how many dynamic values a static variadic operand corresponds to. // This assumes all static variadic operands have the same dynamic value count. int variadicSize = (getOperation()->getNumOperands() - 0) / 1; // `index` passed in as the parameter is the static index which counts each // operand (variadic or not) as size 1. So here for each previous static variadic // operand, we need to offset by (variadicSize - 1) to get where the dynamic // value pack for this static operand starts. int start = index + (variadicSize - 1) * prevVariadicCount; int size = isVariadic[index] ? variadicSize : 1; return {start, size}; } ::mlir::MutableOperandRange ApplyNativeConstraintOp::getArgsMutable() { auto range = getODSOperandIndexAndLength(0); auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); return mutableRange; } std::pair ApplyNativeConstraintOp::getODSResultIndexAndLength(unsigned index) { bool isVariadic[] = {true}; int prevVariadicCount = 0; for (unsigned i = 0; i < index; ++i) if (isVariadic[i]) ++prevVariadicCount; // Calculate how many dynamic values a static variadic operand corresponds to. // This assumes all static variadic operands have the same dynamic value count. int variadicSize = (getOperation()->getNumResults() - 0) / 1; // `index` passed in as the parameter is the static index which counts each // operand (variadic or not) as size 1. So here for each previous static variadic // operand, we need to offset by (variadicSize - 1) to get where the dynamic // value pack for this static operand starts. int start = index + (variadicSize - 1) * prevVariadicCount; int size = isVariadic[index] ? variadicSize : 1; return {start, size}; } ::llvm::LogicalResult ApplyNativeConstraintOp::setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { ::mlir::DictionaryAttr dict = ::llvm::dyn_cast<::mlir::DictionaryAttr>(attr); if (!dict) { emitError() << "expected DictionaryAttr to set properties"; return ::mlir::failure(); } { auto &propStorage = prop.isNegated; auto attr = dict.get("isNegated"); if (attr) { auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `isNegated` in property conversion: " << attr; return ::mlir::failure(); } } } { auto &propStorage = prop.name; auto attr = dict.get("name"); if (attr) { auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `name` in property conversion: " << attr; return ::mlir::failure(); } } } return ::mlir::success(); } ::mlir::Attribute ApplyNativeConstraintOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) { ::mlir::SmallVector<::mlir::NamedAttribute> attrs; ::mlir::Builder odsBuilder{ctx}; { const auto &propStorage = prop.isNegated; if (propStorage) attrs.push_back(odsBuilder.getNamedAttr("isNegated", propStorage)); } { const auto &propStorage = prop.name; if (propStorage) attrs.push_back(odsBuilder.getNamedAttr("name", propStorage)); } if (!attrs.empty()) return odsBuilder.getDictionaryAttr(attrs); return {}; } llvm::hash_code ApplyNativeConstraintOp::computePropertiesHash(const Properties &prop) { using llvm::hash_value; return llvm::hash_combine( llvm::hash_value(prop.isNegated.getAsOpaquePointer()), llvm::hash_value(prop.name.getAsOpaquePointer())); } std::optional ApplyNativeConstraintOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { if (name == "isNegated") return prop.isNegated; if (name == "name") return prop.name; return std::nullopt; } void ApplyNativeConstraintOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { if (name == "isNegated") { prop.isNegated = ::llvm::dyn_cast_or_null>(value); return; } if (name == "name") { prop.name = ::llvm::dyn_cast_or_null>(value); return; } } void ApplyNativeConstraintOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { if (prop.isNegated) attrs.append("isNegated", prop.isNegated); if (prop.name) attrs.append("name", prop.name); } ::llvm::LogicalResult ApplyNativeConstraintOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { { ::mlir::Attribute attr = attrs.get(getIsNegatedAttrName(opName)); if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_PDLOps2(attr, "isNegated", emitError))) return ::mlir::failure(); } { ::mlir::Attribute attr = attrs.get(getNameAttrName(opName)); if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_PDLOps1(attr, "name", emitError))) return ::mlir::failure(); } return ::mlir::success(); } ::llvm::LogicalResult ApplyNativeConstraintOp::readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state) { auto &prop = state.getOrAddProperties(); (void)prop; if (::mlir::failed(reader.readOptionalAttribute(prop.isNegated))) return ::mlir::failure(); if (::mlir::failed(reader.readAttribute(prop.name))) return ::mlir::failure(); return ::mlir::success(); } void ApplyNativeConstraintOp::writeProperties(::mlir::DialectBytecodeWriter &writer) { auto &prop = getProperties(); (void)prop; writer.writeOptionalAttribute(prop.isNegated); writer.writeAttribute(prop.name); } ::llvm::StringRef ApplyNativeConstraintOp::getName() { auto attr = getNameAttr(); return attr.getValue(); } bool ApplyNativeConstraintOp::getIsNegated() { auto attr = getIsNegatedAttr(); return attr.getValue(); } void ApplyNativeConstraintOp::setName(::llvm::StringRef attrValue) { getProperties().name = ::mlir::Builder((*this)->getContext()).getStringAttr(attrValue); } void ApplyNativeConstraintOp::setIsNegated(bool attrValue) { getProperties().isNegated = ::mlir::Builder((*this)->getContext()).getBoolAttr(attrValue); } void ApplyNativeConstraintOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange results, ::mlir::StringAttr name, ::mlir::ValueRange args, ::mlir::BoolAttr isNegated) { odsState.addOperands(args); odsState.getOrAddProperties().name = name; if (isNegated) { odsState.getOrAddProperties().isNegated = isNegated; } odsState.addTypes(results); } ApplyNativeConstraintOp ApplyNativeConstraintOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange results, ::mlir::StringAttr name, ::mlir::ValueRange args, ::mlir::BoolAttr isNegated) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(results), std::forward(name), std::forward(args), std::forward(isNegated)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } ApplyNativeConstraintOp ApplyNativeConstraintOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange results, ::mlir::StringAttr name, ::mlir::ValueRange args, ::mlir::BoolAttr isNegated) { return create(builder, builder.getLoc(), std::forward(results), std::forward(name), std::forward(args), std::forward(isNegated)); } void ApplyNativeConstraintOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange results, ::llvm::StringRef name, ::mlir::ValueRange args, bool isNegated) { odsState.addOperands(args); odsState.getOrAddProperties().name = odsBuilder.getStringAttr(name); odsState.getOrAddProperties().isNegated = odsBuilder.getBoolAttr(isNegated); odsState.addTypes(results); } ApplyNativeConstraintOp ApplyNativeConstraintOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange results, ::llvm::StringRef name, ::mlir::ValueRange args, bool isNegated) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(results), std::forward(name), std::forward(args), std::forward(isNegated)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } ApplyNativeConstraintOp ApplyNativeConstraintOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange results, ::llvm::StringRef name, ::mlir::ValueRange args, bool isNegated) { return create(builder, builder.getLoc(), std::forward(results), std::forward(name), std::forward(args), std::forward(isNegated)); } void ApplyNativeConstraintOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { odsState.addOperands(operands); odsState.addAttributes(attributes); odsState.addTypes(resultTypes); if (!attributes.empty()) { (void)odsState.getOrAddProperties(); ::mlir::PropertyRef properties = odsState.getRawProperties(); std::optional<::mlir::RegisteredOperationName> info = odsState.name.getRegisteredInfo(); if (failed(info->setOpPropertiesFromAttribute(odsState.name, properties, odsState.attributes.getDictionary(odsState.getContext()), nullptr))) ::llvm::report_fatal_error("Property conversion failed."); } } ApplyNativeConstraintOp ApplyNativeConstraintOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(attributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } ApplyNativeConstraintOp ApplyNativeConstraintOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(attributes)); } void ApplyNativeConstraintOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { odsState.addOperands(operands); odsState.useProperties(const_cast(properties)); odsState.addAttributes(discardableAttributes); odsState.addTypes(resultTypes); } ApplyNativeConstraintOp ApplyNativeConstraintOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } ApplyNativeConstraintOp ApplyNativeConstraintOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); } void ApplyNativeConstraintOp::populateDefaultProperties(::mlir::OperationName opName, Properties &properties) { ::mlir::Builder odsBuilder(opName.getContext()); if (!properties.isNegated) properties.isNegated = odsBuilder.getBoolAttr(false); } ::llvm::LogicalResult ApplyNativeConstraintOp::verifyInvariantsImpl() { auto tblgen_isNegated = getProperties().isNegated; (void)tblgen_isNegated; auto tblgen_name = getProperties().name; (void)tblgen_name; if (!tblgen_name) return emitOpError("requires attribute 'name'"); if (::mlir::failed(__mlir_ods_local_attr_constraint_PDLOps1(*this, tblgen_name, "name"))) return ::mlir::failure(); if (::mlir::failed(__mlir_ods_local_attr_constraint_PDLOps2(*this, tblgen_isNegated, "isNegated"))) return ::mlir::failure(); { unsigned index = 0; (void)index; auto valueGroup0 = getODSOperands(0); for (auto v : valueGroup0) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps1(*this, v.getType(), "operand", index++))) return ::mlir::failure(); } } { unsigned index = 0; (void)index; auto valueGroup0 = getODSResults(0); for (auto v : valueGroup0) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps1(*this, v.getType(), "result", index++))) return ::mlir::failure(); } } return ::mlir::success(); } ::llvm::LogicalResult ApplyNativeConstraintOp::verifyInvariants() { if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) return ::mlir::success(); return ::mlir::failure(); } ::mlir::ParseResult ApplyNativeConstraintOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { ::mlir::StringAttr nameAttr; ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> argsOperands; ::llvm::SMLoc argsOperandsLoc; (void)argsOperandsLoc; ::llvm::SmallVector<::mlir::Type, 1> argsTypes; ::llvm::SmallVector<::mlir::Type, 1> resultsTypes; if (parser.parseCustomAttributeWithFallback(nameAttr, parser.getBuilder().getType<::mlir::NoneType>())) { return ::mlir::failure(); } if (nameAttr) result.getOrAddProperties().name = nameAttr; if (parser.parseLParen()) return ::mlir::failure(); argsOperandsLoc = parser.getCurrentLocation(); if (parser.parseOperandList(argsOperands)) return ::mlir::failure(); if (parser.parseColon()) return ::mlir::failure(); if (parser.parseTypeList(argsTypes)) return ::mlir::failure(); if (parser.parseRParen()) return ::mlir::failure(); if (::mlir::succeeded(parser.parseOptionalColon())) { if (parser.parseTypeList(resultsTypes)) return ::mlir::failure(); } { auto loc = parser.getCurrentLocation();(void)loc; if (parser.parseOptionalAttrDict(result.attributes)) return ::mlir::failure(); if (failed(verifyInherentAttrs(result.name, result.attributes, [&]() { return parser.emitError(loc) << "'" << result.name.getStringRef() << "' op "; }))) return ::mlir::failure(); } result.addTypes(resultsTypes); if (parser.resolveOperands(argsOperands, argsTypes, argsOperandsLoc, result.operands)) return ::mlir::failure(); return ::mlir::success(); } void ApplyNativeConstraintOp::print(::mlir::OpAsmPrinter &_odsPrinter) { _odsPrinter << ' '; _odsPrinter.printAttributeWithoutType(getNameAttr()); _odsPrinter << "("; _odsPrinter << getArgs(); _odsPrinter << ' ' << ":"; _odsPrinter << ' '; _odsPrinter << getArgs().getTypes(); _odsPrinter << ")"; if (!getResults().empty()) { _odsPrinter << ' ' << ":"; _odsPrinter << ' '; _odsPrinter << getResults().getTypes(); } ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; elidedAttrs.push_back("name"); { ::mlir::Builder odsBuilder(getContext()); ::mlir::Attribute attr = getIsNegatedAttr(); if(attr && (attr == odsBuilder.getBoolAttr(false))) elidedAttrs.push_back("isNegated"); } _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); } } // namespace mlir::pdl MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::pdl::ApplyNativeConstraintOp) MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::pdl::detail::ApplyNativeConstraintOpGenericAdaptorBase::Properties) namespace mlir::pdl { //===----------------------------------------------------------------------===// // ::mlir::pdl::ApplyNativeRewriteOp definitions //===----------------------------------------------------------------------===// namespace detail { ApplyNativeRewriteOpGenericAdaptorBase::ApplyNativeRewriteOpGenericAdaptorBase(ApplyNativeRewriteOp op) : odsAttrs(op->getRawDictionaryAttrs()), odsOpName(op->getName()), properties(op.getProperties()), odsRegions(op->getRegions()) {} std::pair ApplyNativeRewriteOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { bool isVariadic[] = {true}; int prevVariadicCount = 0; for (unsigned i = 0; i < index; ++i) if (isVariadic[i]) ++prevVariadicCount; // Calculate how many dynamic values a static variadic operand corresponds to. // This assumes all static variadic operands have the same dynamic value count. int variadicSize = (odsOperandsSize - 0) / 1; // `index` passed in as the parameter is the static index which counts each // operand (variadic or not) as size 1. So here for each previous static variadic // operand, we need to offset by (variadicSize - 1) to get where the dynamic // value pack for this static operand starts. int start = index + (variadicSize - 1) * prevVariadicCount; int size = isVariadic[index] ? variadicSize : 1; return {start, size}; } ::llvm::StringRef ApplyNativeRewriteOpGenericAdaptorBase::getName() { auto attr = getNameAttr(); return attr.getValue(); } } // namespace detail ApplyNativeRewriteOpAdaptor::ApplyNativeRewriteOpAdaptor(ApplyNativeRewriteOp op) : ApplyNativeRewriteOpGenericAdaptor(op->getOperands(), op) {} ::llvm::LogicalResult ApplyNativeRewriteOpAdaptor::verify(::mlir::Location loc) { auto tblgen_name = getProperties().name; (void)tblgen_name; if (!tblgen_name) return emitError(loc, "'pdl.apply_native_rewrite' op requires attribute 'name'"); if (tblgen_name && !((::llvm::isa<::mlir::StringAttr>(tblgen_name)))) return emitError(loc, "'pdl.apply_native_rewrite' op attribute 'name' failed to satisfy constraint: string attribute"); return ::mlir::success(); } std::pair ApplyNativeRewriteOp::getODSOperandIndexAndLength(unsigned index) { bool isVariadic[] = {true}; int prevVariadicCount = 0; for (unsigned i = 0; i < index; ++i) if (isVariadic[i]) ++prevVariadicCount; // Calculate how many dynamic values a static variadic operand corresponds to. // This assumes all static variadic operands have the same dynamic value count. int variadicSize = (getOperation()->getNumOperands() - 0) / 1; // `index` passed in as the parameter is the static index which counts each // operand (variadic or not) as size 1. So here for each previous static variadic // operand, we need to offset by (variadicSize - 1) to get where the dynamic // value pack for this static operand starts. int start = index + (variadicSize - 1) * prevVariadicCount; int size = isVariadic[index] ? variadicSize : 1; return {start, size}; } ::mlir::MutableOperandRange ApplyNativeRewriteOp::getArgsMutable() { auto range = getODSOperandIndexAndLength(0); auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); return mutableRange; } std::pair ApplyNativeRewriteOp::getODSResultIndexAndLength(unsigned index) { bool isVariadic[] = {true}; int prevVariadicCount = 0; for (unsigned i = 0; i < index; ++i) if (isVariadic[i]) ++prevVariadicCount; // Calculate how many dynamic values a static variadic operand corresponds to. // This assumes all static variadic operands have the same dynamic value count. int variadicSize = (getOperation()->getNumResults() - 0) / 1; // `index` passed in as the parameter is the static index which counts each // operand (variadic or not) as size 1. So here for each previous static variadic // operand, we need to offset by (variadicSize - 1) to get where the dynamic // value pack for this static operand starts. int start = index + (variadicSize - 1) * prevVariadicCount; int size = isVariadic[index] ? variadicSize : 1; return {start, size}; } ::llvm::LogicalResult ApplyNativeRewriteOp::setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { ::mlir::DictionaryAttr dict = ::llvm::dyn_cast<::mlir::DictionaryAttr>(attr); if (!dict) { emitError() << "expected DictionaryAttr to set properties"; return ::mlir::failure(); } { auto &propStorage = prop.name; auto attr = dict.get("name"); if (attr) { auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `name` in property conversion: " << attr; return ::mlir::failure(); } } } return ::mlir::success(); } ::mlir::Attribute ApplyNativeRewriteOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) { ::mlir::SmallVector<::mlir::NamedAttribute> attrs; ::mlir::Builder odsBuilder{ctx}; { const auto &propStorage = prop.name; if (propStorage) attrs.push_back(odsBuilder.getNamedAttr("name", propStorage)); } if (!attrs.empty()) return odsBuilder.getDictionaryAttr(attrs); return {}; } llvm::hash_code ApplyNativeRewriteOp::computePropertiesHash(const Properties &prop) { using llvm::hash_value; return llvm::hash_combine( llvm::hash_value(prop.name.getAsOpaquePointer())); } std::optional ApplyNativeRewriteOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { if (name == "name") return prop.name; return std::nullopt; } void ApplyNativeRewriteOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { if (name == "name") { prop.name = ::llvm::dyn_cast_or_null>(value); return; } } void ApplyNativeRewriteOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { if (prop.name) attrs.append("name", prop.name); } ::llvm::LogicalResult ApplyNativeRewriteOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { { ::mlir::Attribute attr = attrs.get(getNameAttrName(opName)); if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_PDLOps1(attr, "name", emitError))) return ::mlir::failure(); } return ::mlir::success(); } ::llvm::LogicalResult ApplyNativeRewriteOp::readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state) { auto &prop = state.getOrAddProperties(); (void)prop; if (::mlir::failed(reader.readAttribute(prop.name))) return ::mlir::failure(); return ::mlir::success(); } void ApplyNativeRewriteOp::writeProperties(::mlir::DialectBytecodeWriter &writer) { auto &prop = getProperties(); (void)prop; writer.writeAttribute(prop.name); } ::llvm::StringRef ApplyNativeRewriteOp::getName() { auto attr = getNameAttr(); return attr.getValue(); } void ApplyNativeRewriteOp::setName(::llvm::StringRef attrValue) { getProperties().name = ::mlir::Builder((*this)->getContext()).getStringAttr(attrValue); } void ApplyNativeRewriteOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange results, ::mlir::StringAttr name, ::mlir::ValueRange args) { odsState.addOperands(args); odsState.getOrAddProperties().name = name; odsState.addTypes(results); } ApplyNativeRewriteOp ApplyNativeRewriteOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange results, ::mlir::StringAttr name, ::mlir::ValueRange args) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(results), std::forward(name), std::forward(args)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } ApplyNativeRewriteOp ApplyNativeRewriteOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange results, ::mlir::StringAttr name, ::mlir::ValueRange args) { return create(builder, builder.getLoc(), std::forward(results), std::forward(name), std::forward(args)); } void ApplyNativeRewriteOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange results, ::llvm::StringRef name, ::mlir::ValueRange args) { odsState.addOperands(args); odsState.getOrAddProperties().name = odsBuilder.getStringAttr(name); odsState.addTypes(results); } ApplyNativeRewriteOp ApplyNativeRewriteOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange results, ::llvm::StringRef name, ::mlir::ValueRange args) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(results), std::forward(name), std::forward(args)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } ApplyNativeRewriteOp ApplyNativeRewriteOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange results, ::llvm::StringRef name, ::mlir::ValueRange args) { return create(builder, builder.getLoc(), std::forward(results), std::forward(name), std::forward(args)); } void ApplyNativeRewriteOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { odsState.addOperands(operands); odsState.addAttributes(attributes); odsState.addTypes(resultTypes); if (!attributes.empty()) { (void)odsState.getOrAddProperties(); ::mlir::PropertyRef properties = odsState.getRawProperties(); std::optional<::mlir::RegisteredOperationName> info = odsState.name.getRegisteredInfo(); if (failed(info->setOpPropertiesFromAttribute(odsState.name, properties, odsState.attributes.getDictionary(odsState.getContext()), nullptr))) ::llvm::report_fatal_error("Property conversion failed."); } } ApplyNativeRewriteOp ApplyNativeRewriteOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(attributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } ApplyNativeRewriteOp ApplyNativeRewriteOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(attributes)); } void ApplyNativeRewriteOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { odsState.addOperands(operands); odsState.useProperties(const_cast(properties)); odsState.addAttributes(discardableAttributes); odsState.addTypes(resultTypes); } ApplyNativeRewriteOp ApplyNativeRewriteOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } ApplyNativeRewriteOp ApplyNativeRewriteOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); } ::llvm::LogicalResult ApplyNativeRewriteOp::verifyInvariantsImpl() { auto tblgen_name = getProperties().name; (void)tblgen_name; if (!tblgen_name) return emitOpError("requires attribute 'name'"); if (::mlir::failed(__mlir_ods_local_attr_constraint_PDLOps1(*this, tblgen_name, "name"))) return ::mlir::failure(); { unsigned index = 0; (void)index; auto valueGroup0 = getODSOperands(0); for (auto v : valueGroup0) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps1(*this, v.getType(), "operand", index++))) return ::mlir::failure(); } } { unsigned index = 0; (void)index; auto valueGroup0 = getODSResults(0); for (auto v : valueGroup0) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps1(*this, v.getType(), "result", index++))) return ::mlir::failure(); } } return ::mlir::success(); } ::llvm::LogicalResult ApplyNativeRewriteOp::verifyInvariants() { if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) return ::mlir::success(); return ::mlir::failure(); } ::mlir::ParseResult ApplyNativeRewriteOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { ::mlir::StringAttr nameAttr; ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> argsOperands; ::llvm::SMLoc argsOperandsLoc; (void)argsOperandsLoc; ::llvm::SmallVector<::mlir::Type, 1> argsTypes; ::llvm::SmallVector<::mlir::Type, 1> resultsTypes; if (parser.parseCustomAttributeWithFallback(nameAttr, parser.getBuilder().getType<::mlir::NoneType>())) { return ::mlir::failure(); } if (nameAttr) result.getOrAddProperties().name = nameAttr; if (::mlir::succeeded(parser.parseOptionalLParen())) { argsOperandsLoc = parser.getCurrentLocation(); if (parser.parseOperandList(argsOperands)) return ::mlir::failure(); if (parser.parseColon()) return ::mlir::failure(); if (parser.parseTypeList(argsTypes)) return ::mlir::failure(); if (parser.parseRParen()) return ::mlir::failure(); } if (::mlir::succeeded(parser.parseOptionalColon())) { if (parser.parseTypeList(resultsTypes)) return ::mlir::failure(); } { auto loc = parser.getCurrentLocation();(void)loc; if (parser.parseOptionalAttrDict(result.attributes)) return ::mlir::failure(); if (failed(verifyInherentAttrs(result.name, result.attributes, [&]() { return parser.emitError(loc) << "'" << result.name.getStringRef() << "' op "; }))) return ::mlir::failure(); } result.addTypes(resultsTypes); if (parser.resolveOperands(argsOperands, argsTypes, argsOperandsLoc, result.operands)) return ::mlir::failure(); return ::mlir::success(); } void ApplyNativeRewriteOp::print(::mlir::OpAsmPrinter &_odsPrinter) { _odsPrinter << ' '; _odsPrinter.printAttributeWithoutType(getNameAttr()); if (!getArgs().empty()) { _odsPrinter << "("; _odsPrinter << getArgs(); _odsPrinter << ' ' << ":"; _odsPrinter << ' '; _odsPrinter << getArgs().getTypes(); _odsPrinter << ")"; } if (!getResults().empty()) { _odsPrinter << ' ' << ":"; _odsPrinter << ' '; _odsPrinter << getResults().getTypes(); } ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; elidedAttrs.push_back("name"); _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); } } // namespace mlir::pdl MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::pdl::ApplyNativeRewriteOp) MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::pdl::detail::ApplyNativeRewriteOpGenericAdaptorBase::Properties) namespace mlir::pdl { //===----------------------------------------------------------------------===// // ::mlir::pdl::AttributeOp definitions //===----------------------------------------------------------------------===// namespace detail { AttributeOpGenericAdaptorBase::AttributeOpGenericAdaptorBase(AttributeOp op) : odsAttrs(op->getRawDictionaryAttrs()), odsOpName(op->getName()), properties(op.getProperties()), odsRegions(op->getRegions()) {} std::pair AttributeOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { bool isVariadic[] = {true}; int prevVariadicCount = 0; for (unsigned i = 0; i < index; ++i) if (isVariadic[i]) ++prevVariadicCount; // Calculate how many dynamic values a static variadic operand corresponds to. // This assumes all static variadic operands have the same dynamic value count. int variadicSize = (odsOperandsSize - 0) / 1; // `index` passed in as the parameter is the static index which counts each // operand (variadic or not) as size 1. So here for each previous static variadic // operand, we need to offset by (variadicSize - 1) to get where the dynamic // value pack for this static operand starts. int start = index + (variadicSize - 1) * prevVariadicCount; int size = isVariadic[index] ? variadicSize : 1; return {start, size}; } ::std::optional<::mlir::Attribute> AttributeOpGenericAdaptorBase::getValue() { auto attr = getValueAttr(); return attr ? ::std::optional<::mlir::Attribute>(attr) : (::std::nullopt); } } // namespace detail AttributeOpAdaptor::AttributeOpAdaptor(AttributeOp op) : AttributeOpGenericAdaptor(op->getOperands(), op) {} ::llvm::LogicalResult AttributeOpAdaptor::verify(::mlir::Location loc) { auto tblgen_value = getProperties().value; (void)tblgen_value; if (tblgen_value && !((true))) return emitError(loc, "'pdl.attribute' op attribute 'value' failed to satisfy constraint: any attribute"); return ::mlir::success(); } std::pair AttributeOp::getODSOperandIndexAndLength(unsigned index) { bool isVariadic[] = {true}; int prevVariadicCount = 0; for (unsigned i = 0; i < index; ++i) if (isVariadic[i]) ++prevVariadicCount; // Calculate how many dynamic values a static variadic operand corresponds to. // This assumes all static variadic operands have the same dynamic value count. int variadicSize = (getOperation()->getNumOperands() - 0) / 1; // `index` passed in as the parameter is the static index which counts each // operand (variadic or not) as size 1. So here for each previous static variadic // operand, we need to offset by (variadicSize - 1) to get where the dynamic // value pack for this static operand starts. int start = index + (variadicSize - 1) * prevVariadicCount; int size = isVariadic[index] ? variadicSize : 1; return {start, size}; } ::mlir::MutableOperandRange AttributeOp::getValueTypeMutable() { auto range = getODSOperandIndexAndLength(0); auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); return mutableRange; } ::llvm::LogicalResult AttributeOp::setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { ::mlir::DictionaryAttr dict = ::llvm::dyn_cast<::mlir::DictionaryAttr>(attr); if (!dict) { emitError() << "expected DictionaryAttr to set properties"; return ::mlir::failure(); } { auto &propStorage = prop.value; auto attr = dict.get("value"); if (attr) { auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `value` in property conversion: " << attr; return ::mlir::failure(); } } } return ::mlir::success(); } ::mlir::Attribute AttributeOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) { ::mlir::SmallVector<::mlir::NamedAttribute> attrs; ::mlir::Builder odsBuilder{ctx}; { const auto &propStorage = prop.value; if (propStorage) attrs.push_back(odsBuilder.getNamedAttr("value", propStorage)); } if (!attrs.empty()) return odsBuilder.getDictionaryAttr(attrs); return {}; } llvm::hash_code AttributeOp::computePropertiesHash(const Properties &prop) { using llvm::hash_value; return llvm::hash_combine( llvm::hash_value(prop.value.getAsOpaquePointer())); } std::optional AttributeOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { if (name == "value") return prop.value; return std::nullopt; } void AttributeOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { if (name == "value") { prop.value = ::llvm::dyn_cast_or_null>(value); return; } } void AttributeOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { if (prop.value) attrs.append("value", prop.value); } ::llvm::LogicalResult AttributeOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { { ::mlir::Attribute attr = attrs.get(getValueAttrName(opName)); if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_PDLOps3(attr, "value", emitError))) return ::mlir::failure(); } return ::mlir::success(); } ::llvm::LogicalResult AttributeOp::readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state) { auto &prop = state.getOrAddProperties(); (void)prop; if (::mlir::failed(reader.readOptionalAttribute(prop.value))) return ::mlir::failure(); return ::mlir::success(); } void AttributeOp::writeProperties(::mlir::DialectBytecodeWriter &writer) { auto &prop = getProperties(); (void)prop; writer.writeOptionalAttribute(prop.value); } ::std::optional<::mlir::Attribute> AttributeOp::getValue() { auto attr = getValueAttr(); return attr ? ::std::optional<::mlir::Attribute>(attr) : (::std::nullopt); } void AttributeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, Value type) { build(odsBuilder, odsState, odsBuilder.getType(), type, Attribute()); } AttributeOp AttributeOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, Value type) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(type)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } AttributeOp AttributeOp::create(::mlir::ImplicitLocOpBuilder &builder, Value type) { return create(builder, builder.getLoc(), std::forward(type)); } void AttributeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, Attribute attr) { build(odsBuilder, odsState, odsBuilder.getType(), Value(), attr); } AttributeOp AttributeOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, Attribute attr) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(attr)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } AttributeOp AttributeOp::create(::mlir::ImplicitLocOpBuilder &builder, Attribute attr) { return create(builder, builder.getLoc(), std::forward(attr)); } void AttributeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type attr, /*optional*/::mlir::Value valueType, /*optional*/::mlir::Attribute value) { if (valueType) odsState.addOperands(valueType); if (value) { odsState.getOrAddProperties().value = value; } odsState.addTypes(attr); } AttributeOp AttributeOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Type attr, /*optional*/::mlir::Value valueType, /*optional*/::mlir::Attribute value) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(attr), std::forward(valueType), std::forward(value)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } AttributeOp AttributeOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Type attr, /*optional*/::mlir::Value valueType, /*optional*/::mlir::Attribute value) { return create(builder, builder.getLoc(), std::forward(attr), std::forward(valueType), std::forward(value)); } void AttributeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, /*optional*/::mlir::Value valueType, /*optional*/::mlir::Attribute value) { if (valueType) odsState.addOperands(valueType); if (value) { odsState.getOrAddProperties().value = value; } assert(resultTypes.size() == 1u && "mismatched number of results"); odsState.addTypes(resultTypes); } AttributeOp AttributeOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, /*optional*/::mlir::Value valueType, /*optional*/::mlir::Attribute value) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(valueType), std::forward(value)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } AttributeOp AttributeOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, /*optional*/::mlir::Value valueType, /*optional*/::mlir::Attribute value) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(valueType), std::forward(value)); } void AttributeOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { odsState.addOperands(operands); odsState.addAttributes(attributes); assert(resultTypes.size() == 1u && "mismatched number of return types"); odsState.addTypes(resultTypes); if (!attributes.empty()) { (void)odsState.getOrAddProperties(); ::mlir::PropertyRef properties = odsState.getRawProperties(); std::optional<::mlir::RegisteredOperationName> info = odsState.name.getRegisteredInfo(); if (failed(info->setOpPropertiesFromAttribute(odsState.name, properties, odsState.attributes.getDictionary(odsState.getContext()), nullptr))) ::llvm::report_fatal_error("Property conversion failed."); } } AttributeOp AttributeOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(attributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } AttributeOp AttributeOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(attributes)); } void AttributeOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { odsState.addOperands(operands); odsState.useProperties(const_cast(properties)); odsState.addAttributes(discardableAttributes); assert(resultTypes.size() == 1u && "mismatched number of return types"); odsState.addTypes(resultTypes); } AttributeOp AttributeOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } AttributeOp AttributeOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); } ::llvm::LogicalResult AttributeOp::verifyInvariantsImpl() { auto tblgen_value = getProperties().value; (void)tblgen_value; if (::mlir::failed(__mlir_ods_local_attr_constraint_PDLOps3(*this, tblgen_value, "value"))) return ::mlir::failure(); { unsigned index = 0; (void)index; auto valueGroup0 = getODSOperands(0); if (valueGroup0.size() > 1) { return emitOpError("operand group starting at #") << index << " requires 0 or 1 element, but found " << valueGroup0.size(); } for (auto v : valueGroup0) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps2(*this, v.getType(), "operand", index++))) return ::mlir::failure(); } } { unsigned index = 0; (void)index; auto valueGroup0 = getODSResults(0); for (auto v : valueGroup0) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps3(*this, v.getType(), "result", index++))) return ::mlir::failure(); } } return ::mlir::success(); } ::llvm::LogicalResult AttributeOp::verifyInvariants() { if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) return ::mlir::success(); return ::mlir::failure(); } ::mlir::ParseResult AttributeOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> valueTypeOperands; ::llvm::SMLoc valueTypeOperandsLoc; (void)valueTypeOperandsLoc; ::mlir::Attribute valueAttr; if (::mlir::succeeded(parser.parseOptionalColon())) { { valueTypeOperandsLoc = parser.getCurrentLocation(); ::mlir::OpAsmParser::UnresolvedOperand operand; ::mlir::OptionalParseResult parseResult = parser.parseOptionalOperand(operand); if (parseResult.has_value()) { if (failed(*parseResult)) return ::mlir::failure(); valueTypeOperands.push_back(operand); } } } if (::mlir::succeeded(parser.parseOptionalEqual())) { if (parser.parseAttribute(valueAttr, ::mlir::Type{})) return ::mlir::failure(); if (valueAttr) result.getOrAddProperties().value = valueAttr; } { auto loc = parser.getCurrentLocation();(void)loc; if (parser.parseOptionalAttrDictWithKeyword(result.attributes)) return ::mlir::failure(); if (failed(verifyInherentAttrs(result.name, result.attributes, [&]() { return parser.emitError(loc) << "'" << result.name.getStringRef() << "' op "; }))) return ::mlir::failure(); } ::mlir::Type odsBuildableType0 = parser.getBuilder().getType<::mlir::pdl::AttributeType>(); ::mlir::Type odsBuildableType1 = parser.getBuilder().getType<::mlir::pdl::TypeType>(); result.addTypes(odsBuildableType0); if (!valueTypeOperands.empty()) { if (parser.resolveOperands(valueTypeOperands, odsBuildableType1, valueTypeOperandsLoc, result.operands)) return ::mlir::failure(); } return ::mlir::success(); } void AttributeOp::print(::mlir::OpAsmPrinter &_odsPrinter) { if (getValueType()) { _odsPrinter << ' ' << ":"; _odsPrinter << ' '; if (::mlir::Value value = getValueType()) _odsPrinter << value; } if (getValueAttr()) { _odsPrinter << ' ' << "="; _odsPrinter << ' '; _odsPrinter.printAttribute(getValueAttr()); } ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; elidedAttrs.push_back("value"); _odsPrinter.printOptionalAttrDictWithKeyword((*this)->getAttrs(), elidedAttrs); } } // namespace mlir::pdl MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::pdl::AttributeOp) MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::pdl::detail::AttributeOpGenericAdaptorBase::Properties) namespace mlir::pdl { //===----------------------------------------------------------------------===// // ::mlir::pdl::EraseOp definitions //===----------------------------------------------------------------------===// namespace detail { EraseOpGenericAdaptorBase::EraseOpGenericAdaptorBase(EraseOp op) : odsAttrs(op->getRawDictionaryAttrs()), odsOpName(op->getName()), properties(op.getProperties()), odsRegions(op->getRegions()) {} } // namespace detail EraseOpAdaptor::EraseOpAdaptor(EraseOp op) : EraseOpGenericAdaptor(op->getOperands(), op) {} ::llvm::LogicalResult EraseOpAdaptor::verify(::mlir::Location loc) { return ::mlir::success(); } ::llvm::LogicalResult EraseOp::setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { ::mlir::DictionaryAttr dict = ::llvm::dyn_cast<::mlir::DictionaryAttr>(attr); if (!dict) { emitError() << "expected DictionaryAttr to set properties"; return ::mlir::failure(); } return ::mlir::success(); } ::mlir::Attribute EraseOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) { ::mlir::SmallVector<::mlir::NamedAttribute> attrs; ::mlir::Builder odsBuilder{ctx}; if (!attrs.empty()) return odsBuilder.getDictionaryAttr(attrs); return {}; } llvm::hash_code EraseOp::computePropertiesHash(const Properties &prop) { using llvm::hash_value; return llvm::hash_combine(); } std::optional EraseOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { return std::nullopt; } void EraseOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { } void EraseOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { } ::llvm::LogicalResult EraseOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { return ::mlir::success(); } void EraseOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value opValue) { odsState.addOperands(opValue); } EraseOp EraseOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Value opValue) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(opValue)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } EraseOp EraseOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Value opValue) { return create(builder, builder.getLoc(), std::forward(opValue)); } void EraseOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value opValue) { odsState.addOperands(opValue); assert(resultTypes.size() == 0u && "mismatched number of results"); odsState.addTypes(resultTypes); } EraseOp EraseOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::Value opValue) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(opValue)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } EraseOp EraseOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::Value opValue) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(opValue)); } void EraseOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { assert(operands.size() == 1u && "mismatched number of parameters"); odsState.addOperands(operands); odsState.addAttributes(attributes); assert(resultTypes.size() == 0u && "mismatched number of return types"); odsState.addTypes(resultTypes); } EraseOp EraseOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(attributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } EraseOp EraseOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(attributes)); } void EraseOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { assert(operands.size() == 1u && "mismatched number of parameters"); odsState.addOperands(operands); odsState.useProperties(const_cast(properties)); odsState.addAttributes(discardableAttributes); assert(resultTypes.size() == 0u && "mismatched number of return types"); odsState.addTypes(resultTypes); } EraseOp EraseOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } EraseOp EraseOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); } ::llvm::LogicalResult EraseOp::verifyInvariantsImpl() { { unsigned index = 0; (void)index; auto valueGroup0 = getODSOperands(0); for (auto v : valueGroup0) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps4(*this, v.getType(), "operand", index++))) return ::mlir::failure(); } } return ::mlir::success(); } ::llvm::LogicalResult EraseOp::verifyInvariants() { return verifyInvariantsImpl(); } ::mlir::ParseResult EraseOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { ::mlir::OpAsmParser::UnresolvedOperand opValueRawOperand{}; ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> opValueOperands(&opValueRawOperand, 1); ::llvm::SMLoc opValueOperandsLoc; (void)opValueOperandsLoc; opValueOperandsLoc = parser.getCurrentLocation(); if (parser.parseOperand(opValueRawOperand)) return ::mlir::failure(); { auto loc = parser.getCurrentLocation();(void)loc; if (parser.parseOptionalAttrDict(result.attributes)) return ::mlir::failure(); if (failed(verifyInherentAttrs(result.name, result.attributes, [&]() { return parser.emitError(loc) << "'" << result.name.getStringRef() << "' op "; }))) return ::mlir::failure(); } ::mlir::Type odsBuildableType0 = parser.getBuilder().getType<::mlir::pdl::OperationType>(); if (parser.resolveOperands(opValueOperands, odsBuildableType0, opValueOperandsLoc, result.operands)) return ::mlir::failure(); return ::mlir::success(); } void EraseOp::print(::mlir::OpAsmPrinter &_odsPrinter) { _odsPrinter << ' '; _odsPrinter << getOpValue(); ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); } } // namespace mlir::pdl MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::pdl::EraseOp) namespace mlir::pdl { //===----------------------------------------------------------------------===// // ::mlir::pdl::OperandOp definitions //===----------------------------------------------------------------------===// namespace detail { OperandOpGenericAdaptorBase::OperandOpGenericAdaptorBase(OperandOp op) : odsAttrs(op->getRawDictionaryAttrs()), odsOpName(op->getName()), properties(op.getProperties()), odsRegions(op->getRegions()) {} std::pair OperandOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { bool isVariadic[] = {true}; int prevVariadicCount = 0; for (unsigned i = 0; i < index; ++i) if (isVariadic[i]) ++prevVariadicCount; // Calculate how many dynamic values a static variadic operand corresponds to. // This assumes all static variadic operands have the same dynamic value count. int variadicSize = (odsOperandsSize - 0) / 1; // `index` passed in as the parameter is the static index which counts each // operand (variadic or not) as size 1. So here for each previous static variadic // operand, we need to offset by (variadicSize - 1) to get where the dynamic // value pack for this static operand starts. int start = index + (variadicSize - 1) * prevVariadicCount; int size = isVariadic[index] ? variadicSize : 1; return {start, size}; } } // namespace detail OperandOpAdaptor::OperandOpAdaptor(OperandOp op) : OperandOpGenericAdaptor(op->getOperands(), op) {} ::llvm::LogicalResult OperandOpAdaptor::verify(::mlir::Location loc) { return ::mlir::success(); } std::pair OperandOp::getODSOperandIndexAndLength(unsigned index) { bool isVariadic[] = {true}; int prevVariadicCount = 0; for (unsigned i = 0; i < index; ++i) if (isVariadic[i]) ++prevVariadicCount; // Calculate how many dynamic values a static variadic operand corresponds to. // This assumes all static variadic operands have the same dynamic value count. int variadicSize = (getOperation()->getNumOperands() - 0) / 1; // `index` passed in as the parameter is the static index which counts each // operand (variadic or not) as size 1. So here for each previous static variadic // operand, we need to offset by (variadicSize - 1) to get where the dynamic // value pack for this static operand starts. int start = index + (variadicSize - 1) * prevVariadicCount; int size = isVariadic[index] ? variadicSize : 1; return {start, size}; } ::mlir::MutableOperandRange OperandOp::getValueTypeMutable() { auto range = getODSOperandIndexAndLength(0); auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); return mutableRange; } ::llvm::LogicalResult OperandOp::setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { ::mlir::DictionaryAttr dict = ::llvm::dyn_cast<::mlir::DictionaryAttr>(attr); if (!dict) { emitError() << "expected DictionaryAttr to set properties"; return ::mlir::failure(); } return ::mlir::success(); } ::mlir::Attribute OperandOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) { ::mlir::SmallVector<::mlir::NamedAttribute> attrs; ::mlir::Builder odsBuilder{ctx}; if (!attrs.empty()) return odsBuilder.getDictionaryAttr(attrs); return {}; } llvm::hash_code OperandOp::computePropertiesHash(const Properties &prop) { using llvm::hash_value; return llvm::hash_combine(); } std::optional OperandOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { return std::nullopt; } void OperandOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { } void OperandOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { } ::llvm::LogicalResult OperandOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { return ::mlir::success(); } void OperandOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState) { build(odsBuilder, odsState, odsBuilder.getType(), Value()); } OperandOp OperandOp::create(::mlir::OpBuilder &builder, ::mlir::Location location) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } OperandOp OperandOp::create(::mlir::ImplicitLocOpBuilder &builder) { return create(builder, builder.getLoc()); } void OperandOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type value, /*optional*/::mlir::Value valueType) { if (valueType) odsState.addOperands(valueType); odsState.addTypes(value); } OperandOp OperandOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Type value, /*optional*/::mlir::Value valueType) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(value), std::forward(valueType)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } OperandOp OperandOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Type value, /*optional*/::mlir::Value valueType) { return create(builder, builder.getLoc(), std::forward(value), std::forward(valueType)); } void OperandOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, /*optional*/::mlir::Value valueType) { if (valueType) odsState.addOperands(valueType); assert(resultTypes.size() == 1u && "mismatched number of results"); odsState.addTypes(resultTypes); } OperandOp OperandOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, /*optional*/::mlir::Value valueType) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(valueType)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } OperandOp OperandOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, /*optional*/::mlir::Value valueType) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(valueType)); } void OperandOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { odsState.addOperands(operands); odsState.addAttributes(attributes); assert(resultTypes.size() == 1u && "mismatched number of return types"); odsState.addTypes(resultTypes); } OperandOp OperandOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(attributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } OperandOp OperandOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(attributes)); } void OperandOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { odsState.addOperands(operands); odsState.useProperties(const_cast(properties)); odsState.addAttributes(discardableAttributes); assert(resultTypes.size() == 1u && "mismatched number of return types"); odsState.addTypes(resultTypes); } OperandOp OperandOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } OperandOp OperandOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); } ::llvm::LogicalResult OperandOp::verifyInvariantsImpl() { { unsigned index = 0; (void)index; auto valueGroup0 = getODSOperands(0); if (valueGroup0.size() > 1) { return emitOpError("operand group starting at #") << index << " requires 0 or 1 element, but found " << valueGroup0.size(); } for (auto v : valueGroup0) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps2(*this, v.getType(), "operand", index++))) return ::mlir::failure(); } } { unsigned index = 0; (void)index; auto valueGroup0 = getODSResults(0); for (auto v : valueGroup0) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps5(*this, v.getType(), "result", index++))) return ::mlir::failure(); } } return ::mlir::success(); } ::llvm::LogicalResult OperandOp::verifyInvariants() { if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) return ::mlir::success(); return ::mlir::failure(); } ::mlir::ParseResult OperandOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> valueTypeOperands; ::llvm::SMLoc valueTypeOperandsLoc; (void)valueTypeOperandsLoc; if (::mlir::succeeded(parser.parseOptionalColon())) { { valueTypeOperandsLoc = parser.getCurrentLocation(); ::mlir::OpAsmParser::UnresolvedOperand operand; ::mlir::OptionalParseResult parseResult = parser.parseOptionalOperand(operand); if (parseResult.has_value()) { if (failed(*parseResult)) return ::mlir::failure(); valueTypeOperands.push_back(operand); } } } { auto loc = parser.getCurrentLocation();(void)loc; if (parser.parseOptionalAttrDict(result.attributes)) return ::mlir::failure(); if (failed(verifyInherentAttrs(result.name, result.attributes, [&]() { return parser.emitError(loc) << "'" << result.name.getStringRef() << "' op "; }))) return ::mlir::failure(); } ::mlir::Type odsBuildableType0 = parser.getBuilder().getType<::mlir::pdl::ValueType>(); ::mlir::Type odsBuildableType1 = parser.getBuilder().getType<::mlir::pdl::TypeType>(); result.addTypes(odsBuildableType0); if (!valueTypeOperands.empty()) { if (parser.resolveOperands(valueTypeOperands, odsBuildableType1, valueTypeOperandsLoc, result.operands)) return ::mlir::failure(); } return ::mlir::success(); } void OperandOp::print(::mlir::OpAsmPrinter &_odsPrinter) { if (getValueType()) { _odsPrinter << ' ' << ":"; _odsPrinter << ' '; if (::mlir::Value value = getValueType()) _odsPrinter << value; } ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); } } // namespace mlir::pdl MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::pdl::OperandOp) namespace mlir::pdl { //===----------------------------------------------------------------------===// // ::mlir::pdl::OperandsOp definitions //===----------------------------------------------------------------------===// namespace detail { OperandsOpGenericAdaptorBase::OperandsOpGenericAdaptorBase(OperandsOp op) : odsAttrs(op->getRawDictionaryAttrs()), odsOpName(op->getName()), properties(op.getProperties()), odsRegions(op->getRegions()) {} std::pair OperandsOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { bool isVariadic[] = {true}; int prevVariadicCount = 0; for (unsigned i = 0; i < index; ++i) if (isVariadic[i]) ++prevVariadicCount; // Calculate how many dynamic values a static variadic operand corresponds to. // This assumes all static variadic operands have the same dynamic value count. int variadicSize = (odsOperandsSize - 0) / 1; // `index` passed in as the parameter is the static index which counts each // operand (variadic or not) as size 1. So here for each previous static variadic // operand, we need to offset by (variadicSize - 1) to get where the dynamic // value pack for this static operand starts. int start = index + (variadicSize - 1) * prevVariadicCount; int size = isVariadic[index] ? variadicSize : 1; return {start, size}; } } // namespace detail OperandsOpAdaptor::OperandsOpAdaptor(OperandsOp op) : OperandsOpGenericAdaptor(op->getOperands(), op) {} ::llvm::LogicalResult OperandsOpAdaptor::verify(::mlir::Location loc) { return ::mlir::success(); } std::pair OperandsOp::getODSOperandIndexAndLength(unsigned index) { bool isVariadic[] = {true}; int prevVariadicCount = 0; for (unsigned i = 0; i < index; ++i) if (isVariadic[i]) ++prevVariadicCount; // Calculate how many dynamic values a static variadic operand corresponds to. // This assumes all static variadic operands have the same dynamic value count. int variadicSize = (getOperation()->getNumOperands() - 0) / 1; // `index` passed in as the parameter is the static index which counts each // operand (variadic or not) as size 1. So here for each previous static variadic // operand, we need to offset by (variadicSize - 1) to get where the dynamic // value pack for this static operand starts. int start = index + (variadicSize - 1) * prevVariadicCount; int size = isVariadic[index] ? variadicSize : 1; return {start, size}; } ::mlir::MutableOperandRange OperandsOp::getValueTypeMutable() { auto range = getODSOperandIndexAndLength(0); auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); return mutableRange; } ::llvm::LogicalResult OperandsOp::setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { ::mlir::DictionaryAttr dict = ::llvm::dyn_cast<::mlir::DictionaryAttr>(attr); if (!dict) { emitError() << "expected DictionaryAttr to set properties"; return ::mlir::failure(); } return ::mlir::success(); } ::mlir::Attribute OperandsOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) { ::mlir::SmallVector<::mlir::NamedAttribute> attrs; ::mlir::Builder odsBuilder{ctx}; if (!attrs.empty()) return odsBuilder.getDictionaryAttr(attrs); return {}; } llvm::hash_code OperandsOp::computePropertiesHash(const Properties &prop) { using llvm::hash_value; return llvm::hash_combine(); } std::optional OperandsOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { return std::nullopt; } void OperandsOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { } void OperandsOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { } ::llvm::LogicalResult OperandsOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { return ::mlir::success(); } void OperandsOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState) { build(odsBuilder, odsState, RangeType::get(odsBuilder.getType()), Value()); } OperandsOp OperandsOp::create(::mlir::OpBuilder &builder, ::mlir::Location location) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } OperandsOp OperandsOp::create(::mlir::ImplicitLocOpBuilder &builder) { return create(builder, builder.getLoc()); } void OperandsOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type value, /*optional*/::mlir::Value valueType) { if (valueType) odsState.addOperands(valueType); odsState.addTypes(value); } OperandsOp OperandsOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Type value, /*optional*/::mlir::Value valueType) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(value), std::forward(valueType)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } OperandsOp OperandsOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Type value, /*optional*/::mlir::Value valueType) { return create(builder, builder.getLoc(), std::forward(value), std::forward(valueType)); } void OperandsOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, /*optional*/::mlir::Value valueType) { if (valueType) odsState.addOperands(valueType); assert(resultTypes.size() == 1u && "mismatched number of results"); odsState.addTypes(resultTypes); } OperandsOp OperandsOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, /*optional*/::mlir::Value valueType) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(valueType)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } OperandsOp OperandsOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, /*optional*/::mlir::Value valueType) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(valueType)); } void OperandsOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { odsState.addOperands(operands); odsState.addAttributes(attributes); assert(resultTypes.size() == 1u && "mismatched number of return types"); odsState.addTypes(resultTypes); } OperandsOp OperandsOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(attributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } OperandsOp OperandsOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(attributes)); } void OperandsOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { odsState.addOperands(operands); odsState.useProperties(const_cast(properties)); odsState.addAttributes(discardableAttributes); assert(resultTypes.size() == 1u && "mismatched number of return types"); odsState.addTypes(resultTypes); } OperandsOp OperandsOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } OperandsOp OperandsOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); } ::llvm::LogicalResult OperandsOp::verifyInvariantsImpl() { { unsigned index = 0; (void)index; auto valueGroup0 = getODSOperands(0); if (valueGroup0.size() > 1) { return emitOpError("operand group starting at #") << index << " requires 0 or 1 element, but found " << valueGroup0.size(); } for (auto v : valueGroup0) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps6(*this, v.getType(), "operand", index++))) return ::mlir::failure(); } } { unsigned index = 0; (void)index; auto valueGroup0 = getODSResults(0); for (auto v : valueGroup0) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps7(*this, v.getType(), "result", index++))) return ::mlir::failure(); } } return ::mlir::success(); } ::llvm::LogicalResult OperandsOp::verifyInvariants() { if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) return ::mlir::success(); return ::mlir::failure(); } ::mlir::ParseResult OperandsOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> valueTypeOperands; ::llvm::SMLoc valueTypeOperandsLoc; (void)valueTypeOperandsLoc; if (::mlir::succeeded(parser.parseOptionalColon())) { { valueTypeOperandsLoc = parser.getCurrentLocation(); ::mlir::OpAsmParser::UnresolvedOperand operand; ::mlir::OptionalParseResult parseResult = parser.parseOptionalOperand(operand); if (parseResult.has_value()) { if (failed(*parseResult)) return ::mlir::failure(); valueTypeOperands.push_back(operand); } } } { auto loc = parser.getCurrentLocation();(void)loc; if (parser.parseOptionalAttrDict(result.attributes)) return ::mlir::failure(); if (failed(verifyInherentAttrs(result.name, result.attributes, [&]() { return parser.emitError(loc) << "'" << result.name.getStringRef() << "' op "; }))) return ::mlir::failure(); } ::mlir::Type odsBuildableType0 = ::mlir::pdl::RangeType::get(parser.getBuilder().getType<::mlir::pdl::ValueType>()); ::mlir::Type odsBuildableType1 = ::mlir::pdl::RangeType::get(parser.getBuilder().getType<::mlir::pdl::TypeType>()); result.addTypes(odsBuildableType0); if (!valueTypeOperands.empty()) { if (parser.resolveOperands(valueTypeOperands, odsBuildableType1, valueTypeOperandsLoc, result.operands)) return ::mlir::failure(); } return ::mlir::success(); } void OperandsOp::print(::mlir::OpAsmPrinter &_odsPrinter) { if (getValueType()) { _odsPrinter << ' ' << ":"; _odsPrinter << ' '; if (::mlir::Value value = getValueType()) _odsPrinter << value; } ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); } } // namespace mlir::pdl MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::pdl::OperandsOp) namespace mlir::pdl { //===----------------------------------------------------------------------===// // ::mlir::pdl::OperationOp definitions //===----------------------------------------------------------------------===// namespace detail { OperationOpGenericAdaptorBase::OperationOpGenericAdaptorBase(OperationOp op) : odsAttrs(op->getRawDictionaryAttrs()), odsOpName(op->getName()), properties(op.getProperties()), odsRegions(op->getRegions()) {} std::pair OperationOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { ::llvm::ArrayRef sizeAttr = getProperties().operandSegmentSizes; unsigned start = 0; for (unsigned i = 0; i < index; ++i) start += sizeAttr[i]; return {start, sizeAttr[index]}; } ::std::optional< ::llvm::StringRef > OperationOpGenericAdaptorBase::getOpName() { auto attr = getOpNameAttr(); return attr ? ::std::optional< ::llvm::StringRef >(attr.getValue()) : (::std::nullopt); } ::mlir::ArrayAttr OperationOpGenericAdaptorBase::getAttributeValueNames() { auto attr = getAttributeValueNamesAttr(); return attr; } } // namespace detail OperationOpAdaptor::OperationOpAdaptor(OperationOp op) : OperationOpGenericAdaptor(op->getOperands(), op) {} ::llvm::LogicalResult OperationOpAdaptor::verify(::mlir::Location loc) { auto tblgen_attributeValueNames = getProperties().attributeValueNames; (void)tblgen_attributeValueNames; if (!tblgen_attributeValueNames) return emitError(loc, "'pdl.operation' op requires attribute 'attributeValueNames'"); auto tblgen_opName = getProperties().opName; (void)tblgen_opName; if (tblgen_opName && !((::llvm::isa<::mlir::StringAttr>(tblgen_opName)))) return emitError(loc, "'pdl.operation' op attribute 'opName' failed to satisfy constraint: string attribute"); if (tblgen_attributeValueNames && !(((::llvm::isa<::mlir::ArrayAttr>(tblgen_attributeValueNames))) && (::llvm::all_of(::llvm::cast<::mlir::ArrayAttr>(tblgen_attributeValueNames), [&](::mlir::Attribute attr) { return attr && ((::llvm::isa<::mlir::StringAttr>(attr))); })))) return emitError(loc, "'pdl.operation' op attribute 'attributeValueNames' failed to satisfy constraint: string array attribute"); return ::mlir::success(); } std::pair OperationOp::getODSOperandIndexAndLength(unsigned index) { ::llvm::ArrayRef sizeAttr = getProperties().operandSegmentSizes; unsigned start = 0; for (unsigned i = 0; i < index; ++i) start += sizeAttr[i]; return {start, sizeAttr[index]}; } ::mlir::MutableOperandRange OperationOp::getOperandValuesMutable() { auto range = getODSOperandIndexAndLength(0); auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(0u, {getOperandSegmentSizesAttrName(), ::mlir::DenseI32ArrayAttr::get(getContext(), getProperties().operandSegmentSizes)})); return mutableRange; } ::mlir::MutableOperandRange OperationOp::getAttributeValuesMutable() { auto range = getODSOperandIndexAndLength(1); auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(1u, {getOperandSegmentSizesAttrName(), ::mlir::DenseI32ArrayAttr::get(getContext(), getProperties().operandSegmentSizes)})); return mutableRange; } ::mlir::MutableOperandRange OperationOp::getTypeValuesMutable() { auto range = getODSOperandIndexAndLength(2); auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(2u, {getOperandSegmentSizesAttrName(), ::mlir::DenseI32ArrayAttr::get(getContext(), getProperties().operandSegmentSizes)})); return mutableRange; } ::llvm::LogicalResult OperationOp::setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { ::mlir::DictionaryAttr dict = ::llvm::dyn_cast<::mlir::DictionaryAttr>(attr); if (!dict) { emitError() << "expected DictionaryAttr to set properties"; return ::mlir::failure(); } { auto &propStorage = prop.attributeValueNames; auto attr = dict.get("attributeValueNames"); if (attr) { auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `attributeValueNames` in property conversion: " << attr; return ::mlir::failure(); } } } { auto &propStorage = prop.opName; auto attr = dict.get("opName"); if (attr) { auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `opName` in property conversion: " << attr; return ::mlir::failure(); } } } { auto setFromAttr = [] (auto &propStorage, ::mlir::Attribute propAttr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) -> ::mlir::LogicalResult { return convertFromAttribute(propStorage, propAttr, emitError); }; auto attr = dict.get("operandSegmentSizes"); if (!attr) attr = dict.get("operand_segment_sizes");; ; if (attr && ::mlir::failed(setFromAttr(prop.operandSegmentSizes, attr, [&]() { return emitError() << "for `operandSegmentSizes`: "; }))) return ::mlir::failure(); } return ::mlir::success(); } ::mlir::Attribute OperationOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) { ::mlir::SmallVector<::mlir::NamedAttribute> attrs; ::mlir::Builder odsBuilder{ctx}; { const auto &propStorage = prop.attributeValueNames; if (propStorage) attrs.push_back(odsBuilder.getNamedAttr("attributeValueNames", propStorage)); } { const auto &propStorage = prop.opName; if (propStorage) attrs.push_back(odsBuilder.getNamedAttr("opName", propStorage)); } { const auto &propStorage = prop.operandSegmentSizes; auto attr = [&]() -> ::mlir::Attribute { return ::mlir::DenseI32ArrayAttr::get(ctx, propStorage); }(); attrs.push_back(odsBuilder.getNamedAttr("operandSegmentSizes", attr)); } if (!attrs.empty()) return odsBuilder.getDictionaryAttr(attrs); return {}; } llvm::hash_code OperationOp::computePropertiesHash(const Properties &prop) { auto hash_operandSegmentSizes_ = [] (const auto &propStorage) -> llvm::hash_code { using ::llvm::hash_value; return ::llvm::hash_combine_range(std::begin(propStorage), std::end(propStorage));; }; using llvm::hash_value; return llvm::hash_combine( llvm::hash_value(prop.attributeValueNames.getAsOpaquePointer()), llvm::hash_value(prop.opName.getAsOpaquePointer()), hash_operandSegmentSizes_(prop.operandSegmentSizes)); } std::optional OperationOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { if (name == "attributeValueNames") return prop.attributeValueNames; if (name == "opName") return prop.opName; if (name == "operand_segment_sizes" || name == "operandSegmentSizes") return [&]() -> ::mlir::Attribute { return ::mlir::DenseI32ArrayAttr::get(ctx, prop.operandSegmentSizes); }(); return std::nullopt; } void OperationOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { if (name == "attributeValueNames") { prop.attributeValueNames = ::llvm::dyn_cast_or_null>(value); return; } if (name == "opName") { prop.opName = ::llvm::dyn_cast_or_null>(value); return; } if (name == "operand_segment_sizes" || name == "operandSegmentSizes") { auto arrAttr = ::llvm::dyn_cast_or_null<::mlir::DenseI32ArrayAttr>(value); if (!arrAttr) return; if (arrAttr.size() != sizeof(prop.operandSegmentSizes) / sizeof(int32_t)) return; llvm::copy(arrAttr.asArrayRef(), prop.operandSegmentSizes.begin()); return; } } void OperationOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { if (prop.attributeValueNames) attrs.append("attributeValueNames", prop.attributeValueNames); if (prop.opName) attrs.append("opName", prop.opName); attrs.append("operandSegmentSizes", [&]() -> ::mlir::Attribute { return ::mlir::DenseI32ArrayAttr::get(ctx, prop.operandSegmentSizes); }()); } ::llvm::LogicalResult OperationOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { { ::mlir::Attribute attr = attrs.get(getAttributeValueNamesAttrName(opName)); if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_PDLOps4(attr, "attributeValueNames", emitError))) return ::mlir::failure(); } { ::mlir::Attribute attr = attrs.get(getOpNameAttrName(opName)); if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_PDLOps1(attr, "opName", emitError))) return ::mlir::failure(); } return ::mlir::success(); } ::llvm::LogicalResult OperationOp::readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state) { auto &prop = state.getOrAddProperties(); (void)prop; if (::mlir::failed(reader.readAttribute(prop.attributeValueNames))) return ::mlir::failure(); if (::mlir::failed(reader.readOptionalAttribute(prop.opName))) return ::mlir::failure(); if (reader.getBytecodeVersion() < /*kNativePropertiesODSSegmentSize=*/6) { auto &propStorage = prop.operandSegmentSizes; ::mlir::DenseI32ArrayAttr attr; if (::mlir::failed(reader.readAttribute(attr))) return ::mlir::failure(); if (attr.size() > static_cast(sizeof(propStorage) / sizeof(int32_t))) { reader.emitError("size mismatch for operand/result_segment_size"); return ::mlir::failure(); } ::llvm::copy(::llvm::ArrayRef(attr), propStorage.begin()); } { auto &propStorage = prop.operandSegmentSizes; auto readProp = [&]() { if (reader.getBytecodeVersion() >= /*kNativePropertiesODSSegmentSize=*/6) return reader.readSparseArray(::llvm::MutableArrayRef(propStorage)); ; return ::mlir::success(); }; if (::mlir::failed(readProp())) return ::mlir::failure(); } return ::mlir::success(); } void OperationOp::writeProperties(::mlir::DialectBytecodeWriter &writer) { auto &prop = getProperties(); (void)prop; writer.writeAttribute(prop.attributeValueNames); writer.writeOptionalAttribute(prop.opName); if (writer.getBytecodeVersion() < /*kNativePropertiesODSSegmentSize=*/6) { auto &propStorage = prop.operandSegmentSizes; writer.writeAttribute(::mlir::DenseI32ArrayAttr::get(this->getContext(), propStorage)); } { auto &propStorage = prop.operandSegmentSizes; if (writer.getBytecodeVersion() >= /*kNativePropertiesODSSegmentSize=*/6) writer.writeSparseArray(::llvm::ArrayRef(propStorage)); ; } } ::std::optional< ::llvm::StringRef > OperationOp::getOpName() { auto attr = getOpNameAttr(); return attr ? ::std::optional< ::llvm::StringRef >(attr.getValue()) : (::std::nullopt); } ::mlir::ArrayAttr OperationOp::getAttributeValueNames() { auto attr = getAttributeValueNamesAttr(); return attr; } void OperationOp::setOpName(::std::optional<::llvm::StringRef> attrValue) { auto &odsProp = getProperties().opName; if (attrValue) odsProp = ::mlir::Builder((*this)->getContext()).getStringAttr(*attrValue); else odsProp = nullptr; } void OperationOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, std::optional name, ValueRange operandValues, ArrayRef attrNames, ValueRange attrValues, ValueRange resultTypes) { auto nameAttr = name ? odsBuilder.getStringAttr(*name) : StringAttr(); build(odsBuilder, odsState, odsBuilder.getType(), nameAttr, operandValues, attrValues, odsBuilder.getStrArrayAttr(attrNames), resultTypes); } OperationOp OperationOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, std::optional name, ValueRange operandValues, ArrayRef attrNames, ValueRange attrValues, ValueRange resultTypes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(name), std::forward(operandValues), std::forward(attrNames), std::forward(attrValues), std::forward(resultTypes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } OperationOp OperationOp::create(::mlir::ImplicitLocOpBuilder &builder, std::optional name, ValueRange operandValues, ArrayRef attrNames, ValueRange attrValues, ValueRange resultTypes) { return create(builder, builder.getLoc(), std::forward(name), std::forward(operandValues), std::forward(attrNames), std::forward(attrValues), std::forward(resultTypes)); } void OperationOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type op, /*optional*/::mlir::StringAttr opName, ::mlir::ValueRange operandValues, ::mlir::ValueRange attributeValues, ::mlir::ArrayAttr attributeValueNames, ::mlir::ValueRange typeValues) { odsState.addOperands(operandValues); odsState.addOperands(attributeValues); odsState.addOperands(typeValues); ::llvm::copy(::llvm::ArrayRef({static_cast(operandValues.size()), static_cast(attributeValues.size()), static_cast(typeValues.size())}), odsState.getOrAddProperties().operandSegmentSizes.begin()); if (opName) { odsState.getOrAddProperties().opName = opName; } odsState.getOrAddProperties().attributeValueNames = attributeValueNames; odsState.addTypes(op); } OperationOp OperationOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Type op, /*optional*/::mlir::StringAttr opName, ::mlir::ValueRange operandValues, ::mlir::ValueRange attributeValues, ::mlir::ArrayAttr attributeValueNames, ::mlir::ValueRange typeValues) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(op), std::forward(opName), std::forward(operandValues), std::forward(attributeValues), std::forward(attributeValueNames), std::forward(typeValues)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } OperationOp OperationOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Type op, /*optional*/::mlir::StringAttr opName, ::mlir::ValueRange operandValues, ::mlir::ValueRange attributeValues, ::mlir::ArrayAttr attributeValueNames, ::mlir::ValueRange typeValues) { return create(builder, builder.getLoc(), std::forward(op), std::forward(opName), std::forward(operandValues), std::forward(attributeValues), std::forward(attributeValueNames), std::forward(typeValues)); } void OperationOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, /*optional*/::mlir::StringAttr opName, ::mlir::ValueRange operandValues, ::mlir::ValueRange attributeValues, ::mlir::ArrayAttr attributeValueNames, ::mlir::ValueRange typeValues) { odsState.addOperands(operandValues); odsState.addOperands(attributeValues); odsState.addOperands(typeValues); ::llvm::copy(::llvm::ArrayRef({static_cast(operandValues.size()), static_cast(attributeValues.size()), static_cast(typeValues.size())}), odsState.getOrAddProperties().operandSegmentSizes.begin()); if (opName) { odsState.getOrAddProperties().opName = opName; } odsState.getOrAddProperties().attributeValueNames = attributeValueNames; assert(resultTypes.size() == 1u && "mismatched number of results"); odsState.addTypes(resultTypes); } OperationOp OperationOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, /*optional*/::mlir::StringAttr opName, ::mlir::ValueRange operandValues, ::mlir::ValueRange attributeValues, ::mlir::ArrayAttr attributeValueNames, ::mlir::ValueRange typeValues) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(opName), std::forward(operandValues), std::forward(attributeValues), std::forward(attributeValueNames), std::forward(typeValues)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } OperationOp OperationOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, /*optional*/::mlir::StringAttr opName, ::mlir::ValueRange operandValues, ::mlir::ValueRange attributeValues, ::mlir::ArrayAttr attributeValueNames, ::mlir::ValueRange typeValues) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(opName), std::forward(operandValues), std::forward(attributeValues), std::forward(attributeValueNames), std::forward(typeValues)); } void OperationOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { odsState.addOperands(operands); odsState.addAttributes(attributes); assert(resultTypes.size() == 1u && "mismatched number of return types"); odsState.addTypes(resultTypes); if (!attributes.empty()) { (void)odsState.getOrAddProperties(); ::mlir::PropertyRef properties = odsState.getRawProperties(); std::optional<::mlir::RegisteredOperationName> info = odsState.name.getRegisteredInfo(); if (failed(info->setOpPropertiesFromAttribute(odsState.name, properties, odsState.attributes.getDictionary(odsState.getContext()), nullptr))) ::llvm::report_fatal_error("Property conversion failed."); } } OperationOp OperationOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(attributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } OperationOp OperationOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(attributes)); } void OperationOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { odsState.addOperands(operands); odsState.useProperties(const_cast(properties)); odsState.addAttributes(discardableAttributes); assert(resultTypes.size() == 1u && "mismatched number of return types"); odsState.addTypes(resultTypes); } OperationOp OperationOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } OperationOp OperationOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); } ::llvm::LogicalResult OperationOp::verifyInvariantsImpl() { auto tblgen_attributeValueNames = getProperties().attributeValueNames; (void)tblgen_attributeValueNames; if (!tblgen_attributeValueNames) return emitOpError("requires attribute 'attributeValueNames'"); auto tblgen_opName = getProperties().opName; (void)tblgen_opName; if (::mlir::failed(__mlir_ods_local_attr_constraint_PDLOps1(*this, tblgen_opName, "opName"))) return ::mlir::failure(); if (::mlir::failed(__mlir_ods_local_attr_constraint_PDLOps4(*this, tblgen_attributeValueNames, "attributeValueNames"))) return ::mlir::failure(); { unsigned index = 0; (void)index; auto valueGroup0 = getODSOperands(0); for (auto v : valueGroup0) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps8(*this, v.getType(), "operand", index++))) return ::mlir::failure(); } auto valueGroup1 = getODSOperands(1); for (auto v : valueGroup1) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps9(*this, v.getType(), "operand", index++))) return ::mlir::failure(); } auto valueGroup2 = getODSOperands(2); for (auto v : valueGroup2) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps10(*this, v.getType(), "operand", index++))) return ::mlir::failure(); } } { unsigned index = 0; (void)index; auto valueGroup0 = getODSResults(0); for (auto v : valueGroup0) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps4(*this, v.getType(), "result", index++))) return ::mlir::failure(); } } return ::mlir::success(); } ::llvm::LogicalResult OperationOp::verifyInvariants() { if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) return ::mlir::success(); return ::mlir::failure(); } ::mlir::ParseResult OperationOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { ::mlir::StringAttr opNameAttr; ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> operandValuesOperands; ::llvm::SMLoc operandValuesOperandsLoc; (void)operandValuesOperandsLoc; ::llvm::SmallVector<::mlir::Type, 1> operandValuesTypes; ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> attributeValuesOperands; ::llvm::SMLoc attributeValuesOperandsLoc; (void)attributeValuesOperandsLoc; ::mlir::ArrayAttr attributeValueNamesAttr; ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> typeValuesOperands; ::llvm::SMLoc typeValuesOperandsLoc; (void)typeValuesOperandsLoc; ::llvm::SmallVector<::mlir::Type, 1> typeValuesTypes; ::mlir::OptionalParseResult parseResultopNameAttr = parser.parseOptionalAttribute(opNameAttr, parser.getBuilder().getType<::mlir::NoneType>()); if (parseResultopNameAttr.has_value() && failed(*parseResultopNameAttr)) return ::mlir::failure(); if (parseResultopNameAttr.has_value() && succeeded(*parseResultopNameAttr)) if (opNameAttr) result.getOrAddProperties().opName = opNameAttr; if (opNameAttr) { } if (::mlir::succeeded(parser.parseOptionalLParen())) { operandValuesOperandsLoc = parser.getCurrentLocation(); if (parser.parseOperandList(operandValuesOperands)) return ::mlir::failure(); if (parser.parseColon()) return ::mlir::failure(); if (parser.parseTypeList(operandValuesTypes)) return ::mlir::failure(); if (parser.parseRParen()) return ::mlir::failure(); } { attributeValuesOperandsLoc = parser.getCurrentLocation(); auto odsResult = parseOperationOpAttributes(parser, attributeValuesOperands, attributeValueNamesAttr); if (odsResult) return ::mlir::failure(); result.getOrAddProperties().attributeValueNames = attributeValueNamesAttr; } if (::mlir::succeeded(parser.parseOptionalArrow())) { if (parser.parseLParen()) return ::mlir::failure(); typeValuesOperandsLoc = parser.getCurrentLocation(); if (parser.parseOperandList(typeValuesOperands)) return ::mlir::failure(); if (parser.parseColon()) return ::mlir::failure(); if (parser.parseTypeList(typeValuesTypes)) return ::mlir::failure(); if (parser.parseRParen()) return ::mlir::failure(); } { auto loc = parser.getCurrentLocation();(void)loc; if (parser.parseOptionalAttrDict(result.attributes)) return ::mlir::failure(); if (failed(verifyInherentAttrs(result.name, result.attributes, [&]() { return parser.emitError(loc) << "'" << result.name.getStringRef() << "' op "; }))) return ::mlir::failure(); } ::llvm::copy(::llvm::ArrayRef({static_cast(operandValuesOperands.size()), static_cast(attributeValuesOperands.size()), static_cast(typeValuesOperands.size())}), result.getOrAddProperties().operandSegmentSizes.begin()); ::mlir::Type odsBuildableType0 = parser.getBuilder().getType<::mlir::pdl::OperationType>(); ::mlir::Type odsBuildableType1 = parser.getBuilder().getType<::mlir::pdl::AttributeType>(); result.addTypes(odsBuildableType0); if (parser.resolveOperands(operandValuesOperands, operandValuesTypes, operandValuesOperandsLoc, result.operands)) return ::mlir::failure(); if (parser.resolveOperands(attributeValuesOperands, odsBuildableType1, attributeValuesOperandsLoc, result.operands)) return ::mlir::failure(); if (parser.resolveOperands(typeValuesOperands, typeValuesTypes, typeValuesOperandsLoc, result.operands)) return ::mlir::failure(); return ::mlir::success(); } void OperationOp::print(::mlir::OpAsmPrinter &_odsPrinter) { if (getOpNameAttr()) { _odsPrinter << ' '; _odsPrinter.printAttributeWithoutType(getOpNameAttr()); } if (!getOperandValues().empty()) { _odsPrinter << "("; _odsPrinter << getOperandValues(); _odsPrinter << ' ' << ":"; _odsPrinter << ' '; _odsPrinter << getOperandValues().getTypes(); _odsPrinter << ")"; } _odsPrinter << ' '; printOperationOpAttributes(_odsPrinter, *this, getAttributeValues(), getAttributeValueNamesAttr()); if (!getTypeValues().empty()) { _odsPrinter << ' ' << "->"; _odsPrinter << ' ' << "("; _odsPrinter << getTypeValues(); _odsPrinter << ' ' << ":"; _odsPrinter << ' '; _odsPrinter << getTypeValues().getTypes(); _odsPrinter << ")"; } ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; elidedAttrs.push_back("operandSegmentSizes"); elidedAttrs.push_back("opName"); elidedAttrs.push_back("attributeValueNames"); _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); } } // namespace mlir::pdl MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::pdl::OperationOp) MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::pdl::detail::OperationOpGenericAdaptorBase::Properties) namespace mlir::pdl { //===----------------------------------------------------------------------===// // ::mlir::pdl::PatternOp definitions //===----------------------------------------------------------------------===// namespace detail { PatternOpGenericAdaptorBase::PatternOpGenericAdaptorBase(PatternOp op) : odsAttrs(op->getRawDictionaryAttrs()), odsOpName(op->getName()), properties(op.getProperties()), odsRegions(op->getRegions()) {} uint16_t PatternOpGenericAdaptorBase::getBenefit() { auto attr = getBenefitAttr(); return attr.getValue().getZExtValue(); } ::std::optional< ::llvm::StringRef > PatternOpGenericAdaptorBase::getSymName() { auto attr = getSymNameAttr(); return attr ? ::std::optional< ::llvm::StringRef >(attr.getValue()) : (::std::nullopt); } } // namespace detail PatternOpAdaptor::PatternOpAdaptor(PatternOp op) : PatternOpGenericAdaptor(op->getOperands(), op) {} ::llvm::LogicalResult PatternOpAdaptor::verify(::mlir::Location loc) { auto tblgen_benefit = getProperties().benefit; (void)tblgen_benefit; if (!tblgen_benefit) return emitError(loc, "'pdl.pattern' op requires attribute 'benefit'"); auto tblgen_sym_name = getProperties().sym_name; (void)tblgen_sym_name; if (tblgen_benefit && !((((::llvm::isa<::mlir::IntegerAttr>(tblgen_benefit))) && ((::llvm::cast<::mlir::IntegerAttr>(tblgen_benefit).getType().isSignlessInteger(16)))) && ((!::llvm::cast<::mlir::IntegerAttr>(tblgen_benefit).getValue().isNegative())))) return emitError(loc, "'pdl.pattern' op attribute 'benefit' failed to satisfy constraint: 16-bit signless integer attribute whose value is non-negative"); if (tblgen_sym_name && !((::llvm::isa<::mlir::StringAttr>(tblgen_sym_name)))) return emitError(loc, "'pdl.pattern' op attribute 'sym_name' failed to satisfy constraint: string attribute"); return ::mlir::success(); } ::llvm::LogicalResult PatternOp::setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { ::mlir::DictionaryAttr dict = ::llvm::dyn_cast<::mlir::DictionaryAttr>(attr); if (!dict) { emitError() << "expected DictionaryAttr to set properties"; return ::mlir::failure(); } { auto &propStorage = prop.benefit; auto attr = dict.get("benefit"); if (attr) { auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `benefit` in property conversion: " << attr; return ::mlir::failure(); } } } { auto &propStorage = prop.sym_name; auto attr = dict.get("sym_name"); if (attr) { auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `sym_name` in property conversion: " << attr; return ::mlir::failure(); } } } return ::mlir::success(); } ::mlir::Attribute PatternOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) { ::mlir::SmallVector<::mlir::NamedAttribute> attrs; ::mlir::Builder odsBuilder{ctx}; { const auto &propStorage = prop.benefit; if (propStorage) attrs.push_back(odsBuilder.getNamedAttr("benefit", propStorage)); } { const auto &propStorage = prop.sym_name; if (propStorage) attrs.push_back(odsBuilder.getNamedAttr("sym_name", propStorage)); } if (!attrs.empty()) return odsBuilder.getDictionaryAttr(attrs); return {}; } llvm::hash_code PatternOp::computePropertiesHash(const Properties &prop) { using llvm::hash_value; return llvm::hash_combine( llvm::hash_value(prop.benefit.getAsOpaquePointer()), llvm::hash_value(prop.sym_name.getAsOpaquePointer())); } std::optional PatternOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { if (name == "benefit") return prop.benefit; if (name == "sym_name") return prop.sym_name; return std::nullopt; } void PatternOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { if (name == "benefit") { prop.benefit = ::llvm::dyn_cast_or_null>(value); return; } if (name == "sym_name") { prop.sym_name = ::llvm::dyn_cast_or_null>(value); return; } } void PatternOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { if (prop.benefit) attrs.append("benefit", prop.benefit); if (prop.sym_name) attrs.append("sym_name", prop.sym_name); } ::llvm::LogicalResult PatternOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { { ::mlir::Attribute attr = attrs.get(getBenefitAttrName(opName)); if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_PDLOps5(attr, "benefit", emitError))) return ::mlir::failure(); } { ::mlir::Attribute attr = attrs.get(getSymNameAttrName(opName)); if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_PDLOps1(attr, "sym_name", emitError))) return ::mlir::failure(); } return ::mlir::success(); } ::llvm::LogicalResult PatternOp::readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state) { auto &prop = state.getOrAddProperties(); (void)prop; if (::mlir::failed(reader.readAttribute(prop.benefit))) return ::mlir::failure(); if (::mlir::failed(reader.readOptionalAttribute(prop.sym_name))) return ::mlir::failure(); return ::mlir::success(); } void PatternOp::writeProperties(::mlir::DialectBytecodeWriter &writer) { auto &prop = getProperties(); (void)prop; writer.writeAttribute(prop.benefit); writer.writeOptionalAttribute(prop.sym_name); } uint16_t PatternOp::getBenefit() { auto attr = getBenefitAttr(); return attr.getValue().getZExtValue(); } ::std::optional< ::llvm::StringRef > PatternOp::getSymName() { auto attr = getSymNameAttr(); return attr ? ::std::optional< ::llvm::StringRef >(attr.getValue()) : (::std::nullopt); } void PatternOp::setBenefit(uint16_t attrValue) { getProperties().benefit = ::mlir::Builder((*this)->getContext()).getIntegerAttr(::mlir::Builder((*this)->getContext()).getIntegerType(16), attrValue); } void PatternOp::setSymName(::std::optional<::llvm::StringRef> attrValue) { auto &odsProp = getProperties().sym_name; if (attrValue) odsProp = ::mlir::Builder((*this)->getContext()).getStringAttr(*attrValue); else odsProp = nullptr; } PatternOp PatternOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, std::optional benefit, std::optional name) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(benefit), std::forward(name)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } PatternOp PatternOp::create(::mlir::ImplicitLocOpBuilder &builder, std::optional benefit, std::optional name) { return create(builder, builder.getLoc(), std::forward(benefit), std::forward(name)); } void PatternOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::IntegerAttr benefit, /*optional*/::mlir::StringAttr sym_name) { odsState.getOrAddProperties().benefit = benefit; if (sym_name) { odsState.getOrAddProperties().sym_name = sym_name; } (void)odsState.addRegion(); } PatternOp PatternOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::IntegerAttr benefit, /*optional*/::mlir::StringAttr sym_name) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(benefit), std::forward(sym_name)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } PatternOp PatternOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::IntegerAttr benefit, /*optional*/::mlir::StringAttr sym_name) { return create(builder, builder.getLoc(), std::forward(benefit), std::forward(sym_name)); } void PatternOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::IntegerAttr benefit, /*optional*/::mlir::StringAttr sym_name) { odsState.getOrAddProperties().benefit = benefit; if (sym_name) { odsState.getOrAddProperties().sym_name = sym_name; } (void)odsState.addRegion(); assert(resultTypes.size() == 0u && "mismatched number of results"); odsState.addTypes(resultTypes); } PatternOp PatternOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::IntegerAttr benefit, /*optional*/::mlir::StringAttr sym_name) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(benefit), std::forward(sym_name)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } PatternOp PatternOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::IntegerAttr benefit, /*optional*/::mlir::StringAttr sym_name) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(benefit), std::forward(sym_name)); } void PatternOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, uint16_t benefit, /*optional*/::mlir::StringAttr sym_name) { odsState.getOrAddProperties().benefit = odsBuilder.getIntegerAttr(odsBuilder.getIntegerType(16), benefit); if (sym_name) { odsState.getOrAddProperties().sym_name = sym_name; } (void)odsState.addRegion(); } PatternOp PatternOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, uint16_t benefit, /*optional*/::mlir::StringAttr sym_name) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(benefit), std::forward(sym_name)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } PatternOp PatternOp::create(::mlir::ImplicitLocOpBuilder &builder, uint16_t benefit, /*optional*/::mlir::StringAttr sym_name) { return create(builder, builder.getLoc(), std::forward(benefit), std::forward(sym_name)); } void PatternOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, uint16_t benefit, /*optional*/::mlir::StringAttr sym_name) { odsState.getOrAddProperties().benefit = odsBuilder.getIntegerAttr(odsBuilder.getIntegerType(16), benefit); if (sym_name) { odsState.getOrAddProperties().sym_name = sym_name; } (void)odsState.addRegion(); assert(resultTypes.size() == 0u && "mismatched number of results"); odsState.addTypes(resultTypes); } PatternOp PatternOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, uint16_t benefit, /*optional*/::mlir::StringAttr sym_name) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(benefit), std::forward(sym_name)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } PatternOp PatternOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, uint16_t benefit, /*optional*/::mlir::StringAttr sym_name) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(benefit), std::forward(sym_name)); } void PatternOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { assert(operands.size() == 0u && "mismatched number of parameters"); odsState.addOperands(operands); odsState.addAttributes(attributes); for (unsigned i = 0; i != 1; ++i) (void)odsState.addRegion(); assert(resultTypes.size() == 0u && "mismatched number of return types"); odsState.addTypes(resultTypes); if (!attributes.empty()) { (void)odsState.getOrAddProperties(); ::mlir::PropertyRef properties = odsState.getRawProperties(); std::optional<::mlir::RegisteredOperationName> info = odsState.name.getRegisteredInfo(); if (failed(info->setOpPropertiesFromAttribute(odsState.name, properties, odsState.attributes.getDictionary(odsState.getContext()), nullptr))) ::llvm::report_fatal_error("Property conversion failed."); } } PatternOp PatternOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(attributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } PatternOp PatternOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(attributes)); } void PatternOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { assert(operands.size() == 0u && "mismatched number of parameters"); odsState.addOperands(operands); odsState.useProperties(const_cast(properties)); odsState.addAttributes(discardableAttributes); for (unsigned i = 0; i != 1; ++i) (void)odsState.addRegion(); assert(resultTypes.size() == 0u && "mismatched number of return types"); odsState.addTypes(resultTypes); } PatternOp PatternOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } PatternOp PatternOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); } ::llvm::LogicalResult PatternOp::verifyInvariantsImpl() { auto tblgen_benefit = getProperties().benefit; (void)tblgen_benefit; if (!tblgen_benefit) return emitOpError("requires attribute 'benefit'"); auto tblgen_sym_name = getProperties().sym_name; (void)tblgen_sym_name; if (::mlir::failed(__mlir_ods_local_attr_constraint_PDLOps5(*this, tblgen_benefit, "benefit"))) return ::mlir::failure(); if (::mlir::failed(__mlir_ods_local_attr_constraint_PDLOps1(*this, tblgen_sym_name, "sym_name"))) return ::mlir::failure(); { unsigned index = 0; (void)index; for (auto ®ion : ::llvm::MutableArrayRef((*this)->getRegion(0))) if (::mlir::failed(__mlir_ods_local_region_constraint_PDLOps1(*this, region, "bodyRegion", index++))) return ::mlir::failure(); } return ::mlir::success(); } ::llvm::LogicalResult PatternOp::verifyInvariants() { return verifyInvariantsImpl(); } ::mlir::ParseResult PatternOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { ::mlir::StringAttr sym_nameAttr; ::mlir::IntegerAttr benefitAttr; std::unique_ptr<::mlir::Region> bodyRegionRegion = std::make_unique<::mlir::Region>(); // Parsing an optional symbol name doesn't fail, so no need to check the // result. (void)parser.parseOptionalSymbolName(sym_nameAttr); if (sym_nameAttr) result.getOrAddProperties().sym_name = sym_nameAttr; if (sym_nameAttr) { } if (parser.parseColon()) return ::mlir::failure(); if (parser.parseKeyword("benefit")) return ::mlir::failure(); if (parser.parseLParen()) return ::mlir::failure(); if (parser.parseCustomAttributeWithFallback(benefitAttr, parser.getBuilder().getIntegerType(16))) { return ::mlir::failure(); } if (benefitAttr) result.getOrAddProperties().benefit = benefitAttr; if (parser.parseRParen()) return ::mlir::failure(); { auto loc = parser.getCurrentLocation();(void)loc; if (parser.parseOptionalAttrDictWithKeyword(result.attributes)) return ::mlir::failure(); if (failed(verifyInherentAttrs(result.name, result.attributes, [&]() { return parser.emitError(loc) << "'" << result.name.getStringRef() << "' op "; }))) return ::mlir::failure(); } if (parser.parseRegion(*bodyRegionRegion)) return ::mlir::failure(); if (bodyRegionRegion->empty()) bodyRegionRegion->emplaceBlock(); result.addRegion(std::move(bodyRegionRegion)); return ::mlir::success(); } void PatternOp::print(::mlir::OpAsmPrinter &_odsPrinter) { if (getSymNameAttr()) { _odsPrinter << ' '; _odsPrinter.printSymbolName(getSymNameAttr().getValue()); } _odsPrinter << ' ' << ":"; _odsPrinter << ' ' << "benefit"; _odsPrinter << "("; _odsPrinter.printAttributeWithoutType(getBenefitAttr()); _odsPrinter << ")"; ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; elidedAttrs.push_back("sym_name"); elidedAttrs.push_back("benefit"); _odsPrinter.printOptionalAttrDictWithKeyword((*this)->getAttrs(), elidedAttrs); _odsPrinter << ' '; _odsPrinter.printRegion(getBodyRegion()); } } // namespace mlir::pdl MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::pdl::PatternOp) MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::pdl::detail::PatternOpGenericAdaptorBase::Properties) namespace mlir::pdl { //===----------------------------------------------------------------------===// // ::mlir::pdl::RangeOp definitions //===----------------------------------------------------------------------===// namespace detail { RangeOpGenericAdaptorBase::RangeOpGenericAdaptorBase(RangeOp op) : odsAttrs(op->getRawDictionaryAttrs()), odsOpName(op->getName()), properties(op.getProperties()), odsRegions(op->getRegions()) {} std::pair RangeOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { bool isVariadic[] = {true}; int prevVariadicCount = 0; for (unsigned i = 0; i < index; ++i) if (isVariadic[i]) ++prevVariadicCount; // Calculate how many dynamic values a static variadic operand corresponds to. // This assumes all static variadic operands have the same dynamic value count. int variadicSize = (odsOperandsSize - 0) / 1; // `index` passed in as the parameter is the static index which counts each // operand (variadic or not) as size 1. So here for each previous static variadic // operand, we need to offset by (variadicSize - 1) to get where the dynamic // value pack for this static operand starts. int start = index + (variadicSize - 1) * prevVariadicCount; int size = isVariadic[index] ? variadicSize : 1; return {start, size}; } } // namespace detail RangeOpAdaptor::RangeOpAdaptor(RangeOp op) : RangeOpGenericAdaptor(op->getOperands(), op) {} ::llvm::LogicalResult RangeOpAdaptor::verify(::mlir::Location loc) { return ::mlir::success(); } std::pair RangeOp::getODSOperandIndexAndLength(unsigned index) { bool isVariadic[] = {true}; int prevVariadicCount = 0; for (unsigned i = 0; i < index; ++i) if (isVariadic[i]) ++prevVariadicCount; // Calculate how many dynamic values a static variadic operand corresponds to. // This assumes all static variadic operands have the same dynamic value count. int variadicSize = (getOperation()->getNumOperands() - 0) / 1; // `index` passed in as the parameter is the static index which counts each // operand (variadic or not) as size 1. So here for each previous static variadic // operand, we need to offset by (variadicSize - 1) to get where the dynamic // value pack for this static operand starts. int start = index + (variadicSize - 1) * prevVariadicCount; int size = isVariadic[index] ? variadicSize : 1; return {start, size}; } ::mlir::MutableOperandRange RangeOp::getArgumentsMutable() { auto range = getODSOperandIndexAndLength(0); auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); return mutableRange; } ::llvm::LogicalResult RangeOp::setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { ::mlir::DictionaryAttr dict = ::llvm::dyn_cast<::mlir::DictionaryAttr>(attr); if (!dict) { emitError() << "expected DictionaryAttr to set properties"; return ::mlir::failure(); } return ::mlir::success(); } ::mlir::Attribute RangeOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) { ::mlir::SmallVector<::mlir::NamedAttribute> attrs; ::mlir::Builder odsBuilder{ctx}; if (!attrs.empty()) return odsBuilder.getDictionaryAttr(attrs); return {}; } llvm::hash_code RangeOp::computePropertiesHash(const Properties &prop) { using llvm::hash_value; return llvm::hash_combine(); } std::optional RangeOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { return std::nullopt; } void RangeOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { } void RangeOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { } ::llvm::LogicalResult RangeOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { return ::mlir::success(); } void RangeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type result, ::mlir::ValueRange arguments) { odsState.addOperands(arguments); odsState.addTypes(result); } RangeOp RangeOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Type result, ::mlir::ValueRange arguments) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(result), std::forward(arguments)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } RangeOp RangeOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Type result, ::mlir::ValueRange arguments) { return create(builder, builder.getLoc(), std::forward(result), std::forward(arguments)); } void RangeOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { odsState.addOperands(operands); odsState.addAttributes(attributes); assert(resultTypes.size() == 1u && "mismatched number of return types"); odsState.addTypes(resultTypes); } RangeOp RangeOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(attributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } RangeOp RangeOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(attributes)); } void RangeOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { odsState.addOperands(operands); odsState.useProperties(const_cast(properties)); odsState.addAttributes(discardableAttributes); assert(resultTypes.size() == 1u && "mismatched number of return types"); odsState.addTypes(resultTypes); } RangeOp RangeOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } RangeOp RangeOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); } ::llvm::LogicalResult RangeOp::verifyInvariantsImpl() { { unsigned index = 0; (void)index; auto valueGroup0 = getODSOperands(0); for (auto v : valueGroup0) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps1(*this, v.getType(), "operand", index++))) return ::mlir::failure(); } } { unsigned index = 0; (void)index; auto valueGroup0 = getODSResults(0); for (auto v : valueGroup0) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps11(*this, v.getType(), "result", index++))) return ::mlir::failure(); } } return ::mlir::success(); } ::llvm::LogicalResult RangeOp::verifyInvariants() { if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) return ::mlir::success(); return ::mlir::failure(); } ::mlir::ParseResult RangeOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> argumentsOperands; ::llvm::SMLoc argumentsOperandsLoc; (void)argumentsOperandsLoc; ::llvm::SmallVector<::mlir::Type, 1> argumentsTypes; ::mlir::Type resultRawType{}; ::llvm::ArrayRef<::mlir::Type> resultTypes(&resultRawType, 1); argumentsOperandsLoc = parser.getCurrentLocation(); if (parser.parseOperandList(argumentsOperands)) return ::mlir::failure(); if (!argumentsOperands.empty()) { if (parser.parseColon()) return ::mlir::failure(); if (parser.parseTypeList(argumentsTypes)) return ::mlir::failure(); } { auto odsResult = parseRangeType(parser, argumentsTypes, resultRawType); if (odsResult) return ::mlir::failure(); } { auto loc = parser.getCurrentLocation();(void)loc; if (parser.parseOptionalAttrDict(result.attributes)) return ::mlir::failure(); if (failed(verifyInherentAttrs(result.name, result.attributes, [&]() { return parser.emitError(loc) << "'" << result.name.getStringRef() << "' op "; }))) return ::mlir::failure(); } result.addTypes(resultTypes); if (parser.resolveOperands(argumentsOperands, argumentsTypes, argumentsOperandsLoc, result.operands)) return ::mlir::failure(); return ::mlir::success(); } void RangeOp::print(::mlir::OpAsmPrinter &_odsPrinter) { if (!getArguments().empty()) { _odsPrinter << ' '; _odsPrinter << getArguments(); _odsPrinter << ' ' << ":"; _odsPrinter << ' '; _odsPrinter << getArguments().getTypes(); } _odsPrinter << ' '; printRangeType(_odsPrinter, *this, getArguments().getTypes(), getResult().getType()); ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); } void RangeOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { } } // namespace mlir::pdl MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::pdl::RangeOp) namespace mlir::pdl { //===----------------------------------------------------------------------===// // ::mlir::pdl::ReplaceOp definitions //===----------------------------------------------------------------------===// namespace detail { ReplaceOpGenericAdaptorBase::ReplaceOpGenericAdaptorBase(ReplaceOp op) : odsAttrs(op->getRawDictionaryAttrs()), odsOpName(op->getName()), properties(op.getProperties()), odsRegions(op->getRegions()) {} std::pair ReplaceOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { ::llvm::ArrayRef sizeAttr = getProperties().operandSegmentSizes; unsigned start = 0; for (unsigned i = 0; i < index; ++i) start += sizeAttr[i]; return {start, sizeAttr[index]}; } } // namespace detail ReplaceOpAdaptor::ReplaceOpAdaptor(ReplaceOp op) : ReplaceOpGenericAdaptor(op->getOperands(), op) {} ::llvm::LogicalResult ReplaceOpAdaptor::verify(::mlir::Location loc) { return ::mlir::success(); } std::pair ReplaceOp::getODSOperandIndexAndLength(unsigned index) { ::llvm::ArrayRef sizeAttr = getProperties().operandSegmentSizes; unsigned start = 0; for (unsigned i = 0; i < index; ++i) start += sizeAttr[i]; return {start, sizeAttr[index]}; } ::mlir::MutableOperandRange ReplaceOp::getReplOperationMutable() { auto range = getODSOperandIndexAndLength(1); auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(1u, {getOperandSegmentSizesAttrName(), ::mlir::DenseI32ArrayAttr::get(getContext(), getProperties().operandSegmentSizes)})); return mutableRange; } ::mlir::MutableOperandRange ReplaceOp::getReplValuesMutable() { auto range = getODSOperandIndexAndLength(2); auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(2u, {getOperandSegmentSizesAttrName(), ::mlir::DenseI32ArrayAttr::get(getContext(), getProperties().operandSegmentSizes)})); return mutableRange; } ::llvm::LogicalResult ReplaceOp::setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { ::mlir::DictionaryAttr dict = ::llvm::dyn_cast<::mlir::DictionaryAttr>(attr); if (!dict) { emitError() << "expected DictionaryAttr to set properties"; return ::mlir::failure(); } { auto setFromAttr = [] (auto &propStorage, ::mlir::Attribute propAttr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) -> ::mlir::LogicalResult { return convertFromAttribute(propStorage, propAttr, emitError); }; auto attr = dict.get("operandSegmentSizes"); if (!attr) attr = dict.get("operand_segment_sizes");; ; if (attr && ::mlir::failed(setFromAttr(prop.operandSegmentSizes, attr, [&]() { return emitError() << "for `operandSegmentSizes`: "; }))) return ::mlir::failure(); } return ::mlir::success(); } ::mlir::Attribute ReplaceOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) { ::mlir::SmallVector<::mlir::NamedAttribute> attrs; ::mlir::Builder odsBuilder{ctx}; { const auto &propStorage = prop.operandSegmentSizes; auto attr = [&]() -> ::mlir::Attribute { return ::mlir::DenseI32ArrayAttr::get(ctx, propStorage); }(); attrs.push_back(odsBuilder.getNamedAttr("operandSegmentSizes", attr)); } if (!attrs.empty()) return odsBuilder.getDictionaryAttr(attrs); return {}; } llvm::hash_code ReplaceOp::computePropertiesHash(const Properties &prop) { auto hash_operandSegmentSizes_ = [] (const auto &propStorage) -> llvm::hash_code { using ::llvm::hash_value; return ::llvm::hash_combine_range(std::begin(propStorage), std::end(propStorage));; }; using llvm::hash_value; return llvm::hash_combine( hash_operandSegmentSizes_(prop.operandSegmentSizes)); } std::optional ReplaceOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { if (name == "operand_segment_sizes" || name == "operandSegmentSizes") return [&]() -> ::mlir::Attribute { return ::mlir::DenseI32ArrayAttr::get(ctx, prop.operandSegmentSizes); }(); return std::nullopt; } void ReplaceOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { if (name == "operand_segment_sizes" || name == "operandSegmentSizes") { auto arrAttr = ::llvm::dyn_cast_or_null<::mlir::DenseI32ArrayAttr>(value); if (!arrAttr) return; if (arrAttr.size() != sizeof(prop.operandSegmentSizes) / sizeof(int32_t)) return; llvm::copy(arrAttr.asArrayRef(), prop.operandSegmentSizes.begin()); return; } } void ReplaceOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { attrs.append("operandSegmentSizes", [&]() -> ::mlir::Attribute { return ::mlir::DenseI32ArrayAttr::get(ctx, prop.operandSegmentSizes); }()); } ::llvm::LogicalResult ReplaceOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { return ::mlir::success(); } ::llvm::LogicalResult ReplaceOp::readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state) { auto &prop = state.getOrAddProperties(); (void)prop; if (reader.getBytecodeVersion() < /*kNativePropertiesODSSegmentSize=*/6) { auto &propStorage = prop.operandSegmentSizes; ::mlir::DenseI32ArrayAttr attr; if (::mlir::failed(reader.readAttribute(attr))) return ::mlir::failure(); if (attr.size() > static_cast(sizeof(propStorage) / sizeof(int32_t))) { reader.emitError("size mismatch for operand/result_segment_size"); return ::mlir::failure(); } ::llvm::copy(::llvm::ArrayRef(attr), propStorage.begin()); } { auto &propStorage = prop.operandSegmentSizes; auto readProp = [&]() { if (reader.getBytecodeVersion() >= /*kNativePropertiesODSSegmentSize=*/6) return reader.readSparseArray(::llvm::MutableArrayRef(propStorage)); ; return ::mlir::success(); }; if (::mlir::failed(readProp())) return ::mlir::failure(); } return ::mlir::success(); } void ReplaceOp::writeProperties(::mlir::DialectBytecodeWriter &writer) { auto &prop = getProperties(); (void)prop; if (writer.getBytecodeVersion() < /*kNativePropertiesODSSegmentSize=*/6) { auto &propStorage = prop.operandSegmentSizes; writer.writeAttribute(::mlir::DenseI32ArrayAttr::get(this->getContext(), propStorage)); } { auto &propStorage = prop.operandSegmentSizes; if (writer.getBytecodeVersion() >= /*kNativePropertiesODSSegmentSize=*/6) writer.writeSparseArray(::llvm::ArrayRef(propStorage)); ; } } void ReplaceOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value opValue, /*optional*/::mlir::Value replOperation, ::mlir::ValueRange replValues) { odsState.addOperands(opValue); if (replOperation) odsState.addOperands(replOperation); odsState.addOperands(replValues); ::llvm::copy(::llvm::ArrayRef({1, (replOperation ? 1 : 0), static_cast(replValues.size())}), odsState.getOrAddProperties().operandSegmentSizes.begin()); } ReplaceOp ReplaceOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Value opValue, /*optional*/::mlir::Value replOperation, ::mlir::ValueRange replValues) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(opValue), std::forward(replOperation), std::forward(replValues)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } ReplaceOp ReplaceOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Value opValue, /*optional*/::mlir::Value replOperation, ::mlir::ValueRange replValues) { return create(builder, builder.getLoc(), std::forward(opValue), std::forward(replOperation), std::forward(replValues)); } void ReplaceOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value opValue, /*optional*/::mlir::Value replOperation, ::mlir::ValueRange replValues) { odsState.addOperands(opValue); if (replOperation) odsState.addOperands(replOperation); odsState.addOperands(replValues); ::llvm::copy(::llvm::ArrayRef({1, (replOperation ? 1 : 0), static_cast(replValues.size())}), odsState.getOrAddProperties().operandSegmentSizes.begin()); assert(resultTypes.size() == 0u && "mismatched number of results"); odsState.addTypes(resultTypes); } ReplaceOp ReplaceOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::Value opValue, /*optional*/::mlir::Value replOperation, ::mlir::ValueRange replValues) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(opValue), std::forward(replOperation), std::forward(replValues)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } ReplaceOp ReplaceOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::Value opValue, /*optional*/::mlir::Value replOperation, ::mlir::ValueRange replValues) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(opValue), std::forward(replOperation), std::forward(replValues)); } void ReplaceOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { assert(operands.size() >= 1u && "mismatched number of parameters"); odsState.addOperands(operands); odsState.addAttributes(attributes); assert(resultTypes.size() == 0u && "mismatched number of return types"); odsState.addTypes(resultTypes); if (!attributes.empty()) { (void)odsState.getOrAddProperties(); ::mlir::PropertyRef properties = odsState.getRawProperties(); std::optional<::mlir::RegisteredOperationName> info = odsState.name.getRegisteredInfo(); if (failed(info->setOpPropertiesFromAttribute(odsState.name, properties, odsState.attributes.getDictionary(odsState.getContext()), nullptr))) ::llvm::report_fatal_error("Property conversion failed."); } } ReplaceOp ReplaceOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(attributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } ReplaceOp ReplaceOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(attributes)); } void ReplaceOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { assert(operands.size() >= 1u && "mismatched number of parameters"); odsState.addOperands(operands); odsState.useProperties(const_cast(properties)); odsState.addAttributes(discardableAttributes); assert(resultTypes.size() == 0u && "mismatched number of return types"); odsState.addTypes(resultTypes); } ReplaceOp ReplaceOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } ReplaceOp ReplaceOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); } ::llvm::LogicalResult ReplaceOp::verifyInvariantsImpl() { { unsigned index = 0; (void)index; auto valueGroup0 = getODSOperands(0); for (auto v : valueGroup0) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps4(*this, v.getType(), "operand", index++))) return ::mlir::failure(); } auto valueGroup1 = getODSOperands(1); if (valueGroup1.size() > 1) { return emitOpError("operand group starting at #") << index << " requires 0 or 1 element, but found " << valueGroup1.size(); } for (auto v : valueGroup1) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps4(*this, v.getType(), "operand", index++))) return ::mlir::failure(); } auto valueGroup2 = getODSOperands(2); for (auto v : valueGroup2) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps8(*this, v.getType(), "operand", index++))) return ::mlir::failure(); } } return ::mlir::success(); } ::llvm::LogicalResult ReplaceOp::verifyInvariants() { if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) return ::mlir::success(); return ::mlir::failure(); } ::mlir::ParseResult ReplaceOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { ::mlir::OpAsmParser::UnresolvedOperand opValueRawOperand{}; ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> opValueOperands(&opValueRawOperand, 1); ::llvm::SMLoc opValueOperandsLoc; (void)opValueOperandsLoc; ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> replValuesOperands; ::llvm::SMLoc replValuesOperandsLoc; (void)replValuesOperandsLoc; ::llvm::SmallVector<::mlir::Type, 1> replValuesTypes; ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> replOperationOperands; ::llvm::SMLoc replOperationOperandsLoc; (void)replOperationOperandsLoc; opValueOperandsLoc = parser.getCurrentLocation(); if (parser.parseOperand(opValueRawOperand)) return ::mlir::failure(); if (parser.parseKeyword("with")) return ::mlir::failure(); if (::mlir::succeeded(parser.parseOptionalLParen())) { replValuesOperandsLoc = parser.getCurrentLocation(); if (parser.parseOperandList(replValuesOperands)) return ::mlir::failure(); if (parser.parseColon()) return ::mlir::failure(); if (parser.parseTypeList(replValuesTypes)) return ::mlir::failure(); if (parser.parseRParen()) return ::mlir::failure(); } { replOperationOperandsLoc = parser.getCurrentLocation(); ::mlir::OpAsmParser::UnresolvedOperand operand; ::mlir::OptionalParseResult parseResult = parser.parseOptionalOperand(operand); if (parseResult.has_value()) { if (failed(*parseResult)) return ::mlir::failure(); replOperationOperands.push_back(operand); } } if (!replOperationOperands.empty()) { } { auto loc = parser.getCurrentLocation();(void)loc; if (parser.parseOptionalAttrDict(result.attributes)) return ::mlir::failure(); if (failed(verifyInherentAttrs(result.name, result.attributes, [&]() { return parser.emitError(loc) << "'" << result.name.getStringRef() << "' op "; }))) return ::mlir::failure(); } ::llvm::copy(::llvm::ArrayRef({1, static_cast(replOperationOperands.size()), static_cast(replValuesOperands.size())}), result.getOrAddProperties().operandSegmentSizes.begin()); ::mlir::Type odsBuildableType0 = parser.getBuilder().getType<::mlir::pdl::OperationType>(); if (parser.resolveOperands(opValueOperands, odsBuildableType0, opValueOperandsLoc, result.operands)) return ::mlir::failure(); if (!replOperationOperands.empty()) { if (parser.resolveOperands(replOperationOperands, odsBuildableType0, replOperationOperandsLoc, result.operands)) return ::mlir::failure(); } if (parser.resolveOperands(replValuesOperands, replValuesTypes, replValuesOperandsLoc, result.operands)) return ::mlir::failure(); return ::mlir::success(); } void ReplaceOp::print(::mlir::OpAsmPrinter &_odsPrinter) { _odsPrinter << ' '; _odsPrinter << getOpValue(); _odsPrinter << ' ' << "with"; if (!getReplValues().empty()) { _odsPrinter << "("; _odsPrinter << getReplValues(); _odsPrinter << ' ' << ":"; _odsPrinter << ' '; _odsPrinter << getReplValues().getTypes(); _odsPrinter << ")"; } if (getReplOperation()) { _odsPrinter << ' '; if (::mlir::Value value = getReplOperation()) _odsPrinter << value; } ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; elidedAttrs.push_back("operandSegmentSizes"); _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); } } // namespace mlir::pdl MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::pdl::ReplaceOp) MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::pdl::detail::ReplaceOpGenericAdaptorBase::Properties) namespace mlir::pdl { //===----------------------------------------------------------------------===// // ::mlir::pdl::ResultOp definitions //===----------------------------------------------------------------------===// namespace detail { ResultOpGenericAdaptorBase::ResultOpGenericAdaptorBase(ResultOp op) : odsAttrs(op->getRawDictionaryAttrs()), odsOpName(op->getName()), properties(op.getProperties()), odsRegions(op->getRegions()) {} uint32_t ResultOpGenericAdaptorBase::getIndex() { auto attr = getIndexAttr(); return attr.getValue().getZExtValue(); } } // namespace detail ResultOpAdaptor::ResultOpAdaptor(ResultOp op) : ResultOpGenericAdaptor(op->getOperands(), op) {} ::llvm::LogicalResult ResultOpAdaptor::verify(::mlir::Location loc) { auto tblgen_index = getProperties().index; (void)tblgen_index; if (!tblgen_index) return emitError(loc, "'pdl.result' op requires attribute 'index'"); if (tblgen_index && !(((::llvm::isa<::mlir::IntegerAttr>(tblgen_index))) && ((::llvm::cast<::mlir::IntegerAttr>(tblgen_index).getType().isSignlessInteger(32))))) return emitError(loc, "'pdl.result' op attribute 'index' failed to satisfy constraint: 32-bit signless integer attribute"); return ::mlir::success(); } ::llvm::LogicalResult ResultOp::setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { ::mlir::DictionaryAttr dict = ::llvm::dyn_cast<::mlir::DictionaryAttr>(attr); if (!dict) { emitError() << "expected DictionaryAttr to set properties"; return ::mlir::failure(); } { auto &propStorage = prop.index; auto attr = dict.get("index"); if (attr) { auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `index` in property conversion: " << attr; return ::mlir::failure(); } } } return ::mlir::success(); } ::mlir::Attribute ResultOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) { ::mlir::SmallVector<::mlir::NamedAttribute> attrs; ::mlir::Builder odsBuilder{ctx}; { const auto &propStorage = prop.index; if (propStorage) attrs.push_back(odsBuilder.getNamedAttr("index", propStorage)); } if (!attrs.empty()) return odsBuilder.getDictionaryAttr(attrs); return {}; } llvm::hash_code ResultOp::computePropertiesHash(const Properties &prop) { using llvm::hash_value; return llvm::hash_combine( llvm::hash_value(prop.index.getAsOpaquePointer())); } std::optional ResultOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { if (name == "index") return prop.index; return std::nullopt; } void ResultOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { if (name == "index") { prop.index = ::llvm::dyn_cast_or_null>(value); return; } } void ResultOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { if (prop.index) attrs.append("index", prop.index); } ::llvm::LogicalResult ResultOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { { ::mlir::Attribute attr = attrs.get(getIndexAttrName(opName)); if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_PDLOps6(attr, "index", emitError))) return ::mlir::failure(); } return ::mlir::success(); } ::llvm::LogicalResult ResultOp::readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state) { auto &prop = state.getOrAddProperties(); (void)prop; if (::mlir::failed(reader.readAttribute(prop.index))) return ::mlir::failure(); return ::mlir::success(); } void ResultOp::writeProperties(::mlir::DialectBytecodeWriter &writer) { auto &prop = getProperties(); (void)prop; writer.writeAttribute(prop.index); } uint32_t ResultOp::getIndex() { auto attr = getIndexAttr(); return attr.getValue().getZExtValue(); } void ResultOp::setIndex(uint32_t attrValue) { getProperties().index = ::mlir::Builder((*this)->getContext()).getIntegerAttr(::mlir::Builder((*this)->getContext()).getIntegerType(32), attrValue); } void ResultOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type val, ::mlir::Value parent, ::mlir::IntegerAttr index) { odsState.addOperands(parent); odsState.getOrAddProperties().index = index; odsState.addTypes(val); } ResultOp ResultOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Type val, ::mlir::Value parent, ::mlir::IntegerAttr index) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(val), std::forward(parent), std::forward(index)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } ResultOp ResultOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Type val, ::mlir::Value parent, ::mlir::IntegerAttr index) { return create(builder, builder.getLoc(), std::forward(val), std::forward(parent), std::forward(index)); } void ResultOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value parent, ::mlir::IntegerAttr index) { odsState.addOperands(parent); odsState.getOrAddProperties().index = index; assert(resultTypes.size() == 1u && "mismatched number of results"); odsState.addTypes(resultTypes); } ResultOp ResultOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::Value parent, ::mlir::IntegerAttr index) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(parent), std::forward(index)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } ResultOp ResultOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::Value parent, ::mlir::IntegerAttr index) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(parent), std::forward(index)); } void ResultOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type val, ::mlir::Value parent, uint32_t index) { odsState.addOperands(parent); odsState.getOrAddProperties().index = odsBuilder.getIntegerAttr(odsBuilder.getIntegerType(32), index); odsState.addTypes(val); } ResultOp ResultOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Type val, ::mlir::Value parent, uint32_t index) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(val), std::forward(parent), std::forward(index)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } ResultOp ResultOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Type val, ::mlir::Value parent, uint32_t index) { return create(builder, builder.getLoc(), std::forward(val), std::forward(parent), std::forward(index)); } void ResultOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value parent, uint32_t index) { odsState.addOperands(parent); odsState.getOrAddProperties().index = odsBuilder.getIntegerAttr(odsBuilder.getIntegerType(32), index); assert(resultTypes.size() == 1u && "mismatched number of results"); odsState.addTypes(resultTypes); } ResultOp ResultOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::Value parent, uint32_t index) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(parent), std::forward(index)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } ResultOp ResultOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::Value parent, uint32_t index) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(parent), std::forward(index)); } void ResultOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { assert(operands.size() == 1u && "mismatched number of parameters"); odsState.addOperands(operands); odsState.addAttributes(attributes); assert(resultTypes.size() == 1u && "mismatched number of return types"); odsState.addTypes(resultTypes); if (!attributes.empty()) { (void)odsState.getOrAddProperties(); ::mlir::PropertyRef properties = odsState.getRawProperties(); std::optional<::mlir::RegisteredOperationName> info = odsState.name.getRegisteredInfo(); if (failed(info->setOpPropertiesFromAttribute(odsState.name, properties, odsState.attributes.getDictionary(odsState.getContext()), nullptr))) ::llvm::report_fatal_error("Property conversion failed."); } } ResultOp ResultOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(attributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } ResultOp ResultOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(attributes)); } void ResultOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { assert(operands.size() == 1u && "mismatched number of parameters"); odsState.addOperands(operands); odsState.useProperties(const_cast(properties)); odsState.addAttributes(discardableAttributes); assert(resultTypes.size() == 1u && "mismatched number of return types"); odsState.addTypes(resultTypes); } ResultOp ResultOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } ResultOp ResultOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); } ::llvm::LogicalResult ResultOp::verifyInvariantsImpl() { auto tblgen_index = getProperties().index; (void)tblgen_index; if (!tblgen_index) return emitOpError("requires attribute 'index'"); if (::mlir::failed(__mlir_ods_local_attr_constraint_PDLOps6(*this, tblgen_index, "index"))) return ::mlir::failure(); { unsigned index = 0; (void)index; auto valueGroup0 = getODSOperands(0); for (auto v : valueGroup0) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps4(*this, v.getType(), "operand", index++))) return ::mlir::failure(); } } { unsigned index = 0; (void)index; auto valueGroup0 = getODSResults(0); for (auto v : valueGroup0) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps5(*this, v.getType(), "result", index++))) return ::mlir::failure(); } } return ::mlir::success(); } ::llvm::LogicalResult ResultOp::verifyInvariants() { return verifyInvariantsImpl(); } ::mlir::ParseResult ResultOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { ::mlir::IntegerAttr indexAttr; ::mlir::OpAsmParser::UnresolvedOperand parentRawOperand{}; ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> parentOperands(&parentRawOperand, 1); ::llvm::SMLoc parentOperandsLoc; (void)parentOperandsLoc; if (parser.parseCustomAttributeWithFallback(indexAttr, parser.getBuilder().getIntegerType(32))) { return ::mlir::failure(); } if (indexAttr) result.getOrAddProperties().index = indexAttr; if (parser.parseKeyword("of")) return ::mlir::failure(); parentOperandsLoc = parser.getCurrentLocation(); if (parser.parseOperand(parentRawOperand)) return ::mlir::failure(); { auto loc = parser.getCurrentLocation();(void)loc; if (parser.parseOptionalAttrDict(result.attributes)) return ::mlir::failure(); if (failed(verifyInherentAttrs(result.name, result.attributes, [&]() { return parser.emitError(loc) << "'" << result.name.getStringRef() << "' op "; }))) return ::mlir::failure(); } ::mlir::Type odsBuildableType0 = parser.getBuilder().getType<::mlir::pdl::ValueType>(); ::mlir::Type odsBuildableType1 = parser.getBuilder().getType<::mlir::pdl::OperationType>(); result.addTypes(odsBuildableType0); if (parser.resolveOperands(parentOperands, odsBuildableType1, parentOperandsLoc, result.operands)) return ::mlir::failure(); return ::mlir::success(); } void ResultOp::print(::mlir::OpAsmPrinter &_odsPrinter) { _odsPrinter << ' '; _odsPrinter.printAttributeWithoutType(getIndexAttr()); _odsPrinter << ' ' << "of"; _odsPrinter << ' '; _odsPrinter << getParent(); ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; elidedAttrs.push_back("index"); _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); } void ResultOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { } } // namespace mlir::pdl MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::pdl::ResultOp) MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::pdl::detail::ResultOpGenericAdaptorBase::Properties) namespace mlir::pdl { //===----------------------------------------------------------------------===// // ::mlir::pdl::ResultsOp definitions //===----------------------------------------------------------------------===// namespace detail { ResultsOpGenericAdaptorBase::ResultsOpGenericAdaptorBase(ResultsOp op) : odsAttrs(op->getRawDictionaryAttrs()), odsOpName(op->getName()), properties(op.getProperties()), odsRegions(op->getRegions()) {} ::std::optional ResultsOpGenericAdaptorBase::getIndex() { auto attr = getIndexAttr(); return attr ? ::std::optional(attr.getValue().getZExtValue()) : (::std::nullopt); } } // namespace detail ResultsOpAdaptor::ResultsOpAdaptor(ResultsOp op) : ResultsOpGenericAdaptor(op->getOperands(), op) {} ::llvm::LogicalResult ResultsOpAdaptor::verify(::mlir::Location loc) { auto tblgen_index = getProperties().index; (void)tblgen_index; if (tblgen_index && !(((::llvm::isa<::mlir::IntegerAttr>(tblgen_index))) && ((::llvm::cast<::mlir::IntegerAttr>(tblgen_index).getType().isSignlessInteger(32))))) return emitError(loc, "'pdl.results' op attribute 'index' failed to satisfy constraint: 32-bit signless integer attribute"); return ::mlir::success(); } ::llvm::LogicalResult ResultsOp::setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { ::mlir::DictionaryAttr dict = ::llvm::dyn_cast<::mlir::DictionaryAttr>(attr); if (!dict) { emitError() << "expected DictionaryAttr to set properties"; return ::mlir::failure(); } { auto &propStorage = prop.index; auto attr = dict.get("index"); if (attr) { auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `index` in property conversion: " << attr; return ::mlir::failure(); } } } return ::mlir::success(); } ::mlir::Attribute ResultsOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) { ::mlir::SmallVector<::mlir::NamedAttribute> attrs; ::mlir::Builder odsBuilder{ctx}; { const auto &propStorage = prop.index; if (propStorage) attrs.push_back(odsBuilder.getNamedAttr("index", propStorage)); } if (!attrs.empty()) return odsBuilder.getDictionaryAttr(attrs); return {}; } llvm::hash_code ResultsOp::computePropertiesHash(const Properties &prop) { using llvm::hash_value; return llvm::hash_combine( llvm::hash_value(prop.index.getAsOpaquePointer())); } std::optional ResultsOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { if (name == "index") return prop.index; return std::nullopt; } void ResultsOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { if (name == "index") { prop.index = ::llvm::dyn_cast_or_null>(value); return; } } void ResultsOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { if (prop.index) attrs.append("index", prop.index); } ::llvm::LogicalResult ResultsOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { { ::mlir::Attribute attr = attrs.get(getIndexAttrName(opName)); if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_PDLOps6(attr, "index", emitError))) return ::mlir::failure(); } return ::mlir::success(); } ::llvm::LogicalResult ResultsOp::readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state) { auto &prop = state.getOrAddProperties(); (void)prop; if (::mlir::failed(reader.readOptionalAttribute(prop.index))) return ::mlir::failure(); return ::mlir::success(); } void ResultsOp::writeProperties(::mlir::DialectBytecodeWriter &writer) { auto &prop = getProperties(); (void)prop; writer.writeOptionalAttribute(prop.index); } ::std::optional ResultsOp::getIndex() { auto attr = getIndexAttr(); return attr ? ::std::optional(attr.getValue().getZExtValue()) : (::std::nullopt); } void ResultsOp::setIndex(::std::optional attrValue) { auto &odsProp = getProperties().index; if (attrValue) odsProp = ::mlir::Builder((*this)->getContext()).getIntegerAttr(::mlir::Builder((*this)->getContext()).getIntegerType(32), *attrValue); else odsProp = nullptr; } void ResultsOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type val, ::mlir::Value parent, /*optional*/::mlir::IntegerAttr index) { odsState.addOperands(parent); if (index) { odsState.getOrAddProperties().index = index; } odsState.addTypes(val); } ResultsOp ResultsOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Type val, ::mlir::Value parent, /*optional*/::mlir::IntegerAttr index) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(val), std::forward(parent), std::forward(index)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } ResultsOp ResultsOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Type val, ::mlir::Value parent, /*optional*/::mlir::IntegerAttr index) { return create(builder, builder.getLoc(), std::forward(val), std::forward(parent), std::forward(index)); } void ResultsOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value parent, /*optional*/::mlir::IntegerAttr index) { odsState.addOperands(parent); if (index) { odsState.getOrAddProperties().index = index; } assert(resultTypes.size() == 1u && "mismatched number of results"); odsState.addTypes(resultTypes); } ResultsOp ResultsOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::Value parent, /*optional*/::mlir::IntegerAttr index) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(parent), std::forward(index)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } ResultsOp ResultsOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::Value parent, /*optional*/::mlir::IntegerAttr index) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(parent), std::forward(index)); } void ResultsOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { assert(operands.size() == 1u && "mismatched number of parameters"); odsState.addOperands(operands); odsState.addAttributes(attributes); assert(resultTypes.size() == 1u && "mismatched number of return types"); odsState.addTypes(resultTypes); if (!attributes.empty()) { (void)odsState.getOrAddProperties(); ::mlir::PropertyRef properties = odsState.getRawProperties(); std::optional<::mlir::RegisteredOperationName> info = odsState.name.getRegisteredInfo(); if (failed(info->setOpPropertiesFromAttribute(odsState.name, properties, odsState.attributes.getDictionary(odsState.getContext()), nullptr))) ::llvm::report_fatal_error("Property conversion failed."); } } ResultsOp ResultsOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(attributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } ResultsOp ResultsOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(attributes)); } void ResultsOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { assert(operands.size() == 1u && "mismatched number of parameters"); odsState.addOperands(operands); odsState.useProperties(const_cast(properties)); odsState.addAttributes(discardableAttributes); assert(resultTypes.size() == 1u && "mismatched number of return types"); odsState.addTypes(resultTypes); } ResultsOp ResultsOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } ResultsOp ResultsOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); } ::llvm::LogicalResult ResultsOp::verifyInvariantsImpl() { auto tblgen_index = getProperties().index; (void)tblgen_index; if (::mlir::failed(__mlir_ods_local_attr_constraint_PDLOps6(*this, tblgen_index, "index"))) return ::mlir::failure(); { unsigned index = 0; (void)index; auto valueGroup0 = getODSOperands(0); for (auto v : valueGroup0) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps4(*this, v.getType(), "operand", index++))) return ::mlir::failure(); } } { unsigned index = 0; (void)index; auto valueGroup0 = getODSResults(0); for (auto v : valueGroup0) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps12(*this, v.getType(), "result", index++))) return ::mlir::failure(); } } return ::mlir::success(); } ::llvm::LogicalResult ResultsOp::verifyInvariants() { if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) return ::mlir::success(); return ::mlir::failure(); } ::mlir::ParseResult ResultsOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { ::mlir::IntegerAttr indexAttr; ::mlir::OpAsmParser::UnresolvedOperand parentRawOperand{}; ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> parentOperands(&parentRawOperand, 1); ::llvm::SMLoc parentOperandsLoc; (void)parentOperandsLoc; ::mlir::Type valRawType{}; ::llvm::ArrayRef<::mlir::Type> valTypes(&valRawType, 1); ::mlir::OptionalParseResult parseResultindexAttr = parser.parseOptionalAttribute(indexAttr, parser.getBuilder().getIntegerType(32)); if (parseResultindexAttr.has_value() && failed(*parseResultindexAttr)) return ::mlir::failure(); if (parseResultindexAttr.has_value() && succeeded(*parseResultindexAttr)) if (indexAttr) result.getOrAddProperties().index = indexAttr; if (indexAttr) { } if (parser.parseKeyword("of")) return ::mlir::failure(); parentOperandsLoc = parser.getCurrentLocation(); if (parser.parseOperand(parentRawOperand)) return ::mlir::failure(); { auto odsResult = parseResultsValueType(parser, indexAttr, valRawType); if (odsResult) return ::mlir::failure(); } { auto loc = parser.getCurrentLocation();(void)loc; if (parser.parseOptionalAttrDict(result.attributes)) return ::mlir::failure(); if (failed(verifyInherentAttrs(result.name, result.attributes, [&]() { return parser.emitError(loc) << "'" << result.name.getStringRef() << "' op "; }))) return ::mlir::failure(); } ::mlir::Type odsBuildableType0 = parser.getBuilder().getType<::mlir::pdl::OperationType>(); result.addTypes(valTypes); if (parser.resolveOperands(parentOperands, odsBuildableType0, parentOperandsLoc, result.operands)) return ::mlir::failure(); return ::mlir::success(); } void ResultsOp::print(::mlir::OpAsmPrinter &_odsPrinter) { if (getIndexAttr()) { _odsPrinter << ' '; _odsPrinter.printAttributeWithoutType(getIndexAttr()); } _odsPrinter << ' ' << "of"; _odsPrinter << ' '; _odsPrinter << getParent(); _odsPrinter << ' '; printResultsValueType(_odsPrinter, *this, getIndexAttr(), getVal().getType()); ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; elidedAttrs.push_back("index"); _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); } void ResultsOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { } } // namespace mlir::pdl MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::pdl::ResultsOp) MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::pdl::detail::ResultsOpGenericAdaptorBase::Properties) namespace mlir::pdl { //===----------------------------------------------------------------------===// // ::mlir::pdl::RewriteOp definitions //===----------------------------------------------------------------------===// namespace detail { RewriteOpGenericAdaptorBase::RewriteOpGenericAdaptorBase(RewriteOp op) : odsAttrs(op->getRawDictionaryAttrs()), odsOpName(op->getName()), properties(op.getProperties()), odsRegions(op->getRegions()) {} std::pair RewriteOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { ::llvm::ArrayRef sizeAttr = getProperties().operandSegmentSizes; unsigned start = 0; for (unsigned i = 0; i < index; ++i) start += sizeAttr[i]; return {start, sizeAttr[index]}; } ::std::optional< ::llvm::StringRef > RewriteOpGenericAdaptorBase::getName() { auto attr = getNameAttr(); return attr ? ::std::optional< ::llvm::StringRef >(attr.getValue()) : (::std::nullopt); } } // namespace detail RewriteOpAdaptor::RewriteOpAdaptor(RewriteOp op) : RewriteOpGenericAdaptor(op->getOperands(), op) {} ::llvm::LogicalResult RewriteOpAdaptor::verify(::mlir::Location loc) { auto tblgen_name = getProperties().name; (void)tblgen_name; if (tblgen_name && !((::llvm::isa<::mlir::StringAttr>(tblgen_name)))) return emitError(loc, "'pdl.rewrite' op attribute 'name' failed to satisfy constraint: string attribute"); return ::mlir::success(); } std::pair RewriteOp::getODSOperandIndexAndLength(unsigned index) { ::llvm::ArrayRef sizeAttr = getProperties().operandSegmentSizes; unsigned start = 0; for (unsigned i = 0; i < index; ++i) start += sizeAttr[i]; return {start, sizeAttr[index]}; } ::mlir::MutableOperandRange RewriteOp::getRootMutable() { auto range = getODSOperandIndexAndLength(0); auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(0u, {getOperandSegmentSizesAttrName(), ::mlir::DenseI32ArrayAttr::get(getContext(), getProperties().operandSegmentSizes)})); return mutableRange; } ::mlir::MutableOperandRange RewriteOp::getExternalArgsMutable() { auto range = getODSOperandIndexAndLength(1); auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(1u, {getOperandSegmentSizesAttrName(), ::mlir::DenseI32ArrayAttr::get(getContext(), getProperties().operandSegmentSizes)})); return mutableRange; } ::llvm::LogicalResult RewriteOp::setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { ::mlir::DictionaryAttr dict = ::llvm::dyn_cast<::mlir::DictionaryAttr>(attr); if (!dict) { emitError() << "expected DictionaryAttr to set properties"; return ::mlir::failure(); } { auto &propStorage = prop.name; auto attr = dict.get("name"); if (attr) { auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `name` in property conversion: " << attr; return ::mlir::failure(); } } } { auto setFromAttr = [] (auto &propStorage, ::mlir::Attribute propAttr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) -> ::mlir::LogicalResult { return convertFromAttribute(propStorage, propAttr, emitError); }; auto attr = dict.get("operandSegmentSizes"); if (!attr) attr = dict.get("operand_segment_sizes");; ; if (attr && ::mlir::failed(setFromAttr(prop.operandSegmentSizes, attr, [&]() { return emitError() << "for `operandSegmentSizes`: "; }))) return ::mlir::failure(); } return ::mlir::success(); } ::mlir::Attribute RewriteOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) { ::mlir::SmallVector<::mlir::NamedAttribute> attrs; ::mlir::Builder odsBuilder{ctx}; { const auto &propStorage = prop.name; if (propStorage) attrs.push_back(odsBuilder.getNamedAttr("name", propStorage)); } { const auto &propStorage = prop.operandSegmentSizes; auto attr = [&]() -> ::mlir::Attribute { return ::mlir::DenseI32ArrayAttr::get(ctx, propStorage); }(); attrs.push_back(odsBuilder.getNamedAttr("operandSegmentSizes", attr)); } if (!attrs.empty()) return odsBuilder.getDictionaryAttr(attrs); return {}; } llvm::hash_code RewriteOp::computePropertiesHash(const Properties &prop) { auto hash_operandSegmentSizes_ = [] (const auto &propStorage) -> llvm::hash_code { using ::llvm::hash_value; return ::llvm::hash_combine_range(std::begin(propStorage), std::end(propStorage));; }; using llvm::hash_value; return llvm::hash_combine( llvm::hash_value(prop.name.getAsOpaquePointer()), hash_operandSegmentSizes_(prop.operandSegmentSizes)); } std::optional RewriteOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { if (name == "name") return prop.name; if (name == "operand_segment_sizes" || name == "operandSegmentSizes") return [&]() -> ::mlir::Attribute { return ::mlir::DenseI32ArrayAttr::get(ctx, prop.operandSegmentSizes); }(); return std::nullopt; } void RewriteOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { if (name == "name") { prop.name = ::llvm::dyn_cast_or_null>(value); return; } if (name == "operand_segment_sizes" || name == "operandSegmentSizes") { auto arrAttr = ::llvm::dyn_cast_or_null<::mlir::DenseI32ArrayAttr>(value); if (!arrAttr) return; if (arrAttr.size() != sizeof(prop.operandSegmentSizes) / sizeof(int32_t)) return; llvm::copy(arrAttr.asArrayRef(), prop.operandSegmentSizes.begin()); return; } } void RewriteOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { if (prop.name) attrs.append("name", prop.name); attrs.append("operandSegmentSizes", [&]() -> ::mlir::Attribute { return ::mlir::DenseI32ArrayAttr::get(ctx, prop.operandSegmentSizes); }()); } ::llvm::LogicalResult RewriteOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { { ::mlir::Attribute attr = attrs.get(getNameAttrName(opName)); if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_PDLOps1(attr, "name", emitError))) return ::mlir::failure(); } return ::mlir::success(); } ::llvm::LogicalResult RewriteOp::readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state) { auto &prop = state.getOrAddProperties(); (void)prop; if (::mlir::failed(reader.readOptionalAttribute(prop.name))) return ::mlir::failure(); if (reader.getBytecodeVersion() < /*kNativePropertiesODSSegmentSize=*/6) { auto &propStorage = prop.operandSegmentSizes; ::mlir::DenseI32ArrayAttr attr; if (::mlir::failed(reader.readAttribute(attr))) return ::mlir::failure(); if (attr.size() > static_cast(sizeof(propStorage) / sizeof(int32_t))) { reader.emitError("size mismatch for operand/result_segment_size"); return ::mlir::failure(); } ::llvm::copy(::llvm::ArrayRef(attr), propStorage.begin()); } { auto &propStorage = prop.operandSegmentSizes; auto readProp = [&]() { if (reader.getBytecodeVersion() >= /*kNativePropertiesODSSegmentSize=*/6) return reader.readSparseArray(::llvm::MutableArrayRef(propStorage)); ; return ::mlir::success(); }; if (::mlir::failed(readProp())) return ::mlir::failure(); } return ::mlir::success(); } void RewriteOp::writeProperties(::mlir::DialectBytecodeWriter &writer) { auto &prop = getProperties(); (void)prop; writer.writeOptionalAttribute(prop.name); if (writer.getBytecodeVersion() < /*kNativePropertiesODSSegmentSize=*/6) { auto &propStorage = prop.operandSegmentSizes; writer.writeAttribute(::mlir::DenseI32ArrayAttr::get(this->getContext(), propStorage)); } { auto &propStorage = prop.operandSegmentSizes; if (writer.getBytecodeVersion() >= /*kNativePropertiesODSSegmentSize=*/6) writer.writeSparseArray(::llvm::ArrayRef(propStorage)); ; } } ::std::optional< ::llvm::StringRef > RewriteOp::getName() { auto attr = getNameAttr(); return attr ? ::std::optional< ::llvm::StringRef >(attr.getValue()) : (::std::nullopt); } void RewriteOp::setName(::std::optional<::llvm::StringRef> attrValue) { auto &odsProp = getProperties().name; if (attrValue) odsProp = ::mlir::Builder((*this)->getContext()).getStringAttr(*attrValue); else odsProp = nullptr; } void RewriteOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, /*optional*/::mlir::Value root, /*optional*/::mlir::StringAttr name, ::mlir::ValueRange externalArgs) { if (root) odsState.addOperands(root); odsState.addOperands(externalArgs); ::llvm::copy(::llvm::ArrayRef({(root ? 1 : 0), static_cast(externalArgs.size())}), odsState.getOrAddProperties().operandSegmentSizes.begin()); if (name) { odsState.getOrAddProperties().name = name; } (void)odsState.addRegion(); } RewriteOp RewriteOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, /*optional*/::mlir::Value root, /*optional*/::mlir::StringAttr name, ::mlir::ValueRange externalArgs) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(root), std::forward(name), std::forward(externalArgs)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } RewriteOp RewriteOp::create(::mlir::ImplicitLocOpBuilder &builder, /*optional*/::mlir::Value root, /*optional*/::mlir::StringAttr name, ::mlir::ValueRange externalArgs) { return create(builder, builder.getLoc(), std::forward(root), std::forward(name), std::forward(externalArgs)); } void RewriteOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, /*optional*/::mlir::Value root, /*optional*/::mlir::StringAttr name, ::mlir::ValueRange externalArgs) { if (root) odsState.addOperands(root); odsState.addOperands(externalArgs); ::llvm::copy(::llvm::ArrayRef({(root ? 1 : 0), static_cast(externalArgs.size())}), odsState.getOrAddProperties().operandSegmentSizes.begin()); if (name) { odsState.getOrAddProperties().name = name; } (void)odsState.addRegion(); assert(resultTypes.size() == 0u && "mismatched number of results"); odsState.addTypes(resultTypes); } RewriteOp RewriteOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, /*optional*/::mlir::Value root, /*optional*/::mlir::StringAttr name, ::mlir::ValueRange externalArgs) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(root), std::forward(name), std::forward(externalArgs)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } RewriteOp RewriteOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, /*optional*/::mlir::Value root, /*optional*/::mlir::StringAttr name, ::mlir::ValueRange externalArgs) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(root), std::forward(name), std::forward(externalArgs)); } void RewriteOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { odsState.addOperands(operands); odsState.addAttributes(attributes); for (unsigned i = 0; i != 1; ++i) (void)odsState.addRegion(); assert(resultTypes.size() == 0u && "mismatched number of return types"); odsState.addTypes(resultTypes); if (!attributes.empty()) { (void)odsState.getOrAddProperties(); ::mlir::PropertyRef properties = odsState.getRawProperties(); std::optional<::mlir::RegisteredOperationName> info = odsState.name.getRegisteredInfo(); if (failed(info->setOpPropertiesFromAttribute(odsState.name, properties, odsState.attributes.getDictionary(odsState.getContext()), nullptr))) ::llvm::report_fatal_error("Property conversion failed."); } } RewriteOp RewriteOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(attributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } RewriteOp RewriteOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(attributes)); } void RewriteOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { odsState.addOperands(operands); odsState.useProperties(const_cast(properties)); odsState.addAttributes(discardableAttributes); for (unsigned i = 0; i != 1; ++i) (void)odsState.addRegion(); assert(resultTypes.size() == 0u && "mismatched number of return types"); odsState.addTypes(resultTypes); } RewriteOp RewriteOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } RewriteOp RewriteOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); } ::llvm::LogicalResult RewriteOp::verifyInvariantsImpl() { auto tblgen_name = getProperties().name; (void)tblgen_name; if (::mlir::failed(__mlir_ods_local_attr_constraint_PDLOps1(*this, tblgen_name, "name"))) return ::mlir::failure(); { unsigned index = 0; (void)index; auto valueGroup0 = getODSOperands(0); if (valueGroup0.size() > 1) { return emitOpError("operand group starting at #") << index << " requires 0 or 1 element, but found " << valueGroup0.size(); } for (auto v : valueGroup0) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps4(*this, v.getType(), "operand", index++))) return ::mlir::failure(); } auto valueGroup1 = getODSOperands(1); for (auto v : valueGroup1) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps1(*this, v.getType(), "operand", index++))) return ::mlir::failure(); } } { unsigned index = 0; (void)index; for (auto ®ion : ::llvm::MutableArrayRef((*this)->getRegion(0))) if (::mlir::failed(__mlir_ods_local_region_constraint_PDLOps2(*this, region, "bodyRegion", index++))) return ::mlir::failure(); } return ::mlir::success(); } ::llvm::LogicalResult RewriteOp::verifyInvariants() { return verifyInvariantsImpl(); } ::mlir::ParseResult RewriteOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> rootOperands; ::llvm::SMLoc rootOperandsLoc; (void)rootOperandsLoc; ::mlir::StringAttr nameAttr; ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> externalArgsOperands; ::llvm::SMLoc externalArgsOperandsLoc; (void)externalArgsOperandsLoc; ::llvm::SmallVector<::mlir::Type, 1> externalArgsTypes; std::unique_ptr<::mlir::Region> bodyRegionRegion = std::make_unique<::mlir::Region>(); { rootOperandsLoc = parser.getCurrentLocation(); ::mlir::OpAsmParser::UnresolvedOperand operand; ::mlir::OptionalParseResult parseResult = parser.parseOptionalOperand(operand); if (parseResult.has_value()) { if (failed(*parseResult)) return ::mlir::failure(); rootOperands.push_back(operand); } } if (!rootOperands.empty()) { } if (::mlir::succeeded(parser.parseOptionalKeyword("with"))) { if (parser.parseCustomAttributeWithFallback(nameAttr, parser.getBuilder().getType<::mlir::NoneType>())) { return ::mlir::failure(); } if (nameAttr) result.getOrAddProperties().name = nameAttr; if (::mlir::succeeded(parser.parseOptionalLParen())) { externalArgsOperandsLoc = parser.getCurrentLocation(); if (parser.parseOperandList(externalArgsOperands)) return ::mlir::failure(); if (parser.parseColon()) return ::mlir::failure(); if (parser.parseTypeList(externalArgsTypes)) return ::mlir::failure(); if (parser.parseRParen()) return ::mlir::failure(); } } { auto parseResult = parser.parseOptionalRegion(*bodyRegionRegion); if (parseResult.has_value() && failed(*parseResult)) return ::mlir::failure(); } if (!bodyRegionRegion->empty()) { if (bodyRegionRegion->empty()) bodyRegionRegion->emplaceBlock(); } { auto loc = parser.getCurrentLocation();(void)loc; if (parser.parseOptionalAttrDictWithKeyword(result.attributes)) return ::mlir::failure(); if (failed(verifyInherentAttrs(result.name, result.attributes, [&]() { return parser.emitError(loc) << "'" << result.name.getStringRef() << "' op "; }))) return ::mlir::failure(); } result.addRegion(std::move(bodyRegionRegion)); ::llvm::copy(::llvm::ArrayRef({static_cast(rootOperands.size()), static_cast(externalArgsOperands.size())}), result.getOrAddProperties().operandSegmentSizes.begin()); ::mlir::Type odsBuildableType0 = parser.getBuilder().getType<::mlir::pdl::OperationType>(); if (!rootOperands.empty()) { if (parser.resolveOperands(rootOperands, odsBuildableType0, rootOperandsLoc, result.operands)) return ::mlir::failure(); } if (parser.resolveOperands(externalArgsOperands, externalArgsTypes, externalArgsOperandsLoc, result.operands)) return ::mlir::failure(); return ::mlir::success(); } void RewriteOp::print(::mlir::OpAsmPrinter &_odsPrinter) { if (getRoot()) { _odsPrinter << ' '; if (::mlir::Value value = getRoot()) _odsPrinter << value; } if (getNameAttr()) { _odsPrinter << ' ' << "with"; _odsPrinter << ' '; _odsPrinter.printAttributeWithoutType(getNameAttr()); if (!getExternalArgs().empty()) { _odsPrinter << "("; _odsPrinter << getExternalArgs(); _odsPrinter << ' ' << ":"; _odsPrinter << ' '; _odsPrinter << getExternalArgs().getTypes(); _odsPrinter << ")"; } } if (!getBodyRegion().empty()) { _odsPrinter << ' '; _odsPrinter.printRegion(getBodyRegion()); } ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; elidedAttrs.push_back("operandSegmentSizes"); elidedAttrs.push_back("name"); _odsPrinter.printOptionalAttrDictWithKeyword((*this)->getAttrs(), elidedAttrs); } } // namespace mlir::pdl MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::pdl::RewriteOp) MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::pdl::detail::RewriteOpGenericAdaptorBase::Properties) namespace mlir::pdl { //===----------------------------------------------------------------------===// // ::mlir::pdl::TypeOp definitions //===----------------------------------------------------------------------===// namespace detail { TypeOpGenericAdaptorBase::TypeOpGenericAdaptorBase(TypeOp op) : odsAttrs(op->getRawDictionaryAttrs()), odsOpName(op->getName()), properties(op.getProperties()), odsRegions(op->getRegions()) {} ::std::optional<::mlir::Type> TypeOpGenericAdaptorBase::getConstantType() { auto attr = getConstantTypeAttr(); return attr ? ::std::optional<::mlir::Type>(::llvm::cast<::mlir::Type>(attr.getValue())) : (::std::nullopt); } } // namespace detail TypeOpAdaptor::TypeOpAdaptor(TypeOp op) : TypeOpGenericAdaptor(op->getOperands(), op) {} ::llvm::LogicalResult TypeOpAdaptor::verify(::mlir::Location loc) { auto tblgen_constantType = getProperties().constantType; (void)tblgen_constantType; if (tblgen_constantType && !(((::llvm::isa<::mlir::TypeAttr>(tblgen_constantType))) && ((::llvm::isa<::mlir::Type>(::llvm::cast<::mlir::TypeAttr>(tblgen_constantType).getValue()))) && ((true)))) return emitError(loc, "'pdl.type' op attribute 'constantType' failed to satisfy constraint: any type attribute"); return ::mlir::success(); } ::llvm::LogicalResult TypeOp::setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { ::mlir::DictionaryAttr dict = ::llvm::dyn_cast<::mlir::DictionaryAttr>(attr); if (!dict) { emitError() << "expected DictionaryAttr to set properties"; return ::mlir::failure(); } { auto &propStorage = prop.constantType; auto attr = dict.get("constantType"); if (attr) { auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `constantType` in property conversion: " << attr; return ::mlir::failure(); } } } return ::mlir::success(); } ::mlir::Attribute TypeOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) { ::mlir::SmallVector<::mlir::NamedAttribute> attrs; ::mlir::Builder odsBuilder{ctx}; { const auto &propStorage = prop.constantType; if (propStorage) attrs.push_back(odsBuilder.getNamedAttr("constantType", propStorage)); } if (!attrs.empty()) return odsBuilder.getDictionaryAttr(attrs); return {}; } llvm::hash_code TypeOp::computePropertiesHash(const Properties &prop) { using llvm::hash_value; return llvm::hash_combine( llvm::hash_value(prop.constantType.getAsOpaquePointer())); } std::optional TypeOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { if (name == "constantType") return prop.constantType; return std::nullopt; } void TypeOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { if (name == "constantType") { prop.constantType = ::llvm::dyn_cast_or_null>(value); return; } } void TypeOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { if (prop.constantType) attrs.append("constantType", prop.constantType); } ::llvm::LogicalResult TypeOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { { ::mlir::Attribute attr = attrs.get(getConstantTypeAttrName(opName)); if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_PDLOps7(attr, "constantType", emitError))) return ::mlir::failure(); } return ::mlir::success(); } ::llvm::LogicalResult TypeOp::readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state) { auto &prop = state.getOrAddProperties(); (void)prop; if (::mlir::failed(reader.readOptionalAttribute(prop.constantType))) return ::mlir::failure(); return ::mlir::success(); } void TypeOp::writeProperties(::mlir::DialectBytecodeWriter &writer) { auto &prop = getProperties(); (void)prop; writer.writeOptionalAttribute(prop.constantType); } ::std::optional<::mlir::Type> TypeOp::getConstantType() { auto attr = getConstantTypeAttr(); return attr ? ::std::optional<::mlir::Type>(::llvm::cast<::mlir::Type>(attr.getValue())) : (::std::nullopt); } void TypeOp::setConstantType(::std::optional<::mlir::Type> attrValue) { auto &odsProp = getProperties().constantType; if (attrValue) odsProp = ::mlir::TypeAttr::get(*attrValue); else odsProp = nullptr; } void TypeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type result, /*optional*/::mlir::TypeAttr constantType) { if (constantType) { odsState.getOrAddProperties().constantType = constantType; } odsState.addTypes(result); } TypeOp TypeOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Type result, /*optional*/::mlir::TypeAttr constantType) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(result), std::forward(constantType)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } TypeOp TypeOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Type result, /*optional*/::mlir::TypeAttr constantType) { return create(builder, builder.getLoc(), std::forward(result), std::forward(constantType)); } void TypeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, /*optional*/::mlir::TypeAttr constantType) { if (constantType) { odsState.getOrAddProperties().constantType = constantType; } assert(resultTypes.size() == 1u && "mismatched number of results"); odsState.addTypes(resultTypes); } TypeOp TypeOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, /*optional*/::mlir::TypeAttr constantType) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(constantType)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } TypeOp TypeOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, /*optional*/::mlir::TypeAttr constantType) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(constantType)); } void TypeOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { assert(operands.size() == 0u && "mismatched number of parameters"); odsState.addOperands(operands); odsState.addAttributes(attributes); assert(resultTypes.size() == 1u && "mismatched number of return types"); odsState.addTypes(resultTypes); if (!attributes.empty()) { (void)odsState.getOrAddProperties(); ::mlir::PropertyRef properties = odsState.getRawProperties(); std::optional<::mlir::RegisteredOperationName> info = odsState.name.getRegisteredInfo(); if (failed(info->setOpPropertiesFromAttribute(odsState.name, properties, odsState.attributes.getDictionary(odsState.getContext()), nullptr))) ::llvm::report_fatal_error("Property conversion failed."); } } TypeOp TypeOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(attributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } TypeOp TypeOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(attributes)); } void TypeOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { assert(operands.size() == 0u && "mismatched number of parameters"); odsState.addOperands(operands); odsState.useProperties(const_cast(properties)); odsState.addAttributes(discardableAttributes); assert(resultTypes.size() == 1u && "mismatched number of return types"); odsState.addTypes(resultTypes); } TypeOp TypeOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } TypeOp TypeOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); } ::llvm::LogicalResult TypeOp::verifyInvariantsImpl() { auto tblgen_constantType = getProperties().constantType; (void)tblgen_constantType; if (::mlir::failed(__mlir_ods_local_attr_constraint_PDLOps7(*this, tblgen_constantType, "constantType"))) return ::mlir::failure(); { unsigned index = 0; (void)index; auto valueGroup0 = getODSResults(0); for (auto v : valueGroup0) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps2(*this, v.getType(), "result", index++))) return ::mlir::failure(); } } return ::mlir::success(); } ::llvm::LogicalResult TypeOp::verifyInvariants() { if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) return ::mlir::success(); return ::mlir::failure(); } ::mlir::ParseResult TypeOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { ::mlir::TypeAttr constantTypeAttr; { auto loc = parser.getCurrentLocation();(void)loc; if (parser.parseOptionalAttrDict(result.attributes)) return ::mlir::failure(); if (failed(verifyInherentAttrs(result.name, result.attributes, [&]() { return parser.emitError(loc) << "'" << result.name.getStringRef() << "' op "; }))) return ::mlir::failure(); } if (::mlir::succeeded(parser.parseOptionalColon())) { if (parser.parseCustomAttributeWithFallback(constantTypeAttr, parser.getBuilder().getType<::mlir::NoneType>())) { return ::mlir::failure(); } if (constantTypeAttr) result.getOrAddProperties().constantType = constantTypeAttr; } ::mlir::Type odsBuildableType0 = parser.getBuilder().getType<::mlir::pdl::TypeType>(); result.addTypes(odsBuildableType0); return ::mlir::success(); } void TypeOp::print(::mlir::OpAsmPrinter &_odsPrinter) { ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; elidedAttrs.push_back("constantType"); _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); if (getConstantTypeAttr()) { _odsPrinter << ' ' << ":"; _odsPrinter << ' '; _odsPrinter.printAttributeWithoutType(getConstantTypeAttr()); } } } // namespace mlir::pdl MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::pdl::TypeOp) MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::pdl::detail::TypeOpGenericAdaptorBase::Properties) namespace mlir::pdl { //===----------------------------------------------------------------------===// // ::mlir::pdl::TypesOp definitions //===----------------------------------------------------------------------===// namespace detail { TypesOpGenericAdaptorBase::TypesOpGenericAdaptorBase(TypesOp op) : odsAttrs(op->getRawDictionaryAttrs()), odsOpName(op->getName()), properties(op.getProperties()), odsRegions(op->getRegions()) {} ::std::optional< ::mlir::ArrayAttr > TypesOpGenericAdaptorBase::getConstantTypes() { auto attr = getConstantTypesAttr(); return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); } } // namespace detail TypesOpAdaptor::TypesOpAdaptor(TypesOp op) : TypesOpGenericAdaptor(op->getOperands(), op) {} ::llvm::LogicalResult TypesOpAdaptor::verify(::mlir::Location loc) { auto tblgen_constantTypes = getProperties().constantTypes; (void)tblgen_constantTypes; if (tblgen_constantTypes && !(((::llvm::isa<::mlir::ArrayAttr>(tblgen_constantTypes))) && (::llvm::all_of(::llvm::cast<::mlir::ArrayAttr>(tblgen_constantTypes), [&](::mlir::Attribute attr) { return attr && (((::llvm::isa<::mlir::TypeAttr>(attr))) && ((::llvm::isa<::mlir::Type>(::llvm::cast<::mlir::TypeAttr>(attr).getValue()))) && ((true))); })))) return emitError(loc, "'pdl.types' op attribute 'constantTypes' failed to satisfy constraint: type array attribute"); return ::mlir::success(); } ::llvm::LogicalResult TypesOp::setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { ::mlir::DictionaryAttr dict = ::llvm::dyn_cast<::mlir::DictionaryAttr>(attr); if (!dict) { emitError() << "expected DictionaryAttr to set properties"; return ::mlir::failure(); } { auto &propStorage = prop.constantTypes; auto attr = dict.get("constantTypes"); if (attr) { auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `constantTypes` in property conversion: " << attr; return ::mlir::failure(); } } } return ::mlir::success(); } ::mlir::Attribute TypesOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) { ::mlir::SmallVector<::mlir::NamedAttribute> attrs; ::mlir::Builder odsBuilder{ctx}; { const auto &propStorage = prop.constantTypes; if (propStorage) attrs.push_back(odsBuilder.getNamedAttr("constantTypes", propStorage)); } if (!attrs.empty()) return odsBuilder.getDictionaryAttr(attrs); return {}; } llvm::hash_code TypesOp::computePropertiesHash(const Properties &prop) { using llvm::hash_value; return llvm::hash_combine( llvm::hash_value(prop.constantTypes.getAsOpaquePointer())); } std::optional TypesOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { if (name == "constantTypes") return prop.constantTypes; return std::nullopt; } void TypesOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { if (name == "constantTypes") { prop.constantTypes = ::llvm::dyn_cast_or_null>(value); return; } } void TypesOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { if (prop.constantTypes) attrs.append("constantTypes", prop.constantTypes); } ::llvm::LogicalResult TypesOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { { ::mlir::Attribute attr = attrs.get(getConstantTypesAttrName(opName)); if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_PDLOps8(attr, "constantTypes", emitError))) return ::mlir::failure(); } return ::mlir::success(); } ::llvm::LogicalResult TypesOp::readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state) { auto &prop = state.getOrAddProperties(); (void)prop; if (::mlir::failed(reader.readOptionalAttribute(prop.constantTypes))) return ::mlir::failure(); return ::mlir::success(); } void TypesOp::writeProperties(::mlir::DialectBytecodeWriter &writer) { auto &prop = getProperties(); (void)prop; writer.writeOptionalAttribute(prop.constantTypes); } ::std::optional< ::mlir::ArrayAttr > TypesOp::getConstantTypes() { auto attr = getConstantTypesAttr(); return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); } void TypesOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type result, /*optional*/::mlir::ArrayAttr constantTypes) { if (constantTypes) { odsState.getOrAddProperties().constantTypes = constantTypes; } odsState.addTypes(result); } TypesOp TypesOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Type result, /*optional*/::mlir::ArrayAttr constantTypes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(result), std::forward(constantTypes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } TypesOp TypesOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Type result, /*optional*/::mlir::ArrayAttr constantTypes) { return create(builder, builder.getLoc(), std::forward(result), std::forward(constantTypes)); } void TypesOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, /*optional*/::mlir::ArrayAttr constantTypes) { if (constantTypes) { odsState.getOrAddProperties().constantTypes = constantTypes; } assert(resultTypes.size() == 1u && "mismatched number of results"); odsState.addTypes(resultTypes); } TypesOp TypesOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, /*optional*/::mlir::ArrayAttr constantTypes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(constantTypes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } TypesOp TypesOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, /*optional*/::mlir::ArrayAttr constantTypes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(constantTypes)); } void TypesOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { assert(operands.size() == 0u && "mismatched number of parameters"); odsState.addOperands(operands); odsState.addAttributes(attributes); assert(resultTypes.size() == 1u && "mismatched number of return types"); odsState.addTypes(resultTypes); if (!attributes.empty()) { (void)odsState.getOrAddProperties(); ::mlir::PropertyRef properties = odsState.getRawProperties(); std::optional<::mlir::RegisteredOperationName> info = odsState.name.getRegisteredInfo(); if (failed(info->setOpPropertiesFromAttribute(odsState.name, properties, odsState.attributes.getDictionary(odsState.getContext()), nullptr))) ::llvm::report_fatal_error("Property conversion failed."); } } TypesOp TypesOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(attributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } TypesOp TypesOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(attributes)); } void TypesOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { assert(operands.size() == 0u && "mismatched number of parameters"); odsState.addOperands(operands); odsState.useProperties(const_cast(properties)); odsState.addAttributes(discardableAttributes); assert(resultTypes.size() == 1u && "mismatched number of return types"); odsState.addTypes(resultTypes); } TypesOp TypesOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } TypesOp TypesOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(operands), std::forward(properties), std::forward(discardableAttributes)); } ::llvm::LogicalResult TypesOp::verifyInvariantsImpl() { auto tblgen_constantTypes = getProperties().constantTypes; (void)tblgen_constantTypes; if (::mlir::failed(__mlir_ods_local_attr_constraint_PDLOps8(*this, tblgen_constantTypes, "constantTypes"))) return ::mlir::failure(); { unsigned index = 0; (void)index; auto valueGroup0 = getODSResults(0); for (auto v : valueGroup0) { if (::mlir::failed(__mlir_ods_local_type_constraint_PDLOps6(*this, v.getType(), "result", index++))) return ::mlir::failure(); } } return ::mlir::success(); } ::llvm::LogicalResult TypesOp::verifyInvariants() { if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) return ::mlir::success(); return ::mlir::failure(); } ::mlir::ParseResult TypesOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { ::mlir::ArrayAttr constantTypesAttr; { auto loc = parser.getCurrentLocation();(void)loc; if (parser.parseOptionalAttrDict(result.attributes)) return ::mlir::failure(); if (failed(verifyInherentAttrs(result.name, result.attributes, [&]() { return parser.emitError(loc) << "'" << result.name.getStringRef() << "' op "; }))) return ::mlir::failure(); } if (::mlir::succeeded(parser.parseOptionalColon())) { if (parser.parseCustomAttributeWithFallback(constantTypesAttr, parser.getBuilder().getType<::mlir::NoneType>())) { return ::mlir::failure(); } if (constantTypesAttr) result.getOrAddProperties().constantTypes = constantTypesAttr; } ::mlir::Type odsBuildableType0 = ::mlir::pdl::RangeType::get(parser.getBuilder().getType<::mlir::pdl::TypeType>()); result.addTypes(odsBuildableType0); return ::mlir::success(); } void TypesOp::print(::mlir::OpAsmPrinter &_odsPrinter) { ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; elidedAttrs.push_back("constantTypes"); _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); if (getConstantTypesAttr()) { _odsPrinter << ' ' << ":"; _odsPrinter << ' '; _odsPrinter.printAttributeWithoutType(getConstantTypesAttr()); } } } // namespace mlir::pdl MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::pdl::TypesOp) MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::pdl::detail::TypesOpGenericAdaptorBase::Properties) #endif // GET_OP_CLASSES