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 UseHLXOps = false;
61 bool UseHVXIEEEFPOps = false;
62 bool UseHVXQFloatOps = false;
63 bool UseHVXFloatingPoint = false;
64 bool UseCabac = false;
65
66 bool HasPreV65 = false;
67 bool HasMemNoShuf = false;
68 bool EnableDuplex = false;
69 std::bitset<Hexagon::NUM_TARGET_REGS> UserReservedRegister;
70 std::bitset<Hexagon::NUM_TARGET_REGS> SCSPointerRegister;
71 bool NoreturnStackElim = false;
72
73 /// Register holding the shadow call stack pointer, resolved from
74 /// SCSPointerRegister in initializeSubtargetDependencies().
75 Register SCSPReg;
76
77public:
81 /// True if the target should use Back-Skip-Back scheduling. This is the
82 /// default for V60.
84
86 void apply(ScheduleDAGInstrs *DAG) override;
87 };
89 void apply(ScheduleDAGInstrs *DAG) override;
90 };
92 void apply(ScheduleDAGInstrs *DAG) override;
93 private:
94 bool shouldTFRICallBind(const HexagonInstrInfo &HII,
95 const SUnit &Inst1, const SUnit &Inst2) const;
96 };
98 void apply(ScheduleDAGInstrs *DAG) override;
99 };
101 void apply(ScheduleDAGInstrs *DAG) override;
102 };
103
104private:
105 enum HexagonProcFamilyEnum { Others, TinyCore, HLX2048B };
106
107 std::string CPUString;
108 HexagonProcFamilyEnum HexagonProcFamily = Others;
109 Triple TargetTriple;
110
111 // The following objects can use the TargetTriple, so they must be
112 // declared after it.
113 HexagonInstrInfo InstrInfo;
116 HexagonFrameLowering FrameLowering;
117 InstrItineraryData InstrItins;
118
119public:
120 HexagonSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
121 const TargetMachine &TM);
122
123 const Triple &getTargetTriple() const { return TargetTriple; }
124 bool isEnvironmentMusl() const {
125 return TargetTriple.getEnvironment() == Triple::Musl;
126 }
127
128 /// getInstrItins - Return the instruction itineraries based on subtarget
129 /// selection.
131 return &InstrItins;
132 }
133 const HexagonInstrInfo *getInstrInfo() const override { return &InstrInfo; }
134 const HexagonRegisterInfo *getRegisterInfo() const override {
135 return &InstrInfo.getRegisterInfo();
136 }
137 const HexagonTargetLowering *getTargetLowering() const override {
138 return &TLInfo;
139 }
140 const HexagonFrameLowering *getFrameLowering() const override {
141 return &FrameLowering;
142 }
144 return &TSInfo;
145 }
146
148 StringRef FS);
149
150 void initLibcallLoweringInfo(LibcallLoweringInfo &Info) const override;
151
152 /// ParseSubtargetFeatures - Parses features string setting specified
153 /// subtarget options. Definition of function is auto generated by tblgen.
155
156 bool isXRaySupported() const override { return true; }
157
158 bool hasV5Ops() const {
160 }
161 bool hasV5OpsOnly() const {
163 }
164 bool hasV55Ops() const {
166 }
167 bool hasV55OpsOnly() const {
169 }
170 bool hasV60Ops() const {
172 }
173 bool hasV60OpsOnly() const {
175 }
176 bool hasV62Ops() const {
178 }
179 bool hasV62OpsOnly() const {
181 }
182 bool hasV65Ops() const {
184 }
185 bool hasV65OpsOnly() const {
187 }
188 bool hasV66Ops() const {
190 }
191 bool hasV66OpsOnly() const {
193 }
194 bool hasV67Ops() const {
196 }
197 bool hasV67OpsOnly() const {
199 }
200 bool hasV68Ops() const {
202 }
203 bool hasV68OpsOnly() const {
205 }
206 bool hasV69Ops() const {
208 }
209 bool hasV69OpsOnly() const {
211 }
212 bool hasV71Ops() const {
214 }
215 bool hasV71OpsOnly() const {
217 }
218 bool hasV73Ops() const {
220 }
221 bool hasV73OpsOnly() const {
223 }
224 bool hasV75Ops() const {
226 }
227 bool hasV75OpsOnly() const {
229 }
230 bool hasV79Ops() const {
232 }
233 bool hasV79OpsOnly() const {
235 }
236 bool useHVXV79Ops() const {
238 }
239 bool useHVXV79OpsOnly() const {
241 }
242 bool hasV81Ops() const {
244 }
245 bool hasV81OpsOnly() const {
247 }
248 bool useHVXV81Ops() const {
250 }
251 bool hasV83Ops() const {
253 }
254 bool hasV83OpsOnly() const {
256 }
257 bool useHVXV83Ops() const {
259 }
260 bool hasV85Ops() const {
262 }
263 bool hasV85OpsOnly() const {
265 }
266 bool useHVXV85Ops() const {
268 }
269
270 bool useAudioOps() const { return UseAudioOps; }
271 bool useCompound() const { return UseCompound; }
272 bool useLongCalls() const { return UseLongCalls; }
273 bool useMemops() const { return UseMemops; }
274 bool usePackets() const { return UsePackets; }
275 bool useNewValueJumps() const { return UseNewValueJumps; }
276 bool useNewValueStores() const { return UseNewValueStores; }
277 bool useSmallData() const { return UseSmallData; }
278 bool useZRegOps() const { return UseZRegOps; }
279 bool useHLXOps() const { return UseHLXOps; }
280 bool useHLX2048BOps() const {
281 return UseHLXOps && HexagonProcFamily == HLX2048B;
282 }
283 bool useCabac() const { return UseCabac; }
284
285 bool isTinyCore() const { return HexagonProcFamily == TinyCore; }
286 bool isTinyCoreWithDuplex() const { return isTinyCore() && EnableDuplex; }
287
288 bool useHVXIEEEFPOps() const { return UseHVXIEEEFPOps && useHVXOps(); }
289 bool useHVXQFloatOps() const {
290 return UseHVXQFloatOps && HexagonHVXVersion >= Hexagon::ArchEnum::V68;
291 }
292 bool useHVXFloatingPoint() const { return UseHVXFloatingPoint; }
293 bool useHVXOps() const {
295 }
296 bool useHVXV60Ops() const {
298 }
299 bool useHVXV62Ops() const {
301 }
302 bool useHVXV65Ops() const {
304 }
305 bool useHVXV66Ops() const {
307 }
308 bool useHVXV67Ops() const {
310 }
311 bool useHVXV68Ops() const {
313 }
314 bool useHVXV69Ops() const {
316 }
317 bool useHVXV71Ops() const {
319 }
320 bool useHVXV73Ops() const {
322 }
323 bool useHVX128BOps() const { return useHVXOps() && UseHVX128BOps; }
324 bool useHVX64BOps() const { return useHVXOps() && UseHVX64BOps; }
325
326 bool hasMemNoShuf() const { return HasMemNoShuf; }
327 bool isRegisterReservedByUser(Register i) const override {
328 assert(i.id() < Hexagon::NUM_TARGET_REGS && "Register out of range");
329 return UserReservedRegister[i.id()];
330 }
331
332 /// Returns the register that holds the shadow call stack pointer. Defaults
333 /// to R18, overridable with the "scs-reg-rN" subtarget features.
334 Register getSCSPReg() const { return SCSPReg; }
335
336 bool usePredicatedCalls() const;
337
338 bool noreturnStackElim() const { return NoreturnStackElim; }
339
340 bool useBSBScheduling() const { return UseBSBScheduling; }
341 bool enableMachineScheduler() const override;
342
343 // Always use the TargetLowering default scheduler.
344 // FIXME: This will use the vliw scheduler which is probably just hurting
345 // compiler time and will be removed eventually anyway.
346 bool enableMachineSchedDefaultSched() const override { return false; }
347
348 // For use with PostRAScheduling: get the anti-dependence breaking that should
349 // be performed before post-RA scheduling.
350 AntiDepBreakMode getAntiDepBreakMode() const override { return ANTIDEP_ALL; }
351 /// True if the subtarget should run a scheduler after register
352 /// allocation.
353 bool enablePostRAScheduler() const override { return true; }
354
355 bool enableSubRegLiveness() const override;
356
357 const std::string &getCPUString () const { return CPUString; }
358
362
364 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations)
365 const override;
366
367 void getSMSMutations(
368 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations)
369 const override;
370
371 /// Enable use of alias analysis during code generation (during MI
372 /// scheduling, DAGCombine, etc.).
373 bool useAA() const override;
374
375 /// Perform target specific adjustments to the latency of a schedule
376 /// dependency.
377 void adjustSchedDependency(SUnit *Def, int DefOpIdx, SUnit *Use, int UseOpIdx,
378 SDep &Dep,
379 const TargetSchedModel *SchedModel) const override;
380
381 unsigned getVectorLength() const {
382 assert(useHVXOps());
383 if (useHVX64BOps())
384 return 64;
385 if (useHVX128BOps())
386 return 128;
387 llvm_unreachable("Invalid HVX vector length settings");
388 }
389
391 static MVT Types[] = {MVT::i8, MVT::i16, MVT::i32};
392 static MVT TypesV68[] = {MVT::i8, MVT::i16, MVT::i32, MVT::f16, MVT::f32};
393 static MVT TypesV81[] = {MVT::i8, MVT::i16, MVT::i32,
394 MVT::f16, MVT::bf16, MVT::f32};
395
397 return ArrayRef(TypesV81);
399 return ArrayRef(TypesV68);
400 return ArrayRef(Types);
401 }
402
403 bool isHVXElementType(MVT Ty, bool IncludeBool = false) const;
404 bool isHVXVectorType(EVT VecTy, bool IncludeBool = false) const;
405 bool isTypeForHVX(Type *VecTy, bool IncludeBool = false) const;
406
407 unsigned getHLXVectorLength() const {
408 assert(useHLXOps());
409 if (useHLX2048BOps())
410 return 2048;
411 llvm_unreachable("Invalid HLX vector length settings");
412 }
413
415 static MVT Types[] = {MVT::i8, MVT::i16, MVT::i32};
416
417 return ArrayRef(Types);
418 }
419
420 bool isHLXElementType(MVT Ty) const;
421 bool isHLXVectorType(EVT VecTy) const;
422 bool isTypeForHLX(Type *VecTy) const;
423
425 if (isHVXVectorType(Ty, true))
426 return Align(getVectorLength());
427 return Align(std::max<unsigned>(1, Ty.getSizeInBits() / 8));
428 }
429
430 unsigned getL1CacheLineSize() const;
431 unsigned getL1PrefetchDistance() const;
432
433 Intrinsic::ID getIntrinsicId(unsigned Opc) const;
434
435private:
436 // Helper function responsible for increasing the latency only.
437 int updateLatency(MachineInstr &SrcInst, MachineInstr &DstInst,
438 bool IsArtificial, int Latency) const;
439 void restoreLatency(SUnit *Src, SUnit *Dst) const;
440 void changeLatency(SUnit *Src, SUnit *Dst, unsigned Lat) const;
441 bool isBestZeroLatency(SUnit *Src, SUnit *Dst, const HexagonInstrInfo *TII,
443 SmallPtrSet<SUnit *, 4> &ExclDst) const;
444};
445
446} // end namespace llvm
447
448#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 isTypeForHLX(Type *VecTy) const
bool enableMachineSchedDefaultSched() const override
const HexagonInstrInfo * getInstrInfo() const override
const HexagonFrameLowering * getFrameLowering() const override
Hexagon::ArchEnum HexagonHVXVersion
unsigned getHLXVectorLength() const
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
ArrayRef< MVT > getHLXElementTypes() 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
bool isHLXElementType(MVT Ty) const
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 isHLXVectorType(EVT VecTy) const
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
void apply(ScheduleDAGInstrs *DAG) override