Skip to content

Commit 1afd2b5

Browse files
committed
---
yaml --- r: 60758 b: refs/heads/auto c: b7f71e1 h: refs/heads/master v: v3
1 parent 5149b40 commit 1afd2b5

File tree

19 files changed

+334
-141
lines changed

19 files changed

+334
-141
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: 56a2e5dc22bfd0791b5e71dc89dde48fd3034e03
17+
refs/heads/auto: b7f71e1ee661ea0d5d9731fcf4779a452bbee486
1818
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1919
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c

branches/auto/src/librustc/middle/trans/base.rs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use middle::trans::foreign;
5252
use middle::trans::glue;
5353
use middle::trans::inline;
5454
use middle::trans::machine;
55-
use middle::trans::machine::llsize_of;
55+
use middle::trans::machine::{llalign_of_min, llsize_of};
5656
use middle::trans::meth;
5757
use middle::trans::monomorphize;
5858
use middle::trans::reachable;
@@ -1442,12 +1442,7 @@ pub fn with_cond(bcx: block, val: ValueRef, f: &fn(block) -> block) -> block {
14421442
next_cx
14431443
}
14441444

1445-
pub fn call_memcpy(cx: block, dst: ValueRef, src: ValueRef,
1446-
n_bytes: ValueRef) {
1447-
// FIXME (Related to #1645, I think?): Provide LLVM with better
1448-
// alignment information when the alignment is statically known (it must
1449-
// be nothing more than a constant int, or LLVM complains -- not even a
1450-
// constant element of a tydesc works).
1445+
pub fn call_memcpy(cx: block, dst: ValueRef, src: ValueRef, n_bytes: ValueRef, align: u32) {
14511446
let _icx = cx.insn_ctxt("call_memcpy");
14521447
let ccx = cx.ccx();
14531448
let key = match ccx.sess.targ_cfg.arch {
@@ -1462,7 +1457,7 @@ pub fn call_memcpy(cx: block, dst: ValueRef, src: ValueRef,
14621457
let src_ptr = PointerCast(cx, src, T_ptr(T_i8()));
14631458
let dst_ptr = PointerCast(cx, dst, T_ptr(T_i8()));
14641459
let size = IntCast(cx, n_bytes, ccx.int_type);
1465-
let align = C_i32(1i32);
1460+
let align = C_i32(align as i32);
14661461
let volatile = C_i1(false);
14671462
Call(cx, memcpy, [dst_ptr, src_ptr, size, align, volatile]);
14681463
}
@@ -1471,8 +1466,10 @@ pub fn memcpy_ty(bcx: block, dst: ValueRef, src: ValueRef, t: ty::t) {
14711466
let _icx = bcx.insn_ctxt("memcpy_ty");
14721467
let ccx = bcx.ccx();
14731468
if ty::type_is_structural(t) {
1474-
let llsz = llsize_of(ccx, type_of::type_of(ccx, t));
1475-
call_memcpy(bcx, dst, src, llsz);
1469+
let llty = type_of::type_of(ccx, t);
1470+
let llsz = llsize_of(ccx, llty);
1471+
let llalign = llalign_of_min(ccx, llty);
1472+
call_memcpy(bcx, dst, src, llsz, llalign as u32);
14761473
} else {
14771474
Store(bcx, Load(bcx, src), dst);
14781475
}
@@ -1615,10 +1612,11 @@ pub fn new_fn_ctxt_w_id(ccx: @CrateContext,
16151612
}
16161613
};
16171614
let is_immediate = ty::type_is_immediate(substd_output_type);
1618-
16191615
let fcx = @mut fn_ctxt_ {
16201616
llfn: llfndecl,
1621-
llenv: unsafe { llvm::LLVMGetParam(llfndecl, 1u as c_uint) },
1617+
llenv: unsafe {
1618+
llvm::LLVMGetUndef(T_ptr(T_i8()))
1619+
},
16221620
llretptr: None,
16231621
llstaticallocas: llbbs.sa,
16241622
llloadenv: None,
@@ -1637,7 +1635,9 @@ pub fn new_fn_ctxt_w_id(ccx: @CrateContext,
16371635
path: path,
16381636
ccx: @ccx
16391637
};
1640-
1638+
fcx.llenv = unsafe {
1639+
llvm::LLVMGetParam(llfndecl, fcx.env_arg_pos() as c_uint)
1640+
};
16411641
fcx.llretptr = Some(make_return_pointer(fcx, substd_output_type));
16421642
fcx
16431643
}
@@ -1693,7 +1693,7 @@ pub fn create_llargs_for_fn_args(cx: fn_ctxt,
16931693
// llvm::LLVMGetParam for each argument.
16941694
vec::from_fn(args.len(), |i| {
16951695
unsafe {
1696-
let arg_n = first_real_arg + i;
1696+
let arg_n = cx.arg_pos(i);
16971697
let arg = &args[i];
16981698
let llarg = llvm::LLVMGetParam(cx.llfn, arg_n as c_uint);
16991699

@@ -2296,19 +2296,26 @@ pub fn create_entry_wrapper(ccx: @CrateContext,
22962296
22972297
fn create_main(ccx: @CrateContext, main_llfn: ValueRef) -> ValueRef {
22982298
let nt = ty::mk_nil();
2299+
22992300
let llfty = type_of_fn(ccx, [], nt);
23002301
let llfdecl = decl_fn(ccx.llmod, "_rust_main",
23012302
lib::llvm::CCallConv, llfty);
23022303
23032304
let fcx = new_fn_ctxt(ccx, ~[], llfdecl, nt, None);
23042305
2306+
// the args vector built in create_entry_fn will need
2307+
// be updated if this assertion starts to fail.
2308+
assert!(fcx.has_immediate_return_value);
2309+
23052310
let bcx = top_scope_block(fcx, None);
23062311
let lltop = bcx.llbb;
23072312
23082313
// Call main.
2309-
let lloutputarg = C_null(T_ptr(T_i8()));
2310-
let llenvarg = unsafe { llvm::LLVMGetParam(llfdecl, 1 as c_uint) };
2311-
let args = ~[lloutputarg, llenvarg];
2314+
let llenvarg = unsafe {
2315+
let env_arg = fcx.env_arg_pos();
2316+
llvm::LLVMGetParam(llfdecl, env_arg as c_uint)
2317+
};
2318+
let args = ~[llenvarg];
23122319
let llresult = Call(bcx, main_llfn, args);
23132320
Store(bcx, llresult, fcx.llretptr.get());
23142321
@@ -2350,8 +2357,6 @@ pub fn create_entry_wrapper(ccx: @CrateContext,
23502357
trans_external_path(ccx, start_def_id, start_fn_type);
23512358
}
23522359
2353-
let retptr = llvm::LLVMBuildAlloca(bld, T_i8(), noname());
2354-
23552360
let crate_map = ccx.crate_map;
23562361
let opaque_crate_map = llvm::LLVMBuildPointerCast(bld,
23572362
crate_map,
@@ -2374,7 +2379,6 @@ pub fn create_entry_wrapper(ccx: @CrateContext,
23742379
bld, rust_main, T_ptr(T_i8()), noname());
23752380
23762381
~[
2377-
retptr,
23782382
C_null(T_opaque_box_ptr(ccx)),
23792383
opaque_rust_main,
23802384
llvm::LLVMGetParam(llfn, 0),
@@ -2387,7 +2391,6 @@ pub fn create_entry_wrapper(ccx: @CrateContext,
23872391
debug!("using user-defined start fn");
23882392
let args = {
23892393
~[
2390-
retptr,
23912394
C_null(T_opaque_box_ptr(ccx)),
23922395
llvm::LLVMGetParam(llfn, 0 as c_uint),
23932396
llvm::LLVMGetParam(llfn, 1 as c_uint),

branches/auto/src/librustc/middle/trans/callee.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -510,11 +510,7 @@ pub fn trans_call_inner(in_cx: block,
510510

511511
let mut llargs = ~[];
512512

513-
if ty::type_is_immediate(ret_ty) {
514-
unsafe {
515-
llargs.push(llvm::LLVMGetUndef(T_ptr(T_i8())));
516-
}
517-
} else {
513+
if !ty::type_is_immediate(ret_ty) {
518514
llargs.push(llretslot);
519515
}
520516

branches/auto/src/librustc/middle/trans/closure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ pub fn make_opaque_cbox_take_glue(
521521
[opaque_tydesc, sz],
522522
expr::SaveIn(rval));
523523
let cbox_out = PointerCast(bcx, Load(bcx, rval), llopaquecboxty);
524-
call_memcpy(bcx, cbox_out, cbox_in, sz);
524+
call_memcpy(bcx, cbox_out, cbox_in, sz, 1);
525525
Store(bcx, cbox_out, cboxptr);
526526

527527
// Take the (deeply cloned) type descriptor

branches/auto/src/librustc/middle/trans/common.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,30 @@ pub struct fn_ctxt_ {
351351
ccx: @@CrateContext
352352
}
353353

354+
pub impl fn_ctxt_ {
355+
pub fn arg_pos(&self, arg: uint) -> uint {
356+
if self.has_immediate_return_value {
357+
arg + 1u
358+
} else {
359+
arg + 2u
360+
}
361+
}
362+
363+
pub fn out_arg_pos(&self) -> uint {
364+
assert!(self.has_immediate_return_value);
365+
0u
366+
}
367+
368+
pub fn env_arg_pos(&self) -> uint {
369+
if !self.has_immediate_return_value {
370+
1u
371+
} else {
372+
0u
373+
}
374+
}
375+
376+
}
377+
354378
pub type fn_ctxt = @mut fn_ctxt_;
355379

356380
pub fn warn_not_to_commit(ccx: @CrateContext, msg: &str) {
@@ -660,9 +684,6 @@ pub fn mk_block(llbb: BasicBlockRef, parent: Option<block>, kind: block_kind,
660684
@mut block_(llbb, parent, kind, is_lpad, node_info, fcx)
661685
}
662686

663-
// First two args are retptr, env
664-
pub static first_real_arg: uint = 2u;
665-
666687
pub struct Result {
667688
bcx: block,
668689
val: ValueRef
@@ -962,8 +983,7 @@ pub fn T_tydesc(targ_cfg: @session::config) -> TypeRef {
962983
let tydescpp = T_ptr(T_ptr(tydesc));
963984
let pvoid = T_ptr(T_i8());
964985
let glue_fn_ty =
965-
T_ptr(T_fn([T_ptr(T_nil()), T_ptr(T_nil()), tydescpp,
966-
pvoid], T_void()));
986+
T_ptr(T_fn([T_ptr(T_nil()), tydescpp, pvoid], T_void()));
967987

968988
let int_type = T_int(targ_cfg);
969989
let elems =

branches/auto/src/librustc/middle/trans/foreign.rs

Lines changed: 75 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ fn build_shim_fn_(ccx: @CrateContext,
153153
let fcx = new_fn_ctxt(ccx, ~[], llshimfn, tys.fn_sig.output, None);
154154
let bcx = top_scope_block(fcx, None);
155155
let lltop = bcx.llbb;
156+
156157
let llargbundle = get_param(llshimfn, 0u);
157158
let llargvals = arg_builder(bcx, tys, llargbundle);
158159

@@ -437,11 +438,11 @@ pub fn trans_foreign_mod(ccx: @CrateContext,
437438
let llbasefn = base_fn(ccx, *link_name(ccx, item), tys, cc);
438439
let ty = ty::lookup_item_type(ccx.tcx,
439440
ast_util::local_def(item.id)).ty;
441+
let ret_ty = ty::ty_fn_ret(ty);
440442
let args = vec::from_fn(ty::ty_fn_args(ty).len(), |i| {
441-
get_param(decl, i + first_real_arg)
443+
get_param(decl, fcx.arg_pos(i))
442444
});
443445
let retval = Call(bcx, llbasefn, args);
444-
let ret_ty = ty::ty_fn_ret(ty);
445446
if !ty::type_is_nil(ret_ty) && !ty::type_is_bot(ret_ty) {
446447
Store(bcx, retval, fcx.llretptr.get());
447448
}
@@ -465,11 +466,11 @@ pub fn trans_foreign_mod(ccx: @CrateContext,
465466
set_fixed_stack_segment(fcx.llfn);
466467
let ty = ty::lookup_item_type(ccx.tcx,
467468
ast_util::local_def(item.id)).ty;
469+
let ret_ty = ty::ty_fn_ret(ty);
468470
let args = vec::from_fn(ty::ty_fn_args(ty).len(), |i| {
469-
get_param(decl, i + first_real_arg)
471+
get_param(decl, fcx.arg_pos(i))
470472
});
471473
let retval = Call(bcx, llbasefn, args);
472-
let ret_ty = ty::ty_fn_ret(ty);
473474
if !ty::type_is_nil(ret_ty) && !ty::type_is_bot(ret_ty) {
474475
Store(bcx, retval, fcx.llretptr.get());
475476
}
@@ -512,9 +513,9 @@ pub fn trans_foreign_mod(ccx: @CrateContext,
512513
let _icx = bcx.insn_ctxt("foreign::wrap::build_args");
513514
let ccx = bcx.ccx();
514515
let n = tys.llsig.llarg_tys.len();
515-
let implicit_args = first_real_arg; // return + env
516516
for uint::range(0, n) |i| {
517-
let mut llargval = get_param(llwrapfn, i + implicit_args);
517+
let arg_i = bcx.fcx.arg_pos(i);
518+
let mut llargval = get_param(llwrapfn, arg_i);
518519

519520
// In some cases, Rust will pass a pointer which the
520521
// native C type doesn't have. In that case, just
@@ -568,6 +569,7 @@ pub fn trans_intrinsic(ccx: @CrateContext,
568569

569570
let mut bcx = top_scope_block(fcx, None);
570571
let lltop = bcx.llbb;
572+
let first_real_arg = fcx.arg_pos(0u);
571573
match *ccx.sess.str_of(item.ident) {
572574
~"atomic_cxchg" => {
573575
let old = AtomicCmpXchg(bcx,
@@ -787,7 +789,7 @@ pub fn trans_intrinsic(ccx: @CrateContext,
787789
let llsrcptr = PointerCast(bcx, llsrcptr, T_ptr(T_i8()));
788790

789791
let llsize = llsize_of(ccx, llintype);
790-
call_memcpy(bcx, lldestptr, llsrcptr, llsize);
792+
call_memcpy(bcx, lldestptr, llsrcptr, llsize, 1);
791793
}
792794
}
793795
~"needs_drop" => {
@@ -846,44 +848,82 @@ pub fn trans_intrinsic(ccx: @CrateContext,
846848
Store(bcx, morestack_addr, fcx.llretptr.get());
847849
}
848850
~"memcpy32" => {
849-
let dst_ptr = get_param(decl, first_real_arg);
850-
let src_ptr = get_param(decl, first_real_arg + 1);
851-
let size = get_param(decl, first_real_arg + 2);
852-
let align = C_i32(1);
851+
let tp_ty = substs.tys[0];
852+
let lltp_ty = type_of::type_of(ccx, tp_ty);
853+
let align = C_i32(machine::llalign_of_min(ccx, lltp_ty) as i32);
854+
let size = C_i32(machine::llsize_of_real(ccx, lltp_ty) as i32);
855+
856+
let dst_ptr = PointerCast(bcx, get_param(decl, first_real_arg), T_ptr(T_i8()));
857+
let src_ptr = PointerCast(bcx, get_param(decl, first_real_arg + 1), T_ptr(T_i8()));
858+
let count = get_param(decl, first_real_arg + 2);
853859
let volatile = C_i1(false);
854-
let llfn = *bcx.ccx().intrinsics.get(
855-
&~"llvm.memcpy.p0i8.p0i8.i32");
856-
Call(bcx, llfn, [dst_ptr, src_ptr, size, align, volatile]);
860+
let llfn = *bcx.ccx().intrinsics.get(&~"llvm.memcpy.p0i8.p0i8.i32");
861+
Call(bcx, llfn, [dst_ptr, src_ptr, Mul(bcx, size, count), align, volatile]);
857862
}
858863
~"memcpy64" => {
859-
let dst_ptr = get_param(decl, first_real_arg);
860-
let src_ptr = get_param(decl, first_real_arg + 1);
861-
let size = get_param(decl, first_real_arg + 2);
862-
let align = C_i32(1);
864+
let tp_ty = substs.tys[0];
865+
let lltp_ty = type_of::type_of(ccx, tp_ty);
866+
let align = C_i32(machine::llalign_of_min(ccx, lltp_ty) as i32);
867+
let size = C_i64(machine::llsize_of_real(ccx, lltp_ty) as i64);
868+
869+
let dst_ptr = PointerCast(bcx, get_param(decl, first_real_arg), T_ptr(T_i8()));
870+
let src_ptr = PointerCast(bcx, get_param(decl, first_real_arg + 1), T_ptr(T_i8()));
871+
let count = get_param(decl, first_real_arg + 2);
863872
let volatile = C_i1(false);
864-
let llfn = *bcx.ccx().intrinsics.get(
865-
&~"llvm.memcpy.p0i8.p0i8.i64");
866-
Call(bcx, llfn, [dst_ptr, src_ptr, size, align, volatile]);
873+
let llfn = *bcx.ccx().intrinsics.get(&~"llvm.memcpy.p0i8.p0i8.i64");
874+
Call(bcx, llfn, [dst_ptr, src_ptr, Mul(bcx, size, count), align, volatile]);
867875
}
868876
~"memmove32" => {
869-
let dst_ptr = get_param(decl, first_real_arg);
870-
let src_ptr = get_param(decl, first_real_arg + 1);
871-
let size = get_param(decl, first_real_arg + 2);
872-
let align = C_i32(1);
877+
let tp_ty = substs.tys[0];
878+
let lltp_ty = type_of::type_of(ccx, tp_ty);
879+
let align = C_i32(machine::llalign_of_min(ccx, lltp_ty) as i32);
880+
let size = C_i32(machine::llsize_of_real(ccx, lltp_ty) as i32);
881+
882+
let dst_ptr = PointerCast(bcx, get_param(decl, first_real_arg), T_ptr(T_i8()));
883+
let src_ptr = PointerCast(bcx, get_param(decl, first_real_arg + 1), T_ptr(T_i8()));
884+
let count = get_param(decl, first_real_arg + 2);
873885
let volatile = C_i1(false);
874-
let llfn = *bcx.ccx().intrinsics.get(
875-
&~"llvm.memmove.p0i8.p0i8.i32");
876-
Call(bcx, llfn, [dst_ptr, src_ptr, size, align, volatile]);
886+
let llfn = *bcx.ccx().intrinsics.get(&~"llvm.memmove.p0i8.p0i8.i32");
887+
Call(bcx, llfn, [dst_ptr, src_ptr, Mul(bcx, size, count), align, volatile]);
877888
}
878889
~"memmove64" => {
879-
let dst_ptr = get_param(decl, first_real_arg);
880-
let src_ptr = get_param(decl, first_real_arg + 1);
881-
let size = get_param(decl, first_real_arg + 2);
882-
let align = C_i32(1);
890+
let tp_ty = substs.tys[0];
891+
let lltp_ty = type_of::type_of(ccx, tp_ty);
892+
let align = C_i32(machine::llalign_of_min(ccx, lltp_ty) as i32);
893+
let size = C_i64(machine::llsize_of_real(ccx, lltp_ty) as i64);
894+
895+
let dst_ptr = PointerCast(bcx, get_param(decl, first_real_arg), T_ptr(T_i8()));
896+
let src_ptr = PointerCast(bcx, get_param(decl, first_real_arg + 1), T_ptr(T_i8()));
897+
let count = get_param(decl, first_real_arg + 2);
898+
let volatile = C_i1(false);
899+
let llfn = *bcx.ccx().intrinsics.get(&~"llvm.memmove.p0i8.p0i8.i64");
900+
Call(bcx, llfn, [dst_ptr, src_ptr, Mul(bcx, size, count), align, volatile]);
901+
}
902+
~"memset32" => {
903+
let tp_ty = substs.tys[0];
904+
let lltp_ty = type_of::type_of(ccx, tp_ty);
905+
let align = C_i32(machine::llalign_of_min(ccx, lltp_ty) as i32);
906+
let size = C_i32(machine::llsize_of_real(ccx, lltp_ty) as i32);
907+
908+
let dst_ptr = PointerCast(bcx, get_param(decl, first_real_arg), T_ptr(T_i8()));
909+
let val = get_param(decl, first_real_arg + 1);
910+
let count = get_param(decl, first_real_arg + 2);
883911
let volatile = C_i1(false);
884-
let llfn = *bcx.ccx().intrinsics.get(
885-
&~"llvm.memmove.p0i8.p0i8.i64");
886-
Call(bcx, llfn, [dst_ptr, src_ptr, size, align, volatile]);
912+
let llfn = *bcx.ccx().intrinsics.get(&~"llvm.memset.p0i8.i32");
913+
Call(bcx, llfn, [dst_ptr, val, Mul(bcx, size, count), align, volatile]);
914+
}
915+
~"memset64" => {
916+
let tp_ty = substs.tys[0];
917+
let lltp_ty = type_of::type_of(ccx, tp_ty);
918+
let align = C_i32(machine::llalign_of_min(ccx, lltp_ty) as i32);
919+
let size = C_i64(machine::llsize_of_real(ccx, lltp_ty) as i64);
920+
921+
let dst_ptr = PointerCast(bcx, get_param(decl, first_real_arg), T_ptr(T_i8()));
922+
let val = get_param(decl, first_real_arg + 1);
923+
let count = get_param(decl, first_real_arg + 2);
924+
let volatile = C_i1(false);
925+
let llfn = *bcx.ccx().intrinsics.get(&~"llvm.memset.p0i8.i64");
926+
Call(bcx, llfn, [dst_ptr, val, Mul(bcx, size, count), align, volatile]);
887927
}
888928
~"sqrtf32" => {
889929
let x = get_param(decl, first_real_arg);
@@ -1231,8 +1271,6 @@ pub fn trans_foreign_fn(ccx: @CrateContext,
12311271
if !ty::type_is_immediate(tys.fn_sig.output) {
12321272
let llretptr = load_inbounds(bcx, llargbundle, [0u, n]);
12331273
llargvals.push(llretptr);
1234-
} else {
1235-
llargvals.push(C_null(T_ptr(T_i8())));
12361274
}
12371275

12381276
let llenvptr = C_null(T_opaque_box_ptr(bcx.ccx()));

0 commit comments

Comments
 (0)