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 /// void *memset(void *b, int c, size_t len);
24 // void *memcpy(void *s1, const void *s2, size_t n);
27 // void *memmove(void *s1, const void *s2, size_t n);
30 /// void memset_pattern16(void *b, const void *pattern16, size_t len);
33 /// int iprintf(const char *format, ...);
36 /// int siprintf(char *str, const char *format, ...);
39 /// int fiprintf(FILE *stream, const char *format, ...);
42 // size_t fwrite(const void *ptr, size_t size, size_t nitems,
46 // int fputs(const char *s, FILE *stream);
53 /// TargetLibraryInfo - This immutable pass captures information about what
54 /// library functions are available for the current target, and allows a
55 /// frontend to disable optimizations through -fno-builtin etc.
56 class TargetLibraryInfo : public ImmutablePass {
57 unsigned char AvailableArray[(LibFunc::NumLibFuncs+3)/4];
58 llvm::DenseMap<unsigned, std::string> CustomNames;
59 static const char* StandardNames[LibFunc::NumLibFuncs];
61 enum AvailabilityState {
62 StandardName = 3, // (memset to all ones)
64 Unavailable = 0 // (memset to all zeros)
66 void setState(LibFunc::Func F, AvailabilityState State) {
67 AvailableArray[F/4] &= ~(3 << 2*(F&3));
68 AvailableArray[F/4] |= State << 2*(F&3);
70 AvailabilityState getState(LibFunc::Func F) const {
71 return static_cast<AvailabilityState>((AvailableArray[F/4] >> 2*(F&3)) & 3);
77 TargetLibraryInfo(const Triple &T);
78 explicit TargetLibraryInfo(const TargetLibraryInfo &TLI);
80 /// has - This function is used by optimizations that want to match on or form
81 /// a given library function.
82 bool has(LibFunc::Func F) const {
83 return getState(F) != Unavailable;
86 StringRef getName(LibFunc::Func F) const {
87 AvailabilityState State = getState(F);
88 if (State == Unavailable)
90 if (State == StandardName)
91 return StandardNames[F];
92 assert(State == CustomName);
93 return CustomNames.find(F)->second;
96 /// setUnavailable - this can be used by whatever sets up TargetLibraryInfo to
97 /// ban use of specific library functions.
98 void setUnavailable(LibFunc::Func F) {
99 setState(F, Unavailable);
102 void setAvailable(LibFunc::Func F) {
103 setState(F, StandardName);
106 void setAvailableWithName(LibFunc::Func F, StringRef Name) {
107 if (StandardNames[F] != Name) {
108 setState(F, CustomName);
109 CustomNames[F] = Name;
110 assert(CustomNames.find(F) != CustomNames.end());
112 setState(F, StandardName);
116 /// disableAllFunctions - This disables all builtins, which is used for
117 /// options like -fno-builtin.
118 void disableAllFunctions();
121 } // end namespace llvm