Clement Courbet | df79e79 | 2018-06-01 14:18:02 +0000 | [diff] [blame] | 1 | #include "Analysis.h" |
| 2 | |
| 3 | #include <cassert> |
| 4 | #include <memory> |
| 5 | |
| 6 | #include "llvm/Support/TargetRegistry.h" |
| 7 | #include "llvm/Support/TargetSelect.h" |
| 8 | #include "gmock/gmock.h" |
| 9 | #include "gtest/gtest.h" |
| 10 | |
| 11 | namespace exegesis { |
| 12 | namespace { |
| 13 | |
| 14 | using testing::Pair; |
| 15 | using testing::UnorderedElementsAre; |
| 16 | |
| 17 | class AnalysisTest : public ::testing::Test { |
| 18 | protected: |
| 19 | AnalysisTest() { |
| 20 | const std::string TT = "x86_64-unknown-linux"; |
| 21 | std::string error; |
| 22 | const llvm::Target *const TheTarget = |
| 23 | llvm::TargetRegistry::lookupTarget(TT, error); |
| 24 | if (!TheTarget) { |
| 25 | llvm::errs() << error << "\n"; |
| 26 | return; |
| 27 | } |
| 28 | STI.reset(TheTarget->createMCSubtargetInfo(TT, "haswell", "")); |
| 29 | |
| 30 | // Compute the ProxResIdx of ports unes in tests. |
| 31 | const auto &SM = STI->getSchedModel(); |
| 32 | for (unsigned I = 0, E = SM.getNumProcResourceKinds(); I < E; ++I) { |
| 33 | const std::string Name = SM.getProcResource(I)->Name; |
| 34 | if (Name == "HWPort0") { |
| 35 | P0Idx = I; |
| 36 | } else if (Name == "HWPort1") { |
| 37 | P1Idx = I; |
| 38 | } else if (Name == "HWPort5") { |
| 39 | P5Idx = I; |
| 40 | } else if (Name == "HWPort6") { |
| 41 | P6Idx = I; |
| 42 | } else if (Name == "HWPort05") { |
| 43 | P05Idx = I; |
| 44 | } else if (Name == "HWPort0156") { |
| 45 | P0156Idx = I; |
| 46 | } |
| 47 | } |
| 48 | EXPECT_NE(P0Idx, 0); |
| 49 | EXPECT_NE(P1Idx, 0); |
| 50 | EXPECT_NE(P5Idx, 0); |
| 51 | EXPECT_NE(P6Idx, 0); |
| 52 | EXPECT_NE(P05Idx, 0); |
| 53 | EXPECT_NE(P0156Idx, 0); |
| 54 | } |
| 55 | |
| 56 | static void SetUpTestCase() { |
| 57 | LLVMInitializeX86TargetInfo(); |
| 58 | LLVMInitializeX86Target(); |
| 59 | LLVMInitializeX86TargetMC(); |
| 60 | } |
| 61 | |
| 62 | protected: |
| 63 | std::unique_ptr<const llvm::MCSubtargetInfo> STI; |
| 64 | uint16_t P0Idx = 0; |
| 65 | uint16_t P1Idx = 0; |
| 66 | uint16_t P5Idx = 0; |
| 67 | uint16_t P6Idx = 0; |
| 68 | uint16_t P05Idx = 0; |
| 69 | uint16_t P0156Idx = 0; |
| 70 | }; |
| 71 | |
| 72 | TEST_F(AnalysisTest, ComputeIdealizedProcResPressure_2P0) { |
| 73 | const auto Pressure = |
| 74 | computeIdealizedProcResPressure(STI->getSchedModel(), {{P0Idx, 2}}); |
| 75 | EXPECT_THAT(Pressure, UnorderedElementsAre(Pair(P0Idx, 2.0))); |
| 76 | } |
| 77 | |
| 78 | TEST_F(AnalysisTest, ComputeIdealizedProcResPressure_2P05) { |
| 79 | const auto Pressure = |
| 80 | computeIdealizedProcResPressure(STI->getSchedModel(), {{P05Idx, 2}}); |
| 81 | EXPECT_THAT(Pressure, |
| 82 | UnorderedElementsAre(Pair(P0Idx, 1.0), Pair(P5Idx, 1.0))); |
| 83 | } |
| 84 | |
| 85 | TEST_F(AnalysisTest, ComputeIdealizedProcResPressure_2P05_2P0156) { |
| 86 | const auto Pressure = computeIdealizedProcResPressure( |
| 87 | STI->getSchedModel(), {{P05Idx, 2}, {P0156Idx, 2}}); |
| 88 | EXPECT_THAT(Pressure, |
| 89 | UnorderedElementsAre(Pair(P0Idx, 1.0), Pair(P1Idx, 1.0), |
| 90 | Pair(P5Idx, 1.0), Pair(P6Idx, 1.0))); |
| 91 | } |
| 92 | |
| 93 | TEST_F(AnalysisTest, ComputeIdealizedProcResPressure_1P1_1P05_2P0156) { |
| 94 | const auto Pressure = computeIdealizedProcResPressure( |
| 95 | STI->getSchedModel(), {{P1Idx, 1}, {P05Idx, 1}, {P0156Idx, 2}}); |
| 96 | EXPECT_THAT(Pressure, |
| 97 | UnorderedElementsAre(Pair(P0Idx, 1.0), Pair(P1Idx, 1.0), |
| 98 | Pair(P5Idx, 1.0), Pair(P6Idx, 1.0))); |
| 99 | } |
| 100 | |
| 101 | } // namespace |
| 102 | } // namespace exegesis |