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

dialect: Fix riscv verify #1271

Merged
merged 8 commits into from
Jul 17, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions tests/dialects/test_riscv.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,17 +232,17 @@ def test_immediate_shift_inst():
riscv.SlliOp(a1, (1 << 5) - 1, rd=riscv.Registers.A0)


def check_float_register():
with pytest.raises(VerifyException):
def test_float_register():
kingiler marked this conversation as resolved.
Show resolved Hide resolved
with pytest.raises(VerifyException, match="not in"):
riscv.RegisterType(riscv.Register("ft9"))
with pytest.raises(VerifyException):
with pytest.raises(VerifyException, match="not in"):
riscv.FloatRegisterType(riscv.Register("a0"))

a1 = TestSSAValue(riscv.Registers.A1)
a2 = TestSSAValue(riscv.Registers.A2)
with pytest.raises(VerifyException):
riscv.FAddSOp(a1, a2)
with pytest.raises(VerifyException, match="Operation does not verify"):
riscv.FAddSOp(a1, a2).verify()
kingiler marked this conversation as resolved.
Show resolved Hide resolved

f1 = TestSSAValue(riscv.Registers.FT0)
f2 = TestSSAValue(riscv.Registers.FT1)
riscv.FAddSOp(f1, f2)
riscv.FAddSOp(f1, f2).verify()
12 changes: 8 additions & 4 deletions xdsl/dialects/riscv.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,11 @@ def print_parameter(self, printer: Printer) -> None:
printer.print_string(name)

def verify(self) -> None:
if self.data.name is None or self.data.name.startswith("j"):
name = self.data.name
if name is None or name.startswith("j"):
return
assert self.data.name in Register.RV32I_INDEX_BY_NAME
if name not in Register.RV32I_INDEX_BY_NAME:
raise VerifyException(f"{name} not in RV32I")


@irdl_attr_definition
Expand Down Expand Up @@ -211,9 +213,11 @@ def print_parameter(self, printer: Printer) -> None:
printer.print_string(name)

def verify(self) -> None:
if self.data.name is None or self.data.name.startswith("j"):
name = self.data.name
if name is None or name.startswith("j"):
return
assert self.data.name in Register.RV32F_INDEX_BY_NAME
if name not in Register.RV32F_INDEX_BY_NAME:
raise VerifyException(f"{name} not in RV32F")


class Registers(ABC):
Expand Down