Skip to content

Commit c3a249d

Browse files
committed
Implement Tarjan's strongly-connected components algorithm
This commit implements [Tarjan's algorithm] for finding strongly-connected components. This algorithm takes `O(V+E)` time and uses `O(V+E)` space. Tarjan's algorithm is usually presented as a recursive algorithm, but we do not trust the input and cannot recurse over it for fear of blowing the stack. Therefore, this implementation is iterative. This will be used to do bottom-up inlining in Wasmtime's compilation orchestration. [Tarjan's algorithm]: https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm
1 parent 4b51827 commit c3a249d

File tree

3 files changed

+539
-1
lines changed

3 files changed

+539
-1
lines changed

cranelift/entity/src/set.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Densely numbered entity references as set keys.
22
3-
use crate::EntityRef;
43
use crate::keys::Keys;
4+
use crate::EntityRef;
55
use core::fmt;
66
use core::marker::PhantomData;
77
use cranelift_bitset::CompoundBitSet;
@@ -148,6 +148,14 @@ where
148148
self.bitset.insert(index)
149149
}
150150

151+
/// Remove `k` from this bitset.
152+
///
153+
/// Returns whether `k` was previously in this set or not.
154+
pub fn remove(&mut self, k: K) -> bool {
155+
let index = k.index();
156+
self.bitset.remove(index)
157+
}
158+
151159
/// Removes and returns the entity from the set if it exists.
152160
pub fn pop(&mut self) -> Option<K> {
153161
let index = self.bitset.pop()?;

crates/wasmtime/src/compile.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ use wasmtime_environ::{
4343
StaticModuleIndex,
4444
};
4545

46+
mod scc;
47+
4648
mod code_builder;
4749
pub use self::code_builder::{CodeBuilder, CodeHint, HashedEngineCompileEnv};
4850

0 commit comments

Comments
 (0)