Revert 253497 and 253539 to try to fix clang-cmake-mips buildbot.
authorDaniel Sanders <daniel.sanders@imgtec.com>
Fri, 20 Nov 2015 10:07:11 +0000 (10:07 +0000)
committerDaniel Sanders <daniel.sanders@imgtec.com>
Fri, 20 Nov 2015 10:07:11 +0000 (10:07 +0000)
It caused link errors of the form:
InstrProfiling.c:(.text.__llvm_profile_instrument_target+0x1c0): undefined reference to `__sync_fetch_and_add_8'

We had a network outage at the time of the commit so the first build to show a
problem is http://lab.llvm.org:8011/builders/clang-cmake-mips/builds/10827

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253656 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ProfileData/InstrProf.h
include/llvm/ProfileData/SampleProf.h
include/llvm/Support/MathExtras.h
unittests/ProfileData/InstrProfTest.cpp
unittests/Support/MathExtrasTest.cpp

index c31f4b5b589bd09d10ee684226eb60b89208f47b..59d0e1877a6909ff52ac6b9f60b0f71cc9e772be 100644 (file)
@@ -226,7 +226,7 @@ struct InstrProfValueSiteRecord {
       while (I != IE && I->Value < J->Value)
         ++I;
       if (I != IE && I->Value == J->Value) {
-        I->Count = SaturatingAdd(I->Count, J->Count);
+        I->Count += J->Count;
         ++I;
         continue;
       }
index a7b22c73548087fe15996d2fe2323553cd4dd992..30504981c48b81ae45c25e5f9bd8e81bec908fbc 100644 (file)
@@ -177,7 +177,10 @@ public:
   /// Sample counts accumulate using saturating arithmetic, to avoid wrapping
   /// around unsigned integers.
   void addSamples(uint64_t S) {
-    NumSamples = SaturatingAdd(NumSamples, S);
+    if (NumSamples <= std::numeric_limits<uint64_t>::max() - S)
+      NumSamples += S;
+    else
+      NumSamples = std::numeric_limits<uint64_t>::max();
   }
 
   /// Add called function \p F with samples \p S.
@@ -186,7 +189,10 @@ public:
   /// around unsigned integers.
   void addCalledTarget(StringRef F, uint64_t S) {
     uint64_t &TargetSamples = CallTargets[F];
-    TargetSamples = SaturatingAdd(TargetSamples, S);
+    if (TargetSamples <= std::numeric_limits<uint64_t>::max() - S)
+      TargetSamples += S;
+    else
+      TargetSamples = std::numeric_limits<uint64_t>::max();
   }
 
   /// Return true if this sample record contains function calls.
index 53aad36e929f588832145a9dca4801351dfa225a..9b5c02528ff84f9be711118b55181224e1edf65d 100644 (file)
@@ -653,32 +653,6 @@ inline int64_t SignExtend64(uint64_t X, unsigned B) {
   return int64_t(X << (64 - B)) >> (64 - B);
 }
 
-/// \brief Add two unsigned integers, X and Y, of type T.
-/// Clamp the result to the maximum representable value of T on overflow.
-template <typename T>
-typename std::enable_if<std::is_unsigned<T>::value, T>::type
-SaturatingAdd(T X, T Y) {
-  // Hacker's Delight, p. 29
-  T Z = X + Y;
-  if (Z < X || Z < Y)
-    return std::numeric_limits<T>::max();
-  else
-    return Z;
-}
-
-/// \brief Multiply two unsigned integers, X and Y, of type T.
-/// Clamp the result to the maximum representable value of T on overflow.
-template <typename T>
-typename std::enable_if<std::is_unsigned<T>::value, T>::type
-SaturatingMultiply(T X, T Y) {
-  // Hacker's Delight, p. 30
-  T Z = X * Y;
-  if (Y != 0 && Z / Y != X)
-    return std::numeric_limits<T>::max();
-  else
-    return Z;
-}
-
 extern const float huge_valf;
 } // End llvm namespace
 
index 6891931e4d22a5944a0da4cf00a84e7f4db59920..a9257fe316e0c8c37d333650e92315081f504546 100644 (file)
@@ -350,38 +350,6 @@ TEST_F(InstrProfTest, get_icall_data_merge1) {
   ASSERT_EQ(2U, VD_4[2].Count);
 }
 
-TEST_F(InstrProfTest, get_icall_data_merge1_saturation) {
-  const uint64_t Max = std::numeric_limits<uint64_t>::max();
-
-  InstrProfRecord Record1("caller", 0x1234, {1});
-  InstrProfRecord Record2("caller", 0x1234, {1});
-  InstrProfRecord Record3("callee1", 0x1235, {3, 4});
-
-  Record1.reserveSites(IPVK_IndirectCallTarget, 1);
-  InstrProfValueData VD1[] = {{(uint64_t) "callee1", 1}};
-  Record1.addValueData(IPVK_IndirectCallTarget, 0, VD1, 1, nullptr);
-
-  Record2.reserveSites(IPVK_IndirectCallTarget, 1);
-  InstrProfValueData VD2[] = {{(uint64_t) "callee1", Max}};
-  Record2.addValueData(IPVK_IndirectCallTarget, 0, VD2, 1, nullptr);
-
-  Writer.addRecord(std::move(Record1));
-  Writer.addRecord(std::move(Record2));
-  Writer.addRecord(std::move(Record3));
-
-  auto Profile = Writer.writeBuffer();
-  readProfile(std::move(Profile));
-
-  // Verify saturation of counts.
-  ErrorOr<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234);
-  ASSERT_TRUE(NoError(R.getError()));
-  ASSERT_EQ(1U, R.get().getNumValueSites(IPVK_IndirectCallTarget));
-  std::unique_ptr<InstrProfValueData[]> VD =
-          R.get().getValueForSite(IPVK_IndirectCallTarget, 0);
-  ASSERT_EQ(StringRef("callee1"), StringRef((const char *)VD[0].Value, 7));
-  ASSERT_EQ(Max, VD[0].Count);
-}
-
 TEST_F(InstrProfTest, get_max_function_count) {
   InstrProfRecord Record1("foo", 0x1234, {1ULL << 31, 2});
   InstrProfRecord Record2("bar", 0, {1ULL << 63});
index 0f3854680ac6e7be26357b6833b395c2bed0526c..8bd47e34c7ec1eed32a1a645f184d149c76db023 100644 (file)
@@ -190,21 +190,4 @@ TEST(MathExtras, RoundUpToAlignment) {
   EXPECT_EQ(552u, RoundUpToAlignment(321, 255, 42));
 }
 
-template<typename T>
-void SaturatingAddTestHelper()
-{
-  const T Max = std::numeric_limits<T>::max();
-  EXPECT_EQ(T(3), SaturatingAdd(T(1), T(2)));
-  EXPECT_EQ(Max, SaturatingAdd(Max, T(1)));
-  EXPECT_EQ(Max, SaturatingAdd(T(1), Max));
-  EXPECT_EQ(Max, SaturatingAdd(Max, Max));
-}
-
-TEST(MathExtras, SaturatingAdd) {
-  SaturatingAddTestHelper<uint8_t>();
-  SaturatingAddTestHelper<uint16_t>();
-  SaturatingAddTestHelper<uint32_t>();
-  SaturatingAddTestHelper<uint64_t>();
-}
-
 }