Skip to content

Commit 8d8eba1

Browse files
committed
Generalized memset and memcpy
1 parent 496edbe commit 8d8eba1

File tree

23 files changed

+430
-363
lines changed

23 files changed

+430
-363
lines changed

src/librustc_codegen_llvm/abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use type_::Type;
1919
use type_of::{LayoutLlvmExt, PointerKind};
2020
use value::Value;
2121

22-
use interfaces::{BuilderMethods, ConstMethods, TypeMethods};
22+
use interfaces::{BuilderMethods, ConstMethods, BaseTypeMethods, DerivedTypeMethods};
2323

2424
use rustc_target::abi::{LayoutOf, Size, TyLayout, Abi as LayoutAbi};
2525
use rustc::ty::{self, Ty};

src/librustc_codegen_llvm/asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use builder::Builder;
1515
use value::Value;
1616

1717
use rustc::hir;
18-
use interfaces::{BuilderMethods, ConstMethods, TypeMethods};
18+
use interfaces::{BuilderMethods, ConstMethods, BaseTypeMethods};
1919

2020
use mir::place::PlaceRef;
2121
use mir::operand::OperandValue;

src/librustc_codegen_llvm/base.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ use CrateInfo;
7373
use rustc_data_structures::small_c_str::SmallCStr;
7474
use rustc_data_structures::sync::Lrc;
7575

76-
use interfaces::{BuilderMethods, ConstMethods, TypeMethods, Backend};
76+
use interfaces::{BuilderMethods, ConstMethods, BaseTypeMethods, DerivedTypeMethods, Backend, DerivedIntrinsicMethods};
7777

7878
use std::any::Any;
7979
use std::cmp;
@@ -432,11 +432,11 @@ pub fn to_immediate_scalar<'a, 'll, 'tcx, Builder : BuilderMethods<'a, 'll, 'tcx
432432
val
433433
}
434434

435-
pub fn call_memcpy<'a, 'll: 'a, 'tcx: 'll>(
436-
bx: &Builder<'_ ,'ll, '_, &'ll Value>,
437-
dst: &'ll Value,
438-
src: &'ll Value,
439-
n_bytes: &'ll Value,
435+
pub fn call_memcpy<'a, 'll: 'a, 'tcx: 'll, Builder : BuilderMethods<'a, 'll, 'tcx>>(
436+
bx: &Builder,
437+
dst: <Builder::CodegenCx as Backend>::Value,
438+
src: <Builder::CodegenCx as Backend>::Value,
439+
n_bytes: <Builder::CodegenCx as Backend>::Value,
440440
align: Align,
441441
flags: MemFlags,
442442
) {
@@ -448,21 +448,21 @@ pub fn call_memcpy<'a, 'll: 'a, 'tcx: 'll>(
448448
return;
449449
}
450450
let cx = bx.cx();
451-
let ptr_width = &cx.sess().target.target.target_pointer_width;
451+
let ptr_width = &bx.sess().target.target.target_pointer_width;
452452
let key = format!("llvm.memcpy.p0i8.p0i8.i{}", ptr_width);
453453
let memcpy = cx.get_intrinsic(&key);
454454
let src_ptr = bx.pointercast(src, cx.type_i8p());
455455
let dst_ptr = bx.pointercast(dst, cx.type_i8p());
456-
let size = bx.intcast(n_bytes, cx.isize_ty, false);
456+
let size = bx.intcast(n_bytes, cx.type_isize(), false);
457457
let align = cx.const_i32(align.abi() as i32);
458458
let volatile = cx.const_bool(flags.contains(MemFlags::VOLATILE));
459459
bx.call(memcpy, &[dst_ptr, src_ptr, size, align, volatile], None);
460460
}
461461

462-
pub fn memcpy_ty<'a, 'll: 'a, 'tcx: 'll>(
463-
bx: &Builder<'_ ,'ll, '_, &'ll Value>,
464-
dst: &'ll Value,
465-
src: &'ll Value,
462+
pub fn memcpy_ty<'a, 'll: 'a, 'tcx: 'll, Builder : BuilderMethods<'a, 'll, 'tcx>>(
463+
bx: &Builder,
464+
dst: <Builder::CodegenCx as Backend>::Value,
465+
src: <Builder::CodegenCx as Backend>::Value,
466466
layout: TyLayout<'tcx>,
467467
align: Align,
468468
flags: MemFlags,
@@ -475,15 +475,15 @@ pub fn memcpy_ty<'a, 'll: 'a, 'tcx: 'll>(
475475
call_memcpy(bx, dst, src, bx.cx().const_usize(size), align, flags);
476476
}
477477

478-
pub fn call_memset(
479-
bx: &Builder<'_, 'll, '_, &'ll Value>,
480-
ptr: &'ll Value,
481-
fill_byte: &'ll Value,
482-
size: &'ll Value,
483-
align: &'ll Value,
478+
pub fn call_memset<'a, 'll: 'a, 'tcx: 'll, Builder : BuilderMethods<'a, 'll, 'tcx>>(
479+
bx: &Builder,
480+
ptr: <Builder::CodegenCx as Backend>::Value,
481+
fill_byte: <Builder::CodegenCx as Backend>::Value,
482+
size: <Builder::CodegenCx as Backend>::Value,
483+
align: <Builder::CodegenCx as Backend>::Value,
484484
volatile: bool,
485-
) -> &'ll Value {
486-
let ptr_width = &bx.cx().sess().target.target.target_pointer_width;
485+
) -> <Builder::CodegenCx as Backend>::Value {
486+
let ptr_width = &bx.sess().target.target.target_pointer_width;
487487
let intrinsic_key = format!("llvm.memset.p0i8.i{}", ptr_width);
488488
let llintrinsicfn = bx.cx().get_intrinsic(&intrinsic_key);
489489
let volatile = bx.cx().const_bool(volatile);

src/librustc_codegen_llvm/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc::ty::TyCtxt;
1919
use rustc::ty::layout::{Align, Size};
2020
use rustc::session::{config, Session};
2121
use rustc_data_structures::small_c_str::SmallCStr;
22-
use interfaces::{BuilderMethods, ConstMethods, TypeMethods};
22+
use interfaces::{BuilderMethods, ConstMethods, BaseTypeMethods, DerivedTypeMethods, DerivedIntrinsicMethods};
2323
use syntax;
2424

2525
use std::borrow::Cow;

src/librustc_codegen_llvm/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use llvm;
2222
use monomorphize::Instance;
2323
use type_of::LayoutLlvmExt;
2424
use value::Value;
25-
use interfaces::TypeMethods;
25+
use interfaces::BaseTypeMethods;
2626

2727
use rustc::hir::def_id::DefId;
2828
use rustc::ty::{self, TypeFoldable};

src/librustc_codegen_llvm/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use declare;
2323
use type_::Type;
2424
use type_of::LayoutLlvmExt;
2525
use value::Value;
26-
use interfaces::{Backend, ConstMethods, TypeMethods};
26+
use interfaces::{Backend, ConstMethods, BaseTypeMethods};
2727

2828
use rustc::ty::{self, Ty, TyCtxt};
2929
use rustc::ty::layout::{HasDataLayout, LayoutOf};
@@ -49,7 +49,7 @@ pub fn type_is_freeze<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bo
4949
ty.is_freeze(tcx, ty::ParamEnv::reveal_all(), DUMMY_SP)
5050
}
5151

52-
pub struct OperandBundleDef<'a, Value : 'a> {
52+
pub struct OperandBundleDef<'a, Value> {
5353
pub name: &'a str,
5454
pub val: Value
5555
}

src/librustc_codegen_llvm/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use type_::Type;
2424
use type_of::LayoutLlvmExt;
2525
use value::Value;
2626
use rustc::ty::{self, Ty};
27-
use interfaces::TypeMethods;
27+
use interfaces::{BaseTypeMethods, DerivedTypeMethods};
2828

2929
use rustc::ty::layout::{Align, LayoutOf};
3030

0 commit comments

Comments
 (0)