]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cfg.c
re PR other/77421 (Bugs found in GCC with the help of PVS-Studio)
[thirdparty/gcc.git] / gcc / cfg.c
CommitLineData
402209ff 1/* Control flow graph manipulation code for GNU compiler.
818ab71a 2 Copyright (C) 1987-2016 Free Software Foundation, Inc.
402209ff
JH
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
9dcd6f09 8Software Foundation; either version 3, or (at your option) any later
402209ff
JH
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
9dcd6f09
NC
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
402209ff 19
9d083c8c 20/* This file contains low level functions to manipulate the CFG and
4d6922ee 21 analyze it. All other modules should not transform the data structure
9d083c8c
RS
22 directly and use abstraction instead. The file is supposed to be
23 ordered bottom-up and should not contain any code dependent on a
24 particular intermediate language (RTL or trees).
402209ff
JH
25
26 Available functionality:
27 - Initialization/deallocation
28 init_flow, clear_edges
ca6c03ca
JH
29 - Low level basic block manipulation
30 alloc_block, expunge_block
402209ff 31 - Edge manipulation
7ded4467 32 make_edge, make_single_succ_edge, cached_make_edge, remove_edge
402209ff
JH
33 - Low level edge redirection (without updating instruction chain)
34 redirect_edge_succ, redirect_edge_succ_nodup, redirect_edge_pred
eaec9b3d 35 - Dumping and debugging
ca6c03ca
JH
36 dump_flow_info, debug_flow_info, dump_edge_info
37 - Allocation of AUX fields for basic blocks
38 alloc_aux_for_blocks, free_aux_for_blocks, alloc_aux_for_block
38c1593d 39 - clear_bb_flags
10e9fecc
JH
40 - Consistency checking
41 verify_flow_info
42 - Dumping and debugging
43 print_rtl_with_bb, dump_bb, debug_bb, debug_bb_n
532aafad
SB
44
45 TODO: Document these "Available functionality" functions in the files
46 that implement them.
402209ff
JH
47 */
48\f
49#include "config.h"
50#include "system.h"
4977bab6 51#include "coretypes.h"
5d85afe9 52#include "backend.h"
60393bbc 53#include "hard-reg-set.h"
957060b5
AM
54#include "tree.h"
55#include "cfghooks.h"
6fb5fa3c 56#include "df.h"
c7131fb2 57#include "cfganal.h"
532aafad 58#include "cfgloop.h" /* FIXME: For struct loop. */
7ee2468b 59#include "dumpfile.h"
402209ff 60
402209ff 61\f
33156717
JH
62#define RDIV(X,Y) (((X) + (Y) / 2) / (Y))
63
eaec9b3d 64/* Called once at initialization time. */
402209ff
JH
65
66void
9defb1fe 67init_flow (struct function *the_fun)
402209ff 68{
9defb1fe 69 if (!the_fun->cfg)
766090c2 70 the_fun->cfg = ggc_cleared_alloc<control_flow_graph> ();
dc936fb2 71 n_edges_for_fn (the_fun) = 0;
fefa31b5 72 ENTRY_BLOCK_PTR_FOR_FN (the_fun)
766090c2 73 = ggc_cleared_alloc<basic_block_def> ();
fefa31b5
DM
74 ENTRY_BLOCK_PTR_FOR_FN (the_fun)->index = ENTRY_BLOCK;
75 EXIT_BLOCK_PTR_FOR_FN (the_fun)
766090c2 76 = ggc_cleared_alloc<basic_block_def> ();
fefa31b5
DM
77 EXIT_BLOCK_PTR_FOR_FN (the_fun)->index = EXIT_BLOCK;
78 ENTRY_BLOCK_PTR_FOR_FN (the_fun)->next_bb
79 = EXIT_BLOCK_PTR_FOR_FN (the_fun);
80 EXIT_BLOCK_PTR_FOR_FN (the_fun)->prev_bb
81 = ENTRY_BLOCK_PTR_FOR_FN (the_fun);
402209ff
JH
82}
83\f
d39ac0fd 84/* Helper function for remove_edge and clear_edges. Frees edge structure
532aafad 85 without actually removing it from the pred/succ arrays. */
d39ac0fd
JH
86
87static void
61183076 88free_edge (function *fn, edge e)
d39ac0fd 89{
61183076 90 n_edges_for_fn (fn)--;
80d8221e 91 ggc_free (e);
d39ac0fd
JH
92}
93
402209ff
JH
94/* Free the memory associated with the edge structures. */
95
96void
61183076 97clear_edges (struct function *fn)
402209ff 98{
e0082a72 99 basic_block bb;
d39ac0fd 100 edge e;
628f6a4e 101 edge_iterator ei;
402209ff 102
61183076 103 FOR_EACH_BB_FN (bb, fn)
402209ff 104 {
628f6a4e 105 FOR_EACH_EDGE (e, ei, bb->succs)
61183076 106 free_edge (fn, e);
9771b263
DN
107 vec_safe_truncate (bb->succs, 0);
108 vec_safe_truncate (bb->preds, 0);
d39ac0fd 109 }
4891442b 110
61183076
RB
111 FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR_FOR_FN (fn)->succs)
112 free_edge (fn, e);
113 vec_safe_truncate (EXIT_BLOCK_PTR_FOR_FN (fn)->preds, 0);
114 vec_safe_truncate (ENTRY_BLOCK_PTR_FOR_FN (fn)->succs, 0);
402209ff 115
61183076 116 gcc_assert (!n_edges_for_fn (fn));
402209ff
JH
117}
118\f
ca6c03ca 119/* Allocate memory for basic_block. */
402209ff 120
4262e623 121basic_block
d329e058 122alloc_block (void)
402209ff
JH
123{
124 basic_block bb;
766090c2 125 bb = ggc_cleared_alloc<basic_block_def> ();
4262e623 126 return bb;
402209ff
JH
127}
128
918ed612
ZD
129/* Link block B to chain after AFTER. */
130void
d329e058 131link_block (basic_block b, basic_block after)
918ed612
ZD
132{
133 b->next_bb = after->next_bb;
134 b->prev_bb = after;
135 after->next_bb = b;
136 b->next_bb->prev_bb = b;
137}
f87c27b4 138
918ed612
ZD
139/* Unlink block B from chain. */
140void
d329e058 141unlink_block (basic_block b)
918ed612
ZD
142{
143 b->next_bb->prev_bb = b->prev_bb;
144 b->prev_bb->next_bb = b->next_bb;
6de9cd9a
DN
145 b->prev_bb = NULL;
146 b->next_bb = NULL;
918ed612 147}
f87c27b4 148
bf77398c
ZD
149/* Sequentially order blocks and compact the arrays. */
150void
d329e058 151compact_blocks (void)
bf77398c
ZD
152{
153 int i;
d329e058 154
557c4b49
DM
155 SET_BASIC_BLOCK_FOR_FN (cfun, ENTRY_BLOCK, ENTRY_BLOCK_PTR_FOR_FN (cfun));
156 SET_BASIC_BLOCK_FOR_FN (cfun, EXIT_BLOCK, EXIT_BLOCK_PTR_FOR_FN (cfun));
b8698a0f 157
6fb5fa3c
DB
158 if (df)
159 df_compact_blocks ();
b8698a0f 160 else
bf77398c 161 {
6fb5fa3c 162 basic_block bb;
b8698a0f 163
6fb5fa3c 164 i = NUM_FIXED_BLOCKS;
11cd3bed 165 FOR_EACH_BB_FN (bb, cfun)
6fb5fa3c 166 {
557c4b49 167 SET_BASIC_BLOCK_FOR_FN (cfun, i, bb);
6fb5fa3c
DB
168 bb->index = i;
169 i++;
170 }
0cae8d31 171 gcc_assert (i == n_basic_blocks_for_fn (cfun));
6de9cd9a 172
8b1c6fd7 173 for (; i < last_basic_block_for_fn (cfun); i++)
557c4b49 174 SET_BASIC_BLOCK_FOR_FN (cfun, i, NULL);
6fb5fa3c 175 }
8b1c6fd7 176 last_basic_block_for_fn (cfun) = n_basic_blocks_for_fn (cfun);
bf77398c
ZD
177}
178
bf77398c 179/* Remove block B from the basic block array. */
402209ff 180
6a58eee9 181void
d329e058 182expunge_block (basic_block b)
6a58eee9 183{
918ed612 184 unlink_block (b);
557c4b49 185 SET_BASIC_BLOCK_FOR_FN (cfun, b->index, NULL);
0cae8d31 186 n_basic_blocks_for_fn (cfun)--;
ab3b6795
JH
187 /* We should be able to ggc_free here, but we are not.
188 The dead SSA_NAMES are left pointing to dead statements that are pointing
189 to dead basic blocks making garbage collector to die.
190 We should be able to release all dead SSA_NAMES and at the same time we should
191 clear out BB pointer of dead statements consistently. */
6a58eee9 192}
402209ff 193\f
adf4a335
KH
194/* Connect E to E->src. */
195
196static inline void
197connect_src (edge e)
198{
9771b263 199 vec_safe_push (e->src->succs, e);
6fb5fa3c 200 df_mark_solutions_dirty ();
adf4a335
KH
201}
202
203/* Connect E to E->dest. */
204
205static inline void
206connect_dest (edge e)
207{
208 basic_block dest = e->dest;
9771b263 209 vec_safe_push (dest->preds, e);
adf4a335 210 e->dest_idx = EDGE_COUNT (dest->preds) - 1;
6fb5fa3c 211 df_mark_solutions_dirty ();
adf4a335
KH
212}
213
214/* Disconnect edge E from E->src. */
215
216static inline void
217disconnect_src (edge e)
218{
219 basic_block src = e->src;
220 edge_iterator ei;
221 edge tmp;
222
223 for (ei = ei_start (src->succs); (tmp = ei_safe_edge (ei)); )
224 {
225 if (tmp == e)
226 {
9771b263 227 src->succs->unordered_remove (ei.index);
c813039d 228 df_mark_solutions_dirty ();
adf4a335
KH
229 return;
230 }
231 else
232 ei_next (&ei);
233 }
234
235 gcc_unreachable ();
236}
237
238/* Disconnect edge E from E->dest. */
239
240static inline void
241disconnect_dest (edge e)
242{
243 basic_block dest = e->dest;
244 unsigned int dest_idx = e->dest_idx;
245
9771b263 246 dest->preds->unordered_remove (dest_idx);
adf4a335
KH
247
248 /* If we removed an edge in the middle of the edge vector, we need
249 to update dest_idx of the edge that moved into the "hole". */
250 if (dest_idx < EDGE_COUNT (dest->preds))
251 EDGE_PRED (dest, dest_idx)->dest_idx = dest_idx;
6fb5fa3c 252 df_mark_solutions_dirty ();
adf4a335
KH
253}
254
e0fd3e7a
MM
255/* Create an edge connecting SRC and DEST with flags FLAGS. Return newly
256 created edge. Use this only if you are sure that this edge can't
257 possibly already exist. */
258
259edge
d329e058 260unchecked_make_edge (basic_block src, basic_block dst, int flags)
e0fd3e7a
MM
261{
262 edge e;
766090c2 263 e = ggc_cleared_alloc<edge_def> ();
dc936fb2 264 n_edges_for_fn (cfun)++;
e0fd3e7a 265
e0fd3e7a
MM
266 e->src = src;
267 e->dest = dst;
268 e->flags = flags;
adf4a335
KH
269
270 connect_src (e);
271 connect_dest (e);
e0fd3e7a 272
d9d4706f 273 execute_on_growing_pred (e);
e0fd3e7a
MM
274 return e;
275}
276
7ded4467 277/* Create an edge connecting SRC and DST with FLAGS optionally using
2ba84f36 278 edge cache CACHE. Return the new edge, NULL if already exist. */
4262e623 279
7ded4467 280edge
a6ee1a15 281cached_make_edge (sbitmap edge_cache, basic_block src, basic_block dst, int flags)
402209ff 282{
e2c879a1 283 if (edge_cache == NULL
fefa31b5
DM
284 || src == ENTRY_BLOCK_PTR_FOR_FN (cfun)
285 || dst == EXIT_BLOCK_PTR_FOR_FN (cfun))
e2c879a1 286 return make_edge (src, dst, flags);
402209ff 287
e2c879a1 288 /* Does the requested edge already exist? */
d7c028c0 289 if (! bitmap_bit_p (edge_cache, dst->index))
402209ff 290 {
e2c879a1
KH
291 /* The edge does not exist. Create one and update the
292 cache. */
d7c028c0 293 bitmap_set_bit (edge_cache, dst->index);
e2c879a1 294 return unchecked_make_edge (src, dst, flags);
402209ff 295 }
d329e058 296
e2c879a1
KH
297 /* At this point, we know that the requested edge exists. Adjust
298 flags if necessary. */
299 if (flags)
300 {
301 edge e = find_edge (src, dst);
302 e->flags |= flags;
303 }
7ded4467 304
e2c879a1 305 return NULL;
7ded4467
JH
306}
307
308/* Create an edge connecting SRC and DEST with flags FLAGS. Return newly
309 created edge or NULL if already exist. */
310
311edge
d329e058 312make_edge (basic_block src, basic_block dest, int flags)
7ded4467 313{
e2c879a1
KH
314 edge e = find_edge (src, dest);
315
316 /* Make sure we don't add duplicate edges. */
317 if (e)
318 {
319 e->flags |= flags;
320 return NULL;
321 }
322
323 return unchecked_make_edge (src, dest, flags);
7ded4467
JH
324}
325
eaec9b3d 326/* Create an edge connecting SRC to DEST and set probability by knowing
7ded4467
JH
327 that it is the single edge leaving SRC. */
328
329edge
d329e058 330make_single_succ_edge (basic_block src, basic_block dest, int flags)
7ded4467
JH
331{
332 edge e = make_edge (src, dest, flags);
333
334 e->probability = REG_BR_PROB_BASE;
335 e->count = src->count;
336 return e;
402209ff
JH
337}
338
339/* This function will remove an edge from the flow graph. */
340
341void
452ba14d 342remove_edge_raw (edge e)
402209ff 343{
3809e990 344 remove_predictions_associated_with_edge (e);
d9d4706f
KH
345 execute_on_shrinking_pred (e);
346
adf4a335
KH
347 disconnect_src (e);
348 disconnect_dest (e);
402209ff 349
61183076 350 free_edge (cfun, e);
402209ff
JH
351}
352
353/* Redirect an edge's successor from one block to another. */
354
355void
d329e058 356redirect_edge_succ (edge e, basic_block new_succ)
402209ff 357{
d9d4706f
KH
358 execute_on_shrinking_pred (e);
359
adf4a335 360 disconnect_dest (e);
628f6a4e 361
adf4a335 362 e->dest = new_succ;
402209ff
JH
363
364 /* Reconnect the edge to the new successor block. */
adf4a335
KH
365 connect_dest (e);
366
d9d4706f 367 execute_on_growing_pred (e);
402209ff
JH
368}
369
402209ff
JH
370/* Redirect an edge's predecessor from one block to another. */
371
372void
d329e058 373redirect_edge_pred (edge e, basic_block new_pred)
402209ff 374{
adf4a335 375 disconnect_src (e);
402209ff 376
adf4a335 377 e->src = new_pred;
402209ff
JH
378
379 /* Reconnect the edge to the new predecessor block. */
adf4a335 380 connect_src (e);
402209ff 381}
38c1593d 382
c4669594 383/* Clear all basic block flags that do not have to be preserved. */
38c1593d 384void
d329e058 385clear_bb_flags (void)
38c1593d 386{
e0082a72
ZD
387 basic_block bb;
388
fefa31b5 389 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)
c4669594 390 bb->flags &= BB_FLAGS_TO_PRESERVE;
38c1593d 391}
402209ff 392\f
878f99d2
JH
393/* Check the consistency of profile information. We can't do that
394 in verify_flow_info, as the counts may get invalid for incompletely
395 solved graphs, later eliminating of conditionals or roundoff errors.
396 It is still practical to have them reported for debugging of simple
397 testcases. */
c4669594
SB
398static void
399check_bb_profile (basic_block bb, FILE * file, int indent, int flags)
878f99d2
JH
400{
401 edge e;
402 int sum = 0;
403 gcov_type lsum;
628f6a4e 404 edge_iterator ei;
2eb712b4 405 struct function *fun = DECL_STRUCT_FUNCTION (current_function_decl);
c4669594
SB
406 char *s_indent = (char *) alloca ((size_t) indent + 1);
407 memset ((void *) s_indent, ' ', (size_t) indent);
408 s_indent[indent] = '\0';
878f99d2 409
ea19eb9f 410 if (profile_status_for_fn (fun) == PROFILE_ABSENT)
878f99d2
JH
411 return;
412
fefa31b5 413 if (bb != EXIT_BLOCK_PTR_FOR_FN (fun))
878f99d2 414 {
46f1f3c1 415 bool found = false;
628f6a4e 416 FOR_EACH_EDGE (e, ei, bb->succs)
46f1f3c1
JH
417 {
418 if (!(e->flags & EDGE_EH))
419 found = true;
420 sum += e->probability;
421 }
422 /* Only report mismatches for non-EH control flow. If there are only EH
423 edges it means that the BB ends by noreturn call. Here the control
424 flow may just terminate. */
425 if (found)
426 {
427 if (EDGE_COUNT (bb->succs) && abs (sum - REG_BR_PROB_BASE) > 100)
428 fprintf (file, "%s%sInvalid sum of outgoing probabilities %.1f%%\n",
429 (flags & TDF_COMMENT) ? ";; " : "", s_indent,
430 sum * 100.0 / REG_BR_PROB_BASE);
431 lsum = 0;
432 FOR_EACH_EDGE (e, ei, bb->succs)
433 lsum += e->count;
434 if (EDGE_COUNT (bb->succs)
435 && (lsum - bb->count > 100 || lsum - bb->count < -100))
436 fprintf (file, "%s%sInvalid sum of outgoing counts %i, should be %i\n",
437 (flags & TDF_COMMENT) ? ";; " : "", s_indent,
438 (int) lsum, (int) bb->count);
439 }
878f99d2 440 }
fefa31b5 441 if (bb != ENTRY_BLOCK_PTR_FOR_FN (fun))
878f99d2
JH
442 {
443 sum = 0;
628f6a4e 444 FOR_EACH_EDGE (e, ei, bb->preds)
878f99d2
JH
445 sum += EDGE_FREQUENCY (e);
446 if (abs (sum - bb->frequency) > 100)
447 fprintf (file,
c4669594
SB
448 "%s%sInvalid sum of incoming frequencies %i, should be %i\n",
449 (flags & TDF_COMMENT) ? ";; " : "", s_indent,
878f99d2
JH
450 sum, bb->frequency);
451 lsum = 0;
628f6a4e 452 FOR_EACH_EDGE (e, ei, bb->preds)
878f99d2
JH
453 lsum += e->count;
454 if (lsum - bb->count > 100 || lsum - bb->count < -100)
c4669594
SB
455 fprintf (file, "%s%sInvalid sum of incoming counts %i, should be %i\n",
456 (flags & TDF_COMMENT) ? ";; " : "", s_indent,
878f99d2
JH
457 (int) lsum, (int) bb->count);
458 }
600b5b1d
TJ
459 if (BB_PARTITION (bb) == BB_COLD_PARTITION)
460 {
461 /* Warn about inconsistencies in the partitioning that are
462 currently caused by profile insanities created via optimization. */
463 if (!probably_never_executed_bb_p (fun, bb))
464 fprintf (file, "%s%sBlock in cold partition with hot count\n",
465 (flags & TDF_COMMENT) ? ";; " : "", s_indent);
466 FOR_EACH_EDGE (e, ei, bb->preds)
467 {
468 if (!probably_never_executed_edge_p (fun, e))
469 fprintf (file,
470 "%s%sBlock in cold partition with incoming hot edge\n",
471 (flags & TDF_COMMENT) ? ";; " : "", s_indent);
472 }
473 }
878f99d2
JH
474}
475\f
402209ff 476void
a315c44c 477dump_edge_info (FILE *file, edge e, int flags, int do_succ)
402209ff 478{
ca6c03ca 479 basic_block side = (do_succ ? e->dest : e->src);
a315c44c
SB
480 bool do_details = false;
481
482 if ((flags & TDF_DETAILS) != 0
483 && (flags & TDF_SLIM) == 0)
484 do_details = true;
485
532aafad 486 if (side->index == ENTRY_BLOCK)
ca6c03ca 487 fputs (" ENTRY", file);
532aafad 488 else if (side->index == EXIT_BLOCK)
ca6c03ca
JH
489 fputs (" EXIT", file);
490 else
0b17ab2f 491 fprintf (file, " %d", side->index);
ca6c03ca 492
a315c44c 493 if (e->probability && do_details)
ca6c03ca 494 fprintf (file, " [%.1f%%] ", e->probability * 100.0 / REG_BR_PROB_BASE);
402209ff 495
a315c44c 496 if (e->count && do_details)
402209ff 497 {
edb30094 498 fputs (" count:", file);
16998094 499 fprintf (file, "%" PRId64, e->count);
402209ff
JH
500 }
501
a315c44c 502 if (e->flags && do_details)
402209ff 503 {
a315c44c
SB
504 static const char * const bitnames[] =
505 {
506#define DEF_EDGE_FLAG(NAME,IDX) #NAME ,
507#include "cfg-flags.def"
508 NULL
509#undef DEF_EDGE_FLAG
510 };
511 bool comma = false;
ca6c03ca 512 int i, flags = e->flags;
402209ff 513
a315c44c 514 gcc_assert (e->flags <= EDGE_ALL_FLAGS);
4891442b 515 fputs (" (", file);
402209ff
JH
516 for (i = 0; flags; i++)
517 if (flags & (1 << i))
518 {
519 flags &= ~(1 << i);
520
521 if (comma)
522 fputc (',', file);
a315c44c
SB
523 fputs (bitnames[i], file);
524 comma = true;
402209ff 525 }
4891442b 526
402209ff
JH
527 fputc (')', file);
528 }
529}
7b3b6ae4
LC
530
531DEBUG_FUNCTION void
532debug (edge_def &ref)
533{
534 /* FIXME (crowl): Is this desireable? */
535 dump_edge_info (stderr, &ref, 0, false);
536 dump_edge_info (stderr, &ref, 0, true);
537}
538
539DEBUG_FUNCTION void
540debug (edge_def *ptr)
541{
542 if (ptr)
543 debug (*ptr);
544 else
545 fprintf (stderr, "<nil>\n");
546}
402209ff 547\f
ff7cc307 548/* Simple routines to easily allocate AUX fields of basic blocks. */
4891442b 549
ca6c03ca
JH
550static struct obstack block_aux_obstack;
551static void *first_block_aux_obj = 0;
552static struct obstack edge_aux_obstack;
553static void *first_edge_aux_obj = 0;
402209ff 554
09da1532 555/* Allocate a memory block of SIZE as BB->aux. The obstack must
ca6c03ca 556 be first initialized by alloc_aux_for_blocks. */
402209ff 557
a398224a 558static void
d329e058 559alloc_aux_for_block (basic_block bb, int size)
402209ff 560{
ca6c03ca 561 /* Verify that aux field is clear. */
341c100f 562 gcc_assert (!bb->aux && first_block_aux_obj);
ca6c03ca
JH
563 bb->aux = obstack_alloc (&block_aux_obstack, size);
564 memset (bb->aux, 0, size);
402209ff
JH
565}
566
ca6c03ca
JH
567/* Initialize the block_aux_obstack and if SIZE is nonzero, call
568 alloc_aux_for_block for each basic block. */
402209ff
JH
569
570void
d329e058 571alloc_aux_for_blocks (int size)
402209ff 572{
ca6c03ca 573 static int initialized;
402209ff 574
ca6c03ca 575 if (!initialized)
402209ff 576 {
ca6c03ca
JH
577 gcc_obstack_init (&block_aux_obstack);
578 initialized = 1;
402209ff 579 }
341c100f
NS
580 else
581 /* Check whether AUX data are still allocated. */
582 gcc_assert (!first_block_aux_obj);
c22cacf3 583
703ad42b 584 first_block_aux_obj = obstack_alloc (&block_aux_obstack, 0);
ca6c03ca 585 if (size)
402209ff 586 {
e0082a72 587 basic_block bb;
4891442b 588
04a90bec 589 FOR_ALL_BB_FN (bb, cfun)
e0082a72 590 alloc_aux_for_block (bb, size);
402209ff
JH
591 }
592}
ca6c03ca 593
108c1afc 594/* Clear AUX pointers of all blocks. */
402209ff
JH
595
596void
d329e058 597clear_aux_for_blocks (void)
402209ff 598{
e0082a72 599 basic_block bb;
4891442b 600
04a90bec 601 FOR_ALL_BB_FN (bb, cfun)
e0082a72 602 bb->aux = NULL;
108c1afc
RH
603}
604
605/* Free data allocated in block_aux_obstack and clear AUX pointers
606 of all blocks. */
607
608void
d329e058 609free_aux_for_blocks (void)
108c1afc 610{
341c100f 611 gcc_assert (first_block_aux_obj);
108c1afc 612 obstack_free (&block_aux_obstack, first_block_aux_obj);
ca6c03ca 613 first_block_aux_obj = NULL;
108c1afc
RH
614
615 clear_aux_for_blocks ();
ca6c03ca 616}
402209ff 617
039496da 618/* Allocate a memory edge of SIZE as E->aux. The obstack must
ca6c03ca 619 be first initialized by alloc_aux_for_edges. */
402209ff 620
039496da 621void
d329e058 622alloc_aux_for_edge (edge e, int size)
ca6c03ca
JH
623{
624 /* Verify that aux field is clear. */
341c100f 625 gcc_assert (!e->aux && first_edge_aux_obj);
ca6c03ca
JH
626 e->aux = obstack_alloc (&edge_aux_obstack, size);
627 memset (e->aux, 0, size);
628}
402209ff 629
ca6c03ca
JH
630/* Initialize the edge_aux_obstack and if SIZE is nonzero, call
631 alloc_aux_for_edge for each basic edge. */
402209ff 632
ca6c03ca 633void
d329e058 634alloc_aux_for_edges (int size)
ca6c03ca
JH
635{
636 static int initialized;
402209ff 637
ca6c03ca
JH
638 if (!initialized)
639 {
640 gcc_obstack_init (&edge_aux_obstack);
641 initialized = 1;
402209ff 642 }
341c100f
NS
643 else
644 /* Check whether AUX data are still allocated. */
645 gcc_assert (!first_edge_aux_obj);
4891442b 646
703ad42b 647 first_edge_aux_obj = obstack_alloc (&edge_aux_obstack, 0);
ca6c03ca 648 if (size)
402209ff 649 {
e0082a72
ZD
650 basic_block bb;
651
fefa31b5
DM
652 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun),
653 EXIT_BLOCK_PTR_FOR_FN (cfun), next_bb)
402209ff 654 {
ca6c03ca 655 edge e;
628f6a4e 656 edge_iterator ei;
ca6c03ca 657
628f6a4e 658 FOR_EACH_EDGE (e, ei, bb->succs)
ca6c03ca 659 alloc_aux_for_edge (e, size);
402209ff 660 }
402209ff 661 }
402209ff 662}
402209ff 663
108c1afc 664/* Clear AUX pointers of all edges. */
ca6c03ca
JH
665
666void
d329e058 667clear_aux_for_edges (void)
402209ff 668{
e0082a72
ZD
669 basic_block bb;
670 edge e;
402209ff 671
fefa31b5
DM
672 FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun),
673 EXIT_BLOCK_PTR_FOR_FN (cfun), next_bb)
402209ff 674 {
628f6a4e
BE
675 edge_iterator ei;
676 FOR_EACH_EDGE (e, ei, bb->succs)
ca6c03ca 677 e->aux = NULL;
402209ff 678 }
108c1afc
RH
679}
680
681/* Free data allocated in edge_aux_obstack and clear AUX pointers
682 of all edges. */
683
684void
d329e058 685free_aux_for_edges (void)
108c1afc 686{
341c100f 687 gcc_assert (first_edge_aux_obj);
108c1afc 688 obstack_free (&edge_aux_obstack, first_edge_aux_obj);
ca6c03ca 689 first_edge_aux_obj = NULL;
108c1afc
RH
690
691 clear_aux_for_edges ();
402209ff 692}
9ee634e3 693
24e47c76 694DEBUG_FUNCTION void
d329e058 695debug_bb (basic_block bb)
10e9fecc 696{
f8923f7e 697 dump_bb (stderr, bb, 0, dump_flags);
10e9fecc
JH
698}
699
24e47c76 700DEBUG_FUNCTION basic_block
d329e058 701debug_bb_n (int n)
10e9fecc 702{
06e28de2 703 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, n);
a315c44c 704 debug_bb (bb);
10e9fecc 705 return bb;
9ee634e3 706}
6de9cd9a 707
a315c44c
SB
708/* Dumps cfg related information about basic block BB to OUTF.
709 If HEADER is true, dump things that appear before the instructions
710 contained in BB. If FOOTER is true, dump things that appear after.
711 Flags are the TDF_* masks as documented in dumpfile.h.
712 NB: With TDF_DETAILS, it is assumed that cfun is available, so
713 that maybe_hot_bb_p and probably_never_executed_bb_p don't ICE. */
6de9cd9a 714
a315c44c
SB
715void
716dump_bb_info (FILE *outf, basic_block bb, int indent, int flags,
717 bool do_header, bool do_footer)
6de9cd9a 718{
628f6a4e 719 edge_iterator ei;
a315c44c 720 edge e;
6de9cd9a
DN
721 static const char * const bb_bitnames[] =
722 {
a315c44c
SB
723#define DEF_BASIC_BLOCK_FLAG(NAME,IDX) #NAME ,
724#include "cfg-flags.def"
725 NULL
726#undef DEF_BASIC_BLOCK_FLAG
6de9cd9a
DN
727 };
728 const unsigned n_bitnames = sizeof (bb_bitnames) / sizeof (char *);
c4669594 729 bool first;
a315c44c
SB
730 char *s_indent = (char *) alloca ((size_t) indent + 1);
731 memset ((void *) s_indent, ' ', (size_t) indent);
732 s_indent[indent] = '\0';
6de9cd9a 733
a315c44c
SB
734 gcc_assert (bb->flags <= BB_ALL_FLAGS);
735
736 if (do_header)
737 {
738 unsigned i;
739
740 if (flags & TDF_COMMENT)
741 fputs (";; ", outf);
c4669594 742 fprintf (outf, "%sbasic block %d, loop depth %d",
391886c8 743 s_indent, bb->index, bb_loop_depth (bb));
a315c44c
SB
744 if (flags & TDF_DETAILS)
745 {
2eb712b4 746 struct function *fun = DECL_STRUCT_FUNCTION (current_function_decl);
16998094 747 fprintf (outf, ", count " "%" PRId64,
a9243bfc 748 (int64_t) bb->count);
a315c44c 749 fprintf (outf, ", freq %i", bb->frequency);
2eb712b4 750 if (maybe_hot_bb_p (fun, bb))
a315c44c 751 fputs (", maybe hot", outf);
2eb712b4 752 if (probably_never_executed_bb_p (fun, bb))
a315c44c
SB
753 fputs (", probably never executed", outf);
754 }
755 fputc ('\n', outf);
756
757 if (flags & TDF_DETAILS)
758 {
d00e4baa 759 check_bb_profile (bb, outf, indent, flags);
a315c44c
SB
760 if (flags & TDF_COMMENT)
761 fputs (";; ", outf);
762 fprintf (outf, "%s prev block ", s_indent);
763 if (bb->prev_bb)
764 fprintf (outf, "%d", bb->prev_bb->index);
765 else
766 fprintf (outf, "(nil)");
767 fprintf (outf, ", next block ");
768 if (bb->next_bb)
769 fprintf (outf, "%d", bb->next_bb->index);
770 else
771 fprintf (outf, "(nil)");
772
773 fputs (", flags:", outf);
c4669594 774 first = true;
a315c44c
SB
775 for (i = 0; i < n_bitnames; i++)
776 if (bb->flags & (1 << i))
777 {
778 if (first)
779 fputs (" (", outf);
780 else
781 fputs (", ", outf);
782 first = false;
783 fputs (bb_bitnames[i], outf);
784 }
785 if (!first)
786 fputc (')', outf);
c4669594 787 fputc ('\n', outf);
a315c44c 788 }
a315c44c
SB
789
790 if (flags & TDF_COMMENT)
791 fputs (";; ", outf);
792 fprintf (outf, "%s pred: ", s_indent);
c4669594 793 first = true;
a315c44c 794 FOR_EACH_EDGE (e, ei, bb->preds)
c4669594
SB
795 {
796 if (! first)
797 {
798 if (flags & TDF_COMMENT)
799 fputs (";; ", outf);
800 fprintf (outf, "%s ", s_indent);
801 }
802 first = false;
803 dump_edge_info (outf, e, flags, 0);
804 fputc ('\n', outf);
805 }
1dd5907e
SB
806 if (first)
807 fputc ('\n', outf);
a315c44c
SB
808 }
809
810 if (do_footer)
811 {
a315c44c
SB
812 if (flags & TDF_COMMENT)
813 fputs (";; ", outf);
814 fprintf (outf, "%s succ: ", s_indent);
c4669594 815 first = true;
a315c44c 816 FOR_EACH_EDGE (e, ei, bb->succs)
c4669594
SB
817 {
818 if (! first)
819 {
820 if (flags & TDF_COMMENT)
821 fputs (";; ", outf);
822 fprintf (outf, "%s ", s_indent);
823 }
824 first = false;
825 dump_edge_info (outf, e, flags, 1);
826 fputc ('\n', outf);
827 }
1dd5907e
SB
828 if (first)
829 fputc ('\n', outf);
a315c44c 830 }
6de9cd9a
DN
831}
832
833/* Dumps a brief description of cfg to FILE. */
834
835void
c4669594 836brief_dump_cfg (FILE *file, int flags)
6de9cd9a
DN
837{
838 basic_block bb;
839
11cd3bed 840 FOR_EACH_BB_FN (bb, cfun)
6de9cd9a 841 {
c4669594
SB
842 dump_bb_info (file, bb, 0,
843 flags & (TDF_COMMENT | TDF_DETAILS),
844 true, true);
6de9cd9a
DN
845 }
846}
15db5571
JH
847
848/* An edge originally destinating BB of FREQUENCY and COUNT has been proved to
849 leave the block by TAKEN_EDGE. Update profile of BB such that edge E can be
c22cacf3 850 redirected to destination of TAKEN_EDGE.
15db5571
JH
851
852 This function may leave the profile inconsistent in the case TAKEN_EDGE
853 frequency or count is believed to be lower than FREQUENCY or COUNT
d4a9b3a3 854 respectively. */
15db5571
JH
855void
856update_bb_profile_for_threading (basic_block bb, int edge_frequency,
857 gcov_type count, edge taken_edge)
858{
859 edge c;
860 int prob;
628f6a4e 861 edge_iterator ei;
15db5571
JH
862
863 bb->count -= count;
864 if (bb->count < 0)
2b151cb2
JH
865 {
866 if (dump_file)
867 fprintf (dump_file, "bb %i count became negative after threading",
868 bb->index);
869 bb->count = 0;
870 }
15db5571
JH
871
872 /* Compute the probability of TAKEN_EDGE being reached via threaded edge.
873 Watch for overflows. */
874 if (bb->frequency)
8b47039c 875 prob = GCOV_COMPUTE_SCALE (edge_frequency, bb->frequency);
15db5571
JH
876 else
877 prob = 0;
878 if (prob > taken_edge->probability)
879 {
880 if (dump_file)
881 fprintf (dump_file, "Jump threading proved probability of edge "
882 "%i->%i too small (it is %i, should be %i).\n",
883 taken_edge->src->index, taken_edge->dest->index,
884 taken_edge->probability, prob);
885 prob = taken_edge->probability;
886 }
887
888 /* Now rescale the probabilities. */
889 taken_edge->probability -= prob;
890 prob = REG_BR_PROB_BASE - prob;
891 bb->frequency -= edge_frequency;
892 if (bb->frequency < 0)
893 bb->frequency = 0;
894 if (prob <= 0)
895 {
896 if (dump_file)
897 fprintf (dump_file, "Edge frequencies of bb %i has been reset, "
898 "frequency of block should end up being 0, it is %i\n",
899 bb->index, bb->frequency);
628f6a4e
BE
900 EDGE_SUCC (bb, 0)->probability = REG_BR_PROB_BASE;
901 ei = ei_start (bb->succs);
902 ei_next (&ei);
903 for (; (c = ei_safe_edge (ei)); ei_next (&ei))
15db5571
JH
904 c->probability = 0;
905 }
763ea904
JL
906 else if (prob != REG_BR_PROB_BASE)
907 {
09bac500 908 int scale = RDIV (65536 * REG_BR_PROB_BASE, prob);
763ea904
JL
909
910 FOR_EACH_EDGE (c, ei, bb->succs)
84fc24e8 911 {
3bc8ba25
EB
912 /* Protect from overflow due to additional scaling. */
913 if (c->probability > prob)
84fc24e8 914 c->probability = REG_BR_PROB_BASE;
3bc8ba25
EB
915 else
916 {
917 c->probability = RDIV (c->probability * scale, 65536);
918 if (c->probability > REG_BR_PROB_BASE)
919 c->probability = REG_BR_PROB_BASE;
920 }
84fc24e8 921 }
763ea904 922 }
15db5571 923
41806d92 924 gcc_assert (bb == taken_edge->src);
15db5571
JH
925 taken_edge->count -= count;
926 if (taken_edge->count < 0)
2b151cb2
JH
927 {
928 if (dump_file)
929 fprintf (dump_file, "edge %i->%i count became negative after threading",
930 taken_edge->src->index, taken_edge->dest->index);
931 taken_edge->count = 0;
932 }
15db5571 933}
33156717
JH
934
935/* Multiply all frequencies of basic blocks in array BBS of length NBBS
936 by NUM/DEN, in int arithmetic. May lose some accuracy. */
937void
938scale_bbs_frequencies_int (basic_block *bbs, int nbbs, int num, int den)
939{
940 int i;
941 edge e;
84fc24e8
JH
942 if (num < 0)
943 num = 0;
03cb2019
ZD
944
945 /* Scale NUM and DEN to avoid overflows. Frequencies are in order of
946 10^4, if we make DEN <= 10^3, we can afford to upscale by 100
947 and still safely fit in int during calculations. */
948 if (den > 1000)
949 {
950 if (num > 1000000)
951 return;
952
953 num = RDIV (1000 * num, den);
954 den = 1000;
955 }
956 if (num > 100 * den)
84fc24e8 957 return;
03cb2019 958
33156717
JH
959 for (i = 0; i < nbbs; i++)
960 {
961 edge_iterator ei;
09bac500 962 bbs[i]->frequency = RDIV (bbs[i]->frequency * num, den);
03cb2019
ZD
963 /* Make sure the frequencies do not grow over BB_FREQ_MAX. */
964 if (bbs[i]->frequency > BB_FREQ_MAX)
965 bbs[i]->frequency = BB_FREQ_MAX;
33156717
JH
966 bbs[i]->count = RDIV (bbs[i]->count * num, den);
967 FOR_EACH_EDGE (e, ei, bbs[i]->succs)
09bac500 968 e->count = RDIV (e->count * num, den);
33156717
JH
969 }
970}
971
09bac500
JH
972/* numbers smaller than this value are safe to multiply without getting
973 64bit overflow. */
a9243bfc 974#define MAX_SAFE_MULTIPLIER (1 << (sizeof (int64_t) * 4 - 1))
09bac500 975
33156717
JH
976/* Multiply all frequencies of basic blocks in array BBS of length NBBS
977 by NUM/DEN, in gcov_type arithmetic. More accurate than previous
978 function but considerably slower. */
979void
c22cacf3
MS
980scale_bbs_frequencies_gcov_type (basic_block *bbs, int nbbs, gcov_type num,
981 gcov_type den)
33156717
JH
982{
983 int i;
984 edge e;
09bac500 985 gcov_type fraction = RDIV (num * 65536, den);
33156717 986
09bac500
JH
987 gcc_assert (fraction >= 0);
988
989 if (num < MAX_SAFE_MULTIPLIER)
990 for (i = 0; i < nbbs; i++)
991 {
992 edge_iterator ei;
993 bbs[i]->frequency = RDIV (bbs[i]->frequency * num, den);
994 if (bbs[i]->count <= MAX_SAFE_MULTIPLIER)
995 bbs[i]->count = RDIV (bbs[i]->count * num, den);
996 else
997 bbs[i]->count = RDIV (bbs[i]->count * fraction, 65536);
998 FOR_EACH_EDGE (e, ei, bbs[i]->succs)
999 if (bbs[i]->count <= MAX_SAFE_MULTIPLIER)
1000 e->count = RDIV (e->count * num, den);
1001 else
1002 e->count = RDIV (e->count * fraction, 65536);
1003 }
1004 else
1005 for (i = 0; i < nbbs; i++)
1006 {
1007 edge_iterator ei;
1008 if (sizeof (gcov_type) > sizeof (int))
1009 bbs[i]->frequency = RDIV (bbs[i]->frequency * num, den);
1010 else
1011 bbs[i]->frequency = RDIV (bbs[i]->frequency * fraction, 65536);
1012 bbs[i]->count = RDIV (bbs[i]->count * fraction, 65536);
1013 FOR_EACH_EDGE (e, ei, bbs[i]->succs)
1014 e->count = RDIV (e->count * fraction, 65536);
1015 }
33156717 1016}
6580ee77 1017
703c8606 1018/* Helper types for hash tables. */
6580ee77
JH
1019
1020struct htab_bb_copy_original_entry
1021{
1022 /* Block we are attaching info to. */
1023 int index1;
1024 /* Index of original or copy (depending on the hashtable) */
1025 int index2;
1026};
1027
8d67ee55 1028struct bb_copy_hasher : nofree_ptr_hash <htab_bb_copy_original_entry>
6580ee77 1029{
67f58944
TS
1030 static inline hashval_t hash (const htab_bb_copy_original_entry *);
1031 static inline bool equal (const htab_bb_copy_original_entry *existing,
1032 const htab_bb_copy_original_entry * candidate);
703c8606 1033};
6580ee77 1034
703c8606 1035inline hashval_t
67f58944 1036bb_copy_hasher::hash (const htab_bb_copy_original_entry *data)
703c8606 1037{
6580ee77
JH
1038 return data->index1;
1039}
6580ee77 1040
703c8606 1041inline bool
67f58944
TS
1042bb_copy_hasher::equal (const htab_bb_copy_original_entry *data,
1043 const htab_bb_copy_original_entry *data2)
703c8606 1044{
6580ee77
JH
1045 return data->index1 == data2->index1;
1046}
1047
703c8606
LC
1048/* Data structures used to maintain mapping between basic blocks and
1049 copies. */
c203e8a7
TS
1050static hash_table<bb_copy_hasher> *bb_original;
1051static hash_table<bb_copy_hasher> *bb_copy;
703c8606
LC
1052
1053/* And between loops and copies. */
c203e8a7 1054static hash_table<bb_copy_hasher> *loop_copy;
fb0b2914 1055static object_allocator<htab_bb_copy_original_entry> *original_copy_bb_pool;
703c8606 1056
f341de7b
KH
1057/* Initialize the data structures to maintain mapping between blocks
1058 and its copies. */
6580ee77
JH
1059void
1060initialize_original_copy_tables (void)
1061{
fb0b2914 1062 original_copy_bb_pool = new object_allocator<htab_bb_copy_original_entry>
fcb87c50 1063 ("original_copy");
c203e8a7
TS
1064 bb_original = new hash_table<bb_copy_hasher> (10);
1065 bb_copy = new hash_table<bb_copy_hasher> (10);
1066 loop_copy = new hash_table<bb_copy_hasher> (10);
6580ee77
JH
1067}
1068
f341de7b
KH
1069/* Free the data structures to maintain mapping between blocks and
1070 its copies. */
6580ee77
JH
1071void
1072free_original_copy_tables (void)
1073{
1074 gcc_assert (original_copy_bb_pool);
c203e8a7
TS
1075 delete bb_copy;
1076 bb_copy = NULL;
1077 delete bb_original;
1078 bb_copy = NULL;
1079 delete loop_copy;
1080 loop_copy = NULL;
ac0539d7 1081 delete original_copy_bb_pool;
6580ee77
JH
1082 original_copy_bb_pool = NULL;
1083}
1084
561e8a90
ZD
1085/* Removes the value associated with OBJ from table TAB. */
1086
1087static void
c203e8a7 1088copy_original_table_clear (hash_table<bb_copy_hasher> *tab, unsigned obj)
561e8a90 1089{
703c8606 1090 htab_bb_copy_original_entry **slot;
561e8a90
ZD
1091 struct htab_bb_copy_original_entry key, *elt;
1092
1093 if (!original_copy_bb_pool)
1094 return;
1095
1096 key.index1 = obj;
c203e8a7 1097 slot = tab->find_slot (&key, NO_INSERT);
561e8a90
ZD
1098 if (!slot)
1099 return;
1100
703c8606 1101 elt = *slot;
c203e8a7 1102 tab->clear_slot (slot);
ac0539d7 1103 original_copy_bb_pool->remove (elt);
561e8a90
ZD
1104}
1105
1106/* Sets the value associated with OBJ in table TAB to VAL.
1107 Do nothing when data structures are not initialized. */
1108
1109static void
c203e8a7 1110copy_original_table_set (hash_table<bb_copy_hasher> *tab,
703c8606 1111 unsigned obj, unsigned val)
561e8a90
ZD
1112{
1113 struct htab_bb_copy_original_entry **slot;
1114 struct htab_bb_copy_original_entry key;
1115
1116 if (!original_copy_bb_pool)
1117 return;
1118
1119 key.index1 = obj;
c203e8a7 1120 slot = tab->find_slot (&key, INSERT);
561e8a90
ZD
1121 if (!*slot)
1122 {
ac0539d7 1123 *slot = original_copy_bb_pool->allocate ();
561e8a90
ZD
1124 (*slot)->index1 = obj;
1125 }
1126 (*slot)->index2 = val;
1127}
1128
f341de7b
KH
1129/* Set original for basic block. Do nothing when data structures are not
1130 initialized so passes not needing this don't need to care. */
6580ee77
JH
1131void
1132set_bb_original (basic_block bb, basic_block original)
1133{
561e8a90 1134 copy_original_table_set (bb_original, bb->index, original->index);
6580ee77
JH
1135}
1136
1137/* Get the original basic block. */
1138basic_block
1139get_bb_original (basic_block bb)
1140{
1141 struct htab_bb_copy_original_entry *entry;
1142 struct htab_bb_copy_original_entry key;
1143
1144 gcc_assert (original_copy_bb_pool);
1145
1146 key.index1 = bb->index;
c203e8a7 1147 entry = bb_original->find (&key);
6580ee77 1148 if (entry)
06e28de2 1149 return BASIC_BLOCK_FOR_FN (cfun, entry->index2);
6580ee77
JH
1150 else
1151 return NULL;
1152}
1153
f341de7b
KH
1154/* Set copy for basic block. Do nothing when data structures are not
1155 initialized so passes not needing this don't need to care. */
6580ee77
JH
1156void
1157set_bb_copy (basic_block bb, basic_block copy)
1158{
561e8a90 1159 copy_original_table_set (bb_copy, bb->index, copy->index);
6580ee77
JH
1160}
1161
1162/* Get the copy of basic block. */
1163basic_block
1164get_bb_copy (basic_block bb)
1165{
1166 struct htab_bb_copy_original_entry *entry;
1167 struct htab_bb_copy_original_entry key;
1168
1169 gcc_assert (original_copy_bb_pool);
1170
1171 key.index1 = bb->index;
c203e8a7 1172 entry = bb_copy->find (&key);
6580ee77 1173 if (entry)
06e28de2 1174 return BASIC_BLOCK_FOR_FN (cfun, entry->index2);
6580ee77
JH
1175 else
1176 return NULL;
1177}
561e8a90
ZD
1178
1179/* Set copy for LOOP to COPY. Do nothing when data structures are not
1180 initialized so passes not needing this don't need to care. */
1181
1182void
1183set_loop_copy (struct loop *loop, struct loop *copy)
1184{
1185 if (!copy)
1186 copy_original_table_clear (loop_copy, loop->num);
1187 else
1188 copy_original_table_set (loop_copy, loop->num, copy->num);
1189}
1190
1191/* Get the copy of LOOP. */
1192
1193struct loop *
1194get_loop_copy (struct loop *loop)
1195{
1196 struct htab_bb_copy_original_entry *entry;
1197 struct htab_bb_copy_original_entry key;
1198
1199 gcc_assert (original_copy_bb_pool);
1200
1201 key.index1 = loop->num;
c203e8a7 1202 entry = loop_copy->find (&key);
561e8a90 1203 if (entry)
0fc822d0 1204 return get_loop (cfun, entry->index2);
561e8a90
ZD
1205 else
1206 return NULL;
1207}