[PowerPC] Add support for the QPX vector instruction set
[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 HasFCPSGN;
94   bool HasFSQRT;
95   bool HasFRE, HasFRES, HasFRSQRTE, HasFRSQRTES;
96   bool HasRecipPrec;
97   bool HasSTFIWX;
98   bool HasLFIWAX;
99   bool HasFPRND;
100   bool HasFPCVT;
101   bool HasISEL;
102   bool HasPOPCNTD;
103   bool HasCMPB;
104   bool HasLDBRX;
105   bool IsBookE;
106   bool HasOnlyMSYNC;
107   bool IsE500;
108   bool IsPPC4xx;
109   bool IsPPC6xx;
110   bool DeprecatedMFTB;
111   bool DeprecatedDST;
112   bool HasLazyResolverStubs;
113   bool IsLittleEndian;
114   bool HasICBT;
115   bool HasInvariantFunctionDescriptors;
116
117   /// When targeting QPX running a stock PPC64 Linux kernel where the stack
118   /// alignment has not been changed, we need to keep the 16-byte alignment
119   /// of the stack.
120   bool IsQPXStackUnaligned;
121
122   const PPCTargetMachine &TM;
123   PPCFrameLowering FrameLowering;
124   PPCInstrInfo InstrInfo;
125   PPCTargetLowering TLInfo;
126   PPCSelectionDAGInfo TSInfo;
127
128 public:
129   /// This constructor initializes the data members to match that
130   /// of the specified triple.
131   ///
132   PPCSubtarget(const std::string &TT, const std::string &CPU,
133                const std::string &FS, const PPCTargetMachine &TM);
134
135   /// ParseSubtargetFeatures - Parses features string setting specified
136   /// subtarget options.  Definition of function is auto generated by tblgen.
137   void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
138
139   /// getStackAlignment - Returns the minimum alignment known to hold of the
140   /// stack frame on entry to the function and which must be maintained by every
141   /// function for this subtarget.
142   unsigned getStackAlignment() const { return StackAlignment; }
143
144   /// getDarwinDirective - Returns the -m directive specified for the cpu.
145   ///
146   unsigned getDarwinDirective() const { return DarwinDirective; }
147
148   /// getInstrItins - Return the instruction itineraries based on subtarget
149   /// selection.
150   const InstrItineraryData *getInstrItineraryData() const override {
151     return &InstrItins;
152   }
153
154   const PPCFrameLowering *getFrameLowering() const override {
155     return &FrameLowering;
156   }
157   const PPCInstrInfo *getInstrInfo() const override { return &InstrInfo; }
158   const PPCTargetLowering *getTargetLowering() const override {
159     return &TLInfo;
160   }
161   const PPCSelectionDAGInfo *getSelectionDAGInfo() const override {
162     return &TSInfo;
163   }
164   const PPCRegisterInfo *getRegisterInfo() const override {
165     return &getInstrInfo()->getRegisterInfo();
166   }
167   const PPCTargetMachine &getTargetMachine() const { return TM; }
168
169   /// initializeSubtargetDependencies - Initializes using a CPU and feature string
170   /// so that we can use initializer lists for subtarget initialization.
171   PPCSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);
172
173 private:
174   void initializeEnvironment();
175   void initSubtargetFeatures(StringRef CPU, StringRef FS);
176
177 public:
178   /// isPPC64 - Return true if we are generating code for 64-bit pointer mode.
179   ///
180   bool isPPC64() const;
181
182   /// has64BitSupport - Return true if the selected CPU supports 64-bit
183   /// instructions, regardless of whether we are in 32-bit or 64-bit mode.
184   bool has64BitSupport() const { return Has64BitSupport; }
185
186   /// use64BitRegs - Return true if in 64-bit mode or if we should use 64-bit
187   /// registers in 32-bit mode when possible.  This can only true if
188   /// has64BitSupport() returns true.
189   bool use64BitRegs() const { return Use64BitRegs; }
190
191   /// useCRBits - Return true if we should store and manipulate i1 values in
192   /// the individual condition register bits.
193   bool useCRBits() const { return UseCRBits; }
194
195   /// hasLazyResolverStub - Return true if accesses to the specified global have
196   /// to go through a dyld lazy resolution stub.  This means that an extra load
197   /// is required to get the address of the global.
198   bool hasLazyResolverStub(const GlobalValue *GV) const;
199
200   // isLittleEndian - True if generating little-endian code
201   bool isLittleEndian() const { return IsLittleEndian; }
202
203   // Specific obvious features.
204   bool hasFCPSGN() const { return HasFCPSGN; }
205   bool hasFSQRT() const { return HasFSQRT; }
206   bool hasFRE() const { return HasFRE; }
207   bool hasFRES() const { return HasFRES; }
208   bool hasFRSQRTE() const { return HasFRSQRTE; }
209   bool hasFRSQRTES() const { return HasFRSQRTES; }
210   bool hasRecipPrec() const { return HasRecipPrec; }
211   bool hasSTFIWX() const { return HasSTFIWX; }
212   bool hasLFIWAX() const { return HasLFIWAX; }
213   bool hasFPRND() const { return HasFPRND; }
214   bool hasFPCVT() const { return HasFPCVT; }
215   bool hasAltivec() const { return HasAltivec; }
216   bool hasSPE() const { return HasSPE; }
217   bool hasQPX() const { return HasQPX; }
218   bool hasVSX() const { return HasVSX; }
219   bool hasP8Vector() const { return HasP8Vector; }
220   bool hasP8Altivec() const { return HasP8Altivec; }
221   bool hasMFOCRF() const { return HasMFOCRF; }
222   bool hasISEL() const { return HasISEL; }
223   bool hasPOPCNTD() const { return HasPOPCNTD; }
224   bool hasCMPB() const { return HasCMPB; }
225   bool hasLDBRX() const { return HasLDBRX; }
226   bool isBookE() const { return IsBookE; }
227   bool hasOnlyMSYNC() const { return HasOnlyMSYNC; }
228   bool isPPC4xx() const { return IsPPC4xx; }
229   bool isPPC6xx() const { return IsPPC6xx; }
230   bool isE500() const { return IsE500; }
231   bool isDeprecatedMFTB() const { return DeprecatedMFTB; }
232   bool isDeprecatedDST() const { return DeprecatedDST; }
233   bool hasICBT() const { return HasICBT; }
234   bool hasInvariantFunctionDescriptors() const {
235     return HasInvariantFunctionDescriptors;
236   }
237
238   bool isQPXStackUnaligned() const { return IsQPXStackUnaligned; }
239   unsigned getPlatformStackAlignment() const {
240     if ((hasQPX() || isBGQ()) && !isQPXStackUnaligned())
241       return 32;
242
243     return 16;
244   }
245
246   const Triple &getTargetTriple() const { return TargetTriple; }
247
248   /// isDarwin - True if this is any darwin platform.
249   bool isDarwin() const { return TargetTriple.isMacOSX(); }
250   /// isBGQ - True if this is a BG/Q platform.
251   bool isBGQ() const { return TargetTriple.getVendor() == Triple::BGQ; }
252
253   bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
254   bool isTargetMachO() const { return TargetTriple.isOSBinFormatMachO(); }
255
256   bool isDarwinABI() const { return isTargetMachO() || isDarwin(); }
257   bool isSVR4ABI() const { return !isDarwinABI(); }
258   bool isELFv2ABI() const;
259
260   bool enableEarlyIfConversion() const override { return hasISEL(); }
261
262   // Scheduling customization.
263   bool enableMachineScheduler() const override;
264   // This overrides the PostRAScheduler bit in the SchedModel for each CPU.
265   bool enablePostMachineScheduler() const override;
266   AntiDepBreakMode getAntiDepBreakMode() const override;
267   void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const override;
268
269   void overrideSchedPolicy(MachineSchedPolicy &Policy,
270                            MachineInstr *begin,
271                            MachineInstr *end,
272                            unsigned NumRegionInstrs) const override;
273   bool useAA() const override;
274
275   bool enableSubRegLiveness() const override;
276 };
277 } // End llvm namespace
278
279 #endif