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