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: (x86) - mem access helper #2537

Merged
merged 2 commits into from
May 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 28 additions & 72 deletions xdsl/dialects/x86/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,9 @@ def __init__(
)

def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
return self.r1, self.r2
memory_access = _memory_access_str(self.r2, self.offset)
destination = _assembly_arg_str(self.r1)
return (destination, memory_access)

@classmethod
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
Expand All @@ -508,27 +510,6 @@ def custom_print_attributes(self, printer: Printer) -> Set[str]:
_print_immediate_value(printer, self.offset)
return {"offset"}

def assembly_line(self) -> str | None:
instruction_name = self.assembly_instruction_name()
destination = _assembly_arg_str(self.r1)
source = _assembly_arg_str(self.r2)
if self.offset is not None:
offset = _assembly_arg_str(self.offset)
if self.offset.value.data > 0:
return _assembly_line(
instruction_name,
f"{destination}, [{source}+{offset}]",
self.comment,
)
else:
return _assembly_line(
instruction_name, f"{destination}, [{source}{offset}]", self.comment
)
else:
return _assembly_line(
instruction_name, f"{destination}, [{source}]", self.comment
)


@irdl_op_definition
class RM_AddOp(RMOperation[GeneralRegisterType, GeneralRegisterType]):
Expand Down Expand Up @@ -758,16 +739,8 @@ def __init__(
)

def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
destination = _assembly_arg_str(self.r1)
if self.offset is not None:
offset = _assembly_arg_str(self.offset)
if self.offset.value.data > 0:
destination = f"[{destination}+{offset}]"
else:
destination = f"[{destination}{offset}]"
else:
destination = f"[{destination}]"
return destination, self.r2
memory_access = _memory_access_str(self.r1, self.offset)
return memory_access, self.r2

@classmethod
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
Expand Down Expand Up @@ -889,17 +862,9 @@ def __init__(
)

def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
destination = _assembly_arg_str(self.r1)
immediate = _assembly_arg_str(self.immediate)
if self.offset is not None:
offset = _assembly_arg_str(self.offset)
if self.offset.value.data > 0:
destination = f"[{destination}+{offset}]"
else:
destination = f"[{destination}{offset}]"
else:
destination = f"[{destination}]"
return destination, immediate
memory_access = _memory_access_str(self.r1, self.offset)
return memory_access, immediate

@classmethod
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
Expand Down Expand Up @@ -1091,17 +1056,9 @@ def __init__(

def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
destination = _assembly_arg_str(self.r1)
source = _assembly_arg_str(self.r2)
immediate = _assembly_arg_str(self.immediate)
if self.offset is not None:
offset = _assembly_arg_str(self.offset)
if self.offset.value.data > 0:
source = f"[{source}+{offset}]"
else:
source = f"[{source}{offset}]"
else:
source = f"[{source}]"
return destination, source, immediate
memory_access = _memory_access_str(self.r2, self.offset)
return destination, memory_access, immediate

@classmethod
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
Expand Down Expand Up @@ -1170,16 +1127,8 @@ def __init__(
)

def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
source = _assembly_arg_str(self.source)
if self.offset is not None:
offset = _assembly_arg_str(self.offset)
if self.offset.value.data > 0:
source = f"[{source}+{offset}]"
else:
source = f"[{source}{offset}]"
else:
source = f"[{source}]"
return (source,)
memory_access = _memory_access_str(self.source, self.offset)
return (memory_access,)

@classmethod
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
Expand Down Expand Up @@ -1228,16 +1177,8 @@ def __init__(
)

def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
source = _assembly_arg_str(self.source)
if self.offset is not None:
offset = _assembly_arg_str(self.offset)
if self.offset.value.data > 0:
source = f"[{source}+{offset}]"
else:
source = f"[{source}{offset}]"
else:
source = f"[{source}]"
return (source,)
memory_access = _memory_access_str(self.source, self.offset)
return (memory_access,)

@classmethod
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
Expand Down Expand Up @@ -1362,6 +1303,21 @@ def _print_immediate_value(printer: Printer, immediate: AnyIntegerAttr | LabelAt
printer.print_string_literal(immediate.data)


def _memory_access_str(
register: AssemblyInstructionArg, offset: AnyIntegerAttr | None
) -> str:
register_str = _assembly_arg_str(register)
if offset is not None:
offset_str = _assembly_arg_str(offset)
if offset.value.data > 0:
mem_acc_str = f"[{register_str}+{offset_str}]"
else:
mem_acc_str = f"[{register_str}{offset_str}]"
else:
mem_acc_str = f"[{register_str}]"
return mem_acc_str


# endregion


Expand Down
Loading