[sanitizer] Improve FreeBSD ASLR detection
[llvm-project.git] / llvm / tools / llvm-exegesis / lib / AArch64 / Target.cpp
blobc778b89032cd63d11f23d77f0f5efd42a3dc938d
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 "AArch64.h"
10 #include "AArch64RegisterInfo.h"
12 namespace llvm {
13 namespace exegesis {
15 static unsigned getLoadImmediateOpcode(unsigned RegBitWidth) {
16 switch (RegBitWidth) {
17 case 32:
18 return AArch64::MOVi32imm;
19 case 64:
20 return AArch64::MOVi64imm;
22 llvm_unreachable("Invalid Value Width");
25 // Generates instruction to load an immediate value into a register.
26 static MCInst loadImmediate(unsigned Reg, unsigned RegBitWidth,
27 const APInt &Value) {
28 if (Value.getBitWidth() > RegBitWidth)
29 llvm_unreachable("Value must fit in the Register");
30 return MCInstBuilder(getLoadImmediateOpcode(RegBitWidth))
31 .addReg(Reg)
32 .addImm(Value.getZExtValue());
35 #include "AArch64GenExegesis.inc"
37 namespace {
39 class ExegesisAArch64Target : public ExegesisTarget {
40 public:
41 ExegesisAArch64Target() : ExegesisTarget(AArch64CpuPfmCounters) {}
43 private:
44 std::vector<MCInst> setRegTo(const MCSubtargetInfo &STI, unsigned Reg,
45 const APInt &Value) const override {
46 if (AArch64::GPR32RegClass.contains(Reg))
47 return {loadImmediate(Reg, 32, Value)};
48 if (AArch64::GPR64RegClass.contains(Reg))
49 return {loadImmediate(Reg, 64, Value)};
50 errs() << "setRegTo is not implemented, results will be unreliable\n";
51 return {};
54 bool matchesArch(Triple::ArchType Arch) const override {
55 return Arch == Triple::aarch64 || Arch == Triple::aarch64_be;
58 void addTargetSpecificPasses(PassManagerBase &PM) const override {
59 // Function return is a pseudo-instruction that needs to be expanded
60 PM.add(createAArch64ExpandPseudoPass());
64 } // namespace
66 static ExegesisTarget *getTheExegesisAArch64Target() {
67 static ExegesisAArch64Target Target;
68 return &Target;
71 void InitializeAArch64ExegesisTarget() {
72 ExegesisTarget::registerTarget(getTheExegesisAArch64Target());
75 } // namespace exegesis
76 } // namespace llvm