[ARM] Make sure HasCRC is initialized to false in Subtarget.
[oota-llvm.git] / lib / Target / ARM / ARMSubtarget.cpp
1 //===-- ARMSubtarget.cpp - ARM Subtarget Information ----------------------===//
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 "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"
23
24 #define GET_SUBTARGETINFO_TARGET_DESC
25 #define GET_SUBTARGETINFO_CTOR
26 #include "ARMGenSubtargetInfo.inc"
27
28 using namespace llvm;
29
30 static cl::opt<bool>
31 ReserveR9("arm-reserve-r9", cl::Hidden,
32           cl::desc("Reserve R9, making it unavailable as GPR"));
33
34 static cl::opt<bool>
35 ArmUseMOVT("arm-use-movt", cl::init(true), cl::Hidden);
36
37 static cl::opt<bool>
38 UseFusedMulOps("arm-use-mulops",
39                cl::init(true), cl::Hidden);
40
41 enum AlignMode {
42   DefaultAlign,
43   StrictAlign,
44   NoStrictAlign
45 };
46
47 static cl::opt<AlignMode>
48 Align(cl::desc("Load/store alignment support"),
49       cl::Hidden, cl::init(DefaultAlign),
50       cl::values(
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"),
58           clEnumValEnd));
59
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)
64   , ARMProcClass(None)
65   , stackAlignment(4)
66   , CPUString(CPU)
67   , TargetTriple(TT)
68   , Options(Options)
69   , TargetABI(ARM_ABI_APCS) {
70   initializeEnvironment();
71   resetSubtargetFeatures(CPU, FS);
72 }
73
74 void ARMSubtarget::initializeEnvironment() {
75   HasV4TOps = false;
76   HasV5TOps = false;
77   HasV5TEOps = false;
78   HasV6Ops = false;
79   HasV6MOps = false;
80   HasV6T2Ops = false;
81   HasV7Ops = false;
82   HasV8Ops = false;
83   HasVFPv2 = false;
84   HasVFPv3 = false;
85   HasVFPv4 = false;
86   HasFPARMv8 = false;
87   HasNEON = false;
88   UseNEONForSinglePrecisionFP = false;
89   UseMulOps = UseFusedMulOps;
90   SlowFPVMLx = false;
91   HasVMLxForwarding = false;
92   SlowFPBrcc = false;
93   InThumbMode = false;
94   HasThumb2 = false;
95   NoARM = false;
96   PostRAScheduler = false;
97   IsR9Reserved = ReserveR9;
98   UseMovt = false;
99   SupportsTailCall = false;
100   HasFP16 = false;
101   HasD16 = false;
102   HasHardwareDivide = false;
103   HasHardwareDivideInARM = false;
104   HasT2ExtractPack = false;
105   HasDataBarrier = false;
106   Pref32BitThumb = false;
107   AvoidCPSRPartialUpdate = false;
108   AvoidMOVsShifterOperand = false;
109   HasRAS = false;
110   HasMPExtension = false;
111   FPOnlySP = false;
112   HasPerfMon = false;
113   HasTrustZone = false;
114   HasCrypto = false;
115   HasCRC = false;
116   AllowsUnalignedMem = false;
117   Thumb2DSP = false;
118   UseNaClTrap = false;
119   UnsafeFPMath = false;
120 }
121
122 void ARMSubtarget::resetSubtargetFeatures(const MachineFunction *MF) {
123   AttributeSet FnAttrs = MF->getFunction()->getAttributes();
124   Attribute CPUAttr = FnAttrs.getAttribute(AttributeSet::FunctionIndex,
125                                            "target-cpu");
126   Attribute FSAttr = FnAttrs.getAttribute(AttributeSet::FunctionIndex,
127                                           "target-features");
128   std::string CPU =
129     !CPUAttr.hasAttribute(Attribute::None) ?CPUAttr.getValueAsString() : "";
130   std::string FS =
131     !FSAttr.hasAttribute(Attribute::None) ? FSAttr.getValueAsString() : "";
132   if (!FS.empty()) {
133     initializeEnvironment();
134     resetSubtargetFeatures(CPU, FS);
135   }
136 }
137
138 void ARMSubtarget::resetSubtargetFeatures(StringRef CPU, StringRef FS) {
139   if (CPUString.empty()) {
140     if (isTargetIOS() && TargetTriple.getArchName().endswith("v7s"))
141       // Default to the Swift CPU when targeting armv7s/thumbv7s.
142       CPUString = "swift";
143     else
144       CPUString = "generic";
145   }
146
147   // Insert the architecture feature derived from the target triple into the
148   // feature string. This is important for setting features that are implied
149   // based on the architecture version.
150   std::string ArchFS = ARM_MC::ParseARMTriple(TargetTriple.getTriple(),
151                                               CPUString);
152   if (!FS.empty()) {
153     if (!ArchFS.empty())
154       ArchFS = ArchFS + "," + FS.str();
155     else
156       ArchFS = FS;
157   }
158   ParseSubtargetFeatures(CPUString, ArchFS);
159
160   // Thumb2 implies at least V6T2. FIXME: Fix tests to explicitly specify a
161   // ARM version or CPU and then remove this.
162   if (!HasV6T2Ops && hasThumb2())
163     HasV4TOps = HasV5TOps = HasV5TEOps = HasV6Ops = HasV6MOps = HasV6T2Ops = true;
164
165   // Keep a pointer to static instruction cost data for the specified CPU.
166   SchedModel = getSchedModelForCPU(CPUString);
167
168   // Initialize scheduling itinerary for the specified CPU.
169   InstrItins = getInstrItineraryForCPU(CPUString);
170
171   if ((TargetTriple.getTriple().find("eabi") != std::string::npos) ||
172       (isTargetIOS() && isMClass()))
173     // FIXME: We might want to separate AAPCS and EABI. Some systems, e.g.
174     // Darwin-EABI conforms to AACPS but not the rest of EABI.
175     TargetABI = ARM_ABI_AAPCS;
176
177   if (isAAPCS_ABI())
178     stackAlignment = 8;
179
180   UseMovt = hasV6T2Ops() && ArmUseMOVT;
181
182   if (!isTargetIOS()) {
183     IsR9Reserved = ReserveR9;
184   } else {
185     IsR9Reserved = ReserveR9 | !HasV6Ops;
186     SupportsTailCall = !getTargetTriple().isOSVersionLT(5, 0);
187   }
188
189   if (!isThumb() || hasThumb2())
190     PostRAScheduler = true;
191
192   switch (Align) {
193     case DefaultAlign:
194       // Assume pre-ARMv6 doesn't support unaligned accesses.
195       //
196       // ARMv6 may or may not support unaligned accesses depending on the
197       // SCTLR.U bit, which is architecture-specific. We assume ARMv6
198       // Darwin targets support unaligned accesses, and others don't.
199       //
200       // ARMv7 always has SCTLR.U set to 1, but it has a new SCTLR.A bit
201       // which raises an alignment fault on unaligned accesses. Linux
202       // defaults this bit to 0 and handles it as a system-wide (not
203       // per-process) setting. It is therefore safe to assume that ARMv7+
204       // Linux targets support unaligned accesses. The same goes for NaCl.
205       //
206       // The above behavior is consistent with GCC.
207       AllowsUnalignedMem = (
208           (hasV7Ops() && (isTargetLinux() || isTargetNaCl())) ||
209           (hasV6Ops() && isTargetDarwin()));
210       break;
211     case StrictAlign:
212       AllowsUnalignedMem = false;
213       break;
214     case NoStrictAlign:
215       AllowsUnalignedMem = true;
216       break;
217   }
218
219   // NEON f32 ops are non-IEEE 754 compliant. Darwin is ok with it by default.
220   uint64_t Bits = getFeatureBits();
221   if ((Bits & ARM::ProcA5 || Bits & ARM::ProcA8) && // Where this matters
222       (Options.UnsafeFPMath || isTargetDarwin()))
223     UseNEONForSinglePrecisionFP = true;
224 }
225
226 /// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol.
227 bool
228 ARMSubtarget::GVIsIndirectSymbol(const GlobalValue *GV,
229                                  Reloc::Model RelocM) const {
230   if (RelocM == Reloc::Static)
231     return false;
232
233   // Materializable GVs (in JIT lazy compilation mode) do not require an extra
234   // load from stub.
235   bool isDecl = GV->hasAvailableExternallyLinkage();
236   if (GV->isDeclaration() && !GV->isMaterializable())
237     isDecl = true;
238
239   if (!isTargetDarwin()) {
240     // Extra load is needed for all externally visible.
241     if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
242       return false;
243     return true;
244   } else {
245     if (RelocM == Reloc::PIC_) {
246       // If this is a strong reference to a definition, it is definitely not
247       // through a stub.
248       if (!isDecl && !GV->isWeakForLinker())
249         return false;
250
251       // Unless we have a symbol with hidden visibility, we have to go through a
252       // normal $non_lazy_ptr stub because this symbol might be resolved late.
253       if (!GV->hasHiddenVisibility())  // Non-hidden $non_lazy_ptr reference.
254         return true;
255
256       // If symbol visibility is hidden, we have a stub for common symbol
257       // references and external declarations.
258       if (isDecl || GV->hasCommonLinkage())
259         // Hidden $non_lazy_ptr reference.
260         return true;
261
262       return false;
263     } else {
264       // If this is a strong reference to a definition, it is definitely not
265       // through a stub.
266       if (!isDecl && !GV->isWeakForLinker())
267         return false;
268
269       // Unless we have a symbol with hidden visibility, we have to go through a
270       // normal $non_lazy_ptr stub because this symbol might be resolved late.
271       if (!GV->hasHiddenVisibility())  // Non-hidden $non_lazy_ptr reference.
272         return true;
273     }
274   }
275
276   return false;
277 }
278
279 unsigned ARMSubtarget::getMispredictionPenalty() const {
280   return SchedModel->MispredictPenalty;
281 }
282
283 bool ARMSubtarget::enablePostRAScheduler(
284            CodeGenOpt::Level OptLevel,
285            TargetSubtargetInfo::AntiDepBreakMode& Mode,
286            RegClassVector& CriticalPathRCs) const {
287   Mode = TargetSubtargetInfo::ANTIDEP_NONE;
288   return PostRAScheduler && OptLevel >= CodeGenOpt::Default;
289 }