Coverage Report

Created: 2017-04-15 07:07

/home/travis/build/MoarVM/MoarVM/src/spesh/log.c
Line
Count
Source
1
#include "moar.h"
2
3
/* In order to collect more information to use during specialization, we
4
 * make a pass through the code inserting logging instructions after a
5
 * range of insturctions that obtain data we can't reason about easily
6
 * statically. After a number of logging runs, the collected data is
7
 * used as an additional "fact" source while specializing. */
8
9
92.6k
static void insert_log(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshBB *bb, MVMSpeshIns *ins, MVMint32 next_bb) {
10
92.6k
    /* Add the entry. */
11
92.6k
    MVMSpeshIns *log_ins         = MVM_spesh_alloc(tc, g, sizeof(MVMSpeshIns));
12
92.6k
    log_ins->info                = MVM_op_get_op(MVM_OP_sp_log);
13
92.6k
    log_ins->operands            = MVM_spesh_alloc(tc, g, 2 * sizeof(MVMSpeshOperand));
14
92.6k
    log_ins->operands[0].reg     = ins->operands[0].reg;
15
92.6k
    log_ins->operands[1].lit_i16 = g->num_log_slots;
16
92.6k
    if (next_bb)
17
38.0k
        MVM_spesh_manipulate_insert_ins(tc, bb->succ[0], NULL, log_ins);
18
92.6k
    else
19
54.5k
        MVM_spesh_manipulate_insert_ins(tc, bb, ins, log_ins);
20
92.6k
    g->num_log_slots++;
21
92.6k
22
92.6k
    /* Steal the de-opt annotation into the log instruction, if it exists. */
23
92.6k
    if (ins->annotations) {
24
72.8k
        MVMSpeshAnn *prev_ann = NULL;
25
72.8k
        MVMSpeshAnn *cur_ann  = ins->annotations;
26
111k
        while (cur_ann) {
27
111k
            if (cur_ann->type == MVM_SPESH_ANN_DEOPT_ONE_INS) {
28
72.8k
                if (prev_ann)
29
38.1k
                    prev_ann->next = cur_ann->next;
30
72.8k
                else
31
34.6k
                    ins->annotations = cur_ann->next;
32
72.8k
                cur_ann->next = NULL;
33
72.8k
                log_ins->annotations = cur_ann;
34
72.8k
                break;
35
72.8k
            }
36
38.2k
            prev_ann = cur_ann;
37
38.2k
            cur_ann = cur_ann->next;
38
38.2k
        }
39
72.8k
    }
40
92.6k
}
41
 
42
17.1k
void MVM_spesh_log_add_logging(MVMThreadContext *tc, MVMSpeshGraph *g, MVMint32 osr) {
43
17.1k
    MVMSpeshBB  *bb;
44
17.1k
45
17.1k
    /* We've no log slots so far. */
46
17.1k
    g->num_log_slots = 0;
47
17.1k
48
17.1k
    /* Work through the code, adding logging instructions where needed. */
49
17.1k
    bb = g->entry;
50
331k
    while (bb) {
51
314k
        MVMSpeshIns *ins = bb->first_ins;
52
2.45M
        while (ins) {
53
2.13M
            switch (ins->info->opcode) {
54
23.7k
            case MVM_OP_getlex:
55
23.7k
                if (g->sf->body.local_types[ins->operands[0].reg.orig] == MVM_reg_obj)
56
9.92k
                    insert_log(tc, g, bb, ins, 0);
57
23.7k
                break;
58
44.6k
            case MVM_OP_getlex_no:
59
44.6k
            case MVM_OP_getattr_o:
60
44.6k
            case MVM_OP_getattrs_o:
61
44.6k
            case MVM_OP_getlexstatic_o:
62
44.6k
            case MVM_OP_getlexperinvtype_o:
63
44.6k
                insert_log(tc, g, bb, ins, 0);
64
44.6k
                break;
65
38.0k
            case MVM_OP_invoke_o:
66
38.0k
                insert_log(tc, g, bb, ins, 1);
67
38.0k
                break;
68
4.03k
            case MVM_OP_osrpoint:
69
4.03k
                if (osr)
70
1.07k
                    ins->info = MVM_op_get_op(MVM_OP_sp_osrfinalize);
71
4.03k
                else
72
2.96k
                    MVM_spesh_manipulate_delete_ins(tc, g, bb, ins);
73
4.03k
                break;
74
2.13M
            }
75
2.13M
            ins = ins->next;
76
2.13M
        }
77
314k
        bb = bb->linear_next;
78
314k
    }
79
17.1k
80
17.1k
    /* Allocate space for logging storage. */
81
17.1k
    g->log_slots = g->num_log_slots
82
13.5k
        ? MVM_calloc(g->num_log_slots * MVM_SPESH_LOG_RUNS, sizeof(MVMCollectable *))
83
17.1k
        : NULL;
84
17.1k
}