From f5231e0677e51c7aa8ec767b7f184b3d9bb85128 Mon Sep 17 00:00:00 2001 From: Mel Henning Date: Mon, 12 May 2025 14:58:49 -0400 Subject: [PATCH] nak: Also use rustc-hash for UnionFind Part-of: --- src/nouveau/compiler/nak/assign_regs.rs | 4 ++-- src/nouveau/compiler/nak/repair_ssa.rs | 4 ++-- src/nouveau/compiler/nak/union_find.rs | 28 +++++++++++++------------ 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/nouveau/compiler/nak/assign_regs.rs b/src/nouveau/compiler/nak/assign_regs.rs index 5c3eee9ff3c..e0cbaa2b2e0 100644 --- a/src/nouveau/compiler/nak/assign_regs.rs +++ b/src/nouveau/compiler/nak/assign_regs.rs @@ -7,7 +7,7 @@ use crate::liveness::{BlockLiveness, Liveness, SimpleLiveness}; use crate::union_find::UnionFind; use compiler::bitset::BitSet; -use rustc_hash::{FxHashMap, FxHashSet}; +use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet}; use std::cmp::{max, min, Ordering}; struct KillSet { @@ -164,7 +164,7 @@ impl SSAUseMap { /// Architectures and Synthesis for Embedded Systems (CASES), Taipei, /// Taiwan, 2011, pp. 45-54, doi: 10.1145/2038698.2038708. struct PhiWebs { - uf: UnionFind, + uf: UnionFind, assignments: FxHashMap, } diff --git a/src/nouveau/compiler/nak/repair_ssa.rs b/src/nouveau/compiler/nak/repair_ssa.rs index e1b38677453..d33cba15506 100644 --- a/src/nouveau/compiler/nak/repair_ssa.rs +++ b/src/nouveau/compiler/nak/repair_ssa.rs @@ -5,7 +5,7 @@ use crate::ir::*; use crate::union_find::UnionFind; use compiler::bitset::BitSet; -use rustc_hash::FxHashMap; +use rustc_hash::{FxBuildHasher, FxHashMap}; use std::cell::RefCell; use std::cmp::Reverse; use std::collections::BinaryHeap; @@ -257,7 +257,7 @@ impl Function { // For loop back-edges, we inserted a phi whether we need one or not. // We want to eliminate any redundant phis. - let mut ssa_map = UnionFind::new(); + let mut ssa_map = UnionFind::::new(); if cfg.has_loop() { let mut to_do = true; while to_do { diff --git a/src/nouveau/compiler/nak/union_find.rs b/src/nouveau/compiler/nak/union_find.rs index fb727ec6669..360c858109e 100644 --- a/src/nouveau/compiler/nak/union_find.rs +++ b/src/nouveau/compiler/nak/union_find.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: MIT use std::collections::HashMap; -use std::hash::Hash; +use std::hash::{BuildHasher, Hash}; #[derive(Copy, Clone)] struct Root { @@ -24,12 +24,12 @@ enum Node { /// Robert E. Tarjan and Jan van Leeuwen. 1984. Worst-case Analysis of Set /// Union Algorithms. J. ACM 31, 2 (April 1984), 245–281. /// -pub struct UnionFind { - idx_map: HashMap, +pub struct UnionFind { + idx_map: HashMap, nodes: Vec>, } -impl UnionFind { +impl UnionFind { /// Create a new union-find structure /// /// At initialization, each possible value is in its own set @@ -128,7 +128,9 @@ mod tests { use crate::union_find::Node; use crate::union_find::UnionFind; use std::cmp::max; + use std::hash::BuildHasher; use std::hash::Hash; + use std::hash::RandomState; fn ceil_log2(x: usize) -> u32 { assert!(x > 0); @@ -140,13 +142,13 @@ mod tests { size: usize, } - pub struct HeightCalc<'a, X: Copy + Hash + Eq> { - uf: &'a UnionFind, + pub struct HeightCalc<'a, X: Copy + Hash + Eq, H: BuildHasher + Default> { + uf: &'a UnionFind, downward_edges: Vec>, } - impl<'a, X: Copy + Hash + Eq> HeightCalc<'a, X> { - fn new(uf: &'a UnionFind) -> Self { + impl<'a, X: Copy + Hash + Eq, H: BuildHasher + Default> HeightCalc<'a, X, H> { + fn new(uf: &'a UnionFind) -> Self { let mut downward_edges: Vec> = uf.nodes.iter().map(|_| Vec::new()).collect(); for (i, node) in uf.nodes.iter().enumerate() { @@ -194,14 +196,14 @@ mod tests { return max_height; } - pub fn check(uf: &'a UnionFind) -> u32 { + pub fn check(uf: &'a UnionFind) -> u32 { HeightCalc::new(uf).check_roots() } } #[test] fn test_basic() { - let mut f = UnionFind::new(); + let mut f = UnionFind::::new(); assert_eq!(f.find(10), 10); assert_eq!(f.find(12), 12); @@ -241,7 +243,7 @@ mod tests { #[test] fn test_chain_a_height() { - let mut f = UnionFind::new(); + let mut f = UnionFind::::new(); for i in 0..1000 { f.union(i, i + 1); HeightCalc::check(&f); @@ -251,7 +253,7 @@ mod tests { #[test] fn test_chain_b_height() { - let mut f = UnionFind::new(); + let mut f = UnionFind::::new(); for i in 0..1000 { f.union(i + 1, i); HeightCalc::check(&f); @@ -264,7 +266,7 @@ mod tests { let height = 8; let count = 1 << height; - let mut f = UnionFind::new(); + let mut f = UnionFind::::new(); for current_height in 0..height { let stride = 1 << current_height; for i in (0..count).step_by(2 * stride) {