Fix review comments

This commit is contained in:
bjorn3
2020-07-15 19:19:07 +02:00
committed by Benjamin Bouvier
parent 4431ac1108
commit 0d4fa6d32a
3 changed files with 34 additions and 28 deletions

View File

@@ -1865,7 +1865,7 @@ pub(crate) fn define(
let Sarg = &TypeVar::new( let Sarg = &TypeVar::new(
"Sarg", "Sarg",
"Any scalar or vector type with as most 128 lanes", "Any scalar or vector type with at most 128 lanes",
TypeSetBuilder::new() TypeSetBuilder::new()
.specials(vec![crate::cdsl::types::SpecialType::StructArgument]) .specials(vec![crate::cdsl::types::SpecialType::StructArgument])
.build(), .build(),

View File

@@ -369,6 +369,7 @@ impl FromStr for ArgumentPurpose {
if !s.ends_with(")") { if !s.ends_with(")") {
return Err(()); return Err(());
} }
// Parse 'sarg(size)'
let size: u32 = s["sarg(".len()..s.len() - 1].parse().map_err(|_| ())?; let size: u32 = s["sarg(".len()..s.len() - 1].parse().map_err(|_| ())?;
Ok(Self::StructArgument(size)) Ok(Self::StructArgument(size))
} }

View File

@@ -609,20 +609,14 @@ fn convert_to_abi<PutArg>(
/// Check if a sequence of arguments match a desired sequence of argument types. /// Check if a sequence of arguments match a desired sequence of argument types.
fn check_arg_types(dfg: &DataFlowGraph, args: &[Value], types: &[AbiParam]) -> bool { fn check_arg_types(dfg: &DataFlowGraph, args: &[Value], types: &[AbiParam]) -> bool {
let mut args = args.iter(); args.len() == types.len()
let mut types = types.iter(); && args.iter().zip(types.iter()).all(|(v, at)| {
loop {
match (args.next(), types.next()) {
(Some(&v), Some(at)) => {
if let ArgumentPurpose::StructArgument(_) = at.purpose { if let ArgumentPurpose::StructArgument(_) = at.purpose {
} else if dfg.value_type(v) != at.value_type { true
return false; } else {
} dfg.value_type(*v) == at.value_type
}
(Some(_), None) | (None, Some(_)) => return false,
(None, None) => return true,
}
} }
})
} }
/// Check if the arguments of the call `inst` match the signature. /// Check if the arguments of the call `inst` match the signature.
@@ -1094,6 +1088,30 @@ fn spill_call_arguments(pos: &mut FuncCursor, isa: &dyn TargetIsa) -> bool {
return false; return false;
} }
let mut libc_memcpy = None;
let mut import_memcpy = |func: &mut Function, pointer_type| {
if let Some(libc_memcpy) = libc_memcpy {
return libc_memcpy;
}
let signature = {
let mut s = Signature::new(isa.default_call_conv());
s.params.push(AbiParam::new(pointer_type));
s.params.push(AbiParam::new(pointer_type));
s.params.push(AbiParam::new(pointer_type));
legalize_libcall_signature(&mut s, isa);
func.import_signature(s)
};
let func = func.import_function(ExtFuncData {
name: ExternalName::LibCall(LibCall::Memcpy),
signature,
colocated: false,
});
libc_memcpy = Some(func);
func
};
// Insert the spill instructions and rewrite call arguments. // Insert the spill instructions and rewrite call arguments.
for (idx, arg, ss, size) in arglist { for (idx, arg, ss, size) in arglist {
let stack_val = if let Some(size) = size { let stack_val = if let Some(size) = size {
@@ -1102,21 +1120,8 @@ fn spill_call_arguments(pos: &mut FuncCursor, isa: &dyn TargetIsa) -> bool {
let src = arg; let src = arg;
let dest = pos.ins().stack_addr(pointer_type, ss, 0); let dest = pos.ins().stack_addr(pointer_type, ss, 0);
let size = pos.ins().iconst(pointer_type, i64::from(size)); let size = pos.ins().iconst(pointer_type, i64::from(size));
let signature = {
let mut s = Signature::new(isa.default_call_conv());
s.params.push(AbiParam::new(pointer_type));
s.params.push(AbiParam::new(pointer_type));
s.params.push(AbiParam::new(pointer_type));
legalize_libcall_signature(&mut s, isa);
pos.func.import_signature(s)
};
let libc_memcpy = pos.func.import_function(ExtFuncData {
name: ExternalName::LibCall(LibCall::Memcpy),
signature,
colocated: false,
});
let libc_memcpy = import_memcpy(pos.func, pointer_type);
pos.ins().call(libc_memcpy, &[dest, src, size]); pos.ins().call(libc_memcpy, &[dest, src, size]);
pos.ins().dummy_sarg__() pos.ins().dummy_sarg__()
} else { } else {