Skip to content

Commit 9f1762a

Browse files
committed
Auto merge of #39854 - nagisa:mir-asm-stmt, r=nikomatsakis
[MIR] Make InlineAsm a Statement Previously InlineAsm was an Rvalue, but its semantics doesn't really match the semantics of an Rvalue - rather it behaves more like a Statement. r? @nikomatsakis you wanted this to happen
2 parents 23a0c26 + 4a3c66a commit 9f1762a

File tree

16 files changed

+67
-68
lines changed

16 files changed

+67
-68
lines changed

src/librustc/mir/mod.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,12 @@ pub enum StatementKind<'tcx> {
777777
/// End the current live range for the storage of the local.
778778
StorageDead(Lvalue<'tcx>),
779779

780+
InlineAsm {
781+
asm: InlineAsm,
782+
outputs: Vec<Lvalue<'tcx>>,
783+
inputs: Vec<Operand<'tcx>>
784+
},
785+
780786
/// No-op. Useful for deleting instructions without affecting statement indices.
781787
Nop,
782788
}
@@ -790,7 +796,10 @@ impl<'tcx> Debug for Statement<'tcx> {
790796
StorageDead(ref lv) => write!(fmt, "StorageDead({:?})", lv),
791797
SetDiscriminant{lvalue: ref lv, variant_index: index} => {
792798
write!(fmt, "discriminant({:?}) = {:?}", lv, index)
793-
}
799+
},
800+
InlineAsm { ref asm, ref outputs, ref inputs } => {
801+
write!(fmt, "asm!({:?} : {:?} : {:?})", asm, outputs, inputs)
802+
},
794803
Nop => write!(fmt, "nop"),
795804
}
796805
}
@@ -1004,12 +1013,6 @@ pub enum Rvalue<'tcx> {
10041013
/// that `Foo` has a destructor. These rvalues can be optimized
10051014
/// away after type-checking and before lowering.
10061015
Aggregate(AggregateKind<'tcx>, Vec<Operand<'tcx>>),
1007-
1008-
InlineAsm {
1009-
asm: InlineAsm,
1010-
outputs: Vec<Lvalue<'tcx>>,
1011-
inputs: Vec<Operand<'tcx>>
1012-
}
10131016
}
10141017

10151018
#[derive(Clone, Copy, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)]
@@ -1111,10 +1114,6 @@ impl<'tcx> Debug for Rvalue<'tcx> {
11111114
UnaryOp(ref op, ref a) => write!(fmt, "{:?}({:?})", op, a),
11121115
Discriminant(ref lval) => write!(fmt, "discriminant({:?})", lval),
11131116
Box(ref t) => write!(fmt, "Box({:?})", t),
1114-
InlineAsm { ref asm, ref outputs, ref inputs } => {
1115-
write!(fmt, "asm!({:?} : {:?} : {:?})", asm, outputs, inputs)
1116-
}
1117-
11181117
Ref(_, borrow_kind, ref lv) => {
11191118
let kind_str = match borrow_kind {
11201119
BorrowKind::Shared => "",

src/librustc/mir/tcx.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ impl<'tcx> Rvalue<'tcx> {
207207
}
208208
}
209209
}
210-
Rvalue::InlineAsm { .. } => None
211210
}
212211
}
213212
}

src/librustc/mir/visit.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,16 @@ macro_rules! make_mir_visitor {
333333
StatementKind::StorageDead(ref $($mutability)* lvalue) => {
334334
self.visit_lvalue(lvalue, LvalueContext::StorageDead, location);
335335
}
336+
StatementKind::InlineAsm { ref $($mutability)* outputs,
337+
ref $($mutability)* inputs,
338+
asm: _ } => {
339+
for output in & $($mutability)* outputs[..] {
340+
self.visit_lvalue(output, LvalueContext::Store, location);
341+
}
342+
for input in & $($mutability)* inputs[..] {
343+
self.visit_operand(input, location);
344+
}
345+
}
336346
StatementKind::Nop => {}
337347
}
338348
}
@@ -526,17 +536,6 @@ macro_rules! make_mir_visitor {
526536
self.visit_operand(operand, location);
527537
}
528538
}
529-
530-
Rvalue::InlineAsm { ref $($mutability)* outputs,
531-
ref $($mutability)* inputs,
532-
asm: _ } => {
533-
for output in & $($mutability)* outputs[..] {
534-
self.visit_lvalue(output, LvalueContext::Store, location);
535-
}
536-
for input in & $($mutability)* inputs[..] {
537-
self.visit_operand(input, location);
538-
}
539-
}
540539
}
541540
}
542541

src/librustc_borrowck/borrowck/mir/dataflow/impls.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ impl<'a, 'tcx> BitDenotation for MovingOutStatements<'a, 'tcx> {
473473
}
474474
mir::StatementKind::StorageLive(_) |
475475
mir::StatementKind::StorageDead(_) |
476+
mir::StatementKind::InlineAsm { .. } |
476477
mir::StatementKind::Nop => {}
477478
}
478479
}

src/librustc_borrowck/borrowck/mir/dataflow/sanity_check.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ fn each_block<'a, 'tcx, O>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
104104
}
105105
mir::StatementKind::StorageLive(_) |
106106
mir::StatementKind::StorageDead(_) |
107+
mir::StatementKind::InlineAsm { .. } |
107108
mir::StatementKind::Nop => continue,
108109
mir::StatementKind::SetDiscriminant{ .. } =>
109110
span_bug!(stmt.source_info.span,

src/librustc_borrowck/borrowck/mir/gather_moves.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ impl<'a, 'tcx> MoveDataBuilder<'a, 'tcx> {
412412
span_bug!(stmt.source_info.span,
413413
"SetDiscriminant should not exist during borrowck");
414414
}
415+
StatementKind::InlineAsm { .. } |
415416
StatementKind::Nop => {}
416417
}
417418
}
@@ -436,8 +437,7 @@ impl<'a, 'tcx> MoveDataBuilder<'a, 'tcx> {
436437
}
437438
Rvalue::Ref(..) |
438439
Rvalue::Discriminant(..) |
439-
Rvalue::Len(..) |
440-
Rvalue::InlineAsm { .. } => {}
440+
Rvalue::Len(..) => {}
441441
Rvalue::Box(..) => {
442442
// This returns an rvalue with uninitialized contents. We can't
443443
// move out of it here because it is an rvalue - assignments always

src/librustc_borrowck/borrowck/mir/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ fn drop_flag_effects_for_location<'a, 'tcx, F>(
378378
}
379379
mir::StatementKind::StorageLive(_) |
380380
mir::StatementKind::StorageDead(_) |
381+
mir::StatementKind::InlineAsm { .. } |
381382
mir::StatementKind::Nop => {}
382383
},
383384
None => {

src/librustc_mir/build/expr/as_rvalue.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
4949
ExprKind::Scope { extent, value } => {
5050
this.in_scope(extent, block, |this| this.as_rvalue(block, value))
5151
}
52-
ExprKind::InlineAsm { asm, outputs, inputs } => {
53-
let outputs = outputs.into_iter().map(|output| {
54-
unpack!(block = this.as_lvalue(block, output))
55-
}).collect();
56-
57-
let inputs = inputs.into_iter().map(|input| {
58-
unpack!(block = this.as_operand(block, input))
59-
}).collect();
60-
61-
block.and(Rvalue::InlineAsm {
62-
asm: asm.clone(),
63-
outputs: outputs,
64-
inputs: inputs
65-
})
66-
}
6752
ExprKind::Repeat { value, count } => {
6853
let value_operand = unpack!(block = this.as_operand(block, value));
6954
block.and(Rvalue::Repeat(value_operand, count))
@@ -238,6 +223,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
238223
ExprKind::Break { .. } |
239224
ExprKind::Continue { .. } |
240225
ExprKind::Return { .. } |
226+
ExprKind::InlineAsm { .. } |
241227
ExprKind::StaticRef { .. } => {
242228
// these do not have corresponding `Rvalue` variants,
243229
// so make an operand and then return that

src/librustc_mir/build/expr/into.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
232232
ExprKind::AssignOp { .. } |
233233
ExprKind::Continue { .. } |
234234
ExprKind::Break { .. } |
235+
ExprKind::InlineAsm { .. } |
235236
ExprKind::Return {.. } => {
236237
this.stmt_expr(block, expr)
237238
}
@@ -257,7 +258,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
257258
ExprKind::Index { .. } |
258259
ExprKind::Deref { .. } |
259260
ExprKind::Literal { .. } |
260-
ExprKind::InlineAsm { .. } |
261261
ExprKind::Field { .. } => {
262262
debug_assert!(match Category::of(&expr.kind).unwrap() {
263263
Category::Rvalue(RvalueFunc::Into) => false,

src/librustc_mir/build/expr/stmt.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,23 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
117117
this.exit_scope(expr_span, extent, block, return_block);
118118
this.cfg.start_new_block().unit()
119119
}
120+
ExprKind::InlineAsm { asm, outputs, inputs } => {
121+
let outputs = outputs.into_iter().map(|output| {
122+
unpack!(block = this.as_lvalue(block, output))
123+
}).collect();
124+
let inputs = inputs.into_iter().map(|input| {
125+
unpack!(block = this.as_operand(block, input))
126+
}).collect();
127+
this.cfg.push(block, Statement {
128+
source_info: source_info,
129+
kind: StatementKind::InlineAsm {
130+
asm: asm.clone(),
131+
outputs: outputs,
132+
inputs: inputs
133+
},
134+
});
135+
block.unit()
136+
}
120137
_ => {
121138
let expr_ty = expr.ty;
122139
let temp = this.temp(expr.ty.clone());

0 commit comments

Comments
 (0)