Author: dehao Date: Tue Mar 21 14:55:46 2017 New Revision: 298429 URL: http://llvm.org/viewvc/llvm-project?rev=298429&view=rev Log: 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 Added: cfe/trunk/test/CodeGen/Inputs/pgo-sample-thinlto-summary.prof cfe/trunk/test/CodeGen/pgo-sample-thinlto-summary.c Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=298429&r1=298428&r2=298429&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original) +++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Tue Mar 21 14:55:46 2017 @@ -318,8 +318,13 @@ void EmitAssemblyHelper::CreatePasses(le !CodeGenOpts.DisableLifetimeMarkers); PMBuilder.Inliner = createAlwaysInlinerLegacyPass(InsertLifetimeIntrinsics); } 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( - CodeGenOpts.OptimizationLevel, CodeGenOpts.OptimizeSize); + CodeGenOpts.OptimizationLevel, CodeGenOpts.OptimizeSize, + (!CodeGenOpts.SampleProfileFile.empty() && + CodeGenOpts.EmitSummaryIndex)); } PMBuilder.OptLevel = CodeGenOpts.OptimizationLevel; Added: cfe/trunk/test/CodeGen/Inputs/pgo-sample-thinlto-summary.prof URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/Inputs/pgo-sample-thinlto-summary.prof?rev=298429&view=auto ============================================================================== --- cfe/trunk/test/CodeGen/Inputs/pgo-sample-thinlto-summary.prof (added) +++ cfe/trunk/test/CodeGen/Inputs/pgo-sample-thinlto-summary.prof Tue Mar 21 14:55:46 2017 @@ -0,0 +1,2 @@ +bar:100:100 + 2: 2000 foo:2000 Added: cfe/trunk/test/CodeGen/pgo-sample-thinlto-summary.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/pgo-sample-thinlto-summary.c?rev=298429&view=auto ============================================================================== --- cfe/trunk/test/CodeGen/pgo-sample-thinlto-summary.c (added) +++ cfe/trunk/test/CodeGen/pgo-sample-thinlto-summary.c Tue Mar 21 14:55:46 2017 @@ -0,0 +1,19 @@ +// 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); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits