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