Skip to content

Commit 3a2b292

Browse files
committed
Remove T1C JIT cache invocation
1 parent 7038e04 commit 3a2b292

File tree

4 files changed

+13
-71
lines changed

4 files changed

+13
-71
lines changed

src/jit.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,15 +2038,11 @@ void jit_cache_exit(struct jit_cache *cache)
20382038
free(cache);
20392039
}
20402040

2041-
void jit_cache_update(struct jit_cache *cache,
2042-
uint32_t pc,
2043-
uint32_t from,
2044-
void *entry)
2041+
void jit_cache_update(struct jit_cache *cache, uint32_t pc, void *entry)
20452042
{
20462043
uint32_t pos = pc & (MAX_JIT_CACHE_TABLE_ENTRIES - 1);
20472044

20482045
cache[pos].pc = pc;
2049-
cache[pos].from = from;
20502046
cache[pos].entry = entry;
20512047
}
20522048

src/jit.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,12 @@ typedef void (*exec_t2c_func_t)(riscv_t *);
5959
#define MAX_JIT_CACHE_TABLE_ENTRIES (1 << 12)
6060

6161
struct jit_cache {
62-
uint32_t pc __ALIGNED(4); /* program counter of ELF */
63-
uint32_t from __ALIGNED(4); /* from whether t1c or t2c, ensure the correct
64-
alignment for accessing member in LLVM IR
65-
*/
66-
void *entry; /* entry of JIT-ed code */
62+
uint64_t pc; /* program counter, easy to build LLVM IR with 64-bit width */
63+
void *entry; /* entry of JIT-ed code */
6764
};
6865

6966
struct jit_cache *jit_cache_init();
7067
void jit_cache_exit(struct jit_cache *cache);
71-
void jit_cache_update(struct jit_cache *cache,
72-
uint32_t pc,
73-
uint32_t from,
74-
void *entry);
68+
void jit_cache_update(struct jit_cache *cache, uint32_t pc, void *entry);
7569
void jit_cache_clear(struct jit_cache *cache);
7670
#endif

src/t2c.c

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,7 @@ FORCE_INLINE void t2c_gen_call_io_func(LLVMValueRef start,
135135
&io_param, 1, "");
136136
}
137137

138-
static bool t2c_jit_cache_triggered;
139-
static LLVMTypeRef t2c_t1c_cache_func_proto;
140-
static LLVMValueRef t2c_t1c_cache_func;
141-
static LLVMTypeRef t2c_t2c_cache_func_proto;
138+
static LLVMTypeRef t2c_cache_func_proto;
142139
static LLVMTypeRef jit_cache_ty;
143140

144141
#include "t2c_template.c"
@@ -245,8 +242,6 @@ static void t2c_trace_ebb(LLVMBuilderRef *builder,
245242

246243
void t2c_compile(riscv_t *rv, block_t *block)
247244
{
248-
t2c_jit_cache_triggered = false;
249-
250245
LLVMModuleRef module = LLVMModuleCreateWithName("my_module");
251246
LLVMTypeRef io_members[] = {
252247
LLVMPointerType(LLVMVoidType(), 0), LLVMPointerType(LLVMVoidType(), 0),
@@ -264,20 +259,13 @@ void t2c_compile(riscv_t *rv, block_t *block)
264259
LLVMValueRef start = LLVMAddFunction(
265260
module, "start", LLVMFunctionType(LLVMVoidType(), param_types, 1, 0));
266261

267-
LLVMTypeRef t1c_args[2] = {LLVMInt64Type(), LLVMInt64Type()};
268-
t2c_t1c_cache_func_proto =
269-
LLVMFunctionType(LLVMVoidType(), t1c_args, 2, false);
270-
t2c_t1c_cache_func =
271-
LLVMAddFunction(module, "t2c_invoke_cache", t2c_t1c_cache_func_proto);
272-
273262
LLVMTypeRef t2c_args[1] = {LLVMInt64Type()};
274-
t2c_t2c_cache_func_proto =
275-
LLVMFunctionType(LLVMVoidType(), t2c_args, 1, false);
263+
t2c_cache_func_proto = LLVMFunctionType(LLVMVoidType(), t2c_args, 1, false);
276264

277265
/* Notice to the alignment */
278-
LLVMTypeRef jit_cache_memb[3] = {LLVMInt32Type(), LLVMInt32Type(),
266+
LLVMTypeRef jit_cache_memb[2] = {LLVMInt64Type(),
279267
LLVMPointerType(LLVMVoidType(), 0)};
280-
jit_cache_ty = LLVMStructType(jit_cache_memb, 3, false);
268+
jit_cache_ty = LLVMStructType(jit_cache_memb, 2, false);
281269

282270
LLVMBasicBlockRef first_block = LLVMAppendBasicBlock(start, "first_block");
283271
LLVMBuilderRef first_builder = LLVMCreateBuilder();
@@ -321,13 +309,8 @@ void t2c_compile(riscv_t *rv, block_t *block)
321309
abort();
322310
}
323311

324-
if (t2c_jit_cache_triggered) {
325-
LLVMAddGlobalMapping(engine, t2c_t1c_cache_func,
326-
((struct jit_state *) rv->jit_state)->buf);
327-
}
328-
329312
/* Return the function pointer of T2C generated machine code */
330313
block->func = (exec_t2c_func_t) LLVMGetPointerToGlobal(engine, start);
331-
jit_cache_update(rv->jit_cache, block->pc_start, 2, block->func);
314+
jit_cache_update(rv->jit_cache, block->pc_start, block->func);
332315
block->hot2 = true;
333316
}

src/t2c_template.c

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ FORCE_INLINE void t2c_jit_cache_helper(LLVMBuilderRef *builder,
3838
riscv_t *rv,
3939
rv_insn_t *ir)
4040
{
41-
t2c_jit_cache_triggered = true;
42-
4341
LLVMBasicBlockRef true_path = LLVMAppendBasicBlock(start, "");
4442
LLVMBuilderRef true_builder = LLVMCreateBuilder();
4543
LLVMPositionBuilderAtEnd(true_builder, true_path);
@@ -75,45 +73,16 @@ FORCE_INLINE void t2c_jit_cache_helper(LLVMBuilderRef *builder,
7573

7674
/* get jit_cache_t::entry */
7775
LLVMValueRef entry_ptr =
78-
LLVMBuildStructGEP2(true_builder, jit_cache_ty, element_ptr, 2, "");
79-
80-
/* get jit_cache_t::from */
81-
LLVMValueRef from_prt =
8276
LLVMBuildStructGEP2(true_builder, jit_cache_ty, element_ptr, 1, "");
83-
LLVMValueRef from =
84-
LLVMBuildLoad2(true_builder, LLVMInt32Type(), from_prt, "");
85-
86-
LLVMBasicBlockRef _true_path = LLVMAppendBasicBlock(start, "");
87-
LLVMBuilderRef _true_builder = LLVMCreateBuilder();
88-
LLVMPositionBuilderAtEnd(_true_builder, _true_path);
89-
90-
LLVMBasicBlockRef _false_path = LLVMAppendBasicBlock(start, "");
91-
LLVMBuilderRef _false_builder = LLVMCreateBuilder();
92-
LLVMPositionBuilderAtEnd(_false_builder, _false_path);
93-
94-
LLVMValueRef _cmp =
95-
LLVMBuildICmp(true_builder, LLVMIntEQ, from,
96-
LLVMConstInt(LLVMInt32Type(), 1, false), "");
97-
LLVMBuildCondBr(true_builder, _cmp, _true_path, _false_path);
98-
99-
/* invoke T1C JIT-ed code */
100-
LLVMValueRef t1c_args[2] = {
101-
LLVMConstInt(LLVMInt64Type(), (long) rv, false),
102-
LLVMBuildLoad2(_true_builder, LLVMInt64Type(), entry_ptr, "")};
103-
104-
LLVMBuildCall2(_true_builder, t2c_t1c_cache_func_proto, t2c_t1c_cache_func,
105-
t1c_args, 2, "");
106-
LLVMBuildRetVoid(_true_builder);
10777

10878
/* invoke T2C JIT-ed code */
10979
LLVMValueRef t2c_args[1] = {
11080
LLVMConstInt(LLVMInt64Type(), (long) rv, false)};
11181

112-
LLVMBuildCall2(
113-
_false_builder, t2c_t2c_cache_func_proto,
114-
LLVMBuildLoad2(_false_builder, LLVMInt64Type(), entry_ptr, ""),
115-
t2c_args, 1, "");
116-
LLVMBuildRetVoid(_false_builder);
82+
LLVMBuildCall2(true_builder, t2c_cache_func_proto,
83+
LLVMBuildLoad2(true_builder, LLVMInt64Type(), entry_ptr, ""),
84+
t2c_args, 1, "");
85+
LLVMBuildRetVoid(true_builder);
11786

11887
/* return to interpreter if cache-miss */
11988
LLVMBuildStore(false_builder, addr,

0 commit comments

Comments
 (0)