Skip to content

Commit 145155d

Browse files
committed
parameterize BitVector and BitMatrix by their index types
1 parent a54401e commit 145155d

File tree

16 files changed

+119
-96
lines changed

16 files changed

+119
-96
lines changed

src/librustc/mir/traversal.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use rustc_data_structures::bitvec::BitVector;
12-
use rustc_data_structures::indexed_vec::Idx;
1312

1413
use super::*;
1514

@@ -33,7 +32,7 @@ use super::*;
3332
#[derive(Clone)]
3433
pub struct Preorder<'a, 'tcx: 'a> {
3534
mir: &'a Mir<'tcx>,
36-
visited: BitVector,
35+
visited: BitVector<BasicBlock>,
3736
worklist: Vec<BasicBlock>,
3837
}
3938

@@ -58,7 +57,7 @@ impl<'a, 'tcx> Iterator for Preorder<'a, 'tcx> {
5857

5958
fn next(&mut self) -> Option<(BasicBlock, &'a BasicBlockData<'tcx>)> {
6059
while let Some(idx) = self.worklist.pop() {
61-
if !self.visited.insert(idx.index()) {
60+
if !self.visited.insert(idx) {
6261
continue;
6362
}
6463

@@ -107,7 +106,7 @@ impl<'a, 'tcx> ExactSizeIterator for Preorder<'a, 'tcx> {}
107106
/// A Postorder traversal of this graph is `D B C A` or `D C B A`
108107
pub struct Postorder<'a, 'tcx: 'a> {
109108
mir: &'a Mir<'tcx>,
110-
visited: BitVector,
109+
visited: BitVector<BasicBlock>,
111110
visit_stack: Vec<(BasicBlock, Successors<'a>)>
112111
}
113112

@@ -123,7 +122,7 @@ impl<'a, 'tcx> Postorder<'a, 'tcx> {
123122
let data = &po.mir[root];
124123

125124
if let Some(ref term) = data.terminator {
126-
po.visited.insert(root.index());
125+
po.visited.insert(root);
127126
po.visit_stack.push((root, term.successors()));
128127
po.traverse_successor();
129128
}
@@ -190,8 +189,8 @@ impl<'a, 'tcx> Postorder<'a, 'tcx> {
190189
break;
191190
};
192191

193-
if self.visited.insert(bb.index()) {
194-
if let Some(ref term) = self.mir[bb].terminator {
192+
if self.visited.insert(bb) {
193+
if let Some(term) = &self.mir[bb].terminator {
195194
self.visit_stack.push((bb, term.successors()));
196195
}
197196
}

src/librustc_codegen_llvm/debuginfo/create_scope_map.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub fn create_mir_scopes(cx: &CodegenCx, mir: &Mir, debug_context: &FunctionDebu
6565
let mut has_variables = BitVector::new(mir.source_scopes.len());
6666
for var in mir.vars_iter() {
6767
let decl = &mir.local_decls[var];
68-
has_variables.insert(decl.visibility_scope.index());
68+
has_variables.insert(decl.visibility_scope);
6969
}
7070

7171
// Instantiate all scopes.
@@ -79,7 +79,7 @@ pub fn create_mir_scopes(cx: &CodegenCx, mir: &Mir, debug_context: &FunctionDebu
7979

8080
fn make_mir_scope(cx: &CodegenCx,
8181
mir: &Mir,
82-
has_variables: &BitVector,
82+
has_variables: &BitVector<SourceScope>,
8383
debug_context: &FunctionDebugContextData,
8484
scope: SourceScope,
8585
scopes: &mut IndexVec<SourceScope, MirDebugScope>) {
@@ -102,7 +102,7 @@ fn make_mir_scope(cx: &CodegenCx,
102102
return;
103103
};
104104

105-
if !has_variables.contains(scope.index()) {
105+
if !has_variables.contains(scope) {
106106
// Do not create a DIScope if there are no variables
107107
// defined in this MIR Scope, to avoid debuginfo bloat.
108108

src/librustc_codegen_llvm/mir/analyze.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc::ty::layout::LayoutOf;
2222
use type_of::LayoutLlvmExt;
2323
use super::FunctionCx;
2424

25-
pub fn non_ssa_locals<'a, 'tcx>(fx: &FunctionCx<'a, 'tcx>) -> BitVector {
25+
pub fn non_ssa_locals<'a, 'tcx>(fx: &FunctionCx<'a, 'tcx>) -> BitVector<mir::Local> {
2626
let mir = fx.mir;
2727
let mut analyzer = LocalAnalyzer::new(fx);
2828

@@ -54,7 +54,7 @@ pub fn non_ssa_locals<'a, 'tcx>(fx: &FunctionCx<'a, 'tcx>) -> BitVector {
5454
struct LocalAnalyzer<'mir, 'a: 'mir, 'tcx: 'a> {
5555
fx: &'mir FunctionCx<'a, 'tcx>,
5656
dominators: Dominators<mir::BasicBlock>,
57-
non_ssa_locals: BitVector,
57+
non_ssa_locals: BitVector<mir::Local>,
5858
// The location of the first visited direct assignment to each
5959
// local, or an invalid location (out of bounds `block` index).
6060
first_assignment: IndexVec<mir::Local, Location>
@@ -90,7 +90,7 @@ impl<'mir, 'a, 'tcx> LocalAnalyzer<'mir, 'a, 'tcx> {
9090

9191
fn not_ssa(&mut self, local: mir::Local) {
9292
debug!("marking {:?} as non-SSA", local);
93-
self.non_ssa_locals.insert(local.index());
93+
self.non_ssa_locals.insert(local);
9494
}
9595

9696
fn assign(&mut self, local: mir::Local, location: Location) {

src/librustc_codegen_llvm/mir/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ pub fn codegen_mir<'a, 'tcx: 'a>(
268268
let debug_scope = fx.scopes[decl.visibility_scope];
269269
let dbg = debug_scope.is_valid() && bx.sess().opts.debuginfo == FullDebugInfo;
270270

271-
if !memory_locals.contains(local.index()) && !dbg {
271+
if !memory_locals.contains(local) && !dbg {
272272
debug!("alloc: {:?} ({}) -> operand", local, name);
273273
return LocalRef::new_operand(bx.cx, layout);
274274
}
@@ -291,7 +291,7 @@ pub fn codegen_mir<'a, 'tcx: 'a>(
291291
debug!("alloc: {:?} (return place) -> place", local);
292292
let llretptr = llvm::get_param(llfn, 0);
293293
LocalRef::Place(PlaceRef::new_sized(llretptr, layout, layout.align))
294-
} else if memory_locals.contains(local.index()) {
294+
} else if memory_locals.contains(local) {
295295
debug!("alloc: {:?} -> place", local);
296296
LocalRef::Place(PlaceRef::alloca(&bx, layout, &format!("{:?}", local)))
297297
} else {
@@ -415,7 +415,7 @@ fn create_funclets<'a, 'tcx>(
415415
fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
416416
fx: &FunctionCx<'a, 'tcx>,
417417
scopes: &IndexVec<mir::SourceScope, debuginfo::MirDebugScope>,
418-
memory_locals: &BitVector)
418+
memory_locals: &BitVector<mir::Local>)
419419
-> Vec<LocalRef<'tcx>> {
420420
let mir = fx.mir;
421421
let tcx = bx.tcx();
@@ -487,7 +487,7 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
487487
llarg_idx += 1;
488488
}
489489

490-
if arg_scope.is_none() && !memory_locals.contains(local.index()) {
490+
if arg_scope.is_none() && !memory_locals.contains(local) {
491491
// We don't have to cast or keep the argument in the alloca.
492492
// FIXME(eddyb): We should figure out how to use llvm.dbg.value instead
493493
// of putting everything in allocas just so we can use llvm.dbg.declare.

0 commit comments

Comments
 (0)