Skip to content

Where and When does the outer customized pass plugin execute exactly? #144992

Open
@TJU-PanYizhe

Description

@TJU-PanYizhe

I used PassInfoMixin to implement my own pass plugin and load it with clang-19 -fpass-plugin="build/libRCXLP.so" tests/test.c -S -emit-llvm -o tests/out/test_clang.ll command.

I wonder Where and When does this pass plugin execute exactly?

  • before all other passes implemented in llvm
  • or after all other passes
  • or ... ?

This is my pass plugin code

#include "RCXLP.h"

using namespace std;
using namespace llvm;

namespace
{
  class MY_TEST_Pass : public PassInfoMixin<MY_TEST_Pass>
  {
  public:
    vector<RCXLP::RIRInstruction> rir_instructions;

    PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
    {
      cout << "My first pass plugin" << endl;
      return PreservedAnalyses::all();
    }
  };
}

llvm::PassPluginLibraryInfo getMyPluginInfo()
{
  return {
      LLVM_PLUGIN_API_VERSION, "MY_TEST_Pass", "v0.1",
      [](llvm::PassBuilder &PB)
      {
        PB.registerPipelineStartEPCallback(
            [](ModulePassManager &MPM, OptimizationLevel Level)
            {
              FunctionPassManager FPM;
              MPM.addPass(MY_TEST_Pass());
            });
        PB.registerPipelineParsingCallback(
            [](
                llvm::StringRef Name, llvm::ModulePassManager &MPM,
                llvm::ArrayRef<llvm::PassBuilder::PipelineElement>)
            {
              if (Name == "my-test")
              {
                MPM.addPass(MY_TEST_Pass());
                return true;
              }
              return false;
            });
      }};
}

extern "C" LLVM_ATTRIBUTE_WEAK ::llvm::PassPluginLibraryInfo
llvmGetPassPluginInfo()
{
  return getMyPluginInfo();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    llvm:irquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions