summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp
blob: c55edff9b7eaca0a81fa3c8dad59b02936ed3bd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "Target.h"

#include <cassert>
#include <memory>

#include "MCTargetDesc/X86MCTargetDesc.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"

namespace exegesis {

void InitializeX86ExegesisTarget();

namespace {

using testing::Gt;
using testing::NotNull;
using testing::SizeIs;

class X86TargetTest : public ::testing::Test {
protected:
  X86TargetTest()
      : Target_(ExegesisTarget::lookup(llvm::Triple("x86_64-unknown-linux"))) {
    EXPECT_THAT(Target_, NotNull());
  }
  static void SetUpTestCase() { InitializeX86ExegesisTarget(); }

  const ExegesisTarget *const Target_;
};

TEST_F(X86TargetTest, SetRegToConstantGPR) {
  const auto Insts = Target_->setRegToConstant(llvm::X86::EAX);
  EXPECT_THAT(Insts, SizeIs(1));
  EXPECT_EQ(Insts[0].getOpcode(), llvm::X86::MOV32ri);
  EXPECT_EQ(Insts[0].getOperand(0).getReg(), llvm::X86::EAX);
}

TEST_F(X86TargetTest, SetRegToConstantXMM) {
  const auto Insts = Target_->setRegToConstant(llvm::X86::XMM1);
  EXPECT_THAT(Insts, SizeIs(Gt(0U)));
}

} // namespace
} // namespace exegesis
OpenPOWER on IntegriCloud