Bases: IRDLOperation
Module level declaration of a global variable
See external documentation.
Source code in xdsl/dialects/ml_program.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113 | @irdl_op_definition
class GlobalOp(IRDLOperation):
"""
Module level declaration of a global variable
See external [documentation](https://mlir.llvm.org/docs/Dialects/MLProgramOps/#ml_programglobal-ml_programglobalop).
"""
name = "ml_program.global"
sym_name = attr_def(SymbolNameConstraint())
type = attr_def(TypeAttribute)
is_mutable = opt_attr_def(UnitAttr)
value = opt_attr_def()
sym_visibility = attr_def(StringAttr)
traits = traits_def(SymbolOpInterface())
def __init__(
self,
sym_name: Attribute,
type: Attribute,
is_mutable: Attribute | None,
value: Attribute | None,
sym_visibility: Attribute,
):
super().__init__(
attributes={
"sym_name": sym_name,
"type": type,
"is_mutable": is_mutable,
"value": value,
"sym_visibility": sym_visibility,
},
)
def _verify(self) -> None:
if isinstance(self.is_mutable, NoneType) and isinstance(self.value, NoneType):
raise VerifyException("Immutable global must have an initial value")
def print(self, printer: Printer):
printer.print_string(" ")
if self.sym_visibility:
printer.print_string(self.sym_visibility.data)
printer.print_string(" ")
if self.is_mutable:
printer.print_string("mutable ")
printer.print_string("@")
printer.print_string(self.sym_name.data)
if self.value:
printer.print_string("(")
printer.print_attribute(self.value)
printer.print_string(")")
printer.print_string(" : ")
printer.print_attribute(self.type)
@classmethod
def parse(cls, parser: Parser) -> Self:
attrs = parser.parse_optional_attr_dict()
sym_visibility = parser.parse_visibility_keyword()
if parser.parse_optional_keyword("mutable"):
is_mutable = UnitAttr()
else:
is_mutable = None
sym_name = parser.parse_symbol_name().data
if parser.parse_optional_punctuation("("):
value = parser.parse_attribute()
parser.parse_punctuation(")")
else:
value = None
parser.parse_punctuation(":")
type = parser.parse_type()
global_op = cls(
StringAttr(sym_name),
type,
is_mutable,
value,
sym_visibility,
)
global_op.attributes |= attrs
return global_op
|
name = 'ml_program.global'
class-attribute
instance-attribute
sym_name = attr_def(SymbolNameConstraint())
class-attribute
instance-attribute
type = attr_def(TypeAttribute)
class-attribute
instance-attribute
is_mutable = opt_attr_def(UnitAttr)
class-attribute
instance-attribute
value = opt_attr_def()
class-attribute
instance-attribute
sym_visibility = attr_def(StringAttr)
class-attribute
instance-attribute
traits = traits_def(SymbolOpInterface())
class-attribute
instance-attribute
__init__(sym_name: Attribute, type: Attribute, is_mutable: Attribute | None, value: Attribute | None, sym_visibility: Attribute)
Source code in xdsl/dialects/ml_program.py
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 | def __init__(
self,
sym_name: Attribute,
type: Attribute,
is_mutable: Attribute | None,
value: Attribute | None,
sym_visibility: Attribute,
):
super().__init__(
attributes={
"sym_name": sym_name,
"type": type,
"is_mutable": is_mutable,
"value": value,
"sym_visibility": sym_visibility,
},
)
|
print(printer: Printer)
Source code in xdsl/dialects/ml_program.py
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86 | def print(self, printer: Printer):
printer.print_string(" ")
if self.sym_visibility:
printer.print_string(self.sym_visibility.data)
printer.print_string(" ")
if self.is_mutable:
printer.print_string("mutable ")
printer.print_string("@")
printer.print_string(self.sym_name.data)
if self.value:
printer.print_string("(")
printer.print_attribute(self.value)
printer.print_string(")")
printer.print_string(" : ")
printer.print_attribute(self.type)
|
parse(parser: Parser) -> Self
classmethod
Source code in xdsl/dialects/ml_program.py
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113 | @classmethod
def parse(cls, parser: Parser) -> Self:
attrs = parser.parse_optional_attr_dict()
sym_visibility = parser.parse_visibility_keyword()
if parser.parse_optional_keyword("mutable"):
is_mutable = UnitAttr()
else:
is_mutable = None
sym_name = parser.parse_symbol_name().data
if parser.parse_optional_punctuation("("):
value = parser.parse_attribute()
parser.parse_punctuation(")")
else:
value = None
parser.parse_punctuation(":")
type = parser.parse_type()
global_op = cls(
StringAttr(sym_name),
type,
is_mutable,
value,
sym_visibility,
)
global_op.attributes |= attrs
return global_op
|