summaryrefslogtreecommitdiff
path: root/lib/Transforms/IPO
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Transforms/IPO')
-rw-r--r--lib/Transforms/IPO/LoopExtractor.cpp3
-rw-r--r--lib/Transforms/IPO/RaiseAllocations.cpp92
-rw-r--r--lib/Transforms/IPO/StripSymbols.cpp2
3 files changed, 58 insertions, 39 deletions
diff --git a/lib/Transforms/IPO/LoopExtractor.cpp b/lib/Transforms/IPO/LoopExtractor.cpp
index 5a6e7671d1..7169b503b2 100644
--- a/lib/Transforms/IPO/LoopExtractor.cpp
+++ b/lib/Transforms/IPO/LoopExtractor.cpp
@@ -167,7 +167,8 @@ bool BlockExtractorPass::runOnModule(Module &M) {
Function *F = BB->getParent();
// Map the corresponding function in this module.
- Function *MF = M.getFunction(F->getName(), F->getFunctionType());
+ Function *MF = M.getFunction(F->getName());
+ assert(MF->getFunctionType() == F->getFunctionType() && "Wrong function?");
// Figure out which index the basic block is in its function.
Function::iterator BBI = MF->begin();
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...
diff --git a/lib/Transforms/IPO/StripSymbols.cpp b/lib/Transforms/IPO/StripSymbols.cpp
index 12cd7fe893..db4387fa54 100644
--- a/lib/Transforms/IPO/StripSymbols.cpp
+++ b/lib/Transforms/IPO/StripSymbols.cpp
@@ -28,7 +28,7 @@
#include "llvm/Instructions.h"
#include "llvm/Module.h"
#include "llvm/Pass.h"
-#include "llvm/SymbolTable.h"
+#include "llvm/ValueSymbolTable.h"
#include "llvm/TypeSymbolTable.h"
using namespace llvm;