LLVM  9.0.0svn
PPCSubtarget.h
Go to the documentation of this file.
1 //===-- PPCSubtarget.h - Define Subtarget for the PPC ----------*- 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 PowerPC specific subclass of TargetSubtargetInfo.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_LIB_TARGET_POWERPC_PPCSUBTARGET_H
14 #define LLVM_LIB_TARGET_POWERPC_PPCSUBTARGET_H
15 
16 #include "PPCFrameLowering.h"
17 #include "PPCISelLowering.h"
18 #include "PPCInstrInfo.h"
19 #include "llvm/ADT/Triple.h"
22 #include "llvm/IR/DataLayout.h"
24 #include <string>
25 
26 #define GET_SUBTARGETINFO_HEADER
27 #include "PPCGenSubtargetInfo.inc"
28 
29 // GCC #defines PPC on Linux but we use it as our namespace name
30 #undef PPC
31 
32 namespace llvm {
33 class StringRef;
34 
35 namespace PPC {
36  // -m directive values.
37  enum {
61  };
62 }
63 
64 class GlobalValue;
65 class TargetMachine;
66 
68 public:
69  enum POPCNTDKind {
72  POPCNTD_Fast
73  };
74 
75 protected:
76  /// TargetTriple - What processor and OS we're targeting.
78 
79  /// stackAlignment - The minimum alignment known to hold of the stack frame on
80  /// entry to the function and which must be maintained by every function.
81  unsigned StackAlignment;
82 
83  /// Selected instruction itineraries (one entry per itinerary class.)
85 
86  /// Which cpu directive was used.
87  unsigned DarwinDirective;
88 
89  /// Used by the ISel to turn in optimizations for POWER4-derived architectures
90  bool HasMFOCRF;
93  bool UseCRBits;
95  bool IsPPC64;
96  bool HasAltivec;
97  bool HasFPU;
98  bool HasSPE;
99  bool HasQPX;
100  bool HasVSX;
107  bool HasFCPSGN;
108  bool HasFSQRT;
109  bool HasFRE, HasFRES, HasFRSQRTE, HasFRSQRTES;
111  bool HasSTFIWX;
112  bool HasLFIWAX;
113  bool HasFPRND;
114  bool HasFPCVT;
115  bool HasISEL;
116  bool HasBPERMD;
117  bool HasExtDiv;
118  bool HasCMPB;
119  bool HasLDBRX;
120  bool IsBookE;
122  bool IsE500;
123  bool IsPPC4xx;
124  bool IsPPC6xx;
129  bool HasICBT;
133  bool HasHTM;
134  bool HasFusion;
136  bool IsISA3_0;
138  bool SecurePlt;
142 
144 
145  /// When targeting QPX running a stock PPC64 Linux kernel where the stack
146  /// alignment has not been changed, we need to keep the 16-byte alignment
147  /// of the stack.
149 
155 
156 public:
157  /// This constructor initializes the data members to match that
158  /// of the specified triple.
159  ///
160  PPCSubtarget(const Triple &TT, const std::string &CPU, const std::string &FS,
161  const PPCTargetMachine &TM);
162 
163  /// ParseSubtargetFeatures - Parses features string setting specified
164  /// subtarget options. Definition of function is auto generated by tblgen.
165  void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
166 
167  /// getStackAlignment - Returns the minimum alignment known to hold of the
168  /// stack frame on entry to the function and which must be maintained by every
169  /// function for this subtarget.
170  unsigned getStackAlignment() const { return StackAlignment; }
171 
172  /// getDarwinDirective - Returns the -m directive specified for the cpu.
173  ///
174  unsigned getDarwinDirective() const { return DarwinDirective; }
175 
176  /// getInstrItins - Return the instruction itineraries based on subtarget
177  /// selection.
178  const InstrItineraryData *getInstrItineraryData() const override {
179  return &InstrItins;
180  }
181 
182  const PPCFrameLowering *getFrameLowering() const override {
183  return &FrameLowering;
184  }
185  const PPCInstrInfo *getInstrInfo() const override { return &InstrInfo; }
186  const PPCTargetLowering *getTargetLowering() const override {
187  return &TLInfo;
188  }
189  const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
190  return &TSInfo;
191  }
192  const PPCRegisterInfo *getRegisterInfo() const override {
193  return &getInstrInfo()->getRegisterInfo();
194  }
195  const PPCTargetMachine &getTargetMachine() const { return TM; }
196 
197  /// initializeSubtargetDependencies - Initializes using a CPU and feature string
198  /// so that we can use initializer lists for subtarget initialization.
199  PPCSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);
200 
201 private:
202  void initializeEnvironment();
203  void initSubtargetFeatures(StringRef CPU, StringRef FS);
204 
205 public:
206  /// isPPC64 - Return true if we are generating code for 64-bit pointer mode.
207  ///
208  bool isPPC64() const;
209 
210  /// has64BitSupport - Return true if the selected CPU supports 64-bit
211  /// instructions, regardless of whether we are in 32-bit or 64-bit mode.
212  bool has64BitSupport() const { return Has64BitSupport; }
213  // useSoftFloat - Return true if soft-float option is turned on.
214  bool useSoftFloat() const { return !HasHardFloat; }
215 
216  /// use64BitRegs - Return true if in 64-bit mode or if we should use 64-bit
217  /// registers in 32-bit mode when possible. This can only true if
218  /// has64BitSupport() returns true.
219  bool use64BitRegs() const { return Use64BitRegs; }
220 
221  /// useCRBits - Return true if we should store and manipulate i1 values in
222  /// the individual condition register bits.
223  bool useCRBits() const { return UseCRBits; }
224 
225  /// hasLazyResolverStub - Return true if accesses to the specified global have
226  /// to go through a dyld lazy resolution stub. This means that an extra load
227  /// is required to get the address of the global.
228  bool hasLazyResolverStub(const GlobalValue *GV) const;
229 
230  // isLittleEndian - True if generating little-endian code
231  bool isLittleEndian() const { return IsLittleEndian; }
232 
233  // Specific obvious features.
234  bool hasFCPSGN() const { return HasFCPSGN; }
235  bool hasFSQRT() const { return HasFSQRT; }
236  bool hasFRE() const { return HasFRE; }
237  bool hasFRES() const { return HasFRES; }
238  bool hasFRSQRTE() const { return HasFRSQRTE; }
239  bool hasFRSQRTES() const { return HasFRSQRTES; }
240  bool hasRecipPrec() const { return HasRecipPrec; }
241  bool hasSTFIWX() const { return HasSTFIWX; }
242  bool hasLFIWAX() const { return HasLFIWAX; }
243  bool hasFPRND() const { return HasFPRND; }
244  bool hasFPCVT() const { return HasFPCVT; }
245  bool hasAltivec() const { return HasAltivec; }
246  bool hasSPE() const { return HasSPE; }
247  bool hasFPU() const { return HasFPU; }
248  bool hasQPX() const { return HasQPX; }
249  bool hasVSX() const { return HasVSX; }
250  bool needsTwoConstNR() const { return NeedsTwoConstNR; }
251  bool hasP8Vector() const { return HasP8Vector; }
252  bool hasP8Altivec() const { return HasP8Altivec; }
253  bool hasP8Crypto() const { return HasP8Crypto; }
254  bool hasP9Vector() const { return HasP9Vector; }
255  bool hasP9Altivec() const { return HasP9Altivec; }
256  bool hasMFOCRF() const { return HasMFOCRF; }
257  bool hasISEL() const { return HasISEL; }
258  bool hasBPERMD() const { return HasBPERMD; }
259  bool hasExtDiv() const { return HasExtDiv; }
260  bool hasCMPB() const { return HasCMPB; }
261  bool hasLDBRX() const { return HasLDBRX; }
262  bool isBookE() const { return IsBookE; }
263  bool hasOnlyMSYNC() const { return HasOnlyMSYNC; }
264  bool isPPC4xx() const { return IsPPC4xx; }
265  bool isPPC6xx() const { return IsPPC6xx; }
266  bool isSecurePlt() const {return SecurePlt; }
267  bool vectorsUseTwoUnits() const {return VectorsUseTwoUnits; }
268  bool isE500() const { return IsE500; }
269  bool isFeatureMFTB() const { return FeatureMFTB; }
270  bool isDeprecatedDST() const { return DeprecatedDST; }
271  bool hasICBT() const { return HasICBT; }
273  return HasInvariantFunctionDescriptors;
274  }
275  bool usePPCPreRASchedStrategy() const { return UsePPCPreRASchedStrategy; }
276  bool usePPCPostRASchedStrategy() const { return UsePPCPostRASchedStrategy; }
277  bool hasPartwordAtomics() const { return HasPartwordAtomics; }
278  bool hasDirectMove() const { return HasDirectMove; }
279 
280  bool isQPXStackUnaligned() const { return IsQPXStackUnaligned; }
281  unsigned getPlatformStackAlignment() const {
282  if ((hasQPX() || isBGQ()) && !isQPXStackUnaligned())
283  return 32;
284 
285  return 16;
286  }
287 
288  // DarwinABI has a 224-byte red zone. PPC32 SVR4ABI(Non-DarwinABI) has no
289  // red zone and PPC64 SVR4ABI has a 288-byte red zone.
290  unsigned getRedZoneSize() const {
291  return isDarwinABI() ? 224 : (isPPC64() ? 288 : 0);
292  }
293 
294  bool hasHTM() const { return HasHTM; }
295  bool hasFusion() const { return HasFusion; }
296  bool hasFloat128() const { return HasFloat128; }
297  bool isISA3_0() const { return IsISA3_0; }
298  bool useLongCalls() const { return UseLongCalls; }
299  bool needsSwapsForVSXMemOps() const {
300  return hasVSX() && isLittleEndian() && !hasP9Vector();
301  }
302 
303  POPCNTDKind hasPOPCNTD() const { return HasPOPCNTD; }
304 
305  const Triple &getTargetTriple() const { return TargetTriple; }
306 
307  /// isDarwin - True if this is any darwin platform.
308  bool isDarwin() const { return TargetTriple.isMacOSX(); }
309  /// isBGQ - True if this is a BG/Q platform.
310  bool isBGQ() const { return TargetTriple.getVendor() == Triple::BGQ; }
311 
312  bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
313  bool isTargetMachO() const { return TargetTriple.isOSBinFormatMachO(); }
314  bool isTargetLinux() const { return TargetTriple.isOSLinux(); }
315 
316  bool isDarwinABI() const { return isTargetMachO() || isDarwin(); }
317  bool isSVR4ABI() const { return !isDarwinABI(); }
318  bool isELFv2ABI() const;
319 
320  /// Originally, this function return hasISEL(). Now we always enable it,
321  /// but may expand the ISEL instruction later.
322  bool enableEarlyIfConversion() const override { return true; }
323 
324  // Scheduling customization.
325  bool enableMachineScheduler() const override;
326  // This overrides the PostRAScheduler bit in the SchedModel for each CPU.
327  bool enablePostRAScheduler() const override;
328  AntiDepBreakMode getAntiDepBreakMode() const override;
329  void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const override;
330 
331  void overrideSchedPolicy(MachineSchedPolicy &Policy,
332  unsigned NumRegionInstrs) const override;
333  bool useAA() const override;
334 
335  bool enableSubRegLiveness() const override;
336 
337  /// classifyGlobalReference - Classify a global variable reference for the
338  /// current subtarget accourding to how we should reference it.
339  unsigned char classifyGlobalReference(const GlobalValue *GV) const;
340 
341  bool isXRaySupported() const override { return IsPPC64 && IsLittleEndian; }
342 };
343 } // End llvm namespace
344 
345 #endif
bool hasFPCVT() const
Definition: PPCSubtarget.h:244
bool enableEarlyIfConversion() const override
Originally, this function return hasISEL().
Definition: PPCSubtarget.h:322
bool hasBPERMD() const
Definition: PPCSubtarget.h:258
This class represents lattice values for constants.
Definition: AllocatorList.h:23
bool isMacOSX() const
isMacOSX - Is this a Mac OS X triple.
Definition: Triple.h:451
const SelectionDAGTargetInfo * getSelectionDAGInfo() const override
Definition: PPCSubtarget.h:189
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition: Triple.h:617
bool IsQPXStackUnaligned
When targeting QPX running a stock PPC64 Linux kernel where the stack alignment has not been changed...
Definition: PPCSubtarget.h:148
bool hasVSX() const
Definition: PPCSubtarget.h:249
bool hasFSQRT() const
Definition: PPCSubtarget.h:235
bool isBGQ() const
isBGQ - True if this is a BG/Q platform.
Definition: PPCSubtarget.h:310
unsigned StackAlignment
stackAlignment - The minimum alignment known to hold of the stack frame on entry to the function and ...
Definition: PPCSubtarget.h:81
bool hasQPX() const
Definition: PPCSubtarget.h:248
bool hasSPE() const
Definition: PPCSubtarget.h:246
bool isTargetLinux() const
Definition: PPCSubtarget.h:314
bool needsTwoConstNR() const
Definition: PPCSubtarget.h:250
bool hasFusion() const
Definition: PPCSubtarget.h:295
bool isISA3_0() const
Definition: PPCSubtarget.h:297
SelectionDAGTargetInfo TSInfo
Definition: PPCSubtarget.h:154
unsigned getPlatformStackAlignment() const
Definition: PPCSubtarget.h:281
bool hasDirectMove() const
Definition: PPCSubtarget.h:278
POPCNTDKind HasPOPCNTD
Definition: PPCSubtarget.h:143
bool hasLDBRX() const
Definition: PPCSubtarget.h:261
bool hasMFOCRF() const
Definition: PPCSubtarget.h:256
bool hasP8Crypto() const
Definition: PPCSubtarget.h:253
unsigned DarwinDirective
Which cpu directive was used.
Definition: PPCSubtarget.h:87
bool isTargetELF() const
Definition: PPCSubtarget.h:312
bool useSoftFloat() const
Definition: PPCSubtarget.h:214
bool hasExtDiv() const
Definition: PPCSubtarget.h:259
bool has64BitSupport() const
has64BitSupport - Return true if the selected CPU supports 64-bit instructions, regardless of whether...
Definition: PPCSubtarget.h:212
bool hasP9Vector() const
Definition: PPCSubtarget.h:254
Itinerary data supplied by a subtarget to be used by a target.
const PPCTargetMachine & getTargetMachine() const
Definition: PPCSubtarget.h:195
InstrItineraryData InstrItins
Selected instruction itineraries (one entry per itinerary class.)
Definition: PPCSubtarget.h:84
bool hasSTFIWX() const
Definition: PPCSubtarget.h:241
bool hasInvariantFunctionDescriptors() const
Definition: PPCSubtarget.h:272
bool vectorsUseTwoUnits() const
Definition: PPCSubtarget.h:267
bool isSecurePlt() const
Definition: PPCSubtarget.h:266
bool hasFRES() const
Definition: PPCSubtarget.h:237
VendorType getVendor() const
getVendor - Get the parsed vendor type of this triple.
Definition: Triple.h:300
bool hasFRSQRTES() const
Definition: PPCSubtarget.h:239
bool HasInvariantFunctionDescriptors
Definition: PPCSubtarget.h:130
PPCFrameLowering FrameLowering
Definition: PPCSubtarget.h:151
PPCInstrInfo InstrInfo
Definition: PPCSubtarget.h:152
const PPCFrameLowering * getFrameLowering() const override
Definition: PPCSubtarget.h:182
bool hasPartwordAtomics() const
Definition: PPCSubtarget.h:277
static bool isDarwin(object::Archive::Kind Kind)
const PPCTargetLowering * getTargetLowering() const override
Definition: PPCSubtarget.h:186
bool hasFPRND() const
Definition: PPCSubtarget.h:243
bool isQPXStackUnaligned() const
Definition: PPCSubtarget.h:280
Common code between 32-bit and 64-bit PowerPC targets.
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
Definition: Triple.h:627
Targets can subclass this to parameterize the SelectionDAG lowering and instruction selection process...
bool isLittleEndian() const
Definition: PPCSubtarget.h:231
unsigned getDarwinDirective() const
getDarwinDirective - Returns the -m directive specified for the cpu.
Definition: PPCSubtarget.h:174
const PPCTargetMachine & TM
Definition: PPCSubtarget.h:150
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:43
bool hasP8Vector() const
Definition: PPCSubtarget.h:251
bool isE500() const
Definition: PPCSubtarget.h:268
const PPCRegisterInfo * getRegisterInfo() const override
Definition: PPCSubtarget.h:192
bool isBookE() const
Definition: PPCSubtarget.h:262
const PPCInstrInfo * getInstrInfo() const override
Definition: PPCSubtarget.h:185
bool hasCMPB() const
Definition: PPCSubtarget.h:260
bool isOSLinux() const
Tests whether the OS is Linux.
Definition: Triple.h:580
bool isDarwinABI() const
Definition: PPCSubtarget.h:316
bool isFeatureMFTB() const
Definition: PPCSubtarget.h:269
bool hasP8Altivec() const
Definition: PPCSubtarget.h:252
bool UsePPCPostRASchedStrategy
Definition: PPCSubtarget.h:141
bool hasP9Altivec() const
Definition: PPCSubtarget.h:255
bool hasFPU() const
Definition: PPCSubtarget.h:247
unsigned getRedZoneSize() const
Definition: PPCSubtarget.h:290
bool hasRecipPrec() const
Definition: PPCSubtarget.h:240
Triple TargetTriple
TargetTriple - What processor and OS we&#39;re targeting.
Definition: PPCSubtarget.h:77
bool isPPC4xx() const
Definition: PPCSubtarget.h:264
bool hasHTM() const
Definition: PPCSubtarget.h:294
bool useLongCalls() const
Definition: PPCSubtarget.h:298
bool use64BitRegs() const
use64BitRegs - Return true if in 64-bit mode or if we should use 64-bit registers in 32-bit mode when...
Definition: PPCSubtarget.h:219
bool hasICBT() const
Definition: PPCSubtarget.h:271
Define a generic scheduling policy for targets that don&#39;t provide their own MachineSchedStrategy.
const InstrItineraryData * getInstrItineraryData() const override
getInstrItins - Return the instruction itineraries based on subtarget selection.
Definition: PPCSubtarget.h:178
bool hasFloat128() const
Definition: PPCSubtarget.h:296
bool hasFRSQRTE() const
Definition: PPCSubtarget.h:238
bool hasLFIWAX() const
Definition: PPCSubtarget.h:242
bool hasFCPSGN() const
Definition: PPCSubtarget.h:234
PPCTargetLowering TLInfo
Definition: PPCSubtarget.h:153
bool hasAltivec() const
Definition: PPCSubtarget.h:245
bool hasISEL() const
Definition: PPCSubtarget.h:257
bool useCRBits() const
useCRBits - Return true if we should store and manipulate i1 values in the individual condition regis...
Definition: PPCSubtarget.h:223
bool isDarwin() const
isDarwin - True if this is any darwin platform.
Definition: PPCSubtarget.h:308
bool usePPCPostRASchedStrategy() const
Definition: PPCSubtarget.h:276
bool hasFRE() const
Definition: PPCSubtarget.h:236
POPCNTDKind hasPOPCNTD() const
Definition: PPCSubtarget.h:303
bool needsSwapsForVSXMemOps() const
Definition: PPCSubtarget.h:299
bool isTargetMachO() const
Definition: PPCSubtarget.h:313
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:65
bool usePPCPreRASchedStrategy() const
Definition: PPCSubtarget.h:275
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
bool isSVR4ABI() const
Definition: PPCSubtarget.h:317
bool isXRaySupported() const override
Definition: PPCSubtarget.h:341
bool HasMFOCRF
Used by the ISel to turn in optimizations for POWER4-derived architectures.
Definition: PPCSubtarget.h:90
const Triple & getTargetTriple() const
Definition: PPCSubtarget.h:305
unsigned getStackAlignment() const
getStackAlignment - Returns the minimum alignment known to hold of the stack frame on entry to the fu...
Definition: PPCSubtarget.h:170
bool hasOnlyMSYNC() const
Definition: PPCSubtarget.h:263
bool isPPC6xx() const
Definition: PPCSubtarget.h:265
bool isDeprecatedDST() const
Definition: PPCSubtarget.h:270