/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ |* *| |* Op Definitions *| |* *| |* Automatically generated file, do not edit! *| |* From: FuncOps.td *| |* *| \*===----------------------------------------------------------------------===*/ #ifdef GET_OP_LIST #undef GET_OP_LIST ::mlir::func::CallIndirectOp, ::mlir::func::CallOp, ::mlir::func::ConstantOp, ::mlir::func::FuncOp, ::mlir::func::ReturnOp #endif // GET_OP_LIST #ifdef GET_OP_CLASSES #undef GET_OP_CLASSES //===----------------------------------------------------------------------===// // Local Utility Method Definitions //===----------------------------------------------------------------------===// static ::llvm::LogicalResult __mlir_ods_local_type_constraint_FuncOps1( ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, unsigned valueIndex) { if (!((::llvm::isa<::mlir::FunctionType>(type)))) { return op->emitOpError(valueKind) << " #" << valueIndex << " must be function type, but got " << type; } return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_type_constraint_FuncOps2( ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, unsigned valueIndex) { if (!(!((::llvm::isa<::mlir::TokenType>(type))))) { return op->emitOpError(valueKind) << " #" << valueIndex << " must be variadic of any non-token type, but got " << type; } return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_type_constraint_FuncOps3( ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, unsigned valueIndex) { if (!(!((::llvm::isa<::mlir::TokenType>(type))))) { return op->emitOpError(valueKind) << " #" << valueIndex << " must be any non-token type, but got " << type; } return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_FuncOps1( ::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::DictionaryAttr>(attr))); })))) return emitError() << "attribute '" << attrName << "' failed to satisfy constraint: Array of dictionary attributes"; return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_FuncOps1( ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { return __mlir_ods_local_attr_constraint_FuncOps1(attr, attrName, [op]() { return op->emitOpError(); }); } static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_FuncOps2( ::mlir::Attribute attr, ::llvm::StringRef attrName, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { if (attr && !((::llvm::isa<::mlir::FlatSymbolRefAttr>(attr)))) return emitError() << "attribute '" << attrName << "' failed to satisfy constraint: flat symbol reference attribute"; return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_FuncOps2( ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { return __mlir_ods_local_attr_constraint_FuncOps2(attr, attrName, [op]() { return op->emitOpError(); }); } static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_FuncOps3( ::mlir::Attribute attr, ::llvm::StringRef attrName, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { if (attr && !((::llvm::isa<::mlir::UnitAttr>(attr)))) return emitError() << "attribute '" << attrName << "' failed to satisfy constraint: unit attribute"; return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_FuncOps3( ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { return __mlir_ods_local_attr_constraint_FuncOps3(attr, attrName, [op]() { return op->emitOpError(); }); } static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_FuncOps4( ::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_FuncOps4( ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { return __mlir_ods_local_attr_constraint_FuncOps4(attr, attrName, [op]() { return op->emitOpError(); }); } static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_FuncOps5( ::mlir::Attribute attr, ::llvm::StringRef attrName, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { if (attr && !(((::llvm::isa<::mlir::TypeAttr>(attr))) && ((::llvm::isa<::mlir::FunctionType>(::llvm::cast<::mlir::TypeAttr>(attr).getValue()))) && ((::llvm::isa<::mlir::FunctionType>(::llvm::cast<::mlir::TypeAttr>(attr).getValue()))))) return emitError() << "attribute '" << attrName << "' failed to satisfy constraint: type attribute of function type"; return ::mlir::success(); } static ::llvm::LogicalResult __mlir_ods_local_attr_constraint_FuncOps5( ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { return __mlir_ods_local_attr_constraint_FuncOps5(attr, attrName, [op]() { return op->emitOpError(); }); } static ::llvm::LogicalResult __mlir_ods_local_region_constraint_FuncOps1( ::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::func { //===----------------------------------------------------------------------===// // ::mlir::func::CallIndirectOp definitions //===----------------------------------------------------------------------===// namespace detail { CallIndirectOpGenericAdaptorBase::CallIndirectOpGenericAdaptorBase(CallIndirectOp op) : odsAttrs(op->getRawDictionaryAttrs()), odsOpName(op->getName()), properties(op.getProperties()), odsRegions(op->getRegions()) {} std::pair CallIndirectOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { bool isVariadic[] = {false, 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 - 1) / 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::ArrayAttr > CallIndirectOpGenericAdaptorBase::getArgAttrs() { auto attr = getArgAttrsAttr(); return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); } ::std::optional< ::mlir::ArrayAttr > CallIndirectOpGenericAdaptorBase::getResAttrs() { auto attr = getResAttrsAttr(); return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); } } // namespace detail CallIndirectOpAdaptor::CallIndirectOpAdaptor(CallIndirectOp op) : CallIndirectOpGenericAdaptor(op->getOperands(), op) {} ::llvm::LogicalResult CallIndirectOpAdaptor::verify(::mlir::Location loc) { auto tblgen_arg_attrs = getProperties().arg_attrs; (void)tblgen_arg_attrs; auto tblgen_res_attrs = getProperties().res_attrs; (void)tblgen_res_attrs; if (tblgen_arg_attrs && !(((::llvm::isa<::mlir::ArrayAttr>(tblgen_arg_attrs))) && (::llvm::all_of(::llvm::cast<::mlir::ArrayAttr>(tblgen_arg_attrs), [&](::mlir::Attribute attr) { return attr && ((::llvm::isa<::mlir::DictionaryAttr>(attr))); })))) return emitError(loc, "'func.call_indirect' op attribute 'arg_attrs' failed to satisfy constraint: Array of dictionary attributes"); if (tblgen_res_attrs && !(((::llvm::isa<::mlir::ArrayAttr>(tblgen_res_attrs))) && (::llvm::all_of(::llvm::cast<::mlir::ArrayAttr>(tblgen_res_attrs), [&](::mlir::Attribute attr) { return attr && ((::llvm::isa<::mlir::DictionaryAttr>(attr))); })))) return emitError(loc, "'func.call_indirect' op attribute 'res_attrs' failed to satisfy constraint: Array of dictionary attributes"); return ::mlir::success(); } std::pair CallIndirectOp::getODSOperandIndexAndLength(unsigned index) { bool isVariadic[] = {false, 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() - 1) / 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 CallIndirectOp::getCalleeOperandsMutable() { auto range = getODSOperandIndexAndLength(1); auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); return mutableRange; } std::pair CallIndirectOp::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 CallIndirectOp::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.arg_attrs; auto attr = dict.get("arg_attrs"); if (attr) { auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `arg_attrs` in property conversion: " << attr; return ::mlir::failure(); } } } { auto &propStorage = prop.res_attrs; auto attr = dict.get("res_attrs"); if (attr) { auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `res_attrs` in property conversion: " << attr; return ::mlir::failure(); } } } return ::mlir::success(); } ::mlir::Attribute CallIndirectOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) { ::mlir::SmallVector<::mlir::NamedAttribute> attrs; ::mlir::Builder odsBuilder{ctx}; { const auto &propStorage = prop.arg_attrs; if (propStorage) attrs.push_back(odsBuilder.getNamedAttr("arg_attrs", propStorage)); } { const auto &propStorage = prop.res_attrs; if (propStorage) attrs.push_back(odsBuilder.getNamedAttr("res_attrs", propStorage)); } if (!attrs.empty()) return odsBuilder.getDictionaryAttr(attrs); return {}; } llvm::hash_code CallIndirectOp::computePropertiesHash(const Properties &prop) { using llvm::hash_value; return llvm::hash_combine( llvm::hash_value(prop.arg_attrs.getAsOpaquePointer()), llvm::hash_value(prop.res_attrs.getAsOpaquePointer())); } std::optional CallIndirectOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { if (name == "arg_attrs") return prop.arg_attrs; if (name == "res_attrs") return prop.res_attrs; return std::nullopt; } void CallIndirectOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { if (name == "arg_attrs") { prop.arg_attrs = ::llvm::dyn_cast_or_null>(value); return; } if (name == "res_attrs") { prop.res_attrs = ::llvm::dyn_cast_or_null>(value); return; } } void CallIndirectOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { if (prop.arg_attrs) attrs.append("arg_attrs", prop.arg_attrs); if (prop.res_attrs) attrs.append("res_attrs", prop.res_attrs); } ::llvm::LogicalResult CallIndirectOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { { ::mlir::Attribute attr = attrs.get(getArgAttrsAttrName(opName)); if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_FuncOps1(attr, "arg_attrs", emitError))) return ::mlir::failure(); } { ::mlir::Attribute attr = attrs.get(getResAttrsAttrName(opName)); if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_FuncOps1(attr, "res_attrs", emitError))) return ::mlir::failure(); } return ::mlir::success(); } ::llvm::LogicalResult CallIndirectOp::readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state) { auto &prop = state.getOrAddProperties(); (void)prop; if (::mlir::failed(reader.readOptionalAttribute(prop.arg_attrs))) return ::mlir::failure(); if (::mlir::failed(reader.readOptionalAttribute(prop.res_attrs))) return ::mlir::failure(); return ::mlir::success(); } void CallIndirectOp::writeProperties(::mlir::DialectBytecodeWriter &writer) { auto &prop = getProperties(); (void)prop; writer.writeOptionalAttribute(prop.arg_attrs); writer.writeOptionalAttribute(prop.res_attrs); } ::std::optional< ::mlir::ArrayAttr > CallIndirectOp::getArgAttrs() { auto attr = getArgAttrsAttr(); return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); } ::std::optional< ::mlir::ArrayAttr > CallIndirectOp::getResAttrs() { auto attr = getResAttrsAttr(); return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); } void CallIndirectOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, Value callee, ValueRange operands) { odsState.operands.push_back(callee); odsState.addOperands(operands); odsState.addTypes(::llvm::cast(callee.getType()).getResults()); } CallIndirectOp CallIndirectOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, Value callee, ValueRange operands) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(callee), std::forward(operands)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } CallIndirectOp CallIndirectOp::create(::mlir::ImplicitLocOpBuilder &builder, Value callee, ValueRange operands) { return create(builder, builder.getLoc(), std::forward(callee), std::forward(operands)); } void CallIndirectOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange results, ::mlir::Value callee, ::mlir::ValueRange callee_operands, /*optional*/::mlir::ArrayAttr arg_attrs, /*optional*/::mlir::ArrayAttr res_attrs) { odsState.addOperands(callee); odsState.addOperands(callee_operands); if (arg_attrs) { odsState.getOrAddProperties().arg_attrs = arg_attrs; } if (res_attrs) { odsState.getOrAddProperties().res_attrs = res_attrs; } odsState.addTypes(results); } CallIndirectOp CallIndirectOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange results, ::mlir::Value callee, ::mlir::ValueRange callee_operands, /*optional*/::mlir::ArrayAttr arg_attrs, /*optional*/::mlir::ArrayAttr res_attrs) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(results), std::forward(callee), std::forward(callee_operands), std::forward(arg_attrs), std::forward(res_attrs)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } CallIndirectOp CallIndirectOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange results, ::mlir::Value callee, ::mlir::ValueRange callee_operands, /*optional*/::mlir::ArrayAttr arg_attrs, /*optional*/::mlir::ArrayAttr res_attrs) { return create(builder, builder.getLoc(), std::forward(results), std::forward(callee), std::forward(callee_operands), std::forward(arg_attrs), std::forward(res_attrs)); } void CallIndirectOp::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); 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."); } } CallIndirectOp CallIndirectOp::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__; } CallIndirectOp CallIndirectOp::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 CallIndirectOp::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); odsState.addTypes(resultTypes); } CallIndirectOp CallIndirectOp::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__; } CallIndirectOp CallIndirectOp::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 CallIndirectOp::verifyInvariantsImpl() { auto tblgen_arg_attrs = getProperties().arg_attrs; (void)tblgen_arg_attrs; auto tblgen_res_attrs = getProperties().res_attrs; (void)tblgen_res_attrs; if (::mlir::failed(__mlir_ods_local_attr_constraint_FuncOps1(*this, tblgen_arg_attrs, "arg_attrs"))) return ::mlir::failure(); if (::mlir::failed(__mlir_ods_local_attr_constraint_FuncOps1(*this, tblgen_res_attrs, "res_attrs"))) return ::mlir::failure(); { unsigned index = 0; (void)index; auto valueGroup0 = getODSOperands(0); for (auto v : valueGroup0) { if (::mlir::failed(__mlir_ods_local_type_constraint_FuncOps1(*this, v.getType(), "operand", index++))) return ::mlir::failure(); } auto valueGroup1 = getODSOperands(1); for (auto v : valueGroup1) { if (::mlir::failed(__mlir_ods_local_type_constraint_FuncOps2(*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_FuncOps2(*this, v.getType(), "result", index++))) return ::mlir::failure(); } } if (!((std::equal_to<>()(::llvm::cast((*this->getODSOperands(0).begin()).getType()).getInputs(), this->getODSOperands(1).getType())))) return emitOpError("failed to verify that callee input types match argument types"); if (!((std::equal_to<>()(::llvm::cast((*this->getODSOperands(0).begin()).getType()).getResults(), this->getODSResults(0).getType())))) return emitOpError("failed to verify that callee result types match result types"); return ::mlir::success(); } ::llvm::LogicalResult CallIndirectOp::verifyInvariants() { return verifyInvariantsImpl(); } void CallIndirectOp::getCanonicalizationPatterns(::mlir::RewritePatternSet &results, ::mlir::MLIRContext *context) { results.add(canonicalize); } ::mlir::ParseResult CallIndirectOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { ::mlir::OpAsmParser::UnresolvedOperand calleeRawOperand{}; ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> calleeOperands(&calleeRawOperand, 1); ::llvm::SMLoc calleeOperandsLoc; (void)calleeOperandsLoc; ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> callee_operandsOperands; ::llvm::SMLoc callee_operandsOperandsLoc; (void)callee_operandsOperandsLoc; ::mlir::Type calleeRawType{}; ::llvm::ArrayRef<::mlir::Type> calleeTypes(&calleeRawType, 1); calleeOperandsLoc = parser.getCurrentLocation(); if (parser.parseOperand(calleeRawOperand)) return ::mlir::failure(); if (parser.parseLParen()) return ::mlir::failure(); callee_operandsOperandsLoc = parser.getCurrentLocation(); if (parser.parseOperandList(callee_operandsOperands)) 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(); } if (parser.parseColon()) return ::mlir::failure(); { ::mlir::FunctionType type; if (parser.parseCustomTypeWithFallback(type)) return ::mlir::failure(); calleeRawType = type; } for (::mlir::Type type : calleeTypes) { (void)type; if (!((::llvm::isa<::mlir::FunctionType>(type)))) { return parser.emitError(parser.getNameLoc()) << "'callee' must be function type, but got " << type; } } result.addTypes(::llvm::cast(calleeTypes[0]).getResults()); if (parser.resolveOperands(calleeOperands, calleeTypes, calleeOperandsLoc, result.operands)) return ::mlir::failure(); if (parser.resolveOperands(callee_operandsOperands, ::llvm::cast(calleeTypes[0]).getInputs(), callee_operandsOperandsLoc, result.operands)) return ::mlir::failure(); return ::mlir::success(); } void CallIndirectOp::print(::mlir::OpAsmPrinter &_odsPrinter) { _odsPrinter << ' '; _odsPrinter << getCallee(); _odsPrinter << "("; _odsPrinter << getCalleeOperands(); _odsPrinter << ")"; ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); _odsPrinter << ' ' << ":"; _odsPrinter << ' '; { auto type = getCallee().getType(); if (auto validType = ::llvm::dyn_cast<::mlir::FunctionType>(type)) _odsPrinter.printStrippedAttrOrType(validType); else _odsPrinter << type; } } } // namespace mlir::func MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::func::CallIndirectOp) MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::func::detail::CallIndirectOpGenericAdaptorBase::Properties) namespace mlir::func { //===----------------------------------------------------------------------===// // ::mlir::func::CallOp definitions //===----------------------------------------------------------------------===// namespace detail { CallOpGenericAdaptorBase::CallOpGenericAdaptorBase(CallOp op) : odsAttrs(op->getRawDictionaryAttrs()), odsOpName(op->getName()), properties(op.getProperties()), odsRegions(op->getRegions()) {} std::pair CallOpGenericAdaptorBase::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 CallOpGenericAdaptorBase::getCallee() { auto attr = getCalleeAttr(); return attr.getValue(); } ::std::optional< ::mlir::ArrayAttr > CallOpGenericAdaptorBase::getArgAttrs() { auto attr = getArgAttrsAttr(); return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); } ::std::optional< ::mlir::ArrayAttr > CallOpGenericAdaptorBase::getResAttrs() { auto attr = getResAttrsAttr(); return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); } ::mlir::UnitAttr CallOpGenericAdaptorBase::getNoInlineAttr() { auto attr = ::llvm::dyn_cast_or_null<::mlir::UnitAttr>(getProperties().no_inline); if (!attr) attr = ((false) ? ::mlir::Builder(odsAttrs.getContext()).getUnitAttr() : nullptr); return attr; } bool CallOpGenericAdaptorBase::getNoInline() { auto attr = getNoInlineAttr(); if (!attr) return ((false) ? ::mlir::Builder(odsAttrs.getContext()).getUnitAttr() : nullptr) != nullptr; return attr != nullptr; } } // namespace detail CallOpAdaptor::CallOpAdaptor(CallOp op) : CallOpGenericAdaptor(op->getOperands(), op) {} ::llvm::LogicalResult CallOpAdaptor::verify(::mlir::Location loc) { auto tblgen_arg_attrs = getProperties().arg_attrs; (void)tblgen_arg_attrs; auto tblgen_callee = getProperties().callee; (void)tblgen_callee; if (!tblgen_callee) return emitError(loc, "'func.call' op requires attribute 'callee'"); auto tblgen_no_inline = getProperties().no_inline; (void)tblgen_no_inline; auto tblgen_res_attrs = getProperties().res_attrs; (void)tblgen_res_attrs; if (tblgen_callee && !((::llvm::isa<::mlir::FlatSymbolRefAttr>(tblgen_callee)))) return emitError(loc, "'func.call' op attribute 'callee' failed to satisfy constraint: flat symbol reference attribute"); if (tblgen_arg_attrs && !(((::llvm::isa<::mlir::ArrayAttr>(tblgen_arg_attrs))) && (::llvm::all_of(::llvm::cast<::mlir::ArrayAttr>(tblgen_arg_attrs), [&](::mlir::Attribute attr) { return attr && ((::llvm::isa<::mlir::DictionaryAttr>(attr))); })))) return emitError(loc, "'func.call' op attribute 'arg_attrs' failed to satisfy constraint: Array of dictionary attributes"); if (tblgen_res_attrs && !(((::llvm::isa<::mlir::ArrayAttr>(tblgen_res_attrs))) && (::llvm::all_of(::llvm::cast<::mlir::ArrayAttr>(tblgen_res_attrs), [&](::mlir::Attribute attr) { return attr && ((::llvm::isa<::mlir::DictionaryAttr>(attr))); })))) return emitError(loc, "'func.call' op attribute 'res_attrs' failed to satisfy constraint: Array of dictionary attributes"); if (tblgen_no_inline && !((::llvm::isa<::mlir::UnitAttr>(tblgen_no_inline)))) return emitError(loc, "'func.call' op attribute 'no_inline' failed to satisfy constraint: unit attribute"); return ::mlir::success(); } std::pair CallOp::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 CallOp::getOperandsMutable() { auto range = getODSOperandIndexAndLength(0); auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); return mutableRange; } std::pair CallOp::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 CallOp::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.arg_attrs; auto attr = dict.get("arg_attrs"); if (attr) { auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `arg_attrs` in property conversion: " << attr; return ::mlir::failure(); } } } { auto &propStorage = prop.callee; auto attr = dict.get("callee"); if (attr) { auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `callee` in property conversion: " << attr; return ::mlir::failure(); } } } { auto &propStorage = prop.no_inline; auto attr = dict.get("no_inline"); if (attr) { auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `no_inline` in property conversion: " << attr; return ::mlir::failure(); } } } { auto &propStorage = prop.res_attrs; auto attr = dict.get("res_attrs"); if (attr) { auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `res_attrs` in property conversion: " << attr; return ::mlir::failure(); } } } return ::mlir::success(); } ::mlir::Attribute CallOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) { ::mlir::SmallVector<::mlir::NamedAttribute> attrs; ::mlir::Builder odsBuilder{ctx}; { const auto &propStorage = prop.arg_attrs; if (propStorage) attrs.push_back(odsBuilder.getNamedAttr("arg_attrs", propStorage)); } { const auto &propStorage = prop.callee; if (propStorage) attrs.push_back(odsBuilder.getNamedAttr("callee", propStorage)); } { const auto &propStorage = prop.no_inline; if (propStorage) attrs.push_back(odsBuilder.getNamedAttr("no_inline", propStorage)); } { const auto &propStorage = prop.res_attrs; if (propStorage) attrs.push_back(odsBuilder.getNamedAttr("res_attrs", propStorage)); } if (!attrs.empty()) return odsBuilder.getDictionaryAttr(attrs); return {}; } llvm::hash_code CallOp::computePropertiesHash(const Properties &prop) { using llvm::hash_value; return llvm::hash_combine( llvm::hash_value(prop.arg_attrs.getAsOpaquePointer()), llvm::hash_value(prop.callee.getAsOpaquePointer()), llvm::hash_value(prop.no_inline.getAsOpaquePointer()), llvm::hash_value(prop.res_attrs.getAsOpaquePointer())); } std::optional CallOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { if (name == "arg_attrs") return prop.arg_attrs; if (name == "callee") return prop.callee; if (name == "no_inline") return prop.no_inline; if (name == "res_attrs") return prop.res_attrs; return std::nullopt; } void CallOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { if (name == "arg_attrs") { prop.arg_attrs = ::llvm::dyn_cast_or_null>(value); return; } if (name == "callee") { prop.callee = ::llvm::dyn_cast_or_null>(value); return; } if (name == "no_inline") { prop.no_inline = ::llvm::dyn_cast_or_null>(value); return; } if (name == "res_attrs") { prop.res_attrs = ::llvm::dyn_cast_or_null>(value); return; } } void CallOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { if (prop.arg_attrs) attrs.append("arg_attrs", prop.arg_attrs); if (prop.callee) attrs.append("callee", prop.callee); if (prop.no_inline) attrs.append("no_inline", prop.no_inline); if (prop.res_attrs) attrs.append("res_attrs", prop.res_attrs); } ::llvm::LogicalResult CallOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { { ::mlir::Attribute attr = attrs.get(getArgAttrsAttrName(opName)); if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_FuncOps1(attr, "arg_attrs", emitError))) return ::mlir::failure(); } { ::mlir::Attribute attr = attrs.get(getCalleeAttrName(opName)); if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_FuncOps2(attr, "callee", emitError))) return ::mlir::failure(); } { ::mlir::Attribute attr = attrs.get(getNoInlineAttrName(opName)); if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_FuncOps3(attr, "no_inline", emitError))) return ::mlir::failure(); } { ::mlir::Attribute attr = attrs.get(getResAttrsAttrName(opName)); if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_FuncOps1(attr, "res_attrs", emitError))) return ::mlir::failure(); } return ::mlir::success(); } ::llvm::LogicalResult CallOp::readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state) { auto &prop = state.getOrAddProperties(); (void)prop; if (::mlir::failed(reader.readOptionalAttribute(prop.arg_attrs))) return ::mlir::failure(); if (::mlir::failed(reader.readAttribute(prop.callee))) return ::mlir::failure(); if (::mlir::failed(reader.readOptionalAttribute(prop.no_inline))) return ::mlir::failure(); if (::mlir::failed(reader.readOptionalAttribute(prop.res_attrs))) return ::mlir::failure(); return ::mlir::success(); } void CallOp::writeProperties(::mlir::DialectBytecodeWriter &writer) { auto &prop = getProperties(); (void)prop; writer.writeOptionalAttribute(prop.arg_attrs); writer.writeAttribute(prop.callee); writer.writeOptionalAttribute(prop.no_inline); writer.writeOptionalAttribute(prop.res_attrs); } ::llvm::StringRef CallOp::getCallee() { auto attr = getCalleeAttr(); return attr.getValue(); } ::std::optional< ::mlir::ArrayAttr > CallOp::getArgAttrs() { auto attr = getArgAttrsAttr(); return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); } ::std::optional< ::mlir::ArrayAttr > CallOp::getResAttrs() { auto attr = getResAttrsAttr(); return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); } bool CallOp::getNoInline() { auto attr = getNoInlineAttr(); if (!attr) return ((false) ? ::mlir::Builder((*this)->getContext()).getUnitAttr() : nullptr) != nullptr; return attr != nullptr; } void CallOp::setCallee(::llvm::StringRef attrValue) { getProperties().callee = ::mlir::SymbolRefAttr::get(::mlir::Builder((*this)->getContext()).getContext(), attrValue); } void CallOp::setNoInline(bool attrValue) { auto &odsProp = getProperties().no_inline; if (attrValue) odsProp = ((attrValue) ? ::mlir::Builder((*this)->getContext()).getUnitAttr() : nullptr); else odsProp = nullptr; } void CallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, FuncOp callee, ValueRange operands) { odsState.addOperands(operands); odsState.addAttribute("callee", SymbolRefAttr::get(callee)); odsState.addTypes(callee.getFunctionType().getResults()); } CallOp CallOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, FuncOp callee, ValueRange operands) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(callee), std::forward(operands)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } CallOp CallOp::create(::mlir::ImplicitLocOpBuilder &builder, FuncOp callee, ValueRange operands) { return create(builder, builder.getLoc(), std::forward(callee), std::forward(operands)); } void CallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, SymbolRefAttr callee, TypeRange results, ValueRange operands) { odsState.addOperands(operands); odsState.addAttribute("callee", callee); odsState.addTypes(results); } CallOp CallOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, SymbolRefAttr callee, TypeRange results, ValueRange operands) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(callee), std::forward(results), std::forward(operands)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } CallOp CallOp::create(::mlir::ImplicitLocOpBuilder &builder, SymbolRefAttr callee, TypeRange results, ValueRange operands) { return create(builder, builder.getLoc(), std::forward(callee), std::forward(results), std::forward(operands)); } void CallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, StringAttr callee, TypeRange results, ValueRange operands) { build(odsBuilder, odsState, SymbolRefAttr::get(callee), results, operands); } CallOp CallOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, StringAttr callee, TypeRange results, ValueRange operands) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(callee), std::forward(results), std::forward(operands)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } CallOp CallOp::create(::mlir::ImplicitLocOpBuilder &builder, StringAttr callee, TypeRange results, ValueRange operands) { return create(builder, builder.getLoc(), std::forward(callee), std::forward(results), std::forward(operands)); } void CallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, StringRef callee, TypeRange results, ValueRange operands) { build(odsBuilder, odsState, StringAttr::get(odsBuilder.getContext(), callee), results, operands); } CallOp CallOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, StringRef callee, TypeRange results, ValueRange operands) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(callee), std::forward(results), std::forward(operands)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } CallOp CallOp::create(::mlir::ImplicitLocOpBuilder &builder, StringRef callee, TypeRange results, ValueRange operands) { return create(builder, builder.getLoc(), std::forward(callee), std::forward(results), std::forward(operands)); } void CallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, TypeRange results, FlatSymbolRefAttr callee, ValueRange operands) { build(odsBuilder, odsState, callee, results, operands); } CallOp CallOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, TypeRange results, FlatSymbolRefAttr callee, ValueRange operands) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(results), std::forward(callee), std::forward(operands)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } CallOp CallOp::create(::mlir::ImplicitLocOpBuilder &builder, TypeRange results, FlatSymbolRefAttr callee, ValueRange operands) { return create(builder, builder.getLoc(), std::forward(results), std::forward(callee), std::forward(operands)); } void CallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, TypeRange results, StringAttr callee, ValueRange operands) { build(odsBuilder, odsState, callee, results, operands); } CallOp CallOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, TypeRange results, StringAttr callee, ValueRange operands) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(results), std::forward(callee), std::forward(operands)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } CallOp CallOp::create(::mlir::ImplicitLocOpBuilder &builder, TypeRange results, StringAttr callee, ValueRange operands) { return create(builder, builder.getLoc(), std::forward(results), std::forward(callee), std::forward(operands)); } void CallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, TypeRange results, StringRef callee, ValueRange operands) { build(odsBuilder, odsState, callee, results, operands); } CallOp CallOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, TypeRange results, StringRef callee, ValueRange operands) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(results), std::forward(callee), std::forward(operands)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } CallOp CallOp::create(::mlir::ImplicitLocOpBuilder &builder, TypeRange results, StringRef callee, ValueRange operands) { return create(builder, builder.getLoc(), std::forward(results), std::forward(callee), std::forward(operands)); } void CallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultType0, ::mlir::FlatSymbolRefAttr callee, ::mlir::ValueRange operands, /*optional*/::mlir::ArrayAttr arg_attrs, /*optional*/::mlir::ArrayAttr res_attrs, /*optional*/::mlir::UnitAttr no_inline) { odsState.addOperands(operands); odsState.getOrAddProperties().callee = callee; if (arg_attrs) { odsState.getOrAddProperties().arg_attrs = arg_attrs; } if (res_attrs) { odsState.getOrAddProperties().res_attrs = res_attrs; } if (no_inline) { odsState.getOrAddProperties().no_inline = no_inline; } odsState.addTypes(resultType0); } CallOp CallOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultType0, ::mlir::FlatSymbolRefAttr callee, ::mlir::ValueRange operands, /*optional*/::mlir::ArrayAttr arg_attrs, /*optional*/::mlir::ArrayAttr res_attrs, /*optional*/::mlir::UnitAttr no_inline) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultType0), std::forward(callee), std::forward(operands), std::forward(arg_attrs), std::forward(res_attrs), std::forward(no_inline)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } CallOp CallOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultType0, ::mlir::FlatSymbolRefAttr callee, ::mlir::ValueRange operands, /*optional*/::mlir::ArrayAttr arg_attrs, /*optional*/::mlir::ArrayAttr res_attrs, /*optional*/::mlir::UnitAttr no_inline) { return create(builder, builder.getLoc(), std::forward(resultType0), std::forward(callee), std::forward(operands), std::forward(arg_attrs), std::forward(res_attrs), std::forward(no_inline)); } void CallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultType0, ::llvm::StringRef callee, ::mlir::ValueRange operands, /*optional*/::mlir::ArrayAttr arg_attrs, /*optional*/::mlir::ArrayAttr res_attrs, /*optional*/bool no_inline) { odsState.addOperands(operands); odsState.getOrAddProperties().callee = ::mlir::SymbolRefAttr::get(odsBuilder.getContext(), callee); if (arg_attrs) { odsState.getOrAddProperties().arg_attrs = arg_attrs; } if (res_attrs) { odsState.getOrAddProperties().res_attrs = res_attrs; } if (no_inline) { odsState.getOrAddProperties().no_inline = ((no_inline) ? odsBuilder.getUnitAttr() : nullptr); } odsState.addTypes(resultType0); } CallOp CallOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultType0, ::llvm::StringRef callee, ::mlir::ValueRange operands, /*optional*/::mlir::ArrayAttr arg_attrs, /*optional*/::mlir::ArrayAttr res_attrs, /*optional*/bool no_inline) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultType0), std::forward(callee), std::forward(operands), std::forward(arg_attrs), std::forward(res_attrs), std::forward(no_inline)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } CallOp CallOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultType0, ::llvm::StringRef callee, ::mlir::ValueRange operands, /*optional*/::mlir::ArrayAttr arg_attrs, /*optional*/::mlir::ArrayAttr res_attrs, /*optional*/bool no_inline) { return create(builder, builder.getLoc(), std::forward(resultType0), std::forward(callee), std::forward(operands), std::forward(arg_attrs), std::forward(res_attrs), std::forward(no_inline)); } void CallOp::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."); } } CallOp CallOp::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__; } CallOp CallOp::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 CallOp::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); } CallOp CallOp::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__; } CallOp CallOp::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 CallOp::verifyInvariantsImpl() { auto tblgen_arg_attrs = getProperties().arg_attrs; (void)tblgen_arg_attrs; auto tblgen_callee = getProperties().callee; (void)tblgen_callee; if (!tblgen_callee) return emitOpError("requires attribute 'callee'"); auto tblgen_no_inline = getProperties().no_inline; (void)tblgen_no_inline; auto tblgen_res_attrs = getProperties().res_attrs; (void)tblgen_res_attrs; if (::mlir::failed(__mlir_ods_local_attr_constraint_FuncOps2(*this, tblgen_callee, "callee"))) return ::mlir::failure(); if (::mlir::failed(__mlir_ods_local_attr_constraint_FuncOps1(*this, tblgen_arg_attrs, "arg_attrs"))) return ::mlir::failure(); if (::mlir::failed(__mlir_ods_local_attr_constraint_FuncOps1(*this, tblgen_res_attrs, "res_attrs"))) return ::mlir::failure(); if (::mlir::failed(__mlir_ods_local_attr_constraint_FuncOps3(*this, tblgen_no_inline, "no_inline"))) return ::mlir::failure(); { unsigned index = 0; (void)index; auto valueGroup0 = getODSOperands(0); for (auto v : valueGroup0) { if (::mlir::failed(__mlir_ods_local_type_constraint_FuncOps2(*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_FuncOps2(*this, v.getType(), "result", index++))) return ::mlir::failure(); } } return ::mlir::success(); } ::llvm::LogicalResult CallOp::verifyInvariants() { return verifyInvariantsImpl(); } ::mlir::ParseResult CallOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { ::mlir::FlatSymbolRefAttr calleeAttr; ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> operandsOperands; ::llvm::SMLoc operandsOperandsLoc; (void)operandsOperandsLoc; ::llvm::ArrayRef<::mlir::Type> operandsTypes; ::llvm::ArrayRef<::mlir::Type> allResultTypes; if (parser.parseCustomAttributeWithFallback(calleeAttr, parser.getBuilder().getType<::mlir::NoneType>())) { return ::mlir::failure(); } if (calleeAttr) result.getOrAddProperties().callee = calleeAttr; if (parser.parseLParen()) return ::mlir::failure(); operandsOperandsLoc = parser.getCurrentLocation(); if (parser.parseOperandList(operandsOperands)) 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(); } if (parser.parseColon()) return ::mlir::failure(); ::mlir::FunctionType operands__allResult_functionType; if (parser.parseType(operands__allResult_functionType)) return ::mlir::failure(); operandsTypes = operands__allResult_functionType.getInputs(); allResultTypes = operands__allResult_functionType.getResults(); result.addTypes(allResultTypes); if (parser.resolveOperands(operandsOperands, operandsTypes, operandsOperandsLoc, result.operands)) return ::mlir::failure(); return ::mlir::success(); } void CallOp::print(::mlir::OpAsmPrinter &_odsPrinter) { _odsPrinter << ' '; _odsPrinter.printAttributeWithoutType(getCalleeAttr()); _odsPrinter << "("; _odsPrinter << getOperands(); _odsPrinter << ")"; ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; elidedAttrs.push_back("callee"); { ::mlir::Builder odsBuilder(getContext()); ::mlir::Attribute attr = getNoInlineAttr(); if(attr && (attr == ((false) ? odsBuilder.getUnitAttr() : nullptr))) elidedAttrs.push_back("no_inline"); } _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); _odsPrinter << ' ' << ":"; _odsPrinter << ' '; _odsPrinter.printFunctionalType(getOperands().getTypes(), getOperation()->getResultTypes()); } } // namespace mlir::func MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::func::CallOp) MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::func::detail::CallOpGenericAdaptorBase::Properties) namespace mlir::func { //===----------------------------------------------------------------------===// // ::mlir::func::ConstantOp definitions //===----------------------------------------------------------------------===// namespace detail { ConstantOpGenericAdaptorBase::ConstantOpGenericAdaptorBase(ConstantOp op) : odsAttrs(op->getRawDictionaryAttrs()), odsOpName(op->getName()), properties(op.getProperties()), odsRegions(op->getRegions()) {} ::llvm::StringRef ConstantOpGenericAdaptorBase::getValue() { auto attr = getValueAttr(); return attr.getValue(); } } // namespace detail ConstantOpAdaptor::ConstantOpAdaptor(ConstantOp op) : ConstantOpGenericAdaptor(op->getOperands(), op) {} ::llvm::LogicalResult ConstantOpAdaptor::verify(::mlir::Location loc) { auto tblgen_value = getProperties().value; (void)tblgen_value; if (!tblgen_value) return emitError(loc, "'func.constant' op requires attribute 'value'"); if (tblgen_value && !((::llvm::isa<::mlir::FlatSymbolRefAttr>(tblgen_value)))) return emitError(loc, "'func.constant' op attribute 'value' failed to satisfy constraint: flat symbol reference attribute"); return ::mlir::success(); } ::llvm::LogicalResult ConstantOp::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 ConstantOp::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 ConstantOp::computePropertiesHash(const Properties &prop) { using llvm::hash_value; return llvm::hash_combine( llvm::hash_value(prop.value.getAsOpaquePointer())); } std::optional ConstantOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { if (name == "value") return prop.value; return std::nullopt; } void ConstantOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { if (name == "value") { prop.value = ::llvm::dyn_cast_or_null>(value); return; } } void ConstantOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { if (prop.value) attrs.append("value", prop.value); } ::llvm::LogicalResult ConstantOp::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_FuncOps2(attr, "value", emitError))) return ::mlir::failure(); } return ::mlir::success(); } ::llvm::LogicalResult ConstantOp::readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state) { auto &prop = state.getOrAddProperties(); (void)prop; if (::mlir::failed(reader.readAttribute(prop.value))) return ::mlir::failure(); return ::mlir::success(); } void ConstantOp::writeProperties(::mlir::DialectBytecodeWriter &writer) { auto &prop = getProperties(); (void)prop; writer.writeAttribute(prop.value); } ::llvm::StringRef ConstantOp::getValue() { auto attr = getValueAttr(); return attr.getValue(); } void ConstantOp::setValue(::llvm::StringRef attrValue) { getProperties().value = ::mlir::SymbolRefAttr::get(::mlir::Builder((*this)->getContext()).getContext(), attrValue); } void ConstantOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::FlatSymbolRefAttr value) { odsState.getOrAddProperties().value = value; odsState.addTypes(resultType0); } ConstantOp ConstantOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Type resultType0, ::mlir::FlatSymbolRefAttr value) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultType0), std::forward(value)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } ConstantOp ConstantOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Type resultType0, ::mlir::FlatSymbolRefAttr value) { return create(builder, builder.getLoc(), std::forward(resultType0), std::forward(value)); } void ConstantOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::FlatSymbolRefAttr value) { odsState.getOrAddProperties().value = value; assert(resultTypes.size() == 1u && "mismatched number of results"); odsState.addTypes(resultTypes); } ConstantOp ConstantOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::FlatSymbolRefAttr value) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(value)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } ConstantOp ConstantOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::FlatSymbolRefAttr value) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(value)); } void ConstantOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::llvm::StringRef value) { odsState.getOrAddProperties().value = ::mlir::SymbolRefAttr::get(odsBuilder.getContext(), value); odsState.addTypes(resultType0); } ConstantOp ConstantOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Type resultType0, ::llvm::StringRef value) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultType0), std::forward(value)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } ConstantOp ConstantOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Type resultType0, ::llvm::StringRef value) { return create(builder, builder.getLoc(), std::forward(resultType0), std::forward(value)); } void ConstantOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::llvm::StringRef value) { odsState.getOrAddProperties().value = ::mlir::SymbolRefAttr::get(odsBuilder.getContext(), value); assert(resultTypes.size() == 1u && "mismatched number of results"); odsState.addTypes(resultTypes); } ConstantOp ConstantOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::llvm::StringRef value) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(value)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } ConstantOp ConstantOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::llvm::StringRef value) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(value)); } void ConstantOp::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."); } } ConstantOp ConstantOp::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__; } ConstantOp ConstantOp::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 ConstantOp::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); } ConstantOp ConstantOp::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__; } ConstantOp ConstantOp::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 ConstantOp::verifyInvariantsImpl() { auto tblgen_value = getProperties().value; (void)tblgen_value; if (!tblgen_value) return emitOpError("requires attribute 'value'"); if (::mlir::failed(__mlir_ods_local_attr_constraint_FuncOps2(*this, tblgen_value, "value"))) return ::mlir::failure(); { unsigned index = 0; (void)index; auto valueGroup0 = getODSResults(0); for (auto v : valueGroup0) { if (::mlir::failed(__mlir_ods_local_type_constraint_FuncOps3(*this, v.getType(), "result", index++))) return ::mlir::failure(); } } return ::mlir::success(); } ::llvm::LogicalResult ConstantOp::verifyInvariants() { return verifyInvariantsImpl(); } ::mlir::ParseResult ConstantOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { ::mlir::FlatSymbolRefAttr valueAttr; ::llvm::SmallVector<::mlir::Type, 1> allResultTypes; { 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 (parser.parseCustomAttributeWithFallback(valueAttr, parser.getBuilder().getType<::mlir::NoneType>())) { return ::mlir::failure(); } if (valueAttr) result.getOrAddProperties().value = valueAttr; if (parser.parseColon()) return ::mlir::failure(); if (parser.parseTypeList(allResultTypes)) return ::mlir::failure(); result.addTypes(allResultTypes); return ::mlir::success(); } void ConstantOp::print(::mlir::OpAsmPrinter &_odsPrinter) { ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; elidedAttrs.push_back("value"); _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); _odsPrinter << ' '; _odsPrinter.printAttributeWithoutType(getValueAttr()); _odsPrinter << ' ' << ":"; _odsPrinter << ' '; _odsPrinter << getOperation()->getResultTypes(); } void ConstantOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { } } // namespace mlir::func MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::func::ConstantOp) MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::func::detail::ConstantOpGenericAdaptorBase::Properties) namespace mlir::func { //===----------------------------------------------------------------------===// // ::mlir::func::FuncOp definitions //===----------------------------------------------------------------------===// namespace detail { FuncOpGenericAdaptorBase::FuncOpGenericAdaptorBase(FuncOp op) : odsAttrs(op->getRawDictionaryAttrs()), odsOpName(op->getName()), properties(op.getProperties()), odsRegions(op->getRegions()) {} ::llvm::StringRef FuncOpGenericAdaptorBase::getSymName() { auto attr = getSymNameAttr(); return attr.getValue(); } ::mlir::FunctionType FuncOpGenericAdaptorBase::getFunctionType() { auto attr = getFunctionTypeAttr(); return ::llvm::cast<::mlir::FunctionType>(attr.getValue()); } ::std::optional< ::llvm::StringRef > FuncOpGenericAdaptorBase::getSymVisibility() { auto attr = getSymVisibilityAttr(); return attr ? ::std::optional< ::llvm::StringRef >(attr.getValue()) : (::std::nullopt); } ::std::optional< ::mlir::ArrayAttr > FuncOpGenericAdaptorBase::getArgAttrs() { auto attr = getArgAttrsAttr(); return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); } ::std::optional< ::mlir::ArrayAttr > FuncOpGenericAdaptorBase::getResAttrs() { auto attr = getResAttrsAttr(); return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); } ::mlir::UnitAttr FuncOpGenericAdaptorBase::getNoInlineAttr() { auto attr = ::llvm::dyn_cast_or_null<::mlir::UnitAttr>(getProperties().no_inline); if (!attr) attr = ((false) ? ::mlir::Builder(odsAttrs.getContext()).getUnitAttr() : nullptr); return attr; } bool FuncOpGenericAdaptorBase::getNoInline() { auto attr = getNoInlineAttr(); if (!attr) return ((false) ? ::mlir::Builder(odsAttrs.getContext()).getUnitAttr() : nullptr) != nullptr; return attr != nullptr; } } // namespace detail FuncOpAdaptor::FuncOpAdaptor(FuncOp op) : FuncOpGenericAdaptor(op->getOperands(), op) {} ::llvm::LogicalResult FuncOpAdaptor::verify(::mlir::Location loc) { auto tblgen_arg_attrs = getProperties().arg_attrs; (void)tblgen_arg_attrs; auto tblgen_function_type = getProperties().function_type; (void)tblgen_function_type; if (!tblgen_function_type) return emitError(loc, "'func.func' op requires attribute 'function_type'"); auto tblgen_no_inline = getProperties().no_inline; (void)tblgen_no_inline; auto tblgen_res_attrs = getProperties().res_attrs; (void)tblgen_res_attrs; auto tblgen_sym_name = getProperties().sym_name; (void)tblgen_sym_name; if (!tblgen_sym_name) return emitError(loc, "'func.func' op requires attribute 'sym_name'"); auto tblgen_sym_visibility = getProperties().sym_visibility; (void)tblgen_sym_visibility; if (tblgen_sym_name && !((::llvm::isa<::mlir::StringAttr>(tblgen_sym_name)))) return emitError(loc, "'func.func' op attribute 'sym_name' failed to satisfy constraint: string attribute"); if (tblgen_function_type && !(((::llvm::isa<::mlir::TypeAttr>(tblgen_function_type))) && ((::llvm::isa<::mlir::FunctionType>(::llvm::cast<::mlir::TypeAttr>(tblgen_function_type).getValue()))) && ((::llvm::isa<::mlir::FunctionType>(::llvm::cast<::mlir::TypeAttr>(tblgen_function_type).getValue()))))) return emitError(loc, "'func.func' op attribute 'function_type' failed to satisfy constraint: type attribute of function type"); if (tblgen_sym_visibility && !((::llvm::isa<::mlir::StringAttr>(tblgen_sym_visibility)))) return emitError(loc, "'func.func' op attribute 'sym_visibility' failed to satisfy constraint: string attribute"); if (tblgen_arg_attrs && !(((::llvm::isa<::mlir::ArrayAttr>(tblgen_arg_attrs))) && (::llvm::all_of(::llvm::cast<::mlir::ArrayAttr>(tblgen_arg_attrs), [&](::mlir::Attribute attr) { return attr && ((::llvm::isa<::mlir::DictionaryAttr>(attr))); })))) return emitError(loc, "'func.func' op attribute 'arg_attrs' failed to satisfy constraint: Array of dictionary attributes"); if (tblgen_res_attrs && !(((::llvm::isa<::mlir::ArrayAttr>(tblgen_res_attrs))) && (::llvm::all_of(::llvm::cast<::mlir::ArrayAttr>(tblgen_res_attrs), [&](::mlir::Attribute attr) { return attr && ((::llvm::isa<::mlir::DictionaryAttr>(attr))); })))) return emitError(loc, "'func.func' op attribute 'res_attrs' failed to satisfy constraint: Array of dictionary attributes"); if (tblgen_no_inline && !((::llvm::isa<::mlir::UnitAttr>(tblgen_no_inline)))) return emitError(loc, "'func.func' op attribute 'no_inline' failed to satisfy constraint: unit attribute"); return ::mlir::success(); } ::llvm::LogicalResult FuncOp::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.arg_attrs; auto attr = dict.get("arg_attrs"); if (attr) { auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `arg_attrs` in property conversion: " << attr; return ::mlir::failure(); } } } { auto &propStorage = prop.function_type; auto attr = dict.get("function_type"); if (attr) { auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `function_type` in property conversion: " << attr; return ::mlir::failure(); } } } { auto &propStorage = prop.no_inline; auto attr = dict.get("no_inline"); if (attr) { auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `no_inline` in property conversion: " << attr; return ::mlir::failure(); } } } { auto &propStorage = prop.res_attrs; auto attr = dict.get("res_attrs"); if (attr) { auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `res_attrs` 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(); } } } { auto &propStorage = prop.sym_visibility; auto attr = dict.get("sym_visibility"); if (attr) { auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `sym_visibility` in property conversion: " << attr; return ::mlir::failure(); } } } return ::mlir::success(); } ::mlir::Attribute FuncOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) { ::mlir::SmallVector<::mlir::NamedAttribute> attrs; ::mlir::Builder odsBuilder{ctx}; { const auto &propStorage = prop.arg_attrs; if (propStorage) attrs.push_back(odsBuilder.getNamedAttr("arg_attrs", propStorage)); } { const auto &propStorage = prop.function_type; if (propStorage) attrs.push_back(odsBuilder.getNamedAttr("function_type", propStorage)); } { const auto &propStorage = prop.no_inline; if (propStorage) attrs.push_back(odsBuilder.getNamedAttr("no_inline", propStorage)); } { const auto &propStorage = prop.res_attrs; if (propStorage) attrs.push_back(odsBuilder.getNamedAttr("res_attrs", propStorage)); } { const auto &propStorage = prop.sym_name; if (propStorage) attrs.push_back(odsBuilder.getNamedAttr("sym_name", propStorage)); } { const auto &propStorage = prop.sym_visibility; if (propStorage) attrs.push_back(odsBuilder.getNamedAttr("sym_visibility", propStorage)); } if (!attrs.empty()) return odsBuilder.getDictionaryAttr(attrs); return {}; } llvm::hash_code FuncOp::computePropertiesHash(const Properties &prop) { using llvm::hash_value; return llvm::hash_combine( llvm::hash_value(prop.arg_attrs.getAsOpaquePointer()), llvm::hash_value(prop.function_type.getAsOpaquePointer()), llvm::hash_value(prop.no_inline.getAsOpaquePointer()), llvm::hash_value(prop.res_attrs.getAsOpaquePointer()), llvm::hash_value(prop.sym_name.getAsOpaquePointer()), llvm::hash_value(prop.sym_visibility.getAsOpaquePointer())); } std::optional FuncOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { if (name == "arg_attrs") return prop.arg_attrs; if (name == "function_type") return prop.function_type; if (name == "no_inline") return prop.no_inline; if (name == "res_attrs") return prop.res_attrs; if (name == "sym_name") return prop.sym_name; if (name == "sym_visibility") return prop.sym_visibility; return std::nullopt; } void FuncOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { if (name == "arg_attrs") { prop.arg_attrs = ::llvm::dyn_cast_or_null>(value); return; } if (name == "function_type") { prop.function_type = ::llvm::dyn_cast_or_null>(value); return; } if (name == "no_inline") { prop.no_inline = ::llvm::dyn_cast_or_null>(value); return; } if (name == "res_attrs") { prop.res_attrs = ::llvm::dyn_cast_or_null>(value); return; } if (name == "sym_name") { prop.sym_name = ::llvm::dyn_cast_or_null>(value); return; } if (name == "sym_visibility") { prop.sym_visibility = ::llvm::dyn_cast_or_null>(value); return; } } void FuncOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { if (prop.arg_attrs) attrs.append("arg_attrs", prop.arg_attrs); if (prop.function_type) attrs.append("function_type", prop.function_type); if (prop.no_inline) attrs.append("no_inline", prop.no_inline); if (prop.res_attrs) attrs.append("res_attrs", prop.res_attrs); if (prop.sym_name) attrs.append("sym_name", prop.sym_name); if (prop.sym_visibility) attrs.append("sym_visibility", prop.sym_visibility); } ::llvm::LogicalResult FuncOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { { ::mlir::Attribute attr = attrs.get(getArgAttrsAttrName(opName)); if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_FuncOps1(attr, "arg_attrs", emitError))) return ::mlir::failure(); } { ::mlir::Attribute attr = attrs.get(getFunctionTypeAttrName(opName)); if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_FuncOps5(attr, "function_type", emitError))) return ::mlir::failure(); } { ::mlir::Attribute attr = attrs.get(getNoInlineAttrName(opName)); if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_FuncOps3(attr, "no_inline", emitError))) return ::mlir::failure(); } { ::mlir::Attribute attr = attrs.get(getResAttrsAttrName(opName)); if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_FuncOps1(attr, "res_attrs", emitError))) return ::mlir::failure(); } { ::mlir::Attribute attr = attrs.get(getSymNameAttrName(opName)); if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_FuncOps4(attr, "sym_name", emitError))) return ::mlir::failure(); } { ::mlir::Attribute attr = attrs.get(getSymVisibilityAttrName(opName)); if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_FuncOps4(attr, "sym_visibility", emitError))) return ::mlir::failure(); } return ::mlir::success(); } ::llvm::LogicalResult FuncOp::readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state) { auto &prop = state.getOrAddProperties(); (void)prop; if (::mlir::failed(reader.readOptionalAttribute(prop.arg_attrs))) return ::mlir::failure(); if (::mlir::failed(reader.readAttribute(prop.function_type))) return ::mlir::failure(); if (::mlir::failed(reader.readOptionalAttribute(prop.no_inline))) return ::mlir::failure(); if (::mlir::failed(reader.readOptionalAttribute(prop.res_attrs))) return ::mlir::failure(); if (::mlir::failed(reader.readAttribute(prop.sym_name))) return ::mlir::failure(); if (::mlir::failed(reader.readOptionalAttribute(prop.sym_visibility))) return ::mlir::failure(); return ::mlir::success(); } void FuncOp::writeProperties(::mlir::DialectBytecodeWriter &writer) { auto &prop = getProperties(); (void)prop; writer.writeOptionalAttribute(prop.arg_attrs); writer.writeAttribute(prop.function_type); writer.writeOptionalAttribute(prop.no_inline); writer.writeOptionalAttribute(prop.res_attrs); writer.writeAttribute(prop.sym_name); writer.writeOptionalAttribute(prop.sym_visibility); } ::llvm::StringRef FuncOp::getSymName() { auto attr = getSymNameAttr(); return attr.getValue(); } ::mlir::FunctionType FuncOp::getFunctionType() { auto attr = getFunctionTypeAttr(); return ::llvm::cast<::mlir::FunctionType>(attr.getValue()); } ::std::optional< ::llvm::StringRef > FuncOp::getSymVisibility() { auto attr = getSymVisibilityAttr(); return attr ? ::std::optional< ::llvm::StringRef >(attr.getValue()) : (::std::nullopt); } ::std::optional< ::mlir::ArrayAttr > FuncOp::getArgAttrs() { auto attr = getArgAttrsAttr(); return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); } ::std::optional< ::mlir::ArrayAttr > FuncOp::getResAttrs() { auto attr = getResAttrsAttr(); return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); } bool FuncOp::getNoInline() { auto attr = getNoInlineAttr(); if (!attr) return ((false) ? ::mlir::Builder((*this)->getContext()).getUnitAttr() : nullptr) != nullptr; return attr != nullptr; } void FuncOp::setSymName(::llvm::StringRef attrValue) { getProperties().sym_name = ::mlir::Builder((*this)->getContext()).getStringAttr(attrValue); } void FuncOp::setFunctionType(::mlir::FunctionType attrValue) { getProperties().function_type = ::mlir::TypeAttr::get(attrValue); } void FuncOp::setSymVisibility(::std::optional<::llvm::StringRef> attrValue) { auto &odsProp = getProperties().sym_visibility; if (attrValue) odsProp = ::mlir::Builder((*this)->getContext()).getStringAttr(*attrValue); else odsProp = nullptr; } void FuncOp::setNoInline(bool attrValue) { auto &odsProp = getProperties().no_inline; if (attrValue) odsProp = ((attrValue) ? ::mlir::Builder((*this)->getContext()).getUnitAttr() : nullptr); else odsProp = nullptr; } FuncOp FuncOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, StringRef name, FunctionType type, ArrayRef attrs, ArrayRef argAttrs) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(name), std::forward(type), std::forward(attrs), std::forward(argAttrs)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } FuncOp FuncOp::create(::mlir::ImplicitLocOpBuilder &builder, StringRef name, FunctionType type, ArrayRef attrs, ArrayRef argAttrs) { return create(builder, builder.getLoc(), std::forward(name), std::forward(type), std::forward(attrs), std::forward(argAttrs)); } void FuncOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::StringAttr sym_name, ::mlir::TypeAttr function_type, /*optional*/::mlir::StringAttr sym_visibility, /*optional*/::mlir::ArrayAttr arg_attrs, /*optional*/::mlir::ArrayAttr res_attrs, /*optional*/::mlir::UnitAttr no_inline) { odsState.getOrAddProperties().sym_name = sym_name; odsState.getOrAddProperties().function_type = function_type; if (sym_visibility) { odsState.getOrAddProperties().sym_visibility = sym_visibility; } if (arg_attrs) { odsState.getOrAddProperties().arg_attrs = arg_attrs; } if (res_attrs) { odsState.getOrAddProperties().res_attrs = res_attrs; } if (no_inline) { odsState.getOrAddProperties().no_inline = no_inline; } (void)odsState.addRegion(); } FuncOp FuncOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::StringAttr sym_name, ::mlir::TypeAttr function_type, /*optional*/::mlir::StringAttr sym_visibility, /*optional*/::mlir::ArrayAttr arg_attrs, /*optional*/::mlir::ArrayAttr res_attrs, /*optional*/::mlir::UnitAttr no_inline) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(sym_name), std::forward(function_type), std::forward(sym_visibility), std::forward(arg_attrs), std::forward(res_attrs), std::forward(no_inline)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } FuncOp FuncOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::StringAttr sym_name, ::mlir::TypeAttr function_type, /*optional*/::mlir::StringAttr sym_visibility, /*optional*/::mlir::ArrayAttr arg_attrs, /*optional*/::mlir::ArrayAttr res_attrs, /*optional*/::mlir::UnitAttr no_inline) { return create(builder, builder.getLoc(), std::forward(sym_name), std::forward(function_type), std::forward(sym_visibility), std::forward(arg_attrs), std::forward(res_attrs), std::forward(no_inline)); } void FuncOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::StringAttr sym_name, ::mlir::TypeAttr function_type, /*optional*/::mlir::StringAttr sym_visibility, /*optional*/::mlir::ArrayAttr arg_attrs, /*optional*/::mlir::ArrayAttr res_attrs, /*optional*/::mlir::UnitAttr no_inline) { odsState.getOrAddProperties().sym_name = sym_name; odsState.getOrAddProperties().function_type = function_type; if (sym_visibility) { odsState.getOrAddProperties().sym_visibility = sym_visibility; } if (arg_attrs) { odsState.getOrAddProperties().arg_attrs = arg_attrs; } if (res_attrs) { odsState.getOrAddProperties().res_attrs = res_attrs; } if (no_inline) { odsState.getOrAddProperties().no_inline = no_inline; } (void)odsState.addRegion(); assert(resultTypes.size() == 0u && "mismatched number of results"); odsState.addTypes(resultTypes); } FuncOp FuncOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::StringAttr sym_name, ::mlir::TypeAttr function_type, /*optional*/::mlir::StringAttr sym_visibility, /*optional*/::mlir::ArrayAttr arg_attrs, /*optional*/::mlir::ArrayAttr res_attrs, /*optional*/::mlir::UnitAttr no_inline) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(sym_name), std::forward(function_type), std::forward(sym_visibility), std::forward(arg_attrs), std::forward(res_attrs), std::forward(no_inline)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } FuncOp FuncOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::StringAttr sym_name, ::mlir::TypeAttr function_type, /*optional*/::mlir::StringAttr sym_visibility, /*optional*/::mlir::ArrayAttr arg_attrs, /*optional*/::mlir::ArrayAttr res_attrs, /*optional*/::mlir::UnitAttr no_inline) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(sym_name), std::forward(function_type), std::forward(sym_visibility), std::forward(arg_attrs), std::forward(res_attrs), std::forward(no_inline)); } void FuncOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::llvm::StringRef sym_name, ::mlir::FunctionType function_type, /*optional*/::mlir::StringAttr sym_visibility, /*optional*/::mlir::ArrayAttr arg_attrs, /*optional*/::mlir::ArrayAttr res_attrs, /*optional*/bool no_inline) { odsState.getOrAddProperties().sym_name = odsBuilder.getStringAttr(sym_name); odsState.getOrAddProperties().function_type = ::mlir::TypeAttr::get(function_type); if (sym_visibility) { odsState.getOrAddProperties().sym_visibility = sym_visibility; } if (arg_attrs) { odsState.getOrAddProperties().arg_attrs = arg_attrs; } if (res_attrs) { odsState.getOrAddProperties().res_attrs = res_attrs; } if (no_inline) { odsState.getOrAddProperties().no_inline = ((no_inline) ? odsBuilder.getUnitAttr() : nullptr); } (void)odsState.addRegion(); } FuncOp FuncOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::llvm::StringRef sym_name, ::mlir::FunctionType function_type, /*optional*/::mlir::StringAttr sym_visibility, /*optional*/::mlir::ArrayAttr arg_attrs, /*optional*/::mlir::ArrayAttr res_attrs, /*optional*/bool no_inline) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(sym_name), std::forward(function_type), std::forward(sym_visibility), std::forward(arg_attrs), std::forward(res_attrs), std::forward(no_inline)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } FuncOp FuncOp::create(::mlir::ImplicitLocOpBuilder &builder, ::llvm::StringRef sym_name, ::mlir::FunctionType function_type, /*optional*/::mlir::StringAttr sym_visibility, /*optional*/::mlir::ArrayAttr arg_attrs, /*optional*/::mlir::ArrayAttr res_attrs, /*optional*/bool no_inline) { return create(builder, builder.getLoc(), std::forward(sym_name), std::forward(function_type), std::forward(sym_visibility), std::forward(arg_attrs), std::forward(res_attrs), std::forward(no_inline)); } void FuncOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::llvm::StringRef sym_name, ::mlir::FunctionType function_type, /*optional*/::mlir::StringAttr sym_visibility, /*optional*/::mlir::ArrayAttr arg_attrs, /*optional*/::mlir::ArrayAttr res_attrs, /*optional*/bool no_inline) { odsState.getOrAddProperties().sym_name = odsBuilder.getStringAttr(sym_name); odsState.getOrAddProperties().function_type = ::mlir::TypeAttr::get(function_type); if (sym_visibility) { odsState.getOrAddProperties().sym_visibility = sym_visibility; } if (arg_attrs) { odsState.getOrAddProperties().arg_attrs = arg_attrs; } if (res_attrs) { odsState.getOrAddProperties().res_attrs = res_attrs; } if (no_inline) { odsState.getOrAddProperties().no_inline = ((no_inline) ? odsBuilder.getUnitAttr() : nullptr); } (void)odsState.addRegion(); assert(resultTypes.size() == 0u && "mismatched number of results"); odsState.addTypes(resultTypes); } FuncOp FuncOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::llvm::StringRef sym_name, ::mlir::FunctionType function_type, /*optional*/::mlir::StringAttr sym_visibility, /*optional*/::mlir::ArrayAttr arg_attrs, /*optional*/::mlir::ArrayAttr res_attrs, /*optional*/bool no_inline) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(resultTypes), std::forward(sym_name), std::forward(function_type), std::forward(sym_visibility), std::forward(arg_attrs), std::forward(res_attrs), std::forward(no_inline)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } FuncOp FuncOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::llvm::StringRef sym_name, ::mlir::FunctionType function_type, /*optional*/::mlir::StringAttr sym_visibility, /*optional*/::mlir::ArrayAttr arg_attrs, /*optional*/::mlir::ArrayAttr res_attrs, /*optional*/bool no_inline) { return create(builder, builder.getLoc(), std::forward(resultTypes), std::forward(sym_name), std::forward(function_type), std::forward(sym_visibility), std::forward(arg_attrs), std::forward(res_attrs), std::forward(no_inline)); } void FuncOp::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."); } } FuncOp FuncOp::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__; } FuncOp FuncOp::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 FuncOp::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); } FuncOp FuncOp::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__; } FuncOp FuncOp::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 FuncOp::verifyInvariantsImpl() { auto tblgen_arg_attrs = getProperties().arg_attrs; (void)tblgen_arg_attrs; auto tblgen_function_type = getProperties().function_type; (void)tblgen_function_type; if (!tblgen_function_type) return emitOpError("requires attribute 'function_type'"); auto tblgen_no_inline = getProperties().no_inline; (void)tblgen_no_inline; auto tblgen_res_attrs = getProperties().res_attrs; (void)tblgen_res_attrs; auto tblgen_sym_name = getProperties().sym_name; (void)tblgen_sym_name; if (!tblgen_sym_name) return emitOpError("requires attribute 'sym_name'"); auto tblgen_sym_visibility = getProperties().sym_visibility; (void)tblgen_sym_visibility; if (::mlir::failed(__mlir_ods_local_attr_constraint_FuncOps4(*this, tblgen_sym_name, "sym_name"))) return ::mlir::failure(); if (::mlir::failed(__mlir_ods_local_attr_constraint_FuncOps5(*this, tblgen_function_type, "function_type"))) return ::mlir::failure(); if (::mlir::failed(__mlir_ods_local_attr_constraint_FuncOps4(*this, tblgen_sym_visibility, "sym_visibility"))) return ::mlir::failure(); if (::mlir::failed(__mlir_ods_local_attr_constraint_FuncOps1(*this, tblgen_arg_attrs, "arg_attrs"))) return ::mlir::failure(); if (::mlir::failed(__mlir_ods_local_attr_constraint_FuncOps1(*this, tblgen_res_attrs, "res_attrs"))) return ::mlir::failure(); if (::mlir::failed(__mlir_ods_local_attr_constraint_FuncOps3(*this, tblgen_no_inline, "no_inline"))) return ::mlir::failure(); { unsigned index = 0; (void)index; for (auto ®ion : ::llvm::MutableArrayRef((*this)->getRegion(0))) if (::mlir::failed(__mlir_ods_local_region_constraint_FuncOps1(*this, region, "body", index++))) return ::mlir::failure(); } return ::mlir::success(); } ::llvm::LogicalResult FuncOp::verifyInvariants() { return verifyInvariantsImpl(); } ::llvm::LogicalResult FuncOp::setPropertiesFromParsedAttr(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(); } // keep track of used keys in the input dictionary to be able to error out // if there are some unknown ones. ::mlir::DenseSet<::mlir::StringAttr> usedKeys; ::mlir::MLIRContext *ctx = dict.getContext(); (void)ctx; { auto &propStorage = prop.sym_name; auto sym_nameAttrName = ::mlir::StringAttr::get(ctx, "sym_name"); auto attr = dict.get(sym_nameAttrName); usedKeys.insert(sym_nameAttrName); if (attr || /*isRequired=*/true) { if (!attr) { emitError() << "expected key entry for sym_name in DictionaryAttr to set " "Properties."; return ::mlir::failure(); } auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `sym_name` in property conversion: " << attr; return ::mlir::failure(); } } } { auto &propStorage = prop.function_type; auto function_typeAttrName = ::mlir::StringAttr::get(ctx, "function_type"); auto attr = dict.get(function_typeAttrName); usedKeys.insert(function_typeAttrName); if (attr || /*isRequired=*/true) { if (!attr) { emitError() << "expected key entry for function_type in DictionaryAttr to set " "Properties."; return ::mlir::failure(); } auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `function_type` in property conversion: " << attr; return ::mlir::failure(); } } } { auto &propStorage = prop.sym_visibility; auto sym_visibilityAttrName = ::mlir::StringAttr::get(ctx, "sym_visibility"); auto attr = dict.get(sym_visibilityAttrName); usedKeys.insert(sym_visibilityAttrName); if (attr || /*isRequired=*/false) { if (!attr) { emitError() << "expected key entry for sym_visibility in DictionaryAttr to set " "Properties."; return ::mlir::failure(); } auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `sym_visibility` in property conversion: " << attr; return ::mlir::failure(); } } } { auto &propStorage = prop.arg_attrs; auto arg_attrsAttrName = ::mlir::StringAttr::get(ctx, "arg_attrs"); auto attr = dict.get(arg_attrsAttrName); usedKeys.insert(arg_attrsAttrName); if (attr || /*isRequired=*/false) { if (!attr) { emitError() << "expected key entry for arg_attrs in DictionaryAttr to set " "Properties."; return ::mlir::failure(); } auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `arg_attrs` in property conversion: " << attr; return ::mlir::failure(); } } } { auto &propStorage = prop.res_attrs; auto res_attrsAttrName = ::mlir::StringAttr::get(ctx, "res_attrs"); auto attr = dict.get(res_attrsAttrName); usedKeys.insert(res_attrsAttrName); if (attr || /*isRequired=*/false) { if (!attr) { emitError() << "expected key entry for res_attrs in DictionaryAttr to set " "Properties."; return ::mlir::failure(); } auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `res_attrs` in property conversion: " << attr; return ::mlir::failure(); } } } { auto &propStorage = prop.no_inline; auto no_inlineAttrName = ::mlir::StringAttr::get(ctx, "no_inline"); auto attr = dict.get(no_inlineAttrName); usedKeys.insert(no_inlineAttrName); if (attr || /*isRequired=*/false) { if (!attr) { emitError() << "expected key entry for no_inline in DictionaryAttr to set " "Properties."; return ::mlir::failure(); } auto convertedAttr = ::llvm::dyn_cast>(attr); if (convertedAttr) { propStorage = convertedAttr; } else { emitError() << "Invalid attribute `no_inline` in property conversion: " << attr; return ::mlir::failure(); } } } for (::mlir::NamedAttribute attr : dict) { if (!usedKeys.contains(attr.getName())) return emitError() << "unknown key '" << attr.getName() << "' when parsing properties dictionary"; } return ::mlir::success(); } } // namespace mlir::func MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::func::FuncOp) MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::func::detail::FuncOpGenericAdaptorBase::Properties) namespace mlir::func { //===----------------------------------------------------------------------===// // ::mlir::func::ReturnOp definitions //===----------------------------------------------------------------------===// namespace detail { ReturnOpGenericAdaptorBase::ReturnOpGenericAdaptorBase(ReturnOp op) : odsAttrs(op->getRawDictionaryAttrs()), odsOpName(op->getName()), properties(op.getProperties()), odsRegions(op->getRegions()) {} std::pair ReturnOpGenericAdaptorBase::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 ReturnOpAdaptor::ReturnOpAdaptor(ReturnOp op) : ReturnOpGenericAdaptor(op->getOperands(), op) {} ::llvm::LogicalResult ReturnOpAdaptor::verify(::mlir::Location loc) { return ::mlir::success(); } std::pair ReturnOp::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 ReturnOp::getOperandsMutable() { auto range = getODSOperandIndexAndLength(0); auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); return mutableRange; } ::llvm::LogicalResult ReturnOp::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 ReturnOp::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 ReturnOp::computePropertiesHash(const Properties &prop) { using llvm::hash_value; return llvm::hash_combine(); } std::optional ReturnOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { return std::nullopt; } void ReturnOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { } void ReturnOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { } ::llvm::LogicalResult ReturnOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { return ::mlir::success(); } void ReturnOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState) { build(odsBuilder, odsState, {}); } ReturnOp ReturnOp::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__; } ReturnOp ReturnOp::create(::mlir::ImplicitLocOpBuilder &builder) { return create(builder, builder.getLoc()); } void ReturnOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands) { odsState.addOperands(operands); } ReturnOp ReturnOp::create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::ValueRange operands) { ::mlir::OperationState __state__(location, getOperationName()); build(builder, __state__, std::forward(operands)); auto __res__ = ::llvm::dyn_cast(builder.create(__state__)); assert(__res__ && "builder didn't return the right type"); return __res__; } ReturnOp ReturnOp::create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::ValueRange operands) { return create(builder, builder.getLoc(), std::forward(operands)); } void ReturnOp::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() == 0u && "mismatched number of return types"); odsState.addTypes(resultTypes); } ReturnOp ReturnOp::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__; } ReturnOp ReturnOp::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 ReturnOp::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() == 0u && "mismatched number of return types"); odsState.addTypes(resultTypes); } ReturnOp ReturnOp::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__; } ReturnOp ReturnOp::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 ReturnOp::verifyInvariantsImpl() { { unsigned index = 0; (void)index; auto valueGroup0 = getODSOperands(0); for (auto v : valueGroup0) { if (::mlir::failed(__mlir_ods_local_type_constraint_FuncOps2(*this, v.getType(), "operand", index++))) return ::mlir::failure(); } } return ::mlir::success(); } ::llvm::LogicalResult ReturnOp::verifyInvariants() { return verifyInvariantsImpl(); } ::mlir::ParseResult ReturnOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> operandsOperands; ::llvm::SMLoc operandsOperandsLoc; (void)operandsOperandsLoc; ::llvm::SmallVector<::mlir::Type, 1> operandsTypes; { 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(); } operandsOperandsLoc = parser.getCurrentLocation(); if (parser.parseOperandList(operandsOperands)) return ::mlir::failure(); if (!operandsOperands.empty()) { if (parser.parseColon()) return ::mlir::failure(); if (parser.parseTypeList(operandsTypes)) return ::mlir::failure(); } if (parser.resolveOperands(operandsOperands, operandsTypes, operandsOperandsLoc, result.operands)) return ::mlir::failure(); return ::mlir::success(); } void ReturnOp::print(::mlir::OpAsmPrinter &_odsPrinter) { ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); if (!getOperands().empty()) { _odsPrinter << ' '; _odsPrinter << getOperands(); _odsPrinter << ' ' << ":"; _odsPrinter << ' '; _odsPrinter << getOperands().getTypes(); } } void ReturnOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { } } // namespace mlir::func MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::func::ReturnOp) #endif // GET_OP_CLASSES