Commit 4164ad58 authored by bernds's avatar bernds
Browse files

PR rtl-optimization/39871

	PR rtl-optimization/40615
	PR rtl-optimization/42500
	PR rtl-optimization/42502
	* ira.c (init_reg_equiv_memory_loc: New function.
	(ira): Call it twice.
	* reload.h (calculate_elim_costs_all_insns): Declare.
	* ira-costs.c: Include "reload.h".
	(regno_equiv_gains): New static variable.
	(init_costs): Allocate it.
	(finish_costs): Free it.
	(ira_costs): Call calculate_elim_costs_all_insns.
	(find_costs_and_classes): Take estimated elimination costs
	into account.
	(ira_adjust_equiv_reg_cost): New function.
	* ira.h (ira_adjust_equiv_reg_cost): Declare it.
	* reload1.c (init_eliminable_invariants, free_reg_equiv,
	elimination_costs_in_insn, note_reg_elim_costly): New static
	functions.
	(elim_bb): New static variable.
	(reload): Move code out of here into init_eliminable_invariants and
	free_reg_equiv.  Call them.
	(calculate_elim_costs_all_insns): New function.
	(eliminate_regs_1): Declare.  Add extra arg FOR_COSTS;
	all callers changed.  If FOR_COSTS is true, don't call alter_reg,
	but call note_reg_elim_costly if we turned a valid memory address
	into an invalid one.
	* Makefile.in (ira-costs.o): Depend on reload.h.

testsuite/
	PR rtl-optimization/39871
	PR rtl-optimization/40615
	PR rtl-optimization/42500
	PR rtl-optimization/42502
	* gcc.target/arm/eliminate.c: New test.



git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@160260 138bc75d-0d04-0410-961f-82ee72b054a4
parent 54007dc2
2010-06-04 Bernd Schmidt <bernds@codesourcery.com>
PR rtl-optimization/39871
PR rtl-optimization/40615
PR rtl-optimization/42500
PR rtl-optimization/42502
* ira.c (init_reg_equiv_memory_loc: New function.
(ira): Call it twice.
* reload.h (calculate_elim_costs_all_insns): Declare.
* ira-costs.c: Include "reload.h".
(regno_equiv_gains): New static variable.
(init_costs): Allocate it.
(finish_costs): Free it.
(ira_costs): Call calculate_elim_costs_all_insns.
(find_costs_and_classes): Take estimated elimination costs
into account.
(ira_adjust_equiv_reg_cost): New function.
* ira.h (ira_adjust_equiv_reg_cost): Declare it.
* reload1.c (init_eliminable_invariants, free_reg_equiv,
elimination_costs_in_insn, note_reg_elim_costly): New static
functions.
(elim_bb): New static variable.
(reload): Move code out of here into init_eliminable_invariants and
free_reg_equiv. Call them.
(calculate_elim_costs_all_insns): New function.
(eliminate_regs_1): Declare. Add extra arg FOR_COSTS;
all callers changed. If FOR_COSTS is true, don't call alter_reg,
but call note_reg_elim_costly if we turned a valid memory address
into an invalid one.
* Makefile.in (ira-costs.o): Depend on reload.h.
2010-06-04 Julian Brown <julian@codesourcery.com>
* config/arm/thumb2.md (*thumb2_movdf_soft_insn): Fix alternatives
......
......@@ -3276,7 +3276,7 @@ ira-build.o: ira-build.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
ira-costs.o: ira-costs.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
hard-reg-set.h $(RTL_H) $(EXPR_H) $(TM_P_H) $(FLAGS_H) $(BASIC_BLOCK_H) \
$(REGS_H) addresses.h insn-config.h $(RECOG_H) $(TOPLEV_H) $(TARGET_H) \
$(PARAMS_H) $(IRA_INT_H)
$(PARAMS_H) $(IRA_INT_H) reload.h
ira-conflicts.o: ira-conflicts.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
$(TARGET_H) $(RTL_H) $(REGS_H) hard-reg-set.h $(FLAGS_H) \
insn-config.h $(RECOG_H) $(BASIC_BLOCK_H) $(TOPLEV_H) $(TM_P_H) $(PARAMS_H) \
......
......@@ -33,6 +33,7 @@ along with GCC; see the file COPYING3. If not see
#include "addresses.h"
#include "insn-config.h"
#include "recog.h"
#include "reload.h"
#include "toplev.h"
#include "target.h"
#include "params.h"
......@@ -123,6 +124,10 @@ static enum reg_class *pref_buffer;
/* Record cover register class of each allocno with the same regno. */
static enum reg_class *regno_cover_class;
/* Record cost gains for not allocating a register with an invariant
equivalence. */
static int *regno_equiv_gains;
/* Execution frequency of the current insn. */
static int frequency;
......@@ -1263,6 +1268,7 @@ find_costs_and_classes (FILE *dump_file)
#ifdef FORBIDDEN_INC_DEC_CLASSES
int inc_dec_p = false;
#endif
int equiv_savings = regno_equiv_gains[i];
if (! allocno_p)
{
......@@ -1311,6 +1317,15 @@ find_costs_and_classes (FILE *dump_file)
#endif
}
}
if (equiv_savings < 0)
temp_costs->mem_cost = -equiv_savings;
else if (equiv_savings > 0)
{
temp_costs->mem_cost = 0;
for (k = 0; k < cost_classes_num; k++)
temp_costs->cost[k] += equiv_savings;
}
best_cost = (1 << (HOST_BITS_PER_INT - 2)) - 1;
best = ALL_REGS;
alt_class = NO_REGS;
......@@ -1680,6 +1695,8 @@ init_costs (void)
regno_cover_class
= (enum reg_class *) ira_allocate (sizeof (enum reg_class)
* max_reg_num ());
regno_equiv_gains = (int *) ira_allocate (sizeof (int) * max_reg_num ());
memset (regno_equiv_gains, 0, sizeof (int) * max_reg_num ());
}
/* Common finalization function for ira_costs and
......@@ -1687,6 +1704,7 @@ init_costs (void)
static void
finish_costs (void)
{
ira_free (regno_equiv_gains);
ira_free (regno_cover_class);
ira_free (pref_buffer);
ira_free (costs);
......@@ -1702,6 +1720,7 @@ ira_costs (void)
init_costs ();
total_allocno_costs = (struct costs *) ira_allocate (max_struct_costs_size
* ira_allocnos_num);
calculate_elim_costs_all_insns ();
find_costs_and_classes (ira_dump_file);
setup_allocno_cover_class_and_costs ();
finish_costs ();
......@@ -1802,3 +1821,16 @@ ira_tune_allocno_costs_and_cover_classes (void)
}
}
}
/* Add COST to the estimated gain for eliminating REGNO with its
equivalence. If COST is zero, record that no such elimination is
possible. */
void
ira_adjust_equiv_reg_cost (unsigned regno, int cost)
{
if (cost == 0)
regno_equiv_gains[regno] = 0;
else
regno_equiv_gains[regno] += cost;
}
......@@ -3149,8 +3149,19 @@ build_insn_chain (void)
if (dump_file)
print_insn_chains (dump_file);
}
/* Allocate memory for reg_equiv_memory_loc. */
static void
init_reg_equiv_memory_loc (void)
{
max_regno = max_reg_num ();
/* And the reg_equiv_memory_loc array. */
VEC_safe_grow (rtx, gc, reg_equiv_memory_loc_vec, max_regno);
memset (VEC_address (rtx, reg_equiv_memory_loc_vec), 0,
sizeof (rtx) * max_regno);
reg_equiv_memory_loc = VEC_address (rtx, reg_equiv_memory_loc_vec);
}
/* All natural loops. */
struct loops ira_loops;
......@@ -3255,6 +3266,8 @@ ira (FILE *f)
record_loop_exits ();
current_loops = &ira_loops;
init_reg_equiv_memory_loc ();
if (internal_flag_ira_verbose > 0 && ira_dump_file != NULL)
fprintf (ira_dump_file, "Building IRA IR\n");
loops_p = ira_build (optimize
......@@ -3315,13 +3328,8 @@ ira (FILE *f)
#endif
delete_trivially_dead_insns (get_insns (), max_reg_num ());
max_regno = max_reg_num ();
/* And the reg_equiv_memory_loc array. */
VEC_safe_grow (rtx, gc, reg_equiv_memory_loc_vec, max_regno);
memset (VEC_address (rtx, reg_equiv_memory_loc_vec), 0,
sizeof (rtx) * max_regno);
reg_equiv_memory_loc = VEC_address (rtx, reg_equiv_memory_loc_vec);
init_reg_equiv_memory_loc ();
if (max_regno != max_regno_before_ira)
{
......
......@@ -88,3 +88,4 @@ extern void ira_mark_new_stack_slot (rtx, int, unsigned int);
extern bool ira_better_spill_reload_regno_p (int *, int *, rtx, rtx, rtx);
extern bool ira_bad_reload_regno (int, rtx, rtx);
extern void ira_adjust_equiv_reg_cost (unsigned, int);
......@@ -349,6 +349,10 @@ extern void mark_home_live (int);
extern rtx eliminate_regs (rtx, enum machine_mode, rtx);
extern bool elimination_target_reg_p (rtx);
/* Called from the register allocator to estimate costs of eliminating
invariant registers. */
extern void calculate_elim_costs_all_insns (void);
/* Deallocate the reload register used by reload number R. */
extern void deallocate_reload_reg (int r);
......
This diff is collapsed.
2010-06-04 Bernd Schmidt <bernds@codesourcery.com>
PR rtl-optimization/39871
PR rtl-optimization/40615
PR rtl-optimization/42500
PR rtl-optimization/42502
* gcc.target/arm/eliminate.c: New test.
2010-06-03 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/44410
......
/* { dg-do compile } */
/* { dg-options "-O2" } */
struct X
{
int c;
};
extern void bar(struct X *);
void foo ()
{
struct X x;
bar (&x);
bar (&x);
bar (&x);
}
/* { dg-final { scan-assembler-times "r0,\[\\t \]*sp" 3 } } */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment