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

+10-11
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

-1
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

+10-11
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

+1
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

+1
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

+2-2
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

+1
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

+1-15
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

+1-1
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

+17
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());

src/librustc_mir/transform/qualify_consts.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -774,10 +774,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
774774
}
775775
}
776776
}
777-
778-
Rvalue::InlineAsm {..} => {
779-
self.not_const();
780-
}
781777
}
782778
}
783779

@@ -933,6 +929,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
933929
StatementKind::SetDiscriminant { .. } |
934930
StatementKind::StorageLive(_) |
935931
StatementKind::StorageDead(_) |
932+
StatementKind::InlineAsm {..} |
936933
StatementKind::Nop => {}
937934
}
938935
});

src/librustc_mir/transform/type_check.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,9 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
361361
span_mirbug!(self, stmt, "bad assignment ({:?} = {:?}): {:?}",
362362
lv_ty, rv_ty, terr);
363363
}
364-
// FIXME: rvalue with undeterminable type - e.g. inline
365-
// asm.
366364
}
365+
// FIXME: rvalue with undeterminable type - e.g. AggregateKind::Array branch that
366+
// returns `None`.
367367
}
368368
StatementKind::SetDiscriminant{ ref lvalue, variant_index } => {
369369
let lvalue_type = lvalue.ty(mir, tcx).to_ty(tcx);
@@ -392,6 +392,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
392392
}
393393
}
394394
}
395+
StatementKind::InlineAsm { .. } |
395396
StatementKind::Nop => {}
396397
}
397398
}

src/librustc_passes/mir_stats.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ impl<'a, 'tcx> mir_visit::Visitor<'tcx> for StatCollector<'a, 'tcx> {
128128
StatementKind::SetDiscriminant { .. } => "StatementKind::SetDiscriminant",
129129
StatementKind::StorageLive(..) => "StatementKind::StorageLive",
130130
StatementKind::StorageDead(..) => "StatementKind::StorageDead",
131+
StatementKind::InlineAsm { .. } => "StatementKind::InlineAsm",
131132
StatementKind::Nop => "StatementKind::Nop",
132133
}, &statement.kind);
133134
self.super_statement(block, statement, location);
@@ -198,7 +199,6 @@ impl<'a, 'tcx> mir_visit::Visitor<'tcx> for StatCollector<'a, 'tcx> {
198199

199200
"Rvalue::Aggregate"
200201
}
201-
Rvalue::InlineAsm { .. } => "Rvalue::InlineAsm",
202202
};
203203
self.record(rvalue_kind, rvalue);
204204
self.super_rvalue(rvalue, location);

src/librustc_trans/mir/constant.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,9 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
287287
mir::StatementKind::StorageLive(_) |
288288
mir::StatementKind::StorageDead(_) |
289289
mir::StatementKind::Nop => {}
290+
mir::StatementKind::InlineAsm { .. } |
290291
mir::StatementKind::SetDiscriminant{ .. } => {
291-
span_bug!(span, "SetDiscriminant should not appear in constants?");
292+
span_bug!(span, "{:?} should not appear in constants?", statement.kind);
292293
}
293294
}
294295
}

src/librustc_trans/mir/rvalue.rs

+2-19
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use rustc::mir::tcx::LvalueTy;
1616
use rustc::mir;
1717
use middle::lang_items::ExchangeMallocFnLangItem;
1818

19-
use asm;
2019
use base;
2120
use builder::Builder;
2221
use callee::Callee;
@@ -156,20 +155,6 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
156155
bcx
157156
}
158157

159-
mir::Rvalue::InlineAsm { ref asm, ref outputs, ref inputs } => {
160-
let outputs = outputs.iter().map(|output| {
161-
let lvalue = self.trans_lvalue(&bcx, output);
162-
(lvalue.llval, lvalue.ty.to_ty(bcx.tcx()))
163-
}).collect();
164-
165-
let input_vals = inputs.iter().map(|input| {
166-
self.trans_operand(&bcx, input).immediate()
167-
}).collect();
168-
169-
asm::trans_inline_asm(&bcx, asm, outputs, input_vals);
170-
bcx
171-
}
172-
173158
_ => {
174159
assert!(rvalue_creates_operand(rvalue));
175160
let (bcx, temp) = self.trans_rvalue_operand(bcx, rvalue);
@@ -468,8 +453,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
468453
(bcx, operand)
469454
}
470455
mir::Rvalue::Repeat(..) |
471-
mir::Rvalue::Aggregate(..) |
472-
mir::Rvalue::InlineAsm { .. } => {
456+
mir::Rvalue::Aggregate(..) => {
473457
bug!("cannot generate operand from rvalue {:?}", rvalue);
474458

475459
}
@@ -669,8 +653,7 @@ pub fn rvalue_creates_operand(rvalue: &mir::Rvalue) -> bool {
669653
mir::Rvalue::Use(..) =>
670654
true,
671655
mir::Rvalue::Repeat(..) |
672-
mir::Rvalue::Aggregate(..) |
673-
mir::Rvalue::InlineAsm { .. } =>
656+
mir::Rvalue::Aggregate(..) =>
674657
false,
675658
}
676659

src/librustc_trans/mir/statement.rs

+14
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use rustc::mir;
1212

1313
use base;
14+
use asm;
1415
use common;
1516
use builder::Builder;
1617

@@ -73,6 +74,19 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
7374
mir::StatementKind::StorageDead(ref lvalue) => {
7475
self.trans_storage_liveness(bcx, lvalue, base::Lifetime::End)
7576
}
77+
mir::StatementKind::InlineAsm { ref asm, ref outputs, ref inputs } => {
78+
let outputs = outputs.iter().map(|output| {
79+
let lvalue = self.trans_lvalue(&bcx, output);
80+
(lvalue.llval, lvalue.ty.to_ty(bcx.tcx()))
81+
}).collect();
82+
83+
let input_vals = inputs.iter().map(|input| {
84+
self.trans_operand(&bcx, input).immediate()
85+
}).collect();
86+
87+
asm::trans_inline_asm(&bcx, asm, outputs, input_vals);
88+
bcx
89+
}
7690
mir::StatementKind::Nop => bcx,
7791
}
7892
}

0 commit comments

Comments
 (0)