Skip to content
This repository was archived by the owner on Jan 7, 2022. It is now read-only.

Commit 8b14ea1

Browse files
committed
Remove SSA code.
In hindsight, we've decided we probably don't need TIR to be in SSA. Not all is lost. We have the algorithms in the Git history, so we can refer to it later if we need it (either at runtime, or compile time).
1 parent 3fc4a57 commit 8b14ea1

File tree

5 files changed

+6
-78
lines changed

5 files changed

+6
-78
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3062,7 +3062,6 @@ version = "0.0.0"
30623062
name = "rustc_yk_sections"
30633063
version = "0.0.0"
30643064
dependencies = [
3065-
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
30663065
"rustc 0.0.0",
30673066
"rustc_codegen_utils 0.0.0",
30683067
"rustc_data_structures 0.0.0",

src/librustc_yk_sections/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@ rustc_yk_link = { path = "../librustc_yk_link" }
1515
ykpack = { git = "https://github.com/softdevteam/ykpack" }
1616
rustc_codegen_utils = { path = "../librustc_codegen_utils" }
1717
rustc_data_structures = { path = "../librustc_data_structures" }
18-
log = "0.4.5"

src/librustc_yk_sections/emit_tir.rs

Lines changed: 5 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10-
//! This module converts MIR into Yorick TIR (Tracing IR). TIR is more suitable for the run-time
11-
//! tracer: TIR (unlike MIR) is in SSA form (but it does preserve MIR's block structure).
10+
//! This module converts MIR into Yorick TIR (Tracing IR).
11+
//! Note that we preserve the MIR block structure when lowering to TIR.
1212
//!
1313
//! Serialisation itself is performed by an external library: ykpack.
1414
@@ -30,8 +30,7 @@ use std::error::Error;
3030
use std::cell::{Cell, RefCell};
3131
use std::mem::size_of;
3232
use rustc_data_structures::bit_set::BitSet;
33-
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
34-
use rustc_data_structures::graph::dominators::DominatorFrontiers;
33+
use rustc_data_structures::indexed_vec::IndexVec;
3534
use ykpack;
3635
use ykpack::LocalIndex as TirLocal;
3736
use rustc_data_structures::fx::FxHashSet;
@@ -48,7 +47,7 @@ pub enum TirMode {
4847
TextDump(PathBuf),
4948
}
5049

51-
/// A conversion context holds the state needed to perform the conversion to (pre-SSA) TIR.
50+
/// A conversion context holds the state needed to perform the TIR lowering.
5251
struct ConvCx<'a, 'tcx, 'gcx> {
5352
/// The compiler's god struct. Needed for queries etc.
5453
tcx: &'a TyCtxt<'a, 'tcx, 'gcx>,
@@ -106,11 +105,6 @@ impl<'a, 'tcx, 'gcx> ConvCx<'a, 'tcx, 'gcx> {
106105
})
107106
}
108107

109-
/// Finalise the conversion context, returning the definition sites and block defines mappings.
110-
fn done(self) -> (Vec<BitSet<BasicBlock>>, IndexVec<BasicBlock, FxHashSet<TirLocal>>) {
111-
(self.def_sites.into_inner(), self.block_defines.into_inner())
112-
}
113-
114108
/// Add `bb` as a definition site of the TIR variable `var`.
115109
fn push_def_site(&self, bb: BasicBlock, var: TirLocal) {
116110
let mut sites = self.def_sites.borrow_mut();
@@ -187,19 +181,9 @@ fn do_generate_tir<'a, 'tcx, 'gcx>(
187181

188182
for def_id in sorted_def_ids {
189183
if tcx.is_mir_available(*def_id) {
190-
info!("generating TIR for {:?}", def_id);
191-
192184
let mir = tcx.optimized_mir(*def_id);
193185
let ccx = ConvCx::new(tcx, mir);
194-
195-
let mut pack = (&ccx, def_id, tcx.optimized_mir(*def_id)).to_pack();
196-
{
197-
let ykpack::Pack::Mir(ykpack::Mir{ref mut blocks, ..}) = pack;
198-
let (def_sites, block_defines) = ccx.done();
199-
insert_phis(blocks, mir, def_sites, block_defines);
200-
}
201-
202-
// FIXME - rename variables with fresh SSA names.
186+
let pack = (&ccx, def_id, tcx.optimized_mir(*def_id)).to_pack();
203187

204188
if let Some(ref mut e) = enc {
205189
e.serialise(pack)?;
@@ -218,51 +202,6 @@ fn do_generate_tir<'a, 'tcx, 'gcx>(
218202
Ok(tir_path)
219203
}
220204

221-
/// Insert PHI nodes into the initial pre-SSA TIR pack.
222-
///
223-
/// Algorithm reference:
224-
/// Bottom of p406 of 'Modern Compiler Implementation in Java (2nd ed.)' by Andrew Appel.
225-
fn insert_phis(blocks: &mut Vec<ykpack::BasicBlock>, mir: &Mir,
226-
mut def_sites: Vec<BitSet<BasicBlock>>,
227-
a_orig: IndexVec<BasicBlock, FxHashSet<TirLocal>>) {
228-
let doms = mir.dominators();
229-
let df = DominatorFrontiers::new(mir, &doms);
230-
let num_tir_vars = def_sites.len();
231-
let num_tir_blks = a_orig.len();
232-
233-
let mut a_phi: Vec<BitSet<TirLocal>> = Vec::with_capacity(num_tir_blks);
234-
a_phi.resize(num_tir_blks, BitSet::new_empty(num_tir_vars));
235-
236-
// We don't need the elements of `def_sites` again past this point, so we can take them out
237-
// of `def_sites` with a draining iterator and mutate in-place.
238-
for (a, mut w) in def_sites.drain(..).enumerate() {
239-
while !w.is_empty() {
240-
let n = bitset_pop(&mut w);
241-
for y in df.frontier(n).iter() {
242-
let y_usize = y.index();
243-
// `def_sites` is guaranteed to only contain indices expressible by `u32`.
244-
let a_u32 = a as u32;
245-
if !a_phi[y_usize].contains(a_u32) {
246-
a_phi[y_usize].insert(a_u32);
247-
if !a_orig[y].contains(&a_u32) {
248-
// The assertion in `tir_var()` has already checked the cast is safe.
249-
insert_phi(&mut blocks[y_usize], a as u32, mir.predecessors_for(y).len());
250-
w.insert(y);
251-
}
252-
}
253-
}
254-
}
255-
}
256-
}
257-
258-
fn insert_phi(block: &mut ykpack::BasicBlock, var: TirLocal, arity: usize) {
259-
let lhs = ykpack::Place::Local(var);
260-
let rhs_vars = (0..arity).map(|_| lhs.clone()).collect();
261-
let rhs = ykpack::Rvalue::Phi(rhs_vars);
262-
block.stmts.insert(0, ykpack::Statement::Assign(lhs, rhs));
263-
}
264-
265-
266205
/// The trait for converting MIR data structures into a bytecode packs.
267206
trait ToPack<T> {
268207
fn to_pack(&mut self) -> T;
@@ -415,11 +354,3 @@ impl<'tcx> ToPack<ykpack::Rvalue> for (&ConvCx<'_, 'tcx, '_>, &Rvalue<'tcx>) {
415354
}
416355
}
417356
}
418-
419-
/// At the time of writing, you can't pop from a `BitSet`.
420-
fn bitset_pop<T>(s: &mut BitSet<T>) -> T where T: Eq + Idx + Clone {
421-
let e = s.iter().next().unwrap().clone();
422-
let removed = s.remove(e);
423-
debug_assert!(removed);
424-
e
425-
}

src/librustc_yk_sections/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,5 @@ extern crate rustc_yk_link;
1414
extern crate rustc_codegen_utils;
1515
extern crate ykpack;
1616
extern crate rustc_data_structures;
17-
#[macro_use] extern crate log;
1817

1918
pub mod emit_tir;

src/test/yk-tir/simple_phi.rs renamed to src/test/yk-tir/simple_tir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ fn main() {
2222
// Assign(Local(0), Unimplemented)
2323
// term: Goto { target_bb: 4 }
2424
// bb4:
25-
// Assign(Local(0), Phi([Local(0), Local(0)]))
25+
// Unimplemented
2626
// ...
2727
// [End TIR for main]

0 commit comments

Comments
 (0)