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 llvm::AArch64::MOVi32imm
;
21 return llvm::AArch64::MOVi64imm
;
23 llvm_unreachable("Invalid Value Width");
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
))
33 .addImm(Value
.getZExtValue());
36 #include "AArch64GenExegesis.inc"
40 class ExegesisAArch64Target
: public ExegesisTarget
{
42 ExegesisAArch64Target() : ExegesisTarget(AArch64CpuPfmCounters
) {}
45 std::vector
<llvm::MCInst
> setRegTo(const llvm::MCSubtargetInfo
&STI
,
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";
56 bool matchesArch(llvm::Triple::ArchType Arch
) const override
{
57 return Arch
== llvm::Triple::aarch64
|| Arch
== llvm::Triple::aarch64_be
;
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());
68 static ExegesisTarget
*getTheExegesisAArch64Target() {
69 static ExegesisAArch64Target Target
;
73 void InitializeAArch64ExegesisTarget() {
74 ExegesisTarget::registerTarget(getTheExegesisAArch64Target());
77 } // namespace exegesis