blob: f5723ea5618e60abef1ce6d5aa4b42f19c9384c4 [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"));
24
Daniel Dunbarb711cf02009-08-02 22:11:08 +000025ARMSubtarget::ARMSubtarget(const std::string &TT, const std::string &FS,
Anton Korobeynikovf2e14752009-05-29 23:41:08 +000026 bool isThumb)
Dan Gohmanf17a25c2007-07-18 16:29:46 +000027 : ARMArchVersion(V4T)
Anton Korobeynikov1bf0f082009-05-23 19:51:43 +000028 , ARMFPUType(None)
David Goodwindd19ce42009-08-04 17:53:06 +000029 , UseNEONForSinglePrecisionFP(false)
Anton Korobeynikove7540d62009-06-01 20:00:48 +000030 , IsThumb(isThumb)
31 , ThumbMode(Thumb1)
Bob Wilson243b37c2009-06-22 21:01:46 +000032 , IsR9Reserved(ReserveR9)
Dan Gohmanf17a25c2007-07-18 16:29:46 +000033 , stackAlignment(4)
Anton Korobeynikov7357d8f2009-05-23 19:50:50 +000034 , CPUString("generic")
Dan Gohmanf17a25c2007-07-18 16:29:46 +000035 , TargetType(isELF) // Default to ELF unless otherwise specified.
36 , TargetABI(ARM_ABI_APCS) {
Anton Korobeynikov11713322009-06-08 22:53:56 +000037 // default to soft float ABI
38 if (FloatABIType == FloatABI::Default)
39 FloatABIType = FloatABI::Soft;
40
Dan Gohmanf17a25c2007-07-18 16:29:46 +000041 // Determine default and user specified characteristics
Dan Gohmanf17a25c2007-07-18 16:29:46 +000042
43 // Parse features string.
Anton Korobeynikov7357d8f2009-05-23 19:50:50 +000044 CPUString = ParseSubtargetFeatures(FS, CPUString);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000045
46 // Set the boolean corresponding to the current target triple, or the default
47 // if one cannot be determined, to true.
Evan Chengac1f7792009-03-08 04:02:49 +000048 unsigned Len = TT.length();
Evan Chenga5de2fc2009-03-09 20:25:39 +000049 unsigned Idx = 0;
Anton Korobeynikovf2e14752009-05-29 23:41:08 +000050
Evan Chenga5de2fc2009-03-09 20:25:39 +000051 if (Len >= 5 && TT.substr(0, 4) == "armv")
52 Idx = 4;
Bob Wilson801d50b2009-06-22 21:28:22 +000053 else if (Len >= 6 && TT.substr(0, 5) == "thumb") {
Anton Korobeynikove7540d62009-06-01 20:00:48 +000054 IsThumb = true;
Evan Chenga5de2fc2009-03-09 20:25:39 +000055 if (Len >= 7 && TT[5] == 'v')
56 Idx = 6;
57 }
58 if (Idx) {
59 unsigned SubVer = TT[Idx];
60 if (SubVer > '4' && SubVer <= '9') {
Bob Wilson801d50b2009-06-22 21:28:22 +000061 if (SubVer >= '7') {
Anton Korobeynikovf2e14752009-05-29 23:41:08 +000062 ARMArchVersion = V7A;
Bob Wilson801d50b2009-06-22 21:28:22 +000063 } else if (SubVer == '6') {
Evan Chenga5de2fc2009-03-09 20:25:39 +000064 ARMArchVersion = V6;
Bob Wilson801d50b2009-06-22 21:28:22 +000065 if (Len >= Idx+3 && TT[Idx+1] == 't' && TT[Idx+2] == '2')
66 ARMArchVersion = V6T2;
67 } else if (SubVer == '5') {
Evan Chenga5de2fc2009-03-09 20:25:39 +000068 ARMArchVersion = V5T;
69 if (Len >= Idx+3 && TT[Idx+1] == 't' && TT[Idx+2] == 'e')
70 ARMArchVersion = V5TE;
Evan Chengac1f7792009-03-08 04:02:49 +000071 }
Bob Wilson801d50b2009-06-22 21:28:22 +000072 if (ARMArchVersion >= V6T2)
73 ThumbMode = Thumb2;
Evan Chengac1f7792009-03-08 04:02:49 +000074 }
75 }
76
Evan Cheng68e4b582009-08-01 00:16:10 +000077 // Thumb2 implies at least V6T2.
78 if (ARMArchVersion < V6T2 && ThumbMode >= Thumb2)
79 ARMArchVersion = V6T2;
80
Evan Chenga5de2fc2009-03-09 20:25:39 +000081 if (Len >= 10) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000082 if (TT.find("-darwin") != std::string::npos)
Evan Chenga5de2fc2009-03-09 20:25:39 +000083 // arm-darwin
Dan Gohmanf17a25c2007-07-18 16:29:46 +000084 TargetType = isDarwin;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000085 }
86
87 if (TT.find("eabi") != std::string::npos)
88 TargetABI = ARM_ABI_AAPCS;
89
90 if (isAAPCS_ABI())
91 stackAlignment = 8;
92
Evan Cheng9ecae172009-06-18 23:14:30 +000093 if (isTargetDarwin())
Bob Wilson243b37c2009-06-22 21:01:46 +000094 IsR9Reserved = ReserveR9 | (ARMArchVersion < V6);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000095}
Evan Chengc2999142009-08-28 23:18:09 +000096
97/// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol.
Evan Chengba2cf3d2009-09-03 07:04:02 +000098bool
99ARMSubtarget::GVIsIndirectSymbol(GlobalValue *GV, Reloc::Model RelocM) const {
100 if (RelocM == Reloc::Static)
Evan Chengc2999142009-08-28 23:18:09 +0000101 return false;
Evan Chengba2cf3d2009-09-03 07:04:02 +0000102
103 // GV with ghost linkage (in JIT lazy compilation mode) do not require an
104 // extra load from stub.
105 bool isDecl = GV->isDeclaration() && !GV->hasNotBeenReadFromBitcode();
106
107 if (!isTargetDarwin()) {
108 // Extra load is needed for all externally visible.
109 if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
110 return false;
111 return true;
112 } else {
113 if (RelocM == Reloc::PIC_) {
114 // If this is a strong reference to a definition, it is definitely not
115 // through a stub.
116 if (!isDecl && !GV->isWeakForLinker())
117 return false;
118
119 // Unless we have a symbol with hidden visibility, we have to go through a
120 // normal $non_lazy_ptr stub because this symbol might be resolved late.
121 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
122 return true;
123
124 // If symbol visibility is hidden, we have a stub for common symbol
125 // references and external declarations.
126 if (isDecl || GV->hasCommonLinkage())
127 // Hidden $non_lazy_ptr reference.
128 return true;
129
130 return false;
131 } else {
132 // If this is a strong reference to a definition, it is definitely not
133 // through a stub.
134 if (!isDecl && !GV->isWeakForLinker())
135 return false;
136
137 // Unless we have a symbol with hidden visibility, we have to go through a
138 // normal $non_lazy_ptr stub because this symbol might be resolved late.
139 if (!GV->hasHiddenVisibility()) // Non-hidden $non_lazy_ptr reference.
140 return true;
141 }
142 }
143
144 return false;
Evan Chengc2999142009-08-28 23:18:09 +0000145}