Skip to content

Commit

Permalink
Remove RelocDistance dependency from ir::extfunc and ir::globalvalue
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Jul 25, 2023
1 parent 73279de commit 83be34e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 31 deletions.
10 changes: 0 additions & 10 deletions cranelift/codegen/src/ir/extfunc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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>(
Expand Down
15 changes: 0 additions & 15 deletions cranelift/codegen/src/ir/globalvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 6 additions & 5 deletions cranelift/codegen/src/machinst/isle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 6 additions & 1 deletion cranelift/codegen/src/machinst/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 83be34e

Please sign in to comment.