Skip to content

Commit 3b1dd1b

Browse files
committed
Implement asm goto in MIR and MIR lowering
1 parent b044aaa commit 3b1dd1b

File tree

13 files changed

+53
-17
lines changed

13 files changed

+53
-17
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,8 @@ impl<'cx, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx, R> for MirBorro
749749
}
750750
InlineAsmOperand::Const { value: _ }
751751
| InlineAsmOperand::SymFn { value: _ }
752-
| InlineAsmOperand::SymStatic { def_id: _ } => {}
752+
| InlineAsmOperand::SymStatic { def_id: _ }
753+
| InlineAsmOperand::Label { target_index: _ } => {}
753754
}
754755
}
755756
}

compiler/rustc_borrowck/src/polonius/loan_invalidations.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ impl<'cx, 'tcx> Visitor<'tcx> for LoanInvalidationsGenerator<'cx, 'tcx> {
182182
}
183183
InlineAsmOperand::Const { value: _ }
184184
| InlineAsmOperand::SymFn { value: _ }
185-
| InlineAsmOperand::SymStatic { def_id: _ } => {}
185+
| InlineAsmOperand::SymStatic { def_id: _ }
186+
| InlineAsmOperand::Label { target_index: _ } => {}
186187
}
187188
}
188189
}

compiler/rustc_codegen_cranelift/src/global_asm.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ pub(crate) fn codegen_global_asm_item(tcx: TyCtxt<'_>, global_asm: &mut String,
7878
InlineAsmOperand::In { .. }
7979
| InlineAsmOperand::Out { .. }
8080
| InlineAsmOperand::InOut { .. }
81-
| InlineAsmOperand::SplitInOut { .. } => {
81+
| InlineAsmOperand::SplitInOut { .. }
82+
| InlineAsmOperand::Label { .. } => {
8283
span_bug!(op_sp, "invalid operand type for global_asm!")
8384
}
8485
}

compiler/rustc_codegen_cranelift/src/inline_asm.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>(
129129
let instance = Instance::mono(fx.tcx, def_id).polymorphize(fx.tcx);
130130
CInlineAsmOperand::Symbol { symbol: fx.tcx.symbol_name(instance).name.to_owned() }
131131
}
132+
InlineAsmOperand::Label { .. } => {
133+
span_bug!(span, "asm! label operands are not yet supported");
134+
}
132135
})
133136
.collect::<Vec<_>>();
134137

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11191119
mir::InlineAsmOperand::SymStatic { def_id } => {
11201120
InlineAsmOperandRef::SymStatic { def_id }
11211121
}
1122+
mir::InlineAsmOperand::Label { target_index: _ } => {
1123+
todo!();
1124+
}
11221125
})
11231126
.collect();
11241127

compiler/rustc_middle/src/mir/pretty.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,9 @@ impl<'tcx> TerminatorKind<'tcx> {
830830
InlineAsmOperand::SymStatic { def_id } => {
831831
write!(fmt, "sym_static {def_id:?}")?;
832832
}
833+
InlineAsmOperand::Label { target_index } => {
834+
write!(fmt, "label {target_index}")?;
835+
}
833836
}
834837
}
835838
write!(fmt, ", options({options:?}))")

compiler/rustc_middle/src/mir/syntax.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,10 @@ pub enum InlineAsmOperand<'tcx> {
919919
SymStatic {
920920
def_id: DefId,
921921
},
922+
Label {
923+
/// This represents the index into the `targets` array in `TerminatorKind::InlineAsm`.
924+
target_index: usize,
925+
},
922926
}
923927

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

compiler/rustc_middle/src/mir/visit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,8 @@ macro_rules! make_mir_visitor {
595595
self.visit_constant(value, location);
596596
}
597597
InlineAsmOperand::Out { place: None, .. }
598-
| InlineAsmOperand::SymStatic { def_id: _ } => {}
598+
| InlineAsmOperand::SymStatic { def_id: _ }
599+
| InlineAsmOperand::Label { target_index: _ } => {}
599600
}
600601
}
601602
}

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
400400
line_spans,
401401
}) => {
402402
use rustc_middle::{mir, thir};
403+
404+
let destination_block = this.cfg.start_new_block();
405+
let mut targets = if options.contains(InlineAsmOptions::NORETURN) {
406+
vec![]
407+
} else {
408+
vec![destination_block]
409+
};
410+
403411
let operands = operands
404412
.into_iter()
405413
.map(|op| match *op {
@@ -455,17 +463,28 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
455463
thir::InlineAsmOperand::SymStatic { def_id } => {
456464
mir::InlineAsmOperand::SymStatic { def_id }
457465
}
458-
thir::InlineAsmOperand::Label { .. } => {
459-
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 }
460480
}
461481
})
462482
.collect();
463483

464-
if !options.contains(InlineAsmOptions::NORETURN) {
484+
if !expr.ty.is_never() {
465485
this.cfg.push_assign_unit(block, source_info, destination, this.tcx);
466486
}
467487

468-
let destination_block = this.cfg.start_new_block();
469488
this.cfg.terminate(
470489
block,
471490
source_info,
@@ -474,11 +493,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
474493
operands,
475494
options,
476495
line_spans,
477-
targets: if options.contains(InlineAsmOptions::NORETURN) {
478-
Vec::new()
479-
} else {
480-
vec![destination_block]
481-
},
496+
targets,
482497
unwind: if options.contains(InlineAsmOptions::MAY_UNWIND) {
483498
UnwindAction::Continue
484499
} else {

compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,8 @@ impl<'b, 'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> Gatherer<'b, 'a, 'tcx, F> {
515515
}
516516
InlineAsmOperand::Const { value: _ }
517517
| InlineAsmOperand::SymFn { value: _ }
518-
| InlineAsmOperand::SymStatic { def_id: _ } => {}
518+
| InlineAsmOperand::SymStatic { def_id: _ }
519+
| InlineAsmOperand::Label { target_index: _ } => {}
519520
}
520521
}
521522
}

compiler/rustc_mir_transform/src/dest_prop.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,8 @@ impl WriteInfo {
648648
}
649649
InlineAsmOperand::Const { .. }
650650
| InlineAsmOperand::SymFn { .. }
651-
| InlineAsmOperand::SymStatic { .. } => (),
651+
| InlineAsmOperand::SymStatic { .. }
652+
| InlineAsmOperand::Label { .. } => {}
652653
}
653654
}
654655
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,8 @@ impl<'tcx> Stable<'tcx> for mir::InlineAsmOperand<'tcx> {
559559
}
560560
InlineAsmOperand::Const { .. }
561561
| InlineAsmOperand::SymFn { .. }
562-
| InlineAsmOperand::SymStatic { .. } => (None, None),
562+
| InlineAsmOperand::SymStatic { .. }
563+
| InlineAsmOperand::Label { .. } => (None, None),
563564
};
564565

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

0 commit comments

Comments
 (0)