Skip to content

Commit 913a15c

Browse files
committed
Move "jit-cache" into existing files
1 parent ef1dbb5 commit 913a15c

File tree

7 files changed

+62
-77
lines changed

7 files changed

+62
-77
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,17 @@ endif
140140
ifneq ("$(LLVM_CONFIG)", "")
141141
ifneq ("$(findstring -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS, "$(shell $(LLVM_CONFIG) --cflags)")", "")
142142
ENABLE_T2C := 1
143+
ENABLE_JIT_CACHE := 1
143144
$(call set-feature, T2C)
144-
OBJS_EXT += jit-cache.o t2c.o
145+
$(call set-feature, JIT_CACHE)
146+
OBJS_EXT += t2c.o
145147
CFLAGS += -g $(shell $(LLVM_CONFIG) --cflags)
146148
LDFLAGS += $(shell $(LLVM_CONFIG) --libs)
147149
else
148150
ENABLE_T2C := 0
151+
ENABLE_JIT_CACHE := 0
149152
$(call set-feature, T2C)
153+
$(call set-feature, JIT_CACHE)
150154
$(warning No llvm-config-17 installed. Check llvm-config-17 installation in advance)
151155
endif
152156
endif

src/jit-cache.c

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/jit-cache.h

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/jit.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#include "cache.h"
3838
#include "decode.h"
3939
#include "io.h"
40-
#include "jit-cache.h"
4140
#include "jit.h"
4241
#include "riscv.h"
4342
#include "riscv_private.h"
@@ -2030,3 +2029,32 @@ void jit_state_exit(struct jit_state *state)
20302029
free(state->jumps);
20312030
free(state);
20322031
}
2032+
2033+
#if RV32_HAS(JIT_CACHE)
2034+
struct jit_cache *jit_cache_init()
2035+
{
2036+
return calloc(MAX_JIT_CACHE_TABLE_ENTRIES, sizeof(struct jit_cache));
2037+
}
2038+
2039+
void jit_cache_exit(struct jit_cache *cache)
2040+
{
2041+
free(cache);
2042+
}
2043+
2044+
void jit_cache_update(struct jit_cache *cache,
2045+
uint32_t pc,
2046+
uint32_t from,
2047+
void *entry)
2048+
{
2049+
uint32_t pos = pc & (MAX_JIT_CACHE_TABLE_ENTRIES - 1);
2050+
2051+
cache[pos].pc = pc;
2052+
cache[pos].from = from;
2053+
cache[pos].entry = entry;
2054+
}
2055+
2056+
void jit_cache_clear(struct jit_cache *cache)
2057+
{
2058+
memset(cache, 0, MAX_JIT_CACHE_TABLE_ENTRIES * sizeof(struct jit_cache));
2059+
}
2060+
#endif

src/jit.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,31 @@ typedef void (*exec_block_func_t)(riscv_t *rv, uintptr_t);
5454
void t2c_compile(riscv_t *, block_t *);
5555
typedef void (*exec_t2c_func_t)(riscv_t *);
5656
#endif
57+
58+
#if RV32_HAS(JIT_CACHE)
59+
#if !defined(__x86_64__) && !defined(__aarch64__)
60+
/* make sure LLVM can access the correct address of structure member */
61+
#error "The JIT-cache only supports 64-bit machine (LP64)."
62+
#endif
63+
64+
#define MAX_JIT_CACHE_TABLE_ENTRIES (1 << 12)
65+
66+
/* clang-format off */
67+
struct jit_cache {
68+
__attribute__((aligned(4))) uint32_t pc; /* program counter of ELF */
69+
__attribute__((aligned(4))) uint32_t from; /* from whether t1c or t2c,
70+
easily to build LLVM IR
71+
because of the alignment
72+
*/
73+
void *entry; /* entry of JIT-ed code */
74+
};
75+
/* clang-format on */
76+
77+
struct jit_cache *jit_cache_init();
78+
void jit_cache_exit(struct jit_cache *cache);
79+
void jit_cache_update(struct jit_cache *cache,
80+
uint32_t pc,
81+
uint32_t from,
82+
void *entry);
83+
void jit_cache_clear(struct jit_cache *cache);
84+
#endif

src/riscv.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include <pthread.h>
3333
#endif
3434
#include "cache.h"
35-
#include "jit-cache.h"
3635
#include "jit.h"
3736
#define CODE_CACHE_SIZE (4 * 1024 * 1024)
3837
#endif

src/t2c.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <llvm-c/Transforms/PassBuilder.h>
1212
#include <stdlib.h>
1313

14-
#include "jit-cache.h"
1514
#include "jit.h"
1615
#include "riscv_private.h"
1716

0 commit comments

Comments
 (0)