Annotation of gcc/flow.c, revision 1.1.1.11

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

unix.superglobalmegacorp.com

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