All Projects → abenkhadra → Llvm Pass Tutorial

abenkhadra / Llvm Pass Tutorial

Licence: other
A step-by-step tutorial for building an LLVM sample pass

Projects that are alternatives of or similar to Llvm Pass Tutorial

Cmake Tutorial
CMake 官方教程
Stars: ✭ 162 (+32.79%)
Mutual labels:  cmake, tutorial
Cmake Scripts
A selection of useful scripts for use in CMake projects, include code coverage, sanitizers, and dependency graph generation.
Stars: ✭ 202 (+65.57%)
Mutual labels:  cmake, llvm
How To Write An Llvm Register Allocator
This repository contains a tutorial for a quick start in how to write a register allocator using LLVM
Stars: ✭ 197 (+61.48%)
Mutual labels:  llvm, tutorial
Llvm Sanitizer Tutorial
An LLVM sanitizer tutorial
Stars: ✭ 130 (+6.56%)
Mutual labels:  llvm, tutorial
Cmake Demo
《CMake入门实战》源码
Stars: ✭ 1,071 (+777.87%)
Mutual labels:  cmake, tutorial
Cgold
🐋 The Hitchhiker’s Guide to the CMake
Stars: ✭ 428 (+250.82%)
Mutual labels:  cmake, tutorial
Learning Cmake
learning cmake
Stars: ✭ 2,524 (+1968.85%)
Mutual labels:  cmake, tutorial
Cxxctp
DEPRECATED. USE INSTEAD github.com/blockspacer/flextool
Stars: ✭ 58 (-52.46%)
Mutual labels:  cmake, llvm
Ros Academy For Beginners
中国大学MOOC《机器人操作系统入门》代码示例 ROS tutorial
Stars: ✭ 861 (+605.74%)
Mutual labels:  cmake, tutorial
Cmake Examples
Useful CMake Examples
Stars: ✭ 7,220 (+5818.03%)
Mutual labels:  cmake, tutorial
Llvm 9.0 Learner Tutorial
A blog for LLVM(v9.0.0 or v11.0.0) beginner, step by step, with detailed documents and comments. Record the way I learn LLVM and accomplish a complete project for FPGA High-Level Synthesis with it.
Stars: ✭ 58 (-52.46%)
Mutual labels:  llvm, tutorial
Jni By Examples
🎇Fun Java JNI By Examples - with CMake and C++ (or C, of course!) ‼️ Accepting PRs
Stars: ✭ 99 (-18.85%)
Mutual labels:  cmake, tutorial
Qiskit Tutorials
A collection of Jupyter notebooks showing how to use the Qiskit SDK
Stars: ✭ 1,777 (+1356.56%)
Mutual labels:  tutorial
Pt.javascript.info
Modern JavaScript Tutorial in Portuguese
Stars: ✭ 121 (-0.82%)
Mutual labels:  tutorial
Vuex Shopping Cart
🛒 Shopping cart built with Vue and Vuex
Stars: ✭ 118 (-3.28%)
Mutual labels:  tutorial
Vae Tensorflow
A Tensorflow implementation of a Variational Autoencoder for the deep learning course at the University of Southern California (USC).
Stars: ✭ 117 (-4.1%)
Mutual labels:  tutorial
Griefly
Griefly: Yet Another Space Station Remake
Stars: ✭ 121 (-0.82%)
Mutual labels:  cmake
Pandas Videos
Jupyter notebook and datasets from the pandas Q&A video series
Stars: ✭ 1,716 (+1306.56%)
Mutual labels:  tutorial
Godotrogueliketutorial
A guide to build a simple Roguelike game with Godot engine.
Stars: ✭ 117 (-4.1%)
Mutual labels:  tutorial
Commotion Router
The build system for the OpenWRT-based Commotion firmware.
Stars: ✭ 117 (-4.1%)
Mutual labels:  cmake

At a glance

A step-by-step tutorial for building an out-of-source LLVM pass based on Adrian Sampson's "LLVM for Grad Students"

Setup

LLVM is an umbrella project for building compilers and code transformation tools. It consists of several sub-projects like Clang, LLD and, confusingly enough, the LLVM sub-project. We consider in this tutorial:

  • Building the LLVM sub-project from source
  • Building a trivial out-of-source LLVM pass.

We will be building LLVM v10.0.0 which is the latest as of this writing. We assume that you have a working compiler toolchain (GCC or LLVM) and that CMake is installed (minimum version 3.4).

Compiling LLVM

Compiling LLVM from source is mandatory if you are developing an in-source pass (within LLVM source tree). It can also be convenient in the case of developing out-of-source passes as it gives you full control over the compilation options. For example, a debug build of LLVM is much more pleasant to work with compared to an optimized one. To compile LLVM, please follow the following steps:

  1. Download LLVM source and unpack it in a directory of your choice which will refer to as [LLVM_SRC]

  2. Create a separate build directory

    $ mkdir llvm-build
    $ cd llvm-build
    
  3. Instruct CMake to detect and configure your build environment:

    $ cmake -DCMAKE_BUILD_TYPE=Debug -DLLVM_TARGETS_TO_BUILD=X86 [LLVM_SRC]
    

    Note that we instructed cmake to only build X86 backend. You can choose a different backend if needed. If you do not specify LLVM_TARGETS_TO_BUILD, then all supported backends will be built by default which requires more time.

  4. Now start the actual compilation within your build directory

    $ cmake --build .
    

    The --build option is a portable why to tell cmake to invoke the underlying build tool (make, ninja, xcodebuild, msbuild, etc.)

  5. Building takes some time to finish. After that you can install LLVM in its default directory which is /usr/local

    $ cmake --build . --target install
    

    Alternatively, it's possible to set a different install directory [LLVM_HOME]. Since we will need [LLVM_HOME] in the next stage, we assume that you have defined it as an environment variable $LLVM_HOME. Now you can issue the following command

    $ cmake -DCMAKE_INSTALL_PREFIX=$LLVM_HOME -P cmake_install.cmake
    

    Note that $LLVM_HOME must not contain ~ (tilde) to refer to your home directory as it won't be expanded. Use $HOME or an absolute path instead.

Building a trivial LLVM pass

To build the skeleton LLVM pass found in skeleton folder:

$ cd llvm-pass-tutorial
$ mkdir build
$ cd build
$ cmake ..
$ make

cmake needs to find its LLVM configurations in [LLVM_DIR]. We automatically setup [LLVM_DIR] based on $LLVM_HOME for you. Now the easiest way to run the skeleton pass is to use Clang:

$ clang-7.0 -Xclang -load -Xclang build/skeleton/libSkeletonPass.* something.c$

Note that Clang is the compiler front-end of the LLVM project. It can be installed separately in binary form.

Further resources

This tutorial is based on the following resources

  • Adrian Sampson's blog entry "LLVM for Grad Students" (link)
  • LLVM documentation: Writing an LLVM pass (link)
  • LLVM documentation: Building LLVM with CMake (link)
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].