1 /* A pass for lowering trees to RTL.
2 Copyright (C) 2004-2013 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
25 #include "hard-reg-set.h"
27 #include "stringpool.h"
29 #include "stor-layout.h"
31 #include "print-tree.h"
33 #include "basic-block.h"
36 #include "langhooks.h"
39 #include "gimple-iterator.h"
40 #include "gimple-walk.h"
41 #include "gimple-ssa.h"
44 #include "tree-phinodes.h"
45 #include "ssa-iterators.h"
46 #include "tree-ssanames.h"
49 #include "tree-pass.h"
52 #include "diagnostic.h"
53 #include "gimple-pretty-print.h"
57 #include "tree-inline.h"
58 #include "value-prof.h"
60 #include "tree-ssa-live.h"
61 #include "tree-outof-ssa.h"
64 #include "regs.h" /* For reg_renumber. */
65 #include "insn-attr.h" /* For INSN_SCHEDULING. */
67 #include "tree-ssa-address.h"
71 /* Some systems use __main in a way incompatible with its use in gcc, in these
72 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
73 give the same symbol without quotes for an alternative entry point. You
74 must define both, or neither. */
76 #define NAME__MAIN "__main"
79 /* This variable holds information helping the rewriting of SSA trees
83 /* This variable holds the currently expanded gimple statement for purposes
84 of comminucating the profile info to the builtin expanders. */
85 gimple currently_expanding_gimple_stmt
;
87 static rtx
expand_debug_expr (tree
);
89 /* Return an expression tree corresponding to the RHS of GIMPLE
93 gimple_assign_rhs_to_tree (gimple stmt
)
96 enum gimple_rhs_class grhs_class
;
98 grhs_class
= get_gimple_rhs_class (gimple_expr_code (stmt
));
100 if (grhs_class
== GIMPLE_TERNARY_RHS
)
101 t
= build3 (gimple_assign_rhs_code (stmt
),
102 TREE_TYPE (gimple_assign_lhs (stmt
)),
103 gimple_assign_rhs1 (stmt
),
104 gimple_assign_rhs2 (stmt
),
105 gimple_assign_rhs3 (stmt
));
106 else if (grhs_class
== GIMPLE_BINARY_RHS
)
107 t
= build2 (gimple_assign_rhs_code (stmt
),
108 TREE_TYPE (gimple_assign_lhs (stmt
)),
109 gimple_assign_rhs1 (stmt
),
110 gimple_assign_rhs2 (stmt
));
111 else if (grhs_class
== GIMPLE_UNARY_RHS
)
112 t
= build1 (gimple_assign_rhs_code (stmt
),
113 TREE_TYPE (gimple_assign_lhs (stmt
)),
114 gimple_assign_rhs1 (stmt
));
115 else if (grhs_class
== GIMPLE_SINGLE_RHS
)
117 t
= gimple_assign_rhs1 (stmt
);
118 /* Avoid modifying this tree in place below. */
119 if ((gimple_has_location (stmt
) && CAN_HAVE_LOCATION_P (t
)
120 && gimple_location (stmt
) != EXPR_LOCATION (t
))
121 || (gimple_block (stmt
)
122 && currently_expanding_to_rtl
129 if (gimple_has_location (stmt
) && CAN_HAVE_LOCATION_P (t
))
130 SET_EXPR_LOCATION (t
, gimple_location (stmt
));
136 #ifndef STACK_ALIGNMENT_NEEDED
137 #define STACK_ALIGNMENT_NEEDED 1
140 #define SSAVAR(x) (TREE_CODE (x) == SSA_NAME ? SSA_NAME_VAR (x) : x)
142 /* Associate declaration T with storage space X. If T is no
143 SSA name this is exactly SET_DECL_RTL, otherwise make the
144 partition of T associated with X. */
146 set_rtl (tree t
, rtx x
)
148 if (TREE_CODE (t
) == SSA_NAME
)
150 SA
.partition_to_pseudo
[var_to_partition (SA
.map
, t
)] = x
;
152 set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (t
), x
);
153 /* For the benefit of debug information at -O0 (where vartracking
154 doesn't run) record the place also in the base DECL if it's
155 a normal variable (not a parameter). */
156 if (x
&& x
!= pc_rtx
&& TREE_CODE (SSA_NAME_VAR (t
)) == VAR_DECL
)
158 tree var
= SSA_NAME_VAR (t
);
159 /* If we don't yet have something recorded, just record it now. */
160 if (!DECL_RTL_SET_P (var
))
161 SET_DECL_RTL (var
, x
);
162 /* If we have it set already to "multiple places" don't
164 else if (DECL_RTL (var
) == pc_rtx
)
166 /* If we have something recorded and it's not the same place
167 as we want to record now, we have multiple partitions for the
168 same base variable, with different places. We can't just
169 randomly chose one, hence we have to say that we don't know.
170 This only happens with optimization, and there var-tracking
171 will figure out the right thing. */
172 else if (DECL_RTL (var
) != x
)
173 SET_DECL_RTL (var
, pc_rtx
);
180 /* This structure holds data relevant to one variable that will be
181 placed in a stack slot. */
187 /* Initially, the size of the variable. Later, the size of the partition,
188 if this variable becomes it's partition's representative. */
191 /* The *byte* alignment required for this variable. Or as, with the
192 size, the alignment for this partition. */
195 /* The partition representative. */
196 size_t representative
;
198 /* The next stack variable in the partition, or EOC. */
201 /* The numbers of conflicting stack variables. */
205 #define EOC ((size_t)-1)
207 /* We have an array of such objects while deciding allocation. */
208 static struct stack_var
*stack_vars
;
209 static size_t stack_vars_alloc
;
210 static size_t stack_vars_num
;
211 static struct pointer_map_t
*decl_to_stack_part
;
213 /* Conflict bitmaps go on this obstack. This allows us to destroy
214 all of them in one big sweep. */
215 static bitmap_obstack stack_var_bitmap_obstack
;
217 /* An array of indices such that stack_vars[stack_vars_sorted[i]].size
218 is non-decreasing. */
219 static size_t *stack_vars_sorted
;
221 /* The phase of the stack frame. This is the known misalignment of
222 virtual_stack_vars_rtx from PREFERRED_STACK_BOUNDARY. That is,
223 (frame_offset+frame_phase) % PREFERRED_STACK_BOUNDARY == 0. */
224 static int frame_phase
;
226 /* Used during expand_used_vars to remember if we saw any decls for
227 which we'd like to enable stack smashing protection. */
228 static bool has_protected_decls
;
230 /* Used during expand_used_vars. Remember if we say a character buffer
231 smaller than our cutoff threshold. Used for -Wstack-protector. */
232 static bool has_short_buffer
;
234 /* Compute the byte alignment to use for DECL. Ignore alignment
235 we can't do with expected alignment of the stack boundary. */
238 align_local_variable (tree decl
)
240 unsigned int align
= LOCAL_DECL_ALIGNMENT (decl
);
241 DECL_ALIGN (decl
) = align
;
242 return align
/ BITS_PER_UNIT
;
245 /* Allocate SIZE bytes at byte alignment ALIGN from the stack frame.
246 Return the frame offset. */
249 alloc_stack_frame_space (HOST_WIDE_INT size
, unsigned HOST_WIDE_INT align
)
251 HOST_WIDE_INT offset
, new_frame_offset
;
253 new_frame_offset
= frame_offset
;
254 if (FRAME_GROWS_DOWNWARD
)
256 new_frame_offset
-= size
+ frame_phase
;
257 new_frame_offset
&= -align
;
258 new_frame_offset
+= frame_phase
;
259 offset
= new_frame_offset
;
263 new_frame_offset
-= frame_phase
;
264 new_frame_offset
+= align
- 1;
265 new_frame_offset
&= -align
;
266 new_frame_offset
+= frame_phase
;
267 offset
= new_frame_offset
;
268 new_frame_offset
+= size
;
270 frame_offset
= new_frame_offset
;
272 if (frame_offset_overflow (frame_offset
, cfun
->decl
))
273 frame_offset
= offset
= 0;
278 /* Accumulate DECL into STACK_VARS. */
281 add_stack_var (tree decl
)
285 if (stack_vars_num
>= stack_vars_alloc
)
287 if (stack_vars_alloc
)
288 stack_vars_alloc
= stack_vars_alloc
* 3 / 2;
290 stack_vars_alloc
= 32;
292 = XRESIZEVEC (struct stack_var
, stack_vars
, stack_vars_alloc
);
294 if (!decl_to_stack_part
)
295 decl_to_stack_part
= pointer_map_create ();
297 v
= &stack_vars
[stack_vars_num
];
298 * (size_t *)pointer_map_insert (decl_to_stack_part
, decl
) = stack_vars_num
;
301 v
->size
= tree_to_uhwi (DECL_SIZE_UNIT (SSAVAR (decl
)));
302 /* Ensure that all variables have size, so that &a != &b for any two
303 variables that are simultaneously live. */
306 v
->alignb
= align_local_variable (SSAVAR (decl
));
307 /* An alignment of zero can mightily confuse us later. */
308 gcc_assert (v
->alignb
!= 0);
310 /* All variables are initially in their own partition. */
311 v
->representative
= stack_vars_num
;
314 /* All variables initially conflict with no other. */
317 /* Ensure that this decl doesn't get put onto the list twice. */
318 set_rtl (decl
, pc_rtx
);
323 /* Make the decls associated with luid's X and Y conflict. */
326 add_stack_var_conflict (size_t x
, size_t y
)
328 struct stack_var
*a
= &stack_vars
[x
];
329 struct stack_var
*b
= &stack_vars
[y
];
331 a
->conflicts
= BITMAP_ALLOC (&stack_var_bitmap_obstack
);
333 b
->conflicts
= BITMAP_ALLOC (&stack_var_bitmap_obstack
);
334 bitmap_set_bit (a
->conflicts
, y
);
335 bitmap_set_bit (b
->conflicts
, x
);
338 /* Check whether the decls associated with luid's X and Y conflict. */
341 stack_var_conflict_p (size_t x
, size_t y
)
343 struct stack_var
*a
= &stack_vars
[x
];
344 struct stack_var
*b
= &stack_vars
[y
];
347 /* Partitions containing an SSA name result from gimple registers
348 with things like unsupported modes. They are top-level and
349 hence conflict with everything else. */
350 if (TREE_CODE (a
->decl
) == SSA_NAME
|| TREE_CODE (b
->decl
) == SSA_NAME
)
353 if (!a
->conflicts
|| !b
->conflicts
)
355 return bitmap_bit_p (a
->conflicts
, y
);
358 /* Callback for walk_stmt_ops. If OP is a decl touched by add_stack_var
359 enter its partition number into bitmap DATA. */
362 visit_op (gimple stmt ATTRIBUTE_UNUSED
, tree op
, void *data
)
364 bitmap active
= (bitmap
)data
;
365 op
= get_base_address (op
);
368 && DECL_RTL_IF_SET (op
) == pc_rtx
)
370 size_t *v
= (size_t *) pointer_map_contains (decl_to_stack_part
, op
);
372 bitmap_set_bit (active
, *v
);
377 /* Callback for walk_stmt_ops. If OP is a decl touched by add_stack_var
378 record conflicts between it and all currently active other partitions
382 visit_conflict (gimple stmt ATTRIBUTE_UNUSED
, tree op
, void *data
)
384 bitmap active
= (bitmap
)data
;
385 op
= get_base_address (op
);
388 && DECL_RTL_IF_SET (op
) == pc_rtx
)
391 (size_t *) pointer_map_contains (decl_to_stack_part
, op
);
392 if (v
&& bitmap_set_bit (active
, *v
))
397 gcc_assert (num
< stack_vars_num
);
398 EXECUTE_IF_SET_IN_BITMAP (active
, 0, i
, bi
)
399 add_stack_var_conflict (num
, i
);
405 /* Helper routine for add_scope_conflicts, calculating the active partitions
406 at the end of BB, leaving the result in WORK. We're called to generate
407 conflicts when FOR_CONFLICT is true, otherwise we're just tracking
411 add_scope_conflicts_1 (basic_block bb
, bitmap work
, bool for_conflict
)
415 gimple_stmt_iterator gsi
;
416 bool (*visit
)(gimple
, tree
, void *);
419 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
420 bitmap_ior_into (work
, (bitmap
)e
->src
->aux
);
424 for (gsi
= gsi_start_phis (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
426 gimple stmt
= gsi_stmt (gsi
);
427 walk_stmt_load_store_addr_ops (stmt
, work
, NULL
, NULL
, visit
);
429 for (gsi
= gsi_after_labels (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
431 gimple stmt
= gsi_stmt (gsi
);
433 if (gimple_clobber_p (stmt
))
435 tree lhs
= gimple_assign_lhs (stmt
);
437 /* Nested function lowering might introduce LHSs
438 that are COMPONENT_REFs. */
439 if (TREE_CODE (lhs
) != VAR_DECL
)
441 if (DECL_RTL_IF_SET (lhs
) == pc_rtx
443 pointer_map_contains (decl_to_stack_part
, lhs
)))
444 bitmap_clear_bit (work
, *v
);
446 else if (!is_gimple_debug (stmt
))
449 && visit
== visit_op
)
451 /* If this is the first real instruction in this BB we need
452 to add conflicts for everything live at this point now.
453 Unlike classical liveness for named objects we can't
454 rely on seeing a def/use of the names we're interested in.
455 There might merely be indirect loads/stores. We'd not add any
456 conflicts for such partitions. */
459 EXECUTE_IF_SET_IN_BITMAP (work
, 0, i
, bi
)
461 struct stack_var
*a
= &stack_vars
[i
];
463 a
->conflicts
= BITMAP_ALLOC (&stack_var_bitmap_obstack
);
464 bitmap_ior_into (a
->conflicts
, work
);
466 visit
= visit_conflict
;
468 walk_stmt_load_store_addr_ops (stmt
, work
, visit
, visit
, visit
);
473 /* Generate stack partition conflicts between all partitions that are
474 simultaneously live. */
477 add_scope_conflicts (void)
481 bitmap work
= BITMAP_ALLOC (NULL
);
485 /* We approximate the live range of a stack variable by taking the first
486 mention of its name as starting point(s), and by the end-of-scope
487 death clobber added by gimplify as ending point(s) of the range.
488 This overapproximates in the case we for instance moved an address-taken
489 operation upward, without also moving a dereference to it upwards.
490 But it's conservatively correct as a variable never can hold values
491 before its name is mentioned at least once.
493 We then do a mostly classical bitmap liveness algorithm. */
496 bb
->aux
= BITMAP_ALLOC (&stack_var_bitmap_obstack
);
498 rpo
= XNEWVEC (int, last_basic_block
);
499 n_bbs
= pre_and_rev_post_order_compute (NULL
, rpo
, false);
506 for (i
= 0; i
< n_bbs
; i
++)
509 bb
= BASIC_BLOCK (rpo
[i
]);
510 active
= (bitmap
)bb
->aux
;
511 add_scope_conflicts_1 (bb
, work
, false);
512 if (bitmap_ior_into (active
, work
))
518 add_scope_conflicts_1 (bb
, work
, true);
523 BITMAP_FREE (bb
->aux
);
526 /* A subroutine of partition_stack_vars. A comparison function for qsort,
527 sorting an array of indices by the properties of the object. */
530 stack_var_cmp (const void *a
, const void *b
)
532 size_t ia
= *(const size_t *)a
;
533 size_t ib
= *(const size_t *)b
;
534 unsigned int aligna
= stack_vars
[ia
].alignb
;
535 unsigned int alignb
= stack_vars
[ib
].alignb
;
536 HOST_WIDE_INT sizea
= stack_vars
[ia
].size
;
537 HOST_WIDE_INT sizeb
= stack_vars
[ib
].size
;
538 tree decla
= stack_vars
[ia
].decl
;
539 tree declb
= stack_vars
[ib
].decl
;
541 unsigned int uida
, uidb
;
543 /* Primary compare on "large" alignment. Large comes first. */
544 largea
= (aligna
* BITS_PER_UNIT
> MAX_SUPPORTED_STACK_ALIGNMENT
);
545 largeb
= (alignb
* BITS_PER_UNIT
> MAX_SUPPORTED_STACK_ALIGNMENT
);
546 if (largea
!= largeb
)
547 return (int)largeb
- (int)largea
;
549 /* Secondary compare on size, decreasing */
555 /* Tertiary compare on true alignment, decreasing. */
561 /* Final compare on ID for sort stability, increasing.
562 Two SSA names are compared by their version, SSA names come before
563 non-SSA names, and two normal decls are compared by their DECL_UID. */
564 if (TREE_CODE (decla
) == SSA_NAME
)
566 if (TREE_CODE (declb
) == SSA_NAME
)
567 uida
= SSA_NAME_VERSION (decla
), uidb
= SSA_NAME_VERSION (declb
);
571 else if (TREE_CODE (declb
) == SSA_NAME
)
574 uida
= DECL_UID (decla
), uidb
= DECL_UID (declb
);
583 /* If the points-to solution *PI points to variables that are in a partition
584 together with other variables add all partition members to the pointed-to
588 add_partitioned_vars_to_ptset (struct pt_solution
*pt
,
589 struct pointer_map_t
*decls_to_partitions
,
590 struct pointer_set_t
*visited
, bitmap temp
)
598 /* The pointed-to vars bitmap is shared, it is enough to
600 || pointer_set_insert (visited
, pt
->vars
))
605 /* By using a temporary bitmap to store all members of the partitions
606 we have to add we make sure to visit each of the partitions only
608 EXECUTE_IF_SET_IN_BITMAP (pt
->vars
, 0, i
, bi
)
610 || !bitmap_bit_p (temp
, i
))
611 && (part
= (bitmap
*) pointer_map_contains (decls_to_partitions
,
612 (void *)(size_t) i
)))
613 bitmap_ior_into (temp
, *part
);
614 if (!bitmap_empty_p (temp
))
615 bitmap_ior_into (pt
->vars
, temp
);
618 /* Update points-to sets based on partition info, so we can use them on RTL.
619 The bitmaps representing stack partitions will be saved until expand,
620 where partitioned decls used as bases in memory expressions will be
624 update_alias_info_with_stack_vars (void)
626 struct pointer_map_t
*decls_to_partitions
= NULL
;
628 tree var
= NULL_TREE
;
630 for (i
= 0; i
< stack_vars_num
; i
++)
634 struct ptr_info_def
*pi
;
636 /* Not interested in partitions with single variable. */
637 if (stack_vars
[i
].representative
!= i
638 || stack_vars
[i
].next
== EOC
)
641 if (!decls_to_partitions
)
643 decls_to_partitions
= pointer_map_create ();
644 cfun
->gimple_df
->decls_to_pointers
= pointer_map_create ();
647 /* Create an SSA_NAME that points to the partition for use
648 as base during alias-oracle queries on RTL for bases that
649 have been partitioned. */
650 if (var
== NULL_TREE
)
651 var
= create_tmp_var (ptr_type_node
, NULL
);
652 name
= make_ssa_name (var
, NULL
);
654 /* Create bitmaps representing partitions. They will be used for
655 points-to sets later, so use GGC alloc. */
656 part
= BITMAP_GGC_ALLOC ();
657 for (j
= i
; j
!= EOC
; j
= stack_vars
[j
].next
)
659 tree decl
= stack_vars
[j
].decl
;
660 unsigned int uid
= DECL_PT_UID (decl
);
661 bitmap_set_bit (part
, uid
);
662 *((bitmap
*) pointer_map_insert (decls_to_partitions
,
663 (void *)(size_t) uid
)) = part
;
664 *((tree
*) pointer_map_insert (cfun
->gimple_df
->decls_to_pointers
,
666 if (TREE_ADDRESSABLE (decl
))
667 TREE_ADDRESSABLE (name
) = 1;
670 /* Make the SSA name point to all partition members. */
671 pi
= get_ptr_info (name
);
672 pt_solution_set (&pi
->pt
, part
, false);
675 /* Make all points-to sets that contain one member of a partition
676 contain all members of the partition. */
677 if (decls_to_partitions
)
680 struct pointer_set_t
*visited
= pointer_set_create ();
681 bitmap temp
= BITMAP_ALLOC (&stack_var_bitmap_obstack
);
683 for (i
= 1; i
< num_ssa_names
; i
++)
685 tree name
= ssa_name (i
);
686 struct ptr_info_def
*pi
;
689 && POINTER_TYPE_P (TREE_TYPE (name
))
690 && ((pi
= SSA_NAME_PTR_INFO (name
)) != NULL
))
691 add_partitioned_vars_to_ptset (&pi
->pt
, decls_to_partitions
,
695 add_partitioned_vars_to_ptset (&cfun
->gimple_df
->escaped
,
696 decls_to_partitions
, visited
, temp
);
698 pointer_set_destroy (visited
);
699 pointer_map_destroy (decls_to_partitions
);
704 /* A subroutine of partition_stack_vars. The UNION portion of a UNION/FIND
705 partitioning algorithm. Partitions A and B are known to be non-conflicting.
706 Merge them into a single partition A. */
709 union_stack_vars (size_t a
, size_t b
)
711 struct stack_var
*vb
= &stack_vars
[b
];
715 gcc_assert (stack_vars
[b
].next
== EOC
);
716 /* Add B to A's partition. */
717 stack_vars
[b
].next
= stack_vars
[a
].next
;
718 stack_vars
[b
].representative
= a
;
719 stack_vars
[a
].next
= b
;
721 /* Update the required alignment of partition A to account for B. */
722 if (stack_vars
[a
].alignb
< stack_vars
[b
].alignb
)
723 stack_vars
[a
].alignb
= stack_vars
[b
].alignb
;
725 /* Update the interference graph and merge the conflicts. */
728 EXECUTE_IF_SET_IN_BITMAP (vb
->conflicts
, 0, u
, bi
)
729 add_stack_var_conflict (a
, stack_vars
[u
].representative
);
730 BITMAP_FREE (vb
->conflicts
);
734 /* A subroutine of expand_used_vars. Binpack the variables into
735 partitions constrained by the interference graph. The overall
736 algorithm used is as follows:
738 Sort the objects by size in descending order.
743 Look for the largest non-conflicting object B with size <= S.
750 partition_stack_vars (void)
752 size_t si
, sj
, n
= stack_vars_num
;
754 stack_vars_sorted
= XNEWVEC (size_t, stack_vars_num
);
755 for (si
= 0; si
< n
; ++si
)
756 stack_vars_sorted
[si
] = si
;
761 qsort (stack_vars_sorted
, n
, sizeof (size_t), stack_var_cmp
);
763 for (si
= 0; si
< n
; ++si
)
765 size_t i
= stack_vars_sorted
[si
];
766 unsigned int ialign
= stack_vars
[i
].alignb
;
767 HOST_WIDE_INT isize
= stack_vars
[i
].size
;
769 /* Ignore objects that aren't partition representatives. If we
770 see a var that is not a partition representative, it must
771 have been merged earlier. */
772 if (stack_vars
[i
].representative
!= i
)
775 for (sj
= si
+ 1; sj
< n
; ++sj
)
777 size_t j
= stack_vars_sorted
[sj
];
778 unsigned int jalign
= stack_vars
[j
].alignb
;
779 HOST_WIDE_INT jsize
= stack_vars
[j
].size
;
781 /* Ignore objects that aren't partition representatives. */
782 if (stack_vars
[j
].representative
!= j
)
785 /* Do not mix objects of "small" (supported) alignment
786 and "large" (unsupported) alignment. */
787 if ((ialign
* BITS_PER_UNIT
<= MAX_SUPPORTED_STACK_ALIGNMENT
)
788 != (jalign
* BITS_PER_UNIT
<= MAX_SUPPORTED_STACK_ALIGNMENT
))
791 /* For Address Sanitizer do not mix objects with different
792 sizes, as the shorter vars wouldn't be adequately protected.
793 Don't do that for "large" (unsupported) alignment objects,
794 those aren't protected anyway. */
795 if ((flag_sanitize
& SANITIZE_ADDRESS
) && isize
!= jsize
796 && ialign
* BITS_PER_UNIT
<= MAX_SUPPORTED_STACK_ALIGNMENT
)
799 /* Ignore conflicting objects. */
800 if (stack_var_conflict_p (i
, j
))
803 /* UNION the objects, placing J at OFFSET. */
804 union_stack_vars (i
, j
);
808 update_alias_info_with_stack_vars ();
811 /* A debugging aid for expand_used_vars. Dump the generated partitions. */
814 dump_stack_var_partition (void)
816 size_t si
, i
, j
, n
= stack_vars_num
;
818 for (si
= 0; si
< n
; ++si
)
820 i
= stack_vars_sorted
[si
];
822 /* Skip variables that aren't partition representatives, for now. */
823 if (stack_vars
[i
].representative
!= i
)
826 fprintf (dump_file
, "Partition %lu: size " HOST_WIDE_INT_PRINT_DEC
827 " align %u\n", (unsigned long) i
, stack_vars
[i
].size
,
828 stack_vars
[i
].alignb
);
830 for (j
= i
; j
!= EOC
; j
= stack_vars
[j
].next
)
832 fputc ('\t', dump_file
);
833 print_generic_expr (dump_file
, stack_vars
[j
].decl
, dump_flags
);
835 fputc ('\n', dump_file
);
839 /* Assign rtl to DECL at BASE + OFFSET. */
842 expand_one_stack_var_at (tree decl
, rtx base
, unsigned base_align
,
843 HOST_WIDE_INT offset
)
848 /* If this fails, we've overflowed the stack frame. Error nicely? */
849 gcc_assert (offset
== trunc_int_for_mode (offset
, Pmode
));
851 x
= plus_constant (Pmode
, base
, offset
);
852 x
= gen_rtx_MEM (DECL_MODE (SSAVAR (decl
)), x
);
854 if (TREE_CODE (decl
) != SSA_NAME
)
856 /* Set alignment we actually gave this decl if it isn't an SSA name.
857 If it is we generate stack slots only accidentally so it isn't as
858 important, we'll simply use the alignment that is already set. */
859 if (base
== virtual_stack_vars_rtx
)
860 offset
-= frame_phase
;
861 align
= offset
& -offset
;
862 align
*= BITS_PER_UNIT
;
863 if (align
== 0 || align
> base_align
)
866 /* One would think that we could assert that we're not decreasing
867 alignment here, but (at least) the i386 port does exactly this
868 via the MINIMUM_ALIGNMENT hook. */
870 DECL_ALIGN (decl
) = align
;
871 DECL_USER_ALIGN (decl
) = 0;
874 set_mem_attributes (x
, SSAVAR (decl
), true);
878 struct stack_vars_data
880 /* Vector of offset pairs, always end of some padding followed
881 by start of the padding that needs Address Sanitizer protection.
882 The vector is in reversed, highest offset pairs come first. */
883 vec
<HOST_WIDE_INT
> asan_vec
;
885 /* Vector of partition representative decls in between the paddings. */
886 vec
<tree
> asan_decl_vec
;
889 /* A subroutine of expand_used_vars. Give each partition representative
890 a unique location within the stack frame. Update each partition member
891 with that location. */
894 expand_stack_vars (bool (*pred
) (size_t), struct stack_vars_data
*data
)
896 size_t si
, i
, j
, n
= stack_vars_num
;
897 HOST_WIDE_INT large_size
= 0, large_alloc
= 0;
898 rtx large_base
= NULL
;
899 unsigned large_align
= 0;
902 /* Determine if there are any variables requiring "large" alignment.
903 Since these are dynamically allocated, we only process these if
904 no predicate involved. */
905 large_align
= stack_vars
[stack_vars_sorted
[0]].alignb
* BITS_PER_UNIT
;
906 if (pred
== NULL
&& large_align
> MAX_SUPPORTED_STACK_ALIGNMENT
)
908 /* Find the total size of these variables. */
909 for (si
= 0; si
< n
; ++si
)
913 i
= stack_vars_sorted
[si
];
914 alignb
= stack_vars
[i
].alignb
;
916 /* Stop when we get to the first decl with "small" alignment. */
917 if (alignb
* BITS_PER_UNIT
<= MAX_SUPPORTED_STACK_ALIGNMENT
)
920 /* Skip variables that aren't partition representatives. */
921 if (stack_vars
[i
].representative
!= i
)
924 /* Skip variables that have already had rtl assigned. See also
925 add_stack_var where we perpetrate this pc_rtx hack. */
926 decl
= stack_vars
[i
].decl
;
927 if ((TREE_CODE (decl
) == SSA_NAME
928 ? SA
.partition_to_pseudo
[var_to_partition (SA
.map
, decl
)]
929 : DECL_RTL (decl
)) != pc_rtx
)
932 large_size
+= alignb
- 1;
933 large_size
&= -(HOST_WIDE_INT
)alignb
;
934 large_size
+= stack_vars
[i
].size
;
937 /* If there were any, allocate space. */
939 large_base
= allocate_dynamic_stack_space (GEN_INT (large_size
), 0,
943 for (si
= 0; si
< n
; ++si
)
946 unsigned base_align
, alignb
;
947 HOST_WIDE_INT offset
;
949 i
= stack_vars_sorted
[si
];
951 /* Skip variables that aren't partition representatives, for now. */
952 if (stack_vars
[i
].representative
!= i
)
955 /* Skip variables that have already had rtl assigned. See also
956 add_stack_var where we perpetrate this pc_rtx hack. */
957 decl
= stack_vars
[i
].decl
;
958 if ((TREE_CODE (decl
) == SSA_NAME
959 ? SA
.partition_to_pseudo
[var_to_partition (SA
.map
, decl
)]
960 : DECL_RTL (decl
)) != pc_rtx
)
963 /* Check the predicate to see whether this variable should be
964 allocated in this pass. */
965 if (pred
&& !pred (i
))
968 alignb
= stack_vars
[i
].alignb
;
969 if (alignb
* BITS_PER_UNIT
<= MAX_SUPPORTED_STACK_ALIGNMENT
)
971 if ((flag_sanitize
& SANITIZE_ADDRESS
) && pred
)
973 HOST_WIDE_INT prev_offset
= frame_offset
;
974 tree repr_decl
= NULL_TREE
;
977 = alloc_stack_frame_space (stack_vars
[i
].size
978 + ASAN_RED_ZONE_SIZE
,
979 MAX (alignb
, ASAN_RED_ZONE_SIZE
));
980 data
->asan_vec
.safe_push (prev_offset
);
981 data
->asan_vec
.safe_push (offset
+ stack_vars
[i
].size
);
982 /* Find best representative of the partition.
983 Prefer those with DECL_NAME, even better
984 satisfying asan_protect_stack_decl predicate. */
985 for (j
= i
; j
!= EOC
; j
= stack_vars
[j
].next
)
986 if (asan_protect_stack_decl (stack_vars
[j
].decl
)
987 && DECL_NAME (stack_vars
[j
].decl
))
989 repr_decl
= stack_vars
[j
].decl
;
992 else if (repr_decl
== NULL_TREE
993 && DECL_P (stack_vars
[j
].decl
)
994 && DECL_NAME (stack_vars
[j
].decl
))
995 repr_decl
= stack_vars
[j
].decl
;
996 if (repr_decl
== NULL_TREE
)
997 repr_decl
= stack_vars
[i
].decl
;
998 data
->asan_decl_vec
.safe_push (repr_decl
);
1001 offset
= alloc_stack_frame_space (stack_vars
[i
].size
, alignb
);
1002 base
= virtual_stack_vars_rtx
;
1003 base_align
= crtl
->max_used_stack_slot_alignment
;
1007 /* Large alignment is only processed in the last pass. */
1010 gcc_assert (large_base
!= NULL
);
1012 large_alloc
+= alignb
- 1;
1013 large_alloc
&= -(HOST_WIDE_INT
)alignb
;
1014 offset
= large_alloc
;
1015 large_alloc
+= stack_vars
[i
].size
;
1018 base_align
= large_align
;
1021 /* Create rtl for each variable based on their location within the
1023 for (j
= i
; j
!= EOC
; j
= stack_vars
[j
].next
)
1025 expand_one_stack_var_at (stack_vars
[j
].decl
,
1031 gcc_assert (large_alloc
== large_size
);
1034 /* Take into account all sizes of partitions and reset DECL_RTLs. */
1035 static HOST_WIDE_INT
1036 account_stack_vars (void)
1038 size_t si
, j
, i
, n
= stack_vars_num
;
1039 HOST_WIDE_INT size
= 0;
1041 for (si
= 0; si
< n
; ++si
)
1043 i
= stack_vars_sorted
[si
];
1045 /* Skip variables that aren't partition representatives, for now. */
1046 if (stack_vars
[i
].representative
!= i
)
1049 size
+= stack_vars
[i
].size
;
1050 for (j
= i
; j
!= EOC
; j
= stack_vars
[j
].next
)
1051 set_rtl (stack_vars
[j
].decl
, NULL
);
1056 /* A subroutine of expand_one_var. Called to immediately assign rtl
1057 to a variable to be allocated in the stack frame. */
1060 expand_one_stack_var (tree var
)
1062 HOST_WIDE_INT size
, offset
;
1063 unsigned byte_align
;
1065 size
= tree_to_uhwi (DECL_SIZE_UNIT (SSAVAR (var
)));
1066 byte_align
= align_local_variable (SSAVAR (var
));
1068 /* We handle highly aligned variables in expand_stack_vars. */
1069 gcc_assert (byte_align
* BITS_PER_UNIT
<= MAX_SUPPORTED_STACK_ALIGNMENT
);
1071 offset
= alloc_stack_frame_space (size
, byte_align
);
1073 expand_one_stack_var_at (var
, virtual_stack_vars_rtx
,
1074 crtl
->max_used_stack_slot_alignment
, offset
);
1077 /* A subroutine of expand_one_var. Called to assign rtl to a VAR_DECL
1078 that will reside in a hard register. */
1081 expand_one_hard_reg_var (tree var
)
1083 rest_of_decl_compilation (var
, 0, 0);
1086 /* A subroutine of expand_one_var. Called to assign rtl to a VAR_DECL
1087 that will reside in a pseudo register. */
1090 expand_one_register_var (tree var
)
1092 tree decl
= SSAVAR (var
);
1093 tree type
= TREE_TYPE (decl
);
1094 enum machine_mode reg_mode
= promote_decl_mode (decl
, NULL
);
1095 rtx x
= gen_reg_rtx (reg_mode
);
1099 /* Note if the object is a user variable. */
1100 if (!DECL_ARTIFICIAL (decl
))
1103 if (POINTER_TYPE_P (type
))
1104 mark_reg_pointer (x
, get_pointer_alignment (var
));
1107 /* A subroutine of expand_one_var. Called to assign rtl to a VAR_DECL that
1108 has some associated error, e.g. its type is error-mark. We just need
1109 to pick something that won't crash the rest of the compiler. */
1112 expand_one_error_var (tree var
)
1114 enum machine_mode mode
= DECL_MODE (var
);
1117 if (mode
== BLKmode
)
1118 x
= gen_rtx_MEM (BLKmode
, const0_rtx
);
1119 else if (mode
== VOIDmode
)
1122 x
= gen_reg_rtx (mode
);
1124 SET_DECL_RTL (var
, x
);
1127 /* A subroutine of expand_one_var. VAR is a variable that will be
1128 allocated to the local stack frame. Return true if we wish to
1129 add VAR to STACK_VARS so that it will be coalesced with other
1130 variables. Return false to allocate VAR immediately.
1132 This function is used to reduce the number of variables considered
1133 for coalescing, which reduces the size of the quadratic problem. */
1136 defer_stack_allocation (tree var
, bool toplevel
)
1138 /* Whether the variable is small enough for immediate allocation not to be
1139 a problem with regard to the frame size. */
1141 = ((HOST_WIDE_INT
) tree_to_uhwi (DECL_SIZE_UNIT (var
))
1142 < PARAM_VALUE (PARAM_MIN_SIZE_FOR_STACK_SHARING
));
1144 /* If stack protection is enabled, *all* stack variables must be deferred,
1145 so that we can re-order the strings to the top of the frame.
1146 Similarly for Address Sanitizer. */
1147 if (flag_stack_protect
|| (flag_sanitize
& SANITIZE_ADDRESS
))
1150 /* We handle "large" alignment via dynamic allocation. We want to handle
1151 this extra complication in only one place, so defer them. */
1152 if (DECL_ALIGN (var
) > MAX_SUPPORTED_STACK_ALIGNMENT
)
1155 /* When optimization is enabled, DECL_IGNORED_P variables originally scoped
1156 might be detached from their block and appear at toplevel when we reach
1157 here. We want to coalesce them with variables from other blocks when
1158 the immediate contribution to the frame size would be noticeable. */
1159 if (toplevel
&& optimize
> 0 && DECL_IGNORED_P (var
) && !smallish
)
1162 /* Variables declared in the outermost scope automatically conflict
1163 with every other variable. The only reason to want to defer them
1164 at all is that, after sorting, we can more efficiently pack
1165 small variables in the stack frame. Continue to defer at -O2. */
1166 if (toplevel
&& optimize
< 2)
1169 /* Without optimization, *most* variables are allocated from the
1170 stack, which makes the quadratic problem large exactly when we
1171 want compilation to proceed as quickly as possible. On the
1172 other hand, we don't want the function's stack frame size to
1173 get completely out of hand. So we avoid adding scalars and
1174 "small" aggregates to the list at all. */
1175 if (optimize
== 0 && smallish
)
1181 /* A subroutine of expand_used_vars. Expand one variable according to
1182 its flavor. Variables to be placed on the stack are not actually
1183 expanded yet, merely recorded.
1184 When REALLY_EXPAND is false, only add stack values to be allocated.
1185 Return stack usage this variable is supposed to take.
1188 static HOST_WIDE_INT
1189 expand_one_var (tree var
, bool toplevel
, bool really_expand
)
1191 unsigned int align
= BITS_PER_UNIT
;
1196 if (TREE_TYPE (var
) != error_mark_node
&& TREE_CODE (var
) == VAR_DECL
)
1198 /* Because we don't know if VAR will be in register or on stack,
1199 we conservatively assume it will be on stack even if VAR is
1200 eventually put into register after RA pass. For non-automatic
1201 variables, which won't be on stack, we collect alignment of
1202 type and ignore user specified alignment. */
1203 if (TREE_STATIC (var
) || DECL_EXTERNAL (var
))
1204 align
= MINIMUM_ALIGNMENT (TREE_TYPE (var
),
1205 TYPE_MODE (TREE_TYPE (var
)),
1206 TYPE_ALIGN (TREE_TYPE (var
)));
1207 else if (DECL_HAS_VALUE_EXPR_P (var
)
1208 || (DECL_RTL_SET_P (var
) && MEM_P (DECL_RTL (var
))))
1209 /* Don't consider debug only variables with DECL_HAS_VALUE_EXPR_P set
1210 or variables which were assigned a stack slot already by
1211 expand_one_stack_var_at - in the latter case DECL_ALIGN has been
1212 changed from the offset chosen to it. */
1213 align
= crtl
->stack_alignment_estimated
;
1215 align
= MINIMUM_ALIGNMENT (var
, DECL_MODE (var
), DECL_ALIGN (var
));
1217 /* If the variable alignment is very large we'll dynamicaly allocate
1218 it, which means that in-frame portion is just a pointer. */
1219 if (align
> MAX_SUPPORTED_STACK_ALIGNMENT
)
1220 align
= POINTER_SIZE
;
1223 if (SUPPORTS_STACK_ALIGNMENT
1224 && crtl
->stack_alignment_estimated
< align
)
1226 /* stack_alignment_estimated shouldn't change after stack
1227 realign decision made */
1228 gcc_assert (!crtl
->stack_realign_processed
);
1229 crtl
->stack_alignment_estimated
= align
;
1232 /* stack_alignment_needed > PREFERRED_STACK_BOUNDARY is permitted.
1233 So here we only make sure stack_alignment_needed >= align. */
1234 if (crtl
->stack_alignment_needed
< align
)
1235 crtl
->stack_alignment_needed
= align
;
1236 if (crtl
->max_used_stack_slot_alignment
< align
)
1237 crtl
->max_used_stack_slot_alignment
= align
;
1239 if (TREE_CODE (origvar
) == SSA_NAME
)
1241 gcc_assert (TREE_CODE (var
) != VAR_DECL
1242 || (!DECL_EXTERNAL (var
)
1243 && !DECL_HAS_VALUE_EXPR_P (var
)
1244 && !TREE_STATIC (var
)
1245 && TREE_TYPE (var
) != error_mark_node
1246 && !DECL_HARD_REGISTER (var
)
1249 if (TREE_CODE (var
) != VAR_DECL
&& TREE_CODE (origvar
) != SSA_NAME
)
1251 else if (DECL_EXTERNAL (var
))
1253 else if (DECL_HAS_VALUE_EXPR_P (var
))
1255 else if (TREE_STATIC (var
))
1257 else if (TREE_CODE (origvar
) != SSA_NAME
&& DECL_RTL_SET_P (var
))
1259 else if (TREE_TYPE (var
) == error_mark_node
)
1262 expand_one_error_var (var
);
1264 else if (TREE_CODE (var
) == VAR_DECL
&& DECL_HARD_REGISTER (var
))
1267 expand_one_hard_reg_var (var
);
1269 else if (use_register_for_decl (var
))
1272 expand_one_register_var (origvar
);
1274 else if (! valid_constant_size_p (DECL_SIZE_UNIT (var
)))
1276 /* Reject variables which cover more than half of the address-space. */
1279 error ("size of variable %q+D is too large", var
);
1280 expand_one_error_var (var
);
1283 else if (defer_stack_allocation (var
, toplevel
))
1284 add_stack_var (origvar
);
1288 expand_one_stack_var (origvar
);
1289 return tree_to_uhwi (DECL_SIZE_UNIT (var
));
1294 /* A subroutine of expand_used_vars. Walk down through the BLOCK tree
1295 expanding variables. Those variables that can be put into registers
1296 are allocated pseudos; those that can't are put on the stack.
1298 TOPLEVEL is true if this is the outermost BLOCK. */
1301 expand_used_vars_for_block (tree block
, bool toplevel
)
1305 /* Expand all variables at this level. */
1306 for (t
= BLOCK_VARS (block
); t
; t
= DECL_CHAIN (t
))
1308 && ((TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != RESULT_DECL
)
1309 || !DECL_NONSHAREABLE (t
)))
1310 expand_one_var (t
, toplevel
, true);
1312 /* Expand all variables at containing levels. */
1313 for (t
= BLOCK_SUBBLOCKS (block
); t
; t
= BLOCK_CHAIN (t
))
1314 expand_used_vars_for_block (t
, false);
1317 /* A subroutine of expand_used_vars. Walk down through the BLOCK tree
1318 and clear TREE_USED on all local variables. */
1321 clear_tree_used (tree block
)
1325 for (t
= BLOCK_VARS (block
); t
; t
= DECL_CHAIN (t
))
1326 /* if (!TREE_STATIC (t) && !DECL_EXTERNAL (t)) */
1327 if ((TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != RESULT_DECL
)
1328 || !DECL_NONSHAREABLE (t
))
1331 for (t
= BLOCK_SUBBLOCKS (block
); t
; t
= BLOCK_CHAIN (t
))
1332 clear_tree_used (t
);
1336 SPCT_FLAG_DEFAULT
= 1,
1338 SPCT_FLAG_STRONG
= 3
1341 /* Examine TYPE and determine a bit mask of the following features. */
1343 #define SPCT_HAS_LARGE_CHAR_ARRAY 1
1344 #define SPCT_HAS_SMALL_CHAR_ARRAY 2
1345 #define SPCT_HAS_ARRAY 4
1346 #define SPCT_HAS_AGGREGATE 8
1349 stack_protect_classify_type (tree type
)
1351 unsigned int ret
= 0;
1354 switch (TREE_CODE (type
))
1357 t
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
1358 if (t
== char_type_node
1359 || t
== signed_char_type_node
1360 || t
== unsigned_char_type_node
)
1362 unsigned HOST_WIDE_INT max
= PARAM_VALUE (PARAM_SSP_BUFFER_SIZE
);
1363 unsigned HOST_WIDE_INT len
;
1365 if (!TYPE_SIZE_UNIT (type
)
1366 || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
)))
1369 len
= tree_to_uhwi (TYPE_SIZE_UNIT (type
));
1372 ret
= SPCT_HAS_SMALL_CHAR_ARRAY
| SPCT_HAS_ARRAY
;
1374 ret
= SPCT_HAS_LARGE_CHAR_ARRAY
| SPCT_HAS_ARRAY
;
1377 ret
= SPCT_HAS_ARRAY
;
1381 case QUAL_UNION_TYPE
:
1383 ret
= SPCT_HAS_AGGREGATE
;
1384 for (t
= TYPE_FIELDS (type
); t
; t
= TREE_CHAIN (t
))
1385 if (TREE_CODE (t
) == FIELD_DECL
)
1386 ret
|= stack_protect_classify_type (TREE_TYPE (t
));
1396 /* Return nonzero if DECL should be segregated into the "vulnerable" upper
1397 part of the local stack frame. Remember if we ever return nonzero for
1398 any variable in this function. The return value is the phase number in
1399 which the variable should be allocated. */
1402 stack_protect_decl_phase (tree decl
)
1404 unsigned int bits
= stack_protect_classify_type (TREE_TYPE (decl
));
1407 if (bits
& SPCT_HAS_SMALL_CHAR_ARRAY
)
1408 has_short_buffer
= true;
1410 if (flag_stack_protect
== SPCT_FLAG_ALL
1411 || flag_stack_protect
== SPCT_FLAG_STRONG
)
1413 if ((bits
& (SPCT_HAS_SMALL_CHAR_ARRAY
| SPCT_HAS_LARGE_CHAR_ARRAY
))
1414 && !(bits
& SPCT_HAS_AGGREGATE
))
1416 else if (bits
& SPCT_HAS_ARRAY
)
1420 ret
= (bits
& SPCT_HAS_LARGE_CHAR_ARRAY
) != 0;
1423 has_protected_decls
= true;
1428 /* Two helper routines that check for phase 1 and phase 2. These are used
1429 as callbacks for expand_stack_vars. */
1432 stack_protect_decl_phase_1 (size_t i
)
1434 return stack_protect_decl_phase (stack_vars
[i
].decl
) == 1;
1438 stack_protect_decl_phase_2 (size_t i
)
1440 return stack_protect_decl_phase (stack_vars
[i
].decl
) == 2;
1443 /* And helper function that checks for asan phase (with stack protector
1444 it is phase 3). This is used as callback for expand_stack_vars.
1445 Returns true if any of the vars in the partition need to be protected. */
1448 asan_decl_phase_3 (size_t i
)
1452 if (asan_protect_stack_decl (stack_vars
[i
].decl
))
1454 i
= stack_vars
[i
].next
;
1459 /* Ensure that variables in different stack protection phases conflict
1460 so that they are not merged and share the same stack slot. */
1463 add_stack_protection_conflicts (void)
1465 size_t i
, j
, n
= stack_vars_num
;
1466 unsigned char *phase
;
1468 phase
= XNEWVEC (unsigned char, n
);
1469 for (i
= 0; i
< n
; ++i
)
1470 phase
[i
] = stack_protect_decl_phase (stack_vars
[i
].decl
);
1472 for (i
= 0; i
< n
; ++i
)
1474 unsigned char ph_i
= phase
[i
];
1475 for (j
= i
+ 1; j
< n
; ++j
)
1476 if (ph_i
!= phase
[j
])
1477 add_stack_var_conflict (i
, j
);
1483 /* Create a decl for the guard at the top of the stack frame. */
1486 create_stack_guard (void)
1488 tree guard
= build_decl (DECL_SOURCE_LOCATION (current_function_decl
),
1489 VAR_DECL
, NULL
, ptr_type_node
);
1490 TREE_THIS_VOLATILE (guard
) = 1;
1491 TREE_USED (guard
) = 1;
1492 expand_one_stack_var (guard
);
1493 crtl
->stack_protect_guard
= guard
;
1496 /* Prepare for expanding variables. */
1498 init_vars_expansion (void)
1500 /* Conflict bitmaps, and a few related temporary bitmaps, go here. */
1501 bitmap_obstack_initialize (&stack_var_bitmap_obstack
);
1503 /* A map from decl to stack partition. */
1504 decl_to_stack_part
= pointer_map_create ();
1506 /* Initialize local stack smashing state. */
1507 has_protected_decls
= false;
1508 has_short_buffer
= false;
1511 /* Free up stack variable graph data. */
1513 fini_vars_expansion (void)
1515 bitmap_obstack_release (&stack_var_bitmap_obstack
);
1517 XDELETEVEC (stack_vars
);
1518 if (stack_vars_sorted
)
1519 XDELETEVEC (stack_vars_sorted
);
1521 stack_vars_sorted
= NULL
;
1522 stack_vars_alloc
= stack_vars_num
= 0;
1523 pointer_map_destroy (decl_to_stack_part
);
1524 decl_to_stack_part
= NULL
;
1527 /* Make a fair guess for the size of the stack frame of the function
1528 in NODE. This doesn't have to be exact, the result is only used in
1529 the inline heuristics. So we don't want to run the full stack var
1530 packing algorithm (which is quadratic in the number of stack vars).
1531 Instead, we calculate the total size of all stack vars. This turns
1532 out to be a pretty fair estimate -- packing of stack vars doesn't
1533 happen very often. */
1536 estimated_stack_frame_size (struct cgraph_node
*node
)
1538 HOST_WIDE_INT size
= 0;
1541 struct function
*fn
= DECL_STRUCT_FUNCTION (node
->decl
);
1545 init_vars_expansion ();
1547 FOR_EACH_LOCAL_DECL (fn
, i
, var
)
1548 if (auto_var_in_fn_p (var
, fn
->decl
))
1549 size
+= expand_one_var (var
, true, false);
1551 if (stack_vars_num
> 0)
1553 /* Fake sorting the stack vars for account_stack_vars (). */
1554 stack_vars_sorted
= XNEWVEC (size_t, stack_vars_num
);
1555 for (i
= 0; i
< stack_vars_num
; ++i
)
1556 stack_vars_sorted
[i
] = i
;
1557 size
+= account_stack_vars ();
1560 fini_vars_expansion ();
1565 /* Helper routine to check if a record or union contains an array field. */
1568 record_or_union_type_has_array_p (const_tree tree_type
)
1570 tree fields
= TYPE_FIELDS (tree_type
);
1573 for (f
= fields
; f
; f
= DECL_CHAIN (f
))
1574 if (TREE_CODE (f
) == FIELD_DECL
)
1576 tree field_type
= TREE_TYPE (f
);
1577 if (RECORD_OR_UNION_TYPE_P (field_type
)
1578 && record_or_union_type_has_array_p (field_type
))
1580 if (TREE_CODE (field_type
) == ARRAY_TYPE
)
1586 /* Expand all variables used in the function. */
1589 expand_used_vars (void)
1591 tree var
, outer_block
= DECL_INITIAL (current_function_decl
);
1592 vec
<tree
> maybe_local_decls
= vNULL
;
1593 rtx var_end_seq
= NULL_RTX
;
1594 struct pointer_map_t
*ssa_name_decls
;
1597 bool gen_stack_protect_signal
= false;
1599 /* Compute the phase of the stack frame for this function. */
1601 int align
= PREFERRED_STACK_BOUNDARY
/ BITS_PER_UNIT
;
1602 int off
= STARTING_FRAME_OFFSET
% align
;
1603 frame_phase
= off
? align
- off
: 0;
1606 /* Set TREE_USED on all variables in the local_decls. */
1607 FOR_EACH_LOCAL_DECL (cfun
, i
, var
)
1608 TREE_USED (var
) = 1;
1609 /* Clear TREE_USED on all variables associated with a block scope. */
1610 clear_tree_used (DECL_INITIAL (current_function_decl
));
1612 init_vars_expansion ();
1614 ssa_name_decls
= pointer_map_create ();
1615 for (i
= 0; i
< SA
.map
->num_partitions
; i
++)
1617 tree var
= partition_to_var (SA
.map
, i
);
1619 gcc_assert (!virtual_operand_p (var
));
1621 /* Assign decls to each SSA name partition, share decls for partitions
1622 we could have coalesced (those with the same type). */
1623 if (SSA_NAME_VAR (var
) == NULL_TREE
)
1625 void **slot
= pointer_map_insert (ssa_name_decls
, TREE_TYPE (var
));
1627 *slot
= (void *) create_tmp_reg (TREE_TYPE (var
), NULL
);
1628 replace_ssa_name_symbol (var
, (tree
) *slot
);
1631 /* Always allocate space for partitions based on VAR_DECLs. But for
1632 those based on PARM_DECLs or RESULT_DECLs and which matter for the
1633 debug info, there is no need to do so if optimization is disabled
1634 because all the SSA_NAMEs based on these DECLs have been coalesced
1635 into a single partition, which is thus assigned the canonical RTL
1636 location of the DECLs. */
1637 if (TREE_CODE (SSA_NAME_VAR (var
)) == VAR_DECL
)
1638 expand_one_var (var
, true, true);
1639 else if (DECL_IGNORED_P (SSA_NAME_VAR (var
)) || optimize
)
1641 /* This is a PARM_DECL or RESULT_DECL. For those partitions that
1642 contain the default def (representing the parm or result itself)
1643 we don't do anything here. But those which don't contain the
1644 default def (representing a temporary based on the parm/result)
1645 we need to allocate space just like for normal VAR_DECLs. */
1646 if (!bitmap_bit_p (SA
.partition_has_default_def
, i
))
1648 expand_one_var (var
, true, true);
1649 gcc_assert (SA
.partition_to_pseudo
[i
]);
1653 pointer_map_destroy (ssa_name_decls
);
1655 if (flag_stack_protect
== SPCT_FLAG_STRONG
)
1656 FOR_EACH_LOCAL_DECL (cfun
, i
, var
)
1657 if (!is_global_var (var
))
1659 tree var_type
= TREE_TYPE (var
);
1660 /* Examine local referenced variables that have their addresses taken,
1661 contain an array, or are arrays. */
1662 if (TREE_CODE (var
) == VAR_DECL
1663 && (TREE_CODE (var_type
) == ARRAY_TYPE
1664 || TREE_ADDRESSABLE (var
)
1665 || (RECORD_OR_UNION_TYPE_P (var_type
)
1666 && record_or_union_type_has_array_p (var_type
))))
1668 gen_stack_protect_signal
= true;
1673 /* At this point all variables on the local_decls with TREE_USED
1674 set are not associated with any block scope. Lay them out. */
1676 len
= vec_safe_length (cfun
->local_decls
);
1677 FOR_EACH_LOCAL_DECL (cfun
, i
, var
)
1679 bool expand_now
= false;
1681 /* Expanded above already. */
1682 if (is_gimple_reg (var
))
1684 TREE_USED (var
) = 0;
1687 /* We didn't set a block for static or extern because it's hard
1688 to tell the difference between a global variable (re)declared
1689 in a local scope, and one that's really declared there to
1690 begin with. And it doesn't really matter much, since we're
1691 not giving them stack space. Expand them now. */
1692 else if (TREE_STATIC (var
) || DECL_EXTERNAL (var
))
1695 /* Expand variables not associated with any block now. Those created by
1696 the optimizers could be live anywhere in the function. Those that
1697 could possibly have been scoped originally and detached from their
1698 block will have their allocation deferred so we coalesce them with
1699 others when optimization is enabled. */
1700 else if (TREE_USED (var
))
1703 /* Finally, mark all variables on the list as used. We'll use
1704 this in a moment when we expand those associated with scopes. */
1705 TREE_USED (var
) = 1;
1708 expand_one_var (var
, true, true);
1711 if (DECL_ARTIFICIAL (var
) && !DECL_IGNORED_P (var
))
1713 rtx rtl
= DECL_RTL_IF_SET (var
);
1715 /* Keep artificial non-ignored vars in cfun->local_decls
1716 chain until instantiate_decls. */
1717 if (rtl
&& (MEM_P (rtl
) || GET_CODE (rtl
) == CONCAT
))
1718 add_local_decl (cfun
, var
);
1719 else if (rtl
== NULL_RTX
)
1720 /* If rtl isn't set yet, which can happen e.g. with
1721 -fstack-protector, retry before returning from this
1723 maybe_local_decls
.safe_push (var
);
1727 /* We duplicated some of the decls in CFUN->LOCAL_DECLS.
1729 +-----------------+-----------------+
1730 | ...processed... | ...duplicates...|
1731 +-----------------+-----------------+
1733 +-- LEN points here.
1735 We just want the duplicates, as those are the artificial
1736 non-ignored vars that we want to keep until instantiate_decls.
1737 Move them down and truncate the array. */
1738 if (!vec_safe_is_empty (cfun
->local_decls
))
1739 cfun
->local_decls
->block_remove (0, len
);
1741 /* At this point, all variables within the block tree with TREE_USED
1742 set are actually used by the optimized function. Lay them out. */
1743 expand_used_vars_for_block (outer_block
, true);
1745 if (stack_vars_num
> 0)
1747 add_scope_conflicts ();
1749 /* If stack protection is enabled, we don't share space between
1750 vulnerable data and non-vulnerable data. */
1751 if (flag_stack_protect
)
1752 add_stack_protection_conflicts ();
1754 /* Now that we have collected all stack variables, and have computed a
1755 minimal interference graph, attempt to save some stack space. */
1756 partition_stack_vars ();
1758 dump_stack_var_partition ();
1761 switch (flag_stack_protect
)
1764 create_stack_guard ();
1767 case SPCT_FLAG_STRONG
:
1768 if (gen_stack_protect_signal
1769 || cfun
->calls_alloca
|| has_protected_decls
)
1770 create_stack_guard ();
1773 case SPCT_FLAG_DEFAULT
:
1774 if (cfun
->calls_alloca
|| has_protected_decls
)
1775 create_stack_guard ();
1782 /* Assign rtl to each variable based on these partitions. */
1783 if (stack_vars_num
> 0)
1785 struct stack_vars_data data
;
1787 data
.asan_vec
= vNULL
;
1788 data
.asan_decl_vec
= vNULL
;
1790 /* Reorder decls to be protected by iterating over the variables
1791 array multiple times, and allocating out of each phase in turn. */
1792 /* ??? We could probably integrate this into the qsort we did
1793 earlier, such that we naturally see these variables first,
1794 and thus naturally allocate things in the right order. */
1795 if (has_protected_decls
)
1797 /* Phase 1 contains only character arrays. */
1798 expand_stack_vars (stack_protect_decl_phase_1
, &data
);
1800 /* Phase 2 contains other kinds of arrays. */
1801 if (flag_stack_protect
== 2)
1802 expand_stack_vars (stack_protect_decl_phase_2
, &data
);
1805 if (flag_sanitize
& SANITIZE_ADDRESS
)
1806 /* Phase 3, any partitions that need asan protection
1807 in addition to phase 1 and 2. */
1808 expand_stack_vars (asan_decl_phase_3
, &data
);
1810 if (!data
.asan_vec
.is_empty ())
1812 HOST_WIDE_INT prev_offset
= frame_offset
;
1813 HOST_WIDE_INT offset
1814 = alloc_stack_frame_space (ASAN_RED_ZONE_SIZE
,
1815 ASAN_RED_ZONE_SIZE
);
1816 data
.asan_vec
.safe_push (prev_offset
);
1817 data
.asan_vec
.safe_push (offset
);
1820 = asan_emit_stack_protection (virtual_stack_vars_rtx
,
1821 data
.asan_vec
.address (),
1822 data
.asan_decl_vec
. address (),
1823 data
.asan_vec
.length ());
1826 expand_stack_vars (NULL
, &data
);
1828 data
.asan_vec
.release ();
1829 data
.asan_decl_vec
.release ();
1832 fini_vars_expansion ();
1834 /* If there were any artificial non-ignored vars without rtl
1835 found earlier, see if deferred stack allocation hasn't assigned
1837 FOR_EACH_VEC_ELT_REVERSE (maybe_local_decls
, i
, var
)
1839 rtx rtl
= DECL_RTL_IF_SET (var
);
1841 /* Keep artificial non-ignored vars in cfun->local_decls
1842 chain until instantiate_decls. */
1843 if (rtl
&& (MEM_P (rtl
) || GET_CODE (rtl
) == CONCAT
))
1844 add_local_decl (cfun
, var
);
1846 maybe_local_decls
.release ();
1848 /* If the target requires that FRAME_OFFSET be aligned, do it. */
1849 if (STACK_ALIGNMENT_NEEDED
)
1851 HOST_WIDE_INT align
= PREFERRED_STACK_BOUNDARY
/ BITS_PER_UNIT
;
1852 if (!FRAME_GROWS_DOWNWARD
)
1853 frame_offset
+= align
- 1;
1854 frame_offset
&= -align
;
1861 /* If we need to produce a detailed dump, print the tree representation
1862 for STMT to the dump file. SINCE is the last RTX after which the RTL
1863 generated for STMT should have been appended. */
1866 maybe_dump_rtl_for_gimple_stmt (gimple stmt
, rtx since
)
1868 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1870 fprintf (dump_file
, "\n;; ");
1871 print_gimple_stmt (dump_file
, stmt
, 0,
1872 TDF_SLIM
| (dump_flags
& TDF_LINENO
));
1873 fprintf (dump_file
, "\n");
1875 print_rtl (dump_file
, since
? NEXT_INSN (since
) : since
);
1879 /* Maps the blocks that do not contain tree labels to rtx labels. */
1881 static struct pointer_map_t
*lab_rtx_for_bb
;
1883 /* Returns the label_rtx expression for a label starting basic block BB. */
1886 label_rtx_for_bb (basic_block bb ATTRIBUTE_UNUSED
)
1888 gimple_stmt_iterator gsi
;
1893 if (bb
->flags
& BB_RTL
)
1894 return block_label (bb
);
1896 elt
= pointer_map_contains (lab_rtx_for_bb
, bb
);
1900 /* Find the tree label if it is present. */
1902 for (gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
1904 lab_stmt
= gsi_stmt (gsi
);
1905 if (gimple_code (lab_stmt
) != GIMPLE_LABEL
)
1908 lab
= gimple_label_label (lab_stmt
);
1909 if (DECL_NONLOCAL (lab
))
1912 return label_rtx (lab
);
1915 elt
= pointer_map_insert (lab_rtx_for_bb
, bb
);
1916 *elt
= gen_label_rtx ();
1921 /* A subroutine of expand_gimple_cond. Given E, a fallthrough edge
1922 of a basic block where we just expanded the conditional at the end,
1923 possibly clean up the CFG and instruction sequence. LAST is the
1924 last instruction before the just emitted jump sequence. */
1927 maybe_cleanup_end_of_block (edge e
, rtx last
)
1929 /* Special case: when jumpif decides that the condition is
1930 trivial it emits an unconditional jump (and the necessary
1931 barrier). But we still have two edges, the fallthru one is
1932 wrong. purge_dead_edges would clean this up later. Unfortunately
1933 we have to insert insns (and split edges) before
1934 find_many_sub_basic_blocks and hence before purge_dead_edges.
1935 But splitting edges might create new blocks which depend on the
1936 fact that if there are two edges there's no barrier. So the
1937 barrier would get lost and verify_flow_info would ICE. Instead
1938 of auditing all edge splitters to care for the barrier (which
1939 normally isn't there in a cleaned CFG), fix it here. */
1940 if (BARRIER_P (get_last_insn ()))
1944 /* Now, we have a single successor block, if we have insns to
1945 insert on the remaining edge we potentially will insert
1946 it at the end of this block (if the dest block isn't feasible)
1947 in order to avoid splitting the edge. This insertion will take
1948 place in front of the last jump. But we might have emitted
1949 multiple jumps (conditional and one unconditional) to the
1950 same destination. Inserting in front of the last one then
1951 is a problem. See PR 40021. We fix this by deleting all
1952 jumps except the last unconditional one. */
1953 insn
= PREV_INSN (get_last_insn ());
1954 /* Make sure we have an unconditional jump. Otherwise we're
1956 gcc_assert (JUMP_P (insn
) && !any_condjump_p (insn
));
1957 for (insn
= PREV_INSN (insn
); insn
!= last
;)
1959 insn
= PREV_INSN (insn
);
1960 if (JUMP_P (NEXT_INSN (insn
)))
1962 if (!any_condjump_p (NEXT_INSN (insn
)))
1964 gcc_assert (BARRIER_P (NEXT_INSN (NEXT_INSN (insn
))));
1965 delete_insn (NEXT_INSN (NEXT_INSN (insn
)));
1967 delete_insn (NEXT_INSN (insn
));
1973 /* A subroutine of expand_gimple_basic_block. Expand one GIMPLE_COND.
1974 Returns a new basic block if we've terminated the current basic
1975 block and created a new one. */
1978 expand_gimple_cond (basic_block bb
, gimple stmt
)
1980 basic_block new_bb
, dest
;
1985 enum tree_code code
;
1988 code
= gimple_cond_code (stmt
);
1989 op0
= gimple_cond_lhs (stmt
);
1990 op1
= gimple_cond_rhs (stmt
);
1991 /* We're sometimes presented with such code:
1995 This would expand to two comparisons which then later might
1996 be cleaned up by combine. But some pattern matchers like if-conversion
1997 work better when there's only one compare, so make up for this
1998 here as special exception if TER would have made the same change. */
2000 && TREE_CODE (op0
) == SSA_NAME
2001 && TREE_CODE (TREE_TYPE (op0
)) == BOOLEAN_TYPE
2002 && TREE_CODE (op1
) == INTEGER_CST
2003 && ((gimple_cond_code (stmt
) == NE_EXPR
2004 && integer_zerop (op1
))
2005 || (gimple_cond_code (stmt
) == EQ_EXPR
2006 && integer_onep (op1
)))
2007 && bitmap_bit_p (SA
.values
, SSA_NAME_VERSION (op0
)))
2009 gimple second
= SSA_NAME_DEF_STMT (op0
);
2010 if (gimple_code (second
) == GIMPLE_ASSIGN
)
2012 enum tree_code code2
= gimple_assign_rhs_code (second
);
2013 if (TREE_CODE_CLASS (code2
) == tcc_comparison
)
2016 op0
= gimple_assign_rhs1 (second
);
2017 op1
= gimple_assign_rhs2 (second
);
2019 /* If jumps are cheap turn some more codes into
2021 else if (BRANCH_COST (optimize_insn_for_speed_p (), false) < 4)
2023 if ((code2
== BIT_AND_EXPR
2024 && TYPE_PRECISION (TREE_TYPE (op0
)) == 1
2025 && TREE_CODE (gimple_assign_rhs2 (second
)) != INTEGER_CST
)
2026 || code2
== TRUTH_AND_EXPR
)
2028 code
= TRUTH_ANDIF_EXPR
;
2029 op0
= gimple_assign_rhs1 (second
);
2030 op1
= gimple_assign_rhs2 (second
);
2032 else if (code2
== BIT_IOR_EXPR
|| code2
== TRUTH_OR_EXPR
)
2034 code
= TRUTH_ORIF_EXPR
;
2035 op0
= gimple_assign_rhs1 (second
);
2036 op1
= gimple_assign_rhs2 (second
);
2042 last2
= last
= get_last_insn ();
2044 extract_true_false_edges_from_block (bb
, &true_edge
, &false_edge
);
2045 set_curr_insn_location (gimple_location (stmt
));
2047 /* These flags have no purpose in RTL land. */
2048 true_edge
->flags
&= ~EDGE_TRUE_VALUE
;
2049 false_edge
->flags
&= ~EDGE_FALSE_VALUE
;
2051 /* We can either have a pure conditional jump with one fallthru edge or
2052 two-way jump that needs to be decomposed into two basic blocks. */
2053 if (false_edge
->dest
== bb
->next_bb
)
2055 jumpif_1 (code
, op0
, op1
, label_rtx_for_bb (true_edge
->dest
),
2056 true_edge
->probability
);
2057 maybe_dump_rtl_for_gimple_stmt (stmt
, last
);
2058 if (true_edge
->goto_locus
!= UNKNOWN_LOCATION
)
2059 set_curr_insn_location (true_edge
->goto_locus
);
2060 false_edge
->flags
|= EDGE_FALLTHRU
;
2061 maybe_cleanup_end_of_block (false_edge
, last
);
2064 if (true_edge
->dest
== bb
->next_bb
)
2066 jumpifnot_1 (code
, op0
, op1
, label_rtx_for_bb (false_edge
->dest
),
2067 false_edge
->probability
);
2068 maybe_dump_rtl_for_gimple_stmt (stmt
, last
);
2069 if (false_edge
->goto_locus
!= UNKNOWN_LOCATION
)
2070 set_curr_insn_location (false_edge
->goto_locus
);
2071 true_edge
->flags
|= EDGE_FALLTHRU
;
2072 maybe_cleanup_end_of_block (true_edge
, last
);
2076 jumpif_1 (code
, op0
, op1
, label_rtx_for_bb (true_edge
->dest
),
2077 true_edge
->probability
);
2078 last
= get_last_insn ();
2079 if (false_edge
->goto_locus
!= UNKNOWN_LOCATION
)
2080 set_curr_insn_location (false_edge
->goto_locus
);
2081 emit_jump (label_rtx_for_bb (false_edge
->dest
));
2084 if (BARRIER_P (BB_END (bb
)))
2085 BB_END (bb
) = PREV_INSN (BB_END (bb
));
2086 update_bb_for_insn (bb
);
2088 new_bb
= create_basic_block (NEXT_INSN (last
), get_last_insn (), bb
);
2089 dest
= false_edge
->dest
;
2090 redirect_edge_succ (false_edge
, new_bb
);
2091 false_edge
->flags
|= EDGE_FALLTHRU
;
2092 new_bb
->count
= false_edge
->count
;
2093 new_bb
->frequency
= EDGE_FREQUENCY (false_edge
);
2094 if (current_loops
&& bb
->loop_father
)
2095 add_bb_to_loop (new_bb
, bb
->loop_father
);
2096 new_edge
= make_edge (new_bb
, dest
, 0);
2097 new_edge
->probability
= REG_BR_PROB_BASE
;
2098 new_edge
->count
= new_bb
->count
;
2099 if (BARRIER_P (BB_END (new_bb
)))
2100 BB_END (new_bb
) = PREV_INSN (BB_END (new_bb
));
2101 update_bb_for_insn (new_bb
);
2103 maybe_dump_rtl_for_gimple_stmt (stmt
, last2
);
2105 if (true_edge
->goto_locus
!= UNKNOWN_LOCATION
)
2107 set_curr_insn_location (true_edge
->goto_locus
);
2108 true_edge
->goto_locus
= curr_insn_location ();
2114 /* Mark all calls that can have a transaction restart. */
2117 mark_transaction_restart_calls (gimple stmt
)
2119 struct tm_restart_node dummy
;
2122 if (!cfun
->gimple_df
->tm_restart
)
2126 slot
= htab_find_slot (cfun
->gimple_df
->tm_restart
, &dummy
, NO_INSERT
);
2129 struct tm_restart_node
*n
= (struct tm_restart_node
*) *slot
;
2130 tree list
= n
->label_or_list
;
2133 for (insn
= next_real_insn (get_last_insn ());
2135 insn
= next_real_insn (insn
))
2138 if (TREE_CODE (list
) == LABEL_DECL
)
2139 add_reg_note (insn
, REG_TM
, label_rtx (list
));
2141 for (; list
; list
= TREE_CHAIN (list
))
2142 add_reg_note (insn
, REG_TM
, label_rtx (TREE_VALUE (list
)));
2146 /* A subroutine of expand_gimple_stmt_1, expanding one GIMPLE_CALL
2150 expand_call_stmt (gimple stmt
)
2152 tree exp
, decl
, lhs
;
2156 if (gimple_call_internal_p (stmt
))
2158 expand_internal_call (stmt
);
2162 decl
= gimple_call_fndecl (stmt
);
2163 builtin_p
= decl
&& DECL_BUILT_IN (decl
);
2165 /* Bind bounds call is expanded as assignment. */
2167 && DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
2168 && DECL_FUNCTION_CODE (decl
) == BUILT_IN_CHKP_BIND_BOUNDS
)
2170 expand_assignment (gimple_call_lhs (stmt
),
2171 gimple_call_arg (stmt
, 0), false);
2175 exp
= build_vl_exp (CALL_EXPR
, gimple_call_num_args (stmt
) + 3);
2176 CALL_EXPR_FN (exp
) = gimple_call_fn (stmt
);
2178 /* If this is not a builtin function, the function type through which the
2179 call is made may be different from the type of the function. */
2182 = fold_convert (build_pointer_type (gimple_call_fntype (stmt
)),
2183 CALL_EXPR_FN (exp
));
2185 TREE_TYPE (exp
) = gimple_call_return_type (stmt
);
2186 CALL_EXPR_STATIC_CHAIN (exp
) = gimple_call_chain (stmt
);
2188 for (i
= 0; i
< gimple_call_num_args (stmt
); i
++)
2190 tree arg
= gimple_call_arg (stmt
, i
);
2192 /* TER addresses into arguments of builtin functions so we have a
2193 chance to infer more correct alignment information. See PR39954. */
2195 && TREE_CODE (arg
) == SSA_NAME
2196 && (def
= get_gimple_for_ssa_name (arg
))
2197 && gimple_assign_rhs_code (def
) == ADDR_EXPR
)
2198 arg
= gimple_assign_rhs1 (def
);
2199 CALL_EXPR_ARG (exp
, i
) = arg
;
2202 if (gimple_has_side_effects (stmt
))
2203 TREE_SIDE_EFFECTS (exp
) = 1;
2205 if (gimple_call_nothrow_p (stmt
))
2206 TREE_NOTHROW (exp
) = 1;
2208 CALL_EXPR_TAILCALL (exp
) = gimple_call_tail_p (stmt
);
2209 CALL_EXPR_RETURN_SLOT_OPT (exp
) = gimple_call_return_slot_opt_p (stmt
);
2211 && DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
2212 && (DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA
2213 || DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA_WITH_ALIGN
))
2214 CALL_ALLOCA_FOR_VAR_P (exp
) = gimple_call_alloca_for_var_p (stmt
);
2216 CALL_FROM_THUNK_P (exp
) = gimple_call_from_thunk_p (stmt
);
2217 CALL_EXPR_VA_ARG_PACK (exp
) = gimple_call_va_arg_pack_p (stmt
);
2218 SET_EXPR_LOCATION (exp
, gimple_location (stmt
));
2220 /* Ensure RTL is created for debug args. */
2221 if (decl
&& DECL_HAS_DEBUG_ARGS_P (decl
))
2223 vec
<tree
, va_gc
> **debug_args
= decl_debug_args_lookup (decl
);
2228 for (ix
= 1; (*debug_args
)->iterate (ix
, &dtemp
); ix
+= 2)
2230 gcc_assert (TREE_CODE (dtemp
) == DEBUG_EXPR_DECL
);
2231 expand_debug_expr (dtemp
);
2235 lhs
= gimple_call_lhs (stmt
);
2237 expand_assignment (lhs
, exp
, false);
2239 expand_expr_real_1 (exp
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
, NULL
);
2241 mark_transaction_restart_calls (stmt
);
2245 /* Generate RTL for an asm statement (explicit assembler code).
2246 STRING is a STRING_CST node containing the assembler code text,
2247 or an ADDR_EXPR containing a STRING_CST. VOL nonzero means the
2248 insn is volatile; don't optimize it. */
2251 expand_asm_loc (tree string
, int vol
, location_t locus
)
2255 if (TREE_CODE (string
) == ADDR_EXPR
)
2256 string
= TREE_OPERAND (string
, 0);
2258 body
= gen_rtx_ASM_INPUT_loc (VOIDmode
,
2259 ggc_strdup (TREE_STRING_POINTER (string
)),
2262 MEM_VOLATILE_P (body
) = vol
;
2267 /* Return the number of times character C occurs in string S. */
2269 n_occurrences (int c
, const char *s
)
2277 /* A subroutine of expand_asm_operands. Check that all operands have
2278 the same number of alternatives. Return true if so. */
2281 check_operand_nalternatives (tree outputs
, tree inputs
)
2283 if (outputs
|| inputs
)
2285 tree tmp
= TREE_PURPOSE (outputs
? outputs
: inputs
);
2287 = n_occurrences (',', TREE_STRING_POINTER (TREE_VALUE (tmp
)));
2290 if (nalternatives
+ 1 > MAX_RECOG_ALTERNATIVES
)
2292 error ("too many alternatives in %<asm%>");
2299 const char *constraint
2300 = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tmp
)));
2302 if (n_occurrences (',', constraint
) != nalternatives
)
2304 error ("operand constraints for %<asm%> differ "
2305 "in number of alternatives");
2309 if (TREE_CHAIN (tmp
))
2310 tmp
= TREE_CHAIN (tmp
);
2312 tmp
= next
, next
= 0;
2319 /* Check for overlap between registers marked in CLOBBERED_REGS and
2320 anything inappropriate in T. Emit error and return the register
2321 variable definition for error, NULL_TREE for ok. */
2324 tree_conflicts_with_clobbers_p (tree t
, HARD_REG_SET
*clobbered_regs
)
2326 /* Conflicts between asm-declared register variables and the clobber
2327 list are not allowed. */
2328 tree overlap
= tree_overlaps_hard_reg_set (t
, clobbered_regs
);
2332 error ("asm-specifier for variable %qE conflicts with asm clobber list",
2333 DECL_NAME (overlap
));
2335 /* Reset registerness to stop multiple errors emitted for a single
2337 DECL_REGISTER (overlap
) = 0;
2344 /* Generate RTL for an asm statement with arguments.
2345 STRING is the instruction template.
2346 OUTPUTS is a list of output arguments (lvalues); INPUTS a list of inputs.
2347 Each output or input has an expression in the TREE_VALUE and
2348 a tree list in TREE_PURPOSE which in turn contains a constraint
2349 name in TREE_VALUE (or NULL_TREE) and a constraint string
2351 CLOBBERS is a list of STRING_CST nodes each naming a hard register
2352 that is clobbered by this insn.
2354 LABELS is a list of labels, and if LABELS is non-NULL, FALLTHRU_BB
2355 should be the fallthru basic block of the asm goto.
2357 Not all kinds of lvalue that may appear in OUTPUTS can be stored directly.
2358 Some elements of OUTPUTS may be replaced with trees representing temporary
2359 values. The caller should copy those temporary values to the originally
2362 VOL nonzero means the insn is volatile; don't optimize it. */
2365 expand_asm_operands (tree string
, tree outputs
, tree inputs
,
2366 tree clobbers
, tree labels
, basic_block fallthru_bb
,
2367 int vol
, location_t locus
)
2369 rtvec argvec
, constraintvec
, labelvec
;
2371 int ninputs
= list_length (inputs
);
2372 int noutputs
= list_length (outputs
);
2373 int nlabels
= list_length (labels
);
2376 HARD_REG_SET clobbered_regs
;
2377 int clobber_conflict_found
= 0;
2381 /* Vector of RTX's of evaluated output operands. */
2382 rtx
*output_rtx
= XALLOCAVEC (rtx
, noutputs
);
2383 int *inout_opnum
= XALLOCAVEC (int, noutputs
);
2384 rtx
*real_output_rtx
= XALLOCAVEC (rtx
, noutputs
);
2385 enum machine_mode
*inout_mode
= XALLOCAVEC (enum machine_mode
, noutputs
);
2386 const char **constraints
= XALLOCAVEC (const char *, noutputs
+ ninputs
);
2387 int old_generating_concat_p
= generating_concat_p
;
2388 rtx fallthru_label
= NULL_RTX
;
2390 /* An ASM with no outputs needs to be treated as volatile, for now. */
2394 if (! check_operand_nalternatives (outputs
, inputs
))
2397 string
= resolve_asm_operand_names (string
, outputs
, inputs
, labels
);
2399 /* Collect constraints. */
2401 for (t
= outputs
; t
; t
= TREE_CHAIN (t
), i
++)
2402 constraints
[i
] = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
2403 for (t
= inputs
; t
; t
= TREE_CHAIN (t
), i
++)
2404 constraints
[i
] = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
2406 /* Sometimes we wish to automatically clobber registers across an asm.
2407 Case in point is when the i386 backend moved from cc0 to a hard reg --
2408 maintaining source-level compatibility means automatically clobbering
2409 the flags register. */
2410 clobbers
= targetm
.md_asm_clobbers (outputs
, inputs
, clobbers
);
2412 /* Count the number of meaningful clobbered registers, ignoring what
2413 we would ignore later. */
2415 CLEAR_HARD_REG_SET (clobbered_regs
);
2416 for (tail
= clobbers
; tail
; tail
= TREE_CHAIN (tail
))
2418 const char *regname
;
2421 if (TREE_VALUE (tail
) == error_mark_node
)
2423 regname
= TREE_STRING_POINTER (TREE_VALUE (tail
));
2425 i
= decode_reg_name_and_count (regname
, &nregs
);
2429 error ("unknown register name %qs in %<asm%>", regname
);
2431 /* Mark clobbered registers. */
2436 for (reg
= i
; reg
< i
+ nregs
; reg
++)
2440 /* Clobbering the PIC register is an error. */
2441 if (reg
== (int) PIC_OFFSET_TABLE_REGNUM
)
2443 error ("PIC register clobbered by %qs in %<asm%>", regname
);
2447 SET_HARD_REG_BIT (clobbered_regs
, reg
);
2452 /* First pass over inputs and outputs checks validity and sets
2453 mark_addressable if needed. */
2456 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
2458 tree val
= TREE_VALUE (tail
);
2459 tree type
= TREE_TYPE (val
);
2460 const char *constraint
;
2465 /* If there's an erroneous arg, emit no insn. */
2466 if (type
== error_mark_node
)
2469 /* Try to parse the output constraint. If that fails, there's
2470 no point in going further. */
2471 constraint
= constraints
[i
];
2472 if (!parse_output_constraint (&constraint
, i
, ninputs
, noutputs
,
2473 &allows_mem
, &allows_reg
, &is_inout
))
2480 && REG_P (DECL_RTL (val
))
2481 && GET_MODE (DECL_RTL (val
)) != TYPE_MODE (type
))))
2482 mark_addressable (val
);
2489 if (ninputs
+ noutputs
> MAX_RECOG_OPERANDS
)
2491 error ("more than %d operands in %<asm%>", MAX_RECOG_OPERANDS
);
2495 for (i
= 0, tail
= inputs
; tail
; i
++, tail
= TREE_CHAIN (tail
))
2497 bool allows_reg
, allows_mem
;
2498 const char *constraint
;
2500 /* If there's an erroneous arg, emit no insn, because the ASM_INPUT
2501 would get VOIDmode and that could cause a crash in reload. */
2502 if (TREE_TYPE (TREE_VALUE (tail
)) == error_mark_node
)
2505 constraint
= constraints
[i
+ noutputs
];
2506 if (! parse_input_constraint (&constraint
, i
, ninputs
, noutputs
, ninout
,
2507 constraints
, &allows_mem
, &allows_reg
))
2510 if (! allows_reg
&& allows_mem
)
2511 mark_addressable (TREE_VALUE (tail
));
2514 /* Second pass evaluates arguments. */
2516 /* Make sure stack is consistent for asm goto. */
2518 do_pending_stack_adjust ();
2521 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
2523 tree val
= TREE_VALUE (tail
);
2524 tree type
= TREE_TYPE (val
);
2531 ok
= parse_output_constraint (&constraints
[i
], i
, ninputs
,
2532 noutputs
, &allows_mem
, &allows_reg
,
2536 /* If an output operand is not a decl or indirect ref and our constraint
2537 allows a register, make a temporary to act as an intermediate.
2538 Make the asm insn write into that, then our caller will copy it to
2539 the real output operand. Likewise for promoted variables. */
2541 generating_concat_p
= 0;
2543 real_output_rtx
[i
] = NULL_RTX
;
2544 if ((TREE_CODE (val
) == INDIRECT_REF
2547 && (allows_mem
|| REG_P (DECL_RTL (val
)))
2548 && ! (REG_P (DECL_RTL (val
))
2549 && GET_MODE (DECL_RTL (val
)) != TYPE_MODE (type
)))
2553 op
= expand_expr (val
, NULL_RTX
, VOIDmode
,
2554 !allows_reg
? EXPAND_MEMORY
: EXPAND_WRITE
);
2556 op
= validize_mem (op
);
2558 if (! allows_reg
&& !MEM_P (op
))
2559 error ("output number %d not directly addressable", i
);
2560 if ((! allows_mem
&& MEM_P (op
))
2561 || GET_CODE (op
) == CONCAT
)
2563 real_output_rtx
[i
] = op
;
2564 op
= gen_reg_rtx (GET_MODE (op
));
2566 emit_move_insn (op
, real_output_rtx
[i
]);
2571 op
= assign_temp (type
, 0, 1);
2572 op
= validize_mem (op
);
2573 if (!MEM_P (op
) && TREE_CODE (TREE_VALUE (tail
)) == SSA_NAME
)
2574 set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (TREE_VALUE (tail
)), op
);
2575 TREE_VALUE (tail
) = make_tree (type
, op
);
2579 generating_concat_p
= old_generating_concat_p
;
2583 inout_mode
[ninout
] = TYPE_MODE (type
);
2584 inout_opnum
[ninout
++] = i
;
2587 if (tree_conflicts_with_clobbers_p (val
, &clobbered_regs
))
2588 clobber_conflict_found
= 1;
2591 /* Make vectors for the expression-rtx, constraint strings,
2592 and named operands. */
2594 argvec
= rtvec_alloc (ninputs
);
2595 constraintvec
= rtvec_alloc (ninputs
);
2596 labelvec
= rtvec_alloc (nlabels
);
2598 body
= gen_rtx_ASM_OPERANDS ((noutputs
== 0 ? VOIDmode
2599 : GET_MODE (output_rtx
[0])),
2600 ggc_strdup (TREE_STRING_POINTER (string
)),
2601 empty_string
, 0, argvec
, constraintvec
,
2604 MEM_VOLATILE_P (body
) = vol
;
2606 /* Eval the inputs and put them into ARGVEC.
2607 Put their constraints into ASM_INPUTs and store in CONSTRAINTS. */
2609 for (i
= 0, tail
= inputs
; tail
; tail
= TREE_CHAIN (tail
), ++i
)
2611 bool allows_reg
, allows_mem
;
2612 const char *constraint
;
2617 constraint
= constraints
[i
+ noutputs
];
2618 ok
= parse_input_constraint (&constraint
, i
, ninputs
, noutputs
, ninout
,
2619 constraints
, &allows_mem
, &allows_reg
);
2622 generating_concat_p
= 0;
2624 val
= TREE_VALUE (tail
);
2625 type
= TREE_TYPE (val
);
2626 /* EXPAND_INITIALIZER will not generate code for valid initializer
2627 constants, but will still generate code for other types of operand.
2628 This is the behavior we want for constant constraints. */
2629 op
= expand_expr (val
, NULL_RTX
, VOIDmode
,
2630 allows_reg
? EXPAND_NORMAL
2631 : allows_mem
? EXPAND_MEMORY
2632 : EXPAND_INITIALIZER
);
2634 /* Never pass a CONCAT to an ASM. */
2635 if (GET_CODE (op
) == CONCAT
)
2636 op
= force_reg (GET_MODE (op
), op
);
2637 else if (MEM_P (op
))
2638 op
= validize_mem (op
);
2640 if (asm_operand_ok (op
, constraint
, NULL
) <= 0)
2642 if (allows_reg
&& TYPE_MODE (type
) != BLKmode
)
2643 op
= force_reg (TYPE_MODE (type
), op
);
2644 else if (!allows_mem
)
2645 warning (0, "asm operand %d probably doesn%'t match constraints",
2647 else if (MEM_P (op
))
2649 /* We won't recognize either volatile memory or memory
2650 with a queued address as available a memory_operand
2651 at this point. Ignore it: clearly this *is* a memory. */
2657 generating_concat_p
= old_generating_concat_p
;
2658 ASM_OPERANDS_INPUT (body
, i
) = op
;
2660 ASM_OPERANDS_INPUT_CONSTRAINT_EXP (body
, i
)
2661 = gen_rtx_ASM_INPUT (TYPE_MODE (type
),
2662 ggc_strdup (constraints
[i
+ noutputs
]));
2664 if (tree_conflicts_with_clobbers_p (val
, &clobbered_regs
))
2665 clobber_conflict_found
= 1;
2668 /* Protect all the operands from the queue now that they have all been
2671 generating_concat_p
= 0;
2673 /* For in-out operands, copy output rtx to input rtx. */
2674 for (i
= 0; i
< ninout
; i
++)
2676 int j
= inout_opnum
[i
];
2679 ASM_OPERANDS_INPUT (body
, ninputs
- ninout
+ i
)
2682 sprintf (buffer
, "%d", j
);
2683 ASM_OPERANDS_INPUT_CONSTRAINT_EXP (body
, ninputs
- ninout
+ i
)
2684 = gen_rtx_ASM_INPUT (inout_mode
[i
], ggc_strdup (buffer
));
2687 /* Copy labels to the vector. */
2688 for (i
= 0, tail
= labels
; i
< nlabels
; ++i
, tail
= TREE_CHAIN (tail
))
2691 /* If asm goto has any labels in the fallthru basic block, use
2692 a label that we emit immediately after the asm goto. Expansion
2693 may insert further instructions into the same basic block after
2694 asm goto and if we don't do this, insertion of instructions on
2695 the fallthru edge might misbehave. See PR58670. */
2697 && label_to_block_fn (cfun
, TREE_VALUE (tail
)) == fallthru_bb
)
2699 if (fallthru_label
== NULL_RTX
)
2700 fallthru_label
= gen_label_rtx ();
2704 r
= label_rtx (TREE_VALUE (tail
));
2705 ASM_OPERANDS_LABEL (body
, i
) = gen_rtx_LABEL_REF (Pmode
, r
);
2708 generating_concat_p
= old_generating_concat_p
;
2710 /* Now, for each output, construct an rtx
2711 (set OUTPUT (asm_operands INSN OUTPUTCONSTRAINT OUTPUTNUMBER
2712 ARGVEC CONSTRAINTS OPNAMES))
2713 If there is more than one, put them inside a PARALLEL. */
2715 if (nlabels
> 0 && nclobbers
== 0)
2717 gcc_assert (noutputs
== 0);
2718 emit_jump_insn (body
);
2720 else if (noutputs
== 0 && nclobbers
== 0)
2722 /* No output operands: put in a raw ASM_OPERANDS rtx. */
2725 else if (noutputs
== 1 && nclobbers
== 0)
2727 ASM_OPERANDS_OUTPUT_CONSTRAINT (body
) = ggc_strdup (constraints
[0]);
2728 emit_insn (gen_rtx_SET (VOIDmode
, output_rtx
[0], body
));
2738 body
= gen_rtx_PARALLEL (VOIDmode
, rtvec_alloc (num
+ nclobbers
));
2740 /* For each output operand, store a SET. */
2741 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
2743 XVECEXP (body
, 0, i
)
2744 = gen_rtx_SET (VOIDmode
,
2746 gen_rtx_ASM_OPERANDS
2747 (GET_MODE (output_rtx
[i
]),
2748 ggc_strdup (TREE_STRING_POINTER (string
)),
2749 ggc_strdup (constraints
[i
]),
2750 i
, argvec
, constraintvec
, labelvec
, locus
));
2752 MEM_VOLATILE_P (SET_SRC (XVECEXP (body
, 0, i
))) = vol
;
2755 /* If there are no outputs (but there are some clobbers)
2756 store the bare ASM_OPERANDS into the PARALLEL. */
2759 XVECEXP (body
, 0, i
++) = obody
;
2761 /* Store (clobber REG) for each clobbered register specified. */
2763 for (tail
= clobbers
; tail
; tail
= TREE_CHAIN (tail
))
2765 const char *regname
= TREE_STRING_POINTER (TREE_VALUE (tail
));
2767 int j
= decode_reg_name_and_count (regname
, &nregs
);
2772 if (j
== -3) /* `cc', which is not a register */
2775 if (j
== -4) /* `memory', don't cache memory across asm */
2777 XVECEXP (body
, 0, i
++)
2778 = gen_rtx_CLOBBER (VOIDmode
,
2781 gen_rtx_SCRATCH (VOIDmode
)));
2785 /* Ignore unknown register, error already signaled. */
2789 for (reg
= j
; reg
< j
+ nregs
; reg
++)
2791 /* Use QImode since that's guaranteed to clobber just
2793 clobbered_reg
= gen_rtx_REG (QImode
, reg
);
2795 /* Do sanity check for overlap between clobbers and
2796 respectively input and outputs that hasn't been
2797 handled. Such overlap should have been detected and
2799 if (!clobber_conflict_found
)
2803 /* We test the old body (obody) contents to avoid
2804 tripping over the under-construction body. */
2805 for (opno
= 0; opno
< noutputs
; opno
++)
2806 if (reg_overlap_mentioned_p (clobbered_reg
,
2809 ("asm clobber conflict with output operand");
2811 for (opno
= 0; opno
< ninputs
- ninout
; opno
++)
2812 if (reg_overlap_mentioned_p (clobbered_reg
,
2813 ASM_OPERANDS_INPUT (obody
,
2816 ("asm clobber conflict with input operand");
2819 XVECEXP (body
, 0, i
++)
2820 = gen_rtx_CLOBBER (VOIDmode
, clobbered_reg
);
2825 emit_jump_insn (body
);
2831 emit_label (fallthru_label
);
2833 /* For any outputs that needed reloading into registers, spill them
2834 back to where they belong. */
2835 for (i
= 0; i
< noutputs
; ++i
)
2836 if (real_output_rtx
[i
])
2837 emit_move_insn (real_output_rtx
[i
], output_rtx
[i
]);
2839 crtl
->has_asm_statement
= 1;
2845 expand_asm_stmt (gimple stmt
)
2848 tree outputs
, tail
, t
;
2852 tree str
, out
, in
, cl
, labels
;
2853 location_t locus
= gimple_location (stmt
);
2854 basic_block fallthru_bb
= NULL
;
2856 /* Meh... convert the gimple asm operands into real tree lists.
2857 Eventually we should make all routines work on the vectors instead
2858 of relying on TREE_CHAIN. */
2860 n
= gimple_asm_noutputs (stmt
);
2863 t
= out
= gimple_asm_output_op (stmt
, 0);
2864 for (i
= 1; i
< n
; i
++)
2865 t
= TREE_CHAIN (t
) = gimple_asm_output_op (stmt
, i
);
2869 n
= gimple_asm_ninputs (stmt
);
2872 t
= in
= gimple_asm_input_op (stmt
, 0);
2873 for (i
= 1; i
< n
; i
++)
2874 t
= TREE_CHAIN (t
) = gimple_asm_input_op (stmt
, i
);
2878 n
= gimple_asm_nclobbers (stmt
);
2881 t
= cl
= gimple_asm_clobber_op (stmt
, 0);
2882 for (i
= 1; i
< n
; i
++)
2883 t
= TREE_CHAIN (t
) = gimple_asm_clobber_op (stmt
, i
);
2887 n
= gimple_asm_nlabels (stmt
);
2890 edge fallthru
= find_fallthru_edge (gimple_bb (stmt
)->succs
);
2892 fallthru_bb
= fallthru
->dest
;
2893 t
= labels
= gimple_asm_label_op (stmt
, 0);
2894 for (i
= 1; i
< n
; i
++)
2895 t
= TREE_CHAIN (t
) = gimple_asm_label_op (stmt
, i
);
2898 s
= gimple_asm_string (stmt
);
2899 str
= build_string (strlen (s
), s
);
2901 if (gimple_asm_input_p (stmt
))
2903 expand_asm_loc (str
, gimple_asm_volatile_p (stmt
), locus
);
2908 noutputs
= gimple_asm_noutputs (stmt
);
2909 /* o[I] is the place that output number I should be written. */
2910 o
= (tree
*) alloca (noutputs
* sizeof (tree
));
2912 /* Record the contents of OUTPUTS before it is modified. */
2913 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
2914 o
[i
] = TREE_VALUE (tail
);
2916 /* Generate the ASM_OPERANDS insn; store into the TREE_VALUEs of
2917 OUTPUTS some trees for where the values were actually stored. */
2918 expand_asm_operands (str
, outputs
, in
, cl
, labels
, fallthru_bb
,
2919 gimple_asm_volatile_p (stmt
), locus
);
2921 /* Copy all the intermediate outputs into the specified outputs. */
2922 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
2924 if (o
[i
] != TREE_VALUE (tail
))
2926 expand_assignment (o
[i
], TREE_VALUE (tail
), false);
2929 /* Restore the original value so that it's correct the next
2930 time we expand this function. */
2931 TREE_VALUE (tail
) = o
[i
];
2936 /* Emit code to jump to the address
2937 specified by the pointer expression EXP. */
2940 expand_computed_goto (tree exp
)
2942 rtx x
= expand_normal (exp
);
2944 x
= convert_memory_address (Pmode
, x
);
2946 do_pending_stack_adjust ();
2947 emit_indirect_jump (x
);
2950 /* Generate RTL code for a `goto' statement with target label LABEL.
2951 LABEL should be a LABEL_DECL tree node that was or will later be
2952 defined with `expand_label'. */
2955 expand_goto (tree label
)
2957 #ifdef ENABLE_CHECKING
2958 /* Check for a nonlocal goto to a containing function. Should have
2959 gotten translated to __builtin_nonlocal_goto. */
2960 tree context
= decl_function_context (label
);
2961 gcc_assert (!context
|| context
== current_function_decl
);
2964 emit_jump (label_rtx (label
));
2967 /* Output a return with no value. */
2970 expand_null_return_1 (void)
2972 clear_pending_stack_adjust ();
2973 do_pending_stack_adjust ();
2974 emit_jump (return_label
);
2977 /* Generate RTL to return from the current function, with no value.
2978 (That is, we do not do anything about returning any value.) */
2981 expand_null_return (void)
2983 /* If this function was declared to return a value, but we
2984 didn't, clobber the return registers so that they are not
2985 propagated live to the rest of the function. */
2986 clobber_return_register ();
2988 expand_null_return_1 ();
2991 /* Generate RTL to return from the current function, with value VAL. */
2994 expand_value_return (rtx val
)
2996 /* Copy the value to the return location unless it's already there. */
2998 tree decl
= DECL_RESULT (current_function_decl
);
2999 rtx return_reg
= DECL_RTL (decl
);
3000 if (return_reg
!= val
)
3002 tree funtype
= TREE_TYPE (current_function_decl
);
3003 tree type
= TREE_TYPE (decl
);
3004 int unsignedp
= TYPE_UNSIGNED (type
);
3005 enum machine_mode old_mode
= DECL_MODE (decl
);
3006 enum machine_mode mode
;
3007 if (DECL_BY_REFERENCE (decl
))
3008 mode
= promote_function_mode (type
, old_mode
, &unsignedp
, funtype
, 2);
3010 mode
= promote_function_mode (type
, old_mode
, &unsignedp
, funtype
, 1);
3012 if (mode
!= old_mode
)
3013 val
= convert_modes (mode
, old_mode
, val
, unsignedp
);
3015 if (GET_CODE (return_reg
) == PARALLEL
)
3016 emit_group_load (return_reg
, val
, type
, int_size_in_bytes (type
));
3018 emit_move_insn (return_reg
, val
);
3021 expand_null_return_1 ();
3024 /* Generate RTL to evaluate the expression RETVAL and return it
3025 from the current function. */
3028 expand_return (tree retval
)
3034 /* If function wants no value, give it none. */
3035 if (TREE_CODE (TREE_TYPE (TREE_TYPE (current_function_decl
))) == VOID_TYPE
)
3037 expand_normal (retval
);
3038 expand_null_return ();
3042 if (retval
== error_mark_node
)
3044 /* Treat this like a return of no value from a function that
3046 expand_null_return ();
3049 else if ((TREE_CODE (retval
) == MODIFY_EXPR
3050 || TREE_CODE (retval
) == INIT_EXPR
)
3051 && TREE_CODE (TREE_OPERAND (retval
, 0)) == RESULT_DECL
)
3052 retval_rhs
= TREE_OPERAND (retval
, 1);
3054 retval_rhs
= retval
;
3056 result_rtl
= DECL_RTL (DECL_RESULT (current_function_decl
));
3058 /* If we are returning the RESULT_DECL, then the value has already
3059 been stored into it, so we don't have to do anything special. */
3060 if (TREE_CODE (retval_rhs
) == RESULT_DECL
)
3061 expand_value_return (result_rtl
);
3063 /* If the result is an aggregate that is being returned in one (or more)
3064 registers, load the registers here. */
3066 else if (retval_rhs
!= 0
3067 && TYPE_MODE (TREE_TYPE (retval_rhs
)) == BLKmode
3068 && REG_P (result_rtl
))
3070 val
= copy_blkmode_to_reg (GET_MODE (result_rtl
), retval_rhs
);
3073 /* Use the mode of the result value on the return register. */
3074 PUT_MODE (result_rtl
, GET_MODE (val
));
3075 expand_value_return (val
);
3078 expand_null_return ();
3080 else if (retval_rhs
!= 0
3081 && !VOID_TYPE_P (TREE_TYPE (retval_rhs
))
3082 && (REG_P (result_rtl
)
3083 || (GET_CODE (result_rtl
) == PARALLEL
)))
3085 /* Calculate the return value into a temporary (usually a pseudo
3087 tree ot
= TREE_TYPE (DECL_RESULT (current_function_decl
));
3088 tree nt
= build_qualified_type (ot
, TYPE_QUALS (ot
) | TYPE_QUAL_CONST
);
3090 val
= assign_temp (nt
, 0, 1);
3091 val
= expand_expr (retval_rhs
, val
, GET_MODE (val
), EXPAND_NORMAL
);
3092 val
= force_not_mem (val
);
3093 /* Return the calculated value. */
3094 expand_value_return (val
);
3098 /* No hard reg used; calculate value into hard return reg. */
3099 expand_expr (retval
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
3100 expand_value_return (result_rtl
);
3104 /* A subroutine of expand_gimple_stmt, expanding one gimple statement
3105 STMT that doesn't require special handling for outgoing edges. That
3106 is no tailcalls and no GIMPLE_COND. */
3109 expand_gimple_stmt_1 (gimple stmt
)
3113 set_curr_insn_location (gimple_location (stmt
));
3115 switch (gimple_code (stmt
))
3118 op0
= gimple_goto_dest (stmt
);
3119 if (TREE_CODE (op0
) == LABEL_DECL
)
3122 expand_computed_goto (op0
);
3125 expand_label (gimple_label_label (stmt
));
3128 case GIMPLE_PREDICT
:
3134 expand_asm_stmt (stmt
);
3137 expand_call_stmt (stmt
);
3141 op0
= gimple_return_retval (stmt
);
3143 if (op0
&& op0
!= error_mark_node
)
3145 tree result
= DECL_RESULT (current_function_decl
);
3147 /* If we are not returning the current function's RESULT_DECL,
3148 build an assignment to it. */
3151 /* I believe that a function's RESULT_DECL is unique. */
3152 gcc_assert (TREE_CODE (op0
) != RESULT_DECL
);
3154 /* ??? We'd like to use simply expand_assignment here,
3155 but this fails if the value is of BLKmode but the return
3156 decl is a register. expand_return has special handling
3157 for this combination, which eventually should move
3158 to common code. See comments there. Until then, let's
3159 build a modify expression :-/ */
3160 op0
= build2 (MODIFY_EXPR
, TREE_TYPE (result
),
3165 expand_null_return ();
3167 expand_return (op0
);
3172 tree lhs
= gimple_assign_lhs (stmt
);
3174 /* Tree expand used to fiddle with |= and &= of two bitfield
3175 COMPONENT_REFs here. This can't happen with gimple, the LHS
3176 of binary assigns must be a gimple reg. */
3178 if (TREE_CODE (lhs
) != SSA_NAME
3179 || get_gimple_rhs_class (gimple_expr_code (stmt
))
3180 == GIMPLE_SINGLE_RHS
)
3182 tree rhs
= gimple_assign_rhs1 (stmt
);
3183 gcc_assert (get_gimple_rhs_class (gimple_expr_code (stmt
))
3184 == GIMPLE_SINGLE_RHS
);
3185 if (gimple_has_location (stmt
) && CAN_HAVE_LOCATION_P (rhs
))
3186 SET_EXPR_LOCATION (rhs
, gimple_location (stmt
));
3187 if (TREE_CLOBBER_P (rhs
))
3188 /* This is a clobber to mark the going out of scope for
3192 expand_assignment (lhs
, rhs
,
3193 gimple_assign_nontemporal_move_p (stmt
));
3198 bool nontemporal
= gimple_assign_nontemporal_move_p (stmt
);
3199 struct separate_ops ops
;
3200 bool promoted
= false;
3202 target
= expand_expr (lhs
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
3203 if (GET_CODE (target
) == SUBREG
&& SUBREG_PROMOTED_VAR_P (target
))
3206 ops
.code
= gimple_assign_rhs_code (stmt
);
3207 ops
.type
= TREE_TYPE (lhs
);
3208 switch (get_gimple_rhs_class (gimple_expr_code (stmt
)))
3210 case GIMPLE_TERNARY_RHS
:
3211 ops
.op2
= gimple_assign_rhs3 (stmt
);
3213 case GIMPLE_BINARY_RHS
:
3214 ops
.op1
= gimple_assign_rhs2 (stmt
);
3216 case GIMPLE_UNARY_RHS
:
3217 ops
.op0
= gimple_assign_rhs1 (stmt
);
3222 ops
.location
= gimple_location (stmt
);
3224 /* If we want to use a nontemporal store, force the value to
3225 register first. If we store into a promoted register,
3226 don't directly expand to target. */
3227 temp
= nontemporal
|| promoted
? NULL_RTX
: target
;
3228 temp
= expand_expr_real_2 (&ops
, temp
, GET_MODE (target
),
3235 int unsignedp
= SUBREG_PROMOTED_UNSIGNED_P (target
);
3236 /* If TEMP is a VOIDmode constant, use convert_modes to make
3237 sure that we properly convert it. */
3238 if (CONSTANT_P (temp
) && GET_MODE (temp
) == VOIDmode
)
3240 temp
= convert_modes (GET_MODE (target
),
3241 TYPE_MODE (ops
.type
),
3243 temp
= convert_modes (GET_MODE (SUBREG_REG (target
)),
3244 GET_MODE (target
), temp
, unsignedp
);
3247 convert_move (SUBREG_REG (target
), temp
, unsignedp
);
3249 else if (nontemporal
&& emit_storent_insn (target
, temp
))
3253 temp
= force_operand (temp
, target
);
3255 emit_move_insn (target
, temp
);
3266 /* Expand one gimple statement STMT and return the last RTL instruction
3267 before any of the newly generated ones.
3269 In addition to generating the necessary RTL instructions this also
3270 sets REG_EH_REGION notes if necessary and sets the current source
3271 location for diagnostics. */
3274 expand_gimple_stmt (gimple stmt
)
3276 location_t saved_location
= input_location
;
3277 rtx last
= get_last_insn ();
3282 /* We need to save and restore the current source location so that errors
3283 discovered during expansion are emitted with the right location. But
3284 it would be better if the diagnostic routines used the source location
3285 embedded in the tree nodes rather than globals. */
3286 if (gimple_has_location (stmt
))
3287 input_location
= gimple_location (stmt
);
3289 expand_gimple_stmt_1 (stmt
);
3291 /* Free any temporaries used to evaluate this statement. */
3294 input_location
= saved_location
;
3296 /* Mark all insns that may trap. */
3297 lp_nr
= lookup_stmt_eh_lp (stmt
);
3301 for (insn
= next_real_insn (last
); insn
;
3302 insn
= next_real_insn (insn
))
3304 if (! find_reg_note (insn
, REG_EH_REGION
, NULL_RTX
)
3305 /* If we want exceptions for non-call insns, any
3306 may_trap_p instruction may throw. */
3307 && GET_CODE (PATTERN (insn
)) != CLOBBER
3308 && GET_CODE (PATTERN (insn
)) != USE
3309 && insn_could_throw_p (insn
))
3310 make_reg_eh_region_note (insn
, 0, lp_nr
);
3317 /* A subroutine of expand_gimple_basic_block. Expand one GIMPLE_CALL
3318 that has CALL_EXPR_TAILCALL set. Returns non-null if we actually
3319 generated a tail call (something that might be denied by the ABI
3320 rules governing the call; see calls.c).
3322 Sets CAN_FALLTHRU if we generated a *conditional* tail call, and
3323 can still reach the rest of BB. The case here is __builtin_sqrt,
3324 where the NaN result goes through the external function (with a
3325 tailcall) and the normal result happens via a sqrt instruction. */
3328 expand_gimple_tailcall (basic_block bb
, gimple stmt
, bool *can_fallthru
)
3336 last2
= last
= expand_gimple_stmt (stmt
);
3338 for (last
= NEXT_INSN (last
); last
; last
= NEXT_INSN (last
))
3339 if (CALL_P (last
) && SIBLING_CALL_P (last
))
3342 maybe_dump_rtl_for_gimple_stmt (stmt
, last2
);
3344 *can_fallthru
= true;
3348 /* ??? Wouldn't it be better to just reset any pending stack adjust?
3349 Any instructions emitted here are about to be deleted. */
3350 do_pending_stack_adjust ();
3352 /* Remove any non-eh, non-abnormal edges that don't go to exit. */
3353 /* ??? I.e. the fallthrough edge. HOWEVER! If there were to be
3354 EH or abnormal edges, we shouldn't have created a tail call in
3355 the first place. So it seems to me we should just be removing
3356 all edges here, or redirecting the existing fallthru edge to
3362 for (ei
= ei_start (bb
->succs
); (e
= ei_safe_edge (ei
)); )
3364 if (!(e
->flags
& (EDGE_ABNORMAL
| EDGE_EH
)))
3366 if (e
->dest
!= EXIT_BLOCK_PTR
)
3368 e
->dest
->count
-= e
->count
;
3369 e
->dest
->frequency
-= EDGE_FREQUENCY (e
);
3370 if (e
->dest
->count
< 0)
3372 if (e
->dest
->frequency
< 0)
3373 e
->dest
->frequency
= 0;
3376 probability
+= e
->probability
;
3383 /* This is somewhat ugly: the call_expr expander often emits instructions
3384 after the sibcall (to perform the function return). These confuse the
3385 find_many_sub_basic_blocks code, so we need to get rid of these. */
3386 last
= NEXT_INSN (last
);
3387 gcc_assert (BARRIER_P (last
));
3389 *can_fallthru
= false;
3390 while (NEXT_INSN (last
))
3392 /* For instance an sqrt builtin expander expands if with
3393 sibcall in the then and label for `else`. */
3394 if (LABEL_P (NEXT_INSN (last
)))
3396 *can_fallthru
= true;
3399 delete_insn (NEXT_INSN (last
));
3402 e
= make_edge (bb
, EXIT_BLOCK_PTR
, EDGE_ABNORMAL
| EDGE_SIBCALL
);
3403 e
->probability
+= probability
;
3406 update_bb_for_insn (bb
);
3408 if (NEXT_INSN (last
))
3410 bb
= create_basic_block (NEXT_INSN (last
), get_last_insn (), bb
);
3413 if (BARRIER_P (last
))
3414 BB_END (bb
) = PREV_INSN (last
);
3417 maybe_dump_rtl_for_gimple_stmt (stmt
, last2
);
3422 /* Return the difference between the floor and the truncated result of
3423 a signed division by OP1 with remainder MOD. */
3425 floor_sdiv_adjust (enum machine_mode mode
, rtx mod
, rtx op1
)
3427 /* (mod != 0 ? (op1 / mod < 0 ? -1 : 0) : 0) */
3428 return gen_rtx_IF_THEN_ELSE
3429 (mode
, gen_rtx_NE (BImode
, mod
, const0_rtx
),
3430 gen_rtx_IF_THEN_ELSE
3431 (mode
, gen_rtx_LT (BImode
,
3432 gen_rtx_DIV (mode
, op1
, mod
),
3434 constm1_rtx
, const0_rtx
),
3438 /* Return the difference between the ceil and the truncated result of
3439 a signed division by OP1 with remainder MOD. */
3441 ceil_sdiv_adjust (enum machine_mode mode
, rtx mod
, rtx op1
)
3443 /* (mod != 0 ? (op1 / mod > 0 ? 1 : 0) : 0) */
3444 return gen_rtx_IF_THEN_ELSE
3445 (mode
, gen_rtx_NE (BImode
, mod
, const0_rtx
),
3446 gen_rtx_IF_THEN_ELSE
3447 (mode
, gen_rtx_GT (BImode
,
3448 gen_rtx_DIV (mode
, op1
, mod
),
3450 const1_rtx
, const0_rtx
),
3454 /* Return the difference between the ceil and the truncated result of
3455 an unsigned division by OP1 with remainder MOD. */
3457 ceil_udiv_adjust (enum machine_mode mode
, rtx mod
, rtx op1 ATTRIBUTE_UNUSED
)
3459 /* (mod != 0 ? 1 : 0) */
3460 return gen_rtx_IF_THEN_ELSE
3461 (mode
, gen_rtx_NE (BImode
, mod
, const0_rtx
),
3462 const1_rtx
, const0_rtx
);
3465 /* Return the difference between the rounded and the truncated result
3466 of a signed division by OP1 with remainder MOD. Halfway cases are
3467 rounded away from zero, rather than to the nearest even number. */
3469 round_sdiv_adjust (enum machine_mode mode
, rtx mod
, rtx op1
)
3471 /* (abs (mod) >= abs (op1) - abs (mod)
3472 ? (op1 / mod > 0 ? 1 : -1)
3474 return gen_rtx_IF_THEN_ELSE
3475 (mode
, gen_rtx_GE (BImode
, gen_rtx_ABS (mode
, mod
),
3476 gen_rtx_MINUS (mode
,
3477 gen_rtx_ABS (mode
, op1
),
3478 gen_rtx_ABS (mode
, mod
))),
3479 gen_rtx_IF_THEN_ELSE
3480 (mode
, gen_rtx_GT (BImode
,
3481 gen_rtx_DIV (mode
, op1
, mod
),
3483 const1_rtx
, constm1_rtx
),
3487 /* Return the difference between the rounded and the truncated result
3488 of a unsigned division by OP1 with remainder MOD. Halfway cases
3489 are rounded away from zero, rather than to the nearest even
3492 round_udiv_adjust (enum machine_mode mode
, rtx mod
, rtx op1
)
3494 /* (mod >= op1 - mod ? 1 : 0) */
3495 return gen_rtx_IF_THEN_ELSE
3496 (mode
, gen_rtx_GE (BImode
, mod
,
3497 gen_rtx_MINUS (mode
, op1
, mod
)),
3498 const1_rtx
, const0_rtx
);
3501 /* Convert X to MODE, that must be Pmode or ptr_mode, without emitting
3505 convert_debug_memory_address (enum machine_mode mode
, rtx x
,
3508 enum machine_mode xmode
= GET_MODE (x
);
3510 #ifndef POINTERS_EXTEND_UNSIGNED
3511 gcc_assert (mode
== Pmode
3512 || mode
== targetm
.addr_space
.address_mode (as
));
3513 gcc_assert (xmode
== mode
|| xmode
== VOIDmode
);
3517 gcc_assert (targetm
.addr_space
.valid_pointer_mode (mode
, as
));
3519 if (GET_MODE (x
) == mode
|| GET_MODE (x
) == VOIDmode
)
3522 if (GET_MODE_PRECISION (mode
) < GET_MODE_PRECISION (xmode
))
3523 x
= simplify_gen_subreg (mode
, x
, xmode
,
3524 subreg_lowpart_offset
3526 else if (POINTERS_EXTEND_UNSIGNED
> 0)
3527 x
= gen_rtx_ZERO_EXTEND (mode
, x
);
3528 else if (!POINTERS_EXTEND_UNSIGNED
)
3529 x
= gen_rtx_SIGN_EXTEND (mode
, x
);
3532 switch (GET_CODE (x
))
3535 if ((SUBREG_PROMOTED_VAR_P (x
)
3536 || (REG_P (SUBREG_REG (x
)) && REG_POINTER (SUBREG_REG (x
)))
3537 || (GET_CODE (SUBREG_REG (x
)) == PLUS
3538 && REG_P (XEXP (SUBREG_REG (x
), 0))
3539 && REG_POINTER (XEXP (SUBREG_REG (x
), 0))
3540 && CONST_INT_P (XEXP (SUBREG_REG (x
), 1))))
3541 && GET_MODE (SUBREG_REG (x
)) == mode
)
3542 return SUBREG_REG (x
);
3545 temp
= gen_rtx_LABEL_REF (mode
, XEXP (x
, 0));
3546 LABEL_REF_NONLOCAL_P (temp
) = LABEL_REF_NONLOCAL_P (x
);
3549 temp
= shallow_copy_rtx (x
);
3550 PUT_MODE (temp
, mode
);
3553 temp
= convert_debug_memory_address (mode
, XEXP (x
, 0), as
);
3555 temp
= gen_rtx_CONST (mode
, temp
);
3559 if (CONST_INT_P (XEXP (x
, 1)))
3561 temp
= convert_debug_memory_address (mode
, XEXP (x
, 0), as
);
3563 return gen_rtx_fmt_ee (GET_CODE (x
), mode
, temp
, XEXP (x
, 1));
3569 /* Don't know how to express ptr_extend as operation in debug info. */
3572 #endif /* POINTERS_EXTEND_UNSIGNED */
3577 /* Return an RTX equivalent to the value of the parameter DECL. */
3580 expand_debug_parm_decl (tree decl
)
3582 rtx incoming
= DECL_INCOMING_RTL (decl
);
3585 && GET_MODE (incoming
) != BLKmode
3586 && ((REG_P (incoming
) && HARD_REGISTER_P (incoming
))
3587 || (MEM_P (incoming
)
3588 && REG_P (XEXP (incoming
, 0))
3589 && HARD_REGISTER_P (XEXP (incoming
, 0)))))
3591 rtx rtl
= gen_rtx_ENTRY_VALUE (GET_MODE (incoming
));
3593 #ifdef HAVE_window_save
3594 /* DECL_INCOMING_RTL uses the INCOMING_REGNO of parameter registers.
3595 If the target machine has an explicit window save instruction, the
3596 actual entry value is the corresponding OUTGOING_REGNO instead. */
3597 if (REG_P (incoming
)
3598 && OUTGOING_REGNO (REGNO (incoming
)) != REGNO (incoming
))
3600 = gen_rtx_REG_offset (incoming
, GET_MODE (incoming
),
3601 OUTGOING_REGNO (REGNO (incoming
)), 0);
3602 else if (MEM_P (incoming
))
3604 rtx reg
= XEXP (incoming
, 0);
3605 if (OUTGOING_REGNO (REGNO (reg
)) != REGNO (reg
))
3607 reg
= gen_raw_REG (GET_MODE (reg
), OUTGOING_REGNO (REGNO (reg
)));
3608 incoming
= replace_equiv_address_nv (incoming
, reg
);
3611 incoming
= copy_rtx (incoming
);
3615 ENTRY_VALUE_EXP (rtl
) = incoming
;
3620 && GET_MODE (incoming
) != BLKmode
3621 && !TREE_ADDRESSABLE (decl
)
3623 && (XEXP (incoming
, 0) == virtual_incoming_args_rtx
3624 || (GET_CODE (XEXP (incoming
, 0)) == PLUS
3625 && XEXP (XEXP (incoming
, 0), 0) == virtual_incoming_args_rtx
3626 && CONST_INT_P (XEXP (XEXP (incoming
, 0), 1)))))
3627 return copy_rtx (incoming
);
3632 /* Return an RTX equivalent to the value of the tree expression EXP. */
3635 expand_debug_expr (tree exp
)
3637 rtx op0
= NULL_RTX
, op1
= NULL_RTX
, op2
= NULL_RTX
;
3638 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (exp
));
3639 enum machine_mode inner_mode
= VOIDmode
;
3640 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (exp
));
3643 switch (TREE_CODE_CLASS (TREE_CODE (exp
)))
3645 case tcc_expression
:
3646 switch (TREE_CODE (exp
))
3650 case WIDEN_MULT_PLUS_EXPR
:
3651 case WIDEN_MULT_MINUS_EXPR
:
3655 case TRUTH_ANDIF_EXPR
:
3656 case TRUTH_ORIF_EXPR
:
3657 case TRUTH_AND_EXPR
:
3659 case TRUTH_XOR_EXPR
:
3662 case TRUTH_NOT_EXPR
:
3671 op2
= expand_debug_expr (TREE_OPERAND (exp
, 2));
3678 case tcc_comparison
:
3679 op1
= expand_debug_expr (TREE_OPERAND (exp
, 1));
3686 inner_mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
3687 op0
= expand_debug_expr (TREE_OPERAND (exp
, 0));
3697 case tcc_exceptional
:
3698 case tcc_declaration
:
3704 switch (TREE_CODE (exp
))
3707 if (!lookup_constant_def (exp
))
3709 if (strlen (TREE_STRING_POINTER (exp
)) + 1
3710 != (size_t) TREE_STRING_LENGTH (exp
))
3712 op0
= gen_rtx_CONST_STRING (Pmode
, TREE_STRING_POINTER (exp
));
3713 op0
= gen_rtx_MEM (BLKmode
, op0
);
3714 set_mem_attributes (op0
, exp
, 0);
3717 /* Fall through... */
3722 op0
= expand_expr (exp
, NULL_RTX
, mode
, EXPAND_INITIALIZER
);
3726 gcc_assert (COMPLEX_MODE_P (mode
));
3727 op0
= expand_debug_expr (TREE_REALPART (exp
));
3728 op1
= expand_debug_expr (TREE_IMAGPART (exp
));
3729 return gen_rtx_CONCAT (mode
, op0
, op1
);
3731 case DEBUG_EXPR_DECL
:
3732 op0
= DECL_RTL_IF_SET (exp
);
3737 op0
= gen_rtx_DEBUG_EXPR (mode
);
3738 DEBUG_EXPR_TREE_DECL (op0
) = exp
;
3739 SET_DECL_RTL (exp
, op0
);
3749 op0
= DECL_RTL_IF_SET (exp
);
3751 /* This decl was probably optimized away. */
3754 if (TREE_CODE (exp
) != VAR_DECL
3755 || DECL_EXTERNAL (exp
)
3756 || !TREE_STATIC (exp
)
3758 || DECL_HARD_REGISTER (exp
)
3759 || DECL_IN_CONSTANT_POOL (exp
)
3760 || mode
== VOIDmode
)
3763 op0
= make_decl_rtl_for_debug (exp
);
3765 || GET_CODE (XEXP (op0
, 0)) != SYMBOL_REF
3766 || SYMBOL_REF_DECL (XEXP (op0
, 0)) != exp
)
3770 op0
= copy_rtx (op0
);
3772 if (GET_MODE (op0
) == BLKmode
3773 /* If op0 is not BLKmode, but BLKmode is, adjust_mode
3774 below would ICE. While it is likely a FE bug,
3775 try to be robust here. See PR43166. */
3777 || (mode
== VOIDmode
&& GET_MODE (op0
) != VOIDmode
))
3779 gcc_assert (MEM_P (op0
));
3780 op0
= adjust_address_nv (op0
, mode
, 0);
3791 inner_mode
= GET_MODE (op0
);
3793 if (mode
== inner_mode
)
3796 if (inner_mode
== VOIDmode
)
3798 if (TREE_CODE (exp
) == SSA_NAME
)
3799 inner_mode
= TYPE_MODE (TREE_TYPE (exp
));
3801 inner_mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
3802 if (mode
== inner_mode
)
3806 if (FLOAT_MODE_P (mode
) && FLOAT_MODE_P (inner_mode
))
3808 if (GET_MODE_BITSIZE (mode
) == GET_MODE_BITSIZE (inner_mode
))
3809 op0
= simplify_gen_subreg (mode
, op0
, inner_mode
, 0);
3810 else if (GET_MODE_BITSIZE (mode
) < GET_MODE_BITSIZE (inner_mode
))
3811 op0
= simplify_gen_unary (FLOAT_TRUNCATE
, mode
, op0
, inner_mode
);
3813 op0
= simplify_gen_unary (FLOAT_EXTEND
, mode
, op0
, inner_mode
);
3815 else if (FLOAT_MODE_P (mode
))
3817 gcc_assert (TREE_CODE (exp
) != SSA_NAME
);
3818 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
, 0))))
3819 op0
= simplify_gen_unary (UNSIGNED_FLOAT
, mode
, op0
, inner_mode
);
3821 op0
= simplify_gen_unary (FLOAT
, mode
, op0
, inner_mode
);
3823 else if (FLOAT_MODE_P (inner_mode
))
3826 op0
= simplify_gen_unary (UNSIGNED_FIX
, mode
, op0
, inner_mode
);
3828 op0
= simplify_gen_unary (FIX
, mode
, op0
, inner_mode
);
3830 else if (CONSTANT_P (op0
)
3831 || GET_MODE_PRECISION (mode
) <= GET_MODE_PRECISION (inner_mode
))
3832 op0
= simplify_gen_subreg (mode
, op0
, inner_mode
,
3833 subreg_lowpart_offset (mode
,
3835 else if (TREE_CODE_CLASS (TREE_CODE (exp
)) == tcc_unary
3836 ? TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
, 0)))
3838 op0
= simplify_gen_unary (ZERO_EXTEND
, mode
, op0
, inner_mode
);
3840 op0
= simplify_gen_unary (SIGN_EXTEND
, mode
, op0
, inner_mode
);
3846 if (!is_gimple_mem_ref_addr (TREE_OPERAND (exp
, 0)))
3848 tree newexp
= fold_binary (MEM_REF
, TREE_TYPE (exp
),
3849 TREE_OPERAND (exp
, 0),
3850 TREE_OPERAND (exp
, 1));
3852 return expand_debug_expr (newexp
);
3856 inner_mode
= TYPE_MODE (TREE_TYPE (TREE_OPERAND (exp
, 0)));
3857 op0
= expand_debug_expr (TREE_OPERAND (exp
, 0));
3861 if (TREE_CODE (exp
) == MEM_REF
)
3863 if (GET_CODE (op0
) == DEBUG_IMPLICIT_PTR
3864 || (GET_CODE (op0
) == PLUS
3865 && GET_CODE (XEXP (op0
, 0)) == DEBUG_IMPLICIT_PTR
))
3866 /* (mem (debug_implicit_ptr)) might confuse aliasing.
3867 Instead just use get_inner_reference. */
3870 op1
= expand_debug_expr (TREE_OPERAND (exp
, 1));
3871 if (!op1
|| !CONST_INT_P (op1
))
3874 op0
= plus_constant (inner_mode
, op0
, INTVAL (op1
));
3877 if (POINTER_TYPE_P (TREE_TYPE (exp
)))
3878 as
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)));
3880 as
= ADDR_SPACE_GENERIC
;
3882 op0
= convert_debug_memory_address (targetm
.addr_space
.address_mode (as
),
3884 if (op0
== NULL_RTX
)
3887 op0
= gen_rtx_MEM (mode
, op0
);
3888 set_mem_attributes (op0
, exp
, 0);
3889 if (TREE_CODE (exp
) == MEM_REF
3890 && !is_gimple_mem_ref_addr (TREE_OPERAND (exp
, 0)))
3891 set_mem_expr (op0
, NULL_TREE
);
3892 set_mem_addr_space (op0
, as
);
3896 case TARGET_MEM_REF
:
3897 if (TREE_CODE (TMR_BASE (exp
)) == ADDR_EXPR
3898 && !DECL_RTL_SET_P (TREE_OPERAND (TMR_BASE (exp
), 0)))
3901 op0
= expand_debug_expr
3902 (tree_mem_ref_addr (build_pointer_type (TREE_TYPE (exp
)), exp
));
3906 if (POINTER_TYPE_P (TREE_TYPE (exp
)))
3907 as
= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)));
3909 as
= ADDR_SPACE_GENERIC
;
3911 op0
= convert_debug_memory_address (targetm
.addr_space
.address_mode (as
),
3913 if (op0
== NULL_RTX
)
3916 op0
= gen_rtx_MEM (mode
, op0
);
3918 set_mem_attributes (op0
, exp
, 0);
3919 set_mem_addr_space (op0
, as
);
3925 case ARRAY_RANGE_REF
:
3930 case VIEW_CONVERT_EXPR
:
3932 enum machine_mode mode1
;
3933 HOST_WIDE_INT bitsize
, bitpos
;
3936 tree tem
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
,
3937 &mode1
, &unsignedp
, &volatilep
, false);
3943 orig_op0
= op0
= expand_debug_expr (tem
);
3950 enum machine_mode addrmode
, offmode
;
3955 op0
= XEXP (op0
, 0);
3956 addrmode
= GET_MODE (op0
);
3957 if (addrmode
== VOIDmode
)
3960 op1
= expand_debug_expr (offset
);
3964 offmode
= GET_MODE (op1
);
3965 if (offmode
== VOIDmode
)
3966 offmode
= TYPE_MODE (TREE_TYPE (offset
));
3968 if (addrmode
!= offmode
)
3969 op1
= simplify_gen_subreg (addrmode
, op1
, offmode
,
3970 subreg_lowpart_offset (addrmode
,
3973 /* Don't use offset_address here, we don't need a
3974 recognizable address, and we don't want to generate
3976 op0
= gen_rtx_MEM (mode
, simplify_gen_binary (PLUS
, addrmode
,
3982 if (mode1
== VOIDmode
)
3984 mode1
= smallest_mode_for_size (bitsize
, MODE_INT
);
3985 if (bitpos
>= BITS_PER_UNIT
)
3987 op0
= adjust_address_nv (op0
, mode1
, bitpos
/ BITS_PER_UNIT
);
3988 bitpos
%= BITS_PER_UNIT
;
3990 else if (bitpos
< 0)
3993 = (-bitpos
+ BITS_PER_UNIT
- 1) / BITS_PER_UNIT
;
3994 op0
= adjust_address_nv (op0
, mode1
, units
);
3995 bitpos
+= units
* BITS_PER_UNIT
;
3997 else if (bitpos
== 0 && bitsize
== GET_MODE_BITSIZE (mode
))
3998 op0
= adjust_address_nv (op0
, mode
, 0);
3999 else if (GET_MODE (op0
) != mode1
)
4000 op0
= adjust_address_nv (op0
, mode1
, 0);
4002 op0
= copy_rtx (op0
);
4003 if (op0
== orig_op0
)
4004 op0
= shallow_copy_rtx (op0
);
4005 set_mem_attributes (op0
, exp
, 0);
4008 if (bitpos
== 0 && mode
== GET_MODE (op0
))
4014 if (GET_MODE (op0
) == BLKmode
)
4017 if ((bitpos
% BITS_PER_UNIT
) == 0
4018 && bitsize
== GET_MODE_BITSIZE (mode1
))
4020 enum machine_mode opmode
= GET_MODE (op0
);
4022 if (opmode
== VOIDmode
)
4023 opmode
= TYPE_MODE (TREE_TYPE (tem
));
4025 /* This condition may hold if we're expanding the address
4026 right past the end of an array that turned out not to
4027 be addressable (i.e., the address was only computed in
4028 debug stmts). The gen_subreg below would rightfully
4029 crash, and the address doesn't really exist, so just
4031 if (bitpos
>= GET_MODE_BITSIZE (opmode
))
4034 if ((bitpos
% GET_MODE_BITSIZE (mode
)) == 0)
4035 return simplify_gen_subreg (mode
, op0
, opmode
,
4036 bitpos
/ BITS_PER_UNIT
);
4039 return simplify_gen_ternary (SCALAR_INT_MODE_P (GET_MODE (op0
))
4040 && TYPE_UNSIGNED (TREE_TYPE (exp
))
4042 : ZERO_EXTRACT
, mode
,
4043 GET_MODE (op0
) != VOIDmode
4045 : TYPE_MODE (TREE_TYPE (tem
)),
4046 op0
, GEN_INT (bitsize
), GEN_INT (bitpos
));
4050 return simplify_gen_unary (ABS
, mode
, op0
, mode
);
4053 return simplify_gen_unary (NEG
, mode
, op0
, mode
);
4056 return simplify_gen_unary (NOT
, mode
, op0
, mode
);
4059 return simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
,
4061 ? UNSIGNED_FLOAT
: FLOAT
, mode
, op0
,
4064 case FIX_TRUNC_EXPR
:
4065 return simplify_gen_unary (unsignedp
? UNSIGNED_FIX
: FIX
, mode
, op0
,
4068 case POINTER_PLUS_EXPR
:
4069 /* For the rare target where pointers are not the same size as
4070 size_t, we need to check for mis-matched modes and correct
4073 && GET_MODE (op0
) != VOIDmode
&& GET_MODE (op1
) != VOIDmode
4074 && GET_MODE (op0
) != GET_MODE (op1
))
4076 if (GET_MODE_BITSIZE (GET_MODE (op0
)) < GET_MODE_BITSIZE (GET_MODE (op1
))
4077 /* If OP0 is a partial mode, then we must truncate, even if it has
4078 the same bitsize as OP1 as GCC's representation of partial modes
4080 || (GET_MODE_CLASS (GET_MODE (op0
)) == MODE_PARTIAL_INT
4081 && GET_MODE_BITSIZE (GET_MODE (op0
)) == GET_MODE_BITSIZE (GET_MODE (op1
))))
4082 op1
= simplify_gen_unary (TRUNCATE
, GET_MODE (op0
), op1
,
4085 /* We always sign-extend, regardless of the signedness of
4086 the operand, because the operand is always unsigned
4087 here even if the original C expression is signed. */
4088 op1
= simplify_gen_unary (SIGN_EXTEND
, GET_MODE (op0
), op1
,
4093 return simplify_gen_binary (PLUS
, mode
, op0
, op1
);
4096 return simplify_gen_binary (MINUS
, mode
, op0
, op1
);
4099 return simplify_gen_binary (MULT
, mode
, op0
, op1
);
4102 case TRUNC_DIV_EXPR
:
4103 case EXACT_DIV_EXPR
:
4105 return simplify_gen_binary (UDIV
, mode
, op0
, op1
);
4107 return simplify_gen_binary (DIV
, mode
, op0
, op1
);
4109 case TRUNC_MOD_EXPR
:
4110 return simplify_gen_binary (unsignedp
? UMOD
: MOD
, mode
, op0
, op1
);
4112 case FLOOR_DIV_EXPR
:
4114 return simplify_gen_binary (UDIV
, mode
, op0
, op1
);
4117 rtx div
= simplify_gen_binary (DIV
, mode
, op0
, op1
);
4118 rtx mod
= simplify_gen_binary (MOD
, mode
, op0
, op1
);
4119 rtx adj
= floor_sdiv_adjust (mode
, mod
, op1
);
4120 return simplify_gen_binary (PLUS
, mode
, div
, adj
);
4123 case FLOOR_MOD_EXPR
:
4125 return simplify_gen_binary (UMOD
, mode
, op0
, op1
);
4128 rtx mod
= simplify_gen_binary (MOD
, mode
, op0
, op1
);
4129 rtx adj
= floor_sdiv_adjust (mode
, mod
, op1
);
4130 adj
= simplify_gen_unary (NEG
, mode
,
4131 simplify_gen_binary (MULT
, mode
, adj
, op1
),
4133 return simplify_gen_binary (PLUS
, mode
, mod
, adj
);
4139 rtx div
= simplify_gen_binary (UDIV
, mode
, op0
, op1
);
4140 rtx mod
= simplify_gen_binary (UMOD
, mode
, op0
, op1
);
4141 rtx adj
= ceil_udiv_adjust (mode
, mod
, op1
);
4142 return simplify_gen_binary (PLUS
, mode
, div
, adj
);
4146 rtx div
= simplify_gen_binary (DIV
, mode
, op0
, op1
);
4147 rtx mod
= simplify_gen_binary (MOD
, mode
, op0
, op1
);
4148 rtx adj
= ceil_sdiv_adjust (mode
, mod
, op1
);
4149 return simplify_gen_binary (PLUS
, mode
, div
, adj
);
4155 rtx mod
= simplify_gen_binary (UMOD
, mode
, op0
, op1
);
4156 rtx adj
= ceil_udiv_adjust (mode
, mod
, op1
);
4157 adj
= simplify_gen_unary (NEG
, mode
,
4158 simplify_gen_binary (MULT
, mode
, adj
, op1
),
4160 return simplify_gen_binary (PLUS
, mode
, mod
, adj
);
4164 rtx mod
= simplify_gen_binary (MOD
, mode
, op0
, op1
);
4165 rtx adj
= ceil_sdiv_adjust (mode
, mod
, op1
);
4166 adj
= simplify_gen_unary (NEG
, mode
,
4167 simplify_gen_binary (MULT
, mode
, adj
, op1
),
4169 return simplify_gen_binary (PLUS
, mode
, mod
, adj
);
4172 case ROUND_DIV_EXPR
:
4175 rtx div
= simplify_gen_binary (UDIV
, mode
, op0
, op1
);
4176 rtx mod
= simplify_gen_binary (UMOD
, mode
, op0
, op1
);
4177 rtx adj
= round_udiv_adjust (mode
, mod
, op1
);
4178 return simplify_gen_binary (PLUS
, mode
, div
, adj
);
4182 rtx div
= simplify_gen_binary (DIV
, mode
, op0
, op1
);
4183 rtx mod
= simplify_gen_binary (MOD
, mode
, op0
, op1
);
4184 rtx adj
= round_sdiv_adjust (mode
, mod
, op1
);
4185 return simplify_gen_binary (PLUS
, mode
, div
, adj
);
4188 case ROUND_MOD_EXPR
:
4191 rtx mod
= simplify_gen_binary (UMOD
, mode
, op0
, op1
);
4192 rtx adj
= round_udiv_adjust (mode
, mod
, op1
);
4193 adj
= simplify_gen_unary (NEG
, mode
,
4194 simplify_gen_binary (MULT
, mode
, adj
, op1
),
4196 return simplify_gen_binary (PLUS
, mode
, mod
, adj
);
4200 rtx mod
= simplify_gen_binary (MOD
, mode
, op0
, op1
);
4201 rtx adj
= round_sdiv_adjust (mode
, mod
, op1
);
4202 adj
= simplify_gen_unary (NEG
, mode
,
4203 simplify_gen_binary (MULT
, mode
, adj
, op1
),
4205 return simplify_gen_binary (PLUS
, mode
, mod
, adj
);
4209 return simplify_gen_binary (ASHIFT
, mode
, op0
, op1
);
4213 return simplify_gen_binary (LSHIFTRT
, mode
, op0
, op1
);
4215 return simplify_gen_binary (ASHIFTRT
, mode
, op0
, op1
);
4218 return simplify_gen_binary (ROTATE
, mode
, op0
, op1
);
4221 return simplify_gen_binary (ROTATERT
, mode
, op0
, op1
);
4224 return simplify_gen_binary (unsignedp
? UMIN
: SMIN
, mode
, op0
, op1
);
4227 return simplify_gen_binary (unsignedp
? UMAX
: SMAX
, mode
, op0
, op1
);
4230 case TRUTH_AND_EXPR
:
4231 return simplify_gen_binary (AND
, mode
, op0
, op1
);
4235 return simplify_gen_binary (IOR
, mode
, op0
, op1
);
4238 case TRUTH_XOR_EXPR
:
4239 return simplify_gen_binary (XOR
, mode
, op0
, op1
);
4241 case TRUTH_ANDIF_EXPR
:
4242 return gen_rtx_IF_THEN_ELSE (mode
, op0
, op1
, const0_rtx
);
4244 case TRUTH_ORIF_EXPR
:
4245 return gen_rtx_IF_THEN_ELSE (mode
, op0
, const_true_rtx
, op1
);
4247 case TRUTH_NOT_EXPR
:
4248 return simplify_gen_relational (EQ
, mode
, inner_mode
, op0
, const0_rtx
);
4251 return simplify_gen_relational (unsignedp
? LTU
: LT
, mode
, inner_mode
,
4255 return simplify_gen_relational (unsignedp
? LEU
: LE
, mode
, inner_mode
,
4259 return simplify_gen_relational (unsignedp
? GTU
: GT
, mode
, inner_mode
,
4263 return simplify_gen_relational (unsignedp
? GEU
: GE
, mode
, inner_mode
,
4267 return simplify_gen_relational (EQ
, mode
, inner_mode
, op0
, op1
);
4270 return simplify_gen_relational (NE
, mode
, inner_mode
, op0
, op1
);
4272 case UNORDERED_EXPR
:
4273 return simplify_gen_relational (UNORDERED
, mode
, inner_mode
, op0
, op1
);
4276 return simplify_gen_relational (ORDERED
, mode
, inner_mode
, op0
, op1
);
4279 return simplify_gen_relational (UNLT
, mode
, inner_mode
, op0
, op1
);
4282 return simplify_gen_relational (UNLE
, mode
, inner_mode
, op0
, op1
);
4285 return simplify_gen_relational (UNGT
, mode
, inner_mode
, op0
, op1
);
4288 return simplify_gen_relational (UNGE
, mode
, inner_mode
, op0
, op1
);
4291 return simplify_gen_relational (UNEQ
, mode
, inner_mode
, op0
, op1
);
4294 return simplify_gen_relational (LTGT
, mode
, inner_mode
, op0
, op1
);
4297 return gen_rtx_IF_THEN_ELSE (mode
, op0
, op1
, op2
);
4300 gcc_assert (COMPLEX_MODE_P (mode
));
4301 if (GET_MODE (op0
) == VOIDmode
)
4302 op0
= gen_rtx_CONST (GET_MODE_INNER (mode
), op0
);
4303 if (GET_MODE (op1
) == VOIDmode
)
4304 op1
= gen_rtx_CONST (GET_MODE_INNER (mode
), op1
);
4305 return gen_rtx_CONCAT (mode
, op0
, op1
);
4308 if (GET_CODE (op0
) == CONCAT
)
4309 return gen_rtx_CONCAT (mode
, XEXP (op0
, 0),
4310 simplify_gen_unary (NEG
, GET_MODE_INNER (mode
),
4312 GET_MODE_INNER (mode
)));
4315 enum machine_mode imode
= GET_MODE_INNER (mode
);
4320 re
= adjust_address_nv (op0
, imode
, 0);
4321 im
= adjust_address_nv (op0
, imode
, GET_MODE_SIZE (imode
));
4325 enum machine_mode ifmode
= int_mode_for_mode (mode
);
4326 enum machine_mode ihmode
= int_mode_for_mode (imode
);
4328 if (ifmode
== BLKmode
|| ihmode
== BLKmode
)
4330 halfsize
= GEN_INT (GET_MODE_BITSIZE (ihmode
));
4333 re
= gen_rtx_SUBREG (ifmode
, re
, 0);
4334 re
= gen_rtx_ZERO_EXTRACT (ihmode
, re
, halfsize
, const0_rtx
);
4335 if (imode
!= ihmode
)
4336 re
= gen_rtx_SUBREG (imode
, re
, 0);
4337 im
= copy_rtx (op0
);
4339 im
= gen_rtx_SUBREG (ifmode
, im
, 0);
4340 im
= gen_rtx_ZERO_EXTRACT (ihmode
, im
, halfsize
, halfsize
);
4341 if (imode
!= ihmode
)
4342 im
= gen_rtx_SUBREG (imode
, im
, 0);
4344 im
= gen_rtx_NEG (imode
, im
);
4345 return gen_rtx_CONCAT (mode
, re
, im
);
4349 op0
= expand_debug_expr (TREE_OPERAND (exp
, 0));
4350 if (!op0
|| !MEM_P (op0
))
4352 if ((TREE_CODE (TREE_OPERAND (exp
, 0)) == VAR_DECL
4353 || TREE_CODE (TREE_OPERAND (exp
, 0)) == PARM_DECL
4354 || TREE_CODE (TREE_OPERAND (exp
, 0)) == RESULT_DECL
)
4355 && (!TREE_ADDRESSABLE (TREE_OPERAND (exp
, 0))
4356 || target_for_debug_bind (TREE_OPERAND (exp
, 0))))
4357 return gen_rtx_DEBUG_IMPLICIT_PTR (mode
, TREE_OPERAND (exp
, 0));
4359 if (handled_component_p (TREE_OPERAND (exp
, 0)))
4361 HOST_WIDE_INT bitoffset
, bitsize
, maxsize
;
4363 = get_ref_base_and_extent (TREE_OPERAND (exp
, 0),
4364 &bitoffset
, &bitsize
, &maxsize
);
4365 if ((TREE_CODE (decl
) == VAR_DECL
4366 || TREE_CODE (decl
) == PARM_DECL
4367 || TREE_CODE (decl
) == RESULT_DECL
)
4368 && (!TREE_ADDRESSABLE (decl
)
4369 || target_for_debug_bind (decl
))
4370 && (bitoffset
% BITS_PER_UNIT
) == 0
4372 && bitsize
== maxsize
)
4374 rtx base
= gen_rtx_DEBUG_IMPLICIT_PTR (mode
, decl
);
4375 return plus_constant (mode
, base
, bitoffset
/ BITS_PER_UNIT
);
4379 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == MEM_REF
4380 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
4383 op0
= expand_debug_expr (TREE_OPERAND (TREE_OPERAND (exp
, 0),
4386 && (GET_CODE (op0
) == DEBUG_IMPLICIT_PTR
4387 || (GET_CODE (op0
) == PLUS
4388 && GET_CODE (XEXP (op0
, 0)) == DEBUG_IMPLICIT_PTR
4389 && CONST_INT_P (XEXP (op0
, 1)))))
4391 op1
= expand_debug_expr (TREE_OPERAND (TREE_OPERAND (exp
, 0),
4393 if (!op1
|| !CONST_INT_P (op1
))
4396 return plus_constant (mode
, op0
, INTVAL (op1
));
4403 as
= TYPE_ADDR_SPACE (TREE_TYPE (exp
));
4404 op0
= convert_debug_memory_address (mode
, XEXP (op0
, 0), as
);
4412 op0
= gen_rtx_CONCATN
4413 (mode
, rtvec_alloc (TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp
))));
4415 for (i
= 0; i
< VECTOR_CST_NELTS (exp
); ++i
)
4417 op1
= expand_debug_expr (VECTOR_CST_ELT (exp
, i
));
4420 XVECEXP (op0
, 0, i
) = op1
;
4427 if (TREE_CLOBBER_P (exp
))
4429 else if (TREE_CODE (TREE_TYPE (exp
)) == VECTOR_TYPE
)
4434 op0
= gen_rtx_CONCATN
4435 (mode
, rtvec_alloc (TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp
))));
4437 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), i
, val
)
4439 op1
= expand_debug_expr (val
);
4442 XVECEXP (op0
, 0, i
) = op1
;
4445 if (i
< TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp
)))
4447 op1
= expand_debug_expr
4448 (build_zero_cst (TREE_TYPE (TREE_TYPE (exp
))));
4453 for (; i
< TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp
)); i
++)
4454 XVECEXP (op0
, 0, i
) = op1
;
4460 goto flag_unsupported
;
4463 /* ??? Maybe handle some builtins? */
4468 gimple g
= get_gimple_for_ssa_name (exp
);
4471 op0
= expand_debug_expr (gimple_assign_rhs_to_tree (g
));
4477 int part
= var_to_partition (SA
.map
, exp
);
4479 if (part
== NO_PARTITION
)
4481 /* If this is a reference to an incoming value of parameter
4482 that is never used in the code or where the incoming
4483 value is never used in the code, use PARM_DECL's
4485 if (SSA_NAME_IS_DEFAULT_DEF (exp
)
4486 && TREE_CODE (SSA_NAME_VAR (exp
)) == PARM_DECL
)
4488 op0
= expand_debug_parm_decl (SSA_NAME_VAR (exp
));
4491 op0
= expand_debug_expr (SSA_NAME_VAR (exp
));
4498 gcc_assert (part
>= 0 && (unsigned)part
< SA
.map
->num_partitions
);
4500 op0
= copy_rtx (SA
.partition_to_pseudo
[part
]);
4508 /* Vector stuff. For most of the codes we don't have rtl codes. */
4509 case REALIGN_LOAD_EXPR
:
4510 case REDUC_MAX_EXPR
:
4511 case REDUC_MIN_EXPR
:
4512 case REDUC_PLUS_EXPR
:
4514 case VEC_LSHIFT_EXPR
:
4515 case VEC_PACK_FIX_TRUNC_EXPR
:
4516 case VEC_PACK_SAT_EXPR
:
4517 case VEC_PACK_TRUNC_EXPR
:
4518 case VEC_RSHIFT_EXPR
:
4519 case VEC_UNPACK_FLOAT_HI_EXPR
:
4520 case VEC_UNPACK_FLOAT_LO_EXPR
:
4521 case VEC_UNPACK_HI_EXPR
:
4522 case VEC_UNPACK_LO_EXPR
:
4523 case VEC_WIDEN_MULT_HI_EXPR
:
4524 case VEC_WIDEN_MULT_LO_EXPR
:
4525 case VEC_WIDEN_MULT_EVEN_EXPR
:
4526 case VEC_WIDEN_MULT_ODD_EXPR
:
4527 case VEC_WIDEN_LSHIFT_HI_EXPR
:
4528 case VEC_WIDEN_LSHIFT_LO_EXPR
:
4533 case ADDR_SPACE_CONVERT_EXPR
:
4534 case FIXED_CONVERT_EXPR
:
4536 case WITH_SIZE_EXPR
:
4540 if (SCALAR_INT_MODE_P (GET_MODE (op0
))
4541 && SCALAR_INT_MODE_P (mode
))
4544 = simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
,
4546 ? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op0
,
4549 = simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
,
4551 ? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op1
,
4553 op0
= simplify_gen_binary (MULT
, mode
, op0
, op1
);
4554 return simplify_gen_binary (PLUS
, mode
, op0
, op2
);
4558 case WIDEN_MULT_EXPR
:
4559 case WIDEN_MULT_PLUS_EXPR
:
4560 case WIDEN_MULT_MINUS_EXPR
:
4561 if (SCALAR_INT_MODE_P (GET_MODE (op0
))
4562 && SCALAR_INT_MODE_P (mode
))
4564 inner_mode
= GET_MODE (op0
);
4565 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
, 0))))
4566 op0
= simplify_gen_unary (ZERO_EXTEND
, mode
, op0
, inner_mode
);
4568 op0
= simplify_gen_unary (SIGN_EXTEND
, mode
, op0
, inner_mode
);
4569 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
, 1))))
4570 op1
= simplify_gen_unary (ZERO_EXTEND
, mode
, op1
, inner_mode
);
4572 op1
= simplify_gen_unary (SIGN_EXTEND
, mode
, op1
, inner_mode
);
4573 op0
= simplify_gen_binary (MULT
, mode
, op0
, op1
);
4574 if (TREE_CODE (exp
) == WIDEN_MULT_EXPR
)
4576 else if (TREE_CODE (exp
) == WIDEN_MULT_PLUS_EXPR
)
4577 return simplify_gen_binary (PLUS
, mode
, op0
, op2
);
4579 return simplify_gen_binary (MINUS
, mode
, op2
, op0
);
4583 case MULT_HIGHPART_EXPR
:
4584 /* ??? Similar to the above. */
4587 case WIDEN_SUM_EXPR
:
4588 case WIDEN_LSHIFT_EXPR
:
4589 if (SCALAR_INT_MODE_P (GET_MODE (op0
))
4590 && SCALAR_INT_MODE_P (mode
))
4593 = simplify_gen_unary (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (exp
,
4595 ? ZERO_EXTEND
: SIGN_EXTEND
, mode
, op0
,
4597 return simplify_gen_binary (TREE_CODE (exp
) == WIDEN_LSHIFT_EXPR
4598 ? ASHIFT
: PLUS
, mode
, op0
, op1
);
4603 return simplify_gen_ternary (FMA
, mode
, inner_mode
, op0
, op1
, op2
);
4607 #ifdef ENABLE_CHECKING
4616 /* Return an RTX equivalent to the source bind value of the tree expression
4620 expand_debug_source_expr (tree exp
)
4623 enum machine_mode mode
= VOIDmode
, inner_mode
;
4625 switch (TREE_CODE (exp
))
4629 mode
= DECL_MODE (exp
);
4630 op0
= expand_debug_parm_decl (exp
);
4633 /* See if this isn't an argument that has been completely
4635 if (!DECL_RTL_SET_P (exp
)
4636 && !DECL_INCOMING_RTL (exp
)
4637 && DECL_ABSTRACT_ORIGIN (current_function_decl
))
4639 tree aexp
= DECL_ORIGIN (exp
);
4640 if (DECL_CONTEXT (aexp
)
4641 == DECL_ABSTRACT_ORIGIN (current_function_decl
))
4643 vec
<tree
, va_gc
> **debug_args
;
4646 debug_args
= decl_debug_args_lookup (current_function_decl
);
4647 if (debug_args
!= NULL
)
4649 for (ix
= 0; vec_safe_iterate (*debug_args
, ix
, &ddecl
);
4652 return gen_rtx_DEBUG_PARAMETER_REF (mode
, aexp
);
4662 if (op0
== NULL_RTX
)
4665 inner_mode
= GET_MODE (op0
);
4666 if (mode
== inner_mode
)
4669 if (FLOAT_MODE_P (mode
) && FLOAT_MODE_P (inner_mode
))
4671 if (GET_MODE_BITSIZE (mode
) == GET_MODE_BITSIZE (inner_mode
))
4672 op0
= simplify_gen_subreg (mode
, op0
, inner_mode
, 0);
4673 else if (GET_MODE_BITSIZE (mode
) < GET_MODE_BITSIZE (inner_mode
))
4674 op0
= simplify_gen_unary (FLOAT_TRUNCATE
, mode
, op0
, inner_mode
);
4676 op0
= simplify_gen_unary (FLOAT_EXTEND
, mode
, op0
, inner_mode
);
4678 else if (FLOAT_MODE_P (mode
))
4680 else if (FLOAT_MODE_P (inner_mode
))
4682 if (TYPE_UNSIGNED (TREE_TYPE (exp
)))
4683 op0
= simplify_gen_unary (UNSIGNED_FIX
, mode
, op0
, inner_mode
);
4685 op0
= simplify_gen_unary (FIX
, mode
, op0
, inner_mode
);
4687 else if (CONSTANT_P (op0
)
4688 || GET_MODE_BITSIZE (mode
) <= GET_MODE_BITSIZE (inner_mode
))
4689 op0
= simplify_gen_subreg (mode
, op0
, inner_mode
,
4690 subreg_lowpart_offset (mode
, inner_mode
));
4691 else if (TYPE_UNSIGNED (TREE_TYPE (exp
)))
4692 op0
= simplify_gen_unary (ZERO_EXTEND
, mode
, op0
, inner_mode
);
4694 op0
= simplify_gen_unary (SIGN_EXTEND
, mode
, op0
, inner_mode
);
4699 /* Ensure INSN_VAR_LOCATION_LOC (insn) doesn't have unbound complexity.
4700 Allow 4 levels of rtl nesting for most rtl codes, and if we see anything
4701 deeper than that, create DEBUG_EXPRs and emit DEBUG_INSNs before INSN. */
4704 avoid_complex_debug_insns (rtx insn
, rtx
*exp_p
, int depth
)
4708 if (exp
== NULL_RTX
)
4711 if ((OBJECT_P (exp
) && !MEM_P (exp
)) || GET_CODE (exp
) == CLOBBER
)
4716 /* Create DEBUG_EXPR (and DEBUG_EXPR_DECL). */
4717 rtx dval
= make_debug_expr_from_rtl (exp
);
4719 /* Emit a debug bind insn before INSN. */
4720 rtx bind
= gen_rtx_VAR_LOCATION (GET_MODE (exp
),
4721 DEBUG_EXPR_TREE_DECL (dval
), exp
,
4722 VAR_INIT_STATUS_INITIALIZED
);
4724 emit_debug_insn_before (bind
, insn
);
4729 const char *format_ptr
= GET_RTX_FORMAT (GET_CODE (exp
));
4731 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (exp
)); i
++)
4732 switch (*format_ptr
++)
4735 avoid_complex_debug_insns (insn
, &XEXP (exp
, i
), depth
+ 1);
4740 for (j
= 0; j
< XVECLEN (exp
, i
); j
++)
4741 avoid_complex_debug_insns (insn
, &XVECEXP (exp
, i
, j
), depth
+ 1);
4749 /* Expand the _LOCs in debug insns. We run this after expanding all
4750 regular insns, so that any variables referenced in the function
4751 will have their DECL_RTLs set. */
4754 expand_debug_locations (void)
4757 rtx last
= get_last_insn ();
4758 int save_strict_alias
= flag_strict_aliasing
;
4760 /* New alias sets while setting up memory attributes cause
4761 -fcompare-debug failures, even though it doesn't bring about any
4763 flag_strict_aliasing
= 0;
4765 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
4766 if (DEBUG_INSN_P (insn
))
4768 tree value
= (tree
)INSN_VAR_LOCATION_LOC (insn
);
4769 rtx val
, prev_insn
, insn2
;
4770 enum machine_mode mode
;
4772 if (value
== NULL_TREE
)
4776 if (INSN_VAR_LOCATION_STATUS (insn
)
4777 == VAR_INIT_STATUS_UNINITIALIZED
)
4778 val
= expand_debug_source_expr (value
);
4780 val
= expand_debug_expr (value
);
4781 gcc_assert (last
== get_last_insn ());
4785 val
= gen_rtx_UNKNOWN_VAR_LOC ();
4788 mode
= GET_MODE (INSN_VAR_LOCATION (insn
));
4790 gcc_assert (mode
== GET_MODE (val
)
4791 || (GET_MODE (val
) == VOIDmode
4792 && (CONST_SCALAR_INT_P (val
)
4793 || GET_CODE (val
) == CONST_FIXED
4794 || GET_CODE (val
) == LABEL_REF
)));
4797 INSN_VAR_LOCATION_LOC (insn
) = val
;
4798 prev_insn
= PREV_INSN (insn
);
4799 for (insn2
= insn
; insn2
!= prev_insn
; insn2
= PREV_INSN (insn2
))
4800 avoid_complex_debug_insns (insn2
, &INSN_VAR_LOCATION_LOC (insn2
), 0);
4803 flag_strict_aliasing
= save_strict_alias
;
4806 /* Expand basic block BB from GIMPLE trees to RTL. */
4809 expand_gimple_basic_block (basic_block bb
, bool disable_tail_calls
)
4811 gimple_stmt_iterator gsi
;
4820 fprintf (dump_file
, "\n;; Generating RTL for gimple basic block %d\n",
4823 /* Note that since we are now transitioning from GIMPLE to RTL, we
4824 cannot use the gsi_*_bb() routines because they expect the basic
4825 block to be in GIMPLE, instead of RTL. Therefore, we need to
4826 access the BB sequence directly. */
4827 stmts
= bb_seq (bb
);
4828 bb
->il
.gimple
.seq
= NULL
;
4829 bb
->il
.gimple
.phi_nodes
= NULL
;
4830 rtl_profile_for_bb (bb
);
4831 init_rtl_bb_info (bb
);
4832 bb
->flags
|= BB_RTL
;
4834 /* Remove the RETURN_EXPR if we may fall though to the exit
4836 gsi
= gsi_last (stmts
);
4837 if (!gsi_end_p (gsi
)
4838 && gimple_code (gsi_stmt (gsi
)) == GIMPLE_RETURN
)
4840 gimple ret_stmt
= gsi_stmt (gsi
);
4842 gcc_assert (single_succ_p (bb
));
4843 gcc_assert (single_succ (bb
) == EXIT_BLOCK_PTR
);
4845 if (bb
->next_bb
== EXIT_BLOCK_PTR
4846 && !gimple_return_retval (ret_stmt
))
4848 gsi_remove (&gsi
, false);
4849 single_succ_edge (bb
)->flags
|= EDGE_FALLTHRU
;
4853 gsi
= gsi_start (stmts
);
4854 if (!gsi_end_p (gsi
))
4856 stmt
= gsi_stmt (gsi
);
4857 if (gimple_code (stmt
) != GIMPLE_LABEL
)
4861 elt
= pointer_map_contains (lab_rtx_for_bb
, bb
);
4865 last
= get_last_insn ();
4869 expand_gimple_stmt (stmt
);
4874 emit_label ((rtx
) *elt
);
4876 /* Java emits line number notes in the top of labels.
4877 ??? Make this go away once line number notes are obsoleted. */
4878 BB_HEAD (bb
) = NEXT_INSN (last
);
4879 if (NOTE_P (BB_HEAD (bb
)))
4880 BB_HEAD (bb
) = NEXT_INSN (BB_HEAD (bb
));
4881 note
= emit_note_after (NOTE_INSN_BASIC_BLOCK
, BB_HEAD (bb
));
4883 maybe_dump_rtl_for_gimple_stmt (stmt
, last
);
4886 note
= BB_HEAD (bb
) = emit_note (NOTE_INSN_BASIC_BLOCK
);
4888 NOTE_BASIC_BLOCK (note
) = bb
;
4890 for (; !gsi_end_p (gsi
); gsi_next (&gsi
))
4894 stmt
= gsi_stmt (gsi
);
4896 /* If this statement is a non-debug one, and we generate debug
4897 insns, then this one might be the last real use of a TERed
4898 SSA_NAME, but where there are still some debug uses further
4899 down. Expanding the current SSA name in such further debug
4900 uses by their RHS might lead to wrong debug info, as coalescing
4901 might make the operands of such RHS be placed into the same
4902 pseudo as something else. Like so:
4903 a_1 = a_0 + 1; // Assume a_1 is TERed and a_0 is dead
4907 As a_0 and a_2 don't overlap in lifetime, assume they are coalesced.
4908 If we now would expand a_1 by it's RHS (a_0 + 1) in the debug use,
4909 the write to a_2 would actually have clobbered the place which
4912 So, instead of that, we recognize the situation, and generate
4913 debug temporaries at the last real use of TERed SSA names:
4920 if (MAY_HAVE_DEBUG_INSNS
4922 && !is_gimple_debug (stmt
))
4928 location_t sloc
= curr_insn_location ();
4930 /* Look for SSA names that have their last use here (TERed
4931 names always have only one real use). */
4932 FOR_EACH_SSA_TREE_OPERAND (op
, stmt
, iter
, SSA_OP_USE
)
4933 if ((def
= get_gimple_for_ssa_name (op
)))
4935 imm_use_iterator imm_iter
;
4936 use_operand_p use_p
;
4937 bool have_debug_uses
= false;
4939 FOR_EACH_IMM_USE_FAST (use_p
, imm_iter
, op
)
4941 if (gimple_debug_bind_p (USE_STMT (use_p
)))
4943 have_debug_uses
= true;
4948 if (have_debug_uses
)
4950 /* OP is a TERed SSA name, with DEF it's defining
4951 statement, and where OP is used in further debug
4952 instructions. Generate a debug temporary, and
4953 replace all uses of OP in debug insns with that
4956 tree value
= gimple_assign_rhs_to_tree (def
);
4957 tree vexpr
= make_node (DEBUG_EXPR_DECL
);
4959 enum machine_mode mode
;
4961 set_curr_insn_location (gimple_location (def
));
4963 DECL_ARTIFICIAL (vexpr
) = 1;
4964 TREE_TYPE (vexpr
) = TREE_TYPE (value
);
4966 mode
= DECL_MODE (value
);
4968 mode
= TYPE_MODE (TREE_TYPE (value
));
4969 DECL_MODE (vexpr
) = mode
;
4971 val
= gen_rtx_VAR_LOCATION
4972 (mode
, vexpr
, (rtx
)value
, VAR_INIT_STATUS_INITIALIZED
);
4974 emit_debug_insn (val
);
4976 FOR_EACH_IMM_USE_STMT (debugstmt
, imm_iter
, op
)
4978 if (!gimple_debug_bind_p (debugstmt
))
4981 FOR_EACH_IMM_USE_ON_STMT (use_p
, imm_iter
)
4982 SET_USE (use_p
, vexpr
);
4984 update_stmt (debugstmt
);
4988 set_curr_insn_location (sloc
);
4991 currently_expanding_gimple_stmt
= stmt
;
4993 /* Expand this statement, then evaluate the resulting RTL and
4994 fixup the CFG accordingly. */
4995 if (gimple_code (stmt
) == GIMPLE_COND
)
4997 new_bb
= expand_gimple_cond (bb
, stmt
);
5001 else if (gimple_debug_bind_p (stmt
))
5003 location_t sloc
= curr_insn_location ();
5004 gimple_stmt_iterator nsi
= gsi
;
5008 tree var
= gimple_debug_bind_get_var (stmt
);
5011 enum machine_mode mode
;
5013 if (TREE_CODE (var
) != DEBUG_EXPR_DECL
5014 && TREE_CODE (var
) != LABEL_DECL
5015 && !target_for_debug_bind (var
))
5016 goto delink_debug_stmt
;
5018 if (gimple_debug_bind_has_value_p (stmt
))
5019 value
= gimple_debug_bind_get_value (stmt
);
5023 last
= get_last_insn ();
5025 set_curr_insn_location (gimple_location (stmt
));
5028 mode
= DECL_MODE (var
);
5030 mode
= TYPE_MODE (TREE_TYPE (var
));
5032 val
= gen_rtx_VAR_LOCATION
5033 (mode
, var
, (rtx
)value
, VAR_INIT_STATUS_INITIALIZED
);
5035 emit_debug_insn (val
);
5037 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
5039 /* We can't dump the insn with a TREE where an RTX
5041 PAT_VAR_LOCATION_LOC (val
) = const0_rtx
;
5042 maybe_dump_rtl_for_gimple_stmt (stmt
, last
);
5043 PAT_VAR_LOCATION_LOC (val
) = (rtx
)value
;
5047 /* In order not to generate too many debug temporaries,
5048 we delink all uses of debug statements we already expanded.
5049 Therefore debug statements between definition and real
5050 use of TERed SSA names will continue to use the SSA name,
5051 and not be replaced with debug temps. */
5052 delink_stmt_imm_use (stmt
);
5056 if (gsi_end_p (nsi
))
5058 stmt
= gsi_stmt (nsi
);
5059 if (!gimple_debug_bind_p (stmt
))
5063 set_curr_insn_location (sloc
);
5065 else if (gimple_debug_source_bind_p (stmt
))
5067 location_t sloc
= curr_insn_location ();
5068 tree var
= gimple_debug_source_bind_get_var (stmt
);
5069 tree value
= gimple_debug_source_bind_get_value (stmt
);
5071 enum machine_mode mode
;
5073 last
= get_last_insn ();
5075 set_curr_insn_location (gimple_location (stmt
));
5077 mode
= DECL_MODE (var
);
5079 val
= gen_rtx_VAR_LOCATION (mode
, var
, (rtx
)value
,
5080 VAR_INIT_STATUS_UNINITIALIZED
);
5082 emit_debug_insn (val
);
5084 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
5086 /* We can't dump the insn with a TREE where an RTX
5088 PAT_VAR_LOCATION_LOC (val
) = const0_rtx
;
5089 maybe_dump_rtl_for_gimple_stmt (stmt
, last
);
5090 PAT_VAR_LOCATION_LOC (val
) = (rtx
)value
;
5093 set_curr_insn_location (sloc
);
5097 if (is_gimple_call (stmt
)
5098 && gimple_call_tail_p (stmt
)
5099 && disable_tail_calls
)
5100 gimple_call_set_tail (stmt
, false);
5102 if (is_gimple_call (stmt
) && gimple_call_tail_p (stmt
))
5105 new_bb
= expand_gimple_tailcall (bb
, stmt
, &can_fallthru
);
5116 def_operand_p def_p
;
5117 def_p
= SINGLE_SSA_DEF_OPERAND (stmt
, SSA_OP_DEF
);
5121 /* Ignore this stmt if it is in the list of
5122 replaceable expressions. */
5124 && bitmap_bit_p (SA
.values
,
5125 SSA_NAME_VERSION (DEF_FROM_PTR (def_p
))))
5128 last
= expand_gimple_stmt (stmt
);
5129 maybe_dump_rtl_for_gimple_stmt (stmt
, last
);
5134 currently_expanding_gimple_stmt
= NULL
;
5136 /* Expand implicit goto and convert goto_locus. */
5137 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
5139 if (e
->goto_locus
!= UNKNOWN_LOCATION
)
5140 set_curr_insn_location (e
->goto_locus
);
5141 if ((e
->flags
& EDGE_FALLTHRU
) && e
->dest
!= bb
->next_bb
)
5143 emit_jump (label_rtx_for_bb (e
->dest
));
5144 e
->flags
&= ~EDGE_FALLTHRU
;
5148 /* Expanded RTL can create a jump in the last instruction of block.
5149 This later might be assumed to be a jump to successor and break edge insertion.
5150 We need to insert dummy move to prevent this. PR41440. */
5151 if (single_succ_p (bb
)
5152 && (single_succ_edge (bb
)->flags
& EDGE_FALLTHRU
)
5153 && (last
= get_last_insn ())
5156 rtx dummy
= gen_reg_rtx (SImode
);
5157 emit_insn_after_noloc (gen_move_insn (dummy
, dummy
), last
, NULL
);
5160 do_pending_stack_adjust ();
5162 /* Find the block tail. The last insn in the block is the insn
5163 before a barrier and/or table jump insn. */
5164 last
= get_last_insn ();
5165 if (BARRIER_P (last
))
5166 last
= PREV_INSN (last
);
5167 if (JUMP_TABLE_DATA_P (last
))
5168 last
= PREV_INSN (PREV_INSN (last
));
5171 update_bb_for_insn (bb
);
5177 /* Create a basic block for initialization code. */
5180 construct_init_block (void)
5182 basic_block init_block
, first_block
;
5186 /* Multiple entry points not supported yet. */
5187 gcc_assert (EDGE_COUNT (ENTRY_BLOCK_PTR
->succs
) == 1);
5188 init_rtl_bb_info (ENTRY_BLOCK_PTR
);
5189 init_rtl_bb_info (EXIT_BLOCK_PTR
);
5190 ENTRY_BLOCK_PTR
->flags
|= BB_RTL
;
5191 EXIT_BLOCK_PTR
->flags
|= BB_RTL
;
5193 e
= EDGE_SUCC (ENTRY_BLOCK_PTR
, 0);
5195 /* When entry edge points to first basic block, we don't need jump,
5196 otherwise we have to jump into proper target. */
5197 if (e
&& e
->dest
!= ENTRY_BLOCK_PTR
->next_bb
)
5199 tree label
= gimple_block_label (e
->dest
);
5201 emit_jump (label_rtx (label
));
5205 flags
= EDGE_FALLTHRU
;
5207 init_block
= create_basic_block (NEXT_INSN (get_insns ()),
5210 init_block
->frequency
= ENTRY_BLOCK_PTR
->frequency
;
5211 init_block
->count
= ENTRY_BLOCK_PTR
->count
;
5212 if (current_loops
&& ENTRY_BLOCK_PTR
->loop_father
)
5213 add_bb_to_loop (init_block
, ENTRY_BLOCK_PTR
->loop_father
);
5216 first_block
= e
->dest
;
5217 redirect_edge_succ (e
, init_block
);
5218 e
= make_edge (init_block
, first_block
, flags
);
5221 e
= make_edge (init_block
, EXIT_BLOCK_PTR
, EDGE_FALLTHRU
);
5222 e
->probability
= REG_BR_PROB_BASE
;
5223 e
->count
= ENTRY_BLOCK_PTR
->count
;
5225 update_bb_for_insn (init_block
);
5229 /* For each lexical block, set BLOCK_NUMBER to the depth at which it is
5230 found in the block tree. */
5233 set_block_levels (tree block
, int level
)
5237 BLOCK_NUMBER (block
) = level
;
5238 set_block_levels (BLOCK_SUBBLOCKS (block
), level
+ 1);
5239 block
= BLOCK_CHAIN (block
);
5243 /* Create a block containing landing pads and similar stuff. */
5246 construct_exit_block (void)
5248 rtx head
= get_last_insn ();
5250 basic_block exit_block
;
5254 rtx orig_end
= BB_END (EXIT_BLOCK_PTR
->prev_bb
);
5256 rtl_profile_for_bb (EXIT_BLOCK_PTR
);
5258 /* Make sure the locus is set to the end of the function, so that
5259 epilogue line numbers and warnings are set properly. */
5260 if (LOCATION_LOCUS (cfun
->function_end_locus
) != UNKNOWN_LOCATION
)
5261 input_location
= cfun
->function_end_locus
;
5263 /* Generate rtl for function exit. */
5264 expand_function_end ();
5266 end
= get_last_insn ();
5269 /* While emitting the function end we could move end of the last basic block.
5271 BB_END (EXIT_BLOCK_PTR
->prev_bb
) = orig_end
;
5272 while (NEXT_INSN (head
) && NOTE_P (NEXT_INSN (head
)))
5273 head
= NEXT_INSN (head
);
5274 exit_block
= create_basic_block (NEXT_INSN (head
), end
,
5275 EXIT_BLOCK_PTR
->prev_bb
);
5276 exit_block
->frequency
= EXIT_BLOCK_PTR
->frequency
;
5277 exit_block
->count
= EXIT_BLOCK_PTR
->count
;
5278 if (current_loops
&& EXIT_BLOCK_PTR
->loop_father
)
5279 add_bb_to_loop (exit_block
, EXIT_BLOCK_PTR
->loop_father
);
5282 while (ix
< EDGE_COUNT (EXIT_BLOCK_PTR
->preds
))
5284 e
= EDGE_PRED (EXIT_BLOCK_PTR
, ix
);
5285 if (!(e
->flags
& EDGE_ABNORMAL
))
5286 redirect_edge_succ (e
, exit_block
);
5291 e
= make_edge (exit_block
, EXIT_BLOCK_PTR
, EDGE_FALLTHRU
);
5292 e
->probability
= REG_BR_PROB_BASE
;
5293 e
->count
= EXIT_BLOCK_PTR
->count
;
5294 FOR_EACH_EDGE (e2
, ei
, EXIT_BLOCK_PTR
->preds
)
5297 e
->count
-= e2
->count
;
5298 exit_block
->count
-= e2
->count
;
5299 exit_block
->frequency
-= EDGE_FREQUENCY (e2
);
5303 if (exit_block
->count
< 0)
5304 exit_block
->count
= 0;
5305 if (exit_block
->frequency
< 0)
5306 exit_block
->frequency
= 0;
5307 update_bb_for_insn (exit_block
);
5310 /* Helper function for discover_nonconstant_array_refs.
5311 Look for ARRAY_REF nodes with non-constant indexes and mark them
5315 discover_nonconstant_array_refs_r (tree
* tp
, int *walk_subtrees
,
5316 void *data ATTRIBUTE_UNUSED
)
5320 if (IS_TYPE_OR_DECL_P (t
))
5322 else if (TREE_CODE (t
) == ARRAY_REF
|| TREE_CODE (t
) == ARRAY_RANGE_REF
)
5324 while (((TREE_CODE (t
) == ARRAY_REF
|| TREE_CODE (t
) == ARRAY_RANGE_REF
)
5325 && is_gimple_min_invariant (TREE_OPERAND (t
, 1))
5326 && (!TREE_OPERAND (t
, 2)
5327 || is_gimple_min_invariant (TREE_OPERAND (t
, 2))))
5328 || (TREE_CODE (t
) == COMPONENT_REF
5329 && (!TREE_OPERAND (t
,2)
5330 || is_gimple_min_invariant (TREE_OPERAND (t
, 2))))
5331 || TREE_CODE (t
) == BIT_FIELD_REF
5332 || TREE_CODE (t
) == REALPART_EXPR
5333 || TREE_CODE (t
) == IMAGPART_EXPR
5334 || TREE_CODE (t
) == VIEW_CONVERT_EXPR
5335 || CONVERT_EXPR_P (t
))
5336 t
= TREE_OPERAND (t
, 0);
5338 if (TREE_CODE (t
) == ARRAY_REF
|| TREE_CODE (t
) == ARRAY_RANGE_REF
)
5340 t
= get_base_address (t
);
5342 && DECL_MODE (t
) != BLKmode
)
5343 TREE_ADDRESSABLE (t
) = 1;
5352 /* RTL expansion is not able to compile array references with variable
5353 offsets for arrays stored in single register. Discover such
5354 expressions and mark variables as addressable to avoid this
5358 discover_nonconstant_array_refs (void)
5361 gimple_stmt_iterator gsi
;
5364 for (gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
5366 gimple stmt
= gsi_stmt (gsi
);
5367 if (!is_gimple_debug (stmt
))
5368 walk_gimple_op (stmt
, discover_nonconstant_array_refs_r
, NULL
);
5372 /* This function sets crtl->args.internal_arg_pointer to a virtual
5373 register if DRAP is needed. Local register allocator will replace
5374 virtual_incoming_args_rtx with the virtual register. */
5377 expand_stack_alignment (void)
5380 unsigned int preferred_stack_boundary
;
5382 if (! SUPPORTS_STACK_ALIGNMENT
)
5385 if (cfun
->calls_alloca
5386 || cfun
->has_nonlocal_label
5387 || crtl
->has_nonlocal_goto
)
5388 crtl
->need_drap
= true;
5390 /* Call update_stack_boundary here again to update incoming stack
5391 boundary. It may set incoming stack alignment to a different
5392 value after RTL expansion. TARGET_FUNCTION_OK_FOR_SIBCALL may
5393 use the minimum incoming stack alignment to check if it is OK
5394 to perform sibcall optimization since sibcall optimization will
5395 only align the outgoing stack to incoming stack boundary. */
5396 if (targetm
.calls
.update_stack_boundary
)
5397 targetm
.calls
.update_stack_boundary ();
5399 /* The incoming stack frame has to be aligned at least at
5400 parm_stack_boundary. */
5401 gcc_assert (crtl
->parm_stack_boundary
<= INCOMING_STACK_BOUNDARY
);
5403 /* Update crtl->stack_alignment_estimated and use it later to align
5404 stack. We check PREFERRED_STACK_BOUNDARY if there may be non-call
5405 exceptions since callgraph doesn't collect incoming stack alignment
5407 if (cfun
->can_throw_non_call_exceptions
5408 && PREFERRED_STACK_BOUNDARY
> crtl
->preferred_stack_boundary
)
5409 preferred_stack_boundary
= PREFERRED_STACK_BOUNDARY
;
5411 preferred_stack_boundary
= crtl
->preferred_stack_boundary
;
5412 if (preferred_stack_boundary
> crtl
->stack_alignment_estimated
)
5413 crtl
->stack_alignment_estimated
= preferred_stack_boundary
;
5414 if (preferred_stack_boundary
> crtl
->stack_alignment_needed
)
5415 crtl
->stack_alignment_needed
= preferred_stack_boundary
;
5417 gcc_assert (crtl
->stack_alignment_needed
5418 <= crtl
->stack_alignment_estimated
);
5420 crtl
->stack_realign_needed
5421 = INCOMING_STACK_BOUNDARY
< crtl
->stack_alignment_estimated
;
5422 crtl
->stack_realign_tried
= crtl
->stack_realign_needed
;
5424 crtl
->stack_realign_processed
= true;
5426 /* Target has to redefine TARGET_GET_DRAP_RTX to support stack
5428 gcc_assert (targetm
.calls
.get_drap_rtx
!= NULL
);
5429 drap_rtx
= targetm
.calls
.get_drap_rtx ();
5431 /* stack_realign_drap and drap_rtx must match. */
5432 gcc_assert ((stack_realign_drap
!= 0) == (drap_rtx
!= NULL
));
5434 /* Do nothing if NULL is returned, which means DRAP is not needed. */
5435 if (NULL
!= drap_rtx
)
5437 crtl
->args
.internal_arg_pointer
= drap_rtx
;
5439 /* Call fixup_tail_calls to clean up REG_EQUIV note if DRAP is
5441 fixup_tail_calls ();
5447 expand_main_function (void)
5449 #if (defined(INVOKE__main) \
5450 || (!defined(HAS_INIT_SECTION) \
5451 && !defined(INIT_SECTION_ASM_OP) \
5452 && !defined(INIT_ARRAY_SECTION_ASM_OP)))
5453 emit_library_call (init_one_libfunc (NAME__MAIN
), LCT_NORMAL
, VOIDmode
, 0);
5458 /* Expand code to initialize the stack_protect_guard. This is invoked at
5459 the beginning of a function to be protected. */
5461 #ifndef HAVE_stack_protect_set
5462 # define HAVE_stack_protect_set 0
5463 # define gen_stack_protect_set(x,y) (gcc_unreachable (), NULL_RTX)
5467 stack_protect_prologue (void)
5469 tree guard_decl
= targetm
.stack_protect_guard ();
5472 x
= expand_normal (crtl
->stack_protect_guard
);
5473 y
= expand_normal (guard_decl
);
5475 /* Allow the target to copy from Y to X without leaking Y into a
5477 if (HAVE_stack_protect_set
)
5479 rtx insn
= gen_stack_protect_set (x
, y
);
5487 /* Otherwise do a straight move. */
5488 emit_move_insn (x
, y
);
5491 /* Translate the intermediate representation contained in the CFG
5492 from GIMPLE trees to RTL.
5494 We do conversion per basic block and preserve/update the tree CFG.
5495 This implies we have to do some magic as the CFG can simultaneously
5496 consist of basic blocks containing RTL and GIMPLE trees. This can
5497 confuse the CFG hooks, so be careful to not manipulate CFG during
5501 gimple_expand_cfg (void)
5503 basic_block bb
, init_block
;
5507 rtx var_seq
, var_ret_seq
;
5510 timevar_push (TV_OUT_OF_SSA
);
5511 rewrite_out_of_ssa (&SA
);
5512 timevar_pop (TV_OUT_OF_SSA
);
5513 SA
.partition_to_pseudo
= XCNEWVEC (rtx
, SA
.map
->num_partitions
);
5515 /* Make sure all values used by the optimization passes have sane
5519 /* Some backends want to know that we are expanding to RTL. */
5520 currently_expanding_to_rtl
= 1;
5521 /* Dominators are not kept up-to-date as we may create new basic-blocks. */
5522 free_dominance_info (CDI_DOMINATORS
);
5524 rtl_profile_for_bb (ENTRY_BLOCK_PTR
);
5526 insn_locations_init ();
5527 if (!DECL_IS_BUILTIN (current_function_decl
))
5529 /* Eventually, all FEs should explicitly set function_start_locus. */
5530 if (LOCATION_LOCUS (cfun
->function_start_locus
) == UNKNOWN_LOCATION
)
5531 set_curr_insn_location
5532 (DECL_SOURCE_LOCATION (current_function_decl
));
5534 set_curr_insn_location (cfun
->function_start_locus
);
5537 set_curr_insn_location (UNKNOWN_LOCATION
);
5538 prologue_location
= curr_insn_location ();
5540 #ifdef INSN_SCHEDULING
5541 init_sched_attrs ();
5544 /* Make sure first insn is a note even if we don't want linenums.
5545 This makes sure the first insn will never be deleted.
5546 Also, final expects a note to appear there. */
5547 emit_note (NOTE_INSN_DELETED
);
5549 /* Mark arrays indexed with non-constant indices with TREE_ADDRESSABLE. */
5550 discover_nonconstant_array_refs ();
5552 targetm
.expand_to_rtl_hook ();
5553 crtl
->stack_alignment_needed
= STACK_BOUNDARY
;
5554 crtl
->max_used_stack_slot_alignment
= STACK_BOUNDARY
;
5555 crtl
->stack_alignment_estimated
= 0;
5556 crtl
->preferred_stack_boundary
= STACK_BOUNDARY
;
5557 cfun
->cfg
->max_jumptable_ents
= 0;
5559 /* Resovle the function section. Some targets, like ARM EABI rely on knowledge
5560 of the function section at exapnsion time to predict distance of calls. */
5561 resolve_unique_section (current_function_decl
, 0, flag_function_sections
);
5563 /* Expand the variables recorded during gimple lowering. */
5564 timevar_push (TV_VAR_EXPAND
);
5567 var_ret_seq
= expand_used_vars ();
5569 var_seq
= get_insns ();
5571 timevar_pop (TV_VAR_EXPAND
);
5573 /* Honor stack protection warnings. */
5574 if (warn_stack_protect
)
5576 if (cfun
->calls_alloca
)
5577 warning (OPT_Wstack_protector
,
5578 "stack protector not protecting local variables: "
5579 "variable length buffer");
5580 if (has_short_buffer
&& !crtl
->stack_protect_guard
)
5581 warning (OPT_Wstack_protector
,
5582 "stack protector not protecting function: "
5583 "all local arrays are less than %d bytes long",
5584 (int) PARAM_VALUE (PARAM_SSP_BUFFER_SIZE
));
5587 /* Set up parameters and prepare for return, for the function. */
5588 expand_function_start (current_function_decl
);
5590 /* If we emitted any instructions for setting up the variables,
5591 emit them before the FUNCTION_START note. */
5594 emit_insn_before (var_seq
, parm_birth_insn
);
5596 /* In expand_function_end we'll insert the alloca save/restore
5597 before parm_birth_insn. We've just insertted an alloca call.
5598 Adjust the pointer to match. */
5599 parm_birth_insn
= var_seq
;
5602 /* Now that we also have the parameter RTXs, copy them over to our
5604 for (i
= 0; i
< SA
.map
->num_partitions
; i
++)
5606 tree var
= SSA_NAME_VAR (partition_to_var (SA
.map
, i
));
5608 if (TREE_CODE (var
) != VAR_DECL
5609 && !SA
.partition_to_pseudo
[i
])
5610 SA
.partition_to_pseudo
[i
] = DECL_RTL_IF_SET (var
);
5611 gcc_assert (SA
.partition_to_pseudo
[i
]);
5613 /* If this decl was marked as living in multiple places, reset
5614 this now to NULL. */
5615 if (DECL_RTL_IF_SET (var
) == pc_rtx
)
5616 SET_DECL_RTL (var
, NULL
);
5618 /* Some RTL parts really want to look at DECL_RTL(x) when x
5619 was a decl marked in REG_ATTR or MEM_ATTR. We could use
5620 SET_DECL_RTL here making this available, but that would mean
5621 to select one of the potentially many RTLs for one DECL. Instead
5622 of doing that we simply reset the MEM_EXPR of the RTL in question,
5623 then nobody can get at it and hence nobody can call DECL_RTL on it. */
5624 if (!DECL_RTL_SET_P (var
))
5626 if (MEM_P (SA
.partition_to_pseudo
[i
]))
5627 set_mem_expr (SA
.partition_to_pseudo
[i
], NULL
);
5631 /* If we have a class containing differently aligned pointers
5632 we need to merge those into the corresponding RTL pointer
5634 for (i
= 1; i
< num_ssa_names
; i
++)
5636 tree name
= ssa_name (i
);
5641 /* We might have generated new SSA names in
5642 update_alias_info_with_stack_vars. They will have a NULL
5643 defining statements, and won't be part of the partitioning,
5645 || !SSA_NAME_DEF_STMT (name
))
5647 part
= var_to_partition (SA
.map
, name
);
5648 if (part
== NO_PARTITION
)
5651 /* Adjust all partition members to get the underlying decl of
5652 the representative which we might have created in expand_one_var. */
5653 if (SSA_NAME_VAR (name
) == NULL_TREE
)
5655 tree leader
= partition_to_var (SA
.map
, part
);
5656 gcc_assert (SSA_NAME_VAR (leader
) != NULL_TREE
);
5657 replace_ssa_name_symbol (name
, SSA_NAME_VAR (leader
));
5659 if (!POINTER_TYPE_P (TREE_TYPE (name
)))
5662 r
= SA
.partition_to_pseudo
[part
];
5664 mark_reg_pointer (r
, get_pointer_alignment (name
));
5667 /* If this function is `main', emit a call to `__main'
5668 to run global initializers, etc. */
5669 if (DECL_NAME (current_function_decl
)
5670 && MAIN_NAME_P (DECL_NAME (current_function_decl
))
5671 && DECL_FILE_SCOPE_P (current_function_decl
))
5672 expand_main_function ();
5674 /* Initialize the stack_protect_guard field. This must happen after the
5675 call to __main (if any) so that the external decl is initialized. */
5676 if (crtl
->stack_protect_guard
)
5677 stack_protect_prologue ();
5679 expand_phi_nodes (&SA
);
5681 /* Register rtl specific functions for cfg. */
5682 rtl_register_cfg_hooks ();
5684 init_block
= construct_init_block ();
5686 /* Clear EDGE_EXECUTABLE on the entry edge(s). It is cleaned from the
5687 remaining edges later. */
5688 FOR_EACH_EDGE (e
, ei
, ENTRY_BLOCK_PTR
->succs
)
5689 e
->flags
&= ~EDGE_EXECUTABLE
;
5691 lab_rtx_for_bb
= pointer_map_create ();
5692 FOR_BB_BETWEEN (bb
, init_block
->next_bb
, EXIT_BLOCK_PTR
, next_bb
)
5693 bb
= expand_gimple_basic_block (bb
, var_ret_seq
!= NULL_RTX
);
5695 if (MAY_HAVE_DEBUG_INSNS
)
5696 expand_debug_locations ();
5698 /* Free stuff we no longer need after GIMPLE optimizations. */
5699 free_dominance_info (CDI_DOMINATORS
);
5700 free_dominance_info (CDI_POST_DOMINATORS
);
5701 delete_tree_cfg_annotations ();
5703 timevar_push (TV_OUT_OF_SSA
);
5704 finish_out_of_ssa (&SA
);
5705 timevar_pop (TV_OUT_OF_SSA
);
5707 timevar_push (TV_POST_EXPAND
);
5708 /* We are no longer in SSA form. */
5709 cfun
->gimple_df
->in_ssa_p
= false;
5711 loops_state_clear (LOOP_CLOSED_SSA
);
5713 /* Expansion is used by optimization passes too, set maybe_hot_insn_p
5714 conservatively to true until they are all profile aware. */
5715 pointer_map_destroy (lab_rtx_for_bb
);
5718 construct_exit_block ();
5719 insn_locations_finalize ();
5723 rtx after
= return_label
;
5724 rtx next
= NEXT_INSN (after
);
5725 if (next
&& NOTE_INSN_BASIC_BLOCK_P (next
))
5727 emit_insn_after (var_ret_seq
, after
);
5730 /* Zap the tree EH table. */
5731 set_eh_throw_stmt_table (cfun
, NULL
);
5733 /* We need JUMP_LABEL be set in order to redirect jumps, and hence
5734 split edges which edge insertions might do. */
5735 rebuild_jump_labels (get_insns ());
5737 FOR_BB_BETWEEN (bb
, ENTRY_BLOCK_PTR
, EXIT_BLOCK_PTR
, next_bb
)
5741 for (ei
= ei_start (bb
->succs
); (e
= ei_safe_edge (ei
)); )
5745 rebuild_jump_labels_chain (e
->insns
.r
);
5746 /* Put insns after parm birth, but before
5747 NOTE_INSNS_FUNCTION_BEG. */
5748 if (e
->src
== ENTRY_BLOCK_PTR
5749 && single_succ_p (ENTRY_BLOCK_PTR
))
5751 rtx insns
= e
->insns
.r
;
5752 e
->insns
.r
= NULL_RTX
;
5753 if (NOTE_P (parm_birth_insn
)
5754 && NOTE_KIND (parm_birth_insn
) == NOTE_INSN_FUNCTION_BEG
)
5755 emit_insn_before_noloc (insns
, parm_birth_insn
, e
->dest
);
5757 emit_insn_after_noloc (insns
, parm_birth_insn
, e
->dest
);
5760 commit_one_edge_insertion (e
);
5767 /* We're done expanding trees to RTL. */
5768 currently_expanding_to_rtl
= 0;
5770 FOR_BB_BETWEEN (bb
, ENTRY_BLOCK_PTR
->next_bb
, EXIT_BLOCK_PTR
, next_bb
)
5774 for (ei
= ei_start (bb
->succs
); (e
= ei_safe_edge (ei
)); )
5776 /* Clear EDGE_EXECUTABLE. This flag is never used in the backend. */
5777 e
->flags
&= ~EDGE_EXECUTABLE
;
5779 /* At the moment not all abnormal edges match the RTL
5780 representation. It is safe to remove them here as
5781 find_many_sub_basic_blocks will rediscover them.
5782 In the future we should get this fixed properly. */
5783 if ((e
->flags
& EDGE_ABNORMAL
)
5784 && !(e
->flags
& EDGE_SIBCALL
))
5791 blocks
= sbitmap_alloc (last_basic_block
);
5792 bitmap_ones (blocks
);
5793 find_many_sub_basic_blocks (blocks
);
5794 sbitmap_free (blocks
);
5795 purge_all_dead_edges ();
5797 expand_stack_alignment ();
5799 /* Fixup REG_EQUIV notes in the prologue if there are tailcalls in this
5801 if (crtl
->tail_call_emit
)
5802 fixup_tail_calls ();
5804 /* After initial rtl generation, call back to finish generating
5805 exception support code. We need to do this before cleaning up
5806 the CFG as the code does not expect dead landing pads. */
5807 if (cfun
->eh
->region_tree
!= NULL
)
5808 finish_eh_generation ();
5810 /* Remove unreachable blocks, otherwise we cannot compute dominators
5811 which are needed for loop state verification. As a side-effect
5812 this also compacts blocks.
5813 ??? We cannot remove trivially dead insns here as for example
5814 the DRAP reg on i?86 is not magically live at this point.
5815 gcc.c-torture/execute/ipa-sra-2.c execution, -Os -m32 fails otherwise. */
5816 cleanup_cfg (CLEANUP_NO_INSN_DEL
);
5818 #ifdef ENABLE_CHECKING
5819 verify_flow_info ();
5822 /* Initialize pseudos allocated for hard registers. */
5823 emit_initial_value_sets ();
5825 /* And finally unshare all RTL. */
5828 /* There's no need to defer outputting this function any more; we
5829 know we want to output it. */
5830 DECL_DEFER_OUTPUT (current_function_decl
) = 0;
5832 /* Now that we're done expanding trees to RTL, we shouldn't have any
5833 more CONCATs anywhere. */
5834 generating_concat_p
= 0;
5839 "\n\n;;\n;; Full RTL generated for this function:\n;;\n");
5840 /* And the pass manager will dump RTL for us. */
5843 /* If we're emitting a nested function, make sure its parent gets
5844 emitted as well. Doing otherwise confuses debug info. */
5847 for (parent
= DECL_CONTEXT (current_function_decl
);
5848 parent
!= NULL_TREE
;
5849 parent
= get_containing_scope (parent
))
5850 if (TREE_CODE (parent
) == FUNCTION_DECL
)
5851 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent
)) = 1;
5854 /* We are now committed to emitting code for this function. Do any
5855 preparation, such as emitting abstract debug info for the inline
5856 before it gets mangled by optimization. */
5857 if (cgraph_function_possibly_inlined_p (current_function_decl
))
5858 (*debug_hooks
->outlining_inline_function
) (current_function_decl
);
5860 TREE_ASM_WRITTEN (current_function_decl
) = 1;
5862 /* After expanding, the return labels are no longer needed. */
5863 return_label
= NULL
;
5864 naked_return_label
= NULL
;
5866 /* After expanding, the tm_restart map is no longer needed. */
5867 if (cfun
->gimple_df
->tm_restart
)
5869 htab_delete (cfun
->gimple_df
->tm_restart
);
5870 cfun
->gimple_df
->tm_restart
= NULL
;
5873 /* Tag the blocks with a depth number so that change_scope can find
5874 the common parent easily. */
5875 set_block_levels (DECL_INITIAL (cfun
->decl
), 0);
5876 default_rtl_profile ();
5878 timevar_pop (TV_POST_EXPAND
);
5885 const pass_data pass_data_expand
=
5887 RTL_PASS
, /* type */
5888 "expand", /* name */
5889 OPTGROUP_NONE
, /* optinfo_flags */
5890 false, /* has_gate */
5891 true, /* has_execute */
5892 TV_EXPAND
, /* tv_id */
5893 ( PROP_ssa
| PROP_gimple_leh
| PROP_cfg
5895 | PROP_gimple_lvec
), /* properties_required */
5896 PROP_rtl
, /* properties_provided */
5897 ( PROP_ssa
| PROP_trees
), /* properties_destroyed */
5898 ( TODO_verify_ssa
| TODO_verify_flow
5899 | TODO_verify_stmts
), /* todo_flags_start */
5900 0, /* todo_flags_finish */
5903 class pass_expand
: public rtl_opt_pass
5906 pass_expand (gcc::context
*ctxt
)
5907 : rtl_opt_pass (pass_data_expand
, ctxt
)
5910 /* opt_pass methods: */
5911 unsigned int execute () { return gimple_expand_cfg (); }
5913 }; // class pass_expand
5918 make_pass_expand (gcc::context
*ctxt
)
5920 return new pass_expand (ctxt
);