[llvm] Allow optimization of __size_returning_new variants. (PR #102258)

Snehasish Kumar via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 14 15:06:38 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");
----------------
snehasish wrote:

Done.

https://github.com/llvm/llvm-project/pull/102258


More information about the llvm-commits mailing list