aboutsummaryrefslogtreecommitdiff
path: root/mlir/test/python/dialects/index_dialect.py
blob: 9db883469792c5c9f58e8650d0c1e9230d0ed654 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# RUN: %PYTHON %s | FileCheck %s

from mlir.ir import *
from mlir.dialects import index, arith


def run(f):
    print("\nTEST:", f.__name__)
    with Context() as ctx, Location.unknown():
        module = Module.create()
        with InsertionPoint(module.body):
            f(ctx)
        print(module)


# CHECK-LABEL: TEST: testConstantOp
@run
def testConstantOp(ctx):
    a = index.ConstantOp(value=42)
    # CHECK: %{{.*}} = index.constant 42


# CHECK-LABEL: TEST: testBoolConstantOp
@run
def testBoolConstantOp(ctx):
    a = index.BoolConstantOp(value=True)
    # CHECK: %{{.*}} = index.bool.constant true


# CHECK-LABEL: TEST: testAndOp
@run
def testAndOp(ctx):
    a = index.ConstantOp(value=42)
    r = index.AndOp(a, a)
    # CHECK: %{{.*}} = index.and %{{.*}}, %{{.*}}


# CHECK-LABEL: TEST: testOrOp
@run
def testOrOp(ctx):
    a = index.ConstantOp(value=42)
    r = index.OrOp(a, a)
    # CHECK: %{{.*}} = index.or %{{.*}}, %{{.*}}


# CHECK-LABEL: TEST: testXOrOp
@run
def testXOrOp(ctx):
    a = index.ConstantOp(value=42)
    r = index.XOrOp(a, a)
    # CHECK: %{{.*}} = index.xor %{{.*}}, %{{.*}}


# CHECK-LABEL: TEST: testCastSOp
@run
def testCastSOp(ctx):
    a = index.ConstantOp(value=42)
    b = arith.ConstantOp(value=23, result=IntegerType.get_signless(64))
    c = index.CastSOp(input=a, output=IntegerType.get_signless(32))
    d = index.CastSOp(input=b, output=IndexType.get())
    # CHECK: %{{.*}} = index.casts %{{.*}} : index to i32
    # CHECK: %{{.*}} = index.casts %{{.*}} : i64 to index


# CHECK-LABEL: TEST: testCastUOp
@run
def testCastUOp(ctx):
    a = index.ConstantOp(value=42)
    b = arith.ConstantOp(value=23, result=IntegerType.get_signless(64))
    c = index.CastUOp(input=a, output=IntegerType.get_signless(32))
    d = index.CastUOp(input=b, output=IndexType.get())
    # CHECK: %{{.*}} = index.castu %{{.*}} : index to i32
    # CHECK: %{{.*}} = index.castu %{{.*}} : i64 to index


# CHECK-LABEL: TEST: testCeilDivSOp
@run
def testCeilDivSOp(ctx):
    a = index.ConstantOp(value=42)
    r = index.CeilDivSOp(a, a)
    # CHECK: %{{.*}} = index.ceildivs %{{.*}}, %{{.*}}


# CHECK-LABEL: TEST: testCeilDivUOp
@run
def testCeilDivUOp(ctx):
    a = index.ConstantOp(value=42)
    r = index.CeilDivUOp(a, a)
    # CHECK: %{{.*}} = index.ceildivu %{{.*}}, %{{.*}}


# CHECK-LABEL: TEST: testCmpOp
@run
def testCmpOp(ctx):
    a = index.ConstantOp(value=42)
    b = index.ConstantOp(value=23)
    pred = AttrBuilder.get("IndexCmpPredicateAttr")("slt", context=ctx)
    r = index.CmpOp(pred, lhs=a, rhs=b)
    # CHECK: %{{.*}} = index.cmp slt(%{{.*}}, %{{.*}})


# CHECK-LABEL: TEST: testAddOp
@run
def testAddOp(ctx):
    a = index.ConstantOp(value=42)
    r = index.AddOp(a, a)
    # CHECK: %{{.*}} = index.add %{{.*}}, %{{.*}}


# CHECK-LABEL: TEST: testSubOp
@run
def testSubOp(ctx):
    a = index.ConstantOp(value=42)
    r = index.SubOp(a, a)
    # CHECK: %{{.*}} = index.sub %{{.*}}, %{{.*}}


# CHECK-LABEL: TEST: testMulOp
@run
def testMulOp(ctx):
    a = index.ConstantOp(value=42)
    r = index.MulOp(a, a)
    # CHECK: %{{.*}} = index.mul %{{.*}}, %{{.*}}


# CHECK-LABEL: TEST: testDivSOp
@run
def testDivSOp(ctx):
    a = index.ConstantOp(value=42)
    r = index.DivSOp(a, a)
    # CHECK: %{{.*}} = index.divs %{{.*}}, %{{.*}}


# CHECK-LABEL: TEST: testDivUOp
@run
def testDivUOp(ctx):
    a = index.ConstantOp(value=42)
    r = index.DivUOp(a, a)
    # CHECK: %{{.*}} = index.divu %{{.*}}, %{{.*}}


# CHECK-LABEL: TEST: testFloorDivSOp
@run
def testFloorDivSOp(ctx):
    a = index.ConstantOp(value=42)
    r = index.FloorDivSOp(a, a)
    # CHECK: %{{.*}} = index.floordivs %{{.*}}, %{{.*}}


# CHECK-LABEL: TEST: testMaxSOp
@run
def testMaxSOp(ctx):
    a = index.ConstantOp(value=42)
    b = index.ConstantOp(value=23)
    r = index.MaxSOp(a, b)
    # CHECK: %{{.*}} = index.maxs %{{.*}}, %{{.*}}


# CHECK-LABEL: TEST: testMaxUOp
@run
def testMaxUOp(ctx):
    a = index.ConstantOp(value=42)
    b = index.ConstantOp(value=23)
    r = index.MaxUOp(a, b)
    # CHECK: %{{.*}} = index.maxu %{{.*}}, %{{.*}}


# CHECK-LABEL: TEST: testMinSOp
@run
def testMinSOp(ctx):
    a = index.ConstantOp(value=42)
    b = index.ConstantOp(value=23)
    r = index.MinSOp(a, b)
    # CHECK: %{{.*}} = index.mins %{{.*}}, %{{.*}}


# CHECK-LABEL: TEST: testMinUOp
@run
def testMinUOp(ctx):
    a = index.ConstantOp(value=42)
    b = index.ConstantOp(value=23)
    r = index.MinUOp(a, b)
    # CHECK: %{{.*}} = index.minu %{{.*}}, %{{.*}}


# CHECK-LABEL: TEST: testRemSOp
@run
def testRemSOp(ctx):
    a = index.ConstantOp(value=42)
    b = index.ConstantOp(value=23)
    r = index.RemSOp(a, b)
    # CHECK: %{{.*}} = index.rems %{{.*}}, %{{.*}}


# CHECK-LABEL: TEST: testRemUOp
@run
def testRemUOp(ctx):
    a = index.ConstantOp(value=42)
    b = index.ConstantOp(value=23)
    r = index.RemUOp(a, b)
    # CHECK: %{{.*}} = index.remu %{{.*}}, %{{.*}}


# CHECK-LABEL: TEST: testShlOp
@run
def testShlOp(ctx):
    a = index.ConstantOp(value=42)
    b = index.ConstantOp(value=3)
    r = index.ShlOp(a, b)
    # CHECK: %{{.*}} = index.shl %{{.*}}, %{{.*}}


# CHECK-LABEL: TEST: testShrSOp
@run
def testShrSOp(ctx):
    a = index.ConstantOp(value=42)
    b = index.ConstantOp(value=3)
    r = index.ShrSOp(a, b)
    # CHECK: %{{.*}} = index.shrs %{{.*}}, %{{.*}}


# CHECK-LABEL: TEST: testShrUOp
@run
def testShrUOp(ctx):
    a = index.ConstantOp(value=42)
    b = index.ConstantOp(value=3)
    r = index.ShrUOp(a, b)
    # CHECK: %{{.*}} = index.shru %{{.*}}, %{{.*}}


# CHECK-LABEL: TEST: testSizeOfOp
@run
def testSizeOfOp(ctx):
    r = index.SizeOfOp()
    # CHECK: %{{.*}} = index.sizeof