Commit 5d00cea5 authored by Alastair Robertson's avatar Alastair Robertson

Use base IRBuilder's CreateMemCpy and CreateMemSet functions

parent d1fbcb11
......@@ -153,7 +153,7 @@ void CodegenLLVM::visit(Call &call)
else if (call.func == "str")
{
AllocaInst *buf = b_.CreateAllocaBPF(call.type, "str");
b_.CreateMemset(buf, b_.getInt8(0), call.type.size);
b_.CreateMemSet(buf, b_.getInt8(0), call.type.size, 1);
call.vargs->front()->accept(*this);
b_.CreateProbeReadStr(buf, call.type.size, expr_);
expr_ = buf;
......@@ -195,7 +195,7 @@ void CodegenLLVM::visit(Call &call)
arg.accept(*this);
Value *offset = b_.CreateGEP(printf_args, {b_.getInt32(0), b_.getInt32(i)});
if (arg.type.type == Type::string)
b_.CreateMemcpy(offset, expr_, arg.type.size);
b_.CreateMemCpy(offset, expr_, arg.type.size, 1);
else
b_.CreateStore(expr_, offset);
}
......@@ -421,7 +421,7 @@ AllocaInst *CodegenLLVM::getMapKey(Map &map)
expr->accept(*this);
Value *offset_val = b_.CreateGEP(key, {b_.getInt64(0), b_.getInt64(offset)});
if (expr->type.type == Type::string)
b_.CreateMemcpy(offset_val, expr_, expr->type.size);
b_.CreateMemCpy(offset_val, expr_, expr->type.size, 1);
else
b_.CreateStore(expr_, offset_val);
offset += expr->type.size;
......@@ -451,7 +451,7 @@ AllocaInst *CodegenLLVM::getQuantizeMapKey(Map &map, Value *log2)
expr->accept(*this);
Value *offset_val = b_.CreateGEP(key, {b_.getInt64(0), b_.getInt64(offset)});
if (expr->type.type == Type::string)
b_.CreateMemcpy(offset_val, expr_, expr->type.size);
b_.CreateMemCpy(offset_val, expr_, expr->type.size, 1);
else
b_.CreateStore(expr_, offset_val);
offset += expr->type.size;
......
......@@ -92,18 +92,6 @@ AllocaInst *IRBuilderBPF::CreateAllocaMapKey(int bytes, const std::string &name)
return CreateAllocaBPF(ty, name);
}
void IRBuilderBPF::CreateMemcpy(Value *dst, Value *src, size_t len)
{
Function *memcpy_func = module_.getFunction("llvm.memcpy.p0i8.p0i8.i64");
CreateCall(memcpy_func, {dst, src, getInt64(len), getInt32(1), getInt1(0)}, "memcpy");
}
void IRBuilderBPF::CreateMemset(Value *dst, Value *val, size_t len)
{
Function *memset_func = module_.getFunction("llvm.memset.p0i8.i64");
CreateCall(memset_func, {dst, val, getInt64(len), getInt32(1), getInt1(0)}, "memset");
}
CallInst *IRBuilderBPF::CreateBpfPseudoCall(int mapfd)
{
Function *pseudo_func = module_.getFunction("llvm.bpf.pseudo");
......@@ -148,14 +136,14 @@ Value *IRBuilderBPF::CreateMapLookupElem(Map &map, AllocaInst *key)
SetInsertPoint(lookup_success_block);
if (map.type.type == Type::string)
CreateMemcpy(value, call, map.type.size);
CreateMemCpy(value, call, map.type.size, 1);
else
CreateStore(CreateLoad(getInt64Ty(), call), value);
CreateBr(lookup_merge_block);
SetInsertPoint(lookup_failure_block);
if (map.type.type == Type::string)
CreateMemset(value, getInt8(0), map.type.size);
CreateMemSet(value, getInt8(0), map.type.size, 1);
else
CreateStore(getInt64(0), value);
CreateBr(lookup_merge_block);
......
......@@ -21,8 +21,6 @@ public:
AllocaInst *CreateAllocaBPF(llvm::Type *ty, const std::string &name="");
AllocaInst *CreateAllocaBPF(const SizedType &stype, const std::string &name="");
AllocaInst *CreateAllocaMapKey(int bytes, const std::string &name="");
void CreateMemcpy(Value *dst, Value *src, size_t len);
void CreateMemset(Value *dst, Value *val, size_t len);
CallInst *CreateBpfPseudoCall(int mapfd);
CallInst *CreateBpfPseudoCall(Map &map);
Value *CreateMapLookupElem(Map &map, AllocaInst *key);
......
......@@ -782,7 +782,7 @@ entry:
%str = alloca [64 x i8], align 1
%1 = getelementptr inbounds [64 x i8], [64 x i8]* %str, i64 0, i64 0
call void @llvm.lifetime.start.p0i8(i64 -1, i8* nonnull %1)
%memset = call void @llvm.memset.p0i8.i64([64 x i8]* nonnull %str, i8 0, i64 64, i32 1, i1 false)
call void @llvm.memset.p0i8.i64(i8* nonnull %1, i8 0, i64 64, i32 1, i1 false)
%2 = bitcast i64* %arg0 to i8*
call void @llvm.lifetime.start.p0i8(i64 -1, i8* nonnull %2)
%3 = getelementptr i8, i8* %0, i64 112
......@@ -986,11 +986,11 @@ entry:
br i1 %map_lookup_cond, label %lookup_failure, label %lookup_success
lookup_success: ; preds = %entry
%memcpy = call void @llvm.memcpy.p0i8.p0i8.i64([64 x i8]* nonnull %lookup_elem_val, i8* nonnull %lookup_elem, i64 64, i32 1, i1 false)
call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull %4, i8* nonnull %lookup_elem, i64 64, i32 1, i1 false)
br label %lookup_merge
lookup_failure: ; preds = %entry
%memset = call void @llvm.memset.p0i8.i64([64 x i8]* nonnull %lookup_elem_val, i8 0, i64 64, i32 1, i1 false)
call void @llvm.memset.p0i8.i64(i8* nonnull %4, i8 0, i64 64, i32 1, i1 false)
br label %lookup_merge
lookup_merge: ; preds = %lookup_failure, %lookup_success
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment