Skip to content

Commit 605bc04

Browse files
committed
Use a BitVector instead of Vec<bool> for recording cleanup blocks
Also adds a FromIterator impl for BitVector to allow construction of a BitVector from an iterator yeilding bools.
1 parent 63321ca commit 605bc04

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/librustc_data_structures/bitvec.rs

+26-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use std::iter::FromIterator;
12+
1113
/// A very simple BitVector type.
1214
#[derive(Clone)]
1315
pub struct BitVector {
@@ -51,7 +53,9 @@ impl BitVector {
5153
pub fn grow(&mut self, num_bits: usize) {
5254
let num_words = u64s(num_bits);
5355
let extra_words = self.data.len() - num_words;
54-
self.data.extend((0..extra_words).map(|_| 0));
56+
if extra_words > 0 {
57+
self.data.extend((0..extra_words).map(|_| 0));
58+
}
5559
}
5660

5761
/// Iterates over indexes of set bits in a sorted order
@@ -94,6 +98,27 @@ impl<'a> Iterator for BitVectorIter<'a> {
9498
}
9599
}
96100

101+
impl FromIterator<bool> for BitVector {
102+
fn from_iter<I>(iter: I) -> BitVector where I: IntoIterator<Item=bool> {
103+
let iter = iter.into_iter();
104+
let (len, _) = iter.size_hint();
105+
// Make the minimum length for the bitvector 64 bits since that's
106+
// the smallest non-zero size anyway.
107+
let len = if len < 64 { 64 } else { len };
108+
let mut bv = BitVector::new(len);
109+
for (idx, val) in iter.enumerate() {
110+
if idx > len {
111+
bv.grow(idx);
112+
}
113+
if val {
114+
bv.insert(idx);
115+
}
116+
}
117+
118+
bv
119+
}
120+
}
121+
97122
/// A "bit matrix" is basically a square matrix of booleans
98123
/// represented as one gigantic bitvector. In other words, it is as if
99124
/// you have N bitvectors, each of length N. Note that `elements` here is `N`/

src/librustc_mir/transform/break_critical_edges.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use rustc::mir::repr::*;
1313
use rustc::mir::transform::{MirPass, Pass};
1414
use syntax::ast::NodeId;
1515

16+
use rustc_data_structures::bitvec::BitVector;
17+
1618
use traversal;
1719

1820
pub struct BreakCriticalEdges;
@@ -60,6 +62,9 @@ fn break_critical_edges(mir: &mut Mir) {
6062
}
6163
}
6264

65+
let cleanup_map : BitVector = mir.basic_blocks
66+
.iter().map(|bb| bb.is_cleanup).collect();
67+
6368
// We need a place to store the new blocks generated
6469
let mut new_blocks = Vec::new();
6570

@@ -84,7 +89,9 @@ fn break_critical_edges(mir: &mut Mir) {
8489
scope: term_scope,
8590
kind: TerminatorKind::Goto { target: *tgt }
8691
};
87-
let data = BasicBlockData::new(Some(goto));
92+
let mut data = BasicBlockData::new(Some(goto));
93+
data.is_cleanup = cleanup_map.contains(tgt.index());
94+
8895
// Get the index it will be when inserted into the MIR
8996
let idx = cur_len + new_blocks.len();
9097
new_blocks.push(data);

0 commit comments

Comments
 (0)