Refactor calling convention settings. (#304)
Add a calling-convention setting to the `Flags` used as part of the `TargetIsa`. This allows Cretonne code that generates calls to use the correct convention, such as when emitting libcalls during legalization or when the wasm frontend is decoding functions. This setting can be overridden per-function. This also adds "fast", "cold", and "fastcall" conventions, with "fast" as the new default. Note that "fast" and "cold" are not intended to be ABI-compatible across Cretonne versions. This will also ensure Windows users will get an `unimplemented!` rather than silent calling-convention mismatches, which reflects the fact that Windows calling conventions are not yet implemented. This also renames SpiderWASM, which isn't camel-case, to Baldrdash, which is, and which is also a more relevant name.
This commit is contained in:
@@ -3,9 +3,10 @@
|
||||
use ir;
|
||||
use ir::InstBuilder;
|
||||
use std::vec::Vec;
|
||||
use isa::TargetIsa;
|
||||
|
||||
/// Try to expand `inst` as a library call, returning true is successful.
|
||||
pub fn expand_as_libcall(inst: ir::Inst, func: &mut ir::Function) -> bool {
|
||||
pub fn expand_as_libcall(inst: ir::Inst, func: &mut ir::Function, isa: &TargetIsa) -> bool {
|
||||
// Does the opcode/ctrl_type combo even have a well-known runtime library name.
|
||||
let libcall =
|
||||
match ir::LibCall::for_inst(func.dfg[inst].opcode(), func.dfg.ctrl_typevar(inst)) {
|
||||
@@ -13,7 +14,8 @@ pub fn expand_as_libcall(inst: ir::Inst, func: &mut ir::Function) -> bool {
|
||||
None => return false,
|
||||
};
|
||||
|
||||
let funcref = find_funcref(libcall, func).unwrap_or_else(|| make_funcref(libcall, inst, func));
|
||||
let funcref =
|
||||
find_funcref(libcall, func).unwrap_or_else(|| make_funcref(libcall, inst, func, isa));
|
||||
|
||||
// Now we convert `inst` to a call. First save the arguments.
|
||||
let mut args = Vec::new();
|
||||
@@ -44,9 +46,14 @@ fn find_funcref(libcall: ir::LibCall, func: &ir::Function) -> Option<ir::FuncRef
|
||||
}
|
||||
|
||||
/// Create a funcref for `libcall` with a signature matching `inst`.
|
||||
fn make_funcref(libcall: ir::LibCall, inst: ir::Inst, func: &mut ir::Function) -> ir::FuncRef {
|
||||
// Start with a system_v calling convention. We'll give the ISA a chance to change it.
|
||||
let mut sig = ir::Signature::new(ir::CallConv::SystemV);
|
||||
fn make_funcref(
|
||||
libcall: ir::LibCall,
|
||||
inst: ir::Inst,
|
||||
func: &mut ir::Function,
|
||||
isa: &TargetIsa,
|
||||
) -> ir::FuncRef {
|
||||
// Start with a fast calling convention. We'll give the ISA a chance to change it.
|
||||
let mut sig = ir::Signature::new(isa.flags().call_conv());
|
||||
for &v in func.dfg.inst_args(inst) {
|
||||
sig.params.push(ir::AbiParam::new(func.dfg.value_type(v)));
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ pub fn legalize_function(func: &mut ir::Function, cfg: &mut ControlFlowGraph, is
|
||||
|
||||
// We don't have any pattern expansion for this instruction either.
|
||||
// Try converting it to a library call as a last resort.
|
||||
if expand_as_libcall(inst, pos.func) {
|
||||
if expand_as_libcall(inst, pos.func, isa) {
|
||||
pos.set_position(prev_pos);
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user