Skip to content

Commit 30b1d9e

Browse files
committed
Remove Body from FunctionCx, pass it along during librustc_codegen_ssa
1 parent 649c73f commit 30b1d9e

File tree

8 files changed

+184
-159
lines changed

8 files changed

+184
-159
lines changed

src/librustc_codegen_ssa/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,8 @@ pub fn codegen_instance<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
376376

377377
let mir = cx.tcx().instance_mir(instance.def);
378378
// TODO(nashenas88) move this into instance_mir before merging PR
379-
let mut mir = BodyCache::new(mir);
380-
mir::codegen_mir::<Bx>(cx, lldecl, &mut mir, instance, sig);
379+
let mir = BodyCache::new(mir);
380+
mir::codegen_mir::<Bx>(cx, lldecl, mir, instance, sig);
381381
}
382382

383383
/// Creates the `main` function which will initialize the rust runtime and call

src/librustc_codegen_ssa/mir/analyze.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use rustc_index::bit_set::BitSet;
55
use rustc_data_structures::graph::dominators::Dominators;
66
use rustc_index::vec::{Idx, IndexVec};
7-
use rustc::mir::{self, Body, BodyCache, Location, TerminatorKind};
7+
use rustc::mir::{self, BasicBlock, Body, BodyCache, Location, TerminatorKind};
88
use rustc::mir::visit::{
99
Visitor, PlaceContext, MutatingUseContext, NonMutatingUseContext, NonUseContext,
1010
};
@@ -16,11 +16,12 @@ use syntax_pos::DUMMY_SP;
1616
use super::FunctionCx;
1717
use crate::traits::*;
1818

19-
pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
19+
pub fn non_ssa_locals<'b, 'a: 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
2020
fx: &mut FunctionCx<'a, 'tcx, Bx>,
21+
mir: &'b mut BodyCache<&'a Body<'tcx>>,
2122
) -> BitSet<mir::Local> {
22-
let mir = fx.mir.take().unwrap();
23-
let mut analyzer = LocalAnalyzer::new(fx, mir);
23+
let dominators = mir.dominators();
24+
let mut analyzer = LocalAnalyzer::new(fx, mir, dominators);
2425

2526
analyzer.visit_body(mir);
2627

@@ -54,29 +55,27 @@ pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
5455
}
5556
}
5657

57-
let (mir, non_ssa_locals) = analyzer.finalize();
58-
fx.mir = Some(mir);
59-
non_ssa_locals
58+
analyzer.non_ssa_locals
6059
}
6160

62-
struct LocalAnalyzer<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
61+
struct LocalAnalyzer<'mir, 'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
6362
fx: &'mir FunctionCx<'a, 'tcx, Bx>,
64-
mir: &'a mut BodyCache<&'a Body<'tcx>>,
63+
mir: &'b Body<'tcx>,
6564
dominators: Dominators<mir::BasicBlock>,
6665
non_ssa_locals: BitSet<mir::Local>,
6766
// The location of the first visited direct assignment to each
6867
// local, or an invalid location (out of bounds `block` index).
6968
first_assignment: IndexVec<mir::Local, Location>,
7069
}
7170

72-
impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
73-
fn new(fx: &'mir FunctionCx<'a, 'tcx, Bx>, mir: &'a mut BodyCache<&'a Body<'tcx>>) -> Self {
71+
impl<'mir, 'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'b, 'tcx, Bx> {
72+
fn new(fx: &'mir FunctionCx<'a, 'tcx, Bx>, mir: &'b Body<'tcx>, dominators: Dominators<BasicBlock>) -> Self {
7473
let invalid_location =
7574
mir::BasicBlock::new(mir.basic_blocks().len()).start_location();
7675
let mut analyzer = LocalAnalyzer {
7776
fx,
78-
dominators: mir.dominators(),
7977
mir,
78+
dominators,
8079
non_ssa_locals: BitSet::new_empty(mir.local_decls.len()),
8180
first_assignment: IndexVec::from_elem(invalid_location, &mir.local_decls)
8281
};
@@ -89,10 +88,6 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
8988
analyzer
9089
}
9190

92-
fn finalize(self) -> (&'a mut BodyCache<&'a Body<'tcx>>, BitSet<mir::Local>) {
93-
(self.mir, self.non_ssa_locals)
94-
}
95-
9691
fn first_assignment(&self, local: mir::Local) -> Option<Location> {
9792
let location = self.first_assignment[local];
9893
if location.block.index() < self.mir.basic_blocks().len() {
@@ -138,7 +133,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
138133
};
139134
if is_consume {
140135
let base_ty =
141-
mir::Place::ty_from(place_ref.base, proj_base, self.mir.body(), cx.tcx());
136+
mir::Place::ty_from(place_ref.base, proj_base, self.mir, cx.tcx());
142137
let base_ty = self.fx.monomorphize(&base_ty);
143138

144139
// ZSTs don't require any actual memory access.
@@ -240,8 +235,8 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
240235

241236
}
242237

243-
impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
244-
for LocalAnalyzer<'mir, 'a, 'tcx, Bx>
238+
impl<'mir, 'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
239+
for LocalAnalyzer<'mir, 'a, 'b, 'tcx, Bx>
245240
{
246241
fn visit_assign(&mut self,
247242
place: &mir::Place<'tcx>,
@@ -252,7 +247,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
252247
if let Some(index) = place.as_local() {
253248
self.assign(index, location);
254249
let decl_span = self.mir.local_decls[index].source_info.span;
255-
if !self.fx.rvalue_creates_operand(rvalue, decl_span) {
250+
if !self.fx.rvalue_creates_operand(rvalue, decl_span, self.mir) {
256251
self.not_ssa(index);
257252
}
258253
} else {

0 commit comments

Comments
 (0)