Writing an new LLVM Pass qustion

Hello expert :slight_smile:

I watched “Writing an LLVM Pass — LLVM 18.0.0git documentation

/--------------------------------------------------------------------------------------------------------------------------------
llvm/lib/Passes/PassRegistry.def → FUNCTION_PASS(“helloworld”, HelloWorldPass())
#include in `llvm/lib/Passes/PassBuilder.cpp → #include “llvm/Transforms/Utils/HelloWorld.h”
/---------------------------------------------------------------------------------------------------------------------------------

I followed this and successfully executed the LLVM file. But other llvm-tutor git hub, just add this

llvm::PassPluginLibraryInfo getOpcodeCounterPluginInfo() {
return {
LLVM_PLUGIN_API_VERSION, “OpcodeCounter”, LLVM_VERSION_STRING,
(PassBuilder &PB) {
// #1 REGISTRATION FOR “opt -passes=print”
// Register OpcodeCounterPrinter so that it can be used when
// specifying pass pipelines with -passes=.
PB.registerPipelineParsingCallback(
[&](StringRef Name, FunctionPassManager &FPM,
ArrayRefPassBuilder::PipelineElement) {
if (Name == “print”) {
FPM.addPass(OpcodeCounterPrinter(llvm::errs()));
return true;
}
return false;
});
(https://github.com/banach-space/llvm-tutor/blob/main/lib/OpcodeCounter.cpp)

The code above represents the steps outlined in “Writing an LLVM Pass” implemented in code?