From cc96eeafca395ae2889ddfea8dc3194f2ad1c80d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20=C3=81vila=20de=20Esp=C3=ADndola?= Date: Tue, 31 May 2011 14:03:42 -0400 Subject: [PATCH] Move rust_vec_append_glue to rt. --- mk/rt.mk | 2 +- src/comp/middle/trans.rs | 142 --------------------------------------- src/rt/rustrt.def.in | 1 + src/rt/vec_append.ll | 138 +++++++++++++++++++++++++++++++++++++ 4 files changed, 140 insertions(+), 143 deletions(-) create mode 100644 src/rt/vec_append.ll diff --git a/mk/rt.mk b/mk/rt.mk index 2b1617a07ee..8139f9e4e79 100644 --- a/mk/rt.mk +++ b/mk/rt.mk @@ -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 diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index eb44641b311..619854bc622 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -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); diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index baeac899f24..2c189d18d1d 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -23,6 +23,7 @@ rust_process_wait rust_ptr_eq rust_run_program rust_start +rust_vec_append_glue size_of squareroot str_alloc diff --git a/src/rt/vec_append.ll b/src/rt/vec_append.ll new file mode 100644 index 00000000000..28a6e793cdb --- /dev/null +++ b/src/rt/vec_append.ll @@ -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 + +;