📄 flow.c
字号:
return 0;}/* Check expression X for label references; if one is found, add INSN to the label's chain of references. CHECKDUP means check for and avoid creating duplicate references from the same insn. Such duplicates do no serious harm but can slow life analysis. CHECKDUP is set only when duplicates are likely. */static voidmark_label_ref (x, insn, checkdup) rtx x, insn; int checkdup;{ register RTX_CODE code; register int i; register char *fmt; /* We can be called with NULL when scanning label_value_list. */ if (x == 0) return; code = GET_CODE (x); if (code == LABEL_REF) { register rtx label = XEXP (x, 0); register rtx y; if (GET_CODE (label) != CODE_LABEL) abort (); /* If the label was never emitted, this insn is junk, but avoid a crash trying to refer to BLOCK_NUM (label). This can happen as a result of a syntax error and a diagnostic has already been printed. */ if (INSN_UID (label) == 0) return; CONTAINING_INSN (x) = insn; /* if CHECKDUP is set, check for duplicate ref from same insn and don't insert. */ if (checkdup) for (y = LABEL_REFS (label); y != label; y = LABEL_NEXTREF (y)) if (CONTAINING_INSN (y) == insn) return; LABEL_NEXTREF (x) = LABEL_REFS (label); LABEL_REFS (label) = x; block_live_static[BLOCK_NUM (label)] = 1; return; } fmt = GET_RTX_FORMAT (code); for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) { if (fmt[i] == 'e') mark_label_ref (XEXP (x, i), insn, 0); if (fmt[i] == 'E') { register int j; for (j = 0; j < XVECLEN (x, i); j++) mark_label_ref (XVECEXP (x, i, j), insn, 1); } }}/* Delete INSN by patching it out. Return the next insn. */static rtxflow_delete_insn (insn) rtx insn;{ /* ??? For the moment we assume we don't have to watch for NULLs here since the start/end of basic blocks aren't deleted like this. */ NEXT_INSN (PREV_INSN (insn)) = NEXT_INSN (insn); PREV_INSN (NEXT_INSN (insn)) = PREV_INSN (insn); return NEXT_INSN (insn);}/* Determine which registers are live at the start of each basic block of the function whose first insn is F. NREGS is the number of registers used in F. We allocate the vector basic_block_live_at_start and the regsets that it points to, and fill them with the data. regset_size and regset_bytes are also set here. */static voidlife_analysis (f, nregs) rtx f; int nregs;{ register regset tem; int first_pass; int changed; /* For each basic block, a bitmask of regs live on exit from the block. */ regset *basic_block_live_at_end; /* For each basic block, a bitmask of regs live on entry to a successor-block of this block. If this does not match basic_block_live_at_end, that must be updated, and the block must be rescanned. */ regset *basic_block_new_live_at_end; /* For each basic block, a bitmask of regs whose liveness at the end of the basic block can make a difference in which regs are live on entry to the block. These are the regs that are set within the basic block, possibly excluding those that are used after they are set. */ regset *basic_block_significant; register int i; rtx insn; struct obstack flow_obstack; gcc_obstack_init (&flow_obstack); max_regno = nregs; bzero (regs_ever_live, sizeof regs_ever_live); /* Allocate and zero out many data structures that will record the data from lifetime analysis. */ allocate_for_life_analysis (); reg_next_use = (rtx *) alloca (nregs * sizeof (rtx)); bzero ((char *) reg_next_use, nregs * sizeof (rtx)); /* Set up several regset-vectors used internally within this function. Their meanings are documented above, with their declarations. */ basic_block_live_at_end = (regset *) alloca (n_basic_blocks * sizeof (regset)); /* Don't use alloca since that leads to a crash rather than an error message if there isn't enough space. Don't use oballoc since we may need to allocate other things during this function on the temporary obstack. */ tem = (regset) obstack_alloc (&flow_obstack, n_basic_blocks * regset_bytes); bzero ((char *) tem, n_basic_blocks * regset_bytes); init_regset_vector (basic_block_live_at_end, tem, n_basic_blocks, regset_bytes); basic_block_new_live_at_end = (regset *) alloca (n_basic_blocks * sizeof (regset)); tem = (regset) obstack_alloc (&flow_obstack, n_basic_blocks * regset_bytes); bzero ((char *) tem, n_basic_blocks * regset_bytes); init_regset_vector (basic_block_new_live_at_end, tem, n_basic_blocks, regset_bytes); basic_block_significant = (regset *) alloca (n_basic_blocks * sizeof (regset)); tem = (regset) obstack_alloc (&flow_obstack, n_basic_blocks * regset_bytes); bzero ((char *) tem, n_basic_blocks * regset_bytes); init_regset_vector (basic_block_significant, tem, n_basic_blocks, regset_bytes); /* Record which insns refer to any volatile memory or for any reason can't be deleted just because they are dead stores. Also, delete any insns that copy a register to itself. */ for (insn = f; insn; insn = NEXT_INSN (insn)) { enum rtx_code code1 = GET_CODE (insn); if (code1 == CALL_INSN) INSN_VOLATILE (insn) = 1; else if (code1 == INSN || code1 == JUMP_INSN) { /* Delete (in effect) any obvious no-op moves. */ if (GET_CODE (PATTERN (insn)) == SET && GET_CODE (SET_DEST (PATTERN (insn))) == REG && GET_CODE (SET_SRC (PATTERN (insn))) == REG && REGNO (SET_DEST (PATTERN (insn))) == REGNO (SET_SRC (PATTERN (insn))) /* Insns carrying these notes are useful later on. */ && ! find_reg_note (insn, REG_EQUAL, NULL_RTX)) { PUT_CODE (insn, NOTE); NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED; NOTE_SOURCE_FILE (insn) = 0; } else if (GET_CODE (PATTERN (insn)) == PARALLEL) { /* If nothing but SETs of registers to themselves, this insn can also be deleted. */ for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++) { rtx tem = XVECEXP (PATTERN (insn), 0, i); if (GET_CODE (tem) == USE || GET_CODE (tem) == CLOBBER) continue; if (GET_CODE (tem) != SET || GET_CODE (SET_DEST (tem)) != REG || GET_CODE (SET_SRC (tem)) != REG || REGNO (SET_DEST (tem)) != REGNO (SET_SRC (tem))) break; } if (i == XVECLEN (PATTERN (insn), 0) /* Insns carrying these notes are useful later on. */ && ! find_reg_note (insn, REG_EQUAL, NULL_RTX)) { PUT_CODE (insn, NOTE); NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED; NOTE_SOURCE_FILE (insn) = 0; } else INSN_VOLATILE (insn) = volatile_refs_p (PATTERN (insn)); } else if (GET_CODE (PATTERN (insn)) != USE) INSN_VOLATILE (insn) = volatile_refs_p (PATTERN (insn)); /* A SET that makes space on the stack cannot be dead. (Such SETs occur only for allocating variable-size data, so they will always have a PLUS or MINUS according to the direction of stack growth.) Even if this function never uses this stack pointer value, signal handlers do! */ else if (code1 == INSN && GET_CODE (PATTERN (insn)) == SET && SET_DEST (PATTERN (insn)) == stack_pointer_rtx#ifdef STACK_GROWS_DOWNWARD && GET_CODE (SET_SRC (PATTERN (insn))) == MINUS#else && GET_CODE (SET_SRC (PATTERN (insn))) == PLUS#endif && XEXP (SET_SRC (PATTERN (insn)), 0) == stack_pointer_rtx) INSN_VOLATILE (insn) = 1; } } if (n_basic_blocks > 0)#ifdef EXIT_IGNORE_STACK if (! EXIT_IGNORE_STACK || (! FRAME_POINTER_REQUIRED && flag_omit_frame_pointer))#endif { /* If exiting needs the right stack value, consider the stack pointer live at the end of the function. */ basic_block_live_at_end[n_basic_blocks - 1] [STACK_POINTER_REGNUM / REGSET_ELT_BITS] |= (REGSET_ELT_TYPE) 1 << (STACK_POINTER_REGNUM % REGSET_ELT_BITS); basic_block_new_live_at_end[n_basic_blocks - 1] [STACK_POINTER_REGNUM / REGSET_ELT_BITS] |= (REGSET_ELT_TYPE) 1 << (STACK_POINTER_REGNUM % REGSET_ELT_BITS); } /* Mark the frame pointer is needed at the end of the function. If we end up eliminating it, it will be removed from the live list of each basic block by reload. */ if (n_basic_blocks > 0) { basic_block_live_at_end[n_basic_blocks - 1] [FRAME_POINTER_REGNUM / REGSET_ELT_BITS] |= (REGSET_ELT_TYPE) 1 << (FRAME_POINTER_REGNUM % REGSET_ELT_BITS); basic_block_new_live_at_end[n_basic_blocks - 1] [FRAME_POINTER_REGNUM / REGSET_ELT_BITS] |= (REGSET_ELT_TYPE) 1 << (FRAME_POINTER_REGNUM % REGSET_ELT_BITS);#if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM /* If they are different, also mark the hard frame pointer as live */ basic_block_live_at_end[n_basic_blocks - 1] [HARD_FRAME_POINTER_REGNUM / REGSET_ELT_BITS] |= (REGSET_ELT_TYPE) 1 << (HARD_FRAME_POINTER_REGNUM % REGSET_ELT_BITS); basic_block_new_live_at_end[n_basic_blocks - 1] [HARD_FRAME_POINTER_REGNUM / REGSET_ELT_BITS] |= (REGSET_ELT_TYPE) 1 << (HARD_FRAME_POINTER_REGNUM % REGSET_ELT_BITS);#endif } /* Mark all global registers as being live at the end of the function since they may be referenced by our caller. */ if (n_basic_blocks > 0) for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) if (global_regs[i]) { basic_block_live_at_end[n_basic_blocks - 1] [i / REGSET_ELT_BITS] |= (REGSET_ELT_TYPE) 1 << (i % REGSET_ELT_BITS); basic_block_new_live_at_end[n_basic_blocks - 1] [i / REGSET_ELT_BITS] |= (REGSET_ELT_TYPE) 1 << (i % REGSET_ELT_BITS); } /* Propagate life info through the basic blocks around the graph of basic blocks. This is a relaxation process: each time a new register is live at the end of the basic block, we must scan the block to determine which registers are, as a consequence, live at the beginning of that block. These registers must then be marked live at the ends of all the blocks that can transfer control to that block. The process continues until it reaches a fixed point. */ first_pass = 1; changed = 1; while (changed) { changed = 0; for (i = n_basic_blocks - 1; i >= 0; i--) { int consider = first_pass; int must_rescan = first_pass; register int j; if (!first_pass) { /* Set CONSIDER if this block needs thinking about at all (that is, if the regs live now at the end of it are not the same as were live at the end of it when we last thought about it). Set must_rescan if it needs to be thought about instruction by instruction (that is, if any additional reg that is live at the end now but was not live there before is one of the significant regs of this basic block). */ for (j = 0; j < regset_size; j++) { register REGSET_ELT_TYPE x = (basic_block_new_live_at_end[i][j] & ~basic_block_live_at_end[i][j]); if (x) consider = 1; if (x & basic_block_significant[i][j]) { must_rescan = 1; consider = 1; break; } } if (! consider) continue; } /* The live_at_start of this block may be changing, so another pass will be required after this one. */ changed = 1; if (! must_rescan) { /* No complete rescan needed; just record those variables newly known live at end as live at start as well. */ for (j = 0; j < regset_size; j++) { register REGSET_ELT_TYPE x = (basic_block_new_live_at_end[i][j] & ~basic_block_live_at_end[i][j]); basic_block_live_at_start[i][j] |= x; basic_block_live_at_end[i][j] |= x; } } else { /* Update the basic_block_live_at_start by propagation backwards through the block. */ bcopy ((char *) basic_block_new_live_at_end[i], (char *) basic_block_live_at_end[i], regset_bytes); bcopy ((char *) basic_block_live_at_end[i], (char *) basic_block_live_at_start[i], regset_bytes); propagate_block (basic_block_live_at_start[i], basic_block_head[i], basic_block_end[i], 0, first_pass ? basic_block_significant[i] : (regset) 0, i); } { register rtx jump, head; /* Update the basic_block_new_live_at_end's of the block that falls through into this one (if any). */ head = basic_block_head[i]; if (basic_block_drops_in[i]) { register int j; for (j = 0; j < regset_size; j++) basic_block_new_live_at_end[i-1][j] |= basic_block_live_at_start[i][j]; } /* Update the basic_block_new_live_at_end's of all the blocks that jump to this one. */ if (GET_CODE (head) == CODE_LABEL) for (jump = LABEL_REFS (head); jump != head; jump = LABEL_NEXTREF (jump)) { register int from_block = BLOCK_NUM (CONTAINING_INSN (jump)); register int j; for (j = 0; j < regset_size; j++) basic_block_new_live_at_end[from_block][j] |= basic_block_live_at_start[i][j];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -