2011-07-28 02:57:40 +08:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
|
|
|
#include "llvm/Support/BlockFrequency.h"
|
|
|
|
#include "llvm/Support/BranchProbability.h"
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include <climits>
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
TEST(BlockFrequencyTest, OneToZero) {
|
|
|
|
BlockFrequency Freq(1);
|
|
|
|
BranchProbability Prob(UINT32_MAX - 1, UINT32_MAX);
|
|
|
|
Freq *= Prob;
|
|
|
|
EXPECT_EQ(Freq.getFrequency(), 0u);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BlockFrequencyTest, OneToOne) {
|
|
|
|
BlockFrequency Freq(1);
|
|
|
|
BranchProbability Prob(UINT32_MAX, UINT32_MAX);
|
|
|
|
Freq *= Prob;
|
|
|
|
EXPECT_EQ(Freq.getFrequency(), 1u);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BlockFrequencyTest, ThreeToOne) {
|
|
|
|
BlockFrequency Freq(3);
|
|
|
|
BranchProbability Prob(3000000, 9000000);
|
|
|
|
Freq *= Prob;
|
|
|
|
EXPECT_EQ(Freq.getFrequency(), 1u);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BlockFrequencyTest, MaxToHalfMax) {
|
|
|
|
BlockFrequency Freq(UINT64_MAX);
|
|
|
|
BranchProbability Prob(UINT32_MAX / 2, UINT32_MAX);
|
|
|
|
Freq *= Prob;
|
2012-06-17 22:53:53 +08:00
|
|
|
EXPECT_EQ(Freq.getFrequency(), 9223372034707292159ULL);
|
2011-07-28 02:57:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BlockFrequencyTest, BigToBig) {
|
|
|
|
const uint64_t Big = 387246523487234346LL;
|
|
|
|
const uint32_t P = 123456789;
|
|
|
|
BlockFrequency Freq(Big);
|
|
|
|
BranchProbability Prob(P, P);
|
|
|
|
Freq *= Prob;
|
|
|
|
EXPECT_EQ(Freq.getFrequency(), Big);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(BlockFrequencyTest, MaxToMax) {
|
|
|
|
BlockFrequency Freq(UINT64_MAX);
|
|
|
|
BranchProbability Prob(UINT32_MAX, UINT32_MAX);
|
|
|
|
Freq *= Prob;
|
|
|
|
EXPECT_EQ(Freq.getFrequency(), UINT64_MAX);
|
|
|
|
}
|
|
|
|
|
2011-10-23 19:19:14 +08:00
|
|
|
TEST(BlockFrequencyTest, ProbabilityCompare) {
|
|
|
|
BranchProbability A(4, 5);
|
|
|
|
BranchProbability B(4U << 29, 5U << 29);
|
|
|
|
BranchProbability C(3, 4);
|
|
|
|
|
|
|
|
EXPECT_TRUE(A == B);
|
|
|
|
EXPECT_FALSE(A != B);
|
|
|
|
EXPECT_FALSE(A < B);
|
|
|
|
EXPECT_FALSE(A > B);
|
|
|
|
EXPECT_TRUE(A <= B);
|
|
|
|
EXPECT_TRUE(A >= B);
|
|
|
|
|
|
|
|
EXPECT_FALSE(B == C);
|
|
|
|
EXPECT_TRUE(B != C);
|
|
|
|
EXPECT_FALSE(B < C);
|
|
|
|
EXPECT_TRUE(B > C);
|
|
|
|
EXPECT_FALSE(B <= C);
|
|
|
|
EXPECT_TRUE(B >= C);
|
2011-10-24 21:50:56 +08:00
|
|
|
|
|
|
|
BranchProbability BigZero(0, UINT32_MAX);
|
|
|
|
BranchProbability BigOne(UINT32_MAX, UINT32_MAX);
|
|
|
|
EXPECT_FALSE(BigZero == BigOne);
|
|
|
|
EXPECT_TRUE(BigZero != BigOne);
|
|
|
|
EXPECT_TRUE(BigZero < BigOne);
|
|
|
|
EXPECT_FALSE(BigZero > BigOne);
|
|
|
|
EXPECT_TRUE(BigZero <= BigOne);
|
|
|
|
EXPECT_FALSE(BigZero >= BigOne);
|
2011-10-23 19:19:14 +08:00
|
|
|
}
|
|
|
|
|
2011-07-28 02:57:40 +08:00
|
|
|
}
|