[llvm] [opt][HIPSTDPAR] Handle `__hipstdpar_hidden_malloc` (PR #123150)
Alex Voicu via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 17 12:03:25 PST 2025
https://github.com/AlexVlx updated https://github.com/llvm/llvm-project/pull/123150
>From b60773af8dbda229b1450726c67ade113de0ae05 Mon Sep 17 00:00:00 2001
From: Alex Voicu <alexandru.voicu at amd.com>
Date: Thu, 16 Jan 2025 02:06:11 +0000
Subject: [PATCH 1/2] Handle `__hipstdpar_hidden_malloc`
---
llvm/lib/Transforms/HipStdPar/HipStdPar.cpp | 8 ++++++++
.../test/Transforms/HipStdPar/allocation-interposition.ll | 2 ++
2 files changed, 10 insertions(+)
diff --git a/llvm/lib/Transforms/HipStdPar/HipStdPar.cpp b/llvm/lib/Transforms/HipStdPar/HipStdPar.cpp
index 92042ddab38dc7..691aaecc5e006b 100644
--- a/llvm/lib/Transforms/HipStdPar/HipStdPar.cpp
+++ b/llvm/lib/Transforms/HipStdPar/HipStdPar.cpp
@@ -298,6 +298,14 @@ HipStdParAllocationInterpositionPass::run(Module &M, ModuleAnalysisManager&) {
}
}
+ if (auto F = M.getFunction("__hipstdpar_hidden_malloc")) {
+ auto LibcMalloc =
+ M.getOrInsertFunction("__libc_malloc", F->getFunctionType(),
+ F->getAttributes());
+ F->replaceAllUsesWith(LibcMalloc.getCallee());
+
+ eraseFromModule(*F);
+ }
if (auto F = M.getFunction("__hipstdpar_hidden_free")) {
auto LibcFree = M.getOrInsertFunction("__libc_free", F->getFunctionType(),
F->getAttributes());
diff --git a/llvm/test/Transforms/HipStdPar/allocation-interposition.ll b/llvm/test/Transforms/HipStdPar/allocation-interposition.ll
index 291b06ed0ca9ed..9ec284b1dedb7d 100644
--- a/llvm/test/Transforms/HipStdPar/allocation-interposition.ll
+++ b/llvm/test/Transforms/HipStdPar/allocation-interposition.ll
@@ -14,6 +14,8 @@ declare i32 @__hipstdpar_posix_aligned_alloc(ptr, i64, i64)
declare void @__hipstdpar_hidden_free(ptr)
+declare ptr @__hipstdpar_hidden_malloc(i64)
+
declare ptr @__hipstdpar_realloc(ptr, i64)
declare ptr @__hipstdpar_realloc_array(ptr, i64, i64)
>From 99743aa560900e8f1d0b8951337a3e140d849451 Mon Sep 17 00:00:00 2001
From: Alex Voicu <alexandru.voicu at amd.com>
Date: Thu, 16 Jan 2025 02:29:45 +0000
Subject: [PATCH 2/2] Fix formatting.
---
llvm/lib/Transforms/HipStdPar/HipStdPar.cpp | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Transforms/HipStdPar/HipStdPar.cpp b/llvm/lib/Transforms/HipStdPar/HipStdPar.cpp
index 691aaecc5e006b..11d9740b771a72 100644
--- a/llvm/lib/Transforms/HipStdPar/HipStdPar.cpp
+++ b/llvm/lib/Transforms/HipStdPar/HipStdPar.cpp
@@ -299,9 +299,8 @@ HipStdParAllocationInterpositionPass::run(Module &M, ModuleAnalysisManager&) {
}
if (auto F = M.getFunction("__hipstdpar_hidden_malloc")) {
- auto LibcMalloc =
- M.getOrInsertFunction("__libc_malloc", F->getFunctionType(),
- F->getAttributes());
+ auto LibcMalloc = M.getOrInsertFunction(
+ "__libc_malloc", F->getFunctionType(), F->getAttributes());
F->replaceAllUsesWith(LibcMalloc.getCallee());
eraseFromModule(*F);
More information about the llvm-commits
mailing list