1 //===-- SystemZSubtarget.h - SystemZ subtarget information -----*- 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 SystemZ specific subclass of TargetSubtargetInfo.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZSUBTARGET_H
14 #define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZSUBTARGET_H
15 
16 #include "SystemZFrameLowering.h"
17 #include "SystemZISelLowering.h"
18 #include "SystemZInstrInfo.h"
19 #include "SystemZRegisterInfo.h"
20 #include "SystemZSelectionDAGInfo.h"
21 #include "llvm/ADT/Triple.h"
22 #include "llvm/CodeGen/TargetSubtargetInfo.h"
23 #include "llvm/IR/DataLayout.h"
24 #include <string>
25 
26 #define GET_SUBTARGETINFO_HEADER
27 #include "SystemZGenSubtargetInfo.inc"
28 
29 namespace llvm {
30 class GlobalValue;
31 class StringRef;
32 
33 class SystemZSubtarget : public SystemZGenSubtargetInfo {
34   virtual void anchor();
35 protected:
36   bool HasDistinctOps;
37   bool HasLoadStoreOnCond;
38   bool HasHighWord;
39   bool HasFPExtension;
40   bool HasPopulationCount;
41   bool HasMessageSecurityAssist3;
42   bool HasMessageSecurityAssist4;
43   bool HasResetReferenceBitsMultiple;
44   bool HasFastSerialization;
45   bool HasInterlockedAccess1;
46   bool HasMiscellaneousExtensions;
47   bool HasExecutionHint;
48   bool HasLoadAndTrap;
49   bool HasTransactionalExecution;
50   bool HasProcessorAssist;
51   bool HasDFPZonedConversion;
52   bool HasEnhancedDAT2;
53   bool HasVector;
54   bool HasLoadStoreOnCond2;
55   bool HasLoadAndZeroRightmostByte;
56   bool HasMessageSecurityAssist5;
57   bool HasDFPPackedConversion;
58   bool HasMiscellaneousExtensions2;
59   bool HasGuardedStorage;
60   bool HasMessageSecurityAssist7;
61   bool HasMessageSecurityAssist8;
62   bool HasVectorEnhancements1;
63   bool HasVectorPackedDecimal;
64   bool HasInsertReferenceBitsMultiple;
65   bool HasMiscellaneousExtensions3;
66   bool HasMessageSecurityAssist9;
67   bool HasVectorEnhancements2;
68   bool HasVectorPackedDecimalEnhancement;
69   bool HasEnhancedSort;
70   bool HasDeflateConversion;
71   bool HasVectorPackedDecimalEnhancement2;
72   bool HasNNPAssist;
73   bool HasBEAREnhancement;
74   bool HasResetDATProtection;
75   bool HasProcessorActivityInstrumentation;
76   bool HasSoftFloat;
77 
78 private:
79   Triple TargetTriple;
80   std::unique_ptr<SystemZCallingConventionRegisters> SpecialRegisters;
81   SystemZInstrInfo InstrInfo;
82   SystemZTargetLowering TLInfo;
83   SystemZSelectionDAGInfo TSInfo;
84   std::unique_ptr<const SystemZFrameLowering> FrameLowering;
85 
86   SystemZSubtarget &initializeSubtargetDependencies(StringRef CPU,
87                                                     StringRef TuneCPU,
88                                                     StringRef FS);
89   SystemZCallingConventionRegisters *initializeSpecialRegisters();
90 
91 public:
92   SystemZSubtarget(const Triple &TT, const std::string &CPU,
93                    const std::string &TuneCPU, const std::string &FS,
94                    const TargetMachine &TM);
95 
96   SystemZCallingConventionRegisters *getSpecialRegisters() const {
97     assert(SpecialRegisters && "Unsupported SystemZ calling convention");
98     return SpecialRegisters.get();
99   }
100 
101   template <class SR> SR &getSpecialRegisters() const {
102     return *static_cast<SR *>(getSpecialRegisters());
103   }
104 
105   const TargetFrameLowering *getFrameLowering() const override {
106     return FrameLowering.get();
107   }
108 
109   template <class TFL> const TFL *getFrameLowering() const {
110     return static_cast<const TFL *>(getFrameLowering());
111   }
112 
113   const SystemZInstrInfo *getInstrInfo() const override { return &InstrInfo; }
114   const SystemZRegisterInfo *getRegisterInfo() const override {
115     return &InstrInfo.getRegisterInfo();
116   }
117   const SystemZTargetLowering *getTargetLowering() const override {
118     return &TLInfo;
119   }
120   const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
121     return &TSInfo;
122   }
123 
124   // True if the subtarget should run MachineScheduler after aggressive
125   // coalescing. This currently replaces the SelectionDAG scheduler with the
126   // "source" order scheduler.
127   bool enableMachineScheduler() const override { return true; }
128 
129   // This is important for reducing register pressure in vector code.
130   bool useAA() const override { return true; }
131 
132   // Always enable the early if-conversion pass.
133   bool enableEarlyIfConversion() const override { return true; }
134 
135   // Enable tracking of subregister liveness in register allocator.
136   bool enableSubRegLiveness() const override;
137 
138   // Automatically generated by tblgen.
139   void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
140 
141   // Return true if the target has the distinct-operands facility.
142   bool hasDistinctOps() const { return HasDistinctOps; }
143 
144   // Return true if the target has the load/store-on-condition facility.
145   bool hasLoadStoreOnCond() const { return HasLoadStoreOnCond; }
146 
147   // Return true if the target has the load/store-on-condition facility 2.
148   bool hasLoadStoreOnCond2() const { return HasLoadStoreOnCond2; }
149 
150   // Return true if the target has the high-word facility.
151   bool hasHighWord() const { return HasHighWord; }
152 
153   // Return true if the target has the floating-point extension facility.
154   bool hasFPExtension() const { return HasFPExtension; }
155 
156   // Return true if the target has the population-count facility.
157   bool hasPopulationCount() const { return HasPopulationCount; }
158 
159   // Return true if the target has the message-security-assist
160   // extension facility 3.
161   bool hasMessageSecurityAssist3() const { return HasMessageSecurityAssist3; }
162 
163   // Return true if the target has the message-security-assist
164   // extension facility 4.
165   bool hasMessageSecurityAssist4() const { return HasMessageSecurityAssist4; }
166 
167   // Return true if the target has the reset-reference-bits-multiple facility.
168   bool hasResetReferenceBitsMultiple() const {
169     return HasResetReferenceBitsMultiple;
170   }
171 
172   // Return true if the target has the fast-serialization facility.
173   bool hasFastSerialization() const { return HasFastSerialization; }
174 
175   // Return true if the target has interlocked-access facility 1.
176   bool hasInterlockedAccess1() const { return HasInterlockedAccess1; }
177 
178   // Return true if the target has the miscellaneous-extensions facility.
179   bool hasMiscellaneousExtensions() const {
180     return HasMiscellaneousExtensions;
181   }
182 
183   // Return true if the target has the execution-hint facility.
184   bool hasExecutionHint() const { return HasExecutionHint; }
185 
186   // Return true if the target has the load-and-trap facility.
187   bool hasLoadAndTrap() const { return HasLoadAndTrap; }
188 
189   // Return true if the target has the transactional-execution facility.
190   bool hasTransactionalExecution() const { return HasTransactionalExecution; }
191 
192   // Return true if the target has the processor-assist facility.
193   bool hasProcessorAssist() const { return HasProcessorAssist; }
194 
195   // Return true if the target has the DFP zoned-conversion facility.
196   bool hasDFPZonedConversion() const { return HasDFPZonedConversion; }
197 
198   // Return true if the target has the enhanced-DAT facility 2.
199   bool hasEnhancedDAT2() const { return HasEnhancedDAT2; }
200 
201   // Return true if the target has the load-and-zero-rightmost-byte facility.
202   bool hasLoadAndZeroRightmostByte() const {
203     return HasLoadAndZeroRightmostByte;
204   }
205 
206   // Return true if the target has the message-security-assist
207   // extension facility 5.
208   bool hasMessageSecurityAssist5() const { return HasMessageSecurityAssist5; }
209 
210   // Return true if the target has the DFP packed-conversion facility.
211   bool hasDFPPackedConversion() const { return HasDFPPackedConversion; }
212 
213   // Return true if the target has the vector facility.
214   bool hasVector() const { return HasVector; }
215 
216   // Return true if the target has the miscellaneous-extensions facility 2.
217   bool hasMiscellaneousExtensions2() const {
218     return HasMiscellaneousExtensions2;
219   }
220 
221   // Return true if the target has the guarded-storage facility.
222   bool hasGuardedStorage() const { return HasGuardedStorage; }
223 
224   // Return true if the target has the message-security-assist
225   // extension facility 7.
226   bool hasMessageSecurityAssist7() const { return HasMessageSecurityAssist7; }
227 
228   // Return true if the target has the message-security-assist
229   // extension facility 8.
230   bool hasMessageSecurityAssist8() const { return HasMessageSecurityAssist8; }
231 
232   // Return true if the target has the vector-enhancements facility 1.
233   bool hasVectorEnhancements1() const { return HasVectorEnhancements1; }
234 
235   // Return true if the target has the vector-packed-decimal facility.
236   bool hasVectorPackedDecimal() const { return HasVectorPackedDecimal; }
237 
238   // Return true if the target has the insert-reference-bits-multiple facility.
239   bool hasInsertReferenceBitsMultiple() const {
240     return HasInsertReferenceBitsMultiple;
241   }
242 
243   // Return true if the target has the miscellaneous-extensions facility 3.
244   bool hasMiscellaneousExtensions3() const {
245     return HasMiscellaneousExtensions3;
246   }
247 
248   // Return true if the target has the message-security-assist
249   // extension facility 9.
250   bool hasMessageSecurityAssist9() const { return HasMessageSecurityAssist9; }
251 
252   // Return true if the target has the vector-enhancements facility 2.
253   bool hasVectorEnhancements2() const { return HasVectorEnhancements2; }
254 
255   // Return true if the target has the vector-packed-decimal
256   // enhancement facility.
257   bool hasVectorPackedDecimalEnhancement() const {
258     return HasVectorPackedDecimalEnhancement;
259   }
260 
261   // Return true if the target has the enhanced-sort facility.
262   bool hasEnhancedSort() const { return HasEnhancedSort; }
263 
264   // Return true if the target has the deflate-conversion facility.
265   bool hasDeflateConversion() const { return HasDeflateConversion; }
266 
267   // Return true if the target has the vector-packed-decimal
268   // enhancement facility 2.
269   bool hasVectorPackedDecimalEnhancement2() const {
270     return HasVectorPackedDecimalEnhancement2;
271   }
272 
273   // Return true if the target has the NNP-assist facility.
274   bool hasNNPAssist() const { return HasNNPAssist; }
275 
276   // Return true if the target has the BEAR-enhancement facility.
277   bool hasBEAREnhancement() const { return HasBEAREnhancement; }
278 
279   // Return true if the target has the reset-DAT-protection facility.
280   bool hasResetDATProtection() const { return HasResetDATProtection; }
281 
282   // Return true if the target has the processor-activity-instrumentation
283   // facility.
284   bool hasProcessorActivityInstrumentation() const {
285     return HasProcessorActivityInstrumentation;
286   }
287 
288   // Return true if soft float should be used.
289   bool hasSoftFloat() const { return HasSoftFloat; }
290 
291   // Return true if GV can be accessed using LARL for reloc model RM
292   // and code model CM.
293   bool isPC32DBLSymbol(const GlobalValue *GV, CodeModel::Model CM) const;
294 
295   bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
296 
297   // Returns TRUE if we are generating GOFF object code
298   bool isTargetGOFF() const { return TargetTriple.isOSBinFormatGOFF(); }
299 
300   // Returns TRUE if we are using XPLINK64 linkage convention
301   bool isTargetXPLINK64() const { return (isTargetGOFF() && isTargetzOS()); }
302 
303   // Returns TRUE if we are generating code for a s390x machine running zOS
304   bool isTargetzOS() const { return TargetTriple.isOSzOS(); }
305 };
306 } // end namespace llvm
307 
308 #endif
309