| 1 |
|
| 2 |
""" Register allocation scheme. |
| 3 |
""" |
| 4 |
|
| 5 |
from rpython.jit.backend.llsupport import symbolic |
| 6 |
from rpython.jit.backend.llsupport.descr import CallDescr, unpack_arraydescr |
| 7 |
from rpython.jit.backend.llsupport.gcmap import allocate_gcmap |
| 8 |
from rpython.jit.backend.llsupport.regalloc import (FrameManager, BaseRegalloc, |
| 9 |
RegisterManager, TempVar, compute_vars_longevity, |
| 10 |
valid_addressing_size, get_scale, SAVE_DEFAULT_REGS, SAVE_GCREF_REGS, |
| 11 |
SAVE_ALL_REGS) |
| 12 |
from rpython.jit.backend.x86 import rx86 |
| 13 |
from rpython.jit.backend.x86.arch import (WORD, JITFRAME_FIXED_SIZE, IS_X86_32, |
| 14 |
IS_X86_64, DEFAULT_FRAME_BYTES, WIN64) |
| 15 |
from rpython.jit.backend.x86.jump import remap_frame_layout_mixed |
| 16 |
from rpython.jit.backend.x86.regloc import (FrameLoc, RegLoc, ConstFloatLoc, |
| 17 |
FloatImmedLoc, ImmedLoc, imm, imm0, imm1, ecx, eax, edx, ebx, esi, edi, |
| 18 |
ebp, r8, r9, r10, r11, r12, r13, r14, r15, xmm0, xmm1, xmm2, xmm3, xmm4, |
| 19 |
xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, |
| 20 |
X86_64_SCRATCH_REG, X86_64_XMM_SCRATCH_REG) |
| 21 |
from rpython.jit.backend.x86.vector_ext import VectorRegallocMixin |
| 22 |
from rpython.jit.codewriter import longlong |
| 23 |
from rpython.jit.codewriter.effectinfo import EffectInfo |
| 24 |
from rpython.jit.metainterp.history import (Const, ConstInt, ConstPtr, |
| 25 |
ConstFloat, INT, REF, FLOAT, VECTOR, TargetToken, AbstractFailDescr) |
| 26 |
from rpython.jit.metainterp.resoperation import rop |
| 27 |
from rpython.jit.metainterp.resume import AccumInfo |
| 28 |
from rpython.rlib import rgc |
| 29 |
from rpython.rlib.objectmodel import we_are_translated |
| 30 |
from rpython.rlib.rarithmetic import r_longlong, r_uint |
| 31 |
from rpython.rtyper.lltypesystem import lltype, rffi, rstr |
| 32 |
from rpython.rtyper.lltypesystem.lloperation import llop |
| 33 |
from rpython.jit.backend.x86.regloc import AddressLoc |
| 34 |
|
| 35 |
def compute_gc_level(calldescr, guard_not_forced=False): |
| 36 |
effectinfo = calldescr.get_extra_info() |
| 37 |
if guard_not_forced: |
| 38 |
return SAVE_ALL_REGS |
| 39 |
elif effectinfo is None or effectinfo.check_can_collect(): |
| 40 |
return SAVE_GCREF_REGS |
| 41 |
else: |
| 42 |
return SAVE_DEFAULT_REGS |
| 43 |
|
| 44 |
|
| 45 |
class X86RegisterManager(RegisterManager): |
| 46 |
box_types = [INT, REF] |
| 47 |
all_regs = [ecx, eax, edx, ebx, esi, edi] |
| 48 |
no_lower_byte_regs = [esi, edi] |
| 49 |
save_around_call_regs = [eax, edx, ecx] |
| 50 |
frame_reg = ebp |
| 51 |
|
| 52 |
def call_result_location(self, v): |
| 53 |
return eax |
| 54 |
|
| 55 |
def convert_to_imm(self, c): |
| 56 |
if isinstance(c, ConstInt): |
| 57 |
return imm(c.value) |
| 58 |
elif isinstance(c, ConstPtr): |
| 59 |
if we_are_translated() and c.value and rgc.can_move(c.value): |
| 60 |
not_implemented("convert_to_imm: ConstPtr needs special care") |
| 61 |
return imm(rffi.cast(lltype.Signed, c.value)) |
| 62 |
else: |
| 63 |
not_implemented("convert_to_imm: got a %s" % c) |
| 64 |
|
| 65 |
class X86_64_RegisterManager(X86RegisterManager): |
| 66 |
|
| 67 |
all_regs = [ecx, eax, edx, ebx, esi, edi, r8, r9, r10, r12, r13, r14, r15] |
| 68 |
if WIN64: |
| 69 |
all_regs.remove(r13) |
| 70 |
|
| 71 |
no_lower_byte_regs = [] |
| 72 |
save_around_call_regs = [eax, ecx, edx, esi, edi, r8, r9, r10] |
| 73 |
if WIN64: |
| 74 |
save_around_call_regs.remove(esi) |
| 75 |
save_around_call_regs.remove(edi) |
| 76 |
|
| 77 |
class X86XMMRegisterManager(RegisterManager): |
| 78 |
box_types = [FLOAT, INT] |
| 79 |
all_regs = [xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7] |
| 80 |
|
| 81 |
save_around_call_regs = all_regs |
| 82 |
|
| 83 |
def convert_to_imm(self, c): |
| 84 |
adr = self.assembler.datablockwrapper.malloc_aligned(8, 8) |
| 85 |
x = c.getfloatstorage() |
| 86 |
rffi.cast(rffi.CArrayPtr(longlong.FLOATSTORAGE), adr)[0] = x |
| 87 |
return ConstFloatLoc(adr) |
| 88 |
|
| 89 |
def convert_to_imm_16bytes_align(self, c): |
| 90 |
adr = self.assembler.datablockwrapper.malloc_aligned(16, 16) |
| 91 |
x = c.getfloatstorage() |
| 92 |
y = longlong.ZEROF |
| 93 |
rffi.cast(rffi.CArrayPtr(longlong.FLOATSTORAGE), adr)[0] = x |
| 94 |
rffi.cast(rffi.CArrayPtr(longlong.FLOATSTORAGE), adr)[1] = y |
| 95 |
return ConstFloatLoc(adr) |
| 96 |
|
| 97 |
def expand_float(self, size, const): |
| 98 |
if size == 4: |
| 99 |
loc = self.expand_single_float(const) |
| 100 |
else: |
| 101 |
loc = self.expand_double_float(const) |
| 102 |
return loc |
| 103 |
|
| 104 |
def expand_double_float(self, f): |
| 105 |
adr = self.assembler.datablockwrapper.malloc_aligned(16, 16) |
| 106 |
fs = f.getfloatstorage() |
| 107 |
rffi.cast(rffi.CArrayPtr(longlong.FLOATSTORAGE), adr)[0] = fs |
| 108 |
rffi.cast(rffi.CArrayPtr(longlong.FLOATSTORAGE), adr)[1] = fs |
| 109 |
return ConstFloatLoc(adr) |
| 110 |
|
| 111 |
def expand_single_float(self, f): |
| 112 |
adr = self.assembler.datablockwrapper.malloc_aligned(16, 16) |
| 113 |
fs = rffi.cast(lltype.SingleFloat, f.getfloatstorage()) |
| 114 |
rffi.cast(rffi.CArrayPtr(lltype.SingleFloat), adr)[0] = fs |
| 115 |
rffi.cast(rffi.CArrayPtr(lltype.SingleFloat), adr)[1] = fs |
| 116 |
rffi.cast(rffi.CArrayPtr(lltype.SingleFloat), adr)[2] = fs |
| 117 |
rffi.cast(rffi.CArrayPtr(lltype.SingleFloat), adr)[3] = fs |
| 118 |
return ConstFloatLoc(adr) |
| 119 |
|
| 120 |
def call_result_location(self, v): |
| 121 |
return xmm0 |
| 122 |
|
| 123 |
class X86_64_XMMRegisterManager(X86XMMRegisterManager): |
| 124 |
|
| 125 |
all_regs = [xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14] |
| 126 |
save_around_call_regs = all_regs |
| 127 |
|
| 128 |
class X86_64_WIN_XMMRegisterManager(X86_64_XMMRegisterManager): |
| 129 |
|
| 130 |
all_regs = [xmm0, xmm1, xmm2, xmm3, xmm4] |
| 131 |
|
| 132 |
class X86FrameManager(FrameManager): |
| 133 |
def __init__(self, base_ofs): |
| 134 |
FrameManager.__init__(self) |
| 135 |
self.base_ofs = base_ofs |
| 136 |
|
| 137 |
def frame_pos(self, i, box_type): |
| 138 |
return FrameLoc(i, get_ebp_ofs(self.base_ofs, i), box_type) |
| 139 |
|
| 140 |
@staticmethod |
| 141 |
def frame_size(box_type): |
| 142 |
if IS_X86_32 and box_type == FLOAT: |
| 143 |
return 2 |
| 144 |
else: |
| 145 |
return 1 |
| 146 |
|
| 147 |
@staticmethod |
| 148 |
def get_loc_index(loc): |
| 149 |
assert isinstance(loc, FrameLoc) |
| 150 |
return loc.position |
| 151 |
|
| 152 |
if WORD == 4: |
| 153 |
gpr_reg_mgr_cls = X86RegisterManager |
| 154 |
xmm_reg_mgr_cls = X86XMMRegisterManager |
| 155 |
elif WORD == 8: |
| 156 |
gpr_reg_mgr_cls = X86_64_RegisterManager |
| 157 |
if WIN64: |
| 158 |
xmm_reg_mgr_cls = X86_64_WIN_XMMRegisterManager |
| 159 |
else: |
| 160 |
xmm_reg_mgr_cls = X86_64_XMMRegisterManager |
| 161 |
else: |
| 162 |
raise AssertionError("Word size should be 4 or 8") |
| 163 |
|
| 164 |
gpr_reg_mgr_cls.all_reg_indexes = [-1] * WORD * 2 |
| 165 |
for _i, _reg in enumerate(gpr_reg_mgr_cls.all_regs): |
| 166 |
gpr_reg_mgr_cls.all_reg_indexes[_reg.value] = _i |
| 167 |
|
| 168 |
|
| 169 |
class RegAlloc(BaseRegalloc, VectorRegallocMixin): |
| 170 |
|
| 171 |
def __init__(self, assembler, translate_support_code=False): |
| 172 |
assert isinstance(translate_support_code, bool) |
| 173 |
|
| 174 |
self.assembler = assembler |
| 175 |
self.translate_support_code = translate_support_code |
| 176 |
|
| 177 |
self.jump_target_descr = None |
| 178 |
self.final_jump_op = None |
| 179 |
self.final_jump_op_position = -1 |
| 180 |
|
| 181 |
def _prepare(self, inputargs, operations, allgcrefs): |
| 182 |
from rpython.jit.backend.x86.reghint import X86RegisterHints |
| 183 |
for box in inputargs: |
| 184 |
assert box.get_forwarded() is None |
| 185 |
cpu = self.assembler.cpu |
| 186 |
self.fm = X86FrameManager(cpu.get_baseofs_of_frame_field()) |
| 187 |
operations = cpu.gc_ll_descr.rewrite_assembler(cpu, operations, |
| 188 |
allgcrefs) |
| 189 |
|
| 190 |
longevity = compute_vars_longevity(inputargs, operations) |
| 191 |
X86RegisterHints().add_hints(longevity, inputargs, operations) |
| 192 |
self.longevity = longevity |
| 193 |
self.rm = gpr_reg_mgr_cls(self.longevity, |
| 194 |
frame_manager = self.fm, |
| 195 |
assembler = self.assembler) |
| 196 |
self.xrm = xmm_reg_mgr_cls(self.longevity, frame_manager = self.fm, |
| 197 |
assembler = self.assembler) |
| 198 |
return operations |
| 199 |
|
| 200 |
def prepare_loop(self, inputargs, operations, looptoken, allgcrefs): |
| 201 |
operations = self._prepare(inputargs, operations, allgcrefs) |
| 202 |
self._set_initial_bindings(inputargs, looptoken) |
| 203 |
|
| 204 |
|
| 205 |
self.possibly_free_vars(list(inputargs)) |
| 206 |
if WORD == 4: |
| 207 |
self.min_bytes_before_label = 5 |
| 208 |
else: |
| 209 |
self.min_bytes_before_label = 13 |
| 210 |
return operations |
| 211 |
|
| 212 |
def prepare_bridge(self, inputargs, arglocs, operations, allgcrefs, |
| 213 |
frame_info): |
| 214 |
operations = self._prepare(inputargs, operations, allgcrefs) |
| 215 |
self._update_bindings(arglocs, inputargs) |
| 216 |
self.min_bytes_before_label = 0 |
| 217 |
return operations |
| 218 |
|
| 219 |
def ensure_next_label_is_at_least_at_position(self, at_least_position): |
| 220 |
self.min_bytes_before_label = max(self.min_bytes_before_label, |
| 221 |
at_least_position) |
| 222 |
|
| 223 |
def get_final_frame_depth(self): |
| 224 |
return self.fm.get_frame_depth() |
| 225 |
|
| 226 |
def possibly_free_var(self, var): |
| 227 |
if var.type == FLOAT or var.is_vector(): |
| 228 |
self.xrm.possibly_free_var(var) |
| 229 |
else: |
| 230 |
self.rm.possibly_free_var(var) |
| 231 |
|
| 232 |
def possibly_free_vars_for_op(self, op): |
| 233 |
for i in range(op.numargs()): |
| 234 |
var = op.getarg(i) |
| 235 |
if var is not None: |
| 236 |
self.possibly_free_var(var) |
| 237 |
if op.type != 'v': |
| 238 |
self.possibly_free_var(op) |
| 239 |
|
| 240 |
def possibly_free_vars(self, vars): |
| 241 |
for var in vars: |
| 242 |
if var is not None: |
| 243 |
self.possibly_free_var(var) |
| 244 |
|
| 245 |
def make_sure_var_in_reg(self, var, forbidden_vars=[], |
| 246 |
selected_reg=None, need_lower_byte=False): |
| 247 |
if var.type == FLOAT or var.is_vector(): |
| 248 |
if isinstance(var, ConstFloat): |
| 249 |
return FloatImmedLoc(var.getfloatstorage()) |
| 250 |
return self.xrm.make_sure_var_in_reg(var, forbidden_vars, |
| 251 |
selected_reg, need_lower_byte) |
| 252 |
else: |
| 253 |
return self.rm.make_sure_var_in_reg(var, forbidden_vars, |
| 254 |
selected_reg, need_lower_byte) |
| 255 |
|
| 256 |
def force_allocate_reg(self, var, forbidden_vars=[], selected_reg=None, |
| 257 |
need_lower_byte=False): |
| 258 |
if var.type == FLOAT or var.is_vector(): |
| 259 |
return self.xrm.force_allocate_reg(var, forbidden_vars, |
| 260 |
selected_reg, need_lower_byte) |
| 261 |
else: |
| 262 |
return self.rm.force_allocate_reg(var, forbidden_vars, |
| 263 |
selected_reg, need_lower_byte) |
| 264 |
|
| 265 |
def force_allocate_reg_or_cc(self, var): |
| 266 |
assert var.type == INT |
| 267 |
if self.next_op_can_accept_cc(self.operations, self.rm.position): |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
self.rm.force_allocate_frame_reg(var) |
| 272 |
return ebp |
| 273 |
else: |
| 274 |
|
| 275 |
return self.rm.force_allocate_reg(var, need_lower_byte=True) |
| 276 |
|
| 277 |
def force_spill_var(self, var): |
| 278 |
if var.type == FLOAT: |
| 279 |
return self.xrm.force_spill_var(var) |
| 280 |
else: |
| 281 |
return self.rm.force_spill_var(var) |
| 282 |
|
| 283 |
def load_xmm_aligned_16_bytes(self, var, forbidden_vars=[]): |
| 284 |
|
| 285 |
|
| 286 |
if isinstance(var, Const): |
| 287 |
return self.xrm.convert_to_imm_16bytes_align(var) |
| 288 |
else: |
| 289 |
return self.xrm.make_sure_var_in_reg(var, forbidden_vars) |
| 290 |
|
| 291 |
def _update_bindings(self, locs, inputargs): |
| 292 |
|
| 293 |
used = {} |
| 294 |
i = 0 |
| 295 |
for loc in locs: |
| 296 |
if loc is None: |
| 297 |
loc = ebp |
| 298 |
arg = inputargs[i] |
| 299 |
i += 1 |
| 300 |
if isinstance(loc, RegLoc): |
| 301 |
if arg.type == FLOAT: |
| 302 |
self.xrm.reg_bindings[arg] = loc |
| 303 |
used[loc] = None |
| 304 |
else: |
| 305 |
if loc is ebp: |
| 306 |
assert self.rm.box_currently_in_frame_reg is None |
| 307 |
self.rm.box_currently_in_frame_reg = arg |
| 308 |
else: |
| 309 |
self.rm.reg_bindings[arg] = loc |
| 310 |
used[loc] = None |
| 311 |
else: |
| 312 |
self.fm.bind(arg, loc) |
| 313 |
self.rm.free_regs = [] |
| 314 |
for reg in self.rm.all_regs: |
| 315 |
if reg not in used: |
| 316 |
self.rm.free_regs.append(reg) |
| 317 |
self.xrm.free_regs = [] |
| 318 |
for reg in self.xrm.all_regs: |
| 319 |
if reg not in used: |
| 320 |
self.xrm.free_regs.append(reg) |
| 321 |
self.possibly_free_vars(list(inputargs)) |
| 322 |
self.fm.finish_binding() |
| 323 |
self.rm._check_invariants() |
| 324 |
self.xrm._check_invariants() |
| 325 |
|
| 326 |
def perform(self, op, arglocs, result_loc): |
| 327 |
if not we_are_translated(): |
| 328 |
self.assembler.dump('%s <- %s(%s)' % (result_loc, op, arglocs)) |
| 329 |
self.assembler.regalloc_perform(op, arglocs, result_loc) |
| 330 |
|
| 331 |
def perform_llong(self, op, arglocs, result_loc): |
| 332 |
if not we_are_translated(): |
| 333 |
self.assembler.dump('%s <- %s(%s)' % (result_loc, op, arglocs)) |
| 334 |
self.assembler.regalloc_perform_llong(op, arglocs, result_loc) |
| 335 |
|
| 336 |
def perform_math(self, op, arglocs, result_loc): |
| 337 |
if not we_are_translated(): |
| 338 |
self.assembler.dump('%s <- %s(%s)' % (result_loc, op, arglocs)) |
| 339 |
self.assembler.regalloc_perform_math(op, arglocs, result_loc) |
| 340 |
|
| 341 |
def locs_for_fail(self, guard_op): |
| 342 |
faillocs = [self.loc(arg) for arg in guard_op.getfailargs()] |
| 343 |
descr = guard_op.getdescr() |
| 344 |
if not descr: |
| 345 |
return faillocs |
| 346 |
assert isinstance(descr, AbstractFailDescr) |
| 347 |
if descr.rd_vector_info: |
| 348 |
accuminfo = descr.rd_vector_info |
| 349 |
while accuminfo: |
| 350 |
accuminfo.location = faillocs[accuminfo.getpos_in_failargs()] |
| 351 |
loc = self.loc(accuminfo.getoriginal().get_box_replacement()) |
| 352 |
faillocs[accuminfo.getpos_in_failargs()] = loc |
| 353 |
accuminfo = accuminfo.next() |
| 354 |
return faillocs |
| 355 |
|
| 356 |
def perform_guard(self, guard_op, arglocs, result_loc): |
| 357 |
faillocs = self.locs_for_fail(guard_op) |
| 358 |
if not we_are_translated(): |
| 359 |
if result_loc is not None: |
| 360 |
self.assembler.dump('%s <- %s(%s)' % (result_loc, guard_op, |
| 361 |
arglocs)) |
| 362 |
else: |
| 363 |
self.assembler.dump('%s(%s)' % (guard_op, arglocs)) |
| 364 |
self.assembler.regalloc_perform_guard(guard_op, faillocs, arglocs, |
| 365 |
result_loc, |
| 366 |
self.fm.get_frame_depth()) |
| 367 |
self.possibly_free_vars(guard_op.getfailargs()) |
| 368 |
|
| 369 |
def perform_discard(self, op, arglocs): |
| 370 |
if not we_are_translated(): |
| 371 |
self.assembler.dump('%s(%s)' % (op, arglocs)) |
| 372 |
self.assembler.regalloc_perform_discard(op, arglocs) |
| 373 |
|
| 374 |
def walk_operations(self, inputargs, operations): |
| 375 |
i = 0 |
| 376 |
self.operations = operations |
| 377 |
while i < len(operations): |
| 378 |
op = operations[i] |
| 379 |
self.assembler.mc.mark_op(op) |
| 380 |
assert self.assembler.mc._frame_size == DEFAULT_FRAME_BYTES |
| 381 |
self.rm.position = i |
| 382 |
self.xrm.position = i |
| 383 |
if rop.has_no_side_effect(op.opnum) and op not in self.longevity: |
| 384 |
i += 1 |
| 385 |
self.possibly_free_vars_for_op(op) |
| 386 |
continue |
| 387 |
if not we_are_translated() and op.getopnum() == rop.FORCE_SPILL: |
| 388 |
self._consider_force_spill(op) |
| 389 |
else: |
| 390 |
oplist[op.getopnum()](self, op) |
| 391 |
self.possibly_free_vars_for_op(op) |
| 392 |
self.rm._check_invariants() |
| 393 |
self.xrm._check_invariants() |
| 394 |
i += 1 |
| 395 |
assert len(self.rm.reg_bindings) == 0 |
| 396 |
assert len(self.xrm.reg_bindings) == 0 |
| 397 |
if not we_are_translated(): |
| 398 |
self.assembler.mc.UD2() |
| 399 |
self.flush_loop() |
| 400 |
self.assembler.mc.mark_op(None) |
| 401 |
self.operations = None |
| 402 |
for arg in inputargs: |
| 403 |
self.possibly_free_var(arg) |
| 404 |
|
| 405 |
def flush_loop(self): |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
mc = self.assembler.mc |
| 414 |
current_pos = mc.get_relative_pos() |
| 415 |
target_pos = (current_pos + 15) & ~15 |
| 416 |
target_pos = max(target_pos, self.min_bytes_before_label) |
| 417 |
insert_nops = target_pos - current_pos |
| 418 |
assert 0 <= insert_nops <= 15 |
| 419 |
for c in mc.MULTIBYTE_NOPs[insert_nops]: |
| 420 |
mc.writechar(c) |
| 421 |
|
| 422 |
def loc(self, v): |
| 423 |
if v is None: |
| 424 |
return None |
| 425 |
if v.type == FLOAT or v.is_vector(): |
| 426 |
return self.xrm.loc(v) |
| 427 |
return self.rm.loc(v) |
| 428 |
|
| 429 |
def load_condition_into_cc(self, box): |
| 430 |
if self.assembler.guard_success_cc == rx86.cond_none: |
| 431 |
self.assembler.test_location(self.loc(box)) |
| 432 |
self.assembler.guard_success_cc = rx86.Conditions['NZ'] |
| 433 |
|
| 434 |
|
| 435 |
def _consider_guard_cc(self, op): |
| 436 |
arg = op.getarg(0) |
| 437 |
self.load_condition_into_cc(arg) |
| 438 |
self.perform_guard(op, [], None) |
| 439 |
|
| 440 |
consider_guard_true = _consider_guard_cc |
| 441 |
consider_guard_false = _consider_guard_cc |
| 442 |
consider_guard_nonnull = _consider_guard_cc |
| 443 |
consider_guard_isnull = _consider_guard_cc |
| 444 |
|
| 445 |
def consider_finish(self, op): |
| 446 |
|
| 447 |
|
| 448 |
if op.numargs() == 1: |
| 449 |
loc = self.make_sure_var_in_reg(op.getarg(0)) |
| 450 |
locs = [loc] |
| 451 |
else: |
| 452 |
locs = [] |
| 453 |
self.perform(op, locs, None) |
| 454 |
|
| 455 |
def consider_guard_no_exception(self, op): |
| 456 |
self.perform_guard(op, [], None) |
| 457 |
|
| 458 |
def consider_guard_not_invalidated(self, op): |
| 459 |
mc = self.assembler.mc |
| 460 |
n = mc.get_relative_pos(break_basic_block=False) |
| 461 |
self.perform_guard(op, [], None) |
| 462 |
assert n == mc.get_relative_pos(break_basic_block=False) |
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
self.ensure_next_label_is_at_least_at_position(n + 5) |
| 467 |
|
| 468 |
def consider_guard_exception(self, op): |
| 469 |
loc = self.rm.make_sure_var_in_reg(op.getarg(0)) |
| 470 |
box = TempVar() |
| 471 |
args = op.getarglist() |
| 472 |
loc1 = self.rm.force_allocate_reg(box, args) |
| 473 |
if op in self.longevity: |
| 474 |
|
| 475 |
resloc = self.rm.force_allocate_reg(op, args + [box]) |
| 476 |
else: |
| 477 |
resloc = None |
| 478 |
self.perform_guard(op, [loc, loc1], resloc) |
| 479 |
self.rm.possibly_free_var(box) |
| 480 |
|
| 481 |
def consider_save_exception(self, op): |
| 482 |
resloc = self.rm.force_allocate_reg(op) |
| 483 |
self.perform(op, [], resloc) |
| 484 |
consider_save_exc_class = consider_save_exception |
| 485 |
|
| 486 |
def consider_restore_exception(self, op): |
| 487 |
args = op.getarglist() |
| 488 |
loc0 = self.rm.make_sure_var_in_reg(op.getarg(0), args) |
| 489 |
loc1 = self.rm.make_sure_var_in_reg(op.getarg(1), args) |
| 490 |
self.perform_discard(op, [loc0, loc1]) |
| 491 |
|
| 492 |
consider_guard_no_overflow = consider_guard_no_exception |
| 493 |
consider_guard_overflow = consider_guard_no_exception |
| 494 |
consider_guard_not_forced = consider_guard_no_exception |
| 495 |
|
| 496 |
def consider_guard_value(self, op): |
| 497 |
x = self.make_sure_var_in_reg(op.getarg(0)) |
| 498 |
loc = self.assembler.cpu.all_reg_indexes[x.value] |
| 499 |
op.getdescr().make_a_counter_per_value(op, loc) |
| 500 |
y = self.loc(op.getarg(1)) |
| 501 |
self.perform_guard(op, [x, y], None) |
| 502 |
|
| 503 |
def consider_guard_class(self, op): |
| 504 |
assert not isinstance(op.getarg(0), Const) |
| 505 |
x = self.rm.make_sure_var_in_reg(op.getarg(0)) |
| 506 |
y = self.loc(op.getarg(1)) |
| 507 |
self.perform_guard(op, [x, y], None) |
| 508 |
|
| 509 |
consider_guard_nonnull_class = consider_guard_class |
| 510 |
consider_guard_gc_type = consider_guard_class |
| 511 |
|
| 512 |
def consider_guard_is_object(self, op): |
| 513 |
x = self.make_sure_var_in_reg(op.getarg(0)) |
| 514 |
tmp_box = TempVar() |
| 515 |
y = self.rm.force_allocate_reg(tmp_box, [op.getarg(0)]) |
| 516 |
self.rm.possibly_free_var(tmp_box) |
| 517 |
self.perform_guard(op, [x, y], None) |
| 518 |
|
| 519 |
def consider_guard_subclass(self, op): |
| 520 |
x = self.make_sure_var_in_reg(op.getarg(0)) |
| 521 |
tmp_box = TempVar() |
| 522 |
z = self.rm.force_allocate_reg(tmp_box, [op.getarg(0)]) |
| 523 |
y = self.loc(op.getarg(1)) |
| 524 |
self.rm.possibly_free_var(tmp_box) |
| 525 |
self.perform_guard(op, [x, y, z], None) |
| 526 |
|
| 527 |
def _consider_binop_part(self, op, symm=False): |
| 528 |
x = op.getarg(0) |
| 529 |
y = op.getarg(1) |
| 530 |
xloc = self.loc(x) |
| 531 |
argloc = self.loc(y) |
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
if (symm and not isinstance(xloc, RegLoc) and |
| 537 |
isinstance(argloc, RegLoc)): |
| 538 |
if ((x not in self.rm.longevity or |
| 539 |
self.rm.longevity[x].last_usage > self.rm.position) and |
| 540 |
self.rm.longevity[y].last_usage == self.rm.position): |
| 541 |
x, y = y, x |
| 542 |
argloc = self.loc(y) |
| 543 |
|
| 544 |
args = op.getarglist() |
| 545 |
loc = self.rm.force_result_in_reg(op, x, args) |
| 546 |
return loc, argloc |
| 547 |
|
| 548 |
def _consider_binop(self, op): |
| 549 |
loc, argloc = self._consider_binop_part(op) |
| 550 |
self.perform(op, [loc, argloc], loc) |
| 551 |
|
| 552 |
def _consider_binop_symm(self, op): |
| 553 |
loc, argloc = self._consider_binop_part(op, symm=True) |
| 554 |
self.perform(op, [loc, argloc], loc) |
| 555 |
|
| 556 |
def _consider_lea(self, op): |
| 557 |
x = op.getarg(0) |
| 558 |
loc = self.make_sure_var_in_reg(x) |
| 559 |
|
| 560 |
|
| 561 |
self.possibly_free_var(x) |
| 562 |
argloc = self.loc(op.getarg(1)) |
| 563 |
resloc = self.force_allocate_reg(op) |
| 564 |
self.perform(op, [loc, argloc], resloc) |
| 565 |
|
| 566 |
def consider_int_add(self, op): |
| 567 |
y = op.getarg(1) |
| 568 |
if isinstance(y, ConstInt) and rx86.fits_in_32bits(y.value): |
| 569 |
self._consider_lea(op) |
| 570 |
else: |
| 571 |
self._consider_binop_symm(op) |
| 572 |
|
| 573 |
consider_nursery_ptr_increment = consider_int_add |
| 574 |
|
| 575 |
def consider_int_sub(self, op): |
| 576 |
y = op.getarg(1) |
| 577 |
if isinstance(y, ConstInt) and rx86.fits_in_32bits(-y.value): |
| 578 |
self._consider_lea(op) |
| 579 |
else: |
| 580 |
self._consider_binop(op) |
| 581 |
|
| 582 |
consider_int_mul = _consider_binop_symm |
| 583 |
consider_int_and = _consider_binop_symm |
| 584 |
consider_int_or = _consider_binop_symm |
| 585 |
consider_int_xor = _consider_binop_symm |
| 586 |
|
| 587 |
consider_int_mul_ovf = _consider_binop_symm |
| 588 |
consider_int_sub_ovf = _consider_binop |
| 589 |
consider_int_add_ovf = _consider_binop_symm |
| 590 |
|
| 591 |
def consider_uint_mul_high(self, op): |
| 592 |
arg1, arg2 = op.getarglist() |
| 593 |
|
| 594 |
if isinstance(arg1, Const): |
| 595 |
arg1, arg2 = arg2, arg1 |
| 596 |
self.rm.make_sure_var_in_reg(arg2, selected_reg=eax) |
| 597 |
l1 = self.loc(arg1) |
| 598 |
|
| 599 |
|
| 600 |
assert not isinstance(l1, ImmedLoc) |
| 601 |
assert l1 is not eax or arg1 is arg2 |
| 602 |
|
| 603 |
|
| 604 |
self.rm.possibly_free_var(arg2) |
| 605 |
tmpvar = TempVar() |
| 606 |
self.rm.force_allocate_reg(tmpvar, selected_reg=eax) |
| 607 |
self.rm.possibly_free_var(tmpvar) |
| 608 |
|
| 609 |
self.rm.force_allocate_reg(op, selected_reg=edx) |
| 610 |
self.perform(op, [l1], edx) |
| 611 |
|
| 612 |
def consider_int_neg(self, op): |
| 613 |
res = self.rm.force_result_in_reg(op, op.getarg(0)) |
| 614 |
self.perform(op, [res], res) |
| 615 |
|
| 616 |
consider_int_invert = consider_int_neg |
| 617 |
|
| 618 |
def consider_int_signext(self, op): |
| 619 |
argloc = self.loc(op.getarg(0)) |
| 620 |
numbytesloc = self.loc(op.getarg(1)) |
| 621 |
resloc = self.force_allocate_reg(op) |
| 622 |
self.perform(op, [argloc, numbytesloc], resloc) |
| 623 |
|
| 624 |
def consider_int_lshift(self, op): |
| 625 |
if isinstance(op.getarg(1), Const): |
| 626 |
loc2 = self.rm.convert_to_imm(op.getarg(1)) |
| 627 |
else: |
| 628 |
loc2 = self.rm.make_sure_var_in_reg(op.getarg(1), selected_reg=ecx) |
| 629 |
args = op.getarglist() |
| 630 |
loc1 = self.rm.force_result_in_reg(op, op.getarg(0), args) |
| 631 |
self.perform(op, [loc1, loc2], loc1) |
| 632 |
|
| 633 |
consider_int_rshift = consider_int_lshift |
| 634 |
consider_uint_rshift = consider_int_lshift |
| 635 |
|
| 636 |
def _consider_compop(self, op): |
| 637 |
vx = op.getarg(0) |
| 638 |
vy = op.getarg(1) |
| 639 |
arglocs = [self.loc(vx), self.loc(vy)] |
| 640 |
if (vx in self.rm.reg_bindings or vy in self.rm.reg_bindings or |
| 641 |
isinstance(vx, Const) or isinstance(vy, Const)): |
| 642 |
pass |
| 643 |
else: |
| 644 |
arglocs[0] = self.rm.make_sure_var_in_reg(vx) |
| 645 |
loc = self.force_allocate_reg_or_cc(op) |
| 646 |
self.perform(op, arglocs, loc) |
| 647 |
|
| 648 |
consider_int_lt = _consider_compop |
| 649 |
consider_int_gt = _consider_compop |
| 650 |
consider_int_ge = _consider_compop |
| 651 |
consider_int_le = _consider_compop |
| 652 |
consider_int_ne = _consider_compop |
| 653 |
consider_int_eq = _consider_compop |
| 654 |
consider_uint_gt = _consider_compop |
| 655 |
consider_uint_lt = _consider_compop |
| 656 |
consider_uint_le = _consider_compop |
| 657 |
consider_uint_ge = _consider_compop |
| 658 |
consider_ptr_eq = consider_instance_ptr_eq = _consider_compop |
| 659 |
consider_ptr_ne = consider_instance_ptr_ne = _consider_compop |
| 660 |
|
| 661 |
def _consider_float_op(self, op): |
| 662 |
loc1 = self.xrm.loc(op.getarg(1)) |
| 663 |
args = op.getarglist() |
| 664 |
loc0 = self.xrm.force_result_in_reg(op, op.getarg(0), args) |
| 665 |
self.perform(op, [loc0, loc1], loc0) |
| 666 |
|
| 667 |
consider_float_add = _consider_float_op |
| 668 |
consider_float_sub = _consider_float_op |
| 669 |
consider_float_mul = _consider_float_op |
| 670 |
consider_float_truediv = _consider_float_op |
| 671 |
|
| 672 |
def _consider_float_cmp(self, op): |
| 673 |
vx = op.getarg(0) |
| 674 |
vy = op.getarg(1) |
| 675 |
arglocs = [self.loc(vx), self.loc(vy)] |
| 676 |
if not (isinstance(arglocs[0], RegLoc) or |
| 677 |
isinstance(arglocs[1], RegLoc)): |
| 678 |
if isinstance(vx, Const): |
| 679 |
arglocs[1] = self.xrm.make_sure_var_in_reg(vy) |
| 680 |
else: |
| 681 |
arglocs[0] = self.xrm.make_sure_var_in_reg(vx) |
| 682 |
loc = self.force_allocate_reg_or_cc(op) |
| 683 |
self.perform(op, arglocs, loc) |
| 684 |
|
| 685 |
consider_float_lt = _consider_float_cmp |
| 686 |
consider_float_le = _consider_float_cmp |
| 687 |
consider_float_eq = _consider_float_cmp |
| 688 |
consider_float_ne = _consider_float_cmp |
| 689 |
consider_float_gt = _consider_float_cmp |
| 690 |
consider_float_ge = _consider_float_cmp |
| 691 |
|
| 692 |
def _consider_float_unary_op(self, op): |
| 693 |
loc0 = self.xrm.force_result_in_reg(op, op.getarg(0)) |
| 694 |
self.perform(op, [loc0], loc0) |
| 695 |
|
| 696 |
consider_float_neg = _consider_float_unary_op |
| 697 |
consider_float_abs = _consider_float_unary_op |
| 698 |
|
| 699 |
def consider_cast_float_to_int(self, op): |
| 700 |
loc0 = self.xrm.make_sure_var_in_reg(op.getarg(0)) |
| 701 |
loc1 = self.rm.force_allocate_reg(op) |
| 702 |
self.perform(op, [loc0], loc1) |
| 703 |
|
| 704 |
def consider_cast_int_to_float(self, op): |
| 705 |
loc0 = self.rm.make_sure_var_in_reg(op.getarg(0)) |
| 706 |
loc1 = self.xrm.force_allocate_reg(op) |
| 707 |
self.perform(op, [loc0], loc1) |
| 708 |
|
| 709 |
def consider_cast_float_to_singlefloat(self, op): |
| 710 |
loc0 = self.xrm.make_sure_var_in_reg(op.getarg(0)) |
| 711 |
loc1 = self.rm.force_allocate_reg(op) |
| 712 |
tmpxvar = TempVar() |
| 713 |
loctmp = self.xrm.force_allocate_reg(tmpxvar) |
| 714 |
self.xrm.possibly_free_var(tmpxvar) |
| 715 |
self.perform(op, [loc0, loctmp], loc1) |
| 716 |
|
| 717 |
consider_cast_singlefloat_to_float = consider_cast_int_to_float |
| 718 |
|
| 719 |
def consider_convert_float_bytes_to_longlong(self, op): |
| 720 |
if longlong.is_64_bit: |
| 721 |
loc0 = self.xrm.make_sure_var_in_reg(op.getarg(0)) |
| 722 |
loc1 = self.rm.force_allocate_reg(op) |
| 723 |
self.perform(op, [loc0], loc1) |
| 724 |
else: |
| 725 |
arg0 = op.getarg(0) |
| 726 |
loc0 = self.xrm.loc(arg0) |
| 727 |
loc1 = self.xrm.force_allocate_reg(op, forbidden_vars=[arg0]) |
| 728 |
self.perform(op, [loc0], loc1) |
| 729 |
|
| 730 |
def consider_convert_longlong_bytes_to_float(self, op): |
| 731 |
if longlong.is_64_bit: |
| 732 |
loc0 = self.rm.make_sure_var_in_reg(op.getarg(0)) |
| 733 |
loc1 = self.xrm.force_allocate_reg(op) |
| 734 |
self.perform(op, [loc0], loc1) |
| 735 |
else: |
| 736 |
arg0 = op.getarg(0) |
| 737 |
loc0 = self.xrm.make_sure_var_in_reg(arg0) |
| 738 |
loc1 = self.xrm.force_allocate_reg(op, forbidden_vars=[arg0]) |
| 739 |
self.perform(op, [loc0], loc1) |
| 740 |
|
| 741 |
def _consider_llong_binop_xx(self, op): |
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
args = [op.getarg(1), op.getarg(2)] |
| 747 |
loc1 = self.load_xmm_aligned_16_bytes(args[1]) |
| 748 |
loc0 = self.xrm.force_result_in_reg(op, args[0], args) |
| 749 |
self.perform_llong(op, [loc0, loc1], loc0) |
| 750 |
|
| 751 |
def _consider_llong_eq_ne_xx(self, op): |
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
args = [op.getarg(1), op.getarg(2)] |
| 756 |
loc1 = self.load_xmm_aligned_16_bytes(args[0]) |
| 757 |
loc2 = self.load_xmm_aligned_16_bytes(args[1], args) |
| 758 |
tmpxvar = TempVar() |
| 759 |
loc3 = self.xrm.force_allocate_reg(tmpxvar, args) |
| 760 |
self.xrm.possibly_free_var(tmpxvar) |
| 761 |
loc0 = self.rm.force_allocate_reg(op, need_lower_byte=True) |
| 762 |
self.perform_llong(op, [loc1, loc2, loc3], loc0) |
| 763 |
|
| 764 |
def _maybe_consider_llong_lt(self, op): |
| 765 |
|
| 766 |
box = op.getarg(2) |
| 767 |
if not isinstance(box, ConstFloat): |
| 768 |
return False |
| 769 |
if box.getfloat() != 0.0: |
| 770 |
return False |
| 771 |
|
| 772 |
box = op.getarg(1) |
| 773 |
assert box.type == FLOAT |
| 774 |
loc1 = self.xrm.make_sure_var_in_reg(box) |
| 775 |
loc0 = self.rm.force_allocate_reg(op) |
| 776 |
self.perform_llong(op, [loc1], loc0) |
| 777 |
return True |
| 778 |
|
| 779 |
def _consider_llong_to_int(self, op): |
| 780 |
|
| 781 |
loc1 = self.xrm.loc(op.getarg(1)) |
| 782 |
loc0 = self.rm.force_allocate_reg(op) |
| 783 |
self.perform_llong(op, [loc1], loc0) |
| 784 |
|
| 785 |
def _loc_of_const_longlong(self, value64): |
| 786 |
c = ConstFloat(value64) |
| 787 |
return self.xrm.convert_to_imm(c) |
| 788 |
|
| 789 |
def _consider_llong_from_int(self, op): |
| 790 |
assert IS_X86_32 |
| 791 |
loc0 = self.xrm.force_allocate_reg(op) |
| 792 |
box = op.getarg(1) |
| 793 |
if isinstance(box, ConstInt): |
| 794 |
loc1 = self._loc_of_const_longlong(r_longlong(box.value)) |
| 795 |
loc2 = None |
| 796 |
else: |
| 797 |
loc1 = self.rm.make_sure_var_in_reg(box) |
| 798 |
tmpxvar = TempVar() |
| 799 |
loc2 = self.xrm.force_allocate_reg(tmpxvar, [op]) |
| 800 |
self.xrm.possibly_free_var(tmpxvar) |
| 801 |
self.perform_llong(op, [loc1, loc2], loc0) |
| 802 |
|
| 803 |
def _consider_llong_from_uint(self, op): |
| 804 |
assert IS_X86_32 |
| 805 |
loc0 = self.xrm.force_allocate_reg(op) |
| 806 |
loc1 = self.rm.make_sure_var_in_reg(op.getarg(1)) |
| 807 |
self.perform_llong(op, [loc1], loc0) |
| 808 |
|
| 809 |
def _consider_math_sqrt(self, op): |
| 810 |
loc0 = self.xrm.force_result_in_reg(op, op.getarg(1)) |
| 811 |
self.perform_math(op, [loc0], loc0) |
| 812 |
|
| 813 |
def _consider_threadlocalref_get(self, op): |
| 814 |
if self.translate_support_code: |
| 815 |
offset = op.getarg(1).getint() |
| 816 |
calldescr = op.getdescr() |
| 817 |
size = calldescr.get_result_size() |
| 818 |
sign = calldescr.is_result_signed() |
| 819 |
resloc = self.force_allocate_reg(op) |
| 820 |
self.assembler.threadlocalref_get(offset, resloc, size, sign) |
| 821 |
else: |
| 822 |
self._consider_call(op) |
| 823 |
|
| 824 |
def _call(self, op, arglocs, gc_level): |
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
if gc_level == SAVE_ALL_REGS: |
| 839 |
save_all_regs = SAVE_ALL_REGS |
| 840 |
else: |
| 841 |
save_all_regs = SAVE_DEFAULT_REGS |
| 842 |
self.xrm.before_call(save_all_regs=save_all_regs) |
| 843 |
if gc_level == SAVE_GCREF_REGS: |
| 844 |
gcrootmap = self.assembler.cpu.gc_ll_descr.gcrootmap |
| 845 |
|
| 846 |
if gcrootmap: |
| 847 |
save_all_regs = SAVE_GCREF_REGS |
| 848 |
self.rm.before_call(save_all_regs=save_all_regs) |
| 849 |
if op.type != 'v': |
| 850 |
if op.type == FLOAT: |
| 851 |
resloc = self.xrm.after_call(op) |
| 852 |
else: |
| 853 |
resloc = self.rm.after_call(op) |
| 854 |
else: |
| 855 |
resloc = None |
| 856 |
self.perform(op, arglocs, resloc) |
| 857 |
|
| 858 |
def _consider_call(self, op, guard_not_forced=False, first_arg_index=1): |
| 859 |
calldescr = op.getdescr() |
| 860 |
assert isinstance(calldescr, CallDescr) |
| 861 |
assert len(calldescr.arg_classes) == op.numargs() - first_arg_index |
| 862 |
size = calldescr.get_result_size() |
| 863 |
sign = calldescr.is_result_signed() |
| 864 |
if sign: |
| 865 |
sign_loc = imm1 |
| 866 |
else: |
| 867 |
sign_loc = imm0 |
| 868 |
|
| 869 |
gc_level = compute_gc_level(calldescr, guard_not_forced) |
| 870 |
|
| 871 |
self._call(op, [imm(size), sign_loc] + |
| 872 |
[self.loc(op.getarg(i)) for i in range(op.numargs())], |
| 873 |
gc_level=gc_level) |
| 874 |
|
| 875 |
def _consider_real_call(self, op): |
| 876 |
effectinfo = op.getdescr().get_extra_info() |
| 877 |
assert effectinfo is not None |
| 878 |
oopspecindex = effectinfo.oopspecindex |
| 879 |
if oopspecindex != EffectInfo.OS_NONE: |
| 880 |
if IS_X86_32: |
| 881 |
|
| 882 |
|
| 883 |
if oopspecindex in (EffectInfo.OS_LLONG_ADD, |
| 884 |
EffectInfo.OS_LLONG_SUB, |
| 885 |
EffectInfo.OS_LLONG_AND, |
| 886 |
EffectInfo.OS_LLONG_OR, |
| 887 |
EffectInfo.OS_LLONG_XOR): |
| 888 |
return self._consider_llong_binop_xx(op) |
| 889 |
if oopspecindex == EffectInfo.OS_LLONG_TO_INT: |
| 890 |
return self._consider_llong_to_int(op) |
| 891 |
if oopspecindex == EffectInfo.OS_LLONG_FROM_INT: |
| 892 |
return self._consider_llong_from_int(op) |
| 893 |
if oopspecindex == EffectInfo.OS_LLONG_FROM_UINT: |
| 894 |
return self._consider_llong_from_uint(op) |
| 895 |
if (oopspecindex == EffectInfo.OS_LLONG_EQ or |
| 896 |
oopspecindex == EffectInfo.OS_LLONG_NE): |
| 897 |
return self._consider_llong_eq_ne_xx(op) |
| 898 |
if oopspecindex == EffectInfo.OS_LLONG_LT: |
| 899 |
if self._maybe_consider_llong_lt(op): |
| 900 |
return |
| 901 |
if oopspecindex == EffectInfo.OS_MATH_SQRT: |
| 902 |
return self._consider_math_sqrt(op) |
| 903 |
if oopspecindex == EffectInfo.OS_THREADLOCALREF_GET: |
| 904 |
return self._consider_threadlocalref_get(op) |
| 905 |
if oopspecindex == EffectInfo.OS_MATH_READ_TIMESTAMP: |
| 906 |
return self._consider_math_read_timestamp(op) |
| 907 |
self._consider_call(op) |
| 908 |
consider_call_i = _consider_real_call |
| 909 |
consider_call_r = _consider_real_call |
| 910 |
consider_call_f = _consider_real_call |
| 911 |
consider_call_n = _consider_real_call |
| 912 |
|
| 913 |
def _consider_call_may_force(self, op): |
| 914 |
self._consider_call(op, guard_not_forced=True) |
| 915 |
consider_call_may_force_i = _consider_call_may_force |
| 916 |
consider_call_may_force_r = _consider_call_may_force |
| 917 |
consider_call_may_force_f = _consider_call_may_force |
| 918 |
consider_call_may_force_n = _consider_call_may_force |
| 919 |
|
| 920 |
def _consider_call_release_gil(self, op): |
| 921 |
|
| 922 |
self._consider_call(op, guard_not_forced=True, first_arg_index=2) |
| 923 |
consider_call_release_gil_i = _consider_call_release_gil |
| 924 |
consider_call_release_gil_f = _consider_call_release_gil |
| 925 |
consider_call_release_gil_n = _consider_call_release_gil |
| 926 |
|
| 927 |
def consider_check_memory_error(self, op): |
| 928 |
x = self.rm.make_sure_var_in_reg(op.getarg(0)) |
| 929 |
self.perform_discard(op, [x]) |
| 930 |
|
| 931 |
def _consider_call_assembler(self, op): |
| 932 |
locs = self.locs_for_call_assembler(op) |
| 933 |
self._call(op, locs, gc_level=SAVE_ALL_REGS) |
| 934 |
consider_call_assembler_i = _consider_call_assembler |
| 935 |
consider_call_assembler_r = _consider_call_assembler |
| 936 |
consider_call_assembler_f = _consider_call_assembler |
| 937 |
consider_call_assembler_n = _consider_call_assembler |
| 938 |
|
| 939 |
def consider_cond_call_gc_wb(self, op): |
| 940 |
assert op.type == 'v' |
| 941 |
args = op.getarglist() |
| 942 |
N = len(args) |
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
arglocs = [self.rm.make_sure_var_in_reg(op.getarg(i), args) |
| 947 |
for i in range(N)] |
| 948 |
self.perform_discard(op, arglocs) |
| 949 |
|
| 950 |
consider_cond_call_gc_wb_array = consider_cond_call_gc_wb |
| 951 |
|
| 952 |
def consider_cond_call(self, op): |
| 953 |
args = op.getarglist() |
| 954 |
assert 2 <= len(args) <= 4 + 2 |
| 955 |
v_func = args[1] |
| 956 |
assert isinstance(v_func, Const) |
| 957 |
imm_func = self.rm.convert_to_imm(v_func) |
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
arglocs = [self.loc(args[i]) for i in range(2, len(args))] |
| 963 |
|
| 964 |
if op.type == 'v': |
| 965 |
|
| 966 |
|
| 967 |
gcmap = self.get_gcmap() |
| 968 |
self.load_condition_into_cc(op.getarg(0)) |
| 969 |
resloc = None |
| 970 |
else: |
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
resloc = self.rm.force_result_in_reg(op, args[0], |
| 984 |
forbidden_vars=args[2:]) |
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
gcmap = self.get_gcmap([resloc]) |
| 1001 |
|
| 1002 |
|
| 1003 |
self.assembler.test_location(resloc) |
| 1004 |
self.assembler.guard_success_cc = rx86.Conditions['Z'] |
| 1005 |
|
| 1006 |
if not we_are_translated(): |
| 1007 |
self.assembler.dump('%s <- %s(%s)' % (resloc, op, arglocs)) |
| 1008 |
self.assembler.cond_call(gcmap, imm_func, arglocs, resloc) |
| 1009 |
|
| 1010 |
consider_cond_call_value_i = consider_cond_call |
| 1011 |
consider_cond_call_value_r = consider_cond_call |
| 1012 |
|
| 1013 |
def consider_call_malloc_nursery(self, op): |
| 1014 |
|
| 1015 |
size_box = op.getarg(0) |
| 1016 |
assert isinstance(size_box, ConstInt) |
| 1017 |
size = size_box.getint() |
| 1018 |
|
| 1019 |
self.rm.spill_or_move_registers_before_call([ecx, edx]) |
| 1020 |
|
| 1021 |
self.rm.force_allocate_reg(op, selected_reg=ecx) |
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
tmp_box = TempVar() |
| 1026 |
self.rm.force_allocate_reg(tmp_box, selected_reg=edx) |
| 1027 |
gcmap = self.get_gcmap([ecx, edx]) |
| 1028 |
self.rm.possibly_free_var(tmp_box) |
| 1029 |
|
| 1030 |
gc_ll_descr = self.assembler.cpu.gc_ll_descr |
| 1031 |
self.assembler.malloc_cond( |
| 1032 |
gc_ll_descr.get_nursery_free_addr(), |
| 1033 |
gc_ll_descr.get_nursery_top_addr(), |
| 1034 |
size, gcmap) |
| 1035 |
|
| 1036 |
def consider_call_malloc_nursery_varsize_frame(self, op): |
| 1037 |
size_box = op.getarg(0) |
| 1038 |
assert not isinstance(size_box, Const) |
| 1039 |
|
| 1040 |
|
| 1041 |
sizeloc = self.rm.make_sure_var_in_reg(size_box) |
| 1042 |
self.rm.spill_or_move_registers_before_call([ecx, edx]) |
| 1043 |
self.rm.possibly_free_var(size_box) |
| 1044 |
|
| 1045 |
self.rm.force_allocate_reg(op, selected_reg=ecx) |
| 1046 |
|
| 1047 |
tmp_box = TempVar() |
| 1048 |
self.rm.force_allocate_reg(tmp_box, selected_reg=edx) |
| 1049 |
gcmap = self.get_gcmap([ecx, edx]) |
| 1050 |
self.rm.possibly_free_var(tmp_box) |
| 1051 |
|
| 1052 |
gc_ll_descr = self.assembler.cpu.gc_ll_descr |
| 1053 |
self.assembler.malloc_cond_varsize_frame( |
| 1054 |
gc_ll_descr.get_nursery_free_addr(), |
| 1055 |
gc_ll_descr.get_nursery_top_addr(), |
| 1056 |
sizeloc, gcmap) |
| 1057 |
|
| 1058 |
def consider_call_malloc_nursery_varsize(self, op): |
| 1059 |
gc_ll_descr = self.assembler.cpu.gc_ll_descr |
| 1060 |
if not hasattr(gc_ll_descr, 'max_size_of_young_obj'): |
| 1061 |
raise Exception("unreachable code") |
| 1062 |
|
| 1063 |
arraydescr = op.getdescr() |
| 1064 |
length_box = op.getarg(2) |
| 1065 |
assert not isinstance(length_box, Const) |
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
if self.rm.stays_alive(length_box): |
| 1070 |
self.rm.spill_or_move_registers_before_call([ecx, edx]) |
| 1071 |
|
| 1072 |
self.rm.force_allocate_reg(op, selected_reg=ecx) |
| 1073 |
|
| 1074 |
tmp_box = TempVar() |
| 1075 |
self.rm.force_allocate_reg(tmp_box, selected_reg=edx) |
| 1076 |
gcmap = self.get_gcmap([ecx, edx]) |
| 1077 |
self.rm.possibly_free_var(tmp_box) |
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
lengthloc = self.rm.loc(length_box) |
| 1082 |
self.rm.possibly_free_var(length_box) |
| 1083 |
|
| 1084 |
itemsize = op.getarg(1).getint() |
| 1085 |
maxlength = (gc_ll_descr.max_size_of_young_obj - WORD * 2) |
| 1086 |
self.assembler.malloc_cond_varsize( |
| 1087 |
op.getarg(0).getint(), |
| 1088 |
gc_ll_descr.get_nursery_free_addr(), |
| 1089 |
gc_ll_descr.get_nursery_top_addr(), |
| 1090 |
lengthloc, itemsize, maxlength, gcmap, arraydescr) |
| 1091 |
|
| 1092 |
def get_gcmap(self, forbidden_regs=[], noregs=False): |
| 1093 |
frame_depth = self.fm.get_frame_depth() |
| 1094 |
gcmap = allocate_gcmap(self.assembler, frame_depth, JITFRAME_FIXED_SIZE) |
| 1095 |
for box, loc in self.rm.reg_bindings_iteritems(): |
| 1096 |
if loc in forbidden_regs: |
| 1097 |
continue |
| 1098 |
if box.type == REF and self.rm.is_still_alive(box): |
| 1099 |
assert not noregs |
| 1100 |
assert isinstance(loc, RegLoc) |
| 1101 |
val = gpr_reg_mgr_cls.all_reg_indexes[loc.value] |
| 1102 |
gcmap[val // WORD // 8] |= r_uint(1) << (val % (WORD * 8)) |
| 1103 |
for box, loc in self.fm.bindings_iteritems(): |
| 1104 |
if box.type == REF and self.rm.is_still_alive(box): |
| 1105 |
assert isinstance(loc, FrameLoc) |
| 1106 |
val = loc.position + JITFRAME_FIXED_SIZE |
| 1107 |
gcmap[val // WORD // 8] |= r_uint(1) << (val % (WORD * 8)) |
| 1108 |
return gcmap |
| 1109 |
|
| 1110 |
def consider_gc_store(self, op): |
| 1111 |
args = op.getarglist() |
| 1112 |
base_loc = self.rm.make_sure_var_in_reg(op.getarg(0), args) |
| 1113 |
size_box = op.getarg(3) |
| 1114 |
assert isinstance(size_box, ConstInt) |
| 1115 |
size = size_box.value |
| 1116 |
assert size >= 1 |
| 1117 |
if size == 1: |
| 1118 |
need_lower_byte = True |
| 1119 |
else: |
| 1120 |
need_lower_byte = False |
| 1121 |
value_loc = self.make_sure_var_in_reg(op.getarg(2), args, |
| 1122 |
need_lower_byte=need_lower_byte) |
| 1123 |
ofs_loc = self.rm.make_sure_var_in_reg(op.getarg(1), args) |
| 1124 |
self.perform_discard(op, [base_loc, ofs_loc, value_loc, |
| 1125 |
imm(size)]) |
| 1126 |
|
| 1127 |
def consider_gc_store_indexed(self, op): |
| 1128 |
args = op.getarglist() |
| 1129 |
base_loc = self.rm.make_sure_var_in_reg(op.getarg(0), args) |
| 1130 |
scale_box = op.getarg(3) |
| 1131 |
offset_box = op.getarg(4) |
| 1132 |
size_box = op.getarg(5) |
| 1133 |
assert isinstance(scale_box, ConstInt) |
| 1134 |
assert isinstance(offset_box, ConstInt) |
| 1135 |
assert isinstance(size_box, ConstInt) |
| 1136 |
factor = scale_box.value |
| 1137 |
offset = offset_box.value |
| 1138 |
size = size_box.value |
| 1139 |
assert size >= 1 |
| 1140 |
if size == 1: |
| 1141 |
need_lower_byte = True |
| 1142 |
else: |
| 1143 |
need_lower_byte = False |
| 1144 |
value_loc = self.make_sure_var_in_reg(op.getarg(2), args, |
| 1145 |
need_lower_byte=need_lower_byte) |
| 1146 |
ofs_loc = self.rm.make_sure_var_in_reg(op.getarg(1), args) |
| 1147 |
self.perform_discard(op, [base_loc, ofs_loc, value_loc, |
| 1148 |
imm(factor), imm(offset), imm(size)]) |
| 1149 |
|
| 1150 |
def consider_increment_debug_counter(self, op): |
| 1151 |
base_loc = self.loc(op.getarg(0)) |
| 1152 |
self.perform_discard(op, [base_loc]) |
| 1153 |
|
| 1154 |
def _consider_gc_load(self, op): |
| 1155 |
args = op.getarglist() |
| 1156 |
base_loc = self.rm.make_sure_var_in_reg(op.getarg(0), args) |
| 1157 |
ofs_loc = self.rm.make_sure_var_in_reg(op.getarg(1), args) |
| 1158 |
result_loc = self.force_allocate_reg(op) |
| 1159 |
size_box = op.getarg(2) |
| 1160 |
assert isinstance(size_box, ConstInt) |
| 1161 |
nsize = size_box.value |
| 1162 |
size_loc = imm(abs(nsize)) |
| 1163 |
if nsize < 0: |
| 1164 |
sign_loc = imm1 |
| 1165 |
else: |
| 1166 |
sign_loc = imm0 |
| 1167 |
self.perform(op, [base_loc, ofs_loc, size_loc, sign_loc], result_loc) |
| 1168 |
|
| 1169 |
consider_gc_load_i = _consider_gc_load |
| 1170 |
consider_gc_load_r = _consider_gc_load |
| 1171 |
consider_gc_load_f = _consider_gc_load |
| 1172 |
|
| 1173 |
def _consider_gc_load_indexed(self, op): |
| 1174 |
args = op.getarglist() |
| 1175 |
base_loc = self.rm.make_sure_var_in_reg(op.getarg(0), args) |
| 1176 |
ofs_loc = self.rm.make_sure_var_in_reg(op.getarg(1), args) |
| 1177 |
result_loc = self.force_allocate_reg(op) |
| 1178 |
scale_box = op.getarg(2) |
| 1179 |
offset_box = op.getarg(3) |
| 1180 |
size_box = op.getarg(4) |
| 1181 |
assert isinstance(scale_box, ConstInt) |
| 1182 |
assert isinstance(offset_box, ConstInt) |
| 1183 |
assert isinstance(size_box, ConstInt) |
| 1184 |
scale = scale_box.value |
| 1185 |
offset = offset_box.value |
| 1186 |
nsize = size_box.value |
| 1187 |
size_loc = imm(abs(nsize)) |
| 1188 |
if nsize < 0: |
| 1189 |
sign_loc = imm1 |
| 1190 |
else: |
| 1191 |
sign_loc = imm0 |
| 1192 |
locs = [base_loc, ofs_loc, imm(scale), imm(offset), size_loc, sign_loc] |
| 1193 |
self.perform(op, locs, result_loc) |
| 1194 |
|
| 1195 |
consider_gc_load_indexed_i = _consider_gc_load_indexed |
| 1196 |
consider_gc_load_indexed_r = _consider_gc_load_indexed |
| 1197 |
consider_gc_load_indexed_f = _consider_gc_load_indexed |
| 1198 |
|
| 1199 |
def consider_int_is_true(self, op): |
| 1200 |
|
| 1201 |
argloc = self.loc(op.getarg(0)) |
| 1202 |
resloc = self.force_allocate_reg_or_cc(op) |
| 1203 |
self.perform(op, [argloc], resloc) |
| 1204 |
|
| 1205 |
consider_int_is_zero = consider_int_is_true |
| 1206 |
|
| 1207 |
def _consider_same_as(self, op): |
| 1208 |
argloc = self.loc(op.getarg(0)) |
| 1209 |
resloc = self.force_allocate_reg(op) |
| 1210 |
self.perform(op, [argloc], resloc) |
| 1211 |
consider_cast_ptr_to_int = _consider_same_as |
| 1212 |
consider_cast_int_to_ptr = _consider_same_as |
| 1213 |
consider_same_as_i = _consider_same_as |
| 1214 |
consider_same_as_r = _consider_same_as |
| 1215 |
consider_same_as_f = _consider_same_as |
| 1216 |
|
| 1217 |
def consider_load_from_gc_table(self, op): |
| 1218 |
resloc = self.rm.force_allocate_reg(op) |
| 1219 |
self.perform(op, [], resloc) |
| 1220 |
|
| 1221 |
def consider_int_force_ge_zero(self, op): |
| 1222 |
argloc = self.make_sure_var_in_reg(op.getarg(0)) |
| 1223 |
resloc = self.force_allocate_reg(op, [op.getarg(0)]) |
| 1224 |
self.perform(op, [argloc], resloc) |
| 1225 |
|
| 1226 |
def consider_load_effective_address(self, op): |
| 1227 |
p0 = op.getarg(0) |
| 1228 |
i0 = op.getarg(1) |
| 1229 |
ploc = self.make_sure_var_in_reg(p0, [i0]) |
| 1230 |
iloc = self.make_sure_var_in_reg(i0, [p0]) |
| 1231 |
res = self.rm.force_allocate_reg(op, [p0, i0]) |
| 1232 |
assert isinstance(op.getarg(2), ConstInt) |
| 1233 |
assert isinstance(op.getarg(3), ConstInt) |
| 1234 |
self.assembler.load_effective_addr(iloc, op.getarg(2).getint(), |
| 1235 |
op.getarg(3).getint(), res, ploc) |
| 1236 |
|
| 1237 |
def _consider_math_read_timestamp(self, op): |
| 1238 |
|
| 1239 |
self.rm.spill_or_move_registers_before_call([eax, edx]) |
| 1240 |
tmpbox_high = TempVar() |
| 1241 |
self.rm.force_allocate_reg(tmpbox_high, selected_reg=eax) |
| 1242 |
if longlong.is_64_bit: |
| 1243 |
|
| 1244 |
|
| 1245 |
result_loc = self.rm.force_allocate_reg(op, |
| 1246 |
selected_reg=edx) |
| 1247 |
self.perform_math(op, [], result_loc) |
| 1248 |
else: |
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
tmpbox_low = TempVar() |
| 1253 |
self.rm.force_allocate_reg(tmpbox_low, selected_reg=edx) |
| 1254 |
xmmtmpbox = TempVar() |
| 1255 |
xmmtmploc = self.xrm.force_allocate_reg(xmmtmpbox) |
| 1256 |
result_loc = self.xrm.force_allocate_reg(op) |
| 1257 |
self.perform_math(op, [xmmtmploc], result_loc) |
| 1258 |
self.xrm.possibly_free_var(xmmtmpbox) |
| 1259 |
self.rm.possibly_free_var(tmpbox_low) |
| 1260 |
self.rm.possibly_free_var(tmpbox_high) |
| 1261 |
|
| 1262 |
def compute_hint_frame_locations(self, operations): |
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
op = operations[-1] |
| 1267 |
if op.getopnum() != rop.JUMP: |
| 1268 |
return |
| 1269 |
self.final_jump_op = op |
| 1270 |
self.final_jump_op_position = len(operations) - 1 |
| 1271 |
descr = op.getdescr() |
| 1272 |
assert isinstance(descr, TargetToken) |
| 1273 |
if descr._ll_loop_code != 0: |
| 1274 |
|
| 1275 |
|
| 1276 |
self._compute_hint_locations_from_descr(descr) |
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
def _compute_hint_locations_from_descr(self, descr): |
| 1285 |
arglocs = descr._x86_arglocs |
| 1286 |
jump_op = self.final_jump_op |
| 1287 |
assert len(arglocs) == jump_op.numargs() |
| 1288 |
hinted = [] |
| 1289 |
for i in range(jump_op.numargs()): |
| 1290 |
box = jump_op.getarg(i) |
| 1291 |
if not isinstance(box, Const): |
| 1292 |
loc = arglocs[i] |
| 1293 |
if isinstance(loc, FrameLoc): |
| 1294 |
self.fm.add_frame_pos_hint(box, loc) |
| 1295 |
else: |
| 1296 |
if box not in hinted: |
| 1297 |
hinted.append(box) |
| 1298 |
assert isinstance(loc, RegLoc) |
| 1299 |
self.longevity.fixed_register( |
| 1300 |
self.final_jump_op_position, |
| 1301 |
loc, box) |
| 1302 |
|
| 1303 |
def consider_jump(self, op): |
| 1304 |
assembler = self.assembler |
| 1305 |
assert self.jump_target_descr is None |
| 1306 |
descr = op.getdescr() |
| 1307 |
assert isinstance(descr, TargetToken) |
| 1308 |
arglocs = descr._x86_arglocs |
| 1309 |
self.jump_target_descr = descr |
| 1310 |
|
| 1311 |
src_locations1 = [] |
| 1312 |
dst_locations1 = [] |
| 1313 |
|
| 1314 |
src_locations2 = [] |
| 1315 |
dst_locations2 = [] |
| 1316 |
|
| 1317 |
for i in range(op.numargs()): |
| 1318 |
box = op.getarg(i) |
| 1319 |
src_loc = self.loc(box) |
| 1320 |
dst_loc = arglocs[i] |
| 1321 |
if box.type != FLOAT and not box.is_vector(): |
| 1322 |
src_locations1.append(src_loc) |
| 1323 |
dst_locations1.append(dst_loc) |
| 1324 |
else: |
| 1325 |
src_locations2.append(src_loc) |
| 1326 |
dst_locations2.append(dst_loc) |
| 1327 |
|
| 1328 |
if IS_X86_64: |
| 1329 |
tmpreg = X86_64_SCRATCH_REG |
| 1330 |
xmmtmp = X86_64_XMM_SCRATCH_REG |
| 1331 |
else: |
| 1332 |
tmpreg = None |
| 1333 |
xmmtmp = None |
| 1334 |
|
| 1335 |
num_moves = remap_frame_layout_mixed(assembler, |
| 1336 |
src_locations1, dst_locations1, tmpreg, |
| 1337 |
src_locations2, dst_locations2, xmmtmp) |
| 1338 |
self.possibly_free_vars_for_op(op) |
| 1339 |
assembler.closing_jump(self.jump_target_descr) |
| 1340 |
assembler.num_moves_jump += num_moves |
| 1341 |
|
| 1342 |
def consider_enter_portal_frame(self, op): |
| 1343 |
self.assembler.enter_portal_frame(op) |
| 1344 |
|
| 1345 |
def consider_leave_portal_frame(self, op): |
| 1346 |
self.assembler.leave_portal_frame(op) |
| 1347 |
|
| 1348 |
def consider_jit_debug(self, op): |
| 1349 |
pass |
| 1350 |
|
| 1351 |
def _consider_force_spill(self, op): |
| 1352 |
|
| 1353 |
self.force_spill_var(op.getarg(0)) |
| 1354 |
|
| 1355 |
def consider_force_token(self, op): |
| 1356 |
|
| 1357 |
|
| 1358 |
self.assembler.force_token(self.rm.force_allocate_reg(op)) |
| 1359 |
|
| 1360 |
def consider_label(self, op): |
| 1361 |
descr = op.getdescr() |
| 1362 |
assert isinstance(descr, TargetToken) |
| 1363 |
inputargs = op.getarglist() |
| 1364 |
arglocs = [None] * len(inputargs) |
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
position = self.rm.position |
| 1371 |
for arg in inputargs: |
| 1372 |
assert not isinstance(arg, Const) |
| 1373 |
if self.longevity[arg].is_last_real_use_before(position): |
| 1374 |
self.force_spill_var(arg) |
| 1375 |
|
| 1376 |
|
| 1377 |
for arg in inputargs: |
| 1378 |
if self.loc(arg) is ebp: |
| 1379 |
loc2 = self.fm.loc(arg) |
| 1380 |
self.assembler.mc.MOV(loc2, ebp) |
| 1381 |
self.rm.box_currently_in_frame_reg = None |
| 1382 |
|
| 1383 |
for i in range(len(inputargs)): |
| 1384 |
arg = inputargs[i] |
| 1385 |
assert not isinstance(arg, Const) |
| 1386 |
loc = self.loc(arg) |
| 1387 |
assert loc is not ebp |
| 1388 |
arglocs[i] = loc |
| 1389 |
if isinstance(loc, RegLoc): |
| 1390 |
self.fm.mark_as_free(arg) |
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
self.flush_loop() |
| 1395 |
|
| 1396 |
descr._x86_arglocs = arglocs |
| 1397 |
descr._ll_loop_code = self.assembler.mc.get_relative_pos() |
| 1398 |
descr._x86_clt = self.assembler.current_clt |
| 1399 |
self.assembler.target_tokens_currently_compiling[descr] = None |
| 1400 |
self.possibly_free_vars_for_op(op) |
| 1401 |
self.assembler.label() |
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
jump_op = self.final_jump_op |
| 1408 |
if jump_op is not None and jump_op.getdescr() is descr: |
| 1409 |
self._compute_hint_locations_from_descr(descr) |
| 1410 |
|
| 1411 |
def consider_guard_not_forced_2(self, op): |
| 1412 |
self.rm.before_call(op.getfailargs(), save_all_regs=True) |
| 1413 |
self.xrm.before_call(op.getfailargs(), save_all_regs=True) |
| 1414 |
fail_locs = [self.loc(v) for v in op.getfailargs()] |
| 1415 |
self.assembler.store_force_descr(op, fail_locs, |
| 1416 |
self.fm.get_frame_depth()) |
| 1417 |
self.possibly_free_vars(op.getfailargs()) |
| 1418 |
|
| 1419 |
def consider_keepalive(self, op): |
| 1420 |
pass |
| 1421 |
|
| 1422 |
def _scaled_addr(self, index_loc, itemsize_loc, |
| 1423 |
base_loc, ofs_loc): |
| 1424 |
assert isinstance(itemsize_loc, ImmedLoc) |
| 1425 |
itemsize = itemsize_loc.value |
| 1426 |
if isinstance(index_loc, ImmedLoc): |
| 1427 |
temp_loc = imm(index_loc.value * itemsize) |
| 1428 |
shift = 0 |
| 1429 |
else: |
| 1430 |
assert valid_addressing_size(itemsize), "rewrite did not correctly handle shift/mul!" |
| 1431 |
temp_loc = index_loc |
| 1432 |
shift = get_scale(itemsize) |
| 1433 |
assert isinstance(ofs_loc, ImmedLoc) |
| 1434 |
return AddressLoc(base_loc, temp_loc, shift, ofs_loc.value) |
| 1435 |
|
| 1436 |
def consider_zero_array(self, op): |
| 1437 |
_, baseofs, _ = unpack_arraydescr(op.getdescr()) |
| 1438 |
length_box = op.getarg(2) |
| 1439 |
|
| 1440 |
scale_box = op.getarg(3) |
| 1441 |
assert isinstance(scale_box, ConstInt) |
| 1442 |
start_itemsize = scale_box.value |
| 1443 |
|
| 1444 |
len_scale_box = op.getarg(4) |
| 1445 |
assert isinstance(len_scale_box, ConstInt) |
| 1446 |
len_itemsize = len_scale_box.value |
| 1447 |
|
| 1448 |
constbytes = -1 |
| 1449 |
if isinstance(length_box, ConstInt): |
| 1450 |
constbytes = length_box.getint() |
| 1451 |
args = op.getarglist() |
| 1452 |
base_loc = self.rm.make_sure_var_in_reg(args[0], args) |
| 1453 |
startindex_loc = self.rm.make_sure_var_in_reg(args[1], args) |
| 1454 |
if 0 <= constbytes <= 16 * 8: |
| 1455 |
if IS_X86_64: |
| 1456 |
null_loc = X86_64_XMM_SCRATCH_REG |
| 1457 |
else: |
| 1458 |
null_box = TempVar() |
| 1459 |
null_loc = self.xrm.force_allocate_reg(null_box) |
| 1460 |
self.xrm.possibly_free_var(null_box) |
| 1461 |
self.perform_discard(op, [base_loc, startindex_loc, |
| 1462 |
imm(constbytes), imm(start_itemsize), |
| 1463 |
imm(baseofs), null_loc]) |
| 1464 |
else: |
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
dstaddr_box = TempVar() |
| 1471 |
dstaddr_loc = self.rm.force_allocate_reg(dstaddr_box, [args[2]]) |
| 1472 |
itemsize_loc = imm(start_itemsize) |
| 1473 |
dst_addr = self._scaled_addr(startindex_loc, itemsize_loc, |
| 1474 |
base_loc, imm(baseofs)) |
| 1475 |
self.assembler.mc.LEA(dstaddr_loc, dst_addr) |
| 1476 |
|
| 1477 |
if constbytes >= 0: |
| 1478 |
length_loc = imm(constbytes) |
| 1479 |
else: |
| 1480 |
|
| 1481 |
length_loc = self.rm.make_sure_var_in_reg(length_box, |
| 1482 |
[dstaddr_box]) |
| 1483 |
if len_itemsize > 1: |
| 1484 |
|
| 1485 |
|
| 1486 |
|
| 1487 |
bytes_box = TempVar() |
| 1488 |
bytes_loc = self.rm.force_allocate_reg(bytes_box, |
| 1489 |
[dstaddr_box]) |
| 1490 |
len_itemsize_loc = imm(len_itemsize) |
| 1491 |
b_adr = self._scaled_addr(length_loc, len_itemsize_loc, imm0, imm0) |
| 1492 |
self.assembler.mc.LEA(bytes_loc, b_adr) |
| 1493 |
length_box = bytes_box |
| 1494 |
length_loc = bytes_loc |
| 1495 |
|
| 1496 |
|
| 1497 |
self.rm.before_call() |
| 1498 |
self.xrm.before_call() |
| 1499 |
self.assembler.simple_call_no_collect( |
| 1500 |
imm(self.assembler.memset_addr), |
| 1501 |
[dstaddr_loc, imm0, length_loc]) |
| 1502 |
self.rm.possibly_free_var(length_box) |
| 1503 |
self.rm.possibly_free_var(dstaddr_box) |
| 1504 |
|
| 1505 |
def not_implemented_op(self, op): |
| 1506 |
not_implemented("not implemented operation: %s" % op.getopname()) |
| 1507 |
|
| 1508 |
oplist = [RegAlloc.not_implemented_op] * rop._LAST |
| 1509 |
|
| 1510 |
import itertools |
| 1511 |
iterate = itertools.chain(RegAlloc.__dict__.iteritems(), |
| 1512 |
VectorRegallocMixin.__dict__.iteritems()) |
| 1513 |
for name, value in iterate: |
| 1514 |
if name.startswith('consider_'): |
| 1515 |
name = name[len('consider_'):] |
| 1516 |
num = getattr(rop, name.upper()) |
| 1517 |
oplist[num] = value |
| 1518 |
|
| 1519 |
def get_ebp_ofs(base_ofs, position): |
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
return base_ofs + WORD * (position + JITFRAME_FIXED_SIZE) |
| 1524 |
|
| 1525 |
def not_implemented(msg): |
| 1526 |
msg = '[x86/regalloc] %s\n' % msg |
| 1527 |
if we_are_translated(): |
| 1528 |
llop.debug_print(lltype.Void, msg) |
| 1529 |
raise NotImplementedError(msg) |