]> gcc.gnu.org Git - gcc.git/blame - gcc/cfgexpand.c
2004-11-24 Jeroen Frijters <address@bogus.example.com>
[gcc.git] / gcc / cfgexpand.c
CommitLineData
242229bb
JH
1/* A pass for lowering trees to RTL.
2 Copyright (C) 2004 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GCC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING. If not, write to
18the Free Software Foundation, 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
20
21#include "config.h"
22#include "system.h"
23#include "coretypes.h"
24#include "tm.h"
25#include "tree.h"
26#include "rtl.h"
27#include "tm_p.h"
28#include "basic-block.h"
29#include "function.h"
30#include "expr.h"
31#include "langhooks.h"
32#include "tree-flow.h"
33#include "timevar.h"
34#include "tree-dump.h"
35#include "tree-pass.h"
36#include "except.h"
37#include "flags.h"
1f6d3a08
RH
38#include "diagnostic.h"
39#include "toplev.h"
80c7a9eb 40
e53de54d
JH
41/* Verify that there is exactly single jump instruction since last and attach
42 REG_BR_PROB note specifying probability.
43 ??? We really ought to pass the probability down to RTL expanders and let it
d7e9e62a
KH
44 re-distribute it when the conditional expands into multiple conditionals.
45 This is however difficult to do. */
e53de54d
JH
46static void
47add_reg_br_prob_note (FILE *dump_file, rtx last, int probability)
48{
49 if (profile_status == PROFILE_ABSENT)
50 return;
51 for (last = NEXT_INSN (last); last && NEXT_INSN (last); last = NEXT_INSN (last))
52 if (GET_CODE (last) == JUMP_INSN)
53 {
54 /* It is common to emit condjump-around-jump sequence when we don't know
55 how to reverse the conditional. Special case this. */
56 if (!any_condjump_p (last)
57 || GET_CODE (NEXT_INSN (last)) != JUMP_INSN
58 || !simplejump_p (NEXT_INSN (last))
59 || GET_CODE (NEXT_INSN (NEXT_INSN (last))) != BARRIER
60 || GET_CODE (NEXT_INSN (NEXT_INSN (NEXT_INSN (last)))) != CODE_LABEL
61 || NEXT_INSN (NEXT_INSN (NEXT_INSN (NEXT_INSN (last)))))
62 goto failed;
63 if (find_reg_note (last, REG_BR_PROB, 0))
64 abort ();
65 REG_NOTES (last)
66 = gen_rtx_EXPR_LIST (REG_BR_PROB,
67 GEN_INT (REG_BR_PROB_BASE - probability),
68 REG_NOTES (last));
69 return;
70 }
71 if (!last || GET_CODE (last) != JUMP_INSN || !any_condjump_p (last))
72 goto failed;
73 if (find_reg_note (last, REG_BR_PROB, 0))
74 abort ();
75 REG_NOTES (last)
76 = gen_rtx_EXPR_LIST (REG_BR_PROB,
77 GEN_INT (probability), REG_NOTES (last));
78 return;
79failed:
80 if (dump_file)
81 fprintf (dump_file, "Failed to add probability note\n");
82}
83
80c7a9eb 84
1f6d3a08
RH
85#ifndef LOCAL_ALIGNMENT
86#define LOCAL_ALIGNMENT(TYPE, ALIGNMENT) ALIGNMENT
87#endif
88
89#ifndef STACK_ALIGNMENT_NEEDED
90#define STACK_ALIGNMENT_NEEDED 1
91#endif
92
93#ifdef FRAME_GROWS_DOWNWARD
94# undef FRAME_GROWS_DOWNWARD
95# define FRAME_GROWS_DOWNWARD 1
96#else
97# define FRAME_GROWS_DOWNWARD 0
98#endif
99
100
101/* This structure holds data relevant to one variable that will be
102 placed in a stack slot. */
103struct stack_var
104{
105 /* The Variable. */
106 tree decl;
107
108 /* The offset of the variable. During partitioning, this is the
109 offset relative to the partition. After partitioning, this
110 is relative to the stack frame. */
111 HOST_WIDE_INT offset;
112
113 /* Initially, the size of the variable. Later, the size of the partition,
114 if this variable becomes it's partition's representative. */
115 HOST_WIDE_INT size;
116
117 /* The *byte* alignment required for this variable. Or as, with the
118 size, the alignment for this partition. */
119 unsigned int alignb;
120
121 /* The partition representative. */
122 size_t representative;
123
124 /* The next stack variable in the partition, or EOC. */
125 size_t next;
126};
127
128#define EOC ((size_t)-1)
129
130/* We have an array of such objects while deciding allocation. */
131static struct stack_var *stack_vars;
132static size_t stack_vars_alloc;
133static size_t stack_vars_num;
134
135/* An array of indicies such that stack_vars[stack_vars_sorted[i]].size
136 is non-decreasing. */
137static size_t *stack_vars_sorted;
138
139/* We have an interference graph between such objects. This graph
140 is lower triangular. */
141static bool *stack_vars_conflict;
142static size_t stack_vars_conflict_alloc;
143
144/* The phase of the stack frame. This is the known misalignment of
145 virtual_stack_vars_rtx from PREFERRED_STACK_BOUNDARY. That is,
146 (frame_offset+frame_phase) % PREFERRED_STACK_BOUNDARY == 0. */
147static int frame_phase;
148
149
150/* Discover the byte alignment to use for DECL. Ignore alignment
151 we can't do with expected alignment of the stack boundary. */
152
153static unsigned int
154get_decl_align_unit (tree decl)
155{
156 unsigned int align;
157
158 align = DECL_ALIGN (decl);
159 align = LOCAL_ALIGNMENT (TREE_TYPE (decl), align);
160 if (align > PREFERRED_STACK_BOUNDARY)
161 align = PREFERRED_STACK_BOUNDARY;
162 if (cfun->stack_alignment_needed < align)
163 cfun->stack_alignment_needed = align;
164
165 return align / BITS_PER_UNIT;
166}
167
168/* Allocate SIZE bytes at byte alignment ALIGN from the stack frame.
169 Return the frame offset. */
170
171static HOST_WIDE_INT
172alloc_stack_frame_space (HOST_WIDE_INT size, HOST_WIDE_INT align)
173{
174 HOST_WIDE_INT offset, new_frame_offset;
175
176 new_frame_offset = frame_offset;
177 if (FRAME_GROWS_DOWNWARD)
178 {
179 new_frame_offset -= size + frame_phase;
180 new_frame_offset &= -align;
181 new_frame_offset += frame_phase;
182 offset = new_frame_offset;
183 }
184 else
185 {
186 new_frame_offset -= frame_phase;
187 new_frame_offset += align - 1;
188 new_frame_offset &= -align;
189 new_frame_offset += frame_phase;
190 offset = new_frame_offset;
191 new_frame_offset += size;
192 }
193 frame_offset = new_frame_offset;
194
195 return offset;
196}
197
198/* Accumulate DECL into STACK_VARS. */
199
200static void
201add_stack_var (tree decl)
202{
203 if (stack_vars_num >= stack_vars_alloc)
204 {
205 if (stack_vars_alloc)
206 stack_vars_alloc = stack_vars_alloc * 3 / 2;
207 else
208 stack_vars_alloc = 32;
209 stack_vars
210 = XRESIZEVEC (struct stack_var, stack_vars, stack_vars_alloc);
211 }
212 stack_vars[stack_vars_num].decl = decl;
213 stack_vars[stack_vars_num].offset = 0;
214 stack_vars[stack_vars_num].size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
215 stack_vars[stack_vars_num].alignb = get_decl_align_unit (decl);
216
217 /* All variables are initially in their own partition. */
218 stack_vars[stack_vars_num].representative = stack_vars_num;
219 stack_vars[stack_vars_num].next = EOC;
220
221 /* Ensure that this decl doesn't get put onto the list twice. */
222 SET_DECL_RTL (decl, pc_rtx);
223
224 stack_vars_num++;
225}
226
227/* Compute the linear index of a lower-triangular coordinate (I, J). */
228
229static size_t
230triangular_index (size_t i, size_t j)
231{
232 if (i < j)
233 {
234 size_t t;
235 t = i, i = j, j = t;
236 }
237 return (i * (i + 1)) / 2 + j;
238}
239
240/* Ensure that STACK_VARS_CONFLICT is large enough for N objects. */
241
242static void
243resize_stack_vars_conflict (size_t n)
244{
245 size_t size = triangular_index (n-1, n-1) + 1;
246
247 if (size <= stack_vars_conflict_alloc)
248 return;
249
250 stack_vars_conflict = XRESIZEVEC (bool, stack_vars_conflict, size);
251 memset (stack_vars_conflict + stack_vars_conflict_alloc, 0,
252 (size - stack_vars_conflict_alloc) * sizeof (bool));
253 stack_vars_conflict_alloc = size;
254}
255
256/* Make the decls associated with luid's X and Y conflict. */
257
258static void
259add_stack_var_conflict (size_t x, size_t y)
260{
261 size_t index = triangular_index (x, y);
262 gcc_assert (index < stack_vars_conflict_alloc);
263 stack_vars_conflict[index] = true;
264}
265
266/* Check whether the decls associated with luid's X and Y conflict. */
267
268static bool
269stack_var_conflict_p (size_t x, size_t y)
270{
271 size_t index = triangular_index (x, y);
272 gcc_assert (index < stack_vars_conflict_alloc);
273 return stack_vars_conflict[index];
274}
275
276/* A subroutine of expand_used_vars. If two variables X and Y have alias
277 sets that do not conflict, then do add a conflict for these variables
278 in the interference graph. We also have to mind MEM_IN_STRUCT_P and
279 MEM_SCALAR_P. */
280
281static void
282add_alias_set_conflicts (void)
283{
284 size_t i, j, n = stack_vars_num;
285
286 for (i = 0; i < n; ++i)
287 {
288 bool aggr_i = AGGREGATE_TYPE_P (TREE_TYPE (stack_vars[i].decl));
289 HOST_WIDE_INT set_i = get_alias_set (stack_vars[i].decl);
290
291 for (j = 0; j < i; ++j)
292 {
293 bool aggr_j = AGGREGATE_TYPE_P (TREE_TYPE (stack_vars[j].decl));
294 HOST_WIDE_INT set_j = get_alias_set (stack_vars[j].decl);
295 if (aggr_i != aggr_j || !alias_sets_conflict_p (set_i, set_j))
296 add_stack_var_conflict (i, j);
297 }
298 }
299}
300
301/* A subroutine of partition_stack_vars. A comparison function for qsort,
302 sorting an array of indicies by the size of the object. */
303
304static int
305stack_var_size_cmp (const void *a, const void *b)
306{
307 HOST_WIDE_INT sa = stack_vars[*(const size_t *)a].size;
308 HOST_WIDE_INT sb = stack_vars[*(const size_t *)b].size;
309
310 if (sa < sb)
311 return -1;
312 if (sa > sb)
313 return 1;
314 return 0;
315}
316
317/* A subroutine of partition_stack_vars. The UNION portion of a UNION/FIND
318 partitioning algorithm. Partitions A and B are known to be non-conflicting.
319 Merge them into a single partition A.
320
321 At the same time, add OFFSET to all variables in partition B. At the end
322 of the partitioning process we've have a nice block easy to lay out within
323 the stack frame. */
324
325static void
326union_stack_vars (size_t a, size_t b, HOST_WIDE_INT offset)
327{
328 size_t i, last;
329
330 /* Update each element of partition B with the given offset,
331 and merge them into partition A. */
332 for (last = i = b; i != EOC; last = i, i = stack_vars[i].next)
333 {
334 stack_vars[i].offset += offset;
335 stack_vars[i].representative = a;
336 }
337 stack_vars[last].next = stack_vars[a].next;
338 stack_vars[a].next = b;
339
340 /* Update the required alignment of partition A to account for B. */
341 if (stack_vars[a].alignb < stack_vars[b].alignb)
342 stack_vars[a].alignb = stack_vars[b].alignb;
343
344 /* Update the interference graph and merge the conflicts. */
345 for (last = stack_vars_num, i = 0; i < last; ++i)
346 if (stack_var_conflict_p (b, i))
347 add_stack_var_conflict (a, i);
348}
349
350/* A subroutine of expand_used_vars. Binpack the variables into
351 partitions constrained by the interference graph. The overall
352 algorithm used is as follows:
353
354 Sort the objects by size.
355 For each object A {
356 S = size(A)
357 O = 0
358 loop {
359 Look for the largest non-conflicting object B with size <= S.
360 UNION (A, B)
361 offset(B) = O
362 O += size(B)
363 S -= size(B)
364 }
365 }
366*/
367
368static void
369partition_stack_vars (void)
370{
371 size_t si, sj, n = stack_vars_num;
372
373 stack_vars_sorted = XNEWVEC (size_t, stack_vars_num);
374 for (si = 0; si < n; ++si)
375 stack_vars_sorted[si] = si;
376
377 if (n == 1)
378 return;
379
380 qsort (stack_vars_sorted, n, sizeof (size_t), stack_var_size_cmp);
381
382 /* Special case: detect when all variables conflict, and thus we can't
383 do anything during the partitioning loop. It isn't uncommon (with
384 C code at least) to declare all variables at the top of the function,
385 and if we're not inlining, then all variables will be in the same scope.
386 Take advantage of very fast libc routines for this scan. */
387 gcc_assert (sizeof(bool) == sizeof(char));
388 if (memchr (stack_vars_conflict, false, stack_vars_conflict_alloc) == NULL)
389 return;
390
391 for (si = 0; si < n; ++si)
392 {
393 size_t i = stack_vars_sorted[si];
394 HOST_WIDE_INT isize = stack_vars[i].size;
395 HOST_WIDE_INT offset = 0;
396
397 for (sj = si; sj-- > 0; )
398 {
399 size_t j = stack_vars_sorted[sj];
400 HOST_WIDE_INT jsize = stack_vars[j].size;
401 unsigned int jalign = stack_vars[j].alignb;
402
403 /* Ignore objects that aren't partition representatives. */
404 if (stack_vars[j].representative != j)
405 continue;
406
407 /* Ignore objects too large for the remaining space. */
408 if (isize < jsize)
409 continue;
410
411 /* Ignore conflicting objects. */
412 if (stack_var_conflict_p (i, j))
413 continue;
414
415 /* Refine the remaining space check to include alignment. */
416 if (offset & (jalign - 1))
417 {
418 HOST_WIDE_INT toff = offset;
419 toff += jalign - 1;
420 toff &= -(HOST_WIDE_INT)jalign;
421 if (isize - (toff - offset) < jsize)
422 continue;
423
424 isize -= toff - offset;
425 offset = toff;
426 }
427
428 /* UNION the objects, placing J at OFFSET. */
429 union_stack_vars (i, j, offset);
430
431 isize -= jsize;
432 if (isize == 0)
433 break;
434 }
435 }
436}
437
438/* A debugging aid for expand_used_vars. Dump the generated partitions. */
439
440static void
441dump_stack_var_partition (void)
442{
443 size_t si, i, j, n = stack_vars_num;
444
445 for (si = 0; si < n; ++si)
446 {
447 i = stack_vars_sorted[si];
448
449 /* Skip variables that aren't partition representatives, for now. */
450 if (stack_vars[i].representative != i)
451 continue;
452
453 fprintf (dump_file, "Partition %lu: size " HOST_WIDE_INT_PRINT_DEC
454 " align %u\n", (unsigned long) i, stack_vars[i].size,
455 stack_vars[i].alignb);
456
457 for (j = i; j != EOC; j = stack_vars[j].next)
458 {
459 fputc ('\t', dump_file);
460 print_generic_expr (dump_file, stack_vars[j].decl, dump_flags);
461 fprintf (dump_file, ", offset " HOST_WIDE_INT_PRINT_DEC "\n",
462 stack_vars[i].offset);
463 }
464 }
465}
466
467/* Assign rtl to DECL at frame offset OFFSET. */
468
469static void
470expand_one_stack_var_at (tree decl, HOST_WIDE_INT offset)
471{
472 HOST_WIDE_INT align;
473 rtx x;
474
475 /* If this fails, we've overflowed the stack frame. Error nicely? */
476 gcc_assert (offset == trunc_int_for_mode (offset, Pmode));
477
478 x = plus_constant (virtual_stack_vars_rtx, offset);
479 x = gen_rtx_MEM (DECL_MODE (decl), x);
480
481 /* Set alignment we actually gave this decl. */
482 offset -= frame_phase;
483 align = offset & -offset;
484 align *= BITS_PER_UNIT;
485 if (align > STACK_BOUNDARY || align == 0)
486 align = STACK_BOUNDARY;
487 DECL_ALIGN (decl) = align;
488 DECL_USER_ALIGN (decl) = 0;
489
490 set_mem_attributes (x, decl, true);
491 SET_DECL_RTL (decl, x);
492}
493
494/* A subroutine of expand_used_vars. Give each partition representative
495 a unique location within the stack frame. Update each partition member
496 with that location. */
497
498static void
499expand_stack_vars (void)
500{
501 size_t si, i, j, n = stack_vars_num;
502
503 for (si = 0; si < n; ++si)
504 {
505 HOST_WIDE_INT offset;
506
507 i = stack_vars_sorted[si];
508
509 /* Skip variables that aren't partition representatives, for now. */
510 if (stack_vars[i].representative != i)
511 continue;
512
513 offset = alloc_stack_frame_space (stack_vars[i].size,
514 stack_vars[i].alignb);
515
516 /* Create rtl for each variable based on their location within the
517 partition. */
518 for (j = i; j != EOC; j = stack_vars[j].next)
519 expand_one_stack_var_at (stack_vars[j].decl,
520 stack_vars[j].offset + offset);
521 }
522}
523
524/* A subroutine of expand_one_var. Called to immediately assign rtl
525 to a variable to be allocated in the stack frame. */
526
527static void
528expand_one_stack_var (tree var)
529{
530 HOST_WIDE_INT size, offset, align;
531
532 size = tree_low_cst (DECL_SIZE_UNIT (var), 1);
533 align = get_decl_align_unit (var);
534 offset = alloc_stack_frame_space (size, align);
535
536 expand_one_stack_var_at (var, offset);
537}
538
539/* A subroutine of expand_one_var. Called to assign rtl
540 to a TREE_STATIC VAR_DECL. */
541
542static void
543expand_one_static_var (tree var)
544{
545 /* If this is an inlined copy of a static local variable,
546 look up the original. */
547 var = DECL_ORIGIN (var);
548
549 /* If we've already processed this variable because of that, do nothing. */
550 if (TREE_ASM_WRITTEN (var))
551 return;
552
553 /* Give the front end a chance to do whatever. In practice, this is
554 resolving duplicate names for IMA in C. */
555 if (lang_hooks.expand_decl (var))
556 return;
557
558 /* Otherwise, just emit the variable. */
559 rest_of_decl_compilation (var, 0, 0);
560}
561
562/* A subroutine of expand_one_var. Called to assign rtl to a VAR_DECL
563 that will reside in a hard register. */
564
565static void
566expand_one_hard_reg_var (tree var)
567{
568 rest_of_decl_compilation (var, 0, 0);
569}
570
571/* A subroutine of expand_one_var. Called to assign rtl to a VAR_DECL
572 that will reside in a pseudo register. */
573
574static void
575expand_one_register_var (tree var)
576{
577 tree type = TREE_TYPE (var);
578 int unsignedp = TYPE_UNSIGNED (type);
579 enum machine_mode reg_mode
580 = promote_mode (type, DECL_MODE (var), &unsignedp, 0);
581 rtx x = gen_reg_rtx (reg_mode);
582
583 SET_DECL_RTL (var, x);
584
585 /* Note if the object is a user variable. */
586 if (!DECL_ARTIFICIAL (var))
587 {
588 mark_user_reg (x);
589
590 /* Trust user variables which have a pointer type to really
591 be pointers. Do not trust compiler generated temporaries
592 as our type system is totally busted as it relates to
593 pointer arithmetic which translates into lots of compiler
594 generated objects with pointer types, but which are not really
595 pointers. */
596 if (POINTER_TYPE_P (type))
597 mark_reg_pointer (x, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (var))));
598 }
599}
600
601/* A subroutine of expand_one_var. Called to assign rtl to a VAR_DECL that
602 has some associated error, e.g. it's type is error-mark. We just need
603 to pick something that won't crash the rest of the compiler. */
604
605static void
606expand_one_error_var (tree var)
607{
608 enum machine_mode mode = DECL_MODE (var);
609 rtx x;
610
611 if (mode == BLKmode)
612 x = gen_rtx_MEM (BLKmode, const0_rtx);
613 else if (mode == VOIDmode)
614 x = const0_rtx;
615 else
616 x = gen_reg_rtx (mode);
617
618 SET_DECL_RTL (var, x);
619}
620
621/* A subroutine of expand_one_var. VAR is a variable that will be
622 allocated to the local stack frame. Return true if we wish to
623 add VAR to STACK_VARS so that it will be coalesced with other
624 variables. Return false to allocate VAR immediately.
625
626 This function is used to reduce the number of variables considered
627 for coalescing, which reduces the size of the quadratic problem. */
628
629static bool
630defer_stack_allocation (tree var, bool toplevel)
631{
632 /* Variables in the outermost scope automatically conflict with
633 every other variable. The only reason to want to defer them
634 at all is that, after sorting, we can more efficiently pack
635 small variables in the stack frame. Continue to defer at -O2. */
636 if (toplevel && optimize < 2)
637 return false;
638
639 /* Without optimization, *most* variables are allocated from the
640 stack, which makes the quadratic problem large exactly when we
641 want compilation to proceed as quickly as possible. On the
642 other hand, we don't want the function's stack frame size to
643 get completely out of hand. So we avoid adding scalars and
644 "small" aggregates to the list at all. */
645 if (optimize == 0 && tree_low_cst (DECL_SIZE_UNIT (var), 1) < 32)
646 return false;
647
648 return true;
649}
650
651/* A subroutine of expand_used_vars. Expand one variable according to
2a7e31df 652 its flavor. Variables to be placed on the stack are not actually
1f6d3a08
RH
653 expanded yet, merely recorded. */
654
655static void
656expand_one_var (tree var, bool toplevel)
657{
658 if (TREE_CODE (var) != VAR_DECL)
659 lang_hooks.expand_decl (var);
660 else if (DECL_EXTERNAL (var))
661 ;
662 else if (DECL_VALUE_EXPR (var))
663 ;
664 else if (TREE_STATIC (var))
665 expand_one_static_var (var);
666 else if (DECL_RTL_SET_P (var))
667 ;
668 else if (TREE_TYPE (var) == error_mark_node)
669 expand_one_error_var (var);
670 else if (DECL_HARD_REGISTER (var))
671 expand_one_hard_reg_var (var);
672 else if (use_register_for_decl (var))
673 expand_one_register_var (var);
674 else if (defer_stack_allocation (var, toplevel))
675 add_stack_var (var);
676 else
677 expand_one_stack_var (var);
678}
679
680/* A subroutine of expand_used_vars. Walk down through the BLOCK tree
681 expanding variables. Those variables that can be put into registers
682 are allocated pseudos; those that can't are put on the stack.
683
684 TOPLEVEL is true if this is the outermost BLOCK. */
685
686static void
687expand_used_vars_for_block (tree block, bool toplevel)
688{
689 size_t i, j, old_sv_num, this_sv_num, new_sv_num;
690 tree t;
691
692 old_sv_num = toplevel ? 0 : stack_vars_num;
693
694 /* Expand all variables at this level. */
695 for (t = BLOCK_VARS (block); t ; t = TREE_CHAIN (t))
696 if (TREE_USED (t))
697 expand_one_var (t, toplevel);
698
699 this_sv_num = stack_vars_num;
700
701 /* Expand all variables at containing levels. */
702 for (t = BLOCK_SUBBLOCKS (block); t ; t = BLOCK_CHAIN (t))
703 expand_used_vars_for_block (t, false);
704
705 /* Since we do not track exact variable lifetimes (which is not even
706 possible for varibles whose address escapes), we mirror the block
707 tree in the interference graph. Here we cause all variables at this
708 level, and all sublevels, to conflict. Do make certain that a
709 variable conflicts with itself. */
710 if (old_sv_num < this_sv_num)
711 {
712 new_sv_num = stack_vars_num;
713 resize_stack_vars_conflict (new_sv_num);
714
715 for (i = old_sv_num; i < new_sv_num; ++i)
f4a6d54e
RH
716 for (j = i < this_sv_num ? i+1 : this_sv_num; j-- > old_sv_num ;)
717 add_stack_var_conflict (i, j);
1f6d3a08
RH
718 }
719}
720
721/* A subroutine of expand_used_vars. Walk down through the BLOCK tree
722 and clear TREE_USED on all local variables. */
723
724static void
725clear_tree_used (tree block)
726{
727 tree t;
728
729 for (t = BLOCK_VARS (block); t ; t = TREE_CHAIN (t))
730 /* if (!TREE_STATIC (t) && !DECL_EXTERNAL (t)) */
731 TREE_USED (t) = 0;
732
733 for (t = BLOCK_SUBBLOCKS (block); t ; t = BLOCK_CHAIN (t))
734 clear_tree_used (t);
735}
736
737/* Expand all variables used in the function. */
727a31fa
RH
738
739static void
740expand_used_vars (void)
741{
1f6d3a08 742 tree t, outer_block = DECL_INITIAL (current_function_decl);
727a31fa 743
1f6d3a08
RH
744 /* Compute the phase of the stack frame for this function. */
745 {
746 int align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
747 int off = STARTING_FRAME_OFFSET % align;
748 frame_phase = off ? align - off : 0;
749 }
727a31fa 750
1f6d3a08
RH
751 /* Set TREE_USED on all variables in the unexpanded_var_list. */
752 for (t = cfun->unexpanded_var_list; t; t = TREE_CHAIN (t))
753 TREE_USED (TREE_VALUE (t)) = 1;
727a31fa 754
1f6d3a08
RH
755 /* Clear TREE_USED on all variables associated with a block scope. */
756 clear_tree_used (outer_block);
757
758 /* At this point all variables on the unexpanded_var_list with TREE_USED
759 set are not associated with any block scope. Lay them out. */
760 for (t = cfun->unexpanded_var_list; t; t = TREE_CHAIN (t))
761 {
762 tree var = TREE_VALUE (t);
763 bool expand_now = false;
764
765 /* We didn't set a block for static or extern because it's hard
766 to tell the difference between a global variable (re)declared
767 in a local scope, and one that's really declared there to
768 begin with. And it doesn't really matter much, since we're
769 not giving them stack space. Expand them now. */
770 if (TREE_STATIC (var) || DECL_EXTERNAL (var))
771 expand_now = true;
772
773 /* Any variable that could have been hoisted into an SSA_NAME
774 will have been propagated anywhere the optimizers chose,
775 i.e. not confined to their original block. Allocate them
776 as if they were defined in the outermost scope. */
777 else if (is_gimple_reg (var))
778 expand_now = true;
779
780 /* If the variable is not associated with any block, then it
781 was created by the optimizers, and could be live anywhere
782 in the function. */
783 else if (TREE_USED (var))
784 expand_now = true;
785
786 /* Finally, mark all variables on the list as used. We'll use
787 this in a moment when we expand those associated with scopes. */
788 TREE_USED (var) = 1;
789
790 if (expand_now)
791 expand_one_var (var, true);
792 }
727a31fa 793 cfun->unexpanded_var_list = NULL_TREE;
1f6d3a08
RH
794
795 /* At this point, all variables within the block tree with TREE_USED
796 set are actually used by the optimized function. Lay them out. */
797 expand_used_vars_for_block (outer_block, true);
798
799 if (stack_vars_num > 0)
800 {
801 /* Due to the way alias sets work, no variables with non-conflicting
802 alias sets may be assigned the same address. Add conflicts to
803 reflect this. */
804 add_alias_set_conflicts ();
805
806 /* Now that we have collected all stack variables, and have computed a
807 minimal interference graph, attempt to save some stack space. */
808 partition_stack_vars ();
809 if (dump_file)
810 dump_stack_var_partition ();
811
812 /* Assign rtl to each variable based on these partitions. */
813 expand_stack_vars ();
814
815 /* Free up stack variable graph data. */
816 XDELETEVEC (stack_vars);
817 XDELETEVEC (stack_vars_sorted);
818 XDELETEVEC (stack_vars_conflict);
819 stack_vars = NULL;
820 stack_vars_alloc = stack_vars_num = 0;
821 stack_vars_conflict = NULL;
822 stack_vars_conflict_alloc = 0;
823 }
824
825 /* If the target requires that FRAME_OFFSET be aligned, do it. */
826 if (STACK_ALIGNMENT_NEEDED)
827 {
828 HOST_WIDE_INT align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
829 if (!FRAME_GROWS_DOWNWARD)
830 frame_offset += align - 1;
831 frame_offset &= -align;
832 }
727a31fa
RH
833}
834
835
b7211528
SB
836/* If we need to produce a detailed dump, print the tree representation
837 for STMT to the dump file. SINCE is the last RTX after which the RTL
838 generated for STMT should have been appended. */
839
840static void
841maybe_dump_rtl_for_tree_stmt (tree stmt, rtx since)
842{
843 if (dump_file && (dump_flags & TDF_DETAILS))
844 {
845 fprintf (dump_file, "\n;; ");
846 print_generic_expr (dump_file, stmt, TDF_SLIM);
847 fprintf (dump_file, "\n");
848
849 print_rtl (dump_file, since ? NEXT_INSN (since) : since);
850 }
851}
852
80c7a9eb
RH
853/* A subroutine of expand_gimple_basic_block. Expand one COND_EXPR.
854 Returns a new basic block if we've terminated the current basic
855 block and created a new one. */
856
857static basic_block
858expand_gimple_cond_expr (basic_block bb, tree stmt)
859{
860 basic_block new_bb, dest;
861 edge new_edge;
862 edge true_edge;
863 edge false_edge;
864 tree pred = COND_EXPR_COND (stmt);
865 tree then_exp = COND_EXPR_THEN (stmt);
866 tree else_exp = COND_EXPR_ELSE (stmt);
b7211528
SB
867 rtx last2, last;
868
869 last2 = last = get_last_insn ();
80c7a9eb
RH
870
871 extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
872 if (EXPR_LOCUS (stmt))
873 {
874 emit_line_note (*(EXPR_LOCUS (stmt)));
875 record_block_change (TREE_BLOCK (stmt));
876 }
877
878 /* These flags have no purpose in RTL land. */
879 true_edge->flags &= ~EDGE_TRUE_VALUE;
880 false_edge->flags &= ~EDGE_FALSE_VALUE;
881
882 /* We can either have a pure conditional jump with one fallthru edge or
883 two-way jump that needs to be decomposed into two basic blocks. */
884 if (TREE_CODE (then_exp) == GOTO_EXPR && IS_EMPTY_STMT (else_exp))
885 {
886 jumpif (pred, label_rtx (GOTO_DESTINATION (then_exp)));
e53de54d 887 add_reg_br_prob_note (dump_file, last, true_edge->probability);
b7211528 888 maybe_dump_rtl_for_tree_stmt (stmt, last);
ac8245fa
AP
889 if (EXPR_LOCUS (then_exp))
890 emit_line_note (*(EXPR_LOCUS (then_exp)));
80c7a9eb
RH
891 return NULL;
892 }
893 if (TREE_CODE (else_exp) == GOTO_EXPR && IS_EMPTY_STMT (then_exp))
894 {
895 jumpifnot (pred, label_rtx (GOTO_DESTINATION (else_exp)));
e53de54d 896 add_reg_br_prob_note (dump_file, last, false_edge->probability);
b7211528 897 maybe_dump_rtl_for_tree_stmt (stmt, last);
ac8245fa
AP
898 if (EXPR_LOCUS (else_exp))
899 emit_line_note (*(EXPR_LOCUS (else_exp)));
80c7a9eb
RH
900 return NULL;
901 }
341c100f
NS
902 gcc_assert (TREE_CODE (then_exp) == GOTO_EXPR
903 && TREE_CODE (else_exp) == GOTO_EXPR);
80c7a9eb
RH
904
905 jumpif (pred, label_rtx (GOTO_DESTINATION (then_exp)));
e53de54d 906 add_reg_br_prob_note (dump_file, last, true_edge->probability);
80c7a9eb
RH
907 last = get_last_insn ();
908 expand_expr (else_exp, const0_rtx, VOIDmode, 0);
909
910 BB_END (bb) = last;
911 if (BARRIER_P (BB_END (bb)))
912 BB_END (bb) = PREV_INSN (BB_END (bb));
913 update_bb_for_insn (bb);
914
915 new_bb = create_basic_block (NEXT_INSN (last), get_last_insn (), bb);
916 dest = false_edge->dest;
917 redirect_edge_succ (false_edge, new_bb);
918 false_edge->flags |= EDGE_FALLTHRU;
919 new_bb->count = false_edge->count;
920 new_bb->frequency = EDGE_FREQUENCY (false_edge);
921 new_edge = make_edge (new_bb, dest, 0);
922 new_edge->probability = REG_BR_PROB_BASE;
923 new_edge->count = new_bb->count;
924 if (BARRIER_P (BB_END (new_bb)))
925 BB_END (new_bb) = PREV_INSN (BB_END (new_bb));
926 update_bb_for_insn (new_bb);
927
b7211528 928 maybe_dump_rtl_for_tree_stmt (stmt, last2);
ac8245fa
AP
929
930 if (EXPR_LOCUS (else_exp))
931 emit_line_note (*(EXPR_LOCUS (else_exp)));
80c7a9eb
RH
932
933 return new_bb;
934}
935
936/* A subroutine of expand_gimple_basic_block. Expand one CALL_EXPR
224e770b
RH
937 that has CALL_EXPR_TAILCALL set. Returns non-null if we actually
938 generated a tail call (something that might be denied by the ABI
cea49550
RH
939 rules governing the call; see calls.c).
940
941 Sets CAN_FALLTHRU if we generated a *conditional* tail call, and
942 can still reach the rest of BB. The case here is __builtin_sqrt,
943 where the NaN result goes through the external function (with a
944 tailcall) and the normal result happens via a sqrt instruction. */
80c7a9eb
RH
945
946static basic_block
cea49550 947expand_gimple_tailcall (basic_block bb, tree stmt, bool *can_fallthru)
80c7a9eb 948{
b7211528 949 rtx last2, last;
224e770b 950 edge e;
628f6a4e 951 edge_iterator ei;
224e770b
RH
952 int probability;
953 gcov_type count;
80c7a9eb 954
b7211528
SB
955 last2 = last = get_last_insn ();
956
80c7a9eb
RH
957 expand_expr_stmt (stmt);
958
959 for (last = NEXT_INSN (last); last; last = NEXT_INSN (last))
224e770b
RH
960 if (CALL_P (last) && SIBLING_CALL_P (last))
961 goto found;
80c7a9eb 962
b7211528
SB
963 maybe_dump_rtl_for_tree_stmt (stmt, last);
964
cea49550 965 *can_fallthru = true;
224e770b 966 return NULL;
80c7a9eb 967
224e770b
RH
968 found:
969 /* ??? Wouldn't it be better to just reset any pending stack adjust?
970 Any instructions emitted here are about to be deleted. */
971 do_pending_stack_adjust ();
972
973 /* Remove any non-eh, non-abnormal edges that don't go to exit. */
974 /* ??? I.e. the fallthrough edge. HOWEVER! If there were to be
975 EH or abnormal edges, we shouldn't have created a tail call in
976 the first place. So it seems to me we should just be removing
977 all edges here, or redirecting the existing fallthru edge to
978 the exit block. */
979
224e770b
RH
980 probability = 0;
981 count = 0;
224e770b 982
628f6a4e
BE
983 for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
984 {
224e770b
RH
985 if (!(e->flags & (EDGE_ABNORMAL | EDGE_EH)))
986 {
987 if (e->dest != EXIT_BLOCK_PTR)
80c7a9eb 988 {
224e770b
RH
989 e->dest->count -= e->count;
990 e->dest->frequency -= EDGE_FREQUENCY (e);
991 if (e->dest->count < 0)
992 e->dest->count = 0;
993 if (e->dest->frequency < 0)
994 e->dest->frequency = 0;
80c7a9eb 995 }
224e770b
RH
996 count += e->count;
997 probability += e->probability;
998 remove_edge (e);
80c7a9eb 999 }
628f6a4e
BE
1000 else
1001 ei_next (&ei);
80c7a9eb
RH
1002 }
1003
224e770b
RH
1004 /* This is somewhat ugly: the call_expr expander often emits instructions
1005 after the sibcall (to perform the function return). These confuse the
1006 find_sub_basic_blocks code, so we need to get rid of these. */
1007 last = NEXT_INSN (last);
341c100f 1008 gcc_assert (BARRIER_P (last));
cea49550
RH
1009
1010 *can_fallthru = false;
224e770b
RH
1011 while (NEXT_INSN (last))
1012 {
1013 /* For instance an sqrt builtin expander expands if with
1014 sibcall in the then and label for `else`. */
1015 if (LABEL_P (NEXT_INSN (last)))
cea49550
RH
1016 {
1017 *can_fallthru = true;
1018 break;
1019 }
224e770b
RH
1020 delete_insn (NEXT_INSN (last));
1021 }
1022
1023 e = make_edge (bb, EXIT_BLOCK_PTR, EDGE_ABNORMAL | EDGE_SIBCALL);
1024 e->probability += probability;
1025 e->count += count;
1026 BB_END (bb) = last;
1027 update_bb_for_insn (bb);
1028
1029 if (NEXT_INSN (last))
1030 {
1031 bb = create_basic_block (NEXT_INSN (last), get_last_insn (), bb);
1032
1033 last = BB_END (bb);
1034 if (BARRIER_P (last))
1035 BB_END (bb) = PREV_INSN (last);
1036 }
1037
b7211528
SB
1038 maybe_dump_rtl_for_tree_stmt (stmt, last2);
1039
224e770b 1040 return bb;
80c7a9eb
RH
1041}
1042
242229bb
JH
1043/* Expand basic block BB from GIMPLE trees to RTL. */
1044
1045static basic_block
80c7a9eb 1046expand_gimple_basic_block (basic_block bb, FILE * dump_file)
242229bb
JH
1047{
1048 block_stmt_iterator bsi = bsi_start (bb);
1049 tree stmt = NULL;
1050 rtx note, last;
1051 edge e;
628f6a4e 1052 edge_iterator ei;
242229bb
JH
1053
1054 if (dump_file)
1055 {
b7211528
SB
1056 fprintf (dump_file,
1057 "\n;; Generating RTL for tree basic block %d\n",
1058 bb->index);
242229bb
JH
1059 }
1060
1061 if (!bsi_end_p (bsi))
1062 stmt = bsi_stmt (bsi);
1063
1064 if (stmt && TREE_CODE (stmt) == LABEL_EXPR)
1065 {
1066 last = get_last_insn ();
1067
4dfa0342 1068 expand_expr_stmt (stmt);
242229bb 1069
caf93cb0 1070 /* Java emits line number notes in the top of labels.
242229bb
JH
1071 ??? Make this go away once line number notes are obsoleted. */
1072 BB_HEAD (bb) = NEXT_INSN (last);
4b4bf941 1073 if (NOTE_P (BB_HEAD (bb)))
242229bb
JH
1074 BB_HEAD (bb) = NEXT_INSN (BB_HEAD (bb));
1075 bsi_next (&bsi);
1076 note = emit_note_after (NOTE_INSN_BASIC_BLOCK, BB_HEAD (bb));
b7211528
SB
1077
1078 maybe_dump_rtl_for_tree_stmt (stmt, last);
242229bb
JH
1079 }
1080 else
1081 note = BB_HEAD (bb) = emit_note (NOTE_INSN_BASIC_BLOCK);
1082
1083 NOTE_BASIC_BLOCK (note) = bb;
1084
628f6a4e 1085 for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
242229bb 1086 {
242229bb
JH
1087 /* Clear EDGE_EXECUTABLE. This flag is never used in the backend. */
1088 e->flags &= ~EDGE_EXECUTABLE;
1089
1090 /* At the moment not all abnormal edges match the RTL representation.
1091 It is safe to remove them here as find_sub_basic_blocks will
1092 rediscover them. In the future we should get this fixed properly. */
1093 if (e->flags & EDGE_ABNORMAL)
1094 remove_edge (e);
628f6a4e
BE
1095 else
1096 ei_next (&ei);
242229bb
JH
1097 }
1098
1099 for (; !bsi_end_p (bsi); bsi_next (&bsi))
1100 {
1101 tree stmt = bsi_stmt (bsi);
cea49550 1102 basic_block new_bb;
242229bb
JH
1103
1104 if (!stmt)
1105 continue;
1106
1107 /* Expand this statement, then evaluate the resulting RTL and
1108 fixup the CFG accordingly. */
80c7a9eb 1109 if (TREE_CODE (stmt) == COND_EXPR)
cea49550
RH
1110 {
1111 new_bb = expand_gimple_cond_expr (bb, stmt);
1112 if (new_bb)
1113 return new_bb;
1114 }
80c7a9eb 1115 else
242229bb 1116 {
80c7a9eb
RH
1117 tree call = get_call_expr_in (stmt);
1118 if (call && CALL_EXPR_TAILCALL (call))
cea49550
RH
1119 {
1120 bool can_fallthru;
1121 new_bb = expand_gimple_tailcall (bb, stmt, &can_fallthru);
1122 if (new_bb)
1123 {
1124 if (can_fallthru)
1125 bb = new_bb;
1126 else
1127 return new_bb;
1128 }
1129 }
80c7a9eb 1130 else
b7211528
SB
1131 {
1132 last = get_last_insn ();
1133 expand_expr_stmt (stmt);
1134 maybe_dump_rtl_for_tree_stmt (stmt, last);
1135 }
242229bb
JH
1136 }
1137 }
1138
1139 do_pending_stack_adjust ();
1140
1141 /* Find the the block tail. The last insn is the block is the insn
1142 before a barrier and/or table jump insn. */
1143 last = get_last_insn ();
4b4bf941 1144 if (BARRIER_P (last))
242229bb
JH
1145 last = PREV_INSN (last);
1146 if (JUMP_TABLE_DATA_P (last))
1147 last = PREV_INSN (PREV_INSN (last));
1148 BB_END (bb) = last;
caf93cb0 1149
242229bb 1150 update_bb_for_insn (bb);
80c7a9eb 1151
242229bb
JH
1152 return bb;
1153}
1154
1155
1156/* Create a basic block for initialization code. */
1157
1158static basic_block
1159construct_init_block (void)
1160{
1161 basic_block init_block, first_block;
275a4187 1162 edge e = NULL, e2;
628f6a4e 1163 edge_iterator ei;
275a4187 1164
628f6a4e 1165 FOR_EACH_EDGE (e2, ei, ENTRY_BLOCK_PTR->succs)
275a4187
SB
1166 {
1167 /* Clear EDGE_EXECUTABLE. This flag is never used in the backend.
242229bb 1168
275a4187
SB
1169 For all other blocks this edge flag is cleared while expanding
1170 a basic block in expand_gimple_basic_block, but there we never
1171 looked at the successors of the entry block.
1172 This caused PR17513. */
1173 e2->flags &= ~EDGE_EXECUTABLE;
1174
1175 if (e2->dest == ENTRY_BLOCK_PTR->next_bb)
1176 e = e2;
1177 }
242229bb
JH
1178
1179 init_block = create_basic_block (NEXT_INSN (get_insns ()),
1180 get_last_insn (),
1181 ENTRY_BLOCK_PTR);
1182 init_block->frequency = ENTRY_BLOCK_PTR->frequency;
1183 init_block->count = ENTRY_BLOCK_PTR->count;
1184 if (e)
1185 {
1186 first_block = e->dest;
1187 redirect_edge_succ (e, init_block);
1188 e = make_edge (init_block, first_block, EDGE_FALLTHRU);
1189 }
1190 else
1191 e = make_edge (init_block, EXIT_BLOCK_PTR, EDGE_FALLTHRU);
1192 e->probability = REG_BR_PROB_BASE;
1193 e->count = ENTRY_BLOCK_PTR->count;
1194
1195 update_bb_for_insn (init_block);
1196 return init_block;
1197}
1198
1199
1200/* Create a block containing landing pads and similar stuff. */
1201
1202static void
1203construct_exit_block (void)
1204{
1205 rtx head = get_last_insn ();
1206 rtx end;
1207 basic_block exit_block;
628f6a4e
BE
1208 edge e, e2;
1209 unsigned ix;
1210 edge_iterator ei;
242229bb 1211
caf93cb0 1212 /* Make sure the locus is set to the end of the function, so that
242229bb 1213 epilogue line numbers and warnings are set properly. */
6773e15f
PB
1214#ifdef USE_MAPPED_LOCATION
1215 if (cfun->function_end_locus != UNKNOWN_LOCATION)
1216#else
242229bb 1217 if (cfun->function_end_locus.file)
6773e15f 1218#endif
242229bb
JH
1219 input_location = cfun->function_end_locus;
1220
1221 /* The following insns belong to the top scope. */
1222 record_block_change (DECL_INITIAL (current_function_decl));
1223
242229bb
JH
1224 /* Generate rtl for function exit. */
1225 expand_function_end ();
1226
1227 end = get_last_insn ();
1228 if (head == end)
1229 return;
4b4bf941 1230 while (NEXT_INSN (head) && NOTE_P (NEXT_INSN (head)))
242229bb 1231 head = NEXT_INSN (head);
80c7a9eb
RH
1232 exit_block = create_basic_block (NEXT_INSN (head), end,
1233 EXIT_BLOCK_PTR->prev_bb);
242229bb
JH
1234 exit_block->frequency = EXIT_BLOCK_PTR->frequency;
1235 exit_block->count = EXIT_BLOCK_PTR->count;
628f6a4e
BE
1236
1237 ix = 0;
1238 while (ix < EDGE_COUNT (EXIT_BLOCK_PTR->preds))
242229bb 1239 {
628f6a4e 1240 e = EDGE_I (EXIT_BLOCK_PTR->preds, ix);
242229bb 1241 if (!(e->flags & EDGE_ABNORMAL))
628f6a4e
BE
1242 redirect_edge_succ (e, exit_block);
1243 else
1244 ix++;
242229bb 1245 }
628f6a4e 1246
242229bb
JH
1247 e = make_edge (exit_block, EXIT_BLOCK_PTR, EDGE_FALLTHRU);
1248 e->probability = REG_BR_PROB_BASE;
1249 e->count = EXIT_BLOCK_PTR->count;
628f6a4e 1250 FOR_EACH_EDGE (e2, ei, EXIT_BLOCK_PTR->preds)
242229bb
JH
1251 if (e2 != e)
1252 {
1253 e->count -= e2->count;
1254 exit_block->count -= e2->count;
1255 exit_block->frequency -= EDGE_FREQUENCY (e2);
1256 }
1257 if (e->count < 0)
1258 e->count = 0;
1259 if (exit_block->count < 0)
1260 exit_block->count = 0;
1261 if (exit_block->frequency < 0)
1262 exit_block->frequency = 0;
1263 update_bb_for_insn (exit_block);
1264}
1265
242229bb
JH
1266/* Translate the intermediate representation contained in the CFG
1267 from GIMPLE trees to RTL.
1268
1269 We do conversion per basic block and preserve/update the tree CFG.
1270 This implies we have to do some magic as the CFG can simultaneously
1271 consist of basic blocks containing RTL and GIMPLE trees. This can
61ada8ae 1272 confuse the CFG hooks, so be careful to not manipulate CFG during
242229bb
JH
1273 the expansion. */
1274
1275static void
1276tree_expand_cfg (void)
1277{
1278 basic_block bb, init_block;
1279 sbitmap blocks;
1280
4586b4ca
SB
1281 /* Some backends want to know that we are expanding to RTL. */
1282 currently_expanding_to_rtl = 1;
1283
6429e3be
RH
1284 /* Prepare the rtl middle end to start recording block changes. */
1285 reset_block_changes ();
1286
727a31fa 1287 /* Expand the variables recorded during gimple lowering. */
242229bb
JH
1288 expand_used_vars ();
1289
1290 /* Set up parameters and prepare for return, for the function. */
b79c5284 1291 expand_function_start (current_function_decl);
242229bb
JH
1292
1293 /* If this function is `main', emit a call to `__main'
1294 to run global initializers, etc. */
1295 if (DECL_NAME (current_function_decl)
1296 && MAIN_NAME_P (DECL_NAME (current_function_decl))
1297 && DECL_FILE_SCOPE_P (current_function_decl))
1298 expand_main_function ();
1299
3fbd86b1 1300 /* Register rtl specific functions for cfg. */
242229bb
JH
1301 rtl_register_cfg_hooks ();
1302
1303 init_block = construct_init_block ();
1304
1305 FOR_BB_BETWEEN (bb, init_block->next_bb, EXIT_BLOCK_PTR, next_bb)
80c7a9eb 1306 bb = expand_gimple_basic_block (bb, dump_file);
242229bb
JH
1307
1308 construct_exit_block ();
1309
4586b4ca
SB
1310 /* We're done expanding trees to RTL. */
1311 currently_expanding_to_rtl = 0;
1312
242229bb 1313 /* Convert from NOTE_INSN_EH_REGION style notes, and do other
9f8628ba 1314 sorts of eh initialization. */
242229bb
JH
1315 convert_from_eh_region_ranges ();
1316
1317 rebuild_jump_labels (get_insns ());
1318 find_exception_handler_labels ();
1319
1320 blocks = sbitmap_alloc (last_basic_block);
1321 sbitmap_ones (blocks);
1322 find_many_sub_basic_blocks (blocks);
1323 purge_all_dead_edges (0);
1324 sbitmap_free (blocks);
1325
1326 compact_blocks ();
1327#ifdef ENABLE_CHECKING
1328 verify_flow_info();
1329#endif
9f8628ba
PB
1330
1331 /* There's no need to defer outputting this function any more; we
1332 know we want to output it. */
1333 DECL_DEFER_OUTPUT (current_function_decl) = 0;
1334
1335 /* Now that we're done expanding trees to RTL, we shouldn't have any
1336 more CONCATs anywhere. */
1337 generating_concat_p = 0;
1338
1339 finalize_block_changes ();
b7211528
SB
1340
1341 if (dump_file)
1342 {
1343 fprintf (dump_file,
1344 "\n\n;;\n;; Full RTL generated for this function:\n;;\n");
1345 /* And the pass manager will dump RTL for us. */
1346 }
242229bb
JH
1347}
1348
1349struct tree_opt_pass pass_expand =
1350{
1351 "expand", /* name */
1352 NULL, /* gate */
1353 tree_expand_cfg, /* execute */
1354 NULL, /* sub */
1355 NULL, /* next */
1356 0, /* static_pass_number */
1357 TV_EXPAND, /* tv_id */
1358 /* ??? If TER is enabled, we actually receive GENERIC. */
1359 PROP_gimple_leh | PROP_cfg, /* properties_required */
1360 PROP_rtl, /* properties_provided */
1361 PROP_gimple_leh, /* properties_destroyed */
1362 0, /* todo_flags_start */
9f8628ba
PB
1363 0, /* todo_flags_finish */
1364 'r' /* letter */
242229bb 1365};
This page took 0.375052 seconds and 5 git commands to generate.