This is an archive of the discontinued LLVM Phabricator instance.

[Lint] Use new PM instead of legacy PM in lintFunction and lintModule
ClosedPublic

Authored by bjope on Feb 6 2023, 4:44 AM.

Details

Summary

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.

Diff Detail

Event Timeline

bjope created this revision.Feb 6 2023, 4:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 6 2023, 4:44 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
bjope requested review of this revision.Feb 6 2023, 4:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 6 2023, 4:44 AM
bjope added inline comments.Feb 6 2023, 4:53 AM
llvm/lib/Analysis/Lint.cpp
774–785

I think this is how one is supposed to do it. But it gets a bit cluttery to setup all these managers everywhere.

Do you think it would be better to have some helper to setup a PassBuilder with default managers/analyses/proxies? (I don't think there exist such a helper today, but as some future improvement)

aeubanks accepted this revision.Feb 6 2023, 9:42 AM

can we delete the legacy pass?

llvm/lib/Analysis/Lint.cpp
774–785

yes, I was thinking about how to do that at some point then got distracted

probably something the lines of moving the analysis managers into the PassBuilder

This revision is now accepted and ready to land.Feb 6 2023, 9:42 AM
bjope added a comment.Feb 6 2023, 10:20 AM

can we delete the legacy pass?

It is a quite general analysis, so someone might of course add it in the backend to validate the IR just before ISel or similar. But I doubt that the pass is used like that, so we can probably delete the legacy version.
I can at least prepare another patch for removing the legacy pass, and then we'll see if/when we want to move forward with that.

This revision was landed with ongoing or failed builds.Feb 6 2023, 10:23 AM
This revision was automatically updated to reflect the committed changes.
bjope added a comment.Feb 6 2023, 10:41 AM

Had to revert this due to lots of buildbots failing when linking bugpoint.
Typically like this:

48.373 [370/4/3450] Linking CXX executable bin/bugpoint
FAILED: bin/bugpoint 
: && /usr/bin/c++ -fPIC -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -Wl,--export-dynamic  -Wl,-rpath-link,/home/uweigand/sandbox/buildbot/mlir-s390x-linux/build/./lib tools/bugpoint/CMakeFiles/bugpoint.dir/BugDriver.cpp.o tools/bugpoint/CMakeFiles/bugpoint.dir/CrashDebugger.cpp.o tools/bugpoint/CMakeFiles/bugpoint.dir/ExecutionDriver.cpp.o tools/bugpoint/CMakeFiles/bugpoint.dir/ExtractFunction.cpp.o tools/bugpoint/CMakeFiles/bugpoint.dir/FindBugs.cpp.o tools/bugpoint/CMakeFiles/bugpoint.dir/Miscompilation.cpp.o tools/bugpoint/CMakeFiles/bugpoint.dir/OptimizerDriver.cpp.o tools/bugpoint/CMakeFiles/bugpoint.dir/ToolRunner.cpp.o tools/bugpoint/CMakeFiles/bugpoint.dir/bugpoint.cpp.o -o bin/bugpoint  -Wl,-rpath,"\$ORIGIN/../lib"  lib/libLLVMSystemZAsmParser.a  lib/libLLVMSystemZCodeGen.a  lib/libLLVMSystemZDesc.a  lib/libLLVMSystemZInfo.a  lib/libLLVMAnalysis.a  lib/libLLVMBitWriter.a  lib/libLLVMCodeGen.a  lib/libLLVMExtensions.a  lib/libLLVMCore.a  lib/libLLVMipo.a  lib/libLLVMIRReader.a  lib/libLLVMAggressiveInstCombine.a  lib/libLLVMInstCombine.a  lib/libLLVMInstrumentation.a  lib/libLLVMLinker.a  lib/libLLVMObjCARCOpts.a  lib/libLLVMScalarOpts.a  lib/libLLVMSupport.a  lib/libLLVMTarget.a  lib/libLLVMTargetParser.a  lib/libLLVMTransformUtils.a  lib/libLLVMVectorize.a  -lpthread  lib/libLLVMAsmPrinter.a  lib/libLLVMSelectionDAG.a  lib/libLLVMCodeGen.a  lib/libLLVMObjCARCOpts.a  lib/libLLVMTarget.a  lib/libLLVMBitWriter.a  lib/libLLVMFrontendOpenMP.a  lib/libLLVMScalarOpts.a  lib/libLLVMAggressiveInstCombine.a  lib/libLLVMInstCombine.a  lib/libLLVMTransformUtils.a  lib/libLLVMAnalysis.a  lib/libLLVMProfileData.a  lib/libLLVMSymbolize.a  lib/libLLVMDebugInfoDWARF.a  lib/libLLVMDebugInfoPDB.a  lib/libLLVMObject.a  lib/libLLVMIRReader.a  lib/libLLVMAsmParser.a  lib/libLLVMMCParser.a  lib/libLLVMBitReader.a  lib/libLLVMTextAPI.a  lib/libLLVMDebugInfoMSF.a  lib/libLLVMCore.a  lib/libLLVMRemarks.a  lib/libLLVMBitstreamReader.a  lib/libLLVMMC.a  lib/libLLVMBinaryFormat.a  lib/libLLVMTargetParser.a  lib/libLLVMDebugInfoCodeView.a  lib/libLLVMSupport.a  lib/libLLVMDemangle.a  -lrt  -ldl  -lpthread  -lm  /usr/lib/s390x-linux-gnu/libz.so && :
/usr/bin/ld: lib/libLLVMAnalysis.a(Lint.cpp.o): in function `llvm::lintFunction(llvm::Function const&)':
Lint.cpp:(.text._ZN4llvm12lintFunctionERKNS_8FunctionE+0x62): undefined reference to `llvm::PipelineTuningOptions::PipelineTuningOptions()'
/usr/bin/ld: Lint.cpp:(.text._ZN4llvm12lintFunctionERKNS_8FunctionE+0x90): undefined reference to `llvm::PassBuilder::PassBuilder(llvm::TargetMachine*, llvm::PipelineTuningOptions, std::optional<llvm::PGOOptions>, llvm::PassInstrumentationCallbacks*)'
/usr/bin/ld: Lint.cpp:(.text._ZN4llvm12lintFunctionERKNS_8FunctionE+0xde): undefined reference to `llvm::PassBuilder::registerModuleAnalyses(llvm::AnalysisManager<llvm::Module>&)'
/usr/bin/ld: Lint.cpp:(.text._ZN4llvm12lintFunctionERKNS_8FunctionE+0xec): undefined reference to `llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)'
/usr/bin/ld: Lint.cpp:(.text._ZN4llvm12lintFunctionERKNS_8FunctionE+0x102): undefined reference to `llvm::PassBuilder::crossRegisterProxies(llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::AnalysisManager<llvm::Function>&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::AnalysisManager<llvm::Module>&)'
/usr/bin/ld: lib/libLLVMAnalysis.a(Lint.cpp.o): in function `llvm::lintModule(llvm::Module const&)':
Lint.cpp:(.text._ZN4llvm10lintModuleERKNS_6ModuleE+0x46): undefined reference to `llvm::PipelineTuningOptions::PipelineTuningOptions()'
/usr/bin/ld: Lint.cpp:(.text._ZN4llvm10lintModuleERKNS_6ModuleE+0x70): undefined reference to `llvm::PassBuilder::PassBuilder(llvm::TargetMachine*, llvm::PipelineTuningOptions, std::optional<llvm::PGOOptions>, llvm::PassInstrumentationCallbacks*)'
/usr/bin/ld: Lint.cpp:(.text._ZN4llvm10lintModuleERKNS_6ModuleE+0xc2): undefined reference to `llvm::PassBuilder::registerModuleAnalyses(llvm::AnalysisManager<llvm::Module>&)'
/usr/bin/ld: Lint.cpp:(.text._ZN4llvm10lintModuleERKNS_6ModuleE+0xd0): undefined reference to `llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)'
/usr/bin/ld: Lint.cpp:(.text._ZN4llvm10lintModuleERKNS_6ModuleE+0xe6): undefined reference to `llvm::PassBuilder::crossRegisterProxies(llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::AnalysisManager<llvm::Function>&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::AnalysisManager<llvm::Module>&)'
collect2: error: ld returned 1 exit status

Would perhaps be simpler to just remove lintFunction and lintModule. Not sure if anyone really need those debug support helpers.

+1 to removing those.

if we wanted to go down this route of using the new PM, we'd need to link in Passes into the CMakeLists.txt, which creates a dependency cycle.