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 ARMSUBTARGET_H
15 #define ARMSUBTARGET_H
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"
35 #define GET_SUBTARGETINFO_HEADER
36 #include "ARMGenSubtargetInfo.inc"
43 class ARMSubtarget : public ARMGenSubtargetInfo {
45 enum ARMProcFamilyEnum {
46 Others, CortexA5, CortexA7, CortexA8, CortexA9, CortexA12, CortexA15,
47 CortexR5, Swift, CortexA53, CortexA57, Krait
49 enum ARMProcClassEnum {
50 None, AClass, RClass, MClass
53 /// ARMProcFamily - ARM processor family: Cortex-A8, Cortex-A9, and others.
54 ARMProcFamilyEnum ARMProcFamily;
56 /// ARMProcClass - ARM processor class: None, AClass, RClass or MClass.
57 ARMProcClassEnum ARMProcClass;
59 /// HasV4TOps, HasV5TOps, HasV5TEOps,
60 /// HasV6Ops, HasV6MOps, HasV6T2Ops, HasV7Ops, HasV8Ops -
61 /// Specify whether target support specific ARM ISA variants.
71 /// HasVFPv2, HasVFPv3, HasVFPv4, HasFPARMv8, HasNEON - Specify what
72 /// floating point ISAs are supported.
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;
84 /// UseMulOps - True if non-microcoded fused integer multiply-add and
85 /// multiply-subtract instructions should be used.
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).
92 /// HasVMLxForwarding - If true, NEON has special multiplier accumulator
93 /// forwarding to allow mul + mla being issued back to back.
94 bool HasVMLxForwarding;
96 /// SlowFPBrcc - True if floating point compare + branch is slow.
99 /// InThumbMode - True if compiling for Thumb, false for ARM.
102 /// HasThumb2 - True if Thumb2 instructions are supported.
105 /// NoARM - True if subtarget does not support ARM mode execution.
108 /// PostRAScheduler - True if using post-register-allocation scheduler.
109 bool PostRAScheduler;
111 /// IsR9Reserved - True if R9 is a not available as general purpose register.
114 /// UseMovt - True if MOVT / MOVW pairs are used for materialization of 32-bit
115 /// imms (including global addresses).
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
121 bool SupportsTailCall;
123 /// HasFP16 - True if subtarget supports half-precision FP (We support VFP+HF
127 /// HasD16 - True if subtarget is limited to 16 double precision
128 /// FP registers for VFPv3.
131 /// HasHardwareDivide - True if subtarget supports [su]div
132 bool HasHardwareDivide;
134 /// HasHardwareDivideInARM - True if subtarget supports [su]div in ARM mode
135 bool HasHardwareDivideInARM;
137 /// HasT2ExtractPack - True if subtarget supports thumb2 extract/pack
139 bool HasT2ExtractPack;
141 /// HasDataBarrier - True if the subtarget supports DMB / DSB data barrier
145 /// Pref32BitThumb - If true, codegen would prefer 32-bit Thumb instructions
146 /// over 16-bit ones.
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;
154 /// AvoidMOVsShifterOperand - If true, codegen should avoid using flag setting
155 /// movs with shifter operand (i.e. asr, lsl, lsr).
156 bool AvoidMOVsShifterOperand;
158 /// HasRAS - Some processors perform return stack prediction. CodeGen should
159 /// avoid issue "normal" call instructions to callees which do not return.
162 /// HasMPExtension - True if the subtarget supports Multiprocessing
163 /// extension (ARMv7 only).
166 /// HasVirtualization - True if the subtarget supports the Virtualization
168 bool HasVirtualization;
170 /// FPOnlySP - If true, the floating point unit only supports single
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.
179 /// HasTrustZone - if true, processor supports TrustZone security extensions
182 /// HasCrypto - if true, processor supports Cryptography extensions
185 /// HasCRC - if true, processor supports CRC instructions
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;
192 /// AllowsUnalignedMem - If true, the subtarget allows unaligned memory
193 /// accesses for some types. For details, see
194 /// ARMTargetLowering::allowsUnalignedMemoryAccesses().
195 bool AllowsUnalignedMem;
197 /// RestrictIT - If true, the subtarget disallows generation of deprecated IT
198 /// blocks to conform to ARMv8 rule.
201 /// Thumb2DSP - If true, the subtarget supports the v7 DSP (saturating arith
202 /// and such) instructions in Thumb2 code.
205 /// NaCl TRAP instruction is generated instead of the regular TRAP.
208 /// Target machine allowed unsafe FP math (such as use of NEON fp)
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;
215 /// CPUString - String name of used CPU.
216 std::string CPUString;
218 /// IsLittle - The target is Little Endian
221 /// TargetTriple - What processor and OS we're targeting.
224 /// SchedModel - Processor specific instruction costs.
225 const MCSchedModel *SchedModel;
227 /// Selected instruction itineraries (one entry per itinerary class.)
228 InstrItineraryData InstrItins;
230 /// Options passed via command line that could influence the target
231 const TargetOptions &Options;
237 ARM_ABI_AAPCS // ARM EABI
240 /// This constructor initializes the data members to match that
241 /// of the specified triple.
243 ARMSubtarget(const std::string &TT, const std::string &CPU,
244 const std::string &FS, TargetMachine &TM, bool IsLittle,
245 const TargetOptions &Options);
247 /// getMaxInlineSizeThreshold - Returns the maximum memset / memcpy size
248 /// that still makes it profitable to inline the call.
249 unsigned getMaxInlineSizeThreshold() const {
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);
256 /// \brief Reset the features for the ARM target.
257 void resetSubtargetFeatures(const MachineFunction *MF) override;
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);
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();
275 ARMSelectionDAGInfo TSInfo;
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;
283 void initializeEnvironment();
284 void resetSubtargetFeatures(StringRef CPU, StringRef FS);
286 void computeIssueWidth();
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; }
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; }
308 bool hasARMOps() const { return !NoARM; }
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; }
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());
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; }
344 bool hasFP16() const { return HasFP16; }
345 bool hasD16() const { return HasD16; }
347 const Triple &getTargetTriple() const { return TargetTriple; }
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(); }
356 bool isTargetCOFF() const { return TargetTriple.isOSBinFormatCOFF(); }
357 bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
358 bool isTargetMachO() const { return TargetTriple.isOSBinFormatMachO(); }
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();
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();
384 bool isTargetHardFloat() const {
385 // FIXME: this is invalid for WindowsCE
386 return TargetTriple.getEnvironment() == Triple::GNUEABIHF ||
387 TargetTriple.getEnvironment() == Triple::EABIHF ||
390 bool isTargetAndroid() const {
391 return TargetTriple.getEnvironment() == Triple::Android;
394 bool isAPCS_ABI() const {
395 assert(TargetABI != ARM_ABI_UNKNOWN);
396 return TargetABI == ARM_ABI_APCS;
398 bool isAAPCS_ABI() const {
399 assert(TargetABI != ARM_ABI_UNKNOWN);
400 return TargetABI == ARM_ABI_AAPCS;
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; }
411 bool isR9Reserved() const { return IsR9Reserved; }
413 bool useMovt(const MachineFunction &MF) const;
415 bool supportsTailCall() const { return SupportsTailCall; }
417 bool allowsUnalignedMem() const { return AllowsUnalignedMem; }
419 bool restrictIT() const { return RestrictIT; }
421 const std::string & getCPUString() const { return CPUString; }
423 bool isLittle() const { return IsLittle; }
425 unsigned getMispredictionPenalty() const;
427 /// This function returns true if the target has sincos() routine in its
428 /// compiler runtime or math libraries.
429 bool hasSinCos() const;
431 /// True for some subtargets at > -O0.
432 bool enablePostMachineScheduler() const;
434 /// enablePostRAScheduler - True at 'More' optimization.
435 bool enablePostRAScheduler(CodeGenOpt::Level OptLevel,
436 TargetSubtargetInfo::AntiDepBreakMode& Mode,
437 RegClassVector& CriticalPathRCs) const override;
439 // enableAtomicExpandLoadLinked - True if we need to expand our atomics.
440 bool enableAtomicExpandLoadLinked() const override;
442 /// getInstrItins - Return the instruction itineraies based on subtarget
444 const InstrItineraryData &getInstrItineraryData() const { return InstrItins; }
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; }
451 /// GVIsIndirectSymbol - true if the GV will be accessed via an indirect
453 bool GVIsIndirectSymbol(const GlobalValue *GV, Reloc::Model RelocM) const;
455 /// \brief SrcRC and DstRC will be morphed into NewRC if this returns true
456 bool shouldCoalesce(MachineInstr *MI,
457 const TargetRegisterClass *SrcRC,
459 const TargetRegisterClass *DstRC,
461 const TargetRegisterClass *NewRC) const override;
463 } // End llvm namespace
465 #endif // ARMSUBTARGET_H