Implement asm goto in MIR and MIR lowering
This commit is contained in:
parent
b044aaa905
commit
3b1dd1bfa9
13 changed files with 53 additions and 17 deletions
|
@ -749,7 +749,8 @@ impl<'cx, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx, R> for MirBorro
|
||||||
}
|
}
|
||||||
InlineAsmOperand::Const { value: _ }
|
InlineAsmOperand::Const { value: _ }
|
||||||
| InlineAsmOperand::SymFn { value: _ }
|
| InlineAsmOperand::SymFn { value: _ }
|
||||||
| InlineAsmOperand::SymStatic { def_id: _ } => {}
|
| InlineAsmOperand::SymStatic { def_id: _ }
|
||||||
|
| InlineAsmOperand::Label { target_index: _ } => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,7 +182,8 @@ impl<'cx, 'tcx> Visitor<'tcx> for LoanInvalidationsGenerator<'cx, 'tcx> {
|
||||||
}
|
}
|
||||||
InlineAsmOperand::Const { value: _ }
|
InlineAsmOperand::Const { value: _ }
|
||||||
| InlineAsmOperand::SymFn { value: _ }
|
| InlineAsmOperand::SymFn { value: _ }
|
||||||
| InlineAsmOperand::SymStatic { def_id: _ } => {}
|
| InlineAsmOperand::SymStatic { def_id: _ }
|
||||||
|
| InlineAsmOperand::Label { target_index: _ } => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,8 @@ pub(crate) fn codegen_global_asm_item(tcx: TyCtxt<'_>, global_asm: &mut String,
|
||||||
InlineAsmOperand::In { .. }
|
InlineAsmOperand::In { .. }
|
||||||
| InlineAsmOperand::Out { .. }
|
| InlineAsmOperand::Out { .. }
|
||||||
| InlineAsmOperand::InOut { .. }
|
| InlineAsmOperand::InOut { .. }
|
||||||
| InlineAsmOperand::SplitInOut { .. } => {
|
| InlineAsmOperand::SplitInOut { .. }
|
||||||
|
| InlineAsmOperand::Label { .. } => {
|
||||||
span_bug!(op_sp, "invalid operand type for global_asm!")
|
span_bug!(op_sp, "invalid operand type for global_asm!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,6 +129,9 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>(
|
||||||
let instance = Instance::mono(fx.tcx, def_id).polymorphize(fx.tcx);
|
let instance = Instance::mono(fx.tcx, def_id).polymorphize(fx.tcx);
|
||||||
CInlineAsmOperand::Symbol { symbol: fx.tcx.symbol_name(instance).name.to_owned() }
|
CInlineAsmOperand::Symbol { symbol: fx.tcx.symbol_name(instance).name.to_owned() }
|
||||||
}
|
}
|
||||||
|
InlineAsmOperand::Label { .. } => {
|
||||||
|
span_bug!(span, "asm! label operands are not yet supported");
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
|
|
@ -1119,6 +1119,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
mir::InlineAsmOperand::SymStatic { def_id } => {
|
mir::InlineAsmOperand::SymStatic { def_id } => {
|
||||||
InlineAsmOperandRef::SymStatic { def_id }
|
InlineAsmOperandRef::SymStatic { def_id }
|
||||||
}
|
}
|
||||||
|
mir::InlineAsmOperand::Label { target_index: _ } => {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
|
|
@ -830,6 +830,9 @@ impl<'tcx> TerminatorKind<'tcx> {
|
||||||
InlineAsmOperand::SymStatic { def_id } => {
|
InlineAsmOperand::SymStatic { def_id } => {
|
||||||
write!(fmt, "sym_static {def_id:?}")?;
|
write!(fmt, "sym_static {def_id:?}")?;
|
||||||
}
|
}
|
||||||
|
InlineAsmOperand::Label { target_index } => {
|
||||||
|
write!(fmt, "label {target_index}")?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
write!(fmt, ", options({options:?}))")
|
write!(fmt, ", options({options:?}))")
|
||||||
|
|
|
@ -919,6 +919,10 @@ pub enum InlineAsmOperand<'tcx> {
|
||||||
SymStatic {
|
SymStatic {
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
},
|
},
|
||||||
|
Label {
|
||||||
|
/// This represents the index into the `targets` array in `TerminatorKind::InlineAsm`.
|
||||||
|
target_index: usize,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Type for MIR `Assert` terminator error messages.
|
/// Type for MIR `Assert` terminator error messages.
|
||||||
|
|
|
@ -595,7 +595,8 @@ macro_rules! make_mir_visitor {
|
||||||
self.visit_constant(value, location);
|
self.visit_constant(value, location);
|
||||||
}
|
}
|
||||||
InlineAsmOperand::Out { place: None, .. }
|
InlineAsmOperand::Out { place: None, .. }
|
||||||
| InlineAsmOperand::SymStatic { def_id: _ } => {}
|
| InlineAsmOperand::SymStatic { def_id: _ }
|
||||||
|
| InlineAsmOperand::Label { target_index: _ } => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -400,6 +400,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
line_spans,
|
line_spans,
|
||||||
}) => {
|
}) => {
|
||||||
use rustc_middle::{mir, thir};
|
use rustc_middle::{mir, thir};
|
||||||
|
|
||||||
|
let destination_block = this.cfg.start_new_block();
|
||||||
|
let mut targets = if options.contains(InlineAsmOptions::NORETURN) {
|
||||||
|
vec![]
|
||||||
|
} else {
|
||||||
|
vec![destination_block]
|
||||||
|
};
|
||||||
|
|
||||||
let operands = operands
|
let operands = operands
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|op| match *op {
|
.map(|op| match *op {
|
||||||
|
@ -455,17 +463,28 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
thir::InlineAsmOperand::SymStatic { def_id } => {
|
thir::InlineAsmOperand::SymStatic { def_id } => {
|
||||||
mir::InlineAsmOperand::SymStatic { def_id }
|
mir::InlineAsmOperand::SymStatic { def_id }
|
||||||
}
|
}
|
||||||
thir::InlineAsmOperand::Label { .. } => {
|
thir::InlineAsmOperand::Label { block } => {
|
||||||
todo!()
|
let target = this.cfg.start_new_block();
|
||||||
|
let target_index = targets.len();
|
||||||
|
targets.push(target);
|
||||||
|
|
||||||
|
let tmp = this.get_unit_temp();
|
||||||
|
let target = unpack!(this.ast_block(tmp, target, block, source_info));
|
||||||
|
this.cfg.terminate(
|
||||||
|
target,
|
||||||
|
source_info,
|
||||||
|
TerminatorKind::Goto { target: destination_block },
|
||||||
|
);
|
||||||
|
|
||||||
|
mir::InlineAsmOperand::Label { target_index }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if !options.contains(InlineAsmOptions::NORETURN) {
|
if !expr.ty.is_never() {
|
||||||
this.cfg.push_assign_unit(block, source_info, destination, this.tcx);
|
this.cfg.push_assign_unit(block, source_info, destination, this.tcx);
|
||||||
}
|
}
|
||||||
|
|
||||||
let destination_block = this.cfg.start_new_block();
|
|
||||||
this.cfg.terminate(
|
this.cfg.terminate(
|
||||||
block,
|
block,
|
||||||
source_info,
|
source_info,
|
||||||
|
@ -474,11 +493,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
operands,
|
operands,
|
||||||
options,
|
options,
|
||||||
line_spans,
|
line_spans,
|
||||||
targets: if options.contains(InlineAsmOptions::NORETURN) {
|
targets,
|
||||||
Vec::new()
|
|
||||||
} else {
|
|
||||||
vec![destination_block]
|
|
||||||
},
|
|
||||||
unwind: if options.contains(InlineAsmOptions::MAY_UNWIND) {
|
unwind: if options.contains(InlineAsmOptions::MAY_UNWIND) {
|
||||||
UnwindAction::Continue
|
UnwindAction::Continue
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -271,7 +271,8 @@ impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'_, 'tcx> {
|
||||||
InlineAsmOperand::In { .. }
|
InlineAsmOperand::In { .. }
|
||||||
| InlineAsmOperand::Const { .. }
|
| InlineAsmOperand::Const { .. }
|
||||||
| InlineAsmOperand::SymFn { .. }
|
| InlineAsmOperand::SymFn { .. }
|
||||||
| InlineAsmOperand::SymStatic { .. } => {}
|
| InlineAsmOperand::SymStatic { .. }
|
||||||
|
| InlineAsmOperand::Label { .. } => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -515,7 +515,8 @@ impl<'b, 'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> Gatherer<'b, 'a, 'tcx, F> {
|
||||||
}
|
}
|
||||||
InlineAsmOperand::Const { value: _ }
|
InlineAsmOperand::Const { value: _ }
|
||||||
| InlineAsmOperand::SymFn { value: _ }
|
| InlineAsmOperand::SymFn { value: _ }
|
||||||
| InlineAsmOperand::SymStatic { def_id: _ } => {}
|
| InlineAsmOperand::SymStatic { def_id: _ }
|
||||||
|
| InlineAsmOperand::Label { target_index: _ } => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -648,7 +648,8 @@ impl WriteInfo {
|
||||||
}
|
}
|
||||||
InlineAsmOperand::Const { .. }
|
InlineAsmOperand::Const { .. }
|
||||||
| InlineAsmOperand::SymFn { .. }
|
| InlineAsmOperand::SymFn { .. }
|
||||||
| InlineAsmOperand::SymStatic { .. } => (),
|
| InlineAsmOperand::SymStatic { .. }
|
||||||
|
| InlineAsmOperand::Label { .. } => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -559,7 +559,8 @@ impl<'tcx> Stable<'tcx> for mir::InlineAsmOperand<'tcx> {
|
||||||
}
|
}
|
||||||
InlineAsmOperand::Const { .. }
|
InlineAsmOperand::Const { .. }
|
||||||
| InlineAsmOperand::SymFn { .. }
|
| InlineAsmOperand::SymFn { .. }
|
||||||
| InlineAsmOperand::SymStatic { .. } => (None, None),
|
| InlineAsmOperand::SymStatic { .. }
|
||||||
|
| InlineAsmOperand::Label { .. } => (None, None),
|
||||||
};
|
};
|
||||||
|
|
||||||
stable_mir::mir::InlineAsmOperand { in_value, out_place, raw_rpr: format!("{self:?}") }
|
stable_mir::mir::InlineAsmOperand { in_value, out_place, raw_rpr: format!("{self:?}") }
|
||||||
|
|
Loading…
Add table
Reference in a new issue