From c63d13948242f02201f1d47a8a4276ce8975e57c Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Tue, 14 Feb 2012 13:43:59 -0800 Subject: [PATCH] Add FunctionEmitContext::MemcpyInst() --- ctx.cpp | 30 ++++++++++++++++++++++++++++++ ctx.h | 6 ++++++ 2 files changed, 36 insertions(+) diff --git a/ctx.cpp b/ctx.cpp index 41178a5b..f8dfdf36 100644 --- a/ctx.cpp +++ b/ctx.cpp @@ -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(mcFunc)); + + std::vector 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 FunctionEmitContext::BranchInst(llvm::BasicBlock *dest) { llvm::Instruction *b = llvm::BranchInst::Create(dest, bblock); diff --git a/ctx.h b/ctx.h index adf26560..97e7f08e 100644 --- a/ctx.h +++ b/ctx.h @@ -445,6 +445,12 @@ public: void StoreInst(llvm::Value *value, llvm::Value *ptr, 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 *trueBlock, llvm::BasicBlock *falseBlock, llvm::Value *test);