OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [gimple-iterator.c] - Blame information for rev 733

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 684 jeremybenn
/* Iterator routines for GIMPLE statements.
2
   Copyright (C) 2007, 2008, 2010 Free Software Foundation, Inc.
3
   Contributed by Aldy Hernandez  <aldy@quesejoda.com>
4
 
5
This file is part of GCC.
6
 
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.
11
 
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.
16
 
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/>.  */
20
 
21
#include "config.h"
22
#include "system.h"
23
#include "coretypes.h"
24
#include "tm.h"
25
#include "tree.h"
26
#include "gimple.h"
27
#include "tree-flow.h"
28
#include "value-prof.h"
29
 
30
 
31
/* Mark the statement STMT as modified, and update it.  */
32
 
33
static inline void
34
update_modified_stmt (gimple stmt)
35
{
36
  if (!ssa_operands_active ())
37
    return;
38
  update_stmt_if_modified (stmt);
39
}
40
 
41
 
42
/* Mark the statements in SEQ as modified, and update them.  */
43
 
44
static void
45
update_modified_stmts (gimple_seq seq)
46
{
47
  gimple_stmt_iterator gsi;
48
 
49
  if (!ssa_operands_active ())
50
    return;
51
  for (gsi = gsi_start (seq); !gsi_end_p (gsi); gsi_next (&gsi))
52
    update_stmt_if_modified (gsi_stmt (gsi));
53
}
54
 
55
 
56
/* Set BB to be the basic block for all the statements in the list
57
   starting at FIRST and LAST.  */
58
 
59
static void
60
update_bb_for_stmts (gimple_seq_node first, basic_block bb)
61
{
62
  gimple_seq_node n;
63
 
64
  for (n = first; n; n = n->next)
65
    gimple_set_bb (n->stmt, bb);
66
}
67
 
68
/* Set the frequencies for the cgraph_edges for each of the calls
69
   starting at FIRST for their new position within BB.  */
70
 
71
static void
72
update_call_edge_frequencies (gimple_seq_node first, basic_block bb)
73
{
74
  struct cgraph_node *cfun_node = NULL;
75
  int bb_freq = 0;
76
  gimple_seq_node n;
77
 
78
  for (n = first; n ; n = n->next)
79
    if (is_gimple_call (n->stmt))
80
      {
81
        struct cgraph_edge *e;
82
 
83
        /* These function calls are expensive enough that we want
84
           to avoid calling them if we never see any calls.  */
85
        if (cfun_node == NULL)
86
          {
87
            cfun_node = cgraph_get_node (current_function_decl);
88
            bb_freq = (compute_call_stmt_bb_frequency
89
                       (current_function_decl, bb));
90
          }
91
 
92
        e = cgraph_edge (cfun_node, n->stmt);
93
        if (e != NULL)
94
          e->frequency = bb_freq;
95
      }
96
}
97
 
98
/* Insert the sequence delimited by nodes FIRST and LAST before
99
   iterator I.  M specifies how to update iterator I after insertion
100
   (see enum gsi_iterator_update).
101
 
102
   This routine assumes that there is a forward and backward path
103
   between FIRST and LAST (i.e., they are linked in a doubly-linked
104
   list).  Additionally, if FIRST == LAST, this routine will properly
105
   insert a single node.  */
106
 
107
static void
108
gsi_insert_seq_nodes_before (gimple_stmt_iterator *i,
109
                             gimple_seq_node first,
110
                             gimple_seq_node last,
111
                             enum gsi_iterator_update mode)
112
{
113
  basic_block bb;
114
  gimple_seq_node cur = i->ptr;
115
 
116
  if ((bb = gsi_bb (*i)) != NULL)
117
    update_bb_for_stmts (first, bb);
118
 
119
  /* Link SEQ before CUR in the sequence.  */
120
  if (cur)
121
    {
122
      first->prev = cur->prev;
123
      if (first->prev)
124
        first->prev->next = first;
125
      else
126
        gimple_seq_set_first (i->seq, first);
127
      last->next = cur;
128
      cur->prev = last;
129
    }
130
  else
131
    {
132
      gimple_seq_node itlast = gimple_seq_last (i->seq);
133
 
134
      /* If CUR is NULL, we link at the end of the sequence (this case happens
135
         when gsi_after_labels is called for a basic block that contains only
136
         labels, so it returns an iterator after the end of the block, and
137
         we need to insert before it; it might be cleaner to add a flag to the
138
         iterator saying whether we are at the start or end of the list).  */
139
      first->prev = itlast;
140
      if (itlast)
141
        itlast->next = first;
142
      else
143
        gimple_seq_set_first (i->seq, first);
144
      gimple_seq_set_last (i->seq, last);
145
    }
146
 
147
  /* Update the iterator, if requested.  */
148
  switch (mode)
149
    {
150
    case GSI_NEW_STMT:
151
    case GSI_CONTINUE_LINKING:
152
      i->ptr = first;
153
      break;
154
    case GSI_SAME_STMT:
155
      break;
156
    default:
157
      gcc_unreachable ();
158
    }
159
}
160
 
161
 
162
/* Inserts the sequence of statements SEQ before the statement pointed
163
   by iterator I.  MODE indicates what to do with the iterator after
164
   insertion (see enum gsi_iterator_update).
165
 
166
   This function does not scan for new operands.  It is provided for
167
   the use of the gimplifier, which manipulates statements for which
168
   def/use information has not yet been constructed.  Most callers
169
   should use gsi_insert_seq_before.  */
170
 
171
void
172
gsi_insert_seq_before_without_update (gimple_stmt_iterator *i, gimple_seq seq,
173
                                      enum gsi_iterator_update mode)
174
{
175
  gimple_seq_node first, last;
176
 
177
  if (seq == NULL)
178
    return;
179
 
180
  /* Don't allow inserting a sequence into itself.  */
181
  gcc_assert (seq != i->seq);
182
 
183
  first = gimple_seq_first (seq);
184
  last = gimple_seq_last (seq);
185
 
186
  gimple_seq_set_first (seq, NULL);
187
  gimple_seq_set_last (seq, NULL);
188
  gimple_seq_free (seq);
189
 
190
  /* Empty sequences need no work.  */
191
  if (!first || !last)
192
    {
193
      gcc_assert (first == last);
194
      return;
195
    }
196
 
197
  gsi_insert_seq_nodes_before (i, first, last, mode);
198
}
199
 
200
 
201
/* Inserts the sequence of statements SEQ before the statement pointed
202
   by iterator I.  MODE indicates what to do with the iterator after
203
   insertion (see enum gsi_iterator_update). Scan the statements in SEQ
204
   for new operands.  */
205
 
206
void
207
gsi_insert_seq_before (gimple_stmt_iterator *i, gimple_seq seq,
208
                       enum gsi_iterator_update mode)
209
{
210
  update_modified_stmts (seq);
211
  gsi_insert_seq_before_without_update (i, seq, mode);
212
}
213
 
214
 
215
/* Insert the sequence delimited by nodes FIRST and LAST after
216
   iterator I.  M specifies how to update iterator I after insertion
217
   (see enum gsi_iterator_update).
218
 
219
   This routine assumes that there is a forward and backward path
220
   between FIRST and LAST (i.e., they are linked in a doubly-linked
221
   list).  Additionally, if FIRST == LAST, this routine will properly
222
   insert a single node.  */
223
 
224
static void
225
gsi_insert_seq_nodes_after (gimple_stmt_iterator *i,
226
                            gimple_seq_node first,
227
                            gimple_seq_node last,
228
                            enum gsi_iterator_update m)
229
{
230
  basic_block bb;
231
  gimple_seq_node cur = i->ptr;
232
 
233
  /* If the iterator is inside a basic block, we need to update the
234
     basic block information for all the nodes between FIRST and LAST.  */
235
  if ((bb = gsi_bb (*i)) != NULL)
236
    update_bb_for_stmts (first, bb);
237
 
238
  /* Link SEQ after CUR.  */
239
  if (cur)
240
    {
241
      last->next = cur->next;
242
      if (last->next)
243
        last->next->prev = last;
244
      else
245
        gimple_seq_set_last (i->seq, last);
246
      first->prev = cur;
247
      cur->next = first;
248
    }
249
  else
250
    {
251
      gcc_assert (!gimple_seq_last (i->seq));
252
      gimple_seq_set_first (i->seq, first);
253
      gimple_seq_set_last (i->seq, last);
254
    }
255
 
256
  /* Update the iterator, if requested.  */
257
  switch (m)
258
    {
259
    case GSI_NEW_STMT:
260
      i->ptr = first;
261
      break;
262
    case GSI_CONTINUE_LINKING:
263
      i->ptr = last;
264
      break;
265
    case GSI_SAME_STMT:
266
      gcc_assert (cur);
267
      break;
268
    default:
269
      gcc_unreachable ();
270
    }
271
}
272
 
273
 
274
/* Links sequence SEQ after the statement pointed-to by iterator I.
275
   MODE is as in gsi_insert_after.
276
 
277
   This function does not scan for new operands.  It is provided for
278
   the use of the gimplifier, which manipulates statements for which
279
   def/use information has not yet been constructed.  Most callers
280
   should use gsi_insert_seq_after.  */
281
 
282
void
283
gsi_insert_seq_after_without_update (gimple_stmt_iterator *i, gimple_seq seq,
284
                                     enum gsi_iterator_update mode)
285
{
286
  gimple_seq_node first, last;
287
 
288
  if (seq == NULL)
289
    return;
290
 
291
  /* Don't allow inserting a sequence into itself.  */
292
  gcc_assert (seq != i->seq);
293
 
294
  first = gimple_seq_first (seq);
295
  last = gimple_seq_last (seq);
296
 
297
  gimple_seq_set_first (seq, NULL);
298
  gimple_seq_set_last (seq, NULL);
299
  gimple_seq_free (seq);
300
 
301
  /* Empty sequences need no work.  */
302
  if (!first || !last)
303
    {
304
      gcc_assert (first == last);
305
      return;
306
    }
307
 
308
  gsi_insert_seq_nodes_after (i, first, last, mode);
309
}
310
 
311
 
312
/* Links sequence SEQ after the statement pointed-to by iterator I.
313
   MODE is as in gsi_insert_after.  Scan the statements in SEQ
314
   for new operands.  */
315
 
316
void
317
gsi_insert_seq_after (gimple_stmt_iterator *i, gimple_seq seq,
318
                      enum gsi_iterator_update mode)
319
{
320
  update_modified_stmts (seq);
321
  gsi_insert_seq_after_without_update (i, seq, mode);
322
}
323
 
324
 
325
/* Move all statements in the sequence after I to a new sequence.
326
   Return this new sequence.  */
327
 
328
gimple_seq
329
gsi_split_seq_after (gimple_stmt_iterator i)
330
{
331
  gimple_seq_node cur, next;
332
  gimple_seq old_seq, new_seq;
333
 
334
  cur = i.ptr;
335
 
336
  /* How can we possibly split after the end, or before the beginning?  */
337
  gcc_assert (cur && cur->next);
338
  next = cur->next;
339
 
340
  old_seq = i.seq;
341
  new_seq = gimple_seq_alloc ();
342
 
343
  gimple_seq_set_first (new_seq, next);
344
  gimple_seq_set_last (new_seq, gimple_seq_last (old_seq));
345
  gimple_seq_set_last (old_seq, cur);
346
  cur->next = NULL;
347
  next->prev = NULL;
348
 
349
  return new_seq;
350
}
351
 
352
 
353
/* Move all statements in the sequence before I to a new sequence.
354
   Return this new sequence.  I is set to the head of the new list.  */
355
 
356
gimple_seq
357
gsi_split_seq_before (gimple_stmt_iterator *i)
358
{
359
  gimple_seq_node cur, prev;
360
  gimple_seq old_seq, new_seq;
361
 
362
  cur = i->ptr;
363
 
364
  /* How can we possibly split after the end?  */
365
  gcc_assert (cur);
366
  prev = cur->prev;
367
 
368
  old_seq = i->seq;
369
  new_seq = gimple_seq_alloc ();
370
  i->seq = new_seq;
371
 
372
  /* Set the limits on NEW_SEQ.  */
373
  gimple_seq_set_first (new_seq, cur);
374
  gimple_seq_set_last (new_seq, gimple_seq_last (old_seq));
375
 
376
  /* Cut OLD_SEQ before I.  */
377
  gimple_seq_set_last (old_seq, prev);
378
  cur->prev = NULL;
379
  if (prev)
380
    prev->next = NULL;
381
  else
382
    gimple_seq_set_first (old_seq, NULL);
383
 
384
  return new_seq;
385
}
386
 
387
 
388
/* Replace the statement pointed-to by GSI to STMT.  If UPDATE_EH_INFO
389
   is true, the exception handling information of the original
390
   statement is moved to the new statement.  Assignments must only be
391
   replaced with assignments to the same LHS.  */
392
 
393
void
394
gsi_replace (gimple_stmt_iterator *gsi, gimple stmt, bool update_eh_info)
395
{
396
  gimple orig_stmt = gsi_stmt (*gsi);
397
 
398
  if (stmt == orig_stmt)
399
    return;
400
 
401
  gcc_assert (!gimple_has_lhs (orig_stmt)
402
              || gimple_get_lhs (orig_stmt) == gimple_get_lhs (stmt));
403
 
404
  gimple_set_location (stmt, gimple_location (orig_stmt));
405
  gimple_set_bb (stmt, gsi_bb (*gsi));
406
 
407
  /* Preserve EH region information from the original statement, if
408
     requested by the caller.  */
409
  if (update_eh_info)
410
    maybe_clean_or_replace_eh_stmt (orig_stmt, stmt);
411
 
412
  gimple_duplicate_stmt_histograms (cfun, stmt, cfun, orig_stmt);
413
 
414
  /* Free all the data flow information for ORIG_STMT.  */
415
  gimple_set_bb (orig_stmt, NULL);
416
  gimple_remove_stmt_histograms (cfun, orig_stmt);
417
  delink_stmt_imm_use (orig_stmt);
418
 
419
  *gsi_stmt_ptr (gsi) = stmt;
420
  gimple_set_modified (stmt, true);
421
  update_modified_stmt (stmt);
422
}
423
 
424
 
425
/* Insert statement STMT before the statement pointed-to by iterator I.
426
   M specifies how to update iterator I after insertion (see enum
427
   gsi_iterator_update).
428
 
429
   This function does not scan for new operands.  It is provided for
430
   the use of the gimplifier, which manipulates statements for which
431
   def/use information has not yet been constructed.  Most callers
432
   should use gsi_insert_before.  */
433
 
434
void
435
gsi_insert_before_without_update (gimple_stmt_iterator *i, gimple stmt,
436
                                  enum gsi_iterator_update m)
437
{
438
  gimple_seq_node n;
439
 
440
  n = ggc_alloc_gimple_seq_node_d ();
441
  n->prev = n->next = NULL;
442
  n->stmt = stmt;
443
  gsi_insert_seq_nodes_before (i, n, n, m);
444
}
445
 
446
/* Insert statement STMT before the statement pointed-to by iterator I.
447
   Update STMT's basic block and scan it for new operands.  M
448
   specifies how to update iterator I after insertion (see enum
449
   gsi_iterator_update).  */
450
 
451
void
452
gsi_insert_before (gimple_stmt_iterator *i, gimple stmt,
453
                   enum gsi_iterator_update m)
454
{
455
  update_modified_stmt (stmt);
456
  gsi_insert_before_without_update (i, stmt, m);
457
}
458
 
459
 
460
/* Insert statement STMT after the statement pointed-to by iterator I.
461
   M specifies how to update iterator I after insertion (see enum
462
   gsi_iterator_update).
463
 
464
   This function does not scan for new operands.  It is provided for
465
   the use of the gimplifier, which manipulates statements for which
466
   def/use information has not yet been constructed.  Most callers
467
   should use gsi_insert_after.  */
468
 
469
void
470
gsi_insert_after_without_update (gimple_stmt_iterator *i, gimple stmt,
471
                                 enum gsi_iterator_update m)
472
{
473
  gimple_seq_node n;
474
 
475
  n = ggc_alloc_gimple_seq_node_d ();
476
  n->prev = n->next = NULL;
477
  n->stmt = stmt;
478
  gsi_insert_seq_nodes_after (i, n, n, m);
479
}
480
 
481
 
482
/* Insert statement STMT after the statement pointed-to by iterator I.
483
   Update STMT's basic block and scan it for new operands.  M
484
   specifies how to update iterator I after insertion (see enum
485
   gsi_iterator_update).  */
486
 
487
void
488
gsi_insert_after (gimple_stmt_iterator *i, gimple stmt,
489
                  enum gsi_iterator_update m)
490
{
491
  update_modified_stmt (stmt);
492
  gsi_insert_after_without_update (i, stmt, m);
493
}
494
 
495
 
496
/* Remove the current stmt from the sequence.  The iterator is updated
497
   to point to the next statement.
498
 
499
   REMOVE_PERMANENTLY is true when the statement is going to be removed
500
   from the IL and not reinserted elsewhere.  In that case we remove the
501
   statement pointed to by iterator I from the EH tables, and free its
502
   operand caches.  Otherwise we do not modify this information.  */
503
 
504
void
505
gsi_remove (gimple_stmt_iterator *i, bool remove_permanently)
506
{
507
  gimple_seq_node cur, next, prev;
508
  gimple stmt = gsi_stmt (*i);
509
 
510
  if (gimple_code (stmt) != GIMPLE_PHI)
511
    insert_debug_temps_for_defs (i);
512
 
513
  /* Free all the data flow information for STMT.  */
514
  gimple_set_bb (stmt, NULL);
515
  delink_stmt_imm_use (stmt);
516
  gimple_set_modified (stmt, true);
517
 
518
  if (remove_permanently)
519
    {
520
      remove_stmt_from_eh_lp (stmt);
521
      gimple_remove_stmt_histograms (cfun, stmt);
522
    }
523
 
524
  /* Update the iterator and re-wire the links in I->SEQ.  */
525
  cur = i->ptr;
526
  next = cur->next;
527
  prev = cur->prev;
528
 
529
  if (prev)
530
    prev->next = next;
531
  else
532
    gimple_seq_set_first (i->seq, next);
533
 
534
  if (next)
535
    next->prev = prev;
536
  else
537
    gimple_seq_set_last (i->seq, prev);
538
 
539
  i->ptr = next;
540
}
541
 
542
 
543
/* Finds iterator for STMT.  */
544
 
545
gimple_stmt_iterator
546
gsi_for_stmt (gimple stmt)
547
{
548
  gimple_stmt_iterator i;
549
  basic_block bb = gimple_bb (stmt);
550
 
551
  if (gimple_code (stmt) == GIMPLE_PHI)
552
    i = gsi_start_phis (bb);
553
  else
554
    i = gsi_start_bb (bb);
555
 
556
  for (; !gsi_end_p (i); gsi_next (&i))
557
    if (gsi_stmt (i) == stmt)
558
      return i;
559
 
560
  gcc_unreachable ();
561
}
562
 
563
 
564
/* Move the statement at FROM so it comes right after the statement at TO.  */
565
 
566
void
567
gsi_move_after (gimple_stmt_iterator *from, gimple_stmt_iterator *to)
568
{
569
  gimple stmt = gsi_stmt (*from);
570
  gsi_remove (from, false);
571
 
572
  /* We must have GSI_NEW_STMT here, as gsi_move_after is sometimes used to
573
     move statements to an empty block.  */
574
  gsi_insert_after (to, stmt, GSI_NEW_STMT);
575
}
576
 
577
 
578
/* Move the statement at FROM so it comes right before the statement
579
   at TO.  */
580
 
581
void
582
gsi_move_before (gimple_stmt_iterator *from, gimple_stmt_iterator *to)
583
{
584
  gimple stmt = gsi_stmt (*from);
585
  gsi_remove (from, false);
586
 
587
  /* For consistency with gsi_move_after, it might be better to have
588
     GSI_NEW_STMT here; however, that breaks several places that expect
589
     that TO does not change.  */
590
  gsi_insert_before (to, stmt, GSI_SAME_STMT);
591
}
592
 
593
 
594
/* Move the statement at FROM to the end of basic block BB.  */
595
 
596
void
597
gsi_move_to_bb_end (gimple_stmt_iterator *from, basic_block bb)
598
{
599
  gimple_stmt_iterator last = gsi_last_bb (bb);
600
  gcc_checking_assert (gsi_bb (last) == bb);
601
 
602
  /* Have to check gsi_end_p because it could be an empty block.  */
603
  if (!gsi_end_p (last) && is_ctrl_stmt (gsi_stmt (last)))
604
    gsi_move_before (from, &last);
605
  else
606
    gsi_move_after (from, &last);
607
}
608
 
609
 
610
/* Add STMT to the pending list of edge E.  No actual insertion is
611
   made until a call to gsi_commit_edge_inserts () is made.  */
612
 
613
void
614
gsi_insert_on_edge (edge e, gimple stmt)
615
{
616
  gimple_seq_add_stmt (&PENDING_STMT (e), stmt);
617
}
618
 
619
/* Add the sequence of statements SEQ to the pending list of edge E.
620
   No actual insertion is made until a call to gsi_commit_edge_inserts
621
   is made.  */
622
 
623
void
624
gsi_insert_seq_on_edge (edge e, gimple_seq seq)
625
{
626
  gimple_seq_add_seq (&PENDING_STMT (e), seq);
627
}
628
 
629
 
630
/* Insert the statement pointed-to by GSI into edge E.  Every attempt
631
   is made to place the statement in an existing basic block, but
632
   sometimes that isn't possible.  When it isn't possible, the edge is
633
   split and the statement is added to the new block.
634
 
635
   In all cases, the returned *GSI points to the correct location.  The
636
   return value is true if insertion should be done after the location,
637
   or false if it should be done before the location.  If a new basic block
638
   has to be created, it is stored in *NEW_BB.  */
639
 
640
static bool
641
gimple_find_edge_insert_loc (edge e, gimple_stmt_iterator *gsi,
642
                             basic_block *new_bb)
643
{
644
  basic_block dest, src;
645
  gimple tmp;
646
 
647
  dest = e->dest;
648
 
649
  /* If the destination has one predecessor which has no PHI nodes,
650
     insert there.  Except for the exit block.
651
 
652
     The requirement for no PHI nodes could be relaxed.  Basically we
653
     would have to examine the PHIs to prove that none of them used
654
     the value set by the statement we want to insert on E.  That
655
     hardly seems worth the effort.  */
656
 restart:
657
  if (single_pred_p (dest)
658
      && gimple_seq_empty_p (phi_nodes (dest))
659
      && dest != EXIT_BLOCK_PTR)
660
    {
661
      *gsi = gsi_start_bb (dest);
662
      if (gsi_end_p (*gsi))
663
        return true;
664
 
665
      /* Make sure we insert after any leading labels.  */
666
      tmp = gsi_stmt (*gsi);
667
      while (gimple_code (tmp) == GIMPLE_LABEL)
668
        {
669
          gsi_next (gsi);
670
          if (gsi_end_p (*gsi))
671
            break;
672
          tmp = gsi_stmt (*gsi);
673
        }
674
 
675
      if (gsi_end_p (*gsi))
676
        {
677
          *gsi = gsi_last_bb (dest);
678
          return true;
679
        }
680
      else
681
        return false;
682
    }
683
 
684
  /* If the source has one successor, the edge is not abnormal and
685
     the last statement does not end a basic block, insert there.
686
     Except for the entry block.  */
687
  src = e->src;
688
  if ((e->flags & EDGE_ABNORMAL) == 0
689
      && single_succ_p (src)
690
      && src != ENTRY_BLOCK_PTR)
691
    {
692
      *gsi = gsi_last_bb (src);
693
      if (gsi_end_p (*gsi))
694
        return true;
695
 
696
      tmp = gsi_stmt (*gsi);
697
      if (!stmt_ends_bb_p (tmp))
698
        return true;
699
 
700
      switch (gimple_code (tmp))
701
        {
702
        case GIMPLE_RETURN:
703
        case GIMPLE_RESX:
704
          return false;
705
        default:
706
          break;
707
        }
708
    }
709
 
710
  /* Otherwise, create a new basic block, and split this edge.  */
711
  dest = split_edge (e);
712
  if (new_bb)
713
    *new_bb = dest;
714
  e = single_pred_edge (dest);
715
  goto restart;
716
}
717
 
718
 
719
/* Similar to gsi_insert_on_edge+gsi_commit_edge_inserts.  If a new
720
   block has to be created, it is returned.  */
721
 
722
basic_block
723
gsi_insert_on_edge_immediate (edge e, gimple stmt)
724
{
725
  gimple_stmt_iterator gsi;
726
  struct gimple_seq_node_d node;
727
  basic_block new_bb = NULL;
728
  bool ins_after;
729
 
730
  gcc_assert (!PENDING_STMT (e));
731
 
732
  ins_after = gimple_find_edge_insert_loc (e, &gsi, &new_bb);
733
 
734
  node.stmt = stmt;
735
  node.prev = node.next = NULL;
736
  update_call_edge_frequencies (&node, gsi.bb);
737
 
738
  if (ins_after)
739
    gsi_insert_after (&gsi, stmt, GSI_NEW_STMT);
740
  else
741
    gsi_insert_before (&gsi, stmt, GSI_NEW_STMT);
742
 
743
  return new_bb;
744
}
745
 
746
/* Insert STMTS on edge E.  If a new block has to be created, it
747
   is returned.  */
748
 
749
basic_block
750
gsi_insert_seq_on_edge_immediate (edge e, gimple_seq stmts)
751
{
752
  gimple_stmt_iterator gsi;
753
  basic_block new_bb = NULL;
754
  bool ins_after;
755
 
756
  gcc_assert (!PENDING_STMT (e));
757
 
758
  ins_after = gimple_find_edge_insert_loc (e, &gsi, &new_bb);
759
  update_call_edge_frequencies (gimple_seq_first (stmts), gsi.bb);
760
 
761
  if (ins_after)
762
    gsi_insert_seq_after (&gsi, stmts, GSI_NEW_STMT);
763
  else
764
    gsi_insert_seq_before (&gsi, stmts, GSI_NEW_STMT);
765
 
766
  return new_bb;
767
}
768
 
769
/* This routine will commit all pending edge insertions, creating any new
770
   basic blocks which are necessary.  */
771
 
772
void
773
gsi_commit_edge_inserts (void)
774
{
775
  basic_block bb;
776
  edge e;
777
  edge_iterator ei;
778
 
779
  gsi_commit_one_edge_insert (single_succ_edge (ENTRY_BLOCK_PTR), NULL);
780
 
781
  FOR_EACH_BB (bb)
782
    FOR_EACH_EDGE (e, ei, bb->succs)
783
      gsi_commit_one_edge_insert (e, NULL);
784
}
785
 
786
 
787
/* Commit insertions pending at edge E. If a new block is created, set NEW_BB
788
   to this block, otherwise set it to NULL.  */
789
 
790
void
791
gsi_commit_one_edge_insert (edge e, basic_block *new_bb)
792
{
793
  if (new_bb)
794
    *new_bb = NULL;
795
 
796
  if (PENDING_STMT (e))
797
    {
798
      gimple_stmt_iterator gsi;
799
      gimple_seq seq = PENDING_STMT (e);
800
      bool ins_after;
801
 
802
      PENDING_STMT (e) = NULL;
803
 
804
      ins_after = gimple_find_edge_insert_loc (e, &gsi, new_bb);
805
      update_call_edge_frequencies (gimple_seq_first (seq), gsi.bb);
806
 
807
      if (ins_after)
808
        gsi_insert_seq_after (&gsi, seq, GSI_NEW_STMT);
809
      else
810
        gsi_insert_seq_before (&gsi, seq, GSI_NEW_STMT);
811
    }
812
}
813
 
814
/* Returns iterator at the start of the list of phi nodes of BB.  */
815
 
816
gimple_stmt_iterator
817
gsi_start_phis (basic_block bb)
818
{
819
  return gsi_start (phi_nodes (bb));
820
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.