The libcall lowering decisions should be program dependent, depending on the current module's RuntimeLibcallInfo. We need another related analysis derived from that plus the current function's subtarget to provide concrete lowering decisions. This takes on a somewhat unusual form. It's a Module analysis, with a lookup keyed on the subtarget. This is a separate module analysis from RuntimeLibraryAnalysis to avoid that depending on codegen. It's not a function pass to avoid depending on any particular function, to avoid repeated subtarget map lookups in most of the use passes, and to avoid any recomputation in the common case of one subtarget (and keeps it reusable across repeated compilations). This also switches ExpandFp and PreISelIntrinsicLowering as a sample function and module pass. Note this is not yet wired up to SelectionDAG, which is still using the LibcallLoweringInfo constructed inside of TargetLowering.
62 lines
2.3 KiB
C++
62 lines
2.3 KiB
C++
//===- RuntimeLibcallInfo.cpp ---------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/Analysis/RuntimeLibcallInfo.h"
|
|
#include "llvm/InitializePasses.h"
|
|
|
|
using namespace llvm;
|
|
|
|
AnalysisKey RuntimeLibraryAnalysis::Key;
|
|
|
|
RuntimeLibraryAnalysis::RuntimeLibraryAnalysis(const Triple &TT,
|
|
ExceptionHandling ExceptionModel,
|
|
FloatABI::ABIType FloatABI,
|
|
EABI EABIVersion,
|
|
StringRef ABIName,
|
|
VectorLibrary VecLib)
|
|
: LibcallsInfo(std::in_place, TT, ExceptionModel, FloatABI, EABIVersion,
|
|
ABIName, VecLib) {}
|
|
|
|
RTLIB::RuntimeLibcallsInfo
|
|
RuntimeLibraryAnalysis::run(const Module &M, ModuleAnalysisManager &) {
|
|
if (!LibcallsInfo)
|
|
LibcallsInfo = RTLIB::RuntimeLibcallsInfo(M);
|
|
return *LibcallsInfo;
|
|
}
|
|
|
|
INITIALIZE_PASS(RuntimeLibraryInfoWrapper, "runtime-library-info",
|
|
"Runtime Library Function Analysis", false, true)
|
|
|
|
RuntimeLibraryInfoWrapper::RuntimeLibraryInfoWrapper()
|
|
: ImmutablePass(ID), RTLA(RTLIB::RuntimeLibcallsInfo(Triple())) {}
|
|
|
|
RuntimeLibraryInfoWrapper::RuntimeLibraryInfoWrapper(
|
|
const Triple &TT, ExceptionHandling ExceptionModel,
|
|
FloatABI::ABIType FloatABI, EABI EABIVersion, StringRef ABIName,
|
|
VectorLibrary VecLib)
|
|
: ImmutablePass(ID), RTLCI(std::in_place, TT, ExceptionModel, FloatABI,
|
|
EABIVersion, ABIName, VecLib) {}
|
|
|
|
char RuntimeLibraryInfoWrapper::ID = 0;
|
|
|
|
ModulePass *llvm::createRuntimeLibraryInfoWrapperPass() {
|
|
return new RuntimeLibraryInfoWrapper();
|
|
}
|
|
|
|
void RuntimeLibraryInfoWrapper::getAnalysisUsage(AnalysisUsage &AU) const {
|
|
AU.setPreservesAll();
|
|
}
|
|
|
|
// Assume this is stable unless explicitly invalidated.
|
|
bool RTLIB::RuntimeLibcallsInfo::invalidate(
|
|
Module &M, const PreservedAnalyses &PA,
|
|
ModuleAnalysisManager::Invalidator &) {
|
|
auto PAC = PA.getChecker<RuntimeLibraryAnalysis>();
|
|
return !PAC.preservedWhenStateless();
|
|
}
|