Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9864,6 +9864,21 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
(TC->getTriple().isAMDGPU() || TC->getTriple().isNVPTX()))
LinkerArgs.emplace_back("-lompdevice");

// With PGO/coverage instrumentation, GPU device code references the
// device profile runtime (__llvm_profile_instrument_gpu and the
// __llvm_profile_sections bounds table emitted by
// InstrProfilingPlatformGPU). The offload device link does not otherwise
// pull it in, so forward the static device profile runtime to the GPU
// device linker. The archive is arch-suffixed, so pass its full path
// rather than a -l name.
if (ToolChain::needsProfileRT(Args) &&
(TC->getTriple().isAMDGPU() || TC->getTriple().isNVPTX())) {
std::string ProfileRT =
TC->getCompilerRT(Args, "profile", ToolChain::FT_Static);
if (TC->getVFS().exists(ProfileRT))
LinkerArgs.emplace_back(Args.MakeArgString(ProfileRT));
}

// For SPIR-V, pass some extra flags to `spirv-link`, the out-of-tree
// SPIR-V linker. `spirv-link` isn't called in LTO mode so restrict these
// flags to normal compilation.
Expand Down
20 changes: 20 additions & 0 deletions clang/lib/Driver/ToolChains/HIPAMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "clang/Options/Options.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/TargetParser/TargetParser.h"

using namespace clang::driver;
Expand Down Expand Up @@ -152,6 +153,25 @@ void AMDGCN::Linker::constructLldCommand(Compilation &C, const JobAction &JA,

LldArgs.push_back("--no-whole-archive");

// With PGO/coverage instrumentation, instrumented device code references the
// device profile runtime (__llvm_profile_instrument_gpu and the
// __llvm_profile_sections bounds table emitted by InstrProfilingPlatformGPU).
// The new-offload-driver path injects this in LinkerWrapper::ConstructJob, but
// HIP using the traditional offload path (e.g. on Windows, which does not
// route device linking through clang-linker-wrapper) reaches the device link
// here instead. Forward the static device profile runtime to this lld device
// link so the runtime is pulled in regardless of offload-driver/host OS. The
// archive is arch-suffixed, so pass its full path rather than a -l name.
if (ToolChain::needsProfileRT(Args)) {
std::string ProfileRT =
TC.getCompilerRT(Args, "profile", ToolChain::FT_Static);
// Use the ToolChain VFS (matches the new-offload-driver path in
// Clang.cpp) so overlay/virtual filesystems used by the driver are
// honored; llvm::sys::fs bypasses them and can wrongly skip the runtime.
if (TC.getVFS().exists(ProfileRT))
LldArgs.push_back(Args.MakeArgString(ProfileRT));
}

const char *Lld = Args.MakeArgStringRef(getToolChain().GetProgramPath("lld"));
C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
Lld, LldArgs, Inputs, Output));
Expand Down
13 changes: 10 additions & 3 deletions compiler-rt/lib/profile/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ if (NOT COMPILER_RT_PROFILE_BAREMETAL)
InstrProfilingValue.c
)
if(COMPILER_RT_BUILD_PROFILE_ROCM)
list(APPEND PROFILE_SOURCES InstrProfilingPlatformROCm.cpp)
# Linux uses HSA introspection (InstrProfilingPlatformROCm.cpp); Windows
# keeps the legacy host-shadow drain (InstrProfilingPlatformROCmWindows.cpp).
# Each is platform-guarded internally, so adding both is safe (the other
# platform compiles to an empty TU).
list(APPEND PROFILE_SOURCES InstrProfilingPlatformROCm.cpp
InstrProfilingPlatformROCmWindows.cpp)
endif()
endif()

Expand Down Expand Up @@ -181,7 +186,8 @@ if(COMPILER_RT_HAS_INTERCEPTION AND NOT COMPILER_RT_PROFILE_BAREMETAL
endif()

if(NOT PROFILE_HAS_HIP_INTERCEPTOR)
list(REMOVE_ITEM PROFILE_SOURCES InstrProfilingPlatformROCm.cpp)
list(REMOVE_ITEM PROFILE_SOURCES InstrProfilingPlatformROCm.cpp
InstrProfilingPlatformROCmWindows.cpp)
endif()

# Only advertise the ROCm interceptor to InstrProfilingFile.c when its
Expand Down Expand Up @@ -281,7 +287,8 @@ if(COMPILER_RT_BUILD_PROFILE_ROCM AND NOT COMPILER_RT_PROFILE_BAREMETAL
AND TARGET RTSanitizerCommon.${COMPILER_RT_DEFAULT_TARGET_ARCH}
AND TARGET RTSanitizerCommonLibc.${COMPILER_RT_DEFAULT_TARGET_ARCH})

set(PROFILE_ROCM_SOURCES ${PROFILE_SOURCES} InstrProfilingPlatformROCm.cpp)
set(PROFILE_ROCM_SOURCES ${PROFILE_SOURCES} InstrProfilingPlatformROCm.cpp
InstrProfilingPlatformROCmWindows.cpp)

# Enables the device-collection call in InstrProfilingFile.c.
set(PROFILE_ROCM_FLAGS ${EXTRA_FLAGS} -DCOMPILER_RT_BUILD_PROFILE_ROCM=1)
Expand Down
Loading
Loading