[InstCombine] Signed saturation patterns
[llvm-complete.git] / unittests / tools / llvm-exegesis / AArch64 / TargetTest.cpp
blob5421c1704fb393fd09a10da886e14b7c4c7e5b86
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/AArch64MCTargetDesc.h"
15 #include "llvm/Support/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 InitializeAArch64ExegesisTarget();
25 namespace {
27 using testing::Gt;
28 using testing::IsEmpty;
29 using testing::Not;
30 using testing::NotNull;
32 constexpr const char kTriple[] = "aarch64-unknown-linux";
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*/ ""));
46 static void SetUpTestCase() {
47 LLVMInitializeAArch64TargetInfo();
48 LLVMInitializeAArch64Target();
49 LLVMInitializeAArch64TargetMC();
50 InitializeAArch64ExegesisTarget();
53 std::vector<MCInst> setRegTo(unsigned Reg, const APInt &Value) {
54 return ExegesisTarget_->setRegTo(*STI_, Reg, Value);
57 const Target *Target_;
58 const ExegesisTarget *const ExegesisTarget_;
59 std::unique_ptr<MCSubtargetInfo> STI_;
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()));
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);
75 } // namespace
76 } // namespace exegesis
77 } // namespace llvm