blob: 5af95c33b930c4402529feda94884a7eab7a491b [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- ARMSubtarget.cpp - ARM Subtarget Information ------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +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 Chengc2999142009-08-28 23:18:09 +000016#include "llvm/GlobalValue.h"
Anton Korobeynikov11713322009-06-08 22:53:56 +000017#include "llvm/Target/TargetOptions.h"
Bob Wilson243b37c2009-06-22 21:01:46 +000018#include "llvm/Support/CommandLine.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000019using namespace llvm;
20
Bob Wilson243b37c2009-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 Goodwin736fed92009-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 Wilson243b37c2009-06-22 21:01:46 +000028
Daniel Dunbarb711cf02009-08-02 22:11:08 +000029ARMSubtarget::ARMSubtarget(const std::string &TT, const std::string &FS,
Evan Chengcae7b0e2009-10-16 06:11:08 +000030 bool isT)
Dan Gohmanf17a25c2007-07-18 16:29:46 +000031 : ARMArchVersion(V4T)
Anton Korobeynikov1bf0f082009-05-23 19:51:43 +000032 , ARMFPUType(None)
David Goodwin736fed92009-10-01 22:19:57 +000033 , UseNEONForSinglePrecisionFP(UseNEONFP)
Evan Chengcae7b0e2009-10-16 06:11:08 +000034 , IsThumb(isT)
Anton Korobeynikove7540d62009-06-01 20:00:48 +000035 , ThumbMode(Thumb1)
David Goodwincf89a602009-09-30 00:10:16 +000036 , PostRAScheduler(false)
Bob Wilson243b37c2009-06-22 21:01:46 +000037 , IsR9Reserved(ReserveR9)
Dan Gohmanf17a25c2007-07-18 16:29:46 +000038 , stackAlignment(4)
Anton Korobeynikov7357d8f2009-05-23 19:50:50 +000039 , CPUString("generic")
Dan Gohmanf17a25c2007-07-18 16:29:46 +000040 , TargetType(isELF) // Default to ELF unless otherwise specified.
41 , TargetABI(ARM_ABI_APCS) {
Anton Korobeynikov11713322009-06-08 22:53:56 +000042 // default to soft float ABI
43 if (FloatABIType == FloatABI::Default)
44 FloatABIType = FloatABI::Soft;
45
Dan Gohmanf17a25c2007-07-18 16:29:46 +000046 // Determine default and user specified characteristics
Dan Gohmanf17a25c2007-07-18 16:29:46 +000047
48 // Parse features string.
Anton Korobeynikov7357d8f2009-05-23 19:50:50 +000049 CPUString = ParseSubtargetFeatures(FS, CPUString);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000050
51 // Set the boolean corresponding to the current target triple, or the default
52 // if one cannot be determined, to true.
Evan Chengac1f7792009-03-08 04:02:49 +000053 unsigned Len = TT.length();
Evan Chenga5de2fc2009-03-09 20:25:39 +000054 unsigned Idx = 0;
Anton Korobeynikovf2e14752009-05-29 23:41:08 +000055
Evan Chenga5de2fc2009-03-09 20:25:39 +000056 if (Len >= 5 && TT.substr(0, 4) == "armv")
57 Idx = 4;
Bob Wilson801d50b2009-06-22 21:28:22 +000058 else if (Len >= 6 && TT.substr(0, 5) == "thumb") {
Anton Korobeynikove7540d62009-06-01 20:00:48 +000059 IsThumb = true;
Evan Chenga5de2fc2009-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 Wilson801d50b2009-06-22 21:28:22 +000066 if (SubVer >= '7') {
Anton Korobeynikovf2e14752009-05-29 23:41:08 +000067 ARMArchVersion = V7A;
Bob Wilson801d50b2009-06-22 21:28:22 +000068 } else if (SubVer == '6') {
Evan Chenga5de2fc2009-03-09 20:25:39 +000069 ARMArchVersion = V6;
Bob Wilson801d50b2009-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 Chenga5de2fc2009-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 Chengac1f7792009-03-08 04:02:49 +000076 }
Bob Wilson801d50b2009-06-22 21:28:22 +000077 if (ARMArchVersion >= V6T2)
78 ThumbMode = Thumb2;
Evan Chengac1f7792009-03-08 04:02:49 +000079 }
80 }
81
Evan Cheng68e4b582009-08-01 00:16:10 +000082 // Thumb2 implies at least V6T2.
83 if (ARMArchVersion < V6T2 && ThumbMode >= Thumb2)
84 ARMArchVersion = V6T2;
85
Evan Chenga5de2fc2009-03-09 20:25:39 +000086 if (Len >= 10) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000087 if (TT.find("-darwin") != std::string::npos)
Evan Chenga5de2fc2009-03-09 20:25:39 +000088 // arm-darwin
Dan Gohmanf17a25c2007-07-18 16:29:46 +000089 TargetType = isDarwin;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000090 }
91
92 if (TT.find("eabi") != std::string::npos)
93 TargetABI = ARM_ABI_AAPCS;
94
95 if (isAAPCS_ABI())
96 stackAlignment = 8;
97
Evan Cheng9ecae172009-06-18 23:14:30 +000098 if (isTargetDarwin())
Bob Wilson243b37c2009-06-22 21:01:46 +000099 IsR9Reserved = ReserveR9 | (ARMArchVersion < V6);
David Goodwin089aa852009-10-01 21:46:35 +0000100
Evan Chengcae7b0e2009-10-16 06:11:08 +0000101 if (!isThumb() || hasThumb2())
102 PostRAScheduler = true;
103
David Goodwin089aa852009-10-01 21:46:35 +0000104 // Set CPU specific features.
105 if (CPUString == "cortex-a8") {
Evan Cheng1302f572009-10-16 06:18:09 +0000106 // On Cortex-a8, it's faster to perform some single-precision FP
Evan Cheng11891b12009-10-16 05:33:58 +0000107 // operations with NEON instructions.
David Goodwin736fed92009-10-01 22:19:57 +0000108 if (UseNEONFP.getPosition() == 0)
109 UseNEONForSinglePrecisionFP = true;
David Goodwin089aa852009-10-01 21:46:35 +0000110 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000111}
Evan Chengc2999142009-08-28 23:18:09 +0000112
113/// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol.
Evan Chengba2cf3d2009-09-03 07:04:02 +0000114bool
115ARMSubtarget::GVIsIndirectSymbol(GlobalValue *GV, Reloc::Model RelocM) const {
116 if (RelocM == Reloc::Static)
Evan Chengc2999142009-08-28 23:18:09 +0000117 return false;
Evan Chengba2cf3d2009-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 Chengc2999142009-08-28 23:18:09 +0000161}