Skip to content

Commit

Permalink
dialects (arm): add LabelOp
Browse files Browse the repository at this point in the history
  • Loading branch information
emmau678 committed Jan 13, 2025
1 parent 7b4ddcc commit 967d56c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
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"}

// 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

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)
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

0 comments on commit 967d56c

Please sign in to comment.