home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / g__src3 / stmt.c < prev    next >
C/C++ Source or Header  |  1993-07-23  |  144KB  |  4,630 lines

  1. /* Expands front end tree to back end RTL for GNU C-Compiler
  2.    Copyright (C) 1987, 1988, 1989 Free Software Foundation, Inc.
  3.    Hacked by Michael Tiemann (tiemann@mcc.com)
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 1, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21.  
  22. /* This file handles the generation of rtl code from tree structure
  23.    above the level of expressions, using subroutines in exp*.c and emit-rtl.c.
  24.    It also creates the rtl expressions for parameters and auto variables
  25.    and has full responsibility for allocating stack slots.
  26.  
  27.    The functions whose names start with `expand_' are called by the
  28.    parser to generate RTL instructions for various kinds of constructs.
  29.  
  30.    Some control and binding constructs require calling several such
  31.    functions at different times.  For example, a simple if-then
  32.    is expanded by calling `expand_start_cond' (with the condition-expression
  33.    as argument) before parsing the then-clause and calling `expand_end_cond'
  34.    after parsing the then-clause.
  35.  
  36.    `expand_function_start' is called at the beginning of a function,
  37.    before the function body is parsed, and `expand_function_end' is
  38.    called after parsing the body.
  39.  
  40.    Call `assign_stack_local' to allocate a stack slot for a local variable.
  41.    This is usually done during the RTL generation for the function body,
  42.    but it can also be done in the reload pass when a pseudo-register does
  43.    not get a hard register.
  44.  
  45.    Call `put_var_into_stack' when you learn, belatedly, that a variable
  46.    previously given a pseudo-register must in fact go in the stack.
  47.    This function changes the DECL_RTL to be a stack slot instead of a reg
  48.    then scans all the RTL instructions so far generated to correct them.  */
  49.  
  50. #include "config.h"
  51.  
  52. #include <stdio.h>
  53.  
  54. #include "rtl.h"
  55. #include "tree.h"
  56. #include "flags.h"
  57. #include "insn-flags.h"
  58. #include "insn-config.h"
  59. #include "expr.h"
  60. #include "regs.h"
  61. #include "assert.h"
  62.  
  63. #define MAX(x,y) (((x) > (y)) ? (x) : (y))
  64. #define MIN(x,y) (((x) < (y)) ? (x) : (y))
  65.  
  66. /* Nonzero if function being compiled pops its args on return.
  67.    May affect compilation of return insn or of function epilogue.  */
  68.  
  69. int current_function_pops_args;
  70.  
  71. /* Nonzero if function being compiled needs to be given an address
  72.    where the value should be stored.  */
  73.  
  74. int current_function_returns_struct;
  75.  
  76. /* Nonzero if function being compiled needs to
  77.    return the address of where it has put a structure value.  */
  78.  
  79. int current_function_returns_pcc_struct;
  80.  
  81. /* Nonzero if function being compiled needs to be passed a static chain.  */
  82.  
  83. int current_function_needs_context;
  84.  
  85. /* Nonzero if function being compiled can call setjmp.  */
  86.  
  87. int current_function_calls_setjmp;
  88.  
  89. /* If function's args have a fixed size, this is that size, in bytes.
  90.    Otherwise, it is -1.
  91.    May affect compilation of return insn or of function epilogue.  */
  92.  
  93. int current_function_args_size;
  94.  
  95. /* # bytes the prologue should push and pretend that the caller pushed them.
  96.    The prologue must do this, but only if parms can be passed in registers.  */
  97.  
  98. int current_function_pretend_args_size;
  99.  
  100. /* Name of function now being compiled.  */
  101.  
  102. char *current_function_name;
  103.  
  104. /* Label that will go on cleanup code, if any.
  105.    Jumping to this label runs cleanup code for parameters, if
  106.    such code must be run.  Following this code is the logical return label.  */
  107.  
  108. rtx cleanup_label;
  109.  
  110. /* Label that will go on function epilogue.
  111.    Jumping to this label serves as a "return" instruction
  112.    on machines which require execution of the epilogue on all returns.  */
  113.  
  114. rtx return_label;
  115.  
  116. /* List (chain of EXPR_LISTs) of pseudo-regs of SAVE_EXPRs.
  117.    So we can mark them all live at the end of the function, if nonopt.  */
  118. rtx save_expr_regs;
  119.  
  120. /* List (chain of EXPR_LISTs) of all stack slots in this function.
  121.    Made for the sake of unshare_all_rtl.  */
  122. rtx stack_slot_list;
  123.  
  124. /* Filename and line number of last line-number note,
  125.    whether we actually emitted it or not.  */
  126. char *emit_filename;
  127. int emit_lineno;
  128.  
  129. /* Insn after which register parms and SAVE_EXPRs are born, if nonopt.  */
  130. static rtx parm_birth_insn;
  131.  
  132. /* The FUNCTION_DECL node for the function being compiled.  */
  133.  
  134. static tree this_function;
  135.  
  136. /* Offset to end of allocated area of stack frame.
  137.    If stack grows down, this is the address of the last stack slot allocated.
  138.    If stack grows up, this is the address for the next slot.  */
  139. static int frame_offset;
  140.  
  141. /* Nonzero if a stack slot has been generated whose address is not
  142.    actually valid.  It means that the generated rtl must all be scanned
  143.    to detect and correct the invalid addresses where they occur.  */
  144. static int invalid_stack_slot;
  145.  
  146. /* Label to jump back to for tail recursion, or 0 if we have
  147.    not yet needed one for this function.  */
  148. static rtx tail_recursion_label;
  149.  
  150. /* Place after which to insert the tail_recursion_label if we need one.  */
  151. static rtx tail_recursion_reentry;
  152.  
  153. /* Each time we expand an expression-statement,
  154.    record the expr's type and its RTL value here.  */
  155.  
  156. static tree last_expr_type;
  157. static rtx last_expr_value;
  158.  
  159. /* Chain of all RTL_EXPRs that have insns in them.  */
  160. static tree rtl_expr_chain;
  161.  
  162. /* Last insn of those whose job was to put parms into their nominal homes.  */
  163. static rtx last_parm_insn;
  164.  
  165. static void expand_goto_internal ();
  166. static int expand_fixup ();
  167. static void fixup_gotos ();
  168. static void expand_cleanups ();
  169. static void fixup_cleanups ();
  170. static void expand_null_return_1 ();
  171. static int tail_recursion_args ();
  172. static void fixup_stack_slots ();
  173. static rtx fixup_stack_1 ();
  174. static rtx fixup_memory_subreg ();
  175. static rtx walk_fixup_memory_subreg ();
  176. static void fixup_var_refs ();
  177. static void fixup_var_refs_insns ();
  178. static rtx fixup_var_refs_1 ();
  179. static rtx parm_stack_loc ();
  180. static void optimize_bit_field ();
  181. static void do_jump_if_equal ();
  182.  
  183. /* Functions and data structures for expanding case statements.  */
  184.  
  185. static void balance_case_nodes ();
  186. static void emit_case_nodes ();
  187. static void group_case_nodes ();
  188. static void emit_jump_if_reachable ();
  189.  
  190. /* Case label structure, used to hold info on labels within case
  191.    statements.  We handle "range" labels; for a single-value label
  192.    as in C, the high and low limits are the same.  */
  193.  
  194. struct case_node
  195. {
  196.   struct case_node    *left;
  197.   struct case_node    *right;
  198.   struct case_node    *parent;
  199.   tree            low;
  200.   tree            high;
  201.   tree            test_label;
  202.   tree            code_label;
  203. };
  204.  
  205. typedef struct case_node case_node;
  206. typedef struct case_node *case_node_ptr;
  207.  
  208. /* Stack of control and binding constructs we are currently inside.
  209.  
  210.    These constructs begin when you call `expand_start_WHATEVER'
  211.    and end when you call `expand_end_WHATEVER'.  This stack records
  212.    info about how the construct began that tells the end-function
  213.    what to do.  It also may provide information about the construct
  214.    to alter the behavior of other constructs within the body.
  215.    For example, they may affect the behavior of C `break' and `continue'.
  216.  
  217.    Each construct gets one `struct nesting' object.
  218.    All of these objects are chained through the `all' field.
  219.    `nesting_stack' points to the first object (innermost construct).
  220.    The position of an entry on `nesting_stack' is in its `depth' field.
  221.  
  222.    Each type of construct has its own individual stack.
  223.    For example, loops have `loop_stack'.  Each object points to the
  224.    next object of the same type through the `next' field.
  225.  
  226.    Some constructs are visible to `break' exit-statements and others
  227.    are not.  Which constructs are visible depends on the language.
  228.    Therefore, the data structure allows each construct to be visible
  229.    or not, according to the args given when the construct is started.
  230.    The construct is visible if the `exit_label' field is non-null.
  231.    In that case, the value should be a CODE_LABEL rtx.  */
  232.  
  233. struct nesting
  234. {
  235.   struct nesting *all;
  236.   struct nesting *next;
  237.   int depth;
  238.   rtx exit_label;
  239.   union
  240.     {
  241.       /* For conds (if-then and if-then-else statements).  */
  242.       struct
  243.     {
  244.       /* Label on the else-part, if any, else 0.  */
  245.       rtx else_label;
  246.       /* Label at the end of the whole construct.  */
  247.       rtx after_label;
  248.     } cond;
  249.       /* For loops.  */
  250.       struct
  251.     {
  252.       /* Label at the top of the loop; place to loop back to.  */
  253.       rtx start_label;
  254.       /* Label at the end of the whole construct.  */
  255.       rtx end_label;
  256.       /* Label for `continue' statement to jump to;
  257.          this is in front of the stepper of the loop.  */
  258.       rtx continue_label;
  259.     } loop;
  260.       /* For variable binding contours.  */
  261.       struct
  262.     {
  263.       /* Nonzero => value to restore stack to on exit.  */
  264.       rtx stack_level;
  265.       /* The NOTE that starts this contour.
  266.          Used by expand_goto to check whether the destination
  267.          is within each contour or not.  */
  268.       rtx first_insn;
  269.       /* Innermost containing binding contour that has a stack level.  */
  270.       struct nesting *innermost_stack_block;
  271.       /* List of cleanups to be run on exit from this contour.
  272.          This is a list of expressions to be evaluated.
  273.          The TREE_PURPOSE of each link is the ..._DECL node
  274.          which the cleanup pertains to.  */
  275.       tree cleanups;
  276.       /* List of cleanup-lists of blocks containing this block,
  277.          as they were at the locus where this block appears.
  278.          There is an element for each containing block,
  279.          ordered innermost containing block first.
  280.          The element's TREE_VALUE is the cleanup-list of that block,
  281.          which may be null.  */
  282.       tree outer_cleanups;
  283.       /* Chain of labels defined inside this binding contour.
  284.          For contours that have stack levels or cleanups.  */
  285.       struct label_chain *label_chain;
  286.     } block;
  287.       /* For switch (C) or case (Pascal) statements,
  288.      and also for dummies (see `expand_start_case_dummy').  */
  289.       struct
  290.     {
  291.       /* The insn after which the case dispatch should finally
  292.          be emitted.  Zero for a dummy.  */
  293.       rtx start;
  294.       /* A list of case labels, kept in ascending order by value
  295.          as the list is built.
  296.          During expand_end_case, this list may be rearranged into a
  297.          nearly balanced binary tree.  */
  298.       struct case_node *case_list;
  299.       /* Label to jump to if no case matches.  */
  300.       tree default_label;
  301.       /* The expression to be dispatched on.  */
  302.       tree index_expr;
  303.       /* Type that INDEX_EXPR should be converted to.  */
  304.       tree nominal_type;
  305.       /* Number of range exprs in case statement.  */
  306.       short num_ranges;
  307.     } case_stmt;
  308.     } data;
  309. };
  310.  
  311. /* Chain of all pending binding contours.  */
  312. struct nesting *block_stack;
  313.  
  314. /* Chain of all pending binding contours that restore stack levels
  315.    or have cleanups.  */
  316. struct nesting *stack_block_stack;
  317.  
  318. /* Chain of all pending conditional statements.  */
  319. struct nesting *cond_stack;
  320.  
  321. /* Chain of all pending loops.  */
  322. struct nesting *loop_stack;
  323.  
  324. /* Chain of all pending case or switch statements.  */
  325. struct nesting *case_stack;
  326.  
  327. /* Separate chain including all of the above,
  328.    chained through the `all' field.  */
  329. struct nesting *nesting_stack;
  330.  
  331. /* Number of entries on nesting_stack now.  */
  332. int nesting_depth;
  333.  
  334. /* Pop one of the sub-stacks, such as `loop_stack' or `cond_stack';
  335.    and pop off `nesting_stack' down to the same level.  */
  336.  
  337. #define POPSTACK(STACK)                    \
  338. do { int initial_depth = nesting_stack->depth;        \
  339.      do { struct nesting *this = STACK;            \
  340.       STACK = this->next;                \
  341.       nesting_stack = this->all;            \
  342.       nesting_depth = this->depth;            \
  343.       free (this); }                \
  344.      while (nesting_depth > initial_depth); } while (0)
  345.  
  346. /* Emit a no-op instruction.  */
  347.  
  348. rtx
  349. emit_nop ()
  350. {
  351. #if 0
  352.   rtx last_insn = get_last_insn ();
  353.   /* for now this does nothing.  */
  354.   if (!optimize
  355.       && (GET_CODE (last_insn) == CODE_LABEL
  356.       || prev_real_insn (last_insn) == 0))
  357.     emit_insn (gen_nop ());
  358. #endif
  359. }
  360.  
  361. /* Return the rtx-label that corresponds to a LABEL_DECL,
  362.    creating it if necessary.  */
  363.  
  364. static rtx
  365. label_rtx (label)
  366.      tree label;
  367. {
  368.   if (TREE_CODE (label) != LABEL_DECL)
  369.     abort ();
  370.  
  371.   if (DECL_RTL (label))
  372.     return DECL_RTL (label);
  373.  
  374.   return DECL_RTL (label) = gen_label_rtx ();
  375. }
  376.  
  377. /* Add an unconditional jump to LABEL as the next sequential instruction.  */
  378.  
  379. void
  380. emit_jump (label)
  381.      rtx label;
  382. {
  383.   do_pending_stack_adjust ();
  384.   emit_jump_insn (gen_jump (label));
  385.   emit_barrier ();
  386. }
  387.  
  388. /* Handle goto statements and the labels that they can go to.  */
  389.  
  390. /* In some cases it is impossible to generate code for a forward goto 
  391.    until the label definition is seen.  This happens when it may be necessary
  392.    for the goto to reset the stack pointer: we don't yet know how to do that.
  393.    So expand_goto puts an entry on this fixup list.
  394.    Each time a binding contour that resets the stack is exited,
  395.    we check each fixup.
  396.    If the target label has now been defined, we can insert the proper code.  */
  397.  
  398. struct goto_fixup
  399. {
  400.   /* Points to following fixup.  */
  401.   struct goto_fixup *next;
  402.   /* Points to the insn before the jump insn.
  403.      If more code must be inserted, it goes after this insn.  */
  404.   rtx before_jump;
  405.   /* The LABEL_DECL that this jump is jumping to, or 0
  406.      for break, continue or return.  */
  407.   tree target;
  408.   /* The CODE_LABEL rtx that this is jumping to.  */
  409.   rtx target_rtl;
  410.   /* The outermost stack level that should be restored for this jump.
  411.      Each time a binding contour that resets the stack is exited,
  412.      if the target label is *not* yet defined, this slot is updated.  */
  413.   rtx stack_level;
  414.   /* List of lists of cleanup expressions to be run by this goto.
  415.      There is one element for each block that this goto is within.
  416.      The TREE_VALUE contains the cleanup list of that block as of the
  417.      time this goto was seen.
  418.      The TREE_ADDRESSABLE flag is 1 for a block that has been exited.  */
  419.   tree cleanup_list_list;
  420. };
  421.  
  422. static struct goto_fixup *goto_fixup_chain;
  423.  
  424. /* Within any binding contour that must restore a stack level,
  425.    all labels are recorded with a chain of these structures.  */
  426.  
  427. struct label_chain
  428. {
  429.   /* Points to following fixup.  */
  430.   struct label_chain *next;
  431.   tree label;
  432. };
  433.  
  434. /* Specify the location in the RTL code of a label BODY,
  435.    which is a LABEL_DECL tree node.
  436.  
  437.    This is used for the kind of label that the user can jump to with a
  438.    goto statement, and for alternatives of a switch or case statement.
  439.    RTL labels generated for loops and conditionals don't go through here;
  440.    they are generated directly at the RTL level, by other functions below.
  441.  
  442.    Note that this has nothing to do with defining label *names*.
  443.    Languages vary in how they do that and what that even means.  */
  444.  
  445. void
  446. expand_label (body)
  447.      tree body;
  448. {
  449.   struct label_chain *p;
  450.  
  451.   do_pending_stack_adjust ();
  452.   emit_label (label_rtx (body));
  453.  
  454.   if (stack_block_stack != 0)
  455.     {
  456.       p = (struct label_chain *) oballoc (sizeof (struct label_chain));
  457.       p->next = stack_block_stack->data.block.label_chain;
  458.       stack_block_stack->data.block.label_chain = p;
  459.       p->label = body;
  460.     }
  461. }
  462.  
  463. /* Generate RTL code for a `goto' statement with target label BODY.
  464.    BODY should be a LABEL_DECL tree node that was or will later be
  465.    defined with `expand_label'.  */
  466.  
  467. void
  468. expand_goto (body)
  469.      tree body;
  470. {
  471.   expand_goto_internal (body, label_rtx (body), 0);
  472. }
  473.  
  474. /* Generate RTL code for a `goto' statement with target label BODY.
  475.    LABEL should be a LABEL_REF.
  476.    LAST_INSN, if non-0, is the rtx we should consider as the last
  477.    insn emitted (for the purposes of cleaning up a return).  */
  478.  
  479. static void
  480. expand_goto_internal (body, label, last_insn)
  481.      tree body;
  482.      rtx label;
  483.      rtx last_insn;
  484. {
  485.   struct nesting *block;
  486.   rtx stack_level = 0;
  487.  
  488.   if (GET_CODE (label) != CODE_LABEL)
  489.     abort ();
  490.  
  491.   /* If label has already been defined, we can tell now
  492.      whether and how we must alter the stack level.  */
  493.  
  494.   if (PREV_INSN (label) != 0)
  495.     {
  496.       /* Find the innermost pending block that contains the label.
  497.      (Check containment by comparing insn-uids.)
  498.      Then restore the outermost stack level within that block,
  499.      and do cleanups of all blocks contained in it.  */
  500.       for (block = block_stack; block; block = block->next)
  501.     {
  502.       if (INSN_UID (block->data.block.first_insn) < INSN_UID (label))
  503.         break;
  504.       if (block->data.block.stack_level != 0)
  505.         stack_level = block->data.block.stack_level;
  506.       /* Execute the cleanups for blocks we are exiting.  */
  507.       if (block->data.block.cleanups != 0)
  508.         expand_cleanups (block->data.block.cleanups, 0);
  509.     }
  510.  
  511.       if (stack_level)
  512.     emit_move_insn (stack_pointer_rtx, stack_level);
  513.  
  514.       if (body != 0 && TREE_PACKED (body))
  515.     error ("jump to `%s' invalidly jumps into binding contour",
  516.            IDENTIFIER_POINTER (DECL_NAME (body)));
  517.     }
  518.   /* Label not yet defined: may need to put this goto
  519.      on the fixup list.  */
  520.   else if (! expand_fixup (body, label, last_insn))
  521.     {
  522.       /* No fixup needed.  Record that the label is the target
  523.      of at least one goto that has no fixup.  */
  524.       if (body != 0)
  525.     TREE_ADDRESSABLE (body) = 1;
  526.     }
  527.  
  528.   emit_jump (label);
  529. }
  530.  
  531. /* Generate if necessary a fixup for a goto
  532.    whose target label in tree structure (if any) is TREE_LABEL
  533.    and whose target in rtl is RTL_LABEL.
  534.  
  535.    If LAST_INSN is nonzero, we pretend that the jump appears
  536.    after insn LAST_INSN instead of at the current point in the insn stream.
  537.  
  538.    The fixup will be used later to insert insns at this point
  539.    to restore the stack level as appropriate for the target label.
  540.  
  541.    Value is nonzero if a fixup is made.  */
  542.  
  543. static int
  544. expand_fixup (tree_label, rtl_label, last_insn)
  545.      tree tree_label;
  546.      rtx rtl_label;
  547.      rtx last_insn;
  548. {
  549.   struct nesting *block, *end_block;
  550.  
  551.   /* See if we can recognize which block the label will be output in.
  552.      This is possible in some very common cases.
  553.      If we succeed, set END_BLOCK to that block.
  554.      Otherwise, set it to 0.  */
  555.  
  556.   if (cond_stack
  557.       && (rtl_label == cond_stack->data.cond.else_label
  558.       || rtl_label == cond_stack->data.cond.after_label))
  559.     end_block = cond_stack;
  560.   /* If we are in a loop, recognize certain labels which
  561.      are likely targets.  This reduces the number of fixups
  562.      we need to create.  */
  563.   else if (loop_stack
  564.       && (rtl_label == loop_stack->data.loop.start_label
  565.       || rtl_label == loop_stack->data.loop.end_label
  566.       || rtl_label == loop_stack->data.loop.continue_label))
  567.     end_block = loop_stack;
  568.   else
  569.     end_block = 0;
  570.  
  571.   /* Now set END_BLOCK to the binding level to which we will return.  */
  572.  
  573.   if (end_block)
  574.     {
  575.       struct nesting *next_block = end_block->all;
  576.       block = block_stack;
  577.  
  578.       /* First see if the END_BLOCK is inside the innermost binding level.
  579.      If so, then no cleanups or stack levels are relevant.  */
  580.       while (next_block && next_block != block)
  581.     next_block = next_block->all;
  582.  
  583.       if (next_block)
  584.     return 0;
  585.  
  586.       /* Otherwise, set END_BLOCK to the innermost binding level
  587.      which is outside the relevant control-structure nesting.  */
  588.       next_block = block_stack->next;
  589.       for (block = block_stack; block != end_block; block = block->all)
  590.     if (block == next_block)
  591.       next_block = next_block->next;
  592.       end_block = next_block;
  593.     }
  594.  
  595.   /* Does any containing block have a stack level or cleanups?
  596.      If not, no fixup is needed, and that is the normal case
  597.      (the only case, for standard C).  */
  598.   for (block = block_stack; block != end_block; block = block->next)
  599.     if (block->data.block.stack_level != 0
  600.     || block->data.block.cleanups != 0)
  601.       break;
  602.  
  603.   if (block != end_block)
  604.     {
  605.       /* Ok, a fixup is needed.  Add a fixup to the list of such.  */
  606.       struct goto_fixup *fixup
  607.     = (struct goto_fixup *) oballoc (sizeof (struct goto_fixup));
  608.       /* In case an old stack level is restored, make sure that comes
  609.      after any pending stack adjust.  */
  610.       do_pending_stack_adjust ();
  611.       fixup->before_jump = last_insn ? last_insn : get_last_insn ();
  612.       fixup->target = tree_label;
  613.       fixup->target_rtl = rtl_label;
  614.       fixup->stack_level = 0;
  615.       fixup->cleanup_list_list
  616.     = (block->data.block.outer_cleanups || block->data.block.cleanups
  617.        ? tree_cons (0, block->data.block.cleanups,
  618.             block->data.block.outer_cleanups)
  619.        : 0);
  620.       fixup->next = goto_fixup_chain;
  621.       goto_fixup_chain = fixup;
  622.     }
  623.  
  624.   return block != 0;
  625. }
  626.  
  627. /* When exiting a binding contour, process all pending gotos requiring fixups.
  628.    THISBLOCK is the structure that describes the block being exited.
  629.    STACK_LEVEL is the rtx for the stack level to restore exiting this contour.
  630.    CLEANUP_LIST is a list of expressions to evaluate on exiting this contour.
  631.    FIRST_INSN is the insn that began this contour.
  632.  
  633.    Gotos that jump out of this contour must restore the
  634.    stack level and do the cleanups before actually jumping.
  635.  
  636.    DONT_JUMP_IN nonzero means report error there is a jump into this
  637.    contour from before the beginning of the contour.
  638.    This is also done if STACK_LEVEL is nonzero.  */
  639.  
  640. static void
  641. fixup_gotos (thisblock, stack_level, cleanup_list, first_insn, dont_jump_in)
  642.      struct nesting *thisblock;
  643.      rtx stack_level;
  644.      tree cleanup_list;
  645.      rtx first_insn;
  646.      int dont_jump_in;
  647. {
  648.   register struct goto_fixup *f, *prev;
  649.  
  650.   /* F is the fixup we are considering; PREV is the previous one.  */
  651.  
  652.   for (prev = 0, f = goto_fixup_chain; f; prev = f, f = f->next)
  653.     {
  654.       /* Test for a fixup that is inactive because it is already handled.  */
  655.       if (f->before_jump == 0)
  656.     {
  657.       /* Delete inactive fixup from the chain, if that is easy to do.  */
  658.       if (prev != 0)
  659.         prev->next = f->next;
  660.     }
  661.       /* Has this fixup's target label been defined?
  662.      If so, we can finalize it.  */
  663.       else if (PREV_INSN (f->target_rtl) != 0)
  664.     {
  665.       /* If this fixup jumped into this contour from before the beginning
  666.          of this contour, report an error.  */
  667.       /* ??? Bug: this does not detect jumping in through intermediate
  668.          blocks that have stack levels or cleanups.
  669.          It detects only a problem with the innermost block
  670.          around the label.  */
  671.       if (f->target != 0
  672.           && (dont_jump_in || stack_level || cleanup_list)
  673.           && INSN_UID (first_insn) > INSN_UID (f->before_jump)
  674.           && ! TREE_ADDRESSABLE (f->target))
  675.         {
  676.           error_with_decl (f->target,
  677.                    "label `%s' used before containing binding contour");
  678.           /* Prevent multiple errors for one label.  */
  679.           TREE_ADDRESSABLE (f->target) = 1;
  680.         }
  681.  
  682.       /* Execute cleanups for blocks this jump exits.  */
  683.       if (f->cleanup_list_list)
  684.         {
  685.           tree lists;
  686.           for (lists = f->cleanup_list_list; lists; lists = TREE_CHAIN (lists))
  687.         /* Marked elements correspond to blocks that have been closed.
  688.            Do their cleanups.  */
  689.         if (TREE_ADDRESSABLE (lists)
  690.             && TREE_VALUE (lists) != 0)
  691.           fixup_cleanups (TREE_VALUE (lists), &f->before_jump);
  692.         }
  693.  
  694.       /* Restore stack level for the biggest contour that this
  695.          jump jumps out of.  */
  696.       if (f->stack_level)
  697.         emit_insn_after (gen_move_insn (stack_pointer_rtx, f->stack_level),
  698.                  f->before_jump);
  699.       f->before_jump = 0;
  700.     }
  701.       /* Label has still not appeared.  If we are exiting a block with
  702.      a stack level to restore, mark this stack level as needing
  703.      restoration when the fixup is later finalized.
  704.      Also mark the cleanup_list_list element for F
  705.      that corresponds to this block, so that ultimately
  706.      this block's cleanups will be executed by the code above.  */
  707.       /* Note: if THISBLOCK == 0 and we have a label that hasn't appeared,
  708.      it means the label is undefined.  That's erroneous, but possible.  */
  709.       else if (thisblock != 0)
  710.     {
  711.       tree lists = f->cleanup_list_list;
  712.       for (; lists; lists = TREE_CHAIN (lists))
  713.         /* If the following elt. corresponds to our containing block
  714.            then the elt. must be for this block.  */
  715.         if (TREE_CHAIN (lists) == thisblock->data.block.outer_cleanups)
  716.           TREE_ADDRESSABLE (lists) = 1;
  717.  
  718.       if (stack_level)
  719.         f->stack_level = stack_level;
  720.     }
  721.     }
  722. }
  723.  
  724. /* Generate RTL for an asm statement (explicit assembler code).
  725.    BODY is a STRING_CST node containing the assembler code text.  */
  726.  
  727. void
  728. expand_asm (body)
  729.      tree body;
  730. {
  731.   emit_insn (gen_rtx (ASM_INPUT, VOIDmode,
  732.               TREE_STRING_POINTER (body)));
  733.   last_expr_type = 0;
  734. }
  735.  
  736. /* Generate RTL for an asm statement with arguments.
  737.    STRING is the instruction template.
  738.    OUTPUTS is a list of output arguments (lvalues); INPUTS a list of inputs.
  739.    Each output or input has an expression in the TREE_VALUE and
  740.    a constraint-string in the TREE_PURPOSE.
  741.    CLOBBERS is a list of STRING_CST nodes each naming a hard register
  742.    that is clobbered by this insn.
  743.  
  744.    Not all kinds of lvalue that may appear in OUTPUTS can be stored directly.
  745.    Some elements of OUTPUTS may be replaced with trees representing temporary
  746.    values.  The caller should copy those temporary values to the originally
  747.    specified lvalues.
  748.  
  749.    VOL nonzero means the insn is volatile; don't optimize it.  */
  750.  
  751. void
  752. expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line)
  753.      tree string, outputs, inputs, clobbers;
  754.      int vol;
  755.      char *filename;
  756.      int line;
  757. {
  758.   rtvec argvec, constraints;
  759.   rtx body;
  760.   int ninputs = list_length (inputs);
  761.   int noutputs = list_length (outputs);
  762.   int nclobbers = list_length (clobbers);
  763.   tree tail;
  764.   register int i;
  765.   /* Vector of RTX's of evaluated output operands.  */
  766.   rtx *output_rtx = (rtx *) alloca (noutputs * sizeof (rtx));
  767.   /* The insn we have emitted.  */
  768.   rtx insn;
  769.  
  770.   last_expr_type = 0;
  771.  
  772.   for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
  773.     {
  774.       tree val = TREE_VALUE (tail);
  775.       int j;
  776.       int found_equal;
  777.  
  778.       /* If there's an erroneous arg, emit no insn.  */
  779.       if (TREE_TYPE (val) == error_mark_node)
  780.     return;
  781.  
  782.       /* Make sure constraint has `=' and does not have `+'.  */
  783.  
  784.       found_equal = 0;
  785.       for (j = 0; j < TREE_STRING_LENGTH (TREE_PURPOSE (tail)); j++)
  786.     {
  787.       if (TREE_STRING_POINTER (TREE_PURPOSE (tail))[j] == '+')
  788.         {
  789.           error ("input operand constraint contains `+'");
  790.           return;
  791.         }
  792.       if (TREE_STRING_POINTER (TREE_PURPOSE (tail))[j] == '=')
  793.         found_equal = 1;
  794.     }
  795.       if (! found_equal)
  796.     {
  797.       error ("output operand constraint lacks `='");
  798.       return;
  799.     }
  800.  
  801.       /* If an output operand is not a variable or indirect ref,
  802.      create a SAVE_EXPR which is a pseudo-reg
  803.      to act as an intermediate temporary.
  804.      Make the asm insn write into that, then copy it to
  805.      the real output operand.  */
  806.  
  807.       if (TREE_CODE (val) != VAR_DECL
  808.       && TREE_CODE (val) != PARM_DECL
  809.       && TREE_CODE (val) != INDIRECT_REF)
  810.     {
  811.       rtx reg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (val)));
  812.       /* `build' isn't safe; it really expects args to be trees.  */
  813.       tree t = build_nt (SAVE_EXPR, val, reg);
  814.  
  815.       save_expr_regs = gen_rtx (EXPR_LIST, VOIDmode, reg, save_expr_regs);
  816.       TREE_VALUE (tail) = t;
  817.       TREE_TYPE (t) = TREE_TYPE (val);
  818.     }
  819.       output_rtx[i] = expand_expr (TREE_VALUE (tail), 0, VOIDmode, 0);
  820.     }
  821.  
  822.   if (ninputs + noutputs > MAX_RECOG_OPERANDS)
  823.     {
  824.       error ("more than %d operands in `asm'", MAX_RECOG_OPERANDS);
  825.       return;
  826.     }
  827.  
  828.   /* Make vectors for the expression-rtx and constraint strings.  */
  829.  
  830.   argvec = rtvec_alloc (ninputs);
  831.   constraints = rtvec_alloc (ninputs);
  832.  
  833.   body = gen_rtx (ASM_OPERANDS, VOIDmode,
  834.           TREE_STRING_POINTER (string), "", 0, argvec, constraints,
  835.           filename, line);
  836.   MEM_VOLATILE_P (body) = vol;
  837.  
  838.   /* Eval the inputs and put them into ARGVEC.
  839.      Put their constraints into ASM_INPUTs and store in CONSTRAINTS.  */
  840.  
  841.   i = 0;
  842.   for (tail = inputs; tail; tail = TREE_CHAIN (tail))
  843.     {
  844.       int j;
  845.  
  846.       /* If there's an erroneous arg, emit no insn,
  847.      because the ASM_INPUT would get VOIDmode
  848.      and that could cause a crash in reload.  */
  849.       if (TREE_TYPE (TREE_VALUE (tail)) == error_mark_node)
  850.     return;
  851.       if (TREE_PURPOSE (tail) == NULL_TREE)
  852.     {
  853.       error ("hard register `%s' listed as input operand to `asm'",
  854.          TREE_STRING_POINTER (TREE_VALUE (tail)) );
  855.       return;
  856.     }
  857.  
  858.       /* Make sure constraint has neither `=' nor `+'.  */
  859.  
  860.       for (j = 0; j < TREE_STRING_LENGTH (TREE_PURPOSE (tail)); j++)
  861.     if (TREE_STRING_POINTER (TREE_PURPOSE (tail))[j] == '='
  862.         || TREE_STRING_POINTER (TREE_PURPOSE (tail))[j] == '+')
  863.       {
  864.         error ("input operand constraint contains `%c'",
  865.            TREE_STRING_POINTER (TREE_PURPOSE (tail))[j]);
  866.         return;
  867.       }
  868.  
  869.       XVECEXP (body, 3, i)      /* argvec */
  870.     = expand_expr (TREE_VALUE (tail), 0, VOIDmode, 0);
  871.       XVECEXP (body, 4, i)      /* constraints */
  872.     = gen_rtx (ASM_INPUT, TYPE_MODE (TREE_TYPE (TREE_VALUE (tail))),
  873.            TREE_STRING_POINTER (TREE_PURPOSE (tail)));
  874.       i++;
  875.     }
  876.  
  877.   /* Protect all the operands from the queue,
  878.      now that they have all been evaluated.  */
  879.  
  880.   for (i = 0; i < ninputs; i++)
  881.     XVECEXP (body, 3, i) = protect_from_queue (XVECEXP (body, 3, i), 0);
  882.  
  883.   for (i = 0; i < noutputs; i++)
  884.     output_rtx[i] = protect_from_queue (output_rtx[i], 1);
  885.  
  886.   /* Now, for each output, construct an rtx
  887.      (set OUTPUT (asm_operands INSN OUTPUTNUMBER OUTPUTCONSTRAINT
  888.                    ARGVEC CONSTRAINTS))
  889.      If there is more than one, put them inside a PARALLEL.  */
  890.  
  891.   if (noutputs == 1 && nclobbers == 0)
  892.     {
  893.       XSTR (body, 1) = TREE_STRING_POINTER (TREE_PURPOSE (outputs));
  894.       insn = emit_insn (gen_rtx (SET, VOIDmode, output_rtx[0], body));
  895.     }
  896.   else if (noutputs == 0 && nclobbers == 0)
  897.     {
  898.       /* No output operands: put in a raw ASM_OPERANDS rtx.  */
  899.       insn = emit_insn (body);
  900.     }
  901.   else
  902.     {
  903.       rtx obody = body;
  904.       int num = noutputs;
  905.       if (num == 0) num = 1;
  906.       body = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (num + nclobbers));
  907.  
  908.       /* For each output operand, store a SET.  */
  909.  
  910.       for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
  911.     {
  912.       XVECEXP (body, 0, i)
  913.         = gen_rtx (SET, VOIDmode,
  914.                output_rtx[i],
  915.                gen_rtx (ASM_OPERANDS, VOIDmode,
  916.                 TREE_STRING_POINTER (string),
  917.                 TREE_STRING_POINTER (TREE_PURPOSE (tail)),
  918.                 i, argvec, constraints,
  919.                 filename, line));
  920.       MEM_VOLATILE_P (SET_SRC (XVECEXP (body, 0, i))) = vol;
  921.     }
  922.  
  923.       /* If there are no outputs (but there are some clobbers)
  924.      store the bare ASM_OPERANDS into the PARALLEL.  */
  925.  
  926.       if (i == 0)
  927.     XVECEXP (body, 0, i++) = obody;
  928.  
  929.       /* Store (clobber REG) for each clobbered register specified.  */
  930.  
  931.       for (tail = clobbers; tail; tail = TREE_CHAIN (tail), i++)
  932.     {
  933.       int j;
  934.       char *regname = TREE_STRING_POINTER (TREE_VALUE (tail));
  935.       extern char *reg_names[];
  936.           
  937.       for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
  938.         if (!strcmp (regname, reg_names[j]))
  939.           break;
  940.           
  941.       if (j == FIRST_PSEUDO_REGISTER)
  942.         {
  943.           error ("unknown register name `%s' in `asm'", regname);
  944.           return;
  945.         }
  946.  
  947.       /* Use QImode since that's guaranteed to clobber just one reg.  */
  948.       XVECEXP (body, 0, i)
  949.         = gen_rtx (CLOBBER, VOIDmode, gen_rtx (REG, QImode, j));
  950.     }
  951.  
  952.       insn = emit_insn (body);
  953.     }
  954.  
  955.   last_expr_type = 0;
  956. }
  957.  
  958. /* Nonzero if within a ({...}) grouping, in which case we must
  959.    always compute a value for each expr-stmt in case it is the last one.  */
  960.  
  961. int expr_stmts_for_value;
  962.  
  963. /* Generate RTL to evaluate the expression EXP
  964.    and remember it in case this is the VALUE in a ({... VALUE; }) constr.  */
  965.  
  966. void
  967. expand_expr_stmt (exp)
  968.      tree exp;
  969. {
  970.   /* If -W, warn about statements with no side effects,
  971.      except inside a ({...}) where they may be useful.  */
  972.   if (extra_warnings && expr_stmts_for_value == 0 && !TREE_VOLATILE (exp)
  973.       && exp != error_mark_node)
  974.     warning_with_file_and_line (emit_filename, emit_lineno,
  975.                 "statement with no effect");
  976.   last_expr_type = TREE_TYPE (exp);
  977.   if (! flag_syntax_only)
  978.     last_expr_value = expand_expr (exp, expr_stmts_for_value ? 0 : const0_rtx,
  979.                    VOIDmode, 0);
  980.   emit_queue ();
  981. }
  982.  
  983. /* Clear out the memory of the last expression evaluated.  */
  984.  
  985. void
  986. clear_last_expr ()
  987. {
  988.   last_expr_type = 0;
  989. }
  990.  
  991. /* Begin a statement which will return a value.
  992.    Return the RTL_EXPR for this statement expr.
  993.    The caller must save that value and pass it to expand_end_stmt_expr.  */
  994.  
  995. tree
  996. expand_start_stmt_expr ()
  997. {
  998.   rtx save = start_sequence ();
  999.   /* Make the RTL_EXPR node temporary, not momentary,
  1000.      so that rtl_expr_chain doesn't become garbage.  */
  1001.   int momentary = suspend_momentary ();
  1002.   tree t = make_node (RTL_EXPR);
  1003.   resume_momentary (momentary);
  1004.   RTL_EXPR_RTL (t) = save;
  1005.   expr_stmts_for_value++;
  1006.   return t;
  1007. }
  1008.  
  1009. /* Restore the previous state at the end of a statement that returns a value.
  1010.    Returns a tree node representing the statement's value and the
  1011.    insns to compute the value.
  1012.  
  1013.    The nodes of that expression have been freed by now, so we cannot use them.
  1014.    But we don't want to do that anyway; the expression has already been
  1015.    evaluated and now we just want to use the value.  So generate a RTL_EXPR
  1016.    with the proper type and RTL value.
  1017.  
  1018.    If the last substatement was not an expression,
  1019.    return something with type `void'.  */
  1020.  
  1021. tree
  1022. expand_end_stmt_expr (t)
  1023.      tree t;
  1024. {
  1025.   rtx saved = RTL_EXPR_RTL (t);
  1026.  
  1027.   do_pending_stack_adjust ();
  1028.  
  1029.   if (last_expr_type == 0)
  1030.     {
  1031.       last_expr_type = void_type_node;
  1032.       last_expr_value = const0_rtx;
  1033.     }
  1034.   TREE_TYPE (t) = last_expr_type;
  1035.   RTL_EXPR_RTL (t) = last_expr_value;
  1036.   RTL_EXPR_SEQUENCE (t) = get_insns ();
  1037.  
  1038.   rtl_expr_chain = tree_cons (NULL_TREE, t, rtl_expr_chain);
  1039.  
  1040.   end_sequence (saved);
  1041.  
  1042.   /* Don't consider deleting this expr or containing exprs at tree level.  */
  1043.   TREE_VOLATILE (t) = 1;
  1044.   /* Propagate volatility of the actual RTL expr.  */
  1045.   TREE_THIS_VOLATILE (t) = volatile_refs_p (last_expr_value);
  1046.  
  1047.   last_expr_type = 0;
  1048.   expr_stmts_for_value--;
  1049.  
  1050.   return t;
  1051. }
  1052.  
  1053. /* Generate RTL for the start of an if-then.  COND is the expression
  1054.    whose truth should be tested.
  1055.  
  1056.    If EXITFLAG is nonzero, this conditional is visible to
  1057.    `exit_something'.  */
  1058.  
  1059. void
  1060. expand_start_cond (cond, exitflag)
  1061.      tree cond;
  1062.      int exitflag;
  1063. {
  1064.   struct nesting *thiscond
  1065.     = (struct nesting *) xmalloc (sizeof (struct nesting));
  1066.  
  1067.   /* Make an entry on cond_stack for the cond we are entering.  */
  1068.  
  1069.   thiscond->next = cond_stack;
  1070.   thiscond->all = nesting_stack;
  1071.   thiscond->depth = ++nesting_depth;
  1072.   thiscond->data.cond.after_label = 0;
  1073.   thiscond->data.cond.else_label = gen_label_rtx ();
  1074.   thiscond->exit_label = exitflag ? thiscond->data.cond.else_label : 0;
  1075.   cond_stack = thiscond;
  1076.   nesting_stack = thiscond;
  1077.  
  1078.   do_jump (cond, thiscond->data.cond.else_label, NULL);
  1079. }
  1080.  
  1081. /* Generate RTL for the end of an if-then with no else-clause.
  1082.    Pop the record for it off of cond_stack.  */
  1083.  
  1084. void
  1085. expand_end_cond ()
  1086. {
  1087.   struct nesting *thiscond = cond_stack;
  1088.  
  1089.   do_pending_stack_adjust ();
  1090.   emit_label (thiscond->data.cond.else_label);
  1091.  
  1092.   POPSTACK (cond_stack);
  1093.   last_expr_type = 0;
  1094. }
  1095.  
  1096. /* Generate RTL between the then-clause and the else-clause
  1097.    of an if-then-else.  */
  1098.  
  1099. void
  1100. expand_start_else ()
  1101. {
  1102.   cond_stack->data.cond.after_label = gen_label_rtx ();
  1103.   if (cond_stack->exit_label != 0)
  1104.     cond_stack->exit_label = cond_stack->data.cond.after_label;
  1105.   emit_jump (cond_stack->data.cond.after_label);
  1106.   if (cond_stack->data.cond.else_label)
  1107.     emit_label (cond_stack->data.cond.else_label);
  1108. }
  1109.  
  1110. /* Generate RTL for the end of an if-then-else.
  1111.    Pop the record for it off of cond_stack.  */
  1112.  
  1113. void
  1114. expand_end_else ()
  1115. {
  1116.   struct nesting *thiscond = cond_stack;
  1117.  
  1118.   do_pending_stack_adjust ();
  1119.   /* Note: a syntax error can cause this to be called
  1120.      without first calling `expand_start_else'.  */
  1121.   if (thiscond->data.cond.after_label)
  1122.     emit_label (thiscond->data.cond.after_label);
  1123.  
  1124.   POPSTACK (cond_stack);
  1125.   last_expr_type = 0;
  1126. }
  1127.  
  1128. /* Generate RTL for the start of a loop.  EXIT_FLAG is nonzero if this
  1129.    loop should be exited by `exit_something'.  This is a loop for which
  1130.    `expand_continue' will jump to the top of the loop.
  1131.  
  1132.    Make an entry on loop_stack to record the labels associated with
  1133.    this loop.  */
  1134.  
  1135. void
  1136. expand_start_loop (exit_flag)
  1137.      int exit_flag;
  1138. {
  1139.   register struct nesting *thisloop
  1140.     = (struct nesting *) xmalloc (sizeof (struct nesting));
  1141.  
  1142.   /* Make an entry on loop_stack for the loop we are entering.  */
  1143.  
  1144.   thisloop->next = loop_stack;
  1145.   thisloop->all = nesting_stack;
  1146.   thisloop->depth = ++nesting_depth;
  1147.   thisloop->data.loop.start_label = gen_label_rtx ();
  1148.   thisloop->data.loop.end_label = gen_label_rtx ();
  1149.   thisloop->data.loop.continue_label = thisloop->data.loop.start_label;
  1150.   thisloop->exit_label = exit_flag ? thisloop->data.loop.end_label : 0;
  1151.   loop_stack = thisloop;
  1152.   nesting_stack = thisloop;
  1153.  
  1154.   do_pending_stack_adjust ();
  1155.   emit_queue ();
  1156.   emit_note (0, NOTE_INSN_LOOP_BEG);
  1157.   emit_label (thisloop->data.loop.start_label);
  1158. }
  1159.  
  1160. /* Like expand_start_loop but for a loop where the continuation point
  1161.    (for expand_continue_loop) will be specified explicitly.  */
  1162.  
  1163. void
  1164. expand_start_loop_continue_elsewhere (exit_flag)
  1165.      int exit_flag;
  1166. {
  1167.   expand_start_loop (exit_flag);
  1168.   loop_stack->data.loop.continue_label = gen_label_rtx ();
  1169. }
  1170.  
  1171. /* Specify the continuation point for a loop started with
  1172.    expand_start_loop_continue_elsewhere.
  1173.    Use this at the point in the code to which a continue statement
  1174.    should jump.  */
  1175.  
  1176. void
  1177. expand_loop_continue_here ()
  1178. {
  1179.   do_pending_stack_adjust ();
  1180.   emit_note (0, NOTE_INSN_LOOP_CONT);
  1181.   emit_label (loop_stack->data.loop.continue_label);
  1182. }
  1183.  
  1184. /* Finish a loop.  Generate a jump back to the top and the loop-exit label.
  1185.    Pop the block off of loop_stack.  */
  1186.  
  1187. void
  1188. expand_end_loop ()
  1189. {
  1190.   register rtx insn = get_last_insn ();
  1191.   register rtx start_label = loop_stack->data.loop.start_label;
  1192.  
  1193.   do_pending_stack_adjust ();
  1194.  
  1195.   /* If optimizing, perhaps reorder the loop.  If the loop
  1196.      starts with a conditional exit, roll that to the end
  1197.      where it will optimize together with the jump back.  */
  1198.   if (optimize
  1199.       &&
  1200.       ! (GET_CODE (insn) == JUMP_INSN
  1201.      && GET_CODE (PATTERN (insn)) == SET
  1202.      && SET_DEST (PATTERN (insn)) == pc_rtx
  1203.      && GET_CODE (SET_SRC (PATTERN (insn))) == IF_THEN_ELSE))
  1204.     {
  1205.       /* Scan insns from the top of the loop looking for a qualified
  1206.      conditional exit.  */
  1207.       for (insn = loop_stack->data.loop.start_label; insn; insn= NEXT_INSN (insn))
  1208.     if (GET_CODE (insn) == JUMP_INSN && GET_CODE (PATTERN (insn)) == SET
  1209.         && SET_DEST (PATTERN (insn)) == pc_rtx
  1210.         && GET_CODE (SET_SRC (PATTERN (insn))) == IF_THEN_ELSE
  1211.         &&
  1212.         ((GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 1)) == LABEL_REF
  1213.           && (XEXP (XEXP (SET_SRC (PATTERN (insn)), 1), 0)
  1214.           == loop_stack->data.loop.end_label))
  1215.          ||
  1216.          (GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 2)) == LABEL_REF
  1217.           && (XEXP (XEXP (SET_SRC (PATTERN (insn)), 2), 0)
  1218.           == loop_stack->data.loop.end_label))))
  1219.       break;
  1220.       if (insn != 0)
  1221.     {
  1222.       /* We found one.  Move everything from there up
  1223.          to the end of the loop, and add a jump into the loop
  1224.          to jump to there.  */
  1225.       register rtx newstart_label = gen_label_rtx ();
  1226.  
  1227.       emit_label_after (newstart_label, PREV_INSN (start_label));
  1228.       reorder_insns (start_label, insn, get_last_insn ());
  1229.       emit_jump_insn_after (gen_jump (start_label), PREV_INSN (newstart_label));
  1230.       emit_barrier_after (PREV_INSN (newstart_label));
  1231.       start_label = newstart_label;
  1232.     }
  1233.     }
  1234.  
  1235.   emit_jump (start_label);
  1236.   emit_note (0, NOTE_INSN_LOOP_END);
  1237.   emit_label (loop_stack->data.loop.end_label);
  1238.  
  1239.   POPSTACK (loop_stack);
  1240.  
  1241.   last_expr_type = 0;
  1242. }
  1243.  
  1244. /* Generate a jump to the current loop's continue-point.
  1245.    This is usually the top of the loop, but may be specified
  1246.    explicitly elsewhere.  If not currently inside a loop,
  1247.    return 0 and do nothing; caller will print an error message.  */
  1248.  
  1249. int
  1250. expand_continue_loop ()
  1251. {
  1252.   last_expr_type = 0;
  1253.   if (loop_stack == 0)
  1254.     return 0;
  1255.   expand_goto_internal (0, loop_stack->data.loop.continue_label, 0);
  1256.   return 1;
  1257. }
  1258.  
  1259. /* Generate a jump to exit the current loop.  If not currently inside a loop,
  1260.    return 0 and do nothing; caller will print an error message.  */
  1261.  
  1262. int
  1263. expand_exit_loop ()
  1264. {
  1265.   last_expr_type = 0;
  1266.   if (loop_stack == 0)
  1267.     return 0;
  1268.   expand_goto_internal (0, loop_stack->data.loop.end_label, 0);
  1269.   return 1;
  1270. }
  1271.  
  1272. /* Generate a conditional jump to exit the current loop if COND
  1273.    evaluates to zero.  If not currently inside a loop,
  1274.    return 0 and do nothing; caller will print an error message.  */
  1275.  
  1276. int
  1277. expand_exit_loop_if_false (cond)
  1278.      tree cond;
  1279. {
  1280.   last_expr_type = 0;
  1281.   if (loop_stack == 0)
  1282.     return 0;
  1283.   do_jump (cond, loop_stack->data.loop.end_label, NULL);
  1284.   return 1;
  1285. }
  1286.  
  1287. /* Generate a jump to exit the current loop, conditional, binding contour
  1288.    or case statement.  Not all such constructs are visible to this function,
  1289.    only those started with EXIT_FLAG nonzero.  Individual languages use
  1290.    the EXIT_FLAG parameter to control which kinds of constructs you can
  1291.    exit this way.
  1292.  
  1293.    If not currently inside anything that can be exited,
  1294.    return 0 and do nothing; caller will print an error message.  */
  1295.  
  1296. int
  1297. expand_exit_something ()
  1298. {
  1299.   struct nesting *n;
  1300.   last_expr_type = 0;
  1301.   for (n = nesting_stack; n; n = n->all)
  1302.     if (n->exit_label != 0)
  1303.       {
  1304.     expand_goto_internal (0, n->exit_label, 0);
  1305.     return 1;
  1306.       }
  1307.  
  1308.   return 0;
  1309. }
  1310.  
  1311. /* Generate RTL to return from the current function, with no value.
  1312.    (That is, we do not do anything about returning any value.)  */
  1313.  
  1314. void
  1315. expand_null_return ()
  1316. {
  1317.   struct nesting *block = block_stack;
  1318.   rtx last_insn = 0;
  1319.  
  1320.   while (block && block->data.block.cleanups == 0)
  1321.     block = block->next;
  1322.  
  1323.   if (block)
  1324.     {
  1325.       last_insn = get_last_insn ();
  1326.       if (return_label == 0)
  1327.     return_label = gen_label_rtx ();
  1328.     }
  1329.  
  1330.   expand_null_return_1 (last_insn);
  1331. }
  1332.  
  1333. /* Output a return with no value.  If LAST_INSN is nonzero,
  1334.    pretend that the return takes place after LAST_INSN.  */
  1335.  
  1336. static void
  1337. expand_null_return_1 (last_insn)
  1338.      rtx last_insn;
  1339. {
  1340.   rtx end_label = cleanup_label ? cleanup_label : return_label;
  1341.  
  1342.   clear_pending_stack_adjust ();
  1343.   do_pending_stack_adjust ();
  1344.   last_expr_type = 0;
  1345.  
  1346.   /* PCC-struct return always uses an epilogue.  */
  1347.   if (current_function_returns_pcc_struct)
  1348.     {
  1349.       expand_goto_internal (0, end_label, last_insn);
  1350.       return;
  1351.     }
  1352.  
  1353. #ifdef FUNCTION_EPILOGUE
  1354. #ifdef HAVE_return
  1355.   if (cleanup_label != 0 || last_insn != 0 || ! HAVE_return)
  1356.     expand_goto_internal (0, end_label, last_insn);
  1357.   else
  1358.     {
  1359.       emit_jump_insn (gen_return ());
  1360.       emit_barrier ();
  1361.     }
  1362. #else
  1363.   expand_goto_internal (0, end_label, last_insn);
  1364. #endif
  1365. #else /* no FUNCTION_EPILOGUE */
  1366.   if (cleanup_label != 0 || last_insn != 0)
  1367.     expand_goto_internal (0, end_label, last_insn);
  1368.   else
  1369.     {
  1370.       emit_jump_insn (gen_return ());
  1371.       emit_barrier ();
  1372.     }
  1373. #endif
  1374. }
  1375.  
  1376. /* Generate RTL to evaluate the expression RETVAL and return it
  1377.    from the current function.  */
  1378.  
  1379. void
  1380. expand_return (retval)
  1381.      tree retval;
  1382. {
  1383.   /* If there are any cleanups to be performed, then they will
  1384.      be inserted in front of our `last_insn'.  It is desirable
  1385.      that the last_insn, for such purposes, should be the
  1386.      last insn before computing the return value.  Otherwise, cleanups
  1387.      which call functions can clobber the return value.  */
  1388.   rtx last_insn = 0;
  1389.   register rtx val = 0;
  1390.   register rtx op0;
  1391.   tree retval_rhs;
  1392.   int cleanups;
  1393.   struct nesting *block;
  1394.  
  1395.   /* Are any cleanups needed?  E.g. C++ destructors to be run?  */
  1396.   cleanups = 0;
  1397.   for (block = block_stack; block; block = block->next)
  1398.     if (block->data.block.cleanups != 0)
  1399.       {
  1400.     cleanups = 1;
  1401.     break;
  1402.       }
  1403.  
  1404.   if (TREE_CODE (retval) == RESULT_DECL)
  1405.     retval_rhs = retval;
  1406.   else if ((TREE_CODE (retval) == MODIFY_EXPR || TREE_CODE (retval) == INIT_EXPR)
  1407.        && TREE_CODE (TREE_OPERAND (retval, 0)) == RESULT_DECL)
  1408.     retval_rhs = TREE_OPERAND (retval, 1);
  1409.   else if (TREE_TYPE (retval) == void_type_node)
  1410.     /* Recognize tail-recursive call to void function.  */
  1411.     retval_rhs = retval;
  1412.   else
  1413.     retval_rhs = NULL_TREE;
  1414.  
  1415.   /* Only use `last_insn' if there are cleanups which must be run.  */
  1416.   if (cleanup_label == 0)
  1417.     {
  1418.       struct nesting *block = block_stack;
  1419.  
  1420.       while (block && block->data.block.cleanups == 0)
  1421.     block = block->next;
  1422.  
  1423.       if (block)
  1424.     {
  1425.       last_insn = get_last_insn ();
  1426.       if (return_label == 0)
  1427.         return_label = gen_label_rtx ();
  1428.     }
  1429.     }
  1430.   else last_insn = get_last_insn ();
  1431.   
  1432.   /* For tail-recursive call to current function,
  1433.      just jump back to the beginning.
  1434.      It's unsafe if any auto variable in this function
  1435.      has its address taken; for simplicity,
  1436.      require stack frame to be empty.  */
  1437.   if (optimize && retval_rhs != 0
  1438.       && frame_offset == STARTING_FRAME_OFFSET
  1439.       && TREE_CODE (retval_rhs) == CALL_EXPR
  1440.       && TREE_CODE (TREE_OPERAND (retval_rhs, 0)) == ADDR_EXPR
  1441.       && TREE_OPERAND (TREE_OPERAND (retval_rhs, 0), 0) == this_function
  1442.       /* Finish checking validity, and if valid emit code
  1443.      to set the argument variables for the new call.  */
  1444.       && tail_recursion_args (TREE_OPERAND (retval_rhs, 1),
  1445.                   DECL_ARGUMENTS (this_function)))
  1446.     {
  1447.       if (tail_recursion_label == 0)
  1448.     {
  1449.       tail_recursion_label = gen_label_rtx ();
  1450.       emit_label_after (tail_recursion_label,
  1451.                 tail_recursion_reentry);
  1452.     }
  1453.       expand_goto_internal (0, tail_recursion_label, last_insn);
  1454.       emit_barrier ();
  1455.       return;
  1456.     }
  1457. #ifdef HAVE_return
  1458.   if (HAVE_return && cleanup_label == 0
  1459.       && ! current_function_returns_pcc_struct)
  1460.     {
  1461.       /* If this is  return x == y;  then generate
  1462.      if (x == y) return 1; else return 0;
  1463.      if we can do it with explicit return insns.  */
  1464.       if (retval_rhs)
  1465.     switch (TREE_CODE (retval_rhs))
  1466.       {
  1467.       case EQ_EXPR:
  1468.       case NE_EXPR:
  1469.       case GT_EXPR:
  1470.       case GE_EXPR:
  1471.       case LT_EXPR:
  1472.       case LE_EXPR:
  1473.       case TRUTH_ANDIF_EXPR:
  1474.       case TRUTH_ORIF_EXPR:
  1475.       case TRUTH_AND_EXPR:
  1476.       case TRUTH_OR_EXPR:
  1477.       case TRUTH_NOT_EXPR:
  1478.         op0 = gen_label_rtx ();
  1479.         val = DECL_RTL (DECL_RESULT (this_function));
  1480.         jumpifnot (retval_rhs, op0);
  1481.         emit_move_insn (val, const1_rtx);
  1482.         emit_insn (gen_rtx (USE, VOIDmode, val));
  1483.         expand_null_return ();
  1484.         emit_label (op0);
  1485.         emit_move_insn (val, const0_rtx);
  1486.         emit_insn (gen_rtx (USE, VOIDmode, val));
  1487.         expand_null_return ();
  1488.         return;
  1489.       }
  1490.     }
  1491. #endif /* HAVE_return */
  1492.  
  1493.   if (cleanups
  1494.       && retval_rhs != 0
  1495.       && TREE_TYPE (retval_rhs) != void_type_node
  1496.       && GET_CODE (DECL_RTL (DECL_RESULT (this_function))) == REG)
  1497.     {
  1498.       rtx last_insn;
  1499.       /* Calculate the return value into a pseudo reg.  */
  1500.       val = expand_expr (retval_rhs, 0, VOIDmode, 0);
  1501.       emit_queue ();
  1502.       /* Put the cleanups here.  */
  1503.       last_insn = get_last_insn ();
  1504.       /* Copy the value into hard return reg.  */
  1505.       emit_move_insn (DECL_RTL (DECL_RESULT (this_function)), val);
  1506.       val = DECL_RTL (DECL_RESULT (this_function));
  1507.  
  1508.       if (GET_CODE (val) == REG)
  1509.     emit_insn (gen_rtx (USE, VOIDmode, val));
  1510.       expand_null_return_1 (last_insn);
  1511.     }
  1512.   else
  1513.     {
  1514.       /* No cleanups or no hard reg used;
  1515.      calculate value into hard return reg
  1516.      and let cleanups come after.  */
  1517.       val = expand_expr (retval, 0, VOIDmode, 0);
  1518.       emit_queue ();
  1519.  
  1520.       val = DECL_RTL (DECL_RESULT (this_function));
  1521.       if (GET_CODE (val) == REG)
  1522.     emit_insn (gen_rtx (USE, VOIDmode, val));
  1523.       expand_null_return ();
  1524.     }
  1525. }
  1526.  
  1527. /* Return 1 if the end of the generated RTX is not a barrier.
  1528.    This means code already compiled can drop through.  */
  1529.  
  1530. int
  1531. drop_through_at_end_p ()
  1532. {
  1533.   rtx insn = get_last_insn ();
  1534.   while (insn && GET_CODE (insn) == NOTE)
  1535.     insn = PREV_INSN (insn);
  1536.   return insn && GET_CODE (insn) != BARRIER;
  1537. }
  1538.  
  1539. /* Emit code to alter this function's formal parms for a tail-recursive call.
  1540.    ACTUALS is a list of actual parameter expressions (chain of TREE_LISTs).
  1541.    FORMALS is the chain of decls of formals.
  1542.    Return 1 if this can be done;
  1543.    otherwise return 0 and do not emit any code.  */
  1544.  
  1545. static int
  1546. tail_recursion_args (actuals, formals)
  1547.      tree actuals, formals;
  1548. {
  1549.   register tree a = actuals, f = formals;
  1550.   register int i;
  1551.   register rtx *argvec;
  1552.  
  1553.   /* Check that number and types of actuals are compatible
  1554.      with the formals.  This is not always true in valid C code.
  1555.      Also check that no formal needs to be addressable
  1556.      and that all formals are scalars.  */
  1557.  
  1558.   /* Also count the args.  */
  1559.  
  1560.   for (a = actuals, f = formals, i = 0; a && f; a = TREE_CHAIN (a), f = TREE_CHAIN (f), i++)
  1561.     {
  1562.       if (TREE_TYPE (TREE_VALUE (a)) != TREE_TYPE (f))
  1563.     return 0;
  1564.       if (GET_CODE (DECL_RTL (f)) != REG || DECL_MODE (f) == BLKmode)
  1565.     return 0;
  1566.     }
  1567.   if (a != 0 || f != 0)
  1568.     return 0;
  1569.  
  1570.   /* Compute all the actuals.  */
  1571.  
  1572.   argvec = (rtx *) alloca (i * sizeof (rtx));
  1573.  
  1574.   for (a = actuals, i = 0; a; a = TREE_CHAIN (a), i++)
  1575.     argvec[i] = expand_expr (TREE_VALUE (a), 0, VOIDmode, 0);
  1576.  
  1577.   /* Find which actual values refer to current values of previous formals.
  1578.      Copy each of them now, before any formal is changed.  */
  1579.  
  1580.   for (a = actuals, i = 0; a; a = TREE_CHAIN (a), i++)
  1581.     {
  1582.       int copy = 0;
  1583.       register int j;
  1584.       for (f = formals, j = 0; j < i; f = TREE_CHAIN (f), j++)
  1585.     if (reg_mentioned_p (DECL_RTL (f), argvec[i]))
  1586.       { copy = 1; break; }
  1587.       if (copy)
  1588.     argvec[i] = copy_to_reg (argvec[i]);
  1589.     }
  1590.  
  1591.   /* Store the values of the actuals into the formals.  */
  1592.  
  1593.   for (f = formals, a = actuals, i = 0; f;
  1594.        f = TREE_CHAIN (f), a = TREE_CHAIN (a), i++)
  1595.     {
  1596.       if (DECL_MODE (f) == GET_MODE (argvec[i]))
  1597.     emit_move_insn (DECL_RTL (f), argvec[i]);
  1598.       else
  1599.     convert_move (DECL_RTL (f), argvec[i],
  1600.               TREE_UNSIGNED (TREE_TYPE (TREE_VALUE (a))));
  1601.     }
  1602.  
  1603.   return 1;
  1604. }
  1605.  
  1606. /* Generate the RTL code for entering a binding contour.
  1607.    The variables are declared one by one, by calls to `expand_decl'.
  1608.  
  1609.    EXIT_FLAG is nonzero if this construct should be visible to
  1610.    `exit_something'.  */
  1611.  
  1612. void
  1613. expand_start_bindings (exit_flag)
  1614.      int exit_flag;
  1615. {
  1616.   struct nesting *thisblock
  1617.     = (struct nesting *) xmalloc (sizeof (struct nesting));
  1618.  
  1619.   rtx note = emit_note (0, NOTE_INSN_BLOCK_BEG);
  1620.  
  1621.   /* Make an entry on block_stack for the block we are entering.  */
  1622.  
  1623.   thisblock->next = block_stack;
  1624.   thisblock->all = nesting_stack;
  1625.   thisblock->depth = ++nesting_depth;
  1626.   thisblock->data.block.stack_level = 0;
  1627.   thisblock->data.block.cleanups = 0;
  1628.   /* We build this even if the cleanups lists are empty
  1629.      because we rely on having an element in the chain
  1630.      for each block that is pending.  */
  1631.   thisblock->data.block.outer_cleanups
  1632.     = (block_stack
  1633.        ? tree_cons (NULL_TREE, block_stack->data.block.cleanups,
  1634.             block_stack->data.block.outer_cleanups)
  1635.        : 0);
  1636.   thisblock->data.block.label_chain = 0;
  1637.   thisblock->data.block.innermost_stack_block = stack_block_stack;
  1638.   thisblock->data.block.first_insn = note;
  1639.   thisblock->exit_label = exit_flag ? gen_label_rtx () : 0;
  1640.   block_stack = thisblock;
  1641.   nesting_stack = thisblock;
  1642. }
  1643.  
  1644. /* Output a USE for any register use in RTL.
  1645.    This is used with -noreg to mark the extent of lifespan
  1646.    of any registers used in a user-visible variable's DECL_RTL.  */
  1647.  
  1648. void
  1649. use_variable (rtl)
  1650.      rtx rtl;
  1651. {
  1652.   if (GET_CODE (rtl) == REG)
  1653.     /* This is a register variable.  */
  1654.     emit_insn (gen_rtx (USE, VOIDmode, rtl));
  1655.   else if (GET_CODE (rtl) == MEM
  1656.        && GET_CODE (XEXP (rtl, 0)) == REG
  1657.        && XEXP (rtl, 0) != frame_pointer_rtx
  1658.        && XEXP (rtl, 0) != arg_pointer_rtx)
  1659.     /* This is a variable-sized structure.  */
  1660.     emit_insn (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)));
  1661. }
  1662.  
  1663. /* Like use_variable except that it outputs the USEs after INSN
  1664.    instead of at the end of the insn-chain.  */
  1665.  
  1666. static void
  1667. use_variable_after (rtl, insn)
  1668.      rtx rtl, insn;
  1669. {
  1670.   if (GET_CODE (rtl) == REG)
  1671.     /* This is a register variable.  */
  1672.     emit_insn_after (gen_rtx (USE, VOIDmode, rtl), insn);
  1673.   else if (GET_CODE (rtl) == MEM
  1674.        && GET_CODE (XEXP (rtl, 0)) == REG
  1675.        && XEXP (rtl, 0) != frame_pointer_rtx
  1676.        && XEXP (rtl, 0) != arg_pointer_rtx)
  1677.     /* This is a variable-sized structure.  */
  1678.     emit_insn_after (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)), insn);
  1679. }
  1680.  
  1681. /* Generate RTL code to terminate a binding contour.
  1682.    VARS is the chain of VAR_DECL nodes
  1683.    for the variables bound in this contour.
  1684.    MARK_ENDS is nonzero if we should put a note at the beginning
  1685.    and end of this binding contour.
  1686.  
  1687.    DONT_JUMP_IN is nonzero if it is not valid to jump into this contour.
  1688.    (That is true automatically if the contour has a saved stack level.)  */
  1689.  
  1690. void
  1691. expand_end_bindings (vars, mark_ends, dont_jump_in)
  1692.      tree vars;
  1693.      int mark_ends;
  1694.      int dont_jump_in;
  1695. {
  1696.   register struct nesting *thisblock = block_stack;
  1697.   register tree decl;
  1698.  
  1699.   if (warn_unused)
  1700.     for (decl = vars; decl; decl = TREE_CHAIN (decl))
  1701.       if (! TREE_USED (decl) && TREE_CODE (decl) == VAR_DECL)
  1702.     warning_with_decl (decl, "unused variable `%s'");
  1703.  
  1704.   /* Mark the beginning and end of the scope if requested.  */
  1705.  
  1706.   if (mark_ends)
  1707.     emit_note (0, NOTE_INSN_BLOCK_END);
  1708.   else
  1709.     /* Get rid of the beginning-mark if we don't make an end-mark.  */
  1710.     NOTE_LINE_NUMBER (thisblock->data.block.first_insn) = NOTE_INSN_DELETED;
  1711.  
  1712.   if (thisblock->exit_label)
  1713.     {
  1714.       do_pending_stack_adjust ();
  1715.       emit_label (thisblock->exit_label);
  1716.     }
  1717.  
  1718.   if (dont_jump_in
  1719.       || thisblock->data.block.stack_level != 0
  1720.       || thisblock->data.block.cleanups != 0)
  1721.     {
  1722.       struct label_chain *chain;
  1723.  
  1724.       /* Any labels in this block are no longer valid to go to.
  1725.      Mark them to cause an error message.  */
  1726.       for (chain = thisblock->data.block.label_chain; chain; chain = chain->next)
  1727.     {
  1728.       TREE_PACKED (chain->label) = 1;
  1729.       /* If any goto without a fixup came to this label,
  1730.          that must be an error, because gotos without fixups
  1731.          come from outside all saved stack-levels and all cleanups.  */
  1732.       if (TREE_ADDRESSABLE (chain->label))
  1733.         error_with_decl (chain->label,
  1734.                  "label `%s' used before containing binding contour");
  1735.     }
  1736.     }
  1737.  
  1738.   /* Restore stack level in effect before the block
  1739.      (only if variable-size objects allocated).  */
  1740.  
  1741.   if (thisblock->data.block.stack_level != 0
  1742.       || thisblock->data.block.cleanups != 0)
  1743.     {
  1744.       /* Perform any cleanups associated with the block.  */
  1745.  
  1746.       expand_cleanups (thisblock->data.block.cleanups, 0);
  1747.  
  1748.       /* Restore the stack level.  */
  1749.  
  1750.       if (thisblock->data.block.stack_level != 0)
  1751.     {
  1752.       do_pending_stack_adjust ();
  1753.       emit_move_insn (stack_pointer_rtx,
  1754.               thisblock->data.block.stack_level);
  1755.     }
  1756.  
  1757.       /* Any gotos out of this block must also do these things.
  1758.      Also report any gotos with fixups that came to labels in this level.  */
  1759.       fixup_gotos (thisblock,
  1760.            thisblock->data.block.stack_level,
  1761.            thisblock->data.block.cleanups,
  1762.            thisblock->data.block.first_insn,
  1763.            dont_jump_in);
  1764.     }
  1765.  
  1766.   /* If doing stupid register allocation, make sure lives of all
  1767.      register variables declared here extend thru end of scope.  */
  1768.  
  1769.   if (obey_regdecls)
  1770.     for (decl = vars; decl; decl = TREE_CHAIN (decl))
  1771.       {
  1772.     rtx rtl = DECL_RTL (decl);
  1773.     if (TREE_CODE (decl) == VAR_DECL && rtl != 0)
  1774.       use_variable (rtl);
  1775.       }
  1776.  
  1777.   /* Restore block_stack level for containing block.  */
  1778.  
  1779.   stack_block_stack = thisblock->data.block.innermost_stack_block;
  1780.   POPSTACK (block_stack);
  1781. }
  1782.  
  1783. /* Generate RTL for the automatic variable declaration DECL.
  1784.    (Other kinds of declarations are simply ignored if seen here.)
  1785.    CLEANUP is an expression to be executed at exit from this binding contour;
  1786.    for example, in C++, it might call the destructor for this variable.
  1787.  
  1788.    If CLEANUP contains any SAVE_EXPRs, then you must preevaluate them
  1789.    either before or after calling `expand_decl' but before compiling
  1790.    any subsequent expressions.  This is because CLEANUP may be expanded
  1791.    more than once, on different branches of execution.
  1792.    For the same reason, CLEANUP may not contain a CALL_EXPR
  1793.    except as its topmost node--else `preexpand_calls' would get confused.
  1794.  
  1795.    If CLEANUP is nonzero and DECL is zero, we record a cleanup
  1796.    that is not associated with any particular variable.
  1797.  
  1798.    There is no special support here for C++ constructors.
  1799.    They should be handled by the proper code in DECL_INITIAL.  */
  1800.  
  1801. void
  1802. expand_decl (decl, cleanup)
  1803.      register tree decl;
  1804.      tree cleanup;
  1805. {
  1806.   struct nesting *thisblock = block_stack;
  1807.   tree type;
  1808.   
  1809.   /* Record the cleanup if there is one.  */
  1810.  
  1811.   if (cleanup != 0)
  1812.     {
  1813.       thisblock->data.block.cleanups
  1814.     = temp_tree_cons (decl, cleanup, thisblock->data.block.cleanups);
  1815.       /* If this block has a cleanup, it belongs in stack_block_stack.  */
  1816.       stack_block_stack = thisblock;
  1817.     }
  1818.  
  1819.   if (decl == NULL_TREE)
  1820.     {
  1821.       /* This was a cleanup with no variable.  */
  1822.       if (cleanup == 0)
  1823.     abort ();
  1824.       return;
  1825.     }
  1826.  
  1827.   type = TREE_TYPE (decl);
  1828.  
  1829.   /* Aside from that, only automatic variables need any expansion done.
  1830.      Static and external variables, and external functions,
  1831.      will be handled by `assemble_variable' (called from finish_decl).
  1832.      TYPE_DECL and CONST_DECL require nothing.
  1833.      PARM_DECLs are handled in `assign_parms'.  */
  1834.  
  1835.   if (TREE_CODE (decl) != VAR_DECL)
  1836.     return;
  1837.   if (TREE_STATIC (decl) || TREE_EXTERNAL (decl))
  1838.     return;
  1839.  
  1840.   /* Create the RTL representation for the variable.  */
  1841.  
  1842.   if (type == error_mark_node)
  1843.     DECL_RTL (decl) = gen_rtx (MEM, BLKmode, const0_rtx);
  1844.   else if (DECL_SIZE (decl) == 0)
  1845.     /* Variable with incomplete type.  */
  1846.     {
  1847.       if (DECL_INITIAL (decl) == 0)
  1848.     /* Error message was already done; now avoid a crash.  */
  1849.     DECL_RTL (decl) = assign_stack_local (DECL_MODE (decl), 0);
  1850.       else
  1851.     /* An initializer is going to decide the size of this array.
  1852.        Until we know the size, represent its address with a reg.  */
  1853.     DECL_RTL (decl) = gen_rtx (MEM, BLKmode, gen_reg_rtx (Pmode));
  1854.     }
  1855.   else if (DECL_MODE (decl) != BLKmode
  1856.        /* If -ffloat-store, don't put explicit float vars
  1857.           into regs.  */
  1858.        && !(flag_float_store
  1859.         && TREE_CODE (type) == REAL_TYPE)
  1860.        && ! TREE_VOLATILE (decl)
  1861.        && ! TREE_ADDRESSABLE (decl)
  1862.        && (TREE_REGDECL (decl) || ! obey_regdecls))
  1863.     {
  1864.       /* Automatic variable that can go in a register.  */
  1865.       DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
  1866.       if (TREE_CODE (type) == POINTER_TYPE)
  1867.     mark_reg_pointer (DECL_RTL (decl));
  1868.       REG_USERVAR_P (DECL_RTL (decl)) = 1;
  1869.     }
  1870.   else if (TREE_LITERAL (DECL_SIZE (decl)))
  1871.     {
  1872.       rtx oldaddr = 0;
  1873.       rtx addr;
  1874.  
  1875.       /* If we previously made RTL for this decl, it must be an array
  1876.      whose size was determined by the initializer.
  1877.      The old address was a register; set that register now
  1878.      to the proper address.  */
  1879.       if (DECL_RTL (decl) != 0)
  1880.     {
  1881.       if (GET_CODE (DECL_RTL (decl)) != MEM
  1882.           || GET_CODE (XEXP (DECL_RTL (decl), 0)) != REG)
  1883.         abort ();
  1884.       oldaddr = XEXP (DECL_RTL (decl), 0);
  1885.     }
  1886.  
  1887.       /* Variable of fixed size that goes on the stack.  */
  1888.       DECL_RTL (decl)
  1889.     = assign_stack_local (DECL_MODE (decl),
  1890.                   (TREE_INT_CST_LOW (DECL_SIZE (decl))
  1891.                    * DECL_SIZE_UNIT (decl)
  1892.                    + BITS_PER_UNIT - 1)
  1893.                   / BITS_PER_UNIT);
  1894.       if (oldaddr)
  1895.     {
  1896.       addr = force_operand (XEXP (DECL_RTL (decl), 0), oldaddr);
  1897.       emit_move_insn (oldaddr, addr);
  1898.     }
  1899.  
  1900.       /* If this is a memory ref that contains aggregate components,
  1901.      mark it as such for cse and loop optimize.  */
  1902.       MEM_IN_STRUCT_P (DECL_RTL (decl))
  1903.     = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
  1904.        || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
  1905.        || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE);
  1906. #if 0
  1907.       /* If this is in memory because of -ffloat-store,
  1908.      set the volatile bit, to prevent optimizations from
  1909.      undoing the effects.  */
  1910.       if (flag_float_store && TREE_CODE (type) == REAL_TYPE)
  1911.     MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
  1912. #endif
  1913.     }
  1914.   else
  1915.     /* Dynamic-size object: must push space on the stack.  */
  1916.     {
  1917.       rtx address, size;
  1918.  
  1919.       frame_pointer_needed = 1;
  1920.  
  1921.       /* Record the stack pointer on entry to block, if have
  1922.      not already done so.  */
  1923.       if (thisblock->data.block.stack_level == 0)
  1924.     {
  1925.       do_pending_stack_adjust ();
  1926.       thisblock->data.block.stack_level
  1927.         = copy_to_reg (stack_pointer_rtx);
  1928.       stack_block_stack = thisblock;
  1929.     }
  1930.  
  1931.       /* Compute the variable's size, in bytes.  */
  1932.       size = expand_expr (convert_units (DECL_SIZE (decl),
  1933.                      DECL_SIZE_UNIT (decl),
  1934.                      BITS_PER_UNIT),
  1935.               0, VOIDmode, 0);
  1936.  
  1937.       /* Round it up to this machine's required stack boundary.  */
  1938. #ifdef STACK_BOUNDARY
  1939.       /* Avoid extra code if we can prove it's a multiple already.  */
  1940.       if (DECL_SIZE_UNIT (decl) % STACK_BOUNDARY)
  1941.     size = round_push (size);
  1942. #endif
  1943.  
  1944.       /* Make space on the stack, and get an rtx for the address of it.  */
  1945. #ifdef STACK_GROWS_DOWNWARD
  1946.       anti_adjust_stack (size);
  1947. #endif
  1948.       address = copy_to_reg (stack_pointer_rtx);
  1949. #ifdef STACK_POINTER_OFFSET
  1950.       /* If the contents of the stack pointer reg are offset from the
  1951.      actual top-of-stack address, add the offset here.  */
  1952.       emit_insn (gen_add2_insn (address, gen_rtx (CONST_INT, VOIDmode,
  1953.                           STACK_POINTER_OFFSET)));
  1954. #endif
  1955. #ifndef STACK_GROWS_DOWNWARD
  1956.       anti_adjust_stack (size);
  1957. #endif
  1958.  
  1959.       /* Reference the variable indirect through that rtx.  */
  1960.       DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl), address);
  1961.     }
  1962.  
  1963.   if (TREE_VOLATILE (decl))
  1964.     MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
  1965.   if (TREE_READONLY (decl))
  1966.     RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
  1967.  
  1968.   /* If doing stupid register allocation, make sure life of any
  1969.      register variable starts here, at the start of its scope.  */
  1970.  
  1971.   if (obey_regdecls)
  1972.     use_variable (DECL_RTL (decl));
  1973. }
  1974.  
  1975. /* Emit code to perform the initialization of a declaration DECL.  */
  1976.  
  1977. void
  1978. expand_decl_init (decl)
  1979.      tree decl;
  1980. {
  1981.   if (TREE_STATIC (decl))
  1982.     return;
  1983.  
  1984.   /* Compute and store the initial value now.  */
  1985.  
  1986.   if (DECL_INITIAL (decl) == error_mark_node)
  1987.     {
  1988.       enum tree_code code = TREE_CODE (TREE_TYPE (decl));
  1989.       if (code == INTEGER_TYPE || code == REAL_TYPE || code == ENUMERAL_TYPE
  1990.       || code == POINTER_TYPE)
  1991.     expand_assignment (decl, convert (TREE_TYPE (decl), integer_zero_node),
  1992.                0, 0);
  1993.       emit_queue ();
  1994.     }
  1995.   else if (DECL_INITIAL (decl) && TREE_CODE (DECL_INITIAL (decl)) != TREE_LIST)
  1996.     {
  1997.       emit_line_note (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
  1998.       expand_assignment (decl, DECL_INITIAL (decl), 0, 0);
  1999.       emit_queue ();
  2000.     }
  2001. }
  2002.  
  2003. /* DECL is an anonymous union.  CLEANUP is a cleanup for DECL.
  2004.    DECL_ELTS is the list of elements that belong to DECL's type.
  2005.    In each, the TREE_VALUE is a VAR_DECL, and the TREE_PURPOSE a cleanup.  */
  2006.  
  2007. void
  2008. expand_anon_union_decl (decl, cleanup, decl_elts)
  2009.      tree decl, cleanup, decl_elts;
  2010. {
  2011.   struct nesting *thisblock = block_stack;
  2012.   rtx x;
  2013.  
  2014.   expand_decl (decl, cleanup);
  2015.   x = DECL_RTL (decl);
  2016.  
  2017.   while (decl_elts)
  2018.     {
  2019.       tree decl_elt = TREE_VALUE (decl_elts);
  2020.       tree cleanup_elt = TREE_PURPOSE (decl_elts);
  2021.  
  2022.       DECL_RTL (decl_elt)
  2023.     = (GET_MODE (x) != BLKmode
  2024. /*
  2025. #error broken
  2026. /* ??? This is incorrect if X is a MEM.
  2027.    (SUBREG (MEM)) is not allowed at rtl generation time.  */
  2028.        ? gen_rtx (SUBREG, TYPE_MODE (TREE_TYPE (decl_elt)), x, 0)
  2029.        : x);
  2030.  
  2031.       /* Record the cleanup if there is one.  */
  2032.  
  2033.       if (cleanup != 0)
  2034.     thisblock->data.block.cleanups
  2035.       = temp_tree_cons (decl_elt, cleanup_elt,
  2036.                 thisblock->data.block.cleanups);
  2037.  
  2038.       decl_elts = TREE_CHAIN (decl_elts);
  2039.     }
  2040. }
  2041.  
  2042. /* Expand a list of cleanups LIST.
  2043.    Elements may be expressions or may be nested lists.
  2044.  
  2045.    If DONT_DO is nonnull, then any list-element
  2046.    whose TREE_PURPOSE matches DONT_DO is omitted.
  2047.    This is sometimes used to avoid a cleanup associated with
  2048.    a value that is being returned out of the scope.  */
  2049.  
  2050. static void
  2051. expand_cleanups (list, dont_do)
  2052.      tree list;
  2053.      tree dont_do;
  2054. {
  2055.   tree tail;
  2056.   for (tail = list; tail; tail = TREE_CHAIN (tail))
  2057.     if (dont_do == 0 || TREE_PURPOSE (tail) != dont_do)
  2058.       {
  2059.     if (TREE_CODE (TREE_VALUE (tail)) == TREE_LIST)
  2060.       expand_cleanups (TREE_VALUE (tail), dont_do);
  2061.     else
  2062.       expand_expr (TREE_VALUE (tail), const0_rtx, VOIDmode, 0);
  2063.       }
  2064. }
  2065.  
  2066. /* Expand a list of cleanups for a goto fixup.
  2067.    The expansion is put into the insn chain after the insn *BEFORE_JUMP
  2068.    and *BEFORE_JUMP is set to the insn that now comes before the jump.  */
  2069.  
  2070. static void
  2071. fixup_cleanups (list, before_jump)
  2072.      tree list;
  2073.      rtx *before_jump;
  2074. {
  2075.   rtx beyond_jump = get_last_insn ();
  2076.   rtx new_before_jump;
  2077.  
  2078.   expand_cleanups (list, 0);
  2079.   new_before_jump = get_last_insn ();
  2080.  
  2081.   reorder_insns (NEXT_INSN (beyond_jump), new_before_jump, *before_jump);
  2082.   *before_jump = new_before_jump;
  2083. }
  2084.  
  2085. /* Move all cleanups from the current block_stack
  2086.    to the containing block_stack, where they are assumed to
  2087.    have been created.  If anything can cause a temporary to
  2088.    be created, but not expanded for more than one level of
  2089.    block_stacks, then this code will have to change.  */
  2090.  
  2091. void
  2092. move_cleanups_up ()
  2093. {
  2094.   struct nesting *block = block_stack;
  2095.   struct nesting *outer = block->next;
  2096.  
  2097.   outer->data.block.cleanups
  2098.     = chainon (block->data.block.cleanups,
  2099.            outer->data.block.cleanups);
  2100.   block->data.block.cleanups = 0;
  2101. }
  2102.  
  2103. int
  2104. this_contour_has_cleanups_p ()
  2105. {
  2106.   return block_stack && block_stack->data.block.cleanups != 0;
  2107. }
  2108.  
  2109. /* Enter a case (Pascal) or switch (C) statement.
  2110.    Push a block onto case_stack and nesting_stack
  2111.    to accumulate the case-labels that are seen
  2112.    and to record the labels generated for the statement.
  2113.  
  2114.    EXIT_FLAG is nonzero if `exit_something' should exit this case stmt.
  2115.    Otherwise, this construct is transparent for `exit_something'.
  2116.  
  2117.    EXPR is the index-expression to be dispatched on.
  2118.    TYPE is its nominal type.  We could simply convert EXPR to this type,
  2119.    but instead we take short cuts.  */
  2120.  
  2121. void
  2122. expand_start_case (exit_flag, expr, type)
  2123.      int exit_flag;
  2124.      tree expr;
  2125.      tree type;
  2126. {
  2127.   register struct nesting *thiscase
  2128.     = (struct nesting *) xmalloc (sizeof (struct nesting));
  2129.  
  2130.   /* Make an entry on case_stack for the case we are entering.  */
  2131.  
  2132.   thiscase->next = case_stack;
  2133.   thiscase->all = nesting_stack;
  2134.   thiscase->depth = ++nesting_depth;
  2135.   thiscase->exit_label = exit_flag ? gen_label_rtx () : 0;
  2136.   thiscase->data.case_stmt.case_list = 0;
  2137.   thiscase->data.case_stmt.index_expr = expr;
  2138.   thiscase->data.case_stmt.nominal_type = type;
  2139.   thiscase->data.case_stmt.default_label = 0;
  2140.   thiscase->data.case_stmt.num_ranges = 0;
  2141.   case_stack = thiscase;
  2142.   nesting_stack = thiscase;
  2143.  
  2144.   do_pending_stack_adjust ();
  2145.  
  2146.   /* Make sure case_stmt.start points to something that won't
  2147.      need any transformation before expand_end_case.  */
  2148.   if (GET_CODE (get_last_insn ()) != NOTE)
  2149.     emit_note (0, NOTE_INSN_DELETED);
  2150.  
  2151.   thiscase->data.case_stmt.start = get_last_insn ();
  2152. }
  2153.  
  2154. /* Start a "dummy case statement" within which case labels are invalid
  2155.    and are not connected to any larger real case statement.
  2156.    This can be used if you don't want to let a case statement jump
  2157.    into the middle of certain kinds of constructs.  */
  2158.  
  2159. void
  2160. expand_start_case_dummy ()
  2161. {
  2162.   register struct nesting *thiscase
  2163.     = (struct nesting *) xmalloc (sizeof (struct nesting));
  2164.  
  2165.   /* Make an entry on case_stack for the dummy.  */
  2166.  
  2167.   thiscase->next = case_stack;
  2168.   thiscase->all = nesting_stack;
  2169.   thiscase->depth = ++nesting_depth;
  2170.   thiscase->exit_label = 0;
  2171.   thiscase->data.case_stmt.case_list = 0;
  2172.   thiscase->data.case_stmt.start = 0;
  2173.   thiscase->data.case_stmt.nominal_type = 0;
  2174.   thiscase->data.case_stmt.default_label = 0;
  2175.   thiscase->data.case_stmt.num_ranges = 0;
  2176.   case_stack = thiscase;
  2177.   nesting_stack = thiscase;
  2178. }
  2179.  
  2180. /* End a dummy case statement.  */
  2181.  
  2182. void
  2183. expand_end_case_dummy ()
  2184. {
  2185.   POPSTACK (case_stack);
  2186. }
  2187.  
  2188. /* Accumulate one case or default label inside a case or switch statement.
  2189.    VALUE is the value of the case (a null pointer, for a default label).
  2190.  
  2191.    If not currently inside a case or switch statement, return 1 and do
  2192.    nothing.  The caller will print a language-specific error message.
  2193.    If VALUE is a duplicate or overlaps, return 2 and do nothing.
  2194.    If VALUE is out of range, return 3 and do nothing.
  2195.    Return 0 on success.
  2196.  
  2197.    Extended to handle range statements, should they ever
  2198.    be adopted.  */
  2199.  
  2200. int
  2201. pushcase (value, label)
  2202.      register tree value;
  2203.      register tree label;
  2204. {
  2205.   register struct case_node **l;
  2206.   register struct case_node *n;
  2207.   tree index_type;
  2208.   tree nominal_type;
  2209.  
  2210.   /* Fail if not inside a real case statement.  */
  2211.   if (! (case_stack && case_stack->data.case_stmt.start))
  2212.     return 1;
  2213.  
  2214.   index_type = TREE_TYPE (case_stack->data.case_stmt.index_expr);
  2215.   nominal_type = case_stack->data.case_stmt.nominal_type;
  2216.  
  2217.   /* If the index is erroneous, avoid more problems: pretend to succeed.  */
  2218.   if (index_type == error_mark_node)
  2219.     return 0;
  2220.  
  2221.   /* Convert VALUE to the type in which the comparisons are nominally done.  */
  2222.   if (value != 0)
  2223.     value = convert (nominal_type, value);
  2224.  
  2225.   /* Fail if this value is out of range for the actual type of the index
  2226.      (which may be narrower than NOMINAL_TYPE).  */
  2227.   if (value != 0 && ! int_fits_type_p (value, index_type))
  2228.     return 3;
  2229.  
  2230.   /* Fail if this is a duplicate or overlaps another entry.  */
  2231.   if (value == 0)
  2232.     {
  2233.       if (case_stack->data.case_stmt.default_label != 0)
  2234.     return 2;
  2235.       case_stack->data.case_stmt.default_label = label;
  2236.     }
  2237.   else
  2238.     {
  2239.       /* Find the elt in the chain before which to insert the new value,
  2240.      to keep the chain sorted in increasing order.
  2241.      But report an error if this element is a duplicate.  */
  2242.       for (l = &case_stack->data.case_stmt.case_list;
  2243.        /* Keep going past elements distinctly less than VALUE.  */
  2244.        *l != 0 && tree_int_cst_lt ((*l)->high, value);
  2245.        l = &(*l)->right)
  2246.     ;
  2247.       if (*l)
  2248.     {
  2249.       /* Element we will insert before must be distinctly greater;
  2250.          overlap means error.  */
  2251.       if (! tree_int_cst_lt (value, (*l)->low))
  2252.         return 2;
  2253.     }
  2254.  
  2255.       /* Add this label to the chain, and succeed.
  2256.      Copy VALUE so it is on temporary rather than momentary
  2257.      obstack and will thus survive till the end of the case statement.  */
  2258.       n = (struct case_node *) oballoc (sizeof (struct case_node));
  2259.       n->left = 0;
  2260.       n->right = *l;
  2261.       n->high = n->low = copy_node (value);
  2262.       n->code_label = label;
  2263.       n->test_label = 0;
  2264.       *l = n;
  2265.     }
  2266.  
  2267.   expand_label (label);
  2268.   return 0;
  2269. }
  2270.  
  2271. /* Like pushcase but this case applies to all values
  2272.    between VALUE1 and VALUE2 (inclusive).
  2273.    The return value is the same as that of pushcase
  2274.    but there is one additional error code:
  2275.    4 means the specified range was empty.
  2276.  
  2277.    Note that this does not currently work, since expand_end_case
  2278.    has yet to be extended to handle RANGE_EXPRs.  */
  2279.  
  2280. int
  2281. pushcase_range (value1, value2, label)
  2282.      register tree value1, value2;
  2283.      register tree label;
  2284. {
  2285.   register struct case_node **l;
  2286.   register struct case_node *n;
  2287.   tree index_type;
  2288.   tree nominal_type;
  2289.  
  2290.   /* Fail if not inside a real case statement.  */
  2291.   if (! (case_stack && case_stack->data.case_stmt.start))
  2292.     return 1;
  2293.  
  2294.   index_type = TREE_TYPE (case_stack->data.case_stmt.index_expr);
  2295.   nominal_type = case_stack->data.case_stmt.nominal_type;
  2296.  
  2297.   /* If the index is erroneous, avoid more problems: pretend to succeed.  */
  2298.   if (index_type == error_mark_node)
  2299.     return 0;
  2300.  
  2301.   /* Convert VALUEs to type in which the comparisons are nominally done.  */
  2302.   if (value1 != 0)
  2303.     value1 = convert (nominal_type, value1);
  2304.   if (value2 != 0)
  2305.     value2 = convert (nominal_type, value2);
  2306.  
  2307.   /* Fail if these values are out of range.  */
  2308.   if (value1 != 0 && ! int_fits_type_p (value1, index_type))
  2309.     return 3;
  2310.  
  2311.   if (value2 != 0 && ! int_fits_type_p (value2, index_type))
  2312.     return 3;
  2313.  
  2314.   /* Fail if the range is empty.  */
  2315.   if (tree_int_cst_lt (value2, value1))
  2316.     return 4;
  2317.  
  2318.   /* If the bounds are equal, turn this into the one-value case.  */
  2319.   if (tree_int_cst_equal (value1, value2))
  2320.     return pushcase (value1, label);
  2321.  
  2322.   /* Find the elt in the chain before which to insert the new value,
  2323.      to keep the chain sorted in increasing order.
  2324.      But report an error if this element is a duplicate.  */
  2325.   for (l = &case_stack->data.case_stmt.case_list;
  2326.        /* Keep going past elements distinctly less than this range.  */
  2327.        *l != 0 && tree_int_cst_lt ((*l)->high, value1);
  2328.        l = &(*l)->right)
  2329.     ;
  2330.   if (*l)
  2331.     {
  2332.       /* Element we will insert before must be distinctly greater;
  2333.      overlap means error.  */
  2334.       if (! tree_int_cst_lt (value2, (*l)->low))
  2335.     return 2;
  2336.     }
  2337.  
  2338.   /* Add this label to the chain, and succeed.
  2339.      Copy VALUE1, VALUE2 so they are on temporary rather than momentary
  2340.      obstack and will thus survive till the end of the case statement.  */
  2341.  
  2342.   n = (struct case_node *) oballoc (sizeof (struct case_node));
  2343.   n->left = 0;
  2344.   n->right = *l;
  2345.   n->low = copy_node (value1);
  2346.   n->high = copy_node (value2);
  2347.   n->code_label = label;
  2348.   n->test_label = 0;
  2349.   *l = n;
  2350.  
  2351.   expand_label (label);
  2352.  
  2353.   case_stack->data.case_stmt.num_ranges++;
  2354.  
  2355.   return 0;
  2356. }
  2357.  
  2358. /* Check that all enumeration literals are covered by the case
  2359.    expressions of a switch.  Also, warn if there are any extra
  2360.    switch cases that are *not* elements of the enumerated type. */
  2361.  
  2362. void
  2363. check_for_full_enumeration_handling ()
  2364. {
  2365.   tree index_expr = case_stack->data.case_stmt.index_expr;
  2366.  
  2367.   if (TREE_CODE (index_expr) == INTEGER_CST)
  2368.     return;
  2369.   else
  2370.     {
  2371.       register struct case_node *n;
  2372.       register tree chain;
  2373.       tree enum_node = TREE_OPERAND (index_expr, 0);
  2374.           
  2375.       /* The time complexity of this loop is currently O(N * M), with
  2376.          N being the number of enumerals in the enumerated type, and 
  2377.          M being the number of case expressions in the switch. */
  2378.              
  2379.       for (chain = TYPE_VALUES (TREE_TYPE (enum_node));
  2380.            chain; 
  2381.            chain = TREE_CHAIN (chain))
  2382.         {
  2383.           /* Find a match between enumeral and case expression, if possible.
  2384.              Quit looking when we've gone too far (since case expressions
  2385.              are kept sorted in ascending order).  Warn about enumerals not
  2386.              handled in the switch statement case expression list. */
  2387.  
  2388.           for (n = case_stack->data.case_stmt.case_list; 
  2389.                n && tree_int_cst_lt (n->high, TREE_VALUE (chain));
  2390.                n = n->right)
  2391.             ;
  2392.  
  2393.           if (!(n && tree_int_cst_equal (n->low, TREE_VALUE (chain))))
  2394.         warning ("enumerated value `%s' not handled in switch",
  2395.              IDENTIFIER_POINTER (TREE_PURPOSE (chain)));
  2396.         }
  2397.  
  2398.       /* Now we go the other way around; we warn if there are case 
  2399.          expressions that don't correspond to enumerals.  This can
  2400.          occur since C and C++ don't enforce type-checking of 
  2401.          assignments to enumeration variables. */
  2402.  
  2403.       for (n = case_stack->data.case_stmt.case_list; n; n = n->right)
  2404.         {
  2405.           for (chain = TYPE_VALUES ( TREE_TYPE (enum_node));
  2406.                chain && !tree_int_cst_equal (n->low, TREE_VALUE (chain)); 
  2407.                chain = TREE_CHAIN (chain))
  2408.             ;
  2409.  
  2410.           if (!chain)
  2411.         warning ("case value `%d' not in enumerated type `%s'",
  2412.              TREE_INT_CST_LOW (n->low), 
  2413.              IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (TREE_TYPE (enum_node)))));
  2414.         }
  2415.     }
  2416. }
  2417.  
  2418. /* Terminate a case (Pascal) or switch (C) statement
  2419.    in which CASE_INDEX is the expression to be tested.
  2420.    Generate the code to test it and jump to the right place.  */
  2421.  
  2422. void
  2423. expand_end_case (orig_index)
  2424.      tree orig_index;
  2425. {
  2426.   tree minval, maxval, range;
  2427.   rtx default_label = 0;
  2428.   register struct case_node *n;
  2429.   int count;
  2430.   rtx index;
  2431.   rtx table_label = gen_label_rtx ();
  2432.   int ncases;
  2433.   rtx *labelvec;
  2434.   register int i;
  2435.   rtx before_case;
  2436.   register struct nesting *thiscase = case_stack;
  2437.   tree index_expr = thiscase->data.case_stmt.index_expr;
  2438.  
  2439.   do_pending_stack_adjust ();
  2440.  
  2441.   /* An ERROR_MARK occurs for various reasons including invalid data type.  */
  2442.   if (TREE_TYPE (index_expr) != error_mark_node)
  2443.     {
  2444.       /* If switch expression was an enumerated type, check that all
  2445.      enumeration literals are covered by the cases.
  2446.      No sense trying this if there's a default case, however.  */
  2447.  
  2448.       if (!thiscase->data.case_stmt.default_label 
  2449.       && TREE_CODE (TREE_TYPE (orig_index)) == ENUMERAL_TYPE
  2450.       && warn_switch)
  2451.     check_for_full_enumeration_handling ();
  2452.  
  2453.       /* If we don't have a default-label, create one here,
  2454.      after the body of the switch.  */
  2455.       if (thiscase->data.case_stmt.default_label == 0)
  2456.     {
  2457.       thiscase->data.case_stmt.default_label
  2458.         = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  2459.       expand_label (thiscase->data.case_stmt.default_label);
  2460.     }
  2461.       default_label = label_rtx (thiscase->data.case_stmt.default_label);
  2462.  
  2463.       before_case = get_last_insn ();
  2464.  
  2465.       /* Simplify the case-list before we count it.  */
  2466.       group_case_nodes (thiscase->data.case_stmt.case_list);
  2467.  
  2468.       /* Get upper and lower bounds of case values.
  2469.      Also convert all the case values to the index expr's data type.  */
  2470.  
  2471.       count = 0;
  2472.       for (n = thiscase->data.case_stmt.case_list; n; n = n->right)
  2473.     {
  2474.       /* Check low and high label values are integers.  */
  2475.       if (TREE_CODE (n->low) != INTEGER_CST)
  2476.         abort ();
  2477.       if (TREE_CODE (n->high) != INTEGER_CST)
  2478.         abort ();
  2479.  
  2480.       n->low = convert (TREE_TYPE (index_expr), n->low);
  2481.       n->high = convert (TREE_TYPE (index_expr), n->high);
  2482.  
  2483.       /* Count the elements and track the largest and smallest
  2484.          of them (treating them as signed even if they are not).  */
  2485.       if (count++ == 0)
  2486.         {
  2487.           minval = n->low;
  2488.           maxval = n->high;
  2489.         }
  2490.       else
  2491.         {
  2492.           if (INT_CST_LT (n->low, minval))
  2493.         minval = n->low;
  2494.           if (INT_CST_LT (maxval, n->high))
  2495.         maxval = n->high;
  2496.         }
  2497.       /* A range counts double, since it requires two compares.  */
  2498.       if (! tree_int_cst_equal (n->low, n->high))
  2499.         count++;
  2500.     }
  2501.  
  2502.       /* Compute span of values.  */
  2503.       if (count != 0)
  2504.     range = combine (MINUS_EXPR, maxval, minval);
  2505.  
  2506.       if (count == 0 || TREE_CODE (TREE_TYPE (index_expr)) == ERROR_MARK)
  2507.     {
  2508.       expand_expr (index_expr, const0_rtx, VOIDmode, 0);
  2509.       emit_queue ();
  2510.       emit_jump (default_label);
  2511.     }
  2512.       /* If range of values is much bigger than number of values,
  2513.      make a sequence of conditional branches instead of a dispatch.
  2514.      If the switch-index is a constant, do it this way
  2515.      because we can optimize it.  */
  2516.       else if (TREE_INT_CST_HIGH (range) != 0
  2517. #ifdef HAVE_casesi
  2518.            || count < 4
  2519. #else
  2520.            /* If machine does not have a case insn that compares the
  2521.           bounds, this means extra overhead for dispatch tables
  2522.           which raises the threshold for using them.  */
  2523.            || count < 5
  2524. #endif
  2525.            || (unsigned) (TREE_INT_CST_LOW (range)) > 10 * count
  2526.            || TREE_CODE (index_expr) == INTEGER_CST)
  2527.     {
  2528.       index = expand_expr (index_expr, 0, VOIDmode, 0);
  2529.       emit_queue ();
  2530.       do_pending_stack_adjust ();
  2531.  
  2532.       index = protect_from_queue (index, 0);
  2533.       if (GET_CODE (index) == MEM)
  2534.         index = copy_to_reg (index);
  2535.       if (GET_CODE (index) == CONST_INT
  2536.           || TREE_CODE (index_expr) == INTEGER_CST)
  2537.         {
  2538.           /* Make a tree node with the proper constant value
  2539.          if we don't already have one.  */
  2540.           if (TREE_CODE (index_expr) != INTEGER_CST)
  2541.         {
  2542.           index_expr = build_int_2 (INTVAL (index), 0);
  2543.           index_expr = convert (TREE_TYPE (index_expr), index_expr);
  2544.         }
  2545.  
  2546.           /* For constant index expressions we need only
  2547.          issue a unconditional branch to the appropriate
  2548.          target code.  The job of removing any unreachable
  2549.          code is left to the optimisation phase if the
  2550.          "-O" option is specified.  */
  2551.           for (n = thiscase->data.case_stmt.case_list;
  2552.            n;
  2553.            n = n->right)
  2554.         {
  2555.           if (! tree_int_cst_lt (index_expr, n->low)
  2556.               && ! tree_int_cst_lt (n->high, index_expr))
  2557.             break;
  2558.         }
  2559.           if (n)
  2560.         emit_jump (label_rtx (n->code_label));
  2561.           else
  2562.         emit_jump (default_label);
  2563.         }
  2564.       else
  2565.         {
  2566.           /* If the index expression is not constant we generate
  2567.          a binary decision tree to select the appropriate
  2568.          target code.  This is done as follows:
  2569.  
  2570.          The list of cases is rearranged into a binary tree,
  2571.          nearly optimal assuming equal probability for each case.
  2572.  
  2573.          The tree is transformed into RTL, eliminating
  2574.          redundant test conditions at the same time.
  2575.  
  2576.          If program flow could reach the end of the
  2577.          decision tree an unconditional jump to the
  2578.          default code is emitted.  */
  2579.           balance_case_nodes (&thiscase->data.case_stmt.case_list, 0);
  2580.           emit_case_nodes (index, thiscase->data.case_stmt.case_list,
  2581.                    default_label,
  2582.                    TREE_UNSIGNED (TREE_TYPE (index_expr)));
  2583.           emit_jump_if_reachable (default_label);
  2584.         }
  2585.     }
  2586.       else
  2587.     {
  2588. #ifdef HAVE_casesi
  2589.       /* Convert the index to SImode.  */
  2590.       if (TYPE_MODE (TREE_TYPE (index_expr)) == DImode)
  2591.         {
  2592.           index_expr = build (MINUS_EXPR, TREE_TYPE (index_expr),
  2593.                   index_expr, minval);
  2594.           minval = integer_zero_node;
  2595.         }
  2596.       if (TYPE_MODE (TREE_TYPE (index_expr)) != SImode)
  2597.         index_expr = convert (type_for_size (GET_MODE_BITSIZE (SImode), 0),
  2598.                   index_expr);
  2599.       index = expand_expr (index_expr, 0, VOIDmode, 0);
  2600.       emit_queue ();
  2601.       index = protect_from_queue (index, 0);
  2602.       do_pending_stack_adjust ();
  2603.  
  2604.       emit_jump_insn (gen_casesi (index, expand_expr (minval, 0, VOIDmode, 0),
  2605.                       expand_expr (range, 0, VOIDmode, 0),
  2606.                       table_label, default_label));
  2607. #else
  2608. #ifdef HAVE_tablejump
  2609.       index_expr = convert (type_for_size (GET_MODE_BITSIZE (SImode), 0),
  2610.                 build (MINUS_EXPR, TREE_TYPE (index_expr),
  2611.                        index_expr, minval));
  2612.       index = expand_expr (index_expr, 0, VOIDmode, 0);
  2613.       emit_queue ();
  2614.       index = protect_from_queue (index, 0);
  2615.       do_pending_stack_adjust ();
  2616.  
  2617.       do_tablejump (index,
  2618.             gen_rtx (CONST_INT, VOIDmode, TREE_INT_CST_LOW (range)),
  2619.             table_label, default_label);
  2620. #else
  2621.       lossage;
  2622. #endif                /* not HAVE_tablejump */
  2623. #endif                /* not HAVE_casesi */
  2624.  
  2625.       /* Get table of labels to jump to, in order of case index.  */
  2626.  
  2627.       ncases = TREE_INT_CST_LOW (range) + 1;
  2628.       labelvec = (rtx *) alloca (ncases * sizeof (rtx));
  2629.       bzero (labelvec, ncases * sizeof (rtx));
  2630.  
  2631.       for (n = thiscase->data.case_stmt.case_list; n; n = n->right)
  2632.         {
  2633.           register int i
  2634.         = TREE_INT_CST_LOW (n->low) - TREE_INT_CST_LOW (minval);
  2635.  
  2636.           while (i + TREE_INT_CST_LOW (minval)
  2637.              <= TREE_INT_CST_LOW (n->high))
  2638.         labelvec[i++]
  2639.           = gen_rtx (LABEL_REF, Pmode, label_rtx (n->code_label));
  2640.         }
  2641.  
  2642.       /* Fill in the gaps with the default.  */
  2643.       for (i = 0; i < ncases; i++)
  2644.         if (labelvec[i] == 0)
  2645.           labelvec[i] = gen_rtx (LABEL_REF, Pmode, default_label);
  2646.  
  2647.       /* Output the table */
  2648.       emit_label (table_label);
  2649.  
  2650. #ifdef CASE_VECTOR_PC_RELATIVE
  2651.       emit_jump_insn (gen_rtx (ADDR_DIFF_VEC, CASE_VECTOR_MODE,
  2652.                    gen_rtx (LABEL_REF, Pmode, table_label),
  2653.                    gen_rtvec_v (ncases, labelvec)));
  2654. #else
  2655.       emit_jump_insn (gen_rtx (ADDR_VEC, CASE_VECTOR_MODE,
  2656.                    gen_rtvec_v (ncases, labelvec)));
  2657. #endif
  2658.       /* If the case insn drops through the table,
  2659.          after the table we must jump to the default-label.
  2660.          Otherwise record no drop-through after the table.  */
  2661. #ifdef CASE_DROPS_THROUGH
  2662.       emit_jump (default_label);
  2663. #else
  2664.       emit_barrier ();
  2665. #endif
  2666.     }
  2667.  
  2668.       reorder_insns (NEXT_INSN (before_case), get_last_insn (),
  2669.              thiscase->data.case_stmt.start);
  2670.     }
  2671.   if (thiscase->exit_label)
  2672.     emit_label (thiscase->exit_label);
  2673.  
  2674.   POPSTACK (case_stack);
  2675. }
  2676.  
  2677. /* Generate code to jump to LABEL if OP1 and OP2 are equal.  */
  2678.  
  2679. static void
  2680. do_jump_if_equal (op1, op2, label, unsignedp)
  2681.      rtx op1, op2, label;
  2682.      int unsignedp;
  2683. {
  2684.   if (GET_CODE (op1) == CONST_INT
  2685.       && GET_CODE (op2) == CONST_INT)
  2686.     {
  2687.       if (INTVAL (op1) == INTVAL (op2))
  2688.     emit_jump (label);
  2689.     }
  2690.   else
  2691.     {
  2692.       emit_cmp_insn (op1, op2, 0, unsignedp, 0);
  2693.       emit_jump_insn (gen_beq (label));
  2694.     }
  2695. }
  2696.  
  2697. /* Scan an ordered list of case nodes
  2698.    combining those with consecutive values or ranges.
  2699.  
  2700.    Eg. three separate entries 1: 2: 3: become one entry 1..3:  */
  2701.  
  2702. static void
  2703. group_case_nodes (head)
  2704.      case_node_ptr head;
  2705. {
  2706.   case_node_ptr node = head;
  2707.  
  2708.   while (node)
  2709.     {
  2710.       rtx lb = next_real_insn (label_rtx (node->code_label));
  2711.       case_node_ptr np = node;
  2712.  
  2713.       /* Try to group the successors of NODE with NODE.  */
  2714.       while (((np = np->right) != 0)
  2715.          /* Do they jump to the same place?  */
  2716.          && next_real_insn (label_rtx (np->code_label)) == lb
  2717.          /* Are their ranges consecutive?  */
  2718.          && tree_int_cst_equal (np->low,
  2719.                     combine (PLUS_EXPR, node->high,
  2720.                          build_int_2 (1, 0))))
  2721.     {
  2722.       node->high = np->high;
  2723.     }
  2724.       /* NP is the first node after NODE which can't be grouped with it.
  2725.      Delete the nodes in between, and move on to that node.  */
  2726.       node->right = np;
  2727.       node = np;
  2728.     }
  2729. }
  2730.  
  2731. /* Take an ordered list of case nodes
  2732.    and transform them into a near optimal binary tree,
  2733.    on the assumtion that any target code selection value is as
  2734.    likely as any other.
  2735.  
  2736.    The transformation is performed by splitting the ordered
  2737.    list into two equal sections plus a pivot.  The parts are
  2738.    then attached to the pivot as left and right branches.  Each
  2739.    branch is is then transformed recursively.  */
  2740.  
  2741. static void
  2742. balance_case_nodes (head, parent)
  2743.      case_node_ptr *head;
  2744.      case_node_ptr parent;
  2745. {
  2746.   register case_node_ptr np;
  2747.  
  2748.   np = *head;
  2749.   if (np)
  2750.     {
  2751.       int i = 0;
  2752.       int ranges = 0;
  2753.       register case_node_ptr *npp;
  2754.       case_node_ptr left;
  2755.  
  2756.       /* Count the number of entries on branch.
  2757.      Also count the ranges.  */
  2758.       while (np)
  2759.     {
  2760.       if (!tree_int_cst_equal (np->low, np->high))
  2761.         ranges++;
  2762.       i++;
  2763.       np = np->right;
  2764.     }
  2765.       if (i > 2)
  2766.     {
  2767.       /* Split this list if it is long enough for that to help.  */
  2768.       npp = head;
  2769.       left = *npp;
  2770.       /* If there are just three nodes, split at the middle one.  */
  2771.       if (i == 3)
  2772.         npp = &(*npp)->right;
  2773.       else
  2774.         {
  2775.           /* Find the place in the list that bisects the list's total cost,
  2776.          where ranges count as 2.
  2777.          Here I gets half the total cost.  */
  2778.           i = (i + ranges + 1) / 2;
  2779.           while (1)
  2780.         {
  2781.           /* Skip nodes while their cost does not reach that amount.  */
  2782.           if (!tree_int_cst_equal ((*npp)->low, (*npp)->high))
  2783.             i--;
  2784.           i--;
  2785.           if (i <= 0)
  2786.             break;
  2787.           npp = &(*npp)->right;
  2788.         }
  2789.         }
  2790.       *head = np = *npp;
  2791.       *npp = 0;
  2792.       np->parent = parent;
  2793.       np->left = left;
  2794.  
  2795.       /* Optimize each of the two split parts.  */
  2796.       balance_case_nodes (&np->left, np);
  2797.       balance_case_nodes (&np->right, np);
  2798.     }
  2799.       else
  2800.     {
  2801.       /* Else leave this branch as one level,
  2802.          but fill in `parent' fields.  */
  2803.       np = *head;
  2804.       np->parent = parent;
  2805.       for (; np->right; np = np->right)
  2806.         np->right->parent = np;
  2807.     }
  2808.     }
  2809. }
  2810.  
  2811. /* Search the parent sections of the case node tree
  2812.    to see if a test for the lower bound of NODE would be redundant.
  2813.  
  2814.    The instructions to synthesis the case decision tree are
  2815.    output in the same order as nodes are processed so it is
  2816.    known that if a parent node checks the range of the current
  2817.    node minus one that the current node is bounded at its lower
  2818.    span.  Thus the test would be redundant.  */
  2819.  
  2820. static int
  2821. node_has_low_bound (node)
  2822.      case_node_ptr node;
  2823. {
  2824.   tree low_minus_one;
  2825.   case_node_ptr pnode;
  2826.  
  2827.   if (node->left)
  2828.     {
  2829.       low_minus_one = combine (MINUS_EXPR, node->low, build_int_2 (1, 0));
  2830.       /* Avoid the screw case of overflow where low_minus_one is > low.  */
  2831.       if (tree_int_cst_lt (low_minus_one, node->low))
  2832.     for (pnode = node->parent; pnode; pnode = pnode->parent)
  2833.       {
  2834.         if (tree_int_cst_equal (low_minus_one, pnode->high))
  2835.           return 1;
  2836.         /* If a parent node has a left branch we know that none
  2837.            of its parents can have a high bound of our target
  2838.            minus one so we abort the search.  */
  2839.         if (node->left)
  2840.           break;
  2841.       }
  2842.     }
  2843.   return 0;
  2844. }
  2845.  
  2846. /* Search the parent sections of the case node tree
  2847.    to see if a test for the upper bound of NODE would be redundant.
  2848.  
  2849.    The instructions to synthesis the case decision tree are
  2850.    output in the same order as nodes are processed so it is
  2851.    known that if a parent node checks the range of the current
  2852.    node plus one that the current node is bounded at its upper
  2853.    span.  Thus the test would be redundant.  */
  2854.  
  2855. static int
  2856. node_has_high_bound (node)
  2857.      case_node_ptr node;
  2858. {
  2859.   tree high_plus_one;
  2860.   case_node_ptr pnode;
  2861.  
  2862.   if (node->right == 0)
  2863.     {
  2864.       high_plus_one = combine (PLUS_EXPR, node->high, build_int_2 (1, 0));
  2865.       /* Avoid the screw case of overflow where high_plus_one is > high.  */
  2866.       if (tree_int_cst_lt (node->high, high_plus_one))
  2867.     for (pnode = node->parent; pnode; pnode = pnode->parent)
  2868.       {
  2869.         if (tree_int_cst_equal (high_plus_one, pnode->low))
  2870.           return 1;
  2871.         /* If a parent node has a right branch we know that none
  2872.            of its parents can have a low bound of our target
  2873.            plus one so we abort the search.  */
  2874.         if (node->right)
  2875.           break;
  2876.       }
  2877.     }
  2878.   return 0;
  2879. }
  2880.  
  2881. /* Search the parent sections of the
  2882.    case node tree to see if both tests for the upper and lower
  2883.    bounds of NODE would be redundant.  */
  2884.  
  2885. static int
  2886. node_is_bounded (node)
  2887.      case_node_ptr node;
  2888. {
  2889.   if (node->left || node->right)
  2890.     return 0;
  2891.   return node_has_low_bound (node) && node_has_high_bound (node);
  2892. }
  2893.  
  2894. /*  Emit an unconditional jump to LABEL unless it would be dead code.  */
  2895.  
  2896. static void
  2897. emit_jump_if_reachable (label)
  2898.      rtx label;
  2899. {
  2900.   rtx last_insn;
  2901.  
  2902.   if (GET_CODE (get_last_insn ()) != BARRIER)
  2903.     emit_jump (label);
  2904. }
  2905.  
  2906. /* Emit step-by-step code to select a case for the value of INDEX.
  2907.    The thus generated decision tree follows the form of the
  2908.    case-node binary tree NODE, whose nodes represent test conditions.
  2909.    UNSIGNEDP is nonzero if we should do unsigned comparisons.
  2910.  
  2911.    Care is taken to prune redundant tests from the decision tree
  2912.    by detecting any boundary conditions already checked by
  2913.    emitted rtx.  (See node_has_high_bound, node_has_low_bound
  2914.    and node_is_bounded, above.)
  2915.  
  2916.    Where the test conditions can be shown to be redundant we emit
  2917.    an unconditional jump to the target code.  As a further
  2918.    optimization, the subordinates of a tree node are examined to
  2919.    check for bounded nodes.  In this case conditional and/or
  2920.    unconditional jumps as a result of the boundary check for the
  2921.    current node are arranged to target the subordinates associated
  2922.    code for out of bound conditions on the current node node.  */
  2923.  
  2924. static void
  2925. emit_case_nodes (index, node, default_label, unsignedp)
  2926.      rtx index;
  2927.      case_node_ptr node;
  2928.      rtx default_label;
  2929.      int unsignedp;
  2930. {
  2931.   /* If INDEX has an unsigned type, we must make unsigned branches.  */
  2932.   typedef rtx rtx_function ();
  2933.   rtx_function *gen_bgt_pat = unsignedp ? gen_bgtu : gen_bgt;
  2934.   rtx_function *gen_bge_pat = unsignedp ? gen_bgeu : gen_bge;
  2935.   rtx_function *gen_blt_pat = unsignedp ? gen_bltu : gen_blt;
  2936.   rtx_function *gen_ble_pat = unsignedp ? gen_bleu : gen_ble;
  2937.  
  2938.   if (node->test_label)
  2939.     {
  2940.       /* If this test node requires a label it follows that
  2941.      it must be preceeded by an unconditional branch.
  2942.      If control can pass to this point we can assume that
  2943.      a "br default" is in order.  */
  2944.       emit_jump_if_reachable (default_label);
  2945.       expand_label (node->test_label);
  2946.     }
  2947.   if (tree_int_cst_equal (node->low, node->high))
  2948.     {
  2949.       /* Node is single valued.  */
  2950.       do_jump_if_equal (index, expand_expr (node->low, 0, VOIDmode, 0),
  2951.             label_rtx (node->code_label), unsignedp);
  2952.       if (node->right)
  2953.     {
  2954.       if (node->left)
  2955.         {
  2956.           /* This node has children on either side.  */
  2957.           emit_cmp_insn (index, expand_expr (node->high, 0, VOIDmode, 0), 0, 0, 0);
  2958.  
  2959.           if (node_is_bounded (node->right))
  2960.         {
  2961.           emit_jump_insn ((*gen_bgt_pat) (label_rtx (node->right->code_label)));
  2962.           if (node_is_bounded (node->left))
  2963.             emit_jump (label_rtx (node->left->code_label));
  2964.           else
  2965.             emit_case_nodes (index, node->left,
  2966.                      default_label, unsignedp);
  2967.         }
  2968.           else
  2969.         {
  2970.           if (node_is_bounded (node->left))
  2971.             emit_jump_insn ((*gen_blt_pat) (label_rtx (node->left->code_label)));
  2972.           else
  2973.             {
  2974.               node->right->test_label =
  2975.             build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  2976.               emit_jump_insn ((*gen_bgt_pat) (label_rtx (node->right->test_label)));
  2977.               emit_case_nodes (index, node->left,
  2978.                        default_label, unsignedp);
  2979.             }
  2980.           emit_case_nodes (index, node->right,
  2981.                    default_label, unsignedp);
  2982.         }
  2983.         }
  2984.       else
  2985.         {
  2986.           /* Here we have a right child but no left
  2987.          so we issue conditional branch to default
  2988.          and process the right child.  */
  2989.  
  2990.           /* Omit the conditional branch to default
  2991.          if we it avoid only one right child;
  2992.          it costs too much space to save so little time.  */
  2993.           if (node->right->right && !node_has_low_bound (node))
  2994.         {
  2995.           emit_cmp_insn (index, expand_expr (node->high, 0, VOIDmode, 0), 0, 0, 0);
  2996.           emit_jump_insn ((*gen_blt_pat) (default_label));
  2997.         }
  2998.           if (node_is_bounded (node->right))
  2999.         emit_jump (label_rtx (node->right->code_label));
  3000.           else
  3001.         emit_case_nodes (index, node->right, default_label, unsignedp);
  3002.         }
  3003.     }
  3004.       else if (node->left)
  3005.     {
  3006.       if (node_is_bounded (node->left))
  3007.         emit_jump (label_rtx (node->left->code_label));
  3008.       else
  3009.         emit_case_nodes (index, node->left, default_label, unsignedp);
  3010.     }
  3011.     }
  3012.   else
  3013.     {
  3014.       /* Node is a range.  */
  3015.       if (node->right)
  3016.     {
  3017.       if (node->left)
  3018.         {
  3019.           emit_cmp_insn (index, expand_expr (node->high, 0, VOIDmode, 0), 0, 0, 0);
  3020.           if (node_is_bounded (node->right))
  3021.         {
  3022.           /* Right hand node is fully bounded so we can
  3023.              eliminate any testing and branch directly
  3024.              to the target code.  */
  3025.           emit_jump_insn ((*gen_bgt_pat) (label_rtx (node->right->code_label)));
  3026.         }
  3027.           else
  3028.         {
  3029.           /* Right hand node requires testing so create
  3030.              a label to put on the cmp code.  */
  3031.           node->right->test_label =
  3032.             build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  3033.           emit_jump_insn ((*gen_bgt_pat) (label_rtx (node->right->test_label)));
  3034.         }
  3035.           emit_cmp_insn (index, expand_expr (node->low, 0, VOIDmode, 0), 0, 0, 0);
  3036.           emit_jump_insn ((*gen_bge_pat) (label_rtx (node->code_label)));
  3037.           if (node_is_bounded (node->left))
  3038.         {
  3039.           /* Left hand node is fully bounded so we can
  3040.              eliminate any testing and branch directly
  3041.              to the target code.  */
  3042.           emit_jump (label_rtx (node->left->code_label));
  3043.         }
  3044.           else
  3045.         emit_case_nodes (index, node->left, default_label, unsignedp);
  3046.           /* If right node has been given a test label above
  3047.          we must process it now.  */
  3048.           if (node->right->test_label)
  3049.         emit_case_nodes (index, node->right, default_label, unsignedp);
  3050.         }
  3051.       else
  3052.         {
  3053.           if (!node_has_low_bound (node))
  3054.         {
  3055.           emit_cmp_insn (index, expand_expr (node->low, 0, VOIDmode, 0), 0, 0, 0);
  3056.           emit_jump_insn ((*gen_blt_pat) (default_label));
  3057.         }
  3058.           emit_cmp_insn (index, expand_expr (node->high, 0, VOIDmode, 0), 0, 0, 0);
  3059.           emit_jump_insn ((*gen_ble_pat) (label_rtx (node->code_label)));
  3060.           if (node_is_bounded (node->right))
  3061.         {
  3062.           /* Right hand node is fully bounded so we can
  3063.              eliminate any testing and branch directly
  3064.              to the target code.  */
  3065.           emit_jump (label_rtx (node->right->code_label));
  3066.         }
  3067.           else
  3068.         emit_case_nodes (index, node->right, default_label, unsignedp);
  3069.         }
  3070.     }
  3071.       else if (node->left)
  3072.     {
  3073.       if (!node_has_high_bound (node))
  3074.         {
  3075.           emit_cmp_insn (index, expand_expr (node->high, 0, VOIDmode, 0), 0, 0, 0);
  3076.           emit_jump_insn ((*gen_bgt_pat) (default_label));
  3077.         }
  3078.       emit_cmp_insn (index, expand_expr (node->low, 0, VOIDmode, 0), 0, 0, 0);
  3079.       emit_jump_insn ((*gen_bge_pat) (label_rtx (node->code_label)));
  3080.       if (node_is_bounded (node->left))
  3081.         {
  3082.           /* Left hand node is fully bounded so we can
  3083.          eliminate any testing and branch directly
  3084.          to the target code.  */
  3085.           emit_jump (label_rtx (node->left->code_label));
  3086.         }
  3087.       else
  3088.         emit_case_nodes (index, node->left, default_label, unsignedp);
  3089.     }
  3090.       else
  3091.     {
  3092.       /* Node has no children so we check low and
  3093.          high bounds to remove redundant tests. In practice
  3094.          only one of the limits may be bounded or the parent
  3095.          node will have emmited a jump to our target code.  */
  3096.       if (!node_has_high_bound (node))
  3097.         {
  3098.           emit_cmp_insn (index, expand_expr (node->high, 0, VOIDmode, 0), 0, 0, 0);
  3099.           emit_jump_insn ((*gen_bgt_pat) (default_label));
  3100.         }
  3101.       if (!node_has_low_bound (node))
  3102.         {
  3103.           emit_cmp_insn (index, expand_expr (node->low, 0, VOIDmode, 0), 0, 0, 0);
  3104.           emit_jump_insn ((*gen_bge_pat) (label_rtx (node->code_label)));
  3105.         }
  3106.       /* We allow the default case to drop through since
  3107.          it will picked up by calls to `jump_if_reachable'
  3108.          either on the next test label or at the end of
  3109.          the decision tree emission.  */
  3110.     }
  3111.     }
  3112. }
  3113.  
  3114. /* Allocate fixed slots in the stack frame of the current function.  */
  3115.  
  3116. /* Return size needed for stack frame based on slots so far allocated.  */
  3117.  
  3118. int
  3119. get_frame_size ()
  3120. {
  3121. #ifdef FRAME_GROWS_DOWNWARD
  3122.   return -frame_offset;
  3123. #else
  3124.   return frame_offset;
  3125. #endif
  3126. }
  3127.  
  3128. /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
  3129.    with machine mode MODE.  */
  3130.  
  3131. rtx
  3132. assign_stack_local (mode, size)
  3133.      enum machine_mode mode;
  3134.      int size;
  3135. {
  3136.   register rtx x, addr;
  3137.   int bigend_correction = 0;
  3138.  
  3139.   frame_pointer_needed = 1;
  3140.  
  3141.   /* Make each stack slot a multiple of the main allocation unit.  */
  3142.   size = (((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
  3143.        / (BIGGEST_ALIGNMENT / BITS_PER_UNIT))
  3144.       * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
  3145.  
  3146.   /* On a big-endian machine, if we are allocating more space than we will use,
  3147.      use the least significant bytes of those that are allocated.  */
  3148. #ifdef BYTES_BIG_ENDIAN
  3149.   if (mode != BLKmode)
  3150.     bigend_correction = size - GET_MODE_SIZE (mode);
  3151. #endif
  3152.  
  3153. #ifdef FRAME_GROWS_DOWNWARD
  3154.   frame_offset -= size;
  3155. #endif
  3156.   addr = gen_rtx (PLUS, Pmode, frame_pointer_rtx,
  3157.           gen_rtx (CONST_INT, VOIDmode,
  3158.                (frame_offset + bigend_correction)));
  3159. #ifndef FRAME_GROWS_DOWNWARD
  3160.   frame_offset += size;
  3161. #endif
  3162.  
  3163.   if (! memory_address_p (mode, addr))
  3164.     invalid_stack_slot = 1;
  3165.  
  3166.   x = gen_rtx (MEM, mode, addr);
  3167.  
  3168.   stack_slot_list = gen_rtx (EXPR_LIST, VOIDmode, x, stack_slot_list);
  3169.  
  3170.   return x;
  3171. }
  3172.  
  3173. /* Retroactively move an auto variable from a register to a stack slot.
  3174.    This is done when an address-reference to the variable is seen.  */
  3175.  
  3176. void
  3177. put_var_into_stack (decl)
  3178.      tree decl;
  3179. {
  3180.   register rtx reg = DECL_RTL (decl);
  3181.   register rtx new;
  3182.  
  3183.   /* No need to do anything if decl has no rtx yet
  3184.      since in that case caller is setting TREE_ADDRESSABLE
  3185.      and a stack slot will be assigned when the rtl is made.  */
  3186.   if (reg == 0)
  3187.     return;
  3188.   if (GET_CODE (reg) != REG)
  3189.     return;
  3190.  
  3191.   new = parm_stack_loc (reg);
  3192.   if (new == 0)
  3193.     new = assign_stack_local (GET_MODE (reg), GET_MODE_SIZE (GET_MODE (reg)));
  3194.  
  3195.   XEXP (reg, 0) = XEXP (new, 0);
  3196.   /* `volatil' bit means one thing for MEMs, another entirely for REGs.  */
  3197.   REG_USERVAR_P (reg) = 0;
  3198.   PUT_CODE (reg, MEM);
  3199.  
  3200.   /* If this is a memory ref that contains aggregate components,
  3201.      mark it as such for cse and loop optimize.  */
  3202.   MEM_IN_STRUCT_P (reg)
  3203.     = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
  3204.        || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
  3205.        || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE);
  3206.  
  3207.   fixup_var_refs (reg);
  3208. }
  3209.  
  3210. static void
  3211. fixup_var_refs (var)
  3212.      rtx var;
  3213. {
  3214.   extern rtx sequence_stack;
  3215.   rtx stack = sequence_stack;
  3216.   tree pending;
  3217.  
  3218.   stack = sequence_stack;
  3219.  
  3220.   /* Must scan all insns for stack-refs that exceed the limit.  */
  3221.   fixup_var_refs_insns (var, get_insns (), stack == 0);
  3222.  
  3223.   /* Scan all pending sequences too.  */
  3224.   for (; stack; stack = XEXP (XEXP (stack, 1), 1))
  3225.     {
  3226.       push_to_sequence (XEXP (stack, 0));
  3227.       fixup_var_refs_insns (var, XEXP (stack, 0),
  3228.                 XEXP (XEXP (stack, 1), 1) == 0);
  3229.       end_sequence ();
  3230.     }
  3231.  
  3232.   /* Scan all waiting RTL_EXPRs too.  */
  3233.   for (pending = rtl_expr_chain; pending; pending = TREE_CHAIN (pending))
  3234.     {
  3235.       rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending));
  3236.       if (seq != const0_rtx && seq != 0)
  3237.     {
  3238.       push_to_sequence (seq);
  3239.       fixup_var_refs_insns (var, seq, 0);
  3240.       end_sequence ();
  3241.     }
  3242.     }
  3243. }
  3244.  
  3245. /* Scan the insn-chain starting with INSN for refs to VAR
  3246.    and fix them up.  TOPLEVEL is nonzero if this chain is the
  3247.    main chain of insns for the current function.  */
  3248.  
  3249. static void
  3250. fixup_var_refs_insns (var, insn, toplevel)
  3251.      rtx var;
  3252.      rtx insn;
  3253.      int toplevel;
  3254. {
  3255.   while (insn)
  3256.     {
  3257.       rtx next = NEXT_INSN (insn);
  3258.       rtx note;
  3259.       if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
  3260.       || GET_CODE (insn) == JUMP_INSN)
  3261.     {
  3262.       /* The insn to load VAR from a home in the arglist
  3263.          is now a no-op.  When we see it, just delete it.  */
  3264.       if (toplevel
  3265.           && GET_CODE (PATTERN (insn)) == SET
  3266.           && SET_DEST (PATTERN (insn)) == var
  3267.           && rtx_equal_p (SET_SRC (PATTERN (insn)), var))
  3268.         {
  3269.           next = delete_insn (insn);
  3270.           if (insn == last_parm_insn)
  3271.         last_parm_insn = PREV_INSN (next);
  3272.         }
  3273.       else
  3274.         fixup_var_refs_1 (var, PATTERN (insn), insn);
  3275.       /* Also fix up any invalid exprs in the REG_NOTES of this insn.
  3276.          But don't touch other insns referred to by reg-notes;
  3277.          we will get them elsewhere.  */
  3278.       for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
  3279.         if (GET_CODE (note) != INSN_LIST)
  3280.           XEXP (note, 0) = walk_fixup_memory_subreg (XEXP (note, 0), insn);
  3281.     }
  3282.       insn = next;
  3283.     }
  3284. }
  3285.  
  3286. static rtx
  3287. fixup_var_refs_1 (var, x, insn)
  3288.      register rtx var;
  3289.      register rtx x;
  3290.      rtx insn;
  3291. {
  3292.   register int i;
  3293.   RTX_CODE code = GET_CODE (x);
  3294.   register char *fmt;
  3295.   register rtx tem;
  3296.  
  3297.   switch (code)
  3298.     {
  3299.     case MEM:
  3300.       if (var == x)
  3301.     {
  3302.       x = fixup_stack_1 (x, insn);
  3303.       tem = gen_reg_rtx (GET_MODE (x));
  3304.       emit_insn_before (gen_move_insn (tem, x), insn);
  3305.       return tem;
  3306.     }
  3307.       break;
  3308.  
  3309.     case REG:
  3310.     case CC0:
  3311.     case PC:
  3312.     case CONST_INT:
  3313.     case CONST:
  3314.     case SYMBOL_REF:
  3315.     case LABEL_REF:
  3316.     case CONST_DOUBLE:
  3317.       return x;
  3318.  
  3319.     case SIGN_EXTRACT:
  3320.     case ZERO_EXTRACT:
  3321.       /* Note that in some cases those types of expressions are altered
  3322.      by optimize_bit_field, and do not survive to get here.  */
  3323.     case SUBREG:
  3324.       tem = x;
  3325.       while (GET_CODE (tem) == SUBREG || GET_CODE (tem) == SIGN_EXTRACT
  3326.          || GET_CODE (tem) == ZERO_EXTRACT)
  3327.     tem = XEXP (tem, 0);
  3328.       if (tem == var)
  3329.     {
  3330.       x = fixup_stack_1 (x, insn);
  3331.       tem = gen_reg_rtx (GET_MODE (x));
  3332.       if (GET_CODE (x) == SUBREG)
  3333.         x = fixup_memory_subreg (x, insn);
  3334.       emit_insn_before (gen_move_insn (tem, x), insn);
  3335.       return tem;
  3336.     }
  3337.       break;
  3338.  
  3339.     case SET:
  3340.       /* First do special simplification of bit-field references.  */
  3341.       if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT
  3342.       || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
  3343.     optimize_bit_field (x, insn, 0);
  3344.       if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT
  3345.       || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT)
  3346.     optimize_bit_field (x, insn, 0);
  3347.  
  3348.       {
  3349.     rtx dest = SET_DEST (x);
  3350.     rtx src = SET_SRC (x);
  3351.     rtx outerdest = dest;
  3352.     rtx outersrc = src;
  3353.  
  3354.     while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
  3355.            || GET_CODE (dest) == SIGN_EXTRACT
  3356.            || GET_CODE (dest) == ZERO_EXTRACT)
  3357.       dest = XEXP (dest, 0);
  3358.     while (GET_CODE (src) == SUBREG
  3359.            || GET_CODE (src) == SIGN_EXTRACT
  3360.            || GET_CODE (src) == ZERO_EXTRACT)
  3361.       src = XEXP (src, 0);
  3362.  
  3363.     /* If VAR does not appear at the top level of the SET
  3364.        just scan the lower levels of the tree.  */
  3365.  
  3366.         if (src != var && dest != var)
  3367.       break;
  3368.  
  3369.     /* Clean up (SUBREG:SI (MEM:mode ...) 0)
  3370.        that may appear inside a SIGN_EXTRACT or ZERO_EXTRACT.
  3371.        This was legitimate when the MEM was a REG.  */
  3372.  
  3373.     if ((GET_CODE (outerdest) == SIGN_EXTRACT
  3374.          || GET_CODE (outerdest) == ZERO_EXTRACT)
  3375.         && GET_CODE (XEXP (outerdest, 0)) == SUBREG
  3376.         && SUBREG_REG (XEXP (outerdest, 0)) == var)
  3377.       XEXP (outerdest, 0) = fixup_memory_subreg (XEXP (outerdest, 0), insn);
  3378.  
  3379.     if ((GET_CODE (outersrc) == SIGN_EXTRACT
  3380.          || GET_CODE (outersrc) == ZERO_EXTRACT)
  3381.         && GET_CODE (XEXP (outersrc, 0)) == SUBREG
  3382.         && SUBREG_REG (XEXP (outersrc, 0)) == var)
  3383.       XEXP (outersrc, 0) = fixup_memory_subreg (XEXP (outersrc, 0), insn);
  3384.  
  3385.     /* Make sure a MEM inside a SIGN_EXTRACT has QImode
  3386.        since that's what bit-field insns want.  */
  3387.  
  3388.     if ((GET_CODE (outerdest) == SIGN_EXTRACT
  3389.          || GET_CODE (outerdest) == ZERO_EXTRACT)
  3390.         && GET_CODE (XEXP (outerdest, 0)) == MEM
  3391.         && GET_MODE (XEXP (outerdest, 0)) != QImode)
  3392.       {
  3393.         XEXP (outerdest, 0) = copy_rtx (XEXP (outerdest, 0));
  3394.         PUT_MODE (XEXP (outerdest, 0), QImode);
  3395.       }
  3396.  
  3397.     if ((GET_CODE (outersrc) == SIGN_EXTRACT
  3398.          || GET_CODE (outersrc) == ZERO_EXTRACT)
  3399.         && GET_CODE (XEXP (outersrc, 0)) == MEM
  3400.         && GET_MODE (XEXP (outersrc, 0)) != QImode)
  3401.       {
  3402.         XEXP (outersrc, 0) = copy_rtx (XEXP (outersrc, 0));
  3403.         PUT_MODE (XEXP (outersrc, 0), QImode);
  3404.       }
  3405.  
  3406.     /* STRICT_LOW_PART is a no-op on memory references
  3407.        and it can cause combinations to be unrecognizable,
  3408.        so eliminate it.  */
  3409.  
  3410.     if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
  3411.       SET_DEST (x) = XEXP (SET_DEST (x), 0);
  3412.  
  3413.     /* An insn to copy VAR into or out of a register
  3414.        must be left alone, to avoid an infinite loop here.
  3415.        But do fix up the address of VAR's stack slot if nec,
  3416.        and fix up SUBREGs containing VAR
  3417.        (since they are now memory subregs).  */
  3418.  
  3419.     if (GET_CODE (SET_SRC (x)) == REG || GET_CODE (SET_DEST (x)) == REG
  3420.         || (GET_CODE (SET_SRC (x)) == SUBREG
  3421.         && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG)
  3422.         || (GET_CODE (SET_DEST (x)) == SUBREG
  3423.         && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG))
  3424.       {
  3425.         if (src == var && GET_CODE (SET_SRC (x)) == SUBREG)
  3426.           SET_SRC (x) = fixup_memory_subreg (SET_SRC (x), insn);
  3427.         if (dest == var && GET_CODE (SET_DEST (x)) == SUBREG)
  3428.           SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn);
  3429.         return fixup_stack_1 (x, insn);
  3430.       }
  3431.  
  3432.     /* Otherwise, storing into VAR must be handled specially
  3433.        by storing into a temporary and copying that into VAR
  3434.        with a new insn after this one.  */
  3435.  
  3436.     if (dest == var)
  3437.       {
  3438.         rtx temp;
  3439.         rtx fixeddest;
  3440.         tem = SET_DEST (x);
  3441.         /* STRICT_LOW_PART can be discarded, around a MEM.  */
  3442.         if (GET_CODE (tem) == STRICT_LOW_PART)
  3443.           tem = XEXP (tem, 0);
  3444.         /* Convert (SUBREG (MEM)) to a MEM in a changed mode.  */
  3445.         if (GET_CODE (tem) == SUBREG)
  3446.           tem = fixup_memory_subreg (tem, insn);
  3447.         fixeddest = fixup_stack_1 (tem, insn);
  3448.         temp = gen_reg_rtx (GET_MODE (tem));
  3449.         emit_insn_after (gen_move_insn (fixeddest, temp), insn);
  3450.         SET_DEST (x) = temp;
  3451.       }
  3452.       }
  3453.     }
  3454.  
  3455.   /* Nothing special about this RTX; fix its operands.  */
  3456.  
  3457.   fmt = GET_RTX_FORMAT (code);
  3458.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  3459.     {
  3460.       if (fmt[i] == 'e')
  3461.     XEXP (x, i) = fixup_var_refs_1 (var, XEXP (x, i), insn);
  3462.       if (fmt[i] == 'E')
  3463.     {
  3464.       register int j;
  3465.       for (j = 0; j < XVECLEN (x, i); j++)
  3466.         XVECEXP (x, i, j)
  3467.           = fixup_var_refs_1 (var, XVECEXP (x, i, j), insn);
  3468.     }
  3469.     }
  3470.   return x;
  3471. }
  3472.  
  3473. /* Given X, an rtx of the form (SUBREG:m1 (MEM:m2 addr)),
  3474.    return an rtx (MEM:m1 newaddr) which is equivalent.
  3475.    If any insns must be emitted to compute NEWADDR, put them before INSN.  */
  3476.  
  3477. static rtx
  3478. fixup_memory_subreg (x, insn)
  3479.      rtx x;
  3480.      rtx insn;
  3481. {
  3482.   int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
  3483.   rtx addr = XEXP (SUBREG_REG (x), 0);
  3484.   enum machine_mode mode = GET_MODE (x);
  3485.   rtx saved, result;
  3486.  
  3487. #ifdef BYTES_BIG_ENDIAN
  3488.   offset += (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
  3489.          - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)));
  3490. #endif
  3491.   addr = plus_constant (addr, offset);
  3492.   if (memory_address_p (mode, addr))
  3493.     return change_address (SUBREG_REG (x), mode, addr);
  3494.   saved = start_sequence ();
  3495.   result = change_address (SUBREG_REG (x), mode, addr);
  3496.   emit_insn_before (gen_sequence (), insn);
  3497.   end_sequence (saved);
  3498.   return result;
  3499. }
  3500.  
  3501. /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
  3502.    Replace subexpressions of X in place.
  3503.    If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
  3504.    Otherwise return X, with its contents possibly altered.
  3505.  
  3506.    If any insns must be emitted to compute NEWADDR, put them before INSN.  */
  3507.  
  3508. static rtx
  3509. walk_fixup_memory_subreg (x, insn)
  3510.      register rtx x;
  3511.      rtx insn;
  3512. {
  3513.   register enum rtx_code code;
  3514.   register char *fmt;
  3515.   register int i;
  3516.  
  3517.   if (x == 0)
  3518.     return 0;
  3519.  
  3520.   code = GET_CODE (x);
  3521.  
  3522.   if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
  3523.     return fixup_memory_subreg (x, insn);
  3524.  
  3525.   /* Nothing special about this RTX; fix its operands.  */
  3526.  
  3527.   fmt = GET_RTX_FORMAT (code);
  3528.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  3529.     {
  3530.       if (fmt[i] == 'e')
  3531.     XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn);
  3532.       if (fmt[i] == 'E')
  3533.     {
  3534.       register int j;
  3535.       for (j = 0; j < XVECLEN (x, i); j++)
  3536.         XVECEXP (x, i, j)
  3537.           = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn);
  3538.     }
  3539.     }
  3540.   return x;
  3541. }
  3542.  
  3543. #if 0
  3544. /* Fix up any references to stack slots that are invalid memory addresses
  3545.    because they exceed the maximum range of a displacement.  */
  3546.  
  3547. void
  3548. fixup_stack_slots ()
  3549. {
  3550.   register rtx insn;
  3551.  
  3552.   /* Did we generate a stack slot that is out of range
  3553.      or otherwise has an invalid address?  */
  3554.   if (invalid_stack_slot)
  3555.     {
  3556.       /* Yes.  Must scan all insns for stack-refs that exceed the limit.  */
  3557.       for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  3558.     if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
  3559.         || GET_CODE (insn) == JUMP_INSN)
  3560.       fixup_stack_1 (PATTERN (insn), insn);
  3561.     }
  3562. }
  3563. #endif
  3564.  
  3565. /* For each memory ref within X, if it refers to a stack slot
  3566.    with an out of range displacement, put the address in a temp register
  3567.    (emitting new insns before INSN to load these registers)
  3568.    and alter the memory ref to use that register.
  3569.    Replace each such MEM rtx with a copy, to avoid clobberage.  */
  3570.  
  3571. static rtx
  3572. fixup_stack_1 (x, insn)
  3573.      rtx x;
  3574.      rtx insn;
  3575. {
  3576.   register int i;
  3577.   register RTX_CODE code = GET_CODE (x);
  3578.   register char *fmt;
  3579.  
  3580.   if (code == MEM)
  3581.     {
  3582.       register rtx ad = XEXP (x, 0);
  3583.       /* If we have address of a stack slot but it's not valid
  3584.      (displacement is too large), compute the sum in a register.  */
  3585.       if (GET_CODE (ad) == PLUS
  3586.       && XEXP (ad, 0) == frame_pointer_rtx
  3587.       && GET_CODE (XEXP (ad, 1)) == CONST_INT)
  3588.     {
  3589.       rtx temp;
  3590.       if (memory_address_p (GET_MODE (x), ad))
  3591.         return x;
  3592.       temp = gen_reg_rtx (GET_MODE (ad));
  3593.       emit_insn_before (gen_move_insn (temp, ad), insn);
  3594.       return change_address (x, VOIDmode, temp);
  3595.     }
  3596.       return x;
  3597.     }
  3598.  
  3599.   fmt = GET_RTX_FORMAT (code);
  3600.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  3601.     {
  3602.       if (fmt[i] == 'e')
  3603.     XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn);
  3604.       if (fmt[i] == 'E')
  3605.     {
  3606.       register int j;
  3607.       for (j = 0; j < XVECLEN (x, i); j++)
  3608.         XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn);
  3609.     }
  3610.     }
  3611.   return x;
  3612. }
  3613.  
  3614. /* Optimization: a bit-field instruction whose field
  3615.    happens to be a byte or halfword in memory
  3616.    can be changed to a move instruction.
  3617.  
  3618.    We call here when INSN is an insn to examine or store into a bit-field.
  3619.    BODY is the SET-rtx to be altered.
  3620.  
  3621.    EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
  3622.    (Currently this is called only from stmt.c, and EQUIV_MEM is always 0.)  */
  3623.  
  3624. static void
  3625. optimize_bit_field (body, insn, equiv_mem)
  3626.      rtx body;
  3627.      rtx insn;
  3628.      rtx *equiv_mem;
  3629. {
  3630.   register rtx bitfield;
  3631.   int destflag;
  3632.  
  3633.   if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT
  3634.       || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT)
  3635.     bitfield = SET_DEST (body), destflag = 1;
  3636.   else
  3637.     bitfield = SET_SRC (body), destflag = 0;
  3638.  
  3639.   /* First check that the field being stored has constant size and position
  3640.      and is in fact a byte or halfword suitably aligned.  */
  3641.  
  3642.   if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT
  3643.       && GET_CODE (XEXP (bitfield, 2)) == CONST_INT
  3644.       && (INTVAL (XEXP (bitfield, 1)) == GET_MODE_BITSIZE (QImode)
  3645.       || INTVAL (XEXP (bitfield, 1)) == GET_MODE_BITSIZE (HImode))
  3646.       && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0)
  3647.     {
  3648.       register rtx memref = 0;
  3649.  
  3650.       /* Now check that the containing word is memory, not a register,
  3651.      and that it is safe to change the machine mode and to
  3652.      add something to the address.  */
  3653.  
  3654.       if (GET_CODE (XEXP (bitfield, 0)) == MEM)
  3655.     memref = XEXP (bitfield, 0);
  3656.       else if (GET_CODE (XEXP (bitfield, 0)) == REG
  3657.            && equiv_mem != 0)
  3658.     memref = equiv_mem[REGNO (XEXP (bitfield, 0))];
  3659.       else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
  3660.            && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM)
  3661.     memref = SUBREG_REG (XEXP (bitfield, 0));
  3662.       else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
  3663.            && equiv_mem != 0
  3664.            && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG)
  3665.     memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))];
  3666.  
  3667.       if (memref
  3668.       && ! mode_dependent_address_p (XEXP (memref, 0))
  3669.       && offsetable_address_p (0, GET_MODE (bitfield), XEXP (memref, 0)))
  3670.     {
  3671.       /* Now adjust the address, first for any subreg'ing
  3672.          that we are now getting rid of,
  3673.          and then for which byte of the word is wanted.  */
  3674.  
  3675.       register int offset
  3676.         = INTVAL (XEXP (bitfield, 2)) / GET_MODE_BITSIZE (QImode);
  3677.       if (GET_CODE (XEXP (bitfield, 0)) == SUBREG)
  3678.         {
  3679.           offset += SUBREG_WORD (XEXP (bitfield, 0)) * UNITS_PER_WORD;
  3680. #ifdef BYTES_BIG_ENDIAN
  3681.           offset -= (MIN (UNITS_PER_WORD,
  3682.                   GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0))))
  3683.              - MIN (UNITS_PER_WORD,
  3684.                 GET_MODE_SIZE (GET_MODE (memref))));
  3685. #endif
  3686.         }
  3687.  
  3688.       memref = gen_rtx (MEM,
  3689.                 (INTVAL (XEXP (bitfield, 1)) == GET_MODE_BITSIZE (QImode)
  3690.                  ? QImode : HImode),
  3691.                 XEXP (memref, 0));
  3692.  
  3693.       /* Store this memory reference where
  3694.          we found the bit field reference.  */
  3695.  
  3696.       if (destflag)
  3697.         {
  3698.           SET_DEST (body)
  3699.         = adj_offsetable_operand (memref, offset);
  3700.           if (! CONSTANT_ADDRESS_P (SET_SRC (body)))
  3701.         {
  3702.           rtx src = SET_SRC (body);
  3703.           while (GET_CODE (src) == SUBREG
  3704.              && SUBREG_WORD (src) == 0)
  3705.             src = SUBREG_REG (src);
  3706.           if (GET_MODE (src) != GET_MODE (memref))
  3707.             src = gen_lowpart (GET_MODE (memref), SET_SRC (body));
  3708.           SET_SRC (body) = src;
  3709.         }
  3710.           else if (GET_MODE (SET_SRC (body)) != VOIDmode
  3711.                && GET_MODE (SET_SRC (body)) != GET_MODE (memref))
  3712.         /* This shouldn't happen because anything that didn't have
  3713.            one of these modes should have got converted explicitly
  3714.            and then referenced through a subreg.
  3715.            This is so because the original bit-field was
  3716.            handled by agg_mode and so its tree structure had
  3717.            the same mode that memref now has.  */
  3718.         abort ();
  3719.         }
  3720.       else
  3721.         {
  3722.           rtx dest = SET_DEST (body);
  3723.  
  3724.           while (GET_CODE (dest) == SUBREG
  3725.              && SUBREG_WORD (dest) == 0)
  3726.         dest = SUBREG_REG (dest);
  3727.           SET_DEST (body) = dest;
  3728.  
  3729.           memref = adj_offsetable_operand (memref, offset);
  3730.           if (GET_MODE (dest) == GET_MODE (memref))
  3731.         SET_SRC (body) = memref;
  3732.           else
  3733.         {
  3734.           /* Convert the mem ref to the destination mode.  */
  3735.           rtx last = get_last_insn ();
  3736.           rtx newreg = gen_reg_rtx (GET_MODE (dest));
  3737.           convert_move (newreg, memref,
  3738.                 GET_CODE (SET_SRC (body)) == ZERO_EXTRACT);
  3739.           /* Put the conversion before the insn being fixed.  */
  3740.           reorder_insns (NEXT_INSN (last), get_last_insn (),
  3741.                  PREV_INSN (insn));
  3742.           SET_SRC (body) = newreg;
  3743.         }
  3744.         }
  3745.  
  3746.       /* Cause the insn to be re-recognized.  */
  3747.  
  3748.       INSN_CODE (insn) = -1;
  3749.     }
  3750.     }
  3751. }
  3752.  
  3753. /* 1 + last pseudo register number used for loading a copy
  3754.    of a parameter of this function.  */
  3755.  
  3756. static int max_parm_reg;
  3757.  
  3758. /* Vector indexed by REGNO, containing location on stack in which
  3759.    to put the parm which is nominally in pseudo register REGNO,
  3760.    if we discover that that parm must go in the stack.  */
  3761. static rtx *parm_reg_stack_loc;
  3762.  
  3763. int
  3764. max_parm_reg_num ()
  3765. {
  3766.   return max_parm_reg;
  3767. }
  3768.  
  3769. /* Return the first insn following those generated by `assign_parms'.  */
  3770.  
  3771. rtx
  3772. get_first_nonparm_insn ()
  3773. {
  3774.   if (last_parm_insn)
  3775.     return NEXT_INSN (last_parm_insn);
  3776.   return get_insns ();
  3777. }
  3778.  
  3779. /* Get the stack home of a REG rtx that is one of this function's parameters.
  3780.    This is called rather than assign a new stack slot as a local.
  3781.    Return 0 if there is no existing stack home suitable for such use.  */
  3782.  
  3783. static rtx
  3784. parm_stack_loc (reg)
  3785.      rtx reg;
  3786. {
  3787.   if (REGNO (reg) < max_parm_reg)
  3788.     return parm_reg_stack_loc[REGNO (reg)];
  3789.   return 0;
  3790. }
  3791.  
  3792. /* Assign RTL expressions to the function's parameters.
  3793.    This may involve copying them into registers and using
  3794.    those registers as the RTL for them.  */
  3795.  
  3796. static void
  3797. assign_parms (fndecl)
  3798.      tree fndecl;
  3799. {
  3800.   register tree parm;
  3801.   register rtx entry_parm;
  3802.   register rtx stack_parm;
  3803.   register CUMULATIVE_ARGS args_so_far;
  3804.   enum machine_mode passed_mode, nominal_mode;
  3805.   /* Total space needed so far for args on the stack,
  3806.      given as a constant and a tree-expression.  */
  3807.   struct args_size stack_args_size;
  3808.   int first_parm_offset = FIRST_PARM_OFFSET (fndecl);
  3809.   tree fntype = TREE_TYPE (fndecl);
  3810.  
  3811.   int nparmregs
  3812.     = list_length (DECL_ARGUMENTS (fndecl)) + FIRST_PSEUDO_REGISTER;
  3813.  
  3814.   /* Nonzero if function takes extra anonymous args.
  3815.      This means the last named arg must be on the stack
  3816.      right before the anonymous ones.
  3817.      Also nonzero if the first arg is named `__builtin_va_alist',
  3818.      which is used on some machines for old-fashioned non-ANSI varargs.h;
  3819.      this too should be stuck onto the stack as if it had arrived there.  */
  3820.   int vararg
  3821.     = ((DECL_ARGUMENTS (fndecl) != 0
  3822.     && DECL_NAME (DECL_ARGUMENTS (fndecl))
  3823.     && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (DECL_ARGUMENTS (fndecl))),
  3824.               "__builtin_va_alist")))
  3825.        ||
  3826.        (TYPE_ARG_TYPES (fntype) != 0
  3827.     && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
  3828.         != void_type_node)));
  3829.  
  3830.   stack_args_size.constant = 0;
  3831.   stack_args_size.var = 0;
  3832.  
  3833.   /* If struct value address comes on the stack, count it in size of args.  */
  3834.   if ((DECL_MODE (DECL_RESULT (fndecl)) == BLKmode
  3835.        || RETURN_IN_MEMORY (TREE_TYPE (DECL_RESULT (fndecl))))
  3836.       && GET_CODE (struct_value_incoming_rtx) == MEM)
  3837.     stack_args_size.constant += GET_MODE_SIZE (Pmode);
  3838.  
  3839.   parm_reg_stack_loc = (rtx *) oballoc (nparmregs * sizeof (rtx));
  3840.   bzero (parm_reg_stack_loc, nparmregs * sizeof (rtx));
  3841.  
  3842.   INIT_CUMULATIVE_ARGS (args_so_far, fntype);
  3843.  
  3844.   for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm))
  3845.     {
  3846.       int aggregate
  3847.     = (TREE_CODE (TREE_TYPE (parm)) == ARRAY_TYPE
  3848.        || TREE_CODE (TREE_TYPE (parm)) == RECORD_TYPE
  3849.        || TREE_CODE (TREE_TYPE (parm)) == UNION_TYPE);
  3850.       struct args_size stack_offset;
  3851.       rtx stack_offset_rtx;
  3852.       enum direction where_pad;
  3853.  
  3854.       DECL_OFFSET (parm) = -1;
  3855.  
  3856.       if (TREE_TYPE (parm) == error_mark_node
  3857.       /* This can happen after weird syntax errors
  3858.          or if an enum type is defined among the parms.  */
  3859.       || TREE_CODE (parm) != PARM_DECL
  3860.       || DECL_ARG_TYPE (parm) == NULL)
  3861.     {
  3862.       DECL_RTL (parm) = gen_rtx (MEM, BLKmode, const0_rtx);
  3863.       TREE_USED (parm) = 1;
  3864.       continue;
  3865.     }
  3866.  
  3867.       /* Find mode of arg as it is passed, and mode of arg
  3868.      as it should be during execution of this function.  */
  3869.       passed_mode = TYPE_MODE (DECL_ARG_TYPE (parm));
  3870.       nominal_mode = TYPE_MODE (TREE_TYPE (parm));
  3871.  
  3872.       /* Get this parm's offset as an rtx.  */
  3873.       stack_offset = stack_args_size;
  3874.       stack_offset.constant += first_parm_offset;
  3875.  
  3876.       /* If this argument needs more than the usual parm alignment, do
  3877.      extrinsic padding to reach that alignment.  */
  3878.  
  3879. #ifdef MAX_PARM_BOUNDARY
  3880.       /* If MAX_PARM_BOUNDARY is not defined, it means that the usual
  3881.      alignment requirements are relaxed for parms, and that no parm
  3882.      needs more alignment than PARM_BOUNDARY, regardless of data type.  */
  3883.  
  3884.       if (PARM_BOUNDARY < TYPE_ALIGN (TREE_TYPE (parm)))
  3885.     {
  3886.       int boundary = PARM_BOUNDARY;
  3887.  
  3888.       /* Determine the boundary to pad up to.  */
  3889.       if (TYPE_ALIGN (TREE_TYPE (parm)) > boundary)
  3890.         boundary = TYPE_ALIGN (TREE_TYPE (parm));
  3891.       if (boundary > MAX_PARM_BOUNDARY)
  3892.         boundary = MAX_PARM_BOUNDARY;
  3893.  
  3894.       /* If the previous args don't reach such a boundary,
  3895.          advance to the next one.  */
  3896.       stack_offset.constant += boundary - 1;
  3897.       stack_offset.constant &= boundary - 1;
  3898.  
  3899.       if (stack_offset.var != 0)
  3900.         abort ();        /* This case not implemented yet */
  3901.     }
  3902. #endif /* MAX_PARM_BOUNDARY */
  3903.  
  3904.       /* Find out if the parm needs intrinsic padding (up to PARM_BOUNDARY),
  3905.      and whether above or below.  */
  3906.  
  3907.       where_pad
  3908.     = FUNCTION_ARG_PADDING (passed_mode,
  3909.                 expand_expr (size_in_bytes (DECL_ARG_TYPE (parm)),
  3910.                          0, VOIDmode, 0));
  3911.  
  3912.       /* If arg should be padded below, adjust the stack address upward.
  3913.      This padding is considered part of the space occupied by the
  3914.      argument.  It pads only up to PARM_BOUNDARY, and it does not
  3915.      depend on the previous arguments, since they are assumed to
  3916.      occupy a multiple of PARM_BOUNDARY.  */
  3917.  
  3918.       if (where_pad == downward)
  3919.     {
  3920.       if (passed_mode != BLKmode)
  3921.         {
  3922.           if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
  3923.         stack_offset.constant
  3924.           += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
  3925.                / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
  3926.               - GET_MODE_SIZE (passed_mode));
  3927.         }
  3928.       else
  3929.         {
  3930.           tree sizetree = size_in_bytes (DECL_ARG_TYPE (parm));
  3931.           /* Round the size up to multiple of PARM_BOUNDARY bits.  */
  3932.           tree s1 = convert_units (sizetree, BITS_PER_UNIT, PARM_BOUNDARY);
  3933.           tree s2 = convert_units (s1, PARM_BOUNDARY, BITS_PER_UNIT);
  3934.           /* Add it in.  */
  3935.           ADD_PARM_SIZE (stack_offset, s2);
  3936.           SUB_PARM_SIZE (stack_offset, sizetree);
  3937.         }
  3938.     }
  3939.  
  3940.       stack_offset_rtx = ARGS_SIZE_RTX (stack_offset);
  3941.  
  3942.       /* Determine parm's home in the stack,
  3943.      in case it arrives in the stack or we should pretend it did.  */
  3944.       stack_parm
  3945.     = gen_rtx (MEM, passed_mode,
  3946.            memory_address (passed_mode,
  3947.                    gen_rtx (PLUS, Pmode,
  3948.                         arg_pointer_rtx, stack_offset_rtx)));
  3949.  
  3950.       /* If this is a memory ref that contains aggregate components,
  3951.      mark it as such for cse and loop optimize.  */
  3952.       MEM_IN_STRUCT_P (stack_parm) = aggregate;
  3953.  
  3954.       /* Let machine desc say which reg (if any) the parm arrives in.
  3955.      0 means it arrives on the stack.  */
  3956.       entry_parm = 0;
  3957.       /* Variable-size args, and args following such, are never in regs.  */
  3958.       if (TREE_CODE (TYPE_SIZE (TREE_TYPE (parm))) == INTEGER_CST
  3959.       || stack_offset.var != 0)
  3960.     {
  3961. #ifdef FUNCTION_INCOMING_ARG
  3962.       entry_parm
  3963.         = FUNCTION_INCOMING_ARG (args_so_far, passed_mode,
  3964.                      DECL_ARG_TYPE (parm), 1);
  3965. #else
  3966.       entry_parm
  3967.         = FUNCTION_ARG (args_so_far, passed_mode, DECL_ARG_TYPE (parm), 1);
  3968. #endif
  3969.     }
  3970.       /* If this parm was passed part in regs and part in memory,
  3971.      pretend it arrived entirely in memory
  3972.      by pushing the register-part onto the stack.
  3973.  
  3974.      In the special case of a DImode or DFmode that is split,
  3975.      we could put it together in a pseudoreg directly,
  3976.      but for now that's not worth bothering with.  */
  3977.  
  3978.       /* If this is the last named arg and anonymous args follow,
  3979.      likewise pretend this arg arrived on the stack
  3980.      so varargs can find the anonymous args following it.  */
  3981.       {
  3982.     int nregs = 0;
  3983.     int i;
  3984. #ifdef FUNCTION_ARG_PARTIAL_NREGS
  3985.     nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, passed_mode,
  3986.                         DECL_ARG_TYPE (parm), 1);
  3987. #endif
  3988.     if (TREE_CHAIN (parm) == 0 && vararg && entry_parm != 0)
  3989.       {
  3990.         if (GET_MODE (entry_parm) == BLKmode)
  3991.           nregs = GET_MODE_SIZE (GET_MODE (entry_parm)) / UNITS_PER_WORD;
  3992.         else
  3993.           nregs = (int_size_in_bytes (DECL_ARG_TYPE (parm))
  3994.                / UNITS_PER_WORD);
  3995.       }
  3996.  
  3997.     if (nregs > 0)
  3998.       {
  3999.         current_function_pretend_args_size
  4000.           = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1)
  4001.          / (PARM_BOUNDARY / BITS_PER_UNIT)
  4002.          * (PARM_BOUNDARY / BITS_PER_UNIT));
  4003.  
  4004.         i = nregs;
  4005.         while (--i >= 0)
  4006.           emit_move_insn (gen_rtx (MEM, SImode,
  4007.                        plus_constant (XEXP (stack_parm, 0),
  4008.                               i * GET_MODE_SIZE (SImode))),
  4009.                   gen_rtx (REG, SImode, REGNO (entry_parm) + i));
  4010.         entry_parm = stack_parm;
  4011.       }
  4012.       }
  4013.  
  4014.       /* If we didn't decide this parm came in a register,
  4015.      by default it came on the stack.  */
  4016.       if (entry_parm == 0)
  4017.     entry_parm = stack_parm;
  4018.  
  4019.       /* For a stack parm, record in DECL_OFFSET the arglist offset
  4020.      of the parm at the time it is passed (before conversion).  */
  4021.       if (entry_parm == stack_parm)
  4022.     DECL_OFFSET (parm) = stack_offset.constant * BITS_PER_UNIT;
  4023.  
  4024.       /* If there is actually space on the stack for this parm,
  4025.      count it in stack_args_size; otherwise set stack_parm to 0
  4026.      to indicate there is no preallocated stack slot for the parm.  */
  4027.  
  4028.       if (entry_parm == stack_parm
  4029. #ifdef REG_PARM_STACK_SPACE
  4030.       /* On some machines, even if a parm value arrives in a register
  4031.          there is still an (uninitialized) stack slot allocated for it.  */
  4032.       || 1
  4033. #endif
  4034.       )
  4035.     {
  4036.       tree sizetree = size_in_bytes (DECL_ARG_TYPE (parm));
  4037.       if (where_pad != none)
  4038.         {
  4039.           /* Round the size up to multiple of PARM_BOUNDARY bits.  */
  4040.           tree s1 = convert_units (sizetree, BITS_PER_UNIT, PARM_BOUNDARY);
  4041.           sizetree = convert_units (s1, PARM_BOUNDARY, BITS_PER_UNIT);
  4042.         }
  4043.       /* Add it in.  */
  4044.       ADD_PARM_SIZE (stack_args_size, sizetree);
  4045.     }
  4046.       else
  4047.     /* No stack slot was pushed for this parm.  */
  4048.     stack_parm = 0;
  4049.  
  4050.       /* Now adjust STACK_PARM to the mode and precise location
  4051.      where this parameter should live during execution,
  4052.      if we discover that it must live in the stack during execution.
  4053.      To make debuggers happier on big-endian machines, we store
  4054.      the value in the last bytes of the space available.  */
  4055.  
  4056.       if (nominal_mode != BLKmode && nominal_mode != passed_mode
  4057.       && stack_parm != 0)
  4058.     {
  4059. #ifdef BYTES_BIG_ENDIAN
  4060.       if (GET_MODE_SIZE (nominal_mode) < UNITS_PER_WORD)
  4061.         {
  4062.           stack_offset.constant
  4063.         += GET_MODE_SIZE (passed_mode)
  4064.           - GET_MODE_SIZE (nominal_mode);
  4065.           stack_offset_rtx = ARGS_SIZE_RTX (stack_offset);
  4066.         }
  4067. #endif
  4068.  
  4069.       stack_parm
  4070.         = gen_rtx (MEM, nominal_mode,
  4071.                memory_address (nominal_mode,
  4072.                        gen_rtx (PLUS, Pmode,
  4073.                         arg_pointer_rtx,
  4074.                         stack_offset_rtx)));
  4075.  
  4076.       /* If this is a memory ref that contains aggregate components,
  4077.          mark it as such for cse and loop optimize.  */
  4078.       MEM_IN_STRUCT_P (stack_parm) = aggregate;
  4079.     }
  4080.  
  4081.       /* ENTRY_PARM is an RTX for the parameter as it arrives,
  4082.      in the mode in which it arrives.
  4083.      STACK_PARM is an RTX for a stack slot where the parameter can live
  4084.      during the function (in case we want to put it there).
  4085.      STACK_PARM is 0 if no stack slot was pushed for it.
  4086.  
  4087.      Now output code if necessary to convert ENTRY_PARM to
  4088.      the type in which this function declares it,
  4089.      and store that result in an appropriate place,
  4090.      which may be a pseudo reg, may be STACK_PARM,
  4091.      or may be a local stack slot if STACK_PARM is 0.
  4092.  
  4093.      Set DECL_RTL to that place.  */
  4094.  
  4095.       if (nominal_mode == BLKmode)
  4096.     {
  4097.       /* If a BLKmode arrives in registers, copy it to a stack slot.  */
  4098.       if (GET_CODE (entry_parm) == REG)
  4099.         {
  4100.           if (stack_parm == 0)
  4101.         stack_parm
  4102.           = assign_stack_local (GET_MODE (entry_parm),
  4103.                     int_size_in_bytes (TREE_TYPE (parm)));
  4104.  
  4105.           move_block_from_reg (REGNO (entry_parm), stack_parm,
  4106.                    int_size_in_bytes (TREE_TYPE (parm))
  4107.                    / UNITS_PER_WORD);
  4108.         }
  4109.       DECL_RTL (parm) = stack_parm;
  4110.     }
  4111.       else if (! ((obey_regdecls && ! TREE_REGDECL (parm)
  4112.            && ! TREE_INLINE (fndecl))
  4113.           /* layout_decl may set this.  */
  4114.           || TREE_ADDRESSABLE (parm)
  4115.           || TREE_VOLATILE (parm)
  4116.           /* If -ffloat-store specified, don't put explicit
  4117.              float variables into registers.  */
  4118.           || (flag_float_store
  4119.               && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)))
  4120.     {
  4121.       /* Store the parm in a pseudoregister during the function.  */
  4122.       register rtx parmreg = gen_reg_rtx (nominal_mode);
  4123.  
  4124.       REG_USERVAR_P (parmreg) = 1;
  4125.       DECL_RTL (parm) = parmreg;
  4126.  
  4127.       /* Copy the value into the register.  */
  4128.       if (GET_MODE (parmreg) != GET_MODE (entry_parm))
  4129.         convert_move (parmreg, entry_parm, 0);
  4130.       else
  4131.         emit_move_insn (parmreg, entry_parm);
  4132.  
  4133.       /* In any case, record the parm's desired stack location
  4134.          in case we later discover it must live in the stack.  */
  4135.       if (REGNO (parmreg) >= nparmregs)
  4136.         {
  4137.           rtx *new;
  4138.           nparmregs = REGNO (parmreg) + 5;
  4139.           new = (rtx *) oballoc (nparmregs * sizeof (rtx));
  4140.           bcopy (parm_reg_stack_loc, new, nparmregs * sizeof (rtx));
  4141.           parm_reg_stack_loc = new;
  4142.         }
  4143.       parm_reg_stack_loc[REGNO (parmreg)] = stack_parm;
  4144.  
  4145.       /* Mark the register as eliminable if we did no conversion
  4146.          and it was copied from memory at a fixed offset.  */
  4147.       if (nominal_mode == passed_mode
  4148.           && GET_CODE (entry_parm) == MEM
  4149.           && stack_offset.var == 0)
  4150.         REG_NOTES (get_last_insn ())
  4151.           = gen_rtx (EXPR_LIST, REG_EQUIV,
  4152.              entry_parm, REG_NOTES (get_last_insn ()));
  4153.  
  4154.       /* For pointer data type, suggest pointer register.  */
  4155.       if (TREE_CODE (TREE_TYPE (parm)) == POINTER_TYPE)
  4156.         mark_reg_pointer (parmreg);
  4157.     }
  4158.       else
  4159.     {
  4160.       /* Value must be stored in the stack slot STACK_PARM
  4161.          during function execution.  */
  4162.  
  4163.       if (passed_mode != nominal_mode)
  4164.         /* Conversion is required.  */
  4165.         entry_parm = convert_to_mode (nominal_mode, entry_parm, 0);
  4166.  
  4167.       if (entry_parm != stack_parm)
  4168.         {
  4169.           if (stack_parm == 0)
  4170.         stack_parm = assign_stack_local (GET_MODE (entry_parm),
  4171.                          GET_MODE_SIZE (GET_MODE (entry_parm)));
  4172.           emit_move_insn (stack_parm, entry_parm);
  4173.         }
  4174.  
  4175.       DECL_RTL (parm) = stack_parm;
  4176.       frame_pointer_needed = 1;
  4177.     }
  4178.       
  4179.       if (TREE_VOLATILE (parm))
  4180.     MEM_VOLATILE_P (DECL_RTL (parm)) = 1;
  4181.       if (TREE_READONLY (parm))
  4182.     RTX_UNCHANGING_P (DECL_RTL (parm)) = 1;
  4183.  
  4184.       /* Update info on where next arg arrives in registers.  */
  4185.  
  4186.       FUNCTION_ARG_ADVANCE (args_so_far, passed_mode, DECL_ARG_TYPE (parm), 1);
  4187.     }
  4188.  
  4189.   max_parm_reg = max_reg_num ();
  4190.   last_parm_insn = get_last_insn ();
  4191.  
  4192.   current_function_args_size = stack_args_size.constant;
  4193. }
  4194.  
  4195. /* Allocation of space for returned structure values.
  4196.    During the rtl generation pass, `get_structure_value_addr'
  4197.    is called from time to time to request the address of a block in our
  4198.    stack frame in which called functions will store the structures
  4199.    they are returning.  The same space is used for all of these blocks.  
  4200.  
  4201.    We allocate these blocks like stack locals.  We keep reusing
  4202.    the same block until a bigger one is needed.  */
  4203.  
  4204. /* Length in bytes of largest structure value returned by
  4205.    any function called so far in this function.  */
  4206. static int max_structure_value_size;
  4207.  
  4208. /* An rtx for the addr we are currently using for structure values.
  4209.    This is typically (PLUS (REG:SI stackptr) (CONST_INT...)).  */
  4210. static rtx structure_value;
  4211.  
  4212. rtx
  4213. get_structure_value_addr (sizex)
  4214.      rtx sizex;
  4215. {
  4216.   register int size;
  4217.   if (GET_CODE (sizex) != CONST_INT)
  4218.     abort ();
  4219.   size = INTVAL (sizex);
  4220.  
  4221.   /* Round up to a multiple of the main allocation unit.  */
  4222.   size = (((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
  4223.        / (BIGGEST_ALIGNMENT / BITS_PER_UNIT))
  4224.       * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
  4225.  
  4226.   /* If this size is bigger than space we know to use,
  4227.      get a bigger piece of space.  */
  4228.   if (size > max_structure_value_size)
  4229.     {
  4230.       max_structure_value_size = size;
  4231.       structure_value = assign_stack_local (BLKmode, size);
  4232.       if (GET_CODE (structure_value) == MEM)
  4233.     structure_value = XEXP (structure_value, 0);
  4234.     }
  4235.  
  4236.   return structure_value;
  4237. }
  4238.  
  4239. /* Walk the tree of LET_STMTs describing the binding levels within a function
  4240.    and warn about uninitialized variables.
  4241.    This is done after calling flow_analysis and before global_alloc
  4242.    clobbers the pseudo-regs to hard regs.  */
  4243.  
  4244. void
  4245. uninitialized_vars_warning (block)
  4246.      tree block;
  4247. {
  4248.   register tree decl, sub;
  4249.   for (decl = STMT_VARS (block); decl; decl = TREE_CHAIN (decl))
  4250.     {
  4251.       if (TREE_CODE (decl) == VAR_DECL
  4252.       /* These warnings are unreliable for and aggregates
  4253.          because assigning the fields one by one can fail to convince
  4254.          flow.c that the entire aggregate was initialized.
  4255.          Unions are troublesome because members may be shorter.  */
  4256.       && TREE_CODE (TREE_TYPE (decl)) != RECORD_TYPE
  4257.       && TREE_CODE (TREE_TYPE (decl)) != UNION_TYPE
  4258.       && TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE
  4259.       && GET_CODE (DECL_RTL (decl)) == REG
  4260.       && regno_uninitialized (REGNO (DECL_RTL (decl))))
  4261.     warning_with_decl (decl,
  4262.                "`%s' may be used uninitialized in this function");
  4263.       if (TREE_CODE (decl) == VAR_DECL
  4264.       && GET_CODE (DECL_RTL (decl)) == REG
  4265.       && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
  4266.     warning_with_decl (decl,
  4267.                "variable `%s' may be clobbered by `longjmp'");
  4268.     }
  4269.   for (sub = STMT_BODY (block); sub; sub = TREE_CHAIN (sub))
  4270.     uninitialized_vars_warning (sub);
  4271. }
  4272.  
  4273. /* If this function call setjmp, put all vars into the stack
  4274.    unless they were declared `register'.  */
  4275.  
  4276. void
  4277. setjmp_protect (block)
  4278.      tree block;
  4279. {
  4280.   register tree decl, sub;
  4281.   for (decl = STMT_VARS (block); decl; decl = TREE_CHAIN (decl))
  4282.     if ((TREE_CODE (decl) == VAR_DECL
  4283.      || TREE_CODE (decl) == PARM_DECL)
  4284.     && DECL_RTL (decl) != 0
  4285.     && GET_CODE (DECL_RTL (decl)) == REG
  4286.     && ! TREE_REGDECL (decl))
  4287.       put_var_into_stack (decl);
  4288.   for (sub = STMT_BODY (block); sub; sub = TREE_CHAIN (sub))
  4289.     setjmp_protect (sub);
  4290. }
  4291.  
  4292. /* Generate RTL for the start of the function FUNC (a FUNCTION_DECL tree node)
  4293.    and initialize static variables for generating RTL for the statements
  4294.    of the function.  */
  4295.  
  4296. void
  4297. init_function_start (subr)
  4298.      tree subr;
  4299. {
  4300.   this_function = subr;
  4301.   cse_not_expected = ! optimize;
  4302.  
  4303.   /* We have not yet found a reason why a frame pointer cannot
  4304.      be omitted for this function in particular, but maybe we know
  4305.      a priori that it is required.
  4306.      `flag_omit_frame_pointer' has its main effect here.  */
  4307.   frame_pointer_needed = FRAME_POINTER_REQUIRED || ! flag_omit_frame_pointer;
  4308.  
  4309.   /* Caller save not needed yet.  */
  4310.   caller_save_needed = 0;
  4311.  
  4312.   /* No gotos have been expanded yet.  */
  4313.   goto_fixup_chain = 0;
  4314.  
  4315.   /* No stack slots have been made yet.  */
  4316.   stack_slot_list = 0;
  4317.  
  4318.   /* No invalid stack slots have been made yet.  */
  4319.   invalid_stack_slot = 0;
  4320.  
  4321.   /* Initialize the RTL mechanism.  */
  4322.   init_emit (write_symbols);
  4323.  
  4324.   /* Initialize the queue of pending postincrement and postdecrements,
  4325.      and some other info in expr.c.  */
  4326.   init_expr ();
  4327.  
  4328.   init_const_rtx_hash_table ();
  4329.  
  4330.   /* Decide whether function should try to pop its args on return.  */
  4331.  
  4332.   current_function_pops_args = RETURN_POPS_ARGS (TREE_TYPE (subr));
  4333.  
  4334.   current_function_name = lang_printable_name (subr);
  4335.  
  4336.   /* Nonzero if this is a nested function that uses a static chain.  */
  4337.  
  4338.   current_function_needs_context
  4339.     = (DECL_CONTEXT (current_function_decl) != 0
  4340.        && TREE_CODE (DECL_CONTEXT (current_function_decl)) == LET_STMT);
  4341.  
  4342.   /* Set if a call to setjmp is seen.  */
  4343.  
  4344.   current_function_calls_setjmp = 0;
  4345.  
  4346.   current_function_returns_pcc_struct = 0;
  4347.   current_function_returns_struct = 0;
  4348.  
  4349.   /* No space assigned yet for structure values.  */
  4350.   max_structure_value_size = 0;
  4351.   structure_value = 0;
  4352.  
  4353.   /* We are not currently within any block, conditional, loop or case.
  4354.      @@ No longer true.  We are within the block for the parms.  */
  4355.   block_stack = 0;
  4356.   loop_stack = 0;
  4357.   case_stack = 0;
  4358.   cond_stack = 0;
  4359.   nesting_stack = 0;
  4360.   nesting_depth = 0;
  4361.  
  4362.   /* We have not yet needed to make a label to jump to for tail-recursion.  */
  4363.   tail_recursion_label = 0;
  4364.  
  4365.   /* No stack slots allocated yet.  */
  4366.   frame_offset = STARTING_FRAME_OFFSET;
  4367.  
  4368.   /* No SAVE_EXPRs in this function yet.  */
  4369.   save_expr_regs = 0;
  4370.  
  4371.   /* No RTL_EXPRs in this function yet.  */
  4372.   rtl_expr_chain = 0;
  4373.  
  4374.   /* Within function body, compute a type's size as soon it is laid out.  */
  4375.   immediate_size_expand++;
  4376.  
  4377.   init_pending_stack_adjust ();
  4378.   clear_current_args_size ();
  4379.   current_function_pretend_args_size = 0;
  4380.  
  4381.   /* Prevent ever trying to delete the first instruction of a function.
  4382.      Also tell final how to output a linenum before the function prologue.  */
  4383.   emit_line_note (DECL_SOURCE_FILE (subr), DECL_SOURCE_LINE (subr));
  4384.   /* Make sure first insn is a note even if we don't want linenums.
  4385.      This makes sure the first insn will never be deleted.
  4386.      Also, final expects a note to appear there.  */
  4387.   emit_note (0, NOTE_INSN_DELETED);
  4388. }
  4389.  
  4390. void
  4391. expand_function_start (subr, parms_have_cleanups)
  4392.      tree subr;
  4393.      int parms_have_cleanups;
  4394. {
  4395.   register int i;
  4396.   tree tem;
  4397.  
  4398.   /* If the parameters of this function need cleaning up, get a label
  4399.      for the beginning of the code which executes those cleanups.  This must
  4400.      be done before doing anything with return_label.  */
  4401.   if (parms_have_cleanups)
  4402.     cleanup_label = gen_label_rtx ();
  4403.   else
  4404.     cleanup_label = 0;
  4405.  
  4406.   /* Make the label for return statements to jump to, if this machine
  4407.      does not have a one-instruction return.  */
  4408. #ifdef HAVE_return
  4409.   if (cleanup_label == 0 && HAVE_return && ! current_function_returns_pcc_struct)
  4410.     return_label = 0;
  4411.   else
  4412.     return_label = gen_label_rtx ();
  4413. #else
  4414.   return_label = gen_label_rtx ();
  4415. #endif
  4416.  
  4417.   /* Initialize rtx for parameters and local variables.
  4418.      In some cases this requires emitting insns.  */
  4419.  
  4420.   assign_parms (subr);
  4421.  
  4422.   /* Initialize rtx used to return the value.  */
  4423.  
  4424.   /* Decide whether to return the value in memory or in a register.  */
  4425.   if (DECL_MODE (DECL_RESULT (subr)) == BLKmode
  4426.       || RETURN_IN_MEMORY (TREE_TYPE (DECL_RESULT (current_function_decl)))
  4427.       || (flag_pcc_struct_return
  4428.       && ((TREE_CODE (TREE_TYPE (DECL_RESULT (subr)))
  4429.            == RECORD_TYPE)
  4430.           || (TREE_CODE (TREE_TYPE (DECL_RESULT (subr)))
  4431.           == UNION_TYPE))))
  4432.     {
  4433.       /* Returning something that won't go in a register.  */
  4434.       register rtx value_address;
  4435.  
  4436. #ifdef PCC_STATIC_STRUCT_RETURN
  4437.       if (flag_pcc_struct_return)
  4438.     {
  4439.       int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
  4440.       value_address = assemble_static_space (size);
  4441.       current_function_returns_pcc_struct = 1;
  4442.     }
  4443.       else
  4444. #endif
  4445.     {
  4446.       /* Expect to be passed the address of a place to store the value.  */
  4447.       value_address = gen_reg_rtx (Pmode);
  4448.       emit_move_insn (value_address, struct_value_incoming_rtx);
  4449.       current_function_returns_struct = 1;
  4450.     }
  4451.       DECL_RTL (DECL_RESULT (subr))
  4452.     = gen_rtx (MEM, DECL_MODE (DECL_RESULT (subr)),
  4453.            value_address);
  4454.     }
  4455.   else
  4456.     /* Scalar, returned in a register.  */
  4457.     {
  4458.       if (block_stack->data.block.cleanups == 0
  4459.       || TREE_TYPE (DECL_RESULT (subr)) == void_type_node)
  4460.     {
  4461. #ifdef FUNCTION_OUTGOING_VALUE
  4462.       DECL_RTL (DECL_RESULT (subr))
  4463.         = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
  4464. #else
  4465.       DECL_RTL (DECL_RESULT (subr))
  4466.         = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
  4467. #endif
  4468.       /* Mark this reg as the function's return value.  */
  4469.       if (GET_CODE (DECL_RTL (DECL_RESULT (subr))) == REG)
  4470.         REG_FUNCTION_VALUE_P (DECL_RTL (DECL_RESULT (subr))) = 1;
  4471.     }
  4472.       else
  4473.     DECL_RTL (DECL_RESULT (subr)) = gen_reg_rtx (DECL_MODE (DECL_RESULT (subr)));
  4474.     }
  4475.  
  4476.   /* If doing stupid allocation, mark parms as born here.  */
  4477.  
  4478.   if (obey_regdecls)
  4479.     {
  4480.       parm_birth_insn = get_last_insn ();
  4481.       for (i = FIRST_PSEUDO_REGISTER; i < max_parm_reg; i++)
  4482.     use_variable (regno_reg_rtx[i]);
  4483.     }
  4484.  
  4485.   /* After the parm initializations is where the tail-recursion label
  4486.      should go, if we end up needing one.  */
  4487.   tail_recursion_reentry = get_last_insn ();
  4488.  
  4489.   /* Evaluate now the sizes of any types declared among the arguments.  */
  4490.   for (tem = get_pending_sizes (); tem; tem = TREE_CHAIN (tem))
  4491.     expand_expr (TREE_VALUE (tem), 0, VOIDmode, 0);
  4492. }
  4493.  
  4494. /* Generate RTL for the end of the current function.
  4495.    FILENAME and LINE are the current position in the source file.  */
  4496.  
  4497. void
  4498. expand_function_end (filename, line)
  4499.      char *filename;
  4500.      int line;
  4501. {
  4502.   register int i;
  4503.   extern rtx sequence_stack;
  4504.  
  4505.   /* End any sequences that failed to be closed due to syntax errors.  */
  4506.   while (sequence_stack)
  4507.     end_sequence (0);
  4508.  
  4509.   if (cleanup_label)
  4510.     {
  4511.       /* See that the pseudo-DECL_RESULT is transferred to the real
  4512.      DECL_RESULT of this function.  */
  4513.       if (TREE_TYPE (DECL_RESULT (current_function_decl)) != void_type_node
  4514.       && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG)
  4515.     {
  4516.       rtx real_decl_result;
  4517.  
  4518. #ifdef FUNCTION_OUTGOING_VALUE
  4519.       real_decl_result
  4520.         = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
  4521.                        current_function_decl);
  4522. #else
  4523.       real_decl_result
  4524.         = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
  4525.                   current_function_decl);
  4526. #endif
  4527.       REG_FUNCTION_VALUE_P (real_decl_result) = 1;
  4528.       emit_move_insn (real_decl_result,
  4529.               DECL_RTL (DECL_RESULT (current_function_decl)));
  4530.       emit_insn (gen_rtx (USE, VOIDmode, real_decl_result));
  4531.     }
  4532.     }
  4533.  
  4534.   /* Outside function body, can't compute type's actual size
  4535.      until next function's body starts.  */
  4536.   immediate_size_expand--;
  4537.  
  4538.   /* If returning a structure, arrange to return the address of the value
  4539.      in a place where debuggers expect to find it.  */
  4540.   if (current_function_returns_struct)
  4541.     {
  4542.       rtx value_address = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
  4543.       tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
  4544.       rtx outgoing
  4545.     = hard_function_value (build_pointer_type (type),
  4546.                    current_function_decl);
  4547.  
  4548.       emit_move_insn (outgoing, value_address);
  4549.     }
  4550.  
  4551.   /* If doing stupid register allocation,
  4552.      mark register parms as dying here.  */
  4553.  
  4554.   if (obey_regdecls)
  4555.     {
  4556.       rtx tem;
  4557.       for (i = FIRST_PSEUDO_REGISTER; i < max_parm_reg; i++)
  4558.     use_variable (regno_reg_rtx[i]);
  4559.  
  4560.       /* Likewise for the regs of all the SAVE_EXPRs in the function.  */
  4561.  
  4562.       for (tem = save_expr_regs; tem; tem = XEXP (tem, 1))
  4563.     {
  4564.       /* ??? Tiemann thinks this does not work.  */
  4565.       use_variable (XEXP (tem, 0));
  4566.       use_variable_after (XEXP (tem, 0), parm_birth_insn);
  4567.     }
  4568.     }
  4569.  
  4570.   clear_pending_stack_adjust ();
  4571.   do_pending_stack_adjust ();
  4572.  
  4573.   /* Mark the end of the function body.
  4574.      If control reaches this insn, the function can drop through
  4575.      without returning a value.  */
  4576.   emit_note (0, NOTE_INSN_FUNCTION_END);
  4577.  
  4578.   /* Output a linenumber for the end of the function.
  4579.      SDB depends on this.  */
  4580.   emit_line_note_force (filename, line);
  4581.  
  4582.   /* If we require a true epilogue,
  4583.      put here the label that return statements jump to.
  4584.      If there will be no epilogue, write a return instruction.  */
  4585. #ifdef HAVE_return
  4586.   if (HAVE_return && ! current_function_returns_pcc_struct)
  4587.     {
  4588.       /* If cleanups forced us to have a return label, then emit it.  */
  4589.       if (return_label)
  4590.     emit_label (return_label);
  4591.       emit_jump_insn (gen_return ());
  4592.     }
  4593.   else
  4594. #endif
  4595.     emit_label (return_label);
  4596.  
  4597.   /* If returning a structure PCC style,
  4598.      really return the address of where we put the structure.
  4599.      Do this after the return label, since all returns must
  4600.      do it.  */
  4601.   if (current_function_returns_pcc_struct)
  4602.     {
  4603.       rtx value_address = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
  4604.       tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
  4605.       rtx outgoing
  4606.     = hard_function_value (build_pointer_type (type),
  4607.                    current_function_decl);
  4608.  
  4609.       emit_move_insn (outgoing, value_address);
  4610.       use_variable (outgoing);
  4611.  
  4612. #ifdef HAVE_return
  4613.       if (HAVE_return)
  4614.     {
  4615.       emit_jump_insn (gen_return ());
  4616.       emit_barrier ();
  4617.     }
  4618. #endif
  4619.     }
  4620.  
  4621.   /* Fix up any gotos that jumped out to the outermost
  4622.      binding level of the function.
  4623.      Must follow emitting RETURN_LABEL.  */
  4624.  
  4625.   /* If you have any cleanups to do at this point,
  4626.      and they need to create temporary variables,
  4627.      then you will lose.  */
  4628.   fixup_gotos (0, 0, 0, get_insns (), 0);
  4629. }
  4630.