* rtl.h (MEM_READONLY_P): Replace RTX_UNCHANGING_P. * alias.c (true_dependence): Update to match new semantics. (canon_true_dependence, write_dependence_p): Likewise. (anti_dependence, output_dependence): Update write_dependence_p args. (unchanging_anti_dependence): Remove. * calls.c (purge_mem_unchanging_flag): Remove. (fixup_tail_calls): Don't call it. (expand_call): Don't add unchanging memory to function usage. * expr.c (emit_block_move_via_libcall): Likewise. (clear_storage_via_libcall): Don't clobber RTX_UNCHANGING_P mems. (get_subtarget): Don't use RTX_UNCHANGING_P. (expand_assignment, store_constructor, expand_expr_real_1): Likewise. (do_tablejump): Set MEM_READONLY_P, not RTX_UNCHANGING_P. * combine.c (get_last_value_validate): Use MEM_READONLY_P. * cse.c (insert): Don't use RTX_UNCHANGING_P. (cse_insn, canon_hash): Use MEM_READONLY_P. * emit-rtl.c (set_mem_attributes_minus_bitpos): Use MEM_READONLY_P instead of RTX_UNCHANGING_P. * explow.c (maybe_set_unchanging): Remove. * expr.h (maybe_set_unchanging): Remove. * flow.c (insn_dead_p, mark_used_regs): Use anti_dependence. * function.c (assign_stack_temp_for_type): Don't use RTX_UNCHANGING_P. (assign_parm_setup_reg, expand_function_start): Likewise. * integrate.c (copy_rtx_and_substitute): Likewise. * ra-rewrite.c (emit_colors): Likewise. * regmove.c (copy_src_to_dest, regmove_optimize): Likewise. (fixup_match_1): Likewise. * reload1.c (reload, alter_reg): Likewise. * local-alloc.c (validate_equiv_mem): Check MEM_READONLY_P, not RTX_UNCHANGING_P. (equiv_init_varies_p): Likewise. * loop-invariant.c (check_maybe_invariant): Likewise. * resource.c (mark_referenced_resources, mark_set_resources): Likewise. * loop.c (note_addr_stored): Likewise. (prescan_loop): Likewise. Don't check function usage for clobbered unchanging memory. * rtlanal.c (rtx_unstable_p): Check MEM_READONLY_P, not RTX_UNCHANGING_P. (rtx_varies_p, modified_between_p, modified_in_p): Likewise. * varasm.c (force_const_mem): Likewise. * stmt.c (expand_decl): Don't set RTX_UNCHANGING_P. * web.c (entry_register): Likewise. * tree-gimple.h (get_base_address): Move decl ... * tree.h: ... here. * doc/rtl.texi (MEM_READONLY_P): Replace RTX_UNCHANGING_P. * config/alpha/alpha.c (alpha_set_memflags_1): Rewrite to be called via for_each_rtx. Copy MEM_SCALAR_P, MEM_NOTRAP_P too. (alpha_set_memflags): Update to match. * config/darwin.c (machopic_indirect_data_reference): Set MEM_READONLY_P instead of RTX_UNCHANGING_P. (machopic_indirect_call_target): Likewise. (machopic_legitimize_pic_address): Likewise. * config/arm/arm.c (legitimize_pic_address, arm_gen_load_multiple, arm_gen_store_multiple, arm_gen_movmemqi): Likewise. * config/arm/arm.md (load_multiple, store_multiple): Likewise. * config/frv/frv.md (symGOT2reg): Likewise. * config/i386/i386.c (legitimize_pic_address, legitimize_tls_address, ix86_split_to_parts): Likewise. * config/ia64/ia64.c (ia64_expand_tls_address): Likewise. * config/ia64/ia64.md (load_fptr): Likewise. * config/m32r/m32r.c (m32r_legitimize_pic_address): Likewise. * config/m68k/m68k.c (legitimize_pic_address): Likewise. * config/mcore/mcore.c (block_move_sequence): Likewise. * config/mn10300/mn10300.md (symGOT2reg): Likewise. * config/pa/pa.c (legitimize_pic_address): Likewise. * config/rs6000/rs6000.c (rs6000_legitimize_tls_address): Likewise. (rs6000_emit_move): Likewise. * config/s390/s390.c (legitimize_pic_address): Likewise. (legitimize_tls_address): Likewise. * config/s390/s390.md (casesi): Likewise. * config/sh/sh.c (prepare_move_operands, sh_reorg): Likewise. * config/sh/sh.md (symGOT2reg): Likewise. * config/sparc/sparc.c (legitimize_pic_address): Likewise. * config/v850/v850.md (casesi): Likewise. * config/ia64/ia64.c (gen_thread_pointer): Don't set RTX_UNCHANGING_P. * config/iq2000/iq2000.c (save_restore_insns): Likewise. * config/mips/mips.c (mips_restore_gp): Likewise. (mips_save_restore_reg, mips16_gp_pseudo_reg): Likewise. * config/sh/sh.c (sh_reorg): Likewise. From-SVN: r86178
274 lines
8.1 KiB
C
274 lines
8.1 KiB
C
/* Web construction code for GNU compiler.
|
|
Contributed by Jan Hubicka.
|
|
Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc.
|
|
|
|
This file is part of GCC.
|
|
|
|
GCC is free software; you can redistribute it and/or modify it under
|
|
the terms of the GNU General Public License as published by the Free
|
|
Software Foundation; either version 2, or (at your option) any later
|
|
version.
|
|
|
|
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with GCC; see the file COPYING. If not, write to the Free
|
|
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
02111-1307, USA. */
|
|
|
|
/* Simple optimization pass that splits independent uses of each pseudo,
|
|
increasing effectiveness of other optimizations. The optimization can
|
|
serve as an example of use for the dataflow module.
|
|
|
|
We don't split registers with REG_USERVAR set unless -fmessy-debugging
|
|
is specified, because debugging information about such split variables
|
|
is almost unusable.
|
|
|
|
TODO
|
|
- Add code to keep debugging up-to-date after splitting user variable
|
|
pseudos. This can be done by keeping track of all the pseudos used
|
|
for the variable and using life analysis information before reload
|
|
to determine which one is live and, in case more than one are live,
|
|
choose the one with the latest definition.
|
|
|
|
Other optimization passes can benefit from the infrastructure too.
|
|
|
|
- We may use profile information and ignore infrequent use for the
|
|
purpose of web unifying, inserting the compensation code later to
|
|
implement full induction variable expansion for loops (currently
|
|
we expand only if the induction variable is dead afterward, which
|
|
is often the case). */
|
|
|
|
#include "config.h"
|
|
#include "system.h"
|
|
#include "coretypes.h"
|
|
#include "tm.h"
|
|
#include "toplev.h"
|
|
|
|
#include "rtl.h"
|
|
#include "hard-reg-set.h"
|
|
#include "flags.h"
|
|
#include "basic-block.h"
|
|
#include "output.h"
|
|
#include "df.h"
|
|
#include "function.h"
|
|
|
|
|
|
/* This entry is allocated for each reference in the insn stream. */
|
|
struct web_entry
|
|
{
|
|
/* Pointer to the parent in the union/find tree. */
|
|
struct web_entry *pred;
|
|
/* Newly assigned register to the entry. Set only for roots. */
|
|
rtx reg;
|
|
};
|
|
|
|
static struct web_entry *unionfind_root (struct web_entry *);
|
|
static void unionfind_union (struct web_entry *, struct web_entry *);
|
|
static void union_defs (struct df *, struct ref *, struct web_entry *,
|
|
struct web_entry *);
|
|
static rtx entry_register (struct web_entry *, struct ref *, char *);
|
|
static void replace_ref (struct ref *, rtx);
|
|
|
|
/* Find the root of unionfind tree (the representative of set). */
|
|
|
|
static struct web_entry *
|
|
unionfind_root (struct web_entry *element)
|
|
{
|
|
struct web_entry *element1 = element, *element2;
|
|
|
|
while (element->pred)
|
|
element = element->pred;
|
|
while (element1->pred)
|
|
{
|
|
element2 = element1->pred;
|
|
element1->pred = element;
|
|
element1 = element2;
|
|
}
|
|
return element;
|
|
}
|
|
|
|
/* Union sets. */
|
|
|
|
static void
|
|
unionfind_union (struct web_entry *first, struct web_entry *second)
|
|
{
|
|
first = unionfind_root (first);
|
|
second = unionfind_root (second);
|
|
if (first == second)
|
|
return;
|
|
second->pred = first;
|
|
}
|
|
|
|
/* For each use, all possible defs reaching it must come in the same
|
|
register, union them. */
|
|
|
|
static void
|
|
union_defs (struct df *df, struct ref *use, struct web_entry *def_entry,
|
|
struct web_entry *use_entry)
|
|
{
|
|
rtx insn = DF_REF_INSN (use);
|
|
struct df_link *link = DF_REF_CHAIN (use);
|
|
struct df_link *use_link = DF_INSN_USES (df, insn);
|
|
struct df_link *def_link = DF_INSN_DEFS (df, insn);
|
|
rtx set = single_set (insn);
|
|
|
|
/* Some instructions may use match_dup for their operands. In case the
|
|
operands are dead, we will assign them different pseudos, creating
|
|
invalid instructions, so union all uses of the same operand for each
|
|
insn. */
|
|
|
|
while (use_link)
|
|
{
|
|
if (use != use_link->ref
|
|
&& DF_REF_REAL_REG (use) == DF_REF_REAL_REG (use_link->ref))
|
|
unionfind_union (use_entry + DF_REF_ID (use),
|
|
use_entry + DF_REF_ID (use_link->ref));
|
|
use_link = use_link->next;
|
|
}
|
|
|
|
/* Recognize trivial noop moves and attempt to keep them as noop.
|
|
While most of noop moves should be removed, we still keep some
|
|
of them at libcall boundaries and such. */
|
|
|
|
if (set
|
|
&& SET_SRC (set) == DF_REF_REG (use)
|
|
&& SET_SRC (set) == SET_DEST (set))
|
|
{
|
|
while (def_link)
|
|
{
|
|
if (DF_REF_REAL_REG (use) == DF_REF_REAL_REG (def_link->ref))
|
|
unionfind_union (use_entry + DF_REF_ID (use),
|
|
def_entry + DF_REF_ID (def_link->ref));
|
|
def_link = def_link->next;
|
|
}
|
|
}
|
|
while (link)
|
|
{
|
|
unionfind_union (use_entry + DF_REF_ID (use),
|
|
def_entry + DF_REF_ID (link->ref));
|
|
link = link->next;
|
|
}
|
|
|
|
/* A READ_WRITE use requires the corresponding def to be in the same
|
|
register. Find it and union. */
|
|
if (use->flags & DF_REF_READ_WRITE)
|
|
{
|
|
struct df_link *link = DF_INSN_DEFS (df, DF_REF_INSN (use));
|
|
|
|
while (link)
|
|
{
|
|
if (DF_REF_REAL_REG (link->ref) == DF_REF_REAL_REG (use))
|
|
unionfind_union (use_entry + DF_REF_ID (use),
|
|
def_entry + DF_REF_ID (link->ref));
|
|
link = link->next;
|
|
}
|
|
}
|
|
}
|
|
|
|
/* Find the corresponding register for the given entry. */
|
|
|
|
static rtx
|
|
entry_register (struct web_entry *entry, struct ref *ref, char *used)
|
|
{
|
|
struct web_entry *root;
|
|
rtx reg, newreg;
|
|
|
|
/* Find the corresponding web and see if it has been visited. */
|
|
root = unionfind_root (entry);
|
|
if (root->reg)
|
|
return root->reg;
|
|
|
|
/* We are seeing this web for the first time, do the assignment. */
|
|
reg = DF_REF_REAL_REG (ref);
|
|
|
|
/* In case the original register is already assigned, generate new one. */
|
|
if (!used[REGNO (reg)])
|
|
newreg = reg, used[REGNO (reg)] = 1;
|
|
else if (REG_USERVAR_P (reg) && 0/*&& !flag_messy_debugging*/)
|
|
{
|
|
newreg = reg;
|
|
if (dump_file)
|
|
fprintf (dump_file,
|
|
"New web forced to keep reg=%i (user variable)\n",
|
|
REGNO (reg));
|
|
}
|
|
else
|
|
{
|
|
newreg = gen_reg_rtx (GET_MODE (reg));
|
|
REG_USERVAR_P (newreg) = REG_USERVAR_P (reg);
|
|
REG_POINTER (newreg) = REG_POINTER (reg);
|
|
REG_LOOP_TEST_P (newreg) = REG_LOOP_TEST_P (reg);
|
|
REG_ATTRS (newreg) = REG_ATTRS (reg);
|
|
if (dump_file)
|
|
fprintf (dump_file, "Web oldreg=%i newreg=%i\n", REGNO (reg),
|
|
REGNO (newreg));
|
|
}
|
|
|
|
root->reg = newreg;
|
|
return newreg;
|
|
}
|
|
|
|
/* Replace the reference by REG. */
|
|
|
|
static void
|
|
replace_ref (struct ref *ref, rtx reg)
|
|
{
|
|
rtx oldreg = DF_REF_REAL_REG (ref);
|
|
rtx *loc = DF_REF_REAL_LOC (ref);
|
|
|
|
if (oldreg == reg)
|
|
return;
|
|
if (dump_file)
|
|
fprintf (dump_file, "Updating insn %i (%i->%i)\n",
|
|
INSN_UID (DF_REF_INSN (ref)), REGNO (oldreg), REGNO (reg));
|
|
*loc = reg;
|
|
}
|
|
|
|
/* Main entry point. */
|
|
|
|
void
|
|
web_main (void)
|
|
{
|
|
struct df *df;
|
|
struct web_entry *def_entry;
|
|
struct web_entry *use_entry;
|
|
unsigned int i;
|
|
int max = max_reg_num ();
|
|
char *used;
|
|
|
|
df = df_init ();
|
|
df_analyze (df, 0, DF_UD_CHAIN | DF_EQUIV_NOTES);
|
|
|
|
def_entry = xcalloc (df->n_defs, sizeof (struct web_entry));
|
|
use_entry = xcalloc (df->n_uses, sizeof (struct web_entry));
|
|
used = xcalloc (max, sizeof (char));
|
|
|
|
if (dump_file)
|
|
df_dump (df, DF_UD_CHAIN | DF_DU_CHAIN, dump_file);
|
|
|
|
/* Produce the web. */
|
|
for (i = 0; i < df->n_uses; i++)
|
|
union_defs (df, df->uses[i], def_entry, use_entry);
|
|
|
|
/* Update the instruction stream, allocating new registers for split pseudos
|
|
in progress. */
|
|
for (i = 0; i < df->n_uses; i++)
|
|
replace_ref (df->uses[i], entry_register (use_entry + i, df->uses[i],
|
|
used));
|
|
for (i = 0; i < df->n_defs; i++)
|
|
replace_ref (df->defs[i], entry_register (def_entry + i, df->defs[i],
|
|
used));
|
|
|
|
/* Dataflow information is corrupt here, but it can be easily updated
|
|
by creating new entries for new registers and updates or calling
|
|
df_insns_modify. */
|
|
free (def_entry);
|
|
free (use_entry);
|
|
free (used);
|
|
df_finish (df);
|
|
}
|