aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2023-04-19 08:21:52 -0700
committerTeresa Johnson <tejohnson@google.com>2023-04-19 13:33:46 -0700
commita35206d78280e0ebcf48cd21bc5fff5c3b9c73fa (patch)
treee128be8e1d26a72fe3accdbcbd6957e3f785ebb1 /llvm/lib/Transforms/Utils/BuildLibCalls.cpp
parent24214832fd433a901c2296088bf23b7bc86c6a96 (diff)
downloadllvm-a35206d78280e0ebcf48cd21bc5fff5c3b9c73fa.zip
llvm-a35206d78280e0ebcf48cd21bc5fff5c3b9c73fa.tar.gz
llvm-a35206d78280e0ebcf48cd21bc5fff5c3b9c73fa.tar.bz2
[MemProf] Optionally pass hot/cold hints to operator new
Optionally (off by default) replace operator new() calls marked with a hot or cold memprof attribute with an operator new() call that takes a hot_cold_t parameter. Currently this is supported by the open source version of tcmalloc, see: https://github.com/google/tcmalloc/blob/master/tcmalloc/new_extension.h Differential Revision: https://reviews.llvm.org/D148718
Diffstat (limited to 'llvm/lib/Transforms/Utils/BuildLibCalls.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/BuildLibCalls.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
index 6adf2e6..5de8ff8 100644
--- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
@@ -1941,3 +1941,87 @@ Value *llvm::emitCalloc(Value *Num, Value *Size, IRBuilderBase &B,
return CI;
}
+
+Value *llvm::emitHotColdNew(Value *Num, IRBuilderBase &B,
+ const TargetLibraryInfo *TLI, LibFunc NewFunc,
+ uint8_t HotCold) {
+ Module *M = B.GetInsertBlock()->getModule();
+ if (!isLibFuncEmittable(M, TLI, NewFunc))
+ return nullptr;
+
+ StringRef Name = TLI->getName(NewFunc);
+ FunctionCallee Func = M->getOrInsertFunction(Name, B.getInt8PtrTy(),
+ Num->getType(), B.getInt8Ty());
+ inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
+ CallInst *CI = B.CreateCall(Func, {Num, B.getInt8(HotCold)}, Name);
+
+ if (const Function *F =
+ dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
+ CI->setCallingConv(F->getCallingConv());
+
+ return CI;
+}
+
+Value *llvm::emitHotColdNewNoThrow(Value *Num, Value *NoThrow, IRBuilderBase &B,
+ const TargetLibraryInfo *TLI,
+ LibFunc NewFunc, uint8_t HotCold) {
+ Module *M = B.GetInsertBlock()->getModule();
+ if (!isLibFuncEmittable(M, TLI, NewFunc))
+ return nullptr;
+
+ StringRef Name = TLI->getName(NewFunc);
+ FunctionCallee Func =
+ M->getOrInsertFunction(Name, B.getInt8PtrTy(), Num->getType(),
+ NoThrow->getType(), B.getInt8Ty());
+ inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
+ CallInst *CI = B.CreateCall(Func, {Num, NoThrow, B.getInt8(HotCold)}, Name);
+
+ if (const Function *F =
+ dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
+ CI->setCallingConv(F->getCallingConv());
+
+ return CI;
+}
+
+Value *llvm::emitHotColdNewAligned(Value *Num, Value *Align, IRBuilderBase &B,
+ const TargetLibraryInfo *TLI,
+ LibFunc NewFunc, uint8_t HotCold) {
+ Module *M = B.GetInsertBlock()->getModule();
+ if (!isLibFuncEmittable(M, TLI, NewFunc))
+ return nullptr;
+
+ StringRef Name = TLI->getName(NewFunc);
+ FunctionCallee Func = M->getOrInsertFunction(
+ Name, B.getInt8PtrTy(), Num->getType(), Align->getType(), B.getInt8Ty());
+ inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
+ CallInst *CI = B.CreateCall(Func, {Num, Align, B.getInt8(HotCold)}, Name);
+
+ if (const Function *F =
+ dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
+ CI->setCallingConv(F->getCallingConv());
+
+ return CI;
+}
+
+Value *llvm::emitHotColdNewAlignedNoThrow(Value *Num, Value *Align,
+ Value *NoThrow, IRBuilderBase &B,
+ const TargetLibraryInfo *TLI,
+ LibFunc NewFunc, uint8_t HotCold) {
+ Module *M = B.GetInsertBlock()->getModule();
+ if (!isLibFuncEmittable(M, TLI, NewFunc))
+ return nullptr;
+
+ StringRef Name = TLI->getName(NewFunc);
+ FunctionCallee Func = M->getOrInsertFunction(
+ Name, B.getInt8PtrTy(), Num->getType(), Align->getType(),
+ NoThrow->getType(), B.getInt8Ty());
+ inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
+ CallInst *CI =
+ B.CreateCall(Func, {Num, Align, NoThrow, B.getInt8(HotCold)}, Name);
+
+ if (const Function *F =
+ dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
+ CI->setCallingConv(F->getCallingConv());
+
+ return CI;
+}