@@ -231,45 +231,55 @@ PreservedAnalyses
231
231
}
232
232
233
233
static constexpr std::pair<StringLiteral, StringLiteral> ReplaceMap[]{
234
- {" aligned_alloc" , " __hipstdpar_aligned_alloc" },
235
- {" calloc" , " __hipstdpar_calloc" },
236
- {" free" , " __hipstdpar_free" },
237
- {" malloc" , " __hipstdpar_malloc" },
238
- {" memalign" , " __hipstdpar_aligned_alloc" },
239
- {" posix_memalign" , " __hipstdpar_posix_aligned_alloc" },
240
- {" realloc" , " __hipstdpar_realloc" },
241
- {" reallocarray" , " __hipstdpar_realloc_array" },
242
- {" _ZdaPv" , " __hipstdpar_operator_delete" },
243
- {" _ZdaPvm" , " __hipstdpar_operator_delete_sized" },
244
- {" _ZdaPvSt11align_val_t" , " __hipstdpar_operator_delete_aligned" },
245
- {" _ZdaPvmSt11align_val_t" , " __hipstdpar_operator_delete_aligned_sized" },
246
- {" _ZdlPv" , " __hipstdpar_operator_delete" },
247
- {" _ZdlPvm" , " __hipstdpar_operator_delete_sized" },
248
- {" _ZdlPvSt11align_val_t" , " __hipstdpar_operator_delete_aligned" },
249
- {" _ZdlPvmSt11align_val_t" , " __hipstdpar_operator_delete_aligned_sized" },
250
- {" _Znam" , " __hipstdpar_operator_new" },
251
- {" _ZnamRKSt9nothrow_t" , " __hipstdpar_operator_new_nothrow" },
252
- {" _ZnamSt11align_val_t" , " __hipstdpar_operator_new_aligned" },
253
- {" _ZnamSt11align_val_tRKSt9nothrow_t" ,
254
- " __hipstdpar_operator_new_aligned_nothrow" },
255
-
256
- {" _Znwm" , " __hipstdpar_operator_new" },
257
- {" _ZnwmRKSt9nothrow_t" , " __hipstdpar_operator_new_nothrow" },
258
- {" _ZnwmSt11align_val_t" , " __hipstdpar_operator_new_aligned" },
259
- {" _ZnwmSt11align_val_tRKSt9nothrow_t" ,
260
- " __hipstdpar_operator_new_aligned_nothrow" },
261
- {" __builtin_calloc" , " __hipstdpar_calloc" },
262
- {" __builtin_free" , " __hipstdpar_free" },
263
- {" __builtin_malloc" , " __hipstdpar_malloc" },
264
- {" __builtin_operator_delete" , " __hipstdpar_operator_delete" },
265
- {" __builtin_operator_new" , " __hipstdpar_operator_new" },
266
- {" __builtin_realloc" , " __hipstdpar_realloc" },
267
- {" __libc_calloc" , " __hipstdpar_calloc" },
268
- {" __libc_free" , " __hipstdpar_free" },
269
- {" __libc_malloc" , " __hipstdpar_malloc" },
270
- {" __libc_memalign" , " __hipstdpar_aligned_alloc" },
271
- {" __libc_realloc" , " __hipstdpar_realloc" }
272
- };
234
+ {" aligned_alloc" , " __hipstdpar_aligned_alloc" },
235
+ {" calloc" , " __hipstdpar_calloc" },
236
+ {" free" , " __hipstdpar_free" },
237
+ {" malloc" , " __hipstdpar_malloc" },
238
+ {" memalign" , " __hipstdpar_aligned_alloc" },
239
+ {" mmap" , " __hipstdpar_mmap" },
240
+ {" munmap" , " __hipstdpar_munmap" },
241
+ {" posix_memalign" , " __hipstdpar_posix_aligned_alloc" },
242
+ {" realloc" , " __hipstdpar_realloc" },
243
+ {" reallocarray" , " __hipstdpar_realloc_array" },
244
+ {" _ZdaPv" , " __hipstdpar_operator_delete" },
245
+ {" _ZdaPvm" , " __hipstdpar_operator_delete_sized" },
246
+ {" _ZdaPvSt11align_val_t" , " __hipstdpar_operator_delete_aligned" },
247
+ {" _ZdaPvmSt11align_val_t" , " __hipstdpar_operator_delete_aligned_sized" },
248
+ {" _ZdlPv" , " __hipstdpar_operator_delete" },
249
+ {" _ZdlPvm" , " __hipstdpar_operator_delete_sized" },
250
+ {" _ZdlPvSt11align_val_t" , " __hipstdpar_operator_delete_aligned" },
251
+ {" _ZdlPvmSt11align_val_t" , " __hipstdpar_operator_delete_aligned_sized" },
252
+ {" _Znam" , " __hipstdpar_operator_new" },
253
+ {" _ZnamRKSt9nothrow_t" , " __hipstdpar_operator_new_nothrow" },
254
+ {" _ZnamSt11align_val_t" , " __hipstdpar_operator_new_aligned" },
255
+ {" _ZnamSt11align_val_tRKSt9nothrow_t" ,
256
+ " __hipstdpar_operator_new_aligned_nothrow" },
257
+
258
+ {" _Znwm" , " __hipstdpar_operator_new" },
259
+ {" _ZnwmRKSt9nothrow_t" , " __hipstdpar_operator_new_nothrow" },
260
+ {" _ZnwmSt11align_val_t" , " __hipstdpar_operator_new_aligned" },
261
+ {" _ZnwmSt11align_val_tRKSt9nothrow_t" ,
262
+ " __hipstdpar_operator_new_aligned_nothrow" },
263
+ {" __builtin_calloc" , " __hipstdpar_calloc" },
264
+ {" __builtin_free" , " __hipstdpar_free" },
265
+ {" __builtin_malloc" , " __hipstdpar_malloc" },
266
+ {" __builtin_operator_delete" , " __hipstdpar_operator_delete" },
267
+ {" __builtin_operator_new" , " __hipstdpar_operator_new" },
268
+ {" __builtin_realloc" , " __hipstdpar_realloc" },
269
+ {" __libc_calloc" , " __hipstdpar_calloc" },
270
+ {" __libc_free" , " __hipstdpar_free" },
271
+ {" __libc_malloc" , " __hipstdpar_malloc" },
272
+ {" __libc_memalign" , " __hipstdpar_aligned_alloc" },
273
+ {" __libc_realloc" , " __hipstdpar_realloc" }};
274
+
275
+ static constexpr std::pair<StringLiteral, StringLiteral> HiddenMap[]{
276
+ // hidden_malloc and hidden_free are only kept for backwards compatibility /
277
+ // legacy purposes, and we should remove them in the future
278
+ {" __hipstdpar_hidden_malloc" , " __libc_malloc" },
279
+ {" __hipstdpar_hidden_free" , " __libc_free" },
280
+ {" __hipstdpar_hidden_memalign" , " __libc_memalign" },
281
+ {" __hipstdpar_hidden_mmap" , " mmap" },
282
+ {" __hipstdpar_hidden_munmap" , " munmap" }};
273
283
274
284
PreservedAnalyses
275
285
HipStdParAllocationInterpositionPass::run (Module &M, ModuleAnalysisManager&) {
@@ -299,19 +309,14 @@ HipStdParAllocationInterpositionPass::run(Module &M, ModuleAnalysisManager&) {
299
309
}
300
310
}
301
311
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 ());
312
+ for (auto &&HR : HiddenMap) {
313
+ if (auto F = M.getFunction (HR.first )) {
314
+ auto R = M.getOrInsertFunction (HR.second , F->getFunctionType (),
315
+ F->getAttributes ());
316
+ F->replaceAllUsesWith (R.getCallee ());
306
317
307
- eraseFromModule (*F);
308
- }
309
- if (auto F = M.getFunction (" __hipstdpar_hidden_free" )) {
310
- auto LibcFree = M.getOrInsertFunction (" __libc_free" , F->getFunctionType (),
311
- F->getAttributes ());
312
- F->replaceAllUsesWith (LibcFree.getCallee ());
313
-
314
- eraseFromModule (*F);
318
+ eraseFromModule (*F);
319
+ }
315
320
}
316
321
317
322
return PreservedAnalyses::none ();
0 commit comments