1 //===-- TargetLibraryInfo.cpp - Runtime library information ----------------==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the TargetLibraryInfo class.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Target/TargetLibraryInfo.h"
15 #include "llvm/ADT/Triple.h"
18 // Register the default implementation.
19 INITIALIZE_PASS(TargetLibraryInfo, "targetlibinfo",
20 "Target Library Information", false, true)
21 char TargetLibraryInfo::ID = 0;
23 void TargetLibraryInfo::anchor() { }
25 const char* TargetLibraryInfo::StandardNames[LibFunc::NumLibFuncs] =
119 /// 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.
122 static void initialize(TargetLibraryInfo &TLI, const Triple &T) {
123 initializeTargetLibraryInfoPass(*PassRegistry::getPassRegistry());
126 // memset_pattern16 is only available on iOS 3.0 and Mac OS/X 10.5 and later.
128 if (T.isMacOSXVersionLT(10, 5))
129 TLI.setUnavailable(LibFunc::memset_pattern16);
130 } else if (T.getOS() == Triple::IOS) {
131 if (T.isOSVersionLT(3, 0))
132 TLI.setUnavailable(LibFunc::memset_pattern16);
134 TLI.setUnavailable(LibFunc::memset_pattern16);
137 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");
148 // iprintf and friends are only available on XCore and TCE.
149 if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) {
150 TLI.setUnavailable(LibFunc::iprintf);
151 TLI.setUnavailable(LibFunc::siprintf);
152 TLI.setUnavailable(LibFunc::fiprintf);
157 TargetLibraryInfo::TargetLibraryInfo() : ImmutablePass(ID) {
158 // Default to everything being available.
159 memset(AvailableArray, -1, sizeof(AvailableArray));
161 initialize(*this, Triple());
164 TargetLibraryInfo::TargetLibraryInfo(const Triple &T) : ImmutablePass(ID) {
165 // Default to everything being available.
166 memset(AvailableArray, -1, sizeof(AvailableArray));
168 initialize(*this, T);
171 TargetLibraryInfo::TargetLibraryInfo(const TargetLibraryInfo &TLI)
172 : ImmutablePass(ID) {
173 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
174 CustomNames = TLI.CustomNames;
178 /// disableAllFunctions - This disables all builtins, which is used for options
179 /// like -fno-builtin.
180 void TargetLibraryInfo::disableAllFunctions() {
181 memset(AvailableArray, 0, sizeof(AvailableArray));