From 199b9a8e75f7559109d58d4c35bdf01ce9c811b7 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 17 Dec 2018 03:58:37 -0500 Subject: [PATCH] Update building method --- CMakeLists.txt | 6 ------ pass/CPI.cpp | 4 ++-- safe_rt/rt.c => rt.c | 2 ++ tests/run.sh | 11 ++++++++--- 4 files changed, 12 insertions(+), 11 deletions(-) rename safe_rt/rt.c => rt.c (94%) diff --git a/CMakeLists.txt b/CMakeLists.txt index b954f15..3fbeae8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,10 +13,4 @@ if (APPLE) list (APPEND CMAKE_CXX_FLAGS "-undefined dynamic_lookup") endif(APPLE) -add_library( - safe_rt - STATIC - safe_rt/rt.c -) - add_subdirectory(pass) diff --git a/pass/CPI.cpp b/pass/CPI.cpp index 706fac7..bfb9160 100644 --- a/pass/CPI.cpp +++ b/pass/CPI.cpp @@ -34,10 +34,10 @@ struct CPI : public ModulePass { nop = BinaryOperator::Create(Instruction::Add, zero, zero, "NOP", M.getFunctionList().front().getEntryBlock().getFirstNonPHIOrDbg()); - // Add global variables in libsafe_rt + // Add global variables rt.c smSp = new GlobalVariable(M, intT, false, GlobalValue::ExternalLinkage, nullptr, "__sm_sp"); - // Add function references in libsafe_rt + // Add function references in rt.c smAlloca = cast(M.getOrInsertFunction("__sm_alloca", voidPPT)); smMalloc = cast(M.getOrInsertFunction("__sm_malloc", voidPPT, voidPPT)); smLoad = cast(M.getOrInsertFunction("__sm_load", voidPT, voidPPT, voidPPT)); diff --git a/safe_rt/rt.c b/rt.c similarity index 94% rename from safe_rt/rt.c rename to rt.c index af4c586..5b6dc79 100644 --- a/safe_rt/rt.c +++ b/rt.c @@ -10,6 +10,7 @@ int __sm_sp = 0; static void ***block_table; static int table_sz = 0; +__attribute__((always_inline)) static inline void **sm_alloca() { int block_num = __sm_sp >> 4; if (block_num == table_sz) { @@ -35,6 +36,7 @@ void **__sm_malloc(void **ua) { return sa; } +__attribute__((always_inline)) void *__sm_load(void **sa, void **ua) { assert(*sa == *ua); return *sa; diff --git a/tests/run.sh b/tests/run.sh index 333a900..9d1d5ba 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -38,10 +38,15 @@ name=${src%.*}.llvm # Compile test program with alloca-hoisting and mem2reg clang -emit-llvm -O1 -mllvm -disable-llvm-optzns -c $src -o - | opt -S -alloca-hoisting -mem2reg -o ${name}.ll || exit 1 -clang ${name}.ll -o ${name}.out +clang -O2 ${name}.ll -o ${name}.out # Run CPI pass opt -S -o ${name}.p.ll -load ../build/pass/LLVMCPI.${dll} $CPI_FLAG ${name}.ll || exit 1 -# Build patched code and link to libsafe_rt -clang ${name}.p.ll -L../build -lsafe_rt -o ${name}.p.out +# Build patched code +clang -O2 ${name}.p.ll ../rt.c -o ${name}.p.out +exit + +# Generate combined bitcode +clang -S -emit-llvm -c ../safe_rt/rt.c -o rt.llvm.ll +llvm-link ${name}.p.ll rt.llvm.ll | opt -S -O2 -o ${name}.o.ll