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