blob: 9e745461142d40b7eb42229b866bccc9e000d966 [file] [log] [blame]
Roman Lebedev1d1330c2019-03-29 14:24:27 +00001//===-- SchedClassResolutionTest.cpp ----------------------------*- C++ -*-===//
Jinsong Ji56c74cf2018-11-20 14:41:59 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Ji56c74cf2018-11-20 14:41:59 +00006//
7//===----------------------------------------------------------------------===//
8
Roman Lebedev1d1330c2019-03-29 14:24:27 +00009#include "SchedClassResolution.h"
Clement Courbetdf79e792018-06-01 14:18:02 +000010
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 Song32401af2018-10-22 17:10:47 +000019namespace llvm {
Clement Courbetdf79e792018-06-01 14:18:02 +000020namespace exegesis {
21namespace {
22
23using testing::Pair;
24using testing::UnorderedElementsAre;
25
Roman Lebedev1d1330c2019-03-29 14:24:27 +000026class SchedClassResolutionTest : public ::testing::Test {
Clement Courbetdf79e792018-06-01 14:18:02 +000027protected:
Roman Lebedev1d1330c2019-03-29 14:24:27 +000028 SchedClassResolutionTest() {
Clement Courbetdf79e792018-06-01 14:18:02 +000029 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 Ji56c74cf2018-11-20 14:41:59 +000039 // Compute the ProxResIdx of ports uses in tests.
Clement Courbetdf79e792018-06-01 14:18:02 +000040 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
71protected:
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 Lebedev1d1330c2019-03-29 14:24:27 +000081TEST_F(SchedClassResolutionTest, ComputeIdealizedProcResPressure_2P0) {
Clement Courbetdf79e792018-06-01 14:18:02 +000082 const auto Pressure =
83 computeIdealizedProcResPressure(STI->getSchedModel(), {{P0Idx, 2}});
84 EXPECT_THAT(Pressure, UnorderedElementsAre(Pair(P0Idx, 2.0)));
85}
86
Roman Lebedev1d1330c2019-03-29 14:24:27 +000087TEST_F(SchedClassResolutionTest, ComputeIdealizedProcResPressure_2P05) {
Clement Courbetdf79e792018-06-01 14:18:02 +000088 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 Lebedev1d1330c2019-03-29 14:24:27 +000094TEST_F(SchedClassResolutionTest, ComputeIdealizedProcResPressure_2P05_2P0156) {
Clement Courbetdf79e792018-06-01 14:18:02 +000095 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 Lebedev1d1330c2019-03-29 14:24:27 +0000102TEST_F(SchedClassResolutionTest,
103 ComputeIdealizedProcResPressure_1P1_1P05_2P0156) {
Clement Courbetdf79e792018-06-01 14:18:02 +0000104 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 Song32401af2018-10-22 17:10:47 +0000113} // namespace llvm