-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dialects: (scf) Allow signless integers as induction variable types f…
…or `scf.for` (#1727) This PR adds: - Support for signless integers as induction variable types for `scf.for` (also supported in MLIR) - Custom parsing and printing for the above - Tests (including MLIR interoperability tests) Resolves #1304
- Loading branch information
Showing
5 changed files
with
142 additions
and
6 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
26 changes: 26 additions & 0 deletions
26
tests/filecheck/mlir-conversion/with-mlir/dialects/scf/for_custom_non_index_iv.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,26 @@ | ||
// RUN: xdsl-opt %s | xdsl-opt | mlir-opt | filecheck %s | ||
|
||
%lb = arith.constant 0 : i32 | ||
%ub = arith.constant 42 : i32 | ||
%step = arith.constant 7 : i32 | ||
%sum_init = arith.constant 36 : i32 | ||
%sum = scf.for %iv = %lb to %ub step %step iter_args(%sum_iter = %sum_init) -> (i32) : i32 { | ||
%sum_new = arith.addi %sum_iter, %iv : i32 | ||
scf.yield %sum_new : i32 | ||
} | ||
|
||
scf.for %iv = %lb to %ub step %step : i32 { | ||
} | ||
|
||
// CHECK: module { | ||
// CHECK-NEXT: %{{.*}} = arith.constant 0 : i32 | ||
// CHECK-NEXT: %{{.*}} = arith.constant 42 : i32 | ||
// CHECK-NEXT: %{{.*}} = arith.constant 7 : i32 | ||
// CHECK-NEXT: %{{.*}} = arith.constant 36 : i32 | ||
// CHECK-NEXT: %{{.*}} = scf.for %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%{{.*}} = %{{.*}}) -> (i32) : i32 { | ||
// CHECK-NEXT: %{{.*}} = arith.addi %{{.*}}, %{{.*}} : i32 | ||
// CHECK-NEXT: scf.yield %{{.*}} : i32 | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: scf.for %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} : i32 { | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: } |
33 changes: 33 additions & 0 deletions
33
tests/filecheck/mlir-conversion/with-mlir/dialects/scf/for_generic_non_index_iv.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,33 @@ | ||
// RUN: xdsl-opt %s | mlir-opt --mlir-print-op-generic | xdsl-opt --print-op-generic | filecheck %s | ||
|
||
"builtin.module"() ({ | ||
%lb = "arith.constant"() {"value" = 0 : i32} : () -> i32 | ||
%ub = "arith.constant"() {"value" = 42 : i32} : () -> i32 | ||
%step = "arith.constant"() {"value" = 7 : i32} : () -> i32 | ||
%sum_init = "arith.constant"() {"value" = 36 : i32} : () -> i32 | ||
%sum = "scf.for"(%lb, %ub, %step, %sum_init) ({ | ||
^0(%iv : i32, %sum_iter : i32): | ||
%sum_new = "arith.addi"(%sum_iter, %iv) : (i32, i32) -> i32 | ||
"scf.yield"(%sum_new) : (i32) -> () | ||
}) : (i32, i32, i32, i32) -> i32 | ||
"scf.for"(%lb, %ub, %step) ({ | ||
^bb0(%iv: i32): | ||
"scf.yield"() : () -> () | ||
}) : (i32, i32, i32) -> () | ||
}) : () -> () | ||
|
||
// CHECK: "builtin.module"() ({ | ||
// CHECK-NEXT: %{{.*}} = "arith.constant"() <{"value" = 0 : i32}> : () -> i32 | ||
// CHECK-NEXT: %{{.*}} = "arith.constant"() <{"value" = 42 : i32}> : () -> i32 | ||
// CHECK-NEXT: %{{.*}} = "arith.constant"() <{"value" = 7 : i32}> : () -> i32 | ||
// CHECK-NEXT: %{{.*}} = "arith.constant"() <{"value" = 36 : i32}> : () -> i32 | ||
// CHECK-NEXT: %{{.*}} = "scf.for"(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) ({ | ||
// CHECK-NEXT: ^0(%{{.*}} : i32, %{{.*}} : i32): | ||
// CHECK-NEXT: %{{.*}} = "arith.addi"(%{{.*}}, %{{.*}}) : (i32, i32) -> i32 | ||
// CHECK-NEXT: "scf.yield"(%{{.*}}) : (i32) -> () | ||
// CHECK-NEXT: }) : (i32, i32, i32, i32) -> i32 | ||
// CHECK-NEXT: "scf.for"(%{{.*}}, %{{.*}}, %{{.*}}) ({ | ||
// CHECK-NEXT: ^1(%{{.*}}: i32): | ||
// CHECK-NEXT: "scf.yield"() : () -> () | ||
// CHECK-NEXT: }) : (i32, i32, i32) -> () | ||
// CHECK-NEXT: }) : () -> () |
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