1 /* Expands front end tree to back end RTL for GNU C-Compiler
2 Copyright (C) 1987, 1988, 1989, 1992 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* This file handles the generation of rtl code from tree structure
22 above the level of expressions, using subroutines in exp*.c and emit-rtl.c.
23 It also creates the rtl expressions for parameters and auto variables
24 and has full responsibility for allocating stack slots.
26 The functions whose names start with `expand_' are called by the
27 parser to generate RTL instructions for various kinds of constructs.
29 Some control and binding constructs require calling several such
30 functions at different times. For example, a simple if-then
31 is expanded by calling `expand_start_cond' (with the condition-expression
32 as argument) before parsing the then-clause and calling `expand_end_cond'
33 after parsing the then-clause. */
44 #include "insn-flags.h"
45 #include "insn-config.h"
46 #include "insn-codes.h"
48 #include "hard-reg-set.h"
53 #define obstack_chunk_alloc xmalloc
54 #define obstack_chunk_free free
55 struct obstack stmt_obstack
;
57 /* Filename and line number of last line-number note,
58 whether we actually emitted it or not. */
62 /* Nonzero if within a ({...}) grouping, in which case we must
63 always compute a value for each expr-stmt in case it is the last one. */
65 int expr_stmts_for_value
;
67 /* Each time we expand an expression-statement,
68 record the expr's type and its RTL value here. */
70 static tree last_expr_type
;
71 static rtx last_expr_value
;
73 /* Each time we expand the end of a binding contour (in `expand_end_bindings')
74 and we emit a new NOTE_INSN_BLOCK_END note, we save a pointer to it here.
75 This is used by the `remember_end_note' function to record the endpoint
76 of each generated block in its associated BLOCK node. */
78 static rtx last_block_end_note
;
80 /* Number of binding contours started so far in this function. */
82 int block_start_count
;
84 /* Nonzero if function being compiled needs to
85 return the address of where it has put a structure value. */
87 extern int current_function_returns_pcc_struct
;
89 /* Label that will go on parm cleanup code, if any.
90 Jumping to this label runs cleanup code for parameters, if
91 such code must be run. Following this code is the logical return label. */
93 extern rtx cleanup_label
;
95 /* Label that will go on function epilogue.
96 Jumping to this label serves as a "return" instruction
97 on machines which require execution of the epilogue on all returns. */
99 extern rtx return_label
;
101 /* List (chain of EXPR_LISTs) of pseudo-regs of SAVE_EXPRs.
102 So we can mark them all live at the end of the function, if nonopt. */
103 extern rtx save_expr_regs
;
105 /* Offset to end of allocated area of stack frame.
106 If stack grows down, this is the address of the last stack slot allocated.
107 If stack grows up, this is the address for the next slot. */
108 extern int frame_offset
;
110 /* Label to jump back to for tail recursion, or 0 if we have
111 not yet needed one for this function. */
112 extern rtx tail_recursion_label
;
114 /* Place after which to insert the tail_recursion_label if we need one. */
115 extern rtx tail_recursion_reentry
;
117 /* Location at which to save the argument pointer if it will need to be
118 referenced. There are two cases where this is done: if nonlocal gotos
119 exist, or if vars whose is an offset from the argument pointer will be
120 needed by inner routines. */
122 extern rtx arg_pointer_save_area
;
124 /* Chain of all RTL_EXPRs that have insns in them. */
125 extern tree rtl_expr_chain
;
127 #if 0 /* Turned off because 0 seems to work just as well. */
128 /* Cleanup lists are required for binding levels regardless of whether
129 that binding level has cleanups or not. This node serves as the
130 cleanup list whenever an empty list is required. */
131 static tree empty_cleanup_list
;
134 /* Functions and data structures for expanding case statements. */
136 /* Case label structure, used to hold info on labels within case
137 statements. We handle "range" labels; for a single-value label
138 as in C, the high and low limits are the same.
140 A chain of case nodes is initially maintained via the RIGHT fields
141 in the nodes. Nodes with higher case values are later in the list.
143 Switch statements can be output in one of two forms. A branch table
144 is used if there are more than a few labels and the labels are dense
145 within the range between the smallest and largest case value. If a
146 branch table is used, no further manipulations are done with the case
149 The alternative to the use of a branch table is to generate a series
150 of compare and jump insns. When that is done, we use the LEFT, RIGHT,
151 and PARENT fields to hold a binary tree. Initially the tree is
152 totally unbalanced, with everything on the right. We balance the tree
153 with nodes on the left having lower case values than the parent
154 and nodes on the right having higher values. We then output the tree
159 struct case_node
*left
; /* Left son in binary tree */
160 struct case_node
*right
; /* Right son in binary tree; also node chain */
161 struct case_node
*parent
; /* Parent of node in binary tree */
162 tree low
; /* Lowest index value for this label */
163 tree high
; /* Highest index value for this label */
164 tree code_label
; /* Label to jump to when node matches */
167 typedef struct case_node case_node
;
168 typedef struct case_node
*case_node_ptr
;
170 /* These are used by estimate_case_costs and balance_case_nodes. */
172 /* This must be a signed type, and non-ANSI compilers lack signed char. */
173 static short *cost_table
;
174 static int use_cost_table
;
176 static int estimate_case_costs ();
177 static void balance_case_nodes ();
178 static void emit_case_nodes ();
179 static void group_case_nodes ();
180 static void emit_jump_if_reachable ();
182 static int warn_if_unused_value ();
183 static void expand_goto_internal ();
184 static int expand_fixup ();
186 void free_temp_slots ();
187 static void expand_cleanups ();
188 static void expand_null_return_1 ();
189 static int tail_recursion_args ();
190 static void do_jump_if_equal ();
192 /* Stack of control and binding constructs we are currently inside.
194 These constructs begin when you call `expand_start_WHATEVER'
195 and end when you call `expand_end_WHATEVER'. This stack records
196 info about how the construct began that tells the end-function
197 what to do. It also may provide information about the construct
198 to alter the behavior of other constructs within the body.
199 For example, they may affect the behavior of C `break' and `continue'.
201 Each construct gets one `struct nesting' object.
202 All of these objects are chained through the `all' field.
203 `nesting_stack' points to the first object (innermost construct).
204 The position of an entry on `nesting_stack' is in its `depth' field.
206 Each type of construct has its own individual stack.
207 For example, loops have `loop_stack'. Each object points to the
208 next object of the same type through the `next' field.
210 Some constructs are visible to `break' exit-statements and others
211 are not. Which constructs are visible depends on the language.
212 Therefore, the data structure allows each construct to be visible
213 or not, according to the args given when the construct is started.
214 The construct is visible if the `exit_label' field is non-null.
215 In that case, the value should be a CODE_LABEL rtx. */
220 struct nesting
*next
;
225 /* For conds (if-then and if-then-else statements). */
228 /* Label for the end of the if construct.
229 There is none if EXITFLAG was not set
230 and no `else' has been seen yet. */
232 /* Label for the end of this alternative.
233 This may be the end of the if or the next else/elseif. */
239 /* Label at the top of the loop; place to loop back to. */
241 /* Label at the end of the whole construct. */
243 /* Label for `continue' statement to jump to;
244 this is in front of the stepper of the loop. */
247 /* For variable binding contours. */
250 /* Sequence number of this binding contour within the function,
251 in order of entry. */
252 int block_start_count
;
253 /* Nonzero => value to restore stack to on exit. */
255 /* The NOTE that starts this contour.
256 Used by expand_goto to check whether the destination
257 is within each contour or not. */
259 /* Innermost containing binding contour that has a stack level. */
260 struct nesting
*innermost_stack_block
;
261 /* List of cleanups to be run on exit from this contour.
262 This is a list of expressions to be evaluated.
263 The TREE_PURPOSE of each link is the ..._DECL node
264 which the cleanup pertains to. */
266 /* List of cleanup-lists of blocks containing this block,
267 as they were at the locus where this block appears.
268 There is an element for each containing block,
269 ordered innermost containing block first.
270 The tail of this list can be 0 (was empty_cleanup_list),
271 if all remaining elements would be empty lists.
272 The element's TREE_VALUE is the cleanup-list of that block,
273 which may be null. */
275 /* Chain of labels defined inside this binding contour.
276 For contours that have stack levels or cleanups. */
277 struct label_chain
*label_chain
;
278 /* Number of function calls seen, as of start of this block. */
279 int function_call_count
;
281 /* For switch (C) or case (Pascal) statements,
282 and also for dummies (see `expand_start_case_dummy'). */
285 /* The insn after which the case dispatch should finally
286 be emitted. Zero for a dummy. */
288 /* A list of case labels, kept in ascending order by value
289 as the list is built.
290 During expand_end_case, this list may be rearranged into a
291 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. */
306 /* For exception contours. */
309 /* List of exceptions raised. This is a TREE_LIST
310 of whatever you want. */
312 /* List of exceptions caught. This is also a TREE_LIST
313 of whatever you want. As a special case, it has the
314 value `void_type_node' if it handles default exceptions. */
317 /* First insn of TRY block, in case resumptive model is needed. */
319 /* Label for the catch clauses. */
321 /* Label for unhandled exceptions. */
323 /* Label at the end of whole construct. */
325 /* Label which "escapes" the exception construct.
326 Like EXIT_LABEL for BREAK construct, but for exceptions. */
332 /* Chain of all pending binding contours. */
333 struct nesting
*block_stack
;
335 /* If any new stacks are added here, add them to POPSTACKS too. */
337 /* Chain of all pending binding contours that restore stack levels
339 struct nesting
*stack_block_stack
;
341 /* Chain of all pending conditional statements. */
342 struct nesting
*cond_stack
;
344 /* Chain of all pending loops. */
345 struct nesting
*loop_stack
;
347 /* Chain of all pending case or switch statements. */
348 struct nesting
*case_stack
;
350 /* Chain of all pending exception contours. */
351 struct nesting
*except_stack
;
353 /* Separate chain including all of the above,
354 chained through the `all' field. */
355 struct nesting
*nesting_stack
;
357 /* Number of entries on nesting_stack now. */
360 /* Allocate and return a new `struct nesting'. */
362 #define ALLOC_NESTING() \
363 (struct nesting *) obstack_alloc (&stmt_obstack, sizeof (struct nesting))
365 /* Pop the nesting stack element by element until we pop off
366 the element which is at the top of STACK.
367 Update all the other stacks, popping off elements from them
368 as we pop them from nesting_stack. */
370 #define POPSTACK(STACK) \
371 do { struct nesting *target = STACK; \
372 struct nesting *this; \
373 do { this = nesting_stack; \
374 if (loop_stack == this) \
375 loop_stack = loop_stack->next; \
376 if (cond_stack == this) \
377 cond_stack = cond_stack->next; \
378 if (block_stack == this) \
379 block_stack = block_stack->next; \
380 if (stack_block_stack == this) \
381 stack_block_stack = stack_block_stack->next; \
382 if (case_stack == this) \
383 case_stack = case_stack->next; \
384 if (except_stack == this) \
385 except_stack = except_stack->next; \
386 nesting_depth = nesting_stack->depth - 1; \
387 nesting_stack = this->all; \
388 obstack_free (&stmt_obstack, this); } \
389 while (this != target); } while (0)
391 /* In some cases it is impossible to generate code for a forward goto
392 until the label definition is seen. This happens when it may be necessary
393 for the goto to reset the stack pointer: we don't yet know how to do that.
394 So expand_goto puts an entry on this fixup list.
395 Each time a binding contour that resets the stack is exited,
397 If the target label has now been defined, we can insert the proper code. */
401 /* Points to following fixup. */
402 struct goto_fixup
*next
;
403 /* Points to the insn before the jump insn.
404 If more code must be inserted, it goes after this insn. */
406 /* The LABEL_DECL that this jump is jumping to, or 0
407 for break, continue or return. */
409 /* The BLOCK for the place where this goto was found. */
411 /* The CODE_LABEL rtx that this is jumping to. */
413 /* Number of binding contours started in current function
414 before the label reference. */
415 int block_start_count
;
416 /* The outermost stack level that should be restored for this jump.
417 Each time a binding contour that resets the stack is exited,
418 if the target label is *not* yet defined, this slot is updated. */
420 /* List of lists of cleanup expressions to be run by this goto.
421 There is one element for each block that this goto is within.
422 The tail of this list can be 0 (was empty_cleanup_list),
423 if all remaining elements would be empty.
424 The TREE_VALUE contains the cleanup list of that block as of the
425 time this goto was seen.
426 The TREE_ADDRESSABLE flag is 1 for a block that has been exited. */
427 tree cleanup_list_list
;
430 static struct goto_fixup
*goto_fixup_chain
;
432 /* Within any binding contour that must restore a stack level,
433 all labels are recorded with a chain of these structures. */
437 /* Points to following fixup. */
438 struct label_chain
*next
;
445 gcc_obstack_init (&stmt_obstack
);
447 empty_cleanup_list
= build_tree_list (NULL_TREE
, NULL_TREE
);
452 init_stmt_for_function ()
454 /* We are not currently within any block, conditional, loop or case. */
462 block_start_count
= 0;
464 /* No gotos have been expanded yet. */
465 goto_fixup_chain
= 0;
467 /* We are not processing a ({...}) grouping. */
468 expr_stmts_for_value
= 0;
476 p
->block_stack
= block_stack
;
477 p
->stack_block_stack
= stack_block_stack
;
478 p
->cond_stack
= cond_stack
;
479 p
->loop_stack
= loop_stack
;
480 p
->case_stack
= case_stack
;
481 p
->nesting_stack
= nesting_stack
;
482 p
->nesting_depth
= nesting_depth
;
483 p
->block_start_count
= block_start_count
;
484 p
->last_expr_type
= last_expr_type
;
485 p
->last_expr_value
= last_expr_value
;
486 p
->expr_stmts_for_value
= expr_stmts_for_value
;
487 p
->emit_filename
= emit_filename
;
488 p
->emit_lineno
= emit_lineno
;
489 p
->goto_fixup_chain
= goto_fixup_chain
;
493 restore_stmt_status (p
)
496 block_stack
= p
->block_stack
;
497 stack_block_stack
= p
->stack_block_stack
;
498 cond_stack
= p
->cond_stack
;
499 loop_stack
= p
->loop_stack
;
500 case_stack
= p
->case_stack
;
501 nesting_stack
= p
->nesting_stack
;
502 nesting_depth
= p
->nesting_depth
;
503 block_start_count
= p
->block_start_count
;
504 last_expr_type
= p
->last_expr_type
;
505 last_expr_value
= p
->last_expr_value
;
506 expr_stmts_for_value
= p
->expr_stmts_for_value
;
507 emit_filename
= p
->emit_filename
;
508 emit_lineno
= p
->emit_lineno
;
509 goto_fixup_chain
= p
->goto_fixup_chain
;
512 /* Emit a no-op instruction. */
517 rtx last_insn
= get_last_insn ();
519 && (GET_CODE (last_insn
) == CODE_LABEL
520 || prev_real_insn (last_insn
) == 0))
521 emit_insn (gen_nop ());
524 /* Return the rtx-label that corresponds to a LABEL_DECL,
525 creating it if necessary. */
531 if (TREE_CODE (label
) != LABEL_DECL
)
534 if (DECL_RTL (label
))
535 return DECL_RTL (label
);
537 return DECL_RTL (label
) = gen_label_rtx ();
540 /* Add an unconditional jump to LABEL as the next sequential instruction. */
546 do_pending_stack_adjust ();
547 emit_jump_insn (gen_jump (label
));
551 /* Emit code to jump to the address
552 specified by the pointer expression EXP. */
555 expand_computed_goto (exp
)
558 rtx x
= expand_expr (exp
, NULL_RTX
, VOIDmode
, 0);
560 emit_indirect_jump (x
);
563 /* Handle goto statements and the labels that they can go to. */
565 /* Specify the location in the RTL code of a label LABEL,
566 which is a LABEL_DECL tree node.
568 This is used for the kind of label that the user can jump to with a
569 goto statement, and for alternatives of a switch or case statement.
570 RTL labels generated for loops and conditionals don't go through here;
571 they are generated directly at the RTL level, by other functions below.
573 Note that this has nothing to do with defining label *names*.
574 Languages vary in how they do that and what that even means. */
580 struct label_chain
*p
;
582 do_pending_stack_adjust ();
583 emit_label (label_rtx (label
));
584 if (DECL_NAME (label
))
585 LABEL_NAME (DECL_RTL (label
)) = IDENTIFIER_POINTER (DECL_NAME (label
));
587 if (stack_block_stack
!= 0)
589 p
= (struct label_chain
*) oballoc (sizeof (struct label_chain
));
590 p
->next
= stack_block_stack
->data
.block
.label_chain
;
591 stack_block_stack
->data
.block
.label_chain
= p
;
596 /* Declare that LABEL (a LABEL_DECL) may be used for nonlocal gotos
597 from nested functions. */
600 declare_nonlocal_label (label
)
603 nonlocal_labels
= tree_cons (NULL_TREE
, label
, nonlocal_labels
);
604 LABEL_PRESERVE_P (label_rtx (label
)) = 1;
605 if (nonlocal_goto_handler_slot
== 0)
607 nonlocal_goto_handler_slot
608 = assign_stack_local (Pmode
, GET_MODE_SIZE (Pmode
), 0);
609 emit_stack_save (SAVE_NONLOCAL
,
610 &nonlocal_goto_stack_level
,
611 PREV_INSN (tail_recursion_reentry
));
615 /* Generate RTL code for a `goto' statement with target label LABEL.
616 LABEL should be a LABEL_DECL tree node that was or will later be
617 defined with `expand_label'. */
623 /* Check for a nonlocal goto to a containing function. */
624 tree context
= decl_function_context (label
);
625 if (context
!= 0 && context
!= current_function_decl
)
627 struct function
*p
= find_function_data (context
);
628 rtx label_ref
= gen_rtx (LABEL_REF
, Pmode
, label_rtx (label
));
631 p
->has_nonlocal_label
= 1;
632 LABEL_REF_NONLOCAL_P (label_ref
) = 1;
634 /* Copy the rtl for the slots so that they won't be shared in
635 case the virtual stack vars register gets instantiated differently
636 in the parent than in the child. */
638 #if HAVE_nonlocal_goto
639 if (HAVE_nonlocal_goto
)
640 emit_insn (gen_nonlocal_goto (lookup_static_chain (label
),
641 copy_rtx (p
->nonlocal_goto_handler_slot
),
642 copy_rtx (p
->nonlocal_goto_stack_level
),
649 /* Restore frame pointer for containing function.
650 This sets the actual hard register used for the frame pointer
651 to the location of the function's incoming static chain info.
652 The non-local goto handler will then adjust it to contain the
653 proper value and reload the argument pointer, if needed. */
654 emit_move_insn (frame_pointer_rtx
, lookup_static_chain (label
));
656 /* We have now loaded the frame pointer hardware register with
657 the address of that corresponds to the start of the virtual
658 stack vars. So replace virtual_stack_vars_rtx in all
659 addresses we use with stack_pointer_rtx. */
661 /* Get addr of containing function's current nonlocal goto handler,
662 which will do any cleanups and then jump to the label. */
663 addr
= copy_rtx (p
->nonlocal_goto_handler_slot
);
664 temp
= copy_to_reg (replace_rtx (addr
, virtual_stack_vars_rtx
,
667 /* Restore the stack pointer. Note this uses fp just restored. */
668 addr
= p
->nonlocal_goto_stack_level
;
670 addr
= replace_rtx (copy_rtx (addr
),
671 virtual_stack_vars_rtx
, frame_pointer_rtx
);
673 emit_stack_restore (SAVE_NONLOCAL
, addr
, NULL_RTX
);
675 /* Put in the static chain register the nonlocal label address. */
676 emit_move_insn (static_chain_rtx
, label_ref
);
677 /* USE of frame_pointer_rtx added for consistency; not clear if
679 emit_insn (gen_rtx (USE
, VOIDmode
, frame_pointer_rtx
));
680 emit_insn (gen_rtx (USE
, VOIDmode
, stack_pointer_rtx
));
681 emit_insn (gen_rtx (USE
, VOIDmode
, static_chain_rtx
));
682 emit_indirect_jump (temp
);
686 expand_goto_internal (label
, label_rtx (label
), NULL_RTX
);
689 /* Generate RTL code for a `goto' statement with target label BODY.
690 LABEL should be a LABEL_REF.
691 LAST_INSN, if non-0, is the rtx we should consider as the last
692 insn emitted (for the purposes of cleaning up a return). */
695 expand_goto_internal (body
, label
, last_insn
)
700 struct nesting
*block
;
703 if (GET_CODE (label
) != CODE_LABEL
)
706 /* If label has already been defined, we can tell now
707 whether and how we must alter the stack level. */
709 if (PREV_INSN (label
) != 0)
711 /* Find the innermost pending block that contains the label.
712 (Check containment by comparing insn-uids.)
713 Then restore the outermost stack level within that block,
714 and do cleanups of all blocks contained in it. */
715 for (block
= block_stack
; block
; block
= block
->next
)
717 if (INSN_UID (block
->data
.block
.first_insn
) < INSN_UID (label
))
719 if (block
->data
.block
.stack_level
!= 0)
720 stack_level
= block
->data
.block
.stack_level
;
721 /* Execute the cleanups for blocks we are exiting. */
722 if (block
->data
.block
.cleanups
!= 0)
724 expand_cleanups (block
->data
.block
.cleanups
, NULL_TREE
);
725 do_pending_stack_adjust ();
731 /* Ensure stack adjust isn't done by emit_jump, as this would clobber
732 the stack pointer. This one should be deleted as dead by flow. */
733 clear_pending_stack_adjust ();
734 do_pending_stack_adjust ();
735 emit_stack_restore (SAVE_BLOCK
, stack_level
, NULL_RTX
);
738 if (body
!= 0 && DECL_TOO_LATE (body
))
739 error ("jump to `%s' invalidly jumps into binding contour",
740 IDENTIFIER_POINTER (DECL_NAME (body
)));
742 /* Label not yet defined: may need to put this goto
743 on the fixup list. */
744 else if (! expand_fixup (body
, label
, last_insn
))
746 /* No fixup needed. Record that the label is the target
747 of at least one goto that has no fixup. */
749 TREE_ADDRESSABLE (body
) = 1;
755 /* Generate if necessary a fixup for a goto
756 whose target label in tree structure (if any) is TREE_LABEL
757 and whose target in rtl is RTL_LABEL.
759 If LAST_INSN is nonzero, we pretend that the jump appears
760 after insn LAST_INSN instead of at the current point in the insn stream.
762 The fixup will be used later to insert insns just before the goto.
763 Those insns will restore the stack level as appropriate for the
764 target label, and will (in the case of C++) also invoke any object
765 destructors which have to be invoked when we exit the scopes which
766 are exited by the goto.
768 Value is nonzero if a fixup is made. */
771 expand_fixup (tree_label
, rtl_label
, last_insn
)
776 struct nesting
*block
, *end_block
;
778 /* See if we can recognize which block the label will be output in.
779 This is possible in some very common cases.
780 If we succeed, set END_BLOCK to that block.
781 Otherwise, set it to 0. */
784 && (rtl_label
== cond_stack
->data
.cond
.endif_label
785 || rtl_label
== cond_stack
->data
.cond
.next_label
))
786 end_block
= cond_stack
;
787 /* If we are in a loop, recognize certain labels which
788 are likely targets. This reduces the number of fixups
789 we need to create. */
791 && (rtl_label
== loop_stack
->data
.loop
.start_label
792 || rtl_label
== loop_stack
->data
.loop
.end_label
793 || rtl_label
== loop_stack
->data
.loop
.continue_label
))
794 end_block
= loop_stack
;
798 /* Now set END_BLOCK to the binding level to which we will return. */
802 struct nesting
*next_block
= end_block
->all
;
805 /* First see if the END_BLOCK is inside the innermost binding level.
806 If so, then no cleanups or stack levels are relevant. */
807 while (next_block
&& next_block
!= block
)
808 next_block
= next_block
->all
;
813 /* Otherwise, set END_BLOCK to the innermost binding level
814 which is outside the relevant control-structure nesting. */
815 next_block
= block_stack
->next
;
816 for (block
= block_stack
; block
!= end_block
; block
= block
->all
)
817 if (block
== next_block
)
818 next_block
= next_block
->next
;
819 end_block
= next_block
;
822 /* Does any containing block have a stack level or cleanups?
823 If not, no fixup is needed, and that is the normal case
824 (the only case, for standard C). */
825 for (block
= block_stack
; block
!= end_block
; block
= block
->next
)
826 if (block
->data
.block
.stack_level
!= 0
827 || block
->data
.block
.cleanups
!= 0)
830 if (block
!= end_block
)
832 /* Ok, a fixup is needed. Add a fixup to the list of such. */
833 struct goto_fixup
*fixup
834 = (struct goto_fixup
*) oballoc (sizeof (struct goto_fixup
));
835 /* In case an old stack level is restored, make sure that comes
836 after any pending stack adjust. */
837 /* ?? If the fixup isn't to come at the present position,
838 doing the stack adjust here isn't useful. Doing it with our
839 settings at that location isn't useful either. Let's hope
842 do_pending_stack_adjust ();
843 fixup
->target
= tree_label
;
844 fixup
->target_rtl
= rtl_label
;
846 /* Create a BLOCK node and a corresponding matched set of
847 NOTE_INSN_BEGIN_BLOCK and NOTE_INSN_END_BLOCK notes at
848 this point. The notes will encapsulate any and all fixup
849 code which we might later insert at this point in the insn
850 stream. Also, the BLOCK node will be the parent (i.e. the
851 `SUPERBLOCK') of any other BLOCK nodes which we might create
852 later on when we are expanding the fixup code. */
855 register rtx original_before_jump
856 = last_insn
? last_insn
: get_last_insn ();
860 fixup
->before_jump
= emit_note (NULL_PTR
, NOTE_INSN_BLOCK_BEG
);
861 last_block_end_note
= emit_note (NULL_PTR
, NOTE_INSN_BLOCK_END
);
862 fixup
->context
= poplevel (1, 0, 0); /* Create the BLOCK node now! */
864 emit_insns_after (fixup
->before_jump
, original_before_jump
);
867 fixup
->block_start_count
= block_start_count
;
868 fixup
->stack_level
= 0;
869 fixup
->cleanup_list_list
870 = (((block
->data
.block
.outer_cleanups
872 && block
->data
.block
.outer_cleanups
!= empty_cleanup_list
875 || block
->data
.block
.cleanups
)
876 ? tree_cons (NULL_TREE
, block
->data
.block
.cleanups
,
877 block
->data
.block
.outer_cleanups
)
879 fixup
->next
= goto_fixup_chain
;
880 goto_fixup_chain
= fixup
;
886 /* When exiting a binding contour, process all pending gotos requiring fixups.
887 THISBLOCK is the structure that describes the block being exited.
888 STACK_LEVEL is the rtx for the stack level to restore exiting this contour.
889 CLEANUP_LIST is a list of expressions to evaluate on exiting this contour.
890 FIRST_INSN is the insn that began this contour.
892 Gotos that jump out of this contour must restore the
893 stack level and do the cleanups before actually jumping.
895 DONT_JUMP_IN nonzero means report error there is a jump into this
896 contour from before the beginning of the contour.
897 This is also done if STACK_LEVEL is nonzero. */
900 fixup_gotos (thisblock
, stack_level
, cleanup_list
, first_insn
, dont_jump_in
)
901 struct nesting
*thisblock
;
907 register struct goto_fixup
*f
, *prev
;
909 /* F is the fixup we are considering; PREV is the previous one. */
910 /* We run this loop in two passes so that cleanups of exited blocks
911 are run first, and blocks that are exited are marked so
914 for (prev
= 0, f
= goto_fixup_chain
; f
; prev
= f
, f
= f
->next
)
916 /* Test for a fixup that is inactive because it is already handled. */
917 if (f
->before_jump
== 0)
919 /* Delete inactive fixup from the chain, if that is easy to do. */
921 prev
->next
= f
->next
;
923 /* Has this fixup's target label been defined?
924 If so, we can finalize it. */
925 else if (PREV_INSN (f
->target_rtl
) != 0)
927 register rtx cleanup_insns
;
929 /* Get the first non-label after the label
930 this goto jumps to. If that's before this scope begins,
931 we don't have a jump into the scope. */
932 rtx after_label
= f
->target_rtl
;
933 while (after_label
!= 0 && GET_CODE (after_label
) == CODE_LABEL
)
934 after_label
= NEXT_INSN (after_label
);
936 /* If this fixup jumped into this contour from before the beginning
937 of this contour, report an error. */
938 /* ??? Bug: this does not detect jumping in through intermediate
939 blocks that have stack levels or cleanups.
940 It detects only a problem with the innermost block
943 && (dont_jump_in
|| stack_level
|| cleanup_list
)
944 /* If AFTER_LABEL is 0, it means the jump goes to the end
945 of the rtl, which means it jumps into this scope. */
947 || INSN_UID (first_insn
) < INSN_UID (after_label
))
948 && INSN_UID (first_insn
) > INSN_UID (f
->before_jump
)
949 && ! DECL_REGISTER (f
->target
))
951 error_with_decl (f
->target
,
952 "label `%s' used before containing binding contour");
953 /* Prevent multiple errors for one label. */
954 DECL_REGISTER (f
->target
) = 1;
957 /* We will expand the cleanups into a sequence of their own and
958 then later on we will attach this new sequence to the insn
959 stream just ahead of the actual jump insn. */
963 /* Temporarily restore the lexical context where we will
964 logically be inserting the fixup code. We do this for the
965 sake of getting the debugging information right. */
968 set_block (f
->context
);
970 /* Expand the cleanups for blocks this jump exits. */
971 if (f
->cleanup_list_list
)
974 for (lists
= f
->cleanup_list_list
; lists
; lists
= TREE_CHAIN (lists
))
975 /* Marked elements correspond to blocks that have been closed.
976 Do their cleanups. */
977 if (TREE_ADDRESSABLE (lists
)
978 && TREE_VALUE (lists
) != 0)
980 expand_cleanups (TREE_VALUE (lists
), 0);
981 /* Pop any pushes done in the cleanups,
982 in case function is about to return. */
983 do_pending_stack_adjust ();
987 /* Restore stack level for the biggest contour that this
988 jump jumps out of. */
990 emit_stack_restore (SAVE_BLOCK
, f
->stack_level
, f
->before_jump
);
992 /* Finish up the sequence containing the insns which implement the
993 necessary cleanups, and then attach that whole sequence to the
994 insn stream just ahead of the actual jump insn. Attaching it
995 at that point insures that any cleanups which are in fact
996 implicit C++ object destructions (which must be executed upon
997 leaving the block) appear (to the debugger) to be taking place
998 in an area of the generated code where the object(s) being
999 destructed are still "in scope". */
1001 cleanup_insns
= get_insns ();
1005 emit_insns_after (cleanup_insns
, f
->before_jump
);
1012 /* Mark the cleanups of exited blocks so that they are executed
1013 by the code above. */
1014 for (prev
= 0, f
= goto_fixup_chain
; f
; prev
= f
, f
= f
->next
)
1015 if (f
->before_jump
!= 0
1016 && PREV_INSN (f
->target_rtl
) == 0
1017 /* Label has still not appeared. If we are exiting a block with
1018 a stack level to restore, that started before the fixup,
1019 mark this stack level as needing restoration
1020 when the fixup is later finalized.
1021 Also mark the cleanup_list_list element for F
1022 that corresponds to this block, so that ultimately
1023 this block's cleanups will be executed by the code above. */
1025 /* Note: if THISBLOCK == 0 and we have a label that hasn't appeared,
1026 it means the label is undefined. That's erroneous, but possible. */
1027 && (thisblock
->data
.block
.block_start_count
1028 <= f
->block_start_count
))
1030 tree lists
= f
->cleanup_list_list
;
1031 for (; lists
; lists
= TREE_CHAIN (lists
))
1032 /* If the following elt. corresponds to our containing block
1033 then the elt. must be for this block. */
1034 if (TREE_CHAIN (lists
) == thisblock
->data
.block
.outer_cleanups
)
1035 TREE_ADDRESSABLE (lists
) = 1;
1038 f
->stack_level
= stack_level
;
1042 /* Generate RTL for an asm statement (explicit assembler code).
1043 BODY is a STRING_CST node containing the assembler code text,
1044 or an ADDR_EXPR containing a STRING_CST. */
1050 if (TREE_CODE (body
) == ADDR_EXPR
)
1051 body
= TREE_OPERAND (body
, 0);
1053 emit_insn (gen_rtx (ASM_INPUT
, VOIDmode
,
1054 TREE_STRING_POINTER (body
)));
1058 /* Generate RTL for an asm statement with arguments.
1059 STRING is the instruction template.
1060 OUTPUTS is a list of output arguments (lvalues); INPUTS a list of inputs.
1061 Each output or input has an expression in the TREE_VALUE and
1062 a constraint-string in the TREE_PURPOSE.
1063 CLOBBERS is a list of STRING_CST nodes each naming a hard register
1064 that is clobbered by this insn.
1066 Not all kinds of lvalue that may appear in OUTPUTS can be stored directly.
1067 Some elements of OUTPUTS may be replaced with trees representing temporary
1068 values. The caller should copy those temporary values to the originally
1071 VOL nonzero means the insn is volatile; don't optimize it. */
1074 expand_asm_operands (string
, outputs
, inputs
, clobbers
, vol
, filename
, line
)
1075 tree string
, outputs
, inputs
, clobbers
;
1080 rtvec argvec
, constraints
;
1082 int ninputs
= list_length (inputs
);
1083 int noutputs
= list_length (outputs
);
1087 /* Vector of RTX's of evaluated output operands. */
1088 rtx
*output_rtx
= (rtx
*) alloca (noutputs
* sizeof (rtx
));
1089 /* The insn we have emitted. */
1092 /* Count the number of meaningful clobbered registers, ignoring what
1093 we would ignore later. */
1095 for (tail
= clobbers
; tail
; tail
= TREE_CHAIN (tail
))
1097 char *regname
= TREE_STRING_POINTER (TREE_VALUE (tail
));
1098 i
= decode_reg_name (regname
);
1099 if (i
>= 0 || i
== -4)
1105 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
1107 tree val
= TREE_VALUE (tail
);
1112 /* If there's an erroneous arg, emit no insn. */
1113 if (TREE_TYPE (val
) == error_mark_node
)
1116 /* Make sure constraint has `=' and does not have `+'. */
1119 for (j
= 0; j
< TREE_STRING_LENGTH (TREE_PURPOSE (tail
)); j
++)
1121 if (TREE_STRING_POINTER (TREE_PURPOSE (tail
))[j
] == '+')
1123 error ("output operand constraint contains `+'");
1126 if (TREE_STRING_POINTER (TREE_PURPOSE (tail
))[j
] == '=')
1131 error ("output operand constraint lacks `='");
1135 /* If an output operand is not a variable or indirect ref,
1137 create a SAVE_EXPR which is a pseudo-reg
1138 to act as an intermediate temporary.
1139 Make the asm insn write into that, then copy it to
1140 the real output operand. */
1142 while (TREE_CODE (val
) == COMPONENT_REF
1143 || TREE_CODE (val
) == ARRAY_REF
)
1144 val
= TREE_OPERAND (val
, 0);
1146 if (TREE_CODE (val
) != VAR_DECL
1147 && TREE_CODE (val
) != PARM_DECL
1148 && TREE_CODE (val
) != INDIRECT_REF
)
1149 TREE_VALUE (tail
) = save_expr (TREE_VALUE (tail
));
1151 output_rtx
[i
] = expand_expr (TREE_VALUE (tail
), NULL_RTX
, VOIDmode
, 0);
1154 if (ninputs
+ noutputs
> MAX_RECOG_OPERANDS
)
1156 error ("more than %d operands in `asm'", MAX_RECOG_OPERANDS
);
1160 /* Make vectors for the expression-rtx and constraint strings. */
1162 argvec
= rtvec_alloc (ninputs
);
1163 constraints
= rtvec_alloc (ninputs
);
1165 body
= gen_rtx (ASM_OPERANDS
, VOIDmode
,
1166 TREE_STRING_POINTER (string
), "", 0, argvec
, constraints
,
1168 MEM_VOLATILE_P (body
) = vol
;
1170 /* Eval the inputs and put them into ARGVEC.
1171 Put their constraints into ASM_INPUTs and store in CONSTRAINTS. */
1174 for (tail
= inputs
; tail
; tail
= TREE_CHAIN (tail
))
1178 /* If there's an erroneous arg, emit no insn,
1179 because the ASM_INPUT would get VOIDmode
1180 and that could cause a crash in reload. */
1181 if (TREE_TYPE (TREE_VALUE (tail
)) == error_mark_node
)
1183 if (TREE_PURPOSE (tail
) == NULL_TREE
)
1185 error ("hard register `%s' listed as input operand to `asm'",
1186 TREE_STRING_POINTER (TREE_VALUE (tail
)) );
1190 /* Make sure constraint has neither `=' nor `+'. */
1192 for (j
= 0; j
< TREE_STRING_LENGTH (TREE_PURPOSE (tail
)); j
++)
1193 if (TREE_STRING_POINTER (TREE_PURPOSE (tail
))[j
] == '='
1194 || TREE_STRING_POINTER (TREE_PURPOSE (tail
))[j
] == '+')
1196 error ("input operand constraint contains `%c'",
1197 TREE_STRING_POINTER (TREE_PURPOSE (tail
))[j
]);
1201 XVECEXP (body
, 3, i
) /* argvec */
1202 = expand_expr (TREE_VALUE (tail
), NULL_RTX
, VOIDmode
, 0);
1203 XVECEXP (body
, 4, i
) /* constraints */
1204 = gen_rtx (ASM_INPUT
, TYPE_MODE (TREE_TYPE (TREE_VALUE (tail
))),
1205 TREE_STRING_POINTER (TREE_PURPOSE (tail
)));
1209 /* Protect all the operands from the queue,
1210 now that they have all been evaluated. */
1212 for (i
= 0; i
< ninputs
; i
++)
1213 XVECEXP (body
, 3, i
) = protect_from_queue (XVECEXP (body
, 3, i
), 0);
1215 for (i
= 0; i
< noutputs
; i
++)
1216 output_rtx
[i
] = protect_from_queue (output_rtx
[i
], 1);
1218 /* Now, for each output, construct an rtx
1219 (set OUTPUT (asm_operands INSN OUTPUTNUMBER OUTPUTCONSTRAINT
1220 ARGVEC CONSTRAINTS))
1221 If there is more than one, put them inside a PARALLEL. */
1223 if (noutputs
== 1 && nclobbers
== 0)
1225 XSTR (body
, 1) = TREE_STRING_POINTER (TREE_PURPOSE (outputs
));
1226 insn
= emit_insn (gen_rtx (SET
, VOIDmode
, output_rtx
[0], body
));
1228 else if (noutputs
== 0 && nclobbers
== 0)
1230 /* No output operands: put in a raw ASM_OPERANDS rtx. */
1231 insn
= emit_insn (body
);
1237 if (num
== 0) num
= 1;
1238 body
= gen_rtx (PARALLEL
, VOIDmode
, rtvec_alloc (num
+ nclobbers
));
1240 /* For each output operand, store a SET. */
1242 for (i
= 0, tail
= outputs
; tail
; tail
= TREE_CHAIN (tail
), i
++)
1244 XVECEXP (body
, 0, i
)
1245 = gen_rtx (SET
, VOIDmode
,
1247 gen_rtx (ASM_OPERANDS
, VOIDmode
,
1248 TREE_STRING_POINTER (string
),
1249 TREE_STRING_POINTER (TREE_PURPOSE (tail
)),
1250 i
, argvec
, constraints
,
1252 MEM_VOLATILE_P (SET_SRC (XVECEXP (body
, 0, i
))) = vol
;
1255 /* If there are no outputs (but there are some clobbers)
1256 store the bare ASM_OPERANDS into the PARALLEL. */
1259 XVECEXP (body
, 0, i
++) = obody
;
1261 /* Store (clobber REG) for each clobbered register specified. */
1263 for (tail
= clobbers
; tail
; tail
= TREE_CHAIN (tail
))
1265 char *regname
= TREE_STRING_POINTER (TREE_VALUE (tail
));
1266 int j
= decode_reg_name (regname
);
1270 if (j
== -3) /* `cc', which is not a register */
1273 if (j
== -4) /* `memory', don't cache memory across asm */
1275 XVECEXP (body
, 0, i
++)
1276 = gen_rtx (CLOBBER
, VOIDmode
,
1277 gen_rtx (MEM
, QImode
,
1278 gen_rtx (SCRATCH
, VOIDmode
, 0)));
1282 error ("unknown register name `%s' in `asm'", regname
);
1286 /* Use QImode since that's guaranteed to clobber just one reg. */
1287 XVECEXP (body
, 0, i
++)
1288 = gen_rtx (CLOBBER
, VOIDmode
, gen_rtx (REG
, QImode
, j
));
1291 insn
= emit_insn (body
);
1297 /* Generate RTL to evaluate the expression EXP
1298 and remember it in case this is the VALUE in a ({... VALUE; }) constr. */
1301 expand_expr_stmt (exp
)
1304 /* If -W, warn about statements with no side effects,
1305 except for an explicit cast to void (e.g. for assert()), and
1306 except inside a ({...}) where they may be useful. */
1307 if (expr_stmts_for_value
== 0 && exp
!= error_mark_node
)
1309 if (! TREE_SIDE_EFFECTS (exp
) && (extra_warnings
|| warn_unused
)
1310 && !(TREE_CODE (exp
) == CONVERT_EXPR
1311 && TREE_TYPE (exp
) == void_type_node
))
1312 warning_with_file_and_line (emit_filename
, emit_lineno
,
1313 "statement with no effect");
1314 else if (warn_unused
)
1315 warn_if_unused_value (exp
);
1317 last_expr_type
= TREE_TYPE (exp
);
1318 if (! flag_syntax_only
)
1319 last_expr_value
= expand_expr (exp
,
1320 (expr_stmts_for_value
1321 ? NULL_RTX
: const0_rtx
),
1324 /* If all we do is reference a volatile value in memory,
1325 copy it to a register to be sure it is actually touched. */
1326 if (last_expr_value
!= 0 && GET_CODE (last_expr_value
) == MEM
1327 && TREE_THIS_VOLATILE (exp
))
1329 if (TYPE_MODE (TREE_TYPE (exp
)) != BLKmode
)
1330 copy_to_reg (last_expr_value
);
1333 rtx lab
= gen_label_rtx ();
1335 /* Compare the value with itself to reference it. */
1336 emit_cmp_insn (last_expr_value
, last_expr_value
, EQ
,
1337 expand_expr (TYPE_SIZE (last_expr_type
),
1338 NULL_RTX
, VOIDmode
, 0),
1340 TYPE_ALIGN (last_expr_type
) / BITS_PER_UNIT
);
1341 emit_jump_insn ((*bcc_gen_fctn
[(int) EQ
]) (lab
));
1346 /* If this expression is part of a ({...}) and is in memory, we may have
1347 to preserve temporaries. */
1348 preserve_temp_slots (last_expr_value
);
1350 /* Free any temporaries used to evaluate this expression. Any temporary
1351 used as a result of this expression will already have been preserved
1358 /* Warn if EXP contains any computations whose results are not used.
1359 Return 1 if a warning is printed; 0 otherwise. */
1362 warn_if_unused_value (exp
)
1365 if (TREE_USED (exp
))
1368 switch (TREE_CODE (exp
))
1370 case PREINCREMENT_EXPR
:
1371 case POSTINCREMENT_EXPR
:
1372 case PREDECREMENT_EXPR
:
1373 case POSTDECREMENT_EXPR
:
1378 case METHOD_CALL_EXPR
:
1380 case WITH_CLEANUP_EXPR
:
1382 /* We don't warn about COND_EXPR because it may be a useful
1383 construct if either arm contains a side effect. */
1388 /* For a binding, warn if no side effect within it. */
1389 return warn_if_unused_value (TREE_OPERAND (exp
, 1));
1391 case TRUTH_ORIF_EXPR
:
1392 case TRUTH_ANDIF_EXPR
:
1393 /* In && or ||, warn if 2nd operand has no side effect. */
1394 return warn_if_unused_value (TREE_OPERAND (exp
, 1));
1397 if (warn_if_unused_value (TREE_OPERAND (exp
, 0)))
1399 /* Let people do `(foo (), 0)' without a warning. */
1400 if (TREE_CONSTANT (TREE_OPERAND (exp
, 1)))
1402 return warn_if_unused_value (TREE_OPERAND (exp
, 1));
1406 case NON_LVALUE_EXPR
:
1407 /* Don't warn about values cast to void. */
1408 if (TREE_TYPE (exp
) == void_type_node
)
1410 /* Don't warn about conversions not explicit in the user's program. */
1411 if (TREE_NO_UNUSED_WARNING (exp
))
1413 /* Assignment to a cast usually results in a cast of a modify.
1414 Don't complain about that. */
1415 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == MODIFY_EXPR
)
1417 /* Sometimes it results in a cast of a cast of a modify.
1418 Don't complain about that. */
1419 if ((TREE_CODE (TREE_OPERAND (exp
, 0)) == CONVERT_EXPR
1420 || TREE_CODE (TREE_OPERAND (exp
, 0)) == NOP_EXPR
)
1421 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0)) == MODIFY_EXPR
)
1425 /* Referencing a volatile value is a side effect, so don't warn. */
1426 if ((TREE_CODE_CLASS (TREE_CODE (exp
)) == 'd'
1427 || TREE_CODE_CLASS (TREE_CODE (exp
)) == 'r')
1428 && TREE_THIS_VOLATILE (exp
))
1430 warning_with_file_and_line (emit_filename
, emit_lineno
,
1431 "value computed is not used");
1436 /* Clear out the memory of the last expression evaluated. */
1444 /* Begin a statement which will return a value.
1445 Return the RTL_EXPR for this statement expr.
1446 The caller must save that value and pass it to expand_end_stmt_expr. */
1449 expand_start_stmt_expr ()
1451 /* Make the RTL_EXPR node temporary, not momentary,
1452 so that rtl_expr_chain doesn't become garbage. */
1453 int momentary
= suspend_momentary ();
1454 tree t
= make_node (RTL_EXPR
);
1455 resume_momentary (momentary
);
1458 expr_stmts_for_value
++;
1462 /* Restore the previous state at the end of a statement that returns a value.
1463 Returns a tree node representing the statement's value and the
1464 insns to compute the value.
1466 The nodes of that expression have been freed by now, so we cannot use them.
1467 But we don't want to do that anyway; the expression has already been
1468 evaluated and now we just want to use the value. So generate a RTL_EXPR
1469 with the proper type and RTL value.
1471 If the last substatement was not an expression,
1472 return something with type `void'. */
1475 expand_end_stmt_expr (t
)
1480 if (last_expr_type
== 0)
1482 last_expr_type
= void_type_node
;
1483 last_expr_value
= const0_rtx
;
1485 else if (last_expr_value
== 0)
1486 /* There are some cases where this can happen, such as when the
1487 statement is void type. */
1488 last_expr_value
= const0_rtx
;
1489 else if (GET_CODE (last_expr_value
) != REG
&& ! CONSTANT_P (last_expr_value
))
1490 /* Remove any possible QUEUED. */
1491 last_expr_value
= protect_from_queue (last_expr_value
, 0);
1495 TREE_TYPE (t
) = last_expr_type
;
1496 RTL_EXPR_RTL (t
) = last_expr_value
;
1497 RTL_EXPR_SEQUENCE (t
) = get_insns ();
1499 rtl_expr_chain
= tree_cons (NULL_TREE
, t
, rtl_expr_chain
);
1503 /* Don't consider deleting this expr or containing exprs at tree level. */
1504 TREE_SIDE_EFFECTS (t
) = 1;
1505 /* Propagate volatility of the actual RTL expr. */
1506 TREE_THIS_VOLATILE (t
) = volatile_refs_p (last_expr_value
);
1509 expr_stmts_for_value
--;
1514 /* The exception handling nesting looks like this:
1517 { <-- exception handler block
1519 <-- in an exception handler
1521 : <-- in a TRY block
1522 : <-- in an exception handler
1527 : <-- in an except block
1528 : <-- in an exception handler
1535 /* Return nonzero iff in a try block at level LEVEL. */
1538 in_try_block (level
)
1541 struct nesting
*n
= except_stack
;
1544 while (n
&& n
->data
.except_stmt
.after_label
!= 0)
1555 /* Return nonzero iff in an except block at level LEVEL. */
1558 in_except_block (level
)
1561 struct nesting
*n
= except_stack
;
1564 while (n
&& n
->data
.except_stmt
.after_label
== 0)
1575 /* Return nonzero iff in an exception handler at level LEVEL. */
1578 in_exception_handler (level
)
1581 struct nesting
*n
= except_stack
;
1582 while (n
&& level
--)
1587 /* Record the fact that the current exception nesting raises
1588 exception EX. If not in an exception handler, return 0. */
1595 if (except_stack
== 0)
1597 raises_ptr
= &except_stack
->data
.except_stmt
.raised
;
1598 if (! value_member (ex
, *raises_ptr
))
1599 *raises_ptr
= tree_cons (NULL_TREE
, ex
, *raises_ptr
);
1603 /* Generate RTL for the start of a try block.
1605 TRY_CLAUSE is the condition to test to enter the try block. */
1608 expand_start_try (try_clause
, exitflag
, escapeflag
)
1613 struct nesting
*thishandler
= ALLOC_NESTING ();
1615 /* Make an entry on cond_stack for the cond we are entering. */
1617 thishandler
->next
= except_stack
;
1618 thishandler
->all
= nesting_stack
;
1619 thishandler
->depth
= ++nesting_depth
;
1620 thishandler
->data
.except_stmt
.raised
= 0;
1621 thishandler
->data
.except_stmt
.handled
= 0;
1622 thishandler
->data
.except_stmt
.first_insn
= get_insns ();
1623 thishandler
->data
.except_stmt
.except_label
= gen_label_rtx ();
1624 thishandler
->data
.except_stmt
.unhandled_label
= 0;
1625 thishandler
->data
.except_stmt
.after_label
= 0;
1626 thishandler
->data
.except_stmt
.escape_label
1627 = escapeflag
? thishandler
->data
.except_stmt
.except_label
: 0;
1628 thishandler
->exit_label
= exitflag
? gen_label_rtx () : 0;
1629 except_stack
= thishandler
;
1630 nesting_stack
= thishandler
;
1632 do_jump (try_clause
, thishandler
->data
.except_stmt
.except_label
, NULL_RTX
);
1635 /* End of a TRY block. Nothing to do for now. */
1640 except_stack
->data
.except_stmt
.after_label
= gen_label_rtx ();
1641 expand_goto_internal (NULL_TREE
, except_stack
->data
.except_stmt
.after_label
,
1645 /* Start an `except' nesting contour.
1646 EXITFLAG says whether this contour should be able to `exit' something.
1647 ESCAPEFLAG says whether this contour should be escapable. */
1650 expand_start_except (exitflag
, escapeflag
)
1657 /* An `exit' from catch clauses goes out to next exit level,
1658 if there is one. Otherwise, it just goes to the end
1659 of the construct. */
1660 for (n
= except_stack
->next
; n
; n
= n
->next
)
1661 if (n
->exit_label
!= 0)
1663 except_stack
->exit_label
= n
->exit_label
;
1667 except_stack
->exit_label
= except_stack
->data
.except_stmt
.after_label
;
1672 /* An `escape' from catch clauses goes out to next escape level,
1673 if there is one. Otherwise, it just goes to the end
1674 of the construct. */
1675 for (n
= except_stack
->next
; n
; n
= n
->next
)
1676 if (n
->data
.except_stmt
.escape_label
!= 0)
1678 except_stack
->data
.except_stmt
.escape_label
1679 = n
->data
.except_stmt
.escape_label
;
1683 except_stack
->data
.except_stmt
.escape_label
1684 = except_stack
->data
.except_stmt
.after_label
;
1686 do_pending_stack_adjust ();
1687 emit_label (except_stack
->data
.except_stmt
.except_label
);
1690 /* Generate code to `escape' from an exception contour. This
1691 is like `exiting', but does not conflict with constructs which
1694 Return nonzero if this contour is escapable, otherwise
1695 return zero, and language-specific code will emit the
1696 appropriate error message. */
1698 expand_escape_except ()
1702 for (n
= except_stack
; n
; n
= n
->next
)
1703 if (n
->data
.except_stmt
.escape_label
!= 0)
1705 expand_goto_internal (NULL_TREE
,
1706 n
->data
.except_stmt
.escape_label
, NULL_RTX
);
1713 /* Finish processing and `except' contour.
1714 Culls out all exceptions which might be raise but not
1715 handled, and returns the list to the caller.
1716 Language-specific code is responsible for dealing with these
1720 expand_end_except ()
1723 tree raised
= NULL_TREE
;
1725 do_pending_stack_adjust ();
1726 emit_label (except_stack
->data
.except_stmt
.after_label
);
1728 n
= except_stack
->next
;
1731 /* Propagate exceptions raised but not handled to next
1733 tree handled
= except_stack
->data
.except_stmt
.raised
;
1734 if (handled
!= void_type_node
)
1736 tree prev
= NULL_TREE
;
1737 raised
= except_stack
->data
.except_stmt
.raised
;
1741 for (this_raise
= raised
, prev
= 0; this_raise
;
1742 this_raise
= TREE_CHAIN (this_raise
))
1744 if (value_member (TREE_VALUE (this_raise
), handled
))
1747 TREE_CHAIN (prev
) = TREE_CHAIN (this_raise
);
1750 raised
= TREE_CHAIN (raised
);
1751 if (raised
== NULL_TREE
)
1758 handled
= TREE_CHAIN (handled
);
1760 if (prev
== NULL_TREE
)
1763 TREE_CHAIN (prev
) = n
->data
.except_stmt
.raised
;
1765 n
->data
.except_stmt
.raised
= raised
;
1769 POPSTACK (except_stack
);
1774 /* Record that exception EX is caught by this exception handler.
1775 Return nonzero if in exception handling construct, otherwise return 0. */
1782 if (except_stack
== 0)
1784 raises_ptr
= &except_stack
->data
.except_stmt
.handled
;
1785 if (*raises_ptr
!= void_type_node
1787 && ! value_member (ex
, *raises_ptr
))
1788 *raises_ptr
= tree_cons (NULL_TREE
, ex
, *raises_ptr
);
1792 /* Record that this exception handler catches all exceptions.
1793 Return nonzero if in exception handling construct, otherwise return 0. */
1796 expand_catch_default ()
1798 if (except_stack
== 0)
1800 except_stack
->data
.except_stmt
.handled
= void_type_node
;
1807 if (except_stack
== 0 || except_stack
->data
.except_stmt
.after_label
== 0)
1809 expand_goto_internal (NULL_TREE
, except_stack
->data
.except_stmt
.after_label
,
1814 /* Generate RTL for the start of an if-then. COND is the expression
1815 whose truth should be tested.
1817 If EXITFLAG is nonzero, this conditional is visible to
1818 `exit_something'. */
1821 expand_start_cond (cond
, exitflag
)
1825 struct nesting
*thiscond
= ALLOC_NESTING ();
1827 /* Make an entry on cond_stack for the cond we are entering. */
1829 thiscond
->next
= cond_stack
;
1830 thiscond
->all
= nesting_stack
;
1831 thiscond
->depth
= ++nesting_depth
;
1832 thiscond
->data
.cond
.next_label
= gen_label_rtx ();
1833 /* Before we encounter an `else', we don't need a separate exit label
1834 unless there are supposed to be exit statements
1835 to exit this conditional. */
1836 thiscond
->exit_label
= exitflag
? gen_label_rtx () : 0;
1837 thiscond
->data
.cond
.endif_label
= thiscond
->exit_label
;
1838 cond_stack
= thiscond
;
1839 nesting_stack
= thiscond
;
1841 do_jump (cond
, thiscond
->data
.cond
.next_label
, NULL_RTX
);
1844 /* Generate RTL between then-clause and the elseif-clause
1845 of an if-then-elseif-.... */
1848 expand_start_elseif (cond
)
1851 if (cond_stack
->data
.cond
.endif_label
== 0)
1852 cond_stack
->data
.cond
.endif_label
= gen_label_rtx ();
1853 emit_jump (cond_stack
->data
.cond
.endif_label
);
1854 emit_label (cond_stack
->data
.cond
.next_label
);
1855 cond_stack
->data
.cond
.next_label
= gen_label_rtx ();
1856 do_jump (cond
, cond_stack
->data
.cond
.next_label
, NULL_RTX
);
1859 /* Generate RTL between the then-clause and the else-clause
1860 of an if-then-else. */
1863 expand_start_else ()
1865 if (cond_stack
->data
.cond
.endif_label
== 0)
1866 cond_stack
->data
.cond
.endif_label
= gen_label_rtx ();
1867 emit_jump (cond_stack
->data
.cond
.endif_label
);
1868 emit_label (cond_stack
->data
.cond
.next_label
);
1869 cond_stack
->data
.cond
.next_label
= 0; /* No more _else or _elseif calls. */
1872 /* Generate RTL for the end of an if-then.
1873 Pop the record for it off of cond_stack. */
1878 struct nesting
*thiscond
= cond_stack
;
1880 do_pending_stack_adjust ();
1881 if (thiscond
->data
.cond
.next_label
)
1882 emit_label (thiscond
->data
.cond
.next_label
);
1883 if (thiscond
->data
.cond
.endif_label
)
1884 emit_label (thiscond
->data
.cond
.endif_label
);
1886 POPSTACK (cond_stack
);
1890 /* Generate RTL for the start of a loop. EXIT_FLAG is nonzero if this
1891 loop should be exited by `exit_something'. This is a loop for which
1892 `expand_continue' will jump to the top of the loop.
1894 Make an entry on loop_stack to record the labels associated with
1898 expand_start_loop (exit_flag
)
1901 register struct nesting
*thisloop
= ALLOC_NESTING ();
1903 /* Make an entry on loop_stack for the loop we are entering. */
1905 thisloop
->next
= loop_stack
;
1906 thisloop
->all
= nesting_stack
;
1907 thisloop
->depth
= ++nesting_depth
;
1908 thisloop
->data
.loop
.start_label
= gen_label_rtx ();
1909 thisloop
->data
.loop
.end_label
= gen_label_rtx ();
1910 thisloop
->data
.loop
.continue_label
= thisloop
->data
.loop
.start_label
;
1911 thisloop
->exit_label
= exit_flag
? thisloop
->data
.loop
.end_label
: 0;
1912 loop_stack
= thisloop
;
1913 nesting_stack
= thisloop
;
1915 do_pending_stack_adjust ();
1917 emit_note (NULL_PTR
, NOTE_INSN_LOOP_BEG
);
1918 emit_label (thisloop
->data
.loop
.start_label
);
1923 /* Like expand_start_loop but for a loop where the continuation point
1924 (for expand_continue_loop) will be specified explicitly. */
1927 expand_start_loop_continue_elsewhere (exit_flag
)
1930 struct nesting
*thisloop
= expand_start_loop (exit_flag
);
1931 loop_stack
->data
.loop
.continue_label
= gen_label_rtx ();
1935 /* Specify the continuation point for a loop started with
1936 expand_start_loop_continue_elsewhere.
1937 Use this at the point in the code to which a continue statement
1941 expand_loop_continue_here ()
1943 do_pending_stack_adjust ();
1944 emit_note (NULL_PTR
, NOTE_INSN_LOOP_CONT
);
1945 emit_label (loop_stack
->data
.loop
.continue_label
);
1948 /* Finish a loop. Generate a jump back to the top and the loop-exit label.
1949 Pop the block off of loop_stack. */
1954 register rtx insn
= get_last_insn ();
1955 register rtx start_label
= loop_stack
->data
.loop
.start_label
;
1956 rtx last_test_insn
= 0;
1959 /* Mark the continue-point at the top of the loop if none elsewhere. */
1960 if (start_label
== loop_stack
->data
.loop
.continue_label
)
1961 emit_note_before (NOTE_INSN_LOOP_CONT
, start_label
);
1963 do_pending_stack_adjust ();
1965 /* If optimizing, perhaps reorder the loop. If the loop
1966 starts with a conditional exit, roll that to the end
1967 where it will optimize together with the jump back.
1969 We look for the last conditional branch to the exit that we encounter
1970 before hitting 30 insns or a CALL_INSN. If we see an unconditional
1971 branch to the exit first, use it.
1973 We must also stop at NOTE_INSN_BLOCK_BEG and NOTE_INSN_BLOCK_END notes
1974 because moving them is not valid. */
1978 ! (GET_CODE (insn
) == JUMP_INSN
1979 && GET_CODE (PATTERN (insn
)) == SET
1980 && SET_DEST (PATTERN (insn
)) == pc_rtx
1981 && GET_CODE (SET_SRC (PATTERN (insn
))) == IF_THEN_ELSE
))
1983 /* Scan insns from the top of the loop looking for a qualified
1984 conditional exit. */
1985 for (insn
= NEXT_INSN (loop_stack
->data
.loop
.start_label
); insn
;
1986 insn
= NEXT_INSN (insn
))
1988 if (GET_CODE (insn
) == CALL_INSN
|| GET_CODE (insn
) == CODE_LABEL
)
1991 if (GET_CODE (insn
) == NOTE
1992 && (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_BEG
1993 || NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_END
))
1996 if (GET_CODE (insn
) == JUMP_INSN
|| GET_CODE (insn
) == INSN
)
1999 if (last_test_insn
&& num_insns
> 30)
2002 if (GET_CODE (insn
) == JUMP_INSN
&& GET_CODE (PATTERN (insn
)) == SET
2003 && SET_DEST (PATTERN (insn
)) == pc_rtx
2004 && GET_CODE (SET_SRC (PATTERN (insn
))) == IF_THEN_ELSE
2005 && ((GET_CODE (XEXP (SET_SRC (PATTERN (insn
)), 1)) == LABEL_REF
2006 && (XEXP (XEXP (SET_SRC (PATTERN (insn
)), 1), 0)
2007 == loop_stack
->data
.loop
.end_label
))
2008 || (GET_CODE (XEXP (SET_SRC (PATTERN (insn
)), 2)) == LABEL_REF
2009 && (XEXP (XEXP (SET_SRC (PATTERN (insn
)), 2), 0)
2010 == loop_stack
->data
.loop
.end_label
))))
2011 last_test_insn
= insn
;
2013 if (last_test_insn
== 0 && GET_CODE (insn
) == JUMP_INSN
2014 && GET_CODE (PATTERN (insn
)) == SET
2015 && SET_DEST (PATTERN (insn
)) == pc_rtx
2016 && GET_CODE (SET_SRC (PATTERN (insn
))) == LABEL_REF
2017 && (XEXP (SET_SRC (PATTERN (insn
)), 0)
2018 == loop_stack
->data
.loop
.end_label
))
2019 /* Include BARRIER. */
2020 last_test_insn
= NEXT_INSN (insn
);
2023 if (last_test_insn
!= 0 && last_test_insn
!= get_last_insn ())
2025 /* We found one. Move everything from there up
2026 to the end of the loop, and add a jump into the loop
2027 to jump to there. */
2028 register rtx newstart_label
= gen_label_rtx ();
2029 register rtx start_move
= start_label
;
2031 /* If the start label is preceded by a NOTE_INSN_LOOP_CONT note,
2032 then we want to move this note also. */
2033 if (GET_CODE (PREV_INSN (start_move
)) == NOTE
2034 && (NOTE_LINE_NUMBER (PREV_INSN (start_move
))
2035 == NOTE_INSN_LOOP_CONT
))
2036 start_move
= PREV_INSN (start_move
);
2038 emit_label_after (newstart_label
, PREV_INSN (start_move
));
2039 reorder_insns (start_move
, last_test_insn
, get_last_insn ());
2040 emit_jump_insn_after (gen_jump (start_label
),
2041 PREV_INSN (newstart_label
));
2042 emit_barrier_after (PREV_INSN (newstart_label
));
2043 start_label
= newstart_label
;
2047 emit_jump (start_label
);
2048 emit_note (NULL_PTR
, NOTE_INSN_LOOP_END
);
2049 emit_label (loop_stack
->data
.loop
.end_label
);
2051 POPSTACK (loop_stack
);
2056 /* Generate a jump to the current loop's continue-point.
2057 This is usually the top of the loop, but may be specified
2058 explicitly elsewhere. If not currently inside a loop,
2059 return 0 and do nothing; caller will print an error message. */
2062 expand_continue_loop (whichloop
)
2063 struct nesting
*whichloop
;
2067 whichloop
= loop_stack
;
2070 expand_goto_internal (NULL_TREE
, whichloop
->data
.loop
.continue_label
,
2075 /* Generate a jump to exit the current loop. If not currently inside a loop,
2076 return 0 and do nothing; caller will print an error message. */
2079 expand_exit_loop (whichloop
)
2080 struct nesting
*whichloop
;
2084 whichloop
= loop_stack
;
2087 expand_goto_internal (NULL_TREE
, whichloop
->data
.loop
.end_label
, NULL_RTX
);
2091 /* Generate a conditional jump to exit the current loop if COND
2092 evaluates to zero. If not currently inside a loop,
2093 return 0 and do nothing; caller will print an error message. */
2096 expand_exit_loop_if_false (whichloop
, cond
)
2097 struct nesting
*whichloop
;
2102 whichloop
= loop_stack
;
2105 do_jump (cond
, whichloop
->data
.loop
.end_label
, NULL_RTX
);
2109 /* Return non-zero if we should preserve sub-expressions as separate
2110 pseudos. We never do so if we aren't optimizing. We always do so
2111 if -fexpensive-optimizations.
2113 Otherwise, we only do so if we are in the "early" part of a loop. I.e.,
2114 the loop may still be a small one. */
2117 preserve_subexpressions_p ()
2121 if (flag_expensive_optimizations
)
2124 if (optimize
== 0 || loop_stack
== 0)
2127 insn
= get_last_insn_anywhere ();
2130 && (INSN_UID (insn
) - INSN_UID (loop_stack
->data
.loop
.start_label
)
2131 < n_non_fixed_regs
* 3));
2135 /* Generate a jump to exit the current loop, conditional, binding contour
2136 or case statement. Not all such constructs are visible to this function,
2137 only those started with EXIT_FLAG nonzero. Individual languages use
2138 the EXIT_FLAG parameter to control which kinds of constructs you can
2141 If not currently inside anything that can be exited,
2142 return 0 and do nothing; caller will print an error message. */
2145 expand_exit_something ()
2149 for (n
= nesting_stack
; n
; n
= n
->all
)
2150 if (n
->exit_label
!= 0)
2152 expand_goto_internal (NULL_TREE
, n
->exit_label
, NULL_RTX
);
2159 /* Generate RTL to return from the current function, with no value.
2160 (That is, we do not do anything about returning any value.) */
2163 expand_null_return ()
2165 struct nesting
*block
= block_stack
;
2168 /* Does any pending block have cleanups? */
2170 while (block
&& block
->data
.block
.cleanups
== 0)
2171 block
= block
->next
;
2173 /* If yes, use a goto to return, since that runs cleanups. */
2175 expand_null_return_1 (last_insn
, block
!= 0);
2178 /* Generate RTL to return from the current function, with value VAL. */
2181 expand_value_return (val
)
2184 struct nesting
*block
= block_stack
;
2185 rtx last_insn
= get_last_insn ();
2186 rtx return_reg
= DECL_RTL (DECL_RESULT (current_function_decl
));
2188 /* Copy the value to the return location
2189 unless it's already there. */
2191 if (return_reg
!= val
)
2193 #ifdef PROMOTE_FUNCTION_RETURN
2194 enum machine_mode mode
= DECL_MODE (DECL_RESULT (current_function_decl
));
2195 tree type
= TREE_TYPE (DECL_RESULT (current_function_decl
));
2196 int unsignedp
= TREE_UNSIGNED (type
);
2198 if (TREE_CODE (type
) == INTEGER_TYPE
|| TREE_CODE (type
) == ENUMERAL_TYPE
2199 || TREE_CODE (type
) == BOOLEAN_TYPE
|| TREE_CODE (type
) == CHAR_TYPE
2200 || TREE_CODE (type
) == REAL_TYPE
|| TREE_CODE (type
) == POINTER_TYPE
2201 || TREE_CODE (type
) == OFFSET_TYPE
)
2203 PROMOTE_MODE (mode
, unsignedp
, type
);
2206 if (GET_MODE (val
) != VOIDmode
&& GET_MODE (val
) != mode
)
2207 convert_to_mode (return_reg
, val
, unsignedp
);
2210 emit_move_insn (return_reg
, val
);
2212 if (GET_CODE (return_reg
) == REG
2213 && REGNO (return_reg
) < FIRST_PSEUDO_REGISTER
)
2214 emit_insn (gen_rtx (USE
, VOIDmode
, return_reg
));
2216 /* Does any pending block have cleanups? */
2218 while (block
&& block
->data
.block
.cleanups
== 0)
2219 block
= block
->next
;
2221 /* If yes, use a goto to return, since that runs cleanups.
2222 Use LAST_INSN to put cleanups *before* the move insn emitted above. */
2224 expand_null_return_1 (last_insn
, block
!= 0);
2227 /* Output a return with no value. If LAST_INSN is nonzero,
2228 pretend that the return takes place after LAST_INSN.
2229 If USE_GOTO is nonzero then don't use a return instruction;
2230 go to the return label instead. This causes any cleanups
2231 of pending blocks to be executed normally. */
2234 expand_null_return_1 (last_insn
, use_goto
)
2238 rtx end_label
= cleanup_label
? cleanup_label
: return_label
;
2240 clear_pending_stack_adjust ();
2241 do_pending_stack_adjust ();
2244 /* PCC-struct return always uses an epilogue. */
2245 if (current_function_returns_pcc_struct
|| use_goto
)
2248 end_label
= return_label
= gen_label_rtx ();
2249 expand_goto_internal (NULL_TREE
, end_label
, last_insn
);
2253 /* Otherwise output a simple return-insn if one is available,
2254 unless it won't do the job. */
2256 if (HAVE_return
&& use_goto
== 0 && cleanup_label
== 0)
2258 emit_jump_insn (gen_return ());
2264 /* Otherwise jump to the epilogue. */
2265 expand_goto_internal (NULL_TREE
, end_label
, last_insn
);
2268 /* Generate RTL to evaluate the expression RETVAL and return it
2269 from the current function. */
2272 expand_return (retval
)
2275 /* If there are any cleanups to be performed, then they will
2276 be inserted following LAST_INSN. It is desirable
2277 that the last_insn, for such purposes, should be the
2278 last insn before computing the return value. Otherwise, cleanups
2279 which call functions can clobber the return value. */
2280 /* ??? rms: I think that is erroneous, because in C++ it would
2281 run destructors on variables that might be used in the subsequent
2282 computation of the return value. */
2284 register rtx val
= 0;
2288 struct nesting
*block
;
2290 /* If function wants no value, give it none. */
2291 if (TREE_CODE (TREE_TYPE (TREE_TYPE (current_function_decl
))) == VOID_TYPE
)
2293 expand_expr (retval
, NULL_RTX
, VOIDmode
, 0);
2295 expand_null_return ();
2299 /* Are any cleanups needed? E.g. C++ destructors to be run? */
2300 cleanups
= any_pending_cleanups (1);
2302 if (TREE_CODE (retval
) == RESULT_DECL
)
2303 retval_rhs
= retval
;
2304 else if ((TREE_CODE (retval
) == MODIFY_EXPR
|| TREE_CODE (retval
) == INIT_EXPR
)
2305 && TREE_CODE (TREE_OPERAND (retval
, 0)) == RESULT_DECL
)
2306 retval_rhs
= TREE_OPERAND (retval
, 1);
2307 else if (TREE_TYPE (retval
) == void_type_node
)
2308 /* Recognize tail-recursive call to void function. */
2309 retval_rhs
= retval
;
2311 retval_rhs
= NULL_TREE
;
2313 /* Only use `last_insn' if there are cleanups which must be run. */
2314 if (cleanups
|| cleanup_label
!= 0)
2315 last_insn
= get_last_insn ();
2317 /* Distribute return down conditional expr if either of the sides
2318 may involve tail recursion (see test below). This enhances the number
2319 of tail recursions we see. Don't do this always since it can produce
2320 sub-optimal code in some cases and we distribute assignments into
2321 conditional expressions when it would help. */
2323 if (optimize
&& retval_rhs
!= 0
2324 && frame_offset
== 0
2325 && TREE_CODE (retval_rhs
) == COND_EXPR
2326 && (TREE_CODE (TREE_OPERAND (retval_rhs
, 1)) == CALL_EXPR
2327 || TREE_CODE (TREE_OPERAND (retval_rhs
, 2)) == CALL_EXPR
))
2329 rtx label
= gen_label_rtx ();
2330 do_jump (TREE_OPERAND (retval_rhs
, 0), label
, NULL_RTX
);
2331 expand_return (build (MODIFY_EXPR
, TREE_TYPE (current_function_decl
),
2332 DECL_RESULT (current_function_decl
),
2333 TREE_OPERAND (retval_rhs
, 1)));
2335 expand_return (build (MODIFY_EXPR
, TREE_TYPE (current_function_decl
),
2336 DECL_RESULT (current_function_decl
),
2337 TREE_OPERAND (retval_rhs
, 2)));
2341 /* For tail-recursive call to current function,
2342 just jump back to the beginning.
2343 It's unsafe if any auto variable in this function
2344 has its address taken; for simplicity,
2345 require stack frame to be empty. */
2346 if (optimize
&& retval_rhs
!= 0
2347 && frame_offset
== 0
2348 && TREE_CODE (retval_rhs
) == CALL_EXPR
2349 && TREE_CODE (TREE_OPERAND (retval_rhs
, 0)) == ADDR_EXPR
2350 && TREE_OPERAND (TREE_OPERAND (retval_rhs
, 0), 0) == current_function_decl
2351 /* Finish checking validity, and if valid emit code
2352 to set the argument variables for the new call. */
2353 && tail_recursion_args (TREE_OPERAND (retval_rhs
, 1),
2354 DECL_ARGUMENTS (current_function_decl
)))
2356 if (tail_recursion_label
== 0)
2358 tail_recursion_label
= gen_label_rtx ();
2359 emit_label_after (tail_recursion_label
,
2360 tail_recursion_reentry
);
2363 expand_goto_internal (NULL_TREE
, tail_recursion_label
, last_insn
);
2368 /* This optimization is safe if there are local cleanups
2369 because expand_null_return takes care of them.
2370 ??? I think it should also be safe when there is a cleanup label,
2371 because expand_null_return takes care of them, too.
2372 Any reason why not? */
2373 if (HAVE_return
&& cleanup_label
== 0
2374 && ! current_function_returns_pcc_struct
)
2376 /* If this is return x == y; then generate
2377 if (x == y) return 1; else return 0;
2378 if we can do it with explicit return insns. */
2380 switch (TREE_CODE (retval_rhs
))
2388 case TRUTH_ANDIF_EXPR
:
2389 case TRUTH_ORIF_EXPR
:
2390 case TRUTH_AND_EXPR
:
2392 case TRUTH_NOT_EXPR
:
2393 case TRUTH_XOR_EXPR
:
2394 op0
= gen_label_rtx ();
2395 jumpifnot (retval_rhs
, op0
);
2396 expand_value_return (const1_rtx
);
2398 expand_value_return (const0_rtx
);
2402 #endif /* HAVE_return */
2406 && TREE_TYPE (retval_rhs
) != void_type_node
2407 && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl
))) == REG
)
2409 /* Calculate the return value into a pseudo reg. */
2410 val
= expand_expr (retval_rhs
, NULL_RTX
, VOIDmode
, 0);
2412 /* All temporaries have now been used. */
2414 /* Return the calculated value, doing cleanups first. */
2415 expand_value_return (val
);
2419 /* No cleanups or no hard reg used;
2420 calculate value into hard return reg. */
2421 expand_expr (retval
, NULL_RTX
, VOIDmode
, 0);
2424 expand_value_return (DECL_RTL (DECL_RESULT (current_function_decl
)));
2428 /* Return 1 if the end of the generated RTX is not a barrier.
2429 This means code already compiled can drop through. */
2432 drop_through_at_end_p ()
2434 rtx insn
= get_last_insn ();
2435 while (insn
&& GET_CODE (insn
) == NOTE
)
2436 insn
= PREV_INSN (insn
);
2437 return insn
&& GET_CODE (insn
) != BARRIER
;
2440 /* Emit code to alter this function's formal parms for a tail-recursive call.
2441 ACTUALS is a list of actual parameter expressions (chain of TREE_LISTs).
2442 FORMALS is the chain of decls of formals.
2443 Return 1 if this can be done;
2444 otherwise return 0 and do not emit any code. */
2447 tail_recursion_args (actuals
, formals
)
2448 tree actuals
, formals
;
2450 register tree a
= actuals
, f
= formals
;
2452 register rtx
*argvec
;
2454 /* Check that number and types of actuals are compatible
2455 with the formals. This is not always true in valid C code.
2456 Also check that no formal needs to be addressable
2457 and that all formals are scalars. */
2459 /* Also count the args. */
2461 for (a
= actuals
, f
= formals
, i
= 0; a
&& f
; a
= TREE_CHAIN (a
), f
= TREE_CHAIN (f
), i
++)
2463 if (TREE_TYPE (TREE_VALUE (a
)) != TREE_TYPE (f
))
2465 if (GET_CODE (DECL_RTL (f
)) != REG
|| DECL_MODE (f
) == BLKmode
)
2468 if (a
!= 0 || f
!= 0)
2471 /* Compute all the actuals. */
2473 argvec
= (rtx
*) alloca (i
* sizeof (rtx
));
2475 for (a
= actuals
, i
= 0; a
; a
= TREE_CHAIN (a
), i
++)
2476 argvec
[i
] = expand_expr (TREE_VALUE (a
), NULL_RTX
, VOIDmode
, 0);
2478 /* Find which actual values refer to current values of previous formals.
2479 Copy each of them now, before any formal is changed. */
2481 for (a
= actuals
, i
= 0; a
; a
= TREE_CHAIN (a
), i
++)
2485 for (f
= formals
, j
= 0; j
< i
; f
= TREE_CHAIN (f
), j
++)
2486 if (reg_mentioned_p (DECL_RTL (f
), argvec
[i
]))
2487 { copy
= 1; break; }
2489 argvec
[i
] = copy_to_reg (argvec
[i
]);
2492 /* Store the values of the actuals into the formals. */
2494 for (f
= formals
, a
= actuals
, i
= 0; f
;
2495 f
= TREE_CHAIN (f
), a
= TREE_CHAIN (a
), i
++)
2497 if (GET_MODE (DECL_RTL (f
)) == GET_MODE (argvec
[i
]))
2498 emit_move_insn (DECL_RTL (f
), argvec
[i
]);
2500 convert_move (DECL_RTL (f
), argvec
[i
],
2501 TREE_UNSIGNED (TREE_TYPE (TREE_VALUE (a
))));
2508 /* Generate the RTL code for entering a binding contour.
2509 The variables are declared one by one, by calls to `expand_decl'.
2511 EXIT_FLAG is nonzero if this construct should be visible to
2512 `exit_something'. */
2515 expand_start_bindings (exit_flag
)
2518 struct nesting
*thisblock
= ALLOC_NESTING ();
2520 rtx note
= emit_note (NULL_PTR
, NOTE_INSN_BLOCK_BEG
);
2522 /* Make an entry on block_stack for the block we are entering. */
2524 thisblock
->next
= block_stack
;
2525 thisblock
->all
= nesting_stack
;
2526 thisblock
->depth
= ++nesting_depth
;
2527 thisblock
->data
.block
.stack_level
= 0;
2528 thisblock
->data
.block
.cleanups
= 0;
2529 thisblock
->data
.block
.function_call_count
= 0;
2533 if (block_stack
->data
.block
.cleanups
== NULL_TREE
2534 && (block_stack
->data
.block
.outer_cleanups
== NULL_TREE
2535 || block_stack
->data
.block
.outer_cleanups
== empty_cleanup_list
))
2536 thisblock
->data
.block
.outer_cleanups
= empty_cleanup_list
;
2538 thisblock
->data
.block
.outer_cleanups
2539 = tree_cons (NULL_TREE
, block_stack
->data
.block
.cleanups
,
2540 block_stack
->data
.block
.outer_cleanups
);
2543 thisblock
->data
.block
.outer_cleanups
= 0;
2547 && !(block_stack
->data
.block
.cleanups
== NULL_TREE
2548 && block_stack
->data
.block
.outer_cleanups
== NULL_TREE
))
2549 thisblock
->data
.block
.outer_cleanups
2550 = tree_cons (NULL_TREE
, block_stack
->data
.block
.cleanups
,
2551 block_stack
->data
.block
.outer_cleanups
);
2553 thisblock
->data
.block
.outer_cleanups
= 0;
2555 thisblock
->data
.block
.label_chain
= 0;
2556 thisblock
->data
.block
.innermost_stack_block
= stack_block_stack
;
2557 thisblock
->data
.block
.first_insn
= note
;
2558 thisblock
->data
.block
.block_start_count
= ++block_start_count
;
2559 thisblock
->exit_label
= exit_flag
? gen_label_rtx () : 0;
2560 block_stack
= thisblock
;
2561 nesting_stack
= thisblock
;
2563 /* Make a new level for allocating stack slots. */
2567 /* Given a pointer to a BLOCK node, save a pointer to the most recently
2568 generated NOTE_INSN_BLOCK_END in the BLOCK_END_NOTE field of the given
2572 remember_end_note (block
)
2573 register tree block
;
2575 BLOCK_END_NOTE (block
) = last_block_end_note
;
2576 last_block_end_note
= NULL_RTX
;
2579 /* Generate RTL code to terminate a binding contour.
2580 VARS is the chain of VAR_DECL nodes
2581 for the variables bound in this contour.
2582 MARK_ENDS is nonzero if we should put a note at the beginning
2583 and end of this binding contour.
2585 DONT_JUMP_IN is nonzero if it is not valid to jump into this contour.
2586 (That is true automatically if the contour has a saved stack level.) */
2589 expand_end_bindings (vars
, mark_ends
, dont_jump_in
)
2594 register struct nesting
*thisblock
= block_stack
;
2598 for (decl
= vars
; decl
; decl
= TREE_CHAIN (decl
))
2599 if (! TREE_USED (decl
) && TREE_CODE (decl
) == VAR_DECL
2600 && ! DECL_IN_SYSTEM_HEADER (decl
))
2601 warning_with_decl (decl
, "unused variable `%s'");
2603 if (thisblock
->exit_label
)
2605 do_pending_stack_adjust ();
2606 emit_label (thisblock
->exit_label
);
2609 /* If necessary, make a handler for nonlocal gotos taking
2610 place in the function calls in this block. */
2611 if (function_call_count
!= thisblock
->data
.block
.function_call_count
2613 /* Make handler for outermost block
2614 if there were any nonlocal gotos to this function. */
2615 && (thisblock
->next
== 0 ? current_function_has_nonlocal_label
2616 /* Make handler for inner block if it has something
2617 special to do when you jump out of it. */
2618 : (thisblock
->data
.block
.cleanups
!= 0
2619 || thisblock
->data
.block
.stack_level
!= 0)))
2622 rtx afterward
= gen_label_rtx ();
2623 rtx handler_label
= gen_label_rtx ();
2624 rtx save_receiver
= gen_reg_rtx (Pmode
);
2626 /* Don't let jump_optimize delete the handler. */
2627 LABEL_PRESERVE_P (handler_label
) = 1;
2629 /* Record the handler address in the stack slot for that purpose,
2630 during this block, saving and restoring the outer value. */
2631 if (thisblock
->next
!= 0)
2633 emit_move_insn (nonlocal_goto_handler_slot
, save_receiver
);
2634 emit_insn_before (gen_move_insn (save_receiver
,
2635 nonlocal_goto_handler_slot
),
2636 thisblock
->data
.block
.first_insn
);
2638 emit_insn_before (gen_move_insn (nonlocal_goto_handler_slot
,
2639 gen_rtx (LABEL_REF
, Pmode
,
2641 thisblock
->data
.block
.first_insn
);
2643 /* Jump around the handler; it runs only when specially invoked. */
2644 emit_jump (afterward
);
2645 emit_label (handler_label
);
2647 #ifdef HAVE_nonlocal_goto
2648 if (! HAVE_nonlocal_goto
)
2650 /* First adjust our frame pointer to its actual value. It was
2651 previously set to the start of the virtual area corresponding to
2652 the stacked variables when we branched here and now needs to be
2653 adjusted to the actual hardware fp value.
2655 Assignments are to virtual registers are converted by
2656 instantiate_virtual_regs into the corresponding assignment
2657 to the underlying register (fp in this case) that makes
2658 the original assignment true.
2659 So the following insn will actually be
2660 decrementing fp by STARTING_FRAME_OFFSET. */
2661 emit_move_insn (virtual_stack_vars_rtx
, frame_pointer_rtx
);
2663 #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
2664 if (fixed_regs
[ARG_POINTER_REGNUM
])
2666 #ifdef ELIMINABLE_REGS
2667 /* If the argument pointer can be eliminated in favor of the
2668 frame pointer, we don't need to restore it. We assume here
2669 that if such an elimination is present, it can always be used.
2670 This is the case on all known machines; if we don't make this
2671 assumption, we do unnecessary saving on many machines. */
2672 static struct elims
{int from
, to
;} elim_regs
[] = ELIMINABLE_REGS
;
2675 for (i
= 0; i
< sizeof elim_regs
/ sizeof elim_regs
[0]; i
++)
2676 if (elim_regs
[i
].from
== ARG_POINTER_REGNUM
2677 && elim_regs
[i
].to
== FRAME_POINTER_REGNUM
)
2680 if (i
== sizeof elim_regs
/ sizeof elim_regs
[0])
2683 /* Now restore our arg pointer from the address at which it
2684 was saved in our stack frame.
2685 If there hasn't be space allocated for it yet, make
2687 if (arg_pointer_save_area
== 0)
2688 arg_pointer_save_area
2689 = assign_stack_local (Pmode
, GET_MODE_SIZE (Pmode
), 0);
2690 emit_move_insn (virtual_incoming_args_rtx
,
2691 /* We need a pseudo here, or else
2692 instantiate_virtual_regs_1 complains. */
2693 copy_to_reg (arg_pointer_save_area
));
2698 /* The handler expects the desired label address in the static chain
2699 register. It tests the address and does an appropriate jump
2700 to whatever label is desired. */
2701 for (link
= nonlocal_labels
; link
; link
= TREE_CHAIN (link
))
2702 /* Skip any labels we shouldn't be able to jump to from here. */
2703 if (! DECL_TOO_LATE (TREE_VALUE (link
)))
2705 rtx not_this
= gen_label_rtx ();
2706 rtx
this = gen_label_rtx ();
2707 do_jump_if_equal (static_chain_rtx
,
2708 gen_rtx (LABEL_REF
, Pmode
, DECL_RTL (TREE_VALUE (link
))),
2710 emit_jump (not_this
);
2712 expand_goto (TREE_VALUE (link
));
2713 emit_label (not_this
);
2715 /* If label is not recognized, abort. */
2716 emit_library_call (gen_rtx (SYMBOL_REF
, Pmode
, "abort"), 0,
2718 emit_label (afterward
);
2721 /* Don't allow jumping into a block that has cleanups or a stack level. */
2723 || thisblock
->data
.block
.stack_level
!= 0
2724 || thisblock
->data
.block
.cleanups
!= 0)
2726 struct label_chain
*chain
;
2728 /* Any labels in this block are no longer valid to go to.
2729 Mark them to cause an error message. */
2730 for (chain
= thisblock
->data
.block
.label_chain
; chain
; chain
= chain
->next
)
2732 DECL_TOO_LATE (chain
->label
) = 1;
2733 /* If any goto without a fixup came to this label,
2734 that must be an error, because gotos without fixups
2735 come from outside all saved stack-levels and all cleanups. */
2736 if (TREE_ADDRESSABLE (chain
->label
))
2737 error_with_decl (chain
->label
,
2738 "label `%s' used before containing binding contour");
2742 /* Restore stack level in effect before the block
2743 (only if variable-size objects allocated). */
2744 /* Perform any cleanups associated with the block. */
2746 if (thisblock
->data
.block
.stack_level
!= 0
2747 || thisblock
->data
.block
.cleanups
!= 0)
2749 /* Don't let cleanups affect ({...}) constructs. */
2750 int old_expr_stmts_for_value
= expr_stmts_for_value
;
2751 rtx old_last_expr_value
= last_expr_value
;
2752 tree old_last_expr_type
= last_expr_type
;
2753 expr_stmts_for_value
= 0;
2755 /* Do the cleanups. */
2756 expand_cleanups (thisblock
->data
.block
.cleanups
, NULL_TREE
);
2757 do_pending_stack_adjust ();
2759 expr_stmts_for_value
= old_expr_stmts_for_value
;
2760 last_expr_value
= old_last_expr_value
;
2761 last_expr_type
= old_last_expr_type
;
2763 /* Restore the stack level. */
2765 if (thisblock
->data
.block
.stack_level
!= 0)
2767 emit_stack_restore (thisblock
->next
? SAVE_BLOCK
: SAVE_FUNCTION
,
2768 thisblock
->data
.block
.stack_level
, NULL_RTX
);
2769 if (nonlocal_goto_handler_slot
!= 0)
2770 emit_stack_save (SAVE_NONLOCAL
, &nonlocal_goto_stack_level
,
2774 /* Any gotos out of this block must also do these things.
2775 Also report any gotos with fixups that came to labels in this
2777 fixup_gotos (thisblock
,
2778 thisblock
->data
.block
.stack_level
,
2779 thisblock
->data
.block
.cleanups
,
2780 thisblock
->data
.block
.first_insn
,
2784 /* Mark the beginning and end of the scope if requested.
2785 We do this now, after running cleanups on the variables
2786 just going out of scope, so they are in scope for their cleanups. */
2789 last_block_end_note
= emit_note (NULL_PTR
, NOTE_INSN_BLOCK_END
);
2791 /* Get rid of the beginning-mark if we don't make an end-mark. */
2792 NOTE_LINE_NUMBER (thisblock
->data
.block
.first_insn
) = NOTE_INSN_DELETED
;
2794 /* If doing stupid register allocation, make sure lives of all
2795 register variables declared here extend thru end of scope. */
2798 for (decl
= vars
; decl
; decl
= TREE_CHAIN (decl
))
2800 rtx rtl
= DECL_RTL (decl
);
2801 if (TREE_CODE (decl
) == VAR_DECL
&& rtl
!= 0)
2805 /* Restore block_stack level for containing block. */
2807 stack_block_stack
= thisblock
->data
.block
.innermost_stack_block
;
2808 POPSTACK (block_stack
);
2810 /* Pop the stack slot nesting and free any slots at this level. */
2814 /* Generate RTL for the automatic variable declaration DECL.
2815 (Other kinds of declarations are simply ignored if seen here.)
2816 CLEANUP is an expression to be executed at exit from this binding contour;
2817 for example, in C++, it might call the destructor for this variable.
2819 If CLEANUP contains any SAVE_EXPRs, then you must preevaluate them
2820 either before or after calling `expand_decl' but before compiling
2821 any subsequent expressions. This is because CLEANUP may be expanded
2822 more than once, on different branches of execution.
2823 For the same reason, CLEANUP may not contain a CALL_EXPR
2824 except as its topmost node--else `preexpand_calls' would get confused.
2826 If CLEANUP is nonzero and DECL is zero, we record a cleanup
2827 that is not associated with any particular variable.
2829 There is no special support here for C++ constructors.
2830 They should be handled by the proper code in DECL_INITIAL. */
2836 struct nesting
*thisblock
= block_stack
;
2837 tree type
= TREE_TYPE (decl
);
2839 /* Only automatic variables need any expansion done.
2840 Static and external variables, and external functions,
2841 will be handled by `assemble_variable' (called from finish_decl).
2842 TYPE_DECL and CONST_DECL require nothing.
2843 PARM_DECLs are handled in `assign_parms'. */
2845 if (TREE_CODE (decl
) != VAR_DECL
)
2847 if (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
))
2850 /* Create the RTL representation for the variable. */
2852 if (type
== error_mark_node
)
2853 DECL_RTL (decl
) = gen_rtx (MEM
, BLKmode
, const0_rtx
);
2854 else if (DECL_SIZE (decl
) == 0)
2855 /* Variable with incomplete type. */
2857 if (DECL_INITIAL (decl
) == 0)
2858 /* Error message was already done; now avoid a crash. */
2859 DECL_RTL (decl
) = assign_stack_temp (DECL_MODE (decl
), 0, 1);
2861 /* An initializer is going to decide the size of this array.
2862 Until we know the size, represent its address with a reg. */
2863 DECL_RTL (decl
) = gen_rtx (MEM
, BLKmode
, gen_reg_rtx (Pmode
));
2865 else if (DECL_MODE (decl
) != BLKmode
2866 /* If -ffloat-store, don't put explicit float vars
2868 && !(flag_float_store
2869 && TREE_CODE (type
) == REAL_TYPE
)
2870 && ! TREE_THIS_VOLATILE (decl
)
2871 && ! TREE_ADDRESSABLE (decl
)
2872 && (DECL_REGISTER (decl
) || ! obey_regdecls
))
2874 /* Automatic variable that can go in a register. */
2875 enum machine_mode reg_mode
= DECL_MODE (decl
);
2876 int unsignedp
= TREE_UNSIGNED (type
);
2878 if (TREE_CODE (type
) == INTEGER_TYPE
|| TREE_CODE (type
) == ENUMERAL_TYPE
2879 || TREE_CODE (type
) == BOOLEAN_TYPE
|| TREE_CODE (type
) == CHAR_TYPE
2880 || TREE_CODE (type
) == REAL_TYPE
|| TREE_CODE (type
) == POINTER_TYPE
2881 || TREE_CODE (type
) == OFFSET_TYPE
)
2883 PROMOTE_MODE (reg_mode
, unsignedp
, type
);
2886 DECL_RTL (decl
) = gen_reg_rtx (reg_mode
);
2887 if (TREE_CODE (type
) == POINTER_TYPE
)
2888 mark_reg_pointer (DECL_RTL (decl
));
2889 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
2891 else if (TREE_CODE (DECL_SIZE (decl
)) == INTEGER_CST
)
2893 /* Variable of fixed size that goes on the stack. */
2897 /* If we previously made RTL for this decl, it must be an array
2898 whose size was determined by the initializer.
2899 The old address was a register; set that register now
2900 to the proper address. */
2901 if (DECL_RTL (decl
) != 0)
2903 if (GET_CODE (DECL_RTL (decl
)) != MEM
2904 || GET_CODE (XEXP (DECL_RTL (decl
), 0)) != REG
)
2906 oldaddr
= XEXP (DECL_RTL (decl
), 0);
2910 = assign_stack_temp (DECL_MODE (decl
),
2911 ((TREE_INT_CST_LOW (DECL_SIZE (decl
))
2912 + BITS_PER_UNIT
- 1)
2916 /* Set alignment we actually gave this decl. */
2917 DECL_ALIGN (decl
) = (DECL_MODE (decl
) == BLKmode
? BIGGEST_ALIGNMENT
2918 : GET_MODE_BITSIZE (DECL_MODE (decl
)));
2922 addr
= force_operand (XEXP (DECL_RTL (decl
), 0), oldaddr
);
2923 if (addr
!= oldaddr
)
2924 emit_move_insn (oldaddr
, addr
);
2927 /* If this is a memory ref that contains aggregate components,
2928 mark it as such for cse and loop optimize. */
2929 MEM_IN_STRUCT_P (DECL_RTL (decl
))
2930 = (TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
2931 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
2932 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
);
2934 /* If this is in memory because of -ffloat-store,
2935 set the volatile bit, to prevent optimizations from
2936 undoing the effects. */
2937 if (flag_float_store
&& TREE_CODE (type
) == REAL_TYPE
)
2938 MEM_VOLATILE_P (DECL_RTL (decl
)) = 1;
2942 /* Dynamic-size object: must push space on the stack. */
2946 /* Record the stack pointer on entry to block, if have
2947 not already done so. */
2948 if (thisblock
->data
.block
.stack_level
== 0)
2950 do_pending_stack_adjust ();
2951 emit_stack_save (thisblock
->next
? SAVE_BLOCK
: SAVE_FUNCTION
,
2952 &thisblock
->data
.block
.stack_level
,
2953 thisblock
->data
.block
.first_insn
);
2954 stack_block_stack
= thisblock
;
2957 /* Compute the variable's size, in bytes. */
2958 size
= expand_expr (size_binop (CEIL_DIV_EXPR
,
2960 size_int (BITS_PER_UNIT
)),
2961 NULL_RTX
, VOIDmode
, 0);
2964 /* This is equivalent to calling alloca. */
2965 current_function_calls_alloca
= 1;
2967 /* Allocate space on the stack for the variable. */
2968 address
= allocate_dynamic_stack_space (size
, NULL_RTX
,
2971 if (nonlocal_goto_handler_slot
!= 0)
2972 emit_stack_save (SAVE_NONLOCAL
, &nonlocal_goto_stack_level
, NULL_RTX
);
2974 /* Reference the variable indirect through that rtx. */
2975 DECL_RTL (decl
) = gen_rtx (MEM
, DECL_MODE (decl
), address
);
2977 /* If this is a memory ref that contains aggregate components,
2978 mark it as such for cse and loop optimize. */
2979 MEM_IN_STRUCT_P (DECL_RTL (decl
))
2980 = (TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
2981 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
2982 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
);
2984 /* Indicate the alignment we actually gave this variable. */
2985 #ifdef STACK_BOUNDARY
2986 DECL_ALIGN (decl
) = STACK_BOUNDARY
;
2988 DECL_ALIGN (decl
) = BIGGEST_ALIGNMENT
;
2992 if (TREE_THIS_VOLATILE (decl
))
2993 MEM_VOLATILE_P (DECL_RTL (decl
)) = 1;
2994 if (TREE_READONLY (decl
))
2995 RTX_UNCHANGING_P (DECL_RTL (decl
)) = 1;
2997 /* If doing stupid register allocation, make sure life of any
2998 register variable starts here, at the start of its scope. */
3001 use_variable (DECL_RTL (decl
));
3004 /* Emit code to perform the initialization of a declaration DECL. */
3007 expand_decl_init (decl
)
3010 int was_used
= TREE_USED (decl
);
3012 if (TREE_STATIC (decl
))
3015 /* Compute and store the initial value now. */
3017 if (DECL_INITIAL (decl
) == error_mark_node
)
3019 enum tree_code code
= TREE_CODE (TREE_TYPE (decl
));
3020 if (code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== ENUMERAL_TYPE
3021 || code
== POINTER_TYPE
)
3022 expand_assignment (decl
, convert (TREE_TYPE (decl
), integer_zero_node
),
3026 else if (DECL_INITIAL (decl
) && TREE_CODE (DECL_INITIAL (decl
)) != TREE_LIST
)
3028 emit_line_note (DECL_SOURCE_FILE (decl
), DECL_SOURCE_LINE (decl
));
3029 expand_assignment (decl
, DECL_INITIAL (decl
), 0, 0);
3033 /* Don't let the initialization count as "using" the variable. */
3034 TREE_USED (decl
) = was_used
;
3036 /* Free any temporaries we made while initializing the decl. */
3040 /* CLEANUP is an expression to be executed at exit from this binding contour;
3041 for example, in C++, it might call the destructor for this variable.
3043 If CLEANUP contains any SAVE_EXPRs, then you must preevaluate them
3044 either before or after calling `expand_decl' but before compiling
3045 any subsequent expressions. This is because CLEANUP may be expanded
3046 more than once, on different branches of execution.
3047 For the same reason, CLEANUP may not contain a CALL_EXPR
3048 except as its topmost node--else `preexpand_calls' would get confused.
3050 If CLEANUP is nonzero and DECL is zero, we record a cleanup
3051 that is not associated with any particular variable. */
3054 expand_decl_cleanup (decl
, cleanup
)
3057 struct nesting
*thisblock
= block_stack
;
3059 /* Error if we are not in any block. */
3063 /* Record the cleanup if there is one. */
3067 thisblock
->data
.block
.cleanups
3068 = temp_tree_cons (decl
, cleanup
, thisblock
->data
.block
.cleanups
);
3069 /* If this block has a cleanup, it belongs in stack_block_stack. */
3070 stack_block_stack
= thisblock
;
3075 /* DECL is an anonymous union. CLEANUP is a cleanup for DECL.
3076 DECL_ELTS is the list of elements that belong to DECL's type.
3077 In each, the TREE_VALUE is a VAR_DECL, and the TREE_PURPOSE a cleanup. */
3080 expand_anon_union_decl (decl
, cleanup
, decl_elts
)
3081 tree decl
, cleanup
, decl_elts
;
3083 struct nesting
*thisblock
= block_stack
;
3086 expand_decl (decl
, cleanup
);
3087 x
= DECL_RTL (decl
);
3091 tree decl_elt
= TREE_VALUE (decl_elts
);
3092 tree cleanup_elt
= TREE_PURPOSE (decl_elts
);
3093 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (decl_elt
));
3095 /* (SUBREG (MEM ...)) at RTL generation time is invalid, so we
3096 instead create a new MEM rtx with the proper mode. */
3097 if (GET_CODE (x
) == MEM
)
3099 if (mode
== GET_MODE (x
))
3100 DECL_RTL (decl_elt
) = x
;
3103 DECL_RTL (decl_elt
) = gen_rtx (MEM
, mode
, copy_rtx (XEXP (x
, 0)));
3104 MEM_IN_STRUCT_P (DECL_RTL (decl_elt
)) = MEM_IN_STRUCT_P (x
);
3105 RTX_UNCHANGING_P (DECL_RTL (decl_elt
)) = RTX_UNCHANGING_P (x
);
3108 else if (GET_CODE (x
) == REG
)
3110 if (mode
== GET_MODE (x
))
3111 DECL_RTL (decl_elt
) = x
;
3113 DECL_RTL (decl_elt
) = gen_rtx (SUBREG
, mode
, x
, 0);
3118 /* Record the cleanup if there is one. */
3121 thisblock
->data
.block
.cleanups
3122 = temp_tree_cons (decl_elt
, cleanup_elt
,
3123 thisblock
->data
.block
.cleanups
);
3125 decl_elts
= TREE_CHAIN (decl_elts
);
3129 /* Expand a list of cleanups LIST.
3130 Elements may be expressions or may be nested lists.
3132 If DONT_DO is nonnull, then any list-element
3133 whose TREE_PURPOSE matches DONT_DO is omitted.
3134 This is sometimes used to avoid a cleanup associated with
3135 a value that is being returned out of the scope. */
3138 expand_cleanups (list
, dont_do
)
3143 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
3144 if (dont_do
== 0 || TREE_PURPOSE (tail
) != dont_do
)
3146 if (TREE_CODE (TREE_VALUE (tail
)) == TREE_LIST
)
3147 expand_cleanups (TREE_VALUE (tail
), dont_do
);
3150 /* Cleanups may be run multiple times. For example,
3151 when exiting a binding contour, we expand the
3152 cleanups associated with that contour. When a goto
3153 within that binding contour has a target outside that
3154 contour, it will expand all cleanups from its scope to
3155 the target. Though the cleanups are expanded multiple
3156 times, the control paths are non-overlapping so the
3157 cleanups will not be executed twice. */
3158 expand_expr (TREE_VALUE (tail
), const0_rtx
, VOIDmode
, 0);
3164 /* Move all cleanups from the current block_stack
3165 to the containing block_stack, where they are assumed to
3166 have been created. If anything can cause a temporary to
3167 be created, but not expanded for more than one level of
3168 block_stacks, then this code will have to change. */
3173 struct nesting
*block
= block_stack
;
3174 struct nesting
*outer
= block
->next
;
3176 outer
->data
.block
.cleanups
3177 = chainon (block
->data
.block
.cleanups
,
3178 outer
->data
.block
.cleanups
);
3179 block
->data
.block
.cleanups
= 0;
3183 last_cleanup_this_contour ()
3185 if (block_stack
== 0)
3188 return block_stack
->data
.block
.cleanups
;
3191 /* Return 1 if there are any pending cleanups at this point.
3192 If THIS_CONTOUR is nonzero, check the current contour as well.
3193 Otherwise, look only at the contours that enclose this one. */
3196 any_pending_cleanups (this_contour
)
3199 struct nesting
*block
;
3201 if (block_stack
== 0)
3204 if (this_contour
&& block_stack
->data
.block
.cleanups
!= NULL
)
3206 if (block_stack
->data
.block
.cleanups
== 0
3207 && (block_stack
->data
.block
.outer_cleanups
== 0
3209 || block_stack
->data
.block
.outer_cleanups
== empty_cleanup_list
3214 for (block
= block_stack
->next
; block
; block
= block
->next
)
3215 if (block
->data
.block
.cleanups
!= 0)
3221 /* Enter a case (Pascal) or switch (C) statement.
3222 Push a block onto case_stack and nesting_stack
3223 to accumulate the case-labels that are seen
3224 and to record the labels generated for the statement.
3226 EXIT_FLAG is nonzero if `exit_something' should exit this case stmt.
3227 Otherwise, this construct is transparent for `exit_something'.
3229 EXPR is the index-expression to be dispatched on.
3230 TYPE is its nominal type. We could simply convert EXPR to this type,
3231 but instead we take short cuts. */
3234 expand_start_case (exit_flag
, expr
, type
, printname
)
3240 register struct nesting
*thiscase
= ALLOC_NESTING ();
3242 /* Make an entry on case_stack for the case we are entering. */
3244 thiscase
->next
= case_stack
;
3245 thiscase
->all
= nesting_stack
;
3246 thiscase
->depth
= ++nesting_depth
;
3247 thiscase
->exit_label
= exit_flag
? gen_label_rtx () : 0;
3248 thiscase
->data
.case_stmt
.case_list
= 0;
3249 thiscase
->data
.case_stmt
.index_expr
= expr
;
3250 thiscase
->data
.case_stmt
.nominal_type
= type
;
3251 thiscase
->data
.case_stmt
.default_label
= 0;
3252 thiscase
->data
.case_stmt
.num_ranges
= 0;
3253 thiscase
->data
.case_stmt
.printname
= printname
;
3254 thiscase
->data
.case_stmt
.seenlabel
= 0;
3255 case_stack
= thiscase
;
3256 nesting_stack
= thiscase
;
3258 do_pending_stack_adjust ();
3260 /* Make sure case_stmt.start points to something that won't
3261 need any transformation before expand_end_case. */
3262 if (GET_CODE (get_last_insn ()) != NOTE
)
3263 emit_note (NULL_PTR
, NOTE_INSN_DELETED
);
3265 thiscase
->data
.case_stmt
.start
= get_last_insn ();
3268 /* Start a "dummy case statement" within which case labels are invalid
3269 and are not connected to any larger real case statement.
3270 This can be used if you don't want to let a case statement jump
3271 into the middle of certain kinds of constructs. */
3274 expand_start_case_dummy ()
3276 register struct nesting
*thiscase
= ALLOC_NESTING ();
3278 /* Make an entry on case_stack for the dummy. */
3280 thiscase
->next
= case_stack
;
3281 thiscase
->all
= nesting_stack
;
3282 thiscase
->depth
= ++nesting_depth
;
3283 thiscase
->exit_label
= 0;
3284 thiscase
->data
.case_stmt
.case_list
= 0;
3285 thiscase
->data
.case_stmt
.start
= 0;
3286 thiscase
->data
.case_stmt
.nominal_type
= 0;
3287 thiscase
->data
.case_stmt
.default_label
= 0;
3288 thiscase
->data
.case_stmt
.num_ranges
= 0;
3289 case_stack
= thiscase
;
3290 nesting_stack
= thiscase
;
3293 /* End a dummy case statement. */
3296 expand_end_case_dummy ()
3298 POPSTACK (case_stack
);
3301 /* Return the data type of the index-expression
3302 of the innermost case statement, or null if none. */
3305 case_index_expr_type ()
3308 return TREE_TYPE (case_stack
->data
.case_stmt
.index_expr
);
3312 /* Accumulate one case or default label inside a case or switch statement.
3313 VALUE is the value of the case (a null pointer, for a default label).
3315 If not currently inside a case or switch statement, return 1 and do
3316 nothing. The caller will print a language-specific error message.
3317 If VALUE is a duplicate or overlaps, return 2 and do nothing
3318 except store the (first) duplicate node in *DUPLICATE.
3319 If VALUE is out of range, return 3 and do nothing.
3320 If we are jumping into the scope of a cleaup or var-sized array, return 5.
3321 Return 0 on success.
3323 Extended to handle range statements. */
3326 pushcase (value
, label
, duplicate
)
3327 register tree value
;
3328 register tree label
;
3331 register struct case_node
**l
;
3332 register struct case_node
*n
;
3336 /* Fail if not inside a real case statement. */
3337 if (! (case_stack
&& case_stack
->data
.case_stmt
.start
))
3340 if (stack_block_stack
3341 && stack_block_stack
->depth
> case_stack
->depth
)
3344 index_type
= TREE_TYPE (case_stack
->data
.case_stmt
.index_expr
);
3345 nominal_type
= case_stack
->data
.case_stmt
.nominal_type
;
3347 /* If the index is erroneous, avoid more problems: pretend to succeed. */
3348 if (index_type
== error_mark_node
)
3351 /* Convert VALUE to the type in which the comparisons are nominally done. */
3353 value
= convert (nominal_type
, value
);
3355 /* If this is the first label, warn if any insns have been emitted. */
3356 if (case_stack
->data
.case_stmt
.seenlabel
== 0)
3359 for (insn
= case_stack
->data
.case_stmt
.start
;
3361 insn
= NEXT_INSN (insn
))
3363 if (GET_CODE (insn
) == CODE_LABEL
)
3365 if (GET_CODE (insn
) != NOTE
3366 && (GET_CODE (insn
) != INSN
|| GET_CODE (PATTERN (insn
)) != USE
))
3368 warning ("unreachable code at beginning of %s",
3369 case_stack
->data
.case_stmt
.printname
);
3374 case_stack
->data
.case_stmt
.seenlabel
= 1;
3376 /* Fail if this value is out of range for the actual type of the index
3377 (which may be narrower than NOMINAL_TYPE). */
3378 if (value
!= 0 && ! int_fits_type_p (value
, index_type
))
3381 /* Fail if this is a duplicate or overlaps another entry. */
3384 if (case_stack
->data
.case_stmt
.default_label
!= 0)
3386 *duplicate
= case_stack
->data
.case_stmt
.default_label
;
3389 case_stack
->data
.case_stmt
.default_label
= label
;
3393 /* Find the elt in the chain before which to insert the new value,
3394 to keep the chain sorted in increasing order.
3395 But report an error if this element is a duplicate. */
3396 for (l
= &case_stack
->data
.case_stmt
.case_list
;
3397 /* Keep going past elements distinctly less than VALUE. */
3398 *l
!= 0 && tree_int_cst_lt ((*l
)->high
, value
);
3403 /* Element we will insert before must be distinctly greater;
3404 overlap means error. */
3405 if (! tree_int_cst_lt (value
, (*l
)->low
))
3407 *duplicate
= (*l
)->code_label
;
3412 /* Add this label to the chain, and succeed.
3413 Copy VALUE so it is on temporary rather than momentary
3414 obstack and will thus survive till the end of the case statement. */
3415 n
= (struct case_node
*) oballoc (sizeof (struct case_node
));
3418 n
->high
= n
->low
= copy_node (value
);
3419 n
->code_label
= label
;
3423 expand_label (label
);
3427 /* Like pushcase but this case applies to all values
3428 between VALUE1 and VALUE2 (inclusive).
3429 The return value is the same as that of pushcase
3430 but there is one additional error code:
3431 4 means the specified range was empty. */
3434 pushcase_range (value1
, value2
, label
, duplicate
)
3435 register tree value1
, value2
;
3436 register tree label
;
3439 register struct case_node
**l
;
3440 register struct case_node
*n
;
3444 /* Fail if not inside a real case statement. */
3445 if (! (case_stack
&& case_stack
->data
.case_stmt
.start
))
3448 if (stack_block_stack
3449 && stack_block_stack
->depth
> case_stack
->depth
)
3452 index_type
= TREE_TYPE (case_stack
->data
.case_stmt
.index_expr
);
3453 nominal_type
= case_stack
->data
.case_stmt
.nominal_type
;
3455 /* If the index is erroneous, avoid more problems: pretend to succeed. */
3456 if (index_type
== error_mark_node
)
3459 /* If this is the first label, warn if any insns have been emitted. */
3460 if (case_stack
->data
.case_stmt
.seenlabel
== 0)
3463 for (insn
= case_stack
->data
.case_stmt
.start
;
3465 insn
= NEXT_INSN (insn
))
3467 if (GET_CODE (insn
) == CODE_LABEL
)
3469 if (GET_CODE (insn
) != NOTE
3470 && (GET_CODE (insn
) != INSN
|| GET_CODE (PATTERN (insn
)) != USE
))
3472 warning ("unreachable code at beginning of %s",
3473 case_stack
->data
.case_stmt
.printname
);
3478 case_stack
->data
.case_stmt
.seenlabel
= 1;
3480 /* Convert VALUEs to type in which the comparisons are nominally done. */
3481 if (value1
== 0) /* Negative infinity. */
3482 value1
= TYPE_MIN_VALUE(index_type
);
3483 value1
= convert (nominal_type
, value1
);
3485 if (value2
== 0) /* Positive infinity. */
3486 value2
= TYPE_MAX_VALUE(index_type
);
3487 value2
= convert (nominal_type
, value2
);
3489 /* Fail if these values are out of range. */
3490 if (! int_fits_type_p (value1
, index_type
))
3493 if (! int_fits_type_p (value2
, index_type
))
3496 /* Fail if the range is empty. */
3497 if (tree_int_cst_lt (value2
, value1
))
3500 /* If the bounds are equal, turn this into the one-value case. */
3501 if (tree_int_cst_equal (value1
, value2
))
3502 return pushcase (value1
, label
, duplicate
);
3504 /* Find the elt in the chain before which to insert the new value,
3505 to keep the chain sorted in increasing order.
3506 But report an error if this element is a duplicate. */
3507 for (l
= &case_stack
->data
.case_stmt
.case_list
;
3508 /* Keep going past elements distinctly less than this range. */
3509 *l
!= 0 && tree_int_cst_lt ((*l
)->high
, value1
);
3514 /* Element we will insert before must be distinctly greater;
3515 overlap means error. */
3516 if (! tree_int_cst_lt (value2
, (*l
)->low
))
3518 *duplicate
= (*l
)->code_label
;
3523 /* Add this label to the chain, and succeed.
3524 Copy VALUE1, VALUE2 so they are on temporary rather than momentary
3525 obstack and will thus survive till the end of the case statement. */
3527 n
= (struct case_node
*) oballoc (sizeof (struct case_node
));
3530 n
->low
= copy_node (value1
);
3531 n
->high
= copy_node (value2
);
3532 n
->code_label
= label
;
3535 expand_label (label
);
3537 case_stack
->data
.case_stmt
.num_ranges
++;
3542 /* Called when the index of a switch statement is an enumerated type
3543 and there is no default label.
3545 Checks that all enumeration literals are covered by the case
3546 expressions of a switch. Also, warn if there are any extra
3547 switch cases that are *not* elements of the enumerated type.
3549 If all enumeration literals were covered by the case expressions,
3550 turn one of the expressions into the default expression since it should
3551 not be possible to fall through such a switch. */
3554 check_for_full_enumeration_handling (type
)
3557 register struct case_node
*n
;
3558 register struct case_node
**l
;
3559 register tree chain
;
3562 /* The time complexity of this loop is currently O(N * M), with
3563 N being the number of members in the enumerated type, and
3564 M being the number of case expressions in the switch. */
3566 for (chain
= TYPE_VALUES (type
);
3568 chain
= TREE_CHAIN (chain
))
3570 /* Find a match between enumeral and case expression, if possible.
3571 Quit looking when we've gone too far (since case expressions
3572 are kept sorted in ascending order). Warn about enumerators not
3573 handled in the switch statement case expression list. */
3575 for (n
= case_stack
->data
.case_stmt
.case_list
;
3576 n
&& tree_int_cst_lt (n
->high
, TREE_VALUE (chain
));
3580 if (!n
|| tree_int_cst_lt (TREE_VALUE (chain
), n
->low
))
3583 warning ("enumeration value `%s' not handled in switch",
3584 IDENTIFIER_POINTER (TREE_PURPOSE (chain
)));
3589 /* Now we go the other way around; we warn if there are case
3590 expressions that don't correspond to enumerators. This can
3591 occur since C and C++ don't enforce type-checking of
3592 assignments to enumeration variables. */
3595 for (n
= case_stack
->data
.case_stmt
.case_list
; n
; n
= n
->right
)
3597 for (chain
= TYPE_VALUES (type
);
3598 chain
&& !tree_int_cst_equal (n
->low
, TREE_VALUE (chain
));
3599 chain
= TREE_CHAIN (chain
))
3603 warning ("case value `%d' not in enumerated type `%s'",
3604 TREE_INT_CST_LOW (n
->low
),
3605 IDENTIFIER_POINTER ((TREE_CODE (TYPE_NAME (type
))
3608 : DECL_NAME (TYPE_NAME (type
))));
3609 if (!tree_int_cst_equal (n
->low
, n
->high
))
3611 for (chain
= TYPE_VALUES (type
);
3612 chain
&& !tree_int_cst_equal (n
->high
, TREE_VALUE (chain
));
3613 chain
= TREE_CHAIN (chain
))
3617 warning ("case value `%d' not in enumerated type `%s'",
3618 TREE_INT_CST_LOW (n
->high
),
3619 IDENTIFIER_POINTER ((TREE_CODE (TYPE_NAME (type
))
3622 : DECL_NAME (TYPE_NAME (type
))));
3626 /* If all values were found as case labels, make one of them the default
3627 label. Thus, this switch will never fall through. We arbitrarily pick
3628 the last one to make the default since this is likely the most
3629 efficient choice. */
3633 for (l
= &case_stack
->data
.case_stmt
.case_list
;
3638 case_stack
->data
.case_stmt
.default_label
= (*l
)->code_label
;
3643 /* Terminate a case (Pascal) or switch (C) statement
3644 in which ORIG_INDEX is the expression to be tested.
3645 Generate the code to test it and jump to the right place. */
3648 expand_end_case (orig_index
)
3651 tree minval
, maxval
, range
;
3652 rtx default_label
= 0;
3653 register struct case_node
*n
;
3656 rtx table_label
= gen_label_rtx ();
3661 register struct nesting
*thiscase
= case_stack
;
3662 tree index_expr
= thiscase
->data
.case_stmt
.index_expr
;
3663 int unsignedp
= TREE_UNSIGNED (TREE_TYPE (index_expr
));
3665 do_pending_stack_adjust ();
3667 /* An ERROR_MARK occurs for various reasons including invalid data type. */
3668 if (TREE_TYPE (index_expr
) != error_mark_node
)
3670 /* If switch expression was an enumerated type, check that all
3671 enumeration literals are covered by the cases.
3672 No sense trying this if there's a default case, however. */
3674 if (!thiscase
->data
.case_stmt
.default_label
3675 && TREE_CODE (TREE_TYPE (orig_index
)) == ENUMERAL_TYPE
3676 && TREE_CODE (index_expr
) != INTEGER_CST
)
3677 check_for_full_enumeration_handling (TREE_TYPE (orig_index
));
3679 /* If this is the first label, warn if any insns have been emitted. */
3680 if (thiscase
->data
.case_stmt
.seenlabel
== 0)
3683 for (insn
= get_last_insn ();
3684 insn
!= case_stack
->data
.case_stmt
.start
;
3685 insn
= PREV_INSN (insn
))
3686 if (GET_CODE (insn
) != NOTE
3687 && (GET_CODE (insn
) != INSN
|| GET_CODE (PATTERN (insn
))!= USE
))
3689 warning ("unreachable code at beginning of %s",
3690 case_stack
->data
.case_stmt
.printname
);
3695 /* If we don't have a default-label, create one here,
3696 after the body of the switch. */
3697 if (thiscase
->data
.case_stmt
.default_label
== 0)
3699 thiscase
->data
.case_stmt
.default_label
3700 = build_decl (LABEL_DECL
, NULL_TREE
, NULL_TREE
);
3701 expand_label (thiscase
->data
.case_stmt
.default_label
);
3703 default_label
= label_rtx (thiscase
->data
.case_stmt
.default_label
);
3705 before_case
= get_last_insn ();
3707 /* Simplify the case-list before we count it. */
3708 group_case_nodes (thiscase
->data
.case_stmt
.case_list
);
3710 /* Get upper and lower bounds of case values.
3711 Also convert all the case values to the index expr's data type. */
3714 for (n
= thiscase
->data
.case_stmt
.case_list
; n
; n
= n
->right
)
3716 /* Check low and high label values are integers. */
3717 if (TREE_CODE (n
->low
) != INTEGER_CST
)
3719 if (TREE_CODE (n
->high
) != INTEGER_CST
)
3722 n
->low
= convert (TREE_TYPE (index_expr
), n
->low
);
3723 n
->high
= convert (TREE_TYPE (index_expr
), n
->high
);
3725 /* Count the elements and track the largest and smallest
3726 of them (treating them as signed even if they are not). */
3734 if (INT_CST_LT (n
->low
, minval
))
3736 if (INT_CST_LT (maxval
, n
->high
))
3739 /* A range counts double, since it requires two compares. */
3740 if (! tree_int_cst_equal (n
->low
, n
->high
))
3744 /* Compute span of values. */
3746 range
= fold (build (MINUS_EXPR
, TREE_TYPE (index_expr
),
3749 if (count
== 0 || TREE_CODE (TREE_TYPE (index_expr
)) == ERROR_MARK
)
3751 expand_expr (index_expr
, const0_rtx
, VOIDmode
, 0);
3753 emit_jump (default_label
);
3755 /* If range of values is much bigger than number of values,
3756 make a sequence of conditional branches instead of a dispatch.
3757 If the switch-index is a constant, do it this way
3758 because we can optimize it. */
3760 #ifndef CASE_VALUES_THRESHOLD
3762 #define CASE_VALUES_THRESHOLD (HAVE_casesi ? 4 : 5)
3764 /* If machine does not have a case insn that compares the
3765 bounds, this means extra overhead for dispatch tables
3766 which raises the threshold for using them. */
3767 #define CASE_VALUES_THRESHOLD 5
3768 #endif /* HAVE_casesi */
3769 #endif /* CASE_VALUES_THRESHOLD */
3771 else if (TREE_INT_CST_HIGH (range
) != 0
3772 || count
< CASE_VALUES_THRESHOLD
3773 || ((unsigned HOST_WIDE_INT
) (TREE_INT_CST_LOW (range
))
3775 || TREE_CODE (index_expr
) == INTEGER_CST
3776 /* These will reduce to a constant. */
3777 || (TREE_CODE (index_expr
) == CALL_EXPR
3778 && TREE_CODE (TREE_OPERAND (index_expr
, 0)) == ADDR_EXPR
3779 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (index_expr
, 0), 0)) == FUNCTION_DECL
3780 && DECL_FUNCTION_CODE (TREE_OPERAND (TREE_OPERAND (index_expr
, 0), 0)) == BUILT_IN_CLASSIFY_TYPE
)
3781 || (TREE_CODE (index_expr
) == COMPOUND_EXPR
3782 && TREE_CODE (TREE_OPERAND (index_expr
, 1)) == INTEGER_CST
))
3784 index
= expand_expr (index_expr
, NULL_RTX
, VOIDmode
, 0);
3786 /* If the index is a short or char that we do not have
3787 an insn to handle comparisons directly, convert it to
3788 a full integer now, rather than letting each comparison
3789 generate the conversion. */
3791 if (GET_MODE_CLASS (GET_MODE (index
)) == MODE_INT
3792 && (cmp_optab
->handlers
[(int) GET_MODE(index
)].insn_code
3793 == CODE_FOR_nothing
))
3795 enum machine_mode wider_mode
;
3796 for (wider_mode
= GET_MODE (index
); wider_mode
!= VOIDmode
;
3797 wider_mode
= GET_MODE_WIDER_MODE (wider_mode
))
3798 if (cmp_optab
->handlers
[(int) wider_mode
].insn_code
3799 != CODE_FOR_nothing
)
3801 index
= convert_to_mode (wider_mode
, index
, unsignedp
);
3807 do_pending_stack_adjust ();
3809 index
= protect_from_queue (index
, 0);
3810 if (GET_CODE (index
) == MEM
)
3811 index
= copy_to_reg (index
);
3812 if (GET_CODE (index
) == CONST_INT
3813 || TREE_CODE (index_expr
) == INTEGER_CST
)
3815 /* Make a tree node with the proper constant value
3816 if we don't already have one. */
3817 if (TREE_CODE (index_expr
) != INTEGER_CST
)
3820 = build_int_2 (INTVAL (index
),
3821 !unsignedp
&& INTVAL (index
) >= 0 ? 0 : -1);
3822 index_expr
= convert (TREE_TYPE (index_expr
), index_expr
);
3825 /* For constant index expressions we need only
3826 issue a unconditional branch to the appropriate
3827 target code. The job of removing any unreachable
3828 code is left to the optimisation phase if the
3829 "-O" option is specified. */
3830 for (n
= thiscase
->data
.case_stmt
.case_list
;
3834 if (! tree_int_cst_lt (index_expr
, n
->low
)
3835 && ! tree_int_cst_lt (n
->high
, index_expr
))
3839 emit_jump (label_rtx (n
->code_label
));
3841 emit_jump (default_label
);
3845 /* If the index expression is not constant we generate
3846 a binary decision tree to select the appropriate
3847 target code. This is done as follows:
3849 The list of cases is rearranged into a binary tree,
3850 nearly optimal assuming equal probability for each case.
3852 The tree is transformed into RTL, eliminating
3853 redundant test conditions at the same time.
3855 If program flow could reach the end of the
3856 decision tree an unconditional jump to the
3857 default code is emitted. */
3860 = (TREE_CODE (TREE_TYPE (orig_index
)) != ENUMERAL_TYPE
3861 && estimate_case_costs (thiscase
->data
.case_stmt
.case_list
));
3862 balance_case_nodes (&thiscase
->data
.case_stmt
.case_list
,
3864 emit_case_nodes (index
, thiscase
->data
.case_stmt
.case_list
,
3865 default_label
, TREE_TYPE (index_expr
));
3866 emit_jump_if_reachable (default_label
);
3875 enum machine_mode index_mode
= SImode
;
3876 int index_bits
= GET_MODE_BITSIZE (index_mode
);
3878 /* Convert the index to SImode. */
3879 if (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (index_expr
)))
3880 > GET_MODE_BITSIZE (index_mode
))
3882 enum machine_mode omode
= TYPE_MODE (TREE_TYPE (index_expr
));
3883 rtx rangertx
= expand_expr (range
, NULL_RTX
, VOIDmode
, 0);
3885 /* We must handle the endpoints in the original mode. */
3886 index_expr
= build (MINUS_EXPR
, TREE_TYPE (index_expr
),
3887 index_expr
, minval
);
3888 minval
= integer_zero_node
;
3889 index
= expand_expr (index_expr
, NULL_RTX
, VOIDmode
, 0);
3890 emit_cmp_insn (rangertx
, index
, LTU
, NULL_RTX
, omode
, 0, 0);
3891 emit_jump_insn (gen_bltu (default_label
));
3892 /* Now we can safely truncate. */
3893 index
= convert_to_mode (index_mode
, index
, 0);
3897 if (TYPE_MODE (TREE_TYPE (index_expr
)) != index_mode
)
3898 index_expr
= convert (type_for_size (index_bits
, 0),
3900 index
= expand_expr (index_expr
, NULL_RTX
, VOIDmode
, 0);
3903 index
= protect_from_queue (index
, 0);
3904 do_pending_stack_adjust ();
3906 emit_jump_insn (gen_casesi (index
, expand_expr (minval
, NULL_RTX
,
3908 expand_expr (range
, NULL_RTX
,
3910 table_label
, default_label
));
3914 #ifdef HAVE_tablejump
3915 if (! win
&& HAVE_tablejump
)
3917 index_expr
= convert (thiscase
->data
.case_stmt
.nominal_type
,
3918 fold (build (MINUS_EXPR
,
3919 TREE_TYPE (index_expr
),
3920 index_expr
, minval
)));
3921 index
= expand_expr (index_expr
, NULL_RTX
, VOIDmode
, 0);
3923 index
= protect_from_queue (index
, 0);
3924 do_pending_stack_adjust ();
3926 do_tablejump (index
, TYPE_MODE (TREE_TYPE (index_expr
)),
3927 expand_expr (range
, NULL_RTX
, VOIDmode
, 0),
3928 table_label
, default_label
);
3935 /* Get table of labels to jump to, in order of case index. */
3937 ncases
= TREE_INT_CST_LOW (range
) + 1;
3938 labelvec
= (rtx
*) alloca (ncases
* sizeof (rtx
));
3939 bzero (labelvec
, ncases
* sizeof (rtx
));
3941 for (n
= thiscase
->data
.case_stmt
.case_list
; n
; n
= n
->right
)
3943 register HOST_WIDE_INT i
3944 = TREE_INT_CST_LOW (n
->low
) - TREE_INT_CST_LOW (minval
);
3949 = gen_rtx (LABEL_REF
, Pmode
, label_rtx (n
->code_label
));
3950 if (i
+ TREE_INT_CST_LOW (minval
)
3951 == TREE_INT_CST_LOW (n
->high
))
3957 /* Fill in the gaps with the default. */
3958 for (i
= 0; i
< ncases
; i
++)
3959 if (labelvec
[i
] == 0)
3960 labelvec
[i
] = gen_rtx (LABEL_REF
, Pmode
, default_label
);
3962 /* Output the table */
3963 emit_label (table_label
);
3965 /* This would be a lot nicer if CASE_VECTOR_PC_RELATIVE
3966 were an expression, instead of an #ifdef/#ifndef. */
3968 #ifdef CASE_VECTOR_PC_RELATIVE
3972 emit_jump_insn (gen_rtx (ADDR_DIFF_VEC
, CASE_VECTOR_MODE
,
3973 gen_rtx (LABEL_REF
, Pmode
, table_label
),
3974 gen_rtvec_v (ncases
, labelvec
)));
3976 emit_jump_insn (gen_rtx (ADDR_VEC
, CASE_VECTOR_MODE
,
3977 gen_rtvec_v (ncases
, labelvec
)));
3979 /* If the case insn drops through the table,
3980 after the table we must jump to the default-label.
3981 Otherwise record no drop-through after the table. */
3982 #ifdef CASE_DROPS_THROUGH
3983 emit_jump (default_label
);
3989 before_case
= squeeze_notes (NEXT_INSN (before_case
), get_last_insn ());
3990 reorder_insns (before_case
, get_last_insn (),
3991 thiscase
->data
.case_stmt
.start
);
3993 if (thiscase
->exit_label
)
3994 emit_label (thiscase
->exit_label
);
3996 POPSTACK (case_stack
);
4001 /* Generate code to jump to LABEL if OP1 and OP2 are equal. */
4004 do_jump_if_equal (op1
, op2
, label
, unsignedp
)
4005 rtx op1
, op2
, label
;
4008 if (GET_CODE (op1
) == CONST_INT
4009 && GET_CODE (op2
) == CONST_INT
)
4011 if (INTVAL (op1
) == INTVAL (op2
))
4016 enum machine_mode mode
= GET_MODE (op1
);
4017 if (mode
== VOIDmode
)
4018 mode
= GET_MODE (op2
);
4019 emit_cmp_insn (op1
, op2
, EQ
, NULL_RTX
, mode
, unsignedp
, 0);
4020 emit_jump_insn (gen_beq (label
));
4024 /* Not all case values are encountered equally. This function
4025 uses a heuristic to weight case labels, in cases where that
4026 looks like a reasonable thing to do.
4028 Right now, all we try to guess is text, and we establish the
4031 chars above space: 16
4040 If we find any cases in the switch that are not either -1 or in the range
4041 of valid ASCII characters, or are control characters other than those
4042 commonly used with "\", don't treat this switch scanning text.
4044 Return 1 if these nodes are suitable for cost estimation, otherwise
4048 estimate_case_costs (node
)
4051 tree min_ascii
= build_int_2 (-1, -1);
4052 tree max_ascii
= convert (TREE_TYPE (node
->high
), build_int_2 (127, 0));
4056 /* If we haven't already made the cost table, make it now. Note that the
4057 lower bound of the table is -1, not zero. */
4059 if (cost_table
== NULL
)
4061 cost_table
= ((short *) xmalloc (129 * sizeof (short))) + 1;
4062 bzero (cost_table
- 1, 129 * sizeof (short));
4064 for (i
= 0; i
< 128; i
++)
4068 else if (ispunct (i
))
4070 else if (iscntrl (i
))
4074 cost_table
[' '] = 8;
4075 cost_table
['\t'] = 4;
4076 cost_table
['\0'] = 4;
4077 cost_table
['\n'] = 2;
4078 cost_table
['\f'] = 1;
4079 cost_table
['\v'] = 1;
4080 cost_table
['\b'] = 1;
4083 /* See if all the case expressions look like text. It is text if the
4084 constant is >= -1 and the highest constant is <= 127. Do all comparisons
4085 as signed arithmetic since we don't want to ever access cost_table with a
4086 value less than -1. Also check that none of the constants in a range
4087 are strange control characters. */
4089 for (n
= node
; n
; n
= n
->right
)
4091 if ((INT_CST_LT (n
->low
, min_ascii
)) || INT_CST_LT (max_ascii
, n
->high
))
4094 for (i
= TREE_INT_CST_LOW (n
->low
); i
<= TREE_INT_CST_LOW (n
->high
); i
++)
4095 if (cost_table
[i
] < 0)
4099 /* All interesting values are within the range of interesting
4100 ASCII characters. */
4104 /* Scan an ordered list of case nodes
4105 combining those with consecutive values or ranges.
4107 Eg. three separate entries 1: 2: 3: become one entry 1..3: */
4110 group_case_nodes (head
)
4113 case_node_ptr node
= head
;
4117 rtx lb
= next_real_insn (label_rtx (node
->code_label
));
4118 case_node_ptr np
= node
;
4120 /* Try to group the successors of NODE with NODE. */
4121 while (((np
= np
->right
) != 0)
4122 /* Do they jump to the same place? */
4123 && next_real_insn (label_rtx (np
->code_label
)) == lb
4124 /* Are their ranges consecutive? */
4125 && tree_int_cst_equal (np
->low
,
4126 fold (build (PLUS_EXPR
,
4127 TREE_TYPE (node
->high
),
4130 /* An overflow is not consecutive. */
4131 && tree_int_cst_lt (node
->high
,
4132 fold (build (PLUS_EXPR
,
4133 TREE_TYPE (node
->high
),
4135 integer_one_node
))))
4137 node
->high
= np
->high
;
4139 /* NP is the first node after NODE which can't be grouped with it.
4140 Delete the nodes in between, and move on to that node. */
4146 /* Take an ordered list of case nodes
4147 and transform them into a near optimal binary tree,
4148 on the assumption that any target code selection value is as
4149 likely as any other.
4151 The transformation is performed by splitting the ordered
4152 list into two equal sections plus a pivot. The parts are
4153 then attached to the pivot as left and right branches. Each
4154 branch is is then transformed recursively. */
4157 balance_case_nodes (head
, parent
)
4158 case_node_ptr
*head
;
4159 case_node_ptr parent
;
4161 register case_node_ptr np
;
4169 register case_node_ptr
*npp
;
4172 /* Count the number of entries on branch. Also count the ranges. */
4176 if (!tree_int_cst_equal (np
->low
, np
->high
))
4180 cost
+= cost_table
[TREE_INT_CST_LOW (np
->high
)];
4184 cost
+= cost_table
[TREE_INT_CST_LOW (np
->low
)];
4192 /* Split this list if it is long enough for that to help. */
4197 /* Find the place in the list that bisects the list's total cost,
4198 Here I gets half the total cost. */
4203 /* Skip nodes while their cost does not reach that amount. */
4204 if (!tree_int_cst_equal ((*npp
)->low
, (*npp
)->high
))
4205 i
-= cost_table
[TREE_INT_CST_LOW ((*npp
)->high
)];
4206 i
-= cost_table
[TREE_INT_CST_LOW ((*npp
)->low
)];
4209 npp
= &(*npp
)->right
;
4214 /* Leave this branch lopsided, but optimize left-hand
4215 side and fill in `parent' fields for right-hand side. */
4217 np
->parent
= parent
;
4218 balance_case_nodes (&np
->left
, np
);
4219 for (; np
->right
; np
= np
->right
)
4220 np
->right
->parent
= np
;
4224 /* If there are just three nodes, split at the middle one. */
4226 npp
= &(*npp
)->right
;
4229 /* Find the place in the list that bisects the list's total cost,
4230 where ranges count as 2.
4231 Here I gets half the total cost. */
4232 i
= (i
+ ranges
+ 1) / 2;
4235 /* Skip nodes while their cost does not reach that amount. */
4236 if (!tree_int_cst_equal ((*npp
)->low
, (*npp
)->high
))
4241 npp
= &(*npp
)->right
;
4246 np
->parent
= parent
;
4249 /* Optimize each of the two split parts. */
4250 balance_case_nodes (&np
->left
, np
);
4251 balance_case_nodes (&np
->right
, np
);
4255 /* Else leave this branch as one level,
4256 but fill in `parent' fields. */
4258 np
->parent
= parent
;
4259 for (; np
->right
; np
= np
->right
)
4260 np
->right
->parent
= np
;
4265 /* Search the parent sections of the case node tree
4266 to see if a test for the lower bound of NODE would be redundant.
4267 INDEX_TYPE is the type of the index expression.
4269 The instructions to generate the case decision tree are
4270 output in the same order as nodes are processed so it is
4271 known that if a parent node checks the range of the current
4272 node minus one that the current node is bounded at its lower
4273 span. Thus the test would be redundant. */
4276 node_has_low_bound (node
, index_type
)
4281 case_node_ptr pnode
;
4283 /* If the lower bound of this node is the lowest value in the index type,
4284 we need not test it. */
4286 if (tree_int_cst_equal (node
->low
, TYPE_MIN_VALUE (index_type
)))
4289 /* If this node has a left branch, the value at the left must be less
4290 than that at this node, so it cannot be bounded at the bottom and
4291 we need not bother testing any further. */
4296 low_minus_one
= fold (build (MINUS_EXPR
, TREE_TYPE (node
->low
),
4297 node
->low
, integer_one_node
));
4299 /* If the subtraction above overflowed, we can't verify anything.
4300 Otherwise, look for a parent that tests our value - 1. */
4302 if (! tree_int_cst_lt (low_minus_one
, node
->low
))
4305 for (pnode
= node
->parent
; pnode
; pnode
= pnode
->parent
)
4306 if (tree_int_cst_equal (low_minus_one
, pnode
->high
))
4312 /* Search the parent sections of the case node tree
4313 to see if a test for the upper bound of NODE would be redundant.
4314 INDEX_TYPE is the type of the index expression.
4316 The instructions to generate the case decision tree are
4317 output in the same order as nodes are processed so it is
4318 known that if a parent node checks the range of the current
4319 node plus one that the current node is bounded at its upper
4320 span. Thus the test would be redundant. */
4323 node_has_high_bound (node
, index_type
)
4328 case_node_ptr pnode
;
4330 /* If the upper bound of this node is the highest value in the type
4331 of the index expression, we need not test against it. */
4333 if (tree_int_cst_equal (node
->high
, TYPE_MAX_VALUE (index_type
)))
4336 /* If this node has a right branch, the value at the right must be greater
4337 than that at this node, so it cannot be bounded at the top and
4338 we need not bother testing any further. */
4343 high_plus_one
= fold (build (PLUS_EXPR
, TREE_TYPE (node
->high
),
4344 node
->high
, integer_one_node
));
4346 /* If the addition above overflowed, we can't verify anything.
4347 Otherwise, look for a parent that tests our value + 1. */
4349 if (! tree_int_cst_lt (node
->high
, high_plus_one
))
4352 for (pnode
= node
->parent
; pnode
; pnode
= pnode
->parent
)
4353 if (tree_int_cst_equal (high_plus_one
, pnode
->low
))
4359 /* Search the parent sections of the
4360 case node tree to see if both tests for the upper and lower
4361 bounds of NODE would be redundant. */
4364 node_is_bounded (node
, index_type
)
4368 return (node_has_low_bound (node
, index_type
)
4369 && node_has_high_bound (node
, index_type
));
4372 /* Emit an unconditional jump to LABEL unless it would be dead code. */
4375 emit_jump_if_reachable (label
)
4378 if (GET_CODE (get_last_insn ()) != BARRIER
)
4382 /* Emit step-by-step code to select a case for the value of INDEX.
4383 The thus generated decision tree follows the form of the
4384 case-node binary tree NODE, whose nodes represent test conditions.
4385 INDEX_TYPE is the type of the index of the switch.
4387 Care is taken to prune redundant tests from the decision tree
4388 by detecting any boundary conditions already checked by
4389 emitted rtx. (See node_has_high_bound, node_has_low_bound
4390 and node_is_bounded, above.)
4392 Where the test conditions can be shown to be redundant we emit
4393 an unconditional jump to the target code. As a further
4394 optimization, the subordinates of a tree node are examined to
4395 check for bounded nodes. In this case conditional and/or
4396 unconditional jumps as a result of the boundary check for the
4397 current node are arranged to target the subordinates associated
4398 code for out of bound conditions on the current node node.
4400 We can assume that when control reaches the code generated here,
4401 the index value has already been compared with the parents
4402 of this node, and determined to be on the same side of each parent
4403 as this node is. Thus, if this node tests for the value 51,
4404 and a parent tested for 52, we don't need to consider
4405 the possibility of a value greater than 51. If another parent
4406 tests for the value 50, then this node need not test anything. */
4409 emit_case_nodes (index
, node
, default_label
, index_type
)
4415 /* If INDEX has an unsigned type, we must make unsigned branches. */
4416 int unsignedp
= TREE_UNSIGNED (index_type
);
4417 typedef rtx
rtx_function ();
4418 rtx_function
*gen_bgt_pat
= unsignedp
? gen_bgtu
: gen_bgt
;
4419 rtx_function
*gen_bge_pat
= unsignedp
? gen_bgeu
: gen_bge
;
4420 rtx_function
*gen_blt_pat
= unsignedp
? gen_bltu
: gen_blt
;
4421 rtx_function
*gen_ble_pat
= unsignedp
? gen_bleu
: gen_ble
;
4422 enum machine_mode mode
= GET_MODE (index
);
4424 /* See if our parents have already tested everything for us.
4425 If they have, emit an unconditional jump for this node. */
4426 if (node_is_bounded (node
, index_type
))
4427 emit_jump (label_rtx (node
->code_label
));
4429 else if (tree_int_cst_equal (node
->low
, node
->high
))
4431 /* Node is single valued. First see if the index expression matches
4432 this node and then check our children, if any. */
4434 do_jump_if_equal (index
, expand_expr (node
->low
, NULL_RTX
, VOIDmode
, 0),
4435 label_rtx (node
->code_label
), unsignedp
);
4437 if (node
->right
!= 0 && node
->left
!= 0)
4439 /* This node has children on both sides.
4440 Dispatch to one side or the other
4441 by comparing the index value with this node's value.
4442 If one subtree is bounded, check that one first,
4443 so we can avoid real branches in the tree. */
4445 if (node_is_bounded (node
->right
, index_type
))
4447 emit_cmp_insn (index
, expand_expr (node
->high
, NULL_RTX
,
4449 GT
, NULL_RTX
, mode
, unsignedp
, 0);
4451 emit_jump_insn ((*gen_bgt_pat
) (label_rtx (node
->right
->code_label
)));
4452 emit_case_nodes (index
, node
->left
, default_label
, index_type
);
4455 else if (node_is_bounded (node
->left
, index_type
))
4457 emit_cmp_insn (index
, expand_expr (node
->high
, NULL_RTX
,
4459 LT
, NULL_RTX
, mode
, unsignedp
, 0);
4460 emit_jump_insn ((*gen_blt_pat
) (label_rtx (node
->left
->code_label
)));
4461 emit_case_nodes (index
, node
->right
, default_label
, index_type
);
4466 /* Neither node is bounded. First distinguish the two sides;
4467 then emit the code for one side at a time. */
4470 = build_decl (LABEL_DECL
, NULL_TREE
, NULL_TREE
);
4472 /* See if the value is on the right. */
4473 emit_cmp_insn (index
, expand_expr (node
->high
, NULL_RTX
,
4475 GT
, NULL_RTX
, mode
, unsignedp
, 0);
4476 emit_jump_insn ((*gen_bgt_pat
) (label_rtx (test_label
)));
4478 /* Value must be on the left.
4479 Handle the left-hand subtree. */
4480 emit_case_nodes (index
, node
->left
, default_label
, index_type
);
4481 /* If left-hand subtree does nothing,
4483 emit_jump_if_reachable (default_label
);
4485 /* Code branches here for the right-hand subtree. */
4486 expand_label (test_label
);
4487 emit_case_nodes (index
, node
->right
, default_label
, index_type
);
4491 else if (node
->right
!= 0 && node
->left
== 0)
4493 /* Here we have a right child but no left so we issue conditional
4494 branch to default and process the right child.
4496 Omit the conditional branch to default if we it avoid only one
4497 right child; it costs too much space to save so little time. */
4499 if (node
->right
->right
|| node
->right
->left
4500 || !tree_int_cst_equal (node
->right
->low
, node
->right
->high
))
4502 if (!node_has_low_bound (node
, index_type
))
4504 emit_cmp_insn (index
, expand_expr (node
->high
, NULL_RTX
,
4506 LT
, NULL_RTX
, mode
, unsignedp
, 0);
4507 emit_jump_insn ((*gen_blt_pat
) (default_label
));
4510 emit_case_nodes (index
, node
->right
, default_label
, index_type
);
4513 /* We cannot process node->right normally
4514 since we haven't ruled out the numbers less than
4515 this node's value. So handle node->right explicitly. */
4516 do_jump_if_equal (index
,
4517 expand_expr (node
->right
->low
, NULL_RTX
,
4519 label_rtx (node
->right
->code_label
), unsignedp
);
4522 else if (node
->right
== 0 && node
->left
!= 0)
4524 /* Just one subtree, on the left. */
4526 #if 0 /* The following code and comment were formerly part
4527 of the condition here, but they didn't work
4528 and I don't understand what the idea was. -- rms. */
4529 /* If our "most probable entry" is less probable
4530 than the default label, emit a jump to
4531 the default label using condition codes
4532 already lying around. With no right branch,
4533 a branch-greater-than will get us to the default
4536 && cost_table
[TREE_INT_CST_LOW (node
->high
)] < 12)
4539 if (node
->left
->left
|| node
->left
->right
4540 || !tree_int_cst_equal (node
->left
->low
, node
->left
->high
))
4542 if (!node_has_high_bound (node
, index_type
))
4544 emit_cmp_insn (index
, expand_expr (node
->high
, NULL_RTX
,
4546 GT
, NULL_RTX
, mode
, unsignedp
, 0);
4547 emit_jump_insn ((*gen_bgt_pat
) (default_label
));
4550 emit_case_nodes (index
, node
->left
, default_label
, index_type
);
4553 /* We cannot process node->left normally
4554 since we haven't ruled out the numbers less than
4555 this node's value. So handle node->left explicitly. */
4556 do_jump_if_equal (index
,
4557 expand_expr (node
->left
->low
, NULL_RTX
,
4559 label_rtx (node
->left
->code_label
), unsignedp
);
4564 /* Node is a range. These cases are very similar to those for a single
4565 value, except that we do not start by testing whether this node
4566 is the one to branch to. */
4568 if (node
->right
!= 0 && node
->left
!= 0)
4570 /* Node has subtrees on both sides.
4571 If the right-hand subtree is bounded,
4572 test for it first, since we can go straight there.
4573 Otherwise, we need to make a branch in the control structure,
4574 then handle the two subtrees. */
4575 tree test_label
= 0;
4577 emit_cmp_insn (index
, expand_expr (node
->high
, NULL_RTX
,
4579 GT
, NULL_RTX
, mode
, unsignedp
, 0);
4581 if (node_is_bounded (node
->right
, index_type
))
4582 /* Right hand node is fully bounded so we can eliminate any
4583 testing and branch directly to the target code. */
4584 emit_jump_insn ((*gen_bgt_pat
) (label_rtx (node
->right
->code_label
)));
4587 /* Right hand node requires testing.
4588 Branch to a label where we will handle it later. */
4590 test_label
= build_decl (LABEL_DECL
, NULL_TREE
, NULL_TREE
);
4591 emit_jump_insn ((*gen_bgt_pat
) (label_rtx (test_label
)));
4594 /* Value belongs to this node or to the left-hand subtree. */
4596 emit_cmp_insn (index
, expand_expr (node
->low
, NULL_RTX
, VOIDmode
, 0),
4597 GE
, NULL_RTX
, mode
, unsignedp
, 0);
4598 emit_jump_insn ((*gen_bge_pat
) (label_rtx (node
->code_label
)));
4600 /* Handle the left-hand subtree. */
4601 emit_case_nodes (index
, node
->left
, default_label
, index_type
);
4603 /* If right node had to be handled later, do that now. */
4607 /* If the left-hand subtree fell through,
4608 don't let it fall into the right-hand subtree. */
4609 emit_jump_if_reachable (default_label
);
4611 expand_label (test_label
);
4612 emit_case_nodes (index
, node
->right
, default_label
, index_type
);
4616 else if (node
->right
!= 0 && node
->left
== 0)
4618 /* Deal with values to the left of this node,
4619 if they are possible. */
4620 if (!node_has_low_bound (node
, index_type
))
4622 emit_cmp_insn (index
, expand_expr (node
->low
, NULL_RTX
,
4624 LT
, NULL_RTX
, mode
, unsignedp
, 0);
4625 emit_jump_insn ((*gen_blt_pat
) (default_label
));
4628 /* Value belongs to this node or to the right-hand subtree. */
4630 emit_cmp_insn (index
, expand_expr (node
->high
, NULL_RTX
,
4632 LE
, NULL_RTX
, mode
, unsignedp
, 0);
4633 emit_jump_insn ((*gen_ble_pat
) (label_rtx (node
->code_label
)));
4635 emit_case_nodes (index
, node
->right
, default_label
, index_type
);
4638 else if (node
->right
== 0 && node
->left
!= 0)
4640 /* Deal with values to the right of this node,
4641 if they are possible. */
4642 if (!node_has_high_bound (node
, index_type
))
4644 emit_cmp_insn (index
, expand_expr (node
->high
, NULL_RTX
,
4646 GT
, NULL_RTX
, mode
, unsignedp
, 0);
4647 emit_jump_insn ((*gen_bgt_pat
) (default_label
));
4650 /* Value belongs to this node or to the left-hand subtree. */
4652 emit_cmp_insn (index
, expand_expr (node
->low
, NULL_RTX
, VOIDmode
, 0),
4653 GE
, NULL_RTX
, mode
, unsignedp
, 0);
4654 emit_jump_insn ((*gen_bge_pat
) (label_rtx (node
->code_label
)));
4656 emit_case_nodes (index
, node
->left
, default_label
, index_type
);
4661 /* Node has no children so we check low and high bounds to remove
4662 redundant tests. Only one of the bounds can exist,
4663 since otherwise this node is bounded--a case tested already. */
4665 if (!node_has_high_bound (node
, index_type
))
4667 emit_cmp_insn (index
, expand_expr (node
->high
, NULL_RTX
,
4669 GT
, NULL_RTX
, mode
, unsignedp
, 0);
4670 emit_jump_insn ((*gen_bgt_pat
) (default_label
));
4673 if (!node_has_low_bound (node
, index_type
))
4675 emit_cmp_insn (index
, expand_expr (node
->low
, NULL_RTX
,
4677 LT
, NULL_RTX
, mode
, unsignedp
, 0);
4678 emit_jump_insn ((*gen_blt_pat
) (default_label
));
4681 emit_jump (label_rtx (node
->code_label
));
4686 /* These routines are used by the loop unrolling code. They copy BLOCK trees
4687 so that the debugging info will be correct for the unrolled loop. */
4689 /* Indexed by block number, contains a pointer to the N'th block node. */
4691 static tree
*block_vector
;
4694 find_loop_tree_blocks ()
4696 tree block
= DECL_INITIAL (current_function_decl
);
4698 /* There first block is for the function body, and does not have
4699 corresponding block notes. Don't include it in the block vector. */
4700 block
= BLOCK_SUBBLOCKS (block
);
4702 block_vector
= identify_blocks (block
, get_insns ());
4706 unroll_block_trees ()
4708 tree block
= DECL_INITIAL (current_function_decl
);
4710 reorder_blocks (block_vector
, block
, get_insns ());