blob: 5805cd4837f9c1e329bb3aa0ecdf1d09f42ef812 [file] [log] [blame]
Chris Lattnerce991202011-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
Eli Friedman9d434db2011-11-17 01:27:36 +000023const char* TargetLibraryInfo::StandardNames[LibFunc::NumLibFuncs] =
24 {
Chad Rosier8ff41152011-11-30 19:19:00 +000025 "acos",
26 "acosl",
27 "acosf",
28 "asin",
29 "asinl",
30 "asinf",
31 "atan",
32 "atanl",
33 "atanf",
Chad Rosier32b6c592011-12-01 17:54:37 +000034 "atan2",
35 "atan2l",
36 "atan2f",
Chad Rosier8ff41152011-11-30 19:19:00 +000037 "ceil",
38 "ceill",
39 "ceilf",
40 "cos",
41 "cosl",
42 "cosf",
43 "cosh",
44 "coshl",
45 "coshf",
46 "exp",
47 "expl",
48 "expf",
49 "exp2",
50 "exp2l",
51 "exp2f",
52 "expm1",
53 "expm1l",
54 "expl1f",
55 "fabs",
56 "fabsl",
57 "fabsf",
58 "floor",
59 "floorl",
60 "floorf",
Chad Rosier683e47b2011-11-30 01:51:49 +000061 "fiprintf",
Chad Rosier32b6c592011-12-01 17:54:37 +000062 "fmod",
63 "fmodl",
64 "fmodf",
Chad Rosier683e47b2011-11-30 01:51:49 +000065 "fputs",
66 "fwrite",
67 "iprintf",
Chad Rosier8ff41152011-11-30 19:19:00 +000068 "log",
69 "logl",
70 "logf",
71 "log2",
72 "log2l",
73 "log2f",
74 "log10",
75 "log10l",
76 "log10f",
77 "log1p",
78 "log1pl",
79 "log1pf",
Eli Friedman9d434db2011-11-17 01:27:36 +000080 "memcpy",
81 "memmove",
Chad Rosier683e47b2011-11-30 01:51:49 +000082 "memset",
Eli Friedman9d434db2011-11-17 01:27:36 +000083 "memset_pattern16",
Chad Rosier8ff41152011-11-30 19:19:00 +000084 "pow",
85 "powf",
86 "powl",
Chad Rosier32b6c592011-12-01 17:54:37 +000087 "sin",
88 "sinl",
89 "sinf",
Chad Rosierfbd828d2011-12-01 18:26:19 +000090 "sinh",
91 "sinhl",
92 "sinhf",
93 "siprintf",
Chad Rosier3d925d22011-11-29 23:57:10 +000094 "sqrt",
Chad Rosier8ff41152011-11-30 19:19:00 +000095 "sqrtl",
Chad Rosier32b6c592011-12-01 17:54:37 +000096 "sqrtf",
97 "tan",
98 "tanl",
99 "tanf",
100 "tanh",
101 "tanhl",
102 "tanhf"
Eli Friedman9d434db2011-11-17 01:27:36 +0000103 };
104
Chris Lattnerce991202011-02-18 21:50:34 +0000105/// initialize - Initialize the set of available library functions based on the
106/// specified target triple. This should be carefully written so that a missing
107/// target triple gets a sane set of defaults.
108static void initialize(TargetLibraryInfo &TLI, const Triple &T) {
109 initializeTargetLibraryInfoPass(*PassRegistry::getPassRegistry());
110
111
112 // memset_pattern16 is only available on iOS 3.0 and Mac OS/X 10.5 and later.
Daniel Dunbar558692f2011-04-20 00:14:25 +0000113 if (T.isMacOSX()) {
114 if (T.isMacOSXVersionLT(10, 5))
Daniel Dunbar13fb3b52011-04-19 20:44:08 +0000115 TLI.setUnavailable(LibFunc::memset_pattern16);
116 } else if (T.getOS() == Triple::IOS) {
117 if (T.isOSVersionLT(3, 0))
118 TLI.setUnavailable(LibFunc::memset_pattern16);
119 } else {
Chris Lattnerce991202011-02-18 21:50:34 +0000120 TLI.setUnavailable(LibFunc::memset_pattern16);
Daniel Dunbar13fb3b52011-04-19 20:44:08 +0000121 }
Richard Osborne36498242011-03-03 13:17:51 +0000122
Eli Friedman9d434db2011-11-17 01:27:36 +0000123 if (T.isMacOSX() && T.getArch() == Triple::x86 &&
124 !T.isMacOSXVersionLT(10, 7)) {
125 // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
126 // we don't care about) have two versions; on recent OSX, the one we want
127 // has a $UNIX2003 suffix. The two implementations are identical except
128 // for the return value in some edge cases. However, we don't want to
129 // generate code that depends on the old symbols.
130 TLI.setAvailableWithName(LibFunc::fwrite, "fwrite$UNIX2003");
131 TLI.setAvailableWithName(LibFunc::fputs, "fputs$UNIX2003");
132 }
133
Duncan Sands9fe88972011-06-09 11:11:45 +0000134 // iprintf and friends are only available on XCore and TCE.
135 if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) {
Richard Osborne36498242011-03-03 13:17:51 +0000136 TLI.setUnavailable(LibFunc::iprintf);
Richard Osborne419454a2011-03-03 14:09:28 +0000137 TLI.setUnavailable(LibFunc::siprintf);
Richard Osborne022708f2011-03-03 14:20:22 +0000138 TLI.setUnavailable(LibFunc::fiprintf);
Richard Osborne419454a2011-03-03 14:09:28 +0000139 }
Chris Lattnerce991202011-02-18 21:50:34 +0000140}
141
142
143TargetLibraryInfo::TargetLibraryInfo() : ImmutablePass(ID) {
144 // Default to everything being available.
145 memset(AvailableArray, -1, sizeof(AvailableArray));
146
147 initialize(*this, Triple());
148}
149
150TargetLibraryInfo::TargetLibraryInfo(const Triple &T) : ImmutablePass(ID) {
151 // Default to everything being available.
152 memset(AvailableArray, -1, sizeof(AvailableArray));
153
154 initialize(*this, T);
155}
Chris Lattner188a7e02011-02-18 22:34:03 +0000156
Chris Lattner40f5fbc2011-05-21 20:09:13 +0000157TargetLibraryInfo::TargetLibraryInfo(const TargetLibraryInfo &TLI)
158 : ImmutablePass(ID) {
159 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
Eli Friedman9d434db2011-11-17 01:27:36 +0000160 CustomNames = TLI.CustomNames;
Chris Lattner40f5fbc2011-05-21 20:09:13 +0000161}
162
163
Chris Lattner188a7e02011-02-18 22:34:03 +0000164/// disableAllFunctions - This disables all builtins, which is used for options
165/// like -fno-builtin.
166void TargetLibraryInfo::disableAllFunctions() {
167 memset(AvailableArray, 0, sizeof(AvailableArray));
168}