sfu-arch / memoizer

This project is a memoizer for a given function in a c++ program

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

These programs are demonstrations of how LLVM can be used for (very simple) static and dynamic analyses. However, they use many of the initial building blocks necessary for solving more complex problems.

The provided analyses count the number of direct invocations of a particular function are present within a program or within and execution depending on whether static or dynamic analysis is used.

Building with CMake

To run on server01

  • Add conda to your bashrc
. "/data/miniconda3/etc/profile.d/conda.sh"
conda activate
export PATH=/data/rvv/bin/:/data/llvm-11/bin:$PATH
  1. Clone the demo repository.

     git clone git@github.com:sfu-arch/llvm-demo.git
    
  2. Create a new directory for building.

     mkdir demobuild
    
  3. Change into the new directory.

     cd demobuild
    
  4. Run CMake with the path to the LLVM source.

     cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=True \
         -DLLVM_DIR=</path/to/LLVM/build>/lib/cmake/llvm/ ../llvm-demo
    

To use LLVM-11 on server-01:

-DLLVM_DIR=/data/llvm-11/lib/cmake/llvm
  1. Run make inside the build directory: LLVM_COMPILER=clang BINUTILS_TARGET_PREFIX=riscv64-unknown-elf make -j

This produces a callcounter tool called bin/callcounter and supporting libraries in lib/.

Note, building with a tool like ninja can be done by adding -G Ninja to the cmake invocation and running ninja instead of make.

Running

First suppose that you have a program compiled to bitcode:

clang -g -c -emit-llvm ../llvm-demo/test/simpletest.c -o calls.bc

Running the dynamic call printer:

bin/callcounter -dynamic calls.bc -o calls
./calls

Running the static call printer:

bin/callcounter -static calls.bc

or by loading the pass as a plugin for opt:

opt -analyze -load lib/libcallcounter-lib.so -callcounter calls.bc

About

This project is a memoizer for a given function in a c++ program

License:MIT License


Languages

Language:C++ 88.4%Language:CMake 10.3%Language:C 1.3%