c33bb9d5bc2019e2cc1d56ca65bd606f155c6b05
[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
23 #define GET_SUBTARGETINFO_TARGET_DESC
24 #define GET_SUBTARGETINFO_CTOR
25 #include "ARMGenSubtargetInfo.inc"
26
27 using namespace llvm;
28
29 static cl::opt<bool>
30 ReserveR9("arm-reserve-r9", cl::Hidden,
31           cl::desc("Reserve R9, making it unavailable as GPR"));
32
33 static cl::opt<bool>
34 DarwinUseMOVT("arm-darwin-use-movt", cl::init(true), cl::Hidden);
35
36 static cl::opt<bool>
37 UseFusedMulOps("arm-use-mulops",
38                cl::init(true), cl::Hidden);
39
40 static cl::opt<bool>
41 StrictAlign("arm-strict-align", cl::Hidden,
42             cl::desc("Disallow all unaligned memory accesses"));
43
44 ARMSubtarget::ARMSubtarget(const std::string &TT, const std::string &CPU,
45                            const std::string &FS)
46   : ARMGenSubtargetInfo(TT, CPU, FS)
47   , ARMProcFamily(Others)
48   , HasV4TOps(false)
49   , HasV5TOps(false)
50   , HasV5TEOps(false)
51   , HasV6Ops(false)
52   , HasV6T2Ops(false)
53   , HasV7Ops(false)
54   , HasVFPv2(false)
55   , HasVFPv3(false)
56   , HasVFPv4(false)
57   , HasNEON(false)
58   , UseNEONForSinglePrecisionFP(false)
59   , UseMulOps(UseFusedMulOps)
60   , SlowFPVMLx(false)
61   , HasVMLxForwarding(false)
62   , SlowFPBrcc(false)
63   , InThumbMode(false)
64   , HasThumb2(false)
65   , IsMClass(false)
66   , NoARM(false)
67   , PostRAScheduler(false)
68   , IsR9Reserved(ReserveR9)
69   , UseMovt(false)
70   , SupportsTailCall(false)
71   , HasFP16(false)
72   , HasD16(false)
73   , HasHardwareDivide(false)
74   , HasHardwareDivideInARM(false)
75   , HasT2ExtractPack(false)
76   , HasDataBarrier(false)
77   , Pref32BitThumb(false)
78   , AvoidCPSRPartialUpdate(false)
79   , AvoidMOVsShifterOperand(false)
80   , HasRAS(false)
81   , HasMPExtension(false)
82   , FPOnlySP(false)
83   , AllowsUnalignedMem(false)
84   , Thumb2DSP(false)
85   , UseNaClTrap(false)
86   , stackAlignment(4)
87   , CPUString(CPU)
88   , TargetTriple(TT)
89   , TargetABI(ARM_ABI_APCS) {
90   resetSubtargetFeatures(CPU, FS);
91 }
92
93 void ARMSubtarget::resetSubtargetFeatures(const MachineFunction *MF) {
94   AttributeSet FnAttrs = MF->getFunction()->getAttributes();
95   Attribute CPUAttr = FnAttrs.getAttribute(AttributeSet::FunctionIndex,
96                                            "target-cpu");
97   Attribute FSAttr = FnAttrs.getAttribute(AttributeSet::FunctionIndex,
98                                           "target-features");
99   std::string CPU =
100     !CPUAttr.hasAttribute(Attribute::None) ?CPUAttr.getValueAsString() : "";
101   std::string FS =
102     !FSAttr.hasAttribute(Attribute::None) ? FSAttr.getValueAsString() : "";
103   if (!FS.empty())
104     resetSubtargetFeatures(CPU, FS);
105 }
106
107 void ARMSubtarget::resetSubtargetFeatures(StringRef CPU, StringRef FS) {
108   if (CPUString.empty())
109     CPUString = "generic";
110
111   // Insert the architecture feature derived from the target triple into the
112   // feature string. This is important for setting features that are implied
113   // based on the architecture version.
114   std::string ArchFS = ARM_MC::ParseARMTriple(TargetTriple.getTriple(),
115                                               CPUString);
116   if (!FS.empty()) {
117     if (!ArchFS.empty())
118       ArchFS = ArchFS + "," + FS.str();
119     else
120       ArchFS = FS;
121   }
122   ParseSubtargetFeatures(CPUString, ArchFS);
123
124   // Thumb2 implies at least V6T2. FIXME: Fix tests to explicitly specify a
125   // ARM version or CPU and then remove this.
126   if (!HasV6T2Ops && hasThumb2())
127     HasV4TOps = HasV5TOps = HasV5TEOps = HasV6Ops = HasV6T2Ops = true;
128
129   // Keep a pointer to static instruction cost data for the specified CPU.
130   SchedModel = getSchedModelForCPU(CPUString);
131
132   // Initialize scheduling itinerary for the specified CPU.
133   InstrItins = getInstrItineraryForCPU(CPUString);
134
135   if ((TargetTriple.getTriple().find("eabi") != std::string::npos) ||
136       (isTargetIOS() && isMClass()))
137     // FIXME: We might want to separate AAPCS and EABI. Some systems, e.g.
138     // Darwin-EABI conforms to AACPS but not the rest of EABI.
139     TargetABI = ARM_ABI_AAPCS;
140
141   if (isAAPCS_ABI())
142     stackAlignment = 8;
143
144   if (!isTargetIOS())
145     UseMovt = hasV6T2Ops();
146   else {
147     IsR9Reserved = ReserveR9 | !HasV6Ops;
148     UseMovt = DarwinUseMOVT && hasV6T2Ops();
149     SupportsTailCall = !getTargetTriple().isOSVersionLT(5, 0);
150   }
151
152   if (!isThumb() || hasThumb2())
153     PostRAScheduler = true;
154
155   // v6+ may or may not support unaligned mem access depending on the system
156   // configuration.
157   if (!StrictAlign && hasV6Ops() && isTargetDarwin())
158     AllowsUnalignedMem = true;
159 }
160
161 /// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol.
162 bool
163 ARMSubtarget::GVIsIndirectSymbol(const GlobalValue *GV,
164                                  Reloc::Model RelocM) const {
165   if (RelocM == Reloc::Static)
166     return false;
167
168   // Materializable GVs (in JIT lazy compilation mode) do not require an extra
169   // load from stub.
170   bool isDecl = GV->hasAvailableExternallyLinkage();
171   if (GV->isDeclaration() && !GV->isMaterializable())
172     isDecl = true;
173
174   if (!isTargetDarwin()) {
175     // Extra load is needed for all externally visible.
176     if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
177       return false;
178     return true;
179   } else {
180     if (RelocM == Reloc::PIC_) {
181       // If this is a strong reference to a definition, it is definitely not
182       // through a stub.
183       if (!isDecl && !GV->isWeakForLinker())
184         return false;
185
186       // Unless we have a symbol with hidden visibility, we have to go through a
187       // normal $non_lazy_ptr stub because this symbol might be resolved late.
188       if (!GV->hasHiddenVisibility())  // Non-hidden $non_lazy_ptr reference.
189         return true;
190
191       // If symbol visibility is hidden, we have a stub for common symbol
192       // references and external declarations.
193       if (isDecl || GV->hasCommonLinkage())
194         // Hidden $non_lazy_ptr reference.
195         return true;
196
197       return false;
198     } else {
199       // If this is a strong reference to a definition, it is definitely not
200       // through a stub.
201       if (!isDecl && !GV->isWeakForLinker())
202         return false;
203
204       // Unless we have a symbol with hidden visibility, we have to go through a
205       // normal $non_lazy_ptr stub because this symbol might be resolved late.
206       if (!GV->hasHiddenVisibility())  // Non-hidden $non_lazy_ptr reference.
207         return true;
208     }
209   }
210
211   return false;
212 }
213
214 unsigned ARMSubtarget::getMispredictionPenalty() const {
215   return SchedModel->MispredictPenalty;
216 }
217
218 bool ARMSubtarget::enablePostRAScheduler(
219            CodeGenOpt::Level OptLevel,
220            TargetSubtargetInfo::AntiDepBreakMode& Mode,
221            RegClassVector& CriticalPathRCs) const {
222   Mode = TargetSubtargetInfo::ANTIDEP_CRITICAL;
223   CriticalPathRCs.clear();
224   CriticalPathRCs.push_back(&ARM::GPRRegClass);
225   return PostRAScheduler && OptLevel >= CodeGenOpt::Default;
226 }