From e9b9bdc1ca327a10435af769a4f048d637ab4afd Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Fri, 26 Jul 2024 11:13:49 -0700 Subject: [PATCH] Don't use le32/le64 (#8344) Use i386/x86-64 and wasm32/wasm64 targets instead of le32/le64 for the runtime. --- Makefile | 32 +++++++++++++++++++++++++++----- src/runtime/CMakeLists.txt | 22 ++++++++++++++++------ 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index a49615a91a91..b84f7ea1f7fc 100644 --- a/Makefile +++ b/Makefile @@ -1053,9 +1053,9 @@ $(BIN_DIR)/build_halide_h: $(ROOT_DIR)/tools/build_halide_h.cpp .SECONDARY: # Compile generic 32- or 64-bit code -# (The 'nacl' is a red herring. This is just a generic 32-bit little-endian target.) -RUNTIME_TRIPLE_32 = "le32-unknown-nacl-unknown" -RUNTIME_TRIPLE_64 = "le64-unknown-unknown-unknown" +# Don't be fooled: these are just generic 32/64-bit targets for our purposes here +RUNTIME_TRIPLE_32 = "i386-unknown-unknown-unknown" +RUNTIME_TRIPLE_64 = "x86_64-unknown-unknown-unknown" # Windows requires special handling. The generic windows_* modules must have -fpic elided # and (for 64 bit) must set wchar to be 2 bytes. The windows_*_x86 and windows_*_arm @@ -1068,7 +1068,11 @@ RUNTIME_TRIPLE_WIN_X86_32 = "i386-unknown-windows-unknown" RUNTIME_TRIPLE_WIN_X86_64 = "x86_64-unknown-windows-unknown" RUNTIME_TRIPLE_WIN_ARM_32 = "arm-unknown-windows-unknown" RUNTIME_TRIPLE_WIN_ARM_64 = "aarch64-unknown-windows-unknown" -RUNTIME_TRIPLE_WIN_GENERIC_64 = "le64-unknown-windows-unknown" +# TODO: was le64 here, not sure if this is correct or not +RUNTIME_TRIPLE_WIN_GENERIC_64 = "x86_64-unknown-windows-unknown" + +RUNTIME_TRIPLE_WEBGPU_32 = "wasm32-unknown-unknown-unknown" +RUNTIME_TRIPLE_WEBGPU_64 = "wasm64-unknown-unknown-unknown" # `-fno-threadsafe-statics` is very important here (note that it allows us to use a 'modern' C++ # standard but still skip threadsafe guards for static initialization in our runtime code) @@ -1084,6 +1088,7 @@ RUNTIME_CXX_FLAGS = \ -fno-vectorize \ -fno-threadsafe-statics \ -fno-rtti \ + -fno-jump-tables \ -Wall \ -Wcast-qual \ -Werror \ @@ -1093,7 +1098,8 @@ RUNTIME_CXX_FLAGS = \ -Wno-unknown-warning-option \ -Wno-unused-function \ -Wvla \ - -Wsign-compare + -Wsign-compare \ + -Wno-sync-alignment $(BUILD_DIR)/initmod.windows_%_x86_32.ll: $(SRC_DIR)/runtime/windows_%_x86.cpp $(BUILD_DIR)/clang_ok @mkdir -p $(@D) @@ -1119,6 +1125,22 @@ $(BUILD_DIR)/initmod.windows_%_64.ll: $(SRC_DIR)/runtime/windows_%.cpp $(BUILD_D @mkdir -p $(@D) $(CLANG) $(CXX_WARNING_FLAGS) $(RUNTIME_CXX_FLAGS) -m64 -target $(RUNTIME_TRIPLE_WIN_GENERIC_64) -fshort-wchar -DCOMPILING_HALIDE_RUNTIME -DBITS_64 -emit-llvm -S $(SRC_DIR)/runtime/windows_$*.cpp -o $@ -MMD -MP -MF $(BUILD_DIR)/initmod.windows_$*_64.d +$(BUILD_DIR)/initmod.webgpu_%_32.ll: $(SRC_DIR)/runtime/webgpu_%.cpp $(BUILD_DIR)/clang_ok + @mkdir -p $(@D) + $(CLANG) $(CXX_WARNING_FLAGS) $(RUNTIME_CXX_FLAGS) -m32 -target $(RUNTIME_TRIPLE_WEBGPU_32) -DCOMPILING_HALIDE_RUNTIME -DBITS_32 -emit-llvm -S $(SRC_DIR)/runtime/webgpu_$*.cpp -o $@ -MMD -MP -MF $(BUILD_DIR)/initmod.webgpu_$*_32.d + +$(BUILD_DIR)/initmod.webgpu_%_64.ll: $(SRC_DIR)/runtime/webgpu_%.cpp $(BUILD_DIR)/clang_ok + @mkdir -p $(@D) + $(CLANG) $(CXX_WARNING_FLAGS) $(RUNTIME_CXX_FLAGS) -m64 -target $(RUNTIME_TRIPLE_WEBGPU_64) -DCOMPILING_HALIDE_RUNTIME -DBITS_64 -emit-llvm -S $(SRC_DIR)/runtime/webgpu_$*.cpp -o $@ -MMD -MP -MF $(BUILD_DIR)/initmod.webgpu_$*_64.d + +$(BUILD_DIR)/initmod.webgpu_%_32_debug.ll: $(SRC_DIR)/runtime/webgpu_%.cpp $(BUILD_DIR)/clang_ok + @mkdir -p $(@D) + $(CLANG) $(CXX_WARNING_FLAGS) -g -DDEBUG_RUNTIME $(RUNTIME_CXX_FLAGS) -m32 -target $(RUNTIME_TRIPLE_WEBGPU_32) -DCOMPILING_HALIDE_RUNTIME -DBITS_32 -emit-llvm -S $(SRC_DIR)/runtime/webgpu_$*.cpp -o $@ -MMD -MP -MF $(BUILD_DIR)/initmod.webgpu_$*_32_debug.d + +$(BUILD_DIR)/initmod.webgpu_%_64_debug.ll: $(SRC_DIR)/runtime/webgpu_%.cpp $(BUILD_DIR)/clang_ok + @mkdir -p $(@D) + $(CLANG) $(CXX_WARNING_FLAGS) -g -DDEBUG_RUNTIME $(RUNTIME_CXX_FLAGS) -m64 -target $(RUNTIME_TRIPLE_WEBGPU_64) -DCOMPILING_HALIDE_RUNTIME -DBITS_64 -emit-llvm -S $(SRC_DIR)/runtime/webgpu_$*.cpp -o $@ -MMD -MP -MF $(BUILD_DIR)/initmod.webgpu_$*_64_debug.d + $(BUILD_DIR)/initmod.%_64.ll: $(SRC_DIR)/runtime/%.cpp $(BUILD_DIR)/clang_ok @mkdir -p $(@D) $(CLANG) $(CXX_WARNING_FLAGS) $(RUNTIME_CXX_FLAGS) -fpic -m64 -target $(RUNTIME_TRIPLE_64) -DCOMPILING_HALIDE_RUNTIME -DBITS_64 -emit-llvm -S $(SRC_DIR)/runtime/$*.cpp -o $@ -MMD -MP -MF $(BUILD_DIR)/initmod.$*_64.d diff --git a/src/runtime/CMakeLists.txt b/src/runtime/CMakeLists.txt index 5426c355823c..fba385a85ee7 100644 --- a/src/runtime/CMakeLists.txt +++ b/src/runtime/CMakeLists.txt @@ -161,6 +161,8 @@ set(RUNTIME_CXX_FLAGS -fno-threadsafe-statics # Necessary for using virtual functions in the runtime code. -fno-rtti + # Will generate bad code in some situations + -fno-jump-tables -Wall -Wc++20-designator -Wcast-qual @@ -173,6 +175,7 @@ set(RUNTIME_CXX_FLAGS -Wvla -Wsign-compare -Wimplicit-fallthrough + -Wno-sync-alignment ) option(Halide_CLANG_TIDY_BUILD "Generate fake compile jobs for runtime files when running clang-tidy." OFF) @@ -217,17 +220,24 @@ foreach (i IN LISTS RUNTIME_CPP) # unfortunately, clang doesn't automatically set this flag even though the # ABI is msvc on windows set(fshort-wchar -fshort-wchar) - set(TARGET "le64-unknown-windows-unknown") + # TODO: was le64 here, not sure if this is correct or not + set(TARGET "x86_64-unknown-windows-unknown") endif () endif() - # Everything else + elseif (i MATCHES "webgpu") + if (j EQUAL 32) + # wasm32 will fail for some i386 builds, but i386 won't + set(TARGET "wasm32-unknown-unknown-unknown") + else () + set(TARGET "wasm64-unknown-unknown-unknown") + endif () else() + # don't be fooled: these are just generic 32/64-bit targets for our purposes here if (j EQUAL 32) - # (The 'nacl' is a red herring. This is just a generic 32-bit little-endian target.) - set(TARGET "le32-unknown-nacl-unknown") + # wasm32 will fail for some i386 builds, but i386 won't + set(TARGET "i386-unknown-unknown-unknown") else () - # generic 64-bit code - set(TARGET "le64-unknown-unknown-unknown") + set(TARGET "x86_64-unknown-unknown-unknown") endif () endif ()