From be9e1791041ecfbbbe0f6d46448682e4d3b4f297 Mon Sep 17 00:00:00 2001 From: Victor Hernandez Date: Wed, 21 Oct 2009 19:11:40 +0000 Subject: Make changes to rev 84292 as requested by Chris Lattner. Most changes are cleanup, but there is 1 correctness fix: I fixed InstCombine so that the icmp is removed only if the malloc call is removed (which requires explicit removal because the Worklist won't DCE any calls since they can have side-effects). llvm-svn: 84772 --- llvm/lib/AsmParser/LLParser.cpp | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) (limited to 'llvm/lib/AsmParser') diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index f1d5e4ffbb7..d21f98707fe 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -69,7 +69,7 @@ bool LLParser::Run() { /// ValidateEndOfModule - Do final validity and sanity checks at the end of the /// module. bool LLParser::ValidateEndOfModule() { - // Update auto-upgraded malloc calls from "autoupgrade_malloc" to "malloc". + // Update auto-upgraded malloc calls to "malloc". // FIXME: Remove in LLVM 3.0. if (MallocF) { MallocF->setName("malloc"); @@ -77,15 +77,10 @@ bool LLParser::ValidateEndOfModule() { // declaration of "malloc". In that case, iterate over all calls to MallocF // and get them to call the declared "malloc" instead. if (MallocF->getName() != "malloc") { - Function* realMallocF = M->getFunction("malloc"); - for (User::use_iterator UI = MallocF->use_begin(), UE= MallocF->use_end(); - UI != UE; ) { - User* user = *UI; - UI++; - if (CallInst *Call = dyn_cast(user)) - Call->setCalledFunction(realMallocF); - } - if (!realMallocF->doesNotAlias(0)) realMallocF->setDoesNotAlias(0); + Constant* RealMallocF = M->getFunction("malloc"); + if (RealMallocF->getType() != MallocF->getType()) + RealMallocF = ConstantExpr::getBitCast(RealMallocF, MallocF->getType()); + MallocF->replaceAllUsesWith(RealMallocF); MallocF->eraseFromParent(); MallocF = NULL; } @@ -3482,21 +3477,21 @@ bool LLParser::ParseAlloc(Instruction *&Inst, PerFunctionState &PFS, if (Size && Size->getType() != Type::getInt32Ty(Context)) return Error(SizeLoc, "element count must be i32"); - if (isAlloca) + if (isAlloca) { Inst = new AllocaInst(Ty, Size, Alignment); - else { - // Autoupgrade old malloc instruction to malloc call. - const Type* IntPtrTy = Type::getInt32Ty(Context); - const Type* Int8PtrTy = PointerType::getUnqual(Type::getInt8Ty(Context)); - if (!MallocF) - // Prototype malloc as "void *autoupgrade_malloc(int32)". - MallocF = cast(M->getOrInsertFunction("autoupgrade_malloc", - Int8PtrTy, IntPtrTy, NULL)); - // "autoupgrade_malloc" updated to "malloc" in ValidateEndOfModule(). - - Inst = cast(CallInst::CreateMalloc(BB, IntPtrTy, Ty, - Size, MallocF)); + return false; } + + // Autoupgrade old malloc instruction to malloc call. + // FIXME: Remove in LLVM 3.0. + const Type *IntPtrTy = Type::getInt32Ty(Context); + const Type *Int8PtrTy = Type::getInt8PtrTy(Context); + if (!MallocF) + // Prototype malloc as "void *(int32)". + // This function is renamed as "malloc" in ValidateEndOfModule(). + MallocF = cast(M->getOrInsertFunction(NULL, Int8PtrTy, + IntPtrTy, NULL)); + Inst = CallInst::CreateMalloc(BB, IntPtrTy, Ty, Size, MallocF); return false; } -- cgit v1.2.3