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