Implement SystemV struct argument passing

This commit is contained in:
bjorn3
2020-04-20 12:01:53 +02:00
committed by Benjamin Bouvier
parent 2f368ed5d6
commit 4431ac1108
15 changed files with 298 additions and 50 deletions

View File

@@ -407,6 +407,8 @@ impl fmt::Debug for VectorType {
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub(crate) enum SpecialType {
Flag(shared_types::Flag),
// FIXME remove once the old style backends are removed.
StructArgument,
}
impl SpecialType {
@@ -421,6 +423,9 @@ impl SpecialType {
"CPU flags representing the result of a floating point comparison. These
flags can be tested with a :type:`floatcc` condition code.",
),
SpecialType::StructArgument => {
String::from("After legalization sarg__ arguments will get this type.")
}
}
}
@@ -428,6 +433,7 @@ impl SpecialType {
pub fn lane_bits(self) -> u64 {
match self {
SpecialType::Flag(_) => 0,
SpecialType::StructArgument => 0,
}
}
@@ -436,6 +442,7 @@ impl SpecialType {
match self {
SpecialType::Flag(shared_types::Flag::IFlags) => 1,
SpecialType::Flag(shared_types::Flag::FFlags) => 2,
SpecialType::StructArgument => 3,
}
}
}
@@ -445,6 +452,7 @@ impl fmt::Display for SpecialType {
match *self {
SpecialType::Flag(shared_types::Flag::IFlags) => write!(f, "iflags"),
SpecialType::Flag(shared_types::Flag::FFlags) => write!(f, "fflags"),
SpecialType::StructArgument => write!(f, "sarg__"),
}
}
}
@@ -456,6 +464,7 @@ impl fmt::Debug for SpecialType {
"{}",
match *self {
SpecialType::Flag(_) => format!("FlagsType({})", self),
SpecialType::StructArgument => format!("StructArgument"),
}
)
}
@@ -469,12 +478,14 @@ impl From<shared_types::Flag> for SpecialType {
pub(crate) struct SpecialTypeIterator {
flag_iter: shared_types::FlagIterator,
done: bool,
}
impl SpecialTypeIterator {
fn new() -> Self {
Self {
flag_iter: shared_types::FlagIterator::new(),
done: false,
}
}
}
@@ -485,7 +496,12 @@ impl Iterator for SpecialTypeIterator {
if let Some(f) = self.flag_iter.next() {
Some(SpecialType::from(f))
} else {
None
if !self.done {
self.done = true;
Some(SpecialType::StructArgument)
} else {
None
}
}
}
}

View File

@@ -465,6 +465,7 @@ fn define_moves(e: &mut PerCpuModeEncodings, shared_defs: &SharedDefinitions, r:
let sextend = shared.by_name("sextend");
let set_pinned_reg = shared.by_name("set_pinned_reg");
let uextend = shared.by_name("uextend");
let dummy_sarg__ = shared.by_name("dummy_sarg__");
// Shorthands for recipes.
let rec_copysp = r.template("copysp");
@@ -482,6 +483,7 @@ fn define_moves(e: &mut PerCpuModeEncodings, shared_defs: &SharedDefinitions, r:
let rec_umr_reg_to_ssa = r.template("umr_reg_to_ssa");
let rec_urm_noflags = r.template("urm_noflags");
let rec_urm_noflags_abcd = r.template("urm_noflags_abcd");
let rec_dummy_sarg__ = r.recipe("dummy_sarg__");
// The pinned reg is fixed to a certain value entirely user-controlled, so it generates nothing!
e.enc64_rec(get_pinned_reg.bind(I64), rec_get_pinned_reg, 0);
@@ -747,6 +749,8 @@ fn define_moves(e: &mut PerCpuModeEncodings, shared_defs: &SharedDefinitions, r:
copy_to_ssa.bind(F32),
rec_furm_reg_to_ssa.opcodes(&MOVSS_LOAD),
);
e.enc_32_64_rec(dummy_sarg__, rec_dummy_sarg__, 0);
}
#[inline(never)]

View File

@@ -1270,6 +1270,12 @@ pub(crate) fn define<'shared>(
);
}
recipes.add_recipe(
EncodingRecipeBuilder::new("dummy_sarg__", &formats.nullary, 0)
.operands_out(vec![Stack::new(gpr)])
.emit(""),
);
// XX+rd id with Abs4 function relocation.
recipes.add_template_recipe(
EncodingRecipeBuilder::new("fnaddr4", &formats.func_addr, 4)

View File

@@ -1863,6 +1863,31 @@ pub(crate) fn define(
.can_load(true),
);
let Sarg = &TypeVar::new(
"Sarg",
"Any scalar or vector type with as most 128 lanes",
TypeSetBuilder::new()
.specials(vec![crate::cdsl::types::SpecialType::StructArgument])
.build(),
);
let sarg__ = &Operand::new("sarg__", Sarg);
// FIXME remove once the old style codegen backends are removed.
ig.push(
Inst::new(
"dummy_sarg__",
r#"
This creates a sarg__
This instruction is internal and should not be created by
Cranelift users.
"#,
&formats.nullary,
)
.operands_in(vec![])
.operands_out(vec![sarg__]),
);
let src = &Operand::new("src", &imm.regunit);
let dst = &Operand::new("dst", &imm.regunit);