constify TargetMachine argument.
[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, const TargetMachine &TM, bool IsLittle);
240
241   /// getMaxInlineSizeThreshold - Returns the maximum memset / memcpy size
242   /// that still makes it profitable to inline the call.
243   unsigned getMaxInlineSizeThreshold() const {
244     return 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   /// initializeSubtargetDependencies - Initializes using a CPU and feature string
251   /// so that we can use initializer lists for subtarget initialization.
252   ARMSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);
253
254   const DataLayout *getDataLayout() const override { return &DL; }
255   const ARMSelectionDAGInfo *getSelectionDAGInfo() const override {
256     return &TSInfo;
257   }
258   const ARMBaseInstrInfo *getInstrInfo() const override {
259     return InstrInfo.get();
260   }
261   const ARMTargetLowering *getTargetLowering() const override {
262     return &TLInfo;
263   }
264   const ARMFrameLowering *getFrameLowering() const override {
265     return FrameLowering.get();
266   }
267   const ARMBaseRegisterInfo *getRegisterInfo() const override {
268     return &InstrInfo->getRegisterInfo();
269   }
270
271 private:
272   const DataLayout DL;
273   ARMSelectionDAGInfo TSInfo;
274   // Either Thumb1InstrInfo or Thumb2InstrInfo.
275   std::unique_ptr<ARMBaseInstrInfo> InstrInfo;
276   ARMTargetLowering   TLInfo;
277   // Either Thumb1FrameLowering or ARMFrameLowering.
278   std::unique_ptr<ARMFrameLowering> FrameLowering;
279
280   void initializeEnvironment();
281   void initSubtargetFeatures(StringRef CPU, StringRef FS);
282 public:
283   void computeIssueWidth();
284
285   bool hasV4TOps()  const { return HasV4TOps;  }
286   bool hasV5TOps()  const { return HasV5TOps;  }
287   bool hasV5TEOps() const { return HasV5TEOps; }
288   bool hasV6Ops()   const { return HasV6Ops;   }
289   bool hasV6MOps()  const { return HasV6MOps;  }
290   bool hasV6T2Ops() const { return HasV6T2Ops; }
291   bool hasV7Ops()   const { return HasV7Ops;  }
292   bool hasV8Ops()   const { return HasV8Ops;  }
293
294   bool isCortexA5() const { return ARMProcFamily == CortexA5; }
295   bool isCortexA7() const { return ARMProcFamily == CortexA7; }
296   bool isCortexA8() const { return ARMProcFamily == CortexA8; }
297   bool isCortexA9() const { return ARMProcFamily == CortexA9; }
298   bool isCortexA15() const { return ARMProcFamily == CortexA15; }
299   bool isSwift()    const { return ARMProcFamily == Swift; }
300   bool isCortexM3() const { return CPUString == "cortex-m3"; }
301   bool isLikeA9() const { return isCortexA9() || isCortexA15() || isKrait(); }
302   bool isCortexR5() const { return ARMProcFamily == CortexR5; }
303   bool isKrait() const { return ARMProcFamily == Krait; }
304
305   bool hasARMOps() const { return !NoARM; }
306
307   bool hasVFP2() const { return HasVFPv2; }
308   bool hasVFP3() const { return HasVFPv3; }
309   bool hasVFP4() const { return HasVFPv4; }
310   bool hasFPARMv8() const { return HasFPARMv8; }
311   bool hasNEON() const { return HasNEON;  }
312   bool hasCrypto() const { return HasCrypto; }
313   bool hasCRC() const { return HasCRC; }
314   bool hasVirtualization() const { return HasVirtualization; }
315   bool useNEONForSinglePrecisionFP() const {
316     return hasNEON() && UseNEONForSinglePrecisionFP; }
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.getOS() == Triple::NetBSD; }
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     assert(TargetABI != ARM_ABI_UNKNOWN);
393     return TargetABI == ARM_ABI_APCS;
394   }
395   bool isAAPCS_ABI() const {
396     assert(TargetABI != ARM_ABI_UNKNOWN);
397     return TargetABI == ARM_ABI_AAPCS;
398   }
399
400   bool isThumb() const { return InThumbMode; }
401   bool isThumb1Only() const { return InThumbMode && !HasThumb2; }
402   bool isThumb2() const { return InThumbMode && HasThumb2; }
403   bool hasThumb2() const { return HasThumb2; }
404   bool isMClass() const { return ARMProcClass == MClass; }
405   bool isRClass() const { return ARMProcClass == RClass; }
406   bool isAClass() const { return ARMProcClass == AClass; }
407
408   bool isR9Reserved() const { return IsR9Reserved; }
409
410   bool useMovt(const MachineFunction &MF) const;
411
412   bool supportsTailCall() const { return SupportsTailCall; }
413
414   bool allowsUnalignedMem() const { return AllowsUnalignedMem; }
415
416   bool restrictIT() const { return RestrictIT; }
417
418   const std::string & getCPUString() const { return CPUString; }
419
420   bool isLittle() const { return IsLittle; }
421
422   unsigned getMispredictionPenalty() const;
423
424   /// This function returns true if the target has sincos() routine in its
425   /// compiler runtime or math libraries.
426   bool hasSinCos() const;
427
428   /// True for some subtargets at > -O0.
429   bool enablePostMachineScheduler() const override;
430
431   // enableAtomicExpand- True if we need to expand our atomics.
432   bool enableAtomicExpand() const override;
433
434   /// getInstrItins - Return the instruction itineraries based on subtarget
435   /// selection.
436   const InstrItineraryData *getInstrItineraryData() const override {
437     return &InstrItins;
438   }
439
440   /// getStackAlignment - Returns the minimum alignment known to hold of the
441   /// stack frame on entry to the function and which must be maintained by every
442   /// function for this subtarget.
443   unsigned getStackAlignment() const { return stackAlignment; }
444
445   /// GVIsIndirectSymbol - true if the GV will be accessed via an indirect
446   /// symbol.
447   bool GVIsIndirectSymbol(const GlobalValue *GV, Reloc::Model RelocM) const;
448
449 };
450 } // End llvm namespace
451
452 #endif  // ARMSUBTARGET_H