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

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 15 07:00:27 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());
----------------
nikic wrote:

It would be good to follow up on this, as it may cause issues on s390x.

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


More information about the llvm-commits mailing list