aboutsummaryrefslogtreecommitdiff
path: root/lib/VMCore/Instructions.cpp
diff options
context:
space:
mode:
authorRoman Divacky <rdivacky@FreeBSD.org>2009-10-23 14:19:52 +0000
committerRoman Divacky <rdivacky@FreeBSD.org>2009-10-23 14:19:52 +0000
commit4a142eb28942073eb27a112b5ca1cca3f01beb9c (patch)
tree22cc59e4b240d84c3a5a60531119c4eca914a256 /lib/VMCore/Instructions.cpp
parent5cd822fa9bbb9622241e3bf4d7674ed49ccde5b9 (diff)
downloadsrc-4a142eb28942073eb27a112b5ca1cca3f01beb9c.tar.gz
src-4a142eb28942073eb27a112b5ca1cca3f01beb9c.zip
Update LLVM to r84949.vendor/llvm/llvm-r84949
Notes
Notes: svn path=/vendor/llvm/dist/; revision=198396 svn path=/vendor/llvm/llvm-r84949/; revision=198397; tag=vendor/llvm/llvm-r84949
Diffstat (limited to 'lib/VMCore/Instructions.cpp')
-rw-r--r--lib/VMCore/Instructions.cpp69
1 files changed, 34 insertions, 35 deletions
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index f3d15cb2b88b..e212d5c542a7 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/lib/VMCore/Instructions.cpp
@@ -460,9 +460,10 @@ static Value *checkArraySize(Value *Amt, const Type *IntPtrTy) {
return Amt;
}
-static Value *createMalloc(Instruction *InsertBefore, BasicBlock *InsertAtEnd,
- const Type *IntPtrTy, const Type *AllocTy,
- Value *ArraySize, const Twine &NameStr) {
+static Instruction *createMalloc(Instruction *InsertBefore,
+ BasicBlock *InsertAtEnd, const Type *IntPtrTy,
+ const Type *AllocTy, Value *ArraySize,
+ Function *MallocF, const Twine &NameStr) {
assert(((!InsertBefore && InsertAtEnd) || (InsertBefore && !InsertAtEnd)) &&
"createMalloc needs either InsertBefore or InsertAtEnd");
@@ -499,27 +500,34 @@ static Value *createMalloc(Instruction *InsertBefore, BasicBlock *InsertAtEnd,
BasicBlock* BB = InsertBefore ? InsertBefore->getParent() : InsertAtEnd;
Module* M = BB->getParent()->getParent();
const Type *BPTy = Type::getInt8PtrTy(BB->getContext());
- // prototype malloc as "void *malloc(size_t)"
- Constant *MallocF = M->getOrInsertFunction("malloc", BPTy, IntPtrTy, NULL);
- if (!cast<Function>(MallocF)->doesNotAlias(0))
- cast<Function>(MallocF)->setDoesNotAlias(0);
+ if (!MallocF)
+ // prototype malloc as "void *malloc(size_t)"
+ MallocF = cast<Function>(M->getOrInsertFunction("malloc", BPTy,
+ IntPtrTy, NULL));
+ if (!MallocF->doesNotAlias(0)) MallocF->setDoesNotAlias(0);
const PointerType *AllocPtrType = PointerType::getUnqual(AllocTy);
CallInst *MCall = NULL;
- Value *MCast = NULL;
+ Instruction *Result = NULL;
if (InsertBefore) {
MCall = CallInst::Create(MallocF, AllocSize, "malloccall", InsertBefore);
- // Create a cast instruction to convert to the right type...
- MCast = new BitCastInst(MCall, AllocPtrType, NameStr, InsertBefore);
+ Result = MCall;
+ if (Result->getType() != AllocPtrType)
+ // Create a cast instruction to convert to the right type...
+ Result = new BitCastInst(MCall, AllocPtrType, NameStr, InsertBefore);
} else {
- MCall = CallInst::Create(MallocF, AllocSize, "malloccall", InsertAtEnd);
- // Create a cast instruction to convert to the right type...
- MCast = new BitCastInst(MCall, AllocPtrType, NameStr);
+ MCall = CallInst::Create(MallocF, AllocSize, "malloccall");
+ Result = MCall;
+ if (Result->getType() != AllocPtrType) {
+ InsertAtEnd->getInstList().push_back(MCall);
+ // Create a cast instruction to convert to the right type...
+ Result = new BitCastInst(MCall, AllocPtrType, NameStr);
+ }
}
MCall->setTailCall();
assert(MCall->getType() != Type::getVoidTy(BB->getContext()) &&
"Malloc has void return type");
- return MCast;
+ return Result;
}
/// CreateMalloc - Generate the IR for a call to malloc:
@@ -528,10 +536,11 @@ static Value *createMalloc(Instruction *InsertBefore, BasicBlock *InsertAtEnd,
/// constant 1.
/// 2. Call malloc with that argument.
/// 3. Bitcast the result of the malloc call to the specified type.
-Value *CallInst::CreateMalloc(Instruction *InsertBefore, const Type *IntPtrTy,
- const Type *AllocTy, Value *ArraySize,
- const Twine &Name) {
- return createMalloc(InsertBefore, NULL, IntPtrTy, AllocTy, ArraySize, Name);
+Instruction *CallInst::CreateMalloc(Instruction *InsertBefore,
+ const Type *IntPtrTy, const Type *AllocTy,
+ Value *ArraySize, const Twine &Name) {
+ return createMalloc(InsertBefore, NULL, IntPtrTy, AllocTy,
+ ArraySize, NULL, Name);
}
/// CreateMalloc - Generate the IR for a call to malloc:
@@ -542,10 +551,12 @@ Value *CallInst::CreateMalloc(Instruction *InsertBefore, const Type *IntPtrTy,
/// 3. Bitcast the result of the malloc call to the specified type.
/// Note: This function does not add the bitcast to the basic block, that is the
/// responsibility of the caller.
-Value *CallInst::CreateMalloc(BasicBlock *InsertAtEnd, const Type *IntPtrTy,
- const Type *AllocTy, Value *ArraySize,
- const Twine &Name) {
- return createMalloc(NULL, InsertAtEnd, IntPtrTy, AllocTy, ArraySize, Name);
+Instruction *CallInst::CreateMalloc(BasicBlock *InsertAtEnd,
+ const Type *IntPtrTy, const Type *AllocTy,
+ Value *ArraySize, Function* MallocF,
+ const Twine &Name) {
+ return createMalloc(NULL, InsertAtEnd, IntPtrTy, AllocTy,
+ ArraySize, MallocF, Name);
}
//===----------------------------------------------------------------------===//
@@ -837,7 +848,7 @@ static Value *getAISize(LLVMContext &Context, Value *Amt) {
assert(!isa<BasicBlock>(Amt) &&
"Passed basic block into allocation size parameter! Use other ctor");
assert(Amt->getType() == Type::getInt32Ty(Context) &&
- "Malloc/Allocation array size is not a 32-bit integer!");
+ "Allocation array size is not a 32-bit integer!");
}
return Amt;
}
@@ -3073,18 +3084,6 @@ InsertValueInst *InsertValueInst::clone() const {
return New;
}
-MallocInst *MallocInst::clone() const {
- MallocInst *New = new MallocInst(getAllocatedType(),
- (Value*)getOperand(0),
- getAlignment());
- New->SubclassOptionalData = SubclassOptionalData;
- if (hasMetadata()) {
- LLVMContext &Context = getContext();
- Context.pImpl->TheMetadata.ValueIsCloned(this, New);
- }
- return New;
-}
-
AllocaInst *AllocaInst::clone() const {
AllocaInst *New = new AllocaInst(getAllocatedType(),
(Value*)getOperand(0),