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/Analysis/RuntimeLibcallInfo.h"
15#include "llvm/IR/Module.h"
16#include "llvm/IR/RuntimeLibcalls.h"
17
18using namespace llvm;
19
20PreservedAnalyses DeclareRuntimeLibcallsPass::run(Module &M,
21 ModuleAnalysisManager &MAM) {
22 const RTLIB::RuntimeLibcallsInfo &RTLCI =
23 MAM.getResult<RuntimeLibraryAnalysis>(IR&: M);
24
25 for (RTLIB::LibcallImpl Impl : RTLIB::libcall_impls()) {
26 if (!RTLCI.isAvailable(Impl))
27 continue;
28
29 if (RTLIB::RuntimeLibcallsInfo::isVariable(LibcallImpl: Impl))
30 RTLCI.getOrInsertImplGlobal(M, LibcallImpl: Impl);
31 else
32 RTLCI.getOrInsertLibcallDecl(M, LibcallImpl: Impl);
33 }
34
35 return PreservedAnalyses::none();
36}
37