Commit 618b7f29 by Trevor Saunders Committed by Trevor Saunders

c++ify sreal

gcc/ChangeLog:

2014-11-10  Trevor Saunders  <tsaunders@mozilla.com>

	* ipa-inline.c (edge_badness): Adjust.
	(inline_small_functions): Likewise.
	* predict.c (propagate_freq): Likewise.
	(estimate_bb_frequencies): Likewise.
	* sreal.c (sreal::dump): Rename from dump_sreal.
	(debug): Adjust.
	(copy): Remove function.
	(sreal::shift_right): Rename from sreal_sift_right.
	(sreal::normalize): Rename from normalize.
	(sreal_init): Remove function.
	(sreal::to_int): Rename from sreal_to_int.
	(sreal_compare): Remove function.
	(sreal::operator+): Rename from sreal_add.
	(sreal::operator-): Rename from sreal_sub.
	(sreal::operator*): Rename from sreal_mul.
	(sreal::operator/): Rename from sreal_div.
	* sreal.h (class sreal): Adjust.
	(inline sreal &operator+=): New operator.
	(inline sreal &operator-=): Likewise.
	(inline sreal &operator/=): Likewise.
	(inline sreal &operator*=): Likewise.
	(inline bool operator!=): Likewise.
	(inline bool operator>): Likewise.
	(inline bool operator<=): Likewise.
	(inline bool operator>=): Likewise.

From-SVN: r217332
parent 43722f9f
2014-11-10 Trevor Saunders <tsaunders@mozilla.com>
* ipa-inline.c (edge_badness): Adjust.
(inline_small_functions): Likewise.
* predict.c (propagate_freq): Likewise.
(estimate_bb_frequencies): Likewise.
* sreal.c (sreal::dump): Rename from dump_sreal.
(debug): Adjust.
(copy): Remove function.
(sreal::shift_right): Rename from sreal_sift_right.
(sreal::normalize): Rename from normalize.
(sreal_init): Remove function.
(sreal::to_int): Rename from sreal_to_int.
(sreal_compare): Remove function.
(sreal::operator+): Rename from sreal_add.
(sreal::operator-): Rename from sreal_sub.
(sreal::operator*): Rename from sreal_mul.
(sreal::operator/): Rename from sreal_div.
* sreal.h (class sreal): Adjust.
(inline sreal &operator+=): New operator.
(inline sreal &operator-=): Likewise.
(inline sreal &operator/=): Likewise.
(inline sreal &operator*=): Likewise.
(inline bool operator!=): Likewise.
(inline bool operator>): Likewise.
(inline bool operator<=): Likewise.
(inline bool operator>=): Likewise.
2014-11-11 Bin Cheng <bin.cheng@arm.com> 2014-11-11 Bin Cheng <bin.cheng@arm.com>
* sched-deps.c (sched_analyze_1): Check pending list if it is not * sched-deps.c (sched_analyze_1): Check pending list if it is not
...@@ -962,29 +962,28 @@ edge_badness (struct cgraph_edge *edge, bool dump) ...@@ -962,29 +962,28 @@ edge_badness (struct cgraph_edge *edge, bool dump)
else if (max_count) else if (max_count)
{ {
sreal tmp, relbenefit_real, growth_real;
int relbenefit = relative_time_benefit (callee_info, edge, edge_time); int relbenefit = relative_time_benefit (callee_info, edge, edge_time);
/* Capping edge->count to max_count. edge->count can be larger than /* Capping edge->count to max_count. edge->count can be larger than
max_count if an inline adds new edges which increase max_count max_count if an inline adds new edges which increase max_count
after max_count is computed. */ after max_count is computed. */
gcov_type edge_count = edge->count > max_count ? max_count : edge->count; gcov_type edge_count = edge->count > max_count ? max_count : edge->count;
sreal_init (&relbenefit_real, relbenefit, 0); sreal relbenefit_real (relbenefit, 0);
sreal_init (&growth_real, growth, 0); sreal growth_real (growth, 0);
/* relative_edge_count. */ /* relative_edge_count. */
sreal_init (&tmp, edge_count, 0); sreal tmp (edge_count, 0);
sreal_div (&tmp, &tmp, &max_count_real); tmp /= max_count_real;
/* relative_time_benefit. */ /* relative_time_benefit. */
sreal_mul (&tmp, &tmp, &relbenefit_real); tmp *= relbenefit_real;
sreal_div (&tmp, &tmp, &max_relbenefit_real); tmp /= max_relbenefit_real;
/* growth_f_caller. */ /* growth_f_caller. */
sreal_mul (&tmp, &tmp, &half_int_min_real); tmp *= half_int_min_real;
sreal_div (&tmp, &tmp, &growth_real); tmp /= growth_real;
badness = -1 * sreal_to_int (&tmp); badness = -1 * tmp.to_int ();
if (dump) if (dump)
{ {
...@@ -1627,9 +1626,9 @@ inline_small_functions (void) ...@@ -1627,9 +1626,9 @@ inline_small_functions (void)
if (max_count < edge->count) if (max_count < edge->count)
max_count = edge->count; max_count = edge->count;
} }
sreal_init (&max_count_real, max_count, 0); max_count_real = sreal (max_count, 0);
sreal_init (&max_relbenefit_real, RELATIVE_TIME_BENEFIT_RANGE, 0); max_relbenefit_real = sreal (RELATIVE_TIME_BENEFIT_RANGE, 0);
sreal_init (&half_int_min_real, INT_MAX / 2, 0); half_int_min_real = sreal (INT_MAX / 2, 0);
ipa_free_postorder_info (); ipa_free_postorder_info ();
initialize_growth_caches (); initialize_growth_caches ();
......
...@@ -2528,15 +2528,13 @@ propagate_freq (basic_block head, bitmap tovisit) ...@@ -2528,15 +2528,13 @@ propagate_freq (basic_block head, bitmap tovisit)
bb->count = bb->frequency = 0; bb->count = bb->frequency = 0;
} }
memcpy (&BLOCK_INFO (head)->frequency, &real_one, sizeof (real_one)); BLOCK_INFO (head)->frequency = real_one;
last = head; last = head;
for (bb = head; bb; bb = nextbb) for (bb = head; bb; bb = nextbb)
{ {
edge_iterator ei; edge_iterator ei;
sreal cyclic_probability, frequency; sreal cyclic_probability = real_zero;
sreal frequency = real_zero;
memcpy (&cyclic_probability, &real_zero, sizeof (real_zero));
memcpy (&frequency, &real_zero, sizeof (real_zero));
nextbb = BLOCK_INFO (bb)->next; nextbb = BLOCK_INFO (bb)->next;
BLOCK_INFO (bb)->next = NULL; BLOCK_INFO (bb)->next = NULL;
...@@ -2553,42 +2551,34 @@ propagate_freq (basic_block head, bitmap tovisit) ...@@ -2553,42 +2551,34 @@ propagate_freq (basic_block head, bitmap tovisit)
FOR_EACH_EDGE (e, ei, bb->preds) FOR_EACH_EDGE (e, ei, bb->preds)
if (EDGE_INFO (e)->back_edge) if (EDGE_INFO (e)->back_edge)
{ {
sreal_add (&cyclic_probability, &cyclic_probability, cyclic_probability += EDGE_INFO (e)->back_edge_prob;
&EDGE_INFO (e)->back_edge_prob);
} }
else if (!(e->flags & EDGE_DFS_BACK)) else if (!(e->flags & EDGE_DFS_BACK))
{ {
sreal tmp;
/* frequency += (e->probability /* frequency += (e->probability
* BLOCK_INFO (e->src)->frequency / * BLOCK_INFO (e->src)->frequency /
REG_BR_PROB_BASE); */ REG_BR_PROB_BASE); */
sreal_init (&tmp, e->probability, 0); sreal tmp (e->probability, 0);
sreal_mul (&tmp, &tmp, &BLOCK_INFO (e->src)->frequency); tmp *= BLOCK_INFO (e->src)->frequency;
sreal_mul (&tmp, &tmp, &real_inv_br_prob_base); tmp *= real_inv_br_prob_base;
sreal_add (&frequency, &frequency, &tmp); frequency += tmp;
} }
if (sreal_compare (&cyclic_probability, &real_zero) == 0) if (cyclic_probability == real_zero)
{ {
memcpy (&BLOCK_INFO (bb)->frequency, &frequency, BLOCK_INFO (bb)->frequency = frequency;
sizeof (frequency));
} }
else else
{ {
if (sreal_compare (&cyclic_probability, &real_almost_one) > 0) if (cyclic_probability > real_almost_one)
{ cyclic_probability = real_almost_one;
memcpy (&cyclic_probability, &real_almost_one,
sizeof (real_almost_one));
}
/* BLOCK_INFO (bb)->frequency = frequency /* BLOCK_INFO (bb)->frequency = frequency
/ (1 - cyclic_probability) */ / (1 - cyclic_probability) */
sreal_sub (&cyclic_probability, &real_one, &cyclic_probability); cyclic_probability = real_one - cyclic_probability;
sreal_div (&BLOCK_INFO (bb)->frequency, BLOCK_INFO (bb)->frequency = frequency / cyclic_probability;
&frequency, &cyclic_probability);
} }
} }
...@@ -2597,16 +2587,13 @@ propagate_freq (basic_block head, bitmap tovisit) ...@@ -2597,16 +2587,13 @@ propagate_freq (basic_block head, bitmap tovisit)
e = find_edge (bb, head); e = find_edge (bb, head);
if (e) if (e)
{ {
sreal tmp;
/* EDGE_INFO (e)->back_edge_prob /* EDGE_INFO (e)->back_edge_prob
= ((e->probability * BLOCK_INFO (bb)->frequency) = ((e->probability * BLOCK_INFO (bb)->frequency)
/ REG_BR_PROB_BASE); */ / REG_BR_PROB_BASE); */
sreal_init (&tmp, e->probability, 0); sreal tmp (e->probability, 0);
sreal_mul (&tmp, &tmp, &BLOCK_INFO (bb)->frequency); tmp *= BLOCK_INFO (bb)->frequency;
sreal_mul (&EDGE_INFO (e)->back_edge_prob, EDGE_INFO (e)->back_edge_prob = tmp * real_inv_br_prob_base;
&tmp, &real_inv_br_prob_base);
} }
/* Propagate to successor blocks. */ /* Propagate to successor blocks. */
...@@ -2886,13 +2873,13 @@ estimate_bb_frequencies (bool force) ...@@ -2886,13 +2873,13 @@ estimate_bb_frequencies (bool force)
if (!real_values_initialized) if (!real_values_initialized)
{ {
real_values_initialized = 1; real_values_initialized = 1;
sreal_init (&real_zero, 0, 0); real_zero = sreal (0, 0);
sreal_init (&real_one, 1, 0); real_one = sreal (1, 0);
sreal_init (&real_br_prob_base, REG_BR_PROB_BASE, 0); real_br_prob_base = sreal (REG_BR_PROB_BASE, 0);
sreal_init (&real_bb_freq_max, BB_FREQ_MAX, 0); real_bb_freq_max = sreal (BB_FREQ_MAX, 0);
sreal_init (&real_one_half, 1, -1); real_one_half = sreal (1, -1);
sreal_div (&real_inv_br_prob_base, &real_one, &real_br_prob_base); real_inv_br_prob_base = real_one / real_br_prob_base;
sreal_sub (&real_almost_one, &real_one, &real_inv_br_prob_base); real_almost_one = real_one - real_inv_br_prob_base;
} }
mark_dfs_back_edges (); mark_dfs_back_edges ();
...@@ -2910,10 +2897,8 @@ estimate_bb_frequencies (bool force) ...@@ -2910,10 +2897,8 @@ estimate_bb_frequencies (bool force)
FOR_EACH_EDGE (e, ei, bb->succs) FOR_EACH_EDGE (e, ei, bb->succs)
{ {
sreal_init (&EDGE_INFO (e)->back_edge_prob, e->probability, 0); EDGE_INFO (e)->back_edge_prob = sreal (e->probability, 0);
sreal_mul (&EDGE_INFO (e)->back_edge_prob, EDGE_INFO (e)->back_edge_prob *= real_inv_br_prob_base;
&EDGE_INFO (e)->back_edge_prob,
&real_inv_br_prob_base);
} }
} }
...@@ -2921,19 +2906,16 @@ estimate_bb_frequencies (bool force) ...@@ -2921,19 +2906,16 @@ estimate_bb_frequencies (bool force)
to outermost to examine frequencies for back edges. */ to outermost to examine frequencies for back edges. */
estimate_loops (); estimate_loops ();
memcpy (&freq_max, &real_zero, sizeof (real_zero)); freq_max = real_zero;
FOR_EACH_BB_FN (bb, cfun) FOR_EACH_BB_FN (bb, cfun)
if (sreal_compare (&freq_max, &BLOCK_INFO (bb)->frequency) < 0) if (freq_max < BLOCK_INFO (bb)->frequency)
memcpy (&freq_max, &BLOCK_INFO (bb)->frequency, sizeof (freq_max)); freq_max = BLOCK_INFO (bb)->frequency;
sreal_div (&freq_max, &real_bb_freq_max, &freq_max); freq_max = real_bb_freq_max / freq_max;
FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb) FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)
{ {
sreal tmp; sreal tmp = BLOCK_INFO (bb)->frequency * freq_max + real_one_half;
bb->frequency = tmp.to_int ();
sreal_mul (&tmp, &BLOCK_INFO (bb)->frequency, &freq_max);
sreal_add (&tmp, &tmp, &real_one_half);
bb->frequency = sreal_to_int (&tmp);
} }
free_aux_for_blocks (); free_aux_for_blocks ();
......
...@@ -21,46 +21,92 @@ along with GCC; see the file COPYING3. If not see ...@@ -21,46 +21,92 @@ along with GCC; see the file COPYING3. If not see
#define GCC_SREAL_H #define GCC_SREAL_H
/* SREAL_PART_BITS has to be an even number. */ /* SREAL_PART_BITS has to be an even number. */
#if (HOST_BITS_PER_WIDE_INT / 2) % 2 == 1 #define SREAL_PART_BITS 32
#define SREAL_PART_BITS (HOST_BITS_PER_WIDE_INT / 2 - 1)
#else
#define SREAL_PART_BITS (HOST_BITS_PER_WIDE_INT / 2)
#endif
#define uhwi unsigned HOST_WIDE_INT
#define MAX_HOST_WIDE_INT (((uhwi) 1 << (HOST_BITS_PER_WIDE_INT - 1)) - 1)
#define SREAL_MIN_SIG ((uhwi) 1 << (SREAL_PART_BITS - 1)) #define SREAL_MIN_SIG ((uint64_t) 1 << (SREAL_PART_BITS - 1))
#define SREAL_MAX_SIG (((uhwi) 1 << SREAL_PART_BITS) - 1) #define SREAL_MAX_SIG (((uint64_t) 1 << SREAL_PART_BITS) - 1)
#define SREAL_MAX_EXP (INT_MAX / 4) #define SREAL_MAX_EXP (INT_MAX / 4)
#if SREAL_PART_BITS < 32
#define SREAL_BITS (SREAL_PART_BITS * 2)
#else
#define SREAL_BITS SREAL_PART_BITS #define SREAL_BITS SREAL_PART_BITS
#endif
/* Structure for holding a simple real number. */ /* Structure for holding a simple real number. */
struct sreal class sreal
{ {
#if SREAL_PART_BITS < 32 public:
unsigned HOST_WIDE_INT sig_lo; /* Significant (lower part). */ /* Construct an uninitialized sreal. */
unsigned HOST_WIDE_INT sig_hi; /* Significant (higher part). */ sreal () : m_sig (-1), m_exp (-1) {}
#else
unsigned HOST_WIDE_INT sig; /* Significant. */ /* Construct a sreal. */
#endif sreal (uint64_t sig, int exp) : m_sig (sig), m_exp (exp) { normalize (); }
signed int exp; /* Exponent. */
void dump (FILE *) const;
int64_t to_int () const;
sreal operator+ (const sreal &other) const;
sreal operator- (const sreal &other) const;
sreal operator* (const sreal &other) const;
sreal operator/ (const sreal &other) const;
bool operator< (const sreal &other) const
{
return m_exp < other.m_exp
|| (m_exp == other.m_exp && m_sig < other.m_sig);
}
bool operator== (const sreal &other) const
{
return m_exp == other.m_exp && m_sig == other.m_sig;
}
private:
void normalize ();
void shift_right (int amount);
uint64_t m_sig; /* Significant. */
signed int m_exp; /* Exponent. */
}; };
extern void dump_sreal (FILE *, sreal *);
extern void debug (sreal &ref); extern void debug (sreal &ref);
extern void debug (sreal *ptr); extern void debug (sreal *ptr);
extern sreal *sreal_init (sreal *, unsigned HOST_WIDE_INT, signed int);
extern HOST_WIDE_INT sreal_to_int (sreal *); inline sreal &operator+= (sreal &a, const sreal &b)
extern int sreal_compare (sreal *, sreal *); {
extern sreal *sreal_add (sreal *, sreal *, sreal *); return a = a + b;
extern sreal *sreal_sub (sreal *, sreal *, sreal *); }
extern sreal *sreal_mul (sreal *, sreal *, sreal *);
extern sreal *sreal_div (sreal *, sreal *, sreal *); inline sreal &operator-= (sreal &a, const sreal &b)
{
return a = a - b;
}
inline sreal &operator/= (sreal &a, const sreal &b)
{
return a = a / b;
}
inline sreal &operator*= (sreal &a, const sreal &b)
{
return a = a * b;
}
inline bool operator!= (const sreal &a, const sreal &b)
{
return !(a == b);
}
inline bool operator> (const sreal &a, const sreal &b)
{
return !(a == b || a < b);
}
inline bool operator<= (const sreal &a, const sreal &b)
{
return a < b || a == b;
}
inline bool operator>= (const sreal &a, const sreal &b)
{
return a == b || a > b;
}
#endif #endif
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