blob: 269958fd7f17bfd3e092aac6a42df297b03cf54f [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",
Nick Lewycky4b273cb2012-02-12 02:15:20 +0000116 "truncl",
117 "__cxa_atexit",
118 "__cxa_guard_abort",
119 "__cxa_guard_acquire",
120 "__cxa_guard_release"
Eli Friedman489c0ff2011-11-17 01:27:36 +0000121 };
122
Chris Lattner0e125bb2011-02-18 21:50:34 +0000123/// initialize - Initialize the set of available library functions based on the
124/// specified target triple. This should be carefully written so that a missing
125/// target triple gets a sane set of defaults.
126static void initialize(TargetLibraryInfo &TLI, const Triple &T) {
127 initializeTargetLibraryInfoPass(*PassRegistry::getPassRegistry());
128
129
130 // memset_pattern16 is only available on iOS 3.0 and Mac OS/X 10.5 and later.
Daniel Dunbarcd01ed52011-04-20 00:14:25 +0000131 if (T.isMacOSX()) {
132 if (T.isMacOSXVersionLT(10, 5))
Daniel Dunbar9483bb62011-04-19 20:44:08 +0000133 TLI.setUnavailable(LibFunc::memset_pattern16);
134 } else if (T.getOS() == Triple::IOS) {
135 if (T.isOSVersionLT(3, 0))
136 TLI.setUnavailable(LibFunc::memset_pattern16);
137 } else {
Chris Lattner0e125bb2011-02-18 21:50:34 +0000138 TLI.setUnavailable(LibFunc::memset_pattern16);
Daniel Dunbar9483bb62011-04-19 20:44:08 +0000139 }
Richard Osborne815de532011-03-03 13:17:51 +0000140
Eli Friedman489c0ff2011-11-17 01:27:36 +0000141 if (T.isMacOSX() && T.getArch() == Triple::x86 &&
142 !T.isMacOSXVersionLT(10, 7)) {
143 // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
144 // we don't care about) have two versions; on recent OSX, the one we want
145 // has a $UNIX2003 suffix. The two implementations are identical except
146 // for the return value in some edge cases. However, we don't want to
147 // generate code that depends on the old symbols.
148 TLI.setAvailableWithName(LibFunc::fwrite, "fwrite$UNIX2003");
149 TLI.setAvailableWithName(LibFunc::fputs, "fputs$UNIX2003");
150 }
151
Duncan Sandseeb50c82011-06-09 11:11:45 +0000152 // iprintf and friends are only available on XCore and TCE.
153 if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) {
Richard Osborne815de532011-03-03 13:17:51 +0000154 TLI.setUnavailable(LibFunc::iprintf);
Richard Osborne2dfb8882011-03-03 14:09:28 +0000155 TLI.setUnavailable(LibFunc::siprintf);
Richard Osborneaf52c522011-03-03 14:20:22 +0000156 TLI.setUnavailable(LibFunc::fiprintf);
Richard Osborne2dfb8882011-03-03 14:09:28 +0000157 }
Chris Lattner0e125bb2011-02-18 21:50:34 +0000158}
159
160
161TargetLibraryInfo::TargetLibraryInfo() : ImmutablePass(ID) {
162 // Default to everything being available.
163 memset(AvailableArray, -1, sizeof(AvailableArray));
164
165 initialize(*this, Triple());
166}
167
168TargetLibraryInfo::TargetLibraryInfo(const Triple &T) : ImmutablePass(ID) {
169 // Default to everything being available.
170 memset(AvailableArray, -1, sizeof(AvailableArray));
171
172 initialize(*this, T);
173}
Chris Lattner1341df92011-02-18 22:34:03 +0000174
Chris Lattner4c0d9e22011-05-21 20:09:13 +0000175TargetLibraryInfo::TargetLibraryInfo(const TargetLibraryInfo &TLI)
176 : ImmutablePass(ID) {
177 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
Eli Friedman489c0ff2011-11-17 01:27:36 +0000178 CustomNames = TLI.CustomNames;
Chris Lattner4c0d9e22011-05-21 20:09:13 +0000179}
180
181
Chris Lattner1341df92011-02-18 22:34:03 +0000182/// disableAllFunctions - This disables all builtins, which is used for options
183/// like -fno-builtin.
184void TargetLibraryInfo::disableAllFunctions() {
185 memset(AvailableArray, 0, sizeof(AvailableArray));
186}