1 /* Expands front end tree to back end RTL for GNU C-Compiler
2 Copyright (C) 1987, 88, 89, 92-6, 1997 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. */
46 #include "insn-flags.h"
47 #include "insn-config.h"
48 #include "insn-codes.h"
50 #include "hard-reg-set.h"
57 #include "bc-typecd.h"
58 #include "bc-opcode.h"
62 #define obstack_chunk_alloc xmalloc
63 #define obstack_chunk_free free
64 struct obstack stmt_obstack;
66 /* Filename and line number of last line-number note,
67 whether we actually emitted it or not. */
71 /* Nonzero if within a ({...}) grouping, in which case we must
72 always compute a value for each expr-stmt in case it is the last one. */
74 int expr_stmts_for_value;
76 /* Each time we expand an expression-statement,
77 record the expr's type and its RTL value here. */
79 static tree last_expr_type;
80 static rtx last_expr_value;
82 /* Each time we expand the end of a binding contour (in `expand_end_bindings')
83 and we emit a new NOTE_INSN_BLOCK_END note, we save a pointer to it here.
84 This is used by the `remember_end_note' function to record the endpoint
85 of each generated block in its associated BLOCK node. */
87 static rtx last_block_end_note;
89 /* Number of binding contours started so far in this function. */
91 int block_start_count;
93 /* Nonzero if function being compiled needs to
94 return the address of where it has put a structure value. */
96 extern int current_function_returns_pcc_struct;
98 /* Label that will go on parm cleanup code, if any.
99 Jumping to this label runs cleanup code for parameters, if
100 such code must be run. Following this code is the logical return label. */
102 extern rtx cleanup_label;
104 /* Label that will go on function epilogue.
105 Jumping to this label serves as a "return" instruction
106 on machines which require execution of the epilogue on all returns. */
108 extern rtx return_label;
110 /* Offset to end of allocated area of stack frame.
111 If stack grows down, this is the address of the last stack slot allocated.
112 If stack grows up, this is the address for the next slot. */
113 extern int frame_offset;
115 /* Label to jump back to for tail recursion, or 0 if we have
116 not yet needed one for this function. */
117 extern rtx tail_recursion_label;
119 /* Place after which to insert the tail_recursion_label if we need one. */
120 extern rtx tail_recursion_reentry;
122 /* Location at which to save the argument pointer if it will need to be
123 referenced. There are two cases where this is done: if nonlocal gotos
124 exist, or if vars whose is an offset from the argument pointer will be
125 needed by inner routines. */
127 extern rtx arg_pointer_save_area;
129 /* Chain of all RTL_EXPRs that have insns in them. */
130 extern tree rtl_expr_chain;
132 /* Stack allocation level in which temporaries for TARGET_EXPRs live. */
133 extern int target_temp_slot_level;
135 extern int temp_slot_level;
137 /* Functions and data structures for expanding case statements. */
139 /* Case label structure, used to hold info on labels within case
140 statements. We handle "range" labels; for a single-value label
141 as in C, the high and low limits are the same.
143 An AVL tree of case nodes is initially created, and later transformed
144 to a list linked via the RIGHT fields in the nodes. Nodes with
145 higher case values are later in the list.
147 Switch statements can be output in one of two forms. A branch table
148 is used if there are more than a few labels and the labels are dense
149 within the range between the smallest and largest case value. If a
150 branch table is used, no further manipulations are done with the case
153 The alternative to the use of a branch table is to generate a series
154 of compare and jump insns. When that is done, we use the LEFT, RIGHT,
155 and PARENT fields to hold a binary tree. Initially the tree is
156 totally unbalanced, with everything on the right. We balance the tree
157 with nodes on the left having lower case values than the parent
158 and nodes on the right having higher values. We then output the tree
163 struct case_node *left; /* Left son in binary tree */
164 struct case_node *right; /* Right son in binary tree; also node chain */
165 struct case_node *parent; /* Parent of node in binary tree */
166 tree low; /* Lowest index value for this label */
167 tree high; /* Highest index value for this label */
168 tree code_label; /* Label to jump to when node matches */
172 typedef struct case_node case_node;
173 typedef struct case_node *case_node_ptr;
175 /* These are used by estimate_case_costs and balance_case_nodes. */
177 /* This must be a signed type, and non-ANSI compilers lack signed char. */
178 static short *cost_table;
179 static int use_cost_table;
181 /* Stack of control and binding constructs we are currently inside.
183 These constructs begin when you call `expand_start_WHATEVER'
184 and end when you call `expand_end_WHATEVER'. This stack records
185 info about how the construct began that tells the end-function
186 what to do. It also may provide information about the construct
187 to alter the behavior of other constructs within the body.
188 For example, they may affect the behavior of C `break' and `continue'.
190 Each construct gets one `struct nesting' object.
191 All of these objects are chained through the `all' field.
192 `nesting_stack' points to the first object (innermost construct).
193 The position of an entry on `nesting_stack' is in its `depth' field.
195 Each type of construct has its own individual stack.
196 For example, loops have `loop_stack'. Each object points to the
197 next object of the same type through the `next' field.
199 Some constructs are visible to `break' exit-statements and others
200 are not. Which constructs are visible depends on the language.
201 Therefore, the data structure allows each construct to be visible
202 or not, according to the args given when the construct is started.
203 The construct is visible if the `exit_label' field is non-null.
204 In that case, the value should be a CODE_LABEL rtx. */
209 struct nesting *next;
214 /* For conds (if-then and if-then-else statements). */
217 /* Label for the end of the if construct.
218 There is none if EXITFLAG was not set
219 and no `else' has been seen yet. */
221 /* Label for the end of this alternative.
222 This may be the end of the if or the next else/elseif. */
228 /* Label at the top of the loop; place to loop back to. */
230 /* Label at the end of the whole construct. */
232 /* Label before a jump that branches to the end of the whole
233 construct. This is where destructors go if any. */
235 /* Label for `continue' statement to jump to;
236 this is in front of the stepper of the loop. */
239 /* For variable binding contours. */
242 /* Sequence number of this binding contour within the function,
243 in order of entry. */
244 int block_start_count;
245 /* Nonzero => value to restore stack to on exit. Complemented by
246 bc_stack_level (see below) when generating bytecodes. */
248 /* The NOTE that starts this contour.
249 Used by expand_goto to check whether the destination
250 is within each contour or not. */
252 /* Innermost containing binding contour that has a stack level. */
253 struct nesting *innermost_stack_block;
254 /* List of cleanups to be run on exit from this contour.
255 This is a list of expressions to be evaluated.
256 The TREE_PURPOSE of each link is the ..._DECL node
257 which the cleanup pertains to. */
259 /* List of cleanup-lists of blocks containing this block,
260 as they were at the locus where this block appears.
261 There is an element for each containing block,
262 ordered innermost containing block first.
263 The tail of this list can be 0,
264 if all remaining elements would be empty lists.
265 The element's TREE_VALUE is the cleanup-list of that block,
266 which may be null. */
268 /* Chain of labels defined inside this binding contour.
269 For contours that have stack levels or cleanups. */
270 struct label_chain *label_chain;
271 /* Number of function calls seen, as of start of this block. */
272 int function_call_count;
273 /* Bytecode specific: stack level to restore stack to on exit. */
275 /* Nonzero if this is associated with a EH region. */
276 int exception_region;
277 /* The saved target_temp_slot_level from our outer block.
278 We may reset target_temp_slot_level to be the level of
279 this block, if that is done, target_temp_slot_level
280 reverts to the saved target_temp_slot_level at the very
282 int target_temp_slot_level;
283 /* True if we are currently emitting insns in an area of
284 output code that is controlled by a conditional
285 expression. This is used by the cleanup handling code to
286 generate conditional cleanup actions. */
287 int conditional_code;
288 /* A place to move the start of the exception region for any
289 of the conditional cleanups, must be at the end or after
290 the start of the last unconditional cleanup, and before any
291 conditional branch points. */
292 rtx last_unconditional_cleanup;
293 /* When in a conditional context, this is the specific
294 cleanup list associated with last_unconditional_cleanup,
295 where we place the conditionalized cleanups. */
298 /* For switch (C) or case (Pascal) statements,
299 and also for dummies (see `expand_start_case_dummy'). */
302 /* The insn after which the case dispatch should finally
303 be emitted. Zero for a dummy. */
305 /* For bytecodes, the case table is in-lined right in the code.
306 A label is needed for skipping over this block. It is only
307 used when generating bytecodes. */
309 /* A list of case labels; it is first built as an AVL tree.
310 During expand_end_case, this is converted to a list, and may be
311 rearranged into a nearly balanced binary tree. */
312 struct case_node *case_list;
313 /* Label to jump to if no case matches. */
315 /* The expression to be dispatched on. */
317 /* Type that INDEX_EXPR should be converted to. */
319 /* Number of range exprs in case statement. */
321 /* Name of this kind of statement, for warnings. */
323 /* Nonzero if a case label has been seen in this case stmt. */
329 /* Chain of all pending binding contours. */
330 struct nesting *block_stack;
332 /* If any new stacks are added here, add them to POPSTACKS too. */
334 /* Chain of all pending binding contours that restore stack levels
336 struct nesting *stack_block_stack;
338 /* Chain of all pending conditional statements. */
339 struct nesting *cond_stack;
341 /* Chain of all pending loops. */
342 struct nesting *loop_stack;
344 /* Chain of all pending case or switch statements. */
345 struct nesting *case_stack;
347 /* Separate chain including all of the above,
348 chained through the `all' field. */
349 struct nesting *nesting_stack;
351 /* Number of entries on nesting_stack now. */
354 /* Allocate and return a new `struct nesting'. */
356 #define ALLOC_NESTING() \
357 (struct nesting *) obstack_alloc (&stmt_obstack, sizeof (struct nesting))
359 /* Pop the nesting stack element by element until we pop off
360 the element which is at the top of STACK.
361 Update all the other stacks, popping off elements from them
362 as we pop them from nesting_stack. */
364 #define POPSTACK(STACK) \
365 do { struct nesting *target = STACK; \
366 struct nesting *this; \
367 do { this = nesting_stack; \
368 if (loop_stack == this) \
369 loop_stack = loop_stack->next; \
370 if (cond_stack == this) \
371 cond_stack = cond_stack->next; \
372 if (block_stack == this) \
373 block_stack = block_stack->next; \
374 if (stack_block_stack == this) \
375 stack_block_stack = stack_block_stack->next; \
376 if (case_stack == this) \
377 case_stack = case_stack->next; \
378 nesting_depth = nesting_stack->depth - 1; \
379 nesting_stack = this->all; \
380 obstack_free (&stmt_obstack, this); } \
381 while (this != target); } while (0)
383 /* In some cases it is impossible to generate code for a forward goto
384 until the label definition is seen. This happens when it may be necessary
385 for the goto to reset the stack pointer: we don't yet know how to do that.
386 So expand_goto puts an entry on this fixup list.
387 Each time a binding contour that resets the stack is exited,
389 If the target label has now been defined, we can insert the proper code. */
393 /* Points to following fixup. */
394 struct goto_fixup *next;
395 /* Points to the insn before the jump insn.
396 If more code must be inserted, it goes after this insn. */
398 /* The LABEL_DECL that this jump is jumping to, or 0
399 for break, continue or return. */
401 /* The BLOCK for the place where this goto was found. */
403 /* The CODE_LABEL rtx that this is jumping to. */
405 /* Number of binding contours started in current function
406 before the label reference. */
407 int block_start_count;
408 /* The outermost stack level that should be restored for this jump.
409 Each time a binding contour that resets the stack is exited,
410 if the target label is *not* yet defined, this slot is updated. */
412 /* List of lists of cleanup expressions to be run by this goto.
413 There is one element for each block that this goto is within.
414 The tail of this list can be 0,
415 if all remaining elements would be empty.
416 The TREE_VALUE contains the cleanup list of that block as of the
417 time this goto was seen.
418 The TREE_ADDRESSABLE flag is 1 for a block that has been exited. */
419 tree cleanup_list_list;
421 /* Bytecode specific members follow */
423 /* The label that this jump is jumping to, or 0 for break, continue
425 struct bc_label *bc_target;
427 /* The label we use for the fixup patch */
428 struct bc_label *label;
430 /* True (non-0) if fixup has been handled */
433 /* Like stack_level above, except refers to the interpreter stack */
437 static struct goto_fixup *goto_fixup_chain;
439 /* Within any binding contour that must restore a stack level,
440 all labels are recorded with a chain of these structures. */
444 /* Points to following fixup. */
445 struct label_chain *next;
448 static void expand_goto_internal PROTO((tree, rtx, rtx));
449 static void bc_expand_goto_internal PROTO((enum bytecode_opcode,
450 struct bc_label *, tree));
451 static int expand_fixup PROTO((tree, rtx, rtx));
452 static void bc_expand_fixup PROTO((enum bytecode_opcode,
453 struct bc_label *, int));
454 static void fixup_gotos PROTO((struct nesting *, rtx, tree,
456 static void bc_fixup_gotos PROTO((struct nesting *, int, tree,
458 static void bc_expand_start_cond PROTO((tree, int));
459 static void bc_expand_end_cond PROTO((void));
460 static void bc_expand_start_else PROTO((void));
461 static void bc_expand_end_loop PROTO((void));
462 static void bc_expand_end_bindings PROTO((tree, int, int));
463 static void bc_expand_decl PROTO((tree, tree));
464 static void bc_expand_variable_local_init PROTO((tree));
465 static void bc_expand_decl_init PROTO((tree));
466 static void expand_null_return_1 PROTO((rtx, int));
467 static void expand_value_return PROTO((rtx));
468 static int tail_recursion_args PROTO((tree, tree));
469 static void expand_cleanups PROTO((tree, tree, int, int));
470 static void bc_expand_start_case PROTO((struct nesting *, tree,
472 static int bc_pushcase PROTO((tree, tree));
473 static void bc_check_for_full_enumeration_handling PROTO((tree));
474 static void bc_expand_end_case PROTO((tree));
475 static void do_jump_if_equal PROTO((rtx, rtx, rtx, int));
476 static int estimate_case_costs PROTO((case_node_ptr));
477 static void group_case_nodes PROTO((case_node_ptr));
478 static void balance_case_nodes PROTO((case_node_ptr *,
480 static int node_has_low_bound PROTO((case_node_ptr, tree));
481 static int node_has_high_bound PROTO((case_node_ptr, tree));
482 static int node_is_bounded PROTO((case_node_ptr, tree));
483 static void emit_jump_if_reachable PROTO((rtx));
484 static void emit_case_nodes PROTO((rtx, case_node_ptr, rtx, tree));
485 static int add_case_node PROTO((tree, tree, tree, tree *));
486 static struct case_node *case_tree2list PROTO((case_node *, case_node *));
488 extern rtx bc_allocate_local ();
489 extern rtx bc_allocate_variable_array ();
494 gcc_obstack_init (&stmt_obstack);
499 init_stmt_for_function ()
501 /* We are not currently within any block, conditional, loop or case. */
503 stack_block_stack = 0;
510 block_start_count = 0;
512 /* No gotos have been expanded yet. */
513 goto_fixup_chain = 0;
515 /* We are not processing a ({...}) grouping. */
516 expr_stmts_for_value = 0;
519 init_eh_for_function ();
526 p->block_stack = block_stack;
527 p->stack_block_stack = stack_block_stack;
528 p->cond_stack = cond_stack;
529 p->loop_stack = loop_stack;
530 p->case_stack = case_stack;
531 p->nesting_stack = nesting_stack;
532 p->nesting_depth = nesting_depth;
533 p->block_start_count = block_start_count;
534 p->last_expr_type = last_expr_type;
535 p->last_expr_value = last_expr_value;
536 p->expr_stmts_for_value = expr_stmts_for_value;
537 p->emit_filename = emit_filename;
538 p->emit_lineno = emit_lineno;
539 p->goto_fixup_chain = goto_fixup_chain;
544 restore_stmt_status (p)
547 block_stack = p->block_stack;
548 stack_block_stack = p->stack_block_stack;
549 cond_stack = p->cond_stack;
550 loop_stack = p->loop_stack;
551 case_stack = p->case_stack;
552 nesting_stack = p->nesting_stack;
553 nesting_depth = p->nesting_depth;
554 block_start_count = p->block_start_count;
555 last_expr_type = p->last_expr_type;
556 last_expr_value = p->last_expr_value;
557 expr_stmts_for_value = p->expr_stmts_for_value;
558 emit_filename = p->emit_filename;
559 emit_lineno = p->emit_lineno;
560 goto_fixup_chain = p->goto_fixup_chain;
561 restore_eh_status (p);
564 /* Emit a no-op instruction. */
571 if (!output_bytecode)
573 last_insn = get_last_insn ();
575 && (GET_CODE (last_insn) == CODE_LABEL
576 || (GET_CODE (last_insn) == NOTE
577 && prev_real_insn (last_insn) == 0)))
578 emit_insn (gen_nop ());
582 /* Return the rtx-label that corresponds to a LABEL_DECL,
583 creating it if necessary. */
589 if (TREE_CODE (label) != LABEL_DECL)
592 if (DECL_RTL (label))
593 return DECL_RTL (label);
595 return DECL_RTL (label) = gen_label_rtx ();
598 /* Add an unconditional jump to LABEL as the next sequential instruction. */
604 do_pending_stack_adjust ();
605 emit_jump_insn (gen_jump (label));
609 /* Emit code to jump to the address
610 specified by the pointer expression EXP. */
613 expand_computed_goto (exp)
618 bc_expand_expr (exp);
619 bc_emit_instruction (jumpP);
623 rtx x = expand_expr (exp, NULL_RTX, VOIDmode, 0);
625 #ifdef POINTERS_EXTEND_UNSIGNED
626 x = convert_memory_address (Pmode, x);
630 do_pending_stack_adjust ();
631 emit_indirect_jump (x);
635 /* Handle goto statements and the labels that they can go to. */
637 /* Specify the location in the RTL code of a label LABEL,
638 which is a LABEL_DECL tree node.
640 This is used for the kind of label that the user can jump to with a
641 goto statement, and for alternatives of a switch or case statement.
642 RTL labels generated for loops and conditionals don't go through here;
643 they are generated directly at the RTL level, by other functions below.
645 Note that this has nothing to do with defining label *names*.
646 Languages vary in how they do that and what that even means. */
652 struct label_chain *p;
656 if (! DECL_RTL (label))
657 DECL_RTL (label) = bc_gen_rtx ((char *) 0, 0, bc_get_bytecode_label ());
658 if (! bc_emit_bytecode_labeldef (BYTECODE_BC_LABEL (DECL_RTL (label))))
659 error ("multiply defined label");
663 do_pending_stack_adjust ();
664 emit_label (label_rtx (label));
665 if (DECL_NAME (label))
666 LABEL_NAME (DECL_RTL (label)) = IDENTIFIER_POINTER (DECL_NAME (label));
668 if (stack_block_stack != 0)
670 p = (struct label_chain *) oballoc (sizeof (struct label_chain));
671 p->next = stack_block_stack->data.block.label_chain;
672 stack_block_stack->data.block.label_chain = p;
677 /* Declare that LABEL (a LABEL_DECL) may be used for nonlocal gotos
678 from nested functions. */
681 declare_nonlocal_label (label)
684 nonlocal_labels = tree_cons (NULL_TREE, label, nonlocal_labels);
685 LABEL_PRESERVE_P (label_rtx (label)) = 1;
686 if (nonlocal_goto_handler_slot == 0)
688 nonlocal_goto_handler_slot
689 = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
690 emit_stack_save (SAVE_NONLOCAL,
691 &nonlocal_goto_stack_level,
692 PREV_INSN (tail_recursion_reentry));
696 /* Generate RTL code for a `goto' statement with target label LABEL.
697 LABEL should be a LABEL_DECL tree node that was or will later be
698 defined with `expand_label'. */
708 expand_goto_internal (label, label_rtx (label), NULL_RTX);
712 /* Check for a nonlocal goto to a containing function. */
713 context = decl_function_context (label);
714 if (context != 0 && context != current_function_decl)
716 struct function *p = find_function_data (context);
717 rtx label_ref = gen_rtx (LABEL_REF, Pmode, label_rtx (label));
720 p->has_nonlocal_label = 1;
721 current_function_has_nonlocal_goto = 1;
722 LABEL_REF_NONLOCAL_P (label_ref) = 1;
724 /* Copy the rtl for the slots so that they won't be shared in
725 case the virtual stack vars register gets instantiated differently
726 in the parent than in the child. */
728 #if HAVE_nonlocal_goto
729 if (HAVE_nonlocal_goto)
730 emit_insn (gen_nonlocal_goto (lookup_static_chain (label),
731 copy_rtx (p->nonlocal_goto_handler_slot),
732 copy_rtx (p->nonlocal_goto_stack_level),
739 /* Restore frame pointer for containing function.
740 This sets the actual hard register used for the frame pointer
741 to the location of the function's incoming static chain info.
742 The non-local goto handler will then adjust it to contain the
743 proper value and reload the argument pointer, if needed. */
744 emit_move_insn (hard_frame_pointer_rtx, lookup_static_chain (label));
746 /* We have now loaded the frame pointer hardware register with
747 the address of that corresponds to the start of the virtual
748 stack vars. So replace virtual_stack_vars_rtx in all
749 addresses we use with stack_pointer_rtx. */
751 /* Get addr of containing function's current nonlocal goto handler,
752 which will do any cleanups and then jump to the label. */
753 addr = copy_rtx (p->nonlocal_goto_handler_slot);
754 temp = copy_to_reg (replace_rtx (addr, virtual_stack_vars_rtx,
755 hard_frame_pointer_rtx));
757 /* Restore the stack pointer. Note this uses fp just restored. */
758 addr = p->nonlocal_goto_stack_level;
760 addr = replace_rtx (copy_rtx (addr),
761 virtual_stack_vars_rtx,
762 hard_frame_pointer_rtx);
764 emit_stack_restore (SAVE_NONLOCAL, addr, NULL_RTX);
766 /* Put in the static chain register the nonlocal label address. */
767 emit_move_insn (static_chain_rtx, label_ref);
768 /* USE of hard_frame_pointer_rtx added for consistency; not clear if
770 emit_insn (gen_rtx (USE, VOIDmode, hard_frame_pointer_rtx));
771 emit_insn (gen_rtx (USE, VOIDmode, stack_pointer_rtx));
772 emit_insn (gen_rtx (USE, VOIDmode, static_chain_rtx));
773 emit_indirect_jump (temp);
777 expand_goto_internal (label, label_rtx (label), NULL_RTX);
780 /* Generate RTL code for a `goto' statement with target label BODY.
781 LABEL should be a LABEL_REF.
782 LAST_INSN, if non-0, is the rtx we should consider as the last
783 insn emitted (for the purposes of cleaning up a return). */
786 expand_goto_internal (body, label, last_insn)
791 struct nesting *block;
794 /* NOTICE! If a bytecode instruction other than `jump' is needed,
795 then the caller has to call bc_expand_goto_internal()
796 directly. This is rather an exceptional case, and there aren't
797 that many places where this is necessary. */
800 expand_goto_internal (body, label, last_insn);
804 if (GET_CODE (label) != CODE_LABEL)
807 /* If label has already been defined, we can tell now
808 whether and how we must alter the stack level. */
810 if (PREV_INSN (label) != 0)
812 /* Find the innermost pending block that contains the label.
813 (Check containment by comparing insn-uids.)
814 Then restore the outermost stack level within that block,
815 and do cleanups of all blocks contained in it. */
816 for (block = block_stack; block; block = block->next)
818 if (INSN_UID (block->data.block.first_insn) < INSN_UID (label))
820 if (block->data.block.stack_level != 0)
821 stack_level = block->data.block.stack_level;
822 /* Execute the cleanups for blocks we are exiting. */
823 if (block->data.block.cleanups != 0)
825 expand_cleanups (block->data.block.cleanups, NULL_TREE, 1, 1);
826 do_pending_stack_adjust ();
832 /* Ensure stack adjust isn't done by emit_jump, as this
833 would clobber the stack pointer. This one should be
834 deleted as dead by flow. */
835 clear_pending_stack_adjust ();
836 do_pending_stack_adjust ();
837 emit_stack_restore (SAVE_BLOCK, stack_level, NULL_RTX);
840 if (body != 0 && DECL_TOO_LATE (body))
841 error ("jump to `%s' invalidly jumps into binding contour",
842 IDENTIFIER_POINTER (DECL_NAME (body)));
844 /* Label not yet defined: may need to put this goto
845 on the fixup list. */
846 else if (! expand_fixup (body, label, last_insn))
848 /* No fixup needed. Record that the label is the target
849 of at least one goto that has no fixup. */
851 TREE_ADDRESSABLE (body) = 1;
857 /* Generate a jump with OPCODE to the given bytecode LABEL which is
858 found within BODY. */
861 bc_expand_goto_internal (opcode, label, body)
862 enum bytecode_opcode opcode;
863 struct bc_label *label;
866 struct nesting *block;
867 int stack_level = -1;
869 /* If the label is defined, adjust the stack as necessary.
870 If it's not defined, we have to push the reference on the
876 /* Find the innermost pending block that contains the label.
877 (Check containment by comparing bytecode uids.) Then restore the
878 outermost stack level within that block. */
880 for (block = block_stack; block; block = block->next)
882 if (BYTECODE_BC_LABEL (block->data.block.first_insn)->uid < label->uid)
884 if (block->data.block.bc_stack_level)
885 stack_level = block->data.block.bc_stack_level;
887 /* Execute the cleanups for blocks we are exiting. */
888 if (block->data.block.cleanups != 0)
890 expand_cleanups (block->data.block.cleanups, NULL_TREE, 1, 1);
891 do_pending_stack_adjust ();
895 /* Restore the stack level. If we need to adjust the stack, we
896 must do so after the jump, since the jump may depend on
897 what's on the stack. Thus, any stack-modifying conditional
898 jumps (these are the only ones that rely on what's on the
899 stack) go into the fixup list. */
902 && stack_depth != stack_level
905 bc_expand_fixup (opcode, label, stack_level);
908 if (stack_level >= 0)
909 bc_adjust_stack (stack_depth - stack_level);
911 if (body && DECL_BIT_FIELD (body))
912 error ("jump to `%s' invalidly jumps into binding contour",
913 IDENTIFIER_POINTER (DECL_NAME (body)));
915 /* Emit immediate jump */
916 bc_emit_bytecode (opcode);
917 bc_emit_bytecode_labelref (label);
919 #ifdef DEBUG_PRINT_CODE
920 fputc ('\n', stderr);
925 /* Put goto in the fixup list */
926 bc_expand_fixup (opcode, label, stack_level);
929 /* Generate if necessary a fixup for a goto
930 whose target label in tree structure (if any) is TREE_LABEL
931 and whose target in rtl is RTL_LABEL.
933 If LAST_INSN is nonzero, we pretend that the jump appears
934 after insn LAST_INSN instead of at the current point in the insn stream.
936 The fixup will be used later to insert insns just before the goto.
937 Those insns will restore the stack level as appropriate for the
938 target label, and will (in the case of C++) also invoke any object
939 destructors which have to be invoked when we exit the scopes which
940 are exited by the goto.
942 Value is nonzero if a fixup is made. */
945 expand_fixup (tree_label, rtl_label, last_insn)
950 struct nesting *block, *end_block;
952 /* See if we can recognize which block the label will be output in.
953 This is possible in some very common cases.
954 If we succeed, set END_BLOCK to that block.
955 Otherwise, set it to 0. */
958 && (rtl_label == cond_stack->data.cond.endif_label
959 || rtl_label == cond_stack->data.cond.next_label))
960 end_block = cond_stack;
961 /* If we are in a loop, recognize certain labels which
962 are likely targets. This reduces the number of fixups
963 we need to create. */
965 && (rtl_label == loop_stack->data.loop.start_label
966 || rtl_label == loop_stack->data.loop.end_label
967 || rtl_label == loop_stack->data.loop.continue_label))
968 end_block = loop_stack;
972 /* Now set END_BLOCK to the binding level to which we will return. */
976 struct nesting *next_block = end_block->all;
979 /* First see if the END_BLOCK is inside the innermost binding level.
980 If so, then no cleanups or stack levels are relevant. */
981 while (next_block && next_block != block)
982 next_block = next_block->all;
987 /* Otherwise, set END_BLOCK to the innermost binding level
988 which is outside the relevant control-structure nesting. */
989 next_block = block_stack->next;
990 for (block = block_stack; block != end_block; block = block->all)
991 if (block == next_block)
992 next_block = next_block->next;
993 end_block = next_block;
996 /* Does any containing block have a stack level or cleanups?
997 If not, no fixup is needed, and that is the normal case
998 (the only case, for standard C). */
999 for (block = block_stack; block != end_block; block = block->next)
1000 if (block->data.block.stack_level != 0
1001 || block->data.block.cleanups != 0)
1004 if (block != end_block)
1006 /* Ok, a fixup is needed. Add a fixup to the list of such. */
1007 struct goto_fixup *fixup
1008 = (struct goto_fixup *) oballoc (sizeof (struct goto_fixup));
1009 /* In case an old stack level is restored, make sure that comes
1010 after any pending stack adjust. */
1011 /* ?? If the fixup isn't to come at the present position,
1012 doing the stack adjust here isn't useful. Doing it with our
1013 settings at that location isn't useful either. Let's hope
1016 do_pending_stack_adjust ();
1017 fixup->target = tree_label;
1018 fixup->target_rtl = rtl_label;
1020 /* Create a BLOCK node and a corresponding matched set of
1021 NOTE_INSN_BEGIN_BLOCK and NOTE_INSN_END_BLOCK notes at
1022 this point. The notes will encapsulate any and all fixup
1023 code which we might later insert at this point in the insn
1024 stream. Also, the BLOCK node will be the parent (i.e. the
1025 `SUPERBLOCK') of any other BLOCK nodes which we might create
1026 later on when we are expanding the fixup code. */
1029 register rtx original_before_jump
1030 = last_insn ? last_insn : get_last_insn ();
1034 fixup->before_jump = emit_note (NULL_PTR, NOTE_INSN_BLOCK_BEG);
1035 last_block_end_note = emit_note (NULL_PTR, NOTE_INSN_BLOCK_END);
1036 fixup->context = poplevel (1, 0, 0); /* Create the BLOCK node now! */
1038 emit_insns_after (fixup->before_jump, original_before_jump);
1041 fixup->block_start_count = block_start_count;
1042 fixup->stack_level = 0;
1043 fixup->cleanup_list_list
1044 = ((block->data.block.outer_cleanups
1045 || block->data.block.cleanups)
1046 ? tree_cons (NULL_TREE, block->data.block.cleanups,
1047 block->data.block.outer_cleanups)
1049 fixup->next = goto_fixup_chain;
1050 goto_fixup_chain = fixup;
1057 /* Generate bytecode jump with OPCODE to a fixup routine that links to LABEL.
1058 Make the fixup restore the stack level to STACK_LEVEL. */
1061 bc_expand_fixup (opcode, label, stack_level)
1062 enum bytecode_opcode opcode;
1063 struct bc_label *label;
1066 struct goto_fixup *fixup
1067 = (struct goto_fixup *) oballoc (sizeof (struct goto_fixup));
1069 fixup->label = bc_get_bytecode_label ();
1070 fixup->bc_target = label;
1071 fixup->bc_stack_level = stack_level;
1072 fixup->bc_handled = FALSE;
1074 fixup->next = goto_fixup_chain;
1075 goto_fixup_chain = fixup;
1077 /* Insert a jump to the fixup code */
1078 bc_emit_bytecode (opcode);
1079 bc_emit_bytecode_labelref (fixup->label);
1081 #ifdef DEBUG_PRINT_CODE
1082 fputc ('\n', stderr);
1086 /* Expand any needed fixups in the outputmost binding level of the
1087 function. FIRST_INSN is the first insn in the function. */
1090 expand_fixups (first_insn)
1093 fixup_gotos (NULL_PTR, NULL_RTX, NULL_TREE, first_insn, 0);
1096 /* When exiting a binding contour, process all pending gotos requiring fixups.
1097 THISBLOCK is the structure that describes the block being exited.
1098 STACK_LEVEL is the rtx for the stack level to restore exiting this contour.
1099 CLEANUP_LIST is a list of expressions to evaluate on exiting this contour.
1100 FIRST_INSN is the insn that began this contour.
1102 Gotos that jump out of this contour must restore the
1103 stack level and do the cleanups before actually jumping.
1105 DONT_JUMP_IN nonzero means report error there is a jump into this
1106 contour from before the beginning of the contour.
1107 This is also done if STACK_LEVEL is nonzero. */
1110 fixup_gotos (thisblock, stack_level, cleanup_list, first_insn, dont_jump_in)
1111 struct nesting *thisblock;
1117 register struct goto_fixup *f, *prev;
1119 if (output_bytecode)
1121 /* ??? The second arg is the bc stack level, which is not the same
1122 as STACK_LEVEL. I have no idea what should go here, so I'll
1124 bc_fixup_gotos (thisblock, 0, cleanup_list, first_insn, dont_jump_in);
1128 /* F is the fixup we are considering; PREV is the previous one. */
1129 /* We run this loop in two passes so that cleanups of exited blocks
1130 are run first, and blocks that are exited are marked so
1133 for (prev = 0, f = goto_fixup_chain; f; prev = f, f = f->next)
1135 /* Test for a fixup that is inactive because it is already handled. */
1136 if (f->before_jump == 0)
1138 /* Delete inactive fixup from the chain, if that is easy to do. */
1140 prev->next = f->next;
1142 /* Has this fixup's target label been defined?
1143 If so, we can finalize it. */
1144 else if (PREV_INSN (f->target_rtl) != 0)
1146 register rtx cleanup_insns;
1148 /* Get the first non-label after the label
1149 this goto jumps to. If that's before this scope begins,
1150 we don't have a jump into the scope. */
1151 rtx after_label = f->target_rtl;
1152 while (after_label != 0 && GET_CODE (after_label) == CODE_LABEL)
1153 after_label = NEXT_INSN (after_label);
1155 /* If this fixup jumped into this contour from before the beginning
1156 of this contour, report an error. */
1157 /* ??? Bug: this does not detect jumping in through intermediate
1158 blocks that have stack levels or cleanups.
1159 It detects only a problem with the innermost block
1160 around the label. */
1162 && (dont_jump_in || stack_level || cleanup_list)
1163 /* If AFTER_LABEL is 0, it means the jump goes to the end
1164 of the rtl, which means it jumps into this scope. */
1165 && (after_label == 0
1166 || INSN_UID (first_insn) < INSN_UID (after_label))
1167 && INSN_UID (first_insn) > INSN_UID (f->before_jump)
1168 && ! DECL_ERROR_ISSUED (f->target))
1170 error_with_decl (f->target,
1171 "label `%s' used before containing binding contour");
1172 /* Prevent multiple errors for one label. */
1173 DECL_ERROR_ISSUED (f->target) = 1;
1176 /* We will expand the cleanups into a sequence of their own and
1177 then later on we will attach this new sequence to the insn
1178 stream just ahead of the actual jump insn. */
1182 /* Temporarily restore the lexical context where we will
1183 logically be inserting the fixup code. We do this for the
1184 sake of getting the debugging information right. */
1187 set_block (f->context);
1189 /* Expand the cleanups for blocks this jump exits. */
1190 if (f->cleanup_list_list)
1193 for (lists = f->cleanup_list_list; lists; lists = TREE_CHAIN (lists))
1194 /* Marked elements correspond to blocks that have been closed.
1195 Do their cleanups. */
1196 if (TREE_ADDRESSABLE (lists)
1197 && TREE_VALUE (lists) != 0)
1199 expand_cleanups (TREE_VALUE (lists), NULL_TREE, 1, 1);
1200 /* Pop any pushes done in the cleanups,
1201 in case function is about to return. */
1202 do_pending_stack_adjust ();
1206 /* Restore stack level for the biggest contour that this
1207 jump jumps out of. */
1209 emit_stack_restore (SAVE_BLOCK, f->stack_level, f->before_jump);
1211 /* Finish up the sequence containing the insns which implement the
1212 necessary cleanups, and then attach that whole sequence to the
1213 insn stream just ahead of the actual jump insn. Attaching it
1214 at that point insures that any cleanups which are in fact
1215 implicit C++ object destructions (which must be executed upon
1216 leaving the block) appear (to the debugger) to be taking place
1217 in an area of the generated code where the object(s) being
1218 destructed are still "in scope". */
1220 cleanup_insns = get_insns ();
1224 emit_insns_after (cleanup_insns, f->before_jump);
1231 /* For any still-undefined labels, do the cleanups for this block now.
1232 We must do this now since items in the cleanup list may go out
1233 of scope when the block ends. */
1234 for (prev = 0, f = goto_fixup_chain; f; prev = f, f = f->next)
1235 if (f->before_jump != 0
1236 && PREV_INSN (f->target_rtl) == 0
1237 /* Label has still not appeared. If we are exiting a block with
1238 a stack level to restore, that started before the fixup,
1239 mark this stack level as needing restoration
1240 when the fixup is later finalized. */
1242 /* Note: if THISBLOCK == 0 and we have a label that hasn't appeared, it
1243 means the label is undefined. That's erroneous, but possible. */
1244 && (thisblock->data.block.block_start_count
1245 <= f->block_start_count))
1247 tree lists = f->cleanup_list_list;
1250 for (; lists; lists = TREE_CHAIN (lists))
1251 /* If the following elt. corresponds to our containing block
1252 then the elt. must be for this block. */
1253 if (TREE_CHAIN (lists) == thisblock->data.block.outer_cleanups)
1257 set_block (f->context);
1258 expand_cleanups (TREE_VALUE (lists), NULL_TREE, 1, 1);
1259 do_pending_stack_adjust ();
1260 cleanup_insns = get_insns ();
1263 if (cleanup_insns != 0)
1265 = emit_insns_after (cleanup_insns, f->before_jump);
1267 f->cleanup_list_list = TREE_CHAIN (lists);
1271 f->stack_level = stack_level;
1276 /* When exiting a binding contour, process all pending gotos requiring fixups.
1277 Note: STACK_DEPTH is not altered.
1279 The arguments are currently not used in the bytecode compiler, but we may
1280 need them one day for languages other than C.
1282 THISBLOCK is the structure that describes the block being exited.
1283 STACK_LEVEL is the rtx for the stack level to restore exiting this contour.
1284 CLEANUP_LIST is a list of expressions to evaluate on exiting this contour.
1285 FIRST_INSN is the insn that began this contour.
1287 Gotos that jump out of this contour must restore the
1288 stack level and do the cleanups before actually jumping.
1290 DONT_JUMP_IN nonzero means report error there is a jump into this
1291 contour from before the beginning of the contour.
1292 This is also done if STACK_LEVEL is nonzero. */
1295 bc_fixup_gotos (thisblock, stack_level, cleanup_list, first_insn, dont_jump_in)
1296 struct nesting *thisblock;
1302 register struct goto_fixup *f, *prev;
1303 int saved_stack_depth;
1305 /* F is the fixup we are considering; PREV is the previous one. */
1307 for (prev = 0, f = goto_fixup_chain; f; prev = f, f = f->next)
1309 /* Test for a fixup that is inactive because it is already handled. */
1310 if (f->before_jump == 0)
1312 /* Delete inactive fixup from the chain, if that is easy to do. */
1314 prev->next = f->next;
1317 /* Emit code to restore the stack and continue */
1318 bc_emit_bytecode_labeldef (f->label);
1320 /* Save stack_depth across call, since bc_adjust_stack will alter
1321 the perceived stack depth via the instructions generated. */
1323 if (f->bc_stack_level >= 0)
1325 saved_stack_depth = stack_depth;
1326 bc_adjust_stack (stack_depth - f->bc_stack_level);
1327 stack_depth = saved_stack_depth;
1330 bc_emit_bytecode (jump);
1331 bc_emit_bytecode_labelref (f->bc_target);
1333 #ifdef DEBUG_PRINT_CODE
1334 fputc ('\n', stderr);
1338 goto_fixup_chain = NULL;
1341 /* Generate RTL for an asm statement (explicit assembler code).
1342 BODY is a STRING_CST node containing the assembler code text,
1343 or an ADDR_EXPR containing a STRING_CST. */
1349 if (output_bytecode)
1351 error ("`asm' is invalid when generating bytecode");
1355 if (TREE_CODE (body) == ADDR_EXPR)
1356 body = TREE_OPERAND (body, 0);
1358 emit_insn (gen_rtx (ASM_INPUT, VOIDmode,
1359 TREE_STRING_POINTER (body)));
1363 /* Generate RTL for an asm statement with arguments.
1364 STRING is the instruction template.
1365 OUTPUTS is a list of output arguments (lvalues); INPUTS a list of inputs.
1366 Each output or input has an expression in the TREE_VALUE and
1367 a constraint-string in the TREE_PURPOSE.
1368 CLOBBERS is a list of STRING_CST nodes each naming a hard register
1369 that is clobbered by this insn.
1371 Not all kinds of lvalue that may appear in OUTPUTS can be stored directly.
1372 Some elements of OUTPUTS may be replaced with trees representing temporary
1373 values. The caller should copy those temporary values to the originally
1376 VOL nonzero means the insn is volatile; don't optimize it. */
1379 expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line)
1380 tree string, outputs, inputs, clobbers;
1385 rtvec argvec, constraints;
1387 int ninputs = list_length (inputs);
1388 int noutputs = list_length (outputs);
1393 /* Vector of RTX's of evaluated output operands. */
1394 rtx *output_rtx = (rtx *) alloca (noutputs * sizeof (rtx));
1395 int *inout_opnum = (int *) alloca (noutputs * sizeof (int));
1396 enum machine_mode *inout_mode
1397 = (enum machine_mode *) alloca (noutputs * sizeof (enum machine_mode));
1398 /* The insn we have emitted. */
1401 if (output_bytecode)
1403 error ("`asm' is invalid when generating bytecode");
1407 /* Count the number of meaningful clobbered registers, ignoring what
1408 we would ignore later. */
1410 for (tail = clobbers; tail; tail = TREE_CHAIN (tail))
1412 char *regname = TREE_STRING_POINTER (TREE_VALUE (tail));
1413 i = decode_reg_name (regname);
1414 if (i >= 0 || i == -4)
1417 error ("unknown register name `%s' in `asm'", regname);
1422 for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
1424 tree val = TREE_VALUE (tail);
1425 tree type = TREE_TYPE (val);
1428 int found_equal = 0;
1432 /* If there's an erroneous arg, emit no insn. */
1433 if (TREE_TYPE (val) == error_mark_node)
1436 /* Make sure constraint has `=' and does not have `+'. Also, see
1437 if it allows any register. Be liberal on the latter test, since
1438 the worst that happens if we get it wrong is we issue an error
1441 for (j = 0; j < TREE_STRING_LENGTH (TREE_PURPOSE (tail)) - 1; j++)
1442 switch (TREE_STRING_POINTER (TREE_PURPOSE (tail))[j])
1445 /* Make sure we can specify the matching operand. */
1448 error ("output operand constraint %d contains `+'", i);
1452 /* Replace '+' with '='. */
1453 TREE_STRING_POINTER (TREE_PURPOSE (tail))[j] = '=';
1461 case '?': case '!': case '*': case '%': case '&':
1462 case 'V': case 'm': case 'o': case '<': case '>':
1463 case 'E': case 'F': case 'G': case 'H': case 'X':
1464 case 's': case 'i': case 'n':
1465 case 'I': case 'J': case 'K': case 'L': case 'M':
1466 case 'N': case 'O': case 'P': case ',':
1467 #ifdef EXTRA_CONSTRAINT
1468 case 'Q': case 'R': case 'S': case 'T': case 'U':
1472 case '0': case '1': case '2': case '3': case '4':
1473 case '5': case '6': case '7': case '8': case '9':
1474 error ("matching constraint not valid in output operand");
1477 case 'p': case 'g': case 'r':
1483 if (! found_equal && ! found_plus)
1485 error ("output operand constraint lacks `='");
1489 /* If an output operand is not a decl or indirect ref and our constraint
1490 allows a register, make a temporary to act as an intermediate.
1491 Make the asm insn write into that, then our caller will copy it to
1492 the real output operand. Likewise for promoted variables. */
1494 if (TREE_CODE (val) == INDIRECT_REF
1495 || (TREE_CODE_CLASS (TREE_CODE (val)) == 'd'
1496 && ! (GET_CODE (DECL_RTL (val)) == REG
1497 && GET_MODE (DECL_RTL (val)) != TYPE_MODE (type)))
1502 mark_addressable (TREE_VALUE (tail));
1505 = expand_expr (TREE_VALUE (tail), NULL_RTX, VOIDmode, 0);
1507 if (! allows_reg && GET_CODE (output_rtx[i]) != MEM)
1508 error ("output number %d not directly addressable", i);
1512 output_rtx[i] = assign_temp (type, 0, 0, 0);
1513 TREE_VALUE (tail) = make_tree (type, output_rtx[i]);
1518 inout_mode[ninout] = TYPE_MODE (TREE_TYPE (TREE_VALUE (tail)));
1519 inout_opnum[ninout++] = i;
1524 if (ninputs + noutputs > MAX_RECOG_OPERANDS)
1526 error ("more than %d operands in `asm'", MAX_RECOG_OPERANDS);
1530 /* Make vectors for the expression-rtx and constraint strings. */
1532 argvec = rtvec_alloc (ninputs);
1533 constraints = rtvec_alloc (ninputs);
1535 body = gen_rtx (ASM_OPERANDS, VOIDmode,
1536 TREE_STRING_POINTER (string), "", 0, argvec, constraints,
1538 MEM_VOLATILE_P (body) = vol;
1540 /* Eval the inputs and put them into ARGVEC.
1541 Put their constraints into ASM_INPUTs and store in CONSTRAINTS. */
1544 for (tail = inputs; tail; tail = TREE_CHAIN (tail))
1549 /* If there's an erroneous arg, emit no insn,
1550 because the ASM_INPUT would get VOIDmode
1551 and that could cause a crash in reload. */
1552 if (TREE_TYPE (TREE_VALUE (tail)) == error_mark_node)
1554 if (TREE_PURPOSE (tail) == NULL_TREE)
1556 error ("hard register `%s' listed as input operand to `asm'",
1557 TREE_STRING_POINTER (TREE_VALUE (tail)) );
1561 /* Make sure constraint has neither `=' nor `+'. */
1563 for (j = 0; j < TREE_STRING_LENGTH (TREE_PURPOSE (tail)) - 1; j++)
1564 switch (TREE_STRING_POINTER (TREE_PURPOSE (tail))[j])
1567 error ("input operand constraint contains `%c'",
1568 TREE_STRING_POINTER (TREE_PURPOSE (tail))[j]);
1571 case '?': case '!': case '*': case '%': case '&':
1572 case 'V': case 'm': case 'o': case '<': case '>':
1573 case 'E': case 'F': case 'G': case 'H': case 'X':
1574 case 's': case 'i': case 'n':
1575 case 'I': case 'J': case 'K': case 'L': case 'M':
1576 case 'N': case 'O': case 'P': case ',':
1577 #ifdef EXTRA_CONSTRAINT
1578 case 'Q': case 'R': case 'S': case 'T': case 'U':
1582 /* Whether or not a numeric constraint allows a register is
1583 decided by the matching constraint, and so there is no need
1584 to do anything special with them. We must handle them in
1585 the default case, so that we don't unnecessarily force
1586 operands to memory. */
1587 case '0': case '1': case '2': case '3': case '4':
1588 case '5': case '6': case '7': case '8': case '9':
1589 if (TREE_STRING_POINTER (TREE_PURPOSE (tail))[j]
1591 error ("matching constraint references invalid operand number");
1593 /* ... fall through ... */
1595 case 'p': case 'g': case 'r':
1602 mark_addressable (TREE_VALUE (tail));
1604 XVECEXP (body, 3, i) /* argvec */
1605 = expand_expr (TREE_VALUE (tail), NULL_RTX, VOIDmode, 0);
1606 if (CONSTANT_P (XVECEXP (body, 3, i))
1607 && ! general_operand (XVECEXP (body, 3, i),
1608 TYPE_MODE (TREE_TYPE (TREE_VALUE (tail)))))
1611 XVECEXP (body, 3, i)
1612 = force_reg (TYPE_MODE (TREE_TYPE (TREE_VALUE (tail))),
1613 XVECEXP (body, 3, i));
1615 XVECEXP (body, 3, i)
1616 = force_const_mem (TYPE_MODE (TREE_TYPE (TREE_VALUE (tail))),
1617 XVECEXP (body, 3, i));
1621 && (GET_CODE (XVECEXP (body, 3, i)) == REG
1622 || GET_CODE (XVECEXP (body, 3, i)) == SUBREG
1623 || GET_CODE (XVECEXP (body, 3, i)) == CONCAT))
1625 tree type = TREE_TYPE (TREE_VALUE (tail));
1626 rtx memloc = assign_temp (type, 1, 1, 1);
1628 emit_move_insn (memloc, XVECEXP (body, 3, i));
1629 XVECEXP (body, 3, i) = memloc;
1632 XVECEXP (body, 4, i) /* constraints */
1633 = gen_rtx (ASM_INPUT, TYPE_MODE (TREE_TYPE (TREE_VALUE (tail))),
1634 TREE_STRING_POINTER (TREE_PURPOSE (tail)));
1638 /* Protect all the operands from the queue,
1639 now that they have all been evaluated. */
1641 for (i = 0; i < ninputs - ninout; i++)
1642 XVECEXP (body, 3, i) = protect_from_queue (XVECEXP (body, 3, i), 0);
1644 for (i = 0; i < noutputs; i++)
1645 output_rtx[i] = protect_from_queue (output_rtx[i], 1);
1647 /* For in-out operands, copy output rtx to input rtx. */
1648 for (i = 0; i < ninout; i++)
1650 static char match[9+1][2]
1651 = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
1652 int j = inout_opnum[i];
1654 XVECEXP (body, 3, ninputs - ninout + i) /* argvec */
1656 XVECEXP (body, 4, ninputs - ninout + i) /* constraints */
1657 = gen_rtx (ASM_INPUT, inout_mode[j], match[j]);
1660 /* Now, for each output, construct an rtx
1661 (set OUTPUT (asm_operands INSN OUTPUTNUMBER OUTPUTCONSTRAINT
1662 ARGVEC CONSTRAINTS))
1663 If there is more than one, put them inside a PARALLEL. */
1665 if (noutputs == 1 && nclobbers == 0)
1667 XSTR (body, 1) = TREE_STRING_POINTER (TREE_PURPOSE (outputs));
1668 insn = emit_insn (gen_rtx (SET, VOIDmode, output_rtx[0], body));
1670 else if (noutputs == 0 && nclobbers == 0)
1672 /* No output operands: put in a raw ASM_OPERANDS rtx. */
1673 insn = emit_insn (body);
1679 if (num == 0) num = 1;
1680 body = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (num + nclobbers));
1682 /* For each output operand, store a SET. */
1684 for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
1686 XVECEXP (body, 0, i)
1687 = gen_rtx (SET, VOIDmode,
1689 gen_rtx (ASM_OPERANDS, VOIDmode,
1690 TREE_STRING_POINTER (string),
1691 TREE_STRING_POINTER (TREE_PURPOSE (tail)),
1692 i, argvec, constraints,
1694 MEM_VOLATILE_P (SET_SRC (XVECEXP (body, 0, i))) = vol;
1697 /* If there are no outputs (but there are some clobbers)
1698 store the bare ASM_OPERANDS into the PARALLEL. */
1701 XVECEXP (body, 0, i++) = obody;
1703 /* Store (clobber REG) for each clobbered register specified. */
1705 for (tail = clobbers; tail; tail = TREE_CHAIN (tail))
1707 char *regname = TREE_STRING_POINTER (TREE_VALUE (tail));
1708 int j = decode_reg_name (regname);
1712 if (j == -3) /* `cc', which is not a register */
1715 if (j == -4) /* `memory', don't cache memory across asm */
1717 XVECEXP (body, 0, i++)
1718 = gen_rtx (CLOBBER, VOIDmode,
1719 gen_rtx (MEM, BLKmode,
1720 gen_rtx (SCRATCH, VOIDmode, 0)));
1724 /* Ignore unknown register, error already signalled. */
1728 /* Use QImode since that's guaranteed to clobber just one reg. */
1729 XVECEXP (body, 0, i++)
1730 = gen_rtx (CLOBBER, VOIDmode, gen_rtx (REG, QImode, j));
1733 insn = emit_insn (body);
1739 /* Generate RTL to evaluate the expression EXP
1740 and remember it in case this is the VALUE in a ({... VALUE; }) constr. */
1743 expand_expr_stmt (exp)
1746 if (output_bytecode)
1748 int org_stack_depth = stack_depth;
1750 bc_expand_expr (exp);
1752 /* Restore stack depth */
1753 if (stack_depth < org_stack_depth)
1756 bc_emit_instruction (drop);
1758 last_expr_type = TREE_TYPE (exp);
1762 /* If -W, warn about statements with no side effects,
1763 except for an explicit cast to void (e.g. for assert()), and
1764 except inside a ({...}) where they may be useful. */
1765 if (expr_stmts_for_value == 0 && exp != error_mark_node)
1767 if (! TREE_SIDE_EFFECTS (exp) && (extra_warnings || warn_unused)
1768 && !(TREE_CODE (exp) == CONVERT_EXPR
1769 && TREE_TYPE (exp) == void_type_node))
1770 warning_with_file_and_line (emit_filename, emit_lineno,
1771 "statement with no effect");
1772 else if (warn_unused)
1773 warn_if_unused_value (exp);
1776 /* If EXP is of function type and we are expanding statements for
1777 value, convert it to pointer-to-function. */
1778 if (expr_stmts_for_value && TREE_CODE (TREE_TYPE (exp)) == FUNCTION_TYPE)
1779 exp = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (exp)), exp);
1781 last_expr_type = TREE_TYPE (exp);
1782 if (! flag_syntax_only)
1783 last_expr_value = expand_expr (exp,
1784 (expr_stmts_for_value
1785 ? NULL_RTX : const0_rtx),
1788 /* If all we do is reference a volatile value in memory,
1789 copy it to a register to be sure it is actually touched. */
1790 if (last_expr_value != 0 && GET_CODE (last_expr_value) == MEM
1791 && TREE_THIS_VOLATILE (exp))
1793 if (TYPE_MODE (TREE_TYPE (exp)) == VOIDmode)
1795 else if (TYPE_MODE (TREE_TYPE (exp)) != BLKmode)
1796 copy_to_reg (last_expr_value);
1799 rtx lab = gen_label_rtx ();
1801 /* Compare the value with itself to reference it. */
1802 emit_cmp_insn (last_expr_value, last_expr_value, EQ,
1803 expand_expr (TYPE_SIZE (last_expr_type),
1804 NULL_RTX, VOIDmode, 0),
1806 TYPE_ALIGN (last_expr_type) / BITS_PER_UNIT);
1807 emit_jump_insn ((*bcc_gen_fctn[(int) EQ]) (lab));
1812 /* If this expression is part of a ({...}) and is in memory, we may have
1813 to preserve temporaries. */
1814 preserve_temp_slots (last_expr_value);
1816 /* Free any temporaries used to evaluate this expression. Any temporary
1817 used as a result of this expression will already have been preserved
1824 /* Warn if EXP contains any computations whose results are not used.
1825 Return 1 if a warning is printed; 0 otherwise. */
1828 warn_if_unused_value (exp)
1831 if (TREE_USED (exp))
1834 switch (TREE_CODE (exp))
1836 case PREINCREMENT_EXPR:
1837 case POSTINCREMENT_EXPR:
1838 case PREDECREMENT_EXPR:
1839 case POSTDECREMENT_EXPR:
1844 case METHOD_CALL_EXPR:
1846 case WITH_CLEANUP_EXPR:
1848 /* We don't warn about COND_EXPR because it may be a useful
1849 construct if either arm contains a side effect. */
1854 /* For a binding, warn if no side effect within it. */
1855 return warn_if_unused_value (TREE_OPERAND (exp, 1));
1858 return warn_if_unused_value (TREE_OPERAND (exp, 1));
1860 case TRUTH_ORIF_EXPR:
1861 case TRUTH_ANDIF_EXPR:
1862 /* In && or ||, warn if 2nd operand has no side effect. */
1863 return warn_if_unused_value (TREE_OPERAND (exp, 1));
1866 if (TREE_NO_UNUSED_WARNING (exp))
1868 if (warn_if_unused_value (TREE_OPERAND (exp, 0)))
1870 /* Let people do `(foo (), 0)' without a warning. */
1871 if (TREE_CONSTANT (TREE_OPERAND (exp, 1)))
1873 return warn_if_unused_value (TREE_OPERAND (exp, 1));
1877 case NON_LVALUE_EXPR:
1878 /* Don't warn about values cast to void. */
1879 if (TREE_TYPE (exp) == void_type_node)
1881 /* Don't warn about conversions not explicit in the user's program. */
1882 if (TREE_NO_UNUSED_WARNING (exp))
1884 /* Assignment to a cast usually results in a cast of a modify.
1885 Don't complain about that. There can be an arbitrary number of
1886 casts before the modify, so we must loop until we find the first
1887 non-cast expression and then test to see if that is a modify. */
1889 tree tem = TREE_OPERAND (exp, 0);
1891 while (TREE_CODE (tem) == CONVERT_EXPR || TREE_CODE (tem) == NOP_EXPR)
1892 tem = TREE_OPERAND (tem, 0);
1894 if (TREE_CODE (tem) == MODIFY_EXPR || TREE_CODE (tem) == INIT_EXPR
1895 || TREE_CODE (tem) == CALL_EXPR)
1901 /* Don't warn about automatic dereferencing of references, since
1902 the user cannot control it. */
1903 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == REFERENCE_TYPE)
1904 return warn_if_unused_value (TREE_OPERAND (exp, 0));
1905 /* ... fall through ... */
1908 /* Referencing a volatile value is a side effect, so don't warn. */
1909 if ((TREE_CODE_CLASS (TREE_CODE (exp)) == 'd'
1910 || TREE_CODE_CLASS (TREE_CODE (exp)) == 'r')
1911 && TREE_THIS_VOLATILE (exp))
1914 warning_with_file_and_line (emit_filename, emit_lineno,
1915 "value computed is not used");
1920 /* Clear out the memory of the last expression evaluated. */
1928 /* Begin a statement which will return a value.
1929 Return the RTL_EXPR for this statement expr.
1930 The caller must save that value and pass it to expand_end_stmt_expr. */
1933 expand_start_stmt_expr ()
1938 /* When generating bytecode just note down the stack depth */
1939 if (output_bytecode)
1940 return (build_int_2 (stack_depth, 0));
1942 /* Make the RTL_EXPR node temporary, not momentary,
1943 so that rtl_expr_chain doesn't become garbage. */
1944 momentary = suspend_momentary ();
1945 t = make_node (RTL_EXPR);
1946 resume_momentary (momentary);
1947 do_pending_stack_adjust ();
1948 start_sequence_for_rtl_expr (t);
1950 expr_stmts_for_value++;
1954 /* Restore the previous state at the end of a statement that returns a value.
1955 Returns a tree node representing the statement's value and the
1956 insns to compute the value.
1958 The nodes of that expression have been freed by now, so we cannot use them.
1959 But we don't want to do that anyway; the expression has already been
1960 evaluated and now we just want to use the value. So generate a RTL_EXPR
1961 with the proper type and RTL value.
1963 If the last substatement was not an expression,
1964 return something with type `void'. */
1967 expand_end_stmt_expr (t)
1970 if (output_bytecode)
1976 /* At this point, all expressions have been evaluated in order.
1977 However, all expression values have been popped when evaluated,
1978 which means we have to recover the last expression value. This is
1979 the last value removed by means of a `drop' instruction. Instead
1980 of adding code to inhibit dropping the last expression value, it
1981 is here recovered by undoing the `drop'. Since `drop' is
1982 equivalent to `adjustackSI [1]', it can be undone with `adjstackSI
1985 bc_adjust_stack (-1);
1987 if (!last_expr_type)
1988 last_expr_type = void_type_node;
1990 t = make_node (RTL_EXPR);
1991 TREE_TYPE (t) = last_expr_type;
1992 RTL_EXPR_RTL (t) = NULL;
1993 RTL_EXPR_SEQUENCE (t) = NULL;
1995 /* Don't consider deleting this expr or containing exprs at tree level. */
1996 TREE_THIS_VOLATILE (t) = 1;
2004 if (last_expr_type == 0)
2006 last_expr_type = void_type_node;
2007 last_expr_value = const0_rtx;
2009 else if (last_expr_value == 0)
2010 /* There are some cases where this can happen, such as when the
2011 statement is void type. */
2012 last_expr_value = const0_rtx;
2013 else if (GET_CODE (last_expr_value) != REG && ! CONSTANT_P (last_expr_value))
2014 /* Remove any possible QUEUED. */
2015 last_expr_value = protect_from_queue (last_expr_value, 0);
2019 TREE_TYPE (t) = last_expr_type;
2020 RTL_EXPR_RTL (t) = last_expr_value;
2021 RTL_EXPR_SEQUENCE (t) = get_insns ();
2023 rtl_expr_chain = tree_cons (NULL_TREE, t, rtl_expr_chain);
2027 /* Don't consider deleting this expr or containing exprs at tree level. */
2028 TREE_SIDE_EFFECTS (t) = 1;
2029 /* Propagate volatility of the actual RTL expr. */
2030 TREE_THIS_VOLATILE (t) = volatile_refs_p (last_expr_value);
2033 expr_stmts_for_value--;
2038 /* Generate RTL for the start of an if-then. COND is the expression
2039 whose truth should be tested.
2041 If EXITFLAG is nonzero, this conditional is visible to
2042 `exit_something'. */
2045 expand_start_cond (cond, exitflag)
2049 struct nesting *thiscond = ALLOC_NESTING ();
2051 /* Make an entry on cond_stack for the cond we are entering. */
2053 thiscond->next = cond_stack;
2054 thiscond->all = nesting_stack;
2055 thiscond->depth = ++nesting_depth;
2056 thiscond->data.cond.next_label = gen_label_rtx ();
2057 /* Before we encounter an `else', we don't need a separate exit label
2058 unless there are supposed to be exit statements
2059 to exit this conditional. */
2060 thiscond->exit_label = exitflag ? gen_label_rtx () : 0;
2061 thiscond->data.cond.endif_label = thiscond->exit_label;
2062 cond_stack = thiscond;
2063 nesting_stack = thiscond;
2065 if (output_bytecode)
2066 bc_expand_start_cond (cond, exitflag);
2068 do_jump (cond, thiscond->data.cond.next_label, NULL_RTX);
2071 /* Generate RTL between then-clause and the elseif-clause
2072 of an if-then-elseif-.... */
2075 expand_start_elseif (cond)
2078 if (cond_stack->data.cond.endif_label == 0)
2079 cond_stack->data.cond.endif_label = gen_label_rtx ();
2080 emit_jump (cond_stack->data.cond.endif_label);
2081 emit_label (cond_stack->data.cond.next_label);
2082 cond_stack->data.cond.next_label = gen_label_rtx ();
2083 do_jump (cond, cond_stack->data.cond.next_label, NULL_RTX);
2086 /* Generate RTL between the then-clause and the else-clause
2087 of an if-then-else. */
2090 expand_start_else ()
2092 if (cond_stack->data.cond.endif_label == 0)
2093 cond_stack->data.cond.endif_label = gen_label_rtx ();
2095 if (output_bytecode)
2097 bc_expand_start_else ();
2101 emit_jump (cond_stack->data.cond.endif_label);
2102 emit_label (cond_stack->data.cond.next_label);
2103 cond_stack->data.cond.next_label = 0; /* No more _else or _elseif calls. */
2106 /* After calling expand_start_else, turn this "else" into an "else if"
2107 by providing another condition. */
2110 expand_elseif (cond)
2113 cond_stack->data.cond.next_label = gen_label_rtx ();
2114 do_jump (cond, cond_stack->data.cond.next_label, NULL_RTX);
2117 /* Generate RTL for the end of an if-then.
2118 Pop the record for it off of cond_stack. */
2123 struct nesting *thiscond = cond_stack;
2125 if (output_bytecode)
2126 bc_expand_end_cond ();
2129 do_pending_stack_adjust ();
2130 if (thiscond->data.cond.next_label)
2131 emit_label (thiscond->data.cond.next_label);
2132 if (thiscond->data.cond.endif_label)
2133 emit_label (thiscond->data.cond.endif_label);
2136 POPSTACK (cond_stack);
2141 /* Generate code for the start of an if-then. COND is the expression
2142 whose truth is to be tested; if EXITFLAG is nonzero this conditional
2143 is to be visible to exit_something. It is assumed that the caller
2144 has pushed the previous context on the cond stack. */
2147 bc_expand_start_cond (cond, exitflag)
2151 struct nesting *thiscond = cond_stack;
2153 thiscond->data.case_stmt.nominal_type = cond;
2155 thiscond->exit_label = gen_label_rtx ();
2156 bc_expand_expr (cond);
2157 bc_emit_bytecode (xjumpifnot);
2158 bc_emit_bytecode_labelref (BYTECODE_BC_LABEL (thiscond->exit_label));
2160 #ifdef DEBUG_PRINT_CODE
2161 fputc ('\n', stderr);
2165 /* Generate the label for the end of an if with
2169 bc_expand_end_cond ()
2171 struct nesting *thiscond = cond_stack;
2173 bc_emit_bytecode_labeldef (BYTECODE_BC_LABEL (thiscond->exit_label));
2176 /* Generate code for the start of the else- clause of
2180 bc_expand_start_else ()
2182 struct nesting *thiscond = cond_stack;
2184 thiscond->data.cond.endif_label = thiscond->exit_label;
2185 thiscond->exit_label = gen_label_rtx ();
2186 bc_emit_bytecode (jump);
2187 bc_emit_bytecode_labelref (BYTECODE_BC_LABEL (thiscond->exit_label));
2189 #ifdef DEBUG_PRINT_CODE
2190 fputc ('\n', stderr);
2193 bc_emit_bytecode_labeldef (BYTECODE_BC_LABEL (thiscond->data.cond.endif_label));
2196 /* Generate RTL for the start of a loop. EXIT_FLAG is nonzero if this
2197 loop should be exited by `exit_something'. This is a loop for which
2198 `expand_continue' will jump to the top of the loop.
2200 Make an entry on loop_stack to record the labels associated with
2204 expand_start_loop (exit_flag)
2207 register struct nesting *thisloop = ALLOC_NESTING ();
2209 /* Make an entry on loop_stack for the loop we are entering. */
2211 thisloop->next = loop_stack;
2212 thisloop->all = nesting_stack;
2213 thisloop->depth = ++nesting_depth;
2214 thisloop->data.loop.start_label = gen_label_rtx ();
2215 thisloop->data.loop.end_label = gen_label_rtx ();
2216 thisloop->data.loop.alt_end_label = 0;
2217 thisloop->data.loop.continue_label = thisloop->data.loop.start_label;
2218 thisloop->exit_label = exit_flag ? thisloop->data.loop.end_label : 0;
2219 loop_stack = thisloop;
2220 nesting_stack = thisloop;
2222 if (output_bytecode)
2224 bc_emit_bytecode_labeldef (BYTECODE_BC_LABEL (thisloop->data.loop.start_label));
2228 do_pending_stack_adjust ();
2230 emit_note (NULL_PTR, NOTE_INSN_LOOP_BEG);
2231 emit_label (thisloop->data.loop.start_label);
2236 /* Like expand_start_loop but for a loop where the continuation point
2237 (for expand_continue_loop) will be specified explicitly. */
2240 expand_start_loop_continue_elsewhere (exit_flag)
2243 struct nesting *thisloop = expand_start_loop (exit_flag);
2244 loop_stack->data.loop.continue_label = gen_label_rtx ();
2248 /* Specify the continuation point for a loop started with
2249 expand_start_loop_continue_elsewhere.
2250 Use this at the point in the code to which a continue statement
2254 expand_loop_continue_here ()
2256 if (output_bytecode)
2258 bc_emit_bytecode_labeldef (BYTECODE_BC_LABEL (loop_stack->data.loop.continue_label));
2261 do_pending_stack_adjust ();
2262 emit_note (NULL_PTR, NOTE_INSN_LOOP_CONT);
2263 emit_label (loop_stack->data.loop.continue_label);
2269 bc_expand_end_loop ()
2271 struct nesting *thisloop = loop_stack;
2273 bc_emit_bytecode (jump);
2274 bc_emit_bytecode_labelref (BYTECODE_BC_LABEL (thisloop->data.loop.start_label));
2276 #ifdef DEBUG_PRINT_CODE
2277 fputc ('\n', stderr);
2280 bc_emit_bytecode_labeldef (BYTECODE_BC_LABEL (thisloop->exit_label));
2281 POPSTACK (loop_stack);
2286 /* Finish a loop. Generate a jump back to the top and the loop-exit label.
2287 Pop the block off of loop_stack. */
2293 register rtx start_label;
2294 rtx last_test_insn = 0;
2297 if (output_bytecode)
2299 bc_expand_end_loop ();
2303 insn = get_last_insn ();
2304 start_label = loop_stack->data.loop.start_label;
2306 /* Mark the continue-point at the top of the loop if none elsewhere. */
2307 if (start_label == loop_stack->data.loop.continue_label)
2308 emit_note_before (NOTE_INSN_LOOP_CONT, start_label);
2310 do_pending_stack_adjust ();
2312 /* If optimizing, perhaps reorder the loop. If the loop
2313 starts with a conditional exit, roll that to the end
2314 where it will optimize together with the jump back.
2316 We look for the last conditional branch to the exit that we encounter
2317 before hitting 30 insns or a CALL_INSN. If we see an unconditional
2318 branch to the exit first, use it.
2320 We must also stop at NOTE_INSN_BLOCK_BEG and NOTE_INSN_BLOCK_END notes
2321 because moving them is not valid. */
2325 ! (GET_CODE (insn) == JUMP_INSN
2326 && GET_CODE (PATTERN (insn)) == SET
2327 && SET_DEST (PATTERN (insn)) == pc_rtx
2328 && GET_CODE (SET_SRC (PATTERN (insn))) == IF_THEN_ELSE))
2330 /* Scan insns from the top of the loop looking for a qualified
2331 conditional exit. */
2332 for (insn = NEXT_INSN (loop_stack->data.loop.start_label); insn;
2333 insn = NEXT_INSN (insn))
2335 if (GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == CODE_LABEL)
2338 if (GET_CODE (insn) == NOTE
2339 && (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG
2340 || NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END))
2343 if (GET_CODE (insn) == JUMP_INSN || GET_CODE (insn) == INSN)
2346 if (last_test_insn && num_insns > 30)
2349 if (GET_CODE (insn) == JUMP_INSN && GET_CODE (PATTERN (insn)) == SET
2350 && SET_DEST (PATTERN (insn)) == pc_rtx
2351 && GET_CODE (SET_SRC (PATTERN (insn))) == IF_THEN_ELSE
2352 && ((GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 1)) == LABEL_REF
2353 && ((XEXP (XEXP (SET_SRC (PATTERN (insn)), 1), 0)
2354 == loop_stack->data.loop.end_label)
2355 || (XEXP (XEXP (SET_SRC (PATTERN (insn)), 1), 0)
2356 == loop_stack->data.loop.alt_end_label)))
2357 || (GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 2)) == LABEL_REF
2358 && ((XEXP (XEXP (SET_SRC (PATTERN (insn)), 2), 0)
2359 == loop_stack->data.loop.end_label)
2360 || (XEXP (XEXP (SET_SRC (PATTERN (insn)), 2), 0)
2361 == loop_stack->data.loop.alt_end_label)))))
2362 last_test_insn = insn;
2364 if (last_test_insn == 0 && GET_CODE (insn) == JUMP_INSN
2365 && GET_CODE (PATTERN (insn)) == SET
2366 && SET_DEST (PATTERN (insn)) == pc_rtx
2367 && GET_CODE (SET_SRC (PATTERN (insn))) == LABEL_REF
2368 && ((XEXP (SET_SRC (PATTERN (insn)), 0)
2369 == loop_stack->data.loop.end_label)
2370 || (XEXP (SET_SRC (PATTERN (insn)), 0)
2371 == loop_stack->data.loop.alt_end_label)))
2372 /* Include BARRIER. */
2373 last_test_insn = NEXT_INSN (insn);
2376 if (last_test_insn != 0 && last_test_insn != get_last_insn ())
2378 /* We found one. Move everything from there up
2379 to the end of the loop, and add a jump into the loop
2380 to jump to there. */
2381 register rtx newstart_label = gen_label_rtx ();
2382 register rtx start_move = start_label;
2384 /* If the start label is preceded by a NOTE_INSN_LOOP_CONT note,
2385 then we want to move this note also. */
2386 if (GET_CODE (PREV_INSN (start_move)) == NOTE
2387 && (NOTE_LINE_NUMBER (PREV_INSN (start_move))
2388 == NOTE_INSN_LOOP_CONT))
2389 start_move = PREV_INSN (start_move);
2391 emit_label_after (newstart_label, PREV_INSN (start_move));
2392 reorder_insns (start_move, last_test_insn, get_last_insn ());
2393 emit_jump_insn_after (gen_jump (start_label),
2394 PREV_INSN (newstart_label));
2395 emit_barrier_after (PREV_INSN (newstart_label));
2396 start_label = newstart_label;
2400 emit_jump (start_label);
2401 emit_note (NULL_PTR, NOTE_INSN_LOOP_END);
2402 emit_label (loop_stack->data.loop.end_label);
2404 POPSTACK (loop_stack);
2409 /* Generate a jump to the current loop's continue-point.
2410 This is usually the top of the loop, but may be specified
2411 explicitly elsewhere. If not currently inside a loop,
2412 return 0 and do nothing; caller will print an error message. */
2415 expand_continue_loop (whichloop)
2416 struct nesting *whichloop;
2420 whichloop = loop_stack;
2423 expand_goto_internal (NULL_TREE, whichloop->data.loop.continue_label,
2428 /* Generate a jump to exit the current loop. If not currently inside a loop,
2429 return 0 and do nothing; caller will print an error message. */
2432 expand_exit_loop (whichloop)
2433 struct nesting *whichloop;
2437 whichloop = loop_stack;
2440 expand_goto_internal (NULL_TREE, whichloop->data.loop.end_label, NULL_RTX);
2444 /* Generate a conditional jump to exit the current loop if COND
2445 evaluates to zero. If not currently inside a loop,
2446 return 0 and do nothing; caller will print an error message. */
2449 expand_exit_loop_if_false (whichloop, cond)
2450 struct nesting *whichloop;
2455 whichloop = loop_stack;
2458 if (output_bytecode)
2460 bc_expand_expr (cond);
2461 bc_expand_goto_internal (xjumpifnot,
2462 BYTECODE_BC_LABEL (whichloop->exit_label),
2467 /* In order to handle fixups, we actually create a conditional jump
2468 around a unconditional branch to exit the loop. If fixups are
2469 necessary, they go before the unconditional branch. */
2471 rtx label = gen_label_rtx ();
2474 do_jump (cond, NULL_RTX, label);
2475 last_insn = get_last_insn ();
2476 if (GET_CODE (last_insn) == CODE_LABEL)
2477 whichloop->data.loop.alt_end_label = last_insn;
2478 expand_goto_internal (NULL_TREE, whichloop->data.loop.end_label,
2486 /* Return non-zero if we should preserve sub-expressions as separate
2487 pseudos. We never do so if we aren't optimizing. We always do so
2488 if -fexpensive-optimizations.
2490 Otherwise, we only do so if we are in the "early" part of a loop. I.e.,
2491 the loop may still be a small one. */
2494 preserve_subexpressions_p ()
2498 if (flag_expensive_optimizations)
2501 if (optimize == 0 || loop_stack == 0)
2504 insn = get_last_insn_anywhere ();
2507 && (INSN_UID (insn) - INSN_UID (loop_stack->data.loop.start_label)
2508 < n_non_fixed_regs * 3));
2512 /* Generate a jump to exit the current loop, conditional, binding contour
2513 or case statement. Not all such constructs are visible to this function,
2514 only those started with EXIT_FLAG nonzero. Individual languages use
2515 the EXIT_FLAG parameter to control which kinds of constructs you can
2518 If not currently inside anything that can be exited,
2519 return 0 and do nothing; caller will print an error message. */
2522 expand_exit_something ()
2526 for (n = nesting_stack; n; n = n->all)
2527 if (n->exit_label != 0)
2529 expand_goto_internal (NULL_TREE, n->exit_label, NULL_RTX);
2536 /* Generate RTL to return from the current function, with no value.
2537 (That is, we do not do anything about returning any value.) */
2540 expand_null_return ()
2542 struct nesting *block = block_stack;
2545 if (output_bytecode)
2547 bc_emit_instruction (ret);
2551 /* Does any pending block have cleanups? */
2553 while (block && block->data.block.cleanups == 0)
2554 block = block->next;
2556 /* If yes, use a goto to return, since that runs cleanups. */
2558 expand_null_return_1 (last_insn, block != 0);
2561 /* Generate RTL to return from the current function, with value VAL. */
2564 expand_value_return (val)
2567 struct nesting *block = block_stack;
2568 rtx last_insn = get_last_insn ();
2569 rtx return_reg = DECL_RTL (DECL_RESULT (current_function_decl));
2571 /* Copy the value to the return location
2572 unless it's already there. */
2574 if (return_reg != val)
2576 #ifdef PROMOTE_FUNCTION_RETURN
2577 tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
2578 int unsignedp = TREE_UNSIGNED (type);
2579 enum machine_mode mode
2580 = promote_mode (type, DECL_MODE (DECL_RESULT (current_function_decl)),
2583 if (GET_MODE (val) != VOIDmode && GET_MODE (val) != mode)
2584 convert_move (return_reg, val, unsignedp);
2587 emit_move_insn (return_reg, val);
2589 if (GET_CODE (return_reg) == REG
2590 && REGNO (return_reg) < FIRST_PSEUDO_REGISTER)
2591 emit_insn (gen_rtx (USE, VOIDmode, return_reg));
2592 /* Handle calls that return values in multiple non-contiguous locations.
2593 The Irix 6 ABI has examples of this. */
2594 else if (GET_CODE (return_reg) == PARALLEL)
2598 for (i = 0; i < XVECLEN (return_reg, 0); i++)
2600 rtx x = XEXP (XVECEXP (return_reg, 0, i), 0);
2602 if (GET_CODE (x) == REG
2603 && REGNO (x) < FIRST_PSEUDO_REGISTER)
2604 emit_insn (gen_rtx (USE, VOIDmode, x));
2608 /* Does any pending block have cleanups? */
2610 while (block && block->data.block.cleanups == 0)
2611 block = block->next;
2613 /* If yes, use a goto to return, since that runs cleanups.
2614 Use LAST_INSN to put cleanups *before* the move insn emitted above. */
2616 expand_null_return_1 (last_insn, block != 0);
2619 /* Output a return with no value. If LAST_INSN is nonzero,
2620 pretend that the return takes place after LAST_INSN.
2621 If USE_GOTO is nonzero then don't use a return instruction;
2622 go to the return label instead. This causes any cleanups
2623 of pending blocks to be executed normally. */
2626 expand_null_return_1 (last_insn, use_goto)
2630 rtx end_label = cleanup_label ? cleanup_label : return_label;
2632 clear_pending_stack_adjust ();
2633 do_pending_stack_adjust ();
2636 /* PCC-struct return always uses an epilogue. */
2637 if (current_function_returns_pcc_struct || use_goto)
2640 end_label = return_label = gen_label_rtx ();
2641 expand_goto_internal (NULL_TREE, end_label, last_insn);
2645 /* Otherwise output a simple return-insn if one is available,
2646 unless it won't do the job. */
2648 if (HAVE_return && use_goto == 0 && cleanup_label == 0)
2650 emit_jump_insn (gen_return ());
2656 /* Otherwise jump to the epilogue. */
2657 expand_goto_internal (NULL_TREE, end_label, last_insn);
2660 /* Generate RTL to evaluate the expression RETVAL and return it
2661 from the current function. */
2664 expand_return (retval)
2667 /* If there are any cleanups to be performed, then they will
2668 be inserted following LAST_INSN. It is desirable
2669 that the last_insn, for such purposes, should be the
2670 last insn before computing the return value. Otherwise, cleanups
2671 which call functions can clobber the return value. */
2672 /* ??? rms: I think that is erroneous, because in C++ it would
2673 run destructors on variables that might be used in the subsequent
2674 computation of the return value. */
2676 register rtx val = 0;
2680 struct nesting *block;
2682 /* Bytecode returns are quite simple, just leave the result on the
2683 arithmetic stack. */
2684 if (output_bytecode)
2686 bc_expand_expr (retval);
2687 bc_emit_instruction (ret);
2691 /* If function wants no value, give it none. */
2692 if (TREE_CODE (TREE_TYPE (TREE_TYPE (current_function_decl))) == VOID_TYPE)
2694 expand_expr (retval, NULL_RTX, VOIDmode, 0);
2696 expand_null_return ();
2700 /* Are any cleanups needed? E.g. C++ destructors to be run? */
2701 /* This is not sufficient. We also need to watch for cleanups of the
2702 expression we are about to expand. Unfortunately, we cannot know
2703 if it has cleanups until we expand it, and we want to change how we
2704 expand it depending upon if we need cleanups. We can't win. */
2706 cleanups = any_pending_cleanups (1);
2711 if (TREE_CODE (retval) == RESULT_DECL)
2712 retval_rhs = retval;
2713 else if ((TREE_CODE (retval) == MODIFY_EXPR || TREE_CODE (retval) == INIT_EXPR)
2714 && TREE_CODE (TREE_OPERAND (retval, 0)) == RESULT_DECL)
2715 retval_rhs = TREE_OPERAND (retval, 1);
2716 else if (TREE_TYPE (retval) == void_type_node)
2717 /* Recognize tail-recursive call to void function. */
2718 retval_rhs = retval;
2720 retval_rhs = NULL_TREE;
2722 /* Only use `last_insn' if there are cleanups which must be run. */
2723 if (cleanups || cleanup_label != 0)
2724 last_insn = get_last_insn ();
2726 /* Distribute return down conditional expr if either of the sides
2727 may involve tail recursion (see test below). This enhances the number
2728 of tail recursions we see. Don't do this always since it can produce
2729 sub-optimal code in some cases and we distribute assignments into
2730 conditional expressions when it would help. */
2732 if (optimize && retval_rhs != 0
2733 && frame_offset == 0
2734 && TREE_CODE (retval_rhs) == COND_EXPR
2735 && (TREE_CODE (TREE_OPERAND (retval_rhs, 1)) == CALL_EXPR
2736 || TREE_CODE (TREE_OPERAND (retval_rhs, 2)) == CALL_EXPR))
2738 rtx label = gen_label_rtx ();
2741 do_jump (TREE_OPERAND (retval_rhs, 0), label, NULL_RTX);
2742 expr = build (MODIFY_EXPR, TREE_TYPE (TREE_TYPE (current_function_decl)),
2743 DECL_RESULT (current_function_decl),
2744 TREE_OPERAND (retval_rhs, 1));
2745 TREE_SIDE_EFFECTS (expr) = 1;
2746 expand_return (expr);
2749 expr = build (MODIFY_EXPR, TREE_TYPE (TREE_TYPE (current_function_decl)),
2750 DECL_RESULT (current_function_decl),
2751 TREE_OPERAND (retval_rhs, 2));
2752 TREE_SIDE_EFFECTS (expr) = 1;
2753 expand_return (expr);
2757 /* For tail-recursive call to current function,
2758 just jump back to the beginning.
2759 It's unsafe if any auto variable in this function
2760 has its address taken; for simplicity,
2761 require stack frame to be empty. */
2762 if (optimize && retval_rhs != 0
2763 && frame_offset == 0
2764 && TREE_CODE (retval_rhs) == CALL_EXPR
2765 && TREE_CODE (TREE_OPERAND (retval_rhs, 0)) == ADDR_EXPR
2766 && TREE_OPERAND (TREE_OPERAND (retval_rhs, 0), 0) == current_function_decl
2767 /* Finish checking validity, and if valid emit code
2768 to set the argument variables for the new call. */
2769 && tail_recursion_args (TREE_OPERAND (retval_rhs, 1),
2770 DECL_ARGUMENTS (current_function_decl)))
2772 if (tail_recursion_label == 0)
2774 tail_recursion_label = gen_label_rtx ();
2775 emit_label_after (tail_recursion_label,
2776 tail_recursion_reentry);
2779 expand_goto_internal (NULL_TREE, tail_recursion_label, last_insn);
2784 /* This optimization is safe if there are local cleanups
2785 because expand_null_return takes care of them.
2786 ??? I think it should also be safe when there is a cleanup label,
2787 because expand_null_return takes care of them, too.
2788 Any reason why not? */
2789 if (HAVE_return && cleanup_label == 0
2790 && ! current_function_returns_pcc_struct
2791 && BRANCH_COST <= 1)
2793 /* If this is return x == y; then generate
2794 if (x == y) return 1; else return 0;
2795 if we can do it with explicit return insns and branches are cheap,
2796 but not if we have the corresponding scc insn. */
2799 switch (TREE_CODE (retval_rhs))
2825 case TRUTH_ANDIF_EXPR:
2826 case TRUTH_ORIF_EXPR:
2827 case TRUTH_AND_EXPR:
2829 case TRUTH_NOT_EXPR:
2830 case TRUTH_XOR_EXPR:
2833 op0 = gen_label_rtx ();
2834 jumpifnot (retval_rhs, op0);
2835 expand_value_return (const1_rtx);
2837 expand_value_return (const0_rtx);
2842 #endif /* HAVE_return */
2844 /* If the result is an aggregate that is being returned in one (or more)
2845 registers, load the registers here. The compiler currently can't handle
2846 copying a BLKmode value into registers. We could put this code in a
2847 more general area (for use by everyone instead of just function
2848 call/return), but until this feature is generally usable it is kept here
2849 (and in expand_call). The value must go into a pseudo in case there
2850 are cleanups that will clobber the real return register. */
2853 && TYPE_MODE (TREE_TYPE (retval_rhs)) == BLKmode
2854 && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG)
2856 int i, bitpos, xbitpos;
2857 int big_endian_correction = 0;
2858 int bytes = int_size_in_bytes (TREE_TYPE (retval_rhs));
2859 int n_regs = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
2860 int bitsize = MIN (TYPE_ALIGN (TREE_TYPE (retval_rhs)),BITS_PER_WORD);
2861 rtx *result_pseudos = (rtx *) alloca (sizeof (rtx) * n_regs);
2862 rtx result_reg, src, dst;
2863 rtx result_val = expand_expr (retval_rhs, NULL_RTX, VOIDmode, 0);
2864 enum machine_mode tmpmode, result_reg_mode;
2866 /* Structures whose size is not a multiple of a word are aligned
2867 to the least significant byte (to the right). On a BYTES_BIG_ENDIAN
2868 machine, this means we must skip the empty high order bytes when
2869 calculating the bit offset. */
2870 if (BYTES_BIG_ENDIAN && bytes % UNITS_PER_WORD)
2871 big_endian_correction = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD)
2874 /* Copy the structure BITSIZE bits at a time. */
2875 for (bitpos = 0, xbitpos = big_endian_correction;
2876 bitpos < bytes * BITS_PER_UNIT;
2877 bitpos += bitsize, xbitpos += bitsize)
2879 /* We need a new destination pseudo each time xbitpos is
2880 on a word boundary and when xbitpos == big_endian_correction
2881 (the first time through). */
2882 if (xbitpos % BITS_PER_WORD == 0
2883 || xbitpos == big_endian_correction)
2885 /* Generate an appropriate register. */
2886 dst = gen_reg_rtx (word_mode);
2887 result_pseudos[xbitpos / BITS_PER_WORD] = dst;
2889 /* Clobber the destination before we move anything into it. */
2890 emit_insn (gen_rtx (CLOBBER, VOIDmode, dst));
2893 /* We need a new source operand each time bitpos is on a word
2895 if (bitpos % BITS_PER_WORD == 0)
2896 src = operand_subword_force (result_val,
2897 bitpos / BITS_PER_WORD,
2900 /* Use bitpos for the source extraction (left justified) and
2901 xbitpos for the destination store (right justified). */
2902 store_bit_field (dst, bitsize, xbitpos % BITS_PER_WORD, word_mode,
2903 extract_bit_field (src, bitsize,
2904 bitpos % BITS_PER_WORD, 1,
2905 NULL_RTX, word_mode,
2907 bitsize / BITS_PER_UNIT,
2909 bitsize / BITS_PER_UNIT, BITS_PER_WORD);
2912 /* Find the smallest integer mode large enough to hold the
2913 entire structure and use that mode instead of BLKmode
2914 on the USE insn for the return register. */
2915 bytes = int_size_in_bytes (TREE_TYPE (retval_rhs));
2916 for (tmpmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2917 tmpmode != MAX_MACHINE_MODE;
2918 tmpmode = GET_MODE_WIDER_MODE (tmpmode))
2920 /* Have we found a large enough mode? */
2921 if (GET_MODE_SIZE (tmpmode) >= bytes)
2925 /* No suitable mode found. */
2926 if (tmpmode == MAX_MACHINE_MODE)
2929 PUT_MODE (DECL_RTL (DECL_RESULT (current_function_decl)), tmpmode);
2931 if (GET_MODE_SIZE (tmpmode) < GET_MODE_SIZE (word_mode))
2932 result_reg_mode = word_mode;
2934 result_reg_mode = tmpmode;
2935 result_reg = gen_reg_rtx (result_reg_mode);
2938 for (i = 0; i < n_regs; i++)
2939 emit_move_insn (operand_subword (result_reg, i, 0, result_reg_mode),
2942 if (tmpmode != result_reg_mode)
2943 result_reg = gen_lowpart (tmpmode, result_reg);
2945 expand_value_return (result_reg);
2949 && TREE_TYPE (retval_rhs) != void_type_node
2950 && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG)
2952 /* Calculate the return value into a pseudo reg. */
2953 val = gen_reg_rtx (DECL_MODE (DECL_RESULT (current_function_decl)));
2954 val = expand_expr (retval_rhs, val, GET_MODE (val), 0);
2955 val = force_not_mem (val);
2957 /* Return the calculated value, doing cleanups first. */
2958 expand_value_return (val);
2962 /* No cleanups or no hard reg used;
2963 calculate value into hard return reg. */
2964 expand_expr (retval, const0_rtx, VOIDmode, 0);
2966 expand_value_return (DECL_RTL (DECL_RESULT (current_function_decl)));
2970 /* Return 1 if the end of the generated RTX is not a barrier.
2971 This means code already compiled can drop through. */
2974 drop_through_at_end_p ()
2976 rtx insn = get_last_insn ();
2977 while (insn && GET_CODE (insn) == NOTE)
2978 insn = PREV_INSN (insn);
2979 return insn && GET_CODE (insn) != BARRIER;
2982 /* Emit code to alter this function's formal parms for a tail-recursive call.
2983 ACTUALS is a list of actual parameter expressions (chain of TREE_LISTs).
2984 FORMALS is the chain of decls of formals.
2985 Return 1 if this can be done;
2986 otherwise return 0 and do not emit any code. */
2989 tail_recursion_args (actuals, formals)
2990 tree actuals, formals;
2992 register tree a = actuals, f = formals;
2994 register rtx *argvec;
2996 /* Check that number and types of actuals are compatible
2997 with the formals. This is not always true in valid C code.
2998 Also check that no formal needs to be addressable
2999 and that all formals are scalars. */
3001 /* Also count the args. */
3003 for (a = actuals, f = formals, i = 0; a && f; a = TREE_CHAIN (a), f = TREE_CHAIN (f), i++)
3005 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (a)))
3006 != TYPE_MAIN_VARIANT (TREE_TYPE (f)))
3008 if (GET_CODE (DECL_RTL (f)) != REG || DECL_MODE (f) == BLKmode)
3011 if (a != 0 || f != 0)
3014 /* Compute all the actuals. */
3016 argvec = (rtx *) alloca (i * sizeof (rtx));
3018 for (a = actuals, i = 0; a; a = TREE_CHAIN (a), i++)
3019 argvec[i] = expand_expr (TREE_VALUE (a), NULL_RTX, VOIDmode, 0);
3021 /* Find which actual values refer to current values of previous formals.
3022 Copy each of them now, before any formal is changed. */
3024 for (a = actuals, i = 0; a; a = TREE_CHAIN (a), i++)
3028 for (f = formals, j = 0; j < i; f = TREE_CHAIN (f), j++)
3029 if (reg_mentioned_p (DECL_RTL (f), argvec[i]))
3030 { copy = 1; break; }
3032 argvec[i] = copy_to_reg (argvec[i]);
3035 /* Store the values of the actuals into the formals. */
3037 for (f = formals, a = actuals, i = 0; f;
3038 f = TREE_CHAIN (f), a = TREE_CHAIN (a), i++)
3040 if (GET_MODE (DECL_RTL (f)) == GET_MODE (argvec[i]))
3041 emit_move_insn (DECL_RTL (f), argvec[i]);
3043 convert_move (DECL_RTL (f), argvec[i],
3044 TREE_UNSIGNED (TREE_TYPE (TREE_VALUE (a))));
3051 /* Generate the RTL code for entering a binding contour.
3052 The variables are declared one by one, by calls to `expand_decl'.
3054 EXIT_FLAG is nonzero if this construct should be visible to
3055 `exit_something'. */
3058 expand_start_bindings (exit_flag)
3061 struct nesting *thisblock = ALLOC_NESTING ();
3062 rtx note = output_bytecode ? 0 : emit_note (NULL_PTR, NOTE_INSN_BLOCK_BEG);
3064 /* Make an entry on block_stack for the block we are entering. */
3066 thisblock->next = block_stack;
3067 thisblock->all = nesting_stack;
3068 thisblock->depth = ++nesting_depth;
3069 thisblock->data.block.stack_level = 0;
3070 thisblock->data.block.cleanups = 0;
3071 thisblock->data.block.function_call_count = 0;
3072 thisblock->data.block.exception_region = 0;
3073 thisblock->data.block.target_temp_slot_level = target_temp_slot_level;
3075 thisblock->data.block.conditional_code = 0;
3076 thisblock->data.block.last_unconditional_cleanup = note;
3077 thisblock->data.block.cleanup_ptr = &thisblock->data.block.cleanups;
3080 && !(block_stack->data.block.cleanups == NULL_TREE
3081 && block_stack->data.block.outer_cleanups == NULL_TREE))
3082 thisblock->data.block.outer_cleanups
3083 = tree_cons (NULL_TREE, block_stack->data.block.cleanups,
3084 block_stack->data.block.outer_cleanups);
3086 thisblock->data.block.outer_cleanups = 0;
3087 thisblock->data.block.label_chain = 0;
3088 thisblock->data.block.innermost_stack_block = stack_block_stack;
3089 thisblock->data.block.first_insn = note;
3090 thisblock->data.block.block_start_count = ++block_start_count;
3091 thisblock->exit_label = exit_flag ? gen_label_rtx () : 0;
3092 block_stack = thisblock;
3093 nesting_stack = thisblock;
3095 if (!output_bytecode)
3097 /* Make a new level for allocating stack slots. */
3102 /* Specify the scope of temporaries created by TARGET_EXPRs. Similar
3103 to CLEANUP_POINT_EXPR, but handles cases when a series of calls to
3104 expand_expr are made. After we end the region, we know that all
3105 space for all temporaries that were created by TARGET_EXPRs will be
3106 destroyed and their space freed for reuse. */
3109 expand_start_target_temps ()
3111 /* This is so that even if the result is preserved, the space
3112 allocated will be freed, as we know that it is no longer in use. */
3115 /* Start a new binding layer that will keep track of all cleanup
3116 actions to be performed. */
3117 expand_start_bindings (0);
3119 target_temp_slot_level = temp_slot_level;
3123 expand_end_target_temps ()
3125 expand_end_bindings (NULL_TREE, 0, 0);
3127 /* This is so that even if the result is preserved, the space
3128 allocated will be freed, as we know that it is no longer in use. */
3132 /* Mark top block of block_stack as an implicit binding for an
3133 exception region. This is used to prevent infinite recursion when
3134 ending a binding with expand_end_bindings. It is only ever called
3135 by expand_eh_region_start, as that it the only way to create a
3136 block stack for a exception region. */
3139 mark_block_as_eh_region ()
3141 block_stack->data.block.exception_region = 1;
3142 if (block_stack->next
3143 && block_stack->next->data.block.conditional_code)
3145 block_stack->data.block.conditional_code
3146 = block_stack->next->data.block.conditional_code;
3147 block_stack->data.block.last_unconditional_cleanup
3148 = block_stack->next->data.block.last_unconditional_cleanup;
3149 block_stack->data.block.cleanup_ptr
3150 = block_stack->next->data.block.cleanup_ptr;
3154 /* True if we are currently emitting insns in an area of output code
3155 that is controlled by a conditional expression. This is used by
3156 the cleanup handling code to generate conditional cleanup actions. */
3159 conditional_context ()
3161 return block_stack && block_stack->data.block.conditional_code;
3164 /* Mark top block of block_stack as not for an implicit binding for an
3165 exception region. This is only ever done by expand_eh_region_end
3166 to let expand_end_bindings know that it is being called explicitly
3167 to end the binding layer for just the binding layer associated with
3168 the exception region, otherwise expand_end_bindings would try and
3169 end all implicit binding layers for exceptions regions, and then
3170 one normal binding layer. */
3173 mark_block_as_not_eh_region ()
3175 block_stack->data.block.exception_region = 0;
3178 /* True if the top block of block_stack was marked as for an exception
3179 region by mark_block_as_eh_region. */
3184 return block_stack && block_stack->data.block.exception_region;
3187 /* Given a pointer to a BLOCK node, save a pointer to the most recently
3188 generated NOTE_INSN_BLOCK_END in the BLOCK_END_NOTE field of the given
3192 remember_end_note (block)
3193 register tree block;
3195 BLOCK_END_NOTE (block) = last_block_end_note;
3196 last_block_end_note = NULL_RTX;
3199 /* Generate RTL code to terminate a binding contour.
3200 VARS is the chain of VAR_DECL nodes
3201 for the variables bound in this contour.
3202 MARK_ENDS is nonzero if we should put a note at the beginning
3203 and end of this binding contour.
3205 DONT_JUMP_IN is nonzero if it is not valid to jump into this contour.
3206 (That is true automatically if the contour has a saved stack level.) */
3209 expand_end_bindings (vars, mark_ends, dont_jump_in)
3214 register struct nesting *thisblock;
3217 while (block_stack->data.block.exception_region)
3219 /* Because we don't need or want a new temporary level and
3220 because we didn't create one in expand_eh_region_start,
3221 create a fake one now to avoid removing one in
3222 expand_end_bindings. */
3225 block_stack->data.block.exception_region = 0;
3227 expand_end_bindings (NULL_TREE, 0, 0);
3230 if (output_bytecode)
3232 bc_expand_end_bindings (vars, mark_ends, dont_jump_in);
3236 /* Since expand_eh_region_start does an expand_start_bindings, we
3237 have to first end all the bindings that were created by
3238 expand_eh_region_start. */
3240 thisblock = block_stack;
3243 for (decl = vars; decl; decl = TREE_CHAIN (decl))
3244 if (! TREE_USED (decl) && TREE_CODE (decl) == VAR_DECL
3245 && ! DECL_IN_SYSTEM_HEADER (decl))
3246 warning_with_decl (decl, "unused variable `%s'");
3248 if (thisblock->exit_label)
3250 do_pending_stack_adjust ();
3251 emit_label (thisblock->exit_label);
3254 /* If necessary, make a handler for nonlocal gotos taking
3255 place in the function calls in this block. */
3256 if (function_call_count != thisblock->data.block.function_call_count
3258 /* Make handler for outermost block
3259 if there were any nonlocal gotos to this function. */
3260 && (thisblock->next == 0 ? current_function_has_nonlocal_label
3261 /* Make handler for inner block if it has something
3262 special to do when you jump out of it. */
3263 : (thisblock->data.block.cleanups != 0
3264 || thisblock->data.block.stack_level != 0)))
3267 rtx afterward = gen_label_rtx ();
3268 rtx handler_label = gen_label_rtx ();
3269 rtx save_receiver = gen_reg_rtx (Pmode);
3272 /* Don't let jump_optimize delete the handler. */
3273 LABEL_PRESERVE_P (handler_label) = 1;
3275 /* Record the handler address in the stack slot for that purpose,
3276 during this block, saving and restoring the outer value. */
3277 if (thisblock->next != 0)
3279 emit_move_insn (nonlocal_goto_handler_slot, save_receiver);
3282 emit_move_insn (save_receiver, nonlocal_goto_handler_slot);
3283 insns = get_insns ();
3285 emit_insns_before (insns, thisblock->data.block.first_insn);
3289 emit_move_insn (nonlocal_goto_handler_slot,
3290 gen_rtx (LABEL_REF, Pmode, handler_label));
3291 insns = get_insns ();
3293 emit_insns_before (insns, thisblock->data.block.first_insn);
3295 /* Jump around the handler; it runs only when specially invoked. */
3296 emit_jump (afterward);
3297 emit_label (handler_label);
3299 #ifdef HAVE_nonlocal_goto
3300 if (! HAVE_nonlocal_goto)
3302 /* First adjust our frame pointer to its actual value. It was
3303 previously set to the start of the virtual area corresponding to
3304 the stacked variables when we branched here and now needs to be
3305 adjusted to the actual hardware fp value.
3307 Assignments are to virtual registers are converted by
3308 instantiate_virtual_regs into the corresponding assignment
3309 to the underlying register (fp in this case) that makes
3310 the original assignment true.
3311 So the following insn will actually be
3312 decrementing fp by STARTING_FRAME_OFFSET. */
3313 emit_move_insn (virtual_stack_vars_rtx, hard_frame_pointer_rtx);
3315 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3316 if (fixed_regs[ARG_POINTER_REGNUM])
3318 #ifdef ELIMINABLE_REGS
3319 /* If the argument pointer can be eliminated in favor of the
3320 frame pointer, we don't need to restore it. We assume here
3321 that if such an elimination is present, it can always be used.
3322 This is the case on all known machines; if we don't make this
3323 assumption, we do unnecessary saving on many machines. */
3324 static struct elims {int from, to;} elim_regs[] = ELIMINABLE_REGS;
3327 for (i = 0; i < sizeof elim_regs / sizeof elim_regs[0]; i++)
3328 if (elim_regs[i].from == ARG_POINTER_REGNUM
3329 && elim_regs[i].to == HARD_FRAME_POINTER_REGNUM)
3332 if (i == sizeof elim_regs / sizeof elim_regs [0])
3335 /* Now restore our arg pointer from the address at which it
3336 was saved in our stack frame.
3337 If there hasn't be space allocated for it yet, make
3339 if (arg_pointer_save_area == 0)
3340 arg_pointer_save_area
3341 = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
3342 emit_move_insn (virtual_incoming_args_rtx,
3343 /* We need a pseudo here, or else
3344 instantiate_virtual_regs_1 complains. */
3345 copy_to_reg (arg_pointer_save_area));
3350 #ifdef HAVE_nonlocal_goto_receiver
3351 if (HAVE_nonlocal_goto_receiver)
3352 emit_insn (gen_nonlocal_goto_receiver ());
3355 /* The handler expects the desired label address in the static chain
3356 register. It tests the address and does an appropriate jump
3357 to whatever label is desired. */
3358 for (link = nonlocal_labels; link; link = TREE_CHAIN (link))
3359 /* Skip any labels we shouldn't be able to jump to from here. */
3360 if (! DECL_TOO_LATE (TREE_VALUE (link)))
3362 rtx not_this = gen_label_rtx ();
3363 rtx this = gen_label_rtx ();
3364 do_jump_if_equal (static_chain_rtx,
3365 gen_rtx (LABEL_REF, Pmode, DECL_RTL (TREE_VALUE (link))),
3367 emit_jump (not_this);
3369 expand_goto (TREE_VALUE (link));
3370 emit_label (not_this);
3372 /* If label is not recognized, abort. */
3373 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "abort"), 0,
3376 emit_label (afterward);
3379 /* Don't allow jumping into a block that has cleanups or a stack level. */
3381 || thisblock->data.block.stack_level != 0
3382 || thisblock->data.block.cleanups != 0)
3384 struct label_chain *chain;
3386 /* Any labels in this block are no longer valid to go to.
3387 Mark them to cause an error message. */
3388 for (chain = thisblock->data.block.label_chain; chain; chain = chain->next)
3390 DECL_TOO_LATE (chain->label) = 1;
3391 /* If any goto without a fixup came to this label,
3392 that must be an error, because gotos without fixups
3393 come from outside all saved stack-levels and all cleanups. */
3394 if (TREE_ADDRESSABLE (chain->label))
3395 error_with_decl (chain->label,
3396 "label `%s' used before containing binding contour");
3400 /* Restore stack level in effect before the block
3401 (only if variable-size objects allocated). */
3402 /* Perform any cleanups associated with the block. */
3404 if (thisblock->data.block.stack_level != 0
3405 || thisblock->data.block.cleanups != 0)
3407 /* Only clean up here if this point can actually be reached. */
3408 int reachable = GET_CODE (get_last_insn ()) != BARRIER;
3410 /* Don't let cleanups affect ({...}) constructs. */
3411 int old_expr_stmts_for_value = expr_stmts_for_value;
3412 rtx old_last_expr_value = last_expr_value;
3413 tree old_last_expr_type = last_expr_type;
3414 expr_stmts_for_value = 0;
3416 /* Do the cleanups. */
3417 expand_cleanups (thisblock->data.block.cleanups, NULL_TREE, 0, reachable);
3419 do_pending_stack_adjust ();
3421 expr_stmts_for_value = old_expr_stmts_for_value;
3422 last_expr_value = old_last_expr_value;
3423 last_expr_type = old_last_expr_type;
3425 /* Restore the stack level. */
3427 if (reachable && thisblock->data.block.stack_level != 0)
3429 emit_stack_restore (thisblock->next ? SAVE_BLOCK : SAVE_FUNCTION,
3430 thisblock->data.block.stack_level, NULL_RTX);
3431 if (nonlocal_goto_handler_slot != 0)
3432 emit_stack_save (SAVE_NONLOCAL, &nonlocal_goto_stack_level,
3436 /* Any gotos out of this block must also do these things.
3437 Also report any gotos with fixups that came to labels in this
3439 fixup_gotos (thisblock,
3440 thisblock->data.block.stack_level,
3441 thisblock->data.block.cleanups,
3442 thisblock->data.block.first_insn,
3446 /* Mark the beginning and end of the scope if requested.
3447 We do this now, after running cleanups on the variables
3448 just going out of scope, so they are in scope for their cleanups. */
3451 last_block_end_note = emit_note (NULL_PTR, NOTE_INSN_BLOCK_END);
3453 /* Get rid of the beginning-mark if we don't make an end-mark. */
3454 NOTE_LINE_NUMBER (thisblock->data.block.first_insn) = NOTE_INSN_DELETED;
3456 /* If doing stupid register allocation, make sure lives of all
3457 register variables declared here extend thru end of scope. */
3460 for (decl = vars; decl; decl = TREE_CHAIN (decl))
3462 rtx rtl = DECL_RTL (decl);
3463 if (TREE_CODE (decl) == VAR_DECL && rtl != 0)
3467 /* Restore the temporary level of TARGET_EXPRs. */
3468 target_temp_slot_level = thisblock->data.block.target_temp_slot_level;
3470 /* Restore block_stack level for containing block. */
3472 stack_block_stack = thisblock->data.block.innermost_stack_block;
3473 POPSTACK (block_stack);
3475 /* Pop the stack slot nesting and free any slots at this level. */
3480 /* End a binding contour.
3481 VARS is the chain of VAR_DECL nodes for the variables bound
3482 in this contour. MARK_ENDS is nonzer if we should put a note
3483 at the beginning and end of this binding contour.
3484 DONT_JUMP_IN is nonzero if it is not valid to jump into this
3488 bc_expand_end_bindings (vars, mark_ends, dont_jump_in)
3493 struct nesting *thisbind = nesting_stack;
3497 for (decl = vars; decl; decl = TREE_CHAIN (decl))
3498 if (! TREE_USED (TREE_VALUE (decl)) && TREE_CODE (TREE_VALUE (decl)) == VAR_DECL)
3499 warning_with_decl (decl, "unused variable `%s'");
3501 if (thisbind->exit_label)
3502 bc_emit_bytecode_labeldef (BYTECODE_BC_LABEL (thisbind->exit_label));
3504 /* Pop block/bindings off stack */
3505 POPSTACK (block_stack);
3508 /* Generate RTL for the automatic variable declaration DECL.
3509 (Other kinds of declarations are simply ignored if seen here.) */
3515 struct nesting *thisblock = block_stack;
3518 if (output_bytecode)
3520 bc_expand_decl (decl, 0);
3524 type = TREE_TYPE (decl);
3526 /* Only automatic variables need any expansion done.
3527 Static and external variables, and external functions,
3528 will be handled by `assemble_variable' (called from finish_decl).
3529 TYPE_DECL and CONST_DECL require nothing.
3530 PARM_DECLs are handled in `assign_parms'. */
3532 if (TREE_CODE (decl) != VAR_DECL)
3534 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl))
3537 /* Create the RTL representation for the variable. */
3539 if (type == error_mark_node)
3540 DECL_RTL (decl) = gen_rtx (MEM, BLKmode, const0_rtx);
3541 else if (DECL_SIZE (decl) == 0)
3542 /* Variable with incomplete type. */
3544 if (DECL_INITIAL (decl) == 0)
3545 /* Error message was already done; now avoid a crash. */
3546 DECL_RTL (decl) = assign_stack_temp (DECL_MODE (decl), 0, 1);
3548 /* An initializer is going to decide the size of this array.
3549 Until we know the size, represent its address with a reg. */
3550 DECL_RTL (decl) = gen_rtx (MEM, BLKmode, gen_reg_rtx (Pmode));
3551 MEM_IN_STRUCT_P (DECL_RTL (decl)) = AGGREGATE_TYPE_P (type);
3553 else if (DECL_MODE (decl) != BLKmode
3554 /* If -ffloat-store, don't put explicit float vars
3556 && !(flag_float_store
3557 && TREE_CODE (type) == REAL_TYPE)
3558 && ! TREE_THIS_VOLATILE (decl)
3559 && ! TREE_ADDRESSABLE (decl)
3560 && (DECL_REGISTER (decl) || ! obey_regdecls))
3562 /* Automatic variable that can go in a register. */
3563 int unsignedp = TREE_UNSIGNED (type);
3564 enum machine_mode reg_mode
3565 = promote_mode (type, DECL_MODE (decl), &unsignedp, 0);
3567 DECL_RTL (decl) = gen_reg_rtx (reg_mode);
3568 mark_user_reg (DECL_RTL (decl));
3570 if (TREE_CODE (type) == POINTER_TYPE)
3571 mark_reg_pointer (DECL_RTL (decl),
3572 (TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl)))
3576 else if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
3578 /* Variable of fixed size that goes on the stack. */
3582 /* If we previously made RTL for this decl, it must be an array
3583 whose size was determined by the initializer.
3584 The old address was a register; set that register now
3585 to the proper address. */
3586 if (DECL_RTL (decl) != 0)
3588 if (GET_CODE (DECL_RTL (decl)) != MEM
3589 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != REG)
3591 oldaddr = XEXP (DECL_RTL (decl), 0);
3595 = assign_stack_temp (DECL_MODE (decl),
3596 ((TREE_INT_CST_LOW (DECL_SIZE (decl))
3597 + BITS_PER_UNIT - 1)
3600 MEM_IN_STRUCT_P (DECL_RTL (decl)) = AGGREGATE_TYPE_P (TREE_TYPE (decl));
3602 /* Set alignment we actually gave this decl. */
3603 DECL_ALIGN (decl) = (DECL_MODE (decl) == BLKmode ? BIGGEST_ALIGNMENT
3604 : GET_MODE_BITSIZE (DECL_MODE (decl)));
3608 addr = force_operand (XEXP (DECL_RTL (decl), 0), oldaddr);
3609 if (addr != oldaddr)
3610 emit_move_insn (oldaddr, addr);
3613 /* If this is a memory ref that contains aggregate components,
3614 mark it as such for cse and loop optimize. */
3615 MEM_IN_STRUCT_P (DECL_RTL (decl)) = AGGREGATE_TYPE_P (TREE_TYPE (decl));
3617 /* If this is in memory because of -ffloat-store,
3618 set the volatile bit, to prevent optimizations from
3619 undoing the effects. */
3620 if (flag_float_store && TREE_CODE (type) == REAL_TYPE)
3621 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
3625 /* Dynamic-size object: must push space on the stack. */
3629 /* Record the stack pointer on entry to block, if have
3630 not already done so. */
3631 if (thisblock->data.block.stack_level == 0)
3633 do_pending_stack_adjust ();
3634 emit_stack_save (thisblock->next ? SAVE_BLOCK : SAVE_FUNCTION,
3635 &thisblock->data.block.stack_level,
3636 thisblock->data.block.first_insn);
3637 stack_block_stack = thisblock;
3640 /* Compute the variable's size, in bytes. */
3641 size = expand_expr (size_binop (CEIL_DIV_EXPR,
3643 size_int (BITS_PER_UNIT)),
3644 NULL_RTX, VOIDmode, 0);
3647 /* Allocate space on the stack for the variable. Note that
3648 DECL_ALIGN says how the variable is to be aligned and we
3649 cannot use it to conclude anything about the alignment of
3651 address = allocate_dynamic_stack_space (size, NULL_RTX,
3652 TYPE_ALIGN (TREE_TYPE (decl)));
3654 /* Reference the variable indirect through that rtx. */
3655 DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl), address);
3657 /* If this is a memory ref that contains aggregate components,
3658 mark it as such for cse and loop optimize. */
3659 MEM_IN_STRUCT_P (DECL_RTL (decl)) = AGGREGATE_TYPE_P (TREE_TYPE (decl));
3661 /* Indicate the alignment we actually gave this variable. */
3662 #ifdef STACK_BOUNDARY
3663 DECL_ALIGN (decl) = STACK_BOUNDARY;
3665 DECL_ALIGN (decl) = BIGGEST_ALIGNMENT;
3669 if (TREE_THIS_VOLATILE (decl))
3670 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
3671 #if 0 /* A variable is not necessarily unchanging
3672 just because it is const. RTX_UNCHANGING_P
3673 means no change in the function,
3674 not merely no change in the variable's scope.
3675 It is correct to set RTX_UNCHANGING_P if the variable's scope
3676 is the whole function. There's no convenient way to test that. */
3677 if (TREE_READONLY (decl))
3678 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
3681 /* If doing stupid register allocation, make sure life of any
3682 register variable starts here, at the start of its scope. */
3685 use_variable (DECL_RTL (decl));
3689 /* Generate code for the automatic variable declaration DECL. For
3690 most variables this just means we give it a stack offset. The
3691 compiler sometimes emits cleanups without variables and we will
3692 have to deal with those too. */
3695 bc_expand_decl (decl, cleanup)
3703 /* A cleanup with no variable. */
3710 /* Only auto variables need any work. */
3711 if (TREE_CODE (decl) != VAR_DECL || TREE_STATIC (decl) || DECL_EXTERNAL (decl))
3714 type = TREE_TYPE (decl);
3716 if (type == error_mark_node)
3717 DECL_RTL (decl) = bc_gen_rtx ((char *) 0, 0, (struct bc_label *) 0);
3719 else if (DECL_SIZE (decl) == 0)
3721 /* Variable with incomplete type. The stack offset herein will be
3722 fixed later in expand_decl_init. */
3723 DECL_RTL (decl) = bc_gen_rtx ((char *) 0, 0, (struct bc_label *) 0);
3725 else if (TREE_CONSTANT (DECL_SIZE (decl)))
3727 DECL_RTL (decl) = bc_allocate_local (TREE_INT_CST_LOW (DECL_SIZE (decl)) / BITS_PER_UNIT,
3731 DECL_RTL (decl) = bc_allocate_variable_array (DECL_SIZE (decl));
3734 /* Emit code to perform the initialization of a declaration DECL. */
3737 expand_decl_init (decl)
3740 int was_used = TREE_USED (decl);
3742 if (output_bytecode)
3744 bc_expand_decl_init (decl);
3748 /* If this is a CONST_DECL, we don't have to generate any code, but
3749 if DECL_INITIAL is a constant, call expand_expr to force TREE_CST_RTL
3750 to be set while in the obstack containing the constant. If we don't
3751 do this, we can lose if we have functions nested three deep and the middle
3752 function makes a CONST_DECL whose DECL_INITIAL is a STRING_CST while
3753 the innermost function is the first to expand that STRING_CST. */
3754 if (TREE_CODE (decl) == CONST_DECL)
3756 if (DECL_INITIAL (decl) && TREE_CONSTANT (DECL_INITIAL (decl)))
3757 expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode,
3758 EXPAND_INITIALIZER);
3762 if (TREE_STATIC (decl))
3765 /* Compute and store the initial value now. */
3767 if (DECL_INITIAL (decl) == error_mark_node)
3769 enum tree_code code = TREE_CODE (TREE_TYPE (decl));
3770 if (code == INTEGER_TYPE || code == REAL_TYPE || code == ENUMERAL_TYPE
3771 || code == POINTER_TYPE)
3772 expand_assignment (decl, convert (TREE_TYPE (decl), integer_zero_node),
3776 else if (DECL_INITIAL (decl) && TREE_CODE (DECL_INITIAL (decl)) != TREE_LIST)
3778 emit_line_note (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
3779 expand_assignment (decl, DECL_INITIAL (decl), 0, 0);
3783 /* Don't let the initialization count as "using" the variable. */
3784 TREE_USED (decl) = was_used;
3786 /* Free any temporaries we made while initializing the decl. */
3787 preserve_temp_slots (NULL_RTX);
3791 /* Expand initialization for variable-sized types. Allocate array
3792 using newlocalSI and set local variable, which is a pointer to the
3796 bc_expand_variable_local_init (decl)
3799 /* Evaluate size expression and coerce to SI */
3800 bc_expand_expr (DECL_SIZE (decl));
3802 /* Type sizes are always (?) of TREE_CODE INTEGER_CST, so
3803 no coercion is necessary (?) */
3805 /* emit_typecode_conversion (preferred_typecode (TYPE_MODE (DECL_SIZE (decl)),
3806 TREE_UNSIGNED (DECL_SIZE (decl))), SIcode); */
3808 /* Emit code to allocate array */
3809 bc_emit_instruction (newlocalSI);
3811 /* Store array pointer in local variable. This is the only instance
3812 where we actually want the address of the pointer to the
3813 variable-size block, rather than the pointer itself. We avoid
3814 using expand_address() since that would cause the pointer to be
3815 pushed rather than its address. Hence the hard-coded reference;
3816 notice also that the variable is always local (no global
3817 variable-size type variables). */
3819 bc_load_localaddr (DECL_RTL (decl));
3820 bc_emit_instruction (storeP);
3824 /* Emit code to initialize a declaration. */
3827 bc_expand_decl_init (decl)
3830 int org_stack_depth;
3832 /* Statical initializers are handled elsewhere */
3834 if (TREE_STATIC (decl))
3837 /* Memory original stack depth */
3838 org_stack_depth = stack_depth;
3840 /* If the type is variable-size, we first create its space (we ASSUME
3841 it CAN'T be static). We do this regardless of whether there's an
3842 initializer assignment or not. */
3844 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
3845 bc_expand_variable_local_init (decl);
3847 /* Expand initializer assignment */
3848 if (DECL_INITIAL (decl) == error_mark_node)
3850 enum tree_code code = TREE_CODE (TREE_TYPE (decl));
3852 if (code == INTEGER_TYPE || code == REAL_TYPE || code == ENUMERAL_TYPE
3853 || code == POINTER_TYPE)
3855 expand_assignment (TREE_TYPE (decl), decl, 0, 0);
3857 else if (DECL_INITIAL (decl))
3858 expand_assignment (TREE_TYPE (decl), decl, 0, 0);
3860 /* Restore stack depth */
3861 if (org_stack_depth > stack_depth)
3864 bc_adjust_stack (stack_depth - org_stack_depth);
3868 /* CLEANUP is an expression to be executed at exit from this binding contour;
3869 for example, in C++, it might call the destructor for this variable.
3871 We wrap CLEANUP in an UNSAVE_EXPR node, so that we can expand the
3872 CLEANUP multiple times, and have the correct semantics. This
3873 happens in exception handling, for gotos, returns, breaks that
3874 leave the current scope.
3876 If CLEANUP is nonzero and DECL is zero, we record a cleanup
3877 that is not associated with any particular variable. */
3880 expand_decl_cleanup (decl, cleanup)
3883 struct nesting *thisblock = block_stack;
3885 /* Error if we are not in any block. */
3889 /* Record the cleanup if there is one. */
3895 tree *cleanups = &thisblock->data.block.cleanups;
3896 int cond_context = conditional_context ();
3900 rtx flag = gen_reg_rtx (word_mode);
3905 emit_move_insn (flag, const0_rtx);
3906 set_flag_0 = get_insns ();
3909 thisblock->data.block.last_unconditional_cleanup
3910 = emit_insns_after (set_flag_0,
3911 thisblock->data.block.last_unconditional_cleanup);
3913 emit_move_insn (flag, const1_rtx);
3915 /* All cleanups must be on the function_obstack. */
3916 push_obstacks_nochange ();
3917 resume_temporary_allocation ();
3919 cond = build_decl (VAR_DECL, NULL_TREE, type_for_mode (word_mode, 1));
3920 DECL_RTL (cond) = flag;
3922 /* Conditionalize the cleanup. */
3923 cleanup = build (COND_EXPR, void_type_node,
3924 truthvalue_conversion (cond),
3925 cleanup, integer_zero_node);
3926 cleanup = fold (cleanup);
3930 cleanups = thisblock->data.block.cleanup_ptr;
3933 /* All cleanups must be on the function_obstack. */
3934 push_obstacks_nochange ();
3935 resume_temporary_allocation ();
3936 cleanup = unsave_expr (cleanup);
3939 t = *cleanups = temp_tree_cons (decl, cleanup, *cleanups);
3942 /* If this block has a cleanup, it belongs in stack_block_stack. */
3943 stack_block_stack = thisblock;
3950 /* If this was optimized so that there is no exception region for the
3951 cleanup, then mark the TREE_LIST node, so that we can later tell
3952 if we need to call expand_eh_region_end. */
3953 if (expand_eh_region_start_tree (cleanup))
3954 TREE_ADDRESSABLE (t) = 1;
3960 thisblock->data.block.last_unconditional_cleanup
3961 = emit_insns_after (seq,
3962 thisblock->data.block.last_unconditional_cleanup);
3966 thisblock->data.block.last_unconditional_cleanup
3968 thisblock->data.block.cleanup_ptr = &thisblock->data.block.cleanups;
3974 /* Arrange for the top element of the dynamic cleanup chain to be
3975 popped if we exit the current binding contour. If the current
3976 contour is left via an exception, then __sjthrow will pop the top
3977 element off the dynamic cleanup chain. The code that avoids doing
3978 the action we push into the cleanup chain in the exceptional case
3979 is contained in expand_cleanups.
3981 This routine is only used by expand_eh_region_start, and that is
3982 the only way in which an exception region should be started. This
3983 routine is only used when using the setjmp/longjmp codegen method
3984 for exception handling. */
3987 expand_dcc_cleanup ()
3989 struct nesting *thisblock = block_stack;
3992 /* Error if we are not in any block. */
3996 /* Record the cleanup for the dynamic handler chain. */
3998 /* All cleanups must be on the function_obstack. */
3999 push_obstacks_nochange ();
4000 resume_temporary_allocation ();
4001 cleanup = make_node (POPDCC_EXPR);
4004 /* Add the cleanup in a manner similar to expand_decl_cleanup. */
4005 thisblock->data.block.cleanups
4006 = temp_tree_cons (NULL_TREE, cleanup, thisblock->data.block.cleanups);
4008 /* If this block has a cleanup, it belongs in stack_block_stack. */
4009 stack_block_stack = thisblock;
4013 /* Arrange for the top element of the dynamic handler chain to be
4014 popped if we exit the current binding contour. If the current
4015 contour is left via an exception, then __sjthrow will pop the
4016 top element off the dynamic handler chain. The code that avoids
4017 doing the action we push into the handler chain in the exceptional
4018 case is contained in expand_cleanups.
4020 This routine is only used by expand_eh_region_start, and that is
4021 the only way in which an exception region should be started. This
4022 routine is only used when using the setjmp/longjmp codegen method
4023 for exception handling. */
4026 expand_dhc_cleanup ()
4028 struct nesting *thisblock = block_stack;
4031 /* Error if we are not in any block. */
4035 /* Record the cleanup for the dynamic handler chain. */
4037 /* All cleanups must be on the function_obstack. */
4038 push_obstacks_nochange ();
4039 resume_temporary_allocation ();
4040 cleanup = make_node (POPDHC_EXPR);
4043 /* Add the cleanup in a manner similar to expand_decl_cleanup. */
4044 thisblock->data.block.cleanups
4045 = temp_tree_cons (NULL_TREE, cleanup, thisblock->data.block.cleanups);
4047 /* If this block has a cleanup, it belongs in stack_block_stack. */
4048 stack_block_stack = thisblock;
4052 /* DECL is an anonymous union. CLEANUP is a cleanup for DECL.
4053 DECL_ELTS is the list of elements that belong to DECL's type.
4054 In each, the TREE_VALUE is a VAR_DECL, and the TREE_PURPOSE a cleanup. */
4057 expand_anon_union_decl (decl, cleanup, decl_elts)
4058 tree decl, cleanup, decl_elts;
4060 struct nesting *thisblock = block_stack;
4064 expand_decl_cleanup (decl, cleanup);
4065 x = DECL_RTL (decl);
4069 tree decl_elt = TREE_VALUE (decl_elts);
4070 tree cleanup_elt = TREE_PURPOSE (decl_elts);
4071 enum machine_mode mode = TYPE_MODE (TREE_TYPE (decl_elt));
4073 /* Propagate the union's alignment to the elements. */
4074 DECL_ALIGN (decl_elt) = DECL_ALIGN (decl);
4076 /* If the element has BLKmode and the union doesn't, the union is
4077 aligned such that the element doesn't need to have BLKmode, so
4078 change the element's mode to the appropriate one for its size. */
4079 if (mode == BLKmode && DECL_MODE (decl) != BLKmode)
4080 DECL_MODE (decl_elt) = mode
4081 = mode_for_size (TREE_INT_CST_LOW (DECL_SIZE (decl_elt)),
4084 /* (SUBREG (MEM ...)) at RTL generation time is invalid, so we
4085 instead create a new MEM rtx with the proper mode. */
4086 if (GET_CODE (x) == MEM)
4088 if (mode == GET_MODE (x))
4089 DECL_RTL (decl_elt) = x;
4092 DECL_RTL (decl_elt) = gen_rtx (MEM, mode, copy_rtx (XEXP (x, 0)));
4093 MEM_IN_STRUCT_P (DECL_RTL (decl_elt)) = MEM_IN_STRUCT_P (x);
4094 RTX_UNCHANGING_P (DECL_RTL (decl_elt)) = RTX_UNCHANGING_P (x);
4097 else if (GET_CODE (x) == REG)
4099 if (mode == GET_MODE (x))
4100 DECL_RTL (decl_elt) = x;
4102 DECL_RTL (decl_elt) = gen_rtx (SUBREG, mode, x, 0);
4107 /* Record the cleanup if there is one. */
4110 thisblock->data.block.cleanups
4111 = temp_tree_cons (decl_elt, cleanup_elt,
4112 thisblock->data.block.cleanups);
4114 decl_elts = TREE_CHAIN (decl_elts);
4118 /* Expand a list of cleanups LIST.
4119 Elements may be expressions or may be nested lists.
4121 If DONT_DO is nonnull, then any list-element
4122 whose TREE_PURPOSE matches DONT_DO is omitted.
4123 This is sometimes used to avoid a cleanup associated with
4124 a value that is being returned out of the scope.
4126 If IN_FIXUP is non-zero, we are generating this cleanup for a fixup
4127 goto and handle protection regions specially in that case.
4129 If REACHABLE, we emit code, otherwise just inform the exception handling
4130 code about this finalization. */
4133 expand_cleanups (list, dont_do, in_fixup, reachable)
4140 for (tail = list; tail; tail = TREE_CHAIN (tail))
4141 if (dont_do == 0 || TREE_PURPOSE (tail) != dont_do)
4143 if (TREE_CODE (TREE_VALUE (tail)) == TREE_LIST)
4144 expand_cleanups (TREE_VALUE (tail), dont_do, in_fixup, reachable);
4149 tree cleanup = TREE_VALUE (tail);
4151 /* See expand_d{h,c}c_cleanup for why we avoid this. */
4152 if (TREE_CODE (cleanup) != POPDHC_EXPR
4153 && TREE_CODE (cleanup) != POPDCC_EXPR
4154 /* See expand_eh_region_start_tree for this case. */
4155 && ! TREE_ADDRESSABLE (tail))
4157 cleanup = protect_with_terminate (cleanup);
4158 expand_eh_region_end (cleanup);
4164 /* Cleanups may be run multiple times. For example,
4165 when exiting a binding contour, we expand the
4166 cleanups associated with that contour. When a goto
4167 within that binding contour has a target outside that
4168 contour, it will expand all cleanups from its scope to
4169 the target. Though the cleanups are expanded multiple
4170 times, the control paths are non-overlapping so the
4171 cleanups will not be executed twice. */
4172 expand_expr (TREE_VALUE (tail), const0_rtx, VOIDmode, 0);
4179 /* Mark when the context we are emitting RTL for as a conditional
4180 context, so that any cleanup actions we register with
4181 expand_decl_init will be properly conditionalized when those
4182 cleanup actions are later performed. Must be called before any
4183 expression (tree) is expanded that is within a contidional context. */
4186 start_cleanup_deferal ()
4188 ++block_stack->data.block.conditional_code;
4191 /* Mark the end of a conditional region of code. Because cleanup
4192 deferals may be nested, we may still be in a conditional region
4193 after we end the currently deferred cleanups, only after we end all
4194 deferred cleanups, are we back in unconditional code. */
4197 end_cleanup_deferal ()
4199 --block_stack->data.block.conditional_code;
4202 /* Move all cleanups from the current block_stack
4203 to the containing block_stack, where they are assumed to
4204 have been created. If anything can cause a temporary to
4205 be created, but not expanded for more than one level of
4206 block_stacks, then this code will have to change. */
4211 struct nesting *block = block_stack;
4212 struct nesting *outer = block->next;
4214 outer->data.block.cleanups
4215 = chainon (block->data.block.cleanups,
4216 outer->data.block.cleanups);
4217 block->data.block.cleanups = 0;
4221 last_cleanup_this_contour ()
4223 if (block_stack == 0)
4226 return block_stack->data.block.cleanups;
4229 /* Return 1 if there are any pending cleanups at this point.
4230 If THIS_CONTOUR is nonzero, check the current contour as well.
4231 Otherwise, look only at the contours that enclose this one. */
4234 any_pending_cleanups (this_contour)
4237 struct nesting *block;
4239 if (block_stack == 0)
4242 if (this_contour && block_stack->data.block.cleanups != NULL)
4244 if (block_stack->data.block.cleanups == 0
4245 && block_stack->data.block.outer_cleanups == 0)
4248 for (block = block_stack->next; block; block = block->next)
4249 if (block->data.block.cleanups != 0)
4255 /* Enter a case (Pascal) or switch (C) statement.
4256 Push a block onto case_stack and nesting_stack
4257 to accumulate the case-labels that are seen
4258 and to record the labels generated for the statement.
4260 EXIT_FLAG is nonzero if `exit_something' should exit this case stmt.
4261 Otherwise, this construct is transparent for `exit_something'.
4263 EXPR is the index-expression to be dispatched on.
4264 TYPE is its nominal type. We could simply convert EXPR to this type,
4265 but instead we take short cuts. */
4268 expand_start_case (exit_flag, expr, type, printname)
4274 register struct nesting *thiscase = ALLOC_NESTING ();
4276 /* Make an entry on case_stack for the case we are entering. */
4278 thiscase->next = case_stack;
4279 thiscase->all = nesting_stack;
4280 thiscase->depth = ++nesting_depth;
4281 thiscase->exit_label = exit_flag ? gen_label_rtx () : 0;
4282 thiscase->data.case_stmt.case_list = 0;
4283 thiscase->data.case_stmt.index_expr = expr;
4284 thiscase->data.case_stmt.nominal_type = type;
4285 thiscase->data.case_stmt.default_label = 0;
4286 thiscase->data.case_stmt.num_ranges = 0;
4287 thiscase->data.case_stmt.printname = printname;
4288 thiscase->data.case_stmt.seenlabel = 0;
4289 case_stack = thiscase;
4290 nesting_stack = thiscase;
4292 if (output_bytecode)
4294 bc_expand_start_case (thiscase, expr, type, printname);
4298 do_pending_stack_adjust ();
4300 /* Make sure case_stmt.start points to something that won't
4301 need any transformation before expand_end_case. */
4302 if (GET_CODE (get_last_insn ()) != NOTE)
4303 emit_note (NULL_PTR, NOTE_INSN_DELETED);
4305 thiscase->data.case_stmt.start = get_last_insn ();
4309 /* Enter a case statement. It is assumed that the caller has pushed
4310 the current context onto the case stack. */
4313 bc_expand_start_case (thiscase, expr, type, printname)
4314 struct nesting *thiscase;
4319 bc_expand_expr (expr);
4320 bc_expand_conversion (TREE_TYPE (expr), type);
4322 /* For cases, the skip is a place we jump to that's emitted after
4323 the size of the jump table is known. */
4325 thiscase->data.case_stmt.skip_label = gen_label_rtx ();
4326 bc_emit_bytecode (jump);
4327 bc_emit_bytecode_labelref (BYTECODE_BC_LABEL (thiscase->data.case_stmt.skip_label));
4329 #ifdef DEBUG_PRINT_CODE
4330 fputc ('\n', stderr);
4335 /* Start a "dummy case statement" within which case labels are invalid
4336 and are not connected to any larger real case statement.
4337 This can be used if you don't want to let a case statement jump
4338 into the middle of certain kinds of constructs. */
4341 expand_start_case_dummy ()
4343 register struct nesting *thiscase = ALLOC_NESTING ();
4345 /* Make an entry on case_stack for the dummy. */
4347 thiscase->next = case_stack;
4348 thiscase->all = nesting_stack;
4349 thiscase->depth = ++nesting_depth;
4350 thiscase->exit_label = 0;
4351 thiscase->data.case_stmt.case_list = 0;
4352 thiscase->data.case_stmt.start = 0;
4353 thiscase->data.case_stmt.nominal_type = 0;
4354 thiscase->data.case_stmt.default_label = 0;
4355 thiscase->data.case_stmt.num_ranges = 0;
4356 case_stack = thiscase;
4357 nesting_stack = thiscase;
4360 /* End a dummy case statement. */
4363 expand_end_case_dummy ()
4365 POPSTACK (case_stack);
4368 /* Return the data type of the index-expression
4369 of the innermost case statement, or null if none. */
4372 case_index_expr_type ()
4375 return TREE_TYPE (case_stack->data.case_stmt.index_expr);
4379 /* Accumulate one case or default label inside a case or switch statement.
4380 VALUE is the value of the case (a null pointer, for a default label).
4381 The function CONVERTER, when applied to arguments T and V,
4382 converts the value V to the type T.
4384 If not currently inside a case or switch statement, return 1 and do
4385 nothing. The caller will print a language-specific error message.
4386 If VALUE is a duplicate or overlaps, return 2 and do nothing
4387 except store the (first) duplicate node in *DUPLICATE.
4388 If VALUE is out of range, return 3 and do nothing.
4389 If we are jumping into the scope of a cleanup or var-sized array, return 5.
4390 Return 0 on success.
4392 Extended to handle range statements. */
4395 pushcase (value, converter, label, duplicate)
4396 register tree value;
4397 tree (*converter) PROTO((tree, tree));
4398 register tree label;
4401 register struct case_node **l;
4402 register struct case_node *n;
4406 if (output_bytecode)
4407 return bc_pushcase (value, label);
4409 /* Fail if not inside a real case statement. */
4410 if (! (case_stack && case_stack->data.case_stmt.start))
4413 if (stack_block_stack
4414 && stack_block_stack->depth > case_stack->depth)
4417 index_type = TREE_TYPE (case_stack->data.case_stmt.index_expr);
4418 nominal_type = case_stack->data.case_stmt.nominal_type;
4420 /* If the index is erroneous, avoid more problems: pretend to succeed. */
4421 if (index_type == error_mark_node)
4424 /* Convert VALUE to the type in which the comparisons are nominally done. */
4426 value = (*converter) (nominal_type, value);
4428 /* If this is the first label, warn if any insns have been emitted. */
4429 if (case_stack->data.case_stmt.seenlabel == 0)
4432 for (insn = case_stack->data.case_stmt.start;
4434 insn = NEXT_INSN (insn))
4436 if (GET_CODE (insn) == CODE_LABEL)
4438 if (GET_CODE (insn) != NOTE
4439 && (GET_CODE (insn) != INSN || GET_CODE (PATTERN (insn)) != USE))
4441 warning ("unreachable code at beginning of %s",
4442 case_stack->data.case_stmt.printname);
4447 case_stack->data.case_stmt.seenlabel = 1;
4449 /* Fail if this value is out of range for the actual type of the index
4450 (which may be narrower than NOMINAL_TYPE). */
4451 if (value != 0 && ! int_fits_type_p (value, index_type))
4454 /* Fail if this is a duplicate or overlaps another entry. */
4457 if (case_stack->data.case_stmt.default_label != 0)
4459 *duplicate = case_stack->data.case_stmt.default_label;
4462 case_stack->data.case_stmt.default_label = label;
4465 return add_case_node (value, value, label, duplicate);
4467 expand_label (label);
4471 /* Like pushcase but this case applies to all values
4472 between VALUE1 and VALUE2 (inclusive).
4473 The return value is the same as that of pushcase
4474 but there is one additional error code:
4475 4 means the specified range was empty. */
4478 pushcase_range (value1, value2, converter, label, duplicate)
4479 register tree value1, value2;
4480 tree (*converter) PROTO((tree, tree));
4481 register tree label;
4484 register struct case_node **l;
4485 register struct case_node *n;
4489 /* Fail if not inside a real case statement. */
4490 if (! (case_stack && case_stack->data.case_stmt.start))
4493 /* Fail if the range is empty. */
4494 if (tree_int_cst_lt (value2, value1))
4497 if (stack_block_stack
4498 && stack_block_stack->depth > case_stack->depth)
4501 index_type = TREE_TYPE (case_stack->data.case_stmt.index_expr);
4502 nominal_type = case_stack->data.case_stmt.nominal_type;
4504 /* If the index is erroneous, avoid more problems: pretend to succeed. */
4505 if (index_type == error_mark_node)
4508 /* If this is the first label, warn if any insns have been emitted. */
4509 if (case_stack->data.case_stmt.seenlabel == 0)
4512 for (insn = case_stack->data.case_stmt.start;
4514 insn = NEXT_INSN (insn))
4516 if (GET_CODE (insn) == CODE_LABEL)
4518 if (GET_CODE (insn) != NOTE
4519 && (GET_CODE (insn) != INSN || GET_CODE (PATTERN (insn)) != USE))
4521 warning ("unreachable code at beginning of %s",
4522 case_stack->data.case_stmt.printname);
4527 case_stack->data.case_stmt.seenlabel = 1;
4529 /* Convert VALUEs to type in which the comparisons are nominally done. */
4530 if (value1 == 0) /* Negative infinity. */
4531 value1 = TYPE_MIN_VALUE (index_type);
4532 value1 = (*converter) (nominal_type, value1);
4534 if (value2 == 0) /* Positive infinity. */
4535 value2 = TYPE_MAX_VALUE (index_type);
4536 value2 = (*converter) (nominal_type, value2);
4538 /* Fail if these values are out of range. */
4539 if (! int_fits_type_p (value1, index_type))
4542 if (! int_fits_type_p (value2, index_type))
4545 return add_case_node (value1, value2, label, duplicate);
4548 /* Do the actual insertion of a case label for pushcase and pushcase_range
4549 into case_stack->data.case_stmt.case_list. Use an AVL tree to avoid
4550 slowdown for large switch statements. */
4553 add_case_node (low, high, label, duplicate)
4558 struct case_node *p, **q, *r;
4560 q = &case_stack->data.case_stmt.case_list;
4567 /* Keep going past elements distinctly greater than HIGH. */
4568 if (tree_int_cst_lt (high, p->low))
4571 /* or distinctly less than LOW. */
4572 else if (tree_int_cst_lt (p->high, low))
4577 /* We have an overlap; this is an error. */
4578 *duplicate = p->code_label;
4583 /* Add this label to the chain, and succeed.
4584 Copy LOW, HIGH so they are on temporary rather than momentary
4585 obstack and will thus survive till the end of the case statement. */
4587 r = (struct case_node *) oballoc (sizeof (struct case_node));
4588 r->low = copy_node (low);
4590 /* If the bounds are equal, turn this into the one-value case. */
4592 if (tree_int_cst_equal (low, high))
4596 r->high = copy_node (high);
4597 case_stack->data.case_stmt.num_ranges++;
4600 r->code_label = label;
4601 expand_label (label);
4611 struct case_node *s;
4617 if (! (b = p->balance))
4618 /* Growth propagation from left side. */
4625 if (p->left = s = r->right)
4642 case_stack->data.case_stmt.case_list = r;
4645 /* r->balance == +1 */
4650 struct case_node *t = r->right;
4652 if (p->left = s = t->right)
4656 if (r->right = s = t->left)
4678 case_stack->data.case_stmt.case_list = t;
4685 /* p->balance == +1; growth of left side balances the node. */
4695 if (! (b = p->balance))
4696 /* Growth propagation from right side. */
4704 if (p->right = s = r->left)
4721 case_stack->data.case_stmt.case_list = r;
4725 /* r->balance == -1 */
4729 struct case_node *t = r->left;
4731 if (p->right = s = t->left)
4736 if (r->left = s = t->right)
4759 case_stack->data.case_stmt.case_list = t;
4765 /* p->balance == -1; growth of right side balances the node. */
4778 /* Accumulate one case or default label; VALUE is the value of the
4779 case, or nil for a default label. If not currently inside a case,
4780 return 1 and do nothing. If VALUE is a duplicate or overlaps, return
4781 2 and do nothing. If VALUE is out of range, return 3 and do nothing.
4782 Return 0 on success. This function is a leftover from the earlier
4783 bytecode compiler, which was based on gcc 1.37. It should be
4784 merged into pushcase. */
4787 bc_pushcase (value, label)
4791 struct nesting *thiscase = case_stack;
4792 struct case_node *case_label, *new_label;
4797 /* Fail if duplicate, overlap, or out of type range. */
4800 value = convert (thiscase->data.case_stmt.nominal_type, value);
4801 if (! int_fits_type_p (value, thiscase->data.case_stmt.nominal_type))
4804 for (case_label = thiscase->data.case_stmt.case_list;
4805 case_label->left; case_label = case_label->left)
4806 if (! tree_int_cst_lt (case_label->left->high, value))
4809 if (case_label != thiscase->data.case_stmt.case_list
4810 && ! tree_int_cst_lt (case_label->high, value)
4811 || (case_label->left && ! tree_int_cst_lt (value, case_label->left->low)))
4814 new_label = (struct case_node *) oballoc (sizeof (struct case_node));
4815 new_label->low = new_label->high = copy_node (value);
4816 new_label->code_label = label;
4817 new_label->left = case_label->left;
4819 case_label->left = new_label;
4820 thiscase->data.case_stmt.num_ranges++;
4824 if (thiscase->data.case_stmt.default_label)
4826 thiscase->data.case_stmt.default_label = label;
4829 expand_label (label);
4833 /* Returns the number of possible values of TYPE.
4834 Returns -1 if the number is unknown or variable.
4835 Returns -2 if the number does not fit in a HOST_WIDE_INT.
4836 Sets *SPARENESS to 2 if TYPE is an ENUMERAL_TYPE whose values
4837 do not increase monotonically (there may be duplicates);
4838 to 1 if the values increase monotonically, but not always by 1;
4839 otherwise sets it to 0. */
4842 all_cases_count (type, spareness)
4846 HOST_WIDE_INT count, count_high = 0;
4849 switch (TREE_CODE (type))
4856 count = 1 << BITS_PER_UNIT;
4860 if (TREE_CODE (TYPE_MIN_VALUE (type)) != INTEGER_CST
4861 || TREE_CODE (TYPE_MAX_VALUE (type)) != INTEGER_CST)
4866 = TREE_INT_CST_LOW (TYPE_MAX_VALUE (type))
4867 - TREE_INT_CST_LOW (TYPE_MIN_VALUE (type)) + 1
4868 but with overflow checking. */
4869 tree mint = TYPE_MIN_VALUE (type);
4870 tree maxt = TYPE_MAX_VALUE (type);
4871 HOST_WIDE_INT lo, hi;
4872 neg_double(TREE_INT_CST_LOW (mint), TREE_INT_CST_HIGH (mint),
4874 add_double(TREE_INT_CST_LOW (maxt), TREE_INT_CST_HIGH (maxt),
4876 add_double (lo, hi, 1, 0, &lo, &hi);
4877 if (hi != 0 || lo < 0)
4884 for (t = TYPE_VALUES (type); t != NULL_TREE; t = TREE_CHAIN (t))
4886 if (TREE_CODE (TYPE_MIN_VALUE (type)) != INTEGER_CST
4887 || TREE_CODE (TREE_VALUE (t)) != INTEGER_CST
4888 || TREE_INT_CST_LOW (TYPE_MIN_VALUE (type)) + count
4889 != TREE_INT_CST_LOW (TREE_VALUE (t)))
4893 if (*spareness == 1)
4895 tree prev = TREE_VALUE (TYPE_VALUES (type));
4896 for (t = TYPE_VALUES (type); t = TREE_CHAIN (t), t != NULL_TREE; )
4898 if (! tree_int_cst_lt (prev, TREE_VALUE (t)))
4903 prev = TREE_VALUE (t);
4912 #define BITARRAY_TEST(ARRAY, INDEX) \
4913 ((ARRAY)[(unsigned) (INDEX) / HOST_BITS_PER_CHAR]\
4914 & (1 << ((unsigned) (INDEX) % HOST_BITS_PER_CHAR)))
4915 #define BITARRAY_SET(ARRAY, INDEX) \
4916 ((ARRAY)[(unsigned) (INDEX) / HOST_BITS_PER_CHAR]\
4917 |= 1 << ((unsigned) (INDEX) % HOST_BITS_PER_CHAR))
4919 /* Set the elements of the bitstring CASES_SEEN (which has length COUNT),
4920 with the case values we have seen, assuming the case expression
4922 SPARSENESS is as determined by all_cases_count.
4924 The time needed is proportional to COUNT, unless
4925 SPARSENESS is 2, in which case quadratic time is needed. */
4928 mark_seen_cases (type, cases_seen, count, sparseness)
4930 unsigned char *cases_seen;
4936 tree next_node_to_try = NULL_TREE;
4937 long next_node_offset = 0;
4939 register struct case_node *n, *root = case_stack->data.case_stmt.case_list;
4940 tree val = make_node (INTEGER_CST);
4941 TREE_TYPE (val) = type;
4944 else if (sparseness == 2)
4949 /* This less efficient loop is only needed to handle
4950 duplicate case values (multiple enum constants
4951 with the same value). */
4952 TREE_TYPE (val) = TREE_TYPE (root->low);
4953 for (t = TYPE_VALUES (type), xlo = 0; t != NULL_TREE;
4954 t = TREE_CHAIN (t), xlo++)
4956 TREE_INT_CST_LOW (val) = TREE_INT_CST_LOW (TREE_VALUE (t));
4957 TREE_INT_CST_HIGH (val) = TREE_INT_CST_HIGH (TREE_VALUE (t));
4961 /* Keep going past elements distinctly greater than VAL. */
4962 if (tree_int_cst_lt (val, n->low))
4965 /* or distinctly less than VAL. */
4966 else if (tree_int_cst_lt (n->high, val))
4971 /* We have found a matching range. */
4972 BITARRAY_SET (cases_seen, xlo);
4982 case_stack->data.case_stmt.case_list = root = case_tree2list (root, 0);
4983 for (n = root; n; n = n->right)
4985 TREE_INT_CST_LOW (val) = TREE_INT_CST_LOW (n->low);
4986 TREE_INT_CST_HIGH (val) = TREE_INT_CST_HIGH (n->low);
4987 while ( ! tree_int_cst_lt (n->high, val))
4989 /* Calculate (into xlo) the "offset" of the integer (val).
4990 The element with lowest value has offset 0, the next smallest
4991 element has offset 1, etc. */
4993 HOST_WIDE_INT xlo, xhi;
4995 if (sparseness && TYPE_VALUES (type) != NULL_TREE)
4997 /* The TYPE_VALUES will be in increasing order, so
4998 starting searching where we last ended. */
4999 t = next_node_to_try;
5000 xlo = next_node_offset;
5006 t = TYPE_VALUES (type);
5009 if (tree_int_cst_equal (val, TREE_VALUE (t)))
5011 next_node_to_try = TREE_CHAIN (t);
5012 next_node_offset = xlo + 1;
5017 if (t == next_node_to_try)
5026 t = TYPE_MIN_VALUE (type);
5028 neg_double (TREE_INT_CST_LOW (t), TREE_INT_CST_HIGH (t),
5032 add_double (xlo, xhi,
5033 TREE_INT_CST_LOW (val), TREE_INT_CST_HIGH (val),
5037 if (xhi == 0 && xlo >= 0 && xlo < count)
5038 BITARRAY_SET (cases_seen, xlo);
5039 add_double (TREE_INT_CST_LOW (val), TREE_INT_CST_HIGH (val),
5041 &TREE_INT_CST_LOW (val), &TREE_INT_CST_HIGH (val));
5047 /* Called when the index of a switch statement is an enumerated type
5048 and there is no default label.
5050 Checks that all enumeration literals are covered by the case
5051 expressions of a switch. Also, warn if there are any extra
5052 switch cases that are *not* elements of the enumerated type.
5054 If all enumeration literals were covered by the case expressions,
5055 turn one of the expressions into the default expression since it should
5056 not be possible to fall through such a switch. */
5059 check_for_full_enumeration_handling (type)
5062 register struct case_node *n;
5063 register struct case_node **l;
5064 register tree chain;
5067 /* True iff the selector type is a numbered set mode. */
5070 /* The number of possible selector values. */
5073 /* For each possible selector value. a one iff it has been matched
5074 by a case value alternative. */
5075 unsigned char *cases_seen;
5077 /* The allocated size of cases_seen, in chars. */
5081 if (output_bytecode)
5083 bc_check_for_full_enumeration_handling (type);
5090 size = all_cases_count (type, &sparseness);
5091 bytes_needed = (size + HOST_BITS_PER_CHAR) / HOST_BITS_PER_CHAR;
5093 if (size > 0 && size < 600000
5094 /* We deliberately use malloc here - not xmalloc. */
5095 && (cases_seen = (unsigned char *) malloc (bytes_needed)) != NULL)
5098 tree v = TYPE_VALUES (type);
5099 bzero (cases_seen, bytes_needed);
5101 /* The time complexity of this code is normally O(N), where
5102 N being the number of members in the enumerated type.
5103 However, if type is a ENUMERAL_TYPE whose values do not
5104 increase monotonically, O(N*log(N)) time may be needed. */
5106 mark_seen_cases (type, cases_seen, size, sparseness);
5108 for (i = 0; v != NULL_TREE && i < size; i++, v = TREE_CHAIN (v))
5110 if (BITARRAY_TEST(cases_seen, i) == 0)
5111 warning ("enumeration value `%s' not handled in switch",
5112 IDENTIFIER_POINTER (TREE_PURPOSE (v)));
5118 /* Now we go the other way around; we warn if there are case
5119 expressions that don't correspond to enumerators. This can
5120 occur since C and C++ don't enforce type-checking of
5121 assignments to enumeration variables. */
5123 if (case_stack->data.case_stmt.case_list
5124 && case_stack->data.case_stmt.case_list->left)
5125 case_stack->data.case_stmt.case_list
5126 = case_tree2list (case_stack->data.case_stmt.case_list, 0);
5128 for (n = case_stack->data.case_stmt.case_list; n; n = n->right)
5130 for (chain = TYPE_VALUES (type);
5131 chain && !tree_int_cst_equal (n->low, TREE_VALUE (chain));
5132 chain = TREE_CHAIN (chain))
5137 if (TYPE_NAME (type) == 0)
5138 warning ("case value `%d' not in enumerated type",
5139 TREE_INT_CST_LOW (n->low));
5141 warning ("case value `%d' not in enumerated type `%s'",
5142 TREE_INT_CST_LOW (n->low),
5143 IDENTIFIER_POINTER ((TREE_CODE (TYPE_NAME (type))
5146 : DECL_NAME (TYPE_NAME (type))));
5148 if (!tree_int_cst_equal (n->low, n->high))
5150 for (chain = TYPE_VALUES (type);
5151 chain && !tree_int_cst_equal (n->high, TREE_VALUE (chain));
5152 chain = TREE_CHAIN (chain))
5157 if (TYPE_NAME (type) == 0)
5158 warning ("case value `%d' not in enumerated type",
5159 TREE_INT_CST_LOW (n->high));
5161 warning ("case value `%d' not in enumerated type `%s'",
5162 TREE_INT_CST_LOW (n->high),
5163 IDENTIFIER_POINTER ((TREE_CODE (TYPE_NAME (type))
5166 : DECL_NAME (TYPE_NAME (type))));
5172 /* ??? This optimization is disabled because it causes valid programs to
5173 fail. ANSI C does not guarantee that an expression with enum type
5174 will have a value that is the same as one of the enumeration literals. */
5176 /* If all values were found as case labels, make one of them the default
5177 label. Thus, this switch will never fall through. We arbitrarily pick
5178 the last one to make the default since this is likely the most
5179 efficient choice. */
5183 for (l = &case_stack->data.case_stmt.case_list;
5188 case_stack->data.case_stmt.default_label = (*l)->code_label;
5195 /* Check that all enumeration literals are covered by the case
5196 expressions of a switch. Also warn if there are any cases
5197 that are not elements of the enumerated type. */
5200 bc_check_for_full_enumeration_handling (type)
5203 struct nesting *thiscase = case_stack;
5204 struct case_node *c;
5207 /* Check for enums not handled. */
5208 for (e = TYPE_VALUES (type); e; e = TREE_CHAIN (e))
5210 for (c = thiscase->data.case_stmt.case_list->left;
5211 c && tree_int_cst_lt (c->high, TREE_VALUE (e));
5214 if (! (c && tree_int_cst_equal (c->low, TREE_VALUE (e))))
5215 warning ("enumerated value `%s' not handled in switch",
5216 IDENTIFIER_POINTER (TREE_PURPOSE (e)));
5219 /* Check for cases not in the enumeration. */
5220 for (c = thiscase->data.case_stmt.case_list->left; c; c = c->left)
5222 for (e = TYPE_VALUES (type);
5223 e && !tree_int_cst_equal (c->low, TREE_VALUE (e));
5227 warning ("case value `%d' not in enumerated type `%s'",
5228 TREE_INT_CST_LOW (c->low),
5229 IDENTIFIER_POINTER (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
5231 : DECL_NAME (TYPE_NAME (type))));
5235 /* Terminate a case (Pascal) or switch (C) statement
5236 in which ORIG_INDEX is the expression to be tested.
5237 Generate the code to test it and jump to the right place. */
5240 expand_end_case (orig_index)
5243 tree minval, maxval, range, orig_minval;
5244 rtx default_label = 0;
5245 register struct case_node *n;
5253 register struct nesting *thiscase = case_stack;
5254 tree index_expr, index_type;
5257 if (output_bytecode)
5259 bc_expand_end_case (orig_index);
5263 table_label = gen_label_rtx ();
5264 index_expr = thiscase->data.case_stmt.index_expr;
5265 index_type = TREE_TYPE (index_expr);
5266 unsignedp = TREE_UNSIGNED (index_type);
5268 do_pending_stack_adjust ();
5270 /* An ERROR_MARK occurs for various reasons including invalid data type. */
5271 if (index_type != error_mark_node)
5273 /* If switch expression was an enumerated type, check that all
5274 enumeration literals are covered by the cases.
5275 No sense trying this if there's a default case, however. */
5277 if (!thiscase->data.case_stmt.default_label
5278 && TREE_CODE (TREE_TYPE (orig_index)) == ENUMERAL_TYPE
5279 && TREE_CODE (index_expr) != INTEGER_CST)
5280 check_for_full_enumeration_handling (TREE_TYPE (orig_index));
5282 /* If this is the first label, warn if any insns have been emitted. */
5283 if (thiscase->data.case_stmt.seenlabel == 0)
5286 for (insn = get_last_insn ();
5287 insn != case_stack->data.case_stmt.start;
5288 insn = PREV_INSN (insn))
5289 if (GET_CODE (insn) != NOTE
5290 && (GET_CODE (insn) != INSN || GET_CODE (PATTERN (insn))!= USE))
5292 warning ("unreachable code at beginning of %s",
5293 case_stack->data.case_stmt.printname);
5298 /* If we don't have a default-label, create one here,
5299 after the body of the switch. */
5300 if (thiscase->data.case_stmt.default_label == 0)
5302 thiscase->data.case_stmt.default_label
5303 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
5304 expand_label (thiscase->data.case_stmt.default_label);
5306 default_label = label_rtx (thiscase->data.case_stmt.default_label);
5308 before_case = get_last_insn ();
5310 if (thiscase->data.case_stmt.case_list
5311 && thiscase->data.case_stmt.case_list->left)
5312 thiscase->data.case_stmt.case_list
5313 = case_tree2list(thiscase->data.case_stmt.case_list, 0);
5315 /* Simplify the case-list before we count it. */
5316 group_case_nodes (thiscase->data.case_stmt.case_list);
5318 /* Get upper and lower bounds of case values.
5319 Also convert all the case values to the index expr's data type. */
5322 for (n = thiscase->data.case_stmt.case_list; n; n = n->right)
5324 /* Check low and high label values are integers. */
5325 if (TREE_CODE (n->low) != INTEGER_CST)
5327 if (TREE_CODE (n->high) != INTEGER_CST)
5330 n->low = convert (index_type, n->low);
5331 n->high = convert (index_type, n->high);
5333 /* Count the elements and track the largest and smallest
5334 of them (treating them as signed even if they are not). */
5342 if (INT_CST_LT (n->low, minval))
5344 if (INT_CST_LT (maxval, n->high))
5347 /* A range counts double, since it requires two compares. */
5348 if (! tree_int_cst_equal (n->low, n->high))
5352 orig_minval = minval;
5354 /* Compute span of values. */
5356 range = fold (build (MINUS_EXPR, index_type, maxval, minval));
5360 expand_expr (index_expr, const0_rtx, VOIDmode, 0);
5362 emit_jump (default_label);
5365 /* If range of values is much bigger than number of values,
5366 make a sequence of conditional branches instead of a dispatch.
5367 If the switch-index is a constant, do it this way
5368 because we can optimize it. */
5370 #ifndef CASE_VALUES_THRESHOLD
5372 #define CASE_VALUES_THRESHOLD (HAVE_casesi ? 4 : 5)
5374 /* If machine does not have a case insn that compares the
5375 bounds, this means extra overhead for dispatch tables
5376 which raises the threshold for using them. */
5377 #define CASE_VALUES_THRESHOLD 5
5378 #endif /* HAVE_casesi */
5379 #endif /* CASE_VALUES_THRESHOLD */
5381 else if (TREE_INT_CST_HIGH (range) != 0
5382 || count < CASE_VALUES_THRESHOLD
5383 || ((unsigned HOST_WIDE_INT) (TREE_INT_CST_LOW (range))
5385 #ifndef ASM_OUTPUT_ADDR_DIFF_ELT
5388 || TREE_CODE (index_expr) == INTEGER_CST
5389 /* These will reduce to a constant. */
5390 || (TREE_CODE (index_expr) == CALL_EXPR
5391 && TREE_CODE (TREE_OPERAND (index_expr, 0)) == ADDR_EXPR
5392 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (index_expr, 0), 0)) == FUNCTION_DECL
5393 && DECL_FUNCTION_CODE (TREE_OPERAND (TREE_OPERAND (index_expr, 0), 0)) == BUILT_IN_CLASSIFY_TYPE)
5394 || (TREE_CODE (index_expr) == COMPOUND_EXPR
5395 && TREE_CODE (TREE_OPERAND (index_expr, 1)) == INTEGER_CST))
5397 index = expand_expr (index_expr, NULL_RTX, VOIDmode, 0);
5399 /* If the index is a short or char that we do not have
5400 an insn to handle comparisons directly, convert it to
5401 a full integer now, rather than letting each comparison
5402 generate the conversion. */
5404 if (GET_MODE_CLASS (GET_MODE (index)) == MODE_INT
5405 && (cmp_optab->handlers[(int) GET_MODE(index)].insn_code
5406 == CODE_FOR_nothing))
5408 enum machine_mode wider_mode;
5409 for (wider_mode = GET_MODE (index); wider_mode != VOIDmode;
5410 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
5411 if (cmp_optab->handlers[(int) wider_mode].insn_code
5412 != CODE_FOR_nothing)
5414 index = convert_to_mode (wider_mode, index, unsignedp);
5420 do_pending_stack_adjust ();
5422 index = protect_from_queue (index, 0);
5423 if (GET_CODE (index) == MEM)
5424 index = copy_to_reg (index);
5425 if (GET_CODE (index) == CONST_INT
5426 || TREE_CODE (index_expr) == INTEGER_CST)
5428 /* Make a tree node with the proper constant value
5429 if we don't already have one. */
5430 if (TREE_CODE (index_expr) != INTEGER_CST)
5433 = build_int_2 (INTVAL (index),
5434 unsignedp || INTVAL (index) >= 0 ? 0 : -1);
5435 index_expr = convert (index_type, index_expr);
5438 /* For constant index expressions we need only
5439 issue a unconditional branch to the appropriate
5440 target code. The job of removing any unreachable
5441 code is left to the optimisation phase if the
5442 "-O" option is specified. */
5443 for (n = thiscase->data.case_stmt.case_list; n; n = n->right)
5444 if (! tree_int_cst_lt (index_expr, n->low)
5445 && ! tree_int_cst_lt (n->high, index_expr))
5449 emit_jump (label_rtx (n->code_label));
5451 emit_jump (default_label);
5455 /* If the index expression is not constant we generate
5456 a binary decision tree to select the appropriate
5457 target code. This is done as follows:
5459 The list of cases is rearranged into a binary tree,
5460 nearly optimal assuming equal probability for each case.
5462 The tree is transformed into RTL, eliminating
5463 redundant test conditions at the same time.
5465 If program flow could reach the end of the
5466 decision tree an unconditional jump to the
5467 default code is emitted. */
5470 = (TREE_CODE (TREE_TYPE (orig_index)) != ENUMERAL_TYPE
5471 && estimate_case_costs (thiscase->data.case_stmt.case_list));
5472 balance_case_nodes (&thiscase->data.case_stmt.case_list,
5474 emit_case_nodes (index, thiscase->data.case_stmt.case_list,
5475 default_label, index_type);
5476 emit_jump_if_reachable (default_label);
5485 enum machine_mode index_mode = SImode;
5486 int index_bits = GET_MODE_BITSIZE (index_mode);
5488 enum machine_mode op_mode;
5490 /* Convert the index to SImode. */
5491 if (GET_MODE_BITSIZE (TYPE_MODE (index_type))
5492 > GET_MODE_BITSIZE (index_mode))
5494 enum machine_mode omode = TYPE_MODE (index_type);
5495 rtx rangertx = expand_expr (range, NULL_RTX, VOIDmode, 0);
5497 /* We must handle the endpoints in the original mode. */
5498 index_expr = build (MINUS_EXPR, index_type,
5499 index_expr, minval);
5500 minval = integer_zero_node;
5501 index = expand_expr (index_expr, NULL_RTX, VOIDmode, 0);
5502 emit_cmp_insn (rangertx, index, LTU, NULL_RTX, omode, 1, 0);
5503 emit_jump_insn (gen_bltu (default_label));
5504 /* Now we can safely truncate. */
5505 index = convert_to_mode (index_mode, index, 0);
5509 if (TYPE_MODE (index_type) != index_mode)
5511 index_expr = convert (type_for_size (index_bits, 0),
5513 index_type = TREE_TYPE (index_expr);
5516 index = expand_expr (index_expr, NULL_RTX, VOIDmode, 0);
5519 index = protect_from_queue (index, 0);
5520 do_pending_stack_adjust ();
5522 op_mode = insn_operand_mode[(int)CODE_FOR_casesi][0];
5523 if (! (*insn_operand_predicate[(int)CODE_FOR_casesi][0])
5525 index = copy_to_mode_reg (op_mode, index);
5527 op1 = expand_expr (minval, NULL_RTX, VOIDmode, 0);
5529 op_mode = insn_operand_mode[(int)CODE_FOR_casesi][1];
5530 if (! (*insn_operand_predicate[(int)CODE_FOR_casesi][1])
5532 op1 = copy_to_mode_reg (op_mode, op1);
5534 op2 = expand_expr (range, NULL_RTX, VOIDmode, 0);
5536 op_mode = insn_operand_mode[(int)CODE_FOR_casesi][2];
5537 if (! (*insn_operand_predicate[(int)CODE_FOR_casesi][2])
5539 op2 = copy_to_mode_reg (op_mode, op2);
5541 emit_jump_insn (gen_casesi (index, op1, op2,
5542 table_label, default_label));
5546 #ifdef HAVE_tablejump
5547 if (! win && HAVE_tablejump)
5549 index_expr = convert (thiscase->data.case_stmt.nominal_type,
5550 fold (build (MINUS_EXPR, index_type,
5551 index_expr, minval)));
5552 index_type = TREE_TYPE (index_expr);
5553 index = expand_expr (index_expr, NULL_RTX, VOIDmode, 0);
5555 index = protect_from_queue (index, 0);
5556 do_pending_stack_adjust ();
5558 do_tablejump (index, TYPE_MODE (index_type),
5559 expand_expr (range, NULL_RTX, VOIDmode, 0),
5560 table_label, default_label);
5567 /* Get table of labels to jump to, in order of case index. */
5569 ncases = TREE_INT_CST_LOW (range) + 1;
5570 labelvec = (rtx *) alloca (ncases * sizeof (rtx));
5571 bzero ((char *) labelvec, ncases * sizeof (rtx));
5573 for (n = thiscase->data.case_stmt.case_list; n; n = n->right)
5575 register HOST_WIDE_INT i
5576 = TREE_INT_CST_LOW (n->low) - TREE_INT_CST_LOW (orig_minval);
5581 = gen_rtx (LABEL_REF, Pmode, label_rtx (n->code_label));
5582 if (i + TREE_INT_CST_LOW (orig_minval)
5583 == TREE_INT_CST_LOW (n->high))
5589 /* Fill in the gaps with the default. */
5590 for (i = 0; i < ncases; i++)
5591 if (labelvec[i] == 0)
5592 labelvec[i] = gen_rtx (LABEL_REF, Pmode, default_label);
5594 /* Output the table */
5595 emit_label (table_label);
5597 /* This would be a lot nicer if CASE_VECTOR_PC_RELATIVE
5598 were an expression, instead of an #ifdef/#ifndef. */
5600 #ifdef CASE_VECTOR_PC_RELATIVE
5604 emit_jump_insn (gen_rtx (ADDR_DIFF_VEC, CASE_VECTOR_MODE,
5605 gen_rtx (LABEL_REF, Pmode, table_label),
5606 gen_rtvec_v (ncases, labelvec)));
5608 emit_jump_insn (gen_rtx (ADDR_VEC, CASE_VECTOR_MODE,
5609 gen_rtvec_v (ncases, labelvec)));
5611 /* If the case insn drops through the table,
5612 after the table we must jump to the default-label.
5613 Otherwise record no drop-through after the table. */
5614 #ifdef CASE_DROPS_THROUGH
5615 emit_jump (default_label);
5621 before_case = squeeze_notes (NEXT_INSN (before_case), get_last_insn ());
5622 reorder_insns (before_case, get_last_insn (),
5623 thiscase->data.case_stmt.start);
5626 if (thiscase->exit_label)
5627 emit_label (thiscase->exit_label);
5629 POPSTACK (case_stack);
5634 /* Convert the tree NODE into a list linked by the right field, with the left
5635 field zeroed. RIGHT is used for recursion; it is a list to be placed
5636 rightmost in the resulting list. */
5638 static struct case_node *
5639 case_tree2list (node, right)
5640 struct case_node *node, *right;
5642 struct case_node *left;
5645 right = case_tree2list (node->right, right);
5647 node->right = right;
5648 if (left = node->left)
5651 return case_tree2list (left, node);
5657 /* Terminate a case statement. EXPR is the original index
5661 bc_expand_end_case (expr)
5664 struct nesting *thiscase = case_stack;
5665 enum bytecode_opcode opcode;
5666 struct bc_label *jump_label;
5667 struct case_node *c;
5669 bc_emit_bytecode (jump);
5670 bc_emit_bytecode_labelref (BYTECODE_BC_LABEL (thiscase->exit_label));
5672 #ifdef DEBUG_PRINT_CODE
5673 fputc ('\n', stderr);
5676 /* Now that the size of the jump table is known, emit the actual
5677 indexed jump instruction. */
5678 bc_emit_bytecode_labeldef (BYTECODE_BC_LABEL (thiscase->data.case_stmt.skip_label));
5680 opcode = TYPE_MODE (thiscase->data.case_stmt.nominal_type) == SImode
5681 ? TREE_UNSIGNED (thiscase->data.case_stmt.nominal_type) ? caseSU : caseSI
5682 : TREE_UNSIGNED (thiscase->data.case_stmt.nominal_type) ? caseDU : caseDI;
5684 bc_emit_bytecode (opcode);
5686 /* Now emit the case instructions literal arguments, in order.
5687 In addition to the value on the stack, it uses:
5688 1. The address of the jump table.
5689 2. The size of the jump table.
5690 3. The default label. */
5692 jump_label = bc_get_bytecode_label ();
5693 bc_emit_bytecode_labelref (jump_label);
5694 bc_emit_bytecode_const ((char *) &thiscase->data.case_stmt.num_ranges,
5695 sizeof thiscase->data.case_stmt.num_ranges);
5697 if (thiscase->data.case_stmt.default_label)
5698 bc_emit_bytecode_labelref (BYTECODE_BC_LABEL (DECL_RTL (thiscase->data.case_stmt.default_label)));
5700 bc_emit_bytecode_labelref (BYTECODE_BC_LABEL (thiscase->exit_label));
5702 /* Output the jump table. */
5704 bc_align_bytecode (3 /* PTR_ALIGN */);
5705 bc_emit_bytecode_labeldef (jump_label);
5707 if (TYPE_MODE (thiscase->data.case_stmt.nominal_type) == SImode)
5708 for (c = thiscase->data.case_stmt.case_list->left; c; c = c->left)
5710 opcode = TREE_INT_CST_LOW (c->low);
5711 bc_emit_bytecode_const ((char *) &opcode, sizeof opcode);
5713 opcode = TREE_INT_CST_LOW (c->high);
5714 bc_emit_bytecode_const ((char *) &opcode, sizeof opcode);
5716 bc_emit_bytecode_labelref (BYTECODE_BC_LABEL (DECL_RTL (c->code_label)));
5719 if (TYPE_MODE (thiscase->data.case_stmt.nominal_type) == DImode)
5720 for (c = thiscase->data.case_stmt.case_list->left; c; c = c->left)
5722 bc_emit_bytecode_DI_const (c->low);
5723 bc_emit_bytecode_DI_const (c->high);
5725 bc_emit_bytecode_labelref (BYTECODE_BC_LABEL (DECL_RTL (c->code_label)));
5732 bc_emit_bytecode_labeldef (BYTECODE_BC_LABEL (thiscase->exit_label));
5734 /* Possibly issue enumeration warnings. */
5736 if (!thiscase->data.case_stmt.default_label
5737 && TREE_CODE (TREE_TYPE (expr)) == ENUMERAL_TYPE
5738 && TREE_CODE (expr) != INTEGER_CST
5740 check_for_full_enumeration_handling (TREE_TYPE (expr));
5743 #ifdef DEBUG_PRINT_CODE
5744 fputc ('\n', stderr);
5747 POPSTACK (case_stack);
5751 /* Return unique bytecode ID. */
5756 static int bc_uid = 0;
5761 /* Generate code to jump to LABEL if OP1 and OP2 are equal. */
5764 do_jump_if_equal (op1, op2, label, unsignedp)
5765 rtx op1, op2, label;
5768 if (GET_CODE (op1) == CONST_INT
5769 && GET_CODE (op2) == CONST_INT)
5771 if (INTVAL (op1) == INTVAL (op2))
5776 enum machine_mode mode = GET_MODE (op1);
5777 if (mode == VOIDmode)
5778 mode = GET_MODE (op2);
5779 emit_cmp_insn (op1, op2, EQ, NULL_RTX, mode, unsignedp, 0);
5780 emit_jump_insn (gen_beq (label));
5784 /* Not all case values are encountered equally. This function
5785 uses a heuristic to weight case labels, in cases where that
5786 looks like a reasonable thing to do.
5788 Right now, all we try to guess is text, and we establish the
5791 chars above space: 16
5800 If we find any cases in the switch that are not either -1 or in the range
5801 of valid ASCII characters, or are control characters other than those
5802 commonly used with "\", don't treat this switch scanning text.
5804 Return 1 if these nodes are suitable for cost estimation, otherwise
5808 estimate_case_costs (node)
5811 tree min_ascii = build_int_2 (-1, -1);
5812 tree max_ascii = convert (TREE_TYPE (node->high), build_int_2 (127, 0));
5816 /* If we haven't already made the cost table, make it now. Note that the
5817 lower bound of the table is -1, not zero. */
5819 if (cost_table == NULL)
5821 cost_table = ((short *) xmalloc (129 * sizeof (short))) + 1;
5822 bzero ((char *) (cost_table - 1), 129 * sizeof (short));
5824 for (i = 0; i < 128; i++)
5828 else if (ispunct (i))
5830 else if (iscntrl (i))
5834 cost_table[' '] = 8;
5835 cost_table['\t'] = 4;
5836 cost_table['\0'] = 4;
5837 cost_table['\n'] = 2;
5838 cost_table['\f'] = 1;
5839 cost_table['\v'] = 1;
5840 cost_table['\b'] = 1;
5843 /* See if all the case expressions look like text. It is text if the
5844 constant is >= -1 and the highest constant is <= 127. Do all comparisons
5845 as signed arithmetic since we don't want to ever access cost_table with a
5846 value less than -1. Also check that none of the constants in a range
5847 are strange control characters. */
5849 for (n = node; n; n = n->right)
5851 if ((INT_CST_LT (n->low, min_ascii)) || INT_CST_LT (max_ascii, n->high))
5854 for (i = TREE_INT_CST_LOW (n->low); i <= TREE_INT_CST_LOW (n->high); i++)
5855 if (cost_table[i] < 0)
5859 /* All interesting values are within the range of interesting
5860 ASCII characters. */
5864 /* Scan an ordered list of case nodes
5865 combining those with consecutive values or ranges.
5867 Eg. three separate entries 1: 2: 3: become one entry 1..3: */
5870 group_case_nodes (head)
5873 case_node_ptr node = head;
5877 rtx lb = next_real_insn (label_rtx (node->code_label));
5879 case_node_ptr np = node;
5881 /* Try to group the successors of NODE with NODE. */
5882 while (((np = np->right) != 0)
5883 /* Do they jump to the same place? */
5884 && ((lb2 = next_real_insn (label_rtx (np->code_label))) == lb
5885 || (lb != 0 && lb2 != 0
5886 && simplejump_p (lb)
5887 && simplejump_p (lb2)
5888 && rtx_equal_p (SET_SRC (PATTERN (lb)),
5889 SET_SRC (PATTERN (lb2)))))
5890 /* Are their ranges consecutive? */
5891 && tree_int_cst_equal (np->low,
5892 fold (build (PLUS_EXPR,
5893 TREE_TYPE (node->high),
5896 /* An overflow is not consecutive. */
5897 && tree_int_cst_lt (node->high,
5898 fold (build (PLUS_EXPR,
5899 TREE_TYPE (node->high),
5901 integer_one_node))))
5903 node->high = np->high;
5905 /* NP is the first node after NODE which can't be grouped with it.
5906 Delete the nodes in between, and move on to that node. */
5912 /* Take an ordered list of case nodes
5913 and transform them into a near optimal binary tree,
5914 on the assumption that any target code selection value is as
5915 likely as any other.
5917 The transformation is performed by splitting the ordered
5918 list into two equal sections plus a pivot. The parts are
5919 then attached to the pivot as left and right branches. Each
5920 branch is is then transformed recursively. */
5923 balance_case_nodes (head, parent)
5924 case_node_ptr *head;
5925 case_node_ptr parent;
5927 register case_node_ptr np;
5935 register case_node_ptr *npp;
5938 /* Count the number of entries on branch. Also count the ranges. */
5942 if (!tree_int_cst_equal (np->low, np->high))
5946 cost += cost_table[TREE_INT_CST_LOW (np->high)];
5950 cost += cost_table[TREE_INT_CST_LOW (np->low)];
5958 /* Split this list if it is long enough for that to help. */
5963 /* Find the place in the list that bisects the list's total cost,
5964 Here I gets half the total cost. */
5969 /* Skip nodes while their cost does not reach that amount. */
5970 if (!tree_int_cst_equal ((*npp)->low, (*npp)->high))
5971 i -= cost_table[TREE_INT_CST_LOW ((*npp)->high)];
5972 i -= cost_table[TREE_INT_CST_LOW ((*npp)->low)];
5975 npp = &(*npp)->right;
5980 /* Leave this branch lopsided, but optimize left-hand
5981 side and fill in `parent' fields for right-hand side. */
5983 np->parent = parent;
5984 balance_case_nodes (&np->left, np);
5985 for (; np->right; np = np->right)
5986 np->right->parent = np;
5990 /* If there are just three nodes, split at the middle one. */
5992 npp = &(*npp)->right;
5995 /* Find the place in the list that bisects the list's total cost,
5996 where ranges count as 2.
5997 Here I gets half the total cost. */
5998 i = (i + ranges + 1) / 2;
6001 /* Skip nodes while their cost does not reach that amount. */
6002 if (!tree_int_cst_equal ((*npp)->low, (*npp)->high))
6007 npp = &(*npp)->right;
6012 np->parent = parent;
6015 /* Optimize each of the two split parts. */
6016 balance_case_nodes (&np->left, np);
6017 balance_case_nodes (&np->right, np);
6021 /* Else leave this branch as one level,
6022 but fill in `parent' fields. */
6024 np->parent = parent;
6025 for (; np->right; np = np->right)
6026 np->right->parent = np;
6031 /* Search the parent sections of the case node tree
6032 to see if a test for the lower bound of NODE would be redundant.
6033 INDEX_TYPE is the type of the index expression.
6035 The instructions to generate the case decision tree are
6036 output in the same order as nodes are processed so it is
6037 known that if a parent node checks the range of the current
6038 node minus one that the current node is bounded at its lower
6039 span. Thus the test would be redundant. */
6042 node_has_low_bound (node, index_type)
6047 case_node_ptr pnode;
6049 /* If the lower bound of this node is the lowest value in the index type,
6050 we need not test it. */
6052 if (tree_int_cst_equal (node->low, TYPE_MIN_VALUE (index_type)))
6055 /* If this node has a left branch, the value at the left must be less
6056 than that at this node, so it cannot be bounded at the bottom and
6057 we need not bother testing any further. */
6062 low_minus_one = fold (build (MINUS_EXPR, TREE_TYPE (node->low),
6063 node->low, integer_one_node));
6065 /* If the subtraction above overflowed, we can't verify anything.
6066 Otherwise, look for a parent that tests our value - 1. */
6068 if (! tree_int_cst_lt (low_minus_one, node->low))
6071 for (pnode = node->parent; pnode; pnode = pnode->parent)
6072 if (tree_int_cst_equal (low_minus_one, pnode->high))
6078 /* Search the parent sections of the case node tree
6079 to see if a test for the upper bound of NODE would be redundant.
6080 INDEX_TYPE is the type of the index expression.
6082 The instructions to generate the case decision tree are
6083 output in the same order as nodes are processed so it is
6084 known that if a parent node checks the range of the current
6085 node plus one that the current node is bounded at its upper
6086 span. Thus the test would be redundant. */
6089 node_has_high_bound (node, index_type)
6094 case_node_ptr pnode;
6096 /* If the upper bound of this node is the highest value in the type
6097 of the index expression, we need not test against it. */
6099 if (tree_int_cst_equal (node->high, TYPE_MAX_VALUE (index_type)))
6102 /* If this node has a right branch, the value at the right must be greater
6103 than that at this node, so it cannot be bounded at the top and
6104 we need not bother testing any further. */
6109 high_plus_one = fold (build (PLUS_EXPR, TREE_TYPE (node->high),
6110 node->high, integer_one_node));
6112 /* If the addition above overflowed, we can't verify anything.
6113 Otherwise, look for a parent that tests our value + 1. */
6115 if (! tree_int_cst_lt (node->high, high_plus_one))
6118 for (pnode = node->parent; pnode; pnode = pnode->parent)
6119 if (tree_int_cst_equal (high_plus_one, pnode->low))
6125 /* Search the parent sections of the
6126 case node tree to see if both tests for the upper and lower
6127 bounds of NODE would be redundant. */
6130 node_is_bounded (node, index_type)
6134 return (node_has_low_bound (node, index_type)
6135 && node_has_high_bound (node, index_type));
6138 /* Emit an unconditional jump to LABEL unless it would be dead code. */
6141 emit_jump_if_reachable (label)
6144 if (GET_CODE (get_last_insn ()) != BARRIER)
6148 /* Emit step-by-step code to select a case for the value of INDEX.
6149 The thus generated decision tree follows the form of the
6150 case-node binary tree NODE, whose nodes represent test conditions.
6151 INDEX_TYPE is the type of the index of the switch.
6153 Care is taken to prune redundant tests from the decision tree
6154 by detecting any boundary conditions already checked by
6155 emitted rtx. (See node_has_high_bound, node_has_low_bound
6156 and node_is_bounded, above.)
6158 Where the test conditions can be shown to be redundant we emit
6159 an unconditional jump to the target code. As a further
6160 optimization, the subordinates of a tree node are examined to
6161 check for bounded nodes. In this case conditional and/or
6162 unconditional jumps as a result of the boundary check for the
6163 current node are arranged to target the subordinates associated
6164 code for out of bound conditions on the current node node.
6166 We can assume that when control reaches the code generated here,
6167 the index value has already been compared with the parents
6168 of this node, and determined to be on the same side of each parent
6169 as this node is. Thus, if this node tests for the value 51,
6170 and a parent tested for 52, we don't need to consider
6171 the possibility of a value greater than 51. If another parent
6172 tests for the value 50, then this node need not test anything. */
6175 emit_case_nodes (index, node, default_label, index_type)
6181 /* If INDEX has an unsigned type, we must make unsigned branches. */
6182 int unsignedp = TREE_UNSIGNED (index_type);
6183 typedef rtx rtx_function ();
6184 rtx_function *gen_bgt_pat = unsignedp ? gen_bgtu : gen_bgt;
6185 rtx_function *gen_bge_pat = unsignedp ? gen_bgeu : gen_bge;
6186 rtx_function *gen_blt_pat = unsignedp ? gen_bltu : gen_blt;
6187 rtx_function *gen_ble_pat = unsignedp ? gen_bleu : gen_ble;
6188 enum machine_mode mode = GET_MODE (index);
6190 /* See if our parents have already tested everything for us.
6191 If they have, emit an unconditional jump for this node. */
6192 if (node_is_bounded (node, index_type))
6193 emit_jump (label_rtx (node->code_label));
6195 else if (tree_int_cst_equal (node->low, node->high))
6197 /* Node is single valued. First see if the index expression matches
6198 this node and then check our children, if any. */
6200 do_jump_if_equal (index, expand_expr (node->low, NULL_RTX, VOIDmode, 0),
6201 label_rtx (node->code_label), unsignedp);
6203 if (node->right != 0 && node->left != 0)
6205 /* This node has children on both sides.
6206 Dispatch to one side or the other
6207 by comparing the index value with this node's value.
6208 If one subtree is bounded, check that one first,
6209 so we can avoid real branches in the tree. */
6211 if (node_is_bounded (node->right, index_type))
6213 emit_cmp_insn (index, expand_expr (node->high, NULL_RTX,
6215 GT, NULL_RTX, mode, unsignedp, 0);
6217 emit_jump_insn ((*gen_bgt_pat) (label_rtx (node->right->code_label)));
6218 emit_case_nodes (index, node->left, default_label, index_type);
6221 else if (node_is_bounded (node->left, index_type))
6223 emit_cmp_insn (index, expand_expr (node->high, NULL_RTX,
6225 LT, NULL_RTX, mode, unsignedp, 0);
6226 emit_jump_insn ((*gen_blt_pat) (label_rtx (node->left->code_label)));
6227 emit_case_nodes (index, node->right, default_label, index_type);
6232 /* Neither node is bounded. First distinguish the two sides;
6233 then emit the code for one side at a time. */
6236 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
6238 /* See if the value is on the right. */
6239 emit_cmp_insn (index, expand_expr (node->high, NULL_RTX,
6241 GT, NULL_RTX, mode, unsignedp, 0);
6242 emit_jump_insn ((*gen_bgt_pat) (label_rtx (test_label)));
6244 /* Value must be on the left.
6245 Handle the left-hand subtree. */
6246 emit_case_nodes (index, node->left, default_label, index_type);
6247 /* If left-hand subtree does nothing,
6249 emit_jump_if_reachable (default_label);
6251 /* Code branches here for the right-hand subtree. */
6252 expand_label (test_label);
6253 emit_case_nodes (index, node->right, default_label, index_type);
6257 else if (node->right != 0 && node->left == 0)
6259 /* Here we have a right child but no left so we issue conditional
6260 branch to default and process the right child.
6262 Omit the conditional branch to default if we it avoid only one
6263 right child; it costs too much space to save so little time. */
6265 if (node->right->right || node->right->left
6266 || !tree_int_cst_equal (node->right->low, node->right->high))
6268 if (!node_has_low_bound (node, index_type))
6270 emit_cmp_insn (index, expand_expr (node->high, NULL_RTX,
6272 LT, NULL_RTX, mode, unsignedp, 0);
6273 emit_jump_insn ((*gen_blt_pat) (default_label));
6276 emit_case_nodes (index, node->right, default_label, index_type);
6279 /* We cannot process node->right normally
6280 since we haven't ruled out the numbers less than
6281 this node's value. So handle node->right explicitly. */
6282 do_jump_if_equal (index,
6283 expand_expr (node->right->low, NULL_RTX,
6285 label_rtx (node->right->code_label), unsignedp);
6288 else if (node->right == 0 && node->left != 0)
6290 /* Just one subtree, on the left. */
6292 #if 0 /* The following code and comment were formerly part
6293 of the condition here, but they didn't work
6294 and I don't understand what the idea was. -- rms. */
6295 /* If our "most probable entry" is less probable
6296 than the default label, emit a jump to
6297 the default label using condition codes
6298 already lying around. With no right branch,
6299 a branch-greater-than will get us to the default
6302 && cost_table[TREE_INT_CST_LOW (node->high)] < 12)
6305 if (node->left->left || node->left->right
6306 || !tree_int_cst_equal (node->left->low, node->left->high))
6308 if (!node_has_high_bound (node, index_type))
6310 emit_cmp_insn (index, expand_expr (node->high, NULL_RTX,
6312 GT, NULL_RTX, mode, unsignedp, 0);
6313 emit_jump_insn ((*gen_bgt_pat) (default_label));
6316 emit_case_nodes (index, node->left, default_label, index_type);
6319 /* We cannot process node->left normally
6320 since we haven't ruled out the numbers less than
6321 this node's value. So handle node->left explicitly. */
6322 do_jump_if_equal (index,
6323 expand_expr (node->left->low, NULL_RTX,
6325 label_rtx (node->left->code_label), unsignedp);
6330 /* Node is a range. These cases are very similar to those for a single
6331 value, except that we do not start by testing whether this node
6332 is the one to branch to. */
6334 if (node->right != 0 && node->left != 0)
6336 /* Node has subtrees on both sides.
6337 If the right-hand subtree is bounded,
6338 test for it first, since we can go straight there.
6339 Otherwise, we need to make a branch in the control structure,
6340 then handle the two subtrees. */
6341 tree test_label = 0;
6343 emit_cmp_insn (index, expand_expr (node->high, NULL_RTX,
6345 GT, NULL_RTX, mode, unsignedp, 0);
6347 if (node_is_bounded (node->right, index_type))
6348 /* Right hand node is fully bounded so we can eliminate any
6349 testing and branch directly to the target code. */
6350 emit_jump_insn ((*gen_bgt_pat) (label_rtx (node->right->code_label)));
6353 /* Right hand node requires testing.
6354 Branch to a label where we will handle it later. */
6356 test_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
6357 emit_jump_insn ((*gen_bgt_pat) (label_rtx (test_label)));
6360 /* Value belongs to this node or to the left-hand subtree. */
6362 emit_cmp_insn (index, expand_expr (node->low, NULL_RTX, VOIDmode, 0),
6363 GE, NULL_RTX, mode, unsignedp, 0);
6364 emit_jump_insn ((*gen_bge_pat) (label_rtx (node->code_label)));
6366 /* Handle the left-hand subtree. */
6367 emit_case_nodes (index, node->left, default_label, index_type);
6369 /* If right node had to be handled later, do that now. */
6373 /* If the left-hand subtree fell through,
6374 don't let it fall into the right-hand subtree. */
6375 emit_jump_if_reachable (default_label);
6377 expand_label (test_label);
6378 emit_case_nodes (index, node->right, default_label, index_type);
6382 else if (node->right != 0 && node->left == 0)
6384 /* Deal with values to the left of this node,
6385 if they are possible. */
6386 if (!node_has_low_bound (node, index_type))
6388 emit_cmp_insn (index, expand_expr (node->low, NULL_RTX,
6390 LT, NULL_RTX, mode, unsignedp, 0);
6391 emit_jump_insn ((*gen_blt_pat) (default_label));
6394 /* Value belongs to this node or to the right-hand subtree. */
6396 emit_cmp_insn (index, expand_expr (node->high, NULL_RTX,
6398 LE, NULL_RTX, mode, unsignedp, 0);
6399 emit_jump_insn ((*gen_ble_pat) (label_rtx (node->code_label)));
6401 emit_case_nodes (index, node->right, default_label, index_type);
6404 else if (node->right == 0 && node->left != 0)
6406 /* Deal with values to the right of this node,
6407 if they are possible. */
6408 if (!node_has_high_bound (node, index_type))
6410 emit_cmp_insn (index, expand_expr (node->high, NULL_RTX,
6412 GT, NULL_RTX, mode, unsignedp, 0);
6413 emit_jump_insn ((*gen_bgt_pat) (default_label));
6416 /* Value belongs to this node or to the left-hand subtree. */
6418 emit_cmp_insn (index, expand_expr (node->low, NULL_RTX, VOIDmode, 0),
6419 GE, NULL_RTX, mode, unsignedp, 0);
6420 emit_jump_insn ((*gen_bge_pat) (label_rtx (node->code_label)));
6422 emit_case_nodes (index, node->left, default_label, index_type);
6427 /* Node has no children so we check low and high bounds to remove
6428 redundant tests. Only one of the bounds can exist,
6429 since otherwise this node is bounded--a case tested already. */
6431 if (!node_has_high_bound (node, index_type))
6433 emit_cmp_insn (index, expand_expr (node->high, NULL_RTX,
6435 GT, NULL_RTX, mode, unsignedp, 0);
6436 emit_jump_insn ((*gen_bgt_pat) (default_label));
6439 if (!node_has_low_bound (node, index_type))
6441 emit_cmp_insn (index, expand_expr (node->low, NULL_RTX,
6443 LT, NULL_RTX, mode, unsignedp, 0);
6444 emit_jump_insn ((*gen_blt_pat) (default_label));
6447 emit_jump (label_rtx (node->code_label));
6452 /* These routines are used by the loop unrolling code. They copy BLOCK trees
6453 so that the debugging info will be correct for the unrolled loop. */
6455 /* Indexed by block number, contains a pointer to the N'th block node. */
6457 static tree *block_vector;
6460 find_loop_tree_blocks ()
6462 tree block = DECL_INITIAL (current_function_decl);
6464 block_vector = identify_blocks (block, get_insns ());
6468 unroll_block_trees ()
6470 tree block = DECL_INITIAL (current_function_decl);
6472 reorder_blocks (block_vector, block, get_insns ());