@@ -116,6 +116,10 @@ void build_rpo(void)
116
116
{
117
117
bb_traversal_args_t * args = arena_alloc_traversal_args ();
118
118
for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
119
+ /* Skip function declarations without bodies */
120
+ if (!func -> bbs )
121
+ continue ;
122
+
119
123
args -> func = func ;
120
124
args -> bb = func -> bbs ;
121
125
@@ -158,6 +162,10 @@ basic_block_t *intersect(basic_block_t *i, basic_block_t *j)
158
162
void build_idom (void )
159
163
{
160
164
for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
165
+ /* Skip function declarations without bodies */
166
+ if (!func -> bbs )
167
+ continue ;
168
+
161
169
bool changed ;
162
170
163
171
func -> bbs -> idom = func -> bbs ;
@@ -230,6 +238,10 @@ void build_dom(void)
230
238
{
231
239
bb_traversal_args_t * args = arena_alloc_traversal_args ();
232
240
for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
241
+ /* Skip function declarations without bodies */
242
+ if (!func -> bbs )
243
+ continue ;
244
+
233
245
args -> func = func ;
234
246
args -> bb = func -> bbs ;
235
247
@@ -264,6 +276,10 @@ void build_df(void)
264
276
{
265
277
bb_traversal_args_t * args = arena_alloc_traversal_args ();
266
278
for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
279
+ /* Skip function declarations without bodies */
280
+ if (!func -> bbs )
281
+ continue ;
282
+
267
283
args -> func = func ;
268
284
args -> bb = func -> bbs ;
269
285
@@ -287,6 +303,10 @@ basic_block_t *reverse_intersect(basic_block_t *i, basic_block_t *j)
287
303
void build_r_idom (void )
288
304
{
289
305
for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
306
+ /* Skip function declarations without bodies */
307
+ if (!func -> bbs )
308
+ continue ;
309
+
290
310
bool changed ;
291
311
292
312
func -> exit -> r_idom = func -> exit ;
@@ -354,6 +374,10 @@ void build_rdom(void)
354
374
{
355
375
bb_traversal_args_t * args = arena_alloc_traversal_args ();
356
376
for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
377
+ /* Skip function declarations without bodies */
378
+ if (!func -> bbs )
379
+ continue ;
380
+
357
381
args -> func = func ;
358
382
args -> bb = func -> exit ;
359
383
@@ -398,6 +422,10 @@ void build_rdf(void)
398
422
{
399
423
bb_traversal_args_t * args = arena_alloc_traversal_args ();
400
424
for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
425
+ /* Skip function declarations without bodies */
426
+ if (!func -> bbs )
427
+ continue ;
428
+
401
429
args -> func = func ;
402
430
args -> bb = func -> exit ;
403
431
@@ -439,6 +467,10 @@ void use_chain_delete(use_chain_t *u, var_t *var)
439
467
void use_chain_build (void )
440
468
{
441
469
for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
470
+ /* Skip function declarations without bodies */
471
+ if (!func -> bbs )
472
+ continue ;
473
+
442
474
for (basic_block_t * bb = func -> bbs ; bb ; bb = bb -> rpo_next ) {
443
475
for (insn_t * i = bb -> insn_list .head ; i ; i = i -> next ) {
444
476
if (i -> rs1 )
@@ -545,6 +577,10 @@ void solve_globals(void)
545
577
{
546
578
bb_traversal_args_t * args = arena_alloc_traversal_args ();
547
579
for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
580
+ /* Skip function declarations without bodies */
581
+ if (!func -> bbs )
582
+ continue ;
583
+
548
584
args -> func = func ;
549
585
args -> bb = func -> bbs ;
550
586
@@ -606,6 +642,10 @@ bool insert_phi_insn(basic_block_t *bb, var_t *var)
606
642
void solve_phi_insertion (void )
607
643
{
608
644
for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
645
+ /* Skip function declarations without bodies */
646
+ if (!func -> bbs )
647
+ continue ;
648
+
609
649
for (symbol_t * sym = func -> global_sym_list .head ; sym ; sym = sym -> next ) {
610
650
var_t * var = sym -> var ;
611
651
@@ -798,6 +838,10 @@ void bb_solve_phi_params(basic_block_t *bb)
798
838
void solve_phi_params (void )
799
839
{
800
840
for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
841
+ /* Skip function declarations without bodies */
842
+ if (!func -> bbs )
843
+ continue ;
844
+
801
845
for (int i = 0 ; i < func -> num_params ; i ++ ) {
802
846
/* FIXME: Direct argument renaming in SSA construction phase may
803
847
* interfere with later optimization passes
@@ -874,6 +918,10 @@ void unwind_phi(void)
874
918
{
875
919
bb_traversal_args_t * args = arena_alloc_traversal_args ();
876
920
for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
921
+ /* Skip function declarations without bodies */
922
+ if (!func -> bbs )
923
+ continue ;
924
+
877
925
args -> func = func ;
878
926
args -> bb = func -> bbs ;
879
927
@@ -1135,7 +1183,7 @@ void bb_dump(FILE *fd, func_t *func, basic_block_t *bb)
1135
1183
break ;
1136
1184
case OP_sign_ext :
1137
1185
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>" ,
1139
1187
insn -> rd -> var_name , insn -> rd -> subscript ,
1140
1188
insn -> rs1 -> var_name , insn -> rs1 -> subscript , insn -> sz );
1141
1189
break ;
@@ -1180,6 +1228,10 @@ void dump_cfg(char name[])
1180
1228
fprintf (fd , "strict digraph CFG {\n" );
1181
1229
fprintf (fd , "node [shape=box]\n" );
1182
1230
for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
1231
+ /* Skip function declarations without bodies */
1232
+ if (!func -> bbs )
1233
+ continue ;
1234
+
1183
1235
func -> visited ++ ;
1184
1236
fprintf (fd , "subgraph cluster_%p {\n" , func );
1185
1237
fprintf (fd , "label=\"%p (%s)\"\n" , func , func -> return_def .var_name );
@@ -1209,6 +1261,10 @@ void dump_dom(char name[])
1209
1261
fprintf (fd , "node [shape=box]\n" );
1210
1262
fprintf (fd , "splines=polyline\n" );
1211
1263
for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
1264
+ /* Skip function declarations without bodies */
1265
+ if (!func -> bbs )
1266
+ continue ;
1267
+
1212
1268
fprintf (fd , "subgraph cluster_%p {\n" , func );
1213
1269
fprintf (fd , "label=\"%p\"\n" , func );
1214
1270
dom_dump (fd , func -> bbs );
@@ -1740,6 +1796,10 @@ void dce_sweep(void)
1740
1796
int total_eliminated = 0 ; /* Track effectiveness */
1741
1797
1742
1798
for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
1799
+ /* Skip function declarations without bodies */
1800
+ if (!func -> bbs )
1801
+ continue ;
1802
+
1743
1803
for (basic_block_t * bb = func -> bbs ; bb ; bb = bb -> rpo_next ) {
1744
1804
/* Skip unreachable blocks entirely */
1745
1805
if (is_block_unreachable (bb )) {
@@ -1812,17 +1872,30 @@ void optimize(void)
1812
1872
while (sccp_changed && sccp_iterations < 5 ) {
1813
1873
sccp_changed = false;
1814
1874
for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
1875
+ /* Skip function declarations without bodies */
1876
+ if (!func -> bbs )
1877
+ continue ;
1878
+
1815
1879
if (simple_sccp (func ))
1816
1880
sccp_changed = true;
1817
1881
}
1818
1882
sccp_iterations ++ ;
1819
1883
}
1820
1884
1821
1885
/* 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
+
1823
1891
optimize_constant_casts (func );
1892
+ }
1824
1893
1825
1894
for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
1895
+ /* Skip function declarations without bodies */
1896
+ if (!func -> bbs )
1897
+ continue ;
1898
+
1826
1899
/* basic block level (control flow) optimizations */
1827
1900
1828
1901
for (basic_block_t * bb = func -> bbs ; bb ; bb = bb -> rpo_next ) {
@@ -2190,6 +2263,10 @@ void optimize(void)
2190
2263
2191
2264
/* Phi node optimization - eliminate trivial phi nodes */
2192
2265
for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
2266
+ /* Skip function declarations without bodies */
2267
+ if (!func -> bbs )
2268
+ continue ;
2269
+
2193
2270
for (basic_block_t * bb = func -> bbs ; bb ; bb = bb -> rpo_next ) {
2194
2271
for (insn_t * insn = bb -> insn_list .head ; insn ; insn = insn -> next ) {
2195
2272
if (insn -> opcode == OP_phi && insn -> phi_ops ) {
@@ -2242,6 +2319,10 @@ void optimize(void)
2242
2319
2243
2320
/* Mark useful instructions */
2244
2321
for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
2322
+ /* Skip function declarations without bodies */
2323
+ if (!func -> bbs )
2324
+ continue ;
2325
+
2245
2326
for (basic_block_t * bb = func -> bbs ; bb ; bb = bb -> rpo_next ) {
2246
2327
dce_insn (bb );
2247
2328
}
@@ -2286,6 +2367,10 @@ void build_reversed_rpo(void)
2286
2367
{
2287
2368
bb_traversal_args_t * args = arena_alloc_traversal_args ();
2288
2369
for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
2370
+ /* Skip function declarations without bodies */
2371
+ if (!func -> bbs )
2372
+ continue ;
2373
+
2289
2374
func -> bb_cnt = 0 ;
2290
2375
args -> func = func ;
2291
2376
args -> bb = func -> exit ;
@@ -2521,6 +2606,10 @@ void liveness_analysis(void)
2521
2606
{
2522
2607
bb_traversal_args_t * args = arena_alloc_traversal_args ();
2523
2608
for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
2609
+ /* Skip function declarations without bodies */
2610
+ if (!func -> bbs )
2611
+ continue ;
2612
+
2524
2613
args -> func = func ;
2525
2614
args -> bb = func -> bbs ;
2526
2615
@@ -2535,6 +2624,10 @@ void liveness_analysis(void)
2535
2624
}
2536
2625
2537
2626
for (func_t * func = FUNC_LIST .head ; func ; func = func -> next ) {
2627
+ /* Skip function declarations without bodies */
2628
+ if (!func -> bbs )
2629
+ continue ;
2630
+
2538
2631
basic_block_t * bb = func -> exit ;
2539
2632
bool changed ;
2540
2633
do {
0 commit comments