1 //===-- ARMSubtarget.cpp - ARM Subtarget Information ----------------------===//
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 implements the ARM specific subclass of TargetSubtargetInfo.
12 //===----------------------------------------------------------------------===//
14 #include "ARMSubtarget.h"
15 #include "ARMBaseInstrInfo.h"
16 #include "ARMBaseRegisterInfo.h"
17 #include "llvm/IR/Attributes.h"
18 #include "llvm/IR/GlobalValue.h"
19 #include "llvm/IR/Function.h"
20 #include "llvm/Support/CommandLine.h"
21 #include "llvm/Target/TargetInstrInfo.h"
22 #include "llvm/Target/TargetOptions.h"
24 #define GET_SUBTARGETINFO_TARGET_DESC
25 #define GET_SUBTARGETINFO_CTOR
26 #include "ARMGenSubtargetInfo.inc"
31 ReserveR9("arm-reserve-r9", cl::Hidden,
32 cl::desc("Reserve R9, making it unavailable as GPR"));
35 ArmUseMOVT("arm-use-movt", cl::init(true), cl::Hidden);
38 UseFusedMulOps("arm-use-mulops",
39 cl::init(true), cl::Hidden);
47 static cl::opt<AlignMode>
48 Align(cl::desc("Load/store alignment support"),
49 cl::Hidden, cl::init(DefaultAlign),
51 clEnumValN(DefaultAlign, "arm-default-align",
52 "Generate unaligned accesses only on hardware/OS "
53 "combinations that are known to support them"),
54 clEnumValN(StrictAlign, "arm-strict-align",
55 "Disallow all unaligned memory accesses"),
56 clEnumValN(NoStrictAlign, "arm-no-strict-align",
57 "Allow unaligned memory accesses"),
60 ARMSubtarget::ARMSubtarget(const std::string &TT, const std::string &CPU,
61 const std::string &FS, const TargetOptions &Options)
62 : ARMGenSubtargetInfo(TT, CPU, FS)
63 , ARMProcFamily(Others)
69 , TargetABI(ARM_ABI_APCS) {
70 initializeEnvironment();
71 resetSubtargetFeatures(CPU, FS);
74 void ARMSubtarget::initializeEnvironment() {
88 UseNEONForSinglePrecisionFP = false;
89 UseMulOps = UseFusedMulOps;
91 HasVMLxForwarding = false;
96 PostRAScheduler = false;
97 IsR9Reserved = ReserveR9;
99 SupportsTailCall = false;
102 HasHardwareDivide = false;
103 HasHardwareDivideInARM = false;
104 HasT2ExtractPack = false;
105 HasDataBarrier = false;
106 Pref32BitThumb = false;
107 AvoidCPSRPartialUpdate = false;
108 AvoidMOVsShifterOperand = false;
110 HasMPExtension = false;
113 HasTrustZone = false;
115 AllowsUnalignedMem = false;
118 UnsafeFPMath = false;
121 void ARMSubtarget::resetSubtargetFeatures(const MachineFunction *MF) {
122 AttributeSet FnAttrs = MF->getFunction()->getAttributes();
123 Attribute CPUAttr = FnAttrs.getAttribute(AttributeSet::FunctionIndex,
125 Attribute FSAttr = FnAttrs.getAttribute(AttributeSet::FunctionIndex,
128 !CPUAttr.hasAttribute(Attribute::None) ?CPUAttr.getValueAsString() : "";
130 !FSAttr.hasAttribute(Attribute::None) ? FSAttr.getValueAsString() : "";
132 initializeEnvironment();
133 resetSubtargetFeatures(CPU, FS);
137 void ARMSubtarget::resetSubtargetFeatures(StringRef CPU, StringRef FS) {
138 if (CPUString.empty()) {
139 if (isTargetIOS() && TargetTriple.getArchName().endswith("v7s"))
140 // Default to the Swift CPU when targeting armv7s/thumbv7s.
143 CPUString = "generic";
146 // Insert the architecture feature derived from the target triple into the
147 // feature string. This is important for setting features that are implied
148 // based on the architecture version.
149 std::string ArchFS = ARM_MC::ParseARMTriple(TargetTriple.getTriple(),
153 ArchFS = ArchFS + "," + FS.str();
157 ParseSubtargetFeatures(CPUString, ArchFS);
159 // Thumb2 implies at least V6T2. FIXME: Fix tests to explicitly specify a
160 // ARM version or CPU and then remove this.
161 if (!HasV6T2Ops && hasThumb2())
162 HasV4TOps = HasV5TOps = HasV5TEOps = HasV6Ops = HasV6MOps = HasV6T2Ops = true;
164 // Keep a pointer to static instruction cost data for the specified CPU.
165 SchedModel = getSchedModelForCPU(CPUString);
167 // Initialize scheduling itinerary for the specified CPU.
168 InstrItins = getInstrItineraryForCPU(CPUString);
170 if ((TargetTriple.getTriple().find("eabi") != std::string::npos) ||
171 (isTargetIOS() && isMClass()))
172 // FIXME: We might want to separate AAPCS and EABI. Some systems, e.g.
173 // Darwin-EABI conforms to AACPS but not the rest of EABI.
174 TargetABI = ARM_ABI_AAPCS;
179 UseMovt = hasV6T2Ops() && ArmUseMOVT;
181 if (!isTargetIOS()) {
182 IsR9Reserved = ReserveR9;
184 IsR9Reserved = ReserveR9 | !HasV6Ops;
185 SupportsTailCall = !getTargetTriple().isOSVersionLT(5, 0);
188 if (!isThumb() || hasThumb2())
189 PostRAScheduler = true;
193 // Assume pre-ARMv6 doesn't support unaligned accesses.
195 // ARMv6 may or may not support unaligned accesses depending on the
196 // SCTLR.U bit, which is architecture-specific. We assume ARMv6
197 // Darwin targets support unaligned accesses, and others don't.
199 // ARMv7 always has SCTLR.U set to 1, but it has a new SCTLR.A bit
200 // which raises an alignment fault on unaligned accesses. Linux
201 // defaults this bit to 0 and handles it as a system-wide (not
202 // per-process) setting. It is therefore safe to assume that ARMv7+
203 // Linux targets support unaligned accesses. The same goes for NaCl.
205 // The above behavior is consistent with GCC.
206 AllowsUnalignedMem = (
207 (hasV7Ops() && (isTargetLinux() || isTargetNaCl())) ||
208 (hasV6Ops() && isTargetDarwin()));
211 AllowsUnalignedMem = false;
214 AllowsUnalignedMem = true;
218 // NEON f32 ops are non-IEEE 754 compliant. Darwin is ok with it by default.
219 uint64_t Bits = getFeatureBits();
220 if ((Bits & ARM::ProcA5 || Bits & ARM::ProcA8) && // Where this matters
221 (Options.UnsafeFPMath || isTargetDarwin()))
222 UseNEONForSinglePrecisionFP = true;
225 /// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol.
227 ARMSubtarget::GVIsIndirectSymbol(const GlobalValue *GV,
228 Reloc::Model RelocM) const {
229 if (RelocM == Reloc::Static)
232 // Materializable GVs (in JIT lazy compilation mode) do not require an extra
234 bool isDecl = GV->hasAvailableExternallyLinkage();
235 if (GV->isDeclaration() && !GV->isMaterializable())
238 if (!isTargetDarwin()) {
239 // Extra load is needed for all externally visible.
240 if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
244 if (RelocM == Reloc::PIC_) {
245 // If this is a strong reference to a definition, it is definitely not
247 if (!isDecl && !GV->isWeakForLinker())
250 // Unless we have a symbol with hidden visibility, we have to go through a
251 // normal $non_lazy_ptr stub because this symbol might be resolved late.
252 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
255 // If symbol visibility is hidden, we have a stub for common symbol
256 // references and external declarations.
257 if (isDecl || GV->hasCommonLinkage())
258 // Hidden $non_lazy_ptr reference.
263 // If this is a strong reference to a definition, it is definitely not
265 if (!isDecl && !GV->isWeakForLinker())
268 // Unless we have a symbol with hidden visibility, we have to go through a
269 // normal $non_lazy_ptr stub because this symbol might be resolved late.
270 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
278 unsigned ARMSubtarget::getMispredictionPenalty() const {
279 return SchedModel->MispredictPenalty;
282 bool ARMSubtarget::enablePostRAScheduler(
283 CodeGenOpt::Level OptLevel,
284 TargetSubtargetInfo::AntiDepBreakMode& Mode,
285 RegClassVector& CriticalPathRCs) const {
286 Mode = TargetSubtargetInfo::ANTIDEP_NONE;
287 return PostRAScheduler && OptLevel >= CodeGenOpt::Default;