diff --git a/doc/sample/ir/dominance-test.mie b/doc/sample/ir/dominance-test.mie new file mode 100644 index 0000000..99b28f3 --- /dev/null +++ b/doc/sample/ir/dominance-test.mie @@ -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 = () -> () } : () -> () diff --git a/doc/sample/ir/for-loop-1.mie b/doc/sample/ir/for-loop-1.mie index 2dd7617..29d1c29 100644 --- a/doc/sample/ir/for-loop-1.mie +++ b/doc/sample/ir/for-loop-1.mie @@ -1,15 +1,17 @@ ; Comment -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 - ; 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) { - %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 - ; if final iteration. - scf.yield %sum.next : f32 - } +module { + func.func @reduce(%buffer: memref<1024*f32>, %lb: index, %ub: index, %step: index) -> f32 { + ; Initial sum set to 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 { + %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 + ; if final iteration. + scf.yield %sum.next : f32 + } - func.return %sum : f32 + func.return %sum : f32 + } } diff --git a/doc/sample/ir/for-loop-4.mie b/doc/sample/ir/for-loop-4.mie index 5401691..cece2b1 100644 --- a/doc/sample/ir/for-loop-4.mie +++ b/doc/sample/ir/for-loop-4.mie @@ -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 + } +} diff --git a/doc/sample/ir/parse-test-2.mie b/doc/sample/ir/parse-test-2.mie new file mode 100644 index 0000000..843bc49 --- /dev/null +++ b/doc/sample/ir/parse-test-2.mie @@ -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 } : () -> () +}) : () -> () diff --git a/doc/sample/ir/parse-test.mie b/doc/sample/ir/parse-test.mie index 843bc49..5fb56c1 100644 --- a/doc/sample/ir/parse-test.mie +++ b/doc/sample/ir/parse-test.mie @@ -1,26 +1,25 @@ -~builtin.module() ({ - ~func.func() ({ - ^entry(%buffer: i32, %lb: index, %ub: index, %step: index): +module { + func.func @reduce(%buffer: memref, %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 + %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 + } +}