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;
111 HasVirtualization = false;
114 HasTrustZone = false;
117 AllowsUnalignedMem = false;
120 UnsafeFPMath = false;
123 void ARMSubtarget::resetSubtargetFeatures(const MachineFunction *MF) {
124 AttributeSet FnAttrs = MF->getFunction()->getAttributes();
125 Attribute CPUAttr = FnAttrs.getAttribute(AttributeSet::FunctionIndex,
127 Attribute FSAttr = FnAttrs.getAttribute(AttributeSet::FunctionIndex,
130 !CPUAttr.hasAttribute(Attribute::None) ?CPUAttr.getValueAsString() : "";
132 !FSAttr.hasAttribute(Attribute::None) ? FSAttr.getValueAsString() : "";
134 initializeEnvironment();
135 resetSubtargetFeatures(CPU, FS);
139 void ARMSubtarget::resetSubtargetFeatures(StringRef CPU, StringRef FS) {
140 if (CPUString.empty()) {
141 if (isTargetIOS() && TargetTriple.getArchName().endswith("v7s"))
142 // Default to the Swift CPU when targeting armv7s/thumbv7s.
145 CPUString = "generic";
148 // Insert the architecture feature derived from the target triple into the
149 // feature string. This is important for setting features that are implied
150 // based on the architecture version.
151 std::string ArchFS = ARM_MC::ParseARMTriple(TargetTriple.getTriple(),
155 ArchFS = ArchFS + "," + FS.str();
159 ParseSubtargetFeatures(CPUString, ArchFS);
161 // Thumb2 implies at least V6T2. FIXME: Fix tests to explicitly specify a
162 // ARM version or CPU and then remove this.
163 if (!HasV6T2Ops && hasThumb2())
164 HasV4TOps = HasV5TOps = HasV5TEOps = HasV6Ops = HasV6MOps = HasV6T2Ops = true;
166 // Keep a pointer to static instruction cost data for the specified CPU.
167 SchedModel = getSchedModelForCPU(CPUString);
169 // Initialize scheduling itinerary for the specified CPU.
170 InstrItins = getInstrItineraryForCPU(CPUString);
172 if ((TargetTriple.getTriple().find("eabi") != std::string::npos) ||
173 (isTargetIOS() && isMClass()))
174 // FIXME: We might want to separate AAPCS and EABI. Some systems, e.g.
175 // Darwin-EABI conforms to AACPS but not the rest of EABI.
176 TargetABI = ARM_ABI_AAPCS;
181 UseMovt = hasV6T2Ops() && ArmUseMOVT;
183 if (!isTargetIOS()) {
184 IsR9Reserved = ReserveR9;
186 IsR9Reserved = ReserveR9 | !HasV6Ops;
187 SupportsTailCall = !getTargetTriple().isOSVersionLT(5, 0);
190 if (!isThumb() || hasThumb2())
191 PostRAScheduler = true;
195 // Assume pre-ARMv6 doesn't support unaligned accesses.
197 // ARMv6 may or may not support unaligned accesses depending on the
198 // SCTLR.U bit, which is architecture-specific. We assume ARMv6
199 // Darwin targets support unaligned accesses, and others don't.
201 // ARMv7 always has SCTLR.U set to 1, but it has a new SCTLR.A bit
202 // which raises an alignment fault on unaligned accesses. Linux
203 // defaults this bit to 0 and handles it as a system-wide (not
204 // per-process) setting. It is therefore safe to assume that ARMv7+
205 // Linux targets support unaligned accesses. The same goes for NaCl.
207 // The above behavior is consistent with GCC.
208 AllowsUnalignedMem = (
209 (hasV7Ops() && (isTargetLinux() || isTargetNaCl())) ||
210 (hasV6Ops() && isTargetDarwin()));
213 AllowsUnalignedMem = false;
216 AllowsUnalignedMem = true;
220 // NEON f32 ops are non-IEEE 754 compliant. Darwin is ok with it by default.
221 uint64_t Bits = getFeatureBits();
222 if ((Bits & ARM::ProcA5 || Bits & ARM::ProcA8) && // Where this matters
223 (Options.UnsafeFPMath || isTargetDarwin()))
224 UseNEONForSinglePrecisionFP = true;
227 /// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol.
229 ARMSubtarget::GVIsIndirectSymbol(const GlobalValue *GV,
230 Reloc::Model RelocM) const {
231 if (RelocM == Reloc::Static)
234 // Materializable GVs (in JIT lazy compilation mode) do not require an extra
236 bool isDecl = GV->hasAvailableExternallyLinkage();
237 if (GV->isDeclaration() && !GV->isMaterializable())
240 if (!isTargetDarwin()) {
241 // Extra load is needed for all externally visible.
242 if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
246 if (RelocM == Reloc::PIC_) {
247 // If this is a strong reference to a definition, it is definitely not
249 if (!isDecl && !GV->isWeakForLinker())
252 // Unless we have a symbol with hidden visibility, we have to go through a
253 // normal $non_lazy_ptr stub because this symbol might be resolved late.
254 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
257 // If symbol visibility is hidden, we have a stub for common symbol
258 // references and external declarations.
259 if (isDecl || GV->hasCommonLinkage())
260 // Hidden $non_lazy_ptr reference.
265 // If this is a strong reference to a definition, it is definitely not
267 if (!isDecl && !GV->isWeakForLinker())
270 // Unless we have a symbol with hidden visibility, we have to go through a
271 // normal $non_lazy_ptr stub because this symbol might be resolved late.
272 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
280 unsigned ARMSubtarget::getMispredictionPenalty() const {
281 return SchedModel->MispredictPenalty;
284 bool ARMSubtarget::hasSinCos() const {
285 return getTargetTriple().getOS() == Triple::IOS &&
286 !getTargetTriple().isOSVersionLT(7, 0);
289 bool ARMSubtarget::enablePostRAScheduler(
290 CodeGenOpt::Level OptLevel,
291 TargetSubtargetInfo::AntiDepBreakMode& Mode,
292 RegClassVector& CriticalPathRCs) const {
293 Mode = TargetSubtargetInfo::ANTIDEP_NONE;
294 return PostRAScheduler && OptLevel >= CodeGenOpt::Default;