Skip to content

Commit

Permalink
Lesson 5: Global Analysis & SSA
Browse files Browse the repository at this point in the history
Completed SSA construction routines
  • Loading branch information
kevinjoseph1995 committed Dec 24, 2024
1 parent d337c9f commit 7b67c1d
Show file tree
Hide file tree
Showing 4 changed files with 436 additions and 4 deletions.
1 change: 1 addition & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ indoc = "2.0.5"
serde_json = "1.0"
smallstr = "0.3.0"
smallvec = "1.13.2"
brilirs = { version = "0.1.0", path = "../bril/brilirs" }

[dependencies.bril-rs]
version = "0.1.0"
Expand Down
11 changes: 8 additions & 3 deletions common/src/cfg.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub mod ssa;

use bril_rs::Function;
use std::{
collections::{HashMap, HashSet},
Expand All @@ -23,10 +25,12 @@ struct Node<Data: NodeEntry> {
predecessor_indices: SmallVec<[usize; 2]>,
}

#[derive(Debug, Clone)]
pub struct DirectedGraph<Data: NodeEntry> {
nodes: Vec<Node<Data>>,
}

#[derive(Debug, Clone)]
pub struct Cfg {
pub dag: DirectedGraph<BasicBlock>,
pub function_name: String,
Expand Down Expand Up @@ -223,6 +227,9 @@ impl Cfg {
pub fn get_basic_block(&self, index: NodeIndex) -> &BasicBlock {
&self.dag.nodes[index].data
}
pub fn get_basic_block_mut(&mut self, index: NodeIndex) -> &mut BasicBlock {
&mut self.dag.nodes.get_mut(index).unwrap().data
}
}

impl<'a> Dominators<'a> {
Expand Down Expand Up @@ -344,11 +351,9 @@ impl<'a> Dominators<'a> {

#[cfg(test)]
mod tests {
use super::*;
use bril_rs::Program;
use indoc::indoc;

use super::*;

use std::sync::LazyLock;

static PROGRAM: LazyLock<Program> = LazyLock::new(|| {
Expand Down
Loading

0 comments on commit 7b67c1d

Please sign in to comment.