1//===- LibcallLoweringInfo.cpp - Runtime libcall lowering info ------------===//
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#include "llvm/Analysis/LibcallLoweringInfo.h"
10#include "llvm/Analysis/RuntimeLibcallInfo.h"
11
12using namespace llvm;
13
14LibcallLoweringInfo::LibcallLoweringInfo(
15 const RTLIB::RuntimeLibcallsInfo &RTLCI,
16 ApplyContextRulesFn ApplyContextRules)
17 : RTLCI(RTLCI) {
18 // TODO: This should be generated with lowering predicates, and assert the
19 // call is available.
20 for (RTLIB::LibcallImpl Impl : RTLIB::libcall_impls()) {
21 if (RTLCI.isAvailable(Impl)) {
22 RTLIB::Libcall LC = RTLCI.getLibcallFromImpl(Impl);
23 // FIXME: Hack, assume the first available libcall wins.
24 if (LC != RTLIB::UNKNOWN_LIBCALL &&
25 LibcallImpls[LC] == RTLIB::Unsupported)
26 LibcallImpls[LC] = Impl;
27 }
28 }
29
30 // Apply the caller's context-specific (e.g. subtarget) libcall rules.
31 if (ApplyContextRules)
32 ApplyContextRules(*this);
33}
34
35AnalysisKey LibcallLoweringModuleAnalysis::Key;
36
37bool ModuleLibcallLoweringInfo::invalidate(
38 Module &, const PreservedAnalyses &PA,
39 ModuleAnalysisManager::Invalidator &) {
40 // Passes that change the runtime libcall set must explicitly invalidate this
41 // pass.
42 auto PAC = PA.getChecker<LibcallLoweringModuleAnalysis>();
43 return !PAC.preservedWhenStateless();
44}
45
46ModuleLibcallLoweringInfo
47LibcallLoweringModuleAnalysis::run(Module &M, ModuleAnalysisManager &MAM) {
48 ModuleLibcallLoweringInfo Result;
49 Result.init(RT: &MAM.getResult<RuntimeLibraryAnalysis>(IR&: M));
50 return Result;
51}
52