1 //===-- Target.cpp ----------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "../Latency.h"
11 #include "AArch64RegisterInfo.h"
16 static unsigned getLoadImmediateOpcode(unsigned RegBitWidth
) {
17 switch (RegBitWidth
) {
19 return AArch64::MOVi32imm
;
21 return AArch64::MOVi64imm
;
23 llvm_unreachable("Invalid Value Width");
26 // Generates instruction to load an immediate value into a register.
27 static MCInst
loadImmediate(unsigned Reg
, unsigned RegBitWidth
,
29 if (Value
.getBitWidth() > RegBitWidth
)
30 llvm_unreachable("Value must fit in the Register");
31 return MCInstBuilder(getLoadImmediateOpcode(RegBitWidth
))
33 .addImm(Value
.getZExtValue());
36 #include "AArch64GenExegesis.inc"
40 class ExegesisAArch64Target
: public ExegesisTarget
{
42 ExegesisAArch64Target() : ExegesisTarget(AArch64CpuPfmCounters
) {}
45 std::vector
<MCInst
> setRegTo(const MCSubtargetInfo
&STI
, unsigned Reg
,
46 const APInt
&Value
) const override
{
47 if (AArch64::GPR32RegClass
.contains(Reg
))
48 return {loadImmediate(Reg
, 32, Value
)};
49 if (AArch64::GPR64RegClass
.contains(Reg
))
50 return {loadImmediate(Reg
, 64, Value
)};
51 errs() << "setRegTo is not implemented, results will be unreliable\n";
55 bool matchesArch(Triple::ArchType Arch
) const override
{
56 return Arch
== Triple::aarch64
|| Arch
== Triple::aarch64_be
;
59 void addTargetSpecificPasses(PassManagerBase
&PM
) const override
{
60 // Function return is a pseudo-instruction that needs to be expanded
61 PM
.add(createAArch64ExpandPseudoPass());
67 static ExegesisTarget
*getTheExegesisAArch64Target() {
68 static ExegesisAArch64Target Target
;
72 void InitializeAArch64ExegesisTarget() {
73 ExegesisTarget::registerTarget(getTheExegesisAArch64Target());
76 } // namespace exegesis