Skip to content

Commit

Permalink
backend: (csl) Array literals (#3292)
Browse files Browse the repository at this point in the history
Add support for array literals to the printer.

---------

Co-authored-by: n-io <[email protected]>
  • Loading branch information
n-io and n-io authored Oct 11, 2024
1 parent c33f7b3 commit d1f33aa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/filecheck/backend/csl/print_csl.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@
%global_array = memref.get_global @global_array : memref<10xf32>
%const_array = memref.get_global @const_array : memref<10xi32>

%literal_array = arith.constant dense<[1.200000e+00, 2.300000e+00, 3.400000e+00]> : memref<3xf32>

%uninit_ptr = "csl.addressof"(%uninit_array) : (memref<10xf32>) -> !csl.ptr<f32, #csl<ptr_kind many>, #csl<ptr_const var>>
%global_ptr = "csl.addressof"(%global_array) : (memref<10xf32>) -> !csl.ptr<f32, #csl<ptr_kind many>, #csl<ptr_const var>>
%const_ptr = "csl.addressof"(%const_array) : (memref<10xi32>) -> !csl.ptr<i32, #csl<ptr_kind many>, #csl<ptr_const const>>
Expand Down Expand Up @@ -652,6 +654,7 @@ csl.func @builtins() {
// CHECK-NEXT: var uninit_array : [10]f32;
// CHECK-NEXT: var global_array : [10]f32 = @constants([10]f32, 4.2);
// CHECK-NEXT: const const_array : [10]i32 = @constants([10]i32, 10);
// CHECK-NEXT: const literal_array : [3]f32 = [3]f32 { 1.2, 2.3, 3.4 };
// CHECK-NEXT: var uninit_ptr : [*]f32 = &uninit_array;
// CHECK-NEXT: var global_ptr : [*]f32 = &global_array;
// CHECK-NEXT: const const_ptr : [*]const i32 = &const_array;
Expand Down
2 changes: 2 additions & 0 deletions xdsl/backend/csl/print_csl.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,8 @@ def attribute_value_to_str(self, attr: Attribute) -> str:
return str(val.data)
case StringAttr() as s:
return f'"{s.data}"'
case DenseIntOrFPElementsAttr(data=ArrayAttr(data=data), type=typ):
return f"{self.mlir_type_to_csl_type(typ)} {{ {', '.join(self.attribute_value_to_str(d) for d in data)} }}"
case _:
return f"<!unknown value {attr}>"

Expand Down

0 comments on commit d1f33aa

Please sign in to comment.