CIRCT 20.0.0git
Loading...
Searching...
No Matches
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
5from . import comb
6from ..dialects._ods_common import _cext as _ods_cext
7from ..ir import IntegerAttr, IntegerType, OpView
8from ..support import NamedValueOpView, get_value
9from ._comb_ops_gen import *
10from ._comb_ops_gen import _Dialect
11
12
13# Sugar classes for the various possible verions of ICmpOp.
14class 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
28def 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)
53class EqOp(OpView):
54 pass
55
56
57@CompareOp(1)
58class NeOp(OpView):
59 pass
60
61
62@CompareOp(2)
63class LtSOp(OpView):
64 pass
65
66
67@CompareOp(3)
68class LeSOp(OpView):
69 pass
70
71
72@CompareOp(4)
73class GtSOp(OpView):
74 pass
75
76
77@CompareOp(5)
78class GeSOp(OpView):
79 pass
80
81
82@CompareOp(6)
83class LtUOp(OpView):
84 pass
85
86
87@CompareOp(7)
88class LeUOp(OpView):
89 pass
90
91
92@CompareOp(8)
93class GtUOp(OpView):
94 pass
95
96
97@CompareOp(9)
98class GeUOp(OpView):
99 pass
100
101
102# Builder base classes for non-variadic unary and binary ops.
103class UnaryOpBuilder(NamedValueOpView):
104
105 def operand_names(self):
106 return ["input"]
107
108 def result_names(self):
109 return ["result"]
110
111
112def 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
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
132class BinaryOpBuilder(NamedValueOpView):
133
134 def operand_names(self):
135 return ["lhs", "rhs"]
136
137 def result_names(self):
138 return ["result"]
139
140
141def 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.
158def 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.
171def 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)
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
198 pass
199
200
201# Sugar classes for the various non-variadic binary ops.
202@_ods_cext.register_operation(_Dialect, replace=True)
203@BinaryOp
205 pass
206
207
208@_ods_cext.register_operation(_Dialect, replace=True)
209@BinaryOp
211 pass
212
213
214@_ods_cext.register_operation(_Dialect, replace=True)
215@BinaryOp
217 pass
218
219
220@_ods_cext.register_operation(_Dialect, replace=True)
221@BinaryOp
223 pass
224
225
226@_ods_cext.register_operation(_Dialect, replace=True)
227@BinaryOp
229 pass
230
231
232@_ods_cext.register_operation(_Dialect, replace=True)
233@BinaryOp
235 pass
236
237
238@_ods_cext.register_operation(_Dialect, replace=True)
239@BinaryOp
241 pass
242
243
244@_ods_cext.register_operation(_Dialect, replace=True)
245@BinaryOp
247 pass
248
249
250# Sugar classes for the variadic ops.
251@_ods_cext.register_operation(_Dialect, replace=True)
252@VariadicOp
254 pass
255
256
257@_ods_cext.register_operation(_Dialect, replace=True)
258@VariadicOp
260 pass
261
262
263@_ods_cext.register_operation(_Dialect, replace=True)
264@VariadicOp
266 pass
267
268
269@_ods_cext.register_operation(_Dialect, replace=True)
270@VariadicOp
271class OrOp(OrOp):
272 pass
273
274
275@_ods_cext.register_operation(_Dialect, replace=True)
276@VariadicOp
278 pass
279
280
281@_ods_cext.register_operation(_Dialect, replace=True)
282@VariadicOp
284 pass
285
286
287# Sugar classes for miscellaneous ops.
288@_ods_cext.register_operation(_Dialect, replace=True)
289@CreatableOp
291 pass
operand_names(self)
Definition comb.py:134
__init__(self, low_bit, data_type, input_port_mapping={}, **kwargs)
Definition comb.py:126
create(low_bit, result_type, input=None)
Definition comb.py:187
result_names(self)
Definition comb.py:19
operand_names(self)
Definition comb.py:16
__init__(self, predicate, data_type, input_port_mapping={}, **kwargs)
Definition comb.py:22
operand_names(self)
Definition comb.py:105
result_names(self)
Definition comb.py:108
UnaryOp(base)
Definition comb.py:112
VariadicOp(base)
Definition comb.py:158
BinaryOp(base)
Definition comb.py:141
CompareOp(predicate)
Definition comb.py:28
CreatableOp(base)
Definition comb.py:171