91d1746a8d06d862565f280614f542bf9e2a8bbf
[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 POWERPCSUBTARGET_H
15 #define POWERPCSUBTARGET_H
16
17 #include "PPCFrameLowering.h"
18 #include "PPCInstrInfo.h"
19 #include "PPCISelLowering.h"
20 #include "PPCJITInfo.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_64
59   };
60 }
61
62 class GlobalValue;
63 class TargetMachine;
64
65 class PPCSubtarget : public PPCGenSubtargetInfo {
66 protected:
67   /// stackAlignment - The minimum alignment known to hold of the stack frame on
68   /// entry to the function and which must be maintained by every function.
69   unsigned StackAlignment;
70
71   /// Selected instruction itineraries (one entry per itinerary class.)
72   InstrItineraryData InstrItins;
73
74   /// Which cpu directive was used.
75   unsigned DarwinDirective;
76
77   /// Used by the ISel to turn in optimizations for POWER4-derived architectures
78   bool HasMFOCRF;
79   bool Has64BitSupport;
80   bool Use64BitRegs;
81   bool UseCRBits;
82   bool IsPPC64;
83   bool HasAltivec;
84   bool HasQPX;
85   bool HasVSX;
86   bool HasFCPSGN;
87   bool HasFSQRT;
88   bool HasFRE, HasFRES, HasFRSQRTE, HasFRSQRTES;
89   bool HasRecipPrec;
90   bool HasSTFIWX;
91   bool HasLFIWAX;
92   bool HasFPRND;
93   bool HasFPCVT;
94   bool HasISEL;
95   bool HasPOPCNTD;
96   bool HasLDBRX;
97   bool IsBookE;
98   bool DeprecatedMFTB;
99   bool DeprecatedDST;
100   bool HasLazyResolverStubs;
101   bool IsJITCodeModel;
102   bool IsLittleEndian;
103
104   /// TargetTriple - What processor and OS we're targeting.
105   Triple TargetTriple;
106
107   /// OptLevel - What default optimization level we're emitting code for.
108   CodeGenOpt::Level OptLevel;
109
110   PPCFrameLowering FrameLowering;
111   const DataLayout DL;
112   PPCInstrInfo InstrInfo;
113   PPCJITInfo JITInfo;
114   PPCTargetLowering TLInfo;
115
116 public:
117   /// This constructor initializes the data members to match that
118   /// of the specified triple.
119   ///
120   PPCSubtarget(const std::string &TT, const std::string &CPU,
121                const std::string &FS, PPCTargetMachine &TM, bool is64Bit,
122                CodeGenOpt::Level OptLevel);
123
124   /// ParseSubtargetFeatures - Parses features string setting specified
125   /// subtarget options.  Definition of function is auto generated by tblgen.
126   void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
127
128   /// SetJITMode - This is called to inform the subtarget info that we are
129   /// producing code for the JIT.
130   void SetJITMode();
131
132   /// getStackAlignment - Returns the minimum alignment known to hold of the
133   /// stack frame on entry to the function and which must be maintained by every
134   /// function for this subtarget.
135   unsigned getStackAlignment() const { return StackAlignment; }
136
137   /// getDarwinDirective - Returns the -m directive specified for the cpu.
138   ///
139   unsigned getDarwinDirective() const { return DarwinDirective; }
140
141   /// getInstrItins - Return the instruction itineraies based on subtarget
142   /// selection.
143   const InstrItineraryData &getInstrItineraryData() const { return InstrItins; }
144
145   const PPCFrameLowering *getFrameLowering() const { return &FrameLowering; }
146   const DataLayout *getDataLayout() const { return &DL; }
147   const PPCInstrInfo *getInstrInfo() const { return &InstrInfo; }
148   PPCJITInfo *getJITInfo() { return &JITInfo; }
149   const PPCTargetLowering *getTargetLowering() const { return &TLInfo; }
150
151   /// initializeSubtargetDependencies - Initializes using a CPU and feature string
152   /// so that we can use initializer lists for subtarget initialization.
153   PPCSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);
154
155   /// \brief Reset the features for the PowerPC target.
156   void resetSubtargetFeatures(const MachineFunction *MF) override;
157 private:
158   void initializeEnvironment();
159   void resetSubtargetFeatures(StringRef CPU, StringRef FS);
160
161 public:
162   /// isPPC64 - Return true if we are generating code for 64-bit pointer mode.
163   ///
164   bool isPPC64() const { return IsPPC64; }
165
166   /// has64BitSupport - Return true if the selected CPU supports 64-bit
167   /// instructions, regardless of whether we are in 32-bit or 64-bit mode.
168   bool has64BitSupport() const { return Has64BitSupport; }
169
170   /// use64BitRegs - Return true if in 64-bit mode or if we should use 64-bit
171   /// registers in 32-bit mode when possible.  This can only true if
172   /// has64BitSupport() returns true.
173   bool use64BitRegs() const { return Use64BitRegs; }
174
175   /// useCRBits - Return true if we should store and manipulate i1 values in
176   /// the individual condition register bits.
177   bool useCRBits() const { return UseCRBits; }
178
179   /// hasLazyResolverStub - Return true if accesses to the specified global have
180   /// to go through a dyld lazy resolution stub.  This means that an extra load
181   /// is required to get the address of the global.
182   bool hasLazyResolverStub(const GlobalValue *GV,
183                            const TargetMachine &TM) const;
184
185   // isJITCodeModel - True if we're generating code for the JIT
186   bool isJITCodeModel() const { return IsJITCodeModel; }
187
188   // isLittleEndian - True if generating little-endian code
189   bool isLittleEndian() const { return IsLittleEndian; }
190
191   // Specific obvious features.
192   bool hasFCPSGN() const { return HasFCPSGN; }
193   bool hasFSQRT() const { return HasFSQRT; }
194   bool hasFRE() const { return HasFRE; }
195   bool hasFRES() const { return HasFRES; }
196   bool hasFRSQRTE() const { return HasFRSQRTE; }
197   bool hasFRSQRTES() const { return HasFRSQRTES; }
198   bool hasRecipPrec() const { return HasRecipPrec; }
199   bool hasSTFIWX() const { return HasSTFIWX; }
200   bool hasLFIWAX() const { return HasLFIWAX; }
201   bool hasFPRND() const { return HasFPRND; }
202   bool hasFPCVT() const { return HasFPCVT; }
203   bool hasAltivec() const { return HasAltivec; }
204   bool hasQPX() const { return HasQPX; }
205   bool hasVSX() const { return HasVSX; }
206   bool hasMFOCRF() const { return HasMFOCRF; }
207   bool hasISEL() const { return HasISEL; }
208   bool hasPOPCNTD() const { return HasPOPCNTD; }
209   bool hasLDBRX() const { return HasLDBRX; }
210   bool isBookE() const { return IsBookE; }
211   bool isDeprecatedMFTB() const { return DeprecatedMFTB; }
212   bool isDeprecatedDST() const { return DeprecatedDST; }
213
214   const Triple &getTargetTriple() const { return TargetTriple; }
215
216   /// isDarwin - True if this is any darwin platform.
217   bool isDarwin() const { return TargetTriple.isMacOSX(); }
218   /// isBGQ - True if this is a BG/Q platform.
219   bool isBGQ() const { return TargetTriple.getVendor() == Triple::BGQ; }
220
221   bool isDarwinABI() const { return isDarwin(); }
222   bool isSVR4ABI() const { return !isDarwin(); }
223
224   /// enablePostRAScheduler - True at 'More' optimization.
225   bool enablePostRAScheduler(CodeGenOpt::Level OptLevel,
226                              TargetSubtargetInfo::AntiDepBreakMode& Mode,
227                              RegClassVector& CriticalPathRCs) const override;
228
229   bool enableEarlyIfConversion() const override { return hasISEL(); }
230
231   // Scheduling customization.
232   bool enableMachineScheduler() const override;
233   void overrideSchedPolicy(MachineSchedPolicy &Policy,
234                            MachineInstr *begin,
235                            MachineInstr *end,
236                            unsigned NumRegionInstrs) const override;
237   bool useAA() const override;
238 };
239 } // End llvm namespace
240
241 #endif