[PATCH] D15776: Filtering IR printing for print-after-all/print-before-all

Mehdi AMINI via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 4 16:38:14 PST 2016


joker.eph added a comment.

Thanks for working on this, I thought about this multiple times, but never got to implement it. Some comments below.


================
Comment at: include/llvm/Pass.h:372
@@ -371,2 +371,3 @@
 
+extern bool isFunctionInPrintList(StringRef FunctionName);
 } // End llvm namespace
----------------
Document

================
Comment at: lib/Analysis/LoopPass.cpp:45
@@ -44,2 +44,3 @@
   bool runOnLoop(Loop *L, LPPassManager &) override {
-    P.run(*L);
+    if (L->getHeader() &&
+        isFunctionInPrintList(L->getHeader()->getParent()->getName()))
----------------
What if we don't have a header? When does it happen? Can this inhibit the print of a loop even when `-print-funcs` isn't supplied?
Else, could it be an assert instead?

================
Comment at: lib/CodeGen/MachineFunctionPrinterPass.cpp:45
@@ -44,3 +44,3 @@
   bool runOnMachineFunction(MachineFunction &MF) override {
-    OS << "# " << Banner << ":\n";
-    MF.print(OS, getAnalysisIfAvailable<SlotIndexes>());
+    if (llvm::isFunctionInPrintList(MF.getName())) {
+      OS << "# " << Banner << ":\n";
----------------
Early return is preferred (same for all the similar cases).

================
Comment at: lib/IR/IRPrintingPasses.cpp:34
@@ -32,1 +33,3 @@
+  } else
+    OS << Banner << " (skipped printing)\n";
   return PreservedAnalyses::all();
----------------
What about having the `else` here looping over the module and finding the functions selected to be printed and print them?

================
Comment at: lib/IR/LegacyPassManager.cpp:515
@@ -500,2 +514,3 @@
   activeStack.push(PMDM);
+  PrintFuncNames.insert(PrintFuncsList.begin(), PrintFuncsList.end());
 }
----------------
Not sure if this is the right place to do that, what about a static variable local to `isFunctionInPrintList()`, it would be initialized on the first call to the function.


Repository:
  rL LLVM

http://reviews.llvm.org/D15776





More information about the llvm-commits mailing list