blob: dc813289e73bf623a0811d0eac34a9fb2d4ede32 [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"
David Goodwin2a0ca3b2009-11-10 00:48:55 +000019#include "llvm/ADT/SmallVector.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000020using namespace llvm;
21
Bob Wilson243b37c2009-06-22 21:01:46 +000022static cl::opt<bool>
23ReserveR9("arm-reserve-r9", cl::Hidden,
24 cl::desc("Reserve R9, making it unavailable as GPR"));
David Goodwin736fed92009-10-01 22:19:57 +000025static cl::opt<bool>
26UseNEONFP("arm-use-neon-fp",
27 cl::desc("Use NEON for single-precision FP"),
28 cl::init(false), cl::Hidden);
Bob Wilson243b37c2009-06-22 21:01:46 +000029
Daniel Dunbarb711cf02009-08-02 22:11:08 +000030ARMSubtarget::ARMSubtarget(const std::string &TT, const std::string &FS,
Evan Chengcae7b0e2009-10-16 06:11:08 +000031 bool isT)
Dan Gohmanf17a25c2007-07-18 16:29:46 +000032 : ARMArchVersion(V4T)
Anton Korobeynikov1bf0f082009-05-23 19:51:43 +000033 , ARMFPUType(None)
David Goodwin736fed92009-10-01 22:19:57 +000034 , UseNEONForSinglePrecisionFP(UseNEONFP)
Evan Chengcae7b0e2009-10-16 06:11:08 +000035 , IsThumb(isT)
Anton Korobeynikove7540d62009-06-01 20:00:48 +000036 , ThumbMode(Thumb1)
David Goodwincf89a602009-09-30 00:10:16 +000037 , PostRAScheduler(false)
Bob Wilson243b37c2009-06-22 21:01:46 +000038 , IsR9Reserved(ReserveR9)
Dan Gohmanf17a25c2007-07-18 16:29:46 +000039 , stackAlignment(4)
Anton Korobeynikov7357d8f2009-05-23 19:50:50 +000040 , CPUString("generic")
Dan Gohmanf17a25c2007-07-18 16:29:46 +000041 , TargetType(isELF) // Default to ELF unless otherwise specified.
42 , TargetABI(ARM_ABI_APCS) {
Anton Korobeynikov11713322009-06-08 22:53:56 +000043 // default to soft float ABI
44 if (FloatABIType == FloatABI::Default)
45 FloatABIType = FloatABI::Soft;
46
Dan Gohmanf17a25c2007-07-18 16:29:46 +000047 // Determine default and user specified characteristics
Dan Gohmanf17a25c2007-07-18 16:29:46 +000048
49 // Parse features string.
Anton Korobeynikov7357d8f2009-05-23 19:50:50 +000050 CPUString = ParseSubtargetFeatures(FS, CPUString);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000051
52 // Set the boolean corresponding to the current target triple, or the default
53 // if one cannot be determined, to true.
Evan Chengac1f7792009-03-08 04:02:49 +000054 unsigned Len = TT.length();
Evan Chenga5de2fc2009-03-09 20:25:39 +000055 unsigned Idx = 0;
Anton Korobeynikovf2e14752009-05-29 23:41:08 +000056
Evan Chenga5de2fc2009-03-09 20:25:39 +000057 if (Len >= 5 && TT.substr(0, 4) == "armv")
58 Idx = 4;
Bob Wilson801d50b2009-06-22 21:28:22 +000059 else if (Len >= 6 && TT.substr(0, 5) == "thumb") {
Anton Korobeynikove7540d62009-06-01 20:00:48 +000060 IsThumb = true;
Evan Chenga5de2fc2009-03-09 20:25:39 +000061 if (Len >= 7 && TT[5] == 'v')
62 Idx = 6;
63 }
64 if (Idx) {
65 unsigned SubVer = TT[Idx];
66 if (SubVer > '4' && SubVer <= '9') {
Bob Wilson801d50b2009-06-22 21:28:22 +000067 if (SubVer >= '7') {
Anton Korobeynikovf2e14752009-05-29 23:41:08 +000068 ARMArchVersion = V7A;
Bob Wilson801d50b2009-06-22 21:28:22 +000069 } else if (SubVer == '6') {
Evan Chenga5de2fc2009-03-09 20:25:39 +000070 ARMArchVersion = V6;
Bob Wilson801d50b2009-06-22 21:28:22 +000071 if (Len >= Idx+3 && TT[Idx+1] == 't' && TT[Idx+2] == '2')
72 ARMArchVersion = V6T2;
73 } else if (SubVer == '5') {
Evan Chenga5de2fc2009-03-09 20:25:39 +000074 ARMArchVersion = V5T;
75 if (Len >= Idx+3 && TT[Idx+1] == 't' && TT[Idx+2] == 'e')
76 ARMArchVersion = V5TE;
Evan Chengac1f7792009-03-08 04:02:49 +000077 }
Bob Wilson801d50b2009-06-22 21:28:22 +000078 if (ARMArchVersion >= V6T2)
79 ThumbMode = Thumb2;
Evan Chengac1f7792009-03-08 04:02:49 +000080 }
81 }
82
Evan Cheng68e4b582009-08-01 00:16:10 +000083 // Thumb2 implies at least V6T2.
84 if (ARMArchVersion < V6T2 && ThumbMode >= Thumb2)
85 ARMArchVersion = V6T2;
86
Evan Chenga5de2fc2009-03-09 20:25:39 +000087 if (Len >= 10) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000088 if (TT.find("-darwin") != std::string::npos)
Evan Chenga5de2fc2009-03-09 20:25:39 +000089 // arm-darwin
Dan Gohmanf17a25c2007-07-18 16:29:46 +000090 TargetType = isDarwin;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000091 }
92
93 if (TT.find("eabi") != std::string::npos)
94 TargetABI = ARM_ABI_AAPCS;
95
96 if (isAAPCS_ABI())
97 stackAlignment = 8;
98
Evan Cheng9ecae172009-06-18 23:14:30 +000099 if (isTargetDarwin())
Bob Wilson243b37c2009-06-22 21:01:46 +0000100 IsR9Reserved = ReserveR9 | (ARMArchVersion < V6);
David Goodwin089aa852009-10-01 21:46:35 +0000101
Evan Chengcae7b0e2009-10-16 06:11:08 +0000102 if (!isThumb() || hasThumb2())
103 PostRAScheduler = true;
104
David Goodwin089aa852009-10-01 21:46:35 +0000105 // Set CPU specific features.
106 if (CPUString == "cortex-a8") {
Evan Cheng1302f572009-10-16 06:18:09 +0000107 // On Cortex-a8, it's faster to perform some single-precision FP
Evan Cheng11891b12009-10-16 05:33:58 +0000108 // operations with NEON instructions.
David Goodwin736fed92009-10-01 22:19:57 +0000109 if (UseNEONFP.getPosition() == 0)
110 UseNEONForSinglePrecisionFP = true;
David Goodwin089aa852009-10-01 21:46:35 +0000111 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000112}
Evan Chengc2999142009-08-28 23:18:09 +0000113
114/// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol.
Evan Chengba2cf3d2009-09-03 07:04:02 +0000115bool
116ARMSubtarget::GVIsIndirectSymbol(GlobalValue *GV, Reloc::Model RelocM) const {
117 if (RelocM == Reloc::Static)
Evan Chengc2999142009-08-28 23:18:09 +0000118 return false;
Evan Chengba2cf3d2009-09-03 07:04:02 +0000119
120 // GV with ghost linkage (in JIT lazy compilation mode) do not require an
121 // extra load from stub.
122 bool isDecl = GV->isDeclaration() && !GV->hasNotBeenReadFromBitcode();
123
124 if (!isTargetDarwin()) {
125 // Extra load is needed for all externally visible.
126 if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
127 return false;
128 return true;
129 } else {
130 if (RelocM == Reloc::PIC_) {
131 // If this is a strong reference to a definition, it is definitely not
132 // through a stub.
133 if (!isDecl && !GV->isWeakForLinker())
134 return false;
135
136 // Unless we have a symbol with hidden visibility, we have to go through a
137 // normal $non_lazy_ptr stub because this symbol might be resolved late.
138 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
139 return true;
140
141 // If symbol visibility is hidden, we have a stub for common symbol
142 // references and external declarations.
143 if (isDecl || GV->hasCommonLinkage())
144 // Hidden $non_lazy_ptr reference.
145 return true;
146
147 return false;
148 } else {
149 // If this is a strong reference to a definition, it is definitely not
150 // through a stub.
151 if (!isDecl && !GV->isWeakForLinker())
152 return false;
153
154 // Unless we have a symbol with hidden visibility, we have to go through a
155 // normal $non_lazy_ptr stub because this symbol might be resolved late.
156 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
157 return true;
158 }
159 }
160
161 return false;
Evan Chengc2999142009-08-28 23:18:09 +0000162}
David Goodwin2a0ca3b2009-11-10 00:48:55 +0000163
164bool ARMSubtarget::enablePostRAScheduler(
165 CodeGenOpt::Level OptLevel,
166 TargetSubtarget::AntiDepBreakMode& Mode,
167 ExcludedRCVector& ExcludedRCs) const {
168 Mode = TargetSubtarget::ANTIDEP_CRITICAL;
169 ExcludedRCs.clear();
170 ExcludedRCs.push_back(&ARM::GPRRegClass);
171 return PostRAScheduler && OptLevel >= CodeGenOpt::Default;
172}