Remove unused MCSubtargetInfo argument from the ARM MCInstPrinter ctors.
[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   /// HasV8_1a - if true, the processor has V8.1a: PAN and RDMA extensions
186   bool HasV8_1a;
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::allowsMisalignedMemoryAccesses().
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   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   const ARMBaseTargetMachine &TM;
234
235 public:
236   /// This constructor initializes the data members to match that
237   /// of the specified triple.
238   ///
239   ARMSubtarget(const std::string &TT, const std::string &CPU,
240                const std::string &FS, const ARMBaseTargetMachine &TM, bool IsLittle);
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   /// initializeSubtargetDependencies - Initializes using a CPU and feature string
252   /// so that we can use initializer lists for subtarget initialization.
253   ARMSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);
254
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   ARMSelectionDAGInfo TSInfo;
273   // Either Thumb1FrameLowering or ARMFrameLowering.
274   std::unique_ptr<ARMFrameLowering> FrameLowering;
275   // Either Thumb1InstrInfo or Thumb2InstrInfo.
276   std::unique_ptr<ARMBaseInstrInfo> InstrInfo;
277   ARMTargetLowering   TLInfo;
278
279   void initializeEnvironment();
280   void initSubtargetFeatures(StringRef CPU, StringRef FS);
281   ARMFrameLowering *initializeFrameLowering(StringRef CPU, StringRef FS);
282
283 public:
284   void computeIssueWidth();
285
286   bool hasV4TOps()  const { return HasV4TOps;  }
287   bool hasV5TOps()  const { return HasV5TOps;  }
288   bool hasV5TEOps() const { return HasV5TEOps; }
289   bool hasV6Ops()   const { return HasV6Ops;   }
290   bool hasV6MOps()  const { return HasV6MOps;  }
291   bool hasV6KOps()  const { return HasV6KOps; }
292   bool hasV6T2Ops() const { return HasV6T2Ops; }
293   bool hasV7Ops()   const { return HasV7Ops;  }
294   bool hasV8Ops()   const { return HasV8Ops;  }
295
296   bool isCortexA5() const { return ARMProcFamily == CortexA5; }
297   bool isCortexA7() const { return ARMProcFamily == CortexA7; }
298   bool isCortexA8() const { return ARMProcFamily == CortexA8; }
299   bool isCortexA9() const { return ARMProcFamily == CortexA9; }
300   bool isCortexA15() const { return ARMProcFamily == CortexA15; }
301   bool isSwift()    const { return ARMProcFamily == Swift; }
302   bool isCortexM3() const { return CPUString == "cortex-m3"; }
303   bool isLikeA9() const { return isCortexA9() || isCortexA15() || isKrait(); }
304   bool isCortexR5() const { return ARMProcFamily == CortexR5; }
305   bool isKrait() const { return ARMProcFamily == Krait; }
306
307   bool hasARMOps() const { return !NoARM; }
308
309   bool hasVFP2() const { return HasVFPv2; }
310   bool hasVFP3() const { return HasVFPv3; }
311   bool hasVFP4() const { return HasVFPv4; }
312   bool hasFPARMv8() const { return HasFPARMv8; }
313   bool hasNEON() const { return HasNEON;  }
314   bool hasCrypto() const { return HasCrypto; }
315   bool hasCRC() const { return HasCRC; }
316   bool hasV8_1a() const { return HasV8_1a; }
317   bool hasVirtualization() const { return HasVirtualization; }
318   bool useNEONForSinglePrecisionFP() const {
319     return hasNEON() && UseNEONForSinglePrecisionFP;
320   }
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.isOSNetBSD(); }
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   bool isAAPCS_ABI() const;
397
398   bool isThumb() const { return InThumbMode; }
399   bool isThumb1Only() const { return InThumbMode && !HasThumb2; }
400   bool isThumb2() const { return InThumbMode && HasThumb2; }
401   bool hasThumb2() const { return HasThumb2; }
402   bool isMClass() const { return ARMProcClass == MClass; }
403   bool isRClass() const { return ARMProcClass == RClass; }
404   bool isAClass() const { return ARMProcClass == AClass; }
405
406   bool isV6M() const {
407     return isThumb1Only() && isMClass();
408   }
409
410   bool isR9Reserved() const { return IsR9Reserved; }
411
412   bool useMovt(const MachineFunction &MF) const;
413
414   bool supportsTailCall() const { return SupportsTailCall; }
415
416   bool allowsUnalignedMem() const { return AllowsUnalignedMem; }
417
418   bool restrictIT() const { return RestrictIT; }
419
420   const std::string & getCPUString() const { return CPUString; }
421
422   bool isLittle() const { return IsLittle; }
423
424   unsigned getMispredictionPenalty() const;
425
426   /// This function returns true if the target has sincos() routine in its
427   /// compiler runtime or math libraries.
428   bool hasSinCos() const;
429
430   /// True for some subtargets at > -O0.
431   bool enablePostMachineScheduler() const override;
432
433   // enableAtomicExpand- True if we need to expand our atomics.
434   bool enableAtomicExpand() const override;
435
436   /// getInstrItins - Return the instruction itineraries based on subtarget
437   /// selection.
438   const InstrItineraryData *getInstrItineraryData() const override {
439     return &InstrItins;
440   }
441
442   /// getStackAlignment - Returns the minimum alignment known to hold of the
443   /// stack frame on entry to the function and which must be maintained by every
444   /// function for this subtarget.
445   unsigned getStackAlignment() const { return stackAlignment; }
446
447   /// GVIsIndirectSymbol - true if the GV will be accessed via an indirect
448   /// symbol.
449   bool GVIsIndirectSymbol(const GlobalValue *GV, Reloc::Model RelocM) const;
450
451 };
452 } // End llvm namespace
453
454 #endif  // ARMSUBTARGET_H