-
Notifications
You must be signed in to change notification settings - Fork 86
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
[WIP]: Initialise arm_cf and begin beq implementation #3760
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// RUN: XDSL_ROUNDTRIP | ||
// RUN: XDSL_GENERIC_ROUNDTRIP | ||
// RUN: xdsl-opt -t arm-asm %s | filecheck %s --check-prefix=CHECK-ASM | ||
|
||
// CHECK: %x1 = arm.get_register : !arm.reg<x1> | ||
%x1 = arm.get_register : !arm.reg<x1> | ||
|
||
// CHECK: %x2 = arm.get_register : !arm.reg<x2> | ||
%x2 = arm.get_register : !arm.reg<x2> | ||
|
||
// CHECK: arm.label "testlabel" {comment = "this is a label"} | ||
// CHECK-ASM: testlabel: # this is a label | ||
arm.label "testlabel" {comment = "this is a label"} | ||
|
||
// CHECK-NEXT: arm_cf.beq %x1, %x2, ^testlabel | ||
// CHECK-ASM: arm_cf.beq x1, x2, ^testlabel | ||
arm_cf.beq %x1, %x2, ^testlabel : (!arm.reg<x1>, !arm.reg<x2>) | ||
|
||
// CHECK-GENERIC: "arm.label"() <{label = "testlabel"}> {comment = "this is a label"} : () -> () |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,65 @@ | ||||||
from xdsl.dialects import arm | ||||||
from xdsl.dialects.builtin import StringAttr | ||||||
from xdsl.interpreter import Successor | ||||||
from xdsl.ir import Dialect, Operation, SSAValue | ||||||
from xdsl.irdl import ( | ||||||
irdl_op_definition, | ||||||
operand_def, | ||||||
successor_def, | ||||||
traits_def, | ||||||
) | ||||||
from xdsl.traits import IsTerminator | ||||||
|
||||||
|
||||||
@irdl_op_definition | ||||||
class BEqOp(arm.ops.ARMInstruction): | ||||||
""" | ||||||
Branch if equal | ||||||
https://developer.arm.com/documentation/den0042/a/Unified-Assembly-Language-Instructions/Instruction-set-basics/Conditional-execution | ||||||
""" | ||||||
|
||||||
name = "arm_cf.beq" | ||||||
s1 = operand_def(arm.register.IntRegisterType) | ||||||
s2 = operand_def(arm.register.IntRegisterType) | ||||||
|
||||||
then_block = successor_def() | ||||||
|
||||||
traits = traits_def( | ||||||
IsTerminator(), | ||||||
) | ||||||
|
||||||
assembly_format = ( | ||||||
"$s1 `,` $s2 `,` $then_block attr-dict `:` `(` type($s1) `,` type($s2) `)`" | ||||||
) | ||||||
|
||||||
def __init__( | ||||||
self, | ||||||
s1: Operation | SSAValue, | ||||||
s2: Operation | SSAValue, | ||||||
then_block: Successor, | ||||||
*, | ||||||
comment: str | StringAttr | None = None, | ||||||
): | ||||||
if isinstance(comment, str): | ||||||
comment = StringAttr(comment) | ||||||
|
||||||
super().__init__( | ||||||
operands=[s1, s2], | ||||||
attributes={ | ||||||
"comment": comment, | ||||||
}, | ||||||
successors=(then_block), | ||||||
) | ||||||
|
||||||
def assembly_line_args(self): | ||||||
then_label = self.then_block.first_op | ||||||
assert isinstance(then_label, arm.ops.LabelOp) | ||||||
return (self.s1, self.s2, then_label.label.data) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to allow both str and StringAttr here
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be great to address this before merging, I'm actually leaning towards not allowing strings here at all, requiring the label attribute directly. |
||||||
|
||||||
|
||||||
ARM_CF = Dialect( | ||||||
"arm_cf", | ||||||
[ | ||||||
BEqOp, | ||||||
], | ||||||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the issue is you've that you've referred to a block that doesn't exist
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good opportunity to fix the error message in a separate PR!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR for fixing error message: #3762