-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Passes] Generalize ShouldRunExtraVectorPasses to allow re-use (NFCI). #118323
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
Changes from all commits
5e88848
7ca89e8
26ec459
4061b67
c58ee07
ddc5037
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,85 @@ | ||
//===- ExtraFunctionPassManager.h - Run Optimizations on Demand -*- 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// \file | ||
/// | ||
/// This file provides a pass manager that only runs its passes if the | ||
/// provided marker analysis has been preserved, together with a class to | ||
/// define such a marker analysis. | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_TRANSFORMS_UTILS_EXTRAPASSMANAGER_H | ||
#define LLVM_TRANSFORMS_UTILS_EXTRAPASSMANAGER_H | ||
|
||
#include "llvm/IR/PassManager.h" | ||
#include "llvm/Transforms/Scalar/LoopPassManager.h" | ||
|
||
namespace llvm { | ||
|
||
/// A marker analysis to determine if extra passes should be run on demand. | ||
/// Passes requesting extra transformations to run need to request and preserve | ||
/// this analysis. | ||
template <typename MarkerTy> struct ShouldRunExtraPasses { | ||
struct Result { | ||
bool invalidate(Function &F, const PreservedAnalyses &PA, | ||
FunctionAnalysisManager::Invalidator &) { | ||
// Check whether the analysis has been explicitly invalidated. Otherwise, | ||
// it remains preserved. | ||
auto PAC = PA.getChecker<MarkerTy>(); | ||
return !PAC.preservedWhenStateless(); | ||
} | ||
|
||
bool invalidate(Loop &L, const PreservedAnalyses &PA, | ||
LoopAnalysisManager::Invalidator &) { | ||
// Check whether the analysis has been explicitly invalidated. Otherwise, | ||
// it remains preserved. | ||
auto PAC = PA.getChecker<MarkerTy>(); | ||
return !PAC.preservedWhenStateless(); | ||
} | ||
}; | ||
|
||
Result run(Function &F, FunctionAnalysisManager &FAM) { return Result(); } | ||
|
||
Result run(Loop &L, LoopAnalysisManager &AM, | ||
LoopStandardAnalysisResults &AR) { | ||
return Result(); | ||
} | ||
}; | ||
|
||
/// A pass manager to run a set of extra function passes if the | ||
/// ShouldRunExtraPasses marker analysis is present. This allows passes to | ||
/// request additional transformations on demand. An example is extra | ||
/// simplifications after loop-vectorization, if runtime checks have been added. | ||
template <typename MarkerTy> | ||
struct ExtraFunctionPassManager : public FunctionPassManager { | ||
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. the new pass manager data structures very much do not endorse overriding methods via inheritance. I'd prefer 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. I put up #119348, is that what you had in mind? |
||
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM) { | ||
auto PA = PreservedAnalyses::all(); | ||
if (AM.getCachedResult<MarkerTy>(F)) | ||
PA.intersect(FunctionPassManager::run(F, AM)); | ||
PA.abandon<MarkerTy>(); | ||
return PA; | ||
} | ||
}; | ||
|
||
/// A pass manager to run a set of extra loop passes if the MarkerTy analysis is | ||
/// present. This allows passes to request additional transformations on demand. | ||
/// An example is doing additional runs of SimpleLoopUnswitch. | ||
template <typename MarkerTy> | ||
struct ExtraLoopPassManager : public LoopPassManager { | ||
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM, | ||
LoopStandardAnalysisResults &AR, LPMUpdater &U) { | ||
auto PA = PreservedAnalyses::all(); | ||
if (AM.getCachedResult<MarkerTy>(L)) | ||
PA.intersect(LoopPassManager::run(L, AM, AR, U)); | ||
PA.abandon<MarkerTy>(); | ||
return PA; | ||
} | ||
}; | ||
|
||
} // namespace llvm | ||
|
||
#endif // LLVM_TRANSFORMS_UTILS_EXTRAPASSMANAGER_H |
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.
Two empty lines.
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.
Single line now, thanks