-
Notifications
You must be signed in to change notification settings - Fork 83
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: (csl) adding constructors for CSL ops #2742
Changes from all commits
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 |
---|---|---|
|
@@ -376,6 +376,13 @@ class ImportModuleConstOp(IRDLOperation): | |
|
||
result = result_def(ImportedModuleType) | ||
|
||
def __init__(self, name: str, params: SSAValue | Operation | None = None): | ||
super().__init__( | ||
operands=[params], | ||
result_types=[ImportedModuleType()], | ||
properties={"module": StringAttr(name)}, | ||
) | ||
|
||
|
||
@irdl_op_definition | ||
class ConstStructOp(IRDLOperation): | ||
|
@@ -398,6 +405,18 @@ def verify_(self) -> None: | |
"Number of ssa_fields has to match the number of arguments" | ||
) | ||
|
||
def __init__(self, *args: tuple[str, Operation]): | ||
operands: list[Operation] = [] | ||
fields: list[StringAttr] = [] | ||
for fname, op in args: | ||
fields.append(StringAttr(fname)) | ||
operands.append(op) | ||
super().__init__( | ||
operands=[operands], | ||
result_types=[ComptimeStructType()], | ||
properties={"ssa_fields": ArrayAttr(fields)}, | ||
) | ||
|
||
|
||
@irdl_op_definition | ||
class GetColorOp(IRDLOperation): | ||
|
@@ -406,6 +425,9 @@ class GetColorOp(IRDLOperation): | |
id = operand_def(IntegerType) | ||
res = result_def(ColorType) | ||
|
||
def __init__(self, op: Operation): | ||
super().__init__(operands=[op], result_types=[ColorType()]) | ||
|
||
|
||
@irdl_op_definition | ||
class MemberAccessOp(IRDLOperation): | ||
|
@@ -438,6 +460,21 @@ class MemberCallOp(IRDLOperation): | |
|
||
result = opt_result_def(Attribute) | ||
|
||
def __init__( | ||
self, | ||
fname: str, | ||
result_type: Attribute, | ||
struct: Operation, | ||
*params: SSAValue | Operation, | ||
): | ||
super().__init__( | ||
operands=[struct, params], | ||
result_types=[result_type], | ||
properties={ | ||
"field": StringAttr(fname), | ||
}, | ||
) | ||
|
||
|
||
@irdl_op_definition | ||
class FuncOp(_FuncBase): | ||
|
@@ -703,6 +740,16 @@ class SetTileCodeOp(IRDLOperation): | |
y_coord = operand_def(IntegerType) | ||
params = opt_operand_def(ComptimeStructType) | ||
|
||
def __init__( | ||
self, | ||
fname: str | StringAttr, | ||
x_coord: SSAValue | Operation, | ||
y_coord: SSAValue | Operation, | ||
params: SSAValue | Operation | None = None, | ||
): | ||
name = StringAttr(fname) if isinstance(fname, str) else fname | ||
super().__init__(operands=[x_coord, y_coord, params], properties={"file": name}) | ||
|
||
|
||
class _GetDsdOp(IRDLOperation, ABC): | ||
""" | ||
|
@@ -1486,6 +1533,13 @@ class ParamOp(IRDLOperation): | |
|
||
res = result_def(T) | ||
|
||
def __init__(self, name: str, result_type: T): | ||
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. I'm not sure if this is allowed in python... @PapyChacal do you have any input on this? I think you know more on this than I do... 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. I thought that's what make TypeVars so neat 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. But 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. I don't think it's necessarily wrong, but it's not expressing what you may think it is. 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. You're right, I misread, it's not a TypeVar. I think it's not an IRDL constraint either, though, it should just be a union type with some additional meta data. |
||
super().__init__( | ||
operands=[[]], | ||
result_types=[result_type], | ||
properties={"param_name": StringAttr(name)}, | ||
) | ||
|
||
|
||
@irdl_op_definition | ||
class SignednessCastOp(IRDLOperation): | ||
|
@@ -1511,6 +1565,22 @@ def verify_(self) -> None: | |
"Input and output type must be of different signedness" | ||
) | ||
|
||
def __init__( | ||
self, op: SSAValue | Operation, result_type: IntegerType | None = None | ||
): | ||
if result_type is None: | ||
typ = op.results[0].type if isinstance(op, Operation) else op.type | ||
assert isinstance(typ, IntegerType) | ||
result_type = IntegerType( | ||
typ.width, | ||
( | ||
Signedness.SIGNLESS | ||
if typ.signedness.data == Signedness.UNSIGNED | ||
else Signedness.UNSIGNED | ||
), | ||
) | ||
super().__init__(operands=[op], result_types=[result_type]) | ||
|
||
|
||
@irdl_op_definition | ||
class ConcatStructOp(IRDLOperation): | ||
|
@@ -1534,6 +1604,12 @@ class ConcatStructOp(IRDLOperation): | |
|
||
result = result_def(ComptimeStructType) | ||
|
||
def __init__(self, op1: Operation, op2: Operation): | ||
super().__init__( | ||
operands=[op1, op2], | ||
result_types=[ComptimeStructType()], | ||
) | ||
|
||
|
||
CSL = Dialect( | ||
"csl", | ||
|
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 I'd like this to not be a vararg, and instead be a
Sequence[SSAValue | Operation]
.Having a vararg after a bunch of other arguments would make the code less readable at the call site imo.
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.
As long as it's limited to function name+type, it should hopefully be fine enough to avoid me doing cross-PR changes (:
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 strongly in favour of switching to
Sequence
here, as it's otherwise out of line with the other call operations...