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