提交 4e40a0d4 编写于 作者: E Eduard-Mihai Burtescu

rustc_trans: rename mircx: MirContext to fx: FunctionCx.

上级 209abc71
......@@ -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
......
......@@ -20,18 +20,18 @@
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.
......@@ -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);
}
......@@ -95,7 +95,7 @@ fn visit_assign(&mut self,
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 {
......@@ -117,7 +117,7 @@ fn visit_terminator_kind(&mut self,
}, ..
}),
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.
......@@ -136,7 +136,7 @@ fn visit_place(&mut self,
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.
......@@ -145,12 +145,12 @@ fn visit_place(&mut self,
_ => 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;
}
......@@ -200,11 +200,11 @@ fn visit_local(&mut self,
}
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);
}
}
......
......@@ -29,13 +29,13 @@
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];
......
......@@ -43,7 +43,7 @@
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,
......@@ -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>)
......
......@@ -41,7 +41,7 @@
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,
......@@ -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>
{
......@@ -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,
......@@ -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 {
......@@ -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))
......@@ -302,13 +302,13 @@ 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());
......@@ -316,7 +316,7 @@ pub fn trans_mir<'a, 'tcx: 'a>(
// 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
......@@ -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]);
}
}
}
......@@ -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];
......@@ -392,7 +392,7 @@ 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?!")
......@@ -400,7 +400,7 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
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));
}
......@@ -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,
......@@ -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;
......@@ -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,
......@@ -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,
......
......@@ -24,7 +24,7 @@
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
......@@ -241,7 +241,7 @@ pub fn store(self, bx: &Builder<'a, 'tcx>, dest: PlaceRef<'tcx>) {
}
}
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>)
......
......@@ -25,7 +25,7 @@
use std::ptr;
use super::{MirContext, LocalRef};
use super::{FunctionCx, LocalRef};
use super::operand::{OperandRef, OperandValue};
#[derive(Copy, Clone, Debug)]
......@@ -399,7 +399,7 @@ pub fn storage_dead(&self, bx: &Builder<'a, '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>)
......
......@@ -29,12 +29,12 @@
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>,
......
......@@ -13,10 +13,10 @@
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>)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册