Skip to content

more stuff split out from #9109 #9219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 16, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,8 @@ pub fn trans_external_path(ccx: &mut CrateContext, did: ast::DefId, t: ty::t)
};
}

pub fn invoke(bcx: @mut Block, llfn: ValueRef, llargs: ~[ValueRef])
pub fn invoke(bcx: @mut Block, llfn: ValueRef, llargs: ~[ValueRef],
attributes: &[(uint, lib::llvm::Attribute)])
-> (ValueRef, @mut Block) {
let _icx = push_ctxt("invoke_");
if bcx.unreachable {
Expand Down Expand Up @@ -865,7 +866,7 @@ pub fn invoke(bcx: @mut Block, llfn: ValueRef, llargs: ~[ValueRef])
debug!("arg: %x", ::std::cast::transmute(llarg));
}
}
let llresult = Call(bcx, llfn, llargs);
let llresult = Call(bcx, llfn, llargs, attributes);
return (llresult, bcx);
}
}
Expand Down Expand Up @@ -976,7 +977,7 @@ pub fn get_landing_pad(bcx: @mut Block) -> BasicBlockRef {
// Because we may have unwound across a stack boundary, we must call into
// the runtime to figure out which stack segment we are on and place the
// stack limit back into the TLS.
Call(pad_bcx, bcx.ccx().upcalls.reset_stack_limit, []);
Call(pad_bcx, bcx.ccx().upcalls.reset_stack_limit, [], []);

// We store the retval in a function-central alloca, so that calls to
// Resume can find it.
Expand Down Expand Up @@ -1071,7 +1072,7 @@ pub fn trans_trace(bcx: @mut Block, sp_opt: Option<Span>, trace_str: @str) {
let V_trace_str = PointerCast(bcx, V_trace_str, Type::i8p());
let V_filename = PointerCast(bcx, V_filename, Type::i8p());
let args = ~[V_trace_str, V_filename, C_int(ccx, V_line)];
Call(bcx, ccx.upcalls.trace, args);
Call(bcx, ccx.upcalls.trace, args, []);
}

pub fn ignore_lhs(_bcx: @mut Block, local: &ast::Local) -> bool {
Expand Down Expand Up @@ -1465,7 +1466,7 @@ pub fn call_memcpy(cx: @mut Block, dst: ValueRef, src: ValueRef, n_bytes: ValueR
let size = IntCast(cx, n_bytes, ccx.int_type);
let align = C_i32(align as i32);
let volatile = C_i1(false);
Call(cx, memcpy, [dst_ptr, src_ptr, size, align, volatile]);
Call(cx, memcpy, [dst_ptr, src_ptr, size, align, volatile], []);
}

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

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

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

pub fn trap(bcx: @mut Block) {
match bcx.ccx().intrinsics.find_equiv(& &"llvm.trap") {
Some(&x) => { Call(bcx, x, []); },
Some(&x) => { Call(bcx, x, [], []); },
_ => bcx.sess().bug("unbound llvm.trap in trap")
}
}
Expand Down
16 changes: 6 additions & 10 deletions src/librustc/middle/trans/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,20 +644,16 @@ pub fn InlineAsmCall(cx: @mut Block, asm: *c_char, cons: *c_char,
B(cx).inline_asm_call(asm, cons, inputs, output, volatile, alignstack, dia)
}

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

pub fn FastCall(cx: @mut Block, Fn: ValueRef, Args: &[ValueRef]) -> ValueRef {
pub fn CallWithConv(cx: @mut Block, Fn: ValueRef, Args: &[ValueRef], Conv: CallConv,
attributes: &[(uint, lib::llvm::Attribute)]) -> ValueRef {
if cx.unreachable { return _UndefReturn(cx, Fn); }
B(cx).call(Fn, Args)
}

pub fn CallWithConv(cx: @mut Block, Fn: ValueRef, Args: &[ValueRef],
Conv: CallConv, sret: bool) -> ValueRef {
if cx.unreachable { return _UndefReturn(cx, Fn); }
B(cx).call_with_conv(Fn, Args, Conv, sret)
B(cx).call_with_conv(Fn, Args, Conv, attributes)
}

pub fn AtomicFence(cx: @mut Block, order: AtomicOrdering) {
Expand Down
36 changes: 11 additions & 25 deletions src/librustc/middle/trans/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use lib::llvm::llvm;
use lib::llvm::{CallConv, AtomicBinOp, AtomicOrdering, AsmDialect};
use lib::llvm::{Opcode, IntPredicate, RealPredicate, False};
use lib::llvm::{ValueRef, BasicBlockRef, BuilderRef, ModuleRef};
use lib::llvm::{StructRetAttribute};
use middle::trans::base;
use middle::trans::common::*;
use middle::trans::machine::llalign_of_min;
Expand Down Expand Up @@ -748,7 +747,7 @@ impl Builder {
c, noname(), False, False)
}
};
self.call(asm, []);
self.call(asm, [], []);
}
}

Expand All @@ -773,42 +772,29 @@ impl Builder {
unsafe {
let v = llvm::LLVMInlineAsm(
fty.to_ref(), asm, cons, volatile, alignstack, dia as c_uint);
self.call(v, inputs)
self.call(v, inputs, [])
}
}

pub fn call(&self, llfn: ValueRef, args: &[ValueRef]) -> ValueRef {
pub fn call(&self, llfn: ValueRef, args: &[ValueRef],
attributes: &[(uint, lib::llvm::Attribute)]) -> ValueRef {
self.count_insn("call");
do args.as_imm_buf |ptr, len| {
unsafe {
llvm::LLVMBuildCall(self.llbuilder, llfn, ptr, len as c_uint, noname())
}
}
}

pub fn fastcall(&self, llfn: ValueRef, args: &[ValueRef]) -> ValueRef {
self.count_insn("fastcall");
unsafe {
let v = llvm::LLVMBuildCall(self.llbuilder, llfn, vec::raw::to_ptr(args),
args.len() as c_uint, noname());
lib::llvm::SetInstructionCallConv(v, lib::llvm::FastCallConv);
for &(idx, attr) in attributes.iter() {
llvm::LLVMAddInstrAttribute(v, idx as c_uint, attr as c_uint);
}
v
}
}

pub fn call_with_conv(&self, llfn: ValueRef, args: &[ValueRef],
conv: CallConv, sret: bool) -> ValueRef {
conv: CallConv, attributes: &[(uint, lib::llvm::Attribute)]) -> ValueRef {
self.count_insn("callwithconv");
unsafe {
let v = llvm::LLVMBuildCall(self.llbuilder, llfn, vec::raw::to_ptr(args),
args.len() as c_uint, noname());
lib::llvm::SetInstructionCallConv(v, conv);
if sret {
let return_slot = 1;
llvm::LLVMAddInstrAttribute(v, return_slot, StructRetAttribute as c_uint);
}
v
}
let v = self.call(llfn, args, attributes);
lib::llvm::SetInstructionCallConv(v, conv);
v
}

pub fn select(&self, cond: ValueRef, then_val: ValueRef, else_val: ValueRef) -> ValueRef {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ pub fn trans_call_inner(in_cx: @mut Block,
}

// Invoke the actual rust fn and update bcx/llresult.
let (llret, b) = base::invoke(bcx, llfn, llargs);
let (llret, b) = base::invoke(bcx, llfn, llargs, []);
bcx = b;
llresult = llret;

Expand Down
10 changes: 8 additions & 2 deletions src/librustc/middle/trans/foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use back::{link};
use std::libc::c_uint;
use lib::llvm::{ValueRef, Attribute, CallConv};
use lib::llvm::{ValueRef, Attribute, CallConv, StructRetAttribute};
use lib::llvm::llvm;
use lib;
use middle::trans::machine;
Expand Down Expand Up @@ -266,7 +266,13 @@ pub fn trans_native_call(bcx: @mut Block,
}
};

let llforeign_retval = CallWithConv(bcx, llfn, llargs_foreign, cc, fn_type.sret);
let attrs;
if fn_type.sret {
attrs = &[(1, StructRetAttribute)];
} else {
attrs = &[];
}
let llforeign_retval = CallWithConv(bcx, llfn, llargs_foreign, cc, attrs);

// If the function we just called does not use an outpointer,
// store the result into the rust outpointer. Cast the outpointer
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/trans/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ pub fn call_tydesc_glue_full(bcx: @mut Block,
}
};

Call(bcx, llfn, [C_null(Type::nil().ptr_to()), llrawptr]);
Call(bcx, llfn, [C_null(Type::nil().ptr_to()), llrawptr], []);
}

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

Call(bcx, dtor_addr, args);
Call(bcx, dtor_addr, args, []);

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

Call(bcx, dtor_addr, args);
Call(bcx, dtor_addr, args, []);

// Drop the fields
let field_tys = ty::struct_fields(bcx.tcx(), class_did, substs);
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/middle/trans/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
args[i] = get_param(bcx.fcx.llfn, first_real_arg + i);
}
let llfn = bcx.ccx().intrinsics.get_copy(&name);
Ret(bcx, Call(bcx, llfn, args.slice(0, num_args)));
Ret(bcx, Call(bcx, llfn, args.slice(0, num_args), []));
}

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

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

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

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

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