From 2f8e98c7d8e55277947996ff93a1858b59ad406c Mon Sep 17 00:00:00 2001 From: emmau678 Date: Mon, 13 Jan 2025 15:39:03 +0000 Subject: [PATCH 01/12] Revert "dialects (arm): add LabelAttr (#3745)" This reverts commit 64f809b755f165adc19c4502522e1f8d63b2a94d. --- xdsl/dialects/arm/assembly.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/xdsl/dialects/arm/assembly.py b/xdsl/dialects/arm/assembly.py index 2ae9e20380..f38c901089 100644 --- a/xdsl/dialects/arm/assembly.py +++ b/xdsl/dialects/arm/assembly.py @@ -4,7 +4,7 @@ from xdsl.dialects.builtin import StringAttr from xdsl.ir import SSAValue -AssemblyInstructionArg: TypeAlias = ARMRegisterType | SSAValue +AssemblyInstructionArg: TypeAlias = SSAValue def append_comment(line: str, comment: StringAttr | None) -> str: @@ -17,15 +17,11 @@ def append_comment(line: str, comment: StringAttr | None) -> str: def assembly_arg_str(arg: AssemblyInstructionArg) -> str: - if isinstance(arg, ARMRegisterType): - reg = arg.register_name + if isinstance(arg.type, ARMRegisterType): + reg = arg.type.register_name return reg - else: # SSAValue - if isinstance(arg.type, ARMRegisterType): - reg = arg.type.register_name - return reg - else: - raise ValueError(f"Unexpected argument type {type(arg)}") + else: + raise ValueError(f"Unexpected register type {arg.type}") def assembly_line( From 7b4ddccc13f68167893043ce6f4debe526082a57 Mon Sep 17 00:00:00 2001 From: emmau678 Date: Mon, 13 Jan 2025 15:58:52 +0000 Subject: [PATCH 02/12] Keep update to assembly_arg_str and unit tests --- xdsl/dialects/arm/assembly.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/xdsl/dialects/arm/assembly.py b/xdsl/dialects/arm/assembly.py index f38c901089..2ae9e20380 100644 --- a/xdsl/dialects/arm/assembly.py +++ b/xdsl/dialects/arm/assembly.py @@ -4,7 +4,7 @@ from xdsl.dialects.builtin import StringAttr from xdsl.ir import SSAValue -AssemblyInstructionArg: TypeAlias = SSAValue +AssemblyInstructionArg: TypeAlias = ARMRegisterType | SSAValue def append_comment(line: str, comment: StringAttr | None) -> str: @@ -17,11 +17,15 @@ def append_comment(line: str, comment: StringAttr | None) -> str: def assembly_arg_str(arg: AssemblyInstructionArg) -> str: - if isinstance(arg.type, ARMRegisterType): - reg = arg.type.register_name + if isinstance(arg, ARMRegisterType): + reg = arg.register_name return reg - else: - raise ValueError(f"Unexpected register type {arg.type}") + else: # SSAValue + if isinstance(arg.type, ARMRegisterType): + reg = arg.type.register_name + return reg + else: + raise ValueError(f"Unexpected argument type {type(arg)}") def assembly_line( From 967d56c70df3c7580f86dea45d65fcb822af8199 Mon Sep 17 00:00:00 2001 From: emmau678 Date: Mon, 13 Jan 2025 16:59:05 +0000 Subject: [PATCH 03/12] dialects (arm): add LabelOp --- tests/filecheck/dialects/arm/test_ops.mlir | 5 +++ uv.lock | 2 +- xdsl/dialects/arm/__init__.py | 3 +- xdsl/dialects/arm/ops.py | 40 ++++++++++++++++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/tests/filecheck/dialects/arm/test_ops.mlir b/tests/filecheck/dialects/arm/test_ops.mlir index 0f3f0a5e86..5d691de293 100644 --- a/tests/filecheck/dialects/arm/test_ops.mlir +++ b/tests/filecheck/dialects/arm/test_ops.mlir @@ -17,6 +17,11 @@ // CHECK-ASM: mul x3, x1, x2 # multiply s1 by s2 %dss_mul = arm.dss.mul %x1, %x2 {"comment" = "multiply s1 by s2"} : (!arm.reg, !arm.reg) -> !arm.reg +// CHECK-NEXT: arm.label {"label" = "testlabel", "comment" = "this is a label"} +// CHECK-ASM: testlabel # this is a label +arm.label {"label" = "testlabel", "comment" = "this is a label"} + // CHECK-GENERIC: %x1 = "arm.get_register"() : () -> !arm.reg // CHECK-GENERIC: %ds_mov = "arm.ds.mov"(%x1) {comment = "move contents of s to d"} : (!arm.reg) -> !arm.reg // CHECK-GENERIC: %dss_mul = "arm.dss.mul"(%x1, %x2) {comment = "multiply s1 by s2"} : (!arm.reg, !arm.reg) -> !arm.reg +// CHECK-GENERIC: "arm.label"() {label = "testlabel", comment = "this is a label"} : () -> () diff --git a/uv.lock b/uv.lock index c7a8751286..832c39ca5f 100644 --- a/uv.lock +++ b/uv.lock @@ -2459,7 +2459,7 @@ wheels = [ [[package]] name = "xdsl" -version = "0+dynamic" +version = "0.26+59.gbd3e3099.dirty" source = { editable = "." } dependencies = [ { name = "immutabledict" }, diff --git a/xdsl/dialects/arm/__init__.py b/xdsl/dialects/arm/__init__.py index dbb2afbdba..9e2be4e784 100644 --- a/xdsl/dialects/arm/__init__.py +++ b/xdsl/dialects/arm/__init__.py @@ -8,7 +8,7 @@ from xdsl.dialects.builtin import ModuleOp from xdsl.ir import Dialect -from .ops import ARMOperation, DSMovOp, DSSMulOp, GetRegisterOp +from .ops import ARMOperation, DSMovOp, DSSMulOp, GetRegisterOp, LabelOp from .register import IntRegisterType @@ -26,6 +26,7 @@ def print_assembly(module: ModuleOp, output: IO[str]) -> None: GetRegisterOp, DSMovOp, DSSMulOp, + LabelOp, ], [ IntRegisterType, diff --git a/xdsl/dialects/arm/ops.py b/xdsl/dialects/arm/ops.py index d942dc2943..d4c89fc851 100644 --- a/xdsl/dialects/arm/ops.py +++ b/xdsl/dialects/arm/ops.py @@ -4,6 +4,7 @@ from xdsl.ir import Operation, SSAValue from xdsl.irdl import ( IRDLOperation, + attr_def, irdl_op_definition, operand_def, opt_attr_def, @@ -154,3 +155,42 @@ def __init__( def assembly_line_args(self): return (self.d, self.s1, self.s2) + + +@irdl_op_definition +class LabelOp(ARMOperation): + """ + The label operation is used to emit text labels (e.g. loop:) that are used + as branch, unconditional jump targets and symbol offsets. + https://developer.arm.com/documentation/dui0801/l/Symbols--Literals--Expressions--and-Operators/Labels + """ + + name = "arm.label" + label = attr_def(StringAttr) + comment = opt_attr_def(StringAttr) + + assembly_format = "attr-dict" + + def __init__( + self, + label: str | StringAttr, + *, + comment: str | StringAttr | None = None, + ): + if isinstance(label, str): + label = StringAttr(label) + if isinstance(comment, str): + comment = StringAttr(comment) + + super().__init__( + attributes={ + "label": label, + "comment": comment, + }, + ) + + def assembly_line_args(self): + return () + + def assembly_instruction_name(self) -> str: + return self.label.data From eebb872db3553c1ef857ed6c044957afa60448d7 Mon Sep 17 00:00:00 2001 From: Emma Urquhart <77412390+emmau678@users.noreply.github.com> Date: Tue, 14 Jan 2025 09:38:56 +0000 Subject: [PATCH 04/12] Update tests/filecheck/dialects/arm/test_ops.mlir Co-authored-by: Sasha Lopoukhine --- tests/filecheck/dialects/arm/test_ops.mlir | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/filecheck/dialects/arm/test_ops.mlir b/tests/filecheck/dialects/arm/test_ops.mlir index 5d691de293..0660157ad1 100644 --- a/tests/filecheck/dialects/arm/test_ops.mlir +++ b/tests/filecheck/dialects/arm/test_ops.mlir @@ -19,7 +19,7 @@ // CHECK-NEXT: arm.label {"label" = "testlabel", "comment" = "this is a label"} // CHECK-ASM: testlabel # this is a label -arm.label {"label" = "testlabel", "comment" = "this is a label"} +arm.label "testlabel" {comment = "this is a label"} // CHECK-GENERIC: %x1 = "arm.get_register"() : () -> !arm.reg // CHECK-GENERIC: %ds_mov = "arm.ds.mov"(%x1) {comment = "move contents of s to d"} : (!arm.reg) -> !arm.reg From 9f6845029cdd53f8922c9ec39ecffa8f1a4439c1 Mon Sep 17 00:00:00 2001 From: Emma Urquhart <77412390+emmau678@users.noreply.github.com> Date: Tue, 14 Jan 2025 09:39:08 +0000 Subject: [PATCH 05/12] Update xdsl/dialects/arm/ops.py Co-authored-by: Sasha Lopoukhine --- xdsl/dialects/arm/ops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xdsl/dialects/arm/ops.py b/xdsl/dialects/arm/ops.py index d4c89fc851..33178f6cfd 100644 --- a/xdsl/dialects/arm/ops.py +++ b/xdsl/dialects/arm/ops.py @@ -166,7 +166,7 @@ class LabelOp(ARMOperation): """ name = "arm.label" - label = attr_def(StringAttr) + label = prop_def(StringAttr) comment = opt_attr_def(StringAttr) assembly_format = "attr-dict" From 72b9e89c44881169bcf9f9211c7fe1e975aa24d8 Mon Sep 17 00:00:00 2001 From: Emma Urquhart <77412390+emmau678@users.noreply.github.com> Date: Tue, 14 Jan 2025 09:39:13 +0000 Subject: [PATCH 06/12] Update xdsl/dialects/arm/ops.py Co-authored-by: Sasha Lopoukhine --- xdsl/dialects/arm/ops.py | 1 - 1 file changed, 1 deletion(-) diff --git a/xdsl/dialects/arm/ops.py b/xdsl/dialects/arm/ops.py index 33178f6cfd..2b812e50b0 100644 --- a/xdsl/dialects/arm/ops.py +++ b/xdsl/dialects/arm/ops.py @@ -167,7 +167,6 @@ class LabelOp(ARMOperation): name = "arm.label" label = prop_def(StringAttr) - comment = opt_attr_def(StringAttr) assembly_format = "attr-dict" From 3fd1b0b05a557b2c292fbb20421a396d02a0e1a3 Mon Sep 17 00:00:00 2001 From: Emma Urquhart <77412390+emmau678@users.noreply.github.com> Date: Tue, 14 Jan 2025 09:39:24 +0000 Subject: [PATCH 07/12] Update xdsl/dialects/arm/ops.py Co-authored-by: Sasha Lopoukhine --- xdsl/dialects/arm/ops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xdsl/dialects/arm/ops.py b/xdsl/dialects/arm/ops.py index 2b812e50b0..587aab536c 100644 --- a/xdsl/dialects/arm/ops.py +++ b/xdsl/dialects/arm/ops.py @@ -168,7 +168,7 @@ class LabelOp(ARMOperation): name = "arm.label" label = prop_def(StringAttr) - assembly_format = "attr-dict" + assembly_format = "$label attr-dict" def __init__( self, From ff05f34a993fbf5f189cc41086f44cba138d014b Mon Sep 17 00:00:00 2001 From: Emma Urquhart <77412390+emmau678@users.noreply.github.com> Date: Tue, 14 Jan 2025 09:39:45 +0000 Subject: [PATCH 08/12] Update xdsl/dialects/arm/ops.py Co-authored-by: Sasha Lopoukhine --- xdsl/dialects/arm/ops.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/xdsl/dialects/arm/ops.py b/xdsl/dialects/arm/ops.py index 587aab536c..8f2c9ea651 100644 --- a/xdsl/dialects/arm/ops.py +++ b/xdsl/dialects/arm/ops.py @@ -188,8 +188,5 @@ def __init__( }, ) - def assembly_line_args(self): - return () - - def assembly_instruction_name(self) -> str: - return self.label.data + def assembly_line(self) -> str | None: + return append_comment(f"{self.label.data}:", self.comment) From f390e8c77e81ac6f3094dfda4b3907bb5440f977 Mon Sep 17 00:00:00 2001 From: emmau678 Date: Tue, 14 Jan 2025 10:43:35 +0000 Subject: [PATCH 09/12] add required imports --- xdsl/dialects/arm/ops.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/xdsl/dialects/arm/ops.py b/xdsl/dialects/arm/ops.py index 8f2c9ea651..687cd32d77 100644 --- a/xdsl/dialects/arm/ops.py +++ b/xdsl/dialects/arm/ops.py @@ -4,14 +4,19 @@ from xdsl.ir import Operation, SSAValue from xdsl.irdl import ( IRDLOperation, - attr_def, irdl_op_definition, operand_def, opt_attr_def, + prop_def, result_def, ) -from .assembly import AssemblyInstructionArg, assembly_arg_str, assembly_line +from .assembly import ( + AssemblyInstructionArg, + append_comment, + assembly_arg_str, + assembly_line, +) from .register import IntRegisterType @@ -167,6 +172,7 @@ class LabelOp(ARMOperation): name = "arm.label" label = prop_def(StringAttr) + comment = opt_attr_def(StringAttr) assembly_format = "$label attr-dict" From 3c151473a3a2b784aa16eedc2606a9e728ebc1d8 Mon Sep 17 00:00:00 2001 From: emmau678 Date: Tue, 14 Jan 2025 13:11:29 +0000 Subject: [PATCH 10/12] minor update to filecheck --- tests/filecheck/dialects/arm/test_ops.mlir | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/filecheck/dialects/arm/test_ops.mlir b/tests/filecheck/dialects/arm/test_ops.mlir index 0660157ad1..403e0af6b0 100644 --- a/tests/filecheck/dialects/arm/test_ops.mlir +++ b/tests/filecheck/dialects/arm/test_ops.mlir @@ -17,7 +17,7 @@ // CHECK-ASM: mul x3, x1, x2 # multiply s1 by s2 %dss_mul = arm.dss.mul %x1, %x2 {"comment" = "multiply s1 by s2"} : (!arm.reg, !arm.reg) -> !arm.reg -// CHECK-NEXT: arm.label {"label" = "testlabel", "comment" = "this is a label"} +// CHECK-NEXT: arm.label "testlabel" {"comment" = "this is a label"} // CHECK-ASM: testlabel # this is a label arm.label "testlabel" {comment = "this is a label"} From 2513e2ed6121c2f875231dfd332e132e3ced7c75 Mon Sep 17 00:00:00 2001 From: emmau678 Date: Tue, 14 Jan 2025 13:17:26 +0000 Subject: [PATCH 11/12] debug filecheck issues --- tests/filecheck/dialects/arm/test_ops.mlir | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/filecheck/dialects/arm/test_ops.mlir b/tests/filecheck/dialects/arm/test_ops.mlir index 403e0af6b0..82cd85099d 100644 --- a/tests/filecheck/dialects/arm/test_ops.mlir +++ b/tests/filecheck/dialects/arm/test_ops.mlir @@ -17,11 +17,11 @@ // CHECK-ASM: mul x3, x1, x2 # multiply s1 by s2 %dss_mul = arm.dss.mul %x1, %x2 {"comment" = "multiply s1 by s2"} : (!arm.reg, !arm.reg) -> !arm.reg -// CHECK-NEXT: arm.label "testlabel" {"comment" = "this is a label"} -// CHECK-ASM: testlabel # this is a label +// CHECK-NEXT: arm.label "testlabel" {comment = "this is a label"} +// CHECK-ASM: testlabel: # this is a label arm.label "testlabel" {comment = "this is a label"} // CHECK-GENERIC: %x1 = "arm.get_register"() : () -> !arm.reg // CHECK-GENERIC: %ds_mov = "arm.ds.mov"(%x1) {comment = "move contents of s to d"} : (!arm.reg) -> !arm.reg // CHECK-GENERIC: %dss_mul = "arm.dss.mul"(%x1, %x2) {comment = "multiply s1 by s2"} : (!arm.reg, !arm.reg) -> !arm.reg -// CHECK-GENERIC: "arm.label"() {label = "testlabel", comment = "this is a label"} : () -> () +// CHECK-GENERIC: "arm.label"() <{label = "testlabel"}> {comment = "this is a label"} : () -> () From 6ec86599be43d9309ce77146b8a31c4970c088e6 Mon Sep 17 00:00:00 2001 From: emmau678 Date: Tue, 14 Jan 2025 13:29:05 +0000 Subject: [PATCH 12/12] revert changes to lockfile --- uv.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uv.lock b/uv.lock index 832c39ca5f..c7a8751286 100644 --- a/uv.lock +++ b/uv.lock @@ -2459,7 +2459,7 @@ wheels = [ [[package]] name = "xdsl" -version = "0.26+59.gbd3e3099.dirty" +version = "0+dynamic" source = { editable = "." } dependencies = [ { name = "immutabledict" },