]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/lib/Target/ARM/ARMSubtarget.cpp
Copy head to stable/9 as part of 9.0-RELEASE release cycle.
[FreeBSD/stable/9.git] / contrib / llvm / lib / Target / ARM / ARMSubtarget.cpp
1 //===-- ARMSubtarget.cpp - ARM Subtarget Information ------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the ARM specific subclass of TargetSubtargetInfo.
11 //
12 //===----------------------------------------------------------------------===//
13
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"
20
21 #define GET_SUBTARGETINFO_TARGET_DESC
22 #define GET_SUBTARGETINFO_CTOR
23 #include "ARMGenSubtargetInfo.inc"
24
25 using namespace llvm;
26
27 static cl::opt<bool>
28 ReserveR9("arm-reserve-r9", cl::Hidden,
29           cl::desc("Reserve R9, making it unavailable as GPR"));
30
31 static cl::opt<bool>
32 DarwinUseMOVT("arm-darwin-use-movt", cl::init(true), cl::Hidden);
33
34 static cl::opt<bool>
35 StrictAlign("arm-strict-align", cl::Hidden,
36             cl::desc("Disallow all unaligned memory accesses"));
37
38 ARMSubtarget::ARMSubtarget(const std::string &TT, const std::string &CPU,
39                            const std::string &FS)
40   : ARMGenSubtargetInfo(TT, CPU, FS)
41   , ARMProcFamily(Others)
42   , HasV4TOps(false)
43   , HasV5TOps(false)
44   , HasV5TEOps(false)
45   , HasV6Ops(false)
46   , HasV6T2Ops(false)
47   , HasV7Ops(false)
48   , HasVFPv2(false)
49   , HasVFPv3(false)
50   , HasNEON(false)
51   , UseNEONForSinglePrecisionFP(false)
52   , SlowFPVMLx(false)
53   , HasVMLxForwarding(false)
54   , SlowFPBrcc(false)
55   , InThumbMode(false)
56   , HasThumb2(false)
57   , NoARM(false)
58   , PostRAScheduler(false)
59   , IsR9Reserved(ReserveR9)
60   , UseMovt(false)
61   , HasFP16(false)
62   , HasD16(false)
63   , HasHardwareDivide(false)
64   , HasT2ExtractPack(false)
65   , HasDataBarrier(false)
66   , Pref32BitThumb(false)
67   , AvoidCPSRPartialUpdate(false)
68   , HasMPExtension(false)
69   , FPOnlySP(false)
70   , AllowsUnalignedMem(false)
71   , Thumb2DSP(false)
72   , stackAlignment(4)
73   , CPUString(CPU)
74   , TargetTriple(TT)
75   , TargetABI(ARM_ABI_APCS) {
76   // Determine default and user specified characteristics
77   if (CPUString.empty())
78     CPUString = "generic";
79
80   // Insert the architecture feature derived from the target triple into the
81   // feature string. This is important for setting features that are implied
82   // based on the architecture version.
83   std::string ArchFS = ARM_MC::ParseARMTriple(TT);
84   if (!FS.empty()) {
85     if (!ArchFS.empty())
86       ArchFS = ArchFS + "," + FS;
87     else
88       ArchFS = FS;
89   }
90   ParseSubtargetFeatures(CPUString, ArchFS);
91
92   // Thumb2 implies at least V6T2. FIXME: Fix tests to explicitly specify a
93   // ARM version or CPU and then remove this.
94   if (!HasV6T2Ops && hasThumb2())
95     HasV4TOps = HasV5TOps = HasV5TEOps = HasV6Ops = HasV6T2Ops = true;
96
97   // Initialize scheduling itinerary for the specified CPU.
98   InstrItins = getInstrItineraryForCPU(CPUString);
99
100   // After parsing Itineraries, set ItinData.IssueWidth.
101   computeIssueWidth();
102
103   if (TT.find("eabi") != std::string::npos)
104     TargetABI = ARM_ABI_AAPCS;
105
106   if (isAAPCS_ABI())
107     stackAlignment = 8;
108
109   if (!isTargetDarwin())
110     UseMovt = hasV6T2Ops();
111   else {
112     IsR9Reserved = ReserveR9 | !HasV6Ops;
113     UseMovt = DarwinUseMOVT && hasV6T2Ops();
114   }
115
116   if (!isThumb() || hasThumb2())
117     PostRAScheduler = true;
118
119   // v6+ may or may not support unaligned mem access depending on the system
120   // configuration.
121   if (!StrictAlign && hasV6Ops() && isTargetDarwin())
122     AllowsUnalignedMem = true;
123 }
124
125 /// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol.
126 bool
127 ARMSubtarget::GVIsIndirectSymbol(const GlobalValue *GV,
128                                  Reloc::Model RelocM) const {
129   if (RelocM == Reloc::Static)
130     return false;
131
132   // Materializable GVs (in JIT lazy compilation mode) do not require an extra
133   // load from stub.
134   bool isDecl = GV->hasAvailableExternallyLinkage();
135   if (GV->isDeclaration() && !GV->isMaterializable())
136     isDecl = true;
137
138   if (!isTargetDarwin()) {
139     // Extra load is needed for all externally visible.
140     if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
141       return false;
142     return true;
143   } else {
144     if (RelocM == Reloc::PIC_) {
145       // If this is a strong reference to a definition, it is definitely not
146       // through a stub.
147       if (!isDecl && !GV->isWeakForLinker())
148         return false;
149
150       // Unless we have a symbol with hidden visibility, we have to go through a
151       // normal $non_lazy_ptr stub because this symbol might be resolved late.
152       if (!GV->hasHiddenVisibility())  // Non-hidden $non_lazy_ptr reference.
153         return true;
154
155       // If symbol visibility is hidden, we have a stub for common symbol
156       // references and external declarations.
157       if (isDecl || GV->hasCommonLinkage())
158         // Hidden $non_lazy_ptr reference.
159         return true;
160
161       return false;
162     } else {
163       // If this is a strong reference to a definition, it is definitely not
164       // through a stub.
165       if (!isDecl && !GV->isWeakForLinker())
166         return false;
167
168       // Unless we have a symbol with hidden visibility, we have to go through a
169       // normal $non_lazy_ptr stub because this symbol might be resolved late.
170       if (!GV->hasHiddenVisibility())  // Non-hidden $non_lazy_ptr reference.
171         return true;
172     }
173   }
174
175   return false;
176 }
177
178 unsigned ARMSubtarget::getMispredictionPenalty() const {
179   // If we have a reasonable estimate of the pipeline depth, then we can
180   // estimate the penalty of a misprediction based on that.
181   if (isCortexA8())
182     return 13;
183   else if (isCortexA9())
184     return 8;
185
186   // Otherwise, just return a sensible default.
187   return 10;
188 }
189
190 void ARMSubtarget::computeIssueWidth() {
191   unsigned allStage1Units = 0;
192   for (const InstrItinerary *itin = InstrItins.Itineraries;
193        itin->FirstStage != ~0U; ++itin) {
194     const InstrStage *IS = InstrItins.Stages + itin->FirstStage;
195     allStage1Units |= IS->getUnits();
196   }
197   InstrItins.IssueWidth = 0;
198   while (allStage1Units) {
199     ++InstrItins.IssueWidth;
200     // clear the lowest bit
201     allStage1Units ^= allStage1Units & ~(allStage1Units - 1);
202   }
203   assert(InstrItins.IssueWidth <= 2 && "itinerary bug, too many stage 1 units");
204 }
205
206 bool ARMSubtarget::enablePostRAScheduler(
207            CodeGenOpt::Level OptLevel,
208            TargetSubtargetInfo::AntiDepBreakMode& Mode,
209            RegClassVector& CriticalPathRCs) const {
210   Mode = TargetSubtargetInfo::ANTIDEP_CRITICAL;
211   CriticalPathRCs.clear();
212   CriticalPathRCs.push_back(&ARM::GPRRegClass);
213   return PostRAScheduler && OptLevel >= CodeGenOpt::Default;
214 }