b46bd0c1b80f7c07db920e1351013dbf234420d7
[oota-llvm.git] / 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 TargetSubtarget.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "ARMSubtarget.h"
15 #include "ARMGenSubtarget.inc"
16 #include "llvm/GlobalValue.h"
17 #include "llvm/Target/TargetOptions.h"
18 #include "llvm/Support/CommandLine.h"
19 using namespace llvm;
20
21 static cl::opt<bool>
22 ReserveR9("arm-reserve-r9", cl::Hidden,
23           cl::desc("Reserve R9, making it unavailable as GPR"));
24
25 ARMSubtarget::ARMSubtarget(const std::string &TT, const std::string &FS,
26                            bool isThumb)
27   : ARMArchVersion(V4T)
28   , ARMFPUType(None)
29   , UseNEONForSinglePrecisionFP(false)
30   , IsThumb(isThumb)
31   , ThumbMode(Thumb1)
32   , PostRAScheduler(false)
33   , IsR9Reserved(ReserveR9)
34   , stackAlignment(4)
35   , CPUString("generic")
36   , TargetType(isELF) // Default to ELF unless otherwise specified.
37   , TargetABI(ARM_ABI_APCS) {
38   // default to soft float ABI
39   if (FloatABIType == FloatABI::Default)
40     FloatABIType = FloatABI::Soft;
41
42   // Determine default and user specified characteristics
43
44   // Parse features string.
45   CPUString = ParseSubtargetFeatures(FS, CPUString);
46
47   // Set the boolean corresponding to the current target triple, or the default
48   // if one cannot be determined, to true.
49   unsigned Len = TT.length();
50   unsigned Idx = 0;
51
52   if (Len >= 5 && TT.substr(0, 4) == "armv")
53     Idx = 4;
54   else if (Len >= 6 && TT.substr(0, 5) == "thumb") {
55     IsThumb = true;
56     if (Len >= 7 && TT[5] == 'v')
57       Idx = 6;
58   }
59   if (Idx) {
60     unsigned SubVer = TT[Idx];
61     if (SubVer > '4' && SubVer <= '9') {
62       if (SubVer >= '7') {
63         ARMArchVersion = V7A;
64       } else if (SubVer == '6') {
65         ARMArchVersion = V6;
66         if (Len >= Idx+3 && TT[Idx+1] == 't' && TT[Idx+2] == '2')
67           ARMArchVersion = V6T2;
68       } else if (SubVer == '5') {
69         ARMArchVersion = V5T;
70         if (Len >= Idx+3 && TT[Idx+1] == 't' && TT[Idx+2] == 'e')
71           ARMArchVersion = V5TE;
72       }
73       if (ARMArchVersion >= V6T2)
74         ThumbMode = Thumb2;
75     }
76   }
77
78   // Thumb2 implies at least V6T2.
79   if (ARMArchVersion < V6T2 && ThumbMode >= Thumb2)
80     ARMArchVersion = V6T2;
81
82   if (Len >= 10) {
83     if (TT.find("-darwin") != std::string::npos)
84       // arm-darwin
85       TargetType = isDarwin;
86   }
87
88   if (TT.find("eabi") != std::string::npos)
89     TargetABI = ARM_ABI_AAPCS;
90
91   if (isAAPCS_ABI())
92     stackAlignment = 8;
93
94   if (isTargetDarwin())
95     IsR9Reserved = ReserveR9 | (ARMArchVersion < V6);
96 }
97
98 /// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol.
99 bool
100 ARMSubtarget::GVIsIndirectSymbol(GlobalValue *GV, Reloc::Model RelocM) const {
101   if (RelocM == Reloc::Static)
102     return false;
103
104   // GV with ghost linkage (in JIT lazy compilation mode) do not require an
105   // extra load from stub.
106   bool isDecl = GV->isDeclaration() && !GV->hasNotBeenReadFromBitcode();
107
108   if (!isTargetDarwin()) {
109     // Extra load is needed for all externally visible.
110     if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
111       return false;
112     return true;
113   } else {
114     if (RelocM == Reloc::PIC_) {
115       // If this is a strong reference to a definition, it is definitely not
116       // through a stub.
117       if (!isDecl && !GV->isWeakForLinker())
118         return false;
119
120       // Unless we have a symbol with hidden visibility, we have to go through a
121       // normal $non_lazy_ptr stub because this symbol might be resolved late.
122       if (!GV->hasHiddenVisibility())  // Non-hidden $non_lazy_ptr reference.
123         return true;
124
125       // If symbol visibility is hidden, we have a stub for common symbol
126       // references and external declarations.
127       if (isDecl || GV->hasCommonLinkage())
128         // Hidden $non_lazy_ptr reference.
129         return true;
130
131       return false;
132     } else {
133       // If this is a strong reference to a definition, it is definitely not
134       // through a stub.
135       if (!isDecl && !GV->isWeakForLinker())
136         return false;
137     
138       // Unless we have a symbol with hidden visibility, we have to go through a
139       // normal $non_lazy_ptr stub because this symbol might be resolved late.
140       if (!GV->hasHiddenVisibility())  // Non-hidden $non_lazy_ptr reference.
141         return true;
142     }
143   }
144
145   return false;
146 }