CIRCT 20.0.0git
Loading...
Searching...
No Matches
hwarith.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 ..dialects._ods_common import _cext as _ods_cext
6from ..ir import IntegerAttr, IntegerType
7from ..support import NamedValueOpView, get_value
8from ._hwarith_ops_gen import *
9from ._hwarith_ops_gen import _Dialect
10
11
12class BinaryOpBuilder(NamedValueOpView):
13
14 def operand_names(self):
15 return ["lhs", "rhs"]
16
17 def result_names(self):
18 return ["result"]
19
20
21def BinaryOp(base):
22
23 class _Class(base):
24
25 @classmethod
26 def create(cls, lhs=None, rhs=None, result_type=None):
27 return cls([get_value(lhs), get_value(rhs)])
28
29 return _Class
30
31
32@BinaryOp
33@_ods_cext.register_operation(_Dialect, replace=True)
34class DivOp(DivOp):
35 pass
36
37
38@BinaryOp
39@_ods_cext.register_operation(_Dialect, replace=True)
40class SubOp(SubOp):
41 pass
42
43
44@BinaryOp
45@_ods_cext.register_operation(_Dialect, replace=True)
46class AddOp(AddOp):
47 pass
48
49
50@BinaryOp
51@_ods_cext.register_operation(_Dialect, replace=True)
52class MulOp(MulOp):
53 pass
54
55
56@_ods_cext.register_operation(_Dialect, replace=True)
58
59 @classmethod
60 def create(cls, value, result_type):
61 return cls(result_type, value)
62
63
64@_ods_cext.register_operation(_Dialect, replace=True)
66 # Predicate constants.
67
68 # `==` and `!=`
69 PRED_EQ = 0b000
70 PRED_NE = 0b001
71 # `<` and `>=`
72 PRED_LT = 0b010
73 PRED_GE = 0b011
74 # `<=` and `>`
75 PRED_LE = 0b100
76 PRED_GT = 0b101
77
78 @classmethod
79 def create(cls, pred, a, b):
80 if isinstance(pred, int):
81 pred = IntegerAttr.get(IntegerType.get_signless(64), pred)
82 return cls(pred, a, b)
83
84
85@_ods_cext.register_operation(_Dialect, replace=True)
87
88 @classmethod
89 def create(cls, data_type, value):
90 return cls(IntegerAttr.get(data_type, value))
create(cls, value, result_type)
Definition hwarith.py:60
create(cls, data_type, value)
Definition hwarith.py:89
create(cls, pred, a, b)
Definition hwarith.py:79
BinaryOp(base)
Definition hwarith.py:21