[llvm] Allow optimization of __size_returning_new variants. (PR #102258)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 14 00:11:45 PDT 2024
================
@@ -1963,6 +1964,61 @@ Value *llvm::emitCalloc(Value *Num, Value *Size, IRBuilderBase &B,
return CI;
}
+Value *llvm::emitHotColdSizeReturningNew(Value *Num, IRBuilderBase &B,
+ const TargetLibraryInfo *TLI,
+ LibFunc SizeFeedbackNewFunc,
+ uint8_t HotCold) {
+ Module *M = B.GetInsertBlock()->getModule();
+ if (!isLibFuncEmittable(M, TLI, SizeFeedbackNewFunc))
+ return nullptr;
+
+ StringRef Name = TLI->getName(SizeFeedbackNewFunc);
+
+ // __sized_ptr_t struct return type { void*, size_t }
+ llvm::StructType *SizedPtrT =
+ llvm::StructType::get(M->getContext(), {B.getPtrTy(), Num->getType()});
+ FunctionCallee Func =
+ M->getOrInsertFunction(Name, SizedPtrT, Num->getType(), B.getInt8Ty());
+ inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
+ CallInst *CI = B.CreateCall(Func, {Num, B.getInt8(HotCold)}, Name);
+ // Setting the name makes the tests easier to read.
+ CI->setName("sized_ptr");
----------------
nikic wrote:
This code looks a bit confused. The `Name` passed to `CreateCall` is the value name, so if you want to call it `%sized_ptr`, you should pass `"sized_ptr"` to where you're currently passing `Name`.
https://github.com/llvm/llvm-project/pull/102258
More information about the llvm-commits
mailing list