#include "cgraph.h"
#include "wide-int.h"
#include "sreal.h"
-#include "selftest.h"
/* Names from profile_quality enum values. */
return 0;
gcc_checking_assert (entry_bb_count.initialized_p ());
uint64_t scale;
- gcc_checking_assert (compatible_p (entry_bb_count));
if (!safe_scale_64bit (!entry_bb_count.m_val ? m_val + 1 : m_val,
CGRAPH_FREQ_BASE, MAX (1, entry_bb_count.m_val), &scale))
return CGRAPH_FREQ_MAX;
return 0;
if (m_val == in.m_val)
return 1;
- gcc_checking_assert (compatible_p (in));
if (!in.m_val)
{
profile_count
profile_count::combine_with_ipa_count (profile_count ipa)
{
- if (!initialized_p ())
- return *this;
ipa = ipa.ipa ();
if (ipa.nonzero_p ())
return ipa;
else
return *this * even () + other * even ();
}
-
-#if CHECKING_P
-namespace selftest {
-
-/* Verify non-trivial type conversions for IPA scaling. This happens often
- during inlining. */
-
-static void
-profile_count_verify_ipa_scaling (void)
-{
- profile_count cnt1 = profile_count::from_gcov_type (4).global0 ();
- profile_count cnt2 = profile_count::from_gcov_type (2);
- profile_count cnt3 = profile_count::from_gcov_type (8);
- profile_count cnt4 = cnt3.apply_scale (cnt1, cnt2);
-
- /* Result should be 16 with GUESSED_GLOBAL0. */
- ASSERT_EQ (cnt4.ipa (), profile_count::zero ());
- ASSERT_EQ (cnt4.to_gcov_type (), 16);
-
- cnt1 = profile_count::from_gcov_type (4).global0adjusted ();
- cnt4 = cnt3.apply_scale (cnt1, cnt2);
- /* Result should be 16 with GUESSED_GLOBAL0_ADJUSTED. */
- ASSERT_EQ (cnt4.ipa (), profile_count::adjusted_zero ());
- ASSERT_EQ (cnt4.to_gcov_type (), 16);
-}
-
-/* Verify non-trivial cases of sreal scale calculations. */
-
-static void
-profile_count_verify_to_sreal_scale (void)
-{
- profile_count cnt1 = profile_count::from_gcov_type (4).global0 ();
- profile_count cnt2 = profile_count::from_gcov_type (8);
-
- /* If count is globally 0 it should have 0 scale in non-zero global count. */
- ASSERT_EQ (cnt1.to_sreal_scale (cnt2), 0);
-}
-
-/* Verify non-trivial cases of probability_in calculations. */
-
-static void
-profile_count_verify_probability_in (void)
-{
- /*profile_count cnt1 = profile_count::from_gcov_type (4).global0 ();
- profile_count cnt2 = profile_count::from_gcov_type (8);*/
-
- /* If count is globally 0 it should have 0 probability in non-zero global
- count. */
- /*ASSERT_EQ (cnt1.probability_in (cnt2), profile_probability::never ());*/
-}
-
-/* Run all of the selftests within this file. */
-
-void profile_count_c_tests (void)
-{
- profile_count_verify_ipa_scaling ();
- profile_count_verify_to_sreal_scale ();
- profile_count_verify_probability_in ();
-}
-
-}
-#endif
uint64_t UINT64_BIT_FIELD_ALIGN m_val : n_bits;
#undef UINT64_BIT_FIELD_ALIGN
enum profile_quality m_quality : 3;
-public:
/* Return true if both values can meaningfully appear in single function
body. We have either all counters in function local or global, otherwise
if (*this == zero ()
|| other == zero ())
return true;
- /* Do not allow nonzero global profile together with local guesses
- that are globally0. */
- if (ipa ().nonzero_p ()
- && !(other.ipa () == other))
- return false;
- if (other.ipa ().nonzero_p ()
- && !(ipa () == *this))
- return false;
-
return ipa_p () == other.ipa_p ();
}
-
+public:
/* Used for counters which are expected to be never executed. */
static profile_count zero ()
{
profile_count max (profile_count other) const
{
- profile_count val = *this;
-
- /* Always prefer nonzero IPA counts over local counts. */
- if (ipa ().nonzero_p () || other.ipa ().nonzero_p ())
- {
- val = ipa ();
- other = other.ipa ();
- }
if (!initialized_p ())
return other;
if (!other.initialized_p ())
if (other == zero ())
return *this;
gcc_checking_assert (compatible_p (other));
- if (val.m_val < other.m_val || (m_val == other.m_val
- && val.m_quality < other.m_quality))
+ if (m_val < other.m_val || (m_val == other.m_val
+ && m_quality < other.m_quality))
return other;
return *this;
}
{
if (*this == zero ())
return *this;
-
if (num == zero ())
return num;
if (!initialized_p () || !num.initialized_p () || !den.initialized_p ())
ret.m_val = MIN (val, max_count);
ret.m_quality = MIN (MIN (MIN (m_quality, ADJUSTED),
num.m_quality), den.m_quality);
- /* Be sure that ret is not local or global0 type
- if num is global. */
- if (num.ipa_p () && (!ret.ipa_p () || !(ret.ipa () == ret)))
+ if (num.ipa_p () && !ret.ipa_p ())
ret.m_quality = MIN (num.m_quality, GUESSED);
return ret;
}
if (*this == overall && m_quality == PRECISE)
return profile_probability::always ();
profile_probability ret;
-
gcc_checking_assert (compatible_p (overall));
+
if (overall.m_val < m_val)
{
ret.m_val = profile_probability::max_probability;