Skip to content

LionsWrath/LLVM-RA-DeadCodeElimination

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DEAD CODE ELIMINATION

Information

  • LLVM version: 9.0.0svn;
  • CMake version: 3.13.4;

About the Range Analysis

  • The Range Analysis was modified for the LLVM 9.0.0;
  • The Profile Class was reimplemented and it's working correctly, printing the running times in seconds;
  • The Range Analysis and vSSA passes are now separated.

Compilation

Compilation outside the LLVM

  1. export LLVM_DIR=<path to llvm build>
  2. cd <printer base dir>
  3. mkdir build
  4. cd build
  5. cmake ..
  6. make

Compilation inside the LLVM

To add the Pass to the llvm compilation tree:

  1. cp -r VSSA <path to llvm source>/llvm/lib/Transforms/
  2. cp -r RangeAnalysis <path to llvm source>/llvm/lib/Transforms/
  3. cp -r DeadCodeElimination <path to llvm source>/llvm/lib/Transforms/
  4. Add add_subdirectory(VSSA) to <path to llvm source>/llvm/lib/Transforms/CMakeLists.txt
  5. Add add_subdirectory(RangeAnalysis) to <path to llvm source>/llvm/lib/Transforms/CMakeLists.txt
  6. Add add_subdirectory(DeadCodeElimination) to <path to llvm source>/llvm/lib/Transforms/CMakeLists.txt

Remove MODULE, PLUGIN_TOOL and the opt line from the CMakeList.txt in each of the copied dirs. Then, we can compile the llvm normally (now with our pass included):

  1. cd <path to llvm source>
  2. mkdir build
  3. cd build
  4. cmake .. -G "Unix Makefiles"
  5. make

Execution

First, we need to create the intermediate representation of the program:

  1. clang <input>.c -o <output_1>.bc -c -emit-llvm -O0
  2. opt -instnamer -mem2reg -break-crit-edges <output_1>.bc -o <output_2>.rbc

Outside the LLVM compilation

  1. opt -load <build>/VSSA/LLVMVSSA.so -vssa <output_2>.rbc -o <output_3>.vssa.rbc
  2. opt -load <build>/DeadCodeElimination/LLVMDeadCodeElimination.so -ra-dce <output_3>.vssa.rbc -o <output_4>.dce.rbc

Inside the LLVM compilation

  1. opt -vssa <output_2>.rbc -o <output_3>.vssa.rbc
  2. opt -ra-dce <output_3>.vssa.rbc -o <output_4>.dce.rbc

Scripts

I have some scripts to help execution in the Tests folder:

  • run_DCE.sh: Run the DCE for an .c file as argument;
  • test.sh: Run the DCE for all tests in Tests folder;
  • show.sh: Use dot to show a .dot file to pdf (may not be compatible);

Just rewrite the variables CLANG, OPT and BUILD_DIR to your configuration.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages