Skip to content

Ops

ops

ARMAsmOperation dataclass

Bases: IRDLOperation, OneLineAssemblyPrintable, ABC

Base class for operations that can be a part of ARM assembly printing.

Source code in xdsl/dialects/arm/ops.py
18
19
20
21
class ARMAsmOperation(IRDLOperation, OneLineAssemblyPrintable, ABC):
    """
    Base class for operations that can be a part of ARM assembly printing.
    """

ARMInstruction dataclass

Bases: ARMAsmOperation, ABC

Base class for operations that can be a part of x86 assembly printing. Must represent an instruction in the x86 instruction set. The name of the operation will be used as the x86 assembly instruction name.

Source code in xdsl/dialects/arm/ops.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class ARMInstruction(ARMAsmOperation, ABC):
    """
    Base class for operations that can be a part of x86 assembly printing. Must
    represent an instruction in the x86 instruction set.
    The name of the operation will be used as the x86 assembly instruction name.
    """

    comment = opt_attr_def(StringAttr)
    """
    An optional comment that will be printed along with the instruction.
    """

    @abstractmethod
    def assembly_line_args(self) -> tuple[str | None, ...]:
        """
        The arguments to the instruction, in the order they should be printed in the
        assembly.
        """
        raise NotImplementedError()

    def assembly_instruction_name(self) -> str:
        """
        By default, the name of the instruction is the same as the name of the operation.
        """

        return self.name.split(".")[-1]

    def assembly_line(self) -> str | None:
        # default assembly code generator
        instruction_name = self.assembly_instruction_name()
        arg_str = ", ".join(arg for arg in self.assembly_line_args() if arg is not None)
        return AssemblyPrinter.assembly_line(instruction_name, arg_str, self.comment)

comment = opt_attr_def(StringAttr) class-attribute instance-attribute

An optional comment that will be printed along with the instruction.

assembly_line_args() -> tuple[str | None, ...] abstractmethod

The arguments to the instruction, in the order they should be printed in the assembly.

Source code in xdsl/dialects/arm/ops.py
36
37
38
39
40
41
42
@abstractmethod
def assembly_line_args(self) -> tuple[str | None, ...]:
    """
    The arguments to the instruction, in the order they should be printed in the
    assembly.
    """
    raise NotImplementedError()

assembly_instruction_name() -> str

By default, the name of the instruction is the same as the name of the operation.

Source code in xdsl/dialects/arm/ops.py
44
45
46
47
48
49
def assembly_instruction_name(self) -> str:
    """
    By default, the name of the instruction is the same as the name of the operation.
    """

    return self.name.split(".")[-1]

assembly_line() -> str | None

Source code in xdsl/dialects/arm/ops.py
51
52
53
54
55
def assembly_line(self) -> str | None:
    # default assembly code generator
    instruction_name = self.assembly_instruction_name()
    arg_str = ", ".join(arg for arg in self.assembly_line_args() if arg is not None)
    return AssemblyPrinter.assembly_line(instruction_name, arg_str, self.comment)

DSMovOp

Bases: ARMInstruction

Copies the value of s into d.

See external documentation.

Source code in xdsl/dialects/arm/ops.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
@irdl_op_definition
class DSMovOp(ARMInstruction):
    """
    Copies the value of s into d.

    See external [documentation](https://developer.arm.com/documentation/dui0473/m/arm-and-thumb-instructions/mov).
    """

    name = "arm.ds.mov"

    d = result_def(IntRegisterType)
    s = operand_def(IntRegisterType)
    assembly_format = "$s attr-dict `:` `(` type($s) `)` `->` type($d)"

    def __init__(
        self,
        d: IntRegisterType,
        s: Operation | SSAValue,
        *,
        comment: str | StringAttr | None = None,
    ):
        if isinstance(comment, str):
            comment = StringAttr(comment)

        super().__init__(
            operands=(s,),
            attributes={
                "comment": comment,
            },
            result_types=(d,),
        )

    def assembly_line_args(self):
        return (reg(self.d), reg(self.s))

name = 'arm.ds.mov' class-attribute instance-attribute

d = result_def(IntRegisterType) class-attribute instance-attribute

s = operand_def(IntRegisterType) class-attribute instance-attribute

assembly_format = '$s attr-dict `:` `(` type($s) `)` `->` type($d)' class-attribute instance-attribute

__init__(d: IntRegisterType, s: Operation | SSAValue, *, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/arm/ops.py
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
def __init__(
    self,
    d: IntRegisterType,
    s: Operation | SSAValue,
    *,
    comment: str | StringAttr | None = None,
):
    if isinstance(comment, str):
        comment = StringAttr(comment)

    super().__init__(
        operands=(s,),
        attributes={
            "comment": comment,
        },
        result_types=(d,),
    )

assembly_line_args()

Source code in xdsl/dialects/arm/ops.py
90
91
def assembly_line_args(self):
    return (reg(self.d), reg(self.s))

GetRegisterOp

Bases: ARMAsmOperation

This instruction allows us to create an SSAValue for a given register name.

Source code in xdsl/dialects/arm/ops.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
@irdl_op_definition
class GetRegisterOp(ARMAsmOperation):
    """
    This instruction allows us to create an SSAValue for a given register name.
    """

    name = "arm.get_register"

    result = result_def(IntRegisterType)
    assembly_format = "attr-dict `:` type($result)"

    def __init__(self, register_type: IntRegisterType):
        super().__init__(result_types=[register_type])

    def assembly_line(self):
        return None

name = 'arm.get_register' class-attribute instance-attribute

result = result_def(IntRegisterType) class-attribute instance-attribute

assembly_format = 'attr-dict `:` type($result)' class-attribute instance-attribute

__init__(register_type: IntRegisterType)

Source code in xdsl/dialects/arm/ops.py
105
106
def __init__(self, register_type: IntRegisterType):
    super().__init__(result_types=[register_type])

assembly_line()

Source code in xdsl/dialects/arm/ops.py
108
109
def assembly_line(self):
    return None

DSSMulOp

Bases: ARMInstruction

Multiplies the values in s1 and s2 and stores the result in d.

See external documentation.

Source code in xdsl/dialects/arm/ops.py
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
@irdl_op_definition
class DSSMulOp(ARMInstruction):
    """
    Multiplies the values in s1 and s2 and stores the result in d.

    See external [documentation](https://developer.arm.com/documentation/ddi0597/2024-06/Base-Instructions/MUL--MULS--Multiply-?lang=en).
    """

    name = "arm.dss.mul"

    d = result_def(IntRegisterType)
    s1 = operand_def(IntRegisterType)
    s2 = operand_def(IntRegisterType)
    assembly_format = (
        "$s1 `,` $s2 attr-dict `:` `(` type($s1) `,` type($s2) `)` `->` type($d)"
    )

    def __init__(
        self,
        s1: Operation | SSAValue,
        s2: Operation | SSAValue,
        *,
        d: IntRegisterType,
        comment: str | StringAttr | None = None,
    ):
        if isinstance(comment, str):
            comment = StringAttr(comment)

        super().__init__(
            operands=(s1, s2),
            attributes={
                "comment": comment,
            },
            result_types=(d,),
        )

    def assembly_line_args(self):
        return (reg(self.d), reg(self.s1), reg(self.s2))

name = 'arm.dss.mul' class-attribute instance-attribute

d = result_def(IntRegisterType) class-attribute instance-attribute

s1 = operand_def(IntRegisterType) class-attribute instance-attribute

s2 = operand_def(IntRegisterType) class-attribute instance-attribute

assembly_format = '$s1 `,` $s2 attr-dict `:` `(` type($s1) `,` type($s2) `)` `->` type($d)' class-attribute instance-attribute

__init__(s1: Operation | SSAValue, s2: Operation | SSAValue, *, d: IntRegisterType, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/arm/ops.py
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
def __init__(
    self,
    s1: Operation | SSAValue,
    s2: Operation | SSAValue,
    *,
    d: IntRegisterType,
    comment: str | StringAttr | None = None,
):
    if isinstance(comment, str):
        comment = StringAttr(comment)

    super().__init__(
        operands=(s1, s2),
        attributes={
            "comment": comment,
        },
        result_types=(d,),
    )

assembly_line_args()

Source code in xdsl/dialects/arm/ops.py
148
149
def assembly_line_args(self):
    return (reg(self.d), reg(self.s1), reg(self.s2))

LabelOp

Bases: ARMAsmOperation

The label operation is used to emit text labels (e.g. loop:) that are used as branch, unconditional jump targets and symbol offsets.

See external documentation.

Source code in xdsl/dialects/arm/ops.py
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
@irdl_op_definition
class LabelOp(ARMAsmOperation):
    """
    The label operation is used to emit text labels (e.g. loop:) that are used
    as branch, unconditional jump targets and symbol offsets.

    See external [documentation](https://developer.arm.com/documentation/dui0801/l/Symbols--Literals--Expressions--and-Operators/Labels).
    """

    name = "arm.label"
    label = prop_def(StringAttr)
    comment = opt_attr_def(StringAttr)

    assembly_format = "$label 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(self) -> str | None:
        return AssemblyPrinter.append_comment(f"{self.label.data}:", self.comment)

name = 'arm.label' class-attribute instance-attribute

label = prop_def(StringAttr) class-attribute instance-attribute

comment = opt_attr_def(StringAttr) class-attribute instance-attribute

assembly_format = '$label attr-dict' class-attribute instance-attribute

__init__(label: str | StringAttr, *, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/arm/ops.py
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
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,
        },
    )

assembly_line() -> str | None

Source code in xdsl/dialects/arm/ops.py
185
186
def assembly_line(self) -> str | None:
    return AssemblyPrinter.append_comment(f"{self.label.data}:", self.comment)

CmpRegOp

Bases: ARMInstruction

Compare (register) subtracts an optionally-shifted register value from a register value. It updates the condition flags based on the result, and discards the result.

See external documentation.

Source code in xdsl/dialects/arm/ops.py
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
@irdl_op_definition
class CmpRegOp(ARMInstruction):
    """
    Compare (register) subtracts an optionally-shifted register value from a register value.
    It updates the condition flags based on the result, and discards the result.

    See external [documentation](https://developer.arm.com/documentation/ddi0597/2024-12/Base-Instructions/CMP--register---Compare--register--?lang=en).
    """

    name = "arm.cmp"
    s1 = operand_def(IntRegisterType)
    s2 = operand_def(IntRegisterType)

    assembly_format = "$s1 `,` $s2 attr-dict `:` `(` type($s1) `,` type($s2) `)`"

    def __init__(
        self,
        s1: Operation | SSAValue,
        s2: Operation | SSAValue,
        *,
        comment: str | StringAttr | None = None,
    ):
        if isinstance(comment, str):
            comment = StringAttr(comment)

        super().__init__(
            operands=(s1, s2),
            attributes={
                "comment": comment,
            },
        )

    def assembly_line_args(self):
        return (reg(self.s1), reg(self.s2))

name = 'arm.cmp' class-attribute instance-attribute

s1 = operand_def(IntRegisterType) class-attribute instance-attribute

s2 = operand_def(IntRegisterType) class-attribute instance-attribute

assembly_format = '$s1 `,` $s2 attr-dict `:` `(` type($s1) `,` type($s2) `)`' class-attribute instance-attribute

__init__(s1: Operation | SSAValue, s2: Operation | SSAValue, *, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/arm/ops.py
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
def __init__(
    self,
    s1: Operation | SSAValue,
    s2: Operation | SSAValue,
    *,
    comment: str | StringAttr | None = None,
):
    if isinstance(comment, str):
        comment = StringAttr(comment)

    super().__init__(
        operands=(s1, s2),
        attributes={
            "comment": comment,
        },
    )

assembly_line_args()

Source code in xdsl/dialects/arm/ops.py
221
222
def assembly_line_args(self):
    return (reg(self.s1), reg(self.s2))