From 20478dcbe62bc702132b2eed4c41f0eec25a80ab Mon Sep 17 00:00:00 2001
From: Yifan Zhao <yifanz16@illinois.edu>
Date: Thu, 21 Jan 2021 02:31:26 -0600
Subject: [PATCH] Make each compile step depends on their own pass/libs so that
 pass update triggers recompilation

---
 hpvm/test/dnn_benchmarks/CMakeLists.txt | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/hpvm/test/dnn_benchmarks/CMakeLists.txt b/hpvm/test/dnn_benchmarks/CMakeLists.txt
index 8547971313..887b2d1e6c 100644
--- a/hpvm/test/dnn_benchmarks/CMakeLists.txt
+++ b/hpvm/test/dnn_benchmarks/CMakeLists.txt
@@ -48,7 +48,7 @@ set(HPVM_RT_PATH ${PROJECT_BINARY_DIR}/tools/hpvm/projects/hpvm-rt/hpvm-rt.ll)
 # Compile flags (clang++)
 set(CLANG_FLAGS -fno-exceptions -std=c++11 -O3)
 
-# All compilation uses HPVM_DEFAULT_PASSES, some can pick from HPVM_OPTIONAL_PASSES 
+# All compilation uses HPVM_DEFAULT_PASSES.
 set(
   HPVM_DEFAULT_PASSES
   LLVMBuildDFG
@@ -58,13 +58,6 @@ set(
   LLVMClearDFG
   LLVMGenHPVM
 )
-set(
-  HPVM_OPTIONAL_PASSES
-  LLVMDFG2LLVM_CUDNN
-  LLVMDFG2LLVM_WrapperAPI
-)
-# Manually specify dependencies because we're not using cmake "normally"
-list(APPEND DEPEND clang opt llvm-link hpvm-rt.ll ${HPVM_DEFAULT_PASSES} ${HPVM_OPTIONAL_PASSES})
 
 set(WORK_DIR ${CMAKE_CURRENT_BINARY_DIR})
 set(test_compile_targets "")
@@ -78,34 +71,37 @@ function(compile_single_benchmark target src_file extra_passes extra_dfg_flags)
   )
 
   add_custom_command(
-    OUTPUT "${WORK_DIR}/${target}.ll" DEPENDS ${src_file}
+    OUTPUT "${WORK_DIR}/${target}.ll" DEPENDS ${src_file} clang
     COMMAND ${CMAKE_CXX_COMPILER} ${INCLUDE_COMPILER_STRINGS} ${CLANG_FLAGS} -emit-llvm -S ${src_file}
       -o ${WORK_DIR}/${target}.ll
   )
   add_custom_command(
-    OUTPUT "${WORK_DIR}/${target}.hpvm.ll" DEPENDS "${WORK_DIR}/${target}.ll"
+    OUTPUT "${WORK_DIR}/${target}.hpvm.ll"
+    DEPENDS "${WORK_DIR}/${target}.ll" opt LLVMGenHPVM
     COMMAND ${LLVM_OPT} -load LLVMGenHPVM.so -genhpvm -globaldce -S ${WORK_DIR}/${target}.ll
       -o ${WORK_DIR}/${target}.hpvm.ll
   )
   add_custom_command(
-    OUTPUT "${WORK_DIR}/${target}.llvm.ll" DEPENDS "${WORK_DIR}/${target}.hpvm.ll"
+    OUTPUT "${WORK_DIR}/${target}.llvm.ll"
+    DEPENDS "${WORK_DIR}/${target}.hpvm.ll" opt ${HPVM_DEFAULT_PASSES} ${extra_passes}
     COMMAND ${LLVM_OPT} ${HPVM_PASSES} -S ${WORK_DIR}/${target}.hpvm.ll
       -o ${WORK_DIR}/${target}.llvm.ll
   )
   add_custom_command(
-    OUTPUT "${WORK_DIR}/${target}.linked.bc" DEPENDS "${WORK_DIR}/${target}.llvm.ll"
+    OUTPUT "${WORK_DIR}/${target}.linked.bc"
+    DEPENDS "${WORK_DIR}/${target}.llvm.ll" hpvm-rt.ll llvm-link
     COMMAND ${LLVM_LINK} ${WORK_DIR}/${target}.llvm.ll ${HPVM_RT_PATH}
       -o ${WORK_DIR}/${target}.linked.bc
   )
   add_custom_command(
-    OUTPUT "${WORK_DIR}/${target}" DEPENDS "${WORK_DIR}/${target}.linked.bc"
+    OUTPUT "${WORK_DIR}/${target}"
+    DEPENDS "${WORK_DIR}/${target}.linked.bc" tensor_runtime gpu_profiler promise_profiler
     COMMAND ${CMAKE_CXX_COMPILER}
       ${WORK_DIR}/${target}.linked.bc
       $<TARGET_FILE:tensor_runtime> $<TARGET_FILE:gpu_profiler> $<TARGET_FILE:promise_profiler>
       -o ${WORK_DIR}/${target} ${LINKER_FLAGS}
   )
   add_custom_target(${target} DEPENDS "${WORK_DIR}/${target}")
-  add_dependencies(${target} ${DEPEND})
 
   set(test_compile_targets ${test_compile_targets} ${target} PARENT_SCOPE)
 endfunction(compile_single_benchmark)
-- 
GitLab