This is an archive of the discontinued LLVM Phabricator instance.

[VPlan] Script to extract VPlan digraphs from log
ClosedPublic

Authored by rengolin on Oct 11 2018, 9:30 AM.

Details

Summary

The vectoriser's debug log prints VPlan digraphs, but it's a bit
cumbersome to extract them and render them into PNG images. This script
does exactly that, being careful enough to extract all individual plans,
name them appropriately and save in either .dot or .png files.

Usage:

$ $LLVM_SRC/utils/extract_vplan.py < debug.log 
Exporting VF1UF1 to DOT: VPlanVF1UF1.dot
Exporting VF24UF1 to DOT: VPlanVF24UF1.dot

$ $LLVM_SRC/utils/extract_vplan.py --png < debug.log 
Exporting VF1UF1 to PNG via dot: VPlanVF1UF1.png
Exporting VF24UF1 to PNG via dot: VPlanVF24UF1.png

Diff Detail

Repository
rL LLVM

Event Timeline

rengolin created this revision.Oct 11 2018, 9:30 AM
fhahn added a comment.Oct 11 2018, 9:50 AM

Great, I think we should definitely make it easier to visualize the vplans. I left a few python comments with suggestions, but they are mostly personal preference. I think in the future we may want something like a -dump-vplans flag, to conveniently dump plans as they are transformed.

utils/extract_vplan.py
24 ↗(On Diff #169227)

My python regex knowledge is a bit rusty, but I think it might be possible to simplify this a bit by having a multi line regex, something like pattern = re.compile(r"(digraph VPlan {.*})",re.DOTALL)

I am curious now and will give that a try.

43 ↗(On Diff #169227)

could this be something like for (name, plan) in zip(Names, VPlans):?

56 ↗(On Diff #169227)

could be with open(filename, 'w') as out: out.write(VPlans[i])

fhahn added inline comments.Oct 11 2018, 10:02 AM
utils/extract_vplan.py
24 ↗(On Diff #169227)
pattern = re.compile(r"(digraph VPlan {.*?\n})",re.DOTALL)

matches = re.findall(pattern, sys.stdin.read())

-> matches should be a list containing one string per digraph VPlan {}. I guess the regex could also be tweaked to extract the name, but that might make it a bit more complicated.

rengolin updated this revision to Diff 169232.Oct 11 2018, 10:07 AM

Hi Florian,

Indeed, the "zip" and "with" Python idioms are much nicer, thanks!

I haven't used glob read because I wanted to make sure I got the VF/UF from the right line.

I have now made it even more explicitly by changing the search to a match and making sure the beginning or the line is the one I want.

cheers,
--renato

rengolin updated this revision to Diff 169238.Oct 11 2018, 10:16 AM

Thanks Florian, your regex version is still easy to use and much cleaner.

Patch updated.

rengolin marked 4 inline comments as done.Oct 11 2018, 10:25 AM

I'm wondering... should we choose between dot and png? Or should we always print the dot file and, upon --png flag, also the png file?

I'm wondering... should we choose between dot and png? Or should we always print the dot file and, upon --png flag, also the png file?

I think either dot or png should be fine, and either can be default. If anyone need both, they can run the command twice.

rengolin updated this revision to Diff 169364.Oct 12 2018, 3:20 AM
rengolin edited the summary of this revision. (Show Details)

Consistent messages.

(very gentle ping) :)

fhahn accepted this revision.Oct 15 2018, 4:30 PM

LGTM, thanks!

utils/extract_vplan.py
34 ↗(On Diff #169364)

nit: line quite long

This revision is now accepted and ready to land.Oct 15 2018, 4:30 PM
rengolin marked an inline comment as done.Oct 16 2018, 2:40 AM
This revision was automatically updated to reflect the committed changes.