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