scf.for
← scf dialect
Bounded counted loop with optional loop-carried state.
Operation contract
| Property |
Value |
| Semantic phase |
source structure |
| Traits |
ImplicitTerminator(scf.yield) |
| Interfaces |
LoopLike |
Signature
| Kind |
Name |
Type |
Cardinality |
Description |
| Operand |
lower_bound |
index |
required |
— |
| Operand |
upper_bound |
index |
required |
— |
| Operand |
step |
index |
required |
— |
| Operand |
iter_args |
any |
variadic |
— |
| Operand |
unroll_factor |
index |
optional |
Optional SSA unroll factor policy consumed by unroll transforms. The factor bounds body cloning and does not require the loop trip count to be static. |
| Result |
results |
any |
variadic |
— |
| Attribute |
unroll_policy |
enum ScfForUnrollPolicy |
optional |
Optional bare unroll policy for required full unroll. |
| Attribute |
unroll_schedule |
enum ScfForUnrollSchedule |
optional |
Optional schedule used when materializing unrolled loop body copies. |
| Region |
body |
region |
required |
Loop body. Terminated by scf.yield. (single block, terminator scf.yield.) |
Verification constraints
IterArgsMatchResults(iter_args, results)
YieldCountMatchesResults(body, results)
YieldTypesMatchResults(body, results)
Examples
scf.for %iv = [%c0 to %n step %c1] {
scf.yield
}
%result = scf.for %iv = [%c0 to %n step %c1](%acc = %init : f32) -> (f32) {
%next = scalar.addf %acc, %acc : f32
scf.yield %next : f32
}
scf.for %iv = [%c0 to %n step %c1] unroll(%factor) {
scf.yield
}
scf.for %iv = [%c0 to %n step %c1] unroll(%factor) schedule(interleaved) {
scf.yield
}
%result = scf.for %iv = [%c0 to %n step %c1](%acc = %init : f32) -> (f32) unroll(%factor) schedule(recurrence) {
%next = scalar.addf %acc, %acc : f32
scf.yield %next : f32
}