use crate::type_of::LayoutLlvmExt;
use crate::value::Value;
-use rustc_codegen_ssa::MemFlags;
-use rustc_codegen_ssa::mir::place::PlaceRef;
+use rustc::bug;
+use rustc::ty::layout::{self};
+use rustc::ty::Ty;
use rustc_codegen_ssa::mir::operand::OperandValue;
+use rustc_codegen_ssa::mir::place::PlaceRef;
use rustc_codegen_ssa::traits::*;
+use rustc_codegen_ssa::MemFlags;
use rustc_target::abi::call::ArgAbi;
use rustc_target::abi::{HasDataLayout, LayoutOf};
-use rustc::ty::{Ty};
-use rustc::ty::layout::{self};
use libc::c_uint;
-pub use rustc_target::spec::abi::Abi;
pub use rustc::ty::layout::{FAT_PTR_ADDR, FAT_PTR_EXTRA};
pub use rustc_target::abi::call::*;
+pub use rustc_target::spec::abi::Abi;
macro_rules! for_each_kind {
($flags: ident, $f: ident, $($kind: ident),+) => ({
}
trait ArgAttributeExt {
- fn for_each_kind<F>(&self, f: F) where F: FnMut(llvm::Attribute);
+ fn for_each_kind<F>(&self, f: F)
+ where
+ F: FnMut(llvm::Attribute);
}
impl ArgAttributeExt for ArgAttribute {
- fn for_each_kind<F>(&self, mut f: F) where F: FnMut(llvm::Attribute) {
- for_each_kind!(self, f,
- NoAlias, NoCapture, NonNull, ReadOnly, SExt, StructRet, ZExt, InReg)
+ fn for_each_kind<F>(&self, mut f: F)
+ where
+ F: FnMut(llvm::Attribute),
+ {
+ for_each_kind!(self, f, NoAlias, NoCapture, NonNull, ReadOnly, SExt, StructRet, ZExt, InReg)
}
}
let deref = self.pointee_size.bytes();
if deref != 0 {
if regular.contains(ArgAttribute::NonNull) {
- llvm::LLVMRustAddDereferenceableAttr(llfn,
- idx.as_uint(),
- deref);
+ llvm::LLVMRustAddDereferenceableAttr(llfn, idx.as_uint(), deref);
} else {
- llvm::LLVMRustAddDereferenceableOrNullAttr(llfn,
- idx.as_uint(),
- deref);
+ llvm::LLVMRustAddDereferenceableOrNullAttr(llfn, idx.as_uint(), deref);
}
regular -= ArgAttribute::NonNull;
}
if let Some(align) = self.pointee_align {
- llvm::LLVMRustAddAlignmentAttr(llfn,
- idx.as_uint(),
- align.bytes() as u32);
+ llvm::LLVMRustAddAlignmentAttr(llfn, idx.as_uint(), align.bytes() as u32);
}
if regular.contains(ArgAttribute::ByVal) {
llvm::LLVMRustAddByValAttr(llfn, idx.as_uint(), ty.unwrap());
let deref = self.pointee_size.bytes();
if deref != 0 {
if regular.contains(ArgAttribute::NonNull) {
- llvm::LLVMRustAddDereferenceableCallSiteAttr(callsite,
- idx.as_uint(),
- deref);
+ llvm::LLVMRustAddDereferenceableCallSiteAttr(callsite, idx.as_uint(), deref);
} else {
- llvm::LLVMRustAddDereferenceableOrNullCallSiteAttr(callsite,
- idx.as_uint(),
- deref);
+ llvm::LLVMRustAddDereferenceableOrNullCallSiteAttr(
+ callsite,
+ idx.as_uint(),
+ deref,
+ );
}
regular -= ArgAttribute::NonNull;
}
if let Some(align) = self.pointee_align {
- llvm::LLVMRustAddAlignmentCallSiteAttr(callsite,
- idx.as_uint(),
- align.bytes() as u32);
+ llvm::LLVMRustAddAlignmentCallSiteAttr(
+ callsite,
+ idx.as_uint(),
+ align.bytes() as u32,
+ );
}
if regular.contains(ArgAttribute::ByVal) {
llvm::LLVMRustAddByValCallSiteAttr(callsite, idx.as_uint(), ty.unwrap());
fn llvm_type(&self, cx: &CodegenCx<'ll, '_>) -> &'ll Type {
match self.kind {
RegKind::Integer => cx.type_ix(self.size.bits()),
- RegKind::Float => {
- match self.size.bits() {
- 32 => cx.type_f32(),
- 64 => cx.type_f64(),
- _ => bug!("unsupported float: {:?}", self)
- }
- }
- RegKind::Vector => {
- cx.type_vector(cx.type_i8(), self.size.bytes())
- }
+ RegKind::Float => match self.size.bits() {
+ 32 => cx.type_f32(),
+ 64 => cx.type_f64(),
+ _ => bug!("unsupported float: {:?}", self),
+ },
+ RegKind::Vector => cx.type_vector(cx.type_i8(), self.size.bytes()),
}
}
}
let (rest_count, rem_bytes) = if self.rest.unit.size.bytes() == 0 {
(0, 0)
} else {
- (self.rest.total.bytes() / self.rest.unit.size.bytes(),
- self.rest.total.bytes() % self.rest.unit.size.bytes())
+ (
+ self.rest.total.bytes() / self.rest.unit.size.bytes(),
+ self.rest.total.bytes() % self.rest.unit.size.bytes(),
+ )
};
if self.prefix.iter().all(|x| x.is_none()) {
}
// Create list of fields in the main structure
- let mut args: Vec<_> =
- self.prefix.iter().flat_map(|option_kind| option_kind.map(
- |kind| Reg { kind: kind, size: self.prefix_chunk }.llvm_type(cx)))
+ let mut args: Vec<_> = self
+ .prefix
+ .iter()
+ .flat_map(|option_kind| {
+ option_kind.map(|kind| Reg { kind: kind, size: self.prefix_chunk }.llvm_type(cx))
+ })
.chain((0..rest_count).map(|_| rest_ll_unit))
.collect();
llscratch,
scratch_align,
bx.const_usize(self.layout.size.bytes()),
- MemFlags::empty()
+ MemFlags::empty(),
);
bx.lifetime_end(llscratch, scratch_size);
fn store_fn_arg(
&mut self,
arg_abi: &ArgAbi<'tcx, Ty<'tcx>>,
- idx: &mut usize, dst: PlaceRef<'tcx, Self::Value>
+ idx: &mut usize,
+ dst: PlaceRef<'tcx, Self::Value>,
) {
arg_abi.store_fn_arg(self, idx, dst)
}
&mut self,
arg_abi: &ArgAbi<'tcx, Ty<'tcx>>,
val: &'ll Value,
- dst: PlaceRef<'tcx, &'ll Value>
+ dst: PlaceRef<'tcx, &'ll Value>,
) {
arg_abi.store(self, val, dst)
}
if let PassMode::Pair(_, _) = arg.mode { 2 } else { 1 }
).sum();
let mut llargument_tys = Vec::with_capacity(
- if let PassMode::Indirect(..) = self.ret.mode { 1 } else { 0 } + args_capacity
+ if let PassMode::Indirect(..) = self.ret.mode { 1 } else { 0 } + args_capacity,
);
let llreturn_ty = match self.ret.mode {
PassMode::Ignore => cx.type_void(),
- PassMode::Direct(_) | PassMode::Pair(..) => {
- self.ret.layout.immediate_llvm_type(cx)
- }
+ PassMode::Direct(_) | PassMode::Pair(..) => self.ret.layout.immediate_llvm_type(cx),
PassMode::Cast(cast) => cast.llvm_type(cx),
PassMode::Indirect(..) => {
llargument_tys.push(cx.type_ptr_to(self.ret.memory_ty(cx)));
fn ptr_to_llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type {
unsafe {
- llvm::LLVMPointerType(self.llvm_type(cx),
- cx.data_layout().instruction_address_space as c_uint)
+ llvm::LLVMPointerType(
+ self.llvm_type(cx),
+ cx.data_layout().instruction_address_space as c_uint,
+ )
}
}
fn llvm_cconv(&self) -> llvm::CallConv {
match self.conv {
- Conv::C => llvm::CCallConv,
+ Conv::C | Conv::Rust => llvm::CCallConv,
Conv::AmdGpuKernel => llvm::AmdGpuKernel,
Conv::ArmAapcs => llvm::ArmAapcsCallConv,
Conv::Msp430Intr => llvm::Msp430Intr,
}
match arg.mode {
PassMode::Ignore => {}
- PassMode::Direct(ref attrs) |
- PassMode::Indirect(ref attrs, None) => apply(attrs, Some(arg.layout.llvm_type(cx))),
+ PassMode::Direct(ref attrs) | PassMode::Indirect(ref attrs, None) => {
+ apply(attrs, Some(arg.layout.llvm_type(cx)))
+ }
PassMode::Indirect(ref attrs, Some(ref extra_attrs)) => {
apply(attrs, None);
apply(extra_attrs, None);
}
match arg.mode {
PassMode::Ignore => {}
- PassMode::Direct(ref attrs) |
- PassMode::Indirect(ref attrs, None) => apply(attrs, Some(arg.layout.llvm_type(bx))),
+ PassMode::Direct(ref attrs) | PassMode::Indirect(ref attrs, None) => {
+ apply(attrs, Some(arg.layout.llvm_type(bx)))
+ }
PassMode::Indirect(ref attrs, Some(ref extra_attrs)) => {
apply(attrs, None);
apply(extra_attrs, None);
}
impl AbiBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
- fn apply_attrs_callsite(
- &mut self,
- fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
- callsite: Self::Value
- ) {
+ fn apply_attrs_callsite(&mut self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, callsite: Self::Value) {
fn_abi.apply_attrs_callsite(self, callsite)
}