LLVM New Pass Manager

Hi,
I’m trying to run the following:
analysis pass → transformation pass
In the new pass manger, How can I use the information from the analysis pass? I’m trying to do similar to legacy PM i.e., making a function which returns the analysis of analysis pass and then use that return object to see the analysis. But I’m facing some issues:
This is my example code:

AnalysisKey collectInstructions::Key;

collectInstructions::Result collectInstructions::run(Module &M, ModuleAnalysisManager &AM) {
  std::vector<Instruction*> instructions;
  for (Function &F : M) {
    for (auto &BB : F) {
      for (auto Inst = BB.begin(), IE = BB.end(); Inst != IE; ++Inst) {
        instructions.push_back(&*Inst);
      }
    }
  }
  return instructions;
}

PreservedAnalyses NewHelloWorldPass::run(Module &M, ModuleAnalysisManager &AM) {
  std::vector<Instruction*> instructions = AM.getResult< collectInstructions> (M);
  return PreservedAnalyses::all();
}

This is my analysis pass which is just appending all the instructions inside a vector. And then I’m trying to use this vector in my next pass in the pipeline i.e., transformation pass. But I’m getting errors:

/llvm/IR/PassManager.h:775:42: error: ‘ID’ is not a member of ‘llvm::collectInstructions’
  775 |     assert(AnalysisPasses.count(PassT::ID())
/llvm/IR/PassManager.h:778:32: error: ‘ID’ is not a member of ‘llvm::collectInstructions’
  778 |         getResultImpl(PassT::ID(), IR, ExtraArgs...);

Can someone please guide me the correct way to forward my analysis from previous pass to the next pass in new pass manager.

You probably didn’t inherit from PassInfoMixin<YourAnalysis>, e.g. see an in-tree example.