Skip to content

Commit 9772003

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

File tree

13 files changed

+61
-20
lines changed

13 files changed

+61
-20
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: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,23 @@ 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+
if !expr.ty.is_never() {
400+
this.cfg.push_assign_unit(
401+
destination_block,
402+
source_info,
403+
destination,
404+
this.tcx,
405+
);
406+
}
407+
408+
let mut targets = if options.contains(InlineAsmOptions::NORETURN) {
409+
vec![]
410+
} else {
411+
vec![destination_block]
412+
};
413+
397414
let operands = operands
398415
.into_iter()
399416
.map(|op| match *op {
@@ -449,17 +466,24 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
449466
thir::InlineAsmOperand::SymStatic { def_id } => {
450467
mir::InlineAsmOperand::SymStatic { def_id }
451468
}
452-
thir::InlineAsmOperand::Label { .. } => {
453-
todo!()
469+
thir::InlineAsmOperand::Label { block } => {
470+
let target = this.cfg.start_new_block();
471+
let target_index = targets.len();
472+
targets.push(target);
473+
474+
let tmp = this.get_unit_temp();
475+
let target = unpack!(this.ast_block(tmp, target, block, source_info));
476+
this.cfg.terminate(
477+
target,
478+
source_info,
479+
TerminatorKind::Goto { target: destination_block },
480+
);
481+
482+
mir::InlineAsmOperand::Label { target_index }
454483
}
455484
})
456485
.collect();
457486

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();
463487
this.cfg.terminate(
464488
block,
465489
source_info,
@@ -468,11 +492,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
468492
operands,
469493
options,
470494
line_spans,
471-
targets: if options.contains(InlineAsmOptions::NORETURN) {
472-
Vec::new()
473-
} else {
474-
vec![destination_block]
475-
},
495+
targets,
476496
unwind: if options.contains(InlineAsmOptions::MAY_UNWIND) {
477497
UnwindAction::Continue
478498
} 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
}

0 commit comments

Comments
 (0)