blob: e4396d01fedc5712e8811cf8542e20c7c41814a5 [file] [log] [blame]
Evan Chenga8e29892007-01-19 07:51:42 +00001//===-- ARMSubtarget.cpp - ARM Subtarget Information ------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Evan Chenga8e29892007-01-19 07:51:42 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the ARM specific subclass of TargetSubtarget.
11//
12//===----------------------------------------------------------------------===//
13
14#include "ARMSubtarget.h"
15#include "ARMGenSubtarget.inc"
Evan Chenge4e4ed32009-08-28 23:18:09 +000016#include "llvm/GlobalValue.h"
Anton Korobeynikov0eebf652009-06-08 22:53:56 +000017#include "llvm/Target/TargetOptions.h"
Bob Wilson54fc1242009-06-22 21:01:46 +000018#include "llvm/Support/CommandLine.h"
Evan Chenga8e29892007-01-19 07:51:42 +000019using namespace llvm;
20
Bob Wilson54fc1242009-06-22 21:01:46 +000021static cl::opt<bool>
22ReserveR9("arm-reserve-r9", cl::Hidden,
23 cl::desc("Reserve R9, making it unavailable as GPR"));
David Goodwin9843a932009-10-01 22:19:57 +000024static cl::opt<bool>
25UseNEONFP("arm-use-neon-fp",
26 cl::desc("Use NEON for single-precision FP"),
27 cl::init(false), cl::Hidden);
Bob Wilson54fc1242009-06-22 21:01:46 +000028
Daniel Dunbar3be03402009-08-02 22:11:08 +000029ARMSubtarget::ARMSubtarget(const std::string &TT, const std::string &FS,
Evan Chengd3dd50f2009-10-16 06:11:08 +000030 bool isT)
Evan Cheng1a3771e2007-01-19 19:22:40 +000031 : ARMArchVersion(V4T)
Anton Korobeynikov6d7d2aa2009-05-23 19:51:43 +000032 , ARMFPUType(None)
David Goodwin9843a932009-10-01 22:19:57 +000033 , UseNEONForSinglePrecisionFP(UseNEONFP)
Evan Chengd3dd50f2009-10-16 06:11:08 +000034 , IsThumb(isT)
Anton Korobeynikov70459be2009-06-01 20:00:48 +000035 , ThumbMode(Thumb1)
David Goodwin0dad89f2009-09-30 00:10:16 +000036 , PostRAScheduler(false)
Bob Wilson54fc1242009-06-22 21:01:46 +000037 , IsR9Reserved(ReserveR9)
Lauro Ramos Venancio3630e782007-02-13 19:52:28 +000038 , stackAlignment(4)
Anton Korobeynikov41a02432009-05-23 19:50:50 +000039 , CPUString("generic")
Lauro Ramos Venancio3630e782007-02-13 19:52:28 +000040 , TargetType(isELF) // Default to ELF unless otherwise specified.
41 , TargetABI(ARM_ABI_APCS) {
Anton Korobeynikov0eebf652009-06-08 22:53:56 +000042 // default to soft float ABI
43 if (FloatABIType == FloatABI::Default)
44 FloatABIType = FloatABI::Soft;
45
Evan Chenga8e29892007-01-19 07:51:42 +000046 // Determine default and user specified characteristics
Evan Chenga8e29892007-01-19 07:51:42 +000047
48 // Parse features string.
Anton Korobeynikov41a02432009-05-23 19:50:50 +000049 CPUString = ParseSubtargetFeatures(FS, CPUString);
Evan Chenga8e29892007-01-19 07:51:42 +000050
Evan Chenga8e29892007-01-19 07:51:42 +000051 // Set the boolean corresponding to the current target triple, or the default
52 // if one cannot be determined, to true.
Evan Cheng4b174742009-03-08 04:02:49 +000053 unsigned Len = TT.length();
Evan Cheng8c6b9912009-03-09 20:25:39 +000054 unsigned Idx = 0;
Anton Korobeynikovd4022c32009-05-29 23:41:08 +000055
Evan Cheng8c6b9912009-03-09 20:25:39 +000056 if (Len >= 5 && TT.substr(0, 4) == "armv")
57 Idx = 4;
Bob Wilson9170ab62009-06-22 21:28:22 +000058 else if (Len >= 6 && TT.substr(0, 5) == "thumb") {
Anton Korobeynikov70459be2009-06-01 20:00:48 +000059 IsThumb = true;
Evan Cheng8c6b9912009-03-09 20:25:39 +000060 if (Len >= 7 && TT[5] == 'v')
61 Idx = 6;
62 }
63 if (Idx) {
64 unsigned SubVer = TT[Idx];
65 if (SubVer > '4' && SubVer <= '9') {
Bob Wilson9170ab62009-06-22 21:28:22 +000066 if (SubVer >= '7') {
Anton Korobeynikovd4022c32009-05-29 23:41:08 +000067 ARMArchVersion = V7A;
Bob Wilson9170ab62009-06-22 21:28:22 +000068 } else if (SubVer == '6') {
Evan Cheng8c6b9912009-03-09 20:25:39 +000069 ARMArchVersion = V6;
Bob Wilson9170ab62009-06-22 21:28:22 +000070 if (Len >= Idx+3 && TT[Idx+1] == 't' && TT[Idx+2] == '2')
71 ARMArchVersion = V6T2;
72 } else if (SubVer == '5') {
Evan Cheng8c6b9912009-03-09 20:25:39 +000073 ARMArchVersion = V5T;
74 if (Len >= Idx+3 && TT[Idx+1] == 't' && TT[Idx+2] == 'e')
75 ARMArchVersion = V5TE;
Evan Cheng4b174742009-03-08 04:02:49 +000076 }
Bob Wilson9170ab62009-06-22 21:28:22 +000077 if (ARMArchVersion >= V6T2)
78 ThumbMode = Thumb2;
Evan Cheng4b174742009-03-08 04:02:49 +000079 }
80 }
81
Evan Chengb6207242009-08-01 00:16:10 +000082 // Thumb2 implies at least V6T2.
83 if (ARMArchVersion < V6T2 && ThumbMode >= Thumb2)
84 ARMArchVersion = V6T2;
85
Evan Cheng8c6b9912009-03-09 20:25:39 +000086 if (Len >= 10) {
Evan Cheng1a3771e2007-01-19 19:22:40 +000087 if (TT.find("-darwin") != std::string::npos)
Evan Cheng8c6b9912009-03-09 20:25:39 +000088 // arm-darwin
Evan Cheng1a3771e2007-01-19 19:22:40 +000089 TargetType = isDarwin;
Evan Chenga8e29892007-01-19 07:51:42 +000090 }
91
Lauro Ramos Venancio3630e782007-02-13 19:52:28 +000092 if (TT.find("eabi") != std::string::npos)
93 TargetABI = ARM_ABI_AAPCS;
94
95 if (isAAPCS_ABI())
96 stackAlignment = 8;
97
Evan Chengcd828612009-06-18 23:14:30 +000098 if (isTargetDarwin())
Bob Wilson54fc1242009-06-22 21:01:46 +000099 IsR9Reserved = ReserveR9 | (ARMArchVersion < V6);
David Goodwin471850a2009-10-01 21:46:35 +0000100
Evan Chengd3dd50f2009-10-16 06:11:08 +0000101 if (!isThumb() || hasThumb2())
102 PostRAScheduler = true;
103
David Goodwin471850a2009-10-01 21:46:35 +0000104 // Set CPU specific features.
105 if (CPUString == "cortex-a8") {
Evan Chengfee0c102009-10-16 05:33:58 +0000106 // On Cortext-a8, it's faster to perform some single-precision FP
107 // operations with NEON instructions.
David Goodwin9843a932009-10-01 22:19:57 +0000108 if (UseNEONFP.getPosition() == 0)
109 UseNEONForSinglePrecisionFP = true;
David Goodwin471850a2009-10-01 21:46:35 +0000110 }
Evan Chenga8e29892007-01-19 07:51:42 +0000111}
Evan Chenge4e4ed32009-08-28 23:18:09 +0000112
113/// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol.
Evan Cheng63476a82009-09-03 07:04:02 +0000114bool
115ARMSubtarget::GVIsIndirectSymbol(GlobalValue *GV, Reloc::Model RelocM) const {
116 if (RelocM == Reloc::Static)
Evan Chenge4e4ed32009-08-28 23:18:09 +0000117 return false;
Evan Cheng63476a82009-09-03 07:04:02 +0000118
119 // GV with ghost linkage (in JIT lazy compilation mode) do not require an
120 // extra load from stub.
121 bool isDecl = GV->isDeclaration() && !GV->hasNotBeenReadFromBitcode();
122
123 if (!isTargetDarwin()) {
124 // Extra load is needed for all externally visible.
125 if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
126 return false;
127 return true;
128 } else {
129 if (RelocM == Reloc::PIC_) {
130 // If this is a strong reference to a definition, it is definitely not
131 // through a stub.
132 if (!isDecl && !GV->isWeakForLinker())
133 return false;
134
135 // Unless we have a symbol with hidden visibility, we have to go through a
136 // normal $non_lazy_ptr stub because this symbol might be resolved late.
137 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
138 return true;
139
140 // If symbol visibility is hidden, we have a stub for common symbol
141 // references and external declarations.
142 if (isDecl || GV->hasCommonLinkage())
143 // Hidden $non_lazy_ptr reference.
144 return true;
145
146 return false;
147 } else {
148 // If this is a strong reference to a definition, it is definitely not
149 // through a stub.
150 if (!isDecl && !GV->isWeakForLinker())
151 return false;
152
153 // Unless we have a symbol with hidden visibility, we have to go through a
154 // normal $non_lazy_ptr stub because this symbol might be resolved late.
155 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
156 return true;
157 }
158 }
159
160 return false;
Evan Chenge4e4ed32009-08-28 23:18:09 +0000161}