blob: 0ab0d3123bde05f78c67b88ae89863a888c03d0a [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",
Eli Friedman9d434db2011-11-17 01:27:36 +000087 "siprintf",
Chad Rosier32b6c592011-12-01 17:54:37 +000088 "sin",
89 "sinl",
90 "sinf",
Chad Rosier3d925d22011-11-29 23:57:10 +000091 "sqrt",
Chad Rosier8ff41152011-11-30 19:19:00 +000092 "sqrtl",
Chad Rosier32b6c592011-12-01 17:54:37 +000093 "sqrtf",
94 "tan",
95 "tanl",
96 "tanf",
97 "tanh",
98 "tanhl",
99 "tanhf"
Eli Friedman9d434db2011-11-17 01:27:36 +0000100 };
101
Chris Lattnerce991202011-02-18 21:50:34 +0000102/// initialize - Initialize the set of available library functions based on the
103/// specified target triple. This should be carefully written so that a missing
104/// target triple gets a sane set of defaults.
105static void initialize(TargetLibraryInfo &TLI, const Triple &T) {
106 initializeTargetLibraryInfoPass(*PassRegistry::getPassRegistry());
107
108
109 // memset_pattern16 is only available on iOS 3.0 and Mac OS/X 10.5 and later.
Daniel Dunbar558692f2011-04-20 00:14:25 +0000110 if (T.isMacOSX()) {
111 if (T.isMacOSXVersionLT(10, 5))
Daniel Dunbar13fb3b52011-04-19 20:44:08 +0000112 TLI.setUnavailable(LibFunc::memset_pattern16);
113 } else if (T.getOS() == Triple::IOS) {
114 if (T.isOSVersionLT(3, 0))
115 TLI.setUnavailable(LibFunc::memset_pattern16);
116 } else {
Chris Lattnerce991202011-02-18 21:50:34 +0000117 TLI.setUnavailable(LibFunc::memset_pattern16);
Daniel Dunbar13fb3b52011-04-19 20:44:08 +0000118 }
Richard Osborne36498242011-03-03 13:17:51 +0000119
Eli Friedman9d434db2011-11-17 01:27:36 +0000120 if (T.isMacOSX() && T.getArch() == Triple::x86 &&
121 !T.isMacOSXVersionLT(10, 7)) {
122 // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
123 // we don't care about) have two versions; on recent OSX, the one we want
124 // has a $UNIX2003 suffix. The two implementations are identical except
125 // for the return value in some edge cases. However, we don't want to
126 // generate code that depends on the old symbols.
127 TLI.setAvailableWithName(LibFunc::fwrite, "fwrite$UNIX2003");
128 TLI.setAvailableWithName(LibFunc::fputs, "fputs$UNIX2003");
129 }
130
Duncan Sands9fe88972011-06-09 11:11:45 +0000131 // iprintf and friends are only available on XCore and TCE.
132 if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) {
Richard Osborne36498242011-03-03 13:17:51 +0000133 TLI.setUnavailable(LibFunc::iprintf);
Richard Osborne419454a2011-03-03 14:09:28 +0000134 TLI.setUnavailable(LibFunc::siprintf);
Richard Osborne022708f2011-03-03 14:20:22 +0000135 TLI.setUnavailable(LibFunc::fiprintf);
Richard Osborne419454a2011-03-03 14:09:28 +0000136 }
Chris Lattnerce991202011-02-18 21:50:34 +0000137}
138
139
140TargetLibraryInfo::TargetLibraryInfo() : ImmutablePass(ID) {
141 // Default to everything being available.
142 memset(AvailableArray, -1, sizeof(AvailableArray));
143
144 initialize(*this, Triple());
145}
146
147TargetLibraryInfo::TargetLibraryInfo(const Triple &T) : ImmutablePass(ID) {
148 // Default to everything being available.
149 memset(AvailableArray, -1, sizeof(AvailableArray));
150
151 initialize(*this, T);
152}
Chris Lattner188a7e02011-02-18 22:34:03 +0000153
Chris Lattner40f5fbc2011-05-21 20:09:13 +0000154TargetLibraryInfo::TargetLibraryInfo(const TargetLibraryInfo &TLI)
155 : ImmutablePass(ID) {
156 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
Eli Friedman9d434db2011-11-17 01:27:36 +0000157 CustomNames = TLI.CustomNames;
Chris Lattner40f5fbc2011-05-21 20:09:13 +0000158}
159
160
Chris Lattner188a7e02011-02-18 22:34:03 +0000161/// disableAllFunctions - This disables all builtins, which is used for options
162/// like -fno-builtin.
163void TargetLibraryInfo::disableAllFunctions() {
164 memset(AvailableArray, 0, sizeof(AvailableArray));
165}