[llvm] 246beeb - [BuildLibCalls] Use emitLibCall() in more places (NFCI) (#222557)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 10 01:57:37 PDT 2026


Author: Nikita Popov
Date: 2026-09-10T10:57:30+02:00
New Revision: 246beeb1eef7344750419fd1f584019f7c62b750

URL: https://github.com/llvm/llvm-project/commit/246beeb1eef7344750419fd1f584019f7c62b750
DIFF: https://github.com/llvm/llvm-project/commit/246beeb1eef7344750419fd1f584019f7c62b750.diff

LOG: [BuildLibCalls] Use emitLibCall() in more places (NFCI) (#222557)

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/BuildLibCalls.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
index e9ef993e71ec1..fa61a18de15de 100644
--- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
@@ -2018,143 +2018,49 @@ Value *llvm::emitBinaryFloatFnCall(Value *Op1, Value *Op2,
 // the same precision as int, which need not be 32 bits.
 Value *llvm::emitPutChar(Value *Char, IRBuilderBase &B,
                          const TargetLibraryInfo *TLI) {
-  Module *M = B.GetInsertBlock()->getModule();
-  if (!isLibFuncEmittable(M, TLI, LibFunc_putchar))
-    return nullptr;
-
   Type *IntTy = getIntTy(B, TLI);
-  StringRef PutCharName = TLI->getName(LibFunc_putchar);
-  FunctionCallee PutChar = getOrInsertLibFunc(M, *TLI, LibFunc_putchar,
-                                              IntTy, IntTy);
-  inferNonMandatoryLibFuncAttrs(M, PutCharName, *TLI);
-  CallInst *CI = B.CreateCall(PutChar, Char, PutCharName);
-
-  if (const Function *F =
-          dyn_cast<Function>(PutChar.getCallee()->stripPointerCasts()))
-    CI->setCallingConv(F->getCallingConv());
-  return CI;
+  return emitLibCall(LibFunc_putchar, IntTy, IntTy, Char, B, TLI);
 }
 
 Value *llvm::emitPutS(Value *Str, IRBuilderBase &B,
                       const TargetLibraryInfo *TLI) {
-  Module *M = B.GetInsertBlock()->getModule();
-  if (!isLibFuncEmittable(M, TLI, LibFunc_puts))
-    return nullptr;
-
   Type *IntTy = getIntTy(B, TLI);
-  StringRef PutsName = TLI->getName(LibFunc_puts);
-  FunctionCallee PutS =
-      getOrInsertLibFunc(M, *TLI, LibFunc_puts, IntTy, B.getPtrTy());
-  inferNonMandatoryLibFuncAttrs(M, PutsName, *TLI);
-  CallInst *CI = B.CreateCall(PutS, Str, PutsName);
-  if (const Function *F =
-          dyn_cast<Function>(PutS.getCallee()->stripPointerCasts()))
-    CI->setCallingConv(F->getCallingConv());
-  return CI;
+  return emitLibCall(LibFunc_puts, IntTy, B.getPtrTy(), Str, B, TLI);
 }
 
 Value *llvm::emitFPutC(Value *Char, Value *File, IRBuilderBase &B,
                        const TargetLibraryInfo *TLI) {
-  Module *M = B.GetInsertBlock()->getModule();
-  if (!isLibFuncEmittable(M, TLI, LibFunc_fputc))
-    return nullptr;
-
   Type *IntTy = getIntTy(B, TLI);
-  StringRef FPutcName = TLI->getName(LibFunc_fputc);
-  FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fputc, IntTy,
-                                        IntTy, File->getType());
-  if (File->getType()->isPointerTy())
-    inferNonMandatoryLibFuncAttrs(M, FPutcName, *TLI);
-  CallInst *CI = B.CreateCall(F, {Char, File}, FPutcName);
-
-  if (const Function *Fn =
-          dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
-    CI->setCallingConv(Fn->getCallingConv());
-  return CI;
+  return emitLibCall(LibFunc_fputc, IntTy, {IntTy, File->getType()},
+                     {Char, File}, B, TLI);
 }
 
 Value *llvm::emitFPutS(Value *Str, Value *File, IRBuilderBase &B,
                        const TargetLibraryInfo *TLI) {
-  Module *M = B.GetInsertBlock()->getModule();
-  if (!isLibFuncEmittable(M, TLI, LibFunc_fputs))
-    return nullptr;
-
   Type *IntTy = getIntTy(B, TLI);
-  StringRef FPutsName = TLI->getName(LibFunc_fputs);
-  FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fputs, IntTy,
-                                        B.getPtrTy(), File->getType());
-  if (File->getType()->isPointerTy())
-    inferNonMandatoryLibFuncAttrs(M, FPutsName, *TLI);
-  CallInst *CI = B.CreateCall(F, {Str, File}, FPutsName);
-
-  if (const Function *Fn =
-          dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
-    CI->setCallingConv(Fn->getCallingConv());
-  return CI;
+  return emitLibCall(LibFunc_fputs, IntTy, {B.getPtrTy(), File->getType()},
+                     {Str, File}, B, TLI);
 }
 
 Value *llvm::emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilderBase &B,
                         const DataLayout &DL, const TargetLibraryInfo *TLI) {
-  Module *M = B.GetInsertBlock()->getModule();
-  if (!isLibFuncEmittable(M, TLI, LibFunc_fwrite))
-    return nullptr;
-
   Type *SizeTTy = getSizeTTy(B, TLI);
-  StringRef FWriteName = TLI->getName(LibFunc_fwrite);
-  FunctionCallee F =
-      getOrInsertLibFunc(M, *TLI, LibFunc_fwrite, SizeTTy, B.getPtrTy(),
-                         SizeTTy, SizeTTy, File->getType());
-
-  if (File->getType()->isPointerTy())
-    inferNonMandatoryLibFuncAttrs(M, FWriteName, *TLI);
-  CallInst *CI =
-      B.CreateCall(F, {Ptr, Size,
-                       ConstantInt::get(SizeTTy, 1), File});
-
-  if (const Function *Fn =
-          dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
-    CI->setCallingConv(Fn->getCallingConv());
-  return CI;
+  return emitLibCall(LibFunc_fwrite, SizeTTy,
+                     {B.getPtrTy(), SizeTTy, SizeTTy, File->getType()},
+                     {Ptr, Size, ConstantInt::get(SizeTTy, 1), File}, B, TLI);
 }
 
 Value *llvm::emitMalloc(Value *Num, IRBuilderBase &B, const DataLayout &DL,
                         const TargetLibraryInfo *TLI) {
-  Module *M = B.GetInsertBlock()->getModule();
-  if (!isLibFuncEmittable(M, TLI, LibFunc_malloc))
-    return nullptr;
-
-  StringRef MallocName = TLI->getName(LibFunc_malloc);
   Type *SizeTTy = getSizeTTy(B, TLI);
-  FunctionCallee Malloc =
-      getOrInsertLibFunc(M, *TLI, LibFunc_malloc, B.getPtrTy(), SizeTTy);
-  inferNonMandatoryLibFuncAttrs(M, MallocName, *TLI);
-  CallInst *CI = B.CreateCall(Malloc, Num, MallocName);
-
-  if (const Function *F =
-          dyn_cast<Function>(Malloc.getCallee()->stripPointerCasts()))
-    CI->setCallingConv(F->getCallingConv());
-
-  return CI;
+  return emitLibCall(LibFunc_malloc, B.getPtrTy(), SizeTTy, Num, B, TLI);
 }
 
 Value *llvm::emitCalloc(Value *Num, Value *Size, IRBuilderBase &B,
                         const TargetLibraryInfo &TLI, unsigned AddrSpace) {
-  Module *M = B.GetInsertBlock()->getModule();
-  if (!isLibFuncEmittable(M, &TLI, LibFunc_calloc))
-    return nullptr;
-
-  StringRef CallocName = TLI.getName(LibFunc_calloc);
   Type *SizeTTy = getSizeTTy(B, &TLI);
-  FunctionCallee Calloc = getOrInsertLibFunc(
-      M, TLI, LibFunc_calloc, B.getPtrTy(AddrSpace), SizeTTy, SizeTTy);
-  inferNonMandatoryLibFuncAttrs(M, CallocName, TLI);
-  CallInst *CI = B.CreateCall(Calloc, {Num, Size}, CallocName);
-
-  if (const auto *F =
-          dyn_cast<Function>(Calloc.getCallee()->stripPointerCasts()))
-    CI->setCallingConv(F->getCallingConv());
-
-  return CI;
+  return emitLibCall(LibFunc_calloc, B.getPtrTy(AddrSpace), {SizeTTy, SizeTTy},
+                     {Num, Size}, B, &TLI);
 }
 
 Value *llvm::emitHotColdSizeReturningNew(Value *Num, IRBuilderBase &B,


        


More information about the llvm-commits mailing list