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