Skip to content

Commit 0891cc9

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 0891cc9

File tree

3 files changed

+538
-0
lines changed

3 files changed

+538
-0
lines changed

cranelift/entity/src/set.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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)