LLVM API Documentation
00001 //===-- ARMSubtarget.h - Define Subtarget for the ARM ----------*- C++ -*--===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file declares the ARM specific subclass of TargetSubtargetInfo. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef ARMSUBTARGET_H 00015 #define ARMSUBTARGET_H 00016 00017 #include "MCTargetDesc/ARMMCTargetDesc.h" 00018 #include "llvm/ADT/Triple.h" 00019 #include "llvm/MC/MCInstrItineraries.h" 00020 #include "llvm/Target/TargetSubtargetInfo.h" 00021 #include <string> 00022 00023 #define GET_SUBTARGETINFO_HEADER 00024 #include "ARMGenSubtargetInfo.inc" 00025 00026 namespace llvm { 00027 class GlobalValue; 00028 class StringRef; 00029 class TargetOptions; 00030 00031 class ARMSubtarget : public ARMGenSubtargetInfo { 00032 protected: 00033 enum ARMProcFamilyEnum { 00034 Others, CortexA5, CortexA8, CortexA9, CortexA15, CortexR5, Swift 00035 }; 00036 00037 /// ARMProcFamily - ARM processor family: Cortex-A8, Cortex-A9, and others. 00038 ARMProcFamilyEnum ARMProcFamily; 00039 00040 /// HasV4TOps, HasV5TOps, HasV5TEOps, HasV6Ops, HasV6T2Ops, HasV7Ops - 00041 /// Specify whether target support specific ARM ISA variants. 00042 bool HasV4TOps; 00043 bool HasV5TOps; 00044 bool HasV5TEOps; 00045 bool HasV6Ops; 00046 bool HasV6T2Ops; 00047 bool HasV7Ops; 00048 00049 /// HasVFPv2, HasVFPv3, HasVFPv4, HasNEON - Specify what 00050 /// floating point ISAs are supported. 00051 bool HasVFPv2; 00052 bool HasVFPv3; 00053 bool HasVFPv4; 00054 bool HasNEON; 00055 00056 /// UseNEONForSinglePrecisionFP - if the NEONFP attribute has been 00057 /// specified. Use the method useNEONForSinglePrecisionFP() to 00058 /// determine if NEON should actually be used. 00059 bool UseNEONForSinglePrecisionFP; 00060 00061 /// UseMulOps - True if non-microcoded fused integer multiply-add and 00062 /// multiply-subtract instructions should be used. 00063 bool UseMulOps; 00064 00065 /// SlowFPVMLx - If the VFP2 / NEON instructions are available, indicates 00066 /// whether the FP VML[AS] instructions are slow (if so, don't use them). 00067 bool SlowFPVMLx; 00068 00069 /// HasVMLxForwarding - If true, NEON has special multiplier accumulator 00070 /// forwarding to allow mul + mla being issued back to back. 00071 bool HasVMLxForwarding; 00072 00073 /// SlowFPBrcc - True if floating point compare + branch is slow. 00074 bool SlowFPBrcc; 00075 00076 /// InThumbMode - True if compiling for Thumb, false for ARM. 00077 bool InThumbMode; 00078 00079 /// HasThumb2 - True if Thumb2 instructions are supported. 00080 bool HasThumb2; 00081 00082 /// IsMClass - True if the subtarget belongs to the 'M' profile of CPUs - 00083 /// v6m, v7m for example. 00084 bool IsMClass; 00085 00086 /// NoARM - True if subtarget does not support ARM mode execution. 00087 bool NoARM; 00088 00089 /// PostRAScheduler - True if using post-register-allocation scheduler. 00090 bool PostRAScheduler; 00091 00092 /// IsR9Reserved - True if R9 is a not available as general purpose register. 00093 bool IsR9Reserved; 00094 00095 /// UseMovt - True if MOVT / MOVW pairs are used for materialization of 32-bit 00096 /// imms (including global addresses). 00097 bool UseMovt; 00098 00099 /// SupportsTailCall - True if the OS supports tail call. The dynamic linker 00100 /// must be able to synthesize call stubs for interworking between ARM and 00101 /// Thumb. 00102 bool SupportsTailCall; 00103 00104 /// HasFP16 - True if subtarget supports half-precision FP (We support VFP+HF 00105 /// only so far) 00106 bool HasFP16; 00107 00108 /// HasD16 - True if subtarget is limited to 16 double precision 00109 /// FP registers for VFPv3. 00110 bool HasD16; 00111 00112 /// HasHardwareDivide - True if subtarget supports [su]div 00113 bool HasHardwareDivide; 00114 00115 /// HasHardwareDivideInARM - True if subtarget supports [su]div in ARM mode 00116 bool HasHardwareDivideInARM; 00117 00118 /// HasT2ExtractPack - True if subtarget supports thumb2 extract/pack 00119 /// instructions. 00120 bool HasT2ExtractPack; 00121 00122 /// HasDataBarrier - True if the subtarget supports DMB / DSB data barrier 00123 /// instructions. 00124 bool HasDataBarrier; 00125 00126 /// Pref32BitThumb - If true, codegen would prefer 32-bit Thumb instructions 00127 /// over 16-bit ones. 00128 bool Pref32BitThumb; 00129 00130 /// AvoidCPSRPartialUpdate - If true, codegen would avoid using instructions 00131 /// that partially update CPSR and add false dependency on the previous 00132 /// CPSR setting instruction. 00133 bool AvoidCPSRPartialUpdate; 00134 00135 /// AvoidMOVsShifterOperand - If true, codegen should avoid using flag setting 00136 /// movs with shifter operand (i.e. asr, lsl, lsr). 00137 bool AvoidMOVsShifterOperand; 00138 00139 /// HasRAS - Some processors perform return stack prediction. CodeGen should 00140 /// avoid issue "normal" call instructions to callees which do not return. 00141 bool HasRAS; 00142 00143 /// HasMPExtension - True if the subtarget supports Multiprocessing 00144 /// extension (ARMv7 only). 00145 bool HasMPExtension; 00146 00147 /// FPOnlySP - If true, the floating point unit only supports single 00148 /// precision. 00149 bool FPOnlySP; 00150 00151 /// HasTrustZone - if true, processor supports TrustZone security extensions 00152 bool HasTrustZone; 00153 00154 /// AllowsUnalignedMem - If true, the subtarget allows unaligned memory 00155 /// accesses for some types. For details, see 00156 /// ARMTargetLowering::allowsUnalignedMemoryAccesses(). 00157 bool AllowsUnalignedMem; 00158 00159 /// Thumb2DSP - If true, the subtarget supports the v7 DSP (saturating arith 00160 /// and such) instructions in Thumb2 code. 00161 bool Thumb2DSP; 00162 00163 /// NaCl TRAP instruction is generated instead of the regular TRAP. 00164 bool UseNaClTrap; 00165 00166 /// Target machine allowed unsafe FP math (such as use of NEON fp) 00167 bool UnsafeFPMath; 00168 00169 /// stackAlignment - The minimum alignment known to hold of the stack frame on 00170 /// entry to the function and which must be maintained by every function. 00171 unsigned stackAlignment; 00172 00173 /// CPUString - String name of used CPU. 00174 std::string CPUString; 00175 00176 /// TargetTriple - What processor and OS we're targeting. 00177 Triple TargetTriple; 00178 00179 /// SchedModel - Processor specific instruction costs. 00180 const MCSchedModel *SchedModel; 00181 00182 /// Selected instruction itineraries (one entry per itinerary class.) 00183 InstrItineraryData InstrItins; 00184 00185 /// Options passed via command line that could influence the target 00186 const TargetOptions &Options; 00187 00188 public: 00189 enum { 00190 isELF, isDarwin 00191 } TargetType; 00192 00193 enum { 00194 ARM_ABI_APCS, 00195 ARM_ABI_AAPCS // ARM EABI 00196 } TargetABI; 00197 00198 /// This constructor initializes the data members to match that 00199 /// of the specified triple. 00200 /// 00201 ARMSubtarget(const std::string &TT, const std::string &CPU, 00202 const std::string &FS, const TargetOptions &Options); 00203 00204 /// getMaxInlineSizeThreshold - Returns the maximum memset / memcpy size 00205 /// that still makes it profitable to inline the call. 00206 unsigned getMaxInlineSizeThreshold() const { 00207 // FIXME: For now, we don't lower memcpy's to loads / stores for Thumb1. 00208 // Change this once Thumb1 ldmia / stmia support is added. 00209 return isThumb1Only() ? 0 : 64; 00210 } 00211 /// ParseSubtargetFeatures - Parses features string setting specified 00212 /// subtarget options. Definition of function is auto generated by tblgen. 00213 void ParseSubtargetFeatures(StringRef CPU, StringRef FS); 00214 00215 /// \brief Reset the features for the ARM target. 00216 virtual void resetSubtargetFeatures(const MachineFunction *MF); 00217 private: 00218 void initializeEnvironment(); 00219 void resetSubtargetFeatures(StringRef CPU, StringRef FS); 00220 public: 00221 void computeIssueWidth(); 00222 00223 bool hasV4TOps() const { return HasV4TOps; } 00224 bool hasV5TOps() const { return HasV5TOps; } 00225 bool hasV5TEOps() const { return HasV5TEOps; } 00226 bool hasV6Ops() const { return HasV6Ops; } 00227 bool hasV6T2Ops() const { return HasV6T2Ops; } 00228 bool hasV7Ops() const { return HasV7Ops; } 00229 00230 bool isCortexA5() const { return ARMProcFamily == CortexA5; } 00231 bool isCortexA8() const { return ARMProcFamily == CortexA8; } 00232 bool isCortexA9() const { return ARMProcFamily == CortexA9; } 00233 bool isCortexA15() const { return ARMProcFamily == CortexA15; } 00234 bool isSwift() const { return ARMProcFamily == Swift; } 00235 bool isCortexM3() const { return CPUString == "cortex-m3"; } 00236 bool isLikeA9() const { return isCortexA9() || isCortexA15(); } 00237 bool isCortexR5() const { return ARMProcFamily == CortexR5; } 00238 00239 bool hasARMOps() const { return !NoARM; } 00240 00241 bool hasVFP2() const { return HasVFPv2; } 00242 bool hasVFP3() const { return HasVFPv3; } 00243 bool hasVFP4() const { return HasVFPv4; } 00244 bool hasNEON() const { return HasNEON; } 00245 bool useNEONForSinglePrecisionFP() const { 00246 return hasNEON() && UseNEONForSinglePrecisionFP; } 00247 00248 bool hasDivide() const { return HasHardwareDivide; } 00249 bool hasDivideInARMMode() const { return HasHardwareDivideInARM; } 00250 bool hasT2ExtractPack() const { return HasT2ExtractPack; } 00251 bool hasDataBarrier() const { return HasDataBarrier; } 00252 bool useMulOps() const { return UseMulOps; } 00253 bool useFPVMLx() const { return !SlowFPVMLx; } 00254 bool hasVMLxForwarding() const { return HasVMLxForwarding; } 00255 bool isFPBrccSlow() const { return SlowFPBrcc; } 00256 bool isFPOnlySP() const { return FPOnlySP; } 00257 bool hasTrustZone() const { return HasTrustZone; } 00258 bool prefers32BitThumb() const { return Pref32BitThumb; } 00259 bool avoidCPSRPartialUpdate() const { return AvoidCPSRPartialUpdate; } 00260 bool avoidMOVsShifterOperand() const { return AvoidMOVsShifterOperand; } 00261 bool hasRAS() const { return HasRAS; } 00262 bool hasMPExtension() const { return HasMPExtension; } 00263 bool hasThumb2DSP() const { return Thumb2DSP; } 00264 bool useNaClTrap() const { return UseNaClTrap; } 00265 00266 bool hasFP16() const { return HasFP16; } 00267 bool hasD16() const { return HasD16; } 00268 00269 const Triple &getTargetTriple() const { return TargetTriple; } 00270 00271 bool isTargetIOS() const { return TargetTriple.getOS() == Triple::IOS; } 00272 bool isTargetDarwin() const { return TargetTriple.isOSDarwin(); } 00273 bool isTargetNaCl() const { return TargetTriple.getOS() == Triple::NaCl; } 00274 bool isTargetLinux() const { return TargetTriple.getOS() == Triple::Linux; } 00275 bool isTargetELF() const { return !isTargetDarwin(); } 00276 00277 bool isAPCS_ABI() const { return TargetABI == ARM_ABI_APCS; } 00278 bool isAAPCS_ABI() const { return TargetABI == ARM_ABI_AAPCS; } 00279 00280 bool isThumb() const { return InThumbMode; } 00281 bool isThumb1Only() const { return InThumbMode && !HasThumb2; } 00282 bool isThumb2() const { return InThumbMode && HasThumb2; } 00283 bool hasThumb2() const { return HasThumb2; } 00284 bool isMClass() const { return IsMClass; } 00285 bool isARClass() const { return !IsMClass; } 00286 00287 bool isR9Reserved() const { return IsR9Reserved; } 00288 00289 bool useMovt() const { return UseMovt && hasV6T2Ops(); } 00290 bool supportsTailCall() const { return SupportsTailCall; } 00291 00292 bool allowsUnalignedMem() const { return AllowsUnalignedMem; } 00293 00294 const std::string & getCPUString() const { return CPUString; } 00295 00296 unsigned getMispredictionPenalty() const; 00297 00298 /// enablePostRAScheduler - True at 'More' optimization. 00299 bool enablePostRAScheduler(CodeGenOpt::Level OptLevel, 00300 TargetSubtargetInfo::AntiDepBreakMode& Mode, 00301 RegClassVector& CriticalPathRCs) const; 00302 00303 /// getInstrItins - Return the instruction itineraies based on subtarget 00304 /// selection. 00305 const InstrItineraryData &getInstrItineraryData() const { return InstrItins; } 00306 00307 /// getStackAlignment - Returns the minimum alignment known to hold of the 00308 /// stack frame on entry to the function and which must be maintained by every 00309 /// function for this subtarget. 00310 unsigned getStackAlignment() const { return stackAlignment; } 00311 00312 /// GVIsIndirectSymbol - true if the GV will be accessed via an indirect 00313 /// symbol. 00314 bool GVIsIndirectSymbol(const GlobalValue *GV, Reloc::Model RelocM) const; 00315 }; 00316 } // End llvm namespace 00317 00318 #endif // ARMSUBTARGET_H