More LLVMContext-ification.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74811 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Owen Anderson
2009-07-06 01:34:54 +00:00
parent e8c81ea3f8
commit 14ce9ef2e9
11 changed files with 181 additions and 135 deletions
+14 -9
View File
@@ -16,6 +16,7 @@
#include "llvm/Transforms/IPO.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Instructions.h"
#include "llvm/Pass.h"
@@ -77,7 +78,7 @@ void RaiseAllocations::doInitialization(Module &M) {
// Get the expected prototype for malloc
const FunctionType *Malloc1Type =
FunctionType::get(PointerType::getUnqual(Type::Int8Ty),
Context->getFunctionType(Context->getPointerTypeUnqual(Type::Int8Ty),
std::vector<const Type*>(1, Type::Int64Ty), false);
// Chck to see if we got the expected malloc
@@ -85,14 +86,15 @@ void RaiseAllocations::doInitialization(Module &M) {
// Check to see if the prototype is wrong, giving us i8*(i32) * malloc
// This handles the common declaration of: 'void *malloc(unsigned);'
const FunctionType *Malloc2Type =
FunctionType::get(PointerType::getUnqual(Type::Int8Ty),
Context->getFunctionType(Context->getPointerTypeUnqual(Type::Int8Ty),
std::vector<const Type*>(1, Type::Int32Ty), false);
if (TyWeHave != Malloc2Type) {
// Check to see if the prototype is missing, giving us
// i8*(...) * malloc
// This handles the common declaration of: 'void *malloc();'
const FunctionType *Malloc3Type =
FunctionType::get(PointerType::getUnqual(Type::Int8Ty), true);
Context->getFunctionType(Context->getPointerTypeUnqual(Type::Int8Ty),
true);
if (TyWeHave != Malloc3Type)
// Give up
MallocFunc = 0;
@@ -105,19 +107,22 @@ void RaiseAllocations::doInitialization(Module &M) {
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::getUnqual(Type::Int8Ty)), false);
const FunctionType *Free1Type = Context->getFunctionType(Type::VoidTy,
std::vector<const Type*>(1, Context->getPointerTypeUnqual(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, true);
const FunctionType* Free2Type = Context->getFunctionType(Type::VoidTy,
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, true);
const FunctionType* Free3Type = Context->getFunctionType(Type::Int32Ty,
true);
if (TyWeHave != Free3Type) {
// Give up.
@@ -216,7 +221,7 @@ bool RaiseAllocations::runOnModule(Module &M) {
Value *Source = *CS.arg_begin();
if (!isa<PointerType>(Source->getType()))
Source = new IntToPtrInst(Source,
PointerType::getUnqual(Type::Int8Ty),
Context->getPointerTypeUnqual(Type::Int8Ty),
"FreePtrCast", I);
new FreeInst(Source, I);
@@ -227,7 +232,7 @@ bool RaiseAllocations::runOnModule(Module &M) {
// Delete the old call site
if (I->getType() != Type::VoidTy)
I->replaceAllUsesWith(UndefValue::get(I->getType()));
I->replaceAllUsesWith(Context->getUndef(I->getType()));
I->eraseFromParent();
Changed = true;
++NumRaised;