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