b91e887a7c4a03c13b87ddc1b1789cfc10ae5d37
[oota-llvm.git] / lib / Target / PowerPC / PPCSubtarget.h
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 "PPCSelectionDAGInfo.h"
21 #include "llvm/ADT/Triple.h"
22 #include "llvm/IR/DataLayout.h"
23 #include "llvm/MC/MCInstrItineraries.h"
24 #include "llvm/Target/TargetSubtargetInfo.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 {
39     DIR_NONE,
40     DIR_32,
41     DIR_440,
42     DIR_601,
43     DIR_602,
44     DIR_603,
45     DIR_7400,
46     DIR_750,
47     DIR_970,
48     DIR_A2,
49     DIR_E500mc,
50     DIR_E5500,
51     DIR_PWR3,
52     DIR_PWR4,
53     DIR_PWR5,
54     DIR_PWR5X,
55     DIR_PWR6,
56     DIR_PWR6X,
57     DIR_PWR7,
58     DIR_PWR8,
59     DIR_64
60   };
61 }
62
63 class GlobalValue;
64 class TargetMachine;
65
66 class PPCSubtarget : public PPCGenSubtargetInfo {
67 protected:
68   /// TargetTriple - What processor and OS we're targeting.
69   Triple TargetTriple;
70
71   /// stackAlignment - The minimum alignment known to hold of the stack frame on
72   /// entry to the function and which must be maintained by every function.
73   unsigned StackAlignment;
74
75   /// Selected instruction itineraries (one entry per itinerary class.)
76   InstrItineraryData InstrItins;
77
78   /// Which cpu directive was used.
79   unsigned DarwinDirective;
80
81   /// Used by the ISel to turn in optimizations for POWER4-derived architectures
82   bool HasMFOCRF;
83   bool Has64BitSupport;
84   bool Use64BitRegs;
85   bool UseCRBits;
86   bool IsPPC64;
87   bool HasAltivec;
88   bool HasSPE;
89   bool HasQPX;
90   bool HasVSX;
91   bool HasP8Vector;
92   bool HasP8Altivec;
93   bool HasP8Crypto;
94   bool HasFCPSGN;
95   bool HasFSQRT;
96   bool HasFRE, HasFRES, HasFRSQRTE, HasFRSQRTES;
97   bool HasRecipPrec;
98   bool HasSTFIWX;
99   bool HasLFIWAX;
100   bool HasFPRND;
101   bool HasFPCVT;
102   bool HasISEL;
103   bool HasPOPCNTD;
104   bool HasCMPB;
105   bool HasLDBRX;
106   bool IsBookE;
107   bool HasOnlyMSYNC;
108   bool IsE500;
109   bool IsPPC4xx;
110   bool IsPPC6xx;
111   bool DeprecatedMFTB;
112   bool DeprecatedDST;
113   bool HasLazyResolverStubs;
114   bool IsLittleEndian;
115   bool HasICBT;
116   bool HasInvariantFunctionDescriptors;
117   bool HasPartwordAtomics;
118
119   /// When targeting QPX running a stock PPC64 Linux kernel where the stack
120   /// alignment has not been changed, we need to keep the 16-byte alignment
121   /// of the stack.
122   bool IsQPXStackUnaligned;
123
124   const PPCTargetMachine &TM;
125   PPCFrameLowering FrameLowering;
126   PPCInstrInfo InstrInfo;
127   PPCTargetLowering TLInfo;
128   PPCSelectionDAGInfo TSInfo;
129
130 public:
131   /// This constructor initializes the data members to match that
132   /// of the specified triple.
133   ///
134   PPCSubtarget(const std::string &TT, const std::string &CPU,
135                const std::string &FS, const PPCTargetMachine &TM);
136
137   /// ParseSubtargetFeatures - Parses features string setting specified
138   /// subtarget options.  Definition of function is auto generated by tblgen.
139   void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
140
141   /// getStackAlignment - Returns the minimum alignment known to hold of the
142   /// stack frame on entry to the function and which must be maintained by every
143   /// function for this subtarget.
144   unsigned getStackAlignment() const { return StackAlignment; }
145
146   /// getDarwinDirective - Returns the -m directive specified for the cpu.
147   ///
148   unsigned getDarwinDirective() const { return DarwinDirective; }
149
150   /// getInstrItins - Return the instruction itineraries based on subtarget
151   /// selection.
152   const InstrItineraryData *getInstrItineraryData() const override {
153     return &InstrItins;
154   }
155
156   const PPCFrameLowering *getFrameLowering() const override {
157     return &FrameLowering;
158   }
159   const PPCInstrInfo *getInstrInfo() const override { return &InstrInfo; }
160   const PPCTargetLowering *getTargetLowering() const override {
161     return &TLInfo;
162   }
163   const PPCSelectionDAGInfo *getSelectionDAGInfo() const override {
164     return &TSInfo;
165   }
166   const PPCRegisterInfo *getRegisterInfo() const override {
167     return &getInstrInfo()->getRegisterInfo();
168   }
169   const PPCTargetMachine &getTargetMachine() const { return TM; }
170
171   /// initializeSubtargetDependencies - Initializes using a CPU and feature string
172   /// so that we can use initializer lists for subtarget initialization.
173   PPCSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);
174
175 private:
176   void initializeEnvironment();
177   void initSubtargetFeatures(StringRef CPU, StringRef FS);
178
179 public:
180   /// isPPC64 - Return true if we are generating code for 64-bit pointer mode.
181   ///
182   bool isPPC64() const;
183
184   /// has64BitSupport - Return true if the selected CPU supports 64-bit
185   /// instructions, regardless of whether we are in 32-bit or 64-bit mode.
186   bool has64BitSupport() const { return Has64BitSupport; }
187
188   /// use64BitRegs - Return true if in 64-bit mode or if we should use 64-bit
189   /// registers in 32-bit mode when possible.  This can only true if
190   /// has64BitSupport() returns true.
191   bool use64BitRegs() const { return Use64BitRegs; }
192
193   /// useCRBits - Return true if we should store and manipulate i1 values in
194   /// the individual condition register bits.
195   bool useCRBits() const { return UseCRBits; }
196
197   /// hasLazyResolverStub - Return true if accesses to the specified global have
198   /// to go through a dyld lazy resolution stub.  This means that an extra load
199   /// is required to get the address of the global.
200   bool hasLazyResolverStub(const GlobalValue *GV) const;
201
202   // isLittleEndian - True if generating little-endian code
203   bool isLittleEndian() const { return IsLittleEndian; }
204
205   // Specific obvious features.
206   bool hasFCPSGN() const { return HasFCPSGN; }
207   bool hasFSQRT() const { return HasFSQRT; }
208   bool hasFRE() const { return HasFRE; }
209   bool hasFRES() const { return HasFRES; }
210   bool hasFRSQRTE() const { return HasFRSQRTE; }
211   bool hasFRSQRTES() const { return HasFRSQRTES; }
212   bool hasRecipPrec() const { return HasRecipPrec; }
213   bool hasSTFIWX() const { return HasSTFIWX; }
214   bool hasLFIWAX() const { return HasLFIWAX; }
215   bool hasFPRND() const { return HasFPRND; }
216   bool hasFPCVT() const { return HasFPCVT; }
217   bool hasAltivec() const { return HasAltivec; }
218   bool hasSPE() const { return HasSPE; }
219   bool hasQPX() const { return HasQPX; }
220   bool hasVSX() const { return HasVSX; }
221   bool hasP8Vector() const { return HasP8Vector; }
222   bool hasP8Altivec() const { return HasP8Altivec; }
223   bool hasP8Crypto() const { return HasP8Crypto; }
224   bool hasMFOCRF() const { return HasMFOCRF; }
225   bool hasISEL() const { return HasISEL; }
226   bool hasPOPCNTD() const { return HasPOPCNTD; }
227   bool hasCMPB() const { return HasCMPB; }
228   bool hasLDBRX() const { return HasLDBRX; }
229   bool isBookE() const { return IsBookE; }
230   bool hasOnlyMSYNC() const { return HasOnlyMSYNC; }
231   bool isPPC4xx() const { return IsPPC4xx; }
232   bool isPPC6xx() const { return IsPPC6xx; }
233   bool isE500() const { return IsE500; }
234   bool isDeprecatedMFTB() const { return DeprecatedMFTB; }
235   bool isDeprecatedDST() const { return DeprecatedDST; }
236   bool hasICBT() const { return HasICBT; }
237   bool hasInvariantFunctionDescriptors() const {
238     return HasInvariantFunctionDescriptors;
239   }
240   bool hasPartwordAtomics() const { return HasPartwordAtomics; }
241
242   bool isQPXStackUnaligned() const { return IsQPXStackUnaligned; }
243   unsigned getPlatformStackAlignment() const {
244     if ((hasQPX() || isBGQ()) && !isQPXStackUnaligned())
245       return 32;
246
247     return 16;
248   }
249
250   const Triple &getTargetTriple() const { return TargetTriple; }
251
252   /// isDarwin - True if this is any darwin platform.
253   bool isDarwin() const { return TargetTriple.isMacOSX(); }
254   /// isBGQ - True if this is a BG/Q platform.
255   bool isBGQ() const { return TargetTriple.getVendor() == Triple::BGQ; }
256
257   bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
258   bool isTargetMachO() const { return TargetTriple.isOSBinFormatMachO(); }
259
260   bool isDarwinABI() const { return isTargetMachO() || isDarwin(); }
261   bool isSVR4ABI() const { return !isDarwinABI(); }
262   bool isELFv2ABI() const;
263
264   bool enableEarlyIfConversion() const override { return hasISEL(); }
265
266   // Scheduling customization.
267   bool enableMachineScheduler() const override;
268   // This overrides the PostRAScheduler bit in the SchedModel for each CPU.
269   bool enablePostMachineScheduler() const override;
270   AntiDepBreakMode getAntiDepBreakMode() const override;
271   void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const override;
272
273   void overrideSchedPolicy(MachineSchedPolicy &Policy,
274                            MachineInstr *begin,
275                            MachineInstr *end,
276                            unsigned NumRegionInstrs) const override;
277   bool useAA() const override;
278
279   bool enableSubRegLiveness() const override;
280 };
281 } // End llvm namespace
282
283 #endif