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