@@ -144,7 +144,7 @@ void ir_print_const(const ir_ctx *ctx, const ir_insn *insn, FILE *f, bool quoted
144
144
if (isnan (insn -> val .f )) {
145
145
fprintf (f , "nan" );
146
146
} else {
147
- fprintf (f , "%f " , insn -> val .f );
147
+ fprintf (f , "%g " , insn -> val .f );
148
148
}
149
149
break ;
150
150
default :
@@ -301,58 +301,17 @@ void ir_init(ir_ctx *ctx, uint32_t flags, ir_ref consts_limit, ir_ref insns_limi
301
301
IR_ASSERT (consts_limit >= IR_CONSTS_LIMIT_MIN );
302
302
IR_ASSERT (insns_limit >= IR_INSNS_LIMIT_MIN );
303
303
304
+ memset (ctx , 0 , sizeof (ir_ctx ));
305
+
304
306
ctx -> insns_count = IR_UNUSED + 1 ;
305
307
ctx -> insns_limit = insns_limit ;
306
308
ctx -> consts_count = - (IR_TRUE - 1 );
307
309
ctx -> consts_limit = consts_limit ;
308
310
ctx -> fold_cse_limit = IR_UNUSED + 1 ;
309
311
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
+
327
313
ctx -> spill_base = -1 ;
328
- ctx -> fixed_stack_red_zone = 0 ;
329
314
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 ;
356
315
357
316
buf = ir_mem_malloc ((consts_limit + insns_limit ) * sizeof (ir_insn ));
358
317
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
364
323
ctx -> ir_base [IR_FALSE ].val .u64 = 0 ;
365
324
ctx -> ir_base [IR_TRUE ].optx = IR_OPT (IR_C_BOOL , IR_BOOL );
366
325
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 ));
370
326
}
371
327
372
328
void ir_free (ir_ctx * ctx )
@@ -1991,13 +1947,21 @@ void _ir_UNREACHABLE(ir_ctx *ctx)
1991
1947
void _ir_TAILCALL (ir_ctx * ctx , ir_type type , ir_ref func )
1992
1948
{
1993
1949
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" );
1994
1954
ctx -> control = ir_emit2 (ctx , IR_OPTX (IR_TAILCALL , type , 2 ), ctx -> control , func );
1995
1955
_ir_UNREACHABLE (ctx );
1996
1956
}
1997
1957
1998
1958
void _ir_TAILCALL_1 (ir_ctx * ctx , ir_type type , ir_ref func , ir_ref arg1 )
1999
1959
{
2000
1960
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" );
2001
1965
ctx -> control = ir_emit3 (ctx , IR_OPTX (IR_TAILCALL , type , 3 ), ctx -> control , func , arg1 );
2002
1966
_ir_UNREACHABLE (ctx );
2003
1967
}
@@ -2007,6 +1971,10 @@ void _ir_TAILCALL_2(ir_ctx *ctx, ir_type type, ir_ref func, ir_ref arg1, ir_ref
2007
1971
ir_ref call ;
2008
1972
2009
1973
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" );
2010
1978
call = ir_emit_N (ctx , IR_OPT (IR_TAILCALL , type ), 4 );
2011
1979
ir_set_op (ctx , call , 1 , ctx -> control );
2012
1980
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
2021
1989
ir_ref call ;
2022
1990
2023
1991
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" );
2024
1996
call = ir_emit_N (ctx , IR_OPT (IR_TAILCALL , type ), 5 );
2025
1997
ir_set_op (ctx , call , 1 , ctx -> control );
2026
1998
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
2036
2008
ir_ref call ;
2037
2009
2038
2010
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" );
2039
2015
call = ir_emit_N (ctx , IR_OPT (IR_TAILCALL , type ), 6 );
2040
2016
ir_set_op (ctx , call , 1 , ctx -> control );
2041
2017
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
2052
2028
ir_ref call ;
2053
2029
2054
2030
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" );
2055
2035
call = ir_emit_N (ctx , IR_OPT (IR_TAILCALL , type ), 7 );
2056
2036
ir_set_op (ctx , call , 1 , ctx -> control );
2057
2037
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
2070
2050
uint32_t i ;
2071
2051
2072
2052
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" );
2073
2057
call = ir_emit_N (ctx , IR_OPT (IR_TAILCALL , type ), count + 2 );
2074
2058
ir_set_op (ctx , call , 1 , ctx -> control );
2075
2059
ir_set_op (ctx , call , 2 , func );
@@ -2104,7 +2088,13 @@ void _ir_CASE_DEFAULT(ir_ctx *ctx, ir_ref switch_ref)
2104
2088
2105
2089
void _ir_RETURN (ir_ctx * ctx , ir_ref val )
2106
2090
{
2091
+ ir_type type = (val != IR_UNUSED ) ? ctx -> ir_base [val ].type : IR_VOID ;
2092
+
2107
2093
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" );
2108
2098
ctx -> control = ir_emit3 (ctx , IR_RETURN , ctx -> control , val , ctx -> ir_base [1 ].op1 );
2109
2099
ctx -> ir_base [1 ].op1 = ctx -> control ;
2110
2100
ctx -> control = IR_UNUSED ;
@@ -2330,52 +2320,3 @@ void _ir_STORE(ir_ctx *ctx, ir_ref addr, ir_ref val)
2330
2320
}
2331
2321
ctx -> control = ir_emit3 (ctx , IR_STORE , ctx -> control , addr , val );
2332
2322
}
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