Merge remote-tracking branch 'origin/master' into no_std

This commit is contained in:
Dan Gohman
2018-04-18 17:17:43 -07:00
92 changed files with 508 additions and 295 deletions

View File

@@ -25,13 +25,13 @@ pub enum ArgAction {
}
impl From<ArgumentLoc> for ArgAction {
fn from(x: ArgumentLoc) -> ArgAction {
fn from(x: ArgumentLoc) -> Self {
ArgAction::Assign(x)
}
}
impl From<ValueConversion> for ArgAction {
fn from(x: ValueConversion) -> ArgAction {
fn from(x: ValueConversion) -> Self {
ArgAction::Convert(x)
}
}

View File

@@ -45,8 +45,8 @@ where
C: Comparator<K>,
{
/// Create a new empty forest.
pub fn new() -> MapForest<K, V, C> {
MapForest { nodes: NodePool::new() }
pub fn new() -> Self {
Self { nodes: NodePool::new() }
}
/// Clear all maps in the forest.
@@ -83,8 +83,8 @@ where
C: Comparator<K>,
{
/// Make an empty map.
pub fn new() -> Map<K, V, C> {
Map {
pub fn new() -> Self {
Self {
root: None.into(),
unused: PhantomData,
}

View File

@@ -73,7 +73,7 @@ impl<F: Forest> NodeData<F> {
}
/// Create an inner node with a single key and two sub-trees.
pub fn inner(left: Node, key: F::Key, right: Node) -> NodeData<F> {
pub fn inner(left: Node, key: F::Key, right: Node) -> Self {
// Splat the key and right node to the whole array.
// Saves us from inventing a default/reserved value.
let mut tree = [right; INNER_SIZE];
@@ -86,7 +86,7 @@ impl<F: Forest> NodeData<F> {
}
/// Create a leaf node with a single key-value pair.
pub fn leaf(key: F::Key, value: F::Value) -> NodeData<F> {
pub fn leaf(key: F::Key, value: F::Value) -> Self {
NodeData::Leaf {
size: 1,
keys: F::splat_key(key),
@@ -360,7 +360,7 @@ impl<F: Forest> NodeData<F> {
///
/// In the first case, `None` is returned. In the second case, the new critical key for the
/// right sibling node is returned.
pub fn balance(&mut self, crit_key: F::Key, rhs: &mut NodeData<F>) -> Option<F::Key> {
pub fn balance(&mut self, crit_key: F::Key, rhs: &mut Self) -> Option<F::Key> {
match (self, rhs) {
(&mut NodeData::Inner {
size: ref mut l_size,
@@ -514,7 +514,7 @@ pub(super) enum Removed {
impl Removed {
/// Create a `Removed` status from a size and capacity.
fn new(removed: usize, new_size: usize, capacity: usize) -> Removed {
fn new(removed: usize, new_size: usize, capacity: usize) -> Self {
if 2 * new_size >= capacity {
if removed == new_size {
Removed::Rightmost

View File

@@ -22,8 +22,8 @@ pub(super) struct Path<F: Forest> {
}
impl<F: Forest> Default for Path<F> {
fn default() -> Path<F> {
Path {
fn default() -> Self {
Self {
size: 0,
node: [Node(0); MAX_PATH],
entry: [0; MAX_PATH],

View File

@@ -12,8 +12,8 @@ pub(super) struct NodePool<F: Forest> {
impl<F: Forest> NodePool<F> {
/// Allocate a new empty pool of nodes.
pub fn new() -> NodePool<F> {
NodePool {
pub fn new() -> Self {
Self {
nodes: PrimaryMap::new(),
freelist: None,
}

View File

@@ -42,8 +42,8 @@ where
C: Comparator<K>,
{
/// Create a new empty forest.
pub fn new() -> SetForest<K, C> {
SetForest { nodes: NodePool::new() }
pub fn new() -> Self {
Self { nodes: NodePool::new() }
}
/// Clear all sets in the forest.
@@ -78,8 +78,8 @@ where
C: Comparator<K>,
{
/// Make an empty set.
pub fn new() -> Set<K, C> {
Set {
pub fn new() -> Self {
Self {
root: None.into(),
unused: PhantomData,
}

View File

@@ -38,7 +38,10 @@ pub struct MemoryCodeSink<'a> {
impl<'a> MemoryCodeSink<'a> {
/// Create a new memory code sink that writes a function to the memory pointed to by `data`.
pub fn new<'sink>(
///
/// This function is unsafe since `MemoryCodeSink` does not perform bounds checking on the
/// memory buffer, and it can't guarantee that the `data` pointer is valid.
pub unsafe fn new<'sink>(
data: *mut u8,
relocs: &'sink mut RelocSink,
traps: &'sink mut TrapSink,
@@ -84,6 +87,7 @@ impl<'a> CodeSink for MemoryCodeSink<'a> {
fn put2(&mut self, x: u16) {
unsafe {
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
write_unaligned(self.data.offset(self.offset) as *mut u16, x);
}
self.offset += 2;
@@ -91,6 +95,7 @@ impl<'a> CodeSink for MemoryCodeSink<'a> {
fn put4(&mut self, x: u32) {
unsafe {
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
write_unaligned(self.data.offset(self.offset) as *mut u32, x);
}
self.offset += 4;
@@ -98,6 +103,7 @@ impl<'a> CodeSink for MemoryCodeSink<'a> {
fn put8(&mut self, x: u64) {
unsafe {
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
write_unaligned(self.data.offset(self.offset) as *mut u64, x);
}
self.offset += 8;

View File

@@ -48,12 +48,12 @@ impl fmt::Display for Reloc {
/// already unambigious, e.g. cton 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::X86GOTPCRel4 => write!(f, "{}", "GOTPCRel4"),
Reloc::X86PLTRel4 => write!(f, "{}", "PLTRel4"),
Reloc::Arm32Call | Reloc::Arm64Call | Reloc::RiscvCall => write!(f, "{}", "Call"),
Reloc::Abs4 => write!(f, "Abs4"),
Reloc::Abs8 => write!(f, "Abs8"),
Reloc::X86PCRel4 => write!(f, "PCRel4"),
Reloc::X86GOTPCRel4 => write!(f, "GOTPCRel4"),
Reloc::X86PLTRel4 => write!(f, "PLTRel4"),
Reloc::Arm32Call | Reloc::Arm64Call | Reloc::RiscvCall => write!(f, "Call"),
}
}
}

View File

@@ -52,7 +52,7 @@ impl Context {
/// The returned instance should be reused for compiling multiple functions in order to avoid
/// needless allocator thrashing.
pub fn new() -> Self {
Context::for_function(Function::new())
Self::for_function(Function::new())
}
/// Allocate a new compilation context with an existing Function.
@@ -61,7 +61,7 @@ impl Context {
/// needless allocator thrashing.
pub fn for_function(func: Function) -> Self {
Self {
func: func,
func,
cfg: ControlFlowGraph::new(),
domtree: DominatorTree::new(),
regalloc: regalloc::Context::new(),
@@ -78,6 +78,36 @@ impl Context {
self.loop_analysis.clear();
}
/// Compile the function, and emit machine code into a `Vec<u8>`.
///
/// Run the function through all the passes necessary to generate code for the target ISA
/// represented by `isa`, as well as the final step of emitting machine code into a
/// `Vec<u8>`. The machine code is not relocated. Instead, any relocations are emitted
/// into `relocs`.
///
/// This function calls `compile` and `emit_to_memory`, taking care to resize `mem` as
/// needed, so it provides a safe interface.
pub fn compile_and_emit(
&mut self,
isa: &TargetIsa,
mem: &mut Vec<u8>,
relocs: &mut RelocSink,
traps: &mut TrapSink,
) -> CtonResult {
let code_size = self.compile(isa)?;
let old_len = mem.len();
mem.resize(old_len + code_size as usize, 0);
unsafe {
self.emit_to_memory(
isa,
mem.as_mut_ptr().offset(old_len as isize),
relocs,
traps,
)
};
Ok(())
}
/// Compile the function.
///
/// Run the function through all the passes necessary to generate code for the target ISA
@@ -119,12 +149,15 @@ impl Context {
/// code is returned by `compile` above.
///
/// The machine code is not relocated. Instead, any relocations are emitted into `relocs`.
pub fn emit_to_memory(
///
/// This function is unsafe since it does not perform bounds checking on the memory buffer,
/// and it can't guarantee that the `mem` pointer is valid.
pub unsafe fn emit_to_memory(
&self,
isa: &TargetIsa,
mem: *mut u8,
relocs: &mut RelocSink,
traps: &mut TrapSink,
isa: &TargetIsa,
) {
let _tt = timing::binemit();
isa.emit_function(&self.func, &mut MemoryCodeSink::new(mem, relocs, traps));

View File

@@ -528,8 +528,8 @@ struct ExtraNode {
/// Creating and computing the dominator tree pre-order.
impl DominatorTreePreorder {
/// Create a new blank `DominatorTreePreorder`.
pub fn new() -> DominatorTreePreorder {
DominatorTreePreorder {
pub fn new() -> Self {
Self {
nodes: EntityMap::new(),
stack: Vec::new(),
}

View File

@@ -31,7 +31,7 @@ impl Ebb {
/// Create a new EBB reference from its number. This corresponds to the `ebbNN` representation.
///
/// This method is for use by the parser.
pub fn with_number(n: u32) -> Option<Ebb> {
pub fn with_number(n: u32) -> Option<Self> {
if n < u32::MAX { Some(Ebb(n)) } else { None }
}
}
@@ -46,7 +46,7 @@ impl Value {
/// This is the number in the `vNN` notation.
///
/// This method is for use by the parser.
pub fn with_number(n: u32) -> Option<Value> {
pub fn with_number(n: u32) -> Option<Self> {
if n < u32::MAX / 2 {
Some(Value(n))
} else {
@@ -69,7 +69,7 @@ impl StackSlot {
/// Create a new stack slot reference from its number.
///
/// This method is for use by the parser.
pub fn with_number(n: u32) -> Option<StackSlot> {
pub fn with_number(n: u32) -> Option<Self> {
if n < u32::MAX {
Some(StackSlot(n))
} else {
@@ -87,7 +87,7 @@ impl GlobalVar {
/// Create a new global variable reference from its number.
///
/// This method is for use by the parser.
pub fn with_number(n: u32) -> Option<GlobalVar> {
pub fn with_number(n: u32) -> Option<Self> {
if n < u32::MAX {
Some(GlobalVar(n))
} else {
@@ -105,7 +105,7 @@ impl JumpTable {
/// Create a new jump table reference from its number.
///
/// This method is for use by the parser.
pub fn with_number(n: u32) -> Option<JumpTable> {
pub fn with_number(n: u32) -> Option<Self> {
if n < u32::MAX {
Some(JumpTable(n))
} else {
@@ -123,7 +123,7 @@ impl FuncRef {
/// Create a new external function reference from its number.
///
/// This method is for use by the parser.
pub fn with_number(n: u32) -> Option<FuncRef> {
pub fn with_number(n: u32) -> Option<Self> {
if n < u32::MAX { Some(FuncRef(n)) } else { None }
}
}
@@ -137,7 +137,7 @@ impl SigRef {
/// Create a new function signature reference from its number.
///
/// This method is for use by the parser.
pub fn with_number(n: u32) -> Option<SigRef> {
pub fn with_number(n: u32) -> Option<Self> {
if n < u32::MAX { Some(SigRef(n)) } else { None }
}
}
@@ -151,7 +151,7 @@ impl Heap {
/// Create a new heap reference from its number.
///
/// This method is for use by the parser.
pub fn with_number(n: u32) -> Option<Heap> {
pub fn with_number(n: u32) -> Option<Self> {
if n < u32::MAX { Some(Heap(n)) } else { None }
}
}
@@ -205,55 +205,55 @@ impl fmt::Debug for AnyEntity {
}
impl From<Ebb> for AnyEntity {
fn from(r: Ebb) -> AnyEntity {
fn from(r: Ebb) -> Self {
AnyEntity::Ebb(r)
}
}
impl From<Inst> for AnyEntity {
fn from(r: Inst) -> AnyEntity {
fn from(r: Inst) -> Self {
AnyEntity::Inst(r)
}
}
impl From<Value> for AnyEntity {
fn from(r: Value) -> AnyEntity {
fn from(r: Value) -> Self {
AnyEntity::Value(r)
}
}
impl From<StackSlot> for AnyEntity {
fn from(r: StackSlot) -> AnyEntity {
fn from(r: StackSlot) -> Self {
AnyEntity::StackSlot(r)
}
}
impl From<GlobalVar> for AnyEntity {
fn from(r: GlobalVar) -> AnyEntity {
fn from(r: GlobalVar) -> Self {
AnyEntity::GlobalVar(r)
}
}
impl From<JumpTable> for AnyEntity {
fn from(r: JumpTable) -> AnyEntity {
fn from(r: JumpTable) -> Self {
AnyEntity::JumpTable(r)
}
}
impl From<FuncRef> for AnyEntity {
fn from(r: FuncRef) -> AnyEntity {
fn from(r: FuncRef) -> Self {
AnyEntity::FuncRef(r)
}
}
impl From<SigRef> for AnyEntity {
fn from(r: SigRef) -> AnyEntity {
fn from(r: SigRef) -> Self {
AnyEntity::SigRef(r)
}
}
impl From<Heap> for AnyEntity {
fn from(r: Heap) -> AnyEntity {
fn from(r: Heap) -> Self {
AnyEntity::Heap(r)
}
}

View File

@@ -304,7 +304,7 @@ impl fmt::Display for ArgumentPurpose {
impl FromStr for ArgumentPurpose {
type Err = ();
fn from_str(s: &str) -> Result<ArgumentPurpose, ()> {
fn from_str(s: &str) -> Result<Self, ()> {
match s {
"normal" => Ok(ArgumentPurpose::Normal),
"sret" => Ok(ArgumentPurpose::StructReturn),

View File

@@ -56,7 +56,7 @@ impl ExternalName {
/// let name = ExternalName::testcase("hello");
/// assert_eq!(name.to_string(), "%hello");
/// ```
pub fn testcase<T: AsRef<[u8]>>(v: T) -> ExternalName {
pub fn testcase<T: AsRef<[u8]>>(v: T) -> Self {
let vec = v.as_ref();
let len = cmp::min(vec.len(), TESTCASE_NAME_LENGTH);
let mut bytes = [0u8; TESTCASE_NAME_LENGTH];
@@ -77,17 +77,14 @@ impl ExternalName {
/// let name = ExternalName::user(123, 456);
/// assert_eq!(name.to_string(), "u123:456");
/// ```
pub fn user(namespace: u32, index: u32) -> ExternalName {
ExternalName::User {
namespace: namespace,
index: index,
}
pub fn user(namespace: u32, index: u32) -> Self {
ExternalName::User { namespace, index }
}
}
impl Default for ExternalName {
fn default() -> ExternalName {
ExternalName::user(0, 0)
fn default() -> Self {
Self::user(0, 0)
}
}

View File

@@ -18,12 +18,12 @@ pub struct Imm64(i64);
impl Imm64 {
/// Create a new `Imm64` representing the signed number `x`.
pub fn new(x: i64) -> Imm64 {
pub fn new(x: i64) -> Self {
Imm64(x)
}
/// Return self negated.
pub fn wrapping_neg(self) -> Imm64 {
pub fn wrapping_neg(self) -> Self {
Imm64(self.0.wrapping_neg())
}
}
@@ -143,8 +143,8 @@ impl FromStr for Imm64 {
type Err = &'static str;
// Parse a decimal or hexadecimal `Imm64`, formatted as above.
fn from_str(s: &str) -> Result<Imm64, &'static str> {
parse_i64(s).map(Imm64::new)
fn from_str(s: &str) -> Result<Self, &'static str> {
parse_i64(s).map(Self::new)
}
}
@@ -191,7 +191,7 @@ impl FromStr for Uimm32 {
type Err = &'static str;
// Parse a decimal or hexadecimal `Uimm32`, formatted as above.
fn from_str(s: &str) -> Result<Uimm32, &'static str> {
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))
} else {
@@ -209,7 +209,7 @@ pub struct Offset32(i32);
impl Offset32 {
/// Create a new `Offset32` representing the signed number `x`.
pub fn new(x: i32) -> Offset32 {
pub fn new(x: i32) -> Self {
Offset32(x)
}
}
@@ -255,14 +255,14 @@ impl FromStr for Offset32 {
type Err = &'static str;
// Parse a decimal or hexadecimal `Offset32`, formatted as above.
fn from_str(s: &str) -> Result<Offset32, &'static str> {
fn from_str(s: &str) -> Result<Self, &'static str> {
if !(s.starts_with('-') || s.starts_with('+')) {
return Err("Offset must begin with sign");
}
parse_i64(s).and_then(|x| if i64::from(i32::MIN) <= x &&
x <= i64::from(i32::MAX)
{
Ok(Offset32::new(x as i32))
Ok(Self::new(x as i32))
} else {
Err("Offset out of range")
})
@@ -524,12 +524,12 @@ 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) -> Ieee32 {
pub fn with_bits(x: u32) -> Self {
Ieee32(x)
}
/// Create an `Ieee32` number representing `2.0^n`.
pub fn pow2<I: Into<i32>>(n: I) -> Ieee32 {
pub fn pow2<I: Into<i32>>(n: I) -> Self {
let n = n.into();
let w = 8;
let t = 23;
@@ -542,7 +542,7 @@ impl Ieee32 {
/// Create an `Ieee32` number representing the greatest negative value
/// not convertable from f32 to a signed integer with width n.
pub fn fcvt_to_sint_negative_overflow<I: Into<i32>>(n: I) -> Ieee32 {
pub fn fcvt_to_sint_negative_overflow<I: Into<i32>>(n: I) -> Self {
let n = n.into();
debug_assert!(n < 32);
debug_assert!(23 + 1 - n < 32);
@@ -552,12 +552,12 @@ impl Ieee32 {
}
/// Return self negated.
pub fn neg(self) -> Ieee32 {
pub fn neg(self) -> Self {
Ieee32(self.0 ^ (1 << 31))
}
/// Create a new `Ieee32` representing the number `x`.
pub fn with_float(x: f32) -> Ieee32 {
pub fn with_float(x: f32) -> Self {
Ieee32(unsafe { mem::transmute(x) })
}
@@ -577,7 +577,7 @@ impl Display for Ieee32 {
impl FromStr for Ieee32 {
type Err = &'static str;
fn from_str(s: &str) -> Result<Ieee32, &'static str> {
fn from_str(s: &str) -> Result<Self, &'static str> {
match parse_float(s, 8, 23) {
Ok(b) => Ok(Ieee32(b as u32)),
Err(s) => Err(s),
@@ -587,12 +587,12 @@ impl FromStr for Ieee32 {
impl Ieee64 {
/// Create a new `Ieee64` containing the bits of `x`.
pub fn with_bits(x: u64) -> Ieee64 {
pub fn with_bits(x: u64) -> Self {
Ieee64(x)
}
/// Create an `Ieee64` number representing `2.0^n`.
pub fn pow2<I: Into<i64>>(n: I) -> Ieee64 {
pub fn pow2<I: Into<i64>>(n: I) -> Self {
let n = n.into();
let w = 11;
let t = 52;
@@ -605,7 +605,7 @@ impl Ieee64 {
/// Create an `Ieee64` number representing the greatest negative value
/// not convertable from f64 to a signed integer with width n.
pub fn fcvt_to_sint_negative_overflow<I: Into<i64>>(n: I) -> Ieee64 {
pub fn fcvt_to_sint_negative_overflow<I: Into<i64>>(n: I) -> Self {
let n = n.into();
debug_assert!(n < 64);
debug_assert!(52 + 1 - n < 64);
@@ -615,12 +615,12 @@ impl Ieee64 {
}
/// Return self negated.
pub fn neg(self) -> Ieee64 {
pub fn neg(self) -> Self {
Ieee64(self.0 ^ (1 << 63))
}
/// Create a new `Ieee64` representing the number `x`.
pub fn with_float(x: f64) -> Ieee64 {
pub fn with_float(x: f64) -> Self {
Ieee64(unsafe { mem::transmute(x) })
}
@@ -640,7 +640,7 @@ impl Display for Ieee64 {
impl FromStr for Ieee64 {
type Err = &'static str;
fn from_str(s: &str) -> Result<Ieee64, &'static str> {
fn from_str(s: &str) -> Result<Self, &'static str> {
match parse_float(s, 11, 52) {
Ok(b) => Ok(Ieee64(b)),
Err(s) => Err(s),

View File

@@ -72,7 +72,7 @@ impl FromStr for Opcode {
type Err = &'static str;
/// Parse an Opcode name from a string.
fn from_str(s: &str) -> Result<Opcode, &'static str> {
fn from_str(s: &str) -> Result<Self, &'static str> {
use constant_hash::{probe, simple_hash, Table};
impl<'a> Table<&'a str> for [Option<Opcode>] {
@@ -85,7 +85,7 @@ impl FromStr for Opcode {
}
}
match probe::<&str, [Option<Opcode>]>(&OPCODE_HASH_TABLE, s, simple_hash(s)) {
match probe::<&str, [Option<Self>]>(&OPCODE_HASH_TABLE, s, simple_hash(s)) {
Err(_) => Err("Unknown opcode"),
// We unwrap here because probe() should have ensured that the entry
// at this index is not None.

View File

@@ -72,7 +72,7 @@ impl LibCall {
/// given opcode and controlling type variable.
///
/// Returns `None` if no well-known library routine name exists for that instruction.
pub fn for_inst(opcode: Opcode, ctrl_type: Type) -> Option<LibCall> {
pub fn for_inst(opcode: Opcode, ctrl_type: Type) -> Option<Self> {
Some(match ctrl_type {
types::F32 => {
match opcode {

View File

@@ -17,7 +17,7 @@ use std::u32;
pub struct ProgramPoint(u32);
impl From<Inst> for ProgramPoint {
fn from(inst: Inst) -> ProgramPoint {
fn from(inst: Inst) -> Self {
let idx = inst.index();
debug_assert!(idx < (u32::MAX / 2) as usize);
ProgramPoint((idx * 2) as u32)
@@ -25,7 +25,7 @@ impl From<Inst> for ProgramPoint {
}
impl From<Ebb> for ProgramPoint {
fn from(ebb: Ebb) -> ProgramPoint {
fn from(ebb: Ebb) -> Self {
let idx = ebb.index();
debug_assert!(idx < (u32::MAX / 2) as usize);
ProgramPoint((idx * 2 + 1) as u32)
@@ -33,7 +33,7 @@ impl From<Ebb> for ProgramPoint {
}
impl From<ValueDef> for ProgramPoint {
fn from(def: ValueDef) -> ProgramPoint {
fn from(def: ValueDef) -> Self {
match def {
ValueDef::Result(inst, _) => inst.into(),
ValueDef::Param(ebb, _) => ebb.into(),
@@ -62,19 +62,19 @@ impl ExpandedProgramPoint {
}
impl From<Inst> for ExpandedProgramPoint {
fn from(inst: Inst) -> ExpandedProgramPoint {
fn from(inst: Inst) -> Self {
ExpandedProgramPoint::Inst(inst)
}
}
impl From<Ebb> for ExpandedProgramPoint {
fn from(ebb: Ebb) -> ExpandedProgramPoint {
fn from(ebb: Ebb) -> Self {
ExpandedProgramPoint::Ebb(ebb)
}
}
impl From<ValueDef> for ExpandedProgramPoint {
fn from(def: ValueDef) -> ExpandedProgramPoint {
fn from(def: ValueDef) -> Self {
match def {
ValueDef::Result(inst, _) => inst.into(),
ValueDef::Param(ebb, _) => ebb.into(),
@@ -83,7 +83,7 @@ impl From<ValueDef> for ExpandedProgramPoint {
}
impl From<ProgramPoint> for ExpandedProgramPoint {
fn from(pp: ProgramPoint) -> ExpandedProgramPoint {
fn from(pp: ProgramPoint) -> Self {
if pp.0 & 1 == 0 {
ExpandedProgramPoint::Inst(Inst::new((pp.0 / 2) as usize))
} else {

View File

@@ -17,7 +17,7 @@ pub struct SourceLoc(u32);
impl SourceLoc {
/// Create a new source location with the given bits.
pub fn new(bits: u32) -> SourceLoc {
pub fn new(bits: u32) -> Self {
SourceLoc(bits)
}

View File

@@ -70,7 +70,7 @@ pub enum StackSlotKind {
impl FromStr for StackSlotKind {
type Err = ();
fn from_str(s: &str) -> Result<StackSlotKind, ()> {
fn from_str(s: &str) -> Result<Self, ()> {
use self::StackSlotKind::*;
match s {
"explicit_slot" => Ok(ExplicitSlot),
@@ -117,8 +117,8 @@ pub struct StackSlotData {
impl StackSlotData {
/// Create a stack slot with the specified byte size.
pub fn new(kind: StackSlotKind, size: StackSize) -> StackSlotData {
StackSlotData {
pub fn new(kind: StackSlotKind, size: StackSize) -> Self {
Self {
kind,
size,
offset: None,

View File

@@ -39,7 +39,7 @@ impl Type {
/// Get the lane type of this SIMD vector type.
///
/// A lane type is the same as a SIMD vector type with one lane, so it returns itself.
pub fn lane_type(self) -> Type {
pub fn lane_type(self) -> Self {
if self.0 < VECTOR_BASE {
self
} else {
@@ -72,7 +72,7 @@ impl Type {
}
/// Get an integer type with the requested number of bits.
pub fn int(bits: u16) -> Option<Type> {
pub fn int(bits: u16) -> Option<Self> {
match bits {
8 => Some(I8),
16 => Some(I16),
@@ -83,7 +83,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: Type) -> Type {
fn replace_lanes(self, lane: Self) -> Self {
debug_assert!(lane.is_lane() && !self.is_special());
Type((lane.0 & 0x0f) | (self.0 & 0xf0))
}
@@ -93,7 +93,7 @@ impl Type {
///
/// Scalar types are treated as vectors with one lane, so they are converted to the multi-bit
/// boolean types.
pub fn as_bool_pedantic(self) -> Type {
pub fn as_bool_pedantic(self) -> Self {
// Replace the low 4 bits with the boolean version, preserve the high 4 bits.
self.replace_lanes(match self.lane_type() {
B8 | I8 => B8,
@@ -108,7 +108,7 @@ impl Type {
/// booleans of the same size.
///
/// Scalar types are all converted to `b1` which is usually what you want.
pub fn as_bool(self) -> Type {
pub fn as_bool(self) -> Self {
if !self.is_vector() {
B1
} else {
@@ -118,7 +118,7 @@ impl Type {
/// Get a type with the same number of lanes as this type, but with lanes that are half the
/// number of bits.
pub fn half_width(self) -> Option<Type> {
pub fn half_width(self) -> Option<Self> {
Some(self.replace_lanes(match self.lane_type() {
I16 => I8,
I32 => I16,
@@ -133,7 +133,7 @@ impl Type {
/// Get a type with the same number of lanes as this type, but with lanes that are twice the
/// number of bits.
pub fn double_width(self) -> Option<Type> {
pub fn double_width(self) -> Option<Self> {
Some(self.replace_lanes(match self.lane_type() {
I8 => I16,
I16 => I32,
@@ -235,7 +235,7 @@ impl Type {
///
/// If this is already a SIMD vector type, this produces a SIMD vector type with `n *
/// self.lane_count()` lanes.
pub fn by(self, n: u16) -> Option<Type> {
pub fn by(self, n: u16) -> Option<Self> {
if self.lane_bits() == 0 || !n.is_power_of_two() {
return None;
}
@@ -251,7 +251,7 @@ impl Type {
/// Get a SIMD vector with half the number of lanes.
///
/// There is no `double_vector()` method. Use `t.by(2)` instead.
pub fn half_vector(self) -> Option<Type> {
pub fn half_vector(self) -> Option<Self> {
if self.is_vector() {
Some(Type(self.0 - 0x10))
} else {
@@ -268,7 +268,7 @@ impl Type {
///
/// 1. `self.lane_count() == other.lane_count()` and
/// 2. `self.lane_bits() >= other.lane_bits()`
pub fn wider_or_equal(self, other: Type) -> bool {
pub fn wider_or_equal(self, other: Self) -> bool {
self.lane_count() == other.lane_count() && self.lane_bits() >= other.lane_bits()
}
}

View File

@@ -18,8 +18,8 @@ pub struct Encoding {
impl Encoding {
/// Create a new `Encoding` containing `(recipe, bits)`.
pub fn new(recipe: u16, bits: u16) -> Encoding {
Encoding { recipe, bits }
pub fn new(recipe: u16, bits: u16) -> Self {
Self { recipe, bits }
}
/// Get the recipe number in this encoding.
@@ -122,10 +122,10 @@ impl EncInfo {
///
/// Returns 0 for illegal encodings.
pub fn bytes(&self, enc: Encoding) -> CodeOffset {
self.sizing
.get(enc.recipe())
.map(|s| CodeOffset::from(s.bytes))
.unwrap_or(0)
self.sizing.get(enc.recipe()).map_or(
0,
|s| CodeOffset::from(s.bytes),
)
}
/// Get the branch range that is supported by `enc`, if any.

View File

@@ -24,8 +24,8 @@ struct Args {
}
impl Args {
fn new(bits: u16, enable_e: bool) -> Args {
Args {
fn new(bits: u16, enable_e: bool) -> Self {
Self {
pointer_bits: bits,
pointer_bytes: u32::from(bits) / 8,
pointer_type: Type::int(bits).unwrap(),

View File

@@ -23,10 +23,10 @@ pub struct StackRef {
impl StackRef {
/// Get a reference to the stack slot `ss` using one of the base pointers in `mask`.
pub fn masked(ss: StackSlot, mask: StackBaseMask, frame: &StackSlots) -> Option<StackRef> {
pub fn masked(ss: StackSlot, mask: StackBaseMask, frame: &StackSlots) -> Option<Self> {
// Try an SP-relative reference.
if mask.contains(StackBase::SP) {
return Some(StackRef::sp(ss, frame));
return Some(Self::sp(ss, frame));
}
// No reference possible with this mask.
@@ -34,7 +34,7 @@ impl StackRef {
}
/// Get a reference to `ss` using the stack pointer as a base.
pub fn sp(ss: StackSlot, frame: &StackSlots) -> StackRef {
pub fn sp(ss: StackSlot, frame: &StackSlots) -> Self {
let size = frame.frame_size.expect(
"Stack layout must be computed before referencing stack slots",
);
@@ -48,7 +48,7 @@ impl StackRef {
let sp_offset = -(size as StackOffset);
slot.offset.unwrap() - sp_offset
};
StackRef {
Self {
base: StackBase::SP,
offset,
}

View File

@@ -34,8 +34,8 @@ struct Args {
}
impl Args {
fn new(bits: u16, gpr: &'static [RU], fpr_limit: usize, call_conv: CallConv) -> Args {
Args {
fn new(bits: u16, gpr: &'static [RU], fpr_limit: usize, call_conv: CallConv) -> Self {
Self {
pointer_bytes: u32::from(bits) / 8,
pointer_bits: bits,
pointer_type: ir::Type::int(bits).unwrap(),
@@ -44,7 +44,7 @@ impl Args {
fpr_limit,
fpr_used: 0,
offset: 0,
call_conv: call_conv,
call_conv,
}
}
}
@@ -205,7 +205,7 @@ fn callee_saved_gprs_used(flags: &shared_settings::Flags, func: &ir::Function) -
}
used.intersect(&all_callee_saved);
return used;
used
}
pub fn prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> result::CtonResult {

View File

@@ -1,6 +1,7 @@
//! Cretonne code generation library.
#![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)]
#![warn(unused_import_braces, unstable_features)]
#![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))]
#![cfg_attr(feature="cargo-clippy", allow(
// Rustfmt 0.9.0 is at odds with this lint:
@@ -29,6 +30,16 @@
redundant_field_names,
useless_let_if_seq,
len_without_is_empty))]
#![cfg_attr(feature="cargo-clippy", warn(
float_arithmetic,
mut_mut,
nonminimal_bool,
option_map_unwrap_or,
option_map_unwrap_or_else,
print_stdout,
unicode_not_nfc,
use_self,
))]
// Turns on no_std and alloc features if std is not available.
#![cfg_attr(not(feature = "std"), no_std)]

View File

@@ -150,7 +150,7 @@ fn is_loop_invariant(inst: Inst, dfg: &DataFlowGraph, loop_values: &HashSet<Valu
return false;
}
}
return true;
true
}
// Traverses a loop in reverse post-order from a header EBB and identify loop-invariant
@@ -173,7 +173,7 @@ fn remove_loop_invariant_instructions(
}
pos.goto_top(*ebb);
#[cfg_attr(feature = "cargo-clippy", allow(block_in_if_condition_stmt))]
'next_inst: while let Some(inst) = pos.next_inst() {
while let Some(inst) = pos.next_inst() {
if is_loop_invariant(inst, &pos.func.dfg, &loop_values) {
// If all the instruction's argument are defined outside the loop
// then this instruction is loop-invariant

View File

@@ -32,9 +32,9 @@ struct LoopData {
impl LoopData {
/// Creates a `LoopData` object with the loop header and its eventual parent in the loop tree.
pub fn new(header: Ebb, parent: Option<Loop>) -> LoopData {
LoopData {
header: header,
pub fn new(header: Ebb, parent: Option<Loop>) -> Self {
Self {
header,
parent: parent.into(),
}
}

View File

@@ -19,7 +19,7 @@ pub enum Affinity {
///
/// This indicates a value that is not defined or used by any real instructions. It is a ghost
/// value that won't appear in the final program.
None,
Unassigned,
/// This value should be placed in a spill slot on the stack.
Stack,
@@ -30,16 +30,16 @@ pub enum Affinity {
impl Default for Affinity {
fn default() -> Self {
Affinity::None
Affinity::Unassigned
}
}
impl Affinity {
/// Create an affinity that satisfies a single constraint.
///
/// This will never create an `Affinity::None`.
/// This will never create an `Affinity::Unassigned`.
/// Use the `Default` implementation for that.
pub fn new(constraint: &OperandConstraint) -> Affinity {
pub fn new(constraint: &OperandConstraint) -> Self {
if constraint.kind == ConstraintKind::Stack {
Affinity::Stack
} else {
@@ -48,18 +48,18 @@ impl Affinity {
}
/// Create an affinity that matches an ABI argument for `isa`.
pub fn abi(arg: &AbiParam, isa: &TargetIsa) -> Affinity {
pub fn abi(arg: &AbiParam, isa: &TargetIsa) -> Self {
match arg.location {
ArgumentLoc::Unassigned => Affinity::None,
ArgumentLoc::Unassigned => Affinity::Unassigned,
ArgumentLoc::Reg(_) => Affinity::Reg(isa.regclass_for_abi_type(arg.value_type).into()),
ArgumentLoc::Stack(_) => Affinity::Stack,
}
}
/// Is this the `None` affinity?
pub fn is_none(self) -> bool {
/// Is this the `Unassigned` affinity?
pub fn is_unassigned(self) -> bool {
match self {
Affinity::None => true,
Affinity::Unassigned => true,
_ => false,
}
}
@@ -84,18 +84,18 @@ impl Affinity {
///
/// Note that this does not guarantee that the register allocator will pick a register that
/// satisfies the constraint.
pub fn merge(&mut self, constraint: &OperandConstraint, reg_info: &RegInfo) {
pub fn merge(&mut self, constraint: &OperandConstraint, reginfo: &RegInfo) {
match *self {
Affinity::None => *self = Affinity::new(constraint),
Affinity::Unassigned => *self = Self::new(constraint),
Affinity::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)
{
// If the register classes don't overlap, `intersect` returns `None`, and we
// just keep our previous affinity.
if let Some(subclass) = constraint.regclass.intersect_index(reg_info.rc(rc)) {
// If the register classes don't overlap, `intersect` returns `Unassigned`, and
// 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);
}
@@ -118,7 +118,7 @@ pub struct DisplayAffinity<'a>(Affinity, Option<&'a RegInfo>);
impl<'a> fmt::Display for DisplayAffinity<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.0 {
Affinity::None => write!(f, "none"),
Affinity::Unassigned => write!(f, "unassigned"),
Affinity::Stack => write!(f, "stack"),
Affinity::Reg(rci) => {
match self.1 {

View File

@@ -704,10 +704,10 @@ struct Node {
impl Node {
/// Create a node representing `value`.
pub fn value(value: Value, set_id: u8, func: &Function) -> Node {
pub fn value(value: Value, set_id: u8, func: &Function) -> Self {
let def = func.dfg.value_def(value).pp();
let ebb = func.layout.pp_ebb(def);
Node {
Self {
def,
ebb,
is_vcopy: false,
@@ -717,10 +717,10 @@ impl Node {
}
/// Create a node representing a virtual copy.
pub fn vcopy(branch: Inst, value: Value, set_id: u8, func: &Function) -> Node {
pub fn vcopy(branch: Inst, value: Value, set_id: u8, func: &Function) -> Self {
let def = branch.into();
let ebb = func.layout.pp_ebb(def);
Node {
Self {
def,
ebb,
is_vcopy: true,
@@ -891,8 +891,8 @@ struct VirtualCopies {
impl VirtualCopies {
/// Create an empty VirtualCopies struct.
pub fn new() -> VirtualCopies {
VirtualCopies {
pub fn new() -> Self {
Self {
params: Vec::new(),
branches: Vec::new(),
filter: Vec::new(),

View File

@@ -272,7 +272,7 @@ impl<'a> Context<'a> {
Affinity::Stack => debug_assert!(abi.location.is_stack()),
// This is a ghost value, unused in the function. Don't assign it to a location
// either.
Affinity::None => {}
Affinity::Unassigned => {}
}
}
@@ -1126,8 +1126,8 @@ struct AvailableRegs {
impl AvailableRegs {
/// Initialize both the input and global sets from `regs`.
pub fn new(regs: &RegisterSet) -> AvailableRegs {
AvailableRegs {
pub fn new(regs: &RegisterSet) -> Self {
Self {
input: regs.clone(),
global: regs.clone(),
}

View File

@@ -32,9 +32,9 @@ pub struct Diversion {
impl Diversion {
/// Make a new diversion.
pub fn new(value: Value, from: ValueLoc, to: ValueLoc) -> Diversion {
pub fn new(value: Value, from: ValueLoc, to: ValueLoc) -> Self {
debug_assert!(from.is_assigned() && to.is_assigned());
Diversion { value, from, to }
Self { value, from, to }
}
}

View File

@@ -179,7 +179,7 @@ use entity::SparseMap;
use flowgraph::ControlFlowGraph;
use ir::dfg::ValueDef;
use ir::{Ebb, Function, Inst, Layout, ProgramPoint, Value};
use isa::{EncInfo, TargetIsa};
use isa::{EncInfo, TargetIsa, OperandConstraint};
use regalloc::affinity::Affinity;
use regalloc::liverange::{LiveRange, LiveRangeContext, LiveRangeForest};
use std::mem;
@@ -197,7 +197,7 @@ fn get_or_create<'a>(
value: Value,
isa: &TargetIsa,
func: &Function,
enc_info: &EncInfo,
encinfo: &EncInfo,
) -> &'a mut LiveRange {
// It would be better to use `get_mut()` here, but that leads to borrow checker fighting
// which can probably only be resolved by non-lexical lifetimes.
@@ -211,7 +211,7 @@ fn get_or_create<'a>(
def = inst.into();
// Initialize the affinity from the defining instruction's result constraints.
// Don't do this for call return values which are always tied to a single register.
affinity = enc_info
affinity = encinfo
.operand_constraints(func.encodings[inst])
.and_then(|rc| rc.outs.get(rnum))
.map(Affinity::new)
@@ -385,8 +385,8 @@ impl Liveness {
self.ranges.clear();
// Get ISA data structures used for computing live range affinities.
let enc_info = isa.encoding_info();
let reg_info = isa.register_info();
let encinfo = isa.encoding_info();
let reginfo = isa.register_info();
// The liveness computation needs to visit all uses, but the order doesn't matter.
// TODO: Perhaps this traversal of the function could be combined with a dead code
@@ -397,7 +397,7 @@ impl Liveness {
// TODO: If these parameters are really dead, we could remove them, except for the
// entry block which must match the function signature.
for &arg in func.dfg.ebb_params(ebb) {
get_or_create(&mut self.ranges, arg, isa, func, &enc_info);
get_or_create(&mut self.ranges, arg, isa, func, &encinfo);
}
for inst in func.layout.ebb_insts(ebb) {
@@ -408,20 +408,18 @@ impl Liveness {
// TODO: When we implement DCE, we can use the absence of a live range to indicate
// an unused value.
for &def in func.dfg.inst_results(inst) {
get_or_create(&mut self.ranges, def, isa, func, &enc_info);
get_or_create(&mut self.ranges, def, isa, func, &encinfo);
}
// Iterator of constraints, one per value operand.
let encoding = func.encodings[inst];
let mut operand_constraints = enc_info
.operand_constraints(encoding)
.map(|c| c.ins)
.unwrap_or(&[])
.iter();
let operand_constraint_slice: &[OperandConstraint] =
encinfo.operand_constraints(encoding).map_or(&[], |c| c.ins);
let mut operand_constraints = operand_constraint_slice.iter();
for &arg in func.dfg.inst_args(inst) {
// Get the live range, create it as a dead range if necessary.
let lr = get_or_create(&mut self.ranges, arg, isa, func, &enc_info);
let lr = get_or_create(&mut self.ranges, arg, isa, func, &encinfo);
// Extend the live range to reach this use.
extend_to_use(
@@ -438,7 +436,7 @@ impl Liveness {
// operands described by `operand_constraints`. Variable arguments are either
// EBB arguments or call/return ABI arguments.
if let Some(constraint) = operand_constraints.next() {
lr.affinity.merge(constraint, &reg_info);
lr.affinity.merge(constraint, &reginfo);
}
}
}

View File

@@ -217,8 +217,8 @@ impl<PO: ProgramOrder> GenLiveRange<PO> {
/// Create a new live range for `value` defined at `def`.
///
/// The live range will be created as dead, but it can be extended with `extend_in_ebb()`.
pub fn new(value: Value, def: ProgramPoint, affinity: Affinity) -> GenLiveRange<PO> {
GenLiveRange {
pub fn new(value: Value, def: ProgramPoint, affinity: Affinity) -> Self {
Self {
value,
affinity,
def_begin: def,

View File

@@ -81,8 +81,8 @@ pub struct Pressure {
impl Pressure {
/// Create a new register pressure tracker.
pub fn new(reginfo: &RegInfo, usable: &RegisterSet) -> Pressure {
let mut p = Pressure {
pub fn new(reginfo: &RegInfo, usable: &RegisterSet) -> Self {
let mut p = Self {
aliased: 0,
toprc: Default::default(),
};

View File

@@ -103,7 +103,7 @@ impl RegisterSet {
/// of `other`.
///
/// This assumes that unused bits are 1.
pub fn interferes_with(&self, other: &RegisterSet) -> bool {
pub fn interferes_with(&self, other: &Self) -> bool {
self.avail.iter().zip(&other.avail).any(
|(&x, &y)| (x | y) != !0,
)
@@ -111,7 +111,7 @@ impl RegisterSet {
/// Intersect this set of registers with `other`. This has the effect of removing any register
/// units from this set that are not in `other`.
pub fn intersect(&mut self, other: &RegisterSet) {
pub fn intersect(&mut self, other: &Self) {
for (x, &y) in self.avail.iter_mut().zip(&other.avail) {
*x &= y;
}

View File

@@ -219,7 +219,7 @@ impl<'a> Context<'a> {
self.reloads.insert(ReloadedValue {
stack: cand.value,
reg: reg,
reg,
});
cand.value = reg;

View File

@@ -151,8 +151,8 @@ pub struct Variable {
}
impl Variable {
fn new_live(value: Value, constraint: RegClass, from: RegUnit, is_output: bool) -> Variable {
Variable {
fn new_live(value: Value, constraint: RegClass, from: RegUnit, is_output: bool) -> Self {
Self {
value,
constraint,
from: Some(from),
@@ -164,8 +164,8 @@ impl Variable {
}
}
fn new_def(value: Value, constraint: RegClass, is_global: bool) -> Variable {
Variable {
fn new_def(value: Value, constraint: RegClass, is_global: bool) -> Self {
Self {
value,
constraint,
from: None,
@@ -280,7 +280,7 @@ pub enum Move {
impl Move {
/// Create a register move from an assignment, but not for identity assignments.
fn with_assignment(a: &Assignment) -> Option<Move> {
fn with_assignment(a: &Assignment) -> Option<Self> {
if a.from != a.to {
Some(Move::Reg {
value: a.value,

View File

@@ -363,7 +363,7 @@ impl<'a> Context<'a> {
self.cur.isa.regclass_for_abi_type(abi.value_type).into(),
true,
),
Affinity::None => panic!("Missing affinity for {}", arg),
Affinity::Unassigned => panic!("Missing affinity for {}", arg),
};
let mut reguse = RegUse::new(arg, fixed_args + idx, rci);
reguse.fixed = true;
@@ -393,10 +393,9 @@ impl<'a> Context<'a> {
} else if ru.fixed {
// This is a fixed register use which doesn't necessarily require a copy.
// Make a copy only if this is not the first use of the value.
self.reg_uses
.get(i.wrapping_sub(1))
.map(|ru2| ru2.value == ru.value)
.unwrap_or(false)
self.reg_uses.get(i.wrapping_sub(1)).map_or(false, |ru2| {
ru2.value == ru.value
})
} else {
false
};
@@ -567,8 +566,8 @@ struct RegUse {
}
impl RegUse {
fn new(value: Value, idx: usize, rci: RegClassIndex) -> RegUse {
RegUse {
fn new(value: Value, idx: usize, rci: RegClassIndex) -> Self {
Self {
value,
opidx: idx as u16,
rci,

View File

@@ -101,10 +101,9 @@ impl VirtRegs {
where
'a: 'b,
{
self.get(*value).map(|vr| self.values(vr)).unwrap_or_else(
|| {
ref_slice(value)
},
self.get(*value).map_or_else(
|| ref_slice(value),
|vr| self.values(vr),
)
}
@@ -257,7 +256,7 @@ enum UFEntry {
/// A singleton set is the same as a set with rank 0. It contains only the leader value.
impl UFEntry {
/// Decode a table entry.
fn decode(x: i32) -> UFEntry {
fn decode(x: i32) -> Self {
if x < 0 {
UFEntry::Link(Value::new((!x) as usize))
} else {

View File

@@ -45,7 +45,7 @@ pub enum CtonError {
pub type CtonResult = Result<(), CtonError>;
impl From<verifier::Error> for CtonError {
fn from(e: verifier::Error) -> CtonError {
fn from(e: verifier::Error) -> Self {
CtonError::Verifier(e)
}
}

View File

@@ -50,8 +50,8 @@ pub struct Builder {
impl Builder {
/// Create a new builder with defaults and names from the given template.
pub fn new(tmpl: &'static detail::Template) -> Builder {
Builder {
pub fn new(tmpl: &'static detail::Template) -> Self {
Self {
template: tmpl,
bytes: tmpl.defaults.into(),
}

View File

@@ -102,8 +102,7 @@ impl<'a> FlagsVerifier<'a> {
if self.encinfo
.as_ref()
.and_then(|ei| ei.operand_constraints(self.func.encodings[inst]))
.map(|c| c.clobbers_flags)
.unwrap_or(false) && live_val.is_some()
.map_or(false, |c| c.clobbers_flags) && live_val.is_some()
{
return err!(inst, "encoding clobbers live CPU flags in {}", live);
}

View File

@@ -78,7 +78,7 @@ impl<'a> LivenessVerifier<'a> {
if encoding.is_legal() {
// A legal instruction is not allowed to define ghost values.
if lr.affinity.is_none() {
if lr.affinity.is_unassigned() {
return err!(
inst,
"{} is a ghost value defined by a real [{}] instruction",
@@ -86,7 +86,7 @@ impl<'a> LivenessVerifier<'a> {
self.isa.encoding_info().display(encoding)
);
}
} else if !lr.affinity.is_none() {
} else if !lr.affinity.is_unassigned() {
// A non-encoded instruction can only define ghost values.
return err!(
inst,
@@ -108,7 +108,7 @@ impl<'a> LivenessVerifier<'a> {
}
// A legal instruction is not allowed to depend on ghost values.
if encoding.is_legal() && lr.affinity.is_none() {
if encoding.is_legal() && lr.affinity.is_unassigned() {
return err!(
inst,
"{} is a ghost value used by a real [{}] instruction",

View File

@@ -200,7 +200,7 @@ impl<'a> Verifier<'a> {
);
}
if is_last_inst && !is_terminator {
return err!(ebb, "block does not end in a terminator instruction!");
return err!(ebb, "block does not end in a terminator instruction");
}
// Instructions belong to the correct ebb.
@@ -237,9 +237,9 @@ impl<'a> Verifier<'a> {
let fixed_results = inst_data.opcode().constraints().fixed_results();
// var_results is 0 if we aren't a call instruction
let var_results = dfg.call_signature(inst)
.map(|sig| dfg.signatures[sig].returns.len())
.unwrap_or(0);
let var_results = dfg.call_signature(inst).map_or(0, |sig| {
dfg.signatures[sig].returns.len()
});
let total_results = fixed_results + var_results;
// All result values for multi-valued instructions are created
@@ -1156,7 +1156,7 @@ mod tests {
macro_rules! assert_err_with_msg {
($e:expr, $msg:expr) => {
match $e {
Ok(_) => panic!("Expected an error!"),
Ok(_) => panic!("Expected an error"),
Err(Error { message, .. }) => {
if !message.contains($msg) {
#[cfg(feature = "std")]

View File

@@ -22,7 +22,7 @@ pub fn write_function(w: &mut Write, func: &Function, isa: Option<&TargetIsa>) -
let mut any = write_preamble(w, func, regs)?;
for ebb in &func.layout {
if any {
writeln!(w, "")?;
writeln!(w)?;
}
write_ebb(w, func, isa, ebb)?;
any = true;
@@ -258,7 +258,7 @@ fn write_instruction(
}
write_operands(w, &func.dfg, isa, inst)?;
writeln!(w, "")
writeln!(w)
}
/// Write the operands of `inst` to `w` with a prepended space.