@@ -116,6 +116,10 @@ void build_rpo(void)
116116{
117117 bb_traversal_args_t * args = arena_alloc_traversal_args ();
118118 for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
119+ /* Skip function declarations without bodies */
120+ if (!func -> bbs )
121+ continue ;
122+
119123 args -> func = func ;
120124 args -> bb = func -> bbs ;
121125
@@ -158,6 +162,10 @@ basic_block_t *intersect(basic_block_t *i, basic_block_t *j)
158162void build_idom (void )
159163{
160164 for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
165+ /* Skip function declarations without bodies */
166+ if (!func -> bbs )
167+ continue ;
168+
161169 bool changed ;
162170
163171 func -> bbs -> idom = func -> bbs ;
@@ -230,6 +238,10 @@ void build_dom(void)
230238{
231239 bb_traversal_args_t * args = arena_alloc_traversal_args ();
232240 for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
241+ /* Skip function declarations without bodies */
242+ if (!func -> bbs )
243+ continue ;
244+
233245 args -> func = func ;
234246 args -> bb = func -> bbs ;
235247
@@ -264,6 +276,10 @@ void build_df(void)
264276{
265277 bb_traversal_args_t * args = arena_alloc_traversal_args ();
266278 for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
279+ /* Skip function declarations without bodies */
280+ if (!func -> bbs )
281+ continue ;
282+
267283 args -> func = func ;
268284 args -> bb = func -> bbs ;
269285
@@ -287,6 +303,10 @@ basic_block_t *reverse_intersect(basic_block_t *i, basic_block_t *j)
287303void build_r_idom (void )
288304{
289305 for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
306+ /* Skip function declarations without bodies */
307+ if (!func -> bbs )
308+ continue ;
309+
290310 bool changed ;
291311
292312 func -> exit -> r_idom = func -> exit ;
@@ -354,6 +374,10 @@ void build_rdom(void)
354374{
355375 bb_traversal_args_t * args = arena_alloc_traversal_args ();
356376 for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
377+ /* Skip function declarations without bodies */
378+ if (!func -> bbs )
379+ continue ;
380+
357381 args -> func = func ;
358382 args -> bb = func -> exit ;
359383
@@ -398,6 +422,10 @@ void build_rdf(void)
398422{
399423 bb_traversal_args_t * args = arena_alloc_traversal_args ();
400424 for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
425+ /* Skip function declarations without bodies */
426+ if (!func -> bbs )
427+ continue ;
428+
401429 args -> func = func ;
402430 args -> bb = func -> exit ;
403431
@@ -439,6 +467,10 @@ void use_chain_delete(use_chain_t *u, var_t *var)
439467void use_chain_build (void )
440468{
441469 for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
470+ /* Skip function declarations without bodies */
471+ if (!func -> bbs )
472+ continue ;
473+
442474 for (basic_block_t * bb = func -> bbs ; bb ; bb = bb -> rpo_next ) {
443475 for (insn_t * i = bb -> insn_list .head ; i ; i = i -> next ) {
444476 if (i -> rs1 )
@@ -545,6 +577,10 @@ void solve_globals(void)
545577{
546578 bb_traversal_args_t * args = arena_alloc_traversal_args ();
547579 for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
580+ /* Skip function declarations without bodies */
581+ if (!func -> bbs )
582+ continue ;
583+
548584 args -> func = func ;
549585 args -> bb = func -> bbs ;
550586
@@ -606,6 +642,10 @@ bool insert_phi_insn(basic_block_t *bb, var_t *var)
606642void solve_phi_insertion (void )
607643{
608644 for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
645+ /* Skip function declarations without bodies */
646+ if (!func -> bbs )
647+ continue ;
648+
609649 for (symbol_t * sym = func -> global_sym_list .head ; sym ; sym = sym -> next ) {
610650 var_t * var = sym -> var ;
611651
@@ -798,6 +838,10 @@ void bb_solve_phi_params(basic_block_t *bb)
798838void solve_phi_params (void )
799839{
800840 for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
841+ /* Skip function declarations without bodies */
842+ if (!func -> bbs )
843+ continue ;
844+
801845 for (int i = 0 ; i < func -> num_params ; i ++ ) {
802846 /* FIXME: Direct argument renaming in SSA construction phase may
803847 * interfere with later optimization passes
@@ -874,6 +918,10 @@ void unwind_phi(void)
874918{
875919 bb_traversal_args_t * args = arena_alloc_traversal_args ();
876920 for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
921+ /* Skip function declarations without bodies */
922+ if (!func -> bbs )
923+ continue ;
924+
877925 args -> func = func ;
878926 args -> bb = func -> bbs ;
879927
@@ -1135,7 +1183,7 @@ void bb_dump(FILE *fd, func_t *func, basic_block_t *bb)
11351183 break ;
11361184 case OP_sign_ext :
11371185 sprintf (str ,
1138- "<%s<SUB>%s </SUB> := sign_ext %s<SUB>%d</SUB>, %d>" ,
1186+ "<%s<SUB>%d </SUB> := sign_ext %s<SUB>%d</SUB>, %d>" ,
11391187 insn -> rd -> var_name , insn -> rd -> subscript ,
11401188 insn -> rs1 -> var_name , insn -> rs1 -> subscript , insn -> sz );
11411189 break ;
@@ -1180,6 +1228,10 @@ void dump_cfg(char name[])
11801228 fprintf (fd , "strict digraph CFG {\n" );
11811229 fprintf (fd , "node [shape=box]\n" );
11821230 for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
1231+ /* Skip function declarations without bodies */
1232+ if (!func -> bbs )
1233+ continue ;
1234+
11831235 func -> visited ++ ;
11841236 fprintf (fd , "subgraph cluster_%p {\n" , func );
11851237 fprintf (fd , "label=\"%p (%s)\"\n" , func , func -> return_def .var_name );
@@ -1209,6 +1261,10 @@ void dump_dom(char name[])
12091261 fprintf (fd , "node [shape=box]\n" );
12101262 fprintf (fd , "splines=polyline\n" );
12111263 for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
1264+ /* Skip function declarations without bodies */
1265+ if (!func -> bbs )
1266+ continue ;
1267+
12121268 fprintf (fd , "subgraph cluster_%p {\n" , func );
12131269 fprintf (fd , "label=\"%p\"\n" , func );
12141270 dom_dump (fd , func -> bbs );
@@ -1740,6 +1796,10 @@ void dce_sweep(void)
17401796 int total_eliminated = 0 ; /* Track effectiveness */
17411797
17421798 for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
1799+ /* Skip function declarations without bodies */
1800+ if (!func -> bbs )
1801+ continue ;
1802+
17431803 for (basic_block_t * bb = func -> bbs ; bb ; bb = bb -> rpo_next ) {
17441804 /* Skip unreachable blocks entirely */
17451805 if (is_block_unreachable (bb )) {
@@ -1812,17 +1872,30 @@ void optimize(void)
18121872 while (sccp_changed && sccp_iterations < 5 ) {
18131873 sccp_changed = false;
18141874 for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
1875+ /* Skip function declarations without bodies */
1876+ if (!func -> bbs )
1877+ continue ;
1878+
18151879 if (simple_sccp (func ))
18161880 sccp_changed = true;
18171881 }
18181882 sccp_iterations ++ ;
18191883 }
18201884
18211885 /* Run constant cast optimization for truncation */
1822- for (func_t * func = FUNC_LIST .head ; func ; func = func -> next )
1886+ for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
1887+ /* Skip function declarations without bodies */
1888+ if (!func -> bbs )
1889+ continue ;
1890+
18231891 optimize_constant_casts (func );
1892+ }
18241893
18251894 for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
1895+ /* Skip function declarations without bodies */
1896+ if (!func -> bbs )
1897+ continue ;
1898+
18261899 /* basic block level (control flow) optimizations */
18271900
18281901 for (basic_block_t * bb = func -> bbs ; bb ; bb = bb -> rpo_next ) {
@@ -2190,6 +2263,10 @@ void optimize(void)
21902263
21912264 /* Phi node optimization - eliminate trivial phi nodes */
21922265 for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
2266+ /* Skip function declarations without bodies */
2267+ if (!func -> bbs )
2268+ continue ;
2269+
21932270 for (basic_block_t * bb = func -> bbs ; bb ; bb = bb -> rpo_next ) {
21942271 for (insn_t * insn = bb -> insn_list .head ; insn ; insn = insn -> next ) {
21952272 if (insn -> opcode == OP_phi && insn -> phi_ops ) {
@@ -2242,6 +2319,10 @@ void optimize(void)
22422319
22432320 /* Mark useful instructions */
22442321 for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
2322+ /* Skip function declarations without bodies */
2323+ if (!func -> bbs )
2324+ continue ;
2325+
22452326 for (basic_block_t * bb = func -> bbs ; bb ; bb = bb -> rpo_next ) {
22462327 dce_insn (bb );
22472328 }
@@ -2286,6 +2367,10 @@ void build_reversed_rpo(void)
22862367{
22872368 bb_traversal_args_t * args = arena_alloc_traversal_args ();
22882369 for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
2370+ /* Skip function declarations without bodies */
2371+ if (!func -> bbs )
2372+ continue ;
2373+
22892374 func -> bb_cnt = 0 ;
22902375 args -> func = func ;
22912376 args -> bb = func -> exit ;
@@ -2521,6 +2606,10 @@ void liveness_analysis(void)
25212606{
25222607 bb_traversal_args_t * args = arena_alloc_traversal_args ();
25232608 for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
2609+ /* Skip function declarations without bodies */
2610+ if (!func -> bbs )
2611+ continue ;
2612+
25242613 args -> func = func ;
25252614 args -> bb = func -> bbs ;
25262615
@@ -2535,6 +2624,10 @@ void liveness_analysis(void)
25352624 }
25362625
25372626 for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
2627+ /* Skip function declarations without bodies */
2628+ if (!func -> bbs )
2629+ continue ;
2630+
25382631 basic_block_t * bb = func -> exit ;
25392632 bool changed ;
25402633 do {
0 commit comments