[LTO] Add option enable NewPM with LTOCodeGenerator.
authorFlorian Hahn <flo@fhahn.com>
Sat, 30 Jan 2021 11:50:37 +0000 (11:50 +0000)
committerFlorian Hahn <flo@fhahn.com>
Sat, 30 Jan 2021 11:54:20 +0000 (11:54 +0000)
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
llvm/lib/LTO/LTOCodeGenerator.cpp
llvm/test/LTO/X86/diagnostic-handler-remarks.ll
llvm/test/LTO/X86/disable-verify.ll
llvm/test/Other/X86/lto-hot-cold-split.ll
llvm/tools/llvm-lto/llvm-lto.cpp

index b57c7da..8a7c49e 100644 (file)
@@ -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<ToolOutputFile> StatsFile = nullptr;
   bool DisableVerify = false;
+  bool UseNewPM = LLVM_ENABLE_NEW_PASS_MANAGER;
 };
 }
 #endif
index 180d906..86c0906 100644 (file)
@@ -145,6 +145,7 @@ lto::Config LTOCodeGenerator::toConfig() const {
   Conf.PreCodeGenPassesHook = [](legacy::PassManager &PM) {
     PM.add(createObjCARCContractPass());
   };
+  Conf.UseNewPM = UseNewPM;
 
   return Conf;
 }
index 6af6d86..f38293d 100644 (file)
@@ -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
index 0d507e6..8f34eda 100644 (file)
@@ -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"
index 1c6a33d..dda1437 100644 (file)
@@ -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
 
index e7b09a4..027da28 100644 (file)
@@ -222,6 +222,11 @@ static cl::opt<bool> 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<bool>
+    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());