Skip to content

Commit 2de2fb1

Browse files
committed
auto merge of #9219 : thestinger/rust/function-split, r=alexcrichton
2 parents 72f62ab + 6d0a847 commit 2de2fb1

File tree

7 files changed

+44
-55
lines changed

7 files changed

+44
-55
lines changed

src/librustc/middle/trans/base.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,8 @@ pub fn trans_external_path(ccx: &mut CrateContext, did: ast::DefId, t: ty::t)
825825
};
826826
}
827827
828-
pub fn invoke(bcx: @mut Block, llfn: ValueRef, llargs: ~[ValueRef])
828+
pub fn invoke(bcx: @mut Block, llfn: ValueRef, llargs: ~[ValueRef],
829+
attributes: &[(uint, lib::llvm::Attribute)])
829830
-> (ValueRef, @mut Block) {
830831
let _icx = push_ctxt("invoke_");
831832
if bcx.unreachable {
@@ -865,7 +866,7 @@ pub fn invoke(bcx: @mut Block, llfn: ValueRef, llargs: ~[ValueRef])
865866
debug!("arg: %x", ::std::cast::transmute(llarg));
866867
}
867868
}
868-
let llresult = Call(bcx, llfn, llargs);
869+
let llresult = Call(bcx, llfn, llargs, attributes);
869870
return (llresult, bcx);
870871
}
871872
}
@@ -976,7 +977,7 @@ pub fn get_landing_pad(bcx: @mut Block) -> BasicBlockRef {
976977
// Because we may have unwound across a stack boundary, we must call into
977978
// the runtime to figure out which stack segment we are on and place the
978979
// stack limit back into the TLS.
979-
Call(pad_bcx, bcx.ccx().upcalls.reset_stack_limit, []);
980+
Call(pad_bcx, bcx.ccx().upcalls.reset_stack_limit, [], []);
980981

981982
// We store the retval in a function-central alloca, so that calls to
982983
// Resume can find it.
@@ -1071,7 +1072,7 @@ pub fn trans_trace(bcx: @mut Block, sp_opt: Option<Span>, trace_str: @str) {
10711072
let V_trace_str = PointerCast(bcx, V_trace_str, Type::i8p());
10721073
let V_filename = PointerCast(bcx, V_filename, Type::i8p());
10731074
let args = ~[V_trace_str, V_filename, C_int(ccx, V_line)];
1074-
Call(bcx, ccx.upcalls.trace, args);
1075+
Call(bcx, ccx.upcalls.trace, args, []);
10751076
}
10761077
10771078
pub fn ignore_lhs(_bcx: @mut Block, local: &ast::Local) -> bool {
@@ -1465,7 +1466,7 @@ pub fn call_memcpy(cx: @mut Block, dst: ValueRef, src: ValueRef, n_bytes: ValueR
14651466
let size = IntCast(cx, n_bytes, ccx.int_type);
14661467
let align = C_i32(align as i32);
14671468
let volatile = C_i1(false);
1468-
Call(cx, memcpy, [dst_ptr, src_ptr, size, align, volatile]);
1469+
Call(cx, memcpy, [dst_ptr, src_ptr, size, align, volatile], []);
14691470
}
14701471

14711472
pub fn memcpy_ty(bcx: @mut Block, dst: ValueRef, src: ValueRef, t: ty::t) {
@@ -1510,7 +1511,7 @@ pub fn memzero(b: &Builder, llptr: ValueRef, ty: Type) {
15101511
let size = machine::llsize_of(ccx, ty);
15111512
let align = C_i32(llalign_of_min(ccx, ty) as i32);
15121513
let volatile = C_i1(false);
1513-
b.call(llintrinsicfn, [llptr, llzeroval, size, align, volatile]);
1514+
b.call(llintrinsicfn, [llptr, llzeroval, size, align, volatile], []);
15141515
}
15151516

15161517
pub fn alloc_ty(bcx: @mut Block, t: ty::t, name: &str) -> ValueRef {
@@ -2353,7 +2354,7 @@ pub fn create_entry_wrapper(ccx: @mut CrateContext,
23532354
llvm::LLVMGetParam(llfdecl, env_arg as c_uint)
23542355
};
23552356
let args = ~[llenvarg];
2356-
Call(bcx, main_llfn, args);
2357+
Call(bcx, main_llfn, args, []);
23572358

23582359
finish_fn(fcx, bcx);
23592360
return llfdecl;
@@ -2808,7 +2809,7 @@ pub fn declare_dbg_intrinsics(llmod: ModuleRef, intrinsics: &mut HashMap<&'stati
28082809

28092810
pub fn trap(bcx: @mut Block) {
28102811
match bcx.ccx().intrinsics.find_equiv(& &"llvm.trap") {
2811-
Some(&x) => { Call(bcx, x, []); },
2812+
Some(&x) => { Call(bcx, x, [], []); },
28122813
_ => bcx.sess().bug("unbound llvm.trap in trap")
28132814
}
28142815
}

src/librustc/middle/trans/build.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -644,20 +644,16 @@ pub fn InlineAsmCall(cx: @mut Block, asm: *c_char, cons: *c_char,
644644
B(cx).inline_asm_call(asm, cons, inputs, output, volatile, alignstack, dia)
645645
}
646646

647-
pub fn Call(cx: @mut Block, Fn: ValueRef, Args: &[ValueRef]) -> ValueRef {
647+
pub fn Call(cx: @mut Block, Fn: ValueRef, Args: &[ValueRef],
648+
attributes: &[(uint, lib::llvm::Attribute)]) -> ValueRef {
648649
if cx.unreachable { return _UndefReturn(cx, Fn); }
649-
B(cx).call(Fn, Args)
650+
B(cx).call(Fn, Args, attributes)
650651
}
651652

652-
pub fn FastCall(cx: @mut Block, Fn: ValueRef, Args: &[ValueRef]) -> ValueRef {
653+
pub fn CallWithConv(cx: @mut Block, Fn: ValueRef, Args: &[ValueRef], Conv: CallConv,
654+
attributes: &[(uint, lib::llvm::Attribute)]) -> ValueRef {
653655
if cx.unreachable { return _UndefReturn(cx, Fn); }
654-
B(cx).call(Fn, Args)
655-
}
656-
657-
pub fn CallWithConv(cx: @mut Block, Fn: ValueRef, Args: &[ValueRef],
658-
Conv: CallConv, sret: bool) -> ValueRef {
659-
if cx.unreachable { return _UndefReturn(cx, Fn); }
660-
B(cx).call_with_conv(Fn, Args, Conv, sret)
656+
B(cx).call_with_conv(Fn, Args, Conv, attributes)
661657
}
662658

663659
pub fn AtomicFence(cx: @mut Block, order: AtomicOrdering) {

src/librustc/middle/trans/builder.rs

+11-25
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use lib::llvm::llvm;
1313
use lib::llvm::{CallConv, AtomicBinOp, AtomicOrdering, AsmDialect};
1414
use lib::llvm::{Opcode, IntPredicate, RealPredicate, False};
1515
use lib::llvm::{ValueRef, BasicBlockRef, BuilderRef, ModuleRef};
16-
use lib::llvm::{StructRetAttribute};
1716
use middle::trans::base;
1817
use middle::trans::common::*;
1918
use middle::trans::machine::llalign_of_min;
@@ -748,7 +747,7 @@ impl Builder {
748747
c, noname(), False, False)
749748
}
750749
};
751-
self.call(asm, []);
750+
self.call(asm, [], []);
752751
}
753752
}
754753

@@ -773,42 +772,29 @@ impl Builder {
773772
unsafe {
774773
let v = llvm::LLVMInlineAsm(
775774
fty.to_ref(), asm, cons, volatile, alignstack, dia as c_uint);
776-
self.call(v, inputs)
775+
self.call(v, inputs, [])
777776
}
778777
}
779778

780-
pub fn call(&self, llfn: ValueRef, args: &[ValueRef]) -> ValueRef {
779+
pub fn call(&self, llfn: ValueRef, args: &[ValueRef],
780+
attributes: &[(uint, lib::llvm::Attribute)]) -> ValueRef {
781781
self.count_insn("call");
782-
do args.as_imm_buf |ptr, len| {
783-
unsafe {
784-
llvm::LLVMBuildCall(self.llbuilder, llfn, ptr, len as c_uint, noname())
785-
}
786-
}
787-
}
788-
789-
pub fn fastcall(&self, llfn: ValueRef, args: &[ValueRef]) -> ValueRef {
790-
self.count_insn("fastcall");
791782
unsafe {
792783
let v = llvm::LLVMBuildCall(self.llbuilder, llfn, vec::raw::to_ptr(args),
793784
args.len() as c_uint, noname());
794-
lib::llvm::SetInstructionCallConv(v, lib::llvm::FastCallConv);
785+
for &(idx, attr) in attributes.iter() {
786+
llvm::LLVMAddInstrAttribute(v, idx as c_uint, attr as c_uint);
787+
}
795788
v
796789
}
797790
}
798791

799792
pub fn call_with_conv(&self, llfn: ValueRef, args: &[ValueRef],
800-
conv: CallConv, sret: bool) -> ValueRef {
793+
conv: CallConv, attributes: &[(uint, lib::llvm::Attribute)]) -> ValueRef {
801794
self.count_insn("callwithconv");
802-
unsafe {
803-
let v = llvm::LLVMBuildCall(self.llbuilder, llfn, vec::raw::to_ptr(args),
804-
args.len() as c_uint, noname());
805-
lib::llvm::SetInstructionCallConv(v, conv);
806-
if sret {
807-
let return_slot = 1;
808-
llvm::LLVMAddInstrAttribute(v, return_slot, StructRetAttribute as c_uint);
809-
}
810-
v
811-
}
795+
let v = self.call(llfn, args, attributes);
796+
lib::llvm::SetInstructionCallConv(v, conv);
797+
v
812798
}
813799

814800
pub fn select(&self, cond: ValueRef, then_val: ValueRef, else_val: ValueRef) -> ValueRef {

src/librustc/middle/trans/callee.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ pub fn trans_call_inner(in_cx: @mut Block,
707707
}
708708

709709
// Invoke the actual rust fn and update bcx/llresult.
710-
let (llret, b) = base::invoke(bcx, llfn, llargs);
710+
let (llret, b) = base::invoke(bcx, llfn, llargs, []);
711711
bcx = b;
712712
llresult = llret;
713713

src/librustc/middle/trans/foreign.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
use back::{link};
1313
use std::libc::c_uint;
14-
use lib::llvm::{ValueRef, Attribute, CallConv};
14+
use lib::llvm::{ValueRef, Attribute, CallConv, StructRetAttribute};
1515
use lib::llvm::llvm;
1616
use lib;
1717
use middle::trans::machine;
@@ -266,7 +266,13 @@ pub fn trans_native_call(bcx: @mut Block,
266266
}
267267
};
268268

269-
let llforeign_retval = CallWithConv(bcx, llfn, llargs_foreign, cc, fn_type.sret);
269+
let attrs;
270+
if fn_type.sret {
271+
attrs = &[(1, StructRetAttribute)];
272+
} else {
273+
attrs = &[];
274+
}
275+
let llforeign_retval = CallWithConv(bcx, llfn, llargs_foreign, cc, attrs);
270276

271277
// If the function we just called does not use an outpointer,
272278
// store the result into the rust outpointer. Cast the outpointer

src/librustc/middle/trans/glue.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ pub fn call_tydesc_glue_full(bcx: @mut Block,
332332
}
333333
};
334334

335-
Call(bcx, llfn, [C_null(Type::nil().ptr_to()), llrawptr]);
335+
Call(bcx, llfn, [C_null(Type::nil().ptr_to()), llrawptr], []);
336336
}
337337

338338
// See [Note-arg-mode]
@@ -424,7 +424,7 @@ pub fn trans_struct_drop_flag(bcx: @mut Block, t: ty::t, v0: ValueRef, dtor_did:
424424
let self_arg = PointerCast(bcx, v0, params[0]);
425425
let args = ~[self_arg];
426426

427-
Call(bcx, dtor_addr, args);
427+
Call(bcx, dtor_addr, args, []);
428428

429429
// Drop the fields
430430
let field_tys = ty::struct_fields(bcx.tcx(), class_did, substs);
@@ -459,7 +459,7 @@ pub fn trans_struct_drop(mut bcx: @mut Block, t: ty::t, v0: ValueRef, dtor_did:
459459
let self_arg = PointerCast(bcx, v0, params[0]);
460460
let args = ~[self_arg];
461461

462-
Call(bcx, dtor_addr, args);
462+
Call(bcx, dtor_addr, args, []);
463463

464464
// Drop the fields
465465
let field_tys = ty::struct_fields(bcx.tcx(), class_did, substs);

src/librustc/middle/trans/intrinsic.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
4949
args[i] = get_param(bcx.fcx.llfn, first_real_arg + i);
5050
}
5151
let llfn = bcx.ccx().intrinsics.get_copy(&name);
52-
Ret(bcx, Call(bcx, llfn, args.slice(0, num_args)));
52+
Ret(bcx, Call(bcx, llfn, args.slice(0, num_args), []));
5353
}
5454

5555
fn with_overflow_instrinsic(bcx: @mut Block, name: &'static str) {
@@ -59,7 +59,7 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
5959
let llfn = bcx.ccx().intrinsics.get_copy(&name);
6060

6161
// convert `i1` to a `bool`, and write to the out parameter
62-
let val = Call(bcx, llfn, [a, b]);
62+
let val = Call(bcx, llfn, [a, b], []);
6363
let result = ExtractValue(bcx, val, 0);
6464
let overflow = ZExt(bcx, ExtractValue(bcx, val, 1), Type::bool());
6565
let retptr = get_param(bcx.fcx.llfn, bcx.fcx.out_arg_pos());
@@ -87,7 +87,7 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
8787
let count = get_param(decl, first_real_arg + 2);
8888
let volatile = C_i1(false);
8989
let llfn = bcx.ccx().intrinsics.get_copy(&name);
90-
Call(bcx, llfn, [dst_ptr, src_ptr, Mul(bcx, size, count), align, volatile]);
90+
Call(bcx, llfn, [dst_ptr, src_ptr, Mul(bcx, size, count), align, volatile], []);
9191
RetVoid(bcx);
9292
}
9393

@@ -108,15 +108,15 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
108108
let count = get_param(decl, first_real_arg + 2);
109109
let volatile = C_i1(false);
110110
let llfn = bcx.ccx().intrinsics.get_copy(&name);
111-
Call(bcx, llfn, [dst_ptr, val, Mul(bcx, size, count), align, volatile]);
111+
Call(bcx, llfn, [dst_ptr, val, Mul(bcx, size, count), align, volatile], []);
112112
RetVoid(bcx);
113113
}
114114

115115
fn count_zeros_intrinsic(bcx: @mut Block, name: &'static str) {
116116
let x = get_param(bcx.fcx.llfn, bcx.fcx.arg_pos(0u));
117117
let y = C_i1(false);
118118
let llfn = bcx.ccx().intrinsics.get_copy(&name);
119-
Ret(bcx, Call(bcx, llfn, [x, y]));
119+
Ret(bcx, Call(bcx, llfn, [x, y], []));
120120
}
121121

122122
let output_type = ty::ty_fn_ret(ty::node_id_to_type(ccx.tcx, item.id));
@@ -366,7 +366,7 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
366366
}
367367
"frame_address" => {
368368
let frameaddress = ccx.intrinsics.get_copy(& &"llvm.frameaddress");
369-
let frameaddress_val = Call(bcx, frameaddress, [C_i32(0i32)]);
369+
let frameaddress_val = Call(bcx, frameaddress, [C_i32(0i32)], []);
370370
let star_u8 = ty::mk_imm_ptr(
371371
bcx.tcx(),
372372
ty::mk_mach_uint(ast::ty_u8));

0 commit comments

Comments
 (0)