| 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 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
#include "Target.h" |
| 10 |
|
| 11 |
#include <cassert> |
| 12 |
#include <memory> |
| 13 |
|
| 14 |
#include "MCTargetDesc/PPCMCTargetDesc.h" |
| 15 |
#include "TestBase.h" |
| 16 |
#include "llvm/MC/TargetRegistry.h" |
| 17 |
#include "llvm/Support/TargetSelect.h" |
| 18 |
#include "gmock/gmock.h" |
| 19 |
#include "gtest/gtest.h" |
| 20 |
|
| 21 |
namespace llvm{ |
| 22 |
namespace exegesis { |
| 23 |
|
| 24 |
void InitializePowerPCExegesisTarget(); |
| 25 |
|
| 26 |
namespace { |
| 27 |
|
| 28 |
using testing::NotNull; |
| 29 |
using testing::IsEmpty; |
| 30 |
using testing::Not; |
| 31 |
|
| 32 |
constexpr const char kTriple[] = "powerpc64le-unknown-linux"; |
| 33 |
|
| 34 |
class PowerPCTargetTest : public PPCTestBase { |
| 35 |
protected: |
| 36 |
PowerPCTargetTest() |
| 37 |
: ExegesisTarget_(ExegesisTarget::lookup(Triple(kTriple))) { |
| 38 |
EXPECT_THAT(ExegesisTarget_, NotNull()); |
| 39 |
std::string error; |
| 40 |
Target_ = TargetRegistry::lookupTarget(kTriple, error); |
| 41 |
EXPECT_THAT(Target_, NotNull()); |
| 42 |
} |
| 43 |
|
| 44 |
const Target *Target_; |
| 45 |
const ExegesisTarget *const ExegesisTarget_; |
| 46 |
}; |
| 47 |
|
| 48 |
TEST_F(PowerPCTargetTest, SetRegToConstant) { |
| 49 |
const std::unique_ptr<MCSubtargetInfo> STI( |
| 50 |
Target_->createMCSubtargetInfo(kTriple, "generic", "")); |
| 51 |
const auto Insts = ExegesisTarget_->setRegTo(*STI, PPC::X0, APInt()); |
| 52 |
EXPECT_THAT(Insts, Not(IsEmpty())); |
| 53 |
} |
| 54 |
|
| 55 |
TEST_F(PowerPCTargetTest, DefaultPfmCounters) { |
| 56 |
const std::string Expected = "CYCLES"; |
| 57 |
EXPECT_EQ(ExegesisTarget_->getPfmCounters("").CycleCounter, Expected); |
| 58 |
EXPECT_EQ(ExegesisTarget_->getPfmCounters("unknown_cpu").CycleCounter, |
| 59 |
Expected); |
| 60 |
} |
| 61 |
|
| 62 |
} // namespace |
| 63 |
} // namespace exegesis |
| 64 |
} // namespace llvm |