1 //===-- SchedClassResolutionTest.cpp ----------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "SchedClassResolution.h"
14 #include "llvm/Support/TargetRegistry.h"
15 #include "llvm/Support/TargetSelect.h"
16 #include "gmock/gmock.h"
17 #include "gtest/gtest.h"
24 using testing::UnorderedElementsAre
;
26 class SchedClassResolutionTest
: public ::testing::Test
{
28 SchedClassResolutionTest() {
29 const std::string TT
= "x86_64-unknown-linux";
31 const llvm::Target
*const TheTarget
=
32 llvm::TargetRegistry::lookupTarget(TT
, error
);
34 llvm::errs() << error
<< "\n";
37 STI
.reset(TheTarget
->createMCSubtargetInfo(TT
, "haswell", ""));
39 // Compute the ProxResIdx of ports uses in tests.
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") {
45 } else if (Name
== "HWPort1") {
47 } else if (Name
== "HWPort5") {
49 } else if (Name
== "HWPort6") {
51 } else if (Name
== "HWPort05") {
53 } else if (Name
== "HWPort0156") {
62 EXPECT_NE(P0156Idx
, 0);
65 static void SetUpTestCase() {
66 LLVMInitializeX86TargetInfo();
67 LLVMInitializeX86Target();
68 LLVMInitializeX86TargetMC();
72 std::unique_ptr
<const llvm::MCSubtargetInfo
> STI
;
78 uint16_t P0156Idx
= 0;
81 TEST_F(SchedClassResolutionTest
, ComputeIdealizedProcResPressure_2P0
) {
83 computeIdealizedProcResPressure(STI
->getSchedModel(), {{P0Idx
, 2}});
84 EXPECT_THAT(Pressure
, UnorderedElementsAre(Pair(P0Idx
, 2.0)));
87 TEST_F(SchedClassResolutionTest
, ComputeIdealizedProcResPressure_2P05
) {
89 computeIdealizedProcResPressure(STI
->getSchedModel(), {{P05Idx
, 2}});
91 UnorderedElementsAre(Pair(P0Idx
, 1.0), Pair(P5Idx
, 1.0)));
94 TEST_F(SchedClassResolutionTest
, ComputeIdealizedProcResPressure_2P05_2P0156
) {
95 const auto Pressure
= computeIdealizedProcResPressure(
96 STI
->getSchedModel(), {{P05Idx
, 2}, {P0156Idx
, 2}});
98 UnorderedElementsAre(Pair(P0Idx
, 1.0), Pair(P1Idx
, 1.0),
99 Pair(P5Idx
, 1.0), Pair(P6Idx
, 1.0)));
102 TEST_F(SchedClassResolutionTest
,
103 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)));
112 } // namespace exegesis