Add FunctionEmitContext::MemcpyInst()

This commit is contained in:
Matt Pharr
2012-02-14 13:43:59 -08:00
parent 9e682362e9
commit c63d139482
2 changed files with 36 additions and 0 deletions

30
ctx.cpp
View File

@@ -2514,6 +2514,36 @@ FunctionEmitContext::StoreInst(llvm::Value *value, llvm::Value *ptr,
} }
void
FunctionEmitContext::MemcpyInst(llvm::Value *dest, llvm::Value *src,
llvm::Value *count, llvm::Value *align) {
dest = BitCastInst(dest, LLVMTypes::VoidPointerType);
src = BitCastInst(src, LLVMTypes::VoidPointerType);
if (count->getType() != LLVMTypes::Int64Type) {
Assert(count->getType() == LLVMTypes::Int32Type);
count = ZExtInst(count, LLVMTypes::Int64Type, "count_to_64");
}
if (align == NULL)
align = LLVMInt32(1);
llvm::Constant *mcFunc =
m->module->getOrInsertFunction("llvm.memcpy.p0i8.p0i8.i64",
LLVMTypes::VoidType, LLVMTypes::VoidPointerType,
LLVMTypes::VoidPointerType, LLVMTypes::Int64Type,
LLVMTypes::Int32Type, LLVMTypes::BoolType, NULL);
Assert(mcFunc != NULL);
Assert(llvm::isa<llvm::Function>(mcFunc));
std::vector<llvm::Value *> args;
args.push_back(dest);
args.push_back(src);
args.push_back(count);
args.push_back(align);
args.push_back(LLVMFalse); /* not volatile */
CallInst(mcFunc, NULL, args, "");
}
void void
FunctionEmitContext::BranchInst(llvm::BasicBlock *dest) { FunctionEmitContext::BranchInst(llvm::BasicBlock *dest) {
llvm::Instruction *b = llvm::BranchInst::Create(dest, bblock); llvm::Instruction *b = llvm::BranchInst::Create(dest, bblock);

6
ctx.h
View File

@@ -445,6 +445,12 @@ public:
void StoreInst(llvm::Value *value, llvm::Value *ptr, void StoreInst(llvm::Value *value, llvm::Value *ptr,
llvm::Value *storeMask, const Type *ptrType); llvm::Value *storeMask, const Type *ptrType);
/** Copy count bytes of memory from the location pointed to by src to
the location pointed to by dest. (src and dest must not be
overlapping.) */
void MemcpyInst(llvm::Value *dest, llvm::Value *src, llvm::Value *count,
llvm::Value *align = NULL);
void BranchInst(llvm::BasicBlock *block); void BranchInst(llvm::BasicBlock *block);
void BranchInst(llvm::BasicBlock *trueBlock, llvm::BasicBlock *falseBlock, void BranchInst(llvm::BasicBlock *trueBlock, llvm::BasicBlock *falseBlock,
llvm::Value *test); llvm::Value *test);