Skip to content

Commit

Permalink
rustc_codegen_ssa: use &'tcx mir::Body<'tcx> instead of &'a ... for t…
Browse files Browse the repository at this point in the history
…he MIR body.
  • Loading branch information
eddyb committed Dec 3, 2019
1 parent a57aea8 commit a7094f7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
43 changes: 22 additions & 21 deletions src/librustc_codegen_ssa/mir/block.rs
Expand Up @@ -24,13 +24,14 @@ use super::operand::OperandValue::{Pair, Ref, Immediate};


/// Used by `FunctionCx::codegen_terminator` for emitting common patterns /// Used by `FunctionCx::codegen_terminator` for emitting common patterns
/// e.g., creating a basic block, calling a function, etc. /// e.g., creating a basic block, calling a function, etc.
struct TerminatorCodegenHelper<'a, 'tcx> { struct TerminatorCodegenHelper<'tcx> {
bb: &'a mir::BasicBlock, bb: mir::BasicBlock,
terminator: &'a mir::Terminator<'tcx>, terminator: &'tcx mir::Terminator<'tcx>,
funclet_bb: Option<mir::BasicBlock>, funclet_bb: Option<mir::BasicBlock>,
} }


impl<'a, 'tcx> TerminatorCodegenHelper<'a, 'tcx> { // FIXME(eddyb) clean up the lifetimes in this impl.
impl<'tcx> TerminatorCodegenHelper<'tcx> {
/// Returns the associated funclet from `FunctionCx::funclets` for the /// Returns the associated funclet from `FunctionCx::funclets` for the
/// `funclet_bb` member if it is not `None`. /// `funclet_bb` member if it is not `None`.
fn funclet<'c, 'b, Bx: BuilderMethods<'b, 'tcx>>( fn funclet<'c, 'b, Bx: BuilderMethods<'b, 'tcx>>(
Expand Down Expand Up @@ -132,7 +133,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'a, 'tcx> {
} else { } else {
let llret = bx.call(fn_ptr, &llargs, self.funclet(fx)); let llret = bx.call(fn_ptr, &llargs, self.funclet(fx));
bx.apply_attrs_callsite(&fn_abi, llret); bx.apply_attrs_callsite(&fn_abi, llret);
if fx.mir[*self.bb].is_cleanup { if fx.mir[self.bb].is_cleanup {
// Cleanup is always the cold path. Don't inline // Cleanup is always the cold path. Don't inline
// drop glue. Also, when there is a deeply-nested // drop glue. Also, when there is a deeply-nested
// struct, there are "symmetry" issues that cause // struct, there are "symmetry" issues that cause
Expand All @@ -151,15 +152,15 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'a, 'tcx> {


// Generate sideeffect intrinsic if jumping to any of the targets can form // Generate sideeffect intrinsic if jumping to any of the targets can form
// a loop. // a loop.
fn maybe_sideeffect<'b, 'tcx2: 'b, Bx: BuilderMethods<'b, 'tcx2>>( fn maybe_sideeffect<'b, Bx: BuilderMethods<'b, 'tcx>>(
&self, &self,
mir: mir::ReadOnlyBodyCache<'b, 'tcx>, mir: mir::ReadOnlyBodyCache<'tcx, 'tcx>,
bx: &mut Bx, bx: &mut Bx,
targets: &[mir::BasicBlock], targets: &[mir::BasicBlock],
) { ) {
if bx.tcx().sess.opts.debugging_opts.insert_sideeffect { if bx.tcx().sess.opts.debugging_opts.insert_sideeffect {
if targets.iter().any(|target| { if targets.iter().any(|&target| {
*target <= *self.bb target <= self.bb
&& target && target
.start_location() .start_location()
.is_predecessor_of(self.bb.start_location(), mir) .is_predecessor_of(self.bb.start_location(), mir)
Expand All @@ -173,9 +174,9 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'a, 'tcx> {
/// Codegen implementations for some terminator variants. /// Codegen implementations for some terminator variants.
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
/// Generates code for a `Resume` terminator. /// Generates code for a `Resume` terminator.
fn codegen_resume_terminator<'b>( fn codegen_resume_terminator(
&mut self, &mut self,
helper: TerminatorCodegenHelper<'b, 'tcx>, helper: TerminatorCodegenHelper<'tcx>,
mut bx: Bx, mut bx: Bx,
) { ) {
if let Some(funclet) = helper.funclet(self) { if let Some(funclet) = helper.funclet(self) {
Expand All @@ -201,9 +202,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
} }
} }


fn codegen_switchint_terminator<'b>( fn codegen_switchint_terminator(
&mut self, &mut self,
helper: TerminatorCodegenHelper<'b, 'tcx>, helper: TerminatorCodegenHelper<'tcx>,
mut bx: Bx, mut bx: Bx,
discr: &mir::Operand<'tcx>, discr: &mir::Operand<'tcx>,
switch_ty: Ty<'tcx>, switch_ty: Ty<'tcx>,
Expand Down Expand Up @@ -316,9 +317,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
} }




fn codegen_drop_terminator<'b>( fn codegen_drop_terminator(
&mut self, &mut self,
helper: TerminatorCodegenHelper<'b, 'tcx>, helper: TerminatorCodegenHelper<'tcx>,
mut bx: Bx, mut bx: Bx,
location: &mir::Place<'tcx>, location: &mir::Place<'tcx>,
target: mir::BasicBlock, target: mir::BasicBlock,
Expand Down Expand Up @@ -367,9 +368,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
unwind); unwind);
} }


fn codegen_assert_terminator<'b>( fn codegen_assert_terminator(
&mut self, &mut self,
helper: TerminatorCodegenHelper<'b, 'tcx>, helper: TerminatorCodegenHelper<'tcx>,
mut bx: Bx, mut bx: Bx,
terminator: &mir::Terminator<'tcx>, terminator: &mir::Terminator<'tcx>,
cond: &mir::Operand<'tcx>, cond: &mir::Operand<'tcx>,
Expand Down Expand Up @@ -446,9 +447,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
helper.do_call(self, &mut bx, fn_abi, llfn, &args, None, cleanup); helper.do_call(self, &mut bx, fn_abi, llfn, &args, None, cleanup);
} }


fn codegen_call_terminator<'b>( fn codegen_call_terminator(
&mut self, &mut self,
helper: TerminatorCodegenHelper<'b, 'tcx>, helper: TerminatorCodegenHelper<'tcx>,
mut bx: Bx, mut bx: Bx,
terminator: &mir::Terminator<'tcx>, terminator: &mir::Terminator<'tcx>,
func: &mir::Operand<'tcx>, func: &mir::Operand<'tcx>,
Expand Down Expand Up @@ -807,14 +808,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
&mut self, &mut self,
mut bx: Bx, mut bx: Bx,
bb: mir::BasicBlock, bb: mir::BasicBlock,
terminator: &mir::Terminator<'tcx> terminator: &'tcx mir::Terminator<'tcx>
) { ) {
debug!("codegen_terminator: {:?}", terminator); debug!("codegen_terminator: {:?}", terminator);


// Create the cleanup bundle, if needed. // Create the cleanup bundle, if needed.
let funclet_bb = self.cleanup_kinds[bb].funclet_bb(bb); let funclet_bb = self.cleanup_kinds[bb].funclet_bb(bb);
let helper = TerminatorCodegenHelper { let helper = TerminatorCodegenHelper {
bb: &bb, terminator, funclet_bb bb, terminator, funclet_bb
}; };


self.set_debug_loc(&mut bx, terminator.source_info); self.set_debug_loc(&mut bx, terminator.source_info);
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_codegen_ssa/mir/mod.rs
@@ -1,6 +1,6 @@
use rustc::ty::{self, Ty, TypeFoldable, Instance}; use rustc::ty::{self, Ty, TypeFoldable, Instance};
use rustc::ty::layout::{TyLayout, HasTyCtxt, FnAbiExt}; use rustc::ty::layout::{TyLayout, HasTyCtxt, FnAbiExt};
use rustc::mir::{self, Body, ReadOnlyBodyCache}; use rustc::mir;
use rustc_target::abi::call::{FnAbi, PassMode}; use rustc_target::abi::call::{FnAbi, PassMode};
use crate::base; use crate::base;
use crate::traits::*; use crate::traits::*;
Expand All @@ -21,7 +21,7 @@ use self::operand::{OperandRef, OperandValue};
pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> { pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
instance: Instance<'tcx>, instance: Instance<'tcx>,


mir: mir::ReadOnlyBodyCache<'a, 'tcx>, mir: mir::ReadOnlyBodyCache<'tcx, 'tcx>,


debug_context: Option<FunctionDebugContext<Bx::DIScope>>, debug_context: Option<FunctionDebugContext<Bx::DIScope>>,


Expand Down Expand Up @@ -76,7 +76,7 @@ pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {


/// All `VarDebuginfo` from the MIR body, partitioned by `Local`. /// All `VarDebuginfo` from the MIR body, partitioned by `Local`.
/// This is `None` if no variable debuginfo/names are needed. /// This is `None` if no variable debuginfo/names are needed.
per_local_var_debug_info: Option<IndexVec<mir::Local, Vec<&'a mir::VarDebugInfo<'tcx>>>>, per_local_var_debug_info: Option<IndexVec<mir::Local, Vec<&'tcx mir::VarDebugInfo<'tcx>>>>,
} }


impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
Expand Down Expand Up @@ -122,7 +122,7 @@ impl<'a, 'tcx, V: CodegenObject> LocalRef<'tcx, V> {
pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
cx: &'a Bx::CodegenCx, cx: &'a Bx::CodegenCx,
llfn: Bx::Function, llfn: Bx::Function,
mir: ReadOnlyBodyCache<'a, 'tcx>, mir: mir::ReadOnlyBodyCache<'tcx, 'tcx>,
instance: Instance<'tcx>, instance: Instance<'tcx>,
sig: ty::FnSig<'tcx>, sig: ty::FnSig<'tcx>,
) { ) {
Expand Down Expand Up @@ -156,7 +156,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
}).collect(); }).collect();


let (landing_pads, funclets) = create_funclets(&mir, &mut bx, &cleanup_kinds, &block_bxs); let (landing_pads, funclets) = create_funclets(&mir, &mut bx, &cleanup_kinds, &block_bxs);
let mir_body: &Body<'_> = mir.body(); let mir_body: &mir::Body<'_> = mir.body();
let mut fx = FunctionCx { let mut fx = FunctionCx {
instance, instance,
mir, mir,
Expand Down Expand Up @@ -248,8 +248,8 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
} }
} }


fn create_funclets<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( fn create_funclets<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
mir: &'b Body<'tcx>, mir: &'tcx mir::Body<'tcx>,
bx: &mut Bx, bx: &mut Bx,
cleanup_kinds: &IndexVec<mir::BasicBlock, CleanupKind>, cleanup_kinds: &IndexVec<mir::BasicBlock, CleanupKind>,
block_bxs: &IndexVec<mir::BasicBlock, Bx::BasicBlock>, block_bxs: &IndexVec<mir::BasicBlock, Bx::BasicBlock>,
Expand Down

0 comments on commit a7094f7

Please sign in to comment.