diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt index e88321d822f84..39034fd9ba67d 100644 --- a/compiler-rt/CMakeLists.txt +++ b/compiler-rt/CMakeLists.txt @@ -322,6 +322,15 @@ option(COMPILER_RT_USE_ATOMIC_LIBRARY "Use compiler-rt atomic instead of libatom option(COMPILER_RT_PROFILE_BAREMETAL "Build minimal baremetal profile library" OFF) +set(DEFAULT_COMPILER_RT_BUILD_PROFILE_ROCM ON) +if(APPLE) + set(DEFAULT_COMPILER_RT_BUILD_PROFILE_ROCM OFF) +endif() +option(COMPILER_RT_BUILD_PROFILE_ROCM + "Build the host-side ROCm/HIP device profile collection runtime" + ${DEFAULT_COMPILER_RT_BUILD_PROFILE_ROCM}) +mark_as_advanced(COMPILER_RT_BUILD_PROFILE_ROCM) + include(config-ix) #================================ diff --git a/compiler-rt/lib/profile/CMakeLists.txt b/compiler-rt/lib/profile/CMakeLists.txt index 36e6b5a6a21c1..b8745696bc6ce 100644 --- a/compiler-rt/lib/profile/CMakeLists.txt +++ b/compiler-rt/lib/profile/CMakeLists.txt @@ -89,11 +89,13 @@ if (NOT COMPILER_RT_PROFILE_BAREMETAL) list(APPEND PROFILE_SOURCES GCDAProfiling.c InstrProfilingFile.c - InstrProfilingPlatformROCm.cpp InstrProfilingRuntime.cpp InstrProfilingUtil.c InstrProfilingValue.c ) + if(COMPILER_RT_BUILD_PROFILE_ROCM) + list(APPEND PROFILE_SOURCES InstrProfilingPlatformROCm.cpp) + endif() endif() set(PROFILE_HEADERS @@ -156,6 +158,12 @@ if(COMPILER_RT_PROFILE_BAREMETAL) -DCOMPILER_RT_PROFILE_BAREMETAL=1) endif() +if(COMPILER_RT_BUILD_PROFILE_ROCM) + set(EXTRA_FLAGS + ${EXTRA_FLAGS} + -DCOMPILER_RT_BUILD_PROFILE_ROCM=1) +endif() + set(PROFILE_OBJECT_LIBS) if(COMPILER_RT_HAS_INTERCEPTION AND NOT COMPILER_RT_PROFILE_BAREMETAL) # RTInterception references __sanitizer_internal_{memcpy,memset,memmove} and other diff --git a/compiler-rt/lib/profile/InstrProfilingFile.c b/compiler-rt/lib/profile/InstrProfilingFile.c index 2200f07e70acc..9ea5a2638fac9 100644 --- a/compiler-rt/lib/profile/InstrProfilingFile.c +++ b/compiler-rt/lib/profile/InstrProfilingFile.c @@ -50,11 +50,13 @@ * and the address test at the call site would fold to true. * Windows: __declspec(selectany) is data-only, and the ROCm interceptor path * is not used there, so keep the original strong extern. */ +#if COMPILER_RT_BUILD_PROFILE_ROCM #if defined(_WIN32) extern int __llvm_profile_hip_collect_device_data(void); #else __attribute__((weak)) int __llvm_profile_hip_collect_device_data(void); #endif +#endif /* From where is profile name specified. * The order the enumerators define their @@ -1217,11 +1219,13 @@ int __llvm_profile_write_file(void) { * InstrProfilingPlatformROCm.o is in the link, which happens when the program * references other ROCm-runtime symbols (HIP-with-PGO). Warning on failure is * handled inside the callee. */ +#if COMPILER_RT_BUILD_PROFILE_ROCM #if defined(_WIN32) (void)__llvm_profile_hip_collect_device_data(); #else if (&__llvm_profile_hip_collect_device_data) (void)__llvm_profile_hip_collect_device_data(); +#endif #endif // Restore SIGKILL.