1//===-- ARMTargetMachine.h - Define TargetMachine for ARM -------*- 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 ARM specific subclass of TargetMachine.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_ARM_ARMTARGETMACHINE_H
14#define LLVM_LIB_TARGET_ARM_ARMTARGETMACHINE_H
15
16#include "ARMSubtarget.h"
17#include "llvm/ADT/StringMap.h"
18#include "llvm/ADT/StringRef.h"
19#include "llvm/Analysis/TargetTransformInfo.h"
20#include "llvm/CodeGen/CodeGenTargetMachineImpl.h"
21#include "llvm/Support/CodeGen.h"
22#include "llvm/Target/LastSubtargetCache.h"
23#include "llvm/Target/TargetMachine.h"
24#include "llvm/TargetParser/ARMTargetParser.h"
25#include <memory>
26#include <optional>
27
28namespace llvm {
29
30class ARMBaseTargetMachine : public CodeGenTargetMachineImpl {
31protected:
32 std::unique_ptr<TargetLoweringObjectFile> TLOF;
33 bool isLittle;
34 mutable StringMap<std::unique_ptr<ARMSubtarget>> SubtargetMap;
35
36 /// The attributes that select a subtarget.
37 struct SubtargetAttrs {
38 Attribute CPU, FS, SoftFloat, MinSize, DenormalFPEnv;
39 FloatABI::ABIType FloatABI = FloatABI::Default;
40 ARM::ARMABI ABI = ARM::ARM_ABI_UNKNOWN;
41
42 bool operator==(const SubtargetAttrs &RHS) const {
43 return CPU == RHS.CPU && FS == RHS.FS && SoftFloat == RHS.SoftFloat &&
44 MinSize == RHS.MinSize && DenormalFPEnv == RHS.DenormalFPEnv &&
45 FloatABI == RHS.FloatABI && ABI == RHS.ABI;
46 }
47
48 bool operator!=(const SubtargetAttrs &RHS) const { return !(*this == RHS); }
49 };
50 mutable LastSubtargetCache<ARMSubtarget, SubtargetAttrs> LastSubtarget;
51
52 /// Reset internal state.
53 void reset() override;
54
55public:
56 ARMBaseTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
57 StringRef FS, const TargetOptions &Options,
58 std::optional<Reloc::Model> RM,
59 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL);
60 ~ARMBaseTargetMachine() override;
61
62 const ARMSubtarget *getSubtargetImpl(const Function &F) const override;
63 // DO NOT IMPLEMENT: There is no such thing as a valid default subtarget,
64 // subtargets are per-function entities based on the target-specific
65 // attributes of each function.
66 const ARMSubtarget *getSubtargetImpl() const = delete;
67 bool isLittleEndian() const { return isLittle; }
68
69 /// Returns the floating-point ABI in effect for \p M: the "float-abi" module
70 /// flag if present, otherwise the ABI implied by the target triple. An
71 /// explicit -target-abi=aapcs16 forces the hard-float ABI.
72 FloatABI::ABIType getFloatABI(const Module &M) const;
73
74 /// Returns the ABI in effect for \p M: the "target-abi" module flag if
75 /// present, otherwise the legacy -target-abi option; falling back to the
76 /// TargetMachine-level ABI computed at construction.
77 ARM::ARMABI getEffectiveABI(const Module &M) const;
78
79 TargetTransformInfo getTargetTransformInfo(const Function &F) const override;
80
81 // Pass Pipeline Configuration
82 TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
83
84 void registerPassBuilderCallbacks(PassBuilder &PB) override;
85
86 TargetLoweringObjectFile *getObjFileLowering() const override {
87 return TLOF.get();
88 }
89
90 bool targetSchedulesPostRAScheduling() const override { return true; };
91
92 MachineFunctionInfo *
93 createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F,
94 const TargetSubtargetInfo *STI) const override;
95
96 /// Returns true if a cast between SrcAS and DestAS is a noop.
97 bool isNoopAddrSpaceCast(const DataLayout &, unsigned SrcAS,
98 unsigned DestAS) const override {
99 // Addrspacecasts are always noops.
100 return true;
101 }
102
103 bool isGVIndirectSymbol(const GlobalValue *GV) const {
104 if (!shouldAssumeDSOLocal(GV))
105 return true;
106
107 // 32 bit macho has no relocation for a-b if a is undefined, even if b is in
108 // the section that is being relocated. This means we have to use o load
109 // even for GVs that are known to be local to the dso.
110 if (getTargetTriple().isOSBinFormatMachO() && isPositionIndependent() &&
111 (GV->isDeclarationForLinker() || GV->hasCommonLinkage()))
112 return true;
113
114 return false;
115 }
116
117 yaml::MachineFunctionInfo *createDefaultFuncInfoYAML() const override;
118 yaml::MachineFunctionInfo *
119 convertFuncInfoToYAML(const MachineFunction &MF) const override;
120 bool parseMachineFunctionInfo(const yaml::MachineFunctionInfo &,
121 PerFunctionMIParsingState &PFS,
122 SMDiagnostic &Error,
123 SMRange &SourceRange) const override;
124 ScheduleDAGInstrs *
125 createMachineScheduler(MachineSchedContext *C) const override;
126 ScheduleDAGInstrs *
127 createPostMachineScheduler(MachineSchedContext *C) const override;
128};
129
130/// ARM/Thumb little endian target machine.
131///
132class ARMLETargetMachine : public ARMBaseTargetMachine {
133public:
134 ARMLETargetMachine(const Target &T, const Triple &TT, StringRef CPU,
135 StringRef FS, const TargetOptions &Options,
136 std::optional<Reloc::Model> RM,
137 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL,
138 bool JIT);
139};
140
141/// ARM/Thumb big endian target machine.
142///
143class ARMBETargetMachine : public ARMBaseTargetMachine {
144public:
145 ARMBETargetMachine(const Target &T, const Triple &TT, StringRef CPU,
146 StringRef FS, const TargetOptions &Options,
147 std::optional<Reloc::Model> RM,
148 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL,
149 bool JIT);
150};
151
152} // end namespace llvm
153
154#endif // LLVM_LIB_TARGET_ARM_ARMTARGETMACHINE_H
155