Beispiel #1
0
    def check_operation(self, state, pack, op):
        opnum = op.getopnum()
        descr = op.getdescr()
        if not we_are_translated() and not isinstance(descr, ArrayDescr):
            itemsize = descr.get_item_size_in_bytes()
            ofs = 0
        else:
            itemsize, ofs, _ = unpack_arraydescr(op.getdescr())
        args = [op.getarg(0), op.getarg(1), ConstInt(1), ConstInt(ofs)]
        if rop.is_getarrayitem(opnum) or \
             opnum in (rop.GETARRAYITEM_RAW_I, rop.GETARRAYITEM_RAW_F):
            index_box = op.getarg(1)
            scale, offset, changed, emit = cpu_simplify_scale(state.cpu, index_box, itemsize, ofs)
            args[2] = ConstInt(scale)
            args[3] = ConstInt(offset)
            if emit:
                state.oplist.append(changed)
                args[1] = changed

        return args
Beispiel #2
0
    def check_operation(self, state, pack, op):
        opnum = op.getopnum()
        descr = op.getdescr()
        if not we_are_translated() and not isinstance(descr, ArrayDescr):
            itemsize = descr.get_item_size_in_bytes()
            ofs = 0
        else:
            itemsize, ofs, _ = unpack_arraydescr(op.getdescr())
        args = [op.getarg(0), op.getarg(1), ConstInt(1), ConstInt(ofs)]
        if rop.is_getarrayitem(opnum) or \
             opnum in (rop.GETARRAYITEM_RAW_I, rop.GETARRAYITEM_RAW_F):
            index_box = op.getarg(1)
            scale, offset, changed, emit = cpu_simplify_scale(
                state.cpu, index_box, itemsize, ofs)
            args[2] = ConstInt(scale)
            args[3] = ConstInt(offset)
            if emit:
                state.oplist.append(changed)
                args[1] = changed

        return args
Beispiel #3
0
    def ensure_ptr_info_arg0(self, op):
        from rpython.jit.metainterp.optimizeopt import vstring

        arg0 = self.get_box_replacement(op.getarg(0))
        if arg0.is_constant():
            return info.ConstPtrInfo(arg0)
        opinfo = arg0.get_forwarded()
        if isinstance(opinfo, info.AbstractVirtualPtrInfo):
            return opinfo
        elif opinfo is not None:
            last_guard_pos = opinfo.get_last_guard_pos()
        else:
            last_guard_pos = -1
        assert opinfo is None or opinfo.__class__ is info.NonNullPtrInfo
        opnum = op.opnum
        if (rop.is_getfield(opnum) or opnum == rop.SETFIELD_GC
                or opnum == rop.QUASIIMMUT_FIELD):
            descr = op.getdescr()
            parent_descr = descr.get_parent_descr()
            if parent_descr.is_object():
                opinfo = info.InstancePtrInfo(parent_descr)
            else:
                opinfo = info.StructPtrInfo(parent_descr)
            opinfo.init_fields(parent_descr, descr.get_index())
        elif (rop.is_getarrayitem(opnum) or opnum == rop.SETARRAYITEM_GC
              or opnum == rop.ARRAYLEN_GC):
            opinfo = info.ArrayPtrInfo(op.getdescr())
        elif opnum in (rop.GUARD_CLASS, rop.GUARD_NONNULL_CLASS):
            opinfo = info.InstancePtrInfo()
        elif opnum in (rop.STRLEN, ):
            opinfo = vstring.StrPtrInfo(vstring.mode_string)
        elif opnum in (rop.UNICODELEN, ):
            opinfo = vstring.StrPtrInfo(vstring.mode_unicode)
        else:
            assert False, "operations %s unsupported" % op
        assert isinstance(opinfo, info.NonNullPtrInfo)
        opinfo.last_guard_pos = last_guard_pos
        arg0.set_forwarded(opinfo)
        return opinfo
Beispiel #4
0
 def ensure_ptr_info_arg0(self, op):
     from rpython.jit.metainterp.optimizeopt import vstring
     
     arg0 = self.get_box_replacement(op.getarg(0))
     if arg0.is_constant():
         return info.ConstPtrInfo(arg0)
     opinfo = arg0.get_forwarded()
     if isinstance(opinfo, info.AbstractVirtualPtrInfo):
         return opinfo
     elif opinfo is not None:
         last_guard_pos = opinfo.get_last_guard_pos()
     else:
         last_guard_pos = -1
     assert opinfo is None or opinfo.__class__ is info.NonNullPtrInfo
     opnum = op.opnum
     if (rop.is_getfield(opnum) or opnum == rop.SETFIELD_GC or
         opnum == rop.QUASIIMMUT_FIELD):
         descr = op.getdescr()
         parent_descr = descr.get_parent_descr()
         if parent_descr.is_object():
             opinfo = info.InstancePtrInfo(parent_descr)
         else:
             opinfo = info.StructPtrInfo(parent_descr)
         opinfo.init_fields(parent_descr, descr.get_index())
     elif (rop.is_getarrayitem(opnum) or opnum == rop.SETARRAYITEM_GC or
           opnum == rop.ARRAYLEN_GC):
         opinfo = info.ArrayPtrInfo(op.getdescr())
     elif opnum in (rop.GUARD_CLASS, rop.GUARD_NONNULL_CLASS):
         opinfo = info.InstancePtrInfo()
     elif opnum in (rop.STRLEN,):
         opinfo = vstring.StrPtrInfo(vstring.mode_string)            
     elif opnum in (rop.UNICODELEN,):
         opinfo = vstring.StrPtrInfo(vstring.mode_unicode)
     else:
         assert False, "operations %s unsupported" % op
     assert isinstance(opinfo, info.NonNullPtrInfo)
     opinfo.last_guard_pos = last_guard_pos
     arg0.set_forwarded(opinfo)
     return opinfo
Beispiel #5
0
 def transform_to_gc_load(self, op):
     NOT_SIGNED = 0
     CINT_ZERO = ConstInt(0)
     opnum = op.getopnum()
     if rop.is_getarrayitem(opnum) or \
        opnum in (rop.GETARRAYITEM_RAW_I,
                  rop.GETARRAYITEM_RAW_F):
         self.handle_getarrayitem(op)
     elif opnum in (rop.SETARRAYITEM_GC, rop.SETARRAYITEM_RAW):
         self.handle_setarrayitem(op)
     elif opnum == rop.RAW_STORE:
         itemsize, ofs, _ = unpack_arraydescr(op.getdescr())
         ptr_box = op.getarg(0)
         index_box = op.getarg(1)
         value_box = op.getarg(2)
         self.emit_gc_store_or_indexed(op, ptr_box, index_box, value_box,
                                       itemsize, 1, ofs)
     elif opnum in (rop.RAW_LOAD_I, rop.RAW_LOAD_F):
         itemsize, ofs, sign = unpack_arraydescr(op.getdescr())
         ptr_box = op.getarg(0)
         index_box = op.getarg(1)
         self.emit_gc_load_or_indexed(op, ptr_box, index_box, itemsize, 1,
                                      ofs, sign)
     elif opnum in (rop.GETINTERIORFIELD_GC_I, rop.GETINTERIORFIELD_GC_R,
                    rop.GETINTERIORFIELD_GC_F):
         ofs, itemsize, fieldsize, sign = unpack_interiorfielddescr(
             op.getdescr())
         ptr_box = op.getarg(0)
         index_box = op.getarg(1)
         self.emit_gc_load_or_indexed(op, ptr_box, index_box, fieldsize,
                                      itemsize, ofs, sign)
     elif opnum in (rop.SETINTERIORFIELD_RAW, rop.SETINTERIORFIELD_GC):
         ofs, itemsize, fieldsize, sign = unpack_interiorfielddescr(
             op.getdescr())
         ptr_box = op.getarg(0)
         index_box = op.getarg(1)
         value_box = op.getarg(2)
         self.emit_gc_store_or_indexed(op, ptr_box, index_box, value_box,
                                       fieldsize, itemsize, ofs)
     elif opnum in (rop.GETFIELD_GC_I, rop.GETFIELD_GC_F, rop.GETFIELD_GC_R,
                    rop.GETFIELD_RAW_I, rop.GETFIELD_RAW_F,
                    rop.GETFIELD_RAW_R):
         ofs, itemsize, sign = unpack_fielddescr(op.getdescr())
         ptr_box = op.getarg(0)
         if op.getopnum() in (rop.GETFIELD_GC_F, rop.GETFIELD_GC_I,
                              rop.GETFIELD_GC_R):
             # See test_zero_ptr_field_before_getfield().  We hope there is
             # no getfield_gc in the middle of initialization code, but there
             # shouldn't be, given that a 'new' is already delayed by previous
             # optimization steps.  In practice it should immediately be
             # followed by a bunch of 'setfields', and the 'pending_zeros'
             # optimization we do here is meant for this case.
             self.emit_pending_zeros()
             self.emit_gc_load_or_indexed(op, ptr_box, ConstInt(0),
                                          itemsize, 1, ofs, sign)
             self.emit_op(op)
             return True
         self.emit_gc_load_or_indexed(op, ptr_box, ConstInt(0), itemsize, 1,
                                      ofs, sign)
     elif opnum in (rop.SETFIELD_GC, rop.SETFIELD_RAW):
         ofs, itemsize, sign = unpack_fielddescr(op.getdescr())
         ptr_box = op.getarg(0)
         value_box = op.getarg(1)
         self.emit_gc_store_or_indexed(op, ptr_box, ConstInt(0), value_box,
                                       itemsize, 1, ofs)
     elif opnum == rop.ARRAYLEN_GC:
         descr = op.getdescr()
         assert isinstance(descr, ArrayDescr)
         ofs = descr.lendescr.offset
         self.emit_gc_load_or_indexed(op, op.getarg(0), ConstInt(0), WORD,
                                      1, ofs, NOT_SIGNED)
     elif opnum == rop.STRLEN:
         basesize, itemsize, ofs_length = get_array_token(
             rstr.STR, self.cpu.translate_support_code)
         self.emit_gc_load_or_indexed(op, op.getarg(0), ConstInt(0), WORD,
                                      1, ofs_length, NOT_SIGNED)
     elif opnum == rop.UNICODELEN:
         basesize, itemsize, ofs_length = get_array_token(
             rstr.UNICODE, self.cpu.translate_support_code)
         self.emit_gc_load_or_indexed(op, op.getarg(0), ConstInt(0), WORD,
                                      1, ofs_length, NOT_SIGNED)
     elif opnum == rop.STRHASH:
         offset, size = get_field_token(rstr.STR, 'hash',
                                        self.cpu.translate_support_code)
         assert size == WORD
         self.emit_gc_load_or_indexed(op,
                                      op.getarg(0),
                                      ConstInt(0),
                                      WORD,
                                      1,
                                      offset,
                                      sign=True)
     elif opnum == rop.UNICODEHASH:
         offset, size = get_field_token(rstr.UNICODE, 'hash',
                                        self.cpu.translate_support_code)
         assert size == WORD
         self.emit_gc_load_or_indexed(op,
                                      op.getarg(0),
                                      ConstInt(0),
                                      WORD,
                                      1,
                                      offset,
                                      sign=True)
     elif opnum == rop.STRGETITEM:
         basesize, itemsize, ofs_length = get_array_token(
             rstr.STR, self.cpu.translate_support_code)
         assert itemsize == 1
         basesize -= 1  # for the extra null character
         self.emit_gc_load_or_indexed(op, op.getarg(0), op.getarg(1),
                                      itemsize, itemsize, basesize,
                                      NOT_SIGNED)
     elif opnum == rop.UNICODEGETITEM:
         basesize, itemsize, ofs_length = get_array_token(
             rstr.UNICODE, self.cpu.translate_support_code)
         self.emit_gc_load_or_indexed(op, op.getarg(0), op.getarg(1),
                                      itemsize, itemsize, basesize,
                                      NOT_SIGNED)
     elif opnum == rop.STRSETITEM:
         basesize, itemsize, ofs_length = get_array_token(
             rstr.STR, self.cpu.translate_support_code)
         assert itemsize == 1
         basesize -= 1  # for the extra null character
         self.emit_gc_store_or_indexed(op, op.getarg(0), op.getarg(1),
                                       op.getarg(2), itemsize, itemsize,
                                       basesize)
     elif opnum == rop.UNICODESETITEM:
         basesize, itemsize, ofs_length = get_array_token(
             rstr.UNICODE, self.cpu.translate_support_code)
         self.emit_gc_store_or_indexed(op, op.getarg(0), op.getarg(1),
                                       op.getarg(2), itemsize, itemsize,
                                       basesize)
     return False
Beispiel #6
0
 def transform_to_gc_load(self, op):
     NOT_SIGNED = 0
     CINT_ZERO = ConstInt(0)
     opnum = op.getopnum()
     #if opnum == rop.CALL_MALLOC_NURSERY_VARSIZE:
     #    v_length = op.getarg(2)
     #    scale = op.getarg(1).getint()
     #    if scale not in self.cpu.load_supported_factors:
     #        scale, offset, v_length = \
     #                self._emit_mul_if_factor_offset_not_supported(v_length, scale, 0)
     #        op.setarg(1, ConstInt(scale))
     #        op.setarg(2, v_length)
     if rop.is_getarrayitem(opnum) or \
        opnum in (rop.GETARRAYITEM_RAW_I,
                  rop.GETARRAYITEM_RAW_F):
         self.handle_getarrayitem(op)
     elif opnum in (rop.SETARRAYITEM_GC, rop.SETARRAYITEM_RAW):
         self.handle_setarrayitem(op)
     elif opnum == rop.RAW_STORE:
         itemsize, ofs, _ = unpack_arraydescr(op.getdescr())
         ptr_box = op.getarg(0)
         index_box = op.getarg(1)
         value_box = op.getarg(2)
         self.emit_gc_store_or_indexed(op, ptr_box, index_box, value_box, itemsize, 1, ofs)
     elif opnum in (rop.RAW_LOAD_I, rop.RAW_LOAD_F):
         itemsize, ofs, sign = unpack_arraydescr(op.getdescr())
         ptr_box = op.getarg(0)
         index_box = op.getarg(1)
         self.emit_gc_load_or_indexed(op, ptr_box, index_box, itemsize, 1, ofs, sign)
     elif opnum in (rop.GETINTERIORFIELD_GC_I, rop.GETINTERIORFIELD_GC_R,
                    rop.GETINTERIORFIELD_GC_F):
         ofs, itemsize, fieldsize, sign = unpack_interiorfielddescr(op.getdescr())
         ptr_box = op.getarg(0)
         index_box = op.getarg(1)
         self.emit_gc_load_or_indexed(op, ptr_box, index_box, fieldsize, itemsize, ofs, sign)
     elif opnum in (rop.SETINTERIORFIELD_RAW, rop.SETINTERIORFIELD_GC):
         ofs, itemsize, fieldsize, sign = unpack_interiorfielddescr(op.getdescr())
         ptr_box = op.getarg(0)
         index_box = op.getarg(1)
         value_box = op.getarg(2)
         self.emit_gc_store_or_indexed(op, ptr_box, index_box, value_box,
                                       fieldsize, itemsize, ofs)
     elif opnum in (rop.GETFIELD_GC_I, rop.GETFIELD_GC_F, rop.GETFIELD_GC_R,
                    rop.GETFIELD_RAW_I, rop.GETFIELD_RAW_F, rop.GETFIELD_RAW_R):
         ofs, itemsize, sign = unpack_fielddescr(op.getdescr())
         ptr_box = op.getarg(0)
         if op.getopnum() in (rop.GETFIELD_GC_F, rop.GETFIELD_GC_I, rop.GETFIELD_GC_R):
             # See test_zero_ptr_field_before_getfield().  We hope there is
             # no getfield_gc in the middle of initialization code, but there
             # shouldn't be, given that a 'new' is already delayed by previous
             # optimization steps.  In practice it should immediately be
             # followed by a bunch of 'setfields', and the 'pending_zeros'
             # optimization we do here is meant for this case.
             self.emit_pending_zeros()
             self.emit_gc_load_or_indexed(op, ptr_box, ConstInt(0), itemsize, 1, ofs, sign)
             self.emit_op(op)
             return True
         self.emit_gc_load_or_indexed(op, ptr_box, ConstInt(0), itemsize, 1, ofs, sign)
     elif opnum in (rop.SETFIELD_GC, rop.SETFIELD_RAW):
         ofs, itemsize, sign = unpack_fielddescr(op.getdescr())
         ptr_box = op.getarg(0)
         value_box = op.getarg(1)
         self.emit_gc_store_or_indexed(op, ptr_box, ConstInt(0), value_box, itemsize, 1, ofs)
     elif opnum == rop.ARRAYLEN_GC:
         descr = op.getdescr()
         assert isinstance(descr, ArrayDescr)
         ofs = descr.lendescr.offset
         self.emit_gc_load_or_indexed(op, op.getarg(0), ConstInt(0),
                                      WORD, 1, ofs, NOT_SIGNED)
     elif opnum == rop.STRLEN:
         basesize, itemsize, ofs_length = get_array_token(rstr.STR,
                                              self.cpu.translate_support_code)
         self.emit_gc_load_or_indexed(op, op.getarg(0), ConstInt(0),
                                      WORD, 1, ofs_length, NOT_SIGNED)
     elif opnum == rop.UNICODELEN:
         basesize, itemsize, ofs_length = get_array_token(rstr.UNICODE,
                                              self.cpu.translate_support_code)
         self.emit_gc_load_or_indexed(op, op.getarg(0), ConstInt(0),
                                      WORD, 1, ofs_length, NOT_SIGNED)
     elif opnum == rop.STRGETITEM:
         basesize, itemsize, ofs_length = get_array_token(rstr.STR,
                                              self.cpu.translate_support_code)
         assert itemsize == 1
         self.emit_gc_load_or_indexed(op, op.getarg(0), op.getarg(1),
                                      itemsize, itemsize, basesize, NOT_SIGNED)
     elif opnum == rop.UNICODEGETITEM:
         basesize, itemsize, ofs_length = get_array_token(rstr.UNICODE,
                                              self.cpu.translate_support_code)
         self.emit_gc_load_or_indexed(op, op.getarg(0), op.getarg(1),
                                      itemsize, itemsize, basesize, NOT_SIGNED)
     elif opnum == rop.STRSETITEM:
         basesize, itemsize, ofs_length = get_array_token(rstr.STR,
                                              self.cpu.translate_support_code)
         assert itemsize == 1
         self.emit_gc_store_or_indexed(op, op.getarg(0), op.getarg(1), op.getarg(2),
                                      itemsize, itemsize, basesize)
     elif opnum == rop.UNICODESETITEM:
         basesize, itemsize, ofs_length = get_array_token(rstr.UNICODE,
                                              self.cpu.translate_support_code)
         self.emit_gc_store_or_indexed(op, op.getarg(0), op.getarg(1), op.getarg(2),
                                      itemsize, itemsize, basesize)
     return False