Coverage Report

Created: 2018-07-03 15:31

/home/travis/build/MoarVM/MoarVM/src/jit/expr.h
Line
Count
Source
1
/* Each node that yields a value has a type. This information can
2
 * probably be used by the code generator, somehow. */
3
typedef enum { /* value type */
4
     MVM_JIT_VOID,
5
     MVM_JIT_REG,
6
     MVM_JIT_FLAG,
7
     MVM_JIT_INT,
8
     MVM_JIT_NUM,
9
     MVM_JIT_PTR,
10
     MVM_JIT_C_ARGS,
11
} MVMJitExprVtype;
12
13
3.71M
#define MVM_JIT_PTR_SZ sizeof(void*)
14
1.66M
#define MVM_JIT_REG_SZ sizeof(MVMRegister)
15
#define MVM_JIT_INT_SZ sizeof(MVMint64)
16
#define MVM_JIT_NUM_SZ sizeof(MVMnum64)
17
18
19
/* Control casting behaviour for mixed-sized operands */
20
9.82M
#define MVM_JIT_NO_CAST  0
21
#define MVM_JIT_UNSIGNED 1
22
5.13k
#define MVM_JIT_SIGNED   2
23
24
25
#include "expr_ops.h"
26
27
28
enum {
29
#define MVM_JIT_OP_ENUM(name, nchild, npar, vtype, cast) MVM_JIT_##name
30
MVM_JIT_EXPR_OPS(MVM_JIT_OP_ENUM)
31
#undef MVM_JIT_OP_ENUM
32
};
33
34
typedef MVMint64 MVMJitExprNode;
35
36
struct MVMJitExprOpInfo {
37
    const char     *name;
38
    MVMint32        nchild;
39
    MVMint32        nargs;
40
    MVMJitExprVtype vtype;
41
    MVMint8         cast;
42
};
43
44
/* Tree node information for easy access and use during compilation (a
45
   symbol table entry of sorts) */
46
struct MVMJitExprNodeInfo {
47
    const MVMJitExprOpInfo *op_info;
48
    /* VM instruction represented by this node */
49
    MVMSpeshIns    *spesh_ins;
50
    /* VM 'register' type represented by this node */
51
    MVMint8          opr_type;
52
    /* Size of computed value */
53
    MVMint8         size;
54
    /* internal label for IF/WHEN/ALL/ANY etc, relative to the tree label offset */
55
    MVMint32        label;
56
};
57
58
struct MVMJitExprTree {
59
    MVMJitGraph *graph;
60
    MVM_VECTOR_DECL(MVMJitExprNode, nodes);
61
    MVM_VECTOR_DECL(MVMint32, roots);
62
    MVM_VECTOR_DECL(MVMJitExprNodeInfo, info);
63
64
    MVMint32 label_ofs;
65
    MVMint32 num_labels;
66
    MVMuint32 seq_nr;
67
};
68
69
struct MVMJitExprTemplate {
70
    const MVMJitExprNode *code;
71
    const char *info;
72
    MVMint32 len;
73
    MVMint32 root;
74
    MVMint32 flags;
75
};
76
77
#define MVM_JIT_EXPR_TEMPLATE_VALUE       0
78
578k
#define MVM_JIT_EXPR_TEMPLATE_DESTRUCTIVE 1
79
80
81
struct MVMJitTreeTraverser {
82
    void  (*preorder)(MVMThreadContext *tc, MVMJitTreeTraverser *traverser,
83
                      MVMJitExprTree *tree, MVMint32 node);
84
    void   (*inorder)(MVMThreadContext *tc, MVMJitTreeTraverser *traverser,
85
                      MVMJitExprTree *tree, MVMint32 node, MVMint32 child);
86
    void (*postorder)(MVMThreadContext *tc, MVMJitTreeTraverser *traverser,
87
                      MVMJitExprTree *tree, MVMint32 node);
88
    void       *data;
89
90
    MVM_VECTOR_DECL(MVMint32, visits);
91
    enum {
92
        MVM_JIT_TRAVERSER_REPEAT,
93
        MVM_JIT_TRAVERSER_ONCE
94
    } policy;
95
96
};
97
98
99
const MVMJitExprOpInfo * MVM_jit_expr_op_info(MVMThreadContext *tc, MVMint32 op);
100
/* properties of expression ops */
101
MVMint32 MVM_jit_expr_op_negate_flag(MVMThreadContext *tc, MVMint32 op);
102
MVMint32 MVM_jit_expr_op_is_binary_noncommutative(MVMThreadContext *tc, MVMint32 op);
103
104
MVMJitExprTree * MVM_jit_expr_tree_build(MVMThreadContext *tc, MVMJitGraph *jg, MVMSpeshIterator *iter);
105
void MVM_jit_expr_tree_traverse(MVMThreadContext *tc, MVMJitExprTree *tree, MVMJitTreeTraverser *traverser);
106
void MVM_jit_expr_tree_destroy(MVMThreadContext *tc, MVMJitExprTree *tree);
107
MVMint32 MVM_jit_expr_tree_get_nodes(MVMThreadContext *tc, MVMJitExprTree *tree,
108
                                     MVMint32 node, const char *path, MVMJitExprNode *buffer);