| 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/AArch64MCTargetDesc.h" |
| 15 |
#include "llvm/MC/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 |
|
| 23 |
void InitializeAArch64ExegesisTarget(); |
| 24 |
|
| 25 |
namespace { |
| 26 |
|
| 27 |
using testing::Gt; |
| 28 |
using testing::IsEmpty; |
| 29 |
using testing::Not; |
| 30 |
using testing::NotNull; |
| 31 |
|
| 32 |
constexpr const char kTriple[] = "aarch64-unknown-linux"; |
| 33 |
|
| 34 |
class AArch64TargetTest : public ::testing::Test { |
| 35 |
protected: |
| 36 |
AArch64TargetTest() |
| 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 |
STI_.reset( |
| 43 |
Target_->createMCSubtargetInfo(kTriple, "generic", /*no features*/ "")); |
| 44 |
} |
| 45 |
|
| 46 |
static void SetUpTestCase() { |
| 47 |
LLVMInitializeAArch64TargetInfo(); |
| 48 |
LLVMInitializeAArch64Target(); |
| 49 |
LLVMInitializeAArch64TargetMC(); |
| 50 |
InitializeAArch64ExegesisTarget(); |
| 51 |
} |
| 52 |
|
| 53 |
std::vector<MCInst> setRegTo(unsigned Reg, const APInt &Value) { |
| 54 |
return ExegesisTarget_->setRegTo(*STI_, Reg, Value); |
| 55 |
} |
| 56 |
|
| 57 |
const Target *Target_; |
| 58 |
const ExegesisTarget *const ExegesisTarget_; |
| 59 |
std::unique_ptr<MCSubtargetInfo> STI_; |
| 60 |
}; |
| 61 |
|
| 62 |
TEST_F(AArch64TargetTest, SetRegToConstant) { |
| 63 |
// The AArch64 target currently doesn't know how to set register values. |
| 64 |
const auto Insts = setRegTo(AArch64::X0, APInt()); |
| 65 |
EXPECT_THAT(Insts, Not(IsEmpty())); |
| 66 |
} |
| 67 |
|
| 68 |
TEST_F(AArch64TargetTest, DefaultPfmCounters) { |
| 69 |
const std::string Expected = "CPU_CYCLES"; |
| 70 |
EXPECT_EQ(ExegesisTarget_->getPfmCounters("").CycleCounter, Expected); |
| 71 |
EXPECT_EQ(ExegesisTarget_->getPfmCounters("unknown_cpu").CycleCounter, |
| 72 |
Expected); |
| 73 |
} |
| 74 |
|
| 75 |
} // namespace |
| 76 |
} // namespace exegesis |
| 77 |
} // namespace llvm |