[llvm] Make `IntrinsicLowering` external function call lowering configurable (PR #102148)

Jannik Silvanus via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 8 00:50:01 PDT 2024


================
@@ -26,23 +26,25 @@ using namespace llvm;
 /// an external function. This handles hard cases such as when there was already
 /// a prototype for the external function, but that prototype doesn't match the
 /// arguments we expect to pass in.
-template <class ArgIt>
-static CallInst *ReplaceCallWith(const char *NewFn, CallInst *CI,
-                                 ArgIt ArgBegin, ArgIt ArgEnd,
-                                 Type *RetTy) {
+CallInst *IntrinsicLowering::ReplaceCallWith(const char *NewFn, CallInst *CI,
+                                             ArrayRef<Value *> Args,
+                                             Type *RetTy) {
+  if (!LowerExternalFunctionCalls)
+    return nullptr;
+
   // If we haven't already looked up this function, check to see if the
   // program already contains a function with this name.
   Module *M = CI->getModule();
   // Get or insert the definition now.
   std::vector<Type *> ParamTys;
-  for (ArgIt I = ArgBegin; I != ArgEnd; ++I)
-    ParamTys.push_back((*I)->getType());
+  for (auto *I : Args)
+    ParamTys.push_back(I->getType());
   FunctionCallee FCache =
       M->getOrInsertFunction(NewFn, FunctionType::get(RetTy, ParamTys, false));
 
   IRBuilder<> Builder(CI->getParent(), CI->getIterator());
-  SmallVector<Value *, 8> Args(ArgBegin, ArgEnd);
-  CallInst *NewCI = Builder.CreateCall(FCache, Args);
+  SmallVector<Value *, 8> ArgVals(Args);
----------------
jasilvanus wrote:

This copy should now be unnecessary.

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


More information about the llvm-commits mailing list