doc: sample: update sample ir files

This commit is contained in:
2026-03-16 12:09:37 +00:00
parent a29779aa83
commit 73b4b77816
5 changed files with 99 additions and 51 deletions

View File

@@ -0,0 +1,30 @@
~func.func() ({
^R:
%0 = ~arith.constant() {value = 0 : i32} : () -> i32
~cf.br-cond(%0) [ ^A, ^B, ^C ] : (i32) -> ()
^A:
~cf.br() [ ^D ] : () -> ()
^B:
~cf.br-cond(%0) [ ^D, ^A, ^E ] : (i32) -> ()
^C:
~cf.br-cond(%0) [ ^G, ^F ] : (i32) -> ()
^D:
~cf.br() [ ^L ] : () -> ()
^E:
~cf.br() [ ^H ] : () -> ()
^F:
~cf.br() [ ^I ] : () -> ()
^G:
~cf.br-cond(%0) [ ^I, ^J ] : (i32) -> ()
^H:
~cf.br-cond(%0) [ ^E, ^K ] : (i32) -> ()
^I:
~cf.br() [ ^K ] : () -> ()
^J:
~cf.br() [ ^I ] : () -> ()
^K:
~cf.br-cond(%0) [ ^R, ^I ] : (i32) -> ()
^L:
~cf.br() [ ^H ] : () -> ()
}) {sym_name = "test", function_type = () -> () } : () -> ()

View File

@@ -1,9 +1,10 @@
; Comment
func.func @reduce(%buffer: memref<1024*f32>, %lb: index, %ub: index, %step: index) -> f32 {
module {
func.func @reduce(%buffer: memref<1024*f32>, %lb: index, %ub: index, %step: index) -> f32 {
; Initial sum set to 0.
%sum.0 = f32.constant 0.0
%sum.0 = arith.constant 0.0 : f32
; iter_args binds initial values to the loop's region arguments.
%sum = scf.for %iv = %lb to %ub step %step iter-args(%sum.iter = %sum.0) -> (f32) {
%sum = scf.for %iv = %lb to %ub step %step iter-args(%sum.iter = %sum.0) -> f32 {
%t = memref.load %buffer[%iv] : memref<1024*f32>
%sum.next = arith.addf %sum.iter, %t : f32
; Yield current iteration sum to next iteration %sum.iter or to %sum
@@ -12,4 +13,5 @@ func.func @reduce(%buffer: memref<1024*f32>, %lb: index, %ub: index, %step: inde
}
func.return %sum : f32
}
}

View File

@@ -1,25 +1,16 @@
~func.func() ({
^entry(%buffer: memref<1024*f32>, %lb: index, %ub: index, %step: index):
; Initial sum set to 0.
%sum.0 = ~f32.constant() {value = 0.0 : f32} : () -> f32
; iter_args binds initial values to the loop's region arguments.
;%sum = "scf.for"(%lb, %ub, %step) -> (f32) {
~cf.br [ ^for.entry(%lb: index, %sum.0: f32) ] : () -> ()
^for.entry(%iv: index, %sum.iter: f32):
%t = ~memref.load(%buffer, %iv) : (memref<1024*f32>, index) -> f32
%sum.next = ~arith.addf(%sum.iter, %t) : (f32, f32) -> f32
~cf.br [ ^for.cond:(%iv: index, %sum.next: f32) ] : () -> ()
^for.cond(%iv: index, %sum.next: f32):
; Yield current iteration sum to next iteration %sum.iter or to %sum
; if final iteration.
%iv.next = ~arith.addi(%iv, %step) : (index, index) -> index
%stop = ~arith.cmpi(%iv.next, %ub) {predicate = 9 : i64} : (index, index) -> i1
~cf.br-cond(%stop) [ ^for.end, ^for.entry:(%iv.next: index, %sum.next: f32) ] : () -> ()
^for.end(%sum: f32):
~func.return(%sum) : (f32) -> ()
}) {sym_name = "reduce"} : (memref<1024*f32>, index, index, index) -> f32
module {
func.func @_reduce(%buffer: memref<1024*f32>, %lb: index, %ub: index, %step: index) -> f32 {
%sum.0 = arith.constant 0 : f32
cf.br ^for.entry(%lb: index, %sum.0: f32)
^for.entry(%iv: index, %sum.iter: f32):
%t = memref.load %buffer[%iv] : memref<1024*f32>
%sum.next = arith.addf %sum.iter, %t : f32
cf.br ^for.cond(%iv: index, %sum.next: f32)
^for.cond(%iv.0: index, %sum.iter.0: index):
%iv.next = arith.addi %iv.0, %step : index
%stop = arith.cmpi uge %iv.next, %ub : index
cf.br-cond %stop, ^for.end(%sum.iter.0: index), ^for.entry(%iv.next: index, %sum.iter.0: index)
^for.end(%sum: f32):
func.return %sum : f32
}
}

View File

@@ -0,0 +1,26 @@
~builtin.module() ({
~func.func() ({
^entry(%buffer: i32, %lb: index, %ub: index, %step: index):
; Initial sum set to 0.
%sum.0 = ~arith.constant() {value = 0.0 : f32} : () -> f32
; iter_args binds initial values to the loop's region arguments.
;%sum = "scf.for"(%lb, %ub, %step) -> (f32) {
~cf.br() [ ^for.entry:(%lb: index, %sum.0: f32) ] : () -> ()
^for.entry(%iv: index, %sum.iter: f32):
%t, %x, %z = ~memref.load(%buffer, %iv) : (i32, index) -> (f32, i1, i1)
%sum.next = ~arith.addf(%sum.iter, %t) : (f32, f32) -> f32
~cf.br() [ ^for.cond:(%iv: index, %sum.next: f32) ] : () -> ()
^for.cond(%iv2: index, %sum.next2: f32):
; Yield current iteration sum to next iteration %sum.iter or to %sum
; if final iteration.
%iv.next = ~arith.addi(%iv, %step) : (index, index) -> index
%stop = ~arith.cmpi(%iv.next, %ub) { predicate = 9 } : (index, index) -> i1
~cf.br-cond(%stop) [ ^for.end, ^for.entry:(%iv.next: index, %sum.next: f32) ] : (i1) -> ()
^for.end(%sum: f32):
~func.return(%sum) : (f32) -> ()
}) {sym_name = "reduce", function_type = (i32, index, index, index) -> f32 } : () -> ()
}) : () -> ()

View File

@@ -1,26 +1,25 @@
~builtin.module() ({
~func.func() ({
^entry(%buffer: i32, %lb: index, %ub: index, %step: index):
module {
func.func @reduce(%buffer: memref<?*f32>, %lb: index, %ub: index, %step: index) -> f32 {
; Initial sum set to 0.
%sum.0 = ~arith.constant() {value = 0.0 : f32} : () -> f32
%sum.0 = arith.constant 0.0 : f32
; iter_args binds initial values to the loop's region arguments.
;%sum = "scf.for"(%lb, %ub, %step) -> (f32) {
~cf.br() [ ^for.entry:(%lb: index, %sum.0: f32) ] : () -> ()
cf.br ^for.entry(%lb: index, %sum.0: f32)
^for.entry(%iv: index, %sum.iter: f32):
%t, %x, %z = ~memref.load(%buffer, %iv) : (i32, index) -> (f32, i1, i1)
%sum.next = ~arith.addf(%sum.iter, %t) : (f32, f32) -> f32
%t = memref.load %buffer[%iv] : memref<?*f32>
%sum.next = arith.addf %sum.iter, %t : f32
~cf.br() [ ^for.cond:(%iv: index, %sum.next: f32) ] : () -> ()
cf.br ^for.cond(%iv: index, %sum.next: f32)
^for.cond(%iv2: index, %sum.next2: f32):
; Yield current iteration sum to next iteration %sum.iter or to %sum
; if final iteration.
%iv.next = ~arith.addi(%iv, %step) : (index, index) -> index
%stop = ~arith.cmpi(%iv.next, %ub) { predicate = 9 } : (index, index) -> i1
~cf.br-cond(%stop) [ ^for.end, ^for.entry:(%iv.next: index, %sum.next: f32) ] : (i1) -> ()
%iv.next = arith.addi %iv, %step : index
%stop = arith.cmpi uge %iv.next, %ub : index
cf.br-cond %stop, ^for.end, ^for.entry(%iv.next: index, %sum.next: f32)
^for.end(%sum: f32):
~func.return(%sum) : (f32) -> ()
}) {sym_name = "reduce", function_type = (i32, index, index, index) -> f32 } : () -> ()
}) : () -> ()
func.return %sum : f32
}
}