├── .clang-format ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── LICENSE ├── LibCall.txt ├── README.rst ├── cmake └── FindLLVM.cmake ├── config.h.in ├── debug.gdb ├── example ├── 1.add.c ├── 1.add.ll ├── 2.fibonacci.c ├── 2.fibonacci.ll ├── 3.inst.ll └── 4.edge-profiling.ll ├── llvm-pred.pc.in ├── llvm ├── DeadArgumentElimination.cpp └── DeadStoreElimination.cpp ├── scripts ├── dirdiff.sh ├── drawline.py ├── freqavg.py ├── llc.sh └── quick-make.sh ├── src ├── Adaptive.cpp ├── Adaptive.h ├── CMakeLists.txt ├── DAEAdaptive.cpp ├── DSEAdaptive.cpp ├── IgnoreList.h ├── InsertTripCount.cpp ├── LoopTripCount.cpp ├── LoopTripCount.h ├── PerformPred.cpp ├── Print.cpp ├── Reduce.cpp ├── Reduce.h ├── Resolver.cpp ├── Resolver.h ├── datatype.h ├── ddg.cpp ├── ddg.h ├── debug.h ├── preheader.h ├── util.cpp └── util.h └── unit ├── CGFilterTest.cpp ├── CMakeLists.txt ├── GEPFilterTest.cpp ├── IgnoreListTest.cpp ├── NousedTest.cpp ├── UtilTest.cpp ├── gtest ├── gtest-all.cc ├── gtest.h └── gtest_main.cc └── internal.h /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | BasedOnStyle: WebKit 3 | IndentWidth: 3 4 | --- 5 | Language: Cpp 6 | PointerAlignment: Left 7 | ColumnLimit: 80 8 | AllowShortBlocksOnASingleLine: true 9 | ... 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | 6 | # Compiled Dynamic libraries 7 | *.so 8 | *.dylib 9 | 10 | # Compiled Static libraries 11 | *.lai 12 | *.la 13 | *.a 14 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "doc"] 2 | path = doc 3 | url = git@github.com:xiehuc/llvm-pred.wiki.git 4 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(llvm-pred) 3 | 4 | set(CMAKE_MODULE_PATH 5 | ${CMAKE_MODULE_PATH} 6 | ${CMAKE_SOURCE_DIR}/cmake 7 | ) 8 | 9 | if(NOT CMAKE_BUILD_TYPE) 10 | set(CMAKE_BUILD_TYPE "Release") 11 | endif() 12 | 13 | find_package(LLVM) 14 | 15 | option(DYNAMIC_LINK "Link Dynamic LLVM Libraries" ${LLVM_DYNAMIC_LIBRARY_FOUND}) 16 | option(WITH_DEBUG "Enable Extra Debug Output" On) 17 | option(WITH_MORE_DEBUG "Enable More Extra Debug Output" Off) 18 | set(PROMOTE_FREQ "select" CACHE STRINGS "Select how to fix promote errors in performance predication") 19 | set_property(CACHE PROMOTE_FREQ PROPERTY STRINGS "select" "path_prob") 20 | option(UNIT_TEST "Enable Build Unit Test" Off) 21 | option(TC_USE_SCEV "LoopTripcount use SCEV" Off) 22 | option(DELETE_STORE "Delete the Store instructions" Off) 23 | option(USE_CACHE "Use Cache to Speedup Cacluate" Off) 24 | option(USE_PROMOTE "Use Promote Algorithm to promote view port" On) 25 | 26 | 27 | find_package(PkgConfig) 28 | pkg_check_modules(LLVM_PROF llvm-prof REQUIRED) 29 | 30 | if(NOT WITH_DEBUG) 31 | set(NO_DEBUG On) 32 | endif() 33 | set(ANNOY_DEBUG ${WITH_MORE_DEBUG}) 34 | configure_file(config.h.in config.h) 35 | configure_file(llvm-pred.pc.in llvm-pred.pc @ONLY) 36 | install(FILES ${CMAKE_BINARY_DIR}/llvm-pred.pc DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig) 37 | message(STATUS "Add ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig to $PKG_CONFIG_PATH " 38 | "environment variable to let pkg-config find llvm-pred.pc") 39 | 40 | add_subdirectory(src) 41 | if(UNIT_TEST) 42 | add_subdirectory(unit) 43 | endif() 44 | -------------------------------------------------------------------------------- /LibCall.txt: -------------------------------------------------------------------------------- 1 | # gfortran part 2 | _gfortran_stop_string Mod # this function stops the whole program 3 | _gfortran_st_write_done NoModRef 4 | _gfortran_st_write NoModRef 5 | 6 | #mpi part 7 | mpi_init_ Mod 8 | mpi_finalize_ Mod 9 | mpi_comm_group_ Mod 10 | mpi_comm_size_ Mod 11 | mpi_comm_rank_ Mod 12 | #mpi_bcast_ Mod 13 | #mpi_barrier_ Mod 14 | #mpi_abort_ Mod 15 | #mpi_allreduce_ Mod 16 | #mpi_irecv_ Mod 17 | #mpi_error_string_ Mod 18 | #mpi_isend_ Mod 19 | #mpi_waitall_ Mod 20 | #mpi_win_create_ Mod 21 | #mpi_win_fence_ Mod 22 | #mpi_get_ Mod 23 | #mpi_put_ Mod 24 | #mpi_group_incl_ Mod 25 | #mpi_win_post_ Mod 26 | #mpi_win_start_ Mod 27 | #mpi_win_complete_ Mod 28 | #mpi_win_wait_ Mod 29 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ========= 2 | llvm-pred 3 | ========= 4 | 5 | A set of Pass and functions to help analysis program's performance model. 6 | 7 | build 8 | ------ 9 | 10 | if gcc doesn't support c++11 ,can use clang 11 | 12 | .. code:: bash 13 | 14 | $ export CC=clang 15 | $ export CXX=clang++ 16 | $ mkdir build;cd build 17 | $ cmake .. -DLLVM_RECOMMAND_VERSION="3.4" 18 | $ make 19 | 20 | use ``LLVM_RECOMMAND_VERSION`` to change llvm version directly 21 | 22 | script 23 | ------- 24 | 25 | * drawline.py : used to draw lines from value profiling 26 | * dirdiff.sh : compare two dir's llvmprof.out file and report whether they are 27 | same 28 | 29 | unit test 30 | --------- 31 | 32 | we provide some unit test in ``unit`` dir. to compile them, you need `google 33 | test`_ and `google mock`_ 34 | 35 | .. _google test: https://code.google.com/p/googletest 36 | .. _google mock: https://code.google.com/p/googlemock 37 | 38 | .. code:: bash 39 | 40 | $ cmake .. -DUNIT_TEST=On 41 | $ make 42 | $ cd unit 43 | $ ./unit_test 44 | 45 | documents 46 | ---------- 47 | 48 | we provide documents on wiki pages, you can use git submodule to sync them into 49 | doc folder. 50 | 51 | .. code:: bash 52 | 53 | $ git submodule init 54 | $ git submodule update 55 | -------------------------------------------------------------------------------- /cmake/FindLLVM.cmake: -------------------------------------------------------------------------------- 1 | # - Find LLVM 2 | # This module can be used to find LLVM. 3 | # It requires that the llvm-config executable be available on the system path. 4 | # Once found, llvm-config is used for everything else. 5 | # 6 | # The following variables are set: 7 | # 8 | # LLVM_FOUND - Set to YES if LLVM is found. 9 | # LLVM_VERSION - Set to the decimal version of the LLVM library. 10 | # LLVM_INCLUDE_DIRS - A list of directories where the LLVM headers are located. 11 | # LLVM_LIBRARY_DIRS - A list of directories where the LLVM libraries are located. 12 | # LLVM_LIBRARIES - A list of libraries which should be linked 13 | # LLVM_DYNAMIC_LIBRARY - A single dynamic llvm shared library 14 | # LLVM_DYNAMIC_LIBRARY_FOUND - Whether found the dynamic llvm shared library 15 | # LLVM_OPT - opt program in llvm 16 | # 17 | # Using Following macros to set static library: 18 | # llvm_map_components_to_libraries(OUTPUT_VARIABLE ${llvm components}) 19 | # 20 | # tutorial: 21 | # 1. select default LLVM version: 22 | # cmake .. -DLLVM_RECOMMEND_VERSION="3.5" 23 | # 2. set include dir and link dir: 24 | # include_directories(${LLVM_INCLUDE_DIRS}) 25 | # link_directories(${LLVM_LIBRARY_DIRS}) 26 | # 3.a link static libraries: 27 | # llvm_map_components_to_libraries(LLVM_IRREADER_LIRARY irreader) 28 | # target_link_libraries(target 29 | # ${LLVM_LIBRARIES} 30 | # ${LLVM_IRREADER_LIRARY} 31 | # ) 32 | # 3.b link a dynamic library: 33 | # target_link_libraries(target ${LLVM_DYNAMIC_LIBRARY}) 34 | # 35 | # 14-10-26: 36 | # LLVM_RECOMMAND_VERSION --> LLVM_RECOMMEND_VERSION 37 | # update tutorial 38 | # 39 | # version: 0.9.1 40 | # add LLVM_FLAGS_NDEBUG means llvm build with NDEBUG 41 | # 42 | # version: 0.9 43 | # remove LLVM_{C/CPP/CXX}_FLAGS which import -DNDEBUG 44 | # 45 | # 46 | if(NOT DEFINED LLVM_RECOMMEND_VERSION) 47 | set(LLVM_RECOMMEND_VERSION "" CACHE STRING "Switch the llvm version") 48 | set_property(CACHE LLVM_RECOMMEND_VERSION PROPERTY STRINGS "" "3.4" "3.5") 49 | endif() 50 | 51 | 52 | if(NOT(DEFINED LLVM_ROOT) ) 53 | if(NOT "${LLVM_VERSION}" EQUAL "{LLVM_RECOMMEND_VERSION}") 54 | unset(LLVM_CONFIG_EXE CACHE) 55 | unset(LLVM_DYNAMIC_LIBRARY CACHE) 56 | endif() 57 | # find llvm-config. perfers to the one with version suffix, Ex:llvm-config-3.2 58 | find_program(LLVM_CONFIG_EXE NAMES "llvm-config-${LLVM_RECOMMEND_VERSION}" "llvm-config") 59 | find_program(LLVM_OPT NAMES "opt-${LLVM_RECOMMEND_VERSION}" "opt") 60 | 61 | if(NOT LLVM_CONFIG_EXE) 62 | set(LLVM_FOUND False) 63 | message(FATAL_ERROR "Not Found LLVM (LLVM_RECOMMEND_VERSION=${LLVM_RECOMMEND_VERSION})") 64 | else() 65 | set(LLVM_FOUND True) 66 | endif() 67 | 68 | # Get the directory of llvm by using llvm-config. also remove whitespaces. 69 | execute_process(COMMAND ${LLVM_CONFIG_EXE} --prefix OUTPUT_VARIABLE LLVM_ROOT 70 | OUTPUT_STRIP_TRAILING_WHITESPACE ) 71 | 72 | endif() 73 | 74 | macro(_llvm_config _var_name) 75 | execute_process(COMMAND ${LLVM_CONFIG_EXE} ${ARGN} 76 | OUTPUT_VARIABLE ${_var_name} 77 | OUTPUT_STRIP_TRAILING_WHITESPACE 78 | ) 79 | endmacro() 80 | 81 | set(LLVM_INSTALL_PREFIX ${LLVM_ROOT}) 82 | add_definitions(-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS) 83 | 84 | _llvm_config(LLVM_VERSION --version) 85 | STRING(REGEX REPLACE "^([0-9]+)\\.[0-9]+(svn)?\\.?[0-9]*" "\\1" LLVM_VERSION_MAJOR "${LLVM_VERSION}") 86 | STRING(REGEX REPLACE "^[0-9]+\\.([0-9]+)(svn)?\\.?[0-9]*" "\\1" LLVM_VERSION_MINOR "${LLVM_VERSION}") 87 | _llvm_config(LLVM_LD_FLAGS --ldflags) 88 | _llvm_config(LLVM_LIBRARY_DIRS --libdir) 89 | _llvm_config(LLVM_INCLUDE_DIRS --includedir) 90 | string(REGEX MATCH "-l.*" LLVM_LIBRARIES ${LLVM_LD_FLAGS}) 91 | _llvm_config(LLVM_C_FLAGS --cflags) 92 | if(LLVM_C_FLAGS MATCHES "-DNDEBUG") 93 | add_definitions(-DLLVM_FLAGS_NDEBUG) 94 | endif() 95 | 96 | find_library(LLVM_DYNAMIC_LIBRARY 97 | NAMES "LLVM" "LLVM-${LLVM_VERSION}" 98 | PATHS ${LLVM_LIBRARY_DIRS} 99 | ) 100 | 101 | if(NOT LLVM_DYNAMIC_LIBRARY) 102 | set(LLVM_DYNAMIC_LIBRARY_FOUND False) 103 | else() 104 | set(LLVM_DYNAMIC_LIBRARY_FOUND True) 105 | endif() 106 | 107 | macro(llvm_map_components_to_libraries _var_name) 108 | _llvm_config(${_var_name} --libs "${ARGN}") 109 | endmacro() 110 | 111 | message(STATUS "Found LLVM Version ${LLVM_VERSION} ") 112 | 113 | -------------------------------------------------------------------------------- /config.h.in: -------------------------------------------------------------------------------- 1 | #ifndef LLE_CONFIG_H_H 2 | #define LLE_CONFIG_H_H 3 | 4 | #cmakedefine LLVM_VERSION_MAJOR @LLVM_VERSION_MAJOR@ 5 | #cmakedefine LLVM_VERSION_MINOR @LLVM_VERSION_MINOR@ 6 | #ifndef NO_DEBUG 7 | #cmakedefine NO_DEBUG 8 | #endif 9 | #cmakedefine ANNOY_DEBUG 10 | #define PROMOTE_FREQ_@PROMOTE_FREQ@ 11 | #cmakedefine TC_USE_SCEV 12 | #cmakedefine DELETE_STORE 13 | #cmakedefine USE_CACHE 14 | #cmakedefine USE_PROMOTE 15 | // DDGraph::expr() print ref number. to simplify presentation 16 | #define EXPR_ENABLE_REF 17 | // a special symbol for self reference 18 | #define PHINODE_CIRCLE "Δ" 19 | // a ddg would produce better string expr for loop cycle(tripcount)cycle 20 | #define CYCLE_EXPR_USE_DDG 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /debug.gdb: -------------------------------------------------------------------------------- 1 | define debug_reduce_call 2 | break lle::ReduceCode::nousedOperator(llvm::Use&, llvm::Instruction*, lle::ConfigFlags) 3 | commands 4 | disable $bp_no 5 | end 6 | set $bp_no = $bpnum 7 | # kept memory 8 | set $func_name = $arg0 9 | disable $bp_no 10 | break lle::ReduceCode::getAttribute(llvm::CallInst*) 11 | commands 12 | d $bpnum 13 | break +1 if strcmp(Name.Data, $func_name)==0 14 | commands 15 | enable $bp_no 16 | c 17 | end 18 | end 19 | end 20 | document debug_reduce_call 21 | debug AttributeFlags ReduceCode::getAttribute(CallInst * CI) 22 | it would block on nousedOperator function 23 | usage: debug_reduce_call "mpi_irecv_" 24 | end 25 | 26 | #vim: filetype=gdb 27 | -------------------------------------------------------------------------------- /example/1.add.c: -------------------------------------------------------------------------------- 1 | int a=0; 2 | int b=1; 3 | int main(int argc,char** argv) 4 | { 5 | int n=10000; 6 | int i=0; 7 | for(i=0;i:1 ; preds = %1, %0 15 | %2 = phi i32 [ %b.promoted, %0 ], [ %5, %1 ] 16 | %3 = phi i32 [ %a.promoted, %0 ], [ %4, %1 ] 17 | %i.01 = phi i32 [ 0, %0 ], [ %6, %1 ] 18 | %4 = add nsw i32 %2, %3 19 | %5 = add nsw i32 %4, %2 20 | %6 = add nsw i32 %i.01, 1 21 | %exitcond = icmp eq i32 %6, 10000 22 | br i1 %exitcond, label %7, label %1 23 | 24 | ;