Coverage Report

Created: 2018-07-03 15:31

/home/travis/build/MoarVM/MoarVM/src/jit/label.c
Line
Count
Source (jump to first uncovered line)
1
#include "moar.h"
2
3
540k
MVMint32 MVM_jit_label_before_bb(MVMThreadContext *tc, MVMJitGraph *jg, MVMSpeshBB *bb) {
4
540k
    return bb->idx;
5
540k
}
6
7
11.1k
MVMint32 MVM_jit_label_before_graph(MVMThreadContext *tc, MVMJitGraph *jg, MVMSpeshGraph *sg) {
8
11.1k
    return 0;
9
11.1k
}
10
11
10.7k
MVMint32 MVM_jit_label_after_graph(MVMThreadContext *tc, MVMJitGraph *jg, MVMSpeshGraph *sg) {
12
10.7k
    /* Larger than all basic block labels */
13
10.7k
    return sg->num_bbs;
14
10.7k
}
15
16
17
96.1k
MVMint32 MVM_jit_label_before_ins(MVMThreadContext *tc, MVMJitGraph *jg, MVMSpeshBB *bb, MVMSpeshIns *ins) {
18
96.1k
    /* PHI nodes are always at the start of a basic block, so this not is really necessary */
19
1.26M
    while (ins->prev && ins->prev->info->opcode == MVM_SSA_PHI) {
20
1.16M
        ins = ins->prev;
21
1.16M
    }
22
96.1k
    /* Without predecessor instructions this is the same as the basic block */
23
96.1k
    if (!ins->prev) {
24
62.4k
        return MVM_jit_label_before_bb(tc, jg, bb);
25
62.4k
    }
26
96.1k
    /* Requires a separate label */
27
33.7k
    return MVM_jit_label_for_obj(tc, jg, ins);
28
96.1k
}
29
30
60.5k
MVMint32 MVM_jit_label_after_ins(MVMThreadContext *tc, MVMJitGraph *jg, MVMSpeshBB *bb, MVMSpeshIns *ins) {
31
60.5k
    /* A label after this instruction equals a label before the next */
32
60.5k
    if (ins->next) {
33
26.4k
        return MVM_jit_label_before_ins(tc, jg, bb, ins->next);
34
26.4k
    }
35
60.5k
    /* Or before the next basic block */
36
34.1k
    if (bb->linear_next) {
37
34.1k
        return MVM_jit_label_before_bb(tc, jg, bb->linear_next);
38
34.1k
    }
39
34.1k
    /* And in the edge case after the graph */
40
0
    return MVM_jit_label_after_graph(tc, jg, jg->sg);
41
34.1k
}
42
43
33.7k
MVMint32 MVM_jit_label_for_obj(MVMThreadContext *tc, MVMJitGraph *jg, void *obj) {
44
33.7k
    MVMint32 i;
45
33.7k
    /* Reverse search; it is pretty likely we've seen this ins just before */
46
33.7k
    i      = jg->obj_labels_num;
47
129k
    while (i--) {
48
108k
        if (jg->obj_labels[i] == obj) {
49
13.2k
            return i + jg->obj_label_ofs;
50
13.2k
        }
51
108k
    }
52
33.7k
    /* Add and return new instruction label */
53
20.5k
    MVM_VECTOR_PUSH(jg->obj_labels, obj);
54
20.5k
    return jg->obj_labels_num - 1 + jg->obj_label_ofs;
55
33.7k
}
56
57
0
MVMint32 MVM_jit_label_is_for_graph(MVMThreadContext *tc, MVMJitGraph *jg, MVMint32 label) {
58
0
    return label == 0 || label == jg->sg->num_bbs;
59
0
}
60
61
0
MVMint32 MVM_jit_label_is_for_bb(MVMThreadContext *tc, MVMJitGraph *jg, MVMint32 label) {
62
0
    return label > 0 && label < jg->sg->num_bbs;
63
0
}
64
65
38.5k
MVMint32 MVM_jit_label_is_for_ins(MVMThreadContext *tc, MVMJitGraph *jg, MVMint32 label) {
66
5.69k
    return label > jg->sg->num_bbs && label <= jg->sg->num_bbs + jg->obj_labels_num;
67
38.5k
}
68
69
0
MVMint32 MVM_jit_label_is_internal(MVMThreadContext *tc, MVMJitGraph *jg, MVMint32 label) {
70
0
    /* WARNING: This is *NOT VALID* during jit graph building */
71
0
    return label >= jg->num_labels;
72
0
}