-
Notifications
You must be signed in to change notification settings - Fork 15.1k
ExpandFp: Require RuntimeLibcallsInfo analysis #165197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| //===-- RuntimeLibcallInfo.h - Runtime library information ------*- C++ -*-===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_ANALYSIS_RUNTIMELIBCALLINFO_H | ||
| #define LLVM_ANALYSIS_RUNTIMELIBCALLINFO_H | ||
|
|
||
| #include "llvm/IR/RuntimeLibcalls.h" | ||
| #include "llvm/Pass.h" | ||
|
|
||
| namespace llvm { | ||
|
|
||
| class LLVM_ABI RuntimeLibraryAnalysis | ||
| : public AnalysisInfoMixin<RuntimeLibraryAnalysis> { | ||
| public: | ||
| using Result = RTLIB::RuntimeLibcallsInfo; | ||
|
|
||
| RuntimeLibraryAnalysis() = default; | ||
| RuntimeLibraryAnalysis(RTLIB::RuntimeLibcallsInfo &&BaselineInfoImpl) | ||
| : LibcallsInfo(std::move(BaselineInfoImpl)) {} | ||
| explicit RuntimeLibraryAnalysis(const Triple &T) : LibcallsInfo(T) {} | ||
|
|
||
| LLVM_ABI RTLIB::RuntimeLibcallsInfo run(const Module &M, | ||
| ModuleAnalysisManager &); | ||
|
|
||
| private: | ||
| friend AnalysisInfoMixin<RuntimeLibraryAnalysis>; | ||
| LLVM_ABI static AnalysisKey Key; | ||
|
|
||
| RTLIB::RuntimeLibcallsInfo LibcallsInfo; | ||
| }; | ||
|
|
||
| class LLVM_ABI RuntimeLibraryInfoWrapper : public ImmutablePass { | ||
| RuntimeLibraryAnalysis RTLA; | ||
| std::optional<RTLIB::RuntimeLibcallsInfo> RTLCI; | ||
|
|
||
| public: | ||
| static char ID; | ||
| RuntimeLibraryInfoWrapper(); | ||
| explicit RuntimeLibraryInfoWrapper(const Triple &T); | ||
| explicit RuntimeLibraryInfoWrapper(const RTLIB::RuntimeLibcallsInfo &RTLCI); | ||
|
|
||
| const RTLIB::RuntimeLibcallsInfo &getRTLCI(const Module &M) { | ||
| ModuleAnalysisManager DummyMAM; | ||
| RTLCI = RTLA.run(M, DummyMAM); | ||
| return *RTLCI; | ||
| } | ||
|
|
||
| void getAnalysisUsage(AnalysisUsage &AU) const override; | ||
| }; | ||
|
|
||
| LLVM_ABI ModulePass *createRuntimeLibraryInfoWrapperPass(); | ||
|
|
||
| } // namespace llvm | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| //===- 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; | ||
|
|
||
| RTLIB::RuntimeLibcallsInfo | ||
| RuntimeLibraryAnalysis::run(const Module &M, ModuleAnalysisManager &) { | ||
| return RTLIB::RuntimeLibcallsInfo(M); | ||
| } | ||
|
|
||
| INITIALIZE_PASS(RuntimeLibraryInfoWrapper, "runtime-library-info", | ||
| "Runtime Library Function Analysis", false, true) | ||
|
|
||
| RuntimeLibraryInfoWrapper::RuntimeLibraryInfoWrapper() | ||
| : ImmutablePass(ID), RTLA(RTLIB::RuntimeLibcallsInfo(Triple())) {} | ||
|
|
||
| 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(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| #include "llvm/ADT/SmallVector.h" | ||
| #include "llvm/Analysis/AssumptionCache.h" | ||
| #include "llvm/Analysis/GlobalsModRef.h" | ||
| #include "llvm/Analysis/RuntimeLibcallInfo.h" | ||
| #include "llvm/Analysis/SimplifyQuery.h" | ||
| #include "llvm/Analysis/ValueTracking.h" | ||
| #include "llvm/CodeGen/ISDOpcodes.h" | ||
|
|
@@ -1092,6 +1093,8 @@ class ExpandFpLegacyPass : public FunctionPass { | |
| auto *TM = &getAnalysis<TargetPassConfig>().getTM<TargetMachine>(); | ||
| auto *TLI = TM->getSubtargetImpl(F)->getTargetLowering(); | ||
| AssumptionCache *AC = nullptr; | ||
| const RTLIB::RuntimeLibcallsInfo *Libcalls = | ||
| &getAnalysis<RuntimeLibraryInfoWrapper>().getRTLCI(*F.getParent()); | ||
|
|
||
| if (OptLevel != CodeGenOptLevel::None && !F.hasOptNone()) | ||
| AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F); | ||
|
|
@@ -1104,6 +1107,7 @@ class ExpandFpLegacyPass : public FunctionPass { | |
| AU.addRequired<AssumptionCacheTracker>(); | ||
| AU.addPreserved<AAResultsWrapperPass>(); | ||
| AU.addPreserved<GlobalsAAWrapperPass>(); | ||
| AU.addRequired<RuntimeLibraryInfoWrapper>(); | ||
| } | ||
| }; | ||
| } // namespace | ||
|
|
@@ -1126,13 +1130,23 @@ PreservedAnalyses ExpandFpPass::run(Function &F, FunctionAnalysisManager &FAM) { | |
| AssumptionCache *AC = nullptr; | ||
| if (OptLevel != CodeGenOptLevel::None) | ||
| AC = &FAM.getResult<AssumptionAnalysis>(F); | ||
|
|
||
| auto &MAMProxy = FAM.getResult<ModuleAnalysisManagerFunctionProxy>(F); | ||
| const RTLIB::RuntimeLibcallsInfo *Libcalls = | ||
| MAMProxy.getCachedResult<RuntimeLibraryAnalysis>(*F.getParent()); | ||
| if (!Libcalls) { | ||
| F.getContext().emitError("'runtime-libcall-info' analysis required"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this pattern widely used? Should this just be an
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You cannot assert |
||
| return PreservedAnalyses::all(); | ||
| } | ||
|
|
||
| return runImpl(F, TLI, AC) ? PreservedAnalyses::none() | ||
| : PreservedAnalyses::all(); | ||
| } | ||
|
|
||
| char ExpandFpLegacyPass::ID = 0; | ||
| INITIALIZE_PASS_BEGIN(ExpandFpLegacyPass, "expand-fp", | ||
| "Expand certain fp instructions", false, false) | ||
| INITIALIZE_PASS_DEPENDENCY(RuntimeLibraryInfoWrapper) | ||
| INITIALIZE_PASS_END(ExpandFpLegacyPass, "expand-fp", "Expand fp", false, false) | ||
|
|
||
| FunctionPass *llvm::createExpandFpPass(CodeGenOptLevel OptLevel) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arsenm In the PR description, you wrote:
I am not super familiar with the details of this, but I had a look at the implementation and the documentation. The documentation on
ModuleAnalysisManagerFunctionProxyakaOuterAnalysisManagerProxy<ModuleAnalysisManager, Function>ininclude/llvm/IR/PassManager.hstates that:Hence it seems to me that you cannot/should not request the computation of the analysis information from here and you need to do it in this way.