2424#include "data_struct.h"
2525
2626static ereg ENULL = {VAL_NULL };
27+ static void __ignore ( void * value ) {}
2728
2829typedef struct {
2930 hl_type * t ;
@@ -46,7 +47,14 @@ typedef struct _tmp_phi tmp_phi;
4647#include "data_struct.c"
4748#define blocks_add (set ,v ) blocks_add_impl(DEF_ALLOC,&(set),v)
4849
50+ #define S_TYPE phi_arr
51+ #define S_NAME (name ) phi_##name
52+ #define S_VALUE tmp_phi*
53+ #include "data_struct.c"
54+ #define phi_add (set ,v ) phi_add_impl(DEF_ALLOC,&(set),v)
55+
4956#define S_SORTED
57+
5058#define S_DEFVAL ENULL
5159#define S_CMP (a ,b ) a.index > b.index
5260#define S_TYPE ereg_map
@@ -55,11 +63,15 @@ typedef struct _tmp_phi tmp_phi;
5563#include "data_struct.c"
5664#define ereg_add (set ,v ) ereg_add_impl(DEF_ALLOC,&(set),v)
5765
58- #define S_TYPE phi_arr
59- #define S_NAME (name ) phi_##name
60- #define S_VALUE tmp_phi*
66+ #define S_MAP
67+
68+ #define S_DEFVAL ENULL
69+ #define S_TYPE vreg_map
70+ #define S_NAME (name ) vreg_##name
71+ #define S_KEY int
72+ #define S_VALUE ereg
6173#include "data_struct.c"
62- #define phi_add (set ,v ) phi_add_impl (DEF_ALLOC,&(set),v)
74+ #define vreg_replace (set ,k , v ) vreg_replace_impl (DEF_ALLOC,&(set),k ,v)
6375
6476struct _linked_inf {
6577 int id ;
@@ -76,7 +88,7 @@ struct _emit_block {
7688 bool sealed ;
7789 blocks nexts ;
7890 blocks preds ;
79- int_map written_vars ;
91+ vreg_map written_vars ;
8092 phi_arr phis ;
8193 emit_block * wait_seal_next ;
8294};
@@ -399,21 +411,13 @@ static void block_add_pred( emit_ctx *ctx, emit_block *b, emit_block *p ) {
399411
400412static void store_block_var ( emit_ctx * ctx , emit_block * b , vreg * r , ereg v ) {
401413 if ( IS_NULL (v ) ) jit_assert ();
402- int_map_replace (b -> written_vars ,r -> id ,v . index < 0 ? v . index : v . index + 1 );
414+ vreg_replace (b -> written_vars ,r -> id ,v );
403415 if ( v .index < 0 ) {
404416 tmp_phi * p = GET_PHI (v );
405417 p -> ref_blocks = link_add_sort_unique (ctx ,b -> id ,b ,p -> ref_blocks );
406418 }
407419}
408420
409- static ereg lookup_block_var ( emit_block * b , vreg * r ) {
410- int e = int_map_find (b -> written_vars ,r -> id );
411- if ( !e ) return ENULL ;
412- ereg v ;
413- v .index = e < 0 ? e : e - 1 ;
414- return v ;
415- }
416-
417421static void split_block ( emit_ctx * ctx ) {
418422 emit_block * b = alloc_block (ctx );
419423 b -> sealed = true;
@@ -530,7 +534,7 @@ static ereg optimize_phi_rec( emit_ctx *ctx, tmp_phi *p ) {
530534 linked_inf * l = p -> ref_blocks ;
531535 while ( l ) {
532536 emit_block * b = (emit_block * )l -> ptr ;
533- if ( lookup_block_var ( b ,p -> r ).index == p -> value .index )
537+ if ( vreg_find ( b -> written_vars ,p -> r -> id ).index == p -> value .index )
534538 store_block_var (ctx ,b ,p -> r ,same );
535539 l = l -> next ;
536540 }
@@ -561,7 +565,7 @@ static ereg gather_phis( emit_ctx *ctx, tmp_phi *p ) {
561565}
562566
563567static ereg emit_load_reg_block ( emit_ctx * ctx , emit_block * b , vreg * r ) {
564- ereg v = lookup_block_var ( b , r );
568+ ereg v = vreg_find ( b -> written_vars , r -> id );
565569 if ( !IS_NULL (v ) )
566570 return v ;
567571 if ( !b -> sealed ) {
@@ -1058,6 +1062,7 @@ static void emit_opcode( emit_ctx *ctx, hl_opcode *o ) {
10581062 hl_module * m = ctx -> mod ;
10591063#ifdef HL_DEBUG
10601064 int uid = (ctx -> fun -> findex << 16 ) | ctx -> op_pos ;
1065+ __ignore (& uid );
10611066#endif
10621067 switch ( o -> op ) {
10631068 case OMov :
@@ -1614,10 +1619,10 @@ static void emit_opcode( emit_ctx *ctx, hl_opcode *o ) {
16141619 {
16151620 ereg ref = resolve_ref (ctx , ra -> id );
16161621 if ( IS_NULL (ref ) ) jit_assert ();
1617- ereg r = lookup_block_var (ctx -> current_block , ra );
1622+ ereg r = vreg_find (ctx -> current_block -> written_vars , ra -> id );
16181623 if ( !IS_NULL (r ) ) {
16191624 STORE_MEM (ref , 0 , LOAD (ra ));
1620- int_map_remove (& ctx -> current_block -> written_vars , ra -> id );
1625+ vreg_remove (& ctx -> current_block -> written_vars , ra -> id );
16211626 }
16221627 STORE (dst , ref );
16231628 }
0 commit comments