Author: Maciej Fijalkowski <fij...@gmail.com> Branch: optresult-unroll Changeset: r79520:6cf467e2b9fb Date: 2015-09-08 10:26 +0200 http://bitbucket.org/pypy/pypy/changeset/6cf467e2b9fb/
Log: merge diff --git a/rpython/jit/backend/test/test_random.py b/rpython/jit/backend/test/test_random.py --- a/rpython/jit/backend/test/test_random.py +++ b/rpython/jit/backend/test/test_random.py @@ -2,12 +2,13 @@ import pytest from rpython.rlib.rarithmetic import intmask, LONG_BIT from rpython.jit.metainterp.history import BasicFailDescr, TreeLoop, BasicFinalDescr -from rpython.jit.metainterp.history import BoxInt, ConstInt, JitCellToken, Box -from rpython.jit.metainterp.history import BoxPtr, ConstPtr, TargetToken -from rpython.jit.metainterp.history import BoxFloat, ConstFloat, Const -from rpython.jit.metainterp.history import INT, FLOAT +from rpython.jit.metainterp.history import INT, ConstInt, JitCellToken +from rpython.jit.metainterp.history import REF, ConstPtr, TargetToken +from rpython.jit.metainterp.history import FLOAT, ConstFloat, Const, VOID from rpython.jit.metainterp.resoperation import ResOperation, rop -from rpython.jit.metainterp.executor import execute_nonspec +from rpython.jit.metainterp.resoperation import InputArgInt, InputArgRef +from rpython.jit.metainterp.resoperation import InputArgFloat +from rpython.jit.metainterp.executor import execute_nonspec_const from rpython.jit.metainterp.resoperation import opname from rpython.jit.codewriter import longlong from rpython.rtyper.lltypesystem import lltype, rstr @@ -31,11 +32,11 @@ cpu._faildescr_keepalive = [] self.fakemetainterp = FakeMetaInterp() self.loop = loop - self.intvars = [box for box in vars if isinstance(box, BoxInt)] + self.intvars = [box for box in vars if box.type == INT] self.boolvars = [] # subset of self.intvars self.ptrvars = [] self.prebuilt_ptr_consts = [] - floatvars = [box for box in vars if isinstance(box, BoxFloat)] + floatvars = [box for box in vars if box.type == FLOAT] if cpu.supports_floats: self.floatvars = floatvars else: @@ -53,16 +54,15 @@ def do(self, opnum, argboxes, descr=None): self.fakemetainterp._got_exc = None - if opnum == rop.ZERO_PTR_FIELD: - v_result = None - else: - v_result = execute_nonspec(self.cpu, self.fakemetainterp, - opnum, argboxes, descr) - if isinstance(v_result, Const): - v_result = v_result.clonebox() - self.loop.operations.append(ResOperation(opnum, argboxes, v_result, - descr)) - return v_result + op = ResOperation(opnum, argboxes, descr) + if opnum != rop.ZERO_PTR_FIELD: + assert op.type != VOID, op + c_result = execute_nonspec_const(self.cpu, self.fakemetainterp, + opnum, argboxes, descr, + type=op.type) + op.copy_value_from(c_result) + self.loop.operations.append(op) + return op def get_bool_var(self, r): if self.boolvars and r.random() < 0.8: @@ -100,13 +100,13 @@ if v in names: args.append(names[v]) elif isinstance(v, ConstPtr): - assert not v.value # otherwise should be in the names + assert not v.getref_base() # otherwise should be in the names args.append('ConstPtr(lltype.nullptr(llmemory.GCREF.TO))') elif isinstance(v, ConstFloat): args.append('ConstFloat(longlong.getfloatstorage(%r))' % v.getfloat()) elif isinstance(v, ConstInt): - args.append('ConstInt(%s)' % v.value) + args.append('ConstInt(%s)' % v.getint()) else: raise NotImplementedError(v) if op.getdescr() is None: @@ -119,13 +119,13 @@ descrstr = ', TargetToken()' else: descrstr = ', descr=' + self.descr_counters.get(op.getdescr(), '...') - print >>s, ' ResOperation(rop.%s, [%s], %s%s),' % ( - opname[op.getopnum()], ', '.join(args), names[op.result], descrstr) + print >>s, ' %s = ResOperation(rop.%s, [%s]%s),' % ( + names[op], opname[op.getopnum()], ', '.join(args), descrstr) def print_loop(self, output, fail_descr=None, fail_args=None): def update_names(ops): for op in ops: - v = op.result + v = op if v not in names: writevar(v, 'tmp') if op.is_guard() or op.opnum == rop.FINISH: @@ -197,10 +197,10 @@ # def writevar(v, nameprefix, init=''): if nameprefix == 'const_ptr': - if not v.value: + if not v.getref_base(): return 'lltype.nullptr(llmemory.GCREF.TO)' - TYPE = v.value._obj.ORIGTYPE - cont = lltype.cast_opaque_ptr(TYPE, v.value) + TYPE = v.getref_base()._obj.ORIGTYPE + cont = lltype.cast_opaque_ptr(TYPE, v.getref_base()) if TYPE.TO._is_varsize(): if isinstance(TYPE.TO, lltype.GcStruct): lgt = len(cont.chars) @@ -249,8 +249,8 @@ if hasattr(self.loop, 'inputargs'): vals = [] for i, v in enumerate(self.loop.inputargs): - assert isinstance(v, Box) - if isinstance(v, BoxFloat): + assert not isinstance(v, Const) + if v.type == FLOAT: vals.append("longlong.getfloatstorage(%r)" % v.getfloat()) else: vals.append("%r" % v.getint()) @@ -261,12 +261,12 @@ else: fail_args = self.should_fail_by.getfailargs() for i, v in enumerate(fail_args): - if isinstance(v, (BoxFloat, ConstFloat)): + if v.type == FLOAT: print >>s, (' assert longlong.getrealfloat(' - 'cpu.get_float_value(frame, %d)) == %r' % (i, v.value)) + 'cpu.get_float_value(frame, %d)) == %r' % (i, v.getfloatstorage())) else: print >>s, (' assert cpu.get_int_value(frame, %d) == %d' - % (i, v.value)) + % (i, v.getint())) self.names = names s.flush() @@ -290,14 +290,14 @@ def put(self, builder, args, descr=None): v_result = builder.do(self.opnum, args, descr=descr) if v_result is not None: - if isinstance(v_result, BoxInt): + if v_result.type == INT: builder.intvars.append(v_result) boolres = self.boolres if boolres == 'sometimes': - boolres = v_result.value in [0, 1] + boolres = v_result.getint() in [0, 1] if boolres: builder.boolvars.append(v_result) - elif isinstance(v_result, BoxFloat): + elif v_result.type == FLOAT: builder.floatvars.append(v_result) assert self.boolres != True else: @@ -316,10 +316,8 @@ def produce_into(self, builder, r): if r.random() < 0.4: UnaryOperation.produce_into(self, builder, r) - elif r.random() < 0.75 or not builder.cpu.supports_floats: + else: self.put(builder, [ConstInt(r.random_integer())]) - else: - self.put(builder, [ConstFloat(r.random_float_storage())]) class SignExtOperation(AbstractOperation): def produce_into(self, builder, r): @@ -345,9 +343,11 @@ v_second = ConstInt((value & self.and_mask) | self.or_mask) else: v = r.choice(builder.intvars) - if (v.value & self.and_mask) != v.value: + v_value = v.getint() + if (v_value & self.and_mask) != v_value: v = builder.do(rop.INT_AND, [v, ConstInt(self.and_mask)]) - if (v.value | self.or_mask) != v.value: + v_value = v.getint() + if (v_value | self.or_mask) != v_value: v = builder.do(rop.INT_OR, [v, ConstInt(self.or_mask)]) v_second = v self.put(builder, [v_first, v_second]) @@ -359,14 +359,14 @@ super(AbstractOvfOperation, self).produce_into(builder, r) if builder.fakemetainterp._got_exc: # overflow detected assert isinstance(builder.fakemetainterp._got_exc, OverflowError) - op = ResOperation(rop.GUARD_OVERFLOW, [], None) + op = ResOperation(rop.GUARD_OVERFLOW, []) # the overflowed result should not be used any more, but can # be used on the failure path: recompute fail_subset including # the result, and then remove it from builder.intvars. fail_subset = builder.subset_of_intvars(r) builder.intvars[:] = original_intvars else: - op = ResOperation(rop.GUARD_NO_OVERFLOW, [], None) + op = ResOperation(rop.GUARD_NO_OVERFLOW, []) op.setdescr(builder.getfaildescr()) op.setfailargs(fail_subset) builder.loop.operations.append(op) @@ -404,6 +404,13 @@ raise CannotProduceOperation self.put(builder, [r.choice(builder.floatvars)]) +class ConstUnaryFloatOperation(UnaryFloatOperation): + def produce_into(self, builder, r): + if r.random() < 0.4: + UnaryFloatOperation.produce_into(self, builder, r) + else: + self.put(builder, [ConstFloat(r.random_float_storage())]) + class CastIntToFloatOperation(AbstractFloatOperation): def produce_into(self, builder, r): self.put(builder, [r.choice(builder.intvars)]) @@ -429,9 +436,9 @@ class GuardOperation(AbstractOperation): def gen_guard(self, builder, r): v = builder.get_bool_var(r) - op = ResOperation(self.opnum, [v], None) - passing = ((self.opnum == rop.GUARD_TRUE and v.value) or - (self.opnum == rop.GUARD_FALSE and not v.value)) + op = ResOperation(self.opnum, [v]) + passing = ((self.opnum == rop.GUARD_TRUE and v.getint()) or + (self.opnum == rop.GUARD_FALSE and not v.getint())) return op, passing def produce_into(self, builder, r): @@ -448,9 +455,9 @@ if not builder.ptrvars: raise CannotProduceOperation box = r.choice(builder.ptrvars)[0] - op = ResOperation(self.opnum, [box], None) - passing = ((self.opnum == rop.GUARD_NONNULL and box.value) or - (self.opnum == rop.GUARD_ISNULL and not box.value)) + op = ResOperation(self.opnum, [box]) + passing = ((self.opnum == rop.GUARD_NONNULL and box.getref_base()) or + (self.opnum == rop.GUARD_ISNULL and not box.getref_base())) return op, passing class GuardValueOperation(GuardOperation): @@ -460,14 +467,14 @@ other = r.choice(builder.intvars) else: if r.random() < 0.75: - value = v.value + value = v.getint() elif r.random() < 0.5: - value = v.value ^ 1 + value = v.getint() ^ 1 else: value = r.random_integer() other = ConstInt(value) - op = ResOperation(self.opnum, [v, other], None) - return op, (v.value == other.value) + op = ResOperation(self.opnum, [v, other]) + return op, (v.getint() == other.getint()) # ____________________________________________________________ @@ -516,7 +523,8 @@ OPERATIONS.append(UnaryOperation(rop.INT_IS_TRUE, boolres=True)) OPERATIONS.append(UnaryOperation(rop.INT_IS_ZERO, boolres=True)) -OPERATIONS.append(ConstUnaryOperation(rop.SAME_AS, boolres='sometimes')) +OPERATIONS.append(ConstUnaryOperation(rop.SAME_AS_I, boolres='sometimes')) +OPERATIONS.append(ConstUnaryFloatOperation(rop.SAME_AS_F)) OPERATIONS.append(SignExtOperation(rop.INT_SIGNEXT)) for _op in [rop.INT_ADD_OVF, @@ -616,19 +624,19 @@ startvars = [] if cpu.supports_floats: # pick up a single threshold for the whole 'inputargs', so - # that some loops have no or mostly no BoxFloat while others + # that some loops have no or mostly no FLOATs while others # have a lot of them k = r.random() - # but make sure there is at least one BoxInt + # but make sure there is at least one INT at_least_once = r.randrange(0, pytest.config.option.n_vars) else: k = -1 at_least_once = 0 for i in range(pytest.config.option.n_vars): if r.random() < k and i != at_least_once: - startvars.append(BoxFloat(r.random_float_storage())) + startvars.append(InputArgFloat(r.random_float_storage())) else: - startvars.append(BoxInt(r.random_integer())) + startvars.append(InputArgInt(r.random_integer())) allow_delay = True else: allow_delay = False @@ -665,13 +673,13 @@ for i in range(position): op = loop.operations[i] if (not op.has_no_side_effect() - or not isinstance(op.result, (BoxInt, BoxFloat))): + or op.type not in (INT, FLOAT)): position = i break # cannot move the LABEL later randompos = r.randrange(0, len(self.startvars)+1) - self.startvars.insert(randompos, op.result) + self.startvars.insert(randompos, op) loop._targettoken = TargetToken() - loop.operations.insert(position, ResOperation(rop.LABEL, self.startvars, None, + loop.operations.insert(position, ResOperation(rop.LABEL, self.startvars, loop._targettoken)) def generate_ops(self, builder, r, loop, startvars, needs_a_label=False): @@ -704,7 +712,7 @@ endvars.append(v) r.shuffle(endvars) endvars = endvars[:1] - loop.operations.append(ResOperation(rop.FINISH, endvars, None, + loop.operations.append(ResOperation(rop.FINISH, endvars, descr=builder.getfaildescr(is_finish=True))) if builder.should_fail_by: self.should_fail_by = builder.should_fail_by @@ -716,7 +724,12 @@ endvars = self.get_fail_args() self.expected = {} for v in endvars: - self.expected[v] = v.value + if v.type == INT: + self.expected[v] = v.getint() + elif v.type == FLOAT: + self.expected[v] = v.getfloatstorage() + else: + assert 0, v.type def runjitcelltoken(self): if self.startvars == self.loop.inputargs: @@ -729,7 +742,7 @@ box = box.constbox() args.append(box) self.cpu.compile_loop(self.loop.inputargs, - [ResOperation(rop.JUMP, args, None, + [ResOperation(rop.JUMP, args, descr=self.loop._targettoken)], self._initialjumploop_celltoken) return self._initialjumploop_celltoken @@ -744,7 +757,7 @@ def clear_state(self): for v, S, fields in self.prebuilt_ptr_consts: - container = v.value._obj.container + container = v.getref_base()._obj.container for name, value in fields.items(): if isinstance(name, str): setattr(container, name, value) @@ -762,14 +775,21 @@ # exc = cpu.grab_exc_value() # assert not exc - arguments = [box.value for box in self.loop.inputargs] + arguments = [] + for box in self.loop.inputargs: + if box.type == INT: + arguments.append(box.getint()) + elif box.type == FLOAT: + arguments.append(box.getfloatstorage()) + else: + assert 0, box.type deadframe = cpu.execute_token(self.runjitcelltoken(), *arguments) fail = cpu.get_latest_descr(deadframe) do_assert(fail is self.should_fail_by.getdescr(), "Got %r, expected %r" % (fail, self.should_fail_by.getdescr())) for i, v in enumerate(self.get_fail_args()): - if isinstance(v, (BoxFloat, ConstFloat)): + if v.type == FLOAT: value = cpu.get_float_value(deadframe, i) else: value = cpu.get_int_value(deadframe, i) @@ -792,10 +812,9 @@ def exc_handling(guard_op): # operations need to start with correct GUARD_EXCEPTION if guard_op._exc_box is None: - op = ResOperation(rop.GUARD_NO_EXCEPTION, [], None) + op = ResOperation(rop.GUARD_NO_EXCEPTION, []) else: - op = ResOperation(rop.GUARD_EXCEPTION, [guard_op._exc_box], - BoxPtr()) + op = ResOperation(rop.GUARD_EXCEPTION, [guard_op._exc_box]) op.setdescr(self.builder.getfaildescr()) op.setfailargs([]) return op @@ -845,7 +864,14 @@ raise AssertionError(box.type) subset.append(srcbox) # - args = [x.clonebox() for x in subset] + args = [] + for x in subset: + if x.type == INT: + args.append(InputArgInt(x.getint())) + elif x.type == FLOAT: + args.append(InputArgFloat(x.getfloatstorage())) + else: + assert 0, x.type rl = RandomLoop(self.builder.cpu, self.builder.fork, r, args) # done @@ -854,7 +880,7 @@ assert len(rl.loop.inputargs) == len(args) # The new bridge's execution will end normally at its FINISH. # Just replace the FINISH with the JUMP to the new loop. - jump_op = ResOperation(rop.JUMP, subset, None, + jump_op = ResOperation(rop.JUMP, subset, descr=rl.loop._targettoken) subloop.operations[-1] = jump_op self.guard_op = rl.guard_op _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit