93 lines · cpp
1//===-- PPCAnalysisTest.cpp ---------------------------------------*- C++ -*-===//2//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "Analysis.h"10 11#include <cassert>12#include <memory>13 14#include "llvm/MC/TargetRegistry.h"15#include "llvm/Support/TargetSelect.h"16#include "gmock/gmock.h"17#include "gtest/gtest.h"18 19namespace llvm{20namespace exegesis {21namespace {22 23using testing::Pair;24using testing::UnorderedElementsAre;25 26class PPCAnalysisTest : public ::testing::Test {27protected:28 PPCAnalysisTest() {29 const StringRef TripleName = "powerpc64le-unknown-linux";30 const Triple TT(TripleName);31 std::string error;32 const Target *const TheTarget = TargetRegistry::lookupTarget(TT, error);33 if (!TheTarget) {34 errs() << error << "\n";35 return;36 }37 STI.reset(TheTarget->createMCSubtargetInfo(TT, "pwr9", ""));38 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 == "ALU") {44 ALUIdx = I;45 } else if (Name == "ALUE") {46 ALUEIdx = I;47 } else if (Name == "ALUO") {48 ALUOIdx = I;49 } else if (Name == "IP_AGEN") {50 IPAGENIdx = I;51 }52 }53 EXPECT_NE(ALUIdx, 0);54 EXPECT_NE(ALUEIdx, 0);55 EXPECT_NE(ALUOIdx, 0);56 EXPECT_NE(IPAGENIdx, 0);57 }58 59 static void SetUpTestCase() {60 LLVMInitializePowerPCTargetInfo();61 LLVMInitializePowerPCTarget();62 LLVMInitializePowerPCTargetMC();63 }64 65protected:66 std::unique_ptr<const MCSubtargetInfo> STI;67 uint16_t ALUIdx = 0;68 uint16_t ALUEIdx = 0;69 uint16_t ALUOIdx = 0;70 uint16_t IPAGENIdx = 0;71};72 73TEST_F(PPCAnalysisTest, ComputeIdealizedProcResPressure_2ALU) {74 const auto Pressure =75 computeIdealizedProcResPressure(STI->getSchedModel(), {{ALUIdx, 2, 0}});76 EXPECT_THAT(Pressure, UnorderedElementsAre(Pair(ALUIdx, 2.0)));77}78 79TEST_F(PPCAnalysisTest, ComputeIdealizedProcResPressure_1ALUE) {80 const auto Pressure =81 computeIdealizedProcResPressure(STI->getSchedModel(), {{ALUEIdx, 2, 0}});82 EXPECT_THAT(Pressure, UnorderedElementsAre(Pair(ALUEIdx, 2.0)));83}84 85TEST_F(PPCAnalysisTest, ComputeIdealizedProcResPressure_1ALU1IPAGEN) {86 const auto Pressure = computeIdealizedProcResPressure(87 STI->getSchedModel(), {{ALUIdx, 1, 0}, {IPAGENIdx, 1, 0}});88 EXPECT_THAT(Pressure, UnorderedElementsAre(Pair(ALUIdx, 1.0),Pair(IPAGENIdx, 1)));89}90} // namespace91} // namespace exegesis92} // namespace llvm93