diff --git a/hpvm/projects/CMakeLists.txt b/hpvm/projects/CMakeLists.txt
index 2a51c0b09e672e8508a8a13d189d05eb3ccc2e48..b46164b8d07de77ba9feb570b976e19ae9fdf4b2 100644
--- a/hpvm/projects/CMakeLists.txt
+++ b/hpvm/projects/CMakeLists.txt
@@ -10,6 +10,7 @@ foreach(entry ${entries})
        (NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/parallel-libs) AND
        (NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/openmp) AND
        (NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/debuginfo-tests))
+      set(LLVM_BUILD_DIR ${PROJECT_BINARY_DIR})
       get_filename_component(entry_name "${entry}" NAME)
       add_llvm_external_project(${entry_name})
     endif()
diff --git a/hpvm/projects/hpvm-tensor-rt/CMakeLists.txt b/hpvm/projects/hpvm-tensor-rt/CMakeLists.txt
index 2b41397dfed23043cdaa948e1e9f03890e0d52c5..a04dd2a9c87b95ab9c3bd44e727660a9feace9c9 100644
--- a/hpvm/projects/hpvm-tensor-rt/CMakeLists.txt
+++ b/hpvm/projects/hpvm-tensor-rt/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required (VERSION 3.17)
+cmake_minimum_required(VERSION 3.17)
 project(hpvm-tensor-rt)
 find_package(CUDA 6.5 REQUIRED)
 set(CUDA_SEPARABLE_COMPILATION ON CACHE BOOL "")
@@ -45,16 +45,21 @@ configure_file(
 )
 
 # Default include/link directories
-include_directories(
+set(
+  INCLUDES
   $ENV{CUDNN_PATH} $ENV{CUDNN_PATH}/include
+  ${CUDA_INCLUDE_DIRS}
   ./tensor_runtime/include ${CMAKE_CURRENT_BINARY_DIR}/tensor_runtime/include
   ./dnn_sources/include
   ../gpu_profiler/include ../soc_simulator/include
 )
-link_directories(
+set(
+  LINK_DIRS
   ${CUDA_TOOLKIT_ROOT_DIR}/lib64 $ENV{CUDNN_PATH}
   $ENV{CUDNN_PATH}/lib $ENV{CUDNN_PATH}/lib64
 )
+include_directories(${INCLUDES})
+link_directories(${LINK_DIRS})
 
 # Source files of runtime
 set(
@@ -93,8 +98,8 @@ endforeach()
 get_filename_component(root_dir ${CMAKE_SOURCE_DIR} REALPATH)
 get_filename_component(our_dir ${CMAKE_CURRENT_SOURCE_DIR} REALPATH)
 if(${root_dir} STREQUAL ${our_dir})
-  message("Compiling hpvm-tensor-rt independently")
-  message("Also compiling gpu_profiler and soc_simulator")
+  message(STATUS "Compiling hpvm-tensor-rt independently")
+  message(STATUS "Also compiling gpu_profiler and soc_simulator")
   add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../gpu_profiler ${CMAKE_CURRENT_BINARY_DIR}/gpu_profiler)
   add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../soc_simulator ${CMAKE_CURRENT_BINARY_DIR}/soc_simulator)
 endif()
@@ -112,6 +117,34 @@ target_compile_options(tensor_runtime PRIVATE ${OpenMP_CXX_FLAGS})
 target_link_libraries(tensor_runtime ${LINK_LIBS} ${OpenMP_CXX_FLAGS})
 target_compile_definitions(tensor_runtime PRIVATE -DONLINE_PROFILING=false -DFP16_tuning=true)
 
+if(LLVM_BUILD_DIR)  # Defined in ../CMakeLists.txt
+  get_filename_component(LLVM_CLANG_XX ${LLVM_BUILD_DIR}/bin/clang++ REALPATH)
+  set(GENERATE_LL 1)
+else()
+  # Surely if we're compiling outside of hpvm, then we need the system-wide clang.
+  # Use it but check version 9.0 first
+  execute_process(COMMAND clang++ --version OUTPUT_VARIABLE clang_full_version_string ERROR_QUIET)
+  string(REGEX REPLACE ".*clang version ([0-9]+\\.[0-9]+).*" "\\1" CLANG_VERSION_STRING ${clang_full_version_string})
+  if(CLANG_VERSION_STRING VERSION_EQUAL 9)
+    set(LLVM_CLANG_XX clang++)
+    set(GENERATE_LL 1)
+  else()
+    message(WARNING "System clang++ of version 9 not found; skipping tensor_runtime.ll generation")
+    set(GENERATE_LL 0)
+  endif()
+endif()
+if(GENERATE_LL)
+  foreach(dir ${INCLUDES})
+    list(APPEND INCLUDE_COMPILER_STRINGS "-I${dir}")
+  endforeach()
+  add_custom_command(
+    TARGET tensor_runtime POST_BUILD
+    COMMAND ${LLVM_CLANG_XX} ${INCLUDE_COMPILER_STRINGS} -S -emit-llvm
+    ${CMAKE_CURRENT_SOURCE_DIR}/tensor_runtime/include/tensor_signatures.cc
+    -o ${CMAKE_CURRENT_SOURCE_DIR}/lib/tensor_runtime.ll
+  )
+endif()
+
 # Install version (also offline)
 cuda_add_library(tensor_runtime_install ${RUNTIME_SRCS})
 cuda_add_cublas_to_target(tensor_runtime_install)
diff --git a/hpvm/projects/hpvm-tensor-rt/tensor_runtime/include/tensor_signatures.cc b/hpvm/projects/hpvm-tensor-rt/tensor_runtime/include/tensor_signatures.cc
index 478a7ba037702fd74d6dffb489ca093a49405449..7eb3afc62d9e24cb9f73720a2a522e42004fff57 100644
--- a/hpvm/projects/hpvm-tensor-rt/tensor_runtime/include/tensor_signatures.cc
+++ b/hpvm/projects/hpvm-tensor-rt/tensor_runtime/include/tensor_signatures.cc
@@ -47,10 +47,7 @@ void dummyFunction() {
 
   void *ConvLayer_ = (void *)&wrapper_ConvLayer;
   void *ConvLayer2 = (void *)&wrapper_ConvLayer2;
-<<<<<<< HEAD
-=======
   void *GroupConvLayer = (void *)&wrapper_tensorGroupConvolution;
->>>>>>> 2a31471f4de89edd9180689d139be7ca65b0df08
 
   void *FCLayer2 = (void *)&wrapper_FCLayer;
   void *AddWrapper = (void *)&wrapper_tensorAdd;
@@ -69,5 +66,5 @@ void dummyFunction() {
   void *tensorStencil = (void *)&wrapper_tensorStencil;
   void *tensorCosineT = (void *)&wrapper_tensorCosineT;
 
-  void *tensorNodeID = (void*) &tensor_set_node_id;
+  void *tensorNodeID = (void *)&tensor_set_node_id;
 }