summaryrefslogtreecommitdiff
path: root/lib/Transforms/IPO/RaiseAllocations.cpp
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-02-05 20:47:22 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-02-05 20:47:22 +0000
commitef9b9a793949469cdaa4ab6d0173136229dcab7b (patch)
tree137b30d24ba219e5e745a11abb3807a9c4964aaa /lib/Transforms/IPO/RaiseAllocations.cpp
parent15468bfc22302b4f79300252425d74cd6865f8b1 (diff)
downloadllvm-ef9b9a793949469cdaa4ab6d0173136229dcab7b.tar.gz
llvm-ef9b9a793949469cdaa4ab6d0173136229dcab7b.tar.bz2
llvm-ef9b9a793949469cdaa4ab6d0173136229dcab7b.tar.xz
For PR411:
This patch replaces the SymbolTable class with ValueSymbolTable which does not support types planes. This means that all symbol names in LLVM must now be unique. The patch addresses the necessary changes to deal with this and removes code no longer needed as a result. This completes the bulk of the changes for this PR. Some cleanup patches will follow. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33918 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/IPO/RaiseAllocations.cpp')
-rw-r--r--lib/Transforms/IPO/RaiseAllocations.cpp92
1 files changed, 55 insertions, 37 deletions
diff --git a/lib/Transforms/IPO/RaiseAllocations.cpp b/lib/Transforms/IPO/RaiseAllocations.cpp
index 6082780e35..c5a9cbf447 100644
--- a/lib/Transforms/IPO/RaiseAllocations.cpp
+++ b/lib/Transforms/IPO/RaiseAllocations.cpp
@@ -65,47 +65,65 @@ ModulePass *llvm::createRaiseAllocationsPass() {
// function into the appropriate instruction.
//
void RaiseAllocations::doInitialization(Module &M) {
- const FunctionType *MallocType = // Get the type for malloc
- FunctionType::get(PointerType::get(Type::Int8Ty),
- std::vector<const Type*>(1, Type::Int64Ty), false);
-
- const FunctionType *FreeType = // Get the type for free
- FunctionType::get(Type::VoidTy,
- std::vector<const Type*>(1, PointerType::get(Type::Int8Ty)),
- false);
// Get Malloc and free prototypes if they exist!
- MallocFunc = M.getFunction("malloc", MallocType);
- FreeFunc = M.getFunction("free" , FreeType);
-
- // Check to see if the prototype is wrong, giving us sbyte*(uint) * malloc
- // This handles the common declaration of: 'void *malloc(unsigned);'
- if (MallocFunc == 0) {
- MallocType = FunctionType::get(PointerType::get(Type::Int8Ty),
- std::vector<const Type*>(1, Type::Int32Ty), false);
- MallocFunc = M.getFunction("malloc", MallocType);
- }
-
- // Check to see if the prototype is missing, giving us sbyte*(...) * malloc
- // This handles the common declaration of: 'void *malloc();'
- if (MallocFunc == 0) {
- MallocType = FunctionType::get(PointerType::get(Type::Int8Ty),
- std::vector<const Type*>(), true);
- MallocFunc = M.getFunction("malloc", MallocType);
- }
-
- // Check to see if the prototype was forgotten, giving us void (...) * free
- // This handles the common forward declaration of: 'void free();'
- if (FreeFunc == 0) {
- FreeType = FunctionType::get(Type::VoidTy, std::vector<const Type*>(),true);
- FreeFunc = M.getFunction("free", FreeType);
+ MallocFunc = M.getFunction("malloc");
+ if (MallocFunc) {
+ const FunctionType* TyWeHave = MallocFunc->getFunctionType();
+
+ // Get the expected prototype for malloc
+ const FunctionType *Malloc1Type =
+ FunctionType::get(PointerType::get(Type::Int8Ty),
+ std::vector<const Type*>(1, Type::Int64Ty), false);
+
+ // Chck to see if we got the expected malloc
+ if (TyWeHave != Malloc1Type) {
+ // Check to see if the prototype is wrong, giving us sbyte*(uint) * malloc
+ // This handles the common declaration of: 'void *malloc(unsigned);'
+ const FunctionType *Malloc2Type =
+ FunctionType::get(PointerType::get(Type::Int8Ty),
+ std::vector<const Type*>(1, Type::Int32Ty), false);
+ if (TyWeHave != Malloc2Type) {
+ // Check to see if the prototype is missing, giving us
+ // sbyte*(...) * malloc
+ // This handles the common declaration of: 'void *malloc();'
+ const FunctionType *Malloc3Type =
+ FunctionType::get(PointerType::get(Type::Int8Ty),
+ std::vector<const Type*>(), true);
+ if (TyWeHave != Malloc3Type)
+ // Give up
+ MallocFunc = 0;
+ }
+ }
}
- // One last try, check to see if we can find free as 'int (...)* free'. This
- // handles the case where NOTHING was declared.
- if (FreeFunc == 0) {
- FreeType = FunctionType::get(Type::Int32Ty, std::vector<const Type*>(),true);
- FreeFunc = M.getFunction("free", FreeType);
+ FreeFunc = M.getFunction("free");
+ if (FreeFunc) {
+ const FunctionType* TyWeHave = FreeFunc->getFunctionType();
+
+ // Get the expected prototype for void free(i8*)
+ const FunctionType *Free1Type = FunctionType::get(Type::VoidTy,
+ std::vector<const Type*>(1, PointerType::get(Type::Int8Ty)), false);
+
+ if (TyWeHave != Free1Type) {
+ // Check to see if the prototype was forgotten, giving us
+ // void (...) * free
+ // This handles the common forward declaration of: 'void free();'
+ const FunctionType* Free2Type = FunctionType::get(Type::VoidTy,
+ std::vector<const Type*>(),true);
+
+ if (TyWeHave != Free2Type) {
+ // One last try, check to see if we can find free as
+ // int (...)* free. This handles the case where NOTHING was declared.
+ const FunctionType* Free3Type = FunctionType::get(Type::Int32Ty,
+ std::vector<const Type*>(),true);
+
+ if (TyWeHave != Free3Type) {
+ // Give up.
+ FreeFunc = 0;
+ }
+ }
+ }
}
// Don't mess with locally defined versions of these functions...