Add support for sqrt, sqrtl, and sqrtf in TargetLibraryInfo. Disable
[oota-llvm.git] / lib / Target / TargetLibraryInfo.cpp
1 //===-- 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"
16 using namespace llvm;
17
18 // Register the default implementation.
19 INITIALIZE_PASS(TargetLibraryInfo, "targetlibinfo",
20                 "Target Library Information", false, true)
21 char TargetLibraryInfo::ID = 0;
22
23 const char* TargetLibraryInfo::StandardNames[LibFunc::NumLibFuncs] =
24   {
25     "memset",
26     "memcpy",
27     "memmove",
28     "memset_pattern16",
29     "iprintf",
30     "siprintf",
31     "sqrt",
32     "sqrtl",
33     "sqrtf",
34     "fiprintf",
35     "fwrite",
36     "fputs"
37   };
38
39 /// initialize - Initialize the set of available library functions based on the
40 /// specified target triple.  This should be carefully written so that a missing
41 /// target triple gets a sane set of defaults.
42 static void initialize(TargetLibraryInfo &TLI, const Triple &T) {
43   initializeTargetLibraryInfoPass(*PassRegistry::getPassRegistry());
44
45   
46   // memset_pattern16 is only available on iOS 3.0 and Mac OS/X 10.5 and later.
47   if (T.isMacOSX()) {
48     if (T.isMacOSXVersionLT(10, 5))
49       TLI.setUnavailable(LibFunc::memset_pattern16);
50   } else if (T.getOS() == Triple::IOS) {
51     if (T.isOSVersionLT(3, 0))
52       TLI.setUnavailable(LibFunc::memset_pattern16);
53   } else {
54     TLI.setUnavailable(LibFunc::memset_pattern16);
55   }
56
57   if (T.isMacOSX() && T.getArch() == Triple::x86 &&
58       !T.isMacOSXVersionLT(10, 7)) {
59     // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
60     // we don't care about) have two versions; on recent OSX, the one we want
61     // has a $UNIX2003 suffix. The two implementations are identical except
62     // for the return value in some edge cases.  However, we don't want to
63     // generate code that depends on the old symbols.
64     TLI.setAvailableWithName(LibFunc::fwrite, "fwrite$UNIX2003");
65     TLI.setAvailableWithName(LibFunc::fputs, "fputs$UNIX2003");
66   }
67
68   // iprintf and friends are only available on XCore and TCE.
69   if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) {
70     TLI.setUnavailable(LibFunc::iprintf);
71     TLI.setUnavailable(LibFunc::siprintf);
72     TLI.setUnavailable(LibFunc::fiprintf);
73   }
74 }
75
76
77 TargetLibraryInfo::TargetLibraryInfo() : ImmutablePass(ID) {
78   // Default to everything being available.
79   memset(AvailableArray, -1, sizeof(AvailableArray));
80
81   initialize(*this, Triple());
82 }
83
84 TargetLibraryInfo::TargetLibraryInfo(const Triple &T) : ImmutablePass(ID) {
85   // Default to everything being available.
86   memset(AvailableArray, -1, sizeof(AvailableArray));
87   
88   initialize(*this, T);
89 }
90
91 TargetLibraryInfo::TargetLibraryInfo(const TargetLibraryInfo &TLI)
92   : ImmutablePass(ID) {
93   memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
94   CustomNames = TLI.CustomNames;
95 }
96
97
98 /// disableAllFunctions - This disables all builtins, which is used for options
99 /// like -fno-builtin.
100 void TargetLibraryInfo::disableAllFunctions() {
101   memset(AvailableArray, 0, sizeof(AvailableArray));
102 }