From d34ec1bd06f3c27940b3e8cc31c3b79eadb86d1c Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Fri, 4 Nov 2016 15:19:44 -0700 Subject: [PATCH] Write out value aliases when writing instructions. If an instruction uses any values that are aliases of other values, print out the alias mappings on lines preceding the instruction. This is necessary to reconstruct the data flow graph. We don't make any attempt to only write out each alias mapping once. The parser does not yet support value aliases. --- lib/cretonne/src/write.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/cretonne/src/write.rs b/lib/cretonne/src/write.rs index ac487c6f37..d8db064cd6 100644 --- a/lib/cretonne/src/write.rs +++ b/lib/cretonne/src/write.rs @@ -145,11 +145,28 @@ fn type_suffix(func: &Function, inst: Inst) -> Option { Some(rtype) } +// Write out any value aliases appearing in `inst`. +fn write_value_aliases(w: &mut Write, func: &Function, inst: Inst, indent: usize) -> Result { + for &arg in func.dfg[inst].arguments().iter().flat_map(|x| x.iter()) { + let resolved = func.dfg.resolve_aliases(arg); + if resolved != arg { + try!(writeln!(w, "{1:0$}{2} -> {3}", indent, "", arg, resolved)); + } + } + Ok(()) +} + fn write_instruction(w: &mut Write, func: &Function, isa: Option<&TargetIsa>, inst: Inst) -> Result { + // Indent all instructions to col 24 if any encodings are present. + let indent = if func.encodings.is_empty() { 4 } else { 24 }; + + // Value aliases come out on lines before the instruction using them. + try!(write_value_aliases(w, func, inst, indent)); + // Write out encoding info. if let Some(enc) = func.encodings.get(inst).cloned() { let mut s = String::with_capacity(16); @@ -161,8 +178,8 @@ fn write_instruction(w: &mut Write, // Align instruction following ISA annotation to col 24. try!(write!(w, "{:23} ", s)); } else { - // No annotations, simply indent by 4. - try!(write!(w, " ")); + // No annotations, simply indent. + try!(write!(w, "{1:0$}", indent, "")); } // Write out the result values, if any.