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