This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen] Add Performance Monitor
ClosedPublic

Authored by grosser on Apr 3 2017, 6:20 AM.

Details

Summary

Add support for -polly-codegen-perf-monitoring. When performance monitoring
is enabled, we emit performance monitoring code during code generation that
prints after program exit statistics about the total number of cycles executed
as well as the number of cycles spent in scops. This gives an estimate on how
useful polyhedral optimizations might be for a given program.

Example output:

Polly runtime information
-------------------------
Total: 783110081637
Scops: 663718949365

In the future, we might also add functionality to measure how much time is spent
in optimized scops and how many cycles are spent in the fallback code.

Diff Detail

Repository
rL LLVM

Event Timeline

grosser created this revision.Apr 3 2017, 6:20 AM
sebpop added inline comments.Apr 3 2017, 6:52 AM
lib/CodeGen/PerfMonitor.cpp
58 ↗(On Diff #93852)

So this code will only work on x86?
Could this be made to work on other archs?
If not, we would need to disable the perf monitoring code for all other --target's.

Yes, until know this works only on X86. I intended this as a basic debugging facility. If there is interest (and instructions) it would be nice to generalize this. For ARM we could emit "MRC" instructions, but they do not seem to be accessible by default: http://blog.regehr.org/archives/794

Maybe we should just assert if this is not X86_64 for now?

sebpop edited edge metadata.Apr 3 2017, 7:13 AM

Maybe we should just assert if this is not X86_64 for now?

Yes, before starting generating the code for the perf monitoring, just add
if (Triple.getArch() == llvm::Triple::x86_64)
otherwise the flag should be a no-op, or a warning "flag not supported for this arch".

grosser updated this revision to Diff 93854.Apr 3 2017, 7:24 AM

Add check for X86_64 target sugggested by Sebastian.

We now do not perform performance monitoring on other architectures, but just print that runtime information generation is not supported.

sebpop accepted this revision.Apr 3 2017, 7:33 AM

LGTM.

This revision is now accepted and ready to land.Apr 3 2017, 7:33 AM
bollu edited edge metadata.Apr 3 2017, 8:04 AM

other than typo, LGTM

include/polly/CodeGen/PerfMonitor.h
89 ↗(On Diff #93854)

"modulo" should be "module"?

bollu accepted this revision.Apr 3 2017, 8:04 AM
This revision was automatically updated to reflect the committed changes.