Canonicalize header guards into a common format.
[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 "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   /// 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   const 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  public:
231   enum {
232     ARM_ABI_UNKNOWN,
233     ARM_ABI_APCS,
234     ARM_ABI_AAPCS // ARM EABI
235   } TargetABI;
236
237   /// This constructor initializes the data members to match that
238   /// of the specified triple.
239   ///
240   ARMSubtarget(const std::string &TT, const std::string &CPU,
241                const std::string &FS, TargetMachine &TM, bool IsLittle,
242                const TargetOptions &Options);
243
244   /// getMaxInlineSizeThreshold - Returns the maximum memset / memcpy size
245   /// that still makes it profitable to inline the call.
246   unsigned getMaxInlineSizeThreshold() const {
247     return 64;
248   }
249   /// ParseSubtargetFeatures - Parses features string setting specified
250   /// subtarget options.  Definition of function is auto generated by tblgen.
251   void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
252
253   /// \brief Reset the features for the ARM target.
254   void resetSubtargetFeatures(const MachineFunction *MF) override;
255
256   /// initializeSubtargetDependencies - Initializes using a CPU and feature string
257   /// so that we can use initializer lists for subtarget initialization.
258   ARMSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);
259
260   const DataLayout *getDataLayout() const override { return &DL; }
261   const ARMSelectionDAGInfo *getSelectionDAGInfo() const override {
262     return &TSInfo;
263   }
264   ARMJITInfo *getJITInfo() override { return &JITInfo; }
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   const DataLayout DL;
280   ARMSelectionDAGInfo TSInfo;
281   ARMJITInfo JITInfo;
282   // Either Thumb1InstrInfo or Thumb2InstrInfo.
283   std::unique_ptr<ARMBaseInstrInfo> InstrInfo;
284   ARMTargetLowering   TLInfo;
285   // Either Thumb1FrameLowering or ARMFrameLowering.
286   std::unique_ptr<ARMFrameLowering> FrameLowering;
287
288   void initializeEnvironment();
289   void resetSubtargetFeatures(StringRef CPU, StringRef FS);
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 hasV6T2Ops() const { return HasV6T2Ops; }
299   bool hasV7Ops()   const { return HasV7Ops;  }
300   bool hasV8Ops()   const { return HasV8Ops;  }
301
302   bool isCortexA5() const { return ARMProcFamily == CortexA5; }
303   bool isCortexA7() const { return ARMProcFamily == CortexA7; }
304   bool isCortexA8() const { return ARMProcFamily == CortexA8; }
305   bool isCortexA9() const { return ARMProcFamily == CortexA9; }
306   bool isCortexA15() const { return ARMProcFamily == CortexA15; }
307   bool isSwift()    const { return ARMProcFamily == Swift; }
308   bool isCortexM3() const { return CPUString == "cortex-m3"; }
309   bool isLikeA9() const { return isCortexA9() || isCortexA15() || isKrait(); }
310   bool isCortexR5() const { return ARMProcFamily == CortexR5; }
311   bool isKrait() const { return ARMProcFamily == Krait; }
312
313   bool hasARMOps() const { return !NoARM; }
314
315   bool hasVFP2() const { return HasVFPv2; }
316   bool hasVFP3() const { return HasVFPv3; }
317   bool hasVFP4() const { return HasVFPv4; }
318   bool hasFPARMv8() const { return HasFPARMv8; }
319   bool hasNEON() const { return HasNEON;  }
320   bool hasCrypto() const { return HasCrypto; }
321   bool hasCRC() const { return HasCRC; }
322   bool hasVirtualization() const { return HasVirtualization; }
323   bool useNEONForSinglePrecisionFP() const {
324     return hasNEON() && UseNEONForSinglePrecisionFP; }
325
326   bool hasDivide() const { return HasHardwareDivide; }
327   bool hasDivideInARMMode() const { return HasHardwareDivideInARM; }
328   bool hasT2ExtractPack() const { return HasT2ExtractPack; }
329   bool hasDataBarrier() const { return HasDataBarrier; }
330   bool hasAnyDataBarrier() const {
331     return HasDataBarrier || (hasV6Ops() && !isThumb());
332   }
333   bool useMulOps() const { return UseMulOps; }
334   bool useFPVMLx() const { return !SlowFPVMLx; }
335   bool hasVMLxForwarding() const { return HasVMLxForwarding; }
336   bool isFPBrccSlow() const { return SlowFPBrcc; }
337   bool isFPOnlySP() const { return FPOnlySP; }
338   bool hasPerfMon() const { return HasPerfMon; }
339   bool hasTrustZone() const { return HasTrustZone; }
340   bool hasZeroCycleZeroing() const { return HasZeroCycleZeroing; }
341   bool prefers32BitThumb() const { return Pref32BitThumb; }
342   bool avoidCPSRPartialUpdate() const { return AvoidCPSRPartialUpdate; }
343   bool avoidMOVsShifterOperand() const { return AvoidMOVsShifterOperand; }
344   bool hasRAS() const { return HasRAS; }
345   bool hasMPExtension() const { return HasMPExtension; }
346   bool hasThumb2DSP() const { return Thumb2DSP; }
347   bool useNaClTrap() const { return UseNaClTrap; }
348
349   bool hasFP16() const { return HasFP16; }
350   bool hasD16() const { return HasD16; }
351
352   const Triple &getTargetTriple() const { return TargetTriple; }
353
354   bool isTargetDarwin() const { return TargetTriple.isOSDarwin(); }
355   bool isTargetIOS() const { return TargetTriple.isiOS(); }
356   bool isTargetLinux() const { return TargetTriple.isOSLinux(); }
357   bool isTargetNaCl() const { return TargetTriple.isOSNaCl(); }
358   bool isTargetNetBSD() const { return TargetTriple.getOS() == Triple::NetBSD; }
359   bool isTargetWindows() const { return TargetTriple.isOSWindows(); }
360
361   bool isTargetCOFF() const { return TargetTriple.isOSBinFormatCOFF(); }
362   bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
363   bool isTargetMachO() const { return TargetTriple.isOSBinFormatMachO(); }
364
365   // ARM EABI is the bare-metal EABI described in ARM ABI documents and
366   // can be accessed via -target arm-none-eabi. This is NOT GNUEABI.
367   // FIXME: Add a flag for bare-metal for that target and set Triple::EABI
368   // even for GNUEABI, so we can make a distinction here and still conform to
369   // the EABI on GNU (and Android) mode. This requires change in Clang, too.
370   // FIXME: The Darwin exception is temporary, while we move users to
371   // "*-*-*-macho" triples as quickly as possible.
372   bool isTargetAEABI() const {
373     return (TargetTriple.getEnvironment() == Triple::EABI ||
374             TargetTriple.getEnvironment() == Triple::EABIHF) &&
375            !isTargetDarwin() && !isTargetWindows();
376   }
377
378   // ARM Targets that support EHABI exception handling standard
379   // Darwin uses SjLj. Other targets might need more checks.
380   bool isTargetEHABICompatible() const {
381     return (TargetTriple.getEnvironment() == Triple::EABI ||
382             TargetTriple.getEnvironment() == Triple::GNUEABI ||
383             TargetTriple.getEnvironment() == Triple::EABIHF ||
384             TargetTriple.getEnvironment() == Triple::GNUEABIHF ||
385             TargetTriple.getEnvironment() == Triple::Android) &&
386            !isTargetDarwin() && !isTargetWindows();
387   }
388
389   bool isTargetHardFloat() const {
390     // FIXME: this is invalid for WindowsCE
391     return TargetTriple.getEnvironment() == Triple::GNUEABIHF ||
392            TargetTriple.getEnvironment() == Triple::EABIHF ||
393            isTargetWindows();
394   }
395   bool isTargetAndroid() const {
396     return TargetTriple.getEnvironment() == Triple::Android;
397   }
398
399   bool isAPCS_ABI() const {
400     assert(TargetABI != ARM_ABI_UNKNOWN);
401     return TargetABI == ARM_ABI_APCS;
402   }
403   bool isAAPCS_ABI() const {
404     assert(TargetABI != ARM_ABI_UNKNOWN);
405     return TargetABI == ARM_ABI_AAPCS;
406   }
407
408   bool isThumb() const { return InThumbMode; }
409   bool isThumb1Only() const { return InThumbMode && !HasThumb2; }
410   bool isThumb2() const { return InThumbMode && HasThumb2; }
411   bool hasThumb2() const { return HasThumb2; }
412   bool isMClass() const { return ARMProcClass == MClass; }
413   bool isRClass() const { return ARMProcClass == RClass; }
414   bool isAClass() const { return ARMProcClass == AClass; }
415
416   bool isR9Reserved() const { return IsR9Reserved; }
417
418   bool useMovt(const MachineFunction &MF) const;
419
420   bool supportsTailCall() const { return SupportsTailCall; }
421
422   bool allowsUnalignedMem() const { return AllowsUnalignedMem; }
423
424   bool restrictIT() const { return RestrictIT; }
425
426   const std::string & getCPUString() const { return CPUString; }
427
428   bool isLittle() const { return IsLittle; }
429
430   unsigned getMispredictionPenalty() const;
431
432   /// This function returns true if the target has sincos() routine in its
433   /// compiler runtime or math libraries.
434   bool hasSinCos() const;
435
436   /// True for some subtargets at > -O0.
437   bool enablePostMachineScheduler() 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 {
445     return &InstrItins;
446   }
447
448   /// getStackAlignment - Returns the minimum alignment known to hold of the
449   /// stack frame on entry to the function and which must be maintained by every
450   /// function for this subtarget.
451   unsigned getStackAlignment() const { return stackAlignment; }
452
453   /// GVIsIndirectSymbol - true if the GV will be accessed via an indirect
454   /// symbol.
455   bool GVIsIndirectSymbol(const GlobalValue *GV, Reloc::Model RelocM) const;
456
457 };
458 } // End llvm namespace
459
460 #endif  // ARMSUBTARGET_H