All Projects → androm3da → Optviewer Demo

androm3da / Optviewer Demo

Demonstration of LLVM's opt-viewer tool

Programming Languages

shell
77523 projects

Projects that are alternatives of or similar to Optviewer Demo

Meta Clang
Clang C/C++ cross compiler and runtime for OpenEmbedded/Yocto Project
Stars: ✭ 76 (+20.63%)
Mutual labels:  llvm, clang, compilers
Gllvm
Whole Program LLVM: wllvm ported to go
Stars: ✭ 126 (+100%)
Mutual labels:  llvm, clang, compilers
open-ops
Open Optimizing Parallelizing System
Stars: ✭ 21 (-66.67%)
Mutual labels:  llvm, clang, compilers
Zapcc
zapcc is a caching C++ compiler based on clang, designed to perform faster compilations
Stars: ✭ 1,109 (+1660.32%)
Mutual labels:  llvm, clang
C2goasm
C to Go Assembly
Stars: ✭ 1,072 (+1601.59%)
Mutual labels:  llvm, clang
llvm-project-prepo
Fork of LLVM with modifications to support a program repository
Stars: ✭ 27 (-57.14%)
Mutual labels:  llvm, clang
wasm-toolchain
WebAssembly toolchain
Stars: ✭ 34 (-46.03%)
Mutual labels:  llvm, clang
Clang Power Tools
Bringing clang-tidy magic to Visual Studio C++ developers.
Stars: ✭ 285 (+352.38%)
Mutual labels:  llvm, clang
clang-format-editor
Clang-Format Editor is a tool that helps you find the best Clang-Format Style for your C++, C#, Java, JavaScript, and Objective-C code.
Stars: ✭ 15 (-76.19%)
Mutual labels:  llvm, clang
Swiftweekly.github.io
A community-driven weekly newsletter about Swift.org
Stars: ✭ 305 (+384.13%)
Mutual labels:  llvm, clang
Fcd
An optimizing decompiler
Stars: ✭ 622 (+887.3%)
Mutual labels:  llvm, clang
SameTypeClangPlugin
自定义检查规范的 Clang 插件
Stars: ✭ 47 (-25.4%)
Mutual labels:  llvm, clang
arch-packages
Arch Linux performance important packages
Stars: ✭ 27 (-57.14%)
Mutual labels:  llvm, clang
llvm-svn
Arch Linux PKGBUILD for LLVM, Clang et al. (latest SVN code)
Stars: ✭ 18 (-71.43%)
Mutual labels:  llvm, clang
hmg
💝 My personal Gentoo/Linux configuration backup files
Stars: ✭ 16 (-74.6%)
Mutual labels:  llvm, clang
Olifant
A simple programming language targeting LLVM
Stars: ✭ 58 (-7.94%)
Mutual labels:  llvm, clang
Enzyme
High-performance automatic differentiation of LLVM.
Stars: ✭ 418 (+563.49%)
Mutual labels:  llvm, clang
Cxxctp
DEPRECATED. USE INSTEAD github.com/blockspacer/flextool
Stars: ✭ 58 (-7.94%)
Mutual labels:  llvm, clang
Woboq codebrowser
Woboq CodeBrowser
Stars: ✭ 837 (+1228.57%)
Mutual labels:  llvm, clang
stack-guard
A toy implementation of 'Stack Guard' on top of the LLVM compiler toolchain
Stars: ✭ 21 (-66.67%)
Mutual labels:  llvm, clang

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)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].