Annotation of gcc/flow.c, revision 1.1.1.9

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.
                    124:    Or gives -2 if (REG n) is used in more than one basic block.
                    125:    Or -1 if it has not yet been seen so no basic block is known.
                    126:    This information remains valid for the rest of the compilation
                    127:    of the current function; it is used to control register allocation.  */
                    128: 
1.1.1.4   root      129: #define REG_BLOCK_UNKNOWN -1
                    130: #define REG_BLOCK_GLOBAL -2
1.1       root      131: short *reg_basic_block;
                    132: 
                    133: /* Indexed by n, gives number of times (REG n) is used or set, each
                    134:    weighted by its loop-depth.
                    135:    This information remains valid for the rest of the compilation
                    136:    of the current function; it is used to control register allocation.  */
                    137: 
                    138: short *reg_n_refs;
                    139: 
                    140: /* Indexed by n, gives number of times (REG n) is set.
                    141:    This information remains valid for the rest of the compilation
                    142:    of the current function; it is used to control register allocation.  */
                    143: 
                    144: short *reg_n_sets;
                    145: 
                    146: /* Indexed by N, gives number of places register N dies.
                    147:    This information remains valid for the rest of the compilation
                    148:    of the current function; it is used to control register allocation.  */
                    149: 
                    150: short *reg_n_deaths;
                    151: 
                    152: /* Indexed by N, gives 1 if that reg is live across any CALL_INSNs.
                    153:    This information remains valid for the rest of the compilation
                    154:    of the current function; it is used to control register allocation.  */
                    155: 
                    156: char *reg_crosses_call;
                    157: 
                    158: /* Total number of instructions at which (REG n) is live.
                    159:    The larger this is, the less priority (REG n) gets for
                    160:    allocation in a real register.
                    161:    This information remains valid for the rest of the compilation
1.1.1.2   root      162:    of the current function; it is used to control register allocation.
                    163: 
                    164:    local-alloc.c may alter this number to change the priority.
                    165: 
                    166:    Negative values are special.
                    167:    -1 is used to mark a pseudo reg which has a constant or memory equivalent
                    168:    and is used infrequently enough that it should not get a hard register.
                    169:    -2 is used to mark a pseudo reg for a parameter, when a frame pointer
                    170:    is not required.  global-alloc.c makes an allocno for this but does
                    171:    not try to assign a hard register to it.  */
1.1       root      172: 
                    173: int *reg_live_length;
                    174: 
                    175: /* Element N is the next insn that uses (hard or pseudo) register number N
                    176:    within the current basic block; or zero, if there is no such insn.
                    177:    This is valid only during the final backward scan in propagate_block.  */
                    178: 
                    179: static rtx *reg_next_use;
                    180: 
                    181: /* Size of a regset for the current function,
                    182:    in (1) bytes and (2) elements.  */
                    183: 
                    184: int regset_bytes;
                    185: int regset_size;
                    186: 
                    187: /* Element N is first insn in basic block N.
                    188:    This info lasts until we finish compiling the function.  */
                    189: 
                    190: rtx *basic_block_head;
                    191: 
                    192: /* Element N is last insn in basic block N.
                    193:    This info lasts until we finish compiling the function.  */
                    194: 
                    195: rtx *basic_block_end;
                    196: 
                    197: /* Element N is a regset describing the registers live
                    198:    at the start of basic block N.
                    199:    This info lasts until we finish compiling the function.  */
                    200: 
                    201: regset *basic_block_live_at_start;
                    202: 
1.1.1.2   root      203: /* Regset of regs live when calls to `setjmp'-like functions happen.  */
                    204: 
                    205: regset regs_live_at_setjmp;
                    206: 
1.1       root      207: /* Element N is nonzero if control can drop into basic block N
                    208:    from the preceding basic block.  Freed after life_analysis.  */
                    209: 
1.1.1.2   root      210: static char *basic_block_drops_in;
1.1       root      211: 
                    212: /* Element N is depth within loops of basic block number N.
                    213:    Freed after life_analysis.  */
                    214: 
1.1.1.2   root      215: static short *basic_block_loop_depth;
1.1       root      216: 
                    217: /* Element N nonzero if basic block N can actually be reached.
                    218:    Vector exists only during find_basic_blocks.  */
                    219: 
1.1.1.2   root      220: static char *block_live_static;
1.1       root      221: 
                    222: /* Depth within loops of basic block being scanned for lifetime analysis,
                    223:    plus one.  This is the weight attached to references to registers.  */
                    224: 
1.1.1.2   root      225: static int loop_depth;
                    226: 
                    227: /* Define AUTO_INC_DEC if machine has any kind of incrementing
                    228:    or decrementing addressing.  */
                    229: 
                    230: #ifdef HAVE_PRE_DECREMENT
                    231: #define AUTO_INC_DEC
                    232: #endif
                    233: 
                    234: #ifdef HAVE_PRE_INCREMENT
                    235: #define AUTO_INC_DEC
                    236: #endif
                    237: 
                    238: #ifdef HAVE_POST_DECREMENT
                    239: #define AUTO_INC_DEC
                    240: #endif
                    241: 
                    242: #ifdef HAVE_POST_INCREMENT
                    243: #define AUTO_INC_DEC
                    244: #endif
1.1       root      245: 
                    246: /* Forward declarations */
                    247: static void find_basic_blocks ();
                    248: static void life_analysis ();
                    249: static void mark_label_ref ();
                    250: void allocate_for_life_analysis (); /* Used also in stupid_life_analysis */
                    251: static void init_regset_vector ();
                    252: static void propagate_block ();
                    253: static void mark_set_regs ();
                    254: static void mark_used_regs ();
                    255: static int insn_dead_p ();
                    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.
                    635:         Even if this function never uses this stack pointer value,
                    636:         signal handlers do!  */
                    637:       else if (code1 == INSN && GET_CODE (PATTERN (insn)) == SET
                    638:               && SET_DEST (PATTERN (insn)) == stack_pointer_rtx
                    639: #ifdef STACK_GROWS_DOWNWARD
                    640:               && GET_CODE (SET_SRC (PATTERN (insn))) == MINUS
                    641: #else
                    642:               && GET_CODE (SET_SRC (PATTERN (insn))) == PLUS
                    643: #endif
                    644:               && XEXP (SET_SRC (PATTERN (insn)), 0) == stack_pointer_rtx)
                    645:        INSN_VOLATILE (insn) = 1;
1.1.1.4   root      646:     }
1.1.1.2   root      647: 
                    648:   if (n_basic_blocks > 0)
                    649: #ifdef EXIT_IGNORE_STACK
                    650:     if (! (EXIT_IGNORE_STACK) || ! frame_pointer_needed)
                    651: #endif
                    652:       {
                    653:        /* If exiting needs the right stack value,
                    654:           consider the stack pointer live at the end of the function.  */
                    655:        basic_block_live_at_end[n_basic_blocks - 1]
                    656:          [STACK_POINTER_REGNUM / REGSET_ELT_BITS]
                    657:            |= 1 << (STACK_POINTER_REGNUM % REGSET_ELT_BITS);
                    658:        basic_block_new_live_at_end[n_basic_blocks - 1]
                    659:          [STACK_POINTER_REGNUM / REGSET_ELT_BITS]
                    660:            |= 1 << (STACK_POINTER_REGNUM % REGSET_ELT_BITS);
                    661:       }
                    662: 
1.1       root      663:   /* Propagate life info through the basic blocks
                    664:      around the graph of basic blocks.
                    665: 
                    666:      This is a relaxation process: each time a new register
                    667:      is live at the end of the basic block, we must scan the block
                    668:      to determine which registers are, as a consequence, live at the beginning
                    669:      of that block.  These registers must then be marked live at the ends
                    670:      of all the blocks that can transfer control to that block.
                    671:      The process continues until it reaches a fixed point.  */
                    672: 
                    673:   first_pass = 1;
                    674:   changed = 1;
                    675:   while (changed)
                    676:     {
                    677:       changed = 0;
                    678:       for (i = n_basic_blocks - 1; i >= 0; i--)
                    679:        {
                    680:          int consider = first_pass;
                    681:          int must_rescan = first_pass;
                    682:          register int j;
                    683: 
                    684:          /* Set CONSIDER if this block needs thinking about at all
                    685:             (that is, if the regs live now at the end of it
                    686:             are not the same as were live at the end of it when
                    687:             we last thought about it).
                    688:             Set must_rescan if it needs to be thought about
                    689:             instruction by instruction (that is, if any additional
                    690:             reg that is live at the end now but was not live there before
                    691:             is one of the significant regs of this basic block).  */
                    692: 
                    693:          for (j = 0; j < regset_size; j++)
                    694:            {
                    695:              register int x = basic_block_new_live_at_end[i][j]
                    696:                      & ~basic_block_live_at_end[i][j];
                    697:              if (x)
                    698:                consider = 1;
                    699:              if (x & basic_block_significant[i][j])
                    700:                {
                    701:                  must_rescan = 1;
                    702:                  consider = 1;
                    703:                  break;
                    704:                }
                    705:            }
                    706: 
                    707:          if (! consider)
                    708:            continue;
                    709: 
                    710:          /* The live_at_start of this block may be changing,
                    711:             so another pass will be required after this one.  */
                    712:          changed = 1;
                    713: 
                    714:          if (! must_rescan)
                    715:            {
                    716:              /* No complete rescan needed;
                    717:                 just record those variables newly known live at end
                    718:                 as live at start as well.  */
                    719:              for (j = 0; j < regset_size; j++)
                    720:                {
                    721:                  register int x = basic_block_new_live_at_end[i][j]
                    722:                        & ~basic_block_live_at_end[i][j];
                    723:                  basic_block_live_at_start[i][j] |= x;
                    724:                  basic_block_live_at_end[i][j] |= x;
                    725:                }
                    726:            }
                    727:          else
                    728:            {
                    729:              /* Update the basic_block_live_at_start
                    730:                 by propagation backwards through the block.  */
                    731:              bcopy (basic_block_new_live_at_end[i],
                    732:                     basic_block_live_at_end[i], regset_bytes);
                    733:              bcopy (basic_block_live_at_end[i],
                    734:                     basic_block_live_at_start[i], regset_bytes);
                    735:              propagate_block (basic_block_live_at_start[i],
                    736:                               basic_block_head[i], basic_block_end[i], 0,
                    737:                               first_pass ? basic_block_significant[i] : 0,
                    738:                               i);
                    739:            }
                    740: 
                    741:          {
                    742:            register rtx jump, head;
                    743:            /* Update the basic_block_new_live_at_end's of the block
                    744:               that falls through into this one (if any).  */
                    745:            head = basic_block_head[i];
                    746:            jump = PREV_INSN (head);
                    747:            if (basic_block_drops_in[i])
                    748:              {
                    749:                register from_block = BLOCK_NUM (jump);
                    750:                register int j;
                    751:                for (j = 0; j < regset_size; j++)
                    752:                  basic_block_new_live_at_end[from_block][j]
                    753:                    |= basic_block_live_at_start[i][j];
                    754:              }
                    755:            /* Update the basic_block_new_live_at_end's of
                    756:               all the blocks that jump to this one.  */
                    757:            if (GET_CODE (head) == CODE_LABEL)
                    758:              for (jump = LABEL_REFS (head);
                    759:                   jump != head;
                    760:                   jump = LABEL_NEXTREF (jump))
                    761:                {
                    762:                  register from_block = BLOCK_NUM (CONTAINING_INSN (jump));
                    763:                  register int j;
                    764:                  for (j = 0; j < regset_size; j++)
                    765:                    basic_block_new_live_at_end[from_block][j]
                    766:                      |= basic_block_live_at_start[i][j];
                    767:                }
                    768:          }
                    769:        }
                    770:       first_pass = 0;
                    771:     }
                    772: 
1.1.1.5   root      773: #if 0 /* This seems unnecessary; life at start of function shouldn't
                    774:         mean that the reg is live in more than one basic block.  */
                    775: 
1.1.1.2   root      776:   /* Process the regs live at the beginning of the function.
                    777:      Mark them as not local to any one basic block.  */
                    778: 
                    779:   if (n_basic_blocks > 0)
                    780:     for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
                    781:       if (basic_block_live_at_start[0][i / REGSET_ELT_BITS]
                    782:          & (1 << (i % REGSET_ELT_BITS)))
1.1.1.4   root      783:        reg_basic_block[i] = REG_BLOCK_GLOBAL;
1.1.1.5   root      784: #endif
1.1.1.2   root      785: 
1.1       root      786:   /* Now the life information is accurate.
                    787:      Make one more pass over each basic block
                    788:      to delete dead stores, create autoincrement addressing
                    789:      and record how many times each register is used, is set, or dies.
                    790: 
                    791:      To save time, we operate directly in basic_block_live_at_end[i],
                    792:      thus destroying it (in fact, converting it into a copy of
                    793:      basic_block_live_at_start[i]).  This is ok now because
                    794:      basic_block_live_at_end[i] is no longer used past this point.  */
                    795: 
                    796:   for (i = 0; i < n_basic_blocks; i++)
                    797:     {
                    798:       propagate_block (basic_block_live_at_end[i],
                    799:                       basic_block_head[i], basic_block_end[i], 1, 0, i);
                    800:     }
                    801: }
                    802: 
                    803: /* Subroutines of life analysis.  */
                    804: 
                    805: /* Allocate the permanent data structures that represent the results
                    806:    of life analysis.  Not static since used also for stupid life analysis.  */
                    807: 
                    808: void
                    809: allocate_for_life_analysis ()
                    810: {
                    811:   register int i;
                    812:   register regset tem;
                    813: 
                    814:   regset_size = ((max_regno + REGSET_ELT_BITS - 1) / REGSET_ELT_BITS);
                    815:   regset_bytes = regset_size * sizeof (*(regset)0);
                    816: 
                    817:   reg_n_refs = (short *) oballoc (max_regno * sizeof (short));
                    818:   bzero (reg_n_refs, max_regno * sizeof (short));
                    819: 
                    820:   reg_n_sets = (short *) oballoc (max_regno * sizeof (short));
                    821:   bzero (reg_n_sets, max_regno * sizeof (short));
                    822: 
                    823:   reg_n_deaths = (short *) oballoc (max_regno * sizeof (short));
                    824:   bzero (reg_n_deaths, max_regno * sizeof (short));
                    825: 
                    826:   reg_live_length = (int *) oballoc (max_regno * sizeof (int));
                    827:   bzero (reg_live_length, max_regno * sizeof (int));
                    828: 
                    829:   reg_crosses_call = (char *) oballoc (max_regno);
                    830:   bzero (reg_crosses_call, max_regno);
                    831: 
                    832:   reg_basic_block = (short *) oballoc (max_regno * sizeof (short));
                    833:   for (i = 0; i < max_regno; i++)
1.1.1.4   root      834:     reg_basic_block[i] = REG_BLOCK_UNKNOWN;
1.1       root      835: 
                    836:   basic_block_live_at_start = (regset *) oballoc (n_basic_blocks * sizeof (regset));
                    837:   tem = (regset) oballoc (n_basic_blocks * regset_bytes);
                    838:   bzero (tem, n_basic_blocks * regset_bytes);
                    839:   init_regset_vector (basic_block_live_at_start, tem, n_basic_blocks, regset_bytes);
1.1.1.2   root      840: 
                    841:   regs_live_at_setjmp = (regset) oballoc (regset_bytes);
                    842:   bzero (regs_live_at_setjmp, regset_bytes);
1.1       root      843: }
                    844: 
                    845: /* Make each element of VECTOR point at a regset,
                    846:    taking the space for all those regsets from SPACE.
                    847:    SPACE is of type regset, but it is really as long as NELTS regsets.
                    848:    BYTES_PER_ELT is the number of bytes in one regset.  */
                    849: 
                    850: static void
                    851: init_regset_vector (vector, space, nelts, bytes_per_elt)
                    852:      regset *vector;
                    853:      regset space;
                    854:      int nelts;
                    855:      int bytes_per_elt;
                    856: {
                    857:   register int i;
                    858:   register regset p = space;
                    859: 
                    860:   for (i = 0; i < nelts; i++)
                    861:     {
                    862:       vector[i] = p;
                    863:       p += bytes_per_elt / sizeof (*p);
                    864:     }
                    865: }
                    866: 
                    867: /* Compute the registers live at the beginning of a basic block
                    868:    from those live at the end.
                    869: 
                    870:    When called, OLD contains those live at the end.
                    871:    On return, it contains those live at the beginning.
                    872:    FIRST and LAST are the first and last insns of the basic block.
                    873: 
                    874:    FINAL is nonzero if we are doing the final pass which is not
                    875:    for computing the life info (since that has already been done)
                    876:    but for acting on it.  On this pass, we delete dead stores,
                    877:    set up the logical links and dead-variables lists of instructions,
                    878:    and merge instructions for autoincrement and autodecrement addresses.
                    879: 
                    880:    SIGNIFICANT is nonzero only the first time for each basic block.
                    881:    If it is nonzero, it points to a regset in which we store
                    882:    a 1 for each register that is set within the block.
                    883: 
                    884:    BNUM is the number of the basic block.  */
                    885: 
                    886: static void
                    887: propagate_block (old, first, last, final, significant, bnum)
                    888:      register regset old;
                    889:      rtx first;
                    890:      rtx last;
                    891:      int final;
                    892:      regset significant;
                    893:      int bnum;
                    894: {
                    895:   register rtx insn;
                    896:   rtx prev;
                    897:   regset live;
                    898:   regset dead;
                    899: 
                    900:   /* The following variables are used only if FINAL is nonzero.  */
                    901:   /* This vector gets one element for each reg that has been live
                    902:      at any point in the basic block that has been scanned so far.
                    903:      SOMETIMES_MAX says how many elements are in use so far.
                    904:      In each element, OFFSET is the byte-number within a regset
                    905:      for the register described by the element, and BIT is a mask
                    906:      for that register's bit within the byte.  */
                    907:   register struct foo { short offset; short bit; } *regs_sometimes_live;
                    908:   int sometimes_max = 0;
                    909:   /* This regset has 1 for each reg that we have seen live so far.
                    910:      It and REGS_SOMETIMES_LIVE are updated together.  */
                    911:   regset maxlive;
                    912: 
                    913:   loop_depth = basic_block_loop_depth[bnum];
                    914: 
                    915:   dead = (regset) alloca (regset_bytes);
                    916:   live = (regset) alloca (regset_bytes);
                    917: 
                    918:   if (final)
                    919:     {
                    920:       register int i, offset, bit;
                    921: 
                    922:       maxlive = (regset) alloca (regset_bytes);
                    923:       bcopy (old, maxlive, regset_bytes);
                    924:       regs_sometimes_live
                    925:        = (struct foo *) alloca (max_regno * sizeof (struct foo));
                    926: 
                    927:       /* Process the regs live at the end of the block.
                    928:         Enter them in MAXLIVE and REGS_SOMETIMES_LIVE.
                    929:         Also mark them as not local to any one basic block.  */
                    930: 
                    931:       for (offset = 0, i = 0; offset < regset_size; offset++)
                    932:        for (bit = 1; bit; bit <<= 1, i++)
                    933:          {
                    934:            if (i == max_regno)
                    935:              break;
                    936:            if (old[offset] & bit)
                    937:              {
1.1.1.4   root      938:                reg_basic_block[i] = REG_BLOCK_GLOBAL;
1.1       root      939:                regs_sometimes_live[sometimes_max].offset = offset;
                    940:                regs_sometimes_live[sometimes_max].bit = i % REGSET_ELT_BITS;
                    941:                sometimes_max++;
                    942:              }
                    943:          }
                    944:     }
                    945: 
                    946:   /* Scan the block an insn at a time from end to beginning.  */
                    947: 
                    948:   for (insn = last; ; insn = prev)
                    949:     {
                    950:       prev = PREV_INSN (insn);
                    951: 
1.1.1.2   root      952:       /* If this is a call to `setjmp' et al,
                    953:         warn if any non-volatile datum is live.  */
                    954: 
                    955:       if (final && GET_CODE (insn) == NOTE
                    956:          && NOTE_LINE_NUMBER (insn) == NOTE_INSN_SETJMP)
                    957:        {
                    958:          int i;
                    959:          for (i = 0; i < regset_size; i++)
                    960:            regs_live_at_setjmp[i] |= old[i];
1.1       root      961:        }
                    962: 
                    963:       /* Update the life-status of regs for this insn.
                    964:         First DEAD gets which regs are set in this insn
                    965:         then LIVE gets which regs are used in this insn.
                    966:         Then the regs live before the insn
                    967:         are those live after, with DEAD regs turned off,
                    968:         and then LIVE regs turned on.  */
                    969: 
                    970:       if (GET_CODE (insn) == INSN
                    971:          || GET_CODE (insn) == JUMP_INSN
                    972:          || GET_CODE (insn) == CALL_INSN)
                    973:        {
                    974:          register int i;
1.1.1.2   root      975:          rtx note = find_reg_note (insn, REG_RETVAL, 0);
                    976: 
1.1       root      977:          /* If an instruction consists of just dead store(s) on final pass,
                    978:             "delete" it by turning it into a NOTE of type NOTE_INSN_DELETED.
                    979:             We could really delete it with delete_insn, but that
                    980:             can cause trouble for first or last insn in a basic block.  */
1.1.1.2   root      981:          if (final && insn_dead_p (PATTERN (insn), old, 1)
                    982:              /* Don't delete something that refers to volatile storage!  */
                    983:              && ! INSN_VOLATILE (insn))
1.1       root      984:            {
                    985:              PUT_CODE (insn, NOTE);
                    986:              NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
                    987:              NOTE_SOURCE_FILE (insn) = 0;
1.1.1.2   root      988:              /* If this insn is copying the return value from a library call,
                    989:                 delete the entire library call.  */
                    990:              if (note)
                    991:                {
                    992:                  rtx first = XEXP (note, 0);
                    993:                  rtx prev = insn;
1.1.1.9 ! root      994:                  while (INSN_DELETED_P (first))
1.1.1.2   root      995:                    first = NEXT_INSN (first);
                    996:                  while (prev != first)
                    997:                    {
                    998:                      prev = PREV_INSN (prev);
                    999:                      PUT_CODE (prev, NOTE);
                   1000:                      NOTE_LINE_NUMBER (prev) = NOTE_INSN_DELETED;
                   1001:                      NOTE_SOURCE_FILE (prev) = 0;
                   1002:                    }
                   1003:                }
1.1       root     1004:              goto flushed;
                   1005:            }
1.1.1.2   root     1006: 
                   1007:          for (i = 0; i < regset_size; i++)
1.1       root     1008:            {
1.1.1.2   root     1009:              dead[i] = 0;      /* Faster than bzero here */
                   1010:              live[i] = 0;      /* since regset_size is usually small */
                   1011:            }
1.1       root     1012: 
1.1.1.2   root     1013:          /* See if this is an increment or decrement that can be
                   1014:             merged into a following memory address.  */
                   1015: #ifdef AUTO_INC_DEC
                   1016:          {
                   1017:            register rtx x = PATTERN (insn);
                   1018:            /* Does this instruction increment or decrement a register?  */
                   1019:            if (final && GET_CODE (x) == SET
                   1020:                && GET_CODE (SET_DEST (x)) == REG
                   1021:                && (GET_CODE (SET_SRC (x)) == PLUS
                   1022:                    || GET_CODE (SET_SRC (x)) == MINUS)
                   1023:                && XEXP (SET_SRC (x), 0) == SET_DEST (x)
                   1024:                && GET_CODE (XEXP (SET_SRC (x), 1)) == CONST_INT
                   1025:                /* Ok, look for a following memory ref we can combine with.
                   1026:                   If one is found, change the memory ref to a PRE_INC
                   1027:                   or PRE_DEC, cancel this insn, and return 1.
                   1028:                   Return 0 if nothing has been done.  */
                   1029:                && try_pre_increment_1 (insn))
                   1030:              goto flushed;
                   1031:          }
                   1032: #endif /* AUTO_INC_DEC */
1.1       root     1033: 
1.1.1.2   root     1034:          /* If this is not the final pass, and this insn is copying the
                   1035:             value of a library call and it's dead, don't scan the
                   1036:             insns that perform the library call, so that the call's
                   1037:             arguments are not marked live.  */
                   1038:          if (note && insn_dead_p (PATTERN (insn), old, 1))
1.1.1.3   root     1039:            {
1.1.1.4   root     1040:              /* Mark the dest reg as `significant'.  */
                   1041:              mark_set_regs (old, dead, PATTERN (insn), 0, significant);
                   1042: 
1.1.1.3   root     1043:              insn = XEXP (note, 0);
                   1044:              prev = PREV_INSN (insn);
                   1045:            }
1.1.1.9 ! root     1046:          else if (GET_CODE (PATTERN (insn)) == SET
        !          1047:                   && SET_DEST (PATTERN (insn)) == stack_pointer_rtx
1.1.1.4   root     1048:                   && GET_CODE (SET_SRC (PATTERN (insn))) == PLUS
                   1049:                   && XEXP (SET_SRC (PATTERN (insn)), 0) == stack_pointer_rtx
                   1050:                   && GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 1)) == CONST_INT)
                   1051:            /* These insns, if not dead stores, have no effect on life.  */
                   1052:            ;
1.1.1.2   root     1053:          else
                   1054:            {
                   1055:              /* LIVE gets the regs used in INSN; DEAD gets those set by it.  */
1.1       root     1056:              mark_set_regs (old, dead, PATTERN (insn), final ? insn : 0,
                   1057:                             significant);
1.1.1.2   root     1058:              mark_used_regs (old, live, PATTERN (insn), final, insn);
1.1       root     1059: 
                   1060:              /* Update OLD for the registers used or set.  */
                   1061:              for (i = 0; i < regset_size; i++)
                   1062:                {
                   1063:                  old[i] &= ~dead[i];
                   1064:                  old[i] |= live[i];
                   1065:                }
                   1066: 
1.1.1.2   root     1067:              if (GET_CODE (insn) == CALL_INSN)
                   1068:                {
                   1069:                  register int i;
                   1070: 
                   1071:                  /* Each call clobbers all call-clobbered regs.
                   1072:                     Note that the function-value reg is one of these, and
                   1073:                     mark_set_regs has already had a chance to handle it.  */
                   1074:                  for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
                   1075:                    if (call_used_regs[i])
1.1.1.9 ! root     1076:                      dead[i / REGSET_ELT_BITS] |=
        !          1077:                        (1 << (i % REGSET_ELT_BITS));
1.1.1.2   root     1078: 
                   1079:                  /* The stack ptr is used (honorarily) by a CALL insn.  */
1.1.1.9 ! root     1080:                  live[STACK_POINTER_REGNUM / REGSET_ELT_BITS]
1.1.1.2   root     1081:                    |= (1 << (STACK_POINTER_REGNUM % REGSET_ELT_BITS));
1.1.1.9 ! root     1082:                }
1.1.1.2   root     1083: 
1.1.1.9 ! root     1084:              /* Update OLD for the registers used or set.  */
        !          1085:              for (i = 0; i < regset_size; i++)
        !          1086:                {
        !          1087:                  old[i] &= ~dead[i];
        !          1088:                  old[i] |= live[i];
        !          1089:                }
        !          1090: 
        !          1091:              if (GET_CODE (insn) == CALL_INSN && final)
        !          1092:                {
        !          1093:                  /* Any regs live at the time of a call instruction
        !          1094:                     must not go in a register clobbered by calls.
        !          1095:                     Find all regs now live and record this for them.  */
        !          1096: 
        !          1097:                  register struct foo *p = regs_sometimes_live;
        !          1098: 
        !          1099:                  for (i = 0; i < sometimes_max; i++, p++)
        !          1100:                    if (old[p->offset] & (1 << p->bit))
        !          1101:                      reg_crosses_call[p->offset * REGSET_ELT_BITS + p->bit] = 1;
1.1.1.2   root     1102:                }
                   1103:            }
                   1104: 
                   1105:          /* On final pass, add any additional sometimes-live regs
                   1106:             into MAXLIVE and REGS_SOMETIMES_LIVE.
                   1107:             Also update counts of how many insns each reg is live at.  */
1.1       root     1108: 
1.1.1.2   root     1109:          if (final)
                   1110:            {
                   1111:              for (i = 0; i < regset_size; i++)
1.1       root     1112:                {
1.1.1.2   root     1113:                  register int diff = live[i] & ~maxlive[i];
1.1       root     1114: 
1.1.1.2   root     1115:                  if (diff)
                   1116:                    {
                   1117:                      register int regno;
                   1118:                      maxlive[i] |= diff;
                   1119:                      for (regno = 0; diff && regno < REGSET_ELT_BITS; regno++)
                   1120:                        if (diff & (1 << regno))
                   1121:                          {
                   1122:                            regs_sometimes_live[sometimes_max].offset = i;
                   1123:                            regs_sometimes_live[sometimes_max].bit = regno;
                   1124:                            diff &= ~ (1 << regno);
                   1125:                            sometimes_max++;
                   1126:                          }
                   1127:                    }
                   1128:                }
1.1       root     1129: 
1.1.1.2   root     1130:              {
                   1131:                register struct foo *p = regs_sometimes_live;
                   1132:                for (i = 0; i < sometimes_max; i++, p++)
1.1       root     1133:                  {
1.1.1.2   root     1134:                    if (old[p->offset] & (1 << p->bit))
                   1135:                      reg_live_length[p->offset * REGSET_ELT_BITS + p->bit]++;
1.1       root     1136:                  }
1.1.1.2   root     1137:              }
1.1       root     1138:            }
                   1139:        }
1.1.1.2   root     1140:     flushed: ;
1.1       root     1141:       if (insn == first)
                   1142:        break;
                   1143:     }
                   1144: }
                   1145: 
                   1146: /* Return 1 if X (the body of an insn, or part of it) is just dead stores
                   1147:    (SET expressions whose destinations are registers dead after the insn).
                   1148:    NEEDED is the regset that says which regs are alive after the insn.  */
                   1149: 
                   1150: static int
1.1.1.2   root     1151: insn_dead_p (x, needed, strict_low_ok)
1.1       root     1152:      rtx x;
                   1153:      regset needed;
1.1.1.2   root     1154:      int strict_low_ok;
1.1       root     1155: {
                   1156:   register RTX_CODE code = GET_CODE (x);
1.1.1.2   root     1157: #if 0
1.1       root     1158:   /* Make sure insns to set the stack pointer are never deleted.  */
                   1159:   needed[STACK_POINTER_REGNUM / REGSET_ELT_BITS]
                   1160:     |= 1 << (STACK_POINTER_REGNUM % REGSET_ELT_BITS);
1.1.1.2   root     1161: #endif
                   1162: 
                   1163:   /* If setting something that's a reg or part of one,
                   1164:      see if that register's altered value will be live.  */
                   1165: 
                   1166:   if (code == SET)
1.1       root     1167:     {
1.1.1.2   root     1168:       register rtx r = SET_DEST (x);
                   1169:       /* A SET that is a subroutine call cannot be dead.  */
                   1170:       if (GET_CODE (SET_SRC (x)) == CALL)
                   1171:        return 0;
                   1172:       while (GET_CODE (r) == SUBREG
                   1173:             || (strict_low_ok && GET_CODE (r) == STRICT_LOW_PART)
                   1174:             || GET_CODE (r) == ZERO_EXTRACT
                   1175:             || GET_CODE (r) == SIGN_EXTRACT)
                   1176:        r = SUBREG_REG (r);
                   1177:       if (GET_CODE (r) == REG)
                   1178:        {
                   1179:          register int regno = REGNO (r);
                   1180:          register int offset = regno / REGSET_ELT_BITS;
                   1181:          register int bit = 1 << (regno % REGSET_ELT_BITS);
                   1182:          return (needed[offset] & bit) == 0;
                   1183:        }
1.1       root     1184:     }
1.1.1.2   root     1185:   /* If performing several activities,
                   1186:      insn is dead if each activity is individually dead.
                   1187:      Also, CLOBBERs and USEs can be ignored; a CLOBBER or USE
                   1188:      that's inside a PARALLEL doesn't make the insn worth keeping.  */
                   1189:   else if (code == PARALLEL)
1.1       root     1190:     {
                   1191:       register int i = XVECLEN (x, 0);
                   1192:       for (i--; i >= 0; i--)
1.1.1.2   root     1193:        {
                   1194:          rtx elt = XVECEXP (x, 0, i);
                   1195:          if (!insn_dead_p (elt, needed, strict_low_ok)
                   1196:              && GET_CODE (elt) != CLOBBER
                   1197:              && GET_CODE (elt) != USE)
                   1198:            return 0;
                   1199:        }
1.1       root     1200:       return 1;
                   1201:     }
1.1.1.2   root     1202:   /* We do not check CLOBBER or USE here.
                   1203:      An insn consisting of just a CLOBBER or just a USE
                   1204:      should not be deleted.  */
1.1       root     1205:   return 0;
                   1206: }
                   1207: 
1.1.1.2   root     1208: /* Return 1 if register REGNO was used before it was set.
                   1209:    In other words, if it is live at function entry.  */
1.1       root     1210: 
1.1.1.2   root     1211: int
                   1212: regno_uninitialized (regno)
1.1       root     1213:      int regno;
                   1214: {
1.1.1.2   root     1215:   return (basic_block_live_at_start[0][regno / REGSET_ELT_BITS]
                   1216:          & (1 << (regno % REGSET_ELT_BITS)));
                   1217: }
                   1218: 
                   1219: /* 1 if register REGNO was alive at a place where `setjmp' was called
                   1220:    and was set more than once.  Such regs may be clobbered by `longjmp'.  */
                   1221: 
                   1222: int
                   1223: regno_clobbered_at_setjmp (regno)
                   1224:      int regno;
                   1225: {
                   1226:   return (reg_n_sets[regno] > 1
                   1227:          && (regs_live_at_setjmp[regno / REGSET_ELT_BITS]
                   1228:              & (1 << (regno % REGSET_ELT_BITS))));
1.1       root     1229: }
                   1230: 
                   1231: /* Process the registers that are set within X.
                   1232:    Their bits are set to 1 in the regset DEAD,
                   1233:    because they are dead prior to this insn.
                   1234: 
                   1235:    If INSN is nonzero, it is the insn being processed
                   1236:    and the fact that it is nonzero implies this is the FINAL pass
                   1237:    in propagate_block.  In this case, various info about register
                   1238:    usage is stored, LOG_LINKS fields of insns are set up.  */
                   1239: 
                   1240: static void mark_set_1 ();
                   1241: 
                   1242: static void
                   1243: mark_set_regs (needed, dead, x, insn, significant)
                   1244:      regset needed;
                   1245:      regset dead;
                   1246:      rtx x;
                   1247:      rtx insn;
                   1248:      regset significant;
                   1249: {
                   1250:   register RTX_CODE code = GET_CODE (x);
                   1251: 
                   1252:   if (code == SET || code == CLOBBER)
                   1253:     mark_set_1 (needed, dead, x, insn, significant);
                   1254:   else if (code == PARALLEL)
                   1255:     {
                   1256:       register int i;
                   1257:       for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
                   1258:        {
                   1259:          code = GET_CODE (XVECEXP (x, 0, i));
                   1260:          if (code == SET || code == CLOBBER)
                   1261:            mark_set_1 (needed, dead, XVECEXP (x, 0, i), insn, significant);
                   1262:        }
                   1263:     }
                   1264: }
                   1265: 
                   1266: /* Process a single SET rtx, X.  */
                   1267: 
                   1268: static void
                   1269: mark_set_1 (needed, dead, x, insn, significant)
                   1270:      regset needed;
                   1271:      regset dead;
                   1272:      rtx x;
                   1273:      rtx insn;
                   1274:      regset significant;
                   1275: {
                   1276:   register int regno;
                   1277:   register rtx reg = SET_DEST (x);
                   1278: 
1.1.1.2   root     1279:   if (reg == 0)
                   1280:     return;
                   1281: 
1.1       root     1282:   if (GET_CODE (reg) == SUBREG)
                   1283:     {
                   1284:       /* Modifying just one hardware register
                   1285:         of a multi-register value does not count as "setting"
                   1286:         for live-dead analysis.  Parts of the previous value
                   1287:         might still be significant below this insn.  */
                   1288:       if (REG_SIZE (SUBREG_REG (reg)) > REG_SIZE (reg))
                   1289:        return;
                   1290: 
                   1291:       reg = SUBREG_REG (reg);
                   1292:     }
                   1293: 
                   1294:   if (GET_CODE (reg) == REG
                   1295:       && (regno = REGNO (reg), regno != FRAME_POINTER_REGNUM)
1.1.1.2   root     1296:       && regno != ARG_POINTER_REGNUM)
                   1297:     /* && regno != STACK_POINTER_REGNUM) -- let's try without this.  */
1.1       root     1298:     {
                   1299:       register int offset = regno / REGSET_ELT_BITS;
                   1300:       register int bit = 1 << (regno % REGSET_ELT_BITS);
1.1.1.2   root     1301:       int is_needed = 0;
                   1302: 
1.1       root     1303:       /* Mark the reg being set as dead before this insn.  */
                   1304:       dead[offset] |= bit;
                   1305:       /* Mark it as a significant register for this basic block.  */
                   1306:       if (significant)
                   1307:        significant[offset] |= bit;
1.1.1.2   root     1308:       /* A hard reg in a wide mode may really be multiple registers.
                   1309:         If so, mark all of them just like the first.  */
                   1310:       if (regno < FIRST_PSEUDO_REGISTER)
                   1311:        {
1.1.1.4   root     1312:          int n;
                   1313: 
                   1314:          /* Nothing below is needed for the stack pointer; get out asap.
                   1315:             Eg, log links aren't needed, since combine won't use them.  */
                   1316:          if (regno == STACK_POINTER_REGNUM)
                   1317:            return;
                   1318: 
                   1319:          n = HARD_REGNO_NREGS (regno, GET_MODE (reg));
1.1.1.2   root     1320:          while (--n > 0)
                   1321:            {
                   1322:              dead[(regno + n) / REGSET_ELT_BITS]
                   1323:                |= 1 << ((regno + n) % REGSET_ELT_BITS);
                   1324:              if (significant)
                   1325:                significant[(regno + n) / REGSET_ELT_BITS]
                   1326:                  |= 1 << ((regno + n) % REGSET_ELT_BITS);
                   1327:              is_needed |= (needed[(regno + n) / REGSET_ELT_BITS]
                   1328:                            & 1 << ((regno + n) % REGSET_ELT_BITS));
                   1329:            }
                   1330:        }
1.1       root     1331:       /* Additional data to record if this is the final pass.  */
                   1332:       if (insn)
                   1333:        {
                   1334:          register rtx y = reg_next_use[regno];
                   1335:          register int blocknum = BLOCK_NUM (insn);
                   1336: 
1.1.1.9 ! root     1337:          /* If this is a hard reg, record this function uses the reg.
        !          1338:             `combine.c' will get confused if LOG_LINKs are made
        !          1339:             for hard regs.  */
1.1       root     1340: 
                   1341:          if (regno < FIRST_PSEUDO_REGISTER)
                   1342:            {
                   1343:              register int i;
                   1344:              i = HARD_REGNO_NREGS (regno, GET_MODE (reg));
1.1.1.8   root     1345:              if (i == 0)
                   1346:                i = 1;
1.1       root     1347:              do
                   1348:                regs_ever_live[regno + --i] = 1;
                   1349:              while (i > 0);
1.1.1.4   root     1350: 
                   1351:              if (! ((needed[offset] & bit) || is_needed))
                   1352:                {
                   1353:                  /* Note that dead stores have already been deleted if poss.
                   1354:                     If we get here, we have found a dead store that cannot
                   1355:                     be eliminated (because the insn does something useful).
                   1356:                     Indicate this by marking the reg set as dying here.  */
                   1357:                  REG_NOTES (insn)
                   1358:                    = gen_rtx (EXPR_LIST, REG_DEAD,
                   1359:                               reg, REG_NOTES (insn));
                   1360:                  reg_n_deaths[REGNO (reg)]++;
                   1361:                }
                   1362:              return;
1.1       root     1363:            }
                   1364: 
                   1365:          /* Keep track of which basic blocks each reg appears in.  */
                   1366: 
1.1.1.4   root     1367:          if (reg_basic_block[regno] == REG_BLOCK_UNKNOWN)
1.1       root     1368:            reg_basic_block[regno] = blocknum;
                   1369:          else if (reg_basic_block[regno] != blocknum)
1.1.1.4   root     1370:            reg_basic_block[regno] = REG_BLOCK_GLOBAL;
1.1       root     1371: 
                   1372:          /* Count (weighted) references, stores, etc.  */
                   1373:          reg_n_refs[regno] += loop_depth;
                   1374:          reg_n_sets[regno]++;
1.1.1.2   root     1375:          /* The next use is no longer "next", since a store intervenes.  */
                   1376:          reg_next_use[regno] = 0;
1.1       root     1377:          /* The insns where a reg is live are normally counted elsewhere,
                   1378:             but we want the count to include the insn where the reg is set,
                   1379:             and the normal counting mechanism would not count it.  */
                   1380:          reg_live_length[regno]++;
1.1.1.2   root     1381:          if ((needed[offset] & bit) || is_needed)
1.1       root     1382:            {
                   1383:              /* Make a logical link from the next following insn
                   1384:                 that uses this register, back to this insn.
                   1385:                 The following insns have already been processed.  */
                   1386:              if (y && (BLOCK_NUM (y) == blocknum))
                   1387:                LOG_LINKS (y)
                   1388:                  = gen_rtx (INSN_LIST, VOIDmode, insn, LOG_LINKS (y));
                   1389:            }
                   1390:          else
                   1391:            {
                   1392:              /* Note that dead stores have already been deleted when possible
                   1393:                 If we get here, we have found a dead store that cannot
                   1394:                 be eliminated (because the same insn does something useful).
                   1395:                 Indicate this by marking the reg being set as dying here.  */
                   1396:              REG_NOTES (insn)
                   1397:                = gen_rtx (EXPR_LIST, REG_DEAD,
                   1398:                           reg, REG_NOTES (insn));
1.1.1.3   root     1399:              reg_n_deaths[REGNO (reg)]++;
1.1       root     1400:            }
                   1401:        }
                   1402:     }
                   1403: }
                   1404: 
                   1405: /* Scan expression X and store a 1-bit in LIVE for each reg it uses.
                   1406:    This is done assuming the registers needed from X
                   1407:    are those that have 1-bits in NEEDED.
                   1408: 
1.1.1.2   root     1409:    On the final pass, FINAL is 1.  This means try for autoincrement
                   1410:    and count the uses and deaths of each pseudo-reg.
                   1411: 
                   1412:    INSN is the containing instruction.  */
1.1       root     1413: 
                   1414: static void
1.1.1.2   root     1415: mark_used_regs (needed, live, x, final, insn)
1.1       root     1416:      regset needed;
                   1417:      regset live;
                   1418:      rtx x;
                   1419:      rtx insn;
1.1.1.2   root     1420:      int final;
1.1       root     1421: {
                   1422:   register RTX_CODE code;
                   1423:   register int regno;
                   1424: 
                   1425:  retry:
                   1426:   code = GET_CODE (x);
                   1427:   switch (code)
                   1428:     {
                   1429:     case LABEL_REF:
                   1430:     case SYMBOL_REF:
                   1431:     case CONST_INT:
                   1432:     case CONST:
1.1.1.4   root     1433:     case CONST_DOUBLE:
1.1       root     1434:     case CC0:
                   1435:     case PC:
                   1436:     case CLOBBER:
1.1.1.4   root     1437:     case ADDR_VEC:
                   1438:     case ADDR_DIFF_VEC:
                   1439:     case ASM_INPUT:
1.1       root     1440:       return;
                   1441: 
                   1442: #if defined (HAVE_POST_INCREMENT) || defined (HAVE_POST_DECREMENT)
                   1443:     case MEM:
                   1444:       /* Here we detect use of an index register which might
                   1445:         be good for postincrement or postdecrement.  */
1.1.1.2   root     1446:       if (final)
1.1       root     1447:        {
                   1448:          rtx addr = XEXP (x, 0);
                   1449:          register int size = GET_MODE_SIZE (GET_MODE (x));
                   1450: 
                   1451:          if (GET_CODE (addr) == REG)
                   1452:            {
                   1453:              register rtx y;
                   1454:              regno = REGNO (addr);
                   1455:              /* Is the next use an increment that might make auto-increment? */
                   1456:              y = reg_next_use[regno];
                   1457:              if (y && GET_CODE (PATTERN (y)) == SET
                   1458:                  && BLOCK_NUM (y) == BLOCK_NUM (insn)
                   1459:                  /* Can't add side effects to jumps; if reg is spilled and
                   1460:                     reloaded, there's no way to store back the altered value.  */
                   1461:                  && GET_CODE (insn) != JUMP_INSN
                   1462:                  && (y = SET_SRC (PATTERN (y)),
                   1463:                      (0
                   1464: #ifdef HAVE_POST_INCREMENT
                   1465:                       || GET_CODE (y) == PLUS
                   1466: #endif
                   1467: #ifdef HAVE_POST_DECREMENT
                   1468:                       || GET_CODE (y) == MINUS
                   1469: #endif
                   1470:                       )
                   1471:                      && XEXP (y, 0) == addr
                   1472:                      && GET_CODE (XEXP (y, 1)) == CONST_INT
1.1.1.2   root     1473:                      && INTVAL (XEXP (y, 1)) == size)
                   1474:                  && dead_or_set_p (reg_next_use[regno], addr))
1.1       root     1475:                {
1.1.1.2   root     1476:                  rtx use = find_use_as_address (PATTERN (insn), addr, 0);
1.1       root     1477: 
                   1478:                  /* Make sure this register appears only once in this insn.  */
                   1479:                  if (use != 0 && use != (rtx) 1)
                   1480:                    {
                   1481:                      /* We have found a suitable auto-increment:
                   1482:                         do POST_INC around the register here,
                   1483:                         and patch out the increment instruction that follows. */
                   1484:                      XEXP (x, 0)
                   1485:                        = gen_rtx (GET_CODE (y) == PLUS ? POST_INC : POST_DEC,
                   1486:                                   Pmode, addr);
                   1487:                      /* Record that this insn has an implicit side effect.  */
                   1488:                      REG_NOTES (insn)
                   1489:                        = gen_rtx (EXPR_LIST, REG_INC, addr, REG_NOTES (insn));
                   1490: 
1.1.1.2   root     1491:                      /* Modify the old increment-insn to simply copy
                   1492:                         the already-incremented value of our register.  */
1.1       root     1493:                      y = reg_next_use[regno];
1.1.1.2   root     1494:                      SET_SRC (PATTERN (y)) = addr;
                   1495: 
                   1496:                      /* If that makes it a no-op (copying the register
                   1497:                         into itself) then change it to a simpler no-op
                   1498:                         so it won't appear to be a "use" and a "set"
                   1499:                         of this register.  */
                   1500:                      if (SET_DEST (PATTERN (y)) == addr)
                   1501:                        PATTERN (y) = gen_rtx (USE, VOIDmode, const0_rtx);
                   1502: 
                   1503:                      /* Count an extra reference to the reg for the increment.
                   1504:                         When a reg is incremented.
1.1       root     1505:                         spilling it is worse, so we want to make that
                   1506:                         less likely.  */
                   1507:                      reg_n_refs[regno] += loop_depth;
1.1.1.2   root     1508:                      /* Count the increment as a setting of the register,
                   1509:                         even though it isn't a SET in rtl.  */
                   1510:                      reg_n_sets[regno]++;
1.1       root     1511:                    }
                   1512:                }
                   1513:            }
                   1514:        }
                   1515:       break;
                   1516: #endif /* HAVE_POST_INCREMENT or HAVE_POST_DECREMENT */
                   1517: 
                   1518:     case REG:
                   1519:       /* See a register other than being set
                   1520:         => mark it as needed.  */
                   1521: 
                   1522:       regno = REGNO (x);
                   1523:       if (regno != FRAME_POINTER_REGNUM
1.1.1.2   root     1524:          && regno != ARG_POINTER_REGNUM)
                   1525:        /* && regno != STACK_POINTER_REGNUM) -- let's try without this.  */
1.1       root     1526:        {
                   1527:          register int offset = regno / REGSET_ELT_BITS;
                   1528:          register int bit = 1 << (regno % REGSET_ELT_BITS);
1.1.1.2   root     1529:          int is_needed = 0;
                   1530: 
1.1       root     1531:          live[offset] |= bit;
1.1.1.2   root     1532:          /* A hard reg in a wide mode may really be multiple registers.
                   1533:             If so, mark all of them just like the first.  */
                   1534:          if (regno < FIRST_PSEUDO_REGISTER)
                   1535:            {
1.1.1.4   root     1536:              int n;
                   1537: 
                   1538:              /* For stack ptr, nothing below here can be necessary,
                   1539:                 so waste no more time.  */
                   1540:              if (regno == STACK_POINTER_REGNUM)
                   1541:                return;
                   1542: 
                   1543:              n = HARD_REGNO_NREGS (regno, GET_MODE (x));
1.1.1.2   root     1544:              while (--n > 0)
                   1545:                {
                   1546:                  live[(regno + n) / REGSET_ELT_BITS]
                   1547:                    |= 1 << ((regno + n) % REGSET_ELT_BITS);
                   1548:                  is_needed |= (needed[(regno + n) / REGSET_ELT_BITS]
                   1549:                                & 1 << ((regno + n) % REGSET_ELT_BITS));
                   1550:                }
                   1551:            }
                   1552:          if (final)
1.1       root     1553:            {
                   1554:              if (regno < FIRST_PSEUDO_REGISTER)
                   1555:                {
1.1.1.4   root     1556:                  /* If a hard reg is being used,
                   1557:                     record that this function does use it.  */
                   1558: 
1.1       root     1559:                  register int i;
                   1560:                  i = HARD_REGNO_NREGS (regno, GET_MODE (x));
1.1.1.8   root     1561:                  if (i == 0)
                   1562:                    i = 1;
1.1       root     1563:                  do
                   1564:                    regs_ever_live[regno + --i] = 1;
                   1565:                  while (i > 0);
                   1566:                }
1.1.1.4   root     1567:              else
                   1568:                {
                   1569:                  /* Keep track of which basic block each reg appears in.  */
1.1       root     1570: 
1.1.1.4   root     1571:                  register int blocknum = BLOCK_NUM (insn);
1.1       root     1572: 
1.1.1.4   root     1573:                  if (reg_basic_block[regno] == REG_BLOCK_UNKNOWN)
                   1574:                    reg_basic_block[regno] = blocknum;
                   1575:                  else if (reg_basic_block[regno] != blocknum)
                   1576:                    reg_basic_block[regno] = REG_BLOCK_GLOBAL;
1.1       root     1577: 
1.1.1.4   root     1578:                  /* Record where each reg is used, so when the reg
                   1579:                     is set we know the next insn that uses it.  */
1.1       root     1580: 
1.1.1.4   root     1581:                  reg_next_use[regno] = insn;
1.1       root     1582: 
1.1.1.4   root     1583:                  /* Count (weighted) number of uses of each reg.  */
1.1       root     1584: 
1.1.1.4   root     1585:                  reg_n_refs[regno] += loop_depth;
                   1586:                }
1.1       root     1587:              /* Record and count the insns in which a reg dies.
                   1588:                 If it is used in this insn and was dead below the insn
                   1589:                 then it dies in this insn.  */
                   1590: 
1.1.1.2   root     1591:              if (!(needed[offset] & bit) && !is_needed
                   1592:                  && ! find_regno_note (insn, REG_DEAD, regno))
1.1       root     1593:                {
                   1594:                  REG_NOTES (insn)
                   1595:                    = gen_rtx (EXPR_LIST, REG_DEAD, x, REG_NOTES (insn));
                   1596:                  reg_n_deaths[regno]++;
                   1597:                }
                   1598:            }
                   1599:        }
                   1600:       return;
                   1601: 
                   1602:     case SET:
                   1603:       {
1.1.1.2   root     1604:        register rtx testreg = SET_DEST (x);
                   1605:        int mark_dest = 0;
1.1       root     1606: 
1.1.1.2   root     1607:        /* Storing in STRICT_LOW_PART is like storing in a reg
                   1608:           in that this SET might be dead, so ignore it in TESTREG.
                   1609:           but in some other ways it is like using the reg.  */
                   1610:        /* Storing in a SUBREG or a bit field is like storing the entire
                   1611:           register in that if the register's value is not used
                   1612:           then this SET is not needed.  */
                   1613:        while (GET_CODE (testreg) == STRICT_LOW_PART
                   1614:               || GET_CODE (testreg) == ZERO_EXTRACT
                   1615:               || GET_CODE (testreg) == SIGN_EXTRACT
                   1616:               || GET_CODE (testreg) == SUBREG)
                   1617:          {
                   1618:            /* Modifying a single register in an alternate mode
                   1619:               does not use any of the old value.  But these other
                   1620:               ways of storing in a register do use the old value.  */
                   1621:            if (GET_CODE (testreg) == SUBREG
                   1622:                && !(REG_SIZE (SUBREG_REG (testreg)) > REG_SIZE (testreg)))
                   1623:              ;
                   1624:            else
                   1625:              mark_dest = 1;
                   1626: 
                   1627:            testreg = XEXP (testreg, 0);
                   1628:          }
1.1       root     1629: 
                   1630:        /* If this is a store into a register,
                   1631:           recursively scan the only value being stored,
                   1632:           and only if the register's value is live after this insn.
                   1633:           If the value being computed here would never be used
                   1634:           then the values it uses don't need to be computed either.  */
                   1635: 
1.1.1.2   root     1636:        if (GET_CODE (testreg) == REG
                   1637:            && (regno = REGNO (testreg), regno != FRAME_POINTER_REGNUM)
1.1.1.7   root     1638:            && regno != ARG_POINTER_REGNUM)
                   1639: #if 0 /* This was added in 1.25, but screws up death notes for hard regs.
                   1640:         It probably isn't really needed anyway.  */
1.1.1.6   root     1641:            && (regno >= FIRST_PSEUDO_REGISTER
                   1642:                || INSN_VOLATILE (insn)))
1.1.1.7   root     1643: #endif
1.1       root     1644:          {
                   1645:            register int offset = regno / REGSET_ELT_BITS;
                   1646:            register int bit = 1 << (regno % REGSET_ELT_BITS);
1.1.1.2   root     1647:            if ((needed[offset] & bit)
                   1648:                /* If insn refers to volatile, we mustn't delete it,
                   1649:                   so its inputs are all needed.  */
                   1650:                || INSN_VOLATILE (insn))
                   1651:              {
                   1652:                mark_used_regs (needed, live, SET_SRC (x), final, insn);
                   1653:                if (mark_dest)
                   1654:                  mark_used_regs (needed, live, SET_DEST (x), final, insn);
                   1655:              }
1.1       root     1656:            return;
                   1657:          }
                   1658:       }
                   1659:       break;
                   1660:     }
                   1661: 
                   1662:   /* Recursively scan the operands of this expression.  */
                   1663: 
                   1664:   {
                   1665:     register char *fmt = GET_RTX_FORMAT (code);
                   1666:     register int i;
                   1667:     
                   1668:     for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
                   1669:       {
                   1670:        if (fmt[i] == 'e')
                   1671:          {
                   1672:            /* Tail recursive case: save a function call level.  */
                   1673:            if (i == 0)
                   1674:              {
                   1675:                x = XEXP (x, 0);
                   1676:                goto retry;
                   1677:              }
1.1.1.2   root     1678:            mark_used_regs (needed, live, XEXP (x, i), final, insn);
1.1       root     1679:          }
1.1.1.4   root     1680:        else if (fmt[i] == 'E')
1.1       root     1681:          {
                   1682:            register int j;
                   1683:            for (j = 0; j < XVECLEN (x, i); j++)
1.1.1.2   root     1684:              mark_used_regs (needed, live, XVECEXP (x, i, j), final, insn);
1.1       root     1685:          }
                   1686:       }
                   1687:   }
                   1688: }
                   1689: 
1.1.1.2   root     1690: #ifdef AUTO_INC_DEC
1.1       root     1691: 
                   1692: static int
                   1693: try_pre_increment_1 (insn)
                   1694:      rtx insn;
                   1695: {
                   1696:   /* Find the next use of this reg.  If in same basic block,
                   1697:      make it do pre-increment or pre-decrement if appropriate.  */
                   1698:   rtx x = PATTERN (insn);
                   1699:   int amount = ((GET_CODE (SET_SRC (x)) == PLUS ? 1 : -1)
                   1700:                * INTVAL (XEXP (SET_SRC (x), 1)));
                   1701:   int regno = REGNO (SET_DEST (x));
                   1702:   rtx y = reg_next_use[regno];
                   1703:   if (y != 0
                   1704:       && BLOCK_NUM (y) == BLOCK_NUM (insn)
                   1705:       && try_pre_increment (y, SET_DEST (PATTERN (insn)),
                   1706:                            amount))
                   1707:     {
                   1708:       /* We have found a suitable auto-increment
                   1709:         and already changed insn Y to do it.
                   1710:         So flush this increment-instruction.  */
                   1711:       PUT_CODE (insn, NOTE);
                   1712:       NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
                   1713:       NOTE_SOURCE_FILE (insn) = 0;
                   1714:       /* Count a reference to this reg for the increment
                   1715:         insn we are deleting.  When a reg is incremented.
                   1716:         spilling it is worse, so we want to make that
                   1717:         less likely.  */
                   1718:       reg_n_refs[regno] += loop_depth;
1.1.1.2   root     1719:       reg_n_sets[regno]++;
1.1       root     1720:       return 1;
                   1721:     }
                   1722:   return 0;
                   1723: }
                   1724: 
                   1725: /* Try to change INSN so that it does pre-increment or pre-decrement
                   1726:    addressing on register REG in order to add AMOUNT to REG.
                   1727:    AMOUNT is negative for pre-decrement.
                   1728:    Returns 1 if the change could be made.
                   1729:    This checks all about the validity of the result of modifying INSN.  */
                   1730: 
                   1731: static int
                   1732: try_pre_increment (insn, reg, amount)
                   1733:      rtx insn, reg;
                   1734:      int amount;
                   1735: {
                   1736:   register rtx use;
                   1737: 
1.1.1.2   root     1738:   /* Nonzero if we can try to make a pre-increment or pre-decrement.
                   1739:      For example, addl $4,r1; movl (r1),... can become movl +(r1),...  */
                   1740:   int pre_ok = 0;
                   1741:   /* Nonzero if we can try to make a post-increment or post-decrement.
                   1742:      For example, addl $4,r1; movl -4(r1),... can become movl (r1)+,...
                   1743:      It is possible for both PRE_OK and POST_OK to be nonzero if the machine
                   1744:      supports both pre-inc and post-inc, or both pre-dec and post-dec.  */
                   1745:   int post_ok = 0;
                   1746: 
                   1747:   /* Nonzero if the opportunity actually requires post-inc or post-dec.  */
                   1748:   int do_post = 0;
                   1749: 
                   1750:   /* From the sign of increment, see which possibilities are conceivable
                   1751:      on this target machine.  */
                   1752: #ifdef HAVE_PRE_INCREMENT
1.1       root     1753:   if (amount > 0)
1.1.1.2   root     1754:     pre_ok = 1;
1.1       root     1755: #endif
1.1.1.2   root     1756: #ifdef HAVE_POST_INCREMENT
                   1757:   if (amount > 0)
                   1758:     post_ok = 1;
1.1       root     1759: #endif
                   1760: 
1.1.1.2   root     1761: #ifdef HAVE_PRE_DECREMENT
1.1       root     1762:   if (amount < 0)
1.1.1.2   root     1763:     pre_ok = 1;
                   1764: #endif
                   1765: #ifdef HAVE_POST_DECREMENT
                   1766:   if (amount < 0)
                   1767:     post_ok = 1;
1.1       root     1768: #endif
                   1769: 
1.1.1.2   root     1770:   if (! (pre_ok || post_ok))
                   1771:     return 0;
                   1772: 
1.1       root     1773:   /* It is not safe to add a side effect to a jump insn
                   1774:      because if the incremented register is spilled and must be reloaded
                   1775:      there would be no way to store the incremented value back in memory.  */
                   1776: 
                   1777:   if (GET_CODE (insn) == JUMP_INSN)
                   1778:     return 0;
                   1779: 
1.1.1.2   root     1780:   use = 0;
                   1781:   if (pre_ok)
                   1782:     use = find_use_as_address (PATTERN (insn), reg, 0);
                   1783:   if (post_ok && (use == 0 || use == (rtx) 1))
                   1784:     {
                   1785:       use = find_use_as_address (PATTERN (insn), reg, -amount);
                   1786:       do_post = 1;
                   1787:     }
1.1       root     1788: 
                   1789:   if (use == 0 || use == (rtx) 1)
                   1790:     return 0;
                   1791: 
                   1792:   if (GET_MODE_SIZE (GET_MODE (use)) != (amount > 0 ? amount : - amount))
                   1793:     return 0;
                   1794: 
1.1.1.2   root     1795:   XEXP (use, 0) = gen_rtx (amount > 0
                   1796:                           ? (do_post ? POST_INC : PRE_INC)
                   1797:                           : (do_post ? POST_DEC : PRE_DEC),
1.1       root     1798:                           Pmode, reg);
                   1799: 
                   1800:   /* Record that this insn now has an implicit side effect on X.  */
                   1801:   REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_INC, reg, REG_NOTES (insn));
                   1802:   return 1;
                   1803: }
                   1804: 
1.1.1.2   root     1805: #endif /* AUTO_INC_DEC */
                   1806: 
1.1       root     1807: /* Find the place in the rtx X where REG is used as a memory address.
                   1808:    Return the MEM rtx that so uses it.
1.1.1.2   root     1809:    If PLUSCONST is nonzero, search instead for a memory address equivalent to
                   1810:    (plus REG (const_int PLUSCONST)).
                   1811: 
                   1812:    If such an address does not appear, return 0.
                   1813:    If REG appears more than once, or is used other than in such an address,
1.1       root     1814:    return (rtx)1.  */
                   1815: 
                   1816: static rtx
1.1.1.2   root     1817: find_use_as_address (x, reg, plusconst)
1.1       root     1818:      register rtx x;
                   1819:      rtx reg;
1.1.1.2   root     1820:      int plusconst;
1.1       root     1821: {
                   1822:   enum rtx_code code = GET_CODE (x);
                   1823:   char *fmt = GET_RTX_FORMAT (code);
                   1824:   register int i;
                   1825:   register rtx value = 0;
                   1826:   register rtx tem;
                   1827: 
1.1.1.2   root     1828:   if (code == MEM && XEXP (x, 0) == reg && plusconst == 0)
1.1       root     1829:     return x;
                   1830: 
1.1.1.2   root     1831:   if (code == MEM && GET_CODE (XEXP (x, 0)) == PLUS
                   1832:       && XEXP (XEXP (x, 0), 0) == reg
                   1833:       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
                   1834:       && INTVAL (XEXP (XEXP (x, 0), 1)) == plusconst)
                   1835:     return x;
                   1836: 
                   1837:   if (code == SIGN_EXTRACT || code == ZERO_EXTRACT)
                   1838:     {
                   1839:       /* If REG occurs inside a MEM used in a bit-field reference,
                   1840:         that is unacceptable.  */
                   1841:       if (find_use_as_address (XEXP (x, 0), reg, 0) != 0)
                   1842:        return (rtx) 1;
                   1843:     }
                   1844: 
1.1       root     1845:   if (x == reg)
                   1846:     return (rtx) 1;
                   1847: 
                   1848:   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
                   1849:     {
                   1850:       if (fmt[i] == 'e')
                   1851:        {
1.1.1.2   root     1852:          tem = find_use_as_address (XEXP (x, i), reg, plusconst);
1.1       root     1853:          if (value == 0)
                   1854:            value = tem;
                   1855:          else if (tem != 0)
                   1856:            return (rtx) 1;
                   1857:        }
                   1858:       if (fmt[i] == 'E')
                   1859:        {
                   1860:          register int j;
                   1861:          for (j = XVECLEN (x, i) - 1; j >= 0; j--)
                   1862:            {
1.1.1.2   root     1863:              tem = find_use_as_address (XVECEXP (x, i, j), reg, plusconst);
1.1       root     1864:              if (value == 0)
                   1865:                value = tem;
                   1866:              else if (tem != 0)
                   1867:                return (rtx) 1;
                   1868:            }
                   1869:        }
                   1870:     }
                   1871: 
                   1872:   return value;
                   1873: }
                   1874: 
                   1875: /* Write information about registers and basic blocks into FILE.
                   1876:    This is part of making a debugging dump.  */
                   1877: 
1.1.1.2   root     1878: void
1.1       root     1879: dump_flow_info (file)
                   1880:      FILE *file;
                   1881: {
                   1882:   register int i;
                   1883:   static char *reg_class_names[] = REG_CLASS_NAMES;
                   1884: 
                   1885:   fprintf (file, "%d registers.\n", max_regno);
                   1886: 
                   1887:   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
                   1888:     if (reg_n_refs[i])
                   1889:       {
                   1890:        enum reg_class class;
                   1891:        fprintf (file, "\nRegister %d used %d times across %d insns",
                   1892:                 i, reg_n_refs[i], reg_live_length[i]);
                   1893:        if (reg_basic_block[i] >= 0)
                   1894:          fprintf (file, " in block %d", reg_basic_block[i]);
                   1895:        if (reg_n_deaths[i] != 1)
                   1896:          fprintf (file, "; dies in %d places", reg_n_deaths[i]);
                   1897:        if (reg_crosses_call[i])
                   1898:          fprintf (file, "; crosses calls");
                   1899:        if (PSEUDO_REGNO_BYTES (i) != UNITS_PER_WORD)
                   1900:          fprintf (file, "; %d bytes", PSEUDO_REGNO_BYTES (i));
                   1901:        class = reg_preferred_class (i);
                   1902:        if (class != GENERAL_REGS)
1.1.1.2   root     1903:          {
                   1904:            if (reg_preferred_or_nothing (i))
                   1905:              fprintf (file, "; %s or none", reg_class_names[(int) class]);
                   1906:            else
                   1907:              fprintf (file, "; pref %s", reg_class_names[(int) class]);
                   1908:          }
1.1       root     1909:        if (REGNO_POINTER_FLAG (i))
                   1910:          fprintf (file, "; pointer");
                   1911:        fprintf (file, ".\n");
                   1912:       }
                   1913:   fprintf (file, "\n%d basic blocks.\n", n_basic_blocks);
                   1914:   for (i = 0; i < n_basic_blocks; i++)
                   1915:     {
                   1916:       register rtx head, jump;
                   1917:       register int regno;
                   1918:       fprintf (file, "\nBasic block %d: first insn %d, last %d.\n",
                   1919:               i,
                   1920:               INSN_UID (basic_block_head[i]),
                   1921:               INSN_UID (basic_block_end[i]));
                   1922:       /* The control flow graph's storage is freed
                   1923:         now when flow_analysis returns.
                   1924:         Don't try to print it if it is gone.  */
                   1925:       if (basic_block_drops_in)
                   1926:        {
                   1927:          fprintf (file, "Reached from blocks: ");
                   1928:          head = basic_block_head[i];
                   1929:          if (GET_CODE (head) == CODE_LABEL)
                   1930:            for (jump = LABEL_REFS (head);
                   1931:                 jump != head;
                   1932:                 jump = LABEL_NEXTREF (jump))
                   1933:              {
                   1934:                register from_block = BLOCK_NUM (CONTAINING_INSN (jump));
                   1935:                fprintf (file, " %d", from_block);
                   1936:              }
                   1937:          if (basic_block_drops_in[i])
                   1938:            fprintf (file, " previous");
                   1939:        }
                   1940:       fprintf (file, "\nRegisters live at start:");
                   1941:       for (regno = 0; regno < max_regno; regno++)
                   1942:        {
                   1943:          register int offset = regno / REGSET_ELT_BITS;
                   1944:          register int bit = 1 << (regno % REGSET_ELT_BITS);
                   1945:          if (basic_block_live_at_start[i][offset] & bit)
                   1946:              fprintf (file, " %d", regno);
                   1947:        }
                   1948:       fprintf (file, "\n");
                   1949:     }
                   1950:   fprintf (file, "\n");
                   1951: }

unix.superglobalmegacorp.com

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