-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathjit.h
76 lines (63 loc) · 2.08 KB
/
jit.h
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
/*
* rv32emu is freely redistributable under the MIT License. See the file
* "LICENSE" for information on usage and redistribution of this file.
*/
#pragma once
#include <stdint.h>
#include "riscv_private.h"
#include "utils.h"
struct jump {
uint32_t offset_loc;
uint32_t target_pc;
uint32_t target_offset;
};
struct offset_map {
uint32_t pc;
uint32_t offset;
};
struct jit_state {
set_t set;
uint8_t *buf;
uint32_t offset;
uint32_t stack_size;
uint32_t size;
uint32_t entry_loc;
uint32_t exit_loc;
uint32_t org_size; /* size of prologue and epilogue */
uint32_t retpoline_loc;
struct offset_map *offset_map;
int n_blocks;
struct jump *jumps;
int n_jumps;
};
struct host_reg {
uint8_t reg_idx : 5; /* index to the host's register file */
int8_t vm_reg_idx : 6; /* index to the vm register */
bool dirty : 1; /* whether the context of register has been overridden */
bool alive : 1; /* whether the register is no longer used in current basic
block */
};
struct jit_state *jit_state_init(size_t size);
void jit_state_exit(struct jit_state *state);
void jit_translate(riscv_t *rv, block_t *block);
typedef void (*exec_block_func_t)(riscv_t *rv, uintptr_t);
#if RV32_HAS(T2C)
void t2c_compile(riscv_t *, block_t *);
typedef void (*exec_t2c_func_t)(riscv_t *);
/* The jit-cache records the program counters and the entries of executable
* instructions generated by T2C. Like hardware cache, the old jit-cache will be
* replaced by the new one which uses the same slot.
*/
/* The size of jit-cache table should be the power of 2, thus, we can easily
* access the element by masking the program counter.
*/
#define N_JIT_CACHE_ENTRIES (1 << 12)
struct jit_cache {
uint64_t pc; /* program counter, easy to build LLVM IR with 64-bit width */
void *entry; /* entry of JIT-ed code */
};
struct jit_cache *jit_cache_init();
void jit_cache_exit(struct jit_cache *cache);
void jit_cache_update(struct jit_cache *cache, uint32_t pc, void *entry);
void jit_cache_clear(struct jit_cache *cache);
#endif