1 /* Expands front end tree to back end RTL for GNU C-Compiler
2 Copyright (C) 1987, 88, 89, 92-5, 1996 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 #if 0 /* Turned off because 0 seems to work just as well. */
133 /* Cleanup lists are required for binding levels regardless of whether
134 that binding level has cleanups or not. This node serves as the
135 cleanup list whenever an empty list is required. */
136 static tree empty_cleanup_list;
139 /* Functions and data structures for expanding case statements. */
141 /* Case label structure, used to hold info on labels within case
142 statements. We handle "range" labels; for a single-value label
143 as in C, the high and low limits are the same.
145 An AVL tree of case nodes is initially created, and later transformed
146 to a list linked via the RIGHT fields in the nodes. Nodes with
147 higher case values are later in the list.
149 Switch statements can be output in one of two forms. A branch table
150 is used if there are more than a few labels and the labels are dense
151 within the range between the smallest and largest case value. If a
152 branch table is used, no further manipulations are done with the case
155 The alternative to the use of a branch table is to generate a series
156 of compare and jump insns. When that is done, we use the LEFT, RIGHT,
157 and PARENT fields to hold a binary tree. Initially the tree is
158 totally unbalanced, with everything on the right. We balance the tree
159 with nodes on the left having lower case values than the parent
160 and nodes on the right having higher values. We then output the tree
165 struct case_node *left; /* Left son in binary tree */
166 struct case_node *right; /* Right son in binary tree; also node chain */
167 struct case_node *parent; /* Parent of node in binary tree */
168 tree low; /* Lowest index value for this label */
169 tree high; /* Highest index value for this label */
170 tree code_label; /* Label to jump to when node matches */
174 typedef struct case_node case_node;
175 typedef struct case_node *case_node_ptr;
177 /* These are used by estimate_case_costs and balance_case_nodes. */
179 /* This must be a signed type, and non-ANSI compilers lack signed char. */
180 static short *cost_table;
181 static int use_cost_table;
183 /* Stack of control and binding constructs we are currently inside.
185 These constructs begin when you call `expand_start_WHATEVER'
186 and end when you call `expand_end_WHATEVER'. This stack records
187 info about how the construct began that tells the end-function
188 what to do. It also may provide information about the construct
189 to alter the behavior of other constructs within the body.
190 For example, they may affect the behavior of C `break' and `continue'.
192 Each construct gets one `struct nesting' object.
193 All of these objects are chained through the `all' field.
194 `nesting_stack' points to the first object (innermost construct).
195 The position of an entry on `nesting_stack' is in its `depth' field.
197 Each type of construct has its own individual stack.
198 For example, loops have `loop_stack'. Each object points to the
199 next object of the same type through the `next' field.
201 Some constructs are visible to `break' exit-statements and others
202 are not. Which constructs are visible depends on the language.
203 Therefore, the data structure allows each construct to be visible
204 or not, according to the args given when the construct is started.
205 The construct is visible if the `exit_label' field is non-null.
206 In that case, the value should be a CODE_LABEL rtx. */
211 struct nesting *next;
216 /* For conds (if-then and if-then-else statements). */
219 /* Label for the end of the if construct.
220 There is none if EXITFLAG was not set
221 and no `else' has been seen yet. */
223 /* Label for the end of this alternative.
224 This may be the end of the if or the next else/elseif. */
230 /* Label at the top of the loop; place to loop back to. */
232 /* Label at the end of the whole construct. */
234 /* Label before a jump that branches to the end of the whole
235 construct. This is where destructors go if any. */
237 /* Label for `continue' statement to jump to;
238 this is in front of the stepper of the loop. */
241 /* For variable binding contours. */
244 /* Sequence number of this binding contour within the function,
245 in order of entry. */
246 int block_start_count;
247 /* Nonzero => value to restore stack to on exit. Complemented by
248 bc_stack_level (see below) when generating bytecodes. */
250 /* The NOTE that starts this contour.
251 Used by expand_goto to check whether the destination
252 is within each contour or not. */
254 /* Innermost containing binding contour that has a stack level. */
255 struct nesting *innermost_stack_block;
256 /* List of cleanups to be run on exit from this contour.
257 This is a list of expressions to be evaluated.
258 The TREE_PURPOSE of each link is the ..._DECL node
259 which the cleanup pertains to. */
261 /* List of cleanup-lists of blocks containing this block,
262 as they were at the locus where this block appears.
263 There is an element for each containing block,
264 ordered innermost containing block first.
265 The tail of this list can be 0 (was empty_cleanup_list),
266 if all remaining elements would be empty lists.
267 The element's TREE_VALUE is the cleanup-list of that block,
268 which may be null. */
270 /* Chain of labels defined inside this binding contour.
271 For contours that have stack levels or cleanups. */
272 struct label_chain *label_chain;
273 /* Number of function calls seen, as of start of this block. */
274 int function_call_count;
275 /* Bytecode specific: stack level to restore stack to on exit. */
278 /* For switch (C) or case (Pascal) statements,
279 and also for dummies (see `expand_start_case_dummy'). */
282 /* The insn after which the case dispatch should finally
283 be emitted. Zero for a dummy. */
285 /* For bytecodes, the case table is in-lined right in the code.
286 A label is needed for skipping over this block. It is only
287 used when generating bytecodes. */
289 /* A list of case labels; it is first built as an AVL tree.
290 During expand_end_case, this is converted to a list, and may be
291 rearranged into a nearly balanced binary tree. */
292 struct case_node *case_list;
293 /* Label to jump to if no case matches. */
295 /* The expression to be dispatched on. */
297 /* Type that INDEX_EXPR should be converted to. */
299 /* Number of range exprs in case statement. */
301 /* Name of this kind of statement, for warnings. */
303 /* Nonzero if a case label has been seen in this case stmt. */
309 /* Chain of all pending binding contours. */
310 struct nesting *block_stack;
312 /* If any new stacks are added here, add them to POPSTACKS too. */
314 /* Chain of all pending binding contours that restore stack levels
316 struct nesting *stack_block_stack;
318 /* Chain of all pending conditional statements. */
319 struct nesting *cond_stack;
321 /* Chain of all pending loops. */
322 struct nesting *loop_stack;
324 /* Chain of all pending case or switch statements. */
325 struct nesting *case_stack;
327 /* Separate chain including all of the above,
328 chained through the `all' field. */
329 struct nesting *nesting_stack;
331 /* Number of entries on nesting_stack now. */
334 /* Allocate and return a new `struct nesting'. */
336 #define ALLOC_NESTING() \
337 (struct nesting *) obstack_alloc (&stmt_obstack, sizeof (struct nesting))
339 /* Pop the nesting stack element by element until we pop off
340 the element which is at the top of STACK.
341 Update all the other stacks, popping off elements from them
342 as we pop them from nesting_stack. */
344 #define POPSTACK(STACK) \
345 do { struct nesting *target = STACK; \
346 struct nesting *this; \
347 do { this = nesting_stack; \
348 if (loop_stack == this) \
349 loop_stack = loop_stack->next; \
350 if (cond_stack == this) \
351 cond_stack = cond_stack->next; \
352 if (block_stack == this) \
353 block_stack = block_stack->next; \
354 if (stack_block_stack == this) \
355 stack_block_stack = stack_block_stack->next; \
356 if (case_stack == this) \
357 case_stack = case_stack->next; \
358 nesting_depth = nesting_stack->depth - 1; \
359 nesting_stack = this->all; \
360 obstack_free (&stmt_obstack, this); } \
361 while (this != target); } while (0)
363 /* In some cases it is impossible to generate code for a forward goto
364 until the label definition is seen. This happens when it may be necessary
365 for the goto to reset the stack pointer: we don't yet know how to do that.
366 So expand_goto puts an entry on this fixup list.
367 Each time a binding contour that resets the stack is exited,
369 If the target label has now been defined, we can insert the proper code. */
373 /* Points to following fixup. */
374 struct goto_fixup *next;
375 /* Points to the insn before the jump insn.
376 If more code must be inserted, it goes after this insn. */
378 /* The LABEL_DECL that this jump is jumping to, or 0
379 for break, continue or return. */
381 /* The BLOCK for the place where this goto was found. */
383 /* The CODE_LABEL rtx that this is jumping to. */
385 /* Number of binding contours started in current function
386 before the label reference. */
387 int block_start_count;
388 /* The outermost stack level that should be restored for this jump.
389 Each time a binding contour that resets the stack is exited,
390 if the target label is *not* yet defined, this slot is updated. */
392 /* List of lists of cleanup expressions to be run by this goto.
393 There is one element for each block that this goto is within.
394 The tail of this list can be 0 (was empty_cleanup_list),
395 if all remaining elements would be empty.
396 The TREE_VALUE contains the cleanup list of that block as of the
397 time this goto was seen.
398 The TREE_ADDRESSABLE flag is 1 for a block that has been exited. */
399 tree cleanup_list_list;
401 /* Bytecode specific members follow */
403 /* The label that this jump is jumping to, or 0 for break, continue
405 struct bc_label *bc_target;
407 /* The label we use for the fixup patch */
408 struct bc_label *label;
410 /* True (non-0) if fixup has been handled */
413 /* Like stack_level above, except refers to the interpreter stack */
417 static struct goto_fixup *goto_fixup_chain;
419 /* Within any binding contour that must restore a stack level,
420 all labels are recorded with a chain of these structures. */
424 /* Points to following fixup. */
425 struct label_chain *next;
428 static void expand_goto_internal PROTO((tree, rtx, rtx));
429 static void bc_expand_goto_internal PROTO((enum bytecode_opcode,
430 struct bc_label *, tree));
431 static int expand_fixup PROTO((tree, rtx, rtx));
432 static void bc_expand_fixup PROTO((enum bytecode_opcode,
433 struct bc_label *, int));
434 static void fixup_gotos PROTO((struct nesting *, rtx, tree,
436 static void bc_fixup_gotos PROTO((struct nesting *, int, tree,
438 static void bc_expand_start_cond PROTO((tree, int));
439 static void bc_expand_end_cond PROTO((void));
440 static void bc_expand_start_else PROTO((void));
441 static void bc_expand_end_loop PROTO((void));
442 static void bc_expand_end_bindings PROTO((tree, int, int));
443 static void bc_expand_decl PROTO((tree, tree));
444 static void bc_expand_variable_local_init PROTO((tree));
445 static void bc_expand_decl_init PROTO((tree));
446 static void expand_null_return_1 PROTO((rtx, int));
447 static void expand_value_return PROTO((rtx));
448 static int tail_recursion_args PROTO((tree, tree));
449 static void expand_cleanups PROTO((tree, tree, int, int));
450 static void bc_expand_start_case PROTO((struct nesting *, tree,
452 static int bc_pushcase PROTO((tree, tree));
453 static void bc_check_for_full_enumeration_handling PROTO((tree));
454 static void bc_expand_end_case PROTO((tree));
455 static void do_jump_if_equal PROTO((rtx, rtx, rtx, int));
456 static int estimate_case_costs PROTO((case_node_ptr));
457 static void group_case_nodes PROTO((case_node_ptr));
458 static void balance_case_nodes PROTO((case_node_ptr *,
460 static int node_has_low_bound PROTO((case_node_ptr, tree));
461 static int node_has_high_bound PROTO((case_node_ptr, tree));
462 static int node_is_bounded PROTO((case_node_ptr, tree));
463 static void emit_jump_if_reachable PROTO((rtx));
464 static void emit_case_nodes PROTO((rtx, case_node_ptr, rtx, tree));
465 static int add_case_node PROTO((tree, tree, tree, tree *));
466 static struct case_node *case_tree2list PROTO((case_node *, case_node *));
468 extern rtx bc_allocate_local ();
469 extern rtx bc_allocate_variable_array ();
474 gcc_obstack_init (&stmt_obstack);
479 init_stmt_for_function ()
481 /* We are not currently within any block, conditional, loop or case. */
483 stack_block_stack = 0;
490 block_start_count = 0;
492 /* No gotos have been expanded yet. */
493 goto_fixup_chain = 0;
495 /* We are not processing a ({...}) grouping. */
496 expr_stmts_for_value = 0;
499 init_eh_for_function ();
506 p->block_stack = block_stack;
507 p->stack_block_stack = stack_block_stack;
508 p->cond_stack = cond_stack;
509 p->loop_stack = loop_stack;
510 p->case_stack = case_stack;
511 p->nesting_stack = nesting_stack;
512 p->nesting_depth = nesting_depth;
513 p->block_start_count = block_start_count;
514 p->last_expr_type = last_expr_type;
515 p->last_expr_value = last_expr_value;
516 p->expr_stmts_for_value = expr_stmts_for_value;
517 p->emit_filename = emit_filename;
518 p->emit_lineno = emit_lineno;
519 p->goto_fixup_chain = goto_fixup_chain;
524 restore_stmt_status (p)
527 block_stack = p->block_stack;
528 stack_block_stack = p->stack_block_stack;
529 cond_stack = p->cond_stack;
530 loop_stack = p->loop_stack;
531 case_stack = p->case_stack;
532 nesting_stack = p->nesting_stack;
533 nesting_depth = p->nesting_depth;
534 block_start_count = p->block_start_count;
535 last_expr_type = p->last_expr_type;
536 last_expr_value = p->last_expr_value;
537 expr_stmts_for_value = p->expr_stmts_for_value;
538 emit_filename = p->emit_filename;
539 emit_lineno = p->emit_lineno;
540 goto_fixup_chain = p->goto_fixup_chain;
541 restore_eh_status (p);
544 /* Emit a no-op instruction. */
551 if (!output_bytecode)
553 last_insn = get_last_insn ();
555 && (GET_CODE (last_insn) == CODE_LABEL
556 || (GET_CODE (last_insn) == NOTE
557 && prev_real_insn (last_insn) == 0)))
558 emit_insn (gen_nop ());
562 /* Return the rtx-label that corresponds to a LABEL_DECL,
563 creating it if necessary. */
569 if (TREE_CODE (label) != LABEL_DECL)
572 if (DECL_RTL (label))
573 return DECL_RTL (label);
575 return DECL_RTL (label) = gen_label_rtx ();
578 /* Add an unconditional jump to LABEL as the next sequential instruction. */
584 do_pending_stack_adjust ();
585 emit_jump_insn (gen_jump (label));
589 /* Emit code to jump to the address
590 specified by the pointer expression EXP. */
593 expand_computed_goto (exp)
598 bc_expand_expr (exp);
599 bc_emit_instruction (jumpP);
603 rtx x = expand_expr (exp, NULL_RTX, VOIDmode, 0);
605 #ifdef POINTERS_EXTEND_UNSIGNED
606 x = convert_memory_address (Pmode, x);
610 do_pending_stack_adjust ();
611 emit_indirect_jump (x);
615 /* Handle goto statements and the labels that they can go to. */
617 /* Specify the location in the RTL code of a label LABEL,
618 which is a LABEL_DECL tree node.
620 This is used for the kind of label that the user can jump to with a
621 goto statement, and for alternatives of a switch or case statement.
622 RTL labels generated for loops and conditionals don't go through here;
623 they are generated directly at the RTL level, by other functions below.
625 Note that this has nothing to do with defining label *names*.
626 Languages vary in how they do that and what that even means. */
632 struct label_chain *p;
636 if (! DECL_RTL (label))
637 DECL_RTL (label) = bc_gen_rtx ((char *) 0, 0, bc_get_bytecode_label ());
638 if (! bc_emit_bytecode_labeldef (BYTECODE_BC_LABEL (DECL_RTL (label))))
639 error ("multiply defined label");
643 do_pending_stack_adjust ();
644 emit_label (label_rtx (label));
645 if (DECL_NAME (label))
646 LABEL_NAME (DECL_RTL (label)) = IDENTIFIER_POINTER (DECL_NAME (label));
648 if (stack_block_stack != 0)
650 p = (struct label_chain *) oballoc (sizeof (struct label_chain));
651 p->next = stack_block_stack->data.block.label_chain;
652 stack_block_stack->data.block.label_chain = p;
657 /* Declare that LABEL (a LABEL_DECL) may be used for nonlocal gotos
658 from nested functions. */
661 declare_nonlocal_label (label)
664 nonlocal_labels = tree_cons (NULL_TREE, label, nonlocal_labels);
665 LABEL_PRESERVE_P (label_rtx (label)) = 1;
666 if (nonlocal_goto_handler_slot == 0)
668 nonlocal_goto_handler_slot
669 = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
670 emit_stack_save (SAVE_NONLOCAL,
671 &nonlocal_goto_stack_level,
672 PREV_INSN (tail_recursion_reentry));
676 /* Generate RTL code for a `goto' statement with target label LABEL.
677 LABEL should be a LABEL_DECL tree node that was or will later be
678 defined with `expand_label'. */
688 expand_goto_internal (label, label_rtx (label), NULL_RTX);
692 /* Check for a nonlocal goto to a containing function. */
693 context = decl_function_context (label);
694 if (context != 0 && context != current_function_decl)
696 struct function *p = find_function_data (context);
697 rtx label_ref = gen_rtx (LABEL_REF, Pmode, label_rtx (label));
700 p->has_nonlocal_label = 1;
701 current_function_has_nonlocal_goto = 1;
702 LABEL_REF_NONLOCAL_P (label_ref) = 1;
704 /* Copy the rtl for the slots so that they won't be shared in
705 case the virtual stack vars register gets instantiated differently
706 in the parent than in the child. */
708 #if HAVE_nonlocal_goto
709 if (HAVE_nonlocal_goto)
710 emit_insn (gen_nonlocal_goto (lookup_static_chain (label),
711 copy_rtx (p->nonlocal_goto_handler_slot),
712 copy_rtx (p->nonlocal_goto_stack_level),
719 /* Restore frame pointer for containing function.
720 This sets the actual hard register used for the frame pointer
721 to the location of the function's incoming static chain info.
722 The non-local goto handler will then adjust it to contain the
723 proper value and reload the argument pointer, if needed. */
724 emit_move_insn (hard_frame_pointer_rtx, lookup_static_chain (label));
726 /* We have now loaded the frame pointer hardware register with
727 the address of that corresponds to the start of the virtual
728 stack vars. So replace virtual_stack_vars_rtx in all
729 addresses we use with stack_pointer_rtx. */
731 /* Get addr of containing function's current nonlocal goto handler,
732 which will do any cleanups and then jump to the label. */
733 addr = copy_rtx (p->nonlocal_goto_handler_slot);
734 temp = copy_to_reg (replace_rtx (addr, virtual_stack_vars_rtx,
735 hard_frame_pointer_rtx));
737 /* Restore the stack pointer. Note this uses fp just restored. */
738 addr = p->nonlocal_goto_stack_level;
740 addr = replace_rtx (copy_rtx (addr),
741 virtual_stack_vars_rtx,
742 hard_frame_pointer_rtx);
744 emit_stack_restore (SAVE_NONLOCAL, addr, NULL_RTX);
746 /* Put in the static chain register the nonlocal label address. */
747 emit_move_insn (static_chain_rtx, label_ref);
748 /* USE of hard_frame_pointer_rtx added for consistency; not clear if
750 emit_insn (gen_rtx (USE, VOIDmode, hard_frame_pointer_rtx));
751 emit_insn (gen_rtx (USE, VOIDmode, stack_pointer_rtx));
752 emit_insn (gen_rtx (USE, VOIDmode, static_chain_rtx));
753 emit_indirect_jump (temp);
757 expand_goto_internal (label, label_rtx (label), NULL_RTX);
760 /* Generate RTL code for a `goto' statement with target label BODY.
761 LABEL should be a LABEL_REF.
762 LAST_INSN, if non-0, is the rtx we should consider as the last
763 insn emitted (for the purposes of cleaning up a return). */
766 expand_goto_internal (body, label, last_insn)
771 struct nesting *block;
774 /* NOTICE! If a bytecode instruction other than `jump' is needed,
775 then the caller has to call bc_expand_goto_internal()
776 directly. This is rather an exceptional case, and there aren't
777 that many places where this is necessary. */
780 expand_goto_internal (body, label, last_insn);
784 if (GET_CODE (label) != CODE_LABEL)
787 /* If label has already been defined, we can tell now
788 whether and how we must alter the stack level. */
790 if (PREV_INSN (label) != 0)
792 /* Find the innermost pending block that contains the label.
793 (Check containment by comparing insn-uids.)
794 Then restore the outermost stack level within that block,
795 and do cleanups of all blocks contained in it. */
796 for (block = block_stack; block; block = block->next)
798 if (INSN_UID (block->data.block.first_insn) < INSN_UID (label))
800 if (block->data.block.stack_level != 0)
801 stack_level = block->data.block.stack_level;
802 /* Execute the cleanups for blocks we are exiting. */
803 if (block->data.block.cleanups != 0)
805 expand_cleanups (block->data.block.cleanups, NULL_TREE, 1, 1);
806 do_pending_stack_adjust ();
812 /* Ensure stack adjust isn't done by emit_jump, as this
813 would clobber the stack pointer. This one should be
814 deleted as dead by flow. */
815 clear_pending_stack_adjust ();
816 do_pending_stack_adjust ();
817 emit_stack_restore (SAVE_BLOCK, stack_level, NULL_RTX);
820 if (body != 0 && DECL_TOO_LATE (body))
821 error ("jump to `%s' invalidly jumps into binding contour",
822 IDENTIFIER_POINTER (DECL_NAME (body)));
824 /* Label not yet defined: may need to put this goto
825 on the fixup list. */
826 else if (! expand_fixup (body, label, last_insn))
828 /* No fixup needed. Record that the label is the target
829 of at least one goto that has no fixup. */
831 TREE_ADDRESSABLE (body) = 1;
837 /* Generate a jump with OPCODE to the given bytecode LABEL which is
838 found within BODY. */
841 bc_expand_goto_internal (opcode, label, body)
842 enum bytecode_opcode opcode;
843 struct bc_label *label;
846 struct nesting *block;
847 int stack_level = -1;
849 /* If the label is defined, adjust the stack as necessary.
850 If it's not defined, we have to push the reference on the
856 /* Find the innermost pending block that contains the label.
857 (Check containment by comparing bytecode uids.) Then restore the
858 outermost stack level within that block. */
860 for (block = block_stack; block; block = block->next)
862 if (BYTECODE_BC_LABEL (block->data.block.first_insn)->uid < label->uid)
864 if (block->data.block.bc_stack_level)
865 stack_level = block->data.block.bc_stack_level;
867 /* Execute the cleanups for blocks we are exiting. */
868 if (block->data.block.cleanups != 0)
870 expand_cleanups (block->data.block.cleanups, NULL_TREE, 1, 1);
871 do_pending_stack_adjust ();
875 /* Restore the stack level. If we need to adjust the stack, we
876 must do so after the jump, since the jump may depend on
877 what's on the stack. Thus, any stack-modifying conditional
878 jumps (these are the only ones that rely on what's on the
879 stack) go into the fixup list. */
882 && stack_depth != stack_level
885 bc_expand_fixup (opcode, label, stack_level);
888 if (stack_level >= 0)
889 bc_adjust_stack (stack_depth - stack_level);
891 if (body && DECL_BIT_FIELD (body))
892 error ("jump to `%s' invalidly jumps into binding contour",
893 IDENTIFIER_POINTER (DECL_NAME (body)));
895 /* Emit immediate jump */
896 bc_emit_bytecode (opcode);
897 bc_emit_bytecode_labelref (label);
899 #ifdef DEBUG_PRINT_CODE
900 fputc ('\n', stderr);
905 /* Put goto in the fixup list */
906 bc_expand_fixup (opcode, label, stack_level);
909 /* Generate if necessary a fixup for a goto
910 whose target label in tree structure (if any) is TREE_LABEL
911 and whose target in rtl is RTL_LABEL.
913 If LAST_INSN is nonzero, we pretend that the jump appears
914 after insn LAST_INSN instead of at the current point in the insn stream.
916 The fixup will be used later to insert insns just before the goto.
917 Those insns will restore the stack level as appropriate for the
918 target label, and will (in the case of C++) also invoke any object
919 destructors which have to be invoked when we exit the scopes which
920 are exited by the goto.
922 Value is nonzero if a fixup is made. */
925 expand_fixup (tree_label, rtl_label, last_insn)
930 struct nesting *block, *end_block;
932 /* See if we can recognize which block the label will be output in.
933 This is possible in some very common cases.
934 If we succeed, set END_BLOCK to that block.
935 Otherwise, set it to 0. */
938 && (rtl_label == cond_stack->data.cond.endif_label
939 || rtl_label == cond_stack->data.cond.next_label))
940 end_block = cond_stack;
941 /* If we are in a loop, recognize certain labels which
942 are likely targets. This reduces the number of fixups
943 we need to create. */
945 && (rtl_label == loop_stack->data.loop.start_label
946 || rtl_label == loop_stack->data.loop.end_label
947 || rtl_label == loop_stack->data.loop.continue_label))
948 end_block = loop_stack;
952 /* Now set END_BLOCK to the binding level to which we will return. */
956 struct nesting *next_block = end_block->all;
959 /* First see if the END_BLOCK is inside the innermost binding level.
960 If so, then no cleanups or stack levels are relevant. */
961 while (next_block && next_block != block)
962 next_block = next_block->all;
967 /* Otherwise, set END_BLOCK to the innermost binding level
968 which is outside the relevant control-structure nesting. */
969 next_block = block_stack->next;
970 for (block = block_stack; block != end_block; block = block->all)
971 if (block == next_block)
972 next_block = next_block->next;
973 end_block = next_block;
976 /* Does any containing block have a stack level or cleanups?
977 If not, no fixup is needed, and that is the normal case
978 (the only case, for standard C). */
979 for (block = block_stack; block != end_block; block = block->next)
980 if (block->data.block.stack_level != 0
981 || block->data.block.cleanups != 0)
984 if (block != end_block)
986 /* Ok, a fixup is needed. Add a fixup to the list of such. */
987 struct goto_fixup *fixup
988 = (struct goto_fixup *) oballoc (sizeof (struct goto_fixup));
989 /* In case an old stack level is restored, make sure that comes
990 after any pending stack adjust. */
991 /* ?? If the fixup isn't to come at the present position,
992 doing the stack adjust here isn't useful. Doing it with our
993 settings at that location isn't useful either. Let's hope
996 do_pending_stack_adjust ();
997 fixup->target = tree_label;
998 fixup->target_rtl = rtl_label;
1000 /* Create a BLOCK node and a corresponding matched set of
1001 NOTE_INSN_BEGIN_BLOCK and NOTE_INSN_END_BLOCK notes at
1002 this point. The notes will encapsulate any and all fixup
1003 code which we might later insert at this point in the insn
1004 stream. Also, the BLOCK node will be the parent (i.e. the
1005 `SUPERBLOCK') of any other BLOCK nodes which we might create
1006 later on when we are expanding the fixup code. */
1009 register rtx original_before_jump
1010 = last_insn ? last_insn : get_last_insn ();
1014 fixup->before_jump = emit_note (NULL_PTR, NOTE_INSN_BLOCK_BEG);
1015 last_block_end_note = emit_note (NULL_PTR, NOTE_INSN_BLOCK_END);
1016 fixup->context = poplevel (1, 0, 0); /* Create the BLOCK node now! */
1018 emit_insns_after (fixup->before_jump, original_before_jump);
1021 fixup->block_start_count = block_start_count;
1022 fixup->stack_level = 0;
1023 fixup->cleanup_list_list
1024 = (((block->data.block.outer_cleanups
1026 && block->data.block.outer_cleanups != empty_cleanup_list
1029 || block->data.block.cleanups)
1030 ? tree_cons (NULL_TREE, block->data.block.cleanups,
1031 block->data.block.outer_cleanups)
1033 fixup->next = goto_fixup_chain;
1034 goto_fixup_chain = fixup;
1041 /* Generate bytecode jump with OPCODE to a fixup routine that links to LABEL.
1042 Make the fixup restore the stack level to STACK_LEVEL. */
1045 bc_expand_fixup (opcode, label, stack_level)
1046 enum bytecode_opcode opcode;
1047 struct bc_label *label;
1050 struct goto_fixup *fixup
1051 = (struct goto_fixup *) oballoc (sizeof (struct goto_fixup));
1053 fixup->label = bc_get_bytecode_label ();
1054 fixup->bc_target = label;
1055 fixup->bc_stack_level = stack_level;
1056 fixup->bc_handled = FALSE;
1058 fixup->next = goto_fixup_chain;
1059 goto_fixup_chain = fixup;
1061 /* Insert a jump to the fixup code */
1062 bc_emit_bytecode (opcode);
1063 bc_emit_bytecode_labelref (fixup->label);
1065 #ifdef DEBUG_PRINT_CODE
1066 fputc ('\n', stderr);
1070 /* Expand any needed fixups in the outputmost binding level of the
1071 function. FIRST_INSN is the first insn in the function. */
1074 expand_fixups (first_insn)
1077 fixup_gotos (NULL_PTR, NULL_RTX, NULL_TREE, first_insn, 0);
1080 /* When exiting a binding contour, process all pending gotos requiring fixups.
1081 THISBLOCK is the structure that describes the block being exited.
1082 STACK_LEVEL is the rtx for the stack level to restore exiting this contour.
1083 CLEANUP_LIST is a list of expressions to evaluate on exiting this contour.
1084 FIRST_INSN is the insn that began this contour.
1086 Gotos that jump out of this contour must restore the
1087 stack level and do the cleanups before actually jumping.
1089 DONT_JUMP_IN nonzero means report error there is a jump into this
1090 contour from before the beginning of the contour.
1091 This is also done if STACK_LEVEL is nonzero. */
1094 fixup_gotos (thisblock, stack_level, cleanup_list, first_insn, dont_jump_in)
1095 struct nesting *thisblock;
1101 register struct goto_fixup *f, *prev;
1103 if (output_bytecode)
1105 /* ??? The second arg is the bc stack level, which is not the same
1106 as STACK_LEVEL. I have no idea what should go here, so I'll
1108 bc_fixup_gotos (thisblock, 0, cleanup_list, first_insn, dont_jump_in);
1112 /* F is the fixup we are considering; PREV is the previous one. */
1113 /* We run this loop in two passes so that cleanups of exited blocks
1114 are run first, and blocks that are exited are marked so
1117 for (prev = 0, f = goto_fixup_chain; f; prev = f, f = f->next)
1119 /* Test for a fixup that is inactive because it is already handled. */
1120 if (f->before_jump == 0)
1122 /* Delete inactive fixup from the chain, if that is easy to do. */
1124 prev->next = f->next;
1126 /* Has this fixup's target label been defined?
1127 If so, we can finalize it. */
1128 else if (PREV_INSN (f->target_rtl) != 0)
1130 register rtx cleanup_insns;
1132 /* Get the first non-label after the label
1133 this goto jumps to. If that's before this scope begins,
1134 we don't have a jump into the scope. */
1135 rtx after_label = f->target_rtl;
1136 while (after_label != 0 && GET_CODE (after_label) == CODE_LABEL)
1137 after_label = NEXT_INSN (after_label);
1139 /* If this fixup jumped into this contour from before the beginning
1140 of this contour, report an error. */
1141 /* ??? Bug: this does not detect jumping in through intermediate
1142 blocks that have stack levels or cleanups.
1143 It detects only a problem with the innermost block
1144 around the label. */
1146 && (dont_jump_in || stack_level || cleanup_list)
1147 /* If AFTER_LABEL is 0, it means the jump goes to the end
1148 of the rtl, which means it jumps into this scope. */
1149 && (after_label == 0
1150 || INSN_UID (first_insn) < INSN_UID (after_label))
1151 && INSN_UID (first_insn) > INSN_UID (f->before_jump)
1152 && ! DECL_ERROR_ISSUED (f->target))
1154 error_with_decl (f->target,
1155 "label `%s' used before containing binding contour");
1156 /* Prevent multiple errors for one label. */
1157 DECL_ERROR_ISSUED (f->target) = 1;
1160 /* We will expand the cleanups into a sequence of their own and
1161 then later on we will attach this new sequence to the insn
1162 stream just ahead of the actual jump insn. */
1166 /* Temporarily restore the lexical context where we will
1167 logically be inserting the fixup code. We do this for the
1168 sake of getting the debugging information right. */
1171 set_block (f->context);
1173 /* Expand the cleanups for blocks this jump exits. */
1174 if (f->cleanup_list_list)
1177 for (lists = f->cleanup_list_list; lists; lists = TREE_CHAIN (lists))
1178 /* Marked elements correspond to blocks that have been closed.
1179 Do their cleanups. */
1180 if (TREE_ADDRESSABLE (lists)
1181 && TREE_VALUE (lists) != 0)
1183 expand_cleanups (TREE_VALUE (lists), NULL_TREE, 1, 1);
1184 /* Pop any pushes done in the cleanups,
1185 in case function is about to return. */
1186 do_pending_stack_adjust ();
1190 /* Restore stack level for the biggest contour that this
1191 jump jumps out of. */
1193 emit_stack_restore (SAVE_BLOCK, f->stack_level, f->before_jump);
1195 /* Finish up the sequence containing the insns which implement the
1196 necessary cleanups, and then attach that whole sequence to the
1197 insn stream just ahead of the actual jump insn. Attaching it
1198 at that point insures that any cleanups which are in fact
1199 implicit C++ object destructions (which must be executed upon
1200 leaving the block) appear (to the debugger) to be taking place
1201 in an area of the generated code where the object(s) being
1202 destructed are still "in scope". */
1204 cleanup_insns = get_insns ();
1208 emit_insns_after (cleanup_insns, f->before_jump);
1215 /* For any still-undefined labels, do the cleanups for this block now.
1216 We must do this now since items in the cleanup list may go out
1217 of scope when the block ends. */
1218 for (prev = 0, f = goto_fixup_chain; f; prev = f, f = f->next)
1219 if (f->before_jump != 0
1220 && PREV_INSN (f->target_rtl) == 0
1221 /* Label has still not appeared. If we are exiting a block with
1222 a stack level to restore, that started before the fixup,
1223 mark this stack level as needing restoration
1224 when the fixup is later finalized. */
1226 /* Note: if THISBLOCK == 0 and we have a label that hasn't appeared, it
1227 means the label is undefined. That's erroneous, but possible. */
1228 && (thisblock->data.block.block_start_count
1229 <= f->block_start_count))
1231 tree lists = f->cleanup_list_list;
1234 for (; lists; lists = TREE_CHAIN (lists))
1235 /* If the following elt. corresponds to our containing block
1236 then the elt. must be for this block. */
1237 if (TREE_CHAIN (lists) == thisblock->data.block.outer_cleanups)
1241 set_block (f->context);
1242 expand_cleanups (TREE_VALUE (lists), NULL_TREE, 1, 1);
1243 do_pending_stack_adjust ();
1244 cleanup_insns = get_insns ();
1247 if (cleanup_insns != 0)
1249 = emit_insns_after (cleanup_insns, f->before_jump);
1251 f->cleanup_list_list = TREE_CHAIN (lists);
1255 f->stack_level = stack_level;
1260 /* When exiting a binding contour, process all pending gotos requiring fixups.
1261 Note: STACK_DEPTH is not altered.
1263 The arguments are currently not used in the bytecode compiler, but we may
1264 need them one day for languages other than C.
1266 THISBLOCK is the structure that describes the block being exited.
1267 STACK_LEVEL is the rtx for the stack level to restore exiting this contour.
1268 CLEANUP_LIST is a list of expressions to evaluate on exiting this contour.
1269 FIRST_INSN is the insn that began this contour.
1271 Gotos that jump out of this contour must restore the
1272 stack level and do the cleanups before actually jumping.
1274 DONT_JUMP_IN nonzero means report error there is a jump into this
1275 contour from before the beginning of the contour.
1276 This is also done if STACK_LEVEL is nonzero. */
1279 bc_fixup_gotos (thisblock, stack_level, cleanup_list, first_insn, dont_jump_in)
1280 struct nesting *thisblock;
1286 register struct goto_fixup *f, *prev;
1287 int saved_stack_depth;
1289 /* F is the fixup we are considering; PREV is the previous one. */
1291 for (prev = 0, f = goto_fixup_chain; f; prev = f, f = f->next)
1293 /* Test for a fixup that is inactive because it is already handled. */
1294 if (f->before_jump == 0)
1296 /* Delete inactive fixup from the chain, if that is easy to do. */
1298 prev->next = f->next;
1301 /* Emit code to restore the stack and continue */
1302 bc_emit_bytecode_labeldef (f->label);
1304 /* Save stack_depth across call, since bc_adjust_stack () will alter
1305 the perceived stack depth via the instructions generated. */
1307 if (f->bc_stack_level >= 0)
1309 saved_stack_depth = stack_depth;
1310 bc_adjust_stack (stack_depth - f->bc_stack_level);
1311 stack_depth = saved_stack_depth;
1314 bc_emit_bytecode (jump);
1315 bc_emit_bytecode_labelref (f->bc_target);
1317 #ifdef DEBUG_PRINT_CODE
1318 fputc ('\n', stderr);
1322 goto_fixup_chain = NULL;
1325 /* Generate RTL for an asm statement (explicit assembler code).
1326 BODY is a STRING_CST node containing the assembler code text,
1327 or an ADDR_EXPR containing a STRING_CST. */
1333 if (output_bytecode)
1335 error ("`asm' is invalid when generating bytecode");
1339 if (TREE_CODE (body) == ADDR_EXPR)
1340 body = TREE_OPERAND (body, 0);
1342 emit_insn (gen_rtx (ASM_INPUT, VOIDmode,
1343 TREE_STRING_POINTER (body)));
1347 /* Generate RTL for an asm statement with arguments.
1348 STRING is the instruction template.
1349 OUTPUTS is a list of output arguments (lvalues); INPUTS a list of inputs.
1350 Each output or input has an expression in the TREE_VALUE and
1351 a constraint-string in the TREE_PURPOSE.
1352 CLOBBERS is a list of STRING_CST nodes each naming a hard register
1353 that is clobbered by this insn.
1355 Not all kinds of lvalue that may appear in OUTPUTS can be stored directly.
1356 Some elements of OUTPUTS may be replaced with trees representing temporary
1357 values. The caller should copy those temporary values to the originally
1360 VOL nonzero means the insn is volatile; don't optimize it. */
1363 expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line)
1364 tree string, outputs, inputs, clobbers;
1369 rtvec argvec, constraints;
1371 int ninputs = list_length (inputs);
1372 int noutputs = list_length (outputs);
1377 /* Vector of RTX's of evaluated output operands. */
1378 rtx *output_rtx = (rtx *) alloca (noutputs * sizeof (rtx));
1379 int *inout_opnum = (int *) alloca (noutputs * sizeof (int));
1380 enum machine_mode *inout_mode
1381 = (enum machine_mode *) alloca (noutputs * sizeof (enum machine_mode));
1382 /* The insn we have emitted. */
1385 if (output_bytecode)
1387 error ("`asm' is invalid when generating bytecode");
1391 /* Count the number of meaningful clobbered registers, ignoring what
1392 we would ignore later. */
1394 for (tail = clobbers; tail; tail = TREE_CHAIN (tail))
1396 char *regname = TREE_STRING_POINTER (TREE_VALUE (tail));
1397 i = decode_reg_name (regname);
1398 if (i >= 0 || i == -4)
1401 error ("unknown register name `%s' in `asm'", regname);
1406 for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
1408 tree val = TREE_VALUE (tail);
1409 tree type = TREE_TYPE (val);
1412 int found_equal = 0;
1416 /* If there's an erroneous arg, emit no insn. */
1417 if (TREE_TYPE (val) == error_mark_node)
1420 /* Make sure constraint has `=' and does not have `+'. Also, see
1421 if it allows any register. Be liberal on the latter test, since
1422 the worst that happens if we get it wrong is we issue an error
1425 for (j = 0; j < TREE_STRING_LENGTH (TREE_PURPOSE (tail)) - 1; j++)
1426 switch (TREE_STRING_POINTER (TREE_PURPOSE (tail))[j])
1429 /* Make sure we can specify the matching operand. */
1432 error ("output operand constraint %d contains `+'", i);
1436 /* Replace '+' with '='. */
1437 TREE_STRING_POINTER (TREE_PURPOSE (tail))[j] = '=';
1445 case '?': case '!': case '*': case '%': case '&':
1446 case 'V': case 'm': case 'o': case '<': case '>':
1447 case 'E': case 'F': case 'G': case 'H': case 'X':
1448 case 's': case 'i': case 'n':
1449 case 'I': case 'J': case 'K': case 'L': case 'M':
1450 case 'N': case 'O': case 'P': case ',':
1451 #ifdef EXTRA_CONSTRAINT
1452 case 'Q': case 'R': case 'S': case 'T': case 'U':
1456 case 'p': case 'g': case 'r':
1457 /* Whether or not a numeric constraint allows a register is
1458 decided by the matching constraint, and so there is no need
1459 to do anything special with them. We must handle them in
1460 the default case, so that we don't unnecessarily force
1461 operands to memory. */
1462 case '0': case '1': case '2': case '3': case '4':
1468 if (! found_equal && ! found_plus)
1470 error ("output operand constraint lacks `='");
1474 /* If an output operand is not a decl or indirect ref and our constraint
1475 allows a register, make a temporary to act as an intermediate.
1476 Make the asm insn write into that, then our caller will copy it to
1477 the real output operand. Likewise for promoted variables. */
1479 if (TREE_CODE (val) == INDIRECT_REF
1480 || (TREE_CODE_CLASS (TREE_CODE (val)) == 'd'
1481 && ! (GET_CODE (DECL_RTL (val)) == REG
1482 && GET_MODE (DECL_RTL (val)) != TYPE_MODE (type)))
1487 mark_addressable (TREE_VALUE (tail));
1490 = expand_expr (TREE_VALUE (tail), NULL_RTX, VOIDmode, 0);
1492 if (! allows_reg && GET_CODE (output_rtx[i]) != MEM)
1493 error ("output number %d not directly addressable", i);
1497 output_rtx[i] = assign_temp (type, 0, 0, 0);
1498 TREE_VALUE (tail) = make_tree (type, output_rtx[i]);
1503 inout_mode[ninout] = TYPE_MODE (TREE_TYPE (TREE_VALUE (tail)));
1504 inout_opnum[ninout++] = i;
1509 if (ninputs + noutputs > MAX_RECOG_OPERANDS)
1511 error ("more than %d operands in `asm'", MAX_RECOG_OPERANDS);
1515 /* Make vectors for the expression-rtx and constraint strings. */
1517 argvec = rtvec_alloc (ninputs);
1518 constraints = rtvec_alloc (ninputs);
1520 body = gen_rtx (ASM_OPERANDS, VOIDmode,
1521 TREE_STRING_POINTER (string), "", 0, argvec, constraints,
1523 MEM_VOLATILE_P (body) = vol;
1525 /* Eval the inputs and put them into ARGVEC.
1526 Put their constraints into ASM_INPUTs and store in CONSTRAINTS. */
1529 for (tail = inputs; tail; tail = TREE_CHAIN (tail))
1534 /* If there's an erroneous arg, emit no insn,
1535 because the ASM_INPUT would get VOIDmode
1536 and that could cause a crash in reload. */
1537 if (TREE_TYPE (TREE_VALUE (tail)) == error_mark_node)
1539 if (TREE_PURPOSE (tail) == NULL_TREE)
1541 error ("hard register `%s' listed as input operand to `asm'",
1542 TREE_STRING_POINTER (TREE_VALUE (tail)) );
1546 /* Make sure constraint has neither `=' nor `+'. */
1548 for (j = 0; j < TREE_STRING_LENGTH (TREE_PURPOSE (tail)) - 1; j++)
1549 switch (TREE_STRING_POINTER (TREE_PURPOSE (tail))[j])
1552 error ("input operand constraint contains `%c'",
1553 TREE_STRING_POINTER (TREE_PURPOSE (tail))[j]);
1556 case '?': case '!': case '*': case '%': case '&':
1557 case 'V': case 'm': case 'o': case '<': case '>':
1558 case 'E': case 'F': case 'G': case 'H': case 'X':
1559 case 's': case 'i': case 'n':
1560 case 'I': case 'J': case 'K': case 'L': case 'M':
1561 case 'N': case 'O': case 'P': case ',':
1562 #ifdef EXTRA_CONSTRAINT
1563 case 'Q': case 'R': case 'S': case 'T': case 'U':
1567 case 'p': case 'g': case 'r':
1568 /* Whether or not a numeric constraint allows a register is
1569 decided by the matching constraint, and so there is no need
1570 to do anything special with them. We must handle them in
1571 the default case, so that we don't unnecessarily force
1572 operands to memory. */
1573 case '0': case '1': case '2': case '3': case '4':
1580 mark_addressable (TREE_VALUE (tail));
1582 XVECEXP (body, 3, i) /* argvec */
1583 = expand_expr (TREE_VALUE (tail), NULL_RTX, VOIDmode, 0);
1584 if (CONSTANT_P (XVECEXP (body, 3, i))
1585 && ! general_operand (XVECEXP (body, 3, i),
1586 TYPE_MODE (TREE_TYPE (TREE_VALUE (tail)))))
1589 XVECEXP (body, 3, i)
1590 = force_reg (TYPE_MODE (TREE_TYPE (TREE_VALUE (tail))),
1591 XVECEXP (body, 3, i));
1593 XVECEXP (body, 3, i)
1594 = force_const_mem (TYPE_MODE (TREE_TYPE (TREE_VALUE (tail))),
1595 XVECEXP (body, 3, i));
1599 && (GET_CODE (XVECEXP (body, 3, i)) == REG
1600 || GET_CODE (XVECEXP (body, 3, i)) == SUBREG
1601 || GET_CODE (XVECEXP (body, 3, i)) == CONCAT))
1603 tree type = TREE_TYPE (TREE_VALUE (tail));
1604 rtx memloc = assign_temp (type, 1, 1, 1);
1606 emit_move_insn (memloc, XVECEXP (body, 3, i));
1607 XVECEXP (body, 3, i) = memloc;
1610 XVECEXP (body, 4, i) /* constraints */
1611 = gen_rtx (ASM_INPUT, TYPE_MODE (TREE_TYPE (TREE_VALUE (tail))),
1612 TREE_STRING_POINTER (TREE_PURPOSE (tail)));
1616 /* Protect all the operands from the queue,
1617 now that they have all been evaluated. */
1619 for (i = 0; i < ninputs - ninout; i++)
1620 XVECEXP (body, 3, i) = protect_from_queue (XVECEXP (body, 3, i), 0);
1622 for (i = 0; i < noutputs; i++)
1623 output_rtx[i] = protect_from_queue (output_rtx[i], 1);
1625 /* For in-out operands, copy output rtx to input rtx. */
1626 for (i = 0; i < ninout; i++)
1628 static char match[9+1][2]
1629 = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
1630 int j = inout_opnum[i];
1632 XVECEXP (body, 3, ninputs - ninout + i) /* argvec */
1634 XVECEXP (body, 4, ninputs - ninout + i) /* constraints */
1635 = gen_rtx (ASM_INPUT, inout_mode[j], match[j]);
1638 /* Now, for each output, construct an rtx
1639 (set OUTPUT (asm_operands INSN OUTPUTNUMBER OUTPUTCONSTRAINT
1640 ARGVEC CONSTRAINTS))
1641 If there is more than one, put them inside a PARALLEL. */
1643 if (noutputs == 1 && nclobbers == 0)
1645 XSTR (body, 1) = TREE_STRING_POINTER (TREE_PURPOSE (outputs));
1646 insn = emit_insn (gen_rtx (SET, VOIDmode, output_rtx[0], body));
1648 else if (noutputs == 0 && nclobbers == 0)
1650 /* No output operands: put in a raw ASM_OPERANDS rtx. */
1651 insn = emit_insn (body);
1657 if (num == 0) num = 1;
1658 body = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (num + nclobbers));
1660 /* For each output operand, store a SET. */
1662 for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
1664 XVECEXP (body, 0, i)
1665 = gen_rtx (SET, VOIDmode,
1667 gen_rtx (ASM_OPERANDS, VOIDmode,
1668 TREE_STRING_POINTER (string),
1669 TREE_STRING_POINTER (TREE_PURPOSE (tail)),
1670 i, argvec, constraints,
1672 MEM_VOLATILE_P (SET_SRC (XVECEXP (body, 0, i))) = vol;
1675 /* If there are no outputs (but there are some clobbers)
1676 store the bare ASM_OPERANDS into the PARALLEL. */
1679 XVECEXP (body, 0, i++) = obody;
1681 /* Store (clobber REG) for each clobbered register specified. */
1683 for (tail = clobbers; tail; tail = TREE_CHAIN (tail))
1685 char *regname = TREE_STRING_POINTER (TREE_VALUE (tail));
1686 int j = decode_reg_name (regname);
1690 if (j == -3) /* `cc', which is not a register */
1693 if (j == -4) /* `memory', don't cache memory across asm */
1695 XVECEXP (body, 0, i++)
1696 = gen_rtx (CLOBBER, VOIDmode,
1697 gen_rtx (MEM, BLKmode,
1698 gen_rtx (SCRATCH, VOIDmode, 0)));
1702 /* Ignore unknown register, error already signalled. */
1706 /* Use QImode since that's guaranteed to clobber just one reg. */
1707 XVECEXP (body, 0, i++)
1708 = gen_rtx (CLOBBER, VOIDmode, gen_rtx (REG, QImode, j));
1711 insn = emit_insn (body);
1717 /* Generate RTL to evaluate the expression EXP
1718 and remember it in case this is the VALUE in a ({... VALUE; }) constr. */
1721 expand_expr_stmt (exp)
1724 if (output_bytecode)
1726 int org_stack_depth = stack_depth;
1728 bc_expand_expr (exp);
1730 /* Restore stack depth */
1731 if (stack_depth < org_stack_depth)
1734 bc_emit_instruction (drop);
1736 last_expr_type = TREE_TYPE (exp);
1740 /* If -W, warn about statements with no side effects,
1741 except for an explicit cast to void (e.g. for assert()), and
1742 except inside a ({...}) where they may be useful. */
1743 if (expr_stmts_for_value == 0 && exp != error_mark_node)
1745 if (! TREE_SIDE_EFFECTS (exp) && (extra_warnings || warn_unused)
1746 && !(TREE_CODE (exp) == CONVERT_EXPR
1747 && TREE_TYPE (exp) == void_type_node))
1748 warning_with_file_and_line (emit_filename, emit_lineno,
1749 "statement with no effect");
1750 else if (warn_unused)
1751 warn_if_unused_value (exp);
1754 /* If EXP is of function type and we are expanding statements for
1755 value, convert it to pointer-to-function. */
1756 if (expr_stmts_for_value && TREE_CODE (TREE_TYPE (exp)) == FUNCTION_TYPE)
1757 exp = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (exp)), exp);
1759 last_expr_type = TREE_TYPE (exp);
1760 if (! flag_syntax_only)
1761 last_expr_value = expand_expr (exp,
1762 (expr_stmts_for_value
1763 ? NULL_RTX : const0_rtx),
1766 /* If all we do is reference a volatile value in memory,
1767 copy it to a register to be sure it is actually touched. */
1768 if (last_expr_value != 0 && GET_CODE (last_expr_value) == MEM
1769 && TREE_THIS_VOLATILE (exp))
1771 if (TYPE_MODE (TREE_TYPE (exp)) == VOIDmode)
1773 else if (TYPE_MODE (TREE_TYPE (exp)) != BLKmode)
1774 copy_to_reg (last_expr_value);
1777 rtx lab = gen_label_rtx ();
1779 /* Compare the value with itself to reference it. */
1780 emit_cmp_insn (last_expr_value, last_expr_value, EQ,
1781 expand_expr (TYPE_SIZE (last_expr_type),
1782 NULL_RTX, VOIDmode, 0),
1784 TYPE_ALIGN (last_expr_type) / BITS_PER_UNIT);
1785 emit_jump_insn ((*bcc_gen_fctn[(int) EQ]) (lab));
1790 /* If this expression is part of a ({...}) and is in memory, we may have
1791 to preserve temporaries. */
1792 preserve_temp_slots (last_expr_value);
1794 /* Free any temporaries used to evaluate this expression. Any temporary
1795 used as a result of this expression will already have been preserved
1802 /* Warn if EXP contains any computations whose results are not used.
1803 Return 1 if a warning is printed; 0 otherwise. */
1806 warn_if_unused_value (exp)
1809 if (TREE_USED (exp))
1812 switch (TREE_CODE (exp))
1814 case PREINCREMENT_EXPR:
1815 case POSTINCREMENT_EXPR:
1816 case PREDECREMENT_EXPR:
1817 case POSTDECREMENT_EXPR:
1822 case METHOD_CALL_EXPR:
1824 case WITH_CLEANUP_EXPR:
1826 /* We don't warn about COND_EXPR because it may be a useful
1827 construct if either arm contains a side effect. */
1832 /* For a binding, warn if no side effect within it. */
1833 return warn_if_unused_value (TREE_OPERAND (exp, 1));
1836 return warn_if_unused_value (TREE_OPERAND (exp, 1));
1838 case TRUTH_ORIF_EXPR:
1839 case TRUTH_ANDIF_EXPR:
1840 /* In && or ||, warn if 2nd operand has no side effect. */
1841 return warn_if_unused_value (TREE_OPERAND (exp, 1));
1844 if (TREE_NO_UNUSED_WARNING (exp))
1846 if (warn_if_unused_value (TREE_OPERAND (exp, 0)))
1848 /* Let people do `(foo (), 0)' without a warning. */
1849 if (TREE_CONSTANT (TREE_OPERAND (exp, 1)))
1851 return warn_if_unused_value (TREE_OPERAND (exp, 1));
1855 case NON_LVALUE_EXPR:
1856 /* Don't warn about values cast to void. */
1857 if (TREE_TYPE (exp) == void_type_node)
1859 /* Don't warn about conversions not explicit in the user's program. */
1860 if (TREE_NO_UNUSED_WARNING (exp))
1862 /* Assignment to a cast usually results in a cast of a modify.
1863 Don't complain about that. There can be an arbitrary number of
1864 casts before the modify, so we must loop until we find the first
1865 non-cast expression and then test to see if that is a modify. */
1867 tree tem = TREE_OPERAND (exp, 0);
1869 while (TREE_CODE (tem) == CONVERT_EXPR || TREE_CODE (tem) == NOP_EXPR)
1870 tem = TREE_OPERAND (tem, 0);
1872 if (TREE_CODE (tem) == MODIFY_EXPR || TREE_CODE (tem) == INIT_EXPR
1873 || TREE_CODE (tem) == CALL_EXPR)
1879 /* Don't warn about automatic dereferencing of references, since
1880 the user cannot control it. */
1881 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == REFERENCE_TYPE)
1882 return warn_if_unused_value (TREE_OPERAND (exp, 0));
1883 /* ... fall through ... */
1886 /* Referencing a volatile value is a side effect, so don't warn. */
1887 if ((TREE_CODE_CLASS (TREE_CODE (exp)) == 'd'
1888 || TREE_CODE_CLASS (TREE_CODE (exp)) == 'r')
1889 && TREE_THIS_VOLATILE (exp))
1892 warning_with_file_and_line (emit_filename, emit_lineno,
1893 "value computed is not used");
1898 /* Clear out the memory of the last expression evaluated. */
1906 /* Begin a statement which will return a value.
1907 Return the RTL_EXPR for this statement expr.
1908 The caller must save that value and pass it to expand_end_stmt_expr. */
1911 expand_start_stmt_expr ()
1916 /* When generating bytecode just note down the stack depth */
1917 if (output_bytecode)
1918 return (build_int_2 (stack_depth, 0));
1920 /* Make the RTL_EXPR node temporary, not momentary,
1921 so that rtl_expr_chain doesn't become garbage. */
1922 momentary = suspend_momentary ();
1923 t = make_node (RTL_EXPR);
1924 resume_momentary (momentary);
1925 do_pending_stack_adjust ();
1926 start_sequence_for_rtl_expr (t);
1928 expr_stmts_for_value++;
1932 /* Restore the previous state at the end of a statement that returns a value.
1933 Returns a tree node representing the statement's value and the
1934 insns to compute the value.
1936 The nodes of that expression have been freed by now, so we cannot use them.
1937 But we don't want to do that anyway; the expression has already been
1938 evaluated and now we just want to use the value. So generate a RTL_EXPR
1939 with the proper type and RTL value.
1941 If the last substatement was not an expression,
1942 return something with type `void'. */
1945 expand_end_stmt_expr (t)
1948 if (output_bytecode)
1954 /* At this point, all expressions have been evaluated in order.
1955 However, all expression values have been popped when evaluated,
1956 which means we have to recover the last expression value. This is
1957 the last value removed by means of a `drop' instruction. Instead
1958 of adding code to inhibit dropping the last expression value, it
1959 is here recovered by undoing the `drop'. Since `drop' is
1960 equivalent to `adjustackSI [1]', it can be undone with `adjstackSI
1963 bc_adjust_stack (-1);
1965 if (!last_expr_type)
1966 last_expr_type = void_type_node;
1968 t = make_node (RTL_EXPR);
1969 TREE_TYPE (t) = last_expr_type;
1970 RTL_EXPR_RTL (t) = NULL;
1971 RTL_EXPR_SEQUENCE (t) = NULL;
1973 /* Don't consider deleting this expr or containing exprs at tree level. */
1974 TREE_THIS_VOLATILE (t) = 1;
1982 if (last_expr_type == 0)
1984 last_expr_type = void_type_node;
1985 last_expr_value = const0_rtx;
1987 else if (last_expr_value == 0)
1988 /* There are some cases where this can happen, such as when the
1989 statement is void type. */
1990 last_expr_value = const0_rtx;
1991 else if (GET_CODE (last_expr_value) != REG && ! CONSTANT_P (last_expr_value))
1992 /* Remove any possible QUEUED. */
1993 last_expr_value = protect_from_queue (last_expr_value, 0);
1997 TREE_TYPE (t) = last_expr_type;
1998 RTL_EXPR_RTL (t) = last_expr_value;
1999 RTL_EXPR_SEQUENCE (t) = get_insns ();
2001 rtl_expr_chain = tree_cons (NULL_TREE, t, rtl_expr_chain);
2005 /* Don't consider deleting this expr or containing exprs at tree level. */
2006 TREE_SIDE_EFFECTS (t) = 1;
2007 /* Propagate volatility of the actual RTL expr. */
2008 TREE_THIS_VOLATILE (t) = volatile_refs_p (last_expr_value);
2011 expr_stmts_for_value--;
2016 /* Generate RTL for the start of an if-then. COND is the expression
2017 whose truth should be tested.
2019 If EXITFLAG is nonzero, this conditional is visible to
2020 `exit_something'. */
2023 expand_start_cond (cond, exitflag)
2027 struct nesting *thiscond = ALLOC_NESTING ();
2029 /* Make an entry on cond_stack for the cond we are entering. */
2031 thiscond->next = cond_stack;
2032 thiscond->all = nesting_stack;
2033 thiscond->depth = ++nesting_depth;
2034 thiscond->data.cond.next_label = gen_label_rtx ();
2035 /* Before we encounter an `else', we don't need a separate exit label
2036 unless there are supposed to be exit statements
2037 to exit this conditional. */
2038 thiscond->exit_label = exitflag ? gen_label_rtx () : 0;
2039 thiscond->data.cond.endif_label = thiscond->exit_label;
2040 cond_stack = thiscond;
2041 nesting_stack = thiscond;
2043 if (output_bytecode)
2044 bc_expand_start_cond (cond, exitflag);
2046 do_jump (cond, thiscond->data.cond.next_label, NULL_RTX);
2049 /* Generate RTL between then-clause and the elseif-clause
2050 of an if-then-elseif-.... */
2053 expand_start_elseif (cond)
2056 if (cond_stack->data.cond.endif_label == 0)
2057 cond_stack->data.cond.endif_label = gen_label_rtx ();
2058 emit_jump (cond_stack->data.cond.endif_label);
2059 emit_label (cond_stack->data.cond.next_label);
2060 cond_stack->data.cond.next_label = gen_label_rtx ();
2061 do_jump (cond, cond_stack->data.cond.next_label, NULL_RTX);
2064 /* Generate RTL between the then-clause and the else-clause
2065 of an if-then-else. */
2068 expand_start_else ()
2070 if (cond_stack->data.cond.endif_label == 0)
2071 cond_stack->data.cond.endif_label = gen_label_rtx ();
2073 if (output_bytecode)
2075 bc_expand_start_else ();
2079 emit_jump (cond_stack->data.cond.endif_label);
2080 emit_label (cond_stack->data.cond.next_label);
2081 cond_stack->data.cond.next_label = 0; /* No more _else or _elseif calls. */
2084 /* After calling expand_start_else, turn this "else" into an "else if"
2085 by providing another condition. */
2088 expand_elseif (cond)
2091 cond_stack->data.cond.next_label = gen_label_rtx ();
2092 do_jump (cond, cond_stack->data.cond.next_label, NULL_RTX);
2095 /* Generate RTL for the end of an if-then.
2096 Pop the record for it off of cond_stack. */
2101 struct nesting *thiscond = cond_stack;
2103 if (output_bytecode)
2104 bc_expand_end_cond ();
2107 do_pending_stack_adjust ();
2108 if (thiscond->data.cond.next_label)
2109 emit_label (thiscond->data.cond.next_label);
2110 if (thiscond->data.cond.endif_label)
2111 emit_label (thiscond->data.cond.endif_label);
2114 POPSTACK (cond_stack);
2119 /* Generate code for the start of an if-then. COND is the expression
2120 whose truth is to be tested; if EXITFLAG is nonzero this conditional
2121 is to be visible to exit_something. It is assumed that the caller
2122 has pushed the previous context on the cond stack. */
2125 bc_expand_start_cond (cond, exitflag)
2129 struct nesting *thiscond = cond_stack;
2131 thiscond->data.case_stmt.nominal_type = cond;
2133 thiscond->exit_label = gen_label_rtx ();
2134 bc_expand_expr (cond);
2135 bc_emit_bytecode (xjumpifnot);
2136 bc_emit_bytecode_labelref (BYTECODE_BC_LABEL (thiscond->exit_label));
2138 #ifdef DEBUG_PRINT_CODE
2139 fputc ('\n', stderr);
2143 /* Generate the label for the end of an if with
2147 bc_expand_end_cond ()
2149 struct nesting *thiscond = cond_stack;
2151 bc_emit_bytecode_labeldef (BYTECODE_BC_LABEL (thiscond->exit_label));
2154 /* Generate code for the start of the else- clause of
2158 bc_expand_start_else ()
2160 struct nesting *thiscond = cond_stack;
2162 thiscond->data.cond.endif_label = thiscond->exit_label;
2163 thiscond->exit_label = gen_label_rtx ();
2164 bc_emit_bytecode (jump);
2165 bc_emit_bytecode_labelref (BYTECODE_BC_LABEL (thiscond->exit_label));
2167 #ifdef DEBUG_PRINT_CODE
2168 fputc ('\n', stderr);
2171 bc_emit_bytecode_labeldef (BYTECODE_BC_LABEL (thiscond->data.cond.endif_label));
2174 /* Generate RTL for the start of a loop. EXIT_FLAG is nonzero if this
2175 loop should be exited by `exit_something'. This is a loop for which
2176 `expand_continue' will jump to the top of the loop.
2178 Make an entry on loop_stack to record the labels associated with
2182 expand_start_loop (exit_flag)
2185 register struct nesting *thisloop = ALLOC_NESTING ();
2187 /* Make an entry on loop_stack for the loop we are entering. */
2189 thisloop->next = loop_stack;
2190 thisloop->all = nesting_stack;
2191 thisloop->depth = ++nesting_depth;
2192 thisloop->data.loop.start_label = gen_label_rtx ();
2193 thisloop->data.loop.end_label = gen_label_rtx ();
2194 thisloop->data.loop.alt_end_label = 0;
2195 thisloop->data.loop.continue_label = thisloop->data.loop.start_label;
2196 thisloop->exit_label = exit_flag ? thisloop->data.loop.end_label : 0;
2197 loop_stack = thisloop;
2198 nesting_stack = thisloop;
2200 if (output_bytecode)
2202 bc_emit_bytecode_labeldef (BYTECODE_BC_LABEL (thisloop->data.loop.start_label));
2206 do_pending_stack_adjust ();
2208 emit_note (NULL_PTR, NOTE_INSN_LOOP_BEG);
2209 emit_label (thisloop->data.loop.start_label);
2214 /* Like expand_start_loop but for a loop where the continuation point
2215 (for expand_continue_loop) will be specified explicitly. */
2218 expand_start_loop_continue_elsewhere (exit_flag)
2221 struct nesting *thisloop = expand_start_loop (exit_flag);
2222 loop_stack->data.loop.continue_label = gen_label_rtx ();
2226 /* Specify the continuation point for a loop started with
2227 expand_start_loop_continue_elsewhere.
2228 Use this at the point in the code to which a continue statement
2232 expand_loop_continue_here ()
2234 if (output_bytecode)
2236 bc_emit_bytecode_labeldef (BYTECODE_BC_LABEL (loop_stack->data.loop.continue_label));
2239 do_pending_stack_adjust ();
2240 emit_note (NULL_PTR, NOTE_INSN_LOOP_CONT);
2241 emit_label (loop_stack->data.loop.continue_label);
2247 bc_expand_end_loop ()
2249 struct nesting *thisloop = loop_stack;
2251 bc_emit_bytecode (jump);
2252 bc_emit_bytecode_labelref (BYTECODE_BC_LABEL (thisloop->data.loop.start_label));
2254 #ifdef DEBUG_PRINT_CODE
2255 fputc ('\n', stderr);
2258 bc_emit_bytecode_labeldef (BYTECODE_BC_LABEL (thisloop->exit_label));
2259 POPSTACK (loop_stack);
2264 /* Finish a loop. Generate a jump back to the top and the loop-exit label.
2265 Pop the block off of loop_stack. */
2271 register rtx start_label;
2272 rtx last_test_insn = 0;
2275 if (output_bytecode)
2277 bc_expand_end_loop ();
2281 insn = get_last_insn ();
2282 start_label = loop_stack->data.loop.start_label;
2284 /* Mark the continue-point at the top of the loop if none elsewhere. */
2285 if (start_label == loop_stack->data.loop.continue_label)
2286 emit_note_before (NOTE_INSN_LOOP_CONT, start_label);
2288 do_pending_stack_adjust ();
2290 /* If optimizing, perhaps reorder the loop. If the loop
2291 starts with a conditional exit, roll that to the end
2292 where it will optimize together with the jump back.
2294 We look for the last conditional branch to the exit that we encounter
2295 before hitting 30 insns or a CALL_INSN. If we see an unconditional
2296 branch to the exit first, use it.
2298 We must also stop at NOTE_INSN_BLOCK_BEG and NOTE_INSN_BLOCK_END notes
2299 because moving them is not valid. */
2303 ! (GET_CODE (insn) == JUMP_INSN
2304 && GET_CODE (PATTERN (insn)) == SET
2305 && SET_DEST (PATTERN (insn)) == pc_rtx
2306 && GET_CODE (SET_SRC (PATTERN (insn))) == IF_THEN_ELSE))
2308 /* Scan insns from the top of the loop looking for a qualified
2309 conditional exit. */
2310 for (insn = NEXT_INSN (loop_stack->data.loop.start_label); insn;
2311 insn = NEXT_INSN (insn))
2313 if (GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == CODE_LABEL)
2316 if (GET_CODE (insn) == NOTE
2317 && (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG
2318 || NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END))
2321 if (GET_CODE (insn) == JUMP_INSN || GET_CODE (insn) == INSN)
2324 if (last_test_insn && num_insns > 30)
2327 if (GET_CODE (insn) == JUMP_INSN && GET_CODE (PATTERN (insn)) == SET
2328 && SET_DEST (PATTERN (insn)) == pc_rtx
2329 && GET_CODE (SET_SRC (PATTERN (insn))) == IF_THEN_ELSE
2330 && ((GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 1)) == LABEL_REF
2331 && ((XEXP (XEXP (SET_SRC (PATTERN (insn)), 1), 0)
2332 == loop_stack->data.loop.end_label)
2333 || (XEXP (XEXP (SET_SRC (PATTERN (insn)), 1), 0)
2334 == loop_stack->data.loop.alt_end_label)))
2335 || (GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 2)) == LABEL_REF
2336 && ((XEXP (XEXP (SET_SRC (PATTERN (insn)), 2), 0)
2337 == loop_stack->data.loop.end_label)
2338 || (XEXP (XEXP (SET_SRC (PATTERN (insn)), 2), 0)
2339 == loop_stack->data.loop.alt_end_label)))))
2340 last_test_insn = insn;
2342 if (last_test_insn == 0 && GET_CODE (insn) == JUMP_INSN
2343 && GET_CODE (PATTERN (insn)) == SET
2344 && SET_DEST (PATTERN (insn)) == pc_rtx
2345 && GET_CODE (SET_SRC (PATTERN (insn))) == LABEL_REF
2346 && ((XEXP (SET_SRC (PATTERN (insn)), 0)
2347 == loop_stack->data.loop.end_label)
2348 || (XEXP (SET_SRC (PATTERN (insn)), 0)
2349 == loop_stack->data.loop.alt_end_label)))
2350 /* Include BARRIER. */
2351 last_test_insn = NEXT_INSN (insn);
2354 if (last_test_insn != 0 && last_test_insn != get_last_insn ())
2356 /* We found one. Move everything from there up
2357 to the end of the loop, and add a jump into the loop
2358 to jump to there. */
2359 register rtx newstart_label = gen_label_rtx ();
2360 register rtx start_move = start_label;
2362 /* If the start label is preceded by a NOTE_INSN_LOOP_CONT note,
2363 then we want to move this note also. */
2364 if (GET_CODE (PREV_INSN (start_move)) == NOTE
2365 && (NOTE_LINE_NUMBER (PREV_INSN (start_move))
2366 == NOTE_INSN_LOOP_CONT))
2367 start_move = PREV_INSN (start_move);
2369 emit_label_after (newstart_label, PREV_INSN (start_move));
2370 reorder_insns (start_move, last_test_insn, get_last_insn ());
2371 emit_jump_insn_after (gen_jump (start_label),
2372 PREV_INSN (newstart_label));
2373 emit_barrier_after (PREV_INSN (newstart_label));
2374 start_label = newstart_label;
2378 emit_jump (start_label);
2379 emit_note (NULL_PTR, NOTE_INSN_LOOP_END);
2380 emit_label (loop_stack->data.loop.end_label);
2382 POPSTACK (loop_stack);
2387 /* Generate a jump to the current loop's continue-point.
2388 This is usually the top of the loop, but may be specified
2389 explicitly elsewhere. If not currently inside a loop,
2390 return 0 and do nothing; caller will print an error message. */
2393 expand_continue_loop (whichloop)
2394 struct nesting *whichloop;
2398 whichloop = loop_stack;
2401 expand_goto_internal (NULL_TREE, whichloop->data.loop.continue_label,
2406 /* Generate a jump to exit the current loop. If not currently inside a loop,
2407 return 0 and do nothing; caller will print an error message. */
2410 expand_exit_loop (whichloop)
2411 struct nesting *whichloop;
2415 whichloop = loop_stack;
2418 expand_goto_internal (NULL_TREE, whichloop->data.loop.end_label, NULL_RTX);
2422 /* Generate a conditional jump to exit the current loop if COND
2423 evaluates to zero. If not currently inside a loop,
2424 return 0 and do nothing; caller will print an error message. */
2427 expand_exit_loop_if_false (whichloop, cond)
2428 struct nesting *whichloop;
2433 whichloop = loop_stack;
2436 if (output_bytecode)
2438 bc_expand_expr (cond);
2439 bc_expand_goto_internal (xjumpifnot,
2440 BYTECODE_BC_LABEL (whichloop->exit_label),
2445 /* In order to handle fixups, we actually create a conditional jump
2446 around a unconditional branch to exit the loop. If fixups are
2447 necessary, they go before the unconditional branch. */
2449 rtx label = gen_label_rtx ();
2452 do_jump (cond, NULL_RTX, label);
2453 last_insn = get_last_insn ();
2454 if (GET_CODE (last_insn) == CODE_LABEL)
2455 whichloop->data.loop.alt_end_label = last_insn;
2456 expand_goto_internal (NULL_TREE, whichloop->data.loop.end_label,
2464 /* Return non-zero if we should preserve sub-expressions as separate
2465 pseudos. We never do so if we aren't optimizing. We always do so
2466 if -fexpensive-optimizations.
2468 Otherwise, we only do so if we are in the "early" part of a loop. I.e.,
2469 the loop may still be a small one. */
2472 preserve_subexpressions_p ()
2476 if (flag_expensive_optimizations)
2479 if (optimize == 0 || loop_stack == 0)
2482 insn = get_last_insn_anywhere ();
2485 && (INSN_UID (insn) - INSN_UID (loop_stack->data.loop.start_label)
2486 < n_non_fixed_regs * 3));
2490 /* Generate a jump to exit the current loop, conditional, binding contour
2491 or case statement. Not all such constructs are visible to this function,
2492 only those started with EXIT_FLAG nonzero. Individual languages use
2493 the EXIT_FLAG parameter to control which kinds of constructs you can
2496 If not currently inside anything that can be exited,
2497 return 0 and do nothing; caller will print an error message. */
2500 expand_exit_something ()
2504 for (n = nesting_stack; n; n = n->all)
2505 if (n->exit_label != 0)
2507 expand_goto_internal (NULL_TREE, n->exit_label, NULL_RTX);
2514 /* Generate RTL to return from the current function, with no value.
2515 (That is, we do not do anything about returning any value.) */
2518 expand_null_return ()
2520 struct nesting *block = block_stack;
2523 if (output_bytecode)
2525 bc_emit_instruction (ret);
2529 /* Does any pending block have cleanups? */
2531 while (block && block->data.block.cleanups == 0)
2532 block = block->next;
2534 /* If yes, use a goto to return, since that runs cleanups. */
2536 expand_null_return_1 (last_insn, block != 0);
2539 /* Generate RTL to return from the current function, with value VAL. */
2542 expand_value_return (val)
2545 struct nesting *block = block_stack;
2546 rtx last_insn = get_last_insn ();
2547 rtx return_reg = DECL_RTL (DECL_RESULT (current_function_decl));
2549 /* Copy the value to the return location
2550 unless it's already there. */
2552 if (return_reg != val)
2554 #ifdef PROMOTE_FUNCTION_RETURN
2555 tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
2556 int unsignedp = TREE_UNSIGNED (type);
2557 enum machine_mode mode
2558 = promote_mode (type, DECL_MODE (DECL_RESULT (current_function_decl)),
2561 if (GET_MODE (val) != VOIDmode && GET_MODE (val) != mode)
2562 convert_move (return_reg, val, unsignedp);
2565 emit_move_insn (return_reg, val);
2567 if (GET_CODE (return_reg) == REG
2568 && REGNO (return_reg) < FIRST_PSEUDO_REGISTER)
2569 emit_insn (gen_rtx (USE, VOIDmode, return_reg));
2570 /* Handle calls that return values in multiple non-contiguous locations.
2571 The Irix 6 ABI has examples of this. */
2572 else if (GET_CODE (return_reg) == PARALLEL)
2576 for (i = 0; i < XVECLEN (return_reg, 0); i++)
2578 rtx x = XEXP (XVECEXP (return_reg, 0, i), 0);
2580 if (GET_CODE (x) == REG
2581 && REGNO (x) < FIRST_PSEUDO_REGISTER)
2582 emit_insn (gen_rtx (USE, VOIDmode, x));
2586 /* Does any pending block have cleanups? */
2588 while (block && block->data.block.cleanups == 0)
2589 block = block->next;
2591 /* If yes, use a goto to return, since that runs cleanups.
2592 Use LAST_INSN to put cleanups *before* the move insn emitted above. */
2594 expand_null_return_1 (last_insn, block != 0);
2597 /* Output a return with no value. If LAST_INSN is nonzero,
2598 pretend that the return takes place after LAST_INSN.
2599 If USE_GOTO is nonzero then don't use a return instruction;
2600 go to the return label instead. This causes any cleanups
2601 of pending blocks to be executed normally. */
2604 expand_null_return_1 (last_insn, use_goto)
2608 rtx end_label = cleanup_label ? cleanup_label : return_label;
2610 clear_pending_stack_adjust ();
2611 do_pending_stack_adjust ();
2614 /* PCC-struct return always uses an epilogue. */
2615 if (current_function_returns_pcc_struct || use_goto)
2618 end_label = return_label = gen_label_rtx ();
2619 expand_goto_internal (NULL_TREE, end_label, last_insn);
2623 /* Otherwise output a simple return-insn if one is available,
2624 unless it won't do the job. */
2626 if (HAVE_return && use_goto == 0 && cleanup_label == 0)
2628 emit_jump_insn (gen_return ());
2634 /* Otherwise jump to the epilogue. */
2635 expand_goto_internal (NULL_TREE, end_label, last_insn);
2638 /* Generate RTL to evaluate the expression RETVAL and return it
2639 from the current function. */
2642 expand_return (retval)
2645 /* If there are any cleanups to be performed, then they will
2646 be inserted following LAST_INSN. It is desirable
2647 that the last_insn, for such purposes, should be the
2648 last insn before computing the return value. Otherwise, cleanups
2649 which call functions can clobber the return value. */
2650 /* ??? rms: I think that is erroneous, because in C++ it would
2651 run destructors on variables that might be used in the subsequent
2652 computation of the return value. */
2654 register rtx val = 0;
2658 struct nesting *block;
2660 /* Bytecode returns are quite simple, just leave the result on the
2661 arithmetic stack. */
2662 if (output_bytecode)
2664 bc_expand_expr (retval);
2665 bc_emit_instruction (ret);
2669 /* If function wants no value, give it none. */
2670 if (TREE_CODE (TREE_TYPE (TREE_TYPE (current_function_decl))) == VOID_TYPE)
2672 expand_expr (retval, NULL_RTX, VOIDmode, 0);
2674 expand_null_return ();
2678 /* Are any cleanups needed? E.g. C++ destructors to be run? */
2679 /* This is not sufficient. We also need to watch for cleanups of the
2680 expression we are about to expand. Unfortunately, we cannot know
2681 if it has cleanups until we expand it, and we want to change how we
2682 expand it depending upon if we need cleanups. We can't win. */
2684 cleanups = any_pending_cleanups (1);
2689 if (TREE_CODE (retval) == RESULT_DECL)
2690 retval_rhs = retval;
2691 else if ((TREE_CODE (retval) == MODIFY_EXPR || TREE_CODE (retval) == INIT_EXPR)
2692 && TREE_CODE (TREE_OPERAND (retval, 0)) == RESULT_DECL)
2693 retval_rhs = TREE_OPERAND (retval, 1);
2694 else if (TREE_TYPE (retval) == void_type_node)
2695 /* Recognize tail-recursive call to void function. */
2696 retval_rhs = retval;
2698 retval_rhs = NULL_TREE;
2700 /* Only use `last_insn' if there are cleanups which must be run. */
2701 if (cleanups || cleanup_label != 0)
2702 last_insn = get_last_insn ();
2704 /* Distribute return down conditional expr if either of the sides
2705 may involve tail recursion (see test below). This enhances the number
2706 of tail recursions we see. Don't do this always since it can produce
2707 sub-optimal code in some cases and we distribute assignments into
2708 conditional expressions when it would help. */
2710 if (optimize && retval_rhs != 0
2711 && frame_offset == 0
2712 && TREE_CODE (retval_rhs) == COND_EXPR
2713 && (TREE_CODE (TREE_OPERAND (retval_rhs, 1)) == CALL_EXPR
2714 || TREE_CODE (TREE_OPERAND (retval_rhs, 2)) == CALL_EXPR))
2716 rtx label = gen_label_rtx ();
2719 do_jump (TREE_OPERAND (retval_rhs, 0), label, NULL_RTX);
2720 expr = build (MODIFY_EXPR, TREE_TYPE (current_function_decl),
2721 DECL_RESULT (current_function_decl),
2722 TREE_OPERAND (retval_rhs, 1));
2723 TREE_SIDE_EFFECTS (expr) = 1;
2724 expand_return (expr);
2727 expr = build (MODIFY_EXPR, TREE_TYPE (current_function_decl),
2728 DECL_RESULT (current_function_decl),
2729 TREE_OPERAND (retval_rhs, 2));
2730 TREE_SIDE_EFFECTS (expr) = 1;
2731 expand_return (expr);
2735 /* For tail-recursive call to current function,
2736 just jump back to the beginning.
2737 It's unsafe if any auto variable in this function
2738 has its address taken; for simplicity,
2739 require stack frame to be empty. */
2740 if (optimize && retval_rhs != 0
2741 && frame_offset == 0
2742 && TREE_CODE (retval_rhs) == CALL_EXPR
2743 && TREE_CODE (TREE_OPERAND (retval_rhs, 0)) == ADDR_EXPR
2744 && TREE_OPERAND (TREE_OPERAND (retval_rhs, 0), 0) == current_function_decl
2745 /* Finish checking validity, and if valid emit code
2746 to set the argument variables for the new call. */
2747 && tail_recursion_args (TREE_OPERAND (retval_rhs, 1),
2748 DECL_ARGUMENTS (current_function_decl)))
2750 if (tail_recursion_label == 0)
2752 tail_recursion_label = gen_label_rtx ();
2753 emit_label_after (tail_recursion_label,
2754 tail_recursion_reentry);
2757 expand_goto_internal (NULL_TREE, tail_recursion_label, last_insn);
2762 /* This optimization is safe if there are local cleanups
2763 because expand_null_return takes care of them.
2764 ??? I think it should also be safe when there is a cleanup label,
2765 because expand_null_return takes care of them, too.
2766 Any reason why not? */
2767 if (HAVE_return && cleanup_label == 0
2768 && ! current_function_returns_pcc_struct
2769 && BRANCH_COST <= 1)
2771 /* If this is return x == y; then generate
2772 if (x == y) return 1; else return 0;
2773 if we can do it with explicit return insns and branches are cheap,
2774 but not if we have the corresponding scc insn. */
2777 switch (TREE_CODE (retval_rhs))
2803 case TRUTH_ANDIF_EXPR:
2804 case TRUTH_ORIF_EXPR:
2805 case TRUTH_AND_EXPR:
2807 case TRUTH_NOT_EXPR:
2808 case TRUTH_XOR_EXPR:
2811 op0 = gen_label_rtx ();
2812 jumpifnot (retval_rhs, op0);
2813 expand_value_return (const1_rtx);
2815 expand_value_return (const0_rtx);
2820 #endif /* HAVE_return */
2822 /* If the result is an aggregate that is being returned in one (or more)
2823 registers, load the registers here. The compiler currently can't handle
2824 copying a BLKmode value into registers. We could put this code in a
2825 more general area (for use by everyone instead of just function
2826 call/return), but until this feature is generally usable it is kept here
2827 (and in expand_call). The value must go into a pseudo in case there
2828 are cleanups that will clobber the real return register. */
2831 && TYPE_MODE (TREE_TYPE (retval_rhs)) == BLKmode
2832 && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG)
2834 int i, bitpos, xbitpos;
2835 int big_endian_correction = 0;
2836 int bytes = int_size_in_bytes (TREE_TYPE (retval_rhs));
2837 int n_regs = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
2838 int bitsize = MIN (TYPE_ALIGN (TREE_TYPE (retval_rhs)),BITS_PER_WORD);
2839 rtx *result_pseudos = (rtx *) alloca (sizeof (rtx) * n_regs);
2840 rtx result_reg, src, dst;
2841 rtx result_val = expand_expr (retval_rhs, NULL_RTX, VOIDmode, 0);
2842 enum machine_mode tmpmode, result_reg_mode;
2844 /* Structures whose size is not a multiple of a word are aligned
2845 to the least significant byte (to the right). On a BYTES_BIG_ENDIAN
2846 machine, this means we must skip the empty high order bytes when
2847 calculating the bit offset. */
2848 if (BYTES_BIG_ENDIAN && bytes % UNITS_PER_WORD)
2849 big_endian_correction = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD)
2852 /* Copy the structure BITSIZE bits at a time. */
2853 for (bitpos = 0, xbitpos = big_endian_correction;
2854 bitpos < bytes * BITS_PER_UNIT;
2855 bitpos += bitsize, xbitpos += bitsize)
2857 /* We need a new destination pseudo each time xbitpos is
2858 on a word boundary and when xbitpos == big_endian_correction
2859 (the first time through). */
2860 if (xbitpos % BITS_PER_WORD == 0
2861 || xbitpos == big_endian_correction)
2863 /* Generate an appropriate register. */
2864 dst = gen_reg_rtx (word_mode);
2865 result_pseudos[xbitpos / BITS_PER_WORD] = dst;
2867 /* Clobber the destination before we move anything into it. */
2868 emit_insn (gen_rtx (CLOBBER, VOIDmode, dst));
2871 /* We need a new source operand each time bitpos is on a word
2873 if (bitpos % BITS_PER_WORD == 0)
2874 src = operand_subword_force (result_val,
2875 bitpos / BITS_PER_WORD,
2878 /* Use bitpos for the source extraction (left justified) and
2879 xbitpos for the destination store (right justified). */
2880 store_bit_field (dst, bitsize, xbitpos % BITS_PER_WORD, word_mode,
2881 extract_bit_field (src, bitsize,
2882 bitpos % BITS_PER_WORD, 1,
2883 NULL_RTX, word_mode,
2885 bitsize / BITS_PER_UNIT,
2887 bitsize / BITS_PER_UNIT, BITS_PER_WORD);
2890 /* Find the smallest integer mode large enough to hold the
2891 entire structure and use that mode instead of BLKmode
2892 on the USE insn for the return register. */
2893 bytes = int_size_in_bytes (TREE_TYPE (retval_rhs));
2894 for (tmpmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
2895 tmpmode != MAX_MACHINE_MODE;
2896 tmpmode = GET_MODE_WIDER_MODE (tmpmode))
2898 /* Have we found a large enough mode? */
2899 if (GET_MODE_SIZE (tmpmode) >= bytes)
2903 /* No suitable mode found. */
2904 if (tmpmode == MAX_MACHINE_MODE)
2907 PUT_MODE (DECL_RTL (DECL_RESULT (current_function_decl)), tmpmode);
2909 if (GET_MODE_SIZE (tmpmode) < GET_MODE_SIZE (word_mode))
2910 result_reg_mode = word_mode;
2912 result_reg_mode = tmpmode;
2913 result_reg = gen_reg_rtx (result_reg_mode);
2915 /* Now that the value is in pseudos, copy it to the result reg(s). */
2918 for (i = 0; i < n_regs; i++)
2919 emit_move_insn (operand_subword (result_reg, i, 0, result_reg_mode),
2922 if (tmpmode != result_reg_mode)
2923 result_reg = gen_lowpart (tmpmode, result_reg);
2925 expand_value_return (result_reg);
2929 && TREE_TYPE (retval_rhs) != void_type_node
2930 && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG)
2932 /* Calculate the return value into a pseudo reg. */
2933 val = expand_expr (retval_rhs, NULL_RTX, VOIDmode, 0);
2935 /* All temporaries have now been used. */
2937 /* Return the calculated value, doing cleanups first. */
2938 expand_value_return (val);
2942 /* No cleanups or no hard reg used;
2943 calculate value into hard return reg. */
2944 expand_expr (retval, const0_rtx, VOIDmode, 0);
2947 expand_value_return (DECL_RTL (DECL_RESULT (current_function_decl)));
2951 /* Return 1 if the end of the generated RTX is not a barrier.
2952 This means code already compiled can drop through. */
2955 drop_through_at_end_p ()
2957 rtx insn = get_last_insn ();
2958 while (insn && GET_CODE (insn) == NOTE)
2959 insn = PREV_INSN (insn);
2960 return insn && GET_CODE (insn) != BARRIER;
2963 /* Emit code to alter this function's formal parms for a tail-recursive call.
2964 ACTUALS is a list of actual parameter expressions (chain of TREE_LISTs).
2965 FORMALS is the chain of decls of formals.
2966 Return 1 if this can be done;
2967 otherwise return 0 and do not emit any code. */
2970 tail_recursion_args (actuals, formals)
2971 tree actuals, formals;
2973 register tree a = actuals, f = formals;
2975 register rtx *argvec;
2977 /* Check that number and types of actuals are compatible
2978 with the formals. This is not always true in valid C code.
2979 Also check that no formal needs to be addressable
2980 and that all formals are scalars. */
2982 /* Also count the args. */
2984 for (a = actuals, f = formals, i = 0; a && f; a = TREE_CHAIN (a), f = TREE_CHAIN (f), i++)
2986 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (a)))
2987 != TYPE_MAIN_VARIANT (TREE_TYPE (f)))
2989 if (GET_CODE (DECL_RTL (f)) != REG || DECL_MODE (f) == BLKmode)
2992 if (a != 0 || f != 0)
2995 /* Compute all the actuals. */
2997 argvec = (rtx *) alloca (i * sizeof (rtx));
2999 for (a = actuals, i = 0; a; a = TREE_CHAIN (a), i++)
3000 argvec[i] = expand_expr (TREE_VALUE (a), NULL_RTX, VOIDmode, 0);
3002 /* Find which actual values refer to current values of previous formals.
3003 Copy each of them now, before any formal is changed. */
3005 for (a = actuals, i = 0; a; a = TREE_CHAIN (a), i++)
3009 for (f = formals, j = 0; j < i; f = TREE_CHAIN (f), j++)
3010 if (reg_mentioned_p (DECL_RTL (f), argvec[i]))
3011 { copy = 1; break; }
3013 argvec[i] = copy_to_reg (argvec[i]);
3016 /* Store the values of the actuals into the formals. */
3018 for (f = formals, a = actuals, i = 0; f;
3019 f = TREE_CHAIN (f), a = TREE_CHAIN (a), i++)
3021 if (GET_MODE (DECL_RTL (f)) == GET_MODE (argvec[i]))
3022 emit_move_insn (DECL_RTL (f), argvec[i]);
3024 convert_move (DECL_RTL (f), argvec[i],
3025 TREE_UNSIGNED (TREE_TYPE (TREE_VALUE (a))));
3032 /* Generate the RTL code for entering a binding contour.
3033 The variables are declared one by one, by calls to `expand_decl'.
3035 EXIT_FLAG is nonzero if this construct should be visible to
3036 `exit_something'. */
3039 expand_start_bindings (exit_flag)
3042 struct nesting *thisblock = ALLOC_NESTING ();
3043 rtx note = output_bytecode ? 0 : emit_note (NULL_PTR, NOTE_INSN_BLOCK_BEG);
3045 /* Make an entry on block_stack for the block we are entering. */
3047 thisblock->next = block_stack;
3048 thisblock->all = nesting_stack;
3049 thisblock->depth = ++nesting_depth;
3050 thisblock->data.block.stack_level = 0;
3051 thisblock->data.block.cleanups = 0;
3052 thisblock->data.block.function_call_count = 0;
3056 if (block_stack->data.block.cleanups == NULL_TREE
3057 && (block_stack->data.block.outer_cleanups == NULL_TREE
3058 || block_stack->data.block.outer_cleanups == empty_cleanup_list))
3059 thisblock->data.block.outer_cleanups = empty_cleanup_list;
3061 thisblock->data.block.outer_cleanups
3062 = tree_cons (NULL_TREE, block_stack->data.block.cleanups,
3063 block_stack->data.block.outer_cleanups);
3066 thisblock->data.block.outer_cleanups = 0;
3070 && !(block_stack->data.block.cleanups == NULL_TREE
3071 && block_stack->data.block.outer_cleanups == NULL_TREE))
3072 thisblock->data.block.outer_cleanups
3073 = tree_cons (NULL_TREE, block_stack->data.block.cleanups,
3074 block_stack->data.block.outer_cleanups);
3076 thisblock->data.block.outer_cleanups = 0;
3078 thisblock->data.block.label_chain = 0;
3079 thisblock->data.block.innermost_stack_block = stack_block_stack;
3080 thisblock->data.block.first_insn = note;
3081 thisblock->data.block.block_start_count = ++block_start_count;
3082 thisblock->exit_label = exit_flag ? gen_label_rtx () : 0;
3083 block_stack = thisblock;
3084 nesting_stack = thisblock;
3086 if (!output_bytecode)
3088 /* Make a new level for allocating stack slots. */
3093 /* Given a pointer to a BLOCK node, save a pointer to the most recently
3094 generated NOTE_INSN_BLOCK_END in the BLOCK_END_NOTE field of the given
3098 remember_end_note (block)
3099 register tree block;
3101 BLOCK_END_NOTE (block) = last_block_end_note;
3102 last_block_end_note = NULL_RTX;
3105 /* Generate RTL code to terminate a binding contour.
3106 VARS is the chain of VAR_DECL nodes
3107 for the variables bound in this contour.
3108 MARK_ENDS is nonzero if we should put a note at the beginning
3109 and end of this binding contour.
3111 DONT_JUMP_IN is nonzero if it is not valid to jump into this contour.
3112 (That is true automatically if the contour has a saved stack level.) */
3115 expand_end_bindings (vars, mark_ends, dont_jump_in)
3120 register struct nesting *thisblock = block_stack;
3123 if (output_bytecode)
3125 bc_expand_end_bindings (vars, mark_ends, dont_jump_in);
3130 for (decl = vars; decl; decl = TREE_CHAIN (decl))
3131 if (! TREE_USED (decl) && TREE_CODE (decl) == VAR_DECL
3132 && ! DECL_IN_SYSTEM_HEADER (decl))
3133 warning_with_decl (decl, "unused variable `%s'");
3135 if (thisblock->exit_label)
3137 do_pending_stack_adjust ();
3138 emit_label (thisblock->exit_label);
3141 /* If necessary, make a handler for nonlocal gotos taking
3142 place in the function calls in this block. */
3143 if (function_call_count != thisblock->data.block.function_call_count
3145 /* Make handler for outermost block
3146 if there were any nonlocal gotos to this function. */
3147 && (thisblock->next == 0 ? current_function_has_nonlocal_label
3148 /* Make handler for inner block if it has something
3149 special to do when you jump out of it. */
3150 : (thisblock->data.block.cleanups != 0
3151 || thisblock->data.block.stack_level != 0)))
3154 rtx afterward = gen_label_rtx ();
3155 rtx handler_label = gen_label_rtx ();
3156 rtx save_receiver = gen_reg_rtx (Pmode);
3159 /* Don't let jump_optimize delete the handler. */
3160 LABEL_PRESERVE_P (handler_label) = 1;
3162 /* Record the handler address in the stack slot for that purpose,
3163 during this block, saving and restoring the outer value. */
3164 if (thisblock->next != 0)
3166 emit_move_insn (nonlocal_goto_handler_slot, save_receiver);
3169 emit_move_insn (save_receiver, nonlocal_goto_handler_slot);
3170 insns = get_insns ();
3172 emit_insns_before (insns, thisblock->data.block.first_insn);
3176 emit_move_insn (nonlocal_goto_handler_slot,
3177 gen_rtx (LABEL_REF, Pmode, handler_label));
3178 insns = get_insns ();
3180 emit_insns_before (insns, thisblock->data.block.first_insn);
3182 /* Jump around the handler; it runs only when specially invoked. */
3183 emit_jump (afterward);
3184 emit_label (handler_label);
3186 #ifdef HAVE_nonlocal_goto
3187 if (! HAVE_nonlocal_goto)
3189 /* First adjust our frame pointer to its actual value. It was
3190 previously set to the start of the virtual area corresponding to
3191 the stacked variables when we branched here and now needs to be
3192 adjusted to the actual hardware fp value.
3194 Assignments are to virtual registers are converted by
3195 instantiate_virtual_regs into the corresponding assignment
3196 to the underlying register (fp in this case) that makes
3197 the original assignment true.
3198 So the following insn will actually be
3199 decrementing fp by STARTING_FRAME_OFFSET. */
3200 emit_move_insn (virtual_stack_vars_rtx, hard_frame_pointer_rtx);
3202 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
3203 if (fixed_regs[ARG_POINTER_REGNUM])
3205 #ifdef ELIMINABLE_REGS
3206 /* If the argument pointer can be eliminated in favor of the
3207 frame pointer, we don't need to restore it. We assume here
3208 that if such an elimination is present, it can always be used.
3209 This is the case on all known machines; if we don't make this
3210 assumption, we do unnecessary saving on many machines. */
3211 static struct elims {int from, to;} elim_regs[] = ELIMINABLE_REGS;
3214 for (i = 0; i < sizeof elim_regs / sizeof elim_regs[0]; i++)
3215 if (elim_regs[i].from == ARG_POINTER_REGNUM
3216 && elim_regs[i].to == HARD_FRAME_POINTER_REGNUM)
3219 if (i == sizeof elim_regs / sizeof elim_regs [0])
3222 /* Now restore our arg pointer from the address at which it
3223 was saved in our stack frame.
3224 If there hasn't be space allocated for it yet, make
3226 if (arg_pointer_save_area == 0)
3227 arg_pointer_save_area
3228 = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
3229 emit_move_insn (virtual_incoming_args_rtx,
3230 /* We need a pseudo here, or else
3231 instantiate_virtual_regs_1 complains. */
3232 copy_to_reg (arg_pointer_save_area));
3237 #ifdef HAVE_nonlocal_goto_receiver
3238 if (HAVE_nonlocal_goto_receiver)
3239 emit_insn (gen_nonlocal_goto_receiver ());
3242 /* The handler expects the desired label address in the static chain
3243 register. It tests the address and does an appropriate jump
3244 to whatever label is desired. */
3245 for (link = nonlocal_labels; link; link = TREE_CHAIN (link))
3246 /* Skip any labels we shouldn't be able to jump to from here. */
3247 if (! DECL_TOO_LATE (TREE_VALUE (link)))
3249 rtx not_this = gen_label_rtx ();
3250 rtx this = gen_label_rtx ();
3251 do_jump_if_equal (static_chain_rtx,
3252 gen_rtx (LABEL_REF, Pmode, DECL_RTL (TREE_VALUE (link))),
3254 emit_jump (not_this);
3256 expand_goto (TREE_VALUE (link));
3257 emit_label (not_this);
3259 /* If label is not recognized, abort. */
3260 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "abort"), 0,
3263 emit_label (afterward);
3266 /* Don't allow jumping into a block that has cleanups or a stack level. */
3268 || thisblock->data.block.stack_level != 0
3269 || thisblock->data.block.cleanups != 0)
3271 struct label_chain *chain;
3273 /* Any labels in this block are no longer valid to go to.
3274 Mark them to cause an error message. */
3275 for (chain = thisblock->data.block.label_chain; chain; chain = chain->next)
3277 DECL_TOO_LATE (chain->label) = 1;
3278 /* If any goto without a fixup came to this label,
3279 that must be an error, because gotos without fixups
3280 come from outside all saved stack-levels and all cleanups. */
3281 if (TREE_ADDRESSABLE (chain->label))
3282 error_with_decl (chain->label,
3283 "label `%s' used before containing binding contour");
3287 /* Restore stack level in effect before the block
3288 (only if variable-size objects allocated). */
3289 /* Perform any cleanups associated with the block. */
3291 if (thisblock->data.block.stack_level != 0
3292 || thisblock->data.block.cleanups != 0)
3294 /* Only clean up here if this point can actually be reached. */
3295 int reachable = GET_CODE (get_last_insn ()) != BARRIER;
3297 /* Don't let cleanups affect ({...}) constructs. */
3298 int old_expr_stmts_for_value = expr_stmts_for_value;
3299 rtx old_last_expr_value = last_expr_value;
3300 tree old_last_expr_type = last_expr_type;
3301 expr_stmts_for_value = 0;
3303 /* Do the cleanups. */
3304 expand_cleanups (thisblock->data.block.cleanups, NULL_TREE, 0, reachable);
3306 do_pending_stack_adjust ();
3308 expr_stmts_for_value = old_expr_stmts_for_value;
3309 last_expr_value = old_last_expr_value;
3310 last_expr_type = old_last_expr_type;
3312 /* Restore the stack level. */
3314 if (reachable && thisblock->data.block.stack_level != 0)
3316 emit_stack_restore (thisblock->next ? SAVE_BLOCK : SAVE_FUNCTION,
3317 thisblock->data.block.stack_level, NULL_RTX);
3318 if (nonlocal_goto_handler_slot != 0)
3319 emit_stack_save (SAVE_NONLOCAL, &nonlocal_goto_stack_level,
3323 /* Any gotos out of this block must also do these things.
3324 Also report any gotos with fixups that came to labels in this
3326 fixup_gotos (thisblock,
3327 thisblock->data.block.stack_level,
3328 thisblock->data.block.cleanups,
3329 thisblock->data.block.first_insn,
3333 /* Mark the beginning and end of the scope if requested.
3334 We do this now, after running cleanups on the variables
3335 just going out of scope, so they are in scope for their cleanups. */
3338 last_block_end_note = emit_note (NULL_PTR, NOTE_INSN_BLOCK_END);
3340 /* Get rid of the beginning-mark if we don't make an end-mark. */
3341 NOTE_LINE_NUMBER (thisblock->data.block.first_insn) = NOTE_INSN_DELETED;
3343 /* If doing stupid register allocation, make sure lives of all
3344 register variables declared here extend thru end of scope. */
3347 for (decl = vars; decl; decl = TREE_CHAIN (decl))
3349 rtx rtl = DECL_RTL (decl);
3350 if (TREE_CODE (decl) == VAR_DECL && rtl != 0)
3354 /* Restore block_stack level for containing block. */
3356 stack_block_stack = thisblock->data.block.innermost_stack_block;
3357 POPSTACK (block_stack);
3359 /* Pop the stack slot nesting and free any slots at this level. */
3364 /* End a binding contour.
3365 VARS is the chain of VAR_DECL nodes for the variables bound
3366 in this contour. MARK_ENDS is nonzer if we should put a note
3367 at the beginning and end of this binding contour.
3368 DONT_JUMP_IN is nonzero if it is not valid to jump into this
3372 bc_expand_end_bindings (vars, mark_ends, dont_jump_in)
3377 struct nesting *thisbind = nesting_stack;
3381 for (decl = vars; decl; decl = TREE_CHAIN (decl))
3382 if (! TREE_USED (TREE_VALUE (decl)) && TREE_CODE (TREE_VALUE (decl)) == VAR_DECL)
3383 warning_with_decl (decl, "unused variable `%s'");
3385 if (thisbind->exit_label)
3386 bc_emit_bytecode_labeldef (BYTECODE_BC_LABEL (thisbind->exit_label));
3388 /* Pop block/bindings off stack */
3389 POPSTACK (block_stack);
3392 /* Generate RTL for the automatic variable declaration DECL.
3393 (Other kinds of declarations are simply ignored if seen here.) */
3399 struct nesting *thisblock = block_stack;
3402 if (output_bytecode)
3404 bc_expand_decl (decl, 0);
3408 type = TREE_TYPE (decl);
3410 /* Only automatic variables need any expansion done.
3411 Static and external variables, and external functions,
3412 will be handled by `assemble_variable' (called from finish_decl).
3413 TYPE_DECL and CONST_DECL require nothing.
3414 PARM_DECLs are handled in `assign_parms'. */
3416 if (TREE_CODE (decl) != VAR_DECL)
3418 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl))
3421 /* Create the RTL representation for the variable. */
3423 if (type == error_mark_node)
3424 DECL_RTL (decl) = gen_rtx (MEM, BLKmode, const0_rtx);
3425 else if (DECL_SIZE (decl) == 0)
3426 /* Variable with incomplete type. */
3428 if (DECL_INITIAL (decl) == 0)
3429 /* Error message was already done; now avoid a crash. */
3430 DECL_RTL (decl) = assign_stack_temp (DECL_MODE (decl), 0, 1);
3432 /* An initializer is going to decide the size of this array.
3433 Until we know the size, represent its address with a reg. */
3434 DECL_RTL (decl) = gen_rtx (MEM, BLKmode, gen_reg_rtx (Pmode));
3435 MEM_IN_STRUCT_P (DECL_RTL (decl)) = AGGREGATE_TYPE_P (type);
3437 else if (DECL_MODE (decl) != BLKmode
3438 /* If -ffloat-store, don't put explicit float vars
3440 && !(flag_float_store
3441 && TREE_CODE (type) == REAL_TYPE)
3442 && ! TREE_THIS_VOLATILE (decl)
3443 && ! TREE_ADDRESSABLE (decl)
3444 && (DECL_REGISTER (decl) || ! obey_regdecls))
3446 /* Automatic variable that can go in a register. */
3447 int unsignedp = TREE_UNSIGNED (type);
3448 enum machine_mode reg_mode
3449 = promote_mode (type, DECL_MODE (decl), &unsignedp, 0);
3451 DECL_RTL (decl) = gen_reg_rtx (reg_mode);
3452 mark_user_reg (DECL_RTL (decl));
3454 if (TREE_CODE (type) == POINTER_TYPE)
3455 mark_reg_pointer (DECL_RTL (decl),
3456 (TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl)))
3459 else if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
3461 /* Variable of fixed size that goes on the stack. */
3465 /* If we previously made RTL for this decl, it must be an array
3466 whose size was determined by the initializer.
3467 The old address was a register; set that register now
3468 to the proper address. */
3469 if (DECL_RTL (decl) != 0)
3471 if (GET_CODE (DECL_RTL (decl)) != MEM
3472 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != REG)
3474 oldaddr = XEXP (DECL_RTL (decl), 0);
3478 = assign_stack_temp (DECL_MODE (decl),
3479 ((TREE_INT_CST_LOW (DECL_SIZE (decl))
3480 + BITS_PER_UNIT - 1)
3483 MEM_IN_STRUCT_P (DECL_RTL (decl)) = AGGREGATE_TYPE_P (TREE_TYPE (decl));
3485 /* Set alignment we actually gave this decl. */
3486 DECL_ALIGN (decl) = (DECL_MODE (decl) == BLKmode ? BIGGEST_ALIGNMENT
3487 : GET_MODE_BITSIZE (DECL_MODE (decl)));
3491 addr = force_operand (XEXP (DECL_RTL (decl), 0), oldaddr);
3492 if (addr != oldaddr)
3493 emit_move_insn (oldaddr, addr);
3496 /* If this is a memory ref that contains aggregate components,
3497 mark it as such for cse and loop optimize. */
3498 MEM_IN_STRUCT_P (DECL_RTL (decl)) = AGGREGATE_TYPE_P (TREE_TYPE (decl));
3500 /* If this is in memory because of -ffloat-store,
3501 set the volatile bit, to prevent optimizations from
3502 undoing the effects. */
3503 if (flag_float_store && TREE_CODE (type) == REAL_TYPE)
3504 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
3508 /* Dynamic-size object: must push space on the stack. */
3512 /* Record the stack pointer on entry to block, if have
3513 not already done so. */
3514 if (thisblock->data.block.stack_level == 0)
3516 do_pending_stack_adjust ();
3517 emit_stack_save (thisblock->next ? SAVE_BLOCK : SAVE_FUNCTION,
3518 &thisblock->data.block.stack_level,
3519 thisblock->data.block.first_insn);
3520 stack_block_stack = thisblock;
3523 /* Compute the variable's size, in bytes. */
3524 size = expand_expr (size_binop (CEIL_DIV_EXPR,
3526 size_int (BITS_PER_UNIT)),
3527 NULL_RTX, VOIDmode, 0);
3530 /* Allocate space on the stack for the variable. Note that
3531 DECL_ALIGN says how the variable is to be aligned and we
3532 cannot use it to conclude anything about the alignment of
3534 address = allocate_dynamic_stack_space (size, NULL_RTX,
3535 TYPE_ALIGN (TREE_TYPE (decl)));
3537 /* Reference the variable indirect through that rtx. */
3538 DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl), address);
3540 /* If this is a memory ref that contains aggregate components,
3541 mark it as such for cse and loop optimize. */
3542 MEM_IN_STRUCT_P (DECL_RTL (decl)) = AGGREGATE_TYPE_P (TREE_TYPE (decl));
3544 /* Indicate the alignment we actually gave this variable. */
3545 #ifdef STACK_BOUNDARY
3546 DECL_ALIGN (decl) = STACK_BOUNDARY;
3548 DECL_ALIGN (decl) = BIGGEST_ALIGNMENT;
3552 if (TREE_THIS_VOLATILE (decl))
3553 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
3554 #if 0 /* A variable is not necessarily unchanging
3555 just because it is const. RTX_UNCHANGING_P
3556 means no change in the function,
3557 not merely no change in the variable's scope.
3558 It is correct to set RTX_UNCHANGING_P if the variable's scope
3559 is the whole function. There's no convenient way to test that. */
3560 if (TREE_READONLY (decl))
3561 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
3564 /* If doing stupid register allocation, make sure life of any
3565 register variable starts here, at the start of its scope. */
3568 use_variable (DECL_RTL (decl));
3572 /* Generate code for the automatic variable declaration DECL. For
3573 most variables this just means we give it a stack offset. The
3574 compiler sometimes emits cleanups without variables and we will
3575 have to deal with those too. */
3578 bc_expand_decl (decl, cleanup)
3586 /* A cleanup with no variable. */
3593 /* Only auto variables need any work. */
3594 if (TREE_CODE (decl) != VAR_DECL || TREE_STATIC (decl) || DECL_EXTERNAL (decl))
3597 type = TREE_TYPE (decl);
3599 if (type == error_mark_node)
3600 DECL_RTL (decl) = bc_gen_rtx ((char *) 0, 0, (struct bc_label *) 0);
3602 else if (DECL_SIZE (decl) == 0)
3604 /* Variable with incomplete type. The stack offset herein will be
3605 fixed later in expand_decl_init (). */
3606 DECL_RTL (decl) = bc_gen_rtx ((char *) 0, 0, (struct bc_label *) 0);
3608 else if (TREE_CONSTANT (DECL_SIZE (decl)))
3610 DECL_RTL (decl) = bc_allocate_local (TREE_INT_CST_LOW (DECL_SIZE (decl)) / BITS_PER_UNIT,
3614 DECL_RTL (decl) = bc_allocate_variable_array (DECL_SIZE (decl));
3617 /* Emit code to perform the initialization of a declaration DECL. */
3620 expand_decl_init (decl)
3623 int was_used = TREE_USED (decl);
3625 if (output_bytecode)
3627 bc_expand_decl_init (decl);
3631 /* If this is a CONST_DECL, we don't have to generate any code, but
3632 if DECL_INITIAL is a constant, call expand_expr to force TREE_CST_RTL
3633 to be set while in the obstack containing the constant. If we don't
3634 do this, we can lose if we have functions nested three deep and the middle
3635 function makes a CONST_DECL whose DECL_INITIAL is a STRING_CST while
3636 the innermost function is the first to expand that STRING_CST. */
3637 if (TREE_CODE (decl) == CONST_DECL)
3639 if (DECL_INITIAL (decl) && TREE_CONSTANT (DECL_INITIAL (decl)))
3640 expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode,
3641 EXPAND_INITIALIZER);
3645 if (TREE_STATIC (decl))
3648 /* Compute and store the initial value now. */
3650 if (DECL_INITIAL (decl) == error_mark_node)
3652 enum tree_code code = TREE_CODE (TREE_TYPE (decl));
3653 if (code == INTEGER_TYPE || code == REAL_TYPE || code == ENUMERAL_TYPE
3654 || code == POINTER_TYPE)
3655 expand_assignment (decl, convert (TREE_TYPE (decl), integer_zero_node),
3659 else if (DECL_INITIAL (decl) && TREE_CODE (DECL_INITIAL (decl)) != TREE_LIST)
3661 emit_line_note (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
3662 expand_assignment (decl, DECL_INITIAL (decl), 0, 0);
3666 /* Don't let the initialization count as "using" the variable. */
3667 TREE_USED (decl) = was_used;
3669 /* Free any temporaries we made while initializing the decl. */
3670 preserve_temp_slots (NULL_RTX);
3674 /* Expand initialization for variable-sized types. Allocate array
3675 using newlocalSI and set local variable, which is a pointer to the
3679 bc_expand_variable_local_init (decl)
3682 /* Evaluate size expression and coerce to SI */
3683 bc_expand_expr (DECL_SIZE (decl));
3685 /* Type sizes are always (?) of TREE_CODE INTEGER_CST, so
3686 no coercion is necessary (?) */
3688 /* emit_typecode_conversion (preferred_typecode (TYPE_MODE (DECL_SIZE (decl)),
3689 TREE_UNSIGNED (DECL_SIZE (decl))), SIcode); */
3691 /* Emit code to allocate array */
3692 bc_emit_instruction (newlocalSI);
3694 /* Store array pointer in local variable. This is the only instance
3695 where we actually want the address of the pointer to the
3696 variable-size block, rather than the pointer itself. We avoid
3697 using expand_address() since that would cause the pointer to be
3698 pushed rather than its address. Hence the hard-coded reference;
3699 notice also that the variable is always local (no global
3700 variable-size type variables). */
3702 bc_load_localaddr (DECL_RTL (decl));
3703 bc_emit_instruction (storeP);
3707 /* Emit code to initialize a declaration. */
3710 bc_expand_decl_init (decl)
3713 int org_stack_depth;
3715 /* Statical initializers are handled elsewhere */
3717 if (TREE_STATIC (decl))
3720 /* Memory original stack depth */
3721 org_stack_depth = stack_depth;
3723 /* If the type is variable-size, we first create its space (we ASSUME
3724 it CAN'T be static). We do this regardless of whether there's an
3725 initializer assignment or not. */
3727 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
3728 bc_expand_variable_local_init (decl);
3730 /* Expand initializer assignment */
3731 if (DECL_INITIAL (decl) == error_mark_node)
3733 enum tree_code code = TREE_CODE (TREE_TYPE (decl));
3735 if (code == INTEGER_TYPE || code == REAL_TYPE || code == ENUMERAL_TYPE
3736 || code == POINTER_TYPE)
3738 expand_assignment (TREE_TYPE (decl), decl, 0, 0);
3740 else if (DECL_INITIAL (decl))
3741 expand_assignment (TREE_TYPE (decl), decl, 0, 0);
3743 /* Restore stack depth */
3744 if (org_stack_depth > stack_depth)
3747 bc_adjust_stack (stack_depth - org_stack_depth);
3751 /* CLEANUP is an expression to be executed at exit from this binding contour;
3752 for example, in C++, it might call the destructor for this variable.
3754 We wrap CLEANUP in an UNSAVE_EXPR node, so that we can expand the
3755 CLEANUP multiple times, and have the correct semantics. This
3756 happens in exception handling, and for non-local gotos.
3758 If CLEANUP is nonzero and DECL is zero, we record a cleanup
3759 that is not associated with any particular variable. */
3762 expand_decl_cleanup (decl, cleanup)
3765 struct nesting *thisblock = block_stack;
3767 /* Error if we are not in any block. */
3771 /* Record the cleanup if there is one. */
3775 cleanup = unsave_expr (cleanup);
3777 thisblock->data.block.cleanups
3778 = temp_tree_cons (decl, cleanup, thisblock->data.block.cleanups);
3779 /* If this block has a cleanup, it belongs in stack_block_stack. */
3780 stack_block_stack = thisblock;
3781 expand_eh_region_start ();
3786 /* DECL is an anonymous union. CLEANUP is a cleanup for DECL.
3787 DECL_ELTS is the list of elements that belong to DECL's type.
3788 In each, the TREE_VALUE is a VAR_DECL, and the TREE_PURPOSE a cleanup. */
3791 expand_anon_union_decl (decl, cleanup, decl_elts)
3792 tree decl, cleanup, decl_elts;
3794 struct nesting *thisblock = block_stack;
3798 expand_decl_cleanup (decl, cleanup);
3799 x = DECL_RTL (decl);
3803 tree decl_elt = TREE_VALUE (decl_elts);
3804 tree cleanup_elt = TREE_PURPOSE (decl_elts);
3805 enum machine_mode mode = TYPE_MODE (TREE_TYPE (decl_elt));
3807 /* Propagate the union's alignment to the elements. */
3808 DECL_ALIGN (decl_elt) = DECL_ALIGN (decl);
3810 /* If the element has BLKmode and the union doesn't, the union is
3811 aligned such that the element doesn't need to have BLKmode, so
3812 change the element's mode to the appropriate one for its size. */
3813 if (mode == BLKmode && DECL_MODE (decl) != BLKmode)
3814 DECL_MODE (decl_elt) = mode
3815 = mode_for_size (TREE_INT_CST_LOW (DECL_SIZE (decl_elt)),
3818 /* (SUBREG (MEM ...)) at RTL generation time is invalid, so we
3819 instead create a new MEM rtx with the proper mode. */
3820 if (GET_CODE (x) == MEM)
3822 if (mode == GET_MODE (x))
3823 DECL_RTL (decl_elt) = x;
3826 DECL_RTL (decl_elt) = gen_rtx (MEM, mode, copy_rtx (XEXP (x, 0)));
3827 MEM_IN_STRUCT_P (DECL_RTL (decl_elt)) = MEM_IN_STRUCT_P (x);
3828 RTX_UNCHANGING_P (DECL_RTL (decl_elt)) = RTX_UNCHANGING_P (x);
3831 else if (GET_CODE (x) == REG)
3833 if (mode == GET_MODE (x))
3834 DECL_RTL (decl_elt) = x;
3836 DECL_RTL (decl_elt) = gen_rtx (SUBREG, mode, x, 0);
3841 /* Record the cleanup if there is one. */
3844 thisblock->data.block.cleanups
3845 = temp_tree_cons (decl_elt, cleanup_elt,
3846 thisblock->data.block.cleanups);
3848 decl_elts = TREE_CHAIN (decl_elts);
3852 /* Expand a list of cleanups LIST.
3853 Elements may be expressions or may be nested lists.
3855 If DONT_DO is nonnull, then any list-element
3856 whose TREE_PURPOSE matches DONT_DO is omitted.
3857 This is sometimes used to avoid a cleanup associated with
3858 a value that is being returned out of the scope.
3860 If IN_FIXUP is non-zero, we are generating this cleanup for a fixup
3861 goto and handle protection regions specially in that case.
3863 If REACHABLE, we emit code, otherwise just inform the exception handling
3864 code about this finalization. */
3867 expand_cleanups (list, dont_do, in_fixup, reachable)
3874 for (tail = list; tail; tail = TREE_CHAIN (tail))
3875 if (dont_do == 0 || TREE_PURPOSE (tail) != dont_do)
3877 if (TREE_CODE (TREE_VALUE (tail)) == TREE_LIST)
3878 expand_cleanups (TREE_VALUE (tail), dont_do, in_fixup, reachable);
3882 expand_eh_region_end (TREE_VALUE (tail));
3886 /* Cleanups may be run multiple times. For example,
3887 when exiting a binding contour, we expand the
3888 cleanups associated with that contour. When a goto
3889 within that binding contour has a target outside that
3890 contour, it will expand all cleanups from its scope to
3891 the target. Though the cleanups are expanded multiple
3892 times, the control paths are non-overlapping so the
3893 cleanups will not be executed twice. */
3894 expand_expr (TREE_VALUE (tail), const0_rtx, VOIDmode, 0);
3901 /* Move all cleanups from the current block_stack
3902 to the containing block_stack, where they are assumed to
3903 have been created. If anything can cause a temporary to
3904 be created, but not expanded for more than one level of
3905 block_stacks, then this code will have to change. */
3910 struct nesting *block = block_stack;
3911 struct nesting *outer = block->next;
3913 outer->data.block.cleanups
3914 = chainon (block->data.block.cleanups,
3915 outer->data.block.cleanups);
3916 block->data.block.cleanups = 0;
3920 last_cleanup_this_contour ()
3922 if (block_stack == 0)
3925 return block_stack->data.block.cleanups;
3928 /* Return 1 if there are any pending cleanups at this point.
3929 If THIS_CONTOUR is nonzero, check the current contour as well.
3930 Otherwise, look only at the contours that enclose this one. */
3933 any_pending_cleanups (this_contour)
3936 struct nesting *block;
3938 if (block_stack == 0)
3941 if (this_contour && block_stack->data.block.cleanups != NULL)
3943 if (block_stack->data.block.cleanups == 0
3944 && (block_stack->data.block.outer_cleanups == 0
3946 || block_stack->data.block.outer_cleanups == empty_cleanup_list
3951 for (block = block_stack->next; block; block = block->next)
3952 if (block->data.block.cleanups != 0)
3958 /* Enter a case (Pascal) or switch (C) statement.
3959 Push a block onto case_stack and nesting_stack
3960 to accumulate the case-labels that are seen
3961 and to record the labels generated for the statement.
3963 EXIT_FLAG is nonzero if `exit_something' should exit this case stmt.
3964 Otherwise, this construct is transparent for `exit_something'.
3966 EXPR is the index-expression to be dispatched on.
3967 TYPE is its nominal type. We could simply convert EXPR to this type,
3968 but instead we take short cuts. */
3971 expand_start_case (exit_flag, expr, type, printname)
3977 register struct nesting *thiscase = ALLOC_NESTING ();
3979 /* Make an entry on case_stack for the case we are entering. */
3981 thiscase->next = case_stack;
3982 thiscase->all = nesting_stack;
3983 thiscase->depth = ++nesting_depth;
3984 thiscase->exit_label = exit_flag ? gen_label_rtx () : 0;
3985 thiscase->data.case_stmt.case_list = 0;
3986 thiscase->data.case_stmt.index_expr = expr;
3987 thiscase->data.case_stmt.nominal_type = type;
3988 thiscase->data.case_stmt.default_label = 0;
3989 thiscase->data.case_stmt.num_ranges = 0;
3990 thiscase->data.case_stmt.printname = printname;
3991 thiscase->data.case_stmt.seenlabel = 0;
3992 case_stack = thiscase;
3993 nesting_stack = thiscase;
3995 if (output_bytecode)
3997 bc_expand_start_case (thiscase, expr, type, printname);
4001 do_pending_stack_adjust ();
4003 /* Make sure case_stmt.start points to something that won't
4004 need any transformation before expand_end_case. */
4005 if (GET_CODE (get_last_insn ()) != NOTE)
4006 emit_note (NULL_PTR, NOTE_INSN_DELETED);
4008 thiscase->data.case_stmt.start = get_last_insn ();
4012 /* Enter a case statement. It is assumed that the caller has pushed
4013 the current context onto the case stack. */
4016 bc_expand_start_case (thiscase, expr, type, printname)
4017 struct nesting *thiscase;
4022 bc_expand_expr (expr);
4023 bc_expand_conversion (TREE_TYPE (expr), type);
4025 /* For cases, the skip is a place we jump to that's emitted after
4026 the size of the jump table is known. */
4028 thiscase->data.case_stmt.skip_label = gen_label_rtx ();
4029 bc_emit_bytecode (jump);
4030 bc_emit_bytecode_labelref (BYTECODE_BC_LABEL (thiscase->data.case_stmt.skip_label));
4032 #ifdef DEBUG_PRINT_CODE
4033 fputc ('\n', stderr);
4038 /* Start a "dummy case statement" within which case labels are invalid
4039 and are not connected to any larger real case statement.
4040 This can be used if you don't want to let a case statement jump
4041 into the middle of certain kinds of constructs. */
4044 expand_start_case_dummy ()
4046 register struct nesting *thiscase = ALLOC_NESTING ();
4048 /* Make an entry on case_stack for the dummy. */
4050 thiscase->next = case_stack;
4051 thiscase->all = nesting_stack;
4052 thiscase->depth = ++nesting_depth;
4053 thiscase->exit_label = 0;
4054 thiscase->data.case_stmt.case_list = 0;
4055 thiscase->data.case_stmt.start = 0;
4056 thiscase->data.case_stmt.nominal_type = 0;
4057 thiscase->data.case_stmt.default_label = 0;
4058 thiscase->data.case_stmt.num_ranges = 0;
4059 case_stack = thiscase;
4060 nesting_stack = thiscase;
4063 /* End a dummy case statement. */
4066 expand_end_case_dummy ()
4068 POPSTACK (case_stack);
4071 /* Return the data type of the index-expression
4072 of the innermost case statement, or null if none. */
4075 case_index_expr_type ()
4078 return TREE_TYPE (case_stack->data.case_stmt.index_expr);
4082 /* Accumulate one case or default label inside a case or switch statement.
4083 VALUE is the value of the case (a null pointer, for a default label).
4084 The function CONVERTER, when applied to arguments T and V,
4085 converts the value V to the type T.
4087 If not currently inside a case or switch statement, return 1 and do
4088 nothing. The caller will print a language-specific error message.
4089 If VALUE is a duplicate or overlaps, return 2 and do nothing
4090 except store the (first) duplicate node in *DUPLICATE.
4091 If VALUE is out of range, return 3 and do nothing.
4092 If we are jumping into the scope of a cleaup or var-sized array, return 5.
4093 Return 0 on success.
4095 Extended to handle range statements. */
4098 pushcase (value, converter, label, duplicate)
4099 register tree value;
4100 tree (*converter) PROTO((tree, tree));
4101 register tree label;
4104 register struct case_node **l;
4105 register struct case_node *n;
4109 if (output_bytecode)
4110 return bc_pushcase (value, label);
4112 /* Fail if not inside a real case statement. */
4113 if (! (case_stack && case_stack->data.case_stmt.start))
4116 if (stack_block_stack
4117 && stack_block_stack->depth > case_stack->depth)
4120 index_type = TREE_TYPE (case_stack->data.case_stmt.index_expr);
4121 nominal_type = case_stack->data.case_stmt.nominal_type;
4123 /* If the index is erroneous, avoid more problems: pretend to succeed. */
4124 if (index_type == error_mark_node)
4127 /* Convert VALUE to the type in which the comparisons are nominally done. */
4129 value = (*converter) (nominal_type, value);
4131 /* If this is the first label, warn if any insns have been emitted. */
4132 if (case_stack->data.case_stmt.seenlabel == 0)
4135 for (insn = case_stack->data.case_stmt.start;
4137 insn = NEXT_INSN (insn))
4139 if (GET_CODE (insn) == CODE_LABEL)
4141 if (GET_CODE (insn) != NOTE
4142 && (GET_CODE (insn) != INSN || GET_CODE (PATTERN (insn)) != USE))
4144 warning ("unreachable code at beginning of %s",
4145 case_stack->data.case_stmt.printname);
4150 case_stack->data.case_stmt.seenlabel = 1;
4152 /* Fail if this value is out of range for the actual type of the index
4153 (which may be narrower than NOMINAL_TYPE). */
4154 if (value != 0 && ! int_fits_type_p (value, index_type))
4157 /* Fail if this is a duplicate or overlaps another entry. */
4160 if (case_stack->data.case_stmt.default_label != 0)
4162 *duplicate = case_stack->data.case_stmt.default_label;
4165 case_stack->data.case_stmt.default_label = label;
4168 return add_case_node (value, value, label, duplicate);
4170 expand_label (label);
4174 /* Like pushcase but this case applies to all values
4175 between VALUE1 and VALUE2 (inclusive).
4176 The return value is the same as that of pushcase
4177 but there is one additional error code:
4178 4 means the specified range was empty. */
4181 pushcase_range (value1, value2, converter, label, duplicate)
4182 register tree value1, value2;
4183 tree (*converter) PROTO((tree, tree));
4184 register tree label;
4187 register struct case_node **l;
4188 register struct case_node *n;
4192 /* Fail if not inside a real case statement. */
4193 if (! (case_stack && case_stack->data.case_stmt.start))
4196 if (stack_block_stack
4197 && stack_block_stack->depth > case_stack->depth)
4200 index_type = TREE_TYPE (case_stack->data.case_stmt.index_expr);
4201 nominal_type = case_stack->data.case_stmt.nominal_type;
4203 /* If the index is erroneous, avoid more problems: pretend to succeed. */
4204 if (index_type == error_mark_node)
4207 /* If this is the first label, warn if any insns have been emitted. */
4208 if (case_stack->data.case_stmt.seenlabel == 0)
4211 for (insn = case_stack->data.case_stmt.start;
4213 insn = NEXT_INSN (insn))
4215 if (GET_CODE (insn) == CODE_LABEL)
4217 if (GET_CODE (insn) != NOTE
4218 && (GET_CODE (insn) != INSN || GET_CODE (PATTERN (insn)) != USE))
4220 warning ("unreachable code at beginning of %s",
4221 case_stack->data.case_stmt.printname);
4226 case_stack->data.case_stmt.seenlabel = 1;
4228 /* Convert VALUEs to type in which the comparisons are nominally done. */
4229 if (value1 == 0) /* Negative infinity. */
4230 value1 = TYPE_MIN_VALUE(index_type);
4231 value1 = (*converter) (nominal_type, value1);
4233 if (value2 == 0) /* Positive infinity. */
4234 value2 = TYPE_MAX_VALUE(index_type);
4235 value2 = (*converter) (nominal_type, value2);
4237 /* Fail if these values are out of range. */
4238 if (! int_fits_type_p (value1, index_type))
4241 if (! int_fits_type_p (value2, index_type))
4244 /* Fail if the range is empty. */
4245 if (tree_int_cst_lt (value2, value1))
4248 return add_case_node (value1, value2, label, duplicate);
4251 /* Do the actual insertion of a case label for pushcase and pushcase_range
4252 into case_stack->data.case_stmt.case_list. Use an AVL tree to avoid
4253 slowdown for large switch statements. */
4256 add_case_node (low, high, label, duplicate)
4261 struct case_node *p, **q, *r;
4263 q = &case_stack->data.case_stmt.case_list;
4270 /* Keep going past elements distinctly greater than HIGH. */
4271 if (tree_int_cst_lt (high, p->low))
4274 /* or distinctly less than LOW. */
4275 else if (tree_int_cst_lt (p->high, low))
4280 /* We have an overlap; this is an error. */
4281 *duplicate = p->code_label;
4286 /* Add this label to the chain, and succeed.
4287 Copy LOW, HIGH so they are on temporary rather than momentary
4288 obstack and will thus survive till the end of the case statement. */
4290 r = (struct case_node *) oballoc (sizeof (struct case_node));
4291 r->low = copy_node (low);
4293 /* If the bounds are equal, turn this into the one-value case. */
4295 if (tree_int_cst_equal (low, high))
4299 r->high = copy_node (high);
4300 case_stack->data.case_stmt.num_ranges++;
4303 r->code_label = label;
4304 expand_label (label);
4314 struct case_node *s;
4320 if (! (b = p->balance))
4321 /* Growth propagation from left side. */
4328 if (p->left = s = r->right)
4345 case_stack->data.case_stmt.case_list = r;
4348 /* r->balance == +1 */
4353 struct case_node *t = r->right;
4355 if (p->left = s = t->right)
4359 if (r->right = s = t->left)
4381 case_stack->data.case_stmt.case_list = t;
4388 /* p->balance == +1; growth of left side balances the node. */
4398 if (! (b = p->balance))
4399 /* Growth propagation from right side. */
4407 if (p->right = s = r->left)
4424 case_stack->data.case_stmt.case_list = r;
4428 /* r->balance == -1 */
4432 struct case_node *t = r->left;
4434 if (p->right = s = t->left)
4439 if (r->left = s = t->right)
4462 case_stack->data.case_stmt.case_list = t;
4468 /* p->balance == -1; growth of right side balances the node. */
4481 /* Accumulate one case or default label; VALUE is the value of the
4482 case, or nil for a default label. If not currently inside a case,
4483 return 1 and do nothing. If VALUE is a duplicate or overlaps, return
4484 2 and do nothing. If VALUE is out of range, return 3 and do nothing.
4485 Return 0 on success. This function is a leftover from the earlier
4486 bytecode compiler, which was based on gcc 1.37. It should be
4487 merged into pushcase. */
4490 bc_pushcase (value, label)
4494 struct nesting *thiscase = case_stack;
4495 struct case_node *case_label, *new_label;
4500 /* Fail if duplicate, overlap, or out of type range. */
4503 value = convert (thiscase->data.case_stmt.nominal_type, value);
4504 if (! int_fits_type_p (value, thiscase->data.case_stmt.nominal_type))
4507 for (case_label = thiscase->data.case_stmt.case_list;
4508 case_label->left; case_label = case_label->left)
4509 if (! tree_int_cst_lt (case_label->left->high, value))
4512 if (case_label != thiscase->data.case_stmt.case_list
4513 && ! tree_int_cst_lt (case_label->high, value)
4514 || (case_label->left && ! tree_int_cst_lt (value, case_label->left->low)))
4517 new_label = (struct case_node *) oballoc (sizeof (struct case_node));
4518 new_label->low = new_label->high = copy_node (value);
4519 new_label->code_label = label;
4520 new_label->left = case_label->left;
4522 case_label->left = new_label;
4523 thiscase->data.case_stmt.num_ranges++;
4527 if (thiscase->data.case_stmt.default_label)
4529 thiscase->data.case_stmt.default_label = label;
4532 expand_label (label);
4536 /* Returns the number of possible values of TYPE.
4537 Returns -1 if the number is unknown or variable.
4538 Returns -2 if the number does not fit in a HOST_WIDE_INT.
4539 Sets *SPARENESS to 2 if TYPE is an ENUMERAL_TYPE whose values
4540 do not increase monotonically (there may be duplicates);
4541 to 1 if the values increase monotonically, but not always by 1;
4542 otherwise sets it to 0. */
4545 all_cases_count (type, spareness)
4549 HOST_WIDE_INT count, count_high = 0;
4552 switch (TREE_CODE (type))
4559 count = 1 << BITS_PER_UNIT;
4563 if (TREE_CODE (TYPE_MIN_VALUE (type)) != INTEGER_CST
4564 || TREE_CODE (TYPE_MAX_VALUE (type)) != INTEGER_CST)
4569 = TREE_INT_CST_LOW (TYPE_MAX_VALUE (type))
4570 - TREE_INT_CST_LOW (TYPE_MIN_VALUE (type)) + 1
4571 but with overflow checking. */
4572 tree mint = TYPE_MIN_VALUE (type);
4573 tree maxt = TYPE_MAX_VALUE (type);
4574 HOST_WIDE_INT lo, hi;
4575 neg_double(TREE_INT_CST_LOW (mint), TREE_INT_CST_HIGH (mint),
4577 add_double(TREE_INT_CST_LOW (maxt), TREE_INT_CST_HIGH (maxt),
4579 add_double (lo, hi, 1, 0, &lo, &hi);
4580 if (hi != 0 || lo < 0)
4587 for (t = TYPE_VALUES (type); t != NULL_TREE; t = TREE_CHAIN (t))
4589 if (TREE_CODE (TYPE_MIN_VALUE (type)) != INTEGER_CST
4590 || TREE_CODE (TREE_VALUE (t)) != INTEGER_CST
4591 || TREE_INT_CST_LOW (TYPE_MIN_VALUE (type)) + count
4592 != TREE_INT_CST_LOW (TREE_VALUE (t)))
4596 if (*spareness == 1)
4598 tree prev = TREE_VALUE (TYPE_VALUES (type));
4599 for (t = TYPE_VALUES (type); t = TREE_CHAIN (t), t != NULL_TREE; )
4601 if (! tree_int_cst_lt (prev, TREE_VALUE (t)))
4606 prev = TREE_VALUE (t);
4615 #define BITARRAY_TEST(ARRAY, INDEX) \
4616 ((ARRAY)[(unsigned) (INDEX) / HOST_BITS_PER_CHAR]\
4617 & (1 << ((unsigned) (INDEX) % HOST_BITS_PER_CHAR)))
4618 #define BITARRAY_SET(ARRAY, INDEX) \
4619 ((ARRAY)[(unsigned) (INDEX) / HOST_BITS_PER_CHAR]\
4620 |= 1 << ((unsigned) (INDEX) % HOST_BITS_PER_CHAR))
4622 /* Set the elements of the bitstring CASES_SEEN (which has length COUNT),
4623 with the case values we have seen, assuming the case expression
4625 SPARSENESS is as determined by all_cases_count.
4627 The time needed is proportional to COUNT, unless
4628 SPARSENESS is 2, in which case quadratic time is needed. */
4631 mark_seen_cases (type, cases_seen, count, sparseness)
4633 unsigned char *cases_seen;
4639 tree next_node_to_try = NULL_TREE;
4640 long next_node_offset = 0;
4642 register struct case_node *n, *root = case_stack->data.case_stmt.case_list;
4643 tree val = make_node (INTEGER_CST);
4644 TREE_TYPE (val) = type;
4647 else if (sparseness == 2)
4652 /* This less efficient loop is only needed to handle
4653 duplicate case values (multiple enum constants
4654 with the same value). */
4655 TREE_TYPE (val) = TREE_TYPE (root->low);
4656 for (t = TYPE_VALUES (type), xlo = 0; t != NULL_TREE;
4657 t = TREE_CHAIN (t), xlo++)
4659 TREE_INT_CST_LOW (val) = TREE_INT_CST_LOW (TREE_VALUE (t));
4660 TREE_INT_CST_HIGH (val) = TREE_INT_CST_HIGH (TREE_VALUE (t));
4664 /* Keep going past elements distinctly greater than VAL. */
4665 if (tree_int_cst_lt (val, n->low))
4668 /* or distinctly less than VAL. */
4669 else if (tree_int_cst_lt (n->high, val))
4674 /* We have found a matching range. */
4675 BITARRAY_SET (cases_seen, xlo);
4685 case_stack->data.case_stmt.case_list = root = case_tree2list (root, 0);
4686 for (n = root; n; n = n->right)
4688 TREE_INT_CST_LOW (val) = TREE_INT_CST_LOW (n->low);
4689 TREE_INT_CST_HIGH (val) = TREE_INT_CST_HIGH (n->low);
4690 while ( ! tree_int_cst_lt (n->high, val))
4692 /* Calculate (into xlo) the "offset" of the integer (val).
4693 The element with lowest value has offset 0, the next smallest
4694 element has offset 1, etc. */
4696 HOST_WIDE_INT xlo, xhi;
4698 if (sparseness && TYPE_VALUES (type) != NULL_TREE)
4700 /* The TYPE_VALUES will be in increasing order, so
4701 starting searching where we last ended. */
4702 t = next_node_to_try;
4703 xlo = next_node_offset;
4709 t = TYPE_VALUES (type);
4712 if (tree_int_cst_equal (val, TREE_VALUE (t)))
4714 next_node_to_try = TREE_CHAIN (t);
4715 next_node_offset = xlo + 1;
4720 if (t == next_node_to_try)
4729 t = TYPE_MIN_VALUE (type);
4731 neg_double (TREE_INT_CST_LOW (t), TREE_INT_CST_HIGH (t),
4735 add_double (xlo, xhi,
4736 TREE_INT_CST_LOW (val), TREE_INT_CST_HIGH (val),
4740 if (xhi == 0 && xlo >= 0 && xlo < count)
4741 BITARRAY_SET (cases_seen, xlo);
4742 add_double (TREE_INT_CST_LOW (val), TREE_INT_CST_HIGH (val),
4744 &TREE_INT_CST_LOW (val), &TREE_INT_CST_HIGH (val));
4750 /* Called when the index of a switch statement is an enumerated type
4751 and there is no default label.
4753 Checks that all enumeration literals are covered by the case
4754 expressions of a switch. Also, warn if there are any extra
4755 switch cases that are *not* elements of the enumerated type.
4757 If all enumeration literals were covered by the case expressions,
4758 turn one of the expressions into the default expression since it should
4759 not be possible to fall through such a switch. */
4762 check_for_full_enumeration_handling (type)
4765 register struct case_node *n;
4766 register struct case_node **l;
4767 register tree chain;
4770 /* True iff the selector type is a numbered set mode. */
4773 /* The number of possible selector values. */
4776 /* For each possible selector value. a one iff it has been matched
4777 by a case value alternative. */
4778 unsigned char *cases_seen;
4780 /* The allocated size of cases_seen, in chars. */
4784 if (output_bytecode)
4786 bc_check_for_full_enumeration_handling (type);
4793 size = all_cases_count (type, &sparseness);
4794 bytes_needed = (size + HOST_BITS_PER_CHAR) / HOST_BITS_PER_CHAR;
4796 if (size > 0 && size < 600000
4797 /* We deliberately use malloc here - not xmalloc. */
4798 && (cases_seen = (unsigned char *) malloc (bytes_needed)) != NULL)
4801 tree v = TYPE_VALUES (type);
4802 bzero (cases_seen, bytes_needed);
4804 /* The time complexity of this code is normally O(N), where
4805 N being the number of members in the enumerated type.
4806 However, if type is a ENUMERAL_TYPE whose values do not
4807 increase monotonically, O(N*log(N)) time may be needed. */
4809 mark_seen_cases (type, cases_seen, size, sparseness);
4811 for (i = 0; v != NULL_TREE && i < size; i++, v = TREE_CHAIN (v))
4813 if (BITARRAY_TEST(cases_seen, i) == 0)
4814 warning ("enumeration value `%s' not handled in switch",
4815 IDENTIFIER_POINTER (TREE_PURPOSE (v)));
4821 /* Now we go the other way around; we warn if there are case
4822 expressions that don't correspond to enumerators. This can
4823 occur since C and C++ don't enforce type-checking of
4824 assignments to enumeration variables. */
4826 if (case_stack->data.case_stmt.case_list
4827 && case_stack->data.case_stmt.case_list->left)
4828 case_stack->data.case_stmt.case_list
4829 = case_tree2list (case_stack->data.case_stmt.case_list, 0);
4831 for (n = case_stack->data.case_stmt.case_list; n; n = n->right)
4833 for (chain = TYPE_VALUES (type);
4834 chain && !tree_int_cst_equal (n->low, TREE_VALUE (chain));
4835 chain = TREE_CHAIN (chain))
4840 if (TYPE_NAME (type) == 0)
4841 warning ("case value `%d' not in enumerated type",
4842 TREE_INT_CST_LOW (n->low));
4844 warning ("case value `%d' not in enumerated type `%s'",
4845 TREE_INT_CST_LOW (n->low),
4846 IDENTIFIER_POINTER ((TREE_CODE (TYPE_NAME (type))
4849 : DECL_NAME (TYPE_NAME (type))));
4851 if (!tree_int_cst_equal (n->low, n->high))
4853 for (chain = TYPE_VALUES (type);
4854 chain && !tree_int_cst_equal (n->high, TREE_VALUE (chain));
4855 chain = TREE_CHAIN (chain))
4860 if (TYPE_NAME (type) == 0)
4861 warning ("case value `%d' not in enumerated type",
4862 TREE_INT_CST_LOW (n->high));
4864 warning ("case value `%d' not in enumerated type `%s'",
4865 TREE_INT_CST_LOW (n->high),
4866 IDENTIFIER_POINTER ((TREE_CODE (TYPE_NAME (type))
4869 : DECL_NAME (TYPE_NAME (type))));
4875 /* ??? This optimization is disabled because it causes valid programs to
4876 fail. ANSI C does not guarantee that an expression with enum type
4877 will have a value that is the same as one of the enumeration literals. */
4879 /* If all values were found as case labels, make one of them the default
4880 label. Thus, this switch will never fall through. We arbitrarily pick
4881 the last one to make the default since this is likely the most
4882 efficient choice. */
4886 for (l = &case_stack->data.case_stmt.case_list;
4891 case_stack->data.case_stmt.default_label = (*l)->code_label;
4898 /* Check that all enumeration literals are covered by the case
4899 expressions of a switch. Also warn if there are any cases
4900 that are not elements of the enumerated type. */
4903 bc_check_for_full_enumeration_handling (type)
4906 struct nesting *thiscase = case_stack;
4907 struct case_node *c;
4910 /* Check for enums not handled. */
4911 for (e = TYPE_VALUES (type); e; e = TREE_CHAIN (e))
4913 for (c = thiscase->data.case_stmt.case_list->left;
4914 c && tree_int_cst_lt (c->high, TREE_VALUE (e));
4917 if (! (c && tree_int_cst_equal (c->low, TREE_VALUE (e))))
4918 warning ("enumerated value `%s' not handled in switch",
4919 IDENTIFIER_POINTER (TREE_PURPOSE (e)));
4922 /* Check for cases not in the enumeration. */
4923 for (c = thiscase->data.case_stmt.case_list->left; c; c = c->left)
4925 for (e = TYPE_VALUES (type);
4926 e && !tree_int_cst_equal (c->low, TREE_VALUE (e));
4930 warning ("case value `%d' not in enumerated type `%s'",
4931 TREE_INT_CST_LOW (c->low),
4932 IDENTIFIER_POINTER (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
4934 : DECL_NAME (TYPE_NAME (type))));
4938 /* Terminate a case (Pascal) or switch (C) statement
4939 in which ORIG_INDEX is the expression to be tested.
4940 Generate the code to test it and jump to the right place. */
4943 expand_end_case (orig_index)
4946 tree minval, maxval, range, orig_minval;
4947 rtx default_label = 0;
4948 register struct case_node *n;
4956 register struct nesting *thiscase = case_stack;
4957 tree index_expr, index_type;
4960 if (output_bytecode)
4962 bc_expand_end_case (orig_index);
4966 table_label = gen_label_rtx ();
4967 index_expr = thiscase->data.case_stmt.index_expr;
4968 index_type = TREE_TYPE (index_expr);
4969 unsignedp = TREE_UNSIGNED (index_type);
4971 do_pending_stack_adjust ();
4973 /* An ERROR_MARK occurs for various reasons including invalid data type. */
4974 if (index_type != error_mark_node)
4976 /* If switch expression was an enumerated type, check that all
4977 enumeration literals are covered by the cases.
4978 No sense trying this if there's a default case, however. */
4980 if (!thiscase->data.case_stmt.default_label
4981 && TREE_CODE (TREE_TYPE (orig_index)) == ENUMERAL_TYPE
4982 && TREE_CODE (index_expr) != INTEGER_CST)
4983 check_for_full_enumeration_handling (TREE_TYPE (orig_index));
4985 /* If this is the first label, warn if any insns have been emitted. */
4986 if (thiscase->data.case_stmt.seenlabel == 0)
4989 for (insn = get_last_insn ();
4990 insn != case_stack->data.case_stmt.start;
4991 insn = PREV_INSN (insn))
4992 if (GET_CODE (insn) != NOTE
4993 && (GET_CODE (insn) != INSN || GET_CODE (PATTERN (insn))!= USE))
4995 warning ("unreachable code at beginning of %s",
4996 case_stack->data.case_stmt.printname);
5001 /* If we don't have a default-label, create one here,
5002 after the body of the switch. */
5003 if (thiscase->data.case_stmt.default_label == 0)
5005 thiscase->data.case_stmt.default_label
5006 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
5007 expand_label (thiscase->data.case_stmt.default_label);
5009 default_label = label_rtx (thiscase->data.case_stmt.default_label);
5011 before_case = get_last_insn ();
5013 if (thiscase->data.case_stmt.case_list
5014 && thiscase->data.case_stmt.case_list->left)
5015 thiscase->data.case_stmt.case_list
5016 = case_tree2list(thiscase->data.case_stmt.case_list, 0);
5018 /* Simplify the case-list before we count it. */
5019 group_case_nodes (thiscase->data.case_stmt.case_list);
5021 /* Get upper and lower bounds of case values.
5022 Also convert all the case values to the index expr's data type. */
5025 for (n = thiscase->data.case_stmt.case_list; n; n = n->right)
5027 /* Check low and high label values are integers. */
5028 if (TREE_CODE (n->low) != INTEGER_CST)
5030 if (TREE_CODE (n->high) != INTEGER_CST)
5033 n->low = convert (index_type, n->low);
5034 n->high = convert (index_type, n->high);
5036 /* Count the elements and track the largest and smallest
5037 of them (treating them as signed even if they are not). */
5045 if (INT_CST_LT (n->low, minval))
5047 if (INT_CST_LT (maxval, n->high))
5050 /* A range counts double, since it requires two compares. */
5051 if (! tree_int_cst_equal (n->low, n->high))
5055 orig_minval = minval;
5057 /* Compute span of values. */
5059 range = fold (build (MINUS_EXPR, index_type, maxval, minval));
5063 expand_expr (index_expr, const0_rtx, VOIDmode, 0);
5065 emit_jump (default_label);
5068 /* If range of values is much bigger than number of values,
5069 make a sequence of conditional branches instead of a dispatch.
5070 If the switch-index is a constant, do it this way
5071 because we can optimize it. */
5073 #ifndef CASE_VALUES_THRESHOLD
5075 #define CASE_VALUES_THRESHOLD (HAVE_casesi ? 4 : 5)
5077 /* If machine does not have a case insn that compares the
5078 bounds, this means extra overhead for dispatch tables
5079 which raises the threshold for using them. */
5080 #define CASE_VALUES_THRESHOLD 5
5081 #endif /* HAVE_casesi */
5082 #endif /* CASE_VALUES_THRESHOLD */
5084 else if (TREE_INT_CST_HIGH (range) != 0
5085 || count < CASE_VALUES_THRESHOLD
5086 || ((unsigned HOST_WIDE_INT) (TREE_INT_CST_LOW (range))
5088 #ifndef ASM_OUTPUT_ADDR_DIFF_ELT
5091 || TREE_CODE (index_expr) == INTEGER_CST
5092 /* These will reduce to a constant. */
5093 || (TREE_CODE (index_expr) == CALL_EXPR
5094 && TREE_CODE (TREE_OPERAND (index_expr, 0)) == ADDR_EXPR
5095 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (index_expr, 0), 0)) == FUNCTION_DECL
5096 && DECL_FUNCTION_CODE (TREE_OPERAND (TREE_OPERAND (index_expr, 0), 0)) == BUILT_IN_CLASSIFY_TYPE)
5097 || (TREE_CODE (index_expr) == COMPOUND_EXPR
5098 && TREE_CODE (TREE_OPERAND (index_expr, 1)) == INTEGER_CST))
5100 index = expand_expr (index_expr, NULL_RTX, VOIDmode, 0);
5102 /* If the index is a short or char that we do not have
5103 an insn to handle comparisons directly, convert it to
5104 a full integer now, rather than letting each comparison
5105 generate the conversion. */
5107 if (GET_MODE_CLASS (GET_MODE (index)) == MODE_INT
5108 && (cmp_optab->handlers[(int) GET_MODE(index)].insn_code
5109 == CODE_FOR_nothing))
5111 enum machine_mode wider_mode;
5112 for (wider_mode = GET_MODE (index); wider_mode != VOIDmode;
5113 wider_mode = GET_MODE_WIDER_MODE (wider_mode))
5114 if (cmp_optab->handlers[(int) wider_mode].insn_code
5115 != CODE_FOR_nothing)
5117 index = convert_to_mode (wider_mode, index, unsignedp);
5123 do_pending_stack_adjust ();
5125 index = protect_from_queue (index, 0);
5126 if (GET_CODE (index) == MEM)
5127 index = copy_to_reg (index);
5128 if (GET_CODE (index) == CONST_INT
5129 || TREE_CODE (index_expr) == INTEGER_CST)
5131 /* Make a tree node with the proper constant value
5132 if we don't already have one. */
5133 if (TREE_CODE (index_expr) != INTEGER_CST)
5136 = build_int_2 (INTVAL (index),
5137 unsignedp || INTVAL (index) >= 0 ? 0 : -1);
5138 index_expr = convert (index_type, index_expr);
5141 /* For constant index expressions we need only
5142 issue a unconditional branch to the appropriate
5143 target code. The job of removing any unreachable
5144 code is left to the optimisation phase if the
5145 "-O" option is specified. */
5146 for (n = thiscase->data.case_stmt.case_list; n; n = n->right)
5147 if (! tree_int_cst_lt (index_expr, n->low)
5148 && ! tree_int_cst_lt (n->high, index_expr))
5152 emit_jump (label_rtx (n->code_label));
5154 emit_jump (default_label);
5158 /* If the index expression is not constant we generate
5159 a binary decision tree to select the appropriate
5160 target code. This is done as follows:
5162 The list of cases is rearranged into a binary tree,
5163 nearly optimal assuming equal probability for each case.
5165 The tree is transformed into RTL, eliminating
5166 redundant test conditions at the same time.
5168 If program flow could reach the end of the
5169 decision tree an unconditional jump to the
5170 default code is emitted. */
5173 = (TREE_CODE (TREE_TYPE (orig_index)) != ENUMERAL_TYPE
5174 && estimate_case_costs (thiscase->data.case_stmt.case_list));
5175 balance_case_nodes (&thiscase->data.case_stmt.case_list,
5177 emit_case_nodes (index, thiscase->data.case_stmt.case_list,
5178 default_label, index_type);
5179 emit_jump_if_reachable (default_label);
5188 enum machine_mode index_mode = SImode;
5189 int index_bits = GET_MODE_BITSIZE (index_mode);
5191 enum machine_mode op_mode;
5193 /* Convert the index to SImode. */
5194 if (GET_MODE_BITSIZE (TYPE_MODE (index_type))
5195 > GET_MODE_BITSIZE (index_mode))
5197 enum machine_mode omode = TYPE_MODE (index_type);
5198 rtx rangertx = expand_expr (range, NULL_RTX, VOIDmode, 0);
5200 /* We must handle the endpoints in the original mode. */
5201 index_expr = build (MINUS_EXPR, index_type,
5202 index_expr, minval);
5203 minval = integer_zero_node;
5204 index = expand_expr (index_expr, NULL_RTX, VOIDmode, 0);
5205 emit_cmp_insn (rangertx, index, LTU, NULL_RTX, omode, 1, 0);
5206 emit_jump_insn (gen_bltu (default_label));
5207 /* Now we can safely truncate. */
5208 index = convert_to_mode (index_mode, index, 0);
5212 if (TYPE_MODE (index_type) != index_mode)
5214 index_expr = convert (type_for_size (index_bits, 0),
5216 index_type = TREE_TYPE (index_expr);
5219 index = expand_expr (index_expr, NULL_RTX, VOIDmode, 0);
5222 index = protect_from_queue (index, 0);
5223 do_pending_stack_adjust ();
5225 op_mode = insn_operand_mode[(int)CODE_FOR_casesi][0];
5226 if (! (*insn_operand_predicate[(int)CODE_FOR_casesi][0])
5228 index = copy_to_mode_reg (op_mode, index);
5230 op1 = expand_expr (minval, NULL_RTX, VOIDmode, 0);
5232 op_mode = insn_operand_mode[(int)CODE_FOR_casesi][1];
5233 if (! (*insn_operand_predicate[(int)CODE_FOR_casesi][1])
5235 op1 = copy_to_mode_reg (op_mode, op1);
5237 op2 = expand_expr (range, NULL_RTX, VOIDmode, 0);
5239 op_mode = insn_operand_mode[(int)CODE_FOR_casesi][2];
5240 if (! (*insn_operand_predicate[(int)CODE_FOR_casesi][2])
5242 op2 = copy_to_mode_reg (op_mode, op2);
5244 emit_jump_insn (gen_casesi (index, op1, op2,
5245 table_label, default_label));
5249 #ifdef HAVE_tablejump
5250 if (! win && HAVE_tablejump)
5252 index_expr = convert (thiscase->data.case_stmt.nominal_type,
5253 fold (build (MINUS_EXPR, index_type,
5254 index_expr, minval)));
5255 index_type = TREE_TYPE (index_expr);
5256 index = expand_expr (index_expr, NULL_RTX, VOIDmode, 0);
5258 index = protect_from_queue (index, 0);
5259 do_pending_stack_adjust ();
5261 do_tablejump (index, TYPE_MODE (index_type),
5262 expand_expr (range, NULL_RTX, VOIDmode, 0),
5263 table_label, default_label);
5270 /* Get table of labels to jump to, in order of case index. */
5272 ncases = TREE_INT_CST_LOW (range) + 1;
5273 labelvec = (rtx *) alloca (ncases * sizeof (rtx));
5274 bzero ((char *) labelvec, ncases * sizeof (rtx));
5276 for (n = thiscase->data.case_stmt.case_list; n; n = n->right)
5278 register HOST_WIDE_INT i
5279 = TREE_INT_CST_LOW (n->low) - TREE_INT_CST_LOW (orig_minval);
5284 = gen_rtx (LABEL_REF, Pmode, label_rtx (n->code_label));
5285 if (i + TREE_INT_CST_LOW (orig_minval)
5286 == TREE_INT_CST_LOW (n->high))
5292 /* Fill in the gaps with the default. */
5293 for (i = 0; i < ncases; i++)
5294 if (labelvec[i] == 0)
5295 labelvec[i] = gen_rtx (LABEL_REF, Pmode, default_label);
5297 /* Output the table */
5298 emit_label (table_label);
5300 /* This would be a lot nicer if CASE_VECTOR_PC_RELATIVE
5301 were an expression, instead of an #ifdef/#ifndef. */
5303 #ifdef CASE_VECTOR_PC_RELATIVE
5307 emit_jump_insn (gen_rtx (ADDR_DIFF_VEC, CASE_VECTOR_MODE,
5308 gen_rtx (LABEL_REF, Pmode, table_label),
5309 gen_rtvec_v (ncases, labelvec)));
5311 emit_jump_insn (gen_rtx (ADDR_VEC, CASE_VECTOR_MODE,
5312 gen_rtvec_v (ncases, labelvec)));
5314 /* If the case insn drops through the table,
5315 after the table we must jump to the default-label.
5316 Otherwise record no drop-through after the table. */
5317 #ifdef CASE_DROPS_THROUGH
5318 emit_jump (default_label);
5324 before_case = squeeze_notes (NEXT_INSN (before_case), get_last_insn ());
5325 reorder_insns (before_case, get_last_insn (),
5326 thiscase->data.case_stmt.start);
5329 if (thiscase->exit_label)
5330 emit_label (thiscase->exit_label);
5332 POPSTACK (case_stack);
5337 /* Convert the tree NODE into a list linked by the right field, with the left
5338 field zeroed. RIGHT is used for recursion; it is a list to be placed
5339 rightmost in the resulting list. */
5341 static struct case_node *
5342 case_tree2list (node, right)
5343 struct case_node *node, *right;
5345 struct case_node *left;
5348 right = case_tree2list (node->right, right);
5350 node->right = right;
5351 if (left = node->left)
5354 return case_tree2list (left, node);
5360 /* Terminate a case statement. EXPR is the original index
5364 bc_expand_end_case (expr)
5367 struct nesting *thiscase = case_stack;
5368 enum bytecode_opcode opcode;
5369 struct bc_label *jump_label;
5370 struct case_node *c;
5372 bc_emit_bytecode (jump);
5373 bc_emit_bytecode_labelref (BYTECODE_BC_LABEL (thiscase->exit_label));
5375 #ifdef DEBUG_PRINT_CODE
5376 fputc ('\n', stderr);
5379 /* Now that the size of the jump table is known, emit the actual
5380 indexed jump instruction. */
5381 bc_emit_bytecode_labeldef (BYTECODE_BC_LABEL (thiscase->data.case_stmt.skip_label));
5383 opcode = TYPE_MODE (thiscase->data.case_stmt.nominal_type) == SImode
5384 ? TREE_UNSIGNED (thiscase->data.case_stmt.nominal_type) ? caseSU : caseSI
5385 : TREE_UNSIGNED (thiscase->data.case_stmt.nominal_type) ? caseDU : caseDI;
5387 bc_emit_bytecode (opcode);
5389 /* Now emit the case instructions literal arguments, in order.
5390 In addition to the value on the stack, it uses:
5391 1. The address of the jump table.
5392 2. The size of the jump table.
5393 3. The default label. */
5395 jump_label = bc_get_bytecode_label ();
5396 bc_emit_bytecode_labelref (jump_label);
5397 bc_emit_bytecode_const ((char *) &thiscase->data.case_stmt.num_ranges,
5398 sizeof thiscase->data.case_stmt.num_ranges);
5400 if (thiscase->data.case_stmt.default_label)
5401 bc_emit_bytecode_labelref (BYTECODE_BC_LABEL (DECL_RTL (thiscase->data.case_stmt.default_label)));
5403 bc_emit_bytecode_labelref (BYTECODE_BC_LABEL (thiscase->exit_label));
5405 /* Output the jump table. */
5407 bc_align_bytecode (3 /* PTR_ALIGN */);
5408 bc_emit_bytecode_labeldef (jump_label);
5410 if (TYPE_MODE (thiscase->data.case_stmt.nominal_type) == SImode)
5411 for (c = thiscase->data.case_stmt.case_list->left; c; c = c->left)
5413 opcode = TREE_INT_CST_LOW (c->low);
5414 bc_emit_bytecode_const ((char *) &opcode, sizeof opcode);
5416 opcode = TREE_INT_CST_LOW (c->high);
5417 bc_emit_bytecode_const ((char *) &opcode, sizeof opcode);
5419 bc_emit_bytecode_labelref (BYTECODE_BC_LABEL (DECL_RTL (c->code_label)));
5422 if (TYPE_MODE (thiscase->data.case_stmt.nominal_type) == DImode)
5423 for (c = thiscase->data.case_stmt.case_list->left; c; c = c->left)
5425 bc_emit_bytecode_DI_const (c->low);
5426 bc_emit_bytecode_DI_const (c->high);
5428 bc_emit_bytecode_labelref (BYTECODE_BC_LABEL (DECL_RTL (c->code_label)));
5435 bc_emit_bytecode_labeldef (BYTECODE_BC_LABEL (thiscase->exit_label));
5437 /* Possibly issue enumeration warnings. */
5439 if (!thiscase->data.case_stmt.default_label
5440 && TREE_CODE (TREE_TYPE (expr)) == ENUMERAL_TYPE
5441 && TREE_CODE (expr) != INTEGER_CST
5443 check_for_full_enumeration_handling (TREE_TYPE (expr));
5446 #ifdef DEBUG_PRINT_CODE
5447 fputc ('\n', stderr);
5450 POPSTACK (case_stack);
5454 /* Return unique bytecode ID. */
5459 static int bc_uid = 0;
5464 /* Generate code to jump to LABEL if OP1 and OP2 are equal. */
5467 do_jump_if_equal (op1, op2, label, unsignedp)
5468 rtx op1, op2, label;
5471 if (GET_CODE (op1) == CONST_INT
5472 && GET_CODE (op2) == CONST_INT)
5474 if (INTVAL (op1) == INTVAL (op2))
5479 enum machine_mode mode = GET_MODE (op1);
5480 if (mode == VOIDmode)
5481 mode = GET_MODE (op2);
5482 emit_cmp_insn (op1, op2, EQ, NULL_RTX, mode, unsignedp, 0);
5483 emit_jump_insn (gen_beq (label));
5487 /* Not all case values are encountered equally. This function
5488 uses a heuristic to weight case labels, in cases where that
5489 looks like a reasonable thing to do.
5491 Right now, all we try to guess is text, and we establish the
5494 chars above space: 16
5503 If we find any cases in the switch that are not either -1 or in the range
5504 of valid ASCII characters, or are control characters other than those
5505 commonly used with "\", don't treat this switch scanning text.
5507 Return 1 if these nodes are suitable for cost estimation, otherwise
5511 estimate_case_costs (node)
5514 tree min_ascii = build_int_2 (-1, -1);
5515 tree max_ascii = convert (TREE_TYPE (node->high), build_int_2 (127, 0));
5519 /* If we haven't already made the cost table, make it now. Note that the
5520 lower bound of the table is -1, not zero. */
5522 if (cost_table == NULL)
5524 cost_table = ((short *) xmalloc (129 * sizeof (short))) + 1;
5525 bzero ((char *) (cost_table - 1), 129 * sizeof (short));
5527 for (i = 0; i < 128; i++)
5531 else if (ispunct (i))
5533 else if (iscntrl (i))
5537 cost_table[' '] = 8;
5538 cost_table['\t'] = 4;
5539 cost_table['\0'] = 4;
5540 cost_table['\n'] = 2;
5541 cost_table['\f'] = 1;
5542 cost_table['\v'] = 1;
5543 cost_table['\b'] = 1;
5546 /* See if all the case expressions look like text. It is text if the
5547 constant is >= -1 and the highest constant is <= 127. Do all comparisons
5548 as signed arithmetic since we don't want to ever access cost_table with a
5549 value less than -1. Also check that none of the constants in a range
5550 are strange control characters. */
5552 for (n = node; n; n = n->right)
5554 if ((INT_CST_LT (n->low, min_ascii)) || INT_CST_LT (max_ascii, n->high))
5557 for (i = TREE_INT_CST_LOW (n->low); i <= TREE_INT_CST_LOW (n->high); i++)
5558 if (cost_table[i] < 0)
5562 /* All interesting values are within the range of interesting
5563 ASCII characters. */
5567 /* Scan an ordered list of case nodes
5568 combining those with consecutive values or ranges.
5570 Eg. three separate entries 1: 2: 3: become one entry 1..3: */
5573 group_case_nodes (head)
5576 case_node_ptr node = head;
5580 rtx lb = next_real_insn (label_rtx (node->code_label));
5581 case_node_ptr np = node;
5583 /* Try to group the successors of NODE with NODE. */
5584 while (((np = np->right) != 0)
5585 /* Do they jump to the same place? */
5586 && next_real_insn (label_rtx (np->code_label)) == lb
5587 /* Are their ranges consecutive? */
5588 && tree_int_cst_equal (np->low,
5589 fold (build (PLUS_EXPR,
5590 TREE_TYPE (node->high),
5593 /* An overflow is not consecutive. */
5594 && tree_int_cst_lt (node->high,
5595 fold (build (PLUS_EXPR,
5596 TREE_TYPE (node->high),
5598 integer_one_node))))
5600 node->high = np->high;
5602 /* NP is the first node after NODE which can't be grouped with it.
5603 Delete the nodes in between, and move on to that node. */
5609 /* Take an ordered list of case nodes
5610 and transform them into a near optimal binary tree,
5611 on the assumption that any target code selection value is as
5612 likely as any other.
5614 The transformation is performed by splitting the ordered
5615 list into two equal sections plus a pivot. The parts are
5616 then attached to the pivot as left and right branches. Each
5617 branch is is then transformed recursively. */
5620 balance_case_nodes (head, parent)
5621 case_node_ptr *head;
5622 case_node_ptr parent;
5624 register case_node_ptr np;
5632 register case_node_ptr *npp;
5635 /* Count the number of entries on branch. Also count the ranges. */
5639 if (!tree_int_cst_equal (np->low, np->high))
5643 cost += cost_table[TREE_INT_CST_LOW (np->high)];
5647 cost += cost_table[TREE_INT_CST_LOW (np->low)];
5655 /* Split this list if it is long enough for that to help. */
5660 /* Find the place in the list that bisects the list's total cost,
5661 Here I gets half the total cost. */
5666 /* Skip nodes while their cost does not reach that amount. */
5667 if (!tree_int_cst_equal ((*npp)->low, (*npp)->high))
5668 i -= cost_table[TREE_INT_CST_LOW ((*npp)->high)];
5669 i -= cost_table[TREE_INT_CST_LOW ((*npp)->low)];
5672 npp = &(*npp)->right;
5677 /* Leave this branch lopsided, but optimize left-hand
5678 side and fill in `parent' fields for right-hand side. */
5680 np->parent = parent;
5681 balance_case_nodes (&np->left, np);
5682 for (; np->right; np = np->right)
5683 np->right->parent = np;
5687 /* If there are just three nodes, split at the middle one. */
5689 npp = &(*npp)->right;
5692 /* Find the place in the list that bisects the list's total cost,
5693 where ranges count as 2.
5694 Here I gets half the total cost. */
5695 i = (i + ranges + 1) / 2;
5698 /* Skip nodes while their cost does not reach that amount. */
5699 if (!tree_int_cst_equal ((*npp)->low, (*npp)->high))
5704 npp = &(*npp)->right;
5709 np->parent = parent;
5712 /* Optimize each of the two split parts. */
5713 balance_case_nodes (&np->left, np);
5714 balance_case_nodes (&np->right, np);
5718 /* Else leave this branch as one level,
5719 but fill in `parent' fields. */
5721 np->parent = parent;
5722 for (; np->right; np = np->right)
5723 np->right->parent = np;
5728 /* Search the parent sections of the case node tree
5729 to see if a test for the lower bound of NODE would be redundant.
5730 INDEX_TYPE is the type of the index expression.
5732 The instructions to generate the case decision tree are
5733 output in the same order as nodes are processed so it is
5734 known that if a parent node checks the range of the current
5735 node minus one that the current node is bounded at its lower
5736 span. Thus the test would be redundant. */
5739 node_has_low_bound (node, index_type)
5744 case_node_ptr pnode;
5746 /* If the lower bound of this node is the lowest value in the index type,
5747 we need not test it. */
5749 if (tree_int_cst_equal (node->low, TYPE_MIN_VALUE (index_type)))
5752 /* If this node has a left branch, the value at the left must be less
5753 than that at this node, so it cannot be bounded at the bottom and
5754 we need not bother testing any further. */
5759 low_minus_one = fold (build (MINUS_EXPR, TREE_TYPE (node->low),
5760 node->low, integer_one_node));
5762 /* If the subtraction above overflowed, we can't verify anything.
5763 Otherwise, look for a parent that tests our value - 1. */
5765 if (! tree_int_cst_lt (low_minus_one, node->low))
5768 for (pnode = node->parent; pnode; pnode = pnode->parent)
5769 if (tree_int_cst_equal (low_minus_one, pnode->high))
5775 /* Search the parent sections of the case node tree
5776 to see if a test for the upper bound of NODE would be redundant.
5777 INDEX_TYPE is the type of the index expression.
5779 The instructions to generate the case decision tree are
5780 output in the same order as nodes are processed so it is
5781 known that if a parent node checks the range of the current
5782 node plus one that the current node is bounded at its upper
5783 span. Thus the test would be redundant. */
5786 node_has_high_bound (node, index_type)
5791 case_node_ptr pnode;
5793 /* If the upper bound of this node is the highest value in the type
5794 of the index expression, we need not test against it. */
5796 if (tree_int_cst_equal (node->high, TYPE_MAX_VALUE (index_type)))
5799 /* If this node has a right branch, the value at the right must be greater
5800 than that at this node, so it cannot be bounded at the top and
5801 we need not bother testing any further. */
5806 high_plus_one = fold (build (PLUS_EXPR, TREE_TYPE (node->high),
5807 node->high, integer_one_node));
5809 /* If the addition above overflowed, we can't verify anything.
5810 Otherwise, look for a parent that tests our value + 1. */
5812 if (! tree_int_cst_lt (node->high, high_plus_one))
5815 for (pnode = node->parent; pnode; pnode = pnode->parent)
5816 if (tree_int_cst_equal (high_plus_one, pnode->low))
5822 /* Search the parent sections of the
5823 case node tree to see if both tests for the upper and lower
5824 bounds of NODE would be redundant. */
5827 node_is_bounded (node, index_type)
5831 return (node_has_low_bound (node, index_type)
5832 && node_has_high_bound (node, index_type));
5835 /* Emit an unconditional jump to LABEL unless it would be dead code. */
5838 emit_jump_if_reachable (label)
5841 if (GET_CODE (get_last_insn ()) != BARRIER)
5845 /* Emit step-by-step code to select a case for the value of INDEX.
5846 The thus generated decision tree follows the form of the
5847 case-node binary tree NODE, whose nodes represent test conditions.
5848 INDEX_TYPE is the type of the index of the switch.
5850 Care is taken to prune redundant tests from the decision tree
5851 by detecting any boundary conditions already checked by
5852 emitted rtx. (See node_has_high_bound, node_has_low_bound
5853 and node_is_bounded, above.)
5855 Where the test conditions can be shown to be redundant we emit
5856 an unconditional jump to the target code. As a further
5857 optimization, the subordinates of a tree node are examined to
5858 check for bounded nodes. In this case conditional and/or
5859 unconditional jumps as a result of the boundary check for the
5860 current node are arranged to target the subordinates associated
5861 code for out of bound conditions on the current node node.
5863 We can assume that when control reaches the code generated here,
5864 the index value has already been compared with the parents
5865 of this node, and determined to be on the same side of each parent
5866 as this node is. Thus, if this node tests for the value 51,
5867 and a parent tested for 52, we don't need to consider
5868 the possibility of a value greater than 51. If another parent
5869 tests for the value 50, then this node need not test anything. */
5872 emit_case_nodes (index, node, default_label, index_type)
5878 /* If INDEX has an unsigned type, we must make unsigned branches. */
5879 int unsignedp = TREE_UNSIGNED (index_type);
5880 typedef rtx rtx_function ();
5881 rtx_function *gen_bgt_pat = unsignedp ? gen_bgtu : gen_bgt;
5882 rtx_function *gen_bge_pat = unsignedp ? gen_bgeu : gen_bge;
5883 rtx_function *gen_blt_pat = unsignedp ? gen_bltu : gen_blt;
5884 rtx_function *gen_ble_pat = unsignedp ? gen_bleu : gen_ble;
5885 enum machine_mode mode = GET_MODE (index);
5887 /* See if our parents have already tested everything for us.
5888 If they have, emit an unconditional jump for this node. */
5889 if (node_is_bounded (node, index_type))
5890 emit_jump (label_rtx (node->code_label));
5892 else if (tree_int_cst_equal (node->low, node->high))
5894 /* Node is single valued. First see if the index expression matches
5895 this node and then check our children, if any. */
5897 do_jump_if_equal (index, expand_expr (node->low, NULL_RTX, VOIDmode, 0),
5898 label_rtx (node->code_label), unsignedp);
5900 if (node->right != 0 && node->left != 0)
5902 /* This node has children on both sides.
5903 Dispatch to one side or the other
5904 by comparing the index value with this node's value.
5905 If one subtree is bounded, check that one first,
5906 so we can avoid real branches in the tree. */
5908 if (node_is_bounded (node->right, index_type))
5910 emit_cmp_insn (index, expand_expr (node->high, NULL_RTX,
5912 GT, NULL_RTX, mode, unsignedp, 0);
5914 emit_jump_insn ((*gen_bgt_pat) (label_rtx (node->right->code_label)));
5915 emit_case_nodes (index, node->left, default_label, index_type);
5918 else if (node_is_bounded (node->left, index_type))
5920 emit_cmp_insn (index, expand_expr (node->high, NULL_RTX,
5922 LT, NULL_RTX, mode, unsignedp, 0);
5923 emit_jump_insn ((*gen_blt_pat) (label_rtx (node->left->code_label)));
5924 emit_case_nodes (index, node->right, default_label, index_type);
5929 /* Neither node is bounded. First distinguish the two sides;
5930 then emit the code for one side at a time. */
5933 = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
5935 /* See if the value is on the right. */
5936 emit_cmp_insn (index, expand_expr (node->high, NULL_RTX,
5938 GT, NULL_RTX, mode, unsignedp, 0);
5939 emit_jump_insn ((*gen_bgt_pat) (label_rtx (test_label)));
5941 /* Value must be on the left.
5942 Handle the left-hand subtree. */
5943 emit_case_nodes (index, node->left, default_label, index_type);
5944 /* If left-hand subtree does nothing,
5946 emit_jump_if_reachable (default_label);
5948 /* Code branches here for the right-hand subtree. */
5949 expand_label (test_label);
5950 emit_case_nodes (index, node->right, default_label, index_type);
5954 else if (node->right != 0 && node->left == 0)
5956 /* Here we have a right child but no left so we issue conditional
5957 branch to default and process the right child.
5959 Omit the conditional branch to default if we it avoid only one
5960 right child; it costs too much space to save so little time. */
5962 if (node->right->right || node->right->left
5963 || !tree_int_cst_equal (node->right->low, node->right->high))
5965 if (!node_has_low_bound (node, index_type))
5967 emit_cmp_insn (index, expand_expr (node->high, NULL_RTX,
5969 LT, NULL_RTX, mode, unsignedp, 0);
5970 emit_jump_insn ((*gen_blt_pat) (default_label));
5973 emit_case_nodes (index, node->right, default_label, index_type);
5976 /* We cannot process node->right normally
5977 since we haven't ruled out the numbers less than
5978 this node's value. So handle node->right explicitly. */
5979 do_jump_if_equal (index,
5980 expand_expr (node->right->low, NULL_RTX,
5982 label_rtx (node->right->code_label), unsignedp);
5985 else if (node->right == 0 && node->left != 0)
5987 /* Just one subtree, on the left. */
5989 #if 0 /* The following code and comment were formerly part
5990 of the condition here, but they didn't work
5991 and I don't understand what the idea was. -- rms. */
5992 /* If our "most probable entry" is less probable
5993 than the default label, emit a jump to
5994 the default label using condition codes
5995 already lying around. With no right branch,
5996 a branch-greater-than will get us to the default
5999 && cost_table[TREE_INT_CST_LOW (node->high)] < 12)
6002 if (node->left->left || node->left->right
6003 || !tree_int_cst_equal (node->left->low, node->left->high))
6005 if (!node_has_high_bound (node, index_type))
6007 emit_cmp_insn (index, expand_expr (node->high, NULL_RTX,
6009 GT, NULL_RTX, mode, unsignedp, 0);
6010 emit_jump_insn ((*gen_bgt_pat) (default_label));
6013 emit_case_nodes (index, node->left, default_label, index_type);
6016 /* We cannot process node->left normally
6017 since we haven't ruled out the numbers less than
6018 this node's value. So handle node->left explicitly. */
6019 do_jump_if_equal (index,
6020 expand_expr (node->left->low, NULL_RTX,
6022 label_rtx (node->left->code_label), unsignedp);
6027 /* Node is a range. These cases are very similar to those for a single
6028 value, except that we do not start by testing whether this node
6029 is the one to branch to. */
6031 if (node->right != 0 && node->left != 0)
6033 /* Node has subtrees on both sides.
6034 If the right-hand subtree is bounded,
6035 test for it first, since we can go straight there.
6036 Otherwise, we need to make a branch in the control structure,
6037 then handle the two subtrees. */
6038 tree test_label = 0;
6040 emit_cmp_insn (index, expand_expr (node->high, NULL_RTX,
6042 GT, NULL_RTX, mode, unsignedp, 0);
6044 if (node_is_bounded (node->right, index_type))
6045 /* Right hand node is fully bounded so we can eliminate any
6046 testing and branch directly to the target code. */
6047 emit_jump_insn ((*gen_bgt_pat) (label_rtx (node->right->code_label)));
6050 /* Right hand node requires testing.
6051 Branch to a label where we will handle it later. */
6053 test_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
6054 emit_jump_insn ((*gen_bgt_pat) (label_rtx (test_label)));
6057 /* Value belongs to this node or to the left-hand subtree. */
6059 emit_cmp_insn (index, expand_expr (node->low, NULL_RTX, VOIDmode, 0),
6060 GE, NULL_RTX, mode, unsignedp, 0);
6061 emit_jump_insn ((*gen_bge_pat) (label_rtx (node->code_label)));
6063 /* Handle the left-hand subtree. */
6064 emit_case_nodes (index, node->left, default_label, index_type);
6066 /* If right node had to be handled later, do that now. */
6070 /* If the left-hand subtree fell through,
6071 don't let it fall into the right-hand subtree. */
6072 emit_jump_if_reachable (default_label);
6074 expand_label (test_label);
6075 emit_case_nodes (index, node->right, default_label, index_type);
6079 else if (node->right != 0 && node->left == 0)
6081 /* Deal with values to the left of this node,
6082 if they are possible. */
6083 if (!node_has_low_bound (node, index_type))
6085 emit_cmp_insn (index, expand_expr (node->low, NULL_RTX,
6087 LT, NULL_RTX, mode, unsignedp, 0);
6088 emit_jump_insn ((*gen_blt_pat) (default_label));
6091 /* Value belongs to this node or to the right-hand subtree. */
6093 emit_cmp_insn (index, expand_expr (node->high, NULL_RTX,
6095 LE, NULL_RTX, mode, unsignedp, 0);
6096 emit_jump_insn ((*gen_ble_pat) (label_rtx (node->code_label)));
6098 emit_case_nodes (index, node->right, default_label, index_type);
6101 else if (node->right == 0 && node->left != 0)
6103 /* Deal with values to the right of this node,
6104 if they are possible. */
6105 if (!node_has_high_bound (node, index_type))
6107 emit_cmp_insn (index, expand_expr (node->high, NULL_RTX,
6109 GT, NULL_RTX, mode, unsignedp, 0);
6110 emit_jump_insn ((*gen_bgt_pat) (default_label));
6113 /* Value belongs to this node or to the left-hand subtree. */
6115 emit_cmp_insn (index, expand_expr (node->low, NULL_RTX, VOIDmode, 0),
6116 GE, NULL_RTX, mode, unsignedp, 0);
6117 emit_jump_insn ((*gen_bge_pat) (label_rtx (node->code_label)));
6119 emit_case_nodes (index, node->left, default_label, index_type);
6124 /* Node has no children so we check low and high bounds to remove
6125 redundant tests. Only one of the bounds can exist,
6126 since otherwise this node is bounded--a case tested already. */
6128 if (!node_has_high_bound (node, index_type))
6130 emit_cmp_insn (index, expand_expr (node->high, NULL_RTX,
6132 GT, NULL_RTX, mode, unsignedp, 0);
6133 emit_jump_insn ((*gen_bgt_pat) (default_label));
6136 if (!node_has_low_bound (node, index_type))
6138 emit_cmp_insn (index, expand_expr (node->low, NULL_RTX,
6140 LT, NULL_RTX, mode, unsignedp, 0);
6141 emit_jump_insn ((*gen_blt_pat) (default_label));
6144 emit_jump (label_rtx (node->code_label));
6149 /* These routines are used by the loop unrolling code. They copy BLOCK trees
6150 so that the debugging info will be correct for the unrolled loop. */
6152 /* Indexed by block number, contains a pointer to the N'th block node. */
6154 static tree *block_vector;
6157 find_loop_tree_blocks ()
6159 tree block = DECL_INITIAL (current_function_decl);
6161 block_vector = identify_blocks (block, get_insns ());
6165 unroll_block_trees ()
6167 tree block = DECL_INITIAL (current_function_decl);
6169 reorder_blocks (block_vector, block, get_insns ());