diff options
| author | Paul Daniel Faria <Nashenas88@users.noreply.github.com> | 2019-10-10 23:16:44 -0400 |
|---|---|---|
| committer | Paul Daniel Faria <Nashenas88@users.noreply.github.com> | 2019-12-02 08:30:30 -0500 |
| commit | 649c73f96d8969f05000a071007bcd050fa8d466 (patch) | |
| tree | 2f5f8d3bac4b6f6163726592c7f8cd93d00509e7 /src/librustc_codegen_ssa | |
| parent | c0592faa67a1fe8fb7425f24899c5538dec23ee1 (diff) | |
| download | rust-649c73f96d8969f05000a071007bcd050fa8d466.tar.gz rust-649c73f96d8969f05000a071007bcd050fa8d466.zip | |
Simplify Cache wrapper to single type, impl Deref on it, fix all compilation errors in librustc_codegen_ssa
Diffstat (limited to 'src/librustc_codegen_ssa')
| -rw-r--r-- | src/librustc_codegen_ssa/base.rs | 5 | ||||
| -rw-r--r-- | src/librustc_codegen_ssa/mir/analyze.rs | 40 | ||||
| -rw-r--r-- | src/librustc_codegen_ssa/mir/block.rs | 12 | ||||
| -rw-r--r-- | src/librustc_codegen_ssa/mir/mod.rs | 16 | ||||
| -rw-r--r-- | src/librustc_codegen_ssa/mir/place.rs | 2 | ||||
| -rw-r--r-- | src/librustc_codegen_ssa/mir/rvalue.rs | 6 |
6 files changed, 46 insertions, 35 deletions
diff --git a/src/librustc_codegen_ssa/base.rs b/src/librustc_codegen_ssa/base.rs index 22693beb855..d67a9d3799e 100644 --- a/src/librustc_codegen_ssa/base.rs +++ b/src/librustc_codegen_ssa/base.rs @@ -31,6 +31,7 @@ use rustc::hir::def_id::{DefId, LOCAL_CRATE}; use rustc::middle::cstore::EncodedMetadata; use rustc::middle::lang_items::StartFnLangItem; use rustc::middle::weak_lang_items; +use rustc::mir::BodyCache; use rustc::mir::mono::{CodegenUnitNameBuilder, CodegenUnit, MonoItem}; use rustc::ty::{self, Ty, TyCtxt, Instance}; use rustc::ty::layout::{self, Align, TyLayout, LayoutOf, VariantIdx, HasTyCtxt}; @@ -374,7 +375,9 @@ pub fn codegen_instance<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( let lldecl = cx.get_fn(instance); let mir = cx.tcx().instance_mir(instance.def); - mir::codegen_mir::<Bx>(cx, lldecl, &mir, instance, sig); + // TODO(nashenas88) move this into instance_mir before merging PR + let mut mir = BodyCache::new(mir); + mir::codegen_mir::<Bx>(cx, lldecl, &mut mir, instance, sig); } /// Creates the `main` function which will initialize the rust runtime and call diff --git a/src/librustc_codegen_ssa/mir/analyze.rs b/src/librustc_codegen_ssa/mir/analyze.rs index e44551fcbcd..7a2940a8e67 100644 --- a/src/librustc_codegen_ssa/mir/analyze.rs +++ b/src/librustc_codegen_ssa/mir/analyze.rs @@ -4,7 +4,7 @@ use rustc_index::bit_set::BitSet; use rustc_data_structures::graph::dominators::Dominators; use rustc_index::vec::{Idx, IndexVec}; -use rustc::mir::{self, Location, TerminatorKind}; +use rustc::mir::{self, Body, BodyCache, Location, TerminatorKind}; use rustc::mir::visit::{ Visitor, PlaceContext, MutatingUseContext, NonMutatingUseContext, NonUseContext, }; @@ -17,10 +17,10 @@ use super::FunctionCx; use crate::traits::*; pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( - fx: &FunctionCx<'a, 'tcx, Bx>, + fx: &mut FunctionCx<'a, 'tcx, Bx>, ) -> BitSet<mir::Local> { - let mir = fx.mir; - let mut analyzer = LocalAnalyzer::new(fx); + let mir = fx.mir.take().unwrap(); + let mut analyzer = LocalAnalyzer::new(fx, mir); analyzer.visit_body(mir); @@ -54,11 +54,14 @@ pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( } } - analyzer.non_ssa_locals + let (mir, non_ssa_locals) = analyzer.finalize(); + fx.mir = Some(mir); + non_ssa_locals } struct LocalAnalyzer<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> { fx: &'mir FunctionCx<'a, 'tcx, Bx>, + mir: &'a mut BodyCache<&'a Body<'tcx>>, dominators: Dominators<mir::BasicBlock>, non_ssa_locals: BitSet<mir::Local>, // The location of the first visited direct assignment to each @@ -67,27 +70,32 @@ struct LocalAnalyzer<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> { } impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> { - fn new(fx: &'mir FunctionCx<'a, 'tcx, Bx>) -> Self { + fn new(fx: &'mir FunctionCx<'a, 'tcx, Bx>, mir: &'a mut BodyCache<&'a Body<'tcx>>) -> Self { let invalid_location = - mir::BasicBlock::new(fx.mir.basic_blocks().len()).start_location(); + mir::BasicBlock::new(mir.basic_blocks().len()).start_location(); let mut analyzer = LocalAnalyzer { fx, - dominators: fx.mir.dominators(), - non_ssa_locals: BitSet::new_empty(fx.mir.local_decls.len()), - first_assignment: IndexVec::from_elem(invalid_location, &fx.mir.local_decls) + dominators: mir.dominators(), + mir, + non_ssa_locals: BitSet::new_empty(mir.local_decls.len()), + first_assignment: IndexVec::from_elem(invalid_location, &mir.local_decls) }; // Arguments get assigned to by means of the function being called - for arg in fx.mir.args_iter() { + for arg in mir.args_iter() { analyzer.first_assignment[arg] = mir::START_BLOCK.start_location(); } analyzer } + fn finalize(self) -> (&'a mut BodyCache<&'a Body<'tcx>>, BitSet<mir::Local>) { + (self.mir, self.non_ssa_locals) + } + fn first_assignment(&self, local: mir::Local) -> Option<Location> { let location = self.first_assignment[local]; - if location.block.index() < self.fx.mir.basic_blocks().len() { + if location.block.index() < self.mir.basic_blocks().len() { Some(location) } else { None @@ -130,7 +138,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> { }; if is_consume { let base_ty = - mir::Place::ty_from(place_ref.base, proj_base, self.fx.mir, cx.tcx()); + mir::Place::ty_from(place_ref.base, proj_base, self.mir.body(), cx.tcx()); let base_ty = self.fx.monomorphize(&base_ty); // ZSTs don't require any actual memory access. @@ -139,7 +147,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> { .ty; let elem_ty = self.fx.monomorphize(&elem_ty); let span = if let mir::PlaceBase::Local(index) = place_ref.base { - self.fx.mir.local_decls[*index].source_info.span + self.mir.local_decls[*index].source_info.span } else { DUMMY_SP }; @@ -243,7 +251,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx> if let Some(index) = place.as_local() { self.assign(index, location); - let decl_span = self.fx.mir.local_decls[index].source_info.span; + let decl_span = self.mir.local_decls[index].source_info.span; if !self.fx.rvalue_creates_operand(rvalue, decl_span) { self.not_ssa(index); } @@ -348,7 +356,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx> } PlaceContext::MutatingUse(MutatingUseContext::Drop) => { - let ty = self.fx.mir.local_decls[local].ty; + let ty = self.mir.local_decls[local].ty; let ty = self.fx.monomorphize(&ty); // Only need the place if we're actually dropping it. diff --git a/src/librustc_codegen_ssa/mir/block.rs b/src/librustc_codegen_ssa/mir/block.rs index d76392f7570..d09ff0160db 100644 --- a/src/librustc_codegen_ssa/mir/block.rs +++ b/src/librustc_codegen_ssa/mir/block.rs @@ -132,7 +132,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'a, 'tcx> { } else { let llret = bx.call(fn_ptr, &llargs, self.funclet(fx)); bx.apply_attrs_callsite(&fn_abi, llret); - if fx.mir[*self.bb].is_cleanup { + if fx.mir.unwrap()[*self.bb].is_cleanup { // Cleanup is always the cold path. Don't inline // drop glue. Also, when there is a deeply-nested // struct, there are "symmetry" issues that cause @@ -324,7 +324,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { target: mir::BasicBlock, unwind: Option<mir::BasicBlock>, ) { - let ty = location.ty(self.mir, bx.tcx()).ty; + let ty = location.ty(self.mir.unwrap().body(), bx.tcx()).ty; let ty = self.monomorphize(&ty); let drop_fn = Instance::resolve_drop_in_place(bx.tcx(), ty); @@ -510,7 +510,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let extra_args = &args[sig.inputs().len()..]; let extra_args = extra_args.iter().map(|op_arg| { - let op_ty = op_arg.ty(self.mir, bx.tcx()); + let op_ty = op_arg.ty(self.mir.unwrap().body(), bx.tcx()); self.monomorphize(&op_ty) }).collect::<Vec<_>>(); @@ -791,7 +791,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { bb: mir::BasicBlock, ) { let mut bx = self.build_block(bb); - let data = &self.mir[bb]; + let data = &self.mir.unwrap()[bb]; debug!("codegen_block({:?}={:?})", bb, data); @@ -1053,7 +1053,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { target_bb: Bx::BasicBlock ) -> Bx::BasicBlock { if base::wants_msvc_seh(self.cx.sess()) { - span_bug!(self.mir.span, "landing pad was not inserted?") + span_bug!(self.mir.unwrap().span, "landing pad was not inserted?") } let mut bx = self.new_block("cleanup"); @@ -1154,7 +1154,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { // // If someone changes that, please update this code path // to create a temporary. - span_bug!(self.mir.span, "can't directly store to unaligned value"); + span_bug!(self.mir.unwrap().span, "can't directly store to unaligned value"); } llargs.push(dest.llval); ReturnDest::Nothing diff --git a/src/librustc_codegen_ssa/mir/mod.rs b/src/librustc_codegen_ssa/mir/mod.rs index 6041232489d..8b127867238 100644 --- a/src/librustc_codegen_ssa/mir/mod.rs +++ b/src/librustc_codegen_ssa/mir/mod.rs @@ -1,6 +1,6 @@ use rustc::ty::{self, Ty, TypeFoldable, Instance}; use rustc::ty::layout::{TyLayout, HasTyCtxt, FnAbiExt}; -use rustc::mir::{self, Body}; +use rustc::mir::{self, Body, BodyCache}; use rustc_target::abi::call::{FnAbi, PassMode}; use crate::base; use crate::traits::*; @@ -21,7 +21,7 @@ use self::operand::{OperandRef, OperandValue}; pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> { instance: Instance<'tcx>, - mir: &'a mir::Body<'tcx>, + mir: Option<&'a mut BodyCache<&'a mir::Body<'tcx>>>, debug_context: Option<FunctionDebugContext<Bx::DIScope>>, @@ -122,7 +122,7 @@ impl<'a, 'tcx, V: CodegenObject> LocalRef<'tcx, V> { pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( cx: &'a Bx::CodegenCx, llfn: Bx::Function, - mir: &'a Body<'tcx>, + mir: &'a mut BodyCache<&'a Body<'tcx>>, instance: Instance<'tcx>, sig: ty::FnSig<'tcx>, ) { @@ -159,7 +159,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( let mut fx = FunctionCx { instance, - mir, + mir: Some(mir), llfn, fn_abi, cx, @@ -174,7 +174,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( per_local_var_debug_info: debuginfo::per_local_var_debug_info(cx.tcx(), mir), }; - let memory_locals = analyze::non_ssa_locals(&fx); + let memory_locals = analyze::non_ssa_locals(&mut fx); // Allocate variable and temp allocas fx.locals = { @@ -327,10 +327,10 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( let mut idx = 0; let mut llarg_idx = fx.fn_abi.ret.is_indirect() as usize; - mir.args_iter().enumerate().map(|(arg_index, local)| { - let arg_decl = &mir.local_decls[local]; + mir.unwrap().args_iter().enumerate().map(|(arg_index, local)| { + let arg_decl = &mir.unwrap().local_decls[local]; - if Some(local) == mir.spread_arg { + if Some(local) == mir.unwrap().spread_arg { // This argument (e.g., the last argument in the "rust-call" ABI) // is a tuple that was spread at the ABI level and now we have // to reconstruct it into a tuple local variable, from multiple diff --git a/src/librustc_codegen_ssa/mir/place.rs b/src/librustc_codegen_ssa/mir/place.rs index 4df5bce9537..8f3c1de9c64 100644 --- a/src/librustc_codegen_ssa/mir/place.rs +++ b/src/librustc_codegen_ssa/mir/place.rs @@ -591,7 +591,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { pub fn monomorphized_place_ty(&self, place_ref: &mir::PlaceRef<'_, 'tcx>) -> Ty<'tcx> { let tcx = self.cx.tcx(); - let place_ty = mir::Place::ty_from(place_ref.base, place_ref.projection, self.mir, tcx); + let place_ty = mir::Place::ty_from(place_ref.base, place_ref.projection, self.mir.unwrap().body(), tcx); self.monomorphize(&place_ty.ty) } } diff --git a/src/librustc_codegen_ssa/mir/rvalue.rs b/src/librustc_codegen_ssa/mir/rvalue.rs index f7fb4a57140..c1519b6106d 100644 --- a/src/librustc_codegen_ssa/mir/rvalue.rs +++ b/src/librustc_codegen_ssa/mir/rvalue.rs @@ -460,7 +460,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } mir::Rvalue::Discriminant(ref place) => { - let discr_ty = rvalue.ty(&*self.mir, bx.tcx()); + let discr_ty = rvalue.ty(self.mir.unwrap().body(), bx.tcx()); let discr = self.codegen_place(&mut bx, &place.as_ref()) .codegen_get_discr(&mut bx, discr_ty); (bx, OperandRef { @@ -513,7 +513,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { mir::Rvalue::Aggregate(..) => { // According to `rvalue_creates_operand`, only ZST // aggregate rvalues are allowed to be operands. - let ty = rvalue.ty(self.mir, self.cx.tcx()); + let ty = rvalue.ty(self.mir.unwrap().body(), self.cx.tcx()); let operand = OperandRef::new_zst( &mut bx, self.cx.layout_of(self.monomorphize(&ty)), @@ -710,7 +710,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { true, mir::Rvalue::Repeat(..) | mir::Rvalue::Aggregate(..) => { - let ty = rvalue.ty(self.mir, self.cx.tcx()); + let ty = rvalue.ty(self.mir.unwrap().body(), self.cx.tcx()); let ty = self.monomorphize(&ty); self.cx.spanned_layout_of(ty, span).is_zst() } |
