[docs] Fix build-docs.sh
[llvm-project.git] / llvm / unittests / tools / llvm-exegesis / PowerPC / TargetTest.cpp
blobc3107ee4ec0eb2b1b62e0dcdc129b00c4d7b1be5
1 //===-- TargetTest.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-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "Target.h"
11 #include <cassert>
12 #include <memory>
14 #include "MCTargetDesc/PPCMCTargetDesc.h"
15 #include "llvm/MC/TargetRegistry.h"
16 #include "llvm/Support/TargetSelect.h"
17 #include "gmock/gmock.h"
18 #include "gtest/gtest.h"
20 namespace llvm{
21 namespace exegesis {
23 void InitializePowerPCExegesisTarget();
25 namespace {
27 using testing::NotNull;
28 using testing::IsEmpty;
29 using testing::Not;
31 constexpr const char kTriple[] = "powerpc64le-unknown-linux";
33 class PowerPCTargetTest : public ::testing::Test {
34 protected:
35 PowerPCTargetTest()
36 : ExegesisTarget_(ExegesisTarget::lookup(Triple(kTriple))) {
37 EXPECT_THAT(ExegesisTarget_, NotNull());
38 std::string error;
39 Target_ = TargetRegistry::lookupTarget(kTriple, error);
40 EXPECT_THAT(Target_, NotNull());
42 static void SetUpTestCase() {
43 LLVMInitializePowerPCTargetInfo();
44 LLVMInitializePowerPCTarget();
45 LLVMInitializePowerPCTargetMC();
46 InitializePowerPCExegesisTarget();
49 const Target *Target_;
50 const ExegesisTarget *const ExegesisTarget_;
53 TEST_F(PowerPCTargetTest, SetRegToConstant) {
54 const std::unique_ptr<MCSubtargetInfo> STI(
55 Target_->createMCSubtargetInfo(kTriple, "generic", ""));
56 const auto Insts = ExegesisTarget_->setRegTo(*STI, PPC::X0, APInt());
57 EXPECT_THAT(Insts, Not(IsEmpty()));
60 TEST_F(PowerPCTargetTest, DefaultPfmCounters) {
61 const std::string Expected = "CYCLES";
62 EXPECT_EQ(ExegesisTarget_->getPfmCounters("").CycleCounter, Expected);
63 EXPECT_EQ(ExegesisTarget_->getPfmCounters("unknown_cpu").CycleCounter,
64 Expected);
67 } // namespace
68 } // namespace exegesis
69 } // namespace llvm