1 /* A pass for lowering trees to RTL.
2 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
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/>. */
23 #include "coretypes.h"
28 #include "basic-block.h"
31 #include "langhooks.h"
32 #include "tree-flow.h"
34 #include "tree-dump.h"
35 #include "tree-pass.h"
38 #include "diagnostic.h"
39 #include "tree-pretty-print.h"
40 #include "gimple-pretty-print.h"
44 #include "tree-inline.h"
45 #include "value-prof.h"
47 #include "ssaexpand.h"
50 #include "insn-attr.h" /* For INSN_SCHEDULING. */
52 /* This variable holds information helping the rewriting of SSA trees
56 /* This variable holds the currently expanded gimple statement for purposes
57 of comminucating the profile info to the builtin expanders. */
58 gimple currently_expanding_gimple_stmt
;
60 static rtx
expand_debug_expr (tree
);
62 /* Return an expression tree corresponding to the RHS of GIMPLE
66 gimple_assign_rhs_to_tree (gimple stmt
)
69 enum gimple_rhs_class grhs_class
;
71 grhs_class
= get_gimple_rhs_class (gimple_expr_code (stmt
));
73 if (grhs_class
== GIMPLE_TERNARY_RHS
)
74 t
= build3 (gimple_assign_rhs_code (stmt
),
75 TREE_TYPE (gimple_assign_lhs (stmt
)),
76 gimple_assign_rhs1 (stmt
),
77 gimple_assign_rhs2 (stmt
),
78 gimple_assign_rhs3 (stmt
));
79 else if (grhs_class
== GIMPLE_BINARY_RHS
)
80 t
= build2 (gimple_assign_rhs_code (stmt
),
81 TREE_TYPE (gimple_assign_lhs (stmt
)),
82 gimple_assign_rhs1 (stmt
),
83 gimple_assign_rhs2 (stmt
));
84 else if (grhs_class
== GIMPLE_UNARY_RHS
)
85 t
= build1 (gimple_assign_rhs_code (stmt
),
86 TREE_TYPE (gimple_assign_lhs (stmt
)),
87 gimple_assign_rhs1 (stmt
));
88 else if (grhs_class
== GIMPLE_SINGLE_RHS
)
90 t
= gimple_assign_rhs1 (stmt
);
91 /* Avoid modifying this tree in place below. */
92 if ((gimple_has_location (stmt
) && CAN_HAVE_LOCATION_P (t
)
93 && gimple_location (stmt
) != EXPR_LOCATION (t
))
94 || (gimple_block (stmt
)
95 && currently_expanding_to_rtl
97 && gimple_block (stmt
) != TREE_BLOCK (t
)))
103 if (gimple_has_location (stmt
) && CAN_HAVE_LOCATION_P (t
))
104 SET_EXPR_LOCATION (t
, gimple_location (stmt
));
105 if (gimple_block (stmt
) && currently_expanding_to_rtl
&& EXPR_P (t
))
106 TREE_BLOCK (t
) = gimple_block (stmt
);
112 #ifndef STACK_ALIGNMENT_NEEDED
113 #define STACK_ALIGNMENT_NEEDED 1
116 #define SSAVAR(x) (TREE_CODE (x) == SSA_NAME ? SSA_NAME_VAR (x) : x)
118 /* Associate declaration T with storage space X. If T is no
119 SSA name this is exactly SET_DECL_RTL, otherwise make the
120 partition of T associated with X. */
122 set_rtl (tree t
, rtx x
)
124 if (TREE_CODE (t
) == SSA_NAME
)
126 SA
.partition_to_pseudo
[var_to_partition (SA
.map
, t
)] = x
;
128 set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (t
), x
);
129 /* For the benefit of debug information at -O0 (where vartracking
130 doesn't run) record the place also in the base DECL if it's
131 a normal variable (not a parameter). */
132 if (x
&& x
!= pc_rtx
&& TREE_CODE (SSA_NAME_VAR (t
)) == VAR_DECL
)
134 tree var
= SSA_NAME_VAR (t
);
135 /* If we don't yet have something recorded, just record it now. */
136 if (!DECL_RTL_SET_P (var
))
137 SET_DECL_RTL (var
, x
);
138 /* If we have it set alrady to "multiple places" don't
140 else if (DECL_RTL (var
) == pc_rtx
)
142 /* If we have something recorded and it's not the same place
143 as we want to record now, we have multiple partitions for the
144 same base variable, with different places. We can't just
145 randomly chose one, hence we have to say that we don't know.
146 This only happens with optimization, and there var-tracking
147 will figure out the right thing. */
148 else if (DECL_RTL (var
) != x
)
149 SET_DECL_RTL (var
, pc_rtx
);
156 /* This structure holds data relevant to one variable that will be
157 placed in a stack slot. */
163 /* Initially, the size of the variable. Later, the size of the partition,
164 if this variable becomes it's partition's representative. */
167 /* The *byte* alignment required for this variable. Or as, with the
168 size, the alignment for this partition. */
171 /* The partition representative. */
172 size_t representative
;
174 /* The next stack variable in the partition, or EOC. */
177 /* The numbers of conflicting stack variables. */
181 #define EOC ((size_t)-1)
183 /* We have an array of such objects while deciding allocation. */
184 static struct stack_var
*stack_vars
;
185 static size_t stack_vars_alloc
;
186 static size_t stack_vars_num
;
188 /* An array of indices such that stack_vars[stack_vars_sorted[i]].size
189 is non-decreasing. */
190 static size_t *stack_vars_sorted
;
192 /* The phase of the stack frame. This is the known misalignment of
193 virtual_stack_vars_rtx from PREFERRED_STACK_BOUNDARY. That is,
194 (frame_offset+frame_phase) % PREFERRED_STACK_BOUNDARY == 0. */
195 static int frame_phase
;
197 /* Used during expand_used_vars to remember if we saw any decls for
198 which we'd like to enable stack smashing protection. */
199 static bool has_protected_decls
;
201 /* Used during expand_used_vars. Remember if we say a character buffer
202 smaller than our cutoff threshold. Used for -Wstack-protector. */
203 static bool has_short_buffer
;
205 /* Compute the byte alignment to use for DECL. Ignore alignment
206 we can't do with expected alignment of the stack boundary. */
209 align_local_variable (tree decl
)
211 unsigned int align
= LOCAL_DECL_ALIGNMENT (decl
);
212 DECL_ALIGN (decl
) = align
;
213 return align
/ BITS_PER_UNIT
;
216 /* Allocate SIZE bytes at byte alignment ALIGN from the stack frame.
217 Return the frame offset. */
220 alloc_stack_frame_space (HOST_WIDE_INT size
, unsigned HOST_WIDE_INT align
)
222 HOST_WIDE_INT offset
, new_frame_offset
;
224 new_frame_offset
= frame_offset
;
225 if (FRAME_GROWS_DOWNWARD
)
227 new_frame_offset
-= size
+ frame_phase
;
228 new_frame_offset
&= -align
;
229 new_frame_offset
+= frame_phase
;
230 offset
= new_frame_offset
;
234 new_frame_offset
-= frame_phase
;
235 new_frame_offset
+= align
- 1;
236 new_frame_offset
&= -align
;
237 new_frame_offset
+= frame_phase
;
238 offset
= new_frame_offset
;
239 new_frame_offset
+= size
;
241 frame_offset
= new_frame_offset
;
243 if (frame_offset_overflow (frame_offset
, cfun
->decl
))
244 frame_offset
= offset
= 0;
249 /* Accumulate DECL into STACK_VARS. */
252 add_stack_var (tree decl
)
256 if (stack_vars_num
>= stack_vars_alloc
)
258 if (stack_vars_alloc
)
259 stack_vars_alloc
= stack_vars_alloc
* 3 / 2;
261 stack_vars_alloc
= 32;
263 = XRESIZEVEC (struct stack_var
, stack_vars
, stack_vars_alloc
);
265 v
= &stack_vars
[stack_vars_num
];
268 v
->size
= tree_low_cst (DECL_SIZE_UNIT (SSAVAR (decl
)), 1);
269 /* Ensure that all variables have size, so that &a != &b for any two
270 variables that are simultaneously live. */
273 v
->alignb
= align_local_variable (SSAVAR (decl
));
275 /* All variables are initially in their own partition. */
276 v
->representative
= stack_vars_num
;
279 /* All variables initially conflict with no other. */
282 /* Ensure that this decl doesn't get put onto the list twice. */
283 set_rtl (decl
, pc_rtx
);
288 /* Make the decls associated with luid's X and Y conflict. */
291 add_stack_var_conflict (size_t x
, size_t y
)
293 struct stack_var
*a
= &stack_vars
[x
];
294 struct stack_var
*b
= &stack_vars
[y
];
296 a
->conflicts
= BITMAP_ALLOC (NULL
);
298 b
->conflicts
= BITMAP_ALLOC (NULL
);
299 bitmap_set_bit (a
->conflicts
, y
);
300 bitmap_set_bit (b
->conflicts
, x
);
303 /* Check whether the decls associated with luid's X and Y conflict. */
306 stack_var_conflict_p (size_t x
, size_t y
)
308 struct stack_var
*a
= &stack_vars
[x
];
309 struct stack_var
*b
= &stack_vars
[y
];
310 if (!a
->conflicts
|| !b
->conflicts
)
312 return bitmap_bit_p (a
->conflicts
, y
);
315 /* Returns true if TYPE is or contains a union type. */
318 aggregate_contains_union_type (tree type
)
322 if (TREE_CODE (type
) == UNION_TYPE
323 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
325 if (TREE_CODE (type
) == ARRAY_TYPE
)
326 return aggregate_contains_union_type (TREE_TYPE (type
));
327 if (TREE_CODE (type
) != RECORD_TYPE
)
330 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
331 if (TREE_CODE (field
) == FIELD_DECL
)
332 if (aggregate_contains_union_type (TREE_TYPE (field
)))
338 /* A subroutine of expand_used_vars. If two variables X and Y have alias
339 sets that do not conflict, then do add a conflict for these variables
340 in the interference graph. We also need to make sure to add conflicts
341 for union containing structures. Else RTL alias analysis comes along
342 and due to type based aliasing rules decides that for two overlapping
343 union temporaries { short s; int i; } accesses to the same mem through
344 different types may not alias and happily reorders stores across
345 life-time boundaries of the temporaries (See PR25654).
346 We also have to mind MEM_IN_STRUCT_P and MEM_SCALAR_P. */
349 add_alias_set_conflicts (void)
351 size_t i
, j
, n
= stack_vars_num
;
353 for (i
= 0; i
< n
; ++i
)
355 tree type_i
= TREE_TYPE (stack_vars
[i
].decl
);
356 bool aggr_i
= AGGREGATE_TYPE_P (type_i
);
359 contains_union
= aggregate_contains_union_type (type_i
);
360 for (j
= 0; j
< i
; ++j
)
362 tree type_j
= TREE_TYPE (stack_vars
[j
].decl
);
363 bool aggr_j
= AGGREGATE_TYPE_P (type_j
);
365 /* Either the objects conflict by means of type based
366 aliasing rules, or we need to add a conflict. */
367 || !objects_must_conflict_p (type_i
, type_j
)
368 /* In case the types do not conflict ensure that access
369 to elements will conflict. In case of unions we have
370 to be careful as type based aliasing rules may say
371 access to the same memory does not conflict. So play
372 safe and add a conflict in this case when
373 -fstrict-aliasing is used. */
374 || (contains_union
&& flag_strict_aliasing
))
375 add_stack_var_conflict (i
, j
);
380 /* A subroutine of partition_stack_vars. A comparison function for qsort,
381 sorting an array of indices by the properties of the object. */
384 stack_var_cmp (const void *a
, const void *b
)
386 size_t ia
= *(const size_t *)a
;
387 size_t ib
= *(const size_t *)b
;
388 unsigned int aligna
= stack_vars
[ia
].alignb
;
389 unsigned int alignb
= stack_vars
[ib
].alignb
;
390 HOST_WIDE_INT sizea
= stack_vars
[ia
].size
;
391 HOST_WIDE_INT sizeb
= stack_vars
[ib
].size
;
392 tree decla
= stack_vars
[ia
].decl
;
393 tree declb
= stack_vars
[ib
].decl
;
395 unsigned int uida
, uidb
;
397 /* Primary compare on "large" alignment. Large comes first. */
398 largea
= (aligna
* BITS_PER_UNIT
> MAX_SUPPORTED_STACK_ALIGNMENT
);
399 largeb
= (alignb
* BITS_PER_UNIT
> MAX_SUPPORTED_STACK_ALIGNMENT
);
400 if (largea
!= largeb
)
401 return (int)largeb
- (int)largea
;
403 /* Secondary compare on size, decreasing */
409 /* Tertiary compare on true alignment, decreasing. */
415 /* Final compare on ID for sort stability, increasing.
416 Two SSA names are compared by their version, SSA names come before
417 non-SSA names, and two normal decls are compared by their DECL_UID. */
418 if (TREE_CODE (decla
) == SSA_NAME
)
420 if (TREE_CODE (declb
) == SSA_NAME
)
421 uida
= SSA_NAME_VERSION (decla
), uidb
= SSA_NAME_VERSION (declb
);
425 else if (TREE_CODE (declb
) == SSA_NAME
)
428 uida
= DECL_UID (decla
), uidb
= DECL_UID (declb
);
437 /* If the points-to solution *PI points to variables that are in a partition
438 together with other variables add all partition members to the pointed-to
442 add_partitioned_vars_to_ptset (struct pt_solution
*pt
,
443 struct pointer_map_t
*decls_to_partitions
,
444 struct pointer_set_t
*visited
, bitmap temp
)
452 /* The pointed-to vars bitmap is shared, it is enough to
454 || pointer_set_insert(visited
, pt
->vars
))
459 /* By using a temporary bitmap to store all members of the partitions
460 we have to add we make sure to visit each of the partitions only
462 EXECUTE_IF_SET_IN_BITMAP (pt
->vars
, 0, i
, bi
)
464 || !bitmap_bit_p (temp
, i
))
465 && (part
= (bitmap
*) pointer_map_contains (decls_to_partitions
,
466 (void *)(size_t) i
)))
467 bitmap_ior_into (temp
, *part
);
468 if (!bitmap_empty_p (temp
))
469 bitmap_ior_into (pt
->vars
, temp
);
472 /* Update points-to sets based on partition info, so we can use them on RTL.
473 The bitmaps representing stack partitions will be saved until expand,
474 where partitioned decls used as bases in memory expressions will be
478 update_alias_info_with_stack_vars (void)
480 struct pointer_map_t
*decls_to_partitions
= NULL
;
482 tree var
= NULL_TREE
;
484 for (i
= 0; i
< stack_vars_num
; i
++)
488 struct ptr_info_def
*pi
;
490 /* Not interested in partitions with single variable. */
491 if (stack_vars
[i
].representative
!= i
492 || stack_vars
[i
].next
== EOC
)
495 if (!decls_to_partitions
)
497 decls_to_partitions
= pointer_map_create ();
498 cfun
->gimple_df
->decls_to_pointers
= pointer_map_create ();
501 /* Create an SSA_NAME that points to the partition for use
502 as base during alias-oracle queries on RTL for bases that
503 have been partitioned. */
504 if (var
== NULL_TREE
)
505 var
= create_tmp_var (ptr_type_node
, NULL
);
506 name
= make_ssa_name (var
, NULL
);
508 /* Create bitmaps representing partitions. They will be used for
509 points-to sets later, so use GGC alloc. */
510 part
= BITMAP_GGC_ALLOC ();
511 for (j
= i
; j
!= EOC
; j
= stack_vars
[j
].next
)
513 tree decl
= stack_vars
[j
].decl
;
514 unsigned int uid
= DECL_PT_UID (decl
);
515 /* We should never end up partitioning SSA names (though they
516 may end up on the stack). Neither should we allocate stack
517 space to something that is unused and thus unreferenced, except
518 for -O0 where we are preserving even unreferenced variables. */
519 gcc_assert (DECL_P (decl
)
521 || referenced_var_lookup (cfun
, DECL_UID (decl
))));
522 bitmap_set_bit (part
, uid
);
523 *((bitmap
*) pointer_map_insert (decls_to_partitions
,
524 (void *)(size_t) uid
)) = part
;
525 *((tree
*) pointer_map_insert (cfun
->gimple_df
->decls_to_pointers
,
529 /* Make the SSA name point to all partition members. */
530 pi
= get_ptr_info (name
);
531 pt_solution_set (&pi
->pt
, part
, false, false);
534 /* Make all points-to sets that contain one member of a partition
535 contain all members of the partition. */
536 if (decls_to_partitions
)
539 struct pointer_set_t
*visited
= pointer_set_create ();
540 bitmap temp
= BITMAP_ALLOC (NULL
);
542 for (i
= 1; i
< num_ssa_names
; i
++)
544 tree name
= ssa_name (i
);
545 struct ptr_info_def
*pi
;
548 && POINTER_TYPE_P (TREE_TYPE (name
))
549 && ((pi
= SSA_NAME_PTR_INFO (name
)) != NULL
))
550 add_partitioned_vars_to_ptset (&pi
->pt
, decls_to_partitions
,
554 add_partitioned_vars_to_ptset (&cfun
->gimple_df
->escaped
,
555 decls_to_partitions
, visited
, temp
);
557 pointer_set_destroy (visited
);
558 pointer_map_destroy (decls_to_partitions
);
563 /* A subroutine of partition_stack_vars. The UNION portion of a UNION/FIND
564 partitioning algorithm. Partitions A and B are known to be non-conflicting.
565 Merge them into a single partition A. */
568 union_stack_vars (size_t a
, size_t b
)
570 struct stack_var
*vb
= &stack_vars
[b
];
574 gcc_assert (stack_vars
[b
].next
== EOC
);
575 /* Add B to A's partition. */
576 stack_vars
[b
].next
= stack_vars
[a
].next
;
577 stack_vars
[b
].representative
= a
;
578 stack_vars
[a
].next
= b
;
580 /* Update the required alignment of partition A to account for B. */
581 if (stack_vars
[a
].alignb
< stack_vars
[b
].alignb
)
582 stack_vars
[a
].alignb
= stack_vars
[b
].alignb
;
584 /* Update the interference graph and merge the conflicts. */
587 EXECUTE_IF_SET_IN_BITMAP (vb
->conflicts
, 0, u
, bi
)
588 add_stack_var_conflict (a
, stack_vars
[u
].representative
);
589 BITMAP_FREE (vb
->conflicts
);
593 /* A subroutine of expand_used_vars. Binpack the variables into
594 partitions constrained by the interference graph. The overall
595 algorithm used is as follows:
597 Sort the objects by size in descending order.
602 Look for the largest non-conflicting object B with size <= S.
609 partition_stack_vars (void)
611 size_t si
, sj
, n
= stack_vars_num
;
613 stack_vars_sorted
= XNEWVEC (size_t, stack_vars_num
);
614 for (si
= 0; si
< n
; ++si
)
615 stack_vars_sorted
[si
] = si
;
620 qsort (stack_vars_sorted
, n
, sizeof (size_t), stack_var_cmp
);
622 for (si
= 0; si
< n
; ++si
)
624 size_t i
= stack_vars_sorted
[si
];
625 unsigned int ialign
= stack_vars
[i
].alignb
;
627 /* Ignore objects that aren't partition representatives. If we
628 see a var that is not a partition representative, it must
629 have been merged earlier. */
630 if (stack_vars
[i
].representative
!= i
)
633 for (sj
= si
+ 1; sj
< n
; ++sj
)
635 size_t j
= stack_vars_sorted
[sj
];
636 unsigned int jalign
= stack_vars
[j
].alignb
;
638 /* Ignore objects that aren't partition representatives. */
639 if (stack_vars
[j
].representative
!= j
)
642 /* Ignore conflicting objects. */
643 if (stack_var_conflict_p (i
, j
))
646 /* Do not mix objects of "small" (supported) alignment
647 and "large" (unsupported) alignment. */
648 if ((ialign
* BITS_PER_UNIT
<= MAX_SUPPORTED_STACK_ALIGNMENT
)
649 != (jalign
* BITS_PER_UNIT
<= MAX_SUPPORTED_STACK_ALIGNMENT
))
652 /* UNION the objects, placing J at OFFSET. */
653 union_stack_vars (i
, j
);
657 update_alias_info_with_stack_vars ();
660 /* A debugging aid for expand_used_vars. Dump the generated partitions. */
663 dump_stack_var_partition (void)
665 size_t si
, i
, j
, n
= stack_vars_num
;
667 for (si
= 0; si
< n
; ++si
)
669 i
= stack_vars_sorted
[si
];
671 /* Skip variables that aren't partition representatives, for now. */
672 if (stack_vars
[i
].representative
!= i
)
675 fprintf (dump_file
, "Partition %lu: size " HOST_WIDE_INT_PRINT_DEC
676 " align %u\n", (unsigned long) i
, stack_vars
[i
].size
,
677 stack_vars
[i
].alignb
);
679 for (j
= i
; j
!= EOC
; j
= stack_vars
[j
].next
)
681 fputc ('\t', dump_file
);
682 print_generic_expr (dump_file
, stack_vars
[j
].decl
, dump_flags
);
684 fputc ('\n', dump_file
);
688 /* Assign rtl to DECL at BASE + OFFSET. */
691 expand_one_stack_var_at (tree decl
, rtx base
, unsigned base_align
,
692 HOST_WIDE_INT offset
)
697 /* If this fails, we've overflowed the stack frame. Error nicely? */
698 gcc_assert (offset
== trunc_int_for_mode (offset
, Pmode
));
700 x
= plus_constant (base
, offset
);
701 x
= gen_rtx_MEM (DECL_MODE (SSAVAR (decl
)), x
);
703 if (TREE_CODE (decl
) != SSA_NAME
)
705 /* Set alignment we actually gave this decl if it isn't an SSA name.
706 If it is we generate stack slots only accidentally so it isn't as
707 important, we'll simply use the alignment that is already set. */
708 if (base
== virtual_stack_vars_rtx
)
709 offset
-= frame_phase
;
710 align
= offset
& -offset
;
711 align
*= BITS_PER_UNIT
;
712 if (align
== 0 || align
> base_align
)
715 /* One would think that we could assert that we're not decreasing
716 alignment here, but (at least) the i386 port does exactly this
717 via the MINIMUM_ALIGNMENT hook. */
719 DECL_ALIGN (decl
) = align
;
720 DECL_USER_ALIGN (decl
) = 0;
723 set_mem_attributes (x
, SSAVAR (decl
), true);
727 /* A subroutine of expand_used_vars. Give each partition representative
728 a unique location within the stack frame. Update each partition member
729 with that location. */
732 expand_stack_vars (bool (*pred
) (tree
))
734 size_t si
, i
, j
, n
= stack_vars_num
;
735 HOST_WIDE_INT large_size
= 0, large_alloc
= 0;
736 rtx large_base
= NULL
;
737 unsigned large_align
= 0;
740 /* Determine if there are any variables requiring "large" alignment.
741 Since these are dynamically allocated, we only process these if
742 no predicate involved. */
743 large_align
= stack_vars
[stack_vars_sorted
[0]].alignb
* BITS_PER_UNIT
;
744 if (pred
== NULL
&& large_align
> MAX_SUPPORTED_STACK_ALIGNMENT
)
746 /* Find the total size of these variables. */
747 for (si
= 0; si
< n
; ++si
)
751 i
= stack_vars_sorted
[si
];
752 alignb
= stack_vars
[i
].alignb
;
754 /* Stop when we get to the first decl with "small" alignment. */
755 if (alignb
* BITS_PER_UNIT
<= MAX_SUPPORTED_STACK_ALIGNMENT
)
758 /* Skip variables that aren't partition representatives. */
759 if (stack_vars
[i
].representative
!= i
)
762 /* Skip variables that have already had rtl assigned. See also
763 add_stack_var where we perpetrate this pc_rtx hack. */
764 decl
= stack_vars
[i
].decl
;
765 if ((TREE_CODE (decl
) == SSA_NAME
766 ? SA
.partition_to_pseudo
[var_to_partition (SA
.map
, decl
)]
767 : DECL_RTL (decl
)) != pc_rtx
)
770 large_size
+= alignb
- 1;
771 large_size
&= -(HOST_WIDE_INT
)alignb
;
772 large_size
+= stack_vars
[i
].size
;
775 /* If there were any, allocate space. */
777 large_base
= allocate_dynamic_stack_space (GEN_INT (large_size
), 0,
781 for (si
= 0; si
< n
; ++si
)
784 unsigned base_align
, alignb
;
785 HOST_WIDE_INT offset
;
787 i
= stack_vars_sorted
[si
];
789 /* Skip variables that aren't partition representatives, for now. */
790 if (stack_vars
[i
].representative
!= i
)
793 /* Skip variables that have already had rtl assigned. See also
794 add_stack_var where we perpetrate this pc_rtx hack. */
795 decl
= stack_vars
[i
].decl
;
796 if ((TREE_CODE (decl
) == SSA_NAME
797 ? SA
.partition_to_pseudo
[var_to_partition (SA
.map
, decl
)]
798 : DECL_RTL (decl
)) != pc_rtx
)
801 /* Check the predicate to see whether this variable should be
802 allocated in this pass. */
803 if (pred
&& !pred (decl
))
806 alignb
= stack_vars
[i
].alignb
;
807 if (alignb
* BITS_PER_UNIT
<= MAX_SUPPORTED_STACK_ALIGNMENT
)
809 offset
= alloc_stack_frame_space (stack_vars
[i
].size
, alignb
);
810 base
= virtual_stack_vars_rtx
;
811 base_align
= crtl
->max_used_stack_slot_alignment
;
815 /* Large alignment is only processed in the last pass. */
818 gcc_assert (large_base
!= NULL
);
820 large_alloc
+= alignb
- 1;
821 large_alloc
&= -(HOST_WIDE_INT
)alignb
;
822 offset
= large_alloc
;
823 large_alloc
+= stack_vars
[i
].size
;
826 base_align
= large_align
;
829 /* Create rtl for each variable based on their location within the
831 for (j
= i
; j
!= EOC
; j
= stack_vars
[j
].next
)
833 expand_one_stack_var_at (stack_vars
[j
].decl
,
839 gcc_assert (large_alloc
== large_size
);
842 /* Take into account all sizes of partitions and reset DECL_RTLs. */
844 account_stack_vars (void)
846 size_t si
, j
, i
, n
= stack_vars_num
;
847 HOST_WIDE_INT size
= 0;
849 for (si
= 0; si
< n
; ++si
)
851 i
= stack_vars_sorted
[si
];
853 /* Skip variables that aren't partition representatives, for now. */
854 if (stack_vars
[i
].representative
!= i
)
857 size
+= stack_vars
[i
].size
;
858 for (j
= i
; j
!= EOC
; j
= stack_vars
[j
].next
)
859 set_rtl (stack_vars
[j
].decl
, NULL
);
864 /* A subroutine of expand_one_var. Called to immediately assign rtl
865 to a variable to be allocated in the stack frame. */
868 expand_one_stack_var (tree var
)
870 HOST_WIDE_INT size
, offset
;
873 size
= tree_low_cst (DECL_SIZE_UNIT (SSAVAR (var
)), 1);
874 byte_align
= align_local_variable (SSAVAR (var
));
876 /* We handle highly aligned variables in expand_stack_vars. */
877 gcc_assert (byte_align
* BITS_PER_UNIT
<= MAX_SUPPORTED_STACK_ALIGNMENT
);
879 offset
= alloc_stack_frame_space (size
, byte_align
);
881 expand_one_stack_var_at (var
, virtual_stack_vars_rtx
,
882 crtl
->max_used_stack_slot_alignment
, offset
);
885 /* A subroutine of expand_one_var. Called to assign rtl to a VAR_DECL
886 that will reside in a hard register. */
889 expand_one_hard_reg_var (tree var
)
891 rest_of_decl_compilation (var
, 0, 0);
894 /* A subroutine of expand_one_var. Called to assign rtl to a VAR_DECL
895 that will reside in a pseudo register. */
898 expand_one_register_var (tree var
)
900 tree decl
= SSAVAR (var
);
901 tree type
= TREE_TYPE (decl
);
902 enum machine_mode reg_mode
= promote_decl_mode (decl
, NULL
);
903 rtx x
= gen_reg_rtx (reg_mode
);
907 /* Note if the object is a user variable. */
908 if (!DECL_ARTIFICIAL (decl
))
911 if (POINTER_TYPE_P (type
))
912 mark_reg_pointer (x
, TYPE_ALIGN (TREE_TYPE (type
)));
915 /* A subroutine of expand_one_var. Called to assign rtl to a VAR_DECL that
916 has some associated error, e.g. its type is error-mark. We just need
917 to pick something that won't crash the rest of the compiler. */
920 expand_one_error_var (tree var
)
922 enum machine_mode mode
= DECL_MODE (var
);
926 x
= gen_rtx_MEM (BLKmode
, const0_rtx
);
927 else if (mode
== VOIDmode
)
930 x
= gen_reg_rtx (mode
);
932 SET_DECL_RTL (var
, x
);
935 /* A subroutine of expand_one_var. VAR is a variable that will be
936 allocated to the local stack frame. Return true if we wish to
937 add VAR to STACK_VARS so that it will be coalesced with other
938 variables. Return false to allocate VAR immediately.
940 This function is used to reduce the number of variables considered
941 for coalescing, which reduces the size of the quadratic problem. */
944 defer_stack_allocation (tree var
, bool toplevel
)
946 /* If stack protection is enabled, *all* stack variables must be deferred,
947 so that we can re-order the strings to the top of the frame. */
948 if (flag_stack_protect
)
951 /* We handle "large" alignment via dynamic allocation. We want to handle
952 this extra complication in only one place, so defer them. */
953 if (DECL_ALIGN (var
) > MAX_SUPPORTED_STACK_ALIGNMENT
)
956 /* Variables in the outermost scope automatically conflict with
957 every other variable. The only reason to want to defer them
958 at all is that, after sorting, we can more efficiently pack
959 small variables in the stack frame. Continue to defer at -O2. */
960 if (toplevel
&& optimize
< 2)
963 /* Without optimization, *most* variables are allocated from the
964 stack, which makes the quadratic problem large exactly when we
965 want compilation to proceed as quickly as possible. On the
966 other hand, we don't want the function's stack frame size to
967 get completely out of hand. So we avoid adding scalars and
968 "small" aggregates to the list at all. */
969 if (optimize
== 0 && tree_low_cst (DECL_SIZE_UNIT (var
), 1) < 32)
975 /* A subroutine of expand_used_vars. Expand one variable according to
976 its flavor. Variables to be placed on the stack are not actually
977 expanded yet, merely recorded.
978 When REALLY_EXPAND is false, only add stack values to be allocated.
979 Return stack usage this variable is supposed to take.
983 expand_one_var (tree var
, bool toplevel
, bool really_expand
)
985 unsigned int align
= BITS_PER_UNIT
;
990 if (TREE_TYPE (var
) != error_mark_node
&& TREE_CODE (var
) == VAR_DECL
)
992 /* Because we don't know if VAR will be in register or on stack,
993 we conservatively assume it will be on stack even if VAR is
994 eventually put into register after RA pass. For non-automatic
995 variables, which won't be on stack, we collect alignment of
996 type and ignore user specified alignment. */
997 if (TREE_STATIC (var
) || DECL_EXTERNAL (var
))
998 align
= MINIMUM_ALIGNMENT (TREE_TYPE (var
),
999 TYPE_MODE (TREE_TYPE (var
)),
1000 TYPE_ALIGN (TREE_TYPE (var
)));
1001 else if (DECL_HAS_VALUE_EXPR_P (var
)
1002 || (DECL_RTL_SET_P (var
) && MEM_P (DECL_RTL (var
))))
1003 /* Don't consider debug only variables with DECL_HAS_VALUE_EXPR_P set
1004 or variables which were assigned a stack slot already by
1005 expand_one_stack_var_at - in the latter case DECL_ALIGN has been
1006 changed from the offset chosen to it. */
1007 align
= crtl
->stack_alignment_estimated
;
1009 align
= MINIMUM_ALIGNMENT (var
, DECL_MODE (var
), DECL_ALIGN (var
));
1011 /* If the variable alignment is very large we'll dynamicaly allocate
1012 it, which means that in-frame portion is just a pointer. */
1013 if (align
> MAX_SUPPORTED_STACK_ALIGNMENT
)
1014 align
= POINTER_SIZE
;
1017 if (SUPPORTS_STACK_ALIGNMENT
1018 && crtl
->stack_alignment_estimated
< align
)
1020 /* stack_alignment_estimated shouldn't change after stack
1021 realign decision made */
1022 gcc_assert(!crtl
->stack_realign_processed
);
1023 crtl
->stack_alignment_estimated
= align
;
1026 /* stack_alignment_needed > PREFERRED_STACK_BOUNDARY is permitted.
1027 So here we only make sure stack_alignment_needed >= align. */
1028 if (crtl
->stack_alignment_needed
< align
)
1029 crtl
->stack_alignment_needed
= align
;
1030 if (crtl
->max_used_stack_slot_alignment
< align
)
1031 crtl
->max_used_stack_slot_alignment
= align
;
1033 if (TREE_CODE (origvar
) == SSA_NAME
)
1035 gcc_assert (TREE_CODE (var
) != VAR_DECL
1036 || (!DECL_EXTERNAL (var
)
1037 && !DECL_HAS_VALUE_EXPR_P (var
)
1038 && !TREE_STATIC (var
)
1039 && TREE_TYPE (var
) != error_mark_node
1040 && !DECL_HARD_REGISTER (var
)
1043 if (TREE_CODE (var
) != VAR_DECL
&& TREE_CODE (origvar
) != SSA_NAME
)
1045 else if (DECL_EXTERNAL (var
))
1047 else if (DECL_HAS_VALUE_EXPR_P (var
))
1049 else if (TREE_STATIC (var
))
1051 else if (TREE_CODE (origvar
) != SSA_NAME
&& DECL_RTL_SET_P (var
))
1053 else if (TREE_TYPE (var
) == error_mark_node
)
1056 expand_one_error_var (var
);
1058 else if (TREE_CODE (var
) == VAR_DECL
&& DECL_HARD_REGISTER (var
))
1061 expand_one_hard_reg_var (var
);
1063 else if (use_register_for_decl (var
))
1066 expand_one_register_var (origvar
);
1068 else if (!host_integerp (DECL_SIZE_UNIT (var
), 1))
1072 error ("size of variable %q+D is too large", var
);
1073 expand_one_error_var (var
);
1076 else if (defer_stack_allocation (var
, toplevel
))
1077 add_stack_var (origvar
);
1081 expand_one_stack_var (origvar
);
1082 return tree_low_cst (DECL_SIZE_UNIT (var
), 1);
1087 /* A subroutine of expand_used_vars. Walk down through the BLOCK tree
1088 expanding variables. Those variables that can be put into registers
1089 are allocated pseudos; those that can't are put on the stack.
1091 TOPLEVEL is true if this is the outermost BLOCK. */
1094 expand_used_vars_for_block (tree block
, bool toplevel
)
1096 size_t i
, j
, old_sv_num
, this_sv_num
, new_sv_num
;
1099 old_sv_num
= toplevel
? 0 : stack_vars_num
;
1101 /* Expand all variables at this level. */
1102 for (t
= BLOCK_VARS (block
); t
; t
= DECL_CHAIN (t
))
1104 && ((TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != RESULT_DECL
)
1105 || !DECL_NONSHAREABLE (t
)))
1106 expand_one_var (t
, toplevel
, true);
1108 this_sv_num
= stack_vars_num
;
1110 /* Expand all variables at containing levels. */
1111 for (t
= BLOCK_SUBBLOCKS (block
); t
; t
= BLOCK_CHAIN (t
))
1112 expand_used_vars_for_block (t
, false);
1114 /* Since we do not track exact variable lifetimes (which is not even
1115 possible for variables whose address escapes), we mirror the block
1116 tree in the interference graph. Here we cause all variables at this
1117 level, and all sublevels, to conflict. */
1118 if (old_sv_num
< this_sv_num
)
1120 new_sv_num
= stack_vars_num
;
1122 for (i
= old_sv_num
; i
< new_sv_num
; ++i
)
1123 for (j
= i
< this_sv_num
? i
: this_sv_num
; j
-- > old_sv_num
;)
1124 add_stack_var_conflict (i
, j
);
1128 /* A subroutine of expand_used_vars. Walk down through the BLOCK tree
1129 and clear TREE_USED on all local variables. */
1132 clear_tree_used (tree block
)
1136 for (t
= BLOCK_VARS (block
); t
; t
= DECL_CHAIN (t
))
1137 /* if (!TREE_STATIC (t) && !DECL_EXTERNAL (t)) */
1138 if ((TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != RESULT_DECL
)
1139 || !DECL_NONSHAREABLE (t
))
1142 for (t
= BLOCK_SUBBLOCKS (block
); t
; t
= BLOCK_CHAIN (t
))
1143 clear_tree_used (t
);
1146 /* Examine TYPE and determine a bit mask of the following features. */
1148 #define SPCT_HAS_LARGE_CHAR_ARRAY 1
1149 #define SPCT_HAS_SMALL_CHAR_ARRAY 2
1150 #define SPCT_HAS_ARRAY 4
1151 #define SPCT_HAS_AGGREGATE 8
1154 stack_protect_classify_type (tree type
)
1156 unsigned int ret
= 0;
1159 switch (TREE_CODE (type
))
1162 t
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
1163 if (t
== char_type_node
1164 || t
== signed_char_type_node
1165 || t
== unsigned_char_type_node
)
1167 unsigned HOST_WIDE_INT max
= PARAM_VALUE (PARAM_SSP_BUFFER_SIZE
);
1168 unsigned HOST_WIDE_INT len
;
1170 if (!TYPE_SIZE_UNIT (type
)
1171 || !host_integerp (TYPE_SIZE_UNIT (type
), 1))
1174 len
= tree_low_cst (TYPE_SIZE_UNIT (type
), 1);
1177 ret
= SPCT_HAS_SMALL_CHAR_ARRAY
| SPCT_HAS_ARRAY
;
1179 ret
= SPCT_HAS_LARGE_CHAR_ARRAY
| SPCT_HAS_ARRAY
;
1182 ret
= SPCT_HAS_ARRAY
;
1186 case QUAL_UNION_TYPE
:
1188 ret
= SPCT_HAS_AGGREGATE
;
1189 for (t
= TYPE_FIELDS (type
); t
; t
= TREE_CHAIN (t
))
1190 if (TREE_CODE (t
) == FIELD_DECL
)
1191 ret
|= stack_protect_classify_type (TREE_TYPE (t
));
1201 /* Return nonzero if DECL should be segregated into the "vulnerable" upper
1202 part of the local stack frame. Remember if we ever return nonzero for
1203 any variable in this function. The return value is the phase number in
1204 which the variable should be allocated. */
1207 stack_protect_decl_phase (tree decl
)
1209 unsigned int bits
= stack_protect_classify_type (TREE_TYPE (decl
));
1212 if (bits
& SPCT_HAS_SMALL_CHAR_ARRAY
)
1213 has_short_buffer
= true;
1215 if (flag_stack_protect
== 2)
1217 if ((bits
& (SPCT_HAS_SMALL_CHAR_ARRAY
| SPCT_HAS_LARGE_CHAR_ARRAY
))
1218 && !(bits
& SPCT_HAS_AGGREGATE
))
1220 else if (bits
& SPCT_HAS_ARRAY
)
1224 ret
= (bits
& SPCT_HAS_LARGE_CHAR_ARRAY
) != 0;
1227 has_protected_decls
= true;
1232 /* Two helper routines that check for phase 1 and phase 2. These are used
1233 as callbacks for expand_stack_vars. */
1236 stack_protect_decl_phase_1 (tree decl
)
1238 return stack_protect_decl_phase (decl
) == 1;
1242 stack_protect_decl_phase_2 (tree decl
)
1244 return stack_protect_decl_phase (decl
) == 2;
1247 /* Ensure that variables in different stack protection phases conflict
1248 so that they are not merged and share the same stack slot. */
1251 add_stack_protection_conflicts (void)
1253 size_t i
, j
, n
= stack_vars_num
;
1254 unsigned char *phase
;
1256 phase
= XNEWVEC (unsigned char, n
);
1257 for (i
= 0; i
< n
; ++i
)
1258 phase
[i
] = stack_protect_decl_phase (stack_vars
[i
].decl
);
1260 for (i
= 0; i
< n
; ++i
)
1262 unsigned char ph_i
= phase
[i
];
1263 for (j
= 0; j
< i
; ++j
)
1264 if (ph_i
!= phase
[j
])
1265 add_stack_var_conflict (i
, j
);
1271 /* Create a decl for the guard at the top of the stack frame. */
1274 create_stack_guard (void)
1276 tree guard
= build_decl (DECL_SOURCE_LOCATION (current_function_decl
),
1277 VAR_DECL
, NULL
, ptr_type_node
);
1278 TREE_THIS_VOLATILE (guard
) = 1;
1279 TREE_USED (guard
) = 1;
1280 expand_one_stack_var (guard
);
1281 crtl
->stack_protect_guard
= guard
;
1284 /* Prepare for expanding variables. */
1286 init_vars_expansion (void)
1290 /* Set TREE_USED on all variables in the local_decls. */
1291 FOR_EACH_LOCAL_DECL (cfun
, ix
, t
)
1294 /* Clear TREE_USED on all variables associated with a block scope. */
1295 clear_tree_used (DECL_INITIAL (current_function_decl
));
1297 /* Initialize local stack smashing state. */
1298 has_protected_decls
= false;
1299 has_short_buffer
= false;
1302 /* Free up stack variable graph data. */
1304 fini_vars_expansion (void)
1306 size_t i
, n
= stack_vars_num
;
1307 for (i
= 0; i
< n
; i
++)
1308 BITMAP_FREE (stack_vars
[i
].conflicts
);
1309 XDELETEVEC (stack_vars
);
1310 XDELETEVEC (stack_vars_sorted
);
1312 stack_vars_alloc
= stack_vars_num
= 0;
1315 /* Make a fair guess for the size of the stack frame of the function
1316 in NODE. This doesn't have to be exact, the result is only used in
1317 the inline heuristics. So we don't want to run the full stack var
1318 packing algorithm (which is quadratic in the number of stack vars).
1319 Instead, we calculate the total size of all stack vars. This turns
1320 out to be a pretty fair estimate -- packing of stack vars doesn't
1321 happen very often. */
1324 estimated_stack_frame_size (struct cgraph_node
*node
)
1326 HOST_WIDE_INT size
= 0;
1329 tree old_cur_fun_decl
= current_function_decl
;
1330 referenced_var_iterator rvi
;
1331 struct function
*fn
= DECL_STRUCT_FUNCTION (node
->decl
);
1333 current_function_decl
= node
->decl
;
1336 gcc_checking_assert (gimple_referenced_vars (fn
));
1337 FOR_EACH_REFERENCED_VAR (fn
, var
, rvi
)
1338 size
+= expand_one_var (var
, true, false);
1340 if (stack_vars_num
> 0)
1342 /* Fake sorting the stack vars for account_stack_vars (). */
1343 stack_vars_sorted
= XNEWVEC (size_t, stack_vars_num
);
1344 for (i
= 0; i
< stack_vars_num
; ++i
)
1345 stack_vars_sorted
[i
] = i
;
1346 size
+= account_stack_vars ();
1347 fini_vars_expansion ();
1350 current_function_decl
= old_cur_fun_decl
;
1354 /* Expand all variables used in the function. */
1357 expand_used_vars (void)
1359 tree var
, outer_block
= DECL_INITIAL (current_function_decl
);
1360 VEC(tree
,heap
) *maybe_local_decls
= NULL
;
1364 /* Compute the phase of the stack frame for this function. */
1366 int align
= PREFERRED_STACK_BOUNDARY
/ BITS_PER_UNIT
;
1367 int off
= STARTING_FRAME_OFFSET
% align
;
1368 frame_phase
= off
? align
- off
: 0;
1371 init_vars_expansion ();
1373 for (i
= 0; i
< SA
.map
->num_partitions
; i
++)
1375 tree var
= partition_to_var (SA
.map
, i
);
1377 gcc_assert (is_gimple_reg (var
));
1378 if (TREE_CODE (SSA_NAME_VAR (var
)) == VAR_DECL
)
1379 expand_one_var (var
, true, true);
1382 /* This is a PARM_DECL or RESULT_DECL. For those partitions that
1383 contain the default def (representing the parm or result itself)
1384 we don't do anything here. But those which don't contain the
1385 default def (representing a temporary based on the parm/result)
1386 we need to allocate space just like for normal VAR_DECLs. */
1387 if (!bitmap_bit_p (SA
.partition_has_default_def
, i
))
1389 expand_one_var (var
, true, true);
1390 gcc_assert (SA
.partition_to_pseudo
[i
]);
1395 /* At this point all variables on the local_decls with TREE_USED
1396 set are not associated with any block scope. Lay them out. */
1398 len
= VEC_length (tree
, cfun
->local_decls
);
1399 FOR_EACH_LOCAL_DECL (cfun
, i
, var
)
1401 bool expand_now
= false;
1403 /* Expanded above already. */
1404 if (is_gimple_reg (var
))
1406 TREE_USED (var
) = 0;
1409 /* We didn't set a block for static or extern because it's hard
1410 to tell the difference between a global variable (re)declared
1411 in a local scope, and one that's really declared there to
1412 begin with. And it doesn't really matter much, since we're
1413 not giving them stack space. Expand them now. */
1414 else if (TREE_STATIC (var
) || DECL_EXTERNAL (var
))
1417 /* If the variable is not associated with any block, then it
1418 was created by the optimizers, and could be live anywhere
1420 else if (TREE_USED (var
))
1423 /* Finally, mark all variables on the list as used. We'll use
1424 this in a moment when we expand those associated with scopes. */
1425 TREE_USED (var
) = 1;
1428 expand_one_var (var
, true, true);
1431 if (DECL_ARTIFICIAL (var
) && !DECL_IGNORED_P (var
))
1433 rtx rtl
= DECL_RTL_IF_SET (var
);
1435 /* Keep artificial non-ignored vars in cfun->local_decls
1436 chain until instantiate_decls. */
1437 if (rtl
&& (MEM_P (rtl
) || GET_CODE (rtl
) == CONCAT
))
1438 add_local_decl (cfun
, var
);
1439 else if (rtl
== NULL_RTX
)
1440 /* If rtl isn't set yet, which can happen e.g. with
1441 -fstack-protector, retry before returning from this
1443 VEC_safe_push (tree
, heap
, maybe_local_decls
, var
);
1447 /* We duplicated some of the decls in CFUN->LOCAL_DECLS.
1449 +-----------------+-----------------+
1450 | ...processed... | ...duplicates...|
1451 +-----------------+-----------------+
1453 +-- LEN points here.
1455 We just want the duplicates, as those are the artificial
1456 non-ignored vars that we want to keep until instantiate_decls.
1457 Move them down and truncate the array. */
1458 if (!VEC_empty (tree
, cfun
->local_decls
))
1459 VEC_block_remove (tree
, cfun
->local_decls
, 0, len
);
1461 /* At this point, all variables within the block tree with TREE_USED
1462 set are actually used by the optimized function. Lay them out. */
1463 expand_used_vars_for_block (outer_block
, true);
1465 if (stack_vars_num
> 0)
1467 /* Due to the way alias sets work, no variables with non-conflicting
1468 alias sets may be assigned the same address. Add conflicts to
1470 add_alias_set_conflicts ();
1472 /* If stack protection is enabled, we don't share space between
1473 vulnerable data and non-vulnerable data. */
1474 if (flag_stack_protect
)
1475 add_stack_protection_conflicts ();
1477 /* Now that we have collected all stack variables, and have computed a
1478 minimal interference graph, attempt to save some stack space. */
1479 partition_stack_vars ();
1481 dump_stack_var_partition ();
1484 /* There are several conditions under which we should create a
1485 stack guard: protect-all, alloca used, protected decls present. */
1486 if (flag_stack_protect
== 2
1487 || (flag_stack_protect
1488 && (cfun
->calls_alloca
|| has_protected_decls
)))
1489 create_stack_guard ();
1491 /* Assign rtl to each variable based on these partitions. */
1492 if (stack_vars_num
> 0)
1494 /* Reorder decls to be protected by iterating over the variables
1495 array multiple times, and allocating out of each phase in turn. */
1496 /* ??? We could probably integrate this into the qsort we did
1497 earlier, such that we naturally see these variables first,
1498 and thus naturally allocate things in the right order. */
1499 if (has_protected_decls
)
1501 /* Phase 1 contains only character arrays. */
1502 expand_stack_vars (stack_protect_decl_phase_1
);
1504 /* Phase 2 contains other kinds of arrays. */
1505 if (flag_stack_protect
== 2)
1506 expand_stack_vars (stack_protect_decl_phase_2
);
1509 expand_stack_vars (NULL
);
1511 fini_vars_expansion ();
1514 /* If there were any artificial non-ignored vars without rtl
1515 found earlier, see if deferred stack allocation hasn't assigned
1517 FOR_EACH_VEC_ELT_REVERSE (tree
, maybe_local_decls
, i
, var
)
1519 rtx rtl
= DECL_RTL_IF_SET (var
);
1521 /* Keep artificial non-ignored vars in cfun->local_decls
1522 chain until instantiate_decls. */
1523 if (rtl
&& (MEM_P (rtl
) || GET_CODE (rtl
) == CONCAT
))
1524 add_local_decl (cfun
, var
);
1526 VEC_free (tree
, heap
, maybe_local_decls
);
1528 /* If the target requires that FRAME_OFFSET be aligned, do it. */
1529 if (STACK_ALIGNMENT_NEEDED
)
1531 HOST_WIDE_INT align
= PREFERRED_STACK_BOUNDARY
/ BITS_PER_UNIT
;
1532 if (!FRAME_GROWS_DOWNWARD
)
1533 frame_offset
+= align
- 1;
1534 frame_offset
&= -align
;
1539 /* If we need to produce a detailed dump, print the tree representation
1540 for STMT to the dump file. SINCE is the last RTX after which the RTL
1541 generated for STMT should have been appended. */
1544 maybe_dump_rtl_for_gimple_stmt (gimple stmt
, rtx since
)
1546 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1548 fprintf (dump_file
, "\n;; ");
1549 print_gimple_stmt (dump_file
, stmt
, 0,
1550 TDF_SLIM
| (dump_flags
& TDF_LINENO
));
1551 fprintf (dump_file
, "\n");
1553 print_rtl (dump_file
, since
? NEXT_INSN (since
) : since
);
1557 /* Maps the blocks that do not contain tree labels to rtx labels. */
1559 static struct pointer_map_t
*lab_rtx_for_bb
;
1561 /* Returns the label_rtx expression for a label starting basic block BB. */
1564 label_rtx_for_bb (basic_block bb ATTRIBUTE_UNUSED
)
1566 gimple_stmt_iterator gsi
;
1571 if (bb
->flags
& BB_RTL
)
1572 return block_label (bb
);
1574 elt
= pointer_map_contains (lab_rtx_for_bb
, bb
);
1578 /* Find the tree label if it is present. */
1580 for (gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
1582 lab_stmt
= gsi_stmt (gsi
);
1583 if (gimple_code (lab_stmt
) != GIMPLE_LABEL
)
1586 lab
= gimple_label_label (lab_stmt
);
1587 if (DECL_NONLOCAL (lab
))
1590 return label_rtx (lab
);
1593 elt
= pointer_map_insert (lab_rtx_for_bb
, bb
);
1594 *elt
= gen_label_rtx ();
1599 /* A subroutine of expand_gimple_cond. Given E, a fallthrough edge
1600 of a basic block where we just expanded the conditional at the end,
1601 possibly clean up the CFG and instruction sequence. LAST is the
1602 last instruction before the just emitted jump sequence. */
1605 maybe_cleanup_end_of_block (edge e
, rtx last
)
1607 /* Special case: when jumpif decides that the condition is
1608 trivial it emits an unconditional jump (and the necessary
1609 barrier). But we still have two edges, the fallthru one is
1610 wrong. purge_dead_edges would clean this up later. Unfortunately
1611 we have to insert insns (and split edges) before
1612 find_many_sub_basic_blocks and hence before purge_dead_edges.
1613 But splitting edges might create new blocks which depend on the
1614 fact that if there are two edges there's no barrier. So the
1615 barrier would get lost and verify_flow_info would ICE. Instead
1616 of auditing all edge splitters to care for the barrier (which
1617 normally isn't there in a cleaned CFG), fix it here. */
1618 if (BARRIER_P (get_last_insn ()))
1622 /* Now, we have a single successor block, if we have insns to
1623 insert on the remaining edge we potentially will insert
1624 it at the end of this block (if the dest block isn't feasible)
1625 in order to avoid splitting the edge. This insertion will take
1626 place in front of the last jump. But we might have emitted
1627 multiple jumps (conditional and one unconditional) to the
1628 same destination. Inserting in front of the last one then
1629 is a problem. See PR 40021. We fix this by deleting all
1630 jumps except the last unconditional one. */
1631 insn
= PREV_INSN (get_last_insn ());
1632 /* Make sure we have an unconditional jump. Otherwise we're
1634 gcc_assert (JUMP_P (insn
) && !any_condjump_p (insn
));
1635 for (insn
= PREV_INSN (insn
); insn
!= last
;)
1637 insn
= PREV_INSN (insn
);
1638 if (JUMP_P (NEXT_INSN (insn
)))
1640 if (!any_condjump_p (NEXT_INSN (insn
)))
1642 gcc_assert (BARRIER_P (NEXT_INSN (NEXT_INSN (insn
))));
1643 delete_insn (NEXT_INSN (NEXT_INSN (insn
)));
1645 delete_insn (NEXT_INSN (insn
));
1651 /* A subroutine of expand_gimple_basic_block. Expand one GIMPLE_COND.
1652 Returns a new basic block if we've terminated the current basic
1653 block and created a new one. */
1656 expand_gimple_cond (basic_block bb
, gimple stmt
)
1658 basic_block new_bb
, dest
;
1663 enum tree_code code
;
1666 code
= gimple_cond_code (stmt
);
1667 op0
= gimple_cond_lhs (stmt
);
1668 op1
= gimple_cond_rhs (stmt
);
1669 /* We're sometimes presented with such code:
1673 This would expand to two comparisons which then later might
1674 be cleaned up by combine. But some pattern matchers like if-conversion
1675 work better when there's only one compare, so make up for this
1676 here as special exception if TER would have made the same change. */
1677 if (gimple_cond_single_var_p (stmt
)
1679 && TREE_CODE (op0
) == SSA_NAME
1680 && bitmap_bit_p (SA
.values
, SSA_NAME_VERSION (op0
)))
1682 gimple second
= SSA_NAME_DEF_STMT (op0
);
1683 if (gimple_code (second
) == GIMPLE_ASSIGN
)
1685 enum tree_code code2
= gimple_assign_rhs_code (second
);
1686 if (TREE_CODE_CLASS (code2
) == tcc_comparison
)
1689 op0
= gimple_assign_rhs1 (second
);
1690 op1
= gimple_assign_rhs2 (second
);
1692 /* If jumps are cheap turn some more codes into
1694 else if (BRANCH_COST (optimize_insn_for_speed_p (), false) < 4)
1696 if ((code2
== BIT_AND_EXPR
1697 && TYPE_PRECISION (TREE_TYPE (op0
)) == 1
1698 && TREE_CODE (gimple_assign_rhs2 (second
)) != INTEGER_CST
)
1699 || code2
== TRUTH_AND_EXPR
)
1701 code
= TRUTH_ANDIF_EXPR
;
1702 op0
= gimple_assign_rhs1 (second
);
1703 op1
= gimple_assign_rhs2 (second
);
1705 else if (code2
== BIT_IOR_EXPR
|| code2
== TRUTH_OR_EXPR
)
1707 code
= TRUTH_ORIF_EXPR
;
1708 op0
= gimple_assign_rhs1 (second
);
1709 op1
= gimple_assign_rhs2 (second
);
1715 last2
= last
= get_last_insn ();
1717 extract_true_false_edges_from_block (bb
, &true_edge
, &false_edge
);
1718 set_curr_insn_source_location (gimple_location (stmt
));
1719 set_curr_insn_block (gimple_block (stmt
));
1721 /* These flags have no purpose in RTL land. */
1722 true_edge
->flags
&= ~EDGE_TRUE_VALUE
;
1723 false_edge
->flags
&= ~EDGE_FALSE_VALUE
;
1725 /* We can either have a pure conditional jump with one fallthru edge or
1726 two-way jump that needs to be decomposed into two basic blocks. */
1727 if (false_edge
->dest
== bb
->next_bb
)
1729 jumpif_1 (code
, op0
, op1
, label_rtx_for_bb (true_edge
->dest
),
1730 true_edge
->probability
);
1731 maybe_dump_rtl_for_gimple_stmt (stmt
, last
);
1732 if (true_edge
->goto_locus
)
1734 set_curr_insn_source_location (true_edge
->goto_locus
);
1735 set_curr_insn_block (true_edge
->goto_block
);
1736 true_edge
->goto_locus
= curr_insn_locator ();
1738 true_edge
->goto_block
= NULL
;
1739 false_edge
->flags
|= EDGE_FALLTHRU
;
1740 maybe_cleanup_end_of_block (false_edge
, last
);
1743 if (true_edge
->dest
== bb
->next_bb
)
1745 jumpifnot_1 (code
, op0
, op1
, label_rtx_for_bb (false_edge
->dest
),
1746 false_edge
->probability
);
1747 maybe_dump_rtl_for_gimple_stmt (stmt
, last
);
1748 if (false_edge
->goto_locus
)
1750 set_curr_insn_source_location (false_edge
->goto_locus
);
1751 set_curr_insn_block (false_edge
->goto_block
);
1752 false_edge
->goto_locus
= curr_insn_locator ();
1754 false_edge
->goto_block
= NULL
;
1755 true_edge
->flags
|= EDGE_FALLTHRU
;
1756 maybe_cleanup_end_of_block (true_edge
, last
);
1760 jumpif_1 (code
, op0
, op1
, label_rtx_for_bb (true_edge
->dest
),
1761 true_edge
->probability
);
1762 last
= get_last_insn ();
1763 if (false_edge
->goto_locus
)
1765 set_curr_insn_source_location (false_edge
->goto_locus
);
1766 set_curr_insn_block (false_edge
->goto_block
);
1767 false_edge
->goto_locus
= curr_insn_locator ();
1769 false_edge
->goto_block
= NULL
;
1770 emit_jump (label_rtx_for_bb (false_edge
->dest
));
1773 if (BARRIER_P (BB_END (bb
)))
1774 BB_END (bb
) = PREV_INSN (BB_END (bb
));
1775 update_bb_for_insn (bb
);
1777 new_bb
= create_basic_block (NEXT_INSN (last
), get_last_insn (), bb
);
1778 dest
= false_edge
->dest
;
1779 redirect_edge_succ (false_edge
, new_bb
);
1780 false_edge
->flags
|= EDGE_FALLTHRU
;
1781 new_bb
->count
= false_edge
->count
;
1782 new_bb
->frequency
= EDGE_FREQUENCY (false_edge
);
1783 new_edge
= make_edge (new_bb
, dest
, 0);
1784 new_edge
->probability
= REG_BR_PROB_BASE
;
1785 new_edge
->count
= new_bb
->count
;
1786 if (BARRIER_P (BB_END (new_bb
)))
1787 BB_END (new_bb
) = PREV_INSN (BB_END (new_bb
));
1788 update_bb_for_insn (new_bb
);
1790 maybe_dump_rtl_for_gimple_stmt (stmt
, last2
);
1792 if (true_edge
->goto_locus
)
1794 set_curr_insn_source_location (true_edge
->goto_locus
);
1795 set_curr_insn_block (true_edge
->goto_block
);
1796 true_edge
->goto_locus
= curr_insn_locator ();
1798 true_edge
->goto_block
= NULL
;
1803 /* A subroutine of expand_gimple_stmt_1, expanding one GIMPLE_CALL
1807 expand_call_stmt (gimple stmt
)
1809 tree exp
, decl
, lhs
;
1813 if (gimple_call_internal_p (stmt
))
1815 expand_internal_call (stmt
);
1819 exp
= build_vl_exp (CALL_EXPR
, gimple_call_num_args (stmt
) + 3);
1821 CALL_EXPR_FN (exp
) = gimple_call_fn (stmt
);
1822 decl
= gimple_call_fndecl (stmt
);
1823 builtin_p
= decl
&& DECL_BUILT_IN (decl
);
1825 /* If this is not a builtin function, the function type through which the
1826 call is made may be different from the type of the function. */
1829 = fold_convert (build_pointer_type (gimple_call_fntype (stmt
)),
1830 CALL_EXPR_FN (exp
));
1832 TREE_TYPE (exp
) = gimple_call_return_type (stmt
);
1833 CALL_EXPR_STATIC_CHAIN (exp
) = gimple_call_chain (stmt
);
1835 for (i
= 0; i
< gimple_call_num_args (stmt
); i
++)
1837 tree arg
= gimple_call_arg (stmt
, i
);
1839 /* TER addresses into arguments of builtin functions so we have a
1840 chance to infer more correct alignment information. See PR39954. */
1842 && TREE_CODE (arg
) == SSA_NAME
1843 && (def
= get_gimple_for_ssa_name (arg
))
1844 && gimple_assign_rhs_code (def
) == ADDR_EXPR
)
1845 arg
= gimple_assign_rhs1 (def
);
1846 CALL_EXPR_ARG (exp
, i
) = arg
;
1849 if (gimple_has_side_effects (stmt
))
1850 TREE_SIDE_EFFECTS (exp
) = 1;
1852 if (gimple_call_nothrow_p (stmt
))
1853 TREE_NOTHROW (exp
) = 1;
1855 CALL_EXPR_TAILCALL (exp
) = gimple_call_tail_p (stmt
);
1856 CALL_EXPR_RETURN_SLOT_OPT (exp
) = gimple_call_return_slot_opt_p (stmt
);
1858 && DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
1859 && DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA
)
1860 CALL_ALLOCA_FOR_VAR_P (exp
) = gimple_call_alloca_for_var_p (stmt
);
1862 CALL_FROM_THUNK_P (exp
) = gimple_call_from_thunk_p (stmt
);
1863 CALL_CANNOT_INLINE_P (exp
) = gimple_call_cannot_inline_p (stmt
);
1864 CALL_EXPR_VA_ARG_PACK (exp
) = gimple_call_va_arg_pack_p (stmt
);
1865 SET_EXPR_LOCATION (exp
, gimple_location (stmt
));
1866 TREE_BLOCK (exp
) = gimple_block (stmt
);
1868 /* Ensure RTL is created for debug args. */
1869 if (decl
&& DECL_HAS_DEBUG_ARGS_P (decl
))
1871 VEC(tree
, gc
) **debug_args
= decl_debug_args_lookup (decl
);
1876 for (ix
= 1; VEC_iterate (tree
, *debug_args
, ix
, dtemp
); ix
+= 2)
1878 gcc_assert (TREE_CODE (dtemp
) == DEBUG_EXPR_DECL
);
1879 expand_debug_expr (dtemp
);
1883 lhs
= gimple_call_lhs (stmt
);
1885 expand_assignment (lhs
, exp
, false);
1887 expand_expr_real_1 (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
, NULL
);
1890 /* A subroutine of expand_gimple_stmt, expanding one gimple statement
1891 STMT that doesn't require special handling for outgoing edges. That
1892 is no tailcalls and no GIMPLE_COND. */
1895 expand_gimple_stmt_1 (gimple stmt
)
1899 set_curr_insn_source_location (gimple_location (stmt
));
1900 set_curr_insn_block (gimple_block (stmt
));
1902 switch (gimple_code (stmt
))
1905 op0
= gimple_goto_dest (stmt
);
1906 if (TREE_CODE (op0
) == LABEL_DECL
)
1909 expand_computed_goto (op0
);
1912 expand_label (gimple_label_label (stmt
));
1915 case GIMPLE_PREDICT
:
1921 expand_asm_stmt (stmt
);
1924 expand_call_stmt (stmt
);
1928 op0
= gimple_return_retval (stmt
);
1930 if (op0
&& op0
!= error_mark_node
)
1932 tree result
= DECL_RESULT (current_function_decl
);
1934 /* If we are not returning the current function's RESULT_DECL,
1935 build an assignment to it. */
1938 /* I believe that a function's RESULT_DECL is unique. */
1939 gcc_assert (TREE_CODE (op0
) != RESULT_DECL
);
1941 /* ??? We'd like to use simply expand_assignment here,
1942 but this fails if the value is of BLKmode but the return
1943 decl is a register. expand_return has special handling
1944 for this combination, which eventually should move
1945 to common code. See comments there. Until then, let's
1946 build a modify expression :-/ */
1947 op0
= build2 (MODIFY_EXPR
, TREE_TYPE (result
),
1952 expand_null_return ();
1954 expand_return (op0
);
1959 tree lhs
= gimple_assign_lhs (stmt
);
1961 /* Tree expand used to fiddle with |= and &= of two bitfield
1962 COMPONENT_REFs here. This can't happen with gimple, the LHS
1963 of binary assigns must be a gimple reg. */
1965 if (TREE_CODE (lhs
) != SSA_NAME
1966 || get_gimple_rhs_class (gimple_expr_code (stmt
))
1967 == GIMPLE_SINGLE_RHS
)
1969 tree rhs
= gimple_assign_rhs1 (stmt
);
1970 gcc_assert (get_gimple_rhs_class (gimple_expr_code (stmt
))
1971 == GIMPLE_SINGLE_RHS
);
1972 if (gimple_has_location (stmt
) && CAN_HAVE_LOCATION_P (rhs
))
1973 SET_EXPR_LOCATION (rhs
, gimple_location (stmt
));
1974 expand_assignment (lhs
, rhs
,
1975 gimple_assign_nontemporal_move_p (stmt
));
1980 bool nontemporal
= gimple_assign_nontemporal_move_p (stmt
);
1981 struct separate_ops ops
;
1982 bool promoted
= false;
1984 target
= expand_expr (lhs
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
1985 if (GET_CODE (target
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (target
))
1988 ops
.code
= gimple_assign_rhs_code (stmt
);
1989 ops
.type
= TREE_TYPE (lhs
);
1990 switch (get_gimple_rhs_class (gimple_expr_code (stmt
)))
1992 case GIMPLE_TERNARY_RHS
:
1993 ops
.op2
= gimple_assign_rhs3 (stmt
);
1995 case GIMPLE_BINARY_RHS
:
1996 ops
.op1
= gimple_assign_rhs2 (stmt
);
1998 case GIMPLE_UNARY_RHS
:
1999 ops
.op0
= gimple_assign_rhs1 (stmt
);
2004 ops
.location
= gimple_location (stmt
);
2006 /* If we want to use a nontemporal store, force the value to
2007 register first. If we store into a promoted register,
2008 don't directly expand to target. */
2009 temp
= nontemporal
|| promoted
? NULL_RTX
: target
;
2010 temp
= expand_expr_real_2 (&ops
, temp
, GET_MODE (target
),
2017 int unsignedp
= SUBREG_PROMOTED_UNSIGNED_P (target
);
2018 /* If TEMP is a VOIDmode constant, use convert_modes to make
2019 sure that we properly convert it. */
2020 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
)
2022 temp
= convert_modes (GET_MODE (target
),
2023 TYPE_MODE (ops
.type
),
2025 temp
= convert_modes (GET_MODE (SUBREG_REG (target
)),
2026 GET_MODE (target
), temp
, unsignedp
);
2029 convert_move (SUBREG_REG (target
), temp
, unsignedp
);
2031 else if (nontemporal
&& emit_storent_insn (target
, temp
))
2035 temp
= force_operand (temp
, target
);
2037 emit_move_insn (target
, temp
);
2048 /* Expand one gimple statement STMT and return the last RTL instruction
2049 before any of the newly generated ones.
2051 In addition to generating the necessary RTL instructions this also
2052 sets REG_EH_REGION notes if necessary and sets the current source
2053 location for diagnostics. */
2056 expand_gimple_stmt (gimple stmt
)
2058 location_t saved_location
= input_location
;
2059 rtx last
= get_last_insn ();
2064 /* We need to save and restore the current source location so that errors
2065 discovered during expansion are emitted with the right location. But
2066 it would be better if the diagnostic routines used the source location
2067 embedded in the tree nodes rather than globals. */
2068 if (gimple_has_location (stmt
))
2069 input_location
= gimple_location (stmt
);
2071 expand_gimple_stmt_1 (stmt
);
2073 /* Free any temporaries used to evaluate this statement. */
2076 input_location
= saved_location
;
2078 /* Mark all insns that may trap. */
2079 lp_nr
= lookup_stmt_eh_lp (stmt
);
2083 for (insn
= next_real_insn (last
); insn
;
2084 insn
= next_real_insn (insn
))
2086 if (! find_reg_note (insn
, REG_EH_REGION
, NULL_RTX
)
2087 /* If we want exceptions for non-call insns, any
2088 may_trap_p instruction may throw. */
2089 && GET_CODE (PATTERN (insn
)) != CLOBBER
2090 && GET_CODE (PATTERN (insn
)) != USE
2091 && insn_could_throw_p (insn
))
2092 make_reg_eh_region_note (insn
, 0, lp_nr
);
2099 /* A subroutine of expand_gimple_basic_block. Expand one GIMPLE_CALL
2100 that has CALL_EXPR_TAILCALL set. Returns non-null if we actually
2101 generated a tail call (something that might be denied by the ABI
2102 rules governing the call; see calls.c).
2104 Sets CAN_FALLTHRU if we generated a *conditional* tail call, and
2105 can still reach the rest of BB. The case here is __builtin_sqrt,
2106 where the NaN result goes through the external function (with a
2107 tailcall) and the normal result happens via a sqrt instruction. */
2110 expand_gimple_tailcall (basic_block bb
, gimple stmt
, bool *can_fallthru
)
2118 last2
= last
= expand_gimple_stmt (stmt
);
2120 for (last
= NEXT_INSN (last
); last
; last
= NEXT_INSN (last
))
2121 if (CALL_P (last
) && SIBLING_CALL_P (last
))
2124 maybe_dump_rtl_for_gimple_stmt (stmt
, last2
);
2126 *can_fallthru
= true;
2130 /* ??? Wouldn't it be better to just reset any pending stack adjust?
2131 Any instructions emitted here are about to be deleted. */
2132 do_pending_stack_adjust ();
2134 /* Remove any non-eh, non-abnormal edges that don't go to exit. */
2135 /* ??? I.e. the fallthrough edge. HOWEVER! If there were to be
2136 EH or abnormal edges, we shouldn't have created a tail call in
2137 the first place. So it seems to me we should just be removing
2138 all edges here, or redirecting the existing fallthru edge to
2144 for (ei
= ei_start (bb
->succs
); (e
= ei_safe_edge (ei
)); )
2146 if (!(e
->flags
& (EDGE_ABNORMAL
| EDGE_EH
)))
2148 if (e
->dest
!= EXIT_BLOCK_PTR
)
2150 e
->dest
->count
-= e
->count
;
2151 e
->dest
->frequency
-= EDGE_FREQUENCY (e
);
2152 if (e
->dest
->count
< 0)
2154 if (e
->dest
->frequency
< 0)
2155 e
->dest
->frequency
= 0;
2158 probability
+= e
->probability
;
2165 /* This is somewhat ugly: the call_expr expander often emits instructions
2166 after the sibcall (to perform the function return). These confuse the
2167 find_many_sub_basic_blocks code, so we need to get rid of these. */
2168 last
= NEXT_INSN (last
);
2169 gcc_assert (BARRIER_P (last
));
2171 *can_fallthru
= false;
2172 while (NEXT_INSN (last
))
2174 /* For instance an sqrt builtin expander expands if with
2175 sibcall in the then and label for `else`. */
2176 if (LABEL_P (NEXT_INSN (last
)))
2178 *can_fallthru
= true;
2181 delete_insn (NEXT_INSN (last
));
2184 e
= make_edge (bb
, EXIT_BLOCK_PTR
, EDGE_ABNORMAL
| EDGE_SIBCALL
);
2185 e
->probability
+= probability
;
2188 update_bb_for_insn (bb
);
2190 if (NEXT_INSN (last
))
2192 bb
= create_basic_block (NEXT_INSN (last
), get_last_insn (), bb
);
2195 if (BARRIER_P (last
))
2196 BB_END (bb
) = PREV_INSN (last
);
2199 maybe_dump_rtl_for_gimple_stmt (stmt
, last2
);
2204 /* Return the difference between the floor and the truncated result of
2205 a signed division by OP1 with remainder MOD. */
2207 floor_sdiv_adjust (enum machine_mode mode
, rtx mod
, rtx op1
)
2209 /* (mod != 0 ? (op1 / mod < 0 ? -1 : 0) : 0) */
2210 return gen_rtx_IF_THEN_ELSE
2211 (mode
, gen_rtx_NE (BImode
, mod
, const0_rtx
),
2212 gen_rtx_IF_THEN_ELSE
2213 (mode
, gen_rtx_LT (BImode
,
2214 gen_rtx_DIV (mode
, op1
, mod
),
2216 constm1_rtx
, const0_rtx
),
2220 /* Return the difference between the ceil and the truncated result of
2221 a signed division by OP1 with remainder MOD. */
2223 ceil_sdiv_adjust (enum machine_mode mode
, rtx mod
, rtx op1
)
2225 /* (mod != 0 ? (op1 / mod > 0 ? 1 : 0) : 0) */
2226 return gen_rtx_IF_THEN_ELSE
2227 (mode
, gen_rtx_NE (BImode
, mod
, const0_rtx
),
2228 gen_rtx_IF_THEN_ELSE
2229 (mode
, gen_rtx_GT (BImode
,
2230 gen_rtx_DIV (mode
, op1
, mod
),
2232 const1_rtx
, const0_rtx
),
2236 /* Return the difference between the ceil and the truncated result of
2237 an unsigned division by OP1 with remainder MOD. */
2239 ceil_udiv_adjust (enum machine_mode mode
, rtx mod
, rtx op1 ATTRIBUTE_UNUSED
)
2241 /* (mod != 0 ? 1 : 0) */
2242 return gen_rtx_IF_THEN_ELSE
2243 (mode
, gen_rtx_NE (BImode
, mod
, const0_rtx
),
2244 const1_rtx
, const0_rtx
);
2247 /* Return the difference between the rounded and the truncated result
2248 of a signed division by OP1 with remainder MOD. Halfway cases are
2249 rounded away from zero, rather than to the nearest even number. */
2251 round_sdiv_adjust (enum machine_mode mode
, rtx mod
, rtx op1
)
2253 /* (abs (mod) >= abs (op1) - abs (mod)
2254 ? (op1 / mod > 0 ? 1 : -1)
2256 return gen_rtx_IF_THEN_ELSE
2257 (mode
, gen_rtx_GE (BImode
, gen_rtx_ABS (mode
, mod
),
2258 gen_rtx_MINUS (mode
,
2259 gen_rtx_ABS (mode
, op1
),
2260 gen_rtx_ABS (mode
, mod
))),
2261 gen_rtx_IF_THEN_ELSE
2262 (mode
, gen_rtx_GT (BImode
,
2263 gen_rtx_DIV (mode
, op1
, mod
),
2265 const1_rtx
, constm1_rtx
),
2269 /* Return the difference between the rounded and the truncated result
2270 of a unsigned division by OP1 with remainder MOD. Halfway cases
2271 are rounded away from zero, rather than to the nearest even
2274 round_udiv_adjust (enum machine_mode mode
, rtx mod
, rtx op1
)
2276 /* (mod >= op1 - mod ? 1 : 0) */
2277 return gen_rtx_IF_THEN_ELSE
2278 (mode
, gen_rtx_GE (BImode
, mod
,
2279 gen_rtx_MINUS (mode
, op1
, mod
)),
2280 const1_rtx
, const0_rtx
);
2283 /* Convert X to MODE, that must be Pmode or ptr_mode, without emitting
2287 convert_debug_memory_address (enum machine_mode mode
, rtx x
,
2290 enum machine_mode xmode
= GET_MODE (x
);
2292 #ifndef POINTERS_EXTEND_UNSIGNED
2293 gcc_assert (mode
== Pmode
2294 || mode
== targetm
.addr_space
.address_mode (as
));
2295 gcc_assert (xmode
== mode
|| xmode
== VOIDmode
);
2298 enum machine_mode address_mode
= targetm
.addr_space
.address_mode (as
);
2299 enum machine_mode pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
2301 gcc_assert (mode
== address_mode
|| mode
== pointer_mode
);
2303 if (GET_MODE (x
) == mode
|| GET_MODE (x
) == VOIDmode
)
2306 if (GET_MODE_PRECISION (mode
) < GET_MODE_PRECISION (xmode
))
2307 x
= simplify_gen_subreg (mode
, x
, xmode
,
2308 subreg_lowpart_offset
2310 else if (POINTERS_EXTEND_UNSIGNED
> 0)
2311 x
= gen_rtx_ZERO_EXTEND (mode
, x
);
2312 else if (!POINTERS_EXTEND_UNSIGNED
)
2313 x
= gen_rtx_SIGN_EXTEND (mode
, x
);
2316 switch (GET_CODE (x
))
2319 if ((SUBREG_PROMOTED_VAR_P (x
)
2320 || (REG_P (SUBREG_REG (x
)) && REG_POINTER (SUBREG_REG (x
)))
2321 || (GET_CODE (SUBREG_REG (x
)) == PLUS
2322 && REG_P (XEXP (SUBREG_REG (x
), 0))
2323 && REG_POINTER (XEXP (SUBREG_REG (x
), 0))
2324 && CONST_INT_P (XEXP (SUBREG_REG (x
), 1))))
2325 && GET_MODE (SUBREG_REG (x
)) == mode
)
2326 return SUBREG_REG (x
);
2329 temp
= gen_rtx_LABEL_REF (mode
, XEXP (x
, 0));
2330 LABEL_REF_NONLOCAL_P (temp
) = LABEL_REF_NONLOCAL_P (x
);
2333 temp
= shallow_copy_rtx (x
);
2334 PUT_MODE (temp
, mode
);
2337 temp
= convert_debug_memory_address (mode
, XEXP (x
, 0), as
);
2339 temp
= gen_rtx_CONST (mode
, temp
);
2343 if (CONST_INT_P (XEXP (x
, 1)))
2345 temp
= convert_debug_memory_address (mode
, XEXP (x
, 0), as
);
2347 return gen_rtx_fmt_ee (GET_CODE (x
), mode
, temp
, XEXP (x
, 1));
2353 /* Don't know how to express ptr_extend as operation in debug info. */
2356 #endif /* POINTERS_EXTEND_UNSIGNED */
2361 /* Return an RTX equivalent to the value of the parameter DECL. */
2364 expand_debug_parm_decl (tree decl
)
2366 rtx incoming
= DECL_INCOMING_RTL (decl
);
2369 && GET_MODE (incoming
) != BLKmode
2370 && ((REG_P (incoming
) && HARD_REGISTER_P (incoming
))
2371 || (MEM_P (incoming
)
2372 && REG_P (XEXP (incoming
, 0))
2373 && HARD_REGISTER_P (XEXP (incoming
, 0)))))
2375 rtx rtl
= gen_rtx_ENTRY_VALUE (GET_MODE (incoming
));
2377 #ifdef HAVE_window_save
2378 /* DECL_INCOMING_RTL uses the INCOMING_REGNO of parameter registers.
2379 If the target machine has an explicit window save instruction, the
2380 actual entry value is the corresponding OUTGOING_REGNO instead. */
2381 if (REG_P (incoming
)
2382 && OUTGOING_REGNO (REGNO (incoming
)) != REGNO (incoming
))
2384 = gen_rtx_REG_offset (incoming
, GET_MODE (incoming
),
2385 OUTGOING_REGNO (REGNO (incoming
)), 0);
2386 else if (MEM_P (incoming
))
2388 rtx reg
= XEXP (incoming
, 0);
2389 if (OUTGOING_REGNO (REGNO (reg
)) != REGNO (reg
))
2391 reg
= gen_raw_REG (GET_MODE (reg
), OUTGOING_REGNO (REGNO (reg
)));
2392 incoming
= replace_equiv_address_nv (incoming
, reg
);
2397 ENTRY_VALUE_EXP (rtl
) = incoming
;
2402 && GET_MODE (incoming
) != BLKmode
2403 && !TREE_ADDRESSABLE (decl
)
2405 && (XEXP (incoming
, 0) == virtual_incoming_args_rtx
2406 || (GET_CODE (XEXP (incoming
, 0)) == PLUS
2407 && XEXP (XEXP (incoming
, 0), 0) == virtual_incoming_args_rtx
2408 && CONST_INT_P (XEXP (XEXP (incoming
, 0), 1)))))
2414 /* Return an RTX equivalent to the value of the tree expression EXP. */
2417 expand_debug_expr (tree exp
)
2419 rtx op0
= NULL_RTX
, op1
= NULL_RTX
, op2
= NULL_RTX
;
2420 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (exp
));
2421 enum machine_mode inner_mode
= VOIDmode
;
2422 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (exp
));
2425 switch (TREE_CODE_CLASS (TREE_CODE (exp
)))
2427 case tcc_expression
:
2428 switch (TREE_CODE (exp
))
2432 case WIDEN_MULT_PLUS_EXPR
:
2433 case WIDEN_MULT_MINUS_EXPR
:
2437 case TRUTH_ANDIF_EXPR
:
2438 case TRUTH_ORIF_EXPR
:
2439 case TRUTH_AND_EXPR
:
2441 case TRUTH_XOR_EXPR
:
2444 case TRUTH_NOT_EXPR
:
2453 op2
= expand_debug_expr (TREE_OPERAND (exp
, 2));
2460 case tcc_comparison
:
2461 op1
= expand_debug_expr (TREE_OPERAND (exp
, 1));
2468 inner_mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
2469 op0
= expand_debug_expr (TREE_OPERAND (exp
, 0));
2479 case tcc_exceptional
:
2480 case tcc_declaration
:
2486 switch (TREE_CODE (exp
))
2489 if (!lookup_constant_def (exp
))
2491 if (strlen (TREE_STRING_POINTER (exp
)) + 1
2492 != (size_t) TREE_STRING_LENGTH (exp
))
2494 op0
= gen_rtx_CONST_STRING (Pmode
, TREE_STRING_POINTER (exp
));
2495 op0
= gen_rtx_MEM (BLKmode
, op0
);
2496 set_mem_attributes (op0
, exp
, 0);
2499 /* Fall through... */
2504 op0
= expand_expr (exp
, NULL_RTX
, mode
, EXPAND_INITIALIZER
);
2508 gcc_assert (COMPLEX_MODE_P (mode
));
2509 op0
= expand_debug_expr (TREE_REALPART (exp
));
2510 op1
= expand_debug_expr (TREE_IMAGPART (exp
));
2511 return gen_rtx_CONCAT (mode
, op0
, op1
);
2513 case DEBUG_EXPR_DECL
:
2514 op0
= DECL_RTL_IF_SET (exp
);
2519 op0
= gen_rtx_DEBUG_EXPR (mode
);
2520 DEBUG_EXPR_TREE_DECL (op0
) = exp
;
2521 SET_DECL_RTL (exp
, op0
);
2531 op0
= DECL_RTL_IF_SET (exp
);
2533 /* This decl was probably optimized away. */
2536 if (TREE_CODE (exp
) != VAR_DECL
2537 || DECL_EXTERNAL (exp
)
2538 || !TREE_STATIC (exp
)
2540 || DECL_HARD_REGISTER (exp
)
2541 || DECL_IN_CONSTANT_POOL (exp
)
2542 || mode
== VOIDmode
)
2545 op0
= make_decl_rtl_for_debug (exp
);
2547 || GET_CODE (XEXP (op0
, 0)) != SYMBOL_REF
2548 || SYMBOL_REF_DECL (XEXP (op0
, 0)) != exp
)
2552 op0
= copy_rtx (op0
);
2554 if (GET_MODE (op0
) == BLKmode
2555 /* If op0 is not BLKmode, but BLKmode is, adjust_mode
2556 below would ICE. While it is likely a FE bug,
2557 try to be robust here. See PR43166. */
2559 || (mode
== VOIDmode
&& GET_MODE (op0
) != VOIDmode
))
2561 gcc_assert (MEM_P (op0
));
2562 op0
= adjust_address_nv (op0
, mode
, 0);
2573 inner_mode
= GET_MODE (op0
);
2575 if (mode
== inner_mode
)
2578 if (inner_mode
== VOIDmode
)
2580 if (TREE_CODE (exp
) == SSA_NAME
)
2581 inner_mode
= TYPE_MODE (TREE_TYPE (exp
));
2583 inner_mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
2584 if (mode
== inner_mode
)
2588 if (FLOAT_MODE_P (mode
) && FLOAT_MODE_P (inner_mode
))
2590 if (GET_MODE_BITSIZE (mode
) == GET_MODE_BITSIZE (inner_mode
))
2591 op0
= simplify_gen_subreg (mode
, op0
, inner_mode
, 0);
2592 else if (GET_MODE_BITSIZE (mode
) < GET_MODE_BITSIZE (inner_mode
))
2593 op0
= simplify_gen_unary (FLOAT_TRUNCATE
, mode
, op0
, inner_mode
);
2595 op0
= simplify_gen_unary (FLOAT_EXTEND
, mode
, op0
, inner_mode
);
2597 else if (FLOAT_MODE_P (mode
))
2599 gcc_assert (TREE_CODE (exp
) != SSA_NAME
);
2600 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
, 0))))
2601 op0
= simplify_gen_unary (UNSIGNED_FLOAT
, mode
, op0
, inner_mode
);
2603 op0
= simplify_gen_unary (FLOAT
, mode
, op0
, inner_mode
);
2605 else if (FLOAT_MODE_P (inner_mode
))
2608 op0
= simplify_gen_unary (UNSIGNED_FIX
, mode
, op0
, inner_mode
);
2610 op0
= simplify_gen_unary (FIX
, mode
, op0
, inner_mode
);
2612 else if (CONSTANT_P (op0
)
2613 || GET_MODE_PRECISION (mode
) <= GET_MODE_PRECISION (inner_mode
))
2614 op0
= simplify_gen_subreg (mode
, op0
, inner_mode
,
2615 subreg_lowpart_offset (mode
,
2617 else if (TREE_CODE_CLASS (TREE_CODE (exp
)) == tcc_unary
2618 ? TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
, 0)))
2620 op0
= simplify_gen_unary (ZERO_EXTEND
, mode
, op0
, inner_mode
);
2622 op0
= simplify_gen_unary (SIGN_EXTEND
, mode
, op0
, inner_mode
);
2628 if (!is_gimple_mem_ref_addr (TREE_OPERAND (exp
, 0)))
2630 tree newexp
= fold_binary (MEM_REF
, TREE_TYPE (exp
),
2631 TREE_OPERAND (exp
, 0),
2632 TREE_OPERAND (exp
, 1));
2634 return expand_debug_expr (newexp
);
2638 op0
= expand_debug_expr (TREE_OPERAND (exp
, 0));
2642 if (TREE_CODE (exp
) == MEM_REF
)
2644 if (GET_CODE (op0
) == DEBUG_IMPLICIT_PTR
2645 || (GET_CODE (op0
) == PLUS
2646 && GET_CODE (XEXP (op0
, 0)) == DEBUG_IMPLICIT_PTR
))
2647 /* (mem (debug_implicit_ptr)) might confuse aliasing.
2648 Instead just use get_inner_reference. */
2651 op1
= expand_debug_expr (TREE_OPERAND (exp
, 1));
2652 if (!op1
|| !CONST_INT_P (op1
))
2655 op0
= plus_constant (op0
, INTVAL (op1
));
2658 if (POINTER_TYPE_P (TREE_TYPE (exp
)))
2659 as
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)));
2661 as
= ADDR_SPACE_GENERIC
;
2663 op0
= convert_debug_memory_address (targetm
.addr_space
.address_mode (as
),
2665 if (op0
== NULL_RTX
)
2668 op0
= gen_rtx_MEM (mode
, op0
);
2669 set_mem_attributes (op0
, exp
, 0);
2670 if (TREE_CODE (exp
) == MEM_REF
2671 && !is_gimple_mem_ref_addr (TREE_OPERAND (exp
, 0)))
2672 set_mem_expr (op0
, NULL_TREE
);
2673 set_mem_addr_space (op0
, as
);
2677 case TARGET_MEM_REF
:
2678 if (TREE_CODE (TMR_BASE (exp
)) == ADDR_EXPR
2679 && !DECL_RTL_SET_P (TREE_OPERAND (TMR_BASE (exp
), 0)))
2682 op0
= expand_debug_expr
2683 (tree_mem_ref_addr (build_pointer_type (TREE_TYPE (exp
)), exp
));
2687 if (POINTER_TYPE_P (TREE_TYPE (exp
)))
2688 as
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)));
2690 as
= ADDR_SPACE_GENERIC
;
2692 op0
= convert_debug_memory_address (targetm
.addr_space
.address_mode (as
),
2694 if (op0
== NULL_RTX
)
2697 op0
= gen_rtx_MEM (mode
, op0
);
2699 set_mem_attributes (op0
, exp
, 0);
2700 set_mem_addr_space (op0
, as
);
2706 case ARRAY_RANGE_REF
:
2711 case VIEW_CONVERT_EXPR
:
2713 enum machine_mode mode1
;
2714 HOST_WIDE_INT bitsize
, bitpos
;
2717 tree tem
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
2718 &mode1
, &unsignedp
, &volatilep
, false);
2724 orig_op0
= op0
= expand_debug_expr (tem
);
2731 enum machine_mode addrmode
, offmode
;
2736 op0
= XEXP (op0
, 0);
2737 addrmode
= GET_MODE (op0
);
2738 if (addrmode
== VOIDmode
)
2741 op1
= expand_debug_expr (offset
);
2745 offmode
= GET_MODE (op1
);
2746 if (offmode
== VOIDmode
)
2747 offmode
= TYPE_MODE (TREE_TYPE (offset
));
2749 if (addrmode
!= offmode
)
2750 op1
= simplify_gen_subreg (addrmode
, op1
, offmode
,
2751 subreg_lowpart_offset (addrmode
,
2754 /* Don't use offset_address here, we don't need a
2755 recognizable address, and we don't want to generate
2757 op0
= gen_rtx_MEM (mode
, simplify_gen_binary (PLUS
, addrmode
,
2763 if (mode1
== VOIDmode
)
2765 mode1
= smallest_mode_for_size (bitsize
, MODE_INT
);
2766 if (bitpos
>= BITS_PER_UNIT
)
2768 op0
= adjust_address_nv (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
2769 bitpos
%= BITS_PER_UNIT
;
2771 else if (bitpos
< 0)
2774 = (-bitpos
+ BITS_PER_UNIT
- 1) / BITS_PER_UNIT
;
2775 op0
= adjust_address_nv (op0
, mode1
, units
);
2776 bitpos
+= units
* BITS_PER_UNIT
;
2778 else if (bitpos
== 0 && bitsize
== GET_MODE_BITSIZE (mode
))
2779 op0
= adjust_address_nv (op0
, mode
, 0);
2780 else if (GET_MODE (op0
) != mode1
)
2781 op0
= adjust_address_nv (op0
, mode1
, 0);
2783 op0
= copy_rtx (op0
);
2784 if (op0
== orig_op0
)
2785 op0
= shallow_copy_rtx (op0
);
2786 set_mem_attributes (op0
, exp
, 0);
2789 if (bitpos
== 0 && mode
== GET_MODE (op0
))
2795 if (GET_MODE (op0
) == BLKmode
)
2798 if ((bitpos
% BITS_PER_UNIT
) == 0
2799 && bitsize
== GET_MODE_BITSIZE (mode1
))
2801 enum machine_mode opmode
= GET_MODE (op0
);
2803 if (opmode
== VOIDmode
)
2804 opmode
= TYPE_MODE (TREE_TYPE (tem
));
2806 /* This condition may hold if we're expanding the address
2807 right past the end of an array that turned out not to
2808 be addressable (i.e., the address was only computed in
2809 debug stmts). The gen_subreg below would rightfully
2810 crash, and the address doesn't really exist, so just
2812 if (bitpos
>= GET_MODE_BITSIZE (opmode
))
2815 if ((bitpos
% GET_MODE_BITSIZE (mode
)) == 0)
2816 return simplify_gen_subreg (mode
, op0
, opmode
,
2817 bitpos
/ BITS_PER_UNIT
);
2820 return simplify_gen_ternary (SCALAR_INT_MODE_P (GET_MODE (op0
))
2821 && TYPE_UNSIGNED (TREE_TYPE (exp
))
2823 : ZERO_EXTRACT
, mode
,
2824 GET_MODE (op0
) != VOIDmode
2826 : TYPE_MODE (TREE_TYPE (tem
)),
2827 op0
, GEN_INT (bitsize
), GEN_INT (bitpos
));
2831 return simplify_gen_unary (ABS
, mode
, op0
, mode
);
2834 return simplify_gen_unary (NEG
, mode
, op0
, mode
);
2837 return simplify_gen_unary (NOT
, mode
, op0
, mode
);
2840 return simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
,
2842 ? UNSIGNED_FLOAT
: FLOAT
, mode
, op0
,
2845 case FIX_TRUNC_EXPR
:
2846 return simplify_gen_unary (unsignedp
? UNSIGNED_FIX
: FIX
, mode
, op0
,
2849 case POINTER_PLUS_EXPR
:
2850 /* For the rare target where pointers are not the same size as
2851 size_t, we need to check for mis-matched modes and correct
2854 && GET_MODE (op0
) != VOIDmode
&& GET_MODE (op1
) != VOIDmode
2855 && GET_MODE (op0
) != GET_MODE (op1
))
2857 if (GET_MODE_BITSIZE (GET_MODE (op0
)) < GET_MODE_BITSIZE (GET_MODE (op1
)))
2858 op1
= simplify_gen_unary (TRUNCATE
, GET_MODE (op0
), op1
,
2861 /* We always sign-extend, regardless of the signedness of
2862 the operand, because the operand is always unsigned
2863 here even if the original C expression is signed. */
2864 op1
= simplify_gen_unary (SIGN_EXTEND
, GET_MODE (op0
), op1
,
2869 return simplify_gen_binary (PLUS
, mode
, op0
, op1
);
2872 return simplify_gen_binary (MINUS
, mode
, op0
, op1
);
2875 return simplify_gen_binary (MULT
, mode
, op0
, op1
);
2878 case TRUNC_DIV_EXPR
:
2879 case EXACT_DIV_EXPR
:
2881 return simplify_gen_binary (UDIV
, mode
, op0
, op1
);
2883 return simplify_gen_binary (DIV
, mode
, op0
, op1
);
2885 case TRUNC_MOD_EXPR
:
2886 return simplify_gen_binary (unsignedp
? UMOD
: MOD
, mode
, op0
, op1
);
2888 case FLOOR_DIV_EXPR
:
2890 return simplify_gen_binary (UDIV
, mode
, op0
, op1
);
2893 rtx div
= simplify_gen_binary (DIV
, mode
, op0
, op1
);
2894 rtx mod
= simplify_gen_binary (MOD
, mode
, op0
, op1
);
2895 rtx adj
= floor_sdiv_adjust (mode
, mod
, op1
);
2896 return simplify_gen_binary (PLUS
, mode
, div
, adj
);
2899 case FLOOR_MOD_EXPR
:
2901 return simplify_gen_binary (UMOD
, mode
, op0
, op1
);
2904 rtx mod
= simplify_gen_binary (MOD
, mode
, op0
, op1
);
2905 rtx adj
= floor_sdiv_adjust (mode
, mod
, op1
);
2906 adj
= simplify_gen_unary (NEG
, mode
,
2907 simplify_gen_binary (MULT
, mode
, adj
, op1
),
2909 return simplify_gen_binary (PLUS
, mode
, mod
, adj
);
2915 rtx div
= simplify_gen_binary (UDIV
, mode
, op0
, op1
);
2916 rtx mod
= simplify_gen_binary (UMOD
, mode
, op0
, op1
);
2917 rtx adj
= ceil_udiv_adjust (mode
, mod
, op1
);
2918 return simplify_gen_binary (PLUS
, mode
, div
, adj
);
2922 rtx div
= simplify_gen_binary (DIV
, mode
, op0
, op1
);
2923 rtx mod
= simplify_gen_binary (MOD
, mode
, op0
, op1
);
2924 rtx adj
= ceil_sdiv_adjust (mode
, mod
, op1
);
2925 return simplify_gen_binary (PLUS
, mode
, div
, adj
);
2931 rtx mod
= simplify_gen_binary (UMOD
, mode
, op0
, op1
);
2932 rtx adj
= ceil_udiv_adjust (mode
, mod
, op1
);
2933 adj
= simplify_gen_unary (NEG
, mode
,
2934 simplify_gen_binary (MULT
, mode
, adj
, op1
),
2936 return simplify_gen_binary (PLUS
, mode
, mod
, adj
);
2940 rtx mod
= simplify_gen_binary (MOD
, mode
, op0
, op1
);
2941 rtx adj
= ceil_sdiv_adjust (mode
, mod
, op1
);
2942 adj
= simplify_gen_unary (NEG
, mode
,
2943 simplify_gen_binary (MULT
, mode
, adj
, op1
),
2945 return simplify_gen_binary (PLUS
, mode
, mod
, adj
);
2948 case ROUND_DIV_EXPR
:
2951 rtx div
= simplify_gen_binary (UDIV
, mode
, op0
, op1
);
2952 rtx mod
= simplify_gen_binary (UMOD
, mode
, op0
, op1
);
2953 rtx adj
= round_udiv_adjust (mode
, mod
, op1
);
2954 return simplify_gen_binary (PLUS
, mode
, div
, adj
);
2958 rtx div
= simplify_gen_binary (DIV
, mode
, op0
, op1
);
2959 rtx mod
= simplify_gen_binary (MOD
, mode
, op0
, op1
);
2960 rtx adj
= round_sdiv_adjust (mode
, mod
, op1
);
2961 return simplify_gen_binary (PLUS
, mode
, div
, adj
);
2964 case ROUND_MOD_EXPR
:
2967 rtx mod
= simplify_gen_binary (UMOD
, mode
, op0
, op1
);
2968 rtx adj
= round_udiv_adjust (mode
, mod
, op1
);
2969 adj
= simplify_gen_unary (NEG
, mode
,
2970 simplify_gen_binary (MULT
, mode
, adj
, op1
),
2972 return simplify_gen_binary (PLUS
, mode
, mod
, adj
);
2976 rtx mod
= simplify_gen_binary (MOD
, mode
, op0
, op1
);
2977 rtx adj
= round_sdiv_adjust (mode
, mod
, op1
);
2978 adj
= simplify_gen_unary (NEG
, mode
,
2979 simplify_gen_binary (MULT
, mode
, adj
, op1
),
2981 return simplify_gen_binary (PLUS
, mode
, mod
, adj
);
2985 return simplify_gen_binary (ASHIFT
, mode
, op0
, op1
);
2989 return simplify_gen_binary (LSHIFTRT
, mode
, op0
, op1
);
2991 return simplify_gen_binary (ASHIFTRT
, mode
, op0
, op1
);
2994 return simplify_gen_binary (ROTATE
, mode
, op0
, op1
);
2997 return simplify_gen_binary (ROTATERT
, mode
, op0
, op1
);
3000 return simplify_gen_binary (unsignedp
? UMIN
: SMIN
, mode
, op0
, op1
);
3003 return simplify_gen_binary (unsignedp
? UMAX
: SMAX
, mode
, op0
, op1
);
3006 case TRUTH_AND_EXPR
:
3007 return simplify_gen_binary (AND
, mode
, op0
, op1
);
3011 return simplify_gen_binary (IOR
, mode
, op0
, op1
);
3014 case TRUTH_XOR_EXPR
:
3015 return simplify_gen_binary (XOR
, mode
, op0
, op1
);
3017 case TRUTH_ANDIF_EXPR
:
3018 return gen_rtx_IF_THEN_ELSE (mode
, op0
, op1
, const0_rtx
);
3020 case TRUTH_ORIF_EXPR
:
3021 return gen_rtx_IF_THEN_ELSE (mode
, op0
, const_true_rtx
, op1
);
3023 case TRUTH_NOT_EXPR
:
3024 return simplify_gen_relational (EQ
, mode
, inner_mode
, op0
, const0_rtx
);
3027 return simplify_gen_relational (unsignedp
? LTU
: LT
, mode
, inner_mode
,
3031 return simplify_gen_relational (unsignedp
? LEU
: LE
, mode
, inner_mode
,
3035 return simplify_gen_relational (unsignedp
? GTU
: GT
, mode
, inner_mode
,
3039 return simplify_gen_relational (unsignedp
? GEU
: GE
, mode
, inner_mode
,
3043 return simplify_gen_relational (EQ
, mode
, inner_mode
, op0
, op1
);
3046 return simplify_gen_relational (NE
, mode
, inner_mode
, op0
, op1
);
3048 case UNORDERED_EXPR
:
3049 return simplify_gen_relational (UNORDERED
, mode
, inner_mode
, op0
, op1
);
3052 return simplify_gen_relational (ORDERED
, mode
, inner_mode
, op0
, op1
);
3055 return simplify_gen_relational (UNLT
, mode
, inner_mode
, op0
, op1
);
3058 return simplify_gen_relational (UNLE
, mode
, inner_mode
, op0
, op1
);
3061 return simplify_gen_relational (UNGT
, mode
, inner_mode
, op0
, op1
);
3064 return simplify_gen_relational (UNGE
, mode
, inner_mode
, op0
, op1
);
3067 return simplify_gen_relational (UNEQ
, mode
, inner_mode
, op0
, op1
);
3070 return simplify_gen_relational (LTGT
, mode
, inner_mode
, op0
, op1
);
3073 return gen_rtx_IF_THEN_ELSE (mode
, op0
, op1
, op2
);
3076 gcc_assert (COMPLEX_MODE_P (mode
));
3077 if (GET_MODE (op0
) == VOIDmode
)
3078 op0
= gen_rtx_CONST (GET_MODE_INNER (mode
), op0
);
3079 if (GET_MODE (op1
) == VOIDmode
)
3080 op1
= gen_rtx_CONST (GET_MODE_INNER (mode
), op1
);
3081 return gen_rtx_CONCAT (mode
, op0
, op1
);
3084 if (GET_CODE (op0
) == CONCAT
)
3085 return gen_rtx_CONCAT (mode
, XEXP (op0
, 0),
3086 simplify_gen_unary (NEG
, GET_MODE_INNER (mode
),
3088 GET_MODE_INNER (mode
)));
3091 enum machine_mode imode
= GET_MODE_INNER (mode
);
3096 re
= adjust_address_nv (op0
, imode
, 0);
3097 im
= adjust_address_nv (op0
, imode
, GET_MODE_SIZE (imode
));
3101 enum machine_mode ifmode
= int_mode_for_mode (mode
);
3102 enum machine_mode ihmode
= int_mode_for_mode (imode
);
3104 if (ifmode
== BLKmode
|| ihmode
== BLKmode
)
3106 halfsize
= GEN_INT (GET_MODE_BITSIZE (ihmode
));
3109 re
= gen_rtx_SUBREG (ifmode
, re
, 0);
3110 re
= gen_rtx_ZERO_EXTRACT (ihmode
, re
, halfsize
, const0_rtx
);
3111 if (imode
!= ihmode
)
3112 re
= gen_rtx_SUBREG (imode
, re
, 0);
3113 im
= copy_rtx (op0
);
3115 im
= gen_rtx_SUBREG (ifmode
, im
, 0);
3116 im
= gen_rtx_ZERO_EXTRACT (ihmode
, im
, halfsize
, halfsize
);
3117 if (imode
!= ihmode
)
3118 im
= gen_rtx_SUBREG (imode
, im
, 0);
3120 im
= gen_rtx_NEG (imode
, im
);
3121 return gen_rtx_CONCAT (mode
, re
, im
);
3125 op0
= expand_debug_expr (TREE_OPERAND (exp
, 0));
3126 if (!op0
|| !MEM_P (op0
))
3128 if ((TREE_CODE (TREE_OPERAND (exp
, 0)) == VAR_DECL
3129 || TREE_CODE (TREE_OPERAND (exp
, 0)) == PARM_DECL
3130 || TREE_CODE (TREE_OPERAND (exp
, 0)) == RESULT_DECL
)
3131 && !TREE_ADDRESSABLE (TREE_OPERAND (exp
, 0)))
3132 return gen_rtx_DEBUG_IMPLICIT_PTR (mode
, TREE_OPERAND (exp
, 0));
3134 if (handled_component_p (TREE_OPERAND (exp
, 0)))
3136 HOST_WIDE_INT bitoffset
, bitsize
, maxsize
;
3138 = get_ref_base_and_extent (TREE_OPERAND (exp
, 0),
3139 &bitoffset
, &bitsize
, &maxsize
);
3140 if ((TREE_CODE (decl
) == VAR_DECL
3141 || TREE_CODE (decl
) == PARM_DECL
3142 || TREE_CODE (decl
) == RESULT_DECL
)
3143 && !TREE_ADDRESSABLE (decl
)
3144 && (bitoffset
% BITS_PER_UNIT
) == 0
3146 && bitsize
== maxsize
)
3147 return plus_constant (gen_rtx_DEBUG_IMPLICIT_PTR (mode
, decl
),
3148 bitoffset
/ BITS_PER_UNIT
);
3154 as
= TYPE_ADDR_SPACE (TREE_TYPE (exp
));
3155 op0
= convert_debug_memory_address (mode
, XEXP (op0
, 0), as
);
3160 exp
= build_constructor_from_list (TREE_TYPE (exp
),
3161 TREE_VECTOR_CST_ELTS (exp
));
3165 if (TREE_CODE (TREE_TYPE (exp
)) == VECTOR_TYPE
)
3170 op0
= gen_rtx_CONCATN
3171 (mode
, rtvec_alloc (TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp
))));
3173 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), i
, val
)
3175 op1
= expand_debug_expr (val
);
3178 XVECEXP (op0
, 0, i
) = op1
;
3181 if (i
< TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp
)))
3183 op1
= expand_debug_expr
3184 (build_zero_cst (TREE_TYPE (TREE_TYPE (exp
))));
3189 for (; i
< TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp
)); i
++)
3190 XVECEXP (op0
, 0, i
) = op1
;
3196 goto flag_unsupported
;
3199 /* ??? Maybe handle some builtins? */
3204 gimple g
= get_gimple_for_ssa_name (exp
);
3207 op0
= expand_debug_expr (gimple_assign_rhs_to_tree (g
));
3213 int part
= var_to_partition (SA
.map
, exp
);
3215 if (part
== NO_PARTITION
)
3217 /* If this is a reference to an incoming value of parameter
3218 that is never used in the code or where the incoming
3219 value is never used in the code, use PARM_DECL's
3221 if (SSA_NAME_IS_DEFAULT_DEF (exp
)
3222 && TREE_CODE (SSA_NAME_VAR (exp
)) == PARM_DECL
)
3224 op0
= expand_debug_parm_decl (SSA_NAME_VAR (exp
));
3227 op0
= expand_debug_expr (SSA_NAME_VAR (exp
));
3234 gcc_assert (part
>= 0 && (unsigned)part
< SA
.map
->num_partitions
);
3236 op0
= copy_rtx (SA
.partition_to_pseudo
[part
]);
3244 /* Vector stuff. For most of the codes we don't have rtl codes. */
3245 case REALIGN_LOAD_EXPR
:
3246 case REDUC_MAX_EXPR
:
3247 case REDUC_MIN_EXPR
:
3248 case REDUC_PLUS_EXPR
:
3250 case VEC_EXTRACT_EVEN_EXPR
:
3251 case VEC_EXTRACT_ODD_EXPR
:
3252 case VEC_INTERLEAVE_HIGH_EXPR
:
3253 case VEC_INTERLEAVE_LOW_EXPR
:
3254 case VEC_LSHIFT_EXPR
:
3255 case VEC_PACK_FIX_TRUNC_EXPR
:
3256 case VEC_PACK_SAT_EXPR
:
3257 case VEC_PACK_TRUNC_EXPR
:
3258 case VEC_RSHIFT_EXPR
:
3259 case VEC_UNPACK_FLOAT_HI_EXPR
:
3260 case VEC_UNPACK_FLOAT_LO_EXPR
:
3261 case VEC_UNPACK_HI_EXPR
:
3262 case VEC_UNPACK_LO_EXPR
:
3263 case VEC_WIDEN_MULT_HI_EXPR
:
3264 case VEC_WIDEN_MULT_LO_EXPR
:
3268 case ADDR_SPACE_CONVERT_EXPR
:
3269 case FIXED_CONVERT_EXPR
:
3271 case WITH_SIZE_EXPR
:
3275 if (SCALAR_INT_MODE_P (GET_MODE (op0
))
3276 && SCALAR_INT_MODE_P (mode
))
3279 = simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
,
3281 ? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op0
,
3284 = simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
,
3286 ? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op1
,
3288 op0
= simplify_gen_binary (MULT
, mode
, op0
, op1
);
3289 return simplify_gen_binary (PLUS
, mode
, op0
, op2
);
3293 case WIDEN_MULT_EXPR
:
3294 case WIDEN_MULT_PLUS_EXPR
:
3295 case WIDEN_MULT_MINUS_EXPR
:
3296 if (SCALAR_INT_MODE_P (GET_MODE (op0
))
3297 && SCALAR_INT_MODE_P (mode
))
3299 inner_mode
= GET_MODE (op0
);
3300 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
, 0))))
3301 op0
= simplify_gen_unary (ZERO_EXTEND
, mode
, op0
, inner_mode
);
3303 op0
= simplify_gen_unary (SIGN_EXTEND
, mode
, op0
, inner_mode
);
3304 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
, 1))))
3305 op1
= simplify_gen_unary (ZERO_EXTEND
, mode
, op1
, inner_mode
);
3307 op1
= simplify_gen_unary (SIGN_EXTEND
, mode
, op1
, inner_mode
);
3308 op0
= simplify_gen_binary (MULT
, mode
, op0
, op1
);
3309 if (TREE_CODE (exp
) == WIDEN_MULT_EXPR
)
3311 else if (TREE_CODE (exp
) == WIDEN_MULT_PLUS_EXPR
)
3312 return simplify_gen_binary (PLUS
, mode
, op0
, op2
);
3314 return simplify_gen_binary (MINUS
, mode
, op2
, op0
);
3318 case WIDEN_SUM_EXPR
:
3319 if (SCALAR_INT_MODE_P (GET_MODE (op0
))
3320 && SCALAR_INT_MODE_P (mode
))
3323 = simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
,
3325 ? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op0
,
3327 return simplify_gen_binary (PLUS
, mode
, op0
, op1
);
3332 return simplify_gen_ternary (FMA
, mode
, inner_mode
, op0
, op1
, op2
);
3336 #ifdef ENABLE_CHECKING
3345 /* Return an RTX equivalent to the source bind value of the tree expression
3349 expand_debug_source_expr (tree exp
)
3352 enum machine_mode mode
= VOIDmode
, inner_mode
;
3354 switch (TREE_CODE (exp
))
3358 mode
= DECL_MODE (exp
);
3359 op0
= expand_debug_parm_decl (exp
);
3362 /* See if this isn't an argument that has been completely
3364 if (!DECL_RTL_SET_P (exp
)
3365 && !DECL_INCOMING_RTL (exp
)
3366 && DECL_ABSTRACT_ORIGIN (current_function_decl
))
3369 if (DECL_ABSTRACT_ORIGIN (exp
))
3370 aexp
= DECL_ABSTRACT_ORIGIN (exp
);
3371 if (DECL_CONTEXT (aexp
)
3372 == DECL_ABSTRACT_ORIGIN (current_function_decl
))
3374 VEC(tree
, gc
) **debug_args
;
3377 #ifdef ENABLE_CHECKING
3379 for (parm
= DECL_ARGUMENTS (current_function_decl
);
3380 parm
; parm
= DECL_CHAIN (parm
))
3381 gcc_assert (parm
!= exp
3382 && DECL_ABSTRACT_ORIGIN (parm
) != aexp
);
3384 debug_args
= decl_debug_args_lookup (current_function_decl
);
3385 if (debug_args
!= NULL
)
3387 for (ix
= 0; VEC_iterate (tree
, *debug_args
, ix
, ddecl
);
3390 return gen_rtx_DEBUG_PARAMETER_REF (mode
, aexp
);
3400 if (op0
== NULL_RTX
)
3403 inner_mode
= GET_MODE (op0
);
3404 if (mode
== inner_mode
)
3407 if (FLOAT_MODE_P (mode
) && FLOAT_MODE_P (inner_mode
))
3409 if (GET_MODE_BITSIZE (mode
) == GET_MODE_BITSIZE (inner_mode
))
3410 op0
= simplify_gen_subreg (mode
, op0
, inner_mode
, 0);
3411 else if (GET_MODE_BITSIZE (mode
) < GET_MODE_BITSIZE (inner_mode
))
3412 op0
= simplify_gen_unary (FLOAT_TRUNCATE
, mode
, op0
, inner_mode
);
3414 op0
= simplify_gen_unary (FLOAT_EXTEND
, mode
, op0
, inner_mode
);
3416 else if (FLOAT_MODE_P (mode
))
3418 else if (FLOAT_MODE_P (inner_mode
))
3420 if (TYPE_UNSIGNED (TREE_TYPE (exp
)))
3421 op0
= simplify_gen_unary (UNSIGNED_FIX
, mode
, op0
, inner_mode
);
3423 op0
= simplify_gen_unary (FIX
, mode
, op0
, inner_mode
);
3425 else if (CONSTANT_P (op0
)
3426 || GET_MODE_BITSIZE (mode
) <= GET_MODE_BITSIZE (inner_mode
))
3427 op0
= simplify_gen_subreg (mode
, op0
, inner_mode
,
3428 subreg_lowpart_offset (mode
, inner_mode
));
3429 else if (TYPE_UNSIGNED (TREE_TYPE (exp
)))
3430 op0
= simplify_gen_unary (ZERO_EXTEND
, mode
, op0
, inner_mode
);
3432 op0
= simplify_gen_unary (SIGN_EXTEND
, mode
, op0
, inner_mode
);
3437 /* Expand the _LOCs in debug insns. We run this after expanding all
3438 regular insns, so that any variables referenced in the function
3439 will have their DECL_RTLs set. */
3442 expand_debug_locations (void)
3445 rtx last
= get_last_insn ();
3446 int save_strict_alias
= flag_strict_aliasing
;
3448 /* New alias sets while setting up memory attributes cause
3449 -fcompare-debug failures, even though it doesn't bring about any
3451 flag_strict_aliasing
= 0;
3453 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3454 if (DEBUG_INSN_P (insn
))
3456 tree value
= (tree
)INSN_VAR_LOCATION_LOC (insn
);
3458 enum machine_mode mode
;
3460 if (value
== NULL_TREE
)
3464 if (INSN_VAR_LOCATION_STATUS (insn
)
3465 == VAR_INIT_STATUS_UNINITIALIZED
)
3466 val
= expand_debug_source_expr (value
);
3468 val
= expand_debug_expr (value
);
3469 gcc_assert (last
== get_last_insn ());
3473 val
= gen_rtx_UNKNOWN_VAR_LOC ();
3476 mode
= GET_MODE (INSN_VAR_LOCATION (insn
));
3478 gcc_assert (mode
== GET_MODE (val
)
3479 || (GET_MODE (val
) == VOIDmode
3480 && (CONST_INT_P (val
)
3481 || GET_CODE (val
) == CONST_FIXED
3482 || GET_CODE (val
) == CONST_DOUBLE
3483 || GET_CODE (val
) == LABEL_REF
)));
3486 INSN_VAR_LOCATION_LOC (insn
) = val
;
3489 flag_strict_aliasing
= save_strict_alias
;
3492 /* Expand basic block BB from GIMPLE trees to RTL. */
3495 expand_gimple_basic_block (basic_block bb
)
3497 gimple_stmt_iterator gsi
;
3506 fprintf (dump_file
, "\n;; Generating RTL for gimple basic block %d\n",
3509 /* Note that since we are now transitioning from GIMPLE to RTL, we
3510 cannot use the gsi_*_bb() routines because they expect the basic
3511 block to be in GIMPLE, instead of RTL. Therefore, we need to
3512 access the BB sequence directly. */
3513 stmts
= bb_seq (bb
);
3514 bb
->il
.gimple
= NULL
;
3515 rtl_profile_for_bb (bb
);
3516 init_rtl_bb_info (bb
);
3517 bb
->flags
|= BB_RTL
;
3519 /* Remove the RETURN_EXPR if we may fall though to the exit
3521 gsi
= gsi_last (stmts
);
3522 if (!gsi_end_p (gsi
)
3523 && gimple_code (gsi_stmt (gsi
)) == GIMPLE_RETURN
)
3525 gimple ret_stmt
= gsi_stmt (gsi
);
3527 gcc_assert (single_succ_p (bb
));
3528 gcc_assert (single_succ (bb
) == EXIT_BLOCK_PTR
);
3530 if (bb
->next_bb
== EXIT_BLOCK_PTR
3531 && !gimple_return_retval (ret_stmt
))
3533 gsi_remove (&gsi
, false);
3534 single_succ_edge (bb
)->flags
|= EDGE_FALLTHRU
;
3538 gsi
= gsi_start (stmts
);
3539 if (!gsi_end_p (gsi
))
3541 stmt
= gsi_stmt (gsi
);
3542 if (gimple_code (stmt
) != GIMPLE_LABEL
)
3546 elt
= pointer_map_contains (lab_rtx_for_bb
, bb
);
3550 last
= get_last_insn ();
3554 expand_gimple_stmt (stmt
);
3559 emit_label ((rtx
) *elt
);
3561 /* Java emits line number notes in the top of labels.
3562 ??? Make this go away once line number notes are obsoleted. */
3563 BB_HEAD (bb
) = NEXT_INSN (last
);
3564 if (NOTE_P (BB_HEAD (bb
)))
3565 BB_HEAD (bb
) = NEXT_INSN (BB_HEAD (bb
));
3566 note
= emit_note_after (NOTE_INSN_BASIC_BLOCK
, BB_HEAD (bb
));
3568 maybe_dump_rtl_for_gimple_stmt (stmt
, last
);
3571 note
= BB_HEAD (bb
) = emit_note (NOTE_INSN_BASIC_BLOCK
);
3573 NOTE_BASIC_BLOCK (note
) = bb
;
3575 for (; !gsi_end_p (gsi
); gsi_next (&gsi
))
3579 stmt
= gsi_stmt (gsi
);
3581 /* If this statement is a non-debug one, and we generate debug
3582 insns, then this one might be the last real use of a TERed
3583 SSA_NAME, but where there are still some debug uses further
3584 down. Expanding the current SSA name in such further debug
3585 uses by their RHS might lead to wrong debug info, as coalescing
3586 might make the operands of such RHS be placed into the same
3587 pseudo as something else. Like so:
3588 a_1 = a_0 + 1; // Assume a_1 is TERed and a_0 is dead
3592 As a_0 and a_2 don't overlap in lifetime, assume they are coalesced.
3593 If we now would expand a_1 by it's RHS (a_0 + 1) in the debug use,
3594 the write to a_2 would actually have clobbered the place which
3597 So, instead of that, we recognize the situation, and generate
3598 debug temporaries at the last real use of TERed SSA names:
3605 if (MAY_HAVE_DEBUG_INSNS
3607 && !is_gimple_debug (stmt
))
3613 location_t sloc
= get_curr_insn_source_location ();
3614 tree sblock
= get_curr_insn_block ();
3616 /* Look for SSA names that have their last use here (TERed
3617 names always have only one real use). */
3618 FOR_EACH_SSA_TREE_OPERAND (op
, stmt
, iter
, SSA_OP_USE
)
3619 if ((def
= get_gimple_for_ssa_name (op
)))
3621 imm_use_iterator imm_iter
;
3622 use_operand_p use_p
;
3623 bool have_debug_uses
= false;
3625 FOR_EACH_IMM_USE_FAST (use_p
, imm_iter
, op
)
3627 if (gimple_debug_bind_p (USE_STMT (use_p
)))
3629 have_debug_uses
= true;
3634 if (have_debug_uses
)
3636 /* OP is a TERed SSA name, with DEF it's defining
3637 statement, and where OP is used in further debug
3638 instructions. Generate a debug temporary, and
3639 replace all uses of OP in debug insns with that
3642 tree value
= gimple_assign_rhs_to_tree (def
);
3643 tree vexpr
= make_node (DEBUG_EXPR_DECL
);
3645 enum machine_mode mode
;
3647 set_curr_insn_source_location (gimple_location (def
));
3648 set_curr_insn_block (gimple_block (def
));
3650 DECL_ARTIFICIAL (vexpr
) = 1;
3651 TREE_TYPE (vexpr
) = TREE_TYPE (value
);
3653 mode
= DECL_MODE (value
);
3655 mode
= TYPE_MODE (TREE_TYPE (value
));
3656 DECL_MODE (vexpr
) = mode
;
3658 val
= gen_rtx_VAR_LOCATION
3659 (mode
, vexpr
, (rtx
)value
, VAR_INIT_STATUS_INITIALIZED
);
3661 emit_debug_insn (val
);
3663 FOR_EACH_IMM_USE_STMT (debugstmt
, imm_iter
, op
)
3665 if (!gimple_debug_bind_p (debugstmt
))
3668 FOR_EACH_IMM_USE_ON_STMT (use_p
, imm_iter
)
3669 SET_USE (use_p
, vexpr
);
3671 update_stmt (debugstmt
);
3675 set_curr_insn_source_location (sloc
);
3676 set_curr_insn_block (sblock
);
3679 currently_expanding_gimple_stmt
= stmt
;
3681 /* Expand this statement, then evaluate the resulting RTL and
3682 fixup the CFG accordingly. */
3683 if (gimple_code (stmt
) == GIMPLE_COND
)
3685 new_bb
= expand_gimple_cond (bb
, stmt
);
3689 else if (gimple_debug_bind_p (stmt
))
3691 location_t sloc
= get_curr_insn_source_location ();
3692 tree sblock
= get_curr_insn_block ();
3693 gimple_stmt_iterator nsi
= gsi
;
3697 tree var
= gimple_debug_bind_get_var (stmt
);
3700 enum machine_mode mode
;
3702 if (gimple_debug_bind_has_value_p (stmt
))
3703 value
= gimple_debug_bind_get_value (stmt
);
3707 last
= get_last_insn ();
3709 set_curr_insn_source_location (gimple_location (stmt
));
3710 set_curr_insn_block (gimple_block (stmt
));
3713 mode
= DECL_MODE (var
);
3715 mode
= TYPE_MODE (TREE_TYPE (var
));
3717 val
= gen_rtx_VAR_LOCATION
3718 (mode
, var
, (rtx
)value
, VAR_INIT_STATUS_INITIALIZED
);
3720 emit_debug_insn (val
);
3722 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
3724 /* We can't dump the insn with a TREE where an RTX
3726 PAT_VAR_LOCATION_LOC (val
) = const0_rtx
;
3727 maybe_dump_rtl_for_gimple_stmt (stmt
, last
);
3728 PAT_VAR_LOCATION_LOC (val
) = (rtx
)value
;
3731 /* In order not to generate too many debug temporaries,
3732 we delink all uses of debug statements we already expanded.
3733 Therefore debug statements between definition and real
3734 use of TERed SSA names will continue to use the SSA name,
3735 and not be replaced with debug temps. */
3736 delink_stmt_imm_use (stmt
);
3740 if (gsi_end_p (nsi
))
3742 stmt
= gsi_stmt (nsi
);
3743 if (!gimple_debug_bind_p (stmt
))
3747 set_curr_insn_source_location (sloc
);
3748 set_curr_insn_block (sblock
);
3750 else if (gimple_debug_source_bind_p (stmt
))
3752 location_t sloc
= get_curr_insn_source_location ();
3753 tree sblock
= get_curr_insn_block ();
3754 tree var
= gimple_debug_source_bind_get_var (stmt
);
3755 tree value
= gimple_debug_source_bind_get_value (stmt
);
3757 enum machine_mode mode
;
3759 last
= get_last_insn ();
3761 set_curr_insn_source_location (gimple_location (stmt
));
3762 set_curr_insn_block (gimple_block (stmt
));
3764 mode
= DECL_MODE (var
);
3766 val
= gen_rtx_VAR_LOCATION (mode
, var
, (rtx
)value
,
3767 VAR_INIT_STATUS_UNINITIALIZED
);
3769 emit_debug_insn (val
);
3771 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
3773 /* We can't dump the insn with a TREE where an RTX
3775 PAT_VAR_LOCATION_LOC (val
) = const0_rtx
;
3776 maybe_dump_rtl_for_gimple_stmt (stmt
, last
);
3777 PAT_VAR_LOCATION_LOC (val
) = (rtx
)value
;
3780 set_curr_insn_source_location (sloc
);
3781 set_curr_insn_block (sblock
);
3785 if (is_gimple_call (stmt
) && gimple_call_tail_p (stmt
))
3788 new_bb
= expand_gimple_tailcall (bb
, stmt
, &can_fallthru
);
3799 def_operand_p def_p
;
3800 def_p
= SINGLE_SSA_DEF_OPERAND (stmt
, SSA_OP_DEF
);
3804 /* Ignore this stmt if it is in the list of
3805 replaceable expressions. */
3807 && bitmap_bit_p (SA
.values
,
3808 SSA_NAME_VERSION (DEF_FROM_PTR (def_p
))))
3811 last
= expand_gimple_stmt (stmt
);
3812 maybe_dump_rtl_for_gimple_stmt (stmt
, last
);
3817 currently_expanding_gimple_stmt
= NULL
;
3819 /* Expand implicit goto and convert goto_locus. */
3820 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
3822 if (e
->goto_locus
&& e
->goto_block
)
3824 set_curr_insn_source_location (e
->goto_locus
);
3825 set_curr_insn_block (e
->goto_block
);
3826 e
->goto_locus
= curr_insn_locator ();
3828 e
->goto_block
= NULL
;
3829 if ((e
->flags
& EDGE_FALLTHRU
) && e
->dest
!= bb
->next_bb
)
3831 emit_jump (label_rtx_for_bb (e
->dest
));
3832 e
->flags
&= ~EDGE_FALLTHRU
;
3836 /* Expanded RTL can create a jump in the last instruction of block.
3837 This later might be assumed to be a jump to successor and break edge insertion.
3838 We need to insert dummy move to prevent this. PR41440. */
3839 if (single_succ_p (bb
)
3840 && (single_succ_edge (bb
)->flags
& EDGE_FALLTHRU
)
3841 && (last
= get_last_insn ())
3844 rtx dummy
= gen_reg_rtx (SImode
);
3845 emit_insn_after_noloc (gen_move_insn (dummy
, dummy
), last
, NULL
);
3848 do_pending_stack_adjust ();
3850 /* Find the block tail. The last insn in the block is the insn
3851 before a barrier and/or table jump insn. */
3852 last
= get_last_insn ();
3853 if (BARRIER_P (last
))
3854 last
= PREV_INSN (last
);
3855 if (JUMP_TABLE_DATA_P (last
))
3856 last
= PREV_INSN (PREV_INSN (last
));
3859 update_bb_for_insn (bb
);
3865 /* Create a basic block for initialization code. */
3868 construct_init_block (void)
3870 basic_block init_block
, first_block
;
3874 /* Multiple entry points not supported yet. */
3875 gcc_assert (EDGE_COUNT (ENTRY_BLOCK_PTR
->succs
) == 1);
3876 init_rtl_bb_info (ENTRY_BLOCK_PTR
);
3877 init_rtl_bb_info (EXIT_BLOCK_PTR
);
3878 ENTRY_BLOCK_PTR
->flags
|= BB_RTL
;
3879 EXIT_BLOCK_PTR
->flags
|= BB_RTL
;
3881 e
= EDGE_SUCC (ENTRY_BLOCK_PTR
, 0);
3883 /* When entry edge points to first basic block, we don't need jump,
3884 otherwise we have to jump into proper target. */
3885 if (e
&& e
->dest
!= ENTRY_BLOCK_PTR
->next_bb
)
3887 tree label
= gimple_block_label (e
->dest
);
3889 emit_jump (label_rtx (label
));
3893 flags
= EDGE_FALLTHRU
;
3895 init_block
= create_basic_block (NEXT_INSN (get_insns ()),
3898 init_block
->frequency
= ENTRY_BLOCK_PTR
->frequency
;
3899 init_block
->count
= ENTRY_BLOCK_PTR
->count
;
3902 first_block
= e
->dest
;
3903 redirect_edge_succ (e
, init_block
);
3904 e
= make_edge (init_block
, first_block
, flags
);
3907 e
= make_edge (init_block
, EXIT_BLOCK_PTR
, EDGE_FALLTHRU
);
3908 e
->probability
= REG_BR_PROB_BASE
;
3909 e
->count
= ENTRY_BLOCK_PTR
->count
;
3911 update_bb_for_insn (init_block
);
3915 /* For each lexical block, set BLOCK_NUMBER to the depth at which it is
3916 found in the block tree. */
3919 set_block_levels (tree block
, int level
)
3923 BLOCK_NUMBER (block
) = level
;
3924 set_block_levels (BLOCK_SUBBLOCKS (block
), level
+ 1);
3925 block
= BLOCK_CHAIN (block
);
3929 /* Create a block containing landing pads and similar stuff. */
3932 construct_exit_block (void)
3934 rtx head
= get_last_insn ();
3936 basic_block exit_block
;
3940 rtx orig_end
= BB_END (EXIT_BLOCK_PTR
->prev_bb
);
3942 rtl_profile_for_bb (EXIT_BLOCK_PTR
);
3944 /* Make sure the locus is set to the end of the function, so that
3945 epilogue line numbers and warnings are set properly. */
3946 if (cfun
->function_end_locus
!= UNKNOWN_LOCATION
)
3947 input_location
= cfun
->function_end_locus
;
3949 /* The following insns belong to the top scope. */
3950 set_curr_insn_block (DECL_INITIAL (current_function_decl
));
3952 /* Generate rtl for function exit. */
3953 expand_function_end ();
3955 end
= get_last_insn ();
3958 /* While emitting the function end we could move end of the last basic block.
3960 BB_END (EXIT_BLOCK_PTR
->prev_bb
) = orig_end
;
3961 while (NEXT_INSN (head
) && NOTE_P (NEXT_INSN (head
)))
3962 head
= NEXT_INSN (head
);
3963 exit_block
= create_basic_block (NEXT_INSN (head
), end
,
3964 EXIT_BLOCK_PTR
->prev_bb
);
3965 exit_block
->frequency
= EXIT_BLOCK_PTR
->frequency
;
3966 exit_block
->count
= EXIT_BLOCK_PTR
->count
;
3969 while (ix
< EDGE_COUNT (EXIT_BLOCK_PTR
->preds
))
3971 e
= EDGE_PRED (EXIT_BLOCK_PTR
, ix
);
3972 if (!(e
->flags
& EDGE_ABNORMAL
))
3973 redirect_edge_succ (e
, exit_block
);
3978 e
= make_edge (exit_block
, EXIT_BLOCK_PTR
, EDGE_FALLTHRU
);
3979 e
->probability
= REG_BR_PROB_BASE
;
3980 e
->count
= EXIT_BLOCK_PTR
->count
;
3981 FOR_EACH_EDGE (e2
, ei
, EXIT_BLOCK_PTR
->preds
)
3984 e
->count
-= e2
->count
;
3985 exit_block
->count
-= e2
->count
;
3986 exit_block
->frequency
-= EDGE_FREQUENCY (e2
);
3990 if (exit_block
->count
< 0)
3991 exit_block
->count
= 0;
3992 if (exit_block
->frequency
< 0)
3993 exit_block
->frequency
= 0;
3994 update_bb_for_insn (exit_block
);
3997 /* Helper function for discover_nonconstant_array_refs.
3998 Look for ARRAY_REF nodes with non-constant indexes and mark them
4002 discover_nonconstant_array_refs_r (tree
* tp
, int *walk_subtrees
,
4003 void *data ATTRIBUTE_UNUSED
)
4007 if (IS_TYPE_OR_DECL_P (t
))
4009 else if (TREE_CODE (t
) == ARRAY_REF
|| TREE_CODE (t
) == ARRAY_RANGE_REF
)
4011 while (((TREE_CODE (t
) == ARRAY_REF
|| TREE_CODE (t
) == ARRAY_RANGE_REF
)
4012 && is_gimple_min_invariant (TREE_OPERAND (t
, 1))
4013 && (!TREE_OPERAND (t
, 2)
4014 || is_gimple_min_invariant (TREE_OPERAND (t
, 2))))
4015 || (TREE_CODE (t
) == COMPONENT_REF
4016 && (!TREE_OPERAND (t
,2)
4017 || is_gimple_min_invariant (TREE_OPERAND (t
, 2))))
4018 || TREE_CODE (t
) == BIT_FIELD_REF
4019 || TREE_CODE (t
) == REALPART_EXPR
4020 || TREE_CODE (t
) == IMAGPART_EXPR
4021 || TREE_CODE (t
) == VIEW_CONVERT_EXPR
4022 || CONVERT_EXPR_P (t
))
4023 t
= TREE_OPERAND (t
, 0);
4025 if (TREE_CODE (t
) == ARRAY_REF
|| TREE_CODE (t
) == ARRAY_RANGE_REF
)
4027 t
= get_base_address (t
);
4029 && DECL_MODE (t
) != BLKmode
)
4030 TREE_ADDRESSABLE (t
) = 1;
4039 /* RTL expansion is not able to compile array references with variable
4040 offsets for arrays stored in single register. Discover such
4041 expressions and mark variables as addressable to avoid this
4045 discover_nonconstant_array_refs (void)
4048 gimple_stmt_iterator gsi
;
4051 for (gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
4053 gimple stmt
= gsi_stmt (gsi
);
4054 if (!is_gimple_debug (stmt
))
4055 walk_gimple_op (stmt
, discover_nonconstant_array_refs_r
, NULL
);
4059 /* This function sets crtl->args.internal_arg_pointer to a virtual
4060 register if DRAP is needed. Local register allocator will replace
4061 virtual_incoming_args_rtx with the virtual register. */
4064 expand_stack_alignment (void)
4067 unsigned int preferred_stack_boundary
;
4069 if (! SUPPORTS_STACK_ALIGNMENT
)
4072 if (cfun
->calls_alloca
4073 || cfun
->has_nonlocal_label
4074 || crtl
->has_nonlocal_goto
)
4075 crtl
->need_drap
= true;
4077 /* Call update_stack_boundary here again to update incoming stack
4078 boundary. It may set incoming stack alignment to a different
4079 value after RTL expansion. TARGET_FUNCTION_OK_FOR_SIBCALL may
4080 use the minimum incoming stack alignment to check if it is OK
4081 to perform sibcall optimization since sibcall optimization will
4082 only align the outgoing stack to incoming stack boundary. */
4083 if (targetm
.calls
.update_stack_boundary
)
4084 targetm
.calls
.update_stack_boundary ();
4086 /* The incoming stack frame has to be aligned at least at
4087 parm_stack_boundary. */
4088 gcc_assert (crtl
->parm_stack_boundary
<= INCOMING_STACK_BOUNDARY
);
4090 /* Update crtl->stack_alignment_estimated and use it later to align
4091 stack. We check PREFERRED_STACK_BOUNDARY if there may be non-call
4092 exceptions since callgraph doesn't collect incoming stack alignment
4094 if (cfun
->can_throw_non_call_exceptions
4095 && PREFERRED_STACK_BOUNDARY
> crtl
->preferred_stack_boundary
)
4096 preferred_stack_boundary
= PREFERRED_STACK_BOUNDARY
;
4098 preferred_stack_boundary
= crtl
->preferred_stack_boundary
;
4099 if (preferred_stack_boundary
> crtl
->stack_alignment_estimated
)
4100 crtl
->stack_alignment_estimated
= preferred_stack_boundary
;
4101 if (preferred_stack_boundary
> crtl
->stack_alignment_needed
)
4102 crtl
->stack_alignment_needed
= preferred_stack_boundary
;
4104 gcc_assert (crtl
->stack_alignment_needed
4105 <= crtl
->stack_alignment_estimated
);
4107 crtl
->stack_realign_needed
4108 = INCOMING_STACK_BOUNDARY
< crtl
->stack_alignment_estimated
;
4109 crtl
->stack_realign_tried
= crtl
->stack_realign_needed
;
4111 crtl
->stack_realign_processed
= true;
4113 /* Target has to redefine TARGET_GET_DRAP_RTX to support stack
4115 gcc_assert (targetm
.calls
.get_drap_rtx
!= NULL
);
4116 drap_rtx
= targetm
.calls
.get_drap_rtx ();
4118 /* stack_realign_drap and drap_rtx must match. */
4119 gcc_assert ((stack_realign_drap
!= 0) == (drap_rtx
!= NULL
));
4121 /* Do nothing if NULL is returned, which means DRAP is not needed. */
4122 if (NULL
!= drap_rtx
)
4124 crtl
->args
.internal_arg_pointer
= drap_rtx
;
4126 /* Call fixup_tail_calls to clean up REG_EQUIV note if DRAP is
4128 fixup_tail_calls ();
4132 /* Translate the intermediate representation contained in the CFG
4133 from GIMPLE trees to RTL.
4135 We do conversion per basic block and preserve/update the tree CFG.
4136 This implies we have to do some magic as the CFG can simultaneously
4137 consist of basic blocks containing RTL and GIMPLE trees. This can
4138 confuse the CFG hooks, so be careful to not manipulate CFG during
4142 gimple_expand_cfg (void)
4144 basic_block bb
, init_block
;
4151 timevar_push (TV_OUT_OF_SSA
);
4152 rewrite_out_of_ssa (&SA
);
4153 timevar_pop (TV_OUT_OF_SSA
);
4154 SA
.partition_to_pseudo
= (rtx
*)xcalloc (SA
.map
->num_partitions
,
4157 /* Some backends want to know that we are expanding to RTL. */
4158 currently_expanding_to_rtl
= 1;
4160 rtl_profile_for_bb (ENTRY_BLOCK_PTR
);
4162 insn_locators_alloc ();
4163 if (!DECL_IS_BUILTIN (current_function_decl
))
4165 /* Eventually, all FEs should explicitly set function_start_locus. */
4166 if (cfun
->function_start_locus
== UNKNOWN_LOCATION
)
4167 set_curr_insn_source_location
4168 (DECL_SOURCE_LOCATION (current_function_decl
));
4170 set_curr_insn_source_location (cfun
->function_start_locus
);
4173 set_curr_insn_source_location (UNKNOWN_LOCATION
);
4174 set_curr_insn_block (DECL_INITIAL (current_function_decl
));
4175 prologue_locator
= curr_insn_locator ();
4177 #ifdef INSN_SCHEDULING
4178 init_sched_attrs ();
4181 /* Make sure first insn is a note even if we don't want linenums.
4182 This makes sure the first insn will never be deleted.
4183 Also, final expects a note to appear there. */
4184 emit_note (NOTE_INSN_DELETED
);
4186 /* Mark arrays indexed with non-constant indices with TREE_ADDRESSABLE. */
4187 discover_nonconstant_array_refs ();
4189 targetm
.expand_to_rtl_hook ();
4190 crtl
->stack_alignment_needed
= STACK_BOUNDARY
;
4191 crtl
->max_used_stack_slot_alignment
= STACK_BOUNDARY
;
4192 crtl
->stack_alignment_estimated
= 0;
4193 crtl
->preferred_stack_boundary
= STACK_BOUNDARY
;
4194 cfun
->cfg
->max_jumptable_ents
= 0;
4196 /* Resovle the function section. Some targets, like ARM EABI rely on knowledge
4197 of the function section at exapnsion time to predict distance of calls. */
4198 resolve_unique_section (current_function_decl
, 0, flag_function_sections
);
4200 /* Expand the variables recorded during gimple lowering. */
4201 timevar_push (TV_VAR_EXPAND
);
4204 expand_used_vars ();
4206 var_seq
= get_insns ();
4208 timevar_pop (TV_VAR_EXPAND
);
4210 /* Honor stack protection warnings. */
4211 if (warn_stack_protect
)
4213 if (cfun
->calls_alloca
)
4214 warning (OPT_Wstack_protector
,
4215 "stack protector not protecting local variables: "
4216 "variable length buffer");
4217 if (has_short_buffer
&& !crtl
->stack_protect_guard
)
4218 warning (OPT_Wstack_protector
,
4219 "stack protector not protecting function: "
4220 "all local arrays are less than %d bytes long",
4221 (int) PARAM_VALUE (PARAM_SSP_BUFFER_SIZE
));
4224 /* Set up parameters and prepare for return, for the function. */
4225 expand_function_start (current_function_decl
);
4227 /* If we emitted any instructions for setting up the variables,
4228 emit them before the FUNCTION_START note. */
4231 emit_insn_before (var_seq
, parm_birth_insn
);
4233 /* In expand_function_end we'll insert the alloca save/restore
4234 before parm_birth_insn. We've just insertted an alloca call.
4235 Adjust the pointer to match. */
4236 parm_birth_insn
= var_seq
;
4239 /* Now that we also have the parameter RTXs, copy them over to our
4241 for (i
= 0; i
< SA
.map
->num_partitions
; i
++)
4243 tree var
= SSA_NAME_VAR (partition_to_var (SA
.map
, i
));
4245 if (TREE_CODE (var
) != VAR_DECL
4246 && !SA
.partition_to_pseudo
[i
])
4247 SA
.partition_to_pseudo
[i
] = DECL_RTL_IF_SET (var
);
4248 gcc_assert (SA
.partition_to_pseudo
[i
]);
4250 /* If this decl was marked as living in multiple places, reset
4251 this now to NULL. */
4252 if (DECL_RTL_IF_SET (var
) == pc_rtx
)
4253 SET_DECL_RTL (var
, NULL
);
4255 /* Some RTL parts really want to look at DECL_RTL(x) when x
4256 was a decl marked in REG_ATTR or MEM_ATTR. We could use
4257 SET_DECL_RTL here making this available, but that would mean
4258 to select one of the potentially many RTLs for one DECL. Instead
4259 of doing that we simply reset the MEM_EXPR of the RTL in question,
4260 then nobody can get at it and hence nobody can call DECL_RTL on it. */
4261 if (!DECL_RTL_SET_P (var
))
4263 if (MEM_P (SA
.partition_to_pseudo
[i
]))
4264 set_mem_expr (SA
.partition_to_pseudo
[i
], NULL
);
4268 /* If this function is `main', emit a call to `__main'
4269 to run global initializers, etc. */
4270 if (DECL_NAME (current_function_decl
)
4271 && MAIN_NAME_P (DECL_NAME (current_function_decl
))
4272 && DECL_FILE_SCOPE_P (current_function_decl
))
4273 expand_main_function ();
4275 /* Initialize the stack_protect_guard field. This must happen after the
4276 call to __main (if any) so that the external decl is initialized. */
4277 if (crtl
->stack_protect_guard
)
4278 stack_protect_prologue ();
4280 expand_phi_nodes (&SA
);
4282 /* Register rtl specific functions for cfg. */
4283 rtl_register_cfg_hooks ();
4285 init_block
= construct_init_block ();
4287 /* Clear EDGE_EXECUTABLE on the entry edge(s). It is cleaned from the
4288 remaining edges later. */
4289 FOR_EACH_EDGE (e
, ei
, ENTRY_BLOCK_PTR
->succs
)
4290 e
->flags
&= ~EDGE_EXECUTABLE
;
4292 lab_rtx_for_bb
= pointer_map_create ();
4293 FOR_BB_BETWEEN (bb
, init_block
->next_bb
, EXIT_BLOCK_PTR
, next_bb
)
4294 bb
= expand_gimple_basic_block (bb
);
4296 if (MAY_HAVE_DEBUG_INSNS
)
4297 expand_debug_locations ();
4299 execute_free_datastructures ();
4300 timevar_push (TV_OUT_OF_SSA
);
4301 finish_out_of_ssa (&SA
);
4302 timevar_pop (TV_OUT_OF_SSA
);
4304 timevar_push (TV_POST_EXPAND
);
4305 /* We are no longer in SSA form. */
4306 cfun
->gimple_df
->in_ssa_p
= false;
4308 /* Expansion is used by optimization passes too, set maybe_hot_insn_p
4309 conservatively to true until they are all profile aware. */
4310 pointer_map_destroy (lab_rtx_for_bb
);
4313 construct_exit_block ();
4314 set_curr_insn_block (DECL_INITIAL (current_function_decl
));
4315 insn_locators_finalize ();
4317 /* Zap the tree EH table. */
4318 set_eh_throw_stmt_table (cfun
, NULL
);
4320 /* We need JUMP_LABEL be set in order to redirect jumps, and hence
4321 split edges which edge insertions might do. */
4322 rebuild_jump_labels (get_insns ());
4324 FOR_BB_BETWEEN (bb
, ENTRY_BLOCK_PTR
, EXIT_BLOCK_PTR
, next_bb
)
4328 for (ei
= ei_start (bb
->succs
); (e
= ei_safe_edge (ei
)); )
4332 rebuild_jump_labels_chain (e
->insns
.r
);
4333 /* Avoid putting insns before parm_birth_insn. */
4334 if (e
->src
== ENTRY_BLOCK_PTR
4335 && single_succ_p (ENTRY_BLOCK_PTR
)
4338 rtx insns
= e
->insns
.r
;
4339 e
->insns
.r
= NULL_RTX
;
4340 emit_insn_after_noloc (insns
, parm_birth_insn
, e
->dest
);
4343 commit_one_edge_insertion (e
);
4350 /* We're done expanding trees to RTL. */
4351 currently_expanding_to_rtl
= 0;
4353 FOR_BB_BETWEEN (bb
, ENTRY_BLOCK_PTR
->next_bb
, EXIT_BLOCK_PTR
, next_bb
)
4357 for (ei
= ei_start (bb
->succs
); (e
= ei_safe_edge (ei
)); )
4359 /* Clear EDGE_EXECUTABLE. This flag is never used in the backend. */
4360 e
->flags
&= ~EDGE_EXECUTABLE
;
4362 /* At the moment not all abnormal edges match the RTL
4363 representation. It is safe to remove them here as
4364 find_many_sub_basic_blocks will rediscover them.
4365 In the future we should get this fixed properly. */
4366 if ((e
->flags
& EDGE_ABNORMAL
)
4367 && !(e
->flags
& EDGE_SIBCALL
))
4374 blocks
= sbitmap_alloc (last_basic_block
);
4375 sbitmap_ones (blocks
);
4376 find_many_sub_basic_blocks (blocks
);
4377 sbitmap_free (blocks
);
4378 purge_all_dead_edges ();
4382 expand_stack_alignment ();
4384 #ifdef ENABLE_CHECKING
4385 verify_flow_info ();
4388 /* There's no need to defer outputting this function any more; we
4389 know we want to output it. */
4390 DECL_DEFER_OUTPUT (current_function_decl
) = 0;
4392 /* Now that we're done expanding trees to RTL, we shouldn't have any
4393 more CONCATs anywhere. */
4394 generating_concat_p
= 0;
4399 "\n\n;;\n;; Full RTL generated for this function:\n;;\n");
4400 /* And the pass manager will dump RTL for us. */
4403 /* If we're emitting a nested function, make sure its parent gets
4404 emitted as well. Doing otherwise confuses debug info. */
4407 for (parent
= DECL_CONTEXT (current_function_decl
);
4408 parent
!= NULL_TREE
;
4409 parent
= get_containing_scope (parent
))
4410 if (TREE_CODE (parent
) == FUNCTION_DECL
)
4411 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent
)) = 1;
4414 /* We are now committed to emitting code for this function. Do any
4415 preparation, such as emitting abstract debug info for the inline
4416 before it gets mangled by optimization. */
4417 if (cgraph_function_possibly_inlined_p (current_function_decl
))
4418 (*debug_hooks
->outlining_inline_function
) (current_function_decl
);
4420 TREE_ASM_WRITTEN (current_function_decl
) = 1;
4422 /* After expanding, the return labels are no longer needed. */
4423 return_label
= NULL
;
4424 naked_return_label
= NULL
;
4425 /* Tag the blocks with a depth number so that change_scope can find
4426 the common parent easily. */
4427 set_block_levels (DECL_INITIAL (cfun
->decl
), 0);
4428 default_rtl_profile ();
4429 timevar_pop (TV_POST_EXPAND
);
4433 struct rtl_opt_pass pass_expand
=
4437 "expand", /* name */
4439 gimple_expand_cfg
, /* execute */
4442 0, /* static_pass_number */
4443 TV_EXPAND
, /* tv_id */
4444 PROP_ssa
| PROP_gimple_leh
| PROP_cfg
4445 | PROP_gimple_lcx
, /* properties_required */
4446 PROP_rtl
, /* properties_provided */
4447 PROP_ssa
| PROP_trees
, /* properties_destroyed */
4448 TODO_verify_ssa
| TODO_verify_flow
4449 | TODO_verify_stmts
, /* todo_flags_start */
4450 TODO_ggc_collect
/* todo_flags_finish */