Coverage Report

Created: 2018-06-21 18:56

/home/travis/build/MoarVM/MoarVM/src/jit/label.c
Line
Count
Source (jump to first uncovered line)
1
#include "moar.h"
2
3
509k
MVMint32 MVM_jit_label_before_bb(MVMThreadContext *tc, MVMJitGraph *jg, MVMSpeshBB *bb) {
4
509k
    return bb->idx;
5
509k
}
6
7
12.0k
MVMint32 MVM_jit_label_before_graph(MVMThreadContext *tc, MVMJitGraph *jg, MVMSpeshGraph *sg) {
8
12.0k
    return 0;
9
12.0k
}
10
11
11.5k
MVMint32 MVM_jit_label_after_graph(MVMThreadContext *tc, MVMJitGraph *jg, MVMSpeshGraph *sg) {
12
11.5k
    /* Larger than all basic block labels */
13
11.5k
    return sg->num_bbs;
14
11.5k
}
15
16
17
92.8k
MVMint32 MVM_jit_label_before_ins(MVMThreadContext *tc, MVMJitGraph *jg, MVMSpeshBB *bb, MVMSpeshIns *ins) {
18
92.8k
    /* PHI nodes are always at the start of a basic block, so this not is really necessary */
19
1.22M
    while (ins->prev && ins->prev->info->opcode == MVM_SSA_PHI) {
20
1.13M
        ins = ins->prev;
21
1.13M
    }
22
92.8k
    /* Without predecessor instructions this is the same as the basic block */
23
92.8k
    if (!ins->prev) {
24
61.3k
        return MVM_jit_label_before_bb(tc, jg, bb);
25
61.3k
    }
26
92.8k
    /* Requires a separate label */
27
31.5k
    return MVM_jit_label_for_obj(tc, jg, ins);
28
92.8k
}
29
30
57.1k
MVMint32 MVM_jit_label_after_ins(MVMThreadContext *tc, MVMJitGraph *jg, MVMSpeshBB *bb, MVMSpeshIns *ins) {
31
57.1k
    /* A label after this instruction equals a label before the next */
32
57.1k
    if (ins->next) {
33
24.1k
        return MVM_jit_label_before_ins(tc, jg, bb, ins->next);
34
24.1k
    }
35
57.1k
    /* Or before the next basic block */
36
33.0k
    if (bb->linear_next) {
37
33.0k
        return MVM_jit_label_before_bb(tc, jg, bb->linear_next);
38
33.0k
    }
39
33.0k
    /* And in the edge case after the graph */
40
0
    return MVM_jit_label_after_graph(tc, jg, jg->sg);
41
33.0k
}
42
43
31.5k
MVMint32 MVM_jit_label_for_obj(MVMThreadContext *tc, MVMJitGraph *jg, void *obj) {
44
31.5k
    MVMint32 i;
45
31.5k
    /* Reverse search; it is pretty likely we've seen this ins just before */
46
31.5k
    i      = jg->obj_labels_num;
47
127k
    while (i--) {
48
108k
        if (jg->obj_labels[i] == obj) {
49
12.0k
            return i + jg->obj_label_ofs;
50
12.0k
        }
51
108k
    }
52
31.5k
    /* Add and return new instruction label */
53
19.4k
    MVM_VECTOR_PUSH(jg->obj_labels, obj);
54
19.4k
    return jg->obj_labels_num - 1 + jg->obj_label_ofs;
55
31.5k
}
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
37.6k
MVMint32 MVM_jit_label_is_for_ins(MVMThreadContext *tc, MVMJitGraph *jg, MVMint32 label) {
66
5.44k
    return label > jg->sg->num_bbs && label <= jg->sg->num_bbs + jg->obj_labels_num;
67
37.6k
}
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
}