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 /// double acos(double x);
23 /// long double acosl(long double x);
25 /// float acosf(float x);
27 /// double asin(double x);
29 /// long double asinl(long double x);
31 /// float asinf(float x);
33 /// double atan(double x);
35 /// long double atanl(long double x);
37 /// float atanf(float x);
39 /// double ceil(double x);
41 /// long double ceill(long double x);
43 /// float ceilf(float x);
45 /// double cos(double x);
47 /// long double cosl(long double x);
49 /// float cosf(float x);
51 /// double cosh(double x);
53 /// long double coshl(long double x);
55 /// float coshf(float x);
57 /// double exp(double x);
59 /// long double expl(long double x);
61 /// float expf(float x);
63 /// double exp2(double x);
65 /// long double exp2l(long double x);
67 /// float exp2f(float x);
69 /// double expm1(double x);
71 /// long double expm1l(long double x);
73 /// float expm1f(float x);
75 /// double fabs(double x);
77 /// long double fabsl(long double x);
79 /// float fabsf(float x);
81 /// double floor(double x);
83 /// long double floorl(long double x);
85 /// float floorf(float x);
87 /// int fiprintf(FILE *stream, const char *format, ...);
89 /// int fputs(const char *s, FILE *stream);
91 /// size_t fwrite(const void *ptr, size_t size, size_t nitems,
94 /// int iprintf(const char *format, ...);
96 /// double log(double x);
98 /// long double logl(long double x);
100 /// float logf(float x);
102 /// double log2(double x);
104 /// double long double log2l(long double x);
106 /// float log2f(float x);
108 /// double log10(double x);
110 /// long double log10l(long double x);
112 /// float log10f(float x);
114 /// double log1p(double x);
116 /// long double log1pl(long double x);
118 /// float log1pf(float x);
120 /// void *memcpy(void *s1, const void *s2, size_t n);
122 /// void *memmove(void *s1, const void *s2, size_t n);
124 /// void *memset(void *b, int c, size_t len);
126 /// void memset_pattern16(void *b, const void *pattern16, size_t len);
128 /// double pow(double x, double y);
130 /// float powf(float x, float y);
132 /// long double powl(long double x, long double y);
134 /// int siprintf(char *str, const char *format, ...);
136 /// double sqrt(double x);
138 /// long double sqrtl(long double x);
140 /// float sqrtf(float x);
147 /// TargetLibraryInfo - This immutable pass captures information about what
148 /// library functions are available for the current target, and allows a
149 /// frontend to disable optimizations through -fno-builtin etc.
150 class TargetLibraryInfo : public ImmutablePass {
151 unsigned char AvailableArray[(LibFunc::NumLibFuncs+3)/4];
152 llvm::DenseMap<unsigned, std::string> CustomNames;
153 static const char* StandardNames[LibFunc::NumLibFuncs];
155 enum AvailabilityState {
156 StandardName = 3, // (memset to all ones)
158 Unavailable = 0 // (memset to all zeros)
160 void setState(LibFunc::Func F, AvailabilityState State) {
161 AvailableArray[F/4] &= ~(3 << 2*(F&3));
162 AvailableArray[F/4] |= State << 2*(F&3);
164 AvailabilityState getState(LibFunc::Func F) const {
165 return static_cast<AvailabilityState>((AvailableArray[F/4] >> 2*(F&3)) & 3);
171 TargetLibraryInfo(const Triple &T);
172 explicit TargetLibraryInfo(const TargetLibraryInfo &TLI);
174 /// has - This function is used by optimizations that want to match on or form
175 /// a given library function.
176 bool has(LibFunc::Func F) const {
177 return getState(F) != Unavailable;
180 StringRef getName(LibFunc::Func F) const {
181 AvailabilityState State = getState(F);
182 if (State == Unavailable)
184 if (State == StandardName)
185 return StandardNames[F];
186 assert(State == CustomName);
187 return CustomNames.find(F)->second;
190 /// setUnavailable - this can be used by whatever sets up TargetLibraryInfo to
191 /// ban use of specific library functions.
192 void setUnavailable(LibFunc::Func F) {
193 setState(F, Unavailable);
196 void setAvailable(LibFunc::Func F) {
197 setState(F, StandardName);
200 void setAvailableWithName(LibFunc::Func F, StringRef Name) {
201 if (StandardNames[F] != Name) {
202 setState(F, CustomName);
203 CustomNames[F] = Name;
204 assert(CustomNames.find(F) != CustomNames.end());
206 setState(F, StandardName);
210 /// disableAllFunctions - This disables all builtins, which is used for
211 /// options like -fno-builtin.
212 void disableAllFunctions();
215 } // end namespace llvm