Commit | Line | Data |
---|---|---|
98fa08a5 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
d16005f8 | 2 | /* |
98fa08a5 | 3 | * Copyright (C) 2014-2021 Paul Cercueil <paul@crapouillou.net> |
d16005f8 PC |
4 | */ |
5 | ||
6 | #ifndef __REGCACHE_H__ | |
7 | #define __REGCACHE_H__ | |
8 | ||
ba3814c1 | 9 | #include "lightning-wrapper.h" |
d16005f8 | 10 | |
ba3814c1 | 11 | #define NUM_REGS (JIT_V_NUM - 1) |
d16005f8 | 12 | #define LIGHTREC_REG_STATE (JIT_V(JIT_V_NUM - 1)) |
ba3814c1 PC |
13 | |
14 | #if defined(__powerpc__) | |
15 | # define NUM_TEMPS JIT_R_NUM | |
16 | /* JIT_R0 is callee-saved on PowerPC, we have to use something else */ | |
17 | # define LIGHTREC_REG_CYCLE _R10 | |
18 | # define FIRST_TEMP 0 | |
19 | #else | |
20 | # define NUM_TEMPS (JIT_R_NUM - 1) | |
21 | # define LIGHTREC_REG_CYCLE JIT_R0 | |
22 | # define FIRST_TEMP 1 | |
23 | #endif | |
24 | ||
25 | #include "lightrec-private.h" | |
26 | ||
27 | #define FIRST_REG 0 | |
d16005f8 | 28 | |
98fa08a5 PC |
29 | /* Flags for lightrec_alloc_reg_in / lightrec_alloc_reg_out. */ |
30 | #define REG_EXT BIT(0) /* register is sign-extended */ | |
31 | #define REG_ZEXT BIT(1) /* register is zero-extended */ | |
d16005f8 PC |
32 | |
33 | struct register_value { | |
34 | _Bool known; | |
35 | u32 value; | |
36 | }; | |
37 | ||
38 | struct native_register; | |
39 | struct regcache; | |
40 | ||
41 | u8 lightrec_alloc_reg(struct regcache *cache, jit_state_t *_jit, u8 jit_reg); | |
42 | u8 lightrec_alloc_reg_temp(struct regcache *cache, jit_state_t *_jit); | |
98fa08a5 | 43 | u8 lightrec_alloc_reg_out(struct regcache *cache, jit_state_t *_jit, |
9259d748 | 44 | u16 reg, u8 flags); |
98fa08a5 | 45 | u8 lightrec_alloc_reg_in(struct regcache *cache, jit_state_t *_jit, |
9259d748 | 46 | u16 reg, u8 flags); |
d16005f8 | 47 | |
9259d748 PC |
48 | void lightrec_load_imm(struct regcache *cache, |
49 | jit_state_t *_jit, u8 jit_reg, u32 pc, u32 imm); | |
50 | void lightrec_load_next_pc(struct regcache *cache, jit_state_t *_jit, u8 reg); | |
51 | void lightrec_load_next_pc_imm(struct regcache *cache, | |
52 | jit_state_t *_jit, u32 pc, u32 imm); | |
d16005f8 | 53 | |
ba3814c1 PC |
54 | s8 lightrec_get_reg_with_value(struct regcache *cache, intptr_t value); |
55 | void lightrec_temp_set_value(struct regcache *cache, u8 jit_reg, intptr_t value); | |
56 | ||
98fa08a5 PC |
57 | u8 lightrec_get_reg_in_flags(struct regcache *cache, u8 jit_reg); |
58 | void lightrec_set_reg_out_flags(struct regcache *cache, u8 jit_reg, u8 flags); | |
59 | ||
d16005f8 | 60 | void lightrec_regcache_reset(struct regcache *cache); |
9259d748 | 61 | void lightrec_preload_pc(struct regcache *cache); |
d16005f8 | 62 | |
d16005f8 PC |
63 | void lightrec_free_reg(struct regcache *cache, u8 jit_reg); |
64 | void lightrec_free_regs(struct regcache *cache); | |
65 | void lightrec_clean_reg(struct regcache *cache, jit_state_t *_jit, u8 jit_reg); | |
66 | void lightrec_clean_regs(struct regcache *cache, jit_state_t *_jit); | |
67 | void lightrec_unload_reg(struct regcache *cache, jit_state_t *_jit, u8 jit_reg); | |
68 | void lightrec_storeback_regs(struct regcache *cache, jit_state_t *_jit); | |
ba3814c1 | 69 | _Bool lightrec_has_dirty_regs(struct regcache *cache); |
d16005f8 PC |
70 | |
71 | void lightrec_clean_reg_if_loaded(struct regcache *cache, jit_state_t *_jit, | |
9259d748 PC |
72 | u16 reg, _Bool unload); |
73 | void lightrec_discard_reg_if_loaded(struct regcache *cache, u16 reg); | |
d16005f8 PC |
74 | |
75 | u8 lightrec_alloc_reg_in_address(struct regcache *cache, | |
9259d748 | 76 | jit_state_t *_jit, u16 reg, s16 offset); |
d16005f8 PC |
77 | |
78 | struct native_register * lightrec_regcache_enter_branch(struct regcache *cache); | |
79 | void lightrec_regcache_leave_branch(struct regcache *cache, | |
80 | struct native_register *regs); | |
81 | ||
82 | struct regcache * lightrec_regcache_init(struct lightrec_state *state); | |
83 | void lightrec_free_regcache(struct regcache *cache); | |
84 | ||
85 | const char * lightrec_reg_name(u8 reg); | |
86 | ||
87 | void lightrec_regcache_mark_live(struct regcache *cache, jit_state_t *_jit); | |
88 | ||
89 | #endif /* __REGCACHE_H__ */ |