Use AnonConst for asm! constants
This commit is contained in:
parent
cbd6ec7604
commit
32be124e30
37 changed files with 281 additions and 242 deletions
|
@ -204,8 +204,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
|
|||
} => {
|
||||
for op in operands {
|
||||
match *op {
|
||||
InlineAsmOperand::In { reg: _, ref value }
|
||||
| InlineAsmOperand::Const { ref value } => {
|
||||
InlineAsmOperand::In { reg: _, ref value } => {
|
||||
self.consume_operand(location, value);
|
||||
}
|
||||
InlineAsmOperand::Out { reg: _, late: _, place, .. } => {
|
||||
|
@ -219,7 +218,8 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
|
|||
self.mutate_place(location, out_place, Shallow(None), JustWrite);
|
||||
}
|
||||
}
|
||||
InlineAsmOperand::SymFn { value: _ }
|
||||
InlineAsmOperand::Const { value: _ }
|
||||
| InlineAsmOperand::SymFn { value: _ }
|
||||
| InlineAsmOperand::SymStatic { def_id: _ } => {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -734,8 +734,7 @@ impl<'cx, 'tcx> dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tc
|
|||
} => {
|
||||
for op in operands {
|
||||
match *op {
|
||||
InlineAsmOperand::In { reg: _, ref value }
|
||||
| InlineAsmOperand::Const { ref value } => {
|
||||
InlineAsmOperand::In { reg: _, ref value } => {
|
||||
self.consume_operand(loc, (value, span), flow_state);
|
||||
}
|
||||
InlineAsmOperand::Out { reg: _, late: _, place, .. } => {
|
||||
|
@ -761,7 +760,8 @@ impl<'cx, 'tcx> dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tc
|
|||
);
|
||||
}
|
||||
}
|
||||
InlineAsmOperand::SymFn { value: _ }
|
||||
InlineAsmOperand::Const { value: _ }
|
||||
| InlineAsmOperand::SymFn { value: _ }
|
||||
| InlineAsmOperand::SymStatic { def_id: _ } => {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -425,7 +425,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
|
|||
for op in operands {
|
||||
match *op {
|
||||
InlineAsmOperand::In { reg: _, ref value }
|
||||
| InlineAsmOperand::Const { ref value } => {
|
||||
=> {
|
||||
self.gather_operand(value);
|
||||
}
|
||||
InlineAsmOperand::Out { reg: _, late: _, place, .. } => {
|
||||
|
@ -441,7 +441,8 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
|
|||
self.gather_init(out_place.as_ref(), InitKind::Deep);
|
||||
}
|
||||
}
|
||||
InlineAsmOperand::SymFn { value: _ }
|
||||
InlineAsmOperand::Const { value: _ }
|
||||
| InlineAsmOperand::SymFn { value: _ }
|
||||
| InlineAsmOperand::SymStatic { def_id: _ } => {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -720,9 +720,6 @@ impl Conflicts<'a> {
|
|||
}
|
||||
}
|
||||
}
|
||||
InlineAsmOperand::Const { value } => {
|
||||
assert!(value.place().is_none());
|
||||
}
|
||||
InlineAsmOperand::InOut {
|
||||
reg: _,
|
||||
late: _,
|
||||
|
@ -731,6 +728,7 @@ impl Conflicts<'a> {
|
|||
}
|
||||
| InlineAsmOperand::In { reg: _, value: _ }
|
||||
| InlineAsmOperand::Out { reg: _, late: _, place: None }
|
||||
| InlineAsmOperand::Const { value: _ }
|
||||
| InlineAsmOperand::SymFn { value: _ }
|
||||
| InlineAsmOperand::SymStatic { def_id: _ } => {}
|
||||
}
|
||||
|
|
|
@ -108,9 +108,6 @@ pub enum Candidate {
|
|||
/// the attribute currently provides the semantic requirement that arguments
|
||||
/// must be constant.
|
||||
Argument { bb: BasicBlock, index: usize },
|
||||
|
||||
/// `const` operand in asm!.
|
||||
InlineAsm { bb: BasicBlock, index: usize },
|
||||
}
|
||||
|
||||
impl Candidate {
|
||||
|
@ -118,16 +115,14 @@ impl Candidate {
|
|||
fn forces_explicit_promotion(&self) -> bool {
|
||||
match self {
|
||||
Candidate::Ref(_) => false,
|
||||
Candidate::Argument { .. } | Candidate::InlineAsm { .. } => true,
|
||||
Candidate::Argument { .. } => true,
|
||||
}
|
||||
}
|
||||
|
||||
fn source_info(&self, body: &Body<'_>) -> SourceInfo {
|
||||
match self {
|
||||
Candidate::Ref(location) => *body.source_info(*location),
|
||||
Candidate::Argument { bb, .. } | Candidate::InlineAsm { bb, .. } => {
|
||||
*body.source_info(body.terminator_loc(*bb))
|
||||
}
|
||||
Candidate::Argument { bb, .. } => *body.source_info(body.terminator_loc(*bb)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -217,36 +212,25 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {
|
|||
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
|
||||
self.super_terminator(terminator, location);
|
||||
|
||||
match terminator.kind {
|
||||
TerminatorKind::Call { ref func, .. } => {
|
||||
if let ty::FnDef(def_id, _) = *func.ty(self.ccx.body, self.ccx.tcx).kind() {
|
||||
let fn_sig = self.ccx.tcx.fn_sig(def_id);
|
||||
if let Abi::RustIntrinsic | Abi::PlatformIntrinsic = fn_sig.abi() {
|
||||
let name = self.ccx.tcx.item_name(def_id);
|
||||
// FIXME(eddyb) use `#[rustc_args_required_const(2)]` for shuffles.
|
||||
if name.as_str().starts_with("simd_shuffle") {
|
||||
self.candidates
|
||||
.push(Candidate::Argument { bb: location.block, index: 2 });
|
||||
if let TerminatorKind::Call { ref func, .. } = terminator.kind {
|
||||
if let ty::FnDef(def_id, _) = *func.ty(self.ccx.body, self.ccx.tcx).kind() {
|
||||
let fn_sig = self.ccx.tcx.fn_sig(def_id);
|
||||
if let Abi::RustIntrinsic | Abi::PlatformIntrinsic = fn_sig.abi() {
|
||||
let name = self.ccx.tcx.item_name(def_id);
|
||||
// FIXME(eddyb) use `#[rustc_args_required_const(2)]` for shuffles.
|
||||
if name.as_str().starts_with("simd_shuffle") {
|
||||
self.candidates.push(Candidate::Argument { bb: location.block, index: 2 });
|
||||
|
||||
return; // Don't double count `simd_shuffle` candidates
|
||||
}
|
||||
return; // Don't double count `simd_shuffle` candidates
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(constant_args) = args_required_const(self.ccx.tcx, def_id) {
|
||||
for index in constant_args {
|
||||
self.candidates.push(Candidate::Argument { bb: location.block, index });
|
||||
}
|
||||
if let Some(constant_args) = args_required_const(self.ccx.tcx, def_id) {
|
||||
for index in constant_args {
|
||||
self.candidates.push(Candidate::Argument { bb: location.block, index });
|
||||
}
|
||||
}
|
||||
}
|
||||
TerminatorKind::InlineAsm { ref operands, .. } => {
|
||||
for (index, op) in operands.iter().enumerate() {
|
||||
if let InlineAsmOperand::Const { .. } = op {
|
||||
self.candidates.push(Candidate::InlineAsm { bb: location.block, index })
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -335,18 +319,6 @@ impl<'tcx> Validator<'_, 'tcx> {
|
|||
_ => bug!(),
|
||||
}
|
||||
}
|
||||
Candidate::InlineAsm { bb, index } => {
|
||||
assert!(self.explicit);
|
||||
|
||||
let terminator = self.body[bb].terminator();
|
||||
match &terminator.kind {
|
||||
TerminatorKind::InlineAsm { operands, .. } => match &operands[index] {
|
||||
InlineAsmOperand::Const { value } => self.validate_operand(value),
|
||||
_ => bug!(),
|
||||
},
|
||||
_ => bug!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -818,9 +790,7 @@ pub fn validate_candidates(
|
|||
}
|
||||
|
||||
match candidate {
|
||||
Candidate::Argument { bb, index } | Candidate::InlineAsm { bb, index }
|
||||
if !is_promotable =>
|
||||
{
|
||||
Candidate::Argument { bb, index } if !is_promotable => {
|
||||
let span = ccx.body[bb].terminator().source_info.span;
|
||||
let msg = format!("argument {} is required to be a constant", index + 1);
|
||||
ccx.tcx.sess.span_err(span, &msg);
|
||||
|
@ -1089,24 +1059,6 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
|
|||
_ => bug!(),
|
||||
}
|
||||
}
|
||||
Candidate::InlineAsm { bb, index } => {
|
||||
let terminator = blocks[bb].terminator_mut();
|
||||
match terminator.kind {
|
||||
TerminatorKind::InlineAsm { ref mut operands, .. } => {
|
||||
match &mut operands[index] {
|
||||
InlineAsmOperand::Const { ref mut value } => {
|
||||
let ty = value.ty(local_decls, self.tcx);
|
||||
let span = terminator.source_info.span;
|
||||
|
||||
Rvalue::Use(mem::replace(value, promoted_operand(ty, span)))
|
||||
}
|
||||
_ => bug!(),
|
||||
}
|
||||
}
|
||||
|
||||
_ => bug!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1161,7 +1113,7 @@ pub fn promote_candidates<'tcx>(
|
|||
}
|
||||
}
|
||||
}
|
||||
Candidate::Argument { .. } | Candidate::InlineAsm { .. } => {}
|
||||
Candidate::Argument { .. } => {}
|
||||
}
|
||||
|
||||
// Declare return place local so that `mir::Body::new` doesn't complain.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue