Skip to content

Commit dca8c28

Browse files
committed
Implement asm goto in MIR and MIR lowering
1 parent 1673331 commit dca8c28

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

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

Lines changed: 3 additions & 0 deletions
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:?}))")

compiler/rustc_middle/src/mir/syntax.rs

Lines changed: 4 additions & 0 deletions
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

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,14 @@ 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+
vec![destination_block]
403+
};
404+
397405
let operands = operands
398406
.into_iter()
399407
.map(|op| match *op {
@@ -449,17 +457,28 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
449457
thir::InlineAsmOperand::SymStatic { def_id } => {
450458
mir::InlineAsmOperand::SymStatic { def_id }
451459
}
452-
thir::InlineAsmOperand::Label { .. } => {
453-
todo!()
460+
thir::InlineAsmOperand::Label { block } => {
461+
let target = this.cfg.start_new_block();
462+
let target_index = targets.len();
463+
targets.push(target);
464+
465+
let tmp = this.get_unit_temp();
466+
let target = unpack!(this.ast_block(tmp, target, block, source_info));
467+
this.cfg.terminate(
468+
target,
469+
source_info,
470+
TerminatorKind::Goto { target: destination_block },
471+
);
472+
473+
mir::InlineAsmOperand::Label { target_index }
454474
}
455475
})
456476
.collect();
457477

458-
if !options.contains(InlineAsmOptions::NORETURN) {
478+
if !expr.ty.is_never() {
459479
this.cfg.push_assign_unit(block, source_info, destination, this.tcx);
460480
}
461481

462-
let destination_block = this.cfg.start_new_block();
463482
this.cfg.terminate(
464483
block,
465484
source_info,
@@ -468,11 +487,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
468487
operands,
469488
options,
470489
line_spans,
471-
targets: if options.contains(InlineAsmOptions::NORETURN) {
472-
Vec::new()
473-
} else {
474-
vec![destination_block]
475-
},
490+
targets,
476491
unwind: if options.contains(InlineAsmOptions::MAY_UNWIND) {
477492
UnwindAction::Continue
478493
} 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
@@ -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

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

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