| 1 | /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ |
| 2 | |* *| |
| 3 | |* Op Declarations *| |
| 4 | |* *| |
| 5 | |* Automatically generated file, do not edit! *| |
| 6 | |* From: LoopExtensionOps.td *| |
| 7 | |* *| |
| 8 | \*===----------------------------------------------------------------------===*/ |
| 9 | |
| 10 | namespace mlir::transform { |
| 11 | |
| 12 | /// Hoist loop invariant subset ops |
| 13 | /// This transform hoists loop-invariant subset ops out of the targeted |
| 14 | /// loop-like op. It looks for matching subset extraction/insertion op pairs and |
| 15 | /// hoists them. The loop body operates on a newly introduced region iter_arg. |
| 16 | /// |
| 17 | /// Subset ops are hoisted only from the targeted op. If subset ops should be |
| 18 | /// hoisted from an entire loop nest, this transformation must be applied to |
| 19 | /// each loop-like op of the loop nest, starting with the innermost loop and |
| 20 | /// ending with the outermost loop. |
| 21 | /// |
| 22 | /// Example: |
| 23 | /// ``` |
| 24 | /// %r = scf.for ... iter_args(%t = %a) -> (tensor<?xf32>) { |
| 25 | /// %0 = tensor.extract_slice %t[0][5][1] : tensor<?xf32> to tensor<5xf32> |
| 26 | /// %1 = "test.foo"(%0) : (tensor<5xf32>) -> (tensor<5xf32>) |
| 27 | /// %2 = tensor.insert_slice %1 into %t[0][5][1] |
| 28 | /// : tensor<5xf32> into tensor<?xf32> |
| 29 | /// scf.yield %2 : tensor<?xf32> |
| 30 | /// } |
| 31 | /// ``` |
| 32 | /// Is transformed to: |
| 33 | /// ``` |
| 34 | /// %0 = tensor.extract_slice %a[0][5][1] : tensor<?xf32> to tensor<5xf32> |
| 35 | /// %new_loop:2 = scf.for ... iter_args(%t = %a, %h = %0) -> (tensor<?xf32>) { |
| 36 | /// %1 = "test.foo"(%h) : (tensor<5xf32>) -> (tensor<5xf32>) |
| 37 | /// scf.yield %t, %2 : tensor<?xf32>, tensor<5xf32> |
| 38 | /// } |
| 39 | /// %r = tensor.insert_slice %new_loop#1 into %new_loop#0 |
| 40 | /// : tensor<5xf32> into tensor<?xf32> |
| 41 | /// ``` |
| 42 | /// |
| 43 | /// Subset ops are hoisted only if there are no conflicting subset ops. E.g., |
| 44 | /// if there were a second overlapping extraction in the above example, no ops |
| 45 | /// could be hoisted safely. |
| 46 | /// |
| 47 | /// This transform reads the target handle and modifies the payload. This |
| 48 | /// transform does not invalidate any handles, but loop-like ops are replaced |
| 49 | /// with new loop-like ops when a subset op is hoisted. The transform rewriter |
| 50 | /// updates all handles accordingly. |
| 51 | class HoistLoopInvariantSubsetsOp; |
| 52 | |
| 53 | } // namespace mlir::transform |
| 54 | #ifdef GET_OP_CLASSES |
| 55 | #undef GET_OP_CLASSES |
| 56 | |
| 57 | #include "mlir/IR/OpDefinition.h" |
| 58 | #include "mlir/IR/Types.h" |
| 59 | #include "mlir/Interfaces/SideEffectInterfaces.h" |
| 60 | |
| 61 | namespace mlir::transform { |
| 62 | |
| 63 | |
| 64 | //===----------------------------------------------------------------------===// |
| 65 | // ::mlir::transform::HoistLoopInvariantSubsetsOp declarations |
| 66 | //===----------------------------------------------------------------------===// |
| 67 | |
| 68 | namespace detail { |
| 69 | |
| 70 | class HoistLoopInvariantSubsetsOpGenericAdaptorBase { |
| 71 | public: |
| 72 | using Properties = ::mlir::EmptyProperties; |
| 73 | protected: |
| 74 | ::mlir::DictionaryAttr odsAttrs; |
| 75 | ::std::optional<::mlir::OperationName> odsOpName; |
| 76 | Properties properties; |
| 77 | ::mlir::RegionRange odsRegions; |
| 78 | public: |
| 79 | HoistLoopInvariantSubsetsOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions = {}) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs) |
| 80 | odsOpName.emplace(args: "transform.loop.hoist_loop_invariant_subsets" , args: odsAttrs.getContext()); |
| 81 | } |
| 82 | |
| 83 | HoistLoopInvariantSubsetsOpGenericAdaptorBase(HoistLoopInvariantSubsetsOp op); |
| 84 | |
| 85 | std::pair<unsigned, unsigned> getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { |
| 86 | return {index, 1}; |
| 87 | } |
| 88 | |
| 89 | const Properties &getProperties() { |
| 90 | return properties; |
| 91 | } |
| 92 | |
| 93 | ::mlir::DictionaryAttr getAttributes() { |
| 94 | return odsAttrs; |
| 95 | } |
| 96 | |
| 97 | }; |
| 98 | |
| 99 | } // namespace detail |
| 100 | template <typename RangeT> |
| 101 | class HoistLoopInvariantSubsetsOpGenericAdaptor : public detail::HoistLoopInvariantSubsetsOpGenericAdaptorBase { |
| 102 | using ValueT = ::llvm::detail::ValueOfRange<RangeT>; |
| 103 | using Base = detail::HoistLoopInvariantSubsetsOpGenericAdaptorBase; |
| 104 | static constexpr int odsIndex_target = 0; |
| 105 | public: |
| 106 | HoistLoopInvariantSubsetsOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} |
| 107 | |
| 108 | HoistLoopInvariantSubsetsOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::PropertyRef properties, ::mlir::RegionRange regions = {}) : HoistLoopInvariantSubsetsOpGenericAdaptor(values, attrs, (properties ? *properties.as<Properties *>() : Properties{}), regions) {} |
| 109 | |
| 110 | HoistLoopInvariantSubsetsOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr) : HoistLoopInvariantSubsetsOpGenericAdaptor(values, attrs, Properties{}, {}) {} |
| 111 | |
| 112 | HoistLoopInvariantSubsetsOpGenericAdaptor(RangeT values, const HoistLoopInvariantSubsetsOpGenericAdaptorBase &base) : Base(base), odsOperands(values) {} |
| 113 | |
| 114 | template <typename LateInst = HoistLoopInvariantSubsetsOp, typename = std::enable_if_t<std::is_same_v<LateInst, HoistLoopInvariantSubsetsOp>>> |
| 115 | HoistLoopInvariantSubsetsOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} |
| 116 | |
| 117 | std::pair<unsigned, unsigned> getODSOperandIndexAndLength(unsigned index) { |
| 118 | return Base::getODSOperandIndexAndLength(index, odsOperandsSize: odsOperands.size()); |
| 119 | } |
| 120 | |
| 121 | RangeT getODSOperands(unsigned index) { |
| 122 | auto valueRange = getODSOperandIndexAndLength(index); |
| 123 | return {std::next(odsOperands.begin(), valueRange.first), |
| 124 | std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; |
| 125 | } |
| 126 | |
| 127 | ValueT getTarget() { |
| 128 | return (*getODSOperands(index: 0).begin()); |
| 129 | } |
| 130 | |
| 131 | RangeT getOperands() { |
| 132 | return odsOperands; |
| 133 | } |
| 134 | |
| 135 | private: |
| 136 | RangeT odsOperands; |
| 137 | }; |
| 138 | class HoistLoopInvariantSubsetsOpAdaptor : public HoistLoopInvariantSubsetsOpGenericAdaptor<::mlir::ValueRange> { |
| 139 | public: |
| 140 | using HoistLoopInvariantSubsetsOpGenericAdaptor::HoistLoopInvariantSubsetsOpGenericAdaptor; |
| 141 | HoistLoopInvariantSubsetsOpAdaptor(HoistLoopInvariantSubsetsOp op); |
| 142 | |
| 143 | ::llvm::LogicalResult verify(::mlir::Location loc); |
| 144 | }; |
| 145 | class HoistLoopInvariantSubsetsOp : public ::mlir::Op<HoistLoopInvariantSubsetsOp, ::mlir::OpTrait::ZeroRegions, ::mlir::OpTrait::ZeroResults, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::OneOperand, ::mlir::OpTrait::OpInvariants, ::mlir::transform::TransformOpInterface::Trait, ::mlir::transform::TransformEachOpTrait, ::mlir::MemoryEffectOpInterface::Trait, ::mlir::transform::ReportTrackingListenerFailuresOpTrait> { |
| 146 | public: |
| 147 | using Op::Op; |
| 148 | using Op::print; |
| 149 | using Adaptor = HoistLoopInvariantSubsetsOpAdaptor; |
| 150 | template <typename RangeT> |
| 151 | using GenericAdaptor = HoistLoopInvariantSubsetsOpGenericAdaptor<RangeT>; |
| 152 | using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; |
| 153 | static constexpr int odsIndex_target = 0; |
| 154 | using Properties = FoldAdaptor::Properties; |
| 155 | static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { |
| 156 | return {}; |
| 157 | } |
| 158 | |
| 159 | static constexpr ::llvm::StringLiteral getOperationName() { |
| 160 | return ::llvm::StringLiteral("transform.loop.hoist_loop_invariant_subsets" ); |
| 161 | } |
| 162 | |
| 163 | std::pair<unsigned, unsigned> getODSOperandIndexAndLength(unsigned index) { |
| 164 | return {index, 1}; |
| 165 | } |
| 166 | |
| 167 | ::mlir::Operation::operand_range getODSOperands(unsigned index) { |
| 168 | auto [start, length] = getODSOperandIndexAndLength(index); |
| 169 | return getOperation()->getOperands().slice(n: start, m: length); |
| 170 | } |
| 171 | |
| 172 | ::mlir::TypedValue<::mlir::transform::TransformHandleTypeInterface> getTarget() { |
| 173 | return ::llvm::cast<::mlir::TypedValue<::mlir::transform::TransformHandleTypeInterface>>(Val: *getODSOperands(index: 0).begin()); |
| 174 | } |
| 175 | |
| 176 | ::mlir::OpOperand &getTargetMutable() { |
| 177 | auto range = getODSOperandIndexAndLength(index: 0); |
| 178 | return getOperation()->getOpOperand(idx: range.first); |
| 179 | } |
| 180 | |
| 181 | std::pair<unsigned, unsigned> getODSResultIndexAndLength(unsigned index) { |
| 182 | return {index, 1}; |
| 183 | } |
| 184 | |
| 185 | ::mlir::Operation::result_range getODSResults(unsigned index) { |
| 186 | auto valueRange = getODSResultIndexAndLength(index); |
| 187 | return {std::next(x: getOperation()->result_begin(), n: valueRange.first), |
| 188 | std::next(x: getOperation()->result_begin(), n: valueRange.first + valueRange.second)}; |
| 189 | } |
| 190 | |
| 191 | static ::llvm::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); |
| 192 | static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop); |
| 193 | static llvm::hash_code computePropertiesHash(const Properties &prop); |
| 194 | static std::optional<mlir::Attribute> getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name); |
| 195 | static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value); |
| 196 | static void walkInherentAttrs(::mlir::MLIRContext *ctx, Properties &prop, ::llvm::function_ref<void(::llvm::StringRef, ::mlir::Attribute &)> visitor); |
| 197 | static ::llvm::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); |
| 198 | static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value target); |
| 199 | static HoistLoopInvariantSubsetsOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Value target); |
| 200 | static HoistLoopInvariantSubsetsOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Value target); |
| 201 | static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value target); |
| 202 | static HoistLoopInvariantSubsetsOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::Value target); |
| 203 | static HoistLoopInvariantSubsetsOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::Value target); |
| 204 | static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); |
| 205 | static HoistLoopInvariantSubsetsOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); |
| 206 | static HoistLoopInvariantSubsetsOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); |
| 207 | static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {}); |
| 208 | static HoistLoopInvariantSubsetsOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {}); |
| 209 | static HoistLoopInvariantSubsetsOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {}); |
| 210 | ::llvm::LogicalResult verifyInvariantsImpl(); |
| 211 | ::llvm::LogicalResult verifyInvariants(); |
| 212 | void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); |
| 213 | static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); |
| 214 | LLVM_ATTRIBUTE_MINSIZE void print(::mlir::OpAsmPrinter &_odsPrinter); |
| 215 | public: |
| 216 | ::mlir::DiagnosedSilenceableFailure applyToOne( |
| 217 | ::mlir::transform::TransformRewriter &rewriter, |
| 218 | ::mlir::LoopLikeOpInterface loopLikeOp, |
| 219 | ::mlir::transform::ApplyToEachResultList &results, |
| 220 | ::mlir::transform::TransformState &state); |
| 221 | }; |
| 222 | |
| 223 | } // namespace mlir::transform |
| 224 | MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::transform::HoistLoopInvariantSubsetsOp) |
| 225 | |
| 226 | |
| 227 | #endif // GET_OP_CLASSES |
| 228 | |
| 229 | |