This is an archive of the discontinued LLVM Phabricator instance.

Support of CFG dot dump with layout annotation after MBP pass
ClosedPublic

Authored by davidxl on Jan 25 2017, 11:21 AM.

Details

Summary

There is currently no way to view CFG graphically with layout decision after MBP pass. Developers currently rely on debug text dump to debug layout related bugs.

This patch adds the capability to dump/view cfg dump file after MBP pass. It enhances the existing MBFI graph dumping with an optional functionality to display the layout order of an machine basic block. The order of a basic block is displayed as a sequence number encoded in brackets [] after the block name string. The graph will also show branch probabilities and frequencies/count information.

The option is:

-mllvm -view-block-layout-with-bfi=[integer|fraction|count]

To filter, do -mllvm -view-bfi-func-name=<name>

Example for CodeGen/PowerPC/tail-dup-layout.ll

  1. block layout with tailduplication enabled:

https://reviews.llvm.org/F3024165

  1. block layout with tail-dup disabled:

https://reviews.llvm.org/F3024166

Diff Detail

Repository
rL LLVM

Event Timeline

davidxl created this revision.Jan 25 2017, 11:21 AM
davidxl updated this revision to Diff 86089.Jan 27 2017, 11:45 AM

Remove redundant lines.

vsk added inline comments.Jan 27 2017, 3:46 PM
include/llvm/Analysis/BlockFrequencyInfoImpl.h
1301 ↗(On Diff #86089)

'.str()' shouldn't be needed in either branch.

lib/CodeGen/MachineBlockFrequencyInfo.cpp
117 ↗(On Diff #86089)

Can we just use Node->getNumber() here? IIUC it's available so long as the MBB is in a MachineFunc, which we appear to be assuming?

davidxl marked an inline comment as done.Jan 27 2017, 4:23 PM
davidxl added inline comments.
include/llvm/Analysis/BlockFrequencyInfoImpl.h
1301 ↗(On Diff #86089)

ok

lib/CodeGen/MachineBlockFrequencyInfo.cpp
117 ↗(On Diff #86089)

It is tempting but the requires invoking MF.RenumberBlocks() which has side effects. A debug option should not change optimizer behavior.

vsk accepted this revision.Jan 27 2017, 4:36 PM

LGTM.

lib/CodeGen/MachineBlockFrequencyInfo.cpp
117 ↗(On Diff #86089)

Oh, I see, MBB.Number starts off as -1 without RenumberBlocks().

This revision is now accepted and ready to land.Jan 27 2017, 4:36 PM
davidxl updated this revision to Diff 86144.Jan 27 2017, 4:37 PM
davidxl marked an inline comment as done.

addressed review feedback.

This revision was automatically updated to reflect the committed changes.