Skip to content

Commit

Permalink
[ThinkLTO] Invoke build(Thin)?LTOPreLinkDefaultPipeline.
Browse files Browse the repository at this point in the history
Previously it doesn't actually invoke the designated new PM builder
functions.

This patch moves NameAnonGlobalPass out from PassBuilder, as Chandler
points out that PassBuilder is used for non-O0 builds, and for
optimizations only.

Differential Revision: https://reviews.llvm.org/D34728

llvm-svn: 306756
  • Loading branch information
timshen91 committed Jun 29, 2017
1 parent 8e293f1 commit 6647069
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
20 changes: 16 additions & 4 deletions clang/lib/CodeGen/BackendUtil.cpp
Expand Up @@ -54,6 +54,7 @@
#include "llvm/Transforms/ObjCARC.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Scalar/GVN.h"
#include "llvm/Transforms/Utils/NameAnonGlobals.h"
#include "llvm/Transforms/Utils/SymbolRewriter.h"
#include <memory>
using namespace clang;
Expand Down Expand Up @@ -881,17 +882,28 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
ModulePassManager MPM;

if (!CodeGenOpts.DisableLLVMPasses) {
bool IsThinLTO = CodeGenOpts.EmitSummaryIndex;
bool IsLTO = CodeGenOpts.PrepareForLTO;

if (CodeGenOpts.OptimizationLevel == 0) {
// Build a minimal pipeline based on the semantics required by Clang,
// which is just that always inlining occurs.
MPM.addPass(AlwaysInlinerPass());
if (IsThinLTO)
MPM.addPass(NameAnonGlobalPass());
} else {
// Otherwise, use the default pass pipeline. We also have to map our
// optimization levels into one of the distinct levels used to configure
// the pipeline.
// Map our optimization levels into one of the distinct levels used to
// configure the pipeline.
PassBuilder::OptimizationLevel Level = mapToLevel(CodeGenOpts);

MPM = PB.buildPerModuleDefaultPipeline(Level);
if (IsThinLTO) {
MPM = PB.buildThinLTOPreLinkDefaultPipeline(Level);
MPM.addPass(NameAnonGlobalPass());
} else if (IsLTO) {
MPM = PB.buildLTOPreLinkDefaultPipeline(Level);
} else {
MPM = PB.buildPerModuleDefaultPipeline(Level);
}
}
}

Expand Down
3 changes: 0 additions & 3 deletions llvm/lib/Passes/PassBuilder.cpp
Expand Up @@ -758,9 +758,6 @@ PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level,
// Reduce the size of the IR as much as possible.
MPM.addPass(GlobalOptPass());

// Rename anon globals to be able to export them in the summary.
MPM.addPass(NameAnonGlobalPass());

return MPM;
}

Expand Down
12 changes: 6 additions & 6 deletions llvm/test/Other/new-pm-thinlto-defaults.ll
Expand Up @@ -9,19 +9,19 @@
;
; Prelink pipelines:
; RUN: opt -disable-verify -debug-pass-manager \
; RUN: -passes='thinlto-pre-link<O1>' -S %s 2>&1 \
; RUN: -passes='thinlto-pre-link<O1>,name-anon-globals' -S %s 2>&1 \
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O1,CHECK-PRELINK-O,CHECK-PRELINK-O1
; RUN: opt -disable-verify -debug-pass-manager \
; RUN: -passes='thinlto-pre-link<O2>' -S %s 2>&1 \
; RUN: -passes='thinlto-pre-link<O2>,name-anon-globals' -S %s 2>&1 \
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O2,CHECK-PRELINK-O,CHECK-PRELINK-O2
; RUN: opt -disable-verify -debug-pass-manager \
; RUN: -passes='thinlto-pre-link<O3>' -S %s 2>&1 \
; RUN: -passes='thinlto-pre-link<O3>,name-anon-globals' -S %s 2>&1 \
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O3,CHECK-PRELINK-O,CHECK-PRELINK-O3
; RUN: opt -disable-verify -debug-pass-manager \
; RUN: -passes='thinlto-pre-link<Os>' -S %s 2>&1 \
; RUN: -passes='thinlto-pre-link<Os>,name-anon-globals' -S %s 2>&1 \
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-Os,CHECK-PRELINK-O,CHECK-PRELINK-Os
; RUN: opt -disable-verify -debug-pass-manager \
; RUN: -passes='thinlto-pre-link<Oz>' -S %s 2>&1 \
; RUN: -passes='thinlto-pre-link<Oz>,name-anon-globals' -S %s 2>&1 \
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-Oz,CHECK-PRELINK-O,CHECK-PRELINK-Oz
;
; Postlink pipelines:
Expand Down Expand Up @@ -154,7 +154,6 @@
; CHECK-O-NEXT: Finished CGSCC pass manager run.
; CHECK-O-NEXT: Finished llvm::Module pass manager run.
; CHECK-PRELINK-O-NEXT: Running pass: GlobalOptPass
; CHECK-PRELINK-O-NEXT: Running pass: NameAnonGlobalPass
; CHECK-POSTLINK-O-NEXT: Running pass: PassManager<{{.*}}Module{{.*}}>
; CHECK-POSTLINK-O-NEXT: Starting llvm::Module pass manager run.
; CHECK-POSTLINK-O-NEXT: Running pass: GlobalOptPass
Expand Down Expand Up @@ -188,6 +187,7 @@
; CHECK-POSTLINK-O-NEXT: Running pass: ConstantMergePass
; CHECK-POSTLINK-O-NEXT: Finished llvm::Module pass manager run.
; CHECK-O-NEXT: Finished llvm::Module pass manager run.
; CHECK-PRELINK-O-NEXT: Running pass: NameAnonGlobalPass
; CHECK-O-NEXT: Running pass: PrintModulePass

; Make sure we get the IR back out without changes when we print the module.
Expand Down

0 comments on commit 6647069

Please sign in to comment.