Fix clippy warnings.

This commit fixes the current set of (stable) clippy warnings in the repo.
This commit is contained in:
Peter Huene
2019-10-23 23:15:42 -07:00
committed by Andrew Brown
parent 1176e4f178
commit 9f506692c2
93 changed files with 667 additions and 662 deletions

View File

@@ -168,10 +168,12 @@ pub(crate) enum Literal {
impl Literal {
pub fn enumerator_for(kind: &OperandKind, value: &'static str) -> Self {
let value = match &kind.fields {
OperandKindFields::ImmEnum(values) => values.get(value).expect(&format!(
"nonexistent value '{}' in enumeration '{}'",
value, kind.name
)),
OperandKindFields::ImmEnum(values) => values.get(value).unwrap_or_else(|| {
panic!(
"nonexistent value '{}' in enumeration '{}'",
value, kind.name
)
}),
_ => panic!("enumerator is for enum values"),
};
Literal::Enumerator {

View File

@@ -53,7 +53,7 @@ impl CpuMode {
Some(typ) => self
.typed_legalize
.get(typ)
.map(|x| *x)
.copied()
.unwrap_or_else(|| self.get_default_legalize_code()),
None => self
.monomorphic_legalize

View File

@@ -61,8 +61,8 @@ impl InstructionGroup {
pub fn by_name(&self, name: &'static str) -> &Instruction {
self.instructions
.iter()
.find(|inst| &inst.name == name)
.expect(&format!("unexisting instruction with name {}", name))
.find(|inst| inst.name == name)
.unwrap_or_else(|| panic!("unexisting instruction with name {}", name))
}
}
@@ -167,7 +167,7 @@ impl Bindable for Instruction {
impl fmt::Display for InstructionContent {
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
if self.operands_out.len() > 0 {
if !self.operands_out.is_empty() {
let operands_out = self
.operands_out
.iter()
@@ -180,7 +180,7 @@ impl fmt::Display for InstructionContent {
fmt.write_str(&self.name)?;
if self.operands_in.len() > 0 {
if !self.operands_in.is_empty() {
let operands_in = self
.operands_in
.iter()
@@ -244,53 +244,70 @@ impl InstructionBuilder {
self.operands_in = Some(operands.iter().map(|x| (*x).clone()).collect());
self
}
pub fn operands_out(mut self, operands: Vec<&Operand>) -> Self {
assert!(self.operands_out.is_none());
self.operands_out = Some(operands.iter().map(|x| (*x).clone()).collect());
self
}
pub fn constraints(mut self, constraints: Vec<Constraint>) -> Self {
assert!(self.constraints.is_none());
self.constraints = Some(constraints);
self
}
#[allow(clippy::wrong_self_convention)]
pub fn is_terminator(mut self, val: bool) -> Self {
self.is_terminator = val;
self
}
#[allow(clippy::wrong_self_convention)]
pub fn is_branch(mut self, val: bool) -> Self {
self.is_branch = val;
self
}
#[allow(clippy::wrong_self_convention)]
pub fn is_indirect_branch(mut self, val: bool) -> Self {
self.is_indirect_branch = val;
self
}
#[allow(clippy::wrong_self_convention)]
pub fn is_call(mut self, val: bool) -> Self {
self.is_call = val;
self
}
#[allow(clippy::wrong_self_convention)]
pub fn is_return(mut self, val: bool) -> Self {
self.is_return = val;
self
}
#[allow(clippy::wrong_self_convention)]
pub fn is_ghost(mut self, val: bool) -> Self {
self.is_ghost = val;
self
}
pub fn can_load(mut self, val: bool) -> Self {
self.can_load = val;
self
}
pub fn can_store(mut self, val: bool) -> Self {
self.can_store = val;
self
}
pub fn can_trap(mut self, val: bool) -> Self {
self.can_trap = val;
self
}
pub fn other_side_effects(mut self, val: bool) -> Self {
self.other_side_effects = val;
self
@@ -534,7 +551,7 @@ impl Bindable for BoundInstruction {
}
/// Checks that the input operands actually match the given format.
fn verify_format(inst_name: &str, operands_in: &Vec<Operand>, format: &InstructionFormat) {
fn verify_format(inst_name: &str, operands_in: &[Operand], format: &InstructionFormat) {
// A format is defined by:
// - its number of input value operands,
// - its number and names of input immediate operands,
@@ -586,10 +603,10 @@ fn verify_format(inst_name: &str, operands_in: &Vec<Operand>, format: &Instructi
/// Check if this instruction is polymorphic, and verify its use of type variables.
fn verify_polymorphic(
operands_in: &Vec<Operand>,
operands_out: &Vec<Operand>,
operands_in: &[Operand],
operands_out: &[Operand],
format: &InstructionFormat,
value_opnums: &Vec<usize>,
value_opnums: &[usize],
) -> Option<PolymorphicInfo> {
// The instruction is polymorphic if it has one free input or output operand.
let is_polymorphic = operands_in
@@ -633,7 +650,7 @@ fn verify_polymorphic(
// If we reached here, it means the type variable indicated as the typevar operand couldn't
// control every other input and output type variable. We need to look at the result type
// variables.
if operands_out.len() == 0 {
if operands_out.is_empty() {
// No result means no other possible type variable, so it's a type inference failure.
match maybe_error_message {
Some(msg) => panic!(msg),
@@ -670,8 +687,8 @@ fn verify_polymorphic(
/// Return a vector of other type variables used, or a string explaining what went wrong.
fn is_ctrl_typevar_candidate(
ctrl_typevar: &TypeVar,
operands_in: &Vec<Operand>,
operands_out: &Vec<Operand>,
operands_in: &[Operand],
operands_out: &[Operand],
) -> Result<Vec<TypeVar>, String> {
let mut other_typevars = Vec::new();
@@ -995,8 +1012,7 @@ impl InstructionPredicate {
.value_opnums
.iter()
.enumerate()
.filter(|(_, &op_num)| inst.operands_in[op_num].type_var().unwrap() == type_var)
.next()
.find(|(_, &op_num)| inst.operands_in[op_num].type_var().unwrap() == type_var)
.unwrap()
.0;
InstructionPredicateNode::TypePredicate(TypePredicateNode::TypeVarCheck(

View File

@@ -42,7 +42,7 @@ impl Stack {
pub fn new(regclass: RegClassIndex) -> Self {
Self { regclass }
}
pub fn stack_base_mask(&self) -> &'static str {
pub fn stack_base_mask(self) -> &'static str {
// TODO: Make this configurable instead of just using the SP.
"StackBaseMask(1)"
}
@@ -253,8 +253,8 @@ impl EncodingRecipeBuilder {
}
pub fn build(self) -> EncodingRecipe {
let operands_in = self.operands_in.unwrap_or(Vec::new());
let operands_out = self.operands_out.unwrap_or(Vec::new());
let operands_in = self.operands_in.unwrap_or_default();
let operands_out = self.operands_out.unwrap_or_default();
// The number of input constraints must match the number of format input operands.
if !self.format.has_value_list {
@@ -282,7 +282,7 @@ impl EncodingRecipeBuilder {
let clobbers_flags = self.clobbers_flags.unwrap_or(true);
EncodingRecipe {
name: self.name.into(),
name: self.name,
format: self.format,
base_size: self.base_size,
operands_in,

View File

@@ -164,7 +164,7 @@ impl RegClassBuilder {
name,
width: 0,
count: stop - start,
start: start,
start,
proto: RegClassProto::SubClass(parent_index),
}
}
@@ -214,7 +214,7 @@ impl RegBankBuilder {
self
}
pub fn pinned_reg(mut self, unit: u16) -> Self {
assert!(unit < (self.units as u16));
assert!(unit < u16::from(self.units));
self.pinned_reg = Some(unit);
self
}
@@ -234,7 +234,7 @@ impl IsaRegsBuilder {
}
pub fn add_bank(&mut self, builder: RegBankBuilder) -> RegBankIndex {
let first_unit = if self.banks.len() == 0 {
let first_unit = if self.banks.is_empty() {
0
} else {
let last = &self.banks.last().unwrap();
@@ -358,8 +358,7 @@ impl IsaRegsBuilder {
.unwrap()
.subclasses
.iter()
.find(|x| **x == *i2)
.is_some());
.any(|x| *x == *i2));
}
}
}
@@ -402,7 +401,7 @@ impl IsaRegs {
self.classes
.values()
.find(|&class| class.name == name)
.expect(&format!("register class {} not found", name))
.unwrap_or_else(|| panic!("register class {} not found", name))
.index
}

View File

@@ -268,7 +268,7 @@ impl SettingGroupBuilder {
default: bool,
) -> BoolSettingIndex {
assert!(
self.predicates.len() == 0,
self.predicates.is_empty(),
"predicates must be added after the boolean settings"
);
self.add_setting(name, comment, ProtoSpecificSetting::Bool(default));
@@ -379,7 +379,7 @@ impl SettingGroupBuilder {
}
assert!(
group.predicates.len() == 0,
group.predicates.is_empty(),
"settings_size is the byte size before adding predicates"
);
group.settings_size = group.byte_size();
@@ -393,11 +393,11 @@ impl SettingGroupBuilder {
.extend(predicates.into_iter().map(|predicate| {
let number = predicate_number;
predicate_number += 1;
return Predicate {
Predicate {
name: predicate.name,
node: predicate.node,
number,
};
}
}));
group.presets.extend(self.presets);

View File

@@ -74,7 +74,7 @@ impl Constraint {
}
// Trivially false.
if (&ts1.lanes & &ts2.lanes).len() == 0 {
if (&ts1.lanes & &ts2.lanes).is_empty() {
return true;
}
@@ -155,12 +155,7 @@ impl TypeEnvironment {
}
fn add_constraint(&mut self, constraint: Constraint) {
if self
.constraints
.iter()
.find(|&item| item == &constraint)
.is_some()
{
if self.constraints.iter().any(|item| *item == constraint) {
return;
}
@@ -257,7 +252,7 @@ impl TypeEnvironment {
.map(|tv| self.get_equivalent(tv).free_typevar())
.filter(|opt_tv| {
// Filter out singleton types.
return opt_tv.is_some();
opt_tv.is_some()
})
.map(|tv| tv.unwrap()),
);
@@ -306,7 +301,7 @@ impl TypeEnvironment {
children
.entry(parent_tv)
.or_insert(HashSet::new())
.or_insert_with(HashSet::new)
.insert(type_var.clone());
}
@@ -314,7 +309,7 @@ impl TypeEnvironment {
for (equivalent_tv, canon_tv) in self.equivalency_map.iter() {
children
.entry(canon_tv.clone())
.or_insert(HashSet::new())
.or_insert_with(HashSet::new)
.insert(equivalent_tv.clone());
}
@@ -604,7 +599,7 @@ fn infer_definition(
/// Perform type inference on an transformation. Return an updated type environment or error.
pub(crate) fn infer_transform(
src: DefIndex,
dst: &Vec<DefIndex>,
dst: &[DefIndex],
def_pool: &DefPool,
var_pool: &mut VarPool,
) -> Result<TypeEnvironment, String> {

View File

@@ -6,7 +6,7 @@ use crate::shared::types as shared_types;
use cranelift_codegen_shared::constants;
// Rust name prefix used for the `rust_name` method.
static _RUST_NAME_PREFIX: &'static str = "ir::types::";
static _RUST_NAME_PREFIX: &str = "ir::types::";
// ValueType variants (i8, i32, ...) are provided in `shared::types.rs`.
@@ -242,29 +242,29 @@ impl LaneType {
})
}
pub fn by(&self, lanes: u16) -> ValueType {
pub fn by(self, lanes: u16) -> ValueType {
if lanes == 1 {
(*self).into()
self.into()
} else {
ValueType::Vector(VectorType::new(*self, lanes.into()))
ValueType::Vector(VectorType::new(self, lanes.into()))
}
}
pub fn is_float(&self) -> bool {
pub fn is_float(self) -> bool {
match self {
LaneType::FloatType(_) => true,
_ => false,
}
}
pub fn is_int(&self) -> bool {
pub fn is_int(self) -> bool {
match self {
LaneType::IntType(_) => true,
_ => false,
}
}
pub fn is_bool(&self) -> bool {
pub fn is_bool(self) -> bool {
match self {
LaneType::BoolType(_) => true,
_ => false,

View File

@@ -156,33 +156,33 @@ impl TypeVar {
let ts = self.get_typeset();
// Safety checks to avoid over/underflows.
assert!(ts.specials.len() == 0, "can't derive from special types");
assert!(ts.specials.is_empty(), "can't derive from special types");
match derived_func {
DerivedFunc::HalfWidth => {
assert!(
ts.ints.len() == 0 || *ts.ints.iter().min().unwrap() > 8,
ts.ints.is_empty() || *ts.ints.iter().min().unwrap() > 8,
"can't halve all integer types"
);
assert!(
ts.floats.len() == 0 || *ts.floats.iter().min().unwrap() > 32,
ts.floats.is_empty() || *ts.floats.iter().min().unwrap() > 32,
"can't halve all float types"
);
assert!(
ts.bools.len() == 0 || *ts.bools.iter().min().unwrap() > 8,
ts.bools.is_empty() || *ts.bools.iter().min().unwrap() > 8,
"can't halve all boolean types"
);
}
DerivedFunc::DoubleWidth => {
assert!(
ts.ints.len() == 0 || *ts.ints.iter().max().unwrap() < MAX_BITS,
ts.ints.is_empty() || *ts.ints.iter().max().unwrap() < MAX_BITS,
"can't double all integer types"
);
assert!(
ts.floats.len() == 0 || *ts.floats.iter().max().unwrap() < MAX_FLOAT_BITS,
ts.floats.is_empty() || *ts.floats.iter().max().unwrap() < MAX_FLOAT_BITS,
"can't double all float types"
);
assert!(
ts.bools.len() == 0 || *ts.bools.iter().max().unwrap() < MAX_BITS,
ts.bools.is_empty() || *ts.bools.iter().max().unwrap() < MAX_BITS,
"can't double all boolean types"
);
}
@@ -203,7 +203,7 @@ impl TypeVar {
}
}
return TypeVar {
TypeVar {
content: Rc::new(RefCell::new(TypeVarContent {
name: format!("{}({})", derived_func.name(), self.name),
doc: "".into(),
@@ -213,29 +213,29 @@ impl TypeVar {
derived_func,
}),
})),
};
}
}
pub fn lane_of(&self) -> TypeVar {
return self.derived(DerivedFunc::LaneOf);
self.derived(DerivedFunc::LaneOf)
}
pub fn as_bool(&self) -> TypeVar {
return self.derived(DerivedFunc::AsBool);
self.derived(DerivedFunc::AsBool)
}
pub fn half_width(&self) -> TypeVar {
return self.derived(DerivedFunc::HalfWidth);
self.derived(DerivedFunc::HalfWidth)
}
pub fn double_width(&self) -> TypeVar {
return self.derived(DerivedFunc::DoubleWidth);
self.derived(DerivedFunc::DoubleWidth)
}
pub fn half_vector(&self) -> TypeVar {
return self.derived(DerivedFunc::HalfVector);
self.derived(DerivedFunc::HalfVector)
}
pub fn double_vector(&self) -> TypeVar {
return self.derived(DerivedFunc::DoubleVector);
self.derived(DerivedFunc::DoubleVector)
}
pub fn to_bitvec(&self) -> TypeVar {
return self.derived(DerivedFunc::ToBitVec);
self.derived(DerivedFunc::ToBitVec)
}
/// Constrain the range of types this variable can assume to a subset of those in the typeset
@@ -347,7 +347,7 @@ pub enum DerivedFunc {
}
impl DerivedFunc {
pub fn name(&self) -> &'static str {
pub fn name(self) -> &'static str {
match self {
DerivedFunc::LaneOf => "lane_of",
DerivedFunc::AsBool => "as_bool",
@@ -360,7 +360,7 @@ impl DerivedFunc {
}
/// Returns the inverse function of this one, if it is a bijection.
pub fn inverse(&self) -> Option<DerivedFunc> {
pub fn inverse(self) -> Option<DerivedFunc> {
match self {
DerivedFunc::HalfWidth => Some(DerivedFunc::DoubleWidth),
DerivedFunc::DoubleWidth => Some(DerivedFunc::HalfWidth),
@@ -476,7 +476,7 @@ impl TypeSet {
copy.floats = NumSet::new();
copy.refs = NumSet::new();
copy.bitvecs = NumSet::new();
if (&self.lanes - &num_set![1]).len() > 0 {
if !(&self.lanes - &num_set![1]).is_empty() {
copy.bools = &self.ints | &self.floats;
copy.bools = &copy.bools | &self.bools;
}
@@ -512,7 +512,7 @@ impl TypeSet {
.iter()
.filter(|&&x| x < MAX_BITS)
.map(|&x| x * 2)
.filter(legal_bool),
.filter(|x| legal_bool(*x)),
);
copy.bitvecs = NumSet::from_iter(
self.bitvecs
@@ -600,7 +600,7 @@ impl TypeSet {
fn get_singleton(&self) -> ValueType {
let mut types = self.concrete_types();
assert_eq!(types.len(), 1);
return types.remove(0);
types.remove(0)
}
/// Return the inverse image of self across the derived function func.
@@ -615,7 +615,7 @@ impl TypeSet {
let mut copy = self.clone();
copy.bitvecs = NumSet::new();
copy.lanes =
NumSet::from_iter((0..MAX_LANES.trailing_zeros() + 1).map(|i| u16::pow(2, i)));
NumSet::from_iter((0..=MAX_LANES.trailing_zeros()).map(|i| u16::pow(2, i)));
copy
}
DerivedFunc::AsBool => {
@@ -724,11 +724,11 @@ impl TypeSet {
}
fn set_wider_or_equal(s1: &NumSet, s2: &NumSet) -> bool {
s1.len() > 0 && s2.len() > 0 && s1.iter().min() >= s2.iter().max()
!s1.is_empty() && !s2.is_empty() && s1.iter().min() >= s2.iter().max()
}
fn set_narrower(s1: &NumSet, s2: &NumSet) -> bool {
s1.len() > 0 && s2.len() > 0 && s1.iter().min() < s2.iter().max()
!s1.is_empty() && !s2.is_empty() && s1.iter().min() < s2.iter().max()
}
impl fmt::Debug for TypeSet {
@@ -854,7 +854,7 @@ impl TypeSetBuilder {
let bools = range_to_set(self.bools.to_range(1..MAX_BITS, None))
.into_iter()
.filter(legal_bool)
.filter(|x| legal_bool(*x))
.collect();
TypeSet::new(
@@ -921,9 +921,9 @@ impl Into<Interval> for Range {
}
}
fn legal_bool(bits: &RangeBound) -> bool {
fn legal_bool(bits: RangeBound) -> bool {
// Only allow legal bit widths for bool types.
*bits == 1 || (*bits >= 8 && *bits <= MAX_BITS && bits.is_power_of_two())
bits == 1 || (bits >= 8 && bits <= MAX_BITS && bits.is_power_of_two())
}
/// Generates a set with all the powers of two included in the range.
@@ -939,7 +939,7 @@ fn range_to_set(range: Option<Range>) -> NumSet {
assert!(high.is_power_of_two());
assert!(low <= high);
for i in low.trailing_zeros()..high.trailing_zeros() + 1 {
for i in low.trailing_zeros()..=high.trailing_zeros() {
assert!(1 << i <= RangeBound::max_value());
set.insert(1 << i);
}

View File

@@ -255,6 +255,7 @@ fn rewrite_expr(
Apply::new(apply_target, args)
}
#[allow(clippy::too_many_arguments)]
fn rewrite_def_list(
position: PatternPosition,
dummy_defs: Vec<DummyDef>,

View File

@@ -7,7 +7,7 @@ pub(crate) trait MapWithDefault<K, V: Default> {
impl<K: Eq + Hash, V: Default> MapWithDefault<K, V> for HashMap<K, V> {
fn get_or_default(&mut self, k: K) -> &mut V {
self.entry(k).or_insert_with(|| V::default())
self.entry(k).or_insert_with(V::default)
}
}

View File

@@ -34,7 +34,7 @@ fn gen_recipe(recipe: &EncodingRecipe, fmt: &mut Formatter) {
let is_regmove = ["RegMove", "RegSpill", "RegFill"].contains(&inst_format.name);
// Unpack the instruction data.
fmtln!(fmt, "if let &InstructionData::{} {{", inst_format.name);
fmtln!(fmt, "if let InstructionData::{} {{", inst_format.name);
fmt.indent(|fmt| {
fmt.line("opcode,");
for f in &inst_format.imm_fields {
@@ -49,7 +49,7 @@ fn gen_recipe(recipe: &EncodingRecipe, fmt: &mut Formatter) {
}
fmt.line("..");
fmt.outdented_line("} = inst_data {");
fmt.outdented_line("} = *inst_data {");
// Pass recipe arguments in this order: inputs, imm_fields, outputs.
let mut args = String::new();

View File

@@ -158,8 +158,8 @@ fn emit_recipe_predicates(isa: &TargetIsa, fmt: &mut Formatter) {
fmt,
"fn {}({}: crate::settings::PredicateView, {}: &ir::InstructionData) -> bool {{",
func_name,
if let Some(_) = isap { "isap" } else { "_" },
if let Some(_) = instp { "inst" } else { "_" }
if isap.is_some() { "isap" } else { "_" },
if instp.is_some() { "inst" } else { "_" }
);
fmt.indent(|fmt| {
match (isap, instp) {
@@ -263,13 +263,13 @@ fn emit_recipe_names(isa: &TargetIsa, fmt: &mut Formatter) {
}
/// Returns a set of all the registers involved in fixed register constraints.
fn get_fixed_registers(operands_in: &Vec<OperandConstraint>) -> HashSet<Register> {
fn get_fixed_registers(operands_in: &[OperandConstraint]) -> HashSet<Register> {
HashSet::from_iter(
operands_in
.iter()
.map(|constraint| {
if let OperandConstraint::FixedReg(reg) = &constraint {
Some(reg.clone())
Some(*reg)
} else {
None
}
@@ -286,13 +286,13 @@ fn get_fixed_registers(operands_in: &Vec<OperandConstraint>) -> HashSet<Register
fn emit_operand_constraints(
registers: &IsaRegs,
recipe: &EncodingRecipe,
constraints: &Vec<OperandConstraint>,
constraints: &[OperandConstraint],
field_name: &'static str,
tied_operands: &HashMap<usize, usize>,
fixed_registers: &HashSet<Register>,
fmt: &mut Formatter,
) {
if constraints.len() == 0 {
if constraints.is_empty() {
fmtln!(fmt, "{}: &[],", field_name);
return;
}

View File

@@ -17,7 +17,7 @@ use crate::unique_table::{UniqueSeqTable, UniqueTable};
const TYPESET_LIMIT: usize = 0xff;
/// Generate an instruction format enumeration.
fn gen_formats(formats: &Vec<&InstructionFormat>, fmt: &mut Formatter) {
fn gen_formats(formats: &[&InstructionFormat], fmt: &mut Formatter) {
fmt.doc_comment(
r#"
An instruction format
@@ -49,7 +49,7 @@ fn gen_formats(formats: &Vec<&InstructionFormat>, fmt: &mut Formatter) {
m.arm(
format!("InstructionData::{}", format.name),
vec![".."],
format!("InstructionFormat::{}", format.name),
format!("Self::{}", format.name),
);
}
fmt.add_match(m);
@@ -65,7 +65,7 @@ fn gen_formats(formats: &Vec<&InstructionFormat>, fmt: &mut Formatter) {
/// Every variant must contain an `opcode` field. The size of `InstructionData` should be kept at
/// 16 bytes on 64-bit architectures. If more space is needed to represent an instruction, use a
/// `ValueList` to store the additional information out of line.
fn gen_instruction_data(formats: &Vec<&InstructionFormat>, fmt: &mut Formatter) {
fn gen_instruction_data(formats: &[&InstructionFormat], fmt: &mut Formatter) {
fmt.line("#[derive(Clone, Debug)]");
fmt.line("#[allow(missing_docs)]");
fmt.line("pub enum InstructionData {");
@@ -93,7 +93,7 @@ fn gen_instruction_data(formats: &Vec<&InstructionFormat>, fmt: &mut Formatter)
fmt.line("}");
}
fn gen_arguments_method(formats: &Vec<&InstructionFormat>, fmt: &mut Formatter, is_mut: bool) {
fn gen_arguments_method(formats: &[&InstructionFormat], fmt: &mut Formatter, is_mut: bool) {
let (method, mut_, rslice, as_slice) = if is_mut {
(
"arguments_mut",
@@ -116,7 +116,7 @@ fn gen_arguments_method(formats: &Vec<&InstructionFormat>, fmt: &mut Formatter,
fmt.indent(|fmt| {
let mut m = Match::new("*self");
for format in formats {
let name = format!("InstructionData::{}", format.name);
let name = format!("Self::{}", format.name);
// Formats with a value list put all of their arguments in the list. We don't split
// them up, just return it all as variable arguments. (I expect the distinction to go
@@ -163,7 +163,7 @@ fn gen_arguments_method(formats: &Vec<&InstructionFormat>, fmt: &mut Formatter,
/// - `pub fn put_value_list(&mut self, args: ir::ValueList>`
/// - `pub fn eq(&self, &other: Self, &pool) -> bool`
/// - `pub fn hash<H: Hasher>(&self, state: &mut H, &pool)`
fn gen_instruction_data_impl(formats: &Vec<&InstructionFormat>, fmt: &mut Formatter) {
fn gen_instruction_data_impl(formats: &[&InstructionFormat], fmt: &mut Formatter) {
fmt.line("impl InstructionData {");
fmt.indent(|fmt| {
fmt.doc_comment("Get the opcode of this instruction.");
@@ -171,7 +171,7 @@ fn gen_instruction_data_impl(formats: &Vec<&InstructionFormat>, fmt: &mut Format
fmt.indent(|fmt| {
let mut m = Match::new("*self");
for format in formats {
m.arm(format!("InstructionData::{}", format.name), vec!["opcode", ".."],
m.arm(format!("Self::{}", format.name), vec!["opcode", ".."],
"opcode".to_string());
}
fmt.add_match(m);
@@ -184,7 +184,7 @@ fn gen_instruction_data_impl(formats: &Vec<&InstructionFormat>, fmt: &mut Format
fmt.indent(|fmt| {
let mut m = Match::new("*self");
for format in formats {
let name = format!("InstructionData::{}", format.name);
let name = format!("Self::{}", format.name);
if format.typevar_operand.is_none() {
m.arm(name, vec![".."], "None".to_string());
} else if format.has_value_list {
@@ -227,7 +227,7 @@ fn gen_instruction_data_impl(formats: &Vec<&InstructionFormat>, fmt: &mut Format
for format in formats {
if format.has_value_list {
m.arm(format!("InstructionData::{}", format.name),
m.arm(format!("Self::{}", format.name),
vec!["ref mut args", ".."],
"Some(args.take())".to_string());
}
@@ -254,7 +254,7 @@ fn gen_instruction_data_impl(formats: &Vec<&InstructionFormat>, fmt: &mut Format
fmt.indent(|fmt| {
for format in formats {
if format.has_value_list {
fmtln!(fmt, "InstructionData::{} {{ ref mut args, .. }} => args,", format.name);
fmtln!(fmt, "Self::{} {{ ref mut args, .. }} => args,", format.name);
}
}
fmt.line("_ => panic!(\"No value list: {:?}\", self),");
@@ -283,7 +283,7 @@ fn gen_instruction_data_impl(formats: &Vec<&InstructionFormat>, fmt: &mut Format
fmt.line("match (self, other) {");
fmt.indent(|fmt| {
for format in formats {
let name = format!("&InstructionData::{}", format.name);
let name = format!("&Self::{}", format.name);
let mut members = vec!["opcode"];
let args_eq = if format.typevar_operand.is_none() {
@@ -335,7 +335,7 @@ fn gen_instruction_data_impl(formats: &Vec<&InstructionFormat>, fmt: &mut Format
fmt.line("match *self {");
fmt.indent(|fmt| {
for format in formats {
let name = format!("InstructionData::{}", format.name);
let name = format!("Self::{}", format.name);
let mut members = vec!["opcode"];
let args = if format.typevar_operand.is_none() {
@@ -388,7 +388,7 @@ fn gen_bool_accessor<T: Fn(&Instruction) -> bool>(
let mut m = Match::new("self");
for inst in all_inst.values() {
if get_attr(inst) {
m.arm_no_fields(format!("Opcode::{}", inst.camel_name), "true");
m.arm_no_fields(format!("Self::{}", inst.camel_name), "true");
}
}
m.arm_no_fields("_", "false");
@@ -398,7 +398,7 @@ fn gen_bool_accessor<T: Fn(&Instruction) -> bool>(
fmt.empty_line();
}
fn gen_opcodes<'a>(all_inst: &AllInstructions, fmt: &mut Formatter) {
fn gen_opcodes(all_inst: &AllInstructions, fmt: &mut Formatter) {
fmt.doc_comment(
r#"
An instruction opcode.
@@ -613,7 +613,7 @@ fn get_constraint<'entries, 'table>(
}
assert!(type_var == ctrl_typevar.unwrap());
return "Same".into();
"Same".into()
}
fn gen_bitset<'a, T: IntoIterator<Item = &'a u16>>(
@@ -641,22 +641,22 @@ fn iterable_to_string<I: fmt::Display, T: IntoIterator<Item = I>>(iterable: T) -
fn typeset_to_string(ts: &TypeSet) -> String {
let mut result = format!("TypeSet(lanes={}", iterable_to_string(&ts.lanes));
if ts.ints.len() > 0 {
if !ts.ints.is_empty() {
result += &format!(", ints={}", iterable_to_string(&ts.ints));
}
if ts.floats.len() > 0 {
if !ts.floats.is_empty() {
result += &format!(", floats={}", iterable_to_string(&ts.floats));
}
if ts.bools.len() > 0 {
if !ts.bools.is_empty() {
result += &format!(", bools={}", iterable_to_string(&ts.bools));
}
if ts.bitvecs.len() > 0 {
if !ts.bitvecs.is_empty() {
result += &format!(", bitvecs={}", iterable_to_string(&ts.bitvecs));
}
if ts.specials.len() > 0 {
if !ts.specials.is_empty() {
result += &format!(", specials=[{}]", iterable_to_string(&ts.specials));
}
if ts.refs.len() > 0 {
if !ts.refs.is_empty() {
result += &format!(", refs={}", iterable_to_string(&ts.refs));
}
result += ")";
@@ -680,7 +680,7 @@ pub fn gen_typesets_table(type_sets: &UniqueTable<TypeSet>, fmt: &mut Formatter)
for ts in type_sets.iter() {
fmt.line("ir::instructions::ValueTypeSet {");
fmt.indent(|fmt| {
assert!(ts.bitvecs.len() == 0, "Bitvector types are not emittable.");
assert!(ts.bitvecs.is_empty(), "Bitvector types are not emittable.");
fmt.comment(typeset_to_string(ts));
gen_bitset(&ts.lanes, "lanes", 16, fmt);
gen_bitset(&ts.ints, "ints", 8, fmt);
@@ -710,6 +710,7 @@ fn gen_type_constraints(all_inst: &AllInstructions, fmt: &mut Formatter) {
let mut operand_seqs = UniqueSeqTable::new();
// Preload table with constraints for typical binops.
#[allow(clippy::useless_vec)]
operand_seqs.add(&vec!["Same".to_string(); 3]);
fmt.comment("Table of opcode constraints.");
@@ -926,7 +927,7 @@ fn gen_inst_builder(inst: &Instruction, format: &InstructionFormat, fmt: &mut Fo
_ => format!("({})", vec!["Value"; inst.value_results.len()].join(", ")),
};
let tmpl = if tmpl_types.len() > 0 {
let tmpl = if !tmpl_types.is_empty() {
format!("<{}>", tmpl_types.join(", "))
} else {
"".into()
@@ -1005,7 +1006,7 @@ fn gen_inst_builder(inst: &Instruction, format: &InstructionFormat, fmt: &mut Fo
// Call to the format constructor,
let fcall = format!("self.{}({})", format.name, args.join(", "));
if inst.value_results.len() == 0 {
if inst.value_results.is_empty() {
fmtln!(fmt, "{}.0", fcall);
return;
}
@@ -1037,7 +1038,7 @@ fn gen_inst_builder(inst: &Instruction, format: &InstructionFormat, fmt: &mut Fo
/// Generate a Builder trait with methods for all instructions.
fn gen_builder(
instructions: &AllInstructions,
formats: &Vec<&InstructionFormat>,
formats: &[&InstructionFormat],
fmt: &mut Formatter,
) {
fmt.doc_comment(

View File

@@ -187,7 +187,7 @@ fn unwrap_inst(transform: &Transform, fmt: &mut Formatter) -> bool {
// If the definition creates results, detach the values and place them in locals.
let mut replace_inst = false;
if def.defined_vars.len() > 0 {
if !def.defined_vars.is_empty() {
if def.defined_vars
== def_pool
.get(var_pool.get(def.defined_vars[0]).dst_def.unwrap())
@@ -266,7 +266,7 @@ fn build_derived_expr(tv: &TypeVar) -> String {
///
/// The emitted code is a statement redefining the `predicate` variable like this:
/// let predicate = predicate && ...
fn emit_runtime_typecheck<'a, 'b>(
fn emit_runtime_typecheck<'a>(
constraint: &'a Constraint,
type_sets: &mut UniqueTable<'a, TypeSet>,
fmt: &mut Formatter,
@@ -586,7 +586,7 @@ fn gen_transform_group<'a>(
let inst = &transform.def_pool.get(def_index).apply.inst;
inst_to_transforms
.entry(inst.camel_name.clone())
.or_insert(Vec::new())
.or_insert_with(Vec::new)
.push(transform);
}
@@ -606,7 +606,7 @@ fn gen_transform_group<'a>(
let replace_inst = unwrap_inst(&transforms[0], fmt);
fmt.empty_line();
for (i, transform) in transforms.into_iter().enumerate() {
for (i, transform) in transforms.iter().enumerate() {
if i > 0 {
fmt.empty_line();
}
@@ -697,7 +697,7 @@ fn gen_isa(
/// Generate the legalizer files.
pub(crate) fn generate(
isas: &Vec<TargetIsa>,
isas: &[TargetIsa],
transform_groups: &TransformGroups,
filename_prefix: &str,
out_dir: &str,

View File

@@ -5,7 +5,7 @@ use crate::srcgen::Formatter;
use cranelift_entity::EntityRef;
fn gen_regbank(fmt: &mut Formatter, reg_bank: &RegBank) {
let names = if reg_bank.names.len() > 0 {
let names = if !reg_bank.names.is_empty() {
format!(r#""{}""#, reg_bank.names.join(r#"", ""#))
} else {
"".to_string()

View File

@@ -81,7 +81,7 @@ fn gen_to_and_from_str(name: &str, values: &[&'static str], fmt: &mut Formatter)
fmtln!(fmt, "f.write_str(match *self {");
fmt.indent(|fmt| {
for v in values.iter() {
fmtln!(fmt, "{}::{} => \"{}\",", name, camel_case(v), v);
fmtln!(fmt, "Self::{} => \"{}\",", camel_case(v), v);
}
});
fmtln!(fmt, "})");
@@ -98,7 +98,7 @@ fn gen_to_and_from_str(name: &str, values: &[&'static str], fmt: &mut Formatter)
fmtln!(fmt, "match s {");
fmt.indent(|fmt| {
for v in values.iter() {
fmtln!(fmt, "\"{}\" => Ok({}::{}),", v, name, camel_case(v));
fmtln!(fmt, "\"{}\" => Ok(Self::{}),", v, camel_case(v));
}
fmtln!(fmt, "_ => Err(()),");
});
@@ -198,7 +198,7 @@ fn gen_getters(group: &SettingGroup, fmt: &mut Formatter) {
});
fmtln!(fmt, "}");
if group.settings.len() > 0 {
if !group.settings.is_empty() {
fmt.doc_comment("Dynamic numbered predicate getter.");
fmtln!(fmt, "fn numbered_predicate(&self, p: usize) -> bool {");
fmt.indent(|fmt| {

View File

@@ -22,8 +22,7 @@ impl Isa {
Isa::all()
.iter()
.cloned()
.filter(|isa| isa.to_string() == name)
.next()
.find(|isa| isa.to_string() == name)
}
/// Creates isa target from arch.
@@ -55,7 +54,7 @@ impl fmt::Display for Isa {
}
}
pub(crate) fn define(isas: &Vec<Isa>, shared_defs: &mut SharedDefinitions) -> Vec<TargetIsa> {
pub(crate) fn define(isas: &[Isa], shared_defs: &mut SharedDefinitions) -> Vec<TargetIsa> {
isas.iter()
.map(|isa| match isa {
Isa::Riscv => riscv::define(shared_defs),

View File

@@ -56,7 +56,7 @@ impl<'defs> PerCpuModeEncodings<'defs> {
fn load_bits(funct3: u16) -> u16 {
assert!(funct3 <= 0b111);
0b00000 | (funct3 << 5)
funct3 << 5
}
fn store_bits(funct3: u16) -> u16 {
@@ -91,13 +91,13 @@ fn opimm32_bits(funct3: u16, funct7: u16) -> u16 {
fn op_bits(funct3: u16, funct7: u16) -> u16 {
assert!(funct3 <= 0b111);
assert!(funct7 <= 0b1111111);
assert!(funct7 <= 0b111_1111);
0b01100 | (funct3 << 5) | (funct7 << 8)
}
fn op32_bits(funct3: u16, funct7: u16) -> u16 {
assert!(funct3 <= 0b111);
assert!(funct7 <= 0b1111111);
assert!(funct7 <= 0b111_1111);
0b01110 | (funct3 << 5) | (funct7 << 8)
}
@@ -177,11 +177,11 @@ pub(crate) fn define<'defs>(
// Basic arithmetic binary instructions are encoded in an R-type instruction.
for &(inst, inst_imm, f3, f7) in &[
(iadd, Some(iadd_imm), 0b000, 0b0000000),
(isub, None, 0b000, 0b0100000),
(bxor, Some(bxor_imm), 0b100, 0b0000000),
(bor, Some(bor_imm), 0b110, 0b0000000),
(band, Some(band_imm), 0b111, 0b0000000),
(iadd, Some(iadd_imm), 0b000, 0b000_0000),
(isub, None, 0b000, 0b010_0000),
(bxor, Some(bxor_imm), 0b100, 0b000_0000),
(bor, Some(bor_imm), 0b110, 0b000_0000),
(band, Some(band_imm), 0b111, 0b000_0000),
] {
e.add32(e.enc(inst.bind(I32), r_r, op_bits(f3, f7)));
e.add64(e.enc(inst.bind(I64), r_r, op_bits(f3, f7)));
@@ -194,8 +194,8 @@ pub(crate) fn define<'defs>(
}
// 32-bit ops in RV64.
e.add64(e.enc(iadd.bind(I32), r_r, op32_bits(0b000, 0b0000000)));
e.add64(e.enc(isub.bind(I32), r_r, op32_bits(0b000, 0b0100000)));
e.add64(e.enc(iadd.bind(I32), r_r, op32_bits(0b000, 0b000_0000)));
e.add64(e.enc(isub.bind(I32), r_r, op32_bits(0b000, 0b010_0000)));
// There are no andiw/oriw/xoriw variations.
e.add64(e.enc(iadd_imm.bind(I32), r_ii, opimm32_bits(0b000, 0)));
@@ -208,7 +208,7 @@ pub(crate) fn define<'defs>(
for &(inst, inst_imm, f3, f7) in &[
(ishl, ishl_imm, 0b1, 0b0),
(ushr, ushr_imm, 0b101, 0b0),
(sshr, sshr_imm, 0b101, 0b100000),
(sshr, sshr_imm, 0b101, 0b10_0000),
] {
e.add32(e.enc(inst.bind(I32).bind(I32), r_r, op_bits(f3, f7)));
e.add64(e.enc(inst.bind(I64).bind(I64), r_r, op_bits(f3, f7)));
@@ -246,20 +246,20 @@ pub(crate) fn define<'defs>(
let icmp_i32 = icmp.bind(I32);
let icmp_i64 = icmp.bind(I64);
e.add32(
e.enc(icmp_i32.clone(), r_ricmp, op_bits(0b010, 0b0000000))
e.enc(icmp_i32.clone(), r_ricmp, op_bits(0b010, 0b000_0000))
.inst_predicate(icmp_instp(&icmp_i32, "slt")),
);
e.add64(
e.enc(icmp_i64.clone(), r_ricmp, op_bits(0b010, 0b0000000))
e.enc(icmp_i64.clone(), r_ricmp, op_bits(0b010, 0b000_0000))
.inst_predicate(icmp_instp(&icmp_i64, "slt")),
);
e.add32(
e.enc(icmp_i32.clone(), r_ricmp, op_bits(0b011, 0b0000000))
e.enc(icmp_i32.clone(), r_ricmp, op_bits(0b011, 0b000_0000))
.inst_predicate(icmp_instp(&icmp_i32, "ult")),
);
e.add64(
e.enc(icmp_i64.clone(), r_ricmp, op_bits(0b011, 0b0000000))
e.enc(icmp_i64.clone(), r_ricmp, op_bits(0b011, 0b000_0000))
.inst_predicate(icmp_instp(&icmp_i64, "ult")),
);
@@ -293,15 +293,15 @@ pub(crate) fn define<'defs>(
// "M" Standard Extension for Integer Multiplication and Division.
// Gated by the `use_m` flag.
e.add32(
e.enc(imul.bind(I32), r_r, op_bits(0b000, 0b00000001))
e.enc(imul.bind(I32), r_r, op_bits(0b000, 0b0000_0001))
.isa_predicate(use_m),
);
e.add64(
e.enc(imul.bind(I64), r_r, op_bits(0b000, 0b00000001))
e.enc(imul.bind(I64), r_r, op_bits(0b000, 0b0000_0001))
.isa_predicate(use_m),
);
e.add64(
e.enc(imul.bind(I32), r_r, op32_bits(0b000, 0b00000001))
e.enc(imul.bind(I32), r_r, op32_bits(0b000, 0b0000_0001))
.isa_predicate(use_m),
);

View File

@@ -33,11 +33,10 @@ impl RecipeGroup {
}
pub fn by_name(&self, name: &str) -> EncodingRecipeNumber {
let number = *self
*self
.name_to_recipe
.get(name)
.expect(&format!("unknown riscv recipe name {}", name));
number
.unwrap_or_else(|| panic!("unknown riscv recipe name {}", name))
}
pub fn collect(self) -> Recipes {
@@ -97,7 +96,7 @@ pub(crate) fn define(shared_defs: &SharedDefinitions, regs: &IsaRegs) -> RecipeG
EncodingRecipeBuilder::new("Iz", &formats.unary_imm, 4)
.operands_out(vec![gpr])
.inst_predicate(InstructionPredicate::new_is_signed_int(
&*&formats.unary_imm,
&formats.unary_imm,
"imm",
12,
0,
@@ -111,7 +110,7 @@ pub(crate) fn define(shared_defs: &SharedDefinitions, regs: &IsaRegs) -> RecipeG
.operands_in(vec![gpr])
.operands_out(vec![gpr])
.inst_predicate(InstructionPredicate::new_is_signed_int(
&*&formats.int_compare_imm,
&formats.int_compare_imm,
"imm",
12,
0,
@@ -183,7 +182,7 @@ pub(crate) fn define(shared_defs: &SharedDefinitions, regs: &IsaRegs) -> RecipeG
EncodingRecipeBuilder::new("U", &formats.unary_imm, 4)
.operands_out(vec![gpr])
.inst_predicate(InstructionPredicate::new_is_signed_int(
&*&formats.unary_imm,
&formats.unary_imm,
"imm",
32,
12,

View File

@@ -70,7 +70,7 @@ impl PerCpuModeEncodings {
{
let (recipe, bits) = template.build();
let recipe_number = self.add_recipe(recipe);
let builder = EncodingBuilder::new(inst.into(), recipe_number, bits);
let builder = EncodingBuilder::new(inst, recipe_number, bits);
builder_closure(builder).build(&self.recipes, &mut self.inst_pred_reg)
}
@@ -367,6 +367,7 @@ impl PerCpuModeEncodings {
// Definitions.
#[allow(clippy::cognitive_complexity)]
pub(crate) fn define(
shared_defs: &SharedDefinitions,
settings: &SettingGroup,
@@ -1916,7 +1917,7 @@ pub(crate) fn define(
// SIMD integer addition
for (ty, opcodes) in &[(I8, &PADDB), (I16, &PADDW), (I32, &PADDD), (I64, &PADDQ)] {
let iadd = iadd.bind(vector(ty.clone(), sse_vector_size));
let iadd = iadd.bind(vector(*ty, sse_vector_size));
e.enc_32_64(iadd, rec_fa.opcodes(*opcodes));
}
@@ -1940,7 +1941,7 @@ pub(crate) fn define(
// SIMD integer subtraction
for (ty, opcodes) in &[(I8, &PSUBB), (I16, &PSUBW), (I32, &PSUBD), (I64, &PSUBQ)] {
let isub = isub.bind(vector(ty.clone(), sse_vector_size));
let isub = isub.bind(vector(*ty, sse_vector_size));
e.enc_32_64(isub, rec_fa.opcodes(*opcodes));
}
@@ -1968,7 +1969,7 @@ pub(crate) fn define(
(I16, &PMULLW[..], None),
(I32, &PMULLD[..], Some(use_sse41_simd)),
] {
let imul = imul.bind(vector(ty.clone(), sse_vector_size));
let imul = imul.bind(vector(*ty, sse_vector_size));
e.enc_32_64_maybe_isap(imul, rec_fa.opcodes(opcodes), *isap);
}

View File

@@ -11,6 +11,7 @@ use crate::shared::formats::Formats;
use crate::shared::immediates::Immediates;
use crate::shared::types;
#[allow(clippy::many_single_char_names)]
pub(crate) fn define(
mut all_instructions: &mut AllInstructions,
formats: &Formats,

View File

@@ -6,6 +6,7 @@ use crate::shared::types::Float::F64;
use crate::shared::types::Int::{I16, I32, I64};
use crate::shared::Definitions as SharedDefinitions;
#[allow(clippy::many_single_char_names)]
pub(crate) fn define(shared: &mut SharedDefinitions, x86_instructions: &InstructionGroup) {
let mut group = TransformGroupBuilder::new(
"x86_expand",
@@ -253,7 +254,7 @@ pub(crate) fn define(shared: &mut SharedDefinitions, x86_instructions: &Instruct
def!(r = popcnt.I64(x)),
vec![
def!(qv3 = ushr_imm(x, imm64_1)),
def!(qc77 = iconst(Literal::constant(&imm.imm64, 0x7777777777777777))),
def!(qc77 = iconst(Literal::constant(&imm.imm64, 0x7777_7777_7777_7777))),
def!(qv4 = band(qv3, qc77)),
def!(qv5 = isub(x, qv4)),
def!(qv6 = ushr_imm(qv4, imm64_1)),
@@ -264,9 +265,9 @@ pub(crate) fn define(shared: &mut SharedDefinitions, x86_instructions: &Instruct
def!(qv11 = isub(qv8, qv10)),
def!(qv12 = ushr_imm(qv11, imm64_4)),
def!(qv13 = iadd(qv11, qv12)),
def!(qc0F = iconst(Literal::constant(&imm.imm64, 0x0F0F0F0F0F0F0F0F))),
def!(qc0F = iconst(Literal::constant(&imm.imm64, 0x0F0F_0F0F_0F0F_0F0F))),
def!(qv14 = band(qv13, qc0F)),
def!(qc01 = iconst(Literal::constant(&imm.imm64, 0x0101010101010101))),
def!(qc01 = iconst(Literal::constant(&imm.imm64, 0x0101_0101_0101_0101))),
def!(qv15 = imul(qv14, qc01)),
def!(r = ushr_imm(qv15, Literal::constant(&imm.imm64, 56))),
],
@@ -294,7 +295,7 @@ pub(crate) fn define(shared: &mut SharedDefinitions, x86_instructions: &Instruct
def!(r = popcnt.I32(x)),
vec![
def!(lv3 = ushr_imm(x, imm64_1)),
def!(lc77 = iconst(Literal::constant(&imm.imm64, 0x77777777))),
def!(lc77 = iconst(Literal::constant(&imm.imm64, 0x7777_7777))),
def!(lv4 = band(lv3, lc77)),
def!(lv5 = isub(x, lv4)),
def!(lv6 = ushr_imm(lv4, imm64_1)),
@@ -305,9 +306,9 @@ pub(crate) fn define(shared: &mut SharedDefinitions, x86_instructions: &Instruct
def!(lv11 = isub(lv8, lv10)),
def!(lv12 = ushr_imm(lv11, imm64_4)),
def!(lv13 = iadd(lv11, lv12)),
def!(lc0F = iconst(Literal::constant(&imm.imm64, 0x0F0F0F0F))),
def!(lc0F = iconst(Literal::constant(&imm.imm64, 0x0F0F_0F0F))),
def!(lv14 = band(lv13, lc0F)),
def!(lc01 = iconst(Literal::constant(&imm.imm64, 0x01010101))),
def!(lc01 = iconst(Literal::constant(&imm.imm64, 0x0101_0101))),
def!(lv15 = imul(lv14, lc01)),
def!(r = ushr_imm(lv15, Literal::constant(&imm.imm64, 24))),
],

View File

@@ -51,14 +51,14 @@ impl<'builder> RecipeGroup<'builder> {
pub fn recipe(&self, name: &str) -> &EncodingRecipe {
self.recipes
.iter()
.find(|recipe| &recipe.name == name)
.expect(&format!("unknown recipe name: {}. Try template?", name))
.find(|recipe| recipe.name == name)
.unwrap_or_else(|| panic!("unknown recipe name: {}. Try template?", name))
}
pub fn template(&self, name: &str) -> &Template {
self.templates
.iter()
.find(|recipe| recipe.name() == name)
.expect(&format!("unknown tail recipe name: {}. Try recipe?", name))
.unwrap_or_else(|| panic!("unknown tail recipe name: {}. Try recipe?", name))
}
}
@@ -96,7 +96,7 @@ impl<'builder> RecipeGroup<'builder> {
/// Given a sequence of opcode bytes, compute the recipe name prefix and encoding bits.
fn decode_opcodes(op_bytes: &[u8], rrr: u16, w: u16) -> (&'static str, u16) {
assert!(op_bytes.len() >= 1, "at least one opcode byte");
assert!(!op_bytes.is_empty(), "at least one opcode byte");
let prefix_bytes = &op_bytes[..op_bytes.len() - 1];
let (name, mmpp) = match prefix_bytes {
@@ -121,7 +121,7 @@ fn decode_opcodes(op_bytes: &[u8], rrr: u16, w: u16) -> (&'static str, u16) {
}
};
let opcode_byte = op_bytes[op_bytes.len() - 1] as u16;
let opcode_byte = u16::from(op_bytes[op_bytes.len() - 1]);
(name, opcode_byte | (mmpp << 8) | (rrr << 12) | w << 15)
}
@@ -243,7 +243,7 @@ impl<'builder> Template<'builder> {
if let Some(prefixed) = &self.when_prefixed {
let mut ret = prefixed.rex();
// Forward specialized parameters.
ret.op_bytes = self.op_bytes.clone();
ret.op_bytes = self.op_bytes;
ret.w_bit = self.w_bit;
ret.rrr_bits = self.rrr_bits;
return ret;
@@ -266,18 +266,17 @@ impl<'builder> Template<'builder> {
self.recipe.base_size += size_addendum;
// Branch ranges are relative to the end of the instruction.
self.recipe
.branch_range
.as_mut()
.map(|range| range.inst_size += size_addendum);
if let Some(range) = self.recipe.branch_range.as_mut() {
range.inst_size += size_addendum;
}
self.recipe.emit = replace_put_op(self.recipe.emit, &name);
self.recipe.name = name + &self.recipe.name;
if !self.rex {
let operands_in = self.recipe.operands_in.unwrap_or(Vec::new());
let operands_in = self.recipe.operands_in.unwrap_or_default();
self.recipe.operands_in = Some(replace_nonrex_constraints(self.regs, operands_in));
let operands_out = self.recipe.operands_out.unwrap_or(Vec::new());
let operands_out = self.recipe.operands_out.unwrap_or_default();
self.recipe.operands_out = Some(replace_nonrex_constraints(self.regs, operands_out));
}

View File

@@ -22,7 +22,7 @@ pub fn isa_from_arch(arch: &str) -> Result<isa::Isa, String> {
}
/// Generates all the Rust source files used in Cranelift from the meta-language.
pub fn generate(isas: &Vec<isa::Isa>, out_dir: &str) -> Result<(), error::Error> {
pub fn generate(isas: &[isa::Isa], out_dir: &str) -> Result<(), error::Error> {
// Create all the definitions:
// - common definitions.
let mut shared_defs = shared::define();

View File

@@ -11,6 +11,7 @@ use crate::shared::formats::Formats;
use crate::shared::types;
use crate::shared::{entities::EntityRefs, immediates::Immediates};
#[allow(clippy::many_single_char_names)]
pub(crate) fn define(
all_instructions: &mut AllInstructions,
formats: &Formats,

View File

@@ -7,6 +7,7 @@ use crate::shared::types::Float::{F32, F64};
use crate::shared::types::Int::{I128, I16, I32, I64, I8};
use cranelift_codegen_shared::condcodes::{CondCode, IntCC};
#[allow(clippy::many_single_char_names, clippy::cognitive_complexity)]
pub(crate) fn define(insts: &InstructionGroup, imm: &Immediates) -> TransformGroups {
let mut narrow = TransformGroupBuilder::new(
"narrow",
@@ -766,24 +767,24 @@ pub(crate) fn define(insts: &InstructionGroup, imm: &Immediates) -> TransformGro
expand.legalize(
def!(a = bitrev.I32(x)),
vec![
def!(a1 = band_imm(x, Literal::constant(&imm.imm64, 0xaaaaaaaa))),
def!(a1 = band_imm(x, Literal::constant(&imm.imm64, 0xaaaa_aaaa))),
def!(a2 = ushr_imm(a1, imm64_1)),
def!(a3 = band_imm(x, Literal::constant(&imm.imm64, 0x55555555))),
def!(a3 = band_imm(x, Literal::constant(&imm.imm64, 0x5555_5555))),
def!(a4 = ishl_imm(a3, imm64_1)),
def!(b = bor(a2, a4)),
def!(b1 = band_imm(b, Literal::constant(&imm.imm64, 0xcccccccc))),
def!(b1 = band_imm(b, Literal::constant(&imm.imm64, 0xcccc_cccc))),
def!(b2 = ushr_imm(b1, imm64_2)),
def!(b3 = band_imm(b, Literal::constant(&imm.imm64, 0x33333333))),
def!(b3 = band_imm(b, Literal::constant(&imm.imm64, 0x3333_3333))),
def!(b4 = ishl_imm(b3, imm64_2)),
def!(c = bor(b2, b4)),
def!(c1 = band_imm(c, Literal::constant(&imm.imm64, 0xf0f0f0f0))),
def!(c1 = band_imm(c, Literal::constant(&imm.imm64, 0xf0f0_f0f0))),
def!(c2 = ushr_imm(c1, imm64_4)),
def!(c3 = band_imm(c, Literal::constant(&imm.imm64, 0x0f0f0f0f))),
def!(c3 = band_imm(c, Literal::constant(&imm.imm64, 0x0f0f_0f0f))),
def!(c4 = ishl_imm(c3, imm64_4)),
def!(d = bor(c2, c4)),
def!(d1 = band_imm(d, Literal::constant(&imm.imm64, 0xff00ff00))),
def!(d1 = band_imm(d, Literal::constant(&imm.imm64, 0xff00_ff00))),
def!(d2 = ushr_imm(d1, imm64_8)),
def!(d3 = band_imm(d, Literal::constant(&imm.imm64, 0x00ff00ff))),
def!(d3 = band_imm(d, Literal::constant(&imm.imm64, 0x00ff_00ff))),
def!(d4 = ishl_imm(d3, imm64_8)),
def!(e = bor(d2, d4)),
def!(e1 = ushr_imm(e, imm64_16)),
@@ -793,20 +794,20 @@ pub(crate) fn define(insts: &InstructionGroup, imm: &Immediates) -> TransformGro
);
#[allow(overflowing_literals)]
let imm64_0xaaaaaaaaaaaaaaaa = Literal::constant(&imm.imm64, 0xaaaaaaaaaaaaaaaa);
let imm64_0x5555555555555555 = Literal::constant(&imm.imm64, 0x5555555555555555);
let imm64_0xaaaaaaaaaaaaaaaa = Literal::constant(&imm.imm64, 0xaaaa_aaaa_aaaa_aaaa);
let imm64_0x5555555555555555 = Literal::constant(&imm.imm64, 0x5555_5555_5555_5555);
#[allow(overflowing_literals)]
let imm64_0xcccccccccccccccc = Literal::constant(&imm.imm64, 0xcccccccccccccccc);
let imm64_0x3333333333333333 = Literal::constant(&imm.imm64, 0x3333333333333333);
let imm64_0xcccccccccccccccc = Literal::constant(&imm.imm64, 0xcccc_cccc_cccc_cccc);
let imm64_0x3333333333333333 = Literal::constant(&imm.imm64, 0x3333_3333_3333_3333);
#[allow(overflowing_literals)]
let imm64_0xf0f0f0f0f0f0f0f0 = Literal::constant(&imm.imm64, 0xf0f0f0f0f0f0f0f0);
let imm64_0x0f0f0f0f0f0f0f0f = Literal::constant(&imm.imm64, 0x0f0f0f0f0f0f0f0f);
let imm64_0xf0f0f0f0f0f0f0f0 = Literal::constant(&imm.imm64, 0xf0f0_f0f0_f0f0_f0f0);
let imm64_0x0f0f0f0f0f0f0f0f = Literal::constant(&imm.imm64, 0x0f0f_0f0f_0f0f_0f0f);
#[allow(overflowing_literals)]
let imm64_0xff00ff00ff00ff00 = Literal::constant(&imm.imm64, 0xff00ff00ff00ff00);
let imm64_0x00ff00ff00ff00ff = Literal::constant(&imm.imm64, 0x00ff00ff00ff00ff);
let imm64_0xff00ff00ff00ff00 = Literal::constant(&imm.imm64, 0xff00_ff00_ff00_ff00);
let imm64_0x00ff00ff00ff00ff = Literal::constant(&imm.imm64, 0x00ff_00ff_00ff_00ff);
#[allow(overflowing_literals)]
let imm64_0xffff0000ffff0000 = Literal::constant(&imm.imm64, 0xffff0000ffff0000);
let imm64_0x0000ffff0000ffff = Literal::constant(&imm.imm64, 0x0000ffff0000ffff);
let imm64_0xffff0000ffff0000 = Literal::constant(&imm.imm64, 0xffff_0000_ffff_0000);
let imm64_0x0000ffff0000ffff = Literal::constant(&imm.imm64, 0x0000_ffff_0000_ffff);
let imm64_32 = Literal::constant(&imm.imm64, 32);
expand.legalize(
@@ -845,11 +846,11 @@ pub(crate) fn define(insts: &InstructionGroup, imm: &Immediates) -> TransformGro
// Floating-point sign manipulations.
for &(ty, const_inst, minus_zero) in &[
(F32, f32const, &Literal::bits(&imm.ieee32, 0x80000000)),
(F32, f32const, &Literal::bits(&imm.ieee32, 0x8000_0000)),
(
F64,
f64const,
&Literal::bits(&imm.ieee64, 0x8000000000000000),
&Literal::bits(&imm.ieee64, 0x8000_0000_0000_0000),
),
] {
expand.legalize(

View File

@@ -139,7 +139,7 @@ impl Formatter {
parse_multiline(contents.as_ref())
.iter()
.map(|l| {
if l.len() == 0 {
if l.is_empty() {
"///".into()
} else {
format!("/// {}", l)
@@ -157,7 +157,7 @@ impl Formatter {
let conditions = names
.iter()
.map(|name| {
if fields.len() > 0 {
if !fields.is_empty() {
format!("{} {{ {} }}", name, fields.join(", "))
} else {
name.clone()

View File

@@ -48,8 +48,8 @@ impl<T: PartialEq + Clone> UniqueSeqTable<T> {
pub fn new() -> Self {
Self { table: Vec::new() }
}
pub fn add(&mut self, values: &Vec<T>) -> usize {
if values.len() == 0 {
pub fn add(&mut self, values: &[T]) -> usize {
if values.is_empty() {
return 0;
}
if let Some(offset) = find_subsequence(values, &self.table) {
@@ -87,19 +87,19 @@ impl<T: PartialEq + Clone> UniqueSeqTable<T> {
/// Try to find the subsequence `sub` in the `whole` sequence. Returns None if
/// it's not been found, or Some(index) if it has been. Naive implementation
/// until proven we need something better.
fn find_subsequence<T: PartialEq>(sub: &Vec<T>, whole: &Vec<T>) -> Option<usize> {
assert!(sub.len() > 0);
fn find_subsequence<T: PartialEq>(sub: &[T], whole: &[T]) -> Option<usize> {
assert!(!sub.is_empty());
// We want i + sub.len() <= whole.len(), i.e. i < whole.len() + 1 - sub.len().
if whole.len() < sub.len() {
return None;
}
let max = whole.len() - sub.len();
for i in 0..max + 1 {
for i in 0..=max {
if whole[i..i + sub.len()] == sub[..] {
return Some(i);
}
}
return None;
None
}
#[test]