Skip to content

Commit

Permalink
Run cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-hartl committed Mar 29, 2024
1 parent 7c4498e commit ad2e030
Show file tree
Hide file tree
Showing 24 changed files with 140 additions and 123 deletions.
4 changes: 2 additions & 2 deletions ir/crates/back/src/codegen/machine/abi/calling_convention.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::codegen::{
pub trait CallingConvention {
type Reg: machine::PhysicalRegister;

fn parameter_slots(params: impl Iterator<Item=Size>)
-> impl Iterator<Item=Slot<Self::Reg>>;
fn parameter_slots(params: impl Iterator<Item = Size>)
-> impl Iterator<Item = Slot<Self::Reg>>;

fn return_slot(size: Size) -> Slot<Self::Reg>;
}
Expand Down
2 changes: 1 addition & 1 deletion ir/crates/back/src/codegen/machine/abi/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub use calling_convention::CallingConvention;

pub mod calling_convention;
pub mod calling_convention;
4 changes: 2 additions & 2 deletions ir/crates/back/src/codegen/machine/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ use crate::codegen::{
},
Function,
},
Instr,
TargetMachine,
},
selection_dag::Immediate,
};
use crate::codegen::machine::Instr;

type Reg<B> = <<B as Backend>::TM as TargetMachine>::Reg;
type BackInstr<B> = <<B as Backend>::TM as TargetMachine>::Instr;

pub trait Backend {
type TM: TargetMachine;

type P: Pattern<TM=Self::TM>;
type P: Pattern<TM = Self::TM>;

fn patterns() -> &'static [Self::P];

Expand Down
20 changes: 10 additions & 10 deletions ir/crates/back/src/codegen/machine/function/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ use daggy::{
petgraph::prelude::Bfs,
Walker,
};
use natrix_middle::instruction::CmpOp;
use rustc_hash::FxHashMap;
use tracing::debug;

use natrix_middle::instruction::CmpOp;

use crate::codegen::{
machine::{
backend::{
Expand All @@ -21,6 +20,7 @@ use crate::codegen::{
InstrOperand,
PseudoInstr,
},
Instr,
MachInstr,
Register,
Size,
Expand All @@ -35,7 +35,6 @@ use crate::codegen::{
PseudoOp,
},
};
use crate::codegen::machine::Instr;

#[derive(Debug)]
pub struct FunctionBuilder<TM: TargetMachine> {
Expand Down Expand Up @@ -101,9 +100,13 @@ impl<TM: TargetMachine> FunctionBuilder<TM> {
)));
}
PseudoOp::Phi(dest, operands) => {
self.function.basic_blocks[mbb_id].add_phi(*dest, operands.iter().map(
|(reg, bb)| (*reg, self.bb_mapping[bb])
).collect());
self.function.basic_blocks[mbb_id].add_phi(
*dest,
operands
.iter()
.map(|(reg, bb)| (*reg, self.bb_mapping[bb]))
.collect(),
);
}
PseudoOp::Def(reg) => {
instructions
Expand Down Expand Up @@ -225,10 +228,7 @@ impl<TM: TargetMachine> FunctionBuilder<TM> {
mbb
}

fn operand_to_matched_pattern_operand(
&self,
src: &Operand<TM>,
) -> MatchedPatternOperand<TM> {
fn operand_to_matched_pattern_operand(&self, src: &Operand<TM>) -> MatchedPatternOperand<TM> {
match src {
Operand::Reg(reg) => MatchedPatternOperand::Reg(*reg),
Operand::Imm(imm) => MatchedPatternOperand::Imm(imm.clone()),
Expand Down
19 changes: 9 additions & 10 deletions ir/crates/back/src/codegen/machine/function/cfg.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use daggy::{
NodeIndex,
petgraph::{
Directed,
Direction,
prelude::{
Bfs,
DfsPostOrder,
StableGraph,
},
Directed,
Direction,
},
NodeIndex,
Walker,
};
use index_vec::IndexVec;
Expand All @@ -17,17 +17,16 @@ use rustc_hash::FxHashMap;

use crate::codegen::{
machine::{
Instr,
instr::InstrOperand,
Instr,
InstrId,
MachInstr,
Register,
TargetMachine,
},
register_allocator::{
InstrNumbering,
InstrUid
,
InstrUid,
ProgPoint,
},
};
Expand Down Expand Up @@ -85,25 +84,25 @@ impl Cfg {
}

/// Traverses the cfg using a post order depth first traversal
pub fn dfs_postorder(&self) -> impl Iterator<Item=BasicBlockId> + '_ {
pub fn dfs_postorder(&self) -> impl Iterator<Item = BasicBlockId> + '_ {
DfsPostOrder::new(&self.graph, self.entry_node())
.iter(&self.graph)
.map(|node| self.node_to_block_map[&node])
}

pub fn bfs(&self) -> impl Iterator<Item=BasicBlockId> + '_ {
pub fn bfs(&self) -> impl Iterator<Item = BasicBlockId> + '_ {
Bfs::new(&self.graph, self.entry_node())
.iter(&self.graph)
.map(|node| self.node_to_block_map[&node])
}

pub fn predecessors(&self, bb: BasicBlockId) -> impl Iterator<Item=BasicBlockId> + '_ {
pub fn predecessors(&self, bb: BasicBlockId) -> impl Iterator<Item = BasicBlockId> + '_ {
self.graph
.neighbors_directed(self.block_to_node_map[&bb], Direction::Incoming)
.map(|node| self.node_to_block_map[&node])
}

pub fn successors(&self, bb: BasicBlockId) -> impl Iterator<Item=BasicBlockId> + '_ {
pub fn successors(&self, bb: BasicBlockId) -> impl Iterator<Item = BasicBlockId> + '_ {
self.graph
.neighbors(self.block_to_node_map[&bb])
.map(|node| self.node_to_block_map[&node])
Expand Down
11 changes: 6 additions & 5 deletions ir/crates/back/src/codegen/machine/instr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ use smallvec::{
};

use crate::codegen::{
machine::Register,
machine::{
function::BasicBlockId,
isa::MachInstr as MInstr,
Register,
TargetMachine,
},
selection_dag::Immediate,
};
use crate::codegen::machine::function::BasicBlockId;
use crate::codegen::machine::isa::MachInstr as MInstr;
use crate::codegen::machine::TargetMachine;

index_vec::define_index_type! {
pub struct InstrId = u32;
Expand Down Expand Up @@ -97,7 +99,6 @@ impl<TM: TargetMachine> Instr<TM> {
Instr::Machine(machine) => Some(machine),
}
}

}

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
Expand Down
16 changes: 8 additions & 8 deletions ir/crates/back/src/codegen/machine/isa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::codegen::machine::{
instr::InstrOperand,
reg::Register,
Size,
TargetMachine,
};
use crate::codegen::machine::TargetMachine;

pub trait PhysicalRegister: Debug + Clone + Copy + PartialEq + Eq + Sized + Hash + 'static {
fn name(&self) -> &'static str;
Expand All @@ -30,9 +30,9 @@ pub trait PhysicalRegister: Debug + Clone + Copy + PartialEq + Eq + Sized + Hash

fn superregs(&self) -> Option<&'static [Self]>;

fn regclass(&self) -> impl Iterator<Item=Self>
where
Self: 'static,
fn regclass(&self) -> impl Iterator<Item = Self>
where
Self: 'static,
{
self.subregs()
.into_iter()
Expand All @@ -43,16 +43,16 @@ pub trait PhysicalRegister: Debug + Clone + Copy + PartialEq + Eq + Sized + Hash
}

fn has_subreg(&self, other: Self) -> bool
where
Self: 'static,
where
Self: 'static,
{
self.subregs()
.map_or(false, |subregs| subregs.contains(&other))
}

fn interferes_with(self, other: Self) -> bool
where
Self: 'static,
where
Self: 'static,
{
if self == other {
return true;
Expand Down
17 changes: 9 additions & 8 deletions ir/crates/back/src/codegen/machine/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::fmt::Debug;

pub use cranelift_entity::EntityRef;

pub use backend::Backend;
pub use cranelift_entity::EntityRef;
pub use function::{
Function,
FunctionId,
Expand All @@ -22,8 +21,10 @@ pub use reg::{
VReg,
};

use crate::codegen::machine::abi::CallingConvention;
use crate::codegen::machine::asm::Assembler;
use crate::codegen::machine::{
abi::CallingConvention,
asm::Assembler,
};

pub mod abi;
pub mod asm;
Expand Down Expand Up @@ -98,13 +99,13 @@ pub enum Architecture {
pub trait TargetMachine: Debug + Default + Copy + Clone + PartialEq + Eq {
type Reg: PhysicalRegister;

type Instr: MachInstr<TM=Self>;
type Instr: MachInstr<TM = Self>;

type CallingConvention: CallingConvention<Reg=Self::Reg>;
type CallingConvention: CallingConvention<Reg = Self::Reg>;

type Backend: Backend<TM=Self>;
type Backend: Backend<TM = Self>;

type Assembler: Assembler<TM=Self>;
type Assembler: Assembler<TM = Self>;

fn endianness() -> Endianness;

Expand Down
6 changes: 5 additions & 1 deletion ir/crates/back/src/codegen/machine/module/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ use std::ops::Range;

use cranelift_entity::SecondaryMap;

use crate::codegen::machine::{FunctionId, Module, TargetMachine};
use crate::codegen::machine::{
FunctionId,
Module,
TargetMachine,
};

#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct FunctionSymbolTableEntry {
Expand Down
2 changes: 1 addition & 1 deletion ir/crates/back/src/codegen/machine/module/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::codegen::machine::{
backend::Backend,
function::builder::FunctionBuilder,
Module,
TargetMachine,
};
use crate::codegen::machine::TargetMachine;

#[derive(Debug)]
pub struct Builder<'module, TM: TargetMachine> {
Expand Down
16 changes: 9 additions & 7 deletions ir/crates/back/src/codegen/machine/module/mod.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
pub use asm::AsmModule;
use asm::{
FunctionSymbolTable,
FunctionSymbolTableEntry,
};
pub use builder::Builder;
use cranelift_entity::PrimaryMap;
use tracing::{
debug,
info,
};

use asm::{FunctionSymbolTable, FunctionSymbolTableEntry};
pub use asm::AsmModule;
pub use builder::Builder;

use crate::codegen::{
machine::{
backend::Backend,
function::{
Function,
FunctionId,
},
TargetMachine,
},
register_allocator,
register_allocator::RegAllocAlgorithm,
};
use crate::codegen::machine::TargetMachine;

mod builder;
pub mod asm;
mod builder;

#[derive(Debug, Clone)]
pub struct Module<TM: TargetMachine> {
Expand All @@ -42,7 +44,7 @@ impl<TM: TargetMachine> Module<TM> {
self.functions.push(function)
}

pub fn functions(&self) -> impl ExactSizeIterator<Item=(FunctionId, &Function<TM>)> {
pub fn functions(&self) -> impl ExactSizeIterator<Item = (FunctionId, &Function<TM>)> {
self.functions.iter()
}

Expand Down
7 changes: 6 additions & 1 deletion ir/crates/back/src/codegen/machine/reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ use std::fmt::{

use cranelift_entity::entity_impl;

use crate::codegen::machine::{function::Function, isa::PhysicalRegister, Size, TargetMachine};
use crate::codegen::machine::{
function::Function,
isa::PhysicalRegister,
Size,
TargetMachine,
};

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Register<TM: TargetMachine> {
Expand Down
2 changes: 1 addition & 1 deletion ir/crates/back/src/codegen/register_allocator/coalescer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::codegen::machine::{
PseudoInstr,
},
Module,
TargetMachine,
};
use crate::codegen::machine::TargetMachine;

pub struct Coalescer<'module, TM: TargetMachine> {
module: &'module mut Module<TM>,
Expand Down
3 changes: 2 additions & 1 deletion ir/crates/back/src/codegen/register_allocator/linear_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use crate::codegen::{
machine::{
isa::PhysicalRegister,
Size,
TargetMachine,
VReg,
},
register_allocator::{
LiveRange,
Expand All @@ -15,7 +17,6 @@ use crate::codegen::{
RegAllocVReg,
},
};
use crate::codegen::machine::{TargetMachine, VReg};

#[derive(Debug)]
pub struct RegAlloc<'liveness, TM: TargetMachine> {
Expand Down
Loading

0 comments on commit ad2e030

Please sign in to comment.