Skip to content

Commit

Permalink
Use fx hash instead of default hash for index sets
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-hartl committed Jul 9, 2024
1 parent 7e206c3 commit bc03421
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 22 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ members = [
"ir/crates/front",
"ir/crates/middle",
"lang"
,
"crates/fxindexmap"
]

[profile.release]
Expand Down
8 changes: 8 additions & 0 deletions crates/fxindexmap/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "fxindexmap"
version = "0.0.0"
edition = "2021"

[dependencies]
fxhash = "0.2.1"
indexmap = "2.2.6"
5 changes: 5 additions & 0 deletions crates/fxindexmap/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use fxhash::FxBuildHasher;
pub use indexmap::*;

pub type FxIndexMap<K, V> = IndexMap<K, V, FxBuildHasher>;
pub type FxIndexSet<T> = IndexSet<T, FxBuildHasher>;
4 changes: 2 additions & 2 deletions ir/crates/middle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ edition = "2021"
[dependencies]
tracing = "0.1.40"
rustc-hash = "1.1.0"
strum = { version = "0.26.1",features = ["derive"]}
strum = { version = "0.26.1", features = ["derive"] }
strum_macros = "0.26.1"
tracing-test = "0.2.4"
petgraph = "0.6.4"
smallvec = "1.13.1"
natrix_front = { path = "../front" }
log = "0.4.20"
slotmap = "1.0.7"
indexmap = "2.2.6"
fxindexmap = { path = "../../../crates/fxindexmap" }
itertools = "0.13.0"
derive_more = "0.99.18"
10 changes: 4 additions & 6 deletions ir/crates/middle/src/analysis/dataflow/backward.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use std::collections::VecDeque;

use indexmap::IndexSet;

use crate::{
analysis::dataflow::{Analysis, DFState, InstrWalker},
cfg::BasicBlockRef,
Function, Instr,
};
use fxindexmap::FxIndexSet;
use std::collections::VecDeque;
pub struct BackwardAnalysisRunner<'a, A: Analysis> {
pub state: DFState<A::V>,
visited: IndexSet<BasicBlockRef>,
visited: FxIndexSet<BasicBlockRef>,
worklist: VecDeque<BasicBlockRef>,
pub function: &'a mut Function,
_analysis: std::marker::PhantomData<A>,
Expand All @@ -19,7 +17,7 @@ impl<'a, A: Analysis> BackwardAnalysisRunner<'a, A> {
let worklist = function.cfg.dfs_postorder().collect();
Self {
worklist,
visited: IndexSet::default(),
visited: FxIndexSet::default(),
state: DFState::new(),
function,
_analysis: std::marker::PhantomData,
Expand Down
7 changes: 3 additions & 4 deletions ir/crates/middle/src/analysis/dataflow/forward.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use indexmap::IndexSet;

use crate::{
analysis::dataflow::{Analysis, DFState, InstrWalker},
cfg::BasicBlockRef,
Function, Instr,
};
use fxindexmap::FxIndexSet;

pub struct ForwardAnalysisRunner<'a, A: Analysis> {
pub state: DFState<A::V>,
visited: IndexSet<BasicBlockRef>,
visited: FxIndexSet<BasicBlockRef>,
worklist: Vec<BasicBlockRef>,
pub function: &'a mut Function,
_analysis: std::marker::PhantomData<A>,
Expand All @@ -18,7 +17,7 @@ impl<'a, A: Analysis> ForwardAnalysisRunner<'a, A> {
pub fn new(function: &'a mut Function) -> Self {
Self {
worklist: vec![function.cfg.entry_block_ref()],
visited: IndexSet::default(),
visited: FxIndexSet::default(),
state: DFState::new(),
function,
_analysis: std::marker::PhantomData,
Expand Down
19 changes: 9 additions & 10 deletions ir/crates/middle/src/cfg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@

use std::fmt::{Debug, Display, Formatter};

use crate::{
instruction::{Instr, Op},
InstrKind, Type, Value,
};
pub use builder::Builder;
pub use domtree::DomTree;
use indexmap::IndexSet;
use fxindexmap::FxIndexSet;
#[allow(unused_imports)]
pub use petgraph::{prelude::*, visit::Walker};
use slotmap::{new_key_type, SlotMap};
use smallvec::SmallVec;

use crate::{
instruction::{Instr, Op},
InstrKind, Type, Value,
};

mod builder;
mod domtree;

Expand Down Expand Up @@ -243,8 +242,8 @@ impl Display for BBArg {
#[derive(Debug, Clone)]
pub struct BasicBlock {
pub id: BasicBlockRef,
pub arguments: IndexSet<BBArgRef>,
pub instructions: IndexSet<InstrRef>,
pub arguments: FxIndexSet<BBArgRef>,
pub instructions: FxIndexSet<InstrRef>,
pub terminator: Option<Terminator>,
node_index: NodeIndex,
pub symbol: String,
Expand All @@ -254,8 +253,8 @@ impl BasicBlock {
pub fn new(id: BasicBlockRef, graph_index: NodeIndex, symbol: String) -> Self {
Self {
id,
arguments: IndexSet::new(),
instructions: IndexSet::new(),
arguments: FxIndexSet::default(),
instructions: FxIndexSet::default(),
symbol,
node_index: graph_index,
terminator: None,
Expand Down

0 comments on commit bc03421

Please sign in to comment.