summaryrefslogtreecommitdiffstats
path: root/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_compiler.h
blob: 9a49cffdd1a7f4354071b0a7fcb525307b81cca0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
 * Copyright (C) 2021 Intel Corporation.  All rights reserved.
 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 */

#ifndef _JIT_COMPILER_H_
#define _JIT_COMPILER_H_

#include "bh_platform.h"
#include "../interpreter/wasm_runtime.h"
#include "jit_ir.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct JitGlobals {
    /* Compiler pass sequence, the last element must be 0 */
    const uint8 *passes;
    char *return_to_interp_from_jitted;
#if WASM_ENABLE_LAZY_JIT != 0
    char *compile_fast_jit_and_then_call;
#endif
} JitGlobals;

/**
 * Actions the interpreter should do when jitted code returns to
 * interpreter.
 */
typedef enum JitInterpAction {
    JIT_INTERP_ACTION_NORMAL, /* normal execution */
    JIT_INTERP_ACTION_THROWN, /* exception was thrown */
    JIT_INTERP_ACTION_CALL    /* call wasm function */
} JitInterpAction;

/**
 * Information exchanged between jitted code and interpreter.
 */
typedef struct JitInterpSwitchInfo {
    /* Points to the frame that is passed to jitted code and the frame
       that is returned from jitted code */
    void *frame;

    /* Output values from jitted code of different actions */
    union {
        /* IP and SP offsets for NORMAL */
        struct {
            int32 ip;
            int32 sp;
        } normal;

        /* Function called from jitted code for CALL */
        struct {
            void *function;
        } call;

        /* Returned integer and/or floating point values for RETURN. This
           is also used to pass return values from interpreter to jitted
           code if the caller is in jitted code and the callee is in
           interpreter. */
        struct {
            uint32 ival[2];
            uint32 fval[2];
            uint32 last_return_type;
        } ret;
    } out;
} JitInterpSwitchInfo;

/* Jit compiler options */
typedef struct JitCompOptions {
    uint32 code_cache_size;
    uint32 opt_level;
} JitCompOptions;

bool
jit_compiler_init(const JitCompOptions *option);

void
jit_compiler_destroy();

JitGlobals *
jit_compiler_get_jit_globals();

const char *
jit_compiler_get_pass_name(unsigned i);

bool
jit_compiler_compile(WASMModule *module, uint32 func_idx);

bool
jit_compiler_compile_all(WASMModule *module);

bool
jit_compiler_is_compiled(const WASMModule *module, uint32 func_idx);

#if WASM_ENABLE_LAZY_JIT != 0 && WASM_ENABLE_JIT != 0
bool
jit_compiler_set_call_to_llvm_jit(WASMModule *module, uint32 func_idx);

bool
jit_compiler_set_call_to_fast_jit(WASMModule *module, uint32 func_idx);

void
jit_compiler_set_llvm_jit_func_ptr(WASMModule *module, uint32 func_idx,
                                   void *func_ptr);
#endif

int
jit_interp_switch_to_jitted(void *self, JitInterpSwitchInfo *info,
                            uint32 func_idx, void *pc);

/*
 * Pass declarations:
 */

/**
 * Dump the compilation context.
 */
bool
jit_pass_dump(JitCompContext *cc);

/**
 * Update CFG (usually before dump for better readability).
 */
bool
jit_pass_update_cfg(JitCompContext *cc);

/**
 * Translate profiling result into MIR.
 */
bool
jit_pass_frontend(JitCompContext *cc);

/**
 * Lower unsupported operations into supported ones.
 */
bool
jit_pass_lower_cg(JitCompContext *cc);

/**
 * Register allocation.
 */
bool
jit_pass_regalloc(JitCompContext *cc);

/**
 * Native code generation.
 */
bool
jit_pass_codegen(JitCompContext *cc);

/**
 * Register the jitted code so that it can be executed.
 */
bool
jit_pass_register_jitted_code(JitCompContext *cc);

#ifdef __cplusplus
}
#endif

#endif /* end of _JIT_COMPILER_H_ */