Skip to content

Commit 411b298

Browse files
authored
Rollup merge of rust-lang#66515 - Centril:cheaper-inline-asm, r=oli-obk
Reduce size of `hir::Expr` by boxing more of `hir::InlineAsm` r? @oli-obk
2 parents 4aceeff + 44cebe5 commit 411b298

File tree

13 files changed

+74
-59
lines changed

13 files changed

+74
-59
lines changed

src/librustc/hir/intravisit.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1086,10 +1086,9 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
10861086
ExprKind::Ret(ref optional_expression) => {
10871087
walk_list!(visitor, visit_expr, optional_expression);
10881088
}
1089-
ExprKind::InlineAsm(_, ref outputs, ref inputs) => {
1090-
for expr in outputs.iter().chain(inputs.iter()) {
1091-
visitor.visit_expr(expr)
1092-
}
1089+
ExprKind::InlineAsm(ref asm) => {
1090+
walk_list!(visitor, visit_expr, &asm.outputs_exprs);
1091+
walk_list!(visitor, visit_expr, &asm.inputs_exprs);
10931092
}
10941093
ExprKind::Yield(ref subexpression, _) => {
10951094
visitor.visit_expr(subexpression);

src/librustc/hir/lowering/expr.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ impl LoweringContext<'_> {
966966
}
967967

968968
fn lower_expr_asm(&mut self, asm: &InlineAsm) -> hir::ExprKind {
969-
let hir_asm = hir::InlineAsm {
969+
let inner = hir::InlineAsmInner {
970970
inputs: asm.inputs.iter().map(|&(ref c, _)| c.clone()).collect(),
971971
outputs: asm.outputs
972972
.iter()
@@ -984,18 +984,18 @@ impl LoweringContext<'_> {
984984
alignstack: asm.alignstack,
985985
dialect: asm.dialect,
986986
};
987-
988-
let outputs = asm.outputs
989-
.iter()
990-
.map(|out| self.lower_expr(&out.expr))
991-
.collect();
992-
993-
let inputs = asm.inputs
994-
.iter()
995-
.map(|&(_, ref input)| self.lower_expr(input))
996-
.collect();
997-
998-
hir::ExprKind::InlineAsm(P(hir_asm), outputs, inputs)
987+
let hir_asm = hir::InlineAsm {
988+
inner,
989+
inputs_exprs: asm.inputs
990+
.iter()
991+
.map(|&(_, ref input)| self.lower_expr(input))
992+
.collect(),
993+
outputs_exprs: asm.outputs
994+
.iter()
995+
.map(|out| self.lower_expr(&out.expr))
996+
.collect(),
997+
};
998+
hir::ExprKind::InlineAsm(P(hir_asm))
999999
}
10001000

10011001
fn lower_field(&mut self, f: &Field) -> hir::Field {

src/librustc/hir/mod.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,7 @@ pub struct Expr {
14571457

14581458
// `Expr` is used a lot. Make sure it doesn't unintentionally get bigger.
14591459
#[cfg(target_arch = "x86_64")]
1460-
static_assert_size!(Expr, 72);
1460+
static_assert_size!(Expr, 64);
14611461

14621462
impl Expr {
14631463
pub fn precedence(&self) -> ExprPrecedence {
@@ -1656,7 +1656,7 @@ pub enum ExprKind {
16561656
Ret(Option<P<Expr>>),
16571657

16581658
/// Inline assembly (from `asm!`), with its outputs and inputs.
1659-
InlineAsm(P<InlineAsm>, HirVec<Expr>, HirVec<Expr>),
1659+
InlineAsm(P<InlineAsm>),
16601660

16611661
/// A struct or struct-like variant literal expression.
16621662
///
@@ -2063,7 +2063,7 @@ pub struct InlineAsmOutput {
20632063
// NOTE(eddyb) This is used within MIR as well, so unlike the rest of the HIR,
20642064
// it needs to be `Clone` and use plain `Vec<T>` instead of `HirVec<T>`.
20652065
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)]
2066-
pub struct InlineAsm {
2066+
pub struct InlineAsmInner {
20672067
pub asm: Symbol,
20682068
pub asm_str_style: StrStyle,
20692069
pub outputs: Vec<InlineAsmOutput>,
@@ -2074,6 +2074,13 @@ pub struct InlineAsm {
20742074
pub dialect: AsmDialect,
20752075
}
20762076

2077+
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
2078+
pub struct InlineAsm {
2079+
pub inner: InlineAsmInner,
2080+
pub outputs_exprs: HirVec<Expr>,
2081+
pub inputs_exprs: HirVec<Expr>,
2082+
}
2083+
20772084
/// Represents a parameter in a function header.
20782085
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
20792086
pub struct Param {

src/librustc/hir/print.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -1365,14 +1365,15 @@ impl<'a> State<'a> {
13651365
self.print_expr_maybe_paren(&expr, parser::PREC_JUMP);
13661366
}
13671367
}
1368-
hir::ExprKind::InlineAsm(ref a, ref outputs, ref inputs) => {
1368+
hir::ExprKind::InlineAsm(ref a) => {
1369+
let i = &a.inner;
13691370
self.s.word("asm!");
13701371
self.popen();
1371-
self.print_string(&a.asm.as_str(), a.asm_str_style);
1372+
self.print_string(&i.asm.as_str(), i.asm_str_style);
13721373
self.word_space(":");
13731374

13741375
let mut out_idx = 0;
1375-
self.commasep(Inconsistent, &a.outputs, |s, out| {
1376+
self.commasep(Inconsistent, &i.outputs, |s, out| {
13761377
let constraint = out.constraint.as_str();
13771378
let mut ch = constraint.chars();
13781379
match ch.next() {
@@ -1383,36 +1384,36 @@ impl<'a> State<'a> {
13831384
_ => s.print_string(&constraint, ast::StrStyle::Cooked),
13841385
}
13851386
s.popen();
1386-
s.print_expr(&outputs[out_idx]);
1387+
s.print_expr(&a.outputs_exprs[out_idx]);
13871388
s.pclose();
13881389
out_idx += 1;
13891390
});
13901391
self.s.space();
13911392
self.word_space(":");
13921393

13931394
let mut in_idx = 0;
1394-
self.commasep(Inconsistent, &a.inputs, |s, co| {
1395+
self.commasep(Inconsistent, &i.inputs, |s, co| {
13951396
s.print_string(&co.as_str(), ast::StrStyle::Cooked);
13961397
s.popen();
1397-
s.print_expr(&inputs[in_idx]);
1398+
s.print_expr(&a.inputs_exprs[in_idx]);
13981399
s.pclose();
13991400
in_idx += 1;
14001401
});
14011402
self.s.space();
14021403
self.word_space(":");
14031404

1404-
self.commasep(Inconsistent, &a.clobbers, |s, co| {
1405+
self.commasep(Inconsistent, &i.clobbers, |s, co| {
14051406
s.print_string(&co.as_str(), ast::StrStyle::Cooked);
14061407
});
14071408

14081409
let mut options = vec![];
1409-
if a.volatile {
1410+
if i.volatile {
14101411
options.push("volatile");
14111412
}
1412-
if a.alignstack {
1413+
if i.alignstack {
14131414
options.push("alignstack");
14141415
}
1415-
if a.dialect == ast::AsmDialect::Intel {
1416+
if i.dialect == ast::AsmDialect::Intel {
14161417
options.push("intel");
14171418
}
14181419

src/librustc/middle/expr_use_visitor.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,15 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
283283
self.borrow_expr(&base, bk);
284284
}
285285

286-
hir::ExprKind::InlineAsm(ref ia, ref outputs, ref inputs) => {
287-
for (o, output) in ia.outputs.iter().zip(outputs) {
286+
hir::ExprKind::InlineAsm(ref ia) => {
287+
for (o, output) in ia.inner.outputs.iter().zip(&ia.outputs_exprs) {
288288
if o.is_indirect {
289289
self.consume_expr(output);
290290
} else {
291291
self.mutate_expr(output);
292292
}
293293
}
294-
self.consume_exprs(inputs);
294+
self.consume_exprs(&ia.inputs_exprs);
295295
}
296296

297297
hir::ExprKind::Continue(..) |

src/librustc/mir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
use crate::hir::def::{CtorKind, Namespace};
88
use crate::hir::def_id::DefId;
9-
use crate::hir::{self, InlineAsm as HirInlineAsm};
9+
use crate::hir;
1010
use crate::mir::interpret::{PanicInfo, Scalar};
1111
use crate::mir::visit::MirVisitable;
1212
use crate::ty::adjustment::PointerCast;
@@ -1638,7 +1638,7 @@ pub enum FakeReadCause {
16381638

16391639
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable, TypeFoldable)]
16401640
pub struct InlineAsm<'tcx> {
1641-
pub asm: HirInlineAsm,
1641+
pub asm: hir::InlineAsmInner,
16421642
pub outputs: Box<[Place<'tcx>]>,
16431643
pub inputs: Box<[(Span, Operand<'tcx>)]>,
16441644
}

src/librustc/ty/structural_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ CloneTypeFoldableAndLiftImpls! {
301301
::syntax_pos::symbol::Symbol,
302302
crate::hir::def::Res,
303303
crate::hir::def_id::DefId,
304-
crate::hir::InlineAsm,
304+
crate::hir::InlineAsmInner,
305305
crate::hir::MatchSource,
306306
crate::hir::Mutability,
307307
crate::hir::Unsafety,

src/librustc_codegen_llvm/asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use libc::{c_uint, c_char};
1717
impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
1818
fn codegen_inline_asm(
1919
&mut self,
20-
ia: &hir::InlineAsm,
20+
ia: &hir::InlineAsmInner,
2121
outputs: Vec<PlaceRef<'tcx, &'ll Value>>,
2222
mut inputs: Vec<&'ll Value>,
2323
span: Span,

src/librustc_codegen_ssa/traits/asm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use super::BackendTypes;
22
use crate::mir::place::PlaceRef;
3-
use rustc::hir::{GlobalAsm, InlineAsm};
3+
use rustc::hir::{GlobalAsm, InlineAsmInner};
44
use syntax_pos::Span;
55

66
pub trait AsmBuilderMethods<'tcx>: BackendTypes {
77
/// Take an inline assembly expression and splat it out via LLVM
88
fn codegen_inline_asm(
99
&mut self,
10-
ia: &InlineAsm,
10+
ia: &InlineAsmInner,
1111
outputs: Vec<PlaceRef<'tcx, Self::Value>>,
1212
inputs: Vec<Self::Value>,
1313
span: Span,

src/librustc_mir/hair/cx/expr.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -533,11 +533,11 @@ fn make_mirror_unadjusted<'a, 'tcx>(
533533
convert_path_expr(cx, expr, res)
534534
}
535535

536-
hir::ExprKind::InlineAsm(ref asm, ref outputs, ref inputs) => {
536+
hir::ExprKind::InlineAsm(ref asm) => {
537537
ExprKind::InlineAsm {
538-
asm,
539-
outputs: outputs.to_ref(),
540-
inputs: inputs.to_ref(),
538+
asm: &asm.inner,
539+
outputs: asm.outputs_exprs.to_ref(),
540+
inputs: asm.inputs_exprs.to_ref(),
541541
}
542542
}
543543

src/librustc_mir/hair/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ pub enum StmtKind<'tcx> {
9393
},
9494
}
9595

96+
// `Expr` is used a lot. Make sure it doesn't unintentionally get bigger.
97+
#[cfg(target_arch = "x86_64")]
98+
rustc_data_structures::static_assert_size!(Expr<'_>, 168);
99+
96100
/// The Hair trait implementor lowers their expressions (`&'tcx H::Expr`)
97101
/// into instances of this `Expr` enum. This lowering can be done
98102
/// basically as lazily or as eagerly as desired: every recursive
@@ -264,7 +268,7 @@ pub enum ExprKind<'tcx> {
264268
user_ty: Option<Canonical<'tcx, UserType<'tcx>>>,
265269
},
266270
InlineAsm {
267-
asm: &'tcx hir::InlineAsm,
271+
asm: &'tcx hir::InlineAsmInner,
268272
outputs: Vec<ExprRef<'tcx>>,
269273
inputs: Vec<ExprRef<'tcx>>
270274
},

src/librustc_passes/liveness.rs

+17-13
Original file line numberDiff line numberDiff line change
@@ -1184,17 +1184,21 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
11841184
self.propagate_through_expr(&e, succ)
11851185
}
11861186

1187-
hir::ExprKind::InlineAsm(ref ia, ref outputs, ref inputs) => {
1187+
hir::ExprKind::InlineAsm(ref asm) => {
1188+
let ia = &asm.inner;
1189+
let outputs = &asm.outputs_exprs;
1190+
let inputs = &asm.inputs_exprs;
11881191
let succ = ia.outputs.iter().zip(outputs).rev().fold(succ, |succ, (o, output)| {
1189-
// see comment on places
1190-
// in propagate_through_place_components()
1191-
if o.is_indirect {
1192-
self.propagate_through_expr(output, succ)
1193-
} else {
1194-
let acc = if o.is_rw { ACC_WRITE|ACC_READ } else { ACC_WRITE };
1195-
let succ = self.write_place(output, succ, acc);
1196-
self.propagate_through_place_components(output, succ)
1197-
}});
1192+
// see comment on places
1193+
// in propagate_through_place_components()
1194+
if o.is_indirect {
1195+
self.propagate_through_expr(output, succ)
1196+
} else {
1197+
let acc = if o.is_rw { ACC_WRITE|ACC_READ } else { ACC_WRITE };
1198+
let succ = self.write_place(output, succ, acc);
1199+
self.propagate_through_place_components(output, succ)
1200+
}
1201+
});
11981202

11991203
// Inputs are executed first. Propagate last because of rev order
12001204
self.propagate_through_exprs(inputs, succ)
@@ -1395,13 +1399,13 @@ fn check_expr<'tcx>(this: &mut Liveness<'_, 'tcx>, expr: &'tcx Expr) {
13951399
}
13961400
}
13971401

1398-
hir::ExprKind::InlineAsm(ref ia, ref outputs, ref inputs) => {
1399-
for input in inputs {
1402+
hir::ExprKind::InlineAsm(ref asm) => {
1403+
for input in &asm.inputs_exprs {
14001404
this.visit_expr(input);
14011405
}
14021406

14031407
// Output operands must be places
1404-
for (o, output) in ia.outputs.iter().zip(outputs) {
1408+
for (o, output) in asm.inner.outputs.iter().zip(&asm.outputs_exprs) {
14051409
if !o.is_indirect {
14061410
this.check_place(output);
14071411
}

src/librustc_typeck/check/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
244244
ExprKind::Path(ref qpath) => {
245245
self.check_expr_path(qpath, expr)
246246
}
247-
ExprKind::InlineAsm(_, ref outputs, ref inputs) => {
248-
for expr in outputs.iter().chain(inputs.iter()) {
247+
ExprKind::InlineAsm(ref asm) => {
248+
for expr in asm.outputs_exprs.iter().chain(asm.inputs_exprs.iter()) {
249249
self.check_expr(expr);
250250
}
251251
tcx.mk_unit()

0 commit comments

Comments
 (0)