[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: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());
----------------
snehasish wrote:

When trying to do so I hit the assertion here: https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/Utils/BuildLibCalls.cpp#L1375-L1379

I think we'll need to change getOrInsertLibFunc to handle these cases if we want to use it. Given that the other transforms related to operator new don't use it I'll leave it as is. If you want we can follow up with a patch which addresses them together.

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


More information about the llvm-commits mailing list