Skip to content

Commit

Permalink
dialects: (stablehlo) add stablehlo.token (#3093)
Browse files Browse the repository at this point in the history
Adds stablehlo.token type.

Co-authored-by: Erick Ochoa <erick@ceci-nest-pas.me>
  • Loading branch information
efferifick and Erick Ochoa authored Aug 24, 2024
1 parent b55fadc commit c5c77e2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
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,
],
)

0 comments on commit c5c77e2

Please sign in to comment.