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