Skip to content

Commit 901ce85

Browse files
committed
Implement asm goto in MIR and MIR lowering
1 parent 126910a commit 901ce85

File tree

11 files changed

+56
-22
lines changed

11 files changed

+56
-22
lines changed

compiler/rustc_borrowck/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,8 @@ impl<'cx, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx, R> for MirBorro
750750
}
751751
InlineAsmOperand::Const { value: _ }
752752
| InlineAsmOperand::SymFn { value: _ }
753-
| InlineAsmOperand::SymStatic { def_id: _ } => {}
753+
| InlineAsmOperand::SymStatic { def_id: _ }
754+
| InlineAsmOperand::Label { target_index: _ } => {}
754755
}
755756
}
756757
}

compiler/rustc_borrowck/src/polonius/loan_invalidations.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ impl<'cx, 'tcx> Visitor<'tcx> for LoanInvalidationsGenerator<'cx, 'tcx> {
184184
}
185185
InlineAsmOperand::Const { value: _ }
186186
| InlineAsmOperand::SymFn { value: _ }
187-
| InlineAsmOperand::SymStatic { def_id: _ } => {}
187+
| InlineAsmOperand::SymStatic { def_id: _ }
188+
| InlineAsmOperand::Label { target_index: _ } => {}
188189
}
189190
}
190191
}

compiler/rustc_codegen_ssa/src/mir/block.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11101110
mir::InlineAsmOperand::SymStatic { def_id } => {
11111111
InlineAsmOperandRef::SymStatic { def_id }
11121112
}
1113+
mir::InlineAsmOperand::Label { target_index: _ } => {
1114+
todo!();
1115+
}
11131116
})
11141117
.collect();
11151118

compiler/rustc_middle/src/mir/pretty.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,9 @@ impl<'tcx> TerminatorKind<'tcx> {
857857
InlineAsmOperand::SymStatic { def_id } => {
858858
write!(fmt, "sym_static {def_id:?}")?;
859859
}
860+
InlineAsmOperand::Label { target_index } => {
861+
write!(fmt, "label {target_index}")?;
862+
}
860863
}
861864
}
862865
write!(fmt, ", options({options:?}))")
@@ -899,12 +902,12 @@ impl<'tcx> TerminatorKind<'tcx> {
899902
let mut vec = Vec::with_capacity(targets.len() + 1);
900903
if !options.contains(InlineAsmOptions::NORETURN) {
901904
vec.push("return".into());
902-
}
903-
vec.resize(targets.len(), "unwind".into());
905+
}
906+
vec.resize(targets.len(), "label".into());
904907

905908
if let UnwindAction::Cleanup(_) = unwind {
906909
vec.push("unwind".into());
907-
}
910+
}
908911

909912
vec
910913
}

compiler/rustc_middle/src/mir/syntax.rs

+4
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,10 @@ pub enum InlineAsmOperand<'tcx> {
916916
SymStatic {
917917
def_id: DefId,
918918
},
919+
Label {
920+
/// This represents the index into the `targets` array in `TerminatorKind::InlineAsm`.
921+
target_index: usize,
922+
},
919923
}
920924

921925
/// Type for MIR `Assert` terminator error messages.

compiler/rustc_middle/src/mir/visit.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,8 @@ macro_rules! make_mir_visitor {
593593
self.visit_constant(value, location);
594594
}
595595
InlineAsmOperand::Out { place: None, .. }
596-
| InlineAsmOperand::SymStatic { def_id: _ } => {}
596+
| InlineAsmOperand::SymStatic { def_id: _ }
597+
| InlineAsmOperand::Label { target_index: _ } => {}
597598
}
598599
}
599600
}

compiler/rustc_mir_build/src/build/expr/into.rs

+29-12
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
394394
line_spans,
395395
}) => {
396396
use rustc_middle::{mir, thir};
397+
398+
let destination_block = this.cfg.start_new_block();
399+
let mut targets = if options.contains(InlineAsmOptions::NORETURN) {
400+
vec![]
401+
} else {
402+
this.cfg.push_assign_unit(
403+
destination_block,
404+
source_info,
405+
destination,
406+
this.tcx,
407+
);
408+
vec![destination_block]
409+
};
410+
397411
let operands = operands
398412
.into_iter()
399413
.map(|op| match *op {
@@ -449,17 +463,24 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
449463
thir::InlineAsmOperand::SymStatic { def_id } => {
450464
mir::InlineAsmOperand::SymStatic { def_id }
451465
}
452-
thir::InlineAsmOperand::Label { .. } => {
453-
todo!()
466+
thir::InlineAsmOperand::Label { block } => {
467+
let target = this.cfg.start_new_block();
468+
let target_index = targets.len();
469+
targets.push(target);
470+
471+
let tmp = this.get_unit_temp();
472+
let target = unpack!(this.ast_block(tmp, target, block, source_info));
473+
this.cfg.terminate(
474+
target,
475+
source_info,
476+
TerminatorKind::Goto { target: destination_block },
477+
);
478+
479+
mir::InlineAsmOperand::Label { target_index }
454480
}
455481
})
456482
.collect();
457483

458-
if !options.contains(InlineAsmOptions::NORETURN) {
459-
this.cfg.push_assign_unit(block, source_info, destination, this.tcx);
460-
}
461-
462-
let destination_block = this.cfg.start_new_block();
463484
this.cfg.terminate(
464485
block,
465486
source_info,
@@ -468,11 +489,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
468489
operands,
469490
options,
470491
line_spans,
471-
targets: if options.contains(InlineAsmOptions::NORETURN) {
472-
Vec::new()
473-
} else {
474-
vec![destination_block]
475-
},
492+
targets,
476493
unwind: if options.contains(InlineAsmOptions::MAY_UNWIND) {
477494
UnwindAction::Continue
478495
} else {

compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'_, 'tcx> {
271271
InlineAsmOperand::In { .. }
272272
| InlineAsmOperand::Const { .. }
273273
| InlineAsmOperand::SymFn { .. }
274-
| InlineAsmOperand::SymStatic { .. } => {}
274+
| InlineAsmOperand::SymStatic { .. }
275+
| InlineAsmOperand::Label { .. } => {}
275276
}
276277
}
277278
}

compiler/rustc_mir_dataflow/src/move_paths/builder.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,8 @@ impl<'b, 'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> Gatherer<'b, 'a, 'tcx, F> {
505505
}
506506
InlineAsmOperand::Const { value: _ }
507507
| InlineAsmOperand::SymFn { value: _ }
508-
| InlineAsmOperand::SymStatic { def_id: _ } => {}
508+
| InlineAsmOperand::SymStatic { def_id: _ }
509+
| InlineAsmOperand::Label { target_index: _ } => {}
509510
}
510511
}
511512
}

compiler/rustc_mir_transform/src/dest_prop.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,8 @@ impl WriteInfo {
642642
}
643643
InlineAsmOperand::Const { .. }
644644
| InlineAsmOperand::SymFn { .. }
645-
| InlineAsmOperand::SymStatic { .. } => (),
645+
| InlineAsmOperand::SymStatic { .. }
646+
| InlineAsmOperand::Label { .. } => {}
646647
}
647648
}
648649
}

compiler/rustc_smir/src/rustc_smir/convert/mir.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,8 @@ impl<'tcx> Stable<'tcx> for mir::InlineAsmOperand<'tcx> {
555555
}
556556
InlineAsmOperand::Const { .. }
557557
| InlineAsmOperand::SymFn { .. }
558-
| InlineAsmOperand::SymStatic { .. } => (None, None),
558+
| InlineAsmOperand::SymStatic { .. }
559+
| InlineAsmOperand::Label { .. } => (None, None),
559560
};
560561

561562
stable_mir::mir::InlineAsmOperand { in_value, out_place, raw_rpr: format!("{self:?}") }

0 commit comments

Comments
 (0)