1 //===-- AnalysisTest.cpp ---------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "Analysis.h" 11 12 #include <cassert> 13 #include <memory> 14 15 #include "llvm/Support/TargetRegistry.h" 16 #include "llvm/Support/TargetSelect.h" 17 #include "gmock/gmock.h" 18 #include "gtest/gtest.h" 19 20 namespace llvm{ 21 namespace exegesis { 22 namespace { 23 24 using testing::Pair; 25 using testing::UnorderedElementsAre; 26 27 class AnalysisTest : public ::testing::Test { 28 protected: 29 AnalysisTest() { 30 const std::string TT = "powerpc64le-unknown-linux"; 31 std::string error; 32 const llvm::Target *const TheTarget = 33 llvm::TargetRegistry::lookupTarget(TT, error); 34 if (!TheTarget) { 35 llvm::errs() << error << "\n"; 36 return; 37 } 38 STI.reset(TheTarget->createMCSubtargetInfo(TT, "pwr9", "")); 39 40 // Compute the ProxResIdx of ports uses in tests. 41 const auto &SM = STI->getSchedModel(); 42 for (unsigned I = 0, E = SM.getNumProcResourceKinds(); I < E; ++I) { 43 const std::string Name = SM.getProcResource(I)->Name; 44 if (Name == "ALU") { 45 ALUIdx = I; 46 } else if (Name == "ALUE") { 47 ALUEIdx = I; 48 } else if (Name == "ALUO") { 49 ALUOIdx = I; 50 } else if (Name == "IP_AGEN") { 51 IPAGENIdx = I; 52 } 53 } 54 EXPECT_NE(ALUIdx, 0); 55 EXPECT_NE(ALUEIdx, 0); 56 EXPECT_NE(ALUOIdx, 0); 57 EXPECT_NE(IPAGENIdx, 0); 58 } 59 60 static void SetUpTestCase() { 61 LLVMInitializePowerPCTargetInfo(); 62 LLVMInitializePowerPCTarget(); 63 LLVMInitializePowerPCTargetMC(); 64 } 65 66 protected: 67 std::unique_ptr<const llvm::MCSubtargetInfo> STI; 68 uint16_t ALUIdx = 0; 69 uint16_t ALUEIdx = 0; 70 uint16_t ALUOIdx = 0; 71 uint16_t IPAGENIdx = 0; 72 }; 73 74 TEST_F(AnalysisTest, ComputeIdealizedProcResPressure_2ALU) { 75 const auto Pressure = 76 computeIdealizedProcResPressure(STI->getSchedModel(), {{ALUIdx, 2}}); 77 EXPECT_THAT(Pressure, UnorderedElementsAre(Pair(ALUIdx, 2.0))); 78 } 79 80 TEST_F(AnalysisTest, ComputeIdealizedProcResPressure_1ALUE) { 81 const auto Pressure = 82 computeIdealizedProcResPressure(STI->getSchedModel(), {{ALUEIdx, 2}}); 83 EXPECT_THAT(Pressure, UnorderedElementsAre(Pair(ALUEIdx, 2.0))); 84 } 85 86 TEST_F(AnalysisTest, ComputeIdealizedProcResPressure_1ALU1IPAGEN) { 87 const auto Pressure = 88 computeIdealizedProcResPressure(STI->getSchedModel(), {{ALUIdx, 1}, {IPAGENIdx, 1}}); 89 EXPECT_THAT(Pressure, UnorderedElementsAre(Pair(ALUIdx, 1.0),Pair(IPAGENIdx, 1))); 90 } 91 } // namespace 92 } // namespace exegesis 93 } // namespace llvm 94