blob: 704cf7abfb387bed4ce0bbcf2927b4b71230d6d7 [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"));
24
Daniel Dunbar3be03402009-08-02 22:11:08 +000025ARMSubtarget::ARMSubtarget(const std::string &TT, const std::string &FS,
Anton Korobeynikovd4022c32009-05-29 23:41:08 +000026 bool isThumb)
Evan Cheng1a3771e2007-01-19 19:22:40 +000027 : ARMArchVersion(V4T)
Anton Korobeynikov6d7d2aa2009-05-23 19:51:43 +000028 , ARMFPUType(None)
David Goodwin42a83f22009-08-04 17:53:06 +000029 , UseNEONForSinglePrecisionFP(false)
Anton Korobeynikov70459be2009-06-01 20:00:48 +000030 , IsThumb(isThumb)
31 , ThumbMode(Thumb1)
David Goodwin0dad89f2009-09-30 00:10:16 +000032 , PostRAScheduler(false)
Bob Wilson54fc1242009-06-22 21:01:46 +000033 , IsR9Reserved(ReserveR9)
Lauro Ramos Venancio3630e782007-02-13 19:52:28 +000034 , stackAlignment(4)
Anton Korobeynikov41a02432009-05-23 19:50:50 +000035 , CPUString("generic")
Lauro Ramos Venancio3630e782007-02-13 19:52:28 +000036 , TargetType(isELF) // Default to ELF unless otherwise specified.
37 , TargetABI(ARM_ABI_APCS) {
Anton Korobeynikov0eebf652009-06-08 22:53:56 +000038 // default to soft float ABI
39 if (FloatABIType == FloatABI::Default)
40 FloatABIType = FloatABI::Soft;
41
Evan Chenga8e29892007-01-19 07:51:42 +000042 // Determine default and user specified characteristics
Evan Chenga8e29892007-01-19 07:51:42 +000043
44 // Parse features string.
Anton Korobeynikov41a02432009-05-23 19:50:50 +000045 CPUString = ParseSubtargetFeatures(FS, CPUString);
Evan Chenga8e29892007-01-19 07:51:42 +000046
Evan Chenga8e29892007-01-19 07:51:42 +000047 // Set the boolean corresponding to the current target triple, or the default
48 // if one cannot be determined, to true.
Evan Cheng4b174742009-03-08 04:02:49 +000049 unsigned Len = TT.length();
Evan Cheng8c6b9912009-03-09 20:25:39 +000050 unsigned Idx = 0;
Anton Korobeynikovd4022c32009-05-29 23:41:08 +000051
Evan Cheng8c6b9912009-03-09 20:25:39 +000052 if (Len >= 5 && TT.substr(0, 4) == "armv")
53 Idx = 4;
Bob Wilson9170ab62009-06-22 21:28:22 +000054 else if (Len >= 6 && TT.substr(0, 5) == "thumb") {
Anton Korobeynikov70459be2009-06-01 20:00:48 +000055 IsThumb = true;
Evan Cheng8c6b9912009-03-09 20:25:39 +000056 if (Len >= 7 && TT[5] == 'v')
57 Idx = 6;
58 }
59 if (Idx) {
60 unsigned SubVer = TT[Idx];
61 if (SubVer > '4' && SubVer <= '9') {
Bob Wilson9170ab62009-06-22 21:28:22 +000062 if (SubVer >= '7') {
Anton Korobeynikovd4022c32009-05-29 23:41:08 +000063 ARMArchVersion = V7A;
Bob Wilson9170ab62009-06-22 21:28:22 +000064 } else if (SubVer == '6') {
Evan Cheng8c6b9912009-03-09 20:25:39 +000065 ARMArchVersion = V6;
Bob Wilson9170ab62009-06-22 21:28:22 +000066 if (Len >= Idx+3 && TT[Idx+1] == 't' && TT[Idx+2] == '2')
67 ARMArchVersion = V6T2;
68 } else if (SubVer == '5') {
Evan Cheng8c6b9912009-03-09 20:25:39 +000069 ARMArchVersion = V5T;
70 if (Len >= Idx+3 && TT[Idx+1] == 't' && TT[Idx+2] == 'e')
71 ARMArchVersion = V5TE;
Evan Cheng4b174742009-03-08 04:02:49 +000072 }
Bob Wilson9170ab62009-06-22 21:28:22 +000073 if (ARMArchVersion >= V6T2)
74 ThumbMode = Thumb2;
Evan Cheng4b174742009-03-08 04:02:49 +000075 }
76 }
77
Evan Chengb6207242009-08-01 00:16:10 +000078 // Thumb2 implies at least V6T2.
79 if (ARMArchVersion < V6T2 && ThumbMode >= Thumb2)
80 ARMArchVersion = V6T2;
81
Evan Cheng8c6b9912009-03-09 20:25:39 +000082 if (Len >= 10) {
Evan Cheng1a3771e2007-01-19 19:22:40 +000083 if (TT.find("-darwin") != std::string::npos)
Evan Cheng8c6b9912009-03-09 20:25:39 +000084 // arm-darwin
Evan Cheng1a3771e2007-01-19 19:22:40 +000085 TargetType = isDarwin;
Evan Chenga8e29892007-01-19 07:51:42 +000086 }
87
Lauro Ramos Venancio3630e782007-02-13 19:52:28 +000088 if (TT.find("eabi") != std::string::npos)
89 TargetABI = ARM_ABI_AAPCS;
90
91 if (isAAPCS_ABI())
92 stackAlignment = 8;
93
Evan Chengcd828612009-06-18 23:14:30 +000094 if (isTargetDarwin())
Bob Wilson54fc1242009-06-22 21:01:46 +000095 IsR9Reserved = ReserveR9 | (ARMArchVersion < V6);
David Goodwin471850a2009-10-01 21:46:35 +000096
97 // Set CPU specific features.
98 if (CPUString == "cortex-a8") {
99 PostRAScheduler = true;
100 }
Evan Chenga8e29892007-01-19 07:51:42 +0000101}
Evan Chenge4e4ed32009-08-28 23:18:09 +0000102
103/// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol.
Evan Cheng63476a82009-09-03 07:04:02 +0000104bool
105ARMSubtarget::GVIsIndirectSymbol(GlobalValue *GV, Reloc::Model RelocM) const {
106 if (RelocM == Reloc::Static)
Evan Chenge4e4ed32009-08-28 23:18:09 +0000107 return false;
Evan Cheng63476a82009-09-03 07:04:02 +0000108
109 // GV with ghost linkage (in JIT lazy compilation mode) do not require an
110 // extra load from stub.
111 bool isDecl = GV->isDeclaration() && !GV->hasNotBeenReadFromBitcode();
112
113 if (!isTargetDarwin()) {
114 // Extra load is needed for all externally visible.
115 if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
116 return false;
117 return true;
118 } else {
119 if (RelocM == Reloc::PIC_) {
120 // If this is a strong reference to a definition, it is definitely not
121 // through a stub.
122 if (!isDecl && !GV->isWeakForLinker())
123 return false;
124
125 // Unless we have a symbol with hidden visibility, we have to go through a
126 // normal $non_lazy_ptr stub because this symbol might be resolved late.
127 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
128 return true;
129
130 // If symbol visibility is hidden, we have a stub for common symbol
131 // references and external declarations.
132 if (isDecl || GV->hasCommonLinkage())
133 // Hidden $non_lazy_ptr reference.
134 return true;
135
136 return false;
137 } else {
138 // If this is a strong reference to a definition, it is definitely not
139 // through a stub.
140 if (!isDecl && !GV->isWeakForLinker())
141 return false;
142
143 // Unless we have a symbol with hidden visibility, we have to go through a
144 // normal $non_lazy_ptr stub because this symbol might be resolved late.
145 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
146 return true;
147 }
148 }
149
150 return false;
Evan Chenge4e4ed32009-08-28 23:18:09 +0000151}