Annotation of gcc/stmt.c, revision 1.1.1.14

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.