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

Commit 4bec6f3

Browse files
bors[bot]vext01
andcommitted
Merge #17
17: Remove static ssa r=ltratt a=vext01 This kills the SSA code in the compiler (and switches the lib to Rust 2018). I'm just going to check if we can flip this over to using `yk`, so please don't merge just yet. Co-authored-by: Edd Barrett <vext01@gmail.com>
2 parents 3fc4a57 + f3ad5c4 commit 4bec6f3

File tree

6 files changed

+14
-85
lines changed

6 files changed

+14
-85
lines changed

Cargo.lock

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3062,12 +3062,11 @@ 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",
30693068
"rustc_yk_link 0.0.0",
3070-
"ykpack 0.1.0 (git+https://github.com/softdevteam/ykpack)",
3069+
"ykpack 0.1.0 (git+https://github.com/softdevteam/yk)",
30713070
]
30723071

30733072
[[package]]
@@ -4046,7 +4045,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
40464045
[[package]]
40474046
name = "ykpack"
40484047
version = "0.1.0"
4049-
source = "git+https://github.com/softdevteam/ykpack#9c5542d9d556ce745f0b21983a009a1297f371e4"
4048+
source = "git+https://github.com/softdevteam/yk#0c7016c47bff4b149a2bc1d304cf637f6d64719e"
40504049
dependencies = [
40514050
"fallible-iterator 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
40524051
"rmp-serde 0.14.0 (git+https://github.com/3Hren/msgpack-rust?rev=40b3d480b20961e6eeceb416b32bcd0a3383846a)",
@@ -4390,4 +4389,4 @@ dependencies = [
43904389
"checksum xattr 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "244c3741f4240ef46274860397c7c74e50eb23624996930e484c16679633a54c"
43914390
"checksum xz2 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "df8bf41d3030c3577c9458fd6640a05afbf43b150d0b531b16bd77d3f794f27a"
43924391
"checksum yaml-rust 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e66366e18dc58b46801afbf2ca7661a9f59cc8c5962c29892b6039b4f86fa992"
4393-
"checksum ykpack 0.1.0 (git+https://github.com/softdevteam/ykpack)" = "<none>"
4392+
"checksum ykpack 0.1.0 (git+https://github.com/softdevteam/yk)" = "<none>"

src/librustc_yk_sections/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
authors = ["Edd Barrett <vext01@gmail.com>"]
33
name = "rustc_yk_sections"
44
version = "0.0.0"
5+
edition = "2018"
56

67
[lib]
78
name = "rustc_yk_sections"
@@ -12,7 +13,6 @@ test = false
1213
[dependencies]
1314
rustc = { path = "../librustc" }
1415
rustc_yk_link = { path = "../librustc_yk_link" }
15-
ykpack = { git = "https://github.com/softdevteam/ykpack" }
16+
ykpack = { git = "https://github.com/softdevteam/yk" }
1617
rustc_codegen_utils = { path = "../librustc_codegen_utils" }
1718
rustc_data_structures = { path = "../librustc_data_structures" }
18-
log = "0.4.5"

src/librustc_yk_sections/emit_tir.rs

Lines changed: 7 additions & 76 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();
@@ -165,12 +159,12 @@ fn do_generate_tir<'a, 'tcx, 'gcx>(
165159
// same between builds for the reproducible build tests to pass.
166160
let mut tir_path = exe_path.clone();
167161
tir_path.set_extension(TMP_EXT);
168-
let mut file = File::create(&tir_path)?;
162+
let file = File::create(&tir_path)?;
169163
(tir_path, Some(file), None)
170164
},
171165
TirMode::TextDump(dump_path) => {
172166
// In text dump mode we just write lines to a file and we don't need an encoder.
173-
let mut file = File::create(&dump_path)?;
167+
let file = File::create(&dump_path)?;
174168
(dump_path.clone(), None, Some(file))
175169
},
176170
};
@@ -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]

src/tools/tidy/src/extdeps.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const WHITELISTED_SOURCES: &[&str] = &[
1010
// The following are needed for Yorick whilst we use an unreleased revision not on crates.io.
1111
"\"git+https://github.com/3Hren/msgpack-rust?\
1212
rev=40b3d480b20961e6eeceb416b32bcd0a3383846a#40b3d480b20961e6eeceb416b32bcd0a3383846a\"",
13-
"\"git+https://github.com/softdevteam/ykpack#e0fd6162b9522fd04b6bbb77a232986c4ea5c257\"",
13+
"\"git+https://github.com/softdevteam/yk#0c7016c47bff4b149a2bc1d304cf637f6d64719e\"",
1414
];
1515

1616
/// Checks for external package sources.

0 commit comments

Comments
 (0)