1//==-- AArch64TargetMachine.h - Define TargetMachine for AArch64 -*- 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//
9// This file declares the AArch64 specific subclass of TargetMachine.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_AARCH64_AARCH64TARGETMACHINE_H
14#define LLVM_LIB_TARGET_AARCH64_AARCH64TARGETMACHINE_H
15
16#include "AArch64InstrInfo.h"
17#include "AArch64Subtarget.h"
18#include "llvm/CodeGen/CodeGenTargetMachineImpl.h"
19#include "llvm/IR/Attributes.h"
20#include "llvm/IR/DataLayout.h"
21#include <optional>
22
23namespace llvm {
24
25class AArch64TargetMachine : public CodeGenTargetMachineImpl {
26protected:
27 std::unique_ptr<TargetLoweringObjectFile> TLOF;
28 mutable StringMap<std::unique_ptr<AArch64Subtarget>> SubtargetMap;
29 mutable AttributeSet LastSubtargetAttrs;
30 mutable const AArch64Subtarget *LastSubtarget = nullptr;
31
32 /// Reset internal state.
33 void reset() override;
34
35public:
36 AArch64TargetMachine(const Target &T, const Triple &TT, StringRef CPU,
37 StringRef FS, const TargetOptions &Options,
38 std::optional<Reloc::Model> RM,
39 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL,
40 bool JIT, bool IsLittleEndian);
41
42 ~AArch64TargetMachine() override;
43 const AArch64Subtarget *getSubtargetImpl(const Function &F) const override;
44 // DO NOT IMPLEMENT: There is no such thing as a valid default subtarget,
45 // subtargets are per-function entities based on the target-specific
46 // attributes of each function.
47 const AArch64Subtarget *getSubtargetImpl() const = delete;
48
49 // Pass Pipeline Configuration
50 TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
51
52 void registerPassBuilderCallbacks(PassBuilder &PB) override;
53
54 TargetTransformInfo getTargetTransformInfo(const Function &F) const override;
55
56 TargetLoweringObjectFile* getObjFileLowering() const override {
57 return TLOF.get();
58 }
59
60 MachineFunctionInfo *
61 createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F,
62 const TargetSubtargetInfo *STI) const override;
63
64 yaml::MachineFunctionInfo *createDefaultFuncInfoYAML() const override;
65 yaml::MachineFunctionInfo *
66 convertFuncInfoToYAML(const MachineFunction &MF) const override;
67 bool parseMachineFunctionInfo(const yaml::MachineFunctionInfo &,
68 PerFunctionMIParsingState &PFS,
69 SMDiagnostic &Error,
70 SMRange &SourceRange) const override;
71
72 /// Returns true if a cast between SrcAS and DestAS is a noop.
73 bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override {
74 return getPointerSize(AS: SrcAS) == getPointerSize(AS: DestAS);
75 }
76 ScheduleDAGInstrs *
77 createMachineScheduler(MachineSchedContext *C) const override;
78
79 ScheduleDAGInstrs *
80 createPostMachineScheduler(MachineSchedContext *C) const override;
81
82 size_t clearLinkerOptimizationHints(
83 const SmallPtrSetImpl<MachineInstr *> &MIs) const override;
84
85 /// Returns the optimisation level that enables GlobalISel.
86 unsigned getEnableGlobalISelAtO() const;
87
88 /// This function checks whether the opt level is explicitly set to none,
89 /// or whether GlobalISel was enabled due to SDAG encountering an optnone
90 /// function. If the opt level is greater than the level we automatically
91 /// enable globalisel at, and it wasn't enabled via CLI, we know that it must
92 /// be because of an optnone function.
93 bool isGlobalISelOptNone() const;
94
95private:
96 bool isLittle;
97};
98
99// AArch64 little endian target machine.
100//
101class AArch64leTargetMachine : public AArch64TargetMachine {
102 virtual void anchor();
103
104public:
105 AArch64leTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
106 StringRef FS, const TargetOptions &Options,
107 std::optional<Reloc::Model> RM,
108 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL,
109 bool JIT);
110};
111
112// AArch64 big endian target machine.
113//
114class AArch64beTargetMachine : public AArch64TargetMachine {
115 virtual void anchor();
116
117public:
118 AArch64beTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
119 StringRef FS, const TargetOptions &Options,
120 std::optional<Reloc::Model> RM,
121 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL,
122 bool JIT);
123};
124
125} // end namespace llvm
126
127#endif
128