Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit d3f67db

Browse files
Mike KleinSkia Commit-Bot
Mike Klein
authored and
Skia Commit-Bot
committed
add Builder::dot()
Just a quick hack up to dump out a dot-compatible graph. Arrows go from instruction -> args, making them depends-on arrows, not data-flows-this-way arrows. Example: ninja -C out nanobench out/nanobench --config 8888 -m bitmap_RGBA_8888_A_scale_bicubic --skvm dot /tmp/CT4-AT2-Cov0-Blend3-CS0-Shader7d2763e63326274c.dot -T png -O open /tmp/*.png Change-Id: Ic1ad99bb39f84a211304feef8ac485c0225d6a60 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/276184 Reviewed-by: Herb Derby <[email protected]> Commit-Queue: Mike Klein <[email protected]>
1 parent 121c2af commit d3f67db

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

src/core/SkVM.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,44 @@ namespace skvm {
144144
}
145145
}
146146

147+
void Builder::dot(SkWStream* o) const {
148+
SkDebugfStream debug;
149+
if (!o) { o = &debug; }
150+
151+
std::vector<OptimizedInstruction> optimized = this->optimize();
152+
153+
o->writeText("digraph {\n");
154+
for (Val id = 0; id < (Val)optimized.size(); id++) {
155+
auto [op, x,y,z, immy,immz, death,can_hoist,used_in_loop] = optimized[id];
156+
157+
switch (op) {
158+
default:
159+
write(o, "\t", V{id}, " [label = \"", V{id}, op);
160+
// Not a perfect heuristic; sometimes y/z == NA and there is no immy/z.
161+
// On the other hand, sometimes immy/z=0 is meaningful and should be printed.
162+
if (y == NA) { write(o, "", Hex{immy}); }
163+
if (z == NA) { write(o, "", Hex{immz}); }
164+
write(o, "\"]\n");
165+
166+
write(o, "\t", V{id}, " -> {");
167+
// In contrast to the heuristic imm labels, these dependences are exact.
168+
if (x != NA) { write(o, "", V{x}); }
169+
if (y != NA) { write(o, "", V{y}); }
170+
if (z != NA) { write(o, "", V{z}); }
171+
write(o, " }\n");
172+
173+
break;
174+
175+
// That default: impl works pretty well for most instructions,
176+
// but some are nicer to see with a specialized label.
177+
178+
case Op::splat:
179+
write(o, "\t", V{id}, " [label = \"", V{id}, op, Splat{immy}, "\"]\n");
180+
break;
181+
}
182+
}
183+
o->writeText("}\n");
184+
}
147185

148186
void Builder::dump(SkWStream* o) const {
149187
SkDebugfStream debug;

src/core/SkVM.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ namespace skvm {
557557
Color lerp(Color lo, Color hi, F32 t);
558558

559559
void dump(SkWStream* = nullptr) const;
560+
void dot (SkWStream* = nullptr) const;
560561

561562
uint64_t hash() const;
562563

src/core/SkVMBlitter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,11 @@ namespace {
598598
SkDebugf("\ncouldn't JIT %s\n", debug_name(key).c_str());
599599
builder.dump();
600600
program.dump();
601+
602+
SkString path = SkStringPrintf("/tmp/%s.dot", debug_name(key).c_str());
603+
SkFILEWStream tmp(path.c_str());
604+
builder.dot(&tmp);
605+
601606
missed++;
602607
}
603608
if (0 == total++) {

0 commit comments

Comments
 (0)