Move rust_vec_append_glue to rt.

This commit is contained in:
Rafael Ávila de Espíndola 2011-05-31 14:03:42 -04:00
parent b6971d94df
commit cc96eeafca
4 changed files with 140 additions and 143 deletions

View File

@ -29,7 +29,7 @@ RUNTIME_CS := rt/sync/timer.cpp \
rt/test/rust_test_runtime.cpp \
rt/test/rust_test_util.cpp
RUNTIME_LL := rt/new_exit.ll
RUNTIME_LL := rt/new_exit.ll rt/vec_append.ll
RUNTIME_S := rt/activate_glue.s rt/yield_glue.s

View File

@ -7997,147 +7997,6 @@ fn vec_p1_adjusted(&@block_ctxt bcx, ValueRef v,
ret bcx.build.GEP(vec_p0(bcx, v), [len]);
}
fn trans_vec_append_glue(@local_ctxt cx, &ast::span sp) {
auto llfn = cx.ccx.glues.vec_append_glue;
let ValueRef lltaskptr = llvm::LLVMGetParam(llfn, 0u);
let ValueRef llvec_tydesc = llvm::LLVMGetParam(llfn, 1u);
let ValueRef llelt_tydesc = llvm::LLVMGetParam(llfn, 2u);
let ValueRef lldst_vec_ptr = llvm::LLVMGetParam(llfn, 3u);
let ValueRef llsrc_vec = llvm::LLVMGetParam(llfn, 4u);
let ValueRef llskipnull = llvm::LLVMGetParam(llfn, 5u);
auto derived_tydescs =
map::mk_hashmap[ty::t, derived_tydesc_info](ty::hash_ty, ty::eq_ty);
auto llbbs = mk_standard_basic_blocks(llfn);
auto fcx = @rec(llfn=llfn,
lltaskptr=lltaskptr,
llenv=C_null(T_ptr(T_nil())),
llretptr=C_null(T_ptr(T_nil())),
mutable llallocas = llbbs._0,
mutable llcopyargs = llbbs._1,
mutable llderivedtydescs = llbbs._2,
mutable llself=none[self_vt],
mutable lliterbody=none[ValueRef],
llargs=new_def_hash[ValueRef](),
llobjfields=new_def_hash[ValueRef](),
lllocals=new_def_hash[ValueRef](),
llupvars=new_def_hash[ValueRef](),
mutable lltydescs=vec::empty[ValueRef](),
derived_tydescs=derived_tydescs,
sp=sp,
lcx=cx);
auto bcx = new_top_block_ctxt(fcx);
auto lltop = bcx.llbb;
auto lldst_vec = bcx.build.Load(lldst_vec_ptr);
// First the dst vec needs to grow to accommodate the src vec.
// To do this we have to figure out how many bytes to add.
auto llcopy_dst_ptr = alloca(bcx, T_int());
auto llnew_vec = bcx.build.Call(bcx.fcx.lcx.ccx.upcalls.vec_grow,
[bcx.fcx.lltaskptr, lldst_vec,
vec_fill_adjusted(bcx, llsrc_vec, llskipnull),
llcopy_dst_ptr, llvec_tydesc]);
maybe_name_value(bcx.fcx.lcx.ccx, llnew_vec, "llnew_vec");
auto copy_dst_cx = new_sub_block_ctxt(bcx, "copy new <- dst");
auto copy_src_cx = new_sub_block_ctxt(bcx, "copy new <- src");
auto pp0 = alloca(bcx, T_ptr(T_i8()));
bcx.build.Store(vec_p1_adjusted(bcx, llnew_vec, llskipnull), pp0);
maybe_name_value(bcx.fcx.lcx.ccx, pp0, "pp0");
bcx.build.CondBr(bcx.build.TruncOrBitCast
(bcx.build.Load(llcopy_dst_ptr),
T_i1()),
copy_dst_cx.llbb,
copy_src_cx.llbb);
fn copy_elts(&@block_ctxt cx,
ValueRef elt_tydesc,
ValueRef dst,
ValueRef src,
ValueRef n_bytes) -> result {
auto src_lim = cx.build.GEP(src, [n_bytes]);
maybe_name_value(cx.fcx.lcx.ccx, src_lim, "src_lim");
auto elt_llsz =
cx.build.Load(cx.build.GEP(elt_tydesc,
[C_int(0),
C_int(abi::tydesc_field_size)]));
maybe_name_value(cx.fcx.lcx.ccx, elt_llsz, "elt_llsz");
auto elt_llalign =
cx.build.Load(cx.build.GEP(elt_tydesc,
[C_int(0),
C_int(abi::tydesc_field_align)]));
maybe_name_value(cx.fcx.lcx.ccx, elt_llsz, "elt_llalign");
fn take_one(ValueRef elt_tydesc,
&@block_ctxt cx,
ValueRef dst, ValueRef src) -> result {
auto ti = none[@tydesc_info];
call_tydesc_glue_full(cx, src,
elt_tydesc,
abi::tydesc_field_take_glue, ti);
ret res(cx, src);
}
auto bcx = iter_sequence_raw(cx, dst, src, src_lim,
elt_llsz, bind take_one(elt_tydesc,
_, _, _)).bcx;
ret call_memmove(bcx, dst, src, n_bytes, elt_llalign);
}
// Copy any dst elements in, omitting null if doing str.
auto n_bytes = vec_fill_adjusted(copy_dst_cx, lldst_vec, llskipnull);
maybe_name_value(copy_dst_cx.fcx.lcx.ccx, n_bytes, "n_bytes");
copy_dst_cx = copy_elts(copy_dst_cx,
llelt_tydesc,
vec_p0(copy_dst_cx, llnew_vec),
vec_p0(copy_dst_cx, lldst_vec),
n_bytes).bcx;
put_vec_fill(copy_dst_cx, llnew_vec, vec_fill(copy_dst_cx, lldst_vec));
copy_dst_cx.build.Store(vec_p1_adjusted(copy_dst_cx, llnew_vec,
llskipnull), pp0);
copy_dst_cx.build.Br(copy_src_cx.llbb);
// Copy any src elements in, carrying along null if doing str.
n_bytes = vec_fill(copy_src_cx, llsrc_vec);
copy_src_cx = copy_elts(copy_src_cx,
llelt_tydesc,
copy_src_cx.build.Load(pp0),
vec_p0(copy_src_cx, llsrc_vec),
n_bytes).bcx;
put_vec_fill(copy_src_cx, llnew_vec,
copy_src_cx.build.Add(vec_fill_adjusted(copy_src_cx,
llnew_vec,
llskipnull),
n_bytes));
// Write new_vec back through the alias we were given.
copy_src_cx.build.Store(llnew_vec, lldst_vec_ptr);
copy_src_cx.build.RetVoid();
finish_fn(fcx, lltop);
}
fn make_glues(ModuleRef llmod, &type_names tn) -> @glue_fns {
ret @rec(yield_glue = decl_glue(llmod, tn, abi::yield_glue_name()),
no_op_type_glue = decl_no_op_type_glue(llmod, tn),
@ -8279,7 +8138,6 @@ fn trans_crate(&session::session sess, &@ast::crate crate,
collect_tag_ctors(ccx, crate);
trans_constants(ccx, crate);
trans_mod(cx, crate.node.module);
trans_vec_append_glue(cx, crate.span);
auto crate_map = create_crate_map(ccx);
if (!sess.get_opts().shared) {
trans_main_fn(cx, crate_map);

View File

@ -23,6 +23,7 @@ rust_process_wait
rust_ptr_eq
rust_run_program
rust_start
rust_vec_append_glue
size_of
squareroot
str_alloc

138
src/rt/vec_append.ll Normal file
View File

@ -0,0 +1,138 @@
%0 = type { i32, i32, i32, i32, [0 x i32] }
%task = type { i32, i32, i32, i32, i32, i32, i32, i32 }
%tydesc = type { %tydesc**, i32, i32, void (i1*, %task*, i1*, %tydesc**, i8*)*, void (i1*, %task*, i1*, %tydesc**, i8*)*, void (i1*, %task*, i1*, %tydesc**, i8*)*, void (i1*, %task*, i1*, %tydesc**, i8*)*, void (i1*, %task*, i1*, %tydesc**, i8*)*, void (i1*, %task*, i1*, %tydesc**, i8*)*, void (i1*, %task*, i1*, %tydesc**, i8*)*, void (i1*, %task*, i1*, %tydesc**, i8*, i8*, i8)* }
declare void @llvm.memmove.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
define fastcc void @rust_vec_append_glue(%task*, %tydesc*, %tydesc*, %0**, %0*, i1) {
allocas:
%6 = alloca i32
%7 = alloca i8*
br label %copy_args
copy_args: ; preds = %allocas
br label %derived_tydescs
derived_tydescs: ; preds = %copy_args
br label %8
; <label>:8 ; preds = %derived_tydescs
%9 = load %0** %3
%10 = getelementptr %0* %4, i32 0, i32 2
%11 = load i32* %10
%12 = sub i32 %11, 1
%13 = select i1 %5, i32 %12, i32 %11
%14 = call %0* @upcall_vec_grow(%task* %0, %0* %9, i32 %13, i32* %6, %tydesc* %1)
%15 = getelementptr %0* %14, i32 0, i32 2
%16 = load i32* %15
%17 = sub i32 %16, 1
%18 = select i1 %5, i32 %17, i32 %16
%19 = getelementptr %0* %14, i32 0, i32 4
%20 = bitcast [0 x i32]* %19 to i8*
%21 = getelementptr i8* %20, i32 %18
store i8* %21, i8** %7
%22 = load i32* %6
%23 = trunc i32 %22 to i1
br i1 %23, label %24, label %41
; <label>:24 ; preds = %8
%25 = getelementptr %0* %9, i32 0, i32 2
%26 = load i32* %25
%27 = sub i32 %26, 1
%28 = select i1 %5, i32 %27, i32 %26
%29 = getelementptr %0* %14, i32 0, i32 4
%30 = bitcast [0 x i32]* %29 to i8*
%31 = getelementptr %0* %9, i32 0, i32 4
%32 = bitcast [0 x i32]* %31 to i8*
%33 = getelementptr i8* %32, i32 %28
%34 = getelementptr %tydesc* %2, i32 0, i32 1
%35 = load i32* %34
%36 = getelementptr %tydesc* %2, i32 0, i32 2
%37 = load i32* %36
%38 = ptrtoint i8* %30 to i32
%39 = ptrtoint i8* %32 to i32
%40 = ptrtoint i8* %33 to i32
br label %55
; <label>:41 ; preds = %68, %8
%42 = getelementptr %0* %4, i32 0, i32 2
%43 = load i32* %42
%44 = load i8** %7
%45 = getelementptr %0* %4, i32 0, i32 4
%46 = bitcast [0 x i32]* %45 to i8*
%47 = getelementptr i8* %46, i32 %43
%48 = getelementptr %tydesc* %2, i32 0, i32 1
%49 = load i32* %48
%50 = getelementptr %tydesc* %2, i32 0, i32 2
%51 = load i32* %50
%52 = ptrtoint i8* %44 to i32
%53 = ptrtoint i8* %46 to i32
%54 = ptrtoint i8* %47 to i32
br label %79
; <label>:55 ; preds = %59, %24
%56 = phi i32 [ %38, %24 ], [ %66, %59 ]
%57 = phi i32 [ %39, %24 ], [ %67, %59 ]
%58 = icmp ult i32 %57, %40
br i1 %58, label %59, label %68
; <label>:59 ; preds = %55
%60 = inttoptr i32 %56 to i8*
%61 = inttoptr i32 %57 to i8*
%62 = getelementptr %tydesc* %2, i32 0, i32 0
%63 = load %tydesc*** %62
%64 = getelementptr %tydesc* %2, i32 0, i32 3
%65 = load void (i1*, %task*, i1*, %tydesc**, i8*)** %64
call fastcc void %65(i1* null, %task* %0, i1* null, %tydesc** %63, i8* %61)
%66 = add i32 %56, %35
%67 = add i32 %57, %35
br label %55
; <label>:68 ; preds = %55
call void @llvm.memmove.p0i8.p0i8.i32(i8* %30, i8* %32, i32 %28, i32 0, i1 false)
%69 = getelementptr %0* %9, i32 0, i32 2
%70 = load i32* %69
%71 = getelementptr %0* %14, i32 0, i32 2
store i32 %70, i32* %71
%72 = getelementptr %0* %14, i32 0, i32 2
%73 = load i32* %72
%74 = sub i32 %73, 1
%75 = select i1 %5, i32 %74, i32 %73
%76 = getelementptr %0* %14, i32 0, i32 4
%77 = bitcast [0 x i32]* %76 to i8*
%78 = getelementptr i8* %77, i32 %75
store i8* %78, i8** %7
br label %41
; <label>:79 ; preds = %83, %41
%80 = phi i32 [ %52, %41 ], [ %90, %83 ]
%81 = phi i32 [ %53, %41 ], [ %91, %83 ]
%82 = icmp ult i32 %81, %54
br i1 %82, label %83, label %92
; <label>:83 ; preds = %79
%84 = inttoptr i32 %80 to i8*
%85 = inttoptr i32 %81 to i8*
%86 = getelementptr %tydesc* %2, i32 0, i32 0
%87 = load %tydesc*** %86
%88 = getelementptr %tydesc* %2, i32 0, i32 3
%89 = load void (i1*, %task*, i1*, %tydesc**, i8*)** %88
call fastcc void %89(i1* null, %task* %0, i1* null, %tydesc** %87, i8* %85)
%90 = add i32 %80, %49
%91 = add i32 %81, %49
br label %79
; <label>:92 ; preds = %79
call void @llvm.memmove.p0i8.p0i8.i32(i8* %44, i8* %46, i32 %43, i32 0, i1 false)
%93 = getelementptr %0* %14, i32 0, i32 2
%94 = load i32* %93
%95 = sub i32 %94, 1
%96 = select i1 %5, i32 %95, i32 %94
%97 = add i32 %96, %43
%98 = getelementptr %0* %14, i32 0, i32 2
store i32 %97, i32* %98
store %0* %14, %0** %3
ret void
}
declare %0* @upcall_vec_grow(%task*, %0*, i32, i32*, %tydesc*)