1 //===-- PPCAnalysisTest.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 //===----------------------------------------------------------------------===//
14 #include "llvm/MC/TargetRegistry.h"
15 #include "llvm/Support/TargetSelect.h"
16 #include "gmock/gmock.h"
17 #include "gtest/gtest.h"
24 using testing::UnorderedElementsAre
;
26 class PPCAnalysisTest
: public ::testing::Test
{
29 const std::string TT
= "powerpc64le-unknown-linux";
31 const Target
*const TheTarget
= TargetRegistry::lookupTarget(TT
, error
);
33 errs() << error
<< "\n";
36 STI
.reset(TheTarget
->createMCSubtargetInfo(TT
, "pwr9", ""));
38 // Compute the ProxResIdx of ports uses in tests.
39 const auto &SM
= STI
->getSchedModel();
40 for (unsigned I
= 0, E
= SM
.getNumProcResourceKinds(); I
< E
; ++I
) {
41 const std::string Name
= SM
.getProcResource(I
)->Name
;
44 } else if (Name
== "ALUE") {
46 } else if (Name
== "ALUO") {
48 } else if (Name
== "IP_AGEN") {
53 EXPECT_NE(ALUEIdx
, 0);
54 EXPECT_NE(ALUOIdx
, 0);
55 EXPECT_NE(IPAGENIdx
, 0);
58 static void SetUpTestCase() {
59 LLVMInitializePowerPCTargetInfo();
60 LLVMInitializePowerPCTarget();
61 LLVMInitializePowerPCTargetMC();
65 std::unique_ptr
<const MCSubtargetInfo
> STI
;
69 uint16_t IPAGENIdx
= 0;
72 TEST_F(PPCAnalysisTest
, ComputeIdealizedProcResPressure_2ALU
) {
74 computeIdealizedProcResPressure(STI
->getSchedModel(), {{ALUIdx
, 2}});
75 EXPECT_THAT(Pressure
, UnorderedElementsAre(Pair(ALUIdx
, 2.0)));
78 TEST_F(PPCAnalysisTest
, ComputeIdealizedProcResPressure_1ALUE
) {
80 computeIdealizedProcResPressure(STI
->getSchedModel(), {{ALUEIdx
, 2}});
81 EXPECT_THAT(Pressure
, UnorderedElementsAre(Pair(ALUEIdx
, 2.0)));
84 TEST_F(PPCAnalysisTest
, ComputeIdealizedProcResPressure_1ALU1IPAGEN
) {
86 computeIdealizedProcResPressure(STI
->getSchedModel(), {{ALUIdx
, 1}, {IPAGENIdx
, 1}});
87 EXPECT_THAT(Pressure
, UnorderedElementsAre(Pair(ALUIdx
, 1.0),Pair(IPAGENIdx
, 1)));
90 } // namespace exegesis