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 #ifdef MD_ASM_CLOBBERS
1157 /* Sometimes we wish to automatically clobber registers across an asm.
1158 Case in point is when the i386 backend moved from cc0 to a hard reg --
1159 maintaining source-level compatability means automatically clobbering
1160 the flags register. */
1161 MD_ASM_CLOBBERS (clobbers);
1164 /* Count the number of meaningful clobbered registers, ignoring what
1165 we would ignore later. */
1167 for (tail = clobbers; tail; tail = TREE_CHAIN (tail))
1169 char *regname = TREE_STRING_POINTER (TREE_VALUE (tail));
1170 i = decode_reg_name (regname);
1171 if (i >= 0 || i == -4)
1174 error ("unknown register name `%s' in `asm'", regname);
1179 /* Check that the number of alternatives is constant across all
1181 if (outputs || inputs)
1183 tree tmp = TREE_PURPOSE (outputs ? outputs : inputs);
1184 int nalternatives = n_occurrences (',', TREE_STRING_POINTER (tmp));
1187 if (nalternatives + 1 > MAX_RECOG_ALTERNATIVES)
1189 error ("too many alternatives in `asm'");
1196 char *constraint = TREE_STRING_POINTER (TREE_PURPOSE (tmp));
1197 if (n_occurrences (',', constraint) != nalternatives)
1199 error ("operand constraints for `asm' differ in number of alternatives");
1202 if (TREE_CHAIN (tmp))
1203 tmp = TREE_CHAIN (tmp);
1205 tmp = next, next = 0;
1209 for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
1211 tree val = TREE_VALUE (tail);
1212 tree type = TREE_TYPE (val);
1221 /* If there's an erroneous arg, emit no insn. */
1222 if (TREE_TYPE (val) == error_mark_node)
1225 /* Make sure constraint has `=' and does not have `+'. Also, see
1226 if it allows any register. Be liberal on the latter test, since
1227 the worst that happens if we get it wrong is we issue an error
1230 c_len = TREE_STRING_LENGTH (TREE_PURPOSE (tail)) - 1;
1231 constraint = TREE_STRING_POINTER (TREE_PURPOSE (tail));
1233 /* Allow the `=' or `+' to not be at the beginning of the string,
1234 since it wasn't explicitly documented that way, and there is a
1235 large body of code that puts it last. Swap the character to
1236 the front, so as not to uglify any place else. */
1240 if ((p = strchr (constraint, '=')) != NULL)
1242 if ((p = strchr (constraint, '+')) != NULL)
1245 error ("output operand constraint lacks `='");
1249 if (p != constraint)
1252 bcopy (constraint, constraint+1, p-constraint);
1255 warning ("output constraint `%c' for operand %d is not at the beginning", j, i);
1258 is_inout = constraint[0] == '+';
1259 /* Replace '+' with '='. */
1260 constraint[0] = '=';
1261 /* Make sure we can specify the matching operand. */
1262 if (is_inout && i > 9)
1264 error ("output operand constraint %d contains `+'", i);
1268 for (j = 1; j < c_len; j++)
1269 switch (constraint[j])
1273 error ("operand constraint contains '+' or '=' at illegal position.");
1277 if (i + 1 == ninputs + noutputs)
1279 error ("`%%' constraint used with last operand");
1284 case '?': case '!': case '*': case '&':
1285 case 'E': case 'F': case 'G': case 'H':
1286 case 's': case 'i': case 'n':
1287 case 'I': case 'J': case 'K': case 'L': case 'M':
1288 case 'N': case 'O': case 'P': case ',':
1289 #ifdef EXTRA_CONSTRAINT
1290 case 'Q': case 'R': case 'S': case 'T': case 'U':
1294 case '0': case '1': case '2': case '3': case '4':
1295 case '5': case '6': case '7': case '8': case '9':
1296 error ("matching constraint not valid in output operand");
1299 case 'V': case 'm': case 'o':
1304 /* ??? Before flow, auto inc/dec insns are not supposed to exist,
1305 excepting those that expand_call created. So match memory
1321 /* If an output operand is not a decl or indirect ref and our constraint
1322 allows a register, make a temporary to act as an intermediate.
1323 Make the asm insn write into that, then our caller will copy it to
1324 the real output operand. Likewise for promoted variables. */
1326 real_output_rtx[i] = NULL_RTX;
1327 if ((TREE_CODE (val) == INDIRECT_REF
1329 || (TREE_CODE_CLASS (TREE_CODE (val)) == 'd'
1330 && (allows_mem || GET_CODE (DECL_RTL (val)) == REG)
1331 && ! (GET_CODE (DECL_RTL (val)) == REG
1332 && GET_MODE (DECL_RTL (val)) != TYPE_MODE (type)))
1337 mark_addressable (TREE_VALUE (tail));
1340 = expand_expr (TREE_VALUE (tail), NULL_RTX, VOIDmode,
1341 EXPAND_MEMORY_USE_WO);
1343 if (! allows_reg && GET_CODE (output_rtx[i]) != MEM)
1344 error ("output number %d not directly addressable", i);
1345 if (! allows_mem && GET_CODE (output_rtx[i]) == MEM)
1347 real_output_rtx[i] = protect_from_queue (output_rtx[i], 1);
1348 output_rtx[i] = gen_reg_rtx (GET_MODE (output_rtx[i]));
1350 emit_move_insn (output_rtx[i], real_output_rtx[i]);
1355 output_rtx[i] = assign_temp (type, 0, 0, 0);
1356 TREE_VALUE (tail) = make_tree (type, output_rtx[i]);
1361 inout_mode[ninout] = TYPE_MODE (TREE_TYPE (TREE_VALUE (tail)));
1362 inout_opnum[ninout++] = i;
1367 if (ninputs + noutputs > MAX_RECOG_OPERANDS)
1369 error ("more than %d operands in `asm'", MAX_RECOG_OPERANDS);
1373 /* Make vectors for the expression-rtx and constraint strings. */
1375 argvec = rtvec_alloc (ninputs);
1376 constraints = rtvec_alloc (ninputs);
1378 body = gen_rtx_ASM_OPERANDS (VOIDmode,
1379 TREE_STRING_POINTER (string), "", 0, argvec,
1380 constraints, filename, line);
1382 MEM_VOLATILE_P (body) = vol;
1384 /* Eval the inputs and put them into ARGVEC.
1385 Put their constraints into ASM_INPUTs and store in CONSTRAINTS. */
1388 for (tail = inputs; tail; tail = TREE_CHAIN (tail))
1391 int allows_reg = 0, allows_mem = 0;
1392 char *constraint, *orig_constraint;
1396 /* If there's an erroneous arg, emit no insn,
1397 because the ASM_INPUT would get VOIDmode
1398 and that could cause a crash in reload. */
1399 if (TREE_TYPE (TREE_VALUE (tail)) == error_mark_node)
1402 /* ??? Can this happen, and does the error message make any sense? */
1403 if (TREE_PURPOSE (tail) == NULL_TREE)
1405 error ("hard register `%s' listed as input operand to `asm'",
1406 TREE_STRING_POINTER (TREE_VALUE (tail)) );
1410 c_len = TREE_STRING_LENGTH (TREE_PURPOSE (tail)) - 1;
1411 constraint = TREE_STRING_POINTER (TREE_PURPOSE (tail));
1412 orig_constraint = constraint;
1414 /* Make sure constraint has neither `=', `+', nor '&'. */
1416 for (j = 0; j < c_len; j++)
1417 switch (constraint[j])
1419 case '+': case '=': case '&':
1420 if (constraint == orig_constraint)
1422 error ("input operand constraint contains `%c'", constraint[j]);
1428 if (constraint == orig_constraint
1429 && i + 1 == ninputs - ninout)
1431 error ("`%%' constraint used with last operand");
1436 case 'V': case 'm': case 'o':
1441 case '?': case '!': case '*':
1442 case 'E': case 'F': case 'G': case 'H': case 'X':
1443 case 's': case 'i': case 'n':
1444 case 'I': case 'J': case 'K': case 'L': case 'M':
1445 case 'N': case 'O': case 'P': case ',':
1446 #ifdef EXTRA_CONSTRAINT
1447 case 'Q': case 'R': case 'S': case 'T': case 'U':
1451 /* Whether or not a numeric constraint allows a register is
1452 decided by the matching constraint, and so there is no need
1453 to do anything special with them. We must handle them in
1454 the default case, so that we don't unnecessarily force
1455 operands to memory. */
1456 case '0': case '1': case '2': case '3': case '4':
1457 case '5': case '6': case '7': case '8': case '9':
1458 if (constraint[j] >= '0' + noutputs)
1461 ("matching constraint references invalid operand number");
1465 /* Try and find the real constraint for this dup. */
1466 if ((j == 0 && c_len == 1)
1467 || (j == 1 && c_len == 2 && constraint[0] == '%'))
1470 for (j = constraint[j] - '0'; j > 0; --j)
1473 c_len = TREE_STRING_LENGTH (TREE_PURPOSE (o)) - 1;
1474 constraint = TREE_STRING_POINTER (TREE_PURPOSE (o));
1479 /* ... fall through ... */
1492 if (! allows_reg && allows_mem)
1493 mark_addressable (TREE_VALUE (tail));
1495 op = expand_expr (TREE_VALUE (tail), NULL_RTX, VOIDmode, 0);
1497 if (asm_operand_ok (op, constraint) <= 0)
1500 op = force_reg (TYPE_MODE (TREE_TYPE (TREE_VALUE (tail))), op);
1501 else if (!allows_mem)
1502 warning ("asm operand %d probably doesn't match constraints", i);
1503 else if (CONSTANT_P (op))
1504 op = force_const_mem (TYPE_MODE (TREE_TYPE (TREE_VALUE (tail))),
1506 else if (GET_CODE (op) == REG
1507 || GET_CODE (op) == SUBREG
1508 || GET_CODE (op) == CONCAT)
1510 tree type = TREE_TYPE (TREE_VALUE (tail));
1511 rtx memloc = assign_temp (type, 1, 1, 1);
1513 emit_move_insn (memloc, op);
1516 else if (GET_CODE (op) == MEM && MEM_VOLATILE_P (op))
1517 /* We won't recognize volatile memory as available a
1518 memory_operand at this point. Ignore it. */
1520 else if (queued_subexp_p (op))
1523 /* ??? Leave this only until we have experience with what
1524 happens in combine and elsewhere when constraints are
1526 warning ("asm operand %d probably doesn't match constraints", i);
1528 XVECEXP (body, 3, i) = op;
1530 XVECEXP (body, 4, i) /* constraints */
1531 = gen_rtx_ASM_INPUT (TYPE_MODE (TREE_TYPE (TREE_VALUE (tail))),
1536 /* Protect all the operands from the queue,
1537 now that they have all been evaluated. */
1539 for (i = 0; i < ninputs - ninout; i++)
1540 XVECEXP (body, 3, i) = protect_from_queue (XVECEXP (body, 3, i), 0);
1542 for (i = 0; i < noutputs; i++)
1543 output_rtx[i] = protect_from_queue (output_rtx[i], 1);
1545 /* For in-out operands, copy output rtx to input rtx. */
1546 for (i = 0; i < ninout; i++)
1548 static char match[9+1][2]
1549 = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
1550 int j = inout_opnum[i];
1552 XVECEXP (body, 3, ninputs - ninout + i) /* argvec */
1554 XVECEXP (body, 4, ninputs - ninout + i) /* constraints */
1555 = gen_rtx_ASM_INPUT (inout_mode[i], match[j]);
1558 /* Now, for each output, construct an rtx
1559 (set OUTPUT (asm_operands INSN OUTPUTNUMBER OUTPUTCONSTRAINT
1560 ARGVEC CONSTRAINTS))
1561 If there is more than one, put them inside a PARALLEL. */
1563 if (noutputs == 1 && nclobbers == 0)
1565 XSTR (body, 1) = TREE_STRING_POINTER (TREE_PURPOSE (outputs));
1566 insn = emit_insn (gen_rtx_SET (VOIDmode, output_rtx[0], body));
1568 else if (noutputs == 0 && nclobbers == 0)
1570 /* No output operands: put in a raw ASM_OPERANDS rtx. */
1571 insn = emit_insn (body);
1577 if (num == 0) num = 1;
1578 body = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (num + nclobbers));
1580 /* For each output operand, store a SET. */
1582 for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
1584 XVECEXP (body, 0, i)
1585 = gen_rtx_SET (VOIDmode,
1587 gen_rtx_ASM_OPERANDS (VOIDmode,
1588 TREE_STRING_POINTER (string),
1589 TREE_STRING_POINTER (TREE_PURPOSE (tail)),
1590 i, argvec, constraints,
1592 MEM_VOLATILE_P (SET_SRC (XVECEXP (body, 0, i))) = vol;
1595 /* If there are no outputs (but there are some clobbers)
1596 store the bare ASM_OPERANDS into the PARALLEL. */
1599 XVECEXP (body, 0, i++) = obody;
1601 /* Store (clobber REG) for each clobbered register specified. */
1603 for (tail = clobbers; tail; tail = TREE_CHAIN (tail))
1605 char *regname = TREE_STRING_POINTER (TREE_VALUE (tail));
1606 int j = decode_reg_name (regname);
1610 if (j == -3) /* `cc', which is not a register */
1613 if (j == -4) /* `memory', don't cache memory across asm */
1615 XVECEXP (body, 0, i++)
1616 = gen_rtx_CLOBBER (VOIDmode,
1617 gen_rtx_MEM (BLKmode,
1618 gen_rtx_SCRATCH (VOIDmode)));
1622 /* Ignore unknown register, error already signaled. */
1626 /* Use QImode since that's guaranteed to clobber just one reg. */
1627 XVECEXP (body, 0, i++)
1628 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (QImode, j));
1631 insn = emit_insn (body);
1634 /* For any outputs that needed reloading into registers, spill them
1635 back to where they belong. */
1636 for (i = 0; i < noutputs; ++i)
1637 if (real_output_rtx[i])
1638 emit_move_insn (real_output_rtx[i], output_rtx[i]);
1643 /* Generate RTL to evaluate the expression EXP
1644 and remember it in case this is the VALUE in a ({... VALUE; }) constr. */
1647 expand_expr_stmt (exp)
1650 /* If -W, warn about statements with no side effects,
1651 except for an explicit cast to void (e.g. for assert()), and
1652 except inside a ({...}) where they may be useful. */
1653 if (expr_stmts_for_value == 0 && exp != error_mark_node)
1655 if (! TREE_SIDE_EFFECTS (exp) && (extra_warnings || warn_unused)
1656 && !(TREE_CODE (exp) == CONVERT_EXPR
1657 && TREE_TYPE (exp) == void_type_node))
1658 warning_with_file_and_line (emit_filename, emit_lineno,
1659 "statement with no effect");
1660 else if (warn_unused)
1661 warn_if_unused_value (exp);
1664 /* If EXP is of function type and we are expanding statements for
1665 value, convert it to pointer-to-function. */
1666 if (expr_stmts_for_value && TREE_CODE (TREE_TYPE (exp)) == FUNCTION_TYPE)
1667 exp = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (exp)), exp);
1669 last_expr_type = TREE_TYPE (exp);
1670 last_expr_value = expand_expr (exp,
1671 (expr_stmts_for_value
1672 ? NULL_RTX : const0_rtx),
1675 /* If all we do is reference a volatile value in memory,
1676 copy it to a register to be sure it is actually touched. */
1677 if (last_expr_value != 0 && GET_CODE (last_expr_value) == MEM
1678 && TREE_THIS_VOLATILE (exp))
1680 if (TYPE_MODE (TREE_TYPE (exp)) == VOIDmode)
1682 else if (TYPE_MODE (TREE_TYPE (exp)) != BLKmode)
1683 copy_to_reg (last_expr_value);
1686 rtx lab = gen_label_rtx ();
1688 /* Compare the value with itself to reference it. */
1689 emit_cmp_and_jump_insns (last_expr_value, last_expr_value, EQ,
1690 expand_expr (TYPE_SIZE (last_expr_type),
1691 NULL_RTX, VOIDmode, 0),
1693 TYPE_ALIGN (last_expr_type) / BITS_PER_UNIT,
1699 /* If this expression is part of a ({...}) and is in memory, we may have
1700 to preserve temporaries. */
1701 preserve_temp_slots (last_expr_value);
1703 /* Free any temporaries used to evaluate this expression. Any temporary
1704 used as a result of this expression will already have been preserved
1711 /* Warn if EXP contains any computations whose results are not used.
1712 Return 1 if a warning is printed; 0 otherwise. */
1715 warn_if_unused_value (exp)
1718 if (TREE_USED (exp))
1721 switch (TREE_CODE (exp))
1723 case PREINCREMENT_EXPR:
1724 case POSTINCREMENT_EXPR:
1725 case PREDECREMENT_EXPR:
1726 case POSTDECREMENT_EXPR:
1731 case METHOD_CALL_EXPR:
1733 case TRY_CATCH_EXPR:
1734 case WITH_CLEANUP_EXPR:
1736 /* We don't warn about COND_EXPR because it may be a useful
1737 construct if either arm contains a side effect. */
1742 /* For a binding, warn if no side effect within it. */
1743 return warn_if_unused_value (TREE_OPERAND (exp, 1));
1746 return warn_if_unused_value (TREE_OPERAND (exp, 1));
1748 case TRUTH_ORIF_EXPR:
1749 case TRUTH_ANDIF_EXPR:
1750 /* In && or ||, warn if 2nd operand has no side effect. */
1751 return warn_if_unused_value (TREE_OPERAND (exp, 1));
1754 if (TREE_NO_UNUSED_WARNING (exp))
1756 if (warn_if_unused_value (TREE_OPERAND (exp, 0)))
1758 /* Let people do `(foo (), 0)' without a warning. */
1759 if (TREE_CONSTANT (TREE_OPERAND (exp, 1)))
1761 return warn_if_unused_value (TREE_OPERAND (exp, 1));
1765 case NON_LVALUE_EXPR:
1766 /* Don't warn about values cast to void. */
1767 if (TREE_TYPE (exp) == void_type_node)
1769 /* Don't warn about conversions not explicit in the user's program. */
1770 if (TREE_NO_UNUSED_WARNING (exp))
1772 /* Assignment to a cast usually results in a cast of a modify.
1773 Don't complain about that. There can be an arbitrary number of
1774 casts before the modify, so we must loop until we find the first
1775 non-cast expression and then test to see if that is a modify. */
1777 tree tem = TREE_OPERAND (exp, 0);
1779 while (TREE_CODE (tem) == CONVERT_EXPR || TREE_CODE (tem) == NOP_EXPR)
1780 tem = TREE_OPERAND (tem, 0);
1782 if (TREE_CODE (tem) == MODIFY_EXPR || TREE_CODE (tem) == INIT_EXPR
1783 || TREE_CODE (tem) == CALL_EXPR)
1789 /* Don't warn about automatic dereferencing of references, since
1790 the user cannot control it. */
1791 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == REFERENCE_TYPE)
1792 return warn_if_unused_value (TREE_OPERAND (exp, 0));
1793 /* ... fall through ... */
1796 /* Referencing a volatile value is a side effect, so don't warn. */
1797 if ((TREE_CODE_CLASS (TREE_CODE (exp)) == 'd'
1798 || TREE_CODE_CLASS (TREE_CODE (exp)) == 'r')
1799 && TREE_THIS_VOLATILE (exp))
1802 warning_with_file_and_line (emit_filename, emit_lineno,
1803 "value computed is not used");
1808 /* Clear out the memory of the last expression evaluated. */
1816 /* Begin a statement which will return a value.
1817 Return the RTL_EXPR for this statement expr.
1818 The caller must save that value and pass it to expand_end_stmt_expr. */
1821 expand_start_stmt_expr ()
1826 /* Make the RTL_EXPR node temporary, not momentary,
1827 so that rtl_expr_chain doesn't become garbage. */
1828 momentary = suspend_momentary ();
1829 t = make_node (RTL_EXPR);
1830 resume_momentary (momentary);
1831 do_pending_stack_adjust ();
1832 start_sequence_for_rtl_expr (t);
1834 expr_stmts_for_value++;
1838 /* Restore the previous state at the end of a statement that returns a value.
1839 Returns a tree node representing the statement's value and the
1840 insns to compute the value.
1842 The nodes of that expression have been freed by now, so we cannot use them.
1843 But we don't want to do that anyway; the expression has already been
1844 evaluated and now we just want to use the value. So generate a RTL_EXPR
1845 with the proper type and RTL value.
1847 If the last substatement was not an expression,
1848 return something with type `void'. */
1851 expand_end_stmt_expr (t)
1856 if (last_expr_type == 0)
1858 last_expr_type = void_type_node;
1859 last_expr_value = const0_rtx;
1861 else if (last_expr_value == 0)
1862 /* There are some cases where this can happen, such as when the
1863 statement is void type. */
1864 last_expr_value = const0_rtx;
1865 else if (GET_CODE (last_expr_value) != REG && ! CONSTANT_P (last_expr_value))
1866 /* Remove any possible QUEUED. */
1867 last_expr_value = protect_from_queue (last_expr_value, 0);
1871 TREE_TYPE (t) = last_expr_type;
1872 RTL_EXPR_RTL (t) = last_expr_value;
1873 RTL_EXPR_SEQUENCE (t) = get_insns ();
1875 rtl_expr_chain = tree_cons (NULL_TREE, t, rtl_expr_chain);
1879 /* Don't consider deleting this expr or containing exprs at tree level. */
1880 TREE_SIDE_EFFECTS (t) = 1;
1881 /* Propagate volatility of the actual RTL expr. */
1882 TREE_THIS_VOLATILE (t) = volatile_refs_p (last_expr_value);
1885 expr_stmts_for_value--;
1890 /* Generate RTL for the start of an if-then. COND is the expression
1891 whose truth should be tested.
1893 If EXITFLAG is nonzero, this conditional is visible to
1894 `exit_something'. */
1897 expand_start_cond (cond, exitflag)
1901 struct nesting *thiscond = ALLOC_NESTING ();
1903 /* Make an entry on cond_stack for the cond we are entering. */
1905 thiscond->next = cond_stack;
1906 thiscond->all = nesting_stack;
1907 thiscond->depth = ++nesting_depth;
1908 thiscond->data.cond.next_label = gen_label_rtx ();
1909 /* Before we encounter an `else', we don't need a separate exit label
1910 unless there are supposed to be exit statements
1911 to exit this conditional. */
1912 thiscond->exit_label = exitflag ? gen_label_rtx () : 0;
1913 thiscond->data.cond.endif_label = thiscond->exit_label;
1914 cond_stack = thiscond;
1915 nesting_stack = thiscond;
1917 do_jump (cond, thiscond->data.cond.next_label, NULL_RTX);
1920 /* Generate RTL between then-clause and the elseif-clause
1921 of an if-then-elseif-.... */
1924 expand_start_elseif (cond)
1927 if (cond_stack->data.cond.endif_label == 0)
1928 cond_stack->data.cond.endif_label = gen_label_rtx ();
1929 emit_jump (cond_stack->data.cond.endif_label);
1930 emit_label (cond_stack->data.cond.next_label);
1931 cond_stack->data.cond.next_label = gen_label_rtx ();
1932 do_jump (cond, cond_stack->data.cond.next_label, NULL_RTX);
1935 /* Generate RTL between the then-clause and the else-clause
1936 of an if-then-else. */
1939 expand_start_else ()
1941 if (cond_stack->data.cond.endif_label == 0)
1942 cond_stack->data.cond.endif_label = gen_label_rtx ();
1944 emit_jump (cond_stack->data.cond.endif_label);
1945 emit_label (cond_stack->data.cond.next_label);
1946 cond_stack->data.cond.next_label = 0; /* No more _else or _elseif calls. */
1949 /* After calling expand_start_else, turn this "else" into an "else if"
1950 by providing another condition. */
1953 expand_elseif (cond)
1956 cond_stack->data.cond.next_label = gen_label_rtx ();
1957 do_jump (cond, cond_stack->data.cond.next_label, NULL_RTX);
1960 /* Generate RTL for the end of an if-then.
1961 Pop the record for it off of cond_stack. */
1966 struct nesting *thiscond = cond_stack;
1968 do_pending_stack_adjust ();
1969 if (thiscond->data.cond.next_label)
1970 emit_label (thiscond->data.cond.next_label);
1971 if (thiscond->data.cond.endif_label)
1972 emit_label (thiscond->data.cond.endif_label);
1974 POPSTACK (cond_stack);
1980 /* Generate RTL for the start of a loop. EXIT_FLAG is nonzero if this
1981 loop should be exited by `exit_something'. This is a loop for which
1982 `expand_continue' will jump to the top of the loop.
1984 Make an entry on loop_stack to record the labels associated with
1988 expand_start_loop (exit_flag)
1991 register struct nesting *thisloop = ALLOC_NESTING ();
1993 /* Make an entry on loop_stack for the loop we are entering. */
1995 thisloop->next = loop_stack;
1996 thisloop->all = nesting_stack;
1997 thisloop->depth = ++nesting_depth;
1998 thisloop->data.loop.start_label = gen_label_rtx ();
1999 thisloop->data.loop.end_label = gen_label_rtx ();
2000 thisloop->data.loop.alt_end_label = 0;
2001 thisloop->data.loop.continue_label = thisloop->data.loop.start_label;
2002 thisloop->exit_label = exit_flag ? thisloop->data.loop.end_label : 0;
2003 loop_stack = thisloop;
2004 nesting_stack = thisloop;
2006 do_pending_stack_adjust ();
2008 emit_note (NULL_PTR, NOTE_INSN_LOOP_BEG);
2009 emit_label (thisloop->data.loop.start_label);
2014 /* Like expand_start_loop but for a loop where the continuation point
2015 (for expand_continue_loop) will be specified explicitly. */
2018 expand_start_loop_continue_elsewhere (exit_flag)
2021 struct nesting *thisloop = expand_start_loop (exit_flag);
2022 loop_stack->data.loop.continue_label = gen_label_rtx ();
2026 /* Specify the continuation point for a loop started with
2027 expand_start_loop_continue_elsewhere.
2028 Use this at the point in the code to which a continue statement
2032 expand_loop_continue_here ()
2034 do_pending_stack_adjust ();
2035 emit_note (NULL_PTR, NOTE_INSN_LOOP_CONT);
2036 emit_label (loop_stack->data.loop.continue_label);
2039 /* Finish a loop. Generate a jump back to the top and the loop-exit label.
2040 Pop the block off of loop_stack. */
2045 rtx start_label = loop_stack->data.loop.start_label;
2046 rtx insn = get_last_insn ();
2047 int needs_end_jump = 1;
2049 /* Mark the continue-point at the top of the loop if none elsewhere. */
2050 if (start_label == loop_stack->data.loop.continue_label)
2051 emit_note_before (NOTE_INSN_LOOP_CONT, start_label);
2053 do_pending_stack_adjust ();
2055 /* If optimizing, perhaps reorder the loop.
2056 First, try to use a condjump near the end.
2057 expand_exit_loop_if_false ends loops with unconditional jumps,
2060 if (test) goto label;
2062 goto loop_stack->data.loop.end_label
2066 If we find such a pattern, we can end the loop earlier. */
2069 && GET_CODE (insn) == CODE_LABEL
2070 && LABEL_NAME (insn) == NULL
2071 && GET_CODE (PREV_INSN (insn)) == BARRIER)
2074 rtx jump = PREV_INSN (PREV_INSN (label));
2076 if (GET_CODE (jump) == JUMP_INSN
2077 && GET_CODE (PATTERN (jump)) == SET
2078 && SET_DEST (PATTERN (jump)) == pc_rtx
2079 && GET_CODE (SET_SRC (PATTERN (jump))) == LABEL_REF
2080 && (XEXP (SET_SRC (PATTERN (jump)), 0)
2081 == loop_stack->data.loop.end_label))
2085 /* The test might be complex and reference LABEL multiple times,
2086 like the loop in loop_iterations to set vtop. To handle this,
2088 insn = PREV_INSN (label);
2089 reorder_insns (label, label, start_label);
2091 for (prev = PREV_INSN (jump); ; prev = PREV_INSN (prev))
2093 /* We ignore line number notes, but if we see any other note,
2094 in particular NOTE_INSN_BLOCK_*, NOTE_INSN_EH_REGION_*,
2095 NOTE_INSN_LOOP_*, we disable this optimization. */
2096 if (GET_CODE (prev) == NOTE)
2098 if (NOTE_LINE_NUMBER (prev) < 0)
2102 if (GET_CODE (prev) == CODE_LABEL)
2104 if (GET_CODE (prev) == JUMP_INSN)
2106 if (GET_CODE (PATTERN (prev)) == SET
2107 && SET_DEST (PATTERN (prev)) == pc_rtx
2108 && GET_CODE (SET_SRC (PATTERN (prev))) == IF_THEN_ELSE
2109 && (GET_CODE (XEXP (SET_SRC (PATTERN (prev)), 1))
2111 && XEXP (XEXP (SET_SRC (PATTERN (prev)), 1), 0) == label)
2113 XEXP (XEXP (SET_SRC (PATTERN (prev)), 1), 0)
2115 emit_note_after (NOTE_INSN_LOOP_END, prev);
2124 /* If the loop starts with a loop exit, roll that to the end where
2125 it will optimize together with the jump back.
2127 We look for the conditional branch to the exit, except that once
2128 we find such a branch, we don't look past 30 instructions.
2130 In more detail, if the loop presently looks like this (in pseudo-C):
2133 if (test) goto end_label;
2138 transform it to look like:
2144 if (test) goto end_label;
2145 goto newstart_label;
2148 Here, the `test' may actually consist of some reasonably complex
2149 code, terminating in a test. */
2154 ! (GET_CODE (insn) == JUMP_INSN
2155 && GET_CODE (PATTERN (insn)) == SET
2156 && SET_DEST (PATTERN (insn)) == pc_rtx
2157 && GET_CODE (SET_SRC (PATTERN (insn))) == IF_THEN_ELSE))
2161 rtx last_test_insn = NULL_RTX;
2163 /* Scan insns from the top of the loop looking for a qualified
2164 conditional exit. */
2165 for (insn = NEXT_INSN (loop_stack->data.loop.start_label); insn;
2166 insn = NEXT_INSN (insn))
2168 if (GET_CODE (insn) == NOTE)
2171 && (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG
2172 || NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END))
2173 /* The code that actually moves the exit test will
2174 carefully leave BLOCK notes in their original
2175 location. That means, however, that we can't debug
2176 the exit test itself. So, we refuse to move code
2177 containing BLOCK notes at low optimization levels. */
2180 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG)
2182 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END)
2186 /* We've come to the end of an EH region, but
2187 never saw the beginning of that region. That
2188 means that an EH region begins before the top
2189 of the loop, and ends in the middle of it. The
2190 existence of such a situation violates a basic
2191 assumption in this code, since that would imply
2192 that even when EH_REGIONS is zero, we might
2193 move code out of an exception region. */
2197 /* We must not walk into a nested loop. */
2198 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
2201 /* We already know this INSN is a NOTE, so there's no
2202 point in looking at it to see if it's a JUMP. */
2206 if (GET_CODE (insn) == JUMP_INSN || GET_CODE (insn) == INSN)
2209 if (last_test_insn && num_insns > 30)
2213 /* We don't want to move a partial EH region. Consider:
2227 This isn't legal C++, but here's what it's supposed to
2228 mean: if cond() is true, stop looping. Otherwise,
2229 call bar, and keep looping. In addition, if cond
2230 throws an exception, catch it and keep looping. Such
2231 constructs are certainy legal in LISP.
2233 We should not move the `if (cond()) 0' test since then
2234 the EH-region for the try-block would be broken up.
2235 (In this case we would the EH_BEG note for the `try'
2236 and `if cond()' but not the call to bar() or the
2239 So we don't look for tests within an EH region. */
2242 if (GET_CODE (insn) == JUMP_INSN
2243 && GET_CODE (PATTERN (insn)) == SET
2244 && SET_DEST (PATTERN (insn)) == pc_rtx)
2246 /* This is indeed a jump. */
2247 rtx dest1 = NULL_RTX;
2248 rtx dest2 = NULL_RTX;
2249 rtx potential_last_test;
2250 if (GET_CODE (SET_SRC (PATTERN (insn))) == IF_THEN_ELSE)
2252 /* A conditional jump. */
2253 dest1 = XEXP (SET_SRC (PATTERN (insn)), 1);
2254 dest2 = XEXP (SET_SRC (PATTERN (insn)), 2);
2255 potential_last_test = insn;
2259 /* An unconditional jump. */
2260 dest1 = SET_SRC (PATTERN (insn));
2261 /* Include the BARRIER after the JUMP. */
2262 potential_last_test = NEXT_INSN (insn);
2266 if (dest1 && GET_CODE (dest1) == LABEL_REF
2267 && ((XEXP (dest1, 0)
2268 == loop_stack->data.loop.alt_end_label)
2270 == loop_stack->data.loop.end_label)))
2272 last_test_insn = potential_last_test;
2276 /* If this was a conditional jump, there may be
2277 another label at which we should look. */
2284 if (last_test_insn != 0 && last_test_insn != get_last_insn ())
2286 /* We found one. Move everything from there up
2287 to the end of the loop, and add a jump into the loop
2288 to jump to there. */
2289 register rtx newstart_label = gen_label_rtx ();
2290 register rtx start_move = start_label;
2293 /* If the start label is preceded by a NOTE_INSN_LOOP_CONT note,
2294 then we want to move this note also. */
2295 if (GET_CODE (PREV_INSN (start_move)) == NOTE
2296 && (NOTE_LINE_NUMBER (PREV_INSN (start_move))
2297 == NOTE_INSN_LOOP_CONT))
2298 start_move = PREV_INSN (start_move);
2300 emit_label_after (newstart_label, PREV_INSN (start_move));
2302 /* Actually move the insns. Start at the beginning, and
2303 keep copying insns until we've copied the
2305 for (insn = start_move; insn; insn = next_insn)
2307 /* Figure out which insn comes after this one. We have
2308 to do this before we move INSN. */
2309 if (insn == last_test_insn)
2310 /* We've moved all the insns. */
2311 next_insn = NULL_RTX;
2313 next_insn = NEXT_INSN (insn);
2315 if (GET_CODE (insn) == NOTE
2316 && (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG
2317 || NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END))
2318 /* We don't want to move NOTE_INSN_BLOCK_BEGs or
2319 NOTE_INSN_BLOCK_ENDs because the correct generation
2320 of debugging information depends on these appearing
2321 in the same order in the RTL and in the tree
2322 structure, where they are represented as BLOCKs.
2323 So, we don't move block notes. Of course, moving
2324 the code inside the block is likely to make it
2325 impossible to debug the instructions in the exit
2326 test, but such is the price of optimization. */
2329 /* Move the INSN. */
2330 reorder_insns (insn, insn, get_last_insn ());
2333 emit_jump_insn_after (gen_jump (start_label),
2334 PREV_INSN (newstart_label));
2335 emit_barrier_after (PREV_INSN (newstart_label));
2336 start_label = newstart_label;
2342 emit_jump (start_label);
2343 emit_note (NULL_PTR, NOTE_INSN_LOOP_END);
2345 emit_label (loop_stack->data.loop.end_label);
2347 POPSTACK (loop_stack);
2352 /* Generate a jump to the current loop's continue-point.
2353 This is usually the top of the loop, but may be specified
2354 explicitly elsewhere. If not currently inside a loop,
2355 return 0 and do nothing; caller will print an error message. */
2358 expand_continue_loop (whichloop)
2359 struct nesting *whichloop;
2363 whichloop = loop_stack;
2366 expand_goto_internal (NULL_TREE, whichloop->data.loop.continue_label,
2371 /* Generate a jump to exit the current loop. If not currently inside a loop,
2372 return 0 and do nothing; caller will print an error message. */
2375 expand_exit_loop (whichloop)
2376 struct nesting *whichloop;
2380 whichloop = loop_stack;
2383 expand_goto_internal (NULL_TREE, whichloop->data.loop.end_label, NULL_RTX);
2387 /* Generate a conditional jump to exit the current loop if COND
2388 evaluates to zero. If not currently inside a loop,
2389 return 0 and do nothing; caller will print an error message. */
2392 expand_exit_loop_if_false (whichloop, cond)
2393 struct nesting *whichloop;
2396 rtx label = gen_label_rtx ();
2401 whichloop = loop_stack;
2404 /* In order to handle fixups, we actually create a conditional jump
2405 around a unconditional branch to exit the loop. If fixups are
2406 necessary, they go before the unconditional branch. */
2409 do_jump (cond, NULL_RTX, label);
2410 last_insn = get_last_insn ();
2411 if (GET_CODE (last_insn) == CODE_LABEL)
2412 whichloop->data.loop.alt_end_label = last_insn;
2413 expand_goto_internal (NULL_TREE, whichloop->data.loop.end_label,
2420 /* Return nonzero if the loop nest is empty. Else return zero. */
2423 stmt_loop_nest_empty ()
2425 return (loop_stack == NULL);
2428 /* Return non-zero if we should preserve sub-expressions as separate
2429 pseudos. We never do so if we aren't optimizing. We always do so
2430 if -fexpensive-optimizations.
2432 Otherwise, we only do so if we are in the "early" part of a loop. I.e.,
2433 the loop may still be a small one. */
2436 preserve_subexpressions_p ()
2440 if (flag_expensive_optimizations)
2443 if (optimize == 0 || current_function == 0 || loop_stack == 0)
2446 insn = get_last_insn_anywhere ();
2449 && (INSN_UID (insn) - INSN_UID (loop_stack->data.loop.start_label)
2450 < n_non_fixed_regs * 3));
2454 /* Generate a jump to exit the current loop, conditional, binding contour
2455 or case statement. Not all such constructs are visible to this function,
2456 only those started with EXIT_FLAG nonzero. Individual languages use
2457 the EXIT_FLAG parameter to control which kinds of constructs you can
2460 If not currently inside anything that can be exited,
2461 return 0 and do nothing; caller will print an error message. */
2464 expand_exit_something ()
2468 for (n = nesting_stack; n; n = n->all)
2469 if (n->exit_label != 0)
2471 expand_goto_internal (NULL_TREE, n->exit_label, NULL_RTX);
2478 /* Generate RTL to return from the current function, with no value.
2479 (That is, we do not do anything about returning any value.) */
2482 expand_null_return ()
2484 struct nesting *block = block_stack;
2487 /* Does any pending block have cleanups? */
2489 while (block && block->data.block.cleanups == 0)
2490 block = block->next;
2492 /* If yes, use a goto to return, since that runs cleanups. */
2494 expand_null_return_1 (last_insn, block != 0);
2497 /* Generate RTL to return from the current function, with value VAL. */
2500 expand_value_return (val)
2503 struct nesting *block = block_stack;
2504 rtx last_insn = get_last_insn ();
2505 rtx return_reg = DECL_RTL (DECL_RESULT (current_function_decl));
2507 /* Copy the value to the return location
2508 unless it's already there. */
2510 if (return_reg != val)
2512 #ifdef PROMOTE_FUNCTION_RETURN
2513 tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
2514 int unsignedp = TREE_UNSIGNED (type);
2515 enum machine_mode mode
2516 = promote_mode (type, DECL_MODE (DECL_RESULT (current_function_decl)),
2519 if (GET_MODE (val) != VOIDmode && GET_MODE (val) != mode)
2520 convert_move (return_reg, val, unsignedp);
2523 emit_move_insn (return_reg, val);
2525 if (GET_CODE (return_reg) == REG
2526 && REGNO (return_reg) < FIRST_PSEUDO_REGISTER)
2527 emit_insn (gen_rtx_USE (VOIDmode, return_reg));
2528 /* Handle calls that return values in multiple non-contiguous locations.
2529 The Irix 6 ABI has examples of this. */
2530 else if (GET_CODE (return_reg) == PARALLEL)
2534 for (i = 0; i < XVECLEN (return_reg, 0); i++)
2536 rtx x = XEXP (XVECEXP (return_reg, 0, i), 0);
2538 if (GET_CODE (x) == REG
2539 && REGNO (x) < FIRST_PSEUDO_REGISTER)
2540 emit_insn (gen_rtx_USE (VOIDmode, x));
2544 /* Does any pending block have cleanups? */
2546 while (block && block->data.block.cleanups == 0)
2547 block = block->next;
2549 /* If yes, use a goto to return, since that runs cleanups.
2550 Use LAST_INSN to put cleanups *before* the move insn emitted above. */
2552 expand_null_return_1 (last_insn, block != 0);
2555 /* Output a return with no value. If LAST_INSN is nonzero,
2556 pretend that the return takes place after LAST_INSN.
2557 If USE_GOTO is nonzero then don't use a return instruction;
2558 go to the return label instead. This causes any cleanups
2559 of pending blocks to be executed normally. */
2562 expand_null_return_1 (last_insn, use_goto)
2566 rtx end_label = cleanup_label ? cleanup_label : return_label;
2568 clear_pending_stack_adjust ();
2569 do_pending_stack_adjust ();
2572 /* PCC-struct return always uses an epilogue. */
2573 if (current_function_returns_pcc_struct || use_goto)
2576 end_label = return_label = gen_label_rtx ();
2577 expand_goto_internal (NULL_TREE, end_label, last_insn);
2581 /* Otherwise output a simple return-insn if one is available,
2582 unless it won't do the job. */
2584 if (HAVE_return && use_goto == 0 && cleanup_label == 0)
2586 emit_jump_insn (gen_return ());
2592 /* Otherwise jump to the epilogue. */
2593 expand_goto_internal (NULL_TREE, end_label, last_insn);
2596 /* Generate RTL to evaluate the expression RETVAL and return it
2597 from the current function. */
2600 expand_return (retval)
2603 /* If there are any cleanups to be performed, then they will
2604 be inserted following LAST_INSN. It is desirable
2605 that the last_insn, for such purposes, should be the
2606 last insn before computing the return value. Otherwise, cleanups
2607 which call functions can clobber the return value. */
2608 /* ??? rms: I think that is erroneous, because in C++ it would
2609 run destructors on variables that might be used in the subsequent
2610 computation of the return value. */
2612 register rtx val = 0;
2617 /* If function wants no value, give it none. */
2618 if (TREE_CODE (TREE_TYPE (TREE_TYPE (current_function_decl))) == VOID_TYPE)
2620 expand_expr (retval, NULL_RTX, VOIDmode, 0);
2622 expand_null_return ();
2626 /* Are any cleanups needed? E.g. C++ destructors to be run? */
2627 /* This is not sufficient. We also need to watch for cleanups of the
2628 expression we are about to expand. Unfortunately, we cannot know
2629 if it has cleanups until we expand it, and we want to change how we
2630 expand it depending upon if we need cleanups. We can't win. */
2632 cleanups = any_pending_cleanups (1);
2637 if (TREE_CODE (retval) == RESULT_DECL)
2638 retval_rhs = retval;
2639 else if ((TREE_CODE (retval) == MODIFY_EXPR || TREE_CODE (retval) == INIT_EXPR)
2640 && TREE_CODE (TREE_OPERAND (retval, 0)) == RESULT_DECL)
2641 retval_rhs = TREE_OPERAND (retval, 1);
2642 else if (TREE_TYPE (retval) == void_type_node)
2643 /* Recognize tail-recursive call to void function. */
2644 retval_rhs = retval;
2646 retval_rhs = NULL_TREE;
2648 /* Only use `last_insn' if there are cleanups which must be run. */
2649 if (cleanups || cleanup_label != 0)
2650 last_insn = get_last_insn ();
2652 /* Distribute return down conditional expr if either of the sides
2653 may involve tail recursion (see test below). This enhances the number
2654 of tail recursions we see. Don't do this always since it can produce
2655 sub-optimal code in some cases and we distribute assignments into
2656 conditional expressions when it would help. */
2658 if (optimize && retval_rhs != 0
2659 && frame_offset == 0
2660 && TREE_CODE (retval_rhs) == COND_EXPR
2661 && (TREE_CODE (TREE_OPERAND (retval_rhs, 1)) == CALL_EXPR
2662 || TREE_CODE (TREE_OPERAND (retval_rhs, 2)) == CALL_EXPR))
2664 rtx label = gen_label_rtx ();
2667 do_jump (TREE_OPERAND (retval_rhs, 0), label, NULL_RTX);
2668 start_cleanup_deferral ();
2669 expr = build (MODIFY_EXPR, TREE_TYPE (TREE_TYPE (current_function_decl)),
2670 DECL_RESULT (current_function_decl),
2671 TREE_OPERAND (retval_rhs, 1));
2672 TREE_SIDE_EFFECTS (expr) = 1;
2673 expand_return (expr);
2676 expr = build (MODIFY_EXPR, TREE_TYPE (TREE_TYPE (current_function_decl)),
2677 DECL_RESULT (current_function_decl),
2678 TREE_OPERAND (retval_rhs, 2));
2679 TREE_SIDE_EFFECTS (expr) = 1;
2680 expand_return (expr);
2681 end_cleanup_deferral ();
2685 /* Attempt to optimize the call if it is tail recursive. */
2686 if (optimize_tail_recursion (retval_rhs, last_insn))
2690 /* This optimization is safe if there are local cleanups
2691 because expand_null_return takes care of them.
2692 ??? I think it should also be safe when there is a cleanup label,
2693 because expand_null_return takes care of them, too.
2694 Any reason why not? */
2695 if (HAVE_return && cleanup_label == 0
2696 && ! current_function_returns_pcc_struct
2697 && BRANCH_COST <= 1)
2699 /* If this is return x == y; then generate
2700 if (x == y) return 1; else return 0;
2701 if we can do it with explicit return insns and branches are cheap,
2702 but not if we have the corresponding scc insn. */
2705 switch (TREE_CODE (retval_rhs))
2731 case TRUTH_ANDIF_EXPR:
2732 case TRUTH_ORIF_EXPR:
2733 case TRUTH_AND_EXPR:
2735 case TRUTH_NOT_EXPR:
2736 case TRUTH_XOR_EXPR:
2739 op0 = gen_label_rtx ();
2740 jumpifnot (retval_rhs, op0);
2741 expand_value_return (const1_rtx);
2743 expand_value_return (const0_rtx);
2752 #endif /* HAVE_return */
2754 /* If the result is an aggregate that is being returned in one (or more)
2755 registers, load the registers here. The compiler currently can't handle
2756 copying a BLKmode value into registers. We could put this code in a
2757 more general area (for use by everyone instead of just function
2758 call/return), but until this feature is generally usable it is kept here
2759 (and in expand_call). The value must go into a pseudo in case there
2760 are cleanups that will clobber the real return register. */
2763 && TYPE_MODE (TREE_TYPE (retval_rhs)) == BLKmode
2764 && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG)
2766 int i, bitpos, xbitpos;
2767 int big_endian_correction = 0;
2768 int bytes = int_size_in_bytes (TREE_TYPE (retval_rhs));
2769 int n_regs = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
2770 int bitsize = MIN (TYPE_ALIGN (TREE_TYPE (retval_rhs)),
2771 (unsigned int)BITS_PER_WORD);
2772 rtx *result_pseudos = (rtx *) alloca (sizeof (rtx) * n_regs);
2773 rtx result_reg, src = NULL_RTX, dst = NULL_RTX;
2774 rtx result_val = expand_expr (retval_rhs, NULL_RTX, VOIDmode, 0);
2775 enum machine_mode tmpmode, result_reg_mode;
2777 /* Structures whose size is not a multiple of a word are aligned
2778 to the least significant byte (to the right). On a BYTES_BIG_ENDIAN
2779 machine, this means we must skip the empty high order bytes when
2780 calculating the bit offset. */
2781 if (BYTES_BIG_ENDIAN && bytes % UNITS_PER_WORD)
2782 big_endian_correction = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD)
2785 /* Copy the structure BITSIZE bits at a time. */
2786 for (bitpos = 0, xbitpos = big_endian_correction;
2787 bitpos < bytes * BITS_PER_UNIT;
2788 bitpos += bitsize, xbitpos += bitsize)
2790 /* We need a new destination pseudo each time xbitpos is
2791 on a word boundary and when xbitpos == big_endian_correction
2792 (the first time through). */
2793 if (xbitpos % BITS_PER_WORD == 0
2794 || xbitpos == big_endian_correction)
2796 /* Generate an appropriate register. */
2797 dst = gen_reg_rtx (word_mode);
2798 result_pseudos[xbitpos / BITS_PER_WORD] = dst;
2800 /* Clobber the destination before we move anything into it. */
2801 emit_insn (gen_rtx_CLOBBER (VOIDmode, dst));
2804 /* We need a new source operand each time bitpos is on a word
2806 if (bitpos % BITS_PER_WORD == 0)
2807 src = operand_subword_force (result_val,
2808 bitpos / BITS_PER_WORD,
2811 /* Use bitpos for the source extraction (left justified) and
2812 xbitpos for the destination store (right justified). */
2813 store_bit_field (dst, bitsize, xbitpos % BITS_PER_WORD, word_mode,
2814 extract_bit_field (src, bitsize,
2815 bitpos % BITS_PER_WORD, 1,
2816 NULL_RTX, word_mode,
2818 bitsize / BITS_PER_UNIT,
2820 bitsize / BITS_PER_UNIT, BITS_PER_WORD);
2823 /* Find the smallest integer mode large enough to hold the
2824 entire structure and use that mode instead of BLKmode
2825 on the USE insn for the return register. */
2826 bytes = int_size_in_bytes (TREE_TYPE (retval_rhs));
2827 for (tmpmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2828 tmpmode != VOIDmode;
2829 tmpmode = GET_MODE_WIDER_MODE (tmpmode))
2831 /* Have we found a large enough mode? */
2832 if (GET_MODE_SIZE (tmpmode) >= bytes)
2836 /* No suitable mode found. */
2837 if (tmpmode == VOIDmode)
2840 PUT_MODE (DECL_RTL (DECL_RESULT (current_function_decl)), tmpmode);
2842 if (GET_MODE_SIZE (tmpmode) < GET_MODE_SIZE (word_mode))
2843 result_reg_mode = word_mode;
2845 result_reg_mode = tmpmode;
2846 result_reg = gen_reg_rtx (result_reg_mode);
2849 for (i = 0; i < n_regs; i++)
2850 emit_move_insn (operand_subword (result_reg, i, 0, result_reg_mode),
2853 if (tmpmode != result_reg_mode)
2854 result_reg = gen_lowpart (tmpmode, result_reg);
2856 expand_value_return (result_reg);
2860 && TREE_TYPE (retval_rhs) != void_type_node
2861 && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG)
2863 /* Calculate the return value into a pseudo reg. */
2864 val = gen_reg_rtx (DECL_MODE (DECL_RESULT (current_function_decl)));
2865 val = expand_expr (retval_rhs, val, GET_MODE (val), 0);
2866 val = force_not_mem (val);
2868 /* Return the calculated value, doing cleanups first. */
2869 expand_value_return (val);
2873 /* No cleanups or no hard reg used;
2874 calculate value into hard return reg. */
2875 expand_expr (retval, const0_rtx, VOIDmode, 0);
2877 expand_value_return (DECL_RTL (DECL_RESULT (current_function_decl)));
2881 /* Return 1 if the end of the generated RTX is not a barrier.
2882 This means code already compiled can drop through. */
2885 drop_through_at_end_p ()
2887 rtx insn = get_last_insn ();
2888 while (insn && GET_CODE (insn) == NOTE)
2889 insn = PREV_INSN (insn);
2890 return insn && GET_CODE (insn) != BARRIER;
2893 /* Test CALL_EXPR to determine if it is a potential tail recursion call
2894 and emit code to optimize the tail recursion. LAST_INSN indicates where
2895 to place the jump to the tail recursion label. Return TRUE if the
2896 call was optimized into a goto.
2898 This is only used by expand_return, but expand_call is expected to
2902 optimize_tail_recursion (call_expr, last_insn)
2906 /* For tail-recursive call to current function,
2907 just jump back to the beginning.
2908 It's unsafe if any auto variable in this function
2909 has its address taken; for simplicity,
2910 require stack frame to be empty. */
2911 if (optimize && call_expr != 0
2912 && frame_offset == 0
2913 && TREE_CODE (call_expr) == CALL_EXPR
2914 && TREE_CODE (TREE_OPERAND (call_expr, 0)) == ADDR_EXPR
2915 && TREE_OPERAND (TREE_OPERAND (call_expr, 0), 0) == current_function_decl
2916 /* Finish checking validity, and if valid emit code
2917 to set the argument variables for the new call. */
2918 && tail_recursion_args (TREE_OPERAND (call_expr, 1),
2919 DECL_ARGUMENTS (current_function_decl)))
2921 if (tail_recursion_label == 0)
2923 tail_recursion_label = gen_label_rtx ();
2924 emit_label_after (tail_recursion_label,
2925 tail_recursion_reentry);
2928 expand_goto_internal (NULL_TREE, tail_recursion_label, last_insn);
2936 /* Emit code to alter this function's formal parms for a tail-recursive call.
2937 ACTUALS is a list of actual parameter expressions (chain of TREE_LISTs).
2938 FORMALS is the chain of decls of formals.
2939 Return 1 if this can be done;
2940 otherwise return 0 and do not emit any code. */
2943 tail_recursion_args (actuals, formals)
2944 tree actuals, formals;
2946 register tree a = actuals, f = formals;
2948 register rtx *argvec;
2950 /* Check that number and types of actuals are compatible
2951 with the formals. This is not always true in valid C code.
2952 Also check that no formal needs to be addressable
2953 and that all formals are scalars. */
2955 /* Also count the args. */
2957 for (a = actuals, f = formals, i = 0; a && f; a = TREE_CHAIN (a), f = TREE_CHAIN (f), i++)
2959 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (a)))
2960 != TYPE_MAIN_VARIANT (TREE_TYPE (f)))
2962 if (GET_CODE (DECL_RTL (f)) != REG || DECL_MODE (f) == BLKmode)
2965 if (a != 0 || f != 0)
2968 /* Compute all the actuals. */
2970 argvec = (rtx *) alloca (i * sizeof (rtx));
2972 for (a = actuals, i = 0; a; a = TREE_CHAIN (a), i++)
2973 argvec[i] = expand_expr (TREE_VALUE (a), NULL_RTX, VOIDmode, 0);
2975 /* Find which actual values refer to current values of previous formals.
2976 Copy each of them now, before any formal is changed. */
2978 for (a = actuals, i = 0; a; a = TREE_CHAIN (a), i++)
2982 for (f = formals, j = 0; j < i; f = TREE_CHAIN (f), j++)
2983 if (reg_mentioned_p (DECL_RTL (f), argvec[i]))
2984 { copy = 1; break; }
2986 argvec[i] = copy_to_reg (argvec[i]);
2989 /* Store the values of the actuals into the formals. */
2991 for (f = formals, a = actuals, i = 0; f;
2992 f = TREE_CHAIN (f), a = TREE_CHAIN (a), i++)
2994 if (GET_MODE (DECL_RTL (f)) == GET_MODE (argvec[i]))
2995 emit_move_insn (DECL_RTL (f), argvec[i]);
2997 convert_move (DECL_RTL (f), argvec[i],
2998 TREE_UNSIGNED (TREE_TYPE (TREE_VALUE (a))));
3005 /* Generate the RTL code for entering a binding contour.
3006 The variables are declared one by one, by calls to `expand_decl'.
3008 EXIT_FLAG is nonzero if this construct should be visible to
3009 `exit_something'. */
3012 expand_start_bindings (exit_flag)
3015 struct nesting *thisblock = ALLOC_NESTING ();
3016 rtx note = emit_note (NULL_PTR, NOTE_INSN_BLOCK_BEG);
3018 /* Make an entry on block_stack for the block we are entering. */
3020 thisblock->next = block_stack;
3021 thisblock->all = nesting_stack;
3022 thisblock->depth = ++nesting_depth;
3023 thisblock->data.block.stack_level = 0;
3024 thisblock->data.block.cleanups = 0;
3025 thisblock->data.block.n_function_calls = 0;
3026 thisblock->data.block.exception_region = 0;
3027 thisblock->data.block.block_target_temp_slot_level = target_temp_slot_level;
3029 thisblock->data.block.conditional_code = 0;
3030 thisblock->data.block.last_unconditional_cleanup = note;
3031 thisblock->data.block.cleanup_ptr = &thisblock->data.block.cleanups;
3034 && !(block_stack->data.block.cleanups == NULL_TREE
3035 && block_stack->data.block.outer_cleanups == NULL_TREE))
3036 thisblock->data.block.outer_cleanups
3037 = tree_cons (NULL_TREE, block_stack->data.block.cleanups,
3038 block_stack->data.block.outer_cleanups);
3040 thisblock->data.block.outer_cleanups = 0;
3041 thisblock->data.block.label_chain = 0;
3042 thisblock->data.block.innermost_stack_block = stack_block_stack;
3043 thisblock->data.block.first_insn = note;
3044 thisblock->data.block.block_start_count = ++current_block_start_count;
3045 thisblock->exit_label = exit_flag ? gen_label_rtx () : 0;
3046 block_stack = thisblock;
3047 nesting_stack = thisblock;
3049 /* Make a new level for allocating stack slots. */
3053 /* Specify the scope of temporaries created by TARGET_EXPRs. Similar
3054 to CLEANUP_POINT_EXPR, but handles cases when a series of calls to
3055 expand_expr are made. After we end the region, we know that all
3056 space for all temporaries that were created by TARGET_EXPRs will be
3057 destroyed and their space freed for reuse. */
3060 expand_start_target_temps ()
3062 /* This is so that even if the result is preserved, the space
3063 allocated will be freed, as we know that it is no longer in use. */
3066 /* Start a new binding layer that will keep track of all cleanup
3067 actions to be performed. */
3068 expand_start_bindings (0);
3070 target_temp_slot_level = temp_slot_level;
3074 expand_end_target_temps ()
3076 expand_end_bindings (NULL_TREE, 0, 0);
3078 /* This is so that even if the result is preserved, the space
3079 allocated will be freed, as we know that it is no longer in use. */
3083 /* Mark top block of block_stack as an implicit binding for an
3084 exception region. This is used to prevent infinite recursion when
3085 ending a binding with expand_end_bindings. It is only ever called
3086 by expand_eh_region_start, as that it the only way to create a
3087 block stack for a exception region. */
3090 mark_block_as_eh_region ()
3092 block_stack->data.block.exception_region = 1;
3093 if (block_stack->next
3094 && block_stack->next->data.block.conditional_code)
3096 block_stack->data.block.conditional_code
3097 = block_stack->next->data.block.conditional_code;
3098 block_stack->data.block.last_unconditional_cleanup
3099 = block_stack->next->data.block.last_unconditional_cleanup;
3100 block_stack->data.block.cleanup_ptr
3101 = block_stack->next->data.block.cleanup_ptr;
3105 /* True if we are currently emitting insns in an area of output code
3106 that is controlled by a conditional expression. This is used by
3107 the cleanup handling code to generate conditional cleanup actions. */
3110 conditional_context ()
3112 return block_stack && block_stack->data.block.conditional_code;
3115 /* Mark top block of block_stack as not for an implicit binding for an
3116 exception region. This is only ever done by expand_eh_region_end
3117 to let expand_end_bindings know that it is being called explicitly
3118 to end the binding layer for just the binding layer associated with
3119 the exception region, otherwise expand_end_bindings would try and
3120 end all implicit binding layers for exceptions regions, and then
3121 one normal binding layer. */
3124 mark_block_as_not_eh_region ()
3126 block_stack->data.block.exception_region = 0;
3129 /* True if the top block of block_stack was marked as for an exception
3130 region by mark_block_as_eh_region. */
3135 return (current_function && block_stack
3136 && block_stack->data.block.exception_region);
3139 /* Given a pointer to a BLOCK node, save a pointer to the most recently
3140 generated NOTE_INSN_BLOCK_END in the BLOCK_END_NOTE field of the given
3144 remember_end_note (block)
3145 register tree block;
3147 BLOCK_END_NOTE (block) = last_block_end_note;
3148 last_block_end_note = NULL_RTX;
3151 /* Emit a handler label for a nonlocal goto handler.
3152 Also emit code to store the handler label in SLOT before BEFORE_INSN. */
3155 expand_nl_handler_label (slot, before_insn)
3156 rtx slot, before_insn;
3159 rtx handler_label = gen_label_rtx ();
3161 /* Don't let jump_optimize delete the handler. */
3162 LABEL_PRESERVE_P (handler_label) = 1;
3165 emit_move_insn (slot, gen_rtx_LABEL_REF (Pmode, handler_label));
3166 insns = get_insns ();
3168 emit_insns_before (insns, before_insn);
3170 emit_label (handler_label);
3172 return handler_label;
3175 /* Emit code to restore vital registers at the beginning of a nonlocal goto
3178 expand_nl_goto_receiver ()
3180 #ifdef HAVE_nonlocal_goto
3181 if (! HAVE_nonlocal_goto)
3183 /* First adjust our frame pointer to its actual value. It was
3184 previously set to the start of the virtual area corresponding to
3185 the stacked variables when we branched here and now needs to be
3186 adjusted to the actual hardware fp value.
3188 Assignments are to virtual registers are converted by
3189 instantiate_virtual_regs into the corresponding assignment
3190 to the underlying register (fp in this case) that makes
3191 the original assignment true.
3192 So the following insn will actually be
3193 decrementing fp by STARTING_FRAME_OFFSET. */
3194 emit_move_insn (virtual_stack_vars_rtx, hard_frame_pointer_rtx);
3196 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3197 if (fixed_regs[ARG_POINTER_REGNUM])
3199 #ifdef ELIMINABLE_REGS
3200 /* If the argument pointer can be eliminated in favor of the
3201 frame pointer, we don't need to restore it. We assume here
3202 that if such an elimination is present, it can always be used.
3203 This is the case on all known machines; if we don't make this
3204 assumption, we do unnecessary saving on many machines. */
3205 static struct elims {int from, to;} elim_regs[] = ELIMINABLE_REGS;
3208 for (i = 0; i < sizeof elim_regs / sizeof elim_regs[0]; i++)
3209 if (elim_regs[i].from == ARG_POINTER_REGNUM
3210 && elim_regs[i].to == HARD_FRAME_POINTER_REGNUM)
3213 if (i == sizeof elim_regs / sizeof elim_regs [0])
3216 /* Now restore our arg pointer from the address at which it
3217 was saved in our stack frame.
3218 If there hasn't be space allocated for it yet, make
3220 if (arg_pointer_save_area == 0)
3221 arg_pointer_save_area
3222 = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
3223 emit_move_insn (virtual_incoming_args_rtx,
3224 /* We need a pseudo here, or else
3225 instantiate_virtual_regs_1 complains. */
3226 copy_to_reg (arg_pointer_save_area));
3231 #ifdef HAVE_nonlocal_goto_receiver
3232 if (HAVE_nonlocal_goto_receiver)
3233 emit_insn (gen_nonlocal_goto_receiver ());
3237 /* Make handlers for nonlocal gotos taking place in the function calls in
3241 expand_nl_goto_receivers (thisblock)
3242 struct nesting *thisblock;
3245 rtx afterward = gen_label_rtx ();
3250 /* Record the handler address in the stack slot for that purpose,
3251 during this block, saving and restoring the outer value. */
3252 if (thisblock->next != 0)
3253 for (slot = nonlocal_goto_handler_slots; slot; slot = XEXP (slot, 1))
3255 rtx save_receiver = gen_reg_rtx (Pmode);
3256 emit_move_insn (XEXP (slot, 0), save_receiver);
3259 emit_move_insn (save_receiver, XEXP (slot, 0));
3260 insns = get_insns ();
3262 emit_insns_before (insns, thisblock->data.block.first_insn);
3265 /* Jump around the handlers; they run only when specially invoked. */
3266 emit_jump (afterward);
3268 /* Make a separate handler for each label. */
3269 link = nonlocal_labels;
3270 slot = nonlocal_goto_handler_slots;
3271 label_list = NULL_RTX;
3272 for (; link; link = TREE_CHAIN (link), slot = XEXP (slot, 1))
3273 /* Skip any labels we shouldn't be able to jump to from here,
3274 we generate one special handler for all of them below which just calls
3276 if (! DECL_TOO_LATE (TREE_VALUE (link)))
3279 lab = expand_nl_handler_label (XEXP (slot, 0),
3280 thisblock->data.block.first_insn);
3281 label_list = gen_rtx_EXPR_LIST (VOIDmode, lab, label_list);
3283 expand_nl_goto_receiver ();
3285 /* Jump to the "real" nonlocal label. */
3286 expand_goto (TREE_VALUE (link));
3289 /* A second pass over all nonlocal labels; this time we handle those
3290 we should not be able to jump to at this point. */
3291 link = nonlocal_labels;
3292 slot = nonlocal_goto_handler_slots;
3294 for (; link; link = TREE_CHAIN (link), slot = XEXP (slot, 1))
3295 if (DECL_TOO_LATE (TREE_VALUE (link)))
3298 lab = expand_nl_handler_label (XEXP (slot, 0),
3299 thisblock->data.block.first_insn);
3300 label_list = gen_rtx_EXPR_LIST (VOIDmode, lab, label_list);
3306 expand_nl_goto_receiver ();
3307 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "abort"), 0,
3312 nonlocal_goto_handler_labels = label_list;
3313 emit_label (afterward);
3316 /* Generate RTL code to terminate a binding contour.
3318 VARS is the chain of VAR_DECL nodes for the variables bound in this
3319 contour. There may actually be other nodes in this chain, but any
3320 nodes other than VAR_DECLS are ignored.
3322 MARK_ENDS is nonzero if we should put a note at the beginning
3323 and end of this binding contour.
3325 DONT_JUMP_IN is nonzero if it is not valid to jump into this contour.
3326 (That is true automatically if the contour has a saved stack level.) */
3329 expand_end_bindings (vars, mark_ends, dont_jump_in)
3334 register struct nesting *thisblock;
3337 while (block_stack->data.block.exception_region)
3339 /* Because we don't need or want a new temporary level and
3340 because we didn't create one in expand_eh_region_start,
3341 create a fake one now to avoid removing one in
3342 expand_end_bindings. */
3345 block_stack->data.block.exception_region = 0;
3347 expand_end_bindings (NULL_TREE, 0, 0);
3350 /* Since expand_eh_region_start does an expand_start_bindings, we
3351 have to first end all the bindings that were created by
3352 expand_eh_region_start. */
3354 thisblock = block_stack;
3357 for (decl = vars; decl; decl = TREE_CHAIN (decl))
3358 if (TREE_CODE (decl) == VAR_DECL
3359 && ! TREE_USED (decl)
3360 && ! DECL_IN_SYSTEM_HEADER (decl)
3361 && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
3362 warning_with_decl (decl, "unused variable `%s'");
3364 if (thisblock->exit_label)
3366 do_pending_stack_adjust ();
3367 emit_label (thisblock->exit_label);
3370 /* If necessary, make handlers for nonlocal gotos taking
3371 place in the function calls in this block. */
3372 if (function_call_count != thisblock->data.block.n_function_calls
3374 /* Make handler for outermost block
3375 if there were any nonlocal gotos to this function. */
3376 && (thisblock->next == 0 ? current_function_has_nonlocal_label
3377 /* Make handler for inner block if it has something
3378 special to do when you jump out of it. */
3379 : (thisblock->data.block.cleanups != 0
3380 || thisblock->data.block.stack_level != 0)))
3381 expand_nl_goto_receivers (thisblock);
3383 /* Don't allow jumping into a block that has a stack level.
3384 Cleanups are allowed, though. */
3386 || thisblock->data.block.stack_level != 0)
3388 struct label_chain *chain;
3390 /* Any labels in this block are no longer valid to go to.
3391 Mark them to cause an error message. */
3392 for (chain = thisblock->data.block.label_chain; chain; chain = chain->next)
3394 DECL_TOO_LATE (chain->label) = 1;
3395 /* If any goto without a fixup came to this label,
3396 that must be an error, because gotos without fixups
3397 come from outside all saved stack-levels. */
3398 if (TREE_ADDRESSABLE (chain->label))
3399 error_with_decl (chain->label,
3400 "label `%s' used before containing binding contour");
3404 /* Restore stack level in effect before the block
3405 (only if variable-size objects allocated). */
3406 /* Perform any cleanups associated with the block. */
3408 if (thisblock->data.block.stack_level != 0
3409 || thisblock->data.block.cleanups != 0)
3411 /* Only clean up here if this point can actually be reached. */
3412 int reachable = GET_CODE (get_last_insn ()) != BARRIER;
3414 /* Don't let cleanups affect ({...}) constructs. */
3415 int old_expr_stmts_for_value = expr_stmts_for_value;
3416 rtx old_last_expr_value = last_expr_value;
3417 tree old_last_expr_type = last_expr_type;
3418 expr_stmts_for_value = 0;
3420 /* Do the cleanups. */
3421 expand_cleanups (thisblock->data.block.cleanups, NULL_TREE, 0, reachable);
3423 do_pending_stack_adjust ();
3425 expr_stmts_for_value = old_expr_stmts_for_value;
3426 last_expr_value = old_last_expr_value;
3427 last_expr_type = old_last_expr_type;
3429 /* Restore the stack level. */
3431 if (reachable && thisblock->data.block.stack_level != 0)
3433 emit_stack_restore (thisblock->next ? SAVE_BLOCK : SAVE_FUNCTION,
3434 thisblock->data.block.stack_level, NULL_RTX);
3435 if (nonlocal_goto_handler_slots != 0)
3436 emit_stack_save (SAVE_NONLOCAL, &nonlocal_goto_stack_level,
3440 /* Any gotos out of this block must also do these things.
3441 Also report any gotos with fixups that came to labels in this
3443 fixup_gotos (thisblock,
3444 thisblock->data.block.stack_level,
3445 thisblock->data.block.cleanups,
3446 thisblock->data.block.first_insn,
3450 /* Mark the beginning and end of the scope if requested.
3451 We do this now, after running cleanups on the variables
3452 just going out of scope, so they are in scope for their cleanups. */
3455 last_block_end_note = emit_note (NULL_PTR, NOTE_INSN_BLOCK_END);
3457 /* Get rid of the beginning-mark if we don't make an end-mark. */
3458 NOTE_LINE_NUMBER (thisblock->data.block.first_insn) = NOTE_INSN_DELETED;
3460 /* If doing stupid register allocation, make sure lives of all
3461 register variables declared here extend thru end of scope. */
3464 for (decl = vars; decl; decl = TREE_CHAIN (decl))
3465 if (TREE_CODE (decl) == VAR_DECL && DECL_RTL (decl))
3466 use_variable (DECL_RTL (decl));
3468 /* Restore the temporary level of TARGET_EXPRs. */
3469 target_temp_slot_level = thisblock->data.block.block_target_temp_slot_level;
3471 /* Restore block_stack level for containing block. */
3473 stack_block_stack = thisblock->data.block.innermost_stack_block;
3474 POPSTACK (block_stack);
3476 /* Pop the stack slot nesting and free any slots at this level. */
3480 /* Generate RTL for the automatic variable declaration DECL.
3481 (Other kinds of declarations are simply ignored if seen here.) */
3487 struct nesting *thisblock;
3490 type = TREE_TYPE (decl);
3492 /* Only automatic variables need any expansion done.
3493 Static and external variables, and external functions,
3494 will be handled by `assemble_variable' (called from finish_decl).
3495 TYPE_DECL and CONST_DECL require nothing.
3496 PARM_DECLs are handled in `assign_parms'. */
3498 if (TREE_CODE (decl) != VAR_DECL)
3500 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl))
3503 thisblock = block_stack;
3505 /* Create the RTL representation for the variable. */
3507 if (type == error_mark_node)
3508 DECL_RTL (decl) = gen_rtx_MEM (BLKmode, const0_rtx);
3509 else if (DECL_SIZE (decl) == 0)
3510 /* Variable with incomplete type. */
3512 if (DECL_INITIAL (decl) == 0)
3513 /* Error message was already done; now avoid a crash. */
3514 DECL_RTL (decl) = assign_stack_temp (DECL_MODE (decl), 0, 1);
3516 /* An initializer is going to decide the size of this array.
3517 Until we know the size, represent its address with a reg. */
3518 DECL_RTL (decl) = gen_rtx_MEM (BLKmode, gen_reg_rtx (Pmode));
3519 MEM_SET_IN_STRUCT_P (DECL_RTL (decl), AGGREGATE_TYPE_P (type));
3521 else if (DECL_MODE (decl) != BLKmode
3522 /* If -ffloat-store, don't put explicit float vars
3524 && !(flag_float_store
3525 && TREE_CODE (type) == REAL_TYPE)
3526 && ! TREE_THIS_VOLATILE (decl)
3527 && ! TREE_ADDRESSABLE (decl)
3528 && (DECL_REGISTER (decl) || ! obey_regdecls)
3529 /* if -fcheck-memory-usage, check all variables. */
3530 && ! current_function_check_memory_usage)
3532 /* Automatic variable that can go in a register. */
3533 int unsignedp = TREE_UNSIGNED (type);
3534 enum machine_mode reg_mode
3535 = promote_mode (type, DECL_MODE (decl), &unsignedp, 0);
3537 DECL_RTL (decl) = gen_reg_rtx (reg_mode);
3538 mark_user_reg (DECL_RTL (decl));
3540 if (POINTER_TYPE_P (type))
3541 mark_reg_pointer (DECL_RTL (decl),
3542 (TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl)))
3546 else if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
3547 && ! (flag_stack_check && ! STACK_CHECK_BUILTIN
3548 && (TREE_INT_CST_HIGH (DECL_SIZE (decl)) != 0
3549 || (TREE_INT_CST_LOW (DECL_SIZE (decl))
3550 > STACK_CHECK_MAX_VAR_SIZE * BITS_PER_UNIT))))
3552 /* Variable of fixed size that goes on the stack. */
3556 /* If we previously made RTL for this decl, it must be an array
3557 whose size was determined by the initializer.
3558 The old address was a register; set that register now
3559 to the proper address. */
3560 if (DECL_RTL (decl) != 0)
3562 if (GET_CODE (DECL_RTL (decl)) != MEM
3563 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != REG)
3565 oldaddr = XEXP (DECL_RTL (decl), 0);
3568 DECL_RTL (decl) = assign_temp (TREE_TYPE (decl), 1, 1, 1);
3569 MEM_SET_IN_STRUCT_P (DECL_RTL (decl),
3570 AGGREGATE_TYPE_P (TREE_TYPE (decl)));
3572 /* Set alignment we actually gave this decl. */
3573 DECL_ALIGN (decl) = (DECL_MODE (decl) == BLKmode ? BIGGEST_ALIGNMENT
3574 : GET_MODE_BITSIZE (DECL_MODE (decl)));
3578 addr = force_operand (XEXP (DECL_RTL (decl), 0), oldaddr);
3579 if (addr != oldaddr)
3580 emit_move_insn (oldaddr, addr);
3583 /* If this is a memory ref that contains aggregate components,
3584 mark it as such for cse and loop optimize. */
3585 MEM_SET_IN_STRUCT_P (DECL_RTL (decl),
3586 AGGREGATE_TYPE_P (TREE_TYPE (decl)));
3588 /* If this is in memory because of -ffloat-store,
3589 set the volatile bit, to prevent optimizations from
3590 undoing the effects. */
3591 if (flag_float_store && TREE_CODE (type) == REAL_TYPE)
3592 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
3595 MEM_ALIAS_SET (DECL_RTL (decl)) = get_alias_set (decl);
3598 /* Dynamic-size object: must push space on the stack. */
3602 /* Record the stack pointer on entry to block, if have
3603 not already done so. */
3604 if (thisblock->data.block.stack_level == 0)
3606 do_pending_stack_adjust ();
3607 emit_stack_save (thisblock->next ? SAVE_BLOCK : SAVE_FUNCTION,
3608 &thisblock->data.block.stack_level,
3609 thisblock->data.block.first_insn);
3610 stack_block_stack = thisblock;
3613 /* Compute the variable's size, in bytes. */
3614 size = expand_expr (size_binop (CEIL_DIV_EXPR,
3616 size_int (BITS_PER_UNIT)),
3617 NULL_RTX, VOIDmode, 0);
3620 /* Allocate space on the stack for the variable. Note that
3621 DECL_ALIGN says how the variable is to be aligned and we
3622 cannot use it to conclude anything about the alignment of
3624 address = allocate_dynamic_stack_space (size, NULL_RTX,
3625 TYPE_ALIGN (TREE_TYPE (decl)));
3627 /* Reference the variable indirect through that rtx. */
3628 DECL_RTL (decl) = gen_rtx_MEM (DECL_MODE (decl), address);
3630 /* If this is a memory ref that contains aggregate components,
3631 mark it as such for cse and loop optimize. */
3632 MEM_SET_IN_STRUCT_P (DECL_RTL (decl),
3633 AGGREGATE_TYPE_P (TREE_TYPE (decl)));
3635 /* Indicate the alignment we actually gave this variable. */
3636 #ifdef STACK_BOUNDARY
3637 DECL_ALIGN (decl) = STACK_BOUNDARY;
3639 DECL_ALIGN (decl) = BIGGEST_ALIGNMENT;
3643 if (TREE_THIS_VOLATILE (decl))
3644 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
3645 #if 0 /* A variable is not necessarily unchanging
3646 just because it is const. RTX_UNCHANGING_P
3647 means no change in the function,
3648 not merely no change in the variable's scope.
3649 It is correct to set RTX_UNCHANGING_P if the variable's scope
3650 is the whole function. There's no convenient way to test that. */
3651 if (TREE_READONLY (decl))
3652 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
3655 /* If doing stupid register allocation, make sure life of any
3656 register variable starts here, at the start of its scope. */
3659 use_variable (DECL_RTL (decl));
3664 /* Emit code to perform the initialization of a declaration DECL. */
3667 expand_decl_init (decl)
3670 int was_used = TREE_USED (decl);
3672 /* If this is a CONST_DECL, we don't have to generate any code, but
3673 if DECL_INITIAL is a constant, call expand_expr to force TREE_CST_RTL
3674 to be set while in the obstack containing the constant. If we don't
3675 do this, we can lose if we have functions nested three deep and the middle
3676 function makes a CONST_DECL whose DECL_INITIAL is a STRING_CST while
3677 the innermost function is the first to expand that STRING_CST. */
3678 if (TREE_CODE (decl) == CONST_DECL)
3680 if (DECL_INITIAL (decl) && TREE_CONSTANT (DECL_INITIAL (decl)))
3681 expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode,
3682 EXPAND_INITIALIZER);
3686 if (TREE_STATIC (decl))
3689 /* Compute and store the initial value now. */
3691 if (DECL_INITIAL (decl) == error_mark_node)
3693 enum tree_code code = TREE_CODE (TREE_TYPE (decl));
3695 if (code == INTEGER_TYPE || code == REAL_TYPE || code == ENUMERAL_TYPE
3696 || code == POINTER_TYPE || code == REFERENCE_TYPE)
3697 expand_assignment (decl, convert (TREE_TYPE (decl), integer_zero_node),
3701 else if (DECL_INITIAL (decl) && TREE_CODE (DECL_INITIAL (decl)) != TREE_LIST)
3703 emit_line_note (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
3704 expand_assignment (decl, DECL_INITIAL (decl), 0, 0);
3708 /* Don't let the initialization count as "using" the variable. */
3709 TREE_USED (decl) = was_used;
3711 /* Free any temporaries we made while initializing the decl. */
3712 preserve_temp_slots (NULL_RTX);
3716 /* CLEANUP is an expression to be executed at exit from this binding contour;
3717 for example, in C++, it might call the destructor for this variable.
3719 We wrap CLEANUP in an UNSAVE_EXPR node, so that we can expand the
3720 CLEANUP multiple times, and have the correct semantics. This
3721 happens in exception handling, for gotos, returns, breaks that
3722 leave the current scope.
3724 If CLEANUP is nonzero and DECL is zero, we record a cleanup
3725 that is not associated with any particular variable. */
3728 expand_decl_cleanup (decl, cleanup)
3731 struct nesting *thisblock;
3733 /* Error if we are not in any block. */
3734 if (current_function == 0 || block_stack == 0)
3737 thisblock = block_stack;
3739 /* Record the cleanup if there is one. */
3745 tree *cleanups = &thisblock->data.block.cleanups;
3746 int cond_context = conditional_context ();
3750 rtx flag = gen_reg_rtx (word_mode);
3755 emit_move_insn (flag, const0_rtx);
3756 set_flag_0 = get_insns ();
3759 thisblock->data.block.last_unconditional_cleanup
3760 = emit_insns_after (set_flag_0,
3761 thisblock->data.block.last_unconditional_cleanup);
3763 emit_move_insn (flag, const1_rtx);
3765 /* All cleanups must be on the function_obstack. */
3766 push_obstacks_nochange ();
3767 resume_temporary_allocation ();
3769 cond = build_decl (VAR_DECL, NULL_TREE, type_for_mode (word_mode, 1));
3770 DECL_RTL (cond) = flag;
3772 /* Conditionalize the cleanup. */
3773 cleanup = build (COND_EXPR, void_type_node,
3774 truthvalue_conversion (cond),
3775 cleanup, integer_zero_node);
3776 cleanup = fold (cleanup);
3780 cleanups = thisblock->data.block.cleanup_ptr;
3783 /* All cleanups must be on the function_obstack. */
3784 push_obstacks_nochange ();
3785 resume_temporary_allocation ();
3786 cleanup = unsave_expr (cleanup);
3789 t = *cleanups = temp_tree_cons (decl, cleanup, *cleanups);
3792 /* If this block has a cleanup, it belongs in stack_block_stack. */
3793 stack_block_stack = thisblock;
3800 /* If this was optimized so that there is no exception region for the
3801 cleanup, then mark the TREE_LIST node, so that we can later tell
3802 if we need to call expand_eh_region_end. */
3803 if (! using_eh_for_cleanups_p
3804 || expand_eh_region_start_tree (decl, cleanup))
3805 TREE_ADDRESSABLE (t) = 1;
3806 /* If that started a new EH region, we're in a new block. */
3807 thisblock = block_stack;
3814 thisblock->data.block.last_unconditional_cleanup
3815 = emit_insns_after (seq,
3816 thisblock->data.block.last_unconditional_cleanup);
3820 thisblock->data.block.last_unconditional_cleanup
3822 thisblock->data.block.cleanup_ptr = &thisblock->data.block.cleanups;
3828 /* Like expand_decl_cleanup, but suppress generating an exception handler
3829 to perform the cleanup. */
3832 expand_decl_cleanup_no_eh (decl, cleanup)
3835 int save_eh = using_eh_for_cleanups_p;
3838 using_eh_for_cleanups_p = 0;
3839 result = expand_decl_cleanup (decl, cleanup);
3840 using_eh_for_cleanups_p = save_eh;
3845 /* Arrange for the top element of the dynamic cleanup chain to be
3846 popped if we exit the current binding contour. DECL is the
3847 associated declaration, if any, otherwise NULL_TREE. If the
3848 current contour is left via an exception, then __sjthrow will pop
3849 the top element off the dynamic cleanup chain. The code that
3850 avoids doing the action we push into the cleanup chain in the
3851 exceptional case is contained in expand_cleanups.
3853 This routine is only used by expand_eh_region_start, and that is
3854 the only way in which an exception region should be started. This
3855 routine is only used when using the setjmp/longjmp codegen method
3856 for exception handling. */
3859 expand_dcc_cleanup (decl)
3862 struct nesting *thisblock;
3865 /* Error if we are not in any block. */
3866 if (current_function == 0 || block_stack == 0)
3868 thisblock = block_stack;
3870 /* Record the cleanup for the dynamic handler chain. */
3872 /* All cleanups must be on the function_obstack. */
3873 push_obstacks_nochange ();
3874 resume_temporary_allocation ();
3875 cleanup = make_node (POPDCC_EXPR);
3878 /* Add the cleanup in a manner similar to expand_decl_cleanup. */
3879 thisblock->data.block.cleanups
3880 = temp_tree_cons (decl, cleanup, thisblock->data.block.cleanups);
3882 /* If this block has a cleanup, it belongs in stack_block_stack. */
3883 stack_block_stack = thisblock;
3887 /* Arrange for the top element of the dynamic handler chain to be
3888 popped if we exit the current binding contour. DECL is the
3889 associated declaration, if any, otherwise NULL_TREE. If the current
3890 contour is left via an exception, then __sjthrow will pop the top
3891 element off the dynamic handler chain. The code that avoids doing
3892 the action we push into the handler chain in the exceptional case
3893 is contained in expand_cleanups.
3895 This routine is only used by expand_eh_region_start, and that is
3896 the only way in which an exception region should be started. This
3897 routine is only used when using the setjmp/longjmp codegen method
3898 for exception handling. */
3901 expand_dhc_cleanup (decl)
3904 struct nesting *thisblock;
3907 /* Error if we are not in any block. */
3908 if (current_function == 0 || block_stack == 0)
3910 thisblock = block_stack;
3912 /* Record the cleanup for the dynamic handler chain. */
3914 /* All cleanups must be on the function_obstack. */
3915 push_obstacks_nochange ();
3916 resume_temporary_allocation ();
3917 cleanup = make_node (POPDHC_EXPR);
3920 /* Add the cleanup in a manner similar to expand_decl_cleanup. */
3921 thisblock->data.block.cleanups
3922 = temp_tree_cons (decl, cleanup, thisblock->data.block.cleanups);
3924 /* If this block has a cleanup, it belongs in stack_block_stack. */
3925 stack_block_stack = thisblock;
3929 /* DECL is an anonymous union. CLEANUP is a cleanup for DECL.
3930 DECL_ELTS is the list of elements that belong to DECL's type.
3931 In each, the TREE_VALUE is a VAR_DECL, and the TREE_PURPOSE a cleanup. */
3934 expand_anon_union_decl (decl, cleanup, decl_elts)
3935 tree decl, cleanup, decl_elts;
3937 struct nesting *thisblock = current_function == 0 ? 0 : block_stack;
3941 expand_decl_cleanup (decl, cleanup);
3942 x = DECL_RTL (decl);
3946 tree decl_elt = TREE_VALUE (decl_elts);
3947 tree cleanup_elt = TREE_PURPOSE (decl_elts);
3948 enum machine_mode mode = TYPE_MODE (TREE_TYPE (decl_elt));
3950 /* Propagate the union's alignment to the elements. */
3951 DECL_ALIGN (decl_elt) = DECL_ALIGN (decl);
3953 /* If the element has BLKmode and the union doesn't, the union is
3954 aligned such that the element doesn't need to have BLKmode, so
3955 change the element's mode to the appropriate one for its size. */
3956 if (mode == BLKmode && DECL_MODE (decl) != BLKmode)
3957 DECL_MODE (decl_elt) = mode
3958 = mode_for_size (TREE_INT_CST_LOW (DECL_SIZE (decl_elt)),
3961 /* (SUBREG (MEM ...)) at RTL generation time is invalid, so we
3962 instead create a new MEM rtx with the proper mode. */
3963 if (GET_CODE (x) == MEM)
3965 if (mode == GET_MODE (x))
3966 DECL_RTL (decl_elt) = x;
3969 DECL_RTL (decl_elt) = gen_rtx_MEM (mode, copy_rtx (XEXP (x, 0)));
3970 MEM_COPY_ATTRIBUTES (DECL_RTL (decl_elt), x);
3971 RTX_UNCHANGING_P (DECL_RTL (decl_elt)) = RTX_UNCHANGING_P (x);
3974 else if (GET_CODE (x) == REG)
3976 if (mode == GET_MODE (x))
3977 DECL_RTL (decl_elt) = x;
3979 DECL_RTL (decl_elt) = gen_rtx_SUBREG (mode, x, 0);
3984 /* Record the cleanup if there is one. */
3987 thisblock->data.block.cleanups
3988 = temp_tree_cons (decl_elt, cleanup_elt,
3989 thisblock->data.block.cleanups);
3991 decl_elts = TREE_CHAIN (decl_elts);
3995 /* Expand a list of cleanups LIST.
3996 Elements may be expressions or may be nested lists.
3998 If DONT_DO is nonnull, then any list-element
3999 whose TREE_PURPOSE matches DONT_DO is omitted.
4000 This is sometimes used to avoid a cleanup associated with
4001 a value that is being returned out of the scope.
4003 If IN_FIXUP is non-zero, we are generating this cleanup for a fixup
4004 goto and handle protection regions specially in that case.
4006 If REACHABLE, we emit code, otherwise just inform the exception handling
4007 code about this finalization. */
4010 expand_cleanups (list, dont_do, in_fixup, reachable)
4017 for (tail = list; tail; tail = TREE_CHAIN (tail))
4018 if (dont_do == 0 || TREE_PURPOSE (tail) != dont_do)
4020 if (TREE_CODE (TREE_VALUE (tail)) == TREE_LIST)
4021 expand_cleanups (TREE_VALUE (tail), dont_do, in_fixup, reachable);
4026 tree cleanup = TREE_VALUE (tail);
4028 /* See expand_d{h,c}c_cleanup for why we avoid this. */
4029 if (TREE_CODE (cleanup) != POPDHC_EXPR
4030 && TREE_CODE (cleanup) != POPDCC_EXPR
4031 /* See expand_eh_region_start_tree for this case. */
4032 && ! TREE_ADDRESSABLE (tail))
4034 cleanup = protect_with_terminate (cleanup);
4035 expand_eh_region_end (cleanup);
4041 /* Cleanups may be run multiple times. For example,
4042 when exiting a binding contour, we expand the
4043 cleanups associated with that contour. When a goto
4044 within that binding contour has a target outside that
4045 contour, it will expand all cleanups from its scope to
4046 the target. Though the cleanups are expanded multiple
4047 times, the control paths are non-overlapping so the
4048 cleanups will not be executed twice. */
4050 /* We may need to protect fixups with rethrow regions. */
4051 int protect = (in_fixup && ! TREE_ADDRESSABLE (tail));
4054 expand_fixup_region_start ();
4056 expand_expr (TREE_VALUE (tail), const0_rtx, VOIDmode, 0);
4058 expand_fixup_region_end (TREE_VALUE (tail));
4065 /* Mark when the context we are emitting RTL for as a conditional
4066 context, so that any cleanup actions we register with
4067 expand_decl_init will be properly conditionalized when those
4068 cleanup actions are later performed. Must be called before any
4069 expression (tree) is expanded that is within a conditional context. */
4072 start_cleanup_deferral ()
4074 /* block_stack can be NULL if we are inside the parameter list. It is
4075 OK to do nothing, because cleanups aren't possible here. */
4077 ++block_stack->data.block.conditional_code;
4080 /* Mark the end of a conditional region of code. Because cleanup
4081 deferrals may be nested, we may still be in a conditional region
4082 after we end the currently deferred cleanups, only after we end all
4083 deferred cleanups, are we back in unconditional code. */
4086 end_cleanup_deferral ()
4088 /* block_stack can be NULL if we are inside the parameter list. It is
4089 OK to do nothing, because cleanups aren't possible here. */
4091 --block_stack->data.block.conditional_code;
4094 /* Move all cleanups from the current block_stack
4095 to the containing block_stack, where they are assumed to
4096 have been created. If anything can cause a temporary to
4097 be created, but not expanded for more than one level of
4098 block_stacks, then this code will have to change. */
4103 struct nesting *block = block_stack;
4104 struct nesting *outer = block->next;
4106 outer->data.block.cleanups
4107 = chainon (block->data.block.cleanups,
4108 outer->data.block.cleanups);
4109 block->data.block.cleanups = 0;
4113 last_cleanup_this_contour ()
4115 if (block_stack == 0)
4118 return block_stack->data.block.cleanups;
4121 /* Return 1 if there are any pending cleanups at this point.
4122 If THIS_CONTOUR is nonzero, check the current contour as well.
4123 Otherwise, look only at the contours that enclose this one. */
4126 any_pending_cleanups (this_contour)
4129 struct nesting *block;
4131 if (block_stack == 0)
4134 if (this_contour && block_stack->data.block.cleanups != NULL)
4136 if (block_stack->data.block.cleanups == 0
4137 && block_stack->data.block.outer_cleanups == 0)
4140 for (block = block_stack->next; block; block = block->next)
4141 if (block->data.block.cleanups != 0)
4147 /* Enter a case (Pascal) or switch (C) statement.
4148 Push a block onto case_stack and nesting_stack
4149 to accumulate the case-labels that are seen
4150 and to record the labels generated for the statement.
4152 EXIT_FLAG is nonzero if `exit_something' should exit this case stmt.
4153 Otherwise, this construct is transparent for `exit_something'.
4155 EXPR is the index-expression to be dispatched on.
4156 TYPE is its nominal type. We could simply convert EXPR to this type,
4157 but instead we take short cuts. */
4160 expand_start_case (exit_flag, expr, type, printname)
4164 const char *printname;
4166 register struct nesting *thiscase = ALLOC_NESTING ();
4168 /* Make an entry on case_stack for the case we are entering. */
4170 thiscase->next = case_stack;
4171 thiscase->all = nesting_stack;
4172 thiscase->depth = ++nesting_depth;
4173 thiscase->exit_label = exit_flag ? gen_label_rtx () : 0;
4174 thiscase->data.case_stmt.case_list = 0;
4175 thiscase->data.case_stmt.index_expr = expr;
4176 thiscase->data.case_stmt.nominal_type = type;
4177 thiscase->data.case_stmt.default_label = 0;
4178 thiscase->data.case_stmt.num_ranges = 0;
4179 thiscase->data.case_stmt.printname = printname;
4180 thiscase->data.case_stmt.line_number_status = force_line_numbers ();
4181 case_stack = thiscase;
4182 nesting_stack = thiscase;
4184 do_pending_stack_adjust ();
4186 /* Make sure case_stmt.start points to something that won't
4187 need any transformation before expand_end_case. */
4188 if (GET_CODE (get_last_insn ()) != NOTE)
4189 emit_note (NULL_PTR, NOTE_INSN_DELETED);
4191 thiscase->data.case_stmt.start = get_last_insn ();
4193 start_cleanup_deferral ();
4197 /* Start a "dummy case statement" within which case labels are invalid
4198 and are not connected to any larger real case statement.
4199 This can be used if you don't want to let a case statement jump
4200 into the middle of certain kinds of constructs. */
4203 expand_start_case_dummy ()
4205 register struct nesting *thiscase = ALLOC_NESTING ();
4207 /* Make an entry on case_stack for the dummy. */
4209 thiscase->next = case_stack;
4210 thiscase->all = nesting_stack;
4211 thiscase->depth = ++nesting_depth;
4212 thiscase->exit_label = 0;
4213 thiscase->data.case_stmt.case_list = 0;
4214 thiscase->data.case_stmt.start = 0;
4215 thiscase->data.case_stmt.nominal_type = 0;
4216 thiscase->data.case_stmt.default_label = 0;
4217 thiscase->data.case_stmt.num_ranges = 0;
4218 case_stack = thiscase;
4219 nesting_stack = thiscase;
4220 start_cleanup_deferral ();
4223 /* End a dummy case statement. */
4226 expand_end_case_dummy ()
4228 end_cleanup_deferral ();
4229 POPSTACK (case_stack);
4232 /* Return the data type of the index-expression
4233 of the innermost case statement, or null if none. */
4236 case_index_expr_type ()
4239 return TREE_TYPE (case_stack->data.case_stmt.index_expr);
4246 /* If this is the first label, warn if any insns have been emitted. */
4247 if (case_stack->data.case_stmt.line_number_status >= 0)
4251 restore_line_number_status
4252 (case_stack->data.case_stmt.line_number_status);
4253 case_stack->data.case_stmt.line_number_status = -1;
4255 for (insn = case_stack->data.case_stmt.start;
4257 insn = NEXT_INSN (insn))
4259 if (GET_CODE (insn) == CODE_LABEL)
4261 if (GET_CODE (insn) != NOTE
4262 && (GET_CODE (insn) != INSN || GET_CODE (PATTERN (insn)) != USE))
4265 insn = PREV_INSN (insn);
4266 while (insn && (GET_CODE (insn) != NOTE || NOTE_LINE_NUMBER (insn) < 0));
4268 /* If insn is zero, then there must have been a syntax error. */
4270 warning_with_file_and_line (NOTE_SOURCE_FILE(insn),
4271 NOTE_LINE_NUMBER(insn),
4272 "unreachable code at beginning of %s",
4273 case_stack->data.case_stmt.printname);
4280 /* Accumulate one case or default label inside a case or switch statement.
4281 VALUE is the value of the case (a null pointer, for a default label).
4282 The function CONVERTER, when applied to arguments T and V,
4283 converts the value V to the type T.
4285 If not currently inside a case or switch statement, return 1 and do
4286 nothing. The caller will print a language-specific error message.
4287 If VALUE is a duplicate or overlaps, return 2 and do nothing
4288 except store the (first) duplicate node in *DUPLICATE.
4289 If VALUE is out of range, return 3 and do nothing.
4290 If we are jumping into the scope of a cleanup or var-sized array, return 5.
4291 Return 0 on success.
4293 Extended to handle range statements. */
4296 pushcase (value, converter, label, duplicate)
4297 register tree value;
4298 tree (*converter) PROTO((tree, tree));
4299 register tree label;
4305 /* Fail if not inside a real case statement. */
4306 if (! (case_stack && case_stack->data.case_stmt.start))
4309 if (stack_block_stack
4310 && stack_block_stack->depth > case_stack->depth)
4313 index_type = TREE_TYPE (case_stack->data.case_stmt.index_expr);
4314 nominal_type = case_stack->data.case_stmt.nominal_type;
4316 /* If the index is erroneous, avoid more problems: pretend to succeed. */
4317 if (index_type == error_mark_node)
4320 /* Convert VALUE to the type in which the comparisons are nominally done. */
4322 value = (*converter) (nominal_type, value);
4326 /* Fail if this value is out of range for the actual type of the index
4327 (which may be narrower than NOMINAL_TYPE). */
4328 if (value != 0 && ! int_fits_type_p (value, index_type))
4331 /* Fail if this is a duplicate or overlaps another entry. */
4334 if (case_stack->data.case_stmt.default_label != 0)
4336 *duplicate = case_stack->data.case_stmt.default_label;
4339 case_stack->data.case_stmt.default_label = label;
4342 return add_case_node (value, value, label, duplicate);
4344 expand_label (label);
4348 /* Like pushcase but this case applies to all values between VALUE1 and
4349 VALUE2 (inclusive). If VALUE1 is NULL, the range starts at the lowest
4350 value of the index type and ends at VALUE2. If VALUE2 is NULL, the range
4351 starts at VALUE1 and ends at the highest value of the index type.
4352 If both are NULL, this case applies to all values.
4354 The return value is the same as that of pushcase but there is one
4355 additional error code: 4 means the specified range was empty. */
4358 pushcase_range (value1, value2, converter, label, duplicate)
4359 register tree value1, value2;
4360 tree (*converter) PROTO((tree, tree));
4361 register tree label;
4367 /* Fail if not inside a real case statement. */
4368 if (! (case_stack && case_stack->data.case_stmt.start))
4371 if (stack_block_stack
4372 && stack_block_stack->depth > case_stack->depth)
4375 index_type = TREE_TYPE (case_stack->data.case_stmt.index_expr);
4376 nominal_type = case_stack->data.case_stmt.nominal_type;
4378 /* If the index is erroneous, avoid more problems: pretend to succeed. */
4379 if (index_type == error_mark_node)
4384 /* Convert VALUEs to type in which the comparisons are nominally done
4385 and replace any unspecified value with the corresponding bound. */
4387 value1 = TYPE_MIN_VALUE (index_type);
4389 value2 = TYPE_MAX_VALUE (index_type);
4391 /* Fail if the range is empty. Do this before any conversion since
4392 we want to allow out-of-range empty ranges. */
4393 if (value2 && tree_int_cst_lt (value2, value1))
4396 value1 = (*converter) (nominal_type, value1);
4398 /* If the max was unbounded, use the max of the nominal_type we are
4399 converting to. Do this after the < check above to suppress false
4402 value2 = TYPE_MAX_VALUE (nominal_type);
4403 value2 = (*converter) (nominal_type, value2);
4405 /* Fail if these values are out of range. */
4406 if (TREE_CONSTANT_OVERFLOW (value1)
4407 || ! int_fits_type_p (value1, index_type))
4410 if (TREE_CONSTANT_OVERFLOW (value2)
4411 || ! int_fits_type_p (value2, index_type))
4414 return add_case_node (value1, value2, label, duplicate);
4417 /* Do the actual insertion of a case label for pushcase and pushcase_range
4418 into case_stack->data.case_stmt.case_list. Use an AVL tree to avoid
4419 slowdown for large switch statements. */
4422 add_case_node (low, high, label, duplicate)
4427 struct case_node *p, **q, *r;
4429 q = &case_stack->data.case_stmt.case_list;
4436 /* Keep going past elements distinctly greater than HIGH. */
4437 if (tree_int_cst_lt (high, p->low))
4440 /* or distinctly less than LOW. */
4441 else if (tree_int_cst_lt (p->high, low))
4446 /* We have an overlap; this is an error. */
4447 *duplicate = p->code_label;
4452 /* Add this label to the chain, and succeed.
4453 Copy LOW, HIGH so they are on temporary rather than momentary
4454 obstack and will thus survive till the end of the case statement. */
4456 r = (struct case_node *) oballoc (sizeof (struct case_node));
4457 r->low = copy_node (low);
4459 /* If the bounds are equal, turn this into the one-value case. */
4461 if (tree_int_cst_equal (low, high))
4465 r->high = copy_node (high);
4466 case_stack->data.case_stmt.num_ranges++;
4469 r->code_label = label;
4470 expand_label (label);
4480 struct case_node *s;
4486 if (! (b = p->balance))
4487 /* Growth propagation from left side. */
4494 if ((p->left = s = r->right))
4503 if ((r->parent = s))
4511 case_stack->data.case_stmt.case_list = r;
4514 /* r->balance == +1 */
4519 struct case_node *t = r->right;
4521 if ((p->left = s = t->right))
4525 if ((r->right = s = t->left))
4539 if ((t->parent = s))
4547 case_stack->data.case_stmt.case_list = t;
4554 /* p->balance == +1; growth of left side balances the node. */
4564 if (! (b = p->balance))
4565 /* Growth propagation from right side. */
4573 if ((p->right = s = r->left))
4581 if ((r->parent = s))
4590 case_stack->data.case_stmt.case_list = r;
4594 /* r->balance == -1 */
4598 struct case_node *t = r->left;
4600 if ((p->right = s = t->left))
4605 if ((r->left = s = t->right))
4619 if ((t->parent = s))
4628 case_stack->data.case_stmt.case_list = t;
4634 /* p->balance == -1; growth of right side balances the node. */
4648 /* Returns the number of possible values of TYPE.
4649 Returns -1 if the number is unknown or variable.
4650 Returns -2 if the number does not fit in a HOST_WIDE_INT.
4651 Sets *SPARENESS to 2 if TYPE is an ENUMERAL_TYPE whose values
4652 do not increase monotonically (there may be duplicates);
4653 to 1 if the values increase monotonically, but not always by 1;
4654 otherwise sets it to 0. */
4657 all_cases_count (type, spareness)
4661 HOST_WIDE_INT count;
4664 switch (TREE_CODE (type))
4671 count = 1 << BITS_PER_UNIT;
4675 if (TREE_CODE (TYPE_MIN_VALUE (type)) != INTEGER_CST
4676 || TYPE_MAX_VALUE (type) == NULL
4677 || TREE_CODE (TYPE_MAX_VALUE (type)) != INTEGER_CST)
4682 = TREE_INT_CST_LOW (TYPE_MAX_VALUE (type))
4683 - TREE_INT_CST_LOW (TYPE_MIN_VALUE (type)) + 1
4684 but with overflow checking. */
4685 tree mint = TYPE_MIN_VALUE (type);
4686 tree maxt = TYPE_MAX_VALUE (type);
4687 HOST_WIDE_INT lo, hi;
4688 neg_double(TREE_INT_CST_LOW (mint), TREE_INT_CST_HIGH (mint),
4690 add_double(TREE_INT_CST_LOW (maxt), TREE_INT_CST_HIGH (maxt),
4692 add_double (lo, hi, 1, 0, &lo, &hi);
4693 if (hi != 0 || lo < 0)
4700 for (t = TYPE_VALUES (type); t != NULL_TREE; t = TREE_CHAIN (t))
4702 if (TREE_CODE (TYPE_MIN_VALUE (type)) != INTEGER_CST
4703 || TREE_CODE (TREE_VALUE (t)) != INTEGER_CST
4704 || TREE_INT_CST_LOW (TYPE_MIN_VALUE (type)) + count
4705 != TREE_INT_CST_LOW (TREE_VALUE (t)))
4709 if (*spareness == 1)
4711 tree prev = TREE_VALUE (TYPE_VALUES (type));
4712 for (t = TYPE_VALUES (type); t = TREE_CHAIN (t), t != NULL_TREE; )
4714 if (! tree_int_cst_lt (prev, TREE_VALUE (t)))
4719 prev = TREE_VALUE (t);
4728 #define BITARRAY_TEST(ARRAY, INDEX) \
4729 ((ARRAY)[(unsigned) (INDEX) / HOST_BITS_PER_CHAR]\
4730 & (1 << ((unsigned) (INDEX) % HOST_BITS_PER_CHAR)))
4731 #define BITARRAY_SET(ARRAY, INDEX) \
4732 ((ARRAY)[(unsigned) (INDEX) / HOST_BITS_PER_CHAR]\
4733 |= 1 << ((unsigned) (INDEX) % HOST_BITS_PER_CHAR))
4735 /* Set the elements of the bitstring CASES_SEEN (which has length COUNT),
4736 with the case values we have seen, assuming the case expression
4738 SPARSENESS is as determined by all_cases_count.
4740 The time needed is proportional to COUNT, unless
4741 SPARSENESS is 2, in which case quadratic time is needed. */
4744 mark_seen_cases (type, cases_seen, count, sparseness)
4746 unsigned char *cases_seen;
4750 tree next_node_to_try = NULL_TREE;
4751 long next_node_offset = 0;
4753 register struct case_node *n, *root = case_stack->data.case_stmt.case_list;
4754 tree val = make_node (INTEGER_CST);
4755 TREE_TYPE (val) = type;
4758 else if (sparseness == 2)
4763 /* This less efficient loop is only needed to handle
4764 duplicate case values (multiple enum constants
4765 with the same value). */
4766 TREE_TYPE (val) = TREE_TYPE (root->low);
4767 for (t = TYPE_VALUES (type), xlo = 0; t != NULL_TREE;
4768 t = TREE_CHAIN (t), xlo++)
4770 TREE_INT_CST_LOW (val) = TREE_INT_CST_LOW (TREE_VALUE (t));
4771 TREE_INT_CST_HIGH (val) = TREE_INT_CST_HIGH (TREE_VALUE (t));
4775 /* Keep going past elements distinctly greater than VAL. */
4776 if (tree_int_cst_lt (val, n->low))
4779 /* or distinctly less than VAL. */
4780 else if (tree_int_cst_lt (n->high, val))
4785 /* We have found a matching range. */
4786 BITARRAY_SET (cases_seen, xlo);
4796 case_stack->data.case_stmt.case_list = root = case_tree2list (root, 0);
4797 for (n = root; n; n = n->right)
4799 TREE_INT_CST_LOW (val) = TREE_INT_CST_LOW (n->low);
4800 TREE_INT_CST_HIGH (val) = TREE_INT_CST_HIGH (n->low);
4801 while ( ! tree_int_cst_lt (n->high, val))
4803 /* Calculate (into xlo) the "offset" of the integer (val).
4804 The element with lowest value has offset 0, the next smallest
4805 element has offset 1, etc. */
4807 HOST_WIDE_INT xlo, xhi;
4809 if (sparseness && TYPE_VALUES (type) != NULL_TREE)
4811 /* The TYPE_VALUES will be in increasing order, so
4812 starting searching where we last ended. */
4813 t = next_node_to_try;
4814 xlo = next_node_offset;
4820 t = TYPE_VALUES (type);
4823 if (tree_int_cst_equal (val, TREE_VALUE (t)))
4825 next_node_to_try = TREE_CHAIN (t);
4826 next_node_offset = xlo + 1;
4831 if (t == next_node_to_try)
4840 t = TYPE_MIN_VALUE (type);
4842 neg_double (TREE_INT_CST_LOW (t), TREE_INT_CST_HIGH (t),
4846 add_double (xlo, xhi,
4847 TREE_INT_CST_LOW (val), TREE_INT_CST_HIGH (val),
4851 if (xhi == 0 && xlo >= 0 && xlo < count)
4852 BITARRAY_SET (cases_seen, xlo);
4853 add_double (TREE_INT_CST_LOW (val), TREE_INT_CST_HIGH (val),
4855 &TREE_INT_CST_LOW (val), &TREE_INT_CST_HIGH (val));
4861 /* Called when the index of a switch statement is an enumerated type
4862 and there is no default label.
4864 Checks that all enumeration literals are covered by the case
4865 expressions of a switch. Also, warn if there are any extra
4866 switch cases that are *not* elements of the enumerated type.
4868 If all enumeration literals were covered by the case expressions,
4869 turn one of the expressions into the default expression since it should
4870 not be possible to fall through such a switch. */
4873 check_for_full_enumeration_handling (type)
4876 register struct case_node *n;
4877 register tree chain;
4878 #if 0 /* variable used by 'if 0'ed code below. */
4879 register struct case_node **l;
4883 /* True iff the selector type is a numbered set mode. */
4886 /* The number of possible selector values. */
4889 /* For each possible selector value. a one iff it has been matched
4890 by a case value alternative. */
4891 unsigned char *cases_seen;
4893 /* The allocated size of cases_seen, in chars. */
4899 size = all_cases_count (type, &sparseness);
4900 bytes_needed = (size + HOST_BITS_PER_CHAR) / HOST_BITS_PER_CHAR;
4902 if (size > 0 && size < 600000
4903 /* We deliberately use calloc here - not xcalloc. */
4904 && (cases_seen = (unsigned char *) calloc (bytes_needed, 1)) != NULL)
4907 tree v = TYPE_VALUES (type);
4909 /* The time complexity of this code is normally O(N), where
4910 N being the number of members in the enumerated type.
4911 However, if type is a ENUMERAL_TYPE whose values do not
4912 increase monotonically, O(N*log(N)) time may be needed. */
4914 mark_seen_cases (type, cases_seen, size, sparseness);
4916 for (i = 0; v != NULL_TREE && i < size; i++, v = TREE_CHAIN (v))
4918 if (BITARRAY_TEST(cases_seen, i) == 0)
4919 warning ("enumeration value `%s' not handled in switch",
4920 IDENTIFIER_POINTER (TREE_PURPOSE (v)));
4926 /* Now we go the other way around; we warn if there are case
4927 expressions that don't correspond to enumerators. This can
4928 occur since C and C++ don't enforce type-checking of
4929 assignments to enumeration variables. */
4931 if (case_stack->data.case_stmt.case_list
4932 && case_stack->data.case_stmt.case_list->left)
4933 case_stack->data.case_stmt.case_list
4934 = case_tree2list (case_stack->data.case_stmt.case_list, 0);
4936 for (n = case_stack->data.case_stmt.case_list; n; n = n->right)
4938 for (chain = TYPE_VALUES (type);
4939 chain && !tree_int_cst_equal (n->low, TREE_VALUE (chain));
4940 chain = TREE_CHAIN (chain))
4945 if (TYPE_NAME (type) == 0)
4946 warning ("case value `%ld' not in enumerated type",
4947 (long) TREE_INT_CST_LOW (n->low));
4949 warning ("case value `%ld' not in enumerated type `%s'",
4950 (long) TREE_INT_CST_LOW (n->low),
4951 IDENTIFIER_POINTER ((TREE_CODE (TYPE_NAME (type))
4954 : DECL_NAME (TYPE_NAME (type))));
4956 if (!tree_int_cst_equal (n->low, n->high))
4958 for (chain = TYPE_VALUES (type);
4959 chain && !tree_int_cst_equal (n->high, TREE_VALUE (chain));
4960 chain = TREE_CHAIN (chain))
4965 if (TYPE_NAME (type) == 0)
4966 warning ("case value `%ld' not in enumerated type",
4967 (long) TREE_INT_CST_LOW (n->high));
4969 warning ("case value `%ld' not in enumerated type `%s'",
4970 (long) TREE_INT_CST_LOW (n->high),
4971 IDENTIFIER_POINTER ((TREE_CODE (TYPE_NAME (type))
4974 : DECL_NAME (TYPE_NAME (type))));
4980 /* ??? This optimization is disabled because it causes valid programs to
4981 fail. ANSI C does not guarantee that an expression with enum type
4982 will have a value that is the same as one of the enumeration literals. */
4984 /* If all values were found as case labels, make one of them the default
4985 label. Thus, this switch will never fall through. We arbitrarily pick
4986 the last one to make the default since this is likely the most
4987 efficient choice. */
4991 for (l = &case_stack->data.case_stmt.case_list;
4996 case_stack->data.case_stmt.default_label = (*l)->code_label;
5003 /* Terminate a case (Pascal) or switch (C) statement
5004 in which ORIG_INDEX is the expression to be tested.
5005 Generate the code to test it and jump to the right place. */
5008 expand_end_case (orig_index)
5011 tree minval = NULL_TREE, maxval = NULL_TREE, range, orig_minval;
5012 rtx default_label = 0;
5013 register struct case_node *n;
5021 register struct nesting *thiscase = case_stack;
5022 tree index_expr, index_type;
5025 table_label = gen_label_rtx ();
5026 index_expr = thiscase->data.case_stmt.index_expr;
5027 index_type = TREE_TYPE (index_expr);
5028 unsignedp = TREE_UNSIGNED (index_type);
5030 do_pending_stack_adjust ();
5032 /* This might get an spurious warning in the presence of a syntax error;
5033 it could be fixed by moving the call to check_seenlabel after the
5034 check for error_mark_node, and copying the code of check_seenlabel that
5035 deals with case_stack->data.case_stmt.line_number_status /
5036 restore_line_number_status in front of the call to end_cleanup_deferral;
5037 However, this might miss some useful warnings in the presence of
5038 non-syntax errors. */
5041 /* An ERROR_MARK occurs for various reasons including invalid data type. */
5042 if (index_type != error_mark_node)
5044 /* If switch expression was an enumerated type, check that all
5045 enumeration literals are covered by the cases.
5046 No sense trying this if there's a default case, however. */
5048 if (!thiscase->data.case_stmt.default_label
5049 && TREE_CODE (TREE_TYPE (orig_index)) == ENUMERAL_TYPE
5050 && TREE_CODE (index_expr) != INTEGER_CST)
5051 check_for_full_enumeration_handling (TREE_TYPE (orig_index));
5053 /* If we don't have a default-label, create one here,
5054 after the body of the switch. */
5055 if (thiscase->data.case_stmt.default_label == 0)
5057 thiscase->data.case_stmt.default_label
5058 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
5059 expand_label (thiscase->data.case_stmt.default_label);
5061 default_label = label_rtx (thiscase->data.case_stmt.default_label);
5063 before_case = get_last_insn ();
5065 if (thiscase->data.case_stmt.case_list
5066 && thiscase->data.case_stmt.case_list->left)
5067 thiscase->data.case_stmt.case_list
5068 = case_tree2list(thiscase->data.case_stmt.case_list, 0);
5070 /* Simplify the case-list before we count it. */
5071 group_case_nodes (thiscase->data.case_stmt.case_list);
5073 /* Get upper and lower bounds of case values.
5074 Also convert all the case values to the index expr's data type. */
5077 for (n = thiscase->data.case_stmt.case_list; n; n = n->right)
5079 /* Check low and high label values are integers. */
5080 if (TREE_CODE (n->low) != INTEGER_CST)
5082 if (TREE_CODE (n->high) != INTEGER_CST)
5085 n->low = convert (index_type, n->low);
5086 n->high = convert (index_type, n->high);
5088 /* Count the elements and track the largest and smallest
5089 of them (treating them as signed even if they are not). */
5097 if (INT_CST_LT (n->low, minval))
5099 if (INT_CST_LT (maxval, n->high))
5102 /* A range counts double, since it requires two compares. */
5103 if (! tree_int_cst_equal (n->low, n->high))
5107 orig_minval = minval;
5109 /* Compute span of values. */
5111 range = fold (build (MINUS_EXPR, index_type, maxval, minval));
5113 end_cleanup_deferral ();
5117 expand_expr (index_expr, const0_rtx, VOIDmode, 0);
5119 emit_jump (default_label);
5122 /* If range of values is much bigger than number of values,
5123 make a sequence of conditional branches instead of a dispatch.
5124 If the switch-index is a constant, do it this way
5125 because we can optimize it. */
5127 #ifndef CASE_VALUES_THRESHOLD
5129 #define CASE_VALUES_THRESHOLD (HAVE_casesi ? 4 : 5)
5131 /* If machine does not have a case insn that compares the
5132 bounds, this means extra overhead for dispatch tables
5133 which raises the threshold for using them. */
5134 #define CASE_VALUES_THRESHOLD 5
5135 #endif /* HAVE_casesi */
5136 #endif /* CASE_VALUES_THRESHOLD */
5138 else if (TREE_INT_CST_HIGH (range) != 0
5139 || count < (unsigned int) CASE_VALUES_THRESHOLD
5140 || ((unsigned HOST_WIDE_INT) (TREE_INT_CST_LOW (range))
5142 #ifndef ASM_OUTPUT_ADDR_DIFF_ELT
5145 || TREE_CODE (index_expr) == INTEGER_CST
5146 /* These will reduce to a constant. */
5147 || (TREE_CODE (index_expr) == CALL_EXPR
5148 && TREE_CODE (TREE_OPERAND (index_expr, 0)) == ADDR_EXPR
5149 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (index_expr, 0), 0)) == FUNCTION_DECL
5150 && DECL_FUNCTION_CODE (TREE_OPERAND (TREE_OPERAND (index_expr, 0), 0)) == BUILT_IN_CLASSIFY_TYPE)
5151 || (TREE_CODE (index_expr) == COMPOUND_EXPR
5152 && TREE_CODE (TREE_OPERAND (index_expr, 1)) == INTEGER_CST))
5154 index = expand_expr (index_expr, NULL_RTX, VOIDmode, 0);
5156 /* If the index is a short or char that we do not have
5157 an insn to handle comparisons directly, convert it to
5158 a full integer now, rather than letting each comparison
5159 generate the conversion. */
5161 if (GET_MODE_CLASS (GET_MODE (index)) == MODE_INT
5162 && (cmp_optab->handlers[(int) GET_MODE(index)].insn_code
5163 == CODE_FOR_nothing))
5165 enum machine_mode wider_mode;
5166 for (wider_mode = GET_MODE (index); wider_mode != VOIDmode;
5167 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
5168 if (cmp_optab->handlers[(int) wider_mode].insn_code
5169 != CODE_FOR_nothing)
5171 index = convert_to_mode (wider_mode, index, unsignedp);
5177 do_pending_stack_adjust ();
5179 index = protect_from_queue (index, 0);
5180 if (GET_CODE (index) == MEM)
5181 index = copy_to_reg (index);
5182 if (GET_CODE (index) == CONST_INT
5183 || TREE_CODE (index_expr) == INTEGER_CST)
5185 /* Make a tree node with the proper constant value
5186 if we don't already have one. */
5187 if (TREE_CODE (index_expr) != INTEGER_CST)
5190 = build_int_2 (INTVAL (index),
5191 unsignedp || INTVAL (index) >= 0 ? 0 : -1);
5192 index_expr = convert (index_type, index_expr);
5195 /* For constant index expressions we need only
5196 issue a unconditional branch to the appropriate
5197 target code. The job of removing any unreachable
5198 code is left to the optimisation phase if the
5199 "-O" option is specified. */
5200 for (n = thiscase->data.case_stmt.case_list; n; n = n->right)
5201 if (! tree_int_cst_lt (index_expr, n->low)
5202 && ! tree_int_cst_lt (n->high, index_expr))
5206 emit_jump (label_rtx (n->code_label));
5208 emit_jump (default_label);
5212 /* If the index expression is not constant we generate
5213 a binary decision tree to select the appropriate
5214 target code. This is done as follows:
5216 The list of cases is rearranged into a binary tree,
5217 nearly optimal assuming equal probability for each case.
5219 The tree is transformed into RTL, eliminating
5220 redundant test conditions at the same time.
5222 If program flow could reach the end of the
5223 decision tree an unconditional jump to the
5224 default code is emitted. */
5227 = (TREE_CODE (TREE_TYPE (orig_index)) != ENUMERAL_TYPE
5228 && estimate_case_costs (thiscase->data.case_stmt.case_list));
5229 balance_case_nodes (&thiscase->data.case_stmt.case_list,
5231 emit_case_nodes (index, thiscase->data.case_stmt.case_list,
5232 default_label, index_type);
5233 emit_jump_if_reachable (default_label);
5242 enum machine_mode index_mode = SImode;
5243 int index_bits = GET_MODE_BITSIZE (index_mode);
5245 enum machine_mode op_mode;
5247 /* Convert the index to SImode. */
5248 if (GET_MODE_BITSIZE (TYPE_MODE (index_type))
5249 > GET_MODE_BITSIZE (index_mode))
5251 enum machine_mode omode = TYPE_MODE (index_type);
5252 rtx rangertx = expand_expr (range, NULL_RTX, VOIDmode, 0);
5254 /* We must handle the endpoints in the original mode. */
5255 index_expr = build (MINUS_EXPR, index_type,
5256 index_expr, minval);
5257 minval = integer_zero_node;
5258 index = expand_expr (index_expr, NULL_RTX, VOIDmode, 0);
5259 emit_cmp_and_jump_insns (rangertx, index, LTU, NULL_RTX,
5260 omode, 1, 0, default_label);
5261 /* Now we can safely truncate. */
5262 index = convert_to_mode (index_mode, index, 0);
5266 if (TYPE_MODE (index_type) != index_mode)
5268 index_expr = convert (type_for_size (index_bits, 0),
5270 index_type = TREE_TYPE (index_expr);
5273 index = expand_expr (index_expr, NULL_RTX, VOIDmode, 0);
5276 index = protect_from_queue (index, 0);
5277 do_pending_stack_adjust ();
5279 op_mode = insn_operand_mode[(int)CODE_FOR_casesi][0];
5280 if (! (*insn_operand_predicate[(int)CODE_FOR_casesi][0])
5282 index = copy_to_mode_reg (op_mode, index);
5284 op1 = expand_expr (minval, NULL_RTX, VOIDmode, 0);
5286 op_mode = insn_operand_mode[(int)CODE_FOR_casesi][1];
5287 if (! (*insn_operand_predicate[(int)CODE_FOR_casesi][1])
5289 op1 = copy_to_mode_reg (op_mode, op1);
5291 op2 = expand_expr (range, NULL_RTX, VOIDmode, 0);
5293 op_mode = insn_operand_mode[(int)CODE_FOR_casesi][2];
5294 if (! (*insn_operand_predicate[(int)CODE_FOR_casesi][2])
5296 op2 = copy_to_mode_reg (op_mode, op2);
5298 emit_jump_insn (gen_casesi (index, op1, op2,
5299 table_label, default_label));
5303 #ifdef HAVE_tablejump
5304 if (! win && HAVE_tablejump)
5306 index_expr = convert (thiscase->data.case_stmt.nominal_type,
5307 fold (build (MINUS_EXPR, index_type,
5308 index_expr, minval)));
5309 index_type = TREE_TYPE (index_expr);
5310 index = expand_expr (index_expr, NULL_RTX, VOIDmode, 0);
5312 index = protect_from_queue (index, 0);
5313 do_pending_stack_adjust ();
5315 do_tablejump (index, TYPE_MODE (index_type),
5316 expand_expr (range, NULL_RTX, VOIDmode, 0),
5317 table_label, default_label);
5324 /* Get table of labels to jump to, in order of case index. */
5326 ncases = TREE_INT_CST_LOW (range) + 1;
5327 labelvec = (rtx *) alloca (ncases * sizeof (rtx));
5328 bzero ((char *) labelvec, ncases * sizeof (rtx));
5330 for (n = thiscase->data.case_stmt.case_list; n; n = n->right)
5332 register HOST_WIDE_INT i
5333 = TREE_INT_CST_LOW (n->low) - TREE_INT_CST_LOW (orig_minval);
5338 = gen_rtx_LABEL_REF (Pmode, label_rtx (n->code_label));
5339 if (i + TREE_INT_CST_LOW (orig_minval)
5340 == TREE_INT_CST_LOW (n->high))
5346 /* Fill in the gaps with the default. */
5347 for (i = 0; i < ncases; i++)
5348 if (labelvec[i] == 0)
5349 labelvec[i] = gen_rtx_LABEL_REF (Pmode, default_label);
5351 /* Output the table */
5352 emit_label (table_label);
5354 if (CASE_VECTOR_PC_RELATIVE || flag_pic)
5355 emit_jump_insn (gen_rtx_ADDR_DIFF_VEC (CASE_VECTOR_MODE,
5356 gen_rtx_LABEL_REF (Pmode, table_label),
5357 gen_rtvec_v (ncases, labelvec),
5358 const0_rtx, const0_rtx));
5360 emit_jump_insn (gen_rtx_ADDR_VEC (CASE_VECTOR_MODE,
5361 gen_rtvec_v (ncases, labelvec)));
5363 /* If the case insn drops through the table,
5364 after the table we must jump to the default-label.
5365 Otherwise record no drop-through after the table. */
5366 #ifdef CASE_DROPS_THROUGH
5367 emit_jump (default_label);
5373 before_case = squeeze_notes (NEXT_INSN (before_case), get_last_insn ());
5374 reorder_insns (before_case, get_last_insn (),
5375 thiscase->data.case_stmt.start);
5378 end_cleanup_deferral ();
5380 if (thiscase->exit_label)
5381 emit_label (thiscase->exit_label);
5383 POPSTACK (case_stack);
5388 /* Convert the tree NODE into a list linked by the right field, with the left
5389 field zeroed. RIGHT is used for recursion; it is a list to be placed
5390 rightmost in the resulting list. */
5392 static struct case_node *
5393 case_tree2list (node, right)
5394 struct case_node *node, *right;
5396 struct case_node *left;
5399 right = case_tree2list (node->right, right);
5401 node->right = right;
5402 if ((left = node->left))
5405 return case_tree2list (left, node);
5411 /* Generate code to jump to LABEL if OP1 and OP2 are equal. */
5414 do_jump_if_equal (op1, op2, label, unsignedp)
5415 rtx op1, op2, label;
5418 if (GET_CODE (op1) == CONST_INT
5419 && GET_CODE (op2) == CONST_INT)
5421 if (INTVAL (op1) == INTVAL (op2))
5426 enum machine_mode mode = GET_MODE (op1);
5427 if (mode == VOIDmode)
5428 mode = GET_MODE (op2);
5429 emit_cmp_and_jump_insns (op1, op2, EQ, NULL_RTX, mode, unsignedp,
5434 /* Not all case values are encountered equally. This function
5435 uses a heuristic to weight case labels, in cases where that
5436 looks like a reasonable thing to do.
5438 Right now, all we try to guess is text, and we establish the
5441 chars above space: 16
5450 If we find any cases in the switch that are not either -1 or in the range
5451 of valid ASCII characters, or are control characters other than those
5452 commonly used with "\", don't treat this switch scanning text.
5454 Return 1 if these nodes are suitable for cost estimation, otherwise
5458 estimate_case_costs (node)
5461 tree min_ascii = build_int_2 (-1, -1);
5462 tree max_ascii = convert (TREE_TYPE (node->high), build_int_2 (127, 0));
5466 /* If we haven't already made the cost table, make it now. Note that the
5467 lower bound of the table is -1, not zero. */
5469 if (cost_table == NULL)
5471 cost_table = ((short *) xcalloc (129, sizeof (short))) + 1;
5473 for (i = 0; i < 128; i++)
5477 else if (ISPUNCT (i))
5479 else if (ISCNTRL (i))
5483 cost_table[' '] = 8;
5484 cost_table['\t'] = 4;
5485 cost_table['\0'] = 4;
5486 cost_table['\n'] = 2;
5487 cost_table['\f'] = 1;
5488 cost_table['\v'] = 1;
5489 cost_table['\b'] = 1;
5492 /* See if all the case expressions look like text. It is text if the
5493 constant is >= -1 and the highest constant is <= 127. Do all comparisons
5494 as signed arithmetic since we don't want to ever access cost_table with a
5495 value less than -1. Also check that none of the constants in a range
5496 are strange control characters. */
5498 for (n = node; n; n = n->right)
5500 if ((INT_CST_LT (n->low, min_ascii)) || INT_CST_LT (max_ascii, n->high))
5503 for (i = TREE_INT_CST_LOW (n->low); i <= TREE_INT_CST_LOW (n->high); i++)
5504 if (cost_table[i] < 0)
5508 /* All interesting values are within the range of interesting
5509 ASCII characters. */
5513 /* Scan an ordered list of case nodes
5514 combining those with consecutive values or ranges.
5516 Eg. three separate entries 1: 2: 3: become one entry 1..3: */
5519 group_case_nodes (head)
5522 case_node_ptr node = head;
5526 rtx lb = next_real_insn (label_rtx (node->code_label));
5528 case_node_ptr np = node;
5530 /* Try to group the successors of NODE with NODE. */
5531 while (((np = np->right) != 0)
5532 /* Do they jump to the same place? */
5533 && ((lb2 = next_real_insn (label_rtx (np->code_label))) == lb
5534 || (lb != 0 && lb2 != 0
5535 && simplejump_p (lb)
5536 && simplejump_p (lb2)
5537 && rtx_equal_p (SET_SRC (PATTERN (lb)),
5538 SET_SRC (PATTERN (lb2)))))
5539 /* Are their ranges consecutive? */
5540 && tree_int_cst_equal (np->low,
5541 fold (build (PLUS_EXPR,
5542 TREE_TYPE (node->high),
5545 /* An overflow is not consecutive. */
5546 && tree_int_cst_lt (node->high,
5547 fold (build (PLUS_EXPR,
5548 TREE_TYPE (node->high),
5550 integer_one_node))))
5552 node->high = np->high;
5554 /* NP is the first node after NODE which can't be grouped with it.
5555 Delete the nodes in between, and move on to that node. */
5561 /* Take an ordered list of case nodes
5562 and transform them into a near optimal binary tree,
5563 on the assumption that any target code selection value is as
5564 likely as any other.
5566 The transformation is performed by splitting the ordered
5567 list into two equal sections plus a pivot. The parts are
5568 then attached to the pivot as left and right branches. Each
5569 branch is then transformed recursively. */
5572 balance_case_nodes (head, parent)
5573 case_node_ptr *head;
5574 case_node_ptr parent;
5576 register case_node_ptr np;
5584 register case_node_ptr *npp;
5587 /* Count the number of entries on branch. Also count the ranges. */
5591 if (!tree_int_cst_equal (np->low, np->high))
5595 cost += cost_table[TREE_INT_CST_LOW (np->high)];
5599 cost += cost_table[TREE_INT_CST_LOW (np->low)];
5607 /* Split this list if it is long enough for that to help. */
5612 /* Find the place in the list that bisects the list's total cost,
5613 Here I gets half the total cost. */
5618 /* Skip nodes while their cost does not reach that amount. */
5619 if (!tree_int_cst_equal ((*npp)->low, (*npp)->high))
5620 i -= cost_table[TREE_INT_CST_LOW ((*npp)->high)];
5621 i -= cost_table[TREE_INT_CST_LOW ((*npp)->low)];
5624 npp = &(*npp)->right;
5629 /* Leave this branch lopsided, but optimize left-hand
5630 side and fill in `parent' fields for right-hand side. */
5632 np->parent = parent;
5633 balance_case_nodes (&np->left, np);
5634 for (; np->right; np = np->right)
5635 np->right->parent = np;
5639 /* If there are just three nodes, split at the middle one. */
5641 npp = &(*npp)->right;
5644 /* Find the place in the list that bisects the list's total cost,
5645 where ranges count as 2.
5646 Here I gets half the total cost. */
5647 i = (i + ranges + 1) / 2;
5650 /* Skip nodes while their cost does not reach that amount. */
5651 if (!tree_int_cst_equal ((*npp)->low, (*npp)->high))
5656 npp = &(*npp)->right;
5661 np->parent = parent;
5664 /* Optimize each of the two split parts. */
5665 balance_case_nodes (&np->left, np);
5666 balance_case_nodes (&np->right, np);
5670 /* Else leave this branch as one level,
5671 but fill in `parent' fields. */
5673 np->parent = parent;
5674 for (; np->right; np = np->right)
5675 np->right->parent = np;
5680 /* Search the parent sections of the case node tree
5681 to see if a test for the lower bound of NODE would be redundant.
5682 INDEX_TYPE is the type of the index expression.
5684 The instructions to generate the case decision tree are
5685 output in the same order as nodes are processed so it is
5686 known that if a parent node checks the range of the current
5687 node minus one that the current node is bounded at its lower
5688 span. Thus the test would be redundant. */
5691 node_has_low_bound (node, index_type)
5696 case_node_ptr pnode;
5698 /* If the lower bound of this node is the lowest value in the index type,
5699 we need not test it. */
5701 if (tree_int_cst_equal (node->low, TYPE_MIN_VALUE (index_type)))
5704 /* If this node has a left branch, the value at the left must be less
5705 than that at this node, so it cannot be bounded at the bottom and
5706 we need not bother testing any further. */
5711 low_minus_one = fold (build (MINUS_EXPR, TREE_TYPE (node->low),
5712 node->low, integer_one_node));
5714 /* If the subtraction above overflowed, we can't verify anything.
5715 Otherwise, look for a parent that tests our value - 1. */
5717 if (! tree_int_cst_lt (low_minus_one, node->low))
5720 for (pnode = node->parent; pnode; pnode = pnode->parent)
5721 if (tree_int_cst_equal (low_minus_one, pnode->high))
5727 /* Search the parent sections of the case node tree
5728 to see if a test for the upper bound of NODE would be redundant.
5729 INDEX_TYPE is the type of the index expression.
5731 The instructions to generate the case decision tree are
5732 output in the same order as nodes are processed so it is
5733 known that if a parent node checks the range of the current
5734 node plus one that the current node is bounded at its upper
5735 span. Thus the test would be redundant. */
5738 node_has_high_bound (node, index_type)
5743 case_node_ptr pnode;
5745 /* If there is no upper bound, obviously no test is needed. */
5747 if (TYPE_MAX_VALUE (index_type) == NULL)
5750 /* If the upper bound of this node is the highest value in the type
5751 of the index expression, we need not test against it. */
5753 if (tree_int_cst_equal (node->high, TYPE_MAX_VALUE (index_type)))
5756 /* If this node has a right branch, the value at the right must be greater
5757 than that at this node, so it cannot be bounded at the top and
5758 we need not bother testing any further. */
5763 high_plus_one = fold (build (PLUS_EXPR, TREE_TYPE (node->high),
5764 node->high, integer_one_node));
5766 /* If the addition above overflowed, we can't verify anything.
5767 Otherwise, look for a parent that tests our value + 1. */
5769 if (! tree_int_cst_lt (node->high, high_plus_one))
5772 for (pnode = node->parent; pnode; pnode = pnode->parent)
5773 if (tree_int_cst_equal (high_plus_one, pnode->low))
5779 /* Search the parent sections of the
5780 case node tree to see if both tests for the upper and lower
5781 bounds of NODE would be redundant. */
5784 node_is_bounded (node, index_type)
5788 return (node_has_low_bound (node, index_type)
5789 && node_has_high_bound (node, index_type));
5792 /* Emit an unconditional jump to LABEL unless it would be dead code. */
5795 emit_jump_if_reachable (label)
5798 if (GET_CODE (get_last_insn ()) != BARRIER)
5802 /* Emit step-by-step code to select a case for the value of INDEX.
5803 The thus generated decision tree follows the form of the
5804 case-node binary tree NODE, whose nodes represent test conditions.
5805 INDEX_TYPE is the type of the index of the switch.
5807 Care is taken to prune redundant tests from the decision tree
5808 by detecting any boundary conditions already checked by
5809 emitted rtx. (See node_has_high_bound, node_has_low_bound
5810 and node_is_bounded, above.)
5812 Where the test conditions can be shown to be redundant we emit
5813 an unconditional jump to the target code. As a further
5814 optimization, the subordinates of a tree node are examined to
5815 check for bounded nodes. In this case conditional and/or
5816 unconditional jumps as a result of the boundary check for the
5817 current node are arranged to target the subordinates associated
5818 code for out of bound conditions on the current node.
5820 We can assume that when control reaches the code generated here,
5821 the index value has already been compared with the parents
5822 of this node, and determined to be on the same side of each parent
5823 as this node is. Thus, if this node tests for the value 51,
5824 and a parent tested for 52, we don't need to consider
5825 the possibility of a value greater than 51. If another parent
5826 tests for the value 50, then this node need not test anything. */
5829 emit_case_nodes (index, node, default_label, index_type)
5835 /* If INDEX has an unsigned type, we must make unsigned branches. */
5836 int unsignedp = TREE_UNSIGNED (index_type);
5837 typedef rtx rtx_fn ();
5838 enum machine_mode mode = GET_MODE (index);
5840 /* See if our parents have already tested everything for us.
5841 If they have, emit an unconditional jump for this node. */
5842 if (node_is_bounded (node, index_type))
5843 emit_jump (label_rtx (node->code_label));
5845 else if (tree_int_cst_equal (node->low, node->high))
5847 /* Node is single valued. First see if the index expression matches
5848 this node and then check our children, if any. */
5850 do_jump_if_equal (index, expand_expr (node->low, NULL_RTX, VOIDmode, 0),
5851 label_rtx (node->code_label), unsignedp);
5853 if (node->right != 0 && node->left != 0)
5855 /* This node has children on both sides.
5856 Dispatch to one side or the other
5857 by comparing the index value with this node's value.
5858 If one subtree is bounded, check that one first,
5859 so we can avoid real branches in the tree. */
5861 if (node_is_bounded (node->right, index_type))
5863 emit_cmp_and_jump_insns (index, expand_expr (node->high, NULL_RTX,
5865 GT, NULL_RTX, mode, unsignedp, 0,
5866 label_rtx (node->right->code_label));
5867 emit_case_nodes (index, node->left, default_label, index_type);
5870 else if (node_is_bounded (node->left, index_type))
5872 emit_cmp_and_jump_insns (index, expand_expr (node->high, NULL_RTX,
5874 LT, NULL_RTX, mode, unsignedp, 0,
5875 label_rtx (node->left->code_label));
5876 emit_case_nodes (index, node->right, default_label, index_type);
5881 /* Neither node is bounded. First distinguish the two sides;
5882 then emit the code for one side at a time. */
5885 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
5887 /* See if the value is on the right. */
5888 emit_cmp_and_jump_insns (index, expand_expr (node->high, NULL_RTX,
5890 GT, NULL_RTX, mode, unsignedp, 0,
5891 label_rtx (test_label));
5893 /* Value must be on the left.
5894 Handle the left-hand subtree. */
5895 emit_case_nodes (index, node->left, default_label, index_type);
5896 /* If left-hand subtree does nothing,
5898 emit_jump_if_reachable (default_label);
5900 /* Code branches here for the right-hand subtree. */
5901 expand_label (test_label);
5902 emit_case_nodes (index, node->right, default_label, index_type);
5906 else if (node->right != 0 && node->left == 0)
5908 /* Here we have a right child but no left so we issue conditional
5909 branch to default and process the right child.
5911 Omit the conditional branch to default if we it avoid only one
5912 right child; it costs too much space to save so little time. */
5914 if (node->right->right || node->right->left
5915 || !tree_int_cst_equal (node->right->low, node->right->high))
5917 if (!node_has_low_bound (node, index_type))
5919 emit_cmp_and_jump_insns (index, expand_expr (node->high,
5922 LT, NULL_RTX, mode, unsignedp, 0,
5926 emit_case_nodes (index, node->right, default_label, index_type);
5929 /* We cannot process node->right normally
5930 since we haven't ruled out the numbers less than
5931 this node's value. So handle node->right explicitly. */
5932 do_jump_if_equal (index,
5933 expand_expr (node->right->low, NULL_RTX,
5935 label_rtx (node->right->code_label), unsignedp);
5938 else if (node->right == 0 && node->left != 0)
5940 /* Just one subtree, on the left. */
5942 #if 0 /* The following code and comment were formerly part
5943 of the condition here, but they didn't work
5944 and I don't understand what the idea was. -- rms. */
5945 /* If our "most probable entry" is less probable
5946 than the default label, emit a jump to
5947 the default label using condition codes
5948 already lying around. With no right branch,
5949 a branch-greater-than will get us to the default
5952 && cost_table[TREE_INT_CST_LOW (node->high)] < 12)
5955 if (node->left->left || node->left->right
5956 || !tree_int_cst_equal (node->left->low, node->left->high))
5958 if (!node_has_high_bound (node, index_type))
5960 emit_cmp_and_jump_insns (index, expand_expr (node->high,
5963 GT, NULL_RTX, mode, unsignedp, 0,
5967 emit_case_nodes (index, node->left, default_label, index_type);
5970 /* We cannot process node->left normally
5971 since we haven't ruled out the numbers less than
5972 this node's value. So handle node->left explicitly. */
5973 do_jump_if_equal (index,
5974 expand_expr (node->left->low, NULL_RTX,
5976 label_rtx (node->left->code_label), unsignedp);
5981 /* Node is a range. These cases are very similar to those for a single
5982 value, except that we do not start by testing whether this node
5983 is the one to branch to. */
5985 if (node->right != 0 && node->left != 0)
5987 /* Node has subtrees on both sides.
5988 If the right-hand subtree is bounded,
5989 test for it first, since we can go straight there.
5990 Otherwise, we need to make a branch in the control structure,
5991 then handle the two subtrees. */
5992 tree test_label = 0;
5995 if (node_is_bounded (node->right, index_type))
5996 /* Right hand node is fully bounded so we can eliminate any
5997 testing and branch directly to the target code. */
5998 emit_cmp_and_jump_insns (index, expand_expr (node->high, NULL_RTX,
6000 GT, NULL_RTX, mode, unsignedp, 0,
6001 label_rtx (node->right->code_label));
6004 /* Right hand node requires testing.
6005 Branch to a label where we will handle it later. */
6007 test_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
6008 emit_cmp_and_jump_insns (index, expand_expr (node->high, NULL_RTX,
6010 GT, NULL_RTX, mode, unsignedp, 0,
6011 label_rtx (test_label));
6014 /* Value belongs to this node or to the left-hand subtree. */
6016 emit_cmp_and_jump_insns (index, expand_expr (node->low, NULL_RTX,
6018 GE, NULL_RTX, mode, unsignedp, 0,
6019 label_rtx (node->code_label));
6021 /* Handle the left-hand subtree. */
6022 emit_case_nodes (index, node->left, default_label, index_type);
6024 /* If right node had to be handled later, do that now. */
6028 /* If the left-hand subtree fell through,
6029 don't let it fall into the right-hand subtree. */
6030 emit_jump_if_reachable (default_label);
6032 expand_label (test_label);
6033 emit_case_nodes (index, node->right, default_label, index_type);
6037 else if (node->right != 0 && node->left == 0)
6039 /* Deal with values to the left of this node,
6040 if they are possible. */
6041 if (!node_has_low_bound (node, index_type))
6043 emit_cmp_and_jump_insns (index, expand_expr (node->low, NULL_RTX,
6045 LT, NULL_RTX, mode, unsignedp, 0,
6049 /* Value belongs to this node or to the right-hand subtree. */
6051 emit_cmp_and_jump_insns (index, expand_expr (node->high, NULL_RTX,
6053 LE, NULL_RTX, mode, unsignedp, 0,
6054 label_rtx (node->code_label));
6056 emit_case_nodes (index, node->right, default_label, index_type);
6059 else if (node->right == 0 && node->left != 0)
6061 /* Deal with values to the right of this node,
6062 if they are possible. */
6063 if (!node_has_high_bound (node, index_type))
6065 emit_cmp_and_jump_insns (index, expand_expr (node->high, NULL_RTX,
6067 GT, NULL_RTX, mode, unsignedp, 0,
6071 /* Value belongs to this node or to the left-hand subtree. */
6073 emit_cmp_and_jump_insns (index, expand_expr (node->low, NULL_RTX,
6075 GE, NULL_RTX, mode, unsignedp, 0,
6076 label_rtx (node->code_label));
6078 emit_case_nodes (index, node->left, default_label, index_type);
6083 /* Node has no children so we check low and high bounds to remove
6084 redundant tests. Only one of the bounds can exist,
6085 since otherwise this node is bounded--a case tested already. */
6087 if (!node_has_high_bound (node, index_type))
6089 emit_cmp_and_jump_insns (index, expand_expr (node->high, NULL_RTX,
6091 GT, NULL_RTX, mode, unsignedp, 0,
6095 if (!node_has_low_bound (node, index_type))
6097 emit_cmp_and_jump_insns (index, expand_expr (node->low, NULL_RTX,
6099 LT, NULL_RTX, mode, unsignedp, 0,
6103 emit_jump (label_rtx (node->code_label));
6108 /* These routines are used by the loop unrolling code. They copy BLOCK trees
6109 so that the debugging info will be correct for the unrolled loop. */
6111 /* Indexed by block number, contains a pointer to the N'th block node.
6113 Allocated by the call to identify_blocks, then released after the call
6114 to reorder_blocks in the function unroll_block_trees. */
6116 static tree *block_vector;
6119 find_loop_tree_blocks ()
6121 tree block = DECL_INITIAL (current_function_decl);
6123 block_vector = identify_blocks (block, get_insns ());
6127 unroll_block_trees ()
6129 tree block = DECL_INITIAL (current_function_decl);
6131 reorder_blocks (block_vector, block, get_insns ());
6133 /* Release any memory allocated by identify_blocks. */
6135 free (block_vector);