[Alignment][NFC] Use Align with TargetLowering::setMinFunctionAlignment
[llvm-core.git] / tools / llvm-exegesis / lib / AArch64 / Target.cpp
bloba659278c031354ca6a9160b2cebf747787249b23
1 //===-- Target.cpp ----------------------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 #include "../Target.h"
9 #include "../Latency.h"
10 #include "AArch64.h"
11 #include "AArch64RegisterInfo.h"
13 namespace llvm {
14 namespace exegesis {
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;
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))
32 .addReg(Reg)
33 .addImm(Value.getZExtValue());
36 #include "AArch64GenExegesis.inc"
38 namespace {
40 class ExegesisAArch64Target : public ExegesisTarget {
41 public:
42 ExegesisAArch64Target() : ExegesisTarget(AArch64CpuPfmCounters) {}
44 private:
45 std::vector<llvm::MCInst> setRegTo(const llvm::MCSubtargetInfo &STI,
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 {};
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());
66 } // namespace
68 static ExegesisTarget *getTheExegesisAArch64Target() {
69 static ExegesisAArch64Target Target;
70 return &Target;
73 void InitializeAArch64ExegesisTarget() {
74 ExegesisTarget::registerTarget(getTheExegesisAArch64Target());
77 } // namespace exegesis
78 } // namespace llvm