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