4242#include "decode.h"
4343#include "io.h"
4444#include "jit.h"
45+ #include "log.h"
4546#include "riscv.h"
4647#include "riscv_private.h"
4748#include "utils.h"
@@ -593,6 +594,7 @@ static void update_branch_imm(struct jit_state *state,
593594 assert ((imm & 3 ) == 0 );
594595 uint32_t insn ;
595596 imm >>= 2 ;
597+ rv_log_debug ("JIT: Patching branch at offset=%u, imm=%d" , offset , imm << 2 );
596598#if defined(__APPLE__ ) && defined(__aarch64__ )
597599 /* Must be in write mode to read/write MAP_JIT memory on Apple ARM64 */
598600 pthread_jit_write_protect_np (false);
@@ -2166,6 +2168,8 @@ void clear_hot(block_t *block)
21662168
21672169static void code_cache_flush (struct jit_state * state , riscv_t * rv )
21682170{
2171+ rv_log_debug ("JIT: Flushing code cache (n_blocks=%d, n_jumps=%d, offset=%u)" ,
2172+ state -> n_blocks , state -> n_jumps , state -> offset );
21692173 should_flush = false;
21702174 state -> offset = state -> org_size ;
21712175 state -> n_blocks = 0 ;
@@ -2199,6 +2203,7 @@ static void translate(struct jit_state *state, riscv_t *rv, block_t *block)
21992203
22002204static void resolve_jumps (struct jit_state * state )
22012205{
2206+ rv_log_debug ("JIT: Resolving %d jumps" , state -> n_jumps );
22022207 for (int i = 0 ; i < state -> n_jumps ; i ++ ) {
22032208 struct jump jump = state -> jumps [i ];
22042209 int target_loc ;
@@ -2221,6 +2226,8 @@ static void resolve_jumps(struct jit_state *state)
22212226 (if (jump .target_satp == state -> offset_map [i ].satp ), )
22222227 {
22232228 target_loc = state -> offset_map [i ].offset ;
2229+ rv_log_debug ("JIT: Jump %d resolved to block pc=0x%08x, offset=%d" ,
2230+ i , jump .target_pc , target_loc );
22242231 break ;
22252232 }
22262233 }
@@ -2312,12 +2319,15 @@ void jit_translate(riscv_t *rv, block_t *block)
23122319 ) {
23132320 block -> offset = state -> offset_map [i ].offset ;
23142321 block -> hot = true;
2322+ rv_log_debug ("JIT: Cache hit for block pc=0x%08x, offset=%u" ,
2323+ block -> pc_start , block -> offset );
23152324 return ;
23162325 }
23172326 }
23182327 assert (NULL );
23192328 __UNREACHABLE ;
23202329 }
2330+ rv_log_debug ("JIT: Starting translation for block pc=0x%08x" , block -> pc_start );
23212331restart :
23222332 memset (state -> jumps , 0 , MAX_JUMPS * sizeof (struct jump ));
23232333 state -> n_jumps = 0 ;
@@ -2327,11 +2337,15 @@ void jit_translate(riscv_t *rv, block_t *block)
23272337 /* Mark block as not translated since translation was incomplete */
23282338 block -> hot = false;
23292339 /* Don't reset offset - it will be set correctly on restart */
2340+ rv_log_debug ("JIT: Translation triggered flush for block pc=0x%08x" ,
2341+ block -> pc_start );
23302342 code_cache_flush (state , rv );
23312343 goto restart ;
23322344 }
23332345 resolve_jumps (state );
23342346 block -> hot = true;
2347+ rv_log_debug ("JIT: Translation completed for block pc=0x%08x, offset=%u, size=%u" ,
2348+ block -> pc_start , block -> offset , state -> offset - block -> offset );
23352349}
23362350
23372351struct jit_state * jit_state_init (size_t size )
0 commit comments