[InstCombine] Signed saturation patterns
[llvm-complete.git] / tools / llvm-exegesis / lib / AArch64 / Target.cpp
blobf5cc88c94a9361d1e14ede0631550462f2194fd4
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 AArch64::MOVi32imm;
20 case 64:
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,
28 const APInt &Value) {
29 if (Value.getBitWidth() > RegBitWidth)
30 llvm_unreachable("Value must fit in the Register");
31 return 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<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";
52 return {};
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());
65 } // namespace
67 static ExegesisTarget *getTheExegesisAArch64Target() {
68 static ExegesisAArch64Target Target;
69 return &Target;
72 void InitializeAArch64ExegesisTarget() {
73 ExegesisTarget::registerTarget(getTheExegesisAArch64Target());
76 } // namespace exegesis
77 } // namespace llvm