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