diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a44100..011c0a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,9 +9,23 @@ find_package(MLIR REQUIRED CONFIG) include_directories(${LLVM_INCLUDE_DIRS}) include_directories(${MLIR_INCLUDE_DIRS}) +list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}") +list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") + +include(TableGen) +include(AddLLVM) +include(AddMLIR) +include(HandleLLVMOptions) + set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") +# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") + +add_custom_target(Toy) +macro(add_toy_chapter name) + add_dependencies(Toy ${name}) + add_llvm_example(${name} ${ARGN}) +endmacro(add_toy_chapter name) add_subdirectory(Ch1) add_subdirectory(Ch2) diff --git a/Ch1/CMakeLists.txt b/Ch1/CMakeLists.txt index 2e8ba91..fd71e1f 100644 --- a/Ch1/CMakeLists.txt +++ b/Ch1/CMakeLists.txt @@ -3,7 +3,7 @@ set(LLVM_LINK_COMPONENTS Support ) -add_executable(toyc-ch1 +add_toy_chapter(toyc-ch1 toyc.cpp parser/AST.cpp ) diff --git a/Ch2/CMakeLists.txt b/Ch2/CMakeLists.txt index 1334f9a..a74abc9 100644 --- a/Ch2/CMakeLists.txt +++ b/Ch2/CMakeLists.txt @@ -5,12 +5,17 @@ set(LLVM_LINK_COMPONENTS Support ) -add_executable(toyc-ch2 +add_toy_chapter(toyc-ch2 toyc.cpp parser/AST.cpp mlir/MLIRGen.cpp mlir/Dialect.cpp - ) + + DEPENDS + ToyCh2OpsIncGen + +) + include_directories(include/) include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/) target_link_libraries(toyc-ch2 diff --git a/Ch2/include/toy/CMakeLists.txt b/Ch2/include/toy/CMakeLists.txt index 8b13789..301baaf 100644 --- a/Ch2/include/toy/CMakeLists.txt +++ b/Ch2/include/toy/CMakeLists.txt @@ -1 +1,6 @@ - +set(LLVM_TARGET_DEFINITIONS Ops.td) +mlir_tablegen(Ops.h.inc -gen-op-decls) +mlir_tablegen(Ops.cpp.inc -gen-op-defs) +mlir_tablegen(Dialect.h.inc -gen-dialect-decls) +mlir_tablegen(Dialect.cpp.inc -gen-dialect-defs) +add_public_tablegen_target(ToyCh2OpsIncGen) diff --git a/Ch2/include/toy/Dialect.cpp.inc b/Ch2/include/toy/Dialect.cpp.inc deleted file mode 100644 index 8cbc772..0000000 --- a/Ch2/include/toy/Dialect.cpp.inc +++ /dev/null @@ -1,23 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Dialect Definitions *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: Ops.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::ToyDialect) -namespace mlir { -namespace toy { - -ToyDialect::ToyDialect(::mlir::MLIRContext *context) - : ::mlir::Dialect(getDialectNamespace(), context, ::mlir::TypeID::get()) { - - initialize(); -} - -ToyDialect::~ToyDialect() = default; - -} // namespace toy -} // namespace mlir diff --git a/Ch2/include/toy/Dialect.h.inc b/Ch2/include/toy/Dialect.h.inc deleted file mode 100644 index f19d867..0000000 --- a/Ch2/include/toy/Dialect.h.inc +++ /dev/null @@ -1,26 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Dialect Declarations *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: Ops.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -namespace mlir { -namespace toy { - -class ToyDialect : public ::mlir::Dialect { - explicit ToyDialect(::mlir::MLIRContext *context); - - void initialize(); - friend class ::mlir::MLIRContext; -public: - ~ToyDialect() override; - static constexpr ::llvm::StringLiteral getDialectNamespace() { - return ::llvm::StringLiteral("toy"); - } -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::ToyDialect) diff --git a/Ch2/include/toy/Ops.cpp.inc b/Ch2/include/toy/Ops.cpp.inc deleted file mode 100644 index a3eabd3..0000000 --- a/Ch2/include/toy/Ops.cpp.inc +++ /dev/null @@ -1,2049 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Op Definitions *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: Ops.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -#ifdef GET_OP_LIST -#undef GET_OP_LIST - -::mlir::toy::AddOp, -::mlir::toy::ConstantOp, -::mlir::toy::FuncOp, -::mlir::toy::GenericCallOp, -::mlir::toy::MulOp, -::mlir::toy::PrintOp, -::mlir::toy::ReshapeOp, -::mlir::toy::ReturnOp, -::mlir::toy::TransposeOp -#endif // GET_OP_LIST - -#ifdef GET_OP_CLASSES -#undef GET_OP_CLASSES - - -//===----------------------------------------------------------------------===// -// Local Utility Method Definitions -//===----------------------------------------------------------------------===// - -namespace mlir { -namespace toy { - -static ::mlir::LogicalResult __mlir_ods_local_type_constraint_Ops0( - ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, - unsigned valueIndex) { - if (!(((::llvm::isa<::mlir::TensorType>(type))) && ([](::mlir::Type elementType) { return (elementType.isF64()); }(::llvm::cast<::mlir::ShapedType>(type).getElementType())))) { - return op->emitOpError(valueKind) << " #" << valueIndex - << " must be tensor of 64-bit float values, but got " << type; - } - return ::mlir::success(); -} - -static ::mlir::LogicalResult __mlir_ods_local_type_constraint_Ops1( - ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, - unsigned valueIndex) { - if (!(((::llvm::isa<::mlir::TensorType>(type))) && ([](::mlir::Type elementType) { return (elementType.isF64()); }(::llvm::cast<::mlir::ShapedType>(type).getElementType())))) { - return op->emitOpError(valueKind) << " #" << valueIndex - << " must be variadic of tensor of 64-bit float values, but got " << type; - } - return ::mlir::success(); -} - -static ::mlir::LogicalResult __mlir_ods_local_type_constraint_Ops2( - ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, - unsigned valueIndex) { - if (!((((::llvm::isa<::mlir::RankedTensorType>(type))) && ((::llvm::cast<::mlir::ShapedType>(type).hasStaticShape()))) && ([](::mlir::Type elementType) { return (elementType.isF64()); }(::llvm::cast<::mlir::ShapedType>(type).getElementType())))) { - return op->emitOpError(valueKind) << " #" << valueIndex - << " must be statically shaped tensor of 64-bit float values, but got " << type; - } - return ::mlir::success(); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops0( - ::mlir::Attribute attr, ::llvm::StringRef attrName, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { - if (attr && !((::llvm::isa<::mlir::DenseFPElementsAttr>(attr) &&::llvm::cast<::mlir::DenseElementsAttr>(attr).getType().getElementType().isF64()))) - return emitError() << "attribute '" << attrName - << "' failed to satisfy constraint: 64-bit float elements attribute"; - return ::mlir::success(); -} -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops0( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops0(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops1( - ::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 ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops1( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops1(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops2( - ::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 ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops2( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops2(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops3( - ::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 ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops3( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops3(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops4( - ::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 ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops4( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops4(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_region_constraint_Ops0( - ::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 toy -} // namespace mlir -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::AddOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -AddOpGenericAdaptorBase::AddOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.add", odsAttrs.getContext()); -} - -AddOpGenericAdaptorBase::AddOpGenericAdaptorBase(AddOp op) : AddOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair AddOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr AddOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -AddOpAdaptor::AddOpAdaptor(AddOp op) : AddOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult AddOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair AddOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range AddOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> AddOp::getLhs() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::TypedValue<::mlir::TensorType> AddOp::getRhs() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(1).begin()); -} - -::mlir::OpOperand &AddOp::getLhsMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -::mlir::OpOperand &AddOp::getRhsMutable() { - auto range = getODSOperandIndexAndLength(1); - return getOperation()->getOpOperand(range.first); -} - -std::pair AddOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range AddOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void AddOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value lhs, ::mlir::Value rhs) { - odsState.addOperands(lhs); - odsState.addOperands(rhs); - odsState.addTypes(resultType0); -} - -void AddOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs) { - odsState.addOperands(lhs); - odsState.addOperands(rhs); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void AddOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 2u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult AddOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*this, v.getType(), "operand", index++))) - return ::mlir::failure(); - } - auto valueGroup1 = getODSOperands(1); - - for (auto v : valueGroup1) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult AddOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::AddOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ConstantOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -ConstantOpGenericAdaptorBase::ConstantOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.constant", odsAttrs.getContext()); -} - -ConstantOpGenericAdaptorBase::ConstantOpGenericAdaptorBase(ConstantOp op) : ConstantOpGenericAdaptorBase(op->getDiscardableAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair ConstantOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr ConstantOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -::mlir::DenseElementsAttr ConstantOpGenericAdaptorBase::getValueAttr() { - auto attr = ::llvm::cast<::mlir::DenseElementsAttr>(getProperties().value); - return attr; -} - -::mlir::DenseElementsAttr ConstantOpGenericAdaptorBase::getValue() { - auto attr = getValueAttr(); - return attr; -} - -} // namespace detail -ConstantOpAdaptor::ConstantOpAdaptor(ConstantOp op) : ConstantOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult ConstantOpAdaptor::verify(::mlir::Location loc) { - auto tblgen_value = getProperties().value; (void)tblgen_value; - if (!tblgen_value) return emitError(loc, "'toy.constant' op ""requires attribute 'value'"); - - if (tblgen_value && !((::llvm::isa<::mlir::DenseFPElementsAttr>(tblgen_value) &&::llvm::cast<::mlir::DenseElementsAttr>(tblgen_value).getType().getElementType().isF64()))) - return emitError(loc, "'toy.constant' op ""attribute 'value' failed to satisfy constraint: 64-bit float elements attribute"); - return ::mlir::success(); -} - -std::pair ConstantOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range ConstantOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -std::pair ConstantOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range ConstantOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::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 || /*isRequired=*/true) { - if (!attr) { - emitError() << "expected key entry for value in DictionaryAttr to set " - "Properties."; - return ::mlir::failure(); - } - 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) { - 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); -} - -::mlir::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_Ops0(attr, "value", emitError))) - return ::mlir::failure(); - } - return ::mlir::success(); -} - -::mlir::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); -} - -::mlir::DenseElementsAttr ConstantOp::getValueAttr() { - return ::llvm::cast<::mlir::DenseElementsAttr>(getProperties().value); -} - -::mlir::DenseElementsAttr ConstantOp::getValue() { - auto attr = getValueAttr(); - return attr; -} - -void ConstantOp::setValueAttr(::mlir::DenseElementsAttr attr) { - (*this)->setAttr(getValueAttrName(), attr); -} - -void ConstantOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, DenseElementsAttr value) { - build(odsBuilder, odsState, value.getType(), value); - -} - -void ConstantOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::DenseElementsAttr value) { - odsState.getOrAddProperties().value = value; - odsState.addTypes(resultType0); -} - -void ConstantOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::DenseElementsAttr value) { - odsState.getOrAddProperties().value = value; - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -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); -} - -::mlir::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_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult ConstantOp::verifyInvariants() { - if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) - return ::mlir::success(); - return ::mlir::failure(); -} - -void ConstantOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::ConstantOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::FuncOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -FuncOpGenericAdaptorBase::FuncOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.func", odsAttrs.getContext()); -} - -FuncOpGenericAdaptorBase::FuncOpGenericAdaptorBase(FuncOp op) : FuncOpGenericAdaptorBase(op->getDiscardableAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair FuncOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr FuncOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -::mlir::StringAttr FuncOpGenericAdaptorBase::getSymNameAttr() { - auto attr = ::llvm::cast<::mlir::StringAttr>(getProperties().sym_name); - return attr; -} - -::llvm::StringRef FuncOpGenericAdaptorBase::getSymName() { - auto attr = getSymNameAttr(); - return attr.getValue(); -} - -::mlir::TypeAttr FuncOpGenericAdaptorBase::getFunctionTypeAttr() { - auto attr = ::llvm::cast<::mlir::TypeAttr>(getProperties().function_type); - return attr; -} - -::mlir::FunctionType FuncOpGenericAdaptorBase::getFunctionType() { - auto attr = getFunctionTypeAttr(); - return ::llvm::cast<::mlir::FunctionType>(attr.getValue()); -} - -::mlir::ArrayAttr FuncOpGenericAdaptorBase::getArgAttrsAttr() { - auto attr = ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(getProperties().arg_attrs); - return attr; -} - -::std::optional< ::mlir::ArrayAttr > FuncOpGenericAdaptorBase::getArgAttrs() { - auto attr = getArgAttrsAttr(); - return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); -} - -::mlir::ArrayAttr FuncOpGenericAdaptorBase::getResAttrsAttr() { - auto attr = ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(getProperties().res_attrs); - return attr; -} - -::std::optional< ::mlir::ArrayAttr > FuncOpGenericAdaptorBase::getResAttrs() { - auto attr = getResAttrsAttr(); - return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); -} - -::mlir::Region &FuncOpGenericAdaptorBase::getBody() { - return *odsRegions[0]; -} - -::mlir::RegionRange FuncOpGenericAdaptorBase::getRegions() { - return odsRegions; -} - -} // namespace detail -FuncOpAdaptor::FuncOpAdaptor(FuncOp op) : FuncOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::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, "'toy.func' op ""requires attribute 'function_type'"); - 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, "'toy.func' op ""requires attribute 'sym_name'"); - - if (tblgen_sym_name && !((::llvm::isa<::mlir::StringAttr>(tblgen_sym_name)))) - return emitError(loc, "'toy.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, "'toy.func' op ""attribute 'function_type' failed to satisfy constraint: type attribute of function type"); - - 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, "'toy.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, "'toy.func' op ""attribute 'res_attrs' failed to satisfy constraint: Array of dictionary attributes"); - return ::mlir::success(); -} - -std::pair FuncOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range FuncOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -std::pair FuncOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range FuncOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::Region &FuncOp::getBody() { - return (*this)->getRegion(0); -} - -::mlir::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 || /*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.function_type; - auto attr = dict.get("function_type"); - 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.res_attrs; - auto attr = dict.get("res_attrs"); - 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.sym_name; - auto attr = dict.get("sym_name"); - 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(); - } - } - } - 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.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)); - } - - if (!attrs.empty()) - return odsBuilder.getDictionaryAttr(attrs); - return {}; -} - -llvm::hash_code FuncOp::computePropertiesHash(const Properties &prop) { - return llvm::hash_combine( - llvm::hash_value(prop.arg_attrs.getAsOpaquePointer()), - llvm::hash_value(prop.function_type.getAsOpaquePointer()), - llvm::hash_value(prop.res_attrs.getAsOpaquePointer()), - llvm::hash_value(prop.sym_name.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 == "res_attrs") - return prop.res_attrs; - - if (name == "sym_name") - return prop.sym_name; - 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 == "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; - } -} - -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.res_attrs) attrs.append("res_attrs", prop.res_attrs); - - if (prop.sym_name) attrs.append("sym_name", prop.sym_name); -} - -::mlir::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_Ops3(attr, "arg_attrs", emitError))) - return ::mlir::failure(); - } - - { - ::mlir::Attribute attr = attrs.get(getFunctionTypeAttrName(opName)); - if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_Ops2(attr, "function_type", emitError))) - return ::mlir::failure(); - } - - { - ::mlir::Attribute attr = attrs.get(getResAttrsAttrName(opName)); - if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_Ops3(attr, "res_attrs", emitError))) - return ::mlir::failure(); - } - - { - ::mlir::Attribute attr = attrs.get(getSymNameAttrName(opName)); - if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_Ops1(attr, "sym_name", emitError))) - return ::mlir::failure(); - } - return ::mlir::success(); -} - -::mlir::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.res_attrs))) - return ::mlir::failure(); - - if (::mlir::failed(reader.readAttribute(prop.sym_name))) - 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.res_attrs); - writer.writeAttribute(prop.sym_name); -} - -::mlir::StringAttr FuncOp::getSymNameAttr() { - return ::llvm::cast<::mlir::StringAttr>(getProperties().sym_name); -} - -::llvm::StringRef FuncOp::getSymName() { - auto attr = getSymNameAttr(); - return attr.getValue(); -} - -::mlir::TypeAttr FuncOp::getFunctionTypeAttr() { - return ::llvm::cast<::mlir::TypeAttr>(getProperties().function_type); -} - -::mlir::FunctionType FuncOp::getFunctionType() { - auto attr = getFunctionTypeAttr(); - return ::llvm::cast<::mlir::FunctionType>(attr.getValue()); -} - -::mlir::ArrayAttr FuncOp::getArgAttrsAttr() { - return ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(getProperties().arg_attrs); -} - -::std::optional< ::mlir::ArrayAttr > FuncOp::getArgAttrs() { - auto attr = getArgAttrsAttr(); - return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); -} - -::mlir::ArrayAttr FuncOp::getResAttrsAttr() { - return ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(getProperties().res_attrs); -} - -::std::optional< ::mlir::ArrayAttr > FuncOp::getResAttrs() { - auto attr = getResAttrsAttr(); - return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); -} - -void FuncOp::setSymNameAttr(::mlir::StringAttr attr) { - (*this)->setAttr(getSymNameAttrName(), attr); -} - -void FuncOp::setSymName(::llvm::StringRef attrValue) { - (*this)->setAttr(getSymNameAttrName(), ::mlir::Builder((*this)->getContext()).getStringAttr(attrValue)); -} - -void FuncOp::setFunctionTypeAttr(::mlir::TypeAttr attr) { - (*this)->setAttr(getFunctionTypeAttrName(), attr); -} - -void FuncOp::setFunctionType(::mlir::FunctionType attrValue) { - (*this)->setAttr(getFunctionTypeAttrName(), ::mlir::TypeAttr::get(attrValue)); -} - -void FuncOp::setArgAttrsAttr(::mlir::ArrayAttr attr) { - (*this)->setAttr(getArgAttrsAttrName(), attr); -} - -void FuncOp::setResAttrsAttr(::mlir::ArrayAttr attr) { - (*this)->setAttr(getResAttrsAttrName(), attr); -} - -::mlir::Attribute FuncOp::removeArgAttrsAttr() { - auto &attr = getProperties().arg_attrs; - attr = {}; - return attr; -} - -::mlir::Attribute FuncOp::removeResAttrsAttr() { - auto &attr = getProperties().res_attrs; - attr = {}; - return attr; -} - -::mlir::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_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'"); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops1(*this, tblgen_sym_name, "sym_name"))) - return ::mlir::failure(); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops2(*this, tblgen_function_type, "function_type"))) - return ::mlir::failure(); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops3(*this, tblgen_arg_attrs, "arg_attrs"))) - return ::mlir::failure(); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops3(*this, tblgen_res_attrs, "res_attrs"))) - return ::mlir::failure(); - { - unsigned index = 0; (void)index; - - for (auto ®ion : ::llvm::MutableArrayRef((*this)->getRegion(0))) - if (::mlir::failed(__mlir_ods_local_region_constraint_Ops0(*this, region, "body", index++))) - return ::mlir::failure(); - } - return ::mlir::success(); -} - -::mlir::LogicalResult FuncOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::FuncOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::GenericCallOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -GenericCallOpGenericAdaptorBase::GenericCallOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.generic_call", odsAttrs.getContext()); -} - -GenericCallOpGenericAdaptorBase::GenericCallOpGenericAdaptorBase(GenericCallOp op) : GenericCallOpGenericAdaptorBase(op->getDiscardableAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair GenericCallOpGenericAdaptorBase::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}; -} - -::mlir::DictionaryAttr GenericCallOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -::mlir::FlatSymbolRefAttr GenericCallOpGenericAdaptorBase::getCalleeAttr() { - auto attr = ::llvm::cast<::mlir::FlatSymbolRefAttr>(getProperties().callee); - return attr; -} - -::llvm::StringRef GenericCallOpGenericAdaptorBase::getCallee() { - auto attr = getCalleeAttr(); - return attr.getValue(); -} - -} // namespace detail -GenericCallOpAdaptor::GenericCallOpAdaptor(GenericCallOp op) : GenericCallOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult GenericCallOpAdaptor::verify(::mlir::Location loc) { - auto tblgen_callee = getProperties().callee; (void)tblgen_callee; - if (!tblgen_callee) return emitError(loc, "'toy.generic_call' op ""requires attribute 'callee'"); - - if (tblgen_callee && !((::llvm::isa<::mlir::FlatSymbolRefAttr>(tblgen_callee)))) - return emitError(loc, "'toy.generic_call' op ""attribute 'callee' failed to satisfy constraint: flat symbol reference attribute"); - return ::mlir::success(); -} - -std::pair GenericCallOp::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::Operation::operand_range GenericCallOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::Operation::operand_range GenericCallOp::getInputs() { - return getODSOperands(0); -} - -::mlir::MutableOperandRange GenericCallOp::getInputsMutable() { - auto range = getODSOperandIndexAndLength(0); - auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); - return mutableRange; -} - -std::pair GenericCallOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range GenericCallOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::LogicalResult GenericCallOp::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.callee; - auto attr = dict.get("callee"); - if (attr || /*isRequired=*/true) { - if (!attr) { - emitError() << "expected key entry for callee in DictionaryAttr to set " - "Properties."; - return ::mlir::failure(); - } - auto convertedAttr = ::llvm::dyn_cast>(attr); - if (convertedAttr) { - propStorage = convertedAttr; - } else { - emitError() << "Invalid attribute `callee` in property conversion: " << attr; - return ::mlir::failure(); - } - } - } - return ::mlir::success(); -} - -::mlir::Attribute GenericCallOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) { - ::mlir::SmallVector<::mlir::NamedAttribute> attrs; - ::mlir::Builder odsBuilder{ctx}; - - { - const auto &propStorage = prop.callee; - if (propStorage) - attrs.push_back(odsBuilder.getNamedAttr("callee", - propStorage)); - } - - if (!attrs.empty()) - return odsBuilder.getDictionaryAttr(attrs); - return {}; -} - -llvm::hash_code GenericCallOp::computePropertiesHash(const Properties &prop) { - return llvm::hash_combine( - llvm::hash_value(prop.callee.getAsOpaquePointer())); -} - -std::optional GenericCallOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { - if (name == "callee") - return prop.callee; - return std::nullopt; -} - -void GenericCallOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { - if (name == "callee") { - prop.callee = ::llvm::dyn_cast_or_null>(value); - return; - } -} - -void GenericCallOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { - if (prop.callee) attrs.append("callee", prop.callee); -} - -::mlir::LogicalResult GenericCallOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { - { - ::mlir::Attribute attr = attrs.get(getCalleeAttrName(opName)); - if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_Ops4(attr, "callee", emitError))) - return ::mlir::failure(); - } - return ::mlir::success(); -} - -::mlir::LogicalResult GenericCallOp::readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state) { - auto &prop = state.getOrAddProperties(); (void)prop; - if (::mlir::failed(reader.readAttribute(prop.callee))) - return ::mlir::failure(); - return ::mlir::success(); -} - -void GenericCallOp::writeProperties(::mlir::DialectBytecodeWriter &writer) { - auto &prop = getProperties(); (void)prop; - writer.writeAttribute(prop.callee); -} - -::mlir::FlatSymbolRefAttr GenericCallOp::getCalleeAttr() { - return ::llvm::cast<::mlir::FlatSymbolRefAttr>(getProperties().callee); -} - -::llvm::StringRef GenericCallOp::getCallee() { - auto attr = getCalleeAttr(); - return attr.getValue(); -} - -void GenericCallOp::setCalleeAttr(::mlir::FlatSymbolRefAttr attr) { - (*this)->setAttr(getCalleeAttrName(), attr); -} - -void GenericCallOp::setCallee(::llvm::StringRef attrValue) { - (*this)->setAttr(getCalleeAttrName(), ::mlir::SymbolRefAttr::get(::mlir::Builder((*this)->getContext()).getContext(), attrValue)); -} - -void GenericCallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::FlatSymbolRefAttr callee, ::mlir::ValueRange inputs) { - odsState.addOperands(inputs); - odsState.getOrAddProperties().callee = callee; - odsState.addTypes(resultType0); -} - -void GenericCallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::FlatSymbolRefAttr callee, ::mlir::ValueRange inputs) { - odsState.addOperands(inputs); - odsState.getOrAddProperties().callee = callee; - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void GenericCallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::llvm::StringRef callee, ::mlir::ValueRange inputs) { - odsState.addOperands(inputs); - odsState.getOrAddProperties().callee = ::mlir::SymbolRefAttr::get(odsBuilder.getContext(), callee); - odsState.addTypes(resultType0); -} - -void GenericCallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::llvm::StringRef callee, ::mlir::ValueRange inputs) { - odsState.addOperands(inputs); - odsState.getOrAddProperties().callee = ::mlir::SymbolRefAttr::get(odsBuilder.getContext(), callee); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void GenericCallOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult GenericCallOp::verifyInvariantsImpl() { - auto tblgen_callee = getProperties().callee; (void)tblgen_callee; - if (!tblgen_callee) return emitOpError("requires attribute 'callee'"); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops4(*this, tblgen_callee, "callee"))) - return ::mlir::failure(); - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops1(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult GenericCallOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -::mlir::ParseResult GenericCallOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::FlatSymbolRefAttr calleeAttr; - ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> inputsOperands; - ::llvm::SMLoc inputsOperandsLoc; - (void)inputsOperandsLoc; - ::llvm::ArrayRef<::mlir::Type> inputsTypes; - ::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(); - - inputsOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperandList(inputsOperands)) - 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 inputs__allResult_functionType; - if (parser.parseType(inputs__allResult_functionType)) - return ::mlir::failure(); - inputsTypes = inputs__allResult_functionType.getInputs(); - allResultTypes = inputs__allResult_functionType.getResults(); - result.addTypes(allResultTypes); - if (parser.resolveOperands(inputsOperands, inputsTypes, inputsOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void GenericCallOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << ' '; - _odsPrinter.printAttributeWithoutType(getCalleeAttr()); - _odsPrinter << "("; - _odsPrinter << getInputs(); - _odsPrinter << ")"; - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - elidedAttrs.push_back("callee"); - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - _odsPrinter.printFunctionalType(getInputs().getTypes(), getOperation()->getResultTypes()); -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::GenericCallOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::MulOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -MulOpGenericAdaptorBase::MulOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.mul", odsAttrs.getContext()); -} - -MulOpGenericAdaptorBase::MulOpGenericAdaptorBase(MulOp op) : MulOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair MulOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr MulOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -MulOpAdaptor::MulOpAdaptor(MulOp op) : MulOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult MulOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair MulOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range MulOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> MulOp::getLhs() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::TypedValue<::mlir::TensorType> MulOp::getRhs() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(1).begin()); -} - -::mlir::OpOperand &MulOp::getLhsMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -::mlir::OpOperand &MulOp::getRhsMutable() { - auto range = getODSOperandIndexAndLength(1); - return getOperation()->getOpOperand(range.first); -} - -std::pair MulOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range MulOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void MulOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value lhs, ::mlir::Value rhs) { - odsState.addOperands(lhs); - odsState.addOperands(rhs); - odsState.addTypes(resultType0); -} - -void MulOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs) { - odsState.addOperands(lhs); - odsState.addOperands(rhs); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void MulOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 2u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult MulOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*this, v.getType(), "operand", index++))) - return ::mlir::failure(); - } - auto valueGroup1 = getODSOperands(1); - - for (auto v : valueGroup1) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult MulOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::MulOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::PrintOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -PrintOpGenericAdaptorBase::PrintOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.print", odsAttrs.getContext()); -} - -PrintOpGenericAdaptorBase::PrintOpGenericAdaptorBase(PrintOp op) : PrintOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair PrintOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr PrintOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -PrintOpAdaptor::PrintOpAdaptor(PrintOp op) : PrintOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult PrintOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair PrintOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range PrintOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> PrintOp::getInput() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::OpOperand &PrintOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -std::pair PrintOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range PrintOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void PrintOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value input) { - odsState.addOperands(input); -} - -void PrintOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input) { - odsState.addOperands(input); - assert(resultTypes.size() == 0u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void PrintOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 1u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 0u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult PrintOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*this, v.getType(), "operand", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult PrintOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -::mlir::ParseResult PrintOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::OpAsmParser::UnresolvedOperand inputRawOperands[1]; - ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> inputOperands(inputRawOperands); ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::mlir::Type inputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> inputTypes(inputRawTypes); - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperand(inputRawOperands[0])) - return ::mlir::failure(); - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.parseColon()) - return ::mlir::failure(); - - { - ::mlir::TensorType type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - inputRawTypes[0] = type; - } - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void PrintOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << ' '; - _odsPrinter << getInput(); - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - { - auto type = getInput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::TensorType>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::PrintOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ReshapeOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -ReshapeOpGenericAdaptorBase::ReshapeOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.reshape", odsAttrs.getContext()); -} - -ReshapeOpGenericAdaptorBase::ReshapeOpGenericAdaptorBase(ReshapeOp op) : ReshapeOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair ReshapeOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr ReshapeOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -ReshapeOpAdaptor::ReshapeOpAdaptor(ReshapeOp op) : ReshapeOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult ReshapeOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair ReshapeOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range ReshapeOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> ReshapeOp::getInput() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::OpOperand &ReshapeOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -std::pair ReshapeOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range ReshapeOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void ReshapeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value input) { - odsState.addOperands(input); - odsState.addTypes(resultType0); -} - -void ReshapeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input) { - odsState.addOperands(input); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void ReshapeOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 1u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult ReshapeOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops2(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult ReshapeOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -::mlir::ParseResult ReshapeOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::OpAsmParser::UnresolvedOperand inputRawOperands[1]; - ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> inputOperands(inputRawOperands); ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::mlir::Type inputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> inputTypes(inputRawTypes); - ::llvm::SmallVector<::mlir::Type, 1> allResultTypes; - if (parser.parseLParen()) - return ::mlir::failure(); - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperand(inputRawOperands[0])) - return ::mlir::failure(); - if (parser.parseColon()) - return ::mlir::failure(); - - { - ::mlir::TensorType type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - inputRawTypes[0] = type; - } - if (parser.parseRParen()) - return ::mlir::failure(); - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.parseKeyword("to")) - return ::mlir::failure(); - - if (parser.parseTypeList(allResultTypes)) - return ::mlir::failure(); - result.addTypes(allResultTypes); - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void ReshapeOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << "("; - _odsPrinter << getInput(); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - { - auto type = getInput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::TensorType>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } - _odsPrinter << ")"; - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << "to"; - _odsPrinter << ' '; - _odsPrinter << getOperation()->getResultTypes(); -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::ReshapeOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ReturnOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -ReturnOpGenericAdaptorBase::ReturnOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.return", odsAttrs.getContext()); -} - -ReturnOpGenericAdaptorBase::ReturnOpGenericAdaptorBase(ReturnOp op) : ReturnOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), 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}; -} - -::mlir::DictionaryAttr ReturnOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -ReturnOpAdaptor::ReturnOpAdaptor(ReturnOp op) : ReturnOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::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::Operation::operand_range ReturnOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::Operation::operand_range ReturnOp::getInput() { - return getODSOperands(0); -} - -::mlir::MutableOperandRange ReturnOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); - return mutableRange; -} - -std::pair ReturnOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range ReturnOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void ReturnOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState) { - build(odsBuilder, odsState, std::nullopt); -} - -void ReturnOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange input) { - odsState.addOperands(input); -} - -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); -} - -::mlir::LogicalResult ReturnOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops1(*this, v.getType(), "operand", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult ReturnOp::verifyInvariants() { - if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) - return ::mlir::success(); - return ::mlir::failure(); -} - -::mlir::ParseResult ReturnOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> inputOperands; - ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::llvm::SmallVector<::mlir::Type, 1> inputTypes; - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperandList(inputOperands)) - return ::mlir::failure(); - if (!inputOperands.empty()) { - if (parser.parseColon()) - return ::mlir::failure(); - - if (parser.parseTypeList(inputTypes)) - return ::mlir::failure(); - } - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void ReturnOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - if (!getInput().empty()) { - _odsPrinter << ' '; - _odsPrinter << getInput(); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - _odsPrinter << getInput().getTypes(); - } - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); -} - -void ReturnOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::ReturnOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::TransposeOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -TransposeOpGenericAdaptorBase::TransposeOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.transpose", odsAttrs.getContext()); -} - -TransposeOpGenericAdaptorBase::TransposeOpGenericAdaptorBase(TransposeOp op) : TransposeOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair TransposeOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr TransposeOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -TransposeOpAdaptor::TransposeOpAdaptor(TransposeOp op) : TransposeOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult TransposeOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair TransposeOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range TransposeOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> TransposeOp::getInput() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::OpOperand &TransposeOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -std::pair TransposeOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range TransposeOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void TransposeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value input) { - odsState.addOperands(input); - odsState.addTypes(resultType0); -} - -void TransposeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input) { - odsState.addOperands(input); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void TransposeOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 1u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult TransposeOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult TransposeOp::verifyInvariants() { - if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) - return ::mlir::success(); - return ::mlir::failure(); -} - -::mlir::ParseResult TransposeOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::OpAsmParser::UnresolvedOperand inputRawOperands[1]; - ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> inputOperands(inputRawOperands); ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::mlir::Type inputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> inputTypes(inputRawTypes); - ::llvm::SmallVector<::mlir::Type, 1> allResultTypes; - if (parser.parseLParen()) - return ::mlir::failure(); - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperand(inputRawOperands[0])) - return ::mlir::failure(); - if (parser.parseColon()) - return ::mlir::failure(); - - { - ::mlir::TensorType type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - inputRawTypes[0] = type; - } - if (parser.parseRParen()) - return ::mlir::failure(); - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.parseKeyword("to")) - return ::mlir::failure(); - - if (parser.parseTypeList(allResultTypes)) - return ::mlir::failure(); - result.addTypes(allResultTypes); - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void TransposeOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << "("; - _odsPrinter << getInput(); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - { - auto type = getInput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::TensorType>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } - _odsPrinter << ")"; - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << "to"; - _odsPrinter << ' '; - _odsPrinter << getOperation()->getResultTypes(); -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::TransposeOp) - - -#endif // GET_OP_CLASSES - diff --git a/Ch2/include/toy/Ops.h.inc b/Ch2/include/toy/Ops.h.inc deleted file mode 100644 index ef289c7..0000000 --- a/Ch2/include/toy/Ops.h.inc +++ /dev/null @@ -1,1240 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Op Declarations *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: Ops.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -#if defined(GET_OP_CLASSES) || defined(GET_OP_FWD_DEFINES) -#undef GET_OP_FWD_DEFINES -namespace mlir { -namespace toy { -class AddOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class ConstantOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class FuncOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class GenericCallOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class MulOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class PrintOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class ReshapeOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class ReturnOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class TransposeOp; -} // namespace toy -} // namespace mlir -#endif - -#ifdef GET_OP_CLASSES -#undef GET_OP_CLASSES - - -//===----------------------------------------------------------------------===// -// Local Utility Method Definitions -//===----------------------------------------------------------------------===// - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::AddOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class AddOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - AddOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - AddOpGenericAdaptorBase(AddOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class AddOpGenericAdaptor : public detail::AddOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::AddOpGenericAdaptorBase; -public: - AddOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - AddOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : AddOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - AddOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getLhs() { - return (*getODSOperands(0).begin()); - } - - ValueT getRhs() { - return (*getODSOperands(1).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class AddOpAdaptor : public AddOpGenericAdaptor<::mlir::ValueRange> { -public: - using AddOpGenericAdaptor::AddOpGenericAdaptor; - AddOpAdaptor(AddOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class AddOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::NOperands<2>::Impl, ::mlir::OpTrait::OpInvariants> { -public: - using Op::Op; - using Op::print; - using Adaptor = AddOpAdaptor; - template - using GenericAdaptor = AddOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.add"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getLhs(); - ::mlir::TypedValue<::mlir::TensorType> getRhs(); - ::mlir::OpOperand &getLhsMutable(); - ::mlir::OpOperand &getRhsMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, Value lhs, Value rhs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value lhs, ::mlir::Value rhs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &p); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::AddOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ConstantOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class ConstantOpGenericAdaptorBase { -public: - struct Properties { - using valueTy = ::mlir::DenseElementsAttr; - valueTy value; - - auto getValue() { - auto &propStorage = this->value; - return ::llvm::cast<::mlir::DenseElementsAttr>(propStorage); - } - void setValue(const ::mlir::DenseElementsAttr &propValue) { - this->value = propValue; - } - bool operator==(const Properties &rhs) const { - return - rhs.value == this->value && - true; - } - bool operator!=(const Properties &rhs) const { - return !(*this == rhs); - } - }; -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - Properties properties; - ::mlir::RegionRange odsRegions; -public: - ConstantOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}); - - ConstantOpGenericAdaptorBase(ConstantOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - const Properties &getProperties() { - return properties; - } - - ::mlir::DictionaryAttr getAttributes(); - ::mlir::DenseElementsAttr getValueAttr(); - ::mlir::DenseElementsAttr getValue(); -}; -} // namespace detail -template -class ConstantOpGenericAdaptor : public detail::ConstantOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::ConstantOpGenericAdaptorBase; -public: - ConstantOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - ConstantOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : ConstantOpGenericAdaptor(values, attrs, (properties ? *properties.as() : Properties{}), regions) {} - - template >> - ConstantOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class ConstantOpAdaptor : public ConstantOpGenericAdaptor<::mlir::ValueRange> { -public: - using ConstantOpGenericAdaptor::ConstantOpGenericAdaptor; - ConstantOpAdaptor(ConstantOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class ConstantOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::ZeroOperands, ::mlir::OpTrait::OpInvariants, ::mlir::BytecodeOpInterface::Trait, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = ConstantOpAdaptor; - template - using GenericAdaptor = ConstantOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - using Properties = FoldAdaptor::Properties; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - static ::llvm::StringRef attrNames[] = {::llvm::StringRef("value")}; - return ::llvm::ArrayRef(attrNames); - } - - ::mlir::StringAttr getValueAttrName() { - return getAttributeNameForIndex(0); - } - - static ::mlir::StringAttr getValueAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 0); - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.constant"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static ::mlir::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop); - static llvm::hash_code computePropertiesHash(const Properties &prop); - static std::optional getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name); - static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value); - static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs); - static ::mlir::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::LogicalResult readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state); - void writeProperties(::mlir::DialectBytecodeWriter &writer); - ::mlir::DenseElementsAttr getValueAttr(); - ::mlir::DenseElementsAttr getValue(); - void setValueAttr(::mlir::DenseElementsAttr attr); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, DenseElementsAttr value); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, double value); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::DenseElementsAttr value); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::DenseElementsAttr value); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &p); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - ::mlir::LogicalResult verify(); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -private: - ::mlir::StringAttr getAttributeNameForIndex(unsigned index) { - return getAttributeNameForIndex((*this)->getName(), index); - } - - static ::mlir::StringAttr getAttributeNameForIndex(::mlir::OperationName name, unsigned index) { - assert(index < 1 && "invalid attribute index"); - assert(name.getStringRef() == getOperationName() && "invalid operation name"); - assert(name.isRegistered() && "Operation isn't registered, missing a " - "dependent dialect loading?"); - return name.getAttributeNames()[index]; - } - -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::ConstantOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::FuncOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class FuncOpGenericAdaptorBase { -public: - struct Properties { - using arg_attrsTy = ::mlir::ArrayAttr; - arg_attrsTy arg_attrs; - - auto getArgAttrs() { - auto &propStorage = this->arg_attrs; - return ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(propStorage); - } - void setArgAttrs(const ::mlir::ArrayAttr &propValue) { - this->arg_attrs = propValue; - } - using function_typeTy = ::mlir::TypeAttr; - function_typeTy function_type; - - auto getFunctionType() { - auto &propStorage = this->function_type; - return ::llvm::cast<::mlir::TypeAttr>(propStorage); - } - void setFunctionType(const ::mlir::TypeAttr &propValue) { - this->function_type = propValue; - } - using res_attrsTy = ::mlir::ArrayAttr; - res_attrsTy res_attrs; - - auto getResAttrs() { - auto &propStorage = this->res_attrs; - return ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(propStorage); - } - void setResAttrs(const ::mlir::ArrayAttr &propValue) { - this->res_attrs = propValue; - } - using sym_nameTy = ::mlir::StringAttr; - sym_nameTy sym_name; - - auto getSymName() { - auto &propStorage = this->sym_name; - return ::llvm::cast<::mlir::StringAttr>(propStorage); - } - void setSymName(const ::mlir::StringAttr &propValue) { - this->sym_name = propValue; - } - bool operator==(const Properties &rhs) const { - return - rhs.arg_attrs == this->arg_attrs && - rhs.function_type == this->function_type && - rhs.res_attrs == this->res_attrs && - rhs.sym_name == this->sym_name && - true; - } - bool operator!=(const Properties &rhs) const { - return !(*this == rhs); - } - }; -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - Properties properties; - ::mlir::RegionRange odsRegions; -public: - FuncOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}); - - FuncOpGenericAdaptorBase(FuncOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - const Properties &getProperties() { - return properties; - } - - ::mlir::DictionaryAttr getAttributes(); - ::mlir::StringAttr getSymNameAttr(); - ::llvm::StringRef getSymName(); - ::mlir::TypeAttr getFunctionTypeAttr(); - ::mlir::FunctionType getFunctionType(); - ::mlir::ArrayAttr getArgAttrsAttr(); - ::std::optional< ::mlir::ArrayAttr > getArgAttrs(); - ::mlir::ArrayAttr getResAttrsAttr(); - ::std::optional< ::mlir::ArrayAttr > getResAttrs(); - ::mlir::Region &getBody(); - ::mlir::RegionRange getRegions(); -}; -} // namespace detail -template -class FuncOpGenericAdaptor : public detail::FuncOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::FuncOpGenericAdaptorBase; -public: - FuncOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - FuncOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : FuncOpGenericAdaptor(values, attrs, (properties ? *properties.as() : Properties{}), regions) {} - - template >> - FuncOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class FuncOpAdaptor : public FuncOpGenericAdaptor<::mlir::ValueRange> { -public: - using FuncOpGenericAdaptor::FuncOpGenericAdaptor; - FuncOpAdaptor(FuncOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class FuncOp : public ::mlir::Op { -public: - using Op::Op; - using Op::print; - using Adaptor = FuncOpAdaptor; - template - using GenericAdaptor = FuncOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - using Properties = FoldAdaptor::Properties; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - static ::llvm::StringRef attrNames[] = {::llvm::StringRef("arg_attrs"), ::llvm::StringRef("function_type"), ::llvm::StringRef("res_attrs"), ::llvm::StringRef("sym_name")}; - return ::llvm::ArrayRef(attrNames); - } - - ::mlir::StringAttr getArgAttrsAttrName() { - return getAttributeNameForIndex(0); - } - - static ::mlir::StringAttr getArgAttrsAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 0); - } - - ::mlir::StringAttr getFunctionTypeAttrName() { - return getAttributeNameForIndex(1); - } - - static ::mlir::StringAttr getFunctionTypeAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 1); - } - - ::mlir::StringAttr getResAttrsAttrName() { - return getAttributeNameForIndex(2); - } - - static ::mlir::StringAttr getResAttrsAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 2); - } - - ::mlir::StringAttr getSymNameAttrName() { - return getAttributeNameForIndex(3); - } - - static ::mlir::StringAttr getSymNameAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 3); - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.func"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - ::mlir::Region &getBody(); - static ::mlir::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop); - static llvm::hash_code computePropertiesHash(const Properties &prop); - static std::optional getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name); - static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value); - static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs); - static ::mlir::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::LogicalResult readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state); - void writeProperties(::mlir::DialectBytecodeWriter &writer); - ::mlir::StringAttr getSymNameAttr(); - ::llvm::StringRef getSymName(); - ::mlir::TypeAttr getFunctionTypeAttr(); - ::mlir::FunctionType getFunctionType(); - ::mlir::ArrayAttr getArgAttrsAttr(); - ::std::optional< ::mlir::ArrayAttr > getArgAttrs(); - ::mlir::ArrayAttr getResAttrsAttr(); - ::std::optional< ::mlir::ArrayAttr > getResAttrs(); - void setSymNameAttr(::mlir::StringAttr attr); - void setSymName(::llvm::StringRef attrValue); - void setFunctionTypeAttr(::mlir::TypeAttr attr); - void setFunctionType(::mlir::FunctionType attrValue); - void setArgAttrsAttr(::mlir::ArrayAttr attr); - void setResAttrsAttr(::mlir::ArrayAttr attr); - ::mlir::Attribute removeArgAttrsAttr(); - ::mlir::Attribute removeResAttrsAttr(); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, StringRef name, FunctionType type, ArrayRef attrs = {}); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &p); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); -private: - ::mlir::StringAttr getAttributeNameForIndex(unsigned index) { - return getAttributeNameForIndex((*this)->getName(), index); - } - - static ::mlir::StringAttr getAttributeNameForIndex(::mlir::OperationName name, unsigned index) { - assert(index < 4 && "invalid attribute index"); - assert(name.getStringRef() == getOperationName() && "invalid operation name"); - assert(name.isRegistered() && "Operation isn't registered, missing a " - "dependent dialect loading?"); - return name.getAttributeNames()[index]; - } - -public: - //===------------------------------------------------------------------===// - // FunctionOpInterface Methods - //===------------------------------------------------------------------===// - - /// Returns the argument types of this function. - ArrayRef getArgumentTypes() { return getFunctionType().getInputs(); } - - /// Returns the result types of this function. - ArrayRef getResultTypes() { return getFunctionType().getResults(); } - - Region *getCallableRegion() { return &getBody(); } -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::FuncOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::GenericCallOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class GenericCallOpGenericAdaptorBase { -public: - struct Properties { - using calleeTy = ::mlir::FlatSymbolRefAttr; - calleeTy callee; - - auto getCallee() { - auto &propStorage = this->callee; - return ::llvm::cast<::mlir::FlatSymbolRefAttr>(propStorage); - } - void setCallee(const ::mlir::FlatSymbolRefAttr &propValue) { - this->callee = propValue; - } - bool operator==(const Properties &rhs) const { - return - rhs.callee == this->callee && - true; - } - bool operator!=(const Properties &rhs) const { - return !(*this == rhs); - } - }; -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - Properties properties; - ::mlir::RegionRange odsRegions; -public: - GenericCallOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}); - - GenericCallOpGenericAdaptorBase(GenericCallOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - const Properties &getProperties() { - return properties; - } - - ::mlir::DictionaryAttr getAttributes(); - ::mlir::FlatSymbolRefAttr getCalleeAttr(); - ::llvm::StringRef getCallee(); -}; -} // namespace detail -template -class GenericCallOpGenericAdaptor : public detail::GenericCallOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::GenericCallOpGenericAdaptorBase; -public: - GenericCallOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - GenericCallOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : GenericCallOpGenericAdaptor(values, attrs, (properties ? *properties.as() : Properties{}), regions) {} - - template >> - GenericCallOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - RangeT getInputs() { - return getODSOperands(0); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class GenericCallOpAdaptor : public GenericCallOpGenericAdaptor<::mlir::ValueRange> { -public: - using GenericCallOpGenericAdaptor::GenericCallOpGenericAdaptor; - GenericCallOpAdaptor(GenericCallOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class GenericCallOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::VariadicOperands, ::mlir::OpTrait::OpInvariants, ::mlir::BytecodeOpInterface::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = GenericCallOpAdaptor; - template - using GenericAdaptor = GenericCallOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - using Properties = FoldAdaptor::Properties; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - static ::llvm::StringRef attrNames[] = {::llvm::StringRef("callee")}; - return ::llvm::ArrayRef(attrNames); - } - - ::mlir::StringAttr getCalleeAttrName() { - return getAttributeNameForIndex(0); - } - - static ::mlir::StringAttr getCalleeAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 0); - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.generic_call"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::Operation::operand_range getInputs(); - ::mlir::MutableOperandRange getInputsMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static ::mlir::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop); - static llvm::hash_code computePropertiesHash(const Properties &prop); - static std::optional getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name); - static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value); - static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs); - static ::mlir::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::LogicalResult readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state); - void writeProperties(::mlir::DialectBytecodeWriter &writer); - ::mlir::FlatSymbolRefAttr getCalleeAttr(); - ::llvm::StringRef getCallee(); - void setCalleeAttr(::mlir::FlatSymbolRefAttr attr); - void setCallee(::llvm::StringRef attrValue); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, StringRef callee, ArrayRef arguments); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::FlatSymbolRefAttr callee, ::mlir::ValueRange inputs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::FlatSymbolRefAttr callee, ::mlir::ValueRange inputs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::llvm::StringRef callee, ::mlir::ValueRange inputs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::llvm::StringRef callee, ::mlir::ValueRange inputs); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); -private: - ::mlir::StringAttr getAttributeNameForIndex(unsigned index) { - return getAttributeNameForIndex((*this)->getName(), index); - } - - static ::mlir::StringAttr getAttributeNameForIndex(::mlir::OperationName name, unsigned index) { - assert(index < 1 && "invalid attribute index"); - assert(name.getStringRef() == getOperationName() && "invalid operation name"); - assert(name.isRegistered() && "Operation isn't registered, missing a " - "dependent dialect loading?"); - return name.getAttributeNames()[index]; - } - -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::GenericCallOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::MulOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class MulOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - MulOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - MulOpGenericAdaptorBase(MulOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class MulOpGenericAdaptor : public detail::MulOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::MulOpGenericAdaptorBase; -public: - MulOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - MulOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : MulOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - MulOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getLhs() { - return (*getODSOperands(0).begin()); - } - - ValueT getRhs() { - return (*getODSOperands(1).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class MulOpAdaptor : public MulOpGenericAdaptor<::mlir::ValueRange> { -public: - using MulOpGenericAdaptor::MulOpGenericAdaptor; - MulOpAdaptor(MulOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class MulOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::NOperands<2>::Impl, ::mlir::OpTrait::OpInvariants> { -public: - using Op::Op; - using Op::print; - using Adaptor = MulOpAdaptor; - template - using GenericAdaptor = MulOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.mul"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getLhs(); - ::mlir::TypedValue<::mlir::TensorType> getRhs(); - ::mlir::OpOperand &getLhsMutable(); - ::mlir::OpOperand &getRhsMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, Value lhs, Value rhs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value lhs, ::mlir::Value rhs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &p); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::MulOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::PrintOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class PrintOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - PrintOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - PrintOpGenericAdaptorBase(PrintOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class PrintOpGenericAdaptor : public detail::PrintOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::PrintOpGenericAdaptorBase; -public: - PrintOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - PrintOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : PrintOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - PrintOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getInput() { - return (*getODSOperands(0).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class PrintOpAdaptor : public PrintOpGenericAdaptor<::mlir::ValueRange> { -public: - using PrintOpGenericAdaptor::PrintOpGenericAdaptor; - PrintOpAdaptor(PrintOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class PrintOp : public ::mlir::Op { -public: - using Op::Op; - using Op::print; - using Adaptor = PrintOpAdaptor; - template - using GenericAdaptor = PrintOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.print"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getInput(); - ::mlir::OpOperand &getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::PrintOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ReshapeOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class ReshapeOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - ReshapeOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - ReshapeOpGenericAdaptorBase(ReshapeOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class ReshapeOpGenericAdaptor : public detail::ReshapeOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::ReshapeOpGenericAdaptorBase; -public: - ReshapeOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - ReshapeOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : ReshapeOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - ReshapeOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getInput() { - return (*getODSOperands(0).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class ReshapeOpAdaptor : public ReshapeOpGenericAdaptor<::mlir::ValueRange> { -public: - using ReshapeOpGenericAdaptor::ReshapeOpGenericAdaptor; - ReshapeOpAdaptor(ReshapeOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class ReshapeOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::OneOperand, ::mlir::OpTrait::OpInvariants> { -public: - using Op::Op; - using Op::print; - using Adaptor = ReshapeOpAdaptor; - template - using GenericAdaptor = ReshapeOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.reshape"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getInput(); - ::mlir::OpOperand &getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::ReshapeOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ReturnOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class ReturnOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - ReturnOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - ReturnOpGenericAdaptorBase(ReturnOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class ReturnOpGenericAdaptor : public detail::ReturnOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::ReturnOpGenericAdaptorBase; -public: - ReturnOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - ReturnOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : ReturnOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - ReturnOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - RangeT getInput() { - return getODSOperands(0); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class ReturnOpAdaptor : public ReturnOpGenericAdaptor<::mlir::ValueRange> { -public: - using ReturnOpGenericAdaptor::ReturnOpGenericAdaptor; - ReturnOpAdaptor(ReturnOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class ReturnOp : public ::mlir::Op::Impl, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait, ::mlir::OpTrait::IsTerminator> { -public: - using Op::Op; - using Op::print; - using Adaptor = ReturnOpAdaptor; - template - using GenericAdaptor = ReturnOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.return"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::Operation::operand_range getInput(); - ::mlir::MutableOperandRange getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - ::mlir::LogicalResult verify(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: - bool hasOperand() { return getNumOperands() != 0; } -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::ReturnOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::TransposeOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class TransposeOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - TransposeOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - TransposeOpGenericAdaptorBase(TransposeOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class TransposeOpGenericAdaptor : public detail::TransposeOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::TransposeOpGenericAdaptorBase; -public: - TransposeOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - TransposeOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : TransposeOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - TransposeOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getInput() { - return (*getODSOperands(0).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class TransposeOpAdaptor : public TransposeOpGenericAdaptor<::mlir::ValueRange> { -public: - using TransposeOpGenericAdaptor::TransposeOpGenericAdaptor; - TransposeOpAdaptor(TransposeOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class TransposeOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::OneOperand, ::mlir::OpTrait::OpInvariants> { -public: - using Op::Op; - using Op::print; - using Adaptor = TransposeOpAdaptor; - template - using GenericAdaptor = TransposeOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.transpose"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getInput(); - ::mlir::OpOperand &getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - ::mlir::LogicalResult verify(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::TransposeOp) - - -#endif // GET_OP_CLASSES - diff --git a/Ch2/include/toy/run.sh b/Ch2/include/toy/run.sh deleted file mode 100644 index b123ce1..0000000 --- a/Ch2/include/toy/run.sh +++ /dev/null @@ -1,4 +0,0 @@ -mlir-tblgen-18 -gen-op-decls -I /usr/lib/llvm-18/include Ops.td > Ops.h.inc -mlir-tblgen-18 -gen-op-defs -I /usr/lib/llvm-18/include Ops.td > Ops.cpp.inc -mlir-tblgen-18 -gen-dialect-decls -I /usr/lib/llvm-18/include Ops.td > Dialect.h.inc -mlir-tblgen-18 -gen-dialect-defs -I /usr/lib/llvm-18/include Ops.td > Dialect.cpp.inc \ No newline at end of file diff --git a/Ch3/CMakeLists.txt b/Ch3/CMakeLists.txt index d8b6bf9..565f3c4 100644 --- a/Ch3/CMakeLists.txt +++ b/Ch3/CMakeLists.txt @@ -6,20 +6,20 @@ set(LLVM_LINK_COMPONENTS Support ) -# set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td) -# mlir_tablegen(ToyCombine.inc -gen-rewriters) -# add_public_tablegen_target(ToyCh3CombineIncGen) +set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td) +mlir_tablegen(ToyCombine.inc -gen-rewriters) +add_public_tablegen_target(ToyCh3CombineIncGen) -add_executable(toyc-ch3 +add_toy_chapter(toyc-ch3 toyc.cpp parser/AST.cpp mlir/MLIRGen.cpp mlir/Dialect.cpp mlir/ToyCombine.cpp - # DEPENDS - # ToyCh3OpsIncGen - # ToyCh3CombineIncGen + DEPENDS + ToyCh3OpsIncGen + ToyCh3CombineIncGen ) include_directories(${CMAKE_CURRENT_BINARY_DIR}) diff --git a/Ch3/include/toy/CMakeLists.txt b/Ch3/include/toy/CMakeLists.txt index b8baa27..a233f5d 100644 --- a/Ch3/include/toy/CMakeLists.txt +++ b/Ch3/include/toy/CMakeLists.txt @@ -1,6 +1,6 @@ -# set(LLVM_TARGET_DEFINITIONS Ops.td) -# mlir_tablegen(Ops.h.inc -gen-op-decls) -# mlir_tablegen(Ops.cpp.inc -gen-op-defs) -# mlir_tablegen(Dialect.h.inc -gen-dialect-decls) -# mlir_tablegen(Dialect.cpp.inc -gen-dialect-defs) -# add_public_tablegen_target(ToyCh3OpsIncGen) +set(LLVM_TARGET_DEFINITIONS Ops.td) +mlir_tablegen(Ops.h.inc -gen-op-decls) +mlir_tablegen(Ops.cpp.inc -gen-op-defs) +mlir_tablegen(Dialect.h.inc -gen-dialect-decls) +mlir_tablegen(Dialect.cpp.inc -gen-dialect-defs) +add_public_tablegen_target(ToyCh3OpsIncGen) diff --git a/Ch3/include/toy/Dialect.cpp.inc b/Ch3/include/toy/Dialect.cpp.inc deleted file mode 100644 index 8cbc772..0000000 --- a/Ch3/include/toy/Dialect.cpp.inc +++ /dev/null @@ -1,23 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Dialect Definitions *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: Ops.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::ToyDialect) -namespace mlir { -namespace toy { - -ToyDialect::ToyDialect(::mlir::MLIRContext *context) - : ::mlir::Dialect(getDialectNamespace(), context, ::mlir::TypeID::get()) { - - initialize(); -} - -ToyDialect::~ToyDialect() = default; - -} // namespace toy -} // namespace mlir diff --git a/Ch3/include/toy/Dialect.h.inc b/Ch3/include/toy/Dialect.h.inc deleted file mode 100644 index f19d867..0000000 --- a/Ch3/include/toy/Dialect.h.inc +++ /dev/null @@ -1,26 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Dialect Declarations *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: Ops.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -namespace mlir { -namespace toy { - -class ToyDialect : public ::mlir::Dialect { - explicit ToyDialect(::mlir::MLIRContext *context); - - void initialize(); - friend class ::mlir::MLIRContext; -public: - ~ToyDialect() override; - static constexpr ::llvm::StringLiteral getDialectNamespace() { - return ::llvm::StringLiteral("toy"); - } -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::ToyDialect) diff --git a/Ch3/include/toy/Ops.cpp.inc b/Ch3/include/toy/Ops.cpp.inc deleted file mode 100644 index 555fb7a..0000000 --- a/Ch3/include/toy/Ops.cpp.inc +++ /dev/null @@ -1,2061 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Op Definitions *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: Ops.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -#ifdef GET_OP_LIST -#undef GET_OP_LIST - -::mlir::toy::AddOp, -::mlir::toy::ConstantOp, -::mlir::toy::FuncOp, -::mlir::toy::GenericCallOp, -::mlir::toy::MulOp, -::mlir::toy::PrintOp, -::mlir::toy::ReshapeOp, -::mlir::toy::ReturnOp, -::mlir::toy::TransposeOp -#endif // GET_OP_LIST - -#ifdef GET_OP_CLASSES -#undef GET_OP_CLASSES - - -//===----------------------------------------------------------------------===// -// Local Utility Method Definitions -//===----------------------------------------------------------------------===// - -namespace mlir { -namespace toy { - -static ::mlir::LogicalResult __mlir_ods_local_type_constraint_Ops0( - ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, - unsigned valueIndex) { - if (!(((::llvm::isa<::mlir::TensorType>(type))) && ([](::mlir::Type elementType) { return (elementType.isF64()); }(::llvm::cast<::mlir::ShapedType>(type).getElementType())))) { - return op->emitOpError(valueKind) << " #" << valueIndex - << " must be tensor of 64-bit float values, but got " << type; - } - return ::mlir::success(); -} - -static ::mlir::LogicalResult __mlir_ods_local_type_constraint_Ops1( - ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, - unsigned valueIndex) { - if (!(((::llvm::isa<::mlir::TensorType>(type))) && ([](::mlir::Type elementType) { return (elementType.isF64()); }(::llvm::cast<::mlir::ShapedType>(type).getElementType())))) { - return op->emitOpError(valueKind) << " #" << valueIndex - << " must be variadic of tensor of 64-bit float values, but got " << type; - } - return ::mlir::success(); -} - -static ::mlir::LogicalResult __mlir_ods_local_type_constraint_Ops2( - ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, - unsigned valueIndex) { - if (!((((::llvm::isa<::mlir::RankedTensorType>(type))) && ((::llvm::cast<::mlir::ShapedType>(type).hasStaticShape()))) && ([](::mlir::Type elementType) { return (elementType.isF64()); }(::llvm::cast<::mlir::ShapedType>(type).getElementType())))) { - return op->emitOpError(valueKind) << " #" << valueIndex - << " must be statically shaped tensor of 64-bit float values, but got " << type; - } - return ::mlir::success(); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops0( - ::mlir::Attribute attr, ::llvm::StringRef attrName, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { - if (attr && !((::llvm::isa<::mlir::DenseFPElementsAttr>(attr) &&::llvm::cast<::mlir::DenseElementsAttr>(attr).getType().getElementType().isF64()))) - return emitError() << "attribute '" << attrName - << "' failed to satisfy constraint: 64-bit float elements attribute"; - return ::mlir::success(); -} -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops0( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops0(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops1( - ::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 ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops1( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops1(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops2( - ::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 ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops2( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops2(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops3( - ::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 ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops3( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops3(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops4( - ::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 ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops4( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops4(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_region_constraint_Ops0( - ::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 toy -} // namespace mlir -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::AddOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -AddOpGenericAdaptorBase::AddOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.add", odsAttrs.getContext()); -} - -AddOpGenericAdaptorBase::AddOpGenericAdaptorBase(AddOp op) : AddOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair AddOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr AddOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -AddOpAdaptor::AddOpAdaptor(AddOp op) : AddOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult AddOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair AddOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range AddOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> AddOp::getLhs() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::TypedValue<::mlir::TensorType> AddOp::getRhs() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(1).begin()); -} - -::mlir::OpOperand &AddOp::getLhsMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -::mlir::OpOperand &AddOp::getRhsMutable() { - auto range = getODSOperandIndexAndLength(1); - return getOperation()->getOpOperand(range.first); -} - -std::pair AddOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range AddOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void AddOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value lhs, ::mlir::Value rhs) { - odsState.addOperands(lhs); - odsState.addOperands(rhs); - odsState.addTypes(resultType0); -} - -void AddOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs) { - odsState.addOperands(lhs); - odsState.addOperands(rhs); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void AddOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 2u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult AddOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*this, v.getType(), "operand", index++))) - return ::mlir::failure(); - } - auto valueGroup1 = getODSOperands(1); - - for (auto v : valueGroup1) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult AddOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -void AddOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::AddOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ConstantOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -ConstantOpGenericAdaptorBase::ConstantOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.constant", odsAttrs.getContext()); -} - -ConstantOpGenericAdaptorBase::ConstantOpGenericAdaptorBase(ConstantOp op) : ConstantOpGenericAdaptorBase(op->getDiscardableAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair ConstantOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr ConstantOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -::mlir::DenseElementsAttr ConstantOpGenericAdaptorBase::getValueAttr() { - auto attr = ::llvm::cast<::mlir::DenseElementsAttr>(getProperties().value); - return attr; -} - -::mlir::DenseElementsAttr ConstantOpGenericAdaptorBase::getValue() { - auto attr = getValueAttr(); - return attr; -} - -} // namespace detail -ConstantOpAdaptor::ConstantOpAdaptor(ConstantOp op) : ConstantOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult ConstantOpAdaptor::verify(::mlir::Location loc) { - auto tblgen_value = getProperties().value; (void)tblgen_value; - if (!tblgen_value) return emitError(loc, "'toy.constant' op ""requires attribute 'value'"); - - if (tblgen_value && !((::llvm::isa<::mlir::DenseFPElementsAttr>(tblgen_value) &&::llvm::cast<::mlir::DenseElementsAttr>(tblgen_value).getType().getElementType().isF64()))) - return emitError(loc, "'toy.constant' op ""attribute 'value' failed to satisfy constraint: 64-bit float elements attribute"); - return ::mlir::success(); -} - -std::pair ConstantOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range ConstantOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -std::pair ConstantOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range ConstantOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::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 || /*isRequired=*/true) { - if (!attr) { - emitError() << "expected key entry for value in DictionaryAttr to set " - "Properties."; - return ::mlir::failure(); - } - 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) { - 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); -} - -::mlir::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_Ops0(attr, "value", emitError))) - return ::mlir::failure(); - } - return ::mlir::success(); -} - -::mlir::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); -} - -::mlir::DenseElementsAttr ConstantOp::getValueAttr() { - return ::llvm::cast<::mlir::DenseElementsAttr>(getProperties().value); -} - -::mlir::DenseElementsAttr ConstantOp::getValue() { - auto attr = getValueAttr(); - return attr; -} - -void ConstantOp::setValueAttr(::mlir::DenseElementsAttr attr) { - (*this)->setAttr(getValueAttrName(), attr); -} - -void ConstantOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, DenseElementsAttr value) { - build(odsBuilder, odsState, value.getType(), value); - -} - -void ConstantOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::DenseElementsAttr value) { - odsState.getOrAddProperties().value = value; - odsState.addTypes(resultType0); -} - -void ConstantOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::DenseElementsAttr value) { - odsState.getOrAddProperties().value = value; - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -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); -} - -::mlir::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_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult ConstantOp::verifyInvariants() { - if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) - return ::mlir::success(); - return ::mlir::failure(); -} - -void ConstantOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::ConstantOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::FuncOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -FuncOpGenericAdaptorBase::FuncOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.func", odsAttrs.getContext()); -} - -FuncOpGenericAdaptorBase::FuncOpGenericAdaptorBase(FuncOp op) : FuncOpGenericAdaptorBase(op->getDiscardableAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair FuncOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr FuncOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -::mlir::StringAttr FuncOpGenericAdaptorBase::getSymNameAttr() { - auto attr = ::llvm::cast<::mlir::StringAttr>(getProperties().sym_name); - return attr; -} - -::llvm::StringRef FuncOpGenericAdaptorBase::getSymName() { - auto attr = getSymNameAttr(); - return attr.getValue(); -} - -::mlir::TypeAttr FuncOpGenericAdaptorBase::getFunctionTypeAttr() { - auto attr = ::llvm::cast<::mlir::TypeAttr>(getProperties().function_type); - return attr; -} - -::mlir::FunctionType FuncOpGenericAdaptorBase::getFunctionType() { - auto attr = getFunctionTypeAttr(); - return ::llvm::cast<::mlir::FunctionType>(attr.getValue()); -} - -::mlir::ArrayAttr FuncOpGenericAdaptorBase::getArgAttrsAttr() { - auto attr = ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(getProperties().arg_attrs); - return attr; -} - -::std::optional< ::mlir::ArrayAttr > FuncOpGenericAdaptorBase::getArgAttrs() { - auto attr = getArgAttrsAttr(); - return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); -} - -::mlir::ArrayAttr FuncOpGenericAdaptorBase::getResAttrsAttr() { - auto attr = ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(getProperties().res_attrs); - return attr; -} - -::std::optional< ::mlir::ArrayAttr > FuncOpGenericAdaptorBase::getResAttrs() { - auto attr = getResAttrsAttr(); - return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); -} - -::mlir::Region &FuncOpGenericAdaptorBase::getBody() { - return *odsRegions[0]; -} - -::mlir::RegionRange FuncOpGenericAdaptorBase::getRegions() { - return odsRegions; -} - -} // namespace detail -FuncOpAdaptor::FuncOpAdaptor(FuncOp op) : FuncOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::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, "'toy.func' op ""requires attribute 'function_type'"); - 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, "'toy.func' op ""requires attribute 'sym_name'"); - - if (tblgen_sym_name && !((::llvm::isa<::mlir::StringAttr>(tblgen_sym_name)))) - return emitError(loc, "'toy.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, "'toy.func' op ""attribute 'function_type' failed to satisfy constraint: type attribute of function type"); - - 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, "'toy.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, "'toy.func' op ""attribute 'res_attrs' failed to satisfy constraint: Array of dictionary attributes"); - return ::mlir::success(); -} - -std::pair FuncOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range FuncOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -std::pair FuncOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range FuncOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::Region &FuncOp::getBody() { - return (*this)->getRegion(0); -} - -::mlir::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 || /*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.function_type; - auto attr = dict.get("function_type"); - 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.res_attrs; - auto attr = dict.get("res_attrs"); - 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.sym_name; - auto attr = dict.get("sym_name"); - 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(); - } - } - } - 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.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)); - } - - if (!attrs.empty()) - return odsBuilder.getDictionaryAttr(attrs); - return {}; -} - -llvm::hash_code FuncOp::computePropertiesHash(const Properties &prop) { - return llvm::hash_combine( - llvm::hash_value(prop.arg_attrs.getAsOpaquePointer()), - llvm::hash_value(prop.function_type.getAsOpaquePointer()), - llvm::hash_value(prop.res_attrs.getAsOpaquePointer()), - llvm::hash_value(prop.sym_name.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 == "res_attrs") - return prop.res_attrs; - - if (name == "sym_name") - return prop.sym_name; - 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 == "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; - } -} - -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.res_attrs) attrs.append("res_attrs", prop.res_attrs); - - if (prop.sym_name) attrs.append("sym_name", prop.sym_name); -} - -::mlir::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_Ops3(attr, "arg_attrs", emitError))) - return ::mlir::failure(); - } - - { - ::mlir::Attribute attr = attrs.get(getFunctionTypeAttrName(opName)); - if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_Ops2(attr, "function_type", emitError))) - return ::mlir::failure(); - } - - { - ::mlir::Attribute attr = attrs.get(getResAttrsAttrName(opName)); - if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_Ops3(attr, "res_attrs", emitError))) - return ::mlir::failure(); - } - - { - ::mlir::Attribute attr = attrs.get(getSymNameAttrName(opName)); - if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_Ops1(attr, "sym_name", emitError))) - return ::mlir::failure(); - } - return ::mlir::success(); -} - -::mlir::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.res_attrs))) - return ::mlir::failure(); - - if (::mlir::failed(reader.readAttribute(prop.sym_name))) - 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.res_attrs); - writer.writeAttribute(prop.sym_name); -} - -::mlir::StringAttr FuncOp::getSymNameAttr() { - return ::llvm::cast<::mlir::StringAttr>(getProperties().sym_name); -} - -::llvm::StringRef FuncOp::getSymName() { - auto attr = getSymNameAttr(); - return attr.getValue(); -} - -::mlir::TypeAttr FuncOp::getFunctionTypeAttr() { - return ::llvm::cast<::mlir::TypeAttr>(getProperties().function_type); -} - -::mlir::FunctionType FuncOp::getFunctionType() { - auto attr = getFunctionTypeAttr(); - return ::llvm::cast<::mlir::FunctionType>(attr.getValue()); -} - -::mlir::ArrayAttr FuncOp::getArgAttrsAttr() { - return ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(getProperties().arg_attrs); -} - -::std::optional< ::mlir::ArrayAttr > FuncOp::getArgAttrs() { - auto attr = getArgAttrsAttr(); - return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); -} - -::mlir::ArrayAttr FuncOp::getResAttrsAttr() { - return ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(getProperties().res_attrs); -} - -::std::optional< ::mlir::ArrayAttr > FuncOp::getResAttrs() { - auto attr = getResAttrsAttr(); - return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); -} - -void FuncOp::setSymNameAttr(::mlir::StringAttr attr) { - (*this)->setAttr(getSymNameAttrName(), attr); -} - -void FuncOp::setSymName(::llvm::StringRef attrValue) { - (*this)->setAttr(getSymNameAttrName(), ::mlir::Builder((*this)->getContext()).getStringAttr(attrValue)); -} - -void FuncOp::setFunctionTypeAttr(::mlir::TypeAttr attr) { - (*this)->setAttr(getFunctionTypeAttrName(), attr); -} - -void FuncOp::setFunctionType(::mlir::FunctionType attrValue) { - (*this)->setAttr(getFunctionTypeAttrName(), ::mlir::TypeAttr::get(attrValue)); -} - -void FuncOp::setArgAttrsAttr(::mlir::ArrayAttr attr) { - (*this)->setAttr(getArgAttrsAttrName(), attr); -} - -void FuncOp::setResAttrsAttr(::mlir::ArrayAttr attr) { - (*this)->setAttr(getResAttrsAttrName(), attr); -} - -::mlir::Attribute FuncOp::removeArgAttrsAttr() { - auto &attr = getProperties().arg_attrs; - attr = {}; - return attr; -} - -::mlir::Attribute FuncOp::removeResAttrsAttr() { - auto &attr = getProperties().res_attrs; - attr = {}; - return attr; -} - -::mlir::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_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'"); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops1(*this, tblgen_sym_name, "sym_name"))) - return ::mlir::failure(); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops2(*this, tblgen_function_type, "function_type"))) - return ::mlir::failure(); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops3(*this, tblgen_arg_attrs, "arg_attrs"))) - return ::mlir::failure(); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops3(*this, tblgen_res_attrs, "res_attrs"))) - return ::mlir::failure(); - { - unsigned index = 0; (void)index; - - for (auto ®ion : ::llvm::MutableArrayRef((*this)->getRegion(0))) - if (::mlir::failed(__mlir_ods_local_region_constraint_Ops0(*this, region, "body", index++))) - return ::mlir::failure(); - } - return ::mlir::success(); -} - -::mlir::LogicalResult FuncOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::FuncOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::GenericCallOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -GenericCallOpGenericAdaptorBase::GenericCallOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.generic_call", odsAttrs.getContext()); -} - -GenericCallOpGenericAdaptorBase::GenericCallOpGenericAdaptorBase(GenericCallOp op) : GenericCallOpGenericAdaptorBase(op->getDiscardableAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair GenericCallOpGenericAdaptorBase::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}; -} - -::mlir::DictionaryAttr GenericCallOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -::mlir::FlatSymbolRefAttr GenericCallOpGenericAdaptorBase::getCalleeAttr() { - auto attr = ::llvm::cast<::mlir::FlatSymbolRefAttr>(getProperties().callee); - return attr; -} - -::llvm::StringRef GenericCallOpGenericAdaptorBase::getCallee() { - auto attr = getCalleeAttr(); - return attr.getValue(); -} - -} // namespace detail -GenericCallOpAdaptor::GenericCallOpAdaptor(GenericCallOp op) : GenericCallOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult GenericCallOpAdaptor::verify(::mlir::Location loc) { - auto tblgen_callee = getProperties().callee; (void)tblgen_callee; - if (!tblgen_callee) return emitError(loc, "'toy.generic_call' op ""requires attribute 'callee'"); - - if (tblgen_callee && !((::llvm::isa<::mlir::FlatSymbolRefAttr>(tblgen_callee)))) - return emitError(loc, "'toy.generic_call' op ""attribute 'callee' failed to satisfy constraint: flat symbol reference attribute"); - return ::mlir::success(); -} - -std::pair GenericCallOp::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::Operation::operand_range GenericCallOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::Operation::operand_range GenericCallOp::getInputs() { - return getODSOperands(0); -} - -::mlir::MutableOperandRange GenericCallOp::getInputsMutable() { - auto range = getODSOperandIndexAndLength(0); - auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); - return mutableRange; -} - -std::pair GenericCallOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range GenericCallOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::LogicalResult GenericCallOp::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.callee; - auto attr = dict.get("callee"); - if (attr || /*isRequired=*/true) { - if (!attr) { - emitError() << "expected key entry for callee in DictionaryAttr to set " - "Properties."; - return ::mlir::failure(); - } - auto convertedAttr = ::llvm::dyn_cast>(attr); - if (convertedAttr) { - propStorage = convertedAttr; - } else { - emitError() << "Invalid attribute `callee` in property conversion: " << attr; - return ::mlir::failure(); - } - } - } - return ::mlir::success(); -} - -::mlir::Attribute GenericCallOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) { - ::mlir::SmallVector<::mlir::NamedAttribute> attrs; - ::mlir::Builder odsBuilder{ctx}; - - { - const auto &propStorage = prop.callee; - if (propStorage) - attrs.push_back(odsBuilder.getNamedAttr("callee", - propStorage)); - } - - if (!attrs.empty()) - return odsBuilder.getDictionaryAttr(attrs); - return {}; -} - -llvm::hash_code GenericCallOp::computePropertiesHash(const Properties &prop) { - return llvm::hash_combine( - llvm::hash_value(prop.callee.getAsOpaquePointer())); -} - -std::optional GenericCallOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { - if (name == "callee") - return prop.callee; - return std::nullopt; -} - -void GenericCallOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { - if (name == "callee") { - prop.callee = ::llvm::dyn_cast_or_null>(value); - return; - } -} - -void GenericCallOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { - if (prop.callee) attrs.append("callee", prop.callee); -} - -::mlir::LogicalResult GenericCallOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { - { - ::mlir::Attribute attr = attrs.get(getCalleeAttrName(opName)); - if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_Ops4(attr, "callee", emitError))) - return ::mlir::failure(); - } - return ::mlir::success(); -} - -::mlir::LogicalResult GenericCallOp::readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state) { - auto &prop = state.getOrAddProperties(); (void)prop; - if (::mlir::failed(reader.readAttribute(prop.callee))) - return ::mlir::failure(); - return ::mlir::success(); -} - -void GenericCallOp::writeProperties(::mlir::DialectBytecodeWriter &writer) { - auto &prop = getProperties(); (void)prop; - writer.writeAttribute(prop.callee); -} - -::mlir::FlatSymbolRefAttr GenericCallOp::getCalleeAttr() { - return ::llvm::cast<::mlir::FlatSymbolRefAttr>(getProperties().callee); -} - -::llvm::StringRef GenericCallOp::getCallee() { - auto attr = getCalleeAttr(); - return attr.getValue(); -} - -void GenericCallOp::setCalleeAttr(::mlir::FlatSymbolRefAttr attr) { - (*this)->setAttr(getCalleeAttrName(), attr); -} - -void GenericCallOp::setCallee(::llvm::StringRef attrValue) { - (*this)->setAttr(getCalleeAttrName(), ::mlir::SymbolRefAttr::get(::mlir::Builder((*this)->getContext()).getContext(), attrValue)); -} - -void GenericCallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::FlatSymbolRefAttr callee, ::mlir::ValueRange inputs) { - odsState.addOperands(inputs); - odsState.getOrAddProperties().callee = callee; - odsState.addTypes(resultType0); -} - -void GenericCallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::FlatSymbolRefAttr callee, ::mlir::ValueRange inputs) { - odsState.addOperands(inputs); - odsState.getOrAddProperties().callee = callee; - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void GenericCallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::llvm::StringRef callee, ::mlir::ValueRange inputs) { - odsState.addOperands(inputs); - odsState.getOrAddProperties().callee = ::mlir::SymbolRefAttr::get(odsBuilder.getContext(), callee); - odsState.addTypes(resultType0); -} - -void GenericCallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::llvm::StringRef callee, ::mlir::ValueRange inputs) { - odsState.addOperands(inputs); - odsState.getOrAddProperties().callee = ::mlir::SymbolRefAttr::get(odsBuilder.getContext(), callee); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void GenericCallOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult GenericCallOp::verifyInvariantsImpl() { - auto tblgen_callee = getProperties().callee; (void)tblgen_callee; - if (!tblgen_callee) return emitOpError("requires attribute 'callee'"); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops4(*this, tblgen_callee, "callee"))) - return ::mlir::failure(); - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops1(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult GenericCallOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -::mlir::ParseResult GenericCallOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::FlatSymbolRefAttr calleeAttr; - ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> inputsOperands; - ::llvm::SMLoc inputsOperandsLoc; - (void)inputsOperandsLoc; - ::llvm::ArrayRef<::mlir::Type> inputsTypes; - ::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(); - - inputsOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperandList(inputsOperands)) - 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 inputs__allResult_functionType; - if (parser.parseType(inputs__allResult_functionType)) - return ::mlir::failure(); - inputsTypes = inputs__allResult_functionType.getInputs(); - allResultTypes = inputs__allResult_functionType.getResults(); - result.addTypes(allResultTypes); - if (parser.resolveOperands(inputsOperands, inputsTypes, inputsOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void GenericCallOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << ' '; - _odsPrinter.printAttributeWithoutType(getCalleeAttr()); - _odsPrinter << "("; - _odsPrinter << getInputs(); - _odsPrinter << ")"; - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - elidedAttrs.push_back("callee"); - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - _odsPrinter.printFunctionalType(getInputs().getTypes(), getOperation()->getResultTypes()); -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::GenericCallOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::MulOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -MulOpGenericAdaptorBase::MulOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.mul", odsAttrs.getContext()); -} - -MulOpGenericAdaptorBase::MulOpGenericAdaptorBase(MulOp op) : MulOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair MulOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr MulOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -MulOpAdaptor::MulOpAdaptor(MulOp op) : MulOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult MulOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair MulOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range MulOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> MulOp::getLhs() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::TypedValue<::mlir::TensorType> MulOp::getRhs() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(1).begin()); -} - -::mlir::OpOperand &MulOp::getLhsMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -::mlir::OpOperand &MulOp::getRhsMutable() { - auto range = getODSOperandIndexAndLength(1); - return getOperation()->getOpOperand(range.first); -} - -std::pair MulOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range MulOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void MulOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value lhs, ::mlir::Value rhs) { - odsState.addOperands(lhs); - odsState.addOperands(rhs); - odsState.addTypes(resultType0); -} - -void MulOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs) { - odsState.addOperands(lhs); - odsState.addOperands(rhs); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void MulOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 2u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult MulOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*this, v.getType(), "operand", index++))) - return ::mlir::failure(); - } - auto valueGroup1 = getODSOperands(1); - - for (auto v : valueGroup1) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult MulOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -void MulOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::MulOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::PrintOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -PrintOpGenericAdaptorBase::PrintOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.print", odsAttrs.getContext()); -} - -PrintOpGenericAdaptorBase::PrintOpGenericAdaptorBase(PrintOp op) : PrintOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair PrintOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr PrintOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -PrintOpAdaptor::PrintOpAdaptor(PrintOp op) : PrintOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult PrintOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair PrintOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range PrintOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> PrintOp::getInput() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::OpOperand &PrintOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -std::pair PrintOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range PrintOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void PrintOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value input) { - odsState.addOperands(input); -} - -void PrintOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input) { - odsState.addOperands(input); - assert(resultTypes.size() == 0u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void PrintOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 1u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 0u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult PrintOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*this, v.getType(), "operand", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult PrintOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -::mlir::ParseResult PrintOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::OpAsmParser::UnresolvedOperand inputRawOperands[1]; - ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> inputOperands(inputRawOperands); ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::mlir::Type inputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> inputTypes(inputRawTypes); - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperand(inputRawOperands[0])) - return ::mlir::failure(); - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.parseColon()) - return ::mlir::failure(); - - { - ::mlir::TensorType type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - inputRawTypes[0] = type; - } - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void PrintOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << ' '; - _odsPrinter << getInput(); - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - { - auto type = getInput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::TensorType>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::PrintOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ReshapeOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -ReshapeOpGenericAdaptorBase::ReshapeOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.reshape", odsAttrs.getContext()); -} - -ReshapeOpGenericAdaptorBase::ReshapeOpGenericAdaptorBase(ReshapeOp op) : ReshapeOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair ReshapeOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr ReshapeOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -ReshapeOpAdaptor::ReshapeOpAdaptor(ReshapeOp op) : ReshapeOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult ReshapeOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair ReshapeOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range ReshapeOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> ReshapeOp::getInput() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::OpOperand &ReshapeOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -std::pair ReshapeOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range ReshapeOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void ReshapeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value input) { - odsState.addOperands(input); - odsState.addTypes(resultType0); -} - -void ReshapeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input) { - odsState.addOperands(input); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void ReshapeOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 1u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult ReshapeOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops2(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult ReshapeOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -::mlir::ParseResult ReshapeOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::OpAsmParser::UnresolvedOperand inputRawOperands[1]; - ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> inputOperands(inputRawOperands); ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::mlir::Type inputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> inputTypes(inputRawTypes); - ::llvm::SmallVector<::mlir::Type, 1> allResultTypes; - if (parser.parseLParen()) - return ::mlir::failure(); - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperand(inputRawOperands[0])) - return ::mlir::failure(); - if (parser.parseColon()) - return ::mlir::failure(); - - { - ::mlir::TensorType type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - inputRawTypes[0] = type; - } - if (parser.parseRParen()) - return ::mlir::failure(); - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.parseKeyword("to")) - return ::mlir::failure(); - - if (parser.parseTypeList(allResultTypes)) - return ::mlir::failure(); - result.addTypes(allResultTypes); - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void ReshapeOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << "("; - _odsPrinter << getInput(); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - { - auto type = getInput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::TensorType>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } - _odsPrinter << ")"; - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << "to"; - _odsPrinter << ' '; - _odsPrinter << getOperation()->getResultTypes(); -} - -void ReshapeOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::ReshapeOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ReturnOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -ReturnOpGenericAdaptorBase::ReturnOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.return", odsAttrs.getContext()); -} - -ReturnOpGenericAdaptorBase::ReturnOpGenericAdaptorBase(ReturnOp op) : ReturnOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), 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}; -} - -::mlir::DictionaryAttr ReturnOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -ReturnOpAdaptor::ReturnOpAdaptor(ReturnOp op) : ReturnOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::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::Operation::operand_range ReturnOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::Operation::operand_range ReturnOp::getInput() { - return getODSOperands(0); -} - -::mlir::MutableOperandRange ReturnOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); - return mutableRange; -} - -std::pair ReturnOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range ReturnOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void ReturnOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState) { - build(odsBuilder, odsState, std::nullopt); -} - -void ReturnOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange input) { - odsState.addOperands(input); -} - -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); -} - -::mlir::LogicalResult ReturnOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops1(*this, v.getType(), "operand", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult ReturnOp::verifyInvariants() { - if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) - return ::mlir::success(); - return ::mlir::failure(); -} - -::mlir::ParseResult ReturnOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> inputOperands; - ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::llvm::SmallVector<::mlir::Type, 1> inputTypes; - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperandList(inputOperands)) - return ::mlir::failure(); - if (!inputOperands.empty()) { - if (parser.parseColon()) - return ::mlir::failure(); - - if (parser.parseTypeList(inputTypes)) - return ::mlir::failure(); - } - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void ReturnOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - if (!getInput().empty()) { - _odsPrinter << ' '; - _odsPrinter << getInput(); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - _odsPrinter << getInput().getTypes(); - } - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); -} - -void ReturnOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::ReturnOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::TransposeOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -TransposeOpGenericAdaptorBase::TransposeOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.transpose", odsAttrs.getContext()); -} - -TransposeOpGenericAdaptorBase::TransposeOpGenericAdaptorBase(TransposeOp op) : TransposeOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair TransposeOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr TransposeOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -TransposeOpAdaptor::TransposeOpAdaptor(TransposeOp op) : TransposeOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult TransposeOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair TransposeOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range TransposeOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> TransposeOp::getInput() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::OpOperand &TransposeOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -std::pair TransposeOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range TransposeOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void TransposeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value input) { - odsState.addOperands(input); - odsState.addTypes(resultType0); -} - -void TransposeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input) { - odsState.addOperands(input); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void TransposeOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 1u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult TransposeOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult TransposeOp::verifyInvariants() { - if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) - return ::mlir::success(); - return ::mlir::failure(); -} - -::mlir::ParseResult TransposeOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::OpAsmParser::UnresolvedOperand inputRawOperands[1]; - ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> inputOperands(inputRawOperands); ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::mlir::Type inputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> inputTypes(inputRawTypes); - ::llvm::SmallVector<::mlir::Type, 1> allResultTypes; - if (parser.parseLParen()) - return ::mlir::failure(); - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperand(inputRawOperands[0])) - return ::mlir::failure(); - if (parser.parseColon()) - return ::mlir::failure(); - - { - ::mlir::TensorType type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - inputRawTypes[0] = type; - } - if (parser.parseRParen()) - return ::mlir::failure(); - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.parseKeyword("to")) - return ::mlir::failure(); - - if (parser.parseTypeList(allResultTypes)) - return ::mlir::failure(); - result.addTypes(allResultTypes); - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void TransposeOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << "("; - _odsPrinter << getInput(); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - { - auto type = getInput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::TensorType>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } - _odsPrinter << ")"; - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << "to"; - _odsPrinter << ' '; - _odsPrinter << getOperation()->getResultTypes(); -} - -void TransposeOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::TransposeOp) - - -#endif // GET_OP_CLASSES - diff --git a/Ch3/include/toy/Ops.h.inc b/Ch3/include/toy/Ops.h.inc deleted file mode 100644 index 65c4be8..0000000 --- a/Ch3/include/toy/Ops.h.inc +++ /dev/null @@ -1,1247 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Op Declarations *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: Ops.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -#if defined(GET_OP_CLASSES) || defined(GET_OP_FWD_DEFINES) -#undef GET_OP_FWD_DEFINES -namespace mlir { -namespace toy { -class AddOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class ConstantOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class FuncOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class GenericCallOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class MulOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class PrintOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class ReshapeOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class ReturnOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class TransposeOp; -} // namespace toy -} // namespace mlir -#endif - -#ifdef GET_OP_CLASSES -#undef GET_OP_CLASSES - - -//===----------------------------------------------------------------------===// -// Local Utility Method Definitions -//===----------------------------------------------------------------------===// - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::AddOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class AddOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - AddOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - AddOpGenericAdaptorBase(AddOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class AddOpGenericAdaptor : public detail::AddOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::AddOpGenericAdaptorBase; -public: - AddOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - AddOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : AddOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - AddOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getLhs() { - return (*getODSOperands(0).begin()); - } - - ValueT getRhs() { - return (*getODSOperands(1).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class AddOpAdaptor : public AddOpGenericAdaptor<::mlir::ValueRange> { -public: - using AddOpGenericAdaptor::AddOpGenericAdaptor; - AddOpAdaptor(AddOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class AddOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::NOperands<2>::Impl, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = AddOpAdaptor; - template - using GenericAdaptor = AddOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.add"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getLhs(); - ::mlir::TypedValue<::mlir::TensorType> getRhs(); - ::mlir::OpOperand &getLhsMutable(); - ::mlir::OpOperand &getRhsMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, Value lhs, Value rhs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value lhs, ::mlir::Value rhs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &p); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::AddOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ConstantOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class ConstantOpGenericAdaptorBase { -public: - struct Properties { - using valueTy = ::mlir::DenseElementsAttr; - valueTy value; - - auto getValue() { - auto &propStorage = this->value; - return ::llvm::cast<::mlir::DenseElementsAttr>(propStorage); - } - void setValue(const ::mlir::DenseElementsAttr &propValue) { - this->value = propValue; - } - bool operator==(const Properties &rhs) const { - return - rhs.value == this->value && - true; - } - bool operator!=(const Properties &rhs) const { - return !(*this == rhs); - } - }; -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - Properties properties; - ::mlir::RegionRange odsRegions; -public: - ConstantOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}); - - ConstantOpGenericAdaptorBase(ConstantOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - const Properties &getProperties() { - return properties; - } - - ::mlir::DictionaryAttr getAttributes(); - ::mlir::DenseElementsAttr getValueAttr(); - ::mlir::DenseElementsAttr getValue(); -}; -} // namespace detail -template -class ConstantOpGenericAdaptor : public detail::ConstantOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::ConstantOpGenericAdaptorBase; -public: - ConstantOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - ConstantOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : ConstantOpGenericAdaptor(values, attrs, (properties ? *properties.as() : Properties{}), regions) {} - - template >> - ConstantOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class ConstantOpAdaptor : public ConstantOpGenericAdaptor<::mlir::ValueRange> { -public: - using ConstantOpGenericAdaptor::ConstantOpGenericAdaptor; - ConstantOpAdaptor(ConstantOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class ConstantOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::ZeroOperands, ::mlir::OpTrait::OpInvariants, ::mlir::BytecodeOpInterface::Trait, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = ConstantOpAdaptor; - template - using GenericAdaptor = ConstantOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - using Properties = FoldAdaptor::Properties; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - static ::llvm::StringRef attrNames[] = {::llvm::StringRef("value")}; - return ::llvm::ArrayRef(attrNames); - } - - ::mlir::StringAttr getValueAttrName() { - return getAttributeNameForIndex(0); - } - - static ::mlir::StringAttr getValueAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 0); - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.constant"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static ::mlir::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop); - static llvm::hash_code computePropertiesHash(const Properties &prop); - static std::optional getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name); - static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value); - static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs); - static ::mlir::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::LogicalResult readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state); - void writeProperties(::mlir::DialectBytecodeWriter &writer); - ::mlir::DenseElementsAttr getValueAttr(); - ::mlir::DenseElementsAttr getValue(); - void setValueAttr(::mlir::DenseElementsAttr attr); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, DenseElementsAttr value); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, double value); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::DenseElementsAttr value); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::DenseElementsAttr value); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &p); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - ::mlir::LogicalResult verify(); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -private: - ::mlir::StringAttr getAttributeNameForIndex(unsigned index) { - return getAttributeNameForIndex((*this)->getName(), index); - } - - static ::mlir::StringAttr getAttributeNameForIndex(::mlir::OperationName name, unsigned index) { - assert(index < 1 && "invalid attribute index"); - assert(name.getStringRef() == getOperationName() && "invalid operation name"); - assert(name.isRegistered() && "Operation isn't registered, missing a " - "dependent dialect loading?"); - return name.getAttributeNames()[index]; - } - -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::ConstantOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::FuncOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class FuncOpGenericAdaptorBase { -public: - struct Properties { - using arg_attrsTy = ::mlir::ArrayAttr; - arg_attrsTy arg_attrs; - - auto getArgAttrs() { - auto &propStorage = this->arg_attrs; - return ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(propStorage); - } - void setArgAttrs(const ::mlir::ArrayAttr &propValue) { - this->arg_attrs = propValue; - } - using function_typeTy = ::mlir::TypeAttr; - function_typeTy function_type; - - auto getFunctionType() { - auto &propStorage = this->function_type; - return ::llvm::cast<::mlir::TypeAttr>(propStorage); - } - void setFunctionType(const ::mlir::TypeAttr &propValue) { - this->function_type = propValue; - } - using res_attrsTy = ::mlir::ArrayAttr; - res_attrsTy res_attrs; - - auto getResAttrs() { - auto &propStorage = this->res_attrs; - return ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(propStorage); - } - void setResAttrs(const ::mlir::ArrayAttr &propValue) { - this->res_attrs = propValue; - } - using sym_nameTy = ::mlir::StringAttr; - sym_nameTy sym_name; - - auto getSymName() { - auto &propStorage = this->sym_name; - return ::llvm::cast<::mlir::StringAttr>(propStorage); - } - void setSymName(const ::mlir::StringAttr &propValue) { - this->sym_name = propValue; - } - bool operator==(const Properties &rhs) const { - return - rhs.arg_attrs == this->arg_attrs && - rhs.function_type == this->function_type && - rhs.res_attrs == this->res_attrs && - rhs.sym_name == this->sym_name && - true; - } - bool operator!=(const Properties &rhs) const { - return !(*this == rhs); - } - }; -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - Properties properties; - ::mlir::RegionRange odsRegions; -public: - FuncOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}); - - FuncOpGenericAdaptorBase(FuncOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - const Properties &getProperties() { - return properties; - } - - ::mlir::DictionaryAttr getAttributes(); - ::mlir::StringAttr getSymNameAttr(); - ::llvm::StringRef getSymName(); - ::mlir::TypeAttr getFunctionTypeAttr(); - ::mlir::FunctionType getFunctionType(); - ::mlir::ArrayAttr getArgAttrsAttr(); - ::std::optional< ::mlir::ArrayAttr > getArgAttrs(); - ::mlir::ArrayAttr getResAttrsAttr(); - ::std::optional< ::mlir::ArrayAttr > getResAttrs(); - ::mlir::Region &getBody(); - ::mlir::RegionRange getRegions(); -}; -} // namespace detail -template -class FuncOpGenericAdaptor : public detail::FuncOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::FuncOpGenericAdaptorBase; -public: - FuncOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - FuncOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : FuncOpGenericAdaptor(values, attrs, (properties ? *properties.as() : Properties{}), regions) {} - - template >> - FuncOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class FuncOpAdaptor : public FuncOpGenericAdaptor<::mlir::ValueRange> { -public: - using FuncOpGenericAdaptor::FuncOpGenericAdaptor; - FuncOpAdaptor(FuncOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class FuncOp : public ::mlir::Op { -public: - using Op::Op; - using Op::print; - using Adaptor = FuncOpAdaptor; - template - using GenericAdaptor = FuncOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - using Properties = FoldAdaptor::Properties; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - static ::llvm::StringRef attrNames[] = {::llvm::StringRef("arg_attrs"), ::llvm::StringRef("function_type"), ::llvm::StringRef("res_attrs"), ::llvm::StringRef("sym_name")}; - return ::llvm::ArrayRef(attrNames); - } - - ::mlir::StringAttr getArgAttrsAttrName() { - return getAttributeNameForIndex(0); - } - - static ::mlir::StringAttr getArgAttrsAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 0); - } - - ::mlir::StringAttr getFunctionTypeAttrName() { - return getAttributeNameForIndex(1); - } - - static ::mlir::StringAttr getFunctionTypeAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 1); - } - - ::mlir::StringAttr getResAttrsAttrName() { - return getAttributeNameForIndex(2); - } - - static ::mlir::StringAttr getResAttrsAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 2); - } - - ::mlir::StringAttr getSymNameAttrName() { - return getAttributeNameForIndex(3); - } - - static ::mlir::StringAttr getSymNameAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 3); - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.func"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - ::mlir::Region &getBody(); - static ::mlir::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop); - static llvm::hash_code computePropertiesHash(const Properties &prop); - static std::optional getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name); - static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value); - static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs); - static ::mlir::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::LogicalResult readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state); - void writeProperties(::mlir::DialectBytecodeWriter &writer); - ::mlir::StringAttr getSymNameAttr(); - ::llvm::StringRef getSymName(); - ::mlir::TypeAttr getFunctionTypeAttr(); - ::mlir::FunctionType getFunctionType(); - ::mlir::ArrayAttr getArgAttrsAttr(); - ::std::optional< ::mlir::ArrayAttr > getArgAttrs(); - ::mlir::ArrayAttr getResAttrsAttr(); - ::std::optional< ::mlir::ArrayAttr > getResAttrs(); - void setSymNameAttr(::mlir::StringAttr attr); - void setSymName(::llvm::StringRef attrValue); - void setFunctionTypeAttr(::mlir::TypeAttr attr); - void setFunctionType(::mlir::FunctionType attrValue); - void setArgAttrsAttr(::mlir::ArrayAttr attr); - void setResAttrsAttr(::mlir::ArrayAttr attr); - ::mlir::Attribute removeArgAttrsAttr(); - ::mlir::Attribute removeResAttrsAttr(); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, StringRef name, FunctionType type, ArrayRef attrs = {}); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &p); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); -private: - ::mlir::StringAttr getAttributeNameForIndex(unsigned index) { - return getAttributeNameForIndex((*this)->getName(), index); - } - - static ::mlir::StringAttr getAttributeNameForIndex(::mlir::OperationName name, unsigned index) { - assert(index < 4 && "invalid attribute index"); - assert(name.getStringRef() == getOperationName() && "invalid operation name"); - assert(name.isRegistered() && "Operation isn't registered, missing a " - "dependent dialect loading?"); - return name.getAttributeNames()[index]; - } - -public: - //===------------------------------------------------------------------===// - // FunctionOpInterface Methods - //===------------------------------------------------------------------===// - - /// Returns the argument types of this function. - ArrayRef getArgumentTypes() { return getFunctionType().getInputs(); } - - /// Returns the result types of this function. - ArrayRef getResultTypes() { return getFunctionType().getResults(); } - - /// Returns the region on the current operation that is callable. - ::mlir::Region *getCallableRegion() { return &getBody(); } -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::FuncOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::GenericCallOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class GenericCallOpGenericAdaptorBase { -public: - struct Properties { - using calleeTy = ::mlir::FlatSymbolRefAttr; - calleeTy callee; - - auto getCallee() { - auto &propStorage = this->callee; - return ::llvm::cast<::mlir::FlatSymbolRefAttr>(propStorage); - } - void setCallee(const ::mlir::FlatSymbolRefAttr &propValue) { - this->callee = propValue; - } - bool operator==(const Properties &rhs) const { - return - rhs.callee == this->callee && - true; - } - bool operator!=(const Properties &rhs) const { - return !(*this == rhs); - } - }; -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - Properties properties; - ::mlir::RegionRange odsRegions; -public: - GenericCallOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}); - - GenericCallOpGenericAdaptorBase(GenericCallOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - const Properties &getProperties() { - return properties; - } - - ::mlir::DictionaryAttr getAttributes(); - ::mlir::FlatSymbolRefAttr getCalleeAttr(); - ::llvm::StringRef getCallee(); -}; -} // namespace detail -template -class GenericCallOpGenericAdaptor : public detail::GenericCallOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::GenericCallOpGenericAdaptorBase; -public: - GenericCallOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - GenericCallOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : GenericCallOpGenericAdaptor(values, attrs, (properties ? *properties.as() : Properties{}), regions) {} - - template >> - GenericCallOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - RangeT getInputs() { - return getODSOperands(0); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class GenericCallOpAdaptor : public GenericCallOpGenericAdaptor<::mlir::ValueRange> { -public: - using GenericCallOpGenericAdaptor::GenericCallOpGenericAdaptor; - GenericCallOpAdaptor(GenericCallOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class GenericCallOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::VariadicOperands, ::mlir::OpTrait::OpInvariants, ::mlir::BytecodeOpInterface::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = GenericCallOpAdaptor; - template - using GenericAdaptor = GenericCallOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - using Properties = FoldAdaptor::Properties; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - static ::llvm::StringRef attrNames[] = {::llvm::StringRef("callee")}; - return ::llvm::ArrayRef(attrNames); - } - - ::mlir::StringAttr getCalleeAttrName() { - return getAttributeNameForIndex(0); - } - - static ::mlir::StringAttr getCalleeAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 0); - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.generic_call"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::Operation::operand_range getInputs(); - ::mlir::MutableOperandRange getInputsMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static ::mlir::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop); - static llvm::hash_code computePropertiesHash(const Properties &prop); - static std::optional getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name); - static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value); - static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs); - static ::mlir::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::LogicalResult readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state); - void writeProperties(::mlir::DialectBytecodeWriter &writer); - ::mlir::FlatSymbolRefAttr getCalleeAttr(); - ::llvm::StringRef getCallee(); - void setCalleeAttr(::mlir::FlatSymbolRefAttr attr); - void setCallee(::llvm::StringRef attrValue); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, StringRef callee, ArrayRef arguments); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::FlatSymbolRefAttr callee, ::mlir::ValueRange inputs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::FlatSymbolRefAttr callee, ::mlir::ValueRange inputs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::llvm::StringRef callee, ::mlir::ValueRange inputs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::llvm::StringRef callee, ::mlir::ValueRange inputs); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); -private: - ::mlir::StringAttr getAttributeNameForIndex(unsigned index) { - return getAttributeNameForIndex((*this)->getName(), index); - } - - static ::mlir::StringAttr getAttributeNameForIndex(::mlir::OperationName name, unsigned index) { - assert(index < 1 && "invalid attribute index"); - assert(name.getStringRef() == getOperationName() && "invalid operation name"); - assert(name.isRegistered() && "Operation isn't registered, missing a " - "dependent dialect loading?"); - return name.getAttributeNames()[index]; - } - -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::GenericCallOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::MulOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class MulOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - MulOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - MulOpGenericAdaptorBase(MulOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class MulOpGenericAdaptor : public detail::MulOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::MulOpGenericAdaptorBase; -public: - MulOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - MulOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : MulOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - MulOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getLhs() { - return (*getODSOperands(0).begin()); - } - - ValueT getRhs() { - return (*getODSOperands(1).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class MulOpAdaptor : public MulOpGenericAdaptor<::mlir::ValueRange> { -public: - using MulOpGenericAdaptor::MulOpGenericAdaptor; - MulOpAdaptor(MulOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class MulOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::NOperands<2>::Impl, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = MulOpAdaptor; - template - using GenericAdaptor = MulOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.mul"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getLhs(); - ::mlir::TypedValue<::mlir::TensorType> getRhs(); - ::mlir::OpOperand &getLhsMutable(); - ::mlir::OpOperand &getRhsMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, Value lhs, Value rhs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value lhs, ::mlir::Value rhs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &p); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::MulOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::PrintOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class PrintOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - PrintOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - PrintOpGenericAdaptorBase(PrintOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class PrintOpGenericAdaptor : public detail::PrintOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::PrintOpGenericAdaptorBase; -public: - PrintOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - PrintOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : PrintOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - PrintOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getInput() { - return (*getODSOperands(0).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class PrintOpAdaptor : public PrintOpGenericAdaptor<::mlir::ValueRange> { -public: - using PrintOpGenericAdaptor::PrintOpGenericAdaptor; - PrintOpAdaptor(PrintOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class PrintOp : public ::mlir::Op { -public: - using Op::Op; - using Op::print; - using Adaptor = PrintOpAdaptor; - template - using GenericAdaptor = PrintOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.print"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getInput(); - ::mlir::OpOperand &getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::PrintOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ReshapeOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class ReshapeOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - ReshapeOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - ReshapeOpGenericAdaptorBase(ReshapeOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class ReshapeOpGenericAdaptor : public detail::ReshapeOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::ReshapeOpGenericAdaptorBase; -public: - ReshapeOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - ReshapeOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : ReshapeOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - ReshapeOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getInput() { - return (*getODSOperands(0).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class ReshapeOpAdaptor : public ReshapeOpGenericAdaptor<::mlir::ValueRange> { -public: - using ReshapeOpGenericAdaptor::ReshapeOpGenericAdaptor; - ReshapeOpAdaptor(ReshapeOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class ReshapeOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::OneOperand, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = ReshapeOpAdaptor; - template - using GenericAdaptor = ReshapeOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.reshape"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getInput(); - ::mlir::OpOperand &getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - static void getCanonicalizationPatterns(::mlir::RewritePatternSet &results, ::mlir::MLIRContext *context); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::ReshapeOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ReturnOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class ReturnOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - ReturnOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - ReturnOpGenericAdaptorBase(ReturnOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class ReturnOpGenericAdaptor : public detail::ReturnOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::ReturnOpGenericAdaptorBase; -public: - ReturnOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - ReturnOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : ReturnOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - ReturnOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - RangeT getInput() { - return getODSOperands(0); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class ReturnOpAdaptor : public ReturnOpGenericAdaptor<::mlir::ValueRange> { -public: - using ReturnOpGenericAdaptor::ReturnOpGenericAdaptor; - ReturnOpAdaptor(ReturnOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class ReturnOp : public ::mlir::Op::Impl, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait, ::mlir::OpTrait::IsTerminator> { -public: - using Op::Op; - using Op::print; - using Adaptor = ReturnOpAdaptor; - template - using GenericAdaptor = ReturnOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.return"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::Operation::operand_range getInput(); - ::mlir::MutableOperandRange getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - ::mlir::LogicalResult verify(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: - bool hasOperand() { return getNumOperands() != 0; } -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::ReturnOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::TransposeOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class TransposeOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - TransposeOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - TransposeOpGenericAdaptorBase(TransposeOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class TransposeOpGenericAdaptor : public detail::TransposeOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::TransposeOpGenericAdaptorBase; -public: - TransposeOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - TransposeOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : TransposeOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - TransposeOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getInput() { - return (*getODSOperands(0).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class TransposeOpAdaptor : public TransposeOpGenericAdaptor<::mlir::ValueRange> { -public: - using TransposeOpGenericAdaptor::TransposeOpGenericAdaptor; - TransposeOpAdaptor(TransposeOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class TransposeOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::OneOperand, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = TransposeOpAdaptor; - template - using GenericAdaptor = TransposeOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.transpose"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getInput(); - ::mlir::OpOperand &getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - ::mlir::LogicalResult verify(); - static void getCanonicalizationPatterns(::mlir::RewritePatternSet &results, ::mlir::MLIRContext *context); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::TransposeOp) - - -#endif // GET_OP_CLASSES - diff --git a/Ch3/include/toy/run.sh b/Ch3/include/toy/run.sh deleted file mode 100644 index b123ce1..0000000 --- a/Ch3/include/toy/run.sh +++ /dev/null @@ -1,4 +0,0 @@ -mlir-tblgen-18 -gen-op-decls -I /usr/lib/llvm-18/include Ops.td > Ops.h.inc -mlir-tblgen-18 -gen-op-defs -I /usr/lib/llvm-18/include Ops.td > Ops.cpp.inc -mlir-tblgen-18 -gen-dialect-decls -I /usr/lib/llvm-18/include Ops.td > Dialect.h.inc -mlir-tblgen-18 -gen-dialect-defs -I /usr/lib/llvm-18/include Ops.td > Dialect.cpp.inc \ No newline at end of file diff --git a/Ch3/mlir/ToyCombine.inc b/Ch3/mlir/ToyCombine.inc deleted file mode 100644 index 33ec8e1..0000000 --- a/Ch3/mlir/ToyCombine.inc +++ /dev/null @@ -1,176 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Rewriters *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: ToyCombine.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -/* Generated from: - ToyCombine.td:47 -*/ -struct FoldConstantReshapeOptPattern : public ::mlir::RewritePattern { - FoldConstantReshapeOptPattern(::mlir::MLIRContext *context) - : ::mlir::RewritePattern("toy.reshape", 2, context, {"toy.constant"}) {} - ::mlir::LogicalResult matchAndRewrite(::mlir::Operation *op0, - ::mlir::PatternRewriter &rewriter) const override { - // Variables for capturing values and attributes used while creating ops - ::mlir::DenseElementsAttr arg; - ::mlir::toy::ReshapeOp res; - ::llvm::SmallVector<::mlir::Operation *, 4> tblgen_ops; - - // Match - tblgen_ops.push_back(op0); - auto castedOp0 = ::llvm::dyn_cast<::mlir::toy::ReshapeOp>(op0); (void)castedOp0; - res = castedOp0; - { - auto *op1 = (*castedOp0.getODSOperands(0).begin()).getDefiningOp(); - if (!(op1)){ - return rewriter.notifyMatchFailure(castedOp0, [&](::mlir::Diagnostic &diag) { - diag << "There's no operation that defines operand 0 of castedOp0"; - }); - } - auto castedOp1 = ::llvm::dyn_cast<::mlir::toy::ConstantOp>(op1); (void)castedOp1; - if (!(castedOp1)){ - return rewriter.notifyMatchFailure(op1, [&](::mlir::Diagnostic &diag) { - diag << "castedOp1 is not ::mlir::toy::ConstantOp type"; - }); - } - { - auto tblgen_attr = op1->getAttrOfType<::mlir::DenseElementsAttr>("value");(void)tblgen_attr; - if (!(tblgen_attr)){ - return rewriter.notifyMatchFailure(op1, [&](::mlir::Diagnostic &diag) { - diag << "expected op 'toy.constant' to have attribute 'value' of type '::mlir::DenseElementsAttr'"; - }); - } - arg = tblgen_attr; - } - tblgen_ops.push_back(op1); - } - - // Rewrite - auto odsLoc = rewriter.getFusedLoc({tblgen_ops[0]->getLoc(), tblgen_ops[1]->getLoc()}); (void)odsLoc; - ::llvm::SmallVector<::mlir::Value, 4> tblgen_repl_values; - auto nativeVar_0 = arg.reshape(::llvm::cast((*res.getODSResults(0).begin()).getType())); (void)nativeVar_0; - ::mlir::toy::ConstantOp tblgen_ConstantOp_1; - { - ::llvm::SmallVector<::mlir::Value, 4> tblgen_values; (void)tblgen_values; - ::llvm::SmallVector<::mlir::NamedAttribute, 4> tblgen_attrs; (void)tblgen_attrs; - if (auto tmpAttr = nativeVar_0) { - tblgen_attrs.emplace_back(rewriter.getStringAttr("value"), tmpAttr); - } - ::llvm::SmallVector<::mlir::Type, 4> tblgen_types; (void)tblgen_types; - for (auto v: castedOp0.getODSResults(0)) { - tblgen_types.push_back(v.getType()); - } - tblgen_ConstantOp_1 = rewriter.create<::mlir::toy::ConstantOp>(odsLoc, tblgen_types, tblgen_values, tblgen_attrs); - } - - for (auto v: ::llvm::SmallVector<::mlir::Value, 4>{ tblgen_ConstantOp_1.getODSResults(0) }) { - tblgen_repl_values.push_back(v); - } - - rewriter.replaceOp(op0, tblgen_repl_values); - return ::mlir::success(); - }; -}; - -/* Generated from: - ToyCombine.td:60 -*/ -struct RedundantReshapeOptPattern : public ::mlir::RewritePattern { - RedundantReshapeOptPattern(::mlir::MLIRContext *context) - : ::mlir::RewritePattern("toy.reshape", 1, context, {}) {} - ::mlir::LogicalResult matchAndRewrite(::mlir::Operation *op0, - ::mlir::PatternRewriter &rewriter) const override { - // Variables for capturing values and attributes used while creating ops - ::mlir::Operation::operand_range arg(op0->getOperands()); - ::mlir::toy::ReshapeOp res; - ::llvm::SmallVector<::mlir::Operation *, 4> tblgen_ops; - - // Match - tblgen_ops.push_back(op0); - auto castedOp0 = ::llvm::dyn_cast<::mlir::toy::ReshapeOp>(op0); (void)castedOp0; - res = castedOp0; - arg = castedOp0.getODSOperands(0); - if (!(((*res.getODSResults(0).begin()).getType() == (*arg.begin()).getType()))){ - return rewriter.notifyMatchFailure(op0, [&](::mlir::Diagnostic &diag) { - diag << "entities 'res, arg' failed to satisfy constraint: ''"; - }); - } - - // Rewrite - auto odsLoc = rewriter.getFusedLoc({tblgen_ops[0]->getLoc()}); (void)odsLoc; - ::llvm::SmallVector<::mlir::Value, 4> tblgen_repl_values; - - for (auto v: ::llvm::SmallVector<::mlir::Value, 4>{ arg }) { - tblgen_repl_values.push_back(v); - } - - rewriter.replaceOp(op0, tblgen_repl_values); - return ::mlir::success(); - }; -}; - -/* Generated from: - ToyCombine.td:34 -*/ -struct ReshapeReshapeOptPattern : public ::mlir::RewritePattern { - ReshapeReshapeOptPattern(::mlir::MLIRContext *context) - : ::mlir::RewritePattern("toy.reshape", 2, context, {"toy.reshape"}) {} - ::mlir::LogicalResult matchAndRewrite(::mlir::Operation *op0, - ::mlir::PatternRewriter &rewriter) const override { - // Variables for capturing values and attributes used while creating ops - ::mlir::Operation::operand_range arg(op0->getOperands()); - ::llvm::SmallVector<::mlir::Operation *, 4> tblgen_ops; - - // Match - tblgen_ops.push_back(op0); - auto castedOp0 = ::llvm::dyn_cast<::mlir::toy::ReshapeOp>(op0); (void)castedOp0; - { - auto *op1 = (*castedOp0.getODSOperands(0).begin()).getDefiningOp(); - if (!(op1)){ - return rewriter.notifyMatchFailure(castedOp0, [&](::mlir::Diagnostic &diag) { - diag << "There's no operation that defines operand 0 of castedOp0"; - }); - } - auto castedOp1 = ::llvm::dyn_cast<::mlir::toy::ReshapeOp>(op1); (void)castedOp1; - if (!(castedOp1)){ - return rewriter.notifyMatchFailure(op1, [&](::mlir::Diagnostic &diag) { - diag << "castedOp1 is not ::mlir::toy::ReshapeOp type"; - }); - } - arg = castedOp1.getODSOperands(0); - tblgen_ops.push_back(op1); - } - - // Rewrite - auto odsLoc = rewriter.getFusedLoc({tblgen_ops[0]->getLoc(), tblgen_ops[1]->getLoc()}); (void)odsLoc; - ::llvm::SmallVector<::mlir::Value, 4> tblgen_repl_values; - ::mlir::toy::ReshapeOp tblgen_ReshapeOp_0; - { - ::llvm::SmallVector<::mlir::Value, 4> tblgen_values; (void)tblgen_values; - ::llvm::SmallVector<::mlir::NamedAttribute, 4> tblgen_attrs; (void)tblgen_attrs; - tblgen_values.push_back((*arg.begin())); - ::llvm::SmallVector<::mlir::Type, 4> tblgen_types; (void)tblgen_types; - for (auto v: castedOp0.getODSResults(0)) { - tblgen_types.push_back(v.getType()); - } - tblgen_ReshapeOp_0 = rewriter.create<::mlir::toy::ReshapeOp>(odsLoc, tblgen_types, tblgen_values, tblgen_attrs); - } - - for (auto v: ::llvm::SmallVector<::mlir::Value, 4>{ tblgen_ReshapeOp_0.getODSResults(0) }) { - tblgen_repl_values.push_back(v); - } - - rewriter.replaceOp(op0, tblgen_repl_values); - return ::mlir::success(); - }; -}; - -void LLVM_ATTRIBUTE_UNUSED populateWithGenerated(::mlir::RewritePatternSet &patterns) { - patterns.add(patterns.getContext()); - patterns.add(patterns.getContext()); - patterns.add(patterns.getContext()); -} diff --git a/Ch3/mlir/run.sh b/Ch3/mlir/run.sh deleted file mode 100644 index f592fde..0000000 --- a/Ch3/mlir/run.sh +++ /dev/null @@ -1,2 +0,0 @@ -mlir-tblgen-18 -gen-rewriters -I /usr/lib/llvm-18/include -I ../include ToyCombine.td > ToyCombine.inc - diff --git a/Ch4/CMakeLists.txt b/Ch4/CMakeLists.txt index 0352b99..9d33b7d 100644 --- a/Ch4/CMakeLists.txt +++ b/Ch4/CMakeLists.txt @@ -6,11 +6,11 @@ set(LLVM_LINK_COMPONENTS Support ) -# set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td) -# mlir_tablegen(ToyCombine.inc -gen-rewriters) -# add_public_tablegen_target(ToyCh4CombineIncGen) +set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td) +mlir_tablegen(ToyCombine.inc -gen-rewriters) +add_public_tablegen_target(ToyCh4CombineIncGen) -add_executable(toyc-ch4 +add_toy_chapter(toyc-ch4 toyc.cpp parser/AST.cpp mlir/MLIRGen.cpp @@ -18,10 +18,10 @@ add_executable(toyc-ch4 mlir/ShapeInferencePass.cpp mlir/ToyCombine.cpp - # DEPENDS - # ToyCh4OpsIncGen - # ToyCh4ShapeInferenceInterfaceIncGen - # ToyCh4CombineIncGen + DEPENDS + ToyCh4OpsIncGen + ToyCh4ShapeInferenceInterfaceIncGen + ToyCh4CombineIncGen ) include_directories(${CMAKE_CURRENT_BINARY_DIR}) diff --git a/Ch4/include/run.sh b/Ch4/include/run.sh deleted file mode 100644 index b9d18af..0000000 --- a/Ch4/include/run.sh +++ /dev/null @@ -1,7 +0,0 @@ -mlir-tblgen-18 -gen-op-decls -I /usr/lib/llvm-18/include toy/Ops.td > toy/Ops.h.inc -mlir-tblgen-18 -gen-op-defs -I /usr/lib/llvm-18/include toy/Ops.td > toy/Ops.cpp.inc -mlir-tblgen-18 -gen-dialect-decls -I /usr/lib/llvm-18/include toy/Ops.td > toy/Dialect.h.inc -mlir-tblgen-18 -gen-dialect-defs -I /usr/lib/llvm-18/include toy/Ops.td > toy/Dialect.cpp.inc - -mlir-tblgen-18 -gen-op-interface-decls -I /usr/lib/llvm-18/include toy/ShapeInferenceInterface.td > toy/ShapeInferenceOpInterfaces.h.inc -mlir-tblgen-18 -gen-op-interface-defs -I /usr/lib/llvm-18/include toy/ShapeInferenceInterface.td > toy/ShapeInferenceOpInterfaces.cpp.inc diff --git a/Ch4/include/toy/CMakeLists.txt b/Ch4/include/toy/CMakeLists.txt index 79a1f71..acf7e31 100644 --- a/Ch4/include/toy/CMakeLists.txt +++ b/Ch4/include/toy/CMakeLists.txt @@ -1,13 +1,13 @@ # Most dialects should use add_mlir_dialect(). See examples/standalone. -# set(LLVM_TARGET_DEFINITIONS Ops.td) -# mlir_tablegen(Ops.h.inc -gen-op-decls) -# mlir_tablegen(Ops.cpp.inc -gen-op-defs) -# mlir_tablegen(Dialect.h.inc -gen-dialect-decls) -# mlir_tablegen(Dialect.cpp.inc -gen-dialect-defs) -# add_public_tablegen_target(ToyCh4OpsIncGen) +set(LLVM_TARGET_DEFINITIONS Ops.td) +mlir_tablegen(Ops.h.inc -gen-op-decls) +mlir_tablegen(Ops.cpp.inc -gen-op-defs) +mlir_tablegen(Dialect.h.inc -gen-dialect-decls) +mlir_tablegen(Dialect.cpp.inc -gen-dialect-defs) +add_public_tablegen_target(ToyCh4OpsIncGen) # Most dialects should use add_mlir_interfaces(). -# set(LLVM_TARGET_DEFINITIONS ShapeInferenceInterface.td) -# mlir_tablegen(ShapeInferenceOpInterfaces.h.inc -gen-op-interface-decls) -# mlir_tablegen(ShapeInferenceOpInterfaces.cpp.inc -gen-op-interface-defs) -# add_public_tablegen_target(ToyCh4ShapeInferenceInterfaceIncGen) +set(LLVM_TARGET_DEFINITIONS ShapeInferenceInterface.td) +mlir_tablegen(ShapeInferenceOpInterfaces.h.inc -gen-op-interface-decls) +mlir_tablegen(ShapeInferenceOpInterfaces.cpp.inc -gen-op-interface-defs) +add_public_tablegen_target(ToyCh4ShapeInferenceInterfaceIncGen) diff --git a/Ch4/include/toy/Dialect.cpp.inc b/Ch4/include/toy/Dialect.cpp.inc deleted file mode 100644 index 8cbc772..0000000 --- a/Ch4/include/toy/Dialect.cpp.inc +++ /dev/null @@ -1,23 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Dialect Definitions *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: Ops.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::ToyDialect) -namespace mlir { -namespace toy { - -ToyDialect::ToyDialect(::mlir::MLIRContext *context) - : ::mlir::Dialect(getDialectNamespace(), context, ::mlir::TypeID::get()) { - - initialize(); -} - -ToyDialect::~ToyDialect() = default; - -} // namespace toy -} // namespace mlir diff --git a/Ch4/include/toy/Dialect.h.inc b/Ch4/include/toy/Dialect.h.inc deleted file mode 100644 index f19d867..0000000 --- a/Ch4/include/toy/Dialect.h.inc +++ /dev/null @@ -1,26 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Dialect Declarations *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: Ops.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -namespace mlir { -namespace toy { - -class ToyDialect : public ::mlir::Dialect { - explicit ToyDialect(::mlir::MLIRContext *context); - - void initialize(); - friend class ::mlir::MLIRContext; -public: - ~ToyDialect() override; - static constexpr ::llvm::StringLiteral getDialectNamespace() { - return ::llvm::StringLiteral("toy"); - } -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::ToyDialect) diff --git a/Ch4/include/toy/Ops.cpp.inc b/Ch4/include/toy/Ops.cpp.inc deleted file mode 100644 index c1a6abc..0000000 --- a/Ch4/include/toy/Ops.cpp.inc +++ /dev/null @@ -1,2242 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Op Definitions *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: Ops.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -#ifdef GET_OP_LIST -#undef GET_OP_LIST - -::mlir::toy::AddOp, -::mlir::toy::CastOp, -::mlir::toy::ConstantOp, -::mlir::toy::FuncOp, -::mlir::toy::GenericCallOp, -::mlir::toy::MulOp, -::mlir::toy::PrintOp, -::mlir::toy::ReshapeOp, -::mlir::toy::ReturnOp, -::mlir::toy::TransposeOp -#endif // GET_OP_LIST - -#ifdef GET_OP_CLASSES -#undef GET_OP_CLASSES - - -//===----------------------------------------------------------------------===// -// Local Utility Method Definitions -//===----------------------------------------------------------------------===// - -namespace mlir { -namespace toy { - -static ::mlir::LogicalResult __mlir_ods_local_type_constraint_Ops0( - ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, - unsigned valueIndex) { - if (!(((::llvm::isa<::mlir::TensorType>(type))) && ([](::mlir::Type elementType) { return (elementType.isF64()); }(::llvm::cast<::mlir::ShapedType>(type).getElementType())))) { - return op->emitOpError(valueKind) << " #" << valueIndex - << " must be tensor of 64-bit float values, but got " << type; - } - return ::mlir::success(); -} - -static ::mlir::LogicalResult __mlir_ods_local_type_constraint_Ops1( - ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, - unsigned valueIndex) { - if (!(((::llvm::isa<::mlir::TensorType>(type))) && ([](::mlir::Type elementType) { return (elementType.isF64()); }(::llvm::cast<::mlir::ShapedType>(type).getElementType())))) { - return op->emitOpError(valueKind) << " #" << valueIndex - << " must be variadic of tensor of 64-bit float values, but got " << type; - } - return ::mlir::success(); -} - -static ::mlir::LogicalResult __mlir_ods_local_type_constraint_Ops2( - ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, - unsigned valueIndex) { - if (!((((::llvm::isa<::mlir::RankedTensorType>(type))) && ((::llvm::cast<::mlir::ShapedType>(type).hasStaticShape()))) && ([](::mlir::Type elementType) { return (elementType.isF64()); }(::llvm::cast<::mlir::ShapedType>(type).getElementType())))) { - return op->emitOpError(valueKind) << " #" << valueIndex - << " must be statically shaped tensor of 64-bit float values, but got " << type; - } - return ::mlir::success(); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops0( - ::mlir::Attribute attr, ::llvm::StringRef attrName, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { - if (attr && !((::llvm::isa<::mlir::DenseFPElementsAttr>(attr) &&::llvm::cast<::mlir::DenseElementsAttr>(attr).getType().getElementType().isF64()))) - return emitError() << "attribute '" << attrName - << "' failed to satisfy constraint: 64-bit float elements attribute"; - return ::mlir::success(); -} -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops0( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops0(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops1( - ::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 ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops1( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops1(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops2( - ::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 ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops2( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops2(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops3( - ::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 ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops3( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops3(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops4( - ::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 ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops4( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops4(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_region_constraint_Ops0( - ::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 toy -} // namespace mlir -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::AddOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -AddOpGenericAdaptorBase::AddOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.add", odsAttrs.getContext()); -} - -AddOpGenericAdaptorBase::AddOpGenericAdaptorBase(AddOp op) : AddOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair AddOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr AddOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -AddOpAdaptor::AddOpAdaptor(AddOp op) : AddOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult AddOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair AddOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range AddOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> AddOp::getLhs() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::TypedValue<::mlir::TensorType> AddOp::getRhs() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(1).begin()); -} - -::mlir::OpOperand &AddOp::getLhsMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -::mlir::OpOperand &AddOp::getRhsMutable() { - auto range = getODSOperandIndexAndLength(1); - return getOperation()->getOpOperand(range.first); -} - -std::pair AddOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range AddOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void AddOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value lhs, ::mlir::Value rhs) { - odsState.addOperands(lhs); - odsState.addOperands(rhs); - odsState.addTypes(resultType0); -} - -void AddOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs) { - odsState.addOperands(lhs); - odsState.addOperands(rhs); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void AddOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 2u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult AddOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*this, v.getType(), "operand", index++))) - return ::mlir::failure(); - } - auto valueGroup1 = getODSOperands(1); - - for (auto v : valueGroup1) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult AddOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -void AddOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::AddOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::CastOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -CastOpGenericAdaptorBase::CastOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.cast", odsAttrs.getContext()); -} - -CastOpGenericAdaptorBase::CastOpGenericAdaptorBase(CastOp op) : CastOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair CastOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr CastOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -CastOpAdaptor::CastOpAdaptor(CastOp op) : CastOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult CastOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair CastOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range CastOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> CastOp::getInput() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::OpOperand &CastOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -std::pair CastOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range CastOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> CastOp::getOutput() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSResults(0).begin()); -} - -void CastOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type output, ::mlir::Value input) { - odsState.addOperands(input); - odsState.addTypes(output); -} - -void CastOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input) { - odsState.addOperands(input); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void CastOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 1u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult CastOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult CastOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -::mlir::ParseResult CastOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::OpAsmParser::UnresolvedOperand inputRawOperands[1]; - ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> inputOperands(inputRawOperands); ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::mlir::Type inputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> inputTypes(inputRawTypes); - ::mlir::Type outputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> outputTypes(outputRawTypes); - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperand(inputRawOperands[0])) - return ::mlir::failure(); - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.parseColon()) - return ::mlir::failure(); - - { - ::mlir::TensorType type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - inputRawTypes[0] = type; - } - if (parser.parseKeyword("to")) - return ::mlir::failure(); - - { - ::mlir::TensorType type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - outputRawTypes[0] = type; - } - result.addTypes(outputTypes); - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void CastOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << ' '; - _odsPrinter << getInput(); - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - { - auto type = getInput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::TensorType>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } - _odsPrinter << ' ' << "to"; - _odsPrinter << ' '; - { - auto type = getOutput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::TensorType>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } -} - -void CastOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::CastOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ConstantOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -ConstantOpGenericAdaptorBase::ConstantOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.constant", odsAttrs.getContext()); -} - -ConstantOpGenericAdaptorBase::ConstantOpGenericAdaptorBase(ConstantOp op) : ConstantOpGenericAdaptorBase(op->getDiscardableAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair ConstantOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr ConstantOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -::mlir::DenseElementsAttr ConstantOpGenericAdaptorBase::getValueAttr() { - auto attr = ::llvm::cast<::mlir::DenseElementsAttr>(getProperties().value); - return attr; -} - -::mlir::DenseElementsAttr ConstantOpGenericAdaptorBase::getValue() { - auto attr = getValueAttr(); - return attr; -} - -} // namespace detail -ConstantOpAdaptor::ConstantOpAdaptor(ConstantOp op) : ConstantOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult ConstantOpAdaptor::verify(::mlir::Location loc) { - auto tblgen_value = getProperties().value; (void)tblgen_value; - if (!tblgen_value) return emitError(loc, "'toy.constant' op ""requires attribute 'value'"); - - if (tblgen_value && !((::llvm::isa<::mlir::DenseFPElementsAttr>(tblgen_value) &&::llvm::cast<::mlir::DenseElementsAttr>(tblgen_value).getType().getElementType().isF64()))) - return emitError(loc, "'toy.constant' op ""attribute 'value' failed to satisfy constraint: 64-bit float elements attribute"); - return ::mlir::success(); -} - -std::pair ConstantOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range ConstantOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -std::pair ConstantOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range ConstantOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::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 || /*isRequired=*/true) { - if (!attr) { - emitError() << "expected key entry for value in DictionaryAttr to set " - "Properties."; - return ::mlir::failure(); - } - 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) { - 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); -} - -::mlir::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_Ops0(attr, "value", emitError))) - return ::mlir::failure(); - } - return ::mlir::success(); -} - -::mlir::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); -} - -::mlir::DenseElementsAttr ConstantOp::getValueAttr() { - return ::llvm::cast<::mlir::DenseElementsAttr>(getProperties().value); -} - -::mlir::DenseElementsAttr ConstantOp::getValue() { - auto attr = getValueAttr(); - return attr; -} - -void ConstantOp::setValueAttr(::mlir::DenseElementsAttr attr) { - (*this)->setAttr(getValueAttrName(), attr); -} - -void ConstantOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, DenseElementsAttr value) { - build(odsBuilder, odsState, value.getType(), value); - -} - -void ConstantOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::DenseElementsAttr value) { - odsState.getOrAddProperties().value = value; - odsState.addTypes(resultType0); -} - -void ConstantOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::DenseElementsAttr value) { - odsState.getOrAddProperties().value = value; - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -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); -} - -::mlir::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_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult ConstantOp::verifyInvariants() { - if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) - return ::mlir::success(); - return ::mlir::failure(); -} - -void ConstantOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::ConstantOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::FuncOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -FuncOpGenericAdaptorBase::FuncOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.func", odsAttrs.getContext()); -} - -FuncOpGenericAdaptorBase::FuncOpGenericAdaptorBase(FuncOp op) : FuncOpGenericAdaptorBase(op->getDiscardableAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair FuncOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr FuncOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -::mlir::StringAttr FuncOpGenericAdaptorBase::getSymNameAttr() { - auto attr = ::llvm::cast<::mlir::StringAttr>(getProperties().sym_name); - return attr; -} - -::llvm::StringRef FuncOpGenericAdaptorBase::getSymName() { - auto attr = getSymNameAttr(); - return attr.getValue(); -} - -::mlir::TypeAttr FuncOpGenericAdaptorBase::getFunctionTypeAttr() { - auto attr = ::llvm::cast<::mlir::TypeAttr>(getProperties().function_type); - return attr; -} - -::mlir::FunctionType FuncOpGenericAdaptorBase::getFunctionType() { - auto attr = getFunctionTypeAttr(); - return ::llvm::cast<::mlir::FunctionType>(attr.getValue()); -} - -::mlir::ArrayAttr FuncOpGenericAdaptorBase::getArgAttrsAttr() { - auto attr = ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(getProperties().arg_attrs); - return attr; -} - -::std::optional< ::mlir::ArrayAttr > FuncOpGenericAdaptorBase::getArgAttrs() { - auto attr = getArgAttrsAttr(); - return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); -} - -::mlir::ArrayAttr FuncOpGenericAdaptorBase::getResAttrsAttr() { - auto attr = ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(getProperties().res_attrs); - return attr; -} - -::std::optional< ::mlir::ArrayAttr > FuncOpGenericAdaptorBase::getResAttrs() { - auto attr = getResAttrsAttr(); - return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); -} - -::mlir::Region &FuncOpGenericAdaptorBase::getBody() { - return *odsRegions[0]; -} - -::mlir::RegionRange FuncOpGenericAdaptorBase::getRegions() { - return odsRegions; -} - -} // namespace detail -FuncOpAdaptor::FuncOpAdaptor(FuncOp op) : FuncOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::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, "'toy.func' op ""requires attribute 'function_type'"); - 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, "'toy.func' op ""requires attribute 'sym_name'"); - - if (tblgen_sym_name && !((::llvm::isa<::mlir::StringAttr>(tblgen_sym_name)))) - return emitError(loc, "'toy.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, "'toy.func' op ""attribute 'function_type' failed to satisfy constraint: type attribute of function type"); - - 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, "'toy.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, "'toy.func' op ""attribute 'res_attrs' failed to satisfy constraint: Array of dictionary attributes"); - return ::mlir::success(); -} - -std::pair FuncOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range FuncOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -std::pair FuncOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range FuncOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::Region &FuncOp::getBody() { - return (*this)->getRegion(0); -} - -::mlir::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 || /*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.function_type; - auto attr = dict.get("function_type"); - 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.res_attrs; - auto attr = dict.get("res_attrs"); - 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.sym_name; - auto attr = dict.get("sym_name"); - 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(); - } - } - } - 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.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)); - } - - if (!attrs.empty()) - return odsBuilder.getDictionaryAttr(attrs); - return {}; -} - -llvm::hash_code FuncOp::computePropertiesHash(const Properties &prop) { - return llvm::hash_combine( - llvm::hash_value(prop.arg_attrs.getAsOpaquePointer()), - llvm::hash_value(prop.function_type.getAsOpaquePointer()), - llvm::hash_value(prop.res_attrs.getAsOpaquePointer()), - llvm::hash_value(prop.sym_name.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 == "res_attrs") - return prop.res_attrs; - - if (name == "sym_name") - return prop.sym_name; - 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 == "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; - } -} - -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.res_attrs) attrs.append("res_attrs", prop.res_attrs); - - if (prop.sym_name) attrs.append("sym_name", prop.sym_name); -} - -::mlir::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_Ops3(attr, "arg_attrs", emitError))) - return ::mlir::failure(); - } - - { - ::mlir::Attribute attr = attrs.get(getFunctionTypeAttrName(opName)); - if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_Ops2(attr, "function_type", emitError))) - return ::mlir::failure(); - } - - { - ::mlir::Attribute attr = attrs.get(getResAttrsAttrName(opName)); - if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_Ops3(attr, "res_attrs", emitError))) - return ::mlir::failure(); - } - - { - ::mlir::Attribute attr = attrs.get(getSymNameAttrName(opName)); - if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_Ops1(attr, "sym_name", emitError))) - return ::mlir::failure(); - } - return ::mlir::success(); -} - -::mlir::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.res_attrs))) - return ::mlir::failure(); - - if (::mlir::failed(reader.readAttribute(prop.sym_name))) - 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.res_attrs); - writer.writeAttribute(prop.sym_name); -} - -::mlir::StringAttr FuncOp::getSymNameAttr() { - return ::llvm::cast<::mlir::StringAttr>(getProperties().sym_name); -} - -::llvm::StringRef FuncOp::getSymName() { - auto attr = getSymNameAttr(); - return attr.getValue(); -} - -::mlir::TypeAttr FuncOp::getFunctionTypeAttr() { - return ::llvm::cast<::mlir::TypeAttr>(getProperties().function_type); -} - -::mlir::FunctionType FuncOp::getFunctionType() { - auto attr = getFunctionTypeAttr(); - return ::llvm::cast<::mlir::FunctionType>(attr.getValue()); -} - -::mlir::ArrayAttr FuncOp::getArgAttrsAttr() { - return ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(getProperties().arg_attrs); -} - -::std::optional< ::mlir::ArrayAttr > FuncOp::getArgAttrs() { - auto attr = getArgAttrsAttr(); - return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); -} - -::mlir::ArrayAttr FuncOp::getResAttrsAttr() { - return ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(getProperties().res_attrs); -} - -::std::optional< ::mlir::ArrayAttr > FuncOp::getResAttrs() { - auto attr = getResAttrsAttr(); - return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); -} - -void FuncOp::setSymNameAttr(::mlir::StringAttr attr) { - (*this)->setAttr(getSymNameAttrName(), attr); -} - -void FuncOp::setSymName(::llvm::StringRef attrValue) { - (*this)->setAttr(getSymNameAttrName(), ::mlir::Builder((*this)->getContext()).getStringAttr(attrValue)); -} - -void FuncOp::setFunctionTypeAttr(::mlir::TypeAttr attr) { - (*this)->setAttr(getFunctionTypeAttrName(), attr); -} - -void FuncOp::setFunctionType(::mlir::FunctionType attrValue) { - (*this)->setAttr(getFunctionTypeAttrName(), ::mlir::TypeAttr::get(attrValue)); -} - -void FuncOp::setArgAttrsAttr(::mlir::ArrayAttr attr) { - (*this)->setAttr(getArgAttrsAttrName(), attr); -} - -void FuncOp::setResAttrsAttr(::mlir::ArrayAttr attr) { - (*this)->setAttr(getResAttrsAttrName(), attr); -} - -::mlir::Attribute FuncOp::removeArgAttrsAttr() { - auto &attr = getProperties().arg_attrs; - attr = {}; - return attr; -} - -::mlir::Attribute FuncOp::removeResAttrsAttr() { - auto &attr = getProperties().res_attrs; - attr = {}; - return attr; -} - -::mlir::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_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'"); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops1(*this, tblgen_sym_name, "sym_name"))) - return ::mlir::failure(); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops2(*this, tblgen_function_type, "function_type"))) - return ::mlir::failure(); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops3(*this, tblgen_arg_attrs, "arg_attrs"))) - return ::mlir::failure(); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops3(*this, tblgen_res_attrs, "res_attrs"))) - return ::mlir::failure(); - { - unsigned index = 0; (void)index; - - for (auto ®ion : ::llvm::MutableArrayRef((*this)->getRegion(0))) - if (::mlir::failed(__mlir_ods_local_region_constraint_Ops0(*this, region, "body", index++))) - return ::mlir::failure(); - } - return ::mlir::success(); -} - -::mlir::LogicalResult FuncOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::FuncOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::GenericCallOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -GenericCallOpGenericAdaptorBase::GenericCallOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.generic_call", odsAttrs.getContext()); -} - -GenericCallOpGenericAdaptorBase::GenericCallOpGenericAdaptorBase(GenericCallOp op) : GenericCallOpGenericAdaptorBase(op->getDiscardableAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair GenericCallOpGenericAdaptorBase::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}; -} - -::mlir::DictionaryAttr GenericCallOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -::mlir::FlatSymbolRefAttr GenericCallOpGenericAdaptorBase::getCalleeAttr() { - auto attr = ::llvm::cast<::mlir::FlatSymbolRefAttr>(getProperties().callee); - return attr; -} - -::llvm::StringRef GenericCallOpGenericAdaptorBase::getCallee() { - auto attr = getCalleeAttr(); - return attr.getValue(); -} - -} // namespace detail -GenericCallOpAdaptor::GenericCallOpAdaptor(GenericCallOp op) : GenericCallOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult GenericCallOpAdaptor::verify(::mlir::Location loc) { - auto tblgen_callee = getProperties().callee; (void)tblgen_callee; - if (!tblgen_callee) return emitError(loc, "'toy.generic_call' op ""requires attribute 'callee'"); - - if (tblgen_callee && !((::llvm::isa<::mlir::FlatSymbolRefAttr>(tblgen_callee)))) - return emitError(loc, "'toy.generic_call' op ""attribute 'callee' failed to satisfy constraint: flat symbol reference attribute"); - return ::mlir::success(); -} - -std::pair GenericCallOp::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::Operation::operand_range GenericCallOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::Operation::operand_range GenericCallOp::getInputs() { - return getODSOperands(0); -} - -::mlir::MutableOperandRange GenericCallOp::getInputsMutable() { - auto range = getODSOperandIndexAndLength(0); - auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); - return mutableRange; -} - -std::pair GenericCallOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range GenericCallOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::LogicalResult GenericCallOp::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.callee; - auto attr = dict.get("callee"); - if (attr || /*isRequired=*/true) { - if (!attr) { - emitError() << "expected key entry for callee in DictionaryAttr to set " - "Properties."; - return ::mlir::failure(); - } - auto convertedAttr = ::llvm::dyn_cast>(attr); - if (convertedAttr) { - propStorage = convertedAttr; - } else { - emitError() << "Invalid attribute `callee` in property conversion: " << attr; - return ::mlir::failure(); - } - } - } - return ::mlir::success(); -} - -::mlir::Attribute GenericCallOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) { - ::mlir::SmallVector<::mlir::NamedAttribute> attrs; - ::mlir::Builder odsBuilder{ctx}; - - { - const auto &propStorage = prop.callee; - if (propStorage) - attrs.push_back(odsBuilder.getNamedAttr("callee", - propStorage)); - } - - if (!attrs.empty()) - return odsBuilder.getDictionaryAttr(attrs); - return {}; -} - -llvm::hash_code GenericCallOp::computePropertiesHash(const Properties &prop) { - return llvm::hash_combine( - llvm::hash_value(prop.callee.getAsOpaquePointer())); -} - -std::optional GenericCallOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { - if (name == "callee") - return prop.callee; - return std::nullopt; -} - -void GenericCallOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { - if (name == "callee") { - prop.callee = ::llvm::dyn_cast_or_null>(value); - return; - } -} - -void GenericCallOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { - if (prop.callee) attrs.append("callee", prop.callee); -} - -::mlir::LogicalResult GenericCallOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { - { - ::mlir::Attribute attr = attrs.get(getCalleeAttrName(opName)); - if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_Ops4(attr, "callee", emitError))) - return ::mlir::failure(); - } - return ::mlir::success(); -} - -::mlir::LogicalResult GenericCallOp::readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state) { - auto &prop = state.getOrAddProperties(); (void)prop; - if (::mlir::failed(reader.readAttribute(prop.callee))) - return ::mlir::failure(); - return ::mlir::success(); -} - -void GenericCallOp::writeProperties(::mlir::DialectBytecodeWriter &writer) { - auto &prop = getProperties(); (void)prop; - writer.writeAttribute(prop.callee); -} - -::mlir::FlatSymbolRefAttr GenericCallOp::getCalleeAttr() { - return ::llvm::cast<::mlir::FlatSymbolRefAttr>(getProperties().callee); -} - -::llvm::StringRef GenericCallOp::getCallee() { - auto attr = getCalleeAttr(); - return attr.getValue(); -} - -void GenericCallOp::setCalleeAttr(::mlir::FlatSymbolRefAttr attr) { - (*this)->setAttr(getCalleeAttrName(), attr); -} - -void GenericCallOp::setCallee(::llvm::StringRef attrValue) { - (*this)->setAttr(getCalleeAttrName(), ::mlir::SymbolRefAttr::get(::mlir::Builder((*this)->getContext()).getContext(), attrValue)); -} - -void GenericCallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::FlatSymbolRefAttr callee, ::mlir::ValueRange inputs) { - odsState.addOperands(inputs); - odsState.getOrAddProperties().callee = callee; - odsState.addTypes(resultType0); -} - -void GenericCallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::FlatSymbolRefAttr callee, ::mlir::ValueRange inputs) { - odsState.addOperands(inputs); - odsState.getOrAddProperties().callee = callee; - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void GenericCallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::llvm::StringRef callee, ::mlir::ValueRange inputs) { - odsState.addOperands(inputs); - odsState.getOrAddProperties().callee = ::mlir::SymbolRefAttr::get(odsBuilder.getContext(), callee); - odsState.addTypes(resultType0); -} - -void GenericCallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::llvm::StringRef callee, ::mlir::ValueRange inputs) { - odsState.addOperands(inputs); - odsState.getOrAddProperties().callee = ::mlir::SymbolRefAttr::get(odsBuilder.getContext(), callee); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void GenericCallOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult GenericCallOp::verifyInvariantsImpl() { - auto tblgen_callee = getProperties().callee; (void)tblgen_callee; - if (!tblgen_callee) return emitOpError("requires attribute 'callee'"); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops4(*this, tblgen_callee, "callee"))) - return ::mlir::failure(); - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops1(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult GenericCallOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -::mlir::ParseResult GenericCallOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::FlatSymbolRefAttr calleeAttr; - ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> inputsOperands; - ::llvm::SMLoc inputsOperandsLoc; - (void)inputsOperandsLoc; - ::llvm::ArrayRef<::mlir::Type> inputsTypes; - ::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(); - - inputsOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperandList(inputsOperands)) - 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 inputs__allResult_functionType; - if (parser.parseType(inputs__allResult_functionType)) - return ::mlir::failure(); - inputsTypes = inputs__allResult_functionType.getInputs(); - allResultTypes = inputs__allResult_functionType.getResults(); - result.addTypes(allResultTypes); - if (parser.resolveOperands(inputsOperands, inputsTypes, inputsOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void GenericCallOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << ' '; - _odsPrinter.printAttributeWithoutType(getCalleeAttr()); - _odsPrinter << "("; - _odsPrinter << getInputs(); - _odsPrinter << ")"; - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - elidedAttrs.push_back("callee"); - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - _odsPrinter.printFunctionalType(getInputs().getTypes(), getOperation()->getResultTypes()); -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::GenericCallOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::MulOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -MulOpGenericAdaptorBase::MulOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.mul", odsAttrs.getContext()); -} - -MulOpGenericAdaptorBase::MulOpGenericAdaptorBase(MulOp op) : MulOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair MulOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr MulOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -MulOpAdaptor::MulOpAdaptor(MulOp op) : MulOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult MulOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair MulOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range MulOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> MulOp::getLhs() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::TypedValue<::mlir::TensorType> MulOp::getRhs() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(1).begin()); -} - -::mlir::OpOperand &MulOp::getLhsMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -::mlir::OpOperand &MulOp::getRhsMutable() { - auto range = getODSOperandIndexAndLength(1); - return getOperation()->getOpOperand(range.first); -} - -std::pair MulOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range MulOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void MulOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value lhs, ::mlir::Value rhs) { - odsState.addOperands(lhs); - odsState.addOperands(rhs); - odsState.addTypes(resultType0); -} - -void MulOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs) { - odsState.addOperands(lhs); - odsState.addOperands(rhs); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void MulOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 2u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult MulOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*this, v.getType(), "operand", index++))) - return ::mlir::failure(); - } - auto valueGroup1 = getODSOperands(1); - - for (auto v : valueGroup1) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult MulOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -void MulOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::MulOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::PrintOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -PrintOpGenericAdaptorBase::PrintOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.print", odsAttrs.getContext()); -} - -PrintOpGenericAdaptorBase::PrintOpGenericAdaptorBase(PrintOp op) : PrintOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair PrintOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr PrintOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -PrintOpAdaptor::PrintOpAdaptor(PrintOp op) : PrintOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult PrintOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair PrintOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range PrintOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> PrintOp::getInput() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::OpOperand &PrintOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -std::pair PrintOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range PrintOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void PrintOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value input) { - odsState.addOperands(input); -} - -void PrintOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input) { - odsState.addOperands(input); - assert(resultTypes.size() == 0u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void PrintOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 1u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 0u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult PrintOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*this, v.getType(), "operand", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult PrintOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -::mlir::ParseResult PrintOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::OpAsmParser::UnresolvedOperand inputRawOperands[1]; - ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> inputOperands(inputRawOperands); ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::mlir::Type inputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> inputTypes(inputRawTypes); - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperand(inputRawOperands[0])) - return ::mlir::failure(); - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.parseColon()) - return ::mlir::failure(); - - { - ::mlir::TensorType type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - inputRawTypes[0] = type; - } - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void PrintOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << ' '; - _odsPrinter << getInput(); - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - { - auto type = getInput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::TensorType>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::PrintOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ReshapeOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -ReshapeOpGenericAdaptorBase::ReshapeOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.reshape", odsAttrs.getContext()); -} - -ReshapeOpGenericAdaptorBase::ReshapeOpGenericAdaptorBase(ReshapeOp op) : ReshapeOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair ReshapeOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr ReshapeOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -ReshapeOpAdaptor::ReshapeOpAdaptor(ReshapeOp op) : ReshapeOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult ReshapeOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair ReshapeOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range ReshapeOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> ReshapeOp::getInput() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::OpOperand &ReshapeOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -std::pair ReshapeOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range ReshapeOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void ReshapeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value input) { - odsState.addOperands(input); - odsState.addTypes(resultType0); -} - -void ReshapeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input) { - odsState.addOperands(input); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void ReshapeOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 1u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult ReshapeOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops2(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult ReshapeOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -::mlir::ParseResult ReshapeOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::OpAsmParser::UnresolvedOperand inputRawOperands[1]; - ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> inputOperands(inputRawOperands); ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::mlir::Type inputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> inputTypes(inputRawTypes); - ::llvm::SmallVector<::mlir::Type, 1> allResultTypes; - if (parser.parseLParen()) - return ::mlir::failure(); - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperand(inputRawOperands[0])) - return ::mlir::failure(); - if (parser.parseColon()) - return ::mlir::failure(); - - { - ::mlir::TensorType type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - inputRawTypes[0] = type; - } - if (parser.parseRParen()) - return ::mlir::failure(); - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.parseKeyword("to")) - return ::mlir::failure(); - - if (parser.parseTypeList(allResultTypes)) - return ::mlir::failure(); - result.addTypes(allResultTypes); - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void ReshapeOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << "("; - _odsPrinter << getInput(); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - { - auto type = getInput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::TensorType>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } - _odsPrinter << ")"; - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << "to"; - _odsPrinter << ' '; - _odsPrinter << getOperation()->getResultTypes(); -} - -void ReshapeOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::ReshapeOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ReturnOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -ReturnOpGenericAdaptorBase::ReturnOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.return", odsAttrs.getContext()); -} - -ReturnOpGenericAdaptorBase::ReturnOpGenericAdaptorBase(ReturnOp op) : ReturnOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), 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}; -} - -::mlir::DictionaryAttr ReturnOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -ReturnOpAdaptor::ReturnOpAdaptor(ReturnOp op) : ReturnOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::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::Operation::operand_range ReturnOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::Operation::operand_range ReturnOp::getInput() { - return getODSOperands(0); -} - -::mlir::MutableOperandRange ReturnOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); - return mutableRange; -} - -std::pair ReturnOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range ReturnOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void ReturnOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState) { - build(odsBuilder, odsState, std::nullopt); -} - -void ReturnOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange input) { - odsState.addOperands(input); -} - -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); -} - -::mlir::LogicalResult ReturnOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops1(*this, v.getType(), "operand", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult ReturnOp::verifyInvariants() { - if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) - return ::mlir::success(); - return ::mlir::failure(); -} - -::mlir::ParseResult ReturnOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> inputOperands; - ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::llvm::SmallVector<::mlir::Type, 1> inputTypes; - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperandList(inputOperands)) - return ::mlir::failure(); - if (!inputOperands.empty()) { - if (parser.parseColon()) - return ::mlir::failure(); - - if (parser.parseTypeList(inputTypes)) - return ::mlir::failure(); - } - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void ReturnOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - if (!getInput().empty()) { - _odsPrinter << ' '; - _odsPrinter << getInput(); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - _odsPrinter << getInput().getTypes(); - } - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); -} - -void ReturnOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::ReturnOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::TransposeOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -TransposeOpGenericAdaptorBase::TransposeOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.transpose", odsAttrs.getContext()); -} - -TransposeOpGenericAdaptorBase::TransposeOpGenericAdaptorBase(TransposeOp op) : TransposeOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair TransposeOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr TransposeOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -TransposeOpAdaptor::TransposeOpAdaptor(TransposeOp op) : TransposeOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult TransposeOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair TransposeOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range TransposeOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> TransposeOp::getInput() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::OpOperand &TransposeOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -std::pair TransposeOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range TransposeOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void TransposeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value input) { - odsState.addOperands(input); - odsState.addTypes(resultType0); -} - -void TransposeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input) { - odsState.addOperands(input); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void TransposeOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 1u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult TransposeOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult TransposeOp::verifyInvariants() { - if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) - return ::mlir::success(); - return ::mlir::failure(); -} - -::mlir::ParseResult TransposeOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::OpAsmParser::UnresolvedOperand inputRawOperands[1]; - ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> inputOperands(inputRawOperands); ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::mlir::Type inputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> inputTypes(inputRawTypes); - ::llvm::SmallVector<::mlir::Type, 1> allResultTypes; - if (parser.parseLParen()) - return ::mlir::failure(); - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperand(inputRawOperands[0])) - return ::mlir::failure(); - if (parser.parseColon()) - return ::mlir::failure(); - - { - ::mlir::TensorType type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - inputRawTypes[0] = type; - } - if (parser.parseRParen()) - return ::mlir::failure(); - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.parseKeyword("to")) - return ::mlir::failure(); - - if (parser.parseTypeList(allResultTypes)) - return ::mlir::failure(); - result.addTypes(allResultTypes); - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void TransposeOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << "("; - _odsPrinter << getInput(); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - { - auto type = getInput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::TensorType>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } - _odsPrinter << ")"; - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << "to"; - _odsPrinter << ' '; - _odsPrinter << getOperation()->getResultTypes(); -} - -void TransposeOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::TransposeOp) - - -#endif // GET_OP_CLASSES - diff --git a/Ch4/include/toy/Ops.h.inc b/Ch4/include/toy/Ops.h.inc deleted file mode 100644 index ad68406..0000000 --- a/Ch4/include/toy/Ops.h.inc +++ /dev/null @@ -1,1360 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Op Declarations *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: Ops.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -#if defined(GET_OP_CLASSES) || defined(GET_OP_FWD_DEFINES) -#undef GET_OP_FWD_DEFINES -namespace mlir { -namespace toy { -class AddOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class CastOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class ConstantOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class FuncOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class GenericCallOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class MulOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class PrintOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class ReshapeOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class ReturnOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class TransposeOp; -} // namespace toy -} // namespace mlir -#endif - -#ifdef GET_OP_CLASSES -#undef GET_OP_CLASSES - - -//===----------------------------------------------------------------------===// -// Local Utility Method Definitions -//===----------------------------------------------------------------------===// - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::AddOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class AddOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - AddOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - AddOpGenericAdaptorBase(AddOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class AddOpGenericAdaptor : public detail::AddOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::AddOpGenericAdaptorBase; -public: - AddOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - AddOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : AddOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - AddOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getLhs() { - return (*getODSOperands(0).begin()); - } - - ValueT getRhs() { - return (*getODSOperands(1).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class AddOpAdaptor : public AddOpGenericAdaptor<::mlir::ValueRange> { -public: - using AddOpGenericAdaptor::AddOpGenericAdaptor; - AddOpAdaptor(AddOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class AddOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::NOperands<2>::Impl, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait, ShapeInference::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = AddOpAdaptor; - template - using GenericAdaptor = AddOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.add"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getLhs(); - ::mlir::TypedValue<::mlir::TensorType> getRhs(); - ::mlir::OpOperand &getLhsMutable(); - ::mlir::OpOperand &getRhsMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, Value lhs, Value rhs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value lhs, ::mlir::Value rhs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &p); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - void inferShapes(); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::AddOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::CastOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class CastOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - CastOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - CastOpGenericAdaptorBase(CastOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class CastOpGenericAdaptor : public detail::CastOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::CastOpGenericAdaptorBase; -public: - CastOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - CastOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : CastOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - CastOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getInput() { - return (*getODSOperands(0).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class CastOpAdaptor : public CastOpGenericAdaptor<::mlir::ValueRange> { -public: - using CastOpGenericAdaptor::CastOpGenericAdaptor; - CastOpAdaptor(CastOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class CastOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::OneOperand, ::mlir::OpTrait::OpInvariants, ::mlir::CastOpInterface::Trait, ShapeInference::Trait, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait, ::mlir::OpTrait::SameOperandsAndResultShape> { -public: - using Op::Op; - using Op::print; - using Adaptor = CastOpAdaptor; - template - using GenericAdaptor = CastOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.cast"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getInput(); - ::mlir::OpOperand &getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getOutput(); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type output, ::mlir::Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - static bool areCastCompatible(::mlir::TypeRange inputs, ::mlir::TypeRange outputs); - void inferShapes(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::CastOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ConstantOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class ConstantOpGenericAdaptorBase { -public: - struct Properties { - using valueTy = ::mlir::DenseElementsAttr; - valueTy value; - - auto getValue() { - auto &propStorage = this->value; - return ::llvm::cast<::mlir::DenseElementsAttr>(propStorage); - } - void setValue(const ::mlir::DenseElementsAttr &propValue) { - this->value = propValue; - } - bool operator==(const Properties &rhs) const { - return - rhs.value == this->value && - true; - } - bool operator!=(const Properties &rhs) const { - return !(*this == rhs); - } - }; -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - Properties properties; - ::mlir::RegionRange odsRegions; -public: - ConstantOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}); - - ConstantOpGenericAdaptorBase(ConstantOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - const Properties &getProperties() { - return properties; - } - - ::mlir::DictionaryAttr getAttributes(); - ::mlir::DenseElementsAttr getValueAttr(); - ::mlir::DenseElementsAttr getValue(); -}; -} // namespace detail -template -class ConstantOpGenericAdaptor : public detail::ConstantOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::ConstantOpGenericAdaptorBase; -public: - ConstantOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - ConstantOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : ConstantOpGenericAdaptor(values, attrs, (properties ? *properties.as() : Properties{}), regions) {} - - template >> - ConstantOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class ConstantOpAdaptor : public ConstantOpGenericAdaptor<::mlir::ValueRange> { -public: - using ConstantOpGenericAdaptor::ConstantOpGenericAdaptor; - ConstantOpAdaptor(ConstantOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class ConstantOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::ZeroOperands, ::mlir::OpTrait::OpInvariants, ::mlir::BytecodeOpInterface::Trait, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = ConstantOpAdaptor; - template - using GenericAdaptor = ConstantOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - using Properties = FoldAdaptor::Properties; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - static ::llvm::StringRef attrNames[] = {::llvm::StringRef("value")}; - return ::llvm::ArrayRef(attrNames); - } - - ::mlir::StringAttr getValueAttrName() { - return getAttributeNameForIndex(0); - } - - static ::mlir::StringAttr getValueAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 0); - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.constant"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static ::mlir::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop); - static llvm::hash_code computePropertiesHash(const Properties &prop); - static std::optional getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name); - static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value); - static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs); - static ::mlir::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::LogicalResult readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state); - void writeProperties(::mlir::DialectBytecodeWriter &writer); - ::mlir::DenseElementsAttr getValueAttr(); - ::mlir::DenseElementsAttr getValue(); - void setValueAttr(::mlir::DenseElementsAttr attr); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, DenseElementsAttr value); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, double value); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::DenseElementsAttr value); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::DenseElementsAttr value); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &p); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - ::mlir::LogicalResult verify(); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -private: - ::mlir::StringAttr getAttributeNameForIndex(unsigned index) { - return getAttributeNameForIndex((*this)->getName(), index); - } - - static ::mlir::StringAttr getAttributeNameForIndex(::mlir::OperationName name, unsigned index) { - assert(index < 1 && "invalid attribute index"); - assert(name.getStringRef() == getOperationName() && "invalid operation name"); - assert(name.isRegistered() && "Operation isn't registered, missing a " - "dependent dialect loading?"); - return name.getAttributeNames()[index]; - } - -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::ConstantOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::FuncOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class FuncOpGenericAdaptorBase { -public: - struct Properties { - using arg_attrsTy = ::mlir::ArrayAttr; - arg_attrsTy arg_attrs; - - auto getArgAttrs() { - auto &propStorage = this->arg_attrs; - return ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(propStorage); - } - void setArgAttrs(const ::mlir::ArrayAttr &propValue) { - this->arg_attrs = propValue; - } - using function_typeTy = ::mlir::TypeAttr; - function_typeTy function_type; - - auto getFunctionType() { - auto &propStorage = this->function_type; - return ::llvm::cast<::mlir::TypeAttr>(propStorage); - } - void setFunctionType(const ::mlir::TypeAttr &propValue) { - this->function_type = propValue; - } - using res_attrsTy = ::mlir::ArrayAttr; - res_attrsTy res_attrs; - - auto getResAttrs() { - auto &propStorage = this->res_attrs; - return ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(propStorage); - } - void setResAttrs(const ::mlir::ArrayAttr &propValue) { - this->res_attrs = propValue; - } - using sym_nameTy = ::mlir::StringAttr; - sym_nameTy sym_name; - - auto getSymName() { - auto &propStorage = this->sym_name; - return ::llvm::cast<::mlir::StringAttr>(propStorage); - } - void setSymName(const ::mlir::StringAttr &propValue) { - this->sym_name = propValue; - } - bool operator==(const Properties &rhs) const { - return - rhs.arg_attrs == this->arg_attrs && - rhs.function_type == this->function_type && - rhs.res_attrs == this->res_attrs && - rhs.sym_name == this->sym_name && - true; - } - bool operator!=(const Properties &rhs) const { - return !(*this == rhs); - } - }; -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - Properties properties; - ::mlir::RegionRange odsRegions; -public: - FuncOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}); - - FuncOpGenericAdaptorBase(FuncOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - const Properties &getProperties() { - return properties; - } - - ::mlir::DictionaryAttr getAttributes(); - ::mlir::StringAttr getSymNameAttr(); - ::llvm::StringRef getSymName(); - ::mlir::TypeAttr getFunctionTypeAttr(); - ::mlir::FunctionType getFunctionType(); - ::mlir::ArrayAttr getArgAttrsAttr(); - ::std::optional< ::mlir::ArrayAttr > getArgAttrs(); - ::mlir::ArrayAttr getResAttrsAttr(); - ::std::optional< ::mlir::ArrayAttr > getResAttrs(); - ::mlir::Region &getBody(); - ::mlir::RegionRange getRegions(); -}; -} // namespace detail -template -class FuncOpGenericAdaptor : public detail::FuncOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::FuncOpGenericAdaptorBase; -public: - FuncOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - FuncOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : FuncOpGenericAdaptor(values, attrs, (properties ? *properties.as() : Properties{}), regions) {} - - template >> - FuncOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class FuncOpAdaptor : public FuncOpGenericAdaptor<::mlir::ValueRange> { -public: - using FuncOpGenericAdaptor::FuncOpGenericAdaptor; - FuncOpAdaptor(FuncOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class FuncOp : public ::mlir::Op { -public: - using Op::Op; - using Op::print; - using Adaptor = FuncOpAdaptor; - template - using GenericAdaptor = FuncOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - using Properties = FoldAdaptor::Properties; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - static ::llvm::StringRef attrNames[] = {::llvm::StringRef("arg_attrs"), ::llvm::StringRef("function_type"), ::llvm::StringRef("res_attrs"), ::llvm::StringRef("sym_name")}; - return ::llvm::ArrayRef(attrNames); - } - - ::mlir::StringAttr getArgAttrsAttrName() { - return getAttributeNameForIndex(0); - } - - static ::mlir::StringAttr getArgAttrsAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 0); - } - - ::mlir::StringAttr getFunctionTypeAttrName() { - return getAttributeNameForIndex(1); - } - - static ::mlir::StringAttr getFunctionTypeAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 1); - } - - ::mlir::StringAttr getResAttrsAttrName() { - return getAttributeNameForIndex(2); - } - - static ::mlir::StringAttr getResAttrsAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 2); - } - - ::mlir::StringAttr getSymNameAttrName() { - return getAttributeNameForIndex(3); - } - - static ::mlir::StringAttr getSymNameAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 3); - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.func"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - ::mlir::Region &getBody(); - static ::mlir::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop); - static llvm::hash_code computePropertiesHash(const Properties &prop); - static std::optional getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name); - static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value); - static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs); - static ::mlir::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::LogicalResult readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state); - void writeProperties(::mlir::DialectBytecodeWriter &writer); - ::mlir::StringAttr getSymNameAttr(); - ::llvm::StringRef getSymName(); - ::mlir::TypeAttr getFunctionTypeAttr(); - ::mlir::FunctionType getFunctionType(); - ::mlir::ArrayAttr getArgAttrsAttr(); - ::std::optional< ::mlir::ArrayAttr > getArgAttrs(); - ::mlir::ArrayAttr getResAttrsAttr(); - ::std::optional< ::mlir::ArrayAttr > getResAttrs(); - void setSymNameAttr(::mlir::StringAttr attr); - void setSymName(::llvm::StringRef attrValue); - void setFunctionTypeAttr(::mlir::TypeAttr attr); - void setFunctionType(::mlir::FunctionType attrValue); - void setArgAttrsAttr(::mlir::ArrayAttr attr); - void setResAttrsAttr(::mlir::ArrayAttr attr); - ::mlir::Attribute removeArgAttrsAttr(); - ::mlir::Attribute removeResAttrsAttr(); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, StringRef name, FunctionType type, ArrayRef attrs = {}); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &p); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); -private: - ::mlir::StringAttr getAttributeNameForIndex(unsigned index) { - return getAttributeNameForIndex((*this)->getName(), index); - } - - static ::mlir::StringAttr getAttributeNameForIndex(::mlir::OperationName name, unsigned index) { - assert(index < 4 && "invalid attribute index"); - assert(name.getStringRef() == getOperationName() && "invalid operation name"); - assert(name.isRegistered() && "Operation isn't registered, missing a " - "dependent dialect loading?"); - return name.getAttributeNames()[index]; - } - -public: - //===------------------------------------------------------------------===// - // FunctionOpInterface Methods - //===------------------------------------------------------------------===// - - /// Returns the argument types of this function. - ArrayRef getArgumentTypes() { return getFunctionType().getInputs(); } - - /// Returns the result types of this function. - ArrayRef getResultTypes() { return getFunctionType().getResults(); } - - Region *getCallableRegion() { return &getBody(); } -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::FuncOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::GenericCallOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class GenericCallOpGenericAdaptorBase { -public: - struct Properties { - using calleeTy = ::mlir::FlatSymbolRefAttr; - calleeTy callee; - - auto getCallee() { - auto &propStorage = this->callee; - return ::llvm::cast<::mlir::FlatSymbolRefAttr>(propStorage); - } - void setCallee(const ::mlir::FlatSymbolRefAttr &propValue) { - this->callee = propValue; - } - bool operator==(const Properties &rhs) const { - return - rhs.callee == this->callee && - true; - } - bool operator!=(const Properties &rhs) const { - return !(*this == rhs); - } - }; -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - Properties properties; - ::mlir::RegionRange odsRegions; -public: - GenericCallOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}); - - GenericCallOpGenericAdaptorBase(GenericCallOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - const Properties &getProperties() { - return properties; - } - - ::mlir::DictionaryAttr getAttributes(); - ::mlir::FlatSymbolRefAttr getCalleeAttr(); - ::llvm::StringRef getCallee(); -}; -} // namespace detail -template -class GenericCallOpGenericAdaptor : public detail::GenericCallOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::GenericCallOpGenericAdaptorBase; -public: - GenericCallOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - GenericCallOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : GenericCallOpGenericAdaptor(values, attrs, (properties ? *properties.as() : Properties{}), regions) {} - - template >> - GenericCallOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - RangeT getInputs() { - return getODSOperands(0); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class GenericCallOpAdaptor : public GenericCallOpGenericAdaptor<::mlir::ValueRange> { -public: - using GenericCallOpGenericAdaptor::GenericCallOpGenericAdaptor; - GenericCallOpAdaptor(GenericCallOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class GenericCallOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::VariadicOperands, ::mlir::OpTrait::OpInvariants, ::mlir::BytecodeOpInterface::Trait, ::mlir::CallOpInterface::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = GenericCallOpAdaptor; - template - using GenericAdaptor = GenericCallOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - using Properties = FoldAdaptor::Properties; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - static ::llvm::StringRef attrNames[] = {::llvm::StringRef("callee")}; - return ::llvm::ArrayRef(attrNames); - } - - ::mlir::StringAttr getCalleeAttrName() { - return getAttributeNameForIndex(0); - } - - static ::mlir::StringAttr getCalleeAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 0); - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.generic_call"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::Operation::operand_range getInputs(); - ::mlir::MutableOperandRange getInputsMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static ::mlir::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop); - static llvm::hash_code computePropertiesHash(const Properties &prop); - static std::optional getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name); - static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value); - static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs); - static ::mlir::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::LogicalResult readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state); - void writeProperties(::mlir::DialectBytecodeWriter &writer); - ::mlir::FlatSymbolRefAttr getCalleeAttr(); - ::llvm::StringRef getCallee(); - void setCalleeAttr(::mlir::FlatSymbolRefAttr attr); - void setCallee(::llvm::StringRef attrValue); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, StringRef callee, ArrayRef arguments); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::FlatSymbolRefAttr callee, ::mlir::ValueRange inputs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::FlatSymbolRefAttr callee, ::mlir::ValueRange inputs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::llvm::StringRef callee, ::mlir::ValueRange inputs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::llvm::StringRef callee, ::mlir::ValueRange inputs); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - ::mlir::CallInterfaceCallable getCallableForCallee(); - void setCalleeFromCallable(::mlir::CallInterfaceCallable callee); - ::mlir::Operation::operand_range getArgOperands(); - ::mlir::MutableOperandRange getArgOperandsMutable(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); -private: - ::mlir::StringAttr getAttributeNameForIndex(unsigned index) { - return getAttributeNameForIndex((*this)->getName(), index); - } - - static ::mlir::StringAttr getAttributeNameForIndex(::mlir::OperationName name, unsigned index) { - assert(index < 1 && "invalid attribute index"); - assert(name.getStringRef() == getOperationName() && "invalid operation name"); - assert(name.isRegistered() && "Operation isn't registered, missing a " - "dependent dialect loading?"); - return name.getAttributeNames()[index]; - } - -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::GenericCallOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::MulOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class MulOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - MulOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - MulOpGenericAdaptorBase(MulOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class MulOpGenericAdaptor : public detail::MulOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::MulOpGenericAdaptorBase; -public: - MulOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - MulOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : MulOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - MulOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getLhs() { - return (*getODSOperands(0).begin()); - } - - ValueT getRhs() { - return (*getODSOperands(1).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class MulOpAdaptor : public MulOpGenericAdaptor<::mlir::ValueRange> { -public: - using MulOpGenericAdaptor::MulOpGenericAdaptor; - MulOpAdaptor(MulOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class MulOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::NOperands<2>::Impl, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait, ShapeInference::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = MulOpAdaptor; - template - using GenericAdaptor = MulOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.mul"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getLhs(); - ::mlir::TypedValue<::mlir::TensorType> getRhs(); - ::mlir::OpOperand &getLhsMutable(); - ::mlir::OpOperand &getRhsMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, Value lhs, Value rhs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value lhs, ::mlir::Value rhs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &p); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - void inferShapes(); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::MulOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::PrintOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class PrintOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - PrintOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - PrintOpGenericAdaptorBase(PrintOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class PrintOpGenericAdaptor : public detail::PrintOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::PrintOpGenericAdaptorBase; -public: - PrintOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - PrintOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : PrintOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - PrintOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getInput() { - return (*getODSOperands(0).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class PrintOpAdaptor : public PrintOpGenericAdaptor<::mlir::ValueRange> { -public: - using PrintOpGenericAdaptor::PrintOpGenericAdaptor; - PrintOpAdaptor(PrintOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class PrintOp : public ::mlir::Op { -public: - using Op::Op; - using Op::print; - using Adaptor = PrintOpAdaptor; - template - using GenericAdaptor = PrintOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.print"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getInput(); - ::mlir::OpOperand &getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::PrintOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ReshapeOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class ReshapeOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - ReshapeOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - ReshapeOpGenericAdaptorBase(ReshapeOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class ReshapeOpGenericAdaptor : public detail::ReshapeOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::ReshapeOpGenericAdaptorBase; -public: - ReshapeOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - ReshapeOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : ReshapeOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - ReshapeOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getInput() { - return (*getODSOperands(0).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class ReshapeOpAdaptor : public ReshapeOpGenericAdaptor<::mlir::ValueRange> { -public: - using ReshapeOpGenericAdaptor::ReshapeOpGenericAdaptor; - ReshapeOpAdaptor(ReshapeOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class ReshapeOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::OneOperand, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = ReshapeOpAdaptor; - template - using GenericAdaptor = ReshapeOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.reshape"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getInput(); - ::mlir::OpOperand &getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - static void getCanonicalizationPatterns(::mlir::RewritePatternSet &results, ::mlir::MLIRContext *context); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::ReshapeOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ReturnOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class ReturnOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - ReturnOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - ReturnOpGenericAdaptorBase(ReturnOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class ReturnOpGenericAdaptor : public detail::ReturnOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::ReturnOpGenericAdaptorBase; -public: - ReturnOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - ReturnOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : ReturnOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - ReturnOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - RangeT getInput() { - return getODSOperands(0); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class ReturnOpAdaptor : public ReturnOpGenericAdaptor<::mlir::ValueRange> { -public: - using ReturnOpGenericAdaptor::ReturnOpGenericAdaptor; - ReturnOpAdaptor(ReturnOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class ReturnOp : public ::mlir::Op::Impl, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait, ::mlir::OpTrait::IsTerminator> { -public: - using Op::Op; - using Op::print; - using Adaptor = ReturnOpAdaptor; - template - using GenericAdaptor = ReturnOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.return"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::Operation::operand_range getInput(); - ::mlir::MutableOperandRange getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - ::mlir::LogicalResult verify(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: - bool hasOperand() { return getNumOperands() != 0; } -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::ReturnOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::TransposeOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class TransposeOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - TransposeOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - TransposeOpGenericAdaptorBase(TransposeOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class TransposeOpGenericAdaptor : public detail::TransposeOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::TransposeOpGenericAdaptorBase; -public: - TransposeOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - TransposeOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : TransposeOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - TransposeOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getInput() { - return (*getODSOperands(0).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class TransposeOpAdaptor : public TransposeOpGenericAdaptor<::mlir::ValueRange> { -public: - using TransposeOpGenericAdaptor::TransposeOpGenericAdaptor; - TransposeOpAdaptor(TransposeOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class TransposeOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::OneOperand, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait, ShapeInference::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = TransposeOpAdaptor; - template - using GenericAdaptor = TransposeOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.transpose"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getInput(); - ::mlir::OpOperand &getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - ::mlir::LogicalResult verify(); - static void getCanonicalizationPatterns(::mlir::RewritePatternSet &results, ::mlir::MLIRContext *context); - void inferShapes(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::TransposeOp) - - -#endif // GET_OP_CLASSES - diff --git a/Ch4/include/toy/ShapeInferenceOpInterfaces.cpp.inc b/Ch4/include/toy/ShapeInferenceOpInterfaces.cpp.inc deleted file mode 100644 index a481d2e..0000000 --- a/Ch4/include/toy/ShapeInferenceOpInterfaces.cpp.inc +++ /dev/null @@ -1,12 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Interface Definitions *| -|* *| -|* Automatically generated file, do not edit! *| -|* *| -\*===----------------------------------------------------------------------===*/ - -/// Infer and set the output shape for the current operation. -void ShapeInference::inferShapes() { - return getImpl()->inferShapes(getImpl(), getOperation()); - } diff --git a/Ch4/include/toy/ShapeInferenceOpInterfaces.h.inc b/Ch4/include/toy/ShapeInferenceOpInterfaces.h.inc deleted file mode 100644 index bb24654..0000000 --- a/Ch4/include/toy/ShapeInferenceOpInterfaces.h.inc +++ /dev/null @@ -1,61 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Interface Declarations *| -|* *| -|* Automatically generated file, do not edit! *| -|* *| -\*===----------------------------------------------------------------------===*/ - -class ShapeInference; -namespace detail { -struct ShapeInferenceInterfaceTraits { - struct Concept { - /// The methods defined by the interface. - void (*inferShapes)(const Concept *impl, ::mlir::Operation *); - }; - template - class Model : public Concept { - public: - using Interface = ShapeInference; - Model() : Concept{inferShapes} {} - - static inline void inferShapes(const Concept *impl, ::mlir::Operation *tablegen_opaque_val); - }; - template - class FallbackModel : public Concept { - public: - using Interface = ShapeInference; - FallbackModel() : Concept{inferShapes} {} - - static inline void inferShapes(const Concept *impl, ::mlir::Operation *tablegen_opaque_val); - }; - template - class ExternalModel : public FallbackModel { - public: - using ConcreteEntity = ConcreteOp; - }; -};template -struct ShapeInferenceTrait; - -} // namespace detail -class ShapeInference : public ::mlir::OpInterface { -public: - using ::mlir::OpInterface::OpInterface; - template - struct Trait : public detail::ShapeInferenceTrait {}; - /// Infer and set the output shape for the current operation. - void inferShapes(); -}; -namespace detail { - template - struct ShapeInferenceTrait : public ::mlir::OpInterface::Trait { - }; -}// namespace detail -template -void detail::ShapeInferenceInterfaceTraits::Model::inferShapes(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) { - return (llvm::cast(tablegen_opaque_val)).inferShapes(); -} -template -void detail::ShapeInferenceInterfaceTraits::FallbackModel::inferShapes(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) { - return static_cast(impl)->inferShapes(tablegen_opaque_val); -} diff --git a/Ch4/include/toy/run.sh b/Ch4/include/toy/run.sh deleted file mode 100644 index b9d18af..0000000 --- a/Ch4/include/toy/run.sh +++ /dev/null @@ -1,7 +0,0 @@ -mlir-tblgen-18 -gen-op-decls -I /usr/lib/llvm-18/include toy/Ops.td > toy/Ops.h.inc -mlir-tblgen-18 -gen-op-defs -I /usr/lib/llvm-18/include toy/Ops.td > toy/Ops.cpp.inc -mlir-tblgen-18 -gen-dialect-decls -I /usr/lib/llvm-18/include toy/Ops.td > toy/Dialect.h.inc -mlir-tblgen-18 -gen-dialect-defs -I /usr/lib/llvm-18/include toy/Ops.td > toy/Dialect.cpp.inc - -mlir-tblgen-18 -gen-op-interface-decls -I /usr/lib/llvm-18/include toy/ShapeInferenceInterface.td > toy/ShapeInferenceOpInterfaces.h.inc -mlir-tblgen-18 -gen-op-interface-defs -I /usr/lib/llvm-18/include toy/ShapeInferenceInterface.td > toy/ShapeInferenceOpInterfaces.cpp.inc diff --git a/Ch4/mlir/ToyCombine.inc b/Ch4/mlir/ToyCombine.inc deleted file mode 100644 index 61c6203..0000000 --- a/Ch4/mlir/ToyCombine.inc +++ /dev/null @@ -1,176 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Rewriters *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: ToyCombine.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -/* Generated from: - ToyCombine.td:46 -*/ -struct FoldConstantReshapeOptPattern : public ::mlir::RewritePattern { - FoldConstantReshapeOptPattern(::mlir::MLIRContext *context) - : ::mlir::RewritePattern("toy.reshape", 2, context, {"toy.constant"}) {} - ::mlir::LogicalResult matchAndRewrite(::mlir::Operation *op0, - ::mlir::PatternRewriter &rewriter) const override { - // Variables for capturing values and attributes used while creating ops - ::mlir::DenseElementsAttr arg; - ::mlir::toy::ReshapeOp res; - ::llvm::SmallVector<::mlir::Operation *, 4> tblgen_ops; - - // Match - tblgen_ops.push_back(op0); - auto castedOp0 = ::llvm::dyn_cast<::mlir::toy::ReshapeOp>(op0); (void)castedOp0; - res = castedOp0; - { - auto *op1 = (*castedOp0.getODSOperands(0).begin()).getDefiningOp(); - if (!(op1)){ - return rewriter.notifyMatchFailure(castedOp0, [&](::mlir::Diagnostic &diag) { - diag << "There's no operation that defines operand 0 of castedOp0"; - }); - } - auto castedOp1 = ::llvm::dyn_cast<::mlir::toy::ConstantOp>(op1); (void)castedOp1; - if (!(castedOp1)){ - return rewriter.notifyMatchFailure(op1, [&](::mlir::Diagnostic &diag) { - diag << "castedOp1 is not ::mlir::toy::ConstantOp type"; - }); - } - { - auto tblgen_attr = op1->getAttrOfType<::mlir::DenseElementsAttr>("value");(void)tblgen_attr; - if (!(tblgen_attr)){ - return rewriter.notifyMatchFailure(op1, [&](::mlir::Diagnostic &diag) { - diag << "expected op 'toy.constant' to have attribute 'value' of type '::mlir::DenseElementsAttr'"; - }); - } - arg = tblgen_attr; - } - tblgen_ops.push_back(op1); - } - - // Rewrite - auto odsLoc = rewriter.getFusedLoc({tblgen_ops[0]->getLoc(), tblgen_ops[1]->getLoc()}); (void)odsLoc; - ::llvm::SmallVector<::mlir::Value, 4> tblgen_repl_values; - auto nativeVar_0 = arg.reshape(::llvm::cast((*res.getODSResults(0).begin()).getType())); (void)nativeVar_0; - ::mlir::toy::ConstantOp tblgen_ConstantOp_1; - { - ::llvm::SmallVector<::mlir::Value, 4> tblgen_values; (void)tblgen_values; - ::llvm::SmallVector<::mlir::NamedAttribute, 4> tblgen_attrs; (void)tblgen_attrs; - if (auto tmpAttr = nativeVar_0) { - tblgen_attrs.emplace_back(rewriter.getStringAttr("value"), tmpAttr); - } - ::llvm::SmallVector<::mlir::Type, 4> tblgen_types; (void)tblgen_types; - for (auto v: castedOp0.getODSResults(0)) { - tblgen_types.push_back(v.getType()); - } - tblgen_ConstantOp_1 = rewriter.create<::mlir::toy::ConstantOp>(odsLoc, tblgen_types, tblgen_values, tblgen_attrs); - } - - for (auto v: ::llvm::SmallVector<::mlir::Value, 4>{ tblgen_ConstantOp_1.getODSResults(0) }) { - tblgen_repl_values.push_back(v); - } - - rewriter.replaceOp(op0, tblgen_repl_values); - return ::mlir::success(); - }; -}; - -/* Generated from: - ToyCombine.td:59 -*/ -struct RedundantReshapeOptPattern : public ::mlir::RewritePattern { - RedundantReshapeOptPattern(::mlir::MLIRContext *context) - : ::mlir::RewritePattern("toy.reshape", 1, context, {}) {} - ::mlir::LogicalResult matchAndRewrite(::mlir::Operation *op0, - ::mlir::PatternRewriter &rewriter) const override { - // Variables for capturing values and attributes used while creating ops - ::mlir::Operation::operand_range arg(op0->getOperands()); - ::mlir::toy::ReshapeOp res; - ::llvm::SmallVector<::mlir::Operation *, 4> tblgen_ops; - - // Match - tblgen_ops.push_back(op0); - auto castedOp0 = ::llvm::dyn_cast<::mlir::toy::ReshapeOp>(op0); (void)castedOp0; - res = castedOp0; - arg = castedOp0.getODSOperands(0); - if (!(((*res.getODSResults(0).begin()).getType() == (*arg.begin()).getType()))){ - return rewriter.notifyMatchFailure(op0, [&](::mlir::Diagnostic &diag) { - diag << "entities 'res, arg' failed to satisfy constraint: ''"; - }); - } - - // Rewrite - auto odsLoc = rewriter.getFusedLoc({tblgen_ops[0]->getLoc()}); (void)odsLoc; - ::llvm::SmallVector<::mlir::Value, 4> tblgen_repl_values; - - for (auto v: ::llvm::SmallVector<::mlir::Value, 4>{ arg }) { - tblgen_repl_values.push_back(v); - } - - rewriter.replaceOp(op0, tblgen_repl_values); - return ::mlir::success(); - }; -}; - -/* Generated from: - ToyCombine.td:33 -*/ -struct ReshapeReshapeOptPattern : public ::mlir::RewritePattern { - ReshapeReshapeOptPattern(::mlir::MLIRContext *context) - : ::mlir::RewritePattern("toy.reshape", 2, context, {"toy.reshape"}) {} - ::mlir::LogicalResult matchAndRewrite(::mlir::Operation *op0, - ::mlir::PatternRewriter &rewriter) const override { - // Variables for capturing values and attributes used while creating ops - ::mlir::Operation::operand_range arg(op0->getOperands()); - ::llvm::SmallVector<::mlir::Operation *, 4> tblgen_ops; - - // Match - tblgen_ops.push_back(op0); - auto castedOp0 = ::llvm::dyn_cast<::mlir::toy::ReshapeOp>(op0); (void)castedOp0; - { - auto *op1 = (*castedOp0.getODSOperands(0).begin()).getDefiningOp(); - if (!(op1)){ - return rewriter.notifyMatchFailure(castedOp0, [&](::mlir::Diagnostic &diag) { - diag << "There's no operation that defines operand 0 of castedOp0"; - }); - } - auto castedOp1 = ::llvm::dyn_cast<::mlir::toy::ReshapeOp>(op1); (void)castedOp1; - if (!(castedOp1)){ - return rewriter.notifyMatchFailure(op1, [&](::mlir::Diagnostic &diag) { - diag << "castedOp1 is not ::mlir::toy::ReshapeOp type"; - }); - } - arg = castedOp1.getODSOperands(0); - tblgen_ops.push_back(op1); - } - - // Rewrite - auto odsLoc = rewriter.getFusedLoc({tblgen_ops[0]->getLoc(), tblgen_ops[1]->getLoc()}); (void)odsLoc; - ::llvm::SmallVector<::mlir::Value, 4> tblgen_repl_values; - ::mlir::toy::ReshapeOp tblgen_ReshapeOp_0; - { - ::llvm::SmallVector<::mlir::Value, 4> tblgen_values; (void)tblgen_values; - ::llvm::SmallVector<::mlir::NamedAttribute, 4> tblgen_attrs; (void)tblgen_attrs; - tblgen_values.push_back((*arg.begin())); - ::llvm::SmallVector<::mlir::Type, 4> tblgen_types; (void)tblgen_types; - for (auto v: castedOp0.getODSResults(0)) { - tblgen_types.push_back(v.getType()); - } - tblgen_ReshapeOp_0 = rewriter.create<::mlir::toy::ReshapeOp>(odsLoc, tblgen_types, tblgen_values, tblgen_attrs); - } - - for (auto v: ::llvm::SmallVector<::mlir::Value, 4>{ tblgen_ReshapeOp_0.getODSResults(0) }) { - tblgen_repl_values.push_back(v); - } - - rewriter.replaceOp(op0, tblgen_repl_values); - return ::mlir::success(); - }; -}; - -void LLVM_ATTRIBUTE_UNUSED populateWithGenerated(::mlir::RewritePatternSet &patterns) { - patterns.add(patterns.getContext()); - patterns.add(patterns.getContext()); - patterns.add(patterns.getContext()); -} diff --git a/Ch4/mlir/run.sh b/Ch4/mlir/run.sh deleted file mode 100644 index f592fde..0000000 --- a/Ch4/mlir/run.sh +++ /dev/null @@ -1,2 +0,0 @@ -mlir-tblgen-18 -gen-rewriters -I /usr/lib/llvm-18/include -I ../include ToyCombine.td > ToyCombine.inc - diff --git a/Ch5/CMakeLists.txt b/Ch5/CMakeLists.txt index 43ce7ac..f4f0fec 100644 --- a/Ch5/CMakeLists.txt +++ b/Ch5/CMakeLists.txt @@ -6,11 +6,11 @@ set(LLVM_LINK_COMPONENTS Support ) -# set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td) -# mlir_tablegen(ToyCombine.inc -gen-rewriters) -# add_public_tablegen_target(ToyCh5CombineIncGen) +set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td) +mlir_tablegen(ToyCombine.inc -gen-rewriters) +add_public_tablegen_target(ToyCh5CombineIncGen) -add_executable(toyc-ch5 +add_toy_chapter(toyc-ch5 toyc.cpp parser/AST.cpp mlir/MLIRGen.cpp @@ -19,10 +19,10 @@ add_executable(toyc-ch5 mlir/ShapeInferencePass.cpp mlir/ToyCombine.cpp - # DEPENDS - # ToyCh5ShapeInferenceInterfaceIncGen - # ToyCh5OpsIncGen - # ToyCh5CombineIncGen + DEPENDS + ToyCh5ShapeInferenceInterfaceIncGen + ToyCh5OpsIncGen + ToyCh5CombineIncGen ) include_directories(${CMAKE_CURRENT_BINARY_DIR}) diff --git a/Ch5/include/run.sh b/Ch5/include/run.sh deleted file mode 100644 index b9d18af..0000000 --- a/Ch5/include/run.sh +++ /dev/null @@ -1,7 +0,0 @@ -mlir-tblgen-18 -gen-op-decls -I /usr/lib/llvm-18/include toy/Ops.td > toy/Ops.h.inc -mlir-tblgen-18 -gen-op-defs -I /usr/lib/llvm-18/include toy/Ops.td > toy/Ops.cpp.inc -mlir-tblgen-18 -gen-dialect-decls -I /usr/lib/llvm-18/include toy/Ops.td > toy/Dialect.h.inc -mlir-tblgen-18 -gen-dialect-defs -I /usr/lib/llvm-18/include toy/Ops.td > toy/Dialect.cpp.inc - -mlir-tblgen-18 -gen-op-interface-decls -I /usr/lib/llvm-18/include toy/ShapeInferenceInterface.td > toy/ShapeInferenceOpInterfaces.h.inc -mlir-tblgen-18 -gen-op-interface-defs -I /usr/lib/llvm-18/include toy/ShapeInferenceInterface.td > toy/ShapeInferenceOpInterfaces.cpp.inc diff --git a/Ch5/include/toy/CMakeLists.txt b/Ch5/include/toy/CMakeLists.txt index 4cae256..7d51dd9 100644 --- a/Ch5/include/toy/CMakeLists.txt +++ b/Ch5/include/toy/CMakeLists.txt @@ -1,13 +1,13 @@ -# # Most dialects should use add_mlir_dialect(). See examples/standalone. -# set(LLVM_TARGET_DEFINITIONS Ops.td) -# mlir_tablegen(Ops.h.inc -gen-op-decls) -# mlir_tablegen(Ops.cpp.inc -gen-op-defs) -# mlir_tablegen(Dialect.h.inc -gen-dialect-decls) -# mlir_tablegen(Dialect.cpp.inc -gen-dialect-defs) -# add_public_tablegen_target(ToyCh5OpsIncGen) +# Most dialects should use add_mlir_dialect(). See examples/standalone. +set(LLVM_TARGET_DEFINITIONS Ops.td) +mlir_tablegen(Ops.h.inc -gen-op-decls) +mlir_tablegen(Ops.cpp.inc -gen-op-defs) +mlir_tablegen(Dialect.h.inc -gen-dialect-decls) +mlir_tablegen(Dialect.cpp.inc -gen-dialect-defs) +add_public_tablegen_target(ToyCh5OpsIncGen) -# # Most dialects should use add_mlir_interfaces(). -# set(LLVM_TARGET_DEFINITIONS ShapeInferenceInterface.td) -# mlir_tablegen(ShapeInferenceOpInterfaces.h.inc -gen-op-interface-decls) -# mlir_tablegen(ShapeInferenceOpInterfaces.cpp.inc -gen-op-interface-defs) -# add_public_tablegen_target(ToyCh5ShapeInferenceInterfaceIncGen) +# Most dialects should use add_mlir_interfaces(). +set(LLVM_TARGET_DEFINITIONS ShapeInferenceInterface.td) +mlir_tablegen(ShapeInferenceOpInterfaces.h.inc -gen-op-interface-decls) +mlir_tablegen(ShapeInferenceOpInterfaces.cpp.inc -gen-op-interface-defs) +add_public_tablegen_target(ToyCh5ShapeInferenceInterfaceIncGen) diff --git a/Ch5/include/toy/Dialect.cpp.inc b/Ch5/include/toy/Dialect.cpp.inc deleted file mode 100644 index 8cbc772..0000000 --- a/Ch5/include/toy/Dialect.cpp.inc +++ /dev/null @@ -1,23 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Dialect Definitions *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: Ops.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::ToyDialect) -namespace mlir { -namespace toy { - -ToyDialect::ToyDialect(::mlir::MLIRContext *context) - : ::mlir::Dialect(getDialectNamespace(), context, ::mlir::TypeID::get()) { - - initialize(); -} - -ToyDialect::~ToyDialect() = default; - -} // namespace toy -} // namespace mlir diff --git a/Ch5/include/toy/Dialect.h.inc b/Ch5/include/toy/Dialect.h.inc deleted file mode 100644 index f19d867..0000000 --- a/Ch5/include/toy/Dialect.h.inc +++ /dev/null @@ -1,26 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Dialect Declarations *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: Ops.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -namespace mlir { -namespace toy { - -class ToyDialect : public ::mlir::Dialect { - explicit ToyDialect(::mlir::MLIRContext *context); - - void initialize(); - friend class ::mlir::MLIRContext; -public: - ~ToyDialect() override; - static constexpr ::llvm::StringLiteral getDialectNamespace() { - return ::llvm::StringLiteral("toy"); - } -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::ToyDialect) diff --git a/Ch5/include/toy/Ops.cpp.inc b/Ch5/include/toy/Ops.cpp.inc deleted file mode 100644 index 6bb98a2..0000000 --- a/Ch5/include/toy/Ops.cpp.inc +++ /dev/null @@ -1,2252 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Op Definitions *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: Ops.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -#ifdef GET_OP_LIST -#undef GET_OP_LIST - -::mlir::toy::AddOp, -::mlir::toy::CastOp, -::mlir::toy::ConstantOp, -::mlir::toy::FuncOp, -::mlir::toy::GenericCallOp, -::mlir::toy::MulOp, -::mlir::toy::PrintOp, -::mlir::toy::ReshapeOp, -::mlir::toy::ReturnOp, -::mlir::toy::TransposeOp -#endif // GET_OP_LIST - -#ifdef GET_OP_CLASSES -#undef GET_OP_CLASSES - - -//===----------------------------------------------------------------------===// -// Local Utility Method Definitions -//===----------------------------------------------------------------------===// - -namespace mlir { -namespace toy { - -static ::mlir::LogicalResult __mlir_ods_local_type_constraint_Ops0( - ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, - unsigned valueIndex) { - if (!(((::llvm::isa<::mlir::TensorType>(type))) && ([](::mlir::Type elementType) { return (elementType.isF64()); }(::llvm::cast<::mlir::ShapedType>(type).getElementType())))) { - return op->emitOpError(valueKind) << " #" << valueIndex - << " must be tensor of 64-bit float values, but got " << type; - } - return ::mlir::success(); -} - -static ::mlir::LogicalResult __mlir_ods_local_type_constraint_Ops1( - ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, - unsigned valueIndex) { - if (!(((::llvm::isa<::mlir::TensorType>(type))) && ([](::mlir::Type elementType) { return (elementType.isF64()); }(::llvm::cast<::mlir::ShapedType>(type).getElementType())))) { - return op->emitOpError(valueKind) << " #" << valueIndex - << " must be variadic of tensor of 64-bit float values, but got " << type; - } - return ::mlir::success(); -} - -static ::mlir::LogicalResult __mlir_ods_local_type_constraint_Ops2( - ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, - unsigned valueIndex) { - if (!((((::llvm::isa<::mlir::TensorType>(type))) && ([](::mlir::Type elementType) { return (elementType.isF64()); }(::llvm::cast<::mlir::ShapedType>(type).getElementType()))) || (((::llvm::isa<::mlir::MemRefType>(type))) && ([](::mlir::Type elementType) { return (elementType.isF64()); }(::llvm::cast<::mlir::ShapedType>(type).getElementType()))))) { - return op->emitOpError(valueKind) << " #" << valueIndex - << " must be tensor of 64-bit float values or memref of 64-bit float values, but got " << type; - } - return ::mlir::success(); -} - -static ::mlir::LogicalResult __mlir_ods_local_type_constraint_Ops3( - ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, - unsigned valueIndex) { - if (!((((::llvm::isa<::mlir::RankedTensorType>(type))) && ((::llvm::cast<::mlir::ShapedType>(type).hasStaticShape()))) && ([](::mlir::Type elementType) { return (elementType.isF64()); }(::llvm::cast<::mlir::ShapedType>(type).getElementType())))) { - return op->emitOpError(valueKind) << " #" << valueIndex - << " must be statically shaped tensor of 64-bit float values, but got " << type; - } - return ::mlir::success(); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops0( - ::mlir::Attribute attr, ::llvm::StringRef attrName, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { - if (attr && !((::llvm::isa<::mlir::DenseFPElementsAttr>(attr) &&::llvm::cast<::mlir::DenseElementsAttr>(attr).getType().getElementType().isF64()))) - return emitError() << "attribute '" << attrName - << "' failed to satisfy constraint: 64-bit float elements attribute"; - return ::mlir::success(); -} -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops0( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops0(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops1( - ::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 ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops1( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops1(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops2( - ::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 ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops2( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops2(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops3( - ::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 ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops3( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops3(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops4( - ::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 ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops4( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops4(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_region_constraint_Ops0( - ::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 toy -} // namespace mlir -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::AddOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -AddOpGenericAdaptorBase::AddOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.add", odsAttrs.getContext()); -} - -AddOpGenericAdaptorBase::AddOpGenericAdaptorBase(AddOp op) : AddOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair AddOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr AddOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -AddOpAdaptor::AddOpAdaptor(AddOp op) : AddOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult AddOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair AddOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range AddOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> AddOp::getLhs() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::TypedValue<::mlir::TensorType> AddOp::getRhs() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(1).begin()); -} - -::mlir::OpOperand &AddOp::getLhsMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -::mlir::OpOperand &AddOp::getRhsMutable() { - auto range = getODSOperandIndexAndLength(1); - return getOperation()->getOpOperand(range.first); -} - -std::pair AddOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range AddOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void AddOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value lhs, ::mlir::Value rhs) { - odsState.addOperands(lhs); - odsState.addOperands(rhs); - odsState.addTypes(resultType0); -} - -void AddOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs) { - odsState.addOperands(lhs); - odsState.addOperands(rhs); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void AddOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 2u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult AddOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*this, v.getType(), "operand", index++))) - return ::mlir::failure(); - } - auto valueGroup1 = getODSOperands(1); - - for (auto v : valueGroup1) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult AddOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -void AddOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::AddOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::CastOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -CastOpGenericAdaptorBase::CastOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.cast", odsAttrs.getContext()); -} - -CastOpGenericAdaptorBase::CastOpGenericAdaptorBase(CastOp op) : CastOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair CastOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr CastOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -CastOpAdaptor::CastOpAdaptor(CastOp op) : CastOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult CastOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair CastOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range CastOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> CastOp::getInput() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::OpOperand &CastOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -std::pair CastOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range CastOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> CastOp::getOutput() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSResults(0).begin()); -} - -void CastOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type output, ::mlir::Value input) { - odsState.addOperands(input); - odsState.addTypes(output); -} - -void CastOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input) { - odsState.addOperands(input); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void CastOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 1u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult CastOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult CastOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -::mlir::ParseResult CastOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::OpAsmParser::UnresolvedOperand inputRawOperands[1]; - ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> inputOperands(inputRawOperands); ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::mlir::Type inputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> inputTypes(inputRawTypes); - ::mlir::Type outputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> outputTypes(outputRawTypes); - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperand(inputRawOperands[0])) - return ::mlir::failure(); - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.parseColon()) - return ::mlir::failure(); - - { - ::mlir::TensorType type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - inputRawTypes[0] = type; - } - if (parser.parseKeyword("to")) - return ::mlir::failure(); - - { - ::mlir::TensorType type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - outputRawTypes[0] = type; - } - result.addTypes(outputTypes); - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void CastOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << ' '; - _odsPrinter << getInput(); - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - { - auto type = getInput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::TensorType>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } - _odsPrinter << ' ' << "to"; - _odsPrinter << ' '; - { - auto type = getOutput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::TensorType>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } -} - -void CastOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::CastOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ConstantOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -ConstantOpGenericAdaptorBase::ConstantOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.constant", odsAttrs.getContext()); -} - -ConstantOpGenericAdaptorBase::ConstantOpGenericAdaptorBase(ConstantOp op) : ConstantOpGenericAdaptorBase(op->getDiscardableAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair ConstantOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr ConstantOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -::mlir::DenseElementsAttr ConstantOpGenericAdaptorBase::getValueAttr() { - auto attr = ::llvm::cast<::mlir::DenseElementsAttr>(getProperties().value); - return attr; -} - -::mlir::DenseElementsAttr ConstantOpGenericAdaptorBase::getValue() { - auto attr = getValueAttr(); - return attr; -} - -} // namespace detail -ConstantOpAdaptor::ConstantOpAdaptor(ConstantOp op) : ConstantOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult ConstantOpAdaptor::verify(::mlir::Location loc) { - auto tblgen_value = getProperties().value; (void)tblgen_value; - if (!tblgen_value) return emitError(loc, "'toy.constant' op ""requires attribute 'value'"); - - if (tblgen_value && !((::llvm::isa<::mlir::DenseFPElementsAttr>(tblgen_value) &&::llvm::cast<::mlir::DenseElementsAttr>(tblgen_value).getType().getElementType().isF64()))) - return emitError(loc, "'toy.constant' op ""attribute 'value' failed to satisfy constraint: 64-bit float elements attribute"); - return ::mlir::success(); -} - -std::pair ConstantOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range ConstantOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -std::pair ConstantOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range ConstantOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::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 || /*isRequired=*/true) { - if (!attr) { - emitError() << "expected key entry for value in DictionaryAttr to set " - "Properties."; - return ::mlir::failure(); - } - 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) { - 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); -} - -::mlir::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_Ops0(attr, "value", emitError))) - return ::mlir::failure(); - } - return ::mlir::success(); -} - -::mlir::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); -} - -::mlir::DenseElementsAttr ConstantOp::getValueAttr() { - return ::llvm::cast<::mlir::DenseElementsAttr>(getProperties().value); -} - -::mlir::DenseElementsAttr ConstantOp::getValue() { - auto attr = getValueAttr(); - return attr; -} - -void ConstantOp::setValueAttr(::mlir::DenseElementsAttr attr) { - (*this)->setAttr(getValueAttrName(), attr); -} - -void ConstantOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, DenseElementsAttr value) { - build(odsBuilder, odsState, value.getType(), value); - -} - -void ConstantOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::DenseElementsAttr value) { - odsState.getOrAddProperties().value = value; - odsState.addTypes(resultType0); -} - -void ConstantOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::DenseElementsAttr value) { - odsState.getOrAddProperties().value = value; - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -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); -} - -::mlir::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_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult ConstantOp::verifyInvariants() { - if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) - return ::mlir::success(); - return ::mlir::failure(); -} - -void ConstantOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::ConstantOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::FuncOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -FuncOpGenericAdaptorBase::FuncOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.func", odsAttrs.getContext()); -} - -FuncOpGenericAdaptorBase::FuncOpGenericAdaptorBase(FuncOp op) : FuncOpGenericAdaptorBase(op->getDiscardableAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair FuncOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr FuncOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -::mlir::StringAttr FuncOpGenericAdaptorBase::getSymNameAttr() { - auto attr = ::llvm::cast<::mlir::StringAttr>(getProperties().sym_name); - return attr; -} - -::llvm::StringRef FuncOpGenericAdaptorBase::getSymName() { - auto attr = getSymNameAttr(); - return attr.getValue(); -} - -::mlir::TypeAttr FuncOpGenericAdaptorBase::getFunctionTypeAttr() { - auto attr = ::llvm::cast<::mlir::TypeAttr>(getProperties().function_type); - return attr; -} - -::mlir::FunctionType FuncOpGenericAdaptorBase::getFunctionType() { - auto attr = getFunctionTypeAttr(); - return ::llvm::cast<::mlir::FunctionType>(attr.getValue()); -} - -::mlir::ArrayAttr FuncOpGenericAdaptorBase::getArgAttrsAttr() { - auto attr = ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(getProperties().arg_attrs); - return attr; -} - -::std::optional< ::mlir::ArrayAttr > FuncOpGenericAdaptorBase::getArgAttrs() { - auto attr = getArgAttrsAttr(); - return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); -} - -::mlir::ArrayAttr FuncOpGenericAdaptorBase::getResAttrsAttr() { - auto attr = ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(getProperties().res_attrs); - return attr; -} - -::std::optional< ::mlir::ArrayAttr > FuncOpGenericAdaptorBase::getResAttrs() { - auto attr = getResAttrsAttr(); - return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); -} - -::mlir::Region &FuncOpGenericAdaptorBase::getBody() { - return *odsRegions[0]; -} - -::mlir::RegionRange FuncOpGenericAdaptorBase::getRegions() { - return odsRegions; -} - -} // namespace detail -FuncOpAdaptor::FuncOpAdaptor(FuncOp op) : FuncOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::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, "'toy.func' op ""requires attribute 'function_type'"); - 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, "'toy.func' op ""requires attribute 'sym_name'"); - - if (tblgen_sym_name && !((::llvm::isa<::mlir::StringAttr>(tblgen_sym_name)))) - return emitError(loc, "'toy.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, "'toy.func' op ""attribute 'function_type' failed to satisfy constraint: type attribute of function type"); - - 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, "'toy.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, "'toy.func' op ""attribute 'res_attrs' failed to satisfy constraint: Array of dictionary attributes"); - return ::mlir::success(); -} - -std::pair FuncOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range FuncOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -std::pair FuncOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range FuncOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::Region &FuncOp::getBody() { - return (*this)->getRegion(0); -} - -::mlir::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 || /*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.function_type; - auto attr = dict.get("function_type"); - 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.res_attrs; - auto attr = dict.get("res_attrs"); - 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.sym_name; - auto attr = dict.get("sym_name"); - 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(); - } - } - } - 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.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)); - } - - if (!attrs.empty()) - return odsBuilder.getDictionaryAttr(attrs); - return {}; -} - -llvm::hash_code FuncOp::computePropertiesHash(const Properties &prop) { - return llvm::hash_combine( - llvm::hash_value(prop.arg_attrs.getAsOpaquePointer()), - llvm::hash_value(prop.function_type.getAsOpaquePointer()), - llvm::hash_value(prop.res_attrs.getAsOpaquePointer()), - llvm::hash_value(prop.sym_name.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 == "res_attrs") - return prop.res_attrs; - - if (name == "sym_name") - return prop.sym_name; - 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 == "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; - } -} - -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.res_attrs) attrs.append("res_attrs", prop.res_attrs); - - if (prop.sym_name) attrs.append("sym_name", prop.sym_name); -} - -::mlir::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_Ops3(attr, "arg_attrs", emitError))) - return ::mlir::failure(); - } - - { - ::mlir::Attribute attr = attrs.get(getFunctionTypeAttrName(opName)); - if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_Ops2(attr, "function_type", emitError))) - return ::mlir::failure(); - } - - { - ::mlir::Attribute attr = attrs.get(getResAttrsAttrName(opName)); - if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_Ops3(attr, "res_attrs", emitError))) - return ::mlir::failure(); - } - - { - ::mlir::Attribute attr = attrs.get(getSymNameAttrName(opName)); - if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_Ops1(attr, "sym_name", emitError))) - return ::mlir::failure(); - } - return ::mlir::success(); -} - -::mlir::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.res_attrs))) - return ::mlir::failure(); - - if (::mlir::failed(reader.readAttribute(prop.sym_name))) - 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.res_attrs); - writer.writeAttribute(prop.sym_name); -} - -::mlir::StringAttr FuncOp::getSymNameAttr() { - return ::llvm::cast<::mlir::StringAttr>(getProperties().sym_name); -} - -::llvm::StringRef FuncOp::getSymName() { - auto attr = getSymNameAttr(); - return attr.getValue(); -} - -::mlir::TypeAttr FuncOp::getFunctionTypeAttr() { - return ::llvm::cast<::mlir::TypeAttr>(getProperties().function_type); -} - -::mlir::FunctionType FuncOp::getFunctionType() { - auto attr = getFunctionTypeAttr(); - return ::llvm::cast<::mlir::FunctionType>(attr.getValue()); -} - -::mlir::ArrayAttr FuncOp::getArgAttrsAttr() { - return ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(getProperties().arg_attrs); -} - -::std::optional< ::mlir::ArrayAttr > FuncOp::getArgAttrs() { - auto attr = getArgAttrsAttr(); - return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); -} - -::mlir::ArrayAttr FuncOp::getResAttrsAttr() { - return ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(getProperties().res_attrs); -} - -::std::optional< ::mlir::ArrayAttr > FuncOp::getResAttrs() { - auto attr = getResAttrsAttr(); - return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); -} - -void FuncOp::setSymNameAttr(::mlir::StringAttr attr) { - (*this)->setAttr(getSymNameAttrName(), attr); -} - -void FuncOp::setSymName(::llvm::StringRef attrValue) { - (*this)->setAttr(getSymNameAttrName(), ::mlir::Builder((*this)->getContext()).getStringAttr(attrValue)); -} - -void FuncOp::setFunctionTypeAttr(::mlir::TypeAttr attr) { - (*this)->setAttr(getFunctionTypeAttrName(), attr); -} - -void FuncOp::setFunctionType(::mlir::FunctionType attrValue) { - (*this)->setAttr(getFunctionTypeAttrName(), ::mlir::TypeAttr::get(attrValue)); -} - -void FuncOp::setArgAttrsAttr(::mlir::ArrayAttr attr) { - (*this)->setAttr(getArgAttrsAttrName(), attr); -} - -void FuncOp::setResAttrsAttr(::mlir::ArrayAttr attr) { - (*this)->setAttr(getResAttrsAttrName(), attr); -} - -::mlir::Attribute FuncOp::removeArgAttrsAttr() { - auto &attr = getProperties().arg_attrs; - attr = {}; - return attr; -} - -::mlir::Attribute FuncOp::removeResAttrsAttr() { - auto &attr = getProperties().res_attrs; - attr = {}; - return attr; -} - -::mlir::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_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'"); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops1(*this, tblgen_sym_name, "sym_name"))) - return ::mlir::failure(); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops2(*this, tblgen_function_type, "function_type"))) - return ::mlir::failure(); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops3(*this, tblgen_arg_attrs, "arg_attrs"))) - return ::mlir::failure(); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops3(*this, tblgen_res_attrs, "res_attrs"))) - return ::mlir::failure(); - { - unsigned index = 0; (void)index; - - for (auto ®ion : ::llvm::MutableArrayRef((*this)->getRegion(0))) - if (::mlir::failed(__mlir_ods_local_region_constraint_Ops0(*this, region, "body", index++))) - return ::mlir::failure(); - } - return ::mlir::success(); -} - -::mlir::LogicalResult FuncOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::FuncOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::GenericCallOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -GenericCallOpGenericAdaptorBase::GenericCallOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.generic_call", odsAttrs.getContext()); -} - -GenericCallOpGenericAdaptorBase::GenericCallOpGenericAdaptorBase(GenericCallOp op) : GenericCallOpGenericAdaptorBase(op->getDiscardableAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair GenericCallOpGenericAdaptorBase::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}; -} - -::mlir::DictionaryAttr GenericCallOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -::mlir::FlatSymbolRefAttr GenericCallOpGenericAdaptorBase::getCalleeAttr() { - auto attr = ::llvm::cast<::mlir::FlatSymbolRefAttr>(getProperties().callee); - return attr; -} - -::llvm::StringRef GenericCallOpGenericAdaptorBase::getCallee() { - auto attr = getCalleeAttr(); - return attr.getValue(); -} - -} // namespace detail -GenericCallOpAdaptor::GenericCallOpAdaptor(GenericCallOp op) : GenericCallOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult GenericCallOpAdaptor::verify(::mlir::Location loc) { - auto tblgen_callee = getProperties().callee; (void)tblgen_callee; - if (!tblgen_callee) return emitError(loc, "'toy.generic_call' op ""requires attribute 'callee'"); - - if (tblgen_callee && !((::llvm::isa<::mlir::FlatSymbolRefAttr>(tblgen_callee)))) - return emitError(loc, "'toy.generic_call' op ""attribute 'callee' failed to satisfy constraint: flat symbol reference attribute"); - return ::mlir::success(); -} - -std::pair GenericCallOp::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::Operation::operand_range GenericCallOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::Operation::operand_range GenericCallOp::getInputs() { - return getODSOperands(0); -} - -::mlir::MutableOperandRange GenericCallOp::getInputsMutable() { - auto range = getODSOperandIndexAndLength(0); - auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); - return mutableRange; -} - -std::pair GenericCallOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range GenericCallOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::LogicalResult GenericCallOp::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.callee; - auto attr = dict.get("callee"); - if (attr || /*isRequired=*/true) { - if (!attr) { - emitError() << "expected key entry for callee in DictionaryAttr to set " - "Properties."; - return ::mlir::failure(); - } - auto convertedAttr = ::llvm::dyn_cast>(attr); - if (convertedAttr) { - propStorage = convertedAttr; - } else { - emitError() << "Invalid attribute `callee` in property conversion: " << attr; - return ::mlir::failure(); - } - } - } - return ::mlir::success(); -} - -::mlir::Attribute GenericCallOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) { - ::mlir::SmallVector<::mlir::NamedAttribute> attrs; - ::mlir::Builder odsBuilder{ctx}; - - { - const auto &propStorage = prop.callee; - if (propStorage) - attrs.push_back(odsBuilder.getNamedAttr("callee", - propStorage)); - } - - if (!attrs.empty()) - return odsBuilder.getDictionaryAttr(attrs); - return {}; -} - -llvm::hash_code GenericCallOp::computePropertiesHash(const Properties &prop) { - return llvm::hash_combine( - llvm::hash_value(prop.callee.getAsOpaquePointer())); -} - -std::optional GenericCallOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { - if (name == "callee") - return prop.callee; - return std::nullopt; -} - -void GenericCallOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { - if (name == "callee") { - prop.callee = ::llvm::dyn_cast_or_null>(value); - return; - } -} - -void GenericCallOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { - if (prop.callee) attrs.append("callee", prop.callee); -} - -::mlir::LogicalResult GenericCallOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { - { - ::mlir::Attribute attr = attrs.get(getCalleeAttrName(opName)); - if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_Ops4(attr, "callee", emitError))) - return ::mlir::failure(); - } - return ::mlir::success(); -} - -::mlir::LogicalResult GenericCallOp::readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state) { - auto &prop = state.getOrAddProperties(); (void)prop; - if (::mlir::failed(reader.readAttribute(prop.callee))) - return ::mlir::failure(); - return ::mlir::success(); -} - -void GenericCallOp::writeProperties(::mlir::DialectBytecodeWriter &writer) { - auto &prop = getProperties(); (void)prop; - writer.writeAttribute(prop.callee); -} - -::mlir::FlatSymbolRefAttr GenericCallOp::getCalleeAttr() { - return ::llvm::cast<::mlir::FlatSymbolRefAttr>(getProperties().callee); -} - -::llvm::StringRef GenericCallOp::getCallee() { - auto attr = getCalleeAttr(); - return attr.getValue(); -} - -void GenericCallOp::setCalleeAttr(::mlir::FlatSymbolRefAttr attr) { - (*this)->setAttr(getCalleeAttrName(), attr); -} - -void GenericCallOp::setCallee(::llvm::StringRef attrValue) { - (*this)->setAttr(getCalleeAttrName(), ::mlir::SymbolRefAttr::get(::mlir::Builder((*this)->getContext()).getContext(), attrValue)); -} - -void GenericCallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::FlatSymbolRefAttr callee, ::mlir::ValueRange inputs) { - odsState.addOperands(inputs); - odsState.getOrAddProperties().callee = callee; - odsState.addTypes(resultType0); -} - -void GenericCallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::FlatSymbolRefAttr callee, ::mlir::ValueRange inputs) { - odsState.addOperands(inputs); - odsState.getOrAddProperties().callee = callee; - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void GenericCallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::llvm::StringRef callee, ::mlir::ValueRange inputs) { - odsState.addOperands(inputs); - odsState.getOrAddProperties().callee = ::mlir::SymbolRefAttr::get(odsBuilder.getContext(), callee); - odsState.addTypes(resultType0); -} - -void GenericCallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::llvm::StringRef callee, ::mlir::ValueRange inputs) { - odsState.addOperands(inputs); - odsState.getOrAddProperties().callee = ::mlir::SymbolRefAttr::get(odsBuilder.getContext(), callee); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void GenericCallOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult GenericCallOp::verifyInvariantsImpl() { - auto tblgen_callee = getProperties().callee; (void)tblgen_callee; - if (!tblgen_callee) return emitOpError("requires attribute 'callee'"); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops4(*this, tblgen_callee, "callee"))) - return ::mlir::failure(); - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops1(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult GenericCallOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -::mlir::ParseResult GenericCallOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::FlatSymbolRefAttr calleeAttr; - ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> inputsOperands; - ::llvm::SMLoc inputsOperandsLoc; - (void)inputsOperandsLoc; - ::llvm::ArrayRef<::mlir::Type> inputsTypes; - ::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(); - - inputsOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperandList(inputsOperands)) - 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 inputs__allResult_functionType; - if (parser.parseType(inputs__allResult_functionType)) - return ::mlir::failure(); - inputsTypes = inputs__allResult_functionType.getInputs(); - allResultTypes = inputs__allResult_functionType.getResults(); - result.addTypes(allResultTypes); - if (parser.resolveOperands(inputsOperands, inputsTypes, inputsOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void GenericCallOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << ' '; - _odsPrinter.printAttributeWithoutType(getCalleeAttr()); - _odsPrinter << "("; - _odsPrinter << getInputs(); - _odsPrinter << ")"; - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - elidedAttrs.push_back("callee"); - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - _odsPrinter.printFunctionalType(getInputs().getTypes(), getOperation()->getResultTypes()); -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::GenericCallOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::MulOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -MulOpGenericAdaptorBase::MulOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.mul", odsAttrs.getContext()); -} - -MulOpGenericAdaptorBase::MulOpGenericAdaptorBase(MulOp op) : MulOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair MulOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr MulOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -MulOpAdaptor::MulOpAdaptor(MulOp op) : MulOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult MulOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair MulOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range MulOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> MulOp::getLhs() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::TypedValue<::mlir::TensorType> MulOp::getRhs() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(1).begin()); -} - -::mlir::OpOperand &MulOp::getLhsMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -::mlir::OpOperand &MulOp::getRhsMutable() { - auto range = getODSOperandIndexAndLength(1); - return getOperation()->getOpOperand(range.first); -} - -std::pair MulOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range MulOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void MulOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value lhs, ::mlir::Value rhs) { - odsState.addOperands(lhs); - odsState.addOperands(rhs); - odsState.addTypes(resultType0); -} - -void MulOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs) { - odsState.addOperands(lhs); - odsState.addOperands(rhs); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void MulOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 2u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult MulOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*this, v.getType(), "operand", index++))) - return ::mlir::failure(); - } - auto valueGroup1 = getODSOperands(1); - - for (auto v : valueGroup1) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult MulOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -void MulOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::MulOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::PrintOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -PrintOpGenericAdaptorBase::PrintOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.print", odsAttrs.getContext()); -} - -PrintOpGenericAdaptorBase::PrintOpGenericAdaptorBase(PrintOp op) : PrintOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair PrintOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr PrintOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -PrintOpAdaptor::PrintOpAdaptor(PrintOp op) : PrintOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult PrintOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair PrintOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range PrintOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::Value PrintOp::getInput() { - return ::llvm::cast<::mlir::Value>(*getODSOperands(0).begin()); -} - -::mlir::OpOperand &PrintOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -std::pair PrintOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range PrintOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void PrintOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value input) { - odsState.addOperands(input); -} - -void PrintOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input) { - odsState.addOperands(input); - assert(resultTypes.size() == 0u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void PrintOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 1u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 0u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult PrintOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops2(*this, v.getType(), "operand", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult PrintOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -::mlir::ParseResult PrintOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::OpAsmParser::UnresolvedOperand inputRawOperands[1]; - ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> inputOperands(inputRawOperands); ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::mlir::Type inputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> inputTypes(inputRawTypes); - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperand(inputRawOperands[0])) - return ::mlir::failure(); - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.parseColon()) - return ::mlir::failure(); - - { - ::mlir::Type type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - inputRawTypes[0] = type; - } - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void PrintOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << ' '; - _odsPrinter << getInput(); - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - { - auto type = getInput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::Type>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::PrintOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ReshapeOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -ReshapeOpGenericAdaptorBase::ReshapeOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.reshape", odsAttrs.getContext()); -} - -ReshapeOpGenericAdaptorBase::ReshapeOpGenericAdaptorBase(ReshapeOp op) : ReshapeOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair ReshapeOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr ReshapeOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -ReshapeOpAdaptor::ReshapeOpAdaptor(ReshapeOp op) : ReshapeOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult ReshapeOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair ReshapeOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range ReshapeOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> ReshapeOp::getInput() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::OpOperand &ReshapeOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -std::pair ReshapeOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range ReshapeOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void ReshapeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value input) { - odsState.addOperands(input); - odsState.addTypes(resultType0); -} - -void ReshapeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input) { - odsState.addOperands(input); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void ReshapeOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 1u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult ReshapeOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops3(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult ReshapeOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -::mlir::ParseResult ReshapeOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::OpAsmParser::UnresolvedOperand inputRawOperands[1]; - ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> inputOperands(inputRawOperands); ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::mlir::Type inputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> inputTypes(inputRawTypes); - ::llvm::SmallVector<::mlir::Type, 1> allResultTypes; - if (parser.parseLParen()) - return ::mlir::failure(); - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperand(inputRawOperands[0])) - return ::mlir::failure(); - if (parser.parseColon()) - return ::mlir::failure(); - - { - ::mlir::TensorType type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - inputRawTypes[0] = type; - } - if (parser.parseRParen()) - return ::mlir::failure(); - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.parseKeyword("to")) - return ::mlir::failure(); - - if (parser.parseTypeList(allResultTypes)) - return ::mlir::failure(); - result.addTypes(allResultTypes); - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void ReshapeOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << "("; - _odsPrinter << getInput(); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - { - auto type = getInput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::TensorType>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } - _odsPrinter << ")"; - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << "to"; - _odsPrinter << ' '; - _odsPrinter << getOperation()->getResultTypes(); -} - -void ReshapeOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::ReshapeOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ReturnOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -ReturnOpGenericAdaptorBase::ReturnOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.return", odsAttrs.getContext()); -} - -ReturnOpGenericAdaptorBase::ReturnOpGenericAdaptorBase(ReturnOp op) : ReturnOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), 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}; -} - -::mlir::DictionaryAttr ReturnOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -ReturnOpAdaptor::ReturnOpAdaptor(ReturnOp op) : ReturnOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::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::Operation::operand_range ReturnOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::Operation::operand_range ReturnOp::getInput() { - return getODSOperands(0); -} - -::mlir::MutableOperandRange ReturnOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); - return mutableRange; -} - -std::pair ReturnOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range ReturnOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void ReturnOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState) { - build(odsBuilder, odsState, std::nullopt); -} - -void ReturnOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange input) { - odsState.addOperands(input); -} - -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); -} - -::mlir::LogicalResult ReturnOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops1(*this, v.getType(), "operand", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult ReturnOp::verifyInvariants() { - if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) - return ::mlir::success(); - return ::mlir::failure(); -} - -::mlir::ParseResult ReturnOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> inputOperands; - ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::llvm::SmallVector<::mlir::Type, 1> inputTypes; - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperandList(inputOperands)) - return ::mlir::failure(); - if (!inputOperands.empty()) { - if (parser.parseColon()) - return ::mlir::failure(); - - if (parser.parseTypeList(inputTypes)) - return ::mlir::failure(); - } - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void ReturnOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - if (!getInput().empty()) { - _odsPrinter << ' '; - _odsPrinter << getInput(); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - _odsPrinter << getInput().getTypes(); - } - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); -} - -void ReturnOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::ReturnOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::TransposeOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -TransposeOpGenericAdaptorBase::TransposeOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.transpose", odsAttrs.getContext()); -} - -TransposeOpGenericAdaptorBase::TransposeOpGenericAdaptorBase(TransposeOp op) : TransposeOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair TransposeOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr TransposeOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -TransposeOpAdaptor::TransposeOpAdaptor(TransposeOp op) : TransposeOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult TransposeOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair TransposeOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range TransposeOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> TransposeOp::getInput() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::OpOperand &TransposeOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -std::pair TransposeOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range TransposeOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void TransposeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value input) { - odsState.addOperands(input); - odsState.addTypes(resultType0); -} - -void TransposeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input) { - odsState.addOperands(input); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void TransposeOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 1u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult TransposeOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult TransposeOp::verifyInvariants() { - if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) - return ::mlir::success(); - return ::mlir::failure(); -} - -::mlir::ParseResult TransposeOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::OpAsmParser::UnresolvedOperand inputRawOperands[1]; - ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> inputOperands(inputRawOperands); ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::mlir::Type inputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> inputTypes(inputRawTypes); - ::llvm::SmallVector<::mlir::Type, 1> allResultTypes; - if (parser.parseLParen()) - return ::mlir::failure(); - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperand(inputRawOperands[0])) - return ::mlir::failure(); - if (parser.parseColon()) - return ::mlir::failure(); - - { - ::mlir::TensorType type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - inputRawTypes[0] = type; - } - if (parser.parseRParen()) - return ::mlir::failure(); - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.parseKeyword("to")) - return ::mlir::failure(); - - if (parser.parseTypeList(allResultTypes)) - return ::mlir::failure(); - result.addTypes(allResultTypes); - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void TransposeOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << "("; - _odsPrinter << getInput(); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - { - auto type = getInput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::TensorType>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } - _odsPrinter << ")"; - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << "to"; - _odsPrinter << ' '; - _odsPrinter << getOperation()->getResultTypes(); -} - -void TransposeOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::TransposeOp) - - -#endif // GET_OP_CLASSES - diff --git a/Ch5/include/toy/Ops.h.inc b/Ch5/include/toy/Ops.h.inc deleted file mode 100644 index a3011f8..0000000 --- a/Ch5/include/toy/Ops.h.inc +++ /dev/null @@ -1,1361 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Op Declarations *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: Ops.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -#if defined(GET_OP_CLASSES) || defined(GET_OP_FWD_DEFINES) -#undef GET_OP_FWD_DEFINES -namespace mlir { -namespace toy { -class AddOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class CastOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class ConstantOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class FuncOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class GenericCallOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class MulOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class PrintOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class ReshapeOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class ReturnOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class TransposeOp; -} // namespace toy -} // namespace mlir -#endif - -#ifdef GET_OP_CLASSES -#undef GET_OP_CLASSES - - -//===----------------------------------------------------------------------===// -// Local Utility Method Definitions -//===----------------------------------------------------------------------===// - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::AddOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class AddOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - AddOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - AddOpGenericAdaptorBase(AddOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class AddOpGenericAdaptor : public detail::AddOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::AddOpGenericAdaptorBase; -public: - AddOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - AddOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : AddOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - AddOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getLhs() { - return (*getODSOperands(0).begin()); - } - - ValueT getRhs() { - return (*getODSOperands(1).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class AddOpAdaptor : public AddOpGenericAdaptor<::mlir::ValueRange> { -public: - using AddOpGenericAdaptor::AddOpGenericAdaptor; - AddOpAdaptor(AddOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class AddOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::NOperands<2>::Impl, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait, ShapeInference::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = AddOpAdaptor; - template - using GenericAdaptor = AddOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.add"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getLhs(); - ::mlir::TypedValue<::mlir::TensorType> getRhs(); - ::mlir::OpOperand &getLhsMutable(); - ::mlir::OpOperand &getRhsMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, Value lhs, Value rhs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value lhs, ::mlir::Value rhs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &p); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - void inferShapes(); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::AddOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::CastOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class CastOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - CastOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - CastOpGenericAdaptorBase(CastOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class CastOpGenericAdaptor : public detail::CastOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::CastOpGenericAdaptorBase; -public: - CastOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - CastOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : CastOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - CastOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getInput() { - return (*getODSOperands(0).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class CastOpAdaptor : public CastOpGenericAdaptor<::mlir::ValueRange> { -public: - using CastOpGenericAdaptor::CastOpGenericAdaptor; - CastOpAdaptor(CastOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class CastOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::OneOperand, ::mlir::OpTrait::OpInvariants, ::mlir::CastOpInterface::Trait, ShapeInference::Trait, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait, ::mlir::OpTrait::SameOperandsAndResultShape> { -public: - using Op::Op; - using Op::print; - using Adaptor = CastOpAdaptor; - template - using GenericAdaptor = CastOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.cast"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getInput(); - ::mlir::OpOperand &getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getOutput(); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type output, ::mlir::Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - static bool areCastCompatible(::mlir::TypeRange inputs, ::mlir::TypeRange outputs); - void inferShapes(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::CastOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ConstantOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class ConstantOpGenericAdaptorBase { -public: - struct Properties { - using valueTy = ::mlir::DenseElementsAttr; - valueTy value; - - auto getValue() { - auto &propStorage = this->value; - return ::llvm::cast<::mlir::DenseElementsAttr>(propStorage); - } - void setValue(const ::mlir::DenseElementsAttr &propValue) { - this->value = propValue; - } - bool operator==(const Properties &rhs) const { - return - rhs.value == this->value && - true; - } - bool operator!=(const Properties &rhs) const { - return !(*this == rhs); - } - }; -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - Properties properties; - ::mlir::RegionRange odsRegions; -public: - ConstantOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}); - - ConstantOpGenericAdaptorBase(ConstantOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - const Properties &getProperties() { - return properties; - } - - ::mlir::DictionaryAttr getAttributes(); - ::mlir::DenseElementsAttr getValueAttr(); - ::mlir::DenseElementsAttr getValue(); -}; -} // namespace detail -template -class ConstantOpGenericAdaptor : public detail::ConstantOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::ConstantOpGenericAdaptorBase; -public: - ConstantOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - ConstantOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : ConstantOpGenericAdaptor(values, attrs, (properties ? *properties.as() : Properties{}), regions) {} - - template >> - ConstantOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class ConstantOpAdaptor : public ConstantOpGenericAdaptor<::mlir::ValueRange> { -public: - using ConstantOpGenericAdaptor::ConstantOpGenericAdaptor; - ConstantOpAdaptor(ConstantOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class ConstantOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::ZeroOperands, ::mlir::OpTrait::OpInvariants, ::mlir::BytecodeOpInterface::Trait, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = ConstantOpAdaptor; - template - using GenericAdaptor = ConstantOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - using Properties = FoldAdaptor::Properties; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - static ::llvm::StringRef attrNames[] = {::llvm::StringRef("value")}; - return ::llvm::ArrayRef(attrNames); - } - - ::mlir::StringAttr getValueAttrName() { - return getAttributeNameForIndex(0); - } - - static ::mlir::StringAttr getValueAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 0); - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.constant"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static ::mlir::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop); - static llvm::hash_code computePropertiesHash(const Properties &prop); - static std::optional getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name); - static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value); - static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs); - static ::mlir::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::LogicalResult readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state); - void writeProperties(::mlir::DialectBytecodeWriter &writer); - ::mlir::DenseElementsAttr getValueAttr(); - ::mlir::DenseElementsAttr getValue(); - void setValueAttr(::mlir::DenseElementsAttr attr); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, DenseElementsAttr value); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, double value); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::DenseElementsAttr value); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::DenseElementsAttr value); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &p); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - ::mlir::LogicalResult verify(); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -private: - ::mlir::StringAttr getAttributeNameForIndex(unsigned index) { - return getAttributeNameForIndex((*this)->getName(), index); - } - - static ::mlir::StringAttr getAttributeNameForIndex(::mlir::OperationName name, unsigned index) { - assert(index < 1 && "invalid attribute index"); - assert(name.getStringRef() == getOperationName() && "invalid operation name"); - assert(name.isRegistered() && "Operation isn't registered, missing a " - "dependent dialect loading?"); - return name.getAttributeNames()[index]; - } - -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::ConstantOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::FuncOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class FuncOpGenericAdaptorBase { -public: - struct Properties { - using arg_attrsTy = ::mlir::ArrayAttr; - arg_attrsTy arg_attrs; - - auto getArgAttrs() { - auto &propStorage = this->arg_attrs; - return ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(propStorage); - } - void setArgAttrs(const ::mlir::ArrayAttr &propValue) { - this->arg_attrs = propValue; - } - using function_typeTy = ::mlir::TypeAttr; - function_typeTy function_type; - - auto getFunctionType() { - auto &propStorage = this->function_type; - return ::llvm::cast<::mlir::TypeAttr>(propStorage); - } - void setFunctionType(const ::mlir::TypeAttr &propValue) { - this->function_type = propValue; - } - using res_attrsTy = ::mlir::ArrayAttr; - res_attrsTy res_attrs; - - auto getResAttrs() { - auto &propStorage = this->res_attrs; - return ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(propStorage); - } - void setResAttrs(const ::mlir::ArrayAttr &propValue) { - this->res_attrs = propValue; - } - using sym_nameTy = ::mlir::StringAttr; - sym_nameTy sym_name; - - auto getSymName() { - auto &propStorage = this->sym_name; - return ::llvm::cast<::mlir::StringAttr>(propStorage); - } - void setSymName(const ::mlir::StringAttr &propValue) { - this->sym_name = propValue; - } - bool operator==(const Properties &rhs) const { - return - rhs.arg_attrs == this->arg_attrs && - rhs.function_type == this->function_type && - rhs.res_attrs == this->res_attrs && - rhs.sym_name == this->sym_name && - true; - } - bool operator!=(const Properties &rhs) const { - return !(*this == rhs); - } - }; -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - Properties properties; - ::mlir::RegionRange odsRegions; -public: - FuncOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}); - - FuncOpGenericAdaptorBase(FuncOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - const Properties &getProperties() { - return properties; - } - - ::mlir::DictionaryAttr getAttributes(); - ::mlir::StringAttr getSymNameAttr(); - ::llvm::StringRef getSymName(); - ::mlir::TypeAttr getFunctionTypeAttr(); - ::mlir::FunctionType getFunctionType(); - ::mlir::ArrayAttr getArgAttrsAttr(); - ::std::optional< ::mlir::ArrayAttr > getArgAttrs(); - ::mlir::ArrayAttr getResAttrsAttr(); - ::std::optional< ::mlir::ArrayAttr > getResAttrs(); - ::mlir::Region &getBody(); - ::mlir::RegionRange getRegions(); -}; -} // namespace detail -template -class FuncOpGenericAdaptor : public detail::FuncOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::FuncOpGenericAdaptorBase; -public: - FuncOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - FuncOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : FuncOpGenericAdaptor(values, attrs, (properties ? *properties.as() : Properties{}), regions) {} - - template >> - FuncOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class FuncOpAdaptor : public FuncOpGenericAdaptor<::mlir::ValueRange> { -public: - using FuncOpGenericAdaptor::FuncOpGenericAdaptor; - FuncOpAdaptor(FuncOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class FuncOp : public ::mlir::Op { -public: - using Op::Op; - using Op::print; - using Adaptor = FuncOpAdaptor; - template - using GenericAdaptor = FuncOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - using Properties = FoldAdaptor::Properties; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - static ::llvm::StringRef attrNames[] = {::llvm::StringRef("arg_attrs"), ::llvm::StringRef("function_type"), ::llvm::StringRef("res_attrs"), ::llvm::StringRef("sym_name")}; - return ::llvm::ArrayRef(attrNames); - } - - ::mlir::StringAttr getArgAttrsAttrName() { - return getAttributeNameForIndex(0); - } - - static ::mlir::StringAttr getArgAttrsAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 0); - } - - ::mlir::StringAttr getFunctionTypeAttrName() { - return getAttributeNameForIndex(1); - } - - static ::mlir::StringAttr getFunctionTypeAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 1); - } - - ::mlir::StringAttr getResAttrsAttrName() { - return getAttributeNameForIndex(2); - } - - static ::mlir::StringAttr getResAttrsAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 2); - } - - ::mlir::StringAttr getSymNameAttrName() { - return getAttributeNameForIndex(3); - } - - static ::mlir::StringAttr getSymNameAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 3); - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.func"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - ::mlir::Region &getBody(); - static ::mlir::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop); - static llvm::hash_code computePropertiesHash(const Properties &prop); - static std::optional getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name); - static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value); - static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs); - static ::mlir::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::LogicalResult readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state); - void writeProperties(::mlir::DialectBytecodeWriter &writer); - ::mlir::StringAttr getSymNameAttr(); - ::llvm::StringRef getSymName(); - ::mlir::TypeAttr getFunctionTypeAttr(); - ::mlir::FunctionType getFunctionType(); - ::mlir::ArrayAttr getArgAttrsAttr(); - ::std::optional< ::mlir::ArrayAttr > getArgAttrs(); - ::mlir::ArrayAttr getResAttrsAttr(); - ::std::optional< ::mlir::ArrayAttr > getResAttrs(); - void setSymNameAttr(::mlir::StringAttr attr); - void setSymName(::llvm::StringRef attrValue); - void setFunctionTypeAttr(::mlir::TypeAttr attr); - void setFunctionType(::mlir::FunctionType attrValue); - void setArgAttrsAttr(::mlir::ArrayAttr attr); - void setResAttrsAttr(::mlir::ArrayAttr attr); - ::mlir::Attribute removeArgAttrsAttr(); - ::mlir::Attribute removeResAttrsAttr(); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, StringRef name, FunctionType type, ArrayRef attrs = {}); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &p); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); -private: - ::mlir::StringAttr getAttributeNameForIndex(unsigned index) { - return getAttributeNameForIndex((*this)->getName(), index); - } - - static ::mlir::StringAttr getAttributeNameForIndex(::mlir::OperationName name, unsigned index) { - assert(index < 4 && "invalid attribute index"); - assert(name.getStringRef() == getOperationName() && "invalid operation name"); - assert(name.isRegistered() && "Operation isn't registered, missing a " - "dependent dialect loading?"); - return name.getAttributeNames()[index]; - } - -public: - //===------------------------------------------------------------------===// - // FunctionOpInterface Methods - //===------------------------------------------------------------------===// - - /// Returns the argument types of this function. - ArrayRef getArgumentTypes() { return getFunctionType().getInputs(); } - - /// Returns the result types of this function. - ArrayRef getResultTypes() { return getFunctionType().getResults(); } - - /// Returns the region on the function operation that is callable. - Region *getCallableRegion() { return &getBody(); } -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::FuncOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::GenericCallOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class GenericCallOpGenericAdaptorBase { -public: - struct Properties { - using calleeTy = ::mlir::FlatSymbolRefAttr; - calleeTy callee; - - auto getCallee() { - auto &propStorage = this->callee; - return ::llvm::cast<::mlir::FlatSymbolRefAttr>(propStorage); - } - void setCallee(const ::mlir::FlatSymbolRefAttr &propValue) { - this->callee = propValue; - } - bool operator==(const Properties &rhs) const { - return - rhs.callee == this->callee && - true; - } - bool operator!=(const Properties &rhs) const { - return !(*this == rhs); - } - }; -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - Properties properties; - ::mlir::RegionRange odsRegions; -public: - GenericCallOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}); - - GenericCallOpGenericAdaptorBase(GenericCallOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - const Properties &getProperties() { - return properties; - } - - ::mlir::DictionaryAttr getAttributes(); - ::mlir::FlatSymbolRefAttr getCalleeAttr(); - ::llvm::StringRef getCallee(); -}; -} // namespace detail -template -class GenericCallOpGenericAdaptor : public detail::GenericCallOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::GenericCallOpGenericAdaptorBase; -public: - GenericCallOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - GenericCallOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : GenericCallOpGenericAdaptor(values, attrs, (properties ? *properties.as() : Properties{}), regions) {} - - template >> - GenericCallOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - RangeT getInputs() { - return getODSOperands(0); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class GenericCallOpAdaptor : public GenericCallOpGenericAdaptor<::mlir::ValueRange> { -public: - using GenericCallOpGenericAdaptor::GenericCallOpGenericAdaptor; - GenericCallOpAdaptor(GenericCallOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class GenericCallOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::VariadicOperands, ::mlir::OpTrait::OpInvariants, ::mlir::BytecodeOpInterface::Trait, ::mlir::CallOpInterface::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = GenericCallOpAdaptor; - template - using GenericAdaptor = GenericCallOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - using Properties = FoldAdaptor::Properties; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - static ::llvm::StringRef attrNames[] = {::llvm::StringRef("callee")}; - return ::llvm::ArrayRef(attrNames); - } - - ::mlir::StringAttr getCalleeAttrName() { - return getAttributeNameForIndex(0); - } - - static ::mlir::StringAttr getCalleeAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 0); - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.generic_call"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::Operation::operand_range getInputs(); - ::mlir::MutableOperandRange getInputsMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static ::mlir::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop); - static llvm::hash_code computePropertiesHash(const Properties &prop); - static std::optional getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name); - static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value); - static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs); - static ::mlir::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::LogicalResult readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state); - void writeProperties(::mlir::DialectBytecodeWriter &writer); - ::mlir::FlatSymbolRefAttr getCalleeAttr(); - ::llvm::StringRef getCallee(); - void setCalleeAttr(::mlir::FlatSymbolRefAttr attr); - void setCallee(::llvm::StringRef attrValue); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, StringRef callee, ArrayRef arguments); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::FlatSymbolRefAttr callee, ::mlir::ValueRange inputs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::FlatSymbolRefAttr callee, ::mlir::ValueRange inputs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::llvm::StringRef callee, ::mlir::ValueRange inputs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::llvm::StringRef callee, ::mlir::ValueRange inputs); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - ::mlir::CallInterfaceCallable getCallableForCallee(); - void setCalleeFromCallable(::mlir::CallInterfaceCallable callee); - ::mlir::Operation::operand_range getArgOperands(); - ::mlir::MutableOperandRange getArgOperandsMutable(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); -private: - ::mlir::StringAttr getAttributeNameForIndex(unsigned index) { - return getAttributeNameForIndex((*this)->getName(), index); - } - - static ::mlir::StringAttr getAttributeNameForIndex(::mlir::OperationName name, unsigned index) { - assert(index < 1 && "invalid attribute index"); - assert(name.getStringRef() == getOperationName() && "invalid operation name"); - assert(name.isRegistered() && "Operation isn't registered, missing a " - "dependent dialect loading?"); - return name.getAttributeNames()[index]; - } - -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::GenericCallOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::MulOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class MulOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - MulOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - MulOpGenericAdaptorBase(MulOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class MulOpGenericAdaptor : public detail::MulOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::MulOpGenericAdaptorBase; -public: - MulOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - MulOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : MulOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - MulOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getLhs() { - return (*getODSOperands(0).begin()); - } - - ValueT getRhs() { - return (*getODSOperands(1).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class MulOpAdaptor : public MulOpGenericAdaptor<::mlir::ValueRange> { -public: - using MulOpGenericAdaptor::MulOpGenericAdaptor; - MulOpAdaptor(MulOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class MulOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::NOperands<2>::Impl, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait, ShapeInference::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = MulOpAdaptor; - template - using GenericAdaptor = MulOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.mul"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getLhs(); - ::mlir::TypedValue<::mlir::TensorType> getRhs(); - ::mlir::OpOperand &getLhsMutable(); - ::mlir::OpOperand &getRhsMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, Value lhs, Value rhs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value lhs, ::mlir::Value rhs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &p); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - void inferShapes(); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::MulOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::PrintOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class PrintOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - PrintOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - PrintOpGenericAdaptorBase(PrintOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class PrintOpGenericAdaptor : public detail::PrintOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::PrintOpGenericAdaptorBase; -public: - PrintOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - PrintOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : PrintOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - PrintOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getInput() { - return (*getODSOperands(0).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class PrintOpAdaptor : public PrintOpGenericAdaptor<::mlir::ValueRange> { -public: - using PrintOpGenericAdaptor::PrintOpGenericAdaptor; - PrintOpAdaptor(PrintOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class PrintOp : public ::mlir::Op { -public: - using Op::Op; - using Op::print; - using Adaptor = PrintOpAdaptor; - template - using GenericAdaptor = PrintOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.print"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::Value getInput(); - ::mlir::OpOperand &getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::PrintOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ReshapeOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class ReshapeOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - ReshapeOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - ReshapeOpGenericAdaptorBase(ReshapeOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class ReshapeOpGenericAdaptor : public detail::ReshapeOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::ReshapeOpGenericAdaptorBase; -public: - ReshapeOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - ReshapeOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : ReshapeOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - ReshapeOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getInput() { - return (*getODSOperands(0).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class ReshapeOpAdaptor : public ReshapeOpGenericAdaptor<::mlir::ValueRange> { -public: - using ReshapeOpGenericAdaptor::ReshapeOpGenericAdaptor; - ReshapeOpAdaptor(ReshapeOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class ReshapeOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::OneOperand, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = ReshapeOpAdaptor; - template - using GenericAdaptor = ReshapeOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.reshape"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getInput(); - ::mlir::OpOperand &getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - static void getCanonicalizationPatterns(::mlir::RewritePatternSet &results, ::mlir::MLIRContext *context); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::ReshapeOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ReturnOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class ReturnOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - ReturnOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - ReturnOpGenericAdaptorBase(ReturnOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class ReturnOpGenericAdaptor : public detail::ReturnOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::ReturnOpGenericAdaptorBase; -public: - ReturnOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - ReturnOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : ReturnOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - ReturnOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - RangeT getInput() { - return getODSOperands(0); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class ReturnOpAdaptor : public ReturnOpGenericAdaptor<::mlir::ValueRange> { -public: - using ReturnOpGenericAdaptor::ReturnOpGenericAdaptor; - ReturnOpAdaptor(ReturnOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class ReturnOp : public ::mlir::Op::Impl, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait, ::mlir::OpTrait::IsTerminator> { -public: - using Op::Op; - using Op::print; - using Adaptor = ReturnOpAdaptor; - template - using GenericAdaptor = ReturnOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.return"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::Operation::operand_range getInput(); - ::mlir::MutableOperandRange getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - ::mlir::LogicalResult verify(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: - bool hasOperand() { return getNumOperands() != 0; } -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::ReturnOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::TransposeOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class TransposeOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - TransposeOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - TransposeOpGenericAdaptorBase(TransposeOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class TransposeOpGenericAdaptor : public detail::TransposeOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::TransposeOpGenericAdaptorBase; -public: - TransposeOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - TransposeOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : TransposeOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - TransposeOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getInput() { - return (*getODSOperands(0).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class TransposeOpAdaptor : public TransposeOpGenericAdaptor<::mlir::ValueRange> { -public: - using TransposeOpGenericAdaptor::TransposeOpGenericAdaptor; - TransposeOpAdaptor(TransposeOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class TransposeOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::OneOperand, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait, ShapeInference::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = TransposeOpAdaptor; - template - using GenericAdaptor = TransposeOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.transpose"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getInput(); - ::mlir::OpOperand &getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - ::mlir::LogicalResult verify(); - static void getCanonicalizationPatterns(::mlir::RewritePatternSet &results, ::mlir::MLIRContext *context); - void inferShapes(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::TransposeOp) - - -#endif // GET_OP_CLASSES - diff --git a/Ch5/include/toy/ShapeInferenceOpInterfaces.cpp.inc b/Ch5/include/toy/ShapeInferenceOpInterfaces.cpp.inc deleted file mode 100644 index a481d2e..0000000 --- a/Ch5/include/toy/ShapeInferenceOpInterfaces.cpp.inc +++ /dev/null @@ -1,12 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Interface Definitions *| -|* *| -|* Automatically generated file, do not edit! *| -|* *| -\*===----------------------------------------------------------------------===*/ - -/// Infer and set the output shape for the current operation. -void ShapeInference::inferShapes() { - return getImpl()->inferShapes(getImpl(), getOperation()); - } diff --git a/Ch5/include/toy/ShapeInferenceOpInterfaces.h.inc b/Ch5/include/toy/ShapeInferenceOpInterfaces.h.inc deleted file mode 100644 index bb24654..0000000 --- a/Ch5/include/toy/ShapeInferenceOpInterfaces.h.inc +++ /dev/null @@ -1,61 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Interface Declarations *| -|* *| -|* Automatically generated file, do not edit! *| -|* *| -\*===----------------------------------------------------------------------===*/ - -class ShapeInference; -namespace detail { -struct ShapeInferenceInterfaceTraits { - struct Concept { - /// The methods defined by the interface. - void (*inferShapes)(const Concept *impl, ::mlir::Operation *); - }; - template - class Model : public Concept { - public: - using Interface = ShapeInference; - Model() : Concept{inferShapes} {} - - static inline void inferShapes(const Concept *impl, ::mlir::Operation *tablegen_opaque_val); - }; - template - class FallbackModel : public Concept { - public: - using Interface = ShapeInference; - FallbackModel() : Concept{inferShapes} {} - - static inline void inferShapes(const Concept *impl, ::mlir::Operation *tablegen_opaque_val); - }; - template - class ExternalModel : public FallbackModel { - public: - using ConcreteEntity = ConcreteOp; - }; -};template -struct ShapeInferenceTrait; - -} // namespace detail -class ShapeInference : public ::mlir::OpInterface { -public: - using ::mlir::OpInterface::OpInterface; - template - struct Trait : public detail::ShapeInferenceTrait {}; - /// Infer and set the output shape for the current operation. - void inferShapes(); -}; -namespace detail { - template - struct ShapeInferenceTrait : public ::mlir::OpInterface::Trait { - }; -}// namespace detail -template -void detail::ShapeInferenceInterfaceTraits::Model::inferShapes(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) { - return (llvm::cast(tablegen_opaque_val)).inferShapes(); -} -template -void detail::ShapeInferenceInterfaceTraits::FallbackModel::inferShapes(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) { - return static_cast(impl)->inferShapes(tablegen_opaque_val); -} diff --git a/Ch5/mlir/ToyCombine.inc b/Ch5/mlir/ToyCombine.inc deleted file mode 100644 index 61c6203..0000000 --- a/Ch5/mlir/ToyCombine.inc +++ /dev/null @@ -1,176 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Rewriters *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: ToyCombine.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -/* Generated from: - ToyCombine.td:46 -*/ -struct FoldConstantReshapeOptPattern : public ::mlir::RewritePattern { - FoldConstantReshapeOptPattern(::mlir::MLIRContext *context) - : ::mlir::RewritePattern("toy.reshape", 2, context, {"toy.constant"}) {} - ::mlir::LogicalResult matchAndRewrite(::mlir::Operation *op0, - ::mlir::PatternRewriter &rewriter) const override { - // Variables for capturing values and attributes used while creating ops - ::mlir::DenseElementsAttr arg; - ::mlir::toy::ReshapeOp res; - ::llvm::SmallVector<::mlir::Operation *, 4> tblgen_ops; - - // Match - tblgen_ops.push_back(op0); - auto castedOp0 = ::llvm::dyn_cast<::mlir::toy::ReshapeOp>(op0); (void)castedOp0; - res = castedOp0; - { - auto *op1 = (*castedOp0.getODSOperands(0).begin()).getDefiningOp(); - if (!(op1)){ - return rewriter.notifyMatchFailure(castedOp0, [&](::mlir::Diagnostic &diag) { - diag << "There's no operation that defines operand 0 of castedOp0"; - }); - } - auto castedOp1 = ::llvm::dyn_cast<::mlir::toy::ConstantOp>(op1); (void)castedOp1; - if (!(castedOp1)){ - return rewriter.notifyMatchFailure(op1, [&](::mlir::Diagnostic &diag) { - diag << "castedOp1 is not ::mlir::toy::ConstantOp type"; - }); - } - { - auto tblgen_attr = op1->getAttrOfType<::mlir::DenseElementsAttr>("value");(void)tblgen_attr; - if (!(tblgen_attr)){ - return rewriter.notifyMatchFailure(op1, [&](::mlir::Diagnostic &diag) { - diag << "expected op 'toy.constant' to have attribute 'value' of type '::mlir::DenseElementsAttr'"; - }); - } - arg = tblgen_attr; - } - tblgen_ops.push_back(op1); - } - - // Rewrite - auto odsLoc = rewriter.getFusedLoc({tblgen_ops[0]->getLoc(), tblgen_ops[1]->getLoc()}); (void)odsLoc; - ::llvm::SmallVector<::mlir::Value, 4> tblgen_repl_values; - auto nativeVar_0 = arg.reshape(::llvm::cast((*res.getODSResults(0).begin()).getType())); (void)nativeVar_0; - ::mlir::toy::ConstantOp tblgen_ConstantOp_1; - { - ::llvm::SmallVector<::mlir::Value, 4> tblgen_values; (void)tblgen_values; - ::llvm::SmallVector<::mlir::NamedAttribute, 4> tblgen_attrs; (void)tblgen_attrs; - if (auto tmpAttr = nativeVar_0) { - tblgen_attrs.emplace_back(rewriter.getStringAttr("value"), tmpAttr); - } - ::llvm::SmallVector<::mlir::Type, 4> tblgen_types; (void)tblgen_types; - for (auto v: castedOp0.getODSResults(0)) { - tblgen_types.push_back(v.getType()); - } - tblgen_ConstantOp_1 = rewriter.create<::mlir::toy::ConstantOp>(odsLoc, tblgen_types, tblgen_values, tblgen_attrs); - } - - for (auto v: ::llvm::SmallVector<::mlir::Value, 4>{ tblgen_ConstantOp_1.getODSResults(0) }) { - tblgen_repl_values.push_back(v); - } - - rewriter.replaceOp(op0, tblgen_repl_values); - return ::mlir::success(); - }; -}; - -/* Generated from: - ToyCombine.td:59 -*/ -struct RedundantReshapeOptPattern : public ::mlir::RewritePattern { - RedundantReshapeOptPattern(::mlir::MLIRContext *context) - : ::mlir::RewritePattern("toy.reshape", 1, context, {}) {} - ::mlir::LogicalResult matchAndRewrite(::mlir::Operation *op0, - ::mlir::PatternRewriter &rewriter) const override { - // Variables for capturing values and attributes used while creating ops - ::mlir::Operation::operand_range arg(op0->getOperands()); - ::mlir::toy::ReshapeOp res; - ::llvm::SmallVector<::mlir::Operation *, 4> tblgen_ops; - - // Match - tblgen_ops.push_back(op0); - auto castedOp0 = ::llvm::dyn_cast<::mlir::toy::ReshapeOp>(op0); (void)castedOp0; - res = castedOp0; - arg = castedOp0.getODSOperands(0); - if (!(((*res.getODSResults(0).begin()).getType() == (*arg.begin()).getType()))){ - return rewriter.notifyMatchFailure(op0, [&](::mlir::Diagnostic &diag) { - diag << "entities 'res, arg' failed to satisfy constraint: ''"; - }); - } - - // Rewrite - auto odsLoc = rewriter.getFusedLoc({tblgen_ops[0]->getLoc()}); (void)odsLoc; - ::llvm::SmallVector<::mlir::Value, 4> tblgen_repl_values; - - for (auto v: ::llvm::SmallVector<::mlir::Value, 4>{ arg }) { - tblgen_repl_values.push_back(v); - } - - rewriter.replaceOp(op0, tblgen_repl_values); - return ::mlir::success(); - }; -}; - -/* Generated from: - ToyCombine.td:33 -*/ -struct ReshapeReshapeOptPattern : public ::mlir::RewritePattern { - ReshapeReshapeOptPattern(::mlir::MLIRContext *context) - : ::mlir::RewritePattern("toy.reshape", 2, context, {"toy.reshape"}) {} - ::mlir::LogicalResult matchAndRewrite(::mlir::Operation *op0, - ::mlir::PatternRewriter &rewriter) const override { - // Variables for capturing values and attributes used while creating ops - ::mlir::Operation::operand_range arg(op0->getOperands()); - ::llvm::SmallVector<::mlir::Operation *, 4> tblgen_ops; - - // Match - tblgen_ops.push_back(op0); - auto castedOp0 = ::llvm::dyn_cast<::mlir::toy::ReshapeOp>(op0); (void)castedOp0; - { - auto *op1 = (*castedOp0.getODSOperands(0).begin()).getDefiningOp(); - if (!(op1)){ - return rewriter.notifyMatchFailure(castedOp0, [&](::mlir::Diagnostic &diag) { - diag << "There's no operation that defines operand 0 of castedOp0"; - }); - } - auto castedOp1 = ::llvm::dyn_cast<::mlir::toy::ReshapeOp>(op1); (void)castedOp1; - if (!(castedOp1)){ - return rewriter.notifyMatchFailure(op1, [&](::mlir::Diagnostic &diag) { - diag << "castedOp1 is not ::mlir::toy::ReshapeOp type"; - }); - } - arg = castedOp1.getODSOperands(0); - tblgen_ops.push_back(op1); - } - - // Rewrite - auto odsLoc = rewriter.getFusedLoc({tblgen_ops[0]->getLoc(), tblgen_ops[1]->getLoc()}); (void)odsLoc; - ::llvm::SmallVector<::mlir::Value, 4> tblgen_repl_values; - ::mlir::toy::ReshapeOp tblgen_ReshapeOp_0; - { - ::llvm::SmallVector<::mlir::Value, 4> tblgen_values; (void)tblgen_values; - ::llvm::SmallVector<::mlir::NamedAttribute, 4> tblgen_attrs; (void)tblgen_attrs; - tblgen_values.push_back((*arg.begin())); - ::llvm::SmallVector<::mlir::Type, 4> tblgen_types; (void)tblgen_types; - for (auto v: castedOp0.getODSResults(0)) { - tblgen_types.push_back(v.getType()); - } - tblgen_ReshapeOp_0 = rewriter.create<::mlir::toy::ReshapeOp>(odsLoc, tblgen_types, tblgen_values, tblgen_attrs); - } - - for (auto v: ::llvm::SmallVector<::mlir::Value, 4>{ tblgen_ReshapeOp_0.getODSResults(0) }) { - tblgen_repl_values.push_back(v); - } - - rewriter.replaceOp(op0, tblgen_repl_values); - return ::mlir::success(); - }; -}; - -void LLVM_ATTRIBUTE_UNUSED populateWithGenerated(::mlir::RewritePatternSet &patterns) { - patterns.add(patterns.getContext()); - patterns.add(patterns.getContext()); - patterns.add(patterns.getContext()); -} diff --git a/Ch5/mlir/run.sh b/Ch5/mlir/run.sh deleted file mode 100644 index f592fde..0000000 --- a/Ch5/mlir/run.sh +++ /dev/null @@ -1,2 +0,0 @@ -mlir-tblgen-18 -gen-rewriters -I /usr/lib/llvm-18/include -I ../include ToyCombine.td > ToyCombine.inc - diff --git a/Ch6/CMakeLists.txt b/Ch6/CMakeLists.txt index aef5b99..283b895 100644 --- a/Ch6/CMakeLists.txt +++ b/Ch6/CMakeLists.txt @@ -15,11 +15,11 @@ set(LLVM_LINK_COMPONENTS OrcJIT ) -# set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td) -# mlir_tablegen(ToyCombine.inc -gen-rewriters) -# add_public_tablegen_target(ToyCh6CombineIncGen) +set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td) +mlir_tablegen(ToyCombine.inc -gen-rewriters) +add_public_tablegen_target(ToyCh6CombineIncGen) -add_executable(toyc-ch6 +add_toy_chapter(toyc-ch6 toyc.cpp parser/AST.cpp mlir/MLIRGen.cpp @@ -29,10 +29,10 @@ add_executable(toyc-ch6 mlir/ShapeInferencePass.cpp mlir/ToyCombine.cpp - # DEPENDS - # ToyCh6ShapeInferenceInterfaceIncGen - # ToyCh6OpsIncGen - # ToyCh6CombineIncGen + DEPENDS + ToyCh6ShapeInferenceInterfaceIncGen + ToyCh6OpsIncGen + ToyCh6CombineIncGen ) include_directories(${CMAKE_CURRENT_BINARY_DIR}) diff --git a/Ch6/include/run.sh b/Ch6/include/run.sh deleted file mode 100644 index b9d18af..0000000 --- a/Ch6/include/run.sh +++ /dev/null @@ -1,7 +0,0 @@ -mlir-tblgen-18 -gen-op-decls -I /usr/lib/llvm-18/include toy/Ops.td > toy/Ops.h.inc -mlir-tblgen-18 -gen-op-defs -I /usr/lib/llvm-18/include toy/Ops.td > toy/Ops.cpp.inc -mlir-tblgen-18 -gen-dialect-decls -I /usr/lib/llvm-18/include toy/Ops.td > toy/Dialect.h.inc -mlir-tblgen-18 -gen-dialect-defs -I /usr/lib/llvm-18/include toy/Ops.td > toy/Dialect.cpp.inc - -mlir-tblgen-18 -gen-op-interface-decls -I /usr/lib/llvm-18/include toy/ShapeInferenceInterface.td > toy/ShapeInferenceOpInterfaces.h.inc -mlir-tblgen-18 -gen-op-interface-defs -I /usr/lib/llvm-18/include toy/ShapeInferenceInterface.td > toy/ShapeInferenceOpInterfaces.cpp.inc diff --git a/Ch6/include/toy/CMakeLists.txt b/Ch6/include/toy/CMakeLists.txt index 2f9729c..03e8a2a 100644 --- a/Ch6/include/toy/CMakeLists.txt +++ b/Ch6/include/toy/CMakeLists.txt @@ -1,13 +1,13 @@ -# # Most dialects should use add_mlir_dialect(). See examples/standalone. -# set(LLVM_TARGET_DEFINITIONS Ops.td) -# mlir_tablegen(Ops.h.inc -gen-op-decls) -# mlir_tablegen(Ops.cpp.inc -gen-op-defs) -# mlir_tablegen(Dialect.h.inc -gen-dialect-decls) -# mlir_tablegen(Dialect.cpp.inc -gen-dialect-defs) -# add_public_tablegen_target(ToyCh6OpsIncGen) +# Most dialects should use add_mlir_dialect(). See examples/standalone. +set(LLVM_TARGET_DEFINITIONS Ops.td) +mlir_tablegen(Ops.h.inc -gen-op-decls) +mlir_tablegen(Ops.cpp.inc -gen-op-defs) +mlir_tablegen(Dialect.h.inc -gen-dialect-decls) +mlir_tablegen(Dialect.cpp.inc -gen-dialect-defs) +add_public_tablegen_target(ToyCh6OpsIncGen) -# # Most dialects should use add_mlir_interfaces(). -# set(LLVM_TARGET_DEFINITIONS ShapeInferenceInterface.td) -# mlir_tablegen(ShapeInferenceOpInterfaces.h.inc -gen-op-interface-decls) -# mlir_tablegen(ShapeInferenceOpInterfaces.cpp.inc -gen-op-interface-defs) -# add_public_tablegen_target(ToyCh6ShapeInferenceInterfaceIncGen) +# Most dialects should use add_mlir_interfaces(). +set(LLVM_TARGET_DEFINITIONS ShapeInferenceInterface.td) +mlir_tablegen(ShapeInferenceOpInterfaces.h.inc -gen-op-interface-decls) +mlir_tablegen(ShapeInferenceOpInterfaces.cpp.inc -gen-op-interface-defs) +add_public_tablegen_target(ToyCh6ShapeInferenceInterfaceIncGen) diff --git a/Ch6/include/toy/Dialect.cpp.inc b/Ch6/include/toy/Dialect.cpp.inc deleted file mode 100644 index 8cbc772..0000000 --- a/Ch6/include/toy/Dialect.cpp.inc +++ /dev/null @@ -1,23 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Dialect Definitions *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: Ops.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::ToyDialect) -namespace mlir { -namespace toy { - -ToyDialect::ToyDialect(::mlir::MLIRContext *context) - : ::mlir::Dialect(getDialectNamespace(), context, ::mlir::TypeID::get()) { - - initialize(); -} - -ToyDialect::~ToyDialect() = default; - -} // namespace toy -} // namespace mlir diff --git a/Ch6/include/toy/Dialect.h.inc b/Ch6/include/toy/Dialect.h.inc deleted file mode 100644 index f19d867..0000000 --- a/Ch6/include/toy/Dialect.h.inc +++ /dev/null @@ -1,26 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Dialect Declarations *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: Ops.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -namespace mlir { -namespace toy { - -class ToyDialect : public ::mlir::Dialect { - explicit ToyDialect(::mlir::MLIRContext *context); - - void initialize(); - friend class ::mlir::MLIRContext; -public: - ~ToyDialect() override; - static constexpr ::llvm::StringLiteral getDialectNamespace() { - return ::llvm::StringLiteral("toy"); - } -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::ToyDialect) diff --git a/Ch6/include/toy/Ops.cpp.inc b/Ch6/include/toy/Ops.cpp.inc deleted file mode 100644 index 6bb98a2..0000000 --- a/Ch6/include/toy/Ops.cpp.inc +++ /dev/null @@ -1,2252 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Op Definitions *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: Ops.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -#ifdef GET_OP_LIST -#undef GET_OP_LIST - -::mlir::toy::AddOp, -::mlir::toy::CastOp, -::mlir::toy::ConstantOp, -::mlir::toy::FuncOp, -::mlir::toy::GenericCallOp, -::mlir::toy::MulOp, -::mlir::toy::PrintOp, -::mlir::toy::ReshapeOp, -::mlir::toy::ReturnOp, -::mlir::toy::TransposeOp -#endif // GET_OP_LIST - -#ifdef GET_OP_CLASSES -#undef GET_OP_CLASSES - - -//===----------------------------------------------------------------------===// -// Local Utility Method Definitions -//===----------------------------------------------------------------------===// - -namespace mlir { -namespace toy { - -static ::mlir::LogicalResult __mlir_ods_local_type_constraint_Ops0( - ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, - unsigned valueIndex) { - if (!(((::llvm::isa<::mlir::TensorType>(type))) && ([](::mlir::Type elementType) { return (elementType.isF64()); }(::llvm::cast<::mlir::ShapedType>(type).getElementType())))) { - return op->emitOpError(valueKind) << " #" << valueIndex - << " must be tensor of 64-bit float values, but got " << type; - } - return ::mlir::success(); -} - -static ::mlir::LogicalResult __mlir_ods_local_type_constraint_Ops1( - ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, - unsigned valueIndex) { - if (!(((::llvm::isa<::mlir::TensorType>(type))) && ([](::mlir::Type elementType) { return (elementType.isF64()); }(::llvm::cast<::mlir::ShapedType>(type).getElementType())))) { - return op->emitOpError(valueKind) << " #" << valueIndex - << " must be variadic of tensor of 64-bit float values, but got " << type; - } - return ::mlir::success(); -} - -static ::mlir::LogicalResult __mlir_ods_local_type_constraint_Ops2( - ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, - unsigned valueIndex) { - if (!((((::llvm::isa<::mlir::TensorType>(type))) && ([](::mlir::Type elementType) { return (elementType.isF64()); }(::llvm::cast<::mlir::ShapedType>(type).getElementType()))) || (((::llvm::isa<::mlir::MemRefType>(type))) && ([](::mlir::Type elementType) { return (elementType.isF64()); }(::llvm::cast<::mlir::ShapedType>(type).getElementType()))))) { - return op->emitOpError(valueKind) << " #" << valueIndex - << " must be tensor of 64-bit float values or memref of 64-bit float values, but got " << type; - } - return ::mlir::success(); -} - -static ::mlir::LogicalResult __mlir_ods_local_type_constraint_Ops3( - ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, - unsigned valueIndex) { - if (!((((::llvm::isa<::mlir::RankedTensorType>(type))) && ((::llvm::cast<::mlir::ShapedType>(type).hasStaticShape()))) && ([](::mlir::Type elementType) { return (elementType.isF64()); }(::llvm::cast<::mlir::ShapedType>(type).getElementType())))) { - return op->emitOpError(valueKind) << " #" << valueIndex - << " must be statically shaped tensor of 64-bit float values, but got " << type; - } - return ::mlir::success(); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops0( - ::mlir::Attribute attr, ::llvm::StringRef attrName, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { - if (attr && !((::llvm::isa<::mlir::DenseFPElementsAttr>(attr) &&::llvm::cast<::mlir::DenseElementsAttr>(attr).getType().getElementType().isF64()))) - return emitError() << "attribute '" << attrName - << "' failed to satisfy constraint: 64-bit float elements attribute"; - return ::mlir::success(); -} -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops0( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops0(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops1( - ::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 ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops1( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops1(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops2( - ::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 ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops2( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops2(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops3( - ::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 ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops3( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops3(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops4( - ::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 ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops4( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops4(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_region_constraint_Ops0( - ::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 toy -} // namespace mlir -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::AddOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -AddOpGenericAdaptorBase::AddOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.add", odsAttrs.getContext()); -} - -AddOpGenericAdaptorBase::AddOpGenericAdaptorBase(AddOp op) : AddOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair AddOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr AddOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -AddOpAdaptor::AddOpAdaptor(AddOp op) : AddOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult AddOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair AddOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range AddOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> AddOp::getLhs() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::TypedValue<::mlir::TensorType> AddOp::getRhs() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(1).begin()); -} - -::mlir::OpOperand &AddOp::getLhsMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -::mlir::OpOperand &AddOp::getRhsMutable() { - auto range = getODSOperandIndexAndLength(1); - return getOperation()->getOpOperand(range.first); -} - -std::pair AddOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range AddOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void AddOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value lhs, ::mlir::Value rhs) { - odsState.addOperands(lhs); - odsState.addOperands(rhs); - odsState.addTypes(resultType0); -} - -void AddOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs) { - odsState.addOperands(lhs); - odsState.addOperands(rhs); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void AddOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 2u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult AddOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*this, v.getType(), "operand", index++))) - return ::mlir::failure(); - } - auto valueGroup1 = getODSOperands(1); - - for (auto v : valueGroup1) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult AddOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -void AddOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::AddOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::CastOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -CastOpGenericAdaptorBase::CastOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.cast", odsAttrs.getContext()); -} - -CastOpGenericAdaptorBase::CastOpGenericAdaptorBase(CastOp op) : CastOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair CastOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr CastOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -CastOpAdaptor::CastOpAdaptor(CastOp op) : CastOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult CastOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair CastOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range CastOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> CastOp::getInput() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::OpOperand &CastOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -std::pair CastOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range CastOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> CastOp::getOutput() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSResults(0).begin()); -} - -void CastOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type output, ::mlir::Value input) { - odsState.addOperands(input); - odsState.addTypes(output); -} - -void CastOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input) { - odsState.addOperands(input); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void CastOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 1u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult CastOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult CastOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -::mlir::ParseResult CastOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::OpAsmParser::UnresolvedOperand inputRawOperands[1]; - ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> inputOperands(inputRawOperands); ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::mlir::Type inputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> inputTypes(inputRawTypes); - ::mlir::Type outputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> outputTypes(outputRawTypes); - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperand(inputRawOperands[0])) - return ::mlir::failure(); - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.parseColon()) - return ::mlir::failure(); - - { - ::mlir::TensorType type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - inputRawTypes[0] = type; - } - if (parser.parseKeyword("to")) - return ::mlir::failure(); - - { - ::mlir::TensorType type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - outputRawTypes[0] = type; - } - result.addTypes(outputTypes); - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void CastOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << ' '; - _odsPrinter << getInput(); - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - { - auto type = getInput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::TensorType>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } - _odsPrinter << ' ' << "to"; - _odsPrinter << ' '; - { - auto type = getOutput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::TensorType>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } -} - -void CastOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::CastOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ConstantOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -ConstantOpGenericAdaptorBase::ConstantOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.constant", odsAttrs.getContext()); -} - -ConstantOpGenericAdaptorBase::ConstantOpGenericAdaptorBase(ConstantOp op) : ConstantOpGenericAdaptorBase(op->getDiscardableAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair ConstantOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr ConstantOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -::mlir::DenseElementsAttr ConstantOpGenericAdaptorBase::getValueAttr() { - auto attr = ::llvm::cast<::mlir::DenseElementsAttr>(getProperties().value); - return attr; -} - -::mlir::DenseElementsAttr ConstantOpGenericAdaptorBase::getValue() { - auto attr = getValueAttr(); - return attr; -} - -} // namespace detail -ConstantOpAdaptor::ConstantOpAdaptor(ConstantOp op) : ConstantOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult ConstantOpAdaptor::verify(::mlir::Location loc) { - auto tblgen_value = getProperties().value; (void)tblgen_value; - if (!tblgen_value) return emitError(loc, "'toy.constant' op ""requires attribute 'value'"); - - if (tblgen_value && !((::llvm::isa<::mlir::DenseFPElementsAttr>(tblgen_value) &&::llvm::cast<::mlir::DenseElementsAttr>(tblgen_value).getType().getElementType().isF64()))) - return emitError(loc, "'toy.constant' op ""attribute 'value' failed to satisfy constraint: 64-bit float elements attribute"); - return ::mlir::success(); -} - -std::pair ConstantOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range ConstantOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -std::pair ConstantOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range ConstantOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::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 || /*isRequired=*/true) { - if (!attr) { - emitError() << "expected key entry for value in DictionaryAttr to set " - "Properties."; - return ::mlir::failure(); - } - 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) { - 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); -} - -::mlir::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_Ops0(attr, "value", emitError))) - return ::mlir::failure(); - } - return ::mlir::success(); -} - -::mlir::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); -} - -::mlir::DenseElementsAttr ConstantOp::getValueAttr() { - return ::llvm::cast<::mlir::DenseElementsAttr>(getProperties().value); -} - -::mlir::DenseElementsAttr ConstantOp::getValue() { - auto attr = getValueAttr(); - return attr; -} - -void ConstantOp::setValueAttr(::mlir::DenseElementsAttr attr) { - (*this)->setAttr(getValueAttrName(), attr); -} - -void ConstantOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, DenseElementsAttr value) { - build(odsBuilder, odsState, value.getType(), value); - -} - -void ConstantOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::DenseElementsAttr value) { - odsState.getOrAddProperties().value = value; - odsState.addTypes(resultType0); -} - -void ConstantOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::DenseElementsAttr value) { - odsState.getOrAddProperties().value = value; - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -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); -} - -::mlir::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_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult ConstantOp::verifyInvariants() { - if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) - return ::mlir::success(); - return ::mlir::failure(); -} - -void ConstantOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::ConstantOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::FuncOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -FuncOpGenericAdaptorBase::FuncOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.func", odsAttrs.getContext()); -} - -FuncOpGenericAdaptorBase::FuncOpGenericAdaptorBase(FuncOp op) : FuncOpGenericAdaptorBase(op->getDiscardableAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair FuncOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr FuncOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -::mlir::StringAttr FuncOpGenericAdaptorBase::getSymNameAttr() { - auto attr = ::llvm::cast<::mlir::StringAttr>(getProperties().sym_name); - return attr; -} - -::llvm::StringRef FuncOpGenericAdaptorBase::getSymName() { - auto attr = getSymNameAttr(); - return attr.getValue(); -} - -::mlir::TypeAttr FuncOpGenericAdaptorBase::getFunctionTypeAttr() { - auto attr = ::llvm::cast<::mlir::TypeAttr>(getProperties().function_type); - return attr; -} - -::mlir::FunctionType FuncOpGenericAdaptorBase::getFunctionType() { - auto attr = getFunctionTypeAttr(); - return ::llvm::cast<::mlir::FunctionType>(attr.getValue()); -} - -::mlir::ArrayAttr FuncOpGenericAdaptorBase::getArgAttrsAttr() { - auto attr = ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(getProperties().arg_attrs); - return attr; -} - -::std::optional< ::mlir::ArrayAttr > FuncOpGenericAdaptorBase::getArgAttrs() { - auto attr = getArgAttrsAttr(); - return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); -} - -::mlir::ArrayAttr FuncOpGenericAdaptorBase::getResAttrsAttr() { - auto attr = ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(getProperties().res_attrs); - return attr; -} - -::std::optional< ::mlir::ArrayAttr > FuncOpGenericAdaptorBase::getResAttrs() { - auto attr = getResAttrsAttr(); - return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); -} - -::mlir::Region &FuncOpGenericAdaptorBase::getBody() { - return *odsRegions[0]; -} - -::mlir::RegionRange FuncOpGenericAdaptorBase::getRegions() { - return odsRegions; -} - -} // namespace detail -FuncOpAdaptor::FuncOpAdaptor(FuncOp op) : FuncOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::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, "'toy.func' op ""requires attribute 'function_type'"); - 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, "'toy.func' op ""requires attribute 'sym_name'"); - - if (tblgen_sym_name && !((::llvm::isa<::mlir::StringAttr>(tblgen_sym_name)))) - return emitError(loc, "'toy.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, "'toy.func' op ""attribute 'function_type' failed to satisfy constraint: type attribute of function type"); - - 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, "'toy.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, "'toy.func' op ""attribute 'res_attrs' failed to satisfy constraint: Array of dictionary attributes"); - return ::mlir::success(); -} - -std::pair FuncOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range FuncOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -std::pair FuncOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range FuncOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::Region &FuncOp::getBody() { - return (*this)->getRegion(0); -} - -::mlir::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 || /*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.function_type; - auto attr = dict.get("function_type"); - 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.res_attrs; - auto attr = dict.get("res_attrs"); - 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.sym_name; - auto attr = dict.get("sym_name"); - 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(); - } - } - } - 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.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)); - } - - if (!attrs.empty()) - return odsBuilder.getDictionaryAttr(attrs); - return {}; -} - -llvm::hash_code FuncOp::computePropertiesHash(const Properties &prop) { - return llvm::hash_combine( - llvm::hash_value(prop.arg_attrs.getAsOpaquePointer()), - llvm::hash_value(prop.function_type.getAsOpaquePointer()), - llvm::hash_value(prop.res_attrs.getAsOpaquePointer()), - llvm::hash_value(prop.sym_name.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 == "res_attrs") - return prop.res_attrs; - - if (name == "sym_name") - return prop.sym_name; - 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 == "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; - } -} - -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.res_attrs) attrs.append("res_attrs", prop.res_attrs); - - if (prop.sym_name) attrs.append("sym_name", prop.sym_name); -} - -::mlir::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_Ops3(attr, "arg_attrs", emitError))) - return ::mlir::failure(); - } - - { - ::mlir::Attribute attr = attrs.get(getFunctionTypeAttrName(opName)); - if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_Ops2(attr, "function_type", emitError))) - return ::mlir::failure(); - } - - { - ::mlir::Attribute attr = attrs.get(getResAttrsAttrName(opName)); - if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_Ops3(attr, "res_attrs", emitError))) - return ::mlir::failure(); - } - - { - ::mlir::Attribute attr = attrs.get(getSymNameAttrName(opName)); - if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_Ops1(attr, "sym_name", emitError))) - return ::mlir::failure(); - } - return ::mlir::success(); -} - -::mlir::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.res_attrs))) - return ::mlir::failure(); - - if (::mlir::failed(reader.readAttribute(prop.sym_name))) - 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.res_attrs); - writer.writeAttribute(prop.sym_name); -} - -::mlir::StringAttr FuncOp::getSymNameAttr() { - return ::llvm::cast<::mlir::StringAttr>(getProperties().sym_name); -} - -::llvm::StringRef FuncOp::getSymName() { - auto attr = getSymNameAttr(); - return attr.getValue(); -} - -::mlir::TypeAttr FuncOp::getFunctionTypeAttr() { - return ::llvm::cast<::mlir::TypeAttr>(getProperties().function_type); -} - -::mlir::FunctionType FuncOp::getFunctionType() { - auto attr = getFunctionTypeAttr(); - return ::llvm::cast<::mlir::FunctionType>(attr.getValue()); -} - -::mlir::ArrayAttr FuncOp::getArgAttrsAttr() { - return ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(getProperties().arg_attrs); -} - -::std::optional< ::mlir::ArrayAttr > FuncOp::getArgAttrs() { - auto attr = getArgAttrsAttr(); - return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); -} - -::mlir::ArrayAttr FuncOp::getResAttrsAttr() { - return ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(getProperties().res_attrs); -} - -::std::optional< ::mlir::ArrayAttr > FuncOp::getResAttrs() { - auto attr = getResAttrsAttr(); - return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); -} - -void FuncOp::setSymNameAttr(::mlir::StringAttr attr) { - (*this)->setAttr(getSymNameAttrName(), attr); -} - -void FuncOp::setSymName(::llvm::StringRef attrValue) { - (*this)->setAttr(getSymNameAttrName(), ::mlir::Builder((*this)->getContext()).getStringAttr(attrValue)); -} - -void FuncOp::setFunctionTypeAttr(::mlir::TypeAttr attr) { - (*this)->setAttr(getFunctionTypeAttrName(), attr); -} - -void FuncOp::setFunctionType(::mlir::FunctionType attrValue) { - (*this)->setAttr(getFunctionTypeAttrName(), ::mlir::TypeAttr::get(attrValue)); -} - -void FuncOp::setArgAttrsAttr(::mlir::ArrayAttr attr) { - (*this)->setAttr(getArgAttrsAttrName(), attr); -} - -void FuncOp::setResAttrsAttr(::mlir::ArrayAttr attr) { - (*this)->setAttr(getResAttrsAttrName(), attr); -} - -::mlir::Attribute FuncOp::removeArgAttrsAttr() { - auto &attr = getProperties().arg_attrs; - attr = {}; - return attr; -} - -::mlir::Attribute FuncOp::removeResAttrsAttr() { - auto &attr = getProperties().res_attrs; - attr = {}; - return attr; -} - -::mlir::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_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'"); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops1(*this, tblgen_sym_name, "sym_name"))) - return ::mlir::failure(); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops2(*this, tblgen_function_type, "function_type"))) - return ::mlir::failure(); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops3(*this, tblgen_arg_attrs, "arg_attrs"))) - return ::mlir::failure(); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops3(*this, tblgen_res_attrs, "res_attrs"))) - return ::mlir::failure(); - { - unsigned index = 0; (void)index; - - for (auto ®ion : ::llvm::MutableArrayRef((*this)->getRegion(0))) - if (::mlir::failed(__mlir_ods_local_region_constraint_Ops0(*this, region, "body", index++))) - return ::mlir::failure(); - } - return ::mlir::success(); -} - -::mlir::LogicalResult FuncOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::FuncOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::GenericCallOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -GenericCallOpGenericAdaptorBase::GenericCallOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.generic_call", odsAttrs.getContext()); -} - -GenericCallOpGenericAdaptorBase::GenericCallOpGenericAdaptorBase(GenericCallOp op) : GenericCallOpGenericAdaptorBase(op->getDiscardableAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair GenericCallOpGenericAdaptorBase::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}; -} - -::mlir::DictionaryAttr GenericCallOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -::mlir::FlatSymbolRefAttr GenericCallOpGenericAdaptorBase::getCalleeAttr() { - auto attr = ::llvm::cast<::mlir::FlatSymbolRefAttr>(getProperties().callee); - return attr; -} - -::llvm::StringRef GenericCallOpGenericAdaptorBase::getCallee() { - auto attr = getCalleeAttr(); - return attr.getValue(); -} - -} // namespace detail -GenericCallOpAdaptor::GenericCallOpAdaptor(GenericCallOp op) : GenericCallOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult GenericCallOpAdaptor::verify(::mlir::Location loc) { - auto tblgen_callee = getProperties().callee; (void)tblgen_callee; - if (!tblgen_callee) return emitError(loc, "'toy.generic_call' op ""requires attribute 'callee'"); - - if (tblgen_callee && !((::llvm::isa<::mlir::FlatSymbolRefAttr>(tblgen_callee)))) - return emitError(loc, "'toy.generic_call' op ""attribute 'callee' failed to satisfy constraint: flat symbol reference attribute"); - return ::mlir::success(); -} - -std::pair GenericCallOp::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::Operation::operand_range GenericCallOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::Operation::operand_range GenericCallOp::getInputs() { - return getODSOperands(0); -} - -::mlir::MutableOperandRange GenericCallOp::getInputsMutable() { - auto range = getODSOperandIndexAndLength(0); - auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); - return mutableRange; -} - -std::pair GenericCallOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range GenericCallOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::LogicalResult GenericCallOp::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.callee; - auto attr = dict.get("callee"); - if (attr || /*isRequired=*/true) { - if (!attr) { - emitError() << "expected key entry for callee in DictionaryAttr to set " - "Properties."; - return ::mlir::failure(); - } - auto convertedAttr = ::llvm::dyn_cast>(attr); - if (convertedAttr) { - propStorage = convertedAttr; - } else { - emitError() << "Invalid attribute `callee` in property conversion: " << attr; - return ::mlir::failure(); - } - } - } - return ::mlir::success(); -} - -::mlir::Attribute GenericCallOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) { - ::mlir::SmallVector<::mlir::NamedAttribute> attrs; - ::mlir::Builder odsBuilder{ctx}; - - { - const auto &propStorage = prop.callee; - if (propStorage) - attrs.push_back(odsBuilder.getNamedAttr("callee", - propStorage)); - } - - if (!attrs.empty()) - return odsBuilder.getDictionaryAttr(attrs); - return {}; -} - -llvm::hash_code GenericCallOp::computePropertiesHash(const Properties &prop) { - return llvm::hash_combine( - llvm::hash_value(prop.callee.getAsOpaquePointer())); -} - -std::optional GenericCallOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { - if (name == "callee") - return prop.callee; - return std::nullopt; -} - -void GenericCallOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { - if (name == "callee") { - prop.callee = ::llvm::dyn_cast_or_null>(value); - return; - } -} - -void GenericCallOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { - if (prop.callee) attrs.append("callee", prop.callee); -} - -::mlir::LogicalResult GenericCallOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { - { - ::mlir::Attribute attr = attrs.get(getCalleeAttrName(opName)); - if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_Ops4(attr, "callee", emitError))) - return ::mlir::failure(); - } - return ::mlir::success(); -} - -::mlir::LogicalResult GenericCallOp::readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state) { - auto &prop = state.getOrAddProperties(); (void)prop; - if (::mlir::failed(reader.readAttribute(prop.callee))) - return ::mlir::failure(); - return ::mlir::success(); -} - -void GenericCallOp::writeProperties(::mlir::DialectBytecodeWriter &writer) { - auto &prop = getProperties(); (void)prop; - writer.writeAttribute(prop.callee); -} - -::mlir::FlatSymbolRefAttr GenericCallOp::getCalleeAttr() { - return ::llvm::cast<::mlir::FlatSymbolRefAttr>(getProperties().callee); -} - -::llvm::StringRef GenericCallOp::getCallee() { - auto attr = getCalleeAttr(); - return attr.getValue(); -} - -void GenericCallOp::setCalleeAttr(::mlir::FlatSymbolRefAttr attr) { - (*this)->setAttr(getCalleeAttrName(), attr); -} - -void GenericCallOp::setCallee(::llvm::StringRef attrValue) { - (*this)->setAttr(getCalleeAttrName(), ::mlir::SymbolRefAttr::get(::mlir::Builder((*this)->getContext()).getContext(), attrValue)); -} - -void GenericCallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::FlatSymbolRefAttr callee, ::mlir::ValueRange inputs) { - odsState.addOperands(inputs); - odsState.getOrAddProperties().callee = callee; - odsState.addTypes(resultType0); -} - -void GenericCallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::FlatSymbolRefAttr callee, ::mlir::ValueRange inputs) { - odsState.addOperands(inputs); - odsState.getOrAddProperties().callee = callee; - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void GenericCallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::llvm::StringRef callee, ::mlir::ValueRange inputs) { - odsState.addOperands(inputs); - odsState.getOrAddProperties().callee = ::mlir::SymbolRefAttr::get(odsBuilder.getContext(), callee); - odsState.addTypes(resultType0); -} - -void GenericCallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::llvm::StringRef callee, ::mlir::ValueRange inputs) { - odsState.addOperands(inputs); - odsState.getOrAddProperties().callee = ::mlir::SymbolRefAttr::get(odsBuilder.getContext(), callee); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void GenericCallOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult GenericCallOp::verifyInvariantsImpl() { - auto tblgen_callee = getProperties().callee; (void)tblgen_callee; - if (!tblgen_callee) return emitOpError("requires attribute 'callee'"); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops4(*this, tblgen_callee, "callee"))) - return ::mlir::failure(); - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops1(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult GenericCallOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -::mlir::ParseResult GenericCallOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::FlatSymbolRefAttr calleeAttr; - ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> inputsOperands; - ::llvm::SMLoc inputsOperandsLoc; - (void)inputsOperandsLoc; - ::llvm::ArrayRef<::mlir::Type> inputsTypes; - ::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(); - - inputsOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperandList(inputsOperands)) - 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 inputs__allResult_functionType; - if (parser.parseType(inputs__allResult_functionType)) - return ::mlir::failure(); - inputsTypes = inputs__allResult_functionType.getInputs(); - allResultTypes = inputs__allResult_functionType.getResults(); - result.addTypes(allResultTypes); - if (parser.resolveOperands(inputsOperands, inputsTypes, inputsOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void GenericCallOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << ' '; - _odsPrinter.printAttributeWithoutType(getCalleeAttr()); - _odsPrinter << "("; - _odsPrinter << getInputs(); - _odsPrinter << ")"; - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - elidedAttrs.push_back("callee"); - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - _odsPrinter.printFunctionalType(getInputs().getTypes(), getOperation()->getResultTypes()); -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::GenericCallOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::MulOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -MulOpGenericAdaptorBase::MulOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.mul", odsAttrs.getContext()); -} - -MulOpGenericAdaptorBase::MulOpGenericAdaptorBase(MulOp op) : MulOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair MulOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr MulOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -MulOpAdaptor::MulOpAdaptor(MulOp op) : MulOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult MulOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair MulOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range MulOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> MulOp::getLhs() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::TypedValue<::mlir::TensorType> MulOp::getRhs() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(1).begin()); -} - -::mlir::OpOperand &MulOp::getLhsMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -::mlir::OpOperand &MulOp::getRhsMutable() { - auto range = getODSOperandIndexAndLength(1); - return getOperation()->getOpOperand(range.first); -} - -std::pair MulOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range MulOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void MulOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value lhs, ::mlir::Value rhs) { - odsState.addOperands(lhs); - odsState.addOperands(rhs); - odsState.addTypes(resultType0); -} - -void MulOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs) { - odsState.addOperands(lhs); - odsState.addOperands(rhs); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void MulOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 2u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult MulOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*this, v.getType(), "operand", index++))) - return ::mlir::failure(); - } - auto valueGroup1 = getODSOperands(1); - - for (auto v : valueGroup1) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult MulOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -void MulOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::MulOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::PrintOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -PrintOpGenericAdaptorBase::PrintOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.print", odsAttrs.getContext()); -} - -PrintOpGenericAdaptorBase::PrintOpGenericAdaptorBase(PrintOp op) : PrintOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair PrintOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr PrintOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -PrintOpAdaptor::PrintOpAdaptor(PrintOp op) : PrintOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult PrintOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair PrintOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range PrintOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::Value PrintOp::getInput() { - return ::llvm::cast<::mlir::Value>(*getODSOperands(0).begin()); -} - -::mlir::OpOperand &PrintOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -std::pair PrintOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range PrintOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void PrintOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value input) { - odsState.addOperands(input); -} - -void PrintOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input) { - odsState.addOperands(input); - assert(resultTypes.size() == 0u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void PrintOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 1u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 0u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult PrintOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops2(*this, v.getType(), "operand", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult PrintOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -::mlir::ParseResult PrintOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::OpAsmParser::UnresolvedOperand inputRawOperands[1]; - ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> inputOperands(inputRawOperands); ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::mlir::Type inputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> inputTypes(inputRawTypes); - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperand(inputRawOperands[0])) - return ::mlir::failure(); - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.parseColon()) - return ::mlir::failure(); - - { - ::mlir::Type type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - inputRawTypes[0] = type; - } - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void PrintOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << ' '; - _odsPrinter << getInput(); - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - { - auto type = getInput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::Type>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::PrintOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ReshapeOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -ReshapeOpGenericAdaptorBase::ReshapeOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.reshape", odsAttrs.getContext()); -} - -ReshapeOpGenericAdaptorBase::ReshapeOpGenericAdaptorBase(ReshapeOp op) : ReshapeOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair ReshapeOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr ReshapeOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -ReshapeOpAdaptor::ReshapeOpAdaptor(ReshapeOp op) : ReshapeOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult ReshapeOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair ReshapeOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range ReshapeOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> ReshapeOp::getInput() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::OpOperand &ReshapeOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -std::pair ReshapeOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range ReshapeOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void ReshapeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value input) { - odsState.addOperands(input); - odsState.addTypes(resultType0); -} - -void ReshapeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input) { - odsState.addOperands(input); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void ReshapeOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 1u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult ReshapeOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops3(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult ReshapeOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -::mlir::ParseResult ReshapeOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::OpAsmParser::UnresolvedOperand inputRawOperands[1]; - ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> inputOperands(inputRawOperands); ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::mlir::Type inputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> inputTypes(inputRawTypes); - ::llvm::SmallVector<::mlir::Type, 1> allResultTypes; - if (parser.parseLParen()) - return ::mlir::failure(); - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperand(inputRawOperands[0])) - return ::mlir::failure(); - if (parser.parseColon()) - return ::mlir::failure(); - - { - ::mlir::TensorType type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - inputRawTypes[0] = type; - } - if (parser.parseRParen()) - return ::mlir::failure(); - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.parseKeyword("to")) - return ::mlir::failure(); - - if (parser.parseTypeList(allResultTypes)) - return ::mlir::failure(); - result.addTypes(allResultTypes); - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void ReshapeOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << "("; - _odsPrinter << getInput(); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - { - auto type = getInput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::TensorType>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } - _odsPrinter << ")"; - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << "to"; - _odsPrinter << ' '; - _odsPrinter << getOperation()->getResultTypes(); -} - -void ReshapeOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::ReshapeOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ReturnOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -ReturnOpGenericAdaptorBase::ReturnOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.return", odsAttrs.getContext()); -} - -ReturnOpGenericAdaptorBase::ReturnOpGenericAdaptorBase(ReturnOp op) : ReturnOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), 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}; -} - -::mlir::DictionaryAttr ReturnOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -ReturnOpAdaptor::ReturnOpAdaptor(ReturnOp op) : ReturnOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::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::Operation::operand_range ReturnOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::Operation::operand_range ReturnOp::getInput() { - return getODSOperands(0); -} - -::mlir::MutableOperandRange ReturnOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); - return mutableRange; -} - -std::pair ReturnOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range ReturnOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void ReturnOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState) { - build(odsBuilder, odsState, std::nullopt); -} - -void ReturnOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange input) { - odsState.addOperands(input); -} - -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); -} - -::mlir::LogicalResult ReturnOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops1(*this, v.getType(), "operand", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult ReturnOp::verifyInvariants() { - if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) - return ::mlir::success(); - return ::mlir::failure(); -} - -::mlir::ParseResult ReturnOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> inputOperands; - ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::llvm::SmallVector<::mlir::Type, 1> inputTypes; - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperandList(inputOperands)) - return ::mlir::failure(); - if (!inputOperands.empty()) { - if (parser.parseColon()) - return ::mlir::failure(); - - if (parser.parseTypeList(inputTypes)) - return ::mlir::failure(); - } - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void ReturnOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - if (!getInput().empty()) { - _odsPrinter << ' '; - _odsPrinter << getInput(); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - _odsPrinter << getInput().getTypes(); - } - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); -} - -void ReturnOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::ReturnOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::TransposeOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -TransposeOpGenericAdaptorBase::TransposeOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.transpose", odsAttrs.getContext()); -} - -TransposeOpGenericAdaptorBase::TransposeOpGenericAdaptorBase(TransposeOp op) : TransposeOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair TransposeOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr TransposeOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -TransposeOpAdaptor::TransposeOpAdaptor(TransposeOp op) : TransposeOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult TransposeOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair TransposeOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range TransposeOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> TransposeOp::getInput() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::OpOperand &TransposeOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -std::pair TransposeOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range TransposeOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void TransposeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value input) { - odsState.addOperands(input); - odsState.addTypes(resultType0); -} - -void TransposeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input) { - odsState.addOperands(input); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void TransposeOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 1u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult TransposeOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult TransposeOp::verifyInvariants() { - if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) - return ::mlir::success(); - return ::mlir::failure(); -} - -::mlir::ParseResult TransposeOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::OpAsmParser::UnresolvedOperand inputRawOperands[1]; - ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> inputOperands(inputRawOperands); ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::mlir::Type inputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> inputTypes(inputRawTypes); - ::llvm::SmallVector<::mlir::Type, 1> allResultTypes; - if (parser.parseLParen()) - return ::mlir::failure(); - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperand(inputRawOperands[0])) - return ::mlir::failure(); - if (parser.parseColon()) - return ::mlir::failure(); - - { - ::mlir::TensorType type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - inputRawTypes[0] = type; - } - if (parser.parseRParen()) - return ::mlir::failure(); - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.parseKeyword("to")) - return ::mlir::failure(); - - if (parser.parseTypeList(allResultTypes)) - return ::mlir::failure(); - result.addTypes(allResultTypes); - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void TransposeOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << "("; - _odsPrinter << getInput(); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - { - auto type = getInput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::TensorType>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } - _odsPrinter << ")"; - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << "to"; - _odsPrinter << ' '; - _odsPrinter << getOperation()->getResultTypes(); -} - -void TransposeOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::TransposeOp) - - -#endif // GET_OP_CLASSES - diff --git a/Ch6/include/toy/Ops.h.inc b/Ch6/include/toy/Ops.h.inc deleted file mode 100644 index a3011f8..0000000 --- a/Ch6/include/toy/Ops.h.inc +++ /dev/null @@ -1,1361 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Op Declarations *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: Ops.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -#if defined(GET_OP_CLASSES) || defined(GET_OP_FWD_DEFINES) -#undef GET_OP_FWD_DEFINES -namespace mlir { -namespace toy { -class AddOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class CastOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class ConstantOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class FuncOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class GenericCallOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class MulOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class PrintOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class ReshapeOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class ReturnOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class TransposeOp; -} // namespace toy -} // namespace mlir -#endif - -#ifdef GET_OP_CLASSES -#undef GET_OP_CLASSES - - -//===----------------------------------------------------------------------===// -// Local Utility Method Definitions -//===----------------------------------------------------------------------===// - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::AddOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class AddOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - AddOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - AddOpGenericAdaptorBase(AddOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class AddOpGenericAdaptor : public detail::AddOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::AddOpGenericAdaptorBase; -public: - AddOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - AddOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : AddOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - AddOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getLhs() { - return (*getODSOperands(0).begin()); - } - - ValueT getRhs() { - return (*getODSOperands(1).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class AddOpAdaptor : public AddOpGenericAdaptor<::mlir::ValueRange> { -public: - using AddOpGenericAdaptor::AddOpGenericAdaptor; - AddOpAdaptor(AddOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class AddOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::NOperands<2>::Impl, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait, ShapeInference::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = AddOpAdaptor; - template - using GenericAdaptor = AddOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.add"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getLhs(); - ::mlir::TypedValue<::mlir::TensorType> getRhs(); - ::mlir::OpOperand &getLhsMutable(); - ::mlir::OpOperand &getRhsMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, Value lhs, Value rhs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value lhs, ::mlir::Value rhs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &p); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - void inferShapes(); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::AddOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::CastOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class CastOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - CastOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - CastOpGenericAdaptorBase(CastOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class CastOpGenericAdaptor : public detail::CastOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::CastOpGenericAdaptorBase; -public: - CastOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - CastOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : CastOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - CastOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getInput() { - return (*getODSOperands(0).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class CastOpAdaptor : public CastOpGenericAdaptor<::mlir::ValueRange> { -public: - using CastOpGenericAdaptor::CastOpGenericAdaptor; - CastOpAdaptor(CastOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class CastOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::OneOperand, ::mlir::OpTrait::OpInvariants, ::mlir::CastOpInterface::Trait, ShapeInference::Trait, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait, ::mlir::OpTrait::SameOperandsAndResultShape> { -public: - using Op::Op; - using Op::print; - using Adaptor = CastOpAdaptor; - template - using GenericAdaptor = CastOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.cast"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getInput(); - ::mlir::OpOperand &getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getOutput(); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type output, ::mlir::Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - static bool areCastCompatible(::mlir::TypeRange inputs, ::mlir::TypeRange outputs); - void inferShapes(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::CastOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ConstantOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class ConstantOpGenericAdaptorBase { -public: - struct Properties { - using valueTy = ::mlir::DenseElementsAttr; - valueTy value; - - auto getValue() { - auto &propStorage = this->value; - return ::llvm::cast<::mlir::DenseElementsAttr>(propStorage); - } - void setValue(const ::mlir::DenseElementsAttr &propValue) { - this->value = propValue; - } - bool operator==(const Properties &rhs) const { - return - rhs.value == this->value && - true; - } - bool operator!=(const Properties &rhs) const { - return !(*this == rhs); - } - }; -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - Properties properties; - ::mlir::RegionRange odsRegions; -public: - ConstantOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}); - - ConstantOpGenericAdaptorBase(ConstantOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - const Properties &getProperties() { - return properties; - } - - ::mlir::DictionaryAttr getAttributes(); - ::mlir::DenseElementsAttr getValueAttr(); - ::mlir::DenseElementsAttr getValue(); -}; -} // namespace detail -template -class ConstantOpGenericAdaptor : public detail::ConstantOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::ConstantOpGenericAdaptorBase; -public: - ConstantOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - ConstantOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : ConstantOpGenericAdaptor(values, attrs, (properties ? *properties.as() : Properties{}), regions) {} - - template >> - ConstantOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class ConstantOpAdaptor : public ConstantOpGenericAdaptor<::mlir::ValueRange> { -public: - using ConstantOpGenericAdaptor::ConstantOpGenericAdaptor; - ConstantOpAdaptor(ConstantOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class ConstantOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::ZeroOperands, ::mlir::OpTrait::OpInvariants, ::mlir::BytecodeOpInterface::Trait, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = ConstantOpAdaptor; - template - using GenericAdaptor = ConstantOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - using Properties = FoldAdaptor::Properties; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - static ::llvm::StringRef attrNames[] = {::llvm::StringRef("value")}; - return ::llvm::ArrayRef(attrNames); - } - - ::mlir::StringAttr getValueAttrName() { - return getAttributeNameForIndex(0); - } - - static ::mlir::StringAttr getValueAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 0); - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.constant"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static ::mlir::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop); - static llvm::hash_code computePropertiesHash(const Properties &prop); - static std::optional getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name); - static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value); - static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs); - static ::mlir::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::LogicalResult readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state); - void writeProperties(::mlir::DialectBytecodeWriter &writer); - ::mlir::DenseElementsAttr getValueAttr(); - ::mlir::DenseElementsAttr getValue(); - void setValueAttr(::mlir::DenseElementsAttr attr); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, DenseElementsAttr value); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, double value); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::DenseElementsAttr value); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::DenseElementsAttr value); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &p); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - ::mlir::LogicalResult verify(); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -private: - ::mlir::StringAttr getAttributeNameForIndex(unsigned index) { - return getAttributeNameForIndex((*this)->getName(), index); - } - - static ::mlir::StringAttr getAttributeNameForIndex(::mlir::OperationName name, unsigned index) { - assert(index < 1 && "invalid attribute index"); - assert(name.getStringRef() == getOperationName() && "invalid operation name"); - assert(name.isRegistered() && "Operation isn't registered, missing a " - "dependent dialect loading?"); - return name.getAttributeNames()[index]; - } - -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::ConstantOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::FuncOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class FuncOpGenericAdaptorBase { -public: - struct Properties { - using arg_attrsTy = ::mlir::ArrayAttr; - arg_attrsTy arg_attrs; - - auto getArgAttrs() { - auto &propStorage = this->arg_attrs; - return ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(propStorage); - } - void setArgAttrs(const ::mlir::ArrayAttr &propValue) { - this->arg_attrs = propValue; - } - using function_typeTy = ::mlir::TypeAttr; - function_typeTy function_type; - - auto getFunctionType() { - auto &propStorage = this->function_type; - return ::llvm::cast<::mlir::TypeAttr>(propStorage); - } - void setFunctionType(const ::mlir::TypeAttr &propValue) { - this->function_type = propValue; - } - using res_attrsTy = ::mlir::ArrayAttr; - res_attrsTy res_attrs; - - auto getResAttrs() { - auto &propStorage = this->res_attrs; - return ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(propStorage); - } - void setResAttrs(const ::mlir::ArrayAttr &propValue) { - this->res_attrs = propValue; - } - using sym_nameTy = ::mlir::StringAttr; - sym_nameTy sym_name; - - auto getSymName() { - auto &propStorage = this->sym_name; - return ::llvm::cast<::mlir::StringAttr>(propStorage); - } - void setSymName(const ::mlir::StringAttr &propValue) { - this->sym_name = propValue; - } - bool operator==(const Properties &rhs) const { - return - rhs.arg_attrs == this->arg_attrs && - rhs.function_type == this->function_type && - rhs.res_attrs == this->res_attrs && - rhs.sym_name == this->sym_name && - true; - } - bool operator!=(const Properties &rhs) const { - return !(*this == rhs); - } - }; -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - Properties properties; - ::mlir::RegionRange odsRegions; -public: - FuncOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}); - - FuncOpGenericAdaptorBase(FuncOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - const Properties &getProperties() { - return properties; - } - - ::mlir::DictionaryAttr getAttributes(); - ::mlir::StringAttr getSymNameAttr(); - ::llvm::StringRef getSymName(); - ::mlir::TypeAttr getFunctionTypeAttr(); - ::mlir::FunctionType getFunctionType(); - ::mlir::ArrayAttr getArgAttrsAttr(); - ::std::optional< ::mlir::ArrayAttr > getArgAttrs(); - ::mlir::ArrayAttr getResAttrsAttr(); - ::std::optional< ::mlir::ArrayAttr > getResAttrs(); - ::mlir::Region &getBody(); - ::mlir::RegionRange getRegions(); -}; -} // namespace detail -template -class FuncOpGenericAdaptor : public detail::FuncOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::FuncOpGenericAdaptorBase; -public: - FuncOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - FuncOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : FuncOpGenericAdaptor(values, attrs, (properties ? *properties.as() : Properties{}), regions) {} - - template >> - FuncOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class FuncOpAdaptor : public FuncOpGenericAdaptor<::mlir::ValueRange> { -public: - using FuncOpGenericAdaptor::FuncOpGenericAdaptor; - FuncOpAdaptor(FuncOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class FuncOp : public ::mlir::Op { -public: - using Op::Op; - using Op::print; - using Adaptor = FuncOpAdaptor; - template - using GenericAdaptor = FuncOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - using Properties = FoldAdaptor::Properties; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - static ::llvm::StringRef attrNames[] = {::llvm::StringRef("arg_attrs"), ::llvm::StringRef("function_type"), ::llvm::StringRef("res_attrs"), ::llvm::StringRef("sym_name")}; - return ::llvm::ArrayRef(attrNames); - } - - ::mlir::StringAttr getArgAttrsAttrName() { - return getAttributeNameForIndex(0); - } - - static ::mlir::StringAttr getArgAttrsAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 0); - } - - ::mlir::StringAttr getFunctionTypeAttrName() { - return getAttributeNameForIndex(1); - } - - static ::mlir::StringAttr getFunctionTypeAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 1); - } - - ::mlir::StringAttr getResAttrsAttrName() { - return getAttributeNameForIndex(2); - } - - static ::mlir::StringAttr getResAttrsAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 2); - } - - ::mlir::StringAttr getSymNameAttrName() { - return getAttributeNameForIndex(3); - } - - static ::mlir::StringAttr getSymNameAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 3); - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.func"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - ::mlir::Region &getBody(); - static ::mlir::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop); - static llvm::hash_code computePropertiesHash(const Properties &prop); - static std::optional getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name); - static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value); - static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs); - static ::mlir::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::LogicalResult readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state); - void writeProperties(::mlir::DialectBytecodeWriter &writer); - ::mlir::StringAttr getSymNameAttr(); - ::llvm::StringRef getSymName(); - ::mlir::TypeAttr getFunctionTypeAttr(); - ::mlir::FunctionType getFunctionType(); - ::mlir::ArrayAttr getArgAttrsAttr(); - ::std::optional< ::mlir::ArrayAttr > getArgAttrs(); - ::mlir::ArrayAttr getResAttrsAttr(); - ::std::optional< ::mlir::ArrayAttr > getResAttrs(); - void setSymNameAttr(::mlir::StringAttr attr); - void setSymName(::llvm::StringRef attrValue); - void setFunctionTypeAttr(::mlir::TypeAttr attr); - void setFunctionType(::mlir::FunctionType attrValue); - void setArgAttrsAttr(::mlir::ArrayAttr attr); - void setResAttrsAttr(::mlir::ArrayAttr attr); - ::mlir::Attribute removeArgAttrsAttr(); - ::mlir::Attribute removeResAttrsAttr(); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, StringRef name, FunctionType type, ArrayRef attrs = {}); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &p); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); -private: - ::mlir::StringAttr getAttributeNameForIndex(unsigned index) { - return getAttributeNameForIndex((*this)->getName(), index); - } - - static ::mlir::StringAttr getAttributeNameForIndex(::mlir::OperationName name, unsigned index) { - assert(index < 4 && "invalid attribute index"); - assert(name.getStringRef() == getOperationName() && "invalid operation name"); - assert(name.isRegistered() && "Operation isn't registered, missing a " - "dependent dialect loading?"); - return name.getAttributeNames()[index]; - } - -public: - //===------------------------------------------------------------------===// - // FunctionOpInterface Methods - //===------------------------------------------------------------------===// - - /// Returns the argument types of this function. - ArrayRef getArgumentTypes() { return getFunctionType().getInputs(); } - - /// Returns the result types of this function. - ArrayRef getResultTypes() { return getFunctionType().getResults(); } - - /// Returns the region on the function operation that is callable. - Region *getCallableRegion() { return &getBody(); } -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::FuncOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::GenericCallOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class GenericCallOpGenericAdaptorBase { -public: - struct Properties { - using calleeTy = ::mlir::FlatSymbolRefAttr; - calleeTy callee; - - auto getCallee() { - auto &propStorage = this->callee; - return ::llvm::cast<::mlir::FlatSymbolRefAttr>(propStorage); - } - void setCallee(const ::mlir::FlatSymbolRefAttr &propValue) { - this->callee = propValue; - } - bool operator==(const Properties &rhs) const { - return - rhs.callee == this->callee && - true; - } - bool operator!=(const Properties &rhs) const { - return !(*this == rhs); - } - }; -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - Properties properties; - ::mlir::RegionRange odsRegions; -public: - GenericCallOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}); - - GenericCallOpGenericAdaptorBase(GenericCallOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - const Properties &getProperties() { - return properties; - } - - ::mlir::DictionaryAttr getAttributes(); - ::mlir::FlatSymbolRefAttr getCalleeAttr(); - ::llvm::StringRef getCallee(); -}; -} // namespace detail -template -class GenericCallOpGenericAdaptor : public detail::GenericCallOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::GenericCallOpGenericAdaptorBase; -public: - GenericCallOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - GenericCallOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : GenericCallOpGenericAdaptor(values, attrs, (properties ? *properties.as() : Properties{}), regions) {} - - template >> - GenericCallOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - RangeT getInputs() { - return getODSOperands(0); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class GenericCallOpAdaptor : public GenericCallOpGenericAdaptor<::mlir::ValueRange> { -public: - using GenericCallOpGenericAdaptor::GenericCallOpGenericAdaptor; - GenericCallOpAdaptor(GenericCallOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class GenericCallOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::VariadicOperands, ::mlir::OpTrait::OpInvariants, ::mlir::BytecodeOpInterface::Trait, ::mlir::CallOpInterface::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = GenericCallOpAdaptor; - template - using GenericAdaptor = GenericCallOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - using Properties = FoldAdaptor::Properties; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - static ::llvm::StringRef attrNames[] = {::llvm::StringRef("callee")}; - return ::llvm::ArrayRef(attrNames); - } - - ::mlir::StringAttr getCalleeAttrName() { - return getAttributeNameForIndex(0); - } - - static ::mlir::StringAttr getCalleeAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 0); - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.generic_call"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::Operation::operand_range getInputs(); - ::mlir::MutableOperandRange getInputsMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static ::mlir::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop); - static llvm::hash_code computePropertiesHash(const Properties &prop); - static std::optional getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name); - static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value); - static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs); - static ::mlir::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::LogicalResult readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state); - void writeProperties(::mlir::DialectBytecodeWriter &writer); - ::mlir::FlatSymbolRefAttr getCalleeAttr(); - ::llvm::StringRef getCallee(); - void setCalleeAttr(::mlir::FlatSymbolRefAttr attr); - void setCallee(::llvm::StringRef attrValue); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, StringRef callee, ArrayRef arguments); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::FlatSymbolRefAttr callee, ::mlir::ValueRange inputs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::FlatSymbolRefAttr callee, ::mlir::ValueRange inputs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::llvm::StringRef callee, ::mlir::ValueRange inputs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::llvm::StringRef callee, ::mlir::ValueRange inputs); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - ::mlir::CallInterfaceCallable getCallableForCallee(); - void setCalleeFromCallable(::mlir::CallInterfaceCallable callee); - ::mlir::Operation::operand_range getArgOperands(); - ::mlir::MutableOperandRange getArgOperandsMutable(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); -private: - ::mlir::StringAttr getAttributeNameForIndex(unsigned index) { - return getAttributeNameForIndex((*this)->getName(), index); - } - - static ::mlir::StringAttr getAttributeNameForIndex(::mlir::OperationName name, unsigned index) { - assert(index < 1 && "invalid attribute index"); - assert(name.getStringRef() == getOperationName() && "invalid operation name"); - assert(name.isRegistered() && "Operation isn't registered, missing a " - "dependent dialect loading?"); - return name.getAttributeNames()[index]; - } - -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::GenericCallOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::MulOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class MulOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - MulOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - MulOpGenericAdaptorBase(MulOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class MulOpGenericAdaptor : public detail::MulOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::MulOpGenericAdaptorBase; -public: - MulOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - MulOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : MulOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - MulOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getLhs() { - return (*getODSOperands(0).begin()); - } - - ValueT getRhs() { - return (*getODSOperands(1).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class MulOpAdaptor : public MulOpGenericAdaptor<::mlir::ValueRange> { -public: - using MulOpGenericAdaptor::MulOpGenericAdaptor; - MulOpAdaptor(MulOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class MulOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::NOperands<2>::Impl, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait, ShapeInference::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = MulOpAdaptor; - template - using GenericAdaptor = MulOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.mul"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getLhs(); - ::mlir::TypedValue<::mlir::TensorType> getRhs(); - ::mlir::OpOperand &getLhsMutable(); - ::mlir::OpOperand &getRhsMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, Value lhs, Value rhs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value lhs, ::mlir::Value rhs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &p); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - void inferShapes(); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::MulOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::PrintOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class PrintOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - PrintOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - PrintOpGenericAdaptorBase(PrintOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class PrintOpGenericAdaptor : public detail::PrintOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::PrintOpGenericAdaptorBase; -public: - PrintOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - PrintOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : PrintOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - PrintOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getInput() { - return (*getODSOperands(0).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class PrintOpAdaptor : public PrintOpGenericAdaptor<::mlir::ValueRange> { -public: - using PrintOpGenericAdaptor::PrintOpGenericAdaptor; - PrintOpAdaptor(PrintOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class PrintOp : public ::mlir::Op { -public: - using Op::Op; - using Op::print; - using Adaptor = PrintOpAdaptor; - template - using GenericAdaptor = PrintOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.print"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::Value getInput(); - ::mlir::OpOperand &getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::PrintOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ReshapeOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class ReshapeOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - ReshapeOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - ReshapeOpGenericAdaptorBase(ReshapeOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class ReshapeOpGenericAdaptor : public detail::ReshapeOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::ReshapeOpGenericAdaptorBase; -public: - ReshapeOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - ReshapeOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : ReshapeOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - ReshapeOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getInput() { - return (*getODSOperands(0).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class ReshapeOpAdaptor : public ReshapeOpGenericAdaptor<::mlir::ValueRange> { -public: - using ReshapeOpGenericAdaptor::ReshapeOpGenericAdaptor; - ReshapeOpAdaptor(ReshapeOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class ReshapeOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::OneOperand, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = ReshapeOpAdaptor; - template - using GenericAdaptor = ReshapeOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.reshape"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getInput(); - ::mlir::OpOperand &getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - static void getCanonicalizationPatterns(::mlir::RewritePatternSet &results, ::mlir::MLIRContext *context); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::ReshapeOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ReturnOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class ReturnOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - ReturnOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - ReturnOpGenericAdaptorBase(ReturnOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class ReturnOpGenericAdaptor : public detail::ReturnOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::ReturnOpGenericAdaptorBase; -public: - ReturnOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - ReturnOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : ReturnOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - ReturnOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - RangeT getInput() { - return getODSOperands(0); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class ReturnOpAdaptor : public ReturnOpGenericAdaptor<::mlir::ValueRange> { -public: - using ReturnOpGenericAdaptor::ReturnOpGenericAdaptor; - ReturnOpAdaptor(ReturnOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class ReturnOp : public ::mlir::Op::Impl, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait, ::mlir::OpTrait::IsTerminator> { -public: - using Op::Op; - using Op::print; - using Adaptor = ReturnOpAdaptor; - template - using GenericAdaptor = ReturnOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.return"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::Operation::operand_range getInput(); - ::mlir::MutableOperandRange getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - ::mlir::LogicalResult verify(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: - bool hasOperand() { return getNumOperands() != 0; } -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::ReturnOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::TransposeOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class TransposeOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - TransposeOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - TransposeOpGenericAdaptorBase(TransposeOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class TransposeOpGenericAdaptor : public detail::TransposeOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::TransposeOpGenericAdaptorBase; -public: - TransposeOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - TransposeOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : TransposeOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - TransposeOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getInput() { - return (*getODSOperands(0).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class TransposeOpAdaptor : public TransposeOpGenericAdaptor<::mlir::ValueRange> { -public: - using TransposeOpGenericAdaptor::TransposeOpGenericAdaptor; - TransposeOpAdaptor(TransposeOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class TransposeOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::OneOperand, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait, ShapeInference::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = TransposeOpAdaptor; - template - using GenericAdaptor = TransposeOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.transpose"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getInput(); - ::mlir::OpOperand &getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - ::mlir::LogicalResult verify(); - static void getCanonicalizationPatterns(::mlir::RewritePatternSet &results, ::mlir::MLIRContext *context); - void inferShapes(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::TransposeOp) - - -#endif // GET_OP_CLASSES - diff --git a/Ch6/include/toy/ShapeInferenceOpInterfaces.cpp.inc b/Ch6/include/toy/ShapeInferenceOpInterfaces.cpp.inc deleted file mode 100644 index a481d2e..0000000 --- a/Ch6/include/toy/ShapeInferenceOpInterfaces.cpp.inc +++ /dev/null @@ -1,12 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Interface Definitions *| -|* *| -|* Automatically generated file, do not edit! *| -|* *| -\*===----------------------------------------------------------------------===*/ - -/// Infer and set the output shape for the current operation. -void ShapeInference::inferShapes() { - return getImpl()->inferShapes(getImpl(), getOperation()); - } diff --git a/Ch6/include/toy/ShapeInferenceOpInterfaces.h.inc b/Ch6/include/toy/ShapeInferenceOpInterfaces.h.inc deleted file mode 100644 index bb24654..0000000 --- a/Ch6/include/toy/ShapeInferenceOpInterfaces.h.inc +++ /dev/null @@ -1,61 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Interface Declarations *| -|* *| -|* Automatically generated file, do not edit! *| -|* *| -\*===----------------------------------------------------------------------===*/ - -class ShapeInference; -namespace detail { -struct ShapeInferenceInterfaceTraits { - struct Concept { - /// The methods defined by the interface. - void (*inferShapes)(const Concept *impl, ::mlir::Operation *); - }; - template - class Model : public Concept { - public: - using Interface = ShapeInference; - Model() : Concept{inferShapes} {} - - static inline void inferShapes(const Concept *impl, ::mlir::Operation *tablegen_opaque_val); - }; - template - class FallbackModel : public Concept { - public: - using Interface = ShapeInference; - FallbackModel() : Concept{inferShapes} {} - - static inline void inferShapes(const Concept *impl, ::mlir::Operation *tablegen_opaque_val); - }; - template - class ExternalModel : public FallbackModel { - public: - using ConcreteEntity = ConcreteOp; - }; -};template -struct ShapeInferenceTrait; - -} // namespace detail -class ShapeInference : public ::mlir::OpInterface { -public: - using ::mlir::OpInterface::OpInterface; - template - struct Trait : public detail::ShapeInferenceTrait {}; - /// Infer and set the output shape for the current operation. - void inferShapes(); -}; -namespace detail { - template - struct ShapeInferenceTrait : public ::mlir::OpInterface::Trait { - }; -}// namespace detail -template -void detail::ShapeInferenceInterfaceTraits::Model::inferShapes(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) { - return (llvm::cast(tablegen_opaque_val)).inferShapes(); -} -template -void detail::ShapeInferenceInterfaceTraits::FallbackModel::inferShapes(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) { - return static_cast(impl)->inferShapes(tablegen_opaque_val); -} diff --git a/Ch6/mlir/ToyCombine.inc b/Ch6/mlir/ToyCombine.inc deleted file mode 100644 index 61c6203..0000000 --- a/Ch6/mlir/ToyCombine.inc +++ /dev/null @@ -1,176 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Rewriters *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: ToyCombine.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -/* Generated from: - ToyCombine.td:46 -*/ -struct FoldConstantReshapeOptPattern : public ::mlir::RewritePattern { - FoldConstantReshapeOptPattern(::mlir::MLIRContext *context) - : ::mlir::RewritePattern("toy.reshape", 2, context, {"toy.constant"}) {} - ::mlir::LogicalResult matchAndRewrite(::mlir::Operation *op0, - ::mlir::PatternRewriter &rewriter) const override { - // Variables for capturing values and attributes used while creating ops - ::mlir::DenseElementsAttr arg; - ::mlir::toy::ReshapeOp res; - ::llvm::SmallVector<::mlir::Operation *, 4> tblgen_ops; - - // Match - tblgen_ops.push_back(op0); - auto castedOp0 = ::llvm::dyn_cast<::mlir::toy::ReshapeOp>(op0); (void)castedOp0; - res = castedOp0; - { - auto *op1 = (*castedOp0.getODSOperands(0).begin()).getDefiningOp(); - if (!(op1)){ - return rewriter.notifyMatchFailure(castedOp0, [&](::mlir::Diagnostic &diag) { - diag << "There's no operation that defines operand 0 of castedOp0"; - }); - } - auto castedOp1 = ::llvm::dyn_cast<::mlir::toy::ConstantOp>(op1); (void)castedOp1; - if (!(castedOp1)){ - return rewriter.notifyMatchFailure(op1, [&](::mlir::Diagnostic &diag) { - diag << "castedOp1 is not ::mlir::toy::ConstantOp type"; - }); - } - { - auto tblgen_attr = op1->getAttrOfType<::mlir::DenseElementsAttr>("value");(void)tblgen_attr; - if (!(tblgen_attr)){ - return rewriter.notifyMatchFailure(op1, [&](::mlir::Diagnostic &diag) { - diag << "expected op 'toy.constant' to have attribute 'value' of type '::mlir::DenseElementsAttr'"; - }); - } - arg = tblgen_attr; - } - tblgen_ops.push_back(op1); - } - - // Rewrite - auto odsLoc = rewriter.getFusedLoc({tblgen_ops[0]->getLoc(), tblgen_ops[1]->getLoc()}); (void)odsLoc; - ::llvm::SmallVector<::mlir::Value, 4> tblgen_repl_values; - auto nativeVar_0 = arg.reshape(::llvm::cast((*res.getODSResults(0).begin()).getType())); (void)nativeVar_0; - ::mlir::toy::ConstantOp tblgen_ConstantOp_1; - { - ::llvm::SmallVector<::mlir::Value, 4> tblgen_values; (void)tblgen_values; - ::llvm::SmallVector<::mlir::NamedAttribute, 4> tblgen_attrs; (void)tblgen_attrs; - if (auto tmpAttr = nativeVar_0) { - tblgen_attrs.emplace_back(rewriter.getStringAttr("value"), tmpAttr); - } - ::llvm::SmallVector<::mlir::Type, 4> tblgen_types; (void)tblgen_types; - for (auto v: castedOp0.getODSResults(0)) { - tblgen_types.push_back(v.getType()); - } - tblgen_ConstantOp_1 = rewriter.create<::mlir::toy::ConstantOp>(odsLoc, tblgen_types, tblgen_values, tblgen_attrs); - } - - for (auto v: ::llvm::SmallVector<::mlir::Value, 4>{ tblgen_ConstantOp_1.getODSResults(0) }) { - tblgen_repl_values.push_back(v); - } - - rewriter.replaceOp(op0, tblgen_repl_values); - return ::mlir::success(); - }; -}; - -/* Generated from: - ToyCombine.td:59 -*/ -struct RedundantReshapeOptPattern : public ::mlir::RewritePattern { - RedundantReshapeOptPattern(::mlir::MLIRContext *context) - : ::mlir::RewritePattern("toy.reshape", 1, context, {}) {} - ::mlir::LogicalResult matchAndRewrite(::mlir::Operation *op0, - ::mlir::PatternRewriter &rewriter) const override { - // Variables for capturing values and attributes used while creating ops - ::mlir::Operation::operand_range arg(op0->getOperands()); - ::mlir::toy::ReshapeOp res; - ::llvm::SmallVector<::mlir::Operation *, 4> tblgen_ops; - - // Match - tblgen_ops.push_back(op0); - auto castedOp0 = ::llvm::dyn_cast<::mlir::toy::ReshapeOp>(op0); (void)castedOp0; - res = castedOp0; - arg = castedOp0.getODSOperands(0); - if (!(((*res.getODSResults(0).begin()).getType() == (*arg.begin()).getType()))){ - return rewriter.notifyMatchFailure(op0, [&](::mlir::Diagnostic &diag) { - diag << "entities 'res, arg' failed to satisfy constraint: ''"; - }); - } - - // Rewrite - auto odsLoc = rewriter.getFusedLoc({tblgen_ops[0]->getLoc()}); (void)odsLoc; - ::llvm::SmallVector<::mlir::Value, 4> tblgen_repl_values; - - for (auto v: ::llvm::SmallVector<::mlir::Value, 4>{ arg }) { - tblgen_repl_values.push_back(v); - } - - rewriter.replaceOp(op0, tblgen_repl_values); - return ::mlir::success(); - }; -}; - -/* Generated from: - ToyCombine.td:33 -*/ -struct ReshapeReshapeOptPattern : public ::mlir::RewritePattern { - ReshapeReshapeOptPattern(::mlir::MLIRContext *context) - : ::mlir::RewritePattern("toy.reshape", 2, context, {"toy.reshape"}) {} - ::mlir::LogicalResult matchAndRewrite(::mlir::Operation *op0, - ::mlir::PatternRewriter &rewriter) const override { - // Variables for capturing values and attributes used while creating ops - ::mlir::Operation::operand_range arg(op0->getOperands()); - ::llvm::SmallVector<::mlir::Operation *, 4> tblgen_ops; - - // Match - tblgen_ops.push_back(op0); - auto castedOp0 = ::llvm::dyn_cast<::mlir::toy::ReshapeOp>(op0); (void)castedOp0; - { - auto *op1 = (*castedOp0.getODSOperands(0).begin()).getDefiningOp(); - if (!(op1)){ - return rewriter.notifyMatchFailure(castedOp0, [&](::mlir::Diagnostic &diag) { - diag << "There's no operation that defines operand 0 of castedOp0"; - }); - } - auto castedOp1 = ::llvm::dyn_cast<::mlir::toy::ReshapeOp>(op1); (void)castedOp1; - if (!(castedOp1)){ - return rewriter.notifyMatchFailure(op1, [&](::mlir::Diagnostic &diag) { - diag << "castedOp1 is not ::mlir::toy::ReshapeOp type"; - }); - } - arg = castedOp1.getODSOperands(0); - tblgen_ops.push_back(op1); - } - - // Rewrite - auto odsLoc = rewriter.getFusedLoc({tblgen_ops[0]->getLoc(), tblgen_ops[1]->getLoc()}); (void)odsLoc; - ::llvm::SmallVector<::mlir::Value, 4> tblgen_repl_values; - ::mlir::toy::ReshapeOp tblgen_ReshapeOp_0; - { - ::llvm::SmallVector<::mlir::Value, 4> tblgen_values; (void)tblgen_values; - ::llvm::SmallVector<::mlir::NamedAttribute, 4> tblgen_attrs; (void)tblgen_attrs; - tblgen_values.push_back((*arg.begin())); - ::llvm::SmallVector<::mlir::Type, 4> tblgen_types; (void)tblgen_types; - for (auto v: castedOp0.getODSResults(0)) { - tblgen_types.push_back(v.getType()); - } - tblgen_ReshapeOp_0 = rewriter.create<::mlir::toy::ReshapeOp>(odsLoc, tblgen_types, tblgen_values, tblgen_attrs); - } - - for (auto v: ::llvm::SmallVector<::mlir::Value, 4>{ tblgen_ReshapeOp_0.getODSResults(0) }) { - tblgen_repl_values.push_back(v); - } - - rewriter.replaceOp(op0, tblgen_repl_values); - return ::mlir::success(); - }; -}; - -void LLVM_ATTRIBUTE_UNUSED populateWithGenerated(::mlir::RewritePatternSet &patterns) { - patterns.add(patterns.getContext()); - patterns.add(patterns.getContext()); - patterns.add(patterns.getContext()); -} diff --git a/Ch6/mlir/run.sh b/Ch6/mlir/run.sh deleted file mode 100644 index f592fde..0000000 --- a/Ch6/mlir/run.sh +++ /dev/null @@ -1,2 +0,0 @@ -mlir-tblgen-18 -gen-rewriters -I /usr/lib/llvm-18/include -I ../include ToyCombine.td > ToyCombine.inc - diff --git a/Ch7/CMakeLists.txt b/Ch7/CMakeLists.txt index 360b554..362ab51 100644 --- a/Ch7/CMakeLists.txt +++ b/Ch7/CMakeLists.txt @@ -14,11 +14,11 @@ set(LLVM_LINK_COMPONENTS OrcJIT ) -# set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td) -# mlir_tablegen(ToyCombine.inc -gen-rewriters) -# add_public_tablegen_target(ToyCh7CombineIncGen) +set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td) +mlir_tablegen(ToyCombine.inc -gen-rewriters) +add_public_tablegen_target(ToyCh7CombineIncGen) -add_executable(toyc-ch7 +add_toy_chapter(toyc-ch7 toyc.cpp parser/AST.cpp mlir/MLIRGen.cpp @@ -28,10 +28,10 @@ add_executable(toyc-ch7 mlir/ShapeInferencePass.cpp mlir/ToyCombine.cpp - # DEPENDS - # ToyCh7ShapeInferenceInterfaceIncGen - # ToyCh7OpsIncGen - # ToyCh7CombineIncGen + DEPENDS + ToyCh7ShapeInferenceInterfaceIncGen + ToyCh7OpsIncGen + ToyCh7CombineIncGen ) include_directories(${CMAKE_CURRENT_BINARY_DIR}) diff --git a/Ch7/include/run.sh b/Ch7/include/run.sh deleted file mode 100644 index b9d18af..0000000 --- a/Ch7/include/run.sh +++ /dev/null @@ -1,7 +0,0 @@ -mlir-tblgen-18 -gen-op-decls -I /usr/lib/llvm-18/include toy/Ops.td > toy/Ops.h.inc -mlir-tblgen-18 -gen-op-defs -I /usr/lib/llvm-18/include toy/Ops.td > toy/Ops.cpp.inc -mlir-tblgen-18 -gen-dialect-decls -I /usr/lib/llvm-18/include toy/Ops.td > toy/Dialect.h.inc -mlir-tblgen-18 -gen-dialect-defs -I /usr/lib/llvm-18/include toy/Ops.td > toy/Dialect.cpp.inc - -mlir-tblgen-18 -gen-op-interface-decls -I /usr/lib/llvm-18/include toy/ShapeInferenceInterface.td > toy/ShapeInferenceOpInterfaces.h.inc -mlir-tblgen-18 -gen-op-interface-defs -I /usr/lib/llvm-18/include toy/ShapeInferenceInterface.td > toy/ShapeInferenceOpInterfaces.cpp.inc diff --git a/Ch7/include/toy/CMakeLists.txt b/Ch7/include/toy/CMakeLists.txt index 5ff56e8..7712e42 100644 --- a/Ch7/include/toy/CMakeLists.txt +++ b/Ch7/include/toy/CMakeLists.txt @@ -1,13 +1,13 @@ -# # Most dialects should use add_mlir_dialect(). See examples/standalone. -# set(LLVM_TARGET_DEFINITIONS Ops.td) -# mlir_tablegen(Ops.h.inc -gen-op-decls) -# mlir_tablegen(Ops.cpp.inc -gen-op-defs) -# mlir_tablegen(Dialect.h.inc -gen-dialect-decls) -# mlir_tablegen(Dialect.cpp.inc -gen-dialect-defs) -# add_public_tablegen_target(ToyCh7OpsIncGen) +# Most dialects should use add_mlir_dialect(). See examples/standalone. +set(LLVM_TARGET_DEFINITIONS Ops.td) +mlir_tablegen(Ops.h.inc -gen-op-decls) +mlir_tablegen(Ops.cpp.inc -gen-op-defs) +mlir_tablegen(Dialect.h.inc -gen-dialect-decls) +mlir_tablegen(Dialect.cpp.inc -gen-dialect-defs) +add_public_tablegen_target(ToyCh7OpsIncGen) -# # Most dialects should use add_mlir_interfaces(). -# set(LLVM_TARGET_DEFINITIONS ShapeInferenceInterface.td) -# mlir_tablegen(ShapeInferenceOpInterfaces.h.inc -gen-op-interface-decls) -# mlir_tablegen(ShapeInferenceOpInterfaces.cpp.inc -gen-op-interface-defs) -# add_public_tablegen_target(ToyCh7ShapeInferenceInterfaceIncGen) +# Most dialects should use add_mlir_interfaces(). +set(LLVM_TARGET_DEFINITIONS ShapeInferenceInterface.td) +mlir_tablegen(ShapeInferenceOpInterfaces.h.inc -gen-op-interface-decls) +mlir_tablegen(ShapeInferenceOpInterfaces.cpp.inc -gen-op-interface-defs) +add_public_tablegen_target(ToyCh7ShapeInferenceInterfaceIncGen) diff --git a/Ch7/include/toy/Dialect.cpp.inc b/Ch7/include/toy/Dialect.cpp.inc deleted file mode 100644 index 8cbc772..0000000 --- a/Ch7/include/toy/Dialect.cpp.inc +++ /dev/null @@ -1,23 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Dialect Definitions *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: Ops.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::ToyDialect) -namespace mlir { -namespace toy { - -ToyDialect::ToyDialect(::mlir::MLIRContext *context) - : ::mlir::Dialect(getDialectNamespace(), context, ::mlir::TypeID::get()) { - - initialize(); -} - -ToyDialect::~ToyDialect() = default; - -} // namespace toy -} // namespace mlir diff --git a/Ch7/include/toy/Dialect.h.inc b/Ch7/include/toy/Dialect.h.inc deleted file mode 100644 index 44dfbd5..0000000 --- a/Ch7/include/toy/Dialect.h.inc +++ /dev/null @@ -1,40 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Dialect Declarations *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: Ops.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -namespace mlir { -namespace toy { - -class ToyDialect : public ::mlir::Dialect { - explicit ToyDialect(::mlir::MLIRContext *context); - - void initialize(); - friend class ::mlir::MLIRContext; -public: - ~ToyDialect() override; - static constexpr ::llvm::StringLiteral getDialectNamespace() { - return ::llvm::StringLiteral("toy"); - } - - /// Parse a type registered to this dialect. - ::mlir::Type parseType(::mlir::DialectAsmParser &parser) const override; - - /// Print a type registered to this dialect. - void printType(::mlir::Type type, - ::mlir::DialectAsmPrinter &os) const override; - - /// Materialize a single constant operation from a given attribute value with - /// the desired resultant type. - ::mlir::Operation *materializeConstant(::mlir::OpBuilder &builder, - ::mlir::Attribute value, - ::mlir::Type type, - ::mlir::Location loc) override; -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::ToyDialect) diff --git a/Ch7/include/toy/Ops.cpp.inc b/Ch7/include/toy/Ops.cpp.inc deleted file mode 100644 index f7af5e9..0000000 --- a/Ch7/include/toy/Ops.cpp.inc +++ /dev/null @@ -1,2907 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Op Definitions *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: Ops.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -#ifdef GET_OP_LIST -#undef GET_OP_LIST - -::mlir::toy::AddOp, -::mlir::toy::CastOp, -::mlir::toy::ConstantOp, -::mlir::toy::FuncOp, -::mlir::toy::GenericCallOp, -::mlir::toy::MulOp, -::mlir::toy::PrintOp, -::mlir::toy::ReshapeOp, -::mlir::toy::ReturnOp, -::mlir::toy::StructAccessOp, -::mlir::toy::StructConstantOp, -::mlir::toy::TransposeOp -#endif // GET_OP_LIST - -#ifdef GET_OP_CLASSES -#undef GET_OP_CLASSES - - -//===----------------------------------------------------------------------===// -// Local Utility Method Definitions -//===----------------------------------------------------------------------===// - -namespace mlir { -namespace toy { - -static ::mlir::LogicalResult __mlir_ods_local_type_constraint_Ops0( - ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, - unsigned valueIndex) { - if (!(((::llvm::isa<::mlir::TensorType>(type))) && ([](::mlir::Type elementType) { return (elementType.isF64()); }(::llvm::cast<::mlir::ShapedType>(type).getElementType())))) { - return op->emitOpError(valueKind) << " #" << valueIndex - << " must be tensor of 64-bit float values, but got " << type; - } - return ::mlir::success(); -} - -static ::mlir::LogicalResult __mlir_ods_local_type_constraint_Ops1( - ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, - unsigned valueIndex) { - if (!((((::llvm::isa<::mlir::TensorType>(type))) && ([](::mlir::Type elementType) { return (elementType.isF64()); }(::llvm::cast<::mlir::ShapedType>(type).getElementType()))) || ((::llvm::isa(type))))) { - return op->emitOpError(valueKind) << " #" << valueIndex - << " must be variadic of tensor of 64-bit float values or Toy struct type, but got " << type; - } - return ::mlir::success(); -} - -static ::mlir::LogicalResult __mlir_ods_local_type_constraint_Ops2( - ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, - unsigned valueIndex) { - if (!((((::llvm::isa<::mlir::TensorType>(type))) && ([](::mlir::Type elementType) { return (elementType.isF64()); }(::llvm::cast<::mlir::ShapedType>(type).getElementType()))) || ((::llvm::isa(type))))) { - return op->emitOpError(valueKind) << " #" << valueIndex - << " must be tensor of 64-bit float values or Toy struct type, but got " << type; - } - return ::mlir::success(); -} - -static ::mlir::LogicalResult __mlir_ods_local_type_constraint_Ops3( - ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, - unsigned valueIndex) { - if (!((((::llvm::isa<::mlir::TensorType>(type))) && ([](::mlir::Type elementType) { return (elementType.isF64()); }(::llvm::cast<::mlir::ShapedType>(type).getElementType()))) || (((::llvm::isa<::mlir::MemRefType>(type))) && ([](::mlir::Type elementType) { return (elementType.isF64()); }(::llvm::cast<::mlir::ShapedType>(type).getElementType()))))) { - return op->emitOpError(valueKind) << " #" << valueIndex - << " must be tensor of 64-bit float values or memref of 64-bit float values, but got " << type; - } - return ::mlir::success(); -} - -static ::mlir::LogicalResult __mlir_ods_local_type_constraint_Ops4( - ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, - unsigned valueIndex) { - if (!((((::llvm::isa<::mlir::RankedTensorType>(type))) && ((::llvm::cast<::mlir::ShapedType>(type).hasStaticShape()))) && ([](::mlir::Type elementType) { return (elementType.isF64()); }(::llvm::cast<::mlir::ShapedType>(type).getElementType())))) { - return op->emitOpError(valueKind) << " #" << valueIndex - << " must be statically shaped tensor of 64-bit float values, but got " << type; - } - return ::mlir::success(); -} - -static ::mlir::LogicalResult __mlir_ods_local_type_constraint_Ops5( - ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, - unsigned valueIndex) { - if (!((::llvm::isa(type)))) { - return op->emitOpError(valueKind) << " #" << valueIndex - << " must be Toy struct type, but got " << type; - } - return ::mlir::success(); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops0( - ::mlir::Attribute attr, ::llvm::StringRef attrName, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { - if (attr && !((::llvm::isa<::mlir::DenseFPElementsAttr>(attr) &&::llvm::cast<::mlir::DenseElementsAttr>(attr).getType().getElementType().isF64()))) - return emitError() << "attribute '" << attrName - << "' failed to satisfy constraint: 64-bit float elements attribute"; - return ::mlir::success(); -} -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops0( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops0(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops1( - ::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 ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops1( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops1(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops2( - ::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 ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops2( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops2(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops3( - ::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 ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops3( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops3(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops4( - ::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 ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops4( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops4(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops5( - ::mlir::Attribute attr, ::llvm::StringRef attrName, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { - if (attr && !(((::llvm::isa<::mlir::IntegerAttr>(attr))) && ((::llvm::cast<::mlir::IntegerAttr>(attr).getType().isSignlessInteger(64))))) - return emitError() << "attribute '" << attrName - << "' failed to satisfy constraint: 64-bit signless integer attribute"; - return ::mlir::success(); -} -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops5( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops5(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops6( - ::mlir::Attribute attr, ::llvm::StringRef attrName, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { - if (attr && !((::llvm::isa<::mlir::ArrayAttr>(attr)))) - return emitError() << "attribute '" << attrName - << "' failed to satisfy constraint: array attribute"; - return ::mlir::success(); -} -static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_Ops6( - ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { - return __mlir_ods_local_attr_constraint_Ops6(attr, attrName, [op]() { - return op->emitOpError(); - }); -} - -static ::mlir::LogicalResult __mlir_ods_local_region_constraint_Ops0( - ::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 toy -} // namespace mlir -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::AddOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -AddOpGenericAdaptorBase::AddOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.add", odsAttrs.getContext()); -} - -AddOpGenericAdaptorBase::AddOpGenericAdaptorBase(AddOp op) : AddOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair AddOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr AddOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -AddOpAdaptor::AddOpAdaptor(AddOp op) : AddOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult AddOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair AddOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range AddOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> AddOp::getLhs() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::TypedValue<::mlir::TensorType> AddOp::getRhs() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(1).begin()); -} - -::mlir::OpOperand &AddOp::getLhsMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -::mlir::OpOperand &AddOp::getRhsMutable() { - auto range = getODSOperandIndexAndLength(1); - return getOperation()->getOpOperand(range.first); -} - -std::pair AddOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range AddOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void AddOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value lhs, ::mlir::Value rhs) { - odsState.addOperands(lhs); - odsState.addOperands(rhs); - odsState.addTypes(resultType0); -} - -void AddOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs) { - odsState.addOperands(lhs); - odsState.addOperands(rhs); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void AddOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 2u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult AddOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*this, v.getType(), "operand", index++))) - return ::mlir::failure(); - } - auto valueGroup1 = getODSOperands(1); - - for (auto v : valueGroup1) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult AddOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -void AddOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::AddOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::CastOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -CastOpGenericAdaptorBase::CastOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.cast", odsAttrs.getContext()); -} - -CastOpGenericAdaptorBase::CastOpGenericAdaptorBase(CastOp op) : CastOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair CastOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr CastOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -CastOpAdaptor::CastOpAdaptor(CastOp op) : CastOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult CastOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair CastOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range CastOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> CastOp::getInput() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::OpOperand &CastOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -std::pair CastOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range CastOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> CastOp::getOutput() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSResults(0).begin()); -} - -void CastOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type output, ::mlir::Value input) { - odsState.addOperands(input); - odsState.addTypes(output); -} - -void CastOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input) { - odsState.addOperands(input); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void CastOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 1u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult CastOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult CastOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -::mlir::ParseResult CastOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::OpAsmParser::UnresolvedOperand inputRawOperands[1]; - ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> inputOperands(inputRawOperands); ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::mlir::Type inputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> inputTypes(inputRawTypes); - ::mlir::Type outputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> outputTypes(outputRawTypes); - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperand(inputRawOperands[0])) - return ::mlir::failure(); - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.parseColon()) - return ::mlir::failure(); - - { - ::mlir::TensorType type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - inputRawTypes[0] = type; - } - if (parser.parseKeyword("to")) - return ::mlir::failure(); - - { - ::mlir::TensorType type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - outputRawTypes[0] = type; - } - result.addTypes(outputTypes); - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void CastOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << ' '; - _odsPrinter << getInput(); - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - { - auto type = getInput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::TensorType>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } - _odsPrinter << ' ' << "to"; - _odsPrinter << ' '; - { - auto type = getOutput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::TensorType>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } -} - -void CastOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::CastOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ConstantOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -ConstantOpGenericAdaptorBase::ConstantOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.constant", odsAttrs.getContext()); -} - -ConstantOpGenericAdaptorBase::ConstantOpGenericAdaptorBase(ConstantOp op) : ConstantOpGenericAdaptorBase(op->getDiscardableAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair ConstantOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr ConstantOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -::mlir::DenseElementsAttr ConstantOpGenericAdaptorBase::getValueAttr() { - auto attr = ::llvm::cast<::mlir::DenseElementsAttr>(getProperties().value); - return attr; -} - -::mlir::DenseElementsAttr ConstantOpGenericAdaptorBase::getValue() { - auto attr = getValueAttr(); - return attr; -} - -} // namespace detail -ConstantOpAdaptor::ConstantOpAdaptor(ConstantOp op) : ConstantOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult ConstantOpAdaptor::verify(::mlir::Location loc) { - auto tblgen_value = getProperties().value; (void)tblgen_value; - if (!tblgen_value) return emitError(loc, "'toy.constant' op ""requires attribute 'value'"); - - if (tblgen_value && !((::llvm::isa<::mlir::DenseFPElementsAttr>(tblgen_value) &&::llvm::cast<::mlir::DenseElementsAttr>(tblgen_value).getType().getElementType().isF64()))) - return emitError(loc, "'toy.constant' op ""attribute 'value' failed to satisfy constraint: 64-bit float elements attribute"); - return ::mlir::success(); -} - -std::pair ConstantOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range ConstantOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -std::pair ConstantOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range ConstantOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::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 || /*isRequired=*/true) { - if (!attr) { - emitError() << "expected key entry for value in DictionaryAttr to set " - "Properties."; - return ::mlir::failure(); - } - 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) { - 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); -} - -::mlir::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_Ops0(attr, "value", emitError))) - return ::mlir::failure(); - } - return ::mlir::success(); -} - -::mlir::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); -} - -::mlir::DenseElementsAttr ConstantOp::getValueAttr() { - return ::llvm::cast<::mlir::DenseElementsAttr>(getProperties().value); -} - -::mlir::DenseElementsAttr ConstantOp::getValue() { - auto attr = getValueAttr(); - return attr; -} - -void ConstantOp::setValueAttr(::mlir::DenseElementsAttr attr) { - (*this)->setAttr(getValueAttrName(), attr); -} - -void ConstantOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, DenseElementsAttr value) { - build(odsBuilder, odsState, value.getType(), value); - -} - -void ConstantOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::DenseElementsAttr value) { - odsState.getOrAddProperties().value = value; - odsState.addTypes(resultType0); -} - -void ConstantOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::DenseElementsAttr value) { - odsState.getOrAddProperties().value = value; - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -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); -} - -::mlir::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_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult ConstantOp::verifyInvariants() { - if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) - return ::mlir::success(); - return ::mlir::failure(); -} - -void ConstantOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::ConstantOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::FuncOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -FuncOpGenericAdaptorBase::FuncOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.func", odsAttrs.getContext()); -} - -FuncOpGenericAdaptorBase::FuncOpGenericAdaptorBase(FuncOp op) : FuncOpGenericAdaptorBase(op->getDiscardableAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair FuncOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr FuncOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -::mlir::StringAttr FuncOpGenericAdaptorBase::getSymNameAttr() { - auto attr = ::llvm::cast<::mlir::StringAttr>(getProperties().sym_name); - return attr; -} - -::llvm::StringRef FuncOpGenericAdaptorBase::getSymName() { - auto attr = getSymNameAttr(); - return attr.getValue(); -} - -::mlir::TypeAttr FuncOpGenericAdaptorBase::getFunctionTypeAttr() { - auto attr = ::llvm::cast<::mlir::TypeAttr>(getProperties().function_type); - return attr; -} - -::mlir::FunctionType FuncOpGenericAdaptorBase::getFunctionType() { - auto attr = getFunctionTypeAttr(); - return ::llvm::cast<::mlir::FunctionType>(attr.getValue()); -} - -::mlir::ArrayAttr FuncOpGenericAdaptorBase::getArgAttrsAttr() { - auto attr = ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(getProperties().arg_attrs); - return attr; -} - -::std::optional< ::mlir::ArrayAttr > FuncOpGenericAdaptorBase::getArgAttrs() { - auto attr = getArgAttrsAttr(); - return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); -} - -::mlir::ArrayAttr FuncOpGenericAdaptorBase::getResAttrsAttr() { - auto attr = ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(getProperties().res_attrs); - return attr; -} - -::std::optional< ::mlir::ArrayAttr > FuncOpGenericAdaptorBase::getResAttrs() { - auto attr = getResAttrsAttr(); - return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); -} - -::mlir::Region &FuncOpGenericAdaptorBase::getBody() { - return *odsRegions[0]; -} - -::mlir::RegionRange FuncOpGenericAdaptorBase::getRegions() { - return odsRegions; -} - -} // namespace detail -FuncOpAdaptor::FuncOpAdaptor(FuncOp op) : FuncOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::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, "'toy.func' op ""requires attribute 'function_type'"); - 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, "'toy.func' op ""requires attribute 'sym_name'"); - - if (tblgen_sym_name && !((::llvm::isa<::mlir::StringAttr>(tblgen_sym_name)))) - return emitError(loc, "'toy.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, "'toy.func' op ""attribute 'function_type' failed to satisfy constraint: type attribute of function type"); - - 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, "'toy.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, "'toy.func' op ""attribute 'res_attrs' failed to satisfy constraint: Array of dictionary attributes"); - return ::mlir::success(); -} - -std::pair FuncOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range FuncOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -std::pair FuncOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range FuncOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::Region &FuncOp::getBody() { - return (*this)->getRegion(0); -} - -::mlir::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 || /*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.function_type; - auto attr = dict.get("function_type"); - 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.res_attrs; - auto attr = dict.get("res_attrs"); - 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.sym_name; - auto attr = dict.get("sym_name"); - 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(); - } - } - } - 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.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)); - } - - if (!attrs.empty()) - return odsBuilder.getDictionaryAttr(attrs); - return {}; -} - -llvm::hash_code FuncOp::computePropertiesHash(const Properties &prop) { - return llvm::hash_combine( - llvm::hash_value(prop.arg_attrs.getAsOpaquePointer()), - llvm::hash_value(prop.function_type.getAsOpaquePointer()), - llvm::hash_value(prop.res_attrs.getAsOpaquePointer()), - llvm::hash_value(prop.sym_name.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 == "res_attrs") - return prop.res_attrs; - - if (name == "sym_name") - return prop.sym_name; - 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 == "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; - } -} - -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.res_attrs) attrs.append("res_attrs", prop.res_attrs); - - if (prop.sym_name) attrs.append("sym_name", prop.sym_name); -} - -::mlir::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_Ops3(attr, "arg_attrs", emitError))) - return ::mlir::failure(); - } - - { - ::mlir::Attribute attr = attrs.get(getFunctionTypeAttrName(opName)); - if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_Ops2(attr, "function_type", emitError))) - return ::mlir::failure(); - } - - { - ::mlir::Attribute attr = attrs.get(getResAttrsAttrName(opName)); - if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_Ops3(attr, "res_attrs", emitError))) - return ::mlir::failure(); - } - - { - ::mlir::Attribute attr = attrs.get(getSymNameAttrName(opName)); - if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_Ops1(attr, "sym_name", emitError))) - return ::mlir::failure(); - } - return ::mlir::success(); -} - -::mlir::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.res_attrs))) - return ::mlir::failure(); - - if (::mlir::failed(reader.readAttribute(prop.sym_name))) - 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.res_attrs); - writer.writeAttribute(prop.sym_name); -} - -::mlir::StringAttr FuncOp::getSymNameAttr() { - return ::llvm::cast<::mlir::StringAttr>(getProperties().sym_name); -} - -::llvm::StringRef FuncOp::getSymName() { - auto attr = getSymNameAttr(); - return attr.getValue(); -} - -::mlir::TypeAttr FuncOp::getFunctionTypeAttr() { - return ::llvm::cast<::mlir::TypeAttr>(getProperties().function_type); -} - -::mlir::FunctionType FuncOp::getFunctionType() { - auto attr = getFunctionTypeAttr(); - return ::llvm::cast<::mlir::FunctionType>(attr.getValue()); -} - -::mlir::ArrayAttr FuncOp::getArgAttrsAttr() { - return ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(getProperties().arg_attrs); -} - -::std::optional< ::mlir::ArrayAttr > FuncOp::getArgAttrs() { - auto attr = getArgAttrsAttr(); - return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); -} - -::mlir::ArrayAttr FuncOp::getResAttrsAttr() { - return ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(getProperties().res_attrs); -} - -::std::optional< ::mlir::ArrayAttr > FuncOp::getResAttrs() { - auto attr = getResAttrsAttr(); - return attr ? ::std::optional< ::mlir::ArrayAttr >(attr) : (::std::nullopt); -} - -void FuncOp::setSymNameAttr(::mlir::StringAttr attr) { - (*this)->setAttr(getSymNameAttrName(), attr); -} - -void FuncOp::setSymName(::llvm::StringRef attrValue) { - (*this)->setAttr(getSymNameAttrName(), ::mlir::Builder((*this)->getContext()).getStringAttr(attrValue)); -} - -void FuncOp::setFunctionTypeAttr(::mlir::TypeAttr attr) { - (*this)->setAttr(getFunctionTypeAttrName(), attr); -} - -void FuncOp::setFunctionType(::mlir::FunctionType attrValue) { - (*this)->setAttr(getFunctionTypeAttrName(), ::mlir::TypeAttr::get(attrValue)); -} - -void FuncOp::setArgAttrsAttr(::mlir::ArrayAttr attr) { - (*this)->setAttr(getArgAttrsAttrName(), attr); -} - -void FuncOp::setResAttrsAttr(::mlir::ArrayAttr attr) { - (*this)->setAttr(getResAttrsAttrName(), attr); -} - -::mlir::Attribute FuncOp::removeArgAttrsAttr() { - auto &attr = getProperties().arg_attrs; - attr = {}; - return attr; -} - -::mlir::Attribute FuncOp::removeResAttrsAttr() { - auto &attr = getProperties().res_attrs; - attr = {}; - return attr; -} - -::mlir::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_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'"); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops1(*this, tblgen_sym_name, "sym_name"))) - return ::mlir::failure(); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops2(*this, tblgen_function_type, "function_type"))) - return ::mlir::failure(); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops3(*this, tblgen_arg_attrs, "arg_attrs"))) - return ::mlir::failure(); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops3(*this, tblgen_res_attrs, "res_attrs"))) - return ::mlir::failure(); - { - unsigned index = 0; (void)index; - - for (auto ®ion : ::llvm::MutableArrayRef((*this)->getRegion(0))) - if (::mlir::failed(__mlir_ods_local_region_constraint_Ops0(*this, region, "body", index++))) - return ::mlir::failure(); - } - return ::mlir::success(); -} - -::mlir::LogicalResult FuncOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::FuncOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::GenericCallOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -GenericCallOpGenericAdaptorBase::GenericCallOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.generic_call", odsAttrs.getContext()); -} - -GenericCallOpGenericAdaptorBase::GenericCallOpGenericAdaptorBase(GenericCallOp op) : GenericCallOpGenericAdaptorBase(op->getDiscardableAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair GenericCallOpGenericAdaptorBase::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}; -} - -::mlir::DictionaryAttr GenericCallOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -::mlir::FlatSymbolRefAttr GenericCallOpGenericAdaptorBase::getCalleeAttr() { - auto attr = ::llvm::cast<::mlir::FlatSymbolRefAttr>(getProperties().callee); - return attr; -} - -::llvm::StringRef GenericCallOpGenericAdaptorBase::getCallee() { - auto attr = getCalleeAttr(); - return attr.getValue(); -} - -} // namespace detail -GenericCallOpAdaptor::GenericCallOpAdaptor(GenericCallOp op) : GenericCallOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult GenericCallOpAdaptor::verify(::mlir::Location loc) { - auto tblgen_callee = getProperties().callee; (void)tblgen_callee; - if (!tblgen_callee) return emitError(loc, "'toy.generic_call' op ""requires attribute 'callee'"); - - if (tblgen_callee && !((::llvm::isa<::mlir::FlatSymbolRefAttr>(tblgen_callee)))) - return emitError(loc, "'toy.generic_call' op ""attribute 'callee' failed to satisfy constraint: flat symbol reference attribute"); - return ::mlir::success(); -} - -std::pair GenericCallOp::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::Operation::operand_range GenericCallOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::Operation::operand_range GenericCallOp::getInputs() { - return getODSOperands(0); -} - -::mlir::MutableOperandRange GenericCallOp::getInputsMutable() { - auto range = getODSOperandIndexAndLength(0); - auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); - return mutableRange; -} - -std::pair GenericCallOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range GenericCallOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::LogicalResult GenericCallOp::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.callee; - auto attr = dict.get("callee"); - if (attr || /*isRequired=*/true) { - if (!attr) { - emitError() << "expected key entry for callee in DictionaryAttr to set " - "Properties."; - return ::mlir::failure(); - } - auto convertedAttr = ::llvm::dyn_cast>(attr); - if (convertedAttr) { - propStorage = convertedAttr; - } else { - emitError() << "Invalid attribute `callee` in property conversion: " << attr; - return ::mlir::failure(); - } - } - } - return ::mlir::success(); -} - -::mlir::Attribute GenericCallOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) { - ::mlir::SmallVector<::mlir::NamedAttribute> attrs; - ::mlir::Builder odsBuilder{ctx}; - - { - const auto &propStorage = prop.callee; - if (propStorage) - attrs.push_back(odsBuilder.getNamedAttr("callee", - propStorage)); - } - - if (!attrs.empty()) - return odsBuilder.getDictionaryAttr(attrs); - return {}; -} - -llvm::hash_code GenericCallOp::computePropertiesHash(const Properties &prop) { - return llvm::hash_combine( - llvm::hash_value(prop.callee.getAsOpaquePointer())); -} - -std::optional GenericCallOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { - if (name == "callee") - return prop.callee; - return std::nullopt; -} - -void GenericCallOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { - if (name == "callee") { - prop.callee = ::llvm::dyn_cast_or_null>(value); - return; - } -} - -void GenericCallOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { - if (prop.callee) attrs.append("callee", prop.callee); -} - -::mlir::LogicalResult GenericCallOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { - { - ::mlir::Attribute attr = attrs.get(getCalleeAttrName(opName)); - if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_Ops4(attr, "callee", emitError))) - return ::mlir::failure(); - } - return ::mlir::success(); -} - -::mlir::LogicalResult GenericCallOp::readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state) { - auto &prop = state.getOrAddProperties(); (void)prop; - if (::mlir::failed(reader.readAttribute(prop.callee))) - return ::mlir::failure(); - return ::mlir::success(); -} - -void GenericCallOp::writeProperties(::mlir::DialectBytecodeWriter &writer) { - auto &prop = getProperties(); (void)prop; - writer.writeAttribute(prop.callee); -} - -::mlir::FlatSymbolRefAttr GenericCallOp::getCalleeAttr() { - return ::llvm::cast<::mlir::FlatSymbolRefAttr>(getProperties().callee); -} - -::llvm::StringRef GenericCallOp::getCallee() { - auto attr = getCalleeAttr(); - return attr.getValue(); -} - -void GenericCallOp::setCalleeAttr(::mlir::FlatSymbolRefAttr attr) { - (*this)->setAttr(getCalleeAttrName(), attr); -} - -void GenericCallOp::setCallee(::llvm::StringRef attrValue) { - (*this)->setAttr(getCalleeAttrName(), ::mlir::SymbolRefAttr::get(::mlir::Builder((*this)->getContext()).getContext(), attrValue)); -} - -void GenericCallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::FlatSymbolRefAttr callee, ::mlir::ValueRange inputs) { - odsState.addOperands(inputs); - odsState.getOrAddProperties().callee = callee; - odsState.addTypes(resultType0); -} - -void GenericCallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::FlatSymbolRefAttr callee, ::mlir::ValueRange inputs) { - odsState.addOperands(inputs); - odsState.getOrAddProperties().callee = callee; - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void GenericCallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::llvm::StringRef callee, ::mlir::ValueRange inputs) { - odsState.addOperands(inputs); - odsState.getOrAddProperties().callee = ::mlir::SymbolRefAttr::get(odsBuilder.getContext(), callee); - odsState.addTypes(resultType0); -} - -void GenericCallOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::llvm::StringRef callee, ::mlir::ValueRange inputs) { - odsState.addOperands(inputs); - odsState.getOrAddProperties().callee = ::mlir::SymbolRefAttr::get(odsBuilder.getContext(), callee); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void GenericCallOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult GenericCallOp::verifyInvariantsImpl() { - auto tblgen_callee = getProperties().callee; (void)tblgen_callee; - if (!tblgen_callee) return emitOpError("requires attribute 'callee'"); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops4(*this, tblgen_callee, "callee"))) - return ::mlir::failure(); - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops1(*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_Ops2(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult GenericCallOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -::mlir::ParseResult GenericCallOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::FlatSymbolRefAttr calleeAttr; - ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> inputsOperands; - ::llvm::SMLoc inputsOperandsLoc; - (void)inputsOperandsLoc; - ::llvm::ArrayRef<::mlir::Type> inputsTypes; - ::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(); - - inputsOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperandList(inputsOperands)) - 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 inputs__allResult_functionType; - if (parser.parseType(inputs__allResult_functionType)) - return ::mlir::failure(); - inputsTypes = inputs__allResult_functionType.getInputs(); - allResultTypes = inputs__allResult_functionType.getResults(); - result.addTypes(allResultTypes); - if (parser.resolveOperands(inputsOperands, inputsTypes, inputsOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void GenericCallOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << ' '; - _odsPrinter.printAttributeWithoutType(getCalleeAttr()); - _odsPrinter << "("; - _odsPrinter << getInputs(); - _odsPrinter << ")"; - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - elidedAttrs.push_back("callee"); - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - _odsPrinter.printFunctionalType(getInputs().getTypes(), getOperation()->getResultTypes()); -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::GenericCallOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::MulOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -MulOpGenericAdaptorBase::MulOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.mul", odsAttrs.getContext()); -} - -MulOpGenericAdaptorBase::MulOpGenericAdaptorBase(MulOp op) : MulOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair MulOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr MulOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -MulOpAdaptor::MulOpAdaptor(MulOp op) : MulOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult MulOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair MulOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range MulOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> MulOp::getLhs() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::TypedValue<::mlir::TensorType> MulOp::getRhs() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(1).begin()); -} - -::mlir::OpOperand &MulOp::getLhsMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -::mlir::OpOperand &MulOp::getRhsMutable() { - auto range = getODSOperandIndexAndLength(1); - return getOperation()->getOpOperand(range.first); -} - -std::pair MulOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range MulOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void MulOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value lhs, ::mlir::Value rhs) { - odsState.addOperands(lhs); - odsState.addOperands(rhs); - odsState.addTypes(resultType0); -} - -void MulOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs) { - odsState.addOperands(lhs); - odsState.addOperands(rhs); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void MulOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 2u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult MulOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*this, v.getType(), "operand", index++))) - return ::mlir::failure(); - } - auto valueGroup1 = getODSOperands(1); - - for (auto v : valueGroup1) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult MulOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -void MulOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::MulOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::PrintOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -PrintOpGenericAdaptorBase::PrintOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.print", odsAttrs.getContext()); -} - -PrintOpGenericAdaptorBase::PrintOpGenericAdaptorBase(PrintOp op) : PrintOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair PrintOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr PrintOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -PrintOpAdaptor::PrintOpAdaptor(PrintOp op) : PrintOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult PrintOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair PrintOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range PrintOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::Value PrintOp::getInput() { - return ::llvm::cast<::mlir::Value>(*getODSOperands(0).begin()); -} - -::mlir::OpOperand &PrintOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -std::pair PrintOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range PrintOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void PrintOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value input) { - odsState.addOperands(input); -} - -void PrintOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input) { - odsState.addOperands(input); - assert(resultTypes.size() == 0u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void PrintOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 1u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 0u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult PrintOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops3(*this, v.getType(), "operand", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult PrintOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -::mlir::ParseResult PrintOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::OpAsmParser::UnresolvedOperand inputRawOperands[1]; - ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> inputOperands(inputRawOperands); ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::mlir::Type inputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> inputTypes(inputRawTypes); - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperand(inputRawOperands[0])) - return ::mlir::failure(); - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.parseColon()) - return ::mlir::failure(); - - { - ::mlir::Type type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - inputRawTypes[0] = type; - } - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void PrintOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << ' '; - _odsPrinter << getInput(); - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - { - auto type = getInput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::Type>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::PrintOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ReshapeOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -ReshapeOpGenericAdaptorBase::ReshapeOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.reshape", odsAttrs.getContext()); -} - -ReshapeOpGenericAdaptorBase::ReshapeOpGenericAdaptorBase(ReshapeOp op) : ReshapeOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair ReshapeOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr ReshapeOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -ReshapeOpAdaptor::ReshapeOpAdaptor(ReshapeOp op) : ReshapeOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult ReshapeOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair ReshapeOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range ReshapeOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> ReshapeOp::getInput() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::OpOperand &ReshapeOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -std::pair ReshapeOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range ReshapeOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void ReshapeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value input) { - odsState.addOperands(input); - odsState.addTypes(resultType0); -} - -void ReshapeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input) { - odsState.addOperands(input); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void ReshapeOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 1u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult ReshapeOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops4(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult ReshapeOp::verifyInvariants() { - return verifyInvariantsImpl(); -} - -::mlir::ParseResult ReshapeOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::OpAsmParser::UnresolvedOperand inputRawOperands[1]; - ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> inputOperands(inputRawOperands); ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::mlir::Type inputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> inputTypes(inputRawTypes); - ::llvm::SmallVector<::mlir::Type, 1> allResultTypes; - if (parser.parseLParen()) - return ::mlir::failure(); - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperand(inputRawOperands[0])) - return ::mlir::failure(); - if (parser.parseColon()) - return ::mlir::failure(); - - { - ::mlir::TensorType type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - inputRawTypes[0] = type; - } - if (parser.parseRParen()) - return ::mlir::failure(); - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.parseKeyword("to")) - return ::mlir::failure(); - - if (parser.parseTypeList(allResultTypes)) - return ::mlir::failure(); - result.addTypes(allResultTypes); - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void ReshapeOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << "("; - _odsPrinter << getInput(); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - { - auto type = getInput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::TensorType>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } - _odsPrinter << ")"; - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << "to"; - _odsPrinter << ' '; - _odsPrinter << getOperation()->getResultTypes(); -} - -void ReshapeOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::ReshapeOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ReturnOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -ReturnOpGenericAdaptorBase::ReturnOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.return", odsAttrs.getContext()); -} - -ReturnOpGenericAdaptorBase::ReturnOpGenericAdaptorBase(ReturnOp op) : ReturnOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), 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}; -} - -::mlir::DictionaryAttr ReturnOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -ReturnOpAdaptor::ReturnOpAdaptor(ReturnOp op) : ReturnOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::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::Operation::operand_range ReturnOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::Operation::operand_range ReturnOp::getInput() { - return getODSOperands(0); -} - -::mlir::MutableOperandRange ReturnOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); - return mutableRange; -} - -std::pair ReturnOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range ReturnOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void ReturnOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState) { - build(odsBuilder, odsState, std::nullopt); -} - -void ReturnOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange input) { - odsState.addOperands(input); -} - -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); -} - -::mlir::LogicalResult ReturnOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops1(*this, v.getType(), "operand", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult ReturnOp::verifyInvariants() { - if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) - return ::mlir::success(); - return ::mlir::failure(); -} - -::mlir::ParseResult ReturnOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> inputOperands; - ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::llvm::SmallVector<::mlir::Type, 1> inputTypes; - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperandList(inputOperands)) - return ::mlir::failure(); - if (!inputOperands.empty()) { - if (parser.parseColon()) - return ::mlir::failure(); - - if (parser.parseTypeList(inputTypes)) - return ::mlir::failure(); - } - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void ReturnOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - if (!getInput().empty()) { - _odsPrinter << ' '; - _odsPrinter << getInput(); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - _odsPrinter << getInput().getTypes(); - } - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); -} - -void ReturnOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::ReturnOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::StructAccessOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -StructAccessOpGenericAdaptorBase::StructAccessOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.struct_access", odsAttrs.getContext()); -} - -StructAccessOpGenericAdaptorBase::StructAccessOpGenericAdaptorBase(StructAccessOp op) : StructAccessOpGenericAdaptorBase(op->getDiscardableAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair StructAccessOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr StructAccessOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -::mlir::IntegerAttr StructAccessOpGenericAdaptorBase::getIndexAttr() { - auto attr = ::llvm::cast<::mlir::IntegerAttr>(getProperties().index); - return attr; -} - -uint64_t StructAccessOpGenericAdaptorBase::getIndex() { - auto attr = getIndexAttr(); - return attr.getValue().getZExtValue(); -} - -} // namespace detail -StructAccessOpAdaptor::StructAccessOpAdaptor(StructAccessOp op) : StructAccessOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult StructAccessOpAdaptor::verify(::mlir::Location loc) { - auto tblgen_index = getProperties().index; (void)tblgen_index; - if (!tblgen_index) return emitError(loc, "'toy.struct_access' op ""requires attribute 'index'"); - - if (tblgen_index && !(((::llvm::isa<::mlir::IntegerAttr>(tblgen_index))) && ((::llvm::cast<::mlir::IntegerAttr>(tblgen_index).getType().isSignlessInteger(64))))) - return emitError(loc, "'toy.struct_access' op ""attribute 'index' failed to satisfy constraint: 64-bit signless integer attribute"); - return ::mlir::success(); -} - -std::pair StructAccessOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range StructAccessOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::Value StructAccessOp::getInput() { - return ::llvm::cast<::mlir::Value>(*getODSOperands(0).begin()); -} - -::mlir::OpOperand &StructAccessOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -std::pair StructAccessOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range StructAccessOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::Value StructAccessOp::getOutput() { - return ::llvm::cast<::mlir::Value>(*getODSResults(0).begin()); -} - -::mlir::LogicalResult StructAccessOp::setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { - ::mlir::DictionaryAttr dict = ::llvm::dyn_cast<::mlir::DictionaryAttr>(attr); - if (!dict) { - emitError() << "expected DictionaryAttr to set properties"; - return ::mlir::failure(); - } - - { - auto &propStorage = prop.index; - auto attr = dict.get("index"); - if (attr || /*isRequired=*/true) { - if (!attr) { - emitError() << "expected key entry for index in DictionaryAttr to set " - "Properties."; - return ::mlir::failure(); - } - auto convertedAttr = ::llvm::dyn_cast>(attr); - if (convertedAttr) { - propStorage = convertedAttr; - } else { - emitError() << "Invalid attribute `index` in property conversion: " << attr; - return ::mlir::failure(); - } - } - } - return ::mlir::success(); -} - -::mlir::Attribute StructAccessOp::getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop) { - ::mlir::SmallVector<::mlir::NamedAttribute> attrs; - ::mlir::Builder odsBuilder{ctx}; - - { - const auto &propStorage = prop.index; - if (propStorage) - attrs.push_back(odsBuilder.getNamedAttr("index", - propStorage)); - } - - if (!attrs.empty()) - return odsBuilder.getDictionaryAttr(attrs); - return {}; -} - -llvm::hash_code StructAccessOp::computePropertiesHash(const Properties &prop) { - return llvm::hash_combine( - llvm::hash_value(prop.index.getAsOpaquePointer())); -} - -std::optional StructAccessOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { - if (name == "index") - return prop.index; - return std::nullopt; -} - -void StructAccessOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { - if (name == "index") { - prop.index = ::llvm::dyn_cast_or_null>(value); - return; - } -} - -void StructAccessOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { - if (prop.index) attrs.append("index", prop.index); -} - -::mlir::LogicalResult StructAccessOp::verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) { - { - ::mlir::Attribute attr = attrs.get(getIndexAttrName(opName)); - if (attr && ::mlir::failed(__mlir_ods_local_attr_constraint_Ops5(attr, "index", emitError))) - return ::mlir::failure(); - } - return ::mlir::success(); -} - -::mlir::LogicalResult StructAccessOp::readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state) { - auto &prop = state.getOrAddProperties(); (void)prop; - if (::mlir::failed(reader.readAttribute(prop.index))) - return ::mlir::failure(); - return ::mlir::success(); -} - -void StructAccessOp::writeProperties(::mlir::DialectBytecodeWriter &writer) { - auto &prop = getProperties(); (void)prop; - writer.writeAttribute(prop.index); -} - -::mlir::IntegerAttr StructAccessOp::getIndexAttr() { - return ::llvm::cast<::mlir::IntegerAttr>(getProperties().index); -} - -uint64_t StructAccessOp::getIndex() { - auto attr = getIndexAttr(); - return attr.getValue().getZExtValue(); -} - -void StructAccessOp::setIndexAttr(::mlir::IntegerAttr attr) { - (*this)->setAttr(getIndexAttrName(), attr); -} - -void StructAccessOp::setIndex(uint64_t attrValue) { - (*this)->setAttr(getIndexAttrName(), ::mlir::Builder((*this)->getContext()).getIntegerAttr(::mlir::Builder((*this)->getContext()).getIntegerType(64), attrValue)); -} - -void StructAccessOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type output, ::mlir::Value input, ::mlir::IntegerAttr index) { - odsState.addOperands(input); - odsState.getOrAddProperties().index = index; - odsState.addTypes(output); -} - -void StructAccessOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input, ::mlir::IntegerAttr index) { - odsState.addOperands(input); - odsState.getOrAddProperties().index = index; - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void StructAccessOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type output, ::mlir::Value input, uint64_t index) { - odsState.addOperands(input); - odsState.getOrAddProperties().index = odsBuilder.getIntegerAttr(odsBuilder.getIntegerType(64), index); - odsState.addTypes(output); -} - -void StructAccessOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input, uint64_t index) { - odsState.addOperands(input); - odsState.getOrAddProperties().index = odsBuilder.getIntegerAttr(odsBuilder.getIntegerType(64), index); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void StructAccessOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 1u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult StructAccessOp::verifyInvariantsImpl() { - auto tblgen_index = getProperties().index; (void)tblgen_index; - if (!tblgen_index) return emitOpError("requires attribute 'index'"); - - if (::mlir::failed(__mlir_ods_local_attr_constraint_Ops5(*this, tblgen_index, "index"))) - return ::mlir::failure(); - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops5(*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_Ops2(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult StructAccessOp::verifyInvariants() { - if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) - return ::mlir::success(); - return ::mlir::failure(); -} - -::mlir::ParseResult StructAccessOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::OpAsmParser::UnresolvedOperand inputRawOperands[1]; - ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> inputOperands(inputRawOperands); ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::mlir::IntegerAttr indexAttr; - ::mlir::Type inputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> inputTypes(inputRawTypes); - ::mlir::Type outputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> outputTypes(outputRawTypes); - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperand(inputRawOperands[0])) - return ::mlir::failure(); - if (parser.parseLSquare()) - return ::mlir::failure(); - - if (parser.parseCustomAttributeWithFallback(indexAttr, parser.getBuilder().getIntegerType(64))) { - return ::mlir::failure(); - } - if (indexAttr) result.getOrAddProperties().index = indexAttr; - if (parser.parseRSquare()) - 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::Type type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - inputRawTypes[0] = type; - } - if (parser.parseArrow()) - return ::mlir::failure(); - - { - ::mlir::Type type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - outputRawTypes[0] = type; - } - result.addTypes(outputTypes); - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void StructAccessOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << ' '; - _odsPrinter << getInput(); - _odsPrinter << "["; - _odsPrinter.printAttributeWithoutType(getIndexAttr()); - _odsPrinter << "]"; - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - elidedAttrs.push_back("index"); - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - { - auto type = getInput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::Type>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } - _odsPrinter << ' ' << "->"; - _odsPrinter << ' '; - { - auto type = getOutput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::Type>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } -} - -void StructAccessOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::StructAccessOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::StructConstantOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -StructConstantOpGenericAdaptorBase::StructConstantOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.struct_constant", odsAttrs.getContext()); -} - -StructConstantOpGenericAdaptorBase::StructConstantOpGenericAdaptorBase(StructConstantOp op) : StructConstantOpGenericAdaptorBase(op->getDiscardableAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair StructConstantOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr StructConstantOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -::mlir::ArrayAttr StructConstantOpGenericAdaptorBase::getValueAttr() { - auto attr = ::llvm::cast<::mlir::ArrayAttr>(getProperties().value); - return attr; -} - -::mlir::ArrayAttr StructConstantOpGenericAdaptorBase::getValue() { - auto attr = getValueAttr(); - return attr; -} - -} // namespace detail -StructConstantOpAdaptor::StructConstantOpAdaptor(StructConstantOp op) : StructConstantOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult StructConstantOpAdaptor::verify(::mlir::Location loc) { - auto tblgen_value = getProperties().value; (void)tblgen_value; - if (!tblgen_value) return emitError(loc, "'toy.struct_constant' op ""requires attribute 'value'"); - - if (tblgen_value && !((::llvm::isa<::mlir::ArrayAttr>(tblgen_value)))) - return emitError(loc, "'toy.struct_constant' op ""attribute 'value' failed to satisfy constraint: array attribute"); - return ::mlir::success(); -} - -std::pair StructConstantOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range StructConstantOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -std::pair StructConstantOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range StructConstantOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::Value StructConstantOp::getOutput() { - return ::llvm::cast<::mlir::Value>(*getODSResults(0).begin()); -} - -::mlir::LogicalResult StructConstantOp::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 || /*isRequired=*/true) { - if (!attr) { - emitError() << "expected key entry for value in DictionaryAttr to set " - "Properties."; - return ::mlir::failure(); - } - 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 StructConstantOp::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 StructConstantOp::computePropertiesHash(const Properties &prop) { - return llvm::hash_combine( - llvm::hash_value(prop.value.getAsOpaquePointer())); -} - -std::optional StructConstantOp::getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name) { - if (name == "value") - return prop.value; - return std::nullopt; -} - -void StructConstantOp::setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value) { - if (name == "value") { - prop.value = ::llvm::dyn_cast_or_null>(value); - return; - } -} - -void StructConstantOp::populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs) { - if (prop.value) attrs.append("value", prop.value); -} - -::mlir::LogicalResult StructConstantOp::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_Ops6(attr, "value", emitError))) - return ::mlir::failure(); - } - return ::mlir::success(); -} - -::mlir::LogicalResult StructConstantOp::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 StructConstantOp::writeProperties(::mlir::DialectBytecodeWriter &writer) { - auto &prop = getProperties(); (void)prop; - writer.writeAttribute(prop.value); -} - -::mlir::ArrayAttr StructConstantOp::getValueAttr() { - return ::llvm::cast<::mlir::ArrayAttr>(getProperties().value); -} - -::mlir::ArrayAttr StructConstantOp::getValue() { - auto attr = getValueAttr(); - return attr; -} - -void StructConstantOp::setValueAttr(::mlir::ArrayAttr attr) { - (*this)->setAttr(getValueAttrName(), attr); -} - -void StructConstantOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type output, ::mlir::ArrayAttr value) { - odsState.getOrAddProperties().value = value; - odsState.addTypes(output); -} - -void StructConstantOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ArrayAttr value) { - odsState.getOrAddProperties().value = value; - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void StructConstantOp::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); -} - -::mlir::LogicalResult StructConstantOp::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_Ops6(*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_Ops5(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult StructConstantOp::verifyInvariants() { - if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) - return ::mlir::success(); - return ::mlir::failure(); -} - -::mlir::ParseResult StructConstantOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::ArrayAttr valueAttr; - ::mlir::Type outputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> outputTypes(outputRawTypes); - - if (parser.parseCustomAttributeWithFallback(valueAttr, parser.getBuilder().getType<::mlir::NoneType>())) { - return ::mlir::failure(); - } - if (valueAttr) result.getOrAddProperties().value = valueAttr; - { - 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::Type type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - outputRawTypes[0] = type; - } - result.addTypes(outputTypes); - return ::mlir::success(); -} - -void StructConstantOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << ' '; - _odsPrinter.printAttributeWithoutType(getValueAttr()); - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - elidedAttrs.push_back("value"); - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - { - auto type = getOutput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::Type>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } -} - -void StructConstantOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::StructConstantOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::TransposeOp definitions -//===----------------------------------------------------------------------===// - -namespace detail { -TransposeOpGenericAdaptorBase::TransposeOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const ::mlir::EmptyProperties &properties, ::mlir::RegionRange regions) : odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) - odsOpName.emplace("toy.transpose", odsAttrs.getContext()); -} - -TransposeOpGenericAdaptorBase::TransposeOpGenericAdaptorBase(TransposeOp op) : TransposeOpGenericAdaptorBase(op->getAttrDictionary(), op.getProperties(), op->getRegions()) {} - -std::pair TransposeOpGenericAdaptorBase::getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { - return {index, 1}; -} - -::mlir::DictionaryAttr TransposeOpGenericAdaptorBase::getAttributes() { - return odsAttrs; -} - -} // namespace detail -TransposeOpAdaptor::TransposeOpAdaptor(TransposeOp op) : TransposeOpGenericAdaptor(op->getOperands(), op) {} - -::mlir::LogicalResult TransposeOpAdaptor::verify(::mlir::Location loc) { - return ::mlir::success(); -} - -std::pair TransposeOp::getODSOperandIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::operand_range TransposeOp::getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(getOperation()->operand_begin(), valueRange.first), - std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; -} - -::mlir::TypedValue<::mlir::TensorType> TransposeOp::getInput() { - return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(0).begin()); -} - -::mlir::OpOperand &TransposeOp::getInputMutable() { - auto range = getODSOperandIndexAndLength(0); - return getOperation()->getOpOperand(range.first); -} - -std::pair TransposeOp::getODSResultIndexAndLength(unsigned index) { - return {index, 1}; -} - -::mlir::Operation::result_range TransposeOp::getODSResults(unsigned index) { - auto valueRange = getODSResultIndexAndLength(index); - return {std::next(getOperation()->result_begin(), valueRange.first), - std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; -} - -void TransposeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value input) { - odsState.addOperands(input); - odsState.addTypes(resultType0); -} - -void TransposeOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input) { - odsState.addOperands(input); - assert(resultTypes.size() == 1u && "mismatched number of results"); - odsState.addTypes(resultTypes); -} - -void TransposeOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { - assert(operands.size() == 1u && "mismatched number of parameters"); - odsState.addOperands(operands); - odsState.addAttributes(attributes); - assert(resultTypes.size() == 1u && "mismatched number of return types"); - odsState.addTypes(resultTypes); -} - -::mlir::LogicalResult TransposeOp::verifyInvariantsImpl() { - { - unsigned index = 0; (void)index; - auto valueGroup0 = getODSOperands(0); - - for (auto v : valueGroup0) { - if (::mlir::failed(__mlir_ods_local_type_constraint_Ops0(*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_Ops0(*this, v.getType(), "result", index++))) - return ::mlir::failure(); - } - } - return ::mlir::success(); -} - -::mlir::LogicalResult TransposeOp::verifyInvariants() { - if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) - return ::mlir::success(); - return ::mlir::failure(); -} - -::mlir::ParseResult TransposeOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { - ::mlir::OpAsmParser::UnresolvedOperand inputRawOperands[1]; - ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> inputOperands(inputRawOperands); ::llvm::SMLoc inputOperandsLoc; - (void)inputOperandsLoc; - ::mlir::Type inputRawTypes[1]; - ::llvm::ArrayRef<::mlir::Type> inputTypes(inputRawTypes); - ::llvm::SmallVector<::mlir::Type, 1> allResultTypes; - if (parser.parseLParen()) - return ::mlir::failure(); - - inputOperandsLoc = parser.getCurrentLocation(); - if (parser.parseOperand(inputRawOperands[0])) - return ::mlir::failure(); - if (parser.parseColon()) - return ::mlir::failure(); - - { - ::mlir::TensorType type; - if (parser.parseCustomTypeWithFallback(type)) - return ::mlir::failure(); - inputRawTypes[0] = type; - } - if (parser.parseRParen()) - return ::mlir::failure(); - { - auto loc = parser.getCurrentLocation();(void)loc; - if (parser.parseOptionalAttrDict(result.attributes)) - return ::mlir::failure(); - } - if (parser.parseKeyword("to")) - return ::mlir::failure(); - - if (parser.parseTypeList(allResultTypes)) - return ::mlir::failure(); - result.addTypes(allResultTypes); - if (parser.resolveOperands(inputOperands, inputTypes, inputOperandsLoc, result.operands)) - return ::mlir::failure(); - return ::mlir::success(); -} - -void TransposeOp::print(::mlir::OpAsmPrinter &_odsPrinter) { - _odsPrinter << "("; - _odsPrinter << getInput(); - _odsPrinter << ' ' << ":"; - _odsPrinter << ' '; - { - auto type = getInput().getType(); - if (auto validType = ::llvm::dyn_cast<::mlir::TensorType>(type)) - _odsPrinter.printStrippedAttrOrType(validType); - else - _odsPrinter << type; - } - _odsPrinter << ")"; - ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs; - _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), elidedAttrs); - _odsPrinter << ' ' << "to"; - _odsPrinter << ' '; - _odsPrinter << getOperation()->getResultTypes(); -} - -void TransposeOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { -} - -} // namespace toy -} // namespace mlir -MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::toy::TransposeOp) - - -#endif // GET_OP_CLASSES - diff --git a/Ch7/include/toy/Ops.h.inc b/Ch7/include/toy/Ops.h.inc deleted file mode 100644 index 70c176e..0000000 --- a/Ch7/include/toy/Ops.h.inc +++ /dev/null @@ -1,1698 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Op Declarations *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: Ops.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -#if defined(GET_OP_CLASSES) || defined(GET_OP_FWD_DEFINES) -#undef GET_OP_FWD_DEFINES -namespace mlir { -namespace toy { -class AddOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class CastOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class ConstantOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class FuncOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class GenericCallOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class MulOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class PrintOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class ReshapeOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class ReturnOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class StructAccessOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class StructConstantOp; -} // namespace toy -} // namespace mlir -namespace mlir { -namespace toy { -class TransposeOp; -} // namespace toy -} // namespace mlir -#endif - -#ifdef GET_OP_CLASSES -#undef GET_OP_CLASSES - - -//===----------------------------------------------------------------------===// -// Local Utility Method Definitions -//===----------------------------------------------------------------------===// - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::AddOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class AddOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - AddOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - AddOpGenericAdaptorBase(AddOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class AddOpGenericAdaptor : public detail::AddOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::AddOpGenericAdaptorBase; -public: - AddOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - AddOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : AddOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - AddOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getLhs() { - return (*getODSOperands(0).begin()); - } - - ValueT getRhs() { - return (*getODSOperands(1).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class AddOpAdaptor : public AddOpGenericAdaptor<::mlir::ValueRange> { -public: - using AddOpGenericAdaptor::AddOpGenericAdaptor; - AddOpAdaptor(AddOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class AddOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::NOperands<2>::Impl, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait, ShapeInference::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = AddOpAdaptor; - template - using GenericAdaptor = AddOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.add"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getLhs(); - ::mlir::TypedValue<::mlir::TensorType> getRhs(); - ::mlir::OpOperand &getLhsMutable(); - ::mlir::OpOperand &getRhsMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, Value lhs, Value rhs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value lhs, ::mlir::Value rhs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &p); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - void inferShapes(); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::AddOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::CastOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class CastOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - CastOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - CastOpGenericAdaptorBase(CastOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class CastOpGenericAdaptor : public detail::CastOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::CastOpGenericAdaptorBase; -public: - CastOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - CastOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : CastOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - CastOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getInput() { - return (*getODSOperands(0).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class CastOpAdaptor : public CastOpGenericAdaptor<::mlir::ValueRange> { -public: - using CastOpGenericAdaptor::CastOpGenericAdaptor; - CastOpAdaptor(CastOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class CastOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::OneOperand, ::mlir::OpTrait::OpInvariants, ::mlir::CastOpInterface::Trait, ShapeInference::Trait, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait, ::mlir::OpTrait::SameOperandsAndResultShape> { -public: - using Op::Op; - using Op::print; - using Adaptor = CastOpAdaptor; - template - using GenericAdaptor = CastOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.cast"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getInput(); - ::mlir::OpOperand &getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getOutput(); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type output, ::mlir::Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - static bool areCastCompatible(::mlir::TypeRange inputs, ::mlir::TypeRange outputs); - void inferShapes(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::CastOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ConstantOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class ConstantOpGenericAdaptorBase { -public: - struct Properties { - using valueTy = ::mlir::DenseElementsAttr; - valueTy value; - - auto getValue() { - auto &propStorage = this->value; - return ::llvm::cast<::mlir::DenseElementsAttr>(propStorage); - } - void setValue(const ::mlir::DenseElementsAttr &propValue) { - this->value = propValue; - } - bool operator==(const Properties &rhs) const { - return - rhs.value == this->value && - true; - } - bool operator!=(const Properties &rhs) const { - return !(*this == rhs); - } - }; -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - Properties properties; - ::mlir::RegionRange odsRegions; -public: - ConstantOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}); - - ConstantOpGenericAdaptorBase(ConstantOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - const Properties &getProperties() { - return properties; - } - - ::mlir::DictionaryAttr getAttributes(); - ::mlir::DenseElementsAttr getValueAttr(); - ::mlir::DenseElementsAttr getValue(); -}; -} // namespace detail -template -class ConstantOpGenericAdaptor : public detail::ConstantOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::ConstantOpGenericAdaptorBase; -public: - ConstantOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - ConstantOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : ConstantOpGenericAdaptor(values, attrs, (properties ? *properties.as() : Properties{}), regions) {} - - template >> - ConstantOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class ConstantOpAdaptor : public ConstantOpGenericAdaptor<::mlir::ValueRange> { -public: - using ConstantOpGenericAdaptor::ConstantOpGenericAdaptor; - ConstantOpAdaptor(ConstantOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class ConstantOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::ZeroOperands, ::mlir::OpTrait::OpInvariants, ::mlir::BytecodeOpInterface::Trait, ::mlir::OpTrait::ConstantLike, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait, ShapeInference::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = ConstantOpAdaptor; - template - using GenericAdaptor = ConstantOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - using Properties = FoldAdaptor::Properties; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - static ::llvm::StringRef attrNames[] = {::llvm::StringRef("value")}; - return ::llvm::ArrayRef(attrNames); - } - - ::mlir::StringAttr getValueAttrName() { - return getAttributeNameForIndex(0); - } - - static ::mlir::StringAttr getValueAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 0); - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.constant"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static ::mlir::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop); - static llvm::hash_code computePropertiesHash(const Properties &prop); - static std::optional getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name); - static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value); - static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs); - static ::mlir::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::LogicalResult readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state); - void writeProperties(::mlir::DialectBytecodeWriter &writer); - ::mlir::DenseElementsAttr getValueAttr(); - ::mlir::DenseElementsAttr getValue(); - void setValueAttr(::mlir::DenseElementsAttr attr); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, DenseElementsAttr value); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, double value); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::DenseElementsAttr value); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::DenseElementsAttr value); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &p); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - ::mlir::LogicalResult verify(); - ::mlir::OpFoldResult fold(FoldAdaptor adaptor); - void inferShapes(); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -private: - ::mlir::StringAttr getAttributeNameForIndex(unsigned index) { - return getAttributeNameForIndex((*this)->getName(), index); - } - - static ::mlir::StringAttr getAttributeNameForIndex(::mlir::OperationName name, unsigned index) { - assert(index < 1 && "invalid attribute index"); - assert(name.getStringRef() == getOperationName() && "invalid operation name"); - assert(name.isRegistered() && "Operation isn't registered, missing a " - "dependent dialect loading?"); - return name.getAttributeNames()[index]; - } - -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::ConstantOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::FuncOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class FuncOpGenericAdaptorBase { -public: - struct Properties { - using arg_attrsTy = ::mlir::ArrayAttr; - arg_attrsTy arg_attrs; - - auto getArgAttrs() { - auto &propStorage = this->arg_attrs; - return ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(propStorage); - } - void setArgAttrs(const ::mlir::ArrayAttr &propValue) { - this->arg_attrs = propValue; - } - using function_typeTy = ::mlir::TypeAttr; - function_typeTy function_type; - - auto getFunctionType() { - auto &propStorage = this->function_type; - return ::llvm::cast<::mlir::TypeAttr>(propStorage); - } - void setFunctionType(const ::mlir::TypeAttr &propValue) { - this->function_type = propValue; - } - using res_attrsTy = ::mlir::ArrayAttr; - res_attrsTy res_attrs; - - auto getResAttrs() { - auto &propStorage = this->res_attrs; - return ::llvm::dyn_cast_or_null<::mlir::ArrayAttr>(propStorage); - } - void setResAttrs(const ::mlir::ArrayAttr &propValue) { - this->res_attrs = propValue; - } - using sym_nameTy = ::mlir::StringAttr; - sym_nameTy sym_name; - - auto getSymName() { - auto &propStorage = this->sym_name; - return ::llvm::cast<::mlir::StringAttr>(propStorage); - } - void setSymName(const ::mlir::StringAttr &propValue) { - this->sym_name = propValue; - } - bool operator==(const Properties &rhs) const { - return - rhs.arg_attrs == this->arg_attrs && - rhs.function_type == this->function_type && - rhs.res_attrs == this->res_attrs && - rhs.sym_name == this->sym_name && - true; - } - bool operator!=(const Properties &rhs) const { - return !(*this == rhs); - } - }; -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - Properties properties; - ::mlir::RegionRange odsRegions; -public: - FuncOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}); - - FuncOpGenericAdaptorBase(FuncOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - const Properties &getProperties() { - return properties; - } - - ::mlir::DictionaryAttr getAttributes(); - ::mlir::StringAttr getSymNameAttr(); - ::llvm::StringRef getSymName(); - ::mlir::TypeAttr getFunctionTypeAttr(); - ::mlir::FunctionType getFunctionType(); - ::mlir::ArrayAttr getArgAttrsAttr(); - ::std::optional< ::mlir::ArrayAttr > getArgAttrs(); - ::mlir::ArrayAttr getResAttrsAttr(); - ::std::optional< ::mlir::ArrayAttr > getResAttrs(); - ::mlir::Region &getBody(); - ::mlir::RegionRange getRegions(); -}; -} // namespace detail -template -class FuncOpGenericAdaptor : public detail::FuncOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::FuncOpGenericAdaptorBase; -public: - FuncOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - FuncOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : FuncOpGenericAdaptor(values, attrs, (properties ? *properties.as() : Properties{}), regions) {} - - template >> - FuncOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class FuncOpAdaptor : public FuncOpGenericAdaptor<::mlir::ValueRange> { -public: - using FuncOpGenericAdaptor::FuncOpGenericAdaptor; - FuncOpAdaptor(FuncOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class FuncOp : public ::mlir::Op { -public: - using Op::Op; - using Op::print; - using Adaptor = FuncOpAdaptor; - template - using GenericAdaptor = FuncOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - using Properties = FoldAdaptor::Properties; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - static ::llvm::StringRef attrNames[] = {::llvm::StringRef("arg_attrs"), ::llvm::StringRef("function_type"), ::llvm::StringRef("res_attrs"), ::llvm::StringRef("sym_name")}; - return ::llvm::ArrayRef(attrNames); - } - - ::mlir::StringAttr getArgAttrsAttrName() { - return getAttributeNameForIndex(0); - } - - static ::mlir::StringAttr getArgAttrsAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 0); - } - - ::mlir::StringAttr getFunctionTypeAttrName() { - return getAttributeNameForIndex(1); - } - - static ::mlir::StringAttr getFunctionTypeAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 1); - } - - ::mlir::StringAttr getResAttrsAttrName() { - return getAttributeNameForIndex(2); - } - - static ::mlir::StringAttr getResAttrsAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 2); - } - - ::mlir::StringAttr getSymNameAttrName() { - return getAttributeNameForIndex(3); - } - - static ::mlir::StringAttr getSymNameAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 3); - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.func"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - ::mlir::Region &getBody(); - static ::mlir::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop); - static llvm::hash_code computePropertiesHash(const Properties &prop); - static std::optional getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name); - static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value); - static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs); - static ::mlir::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::LogicalResult readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state); - void writeProperties(::mlir::DialectBytecodeWriter &writer); - ::mlir::StringAttr getSymNameAttr(); - ::llvm::StringRef getSymName(); - ::mlir::TypeAttr getFunctionTypeAttr(); - ::mlir::FunctionType getFunctionType(); - ::mlir::ArrayAttr getArgAttrsAttr(); - ::std::optional< ::mlir::ArrayAttr > getArgAttrs(); - ::mlir::ArrayAttr getResAttrsAttr(); - ::std::optional< ::mlir::ArrayAttr > getResAttrs(); - void setSymNameAttr(::mlir::StringAttr attr); - void setSymName(::llvm::StringRef attrValue); - void setFunctionTypeAttr(::mlir::TypeAttr attr); - void setFunctionType(::mlir::FunctionType attrValue); - void setArgAttrsAttr(::mlir::ArrayAttr attr); - void setResAttrsAttr(::mlir::ArrayAttr attr); - ::mlir::Attribute removeArgAttrsAttr(); - ::mlir::Attribute removeResAttrsAttr(); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, StringRef name, FunctionType type, ArrayRef attrs = {}); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &p); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); -private: - ::mlir::StringAttr getAttributeNameForIndex(unsigned index) { - return getAttributeNameForIndex((*this)->getName(), index); - } - - static ::mlir::StringAttr getAttributeNameForIndex(::mlir::OperationName name, unsigned index) { - assert(index < 4 && "invalid attribute index"); - assert(name.getStringRef() == getOperationName() && "invalid operation name"); - assert(name.isRegistered() && "Operation isn't registered, missing a " - "dependent dialect loading?"); - return name.getAttributeNames()[index]; - } - -public: - //===------------------------------------------------------------------===// - // FunctionOpInterface Methods - //===------------------------------------------------------------------===// - - /// Returns the argument types of this function. - ArrayRef getArgumentTypes() { return getFunctionType().getInputs(); } - - /// Returns the result types of this function. - ArrayRef getResultTypes() { return getFunctionType().getResults(); } - - Region *getCallableRegion() { return &getBody(); } -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::FuncOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::GenericCallOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class GenericCallOpGenericAdaptorBase { -public: - struct Properties { - using calleeTy = ::mlir::FlatSymbolRefAttr; - calleeTy callee; - - auto getCallee() { - auto &propStorage = this->callee; - return ::llvm::cast<::mlir::FlatSymbolRefAttr>(propStorage); - } - void setCallee(const ::mlir::FlatSymbolRefAttr &propValue) { - this->callee = propValue; - } - bool operator==(const Properties &rhs) const { - return - rhs.callee == this->callee && - true; - } - bool operator!=(const Properties &rhs) const { - return !(*this == rhs); - } - }; -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - Properties properties; - ::mlir::RegionRange odsRegions; -public: - GenericCallOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}); - - GenericCallOpGenericAdaptorBase(GenericCallOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - const Properties &getProperties() { - return properties; - } - - ::mlir::DictionaryAttr getAttributes(); - ::mlir::FlatSymbolRefAttr getCalleeAttr(); - ::llvm::StringRef getCallee(); -}; -} // namespace detail -template -class GenericCallOpGenericAdaptor : public detail::GenericCallOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::GenericCallOpGenericAdaptorBase; -public: - GenericCallOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - GenericCallOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : GenericCallOpGenericAdaptor(values, attrs, (properties ? *properties.as() : Properties{}), regions) {} - - template >> - GenericCallOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - RangeT getInputs() { - return getODSOperands(0); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class GenericCallOpAdaptor : public GenericCallOpGenericAdaptor<::mlir::ValueRange> { -public: - using GenericCallOpGenericAdaptor::GenericCallOpGenericAdaptor; - GenericCallOpAdaptor(GenericCallOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class GenericCallOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::VariadicOperands, ::mlir::OpTrait::OpInvariants, ::mlir::BytecodeOpInterface::Trait, ::mlir::CallOpInterface::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = GenericCallOpAdaptor; - template - using GenericAdaptor = GenericCallOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - using Properties = FoldAdaptor::Properties; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - static ::llvm::StringRef attrNames[] = {::llvm::StringRef("callee")}; - return ::llvm::ArrayRef(attrNames); - } - - ::mlir::StringAttr getCalleeAttrName() { - return getAttributeNameForIndex(0); - } - - static ::mlir::StringAttr getCalleeAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 0); - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.generic_call"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::Operation::operand_range getInputs(); - ::mlir::MutableOperandRange getInputsMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static ::mlir::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop); - static llvm::hash_code computePropertiesHash(const Properties &prop); - static std::optional getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name); - static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value); - static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs); - static ::mlir::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::LogicalResult readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state); - void writeProperties(::mlir::DialectBytecodeWriter &writer); - ::mlir::FlatSymbolRefAttr getCalleeAttr(); - ::llvm::StringRef getCallee(); - void setCalleeAttr(::mlir::FlatSymbolRefAttr attr); - void setCallee(::llvm::StringRef attrValue); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, StringRef callee, ArrayRef arguments); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::FlatSymbolRefAttr callee, ::mlir::ValueRange inputs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::FlatSymbolRefAttr callee, ::mlir::ValueRange inputs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::llvm::StringRef callee, ::mlir::ValueRange inputs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::llvm::StringRef callee, ::mlir::ValueRange inputs); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - ::mlir::CallInterfaceCallable getCallableForCallee(); - void setCalleeFromCallable(::mlir::CallInterfaceCallable callee); - ::mlir::Operation::operand_range getArgOperands(); - ::mlir::MutableOperandRange getArgOperandsMutable(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); -private: - ::mlir::StringAttr getAttributeNameForIndex(unsigned index) { - return getAttributeNameForIndex((*this)->getName(), index); - } - - static ::mlir::StringAttr getAttributeNameForIndex(::mlir::OperationName name, unsigned index) { - assert(index < 1 && "invalid attribute index"); - assert(name.getStringRef() == getOperationName() && "invalid operation name"); - assert(name.isRegistered() && "Operation isn't registered, missing a " - "dependent dialect loading?"); - return name.getAttributeNames()[index]; - } - -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::GenericCallOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::MulOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class MulOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - MulOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - MulOpGenericAdaptorBase(MulOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class MulOpGenericAdaptor : public detail::MulOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::MulOpGenericAdaptorBase; -public: - MulOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - MulOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : MulOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - MulOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getLhs() { - return (*getODSOperands(0).begin()); - } - - ValueT getRhs() { - return (*getODSOperands(1).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class MulOpAdaptor : public MulOpGenericAdaptor<::mlir::ValueRange> { -public: - using MulOpGenericAdaptor::MulOpGenericAdaptor; - MulOpAdaptor(MulOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class MulOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::NOperands<2>::Impl, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait, ShapeInference::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = MulOpAdaptor; - template - using GenericAdaptor = MulOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.mul"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getLhs(); - ::mlir::TypedValue<::mlir::TensorType> getRhs(); - ::mlir::OpOperand &getLhsMutable(); - ::mlir::OpOperand &getRhsMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, Value lhs, Value rhs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value lhs, ::mlir::Value rhs); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value lhs, ::mlir::Value rhs); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &p); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - void inferShapes(); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::MulOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::PrintOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class PrintOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - PrintOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - PrintOpGenericAdaptorBase(PrintOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class PrintOpGenericAdaptor : public detail::PrintOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::PrintOpGenericAdaptorBase; -public: - PrintOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - PrintOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : PrintOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - PrintOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getInput() { - return (*getODSOperands(0).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class PrintOpAdaptor : public PrintOpGenericAdaptor<::mlir::ValueRange> { -public: - using PrintOpGenericAdaptor::PrintOpGenericAdaptor; - PrintOpAdaptor(PrintOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class PrintOp : public ::mlir::Op { -public: - using Op::Op; - using Op::print; - using Adaptor = PrintOpAdaptor; - template - using GenericAdaptor = PrintOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.print"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::Value getInput(); - ::mlir::OpOperand &getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::PrintOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ReshapeOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class ReshapeOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - ReshapeOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - ReshapeOpGenericAdaptorBase(ReshapeOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class ReshapeOpGenericAdaptor : public detail::ReshapeOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::ReshapeOpGenericAdaptorBase; -public: - ReshapeOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - ReshapeOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : ReshapeOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - ReshapeOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getInput() { - return (*getODSOperands(0).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class ReshapeOpAdaptor : public ReshapeOpGenericAdaptor<::mlir::ValueRange> { -public: - using ReshapeOpGenericAdaptor::ReshapeOpGenericAdaptor; - ReshapeOpAdaptor(ReshapeOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class ReshapeOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::OneOperand, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = ReshapeOpAdaptor; - template - using GenericAdaptor = ReshapeOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.reshape"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getInput(); - ::mlir::OpOperand &getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - static void getCanonicalizationPatterns(::mlir::RewritePatternSet &results, ::mlir::MLIRContext *context); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::ReshapeOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::ReturnOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class ReturnOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - ReturnOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - ReturnOpGenericAdaptorBase(ReturnOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class ReturnOpGenericAdaptor : public detail::ReturnOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::ReturnOpGenericAdaptorBase; -public: - ReturnOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - ReturnOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : ReturnOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - ReturnOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - RangeT getInput() { - return getODSOperands(0); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class ReturnOpAdaptor : public ReturnOpGenericAdaptor<::mlir::ValueRange> { -public: - using ReturnOpGenericAdaptor::ReturnOpGenericAdaptor; - ReturnOpAdaptor(ReturnOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class ReturnOp : public ::mlir::Op::Impl, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait, ::mlir::OpTrait::IsTerminator> { -public: - using Op::Op; - using Op::print; - using Adaptor = ReturnOpAdaptor; - template - using GenericAdaptor = ReturnOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.return"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::Operation::operand_range getInput(); - ::mlir::MutableOperandRange getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - ::mlir::LogicalResult verify(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: - bool hasOperand() { return getNumOperands() != 0; } -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::ReturnOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::StructAccessOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class StructAccessOpGenericAdaptorBase { -public: - struct Properties { - using indexTy = ::mlir::IntegerAttr; - indexTy index; - - auto getIndex() { - auto &propStorage = this->index; - return ::llvm::cast<::mlir::IntegerAttr>(propStorage); - } - void setIndex(const ::mlir::IntegerAttr &propValue) { - this->index = propValue; - } - bool operator==(const Properties &rhs) const { - return - rhs.index == this->index && - true; - } - bool operator!=(const Properties &rhs) const { - return !(*this == rhs); - } - }; -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - Properties properties; - ::mlir::RegionRange odsRegions; -public: - StructAccessOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}); - - StructAccessOpGenericAdaptorBase(StructAccessOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - const Properties &getProperties() { - return properties; - } - - ::mlir::DictionaryAttr getAttributes(); - ::mlir::IntegerAttr getIndexAttr(); - uint64_t getIndex(); -}; -} // namespace detail -template -class StructAccessOpGenericAdaptor : public detail::StructAccessOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::StructAccessOpGenericAdaptorBase; -public: - StructAccessOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - StructAccessOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : StructAccessOpGenericAdaptor(values, attrs, (properties ? *properties.as() : Properties{}), regions) {} - - template >> - StructAccessOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getInput() { - return (*getODSOperands(0).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class StructAccessOpAdaptor : public StructAccessOpGenericAdaptor<::mlir::ValueRange> { -public: - using StructAccessOpGenericAdaptor::StructAccessOpGenericAdaptor; - StructAccessOpAdaptor(StructAccessOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class StructAccessOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::OneOperand, ::mlir::OpTrait::OpInvariants, ::mlir::BytecodeOpInterface::Trait, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = StructAccessOpAdaptor; - template - using GenericAdaptor = StructAccessOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - using Properties = FoldAdaptor::Properties; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - static ::llvm::StringRef attrNames[] = {::llvm::StringRef("index")}; - return ::llvm::ArrayRef(attrNames); - } - - ::mlir::StringAttr getIndexAttrName() { - return getAttributeNameForIndex(0); - } - - static ::mlir::StringAttr getIndexAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 0); - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.struct_access"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::Value getInput(); - ::mlir::OpOperand &getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - ::mlir::Value getOutput(); - static ::mlir::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop); - static llvm::hash_code computePropertiesHash(const Properties &prop); - static std::optional getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name); - static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value); - static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs); - static ::mlir::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::LogicalResult readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state); - void writeProperties(::mlir::DialectBytecodeWriter &writer); - ::mlir::IntegerAttr getIndexAttr(); - uint64_t getIndex(); - void setIndexAttr(::mlir::IntegerAttr attr); - void setIndex(uint64_t attrValue); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, Value input, size_t index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type output, ::mlir::Value input, ::mlir::IntegerAttr index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input, ::mlir::IntegerAttr index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type output, ::mlir::Value input, uint64_t index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input, uint64_t index); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - ::mlir::LogicalResult verify(); - ::mlir::OpFoldResult fold(FoldAdaptor adaptor); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -private: - ::mlir::StringAttr getAttributeNameForIndex(unsigned index) { - return getAttributeNameForIndex((*this)->getName(), index); - } - - static ::mlir::StringAttr getAttributeNameForIndex(::mlir::OperationName name, unsigned index) { - assert(index < 1 && "invalid attribute index"); - assert(name.getStringRef() == getOperationName() && "invalid operation name"); - assert(name.isRegistered() && "Operation isn't registered, missing a " - "dependent dialect loading?"); - return name.getAttributeNames()[index]; - } - -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::StructAccessOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::StructConstantOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class StructConstantOpGenericAdaptorBase { -public: - struct Properties { - using valueTy = ::mlir::ArrayAttr; - valueTy value; - - auto getValue() { - auto &propStorage = this->value; - return ::llvm::cast<::mlir::ArrayAttr>(propStorage); - } - void setValue(const ::mlir::ArrayAttr &propValue) { - this->value = propValue; - } - bool operator==(const Properties &rhs) const { - return - rhs.value == this->value && - true; - } - bool operator!=(const Properties &rhs) const { - return !(*this == rhs); - } - }; -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - Properties properties; - ::mlir::RegionRange odsRegions; -public: - StructConstantOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}); - - StructConstantOpGenericAdaptorBase(StructConstantOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - const Properties &getProperties() { - return properties; - } - - ::mlir::DictionaryAttr getAttributes(); - ::mlir::ArrayAttr getValueAttr(); - ::mlir::ArrayAttr getValue(); -}; -} // namespace detail -template -class StructConstantOpGenericAdaptor : public detail::StructConstantOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::StructConstantOpGenericAdaptorBase; -public: - StructConstantOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const Properties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - StructConstantOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : StructConstantOpGenericAdaptor(values, attrs, (properties ? *properties.as() : Properties{}), regions) {} - - template >> - StructConstantOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class StructConstantOpAdaptor : public StructConstantOpGenericAdaptor<::mlir::ValueRange> { -public: - using StructConstantOpGenericAdaptor::StructConstantOpGenericAdaptor; - StructConstantOpAdaptor(StructConstantOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class StructConstantOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::ZeroOperands, ::mlir::OpTrait::OpInvariants, ::mlir::BytecodeOpInterface::Trait, ::mlir::OpTrait::ConstantLike, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = StructConstantOpAdaptor; - template - using GenericAdaptor = StructConstantOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - using Properties = FoldAdaptor::Properties; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - static ::llvm::StringRef attrNames[] = {::llvm::StringRef("value")}; - return ::llvm::ArrayRef(attrNames); - } - - ::mlir::StringAttr getValueAttrName() { - return getAttributeNameForIndex(0); - } - - static ::mlir::StringAttr getValueAttrName(::mlir::OperationName name) { - return getAttributeNameForIndex(name, 0); - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.struct_constant"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - ::mlir::Value getOutput(); - static ::mlir::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop); - static llvm::hash_code computePropertiesHash(const Properties &prop); - static std::optional getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name); - static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value); - static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs); - static ::mlir::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); - static ::mlir::LogicalResult readProperties(::mlir::DialectBytecodeReader &reader, ::mlir::OperationState &state); - void writeProperties(::mlir::DialectBytecodeWriter &writer); - ::mlir::ArrayAttr getValueAttr(); - ::mlir::ArrayAttr getValue(); - void setValueAttr(::mlir::ArrayAttr attr); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type output, ::mlir::ArrayAttr value); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ArrayAttr value); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - ::mlir::LogicalResult verify(); - ::mlir::OpFoldResult fold(FoldAdaptor adaptor); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -private: - ::mlir::StringAttr getAttributeNameForIndex(unsigned index) { - return getAttributeNameForIndex((*this)->getName(), index); - } - - static ::mlir::StringAttr getAttributeNameForIndex(::mlir::OperationName name, unsigned index) { - assert(index < 1 && "invalid attribute index"); - assert(name.getStringRef() == getOperationName() && "invalid operation name"); - assert(name.isRegistered() && "Operation isn't registered, missing a " - "dependent dialect loading?"); - return name.getAttributeNames()[index]; - } - -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::StructConstantOp) - -namespace mlir { -namespace toy { - -//===----------------------------------------------------------------------===// -// ::mlir::toy::TransposeOp declarations -//===----------------------------------------------------------------------===// - -namespace detail { -class TransposeOpGenericAdaptorBase { -public: -protected: - ::mlir::DictionaryAttr odsAttrs; - ::std::optional<::mlir::OperationName> odsOpName; - ::mlir::RegionRange odsRegions; -public: - TransposeOpGenericAdaptorBase(::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}); - - TransposeOpGenericAdaptorBase(TransposeOp op); - - std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize); - ::mlir::DictionaryAttr getAttributes(); -}; -} // namespace detail -template -class TransposeOpGenericAdaptor : public detail::TransposeOpGenericAdaptorBase { - using ValueT = ::llvm::detail::ValueOfRange; - using Base = detail::TransposeOpGenericAdaptorBase; -public: - TransposeOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} - - TransposeOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : TransposeOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} - - template >> - TransposeOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} - - std::pair getODSOperandIndexAndLength(unsigned index) { - return Base::getODSOperandIndexAndLength(index, odsOperands.size()); - } - - RangeT getODSOperands(unsigned index) { - auto valueRange = getODSOperandIndexAndLength(index); - return {std::next(odsOperands.begin(), valueRange.first), - std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; - } - - ValueT getInput() { - return (*getODSOperands(0).begin()); - } - - RangeT getOperands() { - return odsOperands; - } - -private: - RangeT odsOperands; -}; -class TransposeOpAdaptor : public TransposeOpGenericAdaptor<::mlir::ValueRange> { -public: - using TransposeOpGenericAdaptor::TransposeOpGenericAdaptor; - TransposeOpAdaptor(TransposeOp op); - - ::mlir::LogicalResult verify(::mlir::Location loc); -}; -class TransposeOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::OneOperand, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait, ShapeInference::Trait> { -public: - using Op::Op; - using Op::print; - using Adaptor = TransposeOpAdaptor; - template - using GenericAdaptor = TransposeOpGenericAdaptor; - using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; - static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { - return {}; - } - - static constexpr ::llvm::StringLiteral getOperationName() { - return ::llvm::StringLiteral("toy.transpose"); - } - - std::pair getODSOperandIndexAndLength(unsigned index); - ::mlir::Operation::operand_range getODSOperands(unsigned index); - ::mlir::TypedValue<::mlir::TensorType> getInput(); - ::mlir::OpOperand &getInputMutable(); - std::pair getODSResultIndexAndLength(unsigned index); - ::mlir::Operation::result_range getODSResults(unsigned index); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type resultType0, ::mlir::Value input); - static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input); - static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); - ::mlir::LogicalResult verifyInvariantsImpl(); - ::mlir::LogicalResult verifyInvariants(); - ::mlir::LogicalResult verify(); - static void getCanonicalizationPatterns(::mlir::RewritePatternSet &results, ::mlir::MLIRContext *context); - void inferShapes(); - static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - void print(::mlir::OpAsmPrinter &_odsPrinter); - void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); -public: -}; -} // namespace toy -} // namespace mlir -MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::toy::TransposeOp) - - -#endif // GET_OP_CLASSES - diff --git a/Ch7/include/toy/ShapeInferenceOpInterfaces.cpp.inc b/Ch7/include/toy/ShapeInferenceOpInterfaces.cpp.inc deleted file mode 100644 index a481d2e..0000000 --- a/Ch7/include/toy/ShapeInferenceOpInterfaces.cpp.inc +++ /dev/null @@ -1,12 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Interface Definitions *| -|* *| -|* Automatically generated file, do not edit! *| -|* *| -\*===----------------------------------------------------------------------===*/ - -/// Infer and set the output shape for the current operation. -void ShapeInference::inferShapes() { - return getImpl()->inferShapes(getImpl(), getOperation()); - } diff --git a/Ch7/include/toy/ShapeInferenceOpInterfaces.h.inc b/Ch7/include/toy/ShapeInferenceOpInterfaces.h.inc deleted file mode 100644 index bb24654..0000000 --- a/Ch7/include/toy/ShapeInferenceOpInterfaces.h.inc +++ /dev/null @@ -1,61 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Interface Declarations *| -|* *| -|* Automatically generated file, do not edit! *| -|* *| -\*===----------------------------------------------------------------------===*/ - -class ShapeInference; -namespace detail { -struct ShapeInferenceInterfaceTraits { - struct Concept { - /// The methods defined by the interface. - void (*inferShapes)(const Concept *impl, ::mlir::Operation *); - }; - template - class Model : public Concept { - public: - using Interface = ShapeInference; - Model() : Concept{inferShapes} {} - - static inline void inferShapes(const Concept *impl, ::mlir::Operation *tablegen_opaque_val); - }; - template - class FallbackModel : public Concept { - public: - using Interface = ShapeInference; - FallbackModel() : Concept{inferShapes} {} - - static inline void inferShapes(const Concept *impl, ::mlir::Operation *tablegen_opaque_val); - }; - template - class ExternalModel : public FallbackModel { - public: - using ConcreteEntity = ConcreteOp; - }; -};template -struct ShapeInferenceTrait; - -} // namespace detail -class ShapeInference : public ::mlir::OpInterface { -public: - using ::mlir::OpInterface::OpInterface; - template - struct Trait : public detail::ShapeInferenceTrait {}; - /// Infer and set the output shape for the current operation. - void inferShapes(); -}; -namespace detail { - template - struct ShapeInferenceTrait : public ::mlir::OpInterface::Trait { - }; -}// namespace detail -template -void detail::ShapeInferenceInterfaceTraits::Model::inferShapes(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) { - return (llvm::cast(tablegen_opaque_val)).inferShapes(); -} -template -void detail::ShapeInferenceInterfaceTraits::FallbackModel::inferShapes(const Concept *impl, ::mlir::Operation *tablegen_opaque_val) { - return static_cast(impl)->inferShapes(tablegen_opaque_val); -} diff --git a/Ch7/mlir/ToyCombine.inc b/Ch7/mlir/ToyCombine.inc deleted file mode 100644 index 61c6203..0000000 --- a/Ch7/mlir/ToyCombine.inc +++ /dev/null @@ -1,176 +0,0 @@ -/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ -|* *| -|* Rewriters *| -|* *| -|* Automatically generated file, do not edit! *| -|* From: ToyCombine.td *| -|* *| -\*===----------------------------------------------------------------------===*/ - -/* Generated from: - ToyCombine.td:46 -*/ -struct FoldConstantReshapeOptPattern : public ::mlir::RewritePattern { - FoldConstantReshapeOptPattern(::mlir::MLIRContext *context) - : ::mlir::RewritePattern("toy.reshape", 2, context, {"toy.constant"}) {} - ::mlir::LogicalResult matchAndRewrite(::mlir::Operation *op0, - ::mlir::PatternRewriter &rewriter) const override { - // Variables for capturing values and attributes used while creating ops - ::mlir::DenseElementsAttr arg; - ::mlir::toy::ReshapeOp res; - ::llvm::SmallVector<::mlir::Operation *, 4> tblgen_ops; - - // Match - tblgen_ops.push_back(op0); - auto castedOp0 = ::llvm::dyn_cast<::mlir::toy::ReshapeOp>(op0); (void)castedOp0; - res = castedOp0; - { - auto *op1 = (*castedOp0.getODSOperands(0).begin()).getDefiningOp(); - if (!(op1)){ - return rewriter.notifyMatchFailure(castedOp0, [&](::mlir::Diagnostic &diag) { - diag << "There's no operation that defines operand 0 of castedOp0"; - }); - } - auto castedOp1 = ::llvm::dyn_cast<::mlir::toy::ConstantOp>(op1); (void)castedOp1; - if (!(castedOp1)){ - return rewriter.notifyMatchFailure(op1, [&](::mlir::Diagnostic &diag) { - diag << "castedOp1 is not ::mlir::toy::ConstantOp type"; - }); - } - { - auto tblgen_attr = op1->getAttrOfType<::mlir::DenseElementsAttr>("value");(void)tblgen_attr; - if (!(tblgen_attr)){ - return rewriter.notifyMatchFailure(op1, [&](::mlir::Diagnostic &diag) { - diag << "expected op 'toy.constant' to have attribute 'value' of type '::mlir::DenseElementsAttr'"; - }); - } - arg = tblgen_attr; - } - tblgen_ops.push_back(op1); - } - - // Rewrite - auto odsLoc = rewriter.getFusedLoc({tblgen_ops[0]->getLoc(), tblgen_ops[1]->getLoc()}); (void)odsLoc; - ::llvm::SmallVector<::mlir::Value, 4> tblgen_repl_values; - auto nativeVar_0 = arg.reshape(::llvm::cast((*res.getODSResults(0).begin()).getType())); (void)nativeVar_0; - ::mlir::toy::ConstantOp tblgen_ConstantOp_1; - { - ::llvm::SmallVector<::mlir::Value, 4> tblgen_values; (void)tblgen_values; - ::llvm::SmallVector<::mlir::NamedAttribute, 4> tblgen_attrs; (void)tblgen_attrs; - if (auto tmpAttr = nativeVar_0) { - tblgen_attrs.emplace_back(rewriter.getStringAttr("value"), tmpAttr); - } - ::llvm::SmallVector<::mlir::Type, 4> tblgen_types; (void)tblgen_types; - for (auto v: castedOp0.getODSResults(0)) { - tblgen_types.push_back(v.getType()); - } - tblgen_ConstantOp_1 = rewriter.create<::mlir::toy::ConstantOp>(odsLoc, tblgen_types, tblgen_values, tblgen_attrs); - } - - for (auto v: ::llvm::SmallVector<::mlir::Value, 4>{ tblgen_ConstantOp_1.getODSResults(0) }) { - tblgen_repl_values.push_back(v); - } - - rewriter.replaceOp(op0, tblgen_repl_values); - return ::mlir::success(); - }; -}; - -/* Generated from: - ToyCombine.td:59 -*/ -struct RedundantReshapeOptPattern : public ::mlir::RewritePattern { - RedundantReshapeOptPattern(::mlir::MLIRContext *context) - : ::mlir::RewritePattern("toy.reshape", 1, context, {}) {} - ::mlir::LogicalResult matchAndRewrite(::mlir::Operation *op0, - ::mlir::PatternRewriter &rewriter) const override { - // Variables for capturing values and attributes used while creating ops - ::mlir::Operation::operand_range arg(op0->getOperands()); - ::mlir::toy::ReshapeOp res; - ::llvm::SmallVector<::mlir::Operation *, 4> tblgen_ops; - - // Match - tblgen_ops.push_back(op0); - auto castedOp0 = ::llvm::dyn_cast<::mlir::toy::ReshapeOp>(op0); (void)castedOp0; - res = castedOp0; - arg = castedOp0.getODSOperands(0); - if (!(((*res.getODSResults(0).begin()).getType() == (*arg.begin()).getType()))){ - return rewriter.notifyMatchFailure(op0, [&](::mlir::Diagnostic &diag) { - diag << "entities 'res, arg' failed to satisfy constraint: ''"; - }); - } - - // Rewrite - auto odsLoc = rewriter.getFusedLoc({tblgen_ops[0]->getLoc()}); (void)odsLoc; - ::llvm::SmallVector<::mlir::Value, 4> tblgen_repl_values; - - for (auto v: ::llvm::SmallVector<::mlir::Value, 4>{ arg }) { - tblgen_repl_values.push_back(v); - } - - rewriter.replaceOp(op0, tblgen_repl_values); - return ::mlir::success(); - }; -}; - -/* Generated from: - ToyCombine.td:33 -*/ -struct ReshapeReshapeOptPattern : public ::mlir::RewritePattern { - ReshapeReshapeOptPattern(::mlir::MLIRContext *context) - : ::mlir::RewritePattern("toy.reshape", 2, context, {"toy.reshape"}) {} - ::mlir::LogicalResult matchAndRewrite(::mlir::Operation *op0, - ::mlir::PatternRewriter &rewriter) const override { - // Variables for capturing values and attributes used while creating ops - ::mlir::Operation::operand_range arg(op0->getOperands()); - ::llvm::SmallVector<::mlir::Operation *, 4> tblgen_ops; - - // Match - tblgen_ops.push_back(op0); - auto castedOp0 = ::llvm::dyn_cast<::mlir::toy::ReshapeOp>(op0); (void)castedOp0; - { - auto *op1 = (*castedOp0.getODSOperands(0).begin()).getDefiningOp(); - if (!(op1)){ - return rewriter.notifyMatchFailure(castedOp0, [&](::mlir::Diagnostic &diag) { - diag << "There's no operation that defines operand 0 of castedOp0"; - }); - } - auto castedOp1 = ::llvm::dyn_cast<::mlir::toy::ReshapeOp>(op1); (void)castedOp1; - if (!(castedOp1)){ - return rewriter.notifyMatchFailure(op1, [&](::mlir::Diagnostic &diag) { - diag << "castedOp1 is not ::mlir::toy::ReshapeOp type"; - }); - } - arg = castedOp1.getODSOperands(0); - tblgen_ops.push_back(op1); - } - - // Rewrite - auto odsLoc = rewriter.getFusedLoc({tblgen_ops[0]->getLoc(), tblgen_ops[1]->getLoc()}); (void)odsLoc; - ::llvm::SmallVector<::mlir::Value, 4> tblgen_repl_values; - ::mlir::toy::ReshapeOp tblgen_ReshapeOp_0; - { - ::llvm::SmallVector<::mlir::Value, 4> tblgen_values; (void)tblgen_values; - ::llvm::SmallVector<::mlir::NamedAttribute, 4> tblgen_attrs; (void)tblgen_attrs; - tblgen_values.push_back((*arg.begin())); - ::llvm::SmallVector<::mlir::Type, 4> tblgen_types; (void)tblgen_types; - for (auto v: castedOp0.getODSResults(0)) { - tblgen_types.push_back(v.getType()); - } - tblgen_ReshapeOp_0 = rewriter.create<::mlir::toy::ReshapeOp>(odsLoc, tblgen_types, tblgen_values, tblgen_attrs); - } - - for (auto v: ::llvm::SmallVector<::mlir::Value, 4>{ tblgen_ReshapeOp_0.getODSResults(0) }) { - tblgen_repl_values.push_back(v); - } - - rewriter.replaceOp(op0, tblgen_repl_values); - return ::mlir::success(); - }; -}; - -void LLVM_ATTRIBUTE_UNUSED populateWithGenerated(::mlir::RewritePatternSet &patterns) { - patterns.add(patterns.getContext()); - patterns.add(patterns.getContext()); - patterns.add(patterns.getContext()); -} diff --git a/Ch7/mlir/run.sh b/Ch7/mlir/run.sh deleted file mode 100644 index f592fde..0000000 --- a/Ch7/mlir/run.sh +++ /dev/null @@ -1,2 +0,0 @@ -mlir-tblgen-18 -gen-rewriters -I /usr/lib/llvm-18/include -I ../include ToyCombine.td > ToyCombine.inc -