1 //===- DeclareRuntimeLibcalls.cpp -----------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // Insert declarations for all runtime library calls known for the target. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "llvm/Transforms/Utils/DeclareRuntimeLibcalls.h" 14 #include "llvm/IR/Module.h" 15 #include "llvm/IR/RuntimeLibcalls.h" 16 17 using namespace llvm; 18 run(Module & M,ModuleAnalysisManager & MAM)19PreservedAnalyses DeclareRuntimeLibcallsPass::run(Module &M, 20 ModuleAnalysisManager &MAM) { 21 RTLIB::RuntimeLibcallsInfo RTLCI(M.getTargetTriple()); 22 LLVMContext &Ctx = M.getContext(); 23 24 for (RTLIB::LibcallImpl Impl : RTLCI.getLibcallImpls()) { 25 if (Impl == RTLIB::Unsupported) 26 continue; 27 28 // TODO: Declare with correct type, calling convention, and attributes. 29 30 FunctionType *FuncTy = 31 FunctionType::get(Type::getVoidTy(Ctx), {}, /*IsVarArgs=*/true); 32 33 const char *FuncName = RTLCI.getLibcallImplName(Impl); 34 M.getOrInsertFunction(FuncName, FuncTy); 35 } 36 37 return PreservedAnalyses::none(); 38 } 39