blob: 698e5e2115e58c3648d9bde16104d3beac764fbd [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,
Anton Korobeynikovf2e14752009-05-29 23:41:08 +000030 bool isThumb)
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)
Anton Korobeynikove7540d62009-06-01 20:00:48 +000034 , IsThumb(isThumb)
35 , 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
101 // Set CPU specific features.
102 if (CPUString == "cortex-a8") {
103 PostRAScheduler = true;
Evan Cheng11891b12009-10-16 05:33:58 +0000104 // On Cortext-a8, it's faster to perform some single-precision FP
105 // operations with NEON instructions.
David Goodwin736fed92009-10-01 22:19:57 +0000106 if (UseNEONFP.getPosition() == 0)
107 UseNEONForSinglePrecisionFP = true;
David Goodwin089aa852009-10-01 21:46:35 +0000108 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000109}
Evan Chengc2999142009-08-28 23:18:09 +0000110
111/// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol.
Evan Chengba2cf3d2009-09-03 07:04:02 +0000112bool
113ARMSubtarget::GVIsIndirectSymbol(GlobalValue *GV, Reloc::Model RelocM) const {
114 if (RelocM == Reloc::Static)
Evan Chengc2999142009-08-28 23:18:09 +0000115 return false;
Evan Chengba2cf3d2009-09-03 07:04:02 +0000116
117 // GV with ghost linkage (in JIT lazy compilation mode) do not require an
118 // extra load from stub.
119 bool isDecl = GV->isDeclaration() && !GV->hasNotBeenReadFromBitcode();
120
121 if (!isTargetDarwin()) {
122 // Extra load is needed for all externally visible.
123 if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
124 return false;
125 return true;
126 } else {
127 if (RelocM == Reloc::PIC_) {
128 // If this is a strong reference to a definition, it is definitely not
129 // through a stub.
130 if (!isDecl && !GV->isWeakForLinker())
131 return false;
132
133 // Unless we have a symbol with hidden visibility, we have to go through a
134 // normal $non_lazy_ptr stub because this symbol might be resolved late.
135 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
136 return true;
137
138 // If symbol visibility is hidden, we have a stub for common symbol
139 // references and external declarations.
140 if (isDecl || GV->hasCommonLinkage())
141 // Hidden $non_lazy_ptr reference.
142 return true;
143
144 return false;
145 } else {
146 // If this is a strong reference to a definition, it is definitely not
147 // through a stub.
148 if (!isDecl && !GV->isWeakForLinker())
149 return false;
150
151 // Unless we have a symbol with hidden visibility, we have to go through a
152 // normal $non_lazy_ptr stub because this symbol might be resolved late.
153 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
154 return true;
155 }
156 }
157
158 return false;
Evan Chengc2999142009-08-28 23:18:09 +0000159}