-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement lowering for AccumulateOp.
- Loading branch information
1 parent
fac45e8
commit fca969e
Showing
4 changed files
with
421 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
experimental/iterators/test/Conversion/IteratorsToLLVM/accumulate.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// RUN: mlir-proto-opt %s -convert-iterators-to-llvm \ | ||
// RUN: | FileCheck --enable-var-scope %s | ||
|
||
!element_type = !llvm.struct<(i32)> | ||
|
||
func.func private @zero_struct() -> !element_type { | ||
%zero = arith.constant 0 : i32 | ||
%undef = llvm.mlir.undef : !element_type | ||
%result = llvm.insertvalue %zero, %undef[0 : index] : !element_type | ||
return %result : !element_type | ||
} | ||
|
||
func.func private @sum_struct(%lhs : !element_type, %rhs : !element_type) -> !element_type { | ||
%lhsi = llvm.extractvalue %lhs[0 : index] : !element_type | ||
%rhsi = llvm.extractvalue %rhs[0 : index] : !element_type | ||
%i = arith.addi %lhsi, %rhsi : i32 | ||
%result = llvm.insertvalue %i, %lhs[0 : index] : !element_type | ||
return %result : !element_type | ||
} | ||
|
||
// CHECK-LABEL: func.func private @iterators.accumulate.next.{{[0-9]+}}(%{{.*}}: !iterators.state<!iterators.state<i32>, i1>) -> (!iterators.state<!iterators.state<i32>, i1>, i1, !llvm.struct<(i32)>) { | ||
// CHECK-NEXT: %[[V1:.*]] = iterators.extractvalue %[[arg0:.*]][0] : !iterators.state<!iterators.state<i32>, i1> | ||
// CHECK-NEXT: %[[V2:.*]] = iterators.extractvalue %[[arg0]][1] : !iterators.state<!iterators.state<i32>, i1> | ||
// CHECK-NEXT: %[[V3:.*]]:2 = scf.if %[[V2]] -> (!iterators.state<i32>, !llvm.struct<(i32)>) { | ||
// CHECK-NEXT: %[[V4:.*]] = llvm.mlir.undef : !llvm.struct<(i32)> | ||
// CHECK-NEXT: scf.yield %[[V1]], %[[V4]] : !iterators.state<i32>, !llvm.struct<(i32)> | ||
// CHECK-NEXT: } else { | ||
// CHECK-NEXT: %[[V4:.*]] = func.call @zero_struct() : () -> !llvm.struct<(i32)> | ||
// CHECK-NEXT: %[[V5:.*]]:3 = scf.while (%[[arg1:.*]] = %[[V1]], %[[arg2:.*]] = %[[V4]]) : (!iterators.state<i32>, !llvm.struct<(i32)>) -> (!iterators.state<i32>, !llvm.struct<(i32)>, !llvm.struct<(i32)>) { | ||
// CHECK-NEXT: %[[V6:.*]]:3 = func.call @iterators.constantstream.next.0(%[[arg1]]) : (!iterators.state<i32>) -> (!iterators.state<i32>, i1, !llvm.struct<(i32)>) | ||
// CHECK-NEXT: scf.condition(%[[V6]]#1) %[[V6]]#0, %[[arg2]], %[[V6]]#2 : !iterators.state<i32>, !llvm.struct<(i32)>, !llvm.struct<(i32)> | ||
// CHECK-NEXT: } do { | ||
// CHECK-NEXT: ^bb0(%[[arg1:.*]]: !iterators.state<i32>, %[[arg2:.*]]: !llvm.struct<(i32)>, %[[arg3:.*]]: !llvm.struct<(i32)>): | ||
// CHECK-NEXT: %[[V7:.*]] = func.call @sum_struct(%[[arg2]], %[[arg3]]) : (!llvm.struct<(i32)>, !llvm.struct<(i32)>) -> !llvm.struct<(i32)> | ||
// CHECK-NEXT: scf.yield %[[arg1]], %[[V7]] : !iterators.state<i32>, !llvm.struct<(i32)> | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: scf.yield %[[V5]]#0, %[[V5]]#1 : !iterators.state<i32>, !llvm.struct<(i32)> | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: %[[V8:.*]] = arith.constant true | ||
// CHECK-NEXT: %[[V9:.*]] = arith.xori %[[V8]], %[[V2]] : i1 | ||
// CHECK-NEXT: %[[Va:.*]] = iterators.insertvalue %[[V3]]#0 into %[[arg0]][0] : !iterators.state<!iterators.state<i32>, i1> | ||
// CHECK-NEXT: %[[Vb:.*]] = iterators.insertvalue %[[V8]] into %[[Va]][1] : !iterators.state<!iterators.state<i32>, i1> | ||
// CHECK-NEXT: return %[[Vb]], %[[V9]], %[[V3]]#1 : !iterators.state<!iterators.state<i32>, i1>, i1, !llvm.struct<(i32)> | ||
// CHECK-NEXT: } | ||
|
||
// CHECK-LABEL: func.func private @iterators.accumulate.open.{{[0-9]+}}(%{{.*}}: !iterators.state<!iterators.state<i32>, i1>) -> !iterators.state<!iterators.state<i32>, i1> { | ||
// CHECK-NEXT: %[[V1:.*]] = iterators.extractvalue %[[arg0:.*]][0] : !iterators.state<!iterators.state<i32>, i1> | ||
// CHECK-NEXT: %[[V2:.*]] = call @iterators.constantstream.open.0(%[[V1]]) : (!iterators.state<i32>) -> !iterators.state<i32> | ||
// CHECK-NEXT: %[[V3:.*]] = iterators.insertvalue %[[V2]] into %[[arg0]][0] : !iterators.state<!iterators.state<i32>, i1> | ||
// CHECK-NEXT: %[[V4:.*]] = arith.constant false | ||
// CHECK-NEXT: %[[V5:.*]] = iterators.insertvalue %[[V4]] into %[[V3]][1] : !iterators.state<!iterators.state<i32>, i1> | ||
// CHECK-NEXT: return %[[V5]] : !iterators.state<!iterators.state<i32>, i1> | ||
// CHECK-NEXT: } | ||
|
||
func.func @main() { | ||
// CHECK-LABEL: func.func @main() | ||
%input = "iterators.constantstream"() { value = [] } : () -> (!iterators.stream<!element_type>) | ||
%accumulated = iterators.accumulate(%input, @zero_struct, @sum_struct) | ||
: (!iterators.stream<!element_type>) -> !iterators.stream<!element_type> | ||
// CHECK: %[[V1:.*]] = iterators.undefstate : !iterators.state<!iterators.state<i32>, i1> | ||
// CHECK-NEXT: %[[V2:.*]] = iterators.insertvalue %[[V0:.*]] into %[[V1]][0] : !iterators.state<!iterators.state<i32>, i1> | ||
return | ||
// CHECK-NEXT: return | ||
} |
Oops, something went wrong.