From 7a6a2cc81aaf064e6f5bc9a9a16973f552d2bdc2 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Sat, 30 Jan 2021 11:50:37 +0000 Subject: [PATCH] [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 6a59f0560648 when LLVM_ENABLE_NEW_PASS_MANAGER=true. --- llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h | 3 +++ llvm/lib/LTO/LTOCodeGenerator.cpp | 1 + llvm/test/LTO/X86/diagnostic-handler-remarks.ll | 22 ++++++++++++++-------- llvm/test/LTO/X86/disable-verify.ll | 6 ++++-- llvm/test/Other/X86/lto-hot-cold-split.ll | 8 ++++++-- llvm/tools/llvm-lto/llvm-lto.cpp | 7 +++++++ 6 files changed, 35 insertions(+), 12 deletions(-) diff --git a/llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h b/llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h index b57c7da..8a7c49e 100644 --- a/llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h +++ b/llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h @@ -186,6 +186,8 @@ struct LTOCodeGenerator { void setDisableVerify(bool Value) { DisableVerify = Value; } + void setUseNewPM(bool Value) { UseNewPM = Value; } + void setDiagnosticHandler(lto_diagnostic_handler_t, void *); LLVMContext &getContext() { return Context; } @@ -246,6 +248,7 @@ private: bool Freestanding = false; std::unique_ptr StatsFile = nullptr; bool DisableVerify = false; + bool UseNewPM = LLVM_ENABLE_NEW_PASS_MANAGER; }; } #endif diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp index 180d906..86c0906c 100644 --- a/llvm/lib/LTO/LTOCodeGenerator.cpp +++ b/llvm/lib/LTO/LTOCodeGenerator.cpp @@ -145,6 +145,7 @@ lto::Config LTOCodeGenerator::toConfig() const { Conf.PreCodeGenPassesHook = [](legacy::PassManager &PM) { PM.add(createObjCARCContractPass()); }; + Conf.UseNewPM = UseNewPM; return Conf; } diff --git a/llvm/test/LTO/X86/diagnostic-handler-remarks.ll b/llvm/test/LTO/X86/diagnostic-handler-remarks.ll index 6af6d86..f38293d 100644 --- a/llvm/test/LTO/X86/diagnostic-handler-remarks.ll +++ b/llvm/test/LTO/X86/diagnostic-handler-remarks.ll @@ -1,35 +1,41 @@ ; RUN: llvm-as < %s >%t.bc ; PR21108: Diagnostic handlers get pass remarks, even if they're not enabled. +; FIXME: Update checks for new pass manager. + ; Confirm that there are -pass-remarks. -; RUN: llvm-lto -pass-remarks=inline \ +; RUN: llvm-lto -use-new-pm=false \ +; RUN: -pass-remarks=inline \ ; RUN: -exported-symbol _func2 -pass-remarks-analysis=loop-vectorize \ ; RUN: -exported-symbol _main -o %t.o %t.bc 2>&1 | \ ; RUN: FileCheck %s -allow-empty -check-prefix=REMARKS ; RUN: llvm-nm %t.o | FileCheck %s -check-prefix NM -; RUN: llvm-lto -pass-remarks=inline -use-diagnostic-handler \ +; RUN: llvm-lto -use-new-pm=false \ +; RUN: -pass-remarks=inline -use-diagnostic-handler \ ; RUN: -exported-symbol _func2 -pass-remarks-analysis=loop-vectorize \ -; RUN: -exported-symbol _main -o %t.o %t.bc 2>&1 | \ +; RUN: -exported-symbol _main -o %t.o %t.bc 2>&1 | \ ; RUN: FileCheck %s -allow-empty -check-prefix=REMARKS_DH ; RUN: llvm-nm %t.o | FileCheck %s -check-prefix NM ; Confirm that -pass-remarks are not printed by default. -; RUN: llvm-lto \ +; RUN: llvm-lto -use-new-pm=false \ ; RUN: -exported-symbol _func2 \ ; RUN: -exported-symbol _main -o %t.o %t.bc 2>&1 | \ ; RUN: FileCheck %s -allow-empty ; RUN: llvm-nm %t.o | FileCheck %s -check-prefix NM -; RUN: llvm-lto -use-diagnostic-handler \ -; RUN: -exported-symbol _func2 \ -; RUN: -exported-symbol _main -o %t.o %t.bc 2>&1 | \ +; RUN: llvm-lto -use-new-pm=false \ +; RUN: -use-diagnostic-handler \ +; RUN: -exported-symbol _func2 \ +; RUN: -exported-symbol _main -o %t.o %t.bc 2>&1 | \ ; RUN: FileCheck %s -allow-empty ; RUN: llvm-nm %t.o | FileCheck %s -check-prefix NM ; Optimization records are collected regardless of the diagnostic handler ; RUN: rm -f %t.yaml -; RUN: llvm-lto -lto-pass-remarks-output=%t.yaml \ +; RUN: llvm-lto -use-new-pm=false \ +; RUN: -lto-pass-remarks-output=%t.yaml \ ; RUN: -exported-symbol _func2 \ ; RUN: -exported-symbol _main -o %t.o %t.bc 2>&1 | \ ; RUN: FileCheck %s -allow-empty diff --git a/llvm/test/LTO/X86/disable-verify.ll b/llvm/test/LTO/X86/disable-verify.ll index 0d507e6..8f34eda 100644 --- a/llvm/test/LTO/X86/disable-verify.ll +++ b/llvm/test/LTO/X86/disable-verify.ll @@ -1,6 +1,8 @@ ; RUN: llvm-as < %s >%t.bc -; RUN: llvm-lto -debug-pass=Arguments -exported-symbol=_f -o /dev/null %t.bc 2>&1 -disable-verify | FileCheck %s -; RUN: llvm-lto -debug-pass=Arguments -exported-symbol=_f -o /dev/null %t.bc 2>&1 | FileCheck %s -check-prefix=VERIFY +; RUN: llvm-lto -use-new-pm=false -debug-pass=Arguments -exported-symbol=_f -o /dev/null %t.bc 2>&1 -disable-verify | FileCheck %s +; 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 + +; FIXME: Update checks for new pass manager. target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-apple-macosx10.10.0" diff --git a/llvm/test/Other/X86/lto-hot-cold-split.ll b/llvm/test/Other/X86/lto-hot-cold-split.ll index 1c6a33d..dda1437 100644 --- a/llvm/test/Other/X86/lto-hot-cold-split.ll +++ b/llvm/test/Other/X86/lto-hot-cold-split.ll @@ -1,6 +1,10 @@ ; RUN: opt -module-summary %s -o %t.bc -; 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 -; RUN: llvm-lto -hot-cold-split=true %t.bc -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=OLDPM-ANYLTO-POSTLINK-Os +; RUN: llvm-lto -use-new-pm=false -hot-cold-split=true \ +; RUN: -thinlto-action=run %t.bc -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=OLDPM-ANYLTO-POSTLINK-Os +; RUN: llvm-lto -use-new-pm=false -hot-cold-split=true \ +; RUN: %t.bc -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=OLDPM-ANYLTO-POSTLINK-Os + +; FIXME: Update checks for new pass manager. ; REQUIRES: asserts diff --git a/llvm/tools/llvm-lto/llvm-lto.cpp b/llvm/tools/llvm-lto/llvm-lto.cpp index e7b09a4..027da28 100644 --- a/llvm/tools/llvm-lto/llvm-lto.cpp +++ b/llvm/tools/llvm-lto/llvm-lto.cpp @@ -222,6 +222,11 @@ static cl::opt PrintMachOCPUOnly( "print-macho-cpu-only", cl::init(false), cl::desc("Instead of running LTO, print the mach-o cpu in each IR file")); +static cl::opt + UseNewPM("use-new-pm", + cl::desc("Run LTO passes using the new pass manager"), + cl::init(LLVM_ENABLE_NEW_PASS_MANAGER), cl::Hidden); + namespace { struct ModuleInfo { @@ -1014,6 +1019,8 @@ int main(int argc, char **argv) { CodeGen.setOptLevel(OptLevel - '0'); CodeGen.setAttrs(codegen::getMAttrs()); + CodeGen.setUseNewPM(UseNewPM); + if (auto FT = codegen::getExplicitFileType()) CodeGen.setFileType(FT.getValue()); -- 2.7.4