Add a prologue_epilogue() hook to TargetIsa.

This will compute the stack frame layout as appropriate for the
function's calling convention and insert prologue and epilogue code.

The default implementation is not useful, each target ISA will need to
override this function.
This commit is contained in:
Jakob Stoklund Olesen
2017-08-03 13:48:30 -07:00
parent 39cc7efc2d
commit 92392c6041
2 changed files with 20 additions and 0 deletions

View File

@@ -49,6 +49,7 @@ use flowgraph;
use settings;
use ir;
use regalloc;
use result;
use isa::enc_tables::Encodings;
#[cfg(build_riscv)]
@@ -227,6 +228,18 @@ pub trait TargetIsa {
/// registers.
fn allocatable_registers(&self, func: &ir::Function) -> regalloc::AllocatableSet;
/// Compute the stack layout and insert prologue and epilogue code into `func`.
///
/// Return an error if the stack frame is too large.
fn prologue_epilogue(&self, func: &mut ir::Function) -> result::CtonResult {
// This default implementation is unlikely to be good enough.
use stack_layout::layout_stack;
let align = if self.flags().is_64bit() { 8 } else { 4 };
layout_stack(&mut func.stack_slots, align)?;
Ok(())
}
/// Emit binary machine code for a single instruction into the `sink` trait object.
///
/// Note that this will call `put*` methods on the trait object via its vtable which is not the