Annotation of gcc/flow.c, revision 1.1.1.2

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

unix.superglobalmegacorp.com

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