-
Notifications
You must be signed in to change notification settings - Fork 0
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
Extend ASL support: strings, comparisons, etc. #1
base: main
Are you sure you want to change the base?
Conversation
This makes it match the name used in ASLi
Also changes the spelling of some primops to match ASLi's spelling
This hack consists of - a bogus operation 'asl.bool_to_if' that fills the gap between how ASL represents bools and how scf represents them - limited implementations of scf.if and scf.yield that are limited to the case that no mutable local variables are modified in the if statement The right way to do this is to add asl.if which would 1) Support a list of elsif blocks 2) Use a region for the guard on each of the elsif blocks 3) Optionally use a region for the guard on the if block (not needed but it is more symmetric) This hack let me run a bunch of tests for operations that return boolean
@irdl_attr_definition | ||
class StringAttr(Data[str]): |
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 would recommend using the StringAttr in the builtin dialect
@classmethod | ||
def parse(cls, parser: Parser) -> ConstantStringOp: | ||
"""Parse the operation.""" | ||
value = parser.parse_str_literal() | ||
attr_dict = parser.parse_optional_attr_dict() | ||
return ConstantStringOp(value, attr_dict) | ||
|
||
def print(self, printer: Printer) -> None: | ||
"""Print the operation.""" | ||
printer.print(" ", '"' + self.value.data + '"') | ||
if self.attributes: | ||
printer.print(" ") | ||
printer.print_attr_dict(self.attributes) |
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.
Would something like this work instead?
assembly_format = "$value attr-dict"
arg = operand_def(BoolType()) | ||
res = result_def(builtin.IntegerType(1)) | ||
|
||
assembly_format = "$arg `:` type($arg) `->` type($res) attr-dict" |
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'm not sure why, but the attr dict tends to be before the type by convention
assembly_format = "$arg `:` type($arg) `->` type($res) attr-dict" | |
assembly_format = "$arg attr-dict `:` type($arg) `->` type($res)" |
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.
Actually, that's because I moved it to the end on the other operations.
Mostly because I hate being it at the beginning, because it is "optional" in a way.
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.
Are there other dialects that do this? Seems to me like we should stick with the convention if not.
results = [] # hack that is maybe good enough for the print_bool function | ||
if cond: | ||
args = interpreter.run_ssacfg_region( | ||
op.true_region, tuple(results), "then_region" |
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.
op.true_region, tuple(results), "then_region" | |
op.true_region, (), "then_region" |
) | ||
else: | ||
args = interpreter.run_ssacfg_region( | ||
op.false_region, tuple(results), "else_region" |
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.
op.false_region, tuple(results), "else_region" | |
op.false_region, (), "else_region" |
@@ -40,6 +41,40 @@ def run_call( | |||
) -> tuple[Any, ...]: | |||
return interpreter.call_op(op.callee.string_value(), args) | |||
|
|||
@impl(scf.IfOp) |
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'm surprised this is necessary, xDSL already has an implementation for scf.If, I would have expected it to be enough
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 just pushed the change that includes the xDSL version of this to main
@@ -1,17 +1,20 @@ | |||
// RUN: asl-opt %s | asl-opt %s | filecheck %s | |||
|
|||
builtin.module { | |||
%true = asl.constant_bool true {attr_dict} | |||
%false = asl.constant_bool false {attr_dict} | |||
%true = asl.constant_bool true {"attr_dict"} |
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 my bad, I switched from a commit to just "main" in xDSL, so I have a feeling that there's drift in our versions, we recently merged a change that avoide the quotes when their content is a valid symbol, so the version on the left in this diff is actually the more up to date spelling.
Very nice! |
This PR:
(this hack is in a separate commit to make it easier to revert/fix)
I have not added a test for each of the new operations yet.
If used with this branch of ASLi
whose HEAD is currently this commit
then running the following commands
will run 119 tests and 17 of them will pass.