Added support for mcpu krait
[oota-llvm.git] / lib / Target / ARM / ARMSubtarget.h
1 //===-- ARMSubtarget.h - Define Subtarget for the ARM ----------*- 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 ARM specific subclass of TargetSubtargetInfo.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef ARMSUBTARGET_H
15 #define ARMSUBTARGET_H
16
17 #include "MCTargetDesc/ARMMCTargetDesc.h"
18 #include "llvm/ADT/Triple.h"
19 #include "llvm/MC/MCInstrItineraries.h"
20 #include "llvm/Target/TargetSubtargetInfo.h"
21 #include <string>
22
23 #define GET_SUBTARGETINFO_HEADER
24 #include "ARMGenSubtargetInfo.inc"
25
26 namespace llvm {
27 class GlobalValue;
28 class StringRef;
29 class TargetOptions;
30
31 class ARMSubtarget : public ARMGenSubtargetInfo {
32 protected:
33   enum ARMProcFamilyEnum {
34     Others, CortexA5, CortexA7, CortexA8, CortexA9, CortexA12, CortexA15, 
35     CortexR5, Swift, CortexA53, CortexA57, Krait
36   };
37   enum ARMProcClassEnum {
38     None, AClass, RClass, MClass
39   };
40
41   /// ARMProcFamily - ARM processor family: Cortex-A8, Cortex-A9, and others.
42   ARMProcFamilyEnum ARMProcFamily;
43
44   /// ARMProcClass - ARM processor class: None, AClass, RClass or MClass.
45   ARMProcClassEnum ARMProcClass;
46
47   /// HasV4TOps, HasV5TOps, HasV5TEOps,
48   /// HasV6Ops, HasV6MOps, HasV6T2Ops, HasV7Ops, HasV8Ops -
49   /// Specify whether target support specific ARM ISA variants.
50   bool HasV4TOps;
51   bool HasV5TOps;
52   bool HasV5TEOps;
53   bool HasV6Ops;
54   bool HasV6MOps;
55   bool HasV6T2Ops;
56   bool HasV7Ops;
57   bool HasV8Ops;
58
59   /// HasVFPv2, HasVFPv3, HasVFPv4, HasFPARMv8, HasNEON - Specify what
60   /// floating point ISAs are supported.
61   bool HasVFPv2;
62   bool HasVFPv3;
63   bool HasVFPv4;
64   bool HasFPARMv8;
65   bool HasNEON;
66
67   /// MinSize - True if the function being compiled has the "minsize" attribute
68   /// and should be optimised for size at the expense of speed.
69   bool MinSize;
70
71   /// UseNEONForSinglePrecisionFP - if the NEONFP attribute has been
72   /// specified. Use the method useNEONForSinglePrecisionFP() to
73   /// determine if NEON should actually be used.
74   bool UseNEONForSinglePrecisionFP;
75
76   /// UseMulOps - True if non-microcoded fused integer multiply-add and
77   /// multiply-subtract instructions should be used.
78   bool UseMulOps;
79
80   /// SlowFPVMLx - If the VFP2 / NEON instructions are available, indicates
81   /// whether the FP VML[AS] instructions are slow (if so, don't use them).
82   bool SlowFPVMLx;
83
84   /// HasVMLxForwarding - If true, NEON has special multiplier accumulator
85   /// forwarding to allow mul + mla being issued back to back.
86   bool HasVMLxForwarding;
87
88   /// SlowFPBrcc - True if floating point compare + branch is slow.
89   bool SlowFPBrcc;
90
91   /// InThumbMode - True if compiling for Thumb, false for ARM.
92   bool InThumbMode;
93
94   /// HasThumb2 - True if Thumb2 instructions are supported.
95   bool HasThumb2;
96
97   /// NoARM - True if subtarget does not support ARM mode execution.
98   bool NoARM;
99
100   /// PostRAScheduler - True if using post-register-allocation scheduler.
101   bool PostRAScheduler;
102
103   /// IsR9Reserved - True if R9 is a not available as general purpose register.
104   bool IsR9Reserved;
105
106   /// UseMovt - True if MOVT / MOVW pairs are used for materialization of 32-bit
107   /// imms (including global addresses).
108   bool UseMovt;
109
110   /// SupportsTailCall - True if the OS supports tail call. The dynamic linker
111   /// must be able to synthesize call stubs for interworking between ARM and
112   /// Thumb.
113   bool SupportsTailCall;
114
115   /// HasFP16 - True if subtarget supports half-precision FP (We support VFP+HF
116   /// only so far)
117   bool HasFP16;
118
119   /// HasD16 - True if subtarget is limited to 16 double precision
120   /// FP registers for VFPv3.
121   bool HasD16;
122
123   /// HasHardwareDivide - True if subtarget supports [su]div
124   bool HasHardwareDivide;
125
126   /// HasHardwareDivideInARM - True if subtarget supports [su]div in ARM mode
127   bool HasHardwareDivideInARM;
128
129   /// HasT2ExtractPack - True if subtarget supports thumb2 extract/pack
130   /// instructions.
131   bool HasT2ExtractPack;
132
133   /// HasDataBarrier - True if the subtarget supports DMB / DSB data barrier
134   /// instructions.
135   bool HasDataBarrier;
136
137   /// Pref32BitThumb - If true, codegen would prefer 32-bit Thumb instructions
138   /// over 16-bit ones.
139   bool Pref32BitThumb;
140
141   /// AvoidCPSRPartialUpdate - If true, codegen would avoid using instructions
142   /// that partially update CPSR and add false dependency on the previous
143   /// CPSR setting instruction.
144   bool AvoidCPSRPartialUpdate;
145
146   /// AvoidMOVsShifterOperand - If true, codegen should avoid using flag setting
147   /// movs with shifter operand (i.e. asr, lsl, lsr).
148   bool AvoidMOVsShifterOperand;
149
150   /// HasRAS - Some processors perform return stack prediction. CodeGen should
151   /// avoid issue "normal" call instructions to callees which do not return.
152   bool HasRAS;
153
154   /// HasMPExtension - True if the subtarget supports Multiprocessing
155   /// extension (ARMv7 only).
156   bool HasMPExtension;
157
158   /// HasVirtualization - True if the subtarget supports the Virtualization
159   /// extension.
160   bool HasVirtualization;
161
162   /// FPOnlySP - If true, the floating point unit only supports single
163   /// precision.
164   bool FPOnlySP;
165
166   /// If true, the processor supports the Performance Monitor Extensions. These
167   /// include a generic cycle-counter as well as more fine-grained (often
168   /// implementation-specific) events.
169   bool HasPerfMon;
170
171   /// HasTrustZone - if true, processor supports TrustZone security extensions
172   bool HasTrustZone;
173
174   /// HasCrypto - if true, processor supports Cryptography extensions
175   bool HasCrypto;
176
177   /// HasCRC - if true, processor supports CRC instructions
178   bool HasCRC;
179
180   /// AllowsUnalignedMem - If true, the subtarget allows unaligned memory
181   /// accesses for some types.  For details, see
182   /// ARMTargetLowering::allowsUnalignedMemoryAccesses().
183   bool AllowsUnalignedMem;
184
185   /// RestrictIT - If true, the subtarget disallows generation of deprecated IT
186   ///  blocks to conform to ARMv8 rule.
187   bool RestrictIT;
188
189   /// Thumb2DSP - If true, the subtarget supports the v7 DSP (saturating arith
190   /// and such) instructions in Thumb2 code.
191   bool Thumb2DSP;
192
193   /// NaCl TRAP instruction is generated instead of the regular TRAP.
194   bool UseNaClTrap;
195
196   /// Target machine allowed unsafe FP math (such as use of NEON fp)
197   bool UnsafeFPMath;
198
199   /// stackAlignment - The minimum alignment known to hold of the stack frame on
200   /// entry to the function and which must be maintained by every function.
201   unsigned stackAlignment;
202
203   /// CPUString - String name of used CPU.
204   std::string CPUString;
205
206   /// TargetTriple - What processor and OS we're targeting.
207   Triple TargetTriple;
208
209   /// SchedModel - Processor specific instruction costs.
210   const MCSchedModel *SchedModel;
211
212   /// Selected instruction itineraries (one entry per itinerary class.)
213   InstrItineraryData InstrItins;
214
215   /// Options passed via command line that could influence the target
216   const TargetOptions &Options;
217
218  public:
219   enum {
220     ARM_ABI_APCS,
221     ARM_ABI_AAPCS // ARM EABI
222   } TargetABI;
223
224   /// This constructor initializes the data members to match that
225   /// of the specified triple.
226   ///
227   ARMSubtarget(const std::string &TT, const std::string &CPU,
228                const std::string &FS, const TargetOptions &Options);
229
230   /// getMaxInlineSizeThreshold - Returns the maximum memset / memcpy size
231   /// that still makes it profitable to inline the call.
232   unsigned getMaxInlineSizeThreshold() const {
233     // FIXME: For now, we don't lower memcpy's to loads / stores for Thumb1.
234     // Change this once Thumb1 ldmia / stmia support is added.
235     return isThumb1Only() ? 0 : 64;
236   }
237   /// ParseSubtargetFeatures - Parses features string setting specified
238   /// subtarget options.  Definition of function is auto generated by tblgen.
239   void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
240
241   /// \brief Reset the features for the ARM target.
242   virtual void resetSubtargetFeatures(const MachineFunction *MF);
243 private:
244   void initializeEnvironment();
245   void resetSubtargetFeatures(StringRef CPU, StringRef FS);
246 public:
247   void computeIssueWidth();
248
249   bool hasV4TOps()  const { return HasV4TOps;  }
250   bool hasV5TOps()  const { return HasV5TOps;  }
251   bool hasV5TEOps() const { return HasV5TEOps; }
252   bool hasV6Ops()   const { return HasV6Ops;   }
253   bool hasV6MOps()  const { return HasV6MOps;  }
254   bool hasV6T2Ops() const { return HasV6T2Ops; }
255   bool hasV7Ops()   const { return HasV7Ops;  }
256   bool hasV8Ops()   const { return HasV8Ops;  }
257
258   bool isCortexA5() const { return ARMProcFamily == CortexA5; }
259   bool isCortexA8() const { return ARMProcFamily == CortexA8; }
260   bool isCortexA9() const { return ARMProcFamily == CortexA9; }
261   bool isCortexA15() const { return ARMProcFamily == CortexA15; }
262   bool isSwift()    const { return ARMProcFamily == Swift; }
263   bool isCortexM3() const { return CPUString == "cortex-m3"; }
264   bool isLikeA9() const { return isCortexA9() || isCortexA15() || isKrait(); }
265   bool isCortexR5() const { return ARMProcFamily == CortexR5; }
266   bool isKrait() const { return ARMProcFamily == Krait; }
267
268   bool hasARMOps() const { return !NoARM; }
269
270   bool hasVFP2() const { return HasVFPv2; }
271   bool hasVFP3() const { return HasVFPv3; }
272   bool hasVFP4() const { return HasVFPv4; }
273   bool hasFPARMv8() const { return HasFPARMv8; }
274   bool hasNEON() const { return HasNEON;  }
275   bool hasCrypto() const { return HasCrypto; }
276   bool hasCRC() const { return HasCRC; }
277   bool hasVirtualization() const { return HasVirtualization; }
278   bool isMinSize() const { return MinSize; }
279   bool useNEONForSinglePrecisionFP() const {
280     return hasNEON() && UseNEONForSinglePrecisionFP; }
281
282   bool hasDivide() const { return HasHardwareDivide; }
283   bool hasDivideInARMMode() const { return HasHardwareDivideInARM; }
284   bool hasT2ExtractPack() const { return HasT2ExtractPack; }
285   bool hasDataBarrier() const { return HasDataBarrier; }
286   bool hasAnyDataBarrier() const {
287     return HasDataBarrier || (hasV6Ops() && !isThumb());
288   }
289   bool useMulOps() const { return UseMulOps; }
290   bool useFPVMLx() const { return !SlowFPVMLx; }
291   bool hasVMLxForwarding() const { return HasVMLxForwarding; }
292   bool isFPBrccSlow() const { return SlowFPBrcc; }
293   bool isFPOnlySP() const { return FPOnlySP; }
294   bool hasPerfMon() const { return HasPerfMon; }
295   bool hasTrustZone() const { return HasTrustZone; }
296   bool prefers32BitThumb() const { return Pref32BitThumb; }
297   bool avoidCPSRPartialUpdate() const { return AvoidCPSRPartialUpdate; }
298   bool avoidMOVsShifterOperand() const { return AvoidMOVsShifterOperand; }
299   bool hasRAS() const { return HasRAS; }
300   bool hasMPExtension() const { return HasMPExtension; }
301   bool hasThumb2DSP() const { return Thumb2DSP; }
302   bool useNaClTrap() const { return UseNaClTrap; }
303
304   bool hasFP16() const { return HasFP16; }
305   bool hasD16() const { return HasD16; }
306
307   const Triple &getTargetTriple() const { return TargetTriple; }
308
309   bool isTargetIOS() const { return TargetTriple.isiOS(); }
310   bool isTargetDarwin() const { return TargetTriple.isOSDarwin(); }
311   bool isTargetNaCl() const { return TargetTriple.isOSNaCl(); }
312   bool isTargetLinux() const { return TargetTriple.isOSLinux(); }
313   bool isTargetELF() const { return !isTargetDarwin(); }
314   // ARM EABI is the bare-metal EABI described in ARM ABI documents and
315   // can be accessed via -target arm-none-eabi. This is NOT GNUEABI.
316   // FIXME: Add a flag for bare-metal for that target and set Triple::EABI
317   // even for GNUEABI, so we can make a distinction here and still conform to
318   // the EABI on GNU (and Android) mode. This requires change in Clang, too.
319   bool isTargetAEABI() const {
320     return TargetTriple.getEnvironment() == Triple::EABI;
321   }
322
323   bool isAPCS_ABI() const { return TargetABI == ARM_ABI_APCS; }
324   bool isAAPCS_ABI() const { return TargetABI == ARM_ABI_AAPCS; }
325
326   bool isThumb() const { return InThumbMode; }
327   bool isThumb1Only() const { return InThumbMode && !HasThumb2; }
328   bool isThumb2() const { return InThumbMode && HasThumb2; }
329   bool hasThumb2() const { return HasThumb2; }
330   bool isMClass() const { return ARMProcClass == MClass; }
331   bool isRClass() const { return ARMProcClass == RClass; }
332   bool isAClass() const { return ARMProcClass == AClass; }
333
334   bool isR9Reserved() const { return IsR9Reserved; }
335
336   bool useMovt() const { return UseMovt && !isMinSize(); }
337   bool supportsTailCall() const { return SupportsTailCall; }
338
339   bool allowsUnalignedMem() const { return AllowsUnalignedMem; }
340
341   bool restrictIT() const { return RestrictIT; }
342
343   const std::string & getCPUString() const { return CPUString; }
344
345   unsigned getMispredictionPenalty() const;
346   
347   /// This function returns true if the target has sincos() routine in its
348   /// compiler runtime or math libraries.
349   bool hasSinCos() const;
350
351   /// enablePostRAScheduler - True at 'More' optimization.
352   bool enablePostRAScheduler(CodeGenOpt::Level OptLevel,
353                              TargetSubtargetInfo::AntiDepBreakMode& Mode,
354                              RegClassVector& CriticalPathRCs) const;
355
356   /// getInstrItins - Return the instruction itineraies based on subtarget
357   /// selection.
358   const InstrItineraryData &getInstrItineraryData() const { return InstrItins; }
359
360   /// getStackAlignment - Returns the minimum alignment known to hold of the
361   /// stack frame on entry to the function and which must be maintained by every
362   /// function for this subtarget.
363   unsigned getStackAlignment() const { return stackAlignment; }
364
365   /// GVIsIndirectSymbol - true if the GV will be accessed via an indirect
366   /// symbol.
367   bool GVIsIndirectSymbol(const GlobalValue *GV, Reloc::Model RelocM) const;
368 };
369 } // End llvm namespace
370
371 #endif  // ARMSUBTARGET_H