John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 1 | #include "Target.h" |
| 2 | |
| 3 | #include <cassert> |
| 4 | #include <memory> |
| 5 | |
| 6 | #include "MCTargetDesc/AArch64MCTargetDesc.h" |
John Brawn | b371ccc | 2018-07-03 10:52:20 +0000 | [diff] [blame] | 7 | #include "llvm/Support/TargetRegistry.h" |
| 8 | #include "llvm/Support/TargetSelect.h" |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 9 | #include "gmock/gmock.h" |
| 10 | #include "gtest/gtest.h" |
| 11 | |
Fangrui Song | 32401af | 2018-10-22 17:10:47 +0000 | [diff] [blame] | 12 | namespace llvm { |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 13 | namespace exegesis { |
| 14 | |
| 15 | void InitializeAArch64ExegesisTarget(); |
| 16 | |
| 17 | namespace { |
| 18 | |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame] | 19 | using llvm::APInt; |
| 20 | using llvm::MCInst; |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 21 | using testing::Gt; |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame] | 22 | using testing::IsEmpty; |
| 23 | using testing::Not; |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 24 | using testing::NotNull; |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 25 | |
Guillaume Chatelet | 12ca74e | 2018-09-20 13:37:04 +0000 | [diff] [blame] | 26 | constexpr const char kTriple[] = "aarch64-unknown-linux"; |
John Brawn | b371ccc | 2018-07-03 10:52:20 +0000 | [diff] [blame] | 27 | |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 28 | class AArch64TargetTest : public ::testing::Test { |
| 29 | protected: |
| 30 | AArch64TargetTest() |
John Brawn | b371ccc | 2018-07-03 10:52:20 +0000 | [diff] [blame] | 31 | : ExegesisTarget_(ExegesisTarget::lookup(llvm::Triple(kTriple))) { |
| 32 | EXPECT_THAT(ExegesisTarget_, NotNull()); |
| 33 | std::string error; |
| 34 | Target_ = llvm::TargetRegistry::lookupTarget(kTriple, error); |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 35 | EXPECT_THAT(Target_, NotNull()); |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame] | 36 | STI_.reset( |
Guillaume Chatelet | 12ca74e | 2018-09-20 13:37:04 +0000 | [diff] [blame] | 37 | Target_->createMCSubtargetInfo(kTriple, "generic", /*no features*/ "")); |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 38 | } |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame] | 39 | |
John Brawn | b371ccc | 2018-07-03 10:52:20 +0000 | [diff] [blame] | 40 | static void SetUpTestCase() { |
| 41 | LLVMInitializeAArch64TargetInfo(); |
| 42 | LLVMInitializeAArch64Target(); |
| 43 | LLVMInitializeAArch64TargetMC(); |
| 44 | InitializeAArch64ExegesisTarget(); |
| 45 | } |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 46 | |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame] | 47 | std::vector<MCInst> setRegTo(unsigned Reg, const APInt &Value) { |
| 48 | return ExegesisTarget_->setRegTo(*STI_, Reg, Value); |
| 49 | } |
| 50 | |
John Brawn | b371ccc | 2018-07-03 10:52:20 +0000 | [diff] [blame] | 51 | const llvm::Target *Target_; |
| 52 | const ExegesisTarget *const ExegesisTarget_; |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame] | 53 | std::unique_ptr<llvm::MCSubtargetInfo> STI_; |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame] | 56 | TEST_F(AArch64TargetTest, SetRegToConstant) { |
| 57 | // The AArch64 target currently doesn't know how to set register values. |
| 58 | const auto Insts = setRegTo(llvm::AArch64::X0, llvm::APInt()); |
| 59 | EXPECT_THAT(Insts, Not(IsEmpty())); |
| 60 | } |
| 61 | |
Clement Courbet | eee2e06 | 2018-11-09 13:15:32 +0000 | [diff] [blame] | 62 | TEST_F(AArch64TargetTest, DefaultPfmCounters) { |
Clement Courbet | df78bf1 | 2018-11-09 14:08:29 +0000 | [diff] [blame^] | 63 | const std::string Expected = "CPU_CYCLES"; |
| 64 | EXPECT_EQ(ExegesisTarget_->getPfmCounters("").CycleCounter, Expected); |
Clement Courbet | eee2e06 | 2018-11-09 13:15:32 +0000 | [diff] [blame] | 65 | EXPECT_EQ(ExegesisTarget_->getPfmCounters("unknown_cpu").CycleCounter, |
Clement Courbet | df78bf1 | 2018-11-09 14:08:29 +0000 | [diff] [blame^] | 66 | Expected); |
Clement Courbet | eee2e06 | 2018-11-09 13:15:32 +0000 | [diff] [blame] | 67 | } |
| 68 | |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 69 | } // namespace |
| 70 | } // namespace exegesis |
Fangrui Song | 32401af | 2018-10-22 17:10:47 +0000 | [diff] [blame] | 71 | } // namespace llvm |