Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shrink mir::Statement. #59630

Merged
merged 1 commit into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use crate::hir::def::{CtorKind, Namespace};
use crate::hir::def_id::DefId;
use crate::hir::{self, HirId, InlineAsm};
use crate::hir::{self, HirId, InlineAsm as HirInlineAsm};
use crate::mir::interpret::{ConstValue, InterpError, Scalar};
use crate::mir::visit::MirVisitable;
use rustc_apfloat::ieee::{Double, Single};
Expand Down Expand Up @@ -1735,7 +1735,7 @@ pub struct Statement<'tcx> {

// `Statement` is used a lot. Make sure it doesn't unintentionally get bigger.
#[cfg(target_arch = "x86_64")]
static_assert!(MEM_SIZE_OF_STATEMENT: mem::size_of::<Statement<'_>>() == 56);
static_assert!(MEM_SIZE_OF_STATEMENT: mem::size_of::<Statement<'_>>() == 48);

impl<'tcx> Statement<'tcx> {
/// Changes a statement to a nop. This is both faster than deleting instructions and avoids
Expand Down Expand Up @@ -1779,12 +1779,9 @@ pub enum StatementKind<'tcx> {
/// End the current live range for the storage of the local.
StorageDead(Local),

/// Executes a piece of inline Assembly.
InlineAsm {
asm: Box<InlineAsm>,
outputs: Box<[Place<'tcx>]>,
inputs: Box<[(Span, Operand<'tcx>)]>,
},
/// Executes a piece of inline Assembly. Stored in a Box to keep the size
/// of `StatementKind` low.
InlineAsm(Box<InlineAsm<'tcx>>),

/// Retag references in the given place, ensuring they got fresh tags. This is
/// part of the Stacked Borrows model. These statements are currently only interpreted
Expand Down Expand Up @@ -1858,6 +1855,13 @@ pub enum FakeReadCause {
ForLet,
}

#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
pub struct InlineAsm<'tcx> {
pub asm: HirInlineAsm,
pub outputs: Box<[Place<'tcx>]>,
pub inputs: Box<[(Span, Operand<'tcx>)]>,
}

impl<'tcx> Debug for Statement<'tcx> {
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
use self::StatementKind::*;
Expand All @@ -1880,11 +1884,8 @@ impl<'tcx> Debug for Statement<'tcx> {
ref place,
variant_index,
} => write!(fmt, "discriminant({:?}) = {:?}", place, variant_index),
InlineAsm {
ref asm,
ref outputs,
ref inputs,
} => write!(fmt, "asm!({:?} : {:?} : {:?})", asm, outputs, inputs),
InlineAsm(ref asm) =>
write!(fmt, "asm!({:?} : {:?} : {:?})", asm.asm, asm.outputs, asm.inputs),
AscribeUserType(ref place, ref variance, ref c_ty) => {
write!(fmt, "AscribeUserType({:?}, {:?}, {:?})", place, variance, c_ty)
}
Expand Down Expand Up @@ -3140,13 +3141,21 @@ EnumTypeFoldableImpl! {
(StatementKind::SetDiscriminant) { place, variant_index },
(StatementKind::StorageLive)(a),
(StatementKind::StorageDead)(a),
(StatementKind::InlineAsm) { asm, outputs, inputs },
(StatementKind::InlineAsm)(a),
(StatementKind::Retag)(kind, place),
(StatementKind::AscribeUserType)(a, v, b),
(StatementKind::Nop),
}
}

BraceStructTypeFoldableImpl! {
impl<'tcx> TypeFoldable<'tcx> for InlineAsm<'tcx> {
asm,
outputs,
inputs,
}
}

EnumTypeFoldableImpl! {
impl<'tcx, T> TypeFoldable<'tcx> for ClearCrossCrate<T> {
(ClearCrossCrate::Clear),
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,15 +391,15 @@ macro_rules! make_mir_visitor {
location
);
}
StatementKind::InlineAsm { outputs, inputs, asm: _ } => {
for output in & $($mutability)? outputs[..] {
StatementKind::InlineAsm(asm) => {
for output in & $($mutability)? asm.outputs[..] {
self.visit_place(
output,
PlaceContext::MutatingUse(MutatingUseContext::AsmOutput),
location
);
}
for (span, input) in & $($mutability)? inputs[..] {
for (span, input) in & $($mutability)? asm.inputs[..] {
self.visit_span(span);
self.visit_operand(input, location);
}
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_codegen_ssa/mir/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}
bx
}
mir::StatementKind::InlineAsm { ref asm, ref outputs, ref inputs } => {
let outputs = outputs.iter().map(|output| {
mir::StatementKind::InlineAsm(ref asm) => {
let outputs = asm.outputs.iter().map(|output| {
self.codegen_place(&mut bx, output)
}).collect();

let input_vals = inputs.iter()
.fold(Vec::with_capacity(inputs.len()), |mut acc, (span, input)| {
let input_vals = asm.inputs.iter()
.fold(Vec::with_capacity(asm.inputs.len()), |mut acc, (span, input)| {
let op = self.codegen_operand(&mut bx, input);
if let OperandValue::Immediate(_) = op.val {
acc.push(op.immediate());
Expand All @@ -85,8 +85,8 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
acc
});

if input_vals.len() == inputs.len() {
let res = bx.codegen_inline_asm(asm, outputs, input_vals);
if input_vals.len() == asm.inputs.len() {
let res = bx.codegen_inline_asm(&asm.asm, outputs, input_vals);
if !res {
span_err!(bx.sess(), statement.source_info.span, E0668,
"malformed inline assembly");
Expand Down
12 changes: 4 additions & 8 deletions src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,16 +525,12 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
flow_state,
);
}
StatementKind::InlineAsm {
ref asm,
ref outputs,
ref inputs,
} => {
StatementKind::InlineAsm(ref asm) => {
let context = ContextKind::InlineAsm.new(location);
for (o, output) in asm.outputs.iter().zip(outputs.iter()) {
for (o, output) in asm.asm.outputs.iter().zip(asm.outputs.iter()) {
if o.is_indirect {
// FIXME(eddyb) indirect inline asm outputs should
// be encoeded through MIR place derefs instead.
// be encoded through MIR place derefs instead.
self.access_place(
context,
(output, o.span),
Expand All @@ -558,7 +554,7 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
);
}
}
for (_, input) in inputs.iter() {
for (_, input) in asm.inputs.iter() {
self.consume_operand(context, (input, span), flow_state);
}
}
Expand Down
12 changes: 4 additions & 8 deletions src/librustc_mir/borrow_check/nll/invalidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,12 @@ impl<'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx, 'gcx> {
JustWrite,
);
}
StatementKind::InlineAsm {
ref asm,
ref outputs,
ref inputs,
} => {
StatementKind::InlineAsm(ref asm) => {
let context = ContextKind::InlineAsm.new(location);
for (o, output) in asm.outputs.iter().zip(outputs.iter()) {
for (o, output) in asm.asm.outputs.iter().zip(asm.outputs.iter()) {
if o.is_indirect {
// FIXME(eddyb) indirect inline asm outputs should
// be encoeded through MIR place derefs instead.
// be encoded through MIR place derefs instead.
self.access_place(
context,
output,
Expand All @@ -117,7 +113,7 @@ impl<'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx, 'gcx> {
);
}
}
for (_, input) in inputs.iter() {
for (_, input) in asm.inputs.iter() {
self.consume_operand(context, input);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/build/expr/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
block,
Statement {
source_info,
kind: StatementKind::InlineAsm {
asm: box asm.clone(),
kind: StatementKind::InlineAsm(box InlineAsm {
asm: asm.clone(),
outputs,
inputs,
},
}),
},
);
this.block_context.pop();
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/dataflow/impls/borrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ impl<'a, 'gcx, 'tcx> BitDenotation<'tcx> for Borrows<'a, 'gcx, 'tcx> {
self.kill_borrows_on_place(sets, &Place::Base(PlaceBase::Local(local)));
}

mir::StatementKind::InlineAsm { ref outputs, ref asm, .. } => {
for (output, kind) in outputs.iter().zip(&asm.outputs) {
mir::StatementKind::InlineAsm(ref asm) => {
for (output, kind) in asm.outputs.iter().zip(&asm.asm.outputs) {
if !kind.is_indirect && !kind.is_rw {
self.kill_borrows_on_place(sets, output);
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/dataflow/move_paths/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,13 @@ impl<'b, 'a, 'gcx, 'tcx> Gatherer<'b, 'a, 'gcx, 'tcx> {
StatementKind::FakeRead(_, ref place) => {
self.create_move_path(place);
}
StatementKind::InlineAsm { ref outputs, ref inputs, ref asm } => {
for (output, kind) in outputs.iter().zip(&asm.outputs) {
StatementKind::InlineAsm(ref asm) => {
for (output, kind) in asm.outputs.iter().zip(&asm.asm.outputs) {
if !kind.is_indirect {
self.gather_init(output, InitKind::Deep);
}
}
for (_, input) in inputs.iter() {
for (_, input) in asm.inputs.iter() {
self.gather_operand(input);
}
}
Expand Down