Reinstate "Nuke the old JIT."
[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 "Thumb1FrameLowering.h"
24 #include "Thumb1InstrInfo.h"
25 #include "Thumb2InstrInfo.h"
26 #include "MCTargetDesc/ARMMCTargetDesc.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
41 class ARMSubtarget : public ARMGenSubtargetInfo {
42 protected:
43   enum ARMProcFamilyEnum {
44     Others, CortexA5, CortexA7, CortexA8, CortexA9, CortexA12, CortexA15,
45     CortexR5, Swift, CortexA53, CortexA57, Krait
46   };
47   enum ARMProcClassEnum {
48     None, AClass, RClass, MClass
49   };
50
51   /// ARMProcFamily - ARM processor family: Cortex-A8, Cortex-A9, and others.
52   ARMProcFamilyEnum ARMProcFamily;
53
54   /// ARMProcClass - ARM processor class: None, AClass, RClass or MClass.
55   ARMProcClassEnum ARMProcClass;
56
57   /// HasV4TOps, HasV5TOps, HasV5TEOps,
58   /// HasV6Ops, HasV6MOps, HasV6T2Ops, HasV7Ops, HasV8Ops -
59   /// Specify whether target support specific ARM ISA variants.
60   bool HasV4TOps;
61   bool HasV5TOps;
62   bool HasV5TEOps;
63   bool HasV6Ops;
64   bool HasV6MOps;
65   bool HasV6T2Ops;
66   bool HasV7Ops;
67   bool HasV8Ops;
68
69   /// HasVFPv2, HasVFPv3, HasVFPv4, HasFPARMv8, HasNEON - Specify what
70   /// floating point ISAs are supported.
71   bool HasVFPv2;
72   bool HasVFPv3;
73   bool HasVFPv4;
74   bool HasFPARMv8;
75   bool HasNEON;
76
77   /// UseNEONForSinglePrecisionFP - if the NEONFP attribute has been
78   /// specified. Use the method useNEONForSinglePrecisionFP() to
79   /// determine if NEON should actually be used.
80   bool UseNEONForSinglePrecisionFP;
81
82   /// UseMulOps - True if non-microcoded fused integer multiply-add and
83   /// multiply-subtract instructions should be used.
84   bool UseMulOps;
85
86   /// SlowFPVMLx - If the VFP2 / NEON instructions are available, indicates
87   /// whether the FP VML[AS] instructions are slow (if so, don't use them).
88   bool SlowFPVMLx;
89
90   /// HasVMLxForwarding - If true, NEON has special multiplier accumulator
91   /// forwarding to allow mul + mla being issued back to back.
92   bool HasVMLxForwarding;
93
94   /// SlowFPBrcc - True if floating point compare + branch is slow.
95   bool SlowFPBrcc;
96
97   /// InThumbMode - True if compiling for Thumb, false for ARM.
98   bool InThumbMode;
99
100   /// HasThumb2 - True if Thumb2 instructions are supported.
101   bool HasThumb2;
102
103   /// NoARM - True if subtarget does not support ARM mode execution.
104   bool NoARM;
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::allowsMisalignedMemoryAccesses().
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   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, TargetMachine &TM, 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 override { return &DL; }
259   const ARMSelectionDAGInfo *getSelectionDAGInfo() const override {
260     return &TSInfo;
261   }
262   const ARMBaseInstrInfo *getInstrInfo() const override {
263     return InstrInfo.get();
264   }
265   const ARMTargetLowering *getTargetLowering() const override {
266     return &TLInfo;
267   }
268   const ARMFrameLowering *getFrameLowering() const override {
269     return FrameLowering.get();
270   }
271   const ARMBaseRegisterInfo *getRegisterInfo() const override {
272     return &InstrInfo->getRegisterInfo();
273   }
274
275 private:
276   const DataLayout DL;
277   ARMSelectionDAGInfo TSInfo;
278   // Either Thumb1InstrInfo or Thumb2InstrInfo.
279   std::unique_ptr<ARMBaseInstrInfo> InstrInfo;
280   ARMTargetLowering   TLInfo;
281   // Either Thumb1FrameLowering or ARMFrameLowering.
282   std::unique_ptr<ARMFrameLowering> FrameLowering;
283
284   void initializeEnvironment();
285   void resetSubtargetFeatures(StringRef CPU, StringRef FS);
286 public:
287   void computeIssueWidth();
288
289   bool hasV4TOps()  const { return HasV4TOps;  }
290   bool hasV5TOps()  const { return HasV5TOps;  }
291   bool hasV5TEOps() const { return HasV5TEOps; }
292   bool hasV6Ops()   const { return HasV6Ops;   }
293   bool hasV6MOps()  const { return HasV6MOps;  }
294   bool hasV6T2Ops() const { return HasV6T2Ops; }
295   bool hasV7Ops()   const { return HasV7Ops;  }
296   bool hasV8Ops()   const { return HasV8Ops;  }
297
298   bool isCortexA5() const { return ARMProcFamily == CortexA5; }
299   bool isCortexA7() const { return ARMProcFamily == CortexA7; }
300   bool isCortexA8() const { return ARMProcFamily == CortexA8; }
301   bool isCortexA9() const { return ARMProcFamily == CortexA9; }
302   bool isCortexA15() const { return ARMProcFamily == CortexA15; }
303   bool isSwift()    const { return ARMProcFamily == Swift; }
304   bool isCortexM3() const { return CPUString == "cortex-m3"; }
305   bool isLikeA9() const { return isCortexA9() || isCortexA15() || isKrait(); }
306   bool isCortexR5() const { return ARMProcFamily == CortexR5; }
307   bool isKrait() const { return ARMProcFamily == Krait; }
308
309   bool hasARMOps() const { return !NoARM; }
310
311   bool hasVFP2() const { return HasVFPv2; }
312   bool hasVFP3() const { return HasVFPv3; }
313   bool hasVFP4() const { return HasVFPv4; }
314   bool hasFPARMv8() const { return HasFPARMv8; }
315   bool hasNEON() const { return HasNEON;  }
316   bool hasCrypto() const { return HasCrypto; }
317   bool hasCRC() const { return HasCRC; }
318   bool hasVirtualization() const { return HasVirtualization; }
319   bool useNEONForSinglePrecisionFP() const {
320     return hasNEON() && UseNEONForSinglePrecisionFP; }
321
322   bool hasDivide() const { return HasHardwareDivide; }
323   bool hasDivideInARMMode() const { return HasHardwareDivideInARM; }
324   bool hasT2ExtractPack() const { return HasT2ExtractPack; }
325   bool hasDataBarrier() const { return HasDataBarrier; }
326   bool hasAnyDataBarrier() const {
327     return HasDataBarrier || (hasV6Ops() && !isThumb());
328   }
329   bool useMulOps() const { return UseMulOps; }
330   bool useFPVMLx() const { return !SlowFPVMLx; }
331   bool hasVMLxForwarding() const { return HasVMLxForwarding; }
332   bool isFPBrccSlow() const { return SlowFPBrcc; }
333   bool isFPOnlySP() const { return FPOnlySP; }
334   bool hasPerfMon() const { return HasPerfMon; }
335   bool hasTrustZone() const { return HasTrustZone; }
336   bool hasZeroCycleZeroing() const { return HasZeroCycleZeroing; }
337   bool prefers32BitThumb() const { return Pref32BitThumb; }
338   bool avoidCPSRPartialUpdate() const { return AvoidCPSRPartialUpdate; }
339   bool avoidMOVsShifterOperand() const { return AvoidMOVsShifterOperand; }
340   bool hasRAS() const { return HasRAS; }
341   bool hasMPExtension() const { return HasMPExtension; }
342   bool hasThumb2DSP() const { return Thumb2DSP; }
343   bool useNaClTrap() const { return UseNaClTrap; }
344
345   bool hasFP16() const { return HasFP16; }
346   bool hasD16() const { return HasD16; }
347
348   const Triple &getTargetTriple() const { return TargetTriple; }
349
350   bool isTargetDarwin() const { return TargetTriple.isOSDarwin(); }
351   bool isTargetIOS() const { return TargetTriple.isiOS(); }
352   bool isTargetLinux() const { return TargetTriple.isOSLinux(); }
353   bool isTargetNaCl() const { return TargetTriple.isOSNaCl(); }
354   bool isTargetNetBSD() const { return TargetTriple.getOS() == Triple::NetBSD; }
355   bool isTargetWindows() const { return TargetTriple.isOSWindows(); }
356
357   bool isTargetCOFF() const { return TargetTriple.isOSBinFormatCOFF(); }
358   bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
359   bool isTargetMachO() const { return TargetTriple.isOSBinFormatMachO(); }
360
361   // ARM EABI is the bare-metal EABI described in ARM ABI documents and
362   // can be accessed via -target arm-none-eabi. This is NOT GNUEABI.
363   // FIXME: Add a flag for bare-metal for that target and set Triple::EABI
364   // even for GNUEABI, so we can make a distinction here and still conform to
365   // the EABI on GNU (and Android) mode. This requires change in Clang, too.
366   // FIXME: The Darwin exception is temporary, while we move users to
367   // "*-*-*-macho" triples as quickly as possible.
368   bool isTargetAEABI() const {
369     return (TargetTriple.getEnvironment() == Triple::EABI ||
370             TargetTriple.getEnvironment() == Triple::EABIHF) &&
371            !isTargetDarwin() && !isTargetWindows();
372   }
373
374   // ARM Targets that support EHABI exception handling standard
375   // Darwin uses SjLj. Other targets might need more checks.
376   bool isTargetEHABICompatible() const {
377     return (TargetTriple.getEnvironment() == Triple::EABI ||
378             TargetTriple.getEnvironment() == Triple::GNUEABI ||
379             TargetTriple.getEnvironment() == Triple::EABIHF ||
380             TargetTriple.getEnvironment() == Triple::GNUEABIHF ||
381             TargetTriple.getEnvironment() == Triple::Android) &&
382            !isTargetDarwin() && !isTargetWindows();
383   }
384
385   bool isTargetHardFloat() const {
386     // FIXME: this is invalid for WindowsCE
387     return TargetTriple.getEnvironment() == Triple::GNUEABIHF ||
388            TargetTriple.getEnvironment() == Triple::EABIHF ||
389            isTargetWindows();
390   }
391   bool isTargetAndroid() const {
392     return TargetTriple.getEnvironment() == Triple::Android;
393   }
394
395   bool isAPCS_ABI() const {
396     assert(TargetABI != ARM_ABI_UNKNOWN);
397     return TargetABI == ARM_ABI_APCS;
398   }
399   bool isAAPCS_ABI() const {
400     assert(TargetABI != ARM_ABI_UNKNOWN);
401     return TargetABI == ARM_ABI_AAPCS;
402   }
403
404   bool isThumb() const { return InThumbMode; }
405   bool isThumb1Only() const { return InThumbMode && !HasThumb2; }
406   bool isThumb2() const { return InThumbMode && HasThumb2; }
407   bool hasThumb2() const { return HasThumb2; }
408   bool isMClass() const { return ARMProcClass == MClass; }
409   bool isRClass() const { return ARMProcClass == RClass; }
410   bool isAClass() const { return ARMProcClass == AClass; }
411
412   bool isR9Reserved() const { return IsR9Reserved; }
413
414   bool useMovt(const MachineFunction &MF) const;
415
416   bool supportsTailCall() const { return SupportsTailCall; }
417
418   bool allowsUnalignedMem() const { return AllowsUnalignedMem; }
419
420   bool restrictIT() const { return RestrictIT; }
421
422   const std::string & getCPUString() const { return CPUString; }
423
424   bool isLittle() const { return IsLittle; }
425
426   unsigned getMispredictionPenalty() const;
427
428   /// This function returns true if the target has sincos() routine in its
429   /// compiler runtime or math libraries.
430   bool hasSinCos() const;
431
432   /// True for some subtargets at > -O0.
433   bool enablePostMachineScheduler() const override;
434
435   // enableAtomicExpand- True if we need to expand our atomics.
436   bool enableAtomicExpand() const override;
437
438   /// getInstrItins - Return the instruction itineraries based on subtarget
439   /// selection.
440   const InstrItineraryData *getInstrItineraryData() const {
441     return &InstrItins;
442   }
443
444   /// getStackAlignment - Returns the minimum alignment known to hold of the
445   /// stack frame on entry to the function and which must be maintained by every
446   /// function for this subtarget.
447   unsigned getStackAlignment() const { return stackAlignment; }
448
449   /// GVIsIndirectSymbol - true if the GV will be accessed via an indirect
450   /// symbol.
451   bool GVIsIndirectSymbol(const GlobalValue *GV, Reloc::Model RelocM) const;
452
453 };
454 } // End llvm namespace
455
456 #endif  // ARMSUBTARGET_H