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 MachineInstr;
39class SDep;
40class SUnit;
41class TargetMachine;
42class Triple;
43
45 virtual void anchor();
46
47 bool UseHVX64BOps = false;
48 bool UseHVX128BOps = false;
49
50 bool UseAudioOps = false;
51 bool UseCompound = false;
52 bool UseLongCalls = false;
53 bool UseMemops = false;
54 bool UsePackets = false;
55 bool UseNewValueJumps = false;
56 bool UseNewValueStores = false;
57 bool UseSmallData = false;
58 bool UseZRegOps = false;
59 bool UseHVXIEEEFPOps = false;
60 bool UseHVXQFloatOps = false;
61 bool UseHVXFloatingPoint = false;
62 bool UseCabac = false;
63
64 bool HasPreV65 = false;
65 bool HasMemNoShuf = false;
66 bool EnableDuplex = false;
67 std::bitset<Hexagon::NUM_TARGET_REGS> UserReservedRegister;
68 std::bitset<Hexagon::NUM_TARGET_REGS> SCSPointerRegister;
69 bool NoreturnStackElim = false;
70
71 /// Register holding the shadow call stack pointer, resolved from
72 /// SCSPointerRegister in initializeSubtargetDependencies().
73 Register SCSPReg;
74
75public:
79 /// True if the target should use Back-Skip-Back scheduling. This is the
80 /// default for V60.
82
84 void apply(ScheduleDAGInstrs *DAG) override;
85 };
87 void apply(ScheduleDAGInstrs *DAG) override;
88 };
90 void apply(ScheduleDAGInstrs *DAG) override;
91 private:
92 bool shouldTFRICallBind(const HexagonInstrInfo &HII,
93 const SUnit &Inst1, const SUnit &Inst2) const;
94 };
96 void apply(ScheduleDAGInstrs *DAG) override;
97 };
98
99private:
100 enum HexagonProcFamilyEnum { Others, TinyCore };
101
102 std::string CPUString;
103 HexagonProcFamilyEnum HexagonProcFamily = Others;
104 Triple TargetTriple;
105
106 // The following objects can use the TargetTriple, so they must be
107 // declared after it.
108 HexagonInstrInfo InstrInfo;
111 HexagonFrameLowering FrameLowering;
112 InstrItineraryData InstrItins;
113
114public:
115 HexagonSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
116 const TargetMachine &TM);
117
118 const Triple &getTargetTriple() const { return TargetTriple; }
119 bool isEnvironmentMusl() const {
120 return TargetTriple.getEnvironment() == Triple::Musl;
121 }
122
123 /// getInstrItins - Return the instruction itineraries based on subtarget
124 /// selection.
126 return &InstrItins;
127 }
128 const HexagonInstrInfo *getInstrInfo() const override { return &InstrInfo; }
129 const HexagonRegisterInfo *getRegisterInfo() const override {
130 return &InstrInfo.getRegisterInfo();
131 }
132 const HexagonTargetLowering *getTargetLowering() const override {
133 return &TLInfo;
134 }
135 const HexagonFrameLowering *getFrameLowering() const override {
136 return &FrameLowering;
137 }
139 return &TSInfo;
140 }
141
143 StringRef FS);
144
145 /// ParseSubtargetFeatures - Parses features string setting specified
146 /// subtarget options. Definition of function is auto generated by tblgen.
148
149 bool isXRaySupported() const override { return true; }
150
151 bool hasV5Ops() const {
153 }
154 bool hasV5OpsOnly() const {
156 }
157 bool hasV55Ops() const {
159 }
160 bool hasV55OpsOnly() const {
162 }
163 bool hasV60Ops() const {
165 }
166 bool hasV60OpsOnly() const {
168 }
169 bool hasV62Ops() const {
171 }
172 bool hasV62OpsOnly() const {
174 }
175 bool hasV65Ops() const {
177 }
178 bool hasV65OpsOnly() const {
180 }
181 bool hasV66Ops() const {
183 }
184 bool hasV66OpsOnly() const {
186 }
187 bool hasV67Ops() const {
189 }
190 bool hasV67OpsOnly() const {
192 }
193 bool hasV68Ops() const {
195 }
196 bool hasV68OpsOnly() const {
198 }
199 bool hasV69Ops() const {
201 }
202 bool hasV69OpsOnly() const {
204 }
205 bool hasV71Ops() const {
207 }
208 bool hasV71OpsOnly() const {
210 }
211 bool hasV73Ops() const {
213 }
214 bool hasV73OpsOnly() const {
216 }
217 bool hasV75Ops() const {
219 }
220 bool hasV75OpsOnly() const {
222 }
223 bool hasV79Ops() const {
225 }
226 bool hasV79OpsOnly() const {
228 }
229 bool useHVXV79Ops() const {
231 }
232 bool hasV81Ops() const {
234 }
235 bool hasV81OpsOnly() const {
237 }
238 bool useHVXV81Ops() const {
240 }
241
242 bool useAudioOps() const { return UseAudioOps; }
243 bool useCompound() const { return UseCompound; }
244 bool useLongCalls() const { return UseLongCalls; }
245 bool useMemops() const { return UseMemops; }
246 bool usePackets() const { return UsePackets; }
247 bool useNewValueJumps() const { return UseNewValueJumps; }
248 bool useNewValueStores() const { return UseNewValueStores; }
249 bool useSmallData() const { return UseSmallData; }
250 bool useZRegOps() const { return UseZRegOps; }
251 bool useCabac() const { return UseCabac; }
252
253 bool isTinyCore() const { return HexagonProcFamily == TinyCore; }
254 bool isTinyCoreWithDuplex() const { return isTinyCore() && EnableDuplex; }
255
256 bool useHVXIEEEFPOps() const { return UseHVXIEEEFPOps && useHVXOps(); }
257 bool useHVXQFloatOps() const {
258 return UseHVXQFloatOps && HexagonHVXVersion >= Hexagon::ArchEnum::V68;
259 }
260 bool useHVXFloatingPoint() const { return UseHVXFloatingPoint; }
261 bool useHVXOps() const {
263 }
264 bool useHVXV60Ops() const {
266 }
267 bool useHVXV62Ops() const {
269 }
270 bool useHVXV65Ops() const {
272 }
273 bool useHVXV66Ops() const {
275 }
276 bool useHVXV67Ops() const {
278 }
279 bool useHVXV68Ops() const {
281 }
282 bool useHVXV69Ops() const {
284 }
285 bool useHVXV71Ops() const {
287 }
288 bool useHVXV73Ops() const {
290 }
291 bool useHVX128BOps() const { return useHVXOps() && UseHVX128BOps; }
292 bool useHVX64BOps() const { return useHVXOps() && UseHVX64BOps; }
293
294 bool hasMemNoShuf() const { return HasMemNoShuf; }
295 bool isRegisterReservedByUser(Register i) const override {
296 assert(i.id() < Hexagon::NUM_TARGET_REGS && "Register out of range");
297 return UserReservedRegister[i.id()];
298 }
299
300 /// Returns the register that holds the shadow call stack pointer. Defaults
301 /// to R18, overridable with the "scs-reg-rN" subtarget features.
302 Register getSCSPReg() const { return SCSPReg; }
303
304 bool usePredicatedCalls() const;
305
306 bool noreturnStackElim() const { return NoreturnStackElim; }
307
308 bool useBSBScheduling() const { return UseBSBScheduling; }
309 bool enableMachineScheduler() const override;
310
311 // Always use the TargetLowering default scheduler.
312 // FIXME: This will use the vliw scheduler which is probably just hurting
313 // compiler time and will be removed eventually anyway.
314 bool enableMachineSchedDefaultSched() const override { return false; }
315
316 // For use with PostRAScheduling: get the anti-dependence breaking that should
317 // be performed before post-RA scheduling.
318 AntiDepBreakMode getAntiDepBreakMode() const override { return ANTIDEP_ALL; }
319 /// True if the subtarget should run a scheduler after register
320 /// allocation.
321 bool enablePostRAScheduler() const override { return true; }
322
323 bool enableSubRegLiveness() const override;
324
325 const std::string &getCPUString () const { return CPUString; }
326
330
332 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations)
333 const override;
334
335 void getSMSMutations(
336 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations)
337 const override;
338
339 /// Enable use of alias analysis during code generation (during MI
340 /// scheduling, DAGCombine, etc.).
341 bool useAA() const override;
342
343 /// Perform target specific adjustments to the latency of a schedule
344 /// dependency.
345 void adjustSchedDependency(SUnit *Def, int DefOpIdx, SUnit *Use, int UseOpIdx,
346 SDep &Dep,
347 const TargetSchedModel *SchedModel) const override;
348
349 unsigned getVectorLength() const {
350 assert(useHVXOps());
351 if (useHVX64BOps())
352 return 64;
353 if (useHVX128BOps())
354 return 128;
355 llvm_unreachable("Invalid HVX vector length settings");
356 }
357
359 static MVT Types[] = {MVT::i8, MVT::i16, MVT::i32};
360 static MVT TypesV68[] = {MVT::i8, MVT::i16, MVT::i32, MVT::f16, MVT::f32};
361 static MVT TypesV81[] = {MVT::i8, MVT::i16, MVT::i32,
362 MVT::f16, MVT::bf16, MVT::f32};
363
365 return ArrayRef(TypesV81);
367 return ArrayRef(TypesV68);
368 return ArrayRef(Types);
369 }
370
371 bool isHVXElementType(MVT Ty, bool IncludeBool = false) const;
372 bool isHVXVectorType(EVT VecTy, bool IncludeBool = false) const;
373 bool isTypeForHVX(Type *VecTy, bool IncludeBool = false) const;
374
376 if (isHVXVectorType(Ty, true))
377 return Align(getVectorLength());
378 return Align(std::max<unsigned>(1, Ty.getSizeInBits() / 8));
379 }
380
381 unsigned getL1CacheLineSize() const;
382 unsigned getL1PrefetchDistance() const;
383
384 Intrinsic::ID getIntrinsicId(unsigned Opc) const;
385
386private:
387 // Helper function responsible for increasing the latency only.
388 int updateLatency(MachineInstr &SrcInst, MachineInstr &DstInst,
389 bool IsArtificial, int Latency) const;
390 void restoreLatency(SUnit *Src, SUnit *Dst) const;
391 void changeLatency(SUnit *Src, SUnit *Dst, unsigned Lat) const;
392 bool isBestZeroLatency(SUnit *Src, SUnit *Dst, const HexagonInstrInfo *TII,
394 SmallPtrSet<SUnit *, 4> &ExclDst) const;
395};
396
397} // end namespace llvm
398
399#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 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.
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:52
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:149
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