1 /* A pass for lowering trees to RTL.
2 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
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"
33 #include "tree-pass.h"
36 #include "diagnostic.h"
37 #include "gimple-pretty-print.h"
41 #include "tree-inline.h"
42 #include "value-prof.h"
44 #include "ssaexpand.h"
48 #include "regs.h" /* For reg_renumber. */
49 #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
102 if (gimple_has_location (stmt
) && CAN_HAVE_LOCATION_P (t
))
103 SET_EXPR_LOCATION (t
, gimple_location (stmt
));
109 #ifndef STACK_ALIGNMENT_NEEDED
110 #define STACK_ALIGNMENT_NEEDED 1
113 #define SSAVAR(x) (TREE_CODE (x) == SSA_NAME ? SSA_NAME_VAR (x) : x)
115 /* Associate declaration T with storage space X. If T is no
116 SSA name this is exactly SET_DECL_RTL, otherwise make the
117 partition of T associated with X. */
119 set_rtl (tree t
, rtx x
)
121 if (TREE_CODE (t
) == SSA_NAME
)
123 SA
.partition_to_pseudo
[var_to_partition (SA
.map
, t
)] = x
;
125 set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (t
), x
);
126 /* For the benefit of debug information at -O0 (where vartracking
127 doesn't run) record the place also in the base DECL if it's
128 a normal variable (not a parameter). */
129 if (x
&& x
!= pc_rtx
&& TREE_CODE (SSA_NAME_VAR (t
)) == VAR_DECL
)
131 tree var
= SSA_NAME_VAR (t
);
132 /* If we don't yet have something recorded, just record it now. */
133 if (!DECL_RTL_SET_P (var
))
134 SET_DECL_RTL (var
, x
);
135 /* If we have it set already to "multiple places" don't
137 else if (DECL_RTL (var
) == pc_rtx
)
139 /* If we have something recorded and it's not the same place
140 as we want to record now, we have multiple partitions for the
141 same base variable, with different places. We can't just
142 randomly chose one, hence we have to say that we don't know.
143 This only happens with optimization, and there var-tracking
144 will figure out the right thing. */
145 else if (DECL_RTL (var
) != x
)
146 SET_DECL_RTL (var
, pc_rtx
);
153 /* This structure holds data relevant to one variable that will be
154 placed in a stack slot. */
160 /* Initially, the size of the variable. Later, the size of the partition,
161 if this variable becomes it's partition's representative. */
164 /* The *byte* alignment required for this variable. Or as, with the
165 size, the alignment for this partition. */
168 /* The partition representative. */
169 size_t representative
;
171 /* The next stack variable in the partition, or EOC. */
174 /* The numbers of conflicting stack variables. */
178 #define EOC ((size_t)-1)
180 /* We have an array of such objects while deciding allocation. */
181 static struct stack_var
*stack_vars
;
182 static size_t stack_vars_alloc
;
183 static size_t stack_vars_num
;
184 static struct pointer_map_t
*decl_to_stack_part
;
186 /* Conflict bitmaps go on this obstack. This allows us to destroy
187 all of them in one big sweep. */
188 static bitmap_obstack stack_var_bitmap_obstack
;
190 /* An array of indices such that stack_vars[stack_vars_sorted[i]].size
191 is non-decreasing. */
192 static size_t *stack_vars_sorted
;
194 /* The phase of the stack frame. This is the known misalignment of
195 virtual_stack_vars_rtx from PREFERRED_STACK_BOUNDARY. That is,
196 (frame_offset+frame_phase) % PREFERRED_STACK_BOUNDARY == 0. */
197 static int frame_phase
;
199 /* Used during expand_used_vars to remember if we saw any decls for
200 which we'd like to enable stack smashing protection. */
201 static bool has_protected_decls
;
203 /* Used during expand_used_vars. Remember if we say a character buffer
204 smaller than our cutoff threshold. Used for -Wstack-protector. */
205 static bool has_short_buffer
;
207 /* Compute the byte alignment to use for DECL. Ignore alignment
208 we can't do with expected alignment of the stack boundary. */
211 align_local_variable (tree decl
)
213 unsigned int align
= LOCAL_DECL_ALIGNMENT (decl
);
214 DECL_ALIGN (decl
) = align
;
215 return align
/ BITS_PER_UNIT
;
218 /* Allocate SIZE bytes at byte alignment ALIGN from the stack frame.
219 Return the frame offset. */
222 alloc_stack_frame_space (HOST_WIDE_INT size
, unsigned HOST_WIDE_INT align
)
224 HOST_WIDE_INT offset
, new_frame_offset
;
226 new_frame_offset
= frame_offset
;
227 if (FRAME_GROWS_DOWNWARD
)
229 new_frame_offset
-= size
+ frame_phase
;
230 new_frame_offset
&= -align
;
231 new_frame_offset
+= frame_phase
;
232 offset
= new_frame_offset
;
236 new_frame_offset
-= frame_phase
;
237 new_frame_offset
+= align
- 1;
238 new_frame_offset
&= -align
;
239 new_frame_offset
+= frame_phase
;
240 offset
= new_frame_offset
;
241 new_frame_offset
+= size
;
243 frame_offset
= new_frame_offset
;
245 if (frame_offset_overflow (frame_offset
, cfun
->decl
))
246 frame_offset
= offset
= 0;
251 /* Accumulate DECL into STACK_VARS. */
254 add_stack_var (tree decl
)
258 if (stack_vars_num
>= stack_vars_alloc
)
260 if (stack_vars_alloc
)
261 stack_vars_alloc
= stack_vars_alloc
* 3 / 2;
263 stack_vars_alloc
= 32;
265 = XRESIZEVEC (struct stack_var
, stack_vars
, stack_vars_alloc
);
267 if (!decl_to_stack_part
)
268 decl_to_stack_part
= pointer_map_create ();
270 v
= &stack_vars
[stack_vars_num
];
271 * (size_t *)pointer_map_insert (decl_to_stack_part
, decl
) = stack_vars_num
;
274 v
->size
= tree_low_cst (DECL_SIZE_UNIT (SSAVAR (decl
)), 1);
275 /* Ensure that all variables have size, so that &a != &b for any two
276 variables that are simultaneously live. */
279 v
->alignb
= align_local_variable (SSAVAR (decl
));
280 /* An alignment of zero can mightily confuse us later. */
281 gcc_assert (v
->alignb
!= 0);
283 /* All variables are initially in their own partition. */
284 v
->representative
= stack_vars_num
;
287 /* All variables initially conflict with no other. */
290 /* Ensure that this decl doesn't get put onto the list twice. */
291 set_rtl (decl
, pc_rtx
);
296 /* Make the decls associated with luid's X and Y conflict. */
299 add_stack_var_conflict (size_t x
, size_t y
)
301 struct stack_var
*a
= &stack_vars
[x
];
302 struct stack_var
*b
= &stack_vars
[y
];
304 a
->conflicts
= BITMAP_ALLOC (&stack_var_bitmap_obstack
);
306 b
->conflicts
= BITMAP_ALLOC (&stack_var_bitmap_obstack
);
307 bitmap_set_bit (a
->conflicts
, y
);
308 bitmap_set_bit (b
->conflicts
, x
);
311 /* Check whether the decls associated with luid's X and Y conflict. */
314 stack_var_conflict_p (size_t x
, size_t y
)
316 struct stack_var
*a
= &stack_vars
[x
];
317 struct stack_var
*b
= &stack_vars
[y
];
320 /* Partitions containing an SSA name result from gimple registers
321 with things like unsupported modes. They are top-level and
322 hence conflict with everything else. */
323 if (TREE_CODE (a
->decl
) == SSA_NAME
|| TREE_CODE (b
->decl
) == SSA_NAME
)
326 if (!a
->conflicts
|| !b
->conflicts
)
328 return bitmap_bit_p (a
->conflicts
, y
);
331 /* Callback for walk_stmt_ops. If OP is a decl touched by add_stack_var
332 enter its partition number into bitmap DATA. */
335 visit_op (gimple stmt ATTRIBUTE_UNUSED
, tree op
, void *data
)
337 bitmap active
= (bitmap
)data
;
338 op
= get_base_address (op
);
341 && DECL_RTL_IF_SET (op
) == pc_rtx
)
343 size_t *v
= (size_t *) pointer_map_contains (decl_to_stack_part
, op
);
345 bitmap_set_bit (active
, *v
);
350 /* Callback for walk_stmt_ops. If OP is a decl touched by add_stack_var
351 record conflicts between it and all currently active other partitions
355 visit_conflict (gimple stmt ATTRIBUTE_UNUSED
, tree op
, void *data
)
357 bitmap active
= (bitmap
)data
;
358 op
= get_base_address (op
);
361 && DECL_RTL_IF_SET (op
) == pc_rtx
)
364 (size_t *) pointer_map_contains (decl_to_stack_part
, op
);
365 if (v
&& bitmap_set_bit (active
, *v
))
370 gcc_assert (num
< stack_vars_num
);
371 EXECUTE_IF_SET_IN_BITMAP (active
, 0, i
, bi
)
372 add_stack_var_conflict (num
, i
);
378 /* Helper routine for add_scope_conflicts, calculating the active partitions
379 at the end of BB, leaving the result in WORK. We're called to generate
380 conflicts when FOR_CONFLICT is true, otherwise we're just tracking
384 add_scope_conflicts_1 (basic_block bb
, bitmap work
, bool for_conflict
)
388 gimple_stmt_iterator gsi
;
389 bool (*visit
)(gimple
, tree
, void *);
392 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
393 bitmap_ior_into (work
, (bitmap
)e
->src
->aux
);
397 for (gsi
= gsi_start_phis (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
399 gimple stmt
= gsi_stmt (gsi
);
400 walk_stmt_load_store_addr_ops (stmt
, work
, NULL
, NULL
, visit
);
402 for (gsi
= gsi_after_labels (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
404 gimple stmt
= gsi_stmt (gsi
);
406 if (gimple_clobber_p (stmt
))
408 tree lhs
= gimple_assign_lhs (stmt
);
410 /* Nested function lowering might introduce LHSs
411 that are COMPONENT_REFs. */
412 if (TREE_CODE (lhs
) != VAR_DECL
)
414 if (DECL_RTL_IF_SET (lhs
) == pc_rtx
416 pointer_map_contains (decl_to_stack_part
, lhs
)))
417 bitmap_clear_bit (work
, *v
);
419 else if (!is_gimple_debug (stmt
))
422 && visit
== visit_op
)
424 /* If this is the first real instruction in this BB we need
425 to add conflicts for everything live at this point now.
426 Unlike classical liveness for named objects we can't
427 rely on seeing a def/use of the names we're interested in.
428 There might merely be indirect loads/stores. We'd not add any
429 conflicts for such partitions. */
432 EXECUTE_IF_SET_IN_BITMAP (work
, 0, i
, bi
)
434 struct stack_var
*a
= &stack_vars
[i
];
436 a
->conflicts
= BITMAP_ALLOC (&stack_var_bitmap_obstack
);
437 bitmap_ior_into (a
->conflicts
, work
);
439 visit
= visit_conflict
;
441 walk_stmt_load_store_addr_ops (stmt
, work
, visit
, visit
, visit
);
446 /* Generate stack partition conflicts between all partitions that are
447 simultaneously live. */
450 add_scope_conflicts (void)
454 bitmap work
= BITMAP_ALLOC (NULL
);
458 /* We approximate the live range of a stack variable by taking the first
459 mention of its name as starting point(s), and by the end-of-scope
460 death clobber added by gimplify as ending point(s) of the range.
461 This overapproximates in the case we for instance moved an address-taken
462 operation upward, without also moving a dereference to it upwards.
463 But it's conservatively correct as a variable never can hold values
464 before its name is mentioned at least once.
466 We then do a mostly classical bitmap liveness algorithm. */
469 bb
->aux
= BITMAP_ALLOC (&stack_var_bitmap_obstack
);
471 rpo
= XNEWVEC (int, last_basic_block
);
472 n_bbs
= pre_and_rev_post_order_compute (NULL
, rpo
, false);
479 for (i
= 0; i
< n_bbs
; i
++)
482 bb
= BASIC_BLOCK (rpo
[i
]);
483 active
= (bitmap
)bb
->aux
;
484 add_scope_conflicts_1 (bb
, work
, false);
485 if (bitmap_ior_into (active
, work
))
491 add_scope_conflicts_1 (bb
, work
, true);
496 BITMAP_FREE (bb
->aux
);
499 /* A subroutine of partition_stack_vars. A comparison function for qsort,
500 sorting an array of indices by the properties of the object. */
503 stack_var_cmp (const void *a
, const void *b
)
505 size_t ia
= *(const size_t *)a
;
506 size_t ib
= *(const size_t *)b
;
507 unsigned int aligna
= stack_vars
[ia
].alignb
;
508 unsigned int alignb
= stack_vars
[ib
].alignb
;
509 HOST_WIDE_INT sizea
= stack_vars
[ia
].size
;
510 HOST_WIDE_INT sizeb
= stack_vars
[ib
].size
;
511 tree decla
= stack_vars
[ia
].decl
;
512 tree declb
= stack_vars
[ib
].decl
;
514 unsigned int uida
, uidb
;
516 /* Primary compare on "large" alignment. Large comes first. */
517 largea
= (aligna
* BITS_PER_UNIT
> MAX_SUPPORTED_STACK_ALIGNMENT
);
518 largeb
= (alignb
* BITS_PER_UNIT
> MAX_SUPPORTED_STACK_ALIGNMENT
);
519 if (largea
!= largeb
)
520 return (int)largeb
- (int)largea
;
522 /* Secondary compare on size, decreasing */
528 /* Tertiary compare on true alignment, decreasing. */
534 /* Final compare on ID for sort stability, increasing.
535 Two SSA names are compared by their version, SSA names come before
536 non-SSA names, and two normal decls are compared by their DECL_UID. */
537 if (TREE_CODE (decla
) == SSA_NAME
)
539 if (TREE_CODE (declb
) == SSA_NAME
)
540 uida
= SSA_NAME_VERSION (decla
), uidb
= SSA_NAME_VERSION (declb
);
544 else if (TREE_CODE (declb
) == SSA_NAME
)
547 uida
= DECL_UID (decla
), uidb
= DECL_UID (declb
);
556 /* If the points-to solution *PI points to variables that are in a partition
557 together with other variables add all partition members to the pointed-to
561 add_partitioned_vars_to_ptset (struct pt_solution
*pt
,
562 struct pointer_map_t
*decls_to_partitions
,
563 struct pointer_set_t
*visited
, bitmap temp
)
571 /* The pointed-to vars bitmap is shared, it is enough to
573 || pointer_set_insert(visited
, pt
->vars
))
578 /* By using a temporary bitmap to store all members of the partitions
579 we have to add we make sure to visit each of the partitions only
581 EXECUTE_IF_SET_IN_BITMAP (pt
->vars
, 0, i
, bi
)
583 || !bitmap_bit_p (temp
, i
))
584 && (part
= (bitmap
*) pointer_map_contains (decls_to_partitions
,
585 (void *)(size_t) i
)))
586 bitmap_ior_into (temp
, *part
);
587 if (!bitmap_empty_p (temp
))
588 bitmap_ior_into (pt
->vars
, temp
);
591 /* Update points-to sets based on partition info, so we can use them on RTL.
592 The bitmaps representing stack partitions will be saved until expand,
593 where partitioned decls used as bases in memory expressions will be
597 update_alias_info_with_stack_vars (void)
599 struct pointer_map_t
*decls_to_partitions
= NULL
;
601 tree var
= NULL_TREE
;
603 for (i
= 0; i
< stack_vars_num
; i
++)
607 struct ptr_info_def
*pi
;
609 /* Not interested in partitions with single variable. */
610 if (stack_vars
[i
].representative
!= i
611 || stack_vars
[i
].next
== EOC
)
614 if (!decls_to_partitions
)
616 decls_to_partitions
= pointer_map_create ();
617 cfun
->gimple_df
->decls_to_pointers
= pointer_map_create ();
620 /* Create an SSA_NAME that points to the partition for use
621 as base during alias-oracle queries on RTL for bases that
622 have been partitioned. */
623 if (var
== NULL_TREE
)
624 var
= create_tmp_var (ptr_type_node
, NULL
);
625 name
= make_ssa_name (var
, NULL
);
627 /* Create bitmaps representing partitions. They will be used for
628 points-to sets later, so use GGC alloc. */
629 part
= BITMAP_GGC_ALLOC ();
630 for (j
= i
; j
!= EOC
; j
= stack_vars
[j
].next
)
632 tree decl
= stack_vars
[j
].decl
;
633 unsigned int uid
= DECL_PT_UID (decl
);
634 bitmap_set_bit (part
, uid
);
635 *((bitmap
*) pointer_map_insert (decls_to_partitions
,
636 (void *)(size_t) uid
)) = part
;
637 *((tree
*) pointer_map_insert (cfun
->gimple_df
->decls_to_pointers
,
639 if (TREE_ADDRESSABLE (decl
))
640 TREE_ADDRESSABLE (name
) = 1;
643 /* Make the SSA name point to all partition members. */
644 pi
= get_ptr_info (name
);
645 pt_solution_set (&pi
->pt
, part
, false);
648 /* Make all points-to sets that contain one member of a partition
649 contain all members of the partition. */
650 if (decls_to_partitions
)
653 struct pointer_set_t
*visited
= pointer_set_create ();
654 bitmap temp
= BITMAP_ALLOC (&stack_var_bitmap_obstack
);
656 for (i
= 1; i
< num_ssa_names
; i
++)
658 tree name
= ssa_name (i
);
659 struct ptr_info_def
*pi
;
662 && POINTER_TYPE_P (TREE_TYPE (name
))
663 && ((pi
= SSA_NAME_PTR_INFO (name
)) != NULL
))
664 add_partitioned_vars_to_ptset (&pi
->pt
, decls_to_partitions
,
668 add_partitioned_vars_to_ptset (&cfun
->gimple_df
->escaped
,
669 decls_to_partitions
, visited
, temp
);
671 pointer_set_destroy (visited
);
672 pointer_map_destroy (decls_to_partitions
);
677 /* A subroutine of partition_stack_vars. The UNION portion of a UNION/FIND
678 partitioning algorithm. Partitions A and B are known to be non-conflicting.
679 Merge them into a single partition A. */
682 union_stack_vars (size_t a
, size_t b
)
684 struct stack_var
*vb
= &stack_vars
[b
];
688 gcc_assert (stack_vars
[b
].next
== EOC
);
689 /* Add B to A's partition. */
690 stack_vars
[b
].next
= stack_vars
[a
].next
;
691 stack_vars
[b
].representative
= a
;
692 stack_vars
[a
].next
= b
;
694 /* Update the required alignment of partition A to account for B. */
695 if (stack_vars
[a
].alignb
< stack_vars
[b
].alignb
)
696 stack_vars
[a
].alignb
= stack_vars
[b
].alignb
;
698 /* Update the interference graph and merge the conflicts. */
701 EXECUTE_IF_SET_IN_BITMAP (vb
->conflicts
, 0, u
, bi
)
702 add_stack_var_conflict (a
, stack_vars
[u
].representative
);
703 BITMAP_FREE (vb
->conflicts
);
707 /* A subroutine of expand_used_vars. Binpack the variables into
708 partitions constrained by the interference graph. The overall
709 algorithm used is as follows:
711 Sort the objects by size in descending order.
716 Look for the largest non-conflicting object B with size <= S.
723 partition_stack_vars (void)
725 size_t si
, sj
, n
= stack_vars_num
;
727 stack_vars_sorted
= XNEWVEC (size_t, stack_vars_num
);
728 for (si
= 0; si
< n
; ++si
)
729 stack_vars_sorted
[si
] = si
;
734 qsort (stack_vars_sorted
, n
, sizeof (size_t), stack_var_cmp
);
736 for (si
= 0; si
< n
; ++si
)
738 size_t i
= stack_vars_sorted
[si
];
739 unsigned int ialign
= stack_vars
[i
].alignb
;
740 HOST_WIDE_INT isize
= stack_vars
[i
].size
;
742 /* Ignore objects that aren't partition representatives. If we
743 see a var that is not a partition representative, it must
744 have been merged earlier. */
745 if (stack_vars
[i
].representative
!= i
)
748 for (sj
= si
+ 1; sj
< n
; ++sj
)
750 size_t j
= stack_vars_sorted
[sj
];
751 unsigned int jalign
= stack_vars
[j
].alignb
;
752 HOST_WIDE_INT jsize
= stack_vars
[j
].size
;
754 /* Ignore objects that aren't partition representatives. */
755 if (stack_vars
[j
].representative
!= j
)
758 /* Do not mix objects of "small" (supported) alignment
759 and "large" (unsupported) alignment. */
760 if ((ialign
* BITS_PER_UNIT
<= MAX_SUPPORTED_STACK_ALIGNMENT
)
761 != (jalign
* BITS_PER_UNIT
<= MAX_SUPPORTED_STACK_ALIGNMENT
))
764 /* For Address Sanitizer do not mix objects with different
765 sizes, as the shorter vars wouldn't be adequately protected.
766 Don't do that for "large" (unsupported) alignment objects,
767 those aren't protected anyway. */
768 if (flag_asan
&& isize
!= jsize
769 && ialign
* BITS_PER_UNIT
<= MAX_SUPPORTED_STACK_ALIGNMENT
)
772 /* Ignore conflicting objects. */
773 if (stack_var_conflict_p (i
, j
))
776 /* UNION the objects, placing J at OFFSET. */
777 union_stack_vars (i
, j
);
781 update_alias_info_with_stack_vars ();
784 /* A debugging aid for expand_used_vars. Dump the generated partitions. */
787 dump_stack_var_partition (void)
789 size_t si
, i
, j
, n
= stack_vars_num
;
791 for (si
= 0; si
< n
; ++si
)
793 i
= stack_vars_sorted
[si
];
795 /* Skip variables that aren't partition representatives, for now. */
796 if (stack_vars
[i
].representative
!= i
)
799 fprintf (dump_file
, "Partition %lu: size " HOST_WIDE_INT_PRINT_DEC
800 " align %u\n", (unsigned long) i
, stack_vars
[i
].size
,
801 stack_vars
[i
].alignb
);
803 for (j
= i
; j
!= EOC
; j
= stack_vars
[j
].next
)
805 fputc ('\t', dump_file
);
806 print_generic_expr (dump_file
, stack_vars
[j
].decl
, dump_flags
);
808 fputc ('\n', dump_file
);
812 /* Assign rtl to DECL at BASE + OFFSET. */
815 expand_one_stack_var_at (tree decl
, rtx base
, unsigned base_align
,
816 HOST_WIDE_INT offset
)
821 /* If this fails, we've overflowed the stack frame. Error nicely? */
822 gcc_assert (offset
== trunc_int_for_mode (offset
, Pmode
));
824 x
= plus_constant (Pmode
, base
, offset
);
825 x
= gen_rtx_MEM (DECL_MODE (SSAVAR (decl
)), x
);
827 if (TREE_CODE (decl
) != SSA_NAME
)
829 /* Set alignment we actually gave this decl if it isn't an SSA name.
830 If it is we generate stack slots only accidentally so it isn't as
831 important, we'll simply use the alignment that is already set. */
832 if (base
== virtual_stack_vars_rtx
)
833 offset
-= frame_phase
;
834 align
= offset
& -offset
;
835 align
*= BITS_PER_UNIT
;
836 if (align
== 0 || align
> base_align
)
839 /* One would think that we could assert that we're not decreasing
840 alignment here, but (at least) the i386 port does exactly this
841 via the MINIMUM_ALIGNMENT hook. */
843 DECL_ALIGN (decl
) = align
;
844 DECL_USER_ALIGN (decl
) = 0;
847 set_mem_attributes (x
, SSAVAR (decl
), true);
851 struct stack_vars_data
853 /* Vector of offset pairs, always end of some padding followed
854 by start of the padding that needs Address Sanitizer protection.
855 The vector is in reversed, highest offset pairs come first. */
856 vec
<HOST_WIDE_INT
> asan_vec
;
858 /* Vector of partition representative decls in between the paddings. */
859 vec
<tree
> asan_decl_vec
;
862 /* A subroutine of expand_used_vars. Give each partition representative
863 a unique location within the stack frame. Update each partition member
864 with that location. */
867 expand_stack_vars (bool (*pred
) (size_t), struct stack_vars_data
*data
)
869 size_t si
, i
, j
, n
= stack_vars_num
;
870 HOST_WIDE_INT large_size
= 0, large_alloc
= 0;
871 rtx large_base
= NULL
;
872 unsigned large_align
= 0;
875 /* Determine if there are any variables requiring "large" alignment.
876 Since these are dynamically allocated, we only process these if
877 no predicate involved. */
878 large_align
= stack_vars
[stack_vars_sorted
[0]].alignb
* BITS_PER_UNIT
;
879 if (pred
== NULL
&& large_align
> MAX_SUPPORTED_STACK_ALIGNMENT
)
881 /* Find the total size of these variables. */
882 for (si
= 0; si
< n
; ++si
)
886 i
= stack_vars_sorted
[si
];
887 alignb
= stack_vars
[i
].alignb
;
889 /* Stop when we get to the first decl with "small" alignment. */
890 if (alignb
* BITS_PER_UNIT
<= MAX_SUPPORTED_STACK_ALIGNMENT
)
893 /* Skip variables that aren't partition representatives. */
894 if (stack_vars
[i
].representative
!= i
)
897 /* Skip variables that have already had rtl assigned. See also
898 add_stack_var where we perpetrate this pc_rtx hack. */
899 decl
= stack_vars
[i
].decl
;
900 if ((TREE_CODE (decl
) == SSA_NAME
901 ? SA
.partition_to_pseudo
[var_to_partition (SA
.map
, decl
)]
902 : DECL_RTL (decl
)) != pc_rtx
)
905 large_size
+= alignb
- 1;
906 large_size
&= -(HOST_WIDE_INT
)alignb
;
907 large_size
+= stack_vars
[i
].size
;
910 /* If there were any, allocate space. */
912 large_base
= allocate_dynamic_stack_space (GEN_INT (large_size
), 0,
916 for (si
= 0; si
< n
; ++si
)
919 unsigned base_align
, alignb
;
920 HOST_WIDE_INT offset
;
922 i
= stack_vars_sorted
[si
];
924 /* Skip variables that aren't partition representatives, for now. */
925 if (stack_vars
[i
].representative
!= i
)
928 /* Skip variables that have already had rtl assigned. See also
929 add_stack_var where we perpetrate this pc_rtx hack. */
930 decl
= stack_vars
[i
].decl
;
931 if ((TREE_CODE (decl
) == SSA_NAME
932 ? SA
.partition_to_pseudo
[var_to_partition (SA
.map
, decl
)]
933 : DECL_RTL (decl
)) != pc_rtx
)
936 /* Check the predicate to see whether this variable should be
937 allocated in this pass. */
938 if (pred
&& !pred (i
))
941 alignb
= stack_vars
[i
].alignb
;
942 if (alignb
* BITS_PER_UNIT
<= MAX_SUPPORTED_STACK_ALIGNMENT
)
944 if (flag_asan
&& pred
)
946 HOST_WIDE_INT prev_offset
= frame_offset
;
947 tree repr_decl
= NULL_TREE
;
950 = alloc_stack_frame_space (stack_vars
[i
].size
951 + ASAN_RED_ZONE_SIZE
,
952 MAX (alignb
, ASAN_RED_ZONE_SIZE
));
953 data
->asan_vec
.safe_push (prev_offset
);
954 data
->asan_vec
.safe_push (offset
+ stack_vars
[i
].size
);
955 /* Find best representative of the partition.
956 Prefer those with DECL_NAME, even better
957 satisfying asan_protect_stack_decl predicate. */
958 for (j
= i
; j
!= EOC
; j
= stack_vars
[j
].next
)
959 if (asan_protect_stack_decl (stack_vars
[j
].decl
)
960 && DECL_NAME (stack_vars
[j
].decl
))
962 repr_decl
= stack_vars
[j
].decl
;
965 else if (repr_decl
== NULL_TREE
966 && DECL_P (stack_vars
[j
].decl
)
967 && DECL_NAME (stack_vars
[j
].decl
))
968 repr_decl
= stack_vars
[j
].decl
;
969 if (repr_decl
== NULL_TREE
)
970 repr_decl
= stack_vars
[i
].decl
;
971 data
->asan_decl_vec
.safe_push (repr_decl
);
974 offset
= alloc_stack_frame_space (stack_vars
[i
].size
, alignb
);
975 base
= virtual_stack_vars_rtx
;
976 base_align
= crtl
->max_used_stack_slot_alignment
;
980 /* Large alignment is only processed in the last pass. */
983 gcc_assert (large_base
!= NULL
);
985 large_alloc
+= alignb
- 1;
986 large_alloc
&= -(HOST_WIDE_INT
)alignb
;
987 offset
= large_alloc
;
988 large_alloc
+= stack_vars
[i
].size
;
991 base_align
= large_align
;
994 /* Create rtl for each variable based on their location within the
996 for (j
= i
; j
!= EOC
; j
= stack_vars
[j
].next
)
998 expand_one_stack_var_at (stack_vars
[j
].decl
,
1004 gcc_assert (large_alloc
== large_size
);
1007 /* Take into account all sizes of partitions and reset DECL_RTLs. */
1008 static HOST_WIDE_INT
1009 account_stack_vars (void)
1011 size_t si
, j
, i
, n
= stack_vars_num
;
1012 HOST_WIDE_INT size
= 0;
1014 for (si
= 0; si
< n
; ++si
)
1016 i
= stack_vars_sorted
[si
];
1018 /* Skip variables that aren't partition representatives, for now. */
1019 if (stack_vars
[i
].representative
!= i
)
1022 size
+= stack_vars
[i
].size
;
1023 for (j
= i
; j
!= EOC
; j
= stack_vars
[j
].next
)
1024 set_rtl (stack_vars
[j
].decl
, NULL
);
1029 /* A subroutine of expand_one_var. Called to immediately assign rtl
1030 to a variable to be allocated in the stack frame. */
1033 expand_one_stack_var (tree var
)
1035 HOST_WIDE_INT size
, offset
;
1036 unsigned byte_align
;
1038 size
= tree_low_cst (DECL_SIZE_UNIT (SSAVAR (var
)), 1);
1039 byte_align
= align_local_variable (SSAVAR (var
));
1041 /* We handle highly aligned variables in expand_stack_vars. */
1042 gcc_assert (byte_align
* BITS_PER_UNIT
<= MAX_SUPPORTED_STACK_ALIGNMENT
);
1044 offset
= alloc_stack_frame_space (size
, byte_align
);
1046 expand_one_stack_var_at (var
, virtual_stack_vars_rtx
,
1047 crtl
->max_used_stack_slot_alignment
, offset
);
1050 /* A subroutine of expand_one_var. Called to assign rtl to a VAR_DECL
1051 that will reside in a hard register. */
1054 expand_one_hard_reg_var (tree var
)
1056 rest_of_decl_compilation (var
, 0, 0);
1059 /* A subroutine of expand_one_var. Called to assign rtl to a VAR_DECL
1060 that will reside in a pseudo register. */
1063 expand_one_register_var (tree var
)
1065 tree decl
= SSAVAR (var
);
1066 tree type
= TREE_TYPE (decl
);
1067 enum machine_mode reg_mode
= promote_decl_mode (decl
, NULL
);
1068 rtx x
= gen_reg_rtx (reg_mode
);
1072 /* Note if the object is a user variable. */
1073 if (!DECL_ARTIFICIAL (decl
))
1076 if (POINTER_TYPE_P (type
))
1077 mark_reg_pointer (x
, get_pointer_alignment (var
));
1080 /* A subroutine of expand_one_var. Called to assign rtl to a VAR_DECL that
1081 has some associated error, e.g. its type is error-mark. We just need
1082 to pick something that won't crash the rest of the compiler. */
1085 expand_one_error_var (tree var
)
1087 enum machine_mode mode
= DECL_MODE (var
);
1090 if (mode
== BLKmode
)
1091 x
= gen_rtx_MEM (BLKmode
, const0_rtx
);
1092 else if (mode
== VOIDmode
)
1095 x
= gen_reg_rtx (mode
);
1097 SET_DECL_RTL (var
, x
);
1100 /* A subroutine of expand_one_var. VAR is a variable that will be
1101 allocated to the local stack frame. Return true if we wish to
1102 add VAR to STACK_VARS so that it will be coalesced with other
1103 variables. Return false to allocate VAR immediately.
1105 This function is used to reduce the number of variables considered
1106 for coalescing, which reduces the size of the quadratic problem. */
1109 defer_stack_allocation (tree var
, bool toplevel
)
1111 /* If stack protection is enabled, *all* stack variables must be deferred,
1112 so that we can re-order the strings to the top of the frame.
1113 Similarly for Address Sanitizer. */
1114 if (flag_stack_protect
|| flag_asan
)
1117 /* We handle "large" alignment via dynamic allocation. We want to handle
1118 this extra complication in only one place, so defer them. */
1119 if (DECL_ALIGN (var
) > MAX_SUPPORTED_STACK_ALIGNMENT
)
1122 /* Variables in the outermost scope automatically conflict with
1123 every other variable. The only reason to want to defer them
1124 at all is that, after sorting, we can more efficiently pack
1125 small variables in the stack frame. Continue to defer at -O2. */
1126 if (toplevel
&& optimize
< 2)
1129 /* Without optimization, *most* variables are allocated from the
1130 stack, which makes the quadratic problem large exactly when we
1131 want compilation to proceed as quickly as possible. On the
1132 other hand, we don't want the function's stack frame size to
1133 get completely out of hand. So we avoid adding scalars and
1134 "small" aggregates to the list at all. */
1135 if (optimize
== 0 && tree_low_cst (DECL_SIZE_UNIT (var
), 1) < 32)
1141 /* A subroutine of expand_used_vars. Expand one variable according to
1142 its flavor. Variables to be placed on the stack are not actually
1143 expanded yet, merely recorded.
1144 When REALLY_EXPAND is false, only add stack values to be allocated.
1145 Return stack usage this variable is supposed to take.
1148 static HOST_WIDE_INT
1149 expand_one_var (tree var
, bool toplevel
, bool really_expand
)
1151 unsigned int align
= BITS_PER_UNIT
;
1156 if (TREE_TYPE (var
) != error_mark_node
&& TREE_CODE (var
) == VAR_DECL
)
1158 /* Because we don't know if VAR will be in register or on stack,
1159 we conservatively assume it will be on stack even if VAR is
1160 eventually put into register after RA pass. For non-automatic
1161 variables, which won't be on stack, we collect alignment of
1162 type and ignore user specified alignment. */
1163 if (TREE_STATIC (var
) || DECL_EXTERNAL (var
))
1164 align
= MINIMUM_ALIGNMENT (TREE_TYPE (var
),
1165 TYPE_MODE (TREE_TYPE (var
)),
1166 TYPE_ALIGN (TREE_TYPE (var
)));
1167 else if (DECL_HAS_VALUE_EXPR_P (var
)
1168 || (DECL_RTL_SET_P (var
) && MEM_P (DECL_RTL (var
))))
1169 /* Don't consider debug only variables with DECL_HAS_VALUE_EXPR_P set
1170 or variables which were assigned a stack slot already by
1171 expand_one_stack_var_at - in the latter case DECL_ALIGN has been
1172 changed from the offset chosen to it. */
1173 align
= crtl
->stack_alignment_estimated
;
1175 align
= MINIMUM_ALIGNMENT (var
, DECL_MODE (var
), DECL_ALIGN (var
));
1177 /* If the variable alignment is very large we'll dynamicaly allocate
1178 it, which means that in-frame portion is just a pointer. */
1179 if (align
> MAX_SUPPORTED_STACK_ALIGNMENT
)
1180 align
= POINTER_SIZE
;
1183 if (SUPPORTS_STACK_ALIGNMENT
1184 && crtl
->stack_alignment_estimated
< align
)
1186 /* stack_alignment_estimated shouldn't change after stack
1187 realign decision made */
1188 gcc_assert(!crtl
->stack_realign_processed
);
1189 crtl
->stack_alignment_estimated
= align
;
1192 /* stack_alignment_needed > PREFERRED_STACK_BOUNDARY is permitted.
1193 So here we only make sure stack_alignment_needed >= align. */
1194 if (crtl
->stack_alignment_needed
< align
)
1195 crtl
->stack_alignment_needed
= align
;
1196 if (crtl
->max_used_stack_slot_alignment
< align
)
1197 crtl
->max_used_stack_slot_alignment
= align
;
1199 if (TREE_CODE (origvar
) == SSA_NAME
)
1201 gcc_assert (TREE_CODE (var
) != VAR_DECL
1202 || (!DECL_EXTERNAL (var
)
1203 && !DECL_HAS_VALUE_EXPR_P (var
)
1204 && !TREE_STATIC (var
)
1205 && TREE_TYPE (var
) != error_mark_node
1206 && !DECL_HARD_REGISTER (var
)
1209 if (TREE_CODE (var
) != VAR_DECL
&& TREE_CODE (origvar
) != SSA_NAME
)
1211 else if (DECL_EXTERNAL (var
))
1213 else if (DECL_HAS_VALUE_EXPR_P (var
))
1215 else if (TREE_STATIC (var
))
1217 else if (TREE_CODE (origvar
) != SSA_NAME
&& DECL_RTL_SET_P (var
))
1219 else if (TREE_TYPE (var
) == error_mark_node
)
1222 expand_one_error_var (var
);
1224 else if (TREE_CODE (var
) == VAR_DECL
&& DECL_HARD_REGISTER (var
))
1227 expand_one_hard_reg_var (var
);
1229 else if (use_register_for_decl (var
))
1232 expand_one_register_var (origvar
);
1234 else if (! valid_constant_size_p (DECL_SIZE_UNIT (var
)))
1236 /* Reject variables which cover more than half of the address-space. */
1239 error ("size of variable %q+D is too large", var
);
1240 expand_one_error_var (var
);
1243 else if (defer_stack_allocation (var
, toplevel
))
1244 add_stack_var (origvar
);
1248 expand_one_stack_var (origvar
);
1249 return tree_low_cst (DECL_SIZE_UNIT (var
), 1);
1254 /* A subroutine of expand_used_vars. Walk down through the BLOCK tree
1255 expanding variables. Those variables that can be put into registers
1256 are allocated pseudos; those that can't are put on the stack.
1258 TOPLEVEL is true if this is the outermost BLOCK. */
1261 expand_used_vars_for_block (tree block
, bool toplevel
)
1265 /* Expand all variables at this level. */
1266 for (t
= BLOCK_VARS (block
); t
; t
= DECL_CHAIN (t
))
1268 && ((TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != RESULT_DECL
)
1269 || !DECL_NONSHAREABLE (t
)))
1270 expand_one_var (t
, toplevel
, true);
1272 /* Expand all variables at containing levels. */
1273 for (t
= BLOCK_SUBBLOCKS (block
); t
; t
= BLOCK_CHAIN (t
))
1274 expand_used_vars_for_block (t
, false);
1277 /* A subroutine of expand_used_vars. Walk down through the BLOCK tree
1278 and clear TREE_USED on all local variables. */
1281 clear_tree_used (tree block
)
1285 for (t
= BLOCK_VARS (block
); t
; t
= DECL_CHAIN (t
))
1286 /* if (!TREE_STATIC (t) && !DECL_EXTERNAL (t)) */
1287 if ((TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != RESULT_DECL
)
1288 || !DECL_NONSHAREABLE (t
))
1291 for (t
= BLOCK_SUBBLOCKS (block
); t
; t
= BLOCK_CHAIN (t
))
1292 clear_tree_used (t
);
1295 /* Examine TYPE and determine a bit mask of the following features. */
1297 #define SPCT_HAS_LARGE_CHAR_ARRAY 1
1298 #define SPCT_HAS_SMALL_CHAR_ARRAY 2
1299 #define SPCT_HAS_ARRAY 4
1300 #define SPCT_HAS_AGGREGATE 8
1303 stack_protect_classify_type (tree type
)
1305 unsigned int ret
= 0;
1308 switch (TREE_CODE (type
))
1311 t
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
1312 if (t
== char_type_node
1313 || t
== signed_char_type_node
1314 || t
== unsigned_char_type_node
)
1316 unsigned HOST_WIDE_INT max
= PARAM_VALUE (PARAM_SSP_BUFFER_SIZE
);
1317 unsigned HOST_WIDE_INT len
;
1319 if (!TYPE_SIZE_UNIT (type
)
1320 || !host_integerp (TYPE_SIZE_UNIT (type
), 1))
1323 len
= tree_low_cst (TYPE_SIZE_UNIT (type
), 1);
1326 ret
= SPCT_HAS_SMALL_CHAR_ARRAY
| SPCT_HAS_ARRAY
;
1328 ret
= SPCT_HAS_LARGE_CHAR_ARRAY
| SPCT_HAS_ARRAY
;
1331 ret
= SPCT_HAS_ARRAY
;
1335 case QUAL_UNION_TYPE
:
1337 ret
= SPCT_HAS_AGGREGATE
;
1338 for (t
= TYPE_FIELDS (type
); t
; t
= TREE_CHAIN (t
))
1339 if (TREE_CODE (t
) == FIELD_DECL
)
1340 ret
|= stack_protect_classify_type (TREE_TYPE (t
));
1350 /* Return nonzero if DECL should be segregated into the "vulnerable" upper
1351 part of the local stack frame. Remember if we ever return nonzero for
1352 any variable in this function. The return value is the phase number in
1353 which the variable should be allocated. */
1356 stack_protect_decl_phase (tree decl
)
1358 unsigned int bits
= stack_protect_classify_type (TREE_TYPE (decl
));
1361 if (bits
& SPCT_HAS_SMALL_CHAR_ARRAY
)
1362 has_short_buffer
= true;
1364 if (flag_stack_protect
== 2)
1366 if ((bits
& (SPCT_HAS_SMALL_CHAR_ARRAY
| SPCT_HAS_LARGE_CHAR_ARRAY
))
1367 && !(bits
& SPCT_HAS_AGGREGATE
))
1369 else if (bits
& SPCT_HAS_ARRAY
)
1373 ret
= (bits
& SPCT_HAS_LARGE_CHAR_ARRAY
) != 0;
1376 has_protected_decls
= true;
1381 /* Two helper routines that check for phase 1 and phase 2. These are used
1382 as callbacks for expand_stack_vars. */
1385 stack_protect_decl_phase_1 (size_t i
)
1387 return stack_protect_decl_phase (stack_vars
[i
].decl
) == 1;
1391 stack_protect_decl_phase_2 (size_t i
)
1393 return stack_protect_decl_phase (stack_vars
[i
].decl
) == 2;
1396 /* And helper function that checks for asan phase (with stack protector
1397 it is phase 3). This is used as callback for expand_stack_vars.
1398 Returns true if any of the vars in the partition need to be protected. */
1401 asan_decl_phase_3 (size_t i
)
1405 if (asan_protect_stack_decl (stack_vars
[i
].decl
))
1407 i
= stack_vars
[i
].next
;
1412 /* Ensure that variables in different stack protection phases conflict
1413 so that they are not merged and share the same stack slot. */
1416 add_stack_protection_conflicts (void)
1418 size_t i
, j
, n
= stack_vars_num
;
1419 unsigned char *phase
;
1421 phase
= XNEWVEC (unsigned char, n
);
1422 for (i
= 0; i
< n
; ++i
)
1423 phase
[i
] = stack_protect_decl_phase (stack_vars
[i
].decl
);
1425 for (i
= 0; i
< n
; ++i
)
1427 unsigned char ph_i
= phase
[i
];
1428 for (j
= i
+ 1; j
< n
; ++j
)
1429 if (ph_i
!= phase
[j
])
1430 add_stack_var_conflict (i
, j
);
1436 /* Create a decl for the guard at the top of the stack frame. */
1439 create_stack_guard (void)
1441 tree guard
= build_decl (DECL_SOURCE_LOCATION (current_function_decl
),
1442 VAR_DECL
, NULL
, ptr_type_node
);
1443 TREE_THIS_VOLATILE (guard
) = 1;
1444 TREE_USED (guard
) = 1;
1445 expand_one_stack_var (guard
);
1446 crtl
->stack_protect_guard
= guard
;
1449 /* Prepare for expanding variables. */
1451 init_vars_expansion (void)
1453 /* Conflict bitmaps, and a few related temporary bitmaps, go here. */
1454 bitmap_obstack_initialize (&stack_var_bitmap_obstack
);
1456 /* A map from decl to stack partition. */
1457 decl_to_stack_part
= pointer_map_create ();
1459 /* Initialize local stack smashing state. */
1460 has_protected_decls
= false;
1461 has_short_buffer
= false;
1464 /* Free up stack variable graph data. */
1466 fini_vars_expansion (void)
1468 bitmap_obstack_release (&stack_var_bitmap_obstack
);
1470 XDELETEVEC (stack_vars
);
1471 if (stack_vars_sorted
)
1472 XDELETEVEC (stack_vars_sorted
);
1474 stack_vars_sorted
= NULL
;
1475 stack_vars_alloc
= stack_vars_num
= 0;
1476 pointer_map_destroy (decl_to_stack_part
);
1477 decl_to_stack_part
= NULL
;
1480 /* Make a fair guess for the size of the stack frame of the function
1481 in NODE. This doesn't have to be exact, the result is only used in
1482 the inline heuristics. So we don't want to run the full stack var
1483 packing algorithm (which is quadratic in the number of stack vars).
1484 Instead, we calculate the total size of all stack vars. This turns
1485 out to be a pretty fair estimate -- packing of stack vars doesn't
1486 happen very often. */
1489 estimated_stack_frame_size (struct cgraph_node
*node
)
1491 HOST_WIDE_INT size
= 0;
1494 struct function
*fn
= DECL_STRUCT_FUNCTION (node
->symbol
.decl
);
1498 init_vars_expansion ();
1500 FOR_EACH_LOCAL_DECL (fn
, i
, var
)
1501 if (auto_var_in_fn_p (var
, fn
->decl
))
1502 size
+= expand_one_var (var
, true, false);
1504 if (stack_vars_num
> 0)
1506 /* Fake sorting the stack vars for account_stack_vars (). */
1507 stack_vars_sorted
= XNEWVEC (size_t, stack_vars_num
);
1508 for (i
= 0; i
< stack_vars_num
; ++i
)
1509 stack_vars_sorted
[i
] = i
;
1510 size
+= account_stack_vars ();
1513 fini_vars_expansion ();
1518 /* Expand all variables used in the function. */
1521 expand_used_vars (void)
1523 tree var
, outer_block
= DECL_INITIAL (current_function_decl
);
1524 vec
<tree
> maybe_local_decls
= vNULL
;
1525 rtx var_end_seq
= NULL_RTX
;
1526 struct pointer_map_t
*ssa_name_decls
;
1530 /* Compute the phase of the stack frame for this function. */
1532 int align
= PREFERRED_STACK_BOUNDARY
/ BITS_PER_UNIT
;
1533 int off
= STARTING_FRAME_OFFSET
% align
;
1534 frame_phase
= off
? align
- off
: 0;
1537 /* Set TREE_USED on all variables in the local_decls. */
1538 FOR_EACH_LOCAL_DECL (cfun
, i
, var
)
1539 TREE_USED (var
) = 1;
1540 /* Clear TREE_USED on all variables associated with a block scope. */
1541 clear_tree_used (DECL_INITIAL (current_function_decl
));
1543 init_vars_expansion ();
1545 ssa_name_decls
= pointer_map_create ();
1546 for (i
= 0; i
< SA
.map
->num_partitions
; i
++)
1548 tree var
= partition_to_var (SA
.map
, i
);
1550 gcc_assert (!virtual_operand_p (var
));
1552 /* Assign decls to each SSA name partition, share decls for partitions
1553 we could have coalesced (those with the same type). */
1554 if (SSA_NAME_VAR (var
) == NULL_TREE
)
1556 void **slot
= pointer_map_insert (ssa_name_decls
, TREE_TYPE (var
));
1558 *slot
= (void *) create_tmp_reg (TREE_TYPE (var
), NULL
);
1559 replace_ssa_name_symbol (var
, (tree
) *slot
);
1562 if (TREE_CODE (SSA_NAME_VAR (var
)) == VAR_DECL
)
1563 expand_one_var (var
, true, true);
1566 /* This is a PARM_DECL or RESULT_DECL. For those partitions that
1567 contain the default def (representing the parm or result itself)
1568 we don't do anything here. But those which don't contain the
1569 default def (representing a temporary based on the parm/result)
1570 we need to allocate space just like for normal VAR_DECLs. */
1571 if (!bitmap_bit_p (SA
.partition_has_default_def
, i
))
1573 expand_one_var (var
, true, true);
1574 gcc_assert (SA
.partition_to_pseudo
[i
]);
1578 pointer_map_destroy (ssa_name_decls
);
1580 /* At this point all variables on the local_decls with TREE_USED
1581 set are not associated with any block scope. Lay them out. */
1583 len
= vec_safe_length (cfun
->local_decls
);
1584 FOR_EACH_LOCAL_DECL (cfun
, i
, var
)
1586 bool expand_now
= false;
1588 /* Expanded above already. */
1589 if (is_gimple_reg (var
))
1591 TREE_USED (var
) = 0;
1594 /* We didn't set a block for static or extern because it's hard
1595 to tell the difference between a global variable (re)declared
1596 in a local scope, and one that's really declared there to
1597 begin with. And it doesn't really matter much, since we're
1598 not giving them stack space. Expand them now. */
1599 else if (TREE_STATIC (var
) || DECL_EXTERNAL (var
))
1602 /* If the variable is not associated with any block, then it
1603 was created by the optimizers, and could be live anywhere
1605 else if (TREE_USED (var
))
1608 /* Finally, mark all variables on the list as used. We'll use
1609 this in a moment when we expand those associated with scopes. */
1610 TREE_USED (var
) = 1;
1613 expand_one_var (var
, true, true);
1616 if (DECL_ARTIFICIAL (var
) && !DECL_IGNORED_P (var
))
1618 rtx rtl
= DECL_RTL_IF_SET (var
);
1620 /* Keep artificial non-ignored vars in cfun->local_decls
1621 chain until instantiate_decls. */
1622 if (rtl
&& (MEM_P (rtl
) || GET_CODE (rtl
) == CONCAT
))
1623 add_local_decl (cfun
, var
);
1624 else if (rtl
== NULL_RTX
)
1625 /* If rtl isn't set yet, which can happen e.g. with
1626 -fstack-protector, retry before returning from this
1628 maybe_local_decls
.safe_push (var
);
1632 /* We duplicated some of the decls in CFUN->LOCAL_DECLS.
1634 +-----------------+-----------------+
1635 | ...processed... | ...duplicates...|
1636 +-----------------+-----------------+
1638 +-- LEN points here.
1640 We just want the duplicates, as those are the artificial
1641 non-ignored vars that we want to keep until instantiate_decls.
1642 Move them down and truncate the array. */
1643 if (!vec_safe_is_empty (cfun
->local_decls
))
1644 cfun
->local_decls
->block_remove (0, len
);
1646 /* At this point, all variables within the block tree with TREE_USED
1647 set are actually used by the optimized function. Lay them out. */
1648 expand_used_vars_for_block (outer_block
, true);
1650 if (stack_vars_num
> 0)
1652 add_scope_conflicts ();
1654 /* If stack protection is enabled, we don't share space between
1655 vulnerable data and non-vulnerable data. */
1656 if (flag_stack_protect
)
1657 add_stack_protection_conflicts ();
1659 /* Now that we have collected all stack variables, and have computed a
1660 minimal interference graph, attempt to save some stack space. */
1661 partition_stack_vars ();
1663 dump_stack_var_partition ();
1666 /* There are several conditions under which we should create a
1667 stack guard: protect-all, alloca used, protected decls present. */
1668 if (flag_stack_protect
== 2
1669 || (flag_stack_protect
1670 && (cfun
->calls_alloca
|| has_protected_decls
)))
1671 create_stack_guard ();
1673 /* Assign rtl to each variable based on these partitions. */
1674 if (stack_vars_num
> 0)
1676 struct stack_vars_data data
;
1678 data
.asan_vec
= vNULL
;
1679 data
.asan_decl_vec
= vNULL
;
1681 /* Reorder decls to be protected by iterating over the variables
1682 array multiple times, and allocating out of each phase in turn. */
1683 /* ??? We could probably integrate this into the qsort we did
1684 earlier, such that we naturally see these variables first,
1685 and thus naturally allocate things in the right order. */
1686 if (has_protected_decls
)
1688 /* Phase 1 contains only character arrays. */
1689 expand_stack_vars (stack_protect_decl_phase_1
, &data
);
1691 /* Phase 2 contains other kinds of arrays. */
1692 if (flag_stack_protect
== 2)
1693 expand_stack_vars (stack_protect_decl_phase_2
, &data
);
1697 /* Phase 3, any partitions that need asan protection
1698 in addition to phase 1 and 2. */
1699 expand_stack_vars (asan_decl_phase_3
, &data
);
1701 if (!data
.asan_vec
.is_empty ())
1703 HOST_WIDE_INT prev_offset
= frame_offset
;
1704 HOST_WIDE_INT offset
1705 = alloc_stack_frame_space (ASAN_RED_ZONE_SIZE
,
1706 ASAN_RED_ZONE_SIZE
);
1707 data
.asan_vec
.safe_push (prev_offset
);
1708 data
.asan_vec
.safe_push (offset
);
1711 = asan_emit_stack_protection (virtual_stack_vars_rtx
,
1712 data
.asan_vec
.address (),
1713 data
.asan_decl_vec
. address(),
1714 data
.asan_vec
.length ());
1717 expand_stack_vars (NULL
, &data
);
1719 data
.asan_vec
.release ();
1720 data
.asan_decl_vec
.release ();
1723 fini_vars_expansion ();
1725 /* If there were any artificial non-ignored vars without rtl
1726 found earlier, see if deferred stack allocation hasn't assigned
1728 FOR_EACH_VEC_ELT_REVERSE (maybe_local_decls
, i
, var
)
1730 rtx rtl
= DECL_RTL_IF_SET (var
);
1732 /* Keep artificial non-ignored vars in cfun->local_decls
1733 chain until instantiate_decls. */
1734 if (rtl
&& (MEM_P (rtl
) || GET_CODE (rtl
) == CONCAT
))
1735 add_local_decl (cfun
, var
);
1737 maybe_local_decls
.release ();
1739 /* If the target requires that FRAME_OFFSET be aligned, do it. */
1740 if (STACK_ALIGNMENT_NEEDED
)
1742 HOST_WIDE_INT align
= PREFERRED_STACK_BOUNDARY
/ BITS_PER_UNIT
;
1743 if (!FRAME_GROWS_DOWNWARD
)
1744 frame_offset
+= align
- 1;
1745 frame_offset
&= -align
;
1752 /* If we need to produce a detailed dump, print the tree representation
1753 for STMT to the dump file. SINCE is the last RTX after which the RTL
1754 generated for STMT should have been appended. */
1757 maybe_dump_rtl_for_gimple_stmt (gimple stmt
, rtx since
)
1759 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1761 fprintf (dump_file
, "\n;; ");
1762 print_gimple_stmt (dump_file
, stmt
, 0,
1763 TDF_SLIM
| (dump_flags
& TDF_LINENO
));
1764 fprintf (dump_file
, "\n");
1766 print_rtl (dump_file
, since
? NEXT_INSN (since
) : since
);
1770 /* Maps the blocks that do not contain tree labels to rtx labels. */
1772 static struct pointer_map_t
*lab_rtx_for_bb
;
1774 /* Returns the label_rtx expression for a label starting basic block BB. */
1777 label_rtx_for_bb (basic_block bb ATTRIBUTE_UNUSED
)
1779 gimple_stmt_iterator gsi
;
1784 if (bb
->flags
& BB_RTL
)
1785 return block_label (bb
);
1787 elt
= pointer_map_contains (lab_rtx_for_bb
, bb
);
1791 /* Find the tree label if it is present. */
1793 for (gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
1795 lab_stmt
= gsi_stmt (gsi
);
1796 if (gimple_code (lab_stmt
) != GIMPLE_LABEL
)
1799 lab
= gimple_label_label (lab_stmt
);
1800 if (DECL_NONLOCAL (lab
))
1803 return label_rtx (lab
);
1806 elt
= pointer_map_insert (lab_rtx_for_bb
, bb
);
1807 *elt
= gen_label_rtx ();
1812 /* A subroutine of expand_gimple_cond. Given E, a fallthrough edge
1813 of a basic block where we just expanded the conditional at the end,
1814 possibly clean up the CFG and instruction sequence. LAST is the
1815 last instruction before the just emitted jump sequence. */
1818 maybe_cleanup_end_of_block (edge e
, rtx last
)
1820 /* Special case: when jumpif decides that the condition is
1821 trivial it emits an unconditional jump (and the necessary
1822 barrier). But we still have two edges, the fallthru one is
1823 wrong. purge_dead_edges would clean this up later. Unfortunately
1824 we have to insert insns (and split edges) before
1825 find_many_sub_basic_blocks and hence before purge_dead_edges.
1826 But splitting edges might create new blocks which depend on the
1827 fact that if there are two edges there's no barrier. So the
1828 barrier would get lost and verify_flow_info would ICE. Instead
1829 of auditing all edge splitters to care for the barrier (which
1830 normally isn't there in a cleaned CFG), fix it here. */
1831 if (BARRIER_P (get_last_insn ()))
1835 /* Now, we have a single successor block, if we have insns to
1836 insert on the remaining edge we potentially will insert
1837 it at the end of this block (if the dest block isn't feasible)
1838 in order to avoid splitting the edge. This insertion will take
1839 place in front of the last jump. But we might have emitted
1840 multiple jumps (conditional and one unconditional) to the
1841 same destination. Inserting in front of the last one then
1842 is a problem. See PR 40021. We fix this by deleting all
1843 jumps except the last unconditional one. */
1844 insn
= PREV_INSN (get_last_insn ());
1845 /* Make sure we have an unconditional jump. Otherwise we're
1847 gcc_assert (JUMP_P (insn
) && !any_condjump_p (insn
));
1848 for (insn
= PREV_INSN (insn
); insn
!= last
;)
1850 insn
= PREV_INSN (insn
);
1851 if (JUMP_P (NEXT_INSN (insn
)))
1853 if (!any_condjump_p (NEXT_INSN (insn
)))
1855 gcc_assert (BARRIER_P (NEXT_INSN (NEXT_INSN (insn
))));
1856 delete_insn (NEXT_INSN (NEXT_INSN (insn
)));
1858 delete_insn (NEXT_INSN (insn
));
1864 /* A subroutine of expand_gimple_basic_block. Expand one GIMPLE_COND.
1865 Returns a new basic block if we've terminated the current basic
1866 block and created a new one. */
1869 expand_gimple_cond (basic_block bb
, gimple stmt
)
1871 basic_block new_bb
, dest
;
1876 enum tree_code code
;
1879 code
= gimple_cond_code (stmt
);
1880 op0
= gimple_cond_lhs (stmt
);
1881 op1
= gimple_cond_rhs (stmt
);
1882 /* We're sometimes presented with such code:
1886 This would expand to two comparisons which then later might
1887 be cleaned up by combine. But some pattern matchers like if-conversion
1888 work better when there's only one compare, so make up for this
1889 here as special exception if TER would have made the same change. */
1890 if (gimple_cond_single_var_p (stmt
)
1892 && TREE_CODE (op0
) == SSA_NAME
1893 && bitmap_bit_p (SA
.values
, SSA_NAME_VERSION (op0
)))
1895 gimple second
= SSA_NAME_DEF_STMT (op0
);
1896 if (gimple_code (second
) == GIMPLE_ASSIGN
)
1898 enum tree_code code2
= gimple_assign_rhs_code (second
);
1899 if (TREE_CODE_CLASS (code2
) == tcc_comparison
)
1902 op0
= gimple_assign_rhs1 (second
);
1903 op1
= gimple_assign_rhs2 (second
);
1905 /* If jumps are cheap turn some more codes into
1907 else if (BRANCH_COST (optimize_insn_for_speed_p (), false) < 4)
1909 if ((code2
== BIT_AND_EXPR
1910 && TYPE_PRECISION (TREE_TYPE (op0
)) == 1
1911 && TREE_CODE (gimple_assign_rhs2 (second
)) != INTEGER_CST
)
1912 || code2
== TRUTH_AND_EXPR
)
1914 code
= TRUTH_ANDIF_EXPR
;
1915 op0
= gimple_assign_rhs1 (second
);
1916 op1
= gimple_assign_rhs2 (second
);
1918 else if (code2
== BIT_IOR_EXPR
|| code2
== TRUTH_OR_EXPR
)
1920 code
= TRUTH_ORIF_EXPR
;
1921 op0
= gimple_assign_rhs1 (second
);
1922 op1
= gimple_assign_rhs2 (second
);
1928 last2
= last
= get_last_insn ();
1930 extract_true_false_edges_from_block (bb
, &true_edge
, &false_edge
);
1931 set_curr_insn_location (gimple_location (stmt
));
1933 /* These flags have no purpose in RTL land. */
1934 true_edge
->flags
&= ~EDGE_TRUE_VALUE
;
1935 false_edge
->flags
&= ~EDGE_FALSE_VALUE
;
1937 /* We can either have a pure conditional jump with one fallthru edge or
1938 two-way jump that needs to be decomposed into two basic blocks. */
1939 if (false_edge
->dest
== bb
->next_bb
)
1941 jumpif_1 (code
, op0
, op1
, label_rtx_for_bb (true_edge
->dest
),
1942 true_edge
->probability
);
1943 maybe_dump_rtl_for_gimple_stmt (stmt
, last
);
1944 if (true_edge
->goto_locus
!= UNKNOWN_LOCATION
)
1945 set_curr_insn_location (true_edge
->goto_locus
);
1946 false_edge
->flags
|= EDGE_FALLTHRU
;
1947 maybe_cleanup_end_of_block (false_edge
, last
);
1950 if (true_edge
->dest
== bb
->next_bb
)
1952 jumpifnot_1 (code
, op0
, op1
, label_rtx_for_bb (false_edge
->dest
),
1953 false_edge
->probability
);
1954 maybe_dump_rtl_for_gimple_stmt (stmt
, last
);
1955 if (false_edge
->goto_locus
!= UNKNOWN_LOCATION
)
1956 set_curr_insn_location (false_edge
->goto_locus
);
1957 true_edge
->flags
|= EDGE_FALLTHRU
;
1958 maybe_cleanup_end_of_block (true_edge
, last
);
1962 jumpif_1 (code
, op0
, op1
, label_rtx_for_bb (true_edge
->dest
),
1963 true_edge
->probability
);
1964 last
= get_last_insn ();
1965 if (false_edge
->goto_locus
!= UNKNOWN_LOCATION
)
1966 set_curr_insn_location (false_edge
->goto_locus
);
1967 emit_jump (label_rtx_for_bb (false_edge
->dest
));
1970 if (BARRIER_P (BB_END (bb
)))
1971 BB_END (bb
) = PREV_INSN (BB_END (bb
));
1972 update_bb_for_insn (bb
);
1974 new_bb
= create_basic_block (NEXT_INSN (last
), get_last_insn (), bb
);
1975 dest
= false_edge
->dest
;
1976 redirect_edge_succ (false_edge
, new_bb
);
1977 false_edge
->flags
|= EDGE_FALLTHRU
;
1978 new_bb
->count
= false_edge
->count
;
1979 new_bb
->frequency
= EDGE_FREQUENCY (false_edge
);
1980 if (current_loops
&& bb
->loop_father
)
1981 add_bb_to_loop (new_bb
, bb
->loop_father
);
1982 new_edge
= make_edge (new_bb
, dest
, 0);
1983 new_edge
->probability
= REG_BR_PROB_BASE
;
1984 new_edge
->count
= new_bb
->count
;
1985 if (BARRIER_P (BB_END (new_bb
)))
1986 BB_END (new_bb
) = PREV_INSN (BB_END (new_bb
));
1987 update_bb_for_insn (new_bb
);
1989 maybe_dump_rtl_for_gimple_stmt (stmt
, last2
);
1991 if (true_edge
->goto_locus
!= UNKNOWN_LOCATION
)
1993 set_curr_insn_location (true_edge
->goto_locus
);
1994 true_edge
->goto_locus
= curr_insn_location ();
2000 /* Mark all calls that can have a transaction restart. */
2003 mark_transaction_restart_calls (gimple stmt
)
2005 struct tm_restart_node dummy
;
2008 if (!cfun
->gimple_df
->tm_restart
)
2012 slot
= htab_find_slot (cfun
->gimple_df
->tm_restart
, &dummy
, NO_INSERT
);
2015 struct tm_restart_node
*n
= (struct tm_restart_node
*) *slot
;
2016 tree list
= n
->label_or_list
;
2019 for (insn
= next_real_insn (get_last_insn ());
2021 insn
= next_real_insn (insn
))
2024 if (TREE_CODE (list
) == LABEL_DECL
)
2025 add_reg_note (insn
, REG_TM
, label_rtx (list
));
2027 for (; list
; list
= TREE_CHAIN (list
))
2028 add_reg_note (insn
, REG_TM
, label_rtx (TREE_VALUE (list
)));
2032 /* A subroutine of expand_gimple_stmt_1, expanding one GIMPLE_CALL
2036 expand_call_stmt (gimple stmt
)
2038 tree exp
, decl
, lhs
;
2042 if (gimple_call_internal_p (stmt
))
2044 expand_internal_call (stmt
);
2048 exp
= build_vl_exp (CALL_EXPR
, gimple_call_num_args (stmt
) + 3);
2050 CALL_EXPR_FN (exp
) = gimple_call_fn (stmt
);
2051 decl
= gimple_call_fndecl (stmt
);
2052 builtin_p
= decl
&& DECL_BUILT_IN (decl
);
2054 /* If this is not a builtin function, the function type through which the
2055 call is made may be different from the type of the function. */
2058 = fold_convert (build_pointer_type (gimple_call_fntype (stmt
)),
2059 CALL_EXPR_FN (exp
));
2061 TREE_TYPE (exp
) = gimple_call_return_type (stmt
);
2062 CALL_EXPR_STATIC_CHAIN (exp
) = gimple_call_chain (stmt
);
2064 for (i
= 0; i
< gimple_call_num_args (stmt
); i
++)
2066 tree arg
= gimple_call_arg (stmt
, i
);
2068 /* TER addresses into arguments of builtin functions so we have a
2069 chance to infer more correct alignment information. See PR39954. */
2071 && TREE_CODE (arg
) == SSA_NAME
2072 && (def
= get_gimple_for_ssa_name (arg
))
2073 && gimple_assign_rhs_code (def
) == ADDR_EXPR
)
2074 arg
= gimple_assign_rhs1 (def
);
2075 CALL_EXPR_ARG (exp
, i
) = arg
;
2078 if (gimple_has_side_effects (stmt
))
2079 TREE_SIDE_EFFECTS (exp
) = 1;
2081 if (gimple_call_nothrow_p (stmt
))
2082 TREE_NOTHROW (exp
) = 1;
2084 CALL_EXPR_TAILCALL (exp
) = gimple_call_tail_p (stmt
);
2085 CALL_EXPR_RETURN_SLOT_OPT (exp
) = gimple_call_return_slot_opt_p (stmt
);
2087 && DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
2088 && (DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA
2089 || DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA_WITH_ALIGN
))
2090 CALL_ALLOCA_FOR_VAR_P (exp
) = gimple_call_alloca_for_var_p (stmt
);
2092 CALL_FROM_THUNK_P (exp
) = gimple_call_from_thunk_p (stmt
);
2093 CALL_EXPR_VA_ARG_PACK (exp
) = gimple_call_va_arg_pack_p (stmt
);
2094 SET_EXPR_LOCATION (exp
, gimple_location (stmt
));
2096 /* Ensure RTL is created for debug args. */
2097 if (decl
&& DECL_HAS_DEBUG_ARGS_P (decl
))
2099 vec
<tree
, va_gc
> **debug_args
= decl_debug_args_lookup (decl
);
2104 for (ix
= 1; (*debug_args
)->iterate (ix
, &dtemp
); ix
+= 2)
2106 gcc_assert (TREE_CODE (dtemp
) == DEBUG_EXPR_DECL
);
2107 expand_debug_expr (dtemp
);
2111 lhs
= gimple_call_lhs (stmt
);
2113 expand_assignment (lhs
, exp
, false);
2115 expand_expr_real_1 (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
, NULL
);
2117 mark_transaction_restart_calls (stmt
);
2120 /* A subroutine of expand_gimple_stmt, expanding one gimple statement
2121 STMT that doesn't require special handling for outgoing edges. That
2122 is no tailcalls and no GIMPLE_COND. */
2125 expand_gimple_stmt_1 (gimple stmt
)
2129 set_curr_insn_location (gimple_location (stmt
));
2131 switch (gimple_code (stmt
))
2134 op0
= gimple_goto_dest (stmt
);
2135 if (TREE_CODE (op0
) == LABEL_DECL
)
2138 expand_computed_goto (op0
);
2141 expand_label (gimple_label_label (stmt
));
2144 case GIMPLE_PREDICT
:
2150 expand_asm_stmt (stmt
);
2153 expand_call_stmt (stmt
);
2157 op0
= gimple_return_retval (stmt
);
2159 if (op0
&& op0
!= error_mark_node
)
2161 tree result
= DECL_RESULT (current_function_decl
);
2163 /* If we are not returning the current function's RESULT_DECL,
2164 build an assignment to it. */
2167 /* I believe that a function's RESULT_DECL is unique. */
2168 gcc_assert (TREE_CODE (op0
) != RESULT_DECL
);
2170 /* ??? We'd like to use simply expand_assignment here,
2171 but this fails if the value is of BLKmode but the return
2172 decl is a register. expand_return has special handling
2173 for this combination, which eventually should move
2174 to common code. See comments there. Until then, let's
2175 build a modify expression :-/ */
2176 op0
= build2 (MODIFY_EXPR
, TREE_TYPE (result
),
2181 expand_null_return ();
2183 expand_return (op0
);
2188 tree lhs
= gimple_assign_lhs (stmt
);
2190 /* Tree expand used to fiddle with |= and &= of two bitfield
2191 COMPONENT_REFs here. This can't happen with gimple, the LHS
2192 of binary assigns must be a gimple reg. */
2194 if (TREE_CODE (lhs
) != SSA_NAME
2195 || get_gimple_rhs_class (gimple_expr_code (stmt
))
2196 == GIMPLE_SINGLE_RHS
)
2198 tree rhs
= gimple_assign_rhs1 (stmt
);
2199 gcc_assert (get_gimple_rhs_class (gimple_expr_code (stmt
))
2200 == GIMPLE_SINGLE_RHS
);
2201 if (gimple_has_location (stmt
) && CAN_HAVE_LOCATION_P (rhs
))
2202 SET_EXPR_LOCATION (rhs
, gimple_location (stmt
));
2203 if (TREE_CLOBBER_P (rhs
))
2204 /* This is a clobber to mark the going out of scope for
2208 expand_assignment (lhs
, rhs
,
2209 gimple_assign_nontemporal_move_p (stmt
));
2214 bool nontemporal
= gimple_assign_nontemporal_move_p (stmt
);
2215 struct separate_ops ops
;
2216 bool promoted
= false;
2218 target
= expand_expr (lhs
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
2219 if (GET_CODE (target
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (target
))
2222 ops
.code
= gimple_assign_rhs_code (stmt
);
2223 ops
.type
= TREE_TYPE (lhs
);
2224 switch (get_gimple_rhs_class (gimple_expr_code (stmt
)))
2226 case GIMPLE_TERNARY_RHS
:
2227 ops
.op2
= gimple_assign_rhs3 (stmt
);
2229 case GIMPLE_BINARY_RHS
:
2230 ops
.op1
= gimple_assign_rhs2 (stmt
);
2232 case GIMPLE_UNARY_RHS
:
2233 ops
.op0
= gimple_assign_rhs1 (stmt
);
2238 ops
.location
= gimple_location (stmt
);
2240 /* If we want to use a nontemporal store, force the value to
2241 register first. If we store into a promoted register,
2242 don't directly expand to target. */
2243 temp
= nontemporal
|| promoted
? NULL_RTX
: target
;
2244 temp
= expand_expr_real_2 (&ops
, temp
, GET_MODE (target
),
2251 int unsignedp
= SUBREG_PROMOTED_UNSIGNED_P (target
);
2252 /* If TEMP is a VOIDmode constant, use convert_modes to make
2253 sure that we properly convert it. */
2254 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
)
2256 temp
= convert_modes (GET_MODE (target
),
2257 TYPE_MODE (ops
.type
),
2259 temp
= convert_modes (GET_MODE (SUBREG_REG (target
)),
2260 GET_MODE (target
), temp
, unsignedp
);
2263 convert_move (SUBREG_REG (target
), temp
, unsignedp
);
2265 else if (nontemporal
&& emit_storent_insn (target
, temp
))
2269 temp
= force_operand (temp
, target
);
2271 emit_move_insn (target
, temp
);
2282 /* Expand one gimple statement STMT and return the last RTL instruction
2283 before any of the newly generated ones.
2285 In addition to generating the necessary RTL instructions this also
2286 sets REG_EH_REGION notes if necessary and sets the current source
2287 location for diagnostics. */
2290 expand_gimple_stmt (gimple stmt
)
2292 location_t saved_location
= input_location
;
2293 rtx last
= get_last_insn ();
2298 /* We need to save and restore the current source location so that errors
2299 discovered during expansion are emitted with the right location. But
2300 it would be better if the diagnostic routines used the source location
2301 embedded in the tree nodes rather than globals. */
2302 if (gimple_has_location (stmt
))
2303 input_location
= gimple_location (stmt
);
2305 expand_gimple_stmt_1 (stmt
);
2307 /* Free any temporaries used to evaluate this statement. */
2310 input_location
= saved_location
;
2312 /* Mark all insns that may trap. */
2313 lp_nr
= lookup_stmt_eh_lp (stmt
);
2317 for (insn
= next_real_insn (last
); insn
;
2318 insn
= next_real_insn (insn
))
2320 if (! find_reg_note (insn
, REG_EH_REGION
, NULL_RTX
)
2321 /* If we want exceptions for non-call insns, any
2322 may_trap_p instruction may throw. */
2323 && GET_CODE (PATTERN (insn
)) != CLOBBER
2324 && GET_CODE (PATTERN (insn
)) != USE
2325 && insn_could_throw_p (insn
))
2326 make_reg_eh_region_note (insn
, 0, lp_nr
);
2333 /* A subroutine of expand_gimple_basic_block. Expand one GIMPLE_CALL
2334 that has CALL_EXPR_TAILCALL set. Returns non-null if we actually
2335 generated a tail call (something that might be denied by the ABI
2336 rules governing the call; see calls.c).
2338 Sets CAN_FALLTHRU if we generated a *conditional* tail call, and
2339 can still reach the rest of BB. The case here is __builtin_sqrt,
2340 where the NaN result goes through the external function (with a
2341 tailcall) and the normal result happens via a sqrt instruction. */
2344 expand_gimple_tailcall (basic_block bb
, gimple stmt
, bool *can_fallthru
)
2352 last2
= last
= expand_gimple_stmt (stmt
);
2354 for (last
= NEXT_INSN (last
); last
; last
= NEXT_INSN (last
))
2355 if (CALL_P (last
) && SIBLING_CALL_P (last
))
2358 maybe_dump_rtl_for_gimple_stmt (stmt
, last2
);
2360 *can_fallthru
= true;
2364 /* ??? Wouldn't it be better to just reset any pending stack adjust?
2365 Any instructions emitted here are about to be deleted. */
2366 do_pending_stack_adjust ();
2368 /* Remove any non-eh, non-abnormal edges that don't go to exit. */
2369 /* ??? I.e. the fallthrough edge. HOWEVER! If there were to be
2370 EH or abnormal edges, we shouldn't have created a tail call in
2371 the first place. So it seems to me we should just be removing
2372 all edges here, or redirecting the existing fallthru edge to
2378 for (ei
= ei_start (bb
->succs
); (e
= ei_safe_edge (ei
)); )
2380 if (!(e
->flags
& (EDGE_ABNORMAL
| EDGE_EH
)))
2382 if (e
->dest
!= EXIT_BLOCK_PTR
)
2384 e
->dest
->count
-= e
->count
;
2385 e
->dest
->frequency
-= EDGE_FREQUENCY (e
);
2386 if (e
->dest
->count
< 0)
2388 if (e
->dest
->frequency
< 0)
2389 e
->dest
->frequency
= 0;
2392 probability
+= e
->probability
;
2399 /* This is somewhat ugly: the call_expr expander often emits instructions
2400 after the sibcall (to perform the function return). These confuse the
2401 find_many_sub_basic_blocks code, so we need to get rid of these. */
2402 last
= NEXT_INSN (last
);
2403 gcc_assert (BARRIER_P (last
));
2405 *can_fallthru
= false;
2406 while (NEXT_INSN (last
))
2408 /* For instance an sqrt builtin expander expands if with
2409 sibcall in the then and label for `else`. */
2410 if (LABEL_P (NEXT_INSN (last
)))
2412 *can_fallthru
= true;
2415 delete_insn (NEXT_INSN (last
));
2418 e
= make_edge (bb
, EXIT_BLOCK_PTR
, EDGE_ABNORMAL
| EDGE_SIBCALL
);
2419 e
->probability
+= probability
;
2422 update_bb_for_insn (bb
);
2424 if (NEXT_INSN (last
))
2426 bb
= create_basic_block (NEXT_INSN (last
), get_last_insn (), bb
);
2429 if (BARRIER_P (last
))
2430 BB_END (bb
) = PREV_INSN (last
);
2433 maybe_dump_rtl_for_gimple_stmt (stmt
, last2
);
2438 /* Return the difference between the floor and the truncated result of
2439 a signed division by OP1 with remainder MOD. */
2441 floor_sdiv_adjust (enum machine_mode mode
, rtx mod
, rtx op1
)
2443 /* (mod != 0 ? (op1 / mod < 0 ? -1 : 0) : 0) */
2444 return gen_rtx_IF_THEN_ELSE
2445 (mode
, gen_rtx_NE (BImode
, mod
, const0_rtx
),
2446 gen_rtx_IF_THEN_ELSE
2447 (mode
, gen_rtx_LT (BImode
,
2448 gen_rtx_DIV (mode
, op1
, mod
),
2450 constm1_rtx
, const0_rtx
),
2454 /* Return the difference between the ceil and the truncated result of
2455 a signed division by OP1 with remainder MOD. */
2457 ceil_sdiv_adjust (enum machine_mode mode
, rtx mod
, rtx op1
)
2459 /* (mod != 0 ? (op1 / mod > 0 ? 1 : 0) : 0) */
2460 return gen_rtx_IF_THEN_ELSE
2461 (mode
, gen_rtx_NE (BImode
, mod
, const0_rtx
),
2462 gen_rtx_IF_THEN_ELSE
2463 (mode
, gen_rtx_GT (BImode
,
2464 gen_rtx_DIV (mode
, op1
, mod
),
2466 const1_rtx
, const0_rtx
),
2470 /* Return the difference between the ceil and the truncated result of
2471 an unsigned division by OP1 with remainder MOD. */
2473 ceil_udiv_adjust (enum machine_mode mode
, rtx mod
, rtx op1 ATTRIBUTE_UNUSED
)
2475 /* (mod != 0 ? 1 : 0) */
2476 return gen_rtx_IF_THEN_ELSE
2477 (mode
, gen_rtx_NE (BImode
, mod
, const0_rtx
),
2478 const1_rtx
, const0_rtx
);
2481 /* Return the difference between the rounded and the truncated result
2482 of a signed division by OP1 with remainder MOD. Halfway cases are
2483 rounded away from zero, rather than to the nearest even number. */
2485 round_sdiv_adjust (enum machine_mode mode
, rtx mod
, rtx op1
)
2487 /* (abs (mod) >= abs (op1) - abs (mod)
2488 ? (op1 / mod > 0 ? 1 : -1)
2490 return gen_rtx_IF_THEN_ELSE
2491 (mode
, gen_rtx_GE (BImode
, gen_rtx_ABS (mode
, mod
),
2492 gen_rtx_MINUS (mode
,
2493 gen_rtx_ABS (mode
, op1
),
2494 gen_rtx_ABS (mode
, mod
))),
2495 gen_rtx_IF_THEN_ELSE
2496 (mode
, gen_rtx_GT (BImode
,
2497 gen_rtx_DIV (mode
, op1
, mod
),
2499 const1_rtx
, constm1_rtx
),
2503 /* Return the difference between the rounded and the truncated result
2504 of a unsigned division by OP1 with remainder MOD. Halfway cases
2505 are rounded away from zero, rather than to the nearest even
2508 round_udiv_adjust (enum machine_mode mode
, rtx mod
, rtx op1
)
2510 /* (mod >= op1 - mod ? 1 : 0) */
2511 return gen_rtx_IF_THEN_ELSE
2512 (mode
, gen_rtx_GE (BImode
, mod
,
2513 gen_rtx_MINUS (mode
, op1
, mod
)),
2514 const1_rtx
, const0_rtx
);
2517 /* Convert X to MODE, that must be Pmode or ptr_mode, without emitting
2521 convert_debug_memory_address (enum machine_mode mode
, rtx x
,
2524 enum machine_mode xmode
= GET_MODE (x
);
2526 #ifndef POINTERS_EXTEND_UNSIGNED
2527 gcc_assert (mode
== Pmode
2528 || mode
== targetm
.addr_space
.address_mode (as
));
2529 gcc_assert (xmode
== mode
|| xmode
== VOIDmode
);
2533 gcc_assert (targetm
.addr_space
.valid_pointer_mode (mode
, as
));
2535 if (GET_MODE (x
) == mode
|| GET_MODE (x
) == VOIDmode
)
2538 if (GET_MODE_PRECISION (mode
) < GET_MODE_PRECISION (xmode
))
2539 x
= simplify_gen_subreg (mode
, x
, xmode
,
2540 subreg_lowpart_offset
2542 else if (POINTERS_EXTEND_UNSIGNED
> 0)
2543 x
= gen_rtx_ZERO_EXTEND (mode
, x
);
2544 else if (!POINTERS_EXTEND_UNSIGNED
)
2545 x
= gen_rtx_SIGN_EXTEND (mode
, x
);
2548 switch (GET_CODE (x
))
2551 if ((SUBREG_PROMOTED_VAR_P (x
)
2552 || (REG_P (SUBREG_REG (x
)) && REG_POINTER (SUBREG_REG (x
)))
2553 || (GET_CODE (SUBREG_REG (x
)) == PLUS
2554 && REG_P (XEXP (SUBREG_REG (x
), 0))
2555 && REG_POINTER (XEXP (SUBREG_REG (x
), 0))
2556 && CONST_INT_P (XEXP (SUBREG_REG (x
), 1))))
2557 && GET_MODE (SUBREG_REG (x
)) == mode
)
2558 return SUBREG_REG (x
);
2561 temp
= gen_rtx_LABEL_REF (mode
, XEXP (x
, 0));
2562 LABEL_REF_NONLOCAL_P (temp
) = LABEL_REF_NONLOCAL_P (x
);
2565 temp
= shallow_copy_rtx (x
);
2566 PUT_MODE (temp
, mode
);
2569 temp
= convert_debug_memory_address (mode
, XEXP (x
, 0), as
);
2571 temp
= gen_rtx_CONST (mode
, temp
);
2575 if (CONST_INT_P (XEXP (x
, 1)))
2577 temp
= convert_debug_memory_address (mode
, XEXP (x
, 0), as
);
2579 return gen_rtx_fmt_ee (GET_CODE (x
), mode
, temp
, XEXP (x
, 1));
2585 /* Don't know how to express ptr_extend as operation in debug info. */
2588 #endif /* POINTERS_EXTEND_UNSIGNED */
2593 /* Return an RTX equivalent to the value of the parameter DECL. */
2596 expand_debug_parm_decl (tree decl
)
2598 rtx incoming
= DECL_INCOMING_RTL (decl
);
2601 && GET_MODE (incoming
) != BLKmode
2602 && ((REG_P (incoming
) && HARD_REGISTER_P (incoming
))
2603 || (MEM_P (incoming
)
2604 && REG_P (XEXP (incoming
, 0))
2605 && HARD_REGISTER_P (XEXP (incoming
, 0)))))
2607 rtx rtl
= gen_rtx_ENTRY_VALUE (GET_MODE (incoming
));
2609 #ifdef HAVE_window_save
2610 /* DECL_INCOMING_RTL uses the INCOMING_REGNO of parameter registers.
2611 If the target machine has an explicit window save instruction, the
2612 actual entry value is the corresponding OUTGOING_REGNO instead. */
2613 if (REG_P (incoming
)
2614 && OUTGOING_REGNO (REGNO (incoming
)) != REGNO (incoming
))
2616 = gen_rtx_REG_offset (incoming
, GET_MODE (incoming
),
2617 OUTGOING_REGNO (REGNO (incoming
)), 0);
2618 else if (MEM_P (incoming
))
2620 rtx reg
= XEXP (incoming
, 0);
2621 if (OUTGOING_REGNO (REGNO (reg
)) != REGNO (reg
))
2623 reg
= gen_raw_REG (GET_MODE (reg
), OUTGOING_REGNO (REGNO (reg
)));
2624 incoming
= replace_equiv_address_nv (incoming
, reg
);
2629 ENTRY_VALUE_EXP (rtl
) = incoming
;
2634 && GET_MODE (incoming
) != BLKmode
2635 && !TREE_ADDRESSABLE (decl
)
2637 && (XEXP (incoming
, 0) == virtual_incoming_args_rtx
2638 || (GET_CODE (XEXP (incoming
, 0)) == PLUS
2639 && XEXP (XEXP (incoming
, 0), 0) == virtual_incoming_args_rtx
2640 && CONST_INT_P (XEXP (XEXP (incoming
, 0), 1)))))
2646 /* Return an RTX equivalent to the value of the tree expression EXP. */
2649 expand_debug_expr (tree exp
)
2651 rtx op0
= NULL_RTX
, op1
= NULL_RTX
, op2
= NULL_RTX
;
2652 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (exp
));
2653 enum machine_mode inner_mode
= VOIDmode
;
2654 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (exp
));
2657 switch (TREE_CODE_CLASS (TREE_CODE (exp
)))
2659 case tcc_expression
:
2660 switch (TREE_CODE (exp
))
2664 case WIDEN_MULT_PLUS_EXPR
:
2665 case WIDEN_MULT_MINUS_EXPR
:
2669 case TRUTH_ANDIF_EXPR
:
2670 case TRUTH_ORIF_EXPR
:
2671 case TRUTH_AND_EXPR
:
2673 case TRUTH_XOR_EXPR
:
2676 case TRUTH_NOT_EXPR
:
2685 op2
= expand_debug_expr (TREE_OPERAND (exp
, 2));
2692 case tcc_comparison
:
2693 op1
= expand_debug_expr (TREE_OPERAND (exp
, 1));
2700 inner_mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
2701 op0
= expand_debug_expr (TREE_OPERAND (exp
, 0));
2711 case tcc_exceptional
:
2712 case tcc_declaration
:
2718 switch (TREE_CODE (exp
))
2721 if (!lookup_constant_def (exp
))
2723 if (strlen (TREE_STRING_POINTER (exp
)) + 1
2724 != (size_t) TREE_STRING_LENGTH (exp
))
2726 op0
= gen_rtx_CONST_STRING (Pmode
, TREE_STRING_POINTER (exp
));
2727 op0
= gen_rtx_MEM (BLKmode
, op0
);
2728 set_mem_attributes (op0
, exp
, 0);
2731 /* Fall through... */
2736 op0
= expand_expr (exp
, NULL_RTX
, mode
, EXPAND_INITIALIZER
);
2740 gcc_assert (COMPLEX_MODE_P (mode
));
2741 op0
= expand_debug_expr (TREE_REALPART (exp
));
2742 op1
= expand_debug_expr (TREE_IMAGPART (exp
));
2743 return gen_rtx_CONCAT (mode
, op0
, op1
);
2745 case DEBUG_EXPR_DECL
:
2746 op0
= DECL_RTL_IF_SET (exp
);
2751 op0
= gen_rtx_DEBUG_EXPR (mode
);
2752 DEBUG_EXPR_TREE_DECL (op0
) = exp
;
2753 SET_DECL_RTL (exp
, op0
);
2763 op0
= DECL_RTL_IF_SET (exp
);
2765 /* This decl was probably optimized away. */
2768 if (TREE_CODE (exp
) != VAR_DECL
2769 || DECL_EXTERNAL (exp
)
2770 || !TREE_STATIC (exp
)
2772 || DECL_HARD_REGISTER (exp
)
2773 || DECL_IN_CONSTANT_POOL (exp
)
2774 || mode
== VOIDmode
)
2777 op0
= make_decl_rtl_for_debug (exp
);
2779 || GET_CODE (XEXP (op0
, 0)) != SYMBOL_REF
2780 || SYMBOL_REF_DECL (XEXP (op0
, 0)) != exp
)
2784 op0
= copy_rtx (op0
);
2786 if (GET_MODE (op0
) == BLKmode
2787 /* If op0 is not BLKmode, but BLKmode is, adjust_mode
2788 below would ICE. While it is likely a FE bug,
2789 try to be robust here. See PR43166. */
2791 || (mode
== VOIDmode
&& GET_MODE (op0
) != VOIDmode
))
2793 gcc_assert (MEM_P (op0
));
2794 op0
= adjust_address_nv (op0
, mode
, 0);
2805 inner_mode
= GET_MODE (op0
);
2807 if (mode
== inner_mode
)
2810 if (inner_mode
== VOIDmode
)
2812 if (TREE_CODE (exp
) == SSA_NAME
)
2813 inner_mode
= TYPE_MODE (TREE_TYPE (exp
));
2815 inner_mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
2816 if (mode
== inner_mode
)
2820 if (FLOAT_MODE_P (mode
) && FLOAT_MODE_P (inner_mode
))
2822 if (GET_MODE_BITSIZE (mode
) == GET_MODE_BITSIZE (inner_mode
))
2823 op0
= simplify_gen_subreg (mode
, op0
, inner_mode
, 0);
2824 else if (GET_MODE_BITSIZE (mode
) < GET_MODE_BITSIZE (inner_mode
))
2825 op0
= simplify_gen_unary (FLOAT_TRUNCATE
, mode
, op0
, inner_mode
);
2827 op0
= simplify_gen_unary (FLOAT_EXTEND
, mode
, op0
, inner_mode
);
2829 else if (FLOAT_MODE_P (mode
))
2831 gcc_assert (TREE_CODE (exp
) != SSA_NAME
);
2832 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
, 0))))
2833 op0
= simplify_gen_unary (UNSIGNED_FLOAT
, mode
, op0
, inner_mode
);
2835 op0
= simplify_gen_unary (FLOAT
, mode
, op0
, inner_mode
);
2837 else if (FLOAT_MODE_P (inner_mode
))
2840 op0
= simplify_gen_unary (UNSIGNED_FIX
, mode
, op0
, inner_mode
);
2842 op0
= simplify_gen_unary (FIX
, mode
, op0
, inner_mode
);
2844 else if (CONSTANT_P (op0
)
2845 || GET_MODE_PRECISION (mode
) <= GET_MODE_PRECISION (inner_mode
))
2846 op0
= simplify_gen_subreg (mode
, op0
, inner_mode
,
2847 subreg_lowpart_offset (mode
,
2849 else if (TREE_CODE_CLASS (TREE_CODE (exp
)) == tcc_unary
2850 ? TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
, 0)))
2852 op0
= simplify_gen_unary (ZERO_EXTEND
, mode
, op0
, inner_mode
);
2854 op0
= simplify_gen_unary (SIGN_EXTEND
, mode
, op0
, inner_mode
);
2860 if (!is_gimple_mem_ref_addr (TREE_OPERAND (exp
, 0)))
2862 tree newexp
= fold_binary (MEM_REF
, TREE_TYPE (exp
),
2863 TREE_OPERAND (exp
, 0),
2864 TREE_OPERAND (exp
, 1));
2866 return expand_debug_expr (newexp
);
2870 inner_mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
2871 op0
= expand_debug_expr (TREE_OPERAND (exp
, 0));
2875 if (TREE_CODE (exp
) == MEM_REF
)
2877 if (GET_CODE (op0
) == DEBUG_IMPLICIT_PTR
2878 || (GET_CODE (op0
) == PLUS
2879 && GET_CODE (XEXP (op0
, 0)) == DEBUG_IMPLICIT_PTR
))
2880 /* (mem (debug_implicit_ptr)) might confuse aliasing.
2881 Instead just use get_inner_reference. */
2884 op1
= expand_debug_expr (TREE_OPERAND (exp
, 1));
2885 if (!op1
|| !CONST_INT_P (op1
))
2888 op0
= plus_constant (inner_mode
, op0
, INTVAL (op1
));
2891 if (POINTER_TYPE_P (TREE_TYPE (exp
)))
2892 as
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)));
2894 as
= ADDR_SPACE_GENERIC
;
2896 op0
= convert_debug_memory_address (targetm
.addr_space
.address_mode (as
),
2898 if (op0
== NULL_RTX
)
2901 op0
= gen_rtx_MEM (mode
, op0
);
2902 set_mem_attributes (op0
, exp
, 0);
2903 if (TREE_CODE (exp
) == MEM_REF
2904 && !is_gimple_mem_ref_addr (TREE_OPERAND (exp
, 0)))
2905 set_mem_expr (op0
, NULL_TREE
);
2906 set_mem_addr_space (op0
, as
);
2910 case TARGET_MEM_REF
:
2911 if (TREE_CODE (TMR_BASE (exp
)) == ADDR_EXPR
2912 && !DECL_RTL_SET_P (TREE_OPERAND (TMR_BASE (exp
), 0)))
2915 op0
= expand_debug_expr
2916 (tree_mem_ref_addr (build_pointer_type (TREE_TYPE (exp
)), exp
));
2920 if (POINTER_TYPE_P (TREE_TYPE (exp
)))
2921 as
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)));
2923 as
= ADDR_SPACE_GENERIC
;
2925 op0
= convert_debug_memory_address (targetm
.addr_space
.address_mode (as
),
2927 if (op0
== NULL_RTX
)
2930 op0
= gen_rtx_MEM (mode
, op0
);
2932 set_mem_attributes (op0
, exp
, 0);
2933 set_mem_addr_space (op0
, as
);
2939 case ARRAY_RANGE_REF
:
2944 case VIEW_CONVERT_EXPR
:
2946 enum machine_mode mode1
;
2947 HOST_WIDE_INT bitsize
, bitpos
;
2950 tree tem
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
2951 &mode1
, &unsignedp
, &volatilep
, false);
2957 orig_op0
= op0
= expand_debug_expr (tem
);
2964 enum machine_mode addrmode
, offmode
;
2969 op0
= XEXP (op0
, 0);
2970 addrmode
= GET_MODE (op0
);
2971 if (addrmode
== VOIDmode
)
2974 op1
= expand_debug_expr (offset
);
2978 offmode
= GET_MODE (op1
);
2979 if (offmode
== VOIDmode
)
2980 offmode
= TYPE_MODE (TREE_TYPE (offset
));
2982 if (addrmode
!= offmode
)
2983 op1
= simplify_gen_subreg (addrmode
, op1
, offmode
,
2984 subreg_lowpart_offset (addrmode
,
2987 /* Don't use offset_address here, we don't need a
2988 recognizable address, and we don't want to generate
2990 op0
= gen_rtx_MEM (mode
, simplify_gen_binary (PLUS
, addrmode
,
2996 if (mode1
== VOIDmode
)
2998 mode1
= smallest_mode_for_size (bitsize
, MODE_INT
);
2999 if (bitpos
>= BITS_PER_UNIT
)
3001 op0
= adjust_address_nv (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
3002 bitpos
%= BITS_PER_UNIT
;
3004 else if (bitpos
< 0)
3007 = (-bitpos
+ BITS_PER_UNIT
- 1) / BITS_PER_UNIT
;
3008 op0
= adjust_address_nv (op0
, mode1
, units
);
3009 bitpos
+= units
* BITS_PER_UNIT
;
3011 else if (bitpos
== 0 && bitsize
== GET_MODE_BITSIZE (mode
))
3012 op0
= adjust_address_nv (op0
, mode
, 0);
3013 else if (GET_MODE (op0
) != mode1
)
3014 op0
= adjust_address_nv (op0
, mode1
, 0);
3016 op0
= copy_rtx (op0
);
3017 if (op0
== orig_op0
)
3018 op0
= shallow_copy_rtx (op0
);
3019 set_mem_attributes (op0
, exp
, 0);
3022 if (bitpos
== 0 && mode
== GET_MODE (op0
))
3028 if (GET_MODE (op0
) == BLKmode
)
3031 if ((bitpos
% BITS_PER_UNIT
) == 0
3032 && bitsize
== GET_MODE_BITSIZE (mode1
))
3034 enum machine_mode opmode
= GET_MODE (op0
);
3036 if (opmode
== VOIDmode
)
3037 opmode
= TYPE_MODE (TREE_TYPE (tem
));
3039 /* This condition may hold if we're expanding the address
3040 right past the end of an array that turned out not to
3041 be addressable (i.e., the address was only computed in
3042 debug stmts). The gen_subreg below would rightfully
3043 crash, and the address doesn't really exist, so just
3045 if (bitpos
>= GET_MODE_BITSIZE (opmode
))
3048 if ((bitpos
% GET_MODE_BITSIZE (mode
)) == 0)
3049 return simplify_gen_subreg (mode
, op0
, opmode
,
3050 bitpos
/ BITS_PER_UNIT
);
3053 return simplify_gen_ternary (SCALAR_INT_MODE_P (GET_MODE (op0
))
3054 && TYPE_UNSIGNED (TREE_TYPE (exp
))
3056 : ZERO_EXTRACT
, mode
,
3057 GET_MODE (op0
) != VOIDmode
3059 : TYPE_MODE (TREE_TYPE (tem
)),
3060 op0
, GEN_INT (bitsize
), GEN_INT (bitpos
));
3064 return simplify_gen_unary (ABS
, mode
, op0
, mode
);
3067 return simplify_gen_unary (NEG
, mode
, op0
, mode
);
3070 return simplify_gen_unary (NOT
, mode
, op0
, mode
);
3073 return simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
,
3075 ? UNSIGNED_FLOAT
: FLOAT
, mode
, op0
,
3078 case FIX_TRUNC_EXPR
:
3079 return simplify_gen_unary (unsignedp
? UNSIGNED_FIX
: FIX
, mode
, op0
,
3082 case POINTER_PLUS_EXPR
:
3083 /* For the rare target where pointers are not the same size as
3084 size_t, we need to check for mis-matched modes and correct
3087 && GET_MODE (op0
) != VOIDmode
&& GET_MODE (op1
) != VOIDmode
3088 && GET_MODE (op0
) != GET_MODE (op1
))
3090 if (GET_MODE_BITSIZE (GET_MODE (op0
)) < GET_MODE_BITSIZE (GET_MODE (op1
)))
3091 op1
= simplify_gen_unary (TRUNCATE
, GET_MODE (op0
), op1
,
3094 /* We always sign-extend, regardless of the signedness of
3095 the operand, because the operand is always unsigned
3096 here even if the original C expression is signed. */
3097 op1
= simplify_gen_unary (SIGN_EXTEND
, GET_MODE (op0
), op1
,
3102 return simplify_gen_binary (PLUS
, mode
, op0
, op1
);
3105 return simplify_gen_binary (MINUS
, mode
, op0
, op1
);
3108 return simplify_gen_binary (MULT
, mode
, op0
, op1
);
3111 case TRUNC_DIV_EXPR
:
3112 case EXACT_DIV_EXPR
:
3114 return simplify_gen_binary (UDIV
, mode
, op0
, op1
);
3116 return simplify_gen_binary (DIV
, mode
, op0
, op1
);
3118 case TRUNC_MOD_EXPR
:
3119 return simplify_gen_binary (unsignedp
? UMOD
: MOD
, mode
, op0
, op1
);
3121 case FLOOR_DIV_EXPR
:
3123 return simplify_gen_binary (UDIV
, mode
, op0
, op1
);
3126 rtx div
= simplify_gen_binary (DIV
, mode
, op0
, op1
);
3127 rtx mod
= simplify_gen_binary (MOD
, mode
, op0
, op1
);
3128 rtx adj
= floor_sdiv_adjust (mode
, mod
, op1
);
3129 return simplify_gen_binary (PLUS
, mode
, div
, adj
);
3132 case FLOOR_MOD_EXPR
:
3134 return simplify_gen_binary (UMOD
, mode
, op0
, op1
);
3137 rtx mod
= simplify_gen_binary (MOD
, mode
, op0
, op1
);
3138 rtx adj
= floor_sdiv_adjust (mode
, mod
, op1
);
3139 adj
= simplify_gen_unary (NEG
, mode
,
3140 simplify_gen_binary (MULT
, mode
, adj
, op1
),
3142 return simplify_gen_binary (PLUS
, mode
, mod
, adj
);
3148 rtx div
= simplify_gen_binary (UDIV
, mode
, op0
, op1
);
3149 rtx mod
= simplify_gen_binary (UMOD
, mode
, op0
, op1
);
3150 rtx adj
= ceil_udiv_adjust (mode
, mod
, op1
);
3151 return simplify_gen_binary (PLUS
, mode
, div
, adj
);
3155 rtx div
= simplify_gen_binary (DIV
, mode
, op0
, op1
);
3156 rtx mod
= simplify_gen_binary (MOD
, mode
, op0
, op1
);
3157 rtx adj
= ceil_sdiv_adjust (mode
, mod
, op1
);
3158 return simplify_gen_binary (PLUS
, mode
, div
, adj
);
3164 rtx mod
= simplify_gen_binary (UMOD
, mode
, op0
, op1
);
3165 rtx adj
= ceil_udiv_adjust (mode
, mod
, op1
);
3166 adj
= simplify_gen_unary (NEG
, mode
,
3167 simplify_gen_binary (MULT
, mode
, adj
, op1
),
3169 return simplify_gen_binary (PLUS
, mode
, mod
, adj
);
3173 rtx mod
= simplify_gen_binary (MOD
, mode
, op0
, op1
);
3174 rtx adj
= ceil_sdiv_adjust (mode
, mod
, op1
);
3175 adj
= simplify_gen_unary (NEG
, mode
,
3176 simplify_gen_binary (MULT
, mode
, adj
, op1
),
3178 return simplify_gen_binary (PLUS
, mode
, mod
, adj
);
3181 case ROUND_DIV_EXPR
:
3184 rtx div
= simplify_gen_binary (UDIV
, mode
, op0
, op1
);
3185 rtx mod
= simplify_gen_binary (UMOD
, mode
, op0
, op1
);
3186 rtx adj
= round_udiv_adjust (mode
, mod
, op1
);
3187 return simplify_gen_binary (PLUS
, mode
, div
, adj
);
3191 rtx div
= simplify_gen_binary (DIV
, mode
, op0
, op1
);
3192 rtx mod
= simplify_gen_binary (MOD
, mode
, op0
, op1
);
3193 rtx adj
= round_sdiv_adjust (mode
, mod
, op1
);
3194 return simplify_gen_binary (PLUS
, mode
, div
, adj
);
3197 case ROUND_MOD_EXPR
:
3200 rtx mod
= simplify_gen_binary (UMOD
, mode
, op0
, op1
);
3201 rtx adj
= round_udiv_adjust (mode
, mod
, op1
);
3202 adj
= simplify_gen_unary (NEG
, mode
,
3203 simplify_gen_binary (MULT
, mode
, adj
, op1
),
3205 return simplify_gen_binary (PLUS
, mode
, mod
, adj
);
3209 rtx mod
= simplify_gen_binary (MOD
, mode
, op0
, op1
);
3210 rtx adj
= round_sdiv_adjust (mode
, mod
, op1
);
3211 adj
= simplify_gen_unary (NEG
, mode
,
3212 simplify_gen_binary (MULT
, mode
, adj
, op1
),
3214 return simplify_gen_binary (PLUS
, mode
, mod
, adj
);
3218 return simplify_gen_binary (ASHIFT
, mode
, op0
, op1
);
3222 return simplify_gen_binary (LSHIFTRT
, mode
, op0
, op1
);
3224 return simplify_gen_binary (ASHIFTRT
, mode
, op0
, op1
);
3227 return simplify_gen_binary (ROTATE
, mode
, op0
, op1
);
3230 return simplify_gen_binary (ROTATERT
, mode
, op0
, op1
);
3233 return simplify_gen_binary (unsignedp
? UMIN
: SMIN
, mode
, op0
, op1
);
3236 return simplify_gen_binary (unsignedp
? UMAX
: SMAX
, mode
, op0
, op1
);
3239 case TRUTH_AND_EXPR
:
3240 return simplify_gen_binary (AND
, mode
, op0
, op1
);
3244 return simplify_gen_binary (IOR
, mode
, op0
, op1
);
3247 case TRUTH_XOR_EXPR
:
3248 return simplify_gen_binary (XOR
, mode
, op0
, op1
);
3250 case TRUTH_ANDIF_EXPR
:
3251 return gen_rtx_IF_THEN_ELSE (mode
, op0
, op1
, const0_rtx
);
3253 case TRUTH_ORIF_EXPR
:
3254 return gen_rtx_IF_THEN_ELSE (mode
, op0
, const_true_rtx
, op1
);
3256 case TRUTH_NOT_EXPR
:
3257 return simplify_gen_relational (EQ
, mode
, inner_mode
, op0
, const0_rtx
);
3260 return simplify_gen_relational (unsignedp
? LTU
: LT
, mode
, inner_mode
,
3264 return simplify_gen_relational (unsignedp
? LEU
: LE
, mode
, inner_mode
,
3268 return simplify_gen_relational (unsignedp
? GTU
: GT
, mode
, inner_mode
,
3272 return simplify_gen_relational (unsignedp
? GEU
: GE
, mode
, inner_mode
,
3276 return simplify_gen_relational (EQ
, mode
, inner_mode
, op0
, op1
);
3279 return simplify_gen_relational (NE
, mode
, inner_mode
, op0
, op1
);
3281 case UNORDERED_EXPR
:
3282 return simplify_gen_relational (UNORDERED
, mode
, inner_mode
, op0
, op1
);
3285 return simplify_gen_relational (ORDERED
, mode
, inner_mode
, op0
, op1
);
3288 return simplify_gen_relational (UNLT
, mode
, inner_mode
, op0
, op1
);
3291 return simplify_gen_relational (UNLE
, mode
, inner_mode
, op0
, op1
);
3294 return simplify_gen_relational (UNGT
, mode
, inner_mode
, op0
, op1
);
3297 return simplify_gen_relational (UNGE
, mode
, inner_mode
, op0
, op1
);
3300 return simplify_gen_relational (UNEQ
, mode
, inner_mode
, op0
, op1
);
3303 return simplify_gen_relational (LTGT
, mode
, inner_mode
, op0
, op1
);
3306 return gen_rtx_IF_THEN_ELSE (mode
, op0
, op1
, op2
);
3309 gcc_assert (COMPLEX_MODE_P (mode
));
3310 if (GET_MODE (op0
) == VOIDmode
)
3311 op0
= gen_rtx_CONST (GET_MODE_INNER (mode
), op0
);
3312 if (GET_MODE (op1
) == VOIDmode
)
3313 op1
= gen_rtx_CONST (GET_MODE_INNER (mode
), op1
);
3314 return gen_rtx_CONCAT (mode
, op0
, op1
);
3317 if (GET_CODE (op0
) == CONCAT
)
3318 return gen_rtx_CONCAT (mode
, XEXP (op0
, 0),
3319 simplify_gen_unary (NEG
, GET_MODE_INNER (mode
),
3321 GET_MODE_INNER (mode
)));
3324 enum machine_mode imode
= GET_MODE_INNER (mode
);
3329 re
= adjust_address_nv (op0
, imode
, 0);
3330 im
= adjust_address_nv (op0
, imode
, GET_MODE_SIZE (imode
));
3334 enum machine_mode ifmode
= int_mode_for_mode (mode
);
3335 enum machine_mode ihmode
= int_mode_for_mode (imode
);
3337 if (ifmode
== BLKmode
|| ihmode
== BLKmode
)
3339 halfsize
= GEN_INT (GET_MODE_BITSIZE (ihmode
));
3342 re
= gen_rtx_SUBREG (ifmode
, re
, 0);
3343 re
= gen_rtx_ZERO_EXTRACT (ihmode
, re
, halfsize
, const0_rtx
);
3344 if (imode
!= ihmode
)
3345 re
= gen_rtx_SUBREG (imode
, re
, 0);
3346 im
= copy_rtx (op0
);
3348 im
= gen_rtx_SUBREG (ifmode
, im
, 0);
3349 im
= gen_rtx_ZERO_EXTRACT (ihmode
, im
, halfsize
, halfsize
);
3350 if (imode
!= ihmode
)
3351 im
= gen_rtx_SUBREG (imode
, im
, 0);
3353 im
= gen_rtx_NEG (imode
, im
);
3354 return gen_rtx_CONCAT (mode
, re
, im
);
3358 op0
= expand_debug_expr (TREE_OPERAND (exp
, 0));
3359 if (!op0
|| !MEM_P (op0
))
3361 if ((TREE_CODE (TREE_OPERAND (exp
, 0)) == VAR_DECL
3362 || TREE_CODE (TREE_OPERAND (exp
, 0)) == PARM_DECL
3363 || TREE_CODE (TREE_OPERAND (exp
, 0)) == RESULT_DECL
)
3364 && (!TREE_ADDRESSABLE (TREE_OPERAND (exp
, 0))
3365 || target_for_debug_bind (TREE_OPERAND (exp
, 0))))
3366 return gen_rtx_DEBUG_IMPLICIT_PTR (mode
, TREE_OPERAND (exp
, 0));
3368 if (handled_component_p (TREE_OPERAND (exp
, 0)))
3370 HOST_WIDE_INT bitoffset
, bitsize
, maxsize
;
3372 = get_ref_base_and_extent (TREE_OPERAND (exp
, 0),
3373 &bitoffset
, &bitsize
, &maxsize
);
3374 if ((TREE_CODE (decl
) == VAR_DECL
3375 || TREE_CODE (decl
) == PARM_DECL
3376 || TREE_CODE (decl
) == RESULT_DECL
)
3377 && (!TREE_ADDRESSABLE (decl
)
3378 || target_for_debug_bind (decl
))
3379 && (bitoffset
% BITS_PER_UNIT
) == 0
3381 && bitsize
== maxsize
)
3383 rtx base
= gen_rtx_DEBUG_IMPLICIT_PTR (mode
, decl
);
3384 return plus_constant (mode
, base
, bitoffset
/ BITS_PER_UNIT
);
3388 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == MEM_REF
3389 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
3392 op0
= expand_debug_expr (TREE_OPERAND (TREE_OPERAND (exp
, 0),
3395 && (GET_CODE (op0
) == DEBUG_IMPLICIT_PTR
3396 || (GET_CODE (op0
) == PLUS
3397 && GET_CODE (XEXP (op0
, 0)) == DEBUG_IMPLICIT_PTR
3398 && CONST_INT_P (XEXP (op0
, 1)))))
3400 op1
= expand_debug_expr (TREE_OPERAND (TREE_OPERAND (exp
, 0),
3402 if (!op1
|| !CONST_INT_P (op1
))
3405 return plus_constant (mode
, op0
, INTVAL (op1
));
3412 as
= TYPE_ADDR_SPACE (TREE_TYPE (exp
));
3413 op0
= convert_debug_memory_address (mode
, XEXP (op0
, 0), as
);
3421 op0
= gen_rtx_CONCATN
3422 (mode
, rtvec_alloc (TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp
))));
3424 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
3426 op1
= expand_debug_expr (VECTOR_CST_ELT (exp
, i
));
3429 XVECEXP (op0
, 0, i
) = op1
;
3436 if (TREE_CLOBBER_P (exp
))
3438 else if (TREE_CODE (TREE_TYPE (exp
)) == VECTOR_TYPE
)
3443 op0
= gen_rtx_CONCATN
3444 (mode
, rtvec_alloc (TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp
))));
3446 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), i
, val
)
3448 op1
= expand_debug_expr (val
);
3451 XVECEXP (op0
, 0, i
) = op1
;
3454 if (i
< TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp
)))
3456 op1
= expand_debug_expr
3457 (build_zero_cst (TREE_TYPE (TREE_TYPE (exp
))));
3462 for (; i
< TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp
)); i
++)
3463 XVECEXP (op0
, 0, i
) = op1
;
3469 goto flag_unsupported
;
3472 /* ??? Maybe handle some builtins? */
3477 gimple g
= get_gimple_for_ssa_name (exp
);
3480 op0
= expand_debug_expr (gimple_assign_rhs_to_tree (g
));
3486 int part
= var_to_partition (SA
.map
, exp
);
3488 if (part
== NO_PARTITION
)
3490 /* If this is a reference to an incoming value of parameter
3491 that is never used in the code or where the incoming
3492 value is never used in the code, use PARM_DECL's
3494 if (SSA_NAME_IS_DEFAULT_DEF (exp
)
3495 && TREE_CODE (SSA_NAME_VAR (exp
)) == PARM_DECL
)
3497 op0
= expand_debug_parm_decl (SSA_NAME_VAR (exp
));
3500 op0
= expand_debug_expr (SSA_NAME_VAR (exp
));
3507 gcc_assert (part
>= 0 && (unsigned)part
< SA
.map
->num_partitions
);
3509 op0
= copy_rtx (SA
.partition_to_pseudo
[part
]);
3517 /* Vector stuff. For most of the codes we don't have rtl codes. */
3518 case REALIGN_LOAD_EXPR
:
3519 case REDUC_MAX_EXPR
:
3520 case REDUC_MIN_EXPR
:
3521 case REDUC_PLUS_EXPR
:
3523 case VEC_LSHIFT_EXPR
:
3524 case VEC_PACK_FIX_TRUNC_EXPR
:
3525 case VEC_PACK_SAT_EXPR
:
3526 case VEC_PACK_TRUNC_EXPR
:
3527 case VEC_RSHIFT_EXPR
:
3528 case VEC_UNPACK_FLOAT_HI_EXPR
:
3529 case VEC_UNPACK_FLOAT_LO_EXPR
:
3530 case VEC_UNPACK_HI_EXPR
:
3531 case VEC_UNPACK_LO_EXPR
:
3532 case VEC_WIDEN_MULT_HI_EXPR
:
3533 case VEC_WIDEN_MULT_LO_EXPR
:
3534 case VEC_WIDEN_MULT_EVEN_EXPR
:
3535 case VEC_WIDEN_MULT_ODD_EXPR
:
3536 case VEC_WIDEN_LSHIFT_HI_EXPR
:
3537 case VEC_WIDEN_LSHIFT_LO_EXPR
:
3542 case ADDR_SPACE_CONVERT_EXPR
:
3543 case FIXED_CONVERT_EXPR
:
3545 case WITH_SIZE_EXPR
:
3549 if (SCALAR_INT_MODE_P (GET_MODE (op0
))
3550 && SCALAR_INT_MODE_P (mode
))
3553 = simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
,
3555 ? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op0
,
3558 = simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
,
3560 ? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op1
,
3562 op0
= simplify_gen_binary (MULT
, mode
, op0
, op1
);
3563 return simplify_gen_binary (PLUS
, mode
, op0
, op2
);
3567 case WIDEN_MULT_EXPR
:
3568 case WIDEN_MULT_PLUS_EXPR
:
3569 case WIDEN_MULT_MINUS_EXPR
:
3570 if (SCALAR_INT_MODE_P (GET_MODE (op0
))
3571 && SCALAR_INT_MODE_P (mode
))
3573 inner_mode
= GET_MODE (op0
);
3574 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
, 0))))
3575 op0
= simplify_gen_unary (ZERO_EXTEND
, mode
, op0
, inner_mode
);
3577 op0
= simplify_gen_unary (SIGN_EXTEND
, mode
, op0
, inner_mode
);
3578 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
, 1))))
3579 op1
= simplify_gen_unary (ZERO_EXTEND
, mode
, op1
, inner_mode
);
3581 op1
= simplify_gen_unary (SIGN_EXTEND
, mode
, op1
, inner_mode
);
3582 op0
= simplify_gen_binary (MULT
, mode
, op0
, op1
);
3583 if (TREE_CODE (exp
) == WIDEN_MULT_EXPR
)
3585 else if (TREE_CODE (exp
) == WIDEN_MULT_PLUS_EXPR
)
3586 return simplify_gen_binary (PLUS
, mode
, op0
, op2
);
3588 return simplify_gen_binary (MINUS
, mode
, op2
, op0
);
3592 case MULT_HIGHPART_EXPR
:
3593 /* ??? Similar to the above. */
3596 case WIDEN_SUM_EXPR
:
3597 case WIDEN_LSHIFT_EXPR
:
3598 if (SCALAR_INT_MODE_P (GET_MODE (op0
))
3599 && SCALAR_INT_MODE_P (mode
))
3602 = simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
,
3604 ? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op0
,
3606 return simplify_gen_binary (TREE_CODE (exp
) == WIDEN_LSHIFT_EXPR
3607 ? ASHIFT
: PLUS
, mode
, op0
, op1
);
3612 return simplify_gen_ternary (FMA
, mode
, inner_mode
, op0
, op1
, op2
);
3616 #ifdef ENABLE_CHECKING
3625 /* Return an RTX equivalent to the source bind value of the tree expression
3629 expand_debug_source_expr (tree exp
)
3632 enum machine_mode mode
= VOIDmode
, inner_mode
;
3634 switch (TREE_CODE (exp
))
3638 mode
= DECL_MODE (exp
);
3639 op0
= expand_debug_parm_decl (exp
);
3642 /* See if this isn't an argument that has been completely
3644 if (!DECL_RTL_SET_P (exp
)
3645 && !DECL_INCOMING_RTL (exp
)
3646 && DECL_ABSTRACT_ORIGIN (current_function_decl
))
3648 tree aexp
= DECL_ORIGIN (exp
);
3649 if (DECL_CONTEXT (aexp
)
3650 == DECL_ABSTRACT_ORIGIN (current_function_decl
))
3652 vec
<tree
, va_gc
> **debug_args
;
3655 debug_args
= decl_debug_args_lookup (current_function_decl
);
3656 if (debug_args
!= NULL
)
3658 for (ix
= 0; vec_safe_iterate (*debug_args
, ix
, &ddecl
);
3661 return gen_rtx_DEBUG_PARAMETER_REF (mode
, aexp
);
3671 if (op0
== NULL_RTX
)
3674 inner_mode
= GET_MODE (op0
);
3675 if (mode
== inner_mode
)
3678 if (FLOAT_MODE_P (mode
) && FLOAT_MODE_P (inner_mode
))
3680 if (GET_MODE_BITSIZE (mode
) == GET_MODE_BITSIZE (inner_mode
))
3681 op0
= simplify_gen_subreg (mode
, op0
, inner_mode
, 0);
3682 else if (GET_MODE_BITSIZE (mode
) < GET_MODE_BITSIZE (inner_mode
))
3683 op0
= simplify_gen_unary (FLOAT_TRUNCATE
, mode
, op0
, inner_mode
);
3685 op0
= simplify_gen_unary (FLOAT_EXTEND
, mode
, op0
, inner_mode
);
3687 else if (FLOAT_MODE_P (mode
))
3689 else if (FLOAT_MODE_P (inner_mode
))
3691 if (TYPE_UNSIGNED (TREE_TYPE (exp
)))
3692 op0
= simplify_gen_unary (UNSIGNED_FIX
, mode
, op0
, inner_mode
);
3694 op0
= simplify_gen_unary (FIX
, mode
, op0
, inner_mode
);
3696 else if (CONSTANT_P (op0
)
3697 || GET_MODE_BITSIZE (mode
) <= GET_MODE_BITSIZE (inner_mode
))
3698 op0
= simplify_gen_subreg (mode
, op0
, inner_mode
,
3699 subreg_lowpart_offset (mode
, inner_mode
));
3700 else if (TYPE_UNSIGNED (TREE_TYPE (exp
)))
3701 op0
= simplify_gen_unary (ZERO_EXTEND
, mode
, op0
, inner_mode
);
3703 op0
= simplify_gen_unary (SIGN_EXTEND
, mode
, op0
, inner_mode
);
3708 /* Expand the _LOCs in debug insns. We run this after expanding all
3709 regular insns, so that any variables referenced in the function
3710 will have their DECL_RTLs set. */
3713 expand_debug_locations (void)
3716 rtx last
= get_last_insn ();
3717 int save_strict_alias
= flag_strict_aliasing
;
3719 /* New alias sets while setting up memory attributes cause
3720 -fcompare-debug failures, even though it doesn't bring about any
3722 flag_strict_aliasing
= 0;
3724 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3725 if (DEBUG_INSN_P (insn
))
3727 tree value
= (tree
)INSN_VAR_LOCATION_LOC (insn
);
3729 enum machine_mode mode
;
3731 if (value
== NULL_TREE
)
3735 if (INSN_VAR_LOCATION_STATUS (insn
)
3736 == VAR_INIT_STATUS_UNINITIALIZED
)
3737 val
= expand_debug_source_expr (value
);
3739 val
= expand_debug_expr (value
);
3740 gcc_assert (last
== get_last_insn ());
3744 val
= gen_rtx_UNKNOWN_VAR_LOC ();
3747 mode
= GET_MODE (INSN_VAR_LOCATION (insn
));
3749 gcc_assert (mode
== GET_MODE (val
)
3750 || (GET_MODE (val
) == VOIDmode
3751 && (CONST_SCALAR_INT_P (val
)
3752 || GET_CODE (val
) == CONST_FIXED
3753 || GET_CODE (val
) == LABEL_REF
)));
3756 INSN_VAR_LOCATION_LOC (insn
) = val
;
3759 flag_strict_aliasing
= save_strict_alias
;
3762 /* Expand basic block BB from GIMPLE trees to RTL. */
3765 expand_gimple_basic_block (basic_block bb
, bool disable_tail_calls
)
3767 gimple_stmt_iterator gsi
;
3776 fprintf (dump_file
, "\n;; Generating RTL for gimple basic block %d\n",
3779 /* Note that since we are now transitioning from GIMPLE to RTL, we
3780 cannot use the gsi_*_bb() routines because they expect the basic
3781 block to be in GIMPLE, instead of RTL. Therefore, we need to
3782 access the BB sequence directly. */
3783 stmts
= bb_seq (bb
);
3784 bb
->il
.gimple
.seq
= NULL
;
3785 bb
->il
.gimple
.phi_nodes
= NULL
;
3786 rtl_profile_for_bb (bb
);
3787 init_rtl_bb_info (bb
);
3788 bb
->flags
|= BB_RTL
;
3790 /* Remove the RETURN_EXPR if we may fall though to the exit
3792 gsi
= gsi_last (stmts
);
3793 if (!gsi_end_p (gsi
)
3794 && gimple_code (gsi_stmt (gsi
)) == GIMPLE_RETURN
)
3796 gimple ret_stmt
= gsi_stmt (gsi
);
3798 gcc_assert (single_succ_p (bb
));
3799 gcc_assert (single_succ (bb
) == EXIT_BLOCK_PTR
);
3801 if (bb
->next_bb
== EXIT_BLOCK_PTR
3802 && !gimple_return_retval (ret_stmt
))
3804 gsi_remove (&gsi
, false);
3805 single_succ_edge (bb
)->flags
|= EDGE_FALLTHRU
;
3809 gsi
= gsi_start (stmts
);
3810 if (!gsi_end_p (gsi
))
3812 stmt
= gsi_stmt (gsi
);
3813 if (gimple_code (stmt
) != GIMPLE_LABEL
)
3817 elt
= pointer_map_contains (lab_rtx_for_bb
, bb
);
3821 last
= get_last_insn ();
3825 expand_gimple_stmt (stmt
);
3830 emit_label ((rtx
) *elt
);
3832 /* Java emits line number notes in the top of labels.
3833 ??? Make this go away once line number notes are obsoleted. */
3834 BB_HEAD (bb
) = NEXT_INSN (last
);
3835 if (NOTE_P (BB_HEAD (bb
)))
3836 BB_HEAD (bb
) = NEXT_INSN (BB_HEAD (bb
));
3837 note
= emit_note_after (NOTE_INSN_BASIC_BLOCK
, BB_HEAD (bb
));
3839 maybe_dump_rtl_for_gimple_stmt (stmt
, last
);
3842 note
= BB_HEAD (bb
) = emit_note (NOTE_INSN_BASIC_BLOCK
);
3844 NOTE_BASIC_BLOCK (note
) = bb
;
3846 for (; !gsi_end_p (gsi
); gsi_next (&gsi
))
3850 stmt
= gsi_stmt (gsi
);
3852 /* If this statement is a non-debug one, and we generate debug
3853 insns, then this one might be the last real use of a TERed
3854 SSA_NAME, but where there are still some debug uses further
3855 down. Expanding the current SSA name in such further debug
3856 uses by their RHS might lead to wrong debug info, as coalescing
3857 might make the operands of such RHS be placed into the same
3858 pseudo as something else. Like so:
3859 a_1 = a_0 + 1; // Assume a_1 is TERed and a_0 is dead
3863 As a_0 and a_2 don't overlap in lifetime, assume they are coalesced.
3864 If we now would expand a_1 by it's RHS (a_0 + 1) in the debug use,
3865 the write to a_2 would actually have clobbered the place which
3868 So, instead of that, we recognize the situation, and generate
3869 debug temporaries at the last real use of TERed SSA names:
3876 if (MAY_HAVE_DEBUG_INSNS
3878 && !is_gimple_debug (stmt
))
3884 location_t sloc
= curr_insn_location ();
3886 /* Look for SSA names that have their last use here (TERed
3887 names always have only one real use). */
3888 FOR_EACH_SSA_TREE_OPERAND (op
, stmt
, iter
, SSA_OP_USE
)
3889 if ((def
= get_gimple_for_ssa_name (op
)))
3891 imm_use_iterator imm_iter
;
3892 use_operand_p use_p
;
3893 bool have_debug_uses
= false;
3895 FOR_EACH_IMM_USE_FAST (use_p
, imm_iter
, op
)
3897 if (gimple_debug_bind_p (USE_STMT (use_p
)))
3899 have_debug_uses
= true;
3904 if (have_debug_uses
)
3906 /* OP is a TERed SSA name, with DEF it's defining
3907 statement, and where OP is used in further debug
3908 instructions. Generate a debug temporary, and
3909 replace all uses of OP in debug insns with that
3912 tree value
= gimple_assign_rhs_to_tree (def
);
3913 tree vexpr
= make_node (DEBUG_EXPR_DECL
);
3915 enum machine_mode mode
;
3917 set_curr_insn_location (gimple_location (def
));
3919 DECL_ARTIFICIAL (vexpr
) = 1;
3920 TREE_TYPE (vexpr
) = TREE_TYPE (value
);
3922 mode
= DECL_MODE (value
);
3924 mode
= TYPE_MODE (TREE_TYPE (value
));
3925 DECL_MODE (vexpr
) = mode
;
3927 val
= gen_rtx_VAR_LOCATION
3928 (mode
, vexpr
, (rtx
)value
, VAR_INIT_STATUS_INITIALIZED
);
3930 emit_debug_insn (val
);
3932 FOR_EACH_IMM_USE_STMT (debugstmt
, imm_iter
, op
)
3934 if (!gimple_debug_bind_p (debugstmt
))
3937 FOR_EACH_IMM_USE_ON_STMT (use_p
, imm_iter
)
3938 SET_USE (use_p
, vexpr
);
3940 update_stmt (debugstmt
);
3944 set_curr_insn_location (sloc
);
3947 currently_expanding_gimple_stmt
= stmt
;
3949 /* Expand this statement, then evaluate the resulting RTL and
3950 fixup the CFG accordingly. */
3951 if (gimple_code (stmt
) == GIMPLE_COND
)
3953 new_bb
= expand_gimple_cond (bb
, stmt
);
3957 else if (gimple_debug_bind_p (stmt
))
3959 location_t sloc
= curr_insn_location ();
3960 gimple_stmt_iterator nsi
= gsi
;
3964 tree var
= gimple_debug_bind_get_var (stmt
);
3967 enum machine_mode mode
;
3969 if (TREE_CODE (var
) != DEBUG_EXPR_DECL
3970 && TREE_CODE (var
) != LABEL_DECL
3971 && !target_for_debug_bind (var
))
3972 goto delink_debug_stmt
;
3974 if (gimple_debug_bind_has_value_p (stmt
))
3975 value
= gimple_debug_bind_get_value (stmt
);
3979 last
= get_last_insn ();
3981 set_curr_insn_location (gimple_location (stmt
));
3984 mode
= DECL_MODE (var
);
3986 mode
= TYPE_MODE (TREE_TYPE (var
));
3988 val
= gen_rtx_VAR_LOCATION
3989 (mode
, var
, (rtx
)value
, VAR_INIT_STATUS_INITIALIZED
);
3991 emit_debug_insn (val
);
3993 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
3995 /* We can't dump the insn with a TREE where an RTX
3997 PAT_VAR_LOCATION_LOC (val
) = const0_rtx
;
3998 maybe_dump_rtl_for_gimple_stmt (stmt
, last
);
3999 PAT_VAR_LOCATION_LOC (val
) = (rtx
)value
;
4003 /* In order not to generate too many debug temporaries,
4004 we delink all uses of debug statements we already expanded.
4005 Therefore debug statements between definition and real
4006 use of TERed SSA names will continue to use the SSA name,
4007 and not be replaced with debug temps. */
4008 delink_stmt_imm_use (stmt
);
4012 if (gsi_end_p (nsi
))
4014 stmt
= gsi_stmt (nsi
);
4015 if (!gimple_debug_bind_p (stmt
))
4019 set_curr_insn_location (sloc
);
4021 else if (gimple_debug_source_bind_p (stmt
))
4023 location_t sloc
= curr_insn_location ();
4024 tree var
= gimple_debug_source_bind_get_var (stmt
);
4025 tree value
= gimple_debug_source_bind_get_value (stmt
);
4027 enum machine_mode mode
;
4029 last
= get_last_insn ();
4031 set_curr_insn_location (gimple_location (stmt
));
4033 mode
= DECL_MODE (var
);
4035 val
= gen_rtx_VAR_LOCATION (mode
, var
, (rtx
)value
,
4036 VAR_INIT_STATUS_UNINITIALIZED
);
4038 emit_debug_insn (val
);
4040 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
4042 /* We can't dump the insn with a TREE where an RTX
4044 PAT_VAR_LOCATION_LOC (val
) = const0_rtx
;
4045 maybe_dump_rtl_for_gimple_stmt (stmt
, last
);
4046 PAT_VAR_LOCATION_LOC (val
) = (rtx
)value
;
4049 set_curr_insn_location (sloc
);
4053 if (is_gimple_call (stmt
)
4054 && gimple_call_tail_p (stmt
)
4055 && disable_tail_calls
)
4056 gimple_call_set_tail (stmt
, false);
4058 if (is_gimple_call (stmt
) && gimple_call_tail_p (stmt
))
4061 new_bb
= expand_gimple_tailcall (bb
, stmt
, &can_fallthru
);
4072 def_operand_p def_p
;
4073 def_p
= SINGLE_SSA_DEF_OPERAND (stmt
, SSA_OP_DEF
);
4077 /* Ignore this stmt if it is in the list of
4078 replaceable expressions. */
4080 && bitmap_bit_p (SA
.values
,
4081 SSA_NAME_VERSION (DEF_FROM_PTR (def_p
))))
4084 last
= expand_gimple_stmt (stmt
);
4085 maybe_dump_rtl_for_gimple_stmt (stmt
, last
);
4090 currently_expanding_gimple_stmt
= NULL
;
4092 /* Expand implicit goto and convert goto_locus. */
4093 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
4095 if (e
->goto_locus
!= UNKNOWN_LOCATION
)
4096 set_curr_insn_location (e
->goto_locus
);
4097 if ((e
->flags
& EDGE_FALLTHRU
) && e
->dest
!= bb
->next_bb
)
4099 emit_jump (label_rtx_for_bb (e
->dest
));
4100 e
->flags
&= ~EDGE_FALLTHRU
;
4104 /* Expanded RTL can create a jump in the last instruction of block.
4105 This later might be assumed to be a jump to successor and break edge insertion.
4106 We need to insert dummy move to prevent this. PR41440. */
4107 if (single_succ_p (bb
)
4108 && (single_succ_edge (bb
)->flags
& EDGE_FALLTHRU
)
4109 && (last
= get_last_insn ())
4112 rtx dummy
= gen_reg_rtx (SImode
);
4113 emit_insn_after_noloc (gen_move_insn (dummy
, dummy
), last
, NULL
);
4116 do_pending_stack_adjust ();
4118 /* Find the block tail. The last insn in the block is the insn
4119 before a barrier and/or table jump insn. */
4120 last
= get_last_insn ();
4121 if (BARRIER_P (last
))
4122 last
= PREV_INSN (last
);
4123 if (JUMP_TABLE_DATA_P (last
))
4124 last
= PREV_INSN (PREV_INSN (last
));
4127 update_bb_for_insn (bb
);
4133 /* Create a basic block for initialization code. */
4136 construct_init_block (void)
4138 basic_block init_block
, first_block
;
4142 /* Multiple entry points not supported yet. */
4143 gcc_assert (EDGE_COUNT (ENTRY_BLOCK_PTR
->succs
) == 1);
4144 init_rtl_bb_info (ENTRY_BLOCK_PTR
);
4145 init_rtl_bb_info (EXIT_BLOCK_PTR
);
4146 ENTRY_BLOCK_PTR
->flags
|= BB_RTL
;
4147 EXIT_BLOCK_PTR
->flags
|= BB_RTL
;
4149 e
= EDGE_SUCC (ENTRY_BLOCK_PTR
, 0);
4151 /* When entry edge points to first basic block, we don't need jump,
4152 otherwise we have to jump into proper target. */
4153 if (e
&& e
->dest
!= ENTRY_BLOCK_PTR
->next_bb
)
4155 tree label
= gimple_block_label (e
->dest
);
4157 emit_jump (label_rtx (label
));
4161 flags
= EDGE_FALLTHRU
;
4163 init_block
= create_basic_block (NEXT_INSN (get_insns ()),
4166 init_block
->frequency
= ENTRY_BLOCK_PTR
->frequency
;
4167 init_block
->count
= ENTRY_BLOCK_PTR
->count
;
4168 if (current_loops
&& ENTRY_BLOCK_PTR
->loop_father
)
4169 add_bb_to_loop (init_block
, ENTRY_BLOCK_PTR
->loop_father
);
4172 first_block
= e
->dest
;
4173 redirect_edge_succ (e
, init_block
);
4174 e
= make_edge (init_block
, first_block
, flags
);
4177 e
= make_edge (init_block
, EXIT_BLOCK_PTR
, EDGE_FALLTHRU
);
4178 e
->probability
= REG_BR_PROB_BASE
;
4179 e
->count
= ENTRY_BLOCK_PTR
->count
;
4181 update_bb_for_insn (init_block
);
4185 /* For each lexical block, set BLOCK_NUMBER to the depth at which it is
4186 found in the block tree. */
4189 set_block_levels (tree block
, int level
)
4193 BLOCK_NUMBER (block
) = level
;
4194 set_block_levels (BLOCK_SUBBLOCKS (block
), level
+ 1);
4195 block
= BLOCK_CHAIN (block
);
4199 /* Create a block containing landing pads and similar stuff. */
4202 construct_exit_block (void)
4204 rtx head
= get_last_insn ();
4206 basic_block exit_block
;
4210 rtx orig_end
= BB_END (EXIT_BLOCK_PTR
->prev_bb
);
4212 rtl_profile_for_bb (EXIT_BLOCK_PTR
);
4214 /* Make sure the locus is set to the end of the function, so that
4215 epilogue line numbers and warnings are set properly. */
4216 if (LOCATION_LOCUS (cfun
->function_end_locus
) != UNKNOWN_LOCATION
)
4217 input_location
= cfun
->function_end_locus
;
4219 /* Generate rtl for function exit. */
4220 expand_function_end ();
4222 end
= get_last_insn ();
4225 /* While emitting the function end we could move end of the last basic block.
4227 BB_END (EXIT_BLOCK_PTR
->prev_bb
) = orig_end
;
4228 while (NEXT_INSN (head
) && NOTE_P (NEXT_INSN (head
)))
4229 head
= NEXT_INSN (head
);
4230 exit_block
= create_basic_block (NEXT_INSN (head
), end
,
4231 EXIT_BLOCK_PTR
->prev_bb
);
4232 exit_block
->frequency
= EXIT_BLOCK_PTR
->frequency
;
4233 exit_block
->count
= EXIT_BLOCK_PTR
->count
;
4234 if (current_loops
&& EXIT_BLOCK_PTR
->loop_father
)
4235 add_bb_to_loop (exit_block
, EXIT_BLOCK_PTR
->loop_father
);
4238 while (ix
< EDGE_COUNT (EXIT_BLOCK_PTR
->preds
))
4240 e
= EDGE_PRED (EXIT_BLOCK_PTR
, ix
);
4241 if (!(e
->flags
& EDGE_ABNORMAL
))
4242 redirect_edge_succ (e
, exit_block
);
4247 e
= make_edge (exit_block
, EXIT_BLOCK_PTR
, EDGE_FALLTHRU
);
4248 e
->probability
= REG_BR_PROB_BASE
;
4249 e
->count
= EXIT_BLOCK_PTR
->count
;
4250 FOR_EACH_EDGE (e2
, ei
, EXIT_BLOCK_PTR
->preds
)
4253 e
->count
-= e2
->count
;
4254 exit_block
->count
-= e2
->count
;
4255 exit_block
->frequency
-= EDGE_FREQUENCY (e2
);
4259 if (exit_block
->count
< 0)
4260 exit_block
->count
= 0;
4261 if (exit_block
->frequency
< 0)
4262 exit_block
->frequency
= 0;
4263 update_bb_for_insn (exit_block
);
4266 /* Helper function for discover_nonconstant_array_refs.
4267 Look for ARRAY_REF nodes with non-constant indexes and mark them
4271 discover_nonconstant_array_refs_r (tree
* tp
, int *walk_subtrees
,
4272 void *data ATTRIBUTE_UNUSED
)
4276 if (IS_TYPE_OR_DECL_P (t
))
4278 else if (TREE_CODE (t
) == ARRAY_REF
|| TREE_CODE (t
) == ARRAY_RANGE_REF
)
4280 while (((TREE_CODE (t
) == ARRAY_REF
|| TREE_CODE (t
) == ARRAY_RANGE_REF
)
4281 && is_gimple_min_invariant (TREE_OPERAND (t
, 1))
4282 && (!TREE_OPERAND (t
, 2)
4283 || is_gimple_min_invariant (TREE_OPERAND (t
, 2))))
4284 || (TREE_CODE (t
) == COMPONENT_REF
4285 && (!TREE_OPERAND (t
,2)
4286 || is_gimple_min_invariant (TREE_OPERAND (t
, 2))))
4287 || TREE_CODE (t
) == BIT_FIELD_REF
4288 || TREE_CODE (t
) == REALPART_EXPR
4289 || TREE_CODE (t
) == IMAGPART_EXPR
4290 || TREE_CODE (t
) == VIEW_CONVERT_EXPR
4291 || CONVERT_EXPR_P (t
))
4292 t
= TREE_OPERAND (t
, 0);
4294 if (TREE_CODE (t
) == ARRAY_REF
|| TREE_CODE (t
) == ARRAY_RANGE_REF
)
4296 t
= get_base_address (t
);
4298 && DECL_MODE (t
) != BLKmode
)
4299 TREE_ADDRESSABLE (t
) = 1;
4308 /* RTL expansion is not able to compile array references with variable
4309 offsets for arrays stored in single register. Discover such
4310 expressions and mark variables as addressable to avoid this
4314 discover_nonconstant_array_refs (void)
4317 gimple_stmt_iterator gsi
;
4320 for (gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
4322 gimple stmt
= gsi_stmt (gsi
);
4323 if (!is_gimple_debug (stmt
))
4324 walk_gimple_op (stmt
, discover_nonconstant_array_refs_r
, NULL
);
4328 /* This function sets crtl->args.internal_arg_pointer to a virtual
4329 register if DRAP is needed. Local register allocator will replace
4330 virtual_incoming_args_rtx with the virtual register. */
4333 expand_stack_alignment (void)
4336 unsigned int preferred_stack_boundary
;
4338 if (! SUPPORTS_STACK_ALIGNMENT
)
4341 if (cfun
->calls_alloca
4342 || cfun
->has_nonlocal_label
4343 || crtl
->has_nonlocal_goto
)
4344 crtl
->need_drap
= true;
4346 /* Call update_stack_boundary here again to update incoming stack
4347 boundary. It may set incoming stack alignment to a different
4348 value after RTL expansion. TARGET_FUNCTION_OK_FOR_SIBCALL may
4349 use the minimum incoming stack alignment to check if it is OK
4350 to perform sibcall optimization since sibcall optimization will
4351 only align the outgoing stack to incoming stack boundary. */
4352 if (targetm
.calls
.update_stack_boundary
)
4353 targetm
.calls
.update_stack_boundary ();
4355 /* The incoming stack frame has to be aligned at least at
4356 parm_stack_boundary. */
4357 gcc_assert (crtl
->parm_stack_boundary
<= INCOMING_STACK_BOUNDARY
);
4359 /* Update crtl->stack_alignment_estimated and use it later to align
4360 stack. We check PREFERRED_STACK_BOUNDARY if there may be non-call
4361 exceptions since callgraph doesn't collect incoming stack alignment
4363 if (cfun
->can_throw_non_call_exceptions
4364 && PREFERRED_STACK_BOUNDARY
> crtl
->preferred_stack_boundary
)
4365 preferred_stack_boundary
= PREFERRED_STACK_BOUNDARY
;
4367 preferred_stack_boundary
= crtl
->preferred_stack_boundary
;
4368 if (preferred_stack_boundary
> crtl
->stack_alignment_estimated
)
4369 crtl
->stack_alignment_estimated
= preferred_stack_boundary
;
4370 if (preferred_stack_boundary
> crtl
->stack_alignment_needed
)
4371 crtl
->stack_alignment_needed
= preferred_stack_boundary
;
4373 gcc_assert (crtl
->stack_alignment_needed
4374 <= crtl
->stack_alignment_estimated
);
4376 crtl
->stack_realign_needed
4377 = INCOMING_STACK_BOUNDARY
< crtl
->stack_alignment_estimated
;
4378 crtl
->stack_realign_tried
= crtl
->stack_realign_needed
;
4380 crtl
->stack_realign_processed
= true;
4382 /* Target has to redefine TARGET_GET_DRAP_RTX to support stack
4384 gcc_assert (targetm
.calls
.get_drap_rtx
!= NULL
);
4385 drap_rtx
= targetm
.calls
.get_drap_rtx ();
4387 /* stack_realign_drap and drap_rtx must match. */
4388 gcc_assert ((stack_realign_drap
!= 0) == (drap_rtx
!= NULL
));
4390 /* Do nothing if NULL is returned, which means DRAP is not needed. */
4391 if (NULL
!= drap_rtx
)
4393 crtl
->args
.internal_arg_pointer
= drap_rtx
;
4395 /* Call fixup_tail_calls to clean up REG_EQUIV note if DRAP is
4397 fixup_tail_calls ();
4401 /* Translate the intermediate representation contained in the CFG
4402 from GIMPLE trees to RTL.
4404 We do conversion per basic block and preserve/update the tree CFG.
4405 This implies we have to do some magic as the CFG can simultaneously
4406 consist of basic blocks containing RTL and GIMPLE trees. This can
4407 confuse the CFG hooks, so be careful to not manipulate CFG during
4411 gimple_expand_cfg (void)
4413 basic_block bb
, init_block
;
4417 rtx var_seq
, var_ret_seq
;
4420 timevar_push (TV_OUT_OF_SSA
);
4421 rewrite_out_of_ssa (&SA
);
4422 timevar_pop (TV_OUT_OF_SSA
);
4423 SA
.partition_to_pseudo
= XCNEWVEC (rtx
, SA
.map
->num_partitions
);
4425 /* Make sure all values used by the optimization passes have sane
4429 /* Some backends want to know that we are expanding to RTL. */
4430 currently_expanding_to_rtl
= 1;
4431 /* Dominators are not kept up-to-date as we may create new basic-blocks. */
4432 free_dominance_info (CDI_DOMINATORS
);
4434 rtl_profile_for_bb (ENTRY_BLOCK_PTR
);
4436 insn_locations_init ();
4437 if (!DECL_IS_BUILTIN (current_function_decl
))
4439 /* Eventually, all FEs should explicitly set function_start_locus. */
4440 if (LOCATION_LOCUS (cfun
->function_start_locus
) == UNKNOWN_LOCATION
)
4441 set_curr_insn_location
4442 (DECL_SOURCE_LOCATION (current_function_decl
));
4444 set_curr_insn_location (cfun
->function_start_locus
);
4447 set_curr_insn_location (UNKNOWN_LOCATION
);
4448 prologue_location
= curr_insn_location ();
4450 #ifdef INSN_SCHEDULING
4451 init_sched_attrs ();
4454 /* Make sure first insn is a note even if we don't want linenums.
4455 This makes sure the first insn will never be deleted.
4456 Also, final expects a note to appear there. */
4457 emit_note (NOTE_INSN_DELETED
);
4459 /* Mark arrays indexed with non-constant indices with TREE_ADDRESSABLE. */
4460 discover_nonconstant_array_refs ();
4462 targetm
.expand_to_rtl_hook ();
4463 crtl
->stack_alignment_needed
= STACK_BOUNDARY
;
4464 crtl
->max_used_stack_slot_alignment
= STACK_BOUNDARY
;
4465 crtl
->stack_alignment_estimated
= 0;
4466 crtl
->preferred_stack_boundary
= STACK_BOUNDARY
;
4467 cfun
->cfg
->max_jumptable_ents
= 0;
4469 /* Resovle the function section. Some targets, like ARM EABI rely on knowledge
4470 of the function section at exapnsion time to predict distance of calls. */
4471 resolve_unique_section (current_function_decl
, 0, flag_function_sections
);
4473 /* Expand the variables recorded during gimple lowering. */
4474 timevar_push (TV_VAR_EXPAND
);
4477 var_ret_seq
= expand_used_vars ();
4479 var_seq
= get_insns ();
4481 timevar_pop (TV_VAR_EXPAND
);
4483 /* Honor stack protection warnings. */
4484 if (warn_stack_protect
)
4486 if (cfun
->calls_alloca
)
4487 warning (OPT_Wstack_protector
,
4488 "stack protector not protecting local variables: "
4489 "variable length buffer");
4490 if (has_short_buffer
&& !crtl
->stack_protect_guard
)
4491 warning (OPT_Wstack_protector
,
4492 "stack protector not protecting function: "
4493 "all local arrays are less than %d bytes long",
4494 (int) PARAM_VALUE (PARAM_SSP_BUFFER_SIZE
));
4497 /* Set up parameters and prepare for return, for the function. */
4498 expand_function_start (current_function_decl
);
4500 /* If we emitted any instructions for setting up the variables,
4501 emit them before the FUNCTION_START note. */
4504 emit_insn_before (var_seq
, parm_birth_insn
);
4506 /* In expand_function_end we'll insert the alloca save/restore
4507 before parm_birth_insn. We've just insertted an alloca call.
4508 Adjust the pointer to match. */
4509 parm_birth_insn
= var_seq
;
4512 /* Now that we also have the parameter RTXs, copy them over to our
4514 for (i
= 0; i
< SA
.map
->num_partitions
; i
++)
4516 tree var
= SSA_NAME_VAR (partition_to_var (SA
.map
, i
));
4518 if (TREE_CODE (var
) != VAR_DECL
4519 && !SA
.partition_to_pseudo
[i
])
4520 SA
.partition_to_pseudo
[i
] = DECL_RTL_IF_SET (var
);
4521 gcc_assert (SA
.partition_to_pseudo
[i
]);
4523 /* If this decl was marked as living in multiple places, reset
4524 this now to NULL. */
4525 if (DECL_RTL_IF_SET (var
) == pc_rtx
)
4526 SET_DECL_RTL (var
, NULL
);
4528 /* Some RTL parts really want to look at DECL_RTL(x) when x
4529 was a decl marked in REG_ATTR or MEM_ATTR. We could use
4530 SET_DECL_RTL here making this available, but that would mean
4531 to select one of the potentially many RTLs for one DECL. Instead
4532 of doing that we simply reset the MEM_EXPR of the RTL in question,
4533 then nobody can get at it and hence nobody can call DECL_RTL on it. */
4534 if (!DECL_RTL_SET_P (var
))
4536 if (MEM_P (SA
.partition_to_pseudo
[i
]))
4537 set_mem_expr (SA
.partition_to_pseudo
[i
], NULL
);
4541 /* If we have a class containing differently aligned pointers
4542 we need to merge those into the corresponding RTL pointer
4544 for (i
= 1; i
< num_ssa_names
; i
++)
4546 tree name
= ssa_name (i
);
4551 /* We might have generated new SSA names in
4552 update_alias_info_with_stack_vars. They will have a NULL
4553 defining statements, and won't be part of the partitioning,
4555 || !SSA_NAME_DEF_STMT (name
))
4557 part
= var_to_partition (SA
.map
, name
);
4558 if (part
== NO_PARTITION
)
4561 /* Adjust all partition members to get the underlying decl of
4562 the representative which we might have created in expand_one_var. */
4563 if (SSA_NAME_VAR (name
) == NULL_TREE
)
4565 tree leader
= partition_to_var (SA
.map
, part
);
4566 gcc_assert (SSA_NAME_VAR (leader
) != NULL_TREE
);
4567 replace_ssa_name_symbol (name
, SSA_NAME_VAR (leader
));
4569 if (!POINTER_TYPE_P (TREE_TYPE (name
)))
4572 r
= SA
.partition_to_pseudo
[part
];
4574 mark_reg_pointer (r
, get_pointer_alignment (name
));
4577 /* If this function is `main', emit a call to `__main'
4578 to run global initializers, etc. */
4579 if (DECL_NAME (current_function_decl
)
4580 && MAIN_NAME_P (DECL_NAME (current_function_decl
))
4581 && DECL_FILE_SCOPE_P (current_function_decl
))
4582 expand_main_function ();
4584 /* Initialize the stack_protect_guard field. This must happen after the
4585 call to __main (if any) so that the external decl is initialized. */
4586 if (crtl
->stack_protect_guard
)
4587 stack_protect_prologue ();
4589 expand_phi_nodes (&SA
);
4591 /* Register rtl specific functions for cfg. */
4592 rtl_register_cfg_hooks ();
4594 init_block
= construct_init_block ();
4596 /* Clear EDGE_EXECUTABLE on the entry edge(s). It is cleaned from the
4597 remaining edges later. */
4598 FOR_EACH_EDGE (e
, ei
, ENTRY_BLOCK_PTR
->succs
)
4599 e
->flags
&= ~EDGE_EXECUTABLE
;
4601 lab_rtx_for_bb
= pointer_map_create ();
4602 FOR_BB_BETWEEN (bb
, init_block
->next_bb
, EXIT_BLOCK_PTR
, next_bb
)
4603 bb
= expand_gimple_basic_block (bb
, var_ret_seq
!= NULL_RTX
);
4605 if (MAY_HAVE_DEBUG_INSNS
)
4606 expand_debug_locations ();
4608 /* Free stuff we no longer need after GIMPLE optimizations. */
4609 free_dominance_info (CDI_DOMINATORS
);
4610 free_dominance_info (CDI_POST_DOMINATORS
);
4611 delete_tree_cfg_annotations ();
4613 timevar_push (TV_OUT_OF_SSA
);
4614 finish_out_of_ssa (&SA
);
4615 timevar_pop (TV_OUT_OF_SSA
);
4617 timevar_push (TV_POST_EXPAND
);
4618 /* We are no longer in SSA form. */
4619 cfun
->gimple_df
->in_ssa_p
= false;
4621 loops_state_clear (LOOP_CLOSED_SSA
);
4623 /* Expansion is used by optimization passes too, set maybe_hot_insn_p
4624 conservatively to true until they are all profile aware. */
4625 pointer_map_destroy (lab_rtx_for_bb
);
4628 construct_exit_block ();
4629 insn_locations_finalize ();
4633 rtx after
= return_label
;
4634 rtx next
= NEXT_INSN (after
);
4635 if (next
&& NOTE_INSN_BASIC_BLOCK_P (next
))
4637 emit_insn_after (var_ret_seq
, after
);
4640 /* Zap the tree EH table. */
4641 set_eh_throw_stmt_table (cfun
, NULL
);
4643 /* We need JUMP_LABEL be set in order to redirect jumps, and hence
4644 split edges which edge insertions might do. */
4645 rebuild_jump_labels (get_insns ());
4647 FOR_BB_BETWEEN (bb
, ENTRY_BLOCK_PTR
, EXIT_BLOCK_PTR
, next_bb
)
4651 for (ei
= ei_start (bb
->succs
); (e
= ei_safe_edge (ei
)); )
4655 rebuild_jump_labels_chain (e
->insns
.r
);
4656 /* Avoid putting insns before parm_birth_insn. */
4657 if (e
->src
== ENTRY_BLOCK_PTR
4658 && single_succ_p (ENTRY_BLOCK_PTR
)
4661 rtx insns
= e
->insns
.r
;
4662 e
->insns
.r
= NULL_RTX
;
4663 emit_insn_after_noloc (insns
, parm_birth_insn
, e
->dest
);
4666 commit_one_edge_insertion (e
);
4673 /* We're done expanding trees to RTL. */
4674 currently_expanding_to_rtl
= 0;
4676 FOR_BB_BETWEEN (bb
, ENTRY_BLOCK_PTR
->next_bb
, EXIT_BLOCK_PTR
, next_bb
)
4680 for (ei
= ei_start (bb
->succs
); (e
= ei_safe_edge (ei
)); )
4682 /* Clear EDGE_EXECUTABLE. This flag is never used in the backend. */
4683 e
->flags
&= ~EDGE_EXECUTABLE
;
4685 /* At the moment not all abnormal edges match the RTL
4686 representation. It is safe to remove them here as
4687 find_many_sub_basic_blocks will rediscover them.
4688 In the future we should get this fixed properly. */
4689 if ((e
->flags
& EDGE_ABNORMAL
)
4690 && !(e
->flags
& EDGE_SIBCALL
))
4697 blocks
= sbitmap_alloc (last_basic_block
);
4698 bitmap_ones (blocks
);
4699 find_many_sub_basic_blocks (blocks
);
4700 sbitmap_free (blocks
);
4701 purge_all_dead_edges ();
4703 expand_stack_alignment ();
4705 /* Fixup REG_EQUIV notes in the prologue if there are tailcalls in this
4707 if (crtl
->tail_call_emit
)
4708 fixup_tail_calls ();
4710 /* After initial rtl generation, call back to finish generating
4711 exception support code. We need to do this before cleaning up
4712 the CFG as the code does not expect dead landing pads. */
4713 if (cfun
->eh
->region_tree
!= NULL
)
4714 finish_eh_generation ();
4716 /* Remove unreachable blocks, otherwise we cannot compute dominators
4717 which are needed for loop state verification. As a side-effect
4718 this also compacts blocks.
4719 ??? We cannot remove trivially dead insns here as for example
4720 the DRAP reg on i?86 is not magically live at this point.
4721 gcc.c-torture/execute/ipa-sra-2.c execution, -Os -m32 fails otherwise. */
4722 cleanup_cfg (CLEANUP_NO_INSN_DEL
);
4724 #ifdef ENABLE_CHECKING
4725 verify_flow_info ();
4728 /* Initialize pseudos allocated for hard registers. */
4729 emit_initial_value_sets ();
4731 /* And finally unshare all RTL. */
4734 /* There's no need to defer outputting this function any more; we
4735 know we want to output it. */
4736 DECL_DEFER_OUTPUT (current_function_decl
) = 0;
4738 /* Now that we're done expanding trees to RTL, we shouldn't have any
4739 more CONCATs anywhere. */
4740 generating_concat_p
= 0;
4745 "\n\n;;\n;; Full RTL generated for this function:\n;;\n");
4746 /* And the pass manager will dump RTL for us. */
4749 /* If we're emitting a nested function, make sure its parent gets
4750 emitted as well. Doing otherwise confuses debug info. */
4753 for (parent
= DECL_CONTEXT (current_function_decl
);
4754 parent
!= NULL_TREE
;
4755 parent
= get_containing_scope (parent
))
4756 if (TREE_CODE (parent
) == FUNCTION_DECL
)
4757 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent
)) = 1;
4760 /* We are now committed to emitting code for this function. Do any
4761 preparation, such as emitting abstract debug info for the inline
4762 before it gets mangled by optimization. */
4763 if (cgraph_function_possibly_inlined_p (current_function_decl
))
4764 (*debug_hooks
->outlining_inline_function
) (current_function_decl
);
4766 TREE_ASM_WRITTEN (current_function_decl
) = 1;
4768 /* After expanding, the return labels are no longer needed. */
4769 return_label
= NULL
;
4770 naked_return_label
= NULL
;
4772 /* After expanding, the tm_restart map is no longer needed. */
4773 if (cfun
->gimple_df
->tm_restart
)
4775 htab_delete (cfun
->gimple_df
->tm_restart
);
4776 cfun
->gimple_df
->tm_restart
= NULL
;
4779 /* Tag the blocks with a depth number so that change_scope can find
4780 the common parent easily. */
4781 set_block_levels (DECL_INITIAL (cfun
->decl
), 0);
4782 default_rtl_profile ();
4784 timevar_pop (TV_POST_EXPAND
);
4789 struct rtl_opt_pass pass_expand
=
4793 "expand", /* name */
4794 OPTGROUP_NONE
, /* optinfo_flags */
4796 gimple_expand_cfg
, /* execute */
4799 0, /* static_pass_number */
4800 TV_EXPAND
, /* tv_id */
4801 PROP_ssa
| PROP_gimple_leh
| PROP_cfg
4802 | PROP_gimple_lcx
, /* properties_required */
4803 PROP_rtl
, /* properties_provided */
4804 PROP_ssa
| PROP_trees
, /* properties_destroyed */
4805 TODO_verify_ssa
| TODO_verify_flow
4806 | TODO_verify_stmts
, /* todo_flags_start */
4807 TODO_ggc_collect
/* todo_flags_finish */