Skip to content

Commit 7a6a2cc

Browse files
committed
[LTO] Add option enable NewPM with LTOCodeGenerator.
This patch adds an option to enable the new pass manager in LTOCodeGenerator. It also updates a few tests with legacy PM specific tests, which started failing after 6a59f05 when LLVM_ENABLE_NEW_PASS_MANAGER=true.
1 parent 6a59f05 commit 7a6a2cc

File tree

6 files changed

+35
-12
lines changed

6 files changed

+35
-12
lines changed

llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ struct LTOCodeGenerator {
186186

187187
void setDisableVerify(bool Value) { DisableVerify = Value; }
188188

189+
void setUseNewPM(bool Value) { UseNewPM = Value; }
190+
189191
void setDiagnosticHandler(lto_diagnostic_handler_t, void *);
190192

191193
LLVMContext &getContext() { return Context; }
@@ -246,6 +248,7 @@ struct LTOCodeGenerator {
246248
bool Freestanding = false;
247249
std::unique_ptr<ToolOutputFile> StatsFile = nullptr;
248250
bool DisableVerify = false;
251+
bool UseNewPM = LLVM_ENABLE_NEW_PASS_MANAGER;
249252
};
250253
}
251254
#endif

llvm/lib/LTO/LTOCodeGenerator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ lto::Config LTOCodeGenerator::toConfig() const {
145145
Conf.PreCodeGenPassesHook = [](legacy::PassManager &PM) {
146146
PM.add(createObjCARCContractPass());
147147
};
148+
Conf.UseNewPM = UseNewPM;
148149

149150
return Conf;
150151
}

llvm/test/LTO/X86/diagnostic-handler-remarks.ll

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,41 @@
11
; RUN: llvm-as < %s >%t.bc
22
; PR21108: Diagnostic handlers get pass remarks, even if they're not enabled.
33

4+
; FIXME: Update checks for new pass manager.
5+
46
; Confirm that there are -pass-remarks.
5-
; RUN: llvm-lto -pass-remarks=inline \
7+
; RUN: llvm-lto -use-new-pm=false \
8+
; RUN: -pass-remarks=inline \
69
; RUN: -exported-symbol _func2 -pass-remarks-analysis=loop-vectorize \
710
; RUN: -exported-symbol _main -o %t.o %t.bc 2>&1 | \
811
; RUN: FileCheck %s -allow-empty -check-prefix=REMARKS
912
; RUN: llvm-nm %t.o | FileCheck %s -check-prefix NM
1013

11-
; RUN: llvm-lto -pass-remarks=inline -use-diagnostic-handler \
14+
; RUN: llvm-lto -use-new-pm=false \
15+
; RUN: -pass-remarks=inline -use-diagnostic-handler \
1216
; RUN: -exported-symbol _func2 -pass-remarks-analysis=loop-vectorize \
13-
; RUN: -exported-symbol _main -o %t.o %t.bc 2>&1 | \
17+
; RUN: -exported-symbol _main -o %t.o %t.bc 2>&1 | \
1418
; RUN: FileCheck %s -allow-empty -check-prefix=REMARKS_DH
1519
; RUN: llvm-nm %t.o | FileCheck %s -check-prefix NM
1620

1721
; Confirm that -pass-remarks are not printed by default.
18-
; RUN: llvm-lto \
22+
; RUN: llvm-lto -use-new-pm=false \
1923
; RUN: -exported-symbol _func2 \
2024
; RUN: -exported-symbol _main -o %t.o %t.bc 2>&1 | \
2125
; RUN: FileCheck %s -allow-empty
2226
; RUN: llvm-nm %t.o | FileCheck %s -check-prefix NM
2327

24-
; RUN: llvm-lto -use-diagnostic-handler \
25-
; RUN: -exported-symbol _func2 \
26-
; RUN: -exported-symbol _main -o %t.o %t.bc 2>&1 | \
28+
; RUN: llvm-lto -use-new-pm=false \
29+
; RUN: -use-diagnostic-handler \
30+
; RUN: -exported-symbol _func2 \
31+
; RUN: -exported-symbol _main -o %t.o %t.bc 2>&1 | \
2732
; RUN: FileCheck %s -allow-empty
2833
; RUN: llvm-nm %t.o | FileCheck %s -check-prefix NM
2934

3035
; Optimization records are collected regardless of the diagnostic handler
3136
; RUN: rm -f %t.yaml
32-
; RUN: llvm-lto -lto-pass-remarks-output=%t.yaml \
37+
; RUN: llvm-lto -use-new-pm=false \
38+
; RUN: -lto-pass-remarks-output=%t.yaml \
3339
; RUN: -exported-symbol _func2 \
3440
; RUN: -exported-symbol _main -o %t.o %t.bc 2>&1 | \
3541
; RUN: FileCheck %s -allow-empty

llvm/test/LTO/X86/disable-verify.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
; RUN: llvm-as < %s >%t.bc
2-
; RUN: llvm-lto -debug-pass=Arguments -exported-symbol=_f -o /dev/null %t.bc 2>&1 -disable-verify | FileCheck %s
3-
; RUN: llvm-lto -debug-pass=Arguments -exported-symbol=_f -o /dev/null %t.bc 2>&1 | FileCheck %s -check-prefix=VERIFY
2+
; RUN: llvm-lto -use-new-pm=false -debug-pass=Arguments -exported-symbol=_f -o /dev/null %t.bc 2>&1 -disable-verify | FileCheck %s
3+
; RUN: llvm-lto -use-new-pm=false -debug-pass=Arguments -exported-symbol=_f -o /dev/null %t.bc 2>&1 | FileCheck %s -check-prefix=VERIFY
4+
5+
; FIXME: Update checks for new pass manager.
46

57
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
68
target triple = "x86_64-apple-macosx10.10.0"

llvm/test/Other/X86/lto-hot-cold-split.ll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
; RUN: opt -module-summary %s -o %t.bc
2-
; RUN: llvm-lto -hot-cold-split=true -thinlto-action=run %t.bc -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=OLDPM-ANYLTO-POSTLINK-Os
3-
; RUN: llvm-lto -hot-cold-split=true %t.bc -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=OLDPM-ANYLTO-POSTLINK-Os
2+
; RUN: llvm-lto -use-new-pm=false -hot-cold-split=true \
3+
; RUN: -thinlto-action=run %t.bc -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=OLDPM-ANYLTO-POSTLINK-Os
4+
; RUN: llvm-lto -use-new-pm=false -hot-cold-split=true \
5+
; RUN: %t.bc -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=OLDPM-ANYLTO-POSTLINK-Os
6+
7+
; FIXME: Update checks for new pass manager.
48

59
; REQUIRES: asserts
610

llvm/tools/llvm-lto/llvm-lto.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ static cl::opt<bool> PrintMachOCPUOnly(
222222
"print-macho-cpu-only", cl::init(false),
223223
cl::desc("Instead of running LTO, print the mach-o cpu in each IR file"));
224224

225+
static cl::opt<bool>
226+
UseNewPM("use-new-pm",
227+
cl::desc("Run LTO passes using the new pass manager"),
228+
cl::init(LLVM_ENABLE_NEW_PASS_MANAGER), cl::Hidden);
229+
225230
namespace {
226231

227232
struct ModuleInfo {
@@ -1014,6 +1019,8 @@ int main(int argc, char **argv) {
10141019
CodeGen.setOptLevel(OptLevel - '0');
10151020
CodeGen.setAttrs(codegen::getMAttrs());
10161021

1022+
CodeGen.setUseNewPM(UseNewPM);
1023+
10171024
if (auto FT = codegen::getExplicitFileType())
10181025
CodeGen.setFileType(FT.getValue());
10191026

0 commit comments

Comments
 (0)