diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2023-07-26 19:03:47 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2023-07-26 19:04:23 +0000 |
commit | 7fa27ce4a07f19b07799a767fc29416f3b625afb (patch) | |
tree | 27825c83636c4de341eb09a74f49f5d38a15d165 /llvm/lib/Transforms/Utils/BuildLibCalls.cpp | |
parent | e3b557809604d036af6e00c60f012c2025b59a5e (diff) |
Diffstat (limited to 'llvm/lib/Transforms/Utils/BuildLibCalls.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/BuildLibCalls.cpp | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp index 1e21a2f85446..5de8ff84de77 100644 --- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp @@ -478,6 +478,8 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F, case LibFunc_modfl: Changed |= setDoesNotThrow(F); Changed |= setWillReturn(F); + Changed |= setOnlyAccessesArgMemory(F); + Changed |= setOnlyWritesMemory(F); Changed |= setDoesNotCapture(F, 1); break; case LibFunc_memcpy: @@ -725,6 +727,8 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F, case LibFunc_frexpl: Changed |= setDoesNotThrow(F); Changed |= setWillReturn(F); + Changed |= setOnlyAccessesArgMemory(F); + Changed |= setOnlyWritesMemory(F); Changed |= setDoesNotCapture(F, 1); break; case LibFunc_fstatvfs: @@ -1937,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; +} |