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