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