ARM: update subtarget information for Windows on ARM
[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   /// If true, the instructions "vmov.i32 d0, #0" and "vmov.i32 q0, #0" are
181   /// particularly effective at zeroing a VFP register.
182   bool HasZeroCycleZeroing;
183
184   /// AllowsUnalignedMem - If true, the subtarget allows unaligned memory
185   /// accesses for some types.  For details, see
186   /// ARMTargetLowering::allowsUnalignedMemoryAccesses().
187   bool AllowsUnalignedMem;
188
189   /// RestrictIT - If true, the subtarget disallows generation of deprecated IT
190   ///  blocks to conform to ARMv8 rule.
191   bool RestrictIT;
192
193   /// Thumb2DSP - If true, the subtarget supports the v7 DSP (saturating arith
194   /// and such) instructions in Thumb2 code.
195   bool Thumb2DSP;
196
197   /// NaCl TRAP instruction is generated instead of the regular TRAP.
198   bool UseNaClTrap;
199
200   /// Target machine allowed unsafe FP math (such as use of NEON fp)
201   bool UnsafeFPMath;
202
203   /// stackAlignment - The minimum alignment known to hold of the stack frame on
204   /// entry to the function and which must be maintained by every function.
205   unsigned stackAlignment;
206
207   /// CPUString - String name of used CPU.
208   std::string CPUString;
209
210   /// IsLittle - The target is Little Endian
211   bool IsLittle;
212
213   /// TargetTriple - What processor and OS we're targeting.
214   Triple TargetTriple;
215
216   /// SchedModel - Processor specific instruction costs.
217   const MCSchedModel *SchedModel;
218
219   /// Selected instruction itineraries (one entry per itinerary class.)
220   InstrItineraryData InstrItins;
221
222   /// Options passed via command line that could influence the target
223   const TargetOptions &Options;
224
225  public:
226   enum {
227     ARM_ABI_UNKNOWN,
228     ARM_ABI_APCS,
229     ARM_ABI_AAPCS // ARM EABI
230   } TargetABI;
231
232   /// This constructor initializes the data members to match that
233   /// of the specified triple.
234   ///
235   ARMSubtarget(const std::string &TT, const std::string &CPU,
236                const std::string &FS, bool IsLittle,
237                const TargetOptions &Options);
238
239   /// getMaxInlineSizeThreshold - Returns the maximum memset / memcpy size
240   /// that still makes it profitable to inline the call.
241   unsigned getMaxInlineSizeThreshold() const {
242     // FIXME: For now, we don't lower memcpy's to loads / stores for Thumb1.
243     // Change this once Thumb1 ldmia / stmia support is added.
244     return isThumb1Only() ? 0 : 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 private:
253   void initializeEnvironment();
254   void resetSubtargetFeatures(StringRef CPU, StringRef FS);
255 public:
256   void computeIssueWidth();
257
258   bool hasV4TOps()  const { return HasV4TOps;  }
259   bool hasV5TOps()  const { return HasV5TOps;  }
260   bool hasV5TEOps() const { return HasV5TEOps; }
261   bool hasV6Ops()   const { return HasV6Ops;   }
262   bool hasV6MOps()  const { return HasV6MOps;  }
263   bool hasV6T2Ops() const { return HasV6T2Ops; }
264   bool hasV7Ops()   const { return HasV7Ops;  }
265   bool hasV8Ops()   const { return HasV8Ops;  }
266
267   bool isCortexA5() const { return ARMProcFamily == CortexA5; }
268   bool isCortexA7() const { return ARMProcFamily == CortexA7; }
269   bool isCortexA8() const { return ARMProcFamily == CortexA8; }
270   bool isCortexA9() const { return ARMProcFamily == CortexA9; }
271   bool isCortexA15() const { return ARMProcFamily == CortexA15; }
272   bool isSwift()    const { return ARMProcFamily == Swift; }
273   bool isCortexM3() const { return CPUString == "cortex-m3"; }
274   bool isLikeA9() const { return isCortexA9() || isCortexA15() || isKrait(); }
275   bool isCortexR5() const { return ARMProcFamily == CortexR5; }
276   bool isKrait() const { return ARMProcFamily == Krait; }
277
278   bool hasARMOps() const { return !NoARM; }
279
280   bool hasVFP2() const { return HasVFPv2; }
281   bool hasVFP3() const { return HasVFPv3; }
282   bool hasVFP4() const { return HasVFPv4; }
283   bool hasFPARMv8() const { return HasFPARMv8; }
284   bool hasNEON() const { return HasNEON;  }
285   bool hasCrypto() const { return HasCrypto; }
286   bool hasCRC() const { return HasCRC; }
287   bool hasVirtualization() const { return HasVirtualization; }
288   bool isMinSize() const { return MinSize; }
289   bool useNEONForSinglePrecisionFP() const {
290     return hasNEON() && UseNEONForSinglePrecisionFP; }
291
292   bool hasDivide() const { return HasHardwareDivide; }
293   bool hasDivideInARMMode() const { return HasHardwareDivideInARM; }
294   bool hasT2ExtractPack() const { return HasT2ExtractPack; }
295   bool hasDataBarrier() const { return HasDataBarrier; }
296   bool hasAnyDataBarrier() const {
297     return HasDataBarrier || (hasV6Ops() && !isThumb());
298   }
299   bool useMulOps() const { return UseMulOps; }
300   bool useFPVMLx() const { return !SlowFPVMLx; }
301   bool hasVMLxForwarding() const { return HasVMLxForwarding; }
302   bool isFPBrccSlow() const { return SlowFPBrcc; }
303   bool isFPOnlySP() const { return FPOnlySP; }
304   bool hasPerfMon() const { return HasPerfMon; }
305   bool hasTrustZone() const { return HasTrustZone; }
306   bool hasZeroCycleZeroing() const { return HasZeroCycleZeroing; }
307   bool prefers32BitThumb() const { return Pref32BitThumb; }
308   bool avoidCPSRPartialUpdate() const { return AvoidCPSRPartialUpdate; }
309   bool avoidMOVsShifterOperand() const { return AvoidMOVsShifterOperand; }
310   bool hasRAS() const { return HasRAS; }
311   bool hasMPExtension() const { return HasMPExtension; }
312   bool hasThumb2DSP() const { return Thumb2DSP; }
313   bool useNaClTrap() const { return UseNaClTrap; }
314
315   bool hasFP16() const { return HasFP16; }
316   bool hasD16() const { return HasD16; }
317
318   const Triple &getTargetTriple() const { return TargetTriple; }
319
320   bool isTargetDarwin() const { return TargetTriple.isOSDarwin(); }
321   bool isTargetIOS() const { return TargetTriple.isiOS(); }
322   bool isTargetLinux() const { return TargetTriple.isOSLinux(); }
323   bool isTargetNaCl() const { return TargetTriple.isOSNaCl(); }
324   bool isTargetNetBSD() const { return TargetTriple.getOS() == Triple::NetBSD; }
325   bool isTargetWindows() const { return TargetTriple.isOSWindows(); }
326
327   bool isTargetCOFF() const { return TargetTriple.isOSBinFormatCOFF(); }
328   bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
329   bool isTargetMachO() const { return TargetTriple.isOSBinFormatMachO(); }
330
331   // ARM EABI is the bare-metal EABI described in ARM ABI documents and
332   // can be accessed via -target arm-none-eabi. This is NOT GNUEABI.
333   // FIXME: Add a flag for bare-metal for that target and set Triple::EABI
334   // even for GNUEABI, so we can make a distinction here and still conform to
335   // the EABI on GNU (and Android) mode. This requires change in Clang, too.
336   // FIXME: The Darwin exception is temporary, while we move users to
337   // "*-*-*-macho" triples as quickly as possible.
338   bool isTargetAEABI() const {
339     return (TargetTriple.getEnvironment() == Triple::EABI ||
340             TargetTriple.getEnvironment() == Triple::EABIHF) &&
341            !isTargetDarwin() && !isTargetWindows();
342   }
343
344   // ARM Targets that support EHABI exception handling standard
345   // Darwin uses SjLj. Other targets might need more checks.
346   bool isTargetEHABICompatible() const {
347     return (TargetTriple.getEnvironment() == Triple::EABI ||
348             TargetTriple.getEnvironment() == Triple::GNUEABI ||
349             TargetTriple.getEnvironment() == Triple::EABIHF ||
350             TargetTriple.getEnvironment() == Triple::GNUEABIHF ||
351             TargetTriple.getEnvironment() == Triple::Android) &&
352            !isTargetDarwin() && !isTargetWindows();
353   }
354
355   bool isTargetHardFloat() const {
356     // FIXME: this is invalid for WindowsCE
357     return TargetTriple.getEnvironment() == Triple::GNUEABIHF ||
358            TargetTriple.getEnvironment() == Triple::EABIHF ||
359            isTargetWindows();
360   }
361   bool isTargetAndroid() const {
362     return TargetTriple.getEnvironment() == Triple::Android;
363   }
364
365   bool isAPCS_ABI() const {
366     assert(TargetABI != ARM_ABI_UNKNOWN);
367     return TargetABI == ARM_ABI_APCS;
368   }
369   bool isAAPCS_ABI() const {
370     assert(TargetABI != ARM_ABI_UNKNOWN);
371     return TargetABI == ARM_ABI_AAPCS;
372   }
373
374   bool isThumb() const { return InThumbMode; }
375   bool isThumb1Only() const { return InThumbMode && !HasThumb2; }
376   bool isThumb2() const { return InThumbMode && HasThumb2; }
377   bool hasThumb2() const { return HasThumb2; }
378   bool isMClass() const { return ARMProcClass == MClass; }
379   bool isRClass() const { return ARMProcClass == RClass; }
380   bool isAClass() const { return ARMProcClass == AClass; }
381
382   bool isR9Reserved() const { return IsR9Reserved; }
383
384   bool useMovt() const { return UseMovt && !isMinSize(); }
385   bool supportsTailCall() const { return SupportsTailCall; }
386
387   bool allowsUnalignedMem() const { return AllowsUnalignedMem; }
388
389   bool restrictIT() const { return RestrictIT; }
390
391   const std::string & getCPUString() const { return CPUString; }
392
393   bool isLittle() const { return IsLittle; }
394
395   unsigned getMispredictionPenalty() const;
396   
397   /// This function returns true if the target has sincos() routine in its
398   /// compiler runtime or math libraries.
399   bool hasSinCos() const;
400
401   /// enablePostRAScheduler - True at 'More' optimization.
402   bool enablePostRAScheduler(CodeGenOpt::Level OptLevel,
403                              TargetSubtargetInfo::AntiDepBreakMode& Mode,
404                              RegClassVector& CriticalPathRCs) const override;
405
406   /// getInstrItins - Return the instruction itineraies based on subtarget
407   /// selection.
408   const InstrItineraryData &getInstrItineraryData() const { return InstrItins; }
409
410   /// getStackAlignment - Returns the minimum alignment known to hold of the
411   /// stack frame on entry to the function and which must be maintained by every
412   /// function for this subtarget.
413   unsigned getStackAlignment() const { return stackAlignment; }
414
415   /// GVIsIndirectSymbol - true if the GV will be accessed via an indirect
416   /// symbol.
417   bool GVIsIndirectSymbol(const GlobalValue *GV, Reloc::Model RelocM) const;
418 };
419 } // End llvm namespace
420
421 #endif  // ARMSUBTARGET_H