| 1 | R"( |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // __NAMESPACE_PATH__::__OP_CPP_NAME__ declarations |
| 4 | //===----------------------------------------------------------------------===// |
| 5 | |
| 6 | __NAMESPACE_OPEN__ |
| 7 | |
| 8 | namespace detail { |
| 9 | |
| 10 | class __OP_CPP_NAME__GenericAdaptorBase { |
| 11 | public: |
| 12 | struct Properties { |
| 13 | }; |
| 14 | public: |
| 15 | __OP_CPP_NAME__GenericAdaptorBase(::mlir::Operation *op) |
| 16 | : odsAttrs(op->getRawDictionaryAttrs()), odsOpName(op->getName()), |
| 17 | odsRegions(op->getRegions()) |
| 18 | {} |
| 19 | |
| 20 | /// Return the unstructured operand index of a structured operand along with |
| 21 | // the amount of unstructured operands it contains. |
| 22 | std::pair<unsigned, unsigned> |
| 23 | getStructuredOperandIndexAndLength (unsigned index, |
| 24 | unsigned odsOperandsSize) { |
| 25 | return {index, 1}; |
| 26 | } |
| 27 | |
| 28 | const Properties &getProperties() { |
| 29 | return properties; |
| 30 | } |
| 31 | |
| 32 | ::mlir::DictionaryAttr getAttributes() { |
| 33 | return odsAttrs; |
| 34 | } |
| 35 | protected: |
| 36 | ::mlir::DictionaryAttr odsAttrs; |
| 37 | ::std::optional<::mlir::OperationName> odsOpName; |
| 38 | Properties properties; |
| 39 | ::mlir::RegionRange odsRegions; |
| 40 | }; |
| 41 | |
| 42 | } // namespace detail |
| 43 | |
| 44 | template <typename RangeT> |
| 45 | class __OP_CPP_NAME__GenericAdaptor |
| 46 | : public detail::__OP_CPP_NAME__GenericAdaptorBase { |
| 47 | using ValueT = ::llvm::detail::ValueOfRange<RangeT>; |
| 48 | using Base = detail::__OP_CPP_NAME__GenericAdaptorBase; |
| 49 | public: |
| 50 | __OP_CPP_NAME__GenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, |
| 51 | ::mlir::OpaqueProperties properties, |
| 52 | ::mlir::RegionRange regions = {}) |
| 53 | : __OP_CPP_NAME__GenericAdaptor(values, attrs, |
| 54 | (properties ? *properties.as<::mlir::EmptyProperties *>() |
| 55 | : ::mlir::EmptyProperties{}), regions) {} |
| 56 | |
| 57 | __OP_CPP_NAME__GenericAdaptor(RangeT values, |
| 58 | const __OP_CPP_NAME__GenericAdaptorBase &base) |
| 59 | : Base(base), odsOperands(values) {} |
| 60 | |
| 61 | // This template parameter allows using __OP_CPP_NAME__ which is declared |
| 62 | // later. |
| 63 | template <typename LateInst = __OP_CPP_NAME__, |
| 64 | typename = std::enable_if_t< |
| 65 | std::is_same_v<LateInst, __OP_CPP_NAME__>>> |
| 66 | __OP_CPP_NAME__GenericAdaptor(RangeT values, LateInst op) |
| 67 | : Base(op), odsOperands(values) {} |
| 68 | |
| 69 | /// Return the unstructured operand index of a structured operand along with |
| 70 | // the amount of unstructured operands it contains. |
| 71 | std::pair<unsigned, unsigned> |
| 72 | getStructuredOperandIndexAndLength(unsigned index) { |
| 73 | return Base::getStructuredOperandIndexAndLength(index, odsOperands.size()); |
| 74 | } |
| 75 | |
| 76 | /// Get the n-th structured operand (single value, variadic or optional). |
| 77 | RangeT getStructuredOperands(unsigned index) { |
| 78 | auto valueRange = getStructuredOperandIndexAndLength(index); |
| 79 | return {std::next(odsOperands.begin(), valueRange.first), |
| 80 | std::next(odsOperands.begin(), |
| 81 | valueRange.first + valueRange.second)}; |
| 82 | } |
| 83 | |
| 84 | RangeT getOperands() { |
| 85 | return odsOperands; |
| 86 | } |
| 87 | |
| 88 | __OP_OPERAND_GETTER_DECLS__ |
| 89 | |
| 90 | private: |
| 91 | RangeT odsOperands; |
| 92 | }; |
| 93 | |
| 94 | class __OP_CPP_NAME__Adaptor |
| 95 | : public __OP_CPP_NAME__GenericAdaptor<::mlir::ValueRange> { |
| 96 | public: |
| 97 | using __OP_CPP_NAME__GenericAdaptor::__OP_CPP_NAME__GenericAdaptor; |
| 98 | __OP_CPP_NAME__Adaptor(__OP_CPP_NAME__ op); |
| 99 | |
| 100 | ::llvm::LogicalResult verify(::mlir::Location loc); |
| 101 | }; |
| 102 | |
| 103 | class __OP_CPP_NAME__ : public ::mlir::Op<__OP_CPP_NAME__> { |
| 104 | public: |
| 105 | using Op::Op; |
| 106 | using Op::print; |
| 107 | using Adaptor = __OP_CPP_NAME__Adaptor; |
| 108 | template <typename RangeT> |
| 109 | using GenericAdaptor = __OP_CPP_NAME__GenericAdaptor<RangeT>; |
| 110 | using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; |
| 111 | static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { |
| 112 | return {}; |
| 113 | } |
| 114 | |
| 115 | static constexpr ::llvm::StringLiteral getOperationName() { |
| 116 | return ::llvm::StringLiteral("__DIALECT_NAME__.__OP_NAME__"); |
| 117 | } |
| 118 | |
| 119 | static ::llvm::ArrayRef<::llvm::StringRef> getOperandNames() { |
| 120 | static ::llvm::StringRef operandNames[] = __OP_OPERAND_INITIALIZER_LIST__; |
| 121 | return operandNames; |
| 122 | } |
| 123 | |
| 124 | static ::llvm::StringRef getOperandName(unsigned index) { |
| 125 | assert(index < __OP_OPERAND_COUNT__ && "invalid attribute index"); |
| 126 | return getOperandNames()[index]; |
| 127 | } |
| 128 | |
| 129 | static ::llvm::ArrayRef<::llvm::StringRef> getResultNames() { |
| 130 | static ::llvm::StringRef resultNames[] = __OP_RESULT_INITIALIZER_LIST__; |
| 131 | return resultNames; |
| 132 | } |
| 133 | |
| 134 | static ::llvm::StringRef getResultName(unsigned index) { |
| 135 | assert(index < __OP_RESULT_COUNT__ && "invalid attribute index"); |
| 136 | return getResultNames()[index]; |
| 137 | } |
| 138 | |
| 139 | /// Return the unstructured operand index of a structured operand along with |
| 140 | // the amount of unstructured operands it contains. |
| 141 | std::pair<unsigned, unsigned> |
| 142 | getStructuredOperandIndexAndLength(unsigned index) { |
| 143 | return {index, 1}; |
| 144 | } |
| 145 | |
| 146 | /// Get the n-th structured operand (single value, variadic or optional). |
| 147 | ::mlir::Operation::operand_range getStructuredOperands(unsigned index) { |
| 148 | auto valueRange = getStructuredOperandIndexAndLength(index); |
| 149 | return {std::next(getOperation()->operand_begin(), valueRange.first), |
| 150 | std::next(getOperation()->operand_begin(), |
| 151 | valueRange.first + valueRange.second)}; |
| 152 | } |
| 153 | |
| 154 | /// Return the unstructured result index of a structured result along with |
| 155 | // the amount of unstructured results it contains. |
| 156 | std::pair<unsigned, unsigned> |
| 157 | getStructuredResultIndexAndLength(unsigned index) { |
| 158 | return {index, 1}; |
| 159 | } |
| 160 | |
| 161 | /// Get the n-th structured result (single value, variadic or optional). |
| 162 | ::mlir::Operation::result_range getStructuredResults(unsigned index) { |
| 163 | auto valueRange = getStructuredResultIndexAndLength(index); |
| 164 | return {std::next(getOperation()->result_begin(), valueRange.first), |
| 165 | std::next(getOperation()->result_begin(), |
| 166 | valueRange.first + valueRange.second)}; |
| 167 | } |
| 168 | |
| 169 | __OP_OPERAND_GETTER_DECLS__ |
| 170 | __OP_RESULT_GETTER_DECLS__ |
| 171 | |
| 172 | __OP_BUILD_DECLS__ |
| 173 | static void build(::mlir::OpBuilder &odsBuilder, |
| 174 | ::mlir::OperationState &odsState, |
| 175 | ::mlir::TypeRange resultTypes, |
| 176 | ::mlir::ValueRange operands, |
| 177 | ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); |
| 178 | }; |
| 179 | |
| 180 | |
| 181 | __NAMESPACE_CLOSE__ |
| 182 | |
| 183 | MLIR_DECLARE_EXPLICIT_TYPE_ID(__NAMESPACE_PATH__::__OP_CPP_NAME__) |
| 184 | |
| 185 | )" |
| 186 | |