Skip to content

Commit 335f1a7

Browse files
authored
[opt][HIPSTDPAR] Handle __hipstdpar_hidden_malloc (#123150)
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.
1 parent c26e1a2 commit 335f1a7

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

llvm/lib/Transforms/HipStdPar/HipStdPar.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,13 @@ HipStdParAllocationInterpositionPass::run(Module &M, ModuleAnalysisManager&) {
299299
}
300300
}
301301

302+
if (auto F = M.getFunction("__hipstdpar_hidden_malloc")) {
303+
auto LibcMalloc = M.getOrInsertFunction(
304+
"__libc_malloc", F->getFunctionType(), F->getAttributes());
305+
F->replaceAllUsesWith(LibcMalloc.getCallee());
306+
307+
eraseFromModule(*F);
308+
}
302309
if (auto F = M.getFunction("__hipstdpar_hidden_free")) {
303310
auto LibcFree = M.getOrInsertFunction("__libc_free", F->getFunctionType(),
304311
F->getAttributes());

llvm/test/Transforms/HipStdPar/allocation-interposition.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ declare i32 @__hipstdpar_posix_aligned_alloc(ptr, i64, i64)
1414

1515
declare void @__hipstdpar_hidden_free(ptr)
1616

17+
declare ptr @__hipstdpar_hidden_malloc(i64)
18+
1719
declare ptr @__hipstdpar_realloc(ptr, i64)
1820

1921
declare ptr @__hipstdpar_realloc_array(ptr, i64, i64)

0 commit comments

Comments
 (0)