Skip to content

Commit

Permalink
dialects (arm): add return instruction (bx lr) (#3521)
Browse files Browse the repository at this point in the history
Add a return instruction which is equivalent to ```bx lr```

---------

Co-authored-by: emmau678 <eu233@Emma-laptop>
  • Loading branch information
emmau678 and emmau678 authored Nov 27, 2024
1 parent dcc1239 commit 6f203de
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/filecheck/dialects/arm_func/test_ops.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: XDSL_ROUNDTRIP
// RUN: XDSL_GENERIC_ROUNDTRIP
// RUN: xdsl-opt -t arm-asm %s | filecheck %s --check-prefix=CHECK-ASM

// CHECK: arm_func.return {"comment" = "this is a return instruction"}
// CHECK-ASM: bx lr # this is a return instruction
arm_func.return {"comment" = "this is a return instruction"}

// CHECK-GENERIC: "arm_func.return"() {"comment" = "this is a return instruction"} : () -> ()
6 changes: 6 additions & 0 deletions xdsl/dialects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ def get_arm():

return ARM

def get_arm_func():
from xdsl.dialects.arm_func import ARM_FUNC

return ARM_FUNC

def get_bufferization():
from xdsl.dialects.bufferization import Bufferization

Expand Down Expand Up @@ -335,6 +340,7 @@ def get_transform():
"air": get_air,
"arith": get_arith,
"arm": get_arm,
"arm_func": get_arm_func,
"bufferization": get_bufferization,
"builtin": get_builtin,
"cf": get_cf,
Expand Down
51 changes: 51 additions & 0 deletions xdsl/dialects/arm_func.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from xdsl.dialects import arm
from xdsl.dialects.builtin import StringAttr
from xdsl.ir import Dialect
from xdsl.irdl import (
irdl_op_definition,
traits_def,
)
from xdsl.traits import IsTerminator


@irdl_op_definition
class RetOp(arm.ops.ARMInstruction):
"""
Return from subroutine.
Equivalent to `bx lr`
"""

name = "arm_func.return"

assembly_format = "attr-dict"

traits = traits_def(IsTerminator())

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

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

def assembly_line_args(self):
return ()

def assembly_instruction_name(self) -> str:
return "bx lr"


ARM_FUNC = Dialect(
"arm_func",
[
RetOp,
],
)

0 comments on commit 6f203de

Please sign in to comment.