@@ -352,13 +352,14 @@ fn write_instruction(
352352 // Write out the result values, if any.
353353 let mut has_results = false ;
354354 for r in func. dfg . inst_results ( inst) {
355+ let r = func. dfg . resolve_aliases ( * r) ;
355356 if !has_results {
356357 has_results = true ;
357358 write ! ( w, "{}" , r) ?;
358359 } else {
359360 write ! ( w, ", {}" , r) ?;
360361 }
361- if let Some ( f) = & func. dfg . facts [ * r] {
362+ if let Some ( f) = & func. dfg . facts [ r] {
362363 write ! ( w, " ! {}" , f) ?;
363364 }
364365 }
@@ -388,43 +389,53 @@ fn write_instruction(
388389pub fn write_operands ( w : & mut dyn Write , dfg : & DataFlowGraph , inst : Inst ) -> fmt:: Result {
389390 let pool = & dfg. value_lists ;
390391 let jump_tables = & dfg. jump_tables ;
392+
393+ // Resolve a value to its alias, if any.
394+ let v = |v : Value | dfg. resolve_aliases ( v) ;
395+
396+ // Resolve a list of values to their aliases and format them.
397+ let vs = |vs : & [ _ ] | {
398+ let vs: Vec < _ > = vs. iter ( ) . copied ( ) . map ( v) . collect ( ) ;
399+ DisplayValues ( & vs) . to_string ( )
400+ } ;
401+
391402 use crate :: ir:: instructions:: InstructionData :: * ;
392403 match dfg. insts [ inst] {
393- AtomicRmw { op, args, .. } => write ! ( w, " {} {}, {}" , op, args[ 0 ] , args[ 1 ] ) ,
394- AtomicCas { args, .. } => write ! ( w, " {}, {}, {}" , args[ 0 ] , args[ 1 ] , args[ 2 ] ) ,
395- LoadNoOffset { flags, arg, .. } => write ! ( w, "{} {}" , flags, arg) ,
396- StoreNoOffset { flags, args, .. } => write ! ( w, "{} {}, {}" , flags, args[ 0 ] , args[ 1 ] ) ,
397- Unary { arg, .. } => write ! ( w, " {}" , arg) ,
404+ AtomicRmw { op, args, .. } => write ! ( w, " {} {}, {}" , op, v ( args[ 0 ] ) , v ( args[ 1 ] ) ) ,
405+ AtomicCas { args, .. } => write ! ( w, " {}, {}, {}" , v ( args[ 0 ] ) , v ( args[ 1 ] ) , v ( args[ 2 ] ) ) ,
406+ LoadNoOffset { flags, arg, .. } => write ! ( w, "{} {}" , flags, v ( arg) ) ,
407+ StoreNoOffset { flags, args, .. } => write ! ( w, "{} {}, {}" , flags, v ( args[ 0 ] ) , v ( args[ 1 ] ) ) ,
408+ Unary { arg, .. } => write ! ( w, " {}" , v ( arg) ) ,
398409 UnaryImm { imm, .. } => write ! ( w, " {}" , imm) ,
399410 UnaryIeee32 { imm, .. } => write ! ( w, " {}" , imm) ,
400411 UnaryIeee64 { imm, .. } => write ! ( w, " {}" , imm) ,
401412 UnaryGlobalValue { global_value, .. } => write ! ( w, " {}" , global_value) ,
402413 UnaryConst {
403414 constant_handle, ..
404415 } => write ! ( w, " {}" , constant_handle) ,
405- Binary { args, .. } => write ! ( w, " {}, {}" , args[ 0 ] , args[ 1 ] ) ,
406- BinaryImm8 { arg, imm, .. } => write ! ( w, " {}, {}" , arg, imm) ,
407- BinaryImm64 { arg, imm, .. } => write ! ( w, " {}, {}" , arg, imm) ,
408- Ternary { args, .. } => write ! ( w, " {}, {}, {}" , args[ 0 ] , args[ 1 ] , args[ 2 ] ) ,
416+ Binary { args, .. } => write ! ( w, " {}, {}" , v ( args[ 0 ] ) , v ( args[ 1 ] ) ) ,
417+ BinaryImm8 { arg, imm, .. } => write ! ( w, " {}, {}" , v ( arg) , imm) ,
418+ BinaryImm64 { arg, imm, .. } => write ! ( w, " {}, {}" , v ( arg) , imm) ,
419+ Ternary { args, .. } => write ! ( w, " {}, {}, {}" , v ( args[ 0 ] ) , v ( args[ 1 ] ) , v ( args[ 2 ] ) ) ,
409420 MultiAry { ref args, .. } => {
410421 if args. is_empty ( ) {
411422 write ! ( w, "" )
412423 } else {
413- write ! ( w, " {}" , DisplayValues ( args. as_slice( pool) ) )
424+ write ! ( w, " {}" , vs ( args. as_slice( pool) ) )
414425 }
415426 }
416427 NullAry { .. } => write ! ( w, " " ) ,
417- TernaryImm8 { imm, args, .. } => write ! ( w, " {}, {}, {}" , args[ 0 ] , args[ 1 ] , imm) ,
428+ TernaryImm8 { imm, args, .. } => write ! ( w, " {}, {}, {}" , v ( args[ 0 ] ) , v ( args[ 1 ] ) , imm) ,
418429 Shuffle { imm, args, .. } => {
419430 let data = dfg. immediates . get ( imm) . expect (
420431 "Expected the shuffle mask to already be inserted into the immediates table" ,
421432 ) ;
422- write ! ( w, " {}, {}, {}" , args[ 0 ] , args[ 1 ] , data)
433+ write ! ( w, " {}, {}, {}" , v ( args[ 0 ] ) , v ( args[ 1 ] ) , data)
423434 }
424- IntCompare { cond, args, .. } => write ! ( w, " {} {}, {}" , cond, args[ 0 ] , args[ 1 ] ) ,
435+ IntCompare { cond, args, .. } => write ! ( w, " {} {}, {}" , cond, v ( args[ 0 ] ) , v ( args[ 1 ] ) ) ,
425436 IntCompareImm { cond, arg, imm, .. } => write ! ( w, " {} {}, {}" , cond, arg, imm) ,
426- IntAddTrap { args, code, .. } => write ! ( w, " {}, {}, {}" , args[ 0 ] , args[ 1 ] , code) ,
427- FloatCompare { cond, args, .. } => write ! ( w, " {} {}, {}" , cond, args[ 0 ] , args[ 1 ] ) ,
437+ IntAddTrap { args, code, .. } => write ! ( w, " {}, {}, {}" , v ( args[ 0 ] ) , v ( args[ 1 ] ) , code) ,
438+ FloatCompare { cond, args, .. } => write ! ( w, " {} {}, {}" , cond, v ( args[ 0 ] ) , v ( args[ 1 ] ) ) ,
428439 Jump { destination, .. } => {
429440 write ! ( w, " {}" , destination. display( pool) )
430441 }
@@ -433,26 +444,20 @@ pub fn write_operands(w: &mut dyn Write, dfg: &DataFlowGraph, inst: Inst) -> fmt
433444 blocks : [ block_then, block_else] ,
434445 ..
435446 } => {
436- write ! ( w, " {}, {}" , arg, block_then. display( pool) ) ?;
447+ write ! ( w, " {}, {}" , v ( arg) , block_then. display( pool) ) ?;
437448 write ! ( w, ", {}" , block_else. display( pool) )
438449 }
439450 BranchTable { arg, table, .. } => {
440- write ! ( w, " {}, {}" , arg, jump_tables[ table] . display( pool) )
451+ write ! ( w, " {}, {}" , v ( arg) , jump_tables[ table] . display( pool) )
441452 }
442453 Call {
443454 func_ref, ref args, ..
444- } => write ! ( w, " {}({})" , func_ref, DisplayValues ( args. as_slice( pool) ) ) ,
455+ } => write ! ( w, " {}({})" , func_ref, vs ( args. as_slice( pool) ) ) ,
445456 CallIndirect {
446457 sig_ref, ref args, ..
447458 } => {
448459 let args = args. as_slice ( pool) ;
449- write ! (
450- w,
451- " {}, {}({})" ,
452- sig_ref,
453- args[ 0 ] ,
454- DisplayValues ( & args[ 1 ..] )
455- )
460+ write ! ( w, " {}, {}({})" , sig_ref, args[ 0 ] , vs( & args[ 1 ..] ) )
456461 }
457462 FuncAddr { func_ref, .. } => write ! ( w, " {}" , func_ref) ,
458463 StackLoad {
@@ -463,7 +468,7 @@ pub fn write_operands(w: &mut dyn Write, dfg: &DataFlowGraph, inst: Inst) -> fmt
463468 stack_slot,
464469 offset,
465470 ..
466- } => write ! ( w, " {}, {}{}" , arg, stack_slot, offset) ,
471+ } => write ! ( w, " {}, {}{}" , v ( arg) , stack_slot, offset) ,
467472 DynamicStackLoad {
468473 dynamic_stack_slot, ..
469474 } => write ! ( w, " {}" , dynamic_stack_slot) ,
@@ -474,15 +479,15 @@ pub fn write_operands(w: &mut dyn Write, dfg: &DataFlowGraph, inst: Inst) -> fmt
474479 } => write ! ( w, " {}, {}" , arg, dynamic_stack_slot) ,
475480 Load {
476481 flags, arg, offset, ..
477- } => write ! ( w, "{} {}{}" , flags, arg, offset) ,
482+ } => write ! ( w, "{} {}{}" , flags, v ( arg) , offset) ,
478483 Store {
479484 flags,
480485 args,
481486 offset,
482487 ..
483- } => write ! ( w, "{} {}, {}{}" , flags, args[ 0 ] , args[ 1 ] , offset) ,
488+ } => write ! ( w, "{} {}, {}{}" , flags, v ( args[ 0 ] ) , v ( args[ 1 ] ) , offset) ,
484489 Trap { code, .. } => write ! ( w, " {}" , code) ,
485- CondTrap { arg, code, .. } => write ! ( w, " {}, {}" , arg, code) ,
490+ CondTrap { arg, code, .. } => write ! ( w, " {}, {}" , v ( arg) , code) ,
486491 } ?;
487492
488493 let mut sep = " ; " ;
@@ -497,7 +502,7 @@ pub fn write_operands(w: &mut dyn Write, dfg: &DataFlowGraph, inst: Inst) -> fmt
497502 } => constant_handle. to_string ( ) ,
498503 _ => continue ,
499504 } ;
500- write ! ( w, "{}{} = {}" , sep, arg, imm) ?;
505+ write ! ( w, "{}{} = {}" , sep, v ( arg) , imm) ?;
501506 sep = ", " ;
502507 }
503508 }
@@ -603,7 +608,7 @@ mod tests {
603608 }
604609 assert_eq ! (
605610 func. to_string( ) ,
606- "function u0:0() fast {\n block0(v3: i32):\n v0 -> v3\n v2 -> v0\n v4 = iconst.i32 42\n v5 = iadd v0, v0 \n v1 -> v5\n v6 = iconst.i32 23\n v7 = iadd v1, v1 \n }\n "
611+ "function u0:0() fast {\n block0(v3: i32):\n v0 -> v3\n v2 -> v0\n v4 = iconst.i32 42\n v5 = iadd v3, v3 \n v1 -> v5\n v6 = iconst.i32 23\n v7 = iadd v5, v5 \n }\n "
607612 ) ;
608613 }
609614
0 commit comments