@@ -144,7 +144,7 @@ void ir_print_const(const ir_ctx *ctx, const ir_insn *insn, FILE *f, bool quoted
144144 if (isnan (insn -> val .f )) {
145145 fprintf (f , "nan" );
146146 } else {
147- fprintf (f , "%f " , insn -> val .f );
147+ fprintf (f , "%g " , insn -> val .f );
148148 }
149149 break ;
150150 default :
@@ -301,58 +301,17 @@ void ir_init(ir_ctx *ctx, uint32_t flags, ir_ref consts_limit, ir_ref insns_limi
301301 IR_ASSERT (consts_limit >= IR_CONSTS_LIMIT_MIN );
302302 IR_ASSERT (insns_limit >= IR_INSNS_LIMIT_MIN );
303303
304+ memset (ctx , 0 , sizeof (ir_ctx ));
305+
304306 ctx -> insns_count = IR_UNUSED + 1 ;
305307 ctx -> insns_limit = insns_limit ;
306308 ctx -> consts_count = - (IR_TRUE - 1 );
307309 ctx -> consts_limit = consts_limit ;
308310 ctx -> fold_cse_limit = IR_UNUSED + 1 ;
309311 ctx -> flags = flags ;
310- ctx -> mflags = 0 ;
311- ctx -> status = 0 ;
312-
313- ctx -> binding = NULL ;
314-
315- ctx -> use_lists = NULL ;
316- ctx -> use_edges = NULL ;
317- ctx -> use_edges_count = 0 ;
318-
319- ctx -> cfg_blocks_count = 0 ;
320- ctx -> cfg_edges_count = 0 ;
321- ctx -> cfg_blocks = NULL ;
322- ctx -> cfg_edges = NULL ;
323- ctx -> cfg_map = NULL ;
324- ctx -> rules = NULL ;
325- ctx -> vregs = NULL ;
326- ctx -> vregs_count = 0 ;
312+
327313 ctx -> spill_base = -1 ;
328- ctx -> fixed_stack_red_zone = 0 ;
329314 ctx -> fixed_stack_frame_size = -1 ;
330- ctx -> fixed_call_stack_size = 0 ;
331- ctx -> fixed_regset = 0 ;
332- ctx -> fixed_save_regset = 0 ;
333- ctx -> live_intervals = NULL ;
334- ctx -> arena = NULL ;
335- ctx -> unused_ranges = NULL ;
336- ctx -> regs = NULL ;
337- ctx -> prev_ref = NULL ;
338- ctx -> data = NULL ;
339- ctx -> snapshot_create = NULL ;
340- ctx -> entries_count = 0 ;
341- ctx -> entries = NULL ;
342- ctx -> osr_entry_loads = NULL ;
343-
344- ctx -> code_buffer = NULL ;
345- ctx -> code_buffer_size = 0 ;
346-
347- #if defined(IR_TARGET_AARCH64 )
348- ctx -> deoptimization_exits = 0 ;
349- ctx -> veneers_size = 0 ;
350- ctx -> get_exit_addr = NULL ;
351- ctx -> get_veneer = NULL ;
352- ctx -> set_veneer = NULL ;
353- #endif
354-
355- ctx -> strtab .data = NULL ;
356315
357316 buf = ir_mem_malloc ((consts_limit + insns_limit ) * sizeof (ir_insn ));
358317 ctx -> ir_base = buf + consts_limit ;
@@ -364,9 +323,6 @@ void ir_init(ir_ctx *ctx, uint32_t flags, ir_ref consts_limit, ir_ref insns_limi
364323 ctx -> ir_base [IR_FALSE ].val .u64 = 0 ;
365324 ctx -> ir_base [IR_TRUE ].optx = IR_OPT (IR_C_BOOL , IR_BOOL );
366325 ctx -> ir_base [IR_TRUE ].val .u64 = 1 ;
367-
368- memset (ctx -> prev_insn_chain , 0 , sizeof (ctx -> prev_insn_chain ));
369- memset (ctx -> prev_const_chain , 0 , sizeof (ctx -> prev_const_chain ));
370326}
371327
372328void ir_free (ir_ctx * ctx )
@@ -1991,13 +1947,21 @@ void _ir_UNREACHABLE(ir_ctx *ctx)
19911947void _ir_TAILCALL (ir_ctx * ctx , ir_type type , ir_ref func )
19921948{
19931949 IR_ASSERT (ctx -> control );
1950+ if (ctx -> ret_type == (ir_type )- 1 ) {
1951+ ctx -> ret_type = type ;
1952+ }
1953+ IR_ASSERT (ctx -> ret_type == type && "conflicting return type" );
19941954 ctx -> control = ir_emit2 (ctx , IR_OPTX (IR_TAILCALL , type , 2 ), ctx -> control , func );
19951955 _ir_UNREACHABLE (ctx );
19961956}
19971957
19981958void _ir_TAILCALL_1 (ir_ctx * ctx , ir_type type , ir_ref func , ir_ref arg1 )
19991959{
20001960 IR_ASSERT (ctx -> control );
1961+ if (ctx -> ret_type == (ir_type )- 1 ) {
1962+ ctx -> ret_type = type ;
1963+ }
1964+ IR_ASSERT (ctx -> ret_type == type && "conflicting return type" );
20011965 ctx -> control = ir_emit3 (ctx , IR_OPTX (IR_TAILCALL , type , 3 ), ctx -> control , func , arg1 );
20021966 _ir_UNREACHABLE (ctx );
20031967}
@@ -2007,6 +1971,10 @@ void _ir_TAILCALL_2(ir_ctx *ctx, ir_type type, ir_ref func, ir_ref arg1, ir_ref
20071971 ir_ref call ;
20081972
20091973 IR_ASSERT (ctx -> control );
1974+ if (ctx -> ret_type == (ir_type )- 1 ) {
1975+ ctx -> ret_type = type ;
1976+ }
1977+ IR_ASSERT (ctx -> ret_type == type && "conflicting return type" );
20101978 call = ir_emit_N (ctx , IR_OPT (IR_TAILCALL , type ), 4 );
20111979 ir_set_op (ctx , call , 1 , ctx -> control );
20121980 ir_set_op (ctx , call , 2 , func );
@@ -2021,6 +1989,10 @@ void _ir_TAILCALL_3(ir_ctx *ctx, ir_type type, ir_ref func, ir_ref arg1, ir_ref
20211989 ir_ref call ;
20221990
20231991 IR_ASSERT (ctx -> control );
1992+ if (ctx -> ret_type == (ir_type )- 1 ) {
1993+ ctx -> ret_type = type ;
1994+ }
1995+ IR_ASSERT (ctx -> ret_type == type && "conflicting return type" );
20241996 call = ir_emit_N (ctx , IR_OPT (IR_TAILCALL , type ), 5 );
20251997 ir_set_op (ctx , call , 1 , ctx -> control );
20261998 ir_set_op (ctx , call , 2 , func );
@@ -2036,6 +2008,10 @@ void _ir_TAILCALL_4(ir_ctx *ctx, ir_type type, ir_ref func, ir_ref arg1, ir_ref
20362008 ir_ref call ;
20372009
20382010 IR_ASSERT (ctx -> control );
2011+ if (ctx -> ret_type == (ir_type )- 1 ) {
2012+ ctx -> ret_type = type ;
2013+ }
2014+ IR_ASSERT (ctx -> ret_type == type && "conflicting return type" );
20392015 call = ir_emit_N (ctx , IR_OPT (IR_TAILCALL , type ), 6 );
20402016 ir_set_op (ctx , call , 1 , ctx -> control );
20412017 ir_set_op (ctx , call , 2 , func );
@@ -2052,6 +2028,10 @@ void _ir_TAILCALL_5(ir_ctx *ctx, ir_type type, ir_ref func, ir_ref arg1, ir_ref
20522028 ir_ref call ;
20532029
20542030 IR_ASSERT (ctx -> control );
2031+ if (ctx -> ret_type == (ir_type )- 1 ) {
2032+ ctx -> ret_type = type ;
2033+ }
2034+ IR_ASSERT (ctx -> ret_type == type && "conflicting return type" );
20552035 call = ir_emit_N (ctx , IR_OPT (IR_TAILCALL , type ), 7 );
20562036 ir_set_op (ctx , call , 1 , ctx -> control );
20572037 ir_set_op (ctx , call , 2 , func );
@@ -2070,6 +2050,10 @@ void _ir_TAILCALL_N(ir_ctx *ctx, ir_type type, ir_ref func, uint32_t count, ir_r
20702050 uint32_t i ;
20712051
20722052 IR_ASSERT (ctx -> control );
2053+ if (ctx -> ret_type == (ir_type )- 1 ) {
2054+ ctx -> ret_type = type ;
2055+ }
2056+ IR_ASSERT (ctx -> ret_type == type && "conflicting return type" );
20732057 call = ir_emit_N (ctx , IR_OPT (IR_TAILCALL , type ), count + 2 );
20742058 ir_set_op (ctx , call , 1 , ctx -> control );
20752059 ir_set_op (ctx , call , 2 , func );
@@ -2104,7 +2088,13 @@ void _ir_CASE_DEFAULT(ir_ctx *ctx, ir_ref switch_ref)
21042088
21052089void _ir_RETURN (ir_ctx * ctx , ir_ref val )
21062090{
2091+ ir_type type = (val != IR_UNUSED ) ? ctx -> ir_base [val ].type : IR_VOID ;
2092+
21072093 IR_ASSERT (ctx -> control );
2094+ if (ctx -> ret_type == (ir_type )- 1 ) {
2095+ ctx -> ret_type = type ;
2096+ }
2097+ IR_ASSERT (ctx -> ret_type == type && "conflicting return type" );
21082098 ctx -> control = ir_emit3 (ctx , IR_RETURN , ctx -> control , val , ctx -> ir_base [1 ].op1 );
21092099 ctx -> ir_base [1 ].op1 = ctx -> control ;
21102100 ctx -> control = IR_UNUSED ;
@@ -2330,52 +2320,3 @@ void _ir_STORE(ir_ctx *ctx, ir_ref addr, ir_ref val)
23302320 }
23312321 ctx -> control = ir_emit3 (ctx , IR_STORE , ctx -> control , addr , val );
23322322}
2333-
2334- ir_type ir_get_return_type (ir_ctx * ctx )
2335- {
2336- ir_ref ref ;
2337- ir_insn * insn ;
2338- uint8_t ret_type = 255 ;
2339- ir_type type ;
2340-
2341- /* Check all RETURN nodes */
2342- ref = ctx -> ir_base [1 ].op1 ;
2343- while (ref ) {
2344- insn = & ctx -> ir_base [ref ];
2345- if (insn -> op == IR_RETURN ) {
2346- type = ctx -> ir_base [insn -> op2 ].type ;
2347- check_type :
2348- if (ret_type == 255 ) {
2349- if (insn -> op2 ) {
2350- ret_type = type ;
2351- } else {
2352- ret_type = IR_VOID ;
2353- }
2354- } else if (insn -> op2 ) {
2355- if (ret_type != type ) {
2356- IR_ASSERT (0 && "conflicting return types" );
2357- return IR_VOID ;
2358- }
2359- } else {
2360- if (ret_type != IR_VOID ) {
2361- IR_ASSERT (0 && "conflicting return types" );
2362- return IR_VOID ;
2363- }
2364- }
2365- } else if (insn -> op == IR_UNREACHABLE ) {
2366- insn = & ctx -> ir_base [insn -> op1 ];
2367- if (insn -> op == IR_TAILCALL ) {
2368- type = insn -> type ;
2369- if (type != IR_VOID ) {
2370- goto check_type ;
2371- }
2372- }
2373- }
2374- ref = ctx -> ir_base [ref ].op3 ;
2375- }
2376-
2377- if (ret_type == 255 ) {
2378- ret_type = IR_VOID ;
2379- }
2380- return (ir_type )ret_type ;
2381- }
0 commit comments