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

backend: (x86) Fix register sets test coverage #3866

Merged
merged 6 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions tests/dialects/test_x86.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
from xdsl.dialects import x86


def test_unallocated_register():
unallocated = x86.register.GeneralRegisterType("")
assert not unallocated.is_allocated
assert unallocated == x86.register.GeneralRegisterType.unallocated()

unallocated = x86.register.RFLAGSRegisterType("")
assert not unallocated.is_allocated
assert unallocated == x86.register.RFLAGSRegisterType.unallocated()

unallocated = x86.register.AVXRegisterType("")
assert not unallocated.is_allocated
assert unallocated == x86.register.AVXRegisterType.unallocated()


@pytest.mark.parametrize(
"register, name",
[
Expand All @@ -28,6 +42,8 @@ def test_register(register: x86.register.GeneralRegisterType, name: str):
assert register.is_allocated
assert register.register_name == name

assert register.instruction_set_name() == "x86"


def test_rflags_register():
rflags = x86.register.RFLAGS
Expand Down Expand Up @@ -75,3 +91,5 @@ def test_rflags_register():
def test_avx_register(register: x86.register.AVXRegisterType, name: str):
assert register.is_allocated
assert register.register_name == name

assert register.instruction_set_name() == "x86AVX"
9 changes: 9 additions & 0 deletions tests/filecheck/dialects/x86/x86_registers_invalid.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: xdsl-opt %s --split-input-file --verify-diagnostics | filecheck %s

// CHECK: foo not in x86
"test.op"() { reg = !x86.reg<foo> } : () -> ()

// -----

// CHECK: foo not in x86AVX
"test.op"() { reg = !x86.avxreg<foo> } : () -> ()
4 changes: 1 addition & 3 deletions xdsl/dialects/x86/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ def parse_parameters(cls, parser: AttrParser) -> Sequence[Attribute]:
if parser.parse_optional_punctuation("<") is not None:
name = parser.parse_identifier()
parser.parse_punctuation(">")
if not name.startswith("e") and not name.startswith("r"):
assert name in cls.abi_index_by_name(), f"{name}"
else:
name = ""
return cls._parameters_from_spelling(name)

def verify(self) -> None:
name = self.spelling.data
if not self.is_allocated or name.startswith("e") or name.startswith("r"):
if not self.is_allocated:
return
if name not in type(self).abi_index_by_name():
raise VerifyException(f"{name} not in {self.instruction_set_name()}")
Expand Down
7 changes: 6 additions & 1 deletion xdsl/tools/command_line_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from xdsl.dialects import get_all_dialects
from xdsl.dialects.builtin import ModuleOp
from xdsl.parser import Parser
from xdsl.utils.exceptions import ParseError
from xdsl.utils.exceptions import DiagnosticException, ParseError
from xdsl.utils.lexer import Span


Expand Down Expand Up @@ -117,5 +117,10 @@ def parse_chunk(
print(e)
else:
raise
except DiagnosticException as e:
if self.args.verify_diagnostics:
print(e)
else:
raise
finally:
chunk.close()