[compiler-rt] [llvm] [PGO][AMDGPU] Add basic HIP offload PGO support (PR #177665)

Yaxun Liu via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 9 09:57:11 PDT 2026


================
@@ -0,0 +1,798 @@
+//===- InstrProfilingPlatformROCm.c - Profile data ROCm platform ---------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+extern "C" {
+#include "InstrProfiling.h"
+#include "InstrProfilingInternal.h"
+#include "InstrProfilingPort.h"
+}
+
+// interception.h pulls in sanitizer_internal_defs.h, which normally includes
+// sanitizer_redefine_builtins.h. That uses inline asm to alias
+// memcpy/memmove/memset to __sanitizer_internal_* (see sanitizer_libc.cpp in
+// sanitizer_common). The instrumented *host* link for HIP (-fprofile-generate)
+// only pulls in libclang_rt.profile.a, not the full sanitizer_common objects
+// that define those symbols, so we get undefined references at link time. This
+// TU does not need the sanitizer builtin redirect; keep using libc
+// memcpy/memset.
+#define SANITIZER_COMMON_NO_REDEFINE_BUILTINS 1
+#include "interception/interception.h"
+#undef SANITIZER_COMMON_NO_REDEFINE_BUILTINS
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
----------------
yxsamliu wrote:

I'd like to keep the C libc headers here: the profile runtime is meant to work on bare-metal and other setups that don't have a normal C++ standard library, so we deliberately avoid standard C++ headers even when the source is C++—the language is fine, but `<cstdio>`-style headers are not. The other `.cpp` in this library (`InstrProfilingRuntime.cpp`) and the ctx_profile runtime sources (`CtxInstrProfiling.cpp`, `RootAutoDetector.cpp`) follow the same convention—C/POSIX and compiler-rt headers only, no C++ standard library includes. The build reflects that with `-nostdinc++` in both `profile/CMakeLists.txt` and `ctx_profile/CMakeLists.txt`; I left a short comment next to the includes in this file too.

https://github.com/llvm/llvm-project/pull/177665


More information about the llvm-commits mailing list