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