]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/lcm.c
* basic-block.h (compute_available): Returns a void now.
[thirdparty/gcc.git] / gcc / lcm.c
1 /* Generic partial redundancy elimination with lazy code motion
2 support.
3 Copyright (C) 1998 Free Software Foundation, Inc.
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22 /* These routines are meant to be used by various optimization
23 passes which can be modeled as lazy code motion problems.
24 Including, but not limited to:
25
26 * Traditional partial redundancy elimination.
27
28 * Placement of caller/caller register save/restores.
29
30 * Load/store motion.
31
32 * Copy motion.
33
34 * Conversion of flat register files to a stacked register
35 model.
36
37 * Dead load/store elimination.
38
39 These routines accept as input:
40
41 * Basic block information (number of blocks, lists of
42 predecessors and successors). Note the granularity
43 does not need to be basic block, they could be statements
44 or functions.
45
46 * Bitmaps of local properties (computed, transparent and
47 anticipatable expressions).
48
49 The output of these routines is bitmap of redundant computations
50 and a bitmap of optimal placement points. */
51
52
53 #include "config.h"
54 #include "system.h"
55
56 #include "rtl.h"
57 #include "regs.h"
58 #include "hard-reg-set.h"
59 #include "flags.h"
60 #include "real.h"
61 #include "insn-config.h"
62 #include "recog.h"
63 #include "basic-block.h"
64
65 /* Edge based LCM routines. */
66 static void compute_antinout_edge PROTO ((sbitmap *, sbitmap *,
67 sbitmap *, sbitmap *));
68 static void compute_earliest PROTO((struct edge_list *, int, sbitmap *,
69 sbitmap *, sbitmap *, sbitmap *,
70 sbitmap *));
71 static void compute_laterin PROTO((struct edge_list *, sbitmap *,
72 sbitmap *, sbitmap *, sbitmap *));
73 static void compute_insert_delete PROTO ((struct edge_list *edge_list,
74 sbitmap *, sbitmap *, sbitmap *,
75 sbitmap *, sbitmap *));
76
77 /* Edge based LCM routines on a reverse flowgraph. */
78 static void compute_farthest PROTO ((struct edge_list *, int, sbitmap *,
79 sbitmap *, sbitmap*, sbitmap *,
80 sbitmap *));
81 static void compute_nearerout PROTO((struct edge_list *, sbitmap *,
82 sbitmap *, sbitmap *, sbitmap *));
83 static void compute_rev_insert_delete PROTO ((struct edge_list *edge_list,
84 sbitmap *, sbitmap *, sbitmap *,
85 sbitmap *, sbitmap *));
86
87 \f
88 /* Edge based lcm routines. */
89
90 /* Compute expression anticipatability at entrance and exit of each block.
91 This is done based on the flow graph, and not on the pred-succ lists.
92 Other than that, its pretty much identical to compute_antinout. */
93
94 static void
95 compute_antinout_edge (antloc, transp, antin, antout)
96 sbitmap *antloc;
97 sbitmap *transp;
98 sbitmap *antin;
99 sbitmap *antout;
100 {
101 int bb;
102 edge e;
103 basic_block *worklist, *tos;
104
105 /* Allocate a worklist array/queue. Entries are only added to the
106 list if they were not already on the list. So the size is
107 bounded by the number of basic blocks. */
108 tos = worklist = (basic_block *) xmalloc (sizeof (basic_block)
109 * n_basic_blocks);
110
111 /* We want a maximal solution, so make an optimistic initialization of
112 ANTIN. */
113 sbitmap_vector_ones (antin, n_basic_blocks);
114
115 /* Put the predecessors of the exit block on the worklist. */
116 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
117 {
118 *tos++ = e->src;
119
120 /* We use the block's aux field to track blocks which are in
121 the worklist; we also use it to quickly determine which blocks
122 are predecessors of the EXIT block. */
123 e->src->aux = EXIT_BLOCK_PTR;
124 }
125
126 /* Iterate until the worklist is empty. */
127 while (tos != worklist)
128 {
129 /* Take the first entry off the worklist. */
130 basic_block b = *--tos;
131 bb = b->index;
132
133 if (b->aux == EXIT_BLOCK_PTR)
134 {
135 /* Do not clear the aux field for blocks which are
136 predecessors of the EXIT block. That way we never
137 add then to the worklist again. */
138 sbitmap_zero (antout[bb]);
139 }
140 else
141 {
142 /* Clear the aux field of this block so that it can be added to
143 the worklist again if necessary. */
144 b->aux = NULL;
145 sbitmap_intersection_of_succs (antout[bb], antin, bb);
146 }
147
148 if (sbitmap_a_or_b_and_c (antin[bb], antloc[bb], transp[bb], antout[bb]))
149 {
150 /* If the in state of this block changed, then we need
151 to add the predecessors of this block to the worklist
152 if they are not already on the worklist. */
153 for (e = b->pred; e; e = e->pred_next)
154 {
155 if (!e->src->aux && e->src != ENTRY_BLOCK_PTR)
156 {
157 *tos++ = e->src;
158 e->src->aux = e;
159 }
160 }
161 }
162 }
163 free (tos);
164 }
165
166 /* Compute the earliest vector for edge based lcm. */
167 static void
168 compute_earliest (edge_list, n_exprs, antin, antout, avout, kill, earliest)
169 struct edge_list *edge_list;
170 int n_exprs;
171 sbitmap *antin, *antout, *avout, *kill, *earliest;
172 {
173 sbitmap difference, temp_bitmap;
174 int x, num_edges;
175 basic_block pred, succ;
176
177 num_edges = NUM_EDGES (edge_list);
178
179 difference = sbitmap_alloc (n_exprs);
180 temp_bitmap = sbitmap_alloc (n_exprs);
181
182 for (x = 0; x < num_edges; x++)
183 {
184 pred = INDEX_EDGE_PRED_BB (edge_list, x);
185 succ = INDEX_EDGE_SUCC_BB (edge_list, x);
186 if (pred == ENTRY_BLOCK_PTR)
187 sbitmap_copy (earliest[x], antin[succ->index]);
188 else
189 {
190 if (succ == EXIT_BLOCK_PTR)
191 {
192 sbitmap_zero (earliest[x]);
193 }
194 else
195 {
196 sbitmap_difference (difference, antin[succ->index],
197 avout[pred->index]);
198 sbitmap_not (temp_bitmap, antout[pred->index]);
199 sbitmap_a_and_b_or_c (earliest[x], difference, kill[pred->index],
200 temp_bitmap);
201 }
202 }
203 }
204 free (temp_bitmap);
205 free (difference);
206 }
207
208 /* later(p,s) is dependent on the calculation of laterin(p).
209 laterin(p) is dependent on the calculation of later(p2,p).
210
211 laterin(ENTRY) is defined as all 0's
212 later(ENTRY, succs(ENTRY)) are defined using laterin(ENTRY)
213 laterin(succs(ENTRY)) is defined by later(ENTRY, succs(ENTRY)).
214
215 If we progress in this manner, starting with all basic blocks
216 in the work list, anytime we change later(bb), we need to add
217 succs(bb) to the worklist if they are not already on the worklist.
218
219 Boundary conditions:
220
221 We prime the worklist all the normal basic blocks. The ENTRY block can
222 never be added to the worklist since it is never the successor of any
223 block. We explicitly prevent the EXIT block from being added to the
224 worklist.
225
226 We optimistically initialize LATER. That is the only time this routine
227 will compute LATER for an edge out of the entry block since the entry
228 block is never on the worklist. Thus, LATERIN is neither used nor
229 computed for the ENTRY block.
230
231 Since the EXIT block is never added to the worklist, we will neither
232 use nor compute LATERIN for the exit block. Edges which reach the
233 EXIT block are handled in the normal fashion inside the loop. However,
234 the insertion/deletion computation needs LATERIN(EXIT), so we have
235 to compute it. */
236
237 static void
238 compute_laterin (edge_list, earliest, antloc, later, laterin)
239 struct edge_list *edge_list;
240 sbitmap *earliest, *antloc, *later, *laterin;
241 {
242 int bb, num_edges, i;
243 edge e;
244 basic_block *worklist, *tos;
245
246 num_edges = NUM_EDGES (edge_list);
247
248 /* Allocate a worklist array/queue. Entries are only added to the
249 list if they were not already on the list. So the size is
250 bounded by the number of basic blocks. */
251 tos = worklist = (basic_block *) xmalloc (sizeof (basic_block)
252 * (n_basic_blocks + 1));
253
254 /* Initialize a mapping from each edge to its index. */
255 for (i = 0; i < num_edges; i++)
256 INDEX_EDGE (edge_list, i)->aux = (void *)i;
257
258 /* We want a maximal solution, so initially consider LATER true for
259 all edges. This allows propagation through a loop since the incoming
260 loop edge will have LATER set, so if all the other incoming edges
261 to the loop are set, then LATERIN will be set for the head of the
262 loop.
263
264 If the optimistic setting of LATER on that edge was incorrect (for
265 example the expression is ANTLOC in a block within the loop) then
266 this algorithm will detect it when we process the block at the head
267 of the optimistic edge. That will requeue the affected blocks. */
268 sbitmap_vector_ones (later, num_edges);
269
270 /* Add all the blocks to the worklist. This prevents an early exit from
271 the loop given our optimistic initialization of LATER above. */
272 for (bb = n_basic_blocks - 1; bb >= 0; bb--)
273 {
274 basic_block b = BASIC_BLOCK (bb);
275 *tos++ = b;
276 b->aux = b;
277 }
278
279 /* Iterate until the worklist is empty. */
280 while (tos != worklist)
281 {
282 /* Take the first entry off the worklist. */
283 basic_block b = *--tos;
284 b->aux = NULL;
285
286 /* Compute the intersection of LATERIN for each incoming edge to B. */
287 bb = b->index;
288 sbitmap_ones (laterin[bb]);
289 for (e = b->pred; e != NULL; e = e->pred_next)
290 sbitmap_a_and_b (laterin[bb], laterin[bb], later[(int)e->aux]);
291
292 /* Calculate LATER for all outgoing edges. */
293 for (e = b->succ; e != NULL; e = e->succ_next)
294 {
295 if (sbitmap_union_of_diff (later[(int)e->aux],
296 earliest[(int)e->aux],
297 laterin[e->src->index],
298 antloc[e->src->index]))
299 {
300 /* If LATER for an outgoing edge was changed, then we need
301 to add the target of the outgoing edge to the worklist. */
302 if (e->dest != EXIT_BLOCK_PTR && e->dest->aux == 0)
303 {
304 *tos++ = e->dest;
305 e->dest->aux = e;
306 }
307 }
308 }
309 }
310
311 /* Computation of insertion and deletion points requires computing LATERIN
312 for the EXIT block. We allocated an extra entry in the LATERIN array
313 for just this purpose. */
314 sbitmap_ones (laterin[n_basic_blocks]);
315 for (e = EXIT_BLOCK_PTR->pred; e != NULL; e = e->pred_next)
316 sbitmap_a_and_b (laterin[n_basic_blocks],
317 laterin[n_basic_blocks],
318 later[(int)e->aux]);
319
320 free (tos);
321 }
322
323 /* Compute the insertion and deletion points for edge based LCM. */
324 static void
325 compute_insert_delete (edge_list, antloc, later, laterin,
326 insert, delete)
327 struct edge_list *edge_list;
328 sbitmap *antloc, *later, *laterin, *insert, *delete;
329 {
330 int x;
331
332 for (x = 0; x < n_basic_blocks; x++)
333 sbitmap_difference (delete[x], antloc[x], laterin[x]);
334
335 for (x = 0; x < NUM_EDGES (edge_list); x++)
336 {
337 basic_block b = INDEX_EDGE_SUCC_BB (edge_list, x);
338 if (b == EXIT_BLOCK_PTR)
339 sbitmap_difference (insert[x], later[x], laterin[n_basic_blocks]);
340 else
341 sbitmap_difference (insert[x], later[x], laterin[b->index]);
342 }
343 }
344
345 /* Given local properties TRANSP, ANTLOC, AVOUT, KILL return the
346 insert and delete vectors for edge based LCM. Returns an
347 edgelist which is used to map the insert vector to what edge
348 an expression should be inserted on. */
349
350 struct edge_list *
351 pre_edge_lcm (file, n_exprs, transp, avloc, antloc, kill, insert, delete)
352 FILE *file ATTRIBUTE_UNUSED;
353 int n_exprs;
354 sbitmap *transp;
355 sbitmap *avloc;
356 sbitmap *antloc;
357 sbitmap *kill;
358 sbitmap **insert;
359 sbitmap **delete;
360 {
361 sbitmap *antin, *antout, *earliest;
362 sbitmap *avin, *avout;
363 sbitmap *later, *laterin;
364 struct edge_list *edge_list;
365 int num_edges;
366
367 edge_list = create_edge_list ();
368 num_edges = NUM_EDGES (edge_list);
369
370 #ifdef LCM_DEBUG_INFO
371 if (file)
372 {
373 fprintf (file, "Edge List:\n");
374 verify_edge_list (file, edge_list);
375 print_edge_list (file, edge_list);
376 dump_sbitmap_vector (file, "transp", "", transp, n_basic_blocks);
377 dump_sbitmap_vector (file, "antloc", "", antloc, n_basic_blocks);
378 dump_sbitmap_vector (file, "avloc", "", avloc, n_basic_blocks);
379 dump_sbitmap_vector (file, "kill", "", kill, n_basic_blocks);
380 }
381 #endif
382
383 /* Compute global availability. */
384 avin = sbitmap_vector_alloc (n_basic_blocks, n_exprs);
385 avout = sbitmap_vector_alloc (n_basic_blocks, n_exprs);
386 compute_available (avloc, kill, avout, avin);
387
388
389 free (avin);
390
391 /* Compute global anticipatability. */
392 antin = sbitmap_vector_alloc (n_basic_blocks, n_exprs);
393 antout = sbitmap_vector_alloc (n_basic_blocks, n_exprs);
394 compute_antinout_edge (antloc, transp, antin, antout);
395
396 #ifdef LCM_DEBUG_INFO
397 if (file)
398 {
399 dump_sbitmap_vector (file, "antin", "", antin, n_basic_blocks);
400 dump_sbitmap_vector (file, "antout", "", antout, n_basic_blocks);
401 }
402 #endif
403
404 /* Compute earliestness. */
405 earliest = sbitmap_vector_alloc (num_edges, n_exprs);
406 compute_earliest (edge_list, n_exprs, antin, antout, avout, kill, earliest);
407
408 #ifdef LCM_DEBUG_INFO
409 if (file)
410 dump_sbitmap_vector (file, "earliest", "", earliest, num_edges);
411 #endif
412
413 free (antout);
414 free (antin);
415 free (avout);
416
417 later = sbitmap_vector_alloc (num_edges, n_exprs);
418 /* Allocate an extra element for the exit block in the laterin vector. */
419 laterin = sbitmap_vector_alloc (n_basic_blocks + 1, n_exprs);
420 compute_laterin (edge_list, earliest, antloc, later, laterin);
421
422
423 #ifdef LCM_DEBUG_INFO
424 if (file)
425 {
426 dump_sbitmap_vector (file, "laterin", "", laterin, n_basic_blocks + 1);
427 dump_sbitmap_vector (file, "later", "", later, num_edges);
428 }
429 #endif
430
431 free (earliest);
432
433 *insert = sbitmap_vector_alloc (num_edges, n_exprs);
434 *delete = sbitmap_vector_alloc (n_basic_blocks, n_exprs);
435 compute_insert_delete (edge_list, antloc, later, laterin, *insert, *delete);
436
437 free (laterin);
438 free (later);
439
440 #ifdef LCM_DEBUG_INFO
441 if (file)
442 {
443 dump_sbitmap_vector (file, "pre_insert_map", "", *insert, num_edges);
444 dump_sbitmap_vector (file, "pre_delete_map", "", *delete, n_basic_blocks);
445 }
446 #endif
447
448 return edge_list;
449 }
450
451 /* Compute the AVIN and AVOUT vectors from the AVLOC and KILL vectors.
452 Return the number of passes we performed to iterate to a solution. */
453 void
454 compute_available (avloc, kill, avout, avin)
455 sbitmap *avloc, *kill, *avout, *avin;
456 {
457 int bb;
458 edge e;
459 basic_block *worklist, *tos;
460
461 /* Allocate a worklist array/queue. Entries are only added to the
462 list if they were not already on the list. So the size is
463 bounded by the number of basic blocks. */
464 tos = worklist = (basic_block *) xmalloc (sizeof (basic_block)
465 * n_basic_blocks);
466
467 /* We want a maximal solution. */
468 sbitmap_vector_ones (avout, n_basic_blocks);
469
470 /* Put the successors of the entry block on the worklist. */
471 for (e = ENTRY_BLOCK_PTR->succ; e; e = e->succ_next)
472 {
473 *tos++ = e->dest;
474
475 /* We use the block's aux field to track blocks which are in
476 the worklist; we also use it to quickly determine which blocks
477 are successors of the ENTRY block. */
478 e->dest->aux = ENTRY_BLOCK_PTR;
479 }
480
481 /* Iterate until the worklist is empty. */
482 while (tos != worklist)
483 {
484 /* Take the first entry off the worklist. */
485 basic_block b = *--tos;
486 bb = b->index;
487
488 /* If one of the predecessor blocks is the ENTRY block, then the
489 intersection of avouts is the null set. We can identify such blocks
490 by the special value in the AUX field in the block structure. */
491 if (b->aux == ENTRY_BLOCK_PTR)
492 {
493 /* Do not clear the aux field for blocks which are
494 successors of the ENTRY block. That way we never
495 add then to the worklist again. */
496 sbitmap_zero (avin[bb]);
497 }
498 else
499 {
500 /* Clear the aux field of this block so that it can be added to
501 the worklist again if necessary. */
502 b->aux = NULL;
503 sbitmap_intersection_of_preds (avin[bb], avout, bb);
504 }
505
506 if (sbitmap_union_of_diff (avout[bb], avloc[bb], avin[bb], kill[bb]))
507 {
508 /* If the out state of this block changed, then we need
509 to add the successors of this block to the worklist
510 if they are not already on the worklist. */
511 for (e = b->succ; e; e = e->succ_next)
512 {
513 if (!e->dest->aux && e->dest != EXIT_BLOCK_PTR)
514 {
515 *tos++ = e->dest;
516 e->dest->aux = e;
517 }
518 }
519 }
520 }
521 free (tos);
522 }
523
524 /* Compute the farthest vector for edge based lcm. */
525 static void
526 compute_farthest (edge_list, n_exprs, st_avout, st_avin, st_antin,
527 kill, farthest)
528 struct edge_list *edge_list;
529 int n_exprs;
530 sbitmap *st_avout, *st_avin, *st_antin, *kill, *farthest;
531 {
532 sbitmap difference, temp_bitmap;
533 int x, num_edges;
534 basic_block pred, succ;
535
536 num_edges = NUM_EDGES (edge_list);
537
538 difference = sbitmap_alloc (n_exprs);
539 temp_bitmap = sbitmap_alloc (n_exprs);
540
541 for (x = 0; x < num_edges; x++)
542 {
543 pred = INDEX_EDGE_PRED_BB (edge_list, x);
544 succ = INDEX_EDGE_SUCC_BB (edge_list, x);
545 if (succ == EXIT_BLOCK_PTR)
546 sbitmap_copy (farthest[x], st_avout[pred->index]);
547 else
548 {
549 if (pred == ENTRY_BLOCK_PTR)
550 {
551 sbitmap_zero (farthest[x]);
552 }
553 else
554 {
555 sbitmap_difference (difference, st_avout[pred->index],
556 st_antin[succ->index]);
557 sbitmap_not (temp_bitmap, st_avin[succ->index]);
558 sbitmap_a_and_b_or_c (farthest[x], difference,
559 kill[succ->index], temp_bitmap);
560 }
561 }
562 }
563 free (temp_bitmap);
564 free (difference);
565 }
566
567 /* Compute nearer and nearerout vectors for edge based lcm.
568
569 This is the mirror of compute_laterin, additional comments on the
570 implementation can be found before compute_laterin. */
571
572 static void
573 compute_nearerout (edge_list, farthest, st_avloc, nearer, nearerout)
574 struct edge_list *edge_list;
575 sbitmap *farthest, *st_avloc, *nearer, *nearerout;
576 {
577 int bb, num_edges, i;
578 edge e;
579 basic_block *worklist, *tos;
580
581 num_edges = NUM_EDGES (edge_list);
582
583 /* Allocate a worklist array/queue. Entries are only added to the
584 list if they were not already on the list. So the size is
585 bounded by the number of basic blocks. */
586 tos = worklist = (basic_block *) xmalloc (sizeof (basic_block)
587 * (n_basic_blocks + 1));
588
589 /* Initialize NEARER for each edge and build a mapping from an edge to
590 its index. */
591 for (i = 0; i < num_edges; i++)
592 INDEX_EDGE (edge_list, i)->aux = (void *)i;
593
594 /* We want a maximal solution. */
595 sbitmap_vector_ones (nearer, num_edges);
596
597 /* Add all the blocks to the worklist. This prevents an early exit
598 from the loop given our optimistic initialization of NEARER. */
599 for (bb = 0; bb < n_basic_blocks; bb++)
600 {
601 basic_block b = BASIC_BLOCK (bb);
602 *tos++ = b;
603 b->aux = b;
604 }
605
606 /* Iterate until the worklist is empty. */
607 while (tos != worklist)
608 {
609 /* Take the first entry off the worklist. */
610 basic_block b = *--tos;
611 b->aux = NULL;
612
613 /* Compute the intersection of NEARER for each outgoing edge from B. */
614 bb = b->index;
615 sbitmap_ones (nearerout[bb]);
616 for (e = b->succ; e != NULL; e = e->succ_next)
617 sbitmap_a_and_b (nearerout[bb], nearerout[bb], nearer[(int)e->aux]);
618
619 /* Calculate NEARER for all incoming edges. */
620 for (e = b->pred; e != NULL; e = e->pred_next)
621 {
622 if (sbitmap_union_of_diff (nearer[(int)e->aux],
623 farthest[(int)e->aux],
624 nearerout[e->dest->index],
625 st_avloc[e->dest->index]))
626 {
627 /* If NEARER for an incoming edge was changed, then we need
628 to add the source of the incoming edge to the worklist. */
629 if (e->src != ENTRY_BLOCK_PTR && e->src->aux == 0)
630 {
631 *tos++ = e->src;
632 e->src->aux = e;
633 }
634 }
635 }
636 }
637
638 /* Computation of insertion and deletion points requires computing NEAREROUT
639 for the ENTRY block. We allocated an extra entry in the NEAREROUT array
640 for just this purpose. */
641 sbitmap_ones (nearerout[n_basic_blocks]);
642 for (e = ENTRY_BLOCK_PTR->succ; e != NULL; e = e->succ_next)
643 sbitmap_a_and_b (nearerout[n_basic_blocks],
644 nearerout[n_basic_blocks],
645 nearer[(int)e->aux]);
646
647 free (tos);
648 }
649
650 /* Compute the insertion and deletion points for edge based LCM. */
651 static void
652 compute_rev_insert_delete (edge_list, st_avloc, nearer, nearerout,
653 insert, delete)
654 struct edge_list *edge_list;
655 sbitmap *st_avloc, *nearer, *nearerout, *insert, *delete;
656 {
657 int x;
658
659 for (x = 0; x < n_basic_blocks; x++)
660 sbitmap_difference (delete[x], st_avloc[x], nearerout[x]);
661
662 for (x = 0; x < NUM_EDGES (edge_list); x++)
663 {
664 basic_block b = INDEX_EDGE_PRED_BB (edge_list, x);
665 if (b == ENTRY_BLOCK_PTR)
666 sbitmap_difference (insert[x], nearer[x], nearerout[n_basic_blocks]);
667 else
668 sbitmap_difference (insert[x], nearer[x], nearerout[b->index]);
669 }
670 }
671
672 /* Given local properties TRANSP, ST_AVLOC, ST_ANTLOC, KILL return the
673 insert and delete vectors for edge based reverse LCM. Returns an
674 edgelist which is used to map the insert vector to what edge
675 an expression should be inserted on. */
676
677 struct edge_list *
678 pre_edge_rev_lcm (file, n_exprs, transp, st_avloc, st_antloc, kill,
679 insert, delete)
680 FILE *file ATTRIBUTE_UNUSED;
681 int n_exprs;
682 sbitmap *transp;
683 sbitmap *st_avloc;
684 sbitmap *st_antloc;
685 sbitmap *kill;
686 sbitmap **insert;
687 sbitmap **delete;
688 {
689 sbitmap *st_antin, *st_antout;
690 sbitmap *st_avout, *st_avin, *farthest;
691 sbitmap *nearer, *nearerout;
692 struct edge_list *edge_list;
693 int num_edges;
694
695 edge_list = create_edge_list ();
696 num_edges = NUM_EDGES (edge_list);
697
698 st_antin = (sbitmap *) sbitmap_vector_alloc (n_basic_blocks, n_exprs);
699 st_antout = (sbitmap *) sbitmap_vector_alloc (n_basic_blocks, n_exprs);
700 sbitmap_vector_zero (st_antin, n_basic_blocks);
701 sbitmap_vector_zero (st_antout, n_basic_blocks);
702 compute_antinout_edge (st_antloc, transp, st_antin, st_antout);
703
704 /* Compute global anticipatability. */
705 st_avout = sbitmap_vector_alloc (n_basic_blocks, n_exprs);
706 st_avin = sbitmap_vector_alloc (n_basic_blocks, n_exprs);
707 compute_available (st_avloc, kill, st_avout, st_avin);
708
709 #ifdef LCM_DEBUG_INFO
710 if (file)
711 {
712 fprintf (file, "Edge List:\n");
713 verify_edge_list (file, edge_list);
714 print_edge_list (file, edge_list);
715 dump_sbitmap_vector (file, "transp", "", transp, n_basic_blocks);
716 dump_sbitmap_vector (file, "st_avloc", "", st_avloc, n_basic_blocks);
717 dump_sbitmap_vector (file, "st_antloc", "", st_antloc, n_basic_blocks);
718 dump_sbitmap_vector (file, "st_antin", "", st_antin, n_basic_blocks);
719 dump_sbitmap_vector (file, "st_antout", "", st_antout, n_basic_blocks);
720 dump_sbitmap_vector (file, "st_kill", "", kill, n_basic_blocks);
721 }
722 #endif
723
724 #ifdef LCM_DEBUG_INFO
725 if (file)
726 {
727 dump_sbitmap_vector (file, "st_avout", "", st_avout, n_basic_blocks);
728 dump_sbitmap_vector (file, "st_avin", "", st_avin, n_basic_blocks);
729 }
730 #endif
731
732 /* Compute farthestness. */
733 farthest = sbitmap_vector_alloc (num_edges, n_exprs);
734 compute_farthest (edge_list, n_exprs, st_avout, st_avin, st_antin,
735 kill, farthest);
736
737 #ifdef LCM_DEBUG_INFO
738 if (file)
739 dump_sbitmap_vector (file, "farthest", "", farthest, num_edges);
740 #endif
741
742 free (st_avin);
743 free (st_avout);
744
745 nearer = sbitmap_vector_alloc (num_edges, n_exprs);
746 /* Allocate an extra element for the entry block. */
747 nearerout = sbitmap_vector_alloc (n_basic_blocks + 1, n_exprs);
748 compute_nearerout (edge_list, farthest, st_avloc, nearer, nearerout);
749
750 #ifdef LCM_DEBUG_INFO
751 if (file)
752 {
753 dump_sbitmap_vector (file, "nearerout", "", nearerout,
754 n_basic_blocks + 1);
755 dump_sbitmap_vector (file, "nearer", "", nearer, num_edges);
756 }
757 #endif
758
759 free (farthest);
760
761 *insert = sbitmap_vector_alloc (num_edges, n_exprs);
762 *delete = sbitmap_vector_alloc (n_basic_blocks, n_exprs);
763 compute_rev_insert_delete (edge_list, st_avloc, nearer, nearerout, *insert, *delete);
764
765 free (nearerout);
766 free (nearer);
767
768 #ifdef LCM_DEBUG_INFO
769 if (file)
770 {
771 dump_sbitmap_vector (file, "pre_insert_map", "", *insert, num_edges);
772 dump_sbitmap_vector (file, "pre_delete_map", "", *delete, n_basic_blocks);
773 }
774 #endif
775
776 return edge_list;
777 }