<commit_before>add_executable(build_halide_h ../tools/build_halide_h.cpp)
add_executable(bitcode2cpp ../tools/bitcode2cpp.cpp)


if (MSVC)
  # Suppress some warnings
  add_definitions("-D_CRT_SECURE_NO_WARNINGS")
  add_definitions("-D_SCL_SECURE_NO_WARNINGS")
  add_definitions("/wd4244 /wd4267 /wd4800 /wd4996")
else()
  add_definitions("-D__STDC_LIMIT_MACROS")
  add_definitions("-D__STDC_CONSTANT_MACROS")
  add_definitions("-std=c++11")
endif()

if (HALIDE_SHARED_LIBRARY)
  add_definitions("-DHalide_SHARED")
  set(HALIDE_LIBRARY_TYPE SHARED)
else()
  set(HALIDE_LIBRARY_TYPE STATIC)
endif()

include_directories ( "${LLVM_INCLUDE}")
link_directories ("${LLVM_LIB}")

if(WIN32)
  file(GLOB LIBS RELATIVE "${LLVM_LIB}" "${LLVM_LIB}/*.lib")
else()
  execute_process(COMMAND "${LLVM_CONFIG}" --ldflags --libs OUTPUT_VARIABLE LIBS)
endif()

if (TARGET_NATIVE_CLIENT)
  add_definitions("-DWITH_NATIVE_CLIENT=1")
endif()

if (TARGET_X86)
  add_definitions("-DWITH_X86=1")
endif()

if (TARGET_ARM)
  add_definitions("-DWITH_ARM=1")
endif()

if (TARGET_PTX)
  add_definitions("-DWITH_PTX=1")
endif()

if (TARGET_OPENCL)
  add_definitions("-DWITH_OPENCL=1")
endif()

if (TARGET_OPENGL)
  add_definitions("-DWITH_OPENGL=1")
endif()

if (TARGET_SPIR)
  add_definitions("-DWITH_SPIR=1")
endif()

if (TARGET_ARM64)
  add_definitions("-DWITH_ARM64=1")
endif()

add_definitions("-DLLVM_VERSION=${LLVM_VERSION}")

set(RUNTIME_CPP
  android_io
  cuda
  fake_thread_pool
  gcd_thread_pool
  ios_io
  android_clock
  linux_clock
  nogpu
  opencl
  opengl
  osx_opengl_context
  linux_opengl_context
  posix_allocator
  posix_clock
  osx_clock
  windows_clock
  posix_error_handler
  posix_io
  nacl_io
  ssp
  osx_io
  posix_math
  posix_thread_pool
  windows_thread_pool
  android_host_cpu_count
  linux_host_cpu_count
  osx_host_cpu_count
  tracing
  write_debug_image
  cuda_debug
  opencl_debug
  opengl_debug
  windows_io)
set (RUNTIME_LL
  arm
  posix_math
  pnacl_math
  ptx_dev
  spir_dev
  spir64_dev
  spir_common_dev
  x86_avx
  x86
  x86_sse41
  pnacl_math)
set (RUNTIME_BC
  compute_20
  compute_30
  compute_35)

set(RUNTIME_DIR "${CMAKE_CURRENT_SOURCE_DIR}/runtime")
file(TO_NATIVE_PATH "${RUNTIME_DIR}/" NATIVE_RUNTIME_DIR)
file(TO_NATIVE_PATH "${CMAKE_CFG_INTDIR}/" NATIVE_INT_DIR)

# ./ seems to confuse cmake on linux
if("${NATIVE_INT_DIR}" STREQUAL "./")
  set(NATIVE_INT_DIR "")
endif()

# Gather dependencies for runtime objects.
file(GLOB RUNTIME_CL_DEPENDS "${RUNTIME_DIR}/CL/*.h")
file(GLOB RUNTIME_CPP_DEPENDS "${RUNTIME_DIR}/*.cpp")
file(GLOB RUNTIME_H_DEPENDS "${RUNTIME_DIR}/*.h")
file(GLOB RUNTIME_LL_DEPENDS "${RUNTIME_DIR}/*.ll")
file(GLOB RUNTIME_BC_DEPENDS "${RUNTIME_DIR}/nvidia_libdevice_bitcode/*.bc")
set (RUNTIME_DEPENDS
  ${RUNTIME_CL_DEPENDS}
  ${RUNTIME_CPP_DEPENDS}
  ${RUNTIME_H_DEPENDS}
  ${RUNTIME_LL_DEPENDS}
  ${RUNTIME_BC_DEPENDS})

# Commands to build initial module objects.
set (INITMOD_PREFIX "_initmod_")
set (ARCHS 32 64)
set(INITIAL_MODULES )
foreach (i ${RUNTIME_CPP} )
  foreach (j ${ARCHS} )
    set(INITMOD "${INITMOD_PREFIX}${i}_${j}.cpp")
    add_custom_command(OUTPUT "${INITMOD}"
                       COMMAND ${CLANG} -fno-blocks -m${j} -DCOMPILING_HALIDE -DBITS_${j} -emit-llvm -O3 -S "${NATIVE_RUNTIME_DIR}${i}.cpp" -o "${NATIVE_INT_DIR}initmod.${i}_${j}.ll"
                       COMMAND "${LLVM_AS}" "${NATIVE_INT_DIR}initmod.${i}_${j}.ll" -o "${NATIVE_INT_DIR}initmod.${i}_${j}.bc"
                       COMMAND bitcode2cpp "${i}_${j}" < "${NATIVE_INT_DIR}initmod.${i}_${j}.bc" > "${INITMOD}"
                       COMMENT "Building initial module ${i}_${j}..."
                       VERBATIM)
    list(APPEND INITIAL_MODULES ${INITMOD})
  endforeach()
endforeach()
foreach (i ${RUNTIME_LL} )
  set(INITMOD "${INITMOD_PREFIX}${i}.cpp")
  add_custom_command(OUTPUT "${INITMOD}"
                     COMMAND "${LLVM_AS}" "${NATIVE_RUNTIME_DIR}${i}.ll" -o "${NATIVE_INT_DIR}initmod.${i}.bc"
                     COMMAND bitcode2cpp ${i}_ll < "${NATIVE_INT_DIR}initmod.${i}.bc" > "${INITMOD}"
                     COMMENT "Building initial module ${i}..."
                     VERBATIM)
  list(APPEND INITIAL_MODULES "${INITMOD}")
endforeach()
foreach (i ${RUNTIME_BC} )
  set(INITMOD "${INITMOD_PREFIX}ptx_${i}.cpp")
  add_custom_command(OUTPUT "${INITMOD}"
                     COMMAND bitcode2cpp "ptx_${i}_ll" < "${NATIVE_RUNTIME_DIR}nvidia_libdevice_bitcode/libdevice.${i}.10.bc" > "${INITMOD}"
                     COMMENT "Building initial module ptx_${i}..."
                     VERBATIM)
  list(APPEND INITIAL_MODULES "${INITMOD}")
endforeach()

add_library(InitialModules STATIC
  ${INITIAL_MODULES})

add_dependencies(InitialModules
  bitcode2cpp)

set(HEADER_FILES
  Util.h
  Type.h
  Argument.h
  Bounds.h
  BoundsInference.h
  Buffer.h
  buffer_t.h
  CodeGen_C.h
  CodeGen.h
  CodeGen_X86.h
  CodeGen_GPU_Host.h
  CodeGen_PTX_Dev.h
  CodeGen_OpenCL_Dev.h
  CodeGen_OpenGL_Dev.h
  CodeGen_GPU_Dev.h
  CodeGen_SPIR_Dev.h
  CodeGen_PNaCl.h
  Deinterleave.h
  Derivative.h
  OneToOne.h
  Extern.h
  FindCalls.h
  Func.h
  Function.h
  Image.h
  InlineReductions.h
  IntegerDivisionTable.h
  Introspection.h
  IntrusivePtr.h
  IREquality.h
  IR.h
  IRMatch.h
  IRMutator.h
  IROperator.h
  IRPrinter.h
  IRVisitor.h
  InjectOpenGLIntrinsics.h
  InjectHostDevBufferCopies.h
  InjectSyncthreads.h<commit_msg>Remove InjectSyncThreads file from CMakeLists<commit_after>add_executable(build_halide_h ../tools/build_halide_h.cpp)
add_executable(bitcode2cpp ../tools/bitcode2cpp.cpp)


if (MSVC)
  # Suppress some warnings
  add_definitions("-D_CRT_SECURE_NO_WARNINGS")
  add_definitions("-D_SCL_SECURE_NO_WARNINGS")
  add_definitions("/wd4244 /wd4267 /wd4800 /wd4996")
else()
  add_definitions("-D__STDC_LIMIT_MACROS")
  add_definitions("-D__STDC_CONSTANT_MACROS")
  add_definitions("-std=c++11")
endif()

if (HALIDE_SHARED_LIBRARY)
  add_definitions("-DHalide_SHARED")
  set(HALIDE_LIBRARY_TYPE SHARED)
else()
  set(HALIDE_LIBRARY_TYPE STATIC)
endif()

include_directories ( "${LLVM_INCLUDE}")
link_directories ("${LLVM_LIB}")

if(WIN32)
  file(GLOB LIBS RELATIVE "${LLVM_LIB}" "${LLVM_LIB}/*.lib")
else()
  execute_process(COMMAND "${LLVM_CONFIG}" --ldflags --libs OUTPUT_VARIABLE LIBS)
endif()

if (TARGET_NATIVE_CLIENT)
  add_definitions("-DWITH_NATIVE_CLIENT=1")
endif()

if (TARGET_X86)
  add_definitions("-DWITH_X86=1")
endif()

if (TARGET_ARM)
  add_definitions("-DWITH_ARM=1")
endif()

if (TARGET_PTX)
  add_definitions("-DWITH_PTX=1")
endif()

if (TARGET_OPENCL)
  add_definitions("-DWITH_OPENCL=1")
endif()

if (TARGET_OPENGL)
  add_definitions("-DWITH_OPENGL=1")
endif()

if (TARGET_SPIR)
  add_definitions("-DWITH_SPIR=1")
endif()

if (TARGET_ARM64)
  add_definitions("-DWITH_ARM64=1")
endif()

add_definitions("-DLLVM_VERSION=${LLVM_VERSION}")

set(RUNTIME_CPP
  android_io
  cuda
  fake_thread_pool
  gcd_thread_pool
  ios_io
  android_clock
  linux_clock
  nogpu
  opencl
  opengl
  osx_opengl_context
  linux_opengl_context
  posix_allocator
  posix_clock
  osx_clock
  windows_clock
  posix_error_handler
  posix_io
  nacl_io
  ssp
  osx_io
  posix_math
  posix_thread_pool
  windows_thread_pool
  android_host_cpu_count
  linux_host_cpu_count
  osx_host_cpu_count
  tracing
  write_debug_image
  cuda_debug
  opencl_debug
  opengl_debug
  windows_io)
set (RUNTIME_LL
  arm
  posix_math
  pnacl_math
  ptx_dev
  spir_dev
  spir64_dev
  spir_common_dev
  x86_avx
  x86
  x86_sse41
  pnacl_math)
set (RUNTIME_BC
  compute_20
  compute_30
  compute_35)

set(RUNTIME_DIR "${CMAKE_CURRENT_SOURCE_DIR}/runtime")
file(TO_NATIVE_PATH "${RUNTIME_DIR}/" NATIVE_RUNTIME_DIR)
file(TO_NATIVE_PATH "${CMAKE_CFG_INTDIR}/" NATIVE_INT_DIR)

# ./ seems to confuse cmake on linux
if("${NATIVE_INT_DIR}" STREQUAL "./")
  set(NATIVE_INT_DIR "")
endif()

# Gather dependencies for runtime objects.
file(GLOB RUNTIME_CL_DEPENDS "${RUNTIME_DIR}/CL/*.h")
file(GLOB RUNTIME_CPP_DEPENDS "${RUNTIME_DIR}/*.cpp")
file(GLOB RUNTIME_H_DEPENDS "${RUNTIME_DIR}/*.h")
file(GLOB RUNTIME_LL_DEPENDS "${RUNTIME_DIR}/*.ll")
file(GLOB RUNTIME_BC_DEPENDS "${RUNTIME_DIR}/nvidia_libdevice_bitcode/*.bc")
set (RUNTIME_DEPENDS
  ${RUNTIME_CL_DEPENDS}
  ${RUNTIME_CPP_DEPENDS}
  ${RUNTIME_H_DEPENDS}
  ${RUNTIME_LL_DEPENDS}
  ${RUNTIME_BC_DEPENDS})

# Commands to build initial module objects.
set (INITMOD_PREFIX "_initmod_")
set (ARCHS 32 64)
set(INITIAL_MODULES )
foreach (i ${RUNTIME_CPP} )
  foreach (j ${ARCHS} )
    set(INITMOD "${INITMOD_PREFIX}${i}_${j}.cpp")
    add_custom_command(OUTPUT "${INITMOD}"
                       COMMAND ${CLANG} -fno-blocks -m${j} -DCOMPILING_HALIDE -DBITS_${j} -emit-llvm -O3 -S "${NATIVE_RUNTIME_DIR}${i}.cpp" -o "${NATIVE_INT_DIR}initmod.${i}_${j}.ll"
                       COMMAND "${LLVM_AS}" "${NATIVE_INT_DIR}initmod.${i}_${j}.ll" -o "${NATIVE_INT_DIR}initmod.${i}_${j}.bc"
                       COMMAND bitcode2cpp "${i}_${j}" < "${NATIVE_INT_DIR}initmod.${i}_${j}.bc" > "${INITMOD}"
                       COMMENT "Building initial module ${i}_${j}..."
                       VERBATIM)
    list(APPEND INITIAL_MODULES ${INITMOD})
  endforeach()
endforeach()
foreach (i ${RUNTIME_LL} )
  set(INITMOD "${INITMOD_PREFIX}${i}.cpp")
  add_custom_command(OUTPUT "${INITMOD}"
                     COMMAND "${LLVM_AS}" "${NATIVE_RUNTIME_DIR}${i}.ll" -o "${NATIVE_INT_DIR}initmod.${i}.bc"
                     COMMAND bitcode2cpp ${i}_ll < "${NATIVE_INT_DIR}initmod.${i}.bc" > "${INITMOD}"
                     COMMENT "Building initial module ${i}..."
                     VERBATIM)
  list(APPEND INITIAL_MODULES "${INITMOD}")
endforeach()
foreach (i ${RUNTIME_BC} )
  set(INITMOD "${INITMOD_PREFIX}ptx_${i}.cpp")
  add_custom_command(OUTPUT "${INITMOD}"
                     COMMAND bitcode2cpp "ptx_${i}_ll" < "${NATIVE_RUNTIME_DIR}nvidia_libdevice_bitcode/libdevice.${i}.10.bc" > "${INITMOD}"
                     COMMENT "Building initial module ptx_${i}..."
                     VERBATIM)
  list(APPEND INITIAL_MODULES "${INITMOD}")
endforeach()

add_library(InitialModules STATIC
  ${INITIAL_MODULES})

add_dependencies(InitialModules
  bitcode2cpp)

set(HEADER_FILES
  Util.h
  Type.h
  Argument.h
  Bounds.h
  BoundsInference.h
  Buffer.h
  buffer_t.h
  CodeGen_C.h
  CodeGen.h
  CodeGen_X86.h
  CodeGen_GPU_Host.h
  CodeGen_PTX_Dev.h
  CodeGen_OpenCL_Dev.h
  CodeGen_OpenGL_Dev.h
  CodeGen_GPU_Dev.h
  CodeGen_SPIR_Dev.h
  CodeGen_PNaCl.h
  Deinterleave.h
  Derivative.h
  OneToOne.h
  Extern.h
  FindCalls.h
  Func.h
  Function.h
  Image.h
  InlineReductions.h
  IntegerDivisionTable.h
  Introspection.h
  IntrusivePtr.h
  IREquality.h
  IR.h
  IRMatch.h
  IRMutator.h
  IROperator.h
  IRPrinter.h
  IRVisitor.h
  InjectOpenGLIntrinsics.h
  InjectHostDevBufferCopies.h
{'fraction_non_alphanumeric': 0.12802156935663817, 'fraction_numerical': 0.012458162885831164, 'mean_word_length': 4.2550073277967755, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5130337', 'n_tokens_mistral': 4480, 'n_tokens_neox': 4320, 'n_words': 658}