diff --git a/cranelift/codegen/src/ir/extfunc.rs b/cranelift/codegen/src/ir/extfunc.rs index e3822c6e401c..2df0f890f1ae 100644 --- a/cranelift/codegen/src/ir/extfunc.rs +++ b/cranelift/codegen/src/ir/extfunc.rs @@ -7,7 +7,6 @@ use crate::ir::{ExternalName, SigRef, Type}; use crate::isa::CallConv; -use crate::machinst::RelocDistance; use alloc::vec::Vec; use core::fmt; use core::str::FromStr; @@ -319,15 +318,6 @@ pub struct ExtFuncData { } impl ExtFuncData { - /// Return an estimate of the distance to the referred-to function symbol. - pub fn reloc_distance(&self) -> RelocDistance { - if self.colocated { - RelocDistance::Near - } else { - RelocDistance::Far - } - } - /// Returns a displayable version of the `ExtFuncData`, with or without extra context to /// prettify the output. pub fn display<'a>( diff --git a/cranelift/codegen/src/ir/function.rs b/cranelift/codegen/src/ir/function.rs index a7a8eee2759c..7572b3f37922 100644 --- a/cranelift/codegen/src/ir/function.rs +++ b/cranelift/codegen/src/ir/function.rs @@ -11,7 +11,6 @@ use crate::ir::{ StackSlots, Table, TableData, Type, }; use crate::isa::CallConv; -use crate::value_label::ValueLabelsRanges; use crate::write::write_function; use crate::HashMap; #[cfg(feature = "enable-serde")] @@ -417,15 +416,7 @@ impl Function { /// Return an object that can display this function with correct ISA-specific annotations. pub fn display(&self) -> DisplayFunction<'_> { - DisplayFunction(self, Default::default()) - } - - /// Return an object that can display this function with correct ISA-specific annotations. - pub fn display_with<'a>( - &'a self, - annotations: DisplayFunctionAnnotations<'a>, - ) -> DisplayFunction<'a> { - DisplayFunction(self, annotations) + DisplayFunction(self) } /// Sets an absolute source location for the given instruction. @@ -456,15 +447,8 @@ impl Function { } } -/// Additional annotations for function display. -#[derive(Default)] -pub struct DisplayFunctionAnnotations<'a> { - /// Enable value labels annotations. - pub value_ranges: Option<&'a ValueLabelsRanges>, -} - -/// Wrapper type capable of displaying a `Function` with correct ISA annotations. -pub struct DisplayFunction<'a>(&'a Function, DisplayFunctionAnnotations<'a>); +/// Wrapper type capable of displaying a `Function`. +pub struct DisplayFunction<'a>(&'a Function); impl<'a> fmt::Display for DisplayFunction<'a> { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { diff --git a/cranelift/codegen/src/ir/globalvalue.rs b/cranelift/codegen/src/ir/globalvalue.rs index 84094d716658..0faef11205f2 100644 --- a/cranelift/codegen/src/ir/globalvalue.rs +++ b/cranelift/codegen/src/ir/globalvalue.rs @@ -3,7 +3,6 @@ use crate::ir::immediates::{Imm64, Offset32}; use crate::ir::{ExternalName, GlobalValue, Type}; use crate::isa::TargetIsa; -use crate::machinst::RelocDistance; use core::fmt; #[cfg(feature = "enable-serde")] @@ -102,20 +101,6 @@ impl GlobalValueData { Self::DynScaleTargetConst { .. } => isa.pointer_type(), } } - - /// If this global references a symbol, return an estimate of the relocation distance, - /// based on the `colocated` flag. - pub fn maybe_reloc_distance(&self) -> Option { - match self { - &GlobalValueData::Symbol { - colocated: true, .. - } => Some(RelocDistance::Near), - &GlobalValueData::Symbol { - colocated: false, .. - } => Some(RelocDistance::Far), - _ => None, - } - } } impl fmt::Display for GlobalValueData { diff --git a/cranelift/codegen/src/ir/mod.rs b/cranelift/codegen/src/ir/mod.rs index cd302c2397d8..91607cf9b804 100644 --- a/cranelift/codegen/src/ir/mod.rs +++ b/cranelift/codegen/src/ir/mod.rs @@ -43,7 +43,7 @@ pub use crate::ir::extfunc::{ AbiParam, ArgumentExtension, ArgumentPurpose, ExtFuncData, Signature, }; pub use crate::ir::extname::{ExternalName, UserExternalName, UserFuncName}; -pub use crate::ir::function::{DisplayFunctionAnnotations, Function}; +pub use crate::ir::function::Function; pub use crate::ir::globalvalue::GlobalValueData; pub use crate::ir::instructions::{ BlockCall, InstructionData, Opcode, ValueList, ValueListPool, VariableArgs, @@ -62,7 +62,6 @@ pub use crate::ir::stackslot::{ pub use crate::ir::table::TableData; pub use crate::ir::trapcode::TrapCode; pub use crate::ir::types::Type; -pub use crate::value_label::LabelValueLoc; use crate::entity::{entity_impl, PrimaryMap, SecondaryMap}; diff --git a/cranelift/codegen/src/lib.rs b/cranelift/codegen/src/lib.rs index 9230d472e94f..1c8fd16d130d 100644 --- a/cranelift/codegen/src/lib.rs +++ b/cranelift/codegen/src/lib.rs @@ -59,7 +59,7 @@ use hashbrown::{hash_map, HashMap, HashSet}; use std::collections::{hash_map, HashMap, HashSet}; pub use crate::context::Context; -pub use crate::value_label::{ValueLabelsRanges, ValueLocRange}; +pub use crate::value_label::{LabelValueLoc, ValueLabelsRanges, ValueLocRange}; pub use crate::verifier::verify_function; pub use crate::write::write_function; diff --git a/cranelift/codegen/src/machinst/isle.rs b/cranelift/codegen/src/machinst/isle.rs index 87c7a29e2b3a..04793db4d8ee 100644 --- a/cranelift/codegen/src/machinst/isle.rs +++ b/cranelift/codegen/src/machinst/isle.rs @@ -306,11 +306,12 @@ macro_rules! isle_lower_prelude_methods { #[inline] fn func_ref_data(&mut self, func_ref: FuncRef) -> (SigRef, ExternalName, RelocDistance) { let funcdata = &self.lower_ctx.dfg().ext_funcs[func_ref]; - ( - funcdata.signature, - funcdata.name.clone(), - funcdata.reloc_distance(), - ) + let reloc_distance = if funcdata.colocated { + RelocDistance::Near + } else { + RelocDistance::Far + }; + (funcdata.signature, funcdata.name.clone(), reloc_distance) } #[inline] diff --git a/cranelift/codegen/src/machinst/lower.rs b/cranelift/codegen/src/machinst/lower.rs index 2a6b2ecc9653..fe200e5d66f0 100644 --- a/cranelift/codegen/src/machinst/lower.rs +++ b/cranelift/codegen/src/machinst/lower.rs @@ -1120,10 +1120,15 @@ impl<'func, I: VCodeInst> Lower<'func, I> { &GlobalValueData::Symbol { ref name, ref offset, + colocated, .. } => { let offset = offset.bits(); - let dist = gvdata.maybe_reloc_distance().unwrap(); + let dist = if colocated { + RelocDistance::Near + } else { + RelocDistance::Far + }; Some((name, dist, offset)) } _ => None, diff --git a/cranelift/codegen/src/machinst/vcode.rs b/cranelift/codegen/src/machinst/vcode.rs index 81787ca36681..6b05b38c8bd3 100644 --- a/cranelift/codegen/src/machinst/vcode.rs +++ b/cranelift/codegen/src/machinst/vcode.rs @@ -20,12 +20,12 @@ use crate::fx::FxHashMap; use crate::fx::FxHashSet; use crate::ir::RelSourceLoc; -use crate::ir::{self, types, Constant, ConstantData, DynamicStackSlot, LabelValueLoc, ValueLabel}; +use crate::ir::{self, types, Constant, ConstantData, DynamicStackSlot, ValueLabel}; use crate::machinst::*; use crate::timing; use crate::trace; use crate::CodegenError; -use crate::ValueLocRange; +use crate::{LabelValueLoc, ValueLocRange}; use cranelift_control::ControlPlane; use regalloc2::{ Edit, Function as RegallocFunction, InstOrEdit, InstRange, Operand, OperandKind, PRegSet, diff --git a/cranelift/codegen/src/value_label.rs b/cranelift/codegen/src/value_label.rs index ab5276909aa1..5a33dc57e09c 100644 --- a/cranelift/codegen/src/value_label.rs +++ b/cranelift/codegen/src/value_label.rs @@ -1,10 +1,7 @@ -use crate::ir::{SourceLoc, ValueLabel}; +use crate::ir::ValueLabel; use crate::machinst::Reg; use crate::HashMap; use alloc::vec::Vec; -use core::cmp::Ordering; -use core::convert::From; -use core::ops::Deref; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; @@ -33,37 +30,3 @@ pub enum LabelValueLoc { /// Resulting map of Value labels and their ranges/locations. pub type ValueLabelsRanges = HashMap>; - -#[derive(Eq, Clone, Copy)] -pub struct ComparableSourceLoc(SourceLoc); - -impl From for ComparableSourceLoc { - fn from(s: SourceLoc) -> Self { - Self(s) - } -} - -impl Deref for ComparableSourceLoc { - type Target = SourceLoc; - fn deref(&self) -> &SourceLoc { - &self.0 - } -} - -impl PartialOrd for ComparableSourceLoc { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - -impl Ord for ComparableSourceLoc { - fn cmp(&self, other: &Self) -> Ordering { - self.0.bits().cmp(&other.0.bits()) - } -} - -impl PartialEq for ComparableSourceLoc { - fn eq(&self, other: &Self) -> bool { - self.0 == other.0 - } -} diff --git a/cranelift/filetests/src/test_wasm/config.rs b/cranelift/filetests/src/test_wasm/config.rs index 6ba4f3c66a30..3836503e7cfa 100644 --- a/cranelift/filetests/src/test_wasm/config.rs +++ b/cranelift/filetests/src/test_wasm/config.rs @@ -9,9 +9,6 @@ use std::collections::BTreeMap; #[derive(Clone, Debug, Serialize, Deserialize)] pub struct TestConfig { - #[serde(default)] - pub debug_info: bool, - #[serde(default)] pub target: String, diff --git a/cranelift/filetests/src/test_wasm/env.rs b/cranelift/filetests/src/test_wasm/env.rs index 330ba204d3ce..c0b97613e52f 100644 --- a/cranelift/filetests/src/test_wasm/env.rs +++ b/cranelift/filetests/src/test_wasm/env.rs @@ -24,7 +24,7 @@ pub struct ModuleEnv { impl ModuleEnv { pub fn new(target_isa: &dyn TargetIsa, config: TestConfig) -> Self { - let inner = DummyEnvironment::new(target_isa.frontend_config(), config.debug_info); + let inner = DummyEnvironment::new(target_isa.frontend_config()); Self { inner, config, @@ -64,10 +64,6 @@ impl<'data> ModuleEnvironment<'data> for ModuleEnv { sig, ); - if self.inner.debug_info { - func.collect_debug_info(); - } - self.inner .trans .translate_body(&mut validator, body, &mut func, &mut func_environ)?; diff --git a/cranelift/src/souper_harvest.rs b/cranelift/src/souper_harvest.rs index cd8d1b9ebe6d..a8490f842ae4 100644 --- a/cranelift/src/souper_harvest.rs +++ b/cranelift/src/souper_harvest.rs @@ -82,7 +82,7 @@ pub fn run(options: &Options) -> Result<()> { .context("failed to read input file")?; let funcs = if &contents[..WASM_MAGIC.len()] == WASM_MAGIC { - let mut dummy_environ = DummyEnvironment::new(fisa.isa.unwrap().frontend_config(), false); + let mut dummy_environ = DummyEnvironment::new(fisa.isa.unwrap().frontend_config()); cranelift_wasm::translate_module(&contents, &mut dummy_environ) .context("failed to translate Wasm module to clif")?; dummy_environ diff --git a/cranelift/src/wasm.rs b/cranelift/src/wasm.rs index 069bcfca1a83..3dd3ae2ccd2b 100644 --- a/cranelift/src/wasm.rs +++ b/cranelift/src/wasm.rs @@ -10,7 +10,6 @@ use crate::disasm::print_all; use anyhow::{Context as _, Result}; use clap::Parser; -use cranelift_codegen::ir::DisplayFunctionAnnotations; use cranelift_codegen::print_errors::{pretty_error, pretty_verifier_error}; use cranelift_codegen::settings::FlagsOrIsa; use cranelift_codegen::timing; @@ -102,10 +101,6 @@ pub struct Options { #[clap(short = 'c')] check_translation: bool, - /// Display values' ranges and their locations - #[clap(long = "value-ranges")] - value_ranges: bool, - /// Use colors in output? [options: auto/never/always; default: auto] #[clap(long = "color", default_value("auto"))] color: ColorOpt, @@ -185,8 +180,7 @@ fn handle_module(options: &Options, path: &Path, name: &str, fisa: FlagsOrIsa) - } }; - let debug_info = options.value_ranges; - let mut dummy_environ = DummyEnvironment::new(isa.frontend_config(), debug_info); + let mut dummy_environ = DummyEnvironment::new(isa.frontend_config()); translate_module(&module_binary, &mut dummy_environ)?; vcprintln!(options.verbose, use_color, terminal, Color::Green, "ok"); @@ -296,17 +290,7 @@ fn handle_module(options: &Options, path: &Path, name: &str, fisa: FlagsOrIsa) - { println!("; Exported as \"{}\"", export_name); } - let value_ranges = if options.value_ranges { - Some(context.compiled_code().unwrap().value_labels_ranges.clone()) - } else { - None - }; - println!( - "{}", - context.func.display_with(DisplayFunctionAnnotations { - value_ranges: value_ranges.as_ref(), - }) - ); + println!("{}", context.func.display()); vprintln!(options.verbose, ""); } diff --git a/cranelift/wasm/src/environ/dummy.rs b/cranelift/wasm/src/environ/dummy.rs index f77b62474d21..09c50a59e8af 100644 --- a/cranelift/wasm/src/environ/dummy.rs +++ b/cranelift/wasm/src/environ/dummy.rs @@ -144,9 +144,6 @@ pub struct DummyEnvironment { /// Vector of wasm bytecode size for each function. pub func_bytecode_sizes: Vec, - /// Instructs to collect debug data during translation. - pub debug_info: bool, - /// Name of the module from the wasm file. pub module_name: Option, @@ -160,12 +157,11 @@ pub struct DummyEnvironment { impl DummyEnvironment { /// Creates a new `DummyEnvironment` instance. - pub fn new(config: TargetFrontendConfig, debug_info: bool) -> Self { + pub fn new(config: TargetFrontendConfig) -> Self { Self { info: DummyModuleInfo::new(config), trans: FuncTranslator::new(), func_bytecode_sizes: Vec::new(), - debug_info, module_name: None, function_names: SecondaryMap::new(), expected_reachability: None, @@ -905,10 +901,6 @@ impl<'data> ModuleEnvironment<'data> for DummyEnvironment { let mut func = ir::Function::with_name_signature(UserFuncName::user(0, func_index.as_u32()), sig); - if self.debug_info { - func.collect_debug_info(); - } - self.trans .translate_body(&mut validator, body, &mut func, &mut func_environ)?; func diff --git a/cranelift/wasm/src/func_translator.rs b/cranelift/wasm/src/func_translator.rs index e99989010fe2..e282c8a0d249 100644 --- a/cranelift/wasm/src/func_translator.rs +++ b/cranelift/wasm/src/func_translator.rs @@ -322,13 +322,10 @@ mod tests { let mut trans = FuncTranslator::new(); let flags = settings::Flags::new(settings::builder()); - let runtime = DummyEnvironment::new( - isa::TargetFrontendConfig { - default_call_conv: isa::CallConv::Fast, - pointer_width: PointerWidth::U64, - }, - false, - ); + let runtime = DummyEnvironment::new(isa::TargetFrontendConfig { + default_call_conv: isa::CallConv::Fast, + pointer_width: PointerWidth::U64, + }); let mut ctx = Context::new(); @@ -360,13 +357,10 @@ mod tests { let mut trans = FuncTranslator::new(); let flags = settings::Flags::new(settings::builder()); - let runtime = DummyEnvironment::new( - isa::TargetFrontendConfig { - default_call_conv: isa::CallConv::Fast, - pointer_width: PointerWidth::U64, - }, - false, - ); + let runtime = DummyEnvironment::new(isa::TargetFrontendConfig { + default_call_conv: isa::CallConv::Fast, + pointer_width: PointerWidth::U64, + }); let mut ctx = Context::new(); @@ -403,13 +397,10 @@ mod tests { let mut trans = FuncTranslator::new(); let flags = settings::Flags::new(settings::builder()); - let runtime = DummyEnvironment::new( - isa::TargetFrontendConfig { - default_call_conv: isa::CallConv::Fast, - pointer_width: PointerWidth::U64, - }, - false, - ); + let runtime = DummyEnvironment::new(isa::TargetFrontendConfig { + default_call_conv: isa::CallConv::Fast, + pointer_width: PointerWidth::U64, + }); let mut ctx = Context::new(); diff --git a/cranelift/wasm/tests/wasm_testsuite.rs b/cranelift/wasm/tests/wasm_testsuite.rs index d69c75526f22..311b879b0b55 100644 --- a/cranelift/wasm/tests/wasm_testsuite.rs +++ b/cranelift/wasm/tests/wasm_testsuite.rs @@ -43,13 +43,10 @@ fn use_name_section() { ) .unwrap(); - let mut dummy_environ = DummyEnvironment::new( - TargetFrontendConfig { - default_call_conv: CallConv::SystemV, - pointer_width: PointerWidth::U32, - }, - false, - ); + let mut dummy_environ = DummyEnvironment::new(TargetFrontendConfig { + default_call_conv: CallConv::SystemV, + pointer_width: PointerWidth::U32, + }); translate_module(data.as_ref(), &mut dummy_environ).unwrap(); @@ -75,13 +72,10 @@ fn read_module(path: &Path) -> Vec { } fn handle_module(data: Vec, flags: &Flags) { - let mut dummy_environ = DummyEnvironment::new( - TargetFrontendConfig { - default_call_conv: CallConv::SystemV, - pointer_width: PointerWidth::U64, - }, - false, - ); + let mut dummy_environ = DummyEnvironment::new(TargetFrontendConfig { + default_call_conv: CallConv::SystemV, + pointer_width: PointerWidth::U64, + }); translate_module(&data, &mut dummy_environ).unwrap(); @@ -148,13 +142,10 @@ fn reachability_is_correct() { for (wat, expected_reachability) in tests { println!("testing wat:\n{}", wat); - let mut env = DummyEnvironment::new( - TargetFrontendConfig { - default_call_conv: CallConv::SystemV, - pointer_width: PointerWidth::U64, - }, - false, - ); + let mut env = DummyEnvironment::new(TargetFrontendConfig { + default_call_conv: CallConv::SystemV, + pointer_width: PointerWidth::U64, + }); env.test_expected_reachability(expected_reachability); let data = wat::parse_str(wat).unwrap(); translate_module(data.as_ref(), &mut env).unwrap(); diff --git a/crates/cranelift/src/debug/transform/expression.rs b/crates/cranelift/src/debug/transform/expression.rs index d375ef7c3674..a0428900c894 100644 --- a/crates/cranelift/src/debug/transform/expression.rs +++ b/crates/cranelift/src/debug/transform/expression.rs @@ -1,8 +1,9 @@ use super::address_transform::AddressTransform; use crate::debug::ModuleMemoryOffset; use anyhow::{Context, Error, Result}; -use cranelift_codegen::ir::{LabelValueLoc, StackSlots, ValueLabel}; +use cranelift_codegen::ir::{StackSlots, ValueLabel}; use cranelift_codegen::isa::TargetIsa; +use cranelift_codegen::LabelValueLoc; use cranelift_codegen::ValueLabelsRanges; use cranelift_wasm::get_vmctx_value_label; use gimli::{self, write, Expression, Operation, Reader, ReaderOffset, X86_64}; @@ -1158,8 +1159,7 @@ mod tests { } fn create_mock_value_ranges() -> (ValueLabelsRanges, (ValueLabel, ValueLabel, ValueLabel)) { - use cranelift_codegen::ir::LabelValueLoc; - use cranelift_codegen::ValueLocRange; + use cranelift_codegen::{LabelValueLoc, ValueLocRange}; use cranelift_entity::EntityRef; use std::collections::HashMap; let mut value_ranges = HashMap::new();