John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 1 | //===-- Target.cpp ----------------------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | #include "../Target.h" |
| 9 | #include "../Latency.h" |
| 10 | #include "AArch64.h" |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame] | 11 | #include "AArch64RegisterInfo.h" |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 12 | |
Fangrui Song | 32401af | 2018-10-22 17:10:47 +0000 | [diff] [blame] | 13 | namespace llvm { |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 14 | namespace exegesis { |
| 15 | |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame] | 16 | static unsigned getLoadImmediateOpcode(unsigned RegBitWidth) { |
| 17 | switch (RegBitWidth) { |
| 18 | case 32: |
| 19 | return llvm::AArch64::MOVi32imm; |
| 20 | case 64: |
| 21 | return llvm::AArch64::MOVi64imm; |
| 22 | } |
| 23 | llvm_unreachable("Invalid Value Width"); |
| 24 | } |
| 25 | |
| 26 | // Generates instruction to load an immediate value into a register. |
| 27 | static llvm::MCInst loadImmediate(unsigned Reg, unsigned RegBitWidth, |
| 28 | const llvm::APInt &Value) { |
| 29 | if (Value.getBitWidth() > RegBitWidth) |
| 30 | llvm_unreachable("Value must fit in the Register"); |
| 31 | return llvm::MCInstBuilder(getLoadImmediateOpcode(RegBitWidth)) |
| 32 | .addReg(Reg) |
| 33 | .addImm(Value.getZExtValue()); |
| 34 | } |
| 35 | |
Clement Courbet | eee2e06 | 2018-11-09 13:15:32 +0000 | [diff] [blame] | 36 | #include "AArch64GenExegesis.inc" |
| 37 | |
| 38 | namespace { |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame] | 39 | |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 40 | class ExegesisAArch64Target : public ExegesisTarget { |
Clement Courbet | 41c8af3 | 2018-10-25 07:44:01 +0000 | [diff] [blame] | 41 | public: |
Clement Courbet | eee2e06 | 2018-11-09 13:15:32 +0000 | [diff] [blame] | 42 | ExegesisAArch64Target() : ExegesisTarget(AArch64CpuPfmCounters) {} |
Clement Courbet | 41c8af3 | 2018-10-25 07:44:01 +0000 | [diff] [blame] | 43 | |
| 44 | private: |
Guillaume Chatelet | 5ad2909 | 2018-09-18 11:26:27 +0000 | [diff] [blame] | 45 | std::vector<llvm::MCInst> setRegTo(const llvm::MCSubtargetInfo &STI, |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame] | 46 | unsigned Reg, |
| 47 | const llvm::APInt &Value) const override { |
| 48 | if (llvm::AArch64::GPR32RegClass.contains(Reg)) |
| 49 | return {loadImmediate(Reg, 32, Value)}; |
| 50 | if (llvm::AArch64::GPR64RegClass.contains(Reg)) |
| 51 | return {loadImmediate(Reg, 64, Value)}; |
| 52 | llvm::errs() << "setRegTo is not implemented, results will be unreliable\n"; |
| 53 | return {}; |
Guillaume Chatelet | 5ad2909 | 2018-09-18 11:26:27 +0000 | [diff] [blame] | 54 | } |
| 55 | |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 56 | bool matchesArch(llvm::Triple::ArchType Arch) const override { |
| 57 | return Arch == llvm::Triple::aarch64 || Arch == llvm::Triple::aarch64_be; |
| 58 | } |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame] | 59 | |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 60 | void addTargetSpecificPasses(llvm::PassManagerBase &PM) const override { |
| 61 | // Function return is a pseudo-instruction that needs to be expanded |
| 62 | PM.add(llvm::createAArch64ExpandPseudoPass()); |
| 63 | } |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | } // namespace |
| 67 | |
| 68 | static ExegesisTarget *getTheExegesisAArch64Target() { |
| 69 | static ExegesisAArch64Target Target; |
| 70 | return &Target; |
| 71 | } |
| 72 | |
| 73 | void InitializeAArch64ExegesisTarget() { |
| 74 | ExegesisTarget::registerTarget(getTheExegesisAArch64Target()); |
| 75 | } |
| 76 | |
| 77 | } // namespace exegesis |
Fangrui Song | 32401af | 2018-10-22 17:10:47 +0000 | [diff] [blame] | 78 | } // namespace llvm |