2005-01-11 Danny Berlin <dberlin@dberlin.org> Kenneth Zadeck <zadeck@naturalbridge.com> * df.h (DF_SCAN, DF_RU, DF_RD, DF_LR, DF_UR, DF_UREC, DF_CHAIN, DF_RI, DF_LAST_PROBLEM_PLUS1, DF_DU_CHAIN, DF_UD_CHAIN, DF_REF_TYPE_NAMES, DF_HARD_REGS, DF_EQUIV_NOTES, DF_SUBREGS, DF_SCAN_BB_INFO, DF_RU_BB_INFO, DF_RD_BB_INFO, DF_LR_BB_INFO, DF_UR_BB_INFO, DF_UREC_BB_INFO, DF_LIVE_IN, DF_LIVE_OUT, DF_RA_LIVE_IN, DF_RA_LIVE_OUT, DF_UPWARD_LIVE_IN, DF_UPWARD_LIVE_OUT, DF_REF_REAL_REG, DF_REF_REGNO, DF_REF_REAL_LOC, DF_REF_REG, DF_REF_LOC, DF_REF_BB, DF_REF_BBNO, DF_REF_INSN, DF_REF_INSN_UID, DF_REF_TYPE, DF_REF_CHAIN, DF_REF_ID, DF_REF_FLAGS, DF_REF_NEXT_REG, DF_REF_PREV_REG, DF_REF_NEXT_REF, DF_REF_DATA, DF_REF_REG_DEF_P, DF_REF_REG_USE_P, DF_REF_REG_MEM_STORE_P, DF_REF_REG_MEM_LOAD_P, DF_REF_REG_MEM_P, DF_DEFS_SIZE, DF_DEFS_GET, DF_DEFS_SET, DF_USES_SIZE, DF_USES_GET, DF_USES_SET, DF_REG_SIZE, DF_REG_DEF_GET, DF_REG_DEF_SET, DF_REG_USE_GET, DF_REG_USE_SET, DF_REGNO_FIRST_DEF, DF_REGNO_LAST_USE, DF_INSN_SIZE, DF_INSN_GET, DF_INSN_SET, DF_INSN_CONTAINS_ASM, DF_INSN_LUID, DF_INSN_DEFS, DF_INSN_USES, DF_INSN_UID_GET, DF_INSN_UID_LUID, DF_INSN_UID_DEFS, DF_INSN_UID_USES, DF_SCAN_INITIAL, DF_SCAN_GLOBAL, DF_SCAN_POST_ALLOC): New macros. (df_flow_dir, df_ref_type, df_ref_flags, df_alloc_function, df_free_bb_function, df_local_compute_function, df_init_function, df_dataflow_function, df_confluence_function_0, df_confluence_function_n, df_transfer_function, df_finalizer_function, df_free_function, df_dump_problem_function, df_problem, dataflow, df_insn_info, df_reg_info, df_ref, df_link, df_ref_info, df, df_map, df_scan_bb_info, df_ru_bb_info, df_ru_bb_info, df_rd_bb_info, df_lr_bb_info, df_ur_bb_info, df_urec_bb_info, ) New types. (df_invalidated_by_call, df_all_hard_regs, df_state) New public variables. (df_init, df_add_problem, df_set_blocks, df_finish, df_analyze, df_analyze_simple_change_some_blocks, df_analyze_simple_change_one_block, df_compact_blocks, df_bb_replace, df_bb_regno_last_use_find, df_bb_regno_first_def_find, df_bb_regno_last_def_find, df_insn_regno_def_p, df_find_def, df_find_use, df_iterative_dataflow, df_dump, df_chain_dump, df_refs_chain_dump, df_regs_chain_dump, df_insn_debug, df_insn_debug_regno, df_regno_debug, df_ref_debug, debug_df_insn, debug_df_regno, debug_df_reg, debug_df_defno, debug_df_useno, debug_df_ref, debug_df_chain, df_get_dependent_problem, df_chain_create, df_chain_unlink, df_chain_copy, df_get_live_in, df_get_live_out, df_grow_bb_info, df_chain_dump, df_print_bb_index, df_ru_add_problem, df_ru_get_bb_info, df_rd_add_problem, df_rd_get_bb_info, df_lr_add_problem, df_lr_get_bb_info, df_ur_add_problem, df_ur_get_bb_info, df_urec_add_problem, df_urec_get_bb_info, df_chain_add_problem, df_ri_add_problem, df_reg_lifetime, df_scan_get_bb_info, df_scan_add_problem, df_rescan_blocks, df_ref_create, df_get_artificial_defs, df_get_artificial_uses, df_reg_chain_create, df_reg_chain_unlink, df_ref_remove, df_insn_refs_delete, df_refs_delete, df_reorganize_refs, df_set_state, df_hard_reg_init, df_read_modify_subreg_p) New public functions. * df-core.c: The core dataflow solver and glue routines for rtl dataflow. (df_init, df_add_problem, df_set_blocks, df_finish, df_hybrid_search_forward, df_hybrid_search_backward, df_iterative_dataflow, df_prune_to_subcfg, df_analyze_problem, df_analyze, df_get_bb_info, df_set_bb_info, df_bb_replace, df_bb_regno_last_use_find, df_bb_regno_first_def_find, df_bb_regno_last_def_find, df_insn_regno_def_p, df_find_def, df_reg_defined, df_find_use, df_reg_used, df_dump, df_refs_chain_dump, df_regs_chain_dump, df_insn_debug, df_insn_debug_regno, df_regno_debug, df_ref_debug, debug_df_insn, debug_df_reg, debug_df_regno, debug_df_ref debug_df_defno, debug_df_useno, reset_df_after_reload): New functions. * df-scan.c: The scanning fuctions, once in df.c, completely rewritten so that they now fully model the functionality of register usage at the backend. (df_scan_free_internal, df_scan_get_bb_info, df_scan_set_bb_info, df_scan_free_bb_info, df_scan_alloc, df_scan_free, df_scan_dump, df_scan_add_problem, df_grow_reg_info, df_grow_ref_info, df_grow_insn_info, df_rescan_blocks, df_ref_create, df_get_artificial_defs, df_get_artificial_uses, df_reg_chain_create, df_ref_unlink, df_reg_chain_unlink, df_ref_remove, df_insn_create_insn_record, df_insn_refs_delete, df_refs_delete, df_reorganize_refs, df_set_state, df_ref_create_structure, df_ref_record, df_read_modify_subreg_p, df_def_record_1, df_defs_record, df_uses_record, df_insn_contains_asm_1, df_insn_contains_asm, df_insn_refs_record, df_has_eh_preds, df_bb_refs_record, df_refs_record, df_mark_reg, df_record_exit_block_uses, df_hard_reg_init): New functions. * df-problems.c: Seven concrete dataflow problems that use the scanning in df-scan.c and are solved by the engine in df-core.c. (df_get_dependent_problem, df_chain_create, df_chain_unlink, df_chain_copy, df_get_live_in, df_get_live_out, df_grow_bb_info, df_chain_dump, df_print_bb_index, df_ref_bitmap, df_set_seen, df_unset_seen, df_ru_get_bb_info, df_ru_set_bb_info, df_ru_free_bb_info, df_ru_alloc, df_ru_bb_local_compute_process_def, df_ru_bb_local_compute_process_use, df_ru_bb_local_compute, df_ru_local_compute, df_ru_init_solution, df_ru_confluence_n, df_ru_transfer_function, df_ru_free, df_ru_dump, df_ru_add_problem, df_rd_get_bb_info, df_rd_set_bb_info, df_rd_free_bb_info, df_rd_alloc, df_rd_bb_local_compute_process_def, df_rd_bb_local_compute, df_rd_local_compute, df_rd_init_solution, df_rd_confluence_n, df_rd_transfer_function, df_rd_free, df_rd_dump, df_rd_add_problem, df_lr_get_bb_info, df_lr_set_bb_info, df_lr_free_bb_info, df_lr_alloc, df_lr_bb_local_compute, df_lr_local_compute, df_lr_init, df_lr_confluence_0, df_lr_confluence_n, df_lr_transfer_function, df_lr_free, df_lr_dump, df_lr_add_problem, df_ur_get_bb_info, df_ur_set_bb_info, df_ur_free_bb_info, df_ur_alloc, df_ur_bb_local_compute, df_ur_local_compute, df_ur_init, df_ur_local_finalize, df_ur_confluence_n, df_ur_transfer_function, df_ur_free, df_ur_dump, df_ur_add_problem, df_urec_get_bb_info, df_urec_set_bb_info, df_urec_free_bb_info, df_urec_alloc, df_urec_mark_reg_change, df_urec_check_earlyclobber, df_urec_mark_reg_use_for_earlyclobber, df_urec_mark_reg_use_for_earlyclobber_1, df_urec_bb_local_compute, df_urec_local_compute, df_urec_init, df_urec_local_finalize, df_urec_confluence_n, df_urec_transfer_function, df_urec_free, df_urec_dump, df_urec_add_problem, df_chain_alloc, df_chain_create_bb_process_use, df_chain_create_bb, df_chain_finalize, df_chain_free, df_chains_dump, df_chain_add_problem, df_ri_alloc, df_ri_bb_compute, df_ri_compute, df_ri_free, df_ri_dump, df_ri_add_problem, df_reg_lifetime): New functions. * df.c: Deleted file. * ddg.c (create_ddg_dep_no_link, build_inter_loop_deps): Made code consistent with new df api. * modulo-sched.c (sms_schedule, rest_of_handle_sms, rest_of_handle_sms): Ditto. * web.c (unionfind_union, union_defs, entry_register, web_main): Ditto. * loop_invariant.c (invariant_for_use, hash_invariant_expr_1, invariant_expr_equal_p, find_defs, check_dependencies, find_invariant_insn, find_invariants_to_move, move_invariant_reg, free_inv_motion_data, move_loop_invariants): Ditto. * sched-deps.c (sched_analyze_1): Ditto. Co-Authored-By: Kenneth Zadeck <zadeck@naturalbridge.com> From-SVN: r109577
314 lines
9.3 KiB
C
314 lines
9.3 KiB
C
/* Web construction code for GNU compiler.
|
||
Contributed by Jan Hubicka.
|
||
Copyright (C) 2001, 2002, 2004, 2006
|
||
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, 51 Franklin Street, Fifth Floor, Boston, MA
|
||
02110-1301, 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 "obstack.h"
|
||
#include "basic-block.h"
|
||
#include "output.h"
|
||
#include "df.h"
|
||
#include "function.h"
|
||
#include "timevar.h"
|
||
#include "tree-pass.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 df_ref *, struct web_entry *,
|
||
struct web_entry *);
|
||
static rtx entry_register (struct web_entry *, struct df_ref *, char *);
|
||
static void replace_ref (struct df_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 df_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_ref *use_link = DF_INSN_USES (df, insn);
|
||
struct df_ref *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
|
||
&& DF_REF_REAL_REG (use) == DF_REF_REAL_REG (use_link))
|
||
unionfind_union (use_entry + DF_REF_ID (use),
|
||
use_entry + DF_REF_ID (use_link));
|
||
use_link = use_link->next_ref;
|
||
}
|
||
|
||
/* 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))
|
||
unionfind_union (use_entry + DF_REF_ID (use),
|
||
def_entry + DF_REF_ID (def_link));
|
||
def_link = def_link->next_ref;
|
||
}
|
||
}
|
||
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_ref *link = DF_INSN_DEFS (df, DF_REF_INSN (use));
|
||
|
||
while (link)
|
||
{
|
||
if (DF_REF_REAL_REG (link) == DF_REF_REAL_REG (use))
|
||
unionfind_union (use_entry + DF_REF_ID (use),
|
||
def_entry + DF_REF_ID (link));
|
||
link = link->next_ref;
|
||
}
|
||
}
|
||
}
|
||
|
||
/* Find the corresponding register for the given entry. */
|
||
|
||
static rtx
|
||
entry_register (struct web_entry *entry, struct df_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_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 df_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. */
|
||
|
||
static 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_EQUIV_NOTES);
|
||
df_chain_add_problem (df, DF_UD_CHAIN);
|
||
df_analyze (df);
|
||
df_reorganize_refs (&df->def_info);
|
||
df_reorganize_refs (&df->use_info);
|
||
|
||
def_entry = xcalloc (DF_DEFS_SIZE (df), sizeof (struct web_entry));
|
||
use_entry = xcalloc (DF_USES_SIZE (df), sizeof (struct web_entry));
|
||
used = xcalloc (max, sizeof (char));
|
||
|
||
if (dump_file)
|
||
df_dump (df, dump_file);
|
||
|
||
/* Produce the web. */
|
||
for (i = 0; i < DF_USES_SIZE (df); i++)
|
||
union_defs (df, DF_USES_GET (df, i), def_entry, use_entry);
|
||
|
||
/* Update the instruction stream, allocating new registers for split pseudos
|
||
in progress. */
|
||
for (i = 0; i < DF_USES_SIZE (df); i++)
|
||
replace_ref (DF_USES_GET (df, i),
|
||
entry_register (use_entry + i, DF_USES_GET (df, i), used));
|
||
for (i = 0; i < DF_DEFS_SIZE (df); i++)
|
||
replace_ref (DF_DEFS_GET (df, i),
|
||
entry_register (def_entry + i, DF_DEFS_GET (df, 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);
|
||
df = NULL;
|
||
}
|
||
|
||
static bool
|
||
gate_handle_web (void)
|
||
{
|
||
return (optimize > 0 && flag_web);
|
||
}
|
||
|
||
static void
|
||
rest_of_handle_web (void)
|
||
{
|
||
web_main ();
|
||
delete_trivially_dead_insns (get_insns (), max_reg_num ());
|
||
cleanup_cfg (CLEANUP_EXPENSIVE);
|
||
reg_scan (get_insns (), max_reg_num ());
|
||
}
|
||
|
||
struct tree_opt_pass pass_web =
|
||
{
|
||
"web", /* name */
|
||
gate_handle_web, /* gate */
|
||
rest_of_handle_web, /* execute */
|
||
NULL, /* sub */
|
||
NULL, /* next */
|
||
0, /* static_pass_number */
|
||
TV_WEB, /* tv_id */
|
||
0, /* properties_required */
|
||
0, /* properties_provided */
|
||
0, /* properties_destroyed */
|
||
0, /* todo_flags_start */
|
||
TODO_dump_func, /* todo_flags_finish */
|
||
'Z' /* letter */
|
||
};
|
||
|