#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "toplev.h"
#include "rtl.h"
#include "tree.h"
#include "tm_p.h"
#include "regs.h"
#include "hard-reg-set.h"
#include "flags.h"
#include "real.h"
#include "insn-config.h"
#include "recog.h"
#include "basic-block.h"
#include "output.h"
#include "function.h"
#include "expr.h"
#include "except.h"
#include "intl.h"
#include "obstack.h"
#include "hashtab.h"
#include "params.h"
#include "target.h"
#include "timevar.h"
#include "tree-pass.h"
static struct
{
int moves_inserted;
int copies_inserted;
int insns_deleted;
} stats;
static htab_t expr_table;
struct expr
{
rtx expr;
hashval_t hash;
struct occr *avail_occr;
};
static struct obstack expr_obstack;
struct occr
{
struct occr *next;
rtx insn;
char deleted_p;
};
static struct obstack occr_obstack;
struct unoccr
{
struct unoccr *next;
edge pred;
rtx insn;
};
static struct obstack unoccr_obstack;
static int *reg_avail_info;
struct modifies_mem
{
rtx insn;
struct modifies_mem *next;
};
static struct modifies_mem *modifies_mem_list;
static struct obstack modifies_mem_obstack;
static struct modifies_mem *modifies_mem_obstack_bottom;
static int *uid_cuid;
#define INSN_CUID(INSN) (uid_cuid[INSN_UID (INSN)])
static void alloc_mem (void);
static void free_mem (void);
static bool oprs_unchanged_p (rtx, rtx, bool);
static void record_last_reg_set_info (rtx, int);
static void record_last_mem_set_info (rtx);
static void record_last_set_info (rtx, rtx, void *);
static void record_opr_changes (rtx);
static void find_mem_conflicts (rtx, rtx, void *);
static int load_killed_in_block_p (int, rtx, bool);
static void reset_opr_set_tables (void);
static hashval_t hash_expr (rtx, int *);
static hashval_t hash_expr_for_htab (const void *);
static int expr_equiv_p (const void *, const void *);
static void insert_expr_in_table (rtx, rtx);
static struct expr *lookup_expr_in_table (rtx);
static int dump_hash_table_entry (void **, void *);
static void dump_hash_table (FILE *);
static bool reg_killed_on_edge (rtx, edge);
static bool reg_used_on_edge (rtx, edge);
static rtx reg_set_between_after_reload_p (rtx, rtx, rtx);
static rtx reg_used_between_after_reload_p (rtx, rtx, rtx);
static rtx get_avail_load_store_reg (rtx);
static bool bb_has_well_behaved_predecessors (basic_block);
static struct occr* get_bb_avail_insn (basic_block, struct occr *);
static void hash_scan_set (rtx);
static void compute_hash_table (void);
static void eliminate_partially_redundant_load (basic_block,
rtx,
struct expr *);
static void eliminate_partially_redundant_loads (void);
static void
alloc_mem (void)
{
int i;
basic_block bb;
rtx insn;
uid_cuid = XCNEWVEC (int, get_max_uid () + 1);
i = 1;
FOR_EACH_BB (bb)
FOR_BB_INSNS (bb, insn)
{
if (INSN_P (insn))
uid_cuid[INSN_UID (insn)] = i++;
else
uid_cuid[INSN_UID (insn)] = i;
}
expr_table = htab_create (MAX (i / 4, 13),
hash_expr_for_htab, expr_equiv_p, NULL);
gcc_obstack_init (&expr_obstack);
gcc_obstack_init (&occr_obstack);
gcc_obstack_init (&unoccr_obstack);
gcc_obstack_init (&modifies_mem_obstack);
reg_avail_info = (int *) xmalloc (FIRST_PSEUDO_REGISTER * sizeof (int));
modifies_mem_obstack_bottom =
(struct modifies_mem *) obstack_alloc (&modifies_mem_obstack,
sizeof (struct modifies_mem));
}
static void
free_mem (void)
{
free (uid_cuid);
htab_delete (expr_table);
obstack_free (&expr_obstack, NULL);
obstack_free (&occr_obstack, NULL);
obstack_free (&unoccr_obstack, NULL);
obstack_free (&modifies_mem_obstack, NULL);
free (reg_avail_info);
}
static hashval_t
hash_expr (rtx x, int *do_not_record_p)
{
*do_not_record_p = 0;
return hash_rtx (x, GET_MODE (x), do_not_record_p,
NULL, false);
}
static hashval_t
hash_expr_for_htab (const void *expp)
{
struct expr *exp = (struct expr *) expp;
return exp->hash;
}
static int
expr_equiv_p (const void *exp1p, const void *exp2p)
{
struct expr *exp1 = (struct expr *) exp1p;
struct expr *exp2 = (struct expr *) exp2p;
int equiv_p = exp_equiv_p (exp1->expr, exp2->expr, 0, true);
gcc_assert (!equiv_p || exp1->hash == exp2->hash);
return equiv_p;
}
static void
insert_expr_in_table (rtx x, rtx insn)
{
int do_not_record_p;
hashval_t hash;
struct expr *cur_expr, **slot;
struct occr *avail_occr, *last_occr = NULL;
hash = hash_expr (x, &do_not_record_p);
if (do_not_record_p)
return;
cur_expr = (struct expr *) obstack_alloc (&expr_obstack,
sizeof (struct expr));
cur_expr->expr = x;
cur_expr->hash = hash;
cur_expr->avail_occr = NULL;
slot = (struct expr **) htab_find_slot_with_hash (expr_table, cur_expr,
hash, INSERT);
if (! (*slot))
*slot = cur_expr;
else
{
obstack_free (&expr_obstack, cur_expr);
cur_expr = *slot;
}
avail_occr = cur_expr->avail_occr;
while (avail_occr && BLOCK_NUM (avail_occr->insn) != BLOCK_NUM (insn))
{
last_occr = avail_occr;
avail_occr = avail_occr->next;
}
if (avail_occr)
avail_occr->insn = insn;
else
{
avail_occr = (struct occr *) obstack_alloc (&occr_obstack,
sizeof (struct occr));
if (cur_expr->avail_occr == NULL)
cur_expr->avail_occr = avail_occr;
else
last_occr->next = avail_occr;
avail_occr->insn = insn;
avail_occr->next = NULL;
avail_occr->deleted_p = 0;
}
}
static struct expr *
lookup_expr_in_table (rtx pat)
{
int do_not_record_p;
struct expr **slot, *tmp_expr;
hashval_t hash = hash_expr (pat, &do_not_record_p);
if (do_not_record_p)
return NULL;
tmp_expr = (struct expr *) obstack_alloc (&expr_obstack,
sizeof (struct expr));
tmp_expr->expr = pat;
tmp_expr->hash = hash;
tmp_expr->avail_occr = NULL;
slot = (struct expr **) htab_find_slot_with_hash (expr_table, tmp_expr,
hash, INSERT);
obstack_free (&expr_obstack, tmp_expr);
if (!slot)
return NULL;
else
return (*slot);
}
static int
dump_hash_table_entry (void **slot, void *filep)
{
struct expr *expr = (struct expr *) *slot;
FILE *file = (FILE *) filep;
struct occr *occr;
fprintf (file, "expr: ");
print_rtl (file, expr->expr);
fprintf (file,"\nhashcode: %u\n", expr->hash);
fprintf (file,"list of occurrences:\n");
occr = expr->avail_occr;
while (occr)
{
rtx insn = occr->insn;
print_rtl_single (file, insn);
fprintf (file, "\n");
occr = occr->next;
}
fprintf (file, "\n");
return 1;
}
static void
dump_hash_table (FILE *file)
{
fprintf (file, "\n\nexpression hash table\n");
fprintf (file, "size %ld, %ld elements, %f collision/search ratio\n",
(long) htab_size (expr_table),
(long) htab_elements (expr_table),
htab_collisions (expr_table));
if (htab_elements (expr_table) > 0)
{
fprintf (file, "\n\ntable entries:\n");
htab_traverse (expr_table, dump_hash_table_entry, file);
}
fprintf (file, "\n");
}
static bool
oprs_unchanged_p (rtx x, rtx insn, bool after_insn)
{
int i, j;
enum rtx_code code;
const char *fmt;
if (x == 0)
return 1;
code = GET_CODE (x);
switch (code)
{
case REG:
gcc_assert (REGNO (x) < FIRST_PSEUDO_REGISTER);
if (after_insn)
return reg_avail_info[REGNO (x)] < INSN_CUID (insn);
else
return reg_avail_info[REGNO (x)] == 0;
case MEM:
if (load_killed_in_block_p (INSN_CUID (insn), x, after_insn))
return 0;
else
return oprs_unchanged_p (XEXP (x, 0), insn, after_insn);
case PC:
case CC0:
case CONST:
case CONST_INT:
case CONST_DOUBLE:
case CONST_VECTOR:
case SYMBOL_REF:
case LABEL_REF:
case ADDR_VEC:
case ADDR_DIFF_VEC:
return 1;
case PRE_DEC:
case PRE_INC:
case POST_DEC:
case POST_INC:
case PRE_MODIFY:
case POST_MODIFY:
if (after_insn)
return 0;
break;
default:
break;
}
for (i = GET_RTX_LENGTH (code) - 1, fmt = GET_RTX_FORMAT (code); i >= 0; i--)
{
if (fmt[i] == 'e')
{
if (! oprs_unchanged_p (XEXP (x, i), insn, after_insn))
return 0;
}
else if (fmt[i] == 'E')
for (j = 0; j < XVECLEN (x, i); j++)
if (! oprs_unchanged_p (XVECEXP (x, i, j), insn, after_insn))
return 0;
}
return 1;
}
static int mems_conflict_p;
static void
find_mem_conflicts (rtx dest, rtx setter ATTRIBUTE_UNUSED,
void *data)
{
rtx mem_op = (rtx) data;
while (GET_CODE (dest) == SUBREG
|| GET_CODE (dest) == ZERO_EXTRACT
|| GET_CODE (dest) == STRICT_LOW_PART)
dest = XEXP (dest, 0);
if (! MEM_P (dest))
return;
if (true_dependence (dest, GET_MODE (dest), mem_op,
rtx_addr_varies_p))
mems_conflict_p = 1;
}
static int
load_killed_in_block_p (int uid_limit, rtx x, bool after_insn)
{
struct modifies_mem *list_entry = modifies_mem_list;
while (list_entry)
{
rtx setter = list_entry->insn;
if ((after_insn
&& INSN_CUID (setter) < uid_limit)
|| (! after_insn
&& INSN_CUID (setter) > uid_limit))
{
list_entry = list_entry->next;
continue;
}
if (CALL_P (setter))
return 1;
mems_conflict_p = 0;
note_stores (PATTERN (setter), find_mem_conflicts, x);
if (mems_conflict_p)
return 1;
list_entry = list_entry->next;
}
return 0;
}
static inline void
record_last_reg_set_info (rtx insn, int regno)
{
reg_avail_info[regno] = INSN_CUID (insn);
}
static void
record_last_mem_set_info (rtx insn)
{
struct modifies_mem *list_entry;
list_entry = (struct modifies_mem *) obstack_alloc (&modifies_mem_obstack,
sizeof (struct modifies_mem));
list_entry->insn = insn;
list_entry->next = modifies_mem_list;
modifies_mem_list = list_entry;
}
static void
record_last_set_info (rtx dest, rtx setter ATTRIBUTE_UNUSED, void *data)
{
rtx last_set_insn = (rtx) data;
if (GET_CODE (dest) == SUBREG)
dest = SUBREG_REG (dest);
if (REG_P (dest))
record_last_reg_set_info (last_set_insn, REGNO (dest));
else if (MEM_P (dest))
{
if (! push_operand (dest, GET_MODE (dest)))
record_last_mem_set_info (last_set_insn);
else
record_last_reg_set_info (last_set_insn, STACK_POINTER_REGNUM);
}
}
static void
reset_opr_set_tables (void)
{
memset (reg_avail_info, 0, FIRST_PSEUDO_REGISTER * sizeof (int));
obstack_free (&modifies_mem_obstack, modifies_mem_obstack_bottom);
modifies_mem_list = NULL;
}
static void
record_opr_changes (rtx insn)
{
rtx note;
note_stores (PATTERN (insn), record_last_set_info, insn);
for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
if (REG_NOTE_KIND (note) == REG_INC)
record_last_reg_set_info (insn, REGNO (XEXP (note, 0)));
if (CALL_P (insn))
{
unsigned int regno;
for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
if (TEST_HARD_REG_BIT (regs_invalidated_by_call, regno))
record_last_reg_set_info (insn, regno);
if (! CONST_OR_PURE_CALL_P (insn))
record_last_mem_set_info (insn);
}
}
static void
hash_scan_set (rtx insn)
{
rtx pat = PATTERN (insn);
rtx src = SET_SRC (pat);
rtx dest = SET_DEST (pat);
if (! MEM_P (src) && ! MEM_P (dest))
return;
if (JUMP_P (insn) || set_noop_p (pat))
return;
if (REG_P (dest))
{
if (
can_copy_p (GET_MODE (dest))
&& general_operand (src, GET_MODE (src))
#ifdef STACK_REGS
&& (REGNO (dest) < FIRST_STACK_REG || REGNO (dest) > LAST_STACK_REG)
#endif
&& oprs_unchanged_p (src, insn, true))
{
insert_expr_in_table (src, insn);
}
}
else if (REG_P (src))
{
if (
can_copy_p (GET_MODE (src))
&& general_operand (dest, GET_MODE (dest))
#ifdef STACK_REGS
&& (REGNO (src) < FIRST_STACK_REG || REGNO (src) > LAST_STACK_REG)
#endif
&& ! (flag_float_store && FLOAT_MODE_P (GET_MODE (dest)))
&& ! load_killed_in_block_p (INSN_CUID (insn) + 1, dest, true)
&& oprs_unchanged_p (XEXP (dest, 0), insn, true))
{
insert_expr_in_table (dest, insn);
}
}
}
static void
compute_hash_table (void)
{
basic_block bb;
FOR_EACH_BB (bb)
{
rtx insn;
reset_opr_set_tables ();
FOR_BB_INSNS (bb, insn)
{
if (INSN_P (insn))
record_opr_changes (insn);
}
FOR_BB_INSNS (bb, insn)
if (INSN_P (insn) && GET_CODE (PATTERN (insn)) == SET)
hash_scan_set (insn);
}
}
static bool
reg_killed_on_edge (rtx reg, edge e)
{
rtx insn;
for (insn = e->insns.r; insn; insn = NEXT_INSN (insn))
if (INSN_P (insn) && reg_set_p (reg, insn))
return true;
return false;
}
static bool
reg_used_on_edge (rtx reg, edge e)
{
rtx insn;
for (insn = e->insns.r; insn; insn = NEXT_INSN (insn))
if (INSN_P (insn) && reg_overlap_mentioned_p (reg, PATTERN (insn)))
return true;
return false;
}
static rtx
reg_set_between_after_reload_p (rtx reg, rtx from_insn, rtx to_insn)
{
rtx insn;
gcc_assert (REG_P (reg) && REGNO (reg) < FIRST_PSEUDO_REGISTER);
if (from_insn == to_insn)
return NULL_RTX;
for (insn = NEXT_INSN (from_insn);
insn != to_insn;
insn = NEXT_INSN (insn))
if (INSN_P (insn))
{
if (set_of (reg, insn) != NULL_RTX)
return insn;
if ((CALL_P (insn)
&& call_used_regs[REGNO (reg)])
|| find_reg_fusage (insn, CLOBBER, reg))
return insn;
if (FIND_REG_INC_NOTE (insn, reg))
return insn;
}
return NULL_RTX;
}
static rtx
reg_used_between_after_reload_p (rtx reg, rtx from_insn, rtx to_insn)
{
rtx insn;
gcc_assert (REG_P (reg) && REGNO (reg) < FIRST_PSEUDO_REGISTER);
if (from_insn == to_insn)
return NULL_RTX;
for (insn = NEXT_INSN (from_insn);
insn != to_insn;
insn = NEXT_INSN (insn))
if (INSN_P (insn))
{
if (reg_overlap_mentioned_p (reg, PATTERN (insn))
|| (CALL_P (insn)
&& call_used_regs[REGNO (reg)])
|| find_reg_fusage (insn, USE, reg)
|| find_reg_fusage (insn, CLOBBER, reg))
return insn;
if (FIND_REG_INC_NOTE (insn, reg))
return insn;
}
return NULL_RTX;
}
static bool
reg_set_or_used_since_bb_start (rtx reg, basic_block bb, rtx up_to_insn)
{
rtx insn, start = PREV_INSN (BB_HEAD (bb));
if (reg_avail_info[REGNO (reg)] != 0)
return true;
insn = reg_used_between_after_reload_p (reg, start, up_to_insn);
if (! insn)
insn = reg_set_between_after_reload_p (reg, start, up_to_insn);
if (insn)
reg_avail_info[REGNO (reg)] = INSN_CUID (insn);
return insn != NULL_RTX;
}
static rtx
get_avail_load_store_reg (rtx insn)
{
if (REG_P (SET_DEST (PATTERN (insn))))
return SET_DEST(PATTERN(insn));
else
{
gcc_assert (REG_P (SET_SRC (PATTERN (insn))));
return SET_SRC (PATTERN (insn));
}
}
static bool
bb_has_well_behaved_predecessors (basic_block bb)
{
edge pred;
edge_iterator ei;
if (EDGE_COUNT (bb->preds) == 0)
return false;
FOR_EACH_EDGE (pred, ei, bb->preds)
{
if ((pred->flags & EDGE_ABNORMAL) && EDGE_CRITICAL_P (pred))
return false;
if (JUMP_TABLE_DATA_P (BB_END (pred->src)))
return false;
}
return true;
}
static struct occr*
get_bb_avail_insn (basic_block bb, struct occr *occr)
{
for (; occr != NULL; occr = occr->next)
if (BLOCK_FOR_INSN (occr->insn) == bb)
return occr;
return NULL;
}
static void
eliminate_partially_redundant_load (basic_block bb, rtx insn,
struct expr *expr)
{
edge pred;
rtx avail_insn = NULL_RTX;
rtx avail_reg;
rtx dest, pat;
struct occr *a_occr;
struct unoccr *occr, *avail_occrs = NULL;
struct unoccr *unoccr, *unavail_occrs = NULL, *rollback_unoccr = NULL;
int npred_ok = 0;
gcov_type ok_count = 0;
gcov_type critical_count = 0;
edge_iterator ei;
bool critical_edge_split = false;
gcov_type not_ok_count = 0;
basic_block pred_bb;
pat = PATTERN (insn);
dest = SET_DEST (pat);
if (reg_set_or_used_since_bb_start (dest, bb, insn))
return;
FOR_EACH_EDGE (pred, ei, bb->preds)
{
rtx next_pred_bb_end;
avail_insn = NULL_RTX;
avail_reg = NULL_RTX;
pred_bb = pred->src;
next_pred_bb_end = NEXT_INSN (BB_END (pred_bb));
for (a_occr = get_bb_avail_insn (pred_bb, expr->avail_occr); a_occr;
a_occr = get_bb_avail_insn (pred_bb, a_occr->next))
{
avail_insn = a_occr->insn;
avail_reg = get_avail_load_store_reg (avail_insn);
gcc_assert (avail_reg);
extract_insn (gen_move_insn (copy_rtx (dest),
copy_rtx (avail_reg)));
if (! constrain_operands (1)
|| reg_killed_on_edge (avail_reg, pred)
|| reg_used_on_edge (dest, pred))
{
avail_insn = NULL;
continue;
}
if (! reg_set_between_after_reload_p (avail_reg, avail_insn,
next_pred_bb_end))
break;
else
avail_insn = NULL;
}
if (EDGE_CRITICAL_P (pred))
critical_count += pred->count;
if (avail_insn != NULL_RTX)
{
npred_ok++;
ok_count += pred->count;
if (! set_noop_p (PATTERN (gen_move_insn (copy_rtx (dest),
copy_rtx (avail_reg)))))
{
if (EDGE_CRITICAL_P (pred))
critical_edge_split = true;
}
else
continue;
occr = (struct unoccr *) obstack_alloc (&unoccr_obstack,
sizeof (struct unoccr));
occr->insn = avail_insn;
occr->pred = pred;
occr->next = avail_occrs;
avail_occrs = occr;
if (! rollback_unoccr)
rollback_unoccr = occr;
}
else
{
if (EDGE_CRITICAL_P (pred))
critical_edge_split = true;
not_ok_count += pred->count;
unoccr = (struct unoccr *) obstack_alloc (&unoccr_obstack,
sizeof (struct unoccr));
unoccr->insn = NULL_RTX;
unoccr->pred = pred;
unoccr->next = unavail_occrs;
unavail_occrs = unoccr;
if (! rollback_unoccr)
rollback_unoccr = unoccr;
}
}
#if defined(TARGET_MACHO) && defined(CONFIG_DARWIN_H)
if (flag_darwin_rtl_pre_ignore_critical_edges)
critical_edge_split = false;
#endif
if (
npred_ok == 0
|| (optimize_size && npred_ok > 1)
|| ((! profile_info || ! flag_branch_probabilities
|| targetm.cannot_modify_jumps_p ())
&& critical_edge_split))
goto cleanup;
if (ok_count < GCSE_AFTER_RELOAD_PARTIAL_FRACTION * not_ok_count)
goto cleanup;
if (ok_count < GCSE_AFTER_RELOAD_CRITICAL_FRACTION * critical_count)
goto cleanup;
for (occr = avail_occrs; occr; occr = occr->next)
{
avail_insn = occr->insn;
pred = occr->pred;
avail_reg = get_avail_load_store_reg (avail_insn);
gcc_assert (avail_reg);
insert_insn_on_edge (gen_move_insn (copy_rtx (dest),
copy_rtx (avail_reg)),
pred);
stats.moves_inserted++;
if (dump_file)
fprintf (dump_file,
"generating move from %d to %d on edge from %d to %d\n",
REGNO (avail_reg),
REGNO (dest),
pred->src->index,
pred->dest->index);
}
for (unoccr = unavail_occrs; unoccr; unoccr = unoccr->next)
{
pred = unoccr->pred;
insert_insn_on_edge (copy_insn (PATTERN (insn)), pred);
stats.copies_inserted++;
if (dump_file)
{
fprintf (dump_file,
"generating on edge from %d to %d a copy of load: ",
pred->src->index,
pred->dest->index);
print_rtl (dump_file, PATTERN (insn));
fprintf (dump_file, "\n");
}
}
for (a_occr = get_bb_avail_insn (bb, expr->avail_occr);
a_occr && (a_occr->insn != insn);
a_occr = get_bb_avail_insn (bb, a_occr->next));
if (!a_occr)
{
stats.insns_deleted++;
if (dump_file)
{
fprintf (dump_file, "deleting insn:\n");
print_rtl_single (dump_file, insn);
fprintf (dump_file, "\n");
}
delete_insn (insn);
}
else
a_occr->deleted_p = 1;
cleanup:
if (rollback_unoccr)
obstack_free (&unoccr_obstack, rollback_unoccr);
}
static void
eliminate_partially_redundant_loads (void)
{
rtx insn;
basic_block bb;
if (ENTRY_BLOCK_PTR->next_bb == EXIT_BLOCK_PTR)
return;
FOR_BB_BETWEEN (bb,
ENTRY_BLOCK_PTR->next_bb->next_bb,
EXIT_BLOCK_PTR,
next_bb)
{
if (! bb_has_well_behaved_predecessors (bb))
continue;
if (probably_cold_bb_p (bb))
continue;
reset_opr_set_tables ();
FOR_BB_INSNS (bb, insn)
{
if (NONJUMP_INSN_P (insn)
&& GET_CODE (PATTERN (insn)) == SET
&& REG_P (SET_DEST (PATTERN (insn)))
&& MEM_P (SET_SRC (PATTERN (insn))))
{
rtx pat = PATTERN (insn);
rtx src = SET_SRC (pat);
struct expr *expr;
if (!MEM_VOLATILE_P (src)
&& GET_MODE (src) != BLKmode
&& general_operand (src, GET_MODE (src))
&& oprs_unchanged_p (src, insn, false)
&& !(flag_non_call_exceptions && may_trap_p (src))
&& !side_effects_p (src)
&& (expr = lookup_expr_in_table (src)) != NULL)
{
eliminate_partially_redundant_load (bb, insn, expr);
}
}
if (INSN_P (insn))
record_opr_changes (insn);
}
}
commit_edge_insertions ();
}
static int
delete_redundant_insns_1 (void **slot, void *data ATTRIBUTE_UNUSED)
{
struct expr *expr = (struct expr *) *slot;
struct occr *occr;
for (occr = expr->avail_occr; occr != NULL; occr = occr->next)
{
if (occr->deleted_p)
{
delete_insn (occr->insn);
stats.insns_deleted++;
if (dump_file)
{
fprintf (dump_file, "deleting insn:\n");
print_rtl_single (dump_file, occr->insn);
fprintf (dump_file, "\n");
}
}
}
return 1;
}
static void
delete_redundant_insns (void)
{
htab_traverse (expr_table, delete_redundant_insns_1, NULL);
if (dump_file)
fprintf (dump_file, "\n");
}
static void
gcse_after_reload_main (rtx f ATTRIBUTE_UNUSED)
{
memset (&stats, 0, sizeof (stats));
alloc_mem ();
init_alias_analysis ();
compute_hash_table ();
if (dump_file)
dump_hash_table (dump_file);
if (htab_elements (expr_table) > 0)
{
eliminate_partially_redundant_loads ();
delete_redundant_insns ();
if (dump_file)
{
fprintf (dump_file, "GCSE AFTER RELOAD stats:\n");
fprintf (dump_file, "copies inserted: %d\n", stats.copies_inserted);
fprintf (dump_file, "moves inserted: %d\n", stats.moves_inserted);
fprintf (dump_file, "insns deleted: %d\n", stats.insns_deleted);
fprintf (dump_file, "\n\n");
}
}
end_alias_analysis ();
free_mem ();
}
static bool
gate_handle_gcse2 (void)
{
return (optimize > 0 && flag_gcse_after_reload);
}
static unsigned int
rest_of_handle_gcse2 (void)
{
gcse_after_reload_main (get_insns ());
rebuild_jump_labels (get_insns ());
delete_trivially_dead_insns (get_insns (), max_reg_num ());
return 0;
}
struct tree_opt_pass pass_gcse2 =
{
"gcse2",
gate_handle_gcse2,
rest_of_handle_gcse2,
NULL,
NULL,
0,
TV_GCSE_AFTER_RELOAD,
0,
0,
0,
0,
TODO_dump_func |
TODO_verify_flow | TODO_ggc_collect,
'J'
};