]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/Target/Hexagon/HexagonSubtarget.h
Vendor import of llvm trunk r321414:
[FreeBSD/FreeBSD.git] / lib / Target / Hexagon / HexagonSubtarget.h
1 //===- HexagonSubtarget.h - Define Subtarget for the Hexagon ----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the Hexagon specific subclass of TargetSubtarget.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONSUBTARGET_H
15 #define LLVM_LIB_TARGET_HEXAGON_HEXAGONSUBTARGET_H
16
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"
28 #include <memory>
29 #include <string>
30 #include <vector>
31
32 #define GET_SUBTARGETINFO_HEADER
33 #include "HexagonGenSubtargetInfo.inc"
34
35 #define Hexagon_SMALL_DATA_THRESHOLD 8
36 #define Hexagon_SLOTS 4
37
38 namespace llvm {
39
40 class MachineInstr;
41 class SDep;
42 class SUnit;
43 class TargetMachine;
44 class Triple;
45
46 class HexagonSubtarget : public HexagonGenSubtargetInfo {
47   virtual void anchor();
48
49   bool UseMemOps, UseHVX64BOps, UseHVX128BOps;
50   bool UseLongCalls;
51   bool ModeIEEERndNear;
52
53   bool HasMemNoShuf = false;
54   bool EnableDuplex = false;
55 public:
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
60   /// default for V60.
61   bool UseBSBScheduling;
62
63   struct UsrOverflowMutation : public ScheduleDAGMutation {
64     void apply(ScheduleDAGInstrs *DAG) override;
65   };
66   struct HVXMemLatencyMutation : public ScheduleDAGMutation {
67     void apply(ScheduleDAGInstrs *DAG) override;
68   };
69   struct CallMutation : public ScheduleDAGMutation {
70     void apply(ScheduleDAGInstrs *DAG) override;
71   private:
72     bool shouldTFRICallBind(const HexagonInstrInfo &HII,
73           const SUnit &Inst1, const SUnit &Inst2) const;
74   };
75   struct BankConflictMutation : public ScheduleDAGMutation {
76     void apply(ScheduleDAGInstrs *DAG) override;
77   };
78
79 private:
80   std::string CPUString;
81   HexagonInstrInfo InstrInfo;
82   HexagonRegisterInfo RegInfo;
83   HexagonTargetLowering TLInfo;
84   HexagonSelectionDAGInfo TSInfo;
85   HexagonFrameLowering FrameLowering;
86   InstrItineraryData InstrItins;
87
88 public:
89   HexagonSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
90                    const TargetMachine &TM);
91
92   /// getInstrItins - Return the instruction itineraries based on subtarget
93   /// selection.
94   const InstrItineraryData *getInstrItineraryData() const override {
95     return &InstrItins;
96   }
97   const HexagonInstrInfo *getInstrInfo() const override { return &InstrInfo; }
98   const HexagonRegisterInfo *getRegisterInfo() const override {
99     return &RegInfo;
100   }
101   const HexagonTargetLowering *getTargetLowering() const override {
102     return &TLInfo;
103   }
104   const HexagonFrameLowering *getFrameLowering() const override {
105     return &FrameLowering;
106   }
107   const HexagonSelectionDAGInfo *getSelectionDAGInfo() const override {
108     return &TSInfo;
109   }
110
111   HexagonSubtarget &initializeSubtargetDependencies(StringRef CPU,
112                                                     StringRef FS);
113
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);
117
118   bool useMemOps() const { return UseMemOps; }
119   bool hasV5TOps() const {
120     return getHexagonArchVersion() >= Hexagon::ArchEnum::V5;
121   }
122   bool hasV5TOpsOnly() const {
123     return getHexagonArchVersion() == Hexagon::ArchEnum::V5;
124   }
125   bool hasV55TOps() const {
126     return getHexagonArchVersion() >= Hexagon::ArchEnum::V55;
127   }
128   bool hasV55TOpsOnly() const {
129     return getHexagonArchVersion() == Hexagon::ArchEnum::V55;
130   }
131   bool hasV60TOps() const {
132     return getHexagonArchVersion() >= Hexagon::ArchEnum::V60;
133   }
134   bool hasV60TOpsOnly() const {
135     return getHexagonArchVersion() == Hexagon::ArchEnum::V60;
136   }
137   bool hasV62TOps() const {
138     return getHexagonArchVersion() >= Hexagon::ArchEnum::V62;
139   }
140   bool hasV62TOpsOnly() const {
141     return getHexagonArchVersion() == Hexagon::ArchEnum::V62;
142   }
143   bool hasV65TOps() const {
144     return getHexagonArchVersion() >= Hexagon::ArchEnum::V65;
145   }
146   bool hasV65TOpsOnly() const {
147     return getHexagonArchVersion() == Hexagon::ArchEnum::V65;
148   }
149
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;
157
158   bool useBSBScheduling() const { return UseBSBScheduling; }
159   bool enableMachineScheduler() const override;
160
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; }
165
166   AntiDepBreakMode getAntiDepBreakMode() const override { return ANTIDEP_ALL; }
167   bool enablePostRAScheduler() const override { return true; }
168
169   bool enableSubRegLiveness() const override;
170
171   const std::string &getCPUString () const { return CPUString; }
172
173   // Threshold for small data section
174   unsigned getSmallDataThreshold() const {
175     return Hexagon_SMALL_DATA_THRESHOLD;
176   }
177
178   const Hexagon::ArchEnum &getHexagonArchVersion() const {
179     return HexagonArchVersion;
180   }
181
182   void getPostRAMutations(
183       std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations)
184       const override;
185
186   void getSMSMutations(
187       std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations)
188       const override;
189
190   /// \brief Enable use of alias analysis during code generation (during MI
191   /// scheduling, DAGCombine, etc.).
192   bool useAA() const override;
193
194   /// \brief Perform target specific adjustments to the latency of a schedule
195   /// dependency.
196   void adjustSchedDependency(SUnit *def, SUnit *use, SDep& dep) const override;
197
198   unsigned getVectorLength() const {
199     assert(useHVXOps());
200     if (useHVX64BOps())
201       return 64;
202     if (useHVX128BOps())
203       return 128;
204     llvm_unreachable("Invalid HVX vector length settings");
205   }
206
207   ArrayRef<MVT> getHVXElementTypes() const {
208     static MVT Types[] = { MVT::i8, MVT::i16, MVT::i32 };
209     return makeArrayRef(Types);
210   }
211
212   bool isHVXVectorType(MVT VecTy, bool IncludeBool = false) const {
213     if (!VecTy.isVector() || !useHVXOps())
214       return false;
215     MVT ElemTy = VecTy.getVectorElementType();
216     if (!IncludeBool && ElemTy == MVT::i1)
217       return false;
218
219     unsigned HwLen = getVectorLength();
220     unsigned NumElems = VecTy.getVectorNumElements();
221     ArrayRef<MVT> ElemTypes = getHVXElementTypes();
222
223     if (IncludeBool && ElemTy == MVT::i1) {
224       // Special case for the v512i1, etc.
225       if (8*HwLen == NumElems)
226         return true;
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)
231           return true;
232       return false;
233     }
234
235     unsigned VecWidth = VecTy.getSizeInBits();
236     if (VecWidth != 8*HwLen && VecWidth != 16*HwLen)
237       return false;
238     return llvm::any_of(ElemTypes, [ElemTy] (MVT T) { return ElemTy == T; });
239   }
240
241   unsigned getL1CacheLineSize() const;
242   unsigned getL1PrefetchDistance() const;
243
244 private:
245   // Helper function responsible for increasing the latency only.
246   void updateLatency(MachineInstr &SrcInst, MachineInstr &DstInst, SDep &Dep)
247       const;
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;
252 };
253
254 } // end namespace llvm
255
256 #endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONSUBTARGET_H