Debian Codegraph @

rpython/jit/backend/arm/assembler.py

raw symbols SCIP
1 from __future__ import print_function, with_statement
2
3 import os
4
5 from rpython.jit.backend.arm import conditions as c, registers as r
6 from rpython.jit.backend.arm import shift
7 from rpython.jit.backend.arm.arch import (WORD, DOUBLE_WORD,
8 JITFRAME_FIXED_SIZE)
9 from rpython.jit.backend.arm.codebuilder import InstrBuilder, OverwritingBuilder
10 from rpython.jit.backend.arm.locations import imm, StackLocation, get_fp_offset
11 from rpython.jit.backend.arm.helper.regalloc import VMEM_imm_size
12 from rpython.jit.backend.arm.opassembler import ResOpAssembler
13 from rpython.jit.backend.arm.regalloc import (Regalloc,
14 CoreRegisterManager, check_imm_arg, VFPRegisterManager,
15 operations as regalloc_operations)
16 from rpython.jit.backend.llsupport import jitframe, rewrite
17 from rpython.jit.backend.llsupport.assembler import BaseAssembler
18 from rpython.jit.backend.llsupport.regalloc import get_scale, valid_addressing_size
19 from rpython.jit.backend.llsupport.asmmemmgr import MachineDataBlockWrapper
20 from rpython.jit.backend.model import CompiledLoopToken
21 from rpython.jit.codewriter.effectinfo import EffectInfo
22 from rpython.jit.metainterp.history import AbstractFailDescr, FLOAT, INT, VOID
23 from rpython.jit.metainterp.resoperation import rop
24 from rpython.rlib.debug import debug_print, debug_start, debug_stop
25 from rpython.rlib.jit import AsmInfo
26 from rpython.rlib.objectmodel import we_are_translated, specialize, compute_unique_id
27 from rpython.rlib.rarithmetic import r_uint
28 from rpython.rtyper.annlowlevel import llhelper, cast_instance_to_gcref
29 from rpython.rtyper.lltypesystem import lltype, rffi
30 from rpython.jit.backend.arm import callbuilder
31 from rpython.rtyper.lltypesystem.lloperation import llop
32 from rpython.rlib.rjitlog import rjitlog as jl
33
34 class AssemblerARM(ResOpAssembler):
35
36 debug = False
37 DEBUG_FRAME_DEPTH = False
38
39 def __init__(self, cpu, translate_support_code=False):
40 ResOpAssembler.__init__(self, cpu, translate_support_code)
41 self.setup_failure_recovery()
42 self.mc = None
43 self.pending_guards = None
44 self._exit_code_addr = 0
45 self.current_clt = None
46 self.malloc_slowpath = 0
47 self.wb_slowpath = [0, 0, 0, 0, 0]
48 self._regalloc = None
49 self.datablockwrapper = None
50 self.propagate_exception_path = 0
51 self.stack_check_slowpath = 0
52 self._debug = False
53 self.loop_run_counters = []
54 self.gcrootmap_retaddr_forced = 0
55
56 def setup_once(self):
57 BaseAssembler.setup_once(self)
58
59 def setup(self, looptoken):
60 BaseAssembler.setup(self, looptoken)
61 assert self.memcpy_addr != 0, 'setup_once() not called?'
62 if we_are_translated():
63 self.debug = False
64 self.current_clt = looptoken.compiled_loop_token
65 self.mc = InstrBuilder(self.cpu.cpuinfo.arch_version)
66 self.pending_guards = []
67 #assert self.datablockwrapper is None --- but obscure case
68 # possible, e.g. getting MemoryError and continuing
69 allblocks = self.get_asmmemmgr_blocks(looptoken)
70 self.datablockwrapper = MachineDataBlockWrapper(self.cpu.asmmemmgr,
71 allblocks)
72 self.mc.datablockwrapper = self.datablockwrapper
73 self.target_tokens_currently_compiling = {}
74 self.frame_depth_to_patch = []
75
76 def teardown(self):
77 self.current_clt = None
78 self._regalloc = None
79 self.mc = None
80 self.pending_guards = None
81
82 def setup_failure_recovery(self):
83 self.failure_recovery_code = [0, 0, 0, 0]
84
85 def _build_propagate_exception_path(self):
86 mc = InstrBuilder(self.cpu.cpuinfo.arch_version)
87 self._store_and_reset_exception(mc, r.r0)
88 ofs = self.cpu.get_ofs_of_frame_field('jf_guard_exc')
89 # make sure ofs fits into a register
90 assert check_imm_arg(ofs)
91 self.store_reg(mc, r.r0, r.fp, ofs)
92 propagate_exception_descr = rffi.cast(lltype.Signed,
93 cast_instance_to_gcref(self.cpu.propagate_exception_descr))
94 # put propagate_exception_descr into frame
95 ofs = self.cpu.get_ofs_of_frame_field('jf_descr')
96 # make sure ofs fits into a register
97 assert check_imm_arg(ofs)
98 mc.gen_load_int(r.r0.value, propagate_exception_descr)
99 self.store_reg(mc, r.r0, r.fp, ofs)
100 mc.MOV_rr(r.r0.value, r.fp.value)
101 self.gen_func_epilog(mc)
102 rawstart = mc.materialize(self.cpu, [])
103 self.propagate_exception_path = rawstart
104
105 def _store_and_reset_exception(self, mc, excvalloc=None, exctploc=None,
106 on_frame=False):
107 """ Resest the exception. If excvalloc is None, then store it on the
108 frame in jf_guard_exc
109 """
110 assert excvalloc is not r.ip
111 assert exctploc is not r.ip
112 tmpreg = r.lr
113 mc.gen_load_int(r.ip.value, self.cpu.pos_exc_value())
114 if excvalloc is not None: # store
115 assert excvalloc.is_core_reg()
116 self.load_reg(mc, excvalloc, r.ip)
117 if on_frame:
118 # store exc_value in JITFRAME
119 ofs = self.cpu.get_ofs_of_frame_field('jf_guard_exc')
120 assert check_imm_arg(ofs)
121 #
122 self.load_reg(mc, r.ip, r.ip, helper=tmpreg)
123 #
124 self.store_reg(mc, r.ip, r.fp, ofs, helper=tmpreg)
125 if exctploc is not None:
126 # store pos_exception in exctploc
127 assert exctploc.is_core_reg()
128 mc.gen_load_int(r.ip.value, self.cpu.pos_exception())
129 self.load_reg(mc, exctploc, r.ip, helper=tmpreg)
130
131 if on_frame or exctploc is not None:
132 mc.gen_load_int(r.ip.value, self.cpu.pos_exc_value())
133
134 # reset exception
135 mc.gen_load_int(tmpreg.value, 0)
136
137 self.store_reg(mc, tmpreg, r.ip, 0)
138
139 mc.gen_load_int(r.ip.value, self.cpu.pos_exception())
140 self.store_reg(mc, tmpreg, r.ip, 0)
141
142 def _restore_exception(self, mc, excvalloc, exctploc):
143 assert excvalloc is not r.ip
144 assert exctploc is not r.ip
145 tmpreg = r.lr # use lr as a second temporary reg
146 mc.gen_load_int(r.ip.value, self.cpu.pos_exc_value())
147 if excvalloc is not None:
148 assert excvalloc.is_core_reg()
149 self.store_reg(mc, excvalloc, r.ip)
150 else:
151 assert exctploc is not r.fp
152 # load exc_value from JITFRAME and put it in pos_exc_value
153 ofs = self.cpu.get_ofs_of_frame_field('jf_guard_exc')
154 self.load_reg(mc, tmpreg, r.fp, ofs)
155 self.store_reg(mc, tmpreg, r.ip)
156 # reset exc_value in the JITFRAME
157 mc.gen_load_int(tmpreg.value, 0)
158 self.store_reg(mc, tmpreg, r.fp, ofs)
159
160 # restore pos_exception from exctploc register
161 mc.gen_load_int(r.ip.value, self.cpu.pos_exception())
162 self.store_reg(mc, exctploc, r.ip)
163
164 def _build_stack_check_slowpath(self):
165 _, _, slowpathaddr = self.cpu.insert_stack_check()
166 if slowpathaddr == 0 or not self.cpu.propagate_exception_descr:
167 return # no stack check (for tests, or non-translated)
168 #
169 # make a "function" that is called immediately at the start of
170 # an assembler function. In particular, the stack looks like:
171 #
172 # | retaddr of caller | <-- aligned to a multiple of 16
173 # | saved argument regs |
174 # | my own retaddr | <-- sp
175 # +-----------------------+
176 #
177 mc = InstrBuilder(self.cpu.cpuinfo.arch_version)
178 # save argument registers and return address
179 mc.PUSH([reg.value for reg in r.argument_regs] + [r.ip.value, r.lr.value])
180 # stack is aligned here
181 # Pass current stack pointer as argument to the call
182 mc.MOV_rr(r.r0.value, r.sp.value)
183 #
184 mc.BL(slowpathaddr)
185
186 # check for an exception
187 mc.gen_load_int(r.r0.value, self.cpu.pos_exception())
188 mc.LDR_ri(r.r0.value, r.r0.value)
189 mc.TST_rr(r.r0.value, r.r0.value)
190 #
191 # restore registers and return
192 # We check for c.EQ here, meaning all bits zero in this case
193 mc.POP([reg.value for reg in r.argument_regs] + [r.ip.value, r.pc.value], cond=c.EQ)
194 # restore sp
195 mc.ADD_ri(r.sp.value, r.sp.value, (len(r.argument_regs) + 2) * WORD)
196 mc.B(self.propagate_exception_path)
197 #
198 rawstart = mc.materialize(self.cpu, [])
199 self.stack_check_slowpath = rawstart
200
201 def _build_wb_slowpath(self, withcards, withfloats=False, for_frame=False):
202 descr = self.cpu.gc_ll_descr.write_barrier_descr
203 if descr is None:
204 return
205 if not withcards:
206 func = descr.get_write_barrier_fn(self.cpu)
207 else:
208 if descr.jit_wb_cards_set == 0:
209 return
210 func = descr.get_write_barrier_from_array_fn(self.cpu)
211 if func == 0:
212 return
213 #
214 # This builds a helper function called from the slow path of
215 # write barriers. It must save all registers, and optionally
216 # all vfp registers. It takes a single argument which is in r0.
217 # It must keep stack alignment accordingly.
218 mc = InstrBuilder(self.cpu.cpuinfo.arch_version)
219 #
220 exc0 = exc1 = None
221 mc.PUSH([r.ip.value, r.lr.value]) # push two words to keep alignment
222 if not for_frame:
223 self._push_all_regs_to_jitframe(mc, [], withfloats, callee_only=True)
224 else:
225 # NOTE: don't save registers on the jitframe here! It might
226 # override already-saved values that will be restored
227 # later...
228 #
229 # we're possibly called from the slowpath of malloc
230 # save the caller saved registers
231 # assuming we do not collect here
232 exc0, exc1 = r.r4, r.r5
233 mc.PUSH([gpr.value for gpr in r.caller_resp] + [exc0.value, exc1.value])
234 mc.VPUSH([vfpr.value for vfpr in r.caller_vfp_resp])
235
236 self._store_and_reset_exception(mc, exc0, exc1)
237 mc.BL(func)
238 #
239 if not for_frame:
240 self._pop_all_regs_from_jitframe(mc, [], withfloats, callee_only=True)
241 else:
242 self._restore_exception(mc, exc0, exc1)
243 mc.VPOP([vfpr.value for vfpr in r.caller_vfp_resp])
244 assert exc0 is not None
245 assert exc1 is not None
246 mc.POP([gpr.value for gpr in r.caller_resp] +
247 [exc0.value, exc1.value])
248 #
249 if withcards:
250 # A final TEST8 before the RET, for the caller. Careful to
251 # not follow this instruction with another one that changes
252 # the status of the CPU flags!
253 mc.LDRB_ri(r.ip.value, r.r0.value,
254 imm=descr.jit_wb_if_flag_byteofs)
255 mc.TST_ri(r.ip.value, imm=0x80)
256 #
257 mc.POP([r.ip.value, r.pc.value])
258 #
259 rawstart = mc.materialize(self.cpu, [])
260 if for_frame:
261 self.wb_slowpath[4] = rawstart
262 else:
263 self.wb_slowpath[withcards + 2 * withfloats] = rawstart
264
265 def _build_cond_call_slowpath(self, supports_floats, callee_only):
266 """ This builds a general call slowpath, for whatever call happens to
267 come.
268 """
269 mc = InstrBuilder(self.cpu.cpuinfo.arch_version)
270 #
271 # We don't save/restore r4; instead the return value (if any)
272 # will be stored there.
273 self._push_all_regs_to_jitframe(mc, [r.r4], self.cpu.supports_floats, callee_only)
274 ## args are in their respective positions
275 mc.PUSH([r.ip.value, r.lr.value])
276 mc.BLX(r.r4.value)
277 mc.MOV_rr(r.r4.value, r.r0.value)
278 self._reload_frame_if_necessary(mc)
279 self._pop_all_regs_from_jitframe(mc, [r.r4], supports_floats,
280 callee_only)
281 # return
282 mc.POP([r.ip.value, r.pc.value])
283 return mc.materialize(self.cpu, [])
284
285 def _build_malloc_slowpath(self, kind):
286 """ While arriving on slowpath, we have a gcpattern on stack 0.
287 The arguments are passed in r0 and r10, as follows:
288
289 kind == 'fixed': nursery_head in r0 and the size in r1 - r0.
290
291 kind == 'str/unicode': length of the string to allocate in r0.
292
293 kind == 'var': length to allocate in r1, tid in r0,
294 and itemsize on the stack.
295
296 This function must preserve all registers apart from r0 and r1.
297 """
298 assert kind in ['fixed', 'str', 'unicode', 'var']
299 mc = InstrBuilder(self.cpu.cpuinfo.arch_version)
300 #
301 self._push_all_regs_to_jitframe(mc, [r.r0, r.r1], self.cpu.supports_floats)
302 #
303 if kind == 'fixed':
304 addr = self.cpu.gc_ll_descr.get_malloc_slowpath_addr()
305 elif kind == 'str':
306 addr = self.cpu.gc_ll_descr.get_malloc_fn_addr('malloc_str')
307 elif kind == 'unicode':
308 addr = self.cpu.gc_ll_descr.get_malloc_fn_addr('malloc_unicode')
309 else:
310 addr = self.cpu.gc_ll_descr.get_malloc_slowpath_array_addr()
311 if kind == 'fixed':
312 # stack layout: [gcmap]
313 # At this point we know that the values we need to compute the size
314 # are stored in r0 and r1.
315 mc.SUB_rr(r.r0.value, r.r1.value, r.r0.value) # compute the size we want
316
317 if hasattr(self.cpu.gc_ll_descr, 'passes_frame'):
318 mc.MOV_rr(r.r1.value, r.fp.value)
319 elif kind == 'str' or kind == 'unicode':
320 # stack layout: [gcmap]
321 mc.MOV_rr(r.r0.value, r.r1.value)
322 else: # var
323 # stack layout: [gcmap][itemsize]...
324 # tid is in r0
325 # length is in r1
326 mc.MOV_rr(r.r2.value, r.r1.value)
327 mc.MOV_rr(r.r1.value, r.r0.value)
328 mc.POP([r.r0.value]) # load itemsize
329 # store the gc pattern
330 mc.POP([r.r4.value])
331 ofs = self.cpu.get_ofs_of_frame_field('jf_gcmap')
332 self.store_reg(mc, r.r4, r.fp, ofs)
333 #
334 # We need to push two registers here because we are going to make a
335 # call an therefore the stack needs to be 8-byte aligned
336 mc.PUSH([r.ip.value, r.lr.value])
337 #
338 mc.BL(addr)
339 #
340 # If the slowpath malloc failed, we raise a MemoryError that
341 # always interrupts the current loop, as a "good enough"
342 # approximation.
343 mc.CMP_ri(r.r0.value, 0)
344 mc.B(self.propagate_exception_path, c=c.EQ)
345 #
346 self._reload_frame_if_necessary(mc)
347 self._pop_all_regs_from_jitframe(mc, [r.r0, r.r1], self.cpu.supports_floats)
348 #
349 nursery_free_adr = self.cpu.gc_ll_descr.get_nursery_free_addr()
350 mc.gen_load_int(r.r1.value, nursery_free_adr)
351 mc.LDR_ri(r.r1.value, r.r1.value)
352 # clear the gc pattern
353 mc.gen_load_int(r.ip.value, 0)
354 self.store_reg(mc, r.ip, r.fp, ofs)
355 # return
356 mc.POP([r.ip.value, r.pc.value])
357
358 #
359 rawstart = mc.materialize(self.cpu, [])
360 return rawstart
361
362 def _reload_frame_if_necessary(self, mc):
363 gcrootmap = self.cpu.gc_ll_descr.gcrootmap
364 if gcrootmap and gcrootmap.is_shadow_stack:
365 rst = gcrootmap.get_root_stack_top_addr()
366 mc.gen_load_int(r.ip.value, rst)
367 self.load_reg(mc, r.ip, r.ip)
368 self.load_reg(mc, r.fp, r.ip, ofs=-WORD)
369 wbdescr = self.cpu.gc_ll_descr.write_barrier_descr
370 if gcrootmap and wbdescr:
371 # frame never uses card marking, so we enforce this is not
372 # an array
373 self._write_barrier_fastpath(mc, wbdescr, [r.fp], array=False,
374 is_frame=True)
375
376 def propagate_memoryerror_if_reg_is_null(self, reg_loc):
377 # see ../x86/assembler.py:genop_discard_check_memory_error()
378 self.mc.CMP_ri(reg_loc.value, 0)
379 self.mc.B(self.propagate_exception_path, c=c.EQ)
380
381 def _push_all_regs_to_jitframe(self, mc, ignored_regs, withfloats,
382 callee_only=False):
383 # Push general purpose registers
384 base_ofs = self.cpu.get_baseofs_of_frame_field()
385 if callee_only:
386 regs = CoreRegisterManager.save_around_call_regs
387 else:
388 regs = CoreRegisterManager.all_regs
389 # XXX add special case if ignored_regs are a block at the start of regs
390 if not ignored_regs: # we want to push a contiguous block of regs
391 assert check_imm_arg(base_ofs)
392 mc.ADD_ri(r.ip.value, r.fp.value, base_ofs)
393 mc.STM(r.ip.value, [reg.value for reg in regs])
394 else:
395 for reg in ignored_regs:
396 assert not reg.is_vfp_reg() # sanity check
397 # we can have holes in the list of regs
398 for i, gpr in enumerate(regs):
399 if gpr in ignored_regs:
400 continue
401 self.store_reg(mc, gpr, r.fp, base_ofs + i * WORD)
402
403 if withfloats:
404 # Push VFP regs
405 regs = VFPRegisterManager.all_regs
406 ofs = len(CoreRegisterManager.all_regs) * WORD
407 assert check_imm_arg(ofs+base_ofs)
408 mc.ADD_ri(r.ip.value, r.fp.value, imm=ofs+base_ofs)
409 mc.VSTM(r.ip.value, [vfpr.value for vfpr in regs])
410
411 def _pop_all_regs_from_jitframe(self, mc, ignored_regs, withfloats,
412 callee_only=False):
413 # Pop general purpose registers
414 base_ofs = self.cpu.get_baseofs_of_frame_field()
415 if callee_only:
416 regs = CoreRegisterManager.save_around_call_regs
417 else:
418 regs = CoreRegisterManager.all_regs
419 # XXX add special case if ignored_regs are a block at the start of regs
420 if not ignored_regs: # we want to pop a contiguous block of regs
421 assert check_imm_arg(base_ofs)
422 mc.ADD_ri(r.ip.value, r.fp.value, base_ofs)
423 mc.LDM(r.ip.value, [reg.value for reg in regs])
424 else:
425 for reg in ignored_regs:
426 assert not reg.is_vfp_reg() # sanity check
427 # we can have holes in the list of regs
428 for i, gpr in enumerate(regs):
429 if gpr in ignored_regs:
430 continue
431 ofs = i * WORD + base_ofs
432 self.load_reg(mc, gpr, r.fp, ofs)
433 if withfloats:
434 # Pop VFP regs
435 regs = VFPRegisterManager.all_regs
436 ofs = len(CoreRegisterManager.all_regs) * WORD
437 assert check_imm_arg(ofs+base_ofs)
438 mc.ADD_ri(r.ip.value, r.fp.value, imm=ofs+base_ofs)
439 mc.VLDM(r.ip.value, [vfpr.value for vfpr in regs])
440
441 def _build_failure_recovery(self, exc, withfloats=False):
442 mc = InstrBuilder(self.cpu.cpuinfo.arch_version)
443 self._push_all_regs_to_jitframe(mc, [], withfloats)
444
445 if exc:
446 # We might have an exception pending. Load it into r4
447 # (this is a register saved across calls)
448 mc.gen_load_int(r.r5.value, self.cpu.pos_exc_value())
449 mc.LDR_ri(r.r4.value, r.r5.value)
450 # clear the exc flags
451 mc.gen_load_int(r.r6.value, 0)
452 mc.STR_ri(r.r6.value, r.r5.value) # pos_exc_value is still in r5
453 mc.gen_load_int(r.r5.value, self.cpu.pos_exception())
454 mc.STR_ri(r.r6.value, r.r5.value)
455 # save r4 into 'jf_guard_exc'
456 offset = self.cpu.get_ofs_of_frame_field('jf_guard_exc')
457 assert check_imm_arg(abs(offset))
458 mc.STR_ri(r.r4.value, r.fp.value, imm=offset)
459 # now we return from the complete frame, which starts from
460 # _call_header_with_stack_check(). The LEA in _call_footer below
461 # throws away most of the frame, including all the PUSHes that we
462 # did just above.
463 ofs = self.cpu.get_ofs_of_frame_field('jf_descr')
464 assert check_imm_arg(abs(ofs))
465 ofs2 = self.cpu.get_ofs_of_frame_field('jf_gcmap')
466 assert check_imm_arg(abs(ofs2))
467 base_ofs = self.cpu.get_baseofs_of_frame_field()
468 # store the gcmap
469 mc.POP([r.ip.value])
470 mc.STR_ri(r.ip.value, r.fp.value, imm=ofs2)
471 # store the descr
472 mc.POP([r.ip.value])
473 mc.STR_ri(r.ip.value, r.fp.value, imm=ofs)
474
475 # set return value
476 assert check_imm_arg(base_ofs)
477 mc.MOV_rr(r.r0.value, r.fp.value)
478 #
479 self.gen_func_epilog(mc)
480 rawstart = mc.materialize(self.cpu, [])
481 self.failure_recovery_code[exc + 2 * withfloats] = rawstart
482
483 def generate_quick_failure(self, guardtok):
484 startpos = self.mc.currpos()
485 faildescrindex, target = self.store_info_on_descr(startpos, guardtok)
486 self.load_from_gc_table(r.ip.value, faildescrindex)
487 self.regalloc_push(r.ip)
488 self.push_gcmap(self.mc, gcmap=guardtok.gcmap, push=True)
489 self.mc.BL(target)
490 return startpos
491
492 def gen_func_epilog(self, mc=None, cond=c.AL):
493 gcrootmap = self.cpu.gc_ll_descr.gcrootmap
494 if mc is None:
495 mc = self.mc
496 if gcrootmap and gcrootmap.is_shadow_stack:
497 self.gen_footer_shadowstack(gcrootmap, mc)
498 if self.cpu.supports_floats:
499 mc.VPOP([reg.value for reg in r.callee_saved_vfp_registers],
500 cond=cond)
501 # pop all callee saved registers. This pops 'pc' last.
502 # It also pops the threadlocal_addr back into 'r1', but it
503 # is not needed any more and will be discarded.
504 mc.POP([reg.value for reg in r.callee_restored_registers] +
505 [r.r1.value], cond=cond)
506 mc.BKPT()
507
508 def gen_func_prolog(self):
509 stack_size = WORD #alignment
510 stack_size += len(r.callee_saved_registers) * WORD
511 if self.cpu.supports_floats:
512 stack_size += len(r.callee_saved_vfp_registers) * 2 * WORD
513
514 # push all callee saved registers including lr; and push r1 as
515 # well, which contains the threadlocal_addr argument. Note that
516 # we're pushing a total of 10 words, which keeps the stack aligned.
517 self.mc.PUSH([reg.value for reg in r.callee_saved_registers] +
518 [r.r1.value])
519 self.saved_threadlocal_addr = 0 # at offset 0 from location 'sp'
520 if self.cpu.supports_floats:
521 self.mc.VPUSH([reg.value for reg in r.callee_saved_vfp_registers])
522 self.saved_threadlocal_addr += (
523 len(r.callee_saved_vfp_registers) * 2 * WORD)
524 assert stack_size % 8 == 0 # ensure we keep alignment
525
526 # set fp to point to the JITFRAME
527 self.mc.MOV_rr(r.fp.value, r.r0.value)
528 #
529 gcrootmap = self.cpu.gc_ll_descr.gcrootmap
530 if gcrootmap and gcrootmap.is_shadow_stack:
531 self.gen_shadowstack_header(gcrootmap)
532
533 def gen_shadowstack_header(self, gcrootmap):
534 # lr = shadow stack top addr
535 # ip = *lr
536 rst = gcrootmap.get_root_stack_top_addr()
537 self.mc.gen_load_int(r.lr.value, rst)
538 self.load_reg(self.mc, r.ip, r.lr)
539 # *ip = r.fp
540 self.store_reg(self.mc, r.fp, r.ip)
541 #
542 self.mc.ADD_ri(r.ip.value, r.ip.value, WORD)
543 # *lr = ip + WORD
544 self.store_reg(self.mc, r.ip, r.lr)
545
546 def gen_footer_shadowstack(self, gcrootmap, mc):
547 rst = gcrootmap.get_root_stack_top_addr()
548 mc.gen_load_int(r.ip.value, rst)
549 self.load_reg(mc, r.r4, r.ip)
550 mc.SUB_ri(r.r4.value, r.r4.value, WORD)
551 self.store_reg(mc, r.r4, r.ip)
552
553 def _dump(self, ops, type='loop'):
554 debug_start('jit-backend-ops')
555 debug_print(type)
556 for op in ops:
557 debug_print(op.repr())
558 debug_stop('jit-backend-ops')
559
560 def _call_header(self):
561 # there is the gc table before this point
562 self.gen_func_prolog()
563
564 def _call_header_with_stack_check(self):
565 self._call_header()
566 if self.stack_check_slowpath == 0:
567 pass # no stack check (e.g. not translated)
568 else:
569 endaddr, lengthaddr, _ = self.cpu.insert_stack_check()
570 # load stack end
571 self.mc.gen_load_int(r.ip.value, endaddr) # load ip, [end]
572 self.mc.LDR_ri(r.ip.value, r.ip.value) # LDR ip, ip
573 # load stack length
574 self.mc.gen_load_int(r.lr.value, lengthaddr) # load lr, lengh
575 self.mc.LDR_ri(r.lr.value, r.lr.value) # ldr lr, *lengh
576 # calculate ofs
577 self.mc.SUB_rr(r.ip.value, r.ip.value, r.sp.value) # SUB ip, current
578 # if ofs
579 self.mc.CMP_rr(r.ip.value, r.lr.value) # CMP ip, lr
580 self.mc.BL(self.stack_check_slowpath, c=c.HI) # call if ip > lr
581
582 # cpu interface
583 def assemble_loop(self, jd_id, unique_id, logger, loopname, inputargs,
584 operations, looptoken, log):
585 clt = CompiledLoopToken(self.cpu, looptoken.number)
586 looptoken.compiled_loop_token = clt
587 clt._debug_nbargs = len(inputargs)
588
589 if not we_are_translated():
590 # Arguments should be unique
591 assert len(set(inputargs)) == len(inputargs)
592
593 self.setup(looptoken)
594 #self.codemap_builder.enter_portal_frame(jd_id, unique_id,
595 # self.mc.get_relative_pos())
596
597
598 frame_info = self.datablockwrapper.malloc_aligned(
599 jitframe.JITFRAMEINFO_SIZE, alignment=WORD)
600 clt.frame_info = rffi.cast(jitframe.JITFRAMEINFOPTR, frame_info)
601 clt.frame_info.clear() # for now
602
603 if log:
604 operations = self._inject_debugging_code(looptoken, operations,
605 'e', looptoken.number)
606
607 regalloc = Regalloc(assembler=self)
608 allgcrefs = []
609 operations = regalloc.prepare_loop(inputargs, operations, looptoken,
610 allgcrefs)
611 self.reserve_gcref_table(allgcrefs)
612 functionpos = self.mc.get_relative_pos()
613
614 self._call_header_with_stack_check()
615 self._check_frame_depth_debug(self.mc)
616
617 loop_head = self.mc.get_relative_pos()
618 looptoken._ll_loop_code = loop_head
619 #
620 frame_depth_no_fixed_size = self._assemble(regalloc, inputargs, operations)
621 self.update_frame_depth(frame_depth_no_fixed_size + JITFRAME_FIXED_SIZE)
622 #
623 size_excluding_failure_stuff = self.mc.get_relative_pos()
624
625 self.write_pending_failure_recoveries()
626
627 full_size = self.mc.get_relative_pos()
628 rawstart = self.materialize_loop(looptoken)
629 looptoken._ll_function_addr = rawstart + functionpos
630
631 self.patch_gcref_table(looptoken, rawstart)
632 self.process_pending_guards(rawstart)
633 self.fixup_target_tokens(rawstart)
634
635 if log and not we_are_translated():
636 self.mc._dump_trace(rawstart,
637 'loop.asm')
638
639 ops_offset = self.mc.ops_offset
640
641 if logger:
642 log = logger.log_trace(jl.MARK_TRACE_ASM, None, self.mc)
643 log.write(inputargs, operations, ops_offset=ops_offset)
644
645 # legacy
646 if logger.logger_ops:
647 logger.logger_ops.log_loop(inputargs, operations, 0,
648 "rewritten", name=loopname,
649 ops_offset=ops_offset)
650
651 self.teardown()
652
653 debug_start("jit-backend-addr")
654 debug_print("Loop %d (%s) has address 0x%x to 0x%x (bootstrap 0x%x)" % (
655 looptoken.number, loopname,
656 r_uint(rawstart + loop_head),
657 r_uint(rawstart + size_excluding_failure_stuff),
658 r_uint(rawstart + functionpos)))
659 debug_print(" gc table: 0x%x" % r_uint(rawstart))
660 debug_print(" function: 0x%x" % r_uint(rawstart + functionpos))
661 debug_print(" resops: 0x%x" % r_uint(rawstart + loop_head))
662 debug_print(" failures: 0x%x" % r_uint(rawstart +
663 size_excluding_failure_stuff))
664 debug_print(" end: 0x%x" % r_uint(rawstart + full_size))
665 debug_stop("jit-backend-addr")
666
667 return AsmInfo(ops_offset, rawstart + loop_head,
668 size_excluding_failure_stuff - loop_head)
669
670 def _assemble(self, regalloc, inputargs, operations):
671 self.guard_success_cc = c.cond_none
672 regalloc.compute_hint_frame_locations(operations)
673 self._walk_operations(inputargs, operations, regalloc)
674 assert self.guard_success_cc == c.cond_none
675 frame_depth = regalloc.get_final_frame_depth()
676 jump_target_descr = regalloc.jump_target_descr
677 if jump_target_descr is not None:
678 tgt_depth = jump_target_descr._arm_clt.frame_info.jfi_frame_depth
679 target_frame_depth = tgt_depth - JITFRAME_FIXED_SIZE
680 frame_depth = max(frame_depth, target_frame_depth)
681 return frame_depth
682
683 def assemble_bridge(self, logger, faildescr, inputargs, operations,
684 original_loop_token, log):
685 if not we_are_translated():
686 # Arguments should be unique
687 assert len(set(inputargs)) == len(inputargs)
688
689 self.setup(original_loop_token)
690 #self.codemap.inherit_code_from_position(faildescr.adr_jump_offset)
691 descr_number = compute_unique_id(faildescr)
692 if log:
693 operations = self._inject_debugging_code(faildescr, operations,
694 'b', descr_number)
695
696 assert isinstance(faildescr, AbstractFailDescr)
697
698 arglocs = self.rebuild_faillocs_from_descr(faildescr, inputargs)
699
700 regalloc = Regalloc(assembler=self)
701 allgcrefs = []
702 operations = regalloc.prepare_bridge(inputargs, arglocs,
703 operations,
704 allgcrefs,
705 self.current_clt.frame_info)
706 self.reserve_gcref_table(allgcrefs)
707 startpos = self.mc.get_relative_pos()
708
709 self._check_frame_depth(self.mc, regalloc.get_gcmap())
710
711 bridgestartpos = self.mc.get_relative_pos()
712 frame_depth_no_fixed_size = self._assemble(regalloc, inputargs, operations)
713
714 codeendpos = self.mc.get_relative_pos()
715
716 self.write_pending_failure_recoveries()
717
718 fullsize = self.mc.get_relative_pos()
719 rawstart = self.materialize_loop(original_loop_token)
720
721 self.patch_gcref_table(original_loop_token, rawstart)
722 self.process_pending_guards(rawstart)
723
724 debug_start("jit-backend-addr")
725 debug_print("bridge out of Guard 0x%x has address 0x%x to 0x%x" %
726 (r_uint(descr_number), r_uint(rawstart + startpos),
727 r_uint(rawstart + codeendpos)))
728 debug_print(" gc table: 0x%x" % r_uint(rawstart))
729 debug_print(" jump target: 0x%x" % r_uint(rawstart + startpos))
730 debug_print(" resops: 0x%x" % r_uint(rawstart + bridgestartpos))
731 debug_print(" failures: 0x%x" % r_uint(rawstart + codeendpos))
732 debug_print(" end: 0x%x" % r_uint(rawstart + fullsize))
733 debug_stop("jit-backend-addr")
734
735 # patch the jump from original guard
736 self.patch_trace(faildescr, original_loop_token,
737 rawstart + startpos, regalloc)
738
739 self.patch_stack_checks(frame_depth_no_fixed_size + JITFRAME_FIXED_SIZE,
740 rawstart)
741 if not we_are_translated():
742 if log:
743 self.mc._dump_trace(rawstart, 'bridge.asm')
744
745 ops_offset = self.mc.ops_offset
746 frame_depth = max(self.current_clt.frame_info.jfi_frame_depth,
747 frame_depth_no_fixed_size + JITFRAME_FIXED_SIZE)
748 self.fixup_target_tokens(rawstart)
749 self.update_frame_depth(frame_depth)
750
751 if logger:
752 log = logger.log_trace(jl.MARK_TRACE_ASM, None, self.mc)
753 log.write(inputargs, operations, ops_offset)
754 # log that the already written bridge is stitched to a descr!
755 logger.log_patch_guard(descr_number, rawstart)
756
757 # legacy
758 if logger.logger_ops:
759 logger.logger_ops.log_bridge(inputargs, operations, "rewritten",
760 faildescr, ops_offset=ops_offset)
761
762 self.teardown()
763
764 return AsmInfo(ops_offset, startpos + rawstart, codeendpos - startpos)
765
766 def reserve_gcref_table(self, allgcrefs):
767 gcref_table_size = len(allgcrefs) * WORD
768 # align to a multiple of 16 and reserve space at the beginning
769 # of the machine code for the gc table. This lets us write
770 # machine code with relative addressing (see load_from_gc_table())
771 gcref_table_size = (gcref_table_size + 15) & ~15
772 mc = self.mc
773 assert mc.get_relative_pos() == 0
774 for i in range(gcref_table_size):
775 mc.writechar('\x00')
776 self.setup_gcrefs_list(allgcrefs)
777
778 def patch_gcref_table(self, looptoken, rawstart):
779 # the gc table is at the start of the machine code. Fill it now
780 tracer = self.cpu.gc_ll_descr.make_gcref_tracer(rawstart,
781 self._allgcrefs)
782 gcreftracers = self.get_asmmemmgr_gcreftracers(looptoken)
783 gcreftracers.append(tracer) # keepalive
784 self.teardown_gcrefs_list()
785
786 def load_from_gc_table(self, regnum, index):
787 """emits either:
788 LDR Rt, [PC, #offset] if -4095 <= offset
789 or:
790 gen_load_int(Rt, offset)
791 LDR Rt, [PC, Rt] for larger offsets
792 """
793 mc = self.mc
794 address_in_buffer = index * WORD # at the start of the buffer
795 offset = address_in_buffer - (mc.get_relative_pos() + 8) # negative
796 if offset >= -4095:
797 mc.LDR_ri(regnum, r.pc.value, offset)
798 else:
799 # The offset we're loading is negative: right now,
800 # gen_load_int() will always use exactly
801 # get_max_size_of_gen_load_int() instructions. No point
802 # in optimizing in case we get less. Just in case though,
803 # we check and pad with nops.
804 extra_bytes = mc.get_max_size_of_gen_load_int() * 4
805 offset -= extra_bytes
806 start = mc.get_relative_pos()
807 mc.gen_load_int(regnum, offset)
808 missing = start + extra_bytes - mc.get_relative_pos()
809 while missing > 0:
810 mc.NOP()
811 missing = start + extra_bytes - mc.get_relative_pos()
812 assert missing == 0
813 mc.LDR_rr(regnum, r.pc.value, regnum)
814
815 def new_stack_loc(self, i, tp):
816 base_ofs = self.cpu.get_baseofs_of_frame_field()
817 return StackLocation(i, get_fp_offset(base_ofs, i), tp)
818
819 def check_frame_before_jump(self, target_token):
820 if target_token in self.target_tokens_currently_compiling:
821 return
822 if target_token._arm_clt is self.current_clt:
823 return
824 # We can have a frame coming from god knows where that's
825 # passed to a jump to another loop. Make sure it has the
826 # correct depth
827 expected_size = target_token._arm_clt.frame_info.jfi_frame_depth
828 self._check_frame_depth(self.mc, self._regalloc.get_gcmap(),
829 expected_size=expected_size)
830
831 def _patch_frame_depth(self, adr, allocated_depth):
832 mc = InstrBuilder(self.cpu.cpuinfo.arch_version)
833 mc.gen_load_int(r.lr.value, allocated_depth)
834 mc.copy_to_raw_memory(adr)
835
836 def _check_frame_depth(self, mc, gcmap, expected_size=-1):
837 """ check if the frame is of enough depth to follow this bridge.
838 Otherwise reallocate the frame in a helper.
839 There are other potential solutions
840 to that, but this one does not sound too bad.
841 """
842 descrs = self.cpu.gc_ll_descr.getframedescrs(self.cpu)
843 ofs = self.cpu.unpack_fielddescr(descrs.arraydescr.lendescr)
844 mc.LDR_ri(r.ip.value, r.fp.value, imm=ofs)
845 stack_check_cmp_ofs = mc.currpos()
846 if expected_size == -1:
847 for _ in range(mc.get_max_size_of_gen_load_int()):
848 mc.NOP()
849 else:
850 mc.gen_load_int(r.lr.value, expected_size)
851 mc.CMP_rr(r.ip.value, r.lr.value)
852
853 jg_location = mc.currpos()
854 mc.BKPT()
855
856 # the size value is still stored in lr
857 mc.PUSH([r.lr.value])
858
859 self.push_gcmap(mc, gcmap, push=True)
860
861 self.mc.BL(self._frame_realloc_slowpath)
862
863 # patch jg_location above
864 currpos = self.mc.currpos()
865 pmc = OverwritingBuilder(mc, jg_location, WORD)
866 pmc.B_offs(currpos, c.GE)
867
868 self.frame_depth_to_patch.append(stack_check_cmp_ofs)
869
870 def _check_frame_depth_debug(self, mc):
871 """ double check the depth size. It prints the error (and potentially
872 segfaults later)
873 """
874 if not self.DEBUG_FRAME_DEPTH:
875 return
876 descrs = self.cpu.gc_ll_descr.getframedescrs(self.cpu)
877 ofs = self.cpu.unpack_fielddescr(descrs.arraydescr.lendescr)
878 mc.LDR_ri(r.ip.value, r.fp.value, imm=ofs)
879 stack_check_cmp_ofs = mc.currpos()
880 for _ in range(mc.get_max_size_of_gen_load_int()):
881 mc.NOP()
882 mc.CMP_rr(r.ip.value, r.lr.value)
883
884 jg_location = mc.currpos()
885 mc.BKPT()
886
887 mc.MOV_rr(r.r0.value, r.fp.value)
888 mc.MOV_ri(r.r1.value, r.lr.value)
889
890 self.mc.BL(self.cpu.realloc_frame_crash)
891 # patch the JG above
892 currpos = self.mc.currpos()
893 pmc = OverwritingBuilder(mc, jg_location, WORD)
894 pmc.B_offs(currpos, c.GE)
895
896 self.frame_depth_to_patch.append(stack_check_cmp_ofs)
897
898 def build_frame_realloc_slowpath(self):
899 # this code should do the following steps
900 # a) store all registers in the jitframe
901 # b) fish for the arguments passed by the caller
902 # c) store the gcmap in the jitframe
903 # d) call realloc_frame
904 # e) set the fp to point to the new jitframe
905 # f) store the address of the new jitframe in the shadowstack
906 # c) set the gcmap field to 0 in the new jitframe
907 # g) restore registers and return
908 mc = InstrBuilder(self.cpu.cpuinfo.arch_version)
909 self._push_all_regs_to_jitframe(mc, [], self.cpu.supports_floats)
910 # this is the gcmap stored by push_gcmap(mov=True) in _check_stack_frame
911 # and the expected_size pushed in _check_stack_frame
912 # pop the values passed on the stack, gcmap -> r0, expected_size -> r1
913 mc.POP([r.r0.value, r.r1.value])
914 # store return address and keep the stack aligned
915 mc.PUSH([r.ip.value, r.lr.value])
916
917 # store the current gcmap(r0) in the jitframe
918 gcmap_ofs = self.cpu.get_ofs_of_frame_field('jf_gcmap')
919 assert check_imm_arg(abs(gcmap_ofs))
920 mc.STR_ri(r.r0.value, r.fp.value, imm=gcmap_ofs)
921
922 # set first arg, which is the old jitframe address
923 mc.MOV_rr(r.r0.value, r.fp.value)
924
925 # store a possibly present exception
926 # we use a callee saved reg here as a tmp for the exc.
927 self._store_and_reset_exception(mc, None, r.r4, on_frame=True)
928
929 # call realloc_frame, it takes two arguments
930 # arg0: the old jitframe
931 # arg1: the new size
932 #
933 mc.BL(self.cpu.realloc_frame)
934
935 # set fp to the new jitframe returned from the previous call
936 mc.MOV_rr(r.fp.value, r.r0.value)
937
938 # restore a possibly present exception
939 self._restore_exception(mc, None, r.r4)
940
941 gcrootmap = self.cpu.gc_ll_descr.gcrootmap
942 if gcrootmap and gcrootmap.is_shadow_stack:
943 self._load_shadowstack_top(mc, r.r5, gcrootmap)
944 # store the new jitframe addr in the shadowstack
945 mc.STR_ri(r.r0.value, r.r5.value, imm=-WORD)
946
947 # reset the jf_gcmap field in the jitframe
948 mc.gen_load_int(r.ip.value, 0)
949 mc.STR_ri(r.ip.value, r.fp.value, imm=gcmap_ofs)
950
951 # restore registers
952 self._pop_all_regs_from_jitframe(mc, [], self.cpu.supports_floats)
953 mc.POP([r.ip.value, r.pc.value]) # return
954 self._frame_realloc_slowpath = mc.materialize(self.cpu, [])
955
956 def _load_shadowstack_top(self, mc, reg, gcrootmap):
957 rst = gcrootmap.get_root_stack_top_addr()
958 mc.gen_load_int(reg.value, rst)
959 self.load_reg(mc, reg, reg)
960 return rst
961
962 def fixup_target_tokens(self, rawstart):
963 for targettoken in self.target_tokens_currently_compiling:
964 targettoken._ll_loop_code += rawstart
965 self.target_tokens_currently_compiling = None
966
967 def _patch_stackadjust(self, adr, allocated_depth):
968 mc = InstrBuilder(self.cpu.cpuinfo.arch_version)
969 mc.gen_load_int(r.lr.value, allocated_depth)
970 mc.copy_to_raw_memory(adr)
971
972 def patch_stack_checks(self, framedepth, rawstart):
973 for ofs in self.frame_depth_to_patch:
974 self._patch_frame_depth(ofs + rawstart, framedepth)
975
976 def target_arglocs(self, loop_token):
977 return loop_token._arm_arglocs
978
979 def materialize_loop(self, looptoken):
980 self.datablockwrapper.done() # finish using cpu.asmmemmgr
981 self.datablockwrapper = None
982 allblocks = self.get_asmmemmgr_blocks(looptoken)
983 size = self.mc.get_relative_pos()
984 res = self.mc.materialize(self.cpu, allblocks,
985 self.cpu.gc_ll_descr.gcrootmap)
986 #self.cpu.codemap.register_codemap(
987 # self.codemap.get_final_bytecode(res, size))
988 return res
989
990 def update_frame_depth(self, frame_depth):
991 baseofs = self.cpu.get_baseofs_of_frame_field()
992 self.current_clt.frame_info.update_frame_depth(baseofs, frame_depth)
993
994 def write_pending_failure_recoveries(self):
995 for tok in self.pending_guards:
996 #generate the exit stub and the encoded representation
997 tok.pos_recovery_stub = self.generate_quick_failure(tok)
998
999 def process_pending_guards(self, block_start):
1000 clt = self.current_clt
1001 for tok in self.pending_guards:
1002 descr = tok.faildescr
1003 assert isinstance(descr, AbstractFailDescr)
1004 failure_recovery_pos = block_start + tok.pos_recovery_stub
1005 descr.adr_jump_offset = failure_recovery_pos
1006 relative_offset = tok.pos_recovery_stub - tok.offset
1007 guard_pos = block_start + tok.offset
1008 if not tok.guard_not_invalidated():
1009 # patch the guard jump to the stub
1010 # overwrite the generate NOP with a B_offs to the pos of the
1011 # stub
1012 mc = InstrBuilder(self.cpu.cpuinfo.arch_version)
1013 mc.B_offs(relative_offset, c.get_opposite_of(tok.fcond))
1014 mc.copy_to_raw_memory(guard_pos)
1015 else:
1016 clt.invalidate_positions.append((guard_pos, relative_offset))
1017
1018 def _walk_operations(self, inputargs, operations, regalloc):
1019 fcond = c.AL
1020 self._regalloc = regalloc
1021 regalloc.operations = operations
1022 while regalloc.position() < len(operations) - 1:
1023 regalloc.next_instruction()
1024 i = regalloc.position()
1025 op = operations[i]
1026 self.mc.mark_op(op)
1027 opnum = op.getopnum()
1028 if rop.has_no_side_effect(opnum) and op not in regalloc.longevity:
1029 regalloc.possibly_free_vars_for_op(op)
1030 elif not we_are_translated() and op.getopnum() == rop.FORCE_SPILL:
1031 regalloc.prepare_force_spill(op, fcond)
1032 else:
1033 arglocs = regalloc_operations[opnum](regalloc, op, fcond)
1034 if arglocs is not None:
1035 fcond = asm_operations[opnum](self, op, arglocs,
1036 regalloc, fcond)
1037 assert fcond is not None
1038 if rop.is_guard(opnum):
1039 regalloc.possibly_free_vars(op.getfailargs())
1040 if op.type != 'v':
1041 regalloc.possibly_free_var(op)
1042 regalloc.possibly_free_vars_for_op(op)
1043 regalloc.free_temp_vars()
1044 regalloc._check_invariants()
1045 if not we_are_translated():
1046 self.mc.BKPT()
1047 self.mc.mark_op(None) # end of the loop
1048 regalloc.operations = None
1049
1050 def regalloc_emit_extra(self, op, arglocs, fcond, regalloc):
1051 # for calls to a function with a specifically-supported OS_xxx
1052 effectinfo = op.getdescr().get_extra_info()
1053 oopspecindex = effectinfo.oopspecindex
1054 asm_extra_operations[oopspecindex](self, op, arglocs, regalloc, fcond)
1055 return fcond
1056
1057 def patch_trace(self, faildescr, looptoken, bridge_addr, regalloc):
1058 b = InstrBuilder(self.cpu.cpuinfo.arch_version)
1059 patch_addr = faildescr.adr_jump_offset
1060 assert patch_addr != 0
1061 b.B(bridge_addr)
1062 b.copy_to_raw_memory(patch_addr)
1063 faildescr.adr_jump_offset = 0
1064
1065 # regalloc support
1066 def load(self, loc, value):
1067 """load an immediate value into a register"""
1068 assert (loc.is_core_reg() and value.is_imm()
1069 or loc.is_vfp_reg() and value.is_imm_float())
1070 if value.is_imm():
1071 self.mc.gen_load_int(loc.value, value.getint())
1072 elif value.is_imm_float():
1073 self.mc.gen_load_int(r.ip.value, value.getint())
1074 self.mc.VLDR(loc.value, r.ip.value)
1075
1076 def load_reg(self, mc, target, base, ofs=0, cond=c.AL, helper=r.ip):
1077 if target.is_vfp_reg():
1078 return self._load_vfp_reg(mc, target, base, ofs, cond, helper)
1079 elif target.is_core_reg():
1080 return self._load_core_reg(mc, target, base, ofs, cond, helper)
1081
1082 def _load_vfp_reg(self, mc, target, base, ofs, cond=c.AL, helper=r.ip):
1083 if check_imm_arg(ofs, VMEM_imm_size):
1084 mc.VLDR(target.value, base.value, imm=ofs, cond=cond)
1085 else:
1086 mc.gen_load_int(helper.value, ofs, cond=cond)
1087 mc.ADD_rr(helper.value, base.value, helper.value, cond=cond)
1088 mc.VLDR(target.value, helper.value, cond=cond)
1089
1090 def _load_core_reg(self, mc, target, base, ofs, cond=c.AL, helper=r.ip):
1091 if check_imm_arg(abs(ofs)):
1092 mc.LDR_ri(target.value, base.value, imm=ofs, cond=cond)
1093 else:
1094 mc.gen_load_int(helper.value, ofs, cond=cond)
1095 mc.LDR_rr(target.value, base.value, helper.value, cond=cond)
1096
1097 def store_reg(self, mc, source, base, ofs=0, cond=c.AL, helper=r.ip):
1098 if source.is_vfp_reg():
1099 return self._store_vfp_reg(mc, source, base, ofs, cond, helper)
1100 else:
1101 return self._store_core_reg(mc, source, base, ofs, cond, helper)
1102
1103 def _store_vfp_reg(self, mc, source, base, ofs, cond=c.AL, helper=r.ip):
1104 if check_imm_arg(ofs, VMEM_imm_size):
1105 mc.VSTR(source.value, base.value, imm=ofs, cond=cond)
1106 else:
1107 mc.gen_load_int(helper.value, ofs, cond=cond)
1108 mc.ADD_rr(helper.value, base.value, helper.value, cond=cond)
1109 mc.VSTR(source.value, helper.value, cond=cond)
1110
1111 def _store_core_reg(self, mc, source, base, ofs, cond=c.AL, helper=r.ip):
1112 if check_imm_arg(ofs):
1113 mc.STR_ri(source.value, base.value, imm=ofs, cond=cond)
1114 else:
1115 mc.gen_load_int(helper.value, ofs, cond=cond)
1116 mc.STR_rr(source.value, base.value, helper.value, cond=cond)
1117
1118 def get_tmp_reg(self, forbidden_regs=None):
1119 if forbidden_regs is None:
1120 return r.ip, False
1121 for x in [r.ip, r.lr]:
1122 if x not in forbidden_regs:
1123 return x, False
1124 # pick some reg, that we need to save
1125 for x in r.all_regs:
1126 if x not in forbidden_regs:
1127 return x, True
1128 assert 0
1129
1130 def _mov_imm_to_loc(self, prev_loc, loc, cond=c.AL):
1131 if loc.type == FLOAT:
1132 raise AssertionError("invalid target for move from imm value")
1133 if loc.is_core_reg():
1134 new_loc = loc
1135 elif loc.is_stack() or loc.is_raw_sp():
1136 new_loc = r.lr
1137 else:
1138 raise AssertionError("invalid target for move from imm value")
1139 self.mc.gen_load_int(new_loc.value, prev_loc.value, cond=cond)
1140 if loc.is_stack():
1141 self.regalloc_mov(new_loc, loc)
1142 elif loc.is_raw_sp():
1143 self.store_reg(self.mc, new_loc, r.sp, loc.value, cond=cond, helper=r.ip)
1144
1145 def _mov_reg_to_loc(self, prev_loc, loc, cond=c.AL):
1146 if loc.is_imm():
1147 raise AssertionError("mov reg to imm doesn't make sense")
1148 if loc.is_core_reg():
1149 self.mc.MOV_rr(loc.value, prev_loc.value, cond=cond)
1150 elif loc.is_stack() and loc.type != FLOAT:
1151 # spill a core register
1152 temp, save = self.get_tmp_reg([prev_loc, loc])
1153 offset = loc.value
1154 is_imm = check_imm_arg(offset, size=0xFFF)
1155 if not is_imm and save:
1156 self.mc.PUSH([temp.value], cond=cond)
1157 self.store_reg(self.mc, prev_loc, r.fp, offset, helper=temp, cond=cond)
1158 if not is_imm and save:
1159 self.mc.POP([temp.value], cond=cond)
1160 elif loc.is_raw_sp() and loc.type != FLOAT:
1161 temp, save = self.get_tmp_reg([prev_loc])
1162 assert not save
1163 self.store_reg(self.mc, prev_loc, r.sp, loc.value, cond=cond, helper=temp)
1164 else:
1165 assert 0, 'unsupported case'
1166
1167 def _mov_stack_to_loc(self, prev_loc, loc, cond=c.AL):
1168 helper = None
1169 offset = prev_loc.value
1170 tmp = None
1171 if loc.is_core_reg():
1172 assert prev_loc.type != FLOAT, 'trying to load from an \
1173 incompatible location into a core register'
1174 # unspill a core register
1175 is_imm = check_imm_arg(offset, size=0xFFF)
1176 helper, save = self.get_tmp_reg([loc])
1177 save_helper = not is_imm and save
1178 elif loc.is_vfp_reg():
1179 assert prev_loc.type == FLOAT, 'trying to load from an \
1180 incompatible location into a float register'
1181 # load spilled value into vfp reg
1182 is_imm = check_imm_arg(offset)
1183 helper, save = self.get_tmp_reg()
1184 save_helper = not is_imm and save
1185 elif loc.is_raw_sp():
1186 assert (loc.type == prev_loc.type == FLOAT
1187 or (loc.type != FLOAT and prev_loc.type != FLOAT))
1188 tmp = loc
1189 if loc.is_float():
1190 loc = r.vfp_ip
1191 else:
1192 loc, save_helper = self.get_tmp_reg()
1193 assert not save_helper
1194 helper, save_helper = self.get_tmp_reg([loc])
1195 assert not save_helper
1196 else:
1197 assert 0, 'unsupported case'
1198
1199 if save_helper:
1200 self.mc.PUSH([helper.value], cond=cond)
1201 self.load_reg(self.mc, loc, r.fp, offset, cond=cond, helper=helper)
1202 if save_helper:
1203 self.mc.POP([helper.value], cond=cond)
1204
1205 if tmp and tmp.is_raw_sp():
1206 self.store_reg(self.mc, loc, r.sp, tmp.value, cond=cond, helper=helper)
1207
1208 def _mov_imm_float_to_loc(self, prev_loc, loc, cond=c.AL):
1209 if loc.is_vfp_reg():
1210 helper, save_helper = self.get_tmp_reg([loc])
1211 if save_helper:
1212 self.mc.PUSH([helper.value], cond=cond)
1213 self.mc.gen_load_int(helper.value, prev_loc.getint(), cond=cond)
1214 self.load_reg(self.mc, loc, helper, 0, cond=cond)
1215 if save_helper:
1216 self.mc.POP([helper.value], cond=cond)
1217 elif loc.is_stack() and loc.type == FLOAT:
1218 self.regalloc_mov(prev_loc, r.vfp_ip, cond)
1219 self.regalloc_mov(r.vfp_ip, loc, cond)
1220 elif loc.is_raw_sp() and loc.type == FLOAT:
1221 self.regalloc_mov(prev_loc, r.vfp_ip, cond)
1222 self.regalloc_mov(r.vfp_ip, loc, cond)
1223 else:
1224 assert 0, 'unsupported case'
1225
1226 def _mov_vfp_reg_to_loc(self, prev_loc, loc, cond=c.AL):
1227 if loc.is_vfp_reg():
1228 self.mc.VMOV_cc(loc.value, prev_loc.value, cond=cond)
1229 elif loc.is_stack():
1230 assert loc.type == FLOAT, 'trying to store to an \
1231 incompatible location from a float register'
1232 # spill vfp register
1233 offset = loc.value
1234 is_imm = check_imm_arg(offset)
1235 self.store_reg(self.mc, prev_loc, r.fp, offset, cond=cond, helper=r.ip)
1236 elif loc.is_raw_sp():
1237 assert loc.type == FLOAT, 'trying to store to an \
1238 incompatible location from a float register'
1239 self.store_reg(self.mc, prev_loc, r.sp, loc.value, cond=cond)
1240 else:
1241 assert 0, 'unsupported case'
1242
1243 def _mov_raw_sp_to_loc(self, prev_loc, loc, cond=c.AL):
1244 if loc.is_core_reg():
1245 # load a value from 'SP + n'
1246 assert prev_loc.value <= 0xFFF # not too far
1247 self.load_reg(self.mc, loc, r.sp, prev_loc.value, cond=cond)
1248 else:
1249 assert 0, 'unsupported case'
1250
1251 def regalloc_mov(self, prev_loc, loc, cond=c.AL):
1252 """Moves a value from a previous location to some other location"""
1253 if prev_loc.is_imm():
1254 return self._mov_imm_to_loc(prev_loc, loc, cond)
1255 elif prev_loc.is_core_reg():
1256 self._mov_reg_to_loc(prev_loc, loc, cond)
1257 elif prev_loc.is_stack():
1258 self._mov_stack_to_loc(prev_loc, loc, cond)
1259 elif prev_loc.is_imm_float():
1260 self._mov_imm_float_to_loc(prev_loc, loc, cond)
1261 elif prev_loc.is_vfp_reg():
1262 self._mov_vfp_reg_to_loc(prev_loc, loc, cond)
1263 elif prev_loc.is_raw_sp():
1264 self._mov_raw_sp_to_loc(prev_loc, loc, cond)
1265 else:
1266 assert 0, 'unsupported case'
1267 mov_loc_loc = regalloc_mov
1268
1269 def mov_from_vfp_loc(self, vfp_loc, reg1, reg2, cond=c.AL):
1270 """Moves floating point values either as an immediate, in a vfp
1271 register or at a stack location to a pair of core registers"""
1272 assert reg1.value + 1 == reg2.value
1273 if vfp_loc.is_vfp_reg():
1274 self.mc.VMOV_rc(reg1.value, reg2.value, vfp_loc.value, cond=cond)
1275 elif vfp_loc.is_imm_float():
1276 helper, save_helper = self.get_tmp_reg([reg1, reg2])
1277 if save_helper:
1278 self.mc.PUSH([helper.value], cond=cond)
1279 self.mc.gen_load_int(helper.value, vfp_loc.getint(), cond=cond)
1280 # we need to load one word to loc and one to loc+1 which are
1281 # two 32-bit core registers
1282 self.mc.LDR_ri(reg1.value, helper.value, cond=cond)
1283 self.mc.LDR_ri(reg2.value, helper.value, imm=WORD, cond=cond)
1284 if save_helper:
1285 self.mc.POP([helper.value], cond=cond)
1286 elif vfp_loc.is_stack() and vfp_loc.type == FLOAT:
1287 # load spilled vfp value into two core registers
1288 offset = vfp_loc.value
1289 if not check_imm_arg(offset, size=0xFFF):
1290 helper, save_helper = self.get_tmp_reg([reg1, reg2])
1291 if save_helper:
1292 self.mc.PUSH([helper.value], cond=cond)
1293 self.mc.gen_load_int(helper.value, offset, cond=cond)
1294 self.mc.LDR_rr(reg1.value, r.fp.value, helper.value, cond=cond)
1295 self.mc.ADD_ri(helper.value, helper.value, imm=WORD, cond=cond)
1296 self.mc.LDR_rr(reg2.value, r.fp.value, helper.value, cond=cond)
1297 if save_helper:
1298 self.mc.POP([helper.value], cond=cond)
1299 else:
1300 self.mc.LDR_ri(reg1.value, r.fp.value, imm=offset, cond=cond)
1301 self.mc.LDR_ri(reg2.value, r.fp.value,
1302 imm=offset + WORD, cond=cond)
1303 else:
1304 assert 0, 'unsupported case'
1305
1306 def mov_to_vfp_loc(self, reg1, reg2, vfp_loc, cond=c.AL):
1307 """Moves a floating point value from to consecutive core registers to a
1308 vfp location, either a vfp regsiter or a stacklocation"""
1309 assert reg1.value + 1 == reg2.value
1310 if vfp_loc.is_vfp_reg():
1311 self.mc.VMOV_cr(vfp_loc.value, reg1.value, reg2.value, cond=cond)
1312 elif vfp_loc.is_stack():
1313 # move from two core registers to a float stack location
1314 offset = vfp_loc.value
1315 if not check_imm_arg(offset + WORD, size=0xFFF):
1316 helper, save_helper = self.get_tmp_reg([reg1, reg2])
1317 if save_helper:
1318 self.mc.PUSH([helper.value], cond=cond)
1319 self.mc.gen_load_int(helper.value, offset, cond=cond)
1320 self.mc.STR_rr(reg1.value, r.fp.value, helper.value, cond=cond)
1321 self.mc.ADD_ri(helper.value, helper.value, imm=WORD, cond=cond)
1322 self.mc.STR_rr(reg2.value, r.fp.value, helper.value, cond=cond)
1323 if save_helper:
1324 self.mc.POP([helper.value], cond=cond)
1325 else:
1326 self.mc.STR_ri(reg1.value, r.fp.value, imm=offset, cond=cond)
1327 self.mc.STR_ri(reg2.value, r.fp.value,
1328 imm=offset + WORD, cond=cond)
1329 else:
1330 assert 0, 'unsupported case'
1331
1332 def regalloc_push(self, loc, cond=c.AL):
1333 """Pushes the value stored in loc to the stack
1334 Can trash the current value of the IP register when pushing a stack
1335 loc"""
1336
1337 if loc.is_stack():
1338 if loc.type != FLOAT:
1339 scratch_reg = r.ip
1340 else:
1341 scratch_reg = r.vfp_ip
1342 self.regalloc_mov(loc, scratch_reg, cond)
1343 self.regalloc_push(scratch_reg, cond)
1344 elif loc.is_core_reg():
1345 self.mc.PUSH([loc.value], cond=cond)
1346 elif loc.is_vfp_reg():
1347 self.mc.VPUSH([loc.value], cond=cond)
1348 elif loc.is_imm():
1349 self.regalloc_mov(loc, r.ip)
1350 self.mc.PUSH([r.ip.value], cond=cond)
1351 elif loc.is_imm_float():
1352 self.regalloc_mov(loc, r.vfp_ip)
1353 self.mc.VPUSH([r.vfp_ip.value], cond=cond)
1354 else:
1355 raise AssertionError('Trying to push an invalid location')
1356
1357 def regalloc_pop(self, loc, cond=c.AL):
1358 """Pops the value on top of the stack to loc Can trash the current
1359 value of the IP register when popping to a stack loc"""
1360 if loc.is_stack():
1361 if loc.type != FLOAT:
1362 scratch_reg = r.ip
1363 else:
1364 scratch_reg = r.vfp_ip
1365 self.regalloc_pop(scratch_reg)
1366 self.regalloc_mov(scratch_reg, loc)
1367 elif loc.is_core_reg():
1368 self.mc.POP([loc.value], cond=cond)
1369 elif loc.is_vfp_reg():
1370 self.mc.VPOP([loc.value], cond=cond)
1371 else:
1372 raise AssertionError('Trying to pop to an invalid location')
1373
1374 def malloc_cond(self, nursery_free_adr, nursery_top_adr, size, gcmap):
1375 assert size & (WORD-1) == 0
1376
1377 self.mc.gen_load_int(r.r0.value, nursery_free_adr)
1378 self.mc.LDR_ri(r.r0.value, r.r0.value)
1379
1380 if check_imm_arg(size):
1381 self.mc.ADD_ri(r.r1.value, r.r0.value, size)
1382 else:
1383 self.mc.gen_load_int(r.r1.value, size)
1384 self.mc.ADD_rr(r.r1.value, r.r0.value, r.r1.value)
1385
1386 self.mc.gen_load_int(r.ip.value, nursery_top_adr)
1387 self.mc.LDR_ri(r.ip.value, r.ip.value)
1388
1389 self.mc.CMP_rr(r.r1.value, r.ip.value)
1390
1391 # We load into r0 the address stored at nursery_free_adr We calculate
1392 # the new value for nursery_free_adr and store in r1 The we load the
1393 # address stored in nursery_top_adr into IP If the value in r1 is
1394 # (unsigned) bigger than the one in ip we conditionally call
1395 # malloc_slowpath in case we called malloc_slowpath, which returns the
1396 # new value of nursery_free_adr in r1 and the adr of the new object in
1397 # r0.
1398 self.push_gcmap(self.mc, gcmap, push=True, cond=c.HI)
1399
1400 self.mc.BL(self.malloc_slowpath, c=c.HI)
1401
1402 self.mc.gen_load_int(r.ip.value, nursery_free_adr)
1403 self.mc.STR_ri(r.r1.value, r.ip.value)
1404
1405 def malloc_cond_varsize_frame(self, nursery_free_adr, nursery_top_adr,
1406 sizeloc, gcmap):
1407 if sizeloc is r.r0:
1408 self.mc.MOV_rr(r.r1.value, r.r0.value)
1409 sizeloc = r.r1
1410 self.mc.gen_load_int(r.r0.value, nursery_free_adr)
1411 self.mc.LDR_ri(r.r0.value, r.r0.value)
1412 #
1413 self.mc.ADD_rr(r.r1.value, r.r0.value, sizeloc.value)
1414 #
1415 self.mc.gen_load_int(r.ip.value, nursery_top_adr)
1416 self.mc.LDR_ri(r.ip.value, r.ip.value)
1417
1418 self.mc.CMP_rr(r.r1.value, r.ip.value)
1419 #
1420 self.push_gcmap(self.mc, gcmap, push=True, cond=c.HI)
1421
1422 self.mc.BL(self.malloc_slowpath, c=c.HI)
1423
1424 self.mc.gen_load_int(r.ip.value, nursery_free_adr)
1425 self.mc.STR_ri(r.r1.value, r.ip.value)
1426
1427 def malloc_cond_varsize(self, kind, nursery_free_adr, nursery_top_adr,
1428 lengthloc, itemsize, maxlength, gcmap,
1429 arraydescr):
1430 from rpython.jit.backend.llsupport.descr import ArrayDescr
1431 assert isinstance(arraydescr, ArrayDescr)
1432
1433 # lengthloc is the length of the array, which we must not modify!
1434 assert lengthloc is not r.r0 and lengthloc is not r.r1
1435 if lengthloc.is_core_reg():
1436 varsizeloc = lengthloc
1437 else:
1438 assert lengthloc.is_stack()
1439 self.regalloc_mov(lengthloc, r.r1)
1440 varsizeloc = r.r1
1441 #
1442 if check_imm_arg(maxlength):
1443 self.mc.CMP_ri(varsizeloc.value, maxlength)
1444 else:
1445 self.mc.gen_load_int(r.ip.value, maxlength)
1446 self.mc.CMP_rr(varsizeloc.value, r.ip.value)
1447 jmp_adr0 = self.mc.currpos() # jump to (large)
1448 self.mc.BKPT()
1449 #
1450 self.mc.gen_load_int(r.r0.value, nursery_free_adr)
1451 self.mc.LDR_ri(r.r0.value, r.r0.value)
1452
1453
1454 if valid_addressing_size(itemsize):
1455 shiftsize = get_scale(itemsize)
1456 else:
1457 shiftsize = self._mul_const_scaled(self.mc, r.lr, varsizeloc,
1458 itemsize)
1459 varsizeloc = r.lr
1460 # now varsizeloc is a register != r0. The size of
1461 # the variable part of the array is (varsizeloc << shiftsize)
1462 assert arraydescr.basesize >= self.gc_minimal_size_in_nursery
1463 constsize = arraydescr.basesize + self.gc_size_of_header
1464 force_realignment = (itemsize % WORD) != 0
1465 if force_realignment:
1466 constsize += WORD - 1
1467 self.mc.gen_load_int(r.ip.value, constsize)
1468 # constsize + (varsizeloc << shiftsize)
1469 self.mc.ADD_rr(r.r1.value, r.ip.value, varsizeloc.value,
1470 imm=shiftsize, shifttype=shift.LSL)
1471 self.mc.ADD_rr(r.r1.value, r.r1.value, r.r0.value)
1472 if force_realignment:
1473 self.mc.MVN_ri(r.ip.value, imm=(WORD - 1))
1474 self.mc.AND_rr(r.r1.value, r.r1.value, r.ip.value)
1475 # now r1 contains the total size in bytes, rounded up to a multiple
1476 # of WORD, plus nursery_free_adr
1477 #
1478 self.mc.gen_load_int(r.ip.value, nursery_top_adr)
1479 self.mc.LDR_ri(r.ip.value, r.ip.value)
1480
1481 self.mc.CMP_rr(r.r1.value, r.ip.value)
1482 jmp_adr1 = self.mc.currpos() # jump to (after-call)
1483 self.mc.BKPT()
1484 #
1485 # (large)
1486 currpos = self.mc.currpos()
1487 pmc = OverwritingBuilder(self.mc, jmp_adr0, WORD)
1488 pmc.B_offs(currpos, c.GT)
1489 #
1490 # save the gcmap
1491 self.push_gcmap(self.mc, gcmap, push=True)
1492 #
1493 if kind == rewrite.FLAG_ARRAY:
1494 self.mc.gen_load_int(r.r0.value, arraydescr.tid)
1495 self.regalloc_mov(lengthloc, r.r1)
1496 self.regalloc_push(imm(itemsize))
1497 addr = self.malloc_slowpath_varsize
1498 else:
1499 if kind == rewrite.FLAG_STR:
1500 addr = self.malloc_slowpath_str
1501 else:
1502 assert kind == rewrite.FLAG_UNICODE
1503 addr = self.malloc_slowpath_unicode
1504 self.regalloc_mov(lengthloc, r.r1)
1505 self.mc.BL(addr)
1506 #
1507 jmp_location = self.mc.currpos() # jump to (done)
1508 self.mc.BKPT()
1509 # (after-call)
1510 currpos = self.mc.currpos()
1511 pmc = OverwritingBuilder(self.mc, jmp_adr1, WORD)
1512 pmc.B_offs(currpos, c.LS)
1513 #
1514 # write down the tid, but not if it's the result of the CALL
1515 self.mc.gen_load_int(r.ip.value, arraydescr.tid)
1516 self.mc.STR_ri(r.ip.value, r.r0.value)
1517
1518 # while we're at it, this line is not needed if we've done the CALL
1519 self.mc.gen_load_int(r.ip.value, nursery_free_adr)
1520 self.mc.STR_ri(r.r1.value, r.ip.value)
1521 # (done)
1522 # skip instructions after call
1523 currpos = self.mc.currpos()
1524 pmc = OverwritingBuilder(self.mc, jmp_location, WORD)
1525 pmc.B_offs(currpos)
1526
1527 def push_gcmap(self, mc, gcmap, push=False, store=False, cond=c.AL):
1528 ptr = rffi.cast(lltype.Signed, gcmap)
1529 if push:
1530 mc.gen_load_int(r.ip.value, ptr, cond=cond)
1531 mc.PUSH([r.ip.value], cond=cond)
1532 else:
1533 assert store
1534 ofs = self.cpu.get_ofs_of_frame_field('jf_gcmap')
1535 mc.gen_load_int(r.ip.value, ptr, cond=cond)
1536 mc.STR_ri(r.ip.value, r.fp.value, imm=ofs, cond=cond)
1537
1538 def pop_gcmap(self, mc):
1539 ofs = self.cpu.get_ofs_of_frame_field('jf_gcmap')
1540 assert check_imm_arg(ofs)
1541 mc.gen_load_int(r.ip.value, 0)
1542 self.store_reg(mc, r.ip, r.fp, ofs)
1543
1544 def _mul_const_scaled(self, mc, targetreg, sourcereg, itemsize):
1545 """Produce one operation to do roughly
1546 targetreg = sourcereg * itemsize
1547 except that the targetreg may still need shifting by 0,1,2,3.
1548 """
1549 if (itemsize & 7) == 0:
1550 shiftsize = 3
1551 elif (itemsize & 3) == 0:
1552 shiftsize = 2
1553 elif (itemsize & 1) == 0:
1554 shiftsize = 1
1555 else:
1556 shiftsize = 0
1557 itemsize >>= shiftsize
1558 #
1559 if valid_addressing_size(itemsize - 1):
1560 self.mc.ADD_rr(targetreg.value, sourcereg.value, sourcereg.value,
1561 imm=get_scale(itemsize - 1), shifttype=shift.LSL)
1562 elif valid_addressing_size(itemsize):
1563 self.mc.LSL_ri(targetreg.value, sourcereg.value,
1564 get_scale(itemsize))
1565 else:
1566 mc.gen_load_int(targetreg.value, itemsize)
1567 mc.MUL(targetreg.value, sourcereg.value, targetreg.value)
1568 #
1569 return shiftsize
1570
1571 def simple_call(self, fnloc, arglocs, result_loc=r.r0):
1572 if result_loc is None:
1573 result_type = VOID
1574 result_size = 0
1575 elif result_loc.is_vfp_reg():
1576 result_type = FLOAT
1577 result_size = DOUBLE_WORD
1578 else:
1579 result_type = INT
1580 result_size = WORD
1581 cb = callbuilder.get_callbuilder(self.cpu, self, fnloc, arglocs,
1582 result_loc, result_type,
1583 result_size)
1584 cb.emit()
1585
1586 def simple_call_no_collect(self, fnloc, arglocs):
1587 cb = callbuilder.get_callbuilder(self.cpu, self, fnloc, arglocs)
1588 cb.emit_no_collect()
1589
1590
1591 def not_implemented(msg):
1592 msg = '[ARM/asm] %s\n' % msg
1593 if we_are_translated():
1594 llop.debug_print(lltype.Void, msg)
1595 raise NotImplementedError(msg)
1596
1597
1598 def notimplemented_op(self, op, arglocs, regalloc, fcond):
1599 print("[ARM/asm] %s not implemented" % op.getopname())
1600 raise NotImplementedError(op)
1601
1602
1603 asm_operations = [notimplemented_op] * (rop._LAST + 1)
1604 asm_extra_operations = {}
1605
1606 for name, value in ResOpAssembler.__dict__.iteritems():
1607 if name.startswith('emit_opx_'):
1608 opname = name[len('emit_opx_'):]
1609 num = getattr(EffectInfo, 'OS_' + opname.upper())
1610 asm_extra_operations[num] = value
1611 elif name.startswith('emit_op_'):
1612 opname = name[len('emit_op_'):]
1613 num = getattr(rop, opname.upper())
1614 asm_operations[num] = value
1615
1616
1617 class BridgeAlreadyCompiled(Exception):
1618 pass