Debian Codegraph @

rpython/rtyper/lltypesystem/lloperation.py

raw symbols SCIP
1 """
2 The table of all LL operations.
3 """
4
5 from rpython.rtyper.extregistry import ExtRegistryEntry
6
7
8 class LLOp(object):
9
10 def __init__(self, sideeffects=True, canfold=False, canraise=(),
11 canmallocgc=False, canrun=False, tryfold=False,
12 revdb_protect=False):
13 # self.opname = ... (set afterwards)
14
15 if canfold:
16 sideeffects = False
17
18 # The operation has no side-effects: it can be removed
19 # if its result is not used
20 self.sideeffects = sideeffects
21
22 # Can be safely constant-folded: no side-effects
23 # and always gives the same result for given args
24 self.canfold = canfold
25
26 # Can *try* to fold the operation, but it may raise on you
27 self.tryfold = tryfold or canfold
28
29 # Exceptions that can be raised
30 self.canraise = canraise
31 assert isinstance(canraise, tuple)
32
33 assert not canraise or not canfold
34
35 # The operation can go a GC malloc
36 self.canmallocgc = canmallocgc
37 if canmallocgc:
38 if (MemoryError not in self.canraise and
39 Exception not in self.canraise):
40 self.canraise += (MemoryError,)
41
42 # The operation can be run directly with __call__
43 self.canrun = canrun or canfold
44
45 # RevDB: the operation must always be protected with RPY_REVDB_EMIT()
46 self.revdb_protect = revdb_protect
47
48 # __________ make the LLOp instances callable from LL helpers __________
49
50 __name__ = property(lambda self: 'llop_'+self.opname)
51
52 def __call__(self, RESULTTYPE, *args):
53 # llop is meant to be rtyped and not called directly, unless it is
54 # a canfold=True operation
55 fold = self.fold
56 if getattr(fold, 'need_result_type', False):
57 val = fold(RESULTTYPE, *args)
58 else:
59 val = fold(*args)
60 if RESULTTYPE is not lltype.Void:
61 val = lltype.enforce(RESULTTYPE, val)
62 return val
63
64 @property
65 def fold(self):
66 if hasattr(self, "_fold"):
67 return self._fold
68 global lltype # <- lazy import hack, worth an XXX
69 from rpython.rtyper.lltypesystem import lltype
70 if self.canrun:
71 from rpython.rtyper.lltypesystem.opimpl import get_op_impl
72 op_impl = get_op_impl(self.opname)
73 else:
74 error = TypeError("cannot constant-fold operation %r" % (
75 self.opname,))
76 def op_impl(*args):
77 raise error
78 # cache the implementation function into 'self'
79 self._fold = op_impl
80 return op_impl
81
82 def is_pure(self, args_v):
83 if self.canfold: # canfold => pure operation
84 return True
85 if (self is llop.debug_assert or # debug_assert is pure enough
86 self is llop.debug_assert_not_none):
87 return True
88 # reading from immutable
89 if self is llop.getfield or self is llop.getarrayitem:
90 field = getattr(args_v[1], 'value', None)
91 return args_v[0].concretetype.TO._immutable_field(field)
92 # default
93 return False
94
95 def __repr__(self):
96 return '<LLOp %s>' % (getattr(self, 'opname', '?'),)
97
98
99 class _LLOP(object):
100 def _freeze_(self):
101 return True
102 llop = _LLOP()
103
104 class VoidMarker(object):
105 # marker wrapper for void arguments to llops
106 def __init__(self, value):
107 self.value = value
108 def _freeze_(self):
109 return True
110
111 def void(value):
112 return VoidMarker(value)
113
114 class Entry(ExtRegistryEntry):
115 _about_ = void
116
117 def compute_result_annotation(self, s_value):
118 assert s_value.is_constant()
119 from rpython.annotator.bookkeeper import getbookkeeper
120 bk = getbookkeeper()
121 return bk.immutablevalue(VoidMarker(s_value.const))
122
123 def specialize_call(self, hop):
124 from rpython.rtyper.lltypesystem import lltype
125 hop.exception_cannot_occur()
126 return hop.inputconst(lltype.Void, None)
127
128 def enum_ops_without_sideeffects(raising_is_ok=False):
129 """Enumerate operations that have no side-effects
130 (see also enum_foldable_ops)."""
131 for opname, opdesc in LL_OPERATIONS.iteritems():
132 if not opdesc.sideeffects:
133 if not opdesc.canraise or raising_is_ok:
134 yield opname
135
136 def enum_foldable_ops(_ignored=None):
137 """Enumerate operations that can be constant-folded."""
138 for opname, opdesc in LL_OPERATIONS.iteritems():
139 if opdesc.canfold:
140 assert not opdesc.canraise
141 yield opname
142
143
144 class Entry(ExtRegistryEntry):
145 "Annotation and rtyping of LLOp instances, which are callable."
146 _type_ = LLOp
147
148 def compute_result_annotation(self, RESULTTYPE, *args):
149 from rpython.rtyper.llannotation import lltype_to_annotation
150 assert RESULTTYPE.is_constant()
151 return lltype_to_annotation(RESULTTYPE.const)
152
153 def specialize_call(self, hop):
154 from rpython.rtyper.lltypesystem import lltype
155 op = self.instance # the LLOp object that was called
156 args_v = []
157 for i, s_arg in enumerate(hop.args_s[1:]):
158 if s_arg.is_constant() and isinstance(s_arg.const, VoidMarker):
159 v_arg = hop.inputconst(lltype.Void, s_arg.const.value)
160 else:
161 v_arg = hop.inputarg(hop.args_r[i+1], i+1)
162 args_v.append(v_arg)
163
164 if op.canraise:
165 hop.exception_is_here()
166 else:
167 hop.exception_cannot_occur()
168 return hop.genop(op.opname, args_v, resulttype=hop.r_result.lowleveltype)
169
170
171 # ____________________________________________________________
172 #
173 # This list corresponds to the operations implemented by the LLInterpreter.
174 # ***** Run test_lloperation after changes. *****
175
176 LL_OPERATIONS = {
177
178 'direct_call': LLOp(canraise=(Exception,)),
179 'indirect_call': LLOp(canraise=(Exception,)),
180
181 # __________ numeric operations __________
182
183 'bool_not': LLOp(canfold=True),
184
185 'char_lt': LLOp(canfold=True),
186 'char_le': LLOp(canfold=True),
187 'char_eq': LLOp(canfold=True),
188 'char_ne': LLOp(canfold=True),
189 'char_gt': LLOp(canfold=True),
190 'char_ge': LLOp(canfold=True),
191
192 'unichar_eq': LLOp(canfold=True),
193 'unichar_ne': LLOp(canfold=True),
194
195 'int_is_true': LLOp(canfold=True),
196 'int_neg': LLOp(canfold=True),
197 'int_abs': LLOp(canfold=True),
198 'int_invert': LLOp(canfold=True),
199
200 'int_add': LLOp(canfold=True),
201 'int_sub': LLOp(canfold=True),
202 'int_mul': LLOp(canfold=True),
203 'int_floordiv': LLOp(canfold=True), # C-like behavior for neg num
204 'int_mod': LLOp(canfold=True), # C-like behavior for neg num
205 'int_lt': LLOp(canfold=True),
206 'int_le': LLOp(canfold=True),
207 'int_eq': LLOp(canfold=True),
208 'int_ne': LLOp(canfold=True),
209 'int_gt': LLOp(canfold=True),
210 'int_ge': LLOp(canfold=True),
211 'int_and': LLOp(canfold=True),
212 'int_or': LLOp(canfold=True),
213 'int_lshift': LLOp(canfold=True),
214 'int_rshift': LLOp(canfold=True),
215 'int_xor': LLOp(canfold=True),
216
217 'int_between': LLOp(canfold=True), # a <= b < c
218 'int_force_ge_zero': LLOp(canfold=True), # 0 if a < 0 else a
219
220 'int_add_ovf': LLOp(canraise=(OverflowError,), tryfold=True),
221 'int_add_nonneg_ovf': LLOp(canraise=(OverflowError,), tryfold=True),
222 # ^^^ more efficient version when 2nd arg is nonneg
223 'int_sub_ovf': LLOp(canraise=(OverflowError,), tryfold=True),
224 'int_mul_ovf': LLOp(canraise=(OverflowError,), tryfold=True),
225
226 'uint_is_true': LLOp(canfold=True),
227 'uint_invert': LLOp(canfold=True),
228
229 'uint_add': LLOp(canfold=True),
230 'uint_sub': LLOp(canfold=True),
231 'uint_mul': LLOp(canfold=True),
232 'uint_floordiv': LLOp(canfold=True),
233 'uint_mod': LLOp(canfold=True),
234 'uint_lt': LLOp(canfold=True),
235 'uint_le': LLOp(canfold=True),
236 'uint_eq': LLOp(canfold=True),
237 'uint_ne': LLOp(canfold=True),
238 'uint_gt': LLOp(canfold=True),
239 'uint_ge': LLOp(canfold=True),
240 'uint_and': LLOp(canfold=True),
241 'uint_or': LLOp(canfold=True),
242 'uint_lshift': LLOp(canfold=True), # args (r_uint, int)
243 'uint_rshift': LLOp(canfold=True), # args (r_uint, int)
244 'uint_xor': LLOp(canfold=True),
245
246 'float_is_true': LLOp(canfold=True), # it really means "x != 0.0"
247 'float_neg': LLOp(canfold=True),
248 'float_abs': LLOp(canfold=True),
249
250 'float_add': LLOp(canfold=True),
251 'float_sub': LLOp(canfold=True),
252 'float_mul': LLOp(canfold=True),
253 'float_truediv': LLOp(canfold=True),
254 'float_lt': LLOp(canfold=True),
255 'float_le': LLOp(canfold=True),
256 'float_eq': LLOp(canfold=True),
257 'float_ne': LLOp(canfold=True),
258 'float_gt': LLOp(canfold=True),
259 'float_ge': LLOp(canfold=True),
260 # don't implement float_mod, use math.fmod instead
261 # don't implement float_pow, use math.pow instead
262
263 'llong_is_true': LLOp(canfold=True),
264 'llong_neg': LLOp(canfold=True),
265 'llong_abs': LLOp(canfold=True),
266 'llong_invert': LLOp(canfold=True),
267
268 'llong_add': LLOp(canfold=True),
269 'llong_sub': LLOp(canfold=True),
270 'llong_mul': LLOp(canfold=True),
271 'llong_floordiv': LLOp(canfold=True),
272 'llong_mod': LLOp(canfold=True),
273 'llong_lt': LLOp(canfold=True),
274 'llong_le': LLOp(canfold=True),
275 'llong_eq': LLOp(canfold=True),
276 'llong_ne': LLOp(canfold=True),
277 'llong_gt': LLOp(canfold=True),
278 'llong_ge': LLOp(canfold=True),
279 'llong_and': LLOp(canfold=True),
280 'llong_or': LLOp(canfold=True),
281 'llong_lshift': LLOp(canfold=True), # args (r_longlong, int)
282 'llong_rshift': LLOp(canfold=True), # args (r_longlong, int)
283 'llong_xor': LLOp(canfold=True),
284
285 'ullong_is_true': LLOp(canfold=True),
286 'ullong_invert': LLOp(canfold=True),
287
288 'ullong_add': LLOp(canfold=True),
289 'ullong_sub': LLOp(canfold=True),
290 'ullong_mul': LLOp(canfold=True),
291 'ullong_floordiv': LLOp(canfold=True),
292 'ullong_mod': LLOp(canfold=True),
293 'ullong_lt': LLOp(canfold=True),
294 'ullong_le': LLOp(canfold=True),
295 'ullong_eq': LLOp(canfold=True),
296 'ullong_ne': LLOp(canfold=True),
297 'ullong_gt': LLOp(canfold=True),
298 'ullong_ge': LLOp(canfold=True),
299 'ullong_and': LLOp(canfold=True),
300 'ullong_or': LLOp(canfold=True),
301 'ullong_lshift': LLOp(canfold=True), # args (r_ulonglong, int)
302 'ullong_rshift': LLOp(canfold=True), # args (r_ulonglong, int)
303 'ullong_xor': LLOp(canfold=True),
304
305 'lllong_is_true': LLOp(canfold=True),
306 'lllong_neg': LLOp(canfold=True),
307 'lllong_abs': LLOp(canfold=True),
308 'lllong_invert': LLOp(canfold=True),
309
310 'lllong_add': LLOp(canfold=True),
311 'lllong_sub': LLOp(canfold=True),
312 'lllong_mul': LLOp(canfold=True),
313 'lllong_floordiv': LLOp(canfold=True),
314 'lllong_mod': LLOp(canfold=True),
315 'lllong_lt': LLOp(canfold=True),
316 'lllong_le': LLOp(canfold=True),
317 'lllong_eq': LLOp(canfold=True),
318 'lllong_ne': LLOp(canfold=True),
319 'lllong_gt': LLOp(canfold=True),
320 'lllong_ge': LLOp(canfold=True),
321 'lllong_and': LLOp(canfold=True),
322 'lllong_or': LLOp(canfold=True),
323 'lllong_lshift': LLOp(canfold=True), # args (r_longlonglong, int)
324 'lllong_rshift': LLOp(canfold=True), # args (r_longlonglong, int)
325 'lllong_xor': LLOp(canfold=True),
326
327 'ulllong_is_true': LLOp(canfold=True),
328 'ulllong_invert': LLOp(canfold=True),
329
330 'ulllong_add': LLOp(canfold=True),
331 'ulllong_sub': LLOp(canfold=True),
332 'ulllong_mul': LLOp(canfold=True),
333 'ulllong_floordiv': LLOp(canfold=True),
334 'ulllong_mod': LLOp(canfold=True),
335 'ulllong_lt': LLOp(canfold=True),
336 'ulllong_le': LLOp(canfold=True),
337 'ulllong_eq': LLOp(canfold=True),
338 'ulllong_ne': LLOp(canfold=True),
339 'ulllong_gt': LLOp(canfold=True),
340 'ulllong_ge': LLOp(canfold=True),
341 'ulllong_and': LLOp(canfold=True),
342 'ulllong_or': LLOp(canfold=True),
343 'ulllong_lshift': LLOp(canfold=True), # args (r_ulonglonglong, int)
344 'ulllong_rshift': LLOp(canfold=True), # args (r_ulonglonglong, int)
345 'ulllong_xor': LLOp(canfold=True),
346
347 'cast_primitive': LLOp(canfold=True),
348 'cast_bool_to_int': LLOp(canfold=True),
349 'cast_bool_to_uint': LLOp(canfold=True),
350 'cast_bool_to_float': LLOp(canfold=True),
351 'cast_char_to_int': LLOp(canfold=True),
352 'cast_unichar_to_int': LLOp(canfold=True),
353 'cast_int_to_char': LLOp(canfold=True),
354 'cast_int_to_unichar': LLOp(canfold=True),
355 'cast_int_to_uint': LLOp(canfold=True),
356 'cast_int_to_float': LLOp(canfold=True),
357 'cast_int_to_longlong': LLOp(canfold=True),
358 'cast_uint_to_int': LLOp(canfold=True),
359 'cast_uint_to_float': LLOp(canfold=True),
360 'cast_longlong_to_float' :LLOp(canfold=True),
361 'cast_ulonglong_to_float':LLOp(canfold=True),
362 'cast_float_to_int': LLOp(canfold=True),
363 'cast_float_to_uint': LLOp(canfold=True),
364 'cast_float_to_longlong' :LLOp(canfold=True),
365 'cast_float_to_ulonglong':LLOp(canfold=True),
366 'truncate_longlong_to_int':LLOp(canfold=True),
367 'force_cast': LLOp(sideeffects=False), # only for rffi.cast()
368 'convert_float_bytes_to_longlong': LLOp(canfold=True),
369 'convert_longlong_bytes_to_float': LLOp(canfold=True),
370
371 'likely': LLOp(canfold=True),
372 'unlikely': LLOp(canfold=True),
373
374 # __________ pointer operations __________
375
376 'malloc': LLOp(canmallocgc=True),
377 'malloc_varsize': LLOp(canmallocgc=True),
378 'shrink_array': LLOp(canrun=True),
379 'zero_gc_pointers_inside': LLOp(),
380 'free': LLOp(),
381 'getfield': LLOp(sideeffects=False, canrun=True),
382 'getarrayitem': LLOp(sideeffects=False, canrun=True),
383 'getarraysize': LLOp(canfold=True),
384 'getsubstruct': LLOp(canfold=True),
385 'getinteriorfield': LLOp(sideeffects=False, canrun=True),
386 'getinteriorarraysize': LLOp(canfold=True),
387 'setinteriorfield': LLOp(),
388 'bare_setinteriorfield': LLOp(),
389 'getarraysubstruct': LLOp(canfold=True),
390 'setfield': LLOp(),
391 'bare_setfield': LLOp(),
392 'setarrayitem': LLOp(),
393 'bare_setarrayitem': LLOp(),
394 'cast_pointer': LLOp(canfold=True),
395 'ptr_eq': LLOp(canfold=True),
396 'ptr_ne': LLOp(canfold=True),
397 'ptr_nonzero': LLOp(canfold=True),
398 'ptr_iszero': LLOp(canfold=True),
399 'cast_ptr_to_int': LLOp(sideeffects=False),
400 'cast_int_to_ptr': LLOp(sideeffects=False),
401 'direct_fieldptr': LLOp(canfold=True),
402 'direct_arrayitems': LLOp(canfold=True),
403 'direct_ptradd': LLOp(canfold=True),
404 'cast_opaque_ptr': LLOp(sideeffects=False),
405 'length_of_simple_gcarray_from_opaque': LLOp(sideeffects=False),
406
407 # __________ address operations __________
408
409 'boehm_malloc': LLOp(),
410 'boehm_malloc_atomic': LLOp(),
411 'boehm_register_finalizer': LLOp(),
412 'boehm_disappearing_link': LLOp(),
413 'raw_malloc': LLOp(revdb_protect=True),
414 'raw_malloc_usage': LLOp(sideeffects=False),
415 'raw_free': LLOp(revdb_protect=True),
416 'raw_memclear': LLOp(revdb_protect=True),
417 'raw_memset': LLOp(revdb_protect=True),
418 'raw_memcopy': LLOp(revdb_protect=True),
419 'raw_memmove': LLOp(revdb_protect=True),
420 'raw_load': LLOp(revdb_protect=True, sideeffects=False,
421 canrun=True),
422 'raw_store': LLOp(revdb_protect=True, canrun=True),
423 'bare_raw_store': LLOp(revdb_protect=True),
424 'gc_load_indexed': LLOp(sideeffects=False, canrun=True),
425 'gc_store': LLOp(canrun=True), # only used by the boehm gc
426 'gc_store_indexed': LLOp(canrun=True),
427 'track_alloc_start': LLOp(),
428 'track_alloc_stop': LLOp(),
429 'adr_add': LLOp(canfold=True),
430 'adr_sub': LLOp(canfold=True),
431 'adr_delta': LLOp(canfold=True),
432 'adr_lt': LLOp(canfold=True),
433 'adr_le': LLOp(canfold=True),
434 'adr_eq': LLOp(canfold=True),
435 'adr_ne': LLOp(canfold=True),
436 'adr_gt': LLOp(canfold=True),
437 'adr_ge': LLOp(canfold=True),
438 'cast_ptr_to_adr': LLOp(sideeffects=False),
439 'cast_adr_to_ptr': LLOp(canfold=True),
440 'cast_adr_to_int': LLOp(sideeffects=False),
441 'cast_int_to_adr': LLOp(canfold=True),
442
443 'get_group_member': LLOp(canfold=True),
444 'get_next_group_member':LLOp(canfold=True),
445 'is_group_member_nonzero':LLOp(canfold=True),
446 'extract_ushort': LLOp(canfold=True),
447 'combine_ushort': LLOp(canfold=True),
448 'gc_gettypeptr_group': LLOp(canfold=True),
449 'get_member_index': LLOp(canfold=True),
450
451 # __________ used by the JIT ________
452
453 'jit_marker': LLOp(),
454 'jit_force_virtualizable':LLOp(canrun=True),
455 'jit_force_virtual': LLOp(canrun=True),
456 'jit_is_virtual': LLOp(canrun=True),
457 'jit_force_quasi_immutable': LLOp(canrun=True),
458 'jit_record_exact_class' : LLOp(canrun=True),
459 'jit_record_exact_value' : LLOp(canrun=True),
460 'jit_ffi_save_result': LLOp(canrun=True),
461 'jit_conditional_call': LLOp(),
462 'jit_conditional_call_value': LLOp(),
463 'jit_enter_portal_frame': LLOp(canrun=True),
464 'jit_leave_portal_frame': LLOp(canrun=True),
465 'get_exception_addr': LLOp(),
466 'get_exc_value_addr': LLOp(),
467 'do_malloc_fixedsize':LLOp(canmallocgc=True),
468 'do_malloc_fixedsize_clear': LLOp(canmallocgc=True),
469 'do_malloc_varsize': LLOp(canmallocgc=True),
470 'do_malloc_varsize_clear': LLOp(canmallocgc=True),
471 'get_write_barrier_failing_case': LLOp(sideeffects=False),
472 'get_write_barrier_from_array_failing_case': LLOp(sideeffects=False),
473 'gc_get_type_info_group': LLOp(sideeffects=False),
474 'll_read_timestamp': LLOp(revdb_protect=True, canrun=True),
475 'll_get_timestamp_unit': LLOp(revdb_protect=True, canrun=True),
476 'jit_record_known_result': LLOp(canrun=True),
477
478 # __________ GC operations __________
479
480 'gc__collect': LLOp(canmallocgc=True),
481 'gc__collect_step': LLOp(canmallocgc=True),
482 'gc__enable': LLOp(),
483 'gc__disable': LLOp(),
484 'gc__isenabled': LLOp(),
485 'gc_free': LLOp(),
486 'gc_fetch_exception': LLOp(),
487 'gc_restore_exception': LLOp(),
488 'gc_call_rtti_destructor': LLOp(),
489 'gc_deallocate': LLOp(),
490 'gc_reload_possibly_moved': LLOp(),
491 # see rlib/objectmodel for gc_identityhash and gc_id
492 'gc_identityhash': LLOp(sideeffects=False, canmallocgc=True),
493 'gc_id': LLOp(sideeffects=False, canmallocgc=True),
494 'gc_obtain_free_space': LLOp(revdb_protect=True),
495 'gc_set_max_heap_size': LLOp(revdb_protect=True),
496 'gc_can_move' : LLOp(sideeffects=False),
497 'gc_thread_run' : LLOp(),
498 'gc_thread_start' : LLOp(),
499 'gc_thread_die' : LLOp(),
500 'gc_thread_before_fork':LLOp(), # returns an opaque address
501 'gc_thread_after_fork': LLOp(), # arguments: (result_of_fork, opaqueaddr)
502 'gc_writebarrier': LLOp(canrun=True),
503 'gc_writebarrier_before_copy': LLOp(canrun=True),
504 'gc_writebarrier_before_move': LLOp(canrun=True),
505 'gc_heap_stats' : LLOp(canmallocgc=True),
506 'gc_pin' : LLOp(canrun=True),
507 'gc_unpin' : LLOp(canrun=True),
508 'gc__is_pinned' : LLOp(canrun=True),
509 'gc_bit' : LLOp(sideeffects=False, canrun=True),
510
511 'gc_get_rpy_roots' : LLOp(),
512 'gc_get_rpy_referents': LLOp(),
513 'gc_get_rpy_memory_usage': LLOp(),
514 'gc_get_rpy_type_index': LLOp(),
515 'gc_is_rpy_instance' : LLOp(),
516 'gc_dump_rpy_heap' : LLOp(canraise=(OSError,)),
517 'gc_typeids_z' : LLOp(),
518 'gc_typeids_list' : LLOp(),
519 'gc_gettypeid' : LLOp(),
520 'gc_gcflag_extra' : LLOp(),
521 'gc_add_memory_pressure': LLOp(),
522 'gc_get_stats' : LLOp(),
523 'gc_fq_next_dead' : LLOp(),
524 'gc_fq_register' : LLOp(),
525 'gc_ignore_finalizer' : LLOp(canrun=True),
526
527 'gc_rawrefcount_init': LLOp(),
528 'gc_rawrefcount_create_link_pypy': LLOp(),
529 'gc_rawrefcount_create_link_pyobj': LLOp(),
530 'gc_rawrefcount_mark_deallocating': LLOp(),
531 'gc_rawrefcount_from_obj': LLOp(sideeffects=False),
532 'gc_rawrefcount_to_obj': LLOp(sideeffects=False),
533 'gc_rawrefcount_next_dead': LLOp(),
534
535 'gc_move_out_of_nursery': LLOp(),
536 'gc_increase_root_stack_depth': LLOp(canrun=True),
537
538 'gc_push_roots' : LLOp(), # temporary: list of roots to save
539 'gc_pop_roots' : LLOp(), # temporary: list of roots to restore
540 'gc_enter_roots_frame' : LLOp(), # reserve N entries, save local frame pos
541 'gc_leave_roots_frame' : LLOp(), # free the shadowstack frame
542 'gc_save_root' : LLOp(), # save value Y in shadowstack pos X
543 'gc_restore_root' : LLOp(), # restore value Y from shadowstack pos X
544
545 # ------- JIT & GC interaction, only for some GCs ----------
546
547 'gc_adr_of_nursery_free' : LLOp(),
548 # ^^^ returns an address of nursery free pointer, for later modifications
549 'gc_adr_of_nursery_top' : LLOp(),
550 # ^^^ returns an address of pointer, since it can change at runtime
551 'gc_adr_of_root_stack_base': LLOp(),
552 'gc_adr_of_root_stack_top': LLOp(),
553 # returns the address of gcdata.root_stack_base/top (for shadowstack only)
554 'gc_modified_shadowstack': LLOp(),
555
556 'gc_stack_bottom': LLOp(canrun=True), # see llinterp.py for docs
557
558 # NOTE NOTE NOTE! don't forget *** canmallocgc=True *** for anything that
559 # can malloc a GC object.
560
561 # __________ weakrefs __________
562
563 'weakref_create': LLOp(sideeffects=False, canmallocgc=True),
564 'weakref_deref': LLOp(sideeffects=False),
565 'cast_ptr_to_weakrefptr': LLOp(sideeffects=False), # no-op type hiding
566 'cast_weakrefptr_to_ptr': LLOp(sideeffects=False), # no-op type revealing
567
568 # __________ misc operations __________
569
570 'stack_current': LLOp(revdb_protect=True, sideeffects=False),
571 'keepalive': LLOp(),
572 'same_as': LLOp(canfold=True),
573 'hint': LLOp(),
574 'check_no_more_arg': LLOp(canraise=(Exception,)),
575 'check_self_nonzero': LLOp(canraise=(Exception,)),
576 'decode_arg': LLOp(canraise=(Exception,)),
577 'decode_arg_def': LLOp(canraise=(Exception,)),
578 'getslice': LLOp(canraise=(Exception,)),
579 'check_and_clear_exc': LLOp(),
580
581 'threadlocalref_addr': LLOp(), # get (or make) addr of tl
582 'threadlocalref_get': LLOp(sideeffects=False), # read field (no check)
583 'threadlocalref_load': LLOp(), # make addr and read field
584 'threadlocalref_store': LLOp(), # write field (with check)
585 'threadlocalref_acquire': LLOp(), # lock for enum
586 'threadlocalref_release': LLOp(), # lock for enum
587 'threadlocalref_enum': LLOp(sideeffects=False), # enum all threadlocalrefs
588
589 # __________ debugging __________
590 'debug_view': LLOp(),
591 'debug_print': LLOp(canrun=True),
592 'debug_start': LLOp(canrun=True),
593 'debug_stop': LLOp(canrun=True),
594 'have_debug_prints': LLOp(canrun=True),
595 'have_debug_prints_for': LLOp(canrun=True),
596 'debug_offset': LLOp(canrun=True),
597 'debug_flush': LLOp(canrun=True),
598 'debug_assert': LLOp(tryfold=True),
599 'debug_assert_not_none': LLOp(tryfold=True),
600 'debug_fatalerror': LLOp(canrun=True),
601 'debug_llinterpcall': LLOp(canraise=(Exception,)),
602 # Python func call 'res=arg[0](*arg[1:])'
603 # in backends, abort() or whatever is fine
604 'debug_start_traceback': LLOp(),
605 'debug_record_traceback': LLOp(),
606 'debug_catch_exception': LLOp(),
607 'debug_reraise_traceback': LLOp(),
608 'debug_print_traceback': LLOp(),
609 'debug_nonnull_pointer': LLOp(canrun=True),
610 'debug_forked': LLOp(),
611
612 # __________ instrumentation _________
613 'instrument_count': LLOp(),
614
615 'revdb_stop_point': LLOp(),
616 'revdb_send_answer': LLOp(),
617 'revdb_breakpoint': LLOp(),
618 'revdb_get_value': LLOp(sideeffects=False),
619 'revdb_get_unique_id': LLOp(sideeffects=False),
620 'revdb_watch_save_state': LLOp(),
621 'revdb_watch_restore_state': LLOp(),
622 'revdb_weakref_create': LLOp(),
623 'revdb_weakref_deref': LLOp(),
624 'revdb_call_destructor': LLOp(),
625 'revdb_set_thread_breakpoint': LLOp(),
626 'revdb_strtod': LLOp(sideeffects=False),
627 'revdb_dtoa': LLOp(sideeffects=False),
628 'revdb_modf': LLOp(sideeffects=False),
629 'revdb_frexp': LLOp(sideeffects=False),
630 'revdb_do_next_call': LLOp(canrun=True),
631 }
632 # ***** Run test_lloperation after changes. *****
633
634 # ____________________________________________________________
635 # Post-processing
636
637 # Stick the opnames into the LLOp instances
638 for opname, opdesc in LL_OPERATIONS.iteritems():
639 opdesc.opname = opname
640 del opname, opdesc
641
642 # Also export all operations in an attribute-based namespace.
643 # Example usage from LL helpers: z = llop.int_add(Signed, x, y)
644
645 for opname, opdesc in LL_OPERATIONS.iteritems():
646 setattr(llop, opname, opdesc)
647 del opname, opdesc