Browse Source

A bunch of minor cleanups (#6767)

* Remove DisplayFunctionAnnotations

It used to exist for printing the debuginfo value ranges with the clif
ir, but this no longer happens, so it is now useless.

* Remove debug info collection from DummyEnvironment

There are no remaining users of it

* Remove ComparableSourceLoc

It is unused

* Move LabelValueLoc re-export out of the ir module

It encodes target specific information, so shouldn't be in the target
independent ir module.

* Remove RelocDistance dependency from ir::extfunc and ir::globalvalue
pull/6771/head
bjorn3 1 year ago
committed by GitHub
parent
commit
729e26409e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      cranelift/codegen/src/ir/extfunc.rs
  2. 22
      cranelift/codegen/src/ir/function.rs
  3. 15
      cranelift/codegen/src/ir/globalvalue.rs
  4. 3
      cranelift/codegen/src/ir/mod.rs
  5. 2
      cranelift/codegen/src/lib.rs
  6. 11
      cranelift/codegen/src/machinst/isle.rs
  7. 7
      cranelift/codegen/src/machinst/lower.rs
  8. 4
      cranelift/codegen/src/machinst/vcode.rs
  9. 39
      cranelift/codegen/src/value_label.rs
  10. 3
      cranelift/filetests/src/test_wasm/config.rs
  11. 6
      cranelift/filetests/src/test_wasm/env.rs
  12. 2
      cranelift/src/souper_harvest.rs
  13. 20
      cranelift/src/wasm.rs
  14. 10
      cranelift/wasm/src/environ/dummy.rs
  15. 33
      cranelift/wasm/src/func_translator.rs
  16. 33
      cranelift/wasm/tests/wasm_testsuite.rs
  17. 6
      crates/cranelift/src/debug/transform/expression.rs

10
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>(

22
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 {

15
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<RelocDistance> {
match self {
&GlobalValueData::Symbol {
colocated: true, ..
} => Some(RelocDistance::Near),
&GlobalValueData::Symbol {
colocated: false, ..
} => Some(RelocDistance::Far),
_ => None,
}
}
}
impl fmt::Display for GlobalValueData {

3
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};

2
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;

11
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]

7
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,

4
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,

39
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<ValueLabel, Vec<ValueLocRange>>;
#[derive(Eq, Clone, Copy)]
pub struct ComparableSourceLoc(SourceLoc);
impl From<SourceLoc> 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<Ordering> {
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
}
}

3
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,

6
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)?;

2
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

20
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, "");
}

10
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<usize>,
/// Instructs to collect debug data during translation.
pub debug_info: bool,
/// Name of the module from the wasm file.
pub module_name: Option<String>,
@ -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

33
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();

33
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<u8> {
}
fn handle_module(data: Vec<u8>, 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();

6
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();

Loading…
Cancel
Save