예제 #1
0
 def optimize(self,
              ops,
              bridge_ops,
              expected,
              expected_loop=None,
              inline_short_preamble=True,
              jump_values=None,
              bridge_values=None):
     loop = self.parse(ops)
     info = self.unroll_and_optimize(loop, None, jump_values=jump_values)
     jitcell_token = compile.make_jitcell_token(None)
     mid_label_descr = TargetToken(jitcell_token)
     mid_label_descr.short_preamble = info.short_preamble
     mid_label_descr.virtual_state = info.virtual_state
     start_label_descr = TargetToken(jitcell_token)
     jitcell_token.target_tokens = [mid_label_descr, start_label_descr]
     loop.operations[0].setdescr(mid_label_descr)
     loop.operations[-1].setdescr(mid_label_descr)
     info.preamble.operations[0].setdescr(start_label_descr)
     guards = [op for op in loop.operations if op.is_guard()]
     assert len(guards) == 1, "more than one guard in the loop"
     bridge = self.parse(bridge_ops)
     bridge.operations[-1].setdescr(jitcell_token)
     self.add_guard_future_condition(bridge)
     trace = oparser.convert_loop_to_trace(
         bridge, FakeMetaInterpStaticData(self.cpu))
     data = compile.BridgeCompileData(
         trace,
         self.convert_values(bridge.operations[-1].getarglist(),
                             bridge_values),
         None,
         enable_opts=self.enable_opts,
         inline_short_preamble=inline_short_preamble)
     bridge_info, ops = self._do_optimize_loop(data)
     loop.check_consistency(check_descr=False)
     info.preamble.check_consistency(check_descr=False)
     bridge.operations = ([ResOperation(rop.LABEL, bridge_info.inputargs)] +
                          ops)
     bridge.inputargs = bridge_info.inputargs
     bridge.check_consistency(check_descr=False)
     expected = self.parse(expected)
     self.assert_equal(bridge,
                       convert_old_style_to_targets(expected, jump=True))
     jump_bridge = bridge.operations[-1]
     jump_d = jump_bridge.getdescr()
     jump_args = jump_bridge.getarglist()
     if loop.operations[0].getdescr() is jump_d:
         # jump to loop
         label_args = loop.operations[0].getarglist()
     else:
         assert info.preamble.operations[0].getdescr() is jump_d
         label_args = info.preamble.operations[0].getarglist()
     assert len(jump_args) == len(label_args)
     for a, b in zip(jump_args, label_args):
         assert a.type == b.type
예제 #2
0
 def optimize(self, ops, bridge_ops, expected, expected_loop=None,
              inline_short_preamble=True, jump_values=None,
              bridge_values=None):
     loop = self.parse(ops, postprocess=self.postprocess)
     self.set_values(loop.operations, jump_values)
     if expected_loop is not None:
         xxx
         exp_loop = self.parse(expected_loop, postprocess=self.postprocess)
         self.assert_equal(loop, convert_old_style_to_targets(exp_loop))
     info = self.unroll_and_optimize(loop, None)
     jitcell_token = compile.make_jitcell_token(None)
     mid_label_descr = TargetToken(jitcell_token)
     mid_label_descr.short_preamble = info.short_preamble
     mid_label_descr.virtual_state = info.virtual_state
     start_label_descr = TargetToken(jitcell_token)
     jitcell_token.target_tokens = [mid_label_descr, start_label_descr]
     loop.operations[0].setdescr(mid_label_descr)
     loop.operations[-1].setdescr(mid_label_descr)
     info.preamble.operations[0].setdescr(start_label_descr)
     guards = [op for op in loop.operations if op.is_guard()]
     assert len(guards) == 1, "more than one guard in the loop"
     bridge = self.parse(bridge_ops, postprocess=self.postprocess)
     self.set_values(bridge.operations, bridge_values)
     start_label = ResOperation(rop.LABEL, bridge.inputargs)
     bridge.operations[-1].setdescr(jitcell_token)
     self.add_guard_future_condition(bridge)
     data = compile.BridgeCompileData(start_label, bridge.operations,
                                      enable_opts=self.enable_opts,
                         inline_short_preamble=inline_short_preamble)
     bridge_info, ops = self._do_optimize_loop(data)
     loop.check_consistency(check_descr=False)
     info.preamble.check_consistency(check_descr=False)
     bridge.operations = ([ResOperation(rop.LABEL, bridge_info.inputargs)] +
                          ops)
     bridge.inputargs = bridge_info.inputargs
     bridge.check_consistency(check_descr=False)
     expected = self.parse(expected, postprocess=self.postprocess)
     self.assert_equal(bridge, convert_old_style_to_targets(expected,
                                                            jump=True))
     jump_bridge = bridge.operations[-1]
     jump_d = jump_bridge.getdescr()
     jump_args = jump_bridge.getarglist()
     if loop.operations[0].getdescr() is jump_d:
         # jump to loop
         label_args = loop.operations[0].getarglist()
     else:
         assert info.preamble.operations[0].getdescr() is jump_d
         label_args = info.preamble.operations[0].getarglist()
     assert len(jump_args) == len(label_args)
     for a, b in zip(jump_args, label_args):
         assert a.type == b.type
예제 #3
0
 def finalize_short_preamble(self, label_op, virtual_state):
     sb = self.short_preamble_producer
     self.optimizer._clean_optimization_info(sb.short_inputargs)
     short_preamble = sb.build_short_preamble()
     jitcelltoken = label_op.getdescr()
     assert isinstance(jitcelltoken, JitCellToken)
     if jitcelltoken.target_tokens is None:
         jitcelltoken.target_tokens = []
     target_token = TargetToken(jitcelltoken,
                                original_jitcell_token=jitcelltoken)
     target_token.original_jitcell_token = jitcelltoken
     target_token.virtual_state = virtual_state
     target_token.short_preamble = short_preamble
     jitcelltoken.target_tokens.append(target_token)
     self.short_preamble_producer = ExtendedShortPreambleBuilder(
         target_token, sb)
     label_op.initarglist(label_op.getarglist() + sb.used_boxes)
     return target_token
예제 #4
0
파일: unroll.py 프로젝트: cimarieta/usp
 def finalize_short_preamble(self, label_op, virtual_state):
     sb = self.short_preamble_producer
     self.optimizer._clean_optimization_info(sb.short_inputargs)
     short_preamble = sb.build_short_preamble()
     jitcelltoken = label_op.getdescr()
     assert isinstance(jitcelltoken, JitCellToken)
     if jitcelltoken.target_tokens is None:
         jitcelltoken.target_tokens = []
     target_token = TargetToken(jitcelltoken,
                                original_jitcell_token=jitcelltoken)
     target_token.original_jitcell_token = jitcelltoken
     target_token.virtual_state = virtual_state
     target_token.short_preamble = short_preamble
     jitcelltoken.target_tokens.append(target_token)
     self.short_preamble_producer = ExtendedShortPreambleBuilder(
         target_token, sb)
     label_op.initarglist(label_op.getarglist() + sb.used_boxes)
     return target_token