Restrictifier



How to use the optimized output from the Web tool

The web tool outputs an optimized LLVM assembly file. Before linking it with the other modules of your C/C++/Objective-C program, you need to compile it for your specific machine.

For this, you need to have installed the LLVM binaries. These can be acquired by either building LLVM yourself (see Installation), or by installing them using a package manager of your operating system:

  1. Ubuntu Linux
  2. apt-get install clang llvm
  3. Mac OS X (you need to have Homebrew installed)
  4. brew install llvm

After having LLVM binaries installed, you can translate from the LLVM assembly to native assembly:

llc optimized.ll -o module.s

And finally compile the native assembly to an object file:

  1. In Linux:
  2. g++ module.s -o module.o
  3. In Mac OS X:
  4. clang++ module.s -o module.o


How to use Restrictifier on your own computer

Compatibility

This tool works on LLVM version 3.6. Compatibility with older versions is not guaranteed.

Download

Installation

You are required to build LLVM yourself. A very good guide for this can be found here. We recommend that you also build Clang, the C/C++/Obj-C frontend, alongside with LLVM, using this guide.

After building LLVM and Clang, it's the turn of building Restrictifier itself. This process is the same as building any custom LLVM pass. As such, this guide can help you in this effort.

Usage

Assuming you've correctly installed LLVM and Clang, it's pretty simple to use Restrictifier. You should have the LLVM binaries in your path.

First, we can translate a C/C++ file into an LLVM bitcode using Clang:

clang -c -emit-llvm file.c -o file.bc ${CFLAGS}
clang++ -c -emit-llvm file.cpp -o file.bc ${CXXFLAGS}

After all units have been compiled, you need to link them together:

llvm-link file1.bc file2.bc file3.bc -o program.bc ${LDFLAGS}

Now it's time to optimize your program. As such, use the LLVM optimizer:

opt -mem2reg -cfl-aa -libcall-aa -globalsmodref-aa -scev-aa -scoped-noalias -basicaa -tbaa 
-load PATH_TO_RESTRICTIFICATION/AliasFunctionCloning.(so|dylib) -afc -O3 -disable-inlining
-o program.optimized.bc

This is quite a long command. Let's break it down:

What is left to do is just translating it from LLVM assembly to native assembly:

llc program.optimized.bc -o program.s

And assemble it:

g++ program.s -o program.exe

Now you have an optimized version of your program.