Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit be01236

Browse files
authored
[mypyc] Merge int ops(for int_rprimitive) to CallC (#9019)
Related issue: mypyc/mypyc#734 int_compare_op of short_int_rprimitive remain unchanged because they'll need some low-level arithmetic.
1 parent 71e4540 commit be01236

15 files changed

+168
-158
lines changed

mypyc/ir/ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ def to_str(self, env: Environment) -> str:
12031203
# return env.format('%r = %s%s', self, self.identifier, ann)
12041204
# TODO: a hack to prevent lots of failed IR tests when developing prototype
12051205
# eventually we will change all the related tests
1206-
return env.format('%r = %s :: static%s ', self, self.identifier[10:], ann)
1206+
return env.format('%r = %s :: static%s', self, self.identifier[10:], ann)
12071207

12081208
def accept(self, visitor: 'OpVisitor[T]') -> T:
12091209
return visitor.visit_load_global(self)

mypyc/primitives/int_ops.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
str_rprimitive, RType
1313
)
1414
from mypyc.primitives.registry import (
15-
name_ref_op, binary_op, custom_op, simple_emit, call_emit, name_emit,
16-
c_unary_op, CFunctionDescription, c_function_op
15+
name_ref_op, binary_op, custom_op, simple_emit, name_emit,
16+
c_unary_op, CFunctionDescription, c_function_op, c_binary_op
1717
)
1818

1919
# These int constructors produce object_rprimitives that then need to be unboxed
@@ -70,20 +70,20 @@
7070
priority=3)
7171

7272

73-
def int_binary_op(op: str, c_func_name: str,
74-
result_type: RType = int_rprimitive,
73+
def int_binary_op(name: str, c_function_name: str,
74+
return_type: RType = int_rprimitive,
7575
error_kind: int = ERR_NEVER) -> None:
76-
binary_op(op=op,
77-
arg_types=[int_rprimitive, int_rprimitive],
78-
result_type=result_type,
79-
error_kind=error_kind,
80-
format_str='{dest} = {args[0]} %s {args[1]} :: int' % op,
81-
emit=call_emit(c_func_name))
76+
c_binary_op(name=name,
77+
arg_types=[int_rprimitive, int_rprimitive],
78+
return_type=return_type,
79+
c_function_name=c_function_name,
80+
error_kind=error_kind)
8281

8382

84-
def int_compare_op(op: str, c_func_name: str) -> None:
85-
int_binary_op(op, c_func_name, bool_rprimitive)
83+
def int_compare_op(name: str, c_function_name: str) -> None:
84+
int_binary_op(name, c_function_name, bool_rprimitive)
8685
# Generate a straight compare if we know both sides are short
86+
op = name
8787
binary_op(op=op,
8888
arg_types=[short_int_rprimitive, short_int_rprimitive],
8989
result_type=bool_rprimitive,

mypyc/test-data/analysis.test

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def f(a):
2121
L0:
2222
r0 = 1
2323
x = r0
24-
r1 = x == a :: int
24+
r1 = CPyTagged_IsEq(x, a)
2525
if r1 goto L1 else goto L2 :: bool
2626
L1:
2727
r2 = 1
@@ -64,7 +64,7 @@ L0:
6464
r0 = 1
6565
x = r0
6666
r1 = 1
67-
r2 = x == r1 :: int
67+
r2 = CPyTagged_IsEq(x, r1)
6868
if r2 goto L1 else goto L2 :: bool
6969
L1:
7070
return a
@@ -156,7 +156,7 @@ def f(a):
156156
r5 :: None
157157
L0:
158158
r0 = 1
159-
r1 = a == r0 :: int
159+
r1 = CPyTagged_IsEq(a, r0)
160160
if r1 goto L1 else goto L2 :: bool
161161
L1:
162162
r2 = 1
@@ -210,11 +210,11 @@ def f(n):
210210
L0:
211211
L1:
212212
r0 = 5
213-
r1 = n < r0 :: int
213+
r1 = CPyTagged_IsLt(n, r0)
214214
if r1 goto L2 else goto L3 :: bool
215215
L2:
216216
r2 = 1
217-
r3 = n + r2 :: int
217+
r3 = CPyTagged_Add(n, r2)
218218
n = r3
219219
m = n
220220
goto L1
@@ -262,13 +262,13 @@ L0:
262262
y = r1
263263
L1:
264264
r2 = 1
265-
r3 = n < r2 :: int
265+
r3 = CPyTagged_IsLt(n, r2)
266266
if r3 goto L2 else goto L6 :: bool
267267
L2:
268268
n = y
269269
L3:
270270
r4 = 2
271-
r5 = n < r4 :: int
271+
r5 = CPyTagged_IsLt(n, r4)
272272
if r5 goto L4 else goto L5 :: bool
273273
L4:
274274
r6 = 1
@@ -319,7 +319,7 @@ L1:
319319
r2 = f(a)
320320
if is_error(r2) goto L3 (error at f:3) else goto L2
321321
L2:
322-
r3 = r2 + a :: int
322+
r3 = CPyTagged_Add(r2, a)
323323
return r3
324324
L3:
325325
r4 = <error> :: int
@@ -349,11 +349,11 @@ def f(a):
349349
r2 :: None
350350
L0:
351351
L1:
352-
r0 = a < a :: int
352+
r0 = CPyTagged_IsLt(a, a)
353353
if r0 goto L2 else goto L6 :: bool
354354
L2:
355355
L3:
356-
r1 = a < a :: int
356+
r1 = CPyTagged_IsLt(a, a)
357357
if r1 goto L4 else goto L5 :: bool
358358
L4:
359359
y = a
@@ -422,7 +422,7 @@ def f(a):
422422
x :: int
423423
r2, r3 :: short_int
424424
L0:
425-
r0 = a == a :: int
425+
r0 = CPyTagged_IsEq(a, a)
426426
if r0 goto L1 else goto L2 :: bool
427427
L1:
428428
r1 = 2
@@ -472,13 +472,13 @@ L0:
472472
r1 = 0
473473
i = r1
474474
L1:
475-
r2 = i <= a :: int
475+
r2 = CPyTagged_IsLe(i, a)
476476
if r2 goto L2 else goto L3 :: bool
477477
L2:
478-
r3 = sum + i :: int
478+
r3 = CPyTagged_Add(sum, i)
479479
sum = r3
480480
r4 = 1
481-
r5 = i + r4 :: int
481+
r5 = CPyTagged_Add(i, r4)
482482
i = r5
483483
goto L1
484484
L3:
@@ -558,7 +558,7 @@ L9:
558558
unreachable
559559
L10:
560560
r10 = 1
561-
r11 = st + r10 :: int
561+
r11 = CPyTagged_Add(st, r10)
562562
return r11
563563
L11:
564564
r12 = <error> :: int

mypyc/test-data/exceptions.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ L0:
141141
r1 = 0
142142
i = r1
143143
L1:
144-
r2 = i < l :: int
144+
r2 = CPyTagged_IsLt(i, l)
145145
if r2 goto L2 else goto L7 :: bool
146146
L2:
147147
r3 = CPyList_GetItem(a, i)
@@ -151,12 +151,12 @@ L3:
151151
dec_ref r3
152152
if is_error(r4) goto L8 (error at sum:6) else goto L4
153153
L4:
154-
r5 = sum + r4 :: int
154+
r5 = CPyTagged_Add(sum, r4)
155155
dec_ref sum :: int
156156
dec_ref r4 :: int
157157
sum = r5
158158
r6 = 1
159-
r7 = i + r6 :: int
159+
r7 = CPyTagged_Add(i, r6)
160160
dec_ref i :: int
161161
i = r7
162162
goto L1

0 commit comments

Comments
 (0)