blob: a659278c031354ca6a9160b2cebf747787249b23 [file] [log] [blame]
John Brawnc4ed6002018-07-03 10:10:29 +00001//===-- Target.cpp ----------------------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Brawnc4ed6002018-07-03 10:10:29 +00006//
7//===----------------------------------------------------------------------===//
8#include "../Target.h"
9#include "../Latency.h"
10#include "AArch64.h"
Guillaume Chateletc96a97b2018-09-20 12:22:18 +000011#include "AArch64RegisterInfo.h"
John Brawnc4ed6002018-07-03 10:10:29 +000012
Fangrui Song32401af2018-10-22 17:10:47 +000013namespace llvm {
John Brawnc4ed6002018-07-03 10:10:29 +000014namespace exegesis {
15
Guillaume Chateletc96a97b2018-09-20 12:22:18 +000016static 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.
27static 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 Courbeteee2e062018-11-09 13:15:32 +000036#include "AArch64GenExegesis.inc"
37
38namespace {
Guillaume Chateletc96a97b2018-09-20 12:22:18 +000039
John Brawnc4ed6002018-07-03 10:10:29 +000040class ExegesisAArch64Target : public ExegesisTarget {
Clement Courbet41c8af32018-10-25 07:44:01 +000041public:
Clement Courbeteee2e062018-11-09 13:15:32 +000042 ExegesisAArch64Target() : ExegesisTarget(AArch64CpuPfmCounters) {}
Clement Courbet41c8af32018-10-25 07:44:01 +000043
44private:
Guillaume Chatelet5ad29092018-09-18 11:26:27 +000045 std::vector<llvm::MCInst> setRegTo(const llvm::MCSubtargetInfo &STI,
Guillaume Chateletc96a97b2018-09-20 12:22:18 +000046 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 Chatelet5ad29092018-09-18 11:26:27 +000054 }
55
John Brawnc4ed6002018-07-03 10:10:29 +000056 bool matchesArch(llvm::Triple::ArchType Arch) const override {
57 return Arch == llvm::Triple::aarch64 || Arch == llvm::Triple::aarch64_be;
58 }
Guillaume Chateletc96a97b2018-09-20 12:22:18 +000059
John Brawnc4ed6002018-07-03 10:10:29 +000060 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 Brawnc4ed6002018-07-03 10:10:29 +000064};
65
66} // namespace
67
68static ExegesisTarget *getTheExegesisAArch64Target() {
69 static ExegesisAArch64Target Target;
70 return &Target;
71}
72
73void InitializeAArch64ExegesisTarget() {
74 ExegesisTarget::registerTarget(getTheExegesisAArch64Target());
75}
76
77} // namespace exegesis
Fangrui Song32401af2018-10-22 17:10:47 +000078} // namespace llvm