提交 c85501b9 编写于 作者: A Ariel Ben-Yehuda

box large variants in MIR

Operand: 72 -> 24 B
Statement: 192 -> 96 B
Terminator: 256 -> 112 B
librustc translation memory usage: 1795 -> 1669 MB

next step would be interning lvalues, I suppose?
上级 2b97174a
......@@ -799,7 +799,7 @@ pub enum StatementKind<'tcx> {
StorageDead(Lvalue<'tcx>),
InlineAsm {
asm: InlineAsm,
asm: Box<InlineAsm>,
outputs: Vec<Lvalue<'tcx>>,
inputs: Vec<Operand<'tcx>>
},
......@@ -995,7 +995,7 @@ pub struct VisibilityScopeData {
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable)]
pub enum Operand<'tcx> {
Consume(Lvalue<'tcx>),
Constant(Constant<'tcx>),
Constant(Box<Constant<'tcx>>),
}
impl<'tcx> Debug for Operand<'tcx> {
......@@ -1015,7 +1015,7 @@ pub fn function_handle<'a>(
substs: &'tcx Substs<'tcx>,
span: Span,
) -> Self {
Operand::Constant(Constant {
Operand::Constant(box Constant {
span: span,
ty: tcx.type_of(def_id).subst(tcx, substs),
literal: Literal::Value { value: ConstVal::Function(def_id, substs) },
......@@ -1062,7 +1062,7 @@ pub enum Rvalue<'tcx> {
/// ..., y: ... }` from `dest.x = ...; dest.y = ...;` in the case
/// that `Foo` has a destructor. These rvalues can be optimized
/// away after type-checking and before lowering.
Aggregate(AggregateKind<'tcx>, Vec<Operand<'tcx>>),
Aggregate(Box<AggregateKind<'tcx>>, Vec<Operand<'tcx>>),
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)]
......@@ -1185,7 +1185,7 @@ fn fmt_tuple(fmt: &mut Formatter, lvs: &[Operand]) -> fmt::Result {
tuple_fmt.finish()
}
match *kind {
match **kind {
AggregateKind::Array(_) => write!(fmt, "{:?}", lvs),
AggregateKind::Tuple => {
......@@ -1603,7 +1603,7 @@ fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F)
Discriminant(ref lval) => Discriminant(lval.fold_with(folder)),
Box(ty) => Box(ty.fold_with(folder)),
Aggregate(ref kind, ref fields) => {
let kind = match *kind {
let kind = box match **kind {
AggregateKind::Array(ty) => AggregateKind::Array(ty.fold_with(folder)),
AggregateKind::Tuple => AggregateKind::Tuple,
AggregateKind::Adt(def, v, substs, n) =>
......@@ -1631,7 +1631,7 @@ fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
Discriminant(ref lval) => lval.visit_with(visitor),
Box(ty) => ty.visit_with(visitor),
Aggregate(ref kind, ref fields) => {
(match *kind {
(match **kind {
AggregateKind::Array(ty) => ty.visit_with(visitor),
AggregateKind::Tuple => false,
AggregateKind::Adt(_, _, substs, _) => substs.visit_with(visitor),
......
......@@ -183,7 +183,7 @@ pub fn ty<'a, 'gcx>(&self, mir: &Mir<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'
tcx.mk_box(t)
}
Rvalue::Aggregate(ref ak, ref ops) => {
match *ak {
match **ak {
AggregateKind::Array(ty) => {
tcx.mk_array(ty, ops.len())
}
......
......@@ -515,6 +515,7 @@ fn super_rvalue(&mut self,
Rvalue::Aggregate(ref $($mutability)* kind,
ref $($mutability)* operands) => {
let kind = &$($mutability)* **kind;
match *kind {
AggregateKind::Array(ref $($mutability)* ty) => {
self.visit_ty(ty);
......
......@@ -517,11 +517,11 @@ fn elaborate_replace(
}
fn constant_bool(&self, span: Span, val: bool) -> Rvalue<'tcx> {
Rvalue::Use(Operand::Constant(Constant {
Rvalue::Use(Operand::Constant(Box::new(Constant {
span: span,
ty: self.tcx.types.bool,
literal: Literal::Value { value: ConstVal::Bool(val) }
}))
})))
}
fn set_drop_flag(&mut self, loc: Location, path: MovePathIndex, val: DropFlagState) {
......
......@@ -60,7 +60,7 @@ pub fn push_assign_constant(&mut self,
temp: &Lvalue<'tcx>,
constant: Constant<'tcx>) {
self.push_assign(block, source_info, temp,
Rvalue::Use(Operand::Constant(constant)));
Rvalue::Use(Operand::Constant(box constant)));
}
pub fn push_assign_unit(&mut self,
......@@ -68,7 +68,7 @@ pub fn push_assign_unit(&mut self,
source_info: SourceInfo,
lvalue: &Lvalue<'tcx>) {
self.push_assign(block, source_info, lvalue, Rvalue::Aggregate(
AggregateKind::Tuple, vec![]
box AggregateKind::Tuple, vec![]
));
}
......
......@@ -66,7 +66,7 @@ fn expr_as_operand(&mut self,
match category {
Category::Constant => {
let constant = this.as_constant(expr);
block.and(Operand::Constant(constant))
block.and(Operand::Constant(box constant))
}
Category::Lvalue |
Category::Rvalue(..) => {
......
......@@ -166,7 +166,7 @@ fn expr_as_rvalue(&mut self,
.map(|f| unpack!(block = this.as_operand(block, scope, f)))
.collect();
block.and(Rvalue::Aggregate(AggregateKind::Array(el_ty), fields))
block.and(Rvalue::Aggregate(box AggregateKind::Array(el_ty), fields))
}
ExprKind::Tuple { fields } => { // see (*) above
// first process the set of fields
......@@ -175,14 +175,14 @@ fn expr_as_rvalue(&mut self,
.map(|f| unpack!(block = this.as_operand(block, scope, f)))
.collect();
block.and(Rvalue::Aggregate(AggregateKind::Tuple, fields))
block.and(Rvalue::Aggregate(box AggregateKind::Tuple, fields))
}
ExprKind::Closure { closure_id, substs, upvars } => { // see (*) above
let upvars =
upvars.into_iter()
.map(|upvar| unpack!(block = this.as_operand(block, scope, upvar)))
.collect();
block.and(Rvalue::Aggregate(AggregateKind::Closure(closure_id, substs), upvars))
block.and(Rvalue::Aggregate(box AggregateKind::Closure(closure_id, substs), upvars))
}
ExprKind::Adt {
adt_def, variant_index, substs, fields, base
......@@ -215,7 +215,8 @@ fn expr_as_rvalue(&mut self,
field_names.iter().filter_map(|n| fields_map.get(n).cloned()).collect()
};
let adt = AggregateKind::Adt(adt_def, variant_index, substs, active_field_index);
let adt =
box AggregateKind::Adt(adt_def, variant_index, substs, active_field_index);
block.and(Rvalue::Aggregate(adt, fields))
}
ExprKind::Assign { .. } |
......
......@@ -129,7 +129,7 @@ pub fn stmt_expr(&mut self, mut block: BasicBlock, expr: Expr<'tcx>) -> BlockAnd
this.cfg.push(block, Statement {
source_info: source_info,
kind: StatementKind::InlineAsm {
asm: asm.clone(),
asm: box asm.clone(),
outputs: outputs,
inputs: inputs
},
......
......@@ -308,7 +308,7 @@ pub fn perform_test(&mut self,
let eq_block = self.cfg.start_new_block();
let cleanup = self.diverge_cleanup();
self.cfg.terminate(block, source_info, TerminatorKind::Call {
func: Operand::Constant(Constant {
func: Operand::Constant(box Constant {
span: test.span,
ty: mty,
literal: method
......
......@@ -40,7 +40,7 @@ pub fn literal_operand(&mut self,
ty: Ty<'tcx>,
literal: Literal<'tcx>)
-> Operand<'tcx> {
let constant = Constant {
let constant = box Constant {
span: span,
ty: ty,
literal: literal,
......@@ -49,7 +49,7 @@ pub fn literal_operand(&mut self,
}
pub fn unit_rvalue(&mut self) -> Rvalue<'tcx> {
Rvalue::Aggregate(AggregateKind::Tuple, vec![])
Rvalue::Aggregate(box AggregateKind::Tuple, vec![])
}
// Returns a zero literal operand for the appropriate type, works for
......
......@@ -786,7 +786,7 @@ fn build_free<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
let free_func = tcx.require_lang_item(lang_items::BoxFreeFnLangItem);
let substs = tcx.intern_substs(&[Kind::from(data.item_ty)]);
TerminatorKind::Call {
func: Operand::Constant(Constant {
func: Operand::Constant(box Constant {
span: data.span,
ty: tcx.type_of(free_func).subst(tcx, substs),
literal: Literal::Value {
......
......@@ -323,7 +323,7 @@ fn build_call_shim<'a, 'tcx>(tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
let (callee, mut args) = match call_kind {
CallKind::Indirect => (rcvr, vec![]),
CallKind::Direct(def_id) => (
Operand::Constant(Constant {
Operand::Constant(box Constant {
span: span,
ty: tcx.type_of(def_id).subst(tcx, param_env.free_substs),
literal: Literal::Value {
......@@ -449,7 +449,7 @@ pub fn build_adt_ctor<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a, 'gcx, 'tcx>,
kind: StatementKind::Assign(
Lvalue::Local(RETURN_POINTER),
Rvalue::Aggregate(
AggregateKind::Adt(adt_def, variant_no, substs, None),
box AggregateKind::Adt(adt_def, variant_no, substs, None),
(1..sig.inputs().len()+1).map(|i| {
Operand::Consume(Lvalue::Local(Local::new(i)))
}).collect()
......
......@@ -316,7 +316,7 @@ fn visit_operand(&mut self, operand: &mut Operand<'tcx>, location: Location) {
_ => return,
}
*operand = Operand::Constant(self.constant.clone());
*operand = Operand::Constant(box self.constant.clone());
self.uses_replaced += 1
}
}
......@@ -49,8 +49,8 @@ fn run_pass<'a, 'tcx>(&self,
&Rvalue::Aggregate(ref agg_kind, ref operands) => (agg_kind, operands),
_ => span_bug!(src_info.span, "expected aggregate, not {:?}", rhs),
};
let (adt_def, variant, substs) = match agg_kind {
&AggregateKind::Adt(adt_def, variant, substs, None)
let (adt_def, variant, substs) = match **agg_kind {
AggregateKind::Adt(adt_def, variant, substs, None)
=> (adt_def, variant, substs),
_ => span_bug!(src_info.span, "expected struct, not {:?}", rhs),
};
......@@ -114,8 +114,8 @@ fn get_aggregate_statement_index<'a, 'tcx, 'b>(start: usize,
&Rvalue::Aggregate(ref kind, ref operands) => (kind, operands),
_ => continue,
};
let (adt_def, variant) = match kind {
&AggregateKind::Adt(adt_def, variant, _, None) => (adt_def, variant),
let (adt_def, variant) = match **kind {
AggregateKind::Adt(adt_def, variant, _, None) => (adt_def, variant),
_ => continue,
};
if operands.len() == 0 {
......
......@@ -230,7 +230,7 @@ fn promote_temp(&mut self, temp: Local) -> Local {
(if self.keep_original {
rhs.clone()
} else {
let unit = Rvalue::Aggregate(AggregateKind::Tuple, vec![]);
let unit = Rvalue::Aggregate(box AggregateKind::Tuple, vec![]);
mem::replace(rhs, unit)
}, statement.source_info)
};
......@@ -288,7 +288,7 @@ fn promote_temp(&mut self, temp: Local) -> Local {
fn promote_candidate(mut self, candidate: Candidate) {
let span = self.promoted.span;
let new_operand = Operand::Constant(Constant {
let new_operand = Operand::Constant(box Constant {
span: span,
ty: self.promoted.return_ty,
literal: Literal::Promoted {
......
......@@ -730,7 +730,7 @@ fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
}
Rvalue::Aggregate(ref kind, _) => {
if let AggregateKind::Adt(def, ..) = *kind {
if let AggregateKind::Adt(def, ..) = **kind {
if def.has_dtor(self.tcx) {
self.add(Qualif::NEEDS_DROP);
self.deny_drop();
......
......@@ -37,7 +37,7 @@ fn run_pass<'a, 'tcx>(&self,
for block in mir.basic_blocks_mut() {
let terminator = block.terminator_mut();
terminator.kind = match terminator.kind {
TerminatorKind::SwitchInt { discr: Operand::Constant(Constant {
TerminatorKind::SwitchInt { discr: Operand::Constant(box Constant {
literal: Literal::Value { ref value }, ..
}), ref values, ref targets, .. } => {
if let Some(ref constint) = value.to_const_int() {
......@@ -54,7 +54,7 @@ fn run_pass<'a, 'tcx>(&self,
continue
}
},
TerminatorKind::Assert { target, cond: Operand::Constant(Constant {
TerminatorKind::Assert { target, cond: Operand::Constant(box Constant {
literal: Literal::Value {
value: ConstVal::Bool(cond)
}, ..
......@@ -66,4 +66,3 @@ fn run_pass<'a, 'tcx>(&self,
}
}
}
......@@ -534,7 +534,7 @@ fn check_call_inputs(&mut self,
fn is_box_free(&self, operand: &Operand<'tcx>) -> bool {
match operand {
&Operand::Constant(Constant {
&Operand::Constant(box Constant {
literal: Literal::Value {
value: ConstVal::Function(def_id, _), ..
}, ..
......
......@@ -190,7 +190,7 @@ fn visit_rvalue(&mut self,
Rvalue::Aggregate(ref kind, ref _operands) => {
// AggregateKind is not distinguished by visit API, so
// record it. (`super_rvalue` handles `_operands`.)
self.record(match *kind {
self.record(match **kind {
AggregateKind::Array(_) => "AggregateKind::Array",
AggregateKind::Tuple => "AggregateKind::Tuple",
AggregateKind::Adt(..) => "AggregateKind::Adt",
......
......@@ -108,7 +108,7 @@ fn visit_terminator_kind(&mut self,
location: Location) {
match *kind {
mir::TerminatorKind::Call {
func: mir::Operand::Constant(mir::Constant {
func: mir::Operand::Constant(box mir::Constant {
literal: Literal::Value {
value: ConstVal::Function(def_id, _), ..
}, ..
......
......@@ -537,7 +537,7 @@ fn const_rvalue(&self, rvalue: &mir::Rvalue<'tcx>,
}
failure?;
match *kind {
match **kind {
mir::AggregateKind::Array(_) => {
self.const_array(dest_ty, &fields)
}
......
......@@ -104,7 +104,7 @@ pub fn trans_rvalue(&mut self,
}
mir::Rvalue::Aggregate(ref kind, ref operands) => {
match *kind {
match **kind {
mir::AggregateKind::Adt(adt_def, variant_index, substs, active_field_index) => {
let discr = adt_def.discriminant_for_variant(bcx.tcx(), variant_index)
.to_u128_unchecked() as u64;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册