Skip to content

Commit 213d8a9

Browse files
committed
[NewPM][PassInstrumentation] IR printing support for (Thin)LTO
Summary: 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. Reviewers: fedor.sergeev, philip.pfaffe Subscribers: mehdi_amini, inglorion, hiraditya, steven_wu, dexonsmith, dang, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66253 llvm-svn: 369024
1 parent 7a210d6 commit 213d8a9

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

llvm/lib/LTO/LTOBackend.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "llvm/MC/SubtargetFeature.h"
2929
#include "llvm/Object/ModuleSymbolTable.h"
3030
#include "llvm/Passes/PassBuilder.h"
31+
#include "llvm/Passes/StandardInstrumentations.h"
3132
#include "llvm/Support/Error.h"
3233
#include "llvm/Support/FileSystem.h"
3334
#include "llvm/Support/MemoryBuffer.h"
@@ -165,7 +166,10 @@ static void runNewPMPasses(Config &Conf, Module &Mod, TargetMachine *TM,
165166
PGOOptions::IRUse, PGOOptions::CSIRUse);
166167
}
167168

168-
PassBuilder PB(TM, PipelineTuningOptions(), PGOOpt);
169+
PassInstrumentationCallbacks PIC;
170+
StandardInstrumentations SI;
171+
SI.registerCallbacks(PIC);
172+
PassBuilder PB(TM, PipelineTuningOptions(),PGOOpt, &PIC);
169173
AAManager AA;
170174

171175
// Parse a custom AA pipeline if asked to.

llvm/test/ThinLTO/X86/printer.ll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-lto2 run -r=%t.bc,foo,pxl -use-new-pm --print-before-all %t.bc -o - 2>&1 | FileCheck %s --check-prefix=CHECK-BEFORE
3+
; RUN: llvm-lto2 run -r=%t.bc,foo,pxl -use-new-pm --print-after-all %t.bc -o - 2>&1 | FileCheck %s --check-prefix=CHECK-AFTER
4+
; CHECK-BEFORE: *** IR Dump Before GlobalDCEPass ***
5+
; CHECK-AFTER: *** IR Dump After GlobalDCEPass ***
6+
7+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
8+
target triple = "x86_64-unknown-linux-gnu"
9+
10+
define i32 @foo() {
11+
ret i32 42
12+
}

0 commit comments

Comments
 (0)