├── .gitignore ├── .travis.yml ├── Dockerfile ├── LICENSE.TXT ├── Makefile ├── Makefile.common.in ├── Makefile.llvm.config.in ├── Makefile.llvm.rules ├── README.md ├── autoconf ├── AutoRegen.sh ├── ExportMap.map ├── LICENSE.TXT ├── aclocal.m4 ├── config.guess ├── config.sub ├── configure.ac ├── install-sh ├── ltmain.sh ├── m4 │ ├── build_exeext.m4 │ ├── c_printf_a.m4 │ ├── check_gnu_make.m4 │ ├── config_makefile.m4 │ ├── config_project.m4 │ ├── cxx_flag_check.m4 │ ├── find_std_program.m4 │ ├── func_isinf.m4 │ ├── func_isnan.m4 │ ├── func_mmap_file.m4 │ ├── header_mmap_anonymous.m4 │ ├── huge_val.m4 │ ├── libtool.m4 │ ├── link_options.m4 │ ├── linux_mixed_64_32.m4 │ ├── ltdl.m4 │ ├── need_dev_zero_for_mmap.m4 │ ├── path_tclsh.m4 │ ├── rand48.m4 │ ├── sanity_check.m4 │ ├── single_cxx_check.m4 │ └── visibility_inlines_hidden.m4 └── mkinstalldirs ├── configure ├── docs ├── GSoC2013 │ ├── proposal │ │ ├── Makefile │ │ ├── main.pdf │ │ ├── main.tex │ │ └── references.bib │ └── report │ │ ├── Makefile │ │ ├── main.pdf │ │ ├── main.tex │ │ ├── references.bib │ │ └── struct-ptr.c ├── blog │ ├── giri-flow.jpg │ ├── giri-flow.vsd │ └── llvm-blog.html └── index.html ├── include ├── Giri │ ├── Giri.h │ ├── Runtime.h │ └── TraceFile.h └── Utility │ ├── BasicBlockNumbering.h │ ├── CountSrcLines.h │ ├── LoadStoreNumbering.h │ ├── PostDominanceFrontier.h │ ├── SourceLineMapping.h │ ├── Utils.h │ └── VectorExtras.h ├── lib ├── Giri │ ├── Giri.cpp │ ├── Makefile │ ├── TestPass.cpp │ ├── TraceFile.cpp │ └── TracingNoGiri.cpp ├── Makefile └── Utility │ ├── BasicBlockNumbering.cpp │ ├── CountSrcLines.cpp │ ├── LoadStoreNumbering.cpp │ ├── Makefile │ ├── PostDominatorFrontier.cpp │ └── SourceLineMapping.cpp ├── runtime ├── Giri │ ├── Makefile │ └── Tracing.cpp └── Makefile ├── test ├── HelloWorld │ ├── Makefile │ └── hello-world.c ├── Makefile ├── Makefile.common ├── UnitTests │ ├── test1 │ │ ├── Makefile │ │ ├── README.md │ │ ├── ans-inst.txt │ │ └── extlibcalls.c │ ├── test10 │ │ ├── Makefile │ │ ├── README.md │ │ ├── ans-inst.txt │ │ └── str.c │ ├── test11 │ │ ├── Makefile │ │ ├── README.md │ │ ├── ans-inst.txt │ │ └── hello2p.c │ ├── test12 │ │ ├── Makefile │ │ ├── README.md │ │ ├── ans-inst.txt │ │ └── psum.c │ ├── test13 │ │ ├── Makefile │ │ ├── README.md │ │ ├── ans-inst.txt │ │ └── struct.c │ ├── test14 │ │ ├── Makefile │ │ ├── README.md │ │ ├── ans-inst.txt │ │ └── struct-ptr.c │ ├── test15 │ │ ├── Makefile │ │ ├── README.md │ │ ├── ans-inst.txt │ │ └── hanoi.c │ ├── test16 │ │ ├── Makefile │ │ ├── README.md │ │ ├── ans-inst.txt │ │ ├── calc.c │ │ ├── calc.h │ │ └── struct-ptr.c │ ├── test17 │ │ ├── Makefile │ │ ├── README.md │ │ ├── ans-inst.txt │ │ ├── ans-loc.txt │ │ ├── criterion-inst.txt │ │ ├── criterion-loc.txt │ │ └── plower.c │ ├── test18 │ │ ├── Makefile │ │ ├── README.md │ │ ├── ans-inst.txt │ │ └── extlibcalls.c │ ├── test19 │ │ ├── Makefile │ │ ├── README.md │ │ ├── ans-inst.txt │ │ └── fibonacci.c │ ├── test2 │ │ ├── Makefile │ │ ├── README.md │ │ ├── ans-inst.txt │ │ └── ifelse.c │ ├── test20 │ │ ├── Makefile │ │ ├── README.md │ │ ├── ans-inst.txt │ │ └── even.c │ ├── test21 │ │ ├── Makefile │ │ ├── README.md │ │ ├── ans-inst.txt │ │ ├── criterion-inst.txt │ │ └── hwtype.c │ ├── test22 │ │ ├── Makefile │ │ ├── ans-inst.txt │ │ ├── criterion-inst.txt │ │ └── fp.c │ ├── test3 │ │ ├── Makefile │ │ ├── README.md │ │ ├── ans-inst.txt │ │ └── fibonacci.c │ ├── test4 │ │ ├── Makefile │ │ ├── README.md │ │ ├── ans-inst.txt │ │ ├── ans-loc.txt │ │ ├── criterion-inst.txt │ │ ├── criterion-loc.txt │ │ └── example.c │ ├── test5 │ │ ├── Makefile │ │ ├── README.md │ │ ├── ans-inst.txt │ │ └── hellothreads.c │ ├── test6 │ │ ├── Makefile │ │ ├── README.md │ │ ├── ans-inst.txt │ │ └── sigusr1.c │ ├── test7 │ │ ├── Makefile │ │ ├── README.md │ │ ├── ans-inst.txt │ │ └── sigint.c │ ├── test8 │ │ ├── Makefile │ │ ├── README.md │ │ ├── ans-inst.txt │ │ └── ptr.c │ └── test9 │ │ ├── Makefile │ │ ├── README.md │ │ ├── ans-inst.txt │ │ └── forloop.c ├── auto-tests.txt ├── histogram │ ├── Makefile │ ├── README.md │ ├── histogram-pthread.c │ ├── histogram-seq.c │ ├── loc-pthread.txt │ └── stddefines.h ├── kmeans │ ├── Makefile │ ├── README.md │ ├── ans-inst-pthread.txt │ ├── ans-inst-seq.txt │ ├── ans-loc-pthread.txt │ ├── ans-loc-seq.txt │ ├── criterion-inst-pthread.txt │ ├── criterion-inst-seq.txt │ ├── criterion-loc-pthread.txt │ ├── criterion-loc-seq.txt │ ├── kmeans-pthread.c │ ├── kmeans-seq.c │ ├── map_reduce.h │ └── stddefines.h ├── linear_regression │ ├── Makefile │ ├── README.md │ ├── linear_regression-pthread.c │ ├── linear_regression-seq.c │ ├── loc-pthread.txt │ └── stddefines.h ├── matrix_multiply │ ├── .gitignore │ ├── Makefile │ ├── README.md │ ├── ans-inst-pthread.txt │ ├── ans-inst-seq.txt │ ├── ans-loc-pthread.txt │ ├── ans-loc-seq.txt │ ├── criterion-inst-pthread.txt │ ├── criterion-inst-seq.txt │ ├── criterion-loc-pthread.txt │ ├── criterion-loc-seq.txt │ ├── map_reduce.h │ ├── matrix_file_A.txt │ ├── matrix_file_B.txt │ ├── matrix_multiply-pthread.c │ ├── matrix_multiply-seq.c │ └── stddefines.h ├── pca │ ├── Makefile │ ├── README.md │ ├── ans-inst-pthread.txt │ ├── ans-inst-seq.txt │ ├── ans-loc-pthread.txt │ ├── ans-loc-seq.txt │ ├── criterion-inst-pthread.txt │ ├── criterion-inst-seq.txt │ ├── criterion-loc-pthread.txt │ ├── criterion-loc-seq.txt │ ├── map_reduce.h │ ├── pca-pthread.c │ ├── pca-seq.c │ └── stddefines.h └── word_count │ ├── Makefile │ ├── README.md │ ├── map_reduce.h │ ├── sort-pthread.c │ ├── sort-pthread.h │ ├── stddefines.h │ ├── word_count-pthread.c │ └── word_count-seq.c ├── tools ├── Makefile ├── PrintTrace │ ├── Makefile │ └── PrintTrace.cpp └── Tracer │ ├── Makefile │ └── Tracer.cpp └── utils ├── build.sh └── install_llvm.sh /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | *.o 3 | *.a 4 | *.so 5 | *.swp 6 | *.ll 7 | *.bc 8 | *.s 9 | *.trace 10 | *.slice 11 | *.exe 12 | *ycm_extra_conf.py* 13 | cscope.* 14 | autom4te.cache 15 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | 3 | compiler: gcc 4 | 5 | os: linux 6 | 7 | env: LLVM_HOME=$HOME/llvm BuildMode=Release+Asserts TEST_PARALLELISM=seq TEST_LOG=test.log 8 | 9 | before_script: 10 | - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test 11 | - sudo apt-get update -qq 12 | - sudo apt-get install -qq gcc-4.8 g++-4.8 13 | - sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 90 14 | 15 | script: 16 | - sudo -E utils/install_llvm.sh 17 | - export PATH=/usr/local/bin:$PATH 18 | - utils/build.sh 19 | 20 | cache: 21 | directories: 22 | - $HOME/llvm 23 | 24 | notifications: 25 | recipients: 26 | - liuml07+update@gmail.com 27 | email: 28 | on_success: change 29 | on_failure: always 30 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu 2 | 3 | MAINTAINER Mingliang Liu 4 | 5 | ENV LLVM_HOME /usr/local/llvm 6 | ENV BuildMode Release+Asserts 7 | ENV TEST_PARALLELISM seq 8 | 9 | RUN apt-get update 10 | RUN apt-get upgrade -y 11 | RUN apt-get install -qq -y wget make g++ python zip unzip autoconf libtool automake 12 | 13 | ADD . giri 14 | 15 | RUN giri/utils/install_llvm.sh 3.4 16 | 17 | RUN cd giri/ && utils/build.sh 18 | -------------------------------------------------------------------------------- /LICENSE.TXT: -------------------------------------------------------------------------------- 1 | ============================================================================== 2 | LLVM Release License 3 | ============================================================================== 4 | University of Illinois/NCSA 5 | Open Source License 6 | 7 | Copyright (c) 2003-2013 University of Illinois at Urbana-Champaign. 8 | All rights reserved. 9 | 10 | Developed by: 11 | 12 | LLVM Team 13 | 14 | University of Illinois at Urbana-Champaign 15 | 16 | http://llvm.org 17 | 18 | Permission is hereby granted, free of charge, to any person obtaining a copy of 19 | this software and associated documentation files (the "Software"), to deal with 20 | the Software without restriction, including without limitation the rights to 21 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 22 | of the Software, and to permit persons to whom the Software is furnished to do 23 | so, subject to the following conditions: 24 | 25 | * Redistributions of source code must retain the above copyright notice, 26 | this list of conditions and the following disclaimers. 27 | 28 | * Redistributions in binary form must reproduce the above copyright notice, 29 | this list of conditions and the following disclaimers in the 30 | documentation and/or other materials provided with the distribution. 31 | 32 | * Neither the names of the LLVM Team, University of Illinois at 33 | Urbana-Champaign, nor the names of its contributors may be used to 34 | endorse or promote products derived from this Software without specific 35 | prior written permission. 36 | 37 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 38 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 39 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 40 | CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 41 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 42 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE 43 | SOFTWARE. 44 | 45 | ============================================================================== 46 | Copyrights and Licenses for Third Party Software Distributed with LLVM: 47 | ============================================================================== 48 | The LLVM software contains code written by third parties. Such software will 49 | have its own individual LICENSE.TXT file in the directory in which it appears. 50 | This file will describe the copyrights, license, and restrictions which apply 51 | to that code. 52 | 53 | The disclaimer of warranty in the University of Illinois Open Source License 54 | applies to all code in the LLVM Distribution, and nothing in any of the 55 | other licenses gives permission to use the names of the LLVM Team or the 56 | University of Illinois to endorse or promote products derived from this 57 | Software. 58 | 59 | The following pieces of software have additional or alternate copyrights, 60 | licenses, and/or restrictions: 61 | 62 | Program Directory 63 | ------- --------- 64 | Autoconf giri/autoconf 65 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/Makefile ----------------------------*- Makefile -*-===## 2 | # 3 | # This is the top Makefile for Giri project, dynamic slicing in LLVM 4 | # 5 | ##===-----------------------------------------------------------===## 6 | 7 | # 8 | # Indicates our relative path to the top of the project's root directory. 9 | # 10 | LEVEL = . 11 | DIRS = lib tools runtime 12 | EXTRA_DIST = include 13 | 14 | # 15 | # Include the Master Makefile that knows how to build all. 16 | # 17 | include $(LEVEL)/Makefile.common 18 | 19 | -------------------------------------------------------------------------------- /Makefile.common.in: -------------------------------------------------------------------------------- 1 | # Set the name of the project here 2 | PROJECT_NAME := Giri 3 | PROJ_VERSION := 3.4 4 | 5 | # Set this variable to the top of the LLVM source tree. 6 | LLVM_SRC_ROOT = @LLVM_SRC@ 7 | 8 | # Set this variable to the top level directory where LLVM was built 9 | # (this is *not* the same as OBJ_ROOT as defined in LLVM's Makefile.config). 10 | LLVM_OBJ_ROOT = @LLVM_OBJ@ 11 | 12 | # Set the directory root of this project's source files 13 | PROJ_SRC_ROOT := $(subst //,/,@abs_top_srcdir@) 14 | 15 | # Set the root directory of this project's object files 16 | PROJ_OBJ_ROOT := $(subst //,/,@abs_top_builddir@) 17 | 18 | # Set the root directory of this project's install prefix 19 | PROJ_INSTALL_ROOT := @prefix@ 20 | 21 | # Configuration file to set paths specific to local installation of LLVM 22 | include $(PROJ_OBJ_ROOT)/Makefile.llvm.config 23 | 24 | # Include all of the build rules used for making LLVM 25 | include $(PROJ_SRC_ROOT)/Makefile.llvm.rules 26 | 27 | CFLAGS += -Wno-deprecated 28 | CXXFLAGS += -Wno-deprecated 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Giri: Dynamic Program Slicing in LLVM 2 | 3 | _Dynamic program slicing_ is a technique that can precisely determine which instructions affected a **particular value** in a single **execution** of a program. Giri implements dynamic backwards slicing in LLVM compiler. 4 | 5 | [![License](https://img.shields.io/badge/license-LLVM-brightgreen.svg)](LICENSE.TXT) 6 | [![Build Status](https://travis-ci.org/liuml07/giri.svg?branch=master)](https://travis-ci.org/liuml07/giri) 7 | [![Current Release](https://img.shields.io/badge/release-3.4-blue.svg)](../../releases/tag/v3.4) 8 | 9 | ### Install 10 | 11 | * Simply use the prebuilt [Docker image](https://registry.hub.docker.com/u/liuml07/giri/): `docker pull liuml07/giri` 12 | * Or, you can [compile Giri](https://github.com/liuml07/giri/wiki/How-to-Compile-Giri) by yourself 13 | 14 | ### Usage 15 | 1. [Hello World!](https://github.com/liuml07/giri/wiki/Hello-World!) 16 | 2. [Example Usage](https://github.com/liuml07/giri/wiki/Example-Usage) 17 | 18 | Please see our [wiki page](https://github.com/liuml07/giri/wiki/) for more information. 19 | 20 | ### Credit 21 | 22 | This project was first developed by [Swarup Kumar Sahoo](http://web.engr.illinois.edu/~ssahoo2/), [John Criswell](http://www.bigw.org/~jcriswel), and [Dr. Vikram S. Adve](http://llvm.cs.uiuc.edu/~vadve/) from UIUC. It was selected by the Google Summer of Code **(GSoC)** 2013, under its umbrella project LLVM. [Mingliang Liu](http://pacman.cs.tsinghua.edu.cn/~liuml07) from Tsinghua University joined to improve Giri in June, 2013. It's an ongoing project and pull requests are heavily appreciated. 23 | 24 | If you use Giri in your research project, please cite our work. 25 | 26 | [1] Swarup Kumar Sahoo, John Criswell, Chase Geigle, and Vikram Adve. *Using Likely Invariants for Automated Software Fault Localization*. 27 | In Proceedings of the 18th International Conference on Architectural Support for Programming Languages and Operating Systems, **ASPLOS**'13, New York, USA, 2013. ACM. 28 | -------------------------------------------------------------------------------- /autoconf/AutoRegen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | die () { 3 | echo "$@" 1>&2 4 | exit 1 5 | } 6 | test -d autoconf && test -f autoconf/configure.ac && cd autoconf 7 | test -f configure.ac || die "Can't find 'autoconf' dir; please cd into it first" 8 | autoconf --version | egrep '2\.[56][0-9]' > /dev/null 9 | if test $? -ne 0 ; then 10 | die "Your autoconf was not detected as being 2.5x or 2.6x" 11 | fi 12 | cwd=`pwd` 13 | if test -d ../../../autoconf/m4 ; then 14 | cd ../../../autoconf/m4 15 | llvm_src_root=../.. 16 | llvm_obj_root=../.. 17 | cd $cwd 18 | elif test -d ../../llvm/autoconf/m4 ; then 19 | cd ../../llvm/autoconf/m4 20 | llvm_src_root=../.. 21 | llvm_obj_root=../.. 22 | cd $cwd 23 | else 24 | while true ; do 25 | echo "LLVM source root not found." 26 | read -p "Enter full path to LLVM source:" REPLY 27 | if test -d "$REPLY/autoconf/m4" ; then 28 | llvm_src_root="$REPLY" 29 | read -p "Enter full path to LLVM objects (empty for same as source):" REPLY 30 | if test -d "$REPLY" ; then 31 | llvm_obj_root="$REPLY" 32 | else 33 | llvm_obj_root="$llvm_src_root" 34 | fi 35 | break 36 | fi 37 | done 38 | fi 39 | echo "Regenerating aclocal.m4 with aclocal" 40 | rm -f aclocal.m4 41 | aclocal -I $cwd/m4 || die "aclocal failed" 42 | echo "Regenerating configure with autoconf" 43 | autoconf --warnings=all -o ../configure configure.ac || die "autoconf failed" 44 | cd .. 45 | exit 0 46 | -------------------------------------------------------------------------------- /autoconf/ExportMap.map: -------------------------------------------------------------------------------- 1 | { 2 | global: main; 3 | __progname; 4 | environ; 5 | 6 | local: *; 7 | }; 8 | -------------------------------------------------------------------------------- /autoconf/LICENSE.TXT: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------ 2 | Autoconf Files 3 | ------------------------------------------------------------------------------ 4 | All autoconf files are licensed under the LLVM license with the following 5 | additions: 6 | 7 | llvm/autoconf/install-sh: 8 | This script is licensed under the LLVM license, with the following 9 | additional copyrights and restrictions: 10 | 11 | Copyright 1991 by the Massachusetts Institute of Technology 12 | 13 | Permission to use, copy, modify, distribute, and sell this software and its 14 | documentation for any purpose is hereby granted without fee, provided that 15 | the above copyright notice appear in all copies and that both that 16 | copyright notice and this permission notice appear in supporting 17 | documentation, and that the name of M.I.T. not be used in advertising or 18 | publicity pertaining to distribution of the software without specific, 19 | written prior permission. M.I.T. makes no representations about the 20 | suitability of this software for any purpose. It is provided "as is" 21 | without express or implied warranty. 22 | 23 | Please see the source files for additional copyrights. 24 | 25 | -------------------------------------------------------------------------------- /autoconf/m4/build_exeext.m4: -------------------------------------------------------------------------------- 1 | # Check for the extension used for executables on build platform. 2 | # This is necessary for cross-compiling where the build platform 3 | # may differ from the host platform. 4 | AC_DEFUN([AC_BUILD_EXEEXT], 5 | [ 6 | AC_MSG_CHECKING([for executable suffix on build platform]) 7 | AC_CACHE_VAL(ac_cv_build_exeext, 8 | [if test "$CYGWIN" = yes || test "$MINGW32" = yes; then 9 | ac_cv_build_exeext=.exe 10 | else 11 | ac_build_prefix=${build_alias}- 12 | 13 | AC_CHECK_PROG(BUILD_CC, ${ac_build_prefix}gcc, ${ac_build_prefix}gcc) 14 | if test -z "$BUILD_CC"; then 15 | AC_CHECK_PROG(BUILD_CC, gcc, gcc) 16 | if test -z "$BUILD_CC"; then 17 | AC_CHECK_PROG(BUILD_CC, cc, cc, , , /usr/ucb/cc) 18 | fi 19 | fi 20 | test -z "$BUILD_CC" && AC_MSG_ERROR([no acceptable cc found in \$PATH]) 21 | ac_build_link='${BUILD_CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&AS_MESSAGE_LOG_FD' 22 | rm -f conftest* 23 | echo 'int main () { return 0; }' > conftest.$ac_ext 24 | ac_cv_build_exeext= 25 | if AC_TRY_EVAL(ac_build_link); then 26 | for file in conftest.*; do 27 | case $file in 28 | *.c | *.o | *.obj | *.dSYM) ;; 29 | *) ac_cv_build_exeext=`echo $file | sed -e s/conftest//` ;; 30 | esac 31 | done 32 | else 33 | AC_MSG_ERROR([installation or configuration problem: compiler cannot create executables.]) 34 | fi 35 | rm -f conftest* 36 | test x"${ac_cv_build_exeext}" = x && ac_cv_build_exeext=blank 37 | fi]) 38 | BUILD_EXEEXT="" 39 | test x"${ac_cv_build_exeext}" != xblank && BUILD_EXEEXT=${ac_cv_build_exeext} 40 | AC_MSG_RESULT(${ac_cv_build_exeext}) 41 | ac_build_exeext=$BUILD_EXEEXT 42 | AC_SUBST(BUILD_EXEEXT)]) 43 | -------------------------------------------------------------------------------- /autoconf/m4/c_printf_a.m4: -------------------------------------------------------------------------------- 1 | # 2 | # Determine if the printf() functions have the %a format character. 3 | # This is modified from: 4 | # http://www.gnu.org/software/ac-archive/htmldoc/ac_cxx_have_ext_slist.html 5 | AC_DEFUN([AC_C_PRINTF_A], 6 | [AC_CACHE_CHECK([if printf has the %a format character],[llvm_cv_c_printf_a], 7 | [AC_LANG_PUSH([C]) 8 | AC_RUN_IFELSE([ 9 | AC_LANG_PROGRAM([[ 10 | #include 11 | #include 12 | ]],[[ 13 | volatile double A, B; 14 | char Buffer[100]; 15 | A = 1; 16 | A /= 10.0; 17 | sprintf(Buffer, "%a", A); 18 | B = atof(Buffer); 19 | if (A != B) 20 | return (1); 21 | if (A != 0x1.999999999999ap-4) 22 | return (1); 23 | return (0);]])], 24 | llvm_cv_c_printf_a=yes, 25 | llvmac_cv_c_printf_a=no, 26 | llvmac_cv_c_printf_a=no) 27 | AC_LANG_POP([C])]) 28 | if test "$llvm_cv_c_printf_a" = "yes"; then 29 | AC_DEFINE([HAVE_PRINTF_A],[1],[Define to have the %a format string]) 30 | fi 31 | ]) 32 | -------------------------------------------------------------------------------- /autoconf/m4/check_gnu_make.m4: -------------------------------------------------------------------------------- 1 | # 2 | # Check for GNU Make. This is originally from 3 | # http://www.gnu.org/software/ac-archive/htmldoc/check_gnu_make.html 4 | # 5 | AC_DEFUN([AC_CHECK_GNU_MAKE], 6 | [AC_CACHE_CHECK([for GNU make],[llvm_cv_gnu_make_command], 7 | dnl Search all the common names for GNU make 8 | [llvm_cv_gnu_make_command='' 9 | for a in "$MAKE" make gmake gnumake ; do 10 | if test -z "$a" ; then continue ; fi ; 11 | if ( sh -c "$a --version" 2> /dev/null | grep GNU 2>&1 > /dev/null ) 12 | then 13 | llvm_cv_gnu_make_command=$a ; 14 | break; 15 | fi 16 | done]) 17 | dnl If there was a GNU version, then set @ifGNUmake@ to the empty string, 18 | dnl '#' otherwise 19 | if test "x$llvm_cv_gnu_make_command" != "x" ; then 20 | ifGNUmake='' ; 21 | else 22 | ifGNUmake='#' ; 23 | AC_MSG_RESULT("Not found"); 24 | fi 25 | AC_SUBST(ifGNUmake) 26 | ]) 27 | -------------------------------------------------------------------------------- /autoconf/m4/config_makefile.m4: -------------------------------------------------------------------------------- 1 | # 2 | # Configure a Makefile without clobbering it if it exists and is not out of 3 | # date. This macro is unique to LLVM. 4 | # 5 | AC_DEFUN([AC_CONFIG_MAKEFILE], 6 | [AC_CONFIG_COMMANDS($1, 7 | [${llvm_src}/autoconf/mkinstalldirs `dirname $1` 8 | ${SHELL} ${llvm_src}/autoconf/install-sh -m 0644 -c ${srcdir}/$1 $1]) 9 | ]) 10 | -------------------------------------------------------------------------------- /autoconf/m4/config_project.m4: -------------------------------------------------------------------------------- 1 | # 2 | # Provide the arguments and other processing needed for an LLVM project 3 | # 4 | AC_DEFUN([LLVM_CONFIG_PROJECT], 5 | [AC_ARG_WITH([llvmsrc], 6 | AS_HELP_STRING([--with-llvmsrc],[Location of LLVM Source Code]), 7 | [llvm_src="$withval"],[llvm_src="]$1["]) 8 | AC_SUBST(LLVM_SRC,$llvm_src) 9 | AC_ARG_WITH([llvmobj], 10 | AS_HELP_STRING([--with-llvmobj],[Location of LLVM Object Code]), 11 | [llvm_obj="$withval"],[llvm_obj="]$2["]) 12 | AC_SUBST(LLVM_OBJ,$llvm_obj) 13 | AC_CONFIG_COMMANDS([setup],,[llvm_src="${LLVM_SRC}"]) 14 | ]) 15 | -------------------------------------------------------------------------------- /autoconf/m4/cxx_flag_check.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([CXX_FLAG_CHECK], 2 | [AC_SUBST($1, `$CXX -Werror $2 -fsyntax-only -xc /dev/null 2>/dev/null && echo $2`)]) 3 | -------------------------------------------------------------------------------- /autoconf/m4/find_std_program.m4: -------------------------------------------------------------------------------- 1 | dnl Check for a standard program that has a bin, include and lib directory 2 | dnl 3 | dnl Parameters: 4 | dnl $1 - prefix directory to check 5 | dnl $2 - program name to check 6 | dnl $3 - header file to check 7 | dnl $4 - library file to check 8 | AC_DEFUN([CHECK_STD_PROGRAM], 9 | [m4_define([allcapsname],translit($2,a-z,A-Z)) 10 | if test -n "$1" -a -d "$1" -a -n "$2" -a -d "$1/bin" -a -x "$1/bin/$2" ; then 11 | AC_SUBST([USE_]allcapsname(),["USE_]allcapsname()[ = 1"]) 12 | AC_SUBST(allcapsname(),[$1/bin/$2]) 13 | AC_SUBST(allcapsname()[_BIN],[$1/bin]) 14 | AC_SUBST(allcapsname()[_DIR],[$1]) 15 | if test -n "$3" -a -d "$1/include" -a -f "$1/include/$3" ; then 16 | AC_SUBST(allcapsname()[_INC],[$1/include]) 17 | fi 18 | if test -n "$4" -a -d "$1/lib" -a -f "$1/lib/$4" ; then 19 | AC_SUBST(allcapsname()[_LIB],[$1/lib]) 20 | fi 21 | fi 22 | ]) 23 | 24 | dnl Find a program via --with options, in the path, or well known places 25 | dnl 26 | dnl Parameters: 27 | dnl $1 - program's executable name 28 | dnl $2 - header file name to check (optional) 29 | dnl $3 - library file name to check (optional) 30 | dnl $4 - alternate (long) name for the program 31 | AC_DEFUN([FIND_STD_PROGRAM], 32 | [m4_define([allcapsname],translit($1,a-z,A-Z)) 33 | m4_define([stdprog_long_name],ifelse($4,,translit($1,[ !@#$%^&*()-+={}[]:;"',./?],[-]),translit($4,[ !@#$%^&*()-+={}[]:;"',./?],[-]))) 34 | AC_MSG_CHECKING([for ]stdprog_long_name()[ bin/lib/include locations]) 35 | AC_ARG_WITH($1, 36 | AS_HELP_STRING([--with-]stdprog_long_name()[=DIR], 37 | [Specify that the ]stdprog_long_name()[ install prefix is DIR]), 38 | $1[pfxdir=$withval],$1[pfxdir=nada]) 39 | AC_ARG_WITH($1[-bin], 40 | AS_HELP_STRING([--with-]stdprog_long_name()[-bin=DIR], 41 | [Specify that the ]stdprog_long_name()[ binary is in DIR]), 42 | $1[bindir=$withval],$1[bindir=nada]) 43 | AC_ARG_WITH($1[-lib], 44 | AS_HELP_STRING([--with-]stdprog_long_name()[-lib=DIR], 45 | [Specify that ]stdprog_long_name()[ libraries are in DIR]), 46 | $1[libdir=$withval],$1[libdir=nada]) 47 | AC_ARG_WITH($1[-inc], 48 | AS_HELP_STRING([--with-]stdprog_long_name()[-inc=DIR], 49 | [Specify that the ]stdprog_long_name()[ includes are in DIR]), 50 | $1[incdir=$withval],$1[incdir=nada]) 51 | eval pfxval=\$\{$1pfxdir\} 52 | eval binval=\$\{$1bindir\} 53 | eval incval=\$\{$1incdir\} 54 | eval libval=\$\{$1libdir\} 55 | if test "${pfxval}" != "nada" ; then 56 | CHECK_STD_PROGRAM(${pfxval},$1,$2,$3) 57 | elif test "${binval}" != "nada" ; then 58 | if test "${libval}" != "nada" ; then 59 | if test "${incval}" != "nada" ; then 60 | if test -d "${binval}" ; then 61 | if test -d "${incval}" ; then 62 | if test -d "${libval}" ; then 63 | AC_SUBST(allcapsname(),${binval}/$1) 64 | AC_SUBST(allcapsname()[_BIN],${binval}) 65 | AC_SUBST(allcapsname()[_INC],${incval}) 66 | AC_SUBST(allcapsname()[_LIB],${libval}) 67 | AC_SUBST([USE_]allcapsname(),["USE_]allcapsname()[ = 1"]) 68 | AC_MSG_RESULT([found via --with options]) 69 | else 70 | AC_MSG_RESULT([failed]) 71 | AC_MSG_ERROR([The --with-]$1[-libdir value must be a directory]) 72 | fi 73 | else 74 | AC_MSG_RESULT([failed]) 75 | AC_MSG_ERROR([The --with-]$1[-incdir value must be a directory]) 76 | fi 77 | else 78 | AC_MSG_RESULT([failed]) 79 | AC_MSG_ERROR([The --with-]$1[-bindir value must be a directory]) 80 | fi 81 | else 82 | AC_MSG_RESULT([failed]) 83 | AC_MSG_ERROR([The --with-]$1[-incdir option must be specified]) 84 | fi 85 | else 86 | AC_MSG_RESULT([failed]) 87 | AC_MSG_ERROR([The --with-]$1[-libdir option must be specified]) 88 | fi 89 | else 90 | tmppfxdir=`which $1 2>&1` 91 | if test -n "$tmppfxdir" -a -d "${tmppfxdir%*$1}" -a \ 92 | -d "${tmppfxdir%*$1}/.." ; then 93 | tmppfxdir=`cd "${tmppfxdir%*$1}/.." ; pwd` 94 | CHECK_STD_PROGRAM($tmppfxdir,$1,$2,$3) 95 | AC_MSG_RESULT([found in PATH at ]$tmppfxdir) 96 | else 97 | checkresult="yes" 98 | eval checkval=\$\{"USE_"allcapsname()\} 99 | CHECK_STD_PROGRAM([/usr],$1,$2,$3) 100 | if test -z "${checkval}" ; then 101 | CHECK_STD_PROGRAM([/usr/local],$1,$2,$3) 102 | if test -z "${checkval}" ; then 103 | CHECK_STD_PROGRAM([/sw],$1,$2,$3) 104 | if test -z "${checkval}" ; then 105 | CHECK_STD_PROGRAM([/opt],$1,$2,$3) 106 | if test -z "${checkval}" ; then 107 | CHECK_STD_PROGRAM([/],$1,$2,$3) 108 | if test -z "${checkval}" ; then 109 | checkresult="no" 110 | fi 111 | fi 112 | fi 113 | fi 114 | fi 115 | AC_MSG_RESULT($checkresult) 116 | fi 117 | fi 118 | ]) 119 | -------------------------------------------------------------------------------- /autoconf/m4/func_isinf.m4: -------------------------------------------------------------------------------- 1 | # 2 | # This function determins if the isinf function isavailable on this 3 | # platform. 4 | # 5 | AC_DEFUN([AC_FUNC_ISINF],[ 6 | AC_SINGLE_CXX_CHECK([ac_cv_func_isinf_in_math_h], 7 | [isinf], [], 8 | [float f; isinf(f);]) 9 | if test "$ac_cv_func_isinf_in_math_h" = "yes" ; then 10 | AC_DEFINE([HAVE_ISINF_IN_MATH_H],1,[Set to 1 if the isinf function is found in ]) 11 | fi 12 | 13 | AC_SINGLE_CXX_CHECK([ac_cv_func_isinf_in_cmath], 14 | [isinf], [], 15 | [float f; isinf(f);]) 16 | if test "$ac_cv_func_isinf_in_cmath" = "yes" ; then 17 | AC_DEFINE([HAVE_ISINF_IN_CMATH],1,[Set to 1 if the isinf function is found in ]) 18 | fi 19 | 20 | AC_SINGLE_CXX_CHECK([ac_cv_func_std_isinf_in_cmath], 21 | [std::isinf], [], 22 | [float f; std::isinf(f);]) 23 | if test "$ac_cv_func_std_isinf_in_cmath" = "yes" ; then 24 | AC_DEFINE([HAVE_STD_ISINF_IN_CMATH],1,[Set to 1 if the std::isinf function is found in ]) 25 | fi 26 | 27 | AC_SINGLE_CXX_CHECK([ac_cv_func_finite_in_ieeefp_h], 28 | [finite], [], 29 | [float f; finite(f);]) 30 | if test "$ac_cv_func_finite_in_ieeefp_h" = "yes" ; then 31 | AC_DEFINE([HAVE_FINITE_IN_IEEEFP_H],1,[Set to 1 if the finite function is found in ]) 32 | fi 33 | 34 | ]) 35 | 36 | 37 | -------------------------------------------------------------------------------- /autoconf/m4/func_isnan.m4: -------------------------------------------------------------------------------- 1 | # 2 | # This function determines if the isnan function is available on this 3 | # platform. 4 | # 5 | AC_DEFUN([AC_FUNC_ISNAN],[ 6 | AC_SINGLE_CXX_CHECK([ac_cv_func_isnan_in_math_h], 7 | [isnan], [], 8 | [float f; isnan(f);]) 9 | 10 | if test "$ac_cv_func_isnan_in_math_h" = "yes" ; then 11 | AC_DEFINE([HAVE_ISNAN_IN_MATH_H],1,[Set to 1 if the isnan function is found in ]) 12 | fi 13 | 14 | AC_SINGLE_CXX_CHECK([ac_cv_func_isnan_in_cmath], 15 | [isnan], [], 16 | [float f; isnan(f);]) 17 | if test "$ac_cv_func_isnan_in_cmath" = "yes" ; then 18 | AC_DEFINE([HAVE_ISNAN_IN_CMATH],1,[Set to 1 if the isnan function is found in ]) 19 | fi 20 | 21 | AC_SINGLE_CXX_CHECK([ac_cv_func_std_isnan_in_cmath], 22 | [std::isnan], [], 23 | [float f; std::isnan(f);]) 24 | if test "$ac_cv_func_std_isnan_in_cmath" = "yes" ; then 25 | AC_DEFINE([HAVE_STD_ISNAN_IN_CMATH],1,[Set to 1 if the std::isnan function is found in ]) 26 | fi 27 | ]) 28 | -------------------------------------------------------------------------------- /autoconf/m4/func_mmap_file.m4: -------------------------------------------------------------------------------- 1 | # 2 | # Check for the ability to mmap a file. 3 | # 4 | AC_DEFUN([AC_FUNC_MMAP_FILE], 5 | [AC_CACHE_CHECK(for mmap of files, 6 | ac_cv_func_mmap_file, 7 | [ AC_LANG_PUSH([C]) 8 | AC_RUN_IFELSE([ 9 | AC_LANG_PROGRAM([[ 10 | #include 11 | #include 12 | #include 13 | ]],[[ 14 | int fd; 15 | fd = creat ("foo",0777); 16 | fd = (int) mmap (0, 1, PROT_READ, MAP_SHARED, fd, 0); 17 | unlink ("foo"); 18 | return (fd != (int) MAP_FAILED);]])], 19 | [ac_cv_func_mmap_file=yes],[ac_cv_func_mmap_file=no],[ac_cv_func_mmap_file=no]) 20 | AC_LANG_POP([C]) 21 | ]) 22 | if test "$ac_cv_func_mmap_file" = yes; then 23 | AC_DEFINE([HAVE_MMAP_FILE],[],[Define if mmap() can map files into memory]) 24 | AC_SUBST(MMAP_FILE,[yes]) 25 | fi 26 | ]) 27 | -------------------------------------------------------------------------------- /autoconf/m4/header_mmap_anonymous.m4: -------------------------------------------------------------------------------- 1 | # 2 | # Check for anonymous mmap macros. This is modified from 3 | # http://www.gnu.org/software/ac-archive/htmldoc/ac_cxx_have_ext_slist.html 4 | # 5 | AC_DEFUN([AC_HEADER_MMAP_ANONYMOUS], 6 | [AC_CACHE_CHECK(for MAP_ANONYMOUS vs. MAP_ANON, 7 | ac_cv_header_mmap_anon, 8 | [ AC_LANG_PUSH([C]) 9 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM( 10 | [[#include 11 | #include 12 | #include ]], 13 | [[mmap (0, 1, PROT_READ, MAP_ANONYMOUS, -1, 0); return (0);]])], 14 | ac_cv_header_mmap_anon=yes, 15 | ac_cv_header_mmap_anon=no) 16 | AC_LANG_POP([C]) 17 | ]) 18 | if test "$ac_cv_header_mmap_anon" = yes; then 19 | AC_DEFINE([HAVE_MMAP_ANONYMOUS],[1],[Define if mmap() uses MAP_ANONYMOUS to map anonymous pages, or undefine if it uses MAP_ANON]) 20 | fi 21 | ]) 22 | -------------------------------------------------------------------------------- /autoconf/m4/huge_val.m4: -------------------------------------------------------------------------------- 1 | # 2 | # This function determins if the HUGE_VAL macro is compilable with the 3 | # -pedantic switch or not. XCode < 2.4.1 doesn't get it right. 4 | # 5 | AC_DEFUN([AC_HUGE_VAL_CHECK],[ 6 | AC_CACHE_CHECK([for HUGE_VAL sanity], [ac_cv_huge_val_sanity],[ 7 | AC_LANG_PUSH([C++]) 8 | ac_save_CXXFLAGS=$CXXFLAGS 9 | CXXFLAGS="$CXXFLAGS -pedantic" 10 | AC_RUN_IFELSE( 11 | AC_LANG_PROGRAM( 12 | [#include ], 13 | [double x = HUGE_VAL; return x != x; ]), 14 | [ac_cv_huge_val_sanity=yes],[ac_cv_huge_val_sanity=no], 15 | [ac_cv_huge_val_sanity=yes]) 16 | CXXFLAGS=$ac_save_CXXFLAGS 17 | AC_LANG_POP([C++]) 18 | ]) 19 | AC_SUBST(HUGE_VAL_SANITY,$ac_cv_huge_val_sanity) 20 | ]) 21 | -------------------------------------------------------------------------------- /autoconf/m4/link_options.m4: -------------------------------------------------------------------------------- 1 | # 2 | # Get the linker version string. 3 | # 4 | # This macro is specific to LLVM. 5 | # 6 | AC_DEFUN([AC_LINK_GET_VERSION], 7 | [AC_CACHE_CHECK([for linker version],[llvm_cv_link_version], 8 | [ 9 | version_string="$(ld -v 2>&1 | head -1)" 10 | 11 | # Check for ld64. 12 | if (echo "$version_string" | grep -q "ld64"); then 13 | llvm_cv_link_version=$(echo "$version_string" | sed -e "s#.*ld64-\([^ ]*\)\( (.*)\)\{0,1\}#\1#") 14 | else 15 | llvm_cv_link_version=$(echo "$version_string" | sed -e "s#[^0-9]*\([0-9.]*\).*#\1#") 16 | fi 17 | ]) 18 | AC_DEFINE_UNQUOTED([HOST_LINK_VERSION],"$llvm_cv_link_version", 19 | [Linker version detected at compile time.]) 20 | ]) 21 | 22 | # 23 | # Determine if the system can handle the -R option being passed to the linker. 24 | # 25 | # This macro is specific to LLVM. 26 | # 27 | AC_DEFUN([AC_LINK_USE_R], 28 | [AC_CACHE_CHECK([for compiler -Wl,-R option],[llvm_cv_link_use_r], 29 | [ AC_LANG_PUSH([C]) 30 | oldcflags="$CFLAGS" 31 | CFLAGS="$CFLAGS -Wl,-R." 32 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])], 33 | [llvm_cv_link_use_r=yes],[llvm_cv_link_use_r=no]) 34 | CFLAGS="$oldcflags" 35 | AC_LANG_POP([C]) 36 | ]) 37 | if test "$llvm_cv_link_use_r" = yes ; then 38 | AC_DEFINE([HAVE_LINK_R],[1],[Define if you can use -Wl,-R. to pass -R. to the linker, in order to add the current directory to the dynamic linker search path.]) 39 | fi 40 | ]) 41 | 42 | # 43 | # Determine if the system can handle the -R option being passed to the linker. 44 | # 45 | # This macro is specific to LLVM. 46 | # 47 | AC_DEFUN([AC_LINK_EXPORT_DYNAMIC], 48 | [AC_CACHE_CHECK([for compiler -Wl,-export-dynamic option], 49 | [llvm_cv_link_use_export_dynamic], 50 | [ AC_LANG_PUSH([C]) 51 | oldcflags="$CFLAGS" 52 | CFLAGS="$CFLAGS -Wl,-export-dynamic" 53 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])], 54 | [llvm_cv_link_use_export_dynamic=yes],[llvm_cv_link_use_export_dynamic=no]) 55 | CFLAGS="$oldcflags" 56 | AC_LANG_POP([C]) 57 | ]) 58 | if test "$llvm_cv_link_use_export_dynamic" = yes ; then 59 | AC_DEFINE([HAVE_LINK_EXPORT_DYNAMIC],[1],[Define if you can use -Wl,-export-dynamic.]) 60 | fi 61 | ]) 62 | 63 | # 64 | # Determine if the system can handle the --version-script option being 65 | # passed to the linker. 66 | # 67 | # This macro is specific to LLVM. 68 | # 69 | AC_DEFUN([AC_LINK_VERSION_SCRIPT], 70 | [AC_CACHE_CHECK([for compiler -Wl,--version-script option], 71 | [llvm_cv_link_use_version_script], 72 | [ AC_LANG_PUSH([C]) 73 | oldcflags="$CFLAGS" 74 | 75 | # The following code is from the autoconf manual, 76 | # "11.13: Limitations of Usual Tools". 77 | # Create a temporary directory $tmp in $TMPDIR (default /tmp). 78 | # Use mktemp if possible; otherwise fall back on mkdir, 79 | # with $RANDOM to make collisions less likely. 80 | : ${TMPDIR=/tmp} 81 | { 82 | tmp=` 83 | (umask 077 && mktemp -d "$TMPDIR/fooXXXXXX") 2>/dev/null 84 | ` && 85 | test -n "$tmp" && test -d "$tmp" 86 | } || { 87 | tmp=$TMPDIR/foo$$-$RANDOM 88 | (umask 077 && mkdir "$tmp") 89 | } || exit $? 90 | 91 | echo "{" > "$tmp/export.map" 92 | echo " global: main;" >> "$tmp/export.map" 93 | echo " local: *;" >> "$tmp/export.map" 94 | echo "};" >> "$tmp/export.map" 95 | 96 | CFLAGS="$CFLAGS -Wl,--version-script=$tmp/export.map" 97 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])], 98 | [llvm_cv_link_use_version_script=yes],[llvm_cv_link_use_version_script=no]) 99 | rm "$tmp/export.map" 100 | rmdir "$tmp" 101 | CFLAGS="$oldcflags" 102 | AC_LANG_POP([C]) 103 | ]) 104 | if test "$llvm_cv_link_use_version_script" = yes ; then 105 | AC_SUBST(HAVE_LINK_VERSION_SCRIPT,1) 106 | fi 107 | ]) 108 | 109 | -------------------------------------------------------------------------------- /autoconf/m4/linux_mixed_64_32.m4: -------------------------------------------------------------------------------- 1 | # 2 | # Some Linux machines run a 64-bit kernel with a 32-bit userspace. 'uname -m' 3 | # shows these as x86_64. Ask the system 'gcc' what it thinks. 4 | # 5 | AC_DEFUN([AC_IS_LINUX_MIXED], 6 | [AC_CACHE_CHECK(for 32-bit userspace on 64-bit system,llvm_cv_linux_mixed, 7 | [ AC_LANG_PUSH([C]) 8 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM( 9 | [[#ifndef __x86_64__ 10 | error: Not x86-64 even if uname says so! 11 | #endif 12 | ]])], 13 | [llvm_cv_linux_mixed=no], 14 | [llvm_cv_linux_mixed=yes]) 15 | AC_LANG_POP([C]) 16 | ]) 17 | ]) 18 | -------------------------------------------------------------------------------- /autoconf/m4/need_dev_zero_for_mmap.m4: -------------------------------------------------------------------------------- 1 | # 2 | # When allocating RWX memory, check whether we need to use /dev/zero 3 | # as the file descriptor or not. 4 | # 5 | AC_DEFUN([AC_NEED_DEV_ZERO_FOR_MMAP], 6 | [AC_CACHE_CHECK([if /dev/zero is needed for mmap], 7 | ac_cv_need_dev_zero_for_mmap, 8 | [if test "$llvm_cv_os_type" = "Interix" ; then 9 | ac_cv_need_dev_zero_for_mmap=yes 10 | else 11 | ac_cv_need_dev_zero_for_mmap=no 12 | fi 13 | ]) 14 | if test "$ac_cv_need_dev_zero_for_mmap" = yes; then 15 | AC_DEFINE([NEED_DEV_ZERO_FOR_MMAP],[1], 16 | [Define if /dev/zero should be used when mapping RWX memory, or undefine if its not necessary]) 17 | fi]) 18 | -------------------------------------------------------------------------------- /autoconf/m4/path_tclsh.m4: -------------------------------------------------------------------------------- 1 | dnl This macro checks for tclsh which is required to run dejagnu. On some 2 | dnl platforms (notably FreeBSD), tclsh is named tclshX.Y - this handles 3 | dnl that for us so we can get the latest installed tclsh version. 4 | dnl 5 | AC_DEFUN([DJ_AC_PATH_TCLSH], [ 6 | no_itcl=true 7 | AC_MSG_CHECKING(for the tclsh program in tclinclude directory) 8 | AC_ARG_WITH(tclinclude, 9 | AS_HELP_STRING([--with-tclinclude], 10 | [directory where tcl headers are]), 11 | [with_tclinclude=${withval}],[with_tclinclude='']) 12 | AC_CACHE_VAL(ac_cv_path_tclsh,[ 13 | dnl first check to see if --with-itclinclude was specified 14 | if test x"${with_tclinclude}" != x ; then 15 | if test -f ${with_tclinclude}/tclsh ; then 16 | ac_cv_path_tclsh=`(cd ${with_tclinclude}; pwd)` 17 | elif test -f ${with_tclinclude}/src/tclsh ; then 18 | ac_cv_path_tclsh=`(cd ${with_tclinclude}/src; pwd)` 19 | else 20 | AC_MSG_ERROR([${with_tclinclude} directory doesn't contain tclsh]) 21 | fi 22 | fi]) 23 | 24 | dnl see if one is installed 25 | if test x"${ac_cv_path_tclsh}" = x ; then 26 | AC_MSG_RESULT(none) 27 | AC_PATH_PROGS([TCLSH],[tclsh8.4 tclsh8.4.8 tclsh8.4.7 tclsh8.4.6 tclsh8.4.5 tclsh8.4.4 tclsh8.4.3 tclsh8.4.2 tclsh8.4.1 tclsh8.4.0 tclsh8.3 tclsh8.3.5 tclsh8.3.4 tclsh8.3.3 tclsh8.3.2 tclsh8.3.1 tclsh8.3.0 tclsh]) 28 | if test x"${TCLSH}" = x ; then 29 | ac_cv_path_tclsh=''; 30 | else 31 | ac_cv_path_tclsh="${TCLSH}"; 32 | fi 33 | else 34 | AC_MSG_RESULT(${ac_cv_path_tclsh}) 35 | TCLSH="${ac_cv_path_tclsh}" 36 | AC_SUBST(TCLSH) 37 | fi 38 | ]) 39 | 40 | -------------------------------------------------------------------------------- /autoconf/m4/rand48.m4: -------------------------------------------------------------------------------- 1 | # 2 | # This function determins if the srand48,drand48,lrand48 functions are 3 | # available on this platform. 4 | # 5 | AC_DEFUN([AC_FUNC_RAND48],[ 6 | AC_SINGLE_CXX_CHECK([ac_cv_func_rand48], 7 | [srand48/lrand48/drand48], [], 8 | [srand48(0);lrand48();drand48();]) 9 | if test "$ac_cv_func_rand48" = "yes" ; then 10 | AC_DEFINE([HAVE_RAND48],1,[Define to 1 if srand48/lrand48/drand48 exist in ]) 11 | fi 12 | ]) 13 | -------------------------------------------------------------------------------- /autoconf/m4/sanity_check.m4: -------------------------------------------------------------------------------- 1 | dnl Check a program for version sanity. The test runs a program, passes it an 2 | dnl argument to make it print out some identification string, and filters that 3 | dnl output with a regular expression. If the output is non-empty, the program 4 | dnl passes the sanity check. 5 | dnl $1 - Name or full path of the program to run 6 | dnl $2 - Argument to pass to print out identification string 7 | dnl $3 - grep RE to match identification string 8 | dnl $4 - set to 1 to make errors only a warning 9 | AC_DEFUN([CHECK_PROGRAM_SANITY], 10 | [ 11 | AC_MSG_CHECKING([sanity for program ]$1) 12 | sanity="0" 13 | sanity_path=`which $1 2>/dev/null` 14 | if test "$?" -eq 0 -a -x "$sanity_path" ; then 15 | sanity=`$1 $2 2>&1 | grep "$3"` 16 | if test -z "$sanity" ; then 17 | AC_MSG_RESULT([no]) 18 | sanity="0" 19 | if test "$4" -eq 1 ; then 20 | AC_MSG_WARN([Program ]$1[ failed to pass sanity check.]) 21 | else 22 | AC_MSG_ERROR([Program ]$1[ failed to pass sanity check.]) 23 | fi 24 | else 25 | AC_MSG_RESULT([yes]) 26 | sanity="1" 27 | fi 28 | else 29 | AC_MSG_RESULT([not found]) 30 | fi 31 | ]) 32 | -------------------------------------------------------------------------------- /autoconf/m4/single_cxx_check.m4: -------------------------------------------------------------------------------- 1 | dnl AC_SINGLE_CXX_CHECK(CACHEVAR, FUNCTION, HEADER, PROGRAM) 2 | dnl $1, $2, $3, $4, 3 | dnl 4 | AC_DEFUN([AC_SINGLE_CXX_CHECK], 5 | [AC_CACHE_CHECK([for $2 in $3], [$1], 6 | [AC_LANG_PUSH([C++]) 7 | AC_COMPILE_IFELSE(AC_LANG_PROGRAM([#include $3],[$4]),[$1=yes],[$1=no]) 8 | AC_LANG_POP([C++])]) 9 | ]) 10 | 11 | -------------------------------------------------------------------------------- /autoconf/m4/visibility_inlines_hidden.m4: -------------------------------------------------------------------------------- 1 | # 2 | # Determine if the compiler accepts -fvisibility-inlines-hidden 3 | # 4 | # This macro is specific to LLVM. 5 | # 6 | AC_DEFUN([AC_CXX_USE_VISIBILITY_INLINES_HIDDEN], 7 | [AC_CACHE_CHECK([for compiler -fvisibility-inlines-hidden option], 8 | [llvm_cv_cxx_visibility_inlines_hidden], 9 | [ AC_LANG_PUSH([C++]) 10 | oldcxxflags="$CXXFLAGS" 11 | CXXFLAGS="$CXXFLAGS -O0 -fvisibility-inlines-hidden -Werror" 12 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM( 13 | [template struct X { void __attribute__((noinline)) f() {} };], 14 | [X().f();])], 15 | [llvm_cv_cxx_visibility_inlines_hidden=yes],[llvm_cv_cxx_visibility_inlines_hidden=no]) 16 | CXXFLAGS="$oldcxxflags" 17 | AC_LANG_POP([C++]) 18 | ]) 19 | if test "$llvm_cv_cxx_visibility_inlines_hidden" = yes ; then 20 | AC_SUBST([ENABLE_VISIBILITY_INLINES_HIDDEN],[1]) 21 | else 22 | AC_SUBST([ENABLE_VISIBILITY_INLINES_HIDDEN],[0]) 23 | fi 24 | ]) 25 | -------------------------------------------------------------------------------- /autoconf/mkinstalldirs: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # mkinstalldirs --- make directory hierarchy 3 | 4 | scriptversion=2004-02-15.20 5 | 6 | # Original author: Noah Friedman 7 | # Created: 1993-05-16 8 | # Public domain. 9 | # 10 | # This file is maintained in Automake, please report 11 | # bugs to or send patches to 12 | # . 13 | 14 | errstatus=0 15 | dirmode="" 16 | 17 | usage="\ 18 | Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ... 19 | 20 | Create each directory DIR (with mode MODE, if specified), including all 21 | leading file name components. 22 | 23 | Report bugs to ." 24 | 25 | # process command line arguments 26 | while test $# -gt 0 ; do 27 | case $1 in 28 | -h | --help | --h*) # -h for help 29 | echo "$usage" 30 | exit 0 31 | ;; 32 | -m) # -m PERM arg 33 | shift 34 | test $# -eq 0 && { echo "$usage" 1>&2; exit 1; } 35 | dirmode=$1 36 | shift 37 | ;; 38 | --version) 39 | echo "$0 $scriptversion" 40 | exit 0 41 | ;; 42 | --) # stop option processing 43 | shift 44 | break 45 | ;; 46 | -*) # unknown option 47 | echo "$usage" 1>&2 48 | exit 1 49 | ;; 50 | *) # first non-opt arg 51 | break 52 | ;; 53 | esac 54 | done 55 | 56 | for file 57 | do 58 | if test -d "$file"; then 59 | shift 60 | else 61 | break 62 | fi 63 | done 64 | 65 | case $# in 66 | 0) exit 0 ;; 67 | esac 68 | 69 | # Solaris 8's mkdir -p isn't thread-safe. If you mkdir -p a/b and 70 | # mkdir -p a/c at the same time, both will detect that a is missing, 71 | # one will create a, then the other will try to create a and die with 72 | # a "File exists" error. This is a problem when calling mkinstalldirs 73 | # from a parallel make. We use --version in the probe to restrict 74 | # ourselves to GNU mkdir, which is thread-safe. 75 | case $dirmode in 76 | '') 77 | if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then 78 | # echo "mkdir -p -- $*" 79 | exec mkdir -p -- "$@" 80 | else 81 | # On NextStep and OpenStep, the `mkdir' command does not 82 | # recognize any option. It will interpret all options as 83 | # directories to create, and then abort because `.' already 84 | # exists. 85 | test -d ./-p && rmdir ./-p 86 | test -d ./--version && rmdir ./--version 87 | fi 88 | ;; 89 | *) 90 | if mkdir -m "$dirmode" -p --version . >/dev/null 2>&1 && 91 | test ! -d ./--version; then 92 | # echo "mkdir -m $dirmode -p -- $*" 93 | exec mkdir -m "$dirmode" -p -- "$@" 94 | else 95 | # Clean up after NextStep and OpenStep mkdir. 96 | for d in ./-m ./-p ./--version "./$dirmode"; 97 | do 98 | test -d $d && rmdir $d 99 | done 100 | fi 101 | ;; 102 | esac 103 | 104 | for file 105 | do 106 | set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` 107 | shift 108 | 109 | pathcomp= 110 | for d 111 | do 112 | pathcomp="$pathcomp$d" 113 | case $pathcomp in 114 | -*) pathcomp=./$pathcomp ;; 115 | esac 116 | 117 | if test ! -d "$pathcomp"; then 118 | # echo "mkdir $pathcomp" 119 | 120 | mkdir "$pathcomp" || lasterr=$? 121 | 122 | if test ! -d "$pathcomp"; then 123 | errstatus=$lasterr 124 | else 125 | if test ! -z "$dirmode"; then 126 | # echo "chmod $dirmode $pathcomp" 127 | lasterr="" 128 | chmod "$dirmode" "$pathcomp" || lasterr=$? 129 | 130 | if test ! -z "$lasterr"; then 131 | errstatus=$lasterr 132 | fi 133 | fi 134 | fi 135 | fi 136 | 137 | pathcomp="$pathcomp/" 138 | done 139 | done 140 | 141 | exit $errstatus 142 | 143 | # Local Variables: 144 | # mode: shell-script 145 | # sh-indentation: 2 146 | # eval: (add-hook 'write-file-hooks 'time-stamp) 147 | # time-stamp-start: "scriptversion=" 148 | # time-stamp-format: "%:y-%02m-%02d.%02H" 149 | # time-stamp-end: "$" 150 | # End: 151 | -------------------------------------------------------------------------------- /docs/GSoC2013/proposal/Makefile: -------------------------------------------------------------------------------- 1 | # GNU/Linux Makefile for the slicing 2 | 3 | .PHONY: all clean clobber help 4 | 5 | all: main.pdf clean 6 | 7 | main.pdf: $(shell ls *.tex) references.bib 8 | pdflatex main 9 | bibtex main 10 | pdflatex main 11 | pdflatex main 12 | 13 | clean: 14 | @ rm -rf *.aux *.bbl *.blg *.log *.out 15 | 16 | clobber: clean 17 | @ rm -rf main.pdf ../figures/*-eps-converted-to.pdf 18 | 19 | rebuild: clobber all 20 | 21 | help: 22 | @ echo "God helps those who help themselves." 23 | -------------------------------------------------------------------------------- /docs/GSoC2013/proposal/main.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuml07/giri/86f3b8a17c806e64ad1434a39a47f280693a70f2/docs/GSoC2013/proposal/main.pdf -------------------------------------------------------------------------------- /docs/GSoC2013/report/Makefile: -------------------------------------------------------------------------------- 1 | all: main.pdf clean 2 | 3 | main.pdf: main.tex references.bib 4 | pdflatex main 5 | bibtex main 6 | pdflatex main 7 | pdflatex main 8 | 9 | clean: 10 | @rm -rf main.aux *.log main.out *.bbl *.blg 11 | 12 | clobber: clean 13 | @rm -rf main.pdf 14 | 15 | rebuild: clobber all 16 | -------------------------------------------------------------------------------- /docs/GSoC2013/report/main.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuml07/giri/86f3b8a17c806e64ad1434a39a47f280693a70f2/docs/GSoC2013/report/main.pdf -------------------------------------------------------------------------------- /docs/GSoC2013/report/struct-ptr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | typedef struct result 6 | { 7 | int result; 8 | int count; 9 | } result_t; 10 | 11 | void calc(int x, result_t *y, result_t *z) 12 | { 13 | if (x < 0) 14 | { 15 | y->result = sqrt(x); 16 | y->count++; 17 | z->result = pow(2, x); 18 | z->count++; 19 | } else { 20 | if (x == 0) 21 | { 22 | y->result = sqrt(x * 2); 23 | y->count++; 24 | z->result = pow(3, x); 25 | z->count++; 26 | } else { 27 | y->result = sqrt(x * 3); 28 | y->count++; 29 | z->result = pow(4, x); 30 | z->count++; 31 | } 32 | } 33 | } 34 | 35 | int main(int argc, char *argv[]) 36 | { 37 | int x, ret; 38 | result_t y = {0, 0}, z = {0, 0}; 39 | 40 | x = atoi(argv[1]); 41 | 42 | calc(x, &y, &z); 43 | 44 | ret = printf("%d\n", y.result); 45 | printf("%d\n", z.result); 46 | 47 | return ret; 48 | } 49 | -------------------------------------------------------------------------------- /docs/blog/giri-flow.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuml07/giri/86f3b8a17c806e64ad1434a39a47f280693a70f2/docs/blog/giri-flow.jpg -------------------------------------------------------------------------------- /docs/blog/giri-flow.vsd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuml07/giri/86f3b8a17c806e64ad1434a39a47f280693a70f2/docs/blog/giri-flow.vsd -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

GIRI PROJECT DOCUMENTATION

4 |

This is just a placeholder

5 | 6 | 7 | -------------------------------------------------------------------------------- /include/Giri/Runtime.h: -------------------------------------------------------------------------------- 1 | //===- Runtime.h - Header file for the dynamic slicing tracing runtime ----===// 2 | // 3 | // Giri: Dynamic Slicing in LLVM 4 | // 5 | // This file was developed by the LLVM research group and is distributed under 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file defines the format of the tracing file. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #ifndef GIRI_RUNTIME_H 15 | #define GIRI_RUNTIME_H 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | //===----------------------------------------------------------------------===// 22 | // Identifiers for record types 23 | //===----------------------------------------------------------------------===// 24 | enum class RecordType : unsigned { 25 | BBType = 'B', // Basic block record 26 | LDType = 'L', // Load record 27 | STType = 'S', // Store record 28 | CLType = 'C', // Call record 29 | RTType = 'R', // Call return record 30 | ENType = 'E', // End record 31 | PDType = 'P' // Select (predicated) record 32 | //static const unsigned char EXType = 'X'; // External Function record 33 | }; 34 | 35 | /// \class This is the format for one entry in the tracing log file. 36 | /// 37 | /// WARNING: 38 | /// This size of this data structure must evenly divide both the machine's 39 | /// page size *and* the size of the in-memory cache of the run-time. An 40 | /// assertion in the run-time library verifies that this condition is met. 41 | /// Therefore, be mindful of this when adding or deleting fields from this 42 | /// structure. One solution is to adding one padding variable with proper size. 43 | struct Entry { 44 | /// The type of entry 45 | /// For special external functions like memcpy, memset, it is 46 | /// type + #elements to transfer 47 | RecordType type; 48 | 49 | /// The ID of the basic block, or the load/store instruction 50 | unsigned id; 51 | 52 | pthread_t tid; ///< The thread ID 53 | 54 | /// For a load or store, it is the memory address which is read or written. 55 | /// For special external functions (e.g., memcpy, memset), it is the 56 | /// destination address or source address as the call is split into loads and 57 | /// stores. 58 | /// Note that we use an integer size that is large enough to hold a pointer. 59 | /// For Basic block entries, it is overloaded to the address of the function 60 | /// it belongs to. 61 | uintptr_t address; 62 | 63 | /// For load/store records, this holds the size of the memory access in bytes. 64 | /// For last returning basic block of the function, it is overloaded to store 65 | /// the id of the function call instruction which invokes it. 66 | uintptr_t length; 67 | 68 | /// Padding to make the Entry size be devided by Page size 69 | #ifndef __LP64__ 70 | char padding[12]; 71 | #endif 72 | 73 | /// A nice one-line method for initializing the structure 74 | explicit Entry(RecordType type, unsigned id) : 75 | type(type), id(id), tid(0), address(0), length(0) { 76 | } 77 | 78 | /// A nice one-line constructor for initializing the structure with pointers 79 | explicit Entry(RecordType type, 80 | unsigned id, 81 | pthread_t tid, 82 | unsigned char *p, 83 | uintptr_t length = 0) : 84 | type(type), id(id), tid(tid), length(length) { 85 | address = reinterpret_cast(p); 86 | } 87 | 88 | /// Keep the default constructor 89 | Entry() { } 90 | }; 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /include/Utility/BasicBlockNumbering.h: -------------------------------------------------------------------------------- 1 | //===- BasicBlockNumbering.h - Provide BB identifiers -----------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file was developed by the LLVM research group and is distributed under 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This class provides LLVM passes that provide a *stable* numbering of basic 11 | // blocks that does not depend on their address in memory (which is 12 | // nondeterministic). 13 | // 14 | //===----------------------------------------------------------------------===// 15 | 16 | #ifndef DG_BASICBLOCKNUMBERING_H 17 | #define DG_BASICBLOCKNUMBERING_H 18 | 19 | #include "llvm/IR/Function.h" 20 | #include "llvm/IR/Module.h" 21 | #include "llvm/Pass.h" 22 | 23 | #include 24 | 25 | using namespace llvm; 26 | 27 | namespace dg { 28 | 29 | /// \class This pass adds metadata to an LLVM module to assign a unique, stable ID 30 | /// to each basic block. 31 | /// 32 | /// It adds metadata that cannot be written to disk 33 | /// using the LLVM BitcodeWriter pass. 34 | class BasicBlockNumberPass : public ModulePass { 35 | public: 36 | static char ID; 37 | BasicBlockNumberPass () : ModulePass (ID) {} 38 | 39 | /// \brief This is the entry point for our pass. It takes a 40 | /// module and assigns a unique identifier for each basic block. 41 | /// \return true since the module was modified. 42 | virtual bool runOnModule (Module & M); 43 | 44 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { 45 | AU.setPreservesCFG(); 46 | }; 47 | 48 | private: 49 | /// Modifies the specified basic block so that it has the specified ID. 50 | MDNode * assignIDToBlock (BasicBlock * BB, unsigned id); 51 | }; 52 | 53 | /// \class This pass is an analysis pass that reads the metadata added by the 54 | /// BasicBlockNumberPass. 55 | /// 56 | /// This pass makes querying the information easier 57 | /// for other passes and centralizes the reading of the metadata information. 58 | class QueryBasicBlockNumbers : public ModulePass { 59 | public: 60 | static char ID; 61 | 62 | QueryBasicBlockNumbers () : ModulePass (ID) {} 63 | 64 | /// This is the entry point for our pass. It examines the metadata for the 65 | /// module and constructs a mapping from basic blocks to identifiers. It can 66 | /// also tell if a basic block has been added since the basic blocks were 67 | // assigned identifiers. 68 | /// @return false since the this is an analysis pass. 69 | virtual bool runOnModule (Module & M); 70 | 71 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { 72 | AU.setPreservesAll(); 73 | }; 74 | 75 | /// Return the ID number for the specified BasicBlock. 76 | /// \return 0 if this basic block has *no* associated ID, otherwise the ID 77 | /// of the basic block is returned. 78 | unsigned getID (BasicBlock *BB) const { 79 | std::map::const_iterator I = IDMap.find(BB); 80 | if (I == IDMap.end()) 81 | return 0; 82 | return I->second; 83 | } 84 | 85 | /// Find the basic block associated with this ID. 86 | /// FIXME: We allow multiple basic blocks to have the same ID. 87 | /// 88 | /// \return 0 if no basic block has this ID. Otherwise, a pointer to the 89 | /// first basic block with this ID is returned. 90 | BasicBlock * getBlock (unsigned id) const { 91 | std::map::const_iterator i = BBMap.find (id); 92 | if (i != BBMap.end()) 93 | return i->second; 94 | return 0; 95 | } 96 | 97 | protected: 98 | /// \brief Maps a basic block to the number to which it was assigned. 99 | /// Note that *multiple* basic blocks can be assigned the same ID (e.g., if a 100 | /// transform clones a function). 101 | std::map IDMap; 102 | 103 | /// Reverse mapping of IDMap 104 | std::map BBMap; 105 | }; 106 | 107 | /// \class This pass removes the metadata that numbers basic blocks. 108 | /// 109 | /// This is necessary because the bitcode writer pass can't handle writing out 110 | /// basic block values. 111 | class RemoveBasicBlockNumbers : public ModulePass { 112 | public: 113 | static char ID; 114 | 115 | RemoveBasicBlockNumbers () : ModulePass (ID) {} 116 | 117 | /// It takes a module and removes the basic block ID metadata. 118 | /// @return false if the module was not modified, true otherwise. 119 | virtual bool runOnModule (Module & M); 120 | 121 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { 122 | AU.setPreservesCFG(); 123 | }; 124 | }; 125 | 126 | } // END namespace dg 127 | 128 | #endif 129 | -------------------------------------------------------------------------------- /include/Utility/CountSrcLines.h: -------------------------------------------------------------------------------- 1 | //===- CountSrcLines.h - Dynamic Slicing Pass -------------------*- C++ -*-===// 2 | // 3 | // Giri: Dynamic Slicing in LLVM 4 | // 5 | // This file was developed by the LLVM research group and is distributed under 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This files defines passes that are used for dynamic slicing. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #ifndef DG_COUNTSRCLINES_H 15 | #define DG_COUNTSRCLINES_H 16 | 17 | #include "Giri/TraceFile.h" 18 | #include "Utility/BasicBlockNumbering.h" 19 | #include "Utility/LoadStoreNumbering.h" 20 | 21 | #include "llvm/Pass.h" 22 | #include "llvm/InstVisitor.h" 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | using namespace llvm; 29 | 30 | namespace dg { 31 | 32 | /// \class This pass counts the number of static Source lines/LLVM insts. 33 | /// executed in a trace. 34 | struct CountSrcLines : public ModulePass { 35 | public: 36 | static char ID; 37 | 38 | CountSrcLines() : ModulePass (ID) { 39 | //llvm::initializeDynamicGiriPass(*PassRegistry::getPassRegistry()); 40 | } 41 | 42 | /// Entry point for this LLVM pass. Using trace information, find the static 43 | /// number of source lines and LLVM instructions in a trace. 44 | /// 45 | /// \param M - The module to analyze. 46 | /// @return false - The module was not modified. 47 | virtual bool runOnModule(Module &M); 48 | 49 | const char *getPassName() const { 50 | return "Count static #SourceLines/LLVM Insts in a trace"; 51 | } 52 | 53 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { 54 | // We will need the ID numbers of basic blocks 55 | AU.addRequiredTransitive(); 56 | 57 | // We will need the ID numbers of loads and stores 58 | AU.addRequiredTransitive(); 59 | 60 | // This pass is an analysis pass, so it does not modify anything 61 | AU.setPreservesAll(); 62 | }; 63 | 64 | void countLines(const std::string &bbrecord_file); 65 | 66 | std::unordered_set readBB(const std::string &bbrecord_file); 67 | 68 | private: 69 | const QueryBasicBlockNumbers *bbNumPass; 70 | const QueryLoadStoreNumbers *lsNumPass; 71 | 72 | }; 73 | 74 | } // END namespace dg 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /include/Utility/LoadStoreNumbering.h: -------------------------------------------------------------------------------- 1 | //===- LoadStoreNumbering.h - Provide load/store identifiers ----*- C++ -*-===// 2 | // 3 | // Giri: Dynamic Slicing in LLVM 4 | // 5 | // This file was developed by the LLVM research group and is distributed under 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file provides LLVM passes that provide a *stable* numbering of load 11 | // and store instructions that does not depend on their address in memory 12 | // (which is nondeterministic). 13 | // 14 | //===----------------------------------------------------------------------===// 15 | 16 | #ifndef DG_LOADSTORENUMBERING_H 17 | #define DG_LOADSTORENUMBERING_H 18 | 19 | #include "Utility/Utils.h" 20 | 21 | #include "llvm/IR/Function.h" 22 | #include "llvm/IR/Module.h" 23 | #include "llvm/Pass.h" 24 | #include "llvm/InstVisitor.h" 25 | 26 | #include 27 | 28 | using namespace llvm; 29 | 30 | namespace dg { 31 | 32 | /// \class This pass adds metadata to an LLVM module to assign a unique, stable ID 33 | /// to each basic block. 34 | /// 35 | /// This pass adds metadata that cannot be written to disk using the LLVM 36 | /// BitcodeWriter pass. 37 | class LoadStoreNumberPass : public ModulePass, 38 | public InstVisitor { 39 | public: 40 | static char ID; 41 | LoadStoreNumberPass() : ModulePass(ID) {} 42 | 43 | /// It takes a module and assigns a unique identifier for each load and 44 | /// store instruction. 45 | /// @return true - The module was modified. 46 | virtual bool runOnModule(Module &M); 47 | 48 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { 49 | AU.setPreservesCFG(); 50 | }; 51 | 52 | ////////////////////// Instruction visitors ////////////////////// 53 | void visitLoadInst(LoadInst &LI) { 54 | MD->addOperand(assignID(&LI, ++count)); 55 | } 56 | void visitStoreInst(StoreInst &SI) { 57 | MD->addOperand(assignID(&SI, ++count)); 58 | } 59 | void visitSelectInst(SelectInst &SI) { 60 | MD->addOperand(assignID(&SI, ++count)); 61 | } 62 | void visitCallInst(CallInst &CI) { 63 | // Don't instrument functions that are part of the dynamic tracing 64 | // run-time libraries. 65 | if (!isTracerFunction(CI.getCalledFunction())) 66 | MD->addOperand(assignID(&CI, ++count)); 67 | } 68 | 69 | private: 70 | /// Modifies the IR to assign the specified ID to the instruction 71 | MDNode *assignID(Instruction *I, unsigned id); 72 | 73 | private: 74 | unsigned count; ///< Counter for assigning unique IDs 75 | NamedMDNode *MD; ///< Store metadata of each load and store 76 | }; 77 | 78 | /// \class This pass is an analysis pass that reads the metadata added by the 79 | /// LoadStoreNumberPass. This pass makes querying the information easier 80 | /// for other passes and centralizes the reading of the metadata information. 81 | class QueryLoadStoreNumbers : public ModulePass { 82 | public: 83 | static char ID; 84 | QueryLoadStoreNumbers() : ModulePass(ID) {} 85 | 86 | /// It examines the metadata for the module and constructs a mapping from 87 | /// instructions to identifiers. It can also tell if an instruction has been 88 | /// added since the instructions were assigned identifiers. 89 | /// 90 | /// @return always false since this is an analysis pass. 91 | virtual bool runOnModule(Module & M); 92 | 93 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { 94 | AU.setPreservesAll(); 95 | }; 96 | 97 | /// Return the ID number for the specified instruction. 98 | /// \return 0 if this instruction has *no* associated ID. Otherwise, the ID 99 | /// of the instruction is returned. 100 | unsigned getID(const Instruction *I) const { 101 | auto im = IDMap.find(I); 102 | if (im != IDMap.end()) 103 | return im->second; 104 | return 0; 105 | } 106 | 107 | Instruction *getInstByID(unsigned id) const { 108 | auto im= InstMap.find(id); 109 | if (im != InstMap.end()) 110 | return im->second; 111 | return 0; 112 | } 113 | 114 | protected: 115 | /// \brief Maps an instruction to the number to which it was assigned. Note 116 | /// *multiple* instructions can be assigned the same ID (e.g., if a 117 | /// transform clones a function). 118 | std::unordered_map IDMap; 119 | 120 | /// \brief Map an ID to the instruction to which it is mapped. Note that we 121 | /// can have multiple IDs mapped to the same instruction; however, we ignore 122 | /// that possibility for now. 123 | std::unordered_map InstMap; 124 | }; 125 | 126 | /// \class This pass removes the metadata that numbers basic blocks. 127 | /// This is necessary because the bitcode writer pass can't handle writing out 128 | /// basic block values. 129 | class RemoveLoadStoreNumbers : public ModulePass { 130 | public: 131 | static char ID; 132 | RemoveLoadStoreNumbers() : ModulePass(ID) {} 133 | 134 | /// It takes a module and removes the instruction ID metadata. 135 | /// @return false if the module was not modified, otherwise true. 136 | virtual bool runOnModule(Module &M); 137 | 138 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { 139 | AU.setPreservesCFG(); 140 | }; 141 | }; 142 | 143 | } // END namespace dg 144 | 145 | #endif 146 | -------------------------------------------------------------------------------- /include/Utility/PostDominanceFrontier.h: -------------------------------------------------------------------------------- 1 | //=- llvm/Analysis/PostDominanceFrontier.h - Post Dominance Frontier Calculation-*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file exposes interfaces to post dominance frontier information. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #ifndef LLVM_ANALYSIS_POST_DOMINANCE_FRONTIER_H 15 | #define LLVM_ANALYSIS_POST_DOMINANCE_FRONTIER_H 16 | 17 | #include 18 | 19 | #include "llvm/Analysis/DominanceFrontier.h" 20 | #include "llvm/Analysis/PostDominators.h" 21 | 22 | namespace llvm { 23 | 24 | /// PostDominanceFrontier Class - Concrete subclass of DominanceFrontier that is 25 | /// used to compute the a post-dominance frontier. 26 | struct PostDominanceFrontier : public DominanceFrontierBase { 27 | static char ID; 28 | PostDominanceFrontier() 29 | : DominanceFrontierBase(ID, true) { 30 | //initializePostDominanceFrontierPass(*PassRegistry::getPassRegistry()); 31 | } 32 | 33 | virtual bool runOnFunction(Function &F) { 34 | Frontiers.clear(); 35 | PostDominatorTree &DT = getAnalysis(); 36 | Roots = DT.getRoots(); 37 | if (const DomTreeNode *Root = DT.getRootNode()) 38 | calculate(DT, Root); 39 | return false; 40 | } 41 | 42 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { 43 | AU.setPreservesAll(); 44 | AU.addRequired(); 45 | } 46 | 47 | private: 48 | const DomSetType &calculate(const PostDominatorTree &DT, 49 | const DomTreeNode *Node); 50 | }; 51 | 52 | FunctionPass* createPostDomFrontier(); 53 | 54 | } // End llvm namespace 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /include/Utility/SourceLineMapping.h: -------------------------------------------------------------------------------- 1 | //===- SourceLineMapping.h - Map instructions to source lines -*- C++ -*-===// 2 | // 3 | // Giri: Dynamic Slicing in LLVM 4 | // 5 | // This file was developed by the LLVM research group and is distributed under 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This class provides LLVM passes that provide a mapping from LLVM 11 | // instruction to Source Line information. 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | #ifndef DG_SOURCELINEMAPPING_H 16 | #define DG_SOURCELINEMAPPING_H 17 | 18 | #include "llvm/IR/Instruction.h" 19 | #include "llvm/Pass.h" 20 | 21 | using namespace llvm; 22 | 23 | namespace dg { 24 | 25 | /// \class This pass provides the functionality to find the source file and 26 | /// line number corresponding to a llvm instruction. 27 | class SourceLineMappingPass : public ModulePass { 28 | public: 29 | static char ID; 30 | 31 | SourceLineMappingPass () : ModulePass (ID) {} 32 | 33 | static std::string locateSrcInfo(Instruction *I); 34 | 35 | /// Map all instruction in Module M to source lines 36 | void mapCompleteFile(Module &M, raw_ostream &Output); 37 | 38 | /// Map all instruction in one function Module M to source lines 39 | void mapOneFunction(Function *F, raw_ostream &Output); 40 | 41 | /// \brief Using debug information, find the source line number corresponding 42 | /// to a specified LLVM instruction. 43 | /// @return false - The module was not modified. 44 | virtual bool runOnModule(Module &M); 45 | 46 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { 47 | AU.setPreservesCFG(); 48 | AU.setPreservesAll(); 49 | }; 50 | }; 51 | 52 | } // END namespace dg 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /include/Utility/VectorExtras.h: -------------------------------------------------------------------------------- 1 | //===-- llvm/ADT/VectorExtras.h - Helpers for std::vector -------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file contains helper functions which are useful for working with the 11 | // std::vector class. 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | #ifndef LLVM_ADT_VECTOREXTRAS_H 16 | #define LLVM_ADT_VECTOREXTRAS_H 17 | 18 | #include 19 | #include 20 | 21 | namespace llvm { 22 | 23 | /// make_vector - Helper function which is useful for building temporary vectors 24 | /// to pass into type construction of CallInst ctors. This turns a null 25 | /// terminated list of pointers (or other value types) into a real live vector. 26 | /// 27 | template 28 | inline std::vector make_vector(T A, ...) { 29 | va_list Args; 30 | va_start(Args, A); 31 | std::vector Result; 32 | Result.push_back(A); 33 | while (T Val = va_arg(Args, T)) 34 | Result.push_back(Val); 35 | va_end(Args); 36 | return Result; 37 | } 38 | 39 | /// make_array - Helper function which is useful for building temporary ArrayRefs 40 | /// to pass into type construction of CallInst ctors. This turns a null 41 | /// terminated list of pointers (or other value types) into a real live Array. 42 | /// 43 | template 44 | inline ArrayRef make_array(T A, ...) { 45 | va_list Args; 46 | va_start(Args, A); 47 | std::vector Result; 48 | Result.push_back(A); 49 | while (T Val = va_arg(Args, T)) 50 | Result.push_back(Val); 51 | va_end(Args); 52 | ArrayRef< Value * > ActualArgs (Result); 53 | return ActualArgs ; 54 | } 55 | 56 | } // End llvm namespace 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /lib/Giri/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/lib/Giri/Makefile ----------------------------*- Makefile -*-===## 2 | 3 | # 4 | # Indicate where we are relative to the top of the source tree. 5 | # 6 | LEVEL=../.. 7 | 8 | # 9 | # Give the name of a library. This will build a dynamic version. 10 | # 11 | LIBRARYNAME=giri 12 | 13 | # 14 | # Build a shared library on platforms that support it. 15 | # 16 | ifneq ($(OS),Cygwin) 17 | ifneq ($(OS),MingW) 18 | SHARED_LIBRARY := 1 19 | endif 20 | endif 21 | 22 | LLVMLIBS = support 23 | 24 | LINK_COMPONENTS := Support 25 | 26 | USEDLIBS := Support.a 27 | 28 | # 29 | # Include Makefile.common so we know what to do. 30 | # 31 | include $(LEVEL)/Makefile.common 32 | -------------------------------------------------------------------------------- /lib/Giri/TestPass.cpp: -------------------------------------------------------------------------------- 1 | //===- Giri.cpp - Find dynamic backwards slice analysis pass -------------- --// 2 | // 3 | // Giri: Dynamic Slicing in LLVM 4 | // 5 | // This file was developed by the LLVM research group and is distributed under 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file implements an analysis pass that allows clients to find the 11 | // instructions contained within the dynamic backwards slice of a specified 12 | // instruction. 13 | // 14 | //===----------------------------------------------------------------------===// 15 | 16 | #define DEBUG_TYPE "giri-test" 17 | 18 | #include "Giri/Giri.h" 19 | 20 | #include "llvm/Support/CommandLine.h" 21 | 22 | using namespace llvm; 23 | 24 | // Command line options 25 | static cl::opt 26 | InstIndex("inst-index", cl::desc("Instruction index in function"), cl::init(0)); 27 | 28 | static cl::opt 29 | Funcname ("funcname", cl::desc("Function Name"), cl::init("main")); 30 | 31 | namespace giri { 32 | 33 | /// This pass is used to test the giri pass. 34 | struct TestGiri : public ModulePass { 35 | protected: 36 | // Dynamic backwards slice 37 | std::set mySliceOfLife; 38 | std::unordered_set myDynSliceOfLife; 39 | std::set myDataFlowGraph; 40 | 41 | public: 42 | static char ID; 43 | TestGiri () : ModulePass (ID) { } 44 | 45 | /// Entry point for this pass. Find the instruction specified by the user 46 | /// and find the backwards slice of it. 47 | virtual bool runOnModule (Module & M) { 48 | // Get a reference to the function specified by the user. 49 | Function * F = M.getFunction (Funcname); 50 | if (!F) return false; 51 | 52 | // Find the instruction referenced by the user and get its backwards slice. 53 | unsigned index = 0; 54 | DynamicGiri & Giri = getAnalysis(); 55 | for (Function::iterator BB = F->begin(); BB != F->end(); ++BB) { 56 | for (BasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) { 57 | if (index++ == InstIndex) { 58 | std::cerr << "Trace for: "; 59 | I->print(llvm::errs ()); 60 | std::cerr << std::endl; 61 | Giri.getBackwardsSlice (I, mySliceOfLife, myDynSliceOfLife, myDataFlowGraph); 62 | break; 63 | } 64 | } 65 | } 66 | 67 | // We never modify the module. 68 | return false; 69 | } 70 | 71 | const char *getPassName() const { 72 | return "Dynamic Backwards Slice Testing Pass"; 73 | } 74 | 75 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { 76 | // We will need the ID numbers of basic blocks 77 | AU.addRequired(); 78 | 79 | // This pass is an analysis pass, so it does not modify anything 80 | AU.setPreservesAll(); 81 | }; 82 | 83 | virtual void releaseMemory () { 84 | mySliceOfLife.clear(); 85 | } 86 | 87 | virtual void print (llvm::raw_ostream & O, const Module * M) const { 88 | std::set::iterator V; 89 | for (V = mySliceOfLife.begin(); V != mySliceOfLife.end(); ++V) { 90 | (*V)->print(O); 91 | O << "\n"; 92 | } 93 | 94 | return; 95 | } 96 | 97 | }; // End TestGiri 98 | 99 | } 100 | 101 | // ID Variable to identify the pass 102 | char giri::TestGiri::ID = 0; 103 | 104 | // Pass registration 105 | static RegisterPass 106 | X ("test-giri", "Dynamic Backwards Slice Testing Pass"); 107 | -------------------------------------------------------------------------------- /lib/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/lib/Makefile ----------------------------*- Makefile -*-===## 2 | 3 | # 4 | # Relative path to the top of the source tree. 5 | # 6 | LEVEL=.. 7 | 8 | # 9 | # List all of the subdirectories that we will compile. 10 | # 11 | PARALLEL_DIRS=Giri Utility 12 | 13 | include $(LEVEL)/Makefile.common 14 | -------------------------------------------------------------------------------- /lib/Utility/BasicBlockNumbering.cpp: -------------------------------------------------------------------------------- 1 | //===- BasicBlockNumbering.cpp - Provide BB identifiers ---------*- C++ -*-===// 2 | // 3 | // Giri: Dynamic Slicing in LLVM 4 | // 5 | // This file was developed by the LLVM research group and is distributed under 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file implements a pass that assigns a unique ID to each basic block. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #define DEBUG_TYPE "giriutil" 15 | 16 | #include "Utility/BasicBlockNumbering.h" 17 | 18 | #include "llvm/IR/Constants.h" 19 | #include "llvm/IR/Instructions.h" 20 | #include "llvm/Support/CommandLine.h" 21 | #include "llvm/Support/Debug.h" 22 | #include "llvm/Support/raw_ostream.h" 23 | 24 | #include 25 | 26 | using namespace dg; 27 | using namespace llvm; 28 | 29 | //===----------------------------------------------------------------------===// 30 | // Command Line Arguments 31 | //===----------------------------------------------------------------------===// 32 | // The trace filename was specified externally in tracing part 33 | static cl::opt 34 | DumpID("dump-bbid", cl::desc("Dump assigned basic block ID"), cl::init(false)); 35 | 36 | //===----------------------------------------------------------------------===// 37 | // Load Store Number Passes 38 | //===----------------------------------------------------------------------===// 39 | char BasicBlockNumberPass::ID = 0; 40 | char QueryBasicBlockNumbers::ID = 0; 41 | char RemoveBasicBlockNumbers::ID = 0; 42 | 43 | static const char *mdKindName = "dg"; 44 | 45 | static RegisterPass 46 | X("bbnum", "Assign Unique Identifiers to Basic Blocks"); 47 | 48 | static RegisterPass 49 | Y("query-bbnum", "Query Unique Identifiers of Basic Blocks"); 50 | 51 | static RegisterPass 52 | Z("remove-bbnum", "Remove Unique Identifiers of Basic Blocks"); 53 | 54 | MDNode* BasicBlockNumberPass::assignIDToBlock (BasicBlock *BB, unsigned id) { 55 | if (DumpID) 56 | dbgs() << id << " : " << BB->getName() << "\n"; 57 | 58 | // Fetch the context in which the enclosing module was defined. We'll need 59 | // it for creating practically everything. 60 | LLVMContext & Context = BB->getParent()->getParent()->getContext(); 61 | 62 | // Create a new metadata node that contains the ID as a constant. 63 | Value *ID[2]; 64 | ID[0] = BB; 65 | ID[1] = ConstantInt::get(Type::getInt32Ty(Context), id); 66 | return MDNode::getWhenValsUnresolved(Context, ArrayRef(ID, 2), false); 67 | } 68 | 69 | bool BasicBlockNumberPass::runOnModule(Module &M) { 70 | // Now create a named metadata node that links all of this metadata together. 71 | NamedMDNode * MD = M.getOrInsertNamedMetadata(mdKindName); 72 | 73 | // Scan through the module and assign a unique, positive (i.e., non-zero) ID 74 | // to every basic block. 75 | unsigned count = 0; 76 | for (Module::iterator MI = M.begin(), ME = M.end(); MI != ME; ++MI) 77 | for (Function::iterator BB = MI->begin(), BE = MI->end(); BB != BE; ++BB) { 78 | MD->addOperand((assignIDToBlock(BB, ++count))); 79 | } 80 | DEBUG(dbgs() << "Total Number of Basic Blocks: " << count << "\n"); 81 | 82 | // We always modify the module. 83 | return true; 84 | } 85 | 86 | bool QueryBasicBlockNumbers::runOnModule(Module &M) { 87 | DEBUG(dbgs() << "Inside QueryBasicBlockNumbers for module " 88 | << M.getModuleIdentifier() 89 | << "\n"); 90 | 91 | // Get the basic block metadata. If there isn't any metadata, then no basic 92 | // block has been numbered. 93 | // 94 | const NamedMDNode *MD = M.getNamedMetadata(mdKindName); 95 | if (!MD) 96 | return false; 97 | 98 | // Scan through all of the metadata (should be pairs of basic blocks/IDs) and 99 | // bring them into our internal data structure. 100 | for (unsigned index = 0; index < MD->getNumOperands(); ++index) { 101 | // The basic block should be the first element, and the ID should be the 102 | // second element. 103 | MDNode *Node = dyn_cast(MD->getOperand(index)); 104 | assert(Node && "Wrong type of meta data!"); 105 | BasicBlock *BB = dyn_cast(Node->getOperand(0)); 106 | ConstantInt *ID = dyn_cast(Node->getOperand(1)); 107 | 108 | // Do some assertions to make sure that everything is sane. 109 | assert(BB && "MDNode first element is not a BasicBlock!"); 110 | assert(ID && "MDNode second element is not a ConstantInt!"); 111 | 112 | // Add the values into the map. 113 | assert(ID->getZExtValue() && "BB with zero ID!"); 114 | IDMap[BB] = ID->getZExtValue(); 115 | unsigned id = static_cast(ID->getZExtValue()); 116 | bool inserted = BBMap.insert(std::make_pair(id,BB)).second; 117 | assert(inserted && "Repeated identifier!"); 118 | } 119 | 120 | return false; 121 | } 122 | 123 | bool RemoveBasicBlockNumbers::runOnModule(Module &M) { 124 | // Get the basic block metadata. If there isn't any metadata, then no basic 125 | // blocks have been numbered. 126 | NamedMDNode * MD = M.getNamedMetadata(mdKindName); 127 | if (!MD) 128 | return false; 129 | 130 | // Remove the metadata. 131 | MD->eraseFromParent(); 132 | 133 | // Assume we always modify the module. 134 | return true; 135 | } 136 | -------------------------------------------------------------------------------- /lib/Utility/CountSrcLines.cpp: -------------------------------------------------------------------------------- 1 | //===- CountSrcLines.cpp - Find dynamic backwards slice analysis pass --------// 2 | // 3 | // Giri: Dynamic Slicing in LLVM 4 | // 5 | // This file was developed by the LLVM research group and is distributed under 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file implements an analysis pass that allows clients to find the 11 | // instructions contained within the dynamic backwards slice of a specified 12 | // instruction. 13 | // 14 | //===----------------------------------------------------------------------===// 15 | 16 | #define DEBUG_TYPE "giriutil" 17 | 18 | #include "Utility/CountSrcLines.h" 19 | #include "Utility/SourceLineMapping.h" 20 | 21 | #include "llvm/ADT/Statistic.h" 22 | #include "llvm/IR/IntrinsicInst.h" 23 | #include "llvm/Support/CommandLine.h" 24 | #include "llvm/Support/Debug.h" 25 | #include "llvm/Support/raw_ostream.h" 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | using namespace llvm; 33 | using namespace dg; 34 | using namespace std; 35 | 36 | //===----------------------------------------------------------------------===// 37 | // Pass Statistics 38 | //===----------------------------------------------------------------------===// 39 | STATISTIC(NumOfDynamicBBs, "Number of basic blocks executed in trace"); 40 | STATISTIC(NumSrcLines, "Number of static source lines executed in trace"); 41 | STATISTIC(NumSrcLinesMissing, "Number of insts missing debug info"); 42 | STATISTIC(NumWithoutSrcLines, "Number of ignored insts without source lines"); 43 | STATISTIC(NumStaticInst, "Number of static LLVM instructions executed"); 44 | STATISTIC(NumBBsNoSrc, "Number of BBs whose source line debug info is missing"); 45 | 46 | //===----------------------------------------------------------------------===// 47 | // Command Line Arguments. 48 | //===----------------------------------------------------------------------===// 49 | cl::opt TraceFilename("trace-file", 50 | cl::desc("Trace filename"), 51 | cl::init("bbrecord")); 52 | 53 | //===----------------------------------------------------------------------===// 54 | // CountSrcLines Pass Implementations 55 | //===----------------------------------------------------------------------===// 56 | 57 | char CountSrcLines::ID = 0; 58 | 59 | static RegisterPass 60 | X("countsrc", "Count number of LLVM instructions and source lines of a trace"); 61 | 62 | void CountSrcLines::countLines(const string &bbrecord_file) { 63 | unordered_set bb_set = readBB(bbrecord_file); 64 | set srcLines; 65 | set BBsNoSrc; 66 | 67 | unordered_set::iterator curr; 68 | for (curr = bb_set.begin(); curr != bb_set.end(); ++curr) { 69 | BasicBlock *BB = bbNumPass->getBlock(*curr); 70 | NumStaticInst += BB->size(); 71 | for (BasicBlock::iterator it = BB->begin(); it != BB->end(); ++it) { 72 | string srcLineInfo = SourceLineMappingPass::locateSrcInfo(it); 73 | if (srcLineInfo.empty()) // Ignored instructions without source lines 74 | NumWithoutSrcLines++; 75 | else if (srcLineInfo == "NIL") { // No source line found using debug info 76 | NumSrcLinesMissing++; 77 | BBsNoSrc.insert(srcLineInfo); 78 | } else 79 | srcLines.insert(srcLineInfo); 80 | } 81 | } 82 | 83 | NumSrcLines = srcLines.size(); 84 | NumBBsNoSrc = BBsNoSrc.size(); 85 | } 86 | 87 | unordered_set CountSrcLines::readBB(const string &bbrecord) { 88 | int bb_fd = open(bbrecord.c_str(), O_RDONLY); 89 | if (!bb_fd) 90 | report_fatal_error("Error opening trace file: " + bbrecord + "!\n"); 91 | 92 | unordered_set bb_set; // Keep track of basic bock ID 93 | Entry entry; 94 | while (read(bb_fd, &entry, sizeof(entry)) == sizeof(entry)) { 95 | if (entry.type == RecordType::BBType) { 96 | bb_set.insert(entry.id); 97 | ++NumOfDynamicBBs; 98 | } 99 | if (entry.type == RecordType::ENType) 100 | break; 101 | } 102 | 103 | close(bb_fd); 104 | 105 | return bb_set; 106 | } 107 | 108 | bool CountSrcLines::runOnModule(Module &M) { 109 | // Get references to other passes used by this pass. 110 | bbNumPass = &getAnalysis(); 111 | lsNumPass = &getAnalysis(); 112 | 113 | // Open the trace file and read the basic block entries. 114 | countLines(TraceFilename); 115 | 116 | // This is an analysis pass, so always return false. 117 | return false; 118 | } 119 | -------------------------------------------------------------------------------- /lib/Utility/LoadStoreNumbering.cpp: -------------------------------------------------------------------------------- 1 | //===- LoadStoreNumbering.cpp - Provide BB identifiers ----------*- C++ -*-===// 2 | // 3 | // Giri: Dynamic Slicing in LLVM 4 | // 5 | // This file was developed by the LLVM research group and is distributed under 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file implements a pass that assigns a unique ID to each basic block. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #define DEBUG_TYPE "giriutil" 15 | 16 | #define MAX_PROGRAM_POINTS 2000000 17 | 18 | #include "Utility/LoadStoreNumbering.h" 19 | 20 | #include "llvm/IR/Constants.h" 21 | #include "llvm/IR/Instructions.h" 22 | #include "llvm/Support/CommandLine.h" 23 | #include "llvm/Support/Debug.h" 24 | #include "llvm/Support/raw_ostream.h" 25 | 26 | #include 27 | 28 | using namespace dg; 29 | using namespace llvm; 30 | 31 | //===----------------------------------------------------------------------===// 32 | // Command Line Arguments 33 | //===----------------------------------------------------------------------===// 34 | // The trace filename was specified externally in tracing part 35 | static cl::opt 36 | DumpID("dump-lsid", cl::desc("Dump assigned Load/Store ID"), cl::init(false)); 37 | 38 | //===----------------------------------------------------------------------===// 39 | // Load Store Number Passes 40 | //===----------------------------------------------------------------------===// 41 | char LoadStoreNumberPass::ID = 0; 42 | char QueryLoadStoreNumbers::ID = 0; 43 | char RemoveLoadStoreNumbers::ID = 0; 44 | 45 | static const char *mdKindName = "dgls"; 46 | 47 | static RegisterPass 48 | X ("lsnum", "Assign Unique Identifiers to Loads and Stores"); 49 | 50 | static RegisterPass 51 | Z ("remove-lsnum", "Remove Unique Identifiers of Loads and Stores"); 52 | 53 | static RegisterPass 54 | Y ("query-lsnum", "Query Unique Identifiers of Loads and Stores"); 55 | 56 | MDNode *LoadStoreNumberPass::assignID(Instruction *I, unsigned id) { 57 | if (DumpID) { 58 | dbgs() << id << " : "; 59 | I->print(dbgs()); 60 | dbgs() << "\n"; 61 | } 62 | 63 | // Fetch the context in which the enclosing module was defined. We'll need 64 | // it for creating practically everything. 65 | Module *M = I->getParent()->getParent()->getParent(); 66 | LLVMContext &Context = M->getContext(); 67 | 68 | // Create a new metadata node that contains the ID as a constant. 69 | Value *ID[2]; 70 | ID[0] = I; 71 | ID[1] = ConstantInt::get(Type::getInt32Ty(Context), id); 72 | return MDNode::getWhenValsUnresolved(Context, ArrayRef(ID, 2), false); 73 | } 74 | 75 | bool LoadStoreNumberPass::runOnModule(Module &M) { 76 | // Now create a named metadata node that links all of this metadata together. 77 | MD = M.getOrInsertNamedMetadata(mdKindName); 78 | 79 | // Scan through the module and assign a unique, positive (i.e., non-zero) ID 80 | // to every load and store instruction. Create an array of metadata nodes 81 | // to hold this data. 82 | count = 0; 83 | visit(&M); 84 | DEBUG(dbgs() << "Number of monitored program points: " << count << "\n"); 85 | if (count > MAX_PROGRAM_POINTS) 86 | errs() << "Number of monitored program points exceeds maximum value.\n"; 87 | return true; 88 | } 89 | 90 | bool QueryLoadStoreNumbers::runOnModule(Module &M) { 91 | DEBUG(dbgs() << "Inside QueryLoadStoreNumbers for module " 92 | << M.getModuleIdentifier() 93 | << "\n"); 94 | // Get the basic block metadata. If there isn't any metadata, then no basic 95 | // block has been numbered. 96 | const NamedMDNode *MD = M.getNamedMetadata(mdKindName); 97 | if (!MD) 98 | return false; 99 | 100 | // Scan through all of the metadata (should be pairs of instructions/IDs) and 101 | // bring them into our internal data structure. 102 | for (unsigned index = 0; index < MD->getNumOperands(); ++index) { 103 | // The instruction should be the first element, and the ID should be the 104 | // second element. 105 | MDNode *Node = dyn_cast(MD->getOperand (index)); 106 | assert(Node && "Wrong type of meta data!\n"); 107 | Instruction *I = dyn_cast(Node->getOperand(0)); 108 | ConstantInt *ID = dyn_cast(Node->getOperand(1)); 109 | 110 | // Do some assertions to make sure that everything is sane. 111 | assert(I && "MDNode first element is not an Instruction!\n"); 112 | assert(ID && "MDNode second element is not a ConstantInt!\n"); 113 | 114 | // Add the values into the map. 115 | assert(ID->getZExtValue() && "Instruction with zero ID!\n"); 116 | IDMap[I] = ID->getZExtValue(); 117 | unsigned id = (unsigned)ID->getZExtValue(); 118 | bool inserted = InstMap.insert(std::make_pair(id,I)).second; 119 | assert(inserted && "Repeated identifier!\n"); 120 | } 121 | 122 | return false; 123 | } 124 | 125 | bool RemoveLoadStoreNumbers::runOnModule(Module &M) { 126 | // Get the basic block metadata. If there isn't any metadata, then no basic 127 | // blocks have been numbered. 128 | NamedMDNode *MD = M.getNamedMetadata(mdKindName); 129 | if (!MD) 130 | return false; 131 | 132 | // Remove the metadata. 133 | MD->eraseFromParent(); 134 | 135 | // Assume we always modify the module. 136 | return true; 137 | } 138 | -------------------------------------------------------------------------------- /lib/Utility/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/lib/Utility/Makefile --------------------------*- Makefile -*-===## 2 | 3 | # 4 | # Indicate where we are relative to the top of the source tree. 5 | # 6 | LEVEL=../.. 7 | 8 | # 9 | # Give the name of a library. This will build a dynamic version. 10 | # 11 | LIBRARYNAME=dgutility 12 | 13 | # 14 | # Build a shared library on platforms that support it. 15 | # 16 | ifneq ($(OS),Cygwin) 17 | ifneq ($(OS),MingW) 18 | SHARED_LIBRARY := 1 19 | endif 20 | endif 21 | 22 | # 23 | # Include Makefile.common so we know what to do. 24 | # 25 | include $(LEVEL)/Makefile.common 26 | -------------------------------------------------------------------------------- /lib/Utility/PostDominatorFrontier.cpp: -------------------------------------------------------------------------------- 1 | //===- PostDominanceFrontier.cpp - Post-Dominance frontier Calculation --------------------===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file implements the post-dominance frontier construction algorithms. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #define DEBUG_TYPE "giriutil" 15 | 16 | #include "Utility/PostDominanceFrontier.h" 17 | 18 | #include "llvm/IR/Instructions.h" 19 | #include "llvm/Support/CFG.h" 20 | #include "llvm/Support/Debug.h" 21 | #include "llvm/ADT/DepthFirstIterator.h" 22 | #include "llvm/ADT/SetOperations.h" 23 | #include "llvm/Analysis/DominatorInternals.h" 24 | 25 | using namespace llvm; 26 | 27 | //===----------------------------------------------------------------------===// 28 | // PostDominanceFrontier Implementation 29 | //===----------------------------------------------------------------------===// 30 | char PostDominanceFrontier::ID = 0; 31 | /* 32 | INITIALIZE_PASS_BEGIN(PostDominanceFrontier, "postdomfrontier", 33 | "Post-Dominance Frontier Construction", true, true) 34 | INITIALIZE_PASS_DEPENDENCY(PostDominatorTree) 35 | INITIALIZE_PASS_END(PostDominanceFrontier, "postdomfrontier", 36 | "Post-Dominance Frontier Construction", true, true) 37 | */ 38 | 39 | static RegisterPass 40 | H("postdomfrontier", "Post-Dominance Frontier Construction", true, true); 41 | 42 | const DominanceFrontier::DomSetType& 43 | PostDominanceFrontier::calculate(const PostDominatorTree &DT, 44 | const DomTreeNode *Node) { 45 | // Loop over CFG successors to calculate DFlocal[Node] 46 | BasicBlock *BB = Node->getBlock(); 47 | DomSetType &S = Frontiers[BB]; // The new set to fill in... 48 | if (getRoots().empty()) return S; 49 | 50 | if (BB) 51 | for (pred_iterator SI = pred_begin(BB), SE = pred_end(BB); 52 | SI != SE; ++SI) { 53 | BasicBlock *P = *SI; 54 | // Does Node immediately dominate this predecessor? 55 | DomTreeNode *SINode = DT[P]; 56 | if (SINode && SINode->getIDom() != Node) 57 | S.insert(P); 58 | } 59 | 60 | // At this point, S is DFlocal. Now we union in DFup's of our children... 61 | // Loop through and visit the nodes that Node immediately dominates (Node's 62 | // children in the IDomTree) 63 | // 64 | for (DomTreeNode::const_iterator 65 | NI = Node->begin(), NE = Node->end(); NI != NE; ++NI) { 66 | DomTreeNode *IDominee = *NI; 67 | const DomSetType &ChildDF = calculate(DT, IDominee); 68 | 69 | DomSetType::const_iterator CDFI = ChildDF.begin(), CDFE = ChildDF.end(); 70 | for (; CDFI != CDFE; ++CDFI) { 71 | if (!DT.properlyDominates(Node, DT[*CDFI])) 72 | S.insert(*CDFI); 73 | } 74 | } 75 | 76 | return S; 77 | } 78 | 79 | FunctionPass* llvm::createPostDomFrontier() { 80 | return new PostDominanceFrontier(); 81 | } 82 | -------------------------------------------------------------------------------- /lib/Utility/SourceLineMapping.cpp: -------------------------------------------------------------------------------- 1 | //===- SourceLineMapping.h - Provide BB identifiers -----------*- C++ -*-===// 2 | // 3 | // Giri: Dynamic Slicing in LLVM 4 | // 5 | // This file was developed by the LLVM research group and is distributed under 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This class provides LLVM passes that provide a mapping from LLVM 11 | // instruction to Source Line information. 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | #define DEBUG_TYPE "giriutil" 16 | 17 | #include "Utility/SourceLineMapping.h" 18 | #include "Utility/Utils.h" 19 | 20 | #include "llvm/ADT/Statistic.h" 21 | #include "llvm/DebugInfo.h" 22 | #include "llvm/IR/Instructions.h" 23 | #include "llvm/IR/IntrinsicInst.h" 24 | #include "llvm/IR/Function.h" 25 | #include "llvm/IR/Module.h" 26 | #include "llvm/IR/LLVMContext.h" 27 | #include "llvm/Pass.h" 28 | #include "llvm/Support/Debug.h" 29 | #include "llvm/Support/CallSite.h" 30 | #include "llvm/Support/CommandLine.h" 31 | #include "llvm/Support/InstIterator.h" 32 | #include "llvm/Support/raw_os_ostream.h" 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | using namespace llvm; 40 | using namespace dg; 41 | 42 | //===----------------------------------------------------------------------===// 43 | // Command line options 44 | //===----------------------------------------------------------------------===// 45 | static cl::opt 46 | FunctionName("mapping-function", 47 | cl::desc("The function name to be mapped"), 48 | cl::init("")); 49 | 50 | static cl::opt 51 | MappingFileName("mapping-output", 52 | cl::desc("The output filename of the source line mapping"), 53 | cl::init("-")); 54 | 55 | //===----------------------------------------------------------------------===// 56 | // Pass Statistics 57 | //===----------------------------------------------------------------------===// 58 | STATISTIC(NumFoundSrc, "Number of source information locations found"); 59 | STATISTIC(NumNotFoundSrc, "Number of source information locations not found"); 60 | STATISTIC(NumQueriedSrc, "Number of queried including ignored LLVM insts"); 61 | 62 | //===----------------------------------------------------------------------===// 63 | // Source Line Mapping Pass 64 | //===----------------------------------------------------------------------===// 65 | 66 | // ID Variable to identify the pass 67 | char SourceLineMappingPass::ID = 0; 68 | 69 | // Pass registration 70 | static RegisterPass 71 | X("srcline-mapping", "Mapping LLVM inst to source line number"); 72 | 73 | std::string SourceLineMappingPass::locateSrcInfo(Instruction *I) { 74 | // Update the number of source locations queried. 75 | ++NumQueriedSrc; 76 | 77 | // Get the ID number for debug metadata. 78 | if (MDNode *N = I->getMetadata("dbg")) { 79 | DILocation Loc(N); 80 | ++NumFoundSrc; 81 | std::stringstream ss; 82 | ss << Loc.getDirectory().str() << "/" 83 | << Loc.getFilename().str() << ":" 84 | << Loc.getLineNumber(); 85 | return ss.str(); 86 | } else { 87 | if (isa(I) || isa(I) || isa(I)) 88 | return ""; 89 | else if (isa(I) || isa(I)) { 90 | // Get the called function and determine if it's a debug function 91 | // or our instrumentation function 92 | CallSite CS(I); 93 | Function *CalledFunc = CS.getCalledFunction(); 94 | if (CalledFunc) { 95 | if (isTracerFunction(CalledFunc)) 96 | return ""; 97 | std::string fnname = CalledFunc->getName().str(); 98 | if (fnname.compare(0, 9, "llvm.dbg.") == 0) 99 | return ""; 100 | } 101 | } 102 | NumNotFoundSrc++; 103 | return "NIL"; 104 | } 105 | } 106 | 107 | void SourceLineMappingPass::mapCompleteFile(Module &M, raw_ostream &Output) { 108 | for (Module::iterator F = M.begin(); F != M.end(); ++F) 109 | if (!F->isDeclaration() && F->hasName()) 110 | mapOneFunction(&*F, Output); 111 | } 112 | 113 | void SourceLineMappingPass::mapOneFunction(Function *F, raw_ostream &Output) { 114 | assert(F && !F->isDeclaration() && F->hasName()); 115 | Output << "========================================================\n"; 116 | Output << "Source line mapping for function: " << F->getName() << "\n"; 117 | Output << "========================================================\n"; 118 | 119 | int instCount = 0; 120 | for (inst_iterator I = inst_begin(F); I != inst_end(F); ++I) { 121 | Output << ++instCount << ": "; 122 | I->print(Output); 123 | Output << ": "; 124 | Output << locateSrcInfo(&*I); 125 | Output << "\n"; 126 | } 127 | } 128 | 129 | bool SourceLineMappingPass::runOnModule(Module &M) { 130 | std::string errinfo; 131 | raw_fd_ostream MappingFile(MappingFileName.c_str(), errinfo); 132 | 133 | if (!FunctionName.empty()) 134 | mapOneFunction(M.getFunction(FunctionName), MappingFile); 135 | else 136 | mapCompleteFile(M, MappingFile); 137 | 138 | // This is an analysis pass, so always return false. 139 | return false; 140 | } 141 | -------------------------------------------------------------------------------- /runtime/Giri/Makefile: -------------------------------------------------------------------------------- 1 | ##===- runtime/Giri/Makefile -------------------------------*- Makefile -*-===## 2 | 3 | # Indicate where we are relative to the top of the source tree. 4 | LEVEL = ../.. 5 | 6 | # Give the name of a library. This will build a dynamic version. 7 | LIBRARYNAME = rtgiri 8 | 9 | ifneq ($(strip $(LLVMCC)),) 10 | BYTECODE_LIBRARY = 1 11 | endif 12 | 13 | ARCHIVE_LIBRARY = 1 14 | 15 | include $(LEVEL)/Makefile.common 16 | -------------------------------------------------------------------------------- /runtime/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/runtime/Makefile -----------------------------*- Makefile -*-===## 2 | 3 | # 4 | # Relative path to the top of the source tree. 5 | # 6 | LEVEL=.. 7 | 8 | # 9 | # List all of the subdirectories that we will compile. 10 | # 11 | PARALLEL_DIRS=Giri 12 | 13 | include $(LEVEL)/Makefile.common 14 | -------------------------------------------------------------------------------- /test/HelloWorld/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/UnitTests/Makefile.common -----------------*- Makefile -*-===## 2 | # 3 | 4 | DEBUGFLAGS ?= -debug 5 | CFLAGS ?= -g -O0 -c -emit-llvm 6 | LDFLAGS ?= 7 | BuildMode ?= Release+Debug+Asserts 8 | GIRI_DIR ?= ../../build/ 9 | NAME ?= hello-world 10 | 11 | CC = clang 12 | CXX = clang++ 13 | GIRI_LIB_DIR = $(GIRI_DIR)/$(BuildMode)/lib 14 | GIRI_BIN_DIR = $(GIRI_DIR)/$(BuildMode)/bin 15 | 16 | .PHONY: all lib 17 | 18 | all: lib $(NAME).slice 19 | @ echo -n "The line numbers of source code slice are: " 20 | @ sed -n '/^Source.*[0-9]$$/p' $(NAME).slice |\ 21 | awk -F: '{print $$3}' |\ 22 | sort -g |\ 23 | uniq | xargs\ 24 | echo 25 | 26 | lib: 27 | $(MAKE) -s -C $(GIRI_DIR) 28 | 29 | $(NAME).slice : $(NAME).bc $(NAME).trace 30 | @ opt -load $(GIRI_LIB_DIR)/libdgutility.so \ 31 | -load $(GIRI_LIB_DIR)/libgiri.so \ 32 | -mergereturn -bbnum -lsnum \ 33 | -dgiri -trace-file=$(NAME).trace -slice-file=$(NAME).slice \ 34 | -remove-bbnum -remove-lsnum \ 35 | -stats $(DEBUGFLAGS) $< -o /dev/null 36 | 37 | $(NAME).trace: $(NAME).trace.exe 38 | - ./$< $(INPUT) 39 | 40 | $(NAME).trace.exe : $(NAME).trace.s 41 | $(CXX) -fno-strict-aliasing $+ -o $@ $(LDFLAGS) -L$(GIRI_LIB_DIR) -lrtgiri 42 | 43 | $(NAME).trace.s : $(NAME).trace.bc 44 | llc -asm-verbose=false -O0 $< -o $@ 45 | 46 | $(NAME).trace.bc : $(NAME).bc 47 | @ opt -load $(GIRI_LIB_DIR)/libdgutility.so \ 48 | -load $(GIRI_LIB_DIR)/libgiri.so \ 49 | -mergereturn -bbnum -lsnum \ 50 | -trace-giri -trace-file=$(NAME).trace \ 51 | -remove-bbnum -remove-lsnum \ 52 | -stats $(DEBUGFLAGS) $< -o $@ 53 | 54 | %.bc : %.c 55 | $(CC) $(CFLAGS) $+ -o $@ 56 | %.ll : %.bc 57 | llvm-dis $< -o $@ 58 | 59 | .PHONY: ptrace rebuild clean 60 | 61 | prtrace: $(NAME).trace 62 | $(GIRI_BIN_DIR)/prtrace $< 63 | 64 | rebuild: clean all 65 | 66 | clean: 67 | @ rm -f *.ll *.bc *.o *.s *.slice *.exe *.trace 68 | -------------------------------------------------------------------------------- /test/HelloWorld/hello-world.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char *argv[]) 4 | { 5 | int ret; 6 | 7 | printf("Hello "); 8 | ret = printf("World!\n"); 9 | 10 | return ret; 11 | } 12 | -------------------------------------------------------------------------------- /test/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/Makefile ----------------------------------*- Makefile -*-===## 2 | # 3 | # Define the default test rule. Just type 'make test' in this directory. 4 | # 5 | ##===----------------------------------------------------------------------===## 6 | 7 | .PHONY: test lib clean 8 | 9 | TEST_LOG ?= /dev/null 10 | 11 | # The default target in this directory is the test:: target 12 | test:: lib 13 | @ echo "Running the test cases..." 14 | @ RET=0;\ 15 | for t in $$(cat auto-tests.txt);\ 16 | do\ 17 | printf "\033[37m%-20s" "$$t";\ 18 | make clean -s -C $$t > /dev/null 2>&1;\ 19 | make -s -C $$t > /dev/null 2>&1;\ 20 | make test -s -C $$t DEBUGFLAGS= >> $(TEST_LOG) 2>&1;\ 21 | if [ $$? -eq 0 ]; then\ 22 | printf "\033[34m[PASS]\033[0m\n";\ 23 | else\ 24 | printf "\033[31m[FAIL]\033[0m\n";\ 25 | RET=1;\ 26 | fi;\ 27 | make clean -s -C $$t > /dev/null 2>&1;\ 28 | done;\ 29 | [ "$(TEST_LOG)" != "/dev/null" ] && cat $(TEST_LOG);\ 30 | exit $$RET 31 | 32 | lib: 33 | @ echo -n "Building the Giri..." 34 | @ $(MAKE) -s -C ../build 2>&1 > /dev/null || (echo "Fail to build the Giri lib!" && exit 1) 35 | @ echo 36 | 37 | clean: 38 | @ for t in $$(cat auto-tests.txt); do make clean -C $$t; done 39 | @ rm -f $(TEST_LOG) 40 | -------------------------------------------------------------------------------- /test/Makefile.common: -------------------------------------------------------------------------------- 1 | ##===- giri/test/UnitTests/Makefile.common -----------------*- Makefile -*-===## 2 | # 3 | 4 | ########################### User defined variables ########################### 5 | NAME ?= main 6 | DEBUGFLAGS ?= -debug 7 | GIRI_DIR ?= ../../../build/ 8 | BuildMode ?= Release+Debug+Asserts 9 | SRC_FILES ?= $(wildcard *.c) 10 | IR_FILES ?= $(SRC_FILES:%.c=%.bc) 11 | INPUT ?= 12 | CRITERION ?= 13 | TEST_ANS ?= ans-inst.txt 14 | MAPPING ?= 15 | 16 | ################# Dont' edit the following lines accidently ################## 17 | CC = clang 18 | CXX = clang++ 19 | CFLAGS += -g -O0 -c -emit-llvm 20 | GIRI_LIB_DIR = $(GIRI_DIR)/$(BuildMode)/lib 21 | GIRI_BIN_DIR = $(GIRI_DIR)/$(BuildMode)/bin 22 | 23 | .PHONY: all lib 24 | 25 | all: lib $(NAME).slice.loc 26 | 27 | lib: 28 | $(MAKE) -s -C $(GIRI_DIR) 29 | 30 | %.slice.loc: %.slice 31 | @ sed -n '/^Source.*[0-9]\+$$/p' $< |\ 32 | awk -F: '{print $$3}' |\ 33 | sort -g |\ 34 | uniq > $@ 35 | 36 | $(NAME).slice : $(NAME).all.bc $(NAME).trace 37 | opt -load $(GIRI_LIB_DIR)/libdgutility.so \ 38 | -load $(GIRI_LIB_DIR)/libgiri.so \ 39 | -mergereturn -bbnum -lsnum \ 40 | -dgiri -trace-file=$(NAME).trace -slice-file=$(NAME).slice $(CRITERION)\ 41 | -remove-bbnum -remove-lsnum \ 42 | -stats $(DEBUGFLAGS) $< -o /dev/null 43 | 44 | $(NAME).trace: $(NAME).trace.exe 45 | - ./$< $(INPUT) 46 | 47 | $(NAME).trace.exe : $(NAME).trace.s 48 | $(CXX) -fno-strict-aliasing $+ -o $@ -L$(GIRI_LIB_DIR) -lrtgiri $(LDFLAGS) 49 | 50 | $(NAME).trace.s : $(NAME).trace.bc 51 | llc -asm-verbose=false -O0 $< -o $@ 52 | 53 | $(NAME).trace.bc : $(NAME).all.bc 54 | opt -load $(GIRI_LIB_DIR)/libdgutility.so \ 55 | -load $(GIRI_LIB_DIR)/libgiri.so \ 56 | -mergereturn -bbnum -lsnum \ 57 | -trace-giri -trace-file=$(NAME).trace \ 58 | -remove-bbnum -remove-lsnum \ 59 | -stats $(DEBUGFLAGS) $< -o $@ 60 | 61 | $(NAME).all.bc: $(IR_FILES) 62 | llvm-link $^ -o $@ 63 | $(IR_FILES) : %.bc : %.c 64 | $(CC) $(CFLAGS) $+ -o $@ 65 | 66 | .PHONY: mapping bbid bbid 67 | 68 | mapping: $(NAME).all.bc 69 | opt -load $(GIRI_LIB_DIR)/libdgutility.so \ 70 | -load $(GIRI_LIB_DIR)/libgiri.so \ 71 | -mergereturn \ 72 | -srcline-mapping $(MAPPING) \ 73 | -stats $(DEBUGFLAGS) $< -o /dev/null 74 | 75 | bbid: $(NAME).all.bc 76 | opt -load $(GIRI_LIB_DIR)/libdgutility.so \ 77 | -mergereturn \ 78 | -bbnum -dump-bbid=true \ 79 | -remove-bbnum \ 80 | -stats $(DEBUGFLAGS) $< -o /dev/null 2>&1 |\ 81 | view - 82 | 83 | lsid: $(NAME).all.bc 84 | opt -load $(GIRI_LIB_DIR)/libdgutility.so \ 85 | -mergereturn \ 86 | -lsnum -dump-lsid=true \ 87 | -remove-lsnum \ 88 | -stats $(DEBUGFLAGS) $< -o /dev/null 2>&1 |\ 89 | view - 90 | 91 | %.ll : %.bc 92 | llvm-dis $< -o $@ 93 | 94 | .PHONY: test ptrace rebuild clean clean-all 95 | 96 | test: $(NAME).slice.loc 97 | diff $< $(TEST_ANS) 98 | 99 | prtrace: $(NAME).trace 100 | $(GIRI_BIN_DIR)/prtrace $< | view - 101 | 102 | rebuild: clean all 103 | 104 | clean: clean-all 105 | @ rm -f *.ll *.bc *.o *.s *.slice *.slice.loc *.exe *.trace ans.txt 106 | clean-all: 107 | -------------------------------------------------------------------------------- /test/UnitTests/test1/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/UnitTests/test1/Makefile ------------------*- Makefile -*-===## 2 | 3 | NAME = extlibcalls 4 | INPUT ?= Mingliang LIU 5 | 6 | include ../../Makefile.common 7 | -------------------------------------------------------------------------------- /test/UnitTests/test1/README.md: -------------------------------------------------------------------------------- 1 | This test is for external library calls. 2 | -------------------------------------------------------------------------------- /test/UnitTests/test1/ans-inst.txt: -------------------------------------------------------------------------------- 1 | 9 2 | 12 3 | 13 4 | 18 5 | -------------------------------------------------------------------------------- /test/UnitTests/test1/extlibcalls.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define LENGTH 128 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | char *input = (char *)malloc(LENGTH); 10 | memset(input, 0, LENGTH); 11 | 12 | strcpy(input, argv[1]); 13 | strcat(input, argv[2]); 14 | 15 | printf("%s\n", input); 16 | printf("%zd\n", strlen(input)); 17 | 18 | return strlen(input); 19 | } 20 | -------------------------------------------------------------------------------- /test/UnitTests/test10/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/UnitTests/test10/Makefile -----------------*- Makefile -*-===## 2 | 3 | NAME = str 4 | INPUT ?= giri 5 | 6 | include ../../Makefile.common 7 | -------------------------------------------------------------------------------- /test/UnitTests/test10/README.md: -------------------------------------------------------------------------------- 1 | This is a simple string operations using strcpy and strlen. 2 | -------------------------------------------------------------------------------- /test/UnitTests/test10/ans-inst.txt: -------------------------------------------------------------------------------- 1 | 13 2 | 18 3 | 19 4 | 28 5 | -------------------------------------------------------------------------------- /test/UnitTests/test10/str.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int cmp(const void *l, const void *r) { 6 | char cl = *((char *)l); 7 | char cr = *((char *)r); 8 | return cl < cr; 9 | } 10 | 11 | int main(int argc, char *argv[]) { 12 | char *str, *ordered_str; 13 | if (argc < 2) { 14 | fprintf(stderr, "Usage: %s str", argv[0]); 15 | exit(EXIT_FAILURE); 16 | } 17 | 18 | str = (char *)malloc(strlen(argv[1]) + 1); 19 | strcpy(str, argv[1]); 20 | str[strlen(str)] = '\0'; 21 | 22 | ordered_str = (char *)malloc(strlen(str) + 1); 23 | strcpy(ordered_str, str); 24 | ordered_str[strlen(ordered_str)] = '\0'; 25 | qsort(ordered_str, strlen(ordered_str), sizeof(char), cmp); 26 | printf("%s\n", ordered_str); 27 | 28 | return str[0]; 29 | } 30 | -------------------------------------------------------------------------------- /test/UnitTests/test11/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/UnitTests/test11/Makefile -----------------*- Makefile -*-===## 2 | 3 | NAME = hello2p 4 | LDFLAGS = -pthread 5 | INPUT ?= 4 6 | 7 | include ../../Makefile.common 8 | -------------------------------------------------------------------------------- /test/UnitTests/test11/README.md: -------------------------------------------------------------------------------- 1 | This is a simple test counting the len of each string. 2 | 3 | - pthreads 4 | - malloc/free 5 | - There is a bug in this code, i.e. a data race adding the retvalue of `pthread_join` 6 | - This is from the book **CS:APP**, chapter _12.4_ 7 | -------------------------------------------------------------------------------- /test/UnitTests/test11/ans-inst.txt: -------------------------------------------------------------------------------- 1 | 21 2 | 23 3 | 28 4 | 29 5 | 41 6 | 44 7 | 47 8 | -------------------------------------------------------------------------------- /test/UnitTests/test11/hello2p.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | void *thread(void *vargp); 8 | 9 | char **ptr; /** Global variable */ 10 | 11 | int main(int argc, char **argv) 12 | { 13 | unsigned nthreads, i; 14 | pthread_t tid; 15 | char *msgs[] = { 16 | "Hello from foo", 17 | "Hello from bar", 18 | "Hello from jar", 19 | "Hello from de" 20 | }; 21 | int total_len = 0; 22 | 23 | if (argc < 2) { 24 | fprintf(stderr, "Usage: %s \n", argv[0]); 25 | exit(EXIT_FAILURE); 26 | } 27 | 28 | nthreads = atoi(argv[1]); 29 | if (nthreads > 4) { 30 | fprintf(stderr, "The nthreads should be less than 5!\n"); 31 | exit(EXIT_FAILURE); 32 | } 33 | 34 | ptr = msgs; /* Make the local variable globally shared */ 35 | 36 | for (i = 0; i < nthreads; i++) { 37 | unsigned *ip = (unsigned *)malloc(sizeof(unsigned)); 38 | *ip = i; 39 | pthread_create(&tid, NULL, thread, (void *)ip); 40 | } 41 | for (i = 0; i < nthreads; i++) { 42 | uintptr_t len; 43 | pthread_join(tid, (void **)&len); 44 | total_len += len; 45 | } 46 | 47 | return total_len; 48 | } 49 | 50 | void *thread(void *vargp) 51 | { 52 | unsigned *ip = (unsigned *)vargp; 53 | unsigned myid = *ip; 54 | uintptr_t len = strlen(ptr[myid]); 55 | free(ip); 56 | return (void *)len; 57 | } 58 | -------------------------------------------------------------------------------- /test/UnitTests/test12/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/UnitTests/test12/Makefile -----------------*- Makefile -*-===## 2 | 3 | NAME = psum 4 | LDFLAGS = -pthread 5 | INPUT ?= 16 8 6 | 7 | include ../../Makefile.common 8 | -------------------------------------------------------------------------------- /test/UnitTests/test12/README.md: -------------------------------------------------------------------------------- 1 | The threads sum the sequence of integers 0, ..., n - 1 in parallel. 2 | 3 | There are shared variables, for loops and arrays. 4 | 5 | To see more about this test, please refer to the **CS:APP** book _Chapter 12.6_ 6 | -------------------------------------------------------------------------------- /test/UnitTests/test12/ans-inst.txt: -------------------------------------------------------------------------------- 1 | 15 2 | 20 3 | 25 4 | 26 5 | 27 6 | 28 7 | 29 8 | 32 9 | 33 10 | 40 11 | 41 12 | 44 13 | 51 14 | 56 15 | 57 16 | 58 17 | 59 18 | 61 19 | 62 20 | 64 21 | -------------------------------------------------------------------------------- /test/UnitTests/test12/psum.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define MAX_THREADS 32 6 | 7 | void *sum(void *vargp); 8 | 9 | /** Global shared variables */ 10 | long psum[MAX_THREADS]; /* partial sum computed by each thread */ 11 | long nelems_per_thread; /* number of elements summed by each thread */ 12 | 13 | int main(int argc, char **argv) 14 | { 15 | long i, nelems, log_nelems, nthreads, esum, result = 0; 16 | pthread_t tid[MAX_THREADS]; 17 | int myid[MAX_THREADS]; 18 | 19 | /* Get the input arguments */ 20 | if (argc != 3) { 21 | fprintf(stderr, "Usage: %s \n", argv[0]); 22 | exit(EXIT_FAILURE); 23 | } 24 | 25 | nthreads = atoi(argv[1]); 26 | log_nelems = atoi(argv[2]); 27 | nelems = (1L << log_nelems); 28 | esum = nelems * (nelems - 1) / 2; 29 | nelems_per_thread = nelems / nthreads; 30 | 31 | /* Create peer threads and wait for them to finish */ 32 | for (i = 0; i < nthreads; i++) { 33 | myid[i] = i; 34 | pthread_create(&tid[i], NULL, sum, &myid[i]); 35 | } 36 | for (i = 0; i < nthreads; i++) 37 | pthread_join(tid[i], NULL); 38 | 39 | /* Add up the partial sums computed by each thread */ 40 | for (i = 0; i < nthreads; i++) 41 | result += psum[i]; 42 | 43 | /* Check final answer */ 44 | if (result != esum) { 45 | fprintf(stderr, "Error: result = %ld\n", result); 46 | exit(EXIT_FAILURE); 47 | } 48 | 49 | printf("The supposed sum is: %ld\n", esum); 50 | 51 | return result % 31; 52 | } 53 | 54 | void *sum(void *vargp) 55 | { 56 | int myid = *((int *)vargp); 57 | long start = myid * nelems_per_thread; /* Extract the thread ID */ 58 | long end = start + nelems_per_thread; /* End element index */ 59 | long i, mysum = 0; 60 | 61 | for (i = start; i < end; i++) 62 | mysum += i; 63 | 64 | psum[myid] = mysum; 65 | 66 | return NULL; 67 | } 68 | -------------------------------------------------------------------------------- /test/UnitTests/test13/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/UnitTests/test13/Makefile -----------------*- Makefile -*-===## 2 | 3 | NAME = struct 4 | LDFLAGS = -lm 5 | INPUT ?= 10 6 | 7 | include ../../Makefile.common 8 | -------------------------------------------------------------------------------- /test/UnitTests/test13/README.md: -------------------------------------------------------------------------------- 1 | The purpose is to test the behavior of the struct types. 2 | 3 | This is the from test case 4. 4 | -------------------------------------------------------------------------------- /test/UnitTests/test13/ans-inst.txt: -------------------------------------------------------------------------------- 1 | 15 2 | 17 3 | 24 4 | 31 5 | 38 6 | 41 7 | -------------------------------------------------------------------------------- /test/UnitTests/test13/struct.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct result_t { 6 | int result; 7 | int count; 8 | }; 9 | 10 | int main(int argc, char *argv[]) 11 | { 12 | int x, ret; 13 | struct result_t y = {0, 0}, z = {0, 0}; 14 | 15 | x = atoi(argv[1]); 16 | 17 | if (x < 0) 18 | { 19 | y.result = sqrt(x); 20 | y.count++; 21 | z.result = pow(2, x); 22 | z.count++; 23 | } else { 24 | if (x == 0) 25 | { 26 | y.result = sqrt(x * 2); 27 | y.count++; 28 | z.result = pow(3, x); 29 | z.count++; 30 | } else { 31 | y.result = sqrt(x * 3); 32 | y.count++; 33 | z.result = pow(4, x); 34 | z.count++; 35 | } 36 | } 37 | 38 | ret = printf("%d\n", y.result); 39 | printf("%d\n", z.result); 40 | 41 | return ret; 42 | } 43 | -------------------------------------------------------------------------------- /test/UnitTests/test14/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/UnitTests/test14/Makefile -----------------*- Makefile -*-===## 2 | 3 | NAME = struct-ptr 4 | LDFLAGS = -lm 5 | INPUT ?= 10 6 | 7 | include ../../Makefile.common 8 | -------------------------------------------------------------------------------- /test/UnitTests/test14/README.md: -------------------------------------------------------------------------------- 1 | The purpose is to test the behavior of the struct pointers. 2 | 3 | This is the from test case 13. 4 | -------------------------------------------------------------------------------- /test/UnitTests/test14/ans-inst.txt: -------------------------------------------------------------------------------- 1 | 13 2 | 20 3 | 27 4 | 40 5 | 42 6 | 44 7 | 47 8 | -------------------------------------------------------------------------------- /test/UnitTests/test14/struct-ptr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | typedef struct result 6 | { 7 | int result; 8 | int count; 9 | } result_t; 10 | 11 | void calc(int x, result_t *y, result_t *z) 12 | { 13 | if (x < 0) 14 | { 15 | y->result = sqrt(x); 16 | y->count++; 17 | z->result = pow(2, x); 18 | z->count++; 19 | } else { 20 | if (x == 0) 21 | { 22 | y->result = sqrt(x * 2); 23 | y->count++; 24 | z->result = pow(3, x); 25 | z->count++; 26 | } else { 27 | y->result = sqrt(x * 3); 28 | y->count++; 29 | z->result = pow(4, x); 30 | z->count++; 31 | } 32 | } 33 | } 34 | 35 | int main(int argc, char *argv[]) 36 | { 37 | int x, ret; 38 | result_t y = {0, 0}, z = {0, 0}; 39 | 40 | x = atoi(argv[1]); 41 | 42 | calc(x, &y, &z); 43 | 44 | ret = printf("%d\n", y.result); 45 | printf("%d\n", z.result); 46 | 47 | return ret; 48 | } 49 | -------------------------------------------------------------------------------- /test/UnitTests/test15/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/UnitTests/test15/Makefile -----------------*- Makefile -*-===## 2 | 3 | NAME = hanoi 4 | INPUT ?= 7 5 | 6 | include ../../Makefile.common 7 | -------------------------------------------------------------------------------- /test/UnitTests/test15/README.md: -------------------------------------------------------------------------------- 1 | This test is for external library calls. 2 | -------------------------------------------------------------------------------- /test/UnitTests/test15/ans-inst.txt: -------------------------------------------------------------------------------- 1 | 6 2 | 7 3 | 8 4 | 10 5 | 11 6 | 12 7 | 13 8 | 20 9 | 25 10 | 26 11 | 28 12 | 29 13 | -------------------------------------------------------------------------------- /test/UnitTests/test15/hanoi.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int move(int n, char from, char to, char via) 5 | { 6 | int count = 0; 7 | if (n > 1) 8 | count += move(n - 1, from, via, to); 9 | printf ("Move %d from %c to %c\n", n, from, to); 10 | count++; 11 | if (n > 1) 12 | count += move(n - 1, via, to, from); 13 | return count; 14 | } 15 | 16 | int main (int argc, char **argv) 17 | { 18 | int n, ret; 19 | 20 | if (argc < 2) { 21 | fprintf(stderr, "Please input the number of towers!\n"); 22 | return EXIT_FAILURE; 23 | } 24 | 25 | n = atoi(argv[1]); 26 | ret = move (n, 'A', 'C', 'B'); 27 | 28 | return ret % 32; 29 | } 30 | -------------------------------------------------------------------------------- /test/UnitTests/test16/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/UnitTests/test16/Makefile -----------------*- Makefile -*-===## 2 | 3 | NAME = struct-ptr 4 | LDFLAGS = -lm 5 | INPUT ?= 10 6 | 7 | include ../../Makefile.common 8 | -------------------------------------------------------------------------------- /test/UnitTests/test16/README.md: -------------------------------------------------------------------------------- 1 | The purpose is to test multiple source files. 2 | 3 | This is from the test case 14. 4 | -------------------------------------------------------------------------------- /test/UnitTests/test16/ans-inst.txt: -------------------------------------------------------------------------------- 1 | 7 2 | 11 3 | 13 4 | 14 5 | 15 6 | 18 7 | 21 8 | -------------------------------------------------------------------------------- /test/UnitTests/test16/calc.c: -------------------------------------------------------------------------------- 1 | #include "calc.h" 2 | 3 | #include 4 | 5 | void calc(int x, struct result_t *y, struct result_t *z) 6 | { 7 | if (x < 0) 8 | { 9 | y->result = sqrt(x); 10 | y->count++; 11 | z->result = pow(2, x); 12 | z->count++; 13 | } else { 14 | if (x == 0) 15 | { 16 | y->result = sqrt(x * 2); 17 | y->count++; 18 | z->result = pow(3, x); 19 | z->count++; 20 | } else { 21 | y->result = sqrt(x * 3); 22 | y->count++; 23 | z->result = pow(4, x); 24 | z->count++; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test/UnitTests/test16/calc.h: -------------------------------------------------------------------------------- 1 | struct result_t 2 | { 3 | int result; 4 | int count; 5 | }; 6 | 7 | void calc(int x, struct result_t *y, struct result_t *z); 8 | -------------------------------------------------------------------------------- /test/UnitTests/test16/struct-ptr.c: -------------------------------------------------------------------------------- 1 | #include "calc.h" 2 | 3 | #include 4 | #include 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | int x, ret; 9 | struct result_t y = {0, 0}, z = {0, 0}; 10 | 11 | x = atoi(argv[1]); 12 | 13 | calc(x, &y, &z); 14 | 15 | ret = printf("%d\n", y.result); 16 | printf("%d\n", z.result); 17 | 18 | return ret; 19 | } 20 | -------------------------------------------------------------------------------- /test/UnitTests/test17/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/UnitTests/test4/Makefile ------------------*- Makefile -*-===## 2 | 3 | DEBUGFLAGS ?= -debug 4 | NAME = plower 5 | LDFLAGS = -lpthread 6 | INPUT ?= 4 7 | CRITERION ?= -criterion-loc=criterion-loc.txt 8 | #CRITERION ?= -criterion-inst=criterion-inst.txt 9 | MAPPING ?= -mapping-function=main 10 | 11 | include ../../Makefile.common 12 | -------------------------------------------------------------------------------- /test/UnitTests/test17/README.md: -------------------------------------------------------------------------------- 1 | The threads sum the sequence of integers 0, ..., n - 1 in parallel. 2 | 3 | There are shared variables, for loops and arrays. 4 | 5 | To see more about this test, please refer to the **CS:APP** book _Chapter 12.6_ 6 | -------------------------------------------------------------------------------- /test/UnitTests/test17/ans-inst.txt: -------------------------------------------------------------------------------- 1 | 11 2 | 16 3 | 21 4 | 25 5 | 26 6 | 27 7 | -------------------------------------------------------------------------------- /test/UnitTests/test17/ans-loc.txt: -------------------------------------------------------------------------------- 1 | 11 2 | 16 3 | 21 4 | 25 5 | 26 6 | 27 7 | -------------------------------------------------------------------------------- /test/UnitTests/test17/criterion-inst.txt: -------------------------------------------------------------------------------- 1 | main 56 2 | -------------------------------------------------------------------------------- /test/UnitTests/test17/criterion-loc.txt: -------------------------------------------------------------------------------- 1 | plower.c 27 2 | -------------------------------------------------------------------------------- /test/UnitTests/test17/plower.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void *mylower(void *vargp); 7 | 8 | int main(int argc, char **argv) 9 | { 10 | size_t i, nthreads, neles; 11 | char *ele = "AAAABBBBCCCCDDDDEEEEFFFFGGGGHHHHIIII"; 12 | char *pele; 13 | pthread_t *tid; 14 | 15 | /* Get the input arguments */ 16 | if (argc != 2) { 17 | fprintf(stderr, "Usage: %s \n", argv[0]); 18 | exit(EXIT_FAILURE); 19 | } 20 | 21 | nthreads = atoi(argv[1]); 22 | tid = (pthread_t *)malloc(nthreads * sizeof(pthread_t)); 23 | 24 | /* Create peer threads and wait for them to finish */ 25 | for (i = 0; i < nthreads; i++) { 26 | pele = (char *)malloc(5); 27 | memcpy(pele, ele + 4 * i, 4); 28 | pele[4] = '\0'; 29 | pthread_create(&tid[i], NULL, mylower, pele); 30 | } 31 | for (i = 0; i < nthreads; i++) 32 | pthread_join(tid[i], NULL); 33 | 34 | return 0; 35 | } 36 | 37 | void *mylower(void *vargp) 38 | { 39 | char *s = (char *)vargp; 40 | for (; *s; s++) 41 | *s = *s + 32; 42 | printf("%s\n", (char *)vargp); 43 | return NULL; 44 | } 45 | -------------------------------------------------------------------------------- /test/UnitTests/test18/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/UnitTests/test1/Makefile ------------------*- Makefile -*-===## 2 | 3 | NAME = extlibcalls 4 | INPUT ?= Mingliang LIU 5 | 6 | include ../../Makefile.common 7 | -------------------------------------------------------------------------------- /test/UnitTests/test18/README.md: -------------------------------------------------------------------------------- 1 | This test is for external library calls, with global variables. 2 | -------------------------------------------------------------------------------- /test/UnitTests/test18/ans-inst.txt: -------------------------------------------------------------------------------- 1 | 11 2 | 14 3 | 15 4 | 20 5 | -------------------------------------------------------------------------------- /test/UnitTests/test18/extlibcalls.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define LENGTH 128 6 | 7 | char *input; 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | input = (char *)malloc(LENGTH); 12 | memset(input, 0, LENGTH); 13 | 14 | strcpy(input, argv[1]); 15 | strcat(input, argv[2]); 16 | 17 | printf("%s\n", input); 18 | printf("%zd\n", strlen(input)); 19 | 20 | return strlen(input); 21 | } 22 | -------------------------------------------------------------------------------- /test/UnitTests/test19/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/UnitTests/test19/Makefile -----------------*- Makefile -*-===## 2 | 3 | NAME = fibocci 4 | INPUT ?= 7 5 | 6 | include ../../Makefile.common 7 | -------------------------------------------------------------------------------- /test/UnitTests/test19/README.md: -------------------------------------------------------------------------------- 1 | This test is fibonacci test for direct recursive function calls. 2 | -------------------------------------------------------------------------------- /test/UnitTests/test19/ans-inst.txt: -------------------------------------------------------------------------------- 1 | 6 2 | 8 3 | 9 4 | 11 5 | 12 6 | 19 7 | 24 8 | 25 9 | 28 10 | 29 11 | -------------------------------------------------------------------------------- /test/UnitTests/test19/fibonacci.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | long long fibocci(int n) 5 | { 6 | if (n < 0) 7 | return 0; 8 | else if (n == 0 || n == 1) 9 | return n; 10 | else 11 | return fibocci(n - 1) + fibocci(n - 2); 12 | } 13 | 14 | int main (int argc, char **argv) 15 | { 16 | int n; 17 | long long ret; 18 | 19 | if (argc < 2) { 20 | fprintf(stderr, "Please input the number!\n"); 21 | return EXIT_FAILURE; 22 | } 23 | 24 | n = atoi(argv[1]); 25 | ret = fibocci(n); 26 | 27 | 28 | return ret % 32; 29 | } 30 | -------------------------------------------------------------------------------- /test/UnitTests/test2/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/UnitTests/test2/Makefile ------------------*- Makefile -*-===## 2 | 3 | NAME = ifelse 4 | INPUT ?= a b c d 5 | 6 | include ../../Makefile.common 7 | -------------------------------------------------------------------------------- /test/UnitTests/test2/README.md: -------------------------------------------------------------------------------- 1 | Test control-dependence tracking. 2 | -------------------------------------------------------------------------------- /test/UnitTests/test2/ans-inst.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 10 3 | 11 4 | 14 5 | -------------------------------------------------------------------------------- /test/UnitTests/test2/ifelse.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int func (int a) { 5 | return a + 3; 6 | } 7 | 8 | int main (int argc, char ** argv) { 9 | volatile int x; 10 | if (argc < func(argc + 3)) 11 | x = argc - 3; 12 | else 13 | x = func(argc); 14 | return x; 15 | } 16 | -------------------------------------------------------------------------------- /test/UnitTests/test20/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/UnitTests/test20/Makefile -----------------*- Makefile -*-===## 2 | 3 | NAME = even 4 | INPUT ?= 719 5 | 6 | include ../../Makefile.common 7 | -------------------------------------------------------------------------------- /test/UnitTests/test20/README.md: -------------------------------------------------------------------------------- 1 | This is for indirect recursive function calls. 2 | 3 | A standard example of (indirect) mutual recursion, which is admittedly artificial, is determining whether a non-negative number is even or is odd by having two separate functions and calling each other, decrementing each time. These functions are based on the observation that the question is 4 even? is equivalent to is 3 odd?, which is in turn equivalent to is 2 even?, and so on down to 0. 4 | -------------------------------------------------------------------------------- /test/UnitTests/test20/ans-inst.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 8 3 | 9 4 | 12 5 | 13 6 | 15 7 | 16 8 | 22 9 | 27 10 | 29 11 | 30 12 | -------------------------------------------------------------------------------- /test/UnitTests/test20/even.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int is_even(int n) { 5 | if (n == 0) 6 | return 1; 7 | else 8 | return is_odd(n - 1); 9 | } 10 | 11 | int is_odd(int n) { 12 | if (n == 0) 13 | return 0; 14 | else 15 | return is_even(n - 1); 16 | } 17 | 18 | int main (int argc, char **argv) 19 | { 20 | int n; 21 | 22 | if (argc < 2) { 23 | fprintf(stderr, "Please input the number!\n"); 24 | return EXIT_FAILURE; 25 | } 26 | 27 | n = atoi(argv[1]); 28 | 29 | return is_even(n); 30 | } 31 | -------------------------------------------------------------------------------- /test/UnitTests/test21/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/UnitTests/test21/Makefile -----------------*- Makefile -*-===## 2 | 3 | NAME = hwtype 4 | INPUT ?= t Giri 5 | CRITERION ?= -criterion-inst=criterion-inst.txt 6 | 7 | include ../../Makefile.common 8 | -------------------------------------------------------------------------------- /test/UnitTests/test21/README.md: -------------------------------------------------------------------------------- 1 | The following C program uses a function pointer to invoke one of two functions (sin or cos) indirectly from another function (compute_sum, computing an approximation of the function's Riemann integration). The program operates by having function main call function compute_sum twice, passing it a pointer to the library function sin the first time, and a pointer to function cos the second time. Function compute_sum in turn invokes one of the two functions indirectly by dereferencing its function pointer argument funcp multiple times, adding together the values that the invoked function returns and returning the resulting sum. The two sums are written to the standard output by main. 2 | -------------------------------------------------------------------------------- /test/UnitTests/test21/ans-inst.txt: -------------------------------------------------------------------------------- 1 | 4 2 | 11 3 | 18 4 | 23 5 | 24 6 | 25 7 | -------------------------------------------------------------------------------- /test/UnitTests/test21/criterion-inst.txt: -------------------------------------------------------------------------------- 1 | main 51 2 | -------------------------------------------------------------------------------- /test/UnitTests/test21/hwtype.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const char* get_hwtype (const char *name) { 4 | return name; 5 | } 6 | 7 | int main(int argc, char **argv) { 8 | const char *hw = NULL; 9 | const char *ap = NULL; 10 | int hw_set = 0; 11 | switch (*argv[1]) { 12 | case 'A': case 'p': { 13 | ap = argv[2]; 14 | break; 15 | } 16 | case 'H': case 't': { 17 | hw = get_hwtype(argv[3]); 18 | hw_set = 1; 19 | break; 20 | } 21 | default : break; 22 | } 23 | if (hw_set && *argv[1] != 'H') 24 | hw = get_hwtype ("DFLT_HW"); 25 | printf("%s %s\n", ap, hw); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /test/UnitTests/test22/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/UnitTests/test22/Makefile -----------------*- Makefile -*-===## 2 | 3 | NAME = fp 4 | LD_FLAGS ?= -lm 5 | INPUT ?= 10 6 | CRITERION ?= -criterion-inst=criterion-inst.txt 7 | 8 | include ../../Makefile.common 9 | -------------------------------------------------------------------------------- /test/UnitTests/test22/ans-inst.txt: -------------------------------------------------------------------------------- 1 | 7 2 | 10 3 | 15 4 | 16 5 | 17 6 | 19 7 | 33 8 | 34 9 | 35 10 | -------------------------------------------------------------------------------- /test/UnitTests/test22/criterion-inst.txt: -------------------------------------------------------------------------------- 1 | main 18 2 | -------------------------------------------------------------------------------- /test/UnitTests/test22/fp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Function taking a function pointer as an argument 5 | double compute_sum(double (*funcp)(double), double lo, double hi) 6 | { 7 | double sum = 0.0; 8 | 9 | // Add values returned by the pointed-to function '*funcp' 10 | for (int i = 0; i <= 100; i++) 11 | { 12 | double x, y; 13 | 14 | // Use the function pointer 'funcp' to invoke the function 15 | x = i/100.0 * (hi - lo) + lo; 16 | y = (*funcp)(x); 17 | sum += y; 18 | } 19 | return (sum/100.0); 20 | } 21 | 22 | int main(void) 23 | { 24 | double (*fp)(double); // Function pointer 25 | double sum; 26 | 27 | // Use 'sin()' as the pointed-to function 28 | fp = sin; 29 | sum = compute_sum(fp, 0.0, 1.0); 30 | printf("sum(sin): %f\n", sum); 31 | 32 | // Use 'cos()' as the pointed-to function 33 | fp = cos; 34 | sum = compute_sum(fp, 0.0, 1.0); 35 | printf("sum(cos): %f\n", sum); 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /test/UnitTests/test3/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/UnitTests/test3/Makefile ------------------*- Makefile -*-===## 2 | 3 | NAME = fibonacci 4 | INPUT ?= 15 5 | 6 | include ../../Makefile.common 7 | -------------------------------------------------------------------------------- /test/UnitTests/test3/README.md: -------------------------------------------------------------------------------- 1 | This test is for recursive function calls. 2 | -------------------------------------------------------------------------------- /test/UnitTests/test3/ans-inst.txt: -------------------------------------------------------------------------------- 1 | 7 2 | 8 3 | 9 4 | 12 5 | 13 6 | 17 7 | 22 8 | 23 9 | 26 10 | -------------------------------------------------------------------------------- /test/UnitTests/test3/fibonacci.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int fibonacci(int n) 6 | { 7 | if (n < 2) 8 | return n; 9 | else if (n > 40) 10 | return INT_MAX; 11 | else 12 | return fibonacci(n - 1) + fibonacci(n - 2); 13 | } 14 | 15 | int main(int argc, char *argv[]) 16 | { 17 | if (argc < 2) { 18 | fprintf(stderr, "Usage: %s n\n", argv[0]); 19 | exit(EXIT_FAILURE); 20 | } 21 | 22 | int n = atoi(argv[1]); 23 | int f = fibonacci(n); 24 | printf("fibonacci(%d) is %d\n", n, f); 25 | 26 | return f; 27 | } 28 | -------------------------------------------------------------------------------- /test/UnitTests/test4/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/UnitTests/test4/Makefile ------------------*- Makefile -*-===## 2 | 3 | NAME = example 4 | LDFLAGS = -lm 5 | INPUT ?= 10 6 | CRITERION ?= -criterion-loc=criterion-loc.txt 7 | #CRITERION ?= -criterion-inst=criterion-inst.txt 8 | MAPPING ?= -mapping-function=main 9 | 10 | include ../../Makefile.common 11 | -------------------------------------------------------------------------------- /test/UnitTests/test4/README.md: -------------------------------------------------------------------------------- 1 | This is the example 1 of the paper _Dynamic Program Slicing_ 2 | -------------------------------------------------------------------------------- /test/UnitTests/test4/ans-inst.txt: -------------------------------------------------------------------------------- 1 | 9 2 | 11 3 | 16 4 | 21 5 | 22 6 | 26 7 | 27 8 | -------------------------------------------------------------------------------- /test/UnitTests/test4/ans-loc.txt: -------------------------------------------------------------------------------- 1 | 9 2 | 11 3 | 16 4 | 21 5 | 22 6 | 26 7 | 27 8 | -------------------------------------------------------------------------------- /test/UnitTests/test4/criterion-inst.txt: -------------------------------------------------------------------------------- 1 | main 63 2 | main 65 3 | -------------------------------------------------------------------------------- /test/UnitTests/test4/criterion-loc.txt: -------------------------------------------------------------------------------- 1 | example.c 26 2 | example.c 27 3 | -------------------------------------------------------------------------------- /test/UnitTests/test4/example.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | int x, y, z; 8 | 9 | x = atoi(argv[1]); 10 | 11 | if (x < 0) 12 | { 13 | y = sqrt(x); 14 | z = pow(2, x); 15 | } else { 16 | if (x == 0) 17 | { 18 | y = sqrt(x * 2); 19 | z = pow(3, x); 20 | } else { 21 | y = sqrt(x * 3); 22 | z = pow(4, x); 23 | } 24 | } 25 | 26 | printf("%d\n", y); 27 | printf("%d\n", z); 28 | 29 | return y; 30 | } 31 | -------------------------------------------------------------------------------- /test/UnitTests/test5/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/UnitTests/test5/Makefile ------------------*- Makefile -*-===## 2 | 3 | NAME = hellothreads 4 | LDFLAGS = -pthread 5 | INPUT ?= 8 6 | 7 | include ../../Makefile.common 8 | -------------------------------------------------------------------------------- /test/UnitTests/test5/README.md: -------------------------------------------------------------------------------- 1 | The main thread simply create multiple threads, each of which say hello and 2 | return. The main thread reaps all the threads before return. 3 | -------------------------------------------------------------------------------- /test/UnitTests/test5/ans-inst.txt: -------------------------------------------------------------------------------- 1 | 23 2 | 28 3 | 29 4 | 30 5 | 32 6 | 34 7 | 35 8 | 39 9 | 40 10 | 41 11 | 45 12 | 46 13 | -------------------------------------------------------------------------------- /test/UnitTests/test5/hellothreads.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #define handle_error_en(en, msg) \ 8 | do { errno = en, perror(msg); exit(EXIT_FAILURE); } while (0) 9 | 10 | void *PrintHello(void *threadid) 11 | { 12 | long tid = *(long *)threadid; 13 | printf("[%ld] Hello thread %lu!\n", tid, pthread_self()); 14 | return NULL; 15 | } 16 | 17 | int main(int argc, char *argv[]) 18 | { 19 | long rc, t; 20 | pthread_t *threads; 21 | long *myid; 22 | 23 | if (argc < 2) { 24 | fprintf(stderr, "Usage: %s num_threads\n", argv[0]); 25 | return -1; 26 | } 27 | 28 | int num_threads = atoi(argv[1]); 29 | threads = (pthread_t *)calloc(num_threads, sizeof(pthread_t)); 30 | myid = (long *)calloc(num_threads, sizeof(long)); 31 | 32 | for(t = 0; t < num_threads; t++) { 33 | myid[t] = t; 34 | rc = pthread_create(&threads[t], NULL, PrintHello, &myid[t]); 35 | if (rc != 0) 36 | handle_error_en(rc, "ERROR creating threads\n"); 37 | } 38 | 39 | for(t = 0; t < num_threads; t++) { 40 | rc = pthread_join(threads[t], NULL); 41 | if (rc != 0) 42 | handle_error_en(rc, "ERROR reaping threads\n"); 43 | } 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /test/UnitTests/test6/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/UnitTests/test6/Makefile ------------------*- Makefile -*-===## 2 | 3 | NAME = sigusr1 4 | INPUT ?= 5 | 6 | include ../../Makefile.common 7 | -------------------------------------------------------------------------------- /test/UnitTests/test6/README.md: -------------------------------------------------------------------------------- 1 | The program catches the SIGUSR1 singnal sent by the shell whenever the user 2 | types `kill -10 PID` at the keyboard. 3 | 4 | This test is for correctly handling asynchronous events (e.g., signal handlers). 5 | -------------------------------------------------------------------------------- /test/UnitTests/test6/ans-inst.txt: -------------------------------------------------------------------------------- 1 | 21 2 | -------------------------------------------------------------------------------- /test/UnitTests/test6/sigusr1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | void handler(int sig) 9 | { 10 | printf("Caught SIGUSR1\n"); 11 | } 12 | 13 | int main() { 14 | printf("%d is running happily...\n", getpid()); 15 | 16 | if (signal(SIGUSR1, handler) == SIG_ERR) 17 | fprintf(stderr, "%s\n", strerror(errno)); 18 | 19 | pause(); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /test/UnitTests/test7/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/UnitTests/test7/Makefile ------------------*- Makefile -*-===## 2 | 3 | NAME = sigint 4 | INPUT ?= 5 | 6 | include ../../Makefile.common 7 | -------------------------------------------------------------------------------- /test/UnitTests/test7/README.md: -------------------------------------------------------------------------------- 1 | The program catches the SIGINT singnal sent by the shell whenever the user 2 | types `ctrl-c` at the keyboard. 3 | 4 | This test is for correctly handling asynchronous events (e.g., signal handlers). 5 | -------------------------------------------------------------------------------- /test/UnitTests/test7/ans-inst.txt: -------------------------------------------------------------------------------- 1 | 21 2 | -------------------------------------------------------------------------------- /test/UnitTests/test7/sigint.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | void handler(int sig) 9 | { 10 | printf("Caught SIGINT!\n"); 11 | } 12 | 13 | int main() { 14 | printf("%d is running happily...\n", getpid()); 15 | 16 | if (signal(SIGINT, handler) == SIG_ERR) 17 | fprintf(stderr, "%s\n", strerror(errno)); 18 | 19 | pause(); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /test/UnitTests/test8/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/UnitTests/test8/Makefile ------------------*- Makefile -*-===## 2 | 3 | NAME = ptr 4 | INPUT ?= 40 54 5 | 6 | include ../../Makefile.common 7 | -------------------------------------------------------------------------------- /test/UnitTests/test8/README.md: -------------------------------------------------------------------------------- 1 | This is a simple swap() function for the pointer test. 2 | -------------------------------------------------------------------------------- /test/UnitTests/test8/ans-inst.txt: -------------------------------------------------------------------------------- 1 | 6 2 | 12 3 | 18 4 | 24 5 | -------------------------------------------------------------------------------- /test/UnitTests/test8/ptr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void swap(int *a, int *b) { 5 | int tmp = *a; 6 | *a = *b; 7 | *b = tmp; 8 | } 9 | 10 | int main(int argc, char *argv[]) { 11 | int a, b; 12 | if (argc < 2) { 13 | fprintf(stderr, "Usage: %s int1 int2", argv[0]); 14 | exit(EXIT_FAILURE); 15 | } 16 | 17 | a = atoi(argv[1]); 18 | b = atoi(argv[2]); 19 | 20 | if (a < b) 21 | swap(&a, &b); 22 | 23 | // return the maxium one 24 | return a; 25 | } 26 | -------------------------------------------------------------------------------- /test/UnitTests/test9/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/UnitTests/test9/Makefile ------------------*- Makefile -*-===## 2 | 3 | NAME = forloop 4 | INPUT ?= 6 19 7 17 32 35 40 54 302 5 | 6 | include ../../Makefile.common 7 | -------------------------------------------------------------------------------- /test/UnitTests/test9/README.md: -------------------------------------------------------------------------------- 1 | This is a simple for loop. 2 | -------------------------------------------------------------------------------- /test/UnitTests/test9/ans-inst.txt: -------------------------------------------------------------------------------- 1 | 9 2 | 14 3 | 15 4 | 20 5 | 25 6 | -------------------------------------------------------------------------------- /test/UnitTests/test9/forloop.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) { 6 | int i; 7 | int sum, min = INT_MAX, max = INT_MIN; 8 | 9 | if (argc < 2) { 10 | fprintf(stderr, "Usage: %s int1 int2 int3 ...", argv[0]); 11 | exit(EXIT_FAILURE); 12 | } 13 | 14 | for (i = 1; i < argc; i++) { 15 | int t = atoi(argv[i]); 16 | if (t > max) 17 | max = t; 18 | if (t < min) 19 | min = t; 20 | sum += t; 21 | } 22 | 23 | printf("The min is %d, and the max is %d\n", min, max); 24 | 25 | return sum; 26 | } 27 | -------------------------------------------------------------------------------- /test/auto-tests.txt: -------------------------------------------------------------------------------- 1 | UnitTests/test1 2 | UnitTests/test2 3 | UnitTests/test3 4 | UnitTests/test4 5 | UnitTests/test5 6 | UnitTests/test8 7 | UnitTests/test9 8 | UnitTests/test10 9 | UnitTests/test11 10 | UnitTests/test12 11 | UnitTests/test13 12 | UnitTests/test14 13 | UnitTests/test15 14 | UnitTests/test16 15 | UnitTests/test17 16 | UnitTests/test18 17 | UnitTests/test19 18 | UnitTests/test20 19 | UnitTests/test21 20 | matrix_multiply 21 | pca 22 | kmeans 23 | -------------------------------------------------------------------------------- /test/histogram/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/histogram/Makefile -----------------*- Makefile -*-===## 2 | 3 | ifeq (pthread,$(TEST_PARALLELISM)) 4 | NAME = histogram-pthread 5 | LDFLAGS = -lpthread 6 | else 7 | NAME = histogram-seq 8 | TEST_PARALLELISM = seq 9 | endif 10 | 11 | GIRI_DIR = ../../build/ 12 | SRC_FILES = $(NAME).c 13 | CRITERION ?= "-criterion-loc=loc-$(TEST_PARALLELISM).txt" 14 | #CRITERION ?= "-criterion-inst=inst-$(TEST_PARALLELISM).txt" 15 | INPUT ?= 16 16 | 17 | include ../Makefile.common 18 | -------------------------------------------------------------------------------- /test/histogram/README.md: -------------------------------------------------------------------------------- 1 | This test program is from Phoenix Project 2 | Historgram Example Application Readme 3 | 4 | Application Overview 5 | ----------------------- 6 | 7 | The Histogram application generates the histogram of frequencies of pixel values in the red, green, and blue channels of a bitmap picture. 8 | 9 | 10 | Running the Application 11 | -------------------------- 12 | 13 | Please modify the `Makefile` first to set the proper variables before every run. 14 | 15 | How to Download the Data Input 16 | ------------------------------ 17 | 18 | We don't provide the data set because of its large size. You can download it from the [official site](http://mapreduce.stanford.edu/datafiles/histogram.tar.gz) of Phoenix. 19 | -------------------------------------------------------------------------------- /test/histogram/histogram-seq.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2009, Stanford University 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * * Neither the name of Stanford University nor the names of its 12 | * contributors may be used to endorse or promote products derived from 13 | * this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include "stddefines.h" 40 | 41 | #define IMG_DATA_OFFSET_POS 10 42 | #define BITS_PER_PIXEL_POS 28 43 | 44 | int swap; // to indicate if we need to swap byte order of header information 45 | 46 | 47 | /* test_endianess 48 | * 49 | */ 50 | void test_endianess() { 51 | unsigned int num = 0x12345678; 52 | char *low = (char *)(&(num)); 53 | if (*low == 0x78) { 54 | dprintf("No need to swap\n"); 55 | swap = 0; 56 | } 57 | else if (*low == 0x12) { 58 | dprintf("Need to swap\n"); 59 | swap = 1; 60 | } 61 | else { 62 | printf("Error: Invalid value found in memory\n"); 63 | exit(1); 64 | } 65 | } 66 | 67 | /* swap_bytes 68 | * 69 | */ 70 | void swap_bytes(char *bytes, int num_bytes) { 71 | int i; 72 | char tmp; 73 | 74 | for (i = 0; i < num_bytes/2; i++) { 75 | dprintf("Swapping %d and %d\n", bytes[i], bytes[num_bytes - i - 1]); 76 | tmp = bytes[i]; 77 | bytes[i] = bytes[num_bytes - i - 1]; 78 | bytes[num_bytes - i - 1] = tmp; 79 | } 80 | } 81 | 82 | int main(int argc, char *argv[]) { 83 | 84 | int i; 85 | int fd; 86 | char *fdata; 87 | struct stat finfo; 88 | char * fname; 89 | int red[256]; 90 | int green[256]; 91 | int blue[256]; 92 | 93 | 94 | // Make sure a filename is specified 95 | if (argv[1] == NULL) { 96 | printf("USAGE: %s \n", argv[0]); 97 | exit(1); 98 | } 99 | 100 | fname = argv[1]; 101 | 102 | // Read in the file 103 | CHECK_ERROR((fd = open(fname, O_RDONLY)) < 0); 104 | // Get the file info (for file length) 105 | CHECK_ERROR(fstat(fd, &finfo) < 0); 106 | // Memory map the file 107 | CHECK_ERROR((fdata = mmap(0, finfo.st_size + 1, 108 | PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0)) == NULL); 109 | 110 | if ((fdata[0] != 'B') || (fdata[1] != 'M')) { 111 | printf("File is not a valid bitmap file. Exiting\n"); 112 | exit(1); 113 | } 114 | 115 | test_endianess(); // will set the variable "swap" 116 | 117 | unsigned short *bitsperpixel = (unsigned short *)(&(fdata[BITS_PER_PIXEL_POS])); 118 | if (swap) { 119 | swap_bytes((char *)(bitsperpixel), sizeof(*bitsperpixel)); 120 | } 121 | if (*bitsperpixel != 24) { // ensure its 3 bytes per pixel 122 | printf("Error: Invalid bitmap format - "); 123 | printf("This application only accepts 24-bit pictures. Exiting\n"); 124 | exit(1); 125 | } 126 | 127 | unsigned short *data_pos = (unsigned short *)(&(fdata[IMG_DATA_OFFSET_POS])); 128 | if (swap) { 129 | swap_bytes((char *)(data_pos), sizeof(*data_pos)); 130 | } 131 | 132 | int imgdata_bytes = (int)finfo.st_size - (int)(*(data_pos)); 133 | printf("This file has %d bytes of image data, %d pixels\n", imgdata_bytes, 134 | imgdata_bytes / 3); 135 | 136 | printf("Starting sequential histogram\n"); 137 | 138 | 139 | memset(&(red[0]), 0, sizeof(int) * 256); 140 | memset(&(green[0]), 0, sizeof(int) * 256); 141 | memset(&(blue[0]), 0, sizeof(int) * 256); 142 | 143 | for (i=*data_pos; i < finfo.st_size; i+=3) { 144 | unsigned char *val = (unsigned char *)&(fdata[i]); 145 | blue[*val]++; 146 | 147 | val = (unsigned char *)&(fdata[i+1]); 148 | green[*val]++; 149 | 150 | val = (unsigned char *)&(fdata[i+2]); 151 | red[*val]++; 152 | } 153 | 154 | dprintf("\n\nBlue\n"); 155 | dprintf("----------\n\n"); 156 | for (i = 0; i < 256; i++) { 157 | dprintf("%d - %d\n", i, blue[i]); 158 | } 159 | 160 | dprintf("\n\nGreen\n"); 161 | dprintf("----------\n\n"); 162 | for (i = 0; i < 256; i++) { 163 | dprintf("%d - %d\n", i, green[i]); 164 | } 165 | 166 | dprintf("\n\nRed\n"); 167 | dprintf("----------\n\n"); 168 | for (i = 0; i < 256; i++) { 169 | dprintf("%d - %d\n", i, red[i]); 170 | } 171 | 172 | CHECK_ERROR(munmap(fdata, finfo.st_size + 1) < 0); 173 | CHECK_ERROR(close(fd) < 0); 174 | 175 | return 0; 176 | } 177 | -------------------------------------------------------------------------------- /test/histogram/loc-pthread.txt: -------------------------------------------------------------------------------- 1 | histogram-pthread.c 259 2 | -------------------------------------------------------------------------------- /test/histogram/stddefines.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2009, Stanford University 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * * Neither the name of Stanford University nor the 12 | * names of its contributors may be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef STDDEFINES_H_ 28 | #define STDDEFINES_H_ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | //#define TIMING 37 | 38 | /* Debug printf */ 39 | #define dprintf(...) fprintf(stdout, __VA_ARGS__) 40 | 41 | /* Wrapper to check for errors */ 42 | #define CHECK_ERROR(a) \ 43 | if (a) \ 44 | { \ 45 | perror("Error at line\n\t" #a "\nSystem Msg"); \ 46 | assert ((a) == 0); \ 47 | } 48 | 49 | static inline void *MALLOC(size_t size) 50 | { 51 | void * temp = malloc(size); 52 | assert(temp); 53 | return temp; 54 | } 55 | 56 | static inline void *CALLOC(size_t num, size_t size) 57 | { 58 | void * temp = calloc(num, size); 59 | assert(temp); 60 | return temp; 61 | } 62 | 63 | static inline void *REALLOC(void *ptr, size_t size) 64 | { 65 | void * temp = realloc(ptr, size); 66 | assert(temp); 67 | return temp; 68 | } 69 | 70 | static inline char *GETENV(char *envstr) 71 | { 72 | char *env = getenv(envstr); 73 | if (!env) return "0"; 74 | else return env; 75 | } 76 | 77 | #define GET_TIME(start, end, duration) \ 78 | duration.tv_sec = (end.tv_sec - start.tv_sec); \ 79 | if (end.tv_nsec >= start.tv_nsec) { \ 80 | duration.tv_nsec = (end.tv_nsec - start.tv_nsec); \ 81 | } \ 82 | else { \ 83 | duration.tv_nsec = (1000000000L - (start.tv_nsec - end.tv_nsec)); \ 84 | duration.tv_sec--; \ 85 | } \ 86 | if (duration.tv_nsec >= 1000000000L) { \ 87 | duration.tv_sec++; \ 88 | duration.tv_nsec -= 1000000000L; \ 89 | } 90 | 91 | static inline unsigned int time_diff ( 92 | struct timeval *end, struct timeval *begin) 93 | { 94 | #ifdef TIMING 95 | uint64_t result; 96 | 97 | result = end->tv_sec - begin->tv_sec; 98 | result *= 1000000; /* usec */ 99 | result += end->tv_usec - begin->tv_usec; 100 | 101 | return result; 102 | #else 103 | return 0; 104 | #endif 105 | } 106 | 107 | static inline void get_time (struct timeval *t) 108 | { 109 | #ifdef TIMING 110 | gettimeofday (t, NULL); 111 | #endif 112 | } 113 | 114 | #endif // STDDEFINES_H_ 115 | -------------------------------------------------------------------------------- /test/kmeans/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/kmeans/Makefile ---------------------------*- Makefile -*-===## 2 | 3 | TEST_PARALLELISM ?= pthread 4 | CRITERION_TYPE ?= inst 5 | DEBUGFLAGS ?= -debug 6 | INPUT ?= 16 7 | 8 | ###### Don't modify the following unless you know exactly what you'r doing ##### 9 | ifeq (pthread,$(TEST_PARALLELISM)) 10 | NAME = kmeans-pthread 11 | LDFLAGS = -lpthread 12 | else 13 | NAME = kmeans-seq 14 | TEST_PARALLELISM = seq 15 | endif 16 | 17 | GIRI_DIR = ../../build/ 18 | SRC_FILES = $(NAME).c 19 | CRITERION = "-criterion-$(CRITERION_TYPE)=criterion-$(CRITERION_TYPE)-$(TEST_PARALLELISM).txt" 20 | TEST_ANS = ans-$(CRITERION_TYPE)-$(TEST_PARALLELISM).txt 21 | 22 | include ../Makefile.common 23 | -------------------------------------------------------------------------------- /test/kmeans/README.md: -------------------------------------------------------------------------------- 1 | This is the matrix multiply program in the Phoenix software (version 2.0.0) from Stanford University. 2 | 3 | We use the pthread version of the code, with very trivial modifications. 4 | -------------------------------------------------------------------------------- /test/kmeans/ans-inst-pthread.txt: -------------------------------------------------------------------------------- 1 | 81 2 | 92 3 | 93 4 | 94 5 | 95 6 | 136 7 | 138 8 | 140 9 | 152 10 | 153 11 | 155 12 | 157 13 | 167 14 | 169 15 | 178 16 | 182 17 | 183 18 | 185 19 | 187 20 | 188 21 | 189 22 | 191 23 | 192 24 | 194 25 | 195 26 | 199 27 | 201 28 | 202 29 | 216 30 | 217 31 | 218 32 | 220 33 | 222 34 | 224 35 | 225 36 | 227 37 | 229 38 | 231 39 | 232 40 | 236 41 | 239 42 | 241 43 | 261 44 | 262 45 | 264 46 | 267 47 | 269 48 | 270 49 | 272 50 | 275 51 | 277 52 | 278 53 | 283 54 | 285 55 | 287 56 | 294 57 | 296 58 | 297 59 | 298 60 | 300 61 | 301 62 | 303 63 | 304 64 | 305 65 | 306 66 | 307 67 | 308 68 | 309 69 | 311 70 | 313 71 | 316 72 | 321 73 | 322 74 | 323 75 | 324 76 | 325 77 | 326 78 | 327 79 | 328 80 | 329 81 | 330 82 | 331 83 | 332 84 | 334 85 | 336 86 | 339 87 | 348 88 | -------------------------------------------------------------------------------- /test/kmeans/ans-inst-seq.txt: -------------------------------------------------------------------------------- 1 | 222 2 | 276 3 | -------------------------------------------------------------------------------- /test/kmeans/ans-loc-pthread.txt: -------------------------------------------------------------------------------- 1 | 81 2 | 348 3 | -------------------------------------------------------------------------------- /test/kmeans/ans-loc-seq.txt: -------------------------------------------------------------------------------- 1 | 222 2 | 276 3 | -------------------------------------------------------------------------------- /test/kmeans/criterion-inst-pthread.txt: -------------------------------------------------------------------------------- 1 | main 402 2 | -------------------------------------------------------------------------------- /test/kmeans/criterion-inst-seq.txt: -------------------------------------------------------------------------------- 1 | main 120 2 | -------------------------------------------------------------------------------- /test/kmeans/criterion-loc-pthread.txt: -------------------------------------------------------------------------------- 1 | kmeans-pthread.c 348 2 | -------------------------------------------------------------------------------- /test/kmeans/criterion-loc-seq.txt: -------------------------------------------------------------------------------- 1 | kmeans-seq.c 276 2 | -------------------------------------------------------------------------------- /test/kmeans/stddefines.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2009, Stanford University 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * * Neither the name of Stanford University nor the 12 | * names of its contributors may be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef STDDEFINES_H_ 28 | #define STDDEFINES_H_ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | //#define TIMING 37 | 38 | /* Debug printf */ 39 | #define dprintf(...) fprintf(stdout, __VA_ARGS__) 40 | 41 | /* Wrapper to check for errors */ 42 | #define CHECK_ERROR(a) \ 43 | if (a) \ 44 | { \ 45 | perror("Error at line\n\t" #a "\nSystem Msg"); \ 46 | assert ((a) == 0); \ 47 | } 48 | 49 | static inline void *MALLOC(size_t size) 50 | { 51 | void * temp = malloc(size); 52 | assert(temp); 53 | return temp; 54 | } 55 | 56 | static inline void *CALLOC(size_t num, size_t size) 57 | { 58 | void * temp = calloc(num, size); 59 | assert(temp); 60 | return temp; 61 | } 62 | 63 | static inline void *REALLOC(void *ptr, size_t size) 64 | { 65 | void * temp = realloc(ptr, size); 66 | assert(temp); 67 | return temp; 68 | } 69 | 70 | static inline char *GETENV(char *envstr) 71 | { 72 | char *env = getenv(envstr); 73 | if (!env) return "0"; 74 | else return env; 75 | } 76 | 77 | #define GET_TIME(start, end, duration) \ 78 | duration.tv_sec = (end.tv_sec - start.tv_sec); \ 79 | if (end.tv_nsec >= start.tv_nsec) { \ 80 | duration.tv_nsec = (end.tv_nsec - start.tv_nsec); \ 81 | } \ 82 | else { \ 83 | duration.tv_nsec = (1000000000L - (start.tv_nsec - end.tv_nsec)); \ 84 | duration.tv_sec--; \ 85 | } \ 86 | if (duration.tv_nsec >= 1000000000L) { \ 87 | duration.tv_sec++; \ 88 | duration.tv_nsec -= 1000000000L; \ 89 | } 90 | 91 | static inline unsigned int time_diff ( 92 | struct timeval *end, struct timeval *begin) 93 | { 94 | #ifdef TIMING 95 | uint64_t result; 96 | 97 | result = end->tv_sec - begin->tv_sec; 98 | result *= 1000000; /* usec */ 99 | result += end->tv_usec - begin->tv_usec; 100 | 101 | return result; 102 | #else 103 | return 0; 104 | #endif 105 | } 106 | 107 | static inline void get_time (struct timeval *t) 108 | { 109 | #ifdef TIMING 110 | gettimeofday (t, NULL); 111 | #endif 112 | } 113 | 114 | #endif // STDDEFINES_H_ 115 | -------------------------------------------------------------------------------- /test/linear_regression/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/linear_regression/Makefile -----------------*- Makefile -*-===## 2 | 3 | TEST_PARALLELISM ?= pthread 4 | CRITERION ?= "-criterion-loc=loc-$(TEST_PARALLELISM).txt" 5 | #CRITERION ?= "-criterion-inst=inst-$(TEST_PARALLELISM).txt" 6 | DEBUGFLAGS ?= -debug 7 | INPUT ?= 4 8 | 9 | ###### Don't modify the following unless you know exactly what you'r doing ##### 10 | ifeq (pthread,$(TEST_PARALLELISM)) 11 | NAME = linear_regression-pthread 12 | LDFLAGS = -lpthread 13 | else 14 | NAME = linear_regression-seq 15 | TEST_PARALLELISM = seq 16 | endif 17 | 18 | GIRI_DIR = ../../build/ 19 | SRC_FILES = $(NAME).c 20 | 21 | include ../Makefile.common 22 | 23 | clean-all: 24 | @ rm -f matrix_file_out_*.txt 25 | -------------------------------------------------------------------------------- /test/linear_regression/README.md: -------------------------------------------------------------------------------- 1 | This test program is from Phoenix Project 2 | Linear Regression Example Application Readme 3 | 4 | Application Overview 5 | ----------------------- 6 | 7 | The Linear Regression application generates the summary statistics of points to give the linear approximation of all the points. It reads the x-y coordinates sequentially from the specified file. 8 | 9 | Running the Application 10 | -------------------------- 11 | 12 | Please modify the `Makefile` first to set the proper variables before every run. 13 | 14 | How to Download the Data Input 15 | ------------------------------ 16 | 17 | We don't provide the data set because of its large size. You can download it from the [official site](http://mapreduce.stanford.edu/datafiles/linear_regression.tar.gz) of Phoenix. 18 | -------------------------------------------------------------------------------- /test/linear_regression/linear_regression-seq.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2009, Stanford University 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * * Neither the name of Stanford University nor the names of its 12 | * contributors may be used to endorse or promote products derived from 13 | * this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include "stddefines.h" 40 | 41 | 42 | typedef struct { 43 | char x; 44 | char y; 45 | } POINT_T; 46 | 47 | int main(int argc, char *argv[]) { 48 | 49 | int fd; 50 | char * fdata; 51 | char * fname; 52 | struct stat finfo; 53 | long i; 54 | 55 | 56 | // Make sure a filename is specified 57 | if (argv[1] == NULL) 58 | { 59 | printf("USAGE: %s \n", argv[0]); 60 | exit(1); 61 | } 62 | 63 | fname = argv[1]; 64 | 65 | printf("Linear Regression Serial: Running...\n"); 66 | 67 | // Read in the file 68 | CHECK_ERROR((fd = open(fname, O_RDONLY)) < 0); 69 | // Get the file info (for file length) 70 | CHECK_ERROR(fstat(fd, &finfo) < 0); 71 | // Memory map the file 72 | CHECK_ERROR((fdata = mmap(0, finfo.st_size + 1, 73 | PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0)) == NULL); 74 | 75 | 76 | POINT_T *points = (POINT_T*)fdata; 77 | long long n = (long long) finfo.st_size / sizeof(POINT_T); 78 | long long SX_ll = 0, SY_ll = 0, SXX_ll = 0, SYY_ll = 0, SXY_ll = 0; 79 | 80 | // ADD UP RESULTS 81 | for (i = 0; i < n; i++) 82 | { 83 | //Compute SX, SY, SYY, SXX, SXY 84 | SX_ll += points[i].x; 85 | SXX_ll += points[i].x*points[i].x; 86 | SY_ll += points[i].y; 87 | SYY_ll += points[i].y*points[i].y; 88 | SXY_ll += points[i].x*points[i].y; 89 | } 90 | 91 | double a, b, xbar, ybar, r2; 92 | double SX = (double)SX_ll; 93 | double SY = (double)SY_ll; 94 | double SXX= (double)SXX_ll; 95 | double SYY= (double)SYY_ll; 96 | double SXY= (double)SXY_ll; 97 | 98 | b = (double)(n*SXY - SX*SY) / (n*SXX - SX*SX); 99 | a = (SY_ll - b*SX_ll) / n; 100 | xbar = (double)SX_ll / n; 101 | ybar = (double)SY_ll / n; 102 | r2 = (double)(n*SXY - SX*SY) * (n*SXY - SX*SY) / ((n*SXX - SX*SX)*(n*SYY - SY*SY)); 103 | 104 | 105 | printf("Linear Regression Serial Results:\n"); 106 | printf("\ta = %lf\n", a); 107 | printf("\tb = %lf\n", b); 108 | printf("\txbar = %lf\n", xbar); 109 | printf("\tybar = %lf\n", ybar); 110 | printf("\tr2 = %lf\n", r2); 111 | printf("\tSX = %lld\n", SX_ll); 112 | printf("\tSY = %lld\n", SY_ll); 113 | printf("\tSXX = %lld\n", SXX_ll); 114 | printf("\tSYY = %lld\n", SYY_ll); 115 | printf("\tSXY = %lld\n", SXY_ll); 116 | 117 | CHECK_ERROR(munmap(fdata, finfo.st_size + 1) < 0); 118 | CHECK_ERROR(close(fd) < 0); 119 | 120 | return 0; 121 | } 122 | 123 | 124 | -------------------------------------------------------------------------------- /test/linear_regression/loc-pthread.txt: -------------------------------------------------------------------------------- 1 | linear_regression-pthread.c 182 2 | -------------------------------------------------------------------------------- /test/linear_regression/stddefines.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2009, Stanford University 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * * Neither the name of Stanford University nor the 12 | * names of its contributors may be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef STDDEFINES_H_ 28 | #define STDDEFINES_H_ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | //#define TIMING 37 | 38 | /* Debug printf */ 39 | #define dprintf(...) fprintf(stdout, __VA_ARGS__) 40 | 41 | /* Wrapper to check for errors */ 42 | #define CHECK_ERROR(a) \ 43 | if (a) \ 44 | { \ 45 | perror("Error at line\n\t" #a "\nSystem Msg"); \ 46 | assert ((a) == 0); \ 47 | } 48 | 49 | static inline void *MALLOC(size_t size) 50 | { 51 | void * temp = malloc(size); 52 | assert(temp); 53 | return temp; 54 | } 55 | 56 | static inline void *CALLOC(size_t num, size_t size) 57 | { 58 | void * temp = calloc(num, size); 59 | assert(temp); 60 | return temp; 61 | } 62 | 63 | static inline void *REALLOC(void *ptr, size_t size) 64 | { 65 | void * temp = realloc(ptr, size); 66 | assert(temp); 67 | return temp; 68 | } 69 | 70 | static inline char *GETENV(char *envstr) 71 | { 72 | char *env = getenv(envstr); 73 | if (!env) return "0"; 74 | else return env; 75 | } 76 | 77 | #define GET_TIME(start, end, duration) \ 78 | duration.tv_sec = (end.tv_sec - start.tv_sec); \ 79 | if (end.tv_nsec >= start.tv_nsec) { \ 80 | duration.tv_nsec = (end.tv_nsec - start.tv_nsec); \ 81 | } \ 82 | else { \ 83 | duration.tv_nsec = (1000000000L - (start.tv_nsec - end.tv_nsec)); \ 84 | duration.tv_sec--; \ 85 | } \ 86 | if (duration.tv_nsec >= 1000000000L) { \ 87 | duration.tv_sec++; \ 88 | duration.tv_nsec -= 1000000000L; \ 89 | } 90 | 91 | static inline unsigned int time_diff ( 92 | struct timeval *end, struct timeval *begin) 93 | { 94 | #ifdef TIMING 95 | uint64_t result; 96 | 97 | result = end->tv_sec - begin->tv_sec; 98 | result *= 1000000; /* usec */ 99 | result += end->tv_usec - begin->tv_usec; 100 | 101 | return result; 102 | #else 103 | return 0; 104 | #endif 105 | } 106 | 107 | static inline void get_time (struct timeval *t) 108 | { 109 | #ifdef TIMING 110 | gettimeofday (t, NULL); 111 | #endif 112 | } 113 | 114 | #endif // STDDEFINES_H_ 115 | -------------------------------------------------------------------------------- /test/matrix_multiply/.gitignore: -------------------------------------------------------------------------------- 1 | matrix_file_out_*.txt 2 | -------------------------------------------------------------------------------- /test/matrix_multiply/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/matrix_multiply/Makefile -----------------*- Makefile -*-===## 2 | 3 | TEST_PARALLELISM ?= pthread 4 | CRITERION_TYPE ?= inst 5 | DEBUGFLAGS ?= -debug 6 | INPUT ?= 4 7 | 8 | ###### Don't modify the following unless you know exactly what you'r doing ##### 9 | ifeq (pthread,$(TEST_PARALLELISM)) 10 | NAME = matrix_multiply-pthread 11 | LDFLAGS = -lpthread 12 | else 13 | NAME = matrix_multiply-seq 14 | TEST_PARALLELISM = seq 15 | endif 16 | 17 | GIRI_DIR = ../../build/ 18 | SRC_FILES = $(NAME).c 19 | CRITERION = "-criterion-$(CRITERION_TYPE)=criterion-$(CRITERION_TYPE)-$(TEST_PARALLELISM).txt" 20 | TEST_ANS = ans-$(CRITERION_TYPE)-$(TEST_PARALLELISM).txt 21 | 22 | include ../Makefile.common 23 | 24 | clean-all: 25 | @ rm -f matrix_file_out_*.txt 26 | -------------------------------------------------------------------------------- /test/matrix_multiply/README.md: -------------------------------------------------------------------------------- 1 | This is the matrix multiply program in the Phoenix software (version 2.0.0) from Stanford University. 2 | 3 | We use the pthread version of the code, with very trivial modifications. 4 | -------------------------------------------------------------------------------- /test/matrix_multiply/ans-inst-pthread.txt: -------------------------------------------------------------------------------- 1 | 51 2 | 52 3 | 53 4 | 69 5 | 72 6 | 75 7 | 76 8 | 77 9 | 78 10 | 79 11 | 84 12 | 89 13 | 92 14 | 94 15 | 95 16 | 96 17 | 98 18 | 99 19 | 100 20 | 102 21 | 103 22 | 105 23 | 109 24 | 127 25 | 129 26 | 133 27 | 135 28 | 136 29 | 138 30 | 140 31 | 142 32 | 144 33 | 145 34 | 147 35 | 149 36 | 150 37 | 152 38 | 155 39 | 179 40 | 185 41 | 186 42 | 187 43 | 188 44 | 189 45 | 193 46 | 196 47 | 201 48 | 204 49 | 240 50 | 242 51 | 245 52 | 249 53 | 251 54 | 253 55 | 258 56 | 261 57 | 263 58 | 265 59 | 266 60 | 272 61 | -------------------------------------------------------------------------------- /test/matrix_multiply/ans-inst-seq.txt: -------------------------------------------------------------------------------- 1 | 56 2 | 90 3 | 97 4 | 113 5 | 119 6 | 120 7 | 121 8 | 122 9 | 123 10 | 129 11 | 131 12 | 133 13 | 137 14 | 139 15 | 141 16 | 145 17 | 147 18 | 149 19 | 154 20 | -------------------------------------------------------------------------------- /test/matrix_multiply/ans-loc-pthread.txt: -------------------------------------------------------------------------------- 1 | 51 2 | 52 3 | 53 4 | 69 5 | 72 6 | 75 7 | 76 8 | 77 9 | 78 10 | 79 11 | 84 12 | 89 13 | 92 14 | 94 15 | 95 16 | 96 17 | 98 18 | 99 19 | 100 20 | 102 21 | 103 22 | 105 23 | 109 24 | 127 25 | 129 26 | 133 27 | 135 28 | 136 29 | 138 30 | 140 31 | 142 32 | 144 33 | 145 34 | 147 35 | 149 36 | 150 37 | 152 38 | 155 39 | 179 40 | 185 41 | 186 42 | 187 43 | 188 44 | 189 45 | 193 46 | 196 47 | 201 48 | 204 49 | 240 50 | 242 51 | 245 52 | 249 53 | 251 54 | 253 55 | 258 56 | 261 57 | 263 58 | 265 59 | 266 60 | 272 61 | -------------------------------------------------------------------------------- /test/matrix_multiply/ans-loc-seq.txt: -------------------------------------------------------------------------------- 1 | 2 | 56 3 | 75 4 | 76 5 | 77 6 | 79 7 | 80 8 | 81 9 | 82 10 | 84 11 | 90 12 | 92 13 | 94 14 | 113 15 | 119 16 | 120 17 | 121 18 | 122 19 | 123 20 | 129 21 | 131 22 | 133 23 | 137 24 | 139 25 | 141 26 | 145 27 | 147 28 | 149 29 | 154 30 | 155 31 | 156 32 | 157 33 | 165 34 | -------------------------------------------------------------------------------- /test/matrix_multiply/criterion-inst-pthread.txt: -------------------------------------------------------------------------------- 1 | matrixmult_map 138 2 | -------------------------------------------------------------------------------- /test/matrix_multiply/criterion-inst-seq.txt: -------------------------------------------------------------------------------- 1 | matrix_mult 285 2 | -------------------------------------------------------------------------------- /test/matrix_multiply/criterion-loc-pthread.txt: -------------------------------------------------------------------------------- 1 | matrix_multiply-pthread.c 155 2 | -------------------------------------------------------------------------------- /test/matrix_multiply/criterion-loc-seq.txt: -------------------------------------------------------------------------------- 1 | matrix_multiply-seq.c 94 2 | -------------------------------------------------------------------------------- /test/matrix_multiply/matrix_file_A.txt: -------------------------------------------------------------------------------- 1 |   -------------------------------------------------------------------------------- /test/matrix_multiply/matrix_file_B.txt: -------------------------------------------------------------------------------- 1 |  2 |   -------------------------------------------------------------------------------- /test/matrix_multiply/stddefines.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2009, Stanford University 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * * Neither the name of Stanford University nor the 12 | * names of its contributors may be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef STDDEFINES_H_ 28 | #define STDDEFINES_H_ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | //#define TIMING 37 | 38 | /* Debug printf */ 39 | #define dprintf(...) fprintf(stdout, __VA_ARGS__) 40 | 41 | /* Wrapper to check for errors */ 42 | #define CHECK_ERROR(a) \ 43 | if (a) \ 44 | { \ 45 | perror("Error at line\n\t" #a "\nSystem Msg"); \ 46 | assert ((a) == 0); \ 47 | } 48 | 49 | static inline void *MALLOC(size_t size) 50 | { 51 | void * temp = malloc(size); 52 | assert(temp); 53 | return temp; 54 | } 55 | 56 | static inline void *CALLOC(size_t num, size_t size) 57 | { 58 | void * temp = calloc(num, size); 59 | assert(temp); 60 | return temp; 61 | } 62 | 63 | static inline void *REALLOC(void *ptr, size_t size) 64 | { 65 | void * temp = realloc(ptr, size); 66 | assert(temp); 67 | return temp; 68 | } 69 | 70 | static inline char *GETENV(char *envstr) 71 | { 72 | char *env = getenv(envstr); 73 | if (!env) return "0"; 74 | else return env; 75 | } 76 | 77 | #define GET_TIME(start, end, duration) \ 78 | duration.tv_sec = (end.tv_sec - start.tv_sec); \ 79 | if (end.tv_nsec >= start.tv_nsec) { \ 80 | duration.tv_nsec = (end.tv_nsec - start.tv_nsec); \ 81 | } \ 82 | else { \ 83 | duration.tv_nsec = (1000000000L - (start.tv_nsec - end.tv_nsec)); \ 84 | duration.tv_sec--; \ 85 | } \ 86 | if (duration.tv_nsec >= 1000000000L) { \ 87 | duration.tv_sec++; \ 88 | duration.tv_nsec -= 1000000000L; \ 89 | } 90 | 91 | static inline unsigned int time_diff ( 92 | struct timeval *end, struct timeval *begin) 93 | { 94 | #ifdef TIMING 95 | uint64_t result; 96 | 97 | result = end->tv_sec - begin->tv_sec; 98 | result *= 1000000; /* usec */ 99 | result += end->tv_usec - begin->tv_usec; 100 | 101 | return result; 102 | #else 103 | return 0; 104 | #endif 105 | } 106 | 107 | static inline void get_time (struct timeval *t) 108 | { 109 | #ifdef TIMING 110 | gettimeofday (t, NULL); 111 | #endif 112 | } 113 | 114 | #endif // STDDEFINES_H_ 115 | -------------------------------------------------------------------------------- /test/pca/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/pca/Makefile -----------------*- Makefile -*-===## 2 | 3 | TEST_PARALLELISM ?= pthread 4 | CRITERION_TYPE ?= inst 5 | DEBUGFLAGS ?= -debug 6 | INPUT ?= 16 7 | 8 | ###### Don't modify the following unless you know exactly what you'r doing ##### 9 | ifeq (pthread,$(TEST_PARALLELISM)) 10 | NAME = pca-pthread 11 | LDFLAGS = -lpthread 12 | else 13 | NAME = pca-seq 14 | TEST_PARALLELISM = seq 15 | endif 16 | 17 | GIRI_DIR = ../../build/ 18 | SRC_FILES = $(NAME).c 19 | CRITERION = "-criterion-$(CRITERION_TYPE)=criterion-$(CRITERION_TYPE)-$(TEST_PARALLELISM).txt" 20 | TEST_ANS = ans-$(CRITERION_TYPE)-$(TEST_PARALLELISM).txt 21 | 22 | include ../Makefile.common 23 | -------------------------------------------------------------------------------- /test/pca/README.md: -------------------------------------------------------------------------------- 1 | The PCA application computes the mean vector and covariance matrix for a randomly generated matrix, which is the first step in performing principal component analysis. 2 | 3 | This is the test rogram in the Phoenix software (version 2.0.0) from Stanford University. We use the pthread version of the code, with very trivial modifications. 4 | -------------------------------------------------------------------------------- /test/pca/ans-inst-pthread.txt: -------------------------------------------------------------------------------- 1 | 51 2 | 52 3 | 53 4 | 69 5 | 70 6 | 71 7 | 125 8 | 127 9 | 129 10 | 140 11 | 142 12 | 143 13 | 144 14 | 145 15 | 147 16 | 193 17 | 196 18 | 197 19 | 203 20 | 204 21 | 205 22 | 208 23 | 209 24 | 210 25 | 211 26 | 212 27 | 213 28 | 215 29 | 216 30 | 265 31 | 266 32 | 268 33 | 271 34 | 277 35 | -------------------------------------------------------------------------------- /test/pca/ans-inst-seq.txt: -------------------------------------------------------------------------------- 1 | 55 2 | 56 3 | 57 4 | 111 5 | 113 6 | 115 7 | 127 8 | 128 9 | 129 10 | 130 11 | 132 12 | 164 13 | 165 14 | 167 15 | 171 16 | 177 17 | 185 18 | -------------------------------------------------------------------------------- /test/pca/ans-loc-pthread.txt: -------------------------------------------------------------------------------- 1 | 51 2 | 52 3 | 53 4 | 69 5 | 70 6 | 71 7 | 125 8 | 127 9 | 129 10 | 140 11 | 142 12 | 143 13 | 144 14 | 145 15 | 147 16 | 193 17 | 196 18 | 197 19 | 203 20 | 204 21 | 205 22 | 208 23 | 209 24 | 210 25 | 211 26 | 212 27 | 213 28 | 215 29 | 216 30 | 265 31 | 266 32 | 268 33 | 271 34 | 277 35 | -------------------------------------------------------------------------------- /test/pca/ans-loc-seq.txt: -------------------------------------------------------------------------------- 1 | 55 2 | 56 3 | 57 4 | 111 5 | 113 6 | 115 7 | 127 8 | 128 9 | 129 10 | 130 11 | 132 12 | 164 13 | 165 14 | 167 15 | 171 16 | 177 17 | 185 18 | -------------------------------------------------------------------------------- /test/pca/criterion-inst-pthread.txt: -------------------------------------------------------------------------------- 1 | calc_mean 58 2 | -------------------------------------------------------------------------------- /test/pca/criterion-inst-seq.txt: -------------------------------------------------------------------------------- 1 | calc_mean 51 2 | -------------------------------------------------------------------------------- /test/pca/criterion-loc-pthread.txt: -------------------------------------------------------------------------------- 1 | pca-pthread.c 147 2 | -------------------------------------------------------------------------------- /test/pca/criterion-loc-seq.txt: -------------------------------------------------------------------------------- 1 | pca-seq.c 132 2 | -------------------------------------------------------------------------------- /test/pca/pca-seq.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2009, Stanford University 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * * Neither the name of Stanford University nor the names of its 12 | * contributors may be used to endorse or promote products derived from 13 | * this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include "stddefines.h" 37 | 38 | #define DEF_GRID_SIZE 100 // all values in the matrix are from 0 to this value 39 | #define DEF_NUM_ROWS 10 40 | #define DEF_NUM_COLS 10 41 | 42 | int num_rows; 43 | int num_cols; 44 | int grid_size; 45 | 46 | /** parse_args() 47 | * Parse the user arguments to determine the number of rows and colums 48 | */ 49 | void parse_args(int argc, char **argv) 50 | { 51 | int c; 52 | extern char *optarg; 53 | extern int optind; 54 | 55 | num_rows = DEF_NUM_ROWS; 56 | num_cols = DEF_NUM_COLS; 57 | grid_size = DEF_GRID_SIZE; 58 | 59 | while ((c = getopt(argc, argv, "r:c:s:")) != EOF) 60 | { 61 | switch (c) { 62 | case 'r': 63 | num_rows = atoi(optarg); 64 | break; 65 | case 'c': 66 | num_cols = atoi(optarg); 67 | break; 68 | case 's': 69 | grid_size = atoi(optarg); 70 | break; 71 | case '?': 72 | printf("Usage: %s -r -c -s \n", argv[0]); 73 | exit(1); 74 | } 75 | } 76 | 77 | if (num_rows <= 0 || num_cols <= 0 || grid_size <= 0) { 78 | printf("Illegal argument value. All values must be numeric and greater than 0\n"); 79 | exit(1); 80 | } 81 | 82 | printf("Number of rows = %d\n", num_rows); 83 | printf("Number of cols = %d\n", num_cols); 84 | printf("Max value for each element = %d\n", grid_size); 85 | } 86 | 87 | /** dump_points() 88 | * Print the values in the matrix to the screen 89 | */ 90 | void dump_points(int **vals, int rows, int cols) 91 | { 92 | int i, j; 93 | 94 | for (i = 0; i < rows; i++) 95 | { 96 | for (j = 0; j < cols; j++) 97 | { 98 | dprintf("%5d ",vals[i][j]); 99 | } 100 | dprintf("\n"); 101 | } 102 | } 103 | 104 | /** generate_points() 105 | * Create the values in the matrix 106 | */ 107 | void generate_points(int **pts, int rows, int cols) 108 | { 109 | int i, j; 110 | 111 | for (i=0; i 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | //#define TIMING 37 | 38 | /* Debug printf */ 39 | #define dprintf(...) fprintf(stdout, __VA_ARGS__) 40 | 41 | /* Wrapper to check for errors */ 42 | #define CHECK_ERROR(a) \ 43 | if (a) \ 44 | { \ 45 | perror("Error at line\n\t" #a "\nSystem Msg"); \ 46 | assert ((a) == 0); \ 47 | } 48 | 49 | static inline void *MALLOC(size_t size) 50 | { 51 | void * temp = malloc(size); 52 | assert(temp); 53 | return temp; 54 | } 55 | 56 | static inline void *CALLOC(size_t num, size_t size) 57 | { 58 | void * temp = calloc(num, size); 59 | assert(temp); 60 | return temp; 61 | } 62 | 63 | static inline void *REALLOC(void *ptr, size_t size) 64 | { 65 | void * temp = realloc(ptr, size); 66 | assert(temp); 67 | return temp; 68 | } 69 | 70 | static inline char *GETENV(char *envstr) 71 | { 72 | char *env = getenv(envstr); 73 | if (!env) return "0"; 74 | else return env; 75 | } 76 | 77 | #define GET_TIME(start, end, duration) \ 78 | duration.tv_sec = (end.tv_sec - start.tv_sec); \ 79 | if (end.tv_nsec >= start.tv_nsec) { \ 80 | duration.tv_nsec = (end.tv_nsec - start.tv_nsec); \ 81 | } \ 82 | else { \ 83 | duration.tv_nsec = (1000000000L - (start.tv_nsec - end.tv_nsec)); \ 84 | duration.tv_sec--; \ 85 | } \ 86 | if (duration.tv_nsec >= 1000000000L) { \ 87 | duration.tv_sec++; \ 88 | duration.tv_nsec -= 1000000000L; \ 89 | } 90 | 91 | static inline unsigned int time_diff ( 92 | struct timeval *end, struct timeval *begin) 93 | { 94 | #ifdef TIMING 95 | uint64_t result; 96 | 97 | result = end->tv_sec - begin->tv_sec; 98 | result *= 1000000; /* usec */ 99 | result += end->tv_usec - begin->tv_usec; 100 | 101 | return result; 102 | #else 103 | return 0; 104 | #endif 105 | } 106 | 107 | static inline void get_time (struct timeval *t) 108 | { 109 | #ifdef TIMING 110 | gettimeofday (t, NULL); 111 | #endif 112 | } 113 | 114 | #endif // STDDEFINES_H_ 115 | -------------------------------------------------------------------------------- /test/word_count/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/test/word_count/Makefile -----------------------*- Makefile -*-===## 2 | 3 | TEST_PARALLELISM ?= pthread 4 | #CRITERION ?= "-criterion-loc=loc-$(TEST_PARALLELISM).txt" 5 | CRITERION ?= "-criterion-inst=inst-$(TEST_PARALLELISM).txt" 6 | DEBUGFLAGS ?= -debug 7 | INPUT ?= Makefile 8 | 9 | ##### Don't modify the following unless you know exactly what you're doing ##### 10 | ifeq (pthread,$(TEST_PARALLELISM)) 11 | NAME = word_count-pthread 12 | SRC_FILES = word_count-pthread.c sort-pthread.c 13 | LDFLAGS = -lpthread 14 | else 15 | NAME = word_count-seq 16 | SRC_FILES = word_count-seq.c 17 | TEST_PARALLELISM = seq 18 | endif 19 | 20 | GIRI_DIR = ../../build/ 21 | 22 | include ../Makefile.common 23 | 24 | clean-all: 25 | @ rm -f matrix_file_out_*.txt 26 | -------------------------------------------------------------------------------- /test/word_count/README.md: -------------------------------------------------------------------------------- 1 | This test program is from Phoenix Project 2 | Wordcount Example Application Readme 3 | 4 | Application Overview 5 | ----------------------- 6 | 7 | The Wordcount application counts the frequency of occurence of each unique word 8 | in a text document. 9 | 10 | Running the Application 11 | -------------------------- 12 | 13 | Please modify the `Makefile` first to set the proper variables before every run. 14 | 15 | How to Download the Data Input 16 | ------------------------------ 17 | 18 | We don't provide the data set because of its large size. You can download it from the [official site](http://mapreduce.stanford.edu/datafiles/word_count.tar.gz) of Phoenix. 19 | -------------------------------------------------------------------------------- /test/word_count/sort-pthread.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2009, Stanford University 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * * Neither the name of Stanford University nor the names of its 12 | * contributors may be used to endorse or promote products derived from 13 | * this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #define CHECK_ERROR(a) \ 37 | if (a) \ 38 | { \ 39 | perror("Error at line\n\t" #a "\nSystem Msg"); \ 40 | exit(1); \ 41 | } 42 | 43 | void *sort_section(void *args_in) ; 44 | 45 | typedef struct { 46 | void* base; 47 | size_t num_elems; 48 | size_t width; 49 | int (*compar)(const void *, const void *); 50 | } sort_args; 51 | 52 | /** sort_section() 53 | * USes qsort to sort the respective portions 54 | */ 55 | void *sort_section(void *args_in) 56 | { 57 | sort_args* args =(sort_args*)args_in; 58 | 59 | qsort(args->base, args->num_elems, args->width, args->compar); 60 | free(args); 61 | return (void *)0; 62 | } 63 | 64 | /** sort_pthreads() 65 | * Function that creates the threads to sort 66 | */ 67 | void sort_pthreads(void *base, size_t num_elems, size_t width, 68 | int (*compar)(const void *, const void *)) 69 | { 70 | int req_units, num_threads, num_procs, i; 71 | pthread_attr_t attr; 72 | pthread_t * tid; 73 | 74 | CHECK_ERROR((num_procs = sysconf(_SC_NPROCESSORS_ONLN)) <= 0); 75 | printf("THe number of processors is %d\n\n", num_procs); 76 | 77 | tid = (pthread_t *)malloc(num_procs * sizeof(pthread_t)); 78 | pthread_attr_init(&attr); 79 | pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); 80 | 81 | num_threads = num_procs; 82 | 83 | while(num_threads > 0) 84 | { 85 | req_units = num_elems / num_threads; 86 | 87 | for(i=0; ibase = ((char*)base) + i*req_units*width; 92 | out->num_elems = req_units; 93 | if(i == (num_threads - 1)) 94 | out->num_elems = num_elems - i*req_units; 95 | out->width = width; 96 | out->compar = compar; 97 | 98 | CHECK_ERROR(pthread_create(&tid[i], &attr, sort_section, (void*)out) != 0); 99 | 100 | } 101 | 102 | /* Barrier, wait for all threads to finish */ 103 | for (i = 0; i < num_threads; i++) 104 | { 105 | int ret_val; 106 | CHECK_ERROR(pthread_join(tid[i], (void **)(void*)&ret_val) != 0); 107 | CHECK_ERROR(ret_val != 0); 108 | } 109 | 110 | num_threads = num_threads / 2; 111 | } 112 | 113 | 114 | //qsort(base, num_elems, width, compar); 115 | 116 | free(tid); 117 | } 118 | -------------------------------------------------------------------------------- /test/word_count/sort-pthread.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2009, Stanford University 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * * Neither the name of Stanford University nor the names of its 12 | * contributors may be used to endorse or promote products derived from 13 | * this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef _SORT_PTHREADS_H_ 28 | #define _SORT_PTHREADS_H_ 29 | 30 | void sort_pthreads(void *base, size_t num_elems, size_t width, 31 | int (*compar)(const void *, const void *)); 32 | 33 | #endif // _SORT_PTHREADS_H_ 34 | -------------------------------------------------------------------------------- /test/word_count/stddefines.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2009, Stanford University 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * * Neither the name of Stanford University nor the 12 | * names of its contributors may be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef STDDEFINES_H_ 28 | #define STDDEFINES_H_ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | //#define TIMING 37 | 38 | /* Debug printf */ 39 | #define dprintf(...) fprintf(stdout, __VA_ARGS__) 40 | 41 | /* Wrapper to check for errors */ 42 | #define CHECK_ERROR(a) \ 43 | if (a) \ 44 | { \ 45 | perror("Error at line\n\t" #a "\nSystem Msg"); \ 46 | assert ((a) == 0); \ 47 | } 48 | 49 | static inline void *MALLOC(size_t size) 50 | { 51 | void * temp = malloc(size); 52 | assert(temp); 53 | return temp; 54 | } 55 | 56 | static inline void *CALLOC(size_t num, size_t size) 57 | { 58 | void * temp = calloc(num, size); 59 | assert(temp); 60 | return temp; 61 | } 62 | 63 | static inline void *REALLOC(void *ptr, size_t size) 64 | { 65 | void * temp = realloc(ptr, size); 66 | assert(temp); 67 | return temp; 68 | } 69 | 70 | static inline char *GETENV(char *envstr) 71 | { 72 | char *env = getenv(envstr); 73 | if (!env) return "0"; 74 | else return env; 75 | } 76 | 77 | #define GET_TIME(start, end, duration) \ 78 | duration.tv_sec = (end.tv_sec - start.tv_sec); \ 79 | if (end.tv_nsec >= start.tv_nsec) { \ 80 | duration.tv_nsec = (end.tv_nsec - start.tv_nsec); \ 81 | } \ 82 | else { \ 83 | duration.tv_nsec = (1000000000L - (start.tv_nsec - end.tv_nsec)); \ 84 | duration.tv_sec--; \ 85 | } \ 86 | if (duration.tv_nsec >= 1000000000L) { \ 87 | duration.tv_sec++; \ 88 | duration.tv_nsec -= 1000000000L; \ 89 | } 90 | 91 | static inline unsigned int time_diff ( 92 | struct timeval *end, struct timeval *begin) 93 | { 94 | #ifdef TIMING 95 | uint64_t result; 96 | 97 | result = end->tv_sec - begin->tv_sec; 98 | result *= 1000000; /* usec */ 99 | result += end->tv_usec - begin->tv_usec; 100 | 101 | return result; 102 | #else 103 | return 0; 104 | #endif 105 | } 106 | 107 | static inline void get_time (struct timeval *t) 108 | { 109 | #ifdef TIMING 110 | gettimeofday (t, NULL); 111 | #endif 112 | } 113 | 114 | #endif // STDDEFINES_H_ 115 | -------------------------------------------------------------------------------- /tools/Makefile: -------------------------------------------------------------------------------- 1 | ##===- giri/tools/Makefile -----------------------------*- Makefile -*-===## 2 | 3 | # 4 | # Relative path to the top of the source tree. 5 | # 6 | LEVEL = .. 7 | 8 | # 9 | # List all of the subdirectories that we will compile. 10 | # 11 | DIRS = PrintTrace Tracer 12 | 13 | include $(LEVEL)/Makefile.common 14 | -------------------------------------------------------------------------------- /tools/PrintTrace/Makefile: -------------------------------------------------------------------------------- 1 | #===- tools/PrintTrace/Makefile ----------------------------*- Makefile -*-===## 2 | # 3 | # The LLVM Compiler Infrastructure 4 | # 5 | # This file was developed by the LLVM research group and is distributed under 6 | # the University of Illinois Open Source License. See LICENSE.TXT for details. 7 | # 8 | ##===----------------------------------------------------------------------===## 9 | 10 | LEVEL = ../.. 11 | TOOLNAME = prtrace 12 | 13 | LINK_COMPONENTS := support 14 | 15 | include $(LEVEL)/Makefile.common 16 | -------------------------------------------------------------------------------- /tools/PrintTrace/PrintTrace.cpp: -------------------------------------------------------------------------------- 1 | //===-- sc - SAFECode Compiler Tool ---------------------------------------===// 2 | // 3 | // Giri: Dynamic Slicing in LLVM 4 | // 5 | // This file was developed by the LLVM research group and is distributed 6 | // under the University of Illinois Open Source License. See LICENSE.TXT for 7 | // details. 8 | // 9 | //===----------------------------------------------------------------------===// 10 | // 11 | // This program is a tool to run the SAFECode passes on a bytecode input file. 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | #include "Giri/TraceFile.h" 16 | 17 | #include "llvm/Support/CommandLine.h" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | static cl::opt 28 | InputFilename(cl::Positional, cl::desc("trace file name"), cl::init("-")); 29 | 30 | int main(int argc, char ** argv) { 31 | // Parse the command line options. 32 | cl::ParseCommandLineOptions(argc, argv, "Print Trace Utility\n"); 33 | 34 | // Open the trace file for read-only access. 35 | int fd = 0; 36 | if (InputFilename == "-") 37 | fd = STDIN_FILENO; 38 | else 39 | fd = open (InputFilename.c_str(), O_RDONLY); 40 | assert((fd != -1) && "Cannot open file!\n"); 41 | 42 | // Print a header that reminds the user of what the fields mean. 43 | printf("-----------------------------------------------------------------------------\n"); 44 | printf("%10s: Record Type: %6s: %15s: %16s: %8s\n", 45 | "Index", "ID", "TID", "Address", "Length"); 46 | printf("-----------------------------------------------------------------------------\n"); 47 | 48 | // Read in each entry and print it out. 49 | Entry entry; 50 | ssize_t readsize; 51 | unsigned index = 0; 52 | while ((readsize = read(fd, &entry, sizeof(entry))) == sizeof(entry)) { 53 | printf("%10u: ", index++); 54 | 55 | // Print the entry's type 56 | switch (entry.type) { 57 | case RecordType::BBType: 58 | printf("BasicBlock : "); 59 | break; 60 | case RecordType::LDType: 61 | printf("Load : "); 62 | break; 63 | case RecordType::STType: 64 | printf("Store : "); 65 | break; 66 | case RecordType::PDType: 67 | printf("Select : "); 68 | break; 69 | case RecordType::CLType: 70 | printf("Call : "); 71 | break; 72 | case RecordType::RTType: 73 | printf("Return : "); 74 | break; 75 | case RecordType::ENType: 76 | printf("End : "); 77 | break; 78 | } 79 | 80 | // Print the value associated with the entry. 81 | if (entry.type == RecordType::BBType) 82 | printf("%6u: %8lu: %16lx: %8lu\n", 83 | entry.id, 84 | entry.tid, 85 | entry.address, 86 | entry.length); 87 | else 88 | printf("%6u: %8lu: %16lx: %8lx\n", 89 | entry.id, 90 | entry.tid, 91 | entry.address, 92 | entry.length); 93 | 94 | // Stop printing entries if we've hit the end of the log. 95 | if (entry.type == RecordType::ENType) { 96 | readsize = 0; 97 | break; 98 | } 99 | } 100 | 101 | if (readsize != 0) { 102 | fprintf(stderr, "Read of incorrect size\n"); 103 | exit(1); 104 | } 105 | 106 | return 0; 107 | } 108 | -------------------------------------------------------------------------------- /tools/Tracer/Makefile: -------------------------------------------------------------------------------- 1 | #===- tools/Tracer/Makefile --------------------------------*- Makefile -*-===## 2 | # 3 | # The LLVM Compiler Infrastructure 4 | # 5 | # This file was developed by the LLVM research group and is distributed under 6 | # the University of Illinois Open Source License. See LICENSE.TXT for details. 7 | # 8 | ##===----------------------------------------------------------------------===## 9 | 10 | LEVEL = ../.. 11 | TOOLNAME = tracer 12 | CXXFLAGS += -fno-rtti 13 | REQUIRES_EH := 1 14 | 15 | LINK_COMPONENTS := bitreader bitwriter instrumentation scalaropts ipo nativecodegen 16 | 17 | USEDLIBS := giri.a dgutility.a 18 | 19 | include $(LEVEL)/Makefile.common 20 | -------------------------------------------------------------------------------- /utils/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | mkdir build 4 | cd build 5 | ../configure --with-llvmsrc=$LLVM_HOME \ 6 | --with-llvmobj=$LLVM_HOME/build \ 7 | --enable-optimized \ 8 | --disable-debug-symbols \ 9 | --disable-docs \ 10 | --disable-terminfo \ 11 | --enable-targets=host-only 12 | make 13 | cd .. 14 | make -C test 15 | -------------------------------------------------------------------------------- /utils/install_llvm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # USAGE: export LLVM_HOME=llvm && $0 [VERSION] 4 | 5 | if [ "giri$LLVM_HOME" == "giri" ]; then 6 | echo "Please set the LLVM_HOME env!" 7 | exit 1 8 | fi 9 | 10 | VERSION=3.4 11 | [ $# -ge 1 ] && VERSION=$1 12 | case $VERSION in 13 | "3.1") 14 | ;; 15 | "3.4") 16 | wget http://llvm.org/releases/3.4/clang-3.4.src.tar.gz 17 | wget http://llvm.org/releases/3.4/llvm-3.4.src.tar.gz 18 | wget http://llvm.org/releases/3.4/compiler-rt-3.4.src.tar.gz 19 | tar xf llvm-3.4.src.tar.gz && rm -f llvm-3.4.src.tar.gz 20 | tar xf clang-3.4.src.tar.gz && rm -f clang-3.4.src.tar.gz 21 | tar xf compiler-rt-3.4.src.tar.gz && rm -f compiler-rt-3.4.src.tar.gz 22 | mv llvm-3.4 $LLVM_HOME 23 | mv clang-3.4 $LLVM_HOME/tools/clang 24 | mv compiler-rt-3.4 $LLVM_HOME/projects/compiler-rt 25 | ;; 26 | esac 27 | 28 | mkdir -p $LLVM_HOME/build 29 | cd $LLVM_HOME/build 30 | ../configure --enable-optimized \ 31 | --disable-debug-symbols \ 32 | --disable-docs \ 33 | --disable-terminfo \ 34 | --disable-bindings \ 35 | --enable-targets=host-only \ 36 | --enable-shared 37 | make -j2 38 | make install 39 | --------------------------------------------------------------------------------