Skip to content

Commit

Permalink
rustc_trans: rename mircx: MirContext to fx: FunctionCx.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Jan 14, 2018
1 parent 209abc7 commit 4e40a0d
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/librustc_trans/debuginfo/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
//!
//! All private state used by the module is stored within either the
//! CrateDebugContext struct (owned by the CodegenCx) or the
//! FunctionDebugContext (owned by the MirContext).
//! FunctionDebugContext (owned by the FunctionCx).
//!
//! This file consists of three conceptual sections:
//! 1. The public interface of the module
Expand Down
42 changes: 21 additions & 21 deletions src/librustc_trans/mir/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ use rustc::mir::traversal;
use rustc::ty;
use rustc::ty::layout::LayoutOf;
use type_of::LayoutLlvmExt;
use super::MirContext;
use super::FunctionCx;

pub fn memory_locals<'a, 'tcx>(mircx: &MirContext<'a, 'tcx>) -> BitVector {
let mir = mircx.mir;
let mut analyzer = LocalAnalyzer::new(mircx);
pub fn memory_locals<'a, 'tcx>(fx: &FunctionCx<'a, 'tcx>) -> BitVector {
let mir = fx.mir;
let mut analyzer = LocalAnalyzer::new(fx);

analyzer.visit_mir(mir);

for (index, ty) in mir.local_decls.iter().map(|l| l.ty).enumerate() {
let ty = mircx.monomorphize(&ty);
let ty = fx.monomorphize(&ty);
debug!("local {} has type {:?}", index, ty);
let layout = mircx.cx.layout_of(ty);
let layout = fx.cx.layout_of(ty);
if layout.is_llvm_immediate() {
// These sorts of types are immediates that we can store
// in an ValueRef without an alloca.
Expand All @@ -52,21 +52,21 @@ pub fn memory_locals<'a, 'tcx>(mircx: &MirContext<'a, 'tcx>) -> BitVector {
}

struct LocalAnalyzer<'mir, 'a: 'mir, 'tcx: 'a> {
cx: &'mir MirContext<'a, 'tcx>,
fx: &'mir FunctionCx<'a, 'tcx>,
memory_locals: BitVector,
seen_assigned: BitVector
}

impl<'mir, 'a, 'tcx> LocalAnalyzer<'mir, 'a, 'tcx> {
fn new(mircx: &'mir MirContext<'a, 'tcx>) -> LocalAnalyzer<'mir, 'a, 'tcx> {
fn new(fx: &'mir FunctionCx<'a, 'tcx>) -> LocalAnalyzer<'mir, 'a, 'tcx> {
let mut analyzer = LocalAnalyzer {
cx: mircx,
memory_locals: BitVector::new(mircx.mir.local_decls.len()),
seen_assigned: BitVector::new(mircx.mir.local_decls.len())
fx,
memory_locals: BitVector::new(fx.mir.local_decls.len()),
seen_assigned: BitVector::new(fx.mir.local_decls.len())
};

// Arguments get assigned to by means of the function being called
for idx in 0..mircx.mir.arg_count {
for idx in 0..fx.mir.arg_count {
analyzer.seen_assigned.insert(idx + 1);
}

Expand Down Expand Up @@ -95,7 +95,7 @@ impl<'mir, 'a, 'tcx> Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'tcx> {

if let mir::Place::Local(index) = *place {
self.mark_assigned(index);
if !self.cx.rvalue_creates_operand(rvalue) {
if !self.fx.rvalue_creates_operand(rvalue) {
self.mark_as_memory(index);
}
} else {
Expand All @@ -117,7 +117,7 @@ impl<'mir, 'a, 'tcx> Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'tcx> {
}, ..
}),
ref args, ..
} if Some(def_id) == self.cx.cx.tcx.lang_items().box_free_fn() => {
} if Some(def_id) == self.fx.cx.tcx.lang_items().box_free_fn() => {
// box_free(x) shares with `drop x` the property that it
// is not guaranteed to be statically dominated by the
// definition of x, so x must always be in an alloca.
Expand All @@ -136,7 +136,7 @@ impl<'mir, 'a, 'tcx> Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'tcx> {
context: PlaceContext<'tcx>,
location: Location) {
debug!("visit_place(place={:?}, context={:?})", place, context);
let cx = self.cx.cx;
let cx = self.fx.cx;

if let mir::Place::Projection(ref proj) = *place {
// Allow uses of projections that are ZSTs or from scalar fields.
Expand All @@ -145,12 +145,12 @@ impl<'mir, 'a, 'tcx> Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'tcx> {
_ => false
};
if is_consume {
let base_ty = proj.base.ty(self.cx.mir, cx.tcx);
let base_ty = self.cx.monomorphize(&base_ty);
let base_ty = proj.base.ty(self.fx.mir, cx.tcx);
let base_ty = self.fx.monomorphize(&base_ty);

// ZSTs don't require any actual memory access.
let elem_ty = base_ty.projection_ty(cx.tcx, &proj.elem).to_ty(cx.tcx);
let elem_ty = self.cx.monomorphize(&elem_ty);
let elem_ty = self.fx.monomorphize(&elem_ty);
if cx.layout_of(elem_ty).is_zst() {
return;
}
Expand Down Expand Up @@ -200,11 +200,11 @@ impl<'mir, 'a, 'tcx> Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'tcx> {
}

PlaceContext::Drop => {
let ty = mir::Place::Local(index).ty(self.cx.mir, self.cx.cx.tcx);
let ty = self.cx.monomorphize(&ty.to_ty(self.cx.cx.tcx));
let ty = mir::Place::Local(index).ty(self.fx.mir, self.fx.cx.tcx);
let ty = self.fx.monomorphize(&ty.to_ty(self.fx.cx.tcx));

// Only need the place if we're actually dropping it.
if self.cx.cx.type_needs_drop(ty) {
if self.fx.cx.type_needs_drop(ty) {
self.mark_as_memory(index);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trans/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ use type_::Type;
use syntax::symbol::Symbol;
use syntax_pos::Pos;

use super::{MirContext, LocalRef};
use super::{FunctionCx, LocalRef};
use super::constant::Const;
use super::place::PlaceRef;
use super::operand::OperandRef;
use super::operand::OperandValue::{Pair, Ref, Immediate};

impl<'a, 'tcx> MirContext<'a, 'tcx> {
impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
pub fn trans_block(&mut self, bb: mir::BasicBlock) {
let mut bx = self.build_block(bb);
let data = &self.mir[bb];
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trans/mir/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use std::fmt;
use std::ptr;

use super::operand::{OperandRef, OperandValue};
use super::MirContext;
use super::FunctionCx;

/// A sized constant rvalue.
/// The LLVM type might not be the same for a single Rust type,
Expand Down Expand Up @@ -1118,7 +1118,7 @@ unsafe fn cast_const_int_to_float(cx: &CodegenCx,
}
}

impl<'a, 'tcx> MirContext<'a, 'tcx> {
impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
pub fn trans_constant(&mut self,
bx: &Builder<'a, 'tcx>,
constant: &mir::Constant<'tcx>)
Expand Down
48 changes: 24 additions & 24 deletions src/librustc_trans/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use rustc::mir::traversal;
use self::operand::{OperandRef, OperandValue};

/// Master context for translating MIR.
pub struct MirContext<'a, 'tcx:'a> {
pub struct FunctionCx<'a, 'tcx:'a> {
mir: &'a mir::Mir<'tcx>,

debug_context: debuginfo::FunctionDebugContext,
Expand Down Expand Up @@ -102,7 +102,7 @@ pub struct MirContext<'a, 'tcx:'a> {
param_substs: &'tcx Substs<'tcx>,
}

impl<'a, 'tcx> MirContext<'a, 'tcx> {
impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
pub fn monomorphize<T>(&self, value: &T) -> T
where T: TransNormalize<'tcx>
{
Expand Down Expand Up @@ -224,7 +224,7 @@ pub fn trans_mir<'a, 'tcx: 'a>(
let scopes = debuginfo::create_mir_scopes(cx, mir, &debug_context);
let (landing_pads, funclets) = create_funclets(&bx, &cleanup_kinds, &block_bxs);

let mut mircx = MirContext {
let mut fx = FunctionCx {
mir,
llfn,
fn_ty,
Expand All @@ -244,20 +244,20 @@ pub fn trans_mir<'a, 'tcx: 'a>(
},
};

let memory_locals = analyze::memory_locals(&mircx);
let memory_locals = analyze::memory_locals(&fx);

// Allocate variable and temp allocas
mircx.locals = {
let args = arg_local_refs(&bx, &mircx, &mircx.scopes, &memory_locals);
fx.locals = {
let args = arg_local_refs(&bx, &fx, &fx.scopes, &memory_locals);

let mut allocate_local = |local| {
let decl = &mir.local_decls[local];
let layout = bx.cx.layout_of(mircx.monomorphize(&decl.ty));
let layout = bx.cx.layout_of(fx.monomorphize(&decl.ty));
assert!(!layout.ty.has_erasable_regions());

if let Some(name) = decl.name {
// User variable
let debug_scope = mircx.scopes[decl.source_info.scope];
let debug_scope = fx.scopes[decl.source_info.scope];
let dbg = debug_scope.is_valid() && bx.sess().opts.debuginfo == FullDebugInfo;

if !memory_locals.contains(local.index()) && !dbg {
Expand All @@ -268,15 +268,15 @@ pub fn trans_mir<'a, 'tcx: 'a>(
debug!("alloc: {:?} ({}) -> place", local, name);
let place = PlaceRef::alloca(&bx, layout, &name.as_str());
if dbg {
let (scope, span) = mircx.debug_loc(decl.source_info);
declare_local(&bx, &mircx.debug_context, name, layout.ty, scope,
let (scope, span) = fx.debug_loc(decl.source_info);
declare_local(&bx, &fx.debug_context, name, layout.ty, scope,
VariableAccess::DirectVariable { alloca: place.llval },
VariableKind::LocalVariable, span);
}
LocalRef::Place(place)
} else {
// Temporary or return place
if local == mir::RETURN_PLACE && mircx.fn_ty.ret.is_indirect() {
if local == mir::RETURN_PLACE && fx.fn_ty.ret.is_indirect() {
debug!("alloc: {:?} (return place) -> place", local);
let llretptr = llvm::get_param(llfn, 0);
LocalRef::Place(PlaceRef::new_sized(llretptr, layout, layout.align))
Expand All @@ -302,21 +302,21 @@ pub fn trans_mir<'a, 'tcx: 'a>(

// Branch to the START block, if it's not the entry block.
if reentrant_start_block {
bx.br(mircx.blocks[mir::START_BLOCK]);
bx.br(fx.blocks[mir::START_BLOCK]);
}

// Up until here, IR instructions for this function have explicitly not been annotated with
// source code location, so we don't step into call setup code. From here on, source location
// emitting should be enabled.
debuginfo::start_emitting_source_locations(&mircx.debug_context);
debuginfo::start_emitting_source_locations(&fx.debug_context);

let rpo = traversal::reverse_postorder(&mir);
let mut visited = BitVector::new(mir.basic_blocks().len());

// Translate the body of each block using reverse postorder
for (bb, _) in rpo {
visited.insert(bb.index());
mircx.trans_block(bb);
fx.trans_block(bb);
}

// Remove blocks that haven't been visited, or have no
Expand All @@ -326,7 +326,7 @@ pub fn trans_mir<'a, 'tcx: 'a>(
if !visited.contains(bb.index()) {
debug!("trans_mir: block {:?} was not visited", bb);
unsafe {
llvm::LLVMDeleteBasicBlock(mircx.blocks[bb]);
llvm::LLVMDeleteBasicBlock(fx.blocks[bb]);
}
}
}
Expand Down Expand Up @@ -356,14 +356,14 @@ fn create_funclets<'a, 'tcx>(
/// argument's value. As arguments are places, these are always
/// indirect.
fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
mircx: &MirContext<'a, 'tcx>,
fx: &FunctionCx<'a, 'tcx>,
scopes: &IndexVec<mir::VisibilityScope, debuginfo::MirDebugScope>,
memory_locals: &BitVector)
-> Vec<LocalRef<'tcx>> {
let mir = mircx.mir;
let mir = fx.mir;
let tcx = bx.tcx();
let mut idx = 0;
let mut llarg_idx = mircx.fn_ty.ret.is_indirect() as usize;
let mut llarg_idx = fx.fn_ty.ret.is_indirect() as usize;

// Get the argument scope, if it exists and if we need it.
let arg_scope = scopes[mir::ARGUMENT_VISIBILITY_SCOPE];
Expand Down Expand Up @@ -392,15 +392,15 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
// to reconstruct it into a tuple local variable, from multiple
// individual LLVM function arguments.

let arg_ty = mircx.monomorphize(&arg_decl.ty);
let arg_ty = fx.monomorphize(&arg_decl.ty);
let tupled_arg_tys = match arg_ty.sty {
ty::TyTuple(ref tys, _) => tys,
_ => bug!("spread argument isn't a tuple?!")
};

let place = PlaceRef::alloca(bx, bx.cx.layout_of(arg_ty), &name);
for i in 0..tupled_arg_tys.len() {
let arg = &mircx.fn_ty.args[idx];
let arg = &fx.fn_ty.args[idx];
idx += 1;
arg.store_fn_arg(bx, &mut llarg_idx, place.project_field(bx, i));
}
Expand All @@ -413,7 +413,7 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
};
declare_local(
bx,
&mircx.debug_context,
&fx.debug_context,
arg_decl.name.unwrap_or(keywords::Invalid.name()),
arg_ty, scope,
variable_access,
Expand All @@ -425,7 +425,7 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
return LocalRef::Place(place);
}

let arg = &mircx.fn_ty.args[idx];
let arg = &fx.fn_ty.args[idx];
idx += 1;
if arg.pad.is_some() {
llarg_idx += 1;
Expand Down Expand Up @@ -499,7 +499,7 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>,

declare_local(
bx,
&mircx.debug_context,
&fx.debug_context,
arg_decl.name.unwrap_or(keywords::Invalid.name()),
arg.layout.ty,
scope,
Expand Down Expand Up @@ -568,7 +568,7 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
};
declare_local(
bx,
&mircx.debug_context,
&fx.debug_context,
decl.debug_name,
ty,
scope,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trans/mir/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use type_::Type;
use std::fmt;
use std::ptr;

use super::{MirContext, LocalRef};
use super::{FunctionCx, LocalRef};
use super::place::PlaceRef;

/// The representation of a Rust value. The enum variant is in fact
Expand Down Expand Up @@ -241,7 +241,7 @@ impl<'a, 'tcx> OperandValue {
}
}

impl<'a, 'tcx> MirContext<'a, 'tcx> {
impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
fn maybe_trans_consume_direct(&mut self,
bx: &Builder<'a, 'tcx>,
place: &mir::Place<'tcx>)
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trans/mir/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use glue;

use std::ptr;

use super::{MirContext, LocalRef};
use super::{FunctionCx, LocalRef};
use super::operand::{OperandRef, OperandValue};

#[derive(Copy, Clone, Debug)]
Expand Down Expand Up @@ -399,7 +399,7 @@ impl<'a, 'tcx> PlaceRef<'tcx> {
}
}

impl<'a, 'tcx> MirContext<'a, 'tcx> {
impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
pub fn trans_place(&mut self,
bx: &Builder<'a, 'tcx>,
place: &mir::Place<'tcx>)
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trans/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ use type_::Type;
use type_of::LayoutLlvmExt;
use value::Value;

use super::{MirContext, LocalRef};
use super::{FunctionCx, LocalRef};
use super::constant::const_scalar_checked_binop;
use super::operand::{OperandRef, OperandValue};
use super::place::PlaceRef;

impl<'a, 'tcx> MirContext<'a, 'tcx> {
impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
pub fn trans_rvalue(&mut self,
bx: Builder<'a, 'tcx>,
dest: PlaceRef<'tcx>,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trans/mir/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ use rustc::mir;
use asm;
use builder::Builder;

use super::MirContext;
use super::FunctionCx;
use super::LocalRef;

impl<'a, 'tcx> MirContext<'a, 'tcx> {
impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
pub fn trans_statement(&mut self,
bx: Builder<'a, 'tcx>,
statement: &mir::Statement<'tcx>)
Expand Down

0 comments on commit 4e40a0d

Please sign in to comment.