[PATCH] D120993: [PassManager] Add pretty stack entries before P->run() call.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 4 13:08:22 PST 2022


fhahn updated this revision to Diff 413121.
fhahn added a comment.

Fix formatting, replace commented out code with explanation why the code doesn't call MF->getName().


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120993/new/

https://reviews.llvm.org/D120993

Files:
  llvm/include/llvm/IR/PassManager.h
  llvm/lib/IR/PassManager.cpp


Index: llvm/lib/IR/PassManager.cpp
===================================================================
--- llvm/lib/IR/PassManager.cpp
+++ llvm/lib/IR/PassManager.cpp
@@ -124,6 +124,7 @@
     PreservedAnalyses PassPA;
     {
       TimeTraceScope TimeScope(Pass->name(), F.getName());
+      NewPassManagerPrettyStackEntry StackEntry(Pass->name(), F);
       PassPA = Pass->run(F, FAM);
     }
 
@@ -152,3 +153,33 @@
 AnalysisSetKey CFGAnalyses::SetKey;
 
 AnalysisSetKey PreservedAnalyses::AllAnalysesKey;
+
+void NewPassManagerPrettyStackEntry::print(raw_ostream &OS) const {
+  OS << "Running pass '" << PassName << "'";
+
+  if (M) {
+    OS << " on module '" << M->getModuleIdentifier() << "'.\n";
+    return;
+  }
+
+  if (MF) {
+    // Printing the machine function's name would require pulling in
+    // llvm/Codegen/MachineFunction.h
+    OS << " on machine function \n";
+    return;
+  }
+
+  assert(V && "Either M, MF or V must be set");
+
+  OS << " on ";
+  if (isa<Function>(V))
+    OS << "function";
+  else if (isa<BasicBlock>(V))
+    OS << "basic block";
+  else
+    OS << "value";
+
+  OS << " '";
+  V->printAsOperand(OS, /*PrintType=*/false);
+  OS << "'\n";
+}
Index: llvm/include/llvm/IR/PassManager.h
===================================================================
--- llvm/include/llvm/IR/PassManager.h
+++ llvm/include/llvm/IR/PassManager.h
@@ -46,6 +46,7 @@
 #include "llvm/IR/Module.h"
 #include "llvm/IR/PassInstrumentation.h"
 #include "llvm/IR/PassManagerInternal.h"
+#include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/TypeName.h"
 #include <cassert>
@@ -451,6 +452,29 @@
 // header.
 class PassInstrumentationAnalysis;
 
+class MachineFunction;
+
+/// Add stack entry with the pass name and the IR unit it runs on.
+class NewPassManagerPrettyStackEntry : public PrettyStackTraceEntry {
+  StringRef PassName;
+  Module *M = nullptr;
+  MachineFunction *MF = nullptr;
+  Value *V = nullptr;
+
+public:
+  NewPassManagerPrettyStackEntry(StringRef PassName, Module &M)
+      : PassName(PassName), M(&M) {}
+
+  NewPassManagerPrettyStackEntry(StringRef PassName, MachineFunction &MF)
+      : PassName(PassName), MF(&MF) {}
+
+  NewPassManagerPrettyStackEntry(StringRef PassName, Value &V)
+      : PassName(PassName), V(&V) {}
+
+  /// print - Emit information about this stack frame to OS.
+  void print(raw_ostream &OS) const override;
+};
+
 /// Manages a sequence of passes over a particular unit of IR.
 ///
 /// A pass manager contains a sequence of passes to run over a particular unit
@@ -519,6 +543,7 @@
       PreservedAnalyses PassPA;
       {
         TimeTraceScope TimeScope(P->name(), IR.getName());
+        NewPassManagerPrettyStackEntry StackEntry(P->name(), IR);
         PassPA = P->run(IR, AM, ExtraArgs...);
       }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120993.413121.patch
Type: text/x-patch
Size: 2836 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220304/5e032d75/attachment.bin>


More information about the llvm-commits mailing list