Files
revng-revng/include/revng/Support/SimplePassManager.h
Giacomo Vercesi 5250ffbb6b Introduce SimplePassManager
Add the `SimplePassManager` and `SimpleFunctionPassManager` classes
which add wrappers around the new LLVM pass manager. Change all the
applicable uses of the legacy pass manager with the wrapper.
2026-02-05 09:25:42 +01:00

57 lines
1.3 KiB
C++

#pragma once
//
// This file is distributed under the MIT License. See LICENSE.md for details.
//
#include "llvm/Passes/PassBuilder.h"
namespace detail {
class SimplePassManagerBase {
protected:
llvm::LoopAnalysisManager LAM;
llvm::FunctionAnalysisManager FAM;
llvm::CGSCCAnalysisManager CGAM;
llvm::ModuleAnalysisManager MAM;
llvm::PassBuilder PB;
SimplePassManagerBase() {
PB.registerModuleAnalyses(MAM);
PB.registerCGSCCAnalyses(CGAM);
PB.registerFunctionAnalyses(FAM);
PB.registerLoopAnalyses(LAM);
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
}
};
} // namespace detail
/// Wrapper for the new llvm pass manager. Does all the required initialization
/// and exposes all the methods to have an easy to use pass manager.
class SimplePassManager : public detail::SimplePassManagerBase {
private:
llvm::ModulePassManager PM;
public:
template<typename T>
void addPass(T &&Pass) {
PM.addPass(std::forward<T>(Pass));
}
void run(llvm::Module &Module) { PM.run(Module, MAM); }
};
class SimpleFunctionPassManager : public detail::SimplePassManagerBase {
private:
llvm::FunctionPassManager PM;
public:
template<typename T>
void addPass(T &&Pass) {
PM.addPass(std::forward<T>(Pass));
}
void run(llvm::Function &Function) { PM.run(Function, FAM); }
};