blob: f21e7ff9bec4ae15ff3d4f91dd51a7e4e9df90a4 [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",
34 "ceil",
35 "ceill",
36 "ceilf",
37 "cos",
38 "cosl",
39 "cosf",
40 "cosh",
41 "coshl",
42 "coshf",
43 "exp",
44 "expl",
45 "expf",
46 "exp2",
47 "exp2l",
48 "exp2f",
49 "expm1",
50 "expm1l",
51 "expl1f",
52 "fabs",
53 "fabsl",
54 "fabsf",
55 "floor",
56 "floorl",
57 "floorf",
Chad Rosier683e47b2011-11-30 01:51:49 +000058 "fiprintf",
59 "fputs",
60 "fwrite",
61 "iprintf",
Chad Rosier8ff41152011-11-30 19:19:00 +000062 "log",
63 "logl",
64 "logf",
65 "log2",
66 "log2l",
67 "log2f",
68 "log10",
69 "log10l",
70 "log10f",
71 "log1p",
72 "log1pl",
73 "log1pf",
Eli Friedman9d434db2011-11-17 01:27:36 +000074 "memcpy",
75 "memmove",
Chad Rosier683e47b2011-11-30 01:51:49 +000076 "memset",
Eli Friedman9d434db2011-11-17 01:27:36 +000077 "memset_pattern16",
Chad Rosier8ff41152011-11-30 19:19:00 +000078 "pow",
79 "powf",
80 "powl",
Eli Friedman9d434db2011-11-17 01:27:36 +000081 "siprintf",
Chad Rosier3d925d22011-11-29 23:57:10 +000082 "sqrt",
Chad Rosier8ff41152011-11-30 19:19:00 +000083 "sqrtl",
84 "sqrtf"
Eli Friedman9d434db2011-11-17 01:27:36 +000085 };
86
Chris Lattnerce991202011-02-18 21:50:34 +000087/// initialize - Initialize the set of available library functions based on the
88/// specified target triple. This should be carefully written so that a missing
89/// target triple gets a sane set of defaults.
90static void initialize(TargetLibraryInfo &TLI, const Triple &T) {
91 initializeTargetLibraryInfoPass(*PassRegistry::getPassRegistry());
92
93
94 // memset_pattern16 is only available on iOS 3.0 and Mac OS/X 10.5 and later.
Daniel Dunbar558692f2011-04-20 00:14:25 +000095 if (T.isMacOSX()) {
96 if (T.isMacOSXVersionLT(10, 5))
Daniel Dunbar13fb3b52011-04-19 20:44:08 +000097 TLI.setUnavailable(LibFunc::memset_pattern16);
98 } else if (T.getOS() == Triple::IOS) {
99 if (T.isOSVersionLT(3, 0))
100 TLI.setUnavailable(LibFunc::memset_pattern16);
101 } else {
Chris Lattnerce991202011-02-18 21:50:34 +0000102 TLI.setUnavailable(LibFunc::memset_pattern16);
Daniel Dunbar13fb3b52011-04-19 20:44:08 +0000103 }
Richard Osborne36498242011-03-03 13:17:51 +0000104
Eli Friedman9d434db2011-11-17 01:27:36 +0000105 if (T.isMacOSX() && T.getArch() == Triple::x86 &&
106 !T.isMacOSXVersionLT(10, 7)) {
107 // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
108 // we don't care about) have two versions; on recent OSX, the one we want
109 // has a $UNIX2003 suffix. The two implementations are identical except
110 // for the return value in some edge cases. However, we don't want to
111 // generate code that depends on the old symbols.
112 TLI.setAvailableWithName(LibFunc::fwrite, "fwrite$UNIX2003");
113 TLI.setAvailableWithName(LibFunc::fputs, "fputs$UNIX2003");
114 }
115
Duncan Sands9fe88972011-06-09 11:11:45 +0000116 // iprintf and friends are only available on XCore and TCE.
117 if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) {
Richard Osborne36498242011-03-03 13:17:51 +0000118 TLI.setUnavailable(LibFunc::iprintf);
Richard Osborne419454a2011-03-03 14:09:28 +0000119 TLI.setUnavailable(LibFunc::siprintf);
Richard Osborne022708f2011-03-03 14:20:22 +0000120 TLI.setUnavailable(LibFunc::fiprintf);
Richard Osborne419454a2011-03-03 14:09:28 +0000121 }
Chris Lattnerce991202011-02-18 21:50:34 +0000122}
123
124
125TargetLibraryInfo::TargetLibraryInfo() : ImmutablePass(ID) {
126 // Default to everything being available.
127 memset(AvailableArray, -1, sizeof(AvailableArray));
128
129 initialize(*this, Triple());
130}
131
132TargetLibraryInfo::TargetLibraryInfo(const Triple &T) : ImmutablePass(ID) {
133 // Default to everything being available.
134 memset(AvailableArray, -1, sizeof(AvailableArray));
135
136 initialize(*this, T);
137}
Chris Lattner188a7e02011-02-18 22:34:03 +0000138
Chris Lattner40f5fbc2011-05-21 20:09:13 +0000139TargetLibraryInfo::TargetLibraryInfo(const TargetLibraryInfo &TLI)
140 : ImmutablePass(ID) {
141 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
Eli Friedman9d434db2011-11-17 01:27:36 +0000142 CustomNames = TLI.CustomNames;
Chris Lattner40f5fbc2011-05-21 20:09:13 +0000143}
144
145
Chris Lattner188a7e02011-02-18 22:34:03 +0000146/// disableAllFunctions - This disables all builtins, which is used for options
147/// like -fno-builtin.
148void TargetLibraryInfo::disableAllFunctions() {
149 memset(AvailableArray, 0, sizeof(AvailableArray));
150}