1 //===-- ARMSubtarget.h - Define Subtarget for the ARM ----------*- C++ -*--===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the ARM specific subclass of TargetSubtargetInfo.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_ARM_ARMSUBTARGET_H
15 #define LLVM_LIB_TARGET_ARM_ARMSUBTARGET_H
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"
33 #define GET_SUBTARGETINFO_HEADER
34 #include "ARMGenSubtargetInfo.inc"
41 class ARMSubtarget : public ARMGenSubtargetInfo {
43 enum ARMProcFamilyEnum {
44 Others, CortexA5, CortexA7, CortexA8, CortexA9, CortexA12, CortexA15,
45 CortexR5, Swift, CortexA53, CortexA57, Krait
47 enum ARMProcClassEnum {
48 None, AClass, RClass, MClass
51 /// ARMProcFamily - ARM processor family: Cortex-A8, Cortex-A9, and others.
52 ARMProcFamilyEnum ARMProcFamily;
54 /// ARMProcClass - ARM processor class: None, AClass, RClass or MClass.
55 ARMProcClassEnum ARMProcClass;
57 /// HasV4TOps, HasV5TOps, HasV5TEOps,
58 /// HasV6Ops, HasV6MOps, HasV6T2Ops, HasV7Ops, HasV8Ops -
59 /// Specify whether target support specific ARM ISA variants.
69 /// HasVFPv2, HasVFPv3, HasVFPv4, HasFPARMv8, HasNEON - Specify what
70 /// floating point ISAs are supported.
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;
82 /// UseMulOps - True if non-microcoded fused integer multiply-add and
83 /// multiply-subtract instructions should be used.
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).
90 /// HasVMLxForwarding - If true, NEON has special multiplier accumulator
91 /// forwarding to allow mul + mla being issued back to back.
92 bool HasVMLxForwarding;
94 /// SlowFPBrcc - True if floating point compare + branch is slow.
97 /// InThumbMode - True if compiling for Thumb, false for ARM.
100 /// HasThumb2 - True if Thumb2 instructions are supported.
103 /// NoARM - True if subtarget does not support ARM mode execution.
106 /// IsR9Reserved - True if R9 is a not available as general purpose register.
109 /// UseMovt - True if MOVT / MOVW pairs are used for materialization of 32-bit
110 /// imms (including global addresses).
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
116 bool SupportsTailCall;
118 /// HasFP16 - True if subtarget supports half-precision FP (We support VFP+HF
122 /// HasD16 - True if subtarget is limited to 16 double precision
123 /// FP registers for VFPv3.
126 /// HasHardwareDivide - True if subtarget supports [su]div
127 bool HasHardwareDivide;
129 /// HasHardwareDivideInARM - True if subtarget supports [su]div in ARM mode
130 bool HasHardwareDivideInARM;
132 /// HasT2ExtractPack - True if subtarget supports thumb2 extract/pack
134 bool HasT2ExtractPack;
136 /// HasDataBarrier - True if the subtarget supports DMB / DSB data barrier
140 /// Pref32BitThumb - If true, codegen would prefer 32-bit Thumb instructions
141 /// over 16-bit ones.
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;
149 /// AvoidMOVsShifterOperand - If true, codegen should avoid using flag setting
150 /// movs with shifter operand (i.e. asr, lsl, lsr).
151 bool AvoidMOVsShifterOperand;
153 /// HasRAS - Some processors perform return stack prediction. CodeGen should
154 /// avoid issue "normal" call instructions to callees which do not return.
157 /// HasMPExtension - True if the subtarget supports Multiprocessing
158 /// extension (ARMv7 only).
161 /// HasVirtualization - True if the subtarget supports the Virtualization
163 bool HasVirtualization;
165 /// FPOnlySP - If true, the floating point unit only supports single
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.
174 /// HasTrustZone - if true, processor supports TrustZone security extensions
177 /// HasCrypto - if true, processor supports Cryptography extensions
180 /// HasCRC - if true, processor supports CRC instructions
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;
187 /// AllowsUnalignedMem - If true, the subtarget allows unaligned memory
188 /// accesses for some types. For details, see
189 /// ARMTargetLowering::allowsMisalignedMemoryAccesses().
190 bool AllowsUnalignedMem;
192 /// RestrictIT - If true, the subtarget disallows generation of deprecated IT
193 /// blocks to conform to ARMv8 rule.
196 /// Thumb2DSP - If true, the subtarget supports the v7 DSP (saturating arith
197 /// and such) instructions in Thumb2 code.
200 /// NaCl TRAP instruction is generated instead of the regular TRAP.
203 /// Target machine allowed unsafe FP math (such as use of NEON fp)
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;
210 /// CPUString - String name of used CPU.
211 std::string CPUString;
213 /// IsLittle - The target is Little Endian
216 /// TargetTriple - What processor and OS we're targeting.
219 /// SchedModel - Processor specific instruction costs.
220 MCSchedModel SchedModel;
222 /// Selected instruction itineraries (one entry per itinerary class.)
223 InstrItineraryData InstrItins;
225 /// Options passed via command line that could influence the target
226 const TargetOptions &Options;
232 ARM_ABI_AAPCS // ARM EABI
235 /// This constructor initializes the data members to match that
236 /// of the specified triple.
238 ARMSubtarget(const std::string &TT, const std::string &CPU,
239 const std::string &FS, const TargetMachine &TM, bool IsLittle);
241 /// getMaxInlineSizeThreshold - Returns the maximum memset / memcpy size
242 /// that still makes it profitable to inline the call.
243 unsigned getMaxInlineSizeThreshold() const {
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);
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);
254 const DataLayout *getDataLayout() const override { return &DL; }
255 const ARMSelectionDAGInfo *getSelectionDAGInfo() const override {
258 const ARMBaseInstrInfo *getInstrInfo() const override {
259 return InstrInfo.get();
261 const ARMTargetLowering *getTargetLowering() const override {
264 const ARMFrameLowering *getFrameLowering() const override {
265 return FrameLowering.get();
267 const ARMBaseRegisterInfo *getRegisterInfo() const override {
268 return &InstrInfo->getRegisterInfo();
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;
280 void initializeEnvironment();
281 void initSubtargetFeatures(StringRef CPU, StringRef FS);
283 void computeIssueWidth();
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; }
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; }
305 bool hasARMOps() const { return !NoARM; }
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; }
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());
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; }
341 bool hasFP16() const { return HasFP16; }
342 bool hasD16() const { return HasD16; }
344 const Triple &getTargetTriple() const { return TargetTriple; }
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(); }
353 bool isTargetCOFF() const { return TargetTriple.isOSBinFormatCOFF(); }
354 bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
355 bool isTargetMachO() const { return TargetTriple.isOSBinFormatMachO(); }
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();
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();
381 bool isTargetHardFloat() const {
382 // FIXME: this is invalid for WindowsCE
383 return TargetTriple.getEnvironment() == Triple::GNUEABIHF ||
384 TargetTriple.getEnvironment() == Triple::EABIHF ||
387 bool isTargetAndroid() const {
388 return TargetTriple.getEnvironment() == Triple::Android;
391 bool isAPCS_ABI() const {
392 assert(TargetABI != ARM_ABI_UNKNOWN);
393 return TargetABI == ARM_ABI_APCS;
395 bool isAAPCS_ABI() const {
396 assert(TargetABI != ARM_ABI_UNKNOWN);
397 return TargetABI == ARM_ABI_AAPCS;
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; }
409 return isThumb1Only() && isMClass();
412 bool isR9Reserved() const { return IsR9Reserved; }
414 bool useMovt(const MachineFunction &MF) const;
416 bool supportsTailCall() const { return SupportsTailCall; }
418 bool allowsUnalignedMem() const { return AllowsUnalignedMem; }
420 bool restrictIT() const { return RestrictIT; }
422 const std::string & getCPUString() const { return CPUString; }
424 bool isLittle() const { return IsLittle; }
426 unsigned getMispredictionPenalty() const;
428 /// This function returns true if the target has sincos() routine in its
429 /// compiler runtime or math libraries.
430 bool hasSinCos() const;
432 /// True for some subtargets at > -O0.
433 bool enablePostMachineScheduler() const override;
435 // enableAtomicExpand- True if we need to expand our atomics.
436 bool enableAtomicExpand() const override;
438 /// getInstrItins - Return the instruction itineraries based on subtarget
440 const InstrItineraryData *getInstrItineraryData() const override {
444 /// getStackAlignment - Returns the minimum alignment known to hold of the
445 /// stack frame on entry to the function and which must be maintained by every
446 /// function for this subtarget.
447 unsigned getStackAlignment() const { return stackAlignment; }
449 /// GVIsIndirectSymbol - true if the GV will be accessed via an indirect
451 bool GVIsIndirectSymbol(const GlobalValue *GV, Reloc::Model RelocM) const;
454 } // End llvm namespace
456 #endif // ARMSUBTARGET_H