From ef9b9a793949469cdaa4ab6d0173136229dcab7b Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Mon, 5 Feb 2007 20:47:22 +0000 Subject: 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 --- lib/Transforms/IPO/LoopExtractor.cpp | 3 +- lib/Transforms/IPO/RaiseAllocations.cpp | 92 ++++++++++++++++++++------------- lib/Transforms/IPO/StripSymbols.cpp | 2 +- 3 files changed, 58 insertions(+), 39 deletions(-) (limited to 'lib/Transforms/IPO') 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(1, Type::Int64Ty), false); - - const FunctionType *FreeType = // Get the type for free - FunctionType::get(Type::VoidTy, - std::vector(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(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(), 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(),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(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(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(), 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(),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(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(),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(),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; -- cgit v1.2.3