[llvm] [CodeGen] Port dot-machine-cfg to new pass manager (PR #195901)

via llvm-commits llvm-commits at lists.llvm.org
Wed May 6 07:58:21 PDT 2026


================
@@ -91,3 +92,15 @@ bool MachineCFGPrinter::runOnMachineFunction(MachineFunction &MF) {
   writeMCFGToDotFile(MF);
   return false;
 }
+
+PreservedAnalyses
+MachineCFGPrinterPass::run(MachineFunction &MF,
+                           MachineFunctionAnalysisManager &MFAM) {
+  if (!MCFGFuncName.empty() && !MF.getName().contains(MCFGFuncName))
+    return PreservedAnalyses::all();
+  errs() << "Writing Machine CFG for function ";
+  errs().write_escaped(MF.getName()) << '\n';
+
+  writeMCFGToDotFile(MF);
+  return getMachineFunctionPassPreservedAnalyses().preserveSet<CFGAnalyses>();
----------------
juanvazquez wrote:

I read other passes and this seems to be how other passes translate what `getAnalysisUsage` does in the legacy pass:

```
  void getAnalysisUsage(AnalysisUsage &AU) const override {
    AU.setPreservesCFG();
    MachineFunctionPass::getAnalysisUsage(AU);
  }
```

I'd expect the legacy pass to call `AU.setPreservesAll();` to do `PreservedAnalyses::all()`.

Kindly let me know if you think I'm interpreting this wrong and it should indeed do `PreservedAnalyses::all()`, happy to change it.

https://github.com/llvm/llvm-project/pull/195901


More information about the llvm-commits mailing list