LLVM 24.0.0git
HexagonSubtarget.h
Go to the documentation of this file.
1//===- HexagonSubtarget.h - Define Subtarget for the Hexagon ----*- 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 Hexagon specific subclass of TargetSubtarget.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONSUBTARGET_H
14#define LLVM_LIB_TARGET_HEXAGON_HEXAGONSUBTARGET_H
15
16#include "HexagonDepArch.h"
18#include "HexagonISelLowering.h"
19#include "HexagonInstrInfo.h"
20#include "HexagonRegisterInfo.h"
22#include "llvm/ADT/SmallSet.h"
23#include "llvm/ADT/StringRef.h"
28#include <bitset>
29#include <memory>
30#include <string>
31#include <vector>
32
33#define GET_SUBTARGETINFO_HEADER
34#include "HexagonGenSubtargetInfo.inc"
35
36namespace llvm {
37
38class LibcallLoweringInfo;
39class MachineInstr;
40class SDep;
41class SUnit;
42class TargetMachine;
43class Triple;
44
46 virtual void anchor();
47
48 bool UseHVX64BOps = false;
49 bool UseHVX128BOps = false;
50
51 bool UseAudioOps = false;
52 bool UseCompound = false;
53 bool UseLongCalls = false;
54 bool UseMemops = false;
55 bool UsePackets = false;
56 bool UseNewValueJumps = false;
57 bool UseNewValueStores = false;
58 bool UseSmallData = false;
59 bool UseZRegOps = false;
60 bool UseHVXIEEEFPOps = false;
61 bool UseHVXQFloatOps = false;
62 bool UseHVXFloatingPoint = false;
63 bool UseCabac = false;
64
65 bool HasPreV65 = false;
66 bool HasMemNoShuf = false;
67 bool EnableDuplex = false;
68 std::bitset<Hexagon::NUM_TARGET_REGS> UserReservedRegister;
69 std::bitset<Hexagon::NUM_TARGET_REGS> SCSPointerRegister;
70 bool NoreturnStackElim = false;
71
72 /// Register holding the shadow call stack pointer, resolved from
73 /// SCSPointerRegister in initializeSubtargetDependencies().
74 Register SCSPReg;
75
76public:
80 /// True if the target should use Back-Skip-Back scheduling. This is the
81 /// default for V60.
83
85 void apply(ScheduleDAGInstrs *DAG) override;
86 };
88 void apply(ScheduleDAGInstrs *DAG) override;
89 };
91 void apply(ScheduleDAGInstrs *DAG) override;
92 private:
93 bool shouldTFRICallBind(const HexagonInstrInfo &HII,
94 const SUnit &Inst1, const SUnit &Inst2) const;
95 };
97 void apply(ScheduleDAGInstrs *DAG) override;
98 };
99
100private:
101 enum HexagonProcFamilyEnum { Others, TinyCore };
102
103 std::string CPUString;
104 HexagonProcFamilyEnum HexagonProcFamily = Others;
105 Triple TargetTriple;
106
107 // The following objects can use the TargetTriple, so they must be
108 // declared after it.
109 HexagonInstrInfo InstrInfo;
112 HexagonFrameLowering FrameLowering;
113 InstrItineraryData InstrItins;
114
115public:
116 HexagonSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
117 const TargetMachine &TM);
118
119 const Triple &getTargetTriple() const { return TargetTriple; }
120 bool isEnvironmentMusl() const {
121 return TargetTriple.getEnvironment() == Triple::Musl;
122 }
123
124 /// getInstrItins - Return the instruction itineraries based on subtarget
125 /// selection.
127 return &InstrItins;
128 }
129 const HexagonInstrInfo *getInstrInfo() const override { return &InstrInfo; }
130 const HexagonRegisterInfo *getRegisterInfo() const override {
131 return &InstrInfo.getRegisterInfo();
132 }
133 const HexagonTargetLowering *getTargetLowering() const override {
134 return &TLInfo;
135 }
136 const HexagonFrameLowering *getFrameLowering() const override {
137 return &FrameLowering;
138 }
140 return &TSInfo;
141 }
142
144 StringRef FS);
145
146 void initLibcallLoweringInfo(LibcallLoweringInfo &Info) const override;
147
148 /// ParseSubtargetFeatures - Parses features string setting specified
149 /// subtarget options. Definition of function is auto generated by tblgen.
151
152 bool isXRaySupported() const override { return true; }
153
154 bool hasV5Ops() const {
156 }
157 bool hasV5OpsOnly() const {
159 }
160 bool hasV55Ops() const {
162 }
163 bool hasV55OpsOnly() const {
165 }
166 bool hasV60Ops() const {
168 }
169 bool hasV60OpsOnly() const {
171 }
172 bool hasV62Ops() const {
174 }
175 bool hasV62OpsOnly() const {
177 }
178 bool hasV65Ops() const {
180 }
181 bool hasV65OpsOnly() const {
183 }
184 bool hasV66Ops() const {
186 }
187 bool hasV66OpsOnly() const {
189 }
190 bool hasV67Ops() const {
192 }
193 bool hasV67OpsOnly() const {
195 }
196 bool hasV68Ops() const {
198 }
199 bool hasV68OpsOnly() const {
201 }
202 bool hasV69Ops() const {
204 }
205 bool hasV69OpsOnly() const {
207 }
208 bool hasV71Ops() const {
210 }
211 bool hasV71OpsOnly() const {
213 }
214 bool hasV73Ops() const {
216 }
217 bool hasV73OpsOnly() const {
219 }
220 bool hasV75Ops() const {
222 }
223 bool hasV75OpsOnly() const {
225 }
226 bool hasV79Ops() const {
228 }
229 bool hasV79OpsOnly() const {
231 }
232 bool useHVXV79Ops() const {
234 }
235 bool useHVXV79OpsOnly() const {
237 }
238 bool hasV81Ops() const {
240 }
241 bool hasV81OpsOnly() const {
243 }
244 bool useHVXV81Ops() const {
246 }
247
248 bool useAudioOps() const { return UseAudioOps; }
249 bool useCompound() const { return UseCompound; }
250 bool useLongCalls() const { return UseLongCalls; }
251 bool useMemops() const { return UseMemops; }
252 bool usePackets() const { return UsePackets; }
253 bool useNewValueJumps() const { return UseNewValueJumps; }
254 bool useNewValueStores() const { return UseNewValueStores; }
255 bool useSmallData() const { return UseSmallData; }
256 bool useZRegOps() const { return UseZRegOps; }
257 bool useCabac() const { return UseCabac; }
258
259 bool isTinyCore() const { return HexagonProcFamily == TinyCore; }
260 bool isTinyCoreWithDuplex() const { return isTinyCore() && EnableDuplex; }
261
262 bool useHVXIEEEFPOps() const { return UseHVXIEEEFPOps && useHVXOps(); }
263 bool useHVXQFloatOps() const {
264 return UseHVXQFloatOps && HexagonHVXVersion >= Hexagon::ArchEnum::V68;
265 }
266 bool useHVXFloatingPoint() const { return UseHVXFloatingPoint; }
267 bool useHVXOps() const {
269 }
270 bool useHVXV60Ops() const {
272 }
273 bool useHVXV62Ops() const {
275 }
276 bool useHVXV65Ops() const {
278 }
279 bool useHVXV66Ops() const {
281 }
282 bool useHVXV67Ops() const {
284 }
285 bool useHVXV68Ops() const {
287 }
288 bool useHVXV69Ops() const {
290 }
291 bool useHVXV71Ops() const {
293 }
294 bool useHVXV73Ops() const {
296 }
297 bool useHVX128BOps() const { return useHVXOps() && UseHVX128BOps; }
298 bool useHVX64BOps() const { return useHVXOps() && UseHVX64BOps; }
299
300 bool hasMemNoShuf() const { return HasMemNoShuf; }
301 bool isRegisterReservedByUser(Register i) const override {
302 assert(i.id() < Hexagon::NUM_TARGET_REGS && "Register out of range");
303 return UserReservedRegister[i.id()];
304 }
305
306 /// Returns the register that holds the shadow call stack pointer. Defaults
307 /// to R18, overridable with the "scs-reg-rN" subtarget features.
308 Register getSCSPReg() const { return SCSPReg; }
309
310 bool usePredicatedCalls() const;
311
312 bool noreturnStackElim() const { return NoreturnStackElim; }
313
314 bool useBSBScheduling() const { return UseBSBScheduling; }
315 bool enableMachineScheduler() const override;
316
317 // Always use the TargetLowering default scheduler.
318 // FIXME: This will use the vliw scheduler which is probably just hurting
319 // compiler time and will be removed eventually anyway.
320 bool enableMachineSchedDefaultSched() const override { return false; }
321
322 // For use with PostRAScheduling: get the anti-dependence breaking that should
323 // be performed before post-RA scheduling.
324 AntiDepBreakMode getAntiDepBreakMode() const override { return ANTIDEP_ALL; }
325 /// True if the subtarget should run a scheduler after register
326 /// allocation.
327 bool enablePostRAScheduler() const override { return true; }
328
329 bool enableSubRegLiveness() const override;
330
331 const std::string &getCPUString () const { return CPUString; }
332
336
338 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations)
339 const override;
340
341 void getSMSMutations(
342 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations)
343 const override;
344
345 /// Enable use of alias analysis during code generation (during MI
346 /// scheduling, DAGCombine, etc.).
347 bool useAA() const override;
348
349 /// Perform target specific adjustments to the latency of a schedule
350 /// dependency.
351 void adjustSchedDependency(SUnit *Def, int DefOpIdx, SUnit *Use, int UseOpIdx,
352 SDep &Dep,
353 const TargetSchedModel *SchedModel) const override;
354
355 unsigned getVectorLength() const {
356 assert(useHVXOps());
357 if (useHVX64BOps())
358 return 64;
359 if (useHVX128BOps())
360 return 128;
361 llvm_unreachable("Invalid HVX vector length settings");
362 }
363
365 static MVT Types[] = {MVT::i8, MVT::i16, MVT::i32};
366 static MVT TypesV68[] = {MVT::i8, MVT::i16, MVT::i32, MVT::f16, MVT::f32};
367 static MVT TypesV81[] = {MVT::i8, MVT::i16, MVT::i32,
368 MVT::f16, MVT::bf16, MVT::f32};
369
371 return ArrayRef(TypesV81);
373 return ArrayRef(TypesV68);
374 return ArrayRef(Types);
375 }
376
377 bool isHVXElementType(MVT Ty, bool IncludeBool = false) const;
378 bool isHVXVectorType(EVT VecTy, bool IncludeBool = false) const;
379 bool isTypeForHVX(Type *VecTy, bool IncludeBool = false) const;
380
382 if (isHVXVectorType(Ty, true))
383 return Align(getVectorLength());
384 return Align(std::max<unsigned>(1, Ty.getSizeInBits() / 8));
385 }
386
387 unsigned getL1CacheLineSize() const;
388 unsigned getL1PrefetchDistance() const;
389
390 Intrinsic::ID getIntrinsicId(unsigned Opc) const;
391
392private:
393 // Helper function responsible for increasing the latency only.
394 int updateLatency(MachineInstr &SrcInst, MachineInstr &DstInst,
395 bool IsArtificial, int Latency) const;
396 void restoreLatency(SUnit *Src, SUnit *Dst) const;
397 void changeLatency(SUnit *Src, SUnit *Dst, unsigned Lat) const;
398 bool isBestZeroLatency(SUnit *Src, SUnit *Dst, const HexagonInstrInfo *TII,
400 SmallPtrSet<SUnit *, 4> &ExclDst) const;
401};
402
403} // end namespace llvm
404
405#endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONSUBTARGET_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const HexagonInstrInfo * TII
This file defines the SmallSet class.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
bool isTinyCoreWithDuplex() const
const InstrItineraryData * getInstrItineraryData() const override
getInstrItins - Return the instruction itineraries based on subtarget selection.
Hexagon::ArchEnum HexagonArchVersion
void adjustSchedDependency(SUnit *Def, int DefOpIdx, SUnit *Use, int UseOpIdx, SDep &Dep, const TargetSchedModel *SchedModel) const override
Perform target specific adjustments to the latency of a schedule dependency.
bool enableMachineSchedDefaultSched() const override
const HexagonInstrInfo * getInstrInfo() const override
const HexagonFrameLowering * getFrameLowering() const override
Hexagon::ArchEnum HexagonHVXVersion
const HexagonRegisterInfo * getRegisterInfo() const override
const Hexagon::ArchEnum & getHexagonArchVersion() const
void getSMSMutations(std::vector< std::unique_ptr< ScheduleDAGMutation > > &Mutations) const override
HexagonSubtarget(const Triple &TT, StringRef CPU, StringRef FS, const TargetMachine &TM)
bool isHVXVectorType(EVT VecTy, bool IncludeBool=false) const
const Triple & getTargetTriple() const
void getPostRAMutations(std::vector< std::unique_ptr< ScheduleDAGMutation > > &Mutations) const override
const HexagonTargetLowering * getTargetLowering() const override
bool UseBSBScheduling
True if the target should use Back-Skip-Back scheduling.
Register getSCSPReg() const
Returns the register that holds the shadow call stack pointer.
unsigned getL1PrefetchDistance() const
ArrayRef< MVT > getHVXElementTypes() const
bool enableSubRegLiveness() const override
Align getTypeAlignment(MVT Ty) const
bool isRegisterReservedByUser(Register i) const override
unsigned getVectorLength() const
AntiDepBreakMode getAntiDepBreakMode() const override
void initLibcallLoweringInfo(LibcallLoweringInfo &Info) const override
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS)
ParseSubtargetFeatures - Parses features string setting specified subtarget options.
unsigned getL1CacheLineSize() const
bool isTypeForHVX(Type *VecTy, bool IncludeBool=false) const
Intrinsic::ID getIntrinsicId(unsigned Opc) const
HexagonSubtarget & initializeSubtargetDependencies(StringRef CPU, StringRef FS)
const HexagonSelectionDAGInfo * getSelectionDAGInfo() const override
bool enableMachineScheduler() const override
bool enablePostRAScheduler() const override
True if the subtarget should run a scheduler after register allocation.
bool isHVXElementType(MVT Ty, bool IncludeBool=false) const
const std::string & getCPUString() const
bool isXRaySupported() const override
bool useAA() const override
Enable use of alias analysis during code generation (during MI scheduling, DAGCombine,...
Itinerary data supplied by a subtarget to be used by a target.
Tracks which library functions to use for a particular subtarget or function.
Machine Value Type.
Representation of each machine instruction.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
constexpr unsigned id() const
Definition Register.h:100
Scheduling dependency.
Definition ScheduleDAG.h:54
Scheduling unit. This is a node in the scheduling DAG.
A ScheduleDAG for scheduling lists of MachineInstr.
Mutate the DAG as a postpass after normal DAG building.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Primary interface to the complete machine description for the target machine.
Provide an instruction scheduling machine model to CodeGen passes.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:280
ArrayRef(const T &OneElt) -> ArrayRef< T >
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Extended Value Type.
Definition ValueTypes.h:35
void apply(ScheduleDAGInstrs *DAG) override
void apply(ScheduleDAGInstrs *DAG) override
void apply(ScheduleDAGInstrs *DAG) override
void apply(ScheduleDAGInstrs *DAG) override