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

dialects (arm): Add LabelOp #3749

Merged
merged 12 commits into from
Jan 14, 2025
5 changes: 5 additions & 0 deletions tests/filecheck/dialects/arm/test_ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -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<x1>, !arm.reg<x2>) -> !arm.reg<x3>

// 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"}
emmau678 marked this conversation as resolved.
Show resolved Hide resolved

// CHECK-GENERIC: %x1 = "arm.get_register"() : () -> !arm.reg<x1>
// CHECK-GENERIC: %ds_mov = "arm.ds.mov"(%x1) {comment = "move contents of s to d"} : (!arm.reg<x1>) -> !arm.reg<x2>
// CHECK-GENERIC: %dss_mul = "arm.dss.mul"(%x1, %x2) {comment = "multiply s1 by s2"} : (!arm.reg<x1>, !arm.reg<x2>) -> !arm.reg<x3>
// CHECK-GENERIC: "arm.label"() {label = "testlabel", comment = "this is a label"} : () -> ()
2 changes: 1 addition & 1 deletion uv.lock
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please revert

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted, thanks

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion xdsl/dialects/arm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -26,6 +26,7 @@ def print_assembly(module: ModuleOp, output: IO[str]) -> None:
GetRegisterOp,
DSMovOp,
DSSMulOp,
LabelOp,
],
[
IntRegisterType,
Expand Down
40 changes: 40 additions & 0 deletions xdsl/dialects/arm/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
emmau678 marked this conversation as resolved.
Show resolved Hide resolved
comment = opt_attr_def(StringAttr)
emmau678 marked this conversation as resolved.
Show resolved Hide resolved

assembly_format = "attr-dict"
emmau678 marked this conversation as resolved.
Show resolved Hide resolved

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
emmau678 marked this conversation as resolved.
Show resolved Hide resolved
Loading