diff --git a/lib/codegen/src/binemit/relaxation.rs b/lib/codegen/src/binemit/relaxation.rs index 299d0a1fb9..3c4e631bfc 100644 --- a/lib/codegen/src/binemit/relaxation.rs +++ b/lib/codegen/src/binemit/relaxation.rs @@ -32,12 +32,12 @@ use cursor::{Cursor, FuncCursor}; use ir::{Function, InstructionData, Opcode}; use isa::{EncInfo, TargetIsa}; use iterators::IteratorExtras; -use result::CtonResult; +use result::CodegenResult; /// Relax branches and compute the final layout of EBB headers in `func`. /// /// Fill in the `func.offsets` table so the function is ready for binary emission. -pub fn relax_branches(func: &mut Function, isa: &TargetIsa) -> CtonResult { +pub fn relax_branches(func: &mut Function, isa: &TargetIsa) -> CodegenResult { let encinfo = isa.encoding_info(); // Clear all offsets so we can recognize EBBs that haven't been visited yet. diff --git a/lib/codegen/src/context.rs b/lib/codegen/src/context.rs index 5c33d56314..6e8c54051b 100644 --- a/lib/codegen/src/context.rs +++ b/lib/codegen/src/context.rs @@ -22,7 +22,7 @@ use nan_canonicalization::do_nan_canonicalization; use postopt::do_postopt; use preopt::do_preopt; use regalloc; -use result::CtonResult; +use result::CodegenResult; use settings::{FlagsOrIsa, OptLevel}; use simple_gvn::do_simple_gvn; use std::vec::Vec; @@ -95,7 +95,7 @@ impl Context { mem: &mut Vec, relocs: &mut RelocSink, traps: &mut TrapSink, - ) -> CtonResult<()> { + ) -> CodegenResult<()> { let code_size = self.compile(isa)?; let old_len = mem.len(); mem.resize(old_len + code_size as usize, 0); @@ -117,7 +117,7 @@ impl Context { /// code sink. /// /// Returns the size of the function's code. - pub fn compile(&mut self, isa: &TargetIsa) -> CtonResult { + pub fn compile(&mut self, isa: &TargetIsa) -> CodegenResult { let _tt = timing::compile(); self.verify_if(isa)?; @@ -179,7 +179,7 @@ impl Context { } /// Run the verifier only if the `enable_verifier` setting is true. - pub fn verify_if<'a, FOI: Into>>(&self, fisa: FOI) -> CtonResult<()> { + pub fn verify_if<'a, FOI: Into>>(&self, fisa: FOI) -> CodegenResult<()> { let fisa = fisa.into(); if fisa.flags.enable_verifier() { self.verify(fisa).map_err(Into::into) @@ -194,7 +194,7 @@ impl Context { } /// Run the locations verifier only if the `enable_verifier` setting is true. - pub fn verify_locations_if(&self, isa: &TargetIsa) -> CtonResult<()> { + pub fn verify_locations_if(&self, isa: &TargetIsa) -> CodegenResult<()> { if isa.flags().enable_verifier() { self.verify_locations(isa).map_err(Into::into) } else { @@ -203,27 +203,27 @@ impl Context { } /// Perform dead-code elimination on the function. - pub fn dce<'a, FOI: Into>>(&mut self, fisa: FOI) -> CtonResult<()> { + pub fn dce<'a, FOI: Into>>(&mut self, fisa: FOI) -> CodegenResult<()> { do_dce(&mut self.func, &mut self.domtree); self.verify_if(fisa)?; Ok(()) } /// Perform pre-legalization rewrites on the function. - pub fn preopt(&mut self, isa: &TargetIsa) -> CtonResult<()> { + pub fn preopt(&mut self, isa: &TargetIsa) -> CodegenResult<()> { do_preopt(&mut self.func); self.verify_if(isa)?; Ok(()) } /// Perform NaN canonicalizing rewrites on the function. - pub fn canonicalize_nans(&mut self, isa: &TargetIsa) -> CtonResult<()> { + pub fn canonicalize_nans(&mut self, isa: &TargetIsa) -> CodegenResult<()> { do_nan_canonicalization(&mut self.func); self.verify_if(isa) } /// Run the legalizer for `isa` on the function. - pub fn legalize(&mut self, isa: &TargetIsa) -> CtonResult<()> { + pub fn legalize(&mut self, isa: &TargetIsa) -> CodegenResult<()> { // Legalization invalidates the domtree and loop_analysis by mutating the CFG. // TODO: Avoid doing this when legalization doesn't actually mutate the CFG. self.domtree.clear(); @@ -233,7 +233,7 @@ impl Context { } /// Perform post-legalization rewrites on the function. - pub fn postopt(&mut self, isa: &TargetIsa) -> CtonResult<()> { + pub fn postopt(&mut self, isa: &TargetIsa) -> CodegenResult<()> { do_postopt(&mut self.func, isa); self.verify_if(isa)?; Ok(()) @@ -262,13 +262,13 @@ impl Context { } /// Perform simple GVN on the function. - pub fn simple_gvn<'a, FOI: Into>>(&mut self, fisa: FOI) -> CtonResult<()> { + pub fn simple_gvn<'a, FOI: Into>>(&mut self, fisa: FOI) -> CodegenResult<()> { do_simple_gvn(&mut self.func, &mut self.domtree); self.verify_if(fisa) } /// Perform LICM on the function. - pub fn licm<'a, FOI: Into>>(&mut self, fisa: FOI) -> CtonResult<()> { + pub fn licm<'a, FOI: Into>>(&mut self, fisa: FOI) -> CodegenResult<()> { do_licm( &mut self.func, &mut self.cfg, @@ -279,7 +279,7 @@ impl Context { } /// Perform unreachable code elimination. - pub fn eliminate_unreachable_code<'a, FOI>(&mut self, fisa: FOI) -> CtonResult<()> + pub fn eliminate_unreachable_code<'a, FOI>(&mut self, fisa: FOI) -> CodegenResult<()> where FOI: Into>, { @@ -288,13 +288,13 @@ impl Context { } /// Run the register allocator. - pub fn regalloc(&mut self, isa: &TargetIsa) -> CtonResult<()> { + pub fn regalloc(&mut self, isa: &TargetIsa) -> CodegenResult<()> { self.regalloc .run(isa, &mut self.func, &self.cfg, &mut self.domtree) } /// Insert prologue and epilogues after computing the stack frame layout. - pub fn prologue_epilogue(&mut self, isa: &TargetIsa) -> CtonResult<()> { + pub fn prologue_epilogue(&mut self, isa: &TargetIsa) -> CodegenResult<()> { assert!( self.func.stack_limit.is_none(), "stack_limit isn't implemented yet" @@ -306,7 +306,7 @@ impl Context { } /// Run the instruction shrinking pass. - pub fn shrink_instructions(&mut self, isa: &TargetIsa) -> CtonResult<()> { + pub fn shrink_instructions(&mut self, isa: &TargetIsa) -> CodegenResult<()> { shrink_instructions(&mut self.func, isa); self.verify_if(isa)?; self.verify_locations_if(isa)?; @@ -314,7 +314,7 @@ impl Context { } /// Run the branch relaxation pass and return the final code size. - pub fn relax_branches(&mut self, isa: &TargetIsa) -> CtonResult { + pub fn relax_branches(&mut self, isa: &TargetIsa) -> CodegenResult { let code_size = relax_branches(&mut self.func, isa)?; self.verify_if(isa)?; self.verify_locations_if(isa)?; diff --git a/lib/codegen/src/isa/mod.rs b/lib/codegen/src/isa/mod.rs index c042a42600..d785c32f57 100644 --- a/lib/codegen/src/isa/mod.rs +++ b/lib/codegen/src/isa/mod.rs @@ -56,7 +56,7 @@ use flowgraph; use ir; use isa::enc_tables::Encodings; use regalloc; -use result::CtonResult; +use result::CodegenResult; use settings; use settings::CallConv; use std::boxed::Box; @@ -281,7 +281,7 @@ pub trait TargetIsa: fmt::Display { /// 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) -> CtonResult<()> { + fn prologue_epilogue(&self, func: &mut ir::Function) -> CodegenResult<()> { let _tt = timing::prologue_epilogue(); // This default implementation is unlikely to be good enough. use ir::stackslot::{StackOffset, StackSize}; diff --git a/lib/codegen/src/isa/x86/abi.rs b/lib/codegen/src/isa/x86/abi.rs index 264a45a137..c74572ecc7 100644 --- a/lib/codegen/src/isa/x86/abi.rs +++ b/lib/codegen/src/isa/x86/abi.rs @@ -10,7 +10,7 @@ use ir::{get_probestack_funcref, AbiParam, ArgumentExtension, ArgumentLoc, Argum InstBuilder, ValueLoc}; use isa::{RegClass, RegUnit, TargetIsa}; use regalloc::RegisterSet; -use result::CtonResult; +use result::CodegenResult; use settings::CallConv; use stack_layout::layout_stack; use std::i32; @@ -257,7 +257,7 @@ fn callee_saved_gprs_used(isa: &TargetIsa, func: &ir::Function) -> RegisterSet { used } -pub fn prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> CtonResult<()> { +pub fn prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> CodegenResult<()> { match func.signature.call_conv { // For now, just translate fast and cold as system_v. CallConv::Fast | CallConv::Cold | CallConv::SystemV => { @@ -269,7 +269,7 @@ pub fn prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> CtonResult } } -pub fn baldrdash_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> CtonResult<()> { +pub fn baldrdash_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> CodegenResult<()> { debug_assert!( !isa.flags().probestack_enabled(), "baldrdash does not expect cretonne to emit stack probes" @@ -290,7 +290,7 @@ pub fn baldrdash_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> /// Implementation of the fastcall-based Win64 calling convention described at [1] /// [1] https://msdn.microsoft.com/en-us/library/ms235286.aspx -pub fn fastcall_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> CtonResult<()> { +pub fn fastcall_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> CodegenResult<()> { if isa.triple().pointer_width().unwrap() != PointerWidth::U64 { panic!("TODO: windows-fastcall: x86-32 not implemented yet"); } @@ -362,7 +362,7 @@ pub fn fastcall_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> C } /// Insert a System V-compatible prologue and epilogue. -pub fn system_v_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> CtonResult<()> { +pub fn system_v_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> CodegenResult<()> { // The original 32-bit x86 ELF ABI had a 4-byte aligned stack pointer, but // newer versions use a 16-byte aligned stack pointer. let stack_align = 16; diff --git a/lib/codegen/src/isa/x86/mod.rs b/lib/codegen/src/isa/x86/mod.rs index cba7a640f9..2681e044d6 100644 --- a/lib/codegen/src/isa/x86/mod.rs +++ b/lib/codegen/src/isa/x86/mod.rs @@ -13,7 +13,7 @@ use isa::enc_tables::{self as shared_enc_tables, lookup_enclist, Encodings}; use isa::Builder as IsaBuilder; use isa::{EncInfo, RegClass, RegInfo, TargetIsa}; use regalloc; -use result::CtonResult; +use result::CodegenResult; use std::boxed::Box; use std::fmt; use target_lexicon::{PointerWidth, Triple}; @@ -129,7 +129,7 @@ impl TargetIsa for Isa { emit_function(func, binemit::emit_inst, sink) } - fn prologue_epilogue(&self, func: &mut ir::Function) -> CtonResult<()> { + fn prologue_epilogue(&self, func: &mut ir::Function) -> CodegenResult<()> { let _tt = timing::prologue_epilogue(); abi::prologue_epilogue(func, self) } diff --git a/lib/codegen/src/print_errors.rs b/lib/codegen/src/print_errors.rs index 283b3d6d08..777fde05b8 100644 --- a/lib/codegen/src/print_errors.rs +++ b/lib/codegen/src/print_errors.rs @@ -2,7 +2,7 @@ use ir; use isa::TargetIsa; -use result::CtonError; +use result::CodegenError; use std::fmt::Write; use std::string::{String, ToString}; use verifier::VerifierError; @@ -25,8 +25,8 @@ pub fn pretty_verifier_error( } /// Pretty-print a Cretonne error. -pub fn pretty_error(func: &ir::Function, isa: Option<&TargetIsa>, err: CtonError) -> String { - if let CtonError::Verifier(e) = err { +pub fn pretty_error(func: &ir::Function, isa: Option<&TargetIsa>, err: CodegenError) -> String { + if let CodegenError::Verifier(e) = err { pretty_verifier_error(func, isa, &e) } else { err.to_string() diff --git a/lib/codegen/src/regalloc/context.rs b/lib/codegen/src/regalloc/context.rs index 10f83b979d..349fa212cb 100644 --- a/lib/codegen/src/regalloc/context.rs +++ b/lib/codegen/src/regalloc/context.rs @@ -15,7 +15,7 @@ use regalloc::liveness::Liveness; use regalloc::reload::Reload; use regalloc::spilling::Spilling; use regalloc::virtregs::VirtRegs; -use result::CtonResult; +use result::CodegenResult; use timing; use topo_order::TopoOrder; use verifier::{verify_context, verify_cssa, verify_liveness, verify_locations}; @@ -72,7 +72,7 @@ impl Context { func: &mut Function, cfg: &ControlFlowGraph, domtree: &mut DominatorTree, - ) -> CtonResult<()> { + ) -> CodegenResult<()> { let _tt = timing::regalloc(); debug_assert!(domtree.is_valid()); diff --git a/lib/codegen/src/result.rs b/lib/codegen/src/result.rs index 9d684dc172..ffdcbb152b 100644 --- a/lib/codegen/src/result.rs +++ b/lib/codegen/src/result.rs @@ -6,7 +6,7 @@ use verifier::VerifierError; /// /// When Cretonne fails to compile a function, it will return one of these error codes. #[derive(Fail, Debug, PartialEq, Eq)] -pub enum CtonError { +pub enum CodegenError { /// An IR verifier error. /// /// This always represents a bug, either in the code that generated IR for Cretonne, or a bug @@ -31,11 +31,11 @@ pub enum CtonError { CodeTooLarge, } -/// A Cretonne compilation result. -pub type CtonResult = Result; +/// A convenient alias for a `Result` that uses `CodegenError` as the error type. +pub type CodegenResult = Result; -impl From for CtonError { +impl From for CodegenError { fn from(e: VerifierError) -> Self { - CtonError::Verifier(e) + CodegenError::Verifier(e) } } diff --git a/lib/codegen/src/stack_layout.rs b/lib/codegen/src/stack_layout.rs index 6334f4d5ed..eced3ada0a 100644 --- a/lib/codegen/src/stack_layout.rs +++ b/lib/codegen/src/stack_layout.rs @@ -2,7 +2,7 @@ use ir::stackslot::{StackOffset, StackSize, StackSlotKind}; use ir::StackSlots; -use result::{CtonError, CtonResult}; +use result::{CodegenError, CodegenResult}; use std::cmp::{max, min}; /// Compute the stack frame layout. @@ -15,7 +15,7 @@ use std::cmp::{max, min}; /// Returns the total stack frame size which is also saved in `frame.frame_size`. /// /// If the stack frame is too big, returns an `ImplLimitExceeded` error. -pub fn layout_stack(frame: &mut StackSlots, alignment: StackSize) -> CtonResult { +pub fn layout_stack(frame: &mut StackSlots, alignment: StackSize) -> CodegenResult { // Each object and the whole stack frame must fit in 2 GB such that any relative offset within // the frame fits in a `StackOffset`. let max_size = StackOffset::max_value() as StackSize; @@ -41,7 +41,7 @@ pub fn layout_stack(frame: &mut StackSlots, alignment: StackSize) -> CtonResult< for slot in frame.values() { if slot.size > max_size { - return Err(CtonError::ImplLimitExceeded); + return Err(CodegenError::ImplLimitExceeded); } match slot.kind { @@ -52,7 +52,7 @@ pub fn layout_stack(frame: &mut StackSlots, alignment: StackSize) -> CtonResult< let offset = slot.offset .unwrap() .checked_add(slot.size as StackOffset) - .ok_or(CtonError::ImplLimitExceeded)?; + .ok_or(CodegenError::ImplLimitExceeded)?; outgoing_max = max(outgoing_max, offset); } StackSlotKind::SpillSlot @@ -85,7 +85,7 @@ pub fn layout_stack(frame: &mut StackSlots, alignment: StackSize) -> CtonResult< offset = offset .checked_sub(slot.size as StackOffset) - .ok_or(CtonError::ImplLimitExceeded)?; + .ok_or(CodegenError::ImplLimitExceeded)?; // Aligning the negative offset can never cause overflow. We're only clearing bits. offset &= -(min_align as StackOffset); @@ -99,7 +99,7 @@ pub fn layout_stack(frame: &mut StackSlots, alignment: StackSize) -> CtonResult< // Finally, make room for the outgoing arguments. offset = offset .checked_sub(outgoing_max) - .ok_or(CtonError::ImplLimitExceeded)?; + .ok_or(CodegenError::ImplLimitExceeded)?; offset &= -(alignment as StackOffset); let frame_size = (offset as StackSize).wrapping_neg(); @@ -113,7 +113,7 @@ mod tests { use ir::stackslot::StackOffset; use ir::types; use ir::{StackSlotData, StackSlotKind, StackSlots}; - use result::CtonError; + use result::CodegenError; #[test] fn layout() { @@ -187,7 +187,7 @@ mod tests { // Also test that an unsupported offset is rejected. sss.get_outgoing_arg(types::I8, StackOffset::max_value() - 1); - assert_eq!(layout_stack(sss, 1), Err(CtonError::ImplLimitExceeded)); + assert_eq!(layout_stack(sss, 1), Err(CodegenError::ImplLimitExceeded)); } #[test] diff --git a/lib/module/src/module.rs b/lib/module/src/module.rs index 23b8328730..74eb1aaf42 100644 --- a/lib/module/src/module.rs +++ b/lib/module/src/module.rs @@ -6,7 +6,7 @@ // shared with `DataContext`? use cretonne_codegen::entity::{EntityRef, PrimaryMap}; -use cretonne_codegen::result::CtonError; +use cretonne_codegen::result::CodegenError; use cretonne_codegen::{binemit, ir, Context}; use data_context::DataContext; use std::borrow::ToOwned; @@ -134,7 +134,7 @@ pub enum ModuleError { InvalidImportDefinition(String), /// Wraps a `cretonne-codegen` error #[fail(display = "Compilation error: {}", _0)] - Compilation(CtonError), + Compilation(CodegenError), /// Wraps a generic error from a backend #[fail(display = "Backend error: {}", _0)] Backend(String),