1 //===-- ARMSubtarget.cpp - ARM Subtarget Information ------------*- 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 implements the ARM specific subclass of TargetSubtargetInfo.
12 //===----------------------------------------------------------------------===//
14 #include "ARMSubtarget.h"
15 #include "ARMBaseRegisterInfo.h"
16 #include "llvm/GlobalValue.h"
17 #include "llvm/Target/TargetSubtargetInfo.h"
18 #include "llvm/Support/CommandLine.h"
19 #include "llvm/ADT/SmallVector.h"
21 #define GET_SUBTARGETINFO_TARGET_DESC
22 #define GET_SUBTARGETINFO_CTOR
23 #include "ARMGenSubtargetInfo.inc"
28 ReserveR9("arm-reserve-r9", cl::Hidden,
29 cl::desc("Reserve R9, making it unavailable as GPR"));
32 DarwinUseMOVT("arm-darwin-use-movt", cl::init(true), cl::Hidden);
35 StrictAlign("arm-strict-align", cl::Hidden,
36 cl::desc("Disallow all unaligned memory accesses"));
38 ARMSubtarget::ARMSubtarget(const std::string &TT, const std::string &CPU,
39 const std::string &FS)
40 : ARMGenSubtargetInfo(TT, CPU, FS)
41 , ARMProcFamily(Others)
51 , UseNEONForSinglePrecisionFP(false)
53 , HasVMLxForwarding(false)
60 , PostRAScheduler(false)
61 , IsR9Reserved(ReserveR9)
63 , SupportsTailCall(false)
66 , HasHardwareDivide(false)
67 , HasT2ExtractPack(false)
68 , HasDataBarrier(false)
69 , Pref32BitThumb(false)
70 , AvoidCPSRPartialUpdate(false)
71 , HasMPExtension(false)
73 , AllowsUnalignedMem(false)
78 , TargetABI(ARM_ABI_APCS) {
79 // Determine default and user specified characteristics
80 if (CPUString.empty())
81 CPUString = "generic";
83 // Insert the architecture feature derived from the target triple into the
84 // feature string. This is important for setting features that are implied
85 // based on the architecture version.
86 std::string ArchFS = ARM_MC::ParseARMTriple(TT);
89 ArchFS = ArchFS + "," + FS;
93 ParseSubtargetFeatures(CPUString, ArchFS);
95 // Thumb2 implies at least V6T2. FIXME: Fix tests to explicitly specify a
96 // ARM version or CPU and then remove this.
97 if (!HasV6T2Ops && hasThumb2())
98 HasV4TOps = HasV5TOps = HasV5TEOps = HasV6Ops = HasV6T2Ops = true;
100 // Initialize scheduling itinerary for the specified CPU.
101 InstrItins = getInstrItineraryForCPU(CPUString);
103 // After parsing Itineraries, set ItinData.IssueWidth.
106 if (TT.find("eabi") != std::string::npos)
107 TargetABI = ARM_ABI_AAPCS;
112 if (!isTargetDarwin())
113 UseMovt = hasV6T2Ops();
115 IsR9Reserved = ReserveR9 | !HasV6Ops;
116 UseMovt = DarwinUseMOVT && hasV6T2Ops();
117 const Triple &T = getTargetTriple();
118 SupportsTailCall = T.getOS() == Triple::IOS && !T.isOSVersionLT(5, 0);
121 if (!isThumb() || hasThumb2())
122 PostRAScheduler = true;
124 // v6+ may or may not support unaligned mem access depending on the system
126 if (!StrictAlign && hasV6Ops() && isTargetDarwin())
127 AllowsUnalignedMem = true;
130 /// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol.
132 ARMSubtarget::GVIsIndirectSymbol(const GlobalValue *GV,
133 Reloc::Model RelocM) const {
134 if (RelocM == Reloc::Static)
137 // Materializable GVs (in JIT lazy compilation mode) do not require an extra
139 bool isDecl = GV->hasAvailableExternallyLinkage();
140 if (GV->isDeclaration() && !GV->isMaterializable())
143 if (!isTargetDarwin()) {
144 // Extra load is needed for all externally visible.
145 if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
149 if (RelocM == Reloc::PIC_) {
150 // If this is a strong reference to a definition, it is definitely not
152 if (!isDecl && !GV->isWeakForLinker())
155 // Unless we have a symbol with hidden visibility, we have to go through a
156 // normal $non_lazy_ptr stub because this symbol might be resolved late.
157 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
160 // If symbol visibility is hidden, we have a stub for common symbol
161 // references and external declarations.
162 if (isDecl || GV->hasCommonLinkage())
163 // Hidden $non_lazy_ptr reference.
168 // If this is a strong reference to a definition, it is definitely not
170 if (!isDecl && !GV->isWeakForLinker())
173 // Unless we have a symbol with hidden visibility, we have to go through a
174 // normal $non_lazy_ptr stub because this symbol might be resolved late.
175 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
183 unsigned ARMSubtarget::getMispredictionPenalty() const {
184 // If we have a reasonable estimate of the pipeline depth, then we can
185 // estimate the penalty of a misprediction based on that.
188 else if (isCortexA9())
191 // Otherwise, just return a sensible default.
195 void ARMSubtarget::computeIssueWidth() {
196 unsigned allStage1Units = 0;
197 for (const InstrItinerary *itin = InstrItins.Itineraries;
198 itin->FirstStage != ~0U; ++itin) {
199 const InstrStage *IS = InstrItins.Stages + itin->FirstStage;
200 allStage1Units |= IS->getUnits();
202 InstrItins.IssueWidth = 0;
203 while (allStage1Units) {
204 ++InstrItins.IssueWidth;
205 // clear the lowest bit
206 allStage1Units ^= allStage1Units & ~(allStage1Units - 1);
208 assert(InstrItins.IssueWidth <= 2 && "itinerary bug, too many stage 1 units");
211 bool ARMSubtarget::enablePostRAScheduler(
212 CodeGenOpt::Level OptLevel,
213 TargetSubtargetInfo::AntiDepBreakMode& Mode,
214 RegClassVector& CriticalPathRCs) const {
215 Mode = TargetSubtargetInfo::ANTIDEP_CRITICAL;
216 CriticalPathRCs.clear();
217 CriticalPathRCs.push_back(&ARM::GPRRegClass);
218 return PostRAScheduler && OptLevel >= CodeGenOpt::Default;