Skip to content

Commit

Permalink
New structurizer: now with ∞% more φ! (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Dec 2, 2020
1 parent adebc90 commit e02bead
Show file tree
Hide file tree
Showing 10 changed files with 523 additions and 13 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/rustc_codegen_spirv/Cargo.toml
Expand Up @@ -28,6 +28,7 @@ use-compiled-tools = ["spirv-tools/use-compiled-tools"]

[dependencies]
bimap = "0.5"
indexmap = "1.6.0"
rspirv = { git = "https://github.com/gfx-rs/rspirv.git", rev = "01ca0d2e5b667a0e4ff1bc1804511e38f9a08759" }
rustc-demangle = "0.1.18"
spirv-tools = { version = "0.1.0", default-features = false }
Expand Down
7 changes: 1 addition & 6 deletions crates/rustc_codegen_spirv/src/builder/builder_methods.rs
Expand Up @@ -482,11 +482,6 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
else_llbb: Self::BasicBlock,
cases: impl ExactSizeIterator<Item = (u128, Self::BasicBlock)>,
) {
if !self.kernel_mode {
// TODO: Remove once structurizer is done.
self.zombie(else_llbb, "OpSwitch before structurizer is done");
}

fn construct_8(self_: &Builder<'_, '_>, signed: bool, v: u128) -> Operand {
if v > u8::MAX as u128 {
self_.fatal(&format!(
Expand Down Expand Up @@ -700,7 +695,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
OverflowOp::Mul => (self.mul(lhs, rhs), fals),
};
self.zombie(
result.1.def(self),
result.0.def(self),
match oop {
OverflowOp::Add => "checked add is not supported yet",
OverflowOp::Sub => "checked sub is not supported yet",
Expand Down
1 change: 1 addition & 0 deletions crates/rustc_codegen_spirv/src/link.rs
Expand Up @@ -408,6 +408,7 @@ fn do_link(sess: &Session, objects: &[PathBuf], rlibs: &[PathBuf], legalize: boo
inline: legalize,
mem2reg: legalize,
structurize: env::var("NO_STRUCTURIZE").is_err(),
use_new_structurizer: env::var("OLD_STRUCTURIZER").is_err(),
};

let link_result = linker::link(sess, modules, &options);
Expand Down
12 changes: 11 additions & 1 deletion crates/rustc_codegen_spirv/src/linker/mem2reg.rs
Expand Up @@ -38,7 +38,17 @@ pub fn mem2reg(
pub fn compute_preds(blocks: &[Block]) -> Vec<Vec<usize>> {
let mut result = vec![vec![]; blocks.len()];
for (source_idx, source) in blocks.iter().enumerate() {
for dest_id in outgoing_edges(source) {
let mut edges = outgoing_edges(source);
// HACK(eddyb) treat `OpSelectionMerge` as an edge, in case it points
// to an otherwise-unreachable block.
if let Some(before_last_idx) = source.instructions.len().checked_sub(2) {
if let Some(before_last) = source.instructions.get(before_last_idx) {
if before_last.class.opcode == Op::SelectionMerge {
edges.push(before_last.operands[0].unwrap_id_ref());
}
}
}
for dest_id in edges {
let dest_idx = blocks
.iter()
.position(|b| b.label_id().unwrap() == dest_id)
Expand Down
8 changes: 7 additions & 1 deletion crates/rustc_codegen_spirv/src/linker/mod.rs
Expand Up @@ -7,6 +7,7 @@ mod duplicates;
mod import_export_link;
mod inline;
mod mem2reg;
mod new_structurizer;
mod simple_passes;
mod structurizer;
mod zombies;
Expand All @@ -26,6 +27,7 @@ pub struct Options {
pub inline: bool,
pub mem2reg: bool,
pub structurize: bool,
pub use_new_structurizer: bool,
}

fn id(header: &mut ModuleHeader) -> Word {
Expand Down Expand Up @@ -136,7 +138,11 @@ pub fn link(sess: &Session, mut inputs: Vec<Module>, opts: &Options) -> Result<M

let mut output = if opts.structurize {
let _timer = sess.timer("link_structurize");
structurizer::structurize(sess, output)
if opts.use_new_structurizer {
new_structurizer::structurize(output)
} else {
structurizer::structurize(sess, output)
}
} else {
output
};
Expand Down

0 comments on commit e02bead

Please sign in to comment.