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
17 #include "MCTargetDesc/ARMMCTargetDesc.h"
18 #include "llvm/ADT/Triple.h"
19 #include "llvm/MC/MCInstrItineraries.h"
20 #include "llvm/Target/TargetSubtargetInfo.h"
23 #define GET_SUBTARGETINFO_HEADER
24 #include "ARMGenSubtargetInfo.inc"
31 class ARMSubtarget : public ARMGenSubtargetInfo {
33 enum ARMProcFamilyEnum {
34 Others, CortexA5, CortexA8, CortexA9, CortexA15, CortexR5, Swift
37 /// ARMProcFamily - ARM processor family: Cortex-A8, Cortex-A9, and others.
38 ARMProcFamilyEnum ARMProcFamily;
40 /// HasV4TOps, HasV5TOps, HasV5TEOps, HasV6Ops, HasV6T2Ops, HasV7Ops -
41 /// Specify whether target support specific ARM ISA variants.
49 /// HasVFPv2, HasVFPv3, HasVFPv4, HasNEON - Specify what
50 /// floating point ISAs are supported.
56 /// UseNEONForSinglePrecisionFP - if the NEONFP attribute has been
57 /// specified. Use the method useNEONForSinglePrecisionFP() to
58 /// determine if NEON should actually be used.
59 bool UseNEONForSinglePrecisionFP;
61 /// UseMulOps - True if non-microcoded fused integer multiply-add and
62 /// multiply-subtract instructions should be used.
65 /// SlowFPVMLx - If the VFP2 / NEON instructions are available, indicates
66 /// whether the FP VML[AS] instructions are slow (if so, don't use them).
69 /// HasVMLxForwarding - If true, NEON has special multiplier accumulator
70 /// forwarding to allow mul + mla being issued back to back.
71 bool HasVMLxForwarding;
73 /// SlowFPBrcc - True if floating point compare + branch is slow.
76 /// InThumbMode - True if compiling for Thumb, false for ARM.
79 /// HasThumb2 - True if Thumb2 instructions are supported.
82 /// IsMClass - True if the subtarget belongs to the 'M' profile of CPUs -
83 /// v6m, v7m for example.
86 /// NoARM - True if subtarget does not support ARM mode execution.
89 /// PostRAScheduler - True if using post-register-allocation scheduler.
92 /// IsR9Reserved - True if R9 is a not available as general purpose register.
95 /// UseMovt - True if MOVT / MOVW pairs are used for materialization of 32-bit
96 /// imms (including global addresses).
99 /// SupportsTailCall - True if the OS supports tail call. The dynamic linker
100 /// must be able to synthesize call stubs for interworking between ARM and
102 bool SupportsTailCall;
104 /// HasFP16 - True if subtarget supports half-precision FP (We support VFP+HF
108 /// HasD16 - True if subtarget is limited to 16 double precision
109 /// FP registers for VFPv3.
112 /// HasHardwareDivide - True if subtarget supports [su]div
113 bool HasHardwareDivide;
115 /// HasHardwareDivideInARM - True if subtarget supports [su]div in ARM mode
116 bool HasHardwareDivideInARM;
118 /// HasT2ExtractPack - True if subtarget supports thumb2 extract/pack
120 bool HasT2ExtractPack;
122 /// HasDataBarrier - True if the subtarget supports DMB / DSB data barrier
126 /// Pref32BitThumb - If true, codegen would prefer 32-bit Thumb instructions
127 /// over 16-bit ones.
130 /// AvoidCPSRPartialUpdate - If true, codegen would avoid using instructions
131 /// that partially update CPSR and add false dependency on the previous
132 /// CPSR setting instruction.
133 bool AvoidCPSRPartialUpdate;
135 /// AvoidMOVsShifterOperand - If true, codegen should avoid using flag setting
136 /// movs with shifter operand (i.e. asr, lsl, lsr).
137 bool AvoidMOVsShifterOperand;
139 /// HasRAS - Some processors perform return stack prediction. CodeGen should
140 /// avoid issue "normal" call instructions to callees which do not return.
143 /// HasMPExtension - True if the subtarget supports Multiprocessing
144 /// extension (ARMv7 only).
147 /// FPOnlySP - If true, the floating point unit only supports single
151 /// HasTrustZone - if true, processor supports TrustZone security extensions
154 /// AllowsUnalignedMem - If true, the subtarget allows unaligned memory
155 /// accesses for some types. For details, see
156 /// ARMTargetLowering::allowsUnalignedMemoryAccesses().
157 bool AllowsUnalignedMem;
159 /// Thumb2DSP - If true, the subtarget supports the v7 DSP (saturating arith
160 /// and such) instructions in Thumb2 code.
163 /// NaCl TRAP instruction is generated instead of the regular TRAP.
166 /// Target machine allowed unsafe FP math (such as use of NEON fp)
169 /// stackAlignment - The minimum alignment known to hold of the stack frame on
170 /// entry to the function and which must be maintained by every function.
171 unsigned stackAlignment;
173 /// CPUString - String name of used CPU.
174 std::string CPUString;
176 /// TargetTriple - What processor and OS we're targeting.
179 /// SchedModel - Processor specific instruction costs.
180 const MCSchedModel *SchedModel;
182 /// Selected instruction itineraries (one entry per itinerary class.)
183 InstrItineraryData InstrItins;
185 /// Options passed via command line that could influence the target
186 const TargetOptions &Options;
195 ARM_ABI_AAPCS // ARM EABI
198 /// This constructor initializes the data members to match that
199 /// of the specified triple.
201 ARMSubtarget(const std::string &TT, const std::string &CPU,
202 const std::string &FS, const TargetOptions &Options);
204 /// getMaxInlineSizeThreshold - Returns the maximum memset / memcpy size
205 /// that still makes it profitable to inline the call.
206 unsigned getMaxInlineSizeThreshold() const {
207 // FIXME: For now, we don't lower memcpy's to loads / stores for Thumb1.
208 // Change this once Thumb1 ldmia / stmia support is added.
209 return isThumb1Only() ? 0 : 64;
211 /// ParseSubtargetFeatures - Parses features string setting specified
212 /// subtarget options. Definition of function is auto generated by tblgen.
213 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
215 /// \brief Reset the features for the ARM target.
216 virtual void resetSubtargetFeatures(const MachineFunction *MF);
218 void initializeEnvironment();
219 void resetSubtargetFeatures(StringRef CPU, StringRef FS);
221 void computeIssueWidth();
223 bool hasV4TOps() const { return HasV4TOps; }
224 bool hasV5TOps() const { return HasV5TOps; }
225 bool hasV5TEOps() const { return HasV5TEOps; }
226 bool hasV6Ops() const { return HasV6Ops; }
227 bool hasV6T2Ops() const { return HasV6T2Ops; }
228 bool hasV7Ops() const { return HasV7Ops; }
230 bool isCortexA5() const { return ARMProcFamily == CortexA5; }
231 bool isCortexA8() const { return ARMProcFamily == CortexA8; }
232 bool isCortexA9() const { return ARMProcFamily == CortexA9; }
233 bool isCortexA15() const { return ARMProcFamily == CortexA15; }
234 bool isSwift() const { return ARMProcFamily == Swift; }
235 bool isCortexM3() const { return CPUString == "cortex-m3"; }
236 bool isLikeA9() const { return isCortexA9() || isCortexA15(); }
237 bool isCortexR5() const { return ARMProcFamily == CortexR5; }
239 bool hasARMOps() const { return !NoARM; }
241 bool hasVFP2() const { return HasVFPv2; }
242 bool hasVFP3() const { return HasVFPv3; }
243 bool hasVFP4() const { return HasVFPv4; }
244 bool hasNEON() const { return HasNEON; }
245 bool useNEONForSinglePrecisionFP() const {
246 return hasNEON() && UseNEONForSinglePrecisionFP; }
248 bool hasDivide() const { return HasHardwareDivide; }
249 bool hasDivideInARMMode() const { return HasHardwareDivideInARM; }
250 bool hasT2ExtractPack() const { return HasT2ExtractPack; }
251 bool hasDataBarrier() const { return HasDataBarrier; }
252 bool useMulOps() const { return UseMulOps; }
253 bool useFPVMLx() const { return !SlowFPVMLx; }
254 bool hasVMLxForwarding() const { return HasVMLxForwarding; }
255 bool isFPBrccSlow() const { return SlowFPBrcc; }
256 bool isFPOnlySP() const { return FPOnlySP; }
257 bool hasTrustZone() const { return HasTrustZone; }
258 bool prefers32BitThumb() const { return Pref32BitThumb; }
259 bool avoidCPSRPartialUpdate() const { return AvoidCPSRPartialUpdate; }
260 bool avoidMOVsShifterOperand() const { return AvoidMOVsShifterOperand; }
261 bool hasRAS() const { return HasRAS; }
262 bool hasMPExtension() const { return HasMPExtension; }
263 bool hasThumb2DSP() const { return Thumb2DSP; }
264 bool useNaClTrap() const { return UseNaClTrap; }
266 bool hasFP16() const { return HasFP16; }
267 bool hasD16() const { return HasD16; }
269 const Triple &getTargetTriple() const { return TargetTriple; }
271 bool isTargetIOS() const { return TargetTriple.getOS() == Triple::IOS; }
272 bool isTargetDarwin() const { return TargetTriple.isOSDarwin(); }
273 bool isTargetNaCl() const {
274 return TargetTriple.getOS() == Triple::NaCl;
276 bool isTargetELF() const { return !isTargetDarwin(); }
278 bool isAPCS_ABI() const { return TargetABI == ARM_ABI_APCS; }
279 bool isAAPCS_ABI() const { return TargetABI == ARM_ABI_AAPCS; }
281 bool isThumb() const { return InThumbMode; }
282 bool isThumb1Only() const { return InThumbMode && !HasThumb2; }
283 bool isThumb2() const { return InThumbMode && HasThumb2; }
284 bool hasThumb2() const { return HasThumb2; }
285 bool isMClass() const { return IsMClass; }
286 bool isARClass() const { return !IsMClass; }
288 bool isR9Reserved() const { return IsR9Reserved; }
290 bool useMovt() const { return UseMovt && hasV6T2Ops(); }
291 bool supportsTailCall() const { return SupportsTailCall; }
293 bool allowsUnalignedMem() const { return AllowsUnalignedMem; }
295 const std::string & getCPUString() const { return CPUString; }
297 unsigned getMispredictionPenalty() const;
299 /// enablePostRAScheduler - True at 'More' optimization.
300 bool enablePostRAScheduler(CodeGenOpt::Level OptLevel,
301 TargetSubtargetInfo::AntiDepBreakMode& Mode,
302 RegClassVector& CriticalPathRCs) const;
304 /// getInstrItins - Return the instruction itineraies based on subtarget
306 const InstrItineraryData &getInstrItineraryData() const { return InstrItins; }
308 /// getStackAlignment - Returns the minimum alignment known to hold of the
309 /// stack frame on entry to the function and which must be maintained by every
310 /// function for this subtarget.
311 unsigned getStackAlignment() const { return stackAlignment; }
313 /// GVIsIndirectSymbol - true if the GV will be accessed via an indirect
315 bool GVIsIndirectSymbol(const GlobalValue *GV, Reloc::Model RelocM) const;
317 } // End llvm namespace
319 #endif // ARMSUBTARGET_H