From 7956084121622e44c64262bb8c8ececfbd7848b9 Mon Sep 17 00:00:00 2001 From: Tyler McMullen Date: Tue, 21 Nov 2017 17:08:31 -0800 Subject: [PATCH] Treat VmContext as positional when using Native CallConv (#195) * Treat VMContext as standard positional argument when using Native CallConv. This requires threading the CallConv through legalize_args and into ArgAssigner. * Stash CallConv in the intel-specific Args struct, for use ArgAssigner. --- lib/cretonne/src/isa/intel/abi.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/cretonne/src/isa/intel/abi.rs b/lib/cretonne/src/isa/intel/abi.rs index 3cd3dce931..e8be53e848 100644 --- a/lib/cretonne/src/isa/intel/abi.rs +++ b/lib/cretonne/src/isa/intel/abi.rs @@ -6,7 +6,7 @@ use regalloc::AllocatableSet; use settings as shared_settings; use super::registers::{GPR, FPR, RU}; use abi::{ArgAction, ValueConversion, ArgAssigner, legalize_args}; -use ir::{AbiParam, ArgumentPurpose, ArgumentLoc, ArgumentExtension}; +use ir::{AbiParam, ArgumentPurpose, ArgumentLoc, ArgumentExtension, CallConv}; use std::i32; /// Argument registers for x86-64 @@ -24,10 +24,11 @@ struct Args { fpr_limit: usize, fpr_used: usize, offset: u32, + call_conv: CallConv, } impl Args { - fn new(bits: u16, gpr: &'static [RU], fpr_limit: usize) -> Args { + fn new(bits: u16, gpr: &'static [RU], fpr_limit: usize, call_conv: CallConv) -> Args { Args { pointer_bytes: u32::from(bits) / 8, pointer_bits: bits, @@ -37,6 +38,7 @@ impl Args { fpr_limit, fpr_used: 0, offset: 0, + call_conv: call_conv, } } } @@ -66,8 +68,7 @@ impl ArgAssigner for Args { } // Handle special-purpose arguments. - // TODO: The registers below are for `spiderwasm`. Should we check the calling convention? - if ty.is_int() { + if ty.is_int() && self.call_conv == CallConv::SpiderWASM { match arg.purpose { // This is SpiderMonkey's `WasmTlsReg`. ArgumentPurpose::VMContext => { @@ -112,15 +113,15 @@ pub fn legalize_signature(sig: &mut ir::Signature, flags: &shared_settings::Flag if flags.is_64bit() { bits = 64; - args = Args::new(bits, &ARG_GPRS, 8); + args = Args::new(bits, &ARG_GPRS, 8, sig.call_conv); } else { bits = 32; - args = Args::new(bits, &[], 0); + args = Args::new(bits, &[], 0, sig.call_conv); } legalize_args(&mut sig.params, &mut args); - let mut rets = Args::new(bits, &RET_GPRS, 2); + let mut rets = Args::new(bits, &RET_GPRS, 2, sig.call_conv); legalize_args(&mut sig.returns, &mut rets); }