Skip to content
Merged
33 changes: 19 additions & 14 deletions cmake/TargetExportScript.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,22 @@ function(target_export_script TARGET)
set(multiValueArgs)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

get_property(target_type TARGET ${TARGET} PROPERTY TYPE)
if (NOT target_type STREQUAL "SHARED_LIBRARY")
# Linker scripts do nothing on non-shared libraries.
return()
endif ()

if (MSVC)
## TODO: implement something similar for Windows/link.exe
# https://github.com/halide/Halide/issues/4651
return()
endif ()

set(dummy_source [[ int main() { return 0; } ]])
set(is_shared "$<STREQUAL:$<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>")

# CMake doesn't recognize MSVC/link.exe's unknown-option warning.
set(extra_errors FAIL_REGEX "LNK4044: unrecognized option")
# CMake doesn't recognize MSVC/ldd link.exe's unknown-option warnings
set(extra_errors FAIL_REGEX "LNK4044: unrecognized option|warning : ignoring unknown argument")

## More linkers support the GNU syntax (ld, lld, gold), so try it first.
set(version_script "LINKER:--version-script=${ARG_GNU_LD}")
Expand All @@ -22,8 +33,8 @@ function(target_export_script TARGET)
check_cxx_source_compiles("${dummy_source}" LINKER_HAS_FLAG_VERSION_SCRIPT ${extra_errors})

if (LINKER_HAS_FLAG_VERSION_SCRIPT)
target_link_options(${TARGET} PRIVATE "$<${is_shared}:${version_script}>")
set_property(TARGET ${TARGET} APPEND PROPERTY LINK_DEPENDS "$<${is_shared}:${ARG_GNU_LD}>")
target_link_options(${TARGET} PRIVATE "${version_script}")
set_property(TARGET ${TARGET} APPEND PROPERTY LINK_DEPENDS "${ARG_GNU_LD}")
return()
endif ()

Expand All @@ -34,16 +45,10 @@ function(target_export_script TARGET)
check_cxx_source_compiles("${dummy_source}" LINKER_HAS_FLAG_EXPORTED_SYMBOLS_LIST ${extra_errors})

if (LINKER_HAS_FLAG_EXPORTED_SYMBOLS_LIST)
target_link_options(${TARGET} PRIVATE "$<${is_shared}:${exported_symbols_list}>")
set_property(TARGET ${TARGET} APPEND PROPERTY LINK_DEPENDS "$<${is_shared}:${ARG_APPLE_LD}>")
target_link_options(${TARGET} PRIVATE "${exported_symbols_list}")
set_property(TARGET ${TARGET} APPEND PROPERTY LINK_DEPENDS "${ARG_APPLE_LD}")
return()
endif ()

## TODO: implement something similar for Windows/link.exe
# https://github.com/halide/Halide/issues/4651

## Warn the user if we were supposed to have been able to attach a linker script.
if (BUILD_SHARED_LIBS AND NOT MSVC)
message(WARNING "Unknown linker! Could not attach Halide linker script.")
endif ()
message(WARNING "Unknown linker! Could not attach Halide linker script.")
endfunction()
6 changes: 3 additions & 3 deletions src/AssociativeOpsTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,16 @@ map<TableKey, vector<AssociativePattern>> pattern_tables;
Expr one_##index = make_const((t), 1); \
Expr neg_one_##index = make_const((t), -1); \
Expr tmax_##index = (t).max(); \
Expr tmin_##index = (t).min();
Expr tmin_##index = (t).min()

#define declare_vars_single(types) \
internal_assert((types).size() == 1); \
declare_vars((types)[0], 0)

#define declare_vars_double(types) \
internal_assert((types).size() == 2); \
declare_vars((types)[0], 0) \
declare_vars((types)[1], 1)
declare_vars((types)[0], 0); \
declare_vars((types)[1], 1)

void populate_ops_table_single_general_add(const vector<Type> &types, vector<AssociativePattern> &table) {
declare_vars_single(types);
Expand Down
4 changes: 2 additions & 2 deletions src/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -568,12 +568,12 @@ class Buffer {
Expr operator()(const Expr &first, Args... rest) const {
std::vector<Expr> args = {first, rest...};
return (*this)(args);
};
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, I'd actually love to enable whatever warnings complains about this, it's a minor pet peeve of mine


template<typename... Args>
Expr operator()(const std::vector<Expr> &args) const {
return buffer_accessor(Buffer<>(*this), args);
};
}
// @}

/** Copy to the GPU, using the device API that is the default for the given Target. */
Expand Down
118 changes: 76 additions & 42 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,7 @@ add_custom_command(OUTPUT "${Halide_BINARY_DIR}/include/Halide.h"
DEPENDS build_halide_h "${LICENSE_PATH}" ${HEADER_FILES}
WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}"
VERBATIM)
add_custom_target(HalideIncludes ALL
DEPENDS "${Halide_BINARY_DIR}/include/Halide.h")
add_custom_target(HalideIncludes ALL DEPENDS "${Halide_BINARY_DIR}/include/Halide.h")

##
# Define the Halide library target.
Expand All @@ -369,10 +368,8 @@ add_library(Halide::Halide ALIAS Halide)

target_link_libraries(Halide PRIVATE Halide::LLVM)
target_link_libraries(Halide PUBLIC Halide::LanguageOptions)
target_compile_definitions(Halide
PRIVATE
$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,STATIC_LIBRARY>:Halide_STATIC_DEFINE>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:WITH_INTROSPECTION>)
target_compile_definitions(Halide PRIVATE $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,STATIC_LIBRARY>:Halide_STATIC_DEFINE>)
target_compile_features(Halide PUBLIC cxx_std_11)

include(TargetExportScript)
## TODO: implement something similar for Windows/link.exe
Expand All @@ -386,57 +383,94 @@ set_target_properties(Halide PROPERTIES
VERSION ${Halide_VERSION}
SOVERSION ${Halide_VERSION_MAJOR})

target_include_directories(Halide INTERFACE "$<BUILD_INTERFACE:${Halide_BINARY_DIR}/include>")
add_dependencies(Halide HalideIncludes)

option(Halide_WITH_INTROSPECTION "Enable use of debugging symbols for default Func, Var, etc. names" ON)
if (Halide_WITH_INTROSPECTION)
target_compile_definitions(Halide PRIVATE WITH_INTROSPECTION)
endif ()

if (TARGET wabt-obj)
target_link_libraries(Halide PRIVATE wabt-obj)
target_compile_definitions(Halide PRIVATE WITH_WABT)
endif ()

##
# Include paths for libHalide
##

set(Halide_INCLUDE_PATH "$<BUILD_INTERFACE:${Halide_BINARY_DIR}/include>")
target_include_directories(Halide INTERFACE ${Halide_INCLUDE_PATH})

##
# Set compiler options for libHalide
##

target_compile_options(Halide
PRIVATE
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wall>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-unused-function>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wcast-qual>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wignored-qualifiers>
target_compile_options(
Halide
PRIVATE
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wall>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wcast-qual>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wignored-qualifiers>

$<$<COMPILE_LANG_AND_ID:CXX,GNU,Clang,AppleClang>:-Woverloaded-virtual>
$<$<COMPILE_LANG_AND_ID:CXX,GNU>:-Wsuggest-override>
$<$<COMPILE_LANG_AND_ID:CXX,Clang,AppleClang>:-Winconsistent-missing-override>
$<$<COMPILE_LANG_AND_ID:CXX,Clang,AppleClang>:-Winconsistent-missing-destructor-override>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-c++98-compat-pedantic>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-c++98-compat>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-cast-align>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-comma>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-covered-switch-default>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-deprecated-declarations>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-documentation-unknown-command>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-documentation>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-double-promotion>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-exit-time-destructors>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-float-conversion>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-float-equal>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-global-constructors>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-implicit-float-conversion>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-implicit-int-conversion>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-implicit-int-float-conversion>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-missing-field-initializers>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-missing-prototypes>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-nonportable-system-include-path>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-old-style-cast>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-reserved-id-macro> # can't have an underscore followed by a capital letter
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-return-std-move-in-c++11>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-shadow-field-in-constructor>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-shadow-field>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-shadow>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-shorten-64-to-32>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-sign-conversion>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-switch-enum>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-undef>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-undefined-func-template>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-unused-function>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-unused-macros>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-unused-member-function>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-unused-parameter>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-unused-template>

$<$<CXX_COMPILER_ID:MSVC>:/W3>
$<$<CXX_COMPILER_ID:MSVC>:/wd4018> # disable "signed/unsigned mismatch"
$<$<CXX_COMPILER_ID:MSVC>:/wd4503> # disable "decorated name length exceeded, name was truncated"
$<$<CXX_COMPILER_ID:MSVC>:/wd4267> # disable "conversion from 'size_t' to 'int', possible loss of data"
$<$<CXX_COMPILER_ID:MSVC>:/wd4800> # forcing value to bool 'true' or 'false' (performance warning)
$<$<CXX_COMPILER_ID:MSVC>:/wd4244> # 4244: conversion, possible loss of data
$<$<CXX_COMPILER_ID:MSVC>:/wd4267> # 4267: conversion, possible loss of data
$<$<CXX_COMPILER_ID:MSVC>:/wd4800> # 4800: BOOL -> true or false
$<$<CXX_COMPILER_ID:MSVC>:/wd4996> # 4996: compiler encountered deprecated declaration
$<$<COMPILE_LANG_AND_ID:CXX,GNU,Clang,AppleClang>:-Woverloaded-virtual>
$<$<COMPILE_LANG_AND_ID:CXX,GNU>:-Wsuggest-override>
$<$<COMPILE_LANG_AND_ID:CXX,Clang,AppleClang>:-Winconsistent-missing-override>
$<$<COMPILE_LANG_AND_ID:CXX,Clang,AppleClang>:-Winconsistent-missing-destructor-override>

# Injected from recent LLVM:
$<$<CXX_COMPILER_ID:MSVC>:/wd4141> # 'inline' used more than once
$<$<CXX_COMPILER_ID:MSVC>:/wd4146> # unary minus applied to unsigned type
$<$<CXX_COMPILER_ID:MSVC>:/wd4291> # No matching operator delete found
$<$<CXX_COMPILER_ID:MSVC>:/W3>
$<$<CXX_COMPILER_ID:MSVC>:/wd4018> # disable "signed/unsigned mismatch"
$<$<CXX_COMPILER_ID:MSVC>:/wd4503> # disable "decorated name length exceeded, name was truncated"
$<$<CXX_COMPILER_ID:MSVC>:/wd4267> # disable "conversion from 'size_t' to 'int', possible loss of data"
$<$<CXX_COMPILER_ID:MSVC>:/wd4800> # forcing value to bool 'true' or 'false' (performance warning)
$<$<CXX_COMPILER_ID:MSVC>:/wd4244> # 4244: conversion, possible loss of data
$<$<CXX_COMPILER_ID:MSVC>:/wd4267> # 4267: conversion, possible loss of data
$<$<CXX_COMPILER_ID:MSVC>:/wd4800> # 4800: BOOL -> true or false
$<$<CXX_COMPILER_ID:MSVC>:/wd4996> # 4996: compiler encountered deprecated declaration

# We could expose the /MP flag to all targets, but that might end up saturating the build
# since multiple MSBuild projects might get built in parallel, each of which compiling their
# source files in parallel; the Halide library itself is a "knot" point of the build graph,
# so compiling its files in parallel should not oversubscribe the system
$<$<CXX_COMPILER_ID:MSVC>:/MP>
)
# Injected from recent LLVM:
$<$<CXX_COMPILER_ID:MSVC>:/wd4141> # 'inline' used more than once
$<$<CXX_COMPILER_ID:MSVC>:/wd4146> # unary minus applied to unsigned type
$<$<CXX_COMPILER_ID:MSVC>:/wd4291> # No matching operator delete found
)

if (CMAKE_GENERATOR MATCHES "Visual Studio")
# We could expose the /MP flag to all targets, but that might end up saturating the build
# since multiple MSBuild projects might get built in parallel, each of which compiling their
# source files in parallel; the Halide library itself is a "knot" point of the build graph,
# so compiling its files in parallel should not oversubscribe the system
target_compile_options(Halide PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/MP>)
endif ()

target_compile_definitions(Halide
PRIVATE
Expand Down
2 changes: 0 additions & 2 deletions src/CodeGen_Hexagon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,6 @@ class SloppyUnpredicateLoadsAndStores : public IRMutator {

return Call::make(op->type, Call::if_then_else,
{condition, load, make_zero(op->type)}, Call::Intrinsic);

return load;
Comment on lines -286 to -287
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch. I wonder if this was a bad merge. Probably worth turning on this warning explicitly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yow. I'm genuinely surprised this is merely a warning.

} else {
// It's a predicated vector gather. Just scalarize. We'd
// prefer to keep it in a loop, but that would require
Expand Down
2 changes: 1 addition & 1 deletion src/CodeGen_LLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ using std::vector;

#ifdef WITH_NVPTX
#define InitializeNVPTXTarget() InitializeTarget(NVPTX)
#define InitializeNVPTXAsmParser() InitializeAsmParser(NVPTX)
// #define InitializeNVPTXAsmParser() InitializeAsmParser(NVPTX) // there is no ASM parser for NVPTX
#define InitializeNVPTXAsmPrinter() InitializeAsmPrinter(NVPTX)
#endif

Expand Down
14 changes: 7 additions & 7 deletions src/IRMatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -2206,7 +2206,7 @@ struct CanProve {
ty.code = halide_type_uint;
ty.bits = 1;
ty.lanes = condition.type().lanes();
};
}
};

template<typename A, typename Prover>
Expand Down Expand Up @@ -2243,7 +2243,7 @@ struct IsFloat {
ty.code = halide_type_uint;
ty.bits = 1;
ty.lanes = t.lanes();
};
}
};

template<typename A>
Expand Down Expand Up @@ -2281,7 +2281,7 @@ struct IsInt {
ty.code = halide_type_uint;
ty.bits = 1;
ty.lanes = t.lanes();
};
}
};

template<typename A>
Expand Down Expand Up @@ -2323,7 +2323,7 @@ struct IsUInt {
ty.code = halide_type_uint;
ty.bits = 1;
ty.lanes = t.lanes();
};
}
};

template<typename A>
Expand Down Expand Up @@ -2364,7 +2364,7 @@ struct IsScalar {
ty.code = halide_type_uint;
ty.bits = 1;
ty.lanes = t.lanes();
};
}
};

template<typename A>
Expand Down Expand Up @@ -2399,7 +2399,7 @@ struct IsMaxValue {
}
ty.code = halide_type_uint;
ty.bits = 1;
};
}
};

template<typename A>
Expand Down Expand Up @@ -2436,7 +2436,7 @@ struct IsMinValue {
}
ty.code = halide_type_uint;
ty.bits = 1;
};
}
};

template<typename A>
Expand Down
4 changes: 2 additions & 2 deletions src/IRVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class VariadicVisitor {
ExprRet dispatch_expr(const BaseExprNode *node, Args &&...args) {
if (node == nullptr) {
return ExprRet{};
};
}
switch (node->node_type) {
case IRNodeType::IntImm:
return ((T *)this)->visit((const IntImm *)node, std::forward<Args>(args)...);
Expand Down Expand Up @@ -250,7 +250,7 @@ class VariadicVisitor {
StmtRet dispatch_stmt(const BaseStmtNode *node, Args &&...args) {
if (node == nullptr) {
return StmtRet{};
};
}
switch (node->node_type) {
case IRNodeType::IntImm:
case IRNodeType::UIntImm:
Expand Down
8 changes: 8 additions & 0 deletions src/Introspection.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#include "Introspection.h"

#if defined(_MSC_VER)
#undef WITH_INTROSPECTION
#elif defined(__has_include)
#if !__has_include(<execinfo.h>)
#undef WITH_INTROSPECTION
#endif
#endif

#ifdef WITH_INTROSPECTION

#include "Debug.h"
Expand Down
2 changes: 1 addition & 1 deletion src/IntrusivePtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct IntrusivePtr {
if (p) {
ref_count(p).increment();
}
};
}

void decref(T *p) {
if (p) {
Expand Down
2 changes: 1 addition & 1 deletion src/LowerWarpShuffles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ class LowerWarpShuffles : public IRMutator {

Expr wild = Variable::make(Int(32), "*");
vector<Expr> result;
int bits;
int bits = 0;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason this isn't needed is extremely subtle: the function is_const_power_of_two_integer returns true iff it initializes bits. The first read of bits is guarded by short-circuit && below. ClangCL isn't clever enough to see this, and I don't blame it.

There's no downside to this (this is not performance-critical) and disabling uninitialized use warnings seems significantly worse.


// Move this_lane as far left as possible in the expression to
// reduce the number of cases to check below.
Expand Down
2 changes: 1 addition & 1 deletion src/Memoization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class KeyInfo {
// for the target function. Make sure it takes 4 bytes in cache key.
Expr key_size() {
return cast<int32_t>(key_size_expr);
};
}

// Code to fill in the Allocation named key_name with the byte of
// the key. The Allocation is guaranteed to be 1d, of type uint8_t
Expand Down
2 changes: 1 addition & 1 deletion src/ParamMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class ParamMap {
pa.mapped_param = v;
pa.buf_out_param = nullptr;
mapping[p.parameter()] = pa;
};
}

void set(const ImageParam &p, const Buffer<> &buf) {
set(p, buf, nullptr);
Expand Down
Loading