@@ -69,7 +69,7 @@ const char *ir_op_name[IR_LAST_OP] = {
69
69
70
70
void ir_print_const (const ir_ctx * ctx , const ir_insn * insn , FILE * f , bool quoted )
71
71
{
72
- if (insn -> op == IR_FUNC ) {
72
+ if (insn -> op == IR_FUNC || insn -> op == IR_SYM ) {
73
73
fprintf (f , "%s" , ir_get_str (ctx , insn -> val .i32 ));
74
74
return ;
75
75
} else if (insn -> op == IR_STR ) {
@@ -462,7 +462,7 @@ ir_ref ir_unique_const_addr(ir_ctx *ctx, uintptr_t addr)
462
462
return ref ;
463
463
}
464
464
465
- IR_NEVER_INLINE ir_ref ir_const (ir_ctx * ctx , ir_val val , uint8_t type )
465
+ static IR_NEVER_INLINE ir_ref ir_const_ex (ir_ctx * ctx , ir_val val , uint8_t type , uint32_t optx )
466
466
{
467
467
ir_insn * insn , * prev_insn ;
468
468
ir_ref ref , prev ;
@@ -477,7 +477,7 @@ IR_NEVER_INLINE ir_ref ir_const(ir_ctx *ctx, ir_val val, uint8_t type)
477
477
while (ref ) {
478
478
insn = & ctx -> ir_base [ref ];
479
479
if (UNEXPECTED (insn -> val .u64 >= val .u64 )) {
480
- if (insn -> val .u64 == val .u64 ) {
480
+ if (insn -> val .u64 == val .u64 && insn -> optx == optx ) {
481
481
return ref ;
482
482
} else {
483
483
break ;
@@ -499,12 +499,17 @@ IR_NEVER_INLINE ir_ref ir_const(ir_ctx *ctx, ir_val val, uint8_t type)
499
499
insn = & ctx -> ir_base [ref ];
500
500
insn -> prev_const = prev ;
501
501
502
- insn -> optx = IR_OPT ( type , type ) ;
502
+ insn -> optx = optx ;
503
503
insn -> val .u64 = val .u64 ;
504
504
505
505
return ref ;
506
506
}
507
507
508
+ ir_ref ir_const (ir_ctx * ctx , ir_val val , uint8_t type )
509
+ {
510
+ return ir_const_ex (ctx , val , type , IR_OPT (type , type ));
511
+ }
512
+
508
513
ir_ref ir_const_i8 (ir_ctx * ctx , int8_t c )
509
514
{
510
515
ir_val val ;
@@ -600,47 +605,33 @@ ir_ref ir_const_addr(ir_ctx *ctx, uintptr_t c)
600
605
601
606
ir_ref ir_const_func_addr (ir_ctx * ctx , uintptr_t c , uint16_t flags )
602
607
{
603
- ir_ref top = - ctx -> consts_count ;
604
- ir_ref ref ;
605
- ir_insn * insn ;
606
-
607
608
if (c == 0 ) {
608
609
return IR_NULL ;
609
610
}
610
611
ir_val val ;
611
612
val .u64 = c ;
612
- ref = ir_const (ctx , val , IR_ADDR );
613
- if (ref == top ) {
614
- insn = & ctx -> ir_base [ref ];
615
- insn -> optx = IR_OPT (IR_FUNC_ADDR , IR_ADDR );
616
- insn -> const_flags = flags ;
617
- } else {
618
- IR_ASSERT (ctx -> ir_base [ref ].opt == IR_OPT (IR_FUNC_ADDR , IR_ADDR ) && ctx -> ir_base [ref ].const_flags == flags );
619
- }
620
- return ref ;
613
+ return ir_const_ex (ctx , val , IR_ADDR , IR_OPTX (IR_FUNC_ADDR , IR_ADDR , flags ));
621
614
}
622
615
623
616
ir_ref ir_const_func (ir_ctx * ctx , ir_ref str , uint16_t flags )
624
617
{
625
- ir_ref ref = ir_next_const (ctx );
626
- ir_insn * insn = & ctx -> ir_base [ref ];
627
-
628
- insn -> optx = IR_OPT (IR_FUNC , IR_ADDR );
629
- insn -> const_flags = flags ;
630
- insn -> val .addr = str ;
618
+ ir_val val ;
619
+ val .addr = str ;
620
+ return ir_const_ex (ctx , val , IR_ADDR , IR_OPTX (IR_FUNC , IR_ADDR , flags ));
621
+ }
631
622
632
- return ref ;
623
+ ir_ref ir_const_sym (ir_ctx * ctx , ir_ref str )
624
+ {
625
+ ir_val val ;
626
+ val .addr = str ;
627
+ return ir_const_ex (ctx , val , IR_ADDR , IR_OPTX (IR_SYM , IR_ADDR , 0 ));
633
628
}
634
629
635
630
ir_ref ir_const_str (ir_ctx * ctx , ir_ref str )
636
631
{
637
- ir_ref ref = ir_next_const (ctx );
638
- ir_insn * insn = & ctx -> ir_base [ref ];
639
-
640
- insn -> optx = IR_OPT (IR_STR , IR_ADDR );
641
- insn -> val .addr = str ;
642
-
643
- return ref ;
632
+ ir_val val ;
633
+ val .addr = str ;
634
+ return ir_const_ex (ctx , val , IR_ADDR , IR_OPTX (IR_STR , IR_ADDR , 0 ));
644
635
}
645
636
646
637
ir_ref ir_str (ir_ctx * ctx , const char * s )
@@ -1997,26 +1988,26 @@ void _ir_UNREACHABLE(ir_ctx *ctx)
1997
1988
ctx -> control = IR_UNUSED ;
1998
1989
}
1999
1990
2000
- void _ir_TAILCALL (ir_ctx * ctx , ir_ref func )
1991
+ void _ir_TAILCALL (ir_ctx * ctx , ir_type type , ir_ref func )
2001
1992
{
2002
1993
IR_ASSERT (ctx -> control );
2003
- ctx -> control = ir_emit2 (ctx , IR_OPTX (IR_TAILCALL , IR_VOID , 2 ), ctx -> control , func );
1994
+ ctx -> control = ir_emit2 (ctx , IR_OPTX (IR_TAILCALL , type , 2 ), ctx -> control , func );
2004
1995
_ir_UNREACHABLE (ctx );
2005
1996
}
2006
1997
2007
- void _ir_TAILCALL_1 (ir_ctx * ctx , ir_ref func , ir_ref arg1 )
1998
+ void _ir_TAILCALL_1 (ir_ctx * ctx , ir_type type , ir_ref func , ir_ref arg1 )
2008
1999
{
2009
2000
IR_ASSERT (ctx -> control );
2010
- ctx -> control = ir_emit3 (ctx , IR_OPTX (IR_TAILCALL , IR_VOID , 3 ), ctx -> control , func , arg1 );
2001
+ ctx -> control = ir_emit3 (ctx , IR_OPTX (IR_TAILCALL , type , 3 ), ctx -> control , func , arg1 );
2011
2002
_ir_UNREACHABLE (ctx );
2012
2003
}
2013
2004
2014
- void _ir_TAILCALL_2 (ir_ctx * ctx , ir_ref func , ir_ref arg1 , ir_ref arg2 )
2005
+ void _ir_TAILCALL_2 (ir_ctx * ctx , ir_type type , ir_ref func , ir_ref arg1 , ir_ref arg2 )
2015
2006
{
2016
2007
ir_ref call ;
2017
2008
2018
2009
IR_ASSERT (ctx -> control );
2019
- call = ir_emit_N (ctx , IR_TAILCALL , 4 );
2010
+ call = ir_emit_N (ctx , IR_OPT ( IR_TAILCALL , type ) , 4 );
2020
2011
ir_set_op (ctx , call , 1 , ctx -> control );
2021
2012
ir_set_op (ctx , call , 2 , func );
2022
2013
ir_set_op (ctx , call , 3 , arg1 );
@@ -2025,12 +2016,12 @@ void _ir_TAILCALL_2(ir_ctx *ctx, ir_ref func, ir_ref arg1, ir_ref arg2)
2025
2016
_ir_UNREACHABLE (ctx );
2026
2017
}
2027
2018
2028
- void _ir_TAILCALL_3 (ir_ctx * ctx , ir_ref func , ir_ref arg1 , ir_ref arg2 , ir_ref arg3 )
2019
+ void _ir_TAILCALL_3 (ir_ctx * ctx , ir_type type , ir_ref func , ir_ref arg1 , ir_ref arg2 , ir_ref arg3 )
2029
2020
{
2030
2021
ir_ref call ;
2031
2022
2032
2023
IR_ASSERT (ctx -> control );
2033
- call = ir_emit_N (ctx , IR_TAILCALL , 5 );
2024
+ call = ir_emit_N (ctx , IR_OPT ( IR_TAILCALL , type ) , 5 );
2034
2025
ir_set_op (ctx , call , 1 , ctx -> control );
2035
2026
ir_set_op (ctx , call , 2 , func );
2036
2027
ir_set_op (ctx , call , 3 , arg1 );
@@ -2040,12 +2031,12 @@ void _ir_TAILCALL_3(ir_ctx *ctx, ir_ref func, ir_ref arg1, ir_ref arg2, ir_ref a
2040
2031
_ir_UNREACHABLE (ctx );
2041
2032
}
2042
2033
2043
- void _ir_TAILCALL_4 (ir_ctx * ctx , ir_ref func , ir_ref arg1 , ir_ref arg2 , ir_ref arg3 , ir_ref arg4 )
2034
+ void _ir_TAILCALL_4 (ir_ctx * ctx , ir_type type , ir_ref func , ir_ref arg1 , ir_ref arg2 , ir_ref arg3 , ir_ref arg4 )
2044
2035
{
2045
2036
ir_ref call ;
2046
2037
2047
2038
IR_ASSERT (ctx -> control );
2048
- call = ir_emit_N (ctx , IR_TAILCALL , 6 );
2039
+ call = ir_emit_N (ctx , IR_OPT ( IR_TAILCALL , type ) , 6 );
2049
2040
ir_set_op (ctx , call , 1 , ctx -> control );
2050
2041
ir_set_op (ctx , call , 2 , func );
2051
2042
ir_set_op (ctx , call , 3 , arg1 );
@@ -2056,12 +2047,12 @@ void _ir_TAILCALL_4(ir_ctx *ctx, ir_ref func, ir_ref arg1, ir_ref arg2, ir_ref a
2056
2047
_ir_UNREACHABLE (ctx );
2057
2048
}
2058
2049
2059
- void _ir_TAILCALL_5 (ir_ctx * ctx , ir_ref func , ir_ref arg1 , ir_ref arg2 , ir_ref arg3 , ir_ref arg4 , ir_ref arg5 )
2050
+ void _ir_TAILCALL_5 (ir_ctx * ctx , ir_type type , ir_ref func , ir_ref arg1 , ir_ref arg2 , ir_ref arg3 , ir_ref arg4 , ir_ref arg5 )
2060
2051
{
2061
2052
ir_ref call ;
2062
2053
2063
2054
IR_ASSERT (ctx -> control );
2064
- call = ir_emit_N (ctx , IR_TAILCALL , 7 );
2055
+ call = ir_emit_N (ctx , IR_OPT ( IR_TAILCALL , type ) , 7 );
2065
2056
ir_set_op (ctx , call , 1 , ctx -> control );
2066
2057
ir_set_op (ctx , call , 2 , func );
2067
2058
ir_set_op (ctx , call , 3 , arg1 );
@@ -2073,13 +2064,13 @@ void _ir_TAILCALL_5(ir_ctx *ctx, ir_ref func, ir_ref arg1, ir_ref arg2, ir_ref a
2073
2064
_ir_UNREACHABLE (ctx );
2074
2065
}
2075
2066
2076
- void _ir_TAILCALL_N (ir_ctx * ctx , ir_ref func , uint32_t count , ir_ref * args )
2067
+ void _ir_TAILCALL_N (ir_ctx * ctx , ir_type type , ir_ref func , uint32_t count , ir_ref * args )
2077
2068
{
2078
2069
ir_ref call ;
2079
2070
uint32_t i ;
2080
2071
2081
2072
IR_ASSERT (ctx -> control );
2082
- call = ir_emit_N (ctx , IR_TAILCALL , count + 2 );
2073
+ call = ir_emit_N (ctx , IR_OPT ( IR_TAILCALL , type ) , count + 2 );
2083
2074
ir_set_op (ctx , call , 1 , ctx -> control );
2084
2075
ir_set_op (ctx , call , 2 , func );
2085
2076
for (i = 0 ; i < count ; i ++ ) {
@@ -2375,7 +2366,9 @@ ir_type ir_get_return_type(ir_ctx *ctx)
2375
2366
insn = & ctx -> ir_base [insn -> op1 ];
2376
2367
if (insn -> op == IR_TAILCALL ) {
2377
2368
type = insn -> type ;
2378
- goto check_type ;
2369
+ if (type != IR_VOID ) {
2370
+ goto check_type ;
2371
+ }
2379
2372
}
2380
2373
}
2381
2374
ref = ctx -> ir_base [ref ].op3 ;
0 commit comments