Пример #1
0
        if not funcvalue.is_constant():
            self.optimize_default(op)
            return
        resvalue = self.loop_invariant_results.get(op.args[0].getint(), None)
        if resvalue is not None:
            self.make_equal_to(op.result, resvalue)
            return
        # change the op to be a normal call, from the backend's point of view
        # there is no reason to have a separate operation for this
        op.opnum = rop.CALL
        self.optimize_default(op)
        resvalue = self.getvalue(op.result)
        self.loop_invariant_results[op.args[0].getint()] = resvalue


optimize_ops = _findall(Optimizer, 'optimize_')


class CachedArrayItems(object):
    def __init__(self):
        self.fixed_index_items = {}
        self.var_index_item = None
        self.var_index_indexvalue = None


class HeapOpOptimizer(object):
    def __init__(self, optimizer):
        self.optimizer = optimizer
        # cached fields:  {descr: {OptValue_instance: OptValue_fieldvalue}}
        self.cached_fields = {}
        # cached array items:  {descr: CachedArrayItems}
Пример #2
0
    find_nodes_GETARRAYITEM_GC_PURE = find_nodes_GETARRAYITEM_GC

    def find_nodes_JUMP(self, op):
        # only set up the 'unique' field of the InstanceNodes;
        # real handling comes later (build_result_specnodes() for loops).
        for box in op.args:
            self.getnode(box).set_unique_nodes()

    def find_nodes_FINISH(self, op):
        # only for bridges, and only for the ones that end in a 'return'
        # or 'raise'; all other cases end with a JUMP.
        for box in op.args:
            self.getnode(box).unique = UNIQUE_NO


find_nodes_ops = _findall(NodeFinder, 'find_nodes_')

# ____________________________________________________________
# Perfect specialization -- for loops only


class PerfectSpecializationFinder(NodeFinder):
    node_fromstart = InstanceNode(fromstart=True)

    def find_nodes_loop(self, loop):
        self.setup_input_nodes(loop.inputargs)
        self.find_nodes(loop.operations)
        self.build_result_specnodes(loop)

    def setup_input_nodes(self, inputargs):
        inputnodes = []
Пример #3
0
    find_nodes_GETARRAYITEM_GC_PURE = find_nodes_GETARRAYITEM_GC

    def find_nodes_JUMP(self, op):
        # only set up the 'unique' field of the InstanceNodes;
        # real handling comes later (build_result_specnodes() for loops).
        for box in op.args:
            self.getnode(box).set_unique_nodes()

    def find_nodes_FINISH(self, op):
        # only for bridges, and only for the ones that end in a 'return'
        # or 'raise'; all other cases end with a JUMP.
        for box in op.args:
            self.getnode(box).unique = UNIQUE_NO

find_nodes_ops = _findall(NodeFinder, 'find_nodes_')

# ____________________________________________________________
# Perfect specialization -- for loops only

class PerfectSpecializationFinder(NodeFinder):
    node_fromstart = InstanceNode(fromstart=True)

    def find_nodes_loop(self, loop):
        self.setup_input_nodes(loop.inputargs)
        self.find_nodes(loop.operations)
        self.build_result_specnodes(loop)

    def setup_input_nodes(self, inputargs):
        inputnodes = []
        for box in inputargs:
Пример #4
0
    def optimize_INSTANCEOF(self, op):
        value = self.getvalue(op.args[0])
        realclassbox = value.get_constant_class(self.cpu)
        if realclassbox is not None:
            checkclassbox = self.cpu.typedescr2classbox(op.descr)
            result = self.cpu.ts.subclassOf(self.cpu, realclassbox, 
                                                      checkclassbox)
            self.make_constant_int(op.result, result)
            return
        self.emit_operation(op)

    def optimize_DEBUG_MERGE_POINT(self, op):
        self.emit_operation(op)

optimize_ops = _findall(Optimizer, 'optimize_')


class CachedArrayItems(object):
    def __init__(self):
        self.fixed_index_items = {}
        self.var_index_item = None
        self.var_index_indexvalue = None


class HeapOpOptimizer(object):
    def __init__(self, optimizer):
        self.optimizer = optimizer
        # cached OptValues for each field descr
        # NOTE: it is important that this is not a av_newdict2 dict!
        # we want more precision to prevent mixing up of unrelated fields, just