Git Product home page Git Product logo

outoftreellvmpass's Introduction

OutOfTreeLLVMPass

Template for creating an out of tree llvm pass that can be built with pre-compiled llvm binaries or from llvm source.

Setup the build system

llvm sources

Clone this repository and the llvm source next to each other and create a build folder. Run cmake from within the build folder:

git clone https://github.com/tgymnich/OutOfTreeLLVMPass.git
git clone https://github.com/llvm/llvm-project.git
mkdir build
cd build
cmake -DPATH_TO_LLVM=../llvm-project/llvm ../OutOfTreeLLVMPass

pre-compiled llvm

Clone this repoitory and install or download a pre-compiled version of llvm for your system. The example uses macOS and llvm 9.0.0. Run cmake from within the build folder.

git clone https://github.com/tgymnich/OutOfTreeLLVMPass.git
wget http://releases.llvm.org/9.0.0/clang+llvm-9.0.0-x86_64-darwin-apple.tar.xz
tar xzf clang+llvm-9.0.0-x86_64-darwin-apple.tar.xz
mkdir build
cd build
cmake -DPATH_TO_LLVM=../clang+llvm-9.0.0-x86_64-darwin-apple ../OutOfTreeLLVMPass

Build the pass

cmake --build .

Run the pass

Make sure to provide some bitcode or LLVM IR in hello.bc / hello.ll. If your are not using macOS make sure to adapt the file ending for the compiled module to .so or .dll.

llvm source

./llvm-build/bin/opt -load OutOfTreeLLVMPass.dylib -hello < hello.ll > /dev/null

pre-compiled llvm

../clang+llvm-9.0.0-x86_64-darwin-apple/bin/opt -load OutOfTreeLLVMPass.dylib -hello < hello.ll > /dev/null

outoftreellvmpass's People

Contributors

tgymnich avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

melt19

outoftreellvmpass's Issues

Missing "-enable-new-pm=0" flag in command line

As described in the red Warning box (https://llvm.org/docs/WritingAnLLVMPass.html#introduction-what-is-a-pass), LLVM uses the new pass manager by default, and to use the legacy pass manager, -enable-new-pm=0 flag should be set.

On my machine, -enable-new-pm=0 is required to load the pass.

E.g. instead of

$ ../clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/opt -load ./OutOfTreeLLVMPass.so -hello < hello.ll > /dev/null
opt: unknown pass name 'hello'

write

$ ../clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/opt -load ./OutOfTreeLLVMPass.so -hello < hello.ll > /dev/null  -enable-new-pm=0
Hello: main

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.