home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / GCC 1.37.1r14 / usr / gcc-1.37.1r14 / (gcc-1.37.π) / stmt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-29  |  153.0 KB  |  4,982 lines  |  [TEXT/KAHL]

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