| 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 | |
| 12 | using namespace llvm; |
| 13 | |
| 14 | LibcallLoweringInfo::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 = RTLIB::RuntimeLibcallsInfo::getLibcallFromImpl(Impl); |
| 23 | // FIXME: Hack, assume the first available libcall wins. |
| 24 | if (LibcallImpls[LC] == RTLIB::Unsupported) |
| 25 | LibcallImpls[LC] = Impl; |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | // Apply the caller's context-specific (e.g. subtarget) libcall rules. |
| 30 | if (ApplyContextRules) |
| 31 | ApplyContextRules(*this); |
| 32 | } |
| 33 | |
| 34 | AnalysisKey LibcallLoweringModuleAnalysis::Key; |
| 35 | |
| 36 | bool ModuleLibcallLoweringInfo::invalidate( |
| 37 | Module &, const PreservedAnalyses &PA, |
| 38 | ModuleAnalysisManager::Invalidator &) { |
| 39 | // Passes that change the runtime libcall set must explicitly invalidate this |
| 40 | // pass. |
| 41 | auto PAC = PA.getChecker<LibcallLoweringModuleAnalysis>(); |
| 42 | return !PAC.preservedWhenStateless(); |
| 43 | } |
| 44 | |
| 45 | ModuleLibcallLoweringInfo |
| 46 | LibcallLoweringModuleAnalysis::run(Module &M, ModuleAnalysisManager &MAM) { |
| 47 | LibcallLoweringMap.init(RT: &MAM.getResult<RuntimeLibraryAnalysis>(IR&: M)); |
| 48 | return LibcallLoweringMap; |
| 49 | } |
| 50 |