[llvm] [opt][HIPSTDPAR] Handle `__hipstdpar_hidden_malloc` (PR #123150)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 15 18:16:20 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Alex Voicu (AlexVlx)
<details>
<summary>Changes</summary>
This patch adds support for replacing calls to `__hipstdpar_hidden_malloc` with calls to `__libc_malloc`, similarly to how we handle hidden `free`. A future paired change in the forwarding header will leverage this capability in order to handle certain special cases where it is not possible / desirable to allocate via the HIP runtime.
---
Full diff: https://github.com/llvm/llvm-project/pull/123150.diff
2 Files Affected:
- (modified) llvm/lib/Transforms/HipStdPar/HipStdPar.cpp (+8)
- (modified) llvm/test/Transforms/HipStdPar/allocation-interposition.ll (+2)
``````````diff
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)
``````````
</details>
https://github.com/llvm/llvm-project/pull/123150
More information about the llvm-commits
mailing list