1 //===-- llvm/Target/TargetLibraryInfo.h - Library information ---*- C++ -*-===//
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 #ifndef LLVM_TARGET_TARGETLIBRARYINFO_H
11 #define LLVM_TARGET_TARGETLIBRARYINFO_H
13 #include "llvm/Pass.h"
14 #include "llvm/ADT/DenseMap.h"
21 /// int fiprintf(FILE *stream, const char *format, ...);
24 /// int fputs(const char *s, FILE *stream);
27 /// size_t fwrite(const void *ptr, size_t size, size_t nitems,
31 /// int iprintf(const char *format, ...);
34 /// void *memcpy(void *s1, const void *s2, size_t n);
37 /// void *memmove(void *s1, const void *s2, size_t n);
40 /// void *memset(void *b, int c, size_t len);
43 /// void memset_pattern16(void *b, const void *pattern16, size_t len);
46 /// int siprintf(char *str, const char *format, ...);
49 /// double sqrt(double x);
52 /// float sqrtf(float x);
55 /// long double sqrtl(long double x);
62 /// TargetLibraryInfo - This immutable pass captures information about what
63 /// library functions are available for the current target, and allows a
64 /// frontend to disable optimizations through -fno-builtin etc.
65 class TargetLibraryInfo : public ImmutablePass {
66 unsigned char AvailableArray[(LibFunc::NumLibFuncs+3)/4];
67 llvm::DenseMap<unsigned, std::string> CustomNames;
68 static const char* StandardNames[LibFunc::NumLibFuncs];
70 enum AvailabilityState {
71 StandardName = 3, // (memset to all ones)
73 Unavailable = 0 // (memset to all zeros)
75 void setState(LibFunc::Func F, AvailabilityState State) {
76 AvailableArray[F/4] &= ~(3 << 2*(F&3));
77 AvailableArray[F/4] |= State << 2*(F&3);
79 AvailabilityState getState(LibFunc::Func F) const {
80 return static_cast<AvailabilityState>((AvailableArray[F/4] >> 2*(F&3)) & 3);
86 TargetLibraryInfo(const Triple &T);
87 explicit TargetLibraryInfo(const TargetLibraryInfo &TLI);
89 /// has - This function is used by optimizations that want to match on or form
90 /// a given library function.
91 bool has(LibFunc::Func F) const {
92 return getState(F) != Unavailable;
95 StringRef getName(LibFunc::Func F) const {
96 AvailabilityState State = getState(F);
97 if (State == Unavailable)
99 if (State == StandardName)
100 return StandardNames[F];
101 assert(State == CustomName);
102 return CustomNames.find(F)->second;
105 /// setUnavailable - this can be used by whatever sets up TargetLibraryInfo to
106 /// ban use of specific library functions.
107 void setUnavailable(LibFunc::Func F) {
108 setState(F, Unavailable);
111 void setAvailable(LibFunc::Func F) {
112 setState(F, StandardName);
115 void setAvailableWithName(LibFunc::Func F, StringRef Name) {
116 if (StandardNames[F] != Name) {
117 setState(F, CustomName);
118 CustomNames[F] = Name;
119 assert(CustomNames.find(F) != CustomNames.end());
121 setState(F, StandardName);
125 /// disableAllFunctions - This disables all builtins, which is used for
126 /// options like -fno-builtin.
127 void disableAllFunctions();
130 } // end namespace llvm