[PATCH] D66253: [NewPM][PassInstrumentation] IR printing support for (Thin)LTO

Taewook Oh via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 14 13:28:30 PDT 2019


twoh created this revision.
twoh added reviewers: fedor.sergeev, philip.pfaffe.
Herald added subscribers: dang, dexonsmith, steven_wu, hiraditya, inglorion, mehdi_amini.
Herald added a project: LLVM.

IR printing has not been correctly supported with (Thin)LTO if the new pass manager is enabled. Previously we only get outputs from backend(codegen) passes, as they are still under legacy pass manager even when the new pass manager is enabled. This patch addresses the issue and enables IR printing for optimization passes with new pass manager + (Thin)LTO setting.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66253

Files:
  llvm/lib/LTO/LTOBackend.cpp
  llvm/test/LTO/X86/Inputs/printer.ll
  llvm/test/LTO/X86/printer.ll


Index: llvm/test/LTO/X86/printer.ll
===================================================================
--- /dev/null
+++ llvm/test/LTO/X86/printer.ll
@@ -0,0 +1,14 @@
+; RUN: clang -flto -fexperimental-new-pass-manager -Wl,-plugin-opt,-print-before-all %s %p/Inputs/printer.ll -o - 2>&1 | FileCheck %s --check-prefix=CHECK-BEFORE
+; RUN: clang -flto -fexperimental-new-pass-manager -Wl,-plugin-opt,-print-after-all %s %p/Inputs/printer.ll -o - 2>&1 | FileCheck %s --check-prefix=CHECK-AFTER
+; CHECK-BEFORE: *** IR Dump Before GlobalDCEPass ***
+; CHECK-AFTER: *** IR Dump After GlobalDCEPass ***
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define i32 @main() {
+    call void @foo()
+    ret i32 42
+}
+
+declare void @foo()
Index: llvm/test/LTO/X86/Inputs/printer.ll
===================================================================
--- /dev/null
+++ llvm/test/LTO/X86/Inputs/printer.ll
@@ -0,0 +1,6 @@
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @foo() {
+    ret void
+}
Index: llvm/lib/LTO/LTOBackend.cpp
===================================================================
--- llvm/lib/LTO/LTOBackend.cpp
+++ llvm/lib/LTO/LTOBackend.cpp
@@ -28,6 +28,7 @@
 #include "llvm/MC/SubtargetFeature.h"
 #include "llvm/Object/ModuleSymbolTable.h"
 #include "llvm/Passes/PassBuilder.h"
+#include "llvm/Passes/StandardInstrumentations.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -165,7 +166,10 @@
                         PGOOptions::IRUse, PGOOptions::CSIRUse);
   }
 
-  PassBuilder PB(TM, PipelineTuningOptions(), PGOOpt);
+  PassInstrumentationCallbacks PIC;
+  StandardInstrumentations SI;
+  SI.registerCallbacks(PIC);
+  PassBuilder PB(TM, PipelineTuningOptions(),PGOOpt, &PIC);
   AAManager AA;
 
   // Parse a custom AA pipeline if asked to.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66253.215227.patch
Type: text/x-patch
Size: 1963 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190814/39a1becb/attachment.bin>


More information about the llvm-commits mailing list