Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backend: (csl) added arith.select to csl backend #3199

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tests/filecheck/backend/csl/print_csl.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@
csl.return %and_ : i1
}

csl.func @select() -> !csl<dsd mem1d_dsd> {
%value1 = arith.constant 100 : si32
%value2 = arith.constant 200 : si32
%toggle = arith.constant 1 : i1
%A = memref.get_global @A : memref<24xf32>
%dsd1 = "csl.get_mem_dsd"(%A, %value1) : (memref<24xf32>, si32) -> !csl<dsd mem1d_dsd>
%dsd2 = "csl.get_mem_dsd"(%A, %value2) : (memref<24xf32>, si32) -> !csl<dsd mem1d_dsd>
%selected_dsd = arith.select %toggle, %dsd1, %dsd2 : !csl<dsd mem1d_dsd>
csl.return %selected_dsd : !csl<dsd mem1d_dsd>
}

csl.func @constants() {
%inline_const = arith.constant 100 : i32

Expand Down Expand Up @@ -574,6 +585,16 @@ csl.func @builtins() {
// CHECK-NEXT: return (((0 <= 1) or (0.0 > 1.1)) and (0.0 >= 1.1));
// CHECK-NEXT: }
// CHECK-NEXT: {{ *}}
// CHECK-NEXT: fn select() mem1d_dsd {
// CHECK-NEXT: const dsd1 : mem1d_dsd = @get_dsd( mem1d_dsd, .{
// CHECK-NEXT: .tensor_access = | d0 | { 100 } -> A[ d0 ]
// CHECK-NEXT: });
// CHECK-NEXT: const dsd2 : mem1d_dsd = @get_dsd( mem1d_dsd, .{
// CHECK-NEXT: .tensor_access = | d0 | { 200 } -> A[ d0 ]
// CHECK-NEXT: });
// CHECK-NEXT: return (if (true) dsd1 else dsd2);
// CHECK-NEXT: }
// CHECK-NEXT: {{ *}}
// CHECK-NEXT: fn constants() void {
// CHECK-NEXT: var v0 : [const27]i16 = @constants([const27]i16, const27);
// CHECK-NEXT: const v1 : [const27]i16 = @constants([const27]i16, const27);
Expand Down
6 changes: 6 additions & 0 deletions xdsl/backend/csl/print_csl.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,12 @@ def print_block(self, body: Block):
self._print_or_promote_to_inline_expr(
res, self._cmp_value_expr(op), brackets=True
)
case arith.Select(cond=cond, lhs=lhs, rhs=rhs, result=res):
cond = self._get_variable_name_for(cond)
lhs = self._get_variable_name_for(lhs)
rhs = self._get_variable_name_for(rhs)
if_str = f"if ({cond}) {lhs} else {rhs}"
self._print_or_promote_to_inline_expr(res, if_str, brackets=True)
case csl.ConcatStructOp(this_struct=a, another_struct=b, result=res):
a_var = self._get_variable_name_for(a)
b_var = self._get_variable_name_for(b)
Expand Down
Loading