Merge branch 'master' into python
[official-gcc.git] / gcc / lcm.c
blob619d2ab946f64a1191567beb31b094db26fe0e81
1 /* Generic partial redundancy elimination with lazy code motion support.
2 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 /* These routines are meant to be used by various optimization
22 passes which can be modeled as lazy code motion problems.
23 Including, but not limited to:
25 * Traditional partial redundancy elimination.
27 * Placement of caller/caller register save/restores.
29 * Load/store motion.
31 * Copy motion.
33 * Conversion of flat register files to a stacked register
34 model.
36 * Dead load/store elimination.
38 These routines accept as input:
40 * Basic block information (number of blocks, lists of
41 predecessors and successors). Note the granularity
42 does not need to be basic block, they could be statements
43 or functions.
45 * Bitmaps of local properties (computed, transparent and
46 anticipatable expressions).
48 The output of these routines is bitmap of redundant computations
49 and a bitmap of optimal placement points. */
52 #include "config.h"
53 #include "system.h"
54 #include "coretypes.h"
55 #include "tm.h"
56 #include "rtl.h"
57 #include "regs.h"
58 #include "hard-reg-set.h"
59 #include "flags.h"
60 #include "insn-config.h"
61 #include "recog.h"
62 #include "basic-block.h"
63 #include "output.h"
64 #include "tm_p.h"
65 #include "function.h"
66 #include "sbitmap.h"
68 /* We want target macros for the mode switching code to be able to refer
69 to instruction attribute values. */
70 #include "insn-attr.h"
72 /* Edge based LCM routines. */
73 static void compute_antinout_edge (sbitmap *, sbitmap *, sbitmap *, sbitmap *);
74 static void compute_earliest (struct edge_list *, int, sbitmap *, sbitmap *,
75 sbitmap *, sbitmap *, sbitmap *);
76 static void compute_laterin (struct edge_list *, sbitmap *, sbitmap *,
77 sbitmap *, sbitmap *);
78 static void compute_insert_delete (struct edge_list *edge_list, sbitmap *,
79 sbitmap *, sbitmap *, sbitmap *, sbitmap *);
81 /* Edge based LCM routines on a reverse flowgraph. */
82 static void compute_farthest (struct edge_list *, int, sbitmap *, sbitmap *,
83 sbitmap*, sbitmap *, sbitmap *);
84 static void compute_nearerout (struct edge_list *, sbitmap *, sbitmap *,
85 sbitmap *, sbitmap *);
86 static void compute_rev_insert_delete (struct edge_list *edge_list, sbitmap *,
87 sbitmap *, sbitmap *, sbitmap *,
88 sbitmap *);
90 /* Edge based lcm routines. */
92 /* Compute expression anticipatability at entrance and exit of each block.
93 This is done based on the flow graph, and not on the pred-succ lists.
94 Other than that, its pretty much identical to compute_antinout. */
96 static void
97 compute_antinout_edge (sbitmap *antloc, sbitmap *transp, sbitmap *antin,
98 sbitmap *antout)
100 basic_block bb;
101 edge e;
102 basic_block *worklist, *qin, *qout, *qend;
103 unsigned int qlen;
104 edge_iterator ei;
106 /* Allocate a worklist array/queue. Entries are only added to the
107 list if they were not already on the list. So the size is
108 bounded by the number of basic blocks. */
109 qin = qout = worklist = XNEWVEC (basic_block, n_basic_blocks);
111 /* We want a maximal solution, so make an optimistic initialization of
112 ANTIN. */
113 sbitmap_vector_ones (antin, last_basic_block);
115 /* Put every block on the worklist; this is necessary because of the
116 optimistic initialization of ANTIN above. */
117 FOR_EACH_BB_REVERSE (bb)
119 *qin++ = bb;
120 bb->aux = bb;
123 qin = worklist;
124 qend = &worklist[n_basic_blocks - NUM_FIXED_BLOCKS];
125 qlen = n_basic_blocks - NUM_FIXED_BLOCKS;
127 /* Mark blocks which are predecessors of the exit block so that we
128 can easily identify them below. */
129 FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR->preds)
130 e->src->aux = EXIT_BLOCK_PTR;
132 /* Iterate until the worklist is empty. */
133 while (qlen)
135 /* Take the first entry off the worklist. */
136 bb = *qout++;
137 qlen--;
139 if (qout >= qend)
140 qout = worklist;
142 if (bb->aux == EXIT_BLOCK_PTR)
143 /* Do not clear the aux field for blocks which are predecessors of
144 the EXIT block. That way we never add then to the worklist
145 again. */
146 sbitmap_zero (antout[bb->index]);
147 else
149 /* Clear the aux field of this block so that it can be added to
150 the worklist again if necessary. */
151 bb->aux = NULL;
152 sbitmap_intersection_of_succs (antout[bb->index], antin, bb->index);
155 if (sbitmap_a_or_b_and_c_cg (antin[bb->index], antloc[bb->index],
156 transp[bb->index], antout[bb->index]))
157 /* If the in state of this block changed, then we need
158 to add the predecessors of this block to the worklist
159 if they are not already on the worklist. */
160 FOR_EACH_EDGE (e, ei, bb->preds)
161 if (!e->src->aux && e->src != ENTRY_BLOCK_PTR)
163 *qin++ = e->src;
164 e->src->aux = e;
165 qlen++;
166 if (qin >= qend)
167 qin = worklist;
171 clear_aux_for_edges ();
172 clear_aux_for_blocks ();
173 free (worklist);
176 /* Compute the earliest vector for edge based lcm. */
178 static void
179 compute_earliest (struct edge_list *edge_list, int n_exprs, sbitmap *antin,
180 sbitmap *antout, sbitmap *avout, sbitmap *kill,
181 sbitmap *earliest)
183 sbitmap difference, temp_bitmap;
184 int x, num_edges;
185 basic_block pred, succ;
187 num_edges = NUM_EDGES (edge_list);
189 difference = sbitmap_alloc (n_exprs);
190 temp_bitmap = sbitmap_alloc (n_exprs);
192 for (x = 0; x < num_edges; x++)
194 pred = INDEX_EDGE_PRED_BB (edge_list, x);
195 succ = INDEX_EDGE_SUCC_BB (edge_list, x);
196 if (pred == ENTRY_BLOCK_PTR)
197 sbitmap_copy (earliest[x], antin[succ->index]);
198 else
200 if (succ == EXIT_BLOCK_PTR)
201 sbitmap_zero (earliest[x]);
202 else
204 sbitmap_difference (difference, antin[succ->index],
205 avout[pred->index]);
206 sbitmap_not (temp_bitmap, antout[pred->index]);
207 sbitmap_a_and_b_or_c (earliest[x], difference,
208 kill[pred->index], temp_bitmap);
213 sbitmap_free (temp_bitmap);
214 sbitmap_free (difference);
217 /* later(p,s) is dependent on the calculation of laterin(p).
218 laterin(p) is dependent on the calculation of later(p2,p).
220 laterin(ENTRY) is defined as all 0's
221 later(ENTRY, succs(ENTRY)) are defined using laterin(ENTRY)
222 laterin(succs(ENTRY)) is defined by later(ENTRY, succs(ENTRY)).
224 If we progress in this manner, starting with all basic blocks
225 in the work list, anytime we change later(bb), we need to add
226 succs(bb) to the worklist if they are not already on the worklist.
228 Boundary conditions:
230 We prime the worklist all the normal basic blocks. The ENTRY block can
231 never be added to the worklist since it is never the successor of any
232 block. We explicitly prevent the EXIT block from being added to the
233 worklist.
235 We optimistically initialize LATER. That is the only time this routine
236 will compute LATER for an edge out of the entry block since the entry
237 block is never on the worklist. Thus, LATERIN is neither used nor
238 computed for the ENTRY block.
240 Since the EXIT block is never added to the worklist, we will neither
241 use nor compute LATERIN for the exit block. Edges which reach the
242 EXIT block are handled in the normal fashion inside the loop. However,
243 the insertion/deletion computation needs LATERIN(EXIT), so we have
244 to compute it. */
246 static void
247 compute_laterin (struct edge_list *edge_list, sbitmap *earliest,
248 sbitmap *antloc, sbitmap *later, sbitmap *laterin)
250 int num_edges, i;
251 edge e;
252 basic_block *worklist, *qin, *qout, *qend, bb;
253 unsigned int qlen;
254 edge_iterator ei;
256 num_edges = NUM_EDGES (edge_list);
258 /* Allocate a worklist array/queue. Entries are only added to the
259 list if they were not already on the list. So the size is
260 bounded by the number of basic blocks. */
261 qin = qout = worklist
262 = XNEWVEC (basic_block, n_basic_blocks);
264 /* Initialize a mapping from each edge to its index. */
265 for (i = 0; i < num_edges; i++)
266 INDEX_EDGE (edge_list, i)->aux = (void *) (size_t) i;
268 /* We want a maximal solution, so initially consider LATER true for
269 all edges. This allows propagation through a loop since the incoming
270 loop edge will have LATER set, so if all the other incoming edges
271 to the loop are set, then LATERIN will be set for the head of the
272 loop.
274 If the optimistic setting of LATER on that edge was incorrect (for
275 example the expression is ANTLOC in a block within the loop) then
276 this algorithm will detect it when we process the block at the head
277 of the optimistic edge. That will requeue the affected blocks. */
278 sbitmap_vector_ones (later, num_edges);
280 /* Note that even though we want an optimistic setting of LATER, we
281 do not want to be overly optimistic. Consider an outgoing edge from
282 the entry block. That edge should always have a LATER value the
283 same as EARLIEST for that edge. */
284 FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR->succs)
285 sbitmap_copy (later[(size_t) e->aux], earliest[(size_t) e->aux]);
287 /* Add all the blocks to the worklist. This prevents an early exit from
288 the loop given our optimistic initialization of LATER above. */
289 FOR_EACH_BB (bb)
291 *qin++ = bb;
292 bb->aux = bb;
295 /* Note that we do not use the last allocated element for our queue,
296 as EXIT_BLOCK is never inserted into it. */
297 qin = worklist;
298 qend = &worklist[n_basic_blocks - NUM_FIXED_BLOCKS];
299 qlen = n_basic_blocks - NUM_FIXED_BLOCKS;
301 /* Iterate until the worklist is empty. */
302 while (qlen)
304 /* Take the first entry off the worklist. */
305 bb = *qout++;
306 bb->aux = NULL;
307 qlen--;
308 if (qout >= qend)
309 qout = worklist;
311 /* Compute the intersection of LATERIN for each incoming edge to B. */
312 sbitmap_ones (laterin[bb->index]);
313 FOR_EACH_EDGE (e, ei, bb->preds)
314 sbitmap_a_and_b (laterin[bb->index], laterin[bb->index],
315 later[(size_t)e->aux]);
317 /* Calculate LATER for all outgoing edges. */
318 FOR_EACH_EDGE (e, ei, bb->succs)
319 if (sbitmap_union_of_diff_cg (later[(size_t) e->aux],
320 earliest[(size_t) e->aux],
321 laterin[e->src->index],
322 antloc[e->src->index])
323 /* If LATER for an outgoing edge was changed, then we need
324 to add the target of the outgoing edge to the worklist. */
325 && e->dest != EXIT_BLOCK_PTR && e->dest->aux == 0)
327 *qin++ = e->dest;
328 e->dest->aux = e;
329 qlen++;
330 if (qin >= qend)
331 qin = worklist;
335 /* Computation of insertion and deletion points requires computing LATERIN
336 for the EXIT block. We allocated an extra entry in the LATERIN array
337 for just this purpose. */
338 sbitmap_ones (laterin[last_basic_block]);
339 FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR->preds)
340 sbitmap_a_and_b (laterin[last_basic_block],
341 laterin[last_basic_block],
342 later[(size_t) e->aux]);
344 clear_aux_for_edges ();
345 free (worklist);
348 /* Compute the insertion and deletion points for edge based LCM. */
350 static void
351 compute_insert_delete (struct edge_list *edge_list, sbitmap *antloc,
352 sbitmap *later, sbitmap *laterin, sbitmap *insert,
353 sbitmap *del)
355 int x;
356 basic_block bb;
358 FOR_EACH_BB (bb)
359 sbitmap_difference (del[bb->index], antloc[bb->index],
360 laterin[bb->index]);
362 for (x = 0; x < NUM_EDGES (edge_list); x++)
364 basic_block b = INDEX_EDGE_SUCC_BB (edge_list, x);
366 if (b == EXIT_BLOCK_PTR)
367 sbitmap_difference (insert[x], later[x], laterin[last_basic_block]);
368 else
369 sbitmap_difference (insert[x], later[x], laterin[b->index]);
373 /* Given local properties TRANSP, ANTLOC, AVOUT, KILL return the insert and
374 delete vectors for edge based LCM. Returns an edgelist which is used to
375 map the insert vector to what edge an expression should be inserted on. */
377 struct edge_list *
378 pre_edge_lcm (int n_exprs, sbitmap *transp,
379 sbitmap *avloc, sbitmap *antloc, sbitmap *kill,
380 sbitmap **insert, sbitmap **del)
382 sbitmap *antin, *antout, *earliest;
383 sbitmap *avin, *avout;
384 sbitmap *later, *laterin;
385 struct edge_list *edge_list;
386 int num_edges;
388 edge_list = create_edge_list ();
389 num_edges = NUM_EDGES (edge_list);
391 #ifdef LCM_DEBUG_INFO
392 if (dump_file)
394 fprintf (dump_file, "Edge List:\n");
395 verify_edge_list (dump_file, edge_list);
396 print_edge_list (dump_file, edge_list);
397 dump_sbitmap_vector (dump_file, "transp", "", transp, last_basic_block);
398 dump_sbitmap_vector (dump_file, "antloc", "", antloc, last_basic_block);
399 dump_sbitmap_vector (dump_file, "avloc", "", avloc, last_basic_block);
400 dump_sbitmap_vector (dump_file, "kill", "", kill, last_basic_block);
402 #endif
404 /* Compute global availability. */
405 avin = sbitmap_vector_alloc (last_basic_block, n_exprs);
406 avout = sbitmap_vector_alloc (last_basic_block, n_exprs);
407 compute_available (avloc, kill, avout, avin);
408 sbitmap_vector_free (avin);
410 /* Compute global anticipatability. */
411 antin = sbitmap_vector_alloc (last_basic_block, n_exprs);
412 antout = sbitmap_vector_alloc (last_basic_block, n_exprs);
413 compute_antinout_edge (antloc, transp, antin, antout);
415 #ifdef LCM_DEBUG_INFO
416 if (dump_file)
418 dump_sbitmap_vector (dump_file, "antin", "", antin, last_basic_block);
419 dump_sbitmap_vector (dump_file, "antout", "", antout, last_basic_block);
421 #endif
423 /* Compute earliestness. */
424 earliest = sbitmap_vector_alloc (num_edges, n_exprs);
425 compute_earliest (edge_list, n_exprs, antin, antout, avout, kill, earliest);
427 #ifdef LCM_DEBUG_INFO
428 if (dump_file)
429 dump_sbitmap_vector (dump_file, "earliest", "", earliest, num_edges);
430 #endif
432 sbitmap_vector_free (antout);
433 sbitmap_vector_free (antin);
434 sbitmap_vector_free (avout);
436 later = sbitmap_vector_alloc (num_edges, n_exprs);
438 /* Allocate an extra element for the exit block in the laterin vector. */
439 laterin = sbitmap_vector_alloc (last_basic_block + 1, n_exprs);
440 compute_laterin (edge_list, earliest, antloc, later, laterin);
442 #ifdef LCM_DEBUG_INFO
443 if (dump_file)
445 dump_sbitmap_vector (dump_file, "laterin", "", laterin, last_basic_block + 1);
446 dump_sbitmap_vector (dump_file, "later", "", later, num_edges);
448 #endif
450 sbitmap_vector_free (earliest);
452 *insert = sbitmap_vector_alloc (num_edges, n_exprs);
453 *del = sbitmap_vector_alloc (last_basic_block, n_exprs);
454 compute_insert_delete (edge_list, antloc, later, laterin, *insert, *del);
456 sbitmap_vector_free (laterin);
457 sbitmap_vector_free (later);
459 #ifdef LCM_DEBUG_INFO
460 if (dump_file)
462 dump_sbitmap_vector (dump_file, "pre_insert_map", "", *insert, num_edges);
463 dump_sbitmap_vector (dump_file, "pre_delete_map", "", *del,
464 last_basic_block);
466 #endif
468 return edge_list;
471 /* Compute the AVIN and AVOUT vectors from the AVLOC and KILL vectors.
472 Return the number of passes we performed to iterate to a solution. */
474 void
475 compute_available (sbitmap *avloc, sbitmap *kill, sbitmap *avout,
476 sbitmap *avin)
478 edge e;
479 basic_block *worklist, *qin, *qout, *qend, bb;
480 unsigned int qlen;
481 edge_iterator ei;
483 /* Allocate a worklist array/queue. Entries are only added to the
484 list if they were not already on the list. So the size is
485 bounded by the number of basic blocks. */
486 qin = qout = worklist =
487 XNEWVEC (basic_block, n_basic_blocks - NUM_FIXED_BLOCKS);
489 /* We want a maximal solution. */
490 sbitmap_vector_ones (avout, last_basic_block);
492 /* Put every block on the worklist; this is necessary because of the
493 optimistic initialization of AVOUT above. */
494 FOR_EACH_BB (bb)
496 *qin++ = bb;
497 bb->aux = bb;
500 qin = worklist;
501 qend = &worklist[n_basic_blocks - NUM_FIXED_BLOCKS];
502 qlen = n_basic_blocks - NUM_FIXED_BLOCKS;
504 /* Mark blocks which are successors of the entry block so that we
505 can easily identify them below. */
506 FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR->succs)
507 e->dest->aux = ENTRY_BLOCK_PTR;
509 /* Iterate until the worklist is empty. */
510 while (qlen)
512 /* Take the first entry off the worklist. */
513 bb = *qout++;
514 qlen--;
516 if (qout >= qend)
517 qout = worklist;
519 /* If one of the predecessor blocks is the ENTRY block, then the
520 intersection of avouts is the null set. We can identify such blocks
521 by the special value in the AUX field in the block structure. */
522 if (bb->aux == ENTRY_BLOCK_PTR)
523 /* Do not clear the aux field for blocks which are successors of the
524 ENTRY block. That way we never add then to the worklist again. */
525 sbitmap_zero (avin[bb->index]);
526 else
528 /* Clear the aux field of this block so that it can be added to
529 the worklist again if necessary. */
530 bb->aux = NULL;
531 sbitmap_intersection_of_preds (avin[bb->index], avout, bb->index);
534 if (sbitmap_union_of_diff_cg (avout[bb->index], avloc[bb->index],
535 avin[bb->index], kill[bb->index]))
536 /* If the out state of this block changed, then we need
537 to add the successors of this block to the worklist
538 if they are not already on the worklist. */
539 FOR_EACH_EDGE (e, ei, bb->succs)
540 if (!e->dest->aux && e->dest != EXIT_BLOCK_PTR)
542 *qin++ = e->dest;
543 e->dest->aux = e;
544 qlen++;
546 if (qin >= qend)
547 qin = worklist;
551 clear_aux_for_edges ();
552 clear_aux_for_blocks ();
553 free (worklist);
556 /* Compute the farthest vector for edge based lcm. */
558 static void
559 compute_farthest (struct edge_list *edge_list, int n_exprs,
560 sbitmap *st_avout, sbitmap *st_avin, sbitmap *st_antin,
561 sbitmap *kill, sbitmap *farthest)
563 sbitmap difference, temp_bitmap;
564 int x, num_edges;
565 basic_block pred, succ;
567 num_edges = NUM_EDGES (edge_list);
569 difference = sbitmap_alloc (n_exprs);
570 temp_bitmap = sbitmap_alloc (n_exprs);
572 for (x = 0; x < num_edges; x++)
574 pred = INDEX_EDGE_PRED_BB (edge_list, x);
575 succ = INDEX_EDGE_SUCC_BB (edge_list, x);
576 if (succ == EXIT_BLOCK_PTR)
577 sbitmap_copy (farthest[x], st_avout[pred->index]);
578 else
580 if (pred == ENTRY_BLOCK_PTR)
581 sbitmap_zero (farthest[x]);
582 else
584 sbitmap_difference (difference, st_avout[pred->index],
585 st_antin[succ->index]);
586 sbitmap_not (temp_bitmap, st_avin[succ->index]);
587 sbitmap_a_and_b_or_c (farthest[x], difference,
588 kill[succ->index], temp_bitmap);
593 sbitmap_free (temp_bitmap);
594 sbitmap_free (difference);
597 /* Compute nearer and nearerout vectors for edge based lcm.
599 This is the mirror of compute_laterin, additional comments on the
600 implementation can be found before compute_laterin. */
602 static void
603 compute_nearerout (struct edge_list *edge_list, sbitmap *farthest,
604 sbitmap *st_avloc, sbitmap *nearer, sbitmap *nearerout)
606 int num_edges, i;
607 edge e;
608 basic_block *worklist, *tos, bb;
609 edge_iterator ei;
611 num_edges = NUM_EDGES (edge_list);
613 /* Allocate a worklist array/queue. Entries are only added to the
614 list if they were not already on the list. So the size is
615 bounded by the number of basic blocks. */
616 tos = worklist = XNEWVEC (basic_block, n_basic_blocks + 1);
618 /* Initialize NEARER for each edge and build a mapping from an edge to
619 its index. */
620 for (i = 0; i < num_edges; i++)
621 INDEX_EDGE (edge_list, i)->aux = (void *) (size_t) i;
623 /* We want a maximal solution. */
624 sbitmap_vector_ones (nearer, num_edges);
626 /* Note that even though we want an optimistic setting of NEARER, we
627 do not want to be overly optimistic. Consider an incoming edge to
628 the exit block. That edge should always have a NEARER value the
629 same as FARTHEST for that edge. */
630 FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR->preds)
631 sbitmap_copy (nearer[(size_t)e->aux], farthest[(size_t)e->aux]);
633 /* Add all the blocks to the worklist. This prevents an early exit
634 from the loop given our optimistic initialization of NEARER. */
635 FOR_EACH_BB (bb)
637 *tos++ = bb;
638 bb->aux = bb;
641 /* Iterate until the worklist is empty. */
642 while (tos != worklist)
644 /* Take the first entry off the worklist. */
645 bb = *--tos;
646 bb->aux = NULL;
648 /* Compute the intersection of NEARER for each outgoing edge from B. */
649 sbitmap_ones (nearerout[bb->index]);
650 FOR_EACH_EDGE (e, ei, bb->succs)
651 sbitmap_a_and_b (nearerout[bb->index], nearerout[bb->index],
652 nearer[(size_t) e->aux]);
654 /* Calculate NEARER for all incoming edges. */
655 FOR_EACH_EDGE (e, ei, bb->preds)
656 if (sbitmap_union_of_diff_cg (nearer[(size_t) e->aux],
657 farthest[(size_t) e->aux],
658 nearerout[e->dest->index],
659 st_avloc[e->dest->index])
660 /* If NEARER for an incoming edge was changed, then we need
661 to add the source of the incoming edge to the worklist. */
662 && e->src != ENTRY_BLOCK_PTR && e->src->aux == 0)
664 *tos++ = e->src;
665 e->src->aux = e;
669 /* Computation of insertion and deletion points requires computing NEAREROUT
670 for the ENTRY block. We allocated an extra entry in the NEAREROUT array
671 for just this purpose. */
672 sbitmap_ones (nearerout[last_basic_block]);
673 FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR->succs)
674 sbitmap_a_and_b (nearerout[last_basic_block],
675 nearerout[last_basic_block],
676 nearer[(size_t) e->aux]);
678 clear_aux_for_edges ();
679 free (tos);
682 /* Compute the insertion and deletion points for edge based LCM. */
684 static void
685 compute_rev_insert_delete (struct edge_list *edge_list, sbitmap *st_avloc,
686 sbitmap *nearer, sbitmap *nearerout,
687 sbitmap *insert, sbitmap *del)
689 int x;
690 basic_block bb;
692 FOR_EACH_BB (bb)
693 sbitmap_difference (del[bb->index], st_avloc[bb->index],
694 nearerout[bb->index]);
696 for (x = 0; x < NUM_EDGES (edge_list); x++)
698 basic_block b = INDEX_EDGE_PRED_BB (edge_list, x);
699 if (b == ENTRY_BLOCK_PTR)
700 sbitmap_difference (insert[x], nearer[x], nearerout[last_basic_block]);
701 else
702 sbitmap_difference (insert[x], nearer[x], nearerout[b->index]);
706 /* Given local properties TRANSP, ST_AVLOC, ST_ANTLOC, KILL return the
707 insert and delete vectors for edge based reverse LCM. Returns an
708 edgelist which is used to map the insert vector to what edge
709 an expression should be inserted on. */
711 struct edge_list *
712 pre_edge_rev_lcm (int n_exprs, sbitmap *transp,
713 sbitmap *st_avloc, sbitmap *st_antloc, sbitmap *kill,
714 sbitmap **insert, sbitmap **del)
716 sbitmap *st_antin, *st_antout;
717 sbitmap *st_avout, *st_avin, *farthest;
718 sbitmap *nearer, *nearerout;
719 struct edge_list *edge_list;
720 int num_edges;
722 edge_list = create_edge_list ();
723 num_edges = NUM_EDGES (edge_list);
725 st_antin = sbitmap_vector_alloc (last_basic_block, n_exprs);
726 st_antout = sbitmap_vector_alloc (last_basic_block, n_exprs);
727 sbitmap_vector_zero (st_antin, last_basic_block);
728 sbitmap_vector_zero (st_antout, last_basic_block);
729 compute_antinout_edge (st_antloc, transp, st_antin, st_antout);
731 /* Compute global anticipatability. */
732 st_avout = sbitmap_vector_alloc (last_basic_block, n_exprs);
733 st_avin = sbitmap_vector_alloc (last_basic_block, n_exprs);
734 compute_available (st_avloc, kill, st_avout, st_avin);
736 #ifdef LCM_DEBUG_INFO
737 if (dump_file)
739 fprintf (dump_file, "Edge List:\n");
740 verify_edge_list (dump_file, edge_list);
741 print_edge_list (dump_file, edge_list);
742 dump_sbitmap_vector (dump_file, "transp", "", transp, last_basic_block);
743 dump_sbitmap_vector (dump_file, "st_avloc", "", st_avloc, last_basic_block);
744 dump_sbitmap_vector (dump_file, "st_antloc", "", st_antloc, last_basic_block);
745 dump_sbitmap_vector (dump_file, "st_antin", "", st_antin, last_basic_block);
746 dump_sbitmap_vector (dump_file, "st_antout", "", st_antout, last_basic_block);
747 dump_sbitmap_vector (dump_file, "st_kill", "", kill, last_basic_block);
749 #endif
751 #ifdef LCM_DEBUG_INFO
752 if (dump_file)
754 dump_sbitmap_vector (dump_file, "st_avout", "", st_avout, last_basic_block);
755 dump_sbitmap_vector (dump_file, "st_avin", "", st_avin, last_basic_block);
757 #endif
759 /* Compute farthestness. */
760 farthest = sbitmap_vector_alloc (num_edges, n_exprs);
761 compute_farthest (edge_list, n_exprs, st_avout, st_avin, st_antin,
762 kill, farthest);
764 #ifdef LCM_DEBUG_INFO
765 if (dump_file)
766 dump_sbitmap_vector (dump_file, "farthest", "", farthest, num_edges);
767 #endif
769 sbitmap_vector_free (st_antin);
770 sbitmap_vector_free (st_antout);
772 sbitmap_vector_free (st_avin);
773 sbitmap_vector_free (st_avout);
775 nearer = sbitmap_vector_alloc (num_edges, n_exprs);
777 /* Allocate an extra element for the entry block. */
778 nearerout = sbitmap_vector_alloc (last_basic_block + 1, n_exprs);
779 compute_nearerout (edge_list, farthest, st_avloc, nearer, nearerout);
781 #ifdef LCM_DEBUG_INFO
782 if (dump_file)
784 dump_sbitmap_vector (dump_file, "nearerout", "", nearerout,
785 last_basic_block + 1);
786 dump_sbitmap_vector (dump_file, "nearer", "", nearer, num_edges);
788 #endif
790 sbitmap_vector_free (farthest);
792 *insert = sbitmap_vector_alloc (num_edges, n_exprs);
793 *del = sbitmap_vector_alloc (last_basic_block, n_exprs);
794 compute_rev_insert_delete (edge_list, st_avloc, nearer, nearerout,
795 *insert, *del);
797 sbitmap_vector_free (nearerout);
798 sbitmap_vector_free (nearer);
800 #ifdef LCM_DEBUG_INFO
801 if (dump_file)
803 dump_sbitmap_vector (dump_file, "pre_insert_map", "", *insert, num_edges);
804 dump_sbitmap_vector (dump_file, "pre_delete_map", "", *del,
805 last_basic_block);
807 #endif
808 return edge_list;