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