Rate This Document
Findability
Accuracy
Completeness
Readability

Updating a Pass Using NewPassManager

In Bisheng Compiler, you can use NewPassManager to customize passes. The following shows how to use a simple NewPassManager to implement a pass that outputs information when a function exits.

1
2
3
4
5
bool runBye(Function &F) {
  errs() << "Bye: ";
  errs().write_escaped(F.getName()) << '\n';
  return false;
}

The following uses NewPassManager to implement Bye Pass.

1
2
3
4
5
6
7
struct Bye : PassInfoMixin<Bye> {
  PreservedAnalyses run(Function &F, FunctionAnalysisManager &) {
    if (!runBye(F))
      return PreservedAnalyses::all();
    return PreservedAnalyses::none();
  }
};

PassInfoMixin provides a simple way to define passes. In a new pass, programmers only need to customize the run function. Users can execute their own functions in the run function. In this example, runBye() is called. The return result for Bisheng Compiler indicates which analysis results are still valid and which need to be recalculated.

  • PreservedAnalyses::all() indicates that all analysis results are still valid.
  • PreservedAnalyses::none() indicates that all analysis results need to be recalculated.