From feee02ca613afe9490a8dd753d32df7057151ffd Mon Sep 17 00:00:00 2001 From: Arm Patinyasakdikul Date: Fri, 3 Oct 2025 14:05:01 -0700 Subject: [PATCH] Change to use -O0 instead of -O1 in debug build. (#1949) * Change to use -O0 instead of -O1 in debug build. * Use -O1 for device code to avoid linking issue in debug build. --- CMakeLists.txt | 9 +++++++++ toolchain-linux.cmake | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c8281f23ed..f5a01109d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -886,6 +886,15 @@ foreach(file ${GENERATED_FILES}) list(APPEND HIP_SOURCES ${file}) endforeach() +# Apply -O1 optimization for generated files in debug builds +# This is needed for device object to not go over the stacksize limit at link time while allowing +# -O0 for host code in debug build. +if(CMAKE_BUILD_TYPE MATCHES "Debug" AND NOT DEFINED ENV{CXXFLAGS}) + message(STATUS "Setting -O1 optimization for device code in ${GEN_DIR} (Debug build)") + set_source_files_properties(${GENERATED_FILES} PROPERTIES COMPILE_OPTIONS "-O1") +endif() + + # Create an initial git_version.cpp file (that will be updated with latest git version) #================================================================================================== file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/git_version.cpp "") diff --git a/toolchain-linux.cmake b/toolchain-linux.cmake index 5a4cf46d98..a462c91fac 100644 --- a/toolchain-linux.cmake +++ b/toolchain-linux.cmake @@ -13,7 +13,7 @@ else() endif() if (NOT DEFINED ENV{CXXFLAGS}) - set(CMAKE_CXX_FLAGS_DEBUG "-g -O1") + set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") set(CMAKE_CXX_FLAGS_RELEASE "-O3") endif() @@ -24,6 +24,6 @@ else() endif() if (NOT DEFINED ENV{CFLAGS}) - set(CMAKE_C_FLAGS_DEBUG "-g -O1") + set(CMAKE_C_FLAGS_DEBUG "-g -O0") set(CMAKE_C_FLAGS_RELEASE "-O3") endif()