PPC: Refactoring to support subtarget feature changing
[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 "llvm/ADT/Triple.h"
18 #include "llvm/MC/MCInstrItineraries.h"
19 #include "llvm/Target/TargetSubtargetInfo.h"
20 #include <string>
21
22 #define GET_SUBTARGETINFO_HEADER
23 #include "PPCGenSubtargetInfo.inc"
24
25 // GCC #defines PPC on Linux but we use it as our namespace name
26 #undef PPC
27
28 namespace llvm {
29 class StringRef;
30
31 namespace PPC {
32   // -m directive values.
33   enum {
34     DIR_NONE,
35     DIR_32,
36     DIR_440,
37     DIR_601,
38     DIR_602,
39     DIR_603,
40     DIR_7400,
41     DIR_750,
42     DIR_970,
43     DIR_A2,
44     DIR_E500mc,
45     DIR_E5500,
46     DIR_PWR3,
47     DIR_PWR4,
48     DIR_PWR5,
49     DIR_PWR5X,
50     DIR_PWR6,
51     DIR_PWR6X,
52     DIR_PWR7,
53     DIR_64
54   };
55 }
56
57 class GlobalValue;
58 class TargetMachine;
59
60 class PPCSubtarget : public PPCGenSubtargetInfo {
61 protected:
62   /// stackAlignment - The minimum alignment known to hold of the stack frame on
63   /// entry to the function and which must be maintained by every function.
64   unsigned StackAlignment;
65
66   /// Selected instruction itineraries (one entry per itinerary class.)
67   InstrItineraryData InstrItins;
68
69   /// Which cpu directive was used.
70   unsigned DarwinDirective;
71
72   /// Used by the ISel to turn in optimizations for POWER4-derived architectures
73   bool HasMFOCRF;
74   bool Has64BitSupport;
75   bool Use64BitRegs;
76   bool IsPPC64;
77   bool HasAltivec;
78   bool HasQPX;
79   bool HasFSQRT;
80   bool HasFRE, HasFRES, HasFRSQRTE, HasFRSQRTES;
81   bool HasRecipPrec;
82   bool HasSTFIWX;
83   bool HasLFIWAX;
84   bool HasFPRND;
85   bool HasFPCVT;
86   bool HasISEL;
87   bool HasPOPCNTD;
88   bool HasLDBRX;
89   bool IsBookE;
90   bool HasLazyResolverStubs;
91   bool IsJITCodeModel;
92
93   /// TargetTriple - What processor and OS we're targeting.
94   Triple TargetTriple;
95
96 public:
97   /// This constructor initializes the data members to match that
98   /// of the specified triple.
99   ///
100   PPCSubtarget(const std::string &TT, const std::string &CPU,
101                const std::string &FS, bool is64Bit);
102
103   /// ParseSubtargetFeatures - Parses features string setting specified
104   /// subtarget options.  Definition of function is auto generated by tblgen.
105   void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
106
107   /// SetJITMode - This is called to inform the subtarget info that we are
108   /// producing code for the JIT.
109   void SetJITMode();
110
111   /// getStackAlignment - Returns the minimum alignment known to hold of the
112   /// stack frame on entry to the function and which must be maintained by every
113   /// function for this subtarget.
114   unsigned getStackAlignment() const { return StackAlignment; }
115
116   /// getDarwinDirective - Returns the -m directive specified for the cpu.
117   ///
118   unsigned getDarwinDirective() const { return DarwinDirective; }
119
120   /// getInstrItins - Return the instruction itineraies based on subtarget
121   /// selection.
122   const InstrItineraryData &getInstrItineraryData() const { return InstrItins; }
123
124   /// getDataLayoutString - Return the pointer size and type alignment
125   /// properties of this subtarget.
126   const char *getDataLayoutString() const {
127     // Note, the alignment values for f64 and i64 on ppc64 in Darwin
128     // documentation are wrong; these are correct (i.e. "what gcc does").
129     if (isPPC64() && isSVR4ABI()) {
130       if (TargetTriple.getOS() == llvm::Triple::FreeBSD)
131         return "E-p:64:64-f64:64:64-i64:64:64-v128:128:128-n32:64";
132       else
133         return "E-p:64:64-f64:64:64-i64:64:64-f128:128:128-v128:128:128-n32:64";
134     }
135
136     return isPPC64() ? "E-p:64:64-f64:64:64-i64:64:64-f128:64:128-n32:64"
137                      : "E-p:32:32-f64:64:64-i64:64:64-f128:64:128-n32";
138   }
139
140   /// \brief Reset the features for the PowerPC target.
141   virtual void resetSubtargetFeatures(const MachineFunction *MF);
142 private:
143   void initializeEnvironment();
144   void resetSubtargetFeatures(StringRef CPU, StringRef FS);
145
146 public:
147   /// isPPC64 - Return true if we are generating code for 64-bit pointer mode.
148   ///
149   bool isPPC64() const { return IsPPC64; }
150
151   /// has64BitSupport - Return true if the selected CPU supports 64-bit
152   /// instructions, regardless of whether we are in 32-bit or 64-bit mode.
153   bool has64BitSupport() const { return Has64BitSupport; }
154
155   /// use64BitRegs - Return true if in 64-bit mode or if we should use 64-bit
156   /// registers in 32-bit mode when possible.  This can only true if
157   /// has64BitSupport() returns true.
158   bool use64BitRegs() const { return Use64BitRegs; }
159
160   /// hasLazyResolverStub - Return true if accesses to the specified global have
161   /// to go through a dyld lazy resolution stub.  This means that an extra load
162   /// is required to get the address of the global.
163   bool hasLazyResolverStub(const GlobalValue *GV,
164                            const TargetMachine &TM) const;
165
166   // isJITCodeModel - True if we're generating code for the JIT
167   bool isJITCodeModel() const { return IsJITCodeModel; }
168
169   // Specific obvious features.
170   bool hasFSQRT() const { return HasFSQRT; }
171   bool hasFRE() const { return HasFRE; }
172   bool hasFRES() const { return HasFRES; }
173   bool hasFRSQRTE() const { return HasFRSQRTE; }
174   bool hasFRSQRTES() const { return HasFRSQRTES; }
175   bool hasRecipPrec() const { return HasRecipPrec; }
176   bool hasSTFIWX() const { return HasSTFIWX; }
177   bool hasLFIWAX() const { return HasLFIWAX; }
178   bool hasFPRND() const { return HasFPRND; }
179   bool hasFPCVT() const { return HasFPCVT; }
180   bool hasAltivec() const { return HasAltivec; }
181   bool hasQPX() const { return HasQPX; }
182   bool hasMFOCRF() const { return HasMFOCRF; }
183   bool hasISEL() const { return HasISEL; }
184   bool hasPOPCNTD() const { return HasPOPCNTD; }
185   bool hasLDBRX() const { return HasLDBRX; }
186   bool isBookE() const { return IsBookE; }
187
188   const Triple &getTargetTriple() const { return TargetTriple; }
189
190   /// isDarwin - True if this is any darwin platform.
191   bool isDarwin() const { return TargetTriple.isMacOSX(); }
192   /// isBGP - True if this is a BG/P platform.
193   bool isBGP() const { return TargetTriple.getVendor() == Triple::BGP; }
194   /// isBGQ - True if this is a BG/Q platform.
195   bool isBGQ() const { return TargetTriple.getVendor() == Triple::BGQ; }
196
197   bool isDarwinABI() const { return isDarwin(); }
198   bool isSVR4ABI() const { return !isDarwin(); }
199
200   /// enablePostRAScheduler - True at 'More' optimization.
201   bool enablePostRAScheduler(CodeGenOpt::Level OptLevel,
202                              TargetSubtargetInfo::AntiDepBreakMode& Mode,
203                              RegClassVector& CriticalPathRCs) const;
204 };
205 } // End llvm namespace
206
207 #endif