• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "llvm/Support/DataTypes.h"
2 #include "llvm/Support/BlockFrequency.h"
3 #include "llvm/Support/BranchProbability.h"
4 
5 #include "gtest/gtest.h"
6 #include <climits>
7 
8 using namespace llvm;
9 
10 namespace {
11 
TEST(BlockFrequencyTest,OneToZero)12 TEST(BlockFrequencyTest, OneToZero) {
13   BlockFrequency Freq(1);
14   BranchProbability Prob(UINT32_MAX - 1, UINT32_MAX);
15   Freq *= Prob;
16   EXPECT_EQ(Freq.getFrequency(), 0u);
17 }
18 
TEST(BlockFrequencyTest,OneToOne)19 TEST(BlockFrequencyTest, OneToOne) {
20   BlockFrequency Freq(1);
21   BranchProbability Prob(UINT32_MAX, UINT32_MAX);
22   Freq *= Prob;
23   EXPECT_EQ(Freq.getFrequency(), 1u);
24 }
25 
TEST(BlockFrequencyTest,ThreeToOne)26 TEST(BlockFrequencyTest, ThreeToOne) {
27   BlockFrequency Freq(3);
28   BranchProbability Prob(3000000, 9000000);
29   Freq *= Prob;
30   EXPECT_EQ(Freq.getFrequency(), 1u);
31 }
32 
TEST(BlockFrequencyTest,MaxToHalfMax)33 TEST(BlockFrequencyTest, MaxToHalfMax) {
34   BlockFrequency Freq(UINT64_MAX);
35   BranchProbability Prob(UINT32_MAX / 2, UINT32_MAX);
36   Freq *= Prob;
37   EXPECT_EQ(Freq.getFrequency(), 9223372034707292159LLu);
38 }
39 
TEST(BlockFrequencyTest,BigToBig)40 TEST(BlockFrequencyTest, BigToBig) {
41   const uint64_t Big = 387246523487234346LL;
42   const uint32_t P = 123456789;
43   BlockFrequency Freq(Big);
44   BranchProbability Prob(P, P);
45   Freq *= Prob;
46   EXPECT_EQ(Freq.getFrequency(), Big);
47 }
48 
TEST(BlockFrequencyTest,MaxToMax)49 TEST(BlockFrequencyTest, MaxToMax) {
50   BlockFrequency Freq(UINT64_MAX);
51   BranchProbability Prob(UINT32_MAX, UINT32_MAX);
52   Freq *= Prob;
53   EXPECT_EQ(Freq.getFrequency(), UINT64_MAX);
54 }
55 
56 }
57