diff --git a/cmake/TargetExportScript.cmake b/cmake/TargetExportScript.cmake index 7a3b38469fac..cbb980baa129 100644 --- a/cmake/TargetExportScript.cmake +++ b/cmake/TargetExportScript.cmake @@ -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 "$,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}") @@ -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 () @@ -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() diff --git a/src/AssociativeOpsTable.cpp b/src/AssociativeOpsTable.cpp index afe886567936..c0436fade13e 100644 --- a/src/AssociativeOpsTable.cpp +++ b/src/AssociativeOpsTable.cpp @@ -130,7 +130,7 @@ map> 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); \ @@ -138,8 +138,8 @@ map> pattern_tables; #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 &types, vector &table) { declare_vars_single(types); diff --git a/src/Buffer.h b/src/Buffer.h index da4c19b2c027..aa42c6aaf231 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -568,12 +568,12 @@ class Buffer { Expr operator()(const Expr &first, Args... rest) const { std::vector args = {first, rest...}; return (*this)(args); - }; + } template Expr operator()(const std::vector &args) const { return buffer_accessor(Buffer<>(*this), args); - }; + } // @} /** Copy to the GPU, using the device API that is the default for the given Target. */ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e2400c9ae1d7..107557bba85d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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. @@ -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 - $<$,STATIC_LIBRARY>:Halide_STATIC_DEFINE> - $<$:WITH_INTROSPECTION>) +target_compile_definitions(Halide PRIVATE $<$,STATIC_LIBRARY>:Halide_STATIC_DEFINE>) +target_compile_features(Halide PUBLIC cxx_std_11) include(TargetExportScript) ## TODO: implement something similar for Windows/link.exe @@ -386,57 +383,94 @@ set_target_properties(Halide PROPERTIES VERSION ${Halide_VERSION} SOVERSION ${Halide_VERSION_MAJOR}) +target_include_directories(Halide INTERFACE "$") 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 "$") -target_include_directories(Halide INTERFACE ${Halide_INCLUDE_PATH}) - ## # Set compiler options for libHalide ## -target_compile_options(Halide - PRIVATE - $<$:-Wall> - $<$:-Wno-unused-function> - $<$:-Wcast-qual> - $<$:-Wignored-qualifiers> +target_compile_options( + Halide + PRIVATE + $<$:-Wall> + $<$:-Wcast-qual> + $<$:-Wignored-qualifiers> - $<$:-Woverloaded-virtual> - $<$:-Wsuggest-override> - $<$:-Winconsistent-missing-override> - $<$:-Winconsistent-missing-destructor-override> + $<$:-Wno-c++98-compat-pedantic> + $<$:-Wno-c++98-compat> + $<$:-Wno-cast-align> + $<$:-Wno-comma> + $<$:-Wno-covered-switch-default> + $<$:-Wno-deprecated-declarations> + $<$:-Wno-documentation-unknown-command> + $<$:-Wno-documentation> + $<$:-Wno-double-promotion> + $<$:-Wno-exit-time-destructors> + $<$:-Wno-float-conversion> + $<$:-Wno-float-equal> + $<$:-Wno-global-constructors> + $<$:-Wno-implicit-float-conversion> + $<$:-Wno-implicit-int-conversion> + $<$:-Wno-implicit-int-float-conversion> + $<$:-Wno-missing-field-initializers> + $<$:-Wno-missing-prototypes> + $<$:-Wno-nonportable-system-include-path> + $<$:-Wno-old-style-cast> + $<$:-Wno-reserved-id-macro> # can't have an underscore followed by a capital letter + $<$:-Wno-return-std-move-in-c++11> + $<$:-Wno-shadow-field-in-constructor> + $<$:-Wno-shadow-field> + $<$:-Wno-shadow> + $<$:-Wno-shorten-64-to-32> + $<$:-Wno-sign-conversion> + $<$:-Wno-switch-enum> + $<$:-Wno-undef> + $<$:-Wno-undefined-func-template> + $<$:-Wno-unused-function> + $<$:-Wno-unused-macros> + $<$:-Wno-unused-member-function> + $<$:-Wno-unused-parameter> + $<$:-Wno-unused-template> - $<$:/W3> - $<$:/wd4018> # disable "signed/unsigned mismatch" - $<$:/wd4503> # disable "decorated name length exceeded, name was truncated" - $<$:/wd4267> # disable "conversion from 'size_t' to 'int', possible loss of data" - $<$:/wd4800> # forcing value to bool 'true' or 'false' (performance warning) - $<$:/wd4244> # 4244: conversion, possible loss of data - $<$:/wd4267> # 4267: conversion, possible loss of data - $<$:/wd4800> # 4800: BOOL -> true or false - $<$:/wd4996> # 4996: compiler encountered deprecated declaration + $<$:-Woverloaded-virtual> + $<$:-Wsuggest-override> + $<$:-Winconsistent-missing-override> + $<$:-Winconsistent-missing-destructor-override> - # Injected from recent LLVM: - $<$:/wd4141> # 'inline' used more than once - $<$:/wd4146> # unary minus applied to unsigned type - $<$:/wd4291> # No matching operator delete found + $<$:/W3> + $<$:/wd4018> # disable "signed/unsigned mismatch" + $<$:/wd4503> # disable "decorated name length exceeded, name was truncated" + $<$:/wd4267> # disable "conversion from 'size_t' to 'int', possible loss of data" + $<$:/wd4800> # forcing value to bool 'true' or 'false' (performance warning) + $<$:/wd4244> # 4244: conversion, possible loss of data + $<$:/wd4267> # 4267: conversion, possible loss of data + $<$:/wd4800> # 4800: BOOL -> true or false + $<$:/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 - $<$:/MP> - ) + # Injected from recent LLVM: + $<$:/wd4141> # 'inline' used more than once + $<$:/wd4146> # unary minus applied to unsigned type + $<$:/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 $<$:/MP>) +endif () target_compile_definitions(Halide PRIVATE diff --git a/src/CodeGen_Hexagon.cpp b/src/CodeGen_Hexagon.cpp index 91d13b13596d..6dd1a9712446 100644 --- a/src/CodeGen_Hexagon.cpp +++ b/src/CodeGen_Hexagon.cpp @@ -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; } else { // It's a predicated vector gather. Just scalarize. We'd // prefer to keep it in a loop, but that would require diff --git a/src/CodeGen_LLVM.cpp b/src/CodeGen_LLVM.cpp index 492c589f96ce..46b8f47fbc4b 100644 --- a/src/CodeGen_LLVM.cpp +++ b/src/CodeGen_LLVM.cpp @@ -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 diff --git a/src/IRMatch.h b/src/IRMatch.h index a1dc5fe14d51..305cdce5277e 100644 --- a/src/IRMatch.h +++ b/src/IRMatch.h @@ -2206,7 +2206,7 @@ struct CanProve { ty.code = halide_type_uint; ty.bits = 1; ty.lanes = condition.type().lanes(); - }; + } }; template @@ -2243,7 +2243,7 @@ struct IsFloat { ty.code = halide_type_uint; ty.bits = 1; ty.lanes = t.lanes(); - }; + } }; template @@ -2281,7 +2281,7 @@ struct IsInt { ty.code = halide_type_uint; ty.bits = 1; ty.lanes = t.lanes(); - }; + } }; template @@ -2323,7 +2323,7 @@ struct IsUInt { ty.code = halide_type_uint; ty.bits = 1; ty.lanes = t.lanes(); - }; + } }; template @@ -2364,7 +2364,7 @@ struct IsScalar { ty.code = halide_type_uint; ty.bits = 1; ty.lanes = t.lanes(); - }; + } }; template @@ -2399,7 +2399,7 @@ struct IsMaxValue { } ty.code = halide_type_uint; ty.bits = 1; - }; + } }; template @@ -2436,7 +2436,7 @@ struct IsMinValue { } ty.code = halide_type_uint; ty.bits = 1; - }; + } }; template diff --git a/src/IRVisitor.h b/src/IRVisitor.h index f5bf8b0faef4..f29bedc182bc 100644 --- a/src/IRVisitor.h +++ b/src/IRVisitor.h @@ -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)...); @@ -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: diff --git a/src/Introspection.cpp b/src/Introspection.cpp index c4410d9d909a..42a0e654df99 100644 --- a/src/Introspection.cpp +++ b/src/Introspection.cpp @@ -1,5 +1,13 @@ #include "Introspection.h" +#if defined(_MSC_VER) +#undef WITH_INTROSPECTION +#elif defined(__has_include) +#if !__has_include() +#undef WITH_INTROSPECTION +#endif +#endif + #ifdef WITH_INTROSPECTION #include "Debug.h" diff --git a/src/IntrusivePtr.h b/src/IntrusivePtr.h index a7d4b9cfae32..f233420c8009 100644 --- a/src/IntrusivePtr.h +++ b/src/IntrusivePtr.h @@ -71,7 +71,7 @@ struct IntrusivePtr { if (p) { ref_count(p).increment(); } - }; + } void decref(T *p) { if (p) { diff --git a/src/LowerWarpShuffles.cpp b/src/LowerWarpShuffles.cpp index 449b6e31ed19..428c10400ad4 100644 --- a/src/LowerWarpShuffles.cpp +++ b/src/LowerWarpShuffles.cpp @@ -571,7 +571,7 @@ class LowerWarpShuffles : public IRMutator { Expr wild = Variable::make(Int(32), "*"); vector result; - int bits; + int bits = 0; // Move this_lane as far left as possible in the expression to // reduce the number of cases to check below. diff --git a/src/Memoization.cpp b/src/Memoization.cpp index a93e34ea879d..09c4355a3868 100644 --- a/src/Memoization.cpp +++ b/src/Memoization.cpp @@ -215,7 +215,7 @@ class KeyInfo { // for the target function. Make sure it takes 4 bytes in cache key. Expr key_size() { return cast(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 diff --git a/src/ParamMap.h b/src/ParamMap.h index bf79fd02793e..6a67c95edc0a 100644 --- a/src/ParamMap.h +++ b/src/ParamMap.h @@ -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); diff --git a/src/Schedule.cpp b/src/Schedule.cpp index 831f27d9e665..c695bfc2d497 100644 --- a/src/Schedule.cpp +++ b/src/Schedule.cpp @@ -224,7 +224,8 @@ struct FuncScheduleContents { Expr memoize_eviction_key; FuncScheduleContents() - : store_level(LoopLevel::inlined()), compute_level(LoopLevel::inlined()){}; + : store_level(LoopLevel::inlined()), compute_level(LoopLevel::inlined()) { + } // Pass an IRMutator through to all Exprs referenced in the FuncScheduleContents void mutate(IRMutator *mutator) { diff --git a/src/SelectGPUAPI.cpp b/src/SelectGPUAPI.cpp index 45fcd5ddda22..19467be8ce42 100644 --- a/src/SelectGPUAPI.cpp +++ b/src/SelectGPUAPI.cpp @@ -44,7 +44,7 @@ class SelectGPUAPI : public IRMutator { SelectGPUAPI(const Target &t) { default_api = get_default_device_api_for_target(t); parent_api = DeviceAPI::Host; - }; + } }; } // namespace diff --git a/src/Simplify_Exprs.cpp b/src/Simplify_Exprs.cpp index 9479e324e9a5..663e0de2680e 100644 --- a/src/Simplify_Exprs.cpp +++ b/src/Simplify_Exprs.cpp @@ -100,7 +100,7 @@ Expr Simplify::visit(const VectorReduce *op, ExprInfo *bounds) { bounds->alignment = ModulusRemainder{}; break; } - }; + } // We can pull multiplications by a broadcast out of horizontal // additions and do the horizontal addition earlier. This means we diff --git a/src/StmtToHtml.cpp b/src/StmtToHtml.cpp index af56cff31ebd..55f1831953a5 100644 --- a/src/StmtToHtml.cpp +++ b/src/StmtToHtml.cpp @@ -375,7 +375,7 @@ class StmtToHtml : public IRVisitor { stream << var(op->name); stream << close_expand_button() << " {"; stream << close_span(); - ; + stream << open_div(op->is_producer ? "ProduceBody Indent" : "ConsumeBody Indent", produce_id); print(op->body); stream << close_div(); diff --git a/src/Util.cpp b/src/Util.cpp index 5f245d015de3..c4ec77dce262 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -102,9 +102,8 @@ std::string get_env_variable(char const *env_var_name) { if (lvl) { return std::string(lvl); } -#endif - return ""; +#endif } string running_program_name() { @@ -529,7 +528,7 @@ struct TickStackEntry { int line; }; -vector tick_stack; +static vector tick_stack; void halide_tic_impl(const char *file, int line) { string f = file; @@ -609,7 +608,7 @@ void WINAPI generic_fiber_entry_point(LPVOID argument) { void run_with_large_stack(const std::function &action) { #if _WIN32 - constexpr SIZE_T required_stack = 8 * 1024 * 1024; + constexpr auto required_stack = 8 * 1024 * 1024; // Only exists for its address, which is used to compute remaining stack space. ULONG_PTR approx_stack_pos; diff --git a/src/VectorizeLoops.cpp b/src/VectorizeLoops.cpp index e6b8ff150e9e..9987dbf2566c 100644 --- a/src/VectorizeLoops.cpp +++ b/src/VectorizeLoops.cpp @@ -1672,4 +1672,4 @@ Stmt vectorize_loops(const Stmt &stmt, const map &env, const T } } // namespace Internal -} // namespace Halide \ No newline at end of file +} // namespace Halide diff --git a/src/WasmExecutor.cpp b/src/WasmExecutor.cpp index a1254a0ca436..9931df6582ff 100644 --- a/src/WasmExecutor.cpp +++ b/src/WasmExecutor.cpp @@ -1586,11 +1586,11 @@ WasmModule WasmModule::compile( #if !defined(WITH_WABT) user_error << "Cannot run JITted WebAssembly without configuring a WebAssembly engine."; return WasmModule(); -#endif - +#else WasmModule wasm_module; wasm_module.contents = new WasmModuleContents(module, arguments, fn_name, jit_externs, extern_deps); return wasm_module; +#endif } /** Run generated previously compiled wasm code with a set of arguments. */ diff --git a/src/runtime/HalideBuffer.h b/src/runtime/HalideBuffer.h index 64ec29c08c9c..6f8265478ab1 100644 --- a/src/runtime/HalideBuffer.h +++ b/src/runtime/HalideBuffer.h @@ -491,7 +491,8 @@ class Buffer { } Dimension(const halide_dimension_t &dim) - : d(dim){}; + : d(dim) { + } }; /** Access the shape of the buffer */