diff --git a/example.svg b/example.svg index 8a66769..a65e274 100644 --- a/example.svg +++ b/example.svg @@ -4,556 +4,556 @@ - - + + ir - + c9 - -C9: CONST I32(1000) + +C9: CONST I32(1000) n19 - -19: GT BOOL + +19: GT c9->n19 - - + + c8 - -C8: CONST DOUBLE(16) + +C8: CONST DOUBLE(16) n14 - -14: GT BOOL + +14: GT c8->n14 - - + + c7 - -C7: CONST I32(1) + +C7: CONST I32(1) n10 - -10: ADD I32 + +10: ADD c7->n10 - - + + c6 - -C6: CONST I32(0) + +C6: CONST I32(0) n22 - -22: RETURN + +22: RETURN c6->n22 - - + + n9 - -9: PHI I32 + +9: PHI I32 c6->n9 - - + + c5 - -C5: CONST DOUBLE(0) + +C5: CONST DOUBLE(0) n7 - -7: PHI DOUBLE + +7: PHI DOUBLE c5->n7 - - + + n8 - -8: PHI DOUBLE + +8: PHI DOUBLE c5->n8 - - + + c4 - -C4: CONST DOUBLE(0.5) + +C4: CONST DOUBLE(0.5) n4 - -4: SUB DOUBLE + +4: SUB c4->n4 - - + + c3 - -C3: CONST BOOL(1) + +C3: CONST BOOL(1) c2 - -C2: CONST BOOL(0) + +C2: CONST BOOL(0) c1 - -C1: CONST ADDR(0) + +C1: CONST ADDR(0) n1 - -1: START - - - -n1->n22 - - - - - -n5 - -5: END - - - -n1->n5 - - - - - -n17 - -17: RETURN - - - -n22->n17 - - + +1: START n2 - -2: PARAM DOUBLE "x" + +2: PARAM DOUBLE "x" - + -n2->n1 - - - - - -n28 - -28: ADD DOUBLE - - - -n2->n28 - - +n1->n2 + + n3 - -3: PARAM DOUBLE "y" + +3: PARAM DOUBLE "y" - + -n3->n1 - - +n1->n3 + + + + + +n5 + +5: END + + + +n1->n5 + + + + + +n22->n1 + + + + + +n28 + +28: ADD + + + +n2->n28 + + n3->n4 - - + + n26 - -26: ADD DOUBLE + +26: ADD n4->n26 - - + + n6 - -6: LOOP_BEGIN + +6: LOOP_BEGIN n5->n6 - - - - - -n15 - -15: IF - - - -n6->n15 - - + + n29 - -29: LOOP_END + +29: LOOP_END - + -n29->n6 - - +n6->n29 + + - + -n7->n6 - - +n6->n7 + + + + + +n6->n8 + + + + + +n6->n9 + + + + + +n15 + +15: IF + + + +n6->n15 + + + + + +n7->n28 + + n12 - -12: MUL DOUBLE + +12: MUL n7->n12 - - + + n7->n12 - - + + n24 - -24: MUL DOUBLE + +24: MUL n7->n24 - - + + - - -n28->n7 - - - - - -n8->n6 - - + + +n8->n26 + + n11 - -11: MUL DOUBLE + +11: MUL n8->n11 - - + + n8->n11 - - + + n8->n24 - - + + - - -n26->n8 - - - - - -n9->n6 - - + + +n9->n10 + + n9->n10 - - + + - - -n10->n9 - - + + +n17 + +17: RETURN n10->n17 - - + + n10->n19 - - + + n13 - -13: ADD DOUBLE + +13: ADD n11->n13 - - + + n25 - -25: SUB DOUBLE + +25: SUB n11->n25 - - + + n12->n13 - - + + n12->n25 - - + + n13->n14 - - + + n14->n15 - - + + n16 - -16: IF_TRUE + +16: IF_TRUE n15->n16 - - + + n18 - -18: IF_FALSE + +18: IF_FALSE n15->n18 - - + + n16->n17 - - + + + + + +n17->n22 + + n20 - -20: IF + +20: IF n18->n20 - - + + n19->n20 - - + + n21 - -21: IF_TRUE + +21: IF_TRUE n20->n21 - - + + n23 - -23: IF_FALSE + +23: IF_FALSE n20->n23 - - + + n21->n22 - - + + n23->n29 - - + + n27 - -27: ADD DOUBLE + +27: ADD n24->n27 - - + + n24->n27 - - + + n25->n26 - - + + n27->n28 - - + + diff --git a/ir_dump.c b/ir_dump.c index b084fd6..73cc4b9 100644 --- a/ir_dump.c +++ b/ir_dump.c @@ -54,9 +54,9 @@ void ir_dump(ir_ctx *ctx, FILE *f) void ir_dump_dot(ir_ctx *ctx, FILE *f) { - int DATA_WEIGHT = 1; - int CONTROL_WEIGHT = 2; - int REF_WEIGHT = 1; + int DATA_WEIGHT = 0; + int CONTROL_WEIGHT = 5; + int REF_WEIGHT = 4; ir_ref i, j, n, ref, *p; ir_insn *insn; uint32_t flags; @@ -73,11 +73,11 @@ void ir_dump_dot(ir_ctx *ctx, FILE *f) flags = ir_op_flags[insn->op]; if (flags & IR_OP_FLAG_CONTROL) { if (insn->op == IR_START) { - fprintf(f, "\t{rank=min; n%d [label=\"%d: %s\",shape=box,style=\"rounded,filled\",fillcolor=red,rank=min];}\n", i, i, ir_op_name[insn->op]); + fprintf(f, "\t{rank=min; n%d [label=\"%d: %s\",shape=box,style=\"rounded,filled\",fillcolor=red];}\n", i, i, ir_op_name[insn->op]); } else if (insn->op == IR_ENTRY) { fprintf(f, "\t{n%d [label=\"%d: %s\",shape=box,style=\"rounded,filled\",fillcolor=red];}\n", i, i, ir_op_name[insn->op]); } else if (flags & IR_OP_FLAG_TERMINATOR) { - fprintf(f, "\t{rank=max; n%d [label=\"%d: %s\",shape=box,style=\"rounded,filled\",fillcolor=red,rank=max];}\n", i, i, ir_op_name[insn->op]); + fprintf(f, "\t{rank=max; n%d [label=\"%d: %s\",shape=box,style=\"rounded,filled\",fillcolor=red];}\n", i, i, ir_op_name[insn->op]); } else if (flags & IR_OP_FLAG_MEM) { fprintf(f, "\tn%d [label=\"%d: %s\",shape=box,style=filled,fillcolor=pink];\n", i, i, ir_op_name[insn->op]); } else { @@ -86,7 +86,7 @@ void ir_dump_dot(ir_ctx *ctx, FILE *f) } else if (flags & IR_OP_FLAG_DATA) { if (IR_OPND_KIND(flags, 1) == IR_OPND_DATA) { /* not a leaf */ - fprintf(f, "\tn%d [label=\"%d: %s %s\"", i, i, ir_op_name[insn->op], ir_type_name[insn->type]); + fprintf(f, "\tn%d [label=\"%d: %s\"", i, i, ir_op_name[insn->op]); fprintf(f, ",shape=diamond,style=filled,fillcolor=deepskyblue];\n"); } else { if (insn->op == IR_PARAM) { @@ -108,13 +108,17 @@ void ir_dump_dot(ir_ctx *ctx, FILE *f) case IR_OPND_VAR: if (IR_IS_CONST_REF(ref)) { fprintf(f, "\tc%d -> n%d [color=blue,weight=%d];\n", -ref, i, DATA_WEIGHT); + } else if (insn->op == IR_PHI + && ctx->ir_base[insn->op1].op == IR_LOOP_BEGIN + && ctx->ir_base[ir_insn_op(&ctx->ir_base[insn->op1], j - 1)].op == IR_LOOP_END) { + fprintf(f, "\tn%d -> n%d [color=blue,dir=back];\n", i, ref); } else { fprintf(f, "\tn%d -> n%d [color=blue,weight=%d];\n", ref, i, DATA_WEIGHT); } break; case IR_OPND_CONTROL: if (insn->op == IR_LOOP_BEGIN && ctx->ir_base[ref].op == IR_LOOP_END) { - fprintf(f, "\tn%d -> n%d [style=bold,color=red,weight=%d];\n", ref, i, REF_WEIGHT); + fprintf(f, "\tn%d -> n%d [style=bold,color=red,dir=back];\n", i, ref); } else if (insn->op == IR_ENTRY) { fprintf(f, "\tn%d -> n%d [style=bold,color=red,style=dashed,weight=%d];\n", ref, i, CONTROL_WEIGHT); } else { @@ -123,7 +127,7 @@ void ir_dump_dot(ir_ctx *ctx, FILE *f) break; case IR_OPND_CONTROL_DEP: case IR_OPND_CONTROL_REF: - fprintf(f, "\tn%d -> n%d [style=dashed,weight=%d];\n", i, ref, REF_WEIGHT); + fprintf(f, "\tn%d -> n%d [style=dashed,dir=back,weight=%d];\n", ref, i, REF_WEIGHT); break; } }