Annotation of gcc/flow.c, revision 1.1.1.12

1.1       root        1: /* Data flow analysis for GNU compiler.
1.1.1.2   root        2:    Copyright (C) 1987, 1988 Free Software Foundation, Inc.
1.1       root        3: 
                      4: This file is part of GNU CC.
                      5: 
1.1.1.12! root        6: GNU CC is free software; you can redistribute it and/or modify
        !             7: it under the terms of the GNU General Public License as published by
        !             8: the Free Software Foundation; either version 1, or (at your option)
        !             9: any later version.
        !            10: 
1.1       root       11: GNU CC is distributed in the hope that it will be useful,
1.1.1.12! root       12: but WITHOUT ANY WARRANTY; without even the implied warranty of
        !            13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        !            14: GNU General Public License for more details.
        !            15: 
        !            16: You should have received a copy of the GNU General Public License
        !            17: along with GNU CC; see the file COPYING.  If not, write to
        !            18: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
1.1       root       19: 
                     20: 
                     21: /* This file contains the data flow analysis pass of the compiler.
                     22:    It computes data flow information
                     23:    which tells combine_instructions which insns to consider combining
                     24:    and controls register allocation.
                     25: 
                     26:    Additional data flow information that is too bulky to record
                     27:    is generated during the analysis, and is used at that time to
                     28:    create autoincrement and autodecrement addressing.
                     29: 
                     30:    The first step is dividing the function into basic blocks.
                     31:    find_basic_blocks does this.  Then life_analysis determines
                     32:    where each register is live and where it is dead.
                     33: 
                     34:    ** find_basic_blocks **
                     35: 
                     36:    find_basic_blocks divides the current function's rtl
                     37:    into basic blocks.  It records the beginnings and ends of the
                     38:    basic blocks in the vectors basic_block_head and basic_block_end,
                     39:    and the number of blocks in n_basic_blocks.
                     40: 
                     41:    find_basic_blocks also finds any unreachable loops
                     42:    and deletes them.
                     43: 
                     44:    ** life_analysis **
                     45: 
                     46:    life_analysis is called immediately after find_basic_blocks.
                     47:    It uses the basic block information to determine where each
                     48:    hard or pseudo register is live.
                     49: 
                     50:    ** live-register info **
                     51: 
                     52:    The information about where each register is live is in two parts:
                     53:    the REG_NOTES of insns, and the vector basic_block_live_at_start.
                     54: 
                     55:    basic_block_live_at_start has an element for each basic block,
                     56:    and the element is a bit-vector with a bit for each hard or pseudo
                     57:    register.  The bit is 1 if the register is live at the beginning
                     58:    of the basic block.
                     59: 
                     60:    To each insn's REG_NOTES is added an element for each register
                     61:    that is live before the insn or set by the insn, but is dead
                     62:    after the insn.
                     63: 
                     64:    To determine which registers are live after any insn, one can
                     65:    start from the beginning of the basic block and scan insns, noting
                     66:    which registers are set by each insn and which die there.
                     67: 
                     68:    ** Other actions of life_analysis **
                     69: 
                     70:    life_analysis sets up the LOG_LINKS fields of insns because the
                     71:    information needed to do so is readily available.
                     72: 
                     73:    life_analysis deletes insns whose only effect is to store a value
                     74:    that is never used.
                     75: 
                     76:    life_analysis notices cases where a reference to a register as
                     77:    a memory address can be combined with a preceding or following
                     78:    incrementation or decrementation of the register.  The separate
                     79:    instruction to increment or decrement is deleted and the address
                     80:    is changed to a POST_INC or similar rtx.
                     81: 
                     82:    Each time an incrementing or decrementing address is created,
                     83:    a REG_INC element is added to the insn's REG_NOTES list.
                     84: 
                     85:    life_analysis fills in certain vectors containing information about
                     86:    register usage: reg_n_refs, reg_n_deaths, reg_n_sets,
                     87:    reg_live_length, reg_crosses_call and reg_basic_block.  */
                     88: 
                     89: #include <stdio.h>
                     90: #include "config.h"
                     91: #include "rtl.h"
                     92: #include "basic-block.h"
                     93: #include "regs.h"
1.1.1.2   root       94: #include "hard-reg-set.h"
                     95: #include "flags.h"
1.1       root       96: 
                     97: /* Get the basic block number of an insn.
                     98:    This info should not be expected to remain available
                     99:    after the end of life_analysis.  */
                    100: 
                    101: #define BLOCK_NUM(INSN)  uid_block_number[INSN_UID (INSN)]
                    102: 
                    103: /* This is where the BLOCK_NUM values are really stored.
                    104:    This is set up by find_basic_blocks and used there and in life_analysis,
                    105:    and then freed.  */
                    106: 
                    107: static short *uid_block_number;
                    108: 
1.1.1.2   root      109: /* INSN_VOLATILE (insn) is 1 if the insn refers to anything volatile.  */
                    110: 
                    111: #define INSN_VOLATILE(INSN) uid_volatile[INSN_UID (INSN)]
                    112: static char *uid_volatile;
                    113: 
1.1       root      114: /* Number of basic blocks in the current function.  */
                    115: 
                    116: int n_basic_blocks;
                    117: 
                    118: /* Maximum register number used in this function, plus one.  */
                    119: 
                    120: int max_regno;
                    121: 
                    122: /* Indexed by n, gives number of basic block that  (REG n) is used in.
1.1.1.10  root      123:    If the value is REG_BLOCK_GLOBAL (-2),
                    124:    it means (REG n) is used in more than one basic block.
                    125:    REG_BLOCK_UNKNOWN (-1) means it hasn't been seen yet so we don't know.
1.1       root      126:    This information remains valid for the rest of the compilation
                    127:    of the current function; it is used to control register allocation.  */
                    128: 
                    129: short *reg_basic_block;
                    130: 
                    131: /* Indexed by n, gives number of times (REG n) is used or set, each
                    132:    weighted by its loop-depth.
                    133:    This information remains valid for the rest of the compilation
                    134:    of the current function; it is used to control register allocation.  */
                    135: 
                    136: short *reg_n_refs;
                    137: 
                    138: /* Indexed by n, gives number of times (REG n) is set.
                    139:    This information remains valid for the rest of the compilation
                    140:    of the current function; it is used to control register allocation.  */
                    141: 
                    142: short *reg_n_sets;
                    143: 
                    144: /* Indexed by N, gives number of places register N dies.
                    145:    This information remains valid for the rest of the compilation
                    146:    of the current function; it is used to control register allocation.  */
                    147: 
                    148: short *reg_n_deaths;
                    149: 
                    150: /* Indexed by N, gives 1 if that reg is live across any CALL_INSNs.
                    151:    This information remains valid for the rest of the compilation
                    152:    of the current function; it is used to control register allocation.  */
                    153: 
1.1.1.12! root      154: int *reg_n_calls_crossed;
1.1       root      155: 
                    156: /* Total number of instructions at which (REG n) is live.
                    157:    The larger this is, the less priority (REG n) gets for
                    158:    allocation in a real register.
                    159:    This information remains valid for the rest of the compilation
1.1.1.2   root      160:    of the current function; it is used to control register allocation.
                    161: 
                    162:    local-alloc.c may alter this number to change the priority.
                    163: 
                    164:    Negative values are special.
                    165:    -1 is used to mark a pseudo reg which has a constant or memory equivalent
                    166:    and is used infrequently enough that it should not get a hard register.
                    167:    -2 is used to mark a pseudo reg for a parameter, when a frame pointer
                    168:    is not required.  global-alloc.c makes an allocno for this but does
                    169:    not try to assign a hard register to it.  */
1.1       root      170: 
                    171: int *reg_live_length;
                    172: 
                    173: /* Element N is the next insn that uses (hard or pseudo) register number N
                    174:    within the current basic block; or zero, if there is no such insn.
                    175:    This is valid only during the final backward scan in propagate_block.  */
                    176: 
                    177: static rtx *reg_next_use;
                    178: 
                    179: /* Size of a regset for the current function,
                    180:    in (1) bytes and (2) elements.  */
                    181: 
                    182: int regset_bytes;
                    183: int regset_size;
                    184: 
                    185: /* Element N is first insn in basic block N.
                    186:    This info lasts until we finish compiling the function.  */
                    187: 
                    188: rtx *basic_block_head;
                    189: 
                    190: /* Element N is last insn in basic block N.
                    191:    This info lasts until we finish compiling the function.  */
                    192: 
                    193: rtx *basic_block_end;
                    194: 
                    195: /* Element N is a regset describing the registers live
                    196:    at the start of basic block N.
                    197:    This info lasts until we finish compiling the function.  */
                    198: 
                    199: regset *basic_block_live_at_start;
                    200: 
1.1.1.2   root      201: /* Regset of regs live when calls to `setjmp'-like functions happen.  */
                    202: 
                    203: regset regs_live_at_setjmp;
                    204: 
1.1       root      205: /* Element N is nonzero if control can drop into basic block N
                    206:    from the preceding basic block.  Freed after life_analysis.  */
                    207: 
1.1.1.2   root      208: static char *basic_block_drops_in;
1.1       root      209: 
                    210: /* Element N is depth within loops of basic block number N.
                    211:    Freed after life_analysis.  */
                    212: 
1.1.1.2   root      213: static short *basic_block_loop_depth;
1.1       root      214: 
                    215: /* Element N nonzero if basic block N can actually be reached.
                    216:    Vector exists only during find_basic_blocks.  */
                    217: 
1.1.1.2   root      218: static char *block_live_static;
1.1       root      219: 
                    220: /* Depth within loops of basic block being scanned for lifetime analysis,
                    221:    plus one.  This is the weight attached to references to registers.  */
                    222: 
1.1.1.2   root      223: static int loop_depth;
                    224: 
                    225: /* Define AUTO_INC_DEC if machine has any kind of incrementing
                    226:    or decrementing addressing.  */
                    227: 
                    228: #ifdef HAVE_PRE_DECREMENT
                    229: #define AUTO_INC_DEC
                    230: #endif
                    231: 
                    232: #ifdef HAVE_PRE_INCREMENT
                    233: #define AUTO_INC_DEC
                    234: #endif
                    235: 
                    236: #ifdef HAVE_POST_DECREMENT
                    237: #define AUTO_INC_DEC
                    238: #endif
                    239: 
                    240: #ifdef HAVE_POST_INCREMENT
                    241: #define AUTO_INC_DEC
                    242: #endif
1.1       root      243: 
                    244: /* Forward declarations */
                    245: static void find_basic_blocks ();
                    246: static void life_analysis ();
                    247: static void mark_label_ref ();
                    248: void allocate_for_life_analysis (); /* Used also in stupid_life_analysis */
                    249: static void init_regset_vector ();
                    250: static void propagate_block ();
                    251: static void mark_set_regs ();
                    252: static void mark_used_regs ();
                    253: static int insn_dead_p ();
1.1.1.10  root      254: static int libcall_dead_p ();
1.1       root      255: static int try_pre_increment ();
                    256: static int try_pre_increment_1 ();
                    257: static rtx find_use_as_address ();
1.1.1.2   root      258: void dump_flow_info ();
1.1       root      259: 
                    260: /* Find basic blocks of the current function and perform data flow analysis.
                    261:    F is the first insn of the function and NREGS the number of register numbers
                    262:    in use.  */
                    263: 
                    264: void
                    265: flow_analysis (f, nregs, file)
                    266:      rtx f;
                    267:      int nregs;
                    268:      FILE *file;
                    269: {
                    270:   register rtx insn;
                    271:   register int i;
                    272:   register int max_uid = 0;
                    273: 
                    274:   /* Count the basic blocks.  Also find maximum insn uid value used.  */
                    275: 
                    276:   {
                    277:     register RTX_CODE prev_code = JUMP_INSN;
                    278:     register RTX_CODE code;
                    279: 
                    280:     for (insn = f, i = 0; insn; insn = NEXT_INSN (insn))
                    281:       {
                    282:        code = GET_CODE (insn);
                    283:        if (INSN_UID (insn) > max_uid)
                    284:          max_uid = INSN_UID (insn);
                    285:        if (code == CODE_LABEL
                    286:            || (prev_code != INSN && prev_code != CALL_INSN
                    287:                && prev_code != CODE_LABEL
                    288:                && (code == INSN || code == CALL_INSN || code == JUMP_INSN)))
                    289:          i++;
                    290:        if (code != NOTE)
                    291:          prev_code = code;
                    292:       }
                    293:   }
                    294: 
                    295:   /* Allocate some tables that last till end of compiling this function
                    296:      and some needed only in find_basic_blocks and life_analysis.  */
                    297: 
                    298:   n_basic_blocks = i;
                    299:   basic_block_head = (rtx *) oballoc (n_basic_blocks * sizeof (rtx));
                    300:   basic_block_end = (rtx *) oballoc (n_basic_blocks * sizeof (rtx));
                    301:   basic_block_drops_in = (char *) alloca (n_basic_blocks);
                    302:   basic_block_loop_depth = (short *) alloca (n_basic_blocks * sizeof (short));
                    303:   uid_block_number = (short *) alloca ((max_uid + 1) * sizeof (short));
1.1.1.2   root      304:   uid_volatile = (char *) alloca (max_uid + 1);
                    305:   bzero (uid_volatile, max_uid + 1);
1.1       root      306: 
                    307:   find_basic_blocks (f);
                    308:   life_analysis (f, nregs);
                    309:   if (file)
                    310:     dump_flow_info (file);
                    311: 
                    312:   basic_block_drops_in = 0;
                    313:   uid_block_number = 0;
                    314:   basic_block_loop_depth = 0;
                    315: }
                    316: 
                    317: /* Find all basic blocks of the function whose first insn is F.
                    318:    Store the correct data in the tables that describe the basic blocks,
                    319:    set up the chains of references for each CODE_LABEL, and
                    320:    delete any entire basic blocks that cannot be reached.  */
                    321: 
                    322: static void
                    323: find_basic_blocks (f)
                    324:      rtx f;
                    325: {
                    326:   register rtx insn;
                    327:   register int i;
                    328: 
                    329:   /* Initialize the ref chain of each label to 0.  */
                    330:   /* Record where all the blocks start and end and their depth in loops.  */
                    331:   /* For each insn, record the block it is in.  */
                    332: 
                    333:   {
                    334:     register RTX_CODE prev_code = JUMP_INSN;
                    335:     register RTX_CODE code;
                    336:     int depth = 1;
                    337: 
                    338:     for (insn = f, i = -1; insn; insn = NEXT_INSN (insn))
                    339:       {
                    340:        code = GET_CODE (insn);
                    341:        if (code == NOTE)
                    342:          {
                    343:            if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
                    344:              depth++;
                    345:            else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
                    346:              depth--;
                    347:          }
                    348:        else if (code == CODE_LABEL
                    349:                 || (prev_code != INSN && prev_code != CALL_INSN
                    350:                     && prev_code != CODE_LABEL
                    351:                     && (code == INSN || code == CALL_INSN || code == JUMP_INSN)))
                    352:          {
                    353:            basic_block_head[++i] = insn;
                    354:            basic_block_end[i] = insn;
                    355:            basic_block_loop_depth[i] = depth;
                    356:            if (code == CODE_LABEL)
                    357:              LABEL_REFS (insn) = insn;
                    358:          }
                    359:        else if (code == INSN || code == CALL_INSN || code == JUMP_INSN)
                    360:          basic_block_end[i] = insn;
                    361:        BLOCK_NUM (insn) = i;
                    362:        if (code != NOTE)
                    363:          prev_code = code;
                    364:       }
1.1.1.4   root      365:     if (i + 1 != n_basic_blocks)
                    366:       abort ();
1.1       root      367:   }
                    368: 
                    369:   /* Record which basic blocks control can drop in to.  */
                    370: 
                    371:   {
                    372:     register int i;
                    373:     for (i = 0; i < n_basic_blocks; i++)
                    374:       {
                    375:        register rtx insn = PREV_INSN (basic_block_head[i]);
1.1.1.2   root      376:        /* TEMP1 is used to avoid a bug in Sequent's compiler.  */
                    377:        register int temp1;
1.1       root      378:        while (insn && GET_CODE (insn) == NOTE)
                    379:          insn = PREV_INSN (insn);
1.1.1.2   root      380:        temp1 = insn && GET_CODE (insn) != BARRIER;
                    381:        basic_block_drops_in[i] = temp1;
1.1       root      382:       }
                    383:   }
                    384: 
                    385:   /* Now find which basic blocks can actually be reached
                    386:      and put all jump insns' LABEL_REFS onto the ref-chains
                    387:      of their target labels.  */
                    388: 
                    389:   if (n_basic_blocks > 0)
                    390:     {
                    391:       register char *block_live = (char *) alloca (n_basic_blocks);
                    392:       register char *block_marked = (char *) alloca (n_basic_blocks);
                    393:       int something_marked = 1;
                    394: 
                    395:       /* Initialize with just block 0 reachable and no blocks marked.  */
                    396: 
                    397:       bzero (block_live, n_basic_blocks);
                    398:       bzero (block_marked, n_basic_blocks);
                    399:       block_live[0] = 1;
                    400:       block_live_static = block_live;
                    401: 
                    402:       /* Pass over all blocks, marking each block that is reachable
                    403:         and has not yet been marked.
                    404:         Keep doing this until, in one pass, no blocks have been marked.
                    405:         Then blocks_live and blocks_marked are identical and correct.
                    406:         In addition, all jumps actually reachable have been marked.  */
                    407: 
                    408:       while (something_marked)
                    409:        {
                    410:          something_marked = 0;
                    411:          for (i = 0; i < n_basic_blocks; i++)
                    412:            if (block_live[i] && !block_marked[i])
                    413:              {
                    414:                block_marked[i] = 1;
                    415:                something_marked = 1;
                    416:                if (i + 1 < n_basic_blocks && basic_block_drops_in[i + 1])
                    417:                  block_live[i + 1] = 1;
                    418:                insn = basic_block_end[i];
                    419:                if (GET_CODE (insn) == JUMP_INSN)
                    420:                  mark_label_ref (PATTERN (insn), insn, 0);
                    421:              }
                    422:        }
                    423: 
                    424:       /* Now delete the code for any basic blocks that can't be reached.
                    425:         They can occur because jump_optimize does not recognize
                    426:         unreachable loops as unreachable.  */
                    427: 
                    428:       for (i = 0; i < n_basic_blocks; i++)
                    429:        if (!block_live[i])
                    430:          {
                    431:            insn = basic_block_head[i];
                    432:            while (1)
                    433:              {
1.1.1.2   root      434:                if (GET_CODE (insn) == BARRIER)
                    435:                  abort ();
1.1       root      436:                if (GET_CODE (insn) != NOTE)
                    437:                  {
                    438:                    PUT_CODE (insn, NOTE);
                    439:                    NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
                    440:                    NOTE_SOURCE_FILE (insn) = 0;
                    441:                  }
                    442:                if (insn == basic_block_end[i])
1.1.1.2   root      443:                  {
                    444:                    /* BARRIERs are between basic blocks, not part of one.
                    445:                       Delete a BARRIER if the preceding jump is deleted.
                    446:                       We cannot alter a BARRIER into a NOTE
                    447:                       because it is too short; but we can really delete
                    448:                       it because it is not part of a basic block.  */
                    449:                    if (NEXT_INSN (insn) != 0
                    450:                        && GET_CODE (NEXT_INSN (insn)) == BARRIER)
                    451:                      delete_insn (NEXT_INSN (insn));
                    452:                    break;
                    453:                  }
1.1       root      454:                insn = NEXT_INSN (insn);
                    455:              }
                    456:            /* Each time we delete some basic blocks,
                    457:               see if there is a jump around them that is
                    458:               being turned into a no-op.  If so, delete it.  */
                    459: 
                    460:            if (block_live[i - 1])
                    461:              {
                    462:                register int j;
                    463:                for (j = i; j < n_basic_blocks; j++)
                    464:                  if (block_live[j])
                    465:                    {
1.1.1.6   root      466:                      rtx label;
1.1       root      467:                      insn = basic_block_end[i - 1];
                    468:                      if (GET_CODE (insn) == JUMP_INSN
1.1.1.6   root      469:                          /* An unconditional jump is the only possibility
                    470:                             we must check for, since a conditional one
                    471:                             would make these blocks live.  */
                    472:                          && simplejump_p (insn)
                    473:                          && (label = XEXP (SET_SRC (PATTERN (insn)), 0), 1)
                    474:                          && INSN_UID (label) != 0
                    475:                          && BLOCK_NUM (label) == j)
1.1       root      476:                        {
                    477:                          PUT_CODE (insn, NOTE);
                    478:                          NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
                    479:                          NOTE_SOURCE_FILE (insn) = 0;
1.1.1.2   root      480:                          if (GET_CODE (NEXT_INSN (insn)) != BARRIER)
                    481:                            abort ();
                    482:                          delete_insn (NEXT_INSN (insn));
1.1       root      483:                        }
                    484:                      break;
                    485:                    }
                    486:              }
                    487:          }
                    488:     }
                    489: }
                    490: 
                    491: /* Check expression X for label references;
                    492:    if one is found, add INSN to the label's chain of references.
                    493: 
                    494:    CHECKDUP means check for and avoid creating duplicate references
                    495:    from the same insn.  Such duplicates do no serious harm but
                    496:    can slow life analysis.  CHECKDUP is set only when duplicates
                    497:    are likely.  */
                    498: 
                    499: static void
                    500: mark_label_ref (x, insn, checkdup)
                    501:      rtx x, insn;
                    502:      int checkdup;
                    503: {
                    504:   register RTX_CODE code = GET_CODE (x);
                    505:   register int i;
                    506:   register char *fmt;
                    507: 
                    508:   if (code == LABEL_REF)
                    509:     {
                    510:       register rtx label = XEXP (x, 0);
                    511:       register rtx y;
                    512:       if (GET_CODE (label) != CODE_LABEL)
1.1.1.4   root      513:        abort ();
1.1.1.2   root      514:       /* If the label was never emitted, this insn is junk,
                    515:         but avoid a crash trying to refer to BLOCK_NUM (label).
                    516:         This can happen as a result of a syntax error
                    517:         and a diagnostic has already been printed.  */
                    518:       if (INSN_UID (label) == 0)
                    519:        return;
1.1       root      520:       CONTAINING_INSN (x) = insn;
                    521:       /* if CHECKDUP is set, check for duplicate ref from same insn
                    522:         and don't insert.  */
                    523:       if (checkdup)
                    524:        for (y = LABEL_REFS (label); y != label; y = LABEL_NEXTREF (y))
                    525:          if (CONTAINING_INSN (y) == insn)
                    526:            return;
                    527:       LABEL_NEXTREF (x) = LABEL_REFS (label);
                    528:       LABEL_REFS (label) = x;
                    529:       block_live_static[BLOCK_NUM (label)] = 1;
                    530:       return;
                    531:     }
                    532: 
                    533:   fmt = GET_RTX_FORMAT (code);
                    534:   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
                    535:     {
                    536:       if (fmt[i] == 'e')
                    537:        mark_label_ref (XEXP (x, i), insn, 0);
                    538:       if (fmt[i] == 'E')
                    539:        {
                    540:          register int j;
                    541:          for (j = 0; j < XVECLEN (x, i); j++)
                    542:            mark_label_ref (XVECEXP (x, i, j), insn, 1);
                    543:        }
                    544:     }
                    545: }
                    546: 
                    547: /* Determine the which registers are live at the start of each
                    548:    basic block of the function whose first insn is F.
                    549:    NREGS is the number of registers used in F.
                    550:    We allocate the vector basic_block_live_at_start
                    551:    and the regsets that it points to, and fill them with the data.
                    552:    regset_size and regset_bytes are also set here.  */
                    553: 
                    554: static void
                    555: life_analysis (f, nregs)
                    556:      rtx f;
                    557:      int nregs;
                    558: {
                    559:   register regset tem;
                    560:   int first_pass;
                    561:   int changed;
                    562:   /* For each basic block, a bitmask of regs
                    563:      live on exit from the block.  */
                    564:   regset *basic_block_live_at_end;
                    565:   /* For each basic block, a bitmask of regs
                    566:      live on entry to a successor-block of this block.
                    567:      If this does not match basic_block_live_at_end,
                    568:      that must be updated, and the block must be rescanned.  */
                    569:   regset *basic_block_new_live_at_end;
                    570:   /* For each basic block, a bitmask of regs
                    571:      whose liveness at the end of the basic block
                    572:      can make a difference in which regs are live on entry to the block.
                    573:      These are the regs that are set within the basic block,
                    574:      possibly excluding those that are used after they are set.  */
                    575:   regset *basic_block_significant;
                    576:   register int i;
1.1.1.2   root      577:   rtx insn;
1.1       root      578: 
                    579:   max_regno = nregs;
                    580: 
                    581:   bzero (regs_ever_live, sizeof regs_ever_live);
                    582: 
                    583:   /* Allocate and zero out many data structures
                    584:      that will record the data from lifetime analysis.  */
                    585: 
                    586:   allocate_for_life_analysis ();
                    587: 
                    588:   reg_next_use = (rtx *) alloca (nregs * sizeof (rtx));
                    589:   bzero (reg_next_use, nregs * sizeof (rtx));
                    590: 
                    591:   /* Set up several regset-vectors used internally within this function.
                    592:      Their meanings are documented above, with their declarations.  */
                    593: 
                    594:   basic_block_live_at_end = (regset *) alloca (n_basic_blocks * sizeof (regset));
                    595:   tem = (regset) alloca (n_basic_blocks * regset_bytes);
                    596:   bzero (tem, n_basic_blocks * regset_bytes);
                    597:   init_regset_vector (basic_block_live_at_end, tem, n_basic_blocks, regset_bytes);
                    598: 
                    599:   basic_block_new_live_at_end = (regset *) alloca (n_basic_blocks * sizeof (regset));
                    600:   tem = (regset) alloca (n_basic_blocks * regset_bytes);
                    601:   bzero (tem, n_basic_blocks * regset_bytes);
                    602:   init_regset_vector (basic_block_new_live_at_end, tem, n_basic_blocks, regset_bytes);
                    603: 
                    604:   basic_block_significant = (regset *) alloca (n_basic_blocks * sizeof (regset));
                    605:   tem = (regset) alloca (n_basic_blocks * regset_bytes);
                    606:   bzero (tem, n_basic_blocks * regset_bytes);
                    607:   init_regset_vector (basic_block_significant, tem, n_basic_blocks, regset_bytes);
                    608: 
1.1.1.4   root      609:   /* Record which insns refer to any volatile memory
1.1.1.9   root      610:      or for any reason can't be deleted just because they are dead stores.
                    611:      Also, delete any insns that copy a register to itself. */
1.1.1.2   root      612: 
                    613:   for (insn = f; insn; insn = NEXT_INSN (insn))
1.1.1.4   root      614:     {
                    615:       enum rtx_code code1 = GET_CODE (insn);
                    616:       if (code1 == CALL_INSN)
                    617:        INSN_VOLATILE (insn) = 1;
                    618:       else if (code1 == INSN || code1 == JUMP_INSN)
                    619:        {
1.1.1.9   root      620:          if (GET_CODE (PATTERN (insn)) == SET
                    621:              && GET_CODE (SET_DEST (PATTERN (insn))) == REG
                    622:              && GET_CODE (SET_SRC (PATTERN (insn))) == REG
                    623:              && REGNO (SET_DEST (PATTERN (insn))) ==
                    624:                        REGNO (SET_SRC (PATTERN (insn))))
                    625:            {
                    626:              PUT_CODE (insn, NOTE);
                    627:              NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
                    628:              NOTE_SOURCE_FILE (insn) = 0;
                    629:            }
                    630:          else if (GET_CODE (PATTERN (insn)) != USE)
1.1.1.4   root      631:            INSN_VOLATILE (insn) = volatile_refs_p (PATTERN (insn));
                    632:        }
1.1.1.6   root      633:       /* A SET that makes space on the stack cannot be dead.
1.1.1.10  root      634:         (Such SETs occur only for allocating variable-size data,
                    635:         so they will always have a PLUS or MINUS according to the
                    636:         direction of stack growth.)
1.1.1.6   root      637:         Even if this function never uses this stack pointer value,
                    638:         signal handlers do!  */
                    639:       else if (code1 == INSN && GET_CODE (PATTERN (insn)) == SET
                    640:               && SET_DEST (PATTERN (insn)) == stack_pointer_rtx
                    641: #ifdef STACK_GROWS_DOWNWARD
                    642:               && GET_CODE (SET_SRC (PATTERN (insn))) == MINUS
                    643: #else
                    644:               && GET_CODE (SET_SRC (PATTERN (insn))) == PLUS
                    645: #endif
                    646:               && XEXP (SET_SRC (PATTERN (insn)), 0) == stack_pointer_rtx)
                    647:        INSN_VOLATILE (insn) = 1;
1.1.1.4   root      648:     }
1.1.1.2   root      649: 
                    650:   if (n_basic_blocks > 0)
                    651: #ifdef EXIT_IGNORE_STACK
                    652:     if (! (EXIT_IGNORE_STACK) || ! frame_pointer_needed)
                    653: #endif
                    654:       {
                    655:        /* If exiting needs the right stack value,
                    656:           consider the stack pointer live at the end of the function.  */
                    657:        basic_block_live_at_end[n_basic_blocks - 1]
                    658:          [STACK_POINTER_REGNUM / REGSET_ELT_BITS]
                    659:            |= 1 << (STACK_POINTER_REGNUM % REGSET_ELT_BITS);
                    660:        basic_block_new_live_at_end[n_basic_blocks - 1]
                    661:          [STACK_POINTER_REGNUM / REGSET_ELT_BITS]
                    662:            |= 1 << (STACK_POINTER_REGNUM % REGSET_ELT_BITS);
                    663:       }
                    664: 
1.1       root      665:   /* Propagate life info through the basic blocks
                    666:      around the graph of basic blocks.
                    667: 
                    668:      This is a relaxation process: each time a new register
                    669:      is live at the end of the basic block, we must scan the block
                    670:      to determine which registers are, as a consequence, live at the beginning
                    671:      of that block.  These registers must then be marked live at the ends
                    672:      of all the blocks that can transfer control to that block.
                    673:      The process continues until it reaches a fixed point.  */
                    674: 
                    675:   first_pass = 1;
                    676:   changed = 1;
                    677:   while (changed)
                    678:     {
                    679:       changed = 0;
                    680:       for (i = n_basic_blocks - 1; i >= 0; i--)
                    681:        {
                    682:          int consider = first_pass;
                    683:          int must_rescan = first_pass;
                    684:          register int j;
                    685: 
                    686:          /* Set CONSIDER if this block needs thinking about at all
                    687:             (that is, if the regs live now at the end of it
                    688:             are not the same as were live at the end of it when
                    689:             we last thought about it).
                    690:             Set must_rescan if it needs to be thought about
                    691:             instruction by instruction (that is, if any additional
                    692:             reg that is live at the end now but was not live there before
                    693:             is one of the significant regs of this basic block).  */
                    694: 
                    695:          for (j = 0; j < regset_size; j++)
                    696:            {
                    697:              register int x = basic_block_new_live_at_end[i][j]
                    698:                      & ~basic_block_live_at_end[i][j];
                    699:              if (x)
                    700:                consider = 1;
                    701:              if (x & basic_block_significant[i][j])
                    702:                {
                    703:                  must_rescan = 1;
                    704:                  consider = 1;
                    705:                  break;
                    706:                }
                    707:            }
                    708: 
                    709:          if (! consider)
                    710:            continue;
                    711: 
                    712:          /* The live_at_start of this block may be changing,
                    713:             so another pass will be required after this one.  */
                    714:          changed = 1;
                    715: 
                    716:          if (! must_rescan)
                    717:            {
                    718:              /* No complete rescan needed;
                    719:                 just record those variables newly known live at end
                    720:                 as live at start as well.  */
                    721:              for (j = 0; j < regset_size; j++)
                    722:                {
                    723:                  register int x = basic_block_new_live_at_end[i][j]
                    724:                        & ~basic_block_live_at_end[i][j];
                    725:                  basic_block_live_at_start[i][j] |= x;
                    726:                  basic_block_live_at_end[i][j] |= x;
                    727:                }
                    728:            }
                    729:          else
                    730:            {
                    731:              /* Update the basic_block_live_at_start
                    732:                 by propagation backwards through the block.  */
                    733:              bcopy (basic_block_new_live_at_end[i],
                    734:                     basic_block_live_at_end[i], regset_bytes);
                    735:              bcopy (basic_block_live_at_end[i],
                    736:                     basic_block_live_at_start[i], regset_bytes);
                    737:              propagate_block (basic_block_live_at_start[i],
                    738:                               basic_block_head[i], basic_block_end[i], 0,
                    739:                               first_pass ? basic_block_significant[i] : 0,
                    740:                               i);
                    741:            }
                    742: 
                    743:          {
                    744:            register rtx jump, head;
                    745:            /* Update the basic_block_new_live_at_end's of the block
                    746:               that falls through into this one (if any).  */
                    747:            head = basic_block_head[i];
                    748:            jump = PREV_INSN (head);
                    749:            if (basic_block_drops_in[i])
                    750:              {
                    751:                register from_block = BLOCK_NUM (jump);
                    752:                register int j;
                    753:                for (j = 0; j < regset_size; j++)
                    754:                  basic_block_new_live_at_end[from_block][j]
                    755:                    |= basic_block_live_at_start[i][j];
                    756:              }
                    757:            /* Update the basic_block_new_live_at_end's of
                    758:               all the blocks that jump to this one.  */
                    759:            if (GET_CODE (head) == CODE_LABEL)
                    760:              for (jump = LABEL_REFS (head);
                    761:                   jump != head;
                    762:                   jump = LABEL_NEXTREF (jump))
                    763:                {
                    764:                  register from_block = BLOCK_NUM (CONTAINING_INSN (jump));
                    765:                  register int j;
                    766:                  for (j = 0; j < regset_size; j++)
                    767:                    basic_block_new_live_at_end[from_block][j]
                    768:                      |= basic_block_live_at_start[i][j];
                    769:                }
                    770:          }
                    771:        }
                    772:       first_pass = 0;
                    773:     }
                    774: 
1.1.1.5   root      775: #if 0 /* This seems unnecessary; life at start of function shouldn't
                    776:         mean that the reg is live in more than one basic block.  */
                    777: 
1.1.1.2   root      778:   /* Process the regs live at the beginning of the function.
                    779:      Mark them as not local to any one basic block.  */
                    780: 
                    781:   if (n_basic_blocks > 0)
                    782:     for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
                    783:       if (basic_block_live_at_start[0][i / REGSET_ELT_BITS]
                    784:          & (1 << (i % REGSET_ELT_BITS)))
1.1.1.4   root      785:        reg_basic_block[i] = REG_BLOCK_GLOBAL;
1.1.1.5   root      786: #endif
1.1.1.2   root      787: 
1.1       root      788:   /* Now the life information is accurate.
                    789:      Make one more pass over each basic block
                    790:      to delete dead stores, create autoincrement addressing
                    791:      and record how many times each register is used, is set, or dies.
                    792: 
                    793:      To save time, we operate directly in basic_block_live_at_end[i],
                    794:      thus destroying it (in fact, converting it into a copy of
                    795:      basic_block_live_at_start[i]).  This is ok now because
                    796:      basic_block_live_at_end[i] is no longer used past this point.  */
                    797: 
                    798:   for (i = 0; i < n_basic_blocks; i++)
                    799:     {
                    800:       propagate_block (basic_block_live_at_end[i],
                    801:                       basic_block_head[i], basic_block_end[i], 1, 0, i);
                    802:     }
                    803: }
                    804: 
                    805: /* Subroutines of life analysis.  */
                    806: 
                    807: /* Allocate the permanent data structures that represent the results
                    808:    of life analysis.  Not static since used also for stupid life analysis.  */
                    809: 
                    810: void
                    811: allocate_for_life_analysis ()
                    812: {
                    813:   register int i;
                    814:   register regset tem;
                    815: 
                    816:   regset_size = ((max_regno + REGSET_ELT_BITS - 1) / REGSET_ELT_BITS);
                    817:   regset_bytes = regset_size * sizeof (*(regset)0);
                    818: 
                    819:   reg_n_refs = (short *) oballoc (max_regno * sizeof (short));
                    820:   bzero (reg_n_refs, max_regno * sizeof (short));
                    821: 
                    822:   reg_n_sets = (short *) oballoc (max_regno * sizeof (short));
                    823:   bzero (reg_n_sets, max_regno * sizeof (short));
                    824: 
                    825:   reg_n_deaths = (short *) oballoc (max_regno * sizeof (short));
                    826:   bzero (reg_n_deaths, max_regno * sizeof (short));
                    827: 
                    828:   reg_live_length = (int *) oballoc (max_regno * sizeof (int));
                    829:   bzero (reg_live_length, max_regno * sizeof (int));
                    830: 
1.1.1.12! root      831:   reg_n_calls_crossed = (int *) oballoc (max_regno * sizeof (int));
        !           832:   bzero (reg_n_calls_crossed, max_regno * sizeof (int));
1.1       root      833: 
                    834:   reg_basic_block = (short *) oballoc (max_regno * sizeof (short));
                    835:   for (i = 0; i < max_regno; i++)
1.1.1.4   root      836:     reg_basic_block[i] = REG_BLOCK_UNKNOWN;
1.1       root      837: 
                    838:   basic_block_live_at_start = (regset *) oballoc (n_basic_blocks * sizeof (regset));
                    839:   tem = (regset) oballoc (n_basic_blocks * regset_bytes);
                    840:   bzero (tem, n_basic_blocks * regset_bytes);
                    841:   init_regset_vector (basic_block_live_at_start, tem, n_basic_blocks, regset_bytes);
1.1.1.2   root      842: 
                    843:   regs_live_at_setjmp = (regset) oballoc (regset_bytes);
                    844:   bzero (regs_live_at_setjmp, regset_bytes);
1.1       root      845: }
                    846: 
                    847: /* Make each element of VECTOR point at a regset,
                    848:    taking the space for all those regsets from SPACE.
                    849:    SPACE is of type regset, but it is really as long as NELTS regsets.
                    850:    BYTES_PER_ELT is the number of bytes in one regset.  */
                    851: 
                    852: static void
                    853: init_regset_vector (vector, space, nelts, bytes_per_elt)
                    854:      regset *vector;
                    855:      regset space;
                    856:      int nelts;
                    857:      int bytes_per_elt;
                    858: {
                    859:   register int i;
                    860:   register regset p = space;
                    861: 
                    862:   for (i = 0; i < nelts; i++)
                    863:     {
                    864:       vector[i] = p;
                    865:       p += bytes_per_elt / sizeof (*p);
                    866:     }
                    867: }
                    868: 
                    869: /* Compute the registers live at the beginning of a basic block
                    870:    from those live at the end.
                    871: 
                    872:    When called, OLD contains those live at the end.
                    873:    On return, it contains those live at the beginning.
                    874:    FIRST and LAST are the first and last insns of the basic block.
                    875: 
                    876:    FINAL is nonzero if we are doing the final pass which is not
                    877:    for computing the life info (since that has already been done)
                    878:    but for acting on it.  On this pass, we delete dead stores,
                    879:    set up the logical links and dead-variables lists of instructions,
                    880:    and merge instructions for autoincrement and autodecrement addresses.
                    881: 
                    882:    SIGNIFICANT is nonzero only the first time for each basic block.
                    883:    If it is nonzero, it points to a regset in which we store
                    884:    a 1 for each register that is set within the block.
                    885: 
                    886:    BNUM is the number of the basic block.  */
                    887: 
                    888: static void
                    889: propagate_block (old, first, last, final, significant, bnum)
                    890:      register regset old;
                    891:      rtx first;
                    892:      rtx last;
                    893:      int final;
                    894:      regset significant;
                    895:      int bnum;
                    896: {
                    897:   register rtx insn;
                    898:   rtx prev;
                    899:   regset live;
                    900:   regset dead;
                    901: 
                    902:   /* The following variables are used only if FINAL is nonzero.  */
                    903:   /* This vector gets one element for each reg that has been live
                    904:      at any point in the basic block that has been scanned so far.
                    905:      SOMETIMES_MAX says how many elements are in use so far.
                    906:      In each element, OFFSET is the byte-number within a regset
                    907:      for the register described by the element, and BIT is a mask
                    908:      for that register's bit within the byte.  */
                    909:   register struct foo { short offset; short bit; } *regs_sometimes_live;
                    910:   int sometimes_max = 0;
                    911:   /* This regset has 1 for each reg that we have seen live so far.
                    912:      It and REGS_SOMETIMES_LIVE are updated together.  */
                    913:   regset maxlive;
                    914: 
                    915:   loop_depth = basic_block_loop_depth[bnum];
                    916: 
                    917:   dead = (regset) alloca (regset_bytes);
                    918:   live = (regset) alloca (regset_bytes);
                    919: 
                    920:   if (final)
                    921:     {
                    922:       register int i, offset, bit;
                    923: 
                    924:       maxlive = (regset) alloca (regset_bytes);
                    925:       bcopy (old, maxlive, regset_bytes);
                    926:       regs_sometimes_live
                    927:        = (struct foo *) alloca (max_regno * sizeof (struct foo));
                    928: 
                    929:       /* Process the regs live at the end of the block.
                    930:         Enter them in MAXLIVE and REGS_SOMETIMES_LIVE.
                    931:         Also mark them as not local to any one basic block.  */
                    932: 
                    933:       for (offset = 0, i = 0; offset < regset_size; offset++)
                    934:        for (bit = 1; bit; bit <<= 1, i++)
                    935:          {
                    936:            if (i == max_regno)
                    937:              break;
                    938:            if (old[offset] & bit)
                    939:              {
1.1.1.4   root      940:                reg_basic_block[i] = REG_BLOCK_GLOBAL;
1.1       root      941:                regs_sometimes_live[sometimes_max].offset = offset;
                    942:                regs_sometimes_live[sometimes_max].bit = i % REGSET_ELT_BITS;
                    943:                sometimes_max++;
                    944:              }
                    945:          }
                    946:     }
                    947: 
                    948:   /* Scan the block an insn at a time from end to beginning.  */
                    949: 
                    950:   for (insn = last; ; insn = prev)
                    951:     {
                    952:       prev = PREV_INSN (insn);
                    953: 
1.1.1.2   root      954:       /* If this is a call to `setjmp' et al,
                    955:         warn if any non-volatile datum is live.  */
                    956: 
                    957:       if (final && GET_CODE (insn) == NOTE
                    958:          && NOTE_LINE_NUMBER (insn) == NOTE_INSN_SETJMP)
                    959:        {
                    960:          int i;
                    961:          for (i = 0; i < regset_size; i++)
                    962:            regs_live_at_setjmp[i] |= old[i];
1.1       root      963:        }
                    964: 
                    965:       /* Update the life-status of regs for this insn.
                    966:         First DEAD gets which regs are set in this insn
                    967:         then LIVE gets which regs are used in this insn.
                    968:         Then the regs live before the insn
                    969:         are those live after, with DEAD regs turned off,
                    970:         and then LIVE regs turned on.  */
                    971: 
                    972:       if (GET_CODE (insn) == INSN
                    973:          || GET_CODE (insn) == JUMP_INSN
                    974:          || GET_CODE (insn) == CALL_INSN)
                    975:        {
                    976:          register int i;
1.1.1.2   root      977:          rtx note = find_reg_note (insn, REG_RETVAL, 0);
                    978: 
1.1       root      979:          /* If an instruction consists of just dead store(s) on final pass,
                    980:             "delete" it by turning it into a NOTE of type NOTE_INSN_DELETED.
                    981:             We could really delete it with delete_insn, but that
                    982:             can cause trouble for first or last insn in a basic block.  */
1.1.1.2   root      983:          if (final && insn_dead_p (PATTERN (insn), old, 1)
                    984:              /* Don't delete something that refers to volatile storage!  */
                    985:              && ! INSN_VOLATILE (insn))
1.1       root      986:            {
1.1.1.10  root      987:              rtx oldpat = PATTERN (insn);
1.1       root      988:              PUT_CODE (insn, NOTE);
                    989:              NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
                    990:              NOTE_SOURCE_FILE (insn) = 0;
1.1.1.2   root      991:              /* If this insn is copying the return value from a library call,
                    992:                 delete the entire library call.  */
1.1.1.10  root      993:              if (note && libcall_dead_p (oldpat, old))
1.1.1.2   root      994:                {
                    995:                  rtx first = XEXP (note, 0);
                    996:                  rtx prev = insn;
1.1.1.9   root      997:                  while (INSN_DELETED_P (first))
1.1.1.2   root      998:                    first = NEXT_INSN (first);
                    999:                  while (prev != first)
                   1000:                    {
                   1001:                      prev = PREV_INSN (prev);
                   1002:                      PUT_CODE (prev, NOTE);
                   1003:                      NOTE_LINE_NUMBER (prev) = NOTE_INSN_DELETED;
                   1004:                      NOTE_SOURCE_FILE (prev) = 0;
                   1005:                    }
                   1006:                }
1.1       root     1007:              goto flushed;
                   1008:            }
1.1.1.2   root     1009: 
                   1010:          for (i = 0; i < regset_size; i++)
1.1       root     1011:            {
1.1.1.2   root     1012:              dead[i] = 0;      /* Faster than bzero here */
                   1013:              live[i] = 0;      /* since regset_size is usually small */
                   1014:            }
1.1       root     1015: 
1.1.1.2   root     1016:          /* See if this is an increment or decrement that can be
                   1017:             merged into a following memory address.  */
                   1018: #ifdef AUTO_INC_DEC
                   1019:          {
                   1020:            register rtx x = PATTERN (insn);
                   1021:            /* Does this instruction increment or decrement a register?  */
                   1022:            if (final && GET_CODE (x) == SET
                   1023:                && GET_CODE (SET_DEST (x)) == REG
                   1024:                && (GET_CODE (SET_SRC (x)) == PLUS
                   1025:                    || GET_CODE (SET_SRC (x)) == MINUS)
                   1026:                && XEXP (SET_SRC (x), 0) == SET_DEST (x)
                   1027:                && GET_CODE (XEXP (SET_SRC (x), 1)) == CONST_INT
                   1028:                /* Ok, look for a following memory ref we can combine with.
                   1029:                   If one is found, change the memory ref to a PRE_INC
                   1030:                   or PRE_DEC, cancel this insn, and return 1.
                   1031:                   Return 0 if nothing has been done.  */
                   1032:                && try_pre_increment_1 (insn))
                   1033:              goto flushed;
                   1034:          }
                   1035: #endif /* AUTO_INC_DEC */
1.1       root     1036: 
1.1.1.2   root     1037:          /* If this is not the final pass, and this insn is copying the
                   1038:             value of a library call and it's dead, don't scan the
                   1039:             insns that perform the library call, so that the call's
                   1040:             arguments are not marked live.  */
1.1.1.10  root     1041:          if (note && insn_dead_p (PATTERN (insn), old, 1)
                   1042:              && libcall_dead_p (PATTERN (insn), old))
1.1.1.3   root     1043:            {
1.1.1.4   root     1044:              /* Mark the dest reg as `significant'.  */
                   1045:              mark_set_regs (old, dead, PATTERN (insn), 0, significant);
                   1046: 
1.1.1.3   root     1047:              insn = XEXP (note, 0);
                   1048:              prev = PREV_INSN (insn);
                   1049:            }
1.1.1.9   root     1050:          else if (GET_CODE (PATTERN (insn)) == SET
                   1051:                   && SET_DEST (PATTERN (insn)) == stack_pointer_rtx
1.1.1.4   root     1052:                   && GET_CODE (SET_SRC (PATTERN (insn))) == PLUS
                   1053:                   && XEXP (SET_SRC (PATTERN (insn)), 0) == stack_pointer_rtx
                   1054:                   && GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 1)) == CONST_INT)
1.1.1.10  root     1055:            /* We have an insn to pop a constant amount off the stack.
                   1056:               (Such insns use PLUS regardless of the direction of the stack,
                   1057:               and any insn to adjust the stack by a constant is always a pop.)
                   1058:               These insns, if not dead stores, have no effect on life.  */
1.1.1.4   root     1059:            ;
1.1.1.2   root     1060:          else
                   1061:            {
                   1062:              /* LIVE gets the regs used in INSN; DEAD gets those set by it.  */
1.1       root     1063:              mark_set_regs (old, dead, PATTERN (insn), final ? insn : 0,
                   1064:                             significant);
1.1.1.2   root     1065:              mark_used_regs (old, live, PATTERN (insn), final, insn);
1.1       root     1066: 
                   1067:              /* Update OLD for the registers used or set.  */
                   1068:              for (i = 0; i < regset_size; i++)
                   1069:                {
                   1070:                  old[i] &= ~dead[i];
                   1071:                  old[i] |= live[i];
                   1072:                }
                   1073: 
1.1.1.2   root     1074:              if (GET_CODE (insn) == CALL_INSN)
                   1075:                {
                   1076:                  register int i;
                   1077: 
                   1078:                  /* Each call clobbers all call-clobbered regs.
                   1079:                     Note that the function-value reg is one of these, and
                   1080:                     mark_set_regs has already had a chance to handle it.  */
                   1081:                  for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
                   1082:                    if (call_used_regs[i])
1.1.1.9   root     1083:                      dead[i / REGSET_ELT_BITS] |=
                   1084:                        (1 << (i % REGSET_ELT_BITS));
1.1.1.2   root     1085: 
                   1086:                  /* The stack ptr is used (honorarily) by a CALL insn.  */
1.1.1.9   root     1087:                  live[STACK_POINTER_REGNUM / REGSET_ELT_BITS]
1.1.1.2   root     1088:                    |= (1 << (STACK_POINTER_REGNUM % REGSET_ELT_BITS));
1.1.1.9   root     1089:                }
1.1.1.2   root     1090: 
1.1.1.9   root     1091:              /* Update OLD for the registers used or set.  */
                   1092:              for (i = 0; i < regset_size; i++)
                   1093:                {
                   1094:                  old[i] &= ~dead[i];
                   1095:                  old[i] |= live[i];
                   1096:                }
                   1097: 
                   1098:              if (GET_CODE (insn) == CALL_INSN && final)
                   1099:                {
                   1100:                  /* Any regs live at the time of a call instruction
                   1101:                     must not go in a register clobbered by calls.
                   1102:                     Find all regs now live and record this for them.  */
                   1103: 
                   1104:                  register struct foo *p = regs_sometimes_live;
                   1105: 
                   1106:                  for (i = 0; i < sometimes_max; i++, p++)
                   1107:                    if (old[p->offset] & (1 << p->bit))
1.1.1.12! root     1108:                      reg_n_calls_crossed[p->offset * REGSET_ELT_BITS + p->bit]+= 1;
1.1.1.2   root     1109:                }
                   1110:            }
                   1111: 
                   1112:          /* On final pass, add any additional sometimes-live regs
                   1113:             into MAXLIVE and REGS_SOMETIMES_LIVE.
                   1114:             Also update counts of how many insns each reg is live at.  */
1.1       root     1115: 
1.1.1.2   root     1116:          if (final)
                   1117:            {
                   1118:              for (i = 0; i < regset_size; i++)
1.1       root     1119:                {
1.1.1.2   root     1120:                  register int diff = live[i] & ~maxlive[i];
1.1       root     1121: 
1.1.1.2   root     1122:                  if (diff)
                   1123:                    {
                   1124:                      register int regno;
                   1125:                      maxlive[i] |= diff;
                   1126:                      for (regno = 0; diff && regno < REGSET_ELT_BITS; regno++)
                   1127:                        if (diff & (1 << regno))
                   1128:                          {
                   1129:                            regs_sometimes_live[sometimes_max].offset = i;
                   1130:                            regs_sometimes_live[sometimes_max].bit = regno;
                   1131:                            diff &= ~ (1 << regno);
                   1132:                            sometimes_max++;
                   1133:                          }
                   1134:                    }
                   1135:                }
1.1       root     1136: 
1.1.1.2   root     1137:              {
                   1138:                register struct foo *p = regs_sometimes_live;
                   1139:                for (i = 0; i < sometimes_max; i++, p++)
1.1       root     1140:                  {
1.1.1.2   root     1141:                    if (old[p->offset] & (1 << p->bit))
                   1142:                      reg_live_length[p->offset * REGSET_ELT_BITS + p->bit]++;
1.1       root     1143:                  }
1.1.1.2   root     1144:              }
1.1       root     1145:            }
                   1146:        }
1.1.1.2   root     1147:     flushed: ;
1.1       root     1148:       if (insn == first)
                   1149:        break;
                   1150:     }
                   1151: }
                   1152: 
                   1153: /* Return 1 if X (the body of an insn, or part of it) is just dead stores
                   1154:    (SET expressions whose destinations are registers dead after the insn).
                   1155:    NEEDED is the regset that says which regs are alive after the insn.  */
                   1156: 
                   1157: static int
1.1.1.2   root     1158: insn_dead_p (x, needed, strict_low_ok)
1.1       root     1159:      rtx x;
                   1160:      regset needed;
1.1.1.2   root     1161:      int strict_low_ok;
1.1       root     1162: {
                   1163:   register RTX_CODE code = GET_CODE (x);
1.1.1.2   root     1164: #if 0
1.1       root     1165:   /* Make sure insns to set the stack pointer are never deleted.  */
                   1166:   needed[STACK_POINTER_REGNUM / REGSET_ELT_BITS]
                   1167:     |= 1 << (STACK_POINTER_REGNUM % REGSET_ELT_BITS);
1.1.1.2   root     1168: #endif
                   1169: 
                   1170:   /* If setting something that's a reg or part of one,
                   1171:      see if that register's altered value will be live.  */
                   1172: 
                   1173:   if (code == SET)
1.1       root     1174:     {
1.1.1.2   root     1175:       register rtx r = SET_DEST (x);
                   1176:       /* A SET that is a subroutine call cannot be dead.  */
                   1177:       if (GET_CODE (SET_SRC (x)) == CALL)
                   1178:        return 0;
                   1179:       while (GET_CODE (r) == SUBREG
                   1180:             || (strict_low_ok && GET_CODE (r) == STRICT_LOW_PART)
                   1181:             || GET_CODE (r) == ZERO_EXTRACT
                   1182:             || GET_CODE (r) == SIGN_EXTRACT)
                   1183:        r = SUBREG_REG (r);
                   1184:       if (GET_CODE (r) == REG)
                   1185:        {
                   1186:          register int regno = REGNO (r);
                   1187:          register int offset = regno / REGSET_ELT_BITS;
                   1188:          register int bit = 1 << (regno % REGSET_ELT_BITS);
1.1.1.11  root     1189:          return (! (regno < FIRST_PSEUDO_REGISTER && global_regs[regno])
                   1190:                  && (needed[offset] & bit) == 0);
1.1.1.2   root     1191:        }
1.1       root     1192:     }
1.1.1.2   root     1193:   /* If performing several activities,
                   1194:      insn is dead if each activity is individually dead.
                   1195:      Also, CLOBBERs and USEs can be ignored; a CLOBBER or USE
                   1196:      that's inside a PARALLEL doesn't make the insn worth keeping.  */
                   1197:   else if (code == PARALLEL)
1.1       root     1198:     {
                   1199:       register int i = XVECLEN (x, 0);
                   1200:       for (i--; i >= 0; i--)
1.1.1.2   root     1201:        {
                   1202:          rtx elt = XVECEXP (x, 0, i);
                   1203:          if (!insn_dead_p (elt, needed, strict_low_ok)
                   1204:              && GET_CODE (elt) != CLOBBER
                   1205:              && GET_CODE (elt) != USE)
                   1206:            return 0;
                   1207:        }
1.1       root     1208:       return 1;
                   1209:     }
1.1.1.2   root     1210:   /* We do not check CLOBBER or USE here.
                   1211:      An insn consisting of just a CLOBBER or just a USE
                   1212:      should not be deleted.  */
1.1       root     1213:   return 0;
                   1214: }
                   1215: 
1.1.1.10  root     1216: /* If X is the last insn in a libcall, and assuming X is dead,
                   1217:    return 1 if the entire library call is dead.
                   1218:    This is true if the source of X is a dead register
                   1219:    (as well as the destination, which we tested already).
                   1220:    If this insn doesn't just copy a register, then we don't
                   1221:    have an ordinary libcall.  In that case, cse could not have
                   1222:    managed to substitute the source for the dest later on,
                   1223:    so we can assume the libcall is dead.  */
                   1224: 
                   1225: static int
                   1226: libcall_dead_p (x, needed)
                   1227:      rtx x;
                   1228:      regset needed;
                   1229: {
                   1230:   register RTX_CODE code = GET_CODE (x);
                   1231: 
                   1232:   if (code == SET)
                   1233:     {
                   1234:       register rtx r = SET_SRC (x);
                   1235:       if (GET_CODE (r) == REG)
                   1236:        {
                   1237:          register int regno = REGNO (r);
                   1238:          register int offset = regno / REGSET_ELT_BITS;
                   1239:          register int bit = 1 << (regno % REGSET_ELT_BITS);
                   1240:          return (needed[offset] & bit) == 0;
                   1241:        }
                   1242:     }
                   1243:   return 1;
                   1244: }
                   1245: 
1.1.1.2   root     1246: /* Return 1 if register REGNO was used before it was set.
                   1247:    In other words, if it is live at function entry.  */
1.1       root     1248: 
1.1.1.2   root     1249: int
                   1250: regno_uninitialized (regno)
1.1       root     1251:      int regno;
                   1252: {
1.1.1.11  root     1253:   if (n_basic_blocks == 0)
                   1254:     return 0;
                   1255: 
1.1.1.2   root     1256:   return (basic_block_live_at_start[0][regno / REGSET_ELT_BITS]
                   1257:          & (1 << (regno % REGSET_ELT_BITS)));
                   1258: }
                   1259: 
                   1260: /* 1 if register REGNO was alive at a place where `setjmp' was called
                   1261:    and was set more than once.  Such regs may be clobbered by `longjmp'.  */
                   1262: 
                   1263: int
                   1264: regno_clobbered_at_setjmp (regno)
                   1265:      int regno;
                   1266: {
                   1267:   return (reg_n_sets[regno] > 1
                   1268:          && (regs_live_at_setjmp[regno / REGSET_ELT_BITS]
                   1269:              & (1 << (regno % REGSET_ELT_BITS))));
1.1       root     1270: }
                   1271: 
                   1272: /* Process the registers that are set within X.
                   1273:    Their bits are set to 1 in the regset DEAD,
                   1274:    because they are dead prior to this insn.
                   1275: 
                   1276:    If INSN is nonzero, it is the insn being processed
                   1277:    and the fact that it is nonzero implies this is the FINAL pass
                   1278:    in propagate_block.  In this case, various info about register
                   1279:    usage is stored, LOG_LINKS fields of insns are set up.  */
                   1280: 
                   1281: static void mark_set_1 ();
                   1282: 
                   1283: static void
                   1284: mark_set_regs (needed, dead, x, insn, significant)
                   1285:      regset needed;
                   1286:      regset dead;
                   1287:      rtx x;
                   1288:      rtx insn;
                   1289:      regset significant;
                   1290: {
                   1291:   register RTX_CODE code = GET_CODE (x);
                   1292: 
                   1293:   if (code == SET || code == CLOBBER)
                   1294:     mark_set_1 (needed, dead, x, insn, significant);
                   1295:   else if (code == PARALLEL)
                   1296:     {
                   1297:       register int i;
                   1298:       for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
                   1299:        {
                   1300:          code = GET_CODE (XVECEXP (x, 0, i));
                   1301:          if (code == SET || code == CLOBBER)
                   1302:            mark_set_1 (needed, dead, XVECEXP (x, 0, i), insn, significant);
                   1303:        }
                   1304:     }
                   1305: }
                   1306: 
                   1307: /* Process a single SET rtx, X.  */
                   1308: 
                   1309: static void
                   1310: mark_set_1 (needed, dead, x, insn, significant)
                   1311:      regset needed;
                   1312:      regset dead;
                   1313:      rtx x;
                   1314:      rtx insn;
                   1315:      regset significant;
                   1316: {
                   1317:   register int regno;
                   1318:   register rtx reg = SET_DEST (x);
                   1319: 
1.1.1.2   root     1320:   if (reg == 0)
                   1321:     return;
                   1322: 
1.1       root     1323:   if (GET_CODE (reg) == SUBREG)
                   1324:     {
                   1325:       /* Modifying just one hardware register
                   1326:         of a multi-register value does not count as "setting"
                   1327:         for live-dead analysis.  Parts of the previous value
                   1328:         might still be significant below this insn.  */
                   1329:       if (REG_SIZE (SUBREG_REG (reg)) > REG_SIZE (reg))
                   1330:        return;
                   1331: 
                   1332:       reg = SUBREG_REG (reg);
                   1333:     }
                   1334: 
                   1335:   if (GET_CODE (reg) == REG
                   1336:       && (regno = REGNO (reg), regno != FRAME_POINTER_REGNUM)
1.1.1.11  root     1337:       && regno != ARG_POINTER_REGNUM
                   1338:       && ! (regno < FIRST_PSEUDO_REGISTER && global_regs[regno]))
1.1.1.2   root     1339:     /* && regno != STACK_POINTER_REGNUM) -- let's try without this.  */
1.1       root     1340:     {
                   1341:       register int offset = regno / REGSET_ELT_BITS;
                   1342:       register int bit = 1 << (regno % REGSET_ELT_BITS);
1.1.1.2   root     1343:       int is_needed = 0;
                   1344: 
1.1       root     1345:       /* Mark the reg being set as dead before this insn.  */
                   1346:       dead[offset] |= bit;
                   1347:       /* Mark it as a significant register for this basic block.  */
                   1348:       if (significant)
                   1349:        significant[offset] |= bit;
1.1.1.2   root     1350:       /* A hard reg in a wide mode may really be multiple registers.
                   1351:         If so, mark all of them just like the first.  */
                   1352:       if (regno < FIRST_PSEUDO_REGISTER)
                   1353:        {
1.1.1.4   root     1354:          int n;
                   1355: 
                   1356:          /* Nothing below is needed for the stack pointer; get out asap.
                   1357:             Eg, log links aren't needed, since combine won't use them.  */
                   1358:          if (regno == STACK_POINTER_REGNUM)
                   1359:            return;
                   1360: 
                   1361:          n = HARD_REGNO_NREGS (regno, GET_MODE (reg));
1.1.1.2   root     1362:          while (--n > 0)
                   1363:            {
                   1364:              dead[(regno + n) / REGSET_ELT_BITS]
                   1365:                |= 1 << ((regno + n) % REGSET_ELT_BITS);
                   1366:              if (significant)
                   1367:                significant[(regno + n) / REGSET_ELT_BITS]
                   1368:                  |= 1 << ((regno + n) % REGSET_ELT_BITS);
                   1369:              is_needed |= (needed[(regno + n) / REGSET_ELT_BITS]
                   1370:                            & 1 << ((regno + n) % REGSET_ELT_BITS));
                   1371:            }
                   1372:        }
1.1       root     1373:       /* Additional data to record if this is the final pass.  */
                   1374:       if (insn)
                   1375:        {
                   1376:          register rtx y = reg_next_use[regno];
                   1377:          register int blocknum = BLOCK_NUM (insn);
                   1378: 
1.1.1.9   root     1379:          /* If this is a hard reg, record this function uses the reg.
                   1380:             `combine.c' will get confused if LOG_LINKs are made
                   1381:             for hard regs.  */
1.1       root     1382: 
                   1383:          if (regno < FIRST_PSEUDO_REGISTER)
                   1384:            {
                   1385:              register int i;
                   1386:              i = HARD_REGNO_NREGS (regno, GET_MODE (reg));
1.1.1.8   root     1387:              if (i == 0)
                   1388:                i = 1;
1.1       root     1389:              do
                   1390:                regs_ever_live[regno + --i] = 1;
                   1391:              while (i > 0);
1.1.1.4   root     1392: 
                   1393:              if (! ((needed[offset] & bit) || is_needed))
                   1394:                {
                   1395:                  /* Note that dead stores have already been deleted if poss.
                   1396:                     If we get here, we have found a dead store that cannot
                   1397:                     be eliminated (because the insn does something useful).
                   1398:                     Indicate this by marking the reg set as dying here.  */
                   1399:                  REG_NOTES (insn)
                   1400:                    = gen_rtx (EXPR_LIST, REG_DEAD,
                   1401:                               reg, REG_NOTES (insn));
                   1402:                  reg_n_deaths[REGNO (reg)]++;
                   1403:                }
                   1404:              return;
1.1       root     1405:            }
                   1406: 
                   1407:          /* Keep track of which basic blocks each reg appears in.  */
                   1408: 
1.1.1.4   root     1409:          if (reg_basic_block[regno] == REG_BLOCK_UNKNOWN)
1.1       root     1410:            reg_basic_block[regno] = blocknum;
                   1411:          else if (reg_basic_block[regno] != blocknum)
1.1.1.4   root     1412:            reg_basic_block[regno] = REG_BLOCK_GLOBAL;
1.1       root     1413: 
                   1414:          /* Count (weighted) references, stores, etc.  */
                   1415:          reg_n_refs[regno] += loop_depth;
                   1416:          reg_n_sets[regno]++;
1.1.1.2   root     1417:          /* The next use is no longer "next", since a store intervenes.  */
                   1418:          reg_next_use[regno] = 0;
1.1       root     1419:          /* The insns where a reg is live are normally counted elsewhere,
                   1420:             but we want the count to include the insn where the reg is set,
                   1421:             and the normal counting mechanism would not count it.  */
                   1422:          reg_live_length[regno]++;
1.1.1.2   root     1423:          if ((needed[offset] & bit) || is_needed)
1.1       root     1424:            {
                   1425:              /* Make a logical link from the next following insn
                   1426:                 that uses this register, back to this insn.
                   1427:                 The following insns have already been processed.  */
                   1428:              if (y && (BLOCK_NUM (y) == blocknum))
                   1429:                LOG_LINKS (y)
                   1430:                  = gen_rtx (INSN_LIST, VOIDmode, insn, LOG_LINKS (y));
                   1431:            }
                   1432:          else
                   1433:            {
                   1434:              /* Note that dead stores have already been deleted when possible
                   1435:                 If we get here, we have found a dead store that cannot
                   1436:                 be eliminated (because the same insn does something useful).
                   1437:                 Indicate this by marking the reg being set as dying here.  */
                   1438:              REG_NOTES (insn)
                   1439:                = gen_rtx (EXPR_LIST, REG_DEAD,
                   1440:                           reg, REG_NOTES (insn));
1.1.1.3   root     1441:              reg_n_deaths[REGNO (reg)]++;
1.1       root     1442:            }
                   1443:        }
                   1444:     }
                   1445: }
                   1446: 
                   1447: /* Scan expression X and store a 1-bit in LIVE for each reg it uses.
                   1448:    This is done assuming the registers needed from X
                   1449:    are those that have 1-bits in NEEDED.
                   1450: 
1.1.1.2   root     1451:    On the final pass, FINAL is 1.  This means try for autoincrement
                   1452:    and count the uses and deaths of each pseudo-reg.
                   1453: 
                   1454:    INSN is the containing instruction.  */
1.1       root     1455: 
                   1456: static void
1.1.1.2   root     1457: mark_used_regs (needed, live, x, final, insn)
1.1       root     1458:      regset needed;
                   1459:      regset live;
                   1460:      rtx x;
                   1461:      rtx insn;
1.1.1.2   root     1462:      int final;
1.1       root     1463: {
                   1464:   register RTX_CODE code;
                   1465:   register int regno;
                   1466: 
                   1467:  retry:
                   1468:   code = GET_CODE (x);
                   1469:   switch (code)
                   1470:     {
                   1471:     case LABEL_REF:
                   1472:     case SYMBOL_REF:
                   1473:     case CONST_INT:
                   1474:     case CONST:
1.1.1.4   root     1475:     case CONST_DOUBLE:
1.1       root     1476:     case CC0:
                   1477:     case PC:
                   1478:     case CLOBBER:
1.1.1.4   root     1479:     case ADDR_VEC:
                   1480:     case ADDR_DIFF_VEC:
                   1481:     case ASM_INPUT:
1.1       root     1482:       return;
                   1483: 
                   1484: #if defined (HAVE_POST_INCREMENT) || defined (HAVE_POST_DECREMENT)
                   1485:     case MEM:
                   1486:       /* Here we detect use of an index register which might
                   1487:         be good for postincrement or postdecrement.  */
1.1.1.2   root     1488:       if (final)
1.1       root     1489:        {
                   1490:          rtx addr = XEXP (x, 0);
                   1491:          register int size = GET_MODE_SIZE (GET_MODE (x));
                   1492: 
                   1493:          if (GET_CODE (addr) == REG)
                   1494:            {
                   1495:              register rtx y;
                   1496:              regno = REGNO (addr);
                   1497:              /* Is the next use an increment that might make auto-increment? */
                   1498:              y = reg_next_use[regno];
                   1499:              if (y && GET_CODE (PATTERN (y)) == SET
                   1500:                  && BLOCK_NUM (y) == BLOCK_NUM (insn)
                   1501:                  /* Can't add side effects to jumps; if reg is spilled and
                   1502:                     reloaded, there's no way to store back the altered value.  */
                   1503:                  && GET_CODE (insn) != JUMP_INSN
                   1504:                  && (y = SET_SRC (PATTERN (y)),
                   1505:                      (0
                   1506: #ifdef HAVE_POST_INCREMENT
                   1507:                       || GET_CODE (y) == PLUS
                   1508: #endif
                   1509: #ifdef HAVE_POST_DECREMENT
                   1510:                       || GET_CODE (y) == MINUS
                   1511: #endif
                   1512:                       )
                   1513:                      && XEXP (y, 0) == addr
                   1514:                      && GET_CODE (XEXP (y, 1)) == CONST_INT
1.1.1.2   root     1515:                      && INTVAL (XEXP (y, 1)) == size)
                   1516:                  && dead_or_set_p (reg_next_use[regno], addr))
1.1       root     1517:                {
1.1.1.2   root     1518:                  rtx use = find_use_as_address (PATTERN (insn), addr, 0);
1.1       root     1519: 
                   1520:                  /* Make sure this register appears only once in this insn.  */
                   1521:                  if (use != 0 && use != (rtx) 1)
                   1522:                    {
                   1523:                      /* We have found a suitable auto-increment:
                   1524:                         do POST_INC around the register here,
                   1525:                         and patch out the increment instruction that follows. */
                   1526:                      XEXP (x, 0)
                   1527:                        = gen_rtx (GET_CODE (y) == PLUS ? POST_INC : POST_DEC,
                   1528:                                   Pmode, addr);
                   1529:                      /* Record that this insn has an implicit side effect.  */
                   1530:                      REG_NOTES (insn)
                   1531:                        = gen_rtx (EXPR_LIST, REG_INC, addr, REG_NOTES (insn));
                   1532: 
1.1.1.2   root     1533:                      /* Modify the old increment-insn to simply copy
                   1534:                         the already-incremented value of our register.  */
1.1       root     1535:                      y = reg_next_use[regno];
1.1.1.2   root     1536:                      SET_SRC (PATTERN (y)) = addr;
                   1537: 
                   1538:                      /* If that makes it a no-op (copying the register
                   1539:                         into itself) then change it to a simpler no-op
                   1540:                         so it won't appear to be a "use" and a "set"
                   1541:                         of this register.  */
                   1542:                      if (SET_DEST (PATTERN (y)) == addr)
                   1543:                        PATTERN (y) = gen_rtx (USE, VOIDmode, const0_rtx);
                   1544: 
                   1545:                      /* Count an extra reference to the reg for the increment.
                   1546:                         When a reg is incremented.
1.1       root     1547:                         spilling it is worse, so we want to make that
                   1548:                         less likely.  */
                   1549:                      reg_n_refs[regno] += loop_depth;
1.1.1.2   root     1550:                      /* Count the increment as a setting of the register,
                   1551:                         even though it isn't a SET in rtl.  */
                   1552:                      reg_n_sets[regno]++;
1.1       root     1553:                    }
                   1554:                }
                   1555:            }
                   1556:        }
                   1557:       break;
                   1558: #endif /* HAVE_POST_INCREMENT or HAVE_POST_DECREMENT */
                   1559: 
                   1560:     case REG:
                   1561:       /* See a register other than being set
                   1562:         => mark it as needed.  */
                   1563: 
                   1564:       regno = REGNO (x);
                   1565:       if (regno != FRAME_POINTER_REGNUM
1.1.1.2   root     1566:          && regno != ARG_POINTER_REGNUM)
                   1567:        /* && regno != STACK_POINTER_REGNUM) -- let's try without this.  */
1.1       root     1568:        {
                   1569:          register int offset = regno / REGSET_ELT_BITS;
                   1570:          register int bit = 1 << (regno % REGSET_ELT_BITS);
1.1.1.2   root     1571:          int is_needed = 0;
                   1572: 
1.1       root     1573:          live[offset] |= bit;
1.1.1.2   root     1574:          /* A hard reg in a wide mode may really be multiple registers.
                   1575:             If so, mark all of them just like the first.  */
                   1576:          if (regno < FIRST_PSEUDO_REGISTER)
                   1577:            {
1.1.1.4   root     1578:              int n;
                   1579: 
                   1580:              /* For stack ptr, nothing below here can be necessary,
                   1581:                 so waste no more time.  */
                   1582:              if (regno == STACK_POINTER_REGNUM)
                   1583:                return;
1.1.1.12! root     1584:              /* No death notes for global register variables;
        !          1585:                 their values are live after this function exits.  */
        !          1586:              if (global_regs[regno])
        !          1587:                return;
1.1.1.4   root     1588: 
                   1589:              n = HARD_REGNO_NREGS (regno, GET_MODE (x));
1.1.1.2   root     1590:              while (--n > 0)
                   1591:                {
                   1592:                  live[(regno + n) / REGSET_ELT_BITS]
                   1593:                    |= 1 << ((regno + n) % REGSET_ELT_BITS);
                   1594:                  is_needed |= (needed[(regno + n) / REGSET_ELT_BITS]
                   1595:                                & 1 << ((regno + n) % REGSET_ELT_BITS));
                   1596:                }
                   1597:            }
                   1598:          if (final)
1.1       root     1599:            {
                   1600:              if (regno < FIRST_PSEUDO_REGISTER)
                   1601:                {
1.1.1.4   root     1602:                  /* If a hard reg is being used,
                   1603:                     record that this function does use it.  */
                   1604: 
1.1       root     1605:                  register int i;
                   1606:                  i = HARD_REGNO_NREGS (regno, GET_MODE (x));
1.1.1.8   root     1607:                  if (i == 0)
                   1608:                    i = 1;
1.1       root     1609:                  do
                   1610:                    regs_ever_live[regno + --i] = 1;
                   1611:                  while (i > 0);
                   1612:                }
1.1.1.4   root     1613:              else
                   1614:                {
                   1615:                  /* Keep track of which basic block each reg appears in.  */
1.1       root     1616: 
1.1.1.4   root     1617:                  register int blocknum = BLOCK_NUM (insn);
1.1       root     1618: 
1.1.1.4   root     1619:                  if (reg_basic_block[regno] == REG_BLOCK_UNKNOWN)
                   1620:                    reg_basic_block[regno] = blocknum;
                   1621:                  else if (reg_basic_block[regno] != blocknum)
                   1622:                    reg_basic_block[regno] = REG_BLOCK_GLOBAL;
1.1       root     1623: 
1.1.1.4   root     1624:                  /* Record where each reg is used, so when the reg
                   1625:                     is set we know the next insn that uses it.  */
1.1       root     1626: 
1.1.1.4   root     1627:                  reg_next_use[regno] = insn;
1.1       root     1628: 
1.1.1.4   root     1629:                  /* Count (weighted) number of uses of each reg.  */
1.1       root     1630: 
1.1.1.4   root     1631:                  reg_n_refs[regno] += loop_depth;
                   1632:                }
1.1.1.12! root     1633: 
1.1       root     1634:              /* Record and count the insns in which a reg dies.
                   1635:                 If it is used in this insn and was dead below the insn
                   1636:                 then it dies in this insn.  */
                   1637: 
1.1.1.2   root     1638:              if (!(needed[offset] & bit) && !is_needed
                   1639:                  && ! find_regno_note (insn, REG_DEAD, regno))
1.1       root     1640:                {
                   1641:                  REG_NOTES (insn)
                   1642:                    = gen_rtx (EXPR_LIST, REG_DEAD, x, REG_NOTES (insn));
                   1643:                  reg_n_deaths[regno]++;
                   1644:                }
                   1645:            }
                   1646:        }
                   1647:       return;
                   1648: 
                   1649:     case SET:
                   1650:       {
1.1.1.2   root     1651:        register rtx testreg = SET_DEST (x);
                   1652:        int mark_dest = 0;
1.1       root     1653: 
1.1.1.2   root     1654:        /* Storing in STRICT_LOW_PART is like storing in a reg
                   1655:           in that this SET might be dead, so ignore it in TESTREG.
                   1656:           but in some other ways it is like using the reg.  */
                   1657:        /* Storing in a SUBREG or a bit field is like storing the entire
                   1658:           register in that if the register's value is not used
                   1659:           then this SET is not needed.  */
                   1660:        while (GET_CODE (testreg) == STRICT_LOW_PART
                   1661:               || GET_CODE (testreg) == ZERO_EXTRACT
                   1662:               || GET_CODE (testreg) == SIGN_EXTRACT
                   1663:               || GET_CODE (testreg) == SUBREG)
                   1664:          {
                   1665:            /* Modifying a single register in an alternate mode
                   1666:               does not use any of the old value.  But these other
                   1667:               ways of storing in a register do use the old value.  */
                   1668:            if (GET_CODE (testreg) == SUBREG
                   1669:                && !(REG_SIZE (SUBREG_REG (testreg)) > REG_SIZE (testreg)))
                   1670:              ;
                   1671:            else
                   1672:              mark_dest = 1;
                   1673: 
                   1674:            testreg = XEXP (testreg, 0);
                   1675:          }
1.1       root     1676: 
                   1677:        /* If this is a store into a register,
                   1678:           recursively scan the only value being stored,
                   1679:           and only if the register's value is live after this insn.
                   1680:           If the value being computed here would never be used
                   1681:           then the values it uses don't need to be computed either.  */
                   1682: 
1.1.1.2   root     1683:        if (GET_CODE (testreg) == REG
                   1684:            && (regno = REGNO (testreg), regno != FRAME_POINTER_REGNUM)
1.1.1.11  root     1685:            && regno != ARG_POINTER_REGNUM
                   1686:            && ! (regno < FIRST_PSEUDO_REGISTER && global_regs[regno]))
1.1.1.7   root     1687: #if 0 /* This was added in 1.25, but screws up death notes for hard regs.
                   1688:         It probably isn't really needed anyway.  */
1.1.1.6   root     1689:            && (regno >= FIRST_PSEUDO_REGISTER
                   1690:                || INSN_VOLATILE (insn)))
1.1.1.7   root     1691: #endif
1.1       root     1692:          {
                   1693:            register int offset = regno / REGSET_ELT_BITS;
                   1694:            register int bit = 1 << (regno % REGSET_ELT_BITS);
1.1.1.2   root     1695:            if ((needed[offset] & bit)
                   1696:                /* If insn refers to volatile, we mustn't delete it,
                   1697:                   so its inputs are all needed.  */
                   1698:                || INSN_VOLATILE (insn))
                   1699:              {
                   1700:                mark_used_regs (needed, live, SET_SRC (x), final, insn);
                   1701:                if (mark_dest)
                   1702:                  mark_used_regs (needed, live, SET_DEST (x), final, insn);
                   1703:              }
1.1       root     1704:            return;
                   1705:          }
                   1706:       }
                   1707:       break;
                   1708:     }
                   1709: 
                   1710:   /* Recursively scan the operands of this expression.  */
                   1711: 
                   1712:   {
                   1713:     register char *fmt = GET_RTX_FORMAT (code);
                   1714:     register int i;
                   1715:     
                   1716:     for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
                   1717:       {
                   1718:        if (fmt[i] == 'e')
                   1719:          {
                   1720:            /* Tail recursive case: save a function call level.  */
                   1721:            if (i == 0)
                   1722:              {
                   1723:                x = XEXP (x, 0);
                   1724:                goto retry;
                   1725:              }
1.1.1.2   root     1726:            mark_used_regs (needed, live, XEXP (x, i), final, insn);
1.1       root     1727:          }
1.1.1.4   root     1728:        else if (fmt[i] == 'E')
1.1       root     1729:          {
                   1730:            register int j;
                   1731:            for (j = 0; j < XVECLEN (x, i); j++)
1.1.1.2   root     1732:              mark_used_regs (needed, live, XVECEXP (x, i, j), final, insn);
1.1       root     1733:          }
                   1734:       }
                   1735:   }
                   1736: }
                   1737: 
1.1.1.2   root     1738: #ifdef AUTO_INC_DEC
1.1       root     1739: 
                   1740: static int
                   1741: try_pre_increment_1 (insn)
                   1742:      rtx insn;
                   1743: {
                   1744:   /* Find the next use of this reg.  If in same basic block,
                   1745:      make it do pre-increment or pre-decrement if appropriate.  */
                   1746:   rtx x = PATTERN (insn);
                   1747:   int amount = ((GET_CODE (SET_SRC (x)) == PLUS ? 1 : -1)
                   1748:                * INTVAL (XEXP (SET_SRC (x), 1)));
                   1749:   int regno = REGNO (SET_DEST (x));
                   1750:   rtx y = reg_next_use[regno];
                   1751:   if (y != 0
                   1752:       && BLOCK_NUM (y) == BLOCK_NUM (insn)
                   1753:       && try_pre_increment (y, SET_DEST (PATTERN (insn)),
                   1754:                            amount))
                   1755:     {
                   1756:       /* We have found a suitable auto-increment
                   1757:         and already changed insn Y to do it.
                   1758:         So flush this increment-instruction.  */
                   1759:       PUT_CODE (insn, NOTE);
                   1760:       NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
                   1761:       NOTE_SOURCE_FILE (insn) = 0;
                   1762:       /* Count a reference to this reg for the increment
                   1763:         insn we are deleting.  When a reg is incremented.
                   1764:         spilling it is worse, so we want to make that
                   1765:         less likely.  */
                   1766:       reg_n_refs[regno] += loop_depth;
1.1.1.2   root     1767:       reg_n_sets[regno]++;
1.1       root     1768:       return 1;
                   1769:     }
                   1770:   return 0;
                   1771: }
                   1772: 
                   1773: /* Try to change INSN so that it does pre-increment or pre-decrement
                   1774:    addressing on register REG in order to add AMOUNT to REG.
                   1775:    AMOUNT is negative for pre-decrement.
                   1776:    Returns 1 if the change could be made.
                   1777:    This checks all about the validity of the result of modifying INSN.  */
                   1778: 
                   1779: static int
                   1780: try_pre_increment (insn, reg, amount)
                   1781:      rtx insn, reg;
                   1782:      int amount;
                   1783: {
                   1784:   register rtx use;
                   1785: 
1.1.1.2   root     1786:   /* Nonzero if we can try to make a pre-increment or pre-decrement.
                   1787:      For example, addl $4,r1; movl (r1),... can become movl +(r1),...  */
                   1788:   int pre_ok = 0;
                   1789:   /* Nonzero if we can try to make a post-increment or post-decrement.
                   1790:      For example, addl $4,r1; movl -4(r1),... can become movl (r1)+,...
                   1791:      It is possible for both PRE_OK and POST_OK to be nonzero if the machine
                   1792:      supports both pre-inc and post-inc, or both pre-dec and post-dec.  */
                   1793:   int post_ok = 0;
                   1794: 
                   1795:   /* Nonzero if the opportunity actually requires post-inc or post-dec.  */
                   1796:   int do_post = 0;
                   1797: 
                   1798:   /* From the sign of increment, see which possibilities are conceivable
                   1799:      on this target machine.  */
                   1800: #ifdef HAVE_PRE_INCREMENT
1.1       root     1801:   if (amount > 0)
1.1.1.2   root     1802:     pre_ok = 1;
1.1       root     1803: #endif
1.1.1.2   root     1804: #ifdef HAVE_POST_INCREMENT
                   1805:   if (amount > 0)
                   1806:     post_ok = 1;
1.1       root     1807: #endif
                   1808: 
1.1.1.2   root     1809: #ifdef HAVE_PRE_DECREMENT
1.1       root     1810:   if (amount < 0)
1.1.1.2   root     1811:     pre_ok = 1;
                   1812: #endif
                   1813: #ifdef HAVE_POST_DECREMENT
                   1814:   if (amount < 0)
                   1815:     post_ok = 1;
1.1       root     1816: #endif
                   1817: 
1.1.1.2   root     1818:   if (! (pre_ok || post_ok))
                   1819:     return 0;
                   1820: 
1.1       root     1821:   /* It is not safe to add a side effect to a jump insn
                   1822:      because if the incremented register is spilled and must be reloaded
                   1823:      there would be no way to store the incremented value back in memory.  */
                   1824: 
                   1825:   if (GET_CODE (insn) == JUMP_INSN)
                   1826:     return 0;
                   1827: 
1.1.1.2   root     1828:   use = 0;
                   1829:   if (pre_ok)
                   1830:     use = find_use_as_address (PATTERN (insn), reg, 0);
                   1831:   if (post_ok && (use == 0 || use == (rtx) 1))
                   1832:     {
                   1833:       use = find_use_as_address (PATTERN (insn), reg, -amount);
                   1834:       do_post = 1;
                   1835:     }
1.1       root     1836: 
                   1837:   if (use == 0 || use == (rtx) 1)
                   1838:     return 0;
                   1839: 
                   1840:   if (GET_MODE_SIZE (GET_MODE (use)) != (amount > 0 ? amount : - amount))
                   1841:     return 0;
                   1842: 
1.1.1.2   root     1843:   XEXP (use, 0) = gen_rtx (amount > 0
                   1844:                           ? (do_post ? POST_INC : PRE_INC)
                   1845:                           : (do_post ? POST_DEC : PRE_DEC),
1.1       root     1846:                           Pmode, reg);
                   1847: 
                   1848:   /* Record that this insn now has an implicit side effect on X.  */
                   1849:   REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_INC, reg, REG_NOTES (insn));
                   1850:   return 1;
                   1851: }
                   1852: 
1.1.1.2   root     1853: #endif /* AUTO_INC_DEC */
                   1854: 
1.1       root     1855: /* Find the place in the rtx X where REG is used as a memory address.
                   1856:    Return the MEM rtx that so uses it.
1.1.1.2   root     1857:    If PLUSCONST is nonzero, search instead for a memory address equivalent to
                   1858:    (plus REG (const_int PLUSCONST)).
                   1859: 
                   1860:    If such an address does not appear, return 0.
                   1861:    If REG appears more than once, or is used other than in such an address,
1.1       root     1862:    return (rtx)1.  */
                   1863: 
                   1864: static rtx
1.1.1.2   root     1865: find_use_as_address (x, reg, plusconst)
1.1       root     1866:      register rtx x;
                   1867:      rtx reg;
1.1.1.2   root     1868:      int plusconst;
1.1       root     1869: {
                   1870:   enum rtx_code code = GET_CODE (x);
                   1871:   char *fmt = GET_RTX_FORMAT (code);
                   1872:   register int i;
                   1873:   register rtx value = 0;
                   1874:   register rtx tem;
                   1875: 
1.1.1.2   root     1876:   if (code == MEM && XEXP (x, 0) == reg && plusconst == 0)
1.1       root     1877:     return x;
                   1878: 
1.1.1.2   root     1879:   if (code == MEM && GET_CODE (XEXP (x, 0)) == PLUS
                   1880:       && XEXP (XEXP (x, 0), 0) == reg
                   1881:       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
                   1882:       && INTVAL (XEXP (XEXP (x, 0), 1)) == plusconst)
                   1883:     return x;
                   1884: 
                   1885:   if (code == SIGN_EXTRACT || code == ZERO_EXTRACT)
                   1886:     {
                   1887:       /* If REG occurs inside a MEM used in a bit-field reference,
                   1888:         that is unacceptable.  */
                   1889:       if (find_use_as_address (XEXP (x, 0), reg, 0) != 0)
                   1890:        return (rtx) 1;
                   1891:     }
                   1892: 
1.1       root     1893:   if (x == reg)
                   1894:     return (rtx) 1;
                   1895: 
                   1896:   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
                   1897:     {
                   1898:       if (fmt[i] == 'e')
                   1899:        {
1.1.1.2   root     1900:          tem = find_use_as_address (XEXP (x, i), reg, plusconst);
1.1       root     1901:          if (value == 0)
                   1902:            value = tem;
                   1903:          else if (tem != 0)
                   1904:            return (rtx) 1;
                   1905:        }
                   1906:       if (fmt[i] == 'E')
                   1907:        {
                   1908:          register int j;
                   1909:          for (j = XVECLEN (x, i) - 1; j >= 0; j--)
                   1910:            {
1.1.1.2   root     1911:              tem = find_use_as_address (XVECEXP (x, i, j), reg, plusconst);
1.1       root     1912:              if (value == 0)
                   1913:                value = tem;
                   1914:              else if (tem != 0)
                   1915:                return (rtx) 1;
                   1916:            }
                   1917:        }
                   1918:     }
                   1919: 
                   1920:   return value;
                   1921: }
                   1922: 
                   1923: /* Write information about registers and basic blocks into FILE.
                   1924:    This is part of making a debugging dump.  */
                   1925: 
1.1.1.2   root     1926: void
1.1       root     1927: dump_flow_info (file)
                   1928:      FILE *file;
                   1929: {
                   1930:   register int i;
                   1931:   static char *reg_class_names[] = REG_CLASS_NAMES;
                   1932: 
                   1933:   fprintf (file, "%d registers.\n", max_regno);
                   1934: 
                   1935:   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
                   1936:     if (reg_n_refs[i])
                   1937:       {
                   1938:        enum reg_class class;
                   1939:        fprintf (file, "\nRegister %d used %d times across %d insns",
                   1940:                 i, reg_n_refs[i], reg_live_length[i]);
                   1941:        if (reg_basic_block[i] >= 0)
                   1942:          fprintf (file, " in block %d", reg_basic_block[i]);
                   1943:        if (reg_n_deaths[i] != 1)
                   1944:          fprintf (file, "; dies in %d places", reg_n_deaths[i]);
1.1.1.12! root     1945:        if (reg_n_calls_crossed[i] == 1)
        !          1946:          fprintf (file, "; crosses 1 call", reg_n_calls_crossed[i]);
        !          1947:        else if (reg_n_calls_crossed[i])
        !          1948:          fprintf (file, "; crosses %d calls", reg_n_calls_crossed[i]);
1.1       root     1949:        if (PSEUDO_REGNO_BYTES (i) != UNITS_PER_WORD)
                   1950:          fprintf (file, "; %d bytes", PSEUDO_REGNO_BYTES (i));
                   1951:        class = reg_preferred_class (i);
                   1952:        if (class != GENERAL_REGS)
1.1.1.2   root     1953:          {
                   1954:            if (reg_preferred_or_nothing (i))
                   1955:              fprintf (file, "; %s or none", reg_class_names[(int) class]);
                   1956:            else
                   1957:              fprintf (file, "; pref %s", reg_class_names[(int) class]);
                   1958:          }
1.1       root     1959:        if (REGNO_POINTER_FLAG (i))
                   1960:          fprintf (file, "; pointer");
                   1961:        fprintf (file, ".\n");
                   1962:       }
                   1963:   fprintf (file, "\n%d basic blocks.\n", n_basic_blocks);
                   1964:   for (i = 0; i < n_basic_blocks; i++)
                   1965:     {
                   1966:       register rtx head, jump;
                   1967:       register int regno;
                   1968:       fprintf (file, "\nBasic block %d: first insn %d, last %d.\n",
                   1969:               i,
                   1970:               INSN_UID (basic_block_head[i]),
                   1971:               INSN_UID (basic_block_end[i]));
                   1972:       /* The control flow graph's storage is freed
                   1973:         now when flow_analysis returns.
                   1974:         Don't try to print it if it is gone.  */
                   1975:       if (basic_block_drops_in)
                   1976:        {
                   1977:          fprintf (file, "Reached from blocks: ");
                   1978:          head = basic_block_head[i];
                   1979:          if (GET_CODE (head) == CODE_LABEL)
                   1980:            for (jump = LABEL_REFS (head);
                   1981:                 jump != head;
                   1982:                 jump = LABEL_NEXTREF (jump))
                   1983:              {
                   1984:                register from_block = BLOCK_NUM (CONTAINING_INSN (jump));
                   1985:                fprintf (file, " %d", from_block);
                   1986:              }
                   1987:          if (basic_block_drops_in[i])
                   1988:            fprintf (file, " previous");
                   1989:        }
                   1990:       fprintf (file, "\nRegisters live at start:");
                   1991:       for (regno = 0; regno < max_regno; regno++)
                   1992:        {
                   1993:          register int offset = regno / REGSET_ELT_BITS;
                   1994:          register int bit = 1 << (regno % REGSET_ELT_BITS);
                   1995:          if (basic_block_live_at_start[i][offset] & bit)
                   1996:              fprintf (file, " %d", regno);
                   1997:        }
                   1998:       fprintf (file, "\n");
                   1999:     }
                   2000:   fprintf (file, "\n");
                   2001: }

unix.superglobalmegacorp.com

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