Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 75 additions & 22 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,9 @@ target_sources(
# keep-sorted end
)

# The sources that go into libHalide. For the sake of IDE support, headers that
# exist in src/ but are not public should be included here.
# The sources that go into libHalide and do not include any LLVM or WASM headers.
# For the sake of IDE support, headers that exist in src/ but are not public
# should be included here.
target_sources(
Halide
PRIVATE
Expand Down Expand Up @@ -253,24 +254,14 @@ target_sources(
CanonicalizeGPUVars.cpp
ClampUnsafeAccesses.cpp
Closure.cpp
CodeGen_ARM.cpp
CodeGen_C.cpp
CodeGen_D3D12Compute_Dev.cpp
CodeGen_GPU_Dev.cpp
CodeGen_Hexagon.cpp
CodeGen_Internal.cpp
CodeGen_LLVM.cpp
CodeGen_Metal_Dev.cpp
CodeGen_OpenCL_Dev.cpp
CodeGen_Posix.cpp
CodeGen_PowerPC.cpp
CodeGen_PTX_Dev.cpp
CodeGen_PyTorch.cpp
CodeGen_RISCV.cpp
CodeGen_Vulkan_Dev.cpp
CodeGen_WebAssembly.cpp
CodeGen_WebGPU_Dev.cpp
CodeGen_X86.cpp
CompilerLogger.cpp
ConstantBounds.cpp
ConstantInterval.cpp
Expand Down Expand Up @@ -305,7 +296,6 @@ target_sources(
FuseGPUThreadLoops.cpp
FuzzFloatStores.cpp
Generator.cpp
HexagonOffload.cpp
HexagonOptimize.cpp
ImageParam.cpp
InferArguments.cpp
Expand All @@ -321,18 +311,14 @@ target_sources(
IROperator.cpp
IRPrinter.cpp
IRVisitor.cpp
JITModule.cpp
Lambda.cpp
Lerp.cpp
LICM.cpp
LLVM_Output.cpp
LLVM_Runtime_Linker.cpp
LoopCarry.cpp
Lower.cpp
LowerParallelTasks.cpp
LowerWarpShuffles.cpp
Memoization.cpp
Module.cpp
ModulusRemainder.cpp
Monotonic.cpp
ObjectInstanceRegistry.cpp
Expand Down Expand Up @@ -413,11 +399,33 @@ target_sources(
Util.cpp
Var.cpp
VectorizeLoops.cpp
WasmExecutor.cpp
WrapCalls.cpp
# keep-sorted end
)

# LLVM sources live in their own object library so they can have a separate PCH.
add_library(
Halide_LLVM_srcs OBJECT
# keep-sorted start case=no
CodeGen_ARM.cpp
CodeGen_Hexagon.cpp
CodeGen_Internal.cpp
CodeGen_LLVM.cpp
CodeGen_Posix.cpp
CodeGen_PowerPC.cpp
CodeGen_PTX_Dev.cpp
CodeGen_RISCV.cpp
CodeGen_WebAssembly.cpp
CodeGen_X86.cpp
HexagonOffload.cpp
JITModule.cpp
LLVM_Output.cpp
LLVM_Runtime_Linker.cpp
Module.cpp
WasmExecutor.cpp
# keep-sorted end
)

set(C_TEMPLATE_FILES
CodeGen_C_prologue
CodeGen_C_vectors
Expand Down Expand Up @@ -584,13 +592,14 @@ if (Halide_WASM_BACKEND STREQUAL "wabt")
find_package(wabt REQUIRED)
_Halide_pkgdep(wabt)

target_link_libraries(Halide PRIVATE wabt::wabt)
target_compile_definitions(Halide PRIVATE WITH_WABT)
target_compile_definitions(Halide_LLVM_srcs PRIVATE WITH_WABT)
target_link_libraries(Halide_LLVM_srcs PRIVATE wabt::wabt)
elseif (Halide_WASM_BACKEND STREQUAL "V8")
find_package(V8 REQUIRED)
_Halide_pkgdep(V8)
target_compile_definitions(Halide PRIVATE WITH_V8)
target_link_libraries(Halide PRIVATE V8::V8)

target_compile_definitions(Halide_LLVM_srcs PRIVATE WITH_V8)
target_link_libraries(Halide_LLVM_srcs PRIVATE V8::V8)
elseif (Halide_WASM_BACKEND)
message(FATAL_ERROR "Unknown Halide_WASM_BACKEND `${Halide_WASM_BACKEND}`")
endif ()
Expand Down Expand Up @@ -662,6 +671,50 @@ else ()
)
endif ()

##
# Precompiled headers
##

# On MSVC, cmake_pch.cxx compiles to a real .obj whose _PchSym_ markers leak
# into the auto-generated exports.def (via CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS),
# causing LNK2001/LNK4022. Disable PCH on MSVC entirely to avoid this.
if (NOT MSVC)
# Non-LLVM sources get a PCH covering the most expensive standard library
# headers.
target_precompile_headers(Halide PRIVATE Halide_pch.h)

# Util.cpp implements run_with_large_stack(), which requires _XOPEN_SOURCE
# to be defined before any includes. The PCH force-include violates this.
set_source_files_properties(Util.cpp PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
endif ()

target_compile_features(Halide_LLVM_srcs PRIVATE cxx_std_17)
set_target_properties(Halide_LLVM_srcs PROPERTIES POSITION_INDEPENDENT_CODE ON)

# Mirror compile flags from the main Halide target.
target_compile_definitions(
Halide_LLVM_srcs PRIVATE
"$<TARGET_PROPERTY:Halide,COMPILE_DEFINITIONS>"
"$<$<STREQUAL:$<TARGET_PROPERTY:Halide,TYPE>,SHARED_LIBRARY>:Halide_EXPORTS>"
)
target_compile_options(
Halide_LLVM_srcs PRIVATE
"$<TARGET_PROPERTY:Halide,COMPILE_OPTIONS>"
)

foreach (backend IN LISTS Halide_LLVM_COMPONENTS)
target_link_libraries(Halide_LLVM_srcs PRIVATE Halide_LLVM::${backend})
endforeach ()

# On MSVC, cmake_pch.cxx compiles to a real .obj whose _PchSym_ markers leak
# into the auto-generated exports.def (via CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS),
# causing LNK2001/LNK4022. Disable the LLVM PCH on MSVC to avoid this.
if (NOT MSVC)
target_precompile_headers(Halide_LLVM_srcs PRIVATE Halide_llvm_pch.h)
endif ()

target_link_libraries(Halide PRIVATE Halide_LLVM_srcs)

##
# Add autoschedulers to the build.
##
Expand Down
12 changes: 12 additions & 0 deletions src/Halide_llvm_pch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Precompiled header for the LLVM-dependent Halide sources (Halide_LLVM_srcs
// object library). Extends the common PCH with LLVM_Headers.h.
#ifndef HALIDE_LLVM_PCH_H
#define HALIDE_LLVM_PCH_H

// LLVM umbrella header
#include "LLVM_Headers.h"

// Common standard library and core Halide headers (shared with non-LLVM sources).
#include "Halide_pch.h"

#endif // HALIDE_LLVM_PCH_H
23 changes: 23 additions & 0 deletions src/Halide_pch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Precompiled header for the main (non-LLVM) Halide sources.
// This covers the standard library headers and core Halide headers that are
// included by the vast majority of translation units. Do not add LLVM headers
// here; those belong in Halide_llvm_pch.h together with the LLVM object library.
#ifndef HALIDE_PCH_H
#define HALIDE_PCH_H

// Standard library headers
#include <algorithm>
#include <functional>
#include <map>
#include <optional>
#include <sstream>
#include <string>
#include <string_view>
#include <vector>

// Core Halide headers included by nearly every TU
#include "Error.h"
#include "Expr.h"
#include "Type.h"

#endif // HALIDE_PCH_H
Loading