Exemple #1
0
def compile_retrace(metainterp, greenkey, start, inputargs, jumpargs,
                    partial_trace, resumekey, start_state):
    """Try to compile a new procedure by closing the current history back
    to the first operation.
    """
    trace = metainterp.history.trace.cut_trace_from(start, inputargs)
    metainterp_sd = metainterp.staticdata
    jitdriver_sd = metainterp.jitdriver_sd
    history = metainterp.history
    #
    metainterp_sd.jitlog.start_new_trace(metainterp_sd,
                                         faildescr=resumekey,
                                         entry_bridge=False)
    #
    loop_jitcell_token = metainterp.get_procedure_token(greenkey)
    assert loop_jitcell_token

    cut = history.get_trace_position()
    history.record(rop.JUMP, jumpargs[:], None, descr=loop_jitcell_token)
    enable_opts = jitdriver_sd.warmstate.enable_opts
    call_pure_results = metainterp.call_pure_results
    loop_data = UnrolledLoopData(trace,
                                 loop_jitcell_token,
                                 start_state,
                                 call_pure_results=call_pure_results,
                                 enable_opts=enable_opts)
    try:
        loop_info, loop_ops = loop_data.optimize_trace(
            metainterp_sd, jitdriver_sd, metainterp.box_names_memo)
    except InvalidLoop:
        metainterp_sd.jitlog.trace_aborted()
        history.cut(cut)
        return None

    label_op = loop_info.label_op
    label_token = label_op.getdescr()
    assert isinstance(label_token, TargetToken)
    if label_token.short_preamble:
        metainterp_sd.logger_ops.log_short_preamble([],
                                                    label_token.short_preamble,
                                                    metainterp.box_names_memo)
    loop = partial_trace
    loop.original_jitcell_token = loop_jitcell_token
    loop.operations = (loop.operations + loop_info.extra_same_as + [label_op] +
                       loop_ops)

    quasi_immutable_deps = {}
    if loop_info.quasi_immutable_deps:
        quasi_immutable_deps.update(loop_info.quasi_immutable_deps)
    if start_state.quasi_immutable_deps:
        quasi_immutable_deps.update(start_state.quasi_immutable_deps)
    if quasi_immutable_deps:
        loop.quasi_immutable_deps = quasi_immutable_deps

    target_token = loop.operations[-1].getdescr()
    resumekey.compile_and_attach(metainterp, loop, inputargs)
    return target_token
Exemple #2
0
def compile_retrace(metainterp, greenkey, start,
                    inputargs, jumpargs,
                    partial_trace, resumekey, start_state):
    """Try to compile a new procedure by closing the current history back
    to the first operation.
    """
    from rpython.jit.metainterp.optimizeopt import optimize_trace

    trace = metainterp.history.trace.cut_trace_from(start, inputargs)
    metainterp_sd = metainterp.staticdata
    jitdriver_sd = metainterp.jitdriver_sd
    history = metainterp.history

    loop_jitcell_token = metainterp.get_procedure_token(greenkey)
    assert loop_jitcell_token

    cut = history.get_trace_position()
    history.record(rop.JUMP, jumpargs[:], None, descr=loop_jitcell_token)
    enable_opts = jitdriver_sd.warmstate.enable_opts
    call_pure_results = metainterp.call_pure_results
    loop_data = UnrolledLoopData(trace, loop_jitcell_token, start_state,
                                 call_pure_results=call_pure_results,
                                 enable_opts=enable_opts)
    try:
        loop_info, loop_ops = optimize_trace(metainterp_sd, jitdriver_sd,
                                             loop_data,
                                             metainterp.box_names_memo)
    except InvalidLoop:
        # Fall back on jumping directly to preamble
        history.cut(cut)
        history.record(rop.JUMP, jumpargs[:], None, descr=loop_jitcell_token)
        loop_data = UnrolledLoopData(trace, loop_jitcell_token, start_state,
                                     call_pure_results=call_pure_results,
                                     enable_opts=enable_opts,
                                     inline_short_preamble=False)
        try:
            loop_info, loop_ops = optimize_trace(metainterp_sd, jitdriver_sd,
                                                 loop_data,
                                                 metainterp.box_names_memo)
        except InvalidLoop:
            history.cut(cut)
            return None

    label_op = loop_info.label_op
    if label_op is None:
        assert False, "unreachable code" # hint for some strange tests
    label_token = label_op.getdescr()
    assert isinstance(label_token, TargetToken)
    if label_token.short_preamble:
        metainterp_sd.logger_ops.log_short_preamble([],
            label_token.short_preamble, metainterp.box_names_memo)
    loop = partial_trace
    loop.original_jitcell_token = loop_jitcell_token
    loop.operations = (loop.operations + loop_info.extra_same_as +
                       [loop_info.label_op]
                       + loop_ops)

    quasi_immutable_deps = {}
    if loop_info.quasi_immutable_deps:
        quasi_immutable_deps.update(loop_info.quasi_immutable_deps)
    if start_state.quasi_immutable_deps:
        quasi_immutable_deps.update(start_state.quasi_immutable_deps)
    if quasi_immutable_deps:
        loop.quasi_immutable_deps = quasi_immutable_deps

    target_token = loop.operations[-1].getdescr()
    resumekey.compile_and_attach(metainterp, loop, inputargs)

    record_loop_or_bridge(metainterp_sd, loop)
    return target_token
Exemple #3
0
def compile_loop(metainterp, greenkey, start, inputargs, jumpargs,
                 full_preamble_needed=True, try_disabling_unroll=False):
    """Try to compile a new procedure by closing the current history back
    to the first operation.
    """
    from rpython.jit.metainterp.optimizeopt import optimize_trace

    metainterp_sd = metainterp.staticdata
    jitdriver_sd = metainterp.jitdriver_sd
    history = metainterp.history
    trace = history.trace
    warmstate = jitdriver_sd.warmstate

    enable_opts = jitdriver_sd.warmstate.enable_opts
    if try_disabling_unroll:
        if 'unroll' not in enable_opts:
            return None
        enable_opts = enable_opts.copy()
        del enable_opts['unroll']

    jitcell_token = make_jitcell_token(jitdriver_sd)
    cut_at = history.get_trace_position()
    history.record(rop.JUMP, jumpargs, None, descr=jitcell_token)
    if start != (0, 0, 0):
        trace = trace.cut_trace_from(start, inputargs)
    if 'unroll' not in enable_opts or not metainterp.cpu.supports_guard_gc_type:
        return compile_simple_loop(metainterp, greenkey, trace, jumpargs,
                                   enable_opts, cut_at)
    call_pure_results = metainterp.call_pure_results
    preamble_data = LoopCompileData(trace, jumpargs,
                                    call_pure_results=call_pure_results,
                                    enable_opts=enable_opts)
    try:
        start_state, preamble_ops = optimize_trace(metainterp_sd, jitdriver_sd,
                                                   preamble_data,
                                                   metainterp.box_names_memo)
    except InvalidLoop:
        history.cut(cut_at)
        return None

    metainterp_sd = metainterp.staticdata
    jitdriver_sd = metainterp.jitdriver_sd
    start_descr = TargetToken(jitcell_token,
                              original_jitcell_token=jitcell_token)
    jitcell_token.target_tokens = [start_descr]
    loop_data = UnrolledLoopData(trace, jitcell_token, start_state,
                                 call_pure_results=call_pure_results,
                                 enable_opts=enable_opts)
    try:
        loop_info, loop_ops = optimize_trace(metainterp_sd, jitdriver_sd,
                                             loop_data,
                                             metainterp.box_names_memo)
    except InvalidLoop:
        history.cut(cut_at)
        return None

    if ((warmstate.vec and jitdriver_sd.vec) or warmstate.vec_all):
        from rpython.jit.metainterp.optimizeopt.vector import optimize_vector
        loop_info, loop_ops = optimize_vector(trace, metainterp_sd,
                                              jitdriver_sd, warmstate,
                                              loop_info, loop_ops,
                                              jitcell_token)
    #
    loop = create_empty_loop(metainterp)
    loop.original_jitcell_token = jitcell_token
    loop.inputargs = start_state.renamed_inputargs
    quasi_immutable_deps = {}
    if start_state.quasi_immutable_deps:
        quasi_immutable_deps.update(start_state.quasi_immutable_deps)
    if loop_info.quasi_immutable_deps:
        quasi_immutable_deps.update(loop_info.quasi_immutable_deps)
    if quasi_immutable_deps:
        loop.quasi_immutable_deps = quasi_immutable_deps
    start_label = ResOperation(rop.LABEL, start_state.renamed_inputargs,
                               descr=start_descr)
    label_token = loop_info.label_op.getdescr()
    assert isinstance(label_token, TargetToken)
    if label_token.short_preamble:
        metainterp_sd.logger_ops.log_short_preamble([],
            label_token.short_preamble, metainterp.box_names_memo)
    loop.operations = ([start_label] + preamble_ops + loop_info.extra_same_as +
                       [loop_info.label_op] + loop_ops)
    if not we_are_translated():
        loop.check_consistency()
    send_loop_to_backend(greenkey, jitdriver_sd, metainterp_sd, loop, "loop",
                         inputargs, metainterp.box_names_memo)
    record_loop_or_bridge(metainterp_sd, loop)
    loop_info.post_loop_compilation(loop, jitdriver_sd, metainterp, jitcell_token)
    return start_descr