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: |
Clement Courbet | 50cdd56 | 2019-10-09 11:58:42 +0000 | [diff] [blame^] | 19 | return AArch64::MOVi32imm; |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame] | 20 | case 64: |
Clement Courbet | 50cdd56 | 2019-10-09 11:58:42 +0000 | [diff] [blame^] | 21 | return AArch64::MOVi64imm; |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame] | 22 | } |
| 23 | llvm_unreachable("Invalid Value Width"); |
| 24 | } |
| 25 | |
| 26 | // Generates instruction to load an immediate value into a register. |
Clement Courbet | 50cdd56 | 2019-10-09 11:58:42 +0000 | [diff] [blame^] | 27 | static MCInst loadImmediate(unsigned Reg, unsigned RegBitWidth, |
| 28 | const APInt &Value) { |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame] | 29 | if (Value.getBitWidth() > RegBitWidth) |
| 30 | llvm_unreachable("Value must fit in the Register"); |
Clement Courbet | 50cdd56 | 2019-10-09 11:58:42 +0000 | [diff] [blame^] | 31 | return MCInstBuilder(getLoadImmediateOpcode(RegBitWidth)) |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame] | 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: |
Clement Courbet | 50cdd56 | 2019-10-09 11:58:42 +0000 | [diff] [blame^] | 45 | std::vector<MCInst> setRegTo(const MCSubtargetInfo &STI, unsigned Reg, |
| 46 | const APInt &Value) const override { |
| 47 | if (AArch64::GPR32RegClass.contains(Reg)) |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame] | 48 | return {loadImmediate(Reg, 32, Value)}; |
Clement Courbet | 50cdd56 | 2019-10-09 11:58:42 +0000 | [diff] [blame^] | 49 | if (AArch64::GPR64RegClass.contains(Reg)) |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame] | 50 | return {loadImmediate(Reg, 64, Value)}; |
Clement Courbet | 50cdd56 | 2019-10-09 11:58:42 +0000 | [diff] [blame^] | 51 | errs() << "setRegTo is not implemented, results will be unreliable\n"; |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame] | 52 | return {}; |
Guillaume Chatelet | 5ad2909 | 2018-09-18 11:26:27 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Clement Courbet | 50cdd56 | 2019-10-09 11:58:42 +0000 | [diff] [blame^] | 55 | bool matchesArch(Triple::ArchType Arch) const override { |
| 56 | return Arch == Triple::aarch64 || Arch == Triple::aarch64_be; |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 57 | } |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame] | 58 | |
Clement Courbet | 50cdd56 | 2019-10-09 11:58:42 +0000 | [diff] [blame^] | 59 | void addTargetSpecificPasses(PassManagerBase &PM) const override { |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 60 | // Function return is a pseudo-instruction that needs to be expanded |
Clement Courbet | 50cdd56 | 2019-10-09 11:58:42 +0000 | [diff] [blame^] | 61 | PM.add(createAArch64ExpandPseudoPass()); |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 62 | } |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | } // namespace |
| 66 | |
| 67 | static ExegesisTarget *getTheExegesisAArch64Target() { |
| 68 | static ExegesisAArch64Target Target; |
| 69 | return &Target; |
| 70 | } |
| 71 | |
| 72 | void InitializeAArch64ExegesisTarget() { |
| 73 | ExegesisTarget::registerTarget(getTheExegesisAArch64Target()); |
| 74 | } |
| 75 | |
| 76 | } // namespace exegesis |
Fangrui Song | 32401af | 2018-10-22 17:10:47 +0000 | [diff] [blame] | 77 | } // namespace llvm |