Jia Liu | b22310f | 2012-02-18 12:03:15 +0000 | [diff] [blame] | 1 | //===-- ARMSubtarget.cpp - ARM Subtarget Information ----------------------===// |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Evan Cheng | 0d639a2 | 2011-07-01 21:01:15 +0000 | [diff] [blame] | 10 | // This file implements the ARM specific subclass of TargetSubtargetInfo. |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "ARMSubtarget.h" |
Andrew Trick | ab722bd | 2012-09-18 03:18:56 +0000 | [diff] [blame] | 15 | #include "ARMBaseInstrInfo.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 16 | #include "ARMBaseRegisterInfo.h" |
Bill Wendling | 5a92eec | 2013-02-15 22:41:25 +0000 | [diff] [blame] | 17 | #include "llvm/IR/Attributes.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 18 | #include "llvm/IR/GlobalValue.h" |
Bill Wendling | 5a92eec | 2013-02-15 22:41:25 +0000 | [diff] [blame] | 19 | #include "llvm/IR/Function.h" |
Bob Wilson | 4582530 | 2009-06-22 21:01:46 +0000 | [diff] [blame] | 20 | #include "llvm/Support/CommandLine.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetInstrInfo.h" |
Renato Golin | b4dd6c5 | 2013-03-21 18:47:47 +0000 | [diff] [blame] | 22 | #include "llvm/Target/TargetOptions.h" |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 23 | |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 24 | #define GET_SUBTARGETINFO_TARGET_DESC |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 25 | #define GET_SUBTARGETINFO_CTOR |
Evan Cheng | c9c090d | 2011-07-01 22:36:09 +0000 | [diff] [blame] | 26 | #include "ARMGenSubtargetInfo.inc" |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 27 | |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 28 | using namespace llvm; |
| 29 | |
Bob Wilson | 4582530 | 2009-06-22 21:01:46 +0000 | [diff] [blame] | 30 | static cl::opt<bool> |
| 31 | ReserveR9("arm-reserve-r9", cl::Hidden, |
| 32 | cl::desc("Reserve R9, making it unavailable as GPR")); |
| 33 | |
Anton Korobeynikov | 2522908 | 2009-11-24 00:44:37 +0000 | [diff] [blame] | 34 | static cl::opt<bool> |
Evan Cheng | 2f2435d | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 35 | DarwinUseMOVT("arm-darwin-use-movt", cl::init(true), cl::Hidden); |
Anton Korobeynikov | 2522908 | 2009-11-24 00:44:37 +0000 | [diff] [blame] | 36 | |
Bob Wilson | 3dc9732 | 2010-09-28 04:09:35 +0000 | [diff] [blame] | 37 | static cl::opt<bool> |
Bob Wilson | e8a549c | 2012-09-29 21:43:49 +0000 | [diff] [blame] | 38 | UseFusedMulOps("arm-use-mulops", |
| 39 | cl::init(true), cl::Hidden); |
| 40 | |
| 41 | static cl::opt<bool> |
Bob Wilson | 3dc9732 | 2010-09-28 04:09:35 +0000 | [diff] [blame] | 42 | StrictAlign("arm-strict-align", cl::Hidden, |
| 43 | cl::desc("Disallow all unaligned memory accesses")); |
| 44 | |
Evan Cheng | fe6e405 | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 45 | ARMSubtarget::ARMSubtarget(const std::string &TT, const std::string &CPU, |
Renato Golin | b4dd6c5 | 2013-03-21 18:47:47 +0000 | [diff] [blame] | 46 | const std::string &FS, const TargetOptions &Options) |
Evan Cheng | 1a72add6 | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 47 | : ARMGenSubtargetInfo(TT, CPU, FS) |
Evan Cheng | bf40707 | 2010-09-10 01:29:16 +0000 | [diff] [blame] | 48 | , ARMProcFamily(Others) |
Lauro Ramos Venancio | 048e16ff | 2007-02-13 19:52:28 +0000 | [diff] [blame] | 49 | , stackAlignment(4) |
Evan Cheng | fe6e405 | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 50 | , CPUString(CPU) |
Evan Cheng | e45d685 | 2011-01-11 21:46:47 +0000 | [diff] [blame] | 51 | , TargetTriple(TT) |
Renato Golin | b4dd6c5 | 2013-03-21 18:47:47 +0000 | [diff] [blame] | 52 | , Options(Options) |
Lauro Ramos Venancio | 048e16ff | 2007-02-13 19:52:28 +0000 | [diff] [blame] | 53 | , TargetABI(ARM_ABI_APCS) { |
Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 54 | initializeEnvironment(); |
Bill Wendling | 5a92eec | 2013-02-15 22:41:25 +0000 | [diff] [blame] | 55 | resetSubtargetFeatures(CPU, FS); |
| 56 | } |
| 57 | |
Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 58 | void ARMSubtarget::initializeEnvironment() { |
| 59 | HasV4TOps = false; |
| 60 | HasV5TOps = false; |
| 61 | HasV5TEOps = false; |
| 62 | HasV6Ops = false; |
| 63 | HasV6T2Ops = false; |
| 64 | HasV7Ops = false; |
| 65 | HasVFPv2 = false; |
| 66 | HasVFPv3 = false; |
| 67 | HasVFPv4 = false; |
| 68 | HasNEON = false; |
| 69 | UseNEONForSinglePrecisionFP = false; |
| 70 | UseMulOps = UseFusedMulOps; |
| 71 | SlowFPVMLx = false; |
| 72 | HasVMLxForwarding = false; |
| 73 | SlowFPBrcc = false; |
| 74 | InThumbMode = false; |
| 75 | HasThumb2 = false; |
| 76 | IsMClass = false; |
| 77 | NoARM = false; |
| 78 | PostRAScheduler = false; |
| 79 | IsR9Reserved = ReserveR9; |
| 80 | UseMovt = false; |
| 81 | SupportsTailCall = false; |
| 82 | HasFP16 = false; |
| 83 | HasD16 = false; |
| 84 | HasHardwareDivide = false; |
| 85 | HasHardwareDivideInARM = false; |
| 86 | HasT2ExtractPack = false; |
| 87 | HasDataBarrier = false; |
| 88 | Pref32BitThumb = false; |
| 89 | AvoidCPSRPartialUpdate = false; |
| 90 | AvoidMOVsShifterOperand = false; |
| 91 | HasRAS = false; |
| 92 | HasMPExtension = false; |
| 93 | FPOnlySP = false; |
Tim Northover | c604765 | 2013-04-10 12:08:35 +0000 | [diff] [blame^] | 94 | HasTrustZone = false; |
Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 95 | AllowsUnalignedMem = false; |
| 96 | Thumb2DSP = false; |
| 97 | UseNaClTrap = false; |
Renato Golin | b4dd6c5 | 2013-03-21 18:47:47 +0000 | [diff] [blame] | 98 | UnsafeFPMath = false; |
Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Bill Wendling | 5a92eec | 2013-02-15 22:41:25 +0000 | [diff] [blame] | 101 | void ARMSubtarget::resetSubtargetFeatures(const MachineFunction *MF) { |
| 102 | AttributeSet FnAttrs = MF->getFunction()->getAttributes(); |
| 103 | Attribute CPUAttr = FnAttrs.getAttribute(AttributeSet::FunctionIndex, |
| 104 | "target-cpu"); |
| 105 | Attribute FSAttr = FnAttrs.getAttribute(AttributeSet::FunctionIndex, |
| 106 | "target-features"); |
| 107 | std::string CPU = |
| 108 | !CPUAttr.hasAttribute(Attribute::None) ?CPUAttr.getValueAsString() : ""; |
| 109 | std::string FS = |
| 110 | !FSAttr.hasAttribute(Attribute::None) ? FSAttr.getValueAsString() : ""; |
Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 111 | if (!FS.empty()) { |
| 112 | initializeEnvironment(); |
Bill Wendling | 5a92eec | 2013-02-15 22:41:25 +0000 | [diff] [blame] | 113 | resetSubtargetFeatures(CPU, FS); |
Bill Wendling | 61375d8 | 2013-02-16 01:36:26 +0000 | [diff] [blame] | 114 | } |
Bill Wendling | 5a92eec | 2013-02-15 22:41:25 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | void ARMSubtarget::resetSubtargetFeatures(StringRef CPU, StringRef FS) { |
Evan Cheng | fe6e405 | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 118 | if (CPUString.empty()) |
| 119 | CPUString = "generic"; |
Evan Cheng | ec415ef | 2009-03-08 04:02:49 +0000 | [diff] [blame] | 120 | |
Evan Cheng | 0b33a32 | 2011-06-30 02:12:44 +0000 | [diff] [blame] | 121 | // Insert the architecture feature derived from the target triple into the |
| 122 | // feature string. This is important for setting features that are implied |
| 123 | // based on the architecture version. |
Bill Wendling | 5a92eec | 2013-02-15 22:41:25 +0000 | [diff] [blame] | 124 | std::string ArchFS = ARM_MC::ParseARMTriple(TargetTriple.getTriple(), |
| 125 | CPUString); |
Evan Cheng | 2bd6536 | 2011-07-07 00:08:19 +0000 | [diff] [blame] | 126 | if (!FS.empty()) { |
| 127 | if (!ArchFS.empty()) |
Bill Wendling | 5a92eec | 2013-02-15 22:41:25 +0000 | [diff] [blame] | 128 | ArchFS = ArchFS + "," + FS.str(); |
Evan Cheng | 2bd6536 | 2011-07-07 00:08:19 +0000 | [diff] [blame] | 129 | else |
| 130 | ArchFS = FS; |
| 131 | } |
Evan Cheng | 1a72add6 | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 132 | ParseSubtargetFeatures(CPUString, ArchFS); |
Evan Cheng | 2bd6536 | 2011-07-07 00:08:19 +0000 | [diff] [blame] | 133 | |
| 134 | // Thumb2 implies at least V6T2. FIXME: Fix tests to explicitly specify a |
| 135 | // ARM version or CPU and then remove this. |
Evan Cheng | 8b2bda0 | 2011-07-07 03:55:05 +0000 | [diff] [blame] | 136 | if (!HasV6T2Ops && hasThumb2()) |
| 137 | HasV4TOps = HasV5TOps = HasV5TEOps = HasV6Ops = HasV6T2Ops = true; |
Bob Wilson | d0046ca | 2010-11-09 22:50:47 +0000 | [diff] [blame] | 138 | |
Andrew Trick | 352abc1 | 2012-08-08 02:44:16 +0000 | [diff] [blame] | 139 | // Keep a pointer to static instruction cost data for the specified CPU. |
| 140 | SchedModel = getSchedModelForCPU(CPUString); |
| 141 | |
Evan Cheng | 54b68e3 | 2011-07-01 20:45:01 +0000 | [diff] [blame] | 142 | // Initialize scheduling itinerary for the specified CPU. |
| 143 | InstrItins = getInstrItineraryForCPU(CPUString); |
| 144 | |
Bill Wendling | 5a92eec | 2013-02-15 22:41:25 +0000 | [diff] [blame] | 145 | if ((TargetTriple.getTriple().find("eabi") != std::string::npos) || |
| 146 | (isTargetIOS() && isMClass())) |
Evan Cheng | 0460ae8 | 2012-02-21 20:46:00 +0000 | [diff] [blame] | 147 | // FIXME: We might want to separate AAPCS and EABI. Some systems, e.g. |
| 148 | // Darwin-EABI conforms to AACPS but not the rest of EABI. |
Evan Cheng | 1a72add6 | 2011-07-07 07:07:08 +0000 | [diff] [blame] | 149 | TargetABI = ARM_ABI_AAPCS; |
| 150 | |
Lauro Ramos Venancio | 048e16ff | 2007-02-13 19:52:28 +0000 | [diff] [blame] | 151 | if (isAAPCS_ABI()) |
| 152 | stackAlignment = 8; |
| 153 | |
Evan Cheng | 68132d8 | 2011-12-20 18:26:50 +0000 | [diff] [blame] | 154 | if (!isTargetIOS()) |
Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 155 | UseMovt = hasV6T2Ops(); |
| 156 | else { |
Evan Cheng | 8b2bda0 | 2011-07-07 03:55:05 +0000 | [diff] [blame] | 157 | IsR9Reserved = ReserveR9 | !HasV6Ops; |
Evan Cheng | 2f2435d | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 158 | UseMovt = DarwinUseMOVT && hasV6T2Ops(); |
Evan Cheng | 0460ae8 | 2012-02-21 20:46:00 +0000 | [diff] [blame] | 159 | SupportsTailCall = !getTargetTriple().isOSVersionLT(5, 0); |
Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 160 | } |
David Goodwin | 9a051a5 | 2009-10-01 21:46:35 +0000 | [diff] [blame] | 161 | |
Evan Cheng | 03da4db | 2009-10-16 06:11:08 +0000 | [diff] [blame] | 162 | if (!isThumb() || hasThumb2()) |
| 163 | PostRAScheduler = true; |
Bob Wilson | 3dc9732 | 2010-09-28 04:09:35 +0000 | [diff] [blame] | 164 | |
| 165 | // v6+ may or may not support unaligned mem access depending on the system |
| 166 | // configuration. |
| 167 | if (!StrictAlign && hasV6Ops() && isTargetDarwin()) |
| 168 | AllowsUnalignedMem = true; |
Renato Golin | b4dd6c5 | 2013-03-21 18:47:47 +0000 | [diff] [blame] | 169 | |
| 170 | // NEON f32 ops are non-IEEE 754 compliant. Darwin is ok with it by default. |
| 171 | uint64_t Bits = getFeatureBits(); |
| 172 | if ((Bits & ARM::ProcA5 || Bits & ARM::ProcA8) && // Where this matters |
| 173 | (Options.UnsafeFPMath || isTargetDarwin())) |
| 174 | UseNEONForSinglePrecisionFP = true; |
Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 175 | } |
Evan Cheng | 43b9ca6 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 176 | |
| 177 | /// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol. |
Evan Cheng | 1b38952 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 178 | bool |
Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 179 | ARMSubtarget::GVIsIndirectSymbol(const GlobalValue *GV, |
| 180 | Reloc::Model RelocM) const { |
Evan Cheng | 1b38952 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 181 | if (RelocM == Reloc::Static) |
Evan Cheng | 43b9ca6 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 182 | return false; |
Evan Cheng | 1b38952 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 183 | |
Jeffrey Yasskin | 091217b | 2010-01-27 20:34:15 +0000 | [diff] [blame] | 184 | // Materializable GVs (in JIT lazy compilation mode) do not require an extra |
| 185 | // load from stub. |
Evan Cheng | 2ce6630 | 2011-02-22 06:58:34 +0000 | [diff] [blame] | 186 | bool isDecl = GV->hasAvailableExternallyLinkage(); |
| 187 | if (GV->isDeclaration() && !GV->isMaterializable()) |
| 188 | isDecl = true; |
Evan Cheng | 1b38952 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 189 | |
| 190 | if (!isTargetDarwin()) { |
| 191 | // Extra load is needed for all externally visible. |
| 192 | if (GV->hasLocalLinkage() || GV->hasHiddenVisibility()) |
| 193 | return false; |
| 194 | return true; |
| 195 | } else { |
| 196 | if (RelocM == Reloc::PIC_) { |
| 197 | // If this is a strong reference to a definition, it is definitely not |
| 198 | // through a stub. |
| 199 | if (!isDecl && !GV->isWeakForLinker()) |
| 200 | return false; |
| 201 | |
| 202 | // Unless we have a symbol with hidden visibility, we have to go through a |
| 203 | // normal $non_lazy_ptr stub because this symbol might be resolved late. |
| 204 | if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference. |
| 205 | return true; |
| 206 | |
| 207 | // If symbol visibility is hidden, we have a stub for common symbol |
| 208 | // references and external declarations. |
| 209 | if (isDecl || GV->hasCommonLinkage()) |
| 210 | // Hidden $non_lazy_ptr reference. |
| 211 | return true; |
| 212 | |
| 213 | return false; |
| 214 | } else { |
| 215 | // If this is a strong reference to a definition, it is definitely not |
| 216 | // through a stub. |
| 217 | if (!isDecl && !GV->isWeakForLinker()) |
| 218 | return false; |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 219 | |
Evan Cheng | 1b38952 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 220 | // Unless we have a symbol with hidden visibility, we have to go through a |
| 221 | // normal $non_lazy_ptr stub because this symbol might be resolved late. |
| 222 | if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference. |
| 223 | return true; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | return false; |
Evan Cheng | 43b9ca6 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 228 | } |
David Goodwin | 0d412c2 | 2009-11-10 00:48:55 +0000 | [diff] [blame] | 229 | |
Owen Anderson | a3181e2 | 2010-09-28 21:57:50 +0000 | [diff] [blame] | 230 | unsigned ARMSubtarget::getMispredictionPenalty() const { |
Andrew Trick | 352abc1 | 2012-08-08 02:44:16 +0000 | [diff] [blame] | 231 | return SchedModel->MispredictPenalty; |
Owen Anderson | a3181e2 | 2010-09-28 21:57:50 +0000 | [diff] [blame] | 232 | } |
| 233 | |
David Goodwin | 0d412c2 | 2009-11-10 00:48:55 +0000 | [diff] [blame] | 234 | bool ARMSubtarget::enablePostRAScheduler( |
| 235 | CodeGenOpt::Level OptLevel, |
Evan Cheng | 0d639a2 | 2011-07-01 21:01:15 +0000 | [diff] [blame] | 236 | TargetSubtargetInfo::AntiDepBreakMode& Mode, |
David Goodwin | b9fe5d5 | 2009-11-13 19:52:48 +0000 | [diff] [blame] | 237 | RegClassVector& CriticalPathRCs) const { |
Evan Cheng | 0d639a2 | 2011-07-01 21:01:15 +0000 | [diff] [blame] | 238 | Mode = TargetSubtargetInfo::ANTIDEP_CRITICAL; |
David Goodwin | b9fe5d5 | 2009-11-13 19:52:48 +0000 | [diff] [blame] | 239 | CriticalPathRCs.clear(); |
| 240 | CriticalPathRCs.push_back(&ARM::GPRRegClass); |
David Goodwin | 0d412c2 | 2009-11-10 00:48:55 +0000 | [diff] [blame] | 241 | return PostRAScheduler && OptLevel >= CodeGenOpt::Default; |
| 242 | } |