1dbefcde6STom Stellard //===-- PPCAnalysisTest.cpp ---------------------------------------*- C++ -*-===//
25fd3e754SJinsong Ji //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65fd3e754SJinsong Ji //
75fd3e754SJinsong Ji //===----------------------------------------------------------------------===//
85fd3e754SJinsong Ji
95fd3e754SJinsong Ji #include "Analysis.h"
105fd3e754SJinsong Ji
115fd3e754SJinsong Ji #include <cassert>
125fd3e754SJinsong Ji #include <memory>
135fd3e754SJinsong Ji
1489b57061SReid Kleckner #include "llvm/MC/TargetRegistry.h"
155fd3e754SJinsong Ji #include "llvm/Support/TargetSelect.h"
165fd3e754SJinsong Ji #include "gmock/gmock.h"
175fd3e754SJinsong Ji #include "gtest/gtest.h"
185fd3e754SJinsong Ji
195fd3e754SJinsong Ji namespace llvm{
205fd3e754SJinsong Ji namespace exegesis {
215fd3e754SJinsong Ji namespace {
225fd3e754SJinsong Ji
235fd3e754SJinsong Ji using testing::Pair;
245fd3e754SJinsong Ji using testing::UnorderedElementsAre;
255fd3e754SJinsong Ji
26dbefcde6STom Stellard class PPCAnalysisTest : public ::testing::Test {
275fd3e754SJinsong Ji protected:
PPCAnalysisTest()28dbefcde6STom Stellard PPCAnalysisTest() {
295fd3e754SJinsong Ji const std::string TT = "powerpc64le-unknown-linux";
305fd3e754SJinsong Ji std::string error;
31d422d3a7SClement Courbet const Target *const TheTarget = TargetRegistry::lookupTarget(TT, error);
325fd3e754SJinsong Ji if (!TheTarget) {
33d422d3a7SClement Courbet errs() << error << "\n";
345fd3e754SJinsong Ji return;
355fd3e754SJinsong Ji }
365fd3e754SJinsong Ji STI.reset(TheTarget->createMCSubtargetInfo(TT, "pwr9", ""));
375fd3e754SJinsong Ji
385fd3e754SJinsong Ji // Compute the ProxResIdx of ports uses in tests.
395fd3e754SJinsong Ji const auto &SM = STI->getSchedModel();
405fd3e754SJinsong Ji for (unsigned I = 0, E = SM.getNumProcResourceKinds(); I < E; ++I) {
415fd3e754SJinsong Ji const std::string Name = SM.getProcResource(I)->Name;
425fd3e754SJinsong Ji if (Name == "ALU") {
435fd3e754SJinsong Ji ALUIdx = I;
445fd3e754SJinsong Ji } else if (Name == "ALUE") {
455fd3e754SJinsong Ji ALUEIdx = I;
465fd3e754SJinsong Ji } else if (Name == "ALUO") {
475fd3e754SJinsong Ji ALUOIdx = I;
485fd3e754SJinsong Ji } else if (Name == "IP_AGEN") {
495fd3e754SJinsong Ji IPAGENIdx = I;
505fd3e754SJinsong Ji }
515fd3e754SJinsong Ji }
525fd3e754SJinsong Ji EXPECT_NE(ALUIdx, 0);
535fd3e754SJinsong Ji EXPECT_NE(ALUEIdx, 0);
545fd3e754SJinsong Ji EXPECT_NE(ALUOIdx, 0);
555fd3e754SJinsong Ji EXPECT_NE(IPAGENIdx, 0);
565fd3e754SJinsong Ji }
575fd3e754SJinsong Ji
SetUpTestCase()585fd3e754SJinsong Ji static void SetUpTestCase() {
595fd3e754SJinsong Ji LLVMInitializePowerPCTargetInfo();
605fd3e754SJinsong Ji LLVMInitializePowerPCTarget();
615fd3e754SJinsong Ji LLVMInitializePowerPCTargetMC();
625fd3e754SJinsong Ji }
635fd3e754SJinsong Ji
645fd3e754SJinsong Ji protected:
65d422d3a7SClement Courbet std::unique_ptr<const MCSubtargetInfo> STI;
665fd3e754SJinsong Ji uint16_t ALUIdx = 0;
675fd3e754SJinsong Ji uint16_t ALUEIdx = 0;
685fd3e754SJinsong Ji uint16_t ALUOIdx = 0;
695fd3e754SJinsong Ji uint16_t IPAGENIdx = 0;
705fd3e754SJinsong Ji };
715fd3e754SJinsong Ji
TEST_F(PPCAnalysisTest,ComputeIdealizedProcResPressure_2ALU)72dbefcde6STom Stellard TEST_F(PPCAnalysisTest, ComputeIdealizedProcResPressure_2ALU) {
735fd3e754SJinsong Ji const auto Pressure =
74*930421e1SFrancesco Petrogalli computeIdealizedProcResPressure(STI->getSchedModel(), {{ALUIdx, 2, 0}});
755fd3e754SJinsong Ji EXPECT_THAT(Pressure, UnorderedElementsAre(Pair(ALUIdx, 2.0)));
765fd3e754SJinsong Ji }
775fd3e754SJinsong Ji
TEST_F(PPCAnalysisTest,ComputeIdealizedProcResPressure_1ALUE)78dbefcde6STom Stellard TEST_F(PPCAnalysisTest, ComputeIdealizedProcResPressure_1ALUE) {
795fd3e754SJinsong Ji const auto Pressure =
80*930421e1SFrancesco Petrogalli computeIdealizedProcResPressure(STI->getSchedModel(), {{ALUEIdx, 2, 0}});
815fd3e754SJinsong Ji EXPECT_THAT(Pressure, UnorderedElementsAre(Pair(ALUEIdx, 2.0)));
825fd3e754SJinsong Ji }
835fd3e754SJinsong Ji
TEST_F(PPCAnalysisTest,ComputeIdealizedProcResPressure_1ALU1IPAGEN)84dbefcde6STom Stellard TEST_F(PPCAnalysisTest, ComputeIdealizedProcResPressure_1ALU1IPAGEN) {
85*930421e1SFrancesco Petrogalli const auto Pressure = computeIdealizedProcResPressure(
86*930421e1SFrancesco Petrogalli STI->getSchedModel(), {{ALUIdx, 1, 0}, {IPAGENIdx, 1, 0}});
875fd3e754SJinsong Ji EXPECT_THAT(Pressure, UnorderedElementsAre(Pair(ALUIdx, 1.0),Pair(IPAGENIdx, 1)));
885fd3e754SJinsong Ji }
895fd3e754SJinsong Ji } // namespace
905fd3e754SJinsong Ji } // namespace exegesis
915fd3e754SJinsong Ji } // namespace llvm
92