[PATCH] D74814: IR printing for single function with the new pass manager.

Hongtao Yu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 18 23:28:25 PST 2020


hoyFB created this revision.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya.
Herald added projects: clang, LLVM.
hoyFB added a reviewer: wenlei.
hoyFB added a subscriber: wenlei.

The IR printing always prints out all functions in a module with the new pass manager, even with -filter-print-funcs specified. This is being fixed in this change. However, there are two exceptions, i.e, with user-specified wildcast switch -filter-print-funcs=* or -print-module-scope, under which IR of all functions should be printed.

Test Plan:
make check-clang
make check-llvm


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D74814

Files:
  clang/test/Misc/print-single-function.c
  llvm/lib/Passes/StandardInstrumentations.cpp


Index: llvm/lib/Passes/StandardInstrumentations.cpp
===================================================================
--- llvm/lib/Passes/StandardInstrumentations.cpp
+++ llvm/lib/Passes/StandardInstrumentations.cpp
@@ -70,16 +70,24 @@
   llvm_unreachable("Unknown IR unit");
 }
 
-void printIR(const Module *M, StringRef Banner, StringRef Extra = StringRef()) {
-  dbgs() << Banner << Extra << "\n";
-  M->print(dbgs(), nullptr, false);
-}
 void printIR(const Function *F, StringRef Banner,
              StringRef Extra = StringRef()) {
   if (!llvm::isFunctionInPrintList(F->getName()))
     return;
   dbgs() << Banner << Extra << "\n" << static_cast<const Value &>(*F);
 }
+
+void printIR(const Module *M, StringRef Banner, StringRef Extra = StringRef()) {
+  if (llvm::isFunctionInPrintList("*") || llvm::forcePrintModuleIR()) {
+    dbgs() << Banner << Extra << "\n";
+    M->print(dbgs(), nullptr, false);
+  } else {
+    for (const auto &F : M->functions()) {
+      printIR(&F, Banner, Extra);
+    }
+  }
+}
+
 void printIR(const LazyCallGraph::SCC *C, StringRef Banner,
              StringRef Extra = StringRef()) {
   bool BannerPrinted = false;
Index: clang/test/Misc/print-single-function.c
===================================================================
--- /dev/null
+++ clang/test/Misc/print-single-function.c
@@ -0,0 +1,21 @@
+// Testing single function IR printing with the new pass manager.  there are two exceptions, i.e, with user-specified wildcast switch -filter-print-funcs=* or -print-module-scope, under which IR of all functions should be printed.
+// RUN: %clang_cc1 -emit-llvm -fexperimental-new-pass-manager -mllvm -print-after-all -mllvm -filter-print-funcs=foo %s -o %t 2>&1 | FileCheck %s --check-prefix=FOO
+// RUN: %clang_cc1 -emit-llvm -fexperimental-new-pass-manager -mllvm -print-after-all -mllvm -filter-print-funcs=foo %s -mllvm -print-module-scope -o %t 2>&1 | FileCheck %s --check-prefix=ALL
+// RUN: %clang_cc1 -emit-llvm -fexperimental-new-pass-manager -mllvm -print-after-all -mllvm -filter-print-funcs=* %s -o %t 2>&1 | FileCheck %s --check-prefix=ALL
+
+// FOO: *** IR Dump After AlwaysInlinerPass ***
+// FOO: define void @foo()
+// FOO-NOT: define void @bar()
+
+// ALL: *** IR Dump After AlwaysInlinerPass ***
+// ALL-NEXT: ; ModuleID =
+// ALL: define void @foo()
+// ALL: define void @bar()
+
+void bar() {
+  return;
+}
+
+void foo() {
+  bar();
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74814.245330.patch
Type: text/x-patch
Size: 2412 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200219/2d367a63/attachment.bin>


More information about the cfe-commits mailing list