1 /* Expands front end tree to back end RTL for GNU C-Compiler
2 Copyright (C) 1987, 88, 89, 92-98, 1999 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
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. */
44 #include "insn-flags.h"
45 #include "insn-config.h"
46 #include "insn-codes.h"
48 #include "hard-reg-set.h"
56 #define obstack_chunk_alloc xmalloc
57 #define obstack_chunk_free free
58 struct obstack stmt_obstack;
60 /* Assume that case vectors are not pc-relative. */
61 #ifndef CASE_VECTOR_PC_RELATIVE
62 #define CASE_VECTOR_PC_RELATIVE 0
65 /* Each time we expand the end of a binding contour (in `expand_end_bindings')
66 and we emit a new NOTE_INSN_BLOCK_END note, we save a pointer to it here.
67 This is used by the `remember_end_note' function to record the endpoint
68 of each generated block in its associated BLOCK node. */
70 static rtx last_block_end_note;
72 /* Functions and data structures for expanding case statements. */
74 /* Case label structure, used to hold info on labels within case
75 statements. We handle "range" labels; for a single-value label
76 as in C, the high and low limits are the same.
78 An AVL tree of case nodes is initially created, and later transformed
79 to a list linked via the RIGHT fields in the nodes. Nodes with
80 higher case values are later in the list.
82 Switch statements can be output in one of two forms. A branch table
83 is used if there are more than a few labels and the labels are dense
84 within the range between the smallest and largest case value. If a
85 branch table is used, no further manipulations are done with the case
88 The alternative to the use of a branch table is to generate a series
89 of compare and jump insns. When that is done, we use the LEFT, RIGHT,
90 and PARENT fields to hold a binary tree. Initially the tree is
91 totally unbalanced, with everything on the right. We balance the tree
92 with nodes on the left having lower case values than the parent
93 and nodes on the right having higher values. We then output the tree
98 struct case_node *left; /* Left son in binary tree */
99 struct case_node *right; /* Right son in binary tree; also node chain */
100 struct case_node *parent; /* Parent of node in binary tree */
101 tree low; /* Lowest index value for this label */
102 tree high; /* Highest index value for this label */
103 tree code_label; /* Label to jump to when node matches */
107 typedef struct case_node case_node;
108 typedef struct case_node *case_node_ptr;
110 /* These are used by estimate_case_costs and balance_case_nodes. */
112 /* This must be a signed type, and non-ANSI compilers lack signed char. */
113 static short *cost_table;
114 static int use_cost_table;
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. */
144 struct nesting *next;
149 /* For conds (if-then and if-then-else statements). */
152 /* Label for the end of the if construct.
153 There is none if EXITFLAG was not set
154 and no `else' has been seen yet. */
156 /* Label for the end of this alternative.
157 This may be the end of the if or the next else/elseif. */
163 /* Label at the top of the loop; place to loop back to. */
165 /* Label at the end of the whole construct. */
167 /* Label before a jump that branches to the end of the whole
168 construct. This is where destructors go if any. */
170 /* Label for `continue' statement to jump to;
171 this is in front of the stepper of the loop. */
174 /* For variable binding contours. */
177 /* Sequence number of this binding contour within the function,
178 in order of entry. */
179 int block_start_count;
180 /* Nonzero => value to restore stack to on exit. */
182 /* The NOTE that starts this contour.
183 Used by expand_goto to check whether the destination
184 is within each contour or not. */
186 /* Innermost containing binding contour that has a stack level. */
187 struct nesting *innermost_stack_block;
188 /* List of cleanups to be run on exit from this contour.
189 This is a list of expressions to be evaluated.
190 The TREE_PURPOSE of each link is the ..._DECL node
191 which the cleanup pertains to. */
193 /* List of cleanup-lists of blocks containing this block,
194 as they were at the locus where this block appears.
195 There is an element for each containing block,
196 ordered innermost containing block first.
197 The tail of this list can be 0,
198 if all remaining elements would be empty lists.
199 The element's TREE_VALUE is the cleanup-list of that block,
200 which may be null. */
202 /* Chain of labels defined inside this binding contour.
203 For contours that have stack levels or cleanups. */
204 struct label_chain *label_chain;
205 /* Number of function calls seen, as of start of this block. */
206 int n_function_calls;
207 /* Nonzero if this is associated with a EH region. */
208 int exception_region;
209 /* The saved target_temp_slot_level from our outer block.
210 We may reset target_temp_slot_level to be the level of
211 this block, if that is done, target_temp_slot_level
212 reverts to the saved target_temp_slot_level at the very
214 int block_target_temp_slot_level;
215 /* True if we are currently emitting insns in an area of
216 output code that is controlled by a conditional
217 expression. This is used by the cleanup handling code to
218 generate conditional cleanup actions. */
219 int conditional_code;
220 /* A place to move the start of the exception region for any
221 of the conditional cleanups, must be at the end or after
222 the start of the last unconditional cleanup, and before any
223 conditional branch points. */
224 rtx last_unconditional_cleanup;
225 /* When in a conditional context, this is the specific
226 cleanup list associated with last_unconditional_cleanup,
227 where we place the conditionalized cleanups. */
230 /* For switch (C) or case (Pascal) statements,
231 and also for dummies (see `expand_start_case_dummy'). */
234 /* The insn after which the case dispatch should finally
235 be emitted. Zero for a dummy. */
237 /* A list of case labels; it is first built as an AVL tree.
238 During expand_end_case, this is converted to a list, and may be
239 rearranged into a nearly balanced binary tree. */
240 struct case_node *case_list;
241 /* Label to jump to if no case matches. */
243 /* The expression to be dispatched on. */
245 /* Type that INDEX_EXPR should be converted to. */
247 /* Number of range exprs in case statement. */
249 /* Name of this kind of statement, for warnings. */
250 const char *printname;
251 /* Used to save no_line_numbers till we see the first case label.
252 We set this to -1 when we see the first case label in this
254 int line_number_status;
259 /* Allocate and return a new `struct nesting'. */
261 #define ALLOC_NESTING() \
262 (struct nesting *) obstack_alloc (&stmt_obstack, sizeof (struct nesting))
264 /* Pop the nesting stack element by element until we pop off
265 the element which is at the top of STACK.
266 Update all the other stacks, popping off elements from them
267 as we pop them from nesting_stack. */
269 #define POPSTACK(STACK) \
270 do { struct nesting *target = STACK; \
271 struct nesting *this; \
272 do { this = nesting_stack; \
273 if (loop_stack == this) \
274 loop_stack = loop_stack->next; \
275 if (cond_stack == this) \
276 cond_stack = cond_stack->next; \
277 if (block_stack == this) \
278 block_stack = block_stack->next; \
279 if (stack_block_stack == this) \
280 stack_block_stack = stack_block_stack->next; \
281 if (case_stack == this) \
282 case_stack = case_stack->next; \
283 nesting_depth = nesting_stack->depth - 1; \
284 nesting_stack = this->all; \
285 obstack_free (&stmt_obstack, this); } \
286 while (this != target); } while (0)
288 /* In some cases it is impossible to generate code for a forward goto
289 until the label definition is seen. This happens when it may be necessary
290 for the goto to reset the stack pointer: we don't yet know how to do that.
291 So expand_goto puts an entry on this fixup list.
292 Each time a binding contour that resets the stack is exited,
294 If the target label has now been defined, we can insert the proper code. */
298 /* Points to following fixup. */
299 struct goto_fixup *next;
300 /* Points to the insn before the jump insn.
301 If more code must be inserted, it goes after this insn. */
303 /* The LABEL_DECL that this jump is jumping to, or 0
304 for break, continue or return. */
306 /* The BLOCK for the place where this goto was found. */
308 /* The CODE_LABEL rtx that this is jumping to. */
310 /* Number of binding contours started in current function
311 before the label reference. */
312 int block_start_count;
313 /* The outermost stack level that should be restored for this jump.
314 Each time a binding contour that resets the stack is exited,
315 if the target label is *not* yet defined, this slot is updated. */
317 /* List of lists of cleanup expressions to be run by this goto.
318 There is one element for each block that this goto is within.
319 The tail of this list can be 0,
320 if all remaining elements would be empty.
321 The TREE_VALUE contains the cleanup list of that block as of the
322 time this goto was seen.
323 The TREE_ADDRESSABLE flag is 1 for a block that has been exited. */
324 tree cleanup_list_list;
327 /* Within any binding contour that must restore a stack level,
328 all labels are recorded with a chain of these structures. */
332 /* Points to following fixup. */
333 struct label_chain *next;
339 /* Chain of all pending binding contours. */
340 struct nesting *x_block_stack;
342 /* If any new stacks are added here, add them to POPSTACKS too. */
344 /* Chain of all pending binding contours that restore stack levels
346 struct nesting *x_stack_block_stack;
348 /* Chain of all pending conditional statements. */
349 struct nesting *x_cond_stack;
351 /* Chain of all pending loops. */
352 struct nesting *x_loop_stack;
354 /* Chain of all pending case or switch statements. */
355 struct nesting *x_case_stack;
357 /* Separate chain including all of the above,
358 chained through the `all' field. */
359 struct nesting *x_nesting_stack;
361 /* Number of entries on nesting_stack now. */
364 /* Number of binding contours started so far in this function. */
365 int x_block_start_count;
367 /* Each time we expand an expression-statement,
368 record the expr's type and its RTL value here. */
369 tree x_last_expr_type;
370 rtx x_last_expr_value;
372 /* Nonzero if within a ({...}) grouping, in which case we must
373 always compute a value for each expr-stmt in case it is the last one. */
374 int x_expr_stmts_for_value;
376 /* Filename and line number of last line-number note,
377 whether we actually emitted it or not. */
378 char *x_emit_filename;
381 struct goto_fixup *x_goto_fixup_chain;
384 #define block_stack (current_function->stmt->x_block_stack)
385 #define stack_block_stack (current_function->stmt->x_stack_block_stack)
386 #define cond_stack (current_function->stmt->x_cond_stack)
387 #define loop_stack (current_function->stmt->x_loop_stack)
388 #define case_stack (current_function->stmt->x_case_stack)
389 #define nesting_stack (current_function->stmt->x_nesting_stack)
390 #define nesting_depth (current_function->stmt->x_nesting_depth)
391 #define current_block_start_count (current_function->stmt->x_block_start_count)
392 #define last_expr_type (current_function->stmt->x_last_expr_type)
393 #define last_expr_value (current_function->stmt->x_last_expr_value)
394 #define expr_stmts_for_value (current_function->stmt->x_expr_stmts_for_value)
395 #define emit_filename (current_function->stmt->x_emit_filename)
396 #define emit_lineno (current_function->stmt->x_emit_lineno)
397 #define goto_fixup_chain (current_function->stmt->x_goto_fixup_chain)
399 /* Non-zero if we are using EH to handle cleanus. */
400 static int using_eh_for_cleanups_p = 0;
403 static int n_occurrences PROTO((int, const char *));
404 static void expand_goto_internal PROTO((tree, rtx, rtx));
405 static int expand_fixup PROTO((tree, rtx, rtx));
406 static rtx expand_nl_handler_label PROTO((rtx, rtx));
407 static void expand_nl_goto_receiver PROTO((void));
408 static void expand_nl_goto_receivers PROTO((struct nesting *));
409 static void fixup_gotos PROTO((struct nesting *, rtx, tree,
411 static void expand_null_return_1 PROTO((rtx, int));
412 static void expand_value_return PROTO((rtx));
413 static int tail_recursion_args PROTO((tree, tree));
414 static void expand_cleanups PROTO((tree, tree, int, int));
415 static void check_seenlabel PROTO((void));
416 static void do_jump_if_equal PROTO((rtx, rtx, rtx, int));
417 static int estimate_case_costs PROTO((case_node_ptr));
418 static void group_case_nodes PROTO((case_node_ptr));
419 static void balance_case_nodes PROTO((case_node_ptr *,
421 static int node_has_low_bound PROTO((case_node_ptr, tree));
422 static int node_has_high_bound PROTO((case_node_ptr, tree));
423 static int node_is_bounded PROTO((case_node_ptr, tree));
424 static void emit_jump_if_reachable PROTO((rtx));
425 static void emit_case_nodes PROTO((rtx, case_node_ptr, rtx, tree));
426 static int add_case_node PROTO((tree, tree, tree, tree *));
427 static struct case_node *case_tree2list PROTO((case_node *, case_node *));
430 using_eh_for_cleanups ()
432 using_eh_for_cleanups_p = 1;
438 gcc_obstack_init (&stmt_obstack);
443 init_stmt_for_function ()
445 current_function->stmt
446 = (struct stmt_status *) xmalloc (sizeof (struct stmt_status));
448 /* We are not currently within any block, conditional, loop or case. */
450 stack_block_stack = 0;
457 current_block_start_count = 0;
459 /* No gotos have been expanded yet. */
460 goto_fixup_chain = 0;
462 /* We are not processing a ({...}) grouping. */
463 expr_stmts_for_value = 0;
466 init_eh_for_function ();
469 /* Return nonzero if anything is pushed on the loop, condition, or case
474 return cond_stack || loop_stack || case_stack;
477 /* Record the current file and line. Called from emit_line_note. */
479 set_file_and_line_for_stmt (file, line)
483 emit_filename = file;
487 /* Emit a no-op instruction. */
494 last_insn = get_last_insn ();
496 && (GET_CODE (last_insn) == CODE_LABEL
497 || (GET_CODE (last_insn) == NOTE
498 && prev_real_insn (last_insn) == 0)))
499 emit_insn (gen_nop ());
502 /* Return the rtx-label that corresponds to a LABEL_DECL,
503 creating it if necessary. */
509 if (TREE_CODE (label) != LABEL_DECL)
512 if (DECL_RTL (label))
513 return DECL_RTL (label);
515 return DECL_RTL (label) = gen_label_rtx ();
518 /* Add an unconditional jump to LABEL as the next sequential instruction. */
524 do_pending_stack_adjust ();
525 emit_jump_insn (gen_jump (label));
529 /* Emit code to jump to the address
530 specified by the pointer expression EXP. */
533 expand_computed_goto (exp)
536 rtx x = expand_expr (exp, NULL_RTX, VOIDmode, 0);
538 #ifdef POINTERS_EXTEND_UNSIGNED
539 x = convert_memory_address (Pmode, x);
543 /* Be sure the function is executable. */
544 if (current_function_check_memory_usage)
545 emit_library_call (chkr_check_exec_libfunc, 1,
546 VOIDmode, 1, x, ptr_mode);
548 do_pending_stack_adjust ();
549 emit_indirect_jump (x);
551 current_function_has_computed_jump = 1;
554 /* Handle goto statements and the labels that they can go to. */
556 /* Specify the location in the RTL code of a label LABEL,
557 which is a LABEL_DECL tree node.
559 This is used for the kind of label that the user can jump to with a
560 goto statement, and for alternatives of a switch or case statement.
561 RTL labels generated for loops and conditionals don't go through here;
562 they are generated directly at the RTL level, by other functions below.
564 Note that this has nothing to do with defining label *names*.
565 Languages vary in how they do that and what that even means. */
571 struct label_chain *p;
573 do_pending_stack_adjust ();
574 emit_label (label_rtx (label));
575 if (DECL_NAME (label))
576 LABEL_NAME (DECL_RTL (label)) = IDENTIFIER_POINTER (DECL_NAME (label));
578 if (stack_block_stack != 0)
580 p = (struct label_chain *) oballoc (sizeof (struct label_chain));
581 p->next = stack_block_stack->data.block.label_chain;
582 stack_block_stack->data.block.label_chain = p;
587 /* Declare that LABEL (a LABEL_DECL) may be used for nonlocal gotos
588 from nested functions. */
591 declare_nonlocal_label (label)
594 rtx slot = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
596 nonlocal_labels = tree_cons (NULL_TREE, label, nonlocal_labels);
597 LABEL_PRESERVE_P (label_rtx (label)) = 1;
598 if (nonlocal_goto_handler_slots == 0)
600 emit_stack_save (SAVE_NONLOCAL,
601 &nonlocal_goto_stack_level,
602 PREV_INSN (tail_recursion_reentry));
604 nonlocal_goto_handler_slots
605 = gen_rtx_EXPR_LIST (VOIDmode, slot, nonlocal_goto_handler_slots);
608 /* Generate RTL code for a `goto' statement with target label LABEL.
609 LABEL should be a LABEL_DECL tree node that was or will later be
610 defined with `expand_label'. */
618 /* Check for a nonlocal goto to a containing function. */
619 context = decl_function_context (label);
620 if (context != 0 && context != current_function_decl)
622 struct function *p = find_function_data (context);
623 rtx label_ref = gen_rtx_LABEL_REF (Pmode, label_rtx (label));
624 rtx temp, handler_slot;
627 /* Find the corresponding handler slot for this label. */
628 handler_slot = p->x_nonlocal_goto_handler_slots;
629 for (link = p->x_nonlocal_labels; TREE_VALUE (link) != label;
630 link = TREE_CHAIN (link))
631 handler_slot = XEXP (handler_slot, 1);
632 handler_slot = XEXP (handler_slot, 0);
634 p->has_nonlocal_label = 1;
635 current_function_has_nonlocal_goto = 1;
636 LABEL_REF_NONLOCAL_P (label_ref) = 1;
638 /* Copy the rtl for the slots so that they won't be shared in
639 case the virtual stack vars register gets instantiated differently
640 in the parent than in the child. */
642 #if HAVE_nonlocal_goto
643 if (HAVE_nonlocal_goto)
644 emit_insn (gen_nonlocal_goto (lookup_static_chain (label),
645 copy_rtx (handler_slot),
646 copy_rtx (p->x_nonlocal_goto_stack_level),
653 /* Restore frame pointer for containing function.
654 This sets the actual hard register used for the frame pointer
655 to the location of the function's incoming static chain info.
656 The non-local goto handler will then adjust it to contain the
657 proper value and reload the argument pointer, if needed. */
658 emit_move_insn (hard_frame_pointer_rtx, lookup_static_chain (label));
660 /* We have now loaded the frame pointer hardware register with
661 the address of that corresponds to the start of the virtual
662 stack vars. So replace virtual_stack_vars_rtx in all
663 addresses we use with stack_pointer_rtx. */
665 /* Get addr of containing function's current nonlocal goto handler,
666 which will do any cleanups and then jump to the label. */
667 addr = copy_rtx (handler_slot);
668 temp = copy_to_reg (replace_rtx (addr, virtual_stack_vars_rtx,
669 hard_frame_pointer_rtx));
671 /* Restore the stack pointer. Note this uses fp just restored. */
672 addr = p->x_nonlocal_goto_stack_level;
674 addr = replace_rtx (copy_rtx (addr),
675 virtual_stack_vars_rtx,
676 hard_frame_pointer_rtx);
678 emit_stack_restore (SAVE_NONLOCAL, addr, NULL_RTX);
680 /* USE of hard_frame_pointer_rtx added for consistency; not clear if
682 emit_insn (gen_rtx_USE (VOIDmode, hard_frame_pointer_rtx));
683 emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
684 emit_indirect_jump (temp);
688 expand_goto_internal (label, label_rtx (label), NULL_RTX);
691 /* Generate RTL code for a `goto' statement with target label BODY.
692 LABEL should be a LABEL_REF.
693 LAST_INSN, if non-0, is the rtx we should consider as the last
694 insn emitted (for the purposes of cleaning up a return). */
697 expand_goto_internal (body, label, last_insn)
702 struct nesting *block;
705 if (GET_CODE (label) != CODE_LABEL)
708 /* If label has already been defined, we can tell now
709 whether and how we must alter the stack level. */
711 if (PREV_INSN (label) != 0)
713 /* Find the innermost pending block that contains the label.
714 (Check containment by comparing insn-uids.)
715 Then restore the outermost stack level within that block,
716 and do cleanups of all blocks contained in it. */
717 for (block = block_stack; block; block = block->next)
719 if (INSN_UID (block->data.block.first_insn) < INSN_UID (label))
721 if (block->data.block.stack_level != 0)
722 stack_level = block->data.block.stack_level;
723 /* Execute the cleanups for blocks we are exiting. */
724 if (block->data.block.cleanups != 0)
726 expand_cleanups (block->data.block.cleanups, NULL_TREE, 1, 1);
727 do_pending_stack_adjust ();
733 /* Ensure stack adjust isn't done by emit_jump, as this
734 would clobber the stack pointer. This one should be
735 deleted as dead by flow. */
736 clear_pending_stack_adjust ();
737 do_pending_stack_adjust ();
738 emit_stack_restore (SAVE_BLOCK, stack_level, NULL_RTX);
741 if (body != 0 && DECL_TOO_LATE (body))
742 error ("jump to `%s' invalidly jumps into binding contour",
743 IDENTIFIER_POINTER (DECL_NAME (body)));
745 /* Label not yet defined: may need to put this goto
746 on the fixup list. */
747 else if (! expand_fixup (body, label, last_insn))
749 /* No fixup needed. Record that the label is the target
750 of at least one goto that has no fixup. */
752 TREE_ADDRESSABLE (body) = 1;
758 /* Generate if necessary a fixup for a goto
759 whose target label in tree structure (if any) is TREE_LABEL
760 and whose target in rtl is RTL_LABEL.
762 If LAST_INSN is nonzero, we pretend that the jump appears
763 after insn LAST_INSN instead of at the current point in the insn stream.
765 The fixup will be used later to insert insns just before the goto.
766 Those insns will restore the stack level as appropriate for the
767 target label, and will (in the case of C++) also invoke any object
768 destructors which have to be invoked when we exit the scopes which
769 are exited by the goto.
771 Value is nonzero if a fixup is made. */
774 expand_fixup (tree_label, rtl_label, last_insn)
779 struct nesting *block, *end_block;
781 /* See if we can recognize which block the label will be output in.
782 This is possible in some very common cases.
783 If we succeed, set END_BLOCK to that block.
784 Otherwise, set it to 0. */
787 && (rtl_label == cond_stack->data.cond.endif_label
788 || rtl_label == cond_stack->data.cond.next_label))
789 end_block = cond_stack;
790 /* If we are in a loop, recognize certain labels which
791 are likely targets. This reduces the number of fixups
792 we need to create. */
794 && (rtl_label == loop_stack->data.loop.start_label
795 || rtl_label == loop_stack->data.loop.end_label
796 || rtl_label == loop_stack->data.loop.continue_label))
797 end_block = loop_stack;
801 /* Now set END_BLOCK to the binding level to which we will return. */
805 struct nesting *next_block = end_block->all;
808 /* First see if the END_BLOCK is inside the innermost binding level.
809 If so, then no cleanups or stack levels are relevant. */
810 while (next_block && next_block != block)
811 next_block = next_block->all;
816 /* Otherwise, set END_BLOCK to the innermost binding level
817 which is outside the relevant control-structure nesting. */
818 next_block = block_stack->next;
819 for (block = block_stack; block != end_block; block = block->all)
820 if (block == next_block)
821 next_block = next_block->next;
822 end_block = next_block;
825 /* Does any containing block have a stack level or cleanups?
826 If not, no fixup is needed, and that is the normal case
827 (the only case, for standard C). */
828 for (block = block_stack; block != end_block; block = block->next)
829 if (block->data.block.stack_level != 0
830 || block->data.block.cleanups != 0)
833 if (block != end_block)
835 /* Ok, a fixup is needed. Add a fixup to the list of such. */
836 struct goto_fixup *fixup
837 = (struct goto_fixup *) oballoc (sizeof (struct goto_fixup));
838 /* In case an old stack level is restored, make sure that comes
839 after any pending stack adjust. */
840 /* ?? If the fixup isn't to come at the present position,
841 doing the stack adjust here isn't useful. Doing it with our
842 settings at that location isn't useful either. Let's hope
845 do_pending_stack_adjust ();
846 fixup->target = tree_label;
847 fixup->target_rtl = rtl_label;
849 /* Create a BLOCK node and a corresponding matched set of
850 NOTE_INSN_BEGIN_BLOCK and NOTE_INSN_END_BLOCK notes at
851 this point. The notes will encapsulate any and all fixup
852 code which we might later insert at this point in the insn
853 stream. Also, the BLOCK node will be the parent (i.e. the
854 `SUPERBLOCK') of any other BLOCK nodes which we might create
855 later on when we are expanding the fixup code.
857 Note that optimization passes (including expand_end_loop)
858 might move the *_BLOCK notes away, so we use a NOTE_INSN_DELETED
862 register rtx original_before_jump
863 = last_insn ? last_insn : get_last_insn ();
868 start = emit_note (NULL_PTR, NOTE_INSN_BLOCK_BEG);
869 fixup->before_jump = emit_note (NULL_PTR, NOTE_INSN_DELETED);
870 last_block_end_note = emit_note (NULL_PTR, NOTE_INSN_BLOCK_END);
871 fixup->context = poplevel (1, 0, 0); /* Create the BLOCK node now! */
873 emit_insns_after (start, original_before_jump);
876 fixup->block_start_count = current_block_start_count;
877 fixup->stack_level = 0;
878 fixup->cleanup_list_list
879 = ((block->data.block.outer_cleanups
880 || block->data.block.cleanups)
881 ? tree_cons (NULL_TREE, block->data.block.cleanups,
882 block->data.block.outer_cleanups)
884 fixup->next = goto_fixup_chain;
885 goto_fixup_chain = fixup;
893 /* Expand any needed fixups in the outputmost binding level of the
894 function. FIRST_INSN is the first insn in the function. */
897 expand_fixups (first_insn)
900 fixup_gotos (NULL_PTR, NULL_RTX, NULL_TREE, first_insn, 0);
903 /* When exiting a binding contour, process all pending gotos requiring fixups.
904 THISBLOCK is the structure that describes the block being exited.
905 STACK_LEVEL is the rtx for the stack level to restore exiting this contour.
906 CLEANUP_LIST is a list of expressions to evaluate on exiting this contour.
907 FIRST_INSN is the insn that began this contour.
909 Gotos that jump out of this contour must restore the
910 stack level and do the cleanups before actually jumping.
912 DONT_JUMP_IN nonzero means report error there is a jump into this
913 contour from before the beginning of the contour.
914 This is also done if STACK_LEVEL is nonzero. */
917 fixup_gotos (thisblock, stack_level, cleanup_list, first_insn, dont_jump_in)
918 struct nesting *thisblock;
924 register struct goto_fixup *f, *prev;
926 /* F is the fixup we are considering; PREV is the previous one. */
927 /* We run this loop in two passes so that cleanups of exited blocks
928 are run first, and blocks that are exited are marked so
931 for (prev = 0, f = goto_fixup_chain; f; prev = f, f = f->next)
933 /* Test for a fixup that is inactive because it is already handled. */
934 if (f->before_jump == 0)
936 /* Delete inactive fixup from the chain, if that is easy to do. */
938 prev->next = f->next;
940 /* Has this fixup's target label been defined?
941 If so, we can finalize it. */
942 else if (PREV_INSN (f->target_rtl) != 0)
944 register rtx cleanup_insns;
946 /* Get the first non-label after the label
947 this goto jumps to. If that's before this scope begins,
948 we don't have a jump into the scope. */
949 rtx after_label = f->target_rtl;
950 while (after_label != 0 && GET_CODE (after_label) == CODE_LABEL)
951 after_label = NEXT_INSN (after_label);
953 /* If this fixup jumped into this contour from before the beginning
954 of this contour, report an error. */
955 /* ??? Bug: this does not detect jumping in through intermediate
956 blocks that have stack levels or cleanups.
957 It detects only a problem with the innermost block
960 && (dont_jump_in || stack_level || cleanup_list)
961 /* If AFTER_LABEL is 0, it means the jump goes to the end
962 of the rtl, which means it jumps into this scope. */
964 || INSN_UID (first_insn) < INSN_UID (after_label))
965 && INSN_UID (first_insn) > INSN_UID (f->before_jump)
966 && ! DECL_ERROR_ISSUED (f->target))
968 error_with_decl (f->target,
969 "label `%s' used before containing binding contour");
970 /* Prevent multiple errors for one label. */
971 DECL_ERROR_ISSUED (f->target) = 1;
974 /* We will expand the cleanups into a sequence of their own and
975 then later on we will attach this new sequence to the insn
976 stream just ahead of the actual jump insn. */
980 /* Temporarily restore the lexical context where we will
981 logically be inserting the fixup code. We do this for the
982 sake of getting the debugging information right. */
985 set_block (f->context);
987 /* Expand the cleanups for blocks this jump exits. */
988 if (f->cleanup_list_list)
991 for (lists = f->cleanup_list_list; lists; lists = TREE_CHAIN (lists))
992 /* Marked elements correspond to blocks that have been closed.
993 Do their cleanups. */
994 if (TREE_ADDRESSABLE (lists)
995 && TREE_VALUE (lists) != 0)
997 expand_cleanups (TREE_VALUE (lists), NULL_TREE, 1, 1);
998 /* Pop any pushes done in the cleanups,
999 in case function is about to return. */
1000 do_pending_stack_adjust ();
1004 /* Restore stack level for the biggest contour that this
1005 jump jumps out of. */
1007 emit_stack_restore (SAVE_BLOCK, f->stack_level, f->before_jump);
1009 /* Finish up the sequence containing the insns which implement the
1010 necessary cleanups, and then attach that whole sequence to the
1011 insn stream just ahead of the actual jump insn. Attaching it
1012 at that point insures that any cleanups which are in fact
1013 implicit C++ object destructions (which must be executed upon
1014 leaving the block) appear (to the debugger) to be taking place
1015 in an area of the generated code where the object(s) being
1016 destructed are still "in scope". */
1018 cleanup_insns = get_insns ();
1022 emit_insns_after (cleanup_insns, f->before_jump);
1029 /* For any still-undefined labels, do the cleanups for this block now.
1030 We must do this now since items in the cleanup list may go out
1031 of scope when the block ends. */
1032 for (prev = 0, f = goto_fixup_chain; f; prev = f, f = f->next)
1033 if (f->before_jump != 0
1034 && PREV_INSN (f->target_rtl) == 0
1035 /* Label has still not appeared. If we are exiting a block with
1036 a stack level to restore, that started before the fixup,
1037 mark this stack level as needing restoration
1038 when the fixup is later finalized. */
1040 /* Note: if THISBLOCK == 0 and we have a label that hasn't appeared, it
1041 means the label is undefined. That's erroneous, but possible. */
1042 && (thisblock->data.block.block_start_count
1043 <= f->block_start_count))
1045 tree lists = f->cleanup_list_list;
1048 for (; lists; lists = TREE_CHAIN (lists))
1049 /* If the following elt. corresponds to our containing block
1050 then the elt. must be for this block. */
1051 if (TREE_CHAIN (lists) == thisblock->data.block.outer_cleanups)
1055 set_block (f->context);
1056 expand_cleanups (TREE_VALUE (lists), NULL_TREE, 1, 1);
1057 do_pending_stack_adjust ();
1058 cleanup_insns = get_insns ();
1061 if (cleanup_insns != 0)
1063 = emit_insns_after (cleanup_insns, f->before_jump);
1065 f->cleanup_list_list = TREE_CHAIN (lists);
1069 f->stack_level = stack_level;
1073 /* Return the number of times character C occurs in string S. */
1075 n_occurrences (c, s)
1085 /* Generate RTL for an asm statement (explicit assembler code).
1086 BODY is a STRING_CST node containing the assembler code text,
1087 or an ADDR_EXPR containing a STRING_CST. */
1093 if (current_function_check_memory_usage)
1095 error ("`asm' cannot be used with `-fcheck-memory-usage'");
1099 if (TREE_CODE (body) == ADDR_EXPR)
1100 body = TREE_OPERAND (body, 0);
1102 emit_insn (gen_rtx_ASM_INPUT (VOIDmode,
1103 TREE_STRING_POINTER (body)));
1107 /* Generate RTL for an asm statement with arguments.
1108 STRING is the instruction template.
1109 OUTPUTS is a list of output arguments (lvalues); INPUTS a list of inputs.
1110 Each output or input has an expression in the TREE_VALUE and
1111 a constraint-string in the TREE_PURPOSE.
1112 CLOBBERS is a list of STRING_CST nodes each naming a hard register
1113 that is clobbered by this insn.
1115 Not all kinds of lvalue that may appear in OUTPUTS can be stored directly.
1116 Some elements of OUTPUTS may be replaced with trees representing temporary
1117 values. The caller should copy those temporary values to the originally
1120 VOL nonzero means the insn is volatile; don't optimize it. */
1123 expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line)
1124 tree string, outputs, inputs, clobbers;
1129 rtvec argvec, constraints;
1131 int ninputs = list_length (inputs);
1132 int noutputs = list_length (outputs);
1137 /* Vector of RTX's of evaluated output operands. */
1138 rtx *output_rtx = (rtx *) alloca (noutputs * sizeof (rtx));
1139 int *inout_opnum = (int *) alloca (noutputs * sizeof (int));
1140 rtx *real_output_rtx = (rtx *) alloca (noutputs * sizeof (rtx));
1141 enum machine_mode *inout_mode
1142 = (enum machine_mode *) alloca (noutputs * sizeof (enum machine_mode));
1143 /* The insn we have emitted. */
1146 /* An ASM with no outputs needs to be treated as volatile, for now. */
1150 if (current_function_check_memory_usage)
1152 error ("`asm' cannot be used with `-fcheck-memory-usage'");
1156 /* Count the number of meaningful clobbered registers, ignoring what
1157 we would ignore later. */
1159 for (tail = clobbers; tail; tail = TREE_CHAIN (tail))
1161 char *regname = TREE_STRING_POINTER (TREE_VALUE (tail));
1162 i = decode_reg_name (regname);
1163 if (i >= 0 || i == -4)
1166 error ("unknown register name `%s' in `asm'", regname);
1171 /* Check that the number of alternatives is constant across all
1173 if (outputs || inputs)
1175 tree tmp = TREE_PURPOSE (outputs ? outputs : inputs);
1176 int nalternatives = n_occurrences (',', TREE_STRING_POINTER (tmp));
1179 if (nalternatives + 1 > MAX_RECOG_ALTERNATIVES)
1181 error ("too many alternatives in `asm'");
1188 char *constraint = TREE_STRING_POINTER (TREE_PURPOSE (tmp));
1189 if (n_occurrences (',', constraint) != nalternatives)
1191 error ("operand constraints for `asm' differ in number of alternatives");
1194 if (TREE_CHAIN (tmp))
1195 tmp = TREE_CHAIN (tmp);
1197 tmp = next, next = 0;
1201 for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
1203 tree val = TREE_VALUE (tail);
1204 tree type = TREE_TYPE (val);
1213 /* If there's an erroneous arg, emit no insn. */
1214 if (TREE_TYPE (val) == error_mark_node)
1217 /* Make sure constraint has `=' and does not have `+'. Also, see
1218 if it allows any register. Be liberal on the latter test, since
1219 the worst that happens if we get it wrong is we issue an error
1222 c_len = TREE_STRING_LENGTH (TREE_PURPOSE (tail)) - 1;
1223 constraint = TREE_STRING_POINTER (TREE_PURPOSE (tail));
1225 /* Allow the `=' or `+' to not be at the beginning of the string,
1226 since it wasn't explicitly documented that way, and there is a
1227 large body of code that puts it last. Swap the character to
1228 the front, so as not to uglify any place else. */
1232 if ((p = strchr (constraint, '=')) != NULL)
1234 if ((p = strchr (constraint, '+')) != NULL)
1237 error ("output operand constraint lacks `='");
1241 if (p != constraint)
1244 bcopy (constraint, constraint+1, p-constraint);
1247 warning ("output constraint `%c' for operand %d is not at the beginning", j, i);
1250 is_inout = constraint[0] == '+';
1251 /* Replace '+' with '='. */
1252 constraint[0] = '=';
1253 /* Make sure we can specify the matching operand. */
1254 if (is_inout && i > 9)
1256 error ("output operand constraint %d contains `+'", i);
1260 for (j = 1; j < c_len; j++)
1261 switch (constraint[j])
1265 error ("operand constraint contains '+' or '=' at illegal position.");
1269 if (i + 1 == ninputs + noutputs)
1271 error ("`%%' constraint used with last operand");
1276 case '?': case '!': case '*': case '&':
1277 case 'E': case 'F': case 'G': case 'H':
1278 case 's': case 'i': case 'n':
1279 case 'I': case 'J': case 'K': case 'L': case 'M':
1280 case 'N': case 'O': case 'P': case ',':
1281 #ifdef EXTRA_CONSTRAINT
1282 case 'Q': case 'R': case 'S': case 'T': case 'U':
1286 case '0': case '1': case '2': case '3': case '4':
1287 case '5': case '6': case '7': case '8': case '9':
1288 error ("matching constraint not valid in output operand");
1291 case 'V': case 'm': case 'o':
1296 /* ??? Before flow, auto inc/dec insns are not supposed to exist,
1297 excepting those that expand_call created. So match memory
1313 /* If an output operand is not a decl or indirect ref and our constraint
1314 allows a register, make a temporary to act as an intermediate.
1315 Make the asm insn write into that, then our caller will copy it to
1316 the real output operand. Likewise for promoted variables. */
1318 real_output_rtx[i] = NULL_RTX;
1319 if ((TREE_CODE (val) == INDIRECT_REF
1321 || (TREE_CODE_CLASS (TREE_CODE (val)) == 'd'
1322 && (allows_mem || GET_CODE (DECL_RTL (val)) == REG)
1323 && ! (GET_CODE (DECL_RTL (val)) == REG
1324 && GET_MODE (DECL_RTL (val)) != TYPE_MODE (type)))
1329 mark_addressable (TREE_VALUE (tail));
1332 = expand_expr (TREE_VALUE (tail), NULL_RTX, VOIDmode,
1333 EXPAND_MEMORY_USE_WO);
1335 if (! allows_reg && GET_CODE (output_rtx[i]) != MEM)
1336 error ("output number %d not directly addressable", i);
1337 if (! allows_mem && GET_CODE (output_rtx[i]) == MEM)
1339 real_output_rtx[i] = protect_from_queue (output_rtx[i], 1);
1340 output_rtx[i] = gen_reg_rtx (GET_MODE (output_rtx[i]));
1342 emit_move_insn (output_rtx[i], real_output_rtx[i]);
1347 output_rtx[i] = assign_temp (type, 0, 0, 0);
1348 TREE_VALUE (tail) = make_tree (type, output_rtx[i]);
1353 inout_mode[ninout] = TYPE_MODE (TREE_TYPE (TREE_VALUE (tail)));
1354 inout_opnum[ninout++] = i;
1359 if (ninputs + noutputs > MAX_RECOG_OPERANDS)
1361 error ("more than %d operands in `asm'", MAX_RECOG_OPERANDS);
1365 /* Make vectors for the expression-rtx and constraint strings. */
1367 argvec = rtvec_alloc (ninputs);
1368 constraints = rtvec_alloc (ninputs);
1370 body = gen_rtx_ASM_OPERANDS (VOIDmode,
1371 TREE_STRING_POINTER (string), "", 0, argvec,
1372 constraints, filename, line);
1374 MEM_VOLATILE_P (body) = vol;
1376 /* Eval the inputs and put them into ARGVEC.
1377 Put their constraints into ASM_INPUTs and store in CONSTRAINTS. */
1380 for (tail = inputs; tail; tail = TREE_CHAIN (tail))
1383 int allows_reg = 0, allows_mem = 0;
1384 char *constraint, *orig_constraint;
1388 /* If there's an erroneous arg, emit no insn,
1389 because the ASM_INPUT would get VOIDmode
1390 and that could cause a crash in reload. */
1391 if (TREE_TYPE (TREE_VALUE (tail)) == error_mark_node)
1394 /* ??? Can this happen, and does the error message make any sense? */
1395 if (TREE_PURPOSE (tail) == NULL_TREE)
1397 error ("hard register `%s' listed as input operand to `asm'",
1398 TREE_STRING_POINTER (TREE_VALUE (tail)) );
1402 c_len = TREE_STRING_LENGTH (TREE_PURPOSE (tail)) - 1;
1403 constraint = TREE_STRING_POINTER (TREE_PURPOSE (tail));
1404 orig_constraint = constraint;
1406 /* Make sure constraint has neither `=', `+', nor '&'. */
1408 for (j = 0; j < c_len; j++)
1409 switch (constraint[j])
1411 case '+': case '=': case '&':
1412 if (constraint == orig_constraint)
1414 error ("input operand constraint contains `%c'", constraint[j]);
1420 if (constraint == orig_constraint
1421 && i + 1 == ninputs - ninout)
1423 error ("`%%' constraint used with last operand");
1428 case 'V': case 'm': case 'o':
1433 case '?': case '!': case '*':
1434 case 'E': case 'F': case 'G': case 'H': case 'X':
1435 case 's': case 'i': case 'n':
1436 case 'I': case 'J': case 'K': case 'L': case 'M':
1437 case 'N': case 'O': case 'P': case ',':
1438 #ifdef EXTRA_CONSTRAINT
1439 case 'Q': case 'R': case 'S': case 'T': case 'U':
1443 /* Whether or not a numeric constraint allows a register is
1444 decided by the matching constraint, and so there is no need
1445 to do anything special with them. We must handle them in
1446 the default case, so that we don't unnecessarily force
1447 operands to memory. */
1448 case '0': case '1': case '2': case '3': case '4':
1449 case '5': case '6': case '7': case '8': case '9':
1450 if (constraint[j] >= '0' + noutputs)
1453 ("matching constraint references invalid operand number");
1457 /* Try and find the real constraint for this dup. */
1458 if ((j == 0 && c_len == 1)
1459 || (j == 1 && c_len == 2 && constraint[0] == '%'))
1462 for (j = constraint[j] - '0'; j > 0; --j)
1465 c_len = TREE_STRING_LENGTH (TREE_PURPOSE (o)) - 1;
1466 constraint = TREE_STRING_POINTER (TREE_PURPOSE (o));
1471 /* ... fall through ... */
1484 if (! allows_reg && allows_mem)
1485 mark_addressable (TREE_VALUE (tail));
1487 op = expand_expr (TREE_VALUE (tail), NULL_RTX, VOIDmode, 0);
1489 if (asm_operand_ok (op, constraint) <= 0)
1492 op = force_reg (TYPE_MODE (TREE_TYPE (TREE_VALUE (tail))), op);
1493 else if (!allows_mem)
1494 warning ("asm operand %d probably doesn't match constraints", i);
1495 else if (CONSTANT_P (op))
1496 op = force_const_mem (TYPE_MODE (TREE_TYPE (TREE_VALUE (tail))),
1498 else if (GET_CODE (op) == REG
1499 || GET_CODE (op) == SUBREG
1500 || GET_CODE (op) == CONCAT)
1502 tree type = TREE_TYPE (TREE_VALUE (tail));
1503 rtx memloc = assign_temp (type, 1, 1, 1);
1505 emit_move_insn (memloc, op);
1508 else if (GET_CODE (op) == MEM && MEM_VOLATILE_P (op))
1509 /* We won't recognize volatile memory as available a
1510 memory_operand at this point. Ignore it. */
1512 else if (queued_subexp_p (op))
1515 /* ??? Leave this only until we have experience with what
1516 happens in combine and elsewhere when constraints are
1518 warning ("asm operand %d probably doesn't match constraints", i);
1520 XVECEXP (body, 3, i) = op;
1522 XVECEXP (body, 4, i) /* constraints */
1523 = gen_rtx_ASM_INPUT (TYPE_MODE (TREE_TYPE (TREE_VALUE (tail))),
1528 /* Protect all the operands from the queue,
1529 now that they have all been evaluated. */
1531 for (i = 0; i < ninputs - ninout; i++)
1532 XVECEXP (body, 3, i) = protect_from_queue (XVECEXP (body, 3, i), 0);
1534 for (i = 0; i < noutputs; i++)
1535 output_rtx[i] = protect_from_queue (output_rtx[i], 1);
1537 /* For in-out operands, copy output rtx to input rtx. */
1538 for (i = 0; i < ninout; i++)
1540 static char match[9+1][2]
1541 = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
1542 int j = inout_opnum[i];
1544 XVECEXP (body, 3, ninputs - ninout + i) /* argvec */
1546 XVECEXP (body, 4, ninputs - ninout + i) /* constraints */
1547 = gen_rtx_ASM_INPUT (inout_mode[j], match[j]);
1550 /* Now, for each output, construct an rtx
1551 (set OUTPUT (asm_operands INSN OUTPUTNUMBER OUTPUTCONSTRAINT
1552 ARGVEC CONSTRAINTS))
1553 If there is more than one, put them inside a PARALLEL. */
1555 if (noutputs == 1 && nclobbers == 0)
1557 XSTR (body, 1) = TREE_STRING_POINTER (TREE_PURPOSE (outputs));
1558 insn = emit_insn (gen_rtx_SET (VOIDmode, output_rtx[0], body));
1560 else if (noutputs == 0 && nclobbers == 0)
1562 /* No output operands: put in a raw ASM_OPERANDS rtx. */
1563 insn = emit_insn (body);
1569 if (num == 0) num = 1;
1570 body = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (num + nclobbers));
1572 /* For each output operand, store a SET. */
1574 for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
1576 XVECEXP (body, 0, i)
1577 = gen_rtx_SET (VOIDmode,
1579 gen_rtx_ASM_OPERANDS (VOIDmode,
1580 TREE_STRING_POINTER (string),
1581 TREE_STRING_POINTER (TREE_PURPOSE (tail)),
1582 i, argvec, constraints,
1584 MEM_VOLATILE_P (SET_SRC (XVECEXP (body, 0, i))) = vol;
1587 /* If there are no outputs (but there are some clobbers)
1588 store the bare ASM_OPERANDS into the PARALLEL. */
1591 XVECEXP (body, 0, i++) = obody;
1593 /* Store (clobber REG) for each clobbered register specified. */
1595 for (tail = clobbers; tail; tail = TREE_CHAIN (tail))
1597 char *regname = TREE_STRING_POINTER (TREE_VALUE (tail));
1598 int j = decode_reg_name (regname);
1602 if (j == -3) /* `cc', which is not a register */
1605 if (j == -4) /* `memory', don't cache memory across asm */
1607 XVECEXP (body, 0, i++)
1608 = gen_rtx_CLOBBER (VOIDmode,
1609 gen_rtx_MEM (BLKmode,
1610 gen_rtx_SCRATCH (VOIDmode)));
1614 /* Ignore unknown register, error already signaled. */
1618 /* Use QImode since that's guaranteed to clobber just one reg. */
1619 XVECEXP (body, 0, i++)
1620 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (QImode, j));
1623 insn = emit_insn (body);
1626 /* For any outputs that needed reloading into registers, spill them
1627 back to where they belong. */
1628 for (i = 0; i < noutputs; ++i)
1629 if (real_output_rtx[i])
1630 emit_move_insn (real_output_rtx[i], output_rtx[i]);
1635 /* Generate RTL to evaluate the expression EXP
1636 and remember it in case this is the VALUE in a ({... VALUE; }) constr. */
1639 expand_expr_stmt (exp)
1642 /* If -W, warn about statements with no side effects,
1643 except for an explicit cast to void (e.g. for assert()), and
1644 except inside a ({...}) where they may be useful. */
1645 if (expr_stmts_for_value == 0 && exp != error_mark_node)
1647 if (! TREE_SIDE_EFFECTS (exp) && (extra_warnings || warn_unused)
1648 && !(TREE_CODE (exp) == CONVERT_EXPR
1649 && TREE_TYPE (exp) == void_type_node))
1650 warning_with_file_and_line (emit_filename, emit_lineno,
1651 "statement with no effect");
1652 else if (warn_unused)
1653 warn_if_unused_value (exp);
1656 /* If EXP is of function type and we are expanding statements for
1657 value, convert it to pointer-to-function. */
1658 if (expr_stmts_for_value && TREE_CODE (TREE_TYPE (exp)) == FUNCTION_TYPE)
1659 exp = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (exp)), exp);
1661 last_expr_type = TREE_TYPE (exp);
1662 last_expr_value = expand_expr (exp,
1663 (expr_stmts_for_value
1664 ? NULL_RTX : const0_rtx),
1667 /* If all we do is reference a volatile value in memory,
1668 copy it to a register to be sure it is actually touched. */
1669 if (last_expr_value != 0 && GET_CODE (last_expr_value) == MEM
1670 && TREE_THIS_VOLATILE (exp))
1672 if (TYPE_MODE (TREE_TYPE (exp)) == VOIDmode)
1674 else if (TYPE_MODE (TREE_TYPE (exp)) != BLKmode)
1675 copy_to_reg (last_expr_value);
1678 rtx lab = gen_label_rtx ();
1680 /* Compare the value with itself to reference it. */
1681 emit_cmp_and_jump_insns (last_expr_value, last_expr_value, EQ,
1682 expand_expr (TYPE_SIZE (last_expr_type),
1683 NULL_RTX, VOIDmode, 0),
1685 TYPE_ALIGN (last_expr_type) / BITS_PER_UNIT,
1691 /* If this expression is part of a ({...}) and is in memory, we may have
1692 to preserve temporaries. */
1693 preserve_temp_slots (last_expr_value);
1695 /* Free any temporaries used to evaluate this expression. Any temporary
1696 used as a result of this expression will already have been preserved
1703 /* Warn if EXP contains any computations whose results are not used.
1704 Return 1 if a warning is printed; 0 otherwise. */
1707 warn_if_unused_value (exp)
1710 if (TREE_USED (exp))
1713 switch (TREE_CODE (exp))
1715 case PREINCREMENT_EXPR:
1716 case POSTINCREMENT_EXPR:
1717 case PREDECREMENT_EXPR:
1718 case POSTDECREMENT_EXPR:
1723 case METHOD_CALL_EXPR:
1725 case TRY_CATCH_EXPR:
1726 case WITH_CLEANUP_EXPR:
1728 /* We don't warn about COND_EXPR because it may be a useful
1729 construct if either arm contains a side effect. */
1734 /* For a binding, warn if no side effect within it. */
1735 return warn_if_unused_value (TREE_OPERAND (exp, 1));
1738 return warn_if_unused_value (TREE_OPERAND (exp, 1));
1740 case TRUTH_ORIF_EXPR:
1741 case TRUTH_ANDIF_EXPR:
1742 /* In && or ||, warn if 2nd operand has no side effect. */
1743 return warn_if_unused_value (TREE_OPERAND (exp, 1));
1746 if (TREE_NO_UNUSED_WARNING (exp))
1748 if (warn_if_unused_value (TREE_OPERAND (exp, 0)))
1750 /* Let people do `(foo (), 0)' without a warning. */
1751 if (TREE_CONSTANT (TREE_OPERAND (exp, 1)))
1753 return warn_if_unused_value (TREE_OPERAND (exp, 1));
1757 case NON_LVALUE_EXPR:
1758 /* Don't warn about values cast to void. */
1759 if (TREE_TYPE (exp) == void_type_node)
1761 /* Don't warn about conversions not explicit in the user's program. */
1762 if (TREE_NO_UNUSED_WARNING (exp))
1764 /* Assignment to a cast usually results in a cast of a modify.
1765 Don't complain about that. There can be an arbitrary number of
1766 casts before the modify, so we must loop until we find the first
1767 non-cast expression and then test to see if that is a modify. */
1769 tree tem = TREE_OPERAND (exp, 0);
1771 while (TREE_CODE (tem) == CONVERT_EXPR || TREE_CODE (tem) == NOP_EXPR)
1772 tem = TREE_OPERAND (tem, 0);
1774 if (TREE_CODE (tem) == MODIFY_EXPR || TREE_CODE (tem) == INIT_EXPR
1775 || TREE_CODE (tem) == CALL_EXPR)
1781 /* Don't warn about automatic dereferencing of references, since
1782 the user cannot control it. */
1783 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == REFERENCE_TYPE)
1784 return warn_if_unused_value (TREE_OPERAND (exp, 0));
1785 /* ... fall through ... */
1788 /* Referencing a volatile value is a side effect, so don't warn. */
1789 if ((TREE_CODE_CLASS (TREE_CODE (exp)) == 'd'
1790 || TREE_CODE_CLASS (TREE_CODE (exp)) == 'r')
1791 && TREE_THIS_VOLATILE (exp))
1794 warning_with_file_and_line (emit_filename, emit_lineno,
1795 "value computed is not used");
1800 /* Clear out the memory of the last expression evaluated. */
1808 /* Begin a statement which will return a value.
1809 Return the RTL_EXPR for this statement expr.
1810 The caller must save that value and pass it to expand_end_stmt_expr. */
1813 expand_start_stmt_expr ()
1818 /* Make the RTL_EXPR node temporary, not momentary,
1819 so that rtl_expr_chain doesn't become garbage. */
1820 momentary = suspend_momentary ();
1821 t = make_node (RTL_EXPR);
1822 resume_momentary (momentary);
1823 do_pending_stack_adjust ();
1824 start_sequence_for_rtl_expr (t);
1826 expr_stmts_for_value++;
1830 /* Restore the previous state at the end of a statement that returns a value.
1831 Returns a tree node representing the statement's value and the
1832 insns to compute the value.
1834 The nodes of that expression have been freed by now, so we cannot use them.
1835 But we don't want to do that anyway; the expression has already been
1836 evaluated and now we just want to use the value. So generate a RTL_EXPR
1837 with the proper type and RTL value.
1839 If the last substatement was not an expression,
1840 return something with type `void'. */
1843 expand_end_stmt_expr (t)
1848 if (last_expr_type == 0)
1850 last_expr_type = void_type_node;
1851 last_expr_value = const0_rtx;
1853 else if (last_expr_value == 0)
1854 /* There are some cases where this can happen, such as when the
1855 statement is void type. */
1856 last_expr_value = const0_rtx;
1857 else if (GET_CODE (last_expr_value) != REG && ! CONSTANT_P (last_expr_value))
1858 /* Remove any possible QUEUED. */
1859 last_expr_value = protect_from_queue (last_expr_value, 0);
1863 TREE_TYPE (t) = last_expr_type;
1864 RTL_EXPR_RTL (t) = last_expr_value;
1865 RTL_EXPR_SEQUENCE (t) = get_insns ();
1867 rtl_expr_chain = tree_cons (NULL_TREE, t, rtl_expr_chain);
1871 /* Don't consider deleting this expr or containing exprs at tree level. */
1872 TREE_SIDE_EFFECTS (t) = 1;
1873 /* Propagate volatility of the actual RTL expr. */
1874 TREE_THIS_VOLATILE (t) = volatile_refs_p (last_expr_value);
1877 expr_stmts_for_value--;
1882 /* Generate RTL for the start of an if-then. COND is the expression
1883 whose truth should be tested.
1885 If EXITFLAG is nonzero, this conditional is visible to
1886 `exit_something'. */
1889 expand_start_cond (cond, exitflag)
1893 struct nesting *thiscond = ALLOC_NESTING ();
1895 /* Make an entry on cond_stack for the cond we are entering. */
1897 thiscond->next = cond_stack;
1898 thiscond->all = nesting_stack;
1899 thiscond->depth = ++nesting_depth;
1900 thiscond->data.cond.next_label = gen_label_rtx ();
1901 /* Before we encounter an `else', we don't need a separate exit label
1902 unless there are supposed to be exit statements
1903 to exit this conditional. */
1904 thiscond->exit_label = exitflag ? gen_label_rtx () : 0;
1905 thiscond->data.cond.endif_label = thiscond->exit_label;
1906 cond_stack = thiscond;
1907 nesting_stack = thiscond;
1909 do_jump (cond, thiscond->data.cond.next_label, NULL_RTX);
1912 /* Generate RTL between then-clause and the elseif-clause
1913 of an if-then-elseif-.... */
1916 expand_start_elseif (cond)
1919 if (cond_stack->data.cond.endif_label == 0)
1920 cond_stack->data.cond.endif_label = gen_label_rtx ();
1921 emit_jump (cond_stack->data.cond.endif_label);
1922 emit_label (cond_stack->data.cond.next_label);
1923 cond_stack->data.cond.next_label = gen_label_rtx ();
1924 do_jump (cond, cond_stack->data.cond.next_label, NULL_RTX);
1927 /* Generate RTL between the then-clause and the else-clause
1928 of an if-then-else. */
1931 expand_start_else ()
1933 if (cond_stack->data.cond.endif_label == 0)
1934 cond_stack->data.cond.endif_label = gen_label_rtx ();
1936 emit_jump (cond_stack->data.cond.endif_label);
1937 emit_label (cond_stack->data.cond.next_label);
1938 cond_stack->data.cond.next_label = 0; /* No more _else or _elseif calls. */
1941 /* After calling expand_start_else, turn this "else" into an "else if"
1942 by providing another condition. */
1945 expand_elseif (cond)
1948 cond_stack->data.cond.next_label = gen_label_rtx ();
1949 do_jump (cond, cond_stack->data.cond.next_label, NULL_RTX);
1952 /* Generate RTL for the end of an if-then.
1953 Pop the record for it off of cond_stack. */
1958 struct nesting *thiscond = cond_stack;
1960 do_pending_stack_adjust ();
1961 if (thiscond->data.cond.next_label)
1962 emit_label (thiscond->data.cond.next_label);
1963 if (thiscond->data.cond.endif_label)
1964 emit_label (thiscond->data.cond.endif_label);
1966 POPSTACK (cond_stack);
1972 /* Generate RTL for the start of a loop. EXIT_FLAG is nonzero if this
1973 loop should be exited by `exit_something'. This is a loop for which
1974 `expand_continue' will jump to the top of the loop.
1976 Make an entry on loop_stack to record the labels associated with
1980 expand_start_loop (exit_flag)
1983 register struct nesting *thisloop = ALLOC_NESTING ();
1985 /* Make an entry on loop_stack for the loop we are entering. */
1987 thisloop->next = loop_stack;
1988 thisloop->all = nesting_stack;
1989 thisloop->depth = ++nesting_depth;
1990 thisloop->data.loop.start_label = gen_label_rtx ();
1991 thisloop->data.loop.end_label = gen_label_rtx ();
1992 thisloop->data.loop.alt_end_label = 0;
1993 thisloop->data.loop.continue_label = thisloop->data.loop.start_label;
1994 thisloop->exit_label = exit_flag ? thisloop->data.loop.end_label : 0;
1995 loop_stack = thisloop;
1996 nesting_stack = thisloop;
1998 do_pending_stack_adjust ();
2000 emit_note (NULL_PTR, NOTE_INSN_LOOP_BEG);
2001 emit_label (thisloop->data.loop.start_label);
2006 /* Like expand_start_loop but for a loop where the continuation point
2007 (for expand_continue_loop) will be specified explicitly. */
2010 expand_start_loop_continue_elsewhere (exit_flag)
2013 struct nesting *thisloop = expand_start_loop (exit_flag);
2014 loop_stack->data.loop.continue_label = gen_label_rtx ();
2018 /* Specify the continuation point for a loop started with
2019 expand_start_loop_continue_elsewhere.
2020 Use this at the point in the code to which a continue statement
2024 expand_loop_continue_here ()
2026 do_pending_stack_adjust ();
2027 emit_note (NULL_PTR, NOTE_INSN_LOOP_CONT);
2028 emit_label (loop_stack->data.loop.continue_label);
2031 /* Finish a loop. Generate a jump back to the top and the loop-exit label.
2032 Pop the block off of loop_stack. */
2037 rtx start_label = loop_stack->data.loop.start_label;
2038 rtx insn = get_last_insn ();
2039 int needs_end_jump = 1;
2041 /* Mark the continue-point at the top of the loop if none elsewhere. */
2042 if (start_label == loop_stack->data.loop.continue_label)
2043 emit_note_before (NOTE_INSN_LOOP_CONT, start_label);
2045 do_pending_stack_adjust ();
2047 /* If optimizing, perhaps reorder the loop.
2048 First, try to use a condjump near the end.
2049 expand_exit_loop_if_false ends loops with unconditional jumps,
2052 if (test) goto label;
2054 goto loop_stack->data.loop.end_label
2058 If we find such a pattern, we can end the loop earlier. */
2061 && GET_CODE (insn) == CODE_LABEL
2062 && LABEL_NAME (insn) == NULL
2063 && GET_CODE (PREV_INSN (insn)) == BARRIER)
2066 rtx jump = PREV_INSN (PREV_INSN (label));
2068 if (GET_CODE (jump) == JUMP_INSN
2069 && GET_CODE (PATTERN (jump)) == SET
2070 && SET_DEST (PATTERN (jump)) == pc_rtx
2071 && GET_CODE (SET_SRC (PATTERN (jump))) == LABEL_REF
2072 && (XEXP (SET_SRC (PATTERN (jump)), 0)
2073 == loop_stack->data.loop.end_label))
2077 /* The test might be complex and reference LABEL multiple times,
2078 like the loop in loop_iterations to set vtop. To handle this,
2080 insn = PREV_INSN (label);
2081 reorder_insns (label, label, start_label);
2083 for (prev = PREV_INSN (jump); ; prev = PREV_INSN (prev))
2085 /* We ignore line number notes, but if we see any other note,
2086 in particular NOTE_INSN_BLOCK_*, NOTE_INSN_EH_REGION_*,
2087 NOTE_INSN_LOOP_*, we disable this optimization. */
2088 if (GET_CODE (prev) == NOTE)
2090 if (NOTE_LINE_NUMBER (prev) < 0)
2094 if (GET_CODE (prev) == CODE_LABEL)
2096 if (GET_CODE (prev) == JUMP_INSN)
2098 if (GET_CODE (PATTERN (prev)) == SET
2099 && SET_DEST (PATTERN (prev)) == pc_rtx
2100 && GET_CODE (SET_SRC (PATTERN (prev))) == IF_THEN_ELSE
2101 && (GET_CODE (XEXP (SET_SRC (PATTERN (prev)), 1))
2103 && XEXP (XEXP (SET_SRC (PATTERN (prev)), 1), 0) == label)
2105 XEXP (XEXP (SET_SRC (PATTERN (prev)), 1), 0)
2107 emit_note_after (NOTE_INSN_LOOP_END, prev);
2116 /* If the loop starts with a loop exit, roll that to the end where
2117 it will optimize together with the jump back.
2119 We look for the conditional branch to the exit, except that once
2120 we find such a branch, we don't look past 30 instructions.
2122 In more detail, if the loop presently looks like this (in pseudo-C):
2125 if (test) goto end_label;
2130 transform it to look like:
2136 if (test) goto end_label;
2137 goto newstart_label;
2140 Here, the `test' may actually consist of some reasonably complex
2141 code, terminating in a test. */
2146 ! (GET_CODE (insn) == JUMP_INSN
2147 && GET_CODE (PATTERN (insn)) == SET
2148 && SET_DEST (PATTERN (insn)) == pc_rtx
2149 && GET_CODE (SET_SRC (PATTERN (insn))) == IF_THEN_ELSE))
2153 rtx last_test_insn = NULL_RTX;
2155 /* Scan insns from the top of the loop looking for a qualified
2156 conditional exit. */
2157 for (insn = NEXT_INSN (loop_stack->data.loop.start_label); insn;
2158 insn = NEXT_INSN (insn))
2160 if (GET_CODE (insn) == NOTE)
2163 && (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG
2164 || NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END))
2165 /* The code that actually moves the exit test will
2166 carefully leave BLOCK notes in their original
2167 location. That means, however, that we can't debug
2168 the exit test itself. So, we refuse to move code
2169 containing BLOCK notes at low optimization levels. */
2172 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG)
2174 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END)
2178 /* We've come to the end of an EH region, but
2179 never saw the beginning of that region. That
2180 means that an EH region begins before the top
2181 of the loop, and ends in the middle of it. The
2182 existence of such a situation violates a basic
2183 assumption in this code, since that would imply
2184 that even when EH_REGIONS is zero, we might
2185 move code out of an exception region. */
2189 /* We must not walk into a nested loop. */
2190 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
2193 /* We already know this INSN is a NOTE, so there's no
2194 point in looking at it to see if it's a JUMP. */
2198 if (GET_CODE (insn) == JUMP_INSN || GET_CODE (insn) == INSN)
2201 if (last_test_insn && num_insns > 30)
2205 /* We don't want to move a partial EH region. Consider:
2219 This isn't legal C++, but here's what it's supposed to
2220 mean: if cond() is true, stop looping. Otherwise,
2221 call bar, and keep looping. In addition, if cond
2222 throws an exception, catch it and keep looping. Such
2223 constructs are certainy legal in LISP.
2225 We should not move the `if (cond()) 0' test since then
2226 the EH-region for the try-block would be broken up.
2227 (In this case we would the EH_BEG note for the `try'
2228 and `if cond()' but not the call to bar() or the
2231 So we don't look for tests within an EH region. */
2234 if (GET_CODE (insn) == JUMP_INSN
2235 && GET_CODE (PATTERN (insn)) == SET
2236 && SET_DEST (PATTERN (insn)) == pc_rtx)
2238 /* This is indeed a jump. */
2239 rtx dest1 = NULL_RTX;
2240 rtx dest2 = NULL_RTX;
2241 rtx potential_last_test;
2242 if (GET_CODE (SET_SRC (PATTERN (insn))) == IF_THEN_ELSE)
2244 /* A conditional jump. */
2245 dest1 = XEXP (SET_SRC (PATTERN (insn)), 1);
2246 dest2 = XEXP (SET_SRC (PATTERN (insn)), 2);
2247 potential_last_test = insn;
2251 /* An unconditional jump. */
2252 dest1 = SET_SRC (PATTERN (insn));
2253 /* Include the BARRIER after the JUMP. */
2254 potential_last_test = NEXT_INSN (insn);
2258 if (dest1 && GET_CODE (dest1) == LABEL_REF
2259 && ((XEXP (dest1, 0)
2260 == loop_stack->data.loop.alt_end_label)
2262 == loop_stack->data.loop.end_label)))
2264 last_test_insn = potential_last_test;
2268 /* If this was a conditional jump, there may be
2269 another label at which we should look. */
2276 if (last_test_insn != 0 && last_test_insn != get_last_insn ())
2278 /* We found one. Move everything from there up
2279 to the end of the loop, and add a jump into the loop
2280 to jump to there. */
2281 register rtx newstart_label = gen_label_rtx ();
2282 register rtx start_move = start_label;
2285 /* If the start label is preceded by a NOTE_INSN_LOOP_CONT note,
2286 then we want to move this note also. */
2287 if (GET_CODE (PREV_INSN (start_move)) == NOTE
2288 && (NOTE_LINE_NUMBER (PREV_INSN (start_move))
2289 == NOTE_INSN_LOOP_CONT))
2290 start_move = PREV_INSN (start_move);
2292 emit_label_after (newstart_label, PREV_INSN (start_move));
2294 /* Actually move the insns. Start at the beginning, and
2295 keep copying insns until we've copied the
2297 for (insn = start_move; insn; insn = next_insn)
2299 /* Figure out which insn comes after this one. We have
2300 to do this before we move INSN. */
2301 if (insn == last_test_insn)
2302 /* We've moved all the insns. */
2303 next_insn = NULL_RTX;
2305 next_insn = NEXT_INSN (insn);
2307 if (GET_CODE (insn) == NOTE
2308 && (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG
2309 || NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END))
2310 /* We don't want to move NOTE_INSN_BLOCK_BEGs or
2311 NOTE_INSN_BLOCK_ENDs because the correct generation
2312 of debugging information depends on these appearing
2313 in the same order in the RTL and in the tree
2314 structure, where they are represented as BLOCKs.
2315 So, we don't move block notes. Of course, moving
2316 the code inside the block is likely to make it
2317 impossible to debug the instructions in the exit
2318 test, but such is the price of optimization. */
2321 /* Move the INSN. */
2322 reorder_insns (insn, insn, get_last_insn ());
2325 emit_jump_insn_after (gen_jump (start_label),
2326 PREV_INSN (newstart_label));
2327 emit_barrier_after (PREV_INSN (newstart_label));
2328 start_label = newstart_label;
2334 emit_jump (start_label);
2335 emit_note (NULL_PTR, NOTE_INSN_LOOP_END);
2337 emit_label (loop_stack->data.loop.end_label);
2339 POPSTACK (loop_stack);
2344 /* Generate a jump to the current loop's continue-point.
2345 This is usually the top of the loop, but may be specified
2346 explicitly elsewhere. If not currently inside a loop,
2347 return 0 and do nothing; caller will print an error message. */
2350 expand_continue_loop (whichloop)
2351 struct nesting *whichloop;
2355 whichloop = loop_stack;
2358 expand_goto_internal (NULL_TREE, whichloop->data.loop.continue_label,
2363 /* Generate a jump to exit the current loop. If not currently inside a loop,
2364 return 0 and do nothing; caller will print an error message. */
2367 expand_exit_loop (whichloop)
2368 struct nesting *whichloop;
2372 whichloop = loop_stack;
2375 expand_goto_internal (NULL_TREE, whichloop->data.loop.end_label, NULL_RTX);
2379 /* Generate a conditional jump to exit the current loop if COND
2380 evaluates to zero. If not currently inside a loop,
2381 return 0 and do nothing; caller will print an error message. */
2384 expand_exit_loop_if_false (whichloop, cond)
2385 struct nesting *whichloop;
2388 rtx label = gen_label_rtx ();
2393 whichloop = loop_stack;
2396 /* In order to handle fixups, we actually create a conditional jump
2397 around a unconditional branch to exit the loop. If fixups are
2398 necessary, they go before the unconditional branch. */
2401 do_jump (cond, NULL_RTX, label);
2402 last_insn = get_last_insn ();
2403 if (GET_CODE (last_insn) == CODE_LABEL)
2404 whichloop->data.loop.alt_end_label = last_insn;
2405 expand_goto_internal (NULL_TREE, whichloop->data.loop.end_label,
2412 /* Return nonzero if the loop nest is empty. Else return zero. */
2415 stmt_loop_nest_empty ()
2417 return (loop_stack == NULL);
2420 /* Return non-zero if we should preserve sub-expressions as separate
2421 pseudos. We never do so if we aren't optimizing. We always do so
2422 if -fexpensive-optimizations.
2424 Otherwise, we only do so if we are in the "early" part of a loop. I.e.,
2425 the loop may still be a small one. */
2428 preserve_subexpressions_p ()
2432 if (flag_expensive_optimizations)
2435 if (optimize == 0 || current_function == 0 || loop_stack == 0)
2438 insn = get_last_insn_anywhere ();
2441 && (INSN_UID (insn) - INSN_UID (loop_stack->data.loop.start_label)
2442 < n_non_fixed_regs * 3));
2446 /* Generate a jump to exit the current loop, conditional, binding contour
2447 or case statement. Not all such constructs are visible to this function,
2448 only those started with EXIT_FLAG nonzero. Individual languages use
2449 the EXIT_FLAG parameter to control which kinds of constructs you can
2452 If not currently inside anything that can be exited,
2453 return 0 and do nothing; caller will print an error message. */
2456 expand_exit_something ()
2460 for (n = nesting_stack; n; n = n->all)
2461 if (n->exit_label != 0)
2463 expand_goto_internal (NULL_TREE, n->exit_label, NULL_RTX);
2470 /* Generate RTL to return from the current function, with no value.
2471 (That is, we do not do anything about returning any value.) */
2474 expand_null_return ()
2476 struct nesting *block = block_stack;
2479 /* Does any pending block have cleanups? */
2481 while (block && block->data.block.cleanups == 0)
2482 block = block->next;
2484 /* If yes, use a goto to return, since that runs cleanups. */
2486 expand_null_return_1 (last_insn, block != 0);
2489 /* Generate RTL to return from the current function, with value VAL. */
2492 expand_value_return (val)
2495 struct nesting *block = block_stack;
2496 rtx last_insn = get_last_insn ();
2497 rtx return_reg = DECL_RTL (DECL_RESULT (current_function_decl));
2499 /* Copy the value to the return location
2500 unless it's already there. */
2502 if (return_reg != val)
2504 #ifdef PROMOTE_FUNCTION_RETURN
2505 tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
2506 int unsignedp = TREE_UNSIGNED (type);
2507 enum machine_mode mode
2508 = promote_mode (type, DECL_MODE (DECL_RESULT (current_function_decl)),
2511 if (GET_MODE (val) != VOIDmode && GET_MODE (val) != mode)
2512 convert_move (return_reg, val, unsignedp);
2515 emit_move_insn (return_reg, val);
2517 if (GET_CODE (return_reg) == REG
2518 && REGNO (return_reg) < FIRST_PSEUDO_REGISTER)
2519 emit_insn (gen_rtx_USE (VOIDmode, return_reg));
2520 /* Handle calls that return values in multiple non-contiguous locations.
2521 The Irix 6 ABI has examples of this. */
2522 else if (GET_CODE (return_reg) == PARALLEL)
2526 for (i = 0; i < XVECLEN (return_reg, 0); i++)
2528 rtx x = XEXP (XVECEXP (return_reg, 0, i), 0);
2530 if (GET_CODE (x) == REG
2531 && REGNO (x) < FIRST_PSEUDO_REGISTER)
2532 emit_insn (gen_rtx_USE (VOIDmode, x));
2536 /* Does any pending block have cleanups? */
2538 while (block && block->data.block.cleanups == 0)
2539 block = block->next;
2541 /* If yes, use a goto to return, since that runs cleanups.
2542 Use LAST_INSN to put cleanups *before* the move insn emitted above. */
2544 expand_null_return_1 (last_insn, block != 0);
2547 /* Output a return with no value. If LAST_INSN is nonzero,
2548 pretend that the return takes place after LAST_INSN.
2549 If USE_GOTO is nonzero then don't use a return instruction;
2550 go to the return label instead. This causes any cleanups
2551 of pending blocks to be executed normally. */
2554 expand_null_return_1 (last_insn, use_goto)
2558 rtx end_label = cleanup_label ? cleanup_label : return_label;
2560 clear_pending_stack_adjust ();
2561 do_pending_stack_adjust ();
2564 /* PCC-struct return always uses an epilogue. */
2565 if (current_function_returns_pcc_struct || use_goto)
2568 end_label = return_label = gen_label_rtx ();
2569 expand_goto_internal (NULL_TREE, end_label, last_insn);
2573 /* Otherwise output a simple return-insn if one is available,
2574 unless it won't do the job. */
2576 if (HAVE_return && use_goto == 0 && cleanup_label == 0)
2578 emit_jump_insn (gen_return ());
2584 /* Otherwise jump to the epilogue. */
2585 expand_goto_internal (NULL_TREE, end_label, last_insn);
2588 /* Generate RTL to evaluate the expression RETVAL and return it
2589 from the current function. */
2592 expand_return (retval)
2595 /* If there are any cleanups to be performed, then they will
2596 be inserted following LAST_INSN. It is desirable
2597 that the last_insn, for such purposes, should be the
2598 last insn before computing the return value. Otherwise, cleanups
2599 which call functions can clobber the return value. */
2600 /* ??? rms: I think that is erroneous, because in C++ it would
2601 run destructors on variables that might be used in the subsequent
2602 computation of the return value. */
2604 register rtx val = 0;
2609 /* If function wants no value, give it none. */
2610 if (TREE_CODE (TREE_TYPE (TREE_TYPE (current_function_decl))) == VOID_TYPE)
2612 expand_expr (retval, NULL_RTX, VOIDmode, 0);
2614 expand_null_return ();
2618 /* Are any cleanups needed? E.g. C++ destructors to be run? */
2619 /* This is not sufficient. We also need to watch for cleanups of the
2620 expression we are about to expand. Unfortunately, we cannot know
2621 if it has cleanups until we expand it, and we want to change how we
2622 expand it depending upon if we need cleanups. We can't win. */
2624 cleanups = any_pending_cleanups (1);
2629 if (TREE_CODE (retval) == RESULT_DECL)
2630 retval_rhs = retval;
2631 else if ((TREE_CODE (retval) == MODIFY_EXPR || TREE_CODE (retval) == INIT_EXPR)
2632 && TREE_CODE (TREE_OPERAND (retval, 0)) == RESULT_DECL)
2633 retval_rhs = TREE_OPERAND (retval, 1);
2634 else if (TREE_TYPE (retval) == void_type_node)
2635 /* Recognize tail-recursive call to void function. */
2636 retval_rhs = retval;
2638 retval_rhs = NULL_TREE;
2640 /* Only use `last_insn' if there are cleanups which must be run. */
2641 if (cleanups || cleanup_label != 0)
2642 last_insn = get_last_insn ();
2644 /* Distribute return down conditional expr if either of the sides
2645 may involve tail recursion (see test below). This enhances the number
2646 of tail recursions we see. Don't do this always since it can produce
2647 sub-optimal code in some cases and we distribute assignments into
2648 conditional expressions when it would help. */
2650 if (optimize && retval_rhs != 0
2651 && frame_offset == 0
2652 && TREE_CODE (retval_rhs) == COND_EXPR
2653 && (TREE_CODE (TREE_OPERAND (retval_rhs, 1)) == CALL_EXPR
2654 || TREE_CODE (TREE_OPERAND (retval_rhs, 2)) == CALL_EXPR))
2656 rtx label = gen_label_rtx ();
2659 do_jump (TREE_OPERAND (retval_rhs, 0), label, NULL_RTX);
2660 start_cleanup_deferral ();
2661 expr = build (MODIFY_EXPR, TREE_TYPE (TREE_TYPE (current_function_decl)),
2662 DECL_RESULT (current_function_decl),
2663 TREE_OPERAND (retval_rhs, 1));
2664 TREE_SIDE_EFFECTS (expr) = 1;
2665 expand_return (expr);
2668 expr = build (MODIFY_EXPR, TREE_TYPE (TREE_TYPE (current_function_decl)),
2669 DECL_RESULT (current_function_decl),
2670 TREE_OPERAND (retval_rhs, 2));
2671 TREE_SIDE_EFFECTS (expr) = 1;
2672 expand_return (expr);
2673 end_cleanup_deferral ();
2677 /* Attempt to optimize the call if it is tail recursive. */
2678 if (optimize_tail_recursion (retval_rhs, last_insn))
2682 /* This optimization is safe if there are local cleanups
2683 because expand_null_return takes care of them.
2684 ??? I think it should also be safe when there is a cleanup label,
2685 because expand_null_return takes care of them, too.
2686 Any reason why not? */
2687 if (HAVE_return && cleanup_label == 0
2688 && ! current_function_returns_pcc_struct
2689 && BRANCH_COST <= 1)
2691 /* If this is return x == y; then generate
2692 if (x == y) return 1; else return 0;
2693 if we can do it with explicit return insns and branches are cheap,
2694 but not if we have the corresponding scc insn. */
2697 switch (TREE_CODE (retval_rhs))
2723 case TRUTH_ANDIF_EXPR:
2724 case TRUTH_ORIF_EXPR:
2725 case TRUTH_AND_EXPR:
2727 case TRUTH_NOT_EXPR:
2728 case TRUTH_XOR_EXPR:
2731 op0 = gen_label_rtx ();
2732 jumpifnot (retval_rhs, op0);
2733 expand_value_return (const1_rtx);
2735 expand_value_return (const0_rtx);
2744 #endif /* HAVE_return */
2746 /* If the result is an aggregate that is being returned in one (or more)
2747 registers, load the registers here. The compiler currently can't handle
2748 copying a BLKmode value into registers. We could put this code in a
2749 more general area (for use by everyone instead of just function
2750 call/return), but until this feature is generally usable it is kept here
2751 (and in expand_call). The value must go into a pseudo in case there
2752 are cleanups that will clobber the real return register. */
2755 && TYPE_MODE (TREE_TYPE (retval_rhs)) == BLKmode
2756 && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG)
2758 int i, bitpos, xbitpos;
2759 int big_endian_correction = 0;
2760 int bytes = int_size_in_bytes (TREE_TYPE (retval_rhs));
2761 int n_regs = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
2762 int bitsize = MIN (TYPE_ALIGN (TREE_TYPE (retval_rhs)),
2763 (unsigned int)BITS_PER_WORD);
2764 rtx *result_pseudos = (rtx *) alloca (sizeof (rtx) * n_regs);
2765 rtx result_reg, src = NULL_RTX, dst = NULL_RTX;
2766 rtx result_val = expand_expr (retval_rhs, NULL_RTX, VOIDmode, 0);
2767 enum machine_mode tmpmode, result_reg_mode;
2769 /* Structures whose size is not a multiple of a word are aligned
2770 to the least significant byte (to the right). On a BYTES_BIG_ENDIAN
2771 machine, this means we must skip the empty high order bytes when
2772 calculating the bit offset. */
2773 if (BYTES_BIG_ENDIAN && bytes % UNITS_PER_WORD)
2774 big_endian_correction = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD)
2777 /* Copy the structure BITSIZE bits at a time. */
2778 for (bitpos = 0, xbitpos = big_endian_correction;
2779 bitpos < bytes * BITS_PER_UNIT;
2780 bitpos += bitsize, xbitpos += bitsize)
2782 /* We need a new destination pseudo each time xbitpos is
2783 on a word boundary and when xbitpos == big_endian_correction
2784 (the first time through). */
2785 if (xbitpos % BITS_PER_WORD == 0
2786 || xbitpos == big_endian_correction)
2788 /* Generate an appropriate register. */
2789 dst = gen_reg_rtx (word_mode);
2790 result_pseudos[xbitpos / BITS_PER_WORD] = dst;
2792 /* Clobber the destination before we move anything into it. */
2793 emit_insn (gen_rtx_CLOBBER (VOIDmode, dst));
2796 /* We need a new source operand each time bitpos is on a word
2798 if (bitpos % BITS_PER_WORD == 0)
2799 src = operand_subword_force (result_val,
2800 bitpos / BITS_PER_WORD,
2803 /* Use bitpos for the source extraction (left justified) and
2804 xbitpos for the destination store (right justified). */
2805 store_bit_field (dst, bitsize, xbitpos % BITS_PER_WORD, word_mode,
2806 extract_bit_field (src, bitsize,
2807 bitpos % BITS_PER_WORD, 1,
2808 NULL_RTX, word_mode,
2810 bitsize / BITS_PER_UNIT,
2812 bitsize / BITS_PER_UNIT, BITS_PER_WORD);
2815 /* Find the smallest integer mode large enough to hold the
2816 entire structure and use that mode instead of BLKmode
2817 on the USE insn for the return register. */
2818 bytes = int_size_in_bytes (TREE_TYPE (retval_rhs));
2819 for (tmpmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2820 tmpmode != VOIDmode;
2821 tmpmode = GET_MODE_WIDER_MODE (tmpmode))
2823 /* Have we found a large enough mode? */
2824 if (GET_MODE_SIZE (tmpmode) >= bytes)
2828 /* No suitable mode found. */
2829 if (tmpmode == VOIDmode)
2832 PUT_MODE (DECL_RTL (DECL_RESULT (current_function_decl)), tmpmode);
2834 if (GET_MODE_SIZE (tmpmode) < GET_MODE_SIZE (word_mode))
2835 result_reg_mode = word_mode;
2837 result_reg_mode = tmpmode;
2838 result_reg = gen_reg_rtx (result_reg_mode);
2841 for (i = 0; i < n_regs; i++)
2842 emit_move_insn (operand_subword (result_reg, i, 0, result_reg_mode),
2845 if (tmpmode != result_reg_mode)
2846 result_reg = gen_lowpart (tmpmode, result_reg);
2848 expand_value_return (result_reg);
2852 && TREE_TYPE (retval_rhs) != void_type_node
2853 && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG)
2855 /* Calculate the return value into a pseudo reg. */
2856 val = gen_reg_rtx (DECL_MODE (DECL_RESULT (current_function_decl)));
2857 val = expand_expr (retval_rhs, val, GET_MODE (val), 0);
2858 val = force_not_mem (val);
2860 /* Return the calculated value, doing cleanups first. */
2861 expand_value_return (val);
2865 /* No cleanups or no hard reg used;
2866 calculate value into hard return reg. */
2867 expand_expr (retval, const0_rtx, VOIDmode, 0);
2869 expand_value_return (DECL_RTL (DECL_RESULT (current_function_decl)));
2873 /* Return 1 if the end of the generated RTX is not a barrier.
2874 This means code already compiled can drop through. */
2877 drop_through_at_end_p ()
2879 rtx insn = get_last_insn ();
2880 while (insn && GET_CODE (insn) == NOTE)
2881 insn = PREV_INSN (insn);
2882 return insn && GET_CODE (insn) != BARRIER;
2885 /* Test CALL_EXPR to determine if it is a potential tail recursion call
2886 and emit code to optimize the tail recursion. LAST_INSN indicates where
2887 to place the jump to the tail recursion label. Return TRUE if the
2888 call was optimized into a goto.
2890 This is only used by expand_return, but expand_call is expected to
2894 optimize_tail_recursion (call_expr, last_insn)
2898 /* For tail-recursive call to current function,
2899 just jump back to the beginning.
2900 It's unsafe if any auto variable in this function
2901 has its address taken; for simplicity,
2902 require stack frame to be empty. */
2903 if (optimize && call_expr != 0
2904 && frame_offset == 0
2905 && TREE_CODE (call_expr) == CALL_EXPR
2906 && TREE_CODE (TREE_OPERAND (call_expr, 0)) == ADDR_EXPR
2907 && TREE_OPERAND (TREE_OPERAND (call_expr, 0), 0) == current_function_decl
2908 /* Finish checking validity, and if valid emit code
2909 to set the argument variables for the new call. */
2910 && tail_recursion_args (TREE_OPERAND (call_expr, 1),
2911 DECL_ARGUMENTS (current_function_decl)))
2913 if (tail_recursion_label == 0)
2915 tail_recursion_label = gen_label_rtx ();
2916 emit_label_after (tail_recursion_label,
2917 tail_recursion_reentry);
2920 expand_goto_internal (NULL_TREE, tail_recursion_label, last_insn);
2928 /* Emit code to alter this function's formal parms for a tail-recursive call.
2929 ACTUALS is a list of actual parameter expressions (chain of TREE_LISTs).
2930 FORMALS is the chain of decls of formals.
2931 Return 1 if this can be done;
2932 otherwise return 0 and do not emit any code. */
2935 tail_recursion_args (actuals, formals)
2936 tree actuals, formals;
2938 register tree a = actuals, f = formals;
2940 register rtx *argvec;
2942 /* Check that number and types of actuals are compatible
2943 with the formals. This is not always true in valid C code.
2944 Also check that no formal needs to be addressable
2945 and that all formals are scalars. */
2947 /* Also count the args. */
2949 for (a = actuals, f = formals, i = 0; a && f; a = TREE_CHAIN (a), f = TREE_CHAIN (f), i++)
2951 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (a)))
2952 != TYPE_MAIN_VARIANT (TREE_TYPE (f)))
2954 if (GET_CODE (DECL_RTL (f)) != REG || DECL_MODE (f) == BLKmode)
2957 if (a != 0 || f != 0)
2960 /* Compute all the actuals. */
2962 argvec = (rtx *) alloca (i * sizeof (rtx));
2964 for (a = actuals, i = 0; a; a = TREE_CHAIN (a), i++)
2965 argvec[i] = expand_expr (TREE_VALUE (a), NULL_RTX, VOIDmode, 0);
2967 /* Find which actual values refer to current values of previous formals.
2968 Copy each of them now, before any formal is changed. */
2970 for (a = actuals, i = 0; a; a = TREE_CHAIN (a), i++)
2974 for (f = formals, j = 0; j < i; f = TREE_CHAIN (f), j++)
2975 if (reg_mentioned_p (DECL_RTL (f), argvec[i]))
2976 { copy = 1; break; }
2978 argvec[i] = copy_to_reg (argvec[i]);
2981 /* Store the values of the actuals into the formals. */
2983 for (f = formals, a = actuals, i = 0; f;
2984 f = TREE_CHAIN (f), a = TREE_CHAIN (a), i++)
2986 if (GET_MODE (DECL_RTL (f)) == GET_MODE (argvec[i]))
2987 emit_move_insn (DECL_RTL (f), argvec[i]);
2989 convert_move (DECL_RTL (f), argvec[i],
2990 TREE_UNSIGNED (TREE_TYPE (TREE_VALUE (a))));
2997 /* Generate the RTL code for entering a binding contour.
2998 The variables are declared one by one, by calls to `expand_decl'.
3000 EXIT_FLAG is nonzero if this construct should be visible to
3001 `exit_something'. */
3004 expand_start_bindings (exit_flag)
3007 struct nesting *thisblock = ALLOC_NESTING ();
3008 rtx note = emit_note (NULL_PTR, NOTE_INSN_BLOCK_BEG);
3010 /* Make an entry on block_stack for the block we are entering. */
3012 thisblock->next = block_stack;
3013 thisblock->all = nesting_stack;
3014 thisblock->depth = ++nesting_depth;
3015 thisblock->data.block.stack_level = 0;
3016 thisblock->data.block.cleanups = 0;
3017 thisblock->data.block.n_function_calls = 0;
3018 thisblock->data.block.exception_region = 0;
3019 thisblock->data.block.block_target_temp_slot_level = target_temp_slot_level;
3021 thisblock->data.block.conditional_code = 0;
3022 thisblock->data.block.last_unconditional_cleanup = note;
3023 thisblock->data.block.cleanup_ptr = &thisblock->data.block.cleanups;
3026 && !(block_stack->data.block.cleanups == NULL_TREE
3027 && block_stack->data.block.outer_cleanups == NULL_TREE))
3028 thisblock->data.block.outer_cleanups
3029 = tree_cons (NULL_TREE, block_stack->data.block.cleanups,
3030 block_stack->data.block.outer_cleanups);
3032 thisblock->data.block.outer_cleanups = 0;
3033 thisblock->data.block.label_chain = 0;
3034 thisblock->data.block.innermost_stack_block = stack_block_stack;
3035 thisblock->data.block.first_insn = note;
3036 thisblock->data.block.block_start_count = ++current_block_start_count;
3037 thisblock->exit_label = exit_flag ? gen_label_rtx () : 0;
3038 block_stack = thisblock;
3039 nesting_stack = thisblock;
3041 /* Make a new level for allocating stack slots. */
3045 /* Specify the scope of temporaries created by TARGET_EXPRs. Similar
3046 to CLEANUP_POINT_EXPR, but handles cases when a series of calls to
3047 expand_expr are made. After we end the region, we know that all
3048 space for all temporaries that were created by TARGET_EXPRs will be
3049 destroyed and their space freed for reuse. */
3052 expand_start_target_temps ()
3054 /* This is so that even if the result is preserved, the space
3055 allocated will be freed, as we know that it is no longer in use. */
3058 /* Start a new binding layer that will keep track of all cleanup
3059 actions to be performed. */
3060 expand_start_bindings (0);
3062 target_temp_slot_level = temp_slot_level;
3066 expand_end_target_temps ()
3068 expand_end_bindings (NULL_TREE, 0, 0);
3070 /* This is so that even if the result is preserved, the space
3071 allocated will be freed, as we know that it is no longer in use. */
3075 /* Mark top block of block_stack as an implicit binding for an
3076 exception region. This is used to prevent infinite recursion when
3077 ending a binding with expand_end_bindings. It is only ever called
3078 by expand_eh_region_start, as that it the only way to create a
3079 block stack for a exception region. */
3082 mark_block_as_eh_region ()
3084 block_stack->data.block.exception_region = 1;
3085 if (block_stack->next
3086 && block_stack->next->data.block.conditional_code)
3088 block_stack->data.block.conditional_code
3089 = block_stack->next->data.block.conditional_code;
3090 block_stack->data.block.last_unconditional_cleanup
3091 = block_stack->next->data.block.last_unconditional_cleanup;
3092 block_stack->data.block.cleanup_ptr
3093 = block_stack->next->data.block.cleanup_ptr;
3097 /* True if we are currently emitting insns in an area of output code
3098 that is controlled by a conditional expression. This is used by
3099 the cleanup handling code to generate conditional cleanup actions. */
3102 conditional_context ()
3104 return block_stack && block_stack->data.block.conditional_code;
3107 /* Mark top block of block_stack as not for an implicit binding for an
3108 exception region. This is only ever done by expand_eh_region_end
3109 to let expand_end_bindings know that it is being called explicitly
3110 to end the binding layer for just the binding layer associated with
3111 the exception region, otherwise expand_end_bindings would try and
3112 end all implicit binding layers for exceptions regions, and then
3113 one normal binding layer. */
3116 mark_block_as_not_eh_region ()
3118 block_stack->data.block.exception_region = 0;
3121 /* True if the top block of block_stack was marked as for an exception
3122 region by mark_block_as_eh_region. */
3127 return (current_function && block_stack
3128 && block_stack->data.block.exception_region);
3131 /* Given a pointer to a BLOCK node, save a pointer to the most recently
3132 generated NOTE_INSN_BLOCK_END in the BLOCK_END_NOTE field of the given
3136 remember_end_note (block)
3137 register tree block;
3139 BLOCK_END_NOTE (block) = last_block_end_note;
3140 last_block_end_note = NULL_RTX;
3143 /* Emit a handler label for a nonlocal goto handler.
3144 Also emit code to store the handler label in SLOT before BEFORE_INSN. */
3147 expand_nl_handler_label (slot, before_insn)
3148 rtx slot, before_insn;
3151 rtx handler_label = gen_label_rtx ();
3153 /* Don't let jump_optimize delete the handler. */
3154 LABEL_PRESERVE_P (handler_label) = 1;
3157 emit_move_insn (slot, gen_rtx_LABEL_REF (Pmode, handler_label));
3158 insns = get_insns ();
3160 emit_insns_before (insns, before_insn);
3162 emit_label (handler_label);
3164 return handler_label;
3167 /* Emit code to restore vital registers at the beginning of a nonlocal goto
3170 expand_nl_goto_receiver ()
3172 #ifdef HAVE_nonlocal_goto
3173 if (! HAVE_nonlocal_goto)
3175 /* First adjust our frame pointer to its actual value. It was
3176 previously set to the start of the virtual area corresponding to
3177 the stacked variables when we branched here and now needs to be
3178 adjusted to the actual hardware fp value.
3180 Assignments are to virtual registers are converted by
3181 instantiate_virtual_regs into the corresponding assignment
3182 to the underlying register (fp in this case) that makes
3183 the original assignment true.
3184 So the following insn will actually be
3185 decrementing fp by STARTING_FRAME_OFFSET. */
3186 emit_move_insn (virtual_stack_vars_rtx, hard_frame_pointer_rtx);
3188 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3189 if (fixed_regs[ARG_POINTER_REGNUM])
3191 #ifdef ELIMINABLE_REGS
3192 /* If the argument pointer can be eliminated in favor of the
3193 frame pointer, we don't need to restore it. We assume here
3194 that if such an elimination is present, it can always be used.
3195 This is the case on all known machines; if we don't make this
3196 assumption, we do unnecessary saving on many machines. */
3197 static struct elims {int from, to;} elim_regs[] = ELIMINABLE_REGS;
3200 for (i = 0; i < sizeof elim_regs / sizeof elim_regs[0]; i++)
3201 if (elim_regs[i].from == ARG_POINTER_REGNUM
3202 && elim_regs[i].to == HARD_FRAME_POINTER_REGNUM)
3205 if (i == sizeof elim_regs / sizeof elim_regs [0])
3208 /* Now restore our arg pointer from the address at which it
3209 was saved in our stack frame.
3210 If there hasn't be space allocated for it yet, make
3212 if (arg_pointer_save_area == 0)
3213 arg_pointer_save_area
3214 = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
3215 emit_move_insn (virtual_incoming_args_rtx,
3216 /* We need a pseudo here, or else
3217 instantiate_virtual_regs_1 complains. */
3218 copy_to_reg (arg_pointer_save_area));
3223 #ifdef HAVE_nonlocal_goto_receiver
3224 if (HAVE_nonlocal_goto_receiver)
3225 emit_insn (gen_nonlocal_goto_receiver ());
3229 /* Make handlers for nonlocal gotos taking place in the function calls in
3233 expand_nl_goto_receivers (thisblock)
3234 struct nesting *thisblock;
3237 rtx afterward = gen_label_rtx ();
3242 /* Record the handler address in the stack slot for that purpose,
3243 during this block, saving and restoring the outer value. */
3244 if (thisblock->next != 0)
3245 for (slot = nonlocal_goto_handler_slots; slot; slot = XEXP (slot, 1))
3247 rtx save_receiver = gen_reg_rtx (Pmode);
3248 emit_move_insn (XEXP (slot, 0), save_receiver);
3251 emit_move_insn (save_receiver, XEXP (slot, 0));
3252 insns = get_insns ();
3254 emit_insns_before (insns, thisblock->data.block.first_insn);
3257 /* Jump around the handlers; they run only when specially invoked. */
3258 emit_jump (afterward);
3260 /* Make a separate handler for each label. */
3261 link = nonlocal_labels;
3262 slot = nonlocal_goto_handler_slots;
3263 label_list = NULL_RTX;
3264 for (; link; link = TREE_CHAIN (link), slot = XEXP (slot, 1))
3265 /* Skip any labels we shouldn't be able to jump to from here,
3266 we generate one special handler for all of them below which just calls
3268 if (! DECL_TOO_LATE (TREE_VALUE (link)))
3271 lab = expand_nl_handler_label (XEXP (slot, 0),
3272 thisblock->data.block.first_insn);
3273 label_list = gen_rtx_EXPR_LIST (VOIDmode, lab, label_list);
3275 expand_nl_goto_receiver ();
3277 /* Jump to the "real" nonlocal label. */
3278 expand_goto (TREE_VALUE (link));
3281 /* A second pass over all nonlocal labels; this time we handle those
3282 we should not be able to jump to at this point. */
3283 link = nonlocal_labels;
3284 slot = nonlocal_goto_handler_slots;
3286 for (; link; link = TREE_CHAIN (link), slot = XEXP (slot, 1))
3287 if (DECL_TOO_LATE (TREE_VALUE (link)))
3290 lab = expand_nl_handler_label (XEXP (slot, 0),
3291 thisblock->data.block.first_insn);
3292 label_list = gen_rtx_EXPR_LIST (VOIDmode, lab, label_list);
3298 expand_nl_goto_receiver ();
3299 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "abort"), 0,
3304 nonlocal_goto_handler_labels = label_list;
3305 emit_label (afterward);
3308 /* Generate RTL code to terminate a binding contour.
3310 VARS is the chain of VAR_DECL nodes for the variables bound in this
3311 contour. There may actually be other nodes in this chain, but any
3312 nodes other than VAR_DECLS are ignored.
3314 MARK_ENDS is nonzero if we should put a note at the beginning
3315 and end of this binding contour.
3317 DONT_JUMP_IN is nonzero if it is not valid to jump into this contour.
3318 (That is true automatically if the contour has a saved stack level.) */
3321 expand_end_bindings (vars, mark_ends, dont_jump_in)
3326 register struct nesting *thisblock;
3329 while (block_stack->data.block.exception_region)
3331 /* Because we don't need or want a new temporary level and
3332 because we didn't create one in expand_eh_region_start,
3333 create a fake one now to avoid removing one in
3334 expand_end_bindings. */
3337 block_stack->data.block.exception_region = 0;
3339 expand_end_bindings (NULL_TREE, 0, 0);
3342 /* Since expand_eh_region_start does an expand_start_bindings, we
3343 have to first end all the bindings that were created by
3344 expand_eh_region_start. */
3346 thisblock = block_stack;
3349 for (decl = vars; decl; decl = TREE_CHAIN (decl))
3350 if (TREE_CODE (decl) == VAR_DECL
3351 && ! TREE_USED (decl)
3352 && ! DECL_IN_SYSTEM_HEADER (decl)
3353 && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
3354 warning_with_decl (decl, "unused variable `%s'");
3356 if (thisblock->exit_label)
3358 do_pending_stack_adjust ();
3359 emit_label (thisblock->exit_label);
3362 /* If necessary, make handlers for nonlocal gotos taking
3363 place in the function calls in this block. */
3364 if (function_call_count != thisblock->data.block.n_function_calls
3366 /* Make handler for outermost block
3367 if there were any nonlocal gotos to this function. */
3368 && (thisblock->next == 0 ? current_function_has_nonlocal_label
3369 /* Make handler for inner block if it has something
3370 special to do when you jump out of it. */
3371 : (thisblock->data.block.cleanups != 0
3372 || thisblock->data.block.stack_level != 0)))
3373 expand_nl_goto_receivers (thisblock);
3375 /* Don't allow jumping into a block that has a stack level.
3376 Cleanups are allowed, though. */
3378 || thisblock->data.block.stack_level != 0)
3380 struct label_chain *chain;
3382 /* Any labels in this block are no longer valid to go to.
3383 Mark them to cause an error message. */
3384 for (chain = thisblock->data.block.label_chain; chain; chain = chain->next)
3386 DECL_TOO_LATE (chain->label) = 1;
3387 /* If any goto without a fixup came to this label,
3388 that must be an error, because gotos without fixups
3389 come from outside all saved stack-levels. */
3390 if (TREE_ADDRESSABLE (chain->label))
3391 error_with_decl (chain->label,
3392 "label `%s' used before containing binding contour");
3396 /* Restore stack level in effect before the block
3397 (only if variable-size objects allocated). */
3398 /* Perform any cleanups associated with the block. */
3400 if (thisblock->data.block.stack_level != 0
3401 || thisblock->data.block.cleanups != 0)
3403 /* Only clean up here if this point can actually be reached. */
3404 int reachable = GET_CODE (get_last_insn ()) != BARRIER;
3406 /* Don't let cleanups affect ({...}) constructs. */
3407 int old_expr_stmts_for_value = expr_stmts_for_value;
3408 rtx old_last_expr_value = last_expr_value;
3409 tree old_last_expr_type = last_expr_type;
3410 expr_stmts_for_value = 0;
3412 /* Do the cleanups. */
3413 expand_cleanups (thisblock->data.block.cleanups, NULL_TREE, 0, reachable);
3415 do_pending_stack_adjust ();
3417 expr_stmts_for_value = old_expr_stmts_for_value;
3418 last_expr_value = old_last_expr_value;
3419 last_expr_type = old_last_expr_type;
3421 /* Restore the stack level. */
3423 if (reachable && thisblock->data.block.stack_level != 0)
3425 emit_stack_restore (thisblock->next ? SAVE_BLOCK : SAVE_FUNCTION,
3426 thisblock->data.block.stack_level, NULL_RTX);
3427 if (nonlocal_goto_handler_slots != 0)
3428 emit_stack_save (SAVE_NONLOCAL, &nonlocal_goto_stack_level,
3432 /* Any gotos out of this block must also do these things.
3433 Also report any gotos with fixups that came to labels in this
3435 fixup_gotos (thisblock,
3436 thisblock->data.block.stack_level,
3437 thisblock->data.block.cleanups,
3438 thisblock->data.block.first_insn,
3442 /* Mark the beginning and end of the scope if requested.
3443 We do this now, after running cleanups on the variables
3444 just going out of scope, so they are in scope for their cleanups. */
3447 last_block_end_note = emit_note (NULL_PTR, NOTE_INSN_BLOCK_END);
3449 /* Get rid of the beginning-mark if we don't make an end-mark. */
3450 NOTE_LINE_NUMBER (thisblock->data.block.first_insn) = NOTE_INSN_DELETED;
3452 /* If doing stupid register allocation, make sure lives of all
3453 register variables declared here extend thru end of scope. */
3456 for (decl = vars; decl; decl = TREE_CHAIN (decl))
3457 if (TREE_CODE (decl) == VAR_DECL && DECL_RTL (decl))
3458 use_variable (DECL_RTL (decl));
3460 /* Restore the temporary level of TARGET_EXPRs. */
3461 target_temp_slot_level = thisblock->data.block.block_target_temp_slot_level;
3463 /* Restore block_stack level for containing block. */
3465 stack_block_stack = thisblock->data.block.innermost_stack_block;
3466 POPSTACK (block_stack);
3468 /* Pop the stack slot nesting and free any slots at this level. */
3472 /* Generate RTL for the automatic variable declaration DECL.
3473 (Other kinds of declarations are simply ignored if seen here.) */
3479 struct nesting *thisblock;
3482 type = TREE_TYPE (decl);
3484 /* Only automatic variables need any expansion done.
3485 Static and external variables, and external functions,
3486 will be handled by `assemble_variable' (called from finish_decl).
3487 TYPE_DECL and CONST_DECL require nothing.
3488 PARM_DECLs are handled in `assign_parms'. */
3490 if (TREE_CODE (decl) != VAR_DECL)
3492 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl))
3495 thisblock = block_stack;
3497 /* Create the RTL representation for the variable. */
3499 if (type == error_mark_node)
3500 DECL_RTL (decl) = gen_rtx_MEM (BLKmode, const0_rtx);
3501 else if (DECL_SIZE (decl) == 0)
3502 /* Variable with incomplete type. */
3504 if (DECL_INITIAL (decl) == 0)
3505 /* Error message was already done; now avoid a crash. */
3506 DECL_RTL (decl) = assign_stack_temp (DECL_MODE (decl), 0, 1);
3508 /* An initializer is going to decide the size of this array.
3509 Until we know the size, represent its address with a reg. */
3510 DECL_RTL (decl) = gen_rtx_MEM (BLKmode, gen_reg_rtx (Pmode));
3511 MEM_SET_IN_STRUCT_P (DECL_RTL (decl), AGGREGATE_TYPE_P (type));
3513 else if (DECL_MODE (decl) != BLKmode
3514 /* If -ffloat-store, don't put explicit float vars
3516 && !(flag_float_store
3517 && TREE_CODE (type) == REAL_TYPE)
3518 && ! TREE_THIS_VOLATILE (decl)
3519 && ! TREE_ADDRESSABLE (decl)
3520 && (DECL_REGISTER (decl) || ! obey_regdecls)
3521 /* if -fcheck-memory-usage, check all variables. */
3522 && ! current_function_check_memory_usage)
3524 /* Automatic variable that can go in a register. */
3525 int unsignedp = TREE_UNSIGNED (type);
3526 enum machine_mode reg_mode
3527 = promote_mode (type, DECL_MODE (decl), &unsignedp, 0);
3529 DECL_RTL (decl) = gen_reg_rtx (reg_mode);
3530 mark_user_reg (DECL_RTL (decl));
3532 if (POINTER_TYPE_P (type))
3533 mark_reg_pointer (DECL_RTL (decl),
3534 (TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl)))
3538 else if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
3539 && ! (flag_stack_check && ! STACK_CHECK_BUILTIN
3540 && (TREE_INT_CST_HIGH (DECL_SIZE (decl)) != 0
3541 || (TREE_INT_CST_LOW (DECL_SIZE (decl))
3542 > STACK_CHECK_MAX_VAR_SIZE * BITS_PER_UNIT))))
3544 /* Variable of fixed size that goes on the stack. */
3548 /* If we previously made RTL for this decl, it must be an array
3549 whose size was determined by the initializer.
3550 The old address was a register; set that register now
3551 to the proper address. */
3552 if (DECL_RTL (decl) != 0)
3554 if (GET_CODE (DECL_RTL (decl)) != MEM
3555 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != REG)
3557 oldaddr = XEXP (DECL_RTL (decl), 0);
3560 DECL_RTL (decl) = assign_temp (TREE_TYPE (decl), 1, 1, 1);
3561 MEM_SET_IN_STRUCT_P (DECL_RTL (decl),
3562 AGGREGATE_TYPE_P (TREE_TYPE (decl)));
3564 /* Set alignment we actually gave this decl. */
3565 DECL_ALIGN (decl) = (DECL_MODE (decl) == BLKmode ? BIGGEST_ALIGNMENT
3566 : GET_MODE_BITSIZE (DECL_MODE (decl)));
3570 addr = force_operand (XEXP (DECL_RTL (decl), 0), oldaddr);
3571 if (addr != oldaddr)
3572 emit_move_insn (oldaddr, addr);
3575 /* If this is a memory ref that contains aggregate components,
3576 mark it as such for cse and loop optimize. */
3577 MEM_SET_IN_STRUCT_P (DECL_RTL (decl),
3578 AGGREGATE_TYPE_P (TREE_TYPE (decl)));
3580 /* If this is in memory because of -ffloat-store,
3581 set the volatile bit, to prevent optimizations from
3582 undoing the effects. */
3583 if (flag_float_store && TREE_CODE (type) == REAL_TYPE)
3584 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
3587 MEM_ALIAS_SET (DECL_RTL (decl)) = get_alias_set (decl);
3590 /* Dynamic-size object: must push space on the stack. */
3594 /* Record the stack pointer on entry to block, if have
3595 not already done so. */
3596 if (thisblock->data.block.stack_level == 0)
3598 do_pending_stack_adjust ();
3599 emit_stack_save (thisblock->next ? SAVE_BLOCK : SAVE_FUNCTION,
3600 &thisblock->data.block.stack_level,
3601 thisblock->data.block.first_insn);
3602 stack_block_stack = thisblock;
3605 /* Compute the variable's size, in bytes. */
3606 size = expand_expr (size_binop (CEIL_DIV_EXPR,
3608 size_int (BITS_PER_UNIT)),
3609 NULL_RTX, VOIDmode, 0);
3612 /* Allocate space on the stack for the variable. Note that
3613 DECL_ALIGN says how the variable is to be aligned and we
3614 cannot use it to conclude anything about the alignment of
3616 address = allocate_dynamic_stack_space (size, NULL_RTX,
3617 TYPE_ALIGN (TREE_TYPE (decl)));
3619 /* Reference the variable indirect through that rtx. */
3620 DECL_RTL (decl) = gen_rtx_MEM (DECL_MODE (decl), address);
3622 /* If this is a memory ref that contains aggregate components,
3623 mark it as such for cse and loop optimize. */
3624 MEM_SET_IN_STRUCT_P (DECL_RTL (decl),
3625 AGGREGATE_TYPE_P (TREE_TYPE (decl)));
3627 /* Indicate the alignment we actually gave this variable. */
3628 #ifdef STACK_BOUNDARY
3629 DECL_ALIGN (decl) = STACK_BOUNDARY;
3631 DECL_ALIGN (decl) = BIGGEST_ALIGNMENT;
3635 if (TREE_THIS_VOLATILE (decl))
3636 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
3637 #if 0 /* A variable is not necessarily unchanging
3638 just because it is const. RTX_UNCHANGING_P
3639 means no change in the function,
3640 not merely no change in the variable's scope.
3641 It is correct to set RTX_UNCHANGING_P if the variable's scope
3642 is the whole function. There's no convenient way to test that. */
3643 if (TREE_READONLY (decl))
3644 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
3647 /* If doing stupid register allocation, make sure life of any
3648 register variable starts here, at the start of its scope. */
3651 use_variable (DECL_RTL (decl));
3656 /* Emit code to perform the initialization of a declaration DECL. */
3659 expand_decl_init (decl)
3662 int was_used = TREE_USED (decl);
3664 /* If this is a CONST_DECL, we don't have to generate any code, but
3665 if DECL_INITIAL is a constant, call expand_expr to force TREE_CST_RTL
3666 to be set while in the obstack containing the constant. If we don't
3667 do this, we can lose if we have functions nested three deep and the middle
3668 function makes a CONST_DECL whose DECL_INITIAL is a STRING_CST while
3669 the innermost function is the first to expand that STRING_CST. */
3670 if (TREE_CODE (decl) == CONST_DECL)
3672 if (DECL_INITIAL (decl) && TREE_CONSTANT (DECL_INITIAL (decl)))
3673 expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode,
3674 EXPAND_INITIALIZER);
3678 if (TREE_STATIC (decl))
3681 /* Compute and store the initial value now. */
3683 if (DECL_INITIAL (decl) == error_mark_node)
3685 enum tree_code code = TREE_CODE (TREE_TYPE (decl));
3687 if (code == INTEGER_TYPE || code == REAL_TYPE || code == ENUMERAL_TYPE
3688 || code == POINTER_TYPE || code == REFERENCE_TYPE)
3689 expand_assignment (decl, convert (TREE_TYPE (decl), integer_zero_node),
3693 else if (DECL_INITIAL (decl) && TREE_CODE (DECL_INITIAL (decl)) != TREE_LIST)
3695 emit_line_note (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
3696 expand_assignment (decl, DECL_INITIAL (decl), 0, 0);
3700 /* Don't let the initialization count as "using" the variable. */
3701 TREE_USED (decl) = was_used;
3703 /* Free any temporaries we made while initializing the decl. */
3704 preserve_temp_slots (NULL_RTX);
3708 /* CLEANUP is an expression to be executed at exit from this binding contour;
3709 for example, in C++, it might call the destructor for this variable.
3711 We wrap CLEANUP in an UNSAVE_EXPR node, so that we can expand the
3712 CLEANUP multiple times, and have the correct semantics. This
3713 happens in exception handling, for gotos, returns, breaks that
3714 leave the current scope.
3716 If CLEANUP is nonzero and DECL is zero, we record a cleanup
3717 that is not associated with any particular variable. */
3720 expand_decl_cleanup (decl, cleanup)
3723 struct nesting *thisblock;
3725 /* Error if we are not in any block. */
3726 if (current_function == 0 || block_stack == 0)
3729 thisblock = block_stack;
3731 /* Record the cleanup if there is one. */
3737 tree *cleanups = &thisblock->data.block.cleanups;
3738 int cond_context = conditional_context ();
3742 rtx flag = gen_reg_rtx (word_mode);
3747 emit_move_insn (flag, const0_rtx);
3748 set_flag_0 = get_insns ();
3751 thisblock->data.block.last_unconditional_cleanup
3752 = emit_insns_after (set_flag_0,
3753 thisblock->data.block.last_unconditional_cleanup);
3755 emit_move_insn (flag, const1_rtx);
3757 /* All cleanups must be on the function_obstack. */
3758 push_obstacks_nochange ();
3759 resume_temporary_allocation ();
3761 cond = build_decl (VAR_DECL, NULL_TREE, type_for_mode (word_mode, 1));
3762 DECL_RTL (cond) = flag;
3764 /* Conditionalize the cleanup. */
3765 cleanup = build (COND_EXPR, void_type_node,
3766 truthvalue_conversion (cond),
3767 cleanup, integer_zero_node);
3768 cleanup = fold (cleanup);
3772 cleanups = thisblock->data.block.cleanup_ptr;
3775 /* All cleanups must be on the function_obstack. */
3776 push_obstacks_nochange ();
3777 resume_temporary_allocation ();
3778 cleanup = unsave_expr (cleanup);
3781 t = *cleanups = temp_tree_cons (decl, cleanup, *cleanups);
3784 /* If this block has a cleanup, it belongs in stack_block_stack. */
3785 stack_block_stack = thisblock;
3792 /* If this was optimized so that there is no exception region for the
3793 cleanup, then mark the TREE_LIST node, so that we can later tell
3794 if we need to call expand_eh_region_end. */
3795 if (! using_eh_for_cleanups_p
3796 || expand_eh_region_start_tree (decl, cleanup))
3797 TREE_ADDRESSABLE (t) = 1;
3798 /* If that started a new EH region, we're in a new block. */
3799 thisblock = block_stack;
3806 thisblock->data.block.last_unconditional_cleanup
3807 = emit_insns_after (seq,
3808 thisblock->data.block.last_unconditional_cleanup);
3812 thisblock->data.block.last_unconditional_cleanup
3814 thisblock->data.block.cleanup_ptr = &thisblock->data.block.cleanups;
3820 /* Like expand_decl_cleanup, but suppress generating an exception handler
3821 to perform the cleanup. */
3824 expand_decl_cleanup_no_eh (decl, cleanup)
3827 int save_eh = using_eh_for_cleanups_p;
3830 using_eh_for_cleanups_p = 0;
3831 result = expand_decl_cleanup (decl, cleanup);
3832 using_eh_for_cleanups_p = save_eh;
3837 /* Arrange for the top element of the dynamic cleanup chain to be
3838 popped if we exit the current binding contour. DECL is the
3839 associated declaration, if any, otherwise NULL_TREE. If the
3840 current contour is left via an exception, then __sjthrow will pop
3841 the top element off the dynamic cleanup chain. The code that
3842 avoids doing the action we push into the cleanup chain in the
3843 exceptional case is contained in expand_cleanups.
3845 This routine is only used by expand_eh_region_start, and that is
3846 the only way in which an exception region should be started. This
3847 routine is only used when using the setjmp/longjmp codegen method
3848 for exception handling. */
3851 expand_dcc_cleanup (decl)
3854 struct nesting *thisblock;
3857 /* Error if we are not in any block. */
3858 if (current_function == 0 || block_stack == 0)
3860 thisblock = block_stack;
3862 /* Record the cleanup for the dynamic handler chain. */
3864 /* All cleanups must be on the function_obstack. */
3865 push_obstacks_nochange ();
3866 resume_temporary_allocation ();
3867 cleanup = make_node (POPDCC_EXPR);
3870 /* Add the cleanup in a manner similar to expand_decl_cleanup. */
3871 thisblock->data.block.cleanups
3872 = temp_tree_cons (decl, cleanup, thisblock->data.block.cleanups);
3874 /* If this block has a cleanup, it belongs in stack_block_stack. */
3875 stack_block_stack = thisblock;
3879 /* Arrange for the top element of the dynamic handler chain to be
3880 popped if we exit the current binding contour. DECL is the
3881 associated declaration, if any, otherwise NULL_TREE. If the current
3882 contour is left via an exception, then __sjthrow will pop the top
3883 element off the dynamic handler chain. The code that avoids doing
3884 the action we push into the handler chain in the exceptional case
3885 is contained in expand_cleanups.
3887 This routine is only used by expand_eh_region_start, and that is
3888 the only way in which an exception region should be started. This
3889 routine is only used when using the setjmp/longjmp codegen method
3890 for exception handling. */
3893 expand_dhc_cleanup (decl)
3896 struct nesting *thisblock;
3899 /* Error if we are not in any block. */
3900 if (current_function == 0 || block_stack == 0)
3902 thisblock = block_stack;
3904 /* Record the cleanup for the dynamic handler chain. */
3906 /* All cleanups must be on the function_obstack. */
3907 push_obstacks_nochange ();
3908 resume_temporary_allocation ();
3909 cleanup = make_node (POPDHC_EXPR);
3912 /* Add the cleanup in a manner similar to expand_decl_cleanup. */
3913 thisblock->data.block.cleanups
3914 = temp_tree_cons (decl, cleanup, thisblock->data.block.cleanups);
3916 /* If this block has a cleanup, it belongs in stack_block_stack. */
3917 stack_block_stack = thisblock;
3921 /* DECL is an anonymous union. CLEANUP is a cleanup for DECL.
3922 DECL_ELTS is the list of elements that belong to DECL's type.
3923 In each, the TREE_VALUE is a VAR_DECL, and the TREE_PURPOSE a cleanup. */
3926 expand_anon_union_decl (decl, cleanup, decl_elts)
3927 tree decl, cleanup, decl_elts;
3929 struct nesting *thisblock = current_function == 0 ? 0 : block_stack;
3933 expand_decl_cleanup (decl, cleanup);
3934 x = DECL_RTL (decl);
3938 tree decl_elt = TREE_VALUE (decl_elts);
3939 tree cleanup_elt = TREE_PURPOSE (decl_elts);
3940 enum machine_mode mode = TYPE_MODE (TREE_TYPE (decl_elt));
3942 /* Propagate the union's alignment to the elements. */
3943 DECL_ALIGN (decl_elt) = DECL_ALIGN (decl);
3945 /* If the element has BLKmode and the union doesn't, the union is
3946 aligned such that the element doesn't need to have BLKmode, so
3947 change the element's mode to the appropriate one for its size. */
3948 if (mode == BLKmode && DECL_MODE (decl) != BLKmode)
3949 DECL_MODE (decl_elt) = mode
3950 = mode_for_size (TREE_INT_CST_LOW (DECL_SIZE (decl_elt)),
3953 /* (SUBREG (MEM ...)) at RTL generation time is invalid, so we
3954 instead create a new MEM rtx with the proper mode. */
3955 if (GET_CODE (x) == MEM)
3957 if (mode == GET_MODE (x))
3958 DECL_RTL (decl_elt) = x;
3961 DECL_RTL (decl_elt) = gen_rtx_MEM (mode, copy_rtx (XEXP (x, 0)));
3962 MEM_COPY_ATTRIBUTES (DECL_RTL (decl_elt), x);
3963 RTX_UNCHANGING_P (DECL_RTL (decl_elt)) = RTX_UNCHANGING_P (x);
3966 else if (GET_CODE (x) == REG)
3968 if (mode == GET_MODE (x))
3969 DECL_RTL (decl_elt) = x;
3971 DECL_RTL (decl_elt) = gen_rtx_SUBREG (mode, x, 0);
3976 /* Record the cleanup if there is one. */
3979 thisblock->data.block.cleanups
3980 = temp_tree_cons (decl_elt, cleanup_elt,
3981 thisblock->data.block.cleanups);
3983 decl_elts = TREE_CHAIN (decl_elts);
3987 /* Expand a list of cleanups LIST.
3988 Elements may be expressions or may be nested lists.
3990 If DONT_DO is nonnull, then any list-element
3991 whose TREE_PURPOSE matches DONT_DO is omitted.
3992 This is sometimes used to avoid a cleanup associated with
3993 a value that is being returned out of the scope.
3995 If IN_FIXUP is non-zero, we are generating this cleanup for a fixup
3996 goto and handle protection regions specially in that case.
3998 If REACHABLE, we emit code, otherwise just inform the exception handling
3999 code about this finalization. */
4002 expand_cleanups (list, dont_do, in_fixup, reachable)
4009 for (tail = list; tail; tail = TREE_CHAIN (tail))
4010 if (dont_do == 0 || TREE_PURPOSE (tail) != dont_do)
4012 if (TREE_CODE (TREE_VALUE (tail)) == TREE_LIST)
4013 expand_cleanups (TREE_VALUE (tail), dont_do, in_fixup, reachable);
4018 tree cleanup = TREE_VALUE (tail);
4020 /* See expand_d{h,c}c_cleanup for why we avoid this. */
4021 if (TREE_CODE (cleanup) != POPDHC_EXPR
4022 && TREE_CODE (cleanup) != POPDCC_EXPR
4023 /* See expand_eh_region_start_tree for this case. */
4024 && ! TREE_ADDRESSABLE (tail))
4026 cleanup = protect_with_terminate (cleanup);
4027 expand_eh_region_end (cleanup);
4033 /* Cleanups may be run multiple times. For example,
4034 when exiting a binding contour, we expand the
4035 cleanups associated with that contour. When a goto
4036 within that binding contour has a target outside that
4037 contour, it will expand all cleanups from its scope to
4038 the target. Though the cleanups are expanded multiple
4039 times, the control paths are non-overlapping so the
4040 cleanups will not be executed twice. */
4042 /* We may need to protect fixups with rethrow regions. */
4043 int protect = (in_fixup && ! TREE_ADDRESSABLE (tail));
4046 expand_fixup_region_start ();
4048 expand_expr (TREE_VALUE (tail), const0_rtx, VOIDmode, 0);
4050 expand_fixup_region_end (TREE_VALUE (tail));
4057 /* Mark when the context we are emitting RTL for as a conditional
4058 context, so that any cleanup actions we register with
4059 expand_decl_init will be properly conditionalized when those
4060 cleanup actions are later performed. Must be called before any
4061 expression (tree) is expanded that is within a conditional context. */
4064 start_cleanup_deferral ()
4066 /* block_stack can be NULL if we are inside the parameter list. It is
4067 OK to do nothing, because cleanups aren't possible here. */
4069 ++block_stack->data.block.conditional_code;
4072 /* Mark the end of a conditional region of code. Because cleanup
4073 deferrals may be nested, we may still be in a conditional region
4074 after we end the currently deferred cleanups, only after we end all
4075 deferred cleanups, are we back in unconditional code. */
4078 end_cleanup_deferral ()
4080 /* block_stack can be NULL if we are inside the parameter list. It is
4081 OK to do nothing, because cleanups aren't possible here. */
4083 --block_stack->data.block.conditional_code;
4086 /* Move all cleanups from the current block_stack
4087 to the containing block_stack, where they are assumed to
4088 have been created. If anything can cause a temporary to
4089 be created, but not expanded for more than one level of
4090 block_stacks, then this code will have to change. */
4095 struct nesting *block = block_stack;
4096 struct nesting *outer = block->next;
4098 outer->data.block.cleanups
4099 = chainon (block->data.block.cleanups,
4100 outer->data.block.cleanups);
4101 block->data.block.cleanups = 0;
4105 last_cleanup_this_contour ()
4107 if (block_stack == 0)
4110 return block_stack->data.block.cleanups;
4113 /* Return 1 if there are any pending cleanups at this point.
4114 If THIS_CONTOUR is nonzero, check the current contour as well.
4115 Otherwise, look only at the contours that enclose this one. */
4118 any_pending_cleanups (this_contour)
4121 struct nesting *block;
4123 if (block_stack == 0)
4126 if (this_contour && block_stack->data.block.cleanups != NULL)
4128 if (block_stack->data.block.cleanups == 0
4129 && block_stack->data.block.outer_cleanups == 0)
4132 for (block = block_stack->next; block; block = block->next)
4133 if (block->data.block.cleanups != 0)
4139 /* Enter a case (Pascal) or switch (C) statement.
4140 Push a block onto case_stack and nesting_stack
4141 to accumulate the case-labels that are seen
4142 and to record the labels generated for the statement.
4144 EXIT_FLAG is nonzero if `exit_something' should exit this case stmt.
4145 Otherwise, this construct is transparent for `exit_something'.
4147 EXPR is the index-expression to be dispatched on.
4148 TYPE is its nominal type. We could simply convert EXPR to this type,
4149 but instead we take short cuts. */
4152 expand_start_case (exit_flag, expr, type, printname)
4156 const char *printname;
4158 register struct nesting *thiscase = ALLOC_NESTING ();
4160 /* Make an entry on case_stack for the case we are entering. */
4162 thiscase->next = case_stack;
4163 thiscase->all = nesting_stack;
4164 thiscase->depth = ++nesting_depth;
4165 thiscase->exit_label = exit_flag ? gen_label_rtx () : 0;
4166 thiscase->data.case_stmt.case_list = 0;
4167 thiscase->data.case_stmt.index_expr = expr;
4168 thiscase->data.case_stmt.nominal_type = type;
4169 thiscase->data.case_stmt.default_label = 0;
4170 thiscase->data.case_stmt.num_ranges = 0;
4171 thiscase->data.case_stmt.printname = printname;
4172 thiscase->data.case_stmt.line_number_status = force_line_numbers ();
4173 case_stack = thiscase;
4174 nesting_stack = thiscase;
4176 do_pending_stack_adjust ();
4178 /* Make sure case_stmt.start points to something that won't
4179 need any transformation before expand_end_case. */
4180 if (GET_CODE (get_last_insn ()) != NOTE)
4181 emit_note (NULL_PTR, NOTE_INSN_DELETED);
4183 thiscase->data.case_stmt.start = get_last_insn ();
4185 start_cleanup_deferral ();
4189 /* Start a "dummy case statement" within which case labels are invalid
4190 and are not connected to any larger real case statement.
4191 This can be used if you don't want to let a case statement jump
4192 into the middle of certain kinds of constructs. */
4195 expand_start_case_dummy ()
4197 register struct nesting *thiscase = ALLOC_NESTING ();
4199 /* Make an entry on case_stack for the dummy. */
4201 thiscase->next = case_stack;
4202 thiscase->all = nesting_stack;
4203 thiscase->depth = ++nesting_depth;
4204 thiscase->exit_label = 0;
4205 thiscase->data.case_stmt.case_list = 0;
4206 thiscase->data.case_stmt.start = 0;
4207 thiscase->data.case_stmt.nominal_type = 0;
4208 thiscase->data.case_stmt.default_label = 0;
4209 thiscase->data.case_stmt.num_ranges = 0;
4210 case_stack = thiscase;
4211 nesting_stack = thiscase;
4212 start_cleanup_deferral ();
4215 /* End a dummy case statement. */
4218 expand_end_case_dummy ()
4220 end_cleanup_deferral ();
4221 POPSTACK (case_stack);
4224 /* Return the data type of the index-expression
4225 of the innermost case statement, or null if none. */
4228 case_index_expr_type ()
4231 return TREE_TYPE (case_stack->data.case_stmt.index_expr);
4238 /* If this is the first label, warn if any insns have been emitted. */
4239 if (case_stack->data.case_stmt.line_number_status >= 0)
4243 restore_line_number_status
4244 (case_stack->data.case_stmt.line_number_status);
4245 case_stack->data.case_stmt.line_number_status = -1;
4247 for (insn = case_stack->data.case_stmt.start;
4249 insn = NEXT_INSN (insn))
4251 if (GET_CODE (insn) == CODE_LABEL)
4253 if (GET_CODE (insn) != NOTE
4254 && (GET_CODE (insn) != INSN || GET_CODE (PATTERN (insn)) != USE))
4257 insn = PREV_INSN (insn);
4258 while (insn && (GET_CODE (insn) != NOTE || NOTE_LINE_NUMBER (insn) < 0));
4260 /* If insn is zero, then there must have been a syntax error. */
4262 warning_with_file_and_line (NOTE_SOURCE_FILE(insn),
4263 NOTE_LINE_NUMBER(insn),
4264 "unreachable code at beginning of %s",
4265 case_stack->data.case_stmt.printname);
4272 /* Accumulate one case or default label inside a case or switch statement.
4273 VALUE is the value of the case (a null pointer, for a default label).
4274 The function CONVERTER, when applied to arguments T and V,
4275 converts the value V to the type T.
4277 If not currently inside a case or switch statement, return 1 and do
4278 nothing. The caller will print a language-specific error message.
4279 If VALUE is a duplicate or overlaps, return 2 and do nothing
4280 except store the (first) duplicate node in *DUPLICATE.
4281 If VALUE is out of range, return 3 and do nothing.
4282 If we are jumping into the scope of a cleanup or var-sized array, return 5.
4283 Return 0 on success.
4285 Extended to handle range statements. */
4288 pushcase (value, converter, label, duplicate)
4289 register tree value;
4290 tree (*converter) PROTO((tree, tree));
4291 register tree label;
4297 /* Fail if not inside a real case statement. */
4298 if (! (case_stack && case_stack->data.case_stmt.start))
4301 if (stack_block_stack
4302 && stack_block_stack->depth > case_stack->depth)
4305 index_type = TREE_TYPE (case_stack->data.case_stmt.index_expr);
4306 nominal_type = case_stack->data.case_stmt.nominal_type;
4308 /* If the index is erroneous, avoid more problems: pretend to succeed. */
4309 if (index_type == error_mark_node)
4312 /* Convert VALUE to the type in which the comparisons are nominally done. */
4314 value = (*converter) (nominal_type, value);
4318 /* Fail if this value is out of range for the actual type of the index
4319 (which may be narrower than NOMINAL_TYPE). */
4320 if (value != 0 && ! int_fits_type_p (value, index_type))
4323 /* Fail if this is a duplicate or overlaps another entry. */
4326 if (case_stack->data.case_stmt.default_label != 0)
4328 *duplicate = case_stack->data.case_stmt.default_label;
4331 case_stack->data.case_stmt.default_label = label;
4334 return add_case_node (value, value, label, duplicate);
4336 expand_label (label);
4340 /* Like pushcase but this case applies to all values between VALUE1 and
4341 VALUE2 (inclusive). If VALUE1 is NULL, the range starts at the lowest
4342 value of the index type and ends at VALUE2. If VALUE2 is NULL, the range
4343 starts at VALUE1 and ends at the highest value of the index type.
4344 If both are NULL, this case applies to all values.
4346 The return value is the same as that of pushcase but there is one
4347 additional error code: 4 means the specified range was empty. */
4350 pushcase_range (value1, value2, converter, label, duplicate)
4351 register tree value1, value2;
4352 tree (*converter) PROTO((tree, tree));
4353 register tree label;
4359 /* Fail if not inside a real case statement. */
4360 if (! (case_stack && case_stack->data.case_stmt.start))
4363 if (stack_block_stack
4364 && stack_block_stack->depth > case_stack->depth)
4367 index_type = TREE_TYPE (case_stack->data.case_stmt.index_expr);
4368 nominal_type = case_stack->data.case_stmt.nominal_type;
4370 /* If the index is erroneous, avoid more problems: pretend to succeed. */
4371 if (index_type == error_mark_node)
4376 /* Convert VALUEs to type in which the comparisons are nominally done
4377 and replace any unspecified value with the corresponding bound. */
4379 value1 = TYPE_MIN_VALUE (index_type);
4381 value2 = TYPE_MAX_VALUE (index_type);
4383 /* Fail if the range is empty. Do this before any conversion since
4384 we want to allow out-of-range empty ranges. */
4385 if (value2 && tree_int_cst_lt (value2, value1))
4388 value1 = (*converter) (nominal_type, value1);
4390 /* If the max was unbounded, use the max of the nominal_type we are
4391 converting to. Do this after the < check above to suppress false
4394 value2 = TYPE_MAX_VALUE (nominal_type);
4395 value2 = (*converter) (nominal_type, value2);
4397 /* Fail if these values are out of range. */
4398 if (TREE_CONSTANT_OVERFLOW (value1)
4399 || ! int_fits_type_p (value1, index_type))
4402 if (TREE_CONSTANT_OVERFLOW (value2)
4403 || ! int_fits_type_p (value2, index_type))
4406 return add_case_node (value1, value2, label, duplicate);
4409 /* Do the actual insertion of a case label for pushcase and pushcase_range
4410 into case_stack->data.case_stmt.case_list. Use an AVL tree to avoid
4411 slowdown for large switch statements. */
4414 add_case_node (low, high, label, duplicate)
4419 struct case_node *p, **q, *r;
4421 q = &case_stack->data.case_stmt.case_list;
4428 /* Keep going past elements distinctly greater than HIGH. */
4429 if (tree_int_cst_lt (high, p->low))
4432 /* or distinctly less than LOW. */
4433 else if (tree_int_cst_lt (p->high, low))
4438 /* We have an overlap; this is an error. */
4439 *duplicate = p->code_label;
4444 /* Add this label to the chain, and succeed.
4445 Copy LOW, HIGH so they are on temporary rather than momentary
4446 obstack and will thus survive till the end of the case statement. */
4448 r = (struct case_node *) oballoc (sizeof (struct case_node));
4449 r->low = copy_node (low);
4451 /* If the bounds are equal, turn this into the one-value case. */
4453 if (tree_int_cst_equal (low, high))
4457 r->high = copy_node (high);
4458 case_stack->data.case_stmt.num_ranges++;
4461 r->code_label = label;
4462 expand_label (label);
4472 struct case_node *s;
4478 if (! (b = p->balance))
4479 /* Growth propagation from left side. */
4486 if ((p->left = s = r->right))
4495 if ((r->parent = s))
4503 case_stack->data.case_stmt.case_list = r;
4506 /* r->balance == +1 */
4511 struct case_node *t = r->right;
4513 if ((p->left = s = t->right))
4517 if ((r->right = s = t->left))
4531 if ((t->parent = s))
4539 case_stack->data.case_stmt.case_list = t;
4546 /* p->balance == +1; growth of left side balances the node. */
4556 if (! (b = p->balance))
4557 /* Growth propagation from right side. */
4565 if ((p->right = s = r->left))
4573 if ((r->parent = s))
4582 case_stack->data.case_stmt.case_list = r;
4586 /* r->balance == -1 */
4590 struct case_node *t = r->left;
4592 if ((p->right = s = t->left))
4597 if ((r->left = s = t->right))
4611 if ((t->parent = s))
4620 case_stack->data.case_stmt.case_list = t;
4626 /* p->balance == -1; growth of right side balances the node. */
4640 /* Returns the number of possible values of TYPE.
4641 Returns -1 if the number is unknown or variable.
4642 Returns -2 if the number does not fit in a HOST_WIDE_INT.
4643 Sets *SPARENESS to 2 if TYPE is an ENUMERAL_TYPE whose values
4644 do not increase monotonically (there may be duplicates);
4645 to 1 if the values increase monotonically, but not always by 1;
4646 otherwise sets it to 0. */
4649 all_cases_count (type, spareness)
4653 HOST_WIDE_INT count;
4656 switch (TREE_CODE (type))
4663 count = 1 << BITS_PER_UNIT;
4667 if (TREE_CODE (TYPE_MIN_VALUE (type)) != INTEGER_CST
4668 || TYPE_MAX_VALUE (type) == NULL
4669 || TREE_CODE (TYPE_MAX_VALUE (type)) != INTEGER_CST)
4674 = TREE_INT_CST_LOW (TYPE_MAX_VALUE (type))
4675 - TREE_INT_CST_LOW (TYPE_MIN_VALUE (type)) + 1
4676 but with overflow checking. */
4677 tree mint = TYPE_MIN_VALUE (type);
4678 tree maxt = TYPE_MAX_VALUE (type);
4679 HOST_WIDE_INT lo, hi;
4680 neg_double(TREE_INT_CST_LOW (mint), TREE_INT_CST_HIGH (mint),
4682 add_double(TREE_INT_CST_LOW (maxt), TREE_INT_CST_HIGH (maxt),
4684 add_double (lo, hi, 1, 0, &lo, &hi);
4685 if (hi != 0 || lo < 0)
4692 for (t = TYPE_VALUES (type); t != NULL_TREE; t = TREE_CHAIN (t))
4694 if (TREE_CODE (TYPE_MIN_VALUE (type)) != INTEGER_CST
4695 || TREE_CODE (TREE_VALUE (t)) != INTEGER_CST
4696 || TREE_INT_CST_LOW (TYPE_MIN_VALUE (type)) + count
4697 != TREE_INT_CST_LOW (TREE_VALUE (t)))
4701 if (*spareness == 1)
4703 tree prev = TREE_VALUE (TYPE_VALUES (type));
4704 for (t = TYPE_VALUES (type); t = TREE_CHAIN (t), t != NULL_TREE; )
4706 if (! tree_int_cst_lt (prev, TREE_VALUE (t)))
4711 prev = TREE_VALUE (t);
4720 #define BITARRAY_TEST(ARRAY, INDEX) \
4721 ((ARRAY)[(unsigned) (INDEX) / HOST_BITS_PER_CHAR]\
4722 & (1 << ((unsigned) (INDEX) % HOST_BITS_PER_CHAR)))
4723 #define BITARRAY_SET(ARRAY, INDEX) \
4724 ((ARRAY)[(unsigned) (INDEX) / HOST_BITS_PER_CHAR]\
4725 |= 1 << ((unsigned) (INDEX) % HOST_BITS_PER_CHAR))
4727 /* Set the elements of the bitstring CASES_SEEN (which has length COUNT),
4728 with the case values we have seen, assuming the case expression
4730 SPARSENESS is as determined by all_cases_count.
4732 The time needed is proportional to COUNT, unless
4733 SPARSENESS is 2, in which case quadratic time is needed. */
4736 mark_seen_cases (type, cases_seen, count, sparseness)
4738 unsigned char *cases_seen;
4742 tree next_node_to_try = NULL_TREE;
4743 long next_node_offset = 0;
4745 register struct case_node *n, *root = case_stack->data.case_stmt.case_list;
4746 tree val = make_node (INTEGER_CST);
4747 TREE_TYPE (val) = type;
4750 else if (sparseness == 2)
4755 /* This less efficient loop is only needed to handle
4756 duplicate case values (multiple enum constants
4757 with the same value). */
4758 TREE_TYPE (val) = TREE_TYPE (root->low);
4759 for (t = TYPE_VALUES (type), xlo = 0; t != NULL_TREE;
4760 t = TREE_CHAIN (t), xlo++)
4762 TREE_INT_CST_LOW (val) = TREE_INT_CST_LOW (TREE_VALUE (t));
4763 TREE_INT_CST_HIGH (val) = TREE_INT_CST_HIGH (TREE_VALUE (t));
4767 /* Keep going past elements distinctly greater than VAL. */
4768 if (tree_int_cst_lt (val, n->low))
4771 /* or distinctly less than VAL. */
4772 else if (tree_int_cst_lt (n->high, val))
4777 /* We have found a matching range. */
4778 BITARRAY_SET (cases_seen, xlo);
4788 case_stack->data.case_stmt.case_list = root = case_tree2list (root, 0);
4789 for (n = root; n; n = n->right)
4791 TREE_INT_CST_LOW (val) = TREE_INT_CST_LOW (n->low);
4792 TREE_INT_CST_HIGH (val) = TREE_INT_CST_HIGH (n->low);
4793 while ( ! tree_int_cst_lt (n->high, val))
4795 /* Calculate (into xlo) the "offset" of the integer (val).
4796 The element with lowest value has offset 0, the next smallest
4797 element has offset 1, etc. */
4799 HOST_WIDE_INT xlo, xhi;
4801 if (sparseness && TYPE_VALUES (type) != NULL_TREE)
4803 /* The TYPE_VALUES will be in increasing order, so
4804 starting searching where we last ended. */
4805 t = next_node_to_try;
4806 xlo = next_node_offset;
4812 t = TYPE_VALUES (type);
4815 if (tree_int_cst_equal (val, TREE_VALUE (t)))
4817 next_node_to_try = TREE_CHAIN (t);
4818 next_node_offset = xlo + 1;
4823 if (t == next_node_to_try)
4832 t = TYPE_MIN_VALUE (type);
4834 neg_double (TREE_INT_CST_LOW (t), TREE_INT_CST_HIGH (t),
4838 add_double (xlo, xhi,
4839 TREE_INT_CST_LOW (val), TREE_INT_CST_HIGH (val),
4843 if (xhi == 0 && xlo >= 0 && xlo < count)
4844 BITARRAY_SET (cases_seen, xlo);
4845 add_double (TREE_INT_CST_LOW (val), TREE_INT_CST_HIGH (val),
4847 &TREE_INT_CST_LOW (val), &TREE_INT_CST_HIGH (val));
4853 /* Called when the index of a switch statement is an enumerated type
4854 and there is no default label.
4856 Checks that all enumeration literals are covered by the case
4857 expressions of a switch. Also, warn if there are any extra
4858 switch cases that are *not* elements of the enumerated type.
4860 If all enumeration literals were covered by the case expressions,
4861 turn one of the expressions into the default expression since it should
4862 not be possible to fall through such a switch. */
4865 check_for_full_enumeration_handling (type)
4868 register struct case_node *n;
4869 register tree chain;
4870 #if 0 /* variable used by 'if 0'ed code below. */
4871 register struct case_node **l;
4875 /* True iff the selector type is a numbered set mode. */
4878 /* The number of possible selector values. */
4881 /* For each possible selector value. a one iff it has been matched
4882 by a case value alternative. */
4883 unsigned char *cases_seen;
4885 /* The allocated size of cases_seen, in chars. */
4891 size = all_cases_count (type, &sparseness);
4892 bytes_needed = (size + HOST_BITS_PER_CHAR) / HOST_BITS_PER_CHAR;
4894 if (size > 0 && size < 600000
4895 /* We deliberately use malloc here - not xmalloc. */
4896 && (cases_seen = (unsigned char *) malloc (bytes_needed)) != NULL)
4899 tree v = TYPE_VALUES (type);
4900 bzero (cases_seen, bytes_needed);
4902 /* The time complexity of this code is normally O(N), where
4903 N being the number of members in the enumerated type.
4904 However, if type is a ENUMERAL_TYPE whose values do not
4905 increase monotonically, O(N*log(N)) time may be needed. */
4907 mark_seen_cases (type, cases_seen, size, sparseness);
4909 for (i = 0; v != NULL_TREE && i < size; i++, v = TREE_CHAIN (v))
4911 if (BITARRAY_TEST(cases_seen, i) == 0)
4912 warning ("enumeration value `%s' not handled in switch",
4913 IDENTIFIER_POINTER (TREE_PURPOSE (v)));
4919 /* Now we go the other way around; we warn if there are case
4920 expressions that don't correspond to enumerators. This can
4921 occur since C and C++ don't enforce type-checking of
4922 assignments to enumeration variables. */
4924 if (case_stack->data.case_stmt.case_list
4925 && case_stack->data.case_stmt.case_list->left)
4926 case_stack->data.case_stmt.case_list
4927 = case_tree2list (case_stack->data.case_stmt.case_list, 0);
4929 for (n = case_stack->data.case_stmt.case_list; n; n = n->right)
4931 for (chain = TYPE_VALUES (type);
4932 chain && !tree_int_cst_equal (n->low, TREE_VALUE (chain));
4933 chain = TREE_CHAIN (chain))
4938 if (TYPE_NAME (type) == 0)
4939 warning ("case value `%ld' not in enumerated type",
4940 (long) TREE_INT_CST_LOW (n->low));
4942 warning ("case value `%ld' not in enumerated type `%s'",
4943 (long) TREE_INT_CST_LOW (n->low),
4944 IDENTIFIER_POINTER ((TREE_CODE (TYPE_NAME (type))
4947 : DECL_NAME (TYPE_NAME (type))));
4949 if (!tree_int_cst_equal (n->low, n->high))
4951 for (chain = TYPE_VALUES (type);
4952 chain && !tree_int_cst_equal (n->high, TREE_VALUE (chain));
4953 chain = TREE_CHAIN (chain))
4958 if (TYPE_NAME (type) == 0)
4959 warning ("case value `%ld' not in enumerated type",
4960 (long) TREE_INT_CST_LOW (n->high));
4962 warning ("case value `%ld' not in enumerated type `%s'",
4963 (long) TREE_INT_CST_LOW (n->high),
4964 IDENTIFIER_POINTER ((TREE_CODE (TYPE_NAME (type))
4967 : DECL_NAME (TYPE_NAME (type))));
4973 /* ??? This optimization is disabled because it causes valid programs to
4974 fail. ANSI C does not guarantee that an expression with enum type
4975 will have a value that is the same as one of the enumeration literals. */
4977 /* If all values were found as case labels, make one of them the default
4978 label. Thus, this switch will never fall through. We arbitrarily pick
4979 the last one to make the default since this is likely the most
4980 efficient choice. */
4984 for (l = &case_stack->data.case_stmt.case_list;
4989 case_stack->data.case_stmt.default_label = (*l)->code_label;
4996 /* Terminate a case (Pascal) or switch (C) statement
4997 in which ORIG_INDEX is the expression to be tested.
4998 Generate the code to test it and jump to the right place. */
5001 expand_end_case (orig_index)
5004 tree minval = NULL_TREE, maxval = NULL_TREE, range, orig_minval;
5005 rtx default_label = 0;
5006 register struct case_node *n;
5014 register struct nesting *thiscase = case_stack;
5015 tree index_expr, index_type;
5018 table_label = gen_label_rtx ();
5019 index_expr = thiscase->data.case_stmt.index_expr;
5020 index_type = TREE_TYPE (index_expr);
5021 unsignedp = TREE_UNSIGNED (index_type);
5023 do_pending_stack_adjust ();
5025 /* This might get an spurious warning in the presence of a syntax error;
5026 it could be fixed by moving the call to check_seenlabel after the
5027 check for error_mark_node, and copying the code of check_seenlabel that
5028 deals with case_stack->data.case_stmt.line_number_status /
5029 restore_line_number_status in front of the call to end_cleanup_deferral;
5030 However, this might miss some useful warnings in the presence of
5031 non-syntax errors. */
5034 /* An ERROR_MARK occurs for various reasons including invalid data type. */
5035 if (index_type != error_mark_node)
5037 /* If switch expression was an enumerated type, check that all
5038 enumeration literals are covered by the cases.
5039 No sense trying this if there's a default case, however. */
5041 if (!thiscase->data.case_stmt.default_label
5042 && TREE_CODE (TREE_TYPE (orig_index)) == ENUMERAL_TYPE
5043 && TREE_CODE (index_expr) != INTEGER_CST)
5044 check_for_full_enumeration_handling (TREE_TYPE (orig_index));
5046 /* If we don't have a default-label, create one here,
5047 after the body of the switch. */
5048 if (thiscase->data.case_stmt.default_label == 0)
5050 thiscase->data.case_stmt.default_label
5051 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
5052 expand_label (thiscase->data.case_stmt.default_label);
5054 default_label = label_rtx (thiscase->data.case_stmt.default_label);
5056 before_case = get_last_insn ();
5058 if (thiscase->data.case_stmt.case_list
5059 && thiscase->data.case_stmt.case_list->left)
5060 thiscase->data.case_stmt.case_list
5061 = case_tree2list(thiscase->data.case_stmt.case_list, 0);
5063 /* Simplify the case-list before we count it. */
5064 group_case_nodes (thiscase->data.case_stmt.case_list);
5066 /* Get upper and lower bounds of case values.
5067 Also convert all the case values to the index expr's data type. */
5070 for (n = thiscase->data.case_stmt.case_list; n; n = n->right)
5072 /* Check low and high label values are integers. */
5073 if (TREE_CODE (n->low) != INTEGER_CST)
5075 if (TREE_CODE (n->high) != INTEGER_CST)
5078 n->low = convert (index_type, n->low);
5079 n->high = convert (index_type, n->high);
5081 /* Count the elements and track the largest and smallest
5082 of them (treating them as signed even if they are not). */
5090 if (INT_CST_LT (n->low, minval))
5092 if (INT_CST_LT (maxval, n->high))
5095 /* A range counts double, since it requires two compares. */
5096 if (! tree_int_cst_equal (n->low, n->high))
5100 orig_minval = minval;
5102 /* Compute span of values. */
5104 range = fold (build (MINUS_EXPR, index_type, maxval, minval));
5106 end_cleanup_deferral ();
5110 expand_expr (index_expr, const0_rtx, VOIDmode, 0);
5112 emit_jump (default_label);
5115 /* If range of values is much bigger than number of values,
5116 make a sequence of conditional branches instead of a dispatch.
5117 If the switch-index is a constant, do it this way
5118 because we can optimize it. */
5120 #ifndef CASE_VALUES_THRESHOLD
5122 #define CASE_VALUES_THRESHOLD (HAVE_casesi ? 4 : 5)
5124 /* If machine does not have a case insn that compares the
5125 bounds, this means extra overhead for dispatch tables
5126 which raises the threshold for using them. */
5127 #define CASE_VALUES_THRESHOLD 5
5128 #endif /* HAVE_casesi */
5129 #endif /* CASE_VALUES_THRESHOLD */
5131 else if (TREE_INT_CST_HIGH (range) != 0
5132 || count < (unsigned int) CASE_VALUES_THRESHOLD
5133 || ((unsigned HOST_WIDE_INT) (TREE_INT_CST_LOW (range))
5135 #ifndef ASM_OUTPUT_ADDR_DIFF_ELT
5138 || TREE_CODE (index_expr) == INTEGER_CST
5139 /* These will reduce to a constant. */
5140 || (TREE_CODE (index_expr) == CALL_EXPR
5141 && TREE_CODE (TREE_OPERAND (index_expr, 0)) == ADDR_EXPR
5142 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (index_expr, 0), 0)) == FUNCTION_DECL
5143 && DECL_FUNCTION_CODE (TREE_OPERAND (TREE_OPERAND (index_expr, 0), 0)) == BUILT_IN_CLASSIFY_TYPE)
5144 || (TREE_CODE (index_expr) == COMPOUND_EXPR
5145 && TREE_CODE (TREE_OPERAND (index_expr, 1)) == INTEGER_CST))
5147 index = expand_expr (index_expr, NULL_RTX, VOIDmode, 0);
5149 /* If the index is a short or char that we do not have
5150 an insn to handle comparisons directly, convert it to
5151 a full integer now, rather than letting each comparison
5152 generate the conversion. */
5154 if (GET_MODE_CLASS (GET_MODE (index)) == MODE_INT
5155 && (cmp_optab->handlers[(int) GET_MODE(index)].insn_code
5156 == CODE_FOR_nothing))
5158 enum machine_mode wider_mode;
5159 for (wider_mode = GET_MODE (index); wider_mode != VOIDmode;
5160 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
5161 if (cmp_optab->handlers[(int) wider_mode].insn_code
5162 != CODE_FOR_nothing)
5164 index = convert_to_mode (wider_mode, index, unsignedp);
5170 do_pending_stack_adjust ();
5172 index = protect_from_queue (index, 0);
5173 if (GET_CODE (index) == MEM)
5174 index = copy_to_reg (index);
5175 if (GET_CODE (index) == CONST_INT
5176 || TREE_CODE (index_expr) == INTEGER_CST)
5178 /* Make a tree node with the proper constant value
5179 if we don't already have one. */
5180 if (TREE_CODE (index_expr) != INTEGER_CST)
5183 = build_int_2 (INTVAL (index),
5184 unsignedp || INTVAL (index) >= 0 ? 0 : -1);
5185 index_expr = convert (index_type, index_expr);
5188 /* For constant index expressions we need only
5189 issue a unconditional branch to the appropriate
5190 target code. The job of removing any unreachable
5191 code is left to the optimisation phase if the
5192 "-O" option is specified. */
5193 for (n = thiscase->data.case_stmt.case_list; n; n = n->right)
5194 if (! tree_int_cst_lt (index_expr, n->low)
5195 && ! tree_int_cst_lt (n->high, index_expr))
5199 emit_jump (label_rtx (n->code_label));
5201 emit_jump (default_label);
5205 /* If the index expression is not constant we generate
5206 a binary decision tree to select the appropriate
5207 target code. This is done as follows:
5209 The list of cases is rearranged into a binary tree,
5210 nearly optimal assuming equal probability for each case.
5212 The tree is transformed into RTL, eliminating
5213 redundant test conditions at the same time.
5215 If program flow could reach the end of the
5216 decision tree an unconditional jump to the
5217 default code is emitted. */
5220 = (TREE_CODE (TREE_TYPE (orig_index)) != ENUMERAL_TYPE
5221 && estimate_case_costs (thiscase->data.case_stmt.case_list));
5222 balance_case_nodes (&thiscase->data.case_stmt.case_list,
5224 emit_case_nodes (index, thiscase->data.case_stmt.case_list,
5225 default_label, index_type);
5226 emit_jump_if_reachable (default_label);
5235 enum machine_mode index_mode = SImode;
5236 int index_bits = GET_MODE_BITSIZE (index_mode);
5238 enum machine_mode op_mode;
5240 /* Convert the index to SImode. */
5241 if (GET_MODE_BITSIZE (TYPE_MODE (index_type))
5242 > GET_MODE_BITSIZE (index_mode))
5244 enum machine_mode omode = TYPE_MODE (index_type);
5245 rtx rangertx = expand_expr (range, NULL_RTX, VOIDmode, 0);
5247 /* We must handle the endpoints in the original mode. */
5248 index_expr = build (MINUS_EXPR, index_type,
5249 index_expr, minval);
5250 minval = integer_zero_node;
5251 index = expand_expr (index_expr, NULL_RTX, VOIDmode, 0);
5252 emit_cmp_and_jump_insns (rangertx, index, LTU, NULL_RTX,
5253 omode, 1, 0, default_label);
5254 /* Now we can safely truncate. */
5255 index = convert_to_mode (index_mode, index, 0);
5259 if (TYPE_MODE (index_type) != index_mode)
5261 index_expr = convert (type_for_size (index_bits, 0),
5263 index_type = TREE_TYPE (index_expr);
5266 index = expand_expr (index_expr, NULL_RTX, VOIDmode, 0);
5269 index = protect_from_queue (index, 0);
5270 do_pending_stack_adjust ();
5272 op_mode = insn_operand_mode[(int)CODE_FOR_casesi][0];
5273 if (! (*insn_operand_predicate[(int)CODE_FOR_casesi][0])
5275 index = copy_to_mode_reg (op_mode, index);
5277 op1 = expand_expr (minval, NULL_RTX, VOIDmode, 0);
5279 op_mode = insn_operand_mode[(int)CODE_FOR_casesi][1];
5280 if (! (*insn_operand_predicate[(int)CODE_FOR_casesi][1])
5282 op1 = copy_to_mode_reg (op_mode, op1);
5284 op2 = expand_expr (range, NULL_RTX, VOIDmode, 0);
5286 op_mode = insn_operand_mode[(int)CODE_FOR_casesi][2];
5287 if (! (*insn_operand_predicate[(int)CODE_FOR_casesi][2])
5289 op2 = copy_to_mode_reg (op_mode, op2);
5291 emit_jump_insn (gen_casesi (index, op1, op2,
5292 table_label, default_label));
5296 #ifdef HAVE_tablejump
5297 if (! win && HAVE_tablejump)
5299 index_expr = convert (thiscase->data.case_stmt.nominal_type,
5300 fold (build (MINUS_EXPR, index_type,
5301 index_expr, minval)));
5302 index_type = TREE_TYPE (index_expr);
5303 index = expand_expr (index_expr, NULL_RTX, VOIDmode, 0);
5305 index = protect_from_queue (index, 0);
5306 do_pending_stack_adjust ();
5308 do_tablejump (index, TYPE_MODE (index_type),
5309 expand_expr (range, NULL_RTX, VOIDmode, 0),
5310 table_label, default_label);
5317 /* Get table of labels to jump to, in order of case index. */
5319 ncases = TREE_INT_CST_LOW (range) + 1;
5320 labelvec = (rtx *) alloca (ncases * sizeof (rtx));
5321 bzero ((char *) labelvec, ncases * sizeof (rtx));
5323 for (n = thiscase->data.case_stmt.case_list; n; n = n->right)
5325 register HOST_WIDE_INT i
5326 = TREE_INT_CST_LOW (n->low) - TREE_INT_CST_LOW (orig_minval);
5331 = gen_rtx_LABEL_REF (Pmode, label_rtx (n->code_label));
5332 if (i + TREE_INT_CST_LOW (orig_minval)
5333 == TREE_INT_CST_LOW (n->high))
5339 /* Fill in the gaps with the default. */
5340 for (i = 0; i < ncases; i++)
5341 if (labelvec[i] == 0)
5342 labelvec[i] = gen_rtx_LABEL_REF (Pmode, default_label);
5344 /* Output the table */
5345 emit_label (table_label);
5347 if (CASE_VECTOR_PC_RELATIVE || flag_pic)
5348 emit_jump_insn (gen_rtx_ADDR_DIFF_VEC (CASE_VECTOR_MODE,
5349 gen_rtx_LABEL_REF (Pmode, table_label),
5350 gen_rtvec_v (ncases, labelvec),
5351 const0_rtx, const0_rtx));
5353 emit_jump_insn (gen_rtx_ADDR_VEC (CASE_VECTOR_MODE,
5354 gen_rtvec_v (ncases, labelvec)));
5356 /* If the case insn drops through the table,
5357 after the table we must jump to the default-label.
5358 Otherwise record no drop-through after the table. */
5359 #ifdef CASE_DROPS_THROUGH
5360 emit_jump (default_label);
5366 before_case = squeeze_notes (NEXT_INSN (before_case), get_last_insn ());
5367 reorder_insns (before_case, get_last_insn (),
5368 thiscase->data.case_stmt.start);
5371 end_cleanup_deferral ();
5373 if (thiscase->exit_label)
5374 emit_label (thiscase->exit_label);
5376 POPSTACK (case_stack);
5381 /* Convert the tree NODE into a list linked by the right field, with the left
5382 field zeroed. RIGHT is used for recursion; it is a list to be placed
5383 rightmost in the resulting list. */
5385 static struct case_node *
5386 case_tree2list (node, right)
5387 struct case_node *node, *right;
5389 struct case_node *left;
5392 right = case_tree2list (node->right, right);
5394 node->right = right;
5395 if ((left = node->left))
5398 return case_tree2list (left, node);
5404 /* Generate code to jump to LABEL if OP1 and OP2 are equal. */
5407 do_jump_if_equal (op1, op2, label, unsignedp)
5408 rtx op1, op2, label;
5411 if (GET_CODE (op1) == CONST_INT
5412 && GET_CODE (op2) == CONST_INT)
5414 if (INTVAL (op1) == INTVAL (op2))
5419 enum machine_mode mode = GET_MODE (op1);
5420 if (mode == VOIDmode)
5421 mode = GET_MODE (op2);
5422 emit_cmp_and_jump_insns (op1, op2, EQ, NULL_RTX, mode, unsignedp,
5427 /* Not all case values are encountered equally. This function
5428 uses a heuristic to weight case labels, in cases where that
5429 looks like a reasonable thing to do.
5431 Right now, all we try to guess is text, and we establish the
5434 chars above space: 16
5443 If we find any cases in the switch that are not either -1 or in the range
5444 of valid ASCII characters, or are control characters other than those
5445 commonly used with "\", don't treat this switch scanning text.
5447 Return 1 if these nodes are suitable for cost estimation, otherwise
5451 estimate_case_costs (node)
5454 tree min_ascii = build_int_2 (-1, -1);
5455 tree max_ascii = convert (TREE_TYPE (node->high), build_int_2 (127, 0));
5459 /* If we haven't already made the cost table, make it now. Note that the
5460 lower bound of the table is -1, not zero. */
5462 if (cost_table == NULL)
5464 cost_table = ((short *) xmalloc (129 * sizeof (short))) + 1;
5465 bzero ((char *) (cost_table - 1), 129 * sizeof (short));
5467 for (i = 0; i < 128; i++)
5471 else if (ISPUNCT (i))
5473 else if (ISCNTRL (i))
5477 cost_table[' '] = 8;
5478 cost_table['\t'] = 4;
5479 cost_table['\0'] = 4;
5480 cost_table['\n'] = 2;
5481 cost_table['\f'] = 1;
5482 cost_table['\v'] = 1;
5483 cost_table['\b'] = 1;
5486 /* See if all the case expressions look like text. It is text if the
5487 constant is >= -1 and the highest constant is <= 127. Do all comparisons
5488 as signed arithmetic since we don't want to ever access cost_table with a
5489 value less than -1. Also check that none of the constants in a range
5490 are strange control characters. */
5492 for (n = node; n; n = n->right)
5494 if ((INT_CST_LT (n->low, min_ascii)) || INT_CST_LT (max_ascii, n->high))
5497 for (i = TREE_INT_CST_LOW (n->low); i <= TREE_INT_CST_LOW (n->high); i++)
5498 if (cost_table[i] < 0)
5502 /* All interesting values are within the range of interesting
5503 ASCII characters. */
5507 /* Scan an ordered list of case nodes
5508 combining those with consecutive values or ranges.
5510 Eg. three separate entries 1: 2: 3: become one entry 1..3: */
5513 group_case_nodes (head)
5516 case_node_ptr node = head;
5520 rtx lb = next_real_insn (label_rtx (node->code_label));
5522 case_node_ptr np = node;
5524 /* Try to group the successors of NODE with NODE. */
5525 while (((np = np->right) != 0)
5526 /* Do they jump to the same place? */
5527 && ((lb2 = next_real_insn (label_rtx (np->code_label))) == lb
5528 || (lb != 0 && lb2 != 0
5529 && simplejump_p (lb)
5530 && simplejump_p (lb2)
5531 && rtx_equal_p (SET_SRC (PATTERN (lb)),
5532 SET_SRC (PATTERN (lb2)))))
5533 /* Are their ranges consecutive? */
5534 && tree_int_cst_equal (np->low,
5535 fold (build (PLUS_EXPR,
5536 TREE_TYPE (node->high),
5539 /* An overflow is not consecutive. */
5540 && tree_int_cst_lt (node->high,
5541 fold (build (PLUS_EXPR,
5542 TREE_TYPE (node->high),
5544 integer_one_node))))
5546 node->high = np->high;
5548 /* NP is the first node after NODE which can't be grouped with it.
5549 Delete the nodes in between, and move on to that node. */
5555 /* Take an ordered list of case nodes
5556 and transform them into a near optimal binary tree,
5557 on the assumption that any target code selection value is as
5558 likely as any other.
5560 The transformation is performed by splitting the ordered
5561 list into two equal sections plus a pivot. The parts are
5562 then attached to the pivot as left and right branches. Each
5563 branch is then transformed recursively. */
5566 balance_case_nodes (head, parent)
5567 case_node_ptr *head;
5568 case_node_ptr parent;
5570 register case_node_ptr np;
5578 register case_node_ptr *npp;
5581 /* Count the number of entries on branch. Also count the ranges. */
5585 if (!tree_int_cst_equal (np->low, np->high))
5589 cost += cost_table[TREE_INT_CST_LOW (np->high)];
5593 cost += cost_table[TREE_INT_CST_LOW (np->low)];
5601 /* Split this list if it is long enough for that to help. */
5606 /* Find the place in the list that bisects the list's total cost,
5607 Here I gets half the total cost. */
5612 /* Skip nodes while their cost does not reach that amount. */
5613 if (!tree_int_cst_equal ((*npp)->low, (*npp)->high))
5614 i -= cost_table[TREE_INT_CST_LOW ((*npp)->high)];
5615 i -= cost_table[TREE_INT_CST_LOW ((*npp)->low)];
5618 npp = &(*npp)->right;
5623 /* Leave this branch lopsided, but optimize left-hand
5624 side and fill in `parent' fields for right-hand side. */
5626 np->parent = parent;
5627 balance_case_nodes (&np->left, np);
5628 for (; np->right; np = np->right)
5629 np->right->parent = np;
5633 /* If there are just three nodes, split at the middle one. */
5635 npp = &(*npp)->right;
5638 /* Find the place in the list that bisects the list's total cost,
5639 where ranges count as 2.
5640 Here I gets half the total cost. */
5641 i = (i + ranges + 1) / 2;
5644 /* Skip nodes while their cost does not reach that amount. */
5645 if (!tree_int_cst_equal ((*npp)->low, (*npp)->high))
5650 npp = &(*npp)->right;
5655 np->parent = parent;
5658 /* Optimize each of the two split parts. */
5659 balance_case_nodes (&np->left, np);
5660 balance_case_nodes (&np->right, np);
5664 /* Else leave this branch as one level,
5665 but fill in `parent' fields. */
5667 np->parent = parent;
5668 for (; np->right; np = np->right)
5669 np->right->parent = np;
5674 /* Search the parent sections of the case node tree
5675 to see if a test for the lower bound of NODE would be redundant.
5676 INDEX_TYPE is the type of the index expression.
5678 The instructions to generate the case decision tree are
5679 output in the same order as nodes are processed so it is
5680 known that if a parent node checks the range of the current
5681 node minus one that the current node is bounded at its lower
5682 span. Thus the test would be redundant. */
5685 node_has_low_bound (node, index_type)
5690 case_node_ptr pnode;
5692 /* If the lower bound of this node is the lowest value in the index type,
5693 we need not test it. */
5695 if (tree_int_cst_equal (node->low, TYPE_MIN_VALUE (index_type)))
5698 /* If this node has a left branch, the value at the left must be less
5699 than that at this node, so it cannot be bounded at the bottom and
5700 we need not bother testing any further. */
5705 low_minus_one = fold (build (MINUS_EXPR, TREE_TYPE (node->low),
5706 node->low, integer_one_node));
5708 /* If the subtraction above overflowed, we can't verify anything.
5709 Otherwise, look for a parent that tests our value - 1. */
5711 if (! tree_int_cst_lt (low_minus_one, node->low))
5714 for (pnode = node->parent; pnode; pnode = pnode->parent)
5715 if (tree_int_cst_equal (low_minus_one, pnode->high))
5721 /* Search the parent sections of the case node tree
5722 to see if a test for the upper bound of NODE would be redundant.
5723 INDEX_TYPE is the type of the index expression.
5725 The instructions to generate the case decision tree are
5726 output in the same order as nodes are processed so it is
5727 known that if a parent node checks the range of the current
5728 node plus one that the current node is bounded at its upper
5729 span. Thus the test would be redundant. */
5732 node_has_high_bound (node, index_type)
5737 case_node_ptr pnode;
5739 /* If there is no upper bound, obviously no test is needed. */
5741 if (TYPE_MAX_VALUE (index_type) == NULL)
5744 /* If the upper bound of this node is the highest value in the type
5745 of the index expression, we need not test against it. */
5747 if (tree_int_cst_equal (node->high, TYPE_MAX_VALUE (index_type)))
5750 /* If this node has a right branch, the value at the right must be greater
5751 than that at this node, so it cannot be bounded at the top and
5752 we need not bother testing any further. */
5757 high_plus_one = fold (build (PLUS_EXPR, TREE_TYPE (node->high),
5758 node->high, integer_one_node));
5760 /* If the addition above overflowed, we can't verify anything.
5761 Otherwise, look for a parent that tests our value + 1. */
5763 if (! tree_int_cst_lt (node->high, high_plus_one))
5766 for (pnode = node->parent; pnode; pnode = pnode->parent)
5767 if (tree_int_cst_equal (high_plus_one, pnode->low))
5773 /* Search the parent sections of the
5774 case node tree to see if both tests for the upper and lower
5775 bounds of NODE would be redundant. */
5778 node_is_bounded (node, index_type)
5782 return (node_has_low_bound (node, index_type)
5783 && node_has_high_bound (node, index_type));
5786 /* Emit an unconditional jump to LABEL unless it would be dead code. */
5789 emit_jump_if_reachable (label)
5792 if (GET_CODE (get_last_insn ()) != BARRIER)
5796 /* Emit step-by-step code to select a case for the value of INDEX.
5797 The thus generated decision tree follows the form of the
5798 case-node binary tree NODE, whose nodes represent test conditions.
5799 INDEX_TYPE is the type of the index of the switch.
5801 Care is taken to prune redundant tests from the decision tree
5802 by detecting any boundary conditions already checked by
5803 emitted rtx. (See node_has_high_bound, node_has_low_bound
5804 and node_is_bounded, above.)
5806 Where the test conditions can be shown to be redundant we emit
5807 an unconditional jump to the target code. As a further
5808 optimization, the subordinates of a tree node are examined to
5809 check for bounded nodes. In this case conditional and/or
5810 unconditional jumps as a result of the boundary check for the
5811 current node are arranged to target the subordinates associated
5812 code for out of bound conditions on the current node.
5814 We can assume that when control reaches the code generated here,
5815 the index value has already been compared with the parents
5816 of this node, and determined to be on the same side of each parent
5817 as this node is. Thus, if this node tests for the value 51,
5818 and a parent tested for 52, we don't need to consider
5819 the possibility of a value greater than 51. If another parent
5820 tests for the value 50, then this node need not test anything. */
5823 emit_case_nodes (index, node, default_label, index_type)
5829 /* If INDEX has an unsigned type, we must make unsigned branches. */
5830 int unsignedp = TREE_UNSIGNED (index_type);
5831 typedef rtx rtx_fn ();
5832 enum machine_mode mode = GET_MODE (index);
5834 /* See if our parents have already tested everything for us.
5835 If they have, emit an unconditional jump for this node. */
5836 if (node_is_bounded (node, index_type))
5837 emit_jump (label_rtx (node->code_label));
5839 else if (tree_int_cst_equal (node->low, node->high))
5841 /* Node is single valued. First see if the index expression matches
5842 this node and then check our children, if any. */
5844 do_jump_if_equal (index, expand_expr (node->low, NULL_RTX, VOIDmode, 0),
5845 label_rtx (node->code_label), unsignedp);
5847 if (node->right != 0 && node->left != 0)
5849 /* This node has children on both sides.
5850 Dispatch to one side or the other
5851 by comparing the index value with this node's value.
5852 If one subtree is bounded, check that one first,
5853 so we can avoid real branches in the tree. */
5855 if (node_is_bounded (node->right, index_type))
5857 emit_cmp_and_jump_insns (index, expand_expr (node->high, NULL_RTX,
5859 GT, NULL_RTX, mode, unsignedp, 0,
5860 label_rtx (node->right->code_label));
5861 emit_case_nodes (index, node->left, default_label, index_type);
5864 else if (node_is_bounded (node->left, index_type))
5866 emit_cmp_and_jump_insns (index, expand_expr (node->high, NULL_RTX,
5868 LT, NULL_RTX, mode, unsignedp, 0,
5869 label_rtx (node->left->code_label));
5870 emit_case_nodes (index, node->right, default_label, index_type);
5875 /* Neither node is bounded. First distinguish the two sides;
5876 then emit the code for one side at a time. */
5879 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
5881 /* See if the value is on the right. */
5882 emit_cmp_and_jump_insns (index, expand_expr (node->high, NULL_RTX,
5884 GT, NULL_RTX, mode, unsignedp, 0,
5885 label_rtx (test_label));
5887 /* Value must be on the left.
5888 Handle the left-hand subtree. */
5889 emit_case_nodes (index, node->left, default_label, index_type);
5890 /* If left-hand subtree does nothing,
5892 emit_jump_if_reachable (default_label);
5894 /* Code branches here for the right-hand subtree. */
5895 expand_label (test_label);
5896 emit_case_nodes (index, node->right, default_label, index_type);
5900 else if (node->right != 0 && node->left == 0)
5902 /* Here we have a right child but no left so we issue conditional
5903 branch to default and process the right child.
5905 Omit the conditional branch to default if we it avoid only one
5906 right child; it costs too much space to save so little time. */
5908 if (node->right->right || node->right->left
5909 || !tree_int_cst_equal (node->right->low, node->right->high))
5911 if (!node_has_low_bound (node, index_type))
5913 emit_cmp_and_jump_insns (index, expand_expr (node->high,
5916 LT, NULL_RTX, mode, unsignedp, 0,
5920 emit_case_nodes (index, node->right, default_label, index_type);
5923 /* We cannot process node->right normally
5924 since we haven't ruled out the numbers less than
5925 this node's value. So handle node->right explicitly. */
5926 do_jump_if_equal (index,
5927 expand_expr (node->right->low, NULL_RTX,
5929 label_rtx (node->right->code_label), unsignedp);
5932 else if (node->right == 0 && node->left != 0)
5934 /* Just one subtree, on the left. */
5936 #if 0 /* The following code and comment were formerly part
5937 of the condition here, but they didn't work
5938 and I don't understand what the idea was. -- rms. */
5939 /* If our "most probable entry" is less probable
5940 than the default label, emit a jump to
5941 the default label using condition codes
5942 already lying around. With no right branch,
5943 a branch-greater-than will get us to the default
5946 && cost_table[TREE_INT_CST_LOW (node->high)] < 12)
5949 if (node->left->left || node->left->right
5950 || !tree_int_cst_equal (node->left->low, node->left->high))
5952 if (!node_has_high_bound (node, index_type))
5954 emit_cmp_and_jump_insns (index, expand_expr (node->high,
5957 GT, NULL_RTX, mode, unsignedp, 0,
5961 emit_case_nodes (index, node->left, default_label, index_type);
5964 /* We cannot process node->left normally
5965 since we haven't ruled out the numbers less than
5966 this node's value. So handle node->left explicitly. */
5967 do_jump_if_equal (index,
5968 expand_expr (node->left->low, NULL_RTX,
5970 label_rtx (node->left->code_label), unsignedp);
5975 /* Node is a range. These cases are very similar to those for a single
5976 value, except that we do not start by testing whether this node
5977 is the one to branch to. */
5979 if (node->right != 0 && node->left != 0)
5981 /* Node has subtrees on both sides.
5982 If the right-hand subtree is bounded,
5983 test for it first, since we can go straight there.
5984 Otherwise, we need to make a branch in the control structure,
5985 then handle the two subtrees. */
5986 tree test_label = 0;
5989 if (node_is_bounded (node->right, index_type))
5990 /* Right hand node is fully bounded so we can eliminate any
5991 testing and branch directly to the target code. */
5992 emit_cmp_and_jump_insns (index, expand_expr (node->high, NULL_RTX,
5994 GT, NULL_RTX, mode, unsignedp, 0,
5995 label_rtx (node->right->code_label));
5998 /* Right hand node requires testing.
5999 Branch to a label where we will handle it later. */
6001 test_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
6002 emit_cmp_and_jump_insns (index, expand_expr (node->high, NULL_RTX,
6004 GT, NULL_RTX, mode, unsignedp, 0,
6005 label_rtx (test_label));
6008 /* Value belongs to this node or to the left-hand subtree. */
6010 emit_cmp_and_jump_insns (index, expand_expr (node->low, NULL_RTX,
6012 GE, NULL_RTX, mode, unsignedp, 0,
6013 label_rtx (node->code_label));
6015 /* Handle the left-hand subtree. */
6016 emit_case_nodes (index, node->left, default_label, index_type);
6018 /* If right node had to be handled later, do that now. */
6022 /* If the left-hand subtree fell through,
6023 don't let it fall into the right-hand subtree. */
6024 emit_jump_if_reachable (default_label);
6026 expand_label (test_label);
6027 emit_case_nodes (index, node->right, default_label, index_type);
6031 else if (node->right != 0 && node->left == 0)
6033 /* Deal with values to the left of this node,
6034 if they are possible. */
6035 if (!node_has_low_bound (node, index_type))
6037 emit_cmp_and_jump_insns (index, expand_expr (node->low, NULL_RTX,
6039 LT, NULL_RTX, mode, unsignedp, 0,
6043 /* Value belongs to this node or to the right-hand subtree. */
6045 emit_cmp_and_jump_insns (index, expand_expr (node->high, NULL_RTX,
6047 LE, NULL_RTX, mode, unsignedp, 0,
6048 label_rtx (node->code_label));
6050 emit_case_nodes (index, node->right, default_label, index_type);
6053 else if (node->right == 0 && node->left != 0)
6055 /* Deal with values to the right of this node,
6056 if they are possible. */
6057 if (!node_has_high_bound (node, index_type))
6059 emit_cmp_and_jump_insns (index, expand_expr (node->high, NULL_RTX,
6061 GT, NULL_RTX, mode, unsignedp, 0,
6065 /* Value belongs to this node or to the left-hand subtree. */
6067 emit_cmp_and_jump_insns (index, expand_expr (node->low, NULL_RTX,
6069 GE, NULL_RTX, mode, unsignedp, 0,
6070 label_rtx (node->code_label));
6072 emit_case_nodes (index, node->left, default_label, index_type);
6077 /* Node has no children so we check low and high bounds to remove
6078 redundant tests. Only one of the bounds can exist,
6079 since otherwise this node is bounded--a case tested already. */
6081 if (!node_has_high_bound (node, index_type))
6083 emit_cmp_and_jump_insns (index, expand_expr (node->high, NULL_RTX,
6085 GT, NULL_RTX, mode, unsignedp, 0,
6089 if (!node_has_low_bound (node, index_type))
6091 emit_cmp_and_jump_insns (index, expand_expr (node->low, NULL_RTX,
6093 LT, NULL_RTX, mode, unsignedp, 0,
6097 emit_jump (label_rtx (node->code_label));
6102 /* These routines are used by the loop unrolling code. They copy BLOCK trees
6103 so that the debugging info will be correct for the unrolled loop. */
6105 /* Indexed by block number, contains a pointer to the N'th block node.
6107 Allocated by the call to identify_blocks, then released after the call
6108 to reorder_blocks in the function unroll_block_trees. */
6110 static tree *block_vector;
6113 find_loop_tree_blocks ()
6115 tree block = DECL_INITIAL (current_function_decl);
6117 block_vector = identify_blocks (block, get_insns ());
6121 unroll_block_trees ()
6123 tree block = DECL_INITIAL (current_function_decl);
6125 reorder_blocks (block_vector, block, get_insns ());
6127 /* Release any memory allocated by identify_blocks. */
6129 free (block_vector);