Skip to content

Commit

Permalink
[Lint] Use new PM instead of legacy PM in lintFunction and lintModule
Browse files Browse the repository at this point in the history
There are some helpers in the Lint analysis pass that will setup
a pass manager and then run the Lint pass on a given Function/Module.

Those have been using the LegacyPassManager, but as a small step
towards removing the deprecated legacy pass manager this patch is
changing those helpers into using the new pass manager instead.

No idea if anyone is really is using those helpers. Maybe an
alternative had been to just remove them. There is at least no unit
tests or similar that verifies that they work, so I validated this
patch by using a hacked opt binary that called those functions
before running the normal pipeline.

Differential Revision: https://reviews.llvm.org/D143388
  • Loading branch information
bjope committed Feb 6, 2023
1 parent df947fe commit 525ed98
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions llvm/lib/Analysis/Lint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Passes/PassBuilder.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/KnownBits.h"
#include "llvm/Support/raw_ostream.h"
Expand Down Expand Up @@ -771,17 +771,33 @@ void llvm::lintFunction(const Function &f) {
Function &F = const_cast<Function &>(f);
assert(!F.isDeclaration() && "Cannot lint external functions");

legacy::FunctionPassManager FPM(F.getParent());
auto *V = new LintLegacyPass();
FPM.add(V);
FPM.run(F);
PassBuilder PB;
LoopAnalysisManager LAM;
FunctionAnalysisManager FAM;
CGSCCAnalysisManager CGAM;
ModuleAnalysisManager MAM;
PB.registerModuleAnalyses(MAM);
PB.registerFunctionAnalyses(FAM);
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);

FunctionPassManager FPM;
FPM.addPass(LintPass());
FPM.run(F, FAM);
}

/// lintModule - Check a module for errors, printing messages on stderr.
///
void llvm::lintModule(const Module &M) {
legacy::PassManager PM;
auto *V = new LintLegacyPass();
PM.add(V);
PM.run(const_cast<Module &>(M));
PassBuilder PB;
LoopAnalysisManager LAM;
FunctionAnalysisManager FAM;
CGSCCAnalysisManager CGAM;
ModuleAnalysisManager MAM;
PB.registerModuleAnalyses(MAM);
PB.registerFunctionAnalyses(FAM);
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);

ModulePassManager MPM;
MPM.addPass(createModuleToFunctionPassAdaptor(LintPass()));
MPM.run(const_cast<Module &>(M), MAM);
}

0 comments on commit 525ed98

Please sign in to comment.