1 //===- HexagonSubtarget.h - Define Subtarget for the Hexagon ----*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file declares the Hexagon specific subclass of TargetSubtarget.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONSUBTARGET_H
14 #define LLVM_LIB_TARGET_HEXAGON_HEXAGONSUBTARGET_H
16 #include "HexagonArch.h"
17 #include "HexagonFrameLowering.h"
18 #include "HexagonISelLowering.h"
19 #include "HexagonInstrInfo.h"
20 #include "HexagonRegisterInfo.h"
21 #include "HexagonSelectionDAGInfo.h"
22 #include "llvm/ADT/SmallSet.h"
23 #include "llvm/ADT/StringRef.h"
24 #include "llvm/CodeGen/ScheduleDAGMutation.h"
25 #include "llvm/CodeGen/TargetSubtargetInfo.h"
26 #include "llvm/MC/MCInstrItineraries.h"
31 #define GET_SUBTARGETINFO_HEADER
32 #include "HexagonGenSubtargetInfo.inc"
42 class HexagonSubtarget : public HexagonGenSubtargetInfo {
43 virtual void anchor();
45 bool UseHVX64BOps = false;
46 bool UseHVX128BOps = false;
48 bool UseAudioOps = false;
49 bool UseCompound = false;
50 bool UseLongCalls = false;
51 bool UseMemops = false;
52 bool UsePackets = false;
53 bool UseNewValueJumps = false;
54 bool UseNewValueStores = false;
55 bool UseSmallData = false;
56 bool UseUnsafeMath = false;
57 bool UseZRegOps = false;
59 bool HasPreV65 = false;
60 bool HasMemNoShuf = false;
61 bool EnableDuplex = false;
62 bool ReservedR19 = false;
63 bool NoreturnStackElim = false;
66 Hexagon::ArchEnum HexagonArchVersion;
67 Hexagon::ArchEnum HexagonHVXVersion = Hexagon::ArchEnum::NoArch;
68 CodeGenOpt::Level OptLevel;
69 /// True if the target should use Back-Skip-Back scheduling. This is the
71 bool UseBSBScheduling;
73 struct UsrOverflowMutation : public ScheduleDAGMutation {
74 void apply(ScheduleDAGInstrs *DAG) override;
76 struct HVXMemLatencyMutation : public ScheduleDAGMutation {
77 void apply(ScheduleDAGInstrs *DAG) override;
79 struct CallMutation : public ScheduleDAGMutation {
80 void apply(ScheduleDAGInstrs *DAG) override;
82 bool shouldTFRICallBind(const HexagonInstrInfo &HII,
83 const SUnit &Inst1, const SUnit &Inst2) const;
85 struct BankConflictMutation : public ScheduleDAGMutation {
86 void apply(ScheduleDAGInstrs *DAG) override;
90 enum HexagonProcFamilyEnum { Others, TinyCore };
92 std::string CPUString;
95 // The following objects can use the TargetTriple, so they must be
97 HexagonProcFamilyEnum HexagonProcFamily = Others;
98 HexagonInstrInfo InstrInfo;
99 HexagonRegisterInfo RegInfo;
100 HexagonTargetLowering TLInfo;
101 HexagonSelectionDAGInfo TSInfo;
102 HexagonFrameLowering FrameLowering;
103 InstrItineraryData InstrItins;
106 HexagonSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
107 const TargetMachine &TM);
109 const Triple &getTargetTriple() const { return TargetTriple; }
110 bool isEnvironmentMusl() const {
111 return TargetTriple.getEnvironment() == Triple::Musl;
114 /// getInstrItins - Return the instruction itineraries based on subtarget
116 const InstrItineraryData *getInstrItineraryData() const override {
119 const HexagonInstrInfo *getInstrInfo() const override { return &InstrInfo; }
120 const HexagonRegisterInfo *getRegisterInfo() const override {
123 const HexagonTargetLowering *getTargetLowering() const override {
126 const HexagonFrameLowering *getFrameLowering() const override {
127 return &FrameLowering;
129 const HexagonSelectionDAGInfo *getSelectionDAGInfo() const override {
133 HexagonSubtarget &initializeSubtargetDependencies(StringRef CPU,
136 /// ParseSubtargetFeatures - Parses features string setting specified
137 /// subtarget options. Definition of function is auto generated by tblgen.
138 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
140 bool hasV5Ops() const {
141 return getHexagonArchVersion() >= Hexagon::ArchEnum::V5;
143 bool hasV5OpsOnly() const {
144 return getHexagonArchVersion() == Hexagon::ArchEnum::V5;
146 bool hasV55Ops() const {
147 return getHexagonArchVersion() >= Hexagon::ArchEnum::V55;
149 bool hasV55OpsOnly() const {
150 return getHexagonArchVersion() == Hexagon::ArchEnum::V55;
152 bool hasV60Ops() const {
153 return getHexagonArchVersion() >= Hexagon::ArchEnum::V60;
155 bool hasV60OpsOnly() const {
156 return getHexagonArchVersion() == Hexagon::ArchEnum::V60;
158 bool hasV62Ops() const {
159 return getHexagonArchVersion() >= Hexagon::ArchEnum::V62;
161 bool hasV62OpsOnly() const {
162 return getHexagonArchVersion() == Hexagon::ArchEnum::V62;
164 bool hasV65Ops() const {
165 return getHexagonArchVersion() >= Hexagon::ArchEnum::V65;
167 bool hasV65OpsOnly() const {
168 return getHexagonArchVersion() == Hexagon::ArchEnum::V65;
170 bool hasV66Ops() const {
171 return getHexagonArchVersion() >= Hexagon::ArchEnum::V66;
173 bool hasV66OpsOnly() const {
174 return getHexagonArchVersion() == Hexagon::ArchEnum::V66;
176 bool hasV67Ops() const {
177 return getHexagonArchVersion() >= Hexagon::ArchEnum::V67;
179 bool hasV67OpsOnly() const {
180 return getHexagonArchVersion() == Hexagon::ArchEnum::V67;
183 bool useAudioOps() const { return UseAudioOps; }
184 bool useCompound() const { return UseCompound; }
185 bool useLongCalls() const { return UseLongCalls; }
186 bool useMemops() const { return UseMemops; }
187 bool usePackets() const { return UsePackets; }
188 bool useNewValueJumps() const { return UseNewValueJumps; }
189 bool useNewValueStores() const { return UseNewValueStores; }
190 bool useSmallData() const { return UseSmallData; }
191 bool useUnsafeMath() const { return UseUnsafeMath; }
192 bool useZRegOps() const { return UseZRegOps; }
194 bool isTinyCore() const { return HexagonProcFamily == TinyCore; }
195 bool isTinyCoreWithDuplex() const { return isTinyCore() && EnableDuplex; }
197 bool useHVXOps() const {
198 return HexagonHVXVersion > Hexagon::ArchEnum::NoArch;
200 bool useHVXV60Ops() const {
201 return HexagonHVXVersion >= Hexagon::ArchEnum::V60;
203 bool useHVXV62Ops() const {
204 return HexagonHVXVersion >= Hexagon::ArchEnum::V62;
206 bool useHVXV65Ops() const {
207 return HexagonHVXVersion >= Hexagon::ArchEnum::V65;
209 bool useHVXV66Ops() const {
210 return HexagonHVXVersion >= Hexagon::ArchEnum::V66;
212 bool useHVXV67Ops() const {
213 return HexagonHVXVersion >= Hexagon::ArchEnum::V67;
215 bool useHVX128BOps() const { return useHVXOps() && UseHVX128BOps; }
216 bool useHVX64BOps() const { return useHVXOps() && UseHVX64BOps; }
218 bool hasMemNoShuf() const { return HasMemNoShuf; }
219 bool hasReservedR19() const { return ReservedR19; }
220 bool usePredicatedCalls() const;
222 bool noreturnStackElim() const { return NoreturnStackElim; }
224 bool useBSBScheduling() const { return UseBSBScheduling; }
225 bool enableMachineScheduler() const override;
227 // Always use the TargetLowering default scheduler.
228 // FIXME: This will use the vliw scheduler which is probably just hurting
229 // compiler time and will be removed eventually anyway.
230 bool enableMachineSchedDefaultSched() const override { return false; }
232 // For use with PostRAScheduling: get the anti-dependence breaking that should
233 // be performed before post-RA scheduling.
234 AntiDepBreakMode getAntiDepBreakMode() const override { return ANTIDEP_ALL; }
235 /// True if the subtarget should run a scheduler after register
237 bool enablePostRAScheduler() const override { return true; }
239 bool enableSubRegLiveness() const override;
241 const std::string &getCPUString () const { return CPUString; }
243 const Hexagon::ArchEnum &getHexagonArchVersion() const {
244 return HexagonArchVersion;
247 void getPostRAMutations(
248 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations)
251 void getSMSMutations(
252 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations)
255 /// Enable use of alias analysis during code generation (during MI
256 /// scheduling, DAGCombine, etc.).
257 bool useAA() const override;
259 /// Perform target specific adjustments to the latency of a schedule
261 void adjustSchedDependency(SUnit *Def, int DefOpIdx, SUnit *Use, int UseOpIdx,
262 SDep &Dep) const override;
264 unsigned getVectorLength() const {
270 llvm_unreachable("Invalid HVX vector length settings");
273 ArrayRef<MVT> getHVXElementTypes() const {
274 static MVT Types[] = { MVT::i8, MVT::i16, MVT::i32 };
275 return makeArrayRef(Types);
278 bool isHVXVectorType(MVT VecTy, bool IncludeBool = false) const {
279 if (!VecTy.isVector() || !useHVXOps() || VecTy.isScalableVector())
281 MVT ElemTy = VecTy.getVectorElementType();
282 if (!IncludeBool && ElemTy == MVT::i1)
285 unsigned HwLen = getVectorLength();
286 unsigned NumElems = VecTy.getVectorNumElements();
287 ArrayRef<MVT> ElemTypes = getHVXElementTypes();
289 if (IncludeBool && ElemTy == MVT::i1) {
290 // Boolean HVX vector types are formed from regular HVX vector types
291 // by replacing the element type with i1.
292 for (MVT T : ElemTypes)
293 if (NumElems * T.getSizeInBits() == 8*HwLen)
298 unsigned VecWidth = VecTy.getSizeInBits();
299 if (VecWidth != 8*HwLen && VecWidth != 16*HwLen)
301 return llvm::any_of(ElemTypes, [ElemTy] (MVT T) { return ElemTy == T; });
304 unsigned getTypeAlignment(MVT Ty) const {
305 if (isHVXVectorType(Ty, true))
306 return getVectorLength();
307 return Ty.getSizeInBits() / 8;
310 unsigned getL1CacheLineSize() const;
311 unsigned getL1PrefetchDistance() const;
314 // Helper function responsible for increasing the latency only.
315 void updateLatency(MachineInstr &SrcInst, MachineInstr &DstInst, SDep &Dep)
317 void restoreLatency(SUnit *Src, SUnit *Dst) const;
318 void changeLatency(SUnit *Src, SUnit *Dst, unsigned Lat) const;
319 bool isBestZeroLatency(SUnit *Src, SUnit *Dst, const HexagonInstrInfo *TII,
320 SmallSet<SUnit*, 4> &ExclSrc, SmallSet<SUnit*, 4> &ExclDst) const;
323 } // end namespace llvm
325 #endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONSUBTARGET_H