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