Code Monkey home page Code Monkey logo

optviewer-demo's Introduction

What is opt-viewer?

opt-viewer can tell you more about missed optimization opportunities. The optimizers that clang uses can explain the rationale for why their specific optimization method couldn't be leveraged in given parts of your source.

Build status

Output Examples

Usage

Prep

Grab a very recent clang, 4.0 or later for your architecture/OS distro and install or unpack it on your machine.

The example below is for ARM7a linux, there are several other releases available.

curl -O http://releases.llvm.org/4.0.0/clang+llvm-4.0.0-armv7a-linux-gnueabihf.tar.xz
tar xf clang+llvm-4.0.0-rc1-armv7a-linux-gnueabihf.tar.xz 

Or instead you might have Ubuntu. Below is how you would do it for Ubuntu Trusty. If you're not sure which Ubuntu release you have, see "Checking Your Ubuntu Version".

wget -nv -O - http://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-add-repository -y 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-4.0 main'
sudo apt-get update -qq
sudo apt-get install -qq -y clang-4.0 llvm-4.0

Next, you must get a copy of opt-viewer. For now, it's not distributed with clang+llvm releases, so a simple way to get it is to just get a copy of the llvm project source from github. Unpack or clone it somewhere convenient and note where you put it.

Once you have a new clang installed, build your software with it. You must include "-fsave-optimization-record" among the arguments. Imagine we have the following sample C/C++ project:

sample/
└── src
    ├── bar.cpp
    ├── baz.cpp
    ├── foo.c
    └── Makefile

If you're using make, you could add these lines to your Makefile:

CXXFLAGS+=-fsave-optimization-record
CLAGS+=-fsave-optimization-record

and then clang will build your program or library like so:

clang-4.0 -fsave-optimization-record -c -o foo.o foo.cpp
...

clang will create build annotation artifacts in the YAML format. Now you can use opt-viewer to see these in relation to your project.

Generating output

First, gather the necessary dependencies for opt-viewer:

virtualenv optviewer_env
source optviewer_env/bin/activate
pip install pyyaml pygments

Let's assume your sample project is in the same directory as the one where you unpacked/cloned llvm. Then you should invoke opt-viewer like so:

llvm/utils/opt-viewer/opt-viewer.py -source-dir sample/src/ \
    sample/src/baz.opt.yaml \
    sample/src/bar.opt.yaml \
    sample/src/foo.opt.yaml \
    ./output_report/

In the output_report dir, we'll have some output files that could look like below:

opt-viewer screenshot

Advanced usage: PGO

If you are able to leverage profile-guided-optimization (PGO), opt-viewer will produce an index that's sorted by the most-frequently executed code ("hotness"). This makes it easy to see which functions and methods would benefit the most from improved optimization.

For more info on PGO, see the clang manual on PGO.

Appendix

  • opt-viewer was introduced in "Compiler-assisted Performance Analysis", 2016 Bay Area LLVM Developer's Meeting (slides, video)

optviewer-demo's People

Contributors

androm3da avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

optviewer-demo's Issues

python 3.8 cgi.escape() deprecated

Deprecated since version 3.2: This function is unsafe because quote is false by default, and therefore deprecated. Use html.escape() instead.

your code failed on a modern system perhaps I should contact LLVM directly?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.