Add a legalize_signature method to TargetIsa.

This entry point will be used for controlling ABI conventions when
legalizing.

Provide an empty implementation for RISC-V and let the other ISAs crash
in legalization.

This is just the scaffolding. We still need to:

- Rewrite the entry block arguments to match the legalized signature.
- Rewrite call and return instructions.
- Implement the legalize_signature() function for all ISAs.
- Add shared generic types to help with the legalize_signature()
  functions.
This commit is contained in:
Jakob Stoklund Olesen
2017-03-01 11:53:52 -08:00
parent cae4368a8a
commit 07f459fb93
5 changed files with 54 additions and 7 deletions

View File

@@ -64,11 +64,6 @@ impl Function {
pub fn new() -> Function { pub fn new() -> Function {
Self::with_name_signature(FunctionName::default(), Signature::new()) Self::with_name_signature(FunctionName::default(), Signature::new())
} }
/// Get the signature of this function.
pub fn own_signature(&self) -> &Signature {
&self.signature
}
} }
impl Display for Function { impl Display for Function {

View File

@@ -45,7 +45,7 @@ pub use isa::registers::{RegInfo, RegUnit, RegClass, RegClassIndex};
pub use isa::constraints::{RecipeConstraints, OperandConstraint, ConstraintKind}; pub use isa::constraints::{RecipeConstraints, OperandConstraint, ConstraintKind};
use settings; use settings;
use ir::{InstructionData, DataFlowGraph}; use ir::{InstructionData, DataFlowGraph, Signature};
pub mod riscv; pub mod riscv;
pub mod intel; pub mod intel;
@@ -161,4 +161,24 @@ pub trait TargetIsa {
recipe_names: self.recipe_names(), recipe_names: self.recipe_names(),
} }
} }
/// Legalize a function signature.
///
/// This is used to legalize both the signature of the function being compiled and any called
/// functions. The signature should be modified by adding `ArgumentLoc` annotations to all
/// arguments and return values.
///
/// Arguments with types that are not supported by the ABI can be expanded into multiple
/// arguments:
///
/// - Integer types that are too large to fit in a register can be broken into multiple
/// arguments of a smaller integer type.
/// - Floating point types can be bit-cast to an integer type of the same size, and possible
/// broken into smaller integer types.
/// - Vector types can be bit-cast and broken down into smaller vectors or scalars.
///
/// The legalizer will adapt argument and return values as necessary at all ABI boundaries.
fn legalize_signature(&self, _sig: &mut Signature) {
unimplemented!()
}
} }

View File

@@ -0,0 +1,12 @@
//! RISC-V ABI implementation.
//!
//! This module implements the RISC-V calling convention through the primary `legalize_signature()`
//! entry point.
use ir::Signature;
use settings as shared_settings;
/// Legalize `sig` for RISC-V.
pub fn legalize_signature(_sig: &mut Signature, _flags: &shared_settings::Flags) {
// TODO: Actually do something.
}

View File

@@ -1,6 +1,7 @@
//! RISC-V Instruction Set Architecture. //! RISC-V Instruction Set Architecture.
pub mod settings; pub mod settings;
mod abi;
mod enc_tables; mod enc_tables;
mod registers; mod registers;
@@ -8,7 +9,7 @@ use super::super::settings as shared_settings;
use isa::enc_tables::{self as shared_enc_tables, lookup_enclist, general_encoding}; use isa::enc_tables::{self as shared_enc_tables, lookup_enclist, general_encoding};
use isa::Builder as IsaBuilder; use isa::Builder as IsaBuilder;
use isa::{TargetIsa, RegInfo, Encoding, Legalize, RecipeConstraints}; use isa::{TargetIsa, RegInfo, Encoding, Legalize, RecipeConstraints};
use ir::{InstructionData, DataFlowGraph}; use ir::{InstructionData, DataFlowGraph, Signature};
#[allow(dead_code)] #[allow(dead_code)]
struct Isa { struct Isa {
@@ -74,6 +75,11 @@ impl TargetIsa for Isa {
fn recipe_constraints(&self) -> &'static [RecipeConstraints] { fn recipe_constraints(&self) -> &'static [RecipeConstraints] {
&enc_tables::RECIPE_CONSTRAINTS &enc_tables::RECIPE_CONSTRAINTS
} }
fn legalize_signature(&self, sig: &mut Signature) {
// We can pass in `self.isa_flags` too, if we need it.
abi::legalize_signature(sig, &self.shared_flags)
}
} }
#[cfg(test)] #[cfg(test)]

View File

@@ -23,6 +23,8 @@ use isa::{TargetIsa, Legalize};
/// - Fill out `func.encodings`. /// - Fill out `func.encodings`.
/// ///
pub fn legalize_function(func: &mut Function, isa: &TargetIsa) { pub fn legalize_function(func: &mut Function, isa: &TargetIsa) {
legalize_signatures(func, isa);
// TODO: This is very simplified and incomplete. // TODO: This is very simplified and incomplete.
func.encodings.resize(func.dfg.num_insts()); func.encodings.resize(func.dfg.num_insts());
let mut pos = Cursor::new(&mut func.layout); let mut pos = Cursor::new(&mut func.layout);
@@ -74,3 +76,15 @@ pub fn legalize_function(func: &mut Function, isa: &TargetIsa) {
// //
// Concretely, this defines private functions `narrow()`, and `expand()`. // Concretely, this defines private functions `narrow()`, and `expand()`.
include!(concat!(env!("OUT_DIR"), "/legalizer.rs")); include!(concat!(env!("OUT_DIR"), "/legalizer.rs"));
/// Legalize all the function signatures in `func`.
///
/// This changes all signatures to be ABI-compliant with full `ArgumentLoc` annotations. It doesn't
/// change the entry block arguments, calls, or return instructions, so this can leave the function
/// in a state with type discrepancies.
fn legalize_signatures(func: &mut Function, isa: &TargetIsa) {
isa.legalize_signature(&mut func.signature);
for sig in func.dfg.signatures.keys() {
isa.legalize_signature(&mut func.dfg.signatures[sig]);
}
}