Skip to content
Snippets Groups Projects
Commit 19560c33 authored by Dehao Chen's avatar Dehao Chen
Browse files

Clang change: Do not inline hot callsites for samplepgo in thinlto compile phase.

Summary:
Because SamplePGO passes will be invoked twice in ThinLTO build: once at compile phase, the other at backend. We want to make sure the IR at the 2nd phase matches the hot part in pro
file, thus we do not want to inline hot callsites in the first phase.

Reviewers: tejohnson, eraman

Reviewed By: tejohnson

Subscribers: mehdi_amini, cfe-commits, Prazek

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@298429 91177308-0d34-0410-b5e6-96231b3b80d8
parent b9931779
No related branches found
No related tags found
No related merge requests found
...@@ -318,8 +318,13 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM, ...@@ -318,8 +318,13 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM,
!CodeGenOpts.DisableLifetimeMarkers); !CodeGenOpts.DisableLifetimeMarkers);
PMBuilder.Inliner = createAlwaysInlinerLegacyPass(InsertLifetimeIntrinsics); PMBuilder.Inliner = createAlwaysInlinerLegacyPass(InsertLifetimeIntrinsics);
} else { } else {
// We do not want to inline hot callsites for SamplePGO module-summary build
// because profile annotation will happen again in ThinLTO backend, and we
// want the IR of the hot path to match the profile.
PMBuilder.Inliner = createFunctionInliningPass( PMBuilder.Inliner = createFunctionInliningPass(
CodeGenOpts.OptimizationLevel, CodeGenOpts.OptimizeSize); CodeGenOpts.OptimizationLevel, CodeGenOpts.OptimizeSize,
(!CodeGenOpts.SampleProfileFile.empty() &&
CodeGenOpts.EmitSummaryIndex));
} }
PMBuilder.OptLevel = CodeGenOpts.OptimizationLevel; PMBuilder.OptLevel = CodeGenOpts.OptimizationLevel;
......
bar:100:100
2: 2000 foo:2000
// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=INLINE
// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -flto=thin -o - 2>&1 | FileCheck %s -check-prefix=NOINLINE
// Checks if hot call is inlined by normal compile, but not inlined by
// thinlto compile.
int baz(int);
int g;
void foo(int n) {
for (int i = 0; i < n; i++)
g += baz(i);
}
// INLINE-NOT: call{{.*}}foo
// NOINLINE: call{{.*}}foo
void bar(int n) {
for (int i = 0; i < n; i++)
foo(i);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment