• Stars
    star
    162
  • Rank 232,284 (Top 5 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 1 year ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Cargo subcommand for viewing LLVM optimization remarks.

cargo-remark Build Status Latest Version

Cargo subcommand that makes it possible to view LLVM optimization remarks generated during the compilation of your crate.

These remarks can tell you where and why has LLVM failed to apply certain optimizations. In certain cases1, you can use this knowledge to change your code so that it optimizes better. In the future, I hope that rustc will be able to emit its own, Rust-specific (MIR?) optimization remarks, but this is just an idea at this point.

cargo remark compiles your crate, generates LLVM remarks, and then parses them and visualizes them in a simple website. It is parallelized, which is important for large programs, because there can be a lot of remarks and since they are in YAML, their parsing is not very fast.

Contributions are welcome!

Generated output example

Screenshot of a set of visualized remarks on top of Rust source code

Installation

$ cargo install cargo-remark

Note that rustc has gained the ability to output LLVM optimization remarks in the YAML format on 2. 7. 2023, and it is currently unstable. Therefore, you will need a recent nightly version2 of the compiler to generate LLVM remarks.

$ rustup update nightly

Usage

rustc can generate LLVM remarks using the (currently unstable) -Zremark-dir flag, which is used internally by this crate. To generate remarks from your crate, use the following command:

$ cargo remark build

After the build finishes, the remarks will be located in target/remarks/yaml, and the rendered website will be located in target/remarks/web. You can open the website by pointing your web browser to target/remarks/web/index.html file, or by using the --open flag.

This command will automatically build your crate with optimizations, so you don't have to pass the --release flag. Currently, only missed optimization remarks will be visualized. Analysis and Passed remarks are ignored.

CLI parameters

Flag Default Description
--open (unset) Open the generated website with the default browser.
--external (unset) Visualize remarks from external crates (dependencies) and stdlib.
--filter FastISelFailure,NeverInline,SpillReloadCopies Comma separated list of remark passes that should be ignored.

Features

There is currently a single feature mimalloc, which is enabled by default, and which enables the use of the mimalloc allocator. To disable the feature, compile (or install) the crate with --no-default-features.

Rendering remarks from a directory

If you have a directory with YAML remarks on disk, and you just want to visualize them without invoking Cargo, you can use the analyze-remarks binary, which comes with this crate.

$ analyze-remarks <yaml-dir> --source-dir <crate root>

When you use this tool, you need to manually pass the root source directory from where the remarks were generated (with cargo remark, it is automatically inferred).

You could even use this binary to render remarks generated from C/C++ programs. One advantage of that is that analyze-remarks will probably be much faster than existing C/C++ remark tools, which are written in Python.

Usage with PGO

If you compile your crate with Profile-guided optimization (PGO), the generated remarks will contain "hotness", a measure of how important is each missed optimization remark. This can help with prioritizing which remarks should be resolved first.

You can combine cargo remark with the cargo-pgo command to generate remarks from a PGO optimized build:

# Compile with PGO instrumentation
$ cargo pgo build

# Gather PGO profiles
$ ./target/release/<target>/<binary> <workload>

# Compile with PGO optimizations and generate remarks
$ cargo remark wrap -- pgo optimize

Related work

This crate, and especially the generated website was heavily inspired by optview2, a tool for visualizing LLVM optimization remarks generated from C and C++ programs.

License

MIT

Footnotes

  1. Currently, probably only if you are a LLVM expert.

  2. At least nightly-2023-07-03-....

More Repositories

1

hardware-effects

Demonstration of various hardware effects.
C++
2,715
star
2

cargo-wizard

Cargo subcommand for configuring Cargo projects for best performance.
Rust
710
star
3

cargo-pgo

Cargo subcommand for optimizing Rust binaries/libraries with PGO and BOLT.
Rust
508
star
4

rust-delegate

Rust method delegation with less boilerplate
Rust
388
star
5

hardware-effects-gpu

Demonstration of various hardware effects on CUDA GPUs.
C++
304
star
6

davis

Assembly debugger written in Angular 2.
TypeScript
56
star
7

rust-course-fei

Rust course taught at FEI VŠB-TUO.
Rust
13
star
8

sigmod-2018

Code for the SIGMOD 2018 programming contest. Finished at 2nd place.
C++
12
star
9

debug-visualizer

Program memory visualizer for GDB/LLDB (bachelor thesis)
Python
10
star
10

sigmod-2019

Code for the SIGMOD 2019 programming contest. Finished at 2nd place.
C++
8
star
11

llvm-instrument

LLVM instrumentation
C++
6
star
12

rustlang.cz

Web that gathers information about the Rust community in the Czech Republic.
HTML
6
star
13

advent-of-code

Advent of code solutions
Python
4
star
14

cuda-profile

Instrumentation based profiler for CUDA (master thesis)
C++
3
star
15

sigmod-2016

Code for the SIGMOD 2016 programming contest. Finished at 14th place.
C++
3
star
16

talks

Source code and slides for my public talks.
Python
3
star
17

cfggen

Python configuration generator
Python
3
star
18

llvm-se

Static analysis using symbolic execution on top of LLVM IR
C++
2
star
19

handmade-quake

Quake recreated by following the tutorial from Philip Buuck (https://www.youtube.com/channel/UCXgjH2-Mrb3-h1_iWurz7dQ).
C
2
star
20

kobzol

2
star
21

async-iterator-examples

Examples of Rust async iterators
Rust
2
star
22

kobzol.github.io

Blog about programming stuff.
HTML
2
star
23

rust-web-app-demo

Demo of a small newsletter web app in Rust.
Rust
2
star
24

Spaceships

Android (Java) 2D game project made as a school assignment.
Java
1
star
25

Ghrab-Robot

Projekt robotického kroužku Gymnázia Ostrava-Hrabůvka.
C
1
star
26

cuda-graph

BFS implemented in CUDA.
C++
1
star
27

agu

Algorithmisation of Geometrical Problems VSB-TUO course
C++
1
star
28

ZPG-project

Project for ZPG (Principles of Computer Graphics).
C
1
star
29

turret

School project, (somehow modified) clone of Tower defense.
Java
1
star
30

Computer-Graphics-I

Code for subject Computer Graphics I at VSB-TUO.
C++
1
star
31

sigmod-2017

Code for the SIGMOD 2017 programming contest. Finished at 15th place.
C++
1
star
32

valgrind-se

Symbolic execution in Valgrind. Based on https://github.com/spirali/aislinn.
C
1
star
33

elsie-gallery

Python
1
star
34

arduino-tetris

Classic tetris game displayed on 8x8 LED Matrix (MAX72xx) on Arduino
C++
1
star
35

mkdocs-nedoc-plugin

Mkdocs plugin for the nedoc Python API documentation generator.
Python
1
star
36

rust-cmd-spawn-bench

Benchmark for process spawning in Rust, on Linux.
Python
1
star
37

pyladies-extended

Jupyter Notebook
1
star