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: (stablehlo) add stablehlo.token #3093

Merged
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
3 changes: 3 additions & 0 deletions tests/filecheck/dialects/stablehlo/attrs.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
highest = #stablehlo<precision HIGHEST>
} : () -> ()

%token = "test.op"() : () -> (!stablehlo.token)

// CHECK: builtin.module {
// CHECK-NEXT: "test.op"() {"default" = #stablehlo<precision DEFAULT>, "high" = #stablehlo<precision HIGH>, "highest" = #stablehlo<precision HIGHEST>} : () -> ()
// CHECK-NEXT: %token = "test.op"() : () -> !stablehlo.token
// CHECK-NEXT: }
21 changes: 20 additions & 1 deletion xdsl/dialects/stablehlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
Attribute,
Dialect,
EnumAttribute,
ParametrizedAttribute,
SpacedOpaqueSyntaxAttribute,
SSAValue,
StrEnum,
TypeAttribute,
)
from xdsl.irdl import (
ConstraintVar,
Expand Down Expand Up @@ -77,6 +79,22 @@ class PrecisionAttr(EnumAttribute[Precision], SpacedOpaqueSyntaxAttribute):
name = "stablehlo.precision"


@irdl_attr_definition
class TokenType(TypeAttribute, ParametrizedAttribute):
"""
Token types represent tokens, i.e. opaque values produced and consumed by some operations.
Tokens are used for imposing execution order on operations as described in the Execution section.

E.g.,

// %input0: !stablehlo.token
// %input1: !stablehlo.token
%result = "stablehlo.after_all"(%input0, %input1) : (!stablehlo.token, !stablehlo.token) -> !stablehlo.token
"""

name = "stablehlo.token"


# endregion


Expand Down Expand Up @@ -277,11 +295,12 @@ def verify_(self) -> None:
AddOp,
AndOp,
MultiplyOp,
SubtractOp,
ReturnOp,
SubtractOp,
TransposeOp,
],
[
PrecisionAttr,
TokenType,
],
)
Loading