Fix clippy warnings.
This commit fixes the current set of (stable) clippy warnings in the repo.
This commit is contained in:
committed by
Andrew Brown
parent
1176e4f178
commit
9f506692c2
@@ -26,13 +26,13 @@ pub enum ArgAction {
|
||||
|
||||
impl From<ArgumentLoc> for ArgAction {
|
||||
fn from(x: ArgumentLoc) -> Self {
|
||||
ArgAction::Assign(x)
|
||||
Self::Assign(x)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ValueConversion> for ArgAction {
|
||||
fn from(x: ValueConversion) -> Self {
|
||||
ArgAction::Convert(x)
|
||||
Self::Convert(x)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,17 +59,17 @@ impl ValueConversion {
|
||||
/// Apply this conversion to a type, return the converted type.
|
||||
pub fn apply(self, ty: Type) -> Type {
|
||||
match self {
|
||||
ValueConversion::IntSplit => ty.half_width().expect("Integer type too small to split"),
|
||||
ValueConversion::VectorSplit => ty.half_vector().expect("Not a vector"),
|
||||
ValueConversion::IntBits => Type::int(ty.bits()).expect("Bad integer size"),
|
||||
ValueConversion::Sext(nty) | ValueConversion::Uext(nty) => nty,
|
||||
Self::IntSplit => ty.half_width().expect("Integer type too small to split"),
|
||||
Self::VectorSplit => ty.half_vector().expect("Not a vector"),
|
||||
Self::IntBits => Type::int(ty.bits()).expect("Bad integer size"),
|
||||
Self::Sext(nty) | Self::Uext(nty) => nty,
|
||||
}
|
||||
}
|
||||
|
||||
/// Is this a split conversion that results in two arguments?
|
||||
pub fn is_split(self) -> bool {
|
||||
match self {
|
||||
ValueConversion::IntSplit | ValueConversion::VectorSplit => true,
|
||||
Self::IntSplit | Self::VectorSplit => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,14 +63,14 @@ impl fmt::Display for Reloc {
|
||||
/// already unambiguous, e.g. clif syntax with isa specified. In other contexts, use Debug.
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
Reloc::Abs4 => write!(f, "Abs4"),
|
||||
Reloc::Abs8 => write!(f, "Abs8"),
|
||||
Reloc::X86PCRel4 => write!(f, "PCRel4"),
|
||||
Reloc::X86PCRelRodata4 => write!(f, "PCRelRodata4"),
|
||||
Reloc::X86CallPCRel4 => write!(f, "CallPCRel4"),
|
||||
Reloc::X86CallPLTRel4 => write!(f, "CallPLTRel4"),
|
||||
Reloc::X86GOTPCRel4 => write!(f, "GOTPCRel4"),
|
||||
Reloc::Arm32Call | Reloc::Arm64Call | Reloc::RiscvCall => write!(f, "Call"),
|
||||
Self::Abs4 => write!(f, "Abs4"),
|
||||
Self::Abs8 => write!(f, "Abs8"),
|
||||
Self::X86PCRel4 => write!(f, "PCRel4"),
|
||||
Self::X86PCRelRodata4 => write!(f, "PCRelRodata4"),
|
||||
Self::X86CallPCRel4 => write!(f, "CallPCRel4"),
|
||||
Self::X86CallPLTRel4 => write!(f, "CallPLTRel4"),
|
||||
Self::X86GOTPCRel4 => write!(f, "GOTPCRel4"),
|
||||
Self::Arm32Call | Self::Arm64Call | Self::RiscvCall => write!(f, "Call"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ fn try_fold_redundant_jump(
|
||||
let arguments_vec: alloc::vec::Vec<_> = first_args
|
||||
.iter()
|
||||
.chain(second_params.iter())
|
||||
.map(|x| *x)
|
||||
.copied()
|
||||
.collect();
|
||||
let value_list = ValueList::from_slice(&arguments_vec, &mut func.dfg.value_lists);
|
||||
|
||||
@@ -255,7 +255,7 @@ fn try_fold_redundant_jump(
|
||||
func.layout.remove_ebb(first_dest); // ...from the layout.
|
||||
}
|
||||
|
||||
return true;
|
||||
true
|
||||
}
|
||||
|
||||
/// Redirects `jump` instructions that point to other `jump` instructions to the final destination.
|
||||
|
||||
@@ -55,7 +55,7 @@ impl Stackmap {
|
||||
}
|
||||
}
|
||||
|
||||
Stackmap::from_slice(&vec)
|
||||
Self::from_slice(&vec)
|
||||
}
|
||||
|
||||
/// Create a vec of Bitsets from a slice of bools.
|
||||
|
||||
@@ -74,7 +74,7 @@ where
|
||||
|
||||
let lo_rng = (one << lo) - one;
|
||||
|
||||
BitSet(hi_rng - lo_rng)
|
||||
Self(hi_rng - lo_rng)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -645,13 +645,14 @@ impl<'c, 'f> ir::InstInserterBase<'c> for &'c mut FuncCursor<'f> {
|
||||
let prev_op = self.data_flow_graph()[prev].opcode();
|
||||
let inst_op = self.data_flow_graph()[inst].opcode();
|
||||
let curr_op = self.data_flow_graph()[curr].opcode();
|
||||
if prev_op.is_branch() && !prev_op.is_terminator() {
|
||||
if !inst_op.is_terminator() {
|
||||
panic!(
|
||||
"Inserting instruction {} after {}, and before {}",
|
||||
inst_op, prev_op, curr_op
|
||||
)
|
||||
};
|
||||
if prev_op.is_branch()
|
||||
&& !prev_op.is_terminator()
|
||||
&& !inst_op.is_terminator()
|
||||
{
|
||||
panic!(
|
||||
"Inserting instruction {} after {}, and before {}",
|
||||
inst_op, prev_op, curr_op
|
||||
)
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -773,15 +774,16 @@ impl<'c, 'f> ir::InstInserterBase<'c> for &'c mut EncCursor<'f> {
|
||||
if let Some(prev) = self.layout().prev_inst(curr) {
|
||||
let prev_op = self.data_flow_graph()[prev].opcode();
|
||||
let inst_op = self.data_flow_graph()[inst].opcode();
|
||||
if prev_op.is_branch() && !prev_op.is_terminator() {
|
||||
if !inst_op.is_terminator() {
|
||||
panic!(
|
||||
"Inserting instruction {} after {} and before {}",
|
||||
self.display_inst(inst),
|
||||
self.display_inst(prev),
|
||||
self.display_inst(curr)
|
||||
)
|
||||
};
|
||||
if prev_op.is_branch()
|
||||
&& !prev_op.is_terminator()
|
||||
&& !inst_op.is_terminator()
|
||||
{
|
||||
panic!(
|
||||
"Inserting instruction {} after {} and before {}",
|
||||
self.display_inst(inst),
|
||||
self.display_inst(prev),
|
||||
self.display_inst(curr)
|
||||
)
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -79,7 +79,7 @@ pub fn magic_u32(d: u32) -> MU32 {
|
||||
|
||||
MU32 {
|
||||
mul_by: q2 + 1,
|
||||
do_add: do_add,
|
||||
do_add,
|
||||
shift_by: p - 32,
|
||||
}
|
||||
}
|
||||
@@ -125,7 +125,7 @@ pub fn magic_u64(d: u64) -> MU64 {
|
||||
|
||||
MU64 {
|
||||
mul_by: q2 + 1,
|
||||
do_add: do_add,
|
||||
do_add,
|
||||
shift_by: p - 64,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ pub struct ConstantData(Vec<u8>);
|
||||
impl FromIterator<u8> for ConstantData {
|
||||
fn from_iter<T: IntoIterator<Item = u8>>(iter: T) -> Self {
|
||||
let v = iter.into_iter().collect();
|
||||
ConstantData(v)
|
||||
Self(v)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ impl ConstantData {
|
||||
}
|
||||
|
||||
/// Convert the data to a vector.
|
||||
pub fn to_vec(self) -> Vec<u8> {
|
||||
pub fn into_vec(self) -> Vec<u8> {
|
||||
self.0
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ impl FromStr for ConstantData {
|
||||
/// ```
|
||||
/// use cranelift_codegen::ir::ConstantData;
|
||||
/// let c: ConstantData = "0x000102".parse().unwrap();
|
||||
/// assert_eq!(c.to_vec(), [2, 1, 0]);
|
||||
/// assert_eq!(c.into_vec(), [2, 1, 0]);
|
||||
/// ```
|
||||
fn from_str(s: &str) -> Result<Self, &'static str> {
|
||||
if s.len() <= 2 || &s[0..2] != "0x" {
|
||||
@@ -137,7 +137,7 @@ impl FromStr for ConstantData {
|
||||
.cloned()
|
||||
.collect(); // remove 0x prefix and any intervening _ characters
|
||||
|
||||
if cleaned.len() == 0 {
|
||||
if cleaned.is_empty() {
|
||||
Err("Hexadecimal string must have some digits")
|
||||
} else if cleaned.len() % 2 != 0 {
|
||||
Err("Hexadecimal string must have an even number of digits")
|
||||
@@ -152,7 +152,7 @@ impl FromStr for ConstantData {
|
||||
.or_else(|_| Err("Unable to parse as hexadecimal"))?;
|
||||
buffer.insert(0, byte);
|
||||
}
|
||||
Ok(ConstantData(buffer))
|
||||
Ok(Self(buffer))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -221,15 +221,13 @@ impl ConstantPool {
|
||||
/// returned.
|
||||
pub fn insert(&mut self, constant_value: ConstantData) -> Constant {
|
||||
if self.values_to_handles.contains_key(&constant_value) {
|
||||
self.values_to_handles.get(&constant_value).unwrap().clone()
|
||||
*self.values_to_handles.get(&constant_value).unwrap()
|
||||
} else {
|
||||
let constant_handle = Constant::new(self.len());
|
||||
self.values_to_handles
|
||||
.insert(constant_value.clone(), constant_handle.clone());
|
||||
self.handles_to_values.insert(
|
||||
constant_handle.clone(),
|
||||
ConstantPoolEntry::new(constant_value),
|
||||
);
|
||||
.insert(constant_value.clone(), constant_handle);
|
||||
self.handles_to_values
|
||||
.insert(constant_handle, ConstantPoolEntry::new(constant_value));
|
||||
constant_handle
|
||||
}
|
||||
}
|
||||
@@ -402,13 +400,13 @@ mod tests {
|
||||
fn add_to_constant_data() {
|
||||
let d = ConstantData::from([1, 2].as_ref());
|
||||
let e = d.append(i16::from(3u8));
|
||||
assert_eq!(e.to_vec(), vec![1, 2, 3, 0])
|
||||
assert_eq!(e.into_vec(), vec![1, 2, 3, 0])
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extend_constant_data() {
|
||||
let d = ConstantData::from([1, 2].as_ref());
|
||||
assert_eq!(d.expand_to(4).to_vec(), vec![1, 2, 0, 0])
|
||||
assert_eq!(d.expand_to(4).into_vec(), vec![1, 2, 0, 0])
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -460,7 +458,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn verify_stored_bytes_in_constant_data() {
|
||||
assert_eq!("0x01".parse::<ConstantData>().unwrap().to_vec(), [1]);
|
||||
assert_eq!("0x01".parse::<ConstantData>().unwrap().into_vec(), [1]);
|
||||
assert_eq!(ConstantData::from([1, 0].as_ref()).0, [1, 0]);
|
||||
assert_eq!(ConstantData::from(vec![1, 0, 0, 0]).0, [1, 0, 0, 0]);
|
||||
}
|
||||
@@ -468,7 +466,10 @@ mod tests {
|
||||
#[test]
|
||||
fn check_constant_data_endianness_as_uimm128() {
|
||||
fn parse_to_uimm128(from: &str) -> Vec<u8> {
|
||||
from.parse::<ConstantData>().unwrap().expand_to(16).to_vec()
|
||||
from.parse::<ConstantData>()
|
||||
.unwrap()
|
||||
.expand_to(16)
|
||||
.into_vec()
|
||||
}
|
||||
|
||||
assert_eq!(
|
||||
|
||||
@@ -378,7 +378,7 @@ impl ValueDef {
|
||||
/// Unwrap the instruction where the value was defined, or panic.
|
||||
pub fn unwrap_inst(&self) -> Inst {
|
||||
match *self {
|
||||
ValueDef::Result(inst, _) => inst,
|
||||
Self::Result(inst, _) => inst,
|
||||
_ => panic!("Value is not an instruction result"),
|
||||
}
|
||||
}
|
||||
@@ -386,7 +386,7 @@ impl ValueDef {
|
||||
/// Unwrap the EBB there the parameter is defined, or panic.
|
||||
pub fn unwrap_ebb(&self) -> Ebb {
|
||||
match *self {
|
||||
ValueDef::Param(ebb, _) => ebb,
|
||||
Self::Param(ebb, _) => ebb,
|
||||
_ => panic!("Value is not an EBB parameter"),
|
||||
}
|
||||
}
|
||||
@@ -402,7 +402,7 @@ impl ValueDef {
|
||||
/// this value.
|
||||
pub fn num(self) -> usize {
|
||||
match self {
|
||||
ValueDef::Result(_, n) | ValueDef::Param(_, n) => n,
|
||||
Self::Result(_, n) | Self::Param(_, n) => n,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ impl Ebb {
|
||||
/// This method is for use by the parser.
|
||||
pub fn with_number(n: u32) -> Option<Self> {
|
||||
if n < u32::MAX {
|
||||
Some(Ebb(n))
|
||||
Some(Self(n))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -72,7 +72,7 @@ impl Value {
|
||||
/// This method is for use by the parser.
|
||||
pub fn with_number(n: u32) -> Option<Self> {
|
||||
if n < u32::MAX / 2 {
|
||||
Some(Value(n))
|
||||
Some(Self(n))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -118,7 +118,7 @@ impl StackSlot {
|
||||
/// This method is for use by the parser.
|
||||
pub fn with_number(n: u32) -> Option<Self> {
|
||||
if n < u32::MAX {
|
||||
Some(StackSlot(n))
|
||||
Some(Self(n))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -152,7 +152,7 @@ impl GlobalValue {
|
||||
/// This method is for use by the parser.
|
||||
pub fn with_number(n: u32) -> Option<Self> {
|
||||
if n < u32::MAX {
|
||||
Some(GlobalValue(n))
|
||||
Some(Self(n))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -174,7 +174,7 @@ impl Constant {
|
||||
/// This method is for use by the parser.
|
||||
pub fn with_number(n: u32) -> Option<Self> {
|
||||
if n < u32::MAX {
|
||||
Some(Constant(n))
|
||||
Some(Self(n))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -197,7 +197,7 @@ impl Immediate {
|
||||
/// This method is for use by the parser.
|
||||
pub fn with_number(n: u32) -> Option<Self> {
|
||||
if n < u32::MAX {
|
||||
Some(Immediate(n))
|
||||
Some(Self(n))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -225,7 +225,7 @@ impl JumpTable {
|
||||
/// This method is for use by the parser.
|
||||
pub fn with_number(n: u32) -> Option<Self> {
|
||||
if n < u32::MAX {
|
||||
Some(JumpTable(n))
|
||||
Some(Self(n))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -258,7 +258,7 @@ impl FuncRef {
|
||||
/// This method is for use by the parser.
|
||||
pub fn with_number(n: u32) -> Option<Self> {
|
||||
if n < u32::MAX {
|
||||
Some(FuncRef(n))
|
||||
Some(Self(n))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -287,7 +287,7 @@ impl SigRef {
|
||||
/// This method is for use by the parser.
|
||||
pub fn with_number(n: u32) -> Option<Self> {
|
||||
if n < u32::MAX {
|
||||
Some(SigRef(n))
|
||||
Some(Self(n))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -310,7 +310,7 @@ impl Heap {
|
||||
/// This method is for use by the parser.
|
||||
pub fn with_number(n: u32) -> Option<Self> {
|
||||
if n < u32::MAX {
|
||||
Some(Heap(n))
|
||||
Some(Self(n))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -334,7 +334,7 @@ impl Table {
|
||||
/// This method is for use by the parser.
|
||||
pub fn with_number(n: u32) -> Option<Self> {
|
||||
if n < u32::MAX {
|
||||
Some(Table(n))
|
||||
Some(Self(n))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -371,17 +371,17 @@ pub enum AnyEntity {
|
||||
impl fmt::Display for AnyEntity {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
AnyEntity::Function => write!(f, "function"),
|
||||
AnyEntity::Ebb(r) => r.fmt(f),
|
||||
AnyEntity::Inst(r) => r.fmt(f),
|
||||
AnyEntity::Value(r) => r.fmt(f),
|
||||
AnyEntity::StackSlot(r) => r.fmt(f),
|
||||
AnyEntity::GlobalValue(r) => r.fmt(f),
|
||||
AnyEntity::JumpTable(r) => r.fmt(f),
|
||||
AnyEntity::FuncRef(r) => r.fmt(f),
|
||||
AnyEntity::SigRef(r) => r.fmt(f),
|
||||
AnyEntity::Heap(r) => r.fmt(f),
|
||||
AnyEntity::Table(r) => r.fmt(f),
|
||||
Self::Function => write!(f, "function"),
|
||||
Self::Ebb(r) => r.fmt(f),
|
||||
Self::Inst(r) => r.fmt(f),
|
||||
Self::Value(r) => r.fmt(f),
|
||||
Self::StackSlot(r) => r.fmt(f),
|
||||
Self::GlobalValue(r) => r.fmt(f),
|
||||
Self::JumpTable(r) => r.fmt(f),
|
||||
Self::FuncRef(r) => r.fmt(f),
|
||||
Self::SigRef(r) => r.fmt(f),
|
||||
Self::Heap(r) => r.fmt(f),
|
||||
Self::Table(r) => r.fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -394,61 +394,61 @@ impl fmt::Debug for AnyEntity {
|
||||
|
||||
impl From<Ebb> for AnyEntity {
|
||||
fn from(r: Ebb) -> Self {
|
||||
AnyEntity::Ebb(r)
|
||||
Self::Ebb(r)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Inst> for AnyEntity {
|
||||
fn from(r: Inst) -> Self {
|
||||
AnyEntity::Inst(r)
|
||||
Self::Inst(r)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Value> for AnyEntity {
|
||||
fn from(r: Value) -> Self {
|
||||
AnyEntity::Value(r)
|
||||
Self::Value(r)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<StackSlot> for AnyEntity {
|
||||
fn from(r: StackSlot) -> Self {
|
||||
AnyEntity::StackSlot(r)
|
||||
Self::StackSlot(r)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<GlobalValue> for AnyEntity {
|
||||
fn from(r: GlobalValue) -> Self {
|
||||
AnyEntity::GlobalValue(r)
|
||||
Self::GlobalValue(r)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<JumpTable> for AnyEntity {
|
||||
fn from(r: JumpTable) -> Self {
|
||||
AnyEntity::JumpTable(r)
|
||||
Self::JumpTable(r)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FuncRef> for AnyEntity {
|
||||
fn from(r: FuncRef) -> Self {
|
||||
AnyEntity::FuncRef(r)
|
||||
Self::FuncRef(r)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SigRef> for AnyEntity {
|
||||
fn from(r: SigRef) -> Self {
|
||||
AnyEntity::SigRef(r)
|
||||
Self::SigRef(r)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Heap> for AnyEntity {
|
||||
fn from(r: Heap) -> Self {
|
||||
AnyEntity::Heap(r)
|
||||
Self::Heap(r)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Table> for AnyEntity {
|
||||
fn from(r: Table) -> Self {
|
||||
AnyEntity::Table(r)
|
||||
Self::Table(r)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -294,14 +294,14 @@ impl FromStr for ArgumentPurpose {
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> Result<Self, ()> {
|
||||
match s {
|
||||
"normal" => Ok(ArgumentPurpose::Normal),
|
||||
"sret" => Ok(ArgumentPurpose::StructReturn),
|
||||
"link" => Ok(ArgumentPurpose::Link),
|
||||
"fp" => Ok(ArgumentPurpose::FramePointer),
|
||||
"csr" => Ok(ArgumentPurpose::CalleeSaved),
|
||||
"vmctx" => Ok(ArgumentPurpose::VMContext),
|
||||
"sigid" => Ok(ArgumentPurpose::SignatureId),
|
||||
"stack_limit" => Ok(ArgumentPurpose::StackLimit),
|
||||
"normal" => Ok(Self::Normal),
|
||||
"sret" => Ok(Self::StructReturn),
|
||||
"link" => Ok(Self::Link),
|
||||
"fp" => Ok(Self::FramePointer),
|
||||
"csr" => Ok(Self::CalleeSaved),
|
||||
"vmctx" => Ok(Self::VMContext),
|
||||
"sigid" => Ok(Self::SignatureId),
|
||||
"stack_limit" => Ok(Self::StackLimit),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ impl ExternalName {
|
||||
let mut bytes = [0u8; TESTCASE_NAME_LENGTH];
|
||||
bytes[0..len].copy_from_slice(&vec[0..len]);
|
||||
|
||||
ExternalName::TestCase {
|
||||
Self::TestCase {
|
||||
length: len as u8,
|
||||
ascii: bytes,
|
||||
}
|
||||
@@ -78,7 +78,7 @@ impl ExternalName {
|
||||
/// assert_eq!(name.to_string(), "u123:456");
|
||||
/// ```
|
||||
pub fn user(namespace: u32, index: u32) -> Self {
|
||||
ExternalName::User { namespace, index }
|
||||
Self::User { namespace, index }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,15 +91,15 @@ impl Default for ExternalName {
|
||||
impl fmt::Display for ExternalName {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
ExternalName::User { namespace, index } => write!(f, "u{}:{}", namespace, index),
|
||||
ExternalName::TestCase { length, ascii } => {
|
||||
Self::User { namespace, index } => write!(f, "u{}:{}", namespace, index),
|
||||
Self::TestCase { length, ascii } => {
|
||||
f.write_char('%')?;
|
||||
for byte in ascii.iter().take(length as usize) {
|
||||
f.write_char(*byte as char)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
ExternalName::LibCall(lc) => write!(f, "%{}", lc),
|
||||
Self::LibCall(lc) => write!(f, "%{}", lc),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,7 +110,7 @@ impl FromStr for ExternalName {
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
// Try to parse as a libcall name, otherwise it's a test case.
|
||||
match s.parse() {
|
||||
Ok(lc) => Ok(ExternalName::LibCall(lc)),
|
||||
Ok(lc) => Ok(Self::LibCall(lc)),
|
||||
Err(_) => Ok(Self::testcase(s.as_bytes())),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ impl GlobalValueData {
|
||||
/// Assume that `self` is an `GlobalValueData::Symbol` and return its name.
|
||||
pub fn symbol_name(&self) -> &ExternalName {
|
||||
match *self {
|
||||
GlobalValueData::Symbol { ref name, .. } => name,
|
||||
Self::Symbol { ref name, .. } => name,
|
||||
_ => panic!("only symbols have names"),
|
||||
}
|
||||
}
|
||||
@@ -78,11 +78,8 @@ impl GlobalValueData {
|
||||
/// Return the type of this global.
|
||||
pub fn global_type(&self, isa: &dyn TargetIsa) -> Type {
|
||||
match *self {
|
||||
GlobalValueData::VMContext { .. } | GlobalValueData::Symbol { .. } => {
|
||||
isa.pointer_type()
|
||||
}
|
||||
GlobalValueData::IAddImm { global_type, .. }
|
||||
| GlobalValueData::Load { global_type, .. } => global_type,
|
||||
Self::VMContext { .. } | Self::Symbol { .. } => isa.pointer_type(),
|
||||
Self::IAddImm { global_type, .. } | Self::Load { global_type, .. } => global_type,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,8 +87,8 @@ impl GlobalValueData {
|
||||
impl fmt::Display for GlobalValueData {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
GlobalValueData::VMContext => write!(f, "vmctx"),
|
||||
GlobalValueData::Load {
|
||||
Self::VMContext => write!(f, "vmctx"),
|
||||
Self::Load {
|
||||
base,
|
||||
offset,
|
||||
global_type,
|
||||
@@ -104,12 +101,12 @@ impl fmt::Display for GlobalValueData {
|
||||
base,
|
||||
offset
|
||||
),
|
||||
GlobalValueData::IAddImm {
|
||||
Self::IAddImm {
|
||||
global_type,
|
||||
base,
|
||||
offset,
|
||||
} => write!(f, "iadd_imm.{} {}, {}", global_type, base, offset),
|
||||
GlobalValueData::Symbol {
|
||||
Self::Symbol {
|
||||
ref name,
|
||||
offset,
|
||||
colocated,
|
||||
|
||||
@@ -50,12 +50,12 @@ pub struct Imm64(i64);
|
||||
impl Imm64 {
|
||||
/// Create a new `Imm64` representing the signed number `x`.
|
||||
pub fn new(x: i64) -> Self {
|
||||
Imm64(x)
|
||||
Self(x)
|
||||
}
|
||||
|
||||
/// Return self negated.
|
||||
pub fn wrapping_neg(self) -> Self {
|
||||
Imm64(self.0.wrapping_neg())
|
||||
Self(self.0.wrapping_neg())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ impl IntoBytes for Imm64 {
|
||||
|
||||
impl From<i64> for Imm64 {
|
||||
fn from(x: i64) -> Self {
|
||||
Imm64(x)
|
||||
Self(x)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,12 +130,12 @@ pub struct Uimm64(u64);
|
||||
impl Uimm64 {
|
||||
/// Create a new `Uimm64` representing the unsigned number `x`.
|
||||
pub fn new(x: u64) -> Self {
|
||||
Uimm64(x)
|
||||
Self(x)
|
||||
}
|
||||
|
||||
/// Return self negated.
|
||||
pub fn wrapping_neg(self) -> Self {
|
||||
Uimm64(self.0.wrapping_neg())
|
||||
Self(self.0.wrapping_neg())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ impl Into<u64> for Uimm64 {
|
||||
|
||||
impl From<u64> for Uimm64 {
|
||||
fn from(x: u64) -> Self {
|
||||
Uimm64(x)
|
||||
Self(x)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,7 +272,7 @@ impl Into<i64> for Uimm32 {
|
||||
|
||||
impl From<u32> for Uimm32 {
|
||||
fn from(x: u32) -> Self {
|
||||
Uimm32(x)
|
||||
Self(x)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ impl FromStr for Uimm32 {
|
||||
fn from_str(s: &str) -> Result<Self, &'static str> {
|
||||
parse_i64(s).and_then(|x| {
|
||||
if 0 <= x && x <= i64::from(u32::MAX) {
|
||||
Ok(Uimm32(x as u32))
|
||||
Ok(Self(x as u32))
|
||||
} else {
|
||||
Err("Uimm32 out of range")
|
||||
}
|
||||
@@ -329,7 +329,7 @@ impl From<&[u8]> for V128Imm {
|
||||
assert_eq!(slice.len(), 16);
|
||||
let mut buffer = [0; 16];
|
||||
buffer.copy_from_slice(slice);
|
||||
V128Imm(buffer)
|
||||
Self(buffer)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,7 +343,7 @@ pub struct Offset32(i32);
|
||||
impl Offset32 {
|
||||
/// Create a new `Offset32` representing the signed number `x`.
|
||||
pub fn new(x: i32) -> Self {
|
||||
Offset32(x)
|
||||
Self(x)
|
||||
}
|
||||
|
||||
/// Create a new `Offset32` representing the signed number `x` if possible.
|
||||
@@ -381,7 +381,7 @@ impl Into<i64> for Offset32 {
|
||||
|
||||
impl From<i32> for Offset32 {
|
||||
fn from(x: i32) -> Self {
|
||||
Offset32(x)
|
||||
Self(x)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -676,7 +676,7 @@ fn parse_float(s: &str, w: u8, t: u8) -> Result<u64, &'static str> {
|
||||
impl Ieee32 {
|
||||
/// Create a new `Ieee32` containing the bits of `x`.
|
||||
pub fn with_bits(x: u32) -> Self {
|
||||
Ieee32(x)
|
||||
Self(x)
|
||||
}
|
||||
|
||||
/// Create an `Ieee32` number representing `2.0^n`.
|
||||
@@ -688,7 +688,7 @@ impl Ieee32 {
|
||||
let exponent = (n + bias) as u32;
|
||||
assert!(exponent > 0, "Underflow n={}", n);
|
||||
assert!(exponent < (1 << w) + 1, "Overflow n={}", n);
|
||||
Ieee32(exponent << t)
|
||||
Self(exponent << t)
|
||||
}
|
||||
|
||||
/// Create an `Ieee32` number representing the greatest negative value
|
||||
@@ -702,12 +702,12 @@ impl Ieee32 {
|
||||
|
||||
/// Return self negated.
|
||||
pub fn neg(self) -> Self {
|
||||
Ieee32(self.0 ^ (1 << 31))
|
||||
Self(self.0 ^ (1 << 31))
|
||||
}
|
||||
|
||||
/// Create a new `Ieee32` representing the number `x`.
|
||||
pub fn with_float(x: f32) -> Self {
|
||||
Ieee32(x.to_bits())
|
||||
Self(x.to_bits())
|
||||
}
|
||||
|
||||
/// Get the bitwise representation.
|
||||
@@ -728,7 +728,7 @@ impl FromStr for Ieee32 {
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, &'static str> {
|
||||
match parse_float(s, 8, 23) {
|
||||
Ok(b) => Ok(Ieee32(b as u32)),
|
||||
Ok(b) => Ok(Self(b as u32)),
|
||||
Err(s) => Err(s),
|
||||
}
|
||||
}
|
||||
@@ -736,7 +736,7 @@ impl FromStr for Ieee32 {
|
||||
|
||||
impl From<f32> for Ieee32 {
|
||||
fn from(x: f32) -> Self {
|
||||
Ieee32::with_float(x)
|
||||
Self::with_float(x)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -749,7 +749,7 @@ impl IntoBytes for Ieee32 {
|
||||
impl Ieee64 {
|
||||
/// Create a new `Ieee64` containing the bits of `x`.
|
||||
pub fn with_bits(x: u64) -> Self {
|
||||
Ieee64(x)
|
||||
Self(x)
|
||||
}
|
||||
|
||||
/// Create an `Ieee64` number representing `2.0^n`.
|
||||
@@ -761,7 +761,7 @@ impl Ieee64 {
|
||||
let exponent = (n + bias) as u64;
|
||||
assert!(exponent > 0, "Underflow n={}", n);
|
||||
assert!(exponent < (1 << w) + 1, "Overflow n={}", n);
|
||||
Ieee64(exponent << t)
|
||||
Self(exponent << t)
|
||||
}
|
||||
|
||||
/// Create an `Ieee64` number representing the greatest negative value
|
||||
@@ -775,12 +775,12 @@ impl Ieee64 {
|
||||
|
||||
/// Return self negated.
|
||||
pub fn neg(self) -> Self {
|
||||
Ieee64(self.0 ^ (1 << 63))
|
||||
Self(self.0 ^ (1 << 63))
|
||||
}
|
||||
|
||||
/// Create a new `Ieee64` representing the number `x`.
|
||||
pub fn with_float(x: f64) -> Self {
|
||||
Ieee64(x.to_bits())
|
||||
Self(x.to_bits())
|
||||
}
|
||||
|
||||
/// Get the bitwise representation.
|
||||
@@ -801,7 +801,7 @@ impl FromStr for Ieee64 {
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, &'static str> {
|
||||
match parse_float(s, 11, 52) {
|
||||
Ok(b) => Ok(Ieee64(b)),
|
||||
Ok(b) => Ok(Self(b)),
|
||||
Err(s) => Err(s),
|
||||
}
|
||||
}
|
||||
@@ -809,13 +809,13 @@ impl FromStr for Ieee64 {
|
||||
|
||||
impl From<f64> for Ieee64 {
|
||||
fn from(x: f64) -> Self {
|
||||
Ieee64::with_float(x)
|
||||
Self::with_float(x)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u64> for Ieee64 {
|
||||
fn from(x: u64) -> Self {
|
||||
Ieee64::with_float(f64::from_bits(x))
|
||||
Self::with_float(f64::from_bits(x))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ pub struct VariableArgs(Vec<Value>);
|
||||
impl VariableArgs {
|
||||
/// Create an empty argument list.
|
||||
pub fn new() -> Self {
|
||||
VariableArgs(Vec::new())
|
||||
Self(Vec::new())
|
||||
}
|
||||
|
||||
/// Add an argument to the end.
|
||||
@@ -168,35 +168,35 @@ impl InstructionData {
|
||||
/// here.
|
||||
pub fn analyze_branch<'a>(&'a self, pool: &'a ValueListPool) -> BranchInfo<'a> {
|
||||
match *self {
|
||||
InstructionData::Jump {
|
||||
Self::Jump {
|
||||
destination,
|
||||
ref args,
|
||||
..
|
||||
} => BranchInfo::SingleDest(destination, args.as_slice(pool)),
|
||||
InstructionData::BranchInt {
|
||||
Self::BranchInt {
|
||||
destination,
|
||||
ref args,
|
||||
..
|
||||
}
|
||||
| InstructionData::BranchFloat {
|
||||
| Self::BranchFloat {
|
||||
destination,
|
||||
ref args,
|
||||
..
|
||||
}
|
||||
| InstructionData::Branch {
|
||||
| Self::Branch {
|
||||
destination,
|
||||
ref args,
|
||||
..
|
||||
} => BranchInfo::SingleDest(destination, &args.as_slice(pool)[1..]),
|
||||
InstructionData::BranchIcmp {
|
||||
Self::BranchIcmp {
|
||||
destination,
|
||||
ref args,
|
||||
..
|
||||
} => BranchInfo::SingleDest(destination, &args.as_slice(pool)[2..]),
|
||||
InstructionData::BranchTable {
|
||||
Self::BranchTable {
|
||||
table, destination, ..
|
||||
} => BranchInfo::Table(table, Some(destination)),
|
||||
InstructionData::IndirectJump { table, .. } => BranchInfo::Table(table, None),
|
||||
Self::IndirectJump { table, .. } => BranchInfo::Table(table, None),
|
||||
_ => {
|
||||
debug_assert!(!self.opcode().is_branch());
|
||||
BranchInfo::NotABranch
|
||||
@@ -210,12 +210,12 @@ impl InstructionData {
|
||||
/// Multi-destination branches like `br_table` return `None`.
|
||||
pub fn branch_destination(&self) -> Option<Ebb> {
|
||||
match *self {
|
||||
InstructionData::Jump { destination, .. }
|
||||
| InstructionData::Branch { destination, .. }
|
||||
| InstructionData::BranchInt { destination, .. }
|
||||
| InstructionData::BranchFloat { destination, .. }
|
||||
| InstructionData::BranchIcmp { destination, .. } => Some(destination),
|
||||
InstructionData::BranchTable { .. } | InstructionData::IndirectJump { .. } => None,
|
||||
Self::Jump { destination, .. }
|
||||
| Self::Branch { destination, .. }
|
||||
| Self::BranchInt { destination, .. }
|
||||
| Self::BranchFloat { destination, .. }
|
||||
| Self::BranchIcmp { destination, .. } => Some(destination),
|
||||
Self::BranchTable { .. } | Self::IndirectJump { .. } => None,
|
||||
_ => {
|
||||
debug_assert!(!self.opcode().is_branch());
|
||||
None
|
||||
@@ -229,27 +229,27 @@ impl InstructionData {
|
||||
/// Multi-destination branches like `br_table` return `None`.
|
||||
pub fn branch_destination_mut(&mut self) -> Option<&mut Ebb> {
|
||||
match *self {
|
||||
InstructionData::Jump {
|
||||
Self::Jump {
|
||||
ref mut destination,
|
||||
..
|
||||
}
|
||||
| InstructionData::Branch {
|
||||
| Self::Branch {
|
||||
ref mut destination,
|
||||
..
|
||||
}
|
||||
| InstructionData::BranchInt {
|
||||
| Self::BranchInt {
|
||||
ref mut destination,
|
||||
..
|
||||
}
|
||||
| InstructionData::BranchFloat {
|
||||
| Self::BranchFloat {
|
||||
ref mut destination,
|
||||
..
|
||||
}
|
||||
| InstructionData::BranchIcmp {
|
||||
| Self::BranchIcmp {
|
||||
ref mut destination,
|
||||
..
|
||||
} => Some(destination),
|
||||
InstructionData::BranchTable { .. } => None,
|
||||
Self::BranchTable { .. } => None,
|
||||
_ => {
|
||||
debug_assert!(!self.opcode().is_branch());
|
||||
None
|
||||
@@ -262,10 +262,10 @@ impl InstructionData {
|
||||
/// Any instruction that can call another function reveals its call signature here.
|
||||
pub fn analyze_call<'a>(&'a self, pool: &'a ValueListPool) -> CallInfo<'a> {
|
||||
match *self {
|
||||
InstructionData::Call {
|
||||
Self::Call {
|
||||
func_ref, ref args, ..
|
||||
} => CallInfo::Direct(func_ref, args.as_slice(pool)),
|
||||
InstructionData::CallIndirect {
|
||||
Self::CallIndirect {
|
||||
sig_ref, ref args, ..
|
||||
} => CallInfo::Indirect(sig_ref, &args.as_slice(pool)[1..]),
|
||||
_ => {
|
||||
|
||||
@@ -59,18 +59,18 @@ impl FromStr for LibCall {
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"Probestack" => Ok(LibCall::Probestack),
|
||||
"CeilF32" => Ok(LibCall::CeilF32),
|
||||
"CeilF64" => Ok(LibCall::CeilF64),
|
||||
"FloorF32" => Ok(LibCall::FloorF32),
|
||||
"FloorF64" => Ok(LibCall::FloorF64),
|
||||
"TruncF32" => Ok(LibCall::TruncF32),
|
||||
"TruncF64" => Ok(LibCall::TruncF64),
|
||||
"NearestF32" => Ok(LibCall::NearestF32),
|
||||
"NearestF64" => Ok(LibCall::NearestF64),
|
||||
"Memcpy" => Ok(LibCall::Memcpy),
|
||||
"Memset" => Ok(LibCall::Memset),
|
||||
"Memmove" => Ok(LibCall::Memmove),
|
||||
"Probestack" => Ok(Self::Probestack),
|
||||
"CeilF32" => Ok(Self::CeilF32),
|
||||
"CeilF64" => Ok(Self::CeilF64),
|
||||
"FloorF32" => Ok(Self::FloorF32),
|
||||
"FloorF64" => Ok(Self::FloorF64),
|
||||
"TruncF32" => Ok(Self::TruncF32),
|
||||
"TruncF64" => Ok(Self::TruncF64),
|
||||
"NearestF32" => Ok(Self::NearestF32),
|
||||
"NearestF64" => Ok(Self::NearestF64),
|
||||
"Memcpy" => Ok(Self::Memcpy),
|
||||
"Memset" => Ok(Self::Memset),
|
||||
"Memmove" => Ok(Self::Memmove),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
@@ -84,17 +84,17 @@ impl LibCall {
|
||||
pub fn for_inst(opcode: Opcode, ctrl_type: Type) -> Option<Self> {
|
||||
Some(match ctrl_type {
|
||||
types::F32 => match opcode {
|
||||
Opcode::Ceil => LibCall::CeilF32,
|
||||
Opcode::Floor => LibCall::FloorF32,
|
||||
Opcode::Trunc => LibCall::TruncF32,
|
||||
Opcode::Nearest => LibCall::NearestF32,
|
||||
Opcode::Ceil => Self::CeilF32,
|
||||
Opcode::Floor => Self::FloorF32,
|
||||
Opcode::Trunc => Self::TruncF32,
|
||||
Opcode::Nearest => Self::NearestF32,
|
||||
_ => return None,
|
||||
},
|
||||
types::F64 => match opcode {
|
||||
Opcode::Ceil => LibCall::CeilF64,
|
||||
Opcode::Floor => LibCall::FloorF64,
|
||||
Opcode::Trunc => LibCall::TruncF64,
|
||||
Opcode::Nearest => LibCall::NearestF64,
|
||||
Opcode::Ceil => Self::CeilF64,
|
||||
Opcode::Floor => Self::FloorF64,
|
||||
Opcode::Trunc => Self::TruncF64,
|
||||
Opcode::Nearest => Self::NearestF64,
|
||||
_ => return None,
|
||||
},
|
||||
_ => return None,
|
||||
|
||||
@@ -20,7 +20,7 @@ impl From<Inst> for ProgramPoint {
|
||||
fn from(inst: Inst) -> Self {
|
||||
let idx = inst.index();
|
||||
debug_assert!(idx < (u32::MAX / 2) as usize);
|
||||
ProgramPoint((idx * 2) as u32)
|
||||
Self((idx * 2) as u32)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ impl From<Ebb> for ProgramPoint {
|
||||
fn from(ebb: Ebb) -> Self {
|
||||
let idx = ebb.index();
|
||||
debug_assert!(idx < (u32::MAX / 2) as usize);
|
||||
ProgramPoint((idx * 2 + 1) as u32)
|
||||
Self((idx * 2 + 1) as u32)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,21 +55,21 @@ impl ExpandedProgramPoint {
|
||||
/// Get the instruction we know is inside.
|
||||
pub fn unwrap_inst(self) -> Inst {
|
||||
match self {
|
||||
ExpandedProgramPoint::Inst(x) => x,
|
||||
ExpandedProgramPoint::Ebb(x) => panic!("expected inst: {}", x),
|
||||
Self::Inst(x) => x,
|
||||
Self::Ebb(x) => panic!("expected inst: {}", x),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Inst> for ExpandedProgramPoint {
|
||||
fn from(inst: Inst) -> Self {
|
||||
ExpandedProgramPoint::Inst(inst)
|
||||
Self::Inst(inst)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Ebb> for ExpandedProgramPoint {
|
||||
fn from(ebb: Ebb) -> Self {
|
||||
ExpandedProgramPoint::Ebb(ebb)
|
||||
Self::Ebb(ebb)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,9 +85,9 @@ impl From<ValueDef> for ExpandedProgramPoint {
|
||||
impl From<ProgramPoint> for ExpandedProgramPoint {
|
||||
fn from(pp: ProgramPoint) -> Self {
|
||||
if pp.0 & 1 == 0 {
|
||||
ExpandedProgramPoint::Inst(Inst::from_u32(pp.0 / 2))
|
||||
Self::Inst(Inst::from_u32(pp.0 / 2))
|
||||
} else {
|
||||
ExpandedProgramPoint::Ebb(Ebb::from_u32(pp.0 / 2))
|
||||
Self::Ebb(Ebb::from_u32(pp.0 / 2))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,8 +95,8 @@ impl From<ProgramPoint> for ExpandedProgramPoint {
|
||||
impl fmt::Display for ExpandedProgramPoint {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
ExpandedProgramPoint::Inst(x) => write!(f, "{}", x),
|
||||
ExpandedProgramPoint::Ebb(x) => write!(f, "{}", x),
|
||||
Self::Inst(x) => write!(f, "{}", x),
|
||||
Self::Ebb(x) => write!(f, "{}", x),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ pub struct SourceLoc(u32);
|
||||
impl SourceLoc {
|
||||
/// Create a new source location with the given bits.
|
||||
pub fn new(bits: u32) -> Self {
|
||||
SourceLoc(bits)
|
||||
Self(bits)
|
||||
}
|
||||
|
||||
/// Is this the default source location?
|
||||
@@ -37,7 +37,7 @@ impl SourceLoc {
|
||||
|
||||
impl Default for SourceLoc {
|
||||
fn default() -> Self {
|
||||
SourceLoc(!0)
|
||||
Self(!0)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ impl Type {
|
||||
/// Get a type with the same number of lanes as `self`, but using `lane` as the lane type.
|
||||
fn replace_lanes(self, lane: Self) -> Self {
|
||||
debug_assert!(lane.is_lane() && !self.is_special());
|
||||
Type((lane.0 & 0x0f) | (self.0 & 0xf0))
|
||||
Self((lane.0 & 0x0f) | (self.0 & 0xf0))
|
||||
}
|
||||
|
||||
/// Get a type with the same number of lanes as this type, but with the lanes replaced by
|
||||
@@ -262,7 +262,7 @@ impl Type {
|
||||
let log2_lanes: u32 = n.trailing_zeros();
|
||||
let new_type = u32::from(self.0) + (log2_lanes << 4);
|
||||
if new_type < 0x100 {
|
||||
Some(Type(new_type as u8))
|
||||
Some(Self(new_type as u8))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -273,7 +273,7 @@ impl Type {
|
||||
/// There is no `double_vector()` method. Use `t.by(2)` instead.
|
||||
pub fn half_vector(self) -> Option<Self> {
|
||||
if self.is_vector() {
|
||||
Some(Type(self.0 - 0x10))
|
||||
Some(Self(self.0 - 0x10))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ pub enum ValueLoc {
|
||||
|
||||
impl Default for ValueLoc {
|
||||
fn default() -> Self {
|
||||
ValueLoc::Unassigned
|
||||
Self::Unassigned
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ impl ValueLoc {
|
||||
/// Is this an assigned location? (That is, not `Unassigned`).
|
||||
pub fn is_assigned(self) -> bool {
|
||||
match self {
|
||||
ValueLoc::Unassigned => false,
|
||||
Self::Unassigned => false,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ impl ValueLoc {
|
||||
/// Get the register unit of this location, or panic.
|
||||
pub fn unwrap_reg(self) -> RegUnit {
|
||||
match self {
|
||||
ValueLoc::Reg(ru) => ru,
|
||||
Self::Reg(ru) => ru,
|
||||
_ => panic!("Expected register: {:?}", self),
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ impl ValueLoc {
|
||||
/// Get the stack slot of this location, or panic.
|
||||
pub fn unwrap_stack(self) -> StackSlot {
|
||||
match self {
|
||||
ValueLoc::Stack(ss) => ss,
|
||||
Self::Stack(ss) => ss,
|
||||
_ => panic!("Expected stack slot: {:?}", self),
|
||||
}
|
||||
}
|
||||
@@ -109,7 +109,7 @@ pub enum ArgumentLoc {
|
||||
|
||||
impl Default for ArgumentLoc {
|
||||
fn default() -> Self {
|
||||
ArgumentLoc::Unassigned
|
||||
Self::Unassigned
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ impl ArgumentLoc {
|
||||
/// Is this an assigned location? (That is, not `Unassigned`).
|
||||
pub fn is_assigned(self) -> bool {
|
||||
match self {
|
||||
ArgumentLoc::Unassigned => false,
|
||||
Self::Unassigned => false,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
@@ -125,7 +125,7 @@ impl ArgumentLoc {
|
||||
/// Is this a register location?
|
||||
pub fn is_reg(self) -> bool {
|
||||
match self {
|
||||
ArgumentLoc::Reg(_) => true,
|
||||
Self::Reg(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@@ -133,7 +133,7 @@ impl ArgumentLoc {
|
||||
/// Is this a stack location?
|
||||
pub fn is_stack(self) -> bool {
|
||||
match self {
|
||||
ArgumentLoc::Stack(_) => true,
|
||||
Self::Stack(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ impl CallConv {
|
||||
match triple.default_calling_convention() {
|
||||
// Default to System V for unknown targets because most everything
|
||||
// uses System V.
|
||||
Ok(CallingConvention::SystemV) | Err(()) => CallConv::SystemV,
|
||||
Ok(CallingConvention::WindowsFastcall) => CallConv::WindowsFastcall,
|
||||
Ok(CallingConvention::SystemV) | Err(()) => Self::SystemV,
|
||||
Ok(CallingConvention::WindowsFastcall) => Self::WindowsFastcall,
|
||||
Ok(unimp) => unimplemented!("calling convention: {:?}", unimp),
|
||||
}
|
||||
}
|
||||
@@ -39,28 +39,28 @@ impl CallConv {
|
||||
pub fn for_libcall(isa: &dyn TargetIsa) -> Self {
|
||||
match isa.flags().libcall_call_conv() {
|
||||
LibcallCallConv::IsaDefault => isa.default_call_conv(),
|
||||
LibcallCallConv::Fast => CallConv::Fast,
|
||||
LibcallCallConv::Cold => CallConv::Cold,
|
||||
LibcallCallConv::SystemV => CallConv::SystemV,
|
||||
LibcallCallConv::WindowsFastcall => CallConv::WindowsFastcall,
|
||||
LibcallCallConv::BaldrdashSystemV => CallConv::BaldrdashSystemV,
|
||||
LibcallCallConv::BaldrdashWindows => CallConv::BaldrdashWindows,
|
||||
LibcallCallConv::Probestack => CallConv::Probestack,
|
||||
LibcallCallConv::Fast => Self::Fast,
|
||||
LibcallCallConv::Cold => Self::Cold,
|
||||
LibcallCallConv::SystemV => Self::SystemV,
|
||||
LibcallCallConv::WindowsFastcall => Self::WindowsFastcall,
|
||||
LibcallCallConv::BaldrdashSystemV => Self::BaldrdashSystemV,
|
||||
LibcallCallConv::BaldrdashWindows => Self::BaldrdashWindows,
|
||||
LibcallCallConv::Probestack => Self::Probestack,
|
||||
}
|
||||
}
|
||||
|
||||
/// Is the calling convention extending the Windows Fastcall ABI?
|
||||
pub fn extends_windows_fastcall(&self) -> bool {
|
||||
pub fn extends_windows_fastcall(self) -> bool {
|
||||
match self {
|
||||
CallConv::WindowsFastcall | CallConv::BaldrdashWindows => true,
|
||||
Self::WindowsFastcall | Self::BaldrdashWindows => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Is the calling convention extending the Baldrdash ABI?
|
||||
pub fn extends_baldrdash(&self) -> bool {
|
||||
pub fn extends_baldrdash(self) -> bool {
|
||||
match self {
|
||||
CallConv::BaldrdashSystemV | CallConv::BaldrdashWindows => true,
|
||||
Self::BaldrdashSystemV | Self::BaldrdashWindows => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@@ -69,13 +69,13 @@ impl CallConv {
|
||||
impl fmt::Display for CallConv {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.write_str(match *self {
|
||||
CallConv::Fast => "fast",
|
||||
CallConv::Cold => "cold",
|
||||
CallConv::SystemV => "system_v",
|
||||
CallConv::WindowsFastcall => "windows_fastcall",
|
||||
CallConv::BaldrdashSystemV => "baldrdash_system_v",
|
||||
CallConv::BaldrdashWindows => "baldrdash_windows",
|
||||
CallConv::Probestack => "probestack",
|
||||
Self::Fast => "fast",
|
||||
Self::Cold => "cold",
|
||||
Self::SystemV => "system_v",
|
||||
Self::WindowsFastcall => "windows_fastcall",
|
||||
Self::BaldrdashSystemV => "baldrdash_system_v",
|
||||
Self::BaldrdashWindows => "baldrdash_windows",
|
||||
Self::Probestack => "probestack",
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -84,13 +84,13 @@ impl str::FromStr for CallConv {
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"fast" => Ok(CallConv::Fast),
|
||||
"cold" => Ok(CallConv::Cold),
|
||||
"system_v" => Ok(CallConv::SystemV),
|
||||
"windows_fastcall" => Ok(CallConv::WindowsFastcall),
|
||||
"baldrdash_system_v" => Ok(CallConv::BaldrdashSystemV),
|
||||
"baldrdash_windows" => Ok(CallConv::BaldrdashWindows),
|
||||
"probestack" => Ok(CallConv::Probestack),
|
||||
"fast" => Ok(Self::Fast),
|
||||
"cold" => Ok(Self::Cold),
|
||||
"system_v" => Ok(Self::SystemV),
|
||||
"windows_fastcall" => Ok(Self::WindowsFastcall),
|
||||
"baldrdash_system_v" => Ok(Self::BaldrdashSystemV),
|
||||
"baldrdash_windows" => Ok(Self::BaldrdashWindows),
|
||||
"probestack" => Ok(Self::Probestack),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ pub struct RegClassIndex(u8);
|
||||
|
||||
impl EntityRef for RegClassIndex {
|
||||
fn new(idx: usize) -> Self {
|
||||
RegClassIndex(idx as u8)
|
||||
Self(idx as u8)
|
||||
}
|
||||
|
||||
fn index(self) -> usize {
|
||||
@@ -247,7 +247,7 @@ impl EntityRef for RegClassIndex {
|
||||
|
||||
impl From<RegClass> for RegClassIndex {
|
||||
fn from(rc: RegClass) -> Self {
|
||||
RegClassIndex(rc.index)
|
||||
Self(rc.index)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -389,14 +389,17 @@ fn expand_br_table_conds(
|
||||
let mut pos = FuncCursor::new(func).at_inst(inst);
|
||||
pos.use_srcloc(inst);
|
||||
|
||||
// Ignore the lint for this loop as the range needs to be 0 to table_size
|
||||
#[allow(clippy::needless_range_loop)]
|
||||
for i in 0..table_size {
|
||||
let dest = pos.func.jump_tables[table].as_slice()[i];
|
||||
let t = pos.ins().icmp_imm(IntCC::Equal, arg, i as i64);
|
||||
pos.ins().brnz(t, dest, &[]);
|
||||
// Jump to the next case.
|
||||
if i < table_size - 1 {
|
||||
pos.ins().jump(cond_failed_ebb[i], &[]);
|
||||
pos.insert_ebb(cond_failed_ebb[i]);
|
||||
let ebb = cond_failed_ebb[i];
|
||||
pos.ins().jump(ebb, &[]);
|
||||
pos.insert_ebb(ebb);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -699,7 +702,7 @@ fn narrow_icmp_imm(
|
||||
|
||||
let imm_low = pos
|
||||
.ins()
|
||||
.iconst(ty_half, imm & (1u128 << ty_half.bits() - 1) as i64);
|
||||
.iconst(ty_half, imm & (1u128 << (ty_half.bits() - 1)) as i64);
|
||||
let imm_high = pos
|
||||
.ins()
|
||||
.iconst(ty_half, imm.wrapping_shr(ty_half.bits().into()));
|
||||
|
||||
@@ -18,13 +18,12 @@
|
||||
clippy::assign_op_pattern,
|
||||
clippy::empty_line_after_outer_attr,
|
||||
// Hard to avoid in generated code:
|
||||
clippy::cyclomatic_complexity,
|
||||
clippy::cognitive_complexity,
|
||||
clippy::too_many_arguments,
|
||||
// Code generator doesn't have a way to collapse identical arms:
|
||||
clippy::match_same_arms,
|
||||
// These are relatively minor style issues, but would be easy to fix:
|
||||
clippy::new_without_default,
|
||||
clippy::new_without_default_derive,
|
||||
clippy::should_implement_trait,
|
||||
clippy::len_without_is_empty))]
|
||||
#![cfg_attr(
|
||||
@@ -35,7 +34,6 @@
|
||||
clippy::nonminimal_bool,
|
||||
clippy::option_map_unwrap_or,
|
||||
clippy::option_map_unwrap_or_else,
|
||||
clippy::print_allocout,
|
||||
clippy::unicode_not_nfc,
|
||||
clippy::use_self
|
||||
)
|
||||
|
||||
@@ -71,7 +71,7 @@ fn create_pre_header(
|
||||
domtree: &DominatorTree,
|
||||
) -> Ebb {
|
||||
let pool = &mut ListPool::<Value>::new();
|
||||
let header_args_values: Vec<Value> = func.dfg.ebb_params(header).into_iter().cloned().collect();
|
||||
let header_args_values = func.dfg.ebb_params(header).to_vec();
|
||||
let header_args_types: Vec<Type> = header_args_values
|
||||
.clone()
|
||||
.into_iter()
|
||||
|
||||
@@ -348,7 +348,7 @@ impl RedundantReloadRemover {
|
||||
impl AvailEnv {
|
||||
// Create a new one.
|
||||
fn new(size: usize) -> Self {
|
||||
let mut env = AvailEnv {
|
||||
let mut env = Self {
|
||||
map: Vec::<Option<SlotInfo>>::new(),
|
||||
};
|
||||
env.map.resize(size, None);
|
||||
@@ -494,9 +494,9 @@ impl RedundantReloadRemover {
|
||||
debug_assert!(!self.processing_stack.is_empty());
|
||||
let ProcessingStackElem {
|
||||
avail_env,
|
||||
cursor: _,
|
||||
diversions,
|
||||
} = &mut self.processing_stack.last_mut().unwrap();
|
||||
..
|
||||
} = self.processing_stack.last_mut().unwrap();
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
debug_assert!(
|
||||
@@ -588,12 +588,7 @@ impl RedundantReloadRemover {
|
||||
invalidate_regs_written_by_inst(locations, diversions, dfg, avail_env, inst);
|
||||
}
|
||||
}
|
||||
InstructionData::RegMove {
|
||||
opcode: _,
|
||||
arg: _,
|
||||
src,
|
||||
dst,
|
||||
} => {
|
||||
InstructionData::RegMove { src, dst, .. } => {
|
||||
// These happen relatively rarely, but just frequently enough that it's worth
|
||||
// tracking the copy (at the machine level, it's really a copy) in `avail_env`.
|
||||
avail_env.copy_reg(*src, *dst);
|
||||
@@ -817,9 +812,9 @@ impl RedundantReloadRemover {
|
||||
for i in 0..num_ebbs {
|
||||
let mut pi = cfg.pred_iter(Ebb::from_u32(i));
|
||||
let mut n_pi = ZeroOneOrMany::Zero;
|
||||
if let Some(_) = pi.next() {
|
||||
if pi.next().is_some() {
|
||||
n_pi = ZeroOneOrMany::One;
|
||||
if let Some(_) = pi.next() {
|
||||
if pi.next().is_some() {
|
||||
n_pi = ZeroOneOrMany::Many;
|
||||
// We don't care if there are more than two preds, so stop counting now.
|
||||
}
|
||||
@@ -886,7 +881,7 @@ impl RedundantReloadRemover {
|
||||
let ctx = Context {
|
||||
cur: EncCursor::new(func, isa),
|
||||
reginfo: isa.register_info(),
|
||||
cfg: cfg,
|
||||
cfg,
|
||||
state: self,
|
||||
};
|
||||
let mut total_regunits = 0;
|
||||
|
||||
@@ -30,7 +30,7 @@ pub enum Affinity {
|
||||
|
||||
impl Default for Affinity {
|
||||
fn default() -> Self {
|
||||
Affinity::Unassigned
|
||||
Self::Unassigned
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,25 +41,25 @@ impl Affinity {
|
||||
/// Use the `Default` implementation for that.
|
||||
pub fn new(constraint: &OperandConstraint) -> Self {
|
||||
if constraint.kind == ConstraintKind::Stack {
|
||||
Affinity::Stack
|
||||
Self::Stack
|
||||
} else {
|
||||
Affinity::Reg(constraint.regclass.into())
|
||||
Self::Reg(constraint.regclass.into())
|
||||
}
|
||||
}
|
||||
|
||||
/// Create an affinity that matches an ABI argument for `isa`.
|
||||
pub fn abi(arg: &AbiParam, isa: &dyn TargetIsa) -> Self {
|
||||
match arg.location {
|
||||
ArgumentLoc::Unassigned => Affinity::Unassigned,
|
||||
ArgumentLoc::Reg(_) => Affinity::Reg(isa.regclass_for_abi_type(arg.value_type).into()),
|
||||
ArgumentLoc::Stack(_) => Affinity::Stack,
|
||||
ArgumentLoc::Unassigned => Self::Unassigned,
|
||||
ArgumentLoc::Reg(_) => Self::Reg(isa.regclass_for_abi_type(arg.value_type).into()),
|
||||
ArgumentLoc::Stack(_) => Self::Stack,
|
||||
}
|
||||
}
|
||||
|
||||
/// Is this the `Unassigned` affinity?
|
||||
pub fn is_unassigned(self) -> bool {
|
||||
match self {
|
||||
Affinity::Unassigned => true,
|
||||
Self::Unassigned => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ impl Affinity {
|
||||
/// Is this the `Reg` affinity?
|
||||
pub fn is_reg(self) -> bool {
|
||||
match self {
|
||||
Affinity::Reg(_) => true,
|
||||
Self::Reg(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,7 @@ impl Affinity {
|
||||
/// Is this the `Stack` affinity?
|
||||
pub fn is_stack(self) -> bool {
|
||||
match self {
|
||||
Affinity::Stack => true,
|
||||
Self::Stack => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@@ -86,8 +86,8 @@ impl Affinity {
|
||||
/// satisfies the constraint.
|
||||
pub fn merge(&mut self, constraint: &OperandConstraint, reginfo: &RegInfo) {
|
||||
match *self {
|
||||
Affinity::Unassigned => *self = Self::new(constraint),
|
||||
Affinity::Reg(rc) => {
|
||||
Self::Unassigned => *self = Self::new(constraint),
|
||||
Self::Reg(rc) => {
|
||||
// If the preferred register class is a subclass of the constraint, there's no need
|
||||
// to change anything.
|
||||
if constraint.kind != ConstraintKind::Stack && !constraint.regclass.has_subclass(rc)
|
||||
@@ -96,11 +96,11 @@ impl Affinity {
|
||||
// we just keep our previous affinity.
|
||||
if let Some(subclass) = constraint.regclass.intersect_index(reginfo.rc(rc)) {
|
||||
// This constraint shrinks our preferred register class.
|
||||
*self = Affinity::Reg(subclass);
|
||||
*self = Self::Reg(subclass);
|
||||
}
|
||||
}
|
||||
}
|
||||
Affinity::Stack => {}
|
||||
Self::Stack => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ impl<'a> Context<'a> {
|
||||
let dfg = &mut self.cur.func.dfg;
|
||||
let old_args: Vec<_> = {
|
||||
let args = dfg[branch].take_value_list().expect("ebb parameters");
|
||||
args.as_slice(&dfg.value_lists).iter().map(|x| *x).collect()
|
||||
args.as_slice(&dfg.value_lists).iter().copied().collect()
|
||||
};
|
||||
let (branch_args, ebb_params) = old_args.split_at(num_fixed);
|
||||
|
||||
@@ -159,16 +159,13 @@ impl<'a> Context<'a> {
|
||||
/// Returns whether we should introduce a new branch.
|
||||
fn should_split_edge(&self, target: Ebb) -> bool {
|
||||
// We should split the edge if the target has any parameters.
|
||||
if self.cur.func.dfg.ebb_params(target).len() > 0 {
|
||||
if !self.cur.func.dfg.ebb_params(target).is_empty() {
|
||||
return true;
|
||||
};
|
||||
|
||||
// Or, if the target has more than one block reaching it.
|
||||
debug_assert!(self.cfg.pred_iter(target).next() != None);
|
||||
if let Some(_) = self.cfg.pred_iter(target).skip(1).next() {
|
||||
return true;
|
||||
};
|
||||
|
||||
false
|
||||
self.cfg.pred_iter(target).nth(1).is_some()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -551,7 +551,7 @@ impl<'a> Context<'a> {
|
||||
let is_reload = match &self.cur.func.dfg[inst] {
|
||||
InstructionData::Unary {
|
||||
opcode: Opcode::Fill,
|
||||
arg: _,
|
||||
..
|
||||
} => true,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
@@ -200,7 +200,7 @@ impl RegDiversions {
|
||||
}
|
||||
debug_assert!(!entry_diversions.map.contains_key(target));
|
||||
let iter = self.current.iter();
|
||||
let mut entry_divert = RegDiversions::new();
|
||||
let mut entry_divert = Self::new();
|
||||
entry_divert.current.extend(iter);
|
||||
entry_diversions.map.insert(EntryRegDiversionsValue {
|
||||
key: target,
|
||||
@@ -225,7 +225,7 @@ impl RegDiversions {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
true
|
||||
}
|
||||
|
||||
/// Return an object that can display the diversions.
|
||||
@@ -237,7 +237,7 @@ impl RegDiversions {
|
||||
impl EntryRegDiversions {
|
||||
/// Create a new empty entry diversion, to associate diversions to each EBB entry.
|
||||
pub fn new() -> Self {
|
||||
EntryRegDiversions {
|
||||
Self {
|
||||
map: SparseMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,9 +259,9 @@ impl UFEntry {
|
||||
/// Decode a table entry.
|
||||
fn decode(x: i32) -> Self {
|
||||
if x < 0 {
|
||||
UFEntry::Link(Value::from_u32((!x) as u32))
|
||||
Self::Link(Value::from_u32((!x) as u32))
|
||||
} else {
|
||||
UFEntry::Rank(x as u32)
|
||||
Self::Rank(x as u32)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,6 @@ pub type CodegenResult<T> = Result<T, CodegenError>;
|
||||
|
||||
impl From<VerifierErrors> for CodegenError {
|
||||
fn from(e: VerifierErrors) -> Self {
|
||||
CodegenError::Verifier(e)
|
||||
Self::Verifier(e)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,7 +324,7 @@ pub mod detail {
|
||||
/// offset field has a different meaning when the detail is a preset.
|
||||
pub fn is_preset(self) -> bool {
|
||||
match self {
|
||||
Detail::Preset => true,
|
||||
Self::Preset => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -597,15 +597,14 @@ fn simplify(pos: &mut FuncCursor, inst: Inst, native_word_width: u32) {
|
||||
}
|
||||
}
|
||||
|
||||
InstructionData::Unary { opcode, arg } => match opcode {
|
||||
Opcode::AdjustSpDown => {
|
||||
InstructionData::Unary { opcode, arg } => {
|
||||
if let Opcode::AdjustSpDown = opcode {
|
||||
if let Some(imm) = resolve_imm64_value(&pos.func.dfg, arg) {
|
||||
// Note this works for both positive and negative immediate values.
|
||||
pos.func.dfg.replace(inst).adjust_sp_down_imm(imm);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
}
|
||||
|
||||
InstructionData::BinaryImm { opcode, arg, imm } => {
|
||||
let ty = pos.func.dfg.ctrl_typevar(inst);
|
||||
@@ -626,27 +625,25 @@ fn simplify(pos: &mut FuncCursor, inst: Inst, native_word_width: u32) {
|
||||
imm: prev_imm,
|
||||
} = &pos.func.dfg[arg_inst]
|
||||
{
|
||||
if opcode == *prev_opcode {
|
||||
if ty == pos.func.dfg.ctrl_typevar(arg_inst) {
|
||||
let lhs: i64 = imm.into();
|
||||
let rhs: i64 = (*prev_imm).into();
|
||||
let new_imm = match opcode {
|
||||
Opcode::BorImm => lhs | rhs,
|
||||
Opcode::BandImm => lhs & rhs,
|
||||
Opcode::BxorImm => lhs ^ rhs,
|
||||
Opcode::IaddImm => lhs.wrapping_add(rhs),
|
||||
Opcode::ImulImm => lhs.wrapping_mul(rhs),
|
||||
_ => panic!("can't happen"),
|
||||
};
|
||||
let new_imm = immediates::Imm64::from(new_imm);
|
||||
let new_arg = *prev_arg;
|
||||
pos.func
|
||||
.dfg
|
||||
.replace(inst)
|
||||
.BinaryImm(opcode, ty, new_imm, new_arg);
|
||||
imm = new_imm;
|
||||
arg = new_arg;
|
||||
}
|
||||
if opcode == *prev_opcode && ty == pos.func.dfg.ctrl_typevar(arg_inst) {
|
||||
let lhs: i64 = imm.into();
|
||||
let rhs: i64 = (*prev_imm).into();
|
||||
let new_imm = match opcode {
|
||||
Opcode::BorImm => lhs | rhs,
|
||||
Opcode::BandImm => lhs & rhs,
|
||||
Opcode::BxorImm => lhs ^ rhs,
|
||||
Opcode::IaddImm => lhs.wrapping_add(rhs),
|
||||
Opcode::ImulImm => lhs.wrapping_mul(rhs),
|
||||
_ => panic!("can't happen"),
|
||||
};
|
||||
let new_imm = immediates::Imm64::from(new_imm);
|
||||
let new_arg = *prev_arg;
|
||||
pos.func
|
||||
.dfg
|
||||
.replace(inst)
|
||||
.BinaryImm(opcode, ty, new_imm, new_arg);
|
||||
imm = new_imm;
|
||||
arg = new_arg;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -679,17 +676,14 @@ fn simplify(pos: &mut FuncCursor, inst: Inst, native_word_width: u32) {
|
||||
| (Opcode::SshrImm, 0) => {
|
||||
// Alias the result value with the original argument.
|
||||
replace_single_result_with_alias(&mut pos.func.dfg, inst, arg);
|
||||
return;
|
||||
}
|
||||
(Opcode::ImulImm, 0) | (Opcode::BandImm, 0) => {
|
||||
// Replace by zero.
|
||||
pos.func.dfg.replace(inst).iconst(ty, 0);
|
||||
return;
|
||||
}
|
||||
(Opcode::BorImm, -1) => {
|
||||
// Replace by minus one.
|
||||
pos.func.dfg.replace(inst).iconst(ty, -1);
|
||||
return;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -789,9 +783,9 @@ fn branch_opt(pos: &mut FuncCursor, inst: Inst) {
|
||||
|
||||
BranchOptInfo {
|
||||
br_inst: inst,
|
||||
cmp_arg: cmp_arg,
|
||||
cmp_arg,
|
||||
args: br_args.clone(),
|
||||
new_opcode: new_opcode,
|
||||
new_opcode,
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
|
||||
@@ -141,7 +141,7 @@ mod details {
|
||||
|
||||
impl Default for PassTimes {
|
||||
fn default() -> Self {
|
||||
PassTimes {
|
||||
Self {
|
||||
pass: [Default::default(); NUM_PASSES],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,14 +104,14 @@ where
|
||||
if range.0 >= range.1 || !loc.is_assigned() {
|
||||
return;
|
||||
}
|
||||
if !ranges.contains_key(&label) {
|
||||
ranges.insert(label, Vec::new());
|
||||
}
|
||||
ranges.get_mut(&label).unwrap().push(ValueLocRange {
|
||||
loc,
|
||||
start: range.0,
|
||||
end: range.1,
|
||||
});
|
||||
ranges
|
||||
.entry(label)
|
||||
.or_insert_with(Vec::new)
|
||||
.push(ValueLocRange {
|
||||
loc,
|
||||
start: range.0,
|
||||
end: range.1,
|
||||
});
|
||||
};
|
||||
|
||||
let mut end_offset = 0;
|
||||
@@ -130,7 +130,7 @@ where
|
||||
add_range(*label, (*start_offset, end_offset), *last_loc);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
true
|
||||
});
|
||||
|
||||
let srcloc = func.srclocs[inst];
|
||||
@@ -152,7 +152,7 @@ where
|
||||
}
|
||||
|
||||
// New source locations range started: abandon all tracked values.
|
||||
if last_srcloc.is_some() && last_srcloc.as_ref().unwrap() > &srcloc {
|
||||
if last_srcloc.is_some() && last_srcloc.unwrap() > srcloc {
|
||||
for (_, label, start_offset, last_loc) in &tracked_values {
|
||||
add_range(*label, (*start_offset, end_offset), *last_loc);
|
||||
}
|
||||
@@ -193,7 +193,7 @@ where
|
||||
|
||||
// Optimize ranges in-place
|
||||
for (_, label_ranges) in ranges.iter_mut() {
|
||||
assert!(label_ranges.len() > 0);
|
||||
assert!(!label_ranges.is_empty());
|
||||
label_ranges.sort_by(|a, b| a.start.cmp(&b.start).then_with(|| a.end.cmp(&b.end)));
|
||||
|
||||
// Merge ranges
|
||||
@@ -245,7 +245,7 @@ pub struct ComparableSourceLoc(SourceLoc);
|
||||
|
||||
impl From<SourceLoc> for ComparableSourceLoc {
|
||||
fn from(s: SourceLoc) -> Self {
|
||||
ComparableSourceLoc(s)
|
||||
Self(s)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -167,7 +167,7 @@ impl VerifierErrors {
|
||||
/// Return a new `VerifierErrors` struct.
|
||||
#[inline]
|
||||
pub fn new() -> Self {
|
||||
VerifierErrors(Vec::new())
|
||||
Self(Vec::new())
|
||||
}
|
||||
|
||||
/// Return whether no errors were reported.
|
||||
@@ -196,7 +196,7 @@ impl VerifierErrors {
|
||||
|
||||
impl From<Vec<VerifierError>> for VerifierErrors {
|
||||
fn from(v: Vec<VerifierError>) -> Self {
|
||||
VerifierErrors(v)
|
||||
Self(v)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -268,9 +268,9 @@ pub fn write_ebb_header(
|
||||
writeln!(w, "):")
|
||||
}
|
||||
|
||||
fn write_valueloc(w: &mut dyn Write, loc: &ValueLoc, regs: &RegInfo) -> fmt::Result {
|
||||
fn write_valueloc(w: &mut dyn Write, loc: ValueLoc, regs: &RegInfo) -> fmt::Result {
|
||||
match loc {
|
||||
ValueLoc::Reg(r) => write!(w, "{}", regs.display_regunit(*r)),
|
||||
ValueLoc::Reg(r) => write!(w, "{}", regs.display_regunit(r)),
|
||||
ValueLoc::Stack(ss) => write!(w, "{}", ss),
|
||||
ValueLoc::Unassigned => write!(w, "?"),
|
||||
}
|
||||
@@ -289,7 +289,7 @@ fn write_value_range_markers(
|
||||
for i in (0..rng.len()).rev() {
|
||||
if rng[i].start == offset {
|
||||
write!(&mut result, " {}@", val)?;
|
||||
write_valueloc(&mut result, &rng[i].loc, regs)?;
|
||||
write_valueloc(&mut result, rng[i].loc, regs)?;
|
||||
shown.insert(val);
|
||||
break;
|
||||
}
|
||||
@@ -303,7 +303,7 @@ fn write_value_range_markers(
|
||||
}
|
||||
}
|
||||
}
|
||||
if result.len() > 0 {
|
||||
if !result.is_empty() {
|
||||
writeln!(w, ";{1:0$}; {2}", indent + 24, "", result)?;
|
||||
}
|
||||
Ok(())
|
||||
@@ -330,21 +330,24 @@ fn decorate_ebb<FW: FuncWriter>(
|
||||
write_value_aliases(w, aliases, a, indent)?;
|
||||
}
|
||||
|
||||
if isa.is_some() && !func.offsets.is_empty() {
|
||||
let encinfo = isa.unwrap().encoding_info();
|
||||
let regs = &isa.unwrap().register_info();
|
||||
for (offset, inst, size) in func.inst_offsets(ebb, &encinfo) {
|
||||
func_w.write_instruction(w, func, aliases, isa, inst, indent)?;
|
||||
if size > 0 {
|
||||
if let Some(val_ranges) = annotations.value_ranges {
|
||||
write_value_range_markers(w, val_ranges, regs, offset + size, indent)?;
|
||||
if let Some(isa) = isa {
|
||||
if !func.offsets.is_empty() {
|
||||
let encinfo = isa.encoding_info();
|
||||
let regs = &isa.register_info();
|
||||
for (offset, inst, size) in func.inst_offsets(ebb, &encinfo) {
|
||||
func_w.write_instruction(w, func, aliases, Some(isa), inst, indent)?;
|
||||
if size > 0 {
|
||||
if let Some(val_ranges) = annotations.value_ranges {
|
||||
write_value_range_markers(w, val_ranges, regs, offset + size, indent)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
} else {
|
||||
for inst in func.layout.ebb_insts(ebb) {
|
||||
func_w.write_instruction(w, func, aliases, isa, inst, indent)?;
|
||||
}
|
||||
}
|
||||
|
||||
for inst in func.layout.ebb_insts(ebb) {
|
||||
func_w.write_instruction(w, func, aliases, isa, inst, indent)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user