1 //===- HexagonSubtarget.h - Define Subtarget for the Hexagon ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the Hexagon specific subclass of TargetSubtarget.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONSUBTARGET_H
15 #define LLVM_LIB_TARGET_HEXAGON_HEXAGONSUBTARGET_H
17 #include "HexagonDepArch.h"
18 #include "HexagonFrameLowering.h"
19 #include "HexagonISelLowering.h"
20 #include "HexagonInstrInfo.h"
21 #include "HexagonRegisterInfo.h"
22 #include "HexagonSelectionDAGInfo.h"
23 #include "llvm/ADT/SmallSet.h"
24 #include "llvm/ADT/StringRef.h"
25 #include "llvm/CodeGen/ScheduleDAGMutation.h"
26 #include "llvm/CodeGen/TargetSubtargetInfo.h"
27 #include "llvm/MC/MCInstrItineraries.h"
32 #define GET_SUBTARGETINFO_HEADER
33 #include "HexagonGenSubtargetInfo.inc"
35 #define Hexagon_SMALL_DATA_THRESHOLD 8
36 #define Hexagon_SLOTS 4
46 class HexagonSubtarget : public HexagonGenSubtargetInfo {
47 virtual void anchor();
49 bool UseMemOps, UseHVX64BOps, UseHVX128BOps;
53 bool HasMemNoShuf = false;
54 bool EnableDuplex = false;
56 Hexagon::ArchEnum HexagonArchVersion;
57 Hexagon::ArchEnum HexagonHVXVersion = Hexagon::ArchEnum::V4;
58 CodeGenOpt::Level OptLevel;
59 /// True if the target should use Back-Skip-Back scheduling. This is the
61 bool UseBSBScheduling;
63 struct UsrOverflowMutation : public ScheduleDAGMutation {
64 void apply(ScheduleDAGInstrs *DAG) override;
66 struct HVXMemLatencyMutation : public ScheduleDAGMutation {
67 void apply(ScheduleDAGInstrs *DAG) override;
69 struct CallMutation : public ScheduleDAGMutation {
70 void apply(ScheduleDAGInstrs *DAG) override;
72 bool shouldTFRICallBind(const HexagonInstrInfo &HII,
73 const SUnit &Inst1, const SUnit &Inst2) const;
75 struct BankConflictMutation : public ScheduleDAGMutation {
76 void apply(ScheduleDAGInstrs *DAG) override;
80 std::string CPUString;
81 HexagonInstrInfo InstrInfo;
82 HexagonRegisterInfo RegInfo;
83 HexagonTargetLowering TLInfo;
84 HexagonSelectionDAGInfo TSInfo;
85 HexagonFrameLowering FrameLowering;
86 InstrItineraryData InstrItins;
89 HexagonSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
90 const TargetMachine &TM);
92 /// getInstrItins - Return the instruction itineraries based on subtarget
94 const InstrItineraryData *getInstrItineraryData() const override {
97 const HexagonInstrInfo *getInstrInfo() const override { return &InstrInfo; }
98 const HexagonRegisterInfo *getRegisterInfo() const override {
101 const HexagonTargetLowering *getTargetLowering() const override {
104 const HexagonFrameLowering *getFrameLowering() const override {
105 return &FrameLowering;
107 const HexagonSelectionDAGInfo *getSelectionDAGInfo() const override {
111 HexagonSubtarget &initializeSubtargetDependencies(StringRef CPU,
114 /// ParseSubtargetFeatures - Parses features string setting specified
115 /// subtarget options. Definition of function is auto generated by tblgen.
116 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
118 bool useMemOps() const { return UseMemOps; }
119 bool hasV5TOps() const {
120 return getHexagonArchVersion() >= Hexagon::ArchEnum::V5;
122 bool hasV5TOpsOnly() const {
123 return getHexagonArchVersion() == Hexagon::ArchEnum::V5;
125 bool hasV55TOps() const {
126 return getHexagonArchVersion() >= Hexagon::ArchEnum::V55;
128 bool hasV55TOpsOnly() const {
129 return getHexagonArchVersion() == Hexagon::ArchEnum::V55;
131 bool hasV60TOps() const {
132 return getHexagonArchVersion() >= Hexagon::ArchEnum::V60;
134 bool hasV60TOpsOnly() const {
135 return getHexagonArchVersion() == Hexagon::ArchEnum::V60;
137 bool hasV62TOps() const {
138 return getHexagonArchVersion() >= Hexagon::ArchEnum::V62;
140 bool hasV62TOpsOnly() const {
141 return getHexagonArchVersion() == Hexagon::ArchEnum::V62;
143 bool hasV65TOps() const {
144 return getHexagonArchVersion() >= Hexagon::ArchEnum::V65;
146 bool hasV65TOpsOnly() const {
147 return getHexagonArchVersion() == Hexagon::ArchEnum::V65;
150 bool modeIEEERndNear() const { return ModeIEEERndNear; }
151 bool useHVXOps() const { return HexagonHVXVersion > Hexagon::ArchEnum::V4; }
152 bool useHVX128BOps() const { return useHVXOps() && UseHVX128BOps; }
153 bool useHVX64BOps() const { return useHVXOps() && UseHVX64BOps; }
154 bool hasMemNoShuf() const { return HasMemNoShuf; }
155 bool useLongCalls() const { return UseLongCalls; }
156 bool usePredicatedCalls() const;
158 bool useBSBScheduling() const { return UseBSBScheduling; }
159 bool enableMachineScheduler() const override;
161 // Always use the TargetLowering default scheduler.
162 // FIXME: This will use the vliw scheduler which is probably just hurting
163 // compiler time and will be removed eventually anyway.
164 bool enableMachineSchedDefaultSched() const override { return false; }
166 AntiDepBreakMode getAntiDepBreakMode() const override { return ANTIDEP_ALL; }
167 bool enablePostRAScheduler() const override { return true; }
169 bool enableSubRegLiveness() const override;
171 const std::string &getCPUString () const { return CPUString; }
173 // Threshold for small data section
174 unsigned getSmallDataThreshold() const {
175 return Hexagon_SMALL_DATA_THRESHOLD;
178 const Hexagon::ArchEnum &getHexagonArchVersion() const {
179 return HexagonArchVersion;
182 void getPostRAMutations(
183 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations)
186 void getSMSMutations(
187 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations)
190 /// \brief Enable use of alias analysis during code generation (during MI
191 /// scheduling, DAGCombine, etc.).
192 bool useAA() const override;
194 /// \brief Perform target specific adjustments to the latency of a schedule
196 void adjustSchedDependency(SUnit *def, SUnit *use, SDep& dep) const override;
198 unsigned getVectorLength() const {
204 llvm_unreachable("Invalid HVX vector length settings");
207 ArrayRef<MVT> getHVXElementTypes() const {
208 static MVT Types[] = { MVT::i8, MVT::i16, MVT::i32 };
209 return makeArrayRef(Types);
212 bool isHVXVectorType(MVT VecTy, bool IncludeBool = false) const {
213 if (!VecTy.isVector() || !useHVXOps())
215 MVT ElemTy = VecTy.getVectorElementType();
216 if (!IncludeBool && ElemTy == MVT::i1)
219 unsigned HwLen = getVectorLength();
220 unsigned NumElems = VecTy.getVectorNumElements();
221 ArrayRef<MVT> ElemTypes = getHVXElementTypes();
223 if (IncludeBool && ElemTy == MVT::i1) {
224 // Special case for the v512i1, etc.
225 if (8*HwLen == NumElems)
227 // Boolean HVX vector types are formed from regular HVX vector types
228 // by replacing the element type with i1.
229 for (MVT T : ElemTypes)
230 if (NumElems * T.getSizeInBits() == 8*HwLen)
235 unsigned VecWidth = VecTy.getSizeInBits();
236 if (VecWidth != 8*HwLen && VecWidth != 16*HwLen)
238 return llvm::any_of(ElemTypes, [ElemTy] (MVT T) { return ElemTy == T; });
241 unsigned getL1CacheLineSize() const;
242 unsigned getL1PrefetchDistance() const;
245 // Helper function responsible for increasing the latency only.
246 void updateLatency(MachineInstr &SrcInst, MachineInstr &DstInst, SDep &Dep)
248 void restoreLatency(SUnit *Src, SUnit *Dst) const;
249 void changeLatency(SUnit *Src, SUnit *Dst, unsigned Lat) const;
250 bool isBestZeroLatency(SUnit *Src, SUnit *Dst, const HexagonInstrInfo *TII,
251 SmallSet<SUnit*, 4> &ExclSrc, SmallSet<SUnit*, 4> &ExclDst) const;
254 } // end namespace llvm
256 #endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONSUBTARGET_H