summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/tools
diff options
context:
space:
mode:
authorJinsong Ji <jji@us.ibm.com>2018-11-08 16:51:42 +0000
committerJinsong Ji <jji@us.ibm.com>2018-11-08 16:51:42 +0000
commit5fd3e754786c394b735555119432e305521fe9ca (patch)
treeaa768085683cd8a8664493dd7ec8fe96d53f5889 /llvm/unittests/tools
parentac8279ab8bbfd0e1af2c4815391aaf90cf548a33 (diff)
downloadbcm5719-llvm-5fd3e754786c394b735555119432e305521fe9ca.tar.gz
bcm5719-llvm-5fd3e754786c394b735555119432e305521fe9ca.zip
[PowerPC][llvm-exegesis] Add a PowerPC target
This is patch to add PowerPC target to llvm-exegesis. The target does just enough to be able to run llvm-exegesis in latency mode for at least some opcodes. Differential Revision: https://reviews.llvm.org/D54185 llvm-svn: 346411
Diffstat (limited to 'llvm/unittests/tools')
-rw-r--r--llvm/unittests/tools/llvm-exegesis/CMakeLists.txt3
-rw-r--r--llvm/unittests/tools/llvm-exegesis/PowerPC/AnalysisTest.cpp93
-rw-r--r--llvm/unittests/tools/llvm-exegesis/PowerPC/CMakeLists.txt22
-rw-r--r--llvm/unittests/tools/llvm-exegesis/PowerPC/TargetTest.cpp64
4 files changed, 182 insertions, 0 deletions
diff --git a/llvm/unittests/tools/llvm-exegesis/CMakeLists.txt b/llvm/unittests/tools/llvm-exegesis/CMakeLists.txt
index 1b373161041..05b2b3bc605 100644
--- a/llvm/unittests/tools/llvm-exegesis/CMakeLists.txt
+++ b/llvm/unittests/tools/llvm-exegesis/CMakeLists.txt
@@ -27,3 +27,6 @@ endif()
if(LLVM_TARGETS_TO_BUILD MATCHES "AArch64")
add_subdirectory(AArch64)
endif()
+if(LLVM_TARGETS_TO_BUILD MATCHES "PowerPC")
+ add_subdirectory(PowerPC)
+endif()
diff --git a/llvm/unittests/tools/llvm-exegesis/PowerPC/AnalysisTest.cpp b/llvm/unittests/tools/llvm-exegesis/PowerPC/AnalysisTest.cpp
new file mode 100644
index 00000000000..15d81ca88de
--- /dev/null
+++ b/llvm/unittests/tools/llvm-exegesis/PowerPC/AnalysisTest.cpp
@@ -0,0 +1,93 @@
+//===-- AnalysisTest.cpp ---------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "Analysis.h"
+
+#include <cassert>
+#include <memory>
+
+#include "llvm/Support/TargetRegistry.h"
+#include "llvm/Support/TargetSelect.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace llvm{
+namespace exegesis {
+namespace {
+
+using testing::Pair;
+using testing::UnorderedElementsAre;
+
+class AnalysisTest : public ::testing::Test {
+protected:
+ AnalysisTest() {
+ const std::string TT = "powerpc64le-unknown-linux";
+ std::string error;
+ const llvm::Target *const TheTarget =
+ llvm::TargetRegistry::lookupTarget(TT, error);
+ if (!TheTarget) {
+ llvm::errs() << error << "\n";
+ return;
+ }
+ STI.reset(TheTarget->createMCSubtargetInfo(TT, "pwr9", ""));
+
+ // Compute the ProxResIdx of ports uses in tests.
+ const auto &SM = STI->getSchedModel();
+ for (unsigned I = 0, E = SM.getNumProcResourceKinds(); I < E; ++I) {
+ const std::string Name = SM.getProcResource(I)->Name;
+ if (Name == "ALU") {
+ ALUIdx = I;
+ } else if (Name == "ALUE") {
+ ALUEIdx = I;
+ } else if (Name == "ALUO") {
+ ALUOIdx = I;
+ } else if (Name == "IP_AGEN") {
+ IPAGENIdx = I;
+ }
+ }
+ EXPECT_NE(ALUIdx, 0);
+ EXPECT_NE(ALUEIdx, 0);
+ EXPECT_NE(ALUOIdx, 0);
+ EXPECT_NE(IPAGENIdx, 0);
+ }
+
+ static void SetUpTestCase() {
+ LLVMInitializePowerPCTargetInfo();
+ LLVMInitializePowerPCTarget();
+ LLVMInitializePowerPCTargetMC();
+ }
+
+protected:
+ std::unique_ptr<const llvm::MCSubtargetInfo> STI;
+ uint16_t ALUIdx = 0;
+ uint16_t ALUEIdx = 0;
+ uint16_t ALUOIdx = 0;
+ uint16_t IPAGENIdx = 0;
+};
+
+TEST_F(AnalysisTest, ComputeIdealizedProcResPressure_2ALU) {
+ const auto Pressure =
+ computeIdealizedProcResPressure(STI->getSchedModel(), {{ALUIdx, 2}});
+ EXPECT_THAT(Pressure, UnorderedElementsAre(Pair(ALUIdx, 2.0)));
+}
+
+TEST_F(AnalysisTest, ComputeIdealizedProcResPressure_1ALUE) {
+ const auto Pressure =
+ computeIdealizedProcResPressure(STI->getSchedModel(), {{ALUEIdx, 2}});
+ EXPECT_THAT(Pressure, UnorderedElementsAre(Pair(ALUEIdx, 2.0)));
+}
+
+TEST_F(AnalysisTest, ComputeIdealizedProcResPressure_1ALU1IPAGEN) {
+ const auto Pressure =
+ computeIdealizedProcResPressure(STI->getSchedModel(), {{ALUIdx, 1}, {IPAGENIdx, 1}});
+ EXPECT_THAT(Pressure, UnorderedElementsAre(Pair(ALUIdx, 1.0),Pair(IPAGENIdx, 1)));
+}
+} // namespace
+} // namespace exegesis
+} // namespace llvm
diff --git a/llvm/unittests/tools/llvm-exegesis/PowerPC/CMakeLists.txt b/llvm/unittests/tools/llvm-exegesis/PowerPC/CMakeLists.txt
new file mode 100644
index 00000000000..e8a53e3692a
--- /dev/null
+++ b/llvm/unittests/tools/llvm-exegesis/PowerPC/CMakeLists.txt
@@ -0,0 +1,22 @@
+include_directories(
+ ${LLVM_MAIN_SRC_DIR}/lib/Target/PowerPC
+ ${LLVM_BINARY_DIR}/lib/Target/PowerPC
+ ${LLVM_MAIN_SRC_DIR}/tools/llvm-exegesis/lib
+ )
+
+set(LLVM_LINK_COMPONENTS
+ MC
+ MCParser
+ Object
+ Support
+ Symbolize
+ PowerPC
+ )
+
+add_llvm_unittest(LLVMExegesisPowerPCTests
+ AnalysisTest.cpp
+ TargetTest.cpp
+ )
+target_link_libraries(LLVMExegesisPowerPCTests PRIVATE
+ LLVMExegesis
+ LLVMExegesisPowerPC)
diff --git a/llvm/unittests/tools/llvm-exegesis/PowerPC/TargetTest.cpp b/llvm/unittests/tools/llvm-exegesis/PowerPC/TargetTest.cpp
new file mode 100644
index 00000000000..e9f6a55af57
--- /dev/null
+++ b/llvm/unittests/tools/llvm-exegesis/PowerPC/TargetTest.cpp
@@ -0,0 +1,64 @@
+//===-- TargetTest.cpp ---------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "Target.h"
+
+#include <cassert>
+#include <memory>
+
+#include "MCTargetDesc/PPCMCTargetDesc.h"
+#include "llvm/Support/TargetRegistry.h"
+#include "llvm/Support/TargetSelect.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace llvm{
+namespace exegesis {
+
+void InitializePowerPCExegesisTarget();
+
+namespace {
+
+using testing::NotNull;
+using testing::IsEmpty;
+using testing::Not;
+
+constexpr const char kTriple[] = "powerpc64le-unknown-linux";
+
+class PowerPCTargetTest : public ::testing::Test {
+protected:
+ PowerPCTargetTest()
+ : ExegesisTarget_(ExegesisTarget::lookup(llvm::Triple(kTriple))) {
+ EXPECT_THAT(ExegesisTarget_, NotNull());
+ std::string error;
+ Target_ = llvm::TargetRegistry::lookupTarget(kTriple, error);
+ EXPECT_THAT(Target_, NotNull());
+ }
+ static void SetUpTestCase() {
+ LLVMInitializePowerPCTargetInfo();
+ LLVMInitializePowerPCTarget();
+ LLVMInitializePowerPCTargetMC();
+ InitializePowerPCExegesisTarget();
+ }
+
+ const llvm::Target *Target_;
+ const ExegesisTarget *const ExegesisTarget_;
+};
+
+TEST_F(PowerPCTargetTest, SetRegToConstant) {
+ const std::unique_ptr<llvm::MCSubtargetInfo> STI(
+ Target_->createMCSubtargetInfo(kTriple, "generic", ""));
+ const auto Insts =
+ ExegesisTarget_->setRegTo(*STI, llvm::PPC::X0, llvm::APInt());
+ EXPECT_THAT(Insts, Not(IsEmpty()));
+}
+
+} // namespace
+} // namespace exegesis
+} // namespace llvm
OpenPOWER on IntegriCloud