Merge pull request #3435 from bjorn3/remove_various_dead_code
Remove various dead code
This commit is contained in:
@@ -99,7 +99,6 @@ mod licm;
|
|||||||
mod log;
|
mod log;
|
||||||
mod machinst;
|
mod machinst;
|
||||||
mod nan_canonicalization;
|
mod nan_canonicalization;
|
||||||
mod predicates;
|
|
||||||
mod remove_constant_phis;
|
mod remove_constant_phis;
|
||||||
mod result;
|
mod result;
|
||||||
mod scoped_hash_map;
|
mod scoped_hash_map;
|
||||||
|
|||||||
@@ -1,140 +0,0 @@
|
|||||||
//! Predicate functions for testing instruction fields.
|
|
||||||
//!
|
|
||||||
//! This module defines functions that are used by the instruction predicates defined by
|
|
||||||
//! `cranelift-codegen/meta/src/cdsl/instructions.rs` classes.
|
|
||||||
//!
|
|
||||||
//! The predicates the operate on integer fields use `Into<i64>` as a shared trait bound. This
|
|
||||||
//! bound is implemented by all the native integer types as well as `Imm64`.
|
|
||||||
//!
|
|
||||||
//! Some of these predicates may be unused in certain ISA configurations, so we suppress the
|
|
||||||
//! dead code warning.
|
|
||||||
|
|
||||||
use crate::ir;
|
|
||||||
use crate::ir::ConstantData;
|
|
||||||
|
|
||||||
/// Check that an integer value is zero.
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn is_zero_int<T: Into<i64>>(x: T) -> bool {
|
|
||||||
x.into() == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Check that a 64-bit floating point value is zero.
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn is_zero_64_bit_float<T: Into<ir::immediates::Ieee64>>(x: T) -> bool {
|
|
||||||
let x64 = x.into();
|
|
||||||
x64.bits() == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Check that a 32-bit floating point value is zero.
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn is_zero_32_bit_float<T: Into<ir::immediates::Ieee32>>(x: T) -> bool {
|
|
||||||
let x32 = x.into();
|
|
||||||
x32.bits() == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Check that a constant contains all zeroes.
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn is_all_zeroes(x: &ConstantData) -> bool {
|
|
||||||
x.iter().all(|&f| f == 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Check that a constant contains all ones.
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn is_all_ones(x: &ConstantData) -> bool {
|
|
||||||
x.iter().all(|&f| f == 0xff)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Check that `x` is the same as `y`.
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn is_equal<T: Eq + Copy, O: Into<T> + Copy>(x: T, y: O) -> bool {
|
|
||||||
x == y.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Check that `x` can be represented as a `wd`-bit signed integer with `sc` low zero bits.
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn is_signed_int<T: Into<i64>>(x: T, wd: u8, sc: u8) -> bool {
|
|
||||||
let s = x.into();
|
|
||||||
s == (s >> sc << (64 - wd + sc) >> (64 - wd))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Check that `x` can be represented as a `wd`-bit unsigned integer with `sc` low zero bits.
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn is_unsigned_int<T: Into<i64>>(x: T, wd: u8, sc: u8) -> bool {
|
|
||||||
let u = x.into() as u64;
|
|
||||||
// Bit-mask of the permitted bits.
|
|
||||||
let m = (1 << wd) - (1 << sc);
|
|
||||||
u == (u & m)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn is_colocated_func(func_ref: ir::FuncRef, func: &ir::Function) -> bool {
|
|
||||||
func.dfg.ext_funcs[func_ref].colocated
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn is_colocated_data(global_value: ir::GlobalValue, func: &ir::Function) -> bool {
|
|
||||||
match func.global_values[global_value] {
|
|
||||||
ir::GlobalValueData::Symbol { colocated, .. } => colocated,
|
|
||||||
_ => panic!("is_colocated_data only makes sense for data with symbolic addresses"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn has_length_of(value_list: &ir::ValueList, num: usize, func: &ir::Function) -> bool {
|
|
||||||
value_list.len(&func.dfg.value_lists) == num
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn cvt_u32() {
|
|
||||||
let x1 = 0u32;
|
|
||||||
let x2 = 1u32;
|
|
||||||
let x3 = 0xffff_fff0u32;
|
|
||||||
|
|
||||||
assert!(is_signed_int(x1, 1, 0));
|
|
||||||
assert!(is_signed_int(x1, 2, 1));
|
|
||||||
assert!(is_signed_int(x2, 2, 0));
|
|
||||||
assert!(!is_signed_int(x2, 2, 1));
|
|
||||||
|
|
||||||
// `u32` doesn't sign-extend when converted to `i64`.
|
|
||||||
assert!(!is_signed_int(x3, 8, 0));
|
|
||||||
|
|
||||||
assert!(is_unsigned_int(x1, 1, 0));
|
|
||||||
assert!(is_unsigned_int(x1, 8, 4));
|
|
||||||
assert!(is_unsigned_int(x2, 1, 0));
|
|
||||||
assert!(!is_unsigned_int(x2, 8, 4));
|
|
||||||
assert!(!is_unsigned_int(x3, 1, 0));
|
|
||||||
assert!(is_unsigned_int(x3, 32, 4));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn cvt_imm64() {
|
|
||||||
use crate::ir::immediates::Imm64;
|
|
||||||
|
|
||||||
let x1 = Imm64::new(-8);
|
|
||||||
let x2 = Imm64::new(8);
|
|
||||||
|
|
||||||
assert!(is_signed_int(x1, 16, 2));
|
|
||||||
assert!(is_signed_int(x2, 16, 2));
|
|
||||||
assert!(!is_signed_int(x1, 16, 4));
|
|
||||||
assert!(!is_signed_int(x2, 16, 4));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn check_is_all_zeroes() {
|
|
||||||
assert!(is_all_zeroes(&[0; 16].as_ref().into()));
|
|
||||||
assert!(is_all_zeroes(
|
|
||||||
&vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0].into()
|
|
||||||
));
|
|
||||||
assert!(!is_all_zeroes(&[1; 16].as_ref().into()));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn check_is_all_ones() {
|
|
||||||
assert!(!is_all_ones(&[0; 16].as_ref().into()));
|
|
||||||
assert!(is_all_ones(&[0xff; 16].as_ref().into()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -54,7 +54,6 @@ define_passes! {
|
|||||||
loop_analysis: "Loop analysis",
|
loop_analysis: "Loop analysis",
|
||||||
preopt: "Pre-legalization rewriting",
|
preopt: "Pre-legalization rewriting",
|
||||||
dce: "Dead code elimination",
|
dce: "Dead code elimination",
|
||||||
legalize: "Legalization",
|
|
||||||
gvn: "Global value numbering",
|
gvn: "Global value numbering",
|
||||||
licm: "Loop invariant code motion",
|
licm: "Loop invariant code motion",
|
||||||
unreachable_code: "Remove unreachable blocks",
|
unreachable_code: "Remove unreachable blocks",
|
||||||
@@ -66,15 +65,6 @@ define_passes! {
|
|||||||
vcode_emit_finish: "VCode emission finalization",
|
vcode_emit_finish: "VCode emission finalization",
|
||||||
|
|
||||||
regalloc: "Register allocation",
|
regalloc: "Register allocation",
|
||||||
ra_liveness: "RA liveness analysis",
|
|
||||||
ra_cssa: "RA coalescing CSSA",
|
|
||||||
ra_spilling: "RA spilling",
|
|
||||||
ra_reload: "RA reloading",
|
|
||||||
ra_coloring: "RA coloring",
|
|
||||||
|
|
||||||
prologue_epilogue: "Prologue/epilogue insertion",
|
|
||||||
shrink_instructions: "Instruction encoding shrinking",
|
|
||||||
relax_branches: "Branch relaxation",
|
|
||||||
binemit: "Binary machine code emission",
|
binemit: "Binary machine code emission",
|
||||||
layout_renumber: "Layout full renumbering",
|
layout_renumber: "Layout full renumbering",
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user