Skip to content

Instantly share code, notes, and snippets.

@Amanieu
Last active February 12, 2020 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Amanieu/ebd5b82cd0b4e492b1d8ab8dc0649c37 to your computer and use it in GitHub Desktop.
Save Amanieu/ebd5b82cd0b4e492b1d8ab8dc0649c37 to your computer and use it in GitHub Desktop.
fn propagate_through_expr(&mut self, expr: &Expr<'_>, succ: LiveNode) -> LiveNode {
match expr.kind {
hir::ExprKind::InlineAsm(ref asm) => {
// Handle non-returning asm
let mut succ = if asm.options.contains(InlineAsmOptions::NORETURN) {
self.s.exit_ln
} else {
succ
};
// Do a first pass for writing outputs only
for (op, _) in asm.operands.iter().rev() {
match op {
hir::InlineAsmOperand::In { expr, .. }
| hir::InlineAsmOperand::Const { expr, .. }
| hir::InlineAsmOperand::Sym { expr, .. } => {}
hir::InlineAsmOperand::Out { expr, .. } => {
if let Some(expr) = expr {
succ = self.write_place(expr, succ, ACC_WRITE);
}
}
hir::InlineAsmOperand::InOut { expr, .. } => {
succ = self.write_place(expr, succ, ACC_READ | ACC_WRITE);
}
hir::InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
if let Some(expr) = out_expr {
succ = self.write_place(expr, succ, ACC_WRITE);
}
}
}
}
// Then do a second pass for inputs
let mut succ = succ;
for (op, _) in asm.operands.iter().rev() {
match op {
hir::InlineAsmOperand::In { expr, .. }
| hir::InlineAsmOperand::Const { expr, .. }
| hir::InlineAsmOperand::Sym { expr, .. } => {
succ = self.propagate_through_expr(expr, succ)
}
hir::InlineAsmOperand::Out { expr, .. } => {
if let Some(expr) = expr {
succ = self.propagate_through_place_components(expr, succ);
}
}
hir::InlineAsmOperand::InOut { expr, .. } => {
succ = self.propagate_through_place_components(expr, succ);
}
hir::InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
if let Some(expr) = out_expr {
succ = self.propagate_through_place_components(expr, succ);
}
succ = self.propagate_through_expr(in_expr, succ);
}
}
}
succ
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment