Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert MIR BasicBlocks to ExtendedBasicBlocks #40700

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
938d024
Rename mir::BasicBlock to mir::Block.
Mark-Simulacrum Mar 11, 2017
ecba023
Dynamically generate new blocks with Builder.invoke.
Mark-Simulacrum Mar 19, 2017
7dd3fa3
Move TerminatorKind::Assert trans to mir::statement.
Mark-Simulacrum Mar 19, 2017
1702c22
Move TerminatorKind::Call trans to mir::statement.
Mark-Simulacrum Mar 19, 2017
7150036
Move TerminatorKind::Drop trans to mir::statement.
Mark-Simulacrum Mar 19, 2017
8cee04a
Remove obsolete CallGuards MIR pass
Mark-Simulacrum Mar 16, 2017
0d40f89
Dynamically generate new block for assert terminator trans.
Mark-Simulacrum Mar 19, 2017
33d124f
Move Assert to StatementKind
Mark-Simulacrum Mar 21, 2017
0295b0f
Fix MIR passes to work with new StatementKind::Assert
Mark-Simulacrum Mar 21, 2017
baa2d07
Calculate predecessors from successors
Mark-Simulacrum Mar 25, 2017
78a856b
Fix "let mut let mut" in MIR CFG graphviz output
Mark-Simulacrum Mar 25, 2017
49b486b
Rename Statement::successors to cleanup_target
Mark-Simulacrum Mar 25, 2017
ff12d78
Switch TerminatorKind::Call to StatementKind.
Mark-Simulacrum Mar 28, 2017
d6f43a4
Revert "Remove obsolete CallGuards MIR pass"
Mark-Simulacrum Mar 29, 2017
699b53d
[WIP] Attempt to fix borrowck
Mark-Simulacrum Apr 1, 2017
71b4d9e
fixup handling of destination to check for Goto terminator
Mark-Simulacrum Apr 8, 2017
52b4a53
more fixes
Mark-Simulacrum Apr 8, 2017
606dca5
further cleanup
Mark-Simulacrum Apr 8, 2017
cb72173
resolve more issues wrt to Assert and Call
Mark-Simulacrum Apr 9, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/liballoc/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub const EMPTY: *mut () = 0x1 as *mut ();
// This function must not unwind. If it does, MIR trans will fail.
#[cfg(not(test))]
#[lang = "exchange_malloc"]
#[inline]
#[inline(never)]
unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
if size == 0 {
EMPTY as *mut u8
Expand Down
42 changes: 35 additions & 7 deletions src/librustc/mir/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
use std::cell::{Ref, RefCell};
use rustc_data_structures::indexed_vec::IndexVec;

use mir::{Mir, BasicBlock};
use mir::{Mir, Block};

use rustc_serialize as serialize;

#[derive(Clone, Debug)]
pub struct Cache {
predecessors: RefCell<Option<IndexVec<BasicBlock, Vec<BasicBlock>>>>
predecessors: RefCell<Option<IndexVec<Block, Vec<Block>>>>,
successors: RefCell<Option<IndexVec<Block, Vec<Block>>>>,
}


Expand All @@ -37,30 +38,57 @@ impl serialize::Decodable for Cache {
impl Cache {
pub fn new() -> Self {
Cache {
predecessors: RefCell::new(None)
predecessors: RefCell::new(None),
successors: RefCell::new(None)
}
}

pub fn invalidate(&self) {
// FIXME: consider being more fine-grained
*self.predecessors.borrow_mut() = None;
*self.successors.borrow_mut() = None;
}

pub fn predecessors(&self, mir: &Mir) -> Ref<IndexVec<BasicBlock, Vec<BasicBlock>>> {
pub fn predecessors(&self, mir: &Mir) -> Ref<IndexVec<Block, Vec<Block>>> {
if self.predecessors.borrow().is_none() {
*self.predecessors.borrow_mut() = Some(calculate_predecessors(mir));
*self.predecessors.borrow_mut() = Some(self.calculate_predecessors(mir));
}

Ref::map(self.predecessors.borrow(), |p| p.as_ref().unwrap())
}

fn calculate_predecessors(&self, mir: &Mir) -> IndexVec<Block, Vec<Block>> {
let mut result = IndexVec::from_elem(vec![], mir.basic_blocks());
for (bb, bbs) in self.successors(mir).iter_enumerated() {
for &tgt in bbs {
result[tgt].push(bb);
}
}

result
}

pub fn successors(&self, mir: &Mir) -> Ref<IndexVec<Block, Vec<Block>>> {
if self.successors.borrow().is_none() {
*self.successors.borrow_mut() = Some(calculate_successors(mir));
}

Ref::map(self.successors.borrow(), |p| p.as_ref().unwrap())
}
}

fn calculate_predecessors(mir: &Mir) -> IndexVec<BasicBlock, Vec<BasicBlock>> {
fn calculate_successors(mir: &Mir) -> IndexVec<Block, Vec<Block>> {
let mut result = IndexVec::from_elem(vec![], mir.basic_blocks());
for (bb, data) in mir.basic_blocks().iter_enumerated() {
for stmt in &data.statements {
if let Some(cleanup) = stmt.cleanup_target() {
result[bb].push(cleanup);
}
}

if let Some(ref term) = data.terminator {
for &tgt in term.successors().iter() {
result[tgt].push(bb);
result[bb].push(tgt);
}
}
}
Expand Down
Loading