Auto-upgrade malloc instructions to malloc calls.

Reviewed by Devang Patel.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82694 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Victor Hernandez
2009-09-24 17:47:49 +00:00
parent c34666ee18
commit 96b930ddc7
16 changed files with 99 additions and 34 deletions

View File

@ -2046,14 +2046,21 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
}
case bitc::FUNC_CODE_INST_MALLOC: { // MALLOC: [instty, op, align]
// Autoupgrade malloc instruction to malloc call.
if (Record.size() < 3)
return Error("Invalid MALLOC record");
const PointerType *Ty =
dyn_cast_or_null<PointerType>(getTypeByID(Record[0]));
Value *Size = getFnValueByID(Record[1], Type::getInt32Ty(Context));
unsigned Align = Record[2];
if (!Ty || !Size) return Error("Invalid MALLOC record");
I = new MallocInst(Ty->getElementType(), Size, (1 << Align) >> 1);
if (!CurBB) return Error("Invalid malloc instruction with no BB");
const Type* Int32Ty = IntegerType::getInt32Ty(CurBB->getContext());
if (Size->getType() != Int32Ty)
Size = CastInst::CreateIntegerCast(Size, Int32Ty, false /*ZExt*/,
"", CurBB);
Value* Malloc = CallInst::CreateMalloc(CurBB, Int32Ty,
Ty->getElementType(), Size, NULL);
I = cast<Instruction>(Malloc);
InstructionList.push_back(I);
break;
}