I have the following Op:
%vec_sum = scf.for %i = %c0 to %input_size step %c64
iter_args(%sum_iter = %sum_init) -> (vector<64xf32>) {
%dif = arith.subi %input_size, %i : index
%mask = vector.create_mask %dif : vector<64xi1>
%pass_thru = arith.constant dense<0.0> : vector<64xf32>
// Compute squared values of the input vector
%t = vector.maskedload %input_ub[%i], %mask, %pass_thru
: memref<?xf32>, vector<64xi1>, vector<64xf32> into vector<64xf32>
%squared = arith.mulf %t, %t : vector<64xf32>
%sum_next = arith.addf %sum_iter, %squared : vector<64xf32>
scf.yield %sum_next : vector<64xf32>
}
and we defined our custom vector type to represent our machine feature, said !my.vector<64xf32>
, when lowering, we need to convert all vector type values into our machine vector types, for example
%vec_sum = scf.for %i = %c0 to %input_size step %c64
iter_args(%sum_iter = %sum_init) -> (!my.vector<64xf32>) {
// .....
scf.yield %sum_next : !my.vector<64xf32>
}
I found the builder of scf::ForOp is :
static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState,
Value lowerBound, Value upperBound, Value step,
ValueRange initArgs = std::nullopt,
function_ref<void(OpBuilder &, Location, Value, ValueRange)> odsArg4 = nullptr);
I can’t find an method to map the original Op’s region into new Op’s region, which only modify the last yieldOp’s operands.
I tried make yieldOp with vectorType is illegal, and convert yieldOp’s operands’ types. I hope argumentMaterialization can do this magic. But it didn’t work.
target.addDynamicallyLegalOp<scf::YieldOp>([&](Operation *op) -> bool {
for (auto result : dyn_cast<scf::YieldOp>(op).getResults()) {
if (result.getType().dyn_cast<VectorType>()) {
return false;
}
}
return true;
});
Thanks for your attention!