/home/travis/build/MoarVM/MoarVM/src/jit/internal.h
Line | Count | Source |
1 | | /* Internal header for the MoarVM JIT compiler. Probably best not to use it |
2 | | * outside the JIT */ |
3 | | |
4 | | /* Override dynasm state definitions, so that we can use our own compiler |
5 | | * with register allocation structures etc. */ |
6 | | #define Dst_DECL MVMJitCompiler *compiler |
7 | 9.45M | #define Dst_REF (compiler->dasm_handle) |
8 | 8.78M | #define Dst (compiler) |
9 | | #include "dasm_proto.h" |
10 | | |
11 | 10.7k | #define MVM_JIT_MAX_GLOBALS 1 |
12 | | |
13 | | struct MVMJitCompiler { |
14 | | dasm_State *dasm_handle; |
15 | | MVMJitGraph *graph; |
16 | | |
17 | | MVMint32 label_offset; |
18 | | MVMint32 label_max; |
19 | | |
20 | | /* For spilling values that don't fit into the register allocator */ |
21 | | MVMint32 spills_base; |
22 | | MVMint32 spills_free[4]; |
23 | | MVM_VECTOR_DECL(struct { MVMint8 reg_type; MVMint32 next; }, spills); |
24 | | |
25 | | void *dasm_globals[MVM_JIT_MAX_GLOBALS]; |
26 | | }; |
27 | | |
28 | | /* Declarations for architecture-specific codegen stuff */ |
29 | | const MVMint32 MVM_jit_support(void); |
30 | | const unsigned char * MVM_jit_actions(void); |
31 | | void MVM_jit_emit_prologue(MVMThreadContext *tc, MVMJitCompiler *compiler, MVMJitGraph *jg); |
32 | | void MVM_jit_emit_epilogue(MVMThreadContext *tc, MVMJitCompiler *compiler, MVMJitGraph *jg); |
33 | | void MVM_jit_emit_primitive(MVMThreadContext *tc, MVMJitCompiler *compiler, |
34 | | MVMJitGraph *jg, MVMJitPrimitive *prim); |
35 | | void MVM_jit_emit_call_c(MVMThreadContext *tc, MVMJitCompiler *compiler, MVMJitGraph *jg, |
36 | | MVMJitCallC *call_spec); |
37 | | void MVM_jit_emit_branch(MVMThreadContext *tc, MVMJitCompiler *compiler, MVMint32 label); |
38 | | void MVM_jit_emit_conditional_branch(MVMThreadContext *tc, MVMJitCompiler *compiler, |
39 | | MVMint32 cond, MVMint32 label); |
40 | | void MVM_jit_emit_block_branch(MVMThreadContext *tc, MVMJitCompiler *compiler, MVMJitGraph *jg, |
41 | | MVMJitBranch *branch_spec); |
42 | | void MVM_jit_emit_label(MVMThreadContext *tc, MVMJitCompiler *compiler, MVMJitGraph *jg, |
43 | | MVMint32 label); |
44 | | void MVM_jit_emit_guard(MVMThreadContext *tc, MVMJitCompiler *compiler, MVMJitGraph *jg, |
45 | | MVMJitGuard *guard); |
46 | | void MVM_jit_emit_invoke(MVMThreadContext *tc, MVMJitCompiler *compiler, MVMJitGraph *jg, |
47 | | MVMJitInvoke *invoke); |
48 | | void MVM_jit_emit_jumplist(MVMThreadContext *tc, MVMJitCompiler *compiler, MVMJitGraph *jg, |
49 | | MVMJitJumpList *jumplist); |
50 | | void MVM_jit_emit_control(MVMThreadContext *tc, MVMJitCompiler *compiler, |
51 | | MVMJitControl *ctrl, MVMJitTile *tile); |
52 | | void MVM_jit_emit_data(MVMThreadContext *tc, MVMJitCompiler *compiler, MVMJitData *data); |
53 | | |
54 | | void MVM_jit_emit_load(MVMThreadContext *tc, MVMJitCompiler *compiler, |
55 | | MVMint32 reg_cls, MVMint8 reg_dst, |
56 | | MVMint32 mem_cls, MVMint32 mem_src, MVMint32 size); |
57 | | void MVM_jit_emit_store(MVMThreadContext *tc, MVMJitCompiler *compiler, |
58 | | MVMint32 mem_cls, MVMint32 mem_pos, |
59 | | MVMint32 reg_cls, MVMint8 reg_pos, MVMint32 size); |
60 | | void MVM_jit_emit_copy(MVMThreadContext *tc, MVMJitCompiler *compiler, |
61 | | MVMint32 dst_cls, MVMint8 dst_reg, MVMint32 src_cls, MVMint8 src_num); |
62 | | void MVM_jit_emit_marker(MVMThreadContext *tc, MVMJitCompiler *compiler, MVMint32 num); |
63 | | |
64 | | MVMint32 MVM_jit_spill_memory_select(MVMThreadContext *tc, MVMJitCompiler *compiler, MVMint8 reg_type); |
65 | | void MVM_jit_spill_memory_release(MVMThreadContext *tc, MVMJitCompiler *compiler, MVMint32 pos, MVMint8 reg_type); |
66 | | |
67 | | |
68 | | |
69 | | |
70 | | /* Although we use these only symbolically, we need to assign a temporary value |
71 | | * in order to to distinguish between them */ |
72 | | #define MVM_JIT_ARCH_X64 1 |
73 | | #define MVM_JIT_PLATFORM_POSIX 1 |
74 | | #define MVM_JIT_PLATFORM_WIN32 2 |
75 | | |
76 | | #if MVM_JIT_ARCH == MVM_JIT_ARCH_X64 |
77 | | #define MVM_JIT_ARCH_H "jit/x64/arch.h" |
78 | | #endif |
79 | | |
80 | | /* Depends on values of MVM_JIT_PLATFORM, so need to be defined, but uses the |
81 | | * MVM_JIT_ARCH names literally, so these need to be undefined. */ |
82 | | #ifdef MVM_JIT_ARCH_H |
83 | | #include MVM_JIT_ARCH_H |
84 | | #endif |
85 | | |
86 | | |
87 | | #undef MVM_JIT_ARCH_X64 |
88 | | #undef MVM_JIT_PLATFORM_POSIX |
89 | | #undef MVM_JIT_PLATFORM_WIN32 |
90 | | |
91 | | /* declare comma (register name separater) to be literal ',', which makes the |
92 | | * enum declaration work */ |
93 | | #ifdef __COMMA__ |
94 | | #error "Defining __COMMA__ cannot end well" |
95 | | #endif |
96 | | |
97 | | #define __COMMA__ , |
98 | | enum { |
99 | | MVM_JIT_ARCH_GPR(MVM_JIT_REG) |
100 | | }; |
101 | | enum { |
102 | | MVM_JIT_ARCH_NUM(MVM_JIT_REG) |
103 | | }; |
104 | | /* it's a ridiculous, dangerous macro and it shouldn't escape */ |
105 | | #undef __COMMA__ |
106 | | |
107 | | /* We need max and min macros, they used to be in libtommath, but aren't anymore */ |
108 | | #ifndef MAX |
109 | 9.29M | #define MAX(a,b) ((a) > (b) ? (a) : (b)) |
110 | | #endif |
111 | | |
112 | | #ifndef MIN |
113 | 11.4M | #define MIN(a,b) ((a) < (b) ? (a) : (b)) |
114 | | #endif |
115 | | |
116 | 14.6M | #define MVM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) |