TargetLibraryInfo.h revision 32b6c59ad068d2bb2466dd33bc17d8c865760215
1//===-- llvm/Target/TargetLibraryInfo.h - Library information ---*- C++ -*-===//
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#ifndef LLVM_TARGET_TARGETLIBRARYINFO_H
11#define LLVM_TARGET_TARGETLIBRARYINFO_H
12
13#include "llvm/Pass.h"
14#include "llvm/ADT/DenseMap.h"
15
16namespace llvm {
17  class Triple;
18
19  namespace LibFunc {
20    enum Func {
21      /// double acos(double x);
22      acos,
23      /// long double acosl(long double x);
24      acosl,
25      /// float acosf(float x);
26      acosf,
27      /// double asin(double x);
28      asin,
29      /// long double asinl(long double x);
30      asinl,
31      /// float asinf(float x);
32      asinf,
33      /// double atan(double x);
34      atan,
35      /// long double atanl(long double x);
36      atanl,
37      /// float atanf(float x);
38      atanf,
39      /// double atan2(double y, double x);
40      atan2,
41      /// long double atan2l(long double y, long double x);
42      atan2l,
43      /// float atan2f(float y, float x);
44      atan2f,
45      /// double ceil(double x);
46      ceil,
47      /// long double ceill(long double x);
48      ceill,
49      /// float ceilf(float x);
50      ceilf,
51      /// double cos(double x);
52      cos,
53      /// long double cosl(long double x);
54      cosl,
55      /// float cosf(float x);
56      cosf,
57      /// double cosh(double x);
58      cosh,
59      /// long double coshl(long double x);
60      coshl,
61      /// float coshf(float x);
62      coshf,
63      /// double exp(double x);
64      exp,
65      /// long double expl(long double x);
66      expl,
67      /// float expf(float x);
68      expf,
69      /// double exp2(double x);
70      exp2,
71      /// long double exp2l(long double x);
72      exp2l,
73      /// float exp2f(float x);
74      exp2f,
75      /// double expm1(double x);
76      expm1,
77      /// long double expm1l(long double x);
78      expm1l,
79      /// float expm1f(float x);
80      expl1f,
81      /// double fabs(double x);
82      fabs,
83      /// long double fabsl(long double x);
84      fabsl,
85      /// float fabsf(float x);
86      fabsf,
87      /// double floor(double x);
88      floor,
89      /// long double floorl(long double x);
90      floorl,
91      /// float floorf(float x);
92      floorf,
93      /// int fiprintf(FILE *stream, const char *format, ...);
94      fiprintf,
95      /// double fmod(double x, double y);
96      fmod,
97      /// long double fmodl(long double x, long double y);
98      fmodl,
99      /// float fmodf(float x, float y);
100      fmodf,
101      /// int fputs(const char *s, FILE *stream);
102      fputs,
103      /// size_t fwrite(const void *ptr, size_t size, size_t nitems,
104      /// FILE *stream);
105      fwrite,
106      /// int iprintf(const char *format, ...);
107      iprintf,
108      /// double log(double x);
109      log,
110      /// long double logl(long double x);
111      logl,
112      /// float logf(float x);
113      logf,
114      /// double log2(double x);
115      log2,
116      /// double long double log2l(long double x);
117      log2l,
118      /// float log2f(float x);
119      log2f,
120      /// double log10(double x);
121      log10,
122      /// long double log10l(long double x);
123      log10l,
124      /// float log10f(float x);
125      log10f,
126      /// double log1p(double x);
127      log1p,
128      /// long double log1pl(long double x);
129      log1pl,
130      /// float log1pf(float x);
131      log1pf,
132      /// void *memcpy(void *s1, const void *s2, size_t n);
133      memcpy,
134      /// void *memmove(void *s1, const void *s2, size_t n);
135      memmove,
136      /// void *memset(void *b, int c, size_t len);
137      memset,
138      /// void memset_pattern16(void *b, const void *pattern16, size_t len);
139      memset_pattern16,
140      /// double pow(double x, double y);
141      pow,
142      /// float powf(float x, float y);
143      powf,
144      /// long double powl(long double x, long double y);
145      powl,
146      /// double sin(double x);
147      sin,
148      /// long double sinl(long double x);
149      sinl,
150      /// float sinf(float x);
151      sinf,
152      /// double sinh(double x);
153      sinh,
154      /// long double sinhl(long double x);
155      sinhl,
156      /// float sinhf(float x);
157      sinhf,
158      /// int siprintf(char *str, const char *format, ...);
159      siprintf,
160      /// double sqrt(double x);
161      sqrt,
162      /// long double sqrtl(long double x);
163      sqrtl,
164      /// float sqrtf(float x);
165      sqrtf,
166      /// double tan(double x);
167      tan,
168      /// long double tanl(long double x);
169      tanl,
170      /// float tanf(float x);
171      tanf,
172      /// double tanh(double x);
173      tanh,
174      /// long double tanhl(long double x);
175      tanhl,
176      /// float tanhf(float x);
177      tanhf,
178
179      NumLibFuncs
180    };
181  }
182
183/// TargetLibraryInfo - This immutable pass captures information about what
184/// library functions are available for the current target, and allows a
185/// frontend to disable optimizations through -fno-builtin etc.
186class TargetLibraryInfo : public ImmutablePass {
187  unsigned char AvailableArray[(LibFunc::NumLibFuncs+3)/4];
188  llvm::DenseMap<unsigned, std::string> CustomNames;
189  static const char* StandardNames[LibFunc::NumLibFuncs];
190
191  enum AvailabilityState {
192    StandardName = 3, // (memset to all ones)
193    CustomName = 1,
194    Unavailable = 0  // (memset to all zeros)
195  };
196  void setState(LibFunc::Func F, AvailabilityState State) {
197    AvailableArray[F/4] &= ~(3 << 2*(F&3));
198    AvailableArray[F/4] |= State << 2*(F&3);
199  }
200  AvailabilityState getState(LibFunc::Func F) const {
201    return static_cast<AvailabilityState>((AvailableArray[F/4] >> 2*(F&3)) & 3);
202  }
203
204public:
205  static char ID;
206  TargetLibraryInfo();
207  TargetLibraryInfo(const Triple &T);
208  explicit TargetLibraryInfo(const TargetLibraryInfo &TLI);
209
210  /// has - This function is used by optimizations that want to match on or form
211  /// a given library function.
212  bool has(LibFunc::Func F) const {
213    return getState(F) != Unavailable;
214  }
215
216  StringRef getName(LibFunc::Func F) const {
217    AvailabilityState State = getState(F);
218    if (State == Unavailable)
219      return StringRef();
220    if (State == StandardName)
221      return StandardNames[F];
222    assert(State == CustomName);
223    return CustomNames.find(F)->second;
224  }
225
226  /// setUnavailable - this can be used by whatever sets up TargetLibraryInfo to
227  /// ban use of specific library functions.
228  void setUnavailable(LibFunc::Func F) {
229    setState(F, Unavailable);
230  }
231
232  void setAvailable(LibFunc::Func F) {
233    setState(F, StandardName);
234  }
235
236  void setAvailableWithName(LibFunc::Func F, StringRef Name) {
237    if (StandardNames[F] != Name) {
238      setState(F, CustomName);
239      CustomNames[F] = Name;
240      assert(CustomNames.find(F) != CustomNames.end());
241    } else {
242      setState(F, StandardName);
243    }
244  }
245
246  /// disableAllFunctions - This disables all builtins, which is used for
247  /// options like -fno-builtin.
248  void disableAllFunctions();
249};
250
251} // end namespace llvm
252
253#endif
254