if b2.is_constant() and b2.getint() == 1: self.make_equal_to(op, arg0) return elif b1.is_constant() and b1.getint() == 0: self.make_constant_int(op, 0) return if b1.known_ge(IntBound(0, 0)) and b2.is_constant(): val = b2.getint() if val & (val - 1) == 0 and val > 0: # val == 2**shift op = self.replace_op_with(op, rop.INT_RSHIFT, args = [op.getarg(0), ConstInt(highest_bit(val))]) self.emit_operation(op) def optimize_CAST_PTR_TO_INT(self, op): self.optimizer.pure_reverse(op) self.emit_operation(op) def optimize_CAST_INT_TO_PTR(self, op): self.optimizer.pure_reverse(op) self.emit_operation(op) def optimize_SAME_AS_I(self, op): self.make_equal_to(op, op.getarg(0)) optimize_SAME_AS_R = optimize_SAME_AS_I optimize_SAME_AS_F = optimize_SAME_AS_I dispatch_opt = make_dispatcher_method(OptRewrite, 'optimize_', default=OptRewrite.emit_operation) optimize_guards = _findall(OptRewrite, 'optimize_', 'GUARD')
return self.emit(op) def optimize_CAST_INT_TO_PTR(self, op): self.optimizer.pure_from_args(rop.CAST_PTR_TO_INT, [op], op.getarg(0)) return self.emit(op) def optimize_SAME_AS_I(self, op): self.make_equal_to(op, op.getarg(0)) optimize_SAME_AS_R = optimize_SAME_AS_I optimize_SAME_AS_F = optimize_SAME_AS_I def serialize_optrewrite(self, available_boxes): res = [] for i, box in self.loop_invariant_results.iteritems(): box = get_box_replacement(box) if box in available_boxes: res.append((i, box)) return res def deserialize_optrewrite(self, tups): for i, box in tups: self.loop_invariant_results[i] = box dispatch_opt = make_dispatcher_method(OptRewrite, 'optimize_', default=OptRewrite.emit) optimize_guards = _findall(OptRewrite, 'optimize_', 'GUARD') dispatch_postprocess = make_dispatcher_method(OptRewrite, 'postprocess_')
return True else: from rpython.jit.metainterp.optimizeopt import intdiv known_nonneg = b1.known_ge(IntBound(0, 0)) operations = intdiv.modulo_operations(arg1, val, known_nonneg) newop = None for newop in operations: self.optimizer.send_extra_operation(newop) self.make_equal_to(op, newop) return True def optimize_CAST_PTR_TO_INT(self, op): self.optimizer.pure_from_args(rop.CAST_INT_TO_PTR, [op], op.getarg(0)) return self.emit(op) def optimize_CAST_INT_TO_PTR(self, op): self.optimizer.pure_from_args(rop.CAST_PTR_TO_INT, [op], op.getarg(0)) return self.emit(op) def optimize_SAME_AS_I(self, op): self.make_equal_to(op, op.getarg(0)) optimize_SAME_AS_R = optimize_SAME_AS_I optimize_SAME_AS_F = optimize_SAME_AS_I dispatch_opt = make_dispatcher_method(OptRewrite, "optimize_", default=OptRewrite.emit) optimize_guards = _findall(OptRewrite, "optimize_", "GUARD") dispatch_postprocess = make_dispatcher_method(OptRewrite, "postprocess_")