blob: 2119c4ee3a2ae5aa3c391b04712735c8882d8d30 [file] [log] [blame]
Chris Lattner0e125bb2011-02-18 21:50:34 +00001//===-- TargetLibraryInfo.cpp - Runtime library information ----------------==//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the TargetLibraryInfo class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/Target/TargetLibraryInfo.h"
15#include "llvm/ADT/Triple.h"
16using namespace llvm;
17
18// Register the default implementation.
19INITIALIZE_PASS(TargetLibraryInfo, "targetlibinfo",
20 "Target Library Information", false, true)
21char TargetLibraryInfo::ID = 0;
22
David Blaikiea379b1812011-12-20 02:50:00 +000023void TargetLibraryInfo::anchor() { }
24
Eli Friedman489c0ff2011-11-17 01:27:36 +000025const char* TargetLibraryInfo::StandardNames[LibFunc::NumLibFuncs] =
26 {
Chad Rosier738da252011-11-30 19:19:00 +000027 "acos",
28 "acosl",
29 "acosf",
30 "asin",
31 "asinl",
32 "asinf",
33 "atan",
34 "atanl",
35 "atanf",
Chad Rosier10fe1fe2011-12-01 17:54:37 +000036 "atan2",
37 "atan2l",
38 "atan2f",
Chad Rosier738da252011-11-30 19:19:00 +000039 "ceil",
40 "ceill",
41 "ceilf",
Owen Andersonbb15fec2011-12-08 22:15:21 +000042 "copysign",
43 "copysignf",
44 "copysignl",
Chad Rosier738da252011-11-30 19:19:00 +000045 "cos",
46 "cosl",
47 "cosf",
48 "cosh",
49 "coshl",
50 "coshf",
51 "exp",
52 "expl",
53 "expf",
54 "exp2",
55 "exp2l",
56 "exp2f",
57 "expm1",
58 "expm1l",
59 "expl1f",
60 "fabs",
61 "fabsl",
62 "fabsf",
63 "floor",
64 "floorl",
65 "floorf",
Chad Rosierabba0942011-11-30 01:51:49 +000066 "fiprintf",
Chad Rosier10fe1fe2011-12-01 17:54:37 +000067 "fmod",
68 "fmodl",
69 "fmodf",
Chad Rosierabba0942011-11-30 01:51:49 +000070 "fputs",
71 "fwrite",
72 "iprintf",
Chad Rosier738da252011-11-30 19:19:00 +000073 "log",
74 "logl",
75 "logf",
76 "log2",
77 "log2l",
78 "log2f",
79 "log10",
80 "log10l",
81 "log10f",
82 "log1p",
83 "log1pl",
84 "log1pf",
Eli Friedman489c0ff2011-11-17 01:27:36 +000085 "memcpy",
86 "memmove",
Chad Rosierabba0942011-11-30 01:51:49 +000087 "memset",
Eli Friedman489c0ff2011-11-17 01:27:36 +000088 "memset_pattern16",
Owen Andersonbb15fec2011-12-08 22:15:21 +000089 "nearbyint",
90 "nearbyintf",
91 "nearbyintl",
Chad Rosier738da252011-11-30 19:19:00 +000092 "pow",
93 "powf",
94 "powl",
Owen Andersonbb15fec2011-12-08 22:15:21 +000095 "rint",
96 "rintf",
97 "rintl",
Chad Rosier10fe1fe2011-12-01 17:54:37 +000098 "sin",
99 "sinl",
100 "sinf",
Chad Rosier676c0932011-12-01 18:26:19 +0000101 "sinh",
102 "sinhl",
103 "sinhf",
104 "siprintf",
Chad Rosier82e1bd82011-11-29 23:57:10 +0000105 "sqrt",
Chad Rosier738da252011-11-30 19:19:00 +0000106 "sqrtl",
Chad Rosier10fe1fe2011-12-01 17:54:37 +0000107 "sqrtf",
108 "tan",
109 "tanl",
110 "tanf",
111 "tanh",
112 "tanhl",
Owen Andersonbb15fec2011-12-08 22:15:21 +0000113 "tanhf",
114 "trunc",
115 "truncf",
116 "truncl"
Eli Friedman489c0ff2011-11-17 01:27:36 +0000117 };
118
Chris Lattner0e125bb2011-02-18 21:50:34 +0000119/// initialize - Initialize the set of available library functions based on the
120/// specified target triple. This should be carefully written so that a missing
121/// target triple gets a sane set of defaults.
122static void initialize(TargetLibraryInfo &TLI, const Triple &T) {
123 initializeTargetLibraryInfoPass(*PassRegistry::getPassRegistry());
124
125
126 // memset_pattern16 is only available on iOS 3.0 and Mac OS/X 10.5 and later.
Daniel Dunbarcd01ed52011-04-20 00:14:25 +0000127 if (T.isMacOSX()) {
128 if (T.isMacOSXVersionLT(10, 5))
Daniel Dunbar9483bb62011-04-19 20:44:08 +0000129 TLI.setUnavailable(LibFunc::memset_pattern16);
130 } else if (T.getOS() == Triple::IOS) {
131 if (T.isOSVersionLT(3, 0))
132 TLI.setUnavailable(LibFunc::memset_pattern16);
133 } else {
Chris Lattner0e125bb2011-02-18 21:50:34 +0000134 TLI.setUnavailable(LibFunc::memset_pattern16);
Daniel Dunbar9483bb62011-04-19 20:44:08 +0000135 }
Richard Osborne815de532011-03-03 13:17:51 +0000136
Eli Friedman489c0ff2011-11-17 01:27:36 +0000137 if (T.isMacOSX() && T.getArch() == Triple::x86 &&
138 !T.isMacOSXVersionLT(10, 7)) {
139 // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
140 // we don't care about) have two versions; on recent OSX, the one we want
141 // has a $UNIX2003 suffix. The two implementations are identical except
142 // for the return value in some edge cases. However, we don't want to
143 // generate code that depends on the old symbols.
144 TLI.setAvailableWithName(LibFunc::fwrite, "fwrite$UNIX2003");
145 TLI.setAvailableWithName(LibFunc::fputs, "fputs$UNIX2003");
146 }
147
Duncan Sandseeb50c82011-06-09 11:11:45 +0000148 // iprintf and friends are only available on XCore and TCE.
149 if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) {
Richard Osborne815de532011-03-03 13:17:51 +0000150 TLI.setUnavailable(LibFunc::iprintf);
Richard Osborne2dfb8882011-03-03 14:09:28 +0000151 TLI.setUnavailable(LibFunc::siprintf);
Richard Osborneaf52c522011-03-03 14:20:22 +0000152 TLI.setUnavailable(LibFunc::fiprintf);
Richard Osborne2dfb8882011-03-03 14:09:28 +0000153 }
Chris Lattner0e125bb2011-02-18 21:50:34 +0000154}
155
156
157TargetLibraryInfo::TargetLibraryInfo() : ImmutablePass(ID) {
158 // Default to everything being available.
159 memset(AvailableArray, -1, sizeof(AvailableArray));
160
161 initialize(*this, Triple());
162}
163
164TargetLibraryInfo::TargetLibraryInfo(const Triple &T) : ImmutablePass(ID) {
165 // Default to everything being available.
166 memset(AvailableArray, -1, sizeof(AvailableArray));
167
168 initialize(*this, T);
169}
Chris Lattner1341df92011-02-18 22:34:03 +0000170
Chris Lattner4c0d9e22011-05-21 20:09:13 +0000171TargetLibraryInfo::TargetLibraryInfo(const TargetLibraryInfo &TLI)
172 : ImmutablePass(ID) {
173 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
Eli Friedman489c0ff2011-11-17 01:27:36 +0000174 CustomNames = TLI.CustomNames;
Chris Lattner4c0d9e22011-05-21 20:09:13 +0000175}
176
177
Chris Lattner1341df92011-02-18 22:34:03 +0000178/// disableAllFunctions - This disables all builtins, which is used for options
179/// like -fno-builtin.
180void TargetLibraryInfo::disableAllFunctions() {
181 memset(AvailableArray, 0, sizeof(AvailableArray));
182}