|
|
1.1 ! root 1: /* Data flow analysis for GNU compiler. ! 2: Copyright (C) 1987 Free Software Foundation, Inc. ! 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" ! 95: ! 96: /* Get the basic block number of an insn. ! 97: This info should not be expected to remain available ! 98: after the end of life_analysis. */ ! 99: ! 100: #define BLOCK_NUM(INSN) uid_block_number[INSN_UID (INSN)] ! 101: ! 102: /* This is where the BLOCK_NUM values are really stored. ! 103: This is set up by find_basic_blocks and used there and in life_analysis, ! 104: and then freed. */ ! 105: ! 106: static short *uid_block_number; ! 107: ! 108: /* Number of basic blocks in the current function. */ ! 109: ! 110: int n_basic_blocks; ! 111: ! 112: /* Maximum register number used in this function, plus one. */ ! 113: ! 114: int max_regno; ! 115: ! 116: /* Indexed by n, gives number of basic block that (REG n) is used in. ! 117: Or gives -2 if (REG n) is used in more than one basic block. ! 118: Or -1 if it has not yet been seen so no basic block is known. ! 119: This information remains valid for the rest of the compilation ! 120: of the current function; it is used to control register allocation. */ ! 121: ! 122: short *reg_basic_block; ! 123: ! 124: /* Indexed by n, gives number of times (REG n) is used or set, each ! 125: weighted by its loop-depth. ! 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_n_refs; ! 130: ! 131: /* Indexed by n, gives number of times (REG n) is set. ! 132: This information remains valid for the rest of the compilation ! 133: of the current function; it is used to control register allocation. */ ! 134: ! 135: short *reg_n_sets; ! 136: ! 137: /* Indexed by N, gives number of places register N dies. ! 138: This information remains valid for the rest of the compilation ! 139: of the current function; it is used to control register allocation. */ ! 140: ! 141: short *reg_n_deaths; ! 142: ! 143: /* Indexed by N, gives 1 if that reg is live across any CALL_INSNs. ! 144: This information remains valid for the rest of the compilation ! 145: of the current function; it is used to control register allocation. */ ! 146: ! 147: char *reg_crosses_call; ! 148: ! 149: /* Total number of instructions at which (REG n) is live. ! 150: The larger this is, the less priority (REG n) gets for ! 151: allocation in a real register. ! 152: This information remains valid for the rest of the compilation ! 153: of the current function; it is used to control register allocation. */ ! 154: ! 155: int *reg_live_length; ! 156: ! 157: /* Element N is the next insn that uses (hard or pseudo) register number N ! 158: within the current basic block; or zero, if there is no such insn. ! 159: This is valid only during the final backward scan in propagate_block. */ ! 160: ! 161: static rtx *reg_next_use; ! 162: ! 163: /* Size of a regset for the current function, ! 164: in (1) bytes and (2) elements. */ ! 165: ! 166: int regset_bytes; ! 167: int regset_size; ! 168: ! 169: /* Element N is first insn in basic block N. ! 170: This info lasts until we finish compiling the function. */ ! 171: ! 172: rtx *basic_block_head; ! 173: ! 174: /* Element N is last insn in basic block N. ! 175: This info lasts until we finish compiling the function. */ ! 176: ! 177: rtx *basic_block_end; ! 178: ! 179: /* Element N is a regset describing the registers live ! 180: at the start of basic block N. ! 181: This info lasts until we finish compiling the function. */ ! 182: ! 183: regset *basic_block_live_at_start; ! 184: ! 185: /* Element N is nonzero if control can drop into basic block N ! 186: from the preceding basic block. Freed after life_analysis. */ ! 187: ! 188: char *basic_block_drops_in; ! 189: ! 190: /* Element N is depth within loops of basic block number N. ! 191: Freed after life_analysis. */ ! 192: ! 193: short *basic_block_loop_depth; ! 194: ! 195: /* Element N nonzero if basic block N can actually be reached. ! 196: Vector exists only during find_basic_blocks. */ ! 197: ! 198: char *block_live_static; ! 199: ! 200: /* Depth within loops of basic block being scanned for lifetime analysis, ! 201: plus one. This is the weight attached to references to registers. */ ! 202: ! 203: int loop_depth; ! 204: ! 205: /* Forward declarations */ ! 206: static void find_basic_blocks (); ! 207: static void life_analysis (); ! 208: static void mark_label_ref (); ! 209: void allocate_for_life_analysis (); /* Used also in stupid_life_analysis */ ! 210: static void init_regset_vector (); ! 211: static void propagate_block (); ! 212: static void mark_set_regs (); ! 213: static void mark_used_regs (); ! 214: static int insn_dead_p (); ! 215: static int try_pre_increment (); ! 216: static int try_pre_increment_1 (); ! 217: static rtx find_use_as_address (); ! 218: ! 219: /* Find basic blocks of the current function and perform data flow analysis. ! 220: F is the first insn of the function and NREGS the number of register numbers ! 221: in use. */ ! 222: ! 223: void ! 224: flow_analysis (f, nregs, file) ! 225: rtx f; ! 226: int nregs; ! 227: FILE *file; ! 228: { ! 229: register rtx insn; ! 230: register int i; ! 231: register int max_uid = 0; ! 232: ! 233: /* Count the basic blocks. Also find maximum insn uid value used. */ ! 234: ! 235: { ! 236: register RTX_CODE prev_code = JUMP_INSN; ! 237: register RTX_CODE code; ! 238: ! 239: for (insn = f, i = 0; insn; insn = NEXT_INSN (insn)) ! 240: { ! 241: code = GET_CODE (insn); ! 242: if (INSN_UID (insn) > max_uid) ! 243: max_uid = INSN_UID (insn); ! 244: if (code == CODE_LABEL ! 245: || (prev_code != INSN && prev_code != CALL_INSN ! 246: && prev_code != CODE_LABEL ! 247: && (code == INSN || code == CALL_INSN || code == JUMP_INSN))) ! 248: i++; ! 249: if (code != NOTE) ! 250: prev_code = code; ! 251: } ! 252: } ! 253: ! 254: /* Allocate some tables that last till end of compiling this function ! 255: and some needed only in find_basic_blocks and life_analysis. */ ! 256: ! 257: n_basic_blocks = i; ! 258: basic_block_head = (rtx *) oballoc (n_basic_blocks * sizeof (rtx)); ! 259: basic_block_end = (rtx *) oballoc (n_basic_blocks * sizeof (rtx)); ! 260: basic_block_drops_in = (char *) alloca (n_basic_blocks); ! 261: basic_block_loop_depth = (short *) alloca (n_basic_blocks * sizeof (short)); ! 262: uid_block_number = (short *) alloca ((max_uid + 1) * sizeof (short)); ! 263: ! 264: find_basic_blocks (f); ! 265: life_analysis (f, nregs); ! 266: if (file) ! 267: dump_flow_info (file); ! 268: ! 269: basic_block_drops_in = 0; ! 270: uid_block_number = 0; ! 271: basic_block_loop_depth = 0; ! 272: } ! 273: ! 274: /* Find all basic blocks of the function whose first insn is F. ! 275: Store the correct data in the tables that describe the basic blocks, ! 276: set up the chains of references for each CODE_LABEL, and ! 277: delete any entire basic blocks that cannot be reached. */ ! 278: ! 279: static void ! 280: find_basic_blocks (f) ! 281: rtx f; ! 282: { ! 283: register rtx insn; ! 284: register int i; ! 285: ! 286: /* Initialize the ref chain of each label to 0. */ ! 287: /* Record where all the blocks start and end and their depth in loops. */ ! 288: /* For each insn, record the block it is in. */ ! 289: ! 290: { ! 291: register RTX_CODE prev_code = JUMP_INSN; ! 292: register RTX_CODE code; ! 293: int depth = 1; ! 294: ! 295: for (insn = f, i = -1; insn; insn = NEXT_INSN (insn)) ! 296: { ! 297: code = GET_CODE (insn); ! 298: if (code == NOTE) ! 299: { ! 300: if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG) ! 301: depth++; ! 302: else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END) ! 303: depth--; ! 304: } ! 305: else if (code == CODE_LABEL ! 306: || (prev_code != INSN && prev_code != CALL_INSN ! 307: && prev_code != CODE_LABEL ! 308: && (code == INSN || code == CALL_INSN || code == JUMP_INSN))) ! 309: { ! 310: basic_block_head[++i] = insn; ! 311: basic_block_end[i] = insn; ! 312: basic_block_loop_depth[i] = depth; ! 313: if (code == CODE_LABEL) ! 314: LABEL_REFS (insn) = insn; ! 315: } ! 316: else if (code == INSN || code == CALL_INSN || code == JUMP_INSN) ! 317: basic_block_end[i] = insn; ! 318: BLOCK_NUM (insn) = i; ! 319: if (code != NOTE) ! 320: prev_code = code; ! 321: } ! 322: } ! 323: ! 324: /* Record which basic blocks control can drop in to. */ ! 325: ! 326: { ! 327: register int i; ! 328: for (i = 0; i < n_basic_blocks; i++) ! 329: { ! 330: register rtx insn = PREV_INSN (basic_block_head[i]); ! 331: while (insn && GET_CODE (insn) == NOTE) ! 332: insn = PREV_INSN (insn); ! 333: basic_block_drops_in[i] ! 334: = insn && GET_CODE (insn) != BARRIER; ! 335: } ! 336: } ! 337: ! 338: /* Now find which basic blocks can actually be reached ! 339: and put all jump insns' LABEL_REFS onto the ref-chains ! 340: of their target labels. */ ! 341: ! 342: if (n_basic_blocks > 0) ! 343: { ! 344: register char *block_live = (char *) alloca (n_basic_blocks); ! 345: register char *block_marked = (char *) alloca (n_basic_blocks); ! 346: int something_marked = 1; ! 347: ! 348: /* Initialize with just block 0 reachable and no blocks marked. */ ! 349: ! 350: bzero (block_live, n_basic_blocks); ! 351: bzero (block_marked, n_basic_blocks); ! 352: block_live[0] = 1; ! 353: block_live_static = block_live; ! 354: ! 355: /* Pass over all blocks, marking each block that is reachable ! 356: and has not yet been marked. ! 357: Keep doing this until, in one pass, no blocks have been marked. ! 358: Then blocks_live and blocks_marked are identical and correct. ! 359: In addition, all jumps actually reachable have been marked. */ ! 360: ! 361: while (something_marked) ! 362: { ! 363: something_marked = 0; ! 364: for (i = 0; i < n_basic_blocks; i++) ! 365: if (block_live[i] && !block_marked[i]) ! 366: { ! 367: block_marked[i] = 1; ! 368: something_marked = 1; ! 369: if (i + 1 < n_basic_blocks && basic_block_drops_in[i + 1]) ! 370: block_live[i + 1] = 1; ! 371: insn = basic_block_end[i]; ! 372: if (GET_CODE (insn) == JUMP_INSN) ! 373: mark_label_ref (PATTERN (insn), insn, 0); ! 374: } ! 375: } ! 376: ! 377: /* Now delete the code for any basic blocks that can't be reached. ! 378: They can occur because jump_optimize does not recognize ! 379: unreachable loops as unreachable. */ ! 380: ! 381: for (i = 0; i < n_basic_blocks; i++) ! 382: if (!block_live[i]) ! 383: { ! 384: insn = basic_block_head[i]; ! 385: while (1) ! 386: { ! 387: if (GET_CODE (insn) != NOTE) ! 388: { ! 389: PUT_CODE (insn, NOTE); ! 390: NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED; ! 391: NOTE_SOURCE_FILE (insn) = 0; ! 392: } ! 393: if (insn == basic_block_end[i]) ! 394: break; ! 395: insn = NEXT_INSN (insn); ! 396: } ! 397: /* Each time we delete some basic blocks, ! 398: see if there is a jump around them that is ! 399: being turned into a no-op. If so, delete it. */ ! 400: ! 401: if (block_live[i - 1]) ! 402: { ! 403: register int j; ! 404: for (j = i; j < n_basic_blocks; j++) ! 405: if (block_live[j]) ! 406: { ! 407: insn = basic_block_end[i - 1]; ! 408: if (GET_CODE (insn) == JUMP_INSN ! 409: && JUMP_LABEL (insn) != 0 ! 410: && BLOCK_NUM (JUMP_LABEL (insn)) == j) ! 411: { ! 412: PUT_CODE (insn, NOTE); ! 413: NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED; ! 414: NOTE_SOURCE_FILE (insn) = 0; ! 415: } ! 416: break; ! 417: } ! 418: } ! 419: } ! 420: } ! 421: } ! 422: ! 423: /* Check expression X for label references; ! 424: if one is found, add INSN to the label's chain of references. ! 425: ! 426: CHECKDUP means check for and avoid creating duplicate references ! 427: from the same insn. Such duplicates do no serious harm but ! 428: can slow life analysis. CHECKDUP is set only when duplicates ! 429: are likely. */ ! 430: ! 431: static void ! 432: mark_label_ref (x, insn, checkdup) ! 433: rtx x, insn; ! 434: int checkdup; ! 435: { ! 436: register RTX_CODE code = GET_CODE (x); ! 437: register int i; ! 438: register char *fmt; ! 439: ! 440: if (code == LABEL_REF) ! 441: { ! 442: register rtx label = XEXP (x, 0); ! 443: register rtx y; ! 444: if (GET_CODE (label) != CODE_LABEL) ! 445: return; ! 446: CONTAINING_INSN (x) = insn; ! 447: /* if CHECKDUP is set, check for duplicate ref from same insn ! 448: and don't insert. */ ! 449: if (checkdup) ! 450: for (y = LABEL_REFS (label); y != label; y = LABEL_NEXTREF (y)) ! 451: if (CONTAINING_INSN (y) == insn) ! 452: return; ! 453: LABEL_NEXTREF (x) = LABEL_REFS (label); ! 454: LABEL_REFS (label) = x; ! 455: block_live_static[BLOCK_NUM (label)] = 1; ! 456: return; ! 457: } ! 458: ! 459: fmt = GET_RTX_FORMAT (code); ! 460: for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) ! 461: { ! 462: if (fmt[i] == 'e') ! 463: mark_label_ref (XEXP (x, i), insn, 0); ! 464: if (fmt[i] == 'E') ! 465: { ! 466: register int j; ! 467: for (j = 0; j < XVECLEN (x, i); j++) ! 468: mark_label_ref (XVECEXP (x, i, j), insn, 1); ! 469: } ! 470: } ! 471: } ! 472: ! 473: /* Determine the which registers are live at the start of each ! 474: basic block of the function whose first insn is F. ! 475: NREGS is the number of registers used in F. ! 476: We allocate the vector basic_block_live_at_start ! 477: and the regsets that it points to, and fill them with the data. ! 478: regset_size and regset_bytes are also set here. */ ! 479: ! 480: static void ! 481: life_analysis (f, nregs) ! 482: rtx f; ! 483: int nregs; ! 484: { ! 485: register regset tem; ! 486: int first_pass; ! 487: int changed; ! 488: /* For each basic block, a bitmask of regs ! 489: live on exit from the block. */ ! 490: regset *basic_block_live_at_end; ! 491: /* For each basic block, a bitmask of regs ! 492: live on entry to a successor-block of this block. ! 493: If this does not match basic_block_live_at_end, ! 494: that must be updated, and the block must be rescanned. */ ! 495: regset *basic_block_new_live_at_end; ! 496: /* For each basic block, a bitmask of regs ! 497: whose liveness at the end of the basic block ! 498: can make a difference in which regs are live on entry to the block. ! 499: These are the regs that are set within the basic block, ! 500: possibly excluding those that are used after they are set. */ ! 501: regset *basic_block_significant; ! 502: register int i; ! 503: ! 504: max_regno = nregs; ! 505: ! 506: bzero (regs_ever_live, sizeof regs_ever_live); ! 507: ! 508: /* Allocate and zero out many data structures ! 509: that will record the data from lifetime analysis. */ ! 510: ! 511: allocate_for_life_analysis (); ! 512: ! 513: reg_next_use = (rtx *) alloca (nregs * sizeof (rtx)); ! 514: bzero (reg_next_use, nregs * sizeof (rtx)); ! 515: ! 516: /* Set up several regset-vectors used internally within this function. ! 517: Their meanings are documented above, with their declarations. */ ! 518: ! 519: basic_block_live_at_end = (regset *) alloca (n_basic_blocks * sizeof (regset)); ! 520: tem = (regset) alloca (n_basic_blocks * regset_bytes); ! 521: bzero (tem, n_basic_blocks * regset_bytes); ! 522: init_regset_vector (basic_block_live_at_end, tem, n_basic_blocks, regset_bytes); ! 523: ! 524: basic_block_new_live_at_end = (regset *) alloca (n_basic_blocks * sizeof (regset)); ! 525: tem = (regset) alloca (n_basic_blocks * regset_bytes); ! 526: bzero (tem, n_basic_blocks * regset_bytes); ! 527: init_regset_vector (basic_block_new_live_at_end, tem, n_basic_blocks, regset_bytes); ! 528: ! 529: basic_block_significant = (regset *) alloca (n_basic_blocks * sizeof (regset)); ! 530: tem = (regset) alloca (n_basic_blocks * regset_bytes); ! 531: bzero (tem, n_basic_blocks * regset_bytes); ! 532: init_regset_vector (basic_block_significant, tem, n_basic_blocks, regset_bytes); ! 533: ! 534: /* Propagate life info through the basic blocks ! 535: around the graph of basic blocks. ! 536: ! 537: This is a relaxation process: each time a new register ! 538: is live at the end of the basic block, we must scan the block ! 539: to determine which registers are, as a consequence, live at the beginning ! 540: of that block. These registers must then be marked live at the ends ! 541: of all the blocks that can transfer control to that block. ! 542: The process continues until it reaches a fixed point. */ ! 543: ! 544: first_pass = 1; ! 545: changed = 1; ! 546: while (changed) ! 547: { ! 548: changed = 0; ! 549: for (i = n_basic_blocks - 1; i >= 0; i--) ! 550: { ! 551: int consider = first_pass; ! 552: int must_rescan = first_pass; ! 553: register int j; ! 554: ! 555: /* Set CONSIDER if this block needs thinking about at all ! 556: (that is, if the regs live now at the end of it ! 557: are not the same as were live at the end of it when ! 558: we last thought about it). ! 559: Set must_rescan if it needs to be thought about ! 560: instruction by instruction (that is, if any additional ! 561: reg that is live at the end now but was not live there before ! 562: is one of the significant regs of this basic block). */ ! 563: ! 564: for (j = 0; j < regset_size; j++) ! 565: { ! 566: register int x = basic_block_new_live_at_end[i][j] ! 567: & ~basic_block_live_at_end[i][j]; ! 568: if (x) ! 569: consider = 1; ! 570: if (x & basic_block_significant[i][j]) ! 571: { ! 572: must_rescan = 1; ! 573: consider = 1; ! 574: break; ! 575: } ! 576: } ! 577: ! 578: if (! consider) ! 579: continue; ! 580: ! 581: /* The live_at_start of this block may be changing, ! 582: so another pass will be required after this one. */ ! 583: changed = 1; ! 584: ! 585: if (! must_rescan) ! 586: { ! 587: /* No complete rescan needed; ! 588: just record those variables newly known live at end ! 589: as live at start as well. */ ! 590: for (j = 0; j < regset_size; j++) ! 591: { ! 592: register int x = basic_block_new_live_at_end[i][j] ! 593: & ~basic_block_live_at_end[i][j]; ! 594: basic_block_live_at_start[i][j] |= x; ! 595: basic_block_live_at_end[i][j] |= x; ! 596: } ! 597: } ! 598: else ! 599: { ! 600: /* Update the basic_block_live_at_start ! 601: by propagation backwards through the block. */ ! 602: bcopy (basic_block_new_live_at_end[i], ! 603: basic_block_live_at_end[i], regset_bytes); ! 604: bcopy (basic_block_live_at_end[i], ! 605: basic_block_live_at_start[i], regset_bytes); ! 606: propagate_block (basic_block_live_at_start[i], ! 607: basic_block_head[i], basic_block_end[i], 0, ! 608: first_pass ? basic_block_significant[i] : 0, ! 609: i); ! 610: } ! 611: ! 612: { ! 613: register rtx jump, head; ! 614: /* Update the basic_block_new_live_at_end's of the block ! 615: that falls through into this one (if any). */ ! 616: head = basic_block_head[i]; ! 617: jump = PREV_INSN (head); ! 618: if (basic_block_drops_in[i]) ! 619: { ! 620: register from_block = BLOCK_NUM (jump); ! 621: register int j; ! 622: for (j = 0; j < regset_size; j++) ! 623: basic_block_new_live_at_end[from_block][j] ! 624: |= basic_block_live_at_start[i][j]; ! 625: } ! 626: /* Update the basic_block_new_live_at_end's of ! 627: all the blocks that jump to this one. */ ! 628: if (GET_CODE (head) == CODE_LABEL) ! 629: for (jump = LABEL_REFS (head); ! 630: jump != head; ! 631: jump = LABEL_NEXTREF (jump)) ! 632: { ! 633: register from_block = BLOCK_NUM (CONTAINING_INSN (jump)); ! 634: register int j; ! 635: for (j = 0; j < regset_size; j++) ! 636: basic_block_new_live_at_end[from_block][j] ! 637: |= basic_block_live_at_start[i][j]; ! 638: } ! 639: } ! 640: } ! 641: first_pass = 0; ! 642: } ! 643: ! 644: /* Now the life information is accurate. ! 645: Make one more pass over each basic block ! 646: to delete dead stores, create autoincrement addressing ! 647: and record how many times each register is used, is set, or dies. ! 648: ! 649: To save time, we operate directly in basic_block_live_at_end[i], ! 650: thus destroying it (in fact, converting it into a copy of ! 651: basic_block_live_at_start[i]). This is ok now because ! 652: basic_block_live_at_end[i] is no longer used past this point. */ ! 653: ! 654: for (i = 0; i < n_basic_blocks; i++) ! 655: { ! 656: propagate_block (basic_block_live_at_end[i], ! 657: basic_block_head[i], basic_block_end[i], 1, 0, i); ! 658: } ! 659: } ! 660: ! 661: /* Subroutines of life analysis. */ ! 662: ! 663: /* Allocate the permanent data structures that represent the results ! 664: of life analysis. Not static since used also for stupid life analysis. */ ! 665: ! 666: void ! 667: allocate_for_life_analysis () ! 668: { ! 669: register int i; ! 670: register regset tem; ! 671: ! 672: regset_size = ((max_regno + REGSET_ELT_BITS - 1) / REGSET_ELT_BITS); ! 673: regset_bytes = regset_size * sizeof (*(regset)0); ! 674: ! 675: reg_n_refs = (short *) oballoc (max_regno * sizeof (short)); ! 676: bzero (reg_n_refs, max_regno * sizeof (short)); ! 677: ! 678: reg_n_sets = (short *) oballoc (max_regno * sizeof (short)); ! 679: bzero (reg_n_sets, max_regno * sizeof (short)); ! 680: ! 681: reg_n_deaths = (short *) oballoc (max_regno * sizeof (short)); ! 682: bzero (reg_n_deaths, max_regno * sizeof (short)); ! 683: ! 684: reg_live_length = (int *) oballoc (max_regno * sizeof (int)); ! 685: bzero (reg_live_length, max_regno * sizeof (int)); ! 686: ! 687: reg_crosses_call = (char *) oballoc (max_regno); ! 688: bzero (reg_crosses_call, max_regno); ! 689: ! 690: reg_basic_block = (short *) oballoc (max_regno * sizeof (short)); ! 691: for (i = 0; i < max_regno; i++) ! 692: reg_basic_block[i] = -1; ! 693: ! 694: basic_block_live_at_start = (regset *) oballoc (n_basic_blocks * sizeof (regset)); ! 695: tem = (regset) oballoc (n_basic_blocks * regset_bytes); ! 696: bzero (tem, n_basic_blocks * regset_bytes); ! 697: init_regset_vector (basic_block_live_at_start, tem, n_basic_blocks, regset_bytes); ! 698: } ! 699: ! 700: /* Make each element of VECTOR point at a regset, ! 701: taking the space for all those regsets from SPACE. ! 702: SPACE is of type regset, but it is really as long as NELTS regsets. ! 703: BYTES_PER_ELT is the number of bytes in one regset. */ ! 704: ! 705: static void ! 706: init_regset_vector (vector, space, nelts, bytes_per_elt) ! 707: regset *vector; ! 708: regset space; ! 709: int nelts; ! 710: int bytes_per_elt; ! 711: { ! 712: register int i; ! 713: register regset p = space; ! 714: ! 715: for (i = 0; i < nelts; i++) ! 716: { ! 717: vector[i] = p; ! 718: p += bytes_per_elt / sizeof (*p); ! 719: } ! 720: } ! 721: ! 722: /* Compute the registers live at the beginning of a basic block ! 723: from those live at the end. ! 724: ! 725: When called, OLD contains those live at the end. ! 726: On return, it contains those live at the beginning. ! 727: FIRST and LAST are the first and last insns of the basic block. ! 728: ! 729: FINAL is nonzero if we are doing the final pass which is not ! 730: for computing the life info (since that has already been done) ! 731: but for acting on it. On this pass, we delete dead stores, ! 732: set up the logical links and dead-variables lists of instructions, ! 733: and merge instructions for autoincrement and autodecrement addresses. ! 734: ! 735: SIGNIFICANT is nonzero only the first time for each basic block. ! 736: If it is nonzero, it points to a regset in which we store ! 737: a 1 for each register that is set within the block. ! 738: ! 739: BNUM is the number of the basic block. */ ! 740: ! 741: static void ! 742: propagate_block (old, first, last, final, significant, bnum) ! 743: register regset old; ! 744: rtx first; ! 745: rtx last; ! 746: int final; ! 747: regset significant; ! 748: int bnum; ! 749: { ! 750: register rtx insn; ! 751: rtx prev; ! 752: regset live; ! 753: regset dead; ! 754: ! 755: /* The following variables are used only if FINAL is nonzero. */ ! 756: /* This vector gets one element for each reg that has been live ! 757: at any point in the basic block that has been scanned so far. ! 758: SOMETIMES_MAX says how many elements are in use so far. ! 759: In each element, OFFSET is the byte-number within a regset ! 760: for the register described by the element, and BIT is a mask ! 761: for that register's bit within the byte. */ ! 762: register struct foo { short offset; short bit; } *regs_sometimes_live; ! 763: int sometimes_max = 0; ! 764: /* This regset has 1 for each reg that we have seen live so far. ! 765: It and REGS_SOMETIMES_LIVE are updated together. */ ! 766: regset maxlive; ! 767: ! 768: loop_depth = basic_block_loop_depth[bnum]; ! 769: ! 770: dead = (regset) alloca (regset_bytes); ! 771: live = (regset) alloca (regset_bytes); ! 772: ! 773: if (final) ! 774: { ! 775: register int i, offset, bit; ! 776: ! 777: maxlive = (regset) alloca (regset_bytes); ! 778: bcopy (old, maxlive, regset_bytes); ! 779: regs_sometimes_live ! 780: = (struct foo *) alloca (max_regno * sizeof (struct foo)); ! 781: ! 782: /* Process the regs live at the end of the block. ! 783: Enter them in MAXLIVE and REGS_SOMETIMES_LIVE. ! 784: Also mark them as not local to any one basic block. */ ! 785: ! 786: for (offset = 0, i = 0; offset < regset_size; offset++) ! 787: for (bit = 1; bit; bit <<= 1, i++) ! 788: { ! 789: if (i == max_regno) ! 790: break; ! 791: if (old[offset] & bit) ! 792: { ! 793: reg_basic_block[i] = -2; ! 794: regs_sometimes_live[sometimes_max].offset = offset; ! 795: regs_sometimes_live[sometimes_max].bit = i % REGSET_ELT_BITS; ! 796: sometimes_max++; ! 797: } ! 798: } ! 799: } ! 800: ! 801: /* Scan the block an insn at a time from end to beginning. */ ! 802: ! 803: for (insn = last; ; insn = prev) ! 804: { ! 805: prev = PREV_INSN (insn); ! 806: if (final && GET_CODE (insn) == CALL_INSN) ! 807: { ! 808: /* Any regs live at the time of a call instruction ! 809: must not go in a register clobbered by calls. ! 810: Find all regs now live and record this for them. */ ! 811: ! 812: register int i; ! 813: register struct foo *p = regs_sometimes_live; ! 814: ! 815: for (i = 0; i < sometimes_max; i++, p++) ! 816: { ! 817: if (old[p->offset] ! 818: & (1 << p->bit)) ! 819: reg_crosses_call[p->offset * REGSET_ELT_BITS + p->bit] = 1; ! 820: } ! 821: } ! 822: ! 823: /* Update the life-status of regs for this insn. ! 824: First DEAD gets which regs are set in this insn ! 825: then LIVE gets which regs are used in this insn. ! 826: Then the regs live before the insn ! 827: are those live after, with DEAD regs turned off, ! 828: and then LIVE regs turned on. */ ! 829: ! 830: if (GET_CODE (insn) == INSN ! 831: || GET_CODE (insn) == JUMP_INSN ! 832: || GET_CODE (insn) == CALL_INSN) ! 833: { ! 834: register int i; ! 835: for (i = 0; i < regset_size; i++) ! 836: { ! 837: dead[i] = 0; /* Faster than bzero here */ ! 838: live[i] = 0; /* since regset_size is usually small */ ! 839: } ! 840: /* If an instruction consists of just dead store(s) on final pass, ! 841: "delete" it by turning it into a NOTE of type NOTE_INSN_DELETED. ! 842: We could really delete it with delete_insn, but that ! 843: can cause trouble for first or last insn in a basic block. */ ! 844: if (final && insn_dead_p (PATTERN (insn), old)) ! 845: { ! 846: PUT_CODE (insn, NOTE); ! 847: NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED; ! 848: NOTE_SOURCE_FILE (insn) = 0; ! 849: goto flushed; ! 850: } ! 851: else ! 852: { ! 853: /* Check for an opportunity to do predecrement or preincrement addressing. */ ! 854: #if defined (HAVE_PRE_INCREMENT) || defined (HAVE_PRE_DECREMENT) ! 855: register rtx x = PATTERN (insn); ! 856: /* Does this instruction increment or decrement a register? */ ! 857: if (final && GET_CODE (x) == SET ! 858: && GET_CODE (SET_DEST (x)) == REG ! 859: && (GET_CODE (SET_SRC (x)) == PLUS ! 860: || GET_CODE (SET_SRC (x)) == MINUS) ! 861: && XEXP (SET_SRC (x), 0) == SET_DEST (x) ! 862: && GET_CODE (XEXP (SET_SRC (x), 1)) == CONST_INT ! 863: /* Ok, look for a following memory ref we can combine with. ! 864: If one is found, change the memory ref to a PRE_INC ! 865: or PRE_DEC, cancel this insn, and return 1. ! 866: Return 0 if nothing has been done. */ ! 867: && try_pre_increment_1 (insn)) ! 868: goto flushed; ! 869: #endif /* HAVE_PRE_INCREMENT or HAVE_PRE_DECREMENT */ ! 870: ! 871: /* LIVE gets the registers used in INSN; DEAD gets those set by it. */ ! 872: ! 873: /* A function call implicitly sets the function-value register */ ! 874: if (GET_CODE (insn) == CALL_INSN) ! 875: dead[FUNCTION_VALUE_REGNUM / REGSET_ELT_BITS] ! 876: |= 1 << (FUNCTION_VALUE_REGNUM % REGSET_ELT_BITS); ! 877: mark_set_regs (old, dead, PATTERN (insn), final ? insn : 0, ! 878: significant); ! 879: mark_used_regs (old, live, PATTERN (insn), final ? insn : 0); ! 880: ! 881: /* Update OLD for the registers used or set. */ ! 882: for (i = 0; i < regset_size; i++) ! 883: { ! 884: old[i] &= ~dead[i]; ! 885: old[i] |= live[i]; ! 886: } ! 887: ! 888: /* On final pass, add any additional sometimes-live regs ! 889: into MAXLIVE and REGS_SOMETIMES_LIVE. ! 890: Also update counts of how many insns each reg is live at. */ ! 891: ! 892: if (final) ! 893: { ! 894: register int diff; ! 895: ! 896: for (i = 0; i < regset_size; i++) ! 897: if (diff = live[i] & ~maxlive[i]) ! 898: { ! 899: register int regno; ! 900: maxlive[i] |= diff; ! 901: for (regno = 0; diff && regno < REGSET_ELT_BITS; regno++) ! 902: if (diff & (1 << regno)) ! 903: { ! 904: regs_sometimes_live[sometimes_max].offset = i; ! 905: regs_sometimes_live[sometimes_max].bit = regno; ! 906: diff &= ~ (1 << regno); ! 907: sometimes_max++; ! 908: } ! 909: } ! 910: ! 911: { ! 912: register struct foo *p = regs_sometimes_live; ! 913: for (i = 0; i < sometimes_max; i++, p++) ! 914: { ! 915: if (old[p->offset] ! 916: & (1 << p->bit)) ! 917: reg_live_length[p->offset * REGSET_ELT_BITS + p->bit]++; ! 918: } ! 919: } ! 920: /* This probably gets set to 1 in various places; ! 921: make sure it is 0. */ ! 922: reg_crosses_call[FUNCTION_VALUE_REGNUM] = 0; ! 923: } ! 924: } ! 925: flushed: ; ! 926: } ! 927: if (insn == first) ! 928: break; ! 929: } ! 930: } ! 931: ! 932: /* Return 1 if X (the body of an insn, or part of it) is just dead stores ! 933: (SET expressions whose destinations are registers dead after the insn). ! 934: NEEDED is the regset that says which regs are alive after the insn. */ ! 935: ! 936: static int ! 937: insn_dead_p (x, needed) ! 938: rtx x; ! 939: regset needed; ! 940: { ! 941: register RTX_CODE code = GET_CODE (x); ! 942: /* Make sure insns to set the stack pointer are never deleted. */ ! 943: needed[STACK_POINTER_REGNUM / REGSET_ELT_BITS] ! 944: |= 1 << (STACK_POINTER_REGNUM % REGSET_ELT_BITS); ! 945: if (code == SET && GET_CODE (SET_DEST (x)) == REG) ! 946: { ! 947: register int regno = REGNO (SET_DEST (x)); ! 948: register int offset = regno / REGSET_ELT_BITS; ! 949: register int bit = 1 << (regno % REGSET_ELT_BITS); ! 950: return (needed[offset] & bit) == 0; ! 951: } ! 952: if (code == PARALLEL) ! 953: { ! 954: register int i = XVECLEN (x, 0); ! 955: for (i--; i >= 0; i--) ! 956: if (!insn_dead_p (XVECEXP (x, 0, i), needed)) ! 957: return 0; ! 958: return 1; ! 959: } ! 960: return 0; ! 961: } ! 962: ! 963: /* Return nonzero if register number REGNO is marked as "dying" in INSN's ! 964: REG_NOTES list. */ ! 965: ! 966: static int ! 967: flow_deadp (regno, insn) ! 968: int regno; ! 969: rtx insn; ! 970: { ! 971: register rtx link; ! 972: for (link = REG_NOTES (insn); link; link = XEXP (link, 1)) ! 973: if (XEXP (link, 0) ! 974: && (enum reg_note) GET_MODE (link) == REG_DEAD ! 975: && regno == REGNO (XEXP (link, 0))) ! 976: return 1; ! 977: return 0; ! 978: } ! 979: ! 980: /* Process the registers that are set within X. ! 981: Their bits are set to 1 in the regset DEAD, ! 982: because they are dead prior to this insn. ! 983: ! 984: If INSN is nonzero, it is the insn being processed ! 985: and the fact that it is nonzero implies this is the FINAL pass ! 986: in propagate_block. In this case, various info about register ! 987: usage is stored, LOG_LINKS fields of insns are set up. */ ! 988: ! 989: static void mark_set_1 (); ! 990: ! 991: static void ! 992: mark_set_regs (needed, dead, x, insn, significant) ! 993: regset needed; ! 994: regset dead; ! 995: rtx x; ! 996: rtx insn; ! 997: regset significant; ! 998: { ! 999: register RTX_CODE code = GET_CODE (x); ! 1000: ! 1001: if (code == SET || code == CLOBBER) ! 1002: mark_set_1 (needed, dead, x, insn, significant); ! 1003: else if (code == PARALLEL) ! 1004: { ! 1005: register int i; ! 1006: for (i = XVECLEN (x, 0) - 1; i >= 0; i--) ! 1007: { ! 1008: code = GET_CODE (XVECEXP (x, 0, i)); ! 1009: if (code == SET || code == CLOBBER) ! 1010: mark_set_1 (needed, dead, XVECEXP (x, 0, i), insn, significant); ! 1011: } ! 1012: } ! 1013: } ! 1014: ! 1015: /* Process a single SET rtx, X. */ ! 1016: ! 1017: static void ! 1018: mark_set_1 (needed, dead, x, insn, significant) ! 1019: regset needed; ! 1020: regset dead; ! 1021: rtx x; ! 1022: rtx insn; ! 1023: regset significant; ! 1024: { ! 1025: register int regno; ! 1026: register rtx reg = SET_DEST (x); ! 1027: ! 1028: if (GET_CODE (reg) == SUBREG) ! 1029: { ! 1030: /* Modifying just one hardware register ! 1031: of a multi-register value does not count as "setting" ! 1032: for live-dead analysis. Parts of the previous value ! 1033: might still be significant below this insn. */ ! 1034: if (REG_SIZE (SUBREG_REG (reg)) > REG_SIZE (reg)) ! 1035: return; ! 1036: ! 1037: reg = SUBREG_REG (reg); ! 1038: } ! 1039: ! 1040: if (GET_CODE (reg) == REG ! 1041: && (regno = REGNO (reg), regno != FRAME_POINTER_REGNUM) ! 1042: && regno != ARG_POINTER_REGNUM && regno != STACK_POINTER_REGNUM) ! 1043: { ! 1044: register int offset = regno / REGSET_ELT_BITS; ! 1045: register int bit = 1 << (regno % REGSET_ELT_BITS); ! 1046: /* Mark the reg being set as dead before this insn. */ ! 1047: dead[offset] |= bit; ! 1048: /* Mark it as a significant register for this basic block. */ ! 1049: if (significant) ! 1050: significant[offset] |= bit; ! 1051: /* Additional data to record if this is the final pass. */ ! 1052: if (insn) ! 1053: { ! 1054: register rtx y = reg_next_use[regno]; ! 1055: register int blocknum = BLOCK_NUM (insn); ! 1056: ! 1057: /* If this is a hard reg, record this function uses the reg. */ ! 1058: ! 1059: if (regno < FIRST_PSEUDO_REGISTER) ! 1060: { ! 1061: register int i; ! 1062: i = HARD_REGNO_NREGS (regno, GET_MODE (reg)); ! 1063: do ! 1064: regs_ever_live[regno + --i] = 1; ! 1065: while (i > 0); ! 1066: } ! 1067: ! 1068: /* Keep track of which basic blocks each reg appears in. */ ! 1069: ! 1070: if (reg_basic_block[regno] == -1) ! 1071: reg_basic_block[regno] = blocknum; ! 1072: else if (reg_basic_block[regno] != blocknum) ! 1073: reg_basic_block[regno] = -2; ! 1074: ! 1075: /* Count (weighted) references, stores, etc. */ ! 1076: reg_n_refs[regno] += loop_depth; ! 1077: reg_n_sets[regno]++; ! 1078: /* The insns where a reg is live are normally counted elsewhere, ! 1079: but we want the count to include the insn where the reg is set, ! 1080: and the normal counting mechanism would not count it. */ ! 1081: reg_live_length[regno]++; ! 1082: if (needed[offset] & bit) ! 1083: { ! 1084: /* Make a logical link from the next following insn ! 1085: that uses this register, back to this insn. ! 1086: The following insns have already been processed. */ ! 1087: if (y && (BLOCK_NUM (y) == blocknum)) ! 1088: LOG_LINKS (y) ! 1089: = gen_rtx (INSN_LIST, VOIDmode, insn, LOG_LINKS (y)); ! 1090: } ! 1091: else ! 1092: { ! 1093: /* Note that dead stores have already been deleted when possible ! 1094: If we get here, we have found a dead store that cannot ! 1095: be eliminated (because the same insn does something useful). ! 1096: Indicate this by marking the reg being set as dying here. */ ! 1097: REG_NOTES (insn) ! 1098: = gen_rtx (EXPR_LIST, REG_DEAD, ! 1099: reg, REG_NOTES (insn)); ! 1100: } ! 1101: } ! 1102: } ! 1103: } ! 1104: ! 1105: /* Scan expression X and store a 1-bit in LIVE for each reg it uses. ! 1106: This is done assuming the registers needed from X ! 1107: are those that have 1-bits in NEEDED. ! 1108: ! 1109: On the final pass, INSN is the containing instruction. */ ! 1110: ! 1111: static void ! 1112: mark_used_regs (needed, live, x, insn) ! 1113: regset needed; ! 1114: regset live; ! 1115: rtx x; ! 1116: rtx insn; ! 1117: { ! 1118: register RTX_CODE code; ! 1119: register int regno; ! 1120: ! 1121: retry: ! 1122: code = GET_CODE (x); ! 1123: switch (code) ! 1124: { ! 1125: case LABEL_REF: ! 1126: case SYMBOL_REF: ! 1127: case CONST_INT: ! 1128: case CONST: ! 1129: case CC0: ! 1130: case PC: ! 1131: case CLOBBER: ! 1132: return; ! 1133: ! 1134: #if defined (HAVE_POST_INCREMENT) || defined (HAVE_POST_DECREMENT) ! 1135: case MEM: ! 1136: /* Here we detect use of an index register which might ! 1137: be good for postincrement or postdecrement. */ ! 1138: if (insn) ! 1139: { ! 1140: rtx addr = XEXP (x, 0); ! 1141: register int size = GET_MODE_SIZE (GET_MODE (x)); ! 1142: ! 1143: if (GET_CODE (addr) == REG) ! 1144: { ! 1145: register rtx y; ! 1146: regno = REGNO (addr); ! 1147: /* Is the next use an increment that might make auto-increment? */ ! 1148: y = reg_next_use[regno]; ! 1149: if (y && GET_CODE (PATTERN (y)) == SET ! 1150: && BLOCK_NUM (y) == BLOCK_NUM (insn) ! 1151: && SET_DEST (PATTERN (y)) == addr ! 1152: /* Can't add side effects to jumps; if reg is spilled and ! 1153: reloaded, there's no way to store back the altered value. */ ! 1154: && GET_CODE (insn) != JUMP_INSN ! 1155: && (y = SET_SRC (PATTERN (y)), ! 1156: (0 ! 1157: #ifdef HAVE_POST_INCREMENT ! 1158: || GET_CODE (y) == PLUS ! 1159: #endif ! 1160: #ifdef HAVE_POST_DECREMENT ! 1161: || GET_CODE (y) == MINUS ! 1162: #endif ! 1163: ) ! 1164: && XEXP (y, 0) == addr ! 1165: && GET_CODE (XEXP (y, 1)) == CONST_INT ! 1166: && INTVAL (XEXP (y, 1)) == size)) ! 1167: { ! 1168: rtx use = find_use_as_address (PATTERN (insn), addr); ! 1169: ! 1170: /* Make sure this register appears only once in this insn. */ ! 1171: if (use != 0 && use != (rtx) 1) ! 1172: { ! 1173: /* We have found a suitable auto-increment: ! 1174: do POST_INC around the register here, ! 1175: and patch out the increment instruction that follows. */ ! 1176: XEXP (x, 0) ! 1177: = gen_rtx (GET_CODE (y) == PLUS ? POST_INC : POST_DEC, ! 1178: Pmode, addr); ! 1179: /* Record that this insn has an implicit side effect. */ ! 1180: REG_NOTES (insn) ! 1181: = gen_rtx (EXPR_LIST, REG_INC, addr, REG_NOTES (insn)); ! 1182: ! 1183: y = reg_next_use[regno]; ! 1184: PUT_CODE (y, NOTE); ! 1185: NOTE_LINE_NUMBER (y) = NOTE_INSN_DELETED; ! 1186: NOTE_SOURCE_FILE (y) = 0; ! 1187: /* Count a reference to this reg for the increment ! 1188: insn we are deleting. When a reg is incremented. ! 1189: spilling it is worse, so we want to make that ! 1190: less likely. */ ! 1191: reg_n_refs[regno] += loop_depth; ! 1192: } ! 1193: } ! 1194: } ! 1195: } ! 1196: break; ! 1197: #endif /* HAVE_POST_INCREMENT or HAVE_POST_DECREMENT */ ! 1198: ! 1199: case REG: ! 1200: /* See a register other than being set ! 1201: => mark it as needed. */ ! 1202: ! 1203: regno = REGNO (x); ! 1204: if (regno != FRAME_POINTER_REGNUM ! 1205: && regno != ARG_POINTER_REGNUM && regno != STACK_POINTER_REGNUM) ! 1206: { ! 1207: register int offset = regno / REGSET_ELT_BITS; ! 1208: register int bit = 1 << (regno % REGSET_ELT_BITS); ! 1209: live[offset] |= bit; ! 1210: if (insn) ! 1211: { ! 1212: register int blocknum = BLOCK_NUM (insn); ! 1213: ! 1214: /* If a hard reg is being used, ! 1215: record that this function does use it. */ ! 1216: ! 1217: if (regno < FIRST_PSEUDO_REGISTER) ! 1218: { ! 1219: register int i; ! 1220: i = HARD_REGNO_NREGS (regno, GET_MODE (x)); ! 1221: do ! 1222: regs_ever_live[regno + --i] = 1; ! 1223: while (i > 0); ! 1224: } ! 1225: ! 1226: /* Keep track of which basic block each reg appears in. */ ! 1227: ! 1228: if (reg_basic_block[regno] == -1) ! 1229: reg_basic_block[regno] = blocknum; ! 1230: else if (reg_basic_block[regno] != blocknum) ! 1231: reg_basic_block[regno] = -2; ! 1232: ! 1233: /* Record where each reg is used ! 1234: so when the reg is set we know the next insn that uses it. */ ! 1235: ! 1236: reg_next_use[regno] = insn; ! 1237: ! 1238: /* Count (weighted) number of uses of each reg. */ ! 1239: ! 1240: reg_n_refs[regno] += loop_depth; ! 1241: ! 1242: /* Record and count the insns in which a reg dies. ! 1243: If it is used in this insn and was dead below the insn ! 1244: then it dies in this insn. */ ! 1245: ! 1246: if (!(needed[offset] & bit) && !flow_deadp (regno, insn)) ! 1247: { ! 1248: REG_NOTES (insn) ! 1249: = gen_rtx (EXPR_LIST, REG_DEAD, x, REG_NOTES (insn)); ! 1250: reg_n_deaths[regno]++; ! 1251: } ! 1252: } ! 1253: } ! 1254: return; ! 1255: ! 1256: case SET: ! 1257: { ! 1258: register rtx reg = SET_DEST (x); ! 1259: ! 1260: /* Modifying just one hardware register ! 1261: of a multi-register value does not count as "setting" ! 1262: for live-dead analysis. It is more like a reference. ! 1263: But storing in a single register with an alternate mode ! 1264: is storing in the register. */ ! 1265: if (GET_CODE (reg) == SUBREG ! 1266: && !(REG_SIZE (SUBREG_REG (reg)) > REG_SIZE (reg))) ! 1267: reg = SUBREG_REG (reg); ! 1268: ! 1269: /* If this is a store into a register, ! 1270: recursively scan the only value being stored, ! 1271: and only if the register's value is live after this insn. ! 1272: If the value being computed here would never be used ! 1273: then the values it uses don't need to be computed either. */ ! 1274: ! 1275: if (GET_CODE (reg) == REG ! 1276: && (regno = REGNO (reg), regno != FRAME_POINTER_REGNUM) ! 1277: && regno != ARG_POINTER_REGNUM && regno != STACK_POINTER_REGNUM) ! 1278: { ! 1279: register int offset = regno / REGSET_ELT_BITS; ! 1280: register int bit = 1 << (regno % REGSET_ELT_BITS); ! 1281: if (needed[offset] & bit) ! 1282: mark_used_regs (needed, live, XEXP (x, 1), insn); ! 1283: return; ! 1284: } ! 1285: } ! 1286: break; ! 1287: } ! 1288: ! 1289: /* Recursively scan the operands of this expression. */ ! 1290: ! 1291: { ! 1292: register char *fmt = GET_RTX_FORMAT (code); ! 1293: register int i; ! 1294: ! 1295: for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) ! 1296: { ! 1297: if (fmt[i] == 'e') ! 1298: { ! 1299: /* Tail recursive case: save a function call level. */ ! 1300: if (i == 0) ! 1301: { ! 1302: x = XEXP (x, 0); ! 1303: goto retry; ! 1304: } ! 1305: mark_used_regs (needed, live, XEXP (x, i), insn); ! 1306: } ! 1307: if (fmt[i] == 'E') ! 1308: { ! 1309: register int j; ! 1310: for (j = 0; j < XVECLEN (x, i); j++) ! 1311: mark_used_regs (needed, live, XVECEXP (x, i, j), insn); ! 1312: } ! 1313: } ! 1314: } ! 1315: } ! 1316: ! 1317: #if defined (HAVE_PRE_INCREMENT) || defined (HAVE_PRE_DECREMENT) ! 1318: ! 1319: static int ! 1320: try_pre_increment_1 (insn) ! 1321: rtx insn; ! 1322: { ! 1323: /* Find the next use of this reg. If in same basic block, ! 1324: make it do pre-increment or pre-decrement if appropriate. */ ! 1325: rtx x = PATTERN (insn); ! 1326: int amount = ((GET_CODE (SET_SRC (x)) == PLUS ? 1 : -1) ! 1327: * INTVAL (XEXP (SET_SRC (x), 1))); ! 1328: int regno = REGNO (SET_DEST (x)); ! 1329: rtx y = reg_next_use[regno]; ! 1330: if (y != 0 ! 1331: && BLOCK_NUM (y) == BLOCK_NUM (insn) ! 1332: && try_pre_increment (y, SET_DEST (PATTERN (insn)), ! 1333: amount)) ! 1334: { ! 1335: /* We have found a suitable auto-increment ! 1336: and already changed insn Y to do it. ! 1337: So flush this increment-instruction. */ ! 1338: PUT_CODE (insn, NOTE); ! 1339: NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED; ! 1340: NOTE_SOURCE_FILE (insn) = 0; ! 1341: /* Count a reference to this reg for the increment ! 1342: insn we are deleting. When a reg is incremented. ! 1343: spilling it is worse, so we want to make that ! 1344: less likely. */ ! 1345: reg_n_refs[regno] += loop_depth; ! 1346: return 1; ! 1347: } ! 1348: return 0; ! 1349: } ! 1350: ! 1351: /* Try to change INSN so that it does pre-increment or pre-decrement ! 1352: addressing on register REG in order to add AMOUNT to REG. ! 1353: AMOUNT is negative for pre-decrement. ! 1354: Returns 1 if the change could be made. ! 1355: This checks all about the validity of the result of modifying INSN. */ ! 1356: ! 1357: static int ! 1358: try_pre_increment (insn, reg, amount) ! 1359: rtx insn, reg; ! 1360: int amount; ! 1361: { ! 1362: register rtx use; ! 1363: ! 1364: #ifndef HAVE_PRE_INCREMENT ! 1365: #ifndef HAVE_PRE_DECREMENT ! 1366: return 0; ! 1367: #else ! 1368: if (amount > 0) ! 1369: return 0; ! 1370: #endif ! 1371: #endif ! 1372: ! 1373: #ifndef HAVE_PRE_DECREMENT ! 1374: if (amount < 0) ! 1375: return 0; ! 1376: #endif ! 1377: ! 1378: /* It is not safe to add a side effect to a jump insn ! 1379: because if the incremented register is spilled and must be reloaded ! 1380: there would be no way to store the incremented value back in memory. */ ! 1381: ! 1382: if (GET_CODE (insn) == JUMP_INSN) ! 1383: return 0; ! 1384: ! 1385: use = find_use_as_address (PATTERN (insn), reg); ! 1386: ! 1387: if (use == 0 || use == (rtx) 1) ! 1388: return 0; ! 1389: ! 1390: if (GET_MODE_SIZE (GET_MODE (use)) != (amount > 0 ? amount : - amount)) ! 1391: return 0; ! 1392: ! 1393: XEXP (use, 0) = gen_rtx (amount > 0 ? PRE_INC : PRE_DEC, ! 1394: Pmode, reg); ! 1395: ! 1396: /* Record that this insn now has an implicit side effect on X. */ ! 1397: REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_INC, reg, REG_NOTES (insn)); ! 1398: return 1; ! 1399: } ! 1400: ! 1401: /* Find the place in the rtx X where REG is used as a memory address. ! 1402: Return the MEM rtx that so uses it. ! 1403: If REG does not appear, return 0. ! 1404: If REG appears more than once, or is used other than as a memory address, ! 1405: return (rtx)1. */ ! 1406: ! 1407: static rtx ! 1408: find_use_as_address (x, reg) ! 1409: register rtx x; ! 1410: rtx reg; ! 1411: { ! 1412: enum rtx_code code = GET_CODE (x); ! 1413: char *fmt = GET_RTX_FORMAT (code); ! 1414: register int i; ! 1415: register rtx value = 0; ! 1416: register rtx tem; ! 1417: ! 1418: if (code == MEM && XEXP (x, 0) == reg) ! 1419: return x; ! 1420: ! 1421: if (x == reg) ! 1422: return (rtx) 1; ! 1423: ! 1424: for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) ! 1425: { ! 1426: if (fmt[i] == 'e') ! 1427: { ! 1428: tem = find_use_as_address (XEXP (x, i), reg); ! 1429: if (value == 0) ! 1430: value = tem; ! 1431: else if (tem != 0) ! 1432: return (rtx) 1; ! 1433: } ! 1434: if (fmt[i] == 'E') ! 1435: { ! 1436: register int j; ! 1437: for (j = XVECLEN (x, i) - 1; j >= 0; j--) ! 1438: { ! 1439: tem = find_use_as_address (XVECEXP (x, i, j), reg); ! 1440: if (value == 0) ! 1441: value = tem; ! 1442: else if (tem != 0) ! 1443: return (rtx) 1; ! 1444: } ! 1445: } ! 1446: } ! 1447: ! 1448: return value; ! 1449: } ! 1450: ! 1451: #endif /* HAVE_PRE_INCREMENT or HAVE_PRE_DECREMENT */ ! 1452: ! 1453: /* Write information about registers and basic blocks into FILE. ! 1454: This is part of making a debugging dump. */ ! 1455: ! 1456: dump_flow_info (file) ! 1457: FILE *file; ! 1458: { ! 1459: register int i; ! 1460: static char *reg_class_names[] = REG_CLASS_NAMES; ! 1461: ! 1462: fprintf (file, "%d registers.\n", max_regno); ! 1463: ! 1464: for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++) ! 1465: if (reg_n_refs[i]) ! 1466: { ! 1467: register rtx chain; ! 1468: enum reg_class class; ! 1469: fprintf (file, "\nRegister %d used %d times across %d insns", ! 1470: i, reg_n_refs[i], reg_live_length[i]); ! 1471: if (reg_basic_block[i] >= 0) ! 1472: fprintf (file, " in block %d", reg_basic_block[i]); ! 1473: if (reg_n_deaths[i] != 1) ! 1474: fprintf (file, "; dies in %d places", reg_n_deaths[i]); ! 1475: if (reg_crosses_call[i]) ! 1476: fprintf (file, "; crosses calls"); ! 1477: if (PSEUDO_REGNO_BYTES (i) != UNITS_PER_WORD) ! 1478: fprintf (file, "; %d bytes", PSEUDO_REGNO_BYTES (i)); ! 1479: class = reg_preferred_class (i); ! 1480: if (class != GENERAL_REGS) ! 1481: fprintf (file, "; pref %s", reg_class_names[(int) class]); ! 1482: if (REGNO_POINTER_FLAG (i)) ! 1483: fprintf (file, "; pointer"); ! 1484: fprintf (file, ".\n"); ! 1485: } ! 1486: fprintf (file, "\n%d basic blocks.\n", n_basic_blocks); ! 1487: for (i = 0; i < n_basic_blocks; i++) ! 1488: { ! 1489: register rtx head, jump; ! 1490: register int regno; ! 1491: fprintf (file, "\nBasic block %d: first insn %d, last %d.\n", ! 1492: i, ! 1493: INSN_UID (basic_block_head[i]), ! 1494: INSN_UID (basic_block_end[i])); ! 1495: /* The control flow graph's storage is freed ! 1496: now when flow_analysis returns. ! 1497: Don't try to print it if it is gone. */ ! 1498: if (basic_block_drops_in) ! 1499: { ! 1500: fprintf (file, "Reached from blocks: "); ! 1501: head = basic_block_head[i]; ! 1502: if (GET_CODE (head) == CODE_LABEL) ! 1503: for (jump = LABEL_REFS (head); ! 1504: jump != head; ! 1505: jump = LABEL_NEXTREF (jump)) ! 1506: { ! 1507: register from_block = BLOCK_NUM (CONTAINING_INSN (jump)); ! 1508: fprintf (file, " %d", from_block); ! 1509: } ! 1510: if (basic_block_drops_in[i]) ! 1511: fprintf (file, " previous"); ! 1512: } ! 1513: fprintf (file, "\nRegisters live at start:"); ! 1514: for (regno = 0; regno < max_regno; regno++) ! 1515: { ! 1516: register int offset = regno / REGSET_ELT_BITS; ! 1517: register int bit = 1 << (regno % REGSET_ELT_BITS); ! 1518: if (basic_block_live_at_start[i][offset] & bit) ! 1519: fprintf (file, " %d", regno); ! 1520: } ! 1521: fprintf (file, "\n"); ! 1522: } ! 1523: fprintf (file, "\n"); ! 1524: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.