Add safety check that didn't show up in testing.
[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 /// initialize - Initialize the set of available library functions based on the
24 /// specified target triple.  This should be carefully written so that a missing
25 /// target triple gets a sane set of defaults.
26 static void initialize(TargetLibraryInfo &TLI, const Triple &T) {
27   initializeTargetLibraryInfoPass(*PassRegistry::getPassRegistry());
28
29   
30   // memset_pattern16 is only available on iOS 3.0 and Mac OS/X 10.5 and later.
31   if (T.getOS() != Triple::Darwin || T.getDarwinMajorNumber() < 9)
32     TLI.setUnavailable(LibFunc::memset_pattern16);
33
34   // iprintf and friends are only available on XCore.
35   if (T.getArch() != Triple::xcore) {
36     TLI.setUnavailable(LibFunc::iprintf);
37     TLI.setUnavailable(LibFunc::siprintf);
38     TLI.setUnavailable(LibFunc::fiprintf);
39   }
40 }
41
42
43 TargetLibraryInfo::TargetLibraryInfo() : ImmutablePass(ID) {
44   // Default to everything being available.
45   memset(AvailableArray, -1, sizeof(AvailableArray));
46
47   initialize(*this, Triple());
48 }
49
50 TargetLibraryInfo::TargetLibraryInfo(const Triple &T) : ImmutablePass(ID) {
51   // Default to everything being available.
52   memset(AvailableArray, -1, sizeof(AvailableArray));
53   
54   initialize(*this, T);
55 }
56
57 /// disableAllFunctions - This disables all builtins, which is used for options
58 /// like -fno-builtin.
59 void TargetLibraryInfo::disableAllFunctions() {
60   memset(AvailableArray, 0, sizeof(AvailableArray));
61 }