CIRCT
20.0.0git
Loading...
Searching...
No Matches
lib
Bindings
Python
dialects
comb.py
Go to the documentation of this file.
1
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2
# See https://llvm.org/LICENSE.txt for license information.
3
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5
from
.
import
comb
6
from
..dialects._ods_common
import
_cext
as
_ods_cext
7
from
..ir
import
IntegerAttr, IntegerType, OpView
8
from
..support
import
NamedValueOpView, get_value
9
from
._comb_ops_gen
import
*
10
from
._comb_ops_gen
import
_Dialect
11
12
13
# Sugar classes for the various possible verions of ICmpOp.
14
class
ICmpOpBuilder
(NamedValueOpView):
15
16
def
operand_names
(self):
17
return
[
"lhs"
,
"rhs"
]
18
19
def
result_names
(self):
20
return
[
"result"
]
21
22
def
__init__
(self, predicate, data_type, input_port_mapping={}, **kwargs):
23
predicate = IntegerAttr.get(IntegerType.get_signless(64), predicate)
24
super().
__init__
(ICmpOp, data_type, input_port_mapping, [predicate],
25
**kwargs)
26
27
28
def
CompareOp
(predicate):
29
30
def
decorated(cls):
31
32
class
_Class(cls):
33
34
@staticmethod
35
def
create(lhs=None, rhs=None):
36
mapping = {}
37
if
lhs:
38
mapping[
"lhs"
] = lhs
39
if
rhs:
40
mapping[
"rhs"
] = rhs
41
if
len(mapping) == 0:
42
result_type = IntegerType.get_signless(1)
43
else
:
44
result_type =
None
45
return
ICmpOpBuilder
(predicate, result_type, mapping)
46
47
return
_Class
48
49
return
decorated
50
51
52
@CompareOp(0)
53
class
EqOp
(OpView):
54
pass
55
56
57
@
CompareOp
(1)
58
class
NeOp
(OpView):
59
pass
60
61
62
@
CompareOp
(2)
63
class
LtSOp
(OpView):
64
pass
65
66
67
@
CompareOp
(3)
68
class
LeSOp
(OpView):
69
pass
70
71
72
@
CompareOp
(4)
73
class
GtSOp
(OpView):
74
pass
75
76
77
@
CompareOp
(5)
78
class
GeSOp
(OpView):
79
pass
80
81
82
@
CompareOp
(6)
83
class
LtUOp
(OpView):
84
pass
85
86
87
@
CompareOp
(7)
88
class
LeUOp
(OpView):
89
pass
90
91
92
@
CompareOp
(8)
93
class
GtUOp
(OpView):
94
pass
95
96
97
@
CompareOp
(9)
98
class
GeUOp
(OpView):
99
pass
100
101
102
# Builder base classes for non-variadic unary and binary ops.
103
class
UnaryOpBuilder(NamedValueOpView):
104
105
def
operand_names
(self):
106
return
[
"input"
]
107
108
def
result_names
(self):
109
return
[
"result"
]
110
111
112
def
UnaryOp
(base):
113
114
class
_Class(base):
115
116
@classmethod
117
def
create(cls, input=None, result_type=None):
118
mapping = {
"input"
: input}
if
input
else
{}
119
return
UnaryOpBuilder
(cls, result_type, mapping)
120
121
return
_Class
122
123
124
class
ExtractOpBuilder
(
UnaryOpBuilder
):
125
126
def
__init__
(self, low_bit, data_type, input_port_mapping={}, **kwargs):
127
low_bit = IntegerAttr.get(IntegerType.get_signless(32), low_bit)
128
super().
__init__
(
comb.ExtractOp
, data_type, input_port_mapping, [],
129
[low_bit], **kwargs)
130
131
132
class
BinaryOpBuilder
(NamedValueOpView):
133
134
def
operand_names
(self):
135
return
[
"lhs"
,
"rhs"
]
136
137
def
result_names
(self):
138
return
[
"result"
]
139
140
141
def
BinaryOp
(base):
142
143
class
_Class(base):
144
145
@classmethod
146
def
create(cls, lhs=None, rhs=None, result_type=None):
147
mapping = {}
148
if
lhs:
149
mapping[
"lhs"
] = lhs
150
if
rhs:
151
mapping[
"rhs"
] = rhs
152
return
BinaryOpBuilder
(cls, result_type, mapping)
153
154
return
_Class
155
156
157
# Base classes for the variadic ops.
158
def
VariadicOp
(base):
159
160
class
_Class(base):
161
162
@classmethod
163
def
create(cls, *args):
164
return
cls([get_value(a)
for
a
in
args])
165
166
return
_Class
167
168
169
# Base class for miscellaneous ops that can't be abstracted but should provide a
170
# create method for uniformity.
171
def
CreatableOp
(base):
172
173
class
_Class(base):
174
175
@classmethod
176
def
create(cls, *args, **kwargs):
177
return
cls(*args, **kwargs)
178
179
return
_Class
180
181
182
# Sugar classes for the various non-variadic unary ops.
183
@_ods_cext.register_operation(_Dialect, replace=True)
184
class
ExtractOp
(
ExtractOp
):
185
186
@staticmethod
187
def
create
(low_bit, result_type, input=None):
188
mapping = {
"input"
: input}
if
input
else
{}
189
return
ExtractOpBuilder
(low_bit,
190
result_type,
191
mapping,
192
needs_result_type=
True
)
193
194
195
@_ods_cext.register_operation(_Dialect, replace=True)
196
@UnaryOp
197
class
ParityOp
(
ParityOp
):
198
pass
199
200
201
# Sugar classes for the various non-variadic binary ops.
202
@_ods_cext.register_operation(_Dialect, replace=
True
)
203
@BinaryOp
204
class
DivSOp
(
DivSOp
):
205
pass
206
207
208
@_ods_cext.register_operation(_Dialect, replace=
True
)
209
@BinaryOp
210
class
DivUOp
(
DivUOp
):
211
pass
212
213
214
@_ods_cext.register_operation(_Dialect, replace=
True
)
215
@BinaryOp
216
class
ModSOp
(
ModSOp
):
217
pass
218
219
220
@_ods_cext.register_operation(_Dialect, replace=
True
)
221
@BinaryOp
222
class
ModUOp
(
ModUOp
):
223
pass
224
225
226
@_ods_cext.register_operation(_Dialect, replace=
True
)
227
@BinaryOp
228
class
ShlOp
(
ShlOp
):
229
pass
230
231
232
@_ods_cext.register_operation(_Dialect, replace=
True
)
233
@BinaryOp
234
class
ShrSOp
(
ShrSOp
):
235
pass
236
237
238
@_ods_cext.register_operation(_Dialect, replace=
True
)
239
@BinaryOp
240
class
ShrUOp
(
ShrUOp
):
241
pass
242
243
244
@_ods_cext.register_operation(_Dialect, replace=
True
)
245
@BinaryOp
246
class
SubOp
(
SubOp
):
247
pass
248
249
250
# Sugar classes for the variadic ops.
251
@_ods_cext.register_operation(_Dialect, replace=
True
)
252
@VariadicOp
253
class
AddOp
(
AddOp
):
254
pass
255
256
257
@_ods_cext.register_operation(_Dialect, replace=
True
)
258
@VariadicOp
259
class
MulOp
(
MulOp
):
260
pass
261
262
263
@_ods_cext.register_operation(_Dialect, replace=
True
)
264
@VariadicOp
265
class
AndOp
(
AndOp
):
266
pass
267
268
269
@_ods_cext.register_operation(_Dialect, replace=
True
)
270
@VariadicOp
271
class
OrOp
(
OrOp
):
272
pass
273
274
275
@_ods_cext.register_operation(_Dialect, replace=
True
)
276
@VariadicOp
277
class
XorOp
(
XorOp
):
278
pass
279
280
281
@_ods_cext.register_operation(_Dialect, replace=
True
)
282
@VariadicOp
283
class
ConcatOp
(
ConcatOp
):
284
pass
285
286
287
# Sugar classes for miscellaneous ops.
288
@_ods_cext.register_operation(_Dialect, replace=
True
)
289
@CreatableOp
290
class
MuxOp
(
MuxOp
):
291
pass
comb.AddOp
Definition
comb.py:253
comb.AndOp
Definition
comb.py:265
comb.BinaryOpBuilder
Definition
comb.py:132
comb.BinaryOpBuilder.operand_names
operand_names(self)
Definition
comb.py:134
comb.BinaryOpBuilder.result_names
result_names(self)
Definition
comb.py:137
comb.ConcatOp
Definition
comb.py:283
comb.DivSOp
Definition
comb.py:204
comb.DivUOp
Definition
comb.py:210
comb.EqOp
Definition
comb.py:53
comb.ExtractOpBuilder
Definition
comb.py:124
comb.ExtractOpBuilder.__init__
__init__(self, low_bit, data_type, input_port_mapping={}, **kwargs)
Definition
comb.py:126
comb.ExtractOp
Definition
comb.py:184
comb.ExtractOp.create
create(low_bit, result_type, input=None)
Definition
comb.py:187
comb.GeSOp
Definition
comb.py:78
comb.GeUOp
Definition
comb.py:98
comb.GtSOp
Definition
comb.py:73
comb.GtUOp
Definition
comb.py:93
comb.ICmpOpBuilder
Definition
comb.py:14
comb.ICmpOpBuilder.result_names
result_names(self)
Definition
comb.py:19
comb.ICmpOpBuilder.operand_names
operand_names(self)
Definition
comb.py:16
comb.ICmpOpBuilder.__init__
__init__(self, predicate, data_type, input_port_mapping={}, **kwargs)
Definition
comb.py:22
comb.LeSOp
Definition
comb.py:68
comb.LeUOp
Definition
comb.py:88
comb.LtSOp
Definition
comb.py:63
comb.LtUOp
Definition
comb.py:83
comb.ModSOp
Definition
comb.py:216
comb.ModUOp
Definition
comb.py:222
comb.MulOp
Definition
comb.py:259
comb.MuxOp
Definition
comb.py:290
comb.NeOp
Definition
comb.py:58
comb.OrOp
Definition
comb.py:271
comb.ParityOp
Definition
comb.py:197
comb.ShlOp
Definition
comb.py:228
comb.ShrSOp
Definition
comb.py:234
comb.ShrUOp
Definition
comb.py:240
comb.SubOp
Definition
comb.py:246
comb.UnaryOpBuilder
Definition
comb.py:103
comb.UnaryOpBuilder.operand_names
operand_names(self)
Definition
comb.py:105
comb.UnaryOpBuilder.result_names
result_names(self)
Definition
comb.py:108
comb.XorOp
Definition
comb.py:277
comb.UnaryOp
UnaryOp(base)
Definition
comb.py:112
comb.VariadicOp
VariadicOp(base)
Definition
comb.py:158
comb.BinaryOp
BinaryOp(base)
Definition
comb.py:141
comb.CompareOp
CompareOp(predicate)
Definition
comb.py:28
comb.CreatableOp
CreatableOp(base)
Definition
comb.py:171
Generated on Sun Feb 2 2025 00:08:27 for CIRCT by
1.9.8