summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2011-11-17 01:27:36 +0000
committerEli Friedman <eli.friedman@gmail.com>2011-11-17 01:27:36 +0000
commit9d434dbff3eb0501efc3457acec2401afdffef2f (patch)
treef07d875db36c105c6b61d98649ab84727af3160b /include
parentd5889d8c7fcd97994cf38bb7469a703fe3db3672 (diff)
downloadllvm-9d434dbff3eb0501efc3457acec2401afdffef2f.tar.gz
llvm-9d434dbff3eb0501efc3457acec2401afdffef2f.tar.bz2
llvm-9d434dbff3eb0501efc3457acec2401afdffef2f.tar.xz
Add support for custom names for library functions in TargetLibraryInfo. Add a custom name for fwrite and fputs on x86-32 OSX. Make SimplifyLibCalls honor the custom
names for fwrite and fputs. Fixes <rdar://problem/9815881>. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@144876 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/Target/TargetLibraryInfo.h56
-rw-r--r--include/llvm/Transforms/Utils/BuildLibCalls.h6
2 files changed, 54 insertions, 8 deletions
diff --git a/include/llvm/Target/TargetLibraryInfo.h b/include/llvm/Target/TargetLibraryInfo.h
index 02a1a3ca23..7770a11ac0 100644
--- a/include/llvm/Target/TargetLibraryInfo.h
+++ b/include/llvm/Target/TargetLibraryInfo.h
@@ -11,6 +11,7 @@
#define LLVM_TARGET_TARGETLIBRARYINFO_H
#include "llvm/Pass.h"
+#include "llvm/ADT/DenseMap.h"
namespace llvm {
class Triple;
@@ -37,7 +38,14 @@ namespace llvm {
/// int fiprintf(FILE *stream, const char *format, ...);
fiprintf,
-
+
+ // size_t fwrite(const void *ptr, size_t size, size_t nitems,
+ // FILE *stream);
+ fwrite,
+
+ // int fputs(const char *s, FILE *stream);
+ fputs,
+
NumLibFuncs
};
}
@@ -46,7 +54,23 @@ namespace llvm {
/// library functions are available for the current target, and allows a
/// frontend to disable optimizations through -fno-builtin etc.
class TargetLibraryInfo : public ImmutablePass {
- unsigned char AvailableArray[(LibFunc::NumLibFuncs+7)/8];
+ unsigned char AvailableArray[(LibFunc::NumLibFuncs+3)/4];
+ llvm::DenseMap<unsigned, std::string> CustomNames;
+ static const char* StandardNames[LibFunc::NumLibFuncs];
+
+ enum AvailabilityState {
+ StandardName = 3, // (memset to all ones)
+ CustomName = 1,
+ Unavailable = 0 // (memset to all zeros)
+ };
+ void setState(LibFunc::Func F, AvailabilityState State) {
+ AvailableArray[F/4] &= ~(3 << 2*(F&3));
+ AvailableArray[F/4] |= State << 2*(F&3);
+ }
+ AvailabilityState getState(LibFunc::Func F) const {
+ return static_cast<AvailabilityState>((AvailableArray[F/4] >> 2*(F&3)) & 3);
+ }
+
public:
static char ID;
TargetLibraryInfo();
@@ -56,19 +80,39 @@ public:
/// has - This function is used by optimizations that want to match on or form
/// a given library function.
bool has(LibFunc::Func F) const {
- return (AvailableArray[F/8] & (1 << (F&7))) != 0;
+ return getState(F) != Unavailable;
+ }
+
+ StringRef getName(LibFunc::Func F) const {
+ AvailabilityState State = getState(F);
+ if (State == Unavailable)
+ return StringRef();
+ if (State == StandardName)
+ return StandardNames[F];
+ assert(State == CustomName);
+ return CustomNames.find(F)->second;
}
/// setUnavailable - this can be used by whatever sets up TargetLibraryInfo to
/// ban use of specific library functions.
void setUnavailable(LibFunc::Func F) {
- AvailableArray[F/8] &= ~(1 << (F&7));
+ setState(F, Unavailable);
}
void setAvailable(LibFunc::Func F) {
- AvailableArray[F/8] |= 1 << (F&7);
+ setState(F, StandardName);
}
-
+
+ void setAvailableWithName(LibFunc::Func F, StringRef Name) {
+ if (StandardNames[F] != Name) {
+ setState(F, CustomName);
+ CustomNames[F] = Name;
+ assert(CustomNames.find(F) != CustomNames.end());
+ } else {
+ setState(F, StandardName);
+ }
+ }
+
/// disableAllFunctions - This disables all builtins, which is used for
/// options like -fno-builtin.
void disableAllFunctions();
diff --git a/include/llvm/Transforms/Utils/BuildLibCalls.h b/include/llvm/Transforms/Utils/BuildLibCalls.h
index 53ff282393..17cd58eb01 100644
--- a/include/llvm/Transforms/Utils/BuildLibCalls.h
+++ b/include/llvm/Transforms/Utils/BuildLibCalls.h
@@ -20,6 +20,7 @@
namespace llvm {
class Value;
class TargetData;
+ class TargetLibraryInfo;
/// CastToCStr - Return V if it is an i8*, otherwise cast it to i8*.
Value *CastToCStr(Value *V, IRBuilder<> &B);
@@ -86,12 +87,13 @@ namespace llvm {
/// EmitFPutS - Emit a call to the puts function. Str is required to be a
/// pointer and File is a pointer to FILE.
- void EmitFPutS(Value *Str, Value *File, IRBuilder<> &B, const TargetData *TD);
+ void EmitFPutS(Value *Str, Value *File, IRBuilder<> &B, const TargetData *TD,
+ const TargetLibraryInfo *TLI);
/// EmitFWrite - Emit a call to the fwrite function. This assumes that Ptr is
/// a pointer, Size is an 'intptr_t', and File is a pointer to FILE.
void EmitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilder<> &B,
- const TargetData *TD);
+ const TargetData *TD, const TargetLibraryInfo *TLI);
/// SimplifyFortifiedLibCalls - Helper class for folding checked library
/// calls (e.g. __strcpy_chk) into their unchecked counterparts.