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