void print_insn (pretty_printer *pp, const_rtx x, int verbose) { if (verbose) { /* Blech, pretty-print can't print integers with a specified width. */ char uid_prefix[32]; snprintf (uid_prefix, sizeof uid_prefix, " %4d: ", INSN_UID (x)); pp_string (pp, uid_prefix); } switch (GET_CODE (x)) { case INSN: print_pattern (pp, PATTERN (x), verbose); break; case DEBUG_INSN: { const char *name = "?"; if (DECL_P (INSN_VAR_LOCATION_DECL (x))) { tree id = DECL_NAME (INSN_VAR_LOCATION_DECL (x)); char idbuf[32]; if (id) name = IDENTIFIER_POINTER (id); else if (TREE_CODE (INSN_VAR_LOCATION_DECL (x)) == DEBUG_EXPR_DECL) { sprintf (idbuf, "D#%i", DEBUG_TEMP_UID (INSN_VAR_LOCATION_DECL (x))); name = idbuf; } else { sprintf (idbuf, "D.%i", DECL_UID (INSN_VAR_LOCATION_DECL (x))); name = idbuf; } } pp_printf (pp, "debug %s => ", name); if (VAR_LOC_UNKNOWN_P (INSN_VAR_LOCATION_LOC (x))) pp_string (pp, "optimized away"); else print_pattern (pp, INSN_VAR_LOCATION_LOC (x), verbose); } break; case JUMP_INSN: print_pattern (pp, PATTERN (x), verbose); break; case CALL_INSN: if (GET_CODE (PATTERN (x)) == PARALLEL) print_pattern (pp, XVECEXP (PATTERN (x), 0, 0), verbose); else print_pattern (pp, PATTERN (x), verbose); break; case CODE_LABEL: pp_printf (pp, "L%d:", INSN_UID (x)); break; case JUMP_TABLE_DATA: pp_string (pp, "jump_table_data{\n"); print_pattern (pp, PATTERN (x), verbose); pp_right_brace (pp); break; case BARRIER: pp_string (pp, "barrier"); break; case NOTE: { pp_string (pp, GET_NOTE_INSN_NAME (NOTE_KIND (x))); switch (NOTE_KIND (x)) { case NOTE_INSN_EH_REGION_BEG: case NOTE_INSN_EH_REGION_END: pp_printf (pp, " %d", NOTE_EH_HANDLER (x)); break; case NOTE_INSN_BLOCK_BEG: case NOTE_INSN_BLOCK_END: pp_printf (pp, " %d", BLOCK_NUMBER (NOTE_BLOCK (x))); break; case NOTE_INSN_BASIC_BLOCK: pp_printf (pp, " %d", NOTE_BASIC_BLOCK (x)->index); break; case NOTE_INSN_DELETED_LABEL: case NOTE_INSN_DELETED_DEBUG_LABEL: { const char *label = NOTE_DELETED_LABEL_NAME (x); if (label == NULL) label = ""; pp_printf (pp, " (\"%s\")", label); } break; case NOTE_INSN_VAR_LOCATION: case NOTE_INSN_CALL_ARG_LOCATION: pp_left_brace (pp); print_pattern (pp, NOTE_VAR_LOCATION (x), verbose); pp_right_brace (pp); break; default: break; } break; } default: gcc_unreachable (); } } /* print_insn */
static bool copyprop_hardreg_forward_1 (basic_block bb, struct value_data *vd) { bool anything_changed = false; rtx insn; for (insn = BB_HEAD (bb); ; insn = NEXT_INSN (insn)) { int n_ops, i, alt, predicated; bool is_asm, any_replacements; rtx set; bool replaced[MAX_RECOG_OPERANDS]; bool changed = false; struct kill_set_value_data ksvd; if (!NONDEBUG_INSN_P (insn)) { if (DEBUG_INSN_P (insn)) { rtx loc = INSN_VAR_LOCATION_LOC (insn); if (!VAR_LOC_UNKNOWN_P (loc)) replace_oldest_value_addr (&INSN_VAR_LOCATION_LOC (insn), ALL_REGS, GET_MODE (loc), ADDR_SPACE_GENERIC, insn, vd); } if (insn == BB_END (bb)) break; else continue; } set = single_set (insn); extract_insn (insn); if (! constrain_operands (1)) fatal_insn_not_found (insn); preprocess_constraints (); alt = which_alternative; n_ops = recog_data.n_operands; is_asm = asm_noperands (PATTERN (insn)) >= 0; /* Simplify the code below by rewriting things to reflect matching constraints. Also promote OP_OUT to OP_INOUT in predicated instructions. */ predicated = GET_CODE (PATTERN (insn)) == COND_EXEC; for (i = 0; i < n_ops; ++i) { int matches = recog_op_alt[i][alt].matches; if (matches >= 0) recog_op_alt[i][alt].cl = recog_op_alt[matches][alt].cl; if (matches >= 0 || recog_op_alt[i][alt].matched >= 0 || (predicated && recog_data.operand_type[i] == OP_OUT)) recog_data.operand_type[i] = OP_INOUT; } /* Apply changes to earlier DEBUG_INSNs if possible. */ if (vd->n_debug_insn_changes) note_uses (&PATTERN (insn), cprop_find_used_regs, vd); /* For each earlyclobber operand, zap the value data. */ for (i = 0; i < n_ops; i++) if (recog_op_alt[i][alt].earlyclobber) kill_value (recog_data.operand[i], vd); /* Within asms, a clobber cannot overlap inputs or outputs. I wouldn't think this were true for regular insns, but scan_rtx treats them like that... */ note_stores (PATTERN (insn), kill_clobbered_value, vd); /* Kill all auto-incremented values. */ /* ??? REG_INC is useless, since stack pushes aren't done that way. */ for_each_rtx (&PATTERN (insn), kill_autoinc_value, vd); /* Kill all early-clobbered operands. */ for (i = 0; i < n_ops; i++) if (recog_op_alt[i][alt].earlyclobber) kill_value (recog_data.operand[i], vd); /* Special-case plain move instructions, since we may well be able to do the move from a different register class. */ if (set && REG_P (SET_SRC (set))) { rtx src = SET_SRC (set); unsigned int regno = REGNO (src); enum machine_mode mode = GET_MODE (src); unsigned int i; rtx new_rtx; /* If we are accessing SRC in some mode other that what we set it in, make sure that the replacement is valid. */ if (mode != vd->e[regno].mode) { if (hard_regno_nregs[regno][mode] > hard_regno_nregs[regno][vd->e[regno].mode]) goto no_move_special_case; /* And likewise, if we are narrowing on big endian the transformation is also invalid. */ if (hard_regno_nregs[regno][mode] < hard_regno_nregs[regno][vd->e[regno].mode] && (GET_MODE_SIZE (vd->e[regno].mode) > UNITS_PER_WORD ? WORDS_BIG_ENDIAN : BYTES_BIG_ENDIAN)) goto no_move_special_case; } /* If the destination is also a register, try to find a source register in the same class. */ if (REG_P (SET_DEST (set))) { new_rtx = find_oldest_value_reg (REGNO_REG_CLASS (regno), src, vd); if (new_rtx && validate_change (insn, &SET_SRC (set), new_rtx, 0)) { if (dump_file) fprintf (dump_file, "insn %u: replaced reg %u with %u\n", INSN_UID (insn), regno, REGNO (new_rtx)); changed = true; goto did_replacement; } /* We need to re-extract as validate_change clobbers recog_data. */ extract_insn (insn); if (! constrain_operands (1)) fatal_insn_not_found (insn); preprocess_constraints (); } /* Otherwise, try all valid registers and see if its valid. */ for (i = vd->e[regno].oldest_regno; i != regno; i = vd->e[i].next_regno) { new_rtx = maybe_mode_change (vd->e[i].mode, vd->e[regno].mode, mode, i, regno); if (new_rtx != NULL_RTX) { if (validate_change (insn, &SET_SRC (set), new_rtx, 0)) { ORIGINAL_REGNO (new_rtx) = ORIGINAL_REGNO (src); REG_ATTRS (new_rtx) = REG_ATTRS (src); REG_POINTER (new_rtx) = REG_POINTER (src); if (dump_file) fprintf (dump_file, "insn %u: replaced reg %u with %u\n", INSN_UID (insn), regno, REGNO (new_rtx)); changed = true; goto did_replacement; } /* We need to re-extract as validate_change clobbers recog_data. */ extract_insn (insn); if (! constrain_operands (1)) fatal_insn_not_found (insn); preprocess_constraints (); } } } no_move_special_case: any_replacements = false; /* For each input operand, replace a hard register with the eldest live copy that's in an appropriate register class. */ for (i = 0; i < n_ops; i++) { replaced[i] = false; /* Don't scan match_operand here, since we've no reg class information to pass down. Any operands that we could substitute in will be represented elsewhere. */ if (recog_data.constraints[i][0] == '\0') continue; /* Don't replace in asms intentionally referencing hard regs. */ if (is_asm && REG_P (recog_data.operand[i]) && (REGNO (recog_data.operand[i]) == ORIGINAL_REGNO (recog_data.operand[i]))) continue; if (recog_data.operand_type[i] == OP_IN) { if (recog_op_alt[i][alt].is_address) replaced[i] = replace_oldest_value_addr (recog_data.operand_loc[i], recog_op_alt[i][alt].cl, VOIDmode, ADDR_SPACE_GENERIC, insn, vd); else if (REG_P (recog_data.operand[i])) replaced[i] = replace_oldest_value_reg (recog_data.operand_loc[i], recog_op_alt[i][alt].cl, insn, vd); else if (MEM_P (recog_data.operand[i])) replaced[i] = replace_oldest_value_mem (recog_data.operand[i], insn, vd); } else if (MEM_P (recog_data.operand[i])) replaced[i] = replace_oldest_value_mem (recog_data.operand[i], insn, vd); /* If we performed any replacement, update match_dups. */ if (replaced[i]) { int j; rtx new_rtx; new_rtx = *recog_data.operand_loc[i]; recog_data.operand[i] = new_rtx; for (j = 0; j < recog_data.n_dups; j++) if (recog_data.dup_num[j] == i) validate_unshare_change (insn, recog_data.dup_loc[j], new_rtx, 1); any_replacements = true; } } if (any_replacements) { if (! apply_change_group ()) { for (i = 0; i < n_ops; i++) if (replaced[i]) { rtx old = *recog_data.operand_loc[i]; recog_data.operand[i] = old; } if (dump_file) fprintf (dump_file, "insn %u: reg replacements not verified\n", INSN_UID (insn)); } else changed = true; } did_replacement: if (changed) { anything_changed = true; /* If something changed, perhaps further changes to earlier DEBUG_INSNs can be applied. */ if (vd->n_debug_insn_changes) note_uses (&PATTERN (insn), cprop_find_used_regs, vd); } ksvd.vd = vd; ksvd.ignore_set_reg = NULL_RTX; /* Clobber call-clobbered registers. */ if (CALL_P (insn)) { unsigned int set_regno = INVALID_REGNUM; unsigned int set_nregs = 0; unsigned int regno; rtx exp; hard_reg_set_iterator hrsi; for (exp = CALL_INSN_FUNCTION_USAGE (insn); exp; exp = XEXP (exp, 1)) { rtx x = XEXP (exp, 0); if (GET_CODE (x) == SET) { rtx dest = SET_DEST (x); kill_value (dest, vd); set_value_regno (REGNO (dest), GET_MODE (dest), vd); copy_value (dest, SET_SRC (x), vd); ksvd.ignore_set_reg = dest; set_regno = REGNO (dest); set_nregs = hard_regno_nregs[set_regno][GET_MODE (dest)]; break; } } EXECUTE_IF_SET_IN_HARD_REG_SET (regs_invalidated_by_call, 0, regno, hrsi) if (regno < set_regno || regno >= set_regno + set_nregs) kill_value_regno (regno, 1, vd); /* If SET was seen in CALL_INSN_FUNCTION_USAGE, and SET_SRC of the SET isn't in regs_invalidated_by_call hard reg set, but instead among CLOBBERs on the CALL_INSN, we could wrongly assume the value in it is still live. */ if (ksvd.ignore_set_reg) note_stores (PATTERN (insn), kill_clobbered_value, vd); } /* Notice stores. */ note_stores (PATTERN (insn), kill_set_value, &ksvd); /* Notice copies. */ if (set && REG_P (SET_DEST (set)) && REG_P (SET_SRC (set))) copy_value (SET_DEST (set), SET_SRC (set), vd); if (insn == BB_END (bb)) break; } return anything_changed; }
void print_insn (char *buf, const_rtx x, int verbose) { char t[BUF_LEN]; const_rtx insn = x; switch (GET_CODE (x)) { case INSN: print_pattern (t, PATTERN (x), verbose); #ifdef INSN_SCHEDULING if (verbose && current_sched_info) sprintf (buf, "%s: %s", (*current_sched_info->print_insn) (x, 1), t); else #endif sprintf (buf, " %4d %s", INSN_UID (x), t); break; case DEBUG_INSN: { const char *name = "?"; if (DECL_P (INSN_VAR_LOCATION_DECL (insn))) { tree id = DECL_NAME (INSN_VAR_LOCATION_DECL (insn)); char idbuf[32]; if (id) name = IDENTIFIER_POINTER (id); else if (TREE_CODE (INSN_VAR_LOCATION_DECL (insn)) == DEBUG_EXPR_DECL) { sprintf (idbuf, "D#%i", DEBUG_TEMP_UID (INSN_VAR_LOCATION_DECL (insn))); name = idbuf; } else { sprintf (idbuf, "D.%i", DECL_UID (INSN_VAR_LOCATION_DECL (insn))); name = idbuf; } } if (VAR_LOC_UNKNOWN_P (INSN_VAR_LOCATION_LOC (insn))) sprintf (buf, " %4d: debug %s optimized away", INSN_UID (insn), name); else { print_pattern (t, INSN_VAR_LOCATION_LOC (insn), verbose); sprintf (buf, " %4d: debug %s => %s", INSN_UID (insn), name, t); } } break; case JUMP_INSN: print_pattern (t, PATTERN (x), verbose); #ifdef INSN_SCHEDULING if (verbose && current_sched_info) sprintf (buf, "%s: jump %s", (*current_sched_info->print_insn) (x, 1), t); else #endif sprintf (buf, " %4d %s", INSN_UID (x), t); break; case CALL_INSN: x = PATTERN (insn); if (GET_CODE (x) == PARALLEL) { x = XVECEXP (x, 0, 0); print_pattern (t, x, verbose); } else strcpy (t, "call <...>"); #ifdef INSN_SCHEDULING if (verbose && current_sched_info) sprintf (buf, "%s: %s", (*current_sched_info->print_insn) (insn, 1), t); else #endif sprintf (buf, " %4d %s", INSN_UID (insn), t); break; case CODE_LABEL: sprintf (buf, "L%d:", INSN_UID (x)); break; case BARRIER: sprintf (buf, "i%4d: barrier", INSN_UID (x)); break; case NOTE: sprintf (buf, " %4d %s", INSN_UID (x), GET_NOTE_INSN_NAME (NOTE_KIND (x))); break; default: sprintf (buf, "i%4d <What %s?>", INSN_UID (x), GET_RTX_NAME (GET_CODE (x))); } } /* print_insn */