1 /* Expands front end tree to back end RTL for GCC
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 /* This file handles the generation of rtl code from tree structure
23 above the level of expressions, using subroutines in exp*.c and emit-rtl.c.
24 It also creates the rtl expressions for parameters and auto variables
25 and has full responsibility for allocating stack slots.
27 The functions whose names start with `expand_' are called by the
28 parser to generate RTL instructions for various kinds of constructs.
30 Some control and binding constructs require calling several such
31 functions at different times. For example, a simple if-then
32 is expanded by calling `expand_start_cond' (with the condition-expression
33 as argument) before parsing the then-clause and calling `expand_end_cond'
34 after parsing the then-clause. */
38 #include "coretypes.h"
47 #include "insn-config.h"
50 #include "hard-reg-set.h"
57 #include "langhooks.h"
62 /* Assume that case vectors are not pc-relative. */
63 #ifndef CASE_VECTOR_PC_RELATIVE
64 #define CASE_VECTOR_PC_RELATIVE 0
67 /* Functions and data structures for expanding case statements. */
69 /* Case label structure, used to hold info on labels within case
70 statements. We handle "range" labels; for a single-value label
71 as in C, the high and low limits are the same.
73 An AVL tree of case nodes is initially created, and later transformed
74 to a list linked via the RIGHT fields in the nodes. Nodes with
75 higher case values are later in the list.
77 Switch statements can be output in one of two forms. A branch table
78 is used if there are more than a few labels and the labels are dense
79 within the range between the smallest and largest case value. If a
80 branch table is used, no further manipulations are done with the case
83 The alternative to the use of a branch table is to generate a series
84 of compare and jump insns. When that is done, we use the LEFT, RIGHT,
85 and PARENT fields to hold a binary tree. Initially the tree is
86 totally unbalanced, with everything on the right. We balance the tree
87 with nodes on the left having lower case values than the parent
88 and nodes on the right having higher values. We then output the tree
91 struct case_node
GTY(())
93 struct case_node
*left
; /* Left son in binary tree */
94 struct case_node
*right
; /* Right son in binary tree; also node chain */
95 struct case_node
*parent
; /* Parent of node in binary tree */
96 tree low
; /* Lowest index value for this label */
97 tree high
; /* Highest index value for this label */
98 tree code_label
; /* Label to jump to when node matches */
102 typedef struct case_node case_node
;
103 typedef struct case_node
*case_node_ptr
;
105 /* These are used by estimate_case_costs and balance_case_nodes. */
107 /* This must be a signed type, and non-ANSI compilers lack signed char. */
108 static short cost_table_
[129];
109 static int use_cost_table
;
110 static int cost_table_initialized
;
112 /* Special care is needed because we allow -1, but TREE_INT_CST_LOW
114 #define COST_TABLE(I) cost_table_[(unsigned HOST_WIDE_INT) ((I) + 1)]
116 /* Stack of control and binding constructs we are currently inside.
118 These constructs begin when you call `expand_start_WHATEVER'
119 and end when you call `expand_end_WHATEVER'. This stack records
120 info about how the construct began that tells the end-function
121 what to do. It also may provide information about the construct
122 to alter the behavior of other constructs within the body.
123 For example, they may affect the behavior of C `break' and `continue'.
125 Each construct gets one `struct nesting' object.
126 All of these objects are chained through the `all' field.
127 `nesting_stack' points to the first object (innermost construct).
128 The position of an entry on `nesting_stack' is in its `depth' field.
130 Each type of construct has its own individual stack.
131 For example, loops have `loop_stack'. Each object points to the
132 next object of the same type through the `next' field.
134 Some constructs are visible to `break' exit-statements and others
135 are not. Which constructs are visible depends on the language.
136 Therefore, the data structure allows each construct to be visible
137 or not, according to the args given when the construct is started.
138 The construct is visible if the `exit_label' field is non-null.
139 In that case, the value should be a CODE_LABEL rtx. */
141 struct nesting
GTY(())
144 struct nesting
*next
;
155 /* For conds (if-then and if-then-else statements). */
158 /* Label for the end of the if construct.
159 There is none if EXITFLAG was not set
160 and no `else' has been seen yet. */
162 /* Label for the end of this alternative.
163 This may be the end of the if or the next else/elseif. */
165 } GTY ((tag ("COND_NESTING"))) cond
;
169 /* Label at the top of the loop; place to loop back to. */
171 /* Label at the end of the whole construct. */
173 /* Label for `continue' statement to jump to;
174 this is in front of the stepper of the loop. */
176 } GTY ((tag ("LOOP_NESTING"))) loop
;
177 /* For variable binding contours. */
180 /* Sequence number of this binding contour within the function,
181 in order of entry. */
182 int block_start_count
;
183 /* Nonzero => value to restore stack to on exit. */
185 /* The NOTE that starts this contour.
186 Used by expand_goto to check whether the destination
187 is within each contour or not. */
189 /* Innermost containing binding contour that has a stack level. */
190 struct nesting
*innermost_stack_block
;
191 /* List of cleanups to be run on exit from this contour.
192 This is a list of expressions to be evaluated.
193 The TREE_PURPOSE of each link is the ..._DECL node
194 which the cleanup pertains to. */
196 /* List of cleanup-lists of blocks containing this block,
197 as they were at the locus where this block appears.
198 There is an element for each containing block,
199 ordered innermost containing block first.
200 The tail of this list can be 0,
201 if all remaining elements would be empty lists.
202 The element's TREE_VALUE is the cleanup-list of that block,
203 which may be null. */
205 /* Chain of labels defined inside this binding contour.
206 For contours that have stack levels or cleanups. */
207 struct label_chain
*label_chain
;
208 /* Nonzero if this is associated with an EH region. */
209 int exception_region
;
210 /* The saved target_temp_slot_level from our outer block.
211 We may reset target_temp_slot_level to be the level of
212 this block, if that is done, target_temp_slot_level
213 reverts to the saved target_temp_slot_level at the very
215 int block_target_temp_slot_level
;
216 /* True if we are currently emitting insns in an area of
217 output code that is controlled by a conditional
218 expression. This is used by the cleanup handling code to
219 generate conditional cleanup actions. */
220 int conditional_code
;
221 /* A place to move the start of the exception region for any
222 of the conditional cleanups, must be at the end or after
223 the start of the last unconditional cleanup, and before any
224 conditional branch points. */
225 rtx last_unconditional_cleanup
;
226 } GTY ((tag ("BLOCK_NESTING"))) block
;
227 /* For switch (C) or case (Pascal) statements,
228 and also for dummies (see `expand_start_case_dummy'). */
231 /* The insn after which the case dispatch should finally
232 be emitted. Zero for a dummy. */
234 /* A list of case labels; it is first built as an AVL tree.
235 During expand_end_case, this is converted to a list, and may be
236 rearranged into a nearly balanced binary tree. */
237 struct case_node
*case_list
;
238 /* Label to jump to if no case matches. */
240 /* The expression to be dispatched on. */
242 /* Type that INDEX_EXPR should be converted to. */
244 /* Name of this kind of statement, for warnings. */
245 const char *printname
;
246 /* Used to save no_line_numbers till we see the first case label.
247 We set this to -1 when we see the first case label in this
249 int line_number_status
;
250 } GTY ((tag ("CASE_NESTING"))) case_stmt
;
251 } GTY ((desc ("%1.desc"))) data
;
254 /* Allocate and return a new `struct nesting'. */
256 #define ALLOC_NESTING() ggc_alloc (sizeof (struct nesting))
258 /* Pop the nesting stack element by element until we pop off
259 the element which is at the top of STACK.
260 Update all the other stacks, popping off elements from them
261 as we pop them from nesting_stack. */
263 #define POPSTACK(STACK) \
264 do { struct nesting *target = STACK; \
265 struct nesting *this; \
266 do { this = nesting_stack; \
267 if (loop_stack == this) \
268 loop_stack = loop_stack->next; \
269 if (cond_stack == this) \
270 cond_stack = cond_stack->next; \
271 if (block_stack == this) \
272 block_stack = block_stack->next; \
273 if (stack_block_stack == this) \
274 stack_block_stack = stack_block_stack->next; \
275 if (case_stack == this) \
276 case_stack = case_stack->next; \
277 nesting_depth = nesting_stack->depth - 1; \
278 nesting_stack = this->all; } \
279 while (this != target); } while (0)
281 /* In some cases it is impossible to generate code for a forward goto
282 until the label definition is seen. This happens when it may be necessary
283 for the goto to reset the stack pointer: we don't yet know how to do that.
284 So expand_goto puts an entry on this fixup list.
285 Each time a binding contour that resets the stack is exited,
287 If the target label has now been defined, we can insert the proper code. */
289 struct goto_fixup
GTY(())
291 /* Points to following fixup. */
292 struct goto_fixup
*next
;
293 /* Points to the insn before the jump insn.
294 If more code must be inserted, it goes after this insn. */
296 /* The LABEL_DECL that this jump is jumping to, or 0
297 for break, continue or return. */
299 /* The BLOCK for the place where this goto was found. */
301 /* The CODE_LABEL rtx that this is jumping to. */
303 /* Number of binding contours started in current function
304 before the label reference. */
305 int block_start_count
;
306 /* The outermost stack level that should be restored for this jump.
307 Each time a binding contour that resets the stack is exited,
308 if the target label is *not* yet defined, this slot is updated. */
310 /* List of lists of cleanup expressions to be run by this goto.
311 There is one element for each block that this goto is within.
312 The tail of this list can be 0,
313 if all remaining elements would be empty.
314 The TREE_VALUE contains the cleanup list of that block as of the
315 time this goto was seen.
316 The TREE_ADDRESSABLE flag is 1 for a block that has been exited. */
317 tree cleanup_list_list
;
320 /* Within any binding contour that must restore a stack level,
321 all labels are recorded with a chain of these structures. */
323 struct label_chain
GTY(())
325 /* Points to following fixup. */
326 struct label_chain
*next
;
330 struct stmt_status
GTY(())
332 /* Chain of all pending binding contours. */
333 struct nesting
* x_block_stack
;
335 /* If any new stacks are added here, add them to POPSTACKS too. */
337 /* Chain of all pending binding contours that restore stack levels
339 struct nesting
* x_stack_block_stack
;
341 /* Chain of all pending conditional statements. */
342 struct nesting
* x_cond_stack
;
344 /* Chain of all pending loops. */
345 struct nesting
* x_loop_stack
;
347 /* Chain of all pending case or switch statements. */
348 struct nesting
* x_case_stack
;
350 /* Separate chain including all of the above,
351 chained through the `all' field. */
352 struct nesting
* x_nesting_stack
;
354 /* Number of entries on nesting_stack now. */
357 /* Number of binding contours started so far in this function. */
358 int x_block_start_count
;
360 /* Each time we expand an expression-statement,
361 record the expr's type and its RTL value here. */
362 tree x_last_expr_type
;
363 rtx x_last_expr_value
;
364 rtx x_last_expr_alt_rtl
;
366 /* Nonzero if within a ({...}) grouping, in which case we must
367 always compute a value for each expr-stmt in case it is the last one. */
368 int x_expr_stmts_for_value
;
370 /* Location of last line-number note, whether we actually
371 emitted it or not. */
372 location_t x_emit_locus
;
374 struct goto_fixup
*x_goto_fixup_chain
;
377 #define block_stack (cfun->stmt->x_block_stack)
378 #define stack_block_stack (cfun->stmt->x_stack_block_stack)
379 #define cond_stack (cfun->stmt->x_cond_stack)
380 #define loop_stack (cfun->stmt->x_loop_stack)
381 #define case_stack (cfun->stmt->x_case_stack)
382 #define nesting_stack (cfun->stmt->x_nesting_stack)
383 #define nesting_depth (cfun->stmt->x_nesting_depth)
384 #define current_block_start_count (cfun->stmt->x_block_start_count)
385 #define last_expr_type (cfun->stmt->x_last_expr_type)
386 #define last_expr_value (cfun->stmt->x_last_expr_value)
387 #define last_expr_alt_rtl (cfun->stmt->x_last_expr_alt_rtl)
388 #define expr_stmts_for_value (cfun->stmt->x_expr_stmts_for_value)
389 #define emit_locus (cfun->stmt->x_emit_locus)
390 #define goto_fixup_chain (cfun->stmt->x_goto_fixup_chain)
392 /* Nonzero if we are using EH to handle cleanups. */
393 static int using_eh_for_cleanups_p
= 0;
395 static int n_occurrences (int, const char *);
396 static bool decl_conflicts_with_clobbers_p (tree
, const HARD_REG_SET
);
397 static void expand_goto_internal (tree
, rtx
, rtx
);
398 static int expand_fixup (tree
, rtx
, rtx
);
399 static rtx
expand_nl_handler_label (rtx
, rtx
);
400 static void expand_nl_goto_receiver (void);
401 static void expand_nl_goto_receivers (struct nesting
*);
402 static void fixup_gotos (struct nesting
*, rtx
, tree
, rtx
, int);
403 static bool check_operand_nalternatives (tree
, tree
);
404 static bool check_unique_operand_names (tree
, tree
);
405 static char *resolve_operand_name_1 (char *, tree
, tree
);
406 static void expand_null_return_1 (rtx
);
407 static enum br_predictor
return_prediction (rtx
);
408 static rtx
shift_return_value (rtx
);
409 static void expand_value_return (rtx
);
410 static int tail_recursion_args (tree
, tree
);
411 static void expand_cleanups (tree
, int, int);
412 static void check_seenlabel (void);
413 static void do_jump_if_equal (rtx
, rtx
, rtx
, int);
414 static int estimate_case_costs (case_node_ptr
);
415 static bool same_case_target_p (rtx
, rtx
);
416 static void strip_default_case_nodes (case_node_ptr
*, rtx
);
417 static bool lshift_cheap_p (void);
418 static int case_bit_test_cmp (const void *, const void *);
419 static void emit_case_bit_tests (tree
, tree
, tree
, tree
, case_node_ptr
, rtx
);
420 static void group_case_nodes (case_node_ptr
);
421 static void balance_case_nodes (case_node_ptr
*, case_node_ptr
);
422 static int node_has_low_bound (case_node_ptr
, tree
);
423 static int node_has_high_bound (case_node_ptr
, tree
);
424 static int node_is_bounded (case_node_ptr
, tree
);
425 static void emit_jump_if_reachable (rtx
);
426 static void emit_case_nodes (rtx
, case_node_ptr
, rtx
, tree
);
427 static struct case_node
*case_tree2list (case_node
*, case_node
*);
430 using_eh_for_cleanups (void)
432 using_eh_for_cleanups_p
= 1;
436 init_stmt_for_function (void)
438 cfun
->stmt
= ggc_alloc_cleared (sizeof (struct stmt_status
));
441 /* Record the current file and line. Called from emit_line_note. */
444 set_file_and_line_for_stmt (location_t location
)
446 /* If we're outputting an inline function, and we add a line note,
447 there may be no CFUN->STMT information. So, there's no need to
450 emit_locus
= location
;
453 /* Emit a no-op instruction. */
460 last_insn
= get_last_insn ();
462 && (GET_CODE (last_insn
) == CODE_LABEL
463 || (GET_CODE (last_insn
) == NOTE
464 && prev_real_insn (last_insn
) == 0)))
465 emit_insn (gen_nop ());
468 /* Return the rtx-label that corresponds to a LABEL_DECL,
469 creating it if necessary. */
472 label_rtx (tree label
)
474 if (TREE_CODE (label
) != LABEL_DECL
)
477 if (!DECL_RTL_SET_P (label
))
478 SET_DECL_RTL (label
, gen_label_rtx ());
480 return DECL_RTL (label
);
483 /* As above, but also put it on the forced-reference list of the
484 function that contains it. */
486 force_label_rtx (tree label
)
488 rtx ref
= label_rtx (label
);
489 tree function
= decl_function_context (label
);
495 if (function
!= current_function_decl
496 && function
!= inline_function_decl
)
497 p
= find_function_data (function
);
501 p
->expr
->x_forced_labels
= gen_rtx_EXPR_LIST (VOIDmode
, ref
,
502 p
->expr
->x_forced_labels
);
506 /* Add an unconditional jump to LABEL as the next sequential instruction. */
509 emit_jump (rtx label
)
511 do_pending_stack_adjust ();
512 emit_jump_insn (gen_jump (label
));
516 /* Emit code to jump to the address
517 specified by the pointer expression EXP. */
520 expand_computed_goto (tree exp
)
522 rtx x
= expand_expr (exp
, NULL_RTX
, VOIDmode
, 0);
524 x
= convert_memory_address (Pmode
, x
);
528 if (! cfun
->computed_goto_common_label
)
530 cfun
->computed_goto_common_reg
= copy_to_mode_reg (Pmode
, x
);
531 cfun
->computed_goto_common_label
= gen_label_rtx ();
532 emit_label (cfun
->computed_goto_common_label
);
534 do_pending_stack_adjust ();
535 emit_indirect_jump (cfun
->computed_goto_common_reg
);
537 current_function_has_computed_jump
= 1;
541 emit_move_insn (cfun
->computed_goto_common_reg
, x
);
542 emit_jump (cfun
->computed_goto_common_label
);
546 /* Handle goto statements and the labels that they can go to. */
548 /* Specify the location in the RTL code of a label LABEL,
549 which is a LABEL_DECL tree node.
551 This is used for the kind of label that the user can jump to with a
552 goto statement, and for alternatives of a switch or case statement.
553 RTL labels generated for loops and conditionals don't go through here;
554 they are generated directly at the RTL level, by other functions below.
556 Note that this has nothing to do with defining label *names*.
557 Languages vary in how they do that and what that even means. */
560 expand_label (tree label
)
562 struct label_chain
*p
;
564 do_pending_stack_adjust ();
565 emit_label (label_rtx (label
));
566 if (DECL_NAME (label
))
567 LABEL_NAME (DECL_RTL (label
)) = IDENTIFIER_POINTER (DECL_NAME (label
));
569 if (stack_block_stack
!= 0)
571 p
= ggc_alloc (sizeof (struct label_chain
));
572 p
->next
= stack_block_stack
->data
.block
.label_chain
;
573 stack_block_stack
->data
.block
.label_chain
= p
;
578 /* Declare that LABEL (a LABEL_DECL) may be used for nonlocal gotos
579 from nested functions. */
582 declare_nonlocal_label (tree label
)
584 rtx slot
= assign_stack_local (Pmode
, GET_MODE_SIZE (Pmode
), 0);
586 nonlocal_labels
= tree_cons (NULL_TREE
, label
, nonlocal_labels
);
587 LABEL_PRESERVE_P (label_rtx (label
)) = 1;
588 if (nonlocal_goto_handler_slots
== 0)
590 emit_stack_save (SAVE_NONLOCAL
,
591 &nonlocal_goto_stack_level
,
592 PREV_INSN (tail_recursion_reentry
));
594 nonlocal_goto_handler_slots
595 = gen_rtx_EXPR_LIST (VOIDmode
, slot
, nonlocal_goto_handler_slots
);
598 /* Generate RTL code for a `goto' statement with target label LABEL.
599 LABEL should be a LABEL_DECL tree node that was or will later be
600 defined with `expand_label'. */
603 expand_goto (tree label
)
607 /* Check for a nonlocal goto to a containing function. */
608 context
= decl_function_context (label
);
609 if (context
!= 0 && context
!= current_function_decl
)
611 struct function
*p
= find_function_data (context
);
612 rtx label_ref
= gen_rtx_LABEL_REF (Pmode
, label_rtx (label
));
613 rtx handler_slot
, static_chain
, save_area
, insn
;
616 /* Find the corresponding handler slot for this label. */
617 handler_slot
= p
->x_nonlocal_goto_handler_slots
;
618 for (link
= p
->x_nonlocal_labels
; TREE_VALUE (link
) != label
;
619 link
= TREE_CHAIN (link
))
620 handler_slot
= XEXP (handler_slot
, 1);
621 handler_slot
= XEXP (handler_slot
, 0);
623 p
->has_nonlocal_label
= 1;
624 current_function_has_nonlocal_goto
= 1;
625 LABEL_REF_NONLOCAL_P (label_ref
) = 1;
627 /* Copy the rtl for the slots so that they won't be shared in
628 case the virtual stack vars register gets instantiated differently
629 in the parent than in the child. */
631 static_chain
= copy_to_reg (lookup_static_chain (label
));
633 /* Get addr of containing function's current nonlocal goto handler,
634 which will do any cleanups and then jump to the label. */
635 handler_slot
= copy_to_reg (replace_rtx (copy_rtx (handler_slot
),
636 virtual_stack_vars_rtx
,
639 /* Get addr of containing function's nonlocal save area. */
640 save_area
= p
->x_nonlocal_goto_stack_level
;
642 save_area
= replace_rtx (copy_rtx (save_area
),
643 virtual_stack_vars_rtx
, static_chain
);
645 #if HAVE_nonlocal_goto
646 if (HAVE_nonlocal_goto
)
647 emit_insn (gen_nonlocal_goto (static_chain
, handler_slot
,
648 save_area
, label_ref
));
652 emit_insn (gen_rtx_CLOBBER (VOIDmode
,
653 gen_rtx_MEM (BLKmode
,
654 gen_rtx_SCRATCH (VOIDmode
))));
655 emit_insn (gen_rtx_CLOBBER (VOIDmode
,
656 gen_rtx_MEM (BLKmode
,
657 hard_frame_pointer_rtx
)));
659 /* Restore frame pointer for containing function.
660 This sets the actual hard register used for the frame pointer
661 to the location of the function's incoming static chain info.
662 The non-local goto handler will then adjust it to contain the
663 proper value and reload the argument pointer, if needed. */
664 emit_move_insn (hard_frame_pointer_rtx
, static_chain
);
665 emit_stack_restore (SAVE_NONLOCAL
, save_area
, NULL_RTX
);
667 /* USE of hard_frame_pointer_rtx added for consistency;
668 not clear if really needed. */
669 emit_insn (gen_rtx_USE (VOIDmode
, hard_frame_pointer_rtx
));
670 emit_insn (gen_rtx_USE (VOIDmode
, stack_pointer_rtx
));
671 emit_indirect_jump (handler_slot
);
674 /* Search backwards to the jump insn and mark it as a
676 for (insn
= get_last_insn (); insn
; insn
= PREV_INSN (insn
))
678 if (GET_CODE (insn
) == JUMP_INSN
)
680 REG_NOTES (insn
) = alloc_EXPR_LIST (REG_NON_LOCAL_GOTO
,
681 const0_rtx
, REG_NOTES (insn
));
684 else if (GET_CODE (insn
) == CALL_INSN
)
689 expand_goto_internal (label
, label_rtx (label
), NULL_RTX
);
692 /* Generate RTL code for a `goto' statement with target label BODY.
693 LABEL should be a LABEL_REF.
694 LAST_INSN, if non-0, is the rtx we should consider as the last
695 insn emitted (for the purposes of cleaning up a return). */
698 expand_goto_internal (tree body
, rtx label
, rtx last_insn
)
700 struct nesting
*block
;
703 if (GET_CODE (label
) != CODE_LABEL
)
706 /* If label has already been defined, we can tell now
707 whether and how we must alter the stack level. */
709 if (PREV_INSN (label
) != 0)
711 /* Find the innermost pending block that contains the label.
712 (Check containment by comparing insn-uids.)
713 Then restore the outermost stack level within that block,
714 and do cleanups of all blocks contained in it. */
715 for (block
= block_stack
; block
; block
= block
->next
)
717 if (INSN_UID (block
->data
.block
.first_insn
) < INSN_UID (label
))
719 if (block
->data
.block
.stack_level
!= 0)
720 stack_level
= block
->data
.block
.stack_level
;
721 /* Execute the cleanups for blocks we are exiting. */
722 if (block
->data
.block
.cleanups
!= 0)
724 expand_cleanups (block
->data
.block
.cleanups
, 1, 1);
725 do_pending_stack_adjust ();
731 /* Ensure stack adjust isn't done by emit_jump, as this
732 would clobber the stack pointer. This one should be
733 deleted as dead by flow. */
734 clear_pending_stack_adjust ();
735 do_pending_stack_adjust ();
737 /* Don't do this adjust if it's to the end label and this function
738 is to return with a depressed stack pointer. */
739 if (label
== return_label
740 && (((TREE_CODE (TREE_TYPE (current_function_decl
))
742 && (TYPE_RETURNS_STACK_DEPRESSED
743 (TREE_TYPE (current_function_decl
))))))
746 emit_stack_restore (SAVE_BLOCK
, stack_level
, NULL_RTX
);
749 if (body
!= 0 && DECL_TOO_LATE (body
))
750 error ("jump to `%s' invalidly jumps into binding contour",
751 IDENTIFIER_POINTER (DECL_NAME (body
)));
753 /* Label not yet defined: may need to put this goto
754 on the fixup list. */
755 else if (! expand_fixup (body
, label
, last_insn
))
757 /* No fixup needed. Record that the label is the target
758 of at least one goto that has no fixup. */
760 TREE_ADDRESSABLE (body
) = 1;
766 /* Generate if necessary a fixup for a goto
767 whose target label in tree structure (if any) is TREE_LABEL
768 and whose target in rtl is RTL_LABEL.
770 If LAST_INSN is nonzero, we pretend that the jump appears
771 after insn LAST_INSN instead of at the current point in the insn stream.
773 The fixup will be used later to insert insns just before the goto.
774 Those insns will restore the stack level as appropriate for the
775 target label, and will (in the case of C++) also invoke any object
776 destructors which have to be invoked when we exit the scopes which
777 are exited by the goto.
779 Value is nonzero if a fixup is made. */
782 expand_fixup (tree tree_label
, rtx rtl_label
, rtx last_insn
)
784 struct nesting
*block
, *end_block
;
786 /* See if we can recognize which block the label will be output in.
787 This is possible in some very common cases.
788 If we succeed, set END_BLOCK to that block.
789 Otherwise, set it to 0. */
792 && (rtl_label
== cond_stack
->data
.cond
.endif_label
793 || rtl_label
== cond_stack
->data
.cond
.next_label
))
794 end_block
= cond_stack
;
795 /* If we are in a loop, recognize certain labels which
796 are likely targets. This reduces the number of fixups
797 we need to create. */
799 && (rtl_label
== loop_stack
->data
.loop
.start_label
800 || rtl_label
== loop_stack
->data
.loop
.end_label
801 || rtl_label
== loop_stack
->data
.loop
.continue_label
))
802 end_block
= loop_stack
;
806 /* Now set END_BLOCK to the binding level to which we will return. */
810 struct nesting
*next_block
= end_block
->all
;
813 /* First see if the END_BLOCK is inside the innermost binding level.
814 If so, then no cleanups or stack levels are relevant. */
815 while (next_block
&& next_block
!= block
)
816 next_block
= next_block
->all
;
821 /* Otherwise, set END_BLOCK to the innermost binding level
822 which is outside the relevant control-structure nesting. */
823 next_block
= block_stack
->next
;
824 for (block
= block_stack
; block
!= end_block
; block
= block
->all
)
825 if (block
== next_block
)
826 next_block
= next_block
->next
;
827 end_block
= next_block
;
830 /* Does any containing block have a stack level or cleanups?
831 If not, no fixup is needed, and that is the normal case
832 (the only case, for standard C). */
833 for (block
= block_stack
; block
!= end_block
; block
= block
->next
)
834 if (block
->data
.block
.stack_level
!= 0
835 || block
->data
.block
.cleanups
!= 0)
838 if (block
!= end_block
)
840 /* Ok, a fixup is needed. Add a fixup to the list of such. */
841 struct goto_fixup
*fixup
= ggc_alloc (sizeof (struct goto_fixup
));
842 /* In case an old stack level is restored, make sure that comes
843 after any pending stack adjust. */
844 /* ?? If the fixup isn't to come at the present position,
845 doing the stack adjust here isn't useful. Doing it with our
846 settings at that location isn't useful either. Let's hope
849 do_pending_stack_adjust ();
850 fixup
->target
= tree_label
;
851 fixup
->target_rtl
= rtl_label
;
853 /* Create a BLOCK node and a corresponding matched set of
854 NOTE_INSN_BLOCK_BEG and NOTE_INSN_BLOCK_END notes at
855 this point. The notes will encapsulate any and all fixup
856 code which we might later insert at this point in the insn
857 stream. Also, the BLOCK node will be the parent (i.e. the
858 `SUPERBLOCK') of any other BLOCK nodes which we might create
859 later on when we are expanding the fixup code.
861 Note that optimization passes (including expand_end_loop)
862 might move the *_BLOCK notes away, so we use a NOTE_INSN_DELETED
866 rtx original_before_jump
867 = last_insn
? last_insn
: get_last_insn ();
872 block
= make_node (BLOCK
);
873 TREE_USED (block
) = 1;
875 if (!cfun
->x_whole_function_mode_p
)
876 (*lang_hooks
.decls
.insert_block
) (block
);
880 = BLOCK_CHAIN (DECL_INITIAL (current_function_decl
));
881 BLOCK_CHAIN (DECL_INITIAL (current_function_decl
))
886 start
= emit_note (NOTE_INSN_BLOCK_BEG
);
887 if (cfun
->x_whole_function_mode_p
)
888 NOTE_BLOCK (start
) = block
;
889 fixup
->before_jump
= emit_note (NOTE_INSN_DELETED
);
890 end
= emit_note (NOTE_INSN_BLOCK_END
);
891 if (cfun
->x_whole_function_mode_p
)
892 NOTE_BLOCK (end
) = block
;
893 fixup
->context
= block
;
895 emit_insn_after (start
, original_before_jump
);
898 fixup
->block_start_count
= current_block_start_count
;
899 fixup
->stack_level
= 0;
900 fixup
->cleanup_list_list
901 = ((block
->data
.block
.outer_cleanups
902 || block
->data
.block
.cleanups
)
903 ? tree_cons (NULL_TREE
, block
->data
.block
.cleanups
,
904 block
->data
.block
.outer_cleanups
)
906 fixup
->next
= goto_fixup_chain
;
907 goto_fixup_chain
= fixup
;
913 /* Expand any needed fixups in the outputmost binding level of the
914 function. FIRST_INSN is the first insn in the function. */
917 expand_fixups (rtx first_insn
)
919 fixup_gotos (NULL
, NULL_RTX
, NULL_TREE
, first_insn
, 0);
922 /* When exiting a binding contour, process all pending gotos requiring fixups.
923 THISBLOCK is the structure that describes the block being exited.
924 STACK_LEVEL is the rtx for the stack level to restore exiting this contour.
925 CLEANUP_LIST is a list of expressions to evaluate on exiting this contour.
926 FIRST_INSN is the insn that began this contour.
928 Gotos that jump out of this contour must restore the
929 stack level and do the cleanups before actually jumping.
931 DONT_JUMP_IN positive means report error if there is a jump into this
932 contour from before the beginning of the contour. This is also done if
933 STACK_LEVEL is nonzero unless DONT_JUMP_IN is negative. */
936 fixup_gotos (struct nesting
*thisblock
, rtx stack_level
,
937 tree cleanup_list
, rtx first_insn
, int dont_jump_in
)
939 struct goto_fixup
*f
, *prev
;
941 /* F is the fixup we are considering; PREV is the previous one. */
942 /* We run this loop in two passes so that cleanups of exited blocks
943 are run first, and blocks that are exited are marked so
946 for (prev
= 0, f
= goto_fixup_chain
; f
; prev
= f
, f
= f
->next
)
948 /* Test for a fixup that is inactive because it is already handled. */
949 if (f
->before_jump
== 0)
951 /* Delete inactive fixup from the chain, if that is easy to do. */
953 prev
->next
= f
->next
;
955 /* Has this fixup's target label been defined?
956 If so, we can finalize it. */
957 else if (PREV_INSN (f
->target_rtl
) != 0)
961 /* If this fixup jumped into this contour from before the beginning
962 of this contour, report an error. This code used to use
963 the first non-label insn after f->target_rtl, but that's
964 wrong since such can be added, by things like put_var_into_stack
965 and have INSN_UIDs that are out of the range of the block. */
966 /* ??? Bug: this does not detect jumping in through intermediate
967 blocks that have stack levels or cleanups.
968 It detects only a problem with the innermost block
971 && (dont_jump_in
> 0 || (dont_jump_in
== 0 && stack_level
)
973 && INSN_UID (first_insn
) < INSN_UID (f
->target_rtl
)
974 && INSN_UID (first_insn
) > INSN_UID (f
->before_jump
)
975 && ! DECL_ERROR_ISSUED (f
->target
))
977 error ("%Jlabel '%D' used before containing binding contour",
978 f
->target
, f
->target
);
979 /* Prevent multiple errors for one label. */
980 DECL_ERROR_ISSUED (f
->target
) = 1;
983 /* We will expand the cleanups into a sequence of their own and
984 then later on we will attach this new sequence to the insn
985 stream just ahead of the actual jump insn. */
989 /* Temporarily restore the lexical context where we will
990 logically be inserting the fixup code. We do this for the
991 sake of getting the debugging information right. */
993 (*lang_hooks
.decls
.pushlevel
) (0);
994 (*lang_hooks
.decls
.set_block
) (f
->context
);
996 /* Expand the cleanups for blocks this jump exits. */
997 if (f
->cleanup_list_list
)
1000 for (lists
= f
->cleanup_list_list
; lists
; lists
= TREE_CHAIN (lists
))
1001 /* Marked elements correspond to blocks that have been closed.
1002 Do their cleanups. */
1003 if (TREE_ADDRESSABLE (lists
)
1004 && TREE_VALUE (lists
) != 0)
1006 expand_cleanups (TREE_VALUE (lists
), 1, 1);
1007 /* Pop any pushes done in the cleanups,
1008 in case function is about to return. */
1009 do_pending_stack_adjust ();
1013 /* Restore stack level for the biggest contour that this
1014 jump jumps out of. */
1016 && ! (f
->target_rtl
== return_label
1017 && ((TREE_CODE (TREE_TYPE (current_function_decl
))
1019 && (TYPE_RETURNS_STACK_DEPRESSED
1020 (TREE_TYPE (current_function_decl
))))))
1021 emit_stack_restore (SAVE_BLOCK
, f
->stack_level
, f
->before_jump
);
1023 /* Finish up the sequence containing the insns which implement the
1024 necessary cleanups, and then attach that whole sequence to the
1025 insn stream just ahead of the actual jump insn. Attaching it
1026 at that point insures that any cleanups which are in fact
1027 implicit C++ object destructions (which must be executed upon
1028 leaving the block) appear (to the debugger) to be taking place
1029 in an area of the generated code where the object(s) being
1030 destructed are still "in scope". */
1032 cleanup_insns
= get_insns ();
1033 (*lang_hooks
.decls
.poplevel
) (1, 0, 0);
1036 emit_insn_after (cleanup_insns
, f
->before_jump
);
1042 /* For any still-undefined labels, do the cleanups for this block now.
1043 We must do this now since items in the cleanup list may go out
1044 of scope when the block ends. */
1045 for (prev
= 0, f
= goto_fixup_chain
; f
; prev
= f
, f
= f
->next
)
1046 if (f
->before_jump
!= 0
1047 && PREV_INSN (f
->target_rtl
) == 0
1048 /* Label has still not appeared. If we are exiting a block with
1049 a stack level to restore, that started before the fixup,
1050 mark this stack level as needing restoration
1051 when the fixup is later finalized. */
1053 /* Note: if THISBLOCK == 0 and we have a label that hasn't appeared, it
1054 means the label is undefined. That's erroneous, but possible. */
1055 && (thisblock
->data
.block
.block_start_count
1056 <= f
->block_start_count
))
1058 tree lists
= f
->cleanup_list_list
;
1061 for (; lists
; lists
= TREE_CHAIN (lists
))
1062 /* If the following elt. corresponds to our containing block
1063 then the elt. must be for this block. */
1064 if (TREE_CHAIN (lists
) == thisblock
->data
.block
.outer_cleanups
)
1067 (*lang_hooks
.decls
.pushlevel
) (0);
1068 (*lang_hooks
.decls
.set_block
) (f
->context
);
1069 expand_cleanups (TREE_VALUE (lists
), 1, 1);
1070 do_pending_stack_adjust ();
1071 cleanup_insns
= get_insns ();
1072 (*lang_hooks
.decls
.poplevel
) (1, 0, 0);
1074 if (cleanup_insns
!= 0)
1076 = emit_insn_after (cleanup_insns
, f
->before_jump
);
1078 f
->cleanup_list_list
= TREE_CHAIN (lists
);
1082 f
->stack_level
= stack_level
;
1086 /* Return the number of times character C occurs in string S. */
1088 n_occurrences (int c
, const char *s
)
1096 /* Generate RTL for an asm statement (explicit assembler code).
1097 STRING is a STRING_CST node containing the assembler code text,
1098 or an ADDR_EXPR containing a STRING_CST. VOL nonzero means the
1099 insn is volatile; don't optimize it. */
1102 expand_asm (tree string
, int vol
)
1106 if (TREE_CODE (string
) == ADDR_EXPR
)
1107 string
= TREE_OPERAND (string
, 0);
1109 body
= gen_rtx_ASM_INPUT (VOIDmode
, TREE_STRING_POINTER (string
));
1111 MEM_VOLATILE_P (body
) = vol
;
1118 /* Parse the output constraint pointed to by *CONSTRAINT_P. It is the
1119 OPERAND_NUMth output operand, indexed from zero. There are NINPUTS
1120 inputs and NOUTPUTS outputs to this extended-asm. Upon return,
1121 *ALLOWS_MEM will be TRUE iff the constraint allows the use of a
1122 memory operand. Similarly, *ALLOWS_REG will be TRUE iff the
1123 constraint allows the use of a register operand. And, *IS_INOUT
1124 will be true if the operand is read-write, i.e., if it is used as
1125 an input as well as an output. If *CONSTRAINT_P is not in
1126 canonical form, it will be made canonical. (Note that `+' will be
1127 replaced with `=' as part of this process.)
1129 Returns TRUE if all went well; FALSE if an error occurred. */
1132 parse_output_constraint (const char **constraint_p
, int operand_num
,
1133 int ninputs
, int noutputs
, bool *allows_mem
,
1134 bool *allows_reg
, bool *is_inout
)
1136 const char *constraint
= *constraint_p
;
1139 /* Assume the constraint doesn't allow the use of either a register
1141 *allows_mem
= false;
1142 *allows_reg
= false;
1144 /* Allow the `=' or `+' to not be at the beginning of the string,
1145 since it wasn't explicitly documented that way, and there is a
1146 large body of code that puts it last. Swap the character to
1147 the front, so as not to uglify any place else. */
1148 p
= strchr (constraint
, '=');
1150 p
= strchr (constraint
, '+');
1152 /* If the string doesn't contain an `=', issue an error
1156 error ("output operand constraint lacks `='");
1160 /* If the constraint begins with `+', then the operand is both read
1161 from and written to. */
1162 *is_inout
= (*p
== '+');
1164 /* Canonicalize the output constraint so that it begins with `='. */
1165 if (p
!= constraint
|| is_inout
)
1168 size_t c_len
= strlen (constraint
);
1170 if (p
!= constraint
)
1171 warning ("output constraint `%c' for operand %d is not at the beginning",
1174 /* Make a copy of the constraint. */
1175 buf
= alloca (c_len
+ 1);
1176 strcpy (buf
, constraint
);
1177 /* Swap the first character and the `=' or `+'. */
1178 buf
[p
- constraint
] = buf
[0];
1179 /* Make sure the first character is an `='. (Until we do this,
1180 it might be a `+'.) */
1182 /* Replace the constraint with the canonicalized string. */
1183 *constraint_p
= ggc_alloc_string (buf
, c_len
);
1184 constraint
= *constraint_p
;
1187 /* Loop through the constraint string. */
1188 for (p
= constraint
+ 1; *p
; p
+= CONSTRAINT_LEN (*p
, p
))
1193 error ("operand constraint contains incorrectly positioned '+' or '='");
1197 if (operand_num
+ 1 == ninputs
+ noutputs
)
1199 error ("`%%' constraint used with last operand");
1204 case 'V': case 'm': case 'o':
1208 case '?': case '!': case '*': case '&': case '#':
1209 case 'E': case 'F': case 'G': case 'H':
1210 case 's': case 'i': case 'n':
1211 case 'I': case 'J': case 'K': case 'L': case 'M':
1212 case 'N': case 'O': case 'P': case ',':
1215 case '0': case '1': case '2': case '3': case '4':
1216 case '5': case '6': case '7': case '8': case '9':
1218 error ("matching constraint not valid in output operand");
1222 /* ??? Before flow, auto inc/dec insns are not supposed to exist,
1223 excepting those that expand_call created. So match memory
1240 if (REG_CLASS_FROM_CONSTRAINT (*p
, p
) != NO_REGS
)
1242 #ifdef EXTRA_CONSTRAINT_STR
1243 else if (EXTRA_ADDRESS_CONSTRAINT (*p
, p
))
1245 else if (EXTRA_MEMORY_CONSTRAINT (*p
, p
))
1249 /* Otherwise we can't assume anything about the nature of
1250 the constraint except that it isn't purely registers.
1251 Treat it like "g" and hope for the best. */
1259 if (*is_inout
&& !*allows_reg
)
1260 warning ("read-write constraint does not allow a register");
1265 /* Similar, but for input constraints. */
1268 parse_input_constraint (const char **constraint_p
, int input_num
,
1269 int ninputs
, int noutputs
, int ninout
,
1270 const char * const * constraints
,
1271 bool *allows_mem
, bool *allows_reg
)
1273 const char *constraint
= *constraint_p
;
1274 const char *orig_constraint
= constraint
;
1275 size_t c_len
= strlen (constraint
);
1277 bool saw_match
= false;
1279 /* Assume the constraint doesn't allow the use of either
1280 a register or memory. */
1281 *allows_mem
= false;
1282 *allows_reg
= false;
1284 /* Make sure constraint has neither `=', `+', nor '&'. */
1286 for (j
= 0; j
< c_len
; j
+= CONSTRAINT_LEN (constraint
[j
], constraint
+j
))
1287 switch (constraint
[j
])
1289 case '+': case '=': case '&':
1290 if (constraint
== orig_constraint
)
1292 error ("input operand constraint contains `%c'", constraint
[j
]);
1298 if (constraint
== orig_constraint
1299 && input_num
+ 1 == ninputs
- ninout
)
1301 error ("`%%' constraint used with last operand");
1306 case 'V': case 'm': case 'o':
1311 case '?': case '!': case '*': case '#':
1312 case 'E': case 'F': case 'G': case 'H':
1313 case 's': case 'i': case 'n':
1314 case 'I': case 'J': case 'K': case 'L': case 'M':
1315 case 'N': case 'O': case 'P': case ',':
1318 /* Whether or not a numeric constraint allows a register is
1319 decided by the matching constraint, and so there is no need
1320 to do anything special with them. We must handle them in
1321 the default case, so that we don't unnecessarily force
1322 operands to memory. */
1323 case '0': case '1': case '2': case '3': case '4':
1324 case '5': case '6': case '7': case '8': case '9':
1327 unsigned long match
;
1331 match
= strtoul (constraint
+ j
, &end
, 10);
1332 if (match
>= (unsigned long) noutputs
)
1334 error ("matching constraint references invalid operand number");
1338 /* Try and find the real constraint for this dup. Only do this
1339 if the matching constraint is the only alternative. */
1341 && (j
== 0 || (j
== 1 && constraint
[0] == '%')))
1343 constraint
= constraints
[match
];
1344 *constraint_p
= constraint
;
1345 c_len
= strlen (constraint
);
1347 /* ??? At the end of the loop, we will skip the first part of
1348 the matched constraint. This assumes not only that the
1349 other constraint is an output constraint, but also that
1350 the '=' or '+' come first. */
1354 j
= end
- constraint
;
1355 /* Anticipate increment at end of loop. */
1370 if (! ISALPHA (constraint
[j
]))
1372 error ("invalid punctuation `%c' in constraint", constraint
[j
]);
1375 if (REG_CLASS_FROM_CONSTRAINT (constraint
[j
], constraint
+ j
)
1378 #ifdef EXTRA_CONSTRAINT_STR
1379 else if (EXTRA_ADDRESS_CONSTRAINT (constraint
[j
], constraint
+ j
))
1381 else if (EXTRA_MEMORY_CONSTRAINT (constraint
[j
], constraint
+ j
))
1385 /* Otherwise we can't assume anything about the nature of
1386 the constraint except that it isn't purely registers.
1387 Treat it like "g" and hope for the best. */
1395 if (saw_match
&& !*allows_reg
)
1396 warning ("matching constraint does not allow a register");
1401 /* Check for overlap between registers marked in CLOBBERED_REGS and
1402 anything inappropriate in DECL. Emit error and return TRUE for error,
1406 decl_conflicts_with_clobbers_p (tree decl
, const HARD_REG_SET clobbered_regs
)
1408 /* Conflicts between asm-declared register variables and the clobber
1409 list are not allowed. */
1410 if ((TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
)
1411 && DECL_REGISTER (decl
)
1412 && REG_P (DECL_RTL (decl
))
1413 && REGNO (DECL_RTL (decl
)) < FIRST_PSEUDO_REGISTER
)
1415 rtx reg
= DECL_RTL (decl
);
1418 for (regno
= REGNO (reg
);
1419 regno
< (REGNO (reg
)
1420 + HARD_REGNO_NREGS (REGNO (reg
), GET_MODE (reg
)));
1422 if (TEST_HARD_REG_BIT (clobbered_regs
, regno
))
1424 error ("asm-specifier for variable `%s' conflicts with asm clobber list",
1425 IDENTIFIER_POINTER (DECL_NAME (decl
)));
1427 /* Reset registerness to stop multiple errors emitted for a
1429 DECL_REGISTER (decl
) = 0;
1436 /* Generate RTL for an asm statement with arguments.
1437 STRING is the instruction template.
1438 OUTPUTS is a list of output arguments (lvalues); INPUTS a list of inputs.
1439 Each output or input has an expression in the TREE_VALUE and
1440 and a tree list in TREE_PURPOSE which in turn contains a constraint
1441 name in TREE_VALUE (or NULL_TREE) and a constraint string
1443 CLOBBERS is a list of STRING_CST nodes each naming a hard register
1444 that is clobbered by this insn.
1446 Not all kinds of lvalue that may appear in OUTPUTS can be stored directly.
1447 Some elements of OUTPUTS may be replaced with trees representing temporary
1448 values. The caller should copy those temporary values to the originally
1451 VOL nonzero means the insn is volatile; don't optimize it. */
1454 expand_asm_operands (tree string
, tree outputs
, tree inputs
,
1455 tree clobbers
, int vol
, location_t locus
)
1457 rtvec argvec
, constraintvec
;
1459 int ninputs
= list_length (inputs
);
1460 int noutputs
= list_length (outputs
);
1463 HARD_REG_SET clobbered_regs
;
1464 int clobber_conflict_found
= 0;
1468 /* Vector of RTX's of evaluated output operands. */
1469 rtx
*output_rtx
= alloca (noutputs
* sizeof (rtx
));
1470 int *inout_opnum
= alloca (noutputs
* sizeof (int));
1471 rtx
*real_output_rtx
= alloca (noutputs
* sizeof (rtx
));
1472 enum machine_mode
*inout_mode
1473 = alloca (noutputs
* sizeof (enum machine_mode
));
1474 const char **constraints
1475 = alloca ((noutputs
+ ninputs
) * sizeof (const char *));
1476 int old_generating_concat_p
= generating_concat_p
;
1478 /* An ASM with no outputs needs to be treated as volatile, for now. */
1482 if (! check_operand_nalternatives (outputs
, inputs
))
1485 string
= resolve_asm_operand_names (string
, outputs
, inputs
);
1487 /* Collect constraints. */
1489 for (t
= outputs
; t
; t
= TREE_CHAIN (t
), i
++)
1490 constraints
[i
] = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1491 for (t
= inputs
; t
; t
= TREE_CHAIN (t
), i
++)
1492 constraints
[i
] = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1494 #ifdef MD_ASM_CLOBBERS
1495 /* Sometimes we wish to automatically clobber registers across an asm.
1496 Case in point is when the i386 backend moved from cc0 to a hard reg --
1497 maintaining source-level compatibility means automatically clobbering
1498 the flags register. */
1499 MD_ASM_CLOBBERS (clobbers
);
1502 /* Count the number of meaningful clobbered registers, ignoring what
1503 we would ignore later. */
1505 CLEAR_HARD_REG_SET (clobbered_regs
);
1506 for (tail
= clobbers
; tail
; tail
= TREE_CHAIN (tail
))
1508 const char *regname
= TREE_STRING_POINTER (TREE_VALUE (tail
));
1510 i
= decode_reg_name (regname
);
1511 if (i
>= 0 || i
== -4)
1514 error ("unknown register name `%s' in `asm'", regname
);
1516 /* Mark clobbered registers. */
1519 /* Clobbering the PIC register is an error */
1520 if (i
== (int) PIC_OFFSET_TABLE_REGNUM
)
1522 error ("PIC register `%s' clobbered in `asm'", regname
);
1526 SET_HARD_REG_BIT (clobbered_regs
, i
);
1532 /* First pass over inputs and outputs checks validity and sets
1533 mark_addressable if needed. */
1536 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
1538 tree val
= TREE_VALUE (tail
);
1539 tree type
= TREE_TYPE (val
);
1540 const char *constraint
;
1545 /* If there's an erroneous arg, emit no insn. */
1546 if (type
== error_mark_node
)
1549 /* Try to parse the output constraint. If that fails, there's
1550 no point in going further. */
1551 constraint
= constraints
[i
];
1552 if (!parse_output_constraint (&constraint
, i
, ninputs
, noutputs
,
1553 &allows_mem
, &allows_reg
, &is_inout
))
1560 && GET_CODE (DECL_RTL (val
)) == REG
1561 && GET_MODE (DECL_RTL (val
)) != TYPE_MODE (type
))))
1562 (*lang_hooks
.mark_addressable
) (val
);
1569 if (ninputs
+ noutputs
> MAX_RECOG_OPERANDS
)
1571 error ("more than %d operands in `asm'", MAX_RECOG_OPERANDS
);
1575 for (i
= 0, tail
= inputs
; tail
; i
++, tail
= TREE_CHAIN (tail
))
1577 bool allows_reg
, allows_mem
;
1578 const char *constraint
;
1580 /* If there's an erroneous arg, emit no insn, because the ASM_INPUT
1581 would get VOIDmode and that could cause a crash in reload. */
1582 if (TREE_TYPE (TREE_VALUE (tail
)) == error_mark_node
)
1585 constraint
= constraints
[i
+ noutputs
];
1586 if (! parse_input_constraint (&constraint
, i
, ninputs
, noutputs
, ninout
,
1587 constraints
, &allows_mem
, &allows_reg
))
1590 if (! allows_reg
&& allows_mem
)
1591 (*lang_hooks
.mark_addressable
) (TREE_VALUE (tail
));
1594 /* Second pass evaluates arguments. */
1597 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
1599 tree val
= TREE_VALUE (tail
);
1600 tree type
= TREE_TYPE (val
);
1606 if (!parse_output_constraint (&constraints
[i
], i
, ninputs
,
1607 noutputs
, &allows_mem
, &allows_reg
,
1611 /* If an output operand is not a decl or indirect ref and our constraint
1612 allows a register, make a temporary to act as an intermediate.
1613 Make the asm insn write into that, then our caller will copy it to
1614 the real output operand. Likewise for promoted variables. */
1616 generating_concat_p
= 0;
1618 real_output_rtx
[i
] = NULL_RTX
;
1619 if ((TREE_CODE (val
) == INDIRECT_REF
1622 && (allows_mem
|| GET_CODE (DECL_RTL (val
)) == REG
)
1623 && ! (GET_CODE (DECL_RTL (val
)) == REG
1624 && GET_MODE (DECL_RTL (val
)) != TYPE_MODE (type
)))
1628 op
= expand_expr (val
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
1629 if (GET_CODE (op
) == MEM
)
1630 op
= validize_mem (op
);
1632 if (! allows_reg
&& GET_CODE (op
) != MEM
)
1633 error ("output number %d not directly addressable", i
);
1634 if ((! allows_mem
&& GET_CODE (op
) == MEM
)
1635 || GET_CODE (op
) == CONCAT
)
1637 real_output_rtx
[i
] = protect_from_queue (op
, 1);
1638 op
= gen_reg_rtx (GET_MODE (op
));
1640 emit_move_insn (op
, real_output_rtx
[i
]);
1645 op
= assign_temp (type
, 0, 0, 1);
1646 op
= validize_mem (op
);
1647 TREE_VALUE (tail
) = make_tree (type
, op
);
1651 generating_concat_p
= old_generating_concat_p
;
1655 inout_mode
[ninout
] = TYPE_MODE (type
);
1656 inout_opnum
[ninout
++] = i
;
1659 if (decl_conflicts_with_clobbers_p (val
, clobbered_regs
))
1660 clobber_conflict_found
= 1;
1663 /* Make vectors for the expression-rtx, constraint strings,
1664 and named operands. */
1666 argvec
= rtvec_alloc (ninputs
);
1667 constraintvec
= rtvec_alloc (ninputs
);
1669 body
= gen_rtx_ASM_OPERANDS ((noutputs
== 0 ? VOIDmode
1670 : GET_MODE (output_rtx
[0])),
1671 TREE_STRING_POINTER (string
),
1672 empty_string
, 0, argvec
, constraintvec
,
1673 locus
.file
, locus
.line
);
1675 MEM_VOLATILE_P (body
) = vol
;
1677 /* Eval the inputs and put them into ARGVEC.
1678 Put their constraints into ASM_INPUTs and store in CONSTRAINTS. */
1680 for (i
= 0, tail
= inputs
; tail
; tail
= TREE_CHAIN (tail
), ++i
)
1682 bool allows_reg
, allows_mem
;
1683 const char *constraint
;
1687 constraint
= constraints
[i
+ noutputs
];
1688 if (! parse_input_constraint (&constraint
, i
, ninputs
, noutputs
, ninout
,
1689 constraints
, &allows_mem
, &allows_reg
))
1692 generating_concat_p
= 0;
1694 val
= TREE_VALUE (tail
);
1695 type
= TREE_TYPE (val
);
1696 op
= expand_expr (val
, NULL_RTX
, VOIDmode
,
1697 (allows_mem
&& !allows_reg
1698 ? EXPAND_MEMORY
: EXPAND_NORMAL
));
1700 /* Never pass a CONCAT to an ASM. */
1701 if (GET_CODE (op
) == CONCAT
)
1702 op
= force_reg (GET_MODE (op
), op
);
1703 else if (GET_CODE (op
) == MEM
)
1704 op
= validize_mem (op
);
1706 if (asm_operand_ok (op
, constraint
) <= 0)
1709 op
= force_reg (TYPE_MODE (type
), op
);
1710 else if (!allows_mem
)
1711 warning ("asm operand %d probably doesn't match constraints",
1713 else if (GET_CODE (op
) == MEM
)
1715 /* We won't recognize either volatile memory or memory
1716 with a queued address as available a memory_operand
1717 at this point. Ignore it: clearly this *is* a memory. */
1721 warning ("use of memory input without lvalue in "
1722 "asm operand %d is deprecated", i
+ noutputs
);
1724 if (CONSTANT_P (op
))
1726 rtx mem
= force_const_mem (TYPE_MODE (type
), op
);
1728 op
= validize_mem (mem
);
1730 op
= force_reg (TYPE_MODE (type
), op
);
1732 if (GET_CODE (op
) == REG
1733 || GET_CODE (op
) == SUBREG
1734 || GET_CODE (op
) == ADDRESSOF
1735 || GET_CODE (op
) == CONCAT
)
1737 tree qual_type
= build_qualified_type (type
,
1739 | TYPE_QUAL_CONST
));
1740 rtx memloc
= assign_temp (qual_type
, 1, 1, 1);
1741 memloc
= validize_mem (memloc
);
1742 emit_move_insn (memloc
, op
);
1748 generating_concat_p
= old_generating_concat_p
;
1749 ASM_OPERANDS_INPUT (body
, i
) = op
;
1751 ASM_OPERANDS_INPUT_CONSTRAINT_EXP (body
, i
)
1752 = gen_rtx_ASM_INPUT (TYPE_MODE (type
), constraints
[i
+ noutputs
]);
1754 if (decl_conflicts_with_clobbers_p (val
, clobbered_regs
))
1755 clobber_conflict_found
= 1;
1758 /* Protect all the operands from the queue now that they have all been
1761 generating_concat_p
= 0;
1763 for (i
= 0; i
< ninputs
- ninout
; i
++)
1764 ASM_OPERANDS_INPUT (body
, i
)
1765 = protect_from_queue (ASM_OPERANDS_INPUT (body
, i
), 0);
1767 for (i
= 0; i
< noutputs
; i
++)
1768 output_rtx
[i
] = protect_from_queue (output_rtx
[i
], 1);
1770 /* For in-out operands, copy output rtx to input rtx. */
1771 for (i
= 0; i
< ninout
; i
++)
1773 int j
= inout_opnum
[i
];
1776 ASM_OPERANDS_INPUT (body
, ninputs
- ninout
+ i
)
1779 sprintf (buffer
, "%d", j
);
1780 ASM_OPERANDS_INPUT_CONSTRAINT_EXP (body
, ninputs
- ninout
+ i
)
1781 = gen_rtx_ASM_INPUT (inout_mode
[i
], ggc_strdup (buffer
));
1784 generating_concat_p
= old_generating_concat_p
;
1786 /* Now, for each output, construct an rtx
1787 (set OUTPUT (asm_operands INSN OUTPUTCONSTRAINT OUTPUTNUMBER
1788 ARGVEC CONSTRAINTS OPNAMES))
1789 If there is more than one, put them inside a PARALLEL. */
1791 if (noutputs
== 1 && nclobbers
== 0)
1793 ASM_OPERANDS_OUTPUT_CONSTRAINT (body
) = constraints
[0];
1794 emit_insn (gen_rtx_SET (VOIDmode
, output_rtx
[0], body
));
1797 else if (noutputs
== 0 && nclobbers
== 0)
1799 /* No output operands: put in a raw ASM_OPERANDS rtx. */
1811 body
= gen_rtx_PARALLEL (VOIDmode
, rtvec_alloc (num
+ nclobbers
));
1813 /* For each output operand, store a SET. */
1814 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
1816 XVECEXP (body
, 0, i
)
1817 = gen_rtx_SET (VOIDmode
,
1819 gen_rtx_ASM_OPERANDS
1820 (GET_MODE (output_rtx
[i
]),
1821 TREE_STRING_POINTER (string
),
1822 constraints
[i
], i
, argvec
, constraintvec
,
1823 locus
.file
, locus
.line
));
1825 MEM_VOLATILE_P (SET_SRC (XVECEXP (body
, 0, i
))) = vol
;
1828 /* If there are no outputs (but there are some clobbers)
1829 store the bare ASM_OPERANDS into the PARALLEL. */
1832 XVECEXP (body
, 0, i
++) = obody
;
1834 /* Store (clobber REG) for each clobbered register specified. */
1836 for (tail
= clobbers
; tail
; tail
= TREE_CHAIN (tail
))
1838 const char *regname
= TREE_STRING_POINTER (TREE_VALUE (tail
));
1839 int j
= decode_reg_name (regname
);
1844 if (j
== -3) /* `cc', which is not a register */
1847 if (j
== -4) /* `memory', don't cache memory across asm */
1849 XVECEXP (body
, 0, i
++)
1850 = gen_rtx_CLOBBER (VOIDmode
,
1853 gen_rtx_SCRATCH (VOIDmode
)));
1857 /* Ignore unknown register, error already signaled. */
1861 /* Use QImode since that's guaranteed to clobber just one reg. */
1862 clobbered_reg
= gen_rtx_REG (QImode
, j
);
1864 /* Do sanity check for overlap between clobbers and respectively
1865 input and outputs that hasn't been handled. Such overlap
1866 should have been detected and reported above. */
1867 if (!clobber_conflict_found
)
1871 /* We test the old body (obody) contents to avoid tripping
1872 over the under-construction body. */
1873 for (opno
= 0; opno
< noutputs
; opno
++)
1874 if (reg_overlap_mentioned_p (clobbered_reg
, output_rtx
[opno
]))
1875 internal_error ("asm clobber conflict with output operand");
1877 for (opno
= 0; opno
< ninputs
- ninout
; opno
++)
1878 if (reg_overlap_mentioned_p (clobbered_reg
,
1879 ASM_OPERANDS_INPUT (obody
, opno
)))
1880 internal_error ("asm clobber conflict with input operand");
1883 XVECEXP (body
, 0, i
++)
1884 = gen_rtx_CLOBBER (VOIDmode
, clobbered_reg
);
1890 /* For any outputs that needed reloading into registers, spill them
1891 back to where they belong. */
1892 for (i
= 0; i
< noutputs
; ++i
)
1893 if (real_output_rtx
[i
])
1894 emit_move_insn (real_output_rtx
[i
], output_rtx
[i
]);
1899 /* A subroutine of expand_asm_operands. Check that all operands have
1900 the same number of alternatives. Return true if so. */
1903 check_operand_nalternatives (tree outputs
, tree inputs
)
1905 if (outputs
|| inputs
)
1907 tree tmp
= TREE_PURPOSE (outputs
? outputs
: inputs
);
1909 = n_occurrences (',', TREE_STRING_POINTER (TREE_VALUE (tmp
)));
1912 if (nalternatives
+ 1 > MAX_RECOG_ALTERNATIVES
)
1914 error ("too many alternatives in `asm'");
1921 const char *constraint
1922 = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tmp
)));
1924 if (n_occurrences (',', constraint
) != nalternatives
)
1926 error ("operand constraints for `asm' differ in number of alternatives");
1930 if (TREE_CHAIN (tmp
))
1931 tmp
= TREE_CHAIN (tmp
);
1933 tmp
= next
, next
= 0;
1940 /* A subroutine of expand_asm_operands. Check that all operand names
1941 are unique. Return true if so. We rely on the fact that these names
1942 are identifiers, and so have been canonicalized by get_identifier,
1943 so all we need are pointer comparisons. */
1946 check_unique_operand_names (tree outputs
, tree inputs
)
1950 for (i
= outputs
; i
; i
= TREE_CHAIN (i
))
1952 tree i_name
= TREE_PURPOSE (TREE_PURPOSE (i
));
1956 for (j
= TREE_CHAIN (i
); j
; j
= TREE_CHAIN (j
))
1957 if (simple_cst_equal (i_name
, TREE_PURPOSE (TREE_PURPOSE (j
))))
1961 for (i
= inputs
; i
; i
= TREE_CHAIN (i
))
1963 tree i_name
= TREE_PURPOSE (TREE_PURPOSE (i
));
1967 for (j
= TREE_CHAIN (i
); j
; j
= TREE_CHAIN (j
))
1968 if (simple_cst_equal (i_name
, TREE_PURPOSE (TREE_PURPOSE (j
))))
1970 for (j
= outputs
; j
; j
= TREE_CHAIN (j
))
1971 if (simple_cst_equal (i_name
, TREE_PURPOSE (TREE_PURPOSE (j
))))
1978 error ("duplicate asm operand name '%s'",
1979 TREE_STRING_POINTER (TREE_PURPOSE (TREE_PURPOSE (i
))));
1983 /* A subroutine of expand_asm_operands. Resolve the names of the operands
1984 in *POUTPUTS and *PINPUTS to numbers, and replace the name expansions in
1985 STRING and in the constraints to those numbers. */
1988 resolve_asm_operand_names (tree string
, tree outputs
, tree inputs
)
1995 check_unique_operand_names (outputs
, inputs
);
1997 /* Substitute [<name>] in input constraint strings. There should be no
1998 named operands in output constraints. */
1999 for (t
= inputs
; t
; t
= TREE_CHAIN (t
))
2001 c
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
2002 if (strchr (c
, '[') != NULL
)
2004 p
= buffer
= xstrdup (c
);
2005 while ((p
= strchr (p
, '[')) != NULL
)
2006 p
= resolve_operand_name_1 (p
, outputs
, inputs
);
2007 TREE_VALUE (TREE_PURPOSE (t
))
2008 = build_string (strlen (buffer
), buffer
);
2013 /* Now check for any needed substitutions in the template. */
2014 c
= TREE_STRING_POINTER (string
);
2015 while ((c
= strchr (c
, '%')) != NULL
)
2019 else if (ISALPHA (c
[1]) && c
[2] == '[')
2030 /* OK, we need to make a copy so we can perform the substitutions.
2031 Assume that we will not need extra space--we get to remove '['
2032 and ']', which means we cannot have a problem until we have more
2033 than 999 operands. */
2034 buffer
= xstrdup (TREE_STRING_POINTER (string
));
2035 p
= buffer
+ (c
- TREE_STRING_POINTER (string
));
2037 while ((p
= strchr (p
, '%')) != NULL
)
2041 else if (ISALPHA (p
[1]) && p
[2] == '[')
2049 p
= resolve_operand_name_1 (p
, outputs
, inputs
);
2052 string
= build_string (strlen (buffer
), buffer
);
2059 /* A subroutine of resolve_operand_names. P points to the '[' for a
2060 potential named operand of the form [<name>]. In place, replace
2061 the name and brackets with a number. Return a pointer to the
2062 balance of the string after substitution. */
2065 resolve_operand_name_1 (char *p
, tree outputs
, tree inputs
)
2072 /* Collect the operand name. */
2073 q
= strchr (p
, ']');
2076 error ("missing close brace for named operand");
2077 return strchr (p
, '\0');
2081 /* Resolve the name to a number. */
2082 for (op
= 0, t
= outputs
; t
; t
= TREE_CHAIN (t
), op
++)
2084 tree name
= TREE_PURPOSE (TREE_PURPOSE (t
));
2087 const char *c
= TREE_STRING_POINTER (name
);
2088 if (strncmp (c
, p
+ 1, len
) == 0 && c
[len
] == '\0')
2092 for (t
= inputs
; t
; t
= TREE_CHAIN (t
), op
++)
2094 tree name
= TREE_PURPOSE (TREE_PURPOSE (t
));
2097 const char *c
= TREE_STRING_POINTER (name
);
2098 if (strncmp (c
, p
+ 1, len
) == 0 && c
[len
] == '\0')
2104 error ("undefined named operand '%s'", p
+ 1);
2108 /* Replace the name with the number. Unfortunately, not all libraries
2109 get the return value of sprintf correct, so search for the end of the
2110 generated string by hand. */
2111 sprintf (p
, "%d", op
);
2112 p
= strchr (p
, '\0');
2114 /* Verify the no extra buffer space assumption. */
2118 /* Shift the rest of the buffer down to fill the gap. */
2119 memmove (p
, q
+ 1, strlen (q
+ 1) + 1);
2124 /* Generate RTL to evaluate the expression EXP
2125 and remember it in case this is the VALUE in a ({... VALUE; }) constr.
2126 Provided just for backward-compatibility. expand_expr_stmt_value()
2127 should be used for new code. */
2130 expand_expr_stmt (tree exp
)
2132 expand_expr_stmt_value (exp
, -1, 1);
2135 /* Generate RTL to evaluate the expression EXP. WANT_VALUE tells
2136 whether to (1) save the value of the expression, (0) discard it or
2137 (-1) use expr_stmts_for_value to tell. The use of -1 is
2138 deprecated, and retained only for backward compatibility. */
2141 expand_expr_stmt_value (tree exp
, int want_value
, int maybe_last
)
2147 if (want_value
== -1)
2148 want_value
= expr_stmts_for_value
!= 0;
2150 /* If -Wextra, warn about statements with no side effects,
2151 except for an explicit cast to void (e.g. for assert()), and
2152 except for last statement in ({...}) where they may be useful. */
2154 && (expr_stmts_for_value
== 0 || ! maybe_last
)
2155 && exp
!= error_mark_node
2156 && warn_unused_value
)
2158 if (TREE_SIDE_EFFECTS (exp
))
2159 warn_if_unused_value (exp
);
2160 else if (!VOID_TYPE_P (TREE_TYPE (exp
)))
2161 warning ("%Hstatement with no effect", &emit_locus
);
2164 /* If EXP is of function type and we are expanding statements for
2165 value, convert it to pointer-to-function. */
2166 if (want_value
&& TREE_CODE (TREE_TYPE (exp
)) == FUNCTION_TYPE
)
2167 exp
= build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (exp
)), exp
);
2169 /* The call to `expand_expr' could cause last_expr_type and
2170 last_expr_value to get reset. Therefore, we set last_expr_value
2171 and last_expr_type *after* calling expand_expr. */
2172 value
= expand_expr_real (exp
, want_value
? NULL_RTX
: const0_rtx
,
2173 VOIDmode
, 0, &alt_rtl
);
2174 type
= TREE_TYPE (exp
);
2176 /* If all we do is reference a volatile value in memory,
2177 copy it to a register to be sure it is actually touched. */
2178 if (value
&& GET_CODE (value
) == MEM
&& TREE_THIS_VOLATILE (exp
))
2180 if (TYPE_MODE (type
) == VOIDmode
)
2182 else if (TYPE_MODE (type
) != BLKmode
)
2183 value
= copy_to_reg (value
);
2186 rtx lab
= gen_label_rtx ();
2188 /* Compare the value with itself to reference it. */
2189 emit_cmp_and_jump_insns (value
, value
, EQ
,
2190 expand_expr (TYPE_SIZE (type
),
2191 NULL_RTX
, VOIDmode
, 0),
2197 /* If this expression is part of a ({...}) and is in memory, we may have
2198 to preserve temporaries. */
2199 preserve_temp_slots (value
);
2201 /* Free any temporaries used to evaluate this expression. Any temporary
2202 used as a result of this expression will already have been preserved
2208 last_expr_value
= value
;
2209 last_expr_alt_rtl
= alt_rtl
;
2210 last_expr_type
= type
;
2216 /* Warn if EXP contains any computations whose results are not used.
2217 Return 1 if a warning is printed; 0 otherwise. */
2220 warn_if_unused_value (tree exp
)
2222 if (TREE_USED (exp
))
2225 /* Don't warn about void constructs. This includes casting to void,
2226 void function calls, and statement expressions with a final cast
2228 if (VOID_TYPE_P (TREE_TYPE (exp
)))
2231 switch (TREE_CODE (exp
))
2233 case PREINCREMENT_EXPR
:
2234 case POSTINCREMENT_EXPR
:
2235 case PREDECREMENT_EXPR
:
2236 case POSTDECREMENT_EXPR
:
2242 case TRY_CATCH_EXPR
:
2243 case WITH_CLEANUP_EXPR
:
2248 /* For a binding, warn if no side effect within it. */
2249 return warn_if_unused_value (TREE_OPERAND (exp
, 1));
2252 return warn_if_unused_value (TREE_OPERAND (exp
, 1));
2254 case TRUTH_ORIF_EXPR
:
2255 case TRUTH_ANDIF_EXPR
:
2256 /* In && or ||, warn if 2nd operand has no side effect. */
2257 return warn_if_unused_value (TREE_OPERAND (exp
, 1));
2260 if (TREE_NO_UNUSED_WARNING (exp
))
2262 if (warn_if_unused_value (TREE_OPERAND (exp
, 0)))
2264 /* Let people do `(foo (), 0)' without a warning. */
2265 if (TREE_CONSTANT (TREE_OPERAND (exp
, 1)))
2267 return warn_if_unused_value (TREE_OPERAND (exp
, 1));
2271 case NON_LVALUE_EXPR
:
2272 /* Don't warn about conversions not explicit in the user's program. */
2273 if (TREE_NO_UNUSED_WARNING (exp
))
2275 /* Assignment to a cast usually results in a cast of a modify.
2276 Don't complain about that. There can be an arbitrary number of
2277 casts before the modify, so we must loop until we find the first
2278 non-cast expression and then test to see if that is a modify. */
2280 tree tem
= TREE_OPERAND (exp
, 0);
2282 while (TREE_CODE (tem
) == CONVERT_EXPR
|| TREE_CODE (tem
) == NOP_EXPR
)
2283 tem
= TREE_OPERAND (tem
, 0);
2285 if (TREE_CODE (tem
) == MODIFY_EXPR
|| TREE_CODE (tem
) == INIT_EXPR
2286 || TREE_CODE (tem
) == CALL_EXPR
)
2292 /* Don't warn about automatic dereferencing of references, since
2293 the user cannot control it. */
2294 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == REFERENCE_TYPE
)
2295 return warn_if_unused_value (TREE_OPERAND (exp
, 0));
2299 /* Referencing a volatile value is a side effect, so don't warn. */
2301 || TREE_CODE_CLASS (TREE_CODE (exp
)) == 'r')
2302 && TREE_THIS_VOLATILE (exp
))
2305 /* If this is an expression which has no operands, there is no value
2306 to be unused. There are no such language-independent codes,
2307 but front ends may define such. */
2308 if (TREE_CODE_CLASS (TREE_CODE (exp
)) == 'e'
2309 && TREE_CODE_LENGTH (TREE_CODE (exp
)) == 0)
2313 /* If this is an expression with side effects, don't warn. */
2314 if (TREE_SIDE_EFFECTS (exp
))
2317 warning ("%Hvalue computed is not used", &emit_locus
);
2322 /* Clear out the memory of the last expression evaluated. */
2325 clear_last_expr (void)
2327 last_expr_type
= NULL_TREE
;
2328 last_expr_value
= NULL_RTX
;
2329 last_expr_alt_rtl
= NULL_RTX
;
2332 /* Begin a statement-expression, i.e., a series of statements which
2333 may return a value. Return the RTL_EXPR for this statement expr.
2334 The caller must save that value and pass it to
2335 expand_end_stmt_expr. If HAS_SCOPE is nonzero, temporaries created
2336 in the statement-expression are deallocated at the end of the
2340 expand_start_stmt_expr (int has_scope
)
2344 /* Make the RTL_EXPR node temporary, not momentary,
2345 so that rtl_expr_chain doesn't become garbage. */
2346 t
= make_node (RTL_EXPR
);
2347 do_pending_stack_adjust ();
2349 start_sequence_for_rtl_expr (t
);
2353 expr_stmts_for_value
++;
2357 /* Restore the previous state at the end of a statement that returns a value.
2358 Returns a tree node representing the statement's value and the
2359 insns to compute the value.
2361 The nodes of that expression have been freed by now, so we cannot use them.
2362 But we don't want to do that anyway; the expression has already been
2363 evaluated and now we just want to use the value. So generate a RTL_EXPR
2364 with the proper type and RTL value.
2366 If the last substatement was not an expression,
2367 return something with type `void'. */
2370 expand_end_stmt_expr (tree t
)
2374 if (! last_expr_value
|| ! last_expr_type
)
2376 last_expr_value
= const0_rtx
;
2377 last_expr_alt_rtl
= NULL_RTX
;
2378 last_expr_type
= void_type_node
;
2380 else if (GET_CODE (last_expr_value
) != REG
&& ! CONSTANT_P (last_expr_value
))
2381 /* Remove any possible QUEUED. */
2382 last_expr_value
= protect_from_queue (last_expr_value
, 0);
2386 TREE_TYPE (t
) = last_expr_type
;
2387 RTL_EXPR_RTL (t
) = last_expr_value
;
2388 RTL_EXPR_ALT_RTL (t
) = last_expr_alt_rtl
;
2389 RTL_EXPR_SEQUENCE (t
) = get_insns ();
2391 rtl_expr_chain
= tree_cons (NULL_TREE
, t
, rtl_expr_chain
);
2395 /* Don't consider deleting this expr or containing exprs at tree level. */
2396 TREE_SIDE_EFFECTS (t
) = 1;
2397 /* Propagate volatility of the actual RTL expr. */
2398 TREE_THIS_VOLATILE (t
) = volatile_refs_p (last_expr_value
);
2401 expr_stmts_for_value
--;
2406 /* Generate RTL for the start of an if-then. COND is the expression
2407 whose truth should be tested.
2409 If EXITFLAG is nonzero, this conditional is visible to
2410 `exit_something'. */
2413 expand_start_cond (tree cond
, int exitflag
)
2415 struct nesting
*thiscond
= ALLOC_NESTING ();
2417 /* Make an entry on cond_stack for the cond we are entering. */
2419 thiscond
->desc
= COND_NESTING
;
2420 thiscond
->next
= cond_stack
;
2421 thiscond
->all
= nesting_stack
;
2422 thiscond
->depth
= ++nesting_depth
;
2423 thiscond
->data
.cond
.next_label
= gen_label_rtx ();
2424 /* Before we encounter an `else', we don't need a separate exit label
2425 unless there are supposed to be exit statements
2426 to exit this conditional. */
2427 thiscond
->exit_label
= exitflag
? gen_label_rtx () : 0;
2428 thiscond
->data
.cond
.endif_label
= thiscond
->exit_label
;
2429 cond_stack
= thiscond
;
2430 nesting_stack
= thiscond
;
2432 do_jump (cond
, thiscond
->data
.cond
.next_label
, NULL_RTX
);
2435 /* Generate RTL between then-clause and the elseif-clause
2436 of an if-then-elseif-.... */
2439 expand_start_elseif (tree cond
)
2441 if (cond_stack
->data
.cond
.endif_label
== 0)
2442 cond_stack
->data
.cond
.endif_label
= gen_label_rtx ();
2443 emit_jump (cond_stack
->data
.cond
.endif_label
);
2444 emit_label (cond_stack
->data
.cond
.next_label
);
2445 cond_stack
->data
.cond
.next_label
= gen_label_rtx ();
2446 do_jump (cond
, cond_stack
->data
.cond
.next_label
, NULL_RTX
);
2449 /* Generate RTL between the then-clause and the else-clause
2450 of an if-then-else. */
2453 expand_start_else (void)
2455 if (cond_stack
->data
.cond
.endif_label
== 0)
2456 cond_stack
->data
.cond
.endif_label
= gen_label_rtx ();
2458 emit_jump (cond_stack
->data
.cond
.endif_label
);
2459 emit_label (cond_stack
->data
.cond
.next_label
);
2460 cond_stack
->data
.cond
.next_label
= 0; /* No more _else or _elseif calls. */
2463 /* After calling expand_start_else, turn this "else" into an "else if"
2464 by providing another condition. */
2467 expand_elseif (tree cond
)
2469 cond_stack
->data
.cond
.next_label
= gen_label_rtx ();
2470 do_jump (cond
, cond_stack
->data
.cond
.next_label
, NULL_RTX
);
2473 /* Generate RTL for the end of an if-then.
2474 Pop the record for it off of cond_stack. */
2477 expand_end_cond (void)
2479 struct nesting
*thiscond
= cond_stack
;
2481 do_pending_stack_adjust ();
2482 if (thiscond
->data
.cond
.next_label
)
2483 emit_label (thiscond
->data
.cond
.next_label
);
2484 if (thiscond
->data
.cond
.endif_label
)
2485 emit_label (thiscond
->data
.cond
.endif_label
);
2487 POPSTACK (cond_stack
);
2491 /* Generate RTL for the start of a loop. EXIT_FLAG is nonzero if this
2492 loop should be exited by `exit_something'. This is a loop for which
2493 `expand_continue' will jump to the top of the loop.
2495 Make an entry on loop_stack to record the labels associated with
2499 expand_start_loop (int exit_flag
)
2501 struct nesting
*thisloop
= ALLOC_NESTING ();
2503 /* Make an entry on loop_stack for the loop we are entering. */
2505 thisloop
->desc
= LOOP_NESTING
;
2506 thisloop
->next
= loop_stack
;
2507 thisloop
->all
= nesting_stack
;
2508 thisloop
->depth
= ++nesting_depth
;
2509 thisloop
->data
.loop
.start_label
= gen_label_rtx ();
2510 thisloop
->data
.loop
.end_label
= gen_label_rtx ();
2511 thisloop
->data
.loop
.continue_label
= thisloop
->data
.loop
.start_label
;
2512 thisloop
->exit_label
= exit_flag
? thisloop
->data
.loop
.end_label
: 0;
2513 loop_stack
= thisloop
;
2514 nesting_stack
= thisloop
;
2516 do_pending_stack_adjust ();
2518 emit_note (NOTE_INSN_LOOP_BEG
);
2519 emit_label (thisloop
->data
.loop
.start_label
);
2524 /* Like expand_start_loop but for a loop where the continuation point
2525 (for expand_continue_loop) will be specified explicitly. */
2528 expand_start_loop_continue_elsewhere (int exit_flag
)
2530 struct nesting
*thisloop
= expand_start_loop (exit_flag
);
2531 loop_stack
->data
.loop
.continue_label
= gen_label_rtx ();
2535 /* Begin a null, aka do { } while (0) "loop". But since the contents
2536 of said loop can still contain a break, we must frob the loop nest. */
2539 expand_start_null_loop (void)
2541 struct nesting
*thisloop
= ALLOC_NESTING ();
2543 /* Make an entry on loop_stack for the loop we are entering. */
2545 thisloop
->desc
= LOOP_NESTING
;
2546 thisloop
->next
= loop_stack
;
2547 thisloop
->all
= nesting_stack
;
2548 thisloop
->depth
= ++nesting_depth
;
2549 thisloop
->data
.loop
.start_label
= emit_note (NOTE_INSN_DELETED
);
2550 thisloop
->data
.loop
.end_label
= gen_label_rtx ();
2551 thisloop
->data
.loop
.continue_label
= thisloop
->data
.loop
.end_label
;
2552 thisloop
->exit_label
= thisloop
->data
.loop
.end_label
;
2553 loop_stack
= thisloop
;
2554 nesting_stack
= thisloop
;
2559 /* Specify the continuation point for a loop started with
2560 expand_start_loop_continue_elsewhere.
2561 Use this at the point in the code to which a continue statement
2565 expand_loop_continue_here (void)
2567 do_pending_stack_adjust ();
2568 emit_note (NOTE_INSN_LOOP_CONT
);
2569 emit_label (loop_stack
->data
.loop
.continue_label
);
2572 /* Finish a loop. Generate a jump back to the top and the loop-exit label.
2573 Pop the block off of loop_stack. */
2576 expand_end_loop (void)
2578 rtx start_label
= loop_stack
->data
.loop
.start_label
;
2580 int eh_regions
, debug_blocks
;
2583 /* Mark the continue-point at the top of the loop if none elsewhere. */
2584 if (start_label
== loop_stack
->data
.loop
.continue_label
)
2585 emit_note_before (NOTE_INSN_LOOP_CONT
, start_label
);
2587 do_pending_stack_adjust ();
2589 /* If the loop starts with a loop exit, roll that to the end where
2590 it will optimize together with the jump back.
2592 If the loop presently looks like this (in pseudo-C):
2596 if (test) goto end_label;
2602 transform it to look like:
2609 if (test) goto end_label;
2613 We rely on the presence of NOTE_INSN_LOOP_END_TOP_COND to mark
2614 the end of the entry conditional. Without this, our lexical scan
2615 can't tell the difference between an entry conditional and a
2616 body conditional that exits the loop. Mistaking the two means
2617 that we can misplace the NOTE_INSN_LOOP_CONT note, which can
2618 screw up loop unrolling.
2620 Things will be oh so much better when loop optimization is done
2621 off of a proper control flow graph... */
2623 /* Scan insns from the top of the loop looking for the END_TOP_COND note. */
2626 eh_regions
= debug_blocks
= 0;
2627 for (etc_note
= start_label
; etc_note
; etc_note
= NEXT_INSN (etc_note
))
2628 if (GET_CODE (etc_note
) == NOTE
)
2630 if (NOTE_LINE_NUMBER (etc_note
) == NOTE_INSN_LOOP_END_TOP_COND
)
2633 /* We must not walk into a nested loop. */
2634 else if (NOTE_LINE_NUMBER (etc_note
) == NOTE_INSN_LOOP_BEG
)
2636 etc_note
= NULL_RTX
;
2640 /* At the same time, scan for EH region notes, as we don't want
2641 to scrog region nesting. This shouldn't happen, but... */
2642 else if (NOTE_LINE_NUMBER (etc_note
) == NOTE_INSN_EH_REGION_BEG
)
2644 else if (NOTE_LINE_NUMBER (etc_note
) == NOTE_INSN_EH_REGION_END
)
2646 if (--eh_regions
< 0)
2647 /* We've come to the end of an EH region, but never saw the
2648 beginning of that region. That means that an EH region
2649 begins before the top of the loop, and ends in the middle
2650 of it. The existence of such a situation violates a basic
2651 assumption in this code, since that would imply that even
2652 when EH_REGIONS is zero, we might move code out of an
2653 exception region. */
2657 /* Likewise for debug scopes. In this case we'll either (1) move
2658 all of the notes if they are properly nested or (2) leave the
2659 notes alone and only rotate the loop at high optimization
2660 levels when we expect to scrog debug info. */
2661 else if (NOTE_LINE_NUMBER (etc_note
) == NOTE_INSN_BLOCK_BEG
)
2663 else if (NOTE_LINE_NUMBER (etc_note
) == NOTE_INSN_BLOCK_END
)
2666 else if (INSN_P (etc_note
))
2673 && (debug_blocks
== 0 || optimize
>= 2)
2674 && NEXT_INSN (etc_note
) != NULL_RTX
2675 && ! any_condjump_p (get_last_insn ()))
2677 /* We found one. Move everything from START to ETC to the end
2678 of the loop, and add a jump from the top of the loop. */
2679 rtx top_label
= gen_label_rtx ();
2680 rtx start_move
= start_label
;
2682 /* If the start label is preceded by a NOTE_INSN_LOOP_CONT note,
2683 then we want to move this note also. */
2684 if (GET_CODE (PREV_INSN (start_move
)) == NOTE
2685 && NOTE_LINE_NUMBER (PREV_INSN (start_move
)) == NOTE_INSN_LOOP_CONT
)
2686 start_move
= PREV_INSN (start_move
);
2688 emit_label_before (top_label
, start_move
);
2690 /* Actually move the insns. If the debug scopes are nested, we
2691 can move everything at once. Otherwise we have to move them
2692 one by one and squeeze out the block notes. */
2693 if (debug_blocks
== 0)
2694 reorder_insns (start_move
, etc_note
, get_last_insn ());
2697 rtx insn
, next_insn
;
2698 for (insn
= start_move
; insn
; insn
= next_insn
)
2700 /* Figure out which insn comes after this one. We have
2701 to do this before we move INSN. */
2702 next_insn
= (insn
== etc_note
? NULL
: NEXT_INSN (insn
));
2704 if (GET_CODE (insn
) == NOTE
2705 && (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_BEG
2706 || NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_END
))
2709 reorder_insns (insn
, insn
, get_last_insn ());
2713 /* Add the jump from the top of the loop. */
2714 emit_jump_insn_before (gen_jump (start_label
), top_label
);
2715 emit_barrier_before (top_label
);
2716 start_label
= top_label
;
2719 emit_jump (start_label
);
2720 emit_note (NOTE_INSN_LOOP_END
);
2721 emit_label (loop_stack
->data
.loop
.end_label
);
2723 POPSTACK (loop_stack
);
2728 /* Finish a null loop, aka do { } while (0). */
2731 expand_end_null_loop (void)
2733 do_pending_stack_adjust ();
2734 emit_label (loop_stack
->data
.loop
.end_label
);
2736 POPSTACK (loop_stack
);
2741 /* Generate a jump to the current loop's continue-point.
2742 This is usually the top of the loop, but may be specified
2743 explicitly elsewhere. If not currently inside a loop,
2744 return 0 and do nothing; caller will print an error message. */
2747 expand_continue_loop (struct nesting
*whichloop
)
2749 /* Emit information for branch prediction. */
2752 if (flag_guess_branch_prob
)
2754 note
= emit_note (NOTE_INSN_PREDICTION
);
2755 NOTE_PREDICTION (note
) = NOTE_PREDICT (PRED_CONTINUE
, IS_TAKEN
);
2759 whichloop
= loop_stack
;
2762 expand_goto_internal (NULL_TREE
, whichloop
->data
.loop
.continue_label
,
2767 /* Generate a jump to exit the current loop. If not currently inside a loop,
2768 return 0 and do nothing; caller will print an error message. */
2771 expand_exit_loop (struct nesting
*whichloop
)
2775 whichloop
= loop_stack
;
2778 expand_goto_internal (NULL_TREE
, whichloop
->data
.loop
.end_label
, NULL_RTX
);
2782 /* Generate a conditional jump to exit the current loop if COND
2783 evaluates to zero. If not currently inside a loop,
2784 return 0 and do nothing; caller will print an error message. */
2787 expand_exit_loop_if_false (struct nesting
*whichloop
, tree cond
)
2793 whichloop
= loop_stack
;
2797 if (integer_nonzerop (cond
))
2799 if (integer_zerop (cond
))
2800 return expand_exit_loop (whichloop
);
2802 /* Check if we definitely won't need a fixup. */
2803 if (whichloop
== nesting_stack
)
2805 jumpifnot (cond
, whichloop
->data
.loop
.end_label
);
2809 /* In order to handle fixups, we actually create a conditional jump
2810 around an unconditional branch to exit the loop. If fixups are
2811 necessary, they go before the unconditional branch. */
2813 label
= gen_label_rtx ();
2814 jumpif (cond
, label
);
2815 expand_goto_internal (NULL_TREE
, whichloop
->data
.loop
.end_label
,
2822 /* Like expand_exit_loop_if_false except also emit a note marking
2823 the end of the conditional. Should only be used immediately
2824 after expand_loop_start. */
2827 expand_exit_loop_top_cond (struct nesting
*whichloop
, tree cond
)
2829 if (! expand_exit_loop_if_false (whichloop
, cond
))
2832 emit_note (NOTE_INSN_LOOP_END_TOP_COND
);
2836 /* Return nonzero if we should preserve sub-expressions as separate
2837 pseudos. We never do so if we aren't optimizing. We always do so
2838 if -fexpensive-optimizations.
2840 Otherwise, we only do so if we are in the "early" part of a loop. I.e.,
2841 the loop may still be a small one. */
2844 preserve_subexpressions_p (void)
2848 if (flag_expensive_optimizations
)
2851 if (optimize
== 0 || cfun
== 0 || cfun
->stmt
== 0 || loop_stack
== 0)
2854 insn
= get_last_insn_anywhere ();
2857 && (INSN_UID (insn
) - INSN_UID (loop_stack
->data
.loop
.start_label
)
2858 < n_non_fixed_regs
* 3));
2862 /* Generate a jump to exit the current loop, conditional, binding contour
2863 or case statement. Not all such constructs are visible to this function,
2864 only those started with EXIT_FLAG nonzero. Individual languages use
2865 the EXIT_FLAG parameter to control which kinds of constructs you can
2868 If not currently inside anything that can be exited,
2869 return 0 and do nothing; caller will print an error message. */
2872 expand_exit_something (void)
2876 for (n
= nesting_stack
; n
; n
= n
->all
)
2877 if (n
->exit_label
!= 0)
2879 expand_goto_internal (NULL_TREE
, n
->exit_label
, NULL_RTX
);
2886 /* Generate RTL to return from the current function, with no value.
2887 (That is, we do not do anything about returning any value.) */
2890 expand_null_return (void)
2894 last_insn
= get_last_insn ();
2896 /* If this function was declared to return a value, but we
2897 didn't, clobber the return registers so that they are not
2898 propagated live to the rest of the function. */
2899 clobber_return_register ();
2901 expand_null_return_1 (last_insn
);
2904 /* Generate RTL to return directly from the current function.
2905 (That is, we bypass any return value.) */
2908 expand_naked_return (void)
2910 rtx last_insn
, end_label
;
2912 last_insn
= get_last_insn ();
2913 end_label
= naked_return_label
;
2915 clear_pending_stack_adjust ();
2916 do_pending_stack_adjust ();
2920 end_label
= naked_return_label
= gen_label_rtx ();
2921 expand_goto_internal (NULL_TREE
, end_label
, last_insn
);
2924 /* Try to guess whether the value of return means error code. */
2925 static enum br_predictor
2926 return_prediction (rtx val
)
2928 /* Different heuristics for pointers and scalars. */
2929 if (POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (current_function_decl
))))
2931 /* NULL is usually not returned. */
2932 if (val
== const0_rtx
)
2933 return PRED_NULL_RETURN
;
2937 /* Negative return values are often used to indicate
2939 if (GET_CODE (val
) == CONST_INT
2940 && INTVAL (val
) < 0)
2941 return PRED_NEGATIVE_RETURN
;
2942 /* Constant return values are also usually erors,
2943 zero/one often mean booleans so exclude them from the
2945 if (CONSTANT_P (val
)
2946 && (val
!= const0_rtx
&& val
!= const1_rtx
))
2947 return PRED_CONST_RETURN
;
2949 return PRED_NO_PREDICTION
;
2953 /* If the current function returns values in the most significant part
2954 of a register, shift return value VAL appropriately. The mode of
2955 the function's return type is known not to be BLKmode. */
2958 shift_return_value (rtx val
)
2962 type
= TREE_TYPE (DECL_RESULT (current_function_decl
));
2963 if (targetm
.calls
.return_in_msb (type
))
2966 HOST_WIDE_INT shift
;
2968 target
= DECL_RTL (DECL_RESULT (current_function_decl
));
2969 shift
= (GET_MODE_BITSIZE (GET_MODE (target
))
2970 - BITS_PER_UNIT
* int_size_in_bytes (type
));
2972 val
= expand_binop (GET_MODE (target
), ashl_optab
,
2973 gen_lowpart (GET_MODE (target
), val
),
2974 GEN_INT (shift
), target
, 1, OPTAB_WIDEN
);
2980 /* Generate RTL to return from the current function, with value VAL. */
2983 expand_value_return (rtx val
)
2987 enum br_predictor pred
;
2989 if (flag_guess_branch_prob
2990 && (pred
= return_prediction (val
)) != PRED_NO_PREDICTION
)
2992 /* Emit information for branch prediction. */
2995 note
= emit_note (NOTE_INSN_PREDICTION
);
2997 NOTE_PREDICTION (note
) = NOTE_PREDICT (pred
, NOT_TAKEN
);
3001 last_insn
= get_last_insn ();
3002 return_reg
= DECL_RTL (DECL_RESULT (current_function_decl
));
3004 /* Copy the value to the return location
3005 unless it's already there. */
3007 if (return_reg
!= val
)
3009 tree type
= TREE_TYPE (DECL_RESULT (current_function_decl
));
3010 if (targetm
.calls
.promote_function_return (TREE_TYPE (current_function_decl
)))
3012 int unsignedp
= TREE_UNSIGNED (type
);
3013 enum machine_mode old_mode
3014 = DECL_MODE (DECL_RESULT (current_function_decl
));
3015 enum machine_mode mode
3016 = promote_mode (type
, old_mode
, &unsignedp
, 1);
3018 if (mode
!= old_mode
)
3019 val
= convert_modes (mode
, old_mode
, val
, unsignedp
);
3021 if (GET_CODE (return_reg
) == PARALLEL
)
3022 emit_group_load (return_reg
, val
, type
, int_size_in_bytes (type
));
3024 emit_move_insn (return_reg
, val
);
3027 expand_null_return_1 (last_insn
);
3030 /* Output a return with no value. If LAST_INSN is nonzero,
3031 pretend that the return takes place after LAST_INSN. */
3034 expand_null_return_1 (rtx last_insn
)
3036 rtx end_label
= cleanup_label
? cleanup_label
: return_label
;
3038 clear_pending_stack_adjust ();
3039 do_pending_stack_adjust ();
3043 end_label
= return_label
= gen_label_rtx ();
3044 expand_goto_internal (NULL_TREE
, end_label
, last_insn
);
3047 /* Generate RTL to evaluate the expression RETVAL and return it
3048 from the current function. */
3051 expand_return (tree retval
)
3053 /* If there are any cleanups to be performed, then they will
3054 be inserted following LAST_INSN. It is desirable
3055 that the last_insn, for such purposes, should be the
3056 last insn before computing the return value. Otherwise, cleanups
3057 which call functions can clobber the return value. */
3058 /* ??? rms: I think that is erroneous, because in C++ it would
3059 run destructors on variables that might be used in the subsequent
3060 computation of the return value. */
3066 /* If function wants no value, give it none. */
3067 if (TREE_CODE (TREE_TYPE (TREE_TYPE (current_function_decl
))) == VOID_TYPE
)
3069 expand_expr (retval
, NULL_RTX
, VOIDmode
, 0);
3071 expand_null_return ();
3075 if (retval
== error_mark_node
)
3077 /* Treat this like a return of no value from a function that
3079 expand_null_return ();
3082 else if (TREE_CODE (retval
) == RESULT_DECL
)
3083 retval_rhs
= retval
;
3084 else if ((TREE_CODE (retval
) == MODIFY_EXPR
|| TREE_CODE (retval
) == INIT_EXPR
)
3085 && TREE_CODE (TREE_OPERAND (retval
, 0)) == RESULT_DECL
)
3086 retval_rhs
= TREE_OPERAND (retval
, 1);
3087 else if (VOID_TYPE_P (TREE_TYPE (retval
)))
3088 /* Recognize tail-recursive call to void function. */
3089 retval_rhs
= retval
;
3091 retval_rhs
= NULL_TREE
;
3093 last_insn
= get_last_insn ();
3095 /* Distribute return down conditional expr if either of the sides
3096 may involve tail recursion (see test below). This enhances the number
3097 of tail recursions we see. Don't do this always since it can produce
3098 sub-optimal code in some cases and we distribute assignments into
3099 conditional expressions when it would help. */
3101 if (optimize
&& retval_rhs
!= 0
3102 && frame_offset
== 0
3103 && TREE_CODE (retval_rhs
) == COND_EXPR
3104 && (TREE_CODE (TREE_OPERAND (retval_rhs
, 1)) == CALL_EXPR
3105 || TREE_CODE (TREE_OPERAND (retval_rhs
, 2)) == CALL_EXPR
))
3107 rtx label
= gen_label_rtx ();
3110 do_jump (TREE_OPERAND (retval_rhs
, 0), label
, NULL_RTX
);
3111 start_cleanup_deferral ();
3112 expr
= build (MODIFY_EXPR
, TREE_TYPE (TREE_TYPE (current_function_decl
)),
3113 DECL_RESULT (current_function_decl
),
3114 TREE_OPERAND (retval_rhs
, 1));
3115 TREE_SIDE_EFFECTS (expr
) = 1;
3116 expand_return (expr
);
3119 expr
= build (MODIFY_EXPR
, TREE_TYPE (TREE_TYPE (current_function_decl
)),
3120 DECL_RESULT (current_function_decl
),
3121 TREE_OPERAND (retval_rhs
, 2));
3122 TREE_SIDE_EFFECTS (expr
) = 1;
3123 expand_return (expr
);
3124 end_cleanup_deferral ();
3128 result_rtl
= DECL_RTL (DECL_RESULT (current_function_decl
));
3130 /* If the result is an aggregate that is being returned in one (or more)
3131 registers, load the registers here. The compiler currently can't handle
3132 copying a BLKmode value into registers. We could put this code in a
3133 more general area (for use by everyone instead of just function
3134 call/return), but until this feature is generally usable it is kept here
3135 (and in expand_call). The value must go into a pseudo in case there
3136 are cleanups that will clobber the real return register. */
3139 && TYPE_MODE (TREE_TYPE (retval_rhs
)) == BLKmode
3140 && GET_CODE (result_rtl
) == REG
)
3143 unsigned HOST_WIDE_INT bitpos
, xbitpos
;
3144 unsigned HOST_WIDE_INT padding_correction
= 0;
3145 unsigned HOST_WIDE_INT bytes
3146 = int_size_in_bytes (TREE_TYPE (retval_rhs
));
3147 int n_regs
= (bytes
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
3148 unsigned int bitsize
3149 = MIN (TYPE_ALIGN (TREE_TYPE (retval_rhs
)), BITS_PER_WORD
);
3150 rtx
*result_pseudos
= alloca (sizeof (rtx
) * n_regs
);
3151 rtx result_reg
, src
= NULL_RTX
, dst
= NULL_RTX
;
3152 rtx result_val
= expand_expr (retval_rhs
, NULL_RTX
, VOIDmode
, 0);
3153 enum machine_mode tmpmode
, result_reg_mode
;
3157 expand_null_return ();
3161 /* If the structure doesn't take up a whole number of words, see
3162 whether the register value should be padded on the left or on
3163 the right. Set PADDING_CORRECTION to the number of padding
3164 bits needed on the left side.
3166 In most ABIs, the structure will be returned at the least end of
3167 the register, which translates to right padding on little-endian
3168 targets and left padding on big-endian targets. The opposite
3169 holds if the structure is returned at the most significant
3170 end of the register. */
3171 if (bytes
% UNITS_PER_WORD
!= 0
3172 && (targetm
.calls
.return_in_msb (TREE_TYPE (retval_rhs
))
3174 : BYTES_BIG_ENDIAN
))
3175 padding_correction
= (BITS_PER_WORD
- ((bytes
% UNITS_PER_WORD
)
3178 /* Copy the structure BITSIZE bits at a time. */
3179 for (bitpos
= 0, xbitpos
= padding_correction
;
3180 bitpos
< bytes
* BITS_PER_UNIT
;
3181 bitpos
+= bitsize
, xbitpos
+= bitsize
)
3183 /* We need a new destination pseudo each time xbitpos is
3184 on a word boundary and when xbitpos == padding_correction
3185 (the first time through). */
3186 if (xbitpos
% BITS_PER_WORD
== 0
3187 || xbitpos
== padding_correction
)
3189 /* Generate an appropriate register. */
3190 dst
= gen_reg_rtx (word_mode
);
3191 result_pseudos
[xbitpos
/ BITS_PER_WORD
] = dst
;
3193 /* Clear the destination before we move anything into it. */
3194 emit_move_insn (dst
, CONST0_RTX (GET_MODE (dst
)));
3197 /* We need a new source operand each time bitpos is on a word
3199 if (bitpos
% BITS_PER_WORD
== 0)
3200 src
= operand_subword_force (result_val
,
3201 bitpos
/ BITS_PER_WORD
,
3204 /* Use bitpos for the source extraction (left justified) and
3205 xbitpos for the destination store (right justified). */
3206 store_bit_field (dst
, bitsize
, xbitpos
% BITS_PER_WORD
, word_mode
,
3207 extract_bit_field (src
, bitsize
,
3208 bitpos
% BITS_PER_WORD
, 1,
3209 NULL_RTX
, word_mode
, word_mode
,
3214 tmpmode
= GET_MODE (result_rtl
);
3215 if (tmpmode
== BLKmode
)
3217 /* Find the smallest integer mode large enough to hold the
3218 entire structure and use that mode instead of BLKmode
3219 on the USE insn for the return register. */
3220 for (tmpmode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
3221 tmpmode
!= VOIDmode
;
3222 tmpmode
= GET_MODE_WIDER_MODE (tmpmode
))
3223 /* Have we found a large enough mode? */
3224 if (GET_MODE_SIZE (tmpmode
) >= bytes
)
3227 /* No suitable mode found. */
3228 if (tmpmode
== VOIDmode
)
3231 PUT_MODE (result_rtl
, tmpmode
);
3234 if (GET_MODE_SIZE (tmpmode
) < GET_MODE_SIZE (word_mode
))
3235 result_reg_mode
= word_mode
;
3237 result_reg_mode
= tmpmode
;
3238 result_reg
= gen_reg_rtx (result_reg_mode
);
3241 for (i
= 0; i
< n_regs
; i
++)
3242 emit_move_insn (operand_subword (result_reg
, i
, 0, result_reg_mode
),
3245 if (tmpmode
!= result_reg_mode
)
3246 result_reg
= gen_lowpart (tmpmode
, result_reg
);
3248 expand_value_return (result_reg
);
3250 else if (retval_rhs
!= 0
3251 && !VOID_TYPE_P (TREE_TYPE (retval_rhs
))
3252 && (GET_CODE (result_rtl
) == REG
3253 || (GET_CODE (result_rtl
) == PARALLEL
)))
3255 /* Calculate the return value into a temporary (usually a pseudo
3257 tree ot
= TREE_TYPE (DECL_RESULT (current_function_decl
));
3258 tree nt
= build_qualified_type (ot
, TYPE_QUALS (ot
) | TYPE_QUAL_CONST
);
3260 val
= assign_temp (nt
, 0, 0, 1);
3261 val
= expand_expr (retval_rhs
, val
, GET_MODE (val
), 0);
3262 val
= force_not_mem (val
);
3264 /* Return the calculated value, doing cleanups first. */
3265 expand_value_return (shift_return_value (val
));
3269 /* No cleanups or no hard reg used;
3270 calculate value into hard return reg. */
3271 expand_expr (retval
, const0_rtx
, VOIDmode
, 0);
3273 expand_value_return (result_rtl
);
3277 /* Attempt to optimize a potential tail recursion call into a goto.
3278 ARGUMENTS are the arguments to a CALL_EXPR; LAST_INSN indicates
3279 where to place the jump to the tail recursion label.
3281 Return TRUE if the call was optimized into a goto. */
3284 optimize_tail_recursion (tree arguments
, rtx last_insn
)
3286 /* Finish checking validity, and if valid emit code to set the
3287 argument variables for the new call. */
3288 if (tail_recursion_args (arguments
, DECL_ARGUMENTS (current_function_decl
)))
3290 if (tail_recursion_label
== 0)
3292 tail_recursion_label
= gen_label_rtx ();
3293 emit_label_after (tail_recursion_label
,
3294 tail_recursion_reentry
);
3297 expand_goto_internal (NULL_TREE
, tail_recursion_label
, last_insn
);
3304 /* Emit code to alter this function's formal parms for a tail-recursive call.
3305 ACTUALS is a list of actual parameter expressions (chain of TREE_LISTs).
3306 FORMALS is the chain of decls of formals.
3307 Return 1 if this can be done;
3308 otherwise return 0 and do not emit any code. */
3311 tail_recursion_args (tree actuals
, tree formals
)
3313 tree a
= actuals
, f
= formals
;
3317 /* Check that number and types of actuals are compatible
3318 with the formals. This is not always true in valid C code.
3319 Also check that no formal needs to be addressable
3320 and that all formals are scalars. */
3322 /* Also count the args. */
3324 for (a
= actuals
, f
= formals
, i
= 0; a
&& f
; a
= TREE_CHAIN (a
), f
= TREE_CHAIN (f
), i
++)
3326 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (a
)))
3327 != TYPE_MAIN_VARIANT (TREE_TYPE (f
)))
3329 if (GET_CODE (DECL_RTL (f
)) != REG
|| DECL_MODE (f
) == BLKmode
)
3332 if (a
!= 0 || f
!= 0)
3335 /* Compute all the actuals. */
3337 argvec
= alloca (i
* sizeof (rtx
));
3339 for (a
= actuals
, i
= 0; a
; a
= TREE_CHAIN (a
), i
++)
3340 argvec
[i
] = expand_expr (TREE_VALUE (a
), NULL_RTX
, VOIDmode
, 0);
3342 /* Find which actual values refer to current values of previous formals.
3343 Copy each of them now, before any formal is changed. */
3345 for (a
= actuals
, i
= 0; a
; a
= TREE_CHAIN (a
), i
++)
3349 for (f
= formals
, j
= 0; j
< i
; f
= TREE_CHAIN (f
), j
++)
3350 if (reg_mentioned_p (DECL_RTL (f
), argvec
[i
]))
3356 argvec
[i
] = copy_to_reg (argvec
[i
]);
3359 /* Store the values of the actuals into the formals. */
3361 for (f
= formals
, a
= actuals
, i
= 0; f
;
3362 f
= TREE_CHAIN (f
), a
= TREE_CHAIN (a
), i
++)
3364 if (GET_MODE (DECL_RTL (f
)) == GET_MODE (argvec
[i
]))
3365 emit_move_insn (DECL_RTL (f
), argvec
[i
]);
3368 rtx tmp
= argvec
[i
];
3369 int unsignedp
= TREE_UNSIGNED (TREE_TYPE (TREE_VALUE (a
)));
3370 promote_mode(TREE_TYPE (TREE_VALUE (a
)), GET_MODE (tmp
),
3372 if (DECL_MODE (f
) != GET_MODE (DECL_RTL (f
)))
3374 tmp
= gen_reg_rtx (DECL_MODE (f
));
3375 convert_move (tmp
, argvec
[i
], unsignedp
);
3377 convert_move (DECL_RTL (f
), tmp
, unsignedp
);
3385 /* Generate the RTL code for entering a binding contour.
3386 The variables are declared one by one, by calls to `expand_decl'.
3388 FLAGS is a bitwise or of the following flags:
3390 1 - Nonzero if this construct should be visible to
3393 2 - Nonzero if this contour does not require a
3394 NOTE_INSN_BLOCK_BEG note. Virtually all calls from
3395 language-independent code should set this flag because they
3396 will not create corresponding BLOCK nodes. (There should be
3397 a one-to-one correspondence between NOTE_INSN_BLOCK_BEG notes
3398 and BLOCKs.) If this flag is set, MARK_ENDS should be zero
3399 when expand_end_bindings is called.
3401 If we are creating a NOTE_INSN_BLOCK_BEG note, a BLOCK may
3402 optionally be supplied. If so, it becomes the NOTE_BLOCK for the
3406 expand_start_bindings_and_block (int flags
, tree block
)
3408 struct nesting
*thisblock
= ALLOC_NESTING ();
3410 int exit_flag
= ((flags
& 1) != 0);
3411 int block_flag
= ((flags
& 2) == 0);
3413 /* If a BLOCK is supplied, then the caller should be requesting a
3414 NOTE_INSN_BLOCK_BEG note. */
3415 if (!block_flag
&& block
)
3418 /* Create a note to mark the beginning of the block. */
3421 note
= emit_note (NOTE_INSN_BLOCK_BEG
);
3422 NOTE_BLOCK (note
) = block
;
3425 note
= emit_note (NOTE_INSN_DELETED
);
3427 /* Make an entry on block_stack for the block we are entering. */
3429 thisblock
->desc
= BLOCK_NESTING
;
3430 thisblock
->next
= block_stack
;
3431 thisblock
->all
= nesting_stack
;
3432 thisblock
->depth
= ++nesting_depth
;
3433 thisblock
->data
.block
.stack_level
= 0;
3434 thisblock
->data
.block
.cleanups
= 0;
3435 thisblock
->data
.block
.exception_region
= 0;
3436 thisblock
->data
.block
.block_target_temp_slot_level
= target_temp_slot_level
;
3438 thisblock
->data
.block
.conditional_code
= 0;
3439 thisblock
->data
.block
.last_unconditional_cleanup
= note
;
3440 /* When we insert instructions after the last unconditional cleanup,
3441 we don't adjust last_insn. That means that a later add_insn will
3442 clobber the instructions we've just added. The easiest way to
3443 fix this is to just insert another instruction here, so that the
3444 instructions inserted after the last unconditional cleanup are
3445 never the last instruction. */
3446 emit_note (NOTE_INSN_DELETED
);
3449 && !(block_stack
->data
.block
.cleanups
== NULL_TREE
3450 && block_stack
->data
.block
.outer_cleanups
== NULL_TREE
))
3451 thisblock
->data
.block
.outer_cleanups
3452 = tree_cons (NULL_TREE
, block_stack
->data
.block
.cleanups
,
3453 block_stack
->data
.block
.outer_cleanups
);
3455 thisblock
->data
.block
.outer_cleanups
= 0;
3456 thisblock
->data
.block
.label_chain
= 0;
3457 thisblock
->data
.block
.innermost_stack_block
= stack_block_stack
;
3458 thisblock
->data
.block
.first_insn
= note
;
3459 thisblock
->data
.block
.block_start_count
= ++current_block_start_count
;
3460 thisblock
->exit_label
= exit_flag
? gen_label_rtx () : 0;
3461 block_stack
= thisblock
;
3462 nesting_stack
= thisblock
;
3464 /* Make a new level for allocating stack slots. */
3468 /* Specify the scope of temporaries created by TARGET_EXPRs. Similar
3469 to CLEANUP_POINT_EXPR, but handles cases when a series of calls to
3470 expand_expr are made. After we end the region, we know that all
3471 space for all temporaries that were created by TARGET_EXPRs will be
3472 destroyed and their space freed for reuse. */
3475 expand_start_target_temps (void)
3477 /* This is so that even if the result is preserved, the space
3478 allocated will be freed, as we know that it is no longer in use. */
3481 /* Start a new binding layer that will keep track of all cleanup
3482 actions to be performed. */
3483 expand_start_bindings (2);
3485 target_temp_slot_level
= temp_slot_level
;
3489 expand_end_target_temps (void)
3491 expand_end_bindings (NULL_TREE
, 0, 0);
3493 /* This is so that even if the result is preserved, the space
3494 allocated will be freed, as we know that it is no longer in use. */
3498 /* Given a pointer to a BLOCK node return nonzero if (and only if) the node
3499 in question represents the outermost pair of curly braces (i.e. the "body
3500 block") of a function or method.
3502 For any BLOCK node representing a "body block" of a function or method, the
3503 BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which
3504 represents the outermost (function) scope for the function or method (i.e.
3505 the one which includes the formal parameters). The BLOCK_SUPERCONTEXT of
3506 *that* node in turn will point to the relevant FUNCTION_DECL node. */
3509 is_body_block (tree stmt
)
3511 if (lang_hooks
.no_body_blocks
)
3514 if (TREE_CODE (stmt
) == BLOCK
)
3516 tree parent
= BLOCK_SUPERCONTEXT (stmt
);
3518 if (parent
&& TREE_CODE (parent
) == BLOCK
)
3520 tree grandparent
= BLOCK_SUPERCONTEXT (parent
);
3522 if (grandparent
&& TREE_CODE (grandparent
) == FUNCTION_DECL
)
3530 /* True if we are currently emitting insns in an area of output code
3531 that is controlled by a conditional expression. This is used by
3532 the cleanup handling code to generate conditional cleanup actions. */
3535 conditional_context (void)
3537 return block_stack
&& block_stack
->data
.block
.conditional_code
;
3540 /* Return an opaque pointer to the current nesting level, so frontend code
3541 can check its own sanity. */
3544 current_nesting_level (void)
3546 return cfun
? block_stack
: 0;
3549 /* Emit a handler label for a nonlocal goto handler.
3550 Also emit code to store the handler label in SLOT before BEFORE_INSN. */
3553 expand_nl_handler_label (rtx slot
, rtx before_insn
)
3556 rtx handler_label
= gen_label_rtx ();
3558 /* Don't let cleanup_cfg delete the handler. */
3559 LABEL_PRESERVE_P (handler_label
) = 1;
3562 emit_move_insn (slot
, gen_rtx_LABEL_REF (Pmode
, handler_label
));
3563 insns
= get_insns ();
3565 emit_insn_before (insns
, before_insn
);
3567 emit_label (handler_label
);
3569 return handler_label
;
3572 /* Emit code to restore vital registers at the beginning of a nonlocal goto
3575 expand_nl_goto_receiver (void)
3577 /* Clobber the FP when we get here, so we have to make sure it's
3578 marked as used by this function. */
3579 emit_insn (gen_rtx_USE (VOIDmode
, hard_frame_pointer_rtx
));
3581 /* Mark the static chain as clobbered here so life information
3582 doesn't get messed up for it. */
3583 emit_insn (gen_rtx_CLOBBER (VOIDmode
, static_chain_rtx
));
3585 #ifdef HAVE_nonlocal_goto
3586 if (! HAVE_nonlocal_goto
)
3588 /* First adjust our frame pointer to its actual value. It was
3589 previously set to the start of the virtual area corresponding to
3590 the stacked variables when we branched here and now needs to be
3591 adjusted to the actual hardware fp value.
3593 Assignments are to virtual registers are converted by
3594 instantiate_virtual_regs into the corresponding assignment
3595 to the underlying register (fp in this case) that makes
3596 the original assignment true.
3597 So the following insn will actually be
3598 decrementing fp by STARTING_FRAME_OFFSET. */
3599 emit_move_insn (virtual_stack_vars_rtx
, hard_frame_pointer_rtx
);
3601 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3602 if (fixed_regs
[ARG_POINTER_REGNUM
])
3604 #ifdef ELIMINABLE_REGS
3605 /* If the argument pointer can be eliminated in favor of the
3606 frame pointer, we don't need to restore it. We assume here
3607 that if such an elimination is present, it can always be used.
3608 This is the case on all known machines; if we don't make this
3609 assumption, we do unnecessary saving on many machines. */
3610 static const struct elims
{const int from
, to
;} elim_regs
[] = ELIMINABLE_REGS
;
3613 for (i
= 0; i
< ARRAY_SIZE (elim_regs
); i
++)
3614 if (elim_regs
[i
].from
== ARG_POINTER_REGNUM
3615 && elim_regs
[i
].to
== HARD_FRAME_POINTER_REGNUM
)
3618 if (i
== ARRAY_SIZE (elim_regs
))
3621 /* Now restore our arg pointer from the address at which it
3622 was saved in our stack frame. */
3623 emit_move_insn (virtual_incoming_args_rtx
,
3624 copy_to_reg (get_arg_pointer_save_area (cfun
)));
3629 #ifdef HAVE_nonlocal_goto_receiver
3630 if (HAVE_nonlocal_goto_receiver
)
3631 emit_insn (gen_nonlocal_goto_receiver ());
3634 /* @@@ This is a kludge. Not all machine descriptions define a blockage
3635 insn, but we must not allow the code we just generated to be reordered
3636 by scheduling. Specifically, the update of the frame pointer must
3637 happen immediately, not later. So emit an ASM_INPUT to act as blockage
3639 emit_insn (gen_rtx_ASM_INPUT (VOIDmode
, ""));
3642 /* Make handlers for nonlocal gotos taking place in the function calls in
3646 expand_nl_goto_receivers (struct nesting
*thisblock
)
3649 rtx afterward
= gen_label_rtx ();
3654 /* Record the handler address in the stack slot for that purpose,
3655 during this block, saving and restoring the outer value. */
3656 if (thisblock
->next
!= 0)
3657 for (slot
= nonlocal_goto_handler_slots
; slot
; slot
= XEXP (slot
, 1))
3659 rtx save_receiver
= gen_reg_rtx (Pmode
);
3660 emit_move_insn (XEXP (slot
, 0), save_receiver
);
3663 emit_move_insn (save_receiver
, XEXP (slot
, 0));
3664 insns
= get_insns ();
3666 emit_insn_before (insns
, thisblock
->data
.block
.first_insn
);
3669 /* Jump around the handlers; they run only when specially invoked. */
3670 emit_jump (afterward
);
3672 /* Make a separate handler for each label. */
3673 link
= nonlocal_labels
;
3674 slot
= nonlocal_goto_handler_slots
;
3675 label_list
= NULL_RTX
;
3676 for (; link
; link
= TREE_CHAIN (link
), slot
= XEXP (slot
, 1))
3677 /* Skip any labels we shouldn't be able to jump to from here,
3678 we generate one special handler for all of them below which just calls
3680 if (! DECL_TOO_LATE (TREE_VALUE (link
)))
3683 lab
= expand_nl_handler_label (XEXP (slot
, 0),
3684 thisblock
->data
.block
.first_insn
);
3685 label_list
= gen_rtx_EXPR_LIST (VOIDmode
, lab
, label_list
);
3687 expand_nl_goto_receiver ();
3689 /* Jump to the "real" nonlocal label. */
3690 expand_goto (TREE_VALUE (link
));
3693 /* A second pass over all nonlocal labels; this time we handle those
3694 we should not be able to jump to at this point. */
3695 link
= nonlocal_labels
;
3696 slot
= nonlocal_goto_handler_slots
;
3698 for (; link
; link
= TREE_CHAIN (link
), slot
= XEXP (slot
, 1))
3699 if (DECL_TOO_LATE (TREE_VALUE (link
)))
3702 lab
= expand_nl_handler_label (XEXP (slot
, 0),
3703 thisblock
->data
.block
.first_insn
);
3704 label_list
= gen_rtx_EXPR_LIST (VOIDmode
, lab
, label_list
);
3710 expand_nl_goto_receiver ();
3711 expand_builtin_trap ();
3714 nonlocal_goto_handler_labels
= label_list
;
3715 emit_label (afterward
);
3718 /* Warn about any unused VARS (which may contain nodes other than
3719 VAR_DECLs, but such nodes are ignored). The nodes are connected
3720 via the TREE_CHAIN field. */
3723 warn_about_unused_variables (tree vars
)
3727 if (warn_unused_variable
)
3728 for (decl
= vars
; decl
; decl
= TREE_CHAIN (decl
))
3729 if (TREE_CODE (decl
) == VAR_DECL
3730 && ! TREE_USED (decl
)
3731 && ! DECL_IN_SYSTEM_HEADER (decl
)
3732 && DECL_NAME (decl
) && ! DECL_ARTIFICIAL (decl
))
3733 warning ("%Junused variable '%D'", decl
, decl
);
3736 /* Generate RTL code to terminate a binding contour.
3738 VARS is the chain of VAR_DECL nodes for the variables bound in this
3739 contour. There may actually be other nodes in this chain, but any
3740 nodes other than VAR_DECLS are ignored.
3742 MARK_ENDS is nonzero if we should put a note at the beginning
3743 and end of this binding contour.
3745 DONT_JUMP_IN is positive if it is not valid to jump into this contour,
3746 zero if we can jump into this contour only if it does not have a saved
3747 stack level, and negative if we are not to check for invalid use of
3748 labels (because the front end does that). */
3751 expand_end_bindings (tree vars
, int mark_ends
, int dont_jump_in
)
3753 struct nesting
*thisblock
= block_stack
;
3755 /* If any of the variables in this scope were not used, warn the
3757 warn_about_unused_variables (vars
);
3759 if (thisblock
->exit_label
)
3761 do_pending_stack_adjust ();
3762 emit_label (thisblock
->exit_label
);
3765 /* If necessary, make handlers for nonlocal gotos taking
3766 place in the function calls in this block. */
3767 if (function_call_count
!= 0 && nonlocal_labels
3768 /* Make handler for outermost block
3769 if there were any nonlocal gotos to this function. */
3770 && (thisblock
->next
== 0 ? current_function_has_nonlocal_label
3771 /* Make handler for inner block if it has something
3772 special to do when you jump out of it. */
3773 : (thisblock
->data
.block
.cleanups
!= 0
3774 || thisblock
->data
.block
.stack_level
!= 0)))
3775 expand_nl_goto_receivers (thisblock
);
3777 /* Don't allow jumping into a block that has a stack level.
3778 Cleanups are allowed, though. */
3779 if (dont_jump_in
> 0
3780 || (dont_jump_in
== 0 && thisblock
->data
.block
.stack_level
!= 0))
3782 struct label_chain
*chain
;
3784 /* Any labels in this block are no longer valid to go to.
3785 Mark them to cause an error message. */
3786 for (chain
= thisblock
->data
.block
.label_chain
; chain
; chain
= chain
->next
)
3788 DECL_TOO_LATE (chain
->label
) = 1;
3789 /* If any goto without a fixup came to this label,
3790 that must be an error, because gotos without fixups
3791 come from outside all saved stack-levels. */
3792 if (TREE_ADDRESSABLE (chain
->label
))
3793 error ("%Jlabel '%D' used before containing binding contour",
3794 chain
->label
, chain
->label
);
3798 /* Restore stack level in effect before the block
3799 (only if variable-size objects allocated). */
3800 /* Perform any cleanups associated with the block. */
3802 if (thisblock
->data
.block
.stack_level
!= 0
3803 || thisblock
->data
.block
.cleanups
!= 0)
3808 /* Don't let cleanups affect ({...}) constructs. */
3809 int old_expr_stmts_for_value
= expr_stmts_for_value
;
3810 rtx old_last_expr_value
= last_expr_value
;
3811 rtx old_last_expr_alt_rtl
= last_expr_alt_rtl
;
3812 tree old_last_expr_type
= last_expr_type
;
3813 expr_stmts_for_value
= 0;
3815 /* Only clean up here if this point can actually be reached. */
3816 insn
= get_last_insn ();
3817 if (GET_CODE (insn
) == NOTE
)
3818 insn
= prev_nonnote_insn (insn
);
3819 reachable
= (! insn
|| GET_CODE (insn
) != BARRIER
);
3821 /* Do the cleanups. */
3822 expand_cleanups (thisblock
->data
.block
.cleanups
, 0, reachable
);
3824 do_pending_stack_adjust ();
3826 expr_stmts_for_value
= old_expr_stmts_for_value
;
3827 last_expr_value
= old_last_expr_value
;
3828 last_expr_alt_rtl
= old_last_expr_alt_rtl
;
3829 last_expr_type
= old_last_expr_type
;
3831 /* Restore the stack level. */
3833 if (reachable
&& thisblock
->data
.block
.stack_level
!= 0)
3835 emit_stack_restore (thisblock
->next
? SAVE_BLOCK
: SAVE_FUNCTION
,
3836 thisblock
->data
.block
.stack_level
, NULL_RTX
);
3837 if (nonlocal_goto_handler_slots
!= 0)
3838 emit_stack_save (SAVE_NONLOCAL
, &nonlocal_goto_stack_level
,
3842 /* Any gotos out of this block must also do these things.
3843 Also report any gotos with fixups that came to labels in this
3845 fixup_gotos (thisblock
,
3846 thisblock
->data
.block
.stack_level
,
3847 thisblock
->data
.block
.cleanups
,
3848 thisblock
->data
.block
.first_insn
,
3852 /* Mark the beginning and end of the scope if requested.
3853 We do this now, after running cleanups on the variables
3854 just going out of scope, so they are in scope for their cleanups. */
3858 rtx note
= emit_note (NOTE_INSN_BLOCK_END
);
3859 NOTE_BLOCK (note
) = NOTE_BLOCK (thisblock
->data
.block
.first_insn
);
3862 /* Get rid of the beginning-mark if we don't make an end-mark. */
3863 NOTE_LINE_NUMBER (thisblock
->data
.block
.first_insn
) = NOTE_INSN_DELETED
;
3865 /* Restore the temporary level of TARGET_EXPRs. */
3866 target_temp_slot_level
= thisblock
->data
.block
.block_target_temp_slot_level
;
3868 /* Restore block_stack level for containing block. */
3870 stack_block_stack
= thisblock
->data
.block
.innermost_stack_block
;
3871 POPSTACK (block_stack
);
3873 /* Pop the stack slot nesting and free any slots at this level. */
3877 /* Generate code to save the stack pointer at the start of the current block
3878 and set up to restore it on exit. */
3881 save_stack_pointer (void)
3883 struct nesting
*thisblock
= block_stack
;
3885 if (thisblock
->data
.block
.stack_level
== 0)
3887 emit_stack_save (thisblock
->next
? SAVE_BLOCK
: SAVE_FUNCTION
,
3888 &thisblock
->data
.block
.stack_level
,
3889 thisblock
->data
.block
.first_insn
);
3890 stack_block_stack
= thisblock
;
3894 /* Generate RTL for the automatic variable declaration DECL.
3895 (Other kinds of declarations are simply ignored if seen here.) */
3898 expand_decl (tree decl
)
3902 type
= TREE_TYPE (decl
);
3904 /* For a CONST_DECL, set mode, alignment, and sizes from those of the
3905 type in case this node is used in a reference. */
3906 if (TREE_CODE (decl
) == CONST_DECL
)
3908 DECL_MODE (decl
) = TYPE_MODE (type
);
3909 DECL_ALIGN (decl
) = TYPE_ALIGN (type
);
3910 DECL_SIZE (decl
) = TYPE_SIZE (type
);
3911 DECL_SIZE_UNIT (decl
) = TYPE_SIZE_UNIT (type
);
3915 /* Otherwise, only automatic variables need any expansion done. Static and
3916 external variables, and external functions, will be handled by
3917 `assemble_variable' (called from finish_decl). TYPE_DECL requires
3918 nothing. PARM_DECLs are handled in `assign_parms'. */
3919 if (TREE_CODE (decl
) != VAR_DECL
)
3922 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
))
3925 /* Create the RTL representation for the variable. */
3927 if (type
== error_mark_node
)
3928 SET_DECL_RTL (decl
, gen_rtx_MEM (BLKmode
, const0_rtx
));
3930 else if (DECL_SIZE (decl
) == 0)
3931 /* Variable with incomplete type. */
3934 if (DECL_INITIAL (decl
) == 0)
3935 /* Error message was already done; now avoid a crash. */
3936 x
= gen_rtx_MEM (BLKmode
, const0_rtx
);
3938 /* An initializer is going to decide the size of this array.
3939 Until we know the size, represent its address with a reg. */
3940 x
= gen_rtx_MEM (BLKmode
, gen_reg_rtx (Pmode
));
3942 set_mem_attributes (x
, decl
, 1);
3943 SET_DECL_RTL (decl
, x
);
3945 else if (DECL_MODE (decl
) != BLKmode
3946 /* If -ffloat-store, don't put explicit float vars
3948 && !(flag_float_store
3949 && TREE_CODE (type
) == REAL_TYPE
)
3950 && ! TREE_THIS_VOLATILE (decl
)
3951 && ! DECL_NONLOCAL (decl
)
3952 && (DECL_REGISTER (decl
) || DECL_ARTIFICIAL (decl
) || optimize
))
3954 /* Automatic variable that can go in a register. */
3955 int unsignedp
= TREE_UNSIGNED (type
);
3956 enum machine_mode reg_mode
3957 = promote_mode (type
, DECL_MODE (decl
), &unsignedp
, 0);
3959 SET_DECL_RTL (decl
, gen_reg_rtx (reg_mode
));
3961 if (!DECL_ARTIFICIAL (decl
))
3962 mark_user_reg (DECL_RTL (decl
));
3964 if (POINTER_TYPE_P (type
))
3965 mark_reg_pointer (DECL_RTL (decl
),
3966 TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
3968 maybe_set_unchanging (DECL_RTL (decl
), decl
);
3970 /* If something wants our address, try to use ADDRESSOF. */
3971 if (TREE_ADDRESSABLE (decl
))
3972 put_var_into_stack (decl
, /*rescan=*/false);
3975 else if (TREE_CODE (DECL_SIZE_UNIT (decl
)) == INTEGER_CST
3976 && ! (flag_stack_check
&& ! STACK_CHECK_BUILTIN
3977 && 0 < compare_tree_int (DECL_SIZE_UNIT (decl
),
3978 STACK_CHECK_MAX_VAR_SIZE
)))
3980 /* Variable of fixed size that goes on the stack. */
3985 /* If we previously made RTL for this decl, it must be an array
3986 whose size was determined by the initializer.
3987 The old address was a register; set that register now
3988 to the proper address. */
3989 if (DECL_RTL_SET_P (decl
))
3991 if (GET_CODE (DECL_RTL (decl
)) != MEM
3992 || GET_CODE (XEXP (DECL_RTL (decl
), 0)) != REG
)
3994 oldaddr
= XEXP (DECL_RTL (decl
), 0);
3997 /* Set alignment we actually gave this decl. */
3998 DECL_ALIGN (decl
) = (DECL_MODE (decl
) == BLKmode
? BIGGEST_ALIGNMENT
3999 : GET_MODE_BITSIZE (DECL_MODE (decl
)));
4000 DECL_USER_ALIGN (decl
) = 0;
4002 x
= assign_temp (decl
, 1, 1, 1);
4003 set_mem_attributes (x
, decl
, 1);
4004 SET_DECL_RTL (decl
, x
);
4008 addr
= force_operand (XEXP (DECL_RTL (decl
), 0), oldaddr
);
4009 if (addr
!= oldaddr
)
4010 emit_move_insn (oldaddr
, addr
);
4014 /* Dynamic-size object: must push space on the stack. */
4016 rtx address
, size
, x
;
4018 /* Record the stack pointer on entry to block, if have
4019 not already done so. */
4020 do_pending_stack_adjust ();
4021 save_stack_pointer ();
4023 /* In function-at-a-time mode, variable_size doesn't expand this,
4025 if (TREE_CODE (type
) == ARRAY_TYPE
&& TYPE_DOMAIN (type
))
4026 expand_expr (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)),
4027 const0_rtx
, VOIDmode
, 0);
4029 /* Compute the variable's size, in bytes. */
4030 size
= expand_expr (DECL_SIZE_UNIT (decl
), NULL_RTX
, VOIDmode
, 0);
4033 /* Allocate space on the stack for the variable. Note that
4034 DECL_ALIGN says how the variable is to be aligned and we
4035 cannot use it to conclude anything about the alignment of
4037 address
= allocate_dynamic_stack_space (size
, NULL_RTX
,
4038 TYPE_ALIGN (TREE_TYPE (decl
)));
4040 /* Reference the variable indirect through that rtx. */
4041 x
= gen_rtx_MEM (DECL_MODE (decl
), address
);
4042 set_mem_attributes (x
, decl
, 1);
4043 SET_DECL_RTL (decl
, x
);
4046 /* Indicate the alignment we actually gave this variable. */
4047 #ifdef STACK_BOUNDARY
4048 DECL_ALIGN (decl
) = STACK_BOUNDARY
;
4050 DECL_ALIGN (decl
) = BIGGEST_ALIGNMENT
;
4052 DECL_USER_ALIGN (decl
) = 0;
4056 /* Emit code to perform the initialization of a declaration DECL. */
4059 expand_decl_init (tree decl
)
4061 int was_used
= TREE_USED (decl
);
4063 /* If this is a CONST_DECL, we don't have to generate any code. Likewise
4064 for static decls. */
4065 if (TREE_CODE (decl
) == CONST_DECL
4066 || TREE_STATIC (decl
))
4069 /* Compute and store the initial value now. */
4073 if (DECL_INITIAL (decl
) == error_mark_node
)
4075 enum tree_code code
= TREE_CODE (TREE_TYPE (decl
));
4077 if (code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== ENUMERAL_TYPE
4078 || code
== POINTER_TYPE
|| code
== REFERENCE_TYPE
)
4079 expand_assignment (decl
, convert (TREE_TYPE (decl
), integer_zero_node
),
4083 else if (DECL_INITIAL (decl
) && TREE_CODE (DECL_INITIAL (decl
)) != TREE_LIST
)
4085 emit_line_note (DECL_SOURCE_LOCATION (decl
));
4086 expand_assignment (decl
, DECL_INITIAL (decl
), 0);
4090 /* Don't let the initialization count as "using" the variable. */
4091 TREE_USED (decl
) = was_used
;
4093 /* Free any temporaries we made while initializing the decl. */
4094 preserve_temp_slots (NULL_RTX
);
4099 /* CLEANUP is an expression to be executed at exit from this binding contour;
4100 for example, in C++, it might call the destructor for this variable.
4102 We wrap CLEANUP in an UNSAVE_EXPR node, so that we can expand the
4103 CLEANUP multiple times, and have the correct semantics. This
4104 happens in exception handling, for gotos, returns, breaks that
4105 leave the current scope.
4107 If CLEANUP is nonzero and DECL is zero, we record a cleanup
4108 that is not associated with any particular variable. */
4111 expand_decl_cleanup (tree decl
, tree cleanup
)
4113 struct nesting
*thisblock
;
4115 /* Error if we are not in any block. */
4116 if (cfun
== 0 || block_stack
== 0)
4119 thisblock
= block_stack
;
4121 /* Record the cleanup if there is one. */
4127 tree
*cleanups
= &thisblock
->data
.block
.cleanups
;
4128 int cond_context
= conditional_context ();
4132 rtx flag
= gen_reg_rtx (word_mode
);
4137 emit_move_insn (flag
, const0_rtx
);
4138 set_flag_0
= get_insns ();
4141 thisblock
->data
.block
.last_unconditional_cleanup
4142 = emit_insn_after (set_flag_0
,
4143 thisblock
->data
.block
.last_unconditional_cleanup
);
4145 emit_move_insn (flag
, const1_rtx
);
4147 cond
= build_decl (VAR_DECL
, NULL_TREE
,
4148 (*lang_hooks
.types
.type_for_mode
) (word_mode
, 1));
4149 SET_DECL_RTL (cond
, flag
);
4151 /* Conditionalize the cleanup. */
4152 cleanup
= build (COND_EXPR
, void_type_node
,
4153 (*lang_hooks
.truthvalue_conversion
) (cond
),
4154 cleanup
, integer_zero_node
);
4155 cleanup
= fold (cleanup
);
4157 cleanups
= &thisblock
->data
.block
.cleanups
;
4160 cleanup
= unsave_expr (cleanup
);
4162 t
= *cleanups
= tree_cons (decl
, cleanup
, *cleanups
);
4165 /* If this block has a cleanup, it belongs in stack_block_stack. */
4166 stack_block_stack
= thisblock
;
4173 if (! using_eh_for_cleanups_p
)
4174 TREE_ADDRESSABLE (t
) = 1;
4176 expand_eh_region_start ();
4183 thisblock
->data
.block
.last_unconditional_cleanup
4184 = emit_insn_after (seq
,
4185 thisblock
->data
.block
.last_unconditional_cleanup
);
4189 thisblock
->data
.block
.last_unconditional_cleanup
4191 /* When we insert instructions after the last unconditional cleanup,
4192 we don't adjust last_insn. That means that a later add_insn will
4193 clobber the instructions we've just added. The easiest way to
4194 fix this is to just insert another instruction here, so that the
4195 instructions inserted after the last unconditional cleanup are
4196 never the last instruction. */
4197 emit_note (NOTE_INSN_DELETED
);
4203 /* Like expand_decl_cleanup, but maybe only run the cleanup if an exception
4207 expand_decl_cleanup_eh (tree decl
, tree cleanup
, int eh_only
)
4209 int ret
= expand_decl_cleanup (decl
, cleanup
);
4212 tree node
= block_stack
->data
.block
.cleanups
;
4213 CLEANUP_EH_ONLY (node
) = eh_only
;
4218 /* DECL is an anonymous union. CLEANUP is a cleanup for DECL.
4219 DECL_ELTS is the list of elements that belong to DECL's type.
4220 In each, the TREE_VALUE is a VAR_DECL, and the TREE_PURPOSE a cleanup. */
4223 expand_anon_union_decl (tree decl
, tree cleanup
, tree decl_elts
)
4225 struct nesting
*thisblock
= cfun
== 0 ? 0 : block_stack
;
4229 /* If any of the elements are addressable, so is the entire union. */
4230 for (t
= decl_elts
; t
; t
= TREE_CHAIN (t
))
4231 if (TREE_ADDRESSABLE (TREE_VALUE (t
)))
4233 TREE_ADDRESSABLE (decl
) = 1;
4238 expand_decl_cleanup (decl
, cleanup
);
4239 x
= DECL_RTL (decl
);
4241 /* Go through the elements, assigning RTL to each. */
4242 for (t
= decl_elts
; t
; t
= TREE_CHAIN (t
))
4244 tree decl_elt
= TREE_VALUE (t
);
4245 tree cleanup_elt
= TREE_PURPOSE (t
);
4246 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (decl_elt
));
4248 /* If any of the elements are addressable, so is the entire
4250 if (TREE_USED (decl_elt
))
4251 TREE_USED (decl
) = 1;
4253 /* Propagate the union's alignment to the elements. */
4254 DECL_ALIGN (decl_elt
) = DECL_ALIGN (decl
);
4255 DECL_USER_ALIGN (decl_elt
) = DECL_USER_ALIGN (decl
);
4257 /* If the element has BLKmode and the union doesn't, the union is
4258 aligned such that the element doesn't need to have BLKmode, so
4259 change the element's mode to the appropriate one for its size. */
4260 if (mode
== BLKmode
&& DECL_MODE (decl
) != BLKmode
)
4261 DECL_MODE (decl_elt
) = mode
4262 = mode_for_size_tree (DECL_SIZE (decl_elt
), MODE_INT
, 1);
4264 /* (SUBREG (MEM ...)) at RTL generation time is invalid, so we
4265 instead create a new MEM rtx with the proper mode. */
4266 if (GET_CODE (x
) == MEM
)
4268 if (mode
== GET_MODE (x
))
4269 SET_DECL_RTL (decl_elt
, x
);
4271 SET_DECL_RTL (decl_elt
, adjust_address_nv (x
, mode
, 0));
4273 else if (GET_CODE (x
) == REG
)
4275 if (mode
== GET_MODE (x
))
4276 SET_DECL_RTL (decl_elt
, x
);
4278 SET_DECL_RTL (decl_elt
, gen_lowpart_SUBREG (mode
, x
));
4283 /* Record the cleanup if there is one. */
4286 thisblock
->data
.block
.cleanups
4287 = tree_cons (decl_elt
, cleanup_elt
,
4288 thisblock
->data
.block
.cleanups
);
4292 /* Expand a list of cleanups LIST.
4293 Elements may be expressions or may be nested lists.
4295 If IN_FIXUP is nonzero, we are generating this cleanup for a fixup
4296 goto and handle protection regions specially in that case.
4298 If REACHABLE, we emit code, otherwise just inform the exception handling
4299 code about this finalization. */
4302 expand_cleanups (tree list
, int in_fixup
, int reachable
)
4305 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
4306 if (TREE_CODE (TREE_VALUE (tail
)) == TREE_LIST
)
4307 expand_cleanups (TREE_VALUE (tail
), in_fixup
, reachable
);
4310 if (! in_fixup
&& using_eh_for_cleanups_p
)
4311 expand_eh_region_end_cleanup (TREE_VALUE (tail
));
4313 if (reachable
&& !CLEANUP_EH_ONLY (tail
))
4315 /* Cleanups may be run multiple times. For example,
4316 when exiting a binding contour, we expand the
4317 cleanups associated with that contour. When a goto
4318 within that binding contour has a target outside that
4319 contour, it will expand all cleanups from its scope to
4320 the target. Though the cleanups are expanded multiple
4321 times, the control paths are non-overlapping so the
4322 cleanups will not be executed twice. */
4324 /* We may need to protect from outer cleanups. */
4325 if (in_fixup
&& using_eh_for_cleanups_p
)
4327 expand_eh_region_start ();
4329 expand_expr (TREE_VALUE (tail
), const0_rtx
, VOIDmode
, 0);
4331 expand_eh_region_end_fixup (TREE_VALUE (tail
));
4334 expand_expr (TREE_VALUE (tail
), const0_rtx
, VOIDmode
, 0);
4341 /* Mark when the context we are emitting RTL for as a conditional
4342 context, so that any cleanup actions we register with
4343 expand_decl_init will be properly conditionalized when those
4344 cleanup actions are later performed. Must be called before any
4345 expression (tree) is expanded that is within a conditional context. */
4348 start_cleanup_deferral (void)
4350 /* block_stack can be NULL if we are inside the parameter list. It is
4351 OK to do nothing, because cleanups aren't possible here. */
4353 ++block_stack
->data
.block
.conditional_code
;
4356 /* Mark the end of a conditional region of code. Because cleanup
4357 deferrals may be nested, we may still be in a conditional region
4358 after we end the currently deferred cleanups, only after we end all
4359 deferred cleanups, are we back in unconditional code. */
4362 end_cleanup_deferral (void)
4364 /* block_stack can be NULL if we are inside the parameter list. It is
4365 OK to do nothing, because cleanups aren't possible here. */
4367 --block_stack
->data
.block
.conditional_code
;
4371 last_cleanup_this_contour (void)
4373 if (block_stack
== 0)
4376 return block_stack
->data
.block
.cleanups
;
4379 /* Return 1 if there are any pending cleanups at this point.
4380 Check the current contour as well as contours that enclose
4381 the current contour. */
4384 any_pending_cleanups (void)
4386 struct nesting
*block
;
4388 if (cfun
== NULL
|| cfun
->stmt
== NULL
|| block_stack
== 0)
4391 if (block_stack
->data
.block
.cleanups
!= NULL
)
4394 if (block_stack
->data
.block
.outer_cleanups
== 0)
4397 for (block
= block_stack
->next
; block
; block
= block
->next
)
4398 if (block
->data
.block
.cleanups
!= 0)
4404 /* Enter a case (Pascal) or switch (C) statement.
4405 Push a block onto case_stack and nesting_stack
4406 to accumulate the case-labels that are seen
4407 and to record the labels generated for the statement.
4409 EXIT_FLAG is nonzero if `exit_something' should exit this case stmt.
4410 Otherwise, this construct is transparent for `exit_something'.
4412 EXPR is the index-expression to be dispatched on.
4413 TYPE is its nominal type. We could simply convert EXPR to this type,
4414 but instead we take short cuts. */
4417 expand_start_case (int exit_flag
, tree expr
, tree type
,
4418 const char *printname
)
4420 struct nesting
*thiscase
= ALLOC_NESTING ();
4422 /* Make an entry on case_stack for the case we are entering. */
4424 thiscase
->desc
= CASE_NESTING
;
4425 thiscase
->next
= case_stack
;
4426 thiscase
->all
= nesting_stack
;
4427 thiscase
->depth
= ++nesting_depth
;
4428 thiscase
->exit_label
= exit_flag
? gen_label_rtx () : 0;
4429 thiscase
->data
.case_stmt
.case_list
= 0;
4430 thiscase
->data
.case_stmt
.index_expr
= expr
;
4431 thiscase
->data
.case_stmt
.nominal_type
= type
;
4432 thiscase
->data
.case_stmt
.default_label
= 0;
4433 thiscase
->data
.case_stmt
.printname
= printname
;
4434 thiscase
->data
.case_stmt
.line_number_status
= force_line_numbers ();
4435 case_stack
= thiscase
;
4436 nesting_stack
= thiscase
;
4438 do_pending_stack_adjust ();
4441 /* Make sure case_stmt.start points to something that won't
4442 need any transformation before expand_end_case. */
4443 if (GET_CODE (get_last_insn ()) != NOTE
)
4444 emit_note (NOTE_INSN_DELETED
);
4446 thiscase
->data
.case_stmt
.start
= get_last_insn ();
4448 start_cleanup_deferral ();
4451 /* Start a "dummy case statement" within which case labels are invalid
4452 and are not connected to any larger real case statement.
4453 This can be used if you don't want to let a case statement jump
4454 into the middle of certain kinds of constructs. */
4457 expand_start_case_dummy (void)
4459 struct nesting
*thiscase
= ALLOC_NESTING ();
4461 /* Make an entry on case_stack for the dummy. */
4463 thiscase
->desc
= CASE_NESTING
;
4464 thiscase
->next
= case_stack
;
4465 thiscase
->all
= nesting_stack
;
4466 thiscase
->depth
= ++nesting_depth
;
4467 thiscase
->exit_label
= 0;
4468 thiscase
->data
.case_stmt
.case_list
= 0;
4469 thiscase
->data
.case_stmt
.start
= 0;
4470 thiscase
->data
.case_stmt
.nominal_type
= 0;
4471 thiscase
->data
.case_stmt
.default_label
= 0;
4472 case_stack
= thiscase
;
4473 nesting_stack
= thiscase
;
4474 start_cleanup_deferral ();
4478 check_seenlabel (void)
4480 /* If this is the first label, warn if any insns have been emitted. */
4481 if (case_stack
->data
.case_stmt
.line_number_status
>= 0)
4485 restore_line_number_status
4486 (case_stack
->data
.case_stmt
.line_number_status
);
4487 case_stack
->data
.case_stmt
.line_number_status
= -1;
4489 for (insn
= case_stack
->data
.case_stmt
.start
;
4491 insn
= NEXT_INSN (insn
))
4493 if (GET_CODE (insn
) == CODE_LABEL
)
4495 if (GET_CODE (insn
) != NOTE
4496 && (GET_CODE (insn
) != INSN
|| GET_CODE (PATTERN (insn
)) != USE
))
4499 insn
= PREV_INSN (insn
);
4500 while (insn
&& (GET_CODE (insn
) != NOTE
|| NOTE_LINE_NUMBER (insn
) < 0));
4502 /* If insn is zero, then there must have been a syntax error. */
4506 locus
.file
= NOTE_SOURCE_FILE (insn
);
4507 locus
.line
= NOTE_LINE_NUMBER (insn
);
4508 warning ("%Hunreachable code at beginning of %s", &locus
,
4509 case_stack
->data
.case_stmt
.printname
);
4517 /* Accumulate one case or default label inside a case or switch statement.
4518 VALUE is the value of the case (a null pointer, for a default label).
4519 The function CONVERTER, when applied to arguments T and V,
4520 converts the value V to the type T.
4522 If not currently inside a case or switch statement, return 1 and do
4523 nothing. The caller will print a language-specific error message.
4524 If VALUE is a duplicate or overlaps, return 2 and do nothing
4525 except store the (first) duplicate node in *DUPLICATE.
4526 If VALUE is out of range, return 3 and do nothing.
4527 If we are jumping into the scope of a cleanup or var-sized array, return 5.
4528 Return 0 on success.
4530 Extended to handle range statements. */
4533 pushcase (tree value
, tree (*converter
) (tree
, tree
), tree label
,
4539 /* Fail if not inside a real case statement. */
4540 if (! (case_stack
&& case_stack
->data
.case_stmt
.start
))
4543 if (stack_block_stack
4544 && stack_block_stack
->depth
> case_stack
->depth
)
4547 index_type
= TREE_TYPE (case_stack
->data
.case_stmt
.index_expr
);
4548 nominal_type
= case_stack
->data
.case_stmt
.nominal_type
;
4550 /* If the index is erroneous, avoid more problems: pretend to succeed. */
4551 if (index_type
== error_mark_node
)
4554 /* Convert VALUE to the type in which the comparisons are nominally done. */
4556 value
= (*converter
) (nominal_type
, value
);
4560 /* Fail if this value is out of range for the actual type of the index
4561 (which may be narrower than NOMINAL_TYPE). */
4563 && (TREE_CONSTANT_OVERFLOW (value
)
4564 || ! int_fits_type_p (value
, index_type
)))
4567 return add_case_node (value
, value
, label
, duplicate
);
4570 /* Like pushcase but this case applies to all values between VALUE1 and
4571 VALUE2 (inclusive). If VALUE1 is NULL, the range starts at the lowest
4572 value of the index type and ends at VALUE2. If VALUE2 is NULL, the range
4573 starts at VALUE1 and ends at the highest value of the index type.
4574 If both are NULL, this case applies to all values.
4576 The return value is the same as that of pushcase but there is one
4577 additional error code: 4 means the specified range was empty. */
4580 pushcase_range (tree value1
, tree value2
, tree (*converter
) (tree
, tree
),
4581 tree label
, tree
*duplicate
)
4586 /* Fail if not inside a real case statement. */
4587 if (! (case_stack
&& case_stack
->data
.case_stmt
.start
))
4590 if (stack_block_stack
4591 && stack_block_stack
->depth
> case_stack
->depth
)
4594 index_type
= TREE_TYPE (case_stack
->data
.case_stmt
.index_expr
);
4595 nominal_type
= case_stack
->data
.case_stmt
.nominal_type
;
4597 /* If the index is erroneous, avoid more problems: pretend to succeed. */
4598 if (index_type
== error_mark_node
)
4603 /* Convert VALUEs to type in which the comparisons are nominally done
4604 and replace any unspecified value with the corresponding bound. */
4606 value1
= TYPE_MIN_VALUE (index_type
);
4608 value2
= TYPE_MAX_VALUE (index_type
);
4610 /* Fail if the range is empty. Do this before any conversion since
4611 we want to allow out-of-range empty ranges. */
4612 if (value2
!= 0 && tree_int_cst_lt (value2
, value1
))
4615 /* If the max was unbounded, use the max of the nominal_type we are
4616 converting to. Do this after the < check above to suppress false
4619 value2
= TYPE_MAX_VALUE (nominal_type
);
4621 value1
= (*converter
) (nominal_type
, value1
);
4622 value2
= (*converter
) (nominal_type
, value2
);
4624 /* Fail if these values are out of range. */
4625 if (TREE_CONSTANT_OVERFLOW (value1
)
4626 || ! int_fits_type_p (value1
, index_type
))
4629 if (TREE_CONSTANT_OVERFLOW (value2
)
4630 || ! int_fits_type_p (value2
, index_type
))
4633 return add_case_node (value1
, value2
, label
, duplicate
);
4636 /* Do the actual insertion of a case label for pushcase and pushcase_range
4637 into case_stack->data.case_stmt.case_list. Use an AVL tree to avoid
4638 slowdown for large switch statements. */
4641 add_case_node (tree low
, tree high
, tree label
, tree
*duplicate
)
4643 struct case_node
*p
, **q
, *r
;
4645 /* If there's no HIGH value, then this is not a case range; it's
4646 just a simple case label. But that's just a degenerate case
4651 /* Handle default labels specially. */
4654 if (case_stack
->data
.case_stmt
.default_label
!= 0)
4656 *duplicate
= case_stack
->data
.case_stmt
.default_label
;
4659 case_stack
->data
.case_stmt
.default_label
= label
;
4660 expand_label (label
);
4664 q
= &case_stack
->data
.case_stmt
.case_list
;
4671 /* Keep going past elements distinctly greater than HIGH. */
4672 if (tree_int_cst_lt (high
, p
->low
))
4675 /* or distinctly less than LOW. */
4676 else if (tree_int_cst_lt (p
->high
, low
))
4681 /* We have an overlap; this is an error. */
4682 *duplicate
= p
->code_label
;
4687 /* Add this label to the chain, and succeed. */
4689 r
= ggc_alloc (sizeof (struct case_node
));
4692 /* If the bounds are equal, turn this into the one-value case. */
4693 if (tree_int_cst_equal (low
, high
))
4698 r
->code_label
= label
;
4699 expand_label (label
);
4709 struct case_node
*s
;
4715 if (! (b
= p
->balance
))
4716 /* Growth propagation from left side. */
4723 if ((p
->left
= s
= r
->right
))
4732 if ((r
->parent
= s
))
4740 case_stack
->data
.case_stmt
.case_list
= r
;
4743 /* r->balance == +1 */
4748 struct case_node
*t
= r
->right
;
4750 if ((p
->left
= s
= t
->right
))
4754 if ((r
->right
= s
= t
->left
))
4768 if ((t
->parent
= s
))
4776 case_stack
->data
.case_stmt
.case_list
= t
;
4783 /* p->balance == +1; growth of left side balances the node. */
4793 if (! (b
= p
->balance
))
4794 /* Growth propagation from right side. */
4802 if ((p
->right
= s
= r
->left
))
4810 if ((r
->parent
= s
))
4819 case_stack
->data
.case_stmt
.case_list
= r
;
4823 /* r->balance == -1 */
4827 struct case_node
*t
= r
->left
;
4829 if ((p
->right
= s
= t
->left
))
4834 if ((r
->left
= s
= t
->right
))
4848 if ((t
->parent
= s
))
4857 case_stack
->data
.case_stmt
.case_list
= t
;
4863 /* p->balance == -1; growth of right side balances the node. */
4876 /* Returns the number of possible values of TYPE.
4877 Returns -1 if the number is unknown, variable, or if the number does not
4878 fit in a HOST_WIDE_INT.
4879 Sets *SPARSENESS to 2 if TYPE is an ENUMERAL_TYPE whose values
4880 do not increase monotonically (there may be duplicates);
4881 to 1 if the values increase monotonically, but not always by 1;
4882 otherwise sets it to 0. */
4885 all_cases_count (tree type
, int *sparseness
)
4888 HOST_WIDE_INT count
, minval
, lastval
;
4892 switch (TREE_CODE (type
))
4899 count
= 1 << BITS_PER_UNIT
;
4904 if (TYPE_MAX_VALUE (type
) != 0
4905 && 0 != (t
= fold (build (MINUS_EXPR
, type
, TYPE_MAX_VALUE (type
),
4906 TYPE_MIN_VALUE (type
))))
4907 && 0 != (t
= fold (build (PLUS_EXPR
, type
, t
,
4908 convert (type
, integer_zero_node
))))
4909 && host_integerp (t
, 1))
4910 count
= tree_low_cst (t
, 1);
4916 /* Don't waste time with enumeral types with huge values. */
4917 if (! host_integerp (TYPE_MIN_VALUE (type
), 0)
4918 || TYPE_MAX_VALUE (type
) == 0
4919 || ! host_integerp (TYPE_MAX_VALUE (type
), 0))
4922 lastval
= minval
= tree_low_cst (TYPE_MIN_VALUE (type
), 0);
4925 for (t
= TYPE_VALUES (type
); t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
4927 HOST_WIDE_INT thisval
= tree_low_cst (TREE_VALUE (t
), 0);
4929 if (*sparseness
== 2 || thisval
<= lastval
)
4931 else if (thisval
!= minval
+ count
)
4942 #define BITARRAY_TEST(ARRAY, INDEX) \
4943 ((ARRAY)[(unsigned) (INDEX) / HOST_BITS_PER_CHAR]\
4944 & (1 << ((unsigned) (INDEX) % HOST_BITS_PER_CHAR)))
4945 #define BITARRAY_SET(ARRAY, INDEX) \
4946 ((ARRAY)[(unsigned) (INDEX) / HOST_BITS_PER_CHAR]\
4947 |= 1 << ((unsigned) (INDEX) % HOST_BITS_PER_CHAR))
4949 /* Set the elements of the bitstring CASES_SEEN (which has length COUNT),
4950 with the case values we have seen, assuming the case expression
4952 SPARSENESS is as determined by all_cases_count.
4954 The time needed is proportional to COUNT, unless
4955 SPARSENESS is 2, in which case quadratic time is needed. */
4958 mark_seen_cases (tree type
, unsigned char *cases_seen
, HOST_WIDE_INT count
,
4961 tree next_node_to_try
= NULL_TREE
;
4962 HOST_WIDE_INT next_node_offset
= 0;
4964 struct case_node
*n
, *root
= case_stack
->data
.case_stmt
.case_list
;
4965 tree val
= make_node (INTEGER_CST
);
4967 TREE_TYPE (val
) = type
;
4971 else if (sparseness
== 2)
4974 unsigned HOST_WIDE_INT xlo
;
4976 /* This less efficient loop is only needed to handle
4977 duplicate case values (multiple enum constants
4978 with the same value). */
4979 TREE_TYPE (val
) = TREE_TYPE (root
->low
);
4980 for (t
= TYPE_VALUES (type
), xlo
= 0; t
!= NULL_TREE
;
4981 t
= TREE_CHAIN (t
), xlo
++)
4983 TREE_INT_CST_LOW (val
) = TREE_INT_CST_LOW (TREE_VALUE (t
));
4984 TREE_INT_CST_HIGH (val
) = TREE_INT_CST_HIGH (TREE_VALUE (t
));
4988 /* Keep going past elements distinctly greater than VAL. */
4989 if (tree_int_cst_lt (val
, n
->low
))
4992 /* or distinctly less than VAL. */
4993 else if (tree_int_cst_lt (n
->high
, val
))
4998 /* We have found a matching range. */
4999 BITARRAY_SET (cases_seen
, xlo
);
5009 case_stack
->data
.case_stmt
.case_list
= root
= case_tree2list (root
, 0);
5011 for (n
= root
; n
; n
= n
->right
)
5013 TREE_INT_CST_LOW (val
) = TREE_INT_CST_LOW (n
->low
);
5014 TREE_INT_CST_HIGH (val
) = TREE_INT_CST_HIGH (n
->low
);
5015 while (! tree_int_cst_lt (n
->high
, val
))
5017 /* Calculate (into xlo) the "offset" of the integer (val).
5018 The element with lowest value has offset 0, the next smallest
5019 element has offset 1, etc. */
5021 unsigned HOST_WIDE_INT xlo
;
5025 if (sparseness
&& TYPE_VALUES (type
) != NULL_TREE
)
5027 /* The TYPE_VALUES will be in increasing order, so
5028 starting searching where we last ended. */
5029 t
= next_node_to_try
;
5030 xlo
= next_node_offset
;
5036 t
= TYPE_VALUES (type
);
5039 if (tree_int_cst_equal (val
, TREE_VALUE (t
)))
5041 next_node_to_try
= TREE_CHAIN (t
);
5042 next_node_offset
= xlo
+ 1;
5047 if (t
== next_node_to_try
)
5056 t
= TYPE_MIN_VALUE (type
);
5058 neg_double (TREE_INT_CST_LOW (t
), TREE_INT_CST_HIGH (t
),
5062 add_double (xlo
, xhi
,
5063 TREE_INT_CST_LOW (val
), TREE_INT_CST_HIGH (val
),
5067 if (xhi
== 0 && xlo
< (unsigned HOST_WIDE_INT
) count
)
5068 BITARRAY_SET (cases_seen
, xlo
);
5070 add_double (TREE_INT_CST_LOW (val
), TREE_INT_CST_HIGH (val
),
5072 &TREE_INT_CST_LOW (val
), &TREE_INT_CST_HIGH (val
));
5078 /* Given a switch statement with an expression that is an enumeration
5079 type, warn if any of the enumeration type's literals are not
5080 covered by the case expressions of the switch. Also, warn if there
5081 are any extra switch cases that are *not* elements of the
5086 At one stage this function would: ``If all enumeration literals
5087 were covered by the case expressions, turn one of the expressions
5088 into the default expression since it should not be possible to fall
5089 through such a switch.''
5091 That code has since been removed as: ``This optimization is
5092 disabled because it causes valid programs to fail. ANSI C does not
5093 guarantee that an expression with enum type will have a value that
5094 is the same as one of the enumeration literals.'' */
5097 check_for_full_enumeration_handling (tree type
)
5099 struct case_node
*n
;
5102 /* True iff the selector type is a numbered set mode. */
5105 /* The number of possible selector values. */
5108 /* For each possible selector value. a one iff it has been matched
5109 by a case value alternative. */
5110 unsigned char *cases_seen
;
5112 /* The allocated size of cases_seen, in chars. */
5113 HOST_WIDE_INT bytes_needed
;
5115 size
= all_cases_count (type
, &sparseness
);
5116 bytes_needed
= (size
+ HOST_BITS_PER_CHAR
) / HOST_BITS_PER_CHAR
;
5118 if (size
> 0 && size
< 600000
5119 /* We deliberately use calloc here, not cmalloc, so that we can suppress
5120 this optimization if we don't have enough memory rather than
5121 aborting, as xmalloc would do. */
5122 && (cases_seen
= really_call_calloc (bytes_needed
, 1)) != NULL
)
5125 tree v
= TYPE_VALUES (type
);
5127 /* The time complexity of this code is normally O(N), where
5128 N being the number of members in the enumerated type.
5129 However, if type is an ENUMERAL_TYPE whose values do not
5130 increase monotonically, O(N*log(N)) time may be needed. */
5132 mark_seen_cases (type
, cases_seen
, size
, sparseness
);
5134 for (i
= 0; v
!= NULL_TREE
&& i
< size
; i
++, v
= TREE_CHAIN (v
))
5135 if (BITARRAY_TEST (cases_seen
, i
) == 0)
5136 warning ("enumeration value `%s' not handled in switch",
5137 IDENTIFIER_POINTER (TREE_PURPOSE (v
)));
5142 /* Now we go the other way around; we warn if there are case
5143 expressions that don't correspond to enumerators. This can
5144 occur since C and C++ don't enforce type-checking of
5145 assignments to enumeration variables. */
5147 if (case_stack
->data
.case_stmt
.case_list
5148 && case_stack
->data
.case_stmt
.case_list
->left
)
5149 case_stack
->data
.case_stmt
.case_list
5150 = case_tree2list (case_stack
->data
.case_stmt
.case_list
, 0);
5151 for (n
= case_stack
->data
.case_stmt
.case_list
; n
; n
= n
->right
)
5153 for (chain
= TYPE_VALUES (type
);
5154 chain
&& !tree_int_cst_equal (n
->low
, TREE_VALUE (chain
));
5155 chain
= TREE_CHAIN (chain
))
5160 if (TYPE_NAME (type
) == 0)
5161 warning ("case value `%ld' not in enumerated type",
5162 (long) TREE_INT_CST_LOW (n
->low
));
5164 warning ("case value `%ld' not in enumerated type `%s'",
5165 (long) TREE_INT_CST_LOW (n
->low
),
5166 IDENTIFIER_POINTER ((TREE_CODE (TYPE_NAME (type
))
5169 : DECL_NAME (TYPE_NAME (type
))));
5171 if (!tree_int_cst_equal (n
->low
, n
->high
))
5173 for (chain
= TYPE_VALUES (type
);
5174 chain
&& !tree_int_cst_equal (n
->high
, TREE_VALUE (chain
));
5175 chain
= TREE_CHAIN (chain
))
5180 if (TYPE_NAME (type
) == 0)
5181 warning ("case value `%ld' not in enumerated type",
5182 (long) TREE_INT_CST_LOW (n
->high
));
5184 warning ("case value `%ld' not in enumerated type `%s'",
5185 (long) TREE_INT_CST_LOW (n
->high
),
5186 IDENTIFIER_POINTER ((TREE_CODE (TYPE_NAME (type
))
5189 : DECL_NAME (TYPE_NAME (type
))));
5196 /* Maximum number of case bit tests. */
5197 #define MAX_CASE_BIT_TESTS 3
5199 /* By default, enable case bit tests on targets with ashlsi3. */
5200 #ifndef CASE_USE_BIT_TESTS
5201 #define CASE_USE_BIT_TESTS (ashl_optab->handlers[word_mode].insn_code \
5202 != CODE_FOR_nothing)
5206 /* A case_bit_test represents a set of case nodes that may be
5207 selected from using a bit-wise comparison. HI and LO hold
5208 the integer to be tested against, LABEL contains the label
5209 to jump to upon success and BITS counts the number of case
5210 nodes handled by this test, typically the number of bits
5213 struct case_bit_test
5221 /* Determine whether "1 << x" is relatively cheap in word_mode. */
5224 bool lshift_cheap_p (void)
5226 static bool init
= false;
5227 static bool cheap
= true;
5231 rtx reg
= gen_rtx_REG (word_mode
, 10000);
5232 int cost
= rtx_cost (gen_rtx_ASHIFT (word_mode
, const1_rtx
, reg
), SET
);
5233 cheap
= cost
< COSTS_N_INSNS (3);
5240 /* Comparison function for qsort to order bit tests by decreasing
5241 number of case nodes, i.e. the node with the most cases gets
5245 int case_bit_test_cmp (const void *p1
, const void *p2
)
5247 const struct case_bit_test
*d1
= p1
;
5248 const struct case_bit_test
*d2
= p2
;
5250 return d2
->bits
- d1
->bits
;
5253 /* Expand a switch statement by a short sequence of bit-wise
5254 comparisons. "switch(x)" is effectively converted into
5255 "if ((1 << (x-MINVAL)) & CST)" where CST and MINVAL are
5258 INDEX_EXPR is the value being switched on, which is of
5259 type INDEX_TYPE. MINVAL is the lowest case value of in
5260 the case nodes, of INDEX_TYPE type, and RANGE is highest
5261 value minus MINVAL, also of type INDEX_TYPE. NODES is
5262 the set of case nodes, and DEFAULT_LABEL is the label to
5263 branch to should none of the cases match.
5265 There *MUST* be MAX_CASE_BIT_TESTS or less unique case
5269 emit_case_bit_tests (tree index_type
, tree index_expr
, tree minval
,
5270 tree range
, case_node_ptr nodes
, rtx default_label
)
5272 struct case_bit_test test
[MAX_CASE_BIT_TESTS
];
5273 enum machine_mode mode
;
5274 rtx expr
, index
, label
;
5275 unsigned int i
,j
,lo
,hi
;
5276 struct case_node
*n
;
5280 for (n
= nodes
; n
; n
= n
->right
)
5282 label
= label_rtx (n
->code_label
);
5283 for (i
= 0; i
< count
; i
++)
5284 if (same_case_target_p (label
, test
[i
].label
))
5289 if (count
>= MAX_CASE_BIT_TESTS
)
5293 test
[i
].label
= label
;
5300 lo
= tree_low_cst (fold (build (MINUS_EXPR
, index_type
,
5301 n
->low
, minval
)), 1);
5302 hi
= tree_low_cst (fold (build (MINUS_EXPR
, index_type
,
5303 n
->high
, minval
)), 1);
5304 for (j
= lo
; j
<= hi
; j
++)
5305 if (j
>= HOST_BITS_PER_WIDE_INT
)
5306 test
[i
].hi
|= (HOST_WIDE_INT
) 1 << (j
- HOST_BITS_PER_INT
);
5308 test
[i
].lo
|= (HOST_WIDE_INT
) 1 << j
;
5311 qsort (test
, count
, sizeof(*test
), case_bit_test_cmp
);
5313 index_expr
= fold (build (MINUS_EXPR
, index_type
,
5314 convert (index_type
, index_expr
),
5315 convert (index_type
, minval
)));
5316 index
= expand_expr (index_expr
, NULL_RTX
, VOIDmode
, 0);
5318 index
= protect_from_queue (index
, 0);
5319 do_pending_stack_adjust ();
5321 mode
= TYPE_MODE (index_type
);
5322 expr
= expand_expr (range
, NULL_RTX
, VOIDmode
, 0);
5323 emit_cmp_and_jump_insns (index
, expr
, GTU
, NULL_RTX
, mode
, 1,
5326 index
= convert_to_mode (word_mode
, index
, 0);
5327 index
= expand_binop (word_mode
, ashl_optab
, const1_rtx
,
5328 index
, NULL_RTX
, 1, OPTAB_WIDEN
);
5330 for (i
= 0; i
< count
; i
++)
5332 expr
= immed_double_const (test
[i
].lo
, test
[i
].hi
, word_mode
);
5333 expr
= expand_binop (word_mode
, and_optab
, index
, expr
,
5334 NULL_RTX
, 1, OPTAB_WIDEN
);
5335 emit_cmp_and_jump_insns (expr
, const0_rtx
, NE
, NULL_RTX
,
5336 word_mode
, 1, test
[i
].label
);
5339 emit_jump (default_label
);
5342 /* Terminate a case (Pascal) or switch (C) statement
5343 in which ORIG_INDEX is the expression to be tested.
5344 If ORIG_TYPE is not NULL, it is the original ORIG_INDEX
5345 type as given in the source before any compiler conversions.
5346 Generate the code to test it and jump to the right place. */
5349 expand_end_case_type (tree orig_index
, tree orig_type
)
5351 tree minval
= NULL_TREE
, maxval
= NULL_TREE
, range
= NULL_TREE
;
5352 rtx default_label
= 0;
5353 struct case_node
*n
, *m
;
5354 unsigned int count
, uniq
;
5360 rtx before_case
, end
, lab
;
5361 struct nesting
*thiscase
= case_stack
;
5362 tree index_expr
, index_type
;
5363 bool exit_done
= false;
5366 /* Don't crash due to previous errors. */
5367 if (thiscase
== NULL
)
5370 index_expr
= thiscase
->data
.case_stmt
.index_expr
;
5371 index_type
= TREE_TYPE (index_expr
);
5372 unsignedp
= TREE_UNSIGNED (index_type
);
5373 if (orig_type
== NULL
)
5374 orig_type
= TREE_TYPE (orig_index
);
5376 do_pending_stack_adjust ();
5378 /* This might get a spurious warning in the presence of a syntax error;
5379 it could be fixed by moving the call to check_seenlabel after the
5380 check for error_mark_node, and copying the code of check_seenlabel that
5381 deals with case_stack->data.case_stmt.line_number_status /
5382 restore_line_number_status in front of the call to end_cleanup_deferral;
5383 However, this might miss some useful warnings in the presence of
5384 non-syntax errors. */
5387 /* An ERROR_MARK occurs for various reasons including invalid data type. */
5388 if (index_type
!= error_mark_node
)
5390 /* If the switch expression was an enumerated type, check that
5391 exactly all enumeration literals are covered by the cases.
5392 The check is made when -Wswitch was specified and there is no
5393 default case, or when -Wswitch-enum was specified. */
5394 if (((warn_switch
&& !thiscase
->data
.case_stmt
.default_label
)
5395 || warn_switch_enum
)
5396 && TREE_CODE (orig_type
) == ENUMERAL_TYPE
5397 && TREE_CODE (index_expr
) != INTEGER_CST
)
5398 check_for_full_enumeration_handling (orig_type
);
5400 if (warn_switch_default
&& !thiscase
->data
.case_stmt
.default_label
)
5401 warning ("switch missing default case");
5403 /* If we don't have a default-label, create one here,
5404 after the body of the switch. */
5405 if (thiscase
->data
.case_stmt
.default_label
== 0)
5407 thiscase
->data
.case_stmt
.default_label
5408 = build_decl (LABEL_DECL
, NULL_TREE
, NULL_TREE
);
5409 /* Share the exit label if possible. */
5410 if (thiscase
->exit_label
)
5412 SET_DECL_RTL (thiscase
->data
.case_stmt
.default_label
,
5413 thiscase
->exit_label
);
5416 expand_label (thiscase
->data
.case_stmt
.default_label
);
5418 default_label
= label_rtx (thiscase
->data
.case_stmt
.default_label
);
5420 before_case
= get_last_insn ();
5422 if (thiscase
->data
.case_stmt
.case_list
5423 && thiscase
->data
.case_stmt
.case_list
->left
)
5424 thiscase
->data
.case_stmt
.case_list
5425 = case_tree2list (thiscase
->data
.case_stmt
.case_list
, 0);
5427 /* Simplify the case-list before we count it. */
5428 group_case_nodes (thiscase
->data
.case_stmt
.case_list
);
5429 strip_default_case_nodes (&thiscase
->data
.case_stmt
.case_list
,
5432 /* Get upper and lower bounds of case values.
5433 Also convert all the case values to the index expr's data type. */
5437 for (n
= thiscase
->data
.case_stmt
.case_list
; n
; n
= n
->right
)
5439 /* Check low and high label values are integers. */
5440 if (TREE_CODE (n
->low
) != INTEGER_CST
)
5442 if (TREE_CODE (n
->high
) != INTEGER_CST
)
5445 n
->low
= convert (index_type
, n
->low
);
5446 n
->high
= convert (index_type
, n
->high
);
5448 /* Count the elements and track the largest and smallest
5449 of them (treating them as signed even if they are not). */
5457 if (INT_CST_LT (n
->low
, minval
))
5459 if (INT_CST_LT (maxval
, n
->high
))
5462 /* A range counts double, since it requires two compares. */
5463 if (! tree_int_cst_equal (n
->low
, n
->high
))
5466 /* Count the number of unique case node targets. */
5468 lab
= label_rtx (n
->code_label
);
5469 for (m
= thiscase
->data
.case_stmt
.case_list
; m
!= n
; m
= m
->right
)
5470 if (same_case_target_p (label_rtx (m
->code_label
), lab
))
5477 /* Compute span of values. */
5479 range
= fold (build (MINUS_EXPR
, index_type
, maxval
, minval
));
5481 end_cleanup_deferral ();
5485 expand_expr (index_expr
, const0_rtx
, VOIDmode
, 0);
5487 emit_jump (default_label
);
5490 /* Try implementing this switch statement by a short sequence of
5491 bit-wise comparisons. However, we let the binary-tree case
5492 below handle constant index expressions. */
5493 else if (CASE_USE_BIT_TESTS
5494 && ! TREE_CONSTANT (index_expr
)
5495 && compare_tree_int (range
, GET_MODE_BITSIZE (word_mode
)) < 0
5496 && compare_tree_int (range
, 0) > 0
5497 && lshift_cheap_p ()
5498 && ((uniq
== 1 && count
>= 3)
5499 || (uniq
== 2 && count
>= 5)
5500 || (uniq
== 3 && count
>= 6)))
5502 /* Optimize the case where all the case values fit in a
5503 word without having to subtract MINVAL. In this case,
5504 we can optimize away the subtraction. */
5505 if (compare_tree_int (minval
, 0) > 0
5506 && compare_tree_int (maxval
, GET_MODE_BITSIZE (word_mode
)) < 0)
5508 minval
= integer_zero_node
;
5511 emit_case_bit_tests (index_type
, index_expr
, minval
, range
,
5512 thiscase
->data
.case_stmt
.case_list
,
5516 /* If range of values is much bigger than number of values,
5517 make a sequence of conditional branches instead of a dispatch.
5518 If the switch-index is a constant, do it this way
5519 because we can optimize it. */
5521 else if (count
< case_values_threshold ()
5522 || compare_tree_int (range
,
5523 (optimize_size
? 3 : 10) * count
) > 0
5524 /* RANGE may be signed, and really large ranges will show up
5525 as negative numbers. */
5526 || compare_tree_int (range
, 0) < 0
5527 #ifndef ASM_OUTPUT_ADDR_DIFF_ELT
5530 || TREE_CONSTANT (index_expr
))
5532 index
= expand_expr (index_expr
, NULL_RTX
, VOIDmode
, 0);
5534 /* If the index is a short or char that we do not have
5535 an insn to handle comparisons directly, convert it to
5536 a full integer now, rather than letting each comparison
5537 generate the conversion. */
5539 if (GET_MODE_CLASS (GET_MODE (index
)) == MODE_INT
5540 && ! have_insn_for (COMPARE
, GET_MODE (index
)))
5542 enum machine_mode wider_mode
;
5543 for (wider_mode
= GET_MODE (index
); wider_mode
!= VOIDmode
;
5544 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
5545 if (have_insn_for (COMPARE
, wider_mode
))
5547 index
= convert_to_mode (wider_mode
, index
, unsignedp
);
5553 do_pending_stack_adjust ();
5555 index
= protect_from_queue (index
, 0);
5556 if (GET_CODE (index
) == MEM
)
5557 index
= copy_to_reg (index
);
5558 if (GET_CODE (index
) == CONST_INT
5559 || TREE_CODE (index_expr
) == INTEGER_CST
)
5561 /* Make a tree node with the proper constant value
5562 if we don't already have one. */
5563 if (TREE_CODE (index_expr
) != INTEGER_CST
)
5566 = build_int_2 (INTVAL (index
),
5567 unsignedp
|| INTVAL (index
) >= 0 ? 0 : -1);
5568 index_expr
= convert (index_type
, index_expr
);
5571 /* For constant index expressions we need only
5572 issue an unconditional branch to the appropriate
5573 target code. The job of removing any unreachable
5574 code is left to the optimization phase if the
5575 "-O" option is specified. */
5576 for (n
= thiscase
->data
.case_stmt
.case_list
; n
; n
= n
->right
)
5577 if (! tree_int_cst_lt (index_expr
, n
->low
)
5578 && ! tree_int_cst_lt (n
->high
, index_expr
))
5582 emit_jump (label_rtx (n
->code_label
));
5584 emit_jump (default_label
);
5588 /* If the index expression is not constant we generate
5589 a binary decision tree to select the appropriate
5590 target code. This is done as follows:
5592 The list of cases is rearranged into a binary tree,
5593 nearly optimal assuming equal probability for each case.
5595 The tree is transformed into RTL, eliminating
5596 redundant test conditions at the same time.
5598 If program flow could reach the end of the
5599 decision tree an unconditional jump to the
5600 default code is emitted. */
5603 = (TREE_CODE (orig_type
) != ENUMERAL_TYPE
5604 && estimate_case_costs (thiscase
->data
.case_stmt
.case_list
));
5605 balance_case_nodes (&thiscase
->data
.case_stmt
.case_list
, NULL
);
5606 emit_case_nodes (index
, thiscase
->data
.case_stmt
.case_list
,
5607 default_label
, index_type
);
5608 emit_jump_if_reachable (default_label
);
5613 table_label
= gen_label_rtx ();
5614 if (! try_casesi (index_type
, index_expr
, minval
, range
,
5615 table_label
, default_label
))
5617 index_type
= thiscase
->data
.case_stmt
.nominal_type
;
5619 /* Index jumptables from zero for suitable values of
5620 minval to avoid a subtraction. */
5622 && compare_tree_int (minval
, 0) > 0
5623 && compare_tree_int (minval
, 3) < 0)
5625 minval
= integer_zero_node
;
5629 if (! try_tablejump (index_type
, index_expr
, minval
, range
,
5630 table_label
, default_label
))
5634 /* Get table of labels to jump to, in order of case index. */
5636 ncases
= tree_low_cst (range
, 0) + 1;
5637 labelvec
= alloca (ncases
* sizeof (rtx
));
5638 memset (labelvec
, 0, ncases
* sizeof (rtx
));
5640 for (n
= thiscase
->data
.case_stmt
.case_list
; n
; n
= n
->right
)
5642 /* Compute the low and high bounds relative to the minimum
5643 value since that should fit in a HOST_WIDE_INT while the
5644 actual values may not. */
5646 = tree_low_cst (fold (build (MINUS_EXPR
, index_type
,
5647 n
->low
, minval
)), 1);
5648 HOST_WIDE_INT i_high
5649 = tree_low_cst (fold (build (MINUS_EXPR
, index_type
,
5650 n
->high
, minval
)), 1);
5653 for (i
= i_low
; i
<= i_high
; i
++)
5655 = gen_rtx_LABEL_REF (Pmode
, label_rtx (n
->code_label
));
5658 /* Fill in the gaps with the default. */
5659 for (i
= 0; i
< ncases
; i
++)
5660 if (labelvec
[i
] == 0)
5661 labelvec
[i
] = gen_rtx_LABEL_REF (Pmode
, default_label
);
5663 /* Output the table. */
5664 emit_label (table_label
);
5666 if (CASE_VECTOR_PC_RELATIVE
|| flag_pic
)
5667 emit_jump_insn (gen_rtx_ADDR_DIFF_VEC (CASE_VECTOR_MODE
,
5668 gen_rtx_LABEL_REF (Pmode
, table_label
),
5669 gen_rtvec_v (ncases
, labelvec
),
5670 const0_rtx
, const0_rtx
));
5672 emit_jump_insn (gen_rtx_ADDR_VEC (CASE_VECTOR_MODE
,
5673 gen_rtvec_v (ncases
, labelvec
)));
5675 /* If the case insn drops through the table,
5676 after the table we must jump to the default-label.
5677 Otherwise record no drop-through after the table. */
5678 #ifdef CASE_DROPS_THROUGH
5679 emit_jump (default_label
);
5685 before_case
= NEXT_INSN (before_case
);
5686 end
= get_last_insn ();
5687 if (squeeze_notes (&before_case
, &end
))
5689 reorder_insns (before_case
, end
,
5690 thiscase
->data
.case_stmt
.start
);
5693 end_cleanup_deferral ();
5695 if (thiscase
->exit_label
&& !exit_done
)
5696 emit_label (thiscase
->exit_label
);
5698 POPSTACK (case_stack
);
5703 /* Convert the tree NODE into a list linked by the right field, with the left
5704 field zeroed. RIGHT is used for recursion; it is a list to be placed
5705 rightmost in the resulting list. */
5707 static struct case_node
*
5708 case_tree2list (struct case_node
*node
, struct case_node
*right
)
5710 struct case_node
*left
;
5713 right
= case_tree2list (node
->right
, right
);
5715 node
->right
= right
;
5716 if ((left
= node
->left
))
5719 return case_tree2list (left
, node
);
5725 /* Generate code to jump to LABEL if OP1 and OP2 are equal. */
5728 do_jump_if_equal (rtx op1
, rtx op2
, rtx label
, int unsignedp
)
5730 if (GET_CODE (op1
) == CONST_INT
&& GET_CODE (op2
) == CONST_INT
)
5736 emit_cmp_and_jump_insns (op1
, op2
, EQ
, NULL_RTX
,
5737 (GET_MODE (op1
) == VOIDmode
5738 ? GET_MODE (op2
) : GET_MODE (op1
)),
5742 /* Not all case values are encountered equally. This function
5743 uses a heuristic to weight case labels, in cases where that
5744 looks like a reasonable thing to do.
5746 Right now, all we try to guess is text, and we establish the
5749 chars above space: 16
5758 If we find any cases in the switch that are not either -1 or in the range
5759 of valid ASCII characters, or are control characters other than those
5760 commonly used with "\", don't treat this switch scanning text.
5762 Return 1 if these nodes are suitable for cost estimation, otherwise
5766 estimate_case_costs (case_node_ptr node
)
5768 tree min_ascii
= integer_minus_one_node
;
5769 tree max_ascii
= convert (TREE_TYPE (node
->high
), build_int_2 (127, 0));
5773 /* If we haven't already made the cost table, make it now. Note that the
5774 lower bound of the table is -1, not zero. */
5776 if (! cost_table_initialized
)
5778 cost_table_initialized
= 1;
5780 for (i
= 0; i
< 128; i
++)
5783 COST_TABLE (i
) = 16;
5784 else if (ISPUNCT (i
))
5786 else if (ISCNTRL (i
))
5787 COST_TABLE (i
) = -1;
5790 COST_TABLE (' ') = 8;
5791 COST_TABLE ('\t') = 4;
5792 COST_TABLE ('\0') = 4;
5793 COST_TABLE ('\n') = 2;
5794 COST_TABLE ('\f') = 1;
5795 COST_TABLE ('\v') = 1;
5796 COST_TABLE ('\b') = 1;
5799 /* See if all the case expressions look like text. It is text if the
5800 constant is >= -1 and the highest constant is <= 127. Do all comparisons
5801 as signed arithmetic since we don't want to ever access cost_table with a
5802 value less than -1. Also check that none of the constants in a range
5803 are strange control characters. */
5805 for (n
= node
; n
; n
= n
->right
)
5807 if ((INT_CST_LT (n
->low
, min_ascii
)) || INT_CST_LT (max_ascii
, n
->high
))
5810 for (i
= (HOST_WIDE_INT
) TREE_INT_CST_LOW (n
->low
);
5811 i
<= (HOST_WIDE_INT
) TREE_INT_CST_LOW (n
->high
); i
++)
5812 if (COST_TABLE (i
) < 0)
5816 /* All interesting values are within the range of interesting
5817 ASCII characters. */
5821 /* Determine whether two case labels branch to the same target. */
5824 same_case_target_p (rtx l1
, rtx l2
)
5831 i1
= next_real_insn (l1
);
5832 i2
= next_real_insn (l2
);
5836 if (i1
&& simplejump_p (i1
))
5838 l1
= XEXP (SET_SRC (PATTERN (i1
)), 0);
5841 if (i2
&& simplejump_p (i2
))
5843 l2
= XEXP (SET_SRC (PATTERN (i2
)), 0);
5848 /* Delete nodes that branch to the default label from a list of
5849 case nodes. Eg. case 5: default: becomes just default: */
5852 strip_default_case_nodes (case_node_ptr
*prev
, rtx deflab
)
5859 if (same_case_target_p (label_rtx (ptr
->code_label
), deflab
))
5866 /* Scan an ordered list of case nodes
5867 combining those with consecutive values or ranges.
5869 Eg. three separate entries 1: 2: 3: become one entry 1..3: */
5872 group_case_nodes (case_node_ptr head
)
5874 case_node_ptr node
= head
;
5878 rtx lab
= label_rtx (node
->code_label
);
5879 case_node_ptr np
= node
;
5881 /* Try to group the successors of NODE with NODE. */
5882 while (((np
= np
->right
) != 0)
5883 /* Do they jump to the same place? */
5884 && same_case_target_p (label_rtx (np
->code_label
), lab
)
5885 /* Are their ranges consecutive? */
5886 && tree_int_cst_equal (np
->low
,
5887 fold (build (PLUS_EXPR
,
5888 TREE_TYPE (node
->high
),
5891 /* An overflow is not consecutive. */
5892 && tree_int_cst_lt (node
->high
,
5893 fold (build (PLUS_EXPR
,
5894 TREE_TYPE (node
->high
),
5896 integer_one_node
))))
5898 node
->high
= np
->high
;
5900 /* NP is the first node after NODE which can't be grouped with it.
5901 Delete the nodes in between, and move on to that node. */
5907 /* Take an ordered list of case nodes
5908 and transform them into a near optimal binary tree,
5909 on the assumption that any target code selection value is as
5910 likely as any other.
5912 The transformation is performed by splitting the ordered
5913 list into two equal sections plus a pivot. The parts are
5914 then attached to the pivot as left and right branches. Each
5915 branch is then transformed recursively. */
5918 balance_case_nodes (case_node_ptr
*head
, case_node_ptr parent
)
5931 /* Count the number of entries on branch. Also count the ranges. */
5935 if (!tree_int_cst_equal (np
->low
, np
->high
))
5939 cost
+= COST_TABLE (TREE_INT_CST_LOW (np
->high
));
5943 cost
+= COST_TABLE (TREE_INT_CST_LOW (np
->low
));
5951 /* Split this list if it is long enough for that to help. */
5956 /* Find the place in the list that bisects the list's total cost,
5957 Here I gets half the total cost. */
5962 /* Skip nodes while their cost does not reach that amount. */
5963 if (!tree_int_cst_equal ((*npp
)->low
, (*npp
)->high
))
5964 i
-= COST_TABLE (TREE_INT_CST_LOW ((*npp
)->high
));
5965 i
-= COST_TABLE (TREE_INT_CST_LOW ((*npp
)->low
));
5968 npp
= &(*npp
)->right
;
5973 /* Leave this branch lopsided, but optimize left-hand
5974 side and fill in `parent' fields for right-hand side. */
5976 np
->parent
= parent
;
5977 balance_case_nodes (&np
->left
, np
);
5978 for (; np
->right
; np
= np
->right
)
5979 np
->right
->parent
= np
;
5983 /* If there are just three nodes, split at the middle one. */
5985 npp
= &(*npp
)->right
;
5988 /* Find the place in the list that bisects the list's total cost,
5989 where ranges count as 2.
5990 Here I gets half the total cost. */
5991 i
= (i
+ ranges
+ 1) / 2;
5994 /* Skip nodes while their cost does not reach that amount. */
5995 if (!tree_int_cst_equal ((*npp
)->low
, (*npp
)->high
))
6000 npp
= &(*npp
)->right
;
6005 np
->parent
= parent
;
6008 /* Optimize each of the two split parts. */
6009 balance_case_nodes (&np
->left
, np
);
6010 balance_case_nodes (&np
->right
, np
);
6014 /* Else leave this branch as one level,
6015 but fill in `parent' fields. */
6017 np
->parent
= parent
;
6018 for (; np
->right
; np
= np
->right
)
6019 np
->right
->parent
= np
;
6024 /* Search the parent sections of the case node tree
6025 to see if a test for the lower bound of NODE would be redundant.
6026 INDEX_TYPE is the type of the index expression.
6028 The instructions to generate the case decision tree are
6029 output in the same order as nodes are processed so it is
6030 known that if a parent node checks the range of the current
6031 node minus one that the current node is bounded at its lower
6032 span. Thus the test would be redundant. */
6035 node_has_low_bound (case_node_ptr node
, tree index_type
)
6038 case_node_ptr pnode
;
6040 /* If the lower bound of this node is the lowest value in the index type,
6041 we need not test it. */
6043 if (tree_int_cst_equal (node
->low
, TYPE_MIN_VALUE (index_type
)))
6046 /* If this node has a left branch, the value at the left must be less
6047 than that at this node, so it cannot be bounded at the bottom and
6048 we need not bother testing any further. */
6053 low_minus_one
= fold (build (MINUS_EXPR
, TREE_TYPE (node
->low
),
6054 node
->low
, integer_one_node
));
6056 /* If the subtraction above overflowed, we can't verify anything.
6057 Otherwise, look for a parent that tests our value - 1. */
6059 if (! tree_int_cst_lt (low_minus_one
, node
->low
))
6062 for (pnode
= node
->parent
; pnode
; pnode
= pnode
->parent
)
6063 if (tree_int_cst_equal (low_minus_one
, pnode
->high
))
6069 /* Search the parent sections of the case node tree
6070 to see if a test for the upper bound of NODE would be redundant.
6071 INDEX_TYPE is the type of the index expression.
6073 The instructions to generate the case decision tree are
6074 output in the same order as nodes are processed so it is
6075 known that if a parent node checks the range of the current
6076 node plus one that the current node is bounded at its upper
6077 span. Thus the test would be redundant. */
6080 node_has_high_bound (case_node_ptr node
, tree index_type
)
6083 case_node_ptr pnode
;
6085 /* If there is no upper bound, obviously no test is needed. */
6087 if (TYPE_MAX_VALUE (index_type
) == NULL
)
6090 /* If the upper bound of this node is the highest value in the type
6091 of the index expression, we need not test against it. */
6093 if (tree_int_cst_equal (node
->high
, TYPE_MAX_VALUE (index_type
)))
6096 /* If this node has a right branch, the value at the right must be greater
6097 than that at this node, so it cannot be bounded at the top and
6098 we need not bother testing any further. */
6103 high_plus_one
= fold (build (PLUS_EXPR
, TREE_TYPE (node
->high
),
6104 node
->high
, integer_one_node
));
6106 /* If the addition above overflowed, we can't verify anything.
6107 Otherwise, look for a parent that tests our value + 1. */
6109 if (! tree_int_cst_lt (node
->high
, high_plus_one
))
6112 for (pnode
= node
->parent
; pnode
; pnode
= pnode
->parent
)
6113 if (tree_int_cst_equal (high_plus_one
, pnode
->low
))
6119 /* Search the parent sections of the
6120 case node tree to see if both tests for the upper and lower
6121 bounds of NODE would be redundant. */
6124 node_is_bounded (case_node_ptr node
, tree index_type
)
6126 return (node_has_low_bound (node
, index_type
)
6127 && node_has_high_bound (node
, index_type
));
6130 /* Emit an unconditional jump to LABEL unless it would be dead code. */
6133 emit_jump_if_reachable (rtx label
)
6135 if (GET_CODE (get_last_insn ()) != BARRIER
)
6139 /* Emit step-by-step code to select a case for the value of INDEX.
6140 The thus generated decision tree follows the form of the
6141 case-node binary tree NODE, whose nodes represent test conditions.
6142 INDEX_TYPE is the type of the index of the switch.
6144 Care is taken to prune redundant tests from the decision tree
6145 by detecting any boundary conditions already checked by
6146 emitted rtx. (See node_has_high_bound, node_has_low_bound
6147 and node_is_bounded, above.)
6149 Where the test conditions can be shown to be redundant we emit
6150 an unconditional jump to the target code. As a further
6151 optimization, the subordinates of a tree node are examined to
6152 check for bounded nodes. In this case conditional and/or
6153 unconditional jumps as a result of the boundary check for the
6154 current node are arranged to target the subordinates associated
6155 code for out of bound conditions on the current node.
6157 We can assume that when control reaches the code generated here,
6158 the index value has already been compared with the parents
6159 of this node, and determined to be on the same side of each parent
6160 as this node is. Thus, if this node tests for the value 51,
6161 and a parent tested for 52, we don't need to consider
6162 the possibility of a value greater than 51. If another parent
6163 tests for the value 50, then this node need not test anything. */
6166 emit_case_nodes (rtx index
, case_node_ptr node
, rtx default_label
,
6169 /* If INDEX has an unsigned type, we must make unsigned branches. */
6170 int unsignedp
= TREE_UNSIGNED (index_type
);
6171 enum machine_mode mode
= GET_MODE (index
);
6172 enum machine_mode imode
= TYPE_MODE (index_type
);
6174 /* See if our parents have already tested everything for us.
6175 If they have, emit an unconditional jump for this node. */
6176 if (node_is_bounded (node
, index_type
))
6177 emit_jump (label_rtx (node
->code_label
));
6179 else if (tree_int_cst_equal (node
->low
, node
->high
))
6181 /* Node is single valued. First see if the index expression matches
6182 this node and then check our children, if any. */
6184 do_jump_if_equal (index
,
6185 convert_modes (mode
, imode
,
6186 expand_expr (node
->low
, NULL_RTX
,
6189 label_rtx (node
->code_label
), unsignedp
);
6191 if (node
->right
!= 0 && node
->left
!= 0)
6193 /* This node has children on both sides.
6194 Dispatch to one side or the other
6195 by comparing the index value with this node's value.
6196 If one subtree is bounded, check that one first,
6197 so we can avoid real branches in the tree. */
6199 if (node_is_bounded (node
->right
, index_type
))
6201 emit_cmp_and_jump_insns (index
,
6204 expand_expr (node
->high
, NULL_RTX
,
6207 GT
, NULL_RTX
, mode
, unsignedp
,
6208 label_rtx (node
->right
->code_label
));
6209 emit_case_nodes (index
, node
->left
, default_label
, index_type
);
6212 else if (node_is_bounded (node
->left
, index_type
))
6214 emit_cmp_and_jump_insns (index
,
6217 expand_expr (node
->high
, NULL_RTX
,
6220 LT
, NULL_RTX
, mode
, unsignedp
,
6221 label_rtx (node
->left
->code_label
));
6222 emit_case_nodes (index
, node
->right
, default_label
, index_type
);
6227 /* Neither node is bounded. First distinguish the two sides;
6228 then emit the code for one side at a time. */
6230 tree test_label
= build_decl (LABEL_DECL
, NULL_TREE
, NULL_TREE
);
6232 /* See if the value is on the right. */
6233 emit_cmp_and_jump_insns (index
,
6236 expand_expr (node
->high
, NULL_RTX
,
6239 GT
, NULL_RTX
, mode
, unsignedp
,
6240 label_rtx (test_label
));
6242 /* Value must be on the left.
6243 Handle the left-hand subtree. */
6244 emit_case_nodes (index
, node
->left
, default_label
, index_type
);
6245 /* If left-hand subtree does nothing,
6247 emit_jump_if_reachable (default_label
);
6249 /* Code branches here for the right-hand subtree. */
6250 expand_label (test_label
);
6251 emit_case_nodes (index
, node
->right
, default_label
, index_type
);
6255 else if (node
->right
!= 0 && node
->left
== 0)
6257 /* Here we have a right child but no left so we issue conditional
6258 branch to default and process the right child.
6260 Omit the conditional branch to default if we it avoid only one
6261 right child; it costs too much space to save so little time. */
6263 if (node
->right
->right
|| node
->right
->left
6264 || !tree_int_cst_equal (node
->right
->low
, node
->right
->high
))
6266 if (!node_has_low_bound (node
, index_type
))
6268 emit_cmp_and_jump_insns (index
,
6271 expand_expr (node
->high
, NULL_RTX
,
6274 LT
, NULL_RTX
, mode
, unsignedp
,
6278 emit_case_nodes (index
, node
->right
, default_label
, index_type
);
6281 /* We cannot process node->right normally
6282 since we haven't ruled out the numbers less than
6283 this node's value. So handle node->right explicitly. */
6284 do_jump_if_equal (index
,
6287 expand_expr (node
->right
->low
, NULL_RTX
,
6290 label_rtx (node
->right
->code_label
), unsignedp
);
6293 else if (node
->right
== 0 && node
->left
!= 0)
6295 /* Just one subtree, on the left. */
6296 if (node
->left
->left
|| node
->left
->right
6297 || !tree_int_cst_equal (node
->left
->low
, node
->left
->high
))
6299 if (!node_has_high_bound (node
, index_type
))
6301 emit_cmp_and_jump_insns (index
,
6304 expand_expr (node
->high
, NULL_RTX
,
6307 GT
, NULL_RTX
, mode
, unsignedp
,
6311 emit_case_nodes (index
, node
->left
, default_label
, index_type
);
6314 /* We cannot process node->left normally
6315 since we haven't ruled out the numbers less than
6316 this node's value. So handle node->left explicitly. */
6317 do_jump_if_equal (index
,
6320 expand_expr (node
->left
->low
, NULL_RTX
,
6323 label_rtx (node
->left
->code_label
), unsignedp
);
6328 /* Node is a range. These cases are very similar to those for a single
6329 value, except that we do not start by testing whether this node
6330 is the one to branch to. */
6332 if (node
->right
!= 0 && node
->left
!= 0)
6334 /* Node has subtrees on both sides.
6335 If the right-hand subtree is bounded,
6336 test for it first, since we can go straight there.
6337 Otherwise, we need to make a branch in the control structure,
6338 then handle the two subtrees. */
6339 tree test_label
= 0;
6341 if (node_is_bounded (node
->right
, index_type
))
6342 /* Right hand node is fully bounded so we can eliminate any
6343 testing and branch directly to the target code. */
6344 emit_cmp_and_jump_insns (index
,
6347 expand_expr (node
->high
, NULL_RTX
,
6350 GT
, NULL_RTX
, mode
, unsignedp
,
6351 label_rtx (node
->right
->code_label
));
6354 /* Right hand node requires testing.
6355 Branch to a label where we will handle it later. */
6357 test_label
= build_decl (LABEL_DECL
, NULL_TREE
, NULL_TREE
);
6358 emit_cmp_and_jump_insns (index
,
6361 expand_expr (node
->high
, NULL_RTX
,
6364 GT
, NULL_RTX
, mode
, unsignedp
,
6365 label_rtx (test_label
));
6368 /* Value belongs to this node or to the left-hand subtree. */
6370 emit_cmp_and_jump_insns (index
,
6373 expand_expr (node
->low
, NULL_RTX
,
6376 GE
, NULL_RTX
, mode
, unsignedp
,
6377 label_rtx (node
->code_label
));
6379 /* Handle the left-hand subtree. */
6380 emit_case_nodes (index
, node
->left
, default_label
, index_type
);
6382 /* If right node had to be handled later, do that now. */
6386 /* If the left-hand subtree fell through,
6387 don't let it fall into the right-hand subtree. */
6388 emit_jump_if_reachable (default_label
);
6390 expand_label (test_label
);
6391 emit_case_nodes (index
, node
->right
, default_label
, index_type
);
6395 else if (node
->right
!= 0 && node
->left
== 0)
6397 /* Deal with values to the left of this node,
6398 if they are possible. */
6399 if (!node_has_low_bound (node
, index_type
))
6401 emit_cmp_and_jump_insns (index
,
6404 expand_expr (node
->low
, NULL_RTX
,
6407 LT
, NULL_RTX
, mode
, unsignedp
,
6411 /* Value belongs to this node or to the right-hand subtree. */
6413 emit_cmp_and_jump_insns (index
,
6416 expand_expr (node
->high
, NULL_RTX
,
6419 LE
, NULL_RTX
, mode
, unsignedp
,
6420 label_rtx (node
->code_label
));
6422 emit_case_nodes (index
, node
->right
, default_label
, index_type
);
6425 else if (node
->right
== 0 && node
->left
!= 0)
6427 /* Deal with values to the right of this node,
6428 if they are possible. */
6429 if (!node_has_high_bound (node
, index_type
))
6431 emit_cmp_and_jump_insns (index
,
6434 expand_expr (node
->high
, NULL_RTX
,
6437 GT
, NULL_RTX
, mode
, unsignedp
,
6441 /* Value belongs to this node or to the left-hand subtree. */
6443 emit_cmp_and_jump_insns (index
,
6446 expand_expr (node
->low
, NULL_RTX
,
6449 GE
, NULL_RTX
, mode
, unsignedp
,
6450 label_rtx (node
->code_label
));
6452 emit_case_nodes (index
, node
->left
, default_label
, index_type
);
6457 /* Node has no children so we check low and high bounds to remove
6458 redundant tests. Only one of the bounds can exist,
6459 since otherwise this node is bounded--a case tested already. */
6460 int high_bound
= node_has_high_bound (node
, index_type
);
6461 int low_bound
= node_has_low_bound (node
, index_type
);
6463 if (!high_bound
&& low_bound
)
6465 emit_cmp_and_jump_insns (index
,
6468 expand_expr (node
->high
, NULL_RTX
,
6471 GT
, NULL_RTX
, mode
, unsignedp
,
6475 else if (!low_bound
&& high_bound
)
6477 emit_cmp_and_jump_insns (index
,
6480 expand_expr (node
->low
, NULL_RTX
,
6483 LT
, NULL_RTX
, mode
, unsignedp
,
6486 else if (!low_bound
&& !high_bound
)
6488 /* Widen LOW and HIGH to the same width as INDEX. */
6489 tree type
= (*lang_hooks
.types
.type_for_mode
) (mode
, unsignedp
);
6490 tree low
= build1 (CONVERT_EXPR
, type
, node
->low
);
6491 tree high
= build1 (CONVERT_EXPR
, type
, node
->high
);
6492 rtx low_rtx
, new_index
, new_bound
;
6494 /* Instead of doing two branches, emit one unsigned branch for
6495 (index-low) > (high-low). */
6496 low_rtx
= expand_expr (low
, NULL_RTX
, mode
, 0);
6497 new_index
= expand_simple_binop (mode
, MINUS
, index
, low_rtx
,
6498 NULL_RTX
, unsignedp
,
6500 new_bound
= expand_expr (fold (build (MINUS_EXPR
, type
,
6504 emit_cmp_and_jump_insns (new_index
, new_bound
, GT
, NULL_RTX
,
6505 mode
, 1, default_label
);
6508 emit_jump (label_rtx (node
->code_label
));
6513 #include "gt-stmt.h"