| 1 | //===- LibcallLoweringInfo.cpp - Interface for runtime libcalls -----------===// |
| 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/CodeGen/LibcallLoweringInfo.h" |
| 10 | #include "llvm/Analysis/RuntimeLibcallInfo.h" |
| 11 | #include "llvm/CodeGen/TargetSubtargetInfo.h" |
| 12 | #include "llvm/InitializePasses.h" |
| 13 | #include "llvm/Target/TargetMachine.h" |
| 14 | |
| 15 | using namespace llvm; |
| 16 | |
| 17 | LibcallLoweringInfo::LibcallLoweringInfo( |
| 18 | const RTLIB::RuntimeLibcallsInfo &RTLCI, |
| 19 | const TargetSubtargetInfo &Subtarget) |
| 20 | : RTLCI(RTLCI) { |
| 21 | // TODO: This should be generated with lowering predicates, and assert the |
| 22 | // call is available. |
| 23 | for (RTLIB::LibcallImpl Impl : RTLIB::libcall_impls()) { |
| 24 | if (RTLCI.isAvailable(Impl)) { |
| 25 | RTLIB::Libcall LC = RTLIB::RuntimeLibcallsInfo::getLibcallFromImpl(Impl); |
| 26 | // FIXME: Hack, assume the first available libcall wins. |
| 27 | if (LibcallImpls[LC] == RTLIB::Unsupported) |
| 28 | LibcallImpls[LC] = Impl; |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | Subtarget.initLibcallLoweringInfo(Info&: *this); |
| 33 | } |
| 34 | |
| 35 | AnalysisKey LibcallLoweringModuleAnalysis::Key; |
| 36 | |
| 37 | bool LibcallLoweringModuleAnalysisResult::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 | |
| 46 | LibcallLoweringModuleAnalysisResult |
| 47 | LibcallLoweringModuleAnalysis::run(Module &M, ModuleAnalysisManager &MAM) { |
| 48 | LibcallLoweringMap.init(RT: &MAM.getResult<RuntimeLibraryAnalysis>(IR&: M)); |
| 49 | return LibcallLoweringMap; |
| 50 | } |
| 51 | |
| 52 | INITIALIZE_PASS_BEGIN(LibcallLoweringInfoWrapper, "libcall-lowering-info" , |
| 53 | "Library Function Lowering Analysis" , false, true) |
| 54 | INITIALIZE_PASS_DEPENDENCY(RuntimeLibraryInfoWrapper) |
| 55 | INITIALIZE_PASS_END(LibcallLoweringInfoWrapper, "libcall-lowering-info" , |
| 56 | "Library Function Lowering Analysis" , false, true) |
| 57 | |
| 58 | char LibcallLoweringInfoWrapper::ID = 0; |
| 59 | |
| 60 | LibcallLoweringInfoWrapper::LibcallLoweringInfoWrapper() : ImmutablePass(ID) {} |
| 61 | |
| 62 | void LibcallLoweringInfoWrapper::initializePass() { |
| 63 | RuntimeLibcallsWrapper = &getAnalysis<RuntimeLibraryInfoWrapper>(); |
| 64 | } |
| 65 | |
| 66 | void LibcallLoweringInfoWrapper::getAnalysisUsage(AnalysisUsage &AU) const { |
| 67 | AU.addRequired<RuntimeLibraryInfoWrapper>(); |
| 68 | AU.setPreservesAll(); |
| 69 | } |
| 70 | |
| 71 | void LibcallLoweringInfoWrapper::releaseMemory() { Result.clear(); } |
| 72 | |
| 73 | ModulePass *llvm::createLibcallLoweringInfoWrapper() { |
| 74 | return new LibcallLoweringInfoWrapper(); |
| 75 | } |
| 76 | |