Exemple #1
0
 def inputarg_for_var(self, elem):
     try:
         return self._cache[elem]
     except KeyError:
         pass
     if elem[0] in 'ifrpv':
         box = OpHelpers.inputarg_from_tp(elem[0])
         number = elem[1:]
         if elem.startswith('v'):
             pattern = re.compile('.*\[(\d+)x(i|f)(\d+)\]')
             match = pattern.match(elem)
             if match:
                 box.datatype = match.group(2)[0]
                 box.bytesize = int(match.group(3)) // 8
                 box.count = int(match.group(1))
                 box.signed == item_type == 'i'
                 number = elem[1:elem.find('[')]
     else:
         number = elem[1:]
         for prefix, boxclass in self.boxkinds.iteritems():
             if elem.startswith(prefix):
                 box = boxclass()
                 break
         else:
             raise ParseError("Unknown variable type: %s" % elem)
     self._cache[elem] = box
     box._str = elem
     return box
 def propagate_all_forward(self, inputargs, ops, call_pure_results=None,
                           rename_inputargs=True, flush=True):
     if rename_inputargs:
         newargs = []
         for inparg in inputargs:
             new_arg = OpHelpers.inputarg_from_tp(inparg.type)
             inparg.set_forwarded(new_arg)
             newargs.append(new_arg)
         self.init_inparg_dict_from(newargs)
     else:
         newargs = inputargs
     self.call_pure_results = call_pure_results
     if ops[-1].getopnum() in (rop.FINISH, rop.JUMP):
         last = len(ops) - 1
         extra_jump = True
     else:
         extra_jump = False
         last = len(ops)
     for i in range(last):
         self._really_emitted_operation = None
         self.first_optimization.propagate_forward(ops[i])
     # accumulate counters
     if flush:
         self.flush()
     if extra_jump:
         self.first_optimization.propagate_forward(ops[-1])
     self.resumedata_memo.update_counters(self.metainterp_sd.profiler)
     
     return (BasicLoopInfo(newargs, self.quasi_immutable_deps),
             self._newoperations)
Exemple #3
0
 def inputarg_for_var(self, elem):
     try:
         return self._cache[elem]
     except KeyError:
         pass
     if elem[0] in 'ifrpv':
         box = OpHelpers.inputarg_from_tp(elem[0])
         number = elem[1:]
         if elem.startswith('v'):
             pattern = re.compile('.*\[(\d+)x(i|f)(\d+)\]')
             match = pattern.match(elem)
             if match:
                 box.datatype = match.group(2)[0]
                 box.bytesize = int(match.group(3)) // 8
                 box.count = int(match.group(1))
                 box.signed == item_type == 'i'
                 number = elem[1:elem.find('[')]
     else:
         number = elem[1:]
         for prefix, boxclass in self.boxkinds.iteritems():
             if elem.startswith(prefix):
                 box = boxclass()
                 break
         else:
             raise ParseError("Unknown variable type: %s" % elem)
     self._cache[elem] = box
     box._str = elem
     return box
Exemple #4
0
 def create_short_inputargs(self, label_args):
     return self.short_inputargs
     short_inpargs = []
     for i in range(len(label_args)):
         inparg = self.produced_short_boxes.get(label_args[i], None)
         if inparg is None:
             renamed = OpHelpers.inputarg_from_tp(label_args[i].type)
             short_inpargs.append(renamed)
         else:
             assert isinstance(inparg.short_op, ShortInputArg)
             short_inpargs.append(inparg.preamble_op)
     return short_inpargs
Exemple #5
0
 def create_short_inputargs(self, label_args):
     return self.short_inputargs
     short_inpargs = []
     for i in range(len(label_args)):
         inparg = self.produced_short_boxes.get(label_args[i], None)
         if inparg is None:
             renamed = OpHelpers.inputarg_from_tp(label_args[i].type)
             short_inpargs.append(renamed)
         else:
             assert isinstance(inparg.short_op, ShortInputArg)
             short_inpargs.append(inparg.preamble_op)
     return short_inpargs
Exemple #6
0
    def create_short_boxes(self, optimizer, inputargs, label_args):
        # all the potential operations that can be produced, subclasses
        # of AbstractShortOp
        self.potential_ops = OrderedDict()
        self.produced_short_boxes = {}
        # a way to produce const boxes, e.g. setfield_gc(p0, Const).
        # We need to remember those, but they don't produce any new boxes
        self.const_short_boxes = []
        self.short_inputargs = []
        for i in range(len(label_args)):
            box = label_args[i]
            renamed = OpHelpers.inputarg_from_tp(box.type)
            self.short_inputargs.append(renamed)
            self.potential_ops[box] = ShortInputArg(box, renamed)

        optimizer.produce_potential_short_preamble_ops(self)

        short_boxes = []
        self.boxes_in_production = {}

        for shortop in self.potential_ops.values():
            self.add_op_to_short(shortop)
        #
        for op, produced_op in self.produced_short_boxes.iteritems():
            short_boxes.append(produced_op)

        for short_op in self.const_short_boxes:
            getfield_op = short_op.getfield_op
            args = getfield_op.getarglist()
            preamble_arg = self.produce_arg(args[0])
            if preamble_arg is not None:
                preamble_op = getfield_op.copy_and_change(
                      getfield_op.getopnum(), [preamble_arg] + args[1:])
                produced_op = ProducedShortOp(short_op, preamble_op)
                short_boxes.append(produced_op)
        return short_boxes
Exemple #7
0
    def create_short_boxes(self, optimizer, inputargs, label_args):
        # all the potential operations that can be produced, subclasses
        # of AbstractShortOp
        self.potential_ops = OrderedDict()
        self.produced_short_boxes = {}
        # a way to produce const boxes, e.g. setfield_gc(p0, Const).
        # We need to remember those, but they don't produce any new boxes
        self.const_short_boxes = []
        self.short_inputargs = []
        for i in range(len(label_args)):
            box = label_args[i]
            renamed = OpHelpers.inputarg_from_tp(box.type)
            self.short_inputargs.append(renamed)
            self.potential_ops[box] = ShortInputArg(box, renamed)

        optimizer.produce_potential_short_preamble_ops(self)

        short_boxes = []
        self.boxes_in_production = {}

        for shortop in self.potential_ops.values():
            self.add_op_to_short(shortop)
        #
        for op, produced_op in self.produced_short_boxes.iteritems():
            short_boxes.append(produced_op)

        for short_op in self.const_short_boxes:
            getfield_op = short_op.getfield_op
            args = getfield_op.getarglist()
            preamble_arg = self.produce_arg(args[0])
            if preamble_arg is not None:
                preamble_op = getfield_op.copy_and_change(
                    getfield_op.getopnum(), [preamble_arg] + args[1:])
                produced_op = ProducedShortOp(short_op, preamble_op)
                short_boxes.append(produced_op)
        return short_boxes