diff options
-rw-r--r-- | clang/lib/CodeGen/BackendUtil.cpp | 7 | ||||
-rw-r--r-- | clang/test/CodeGen/Inputs/pgo-sample-thinlto-summary.prof | 2 | ||||
-rw-r--r-- | clang/test/CodeGen/pgo-sample-thinlto-summary.c | 19 |
3 files changed, 27 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 73730e06d14..d1aae08cb57 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -318,8 +318,13 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM, !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; diff --git a/clang/test/CodeGen/Inputs/pgo-sample-thinlto-summary.prof b/clang/test/CodeGen/Inputs/pgo-sample-thinlto-summary.prof new file mode 100644 index 00000000000..b4ef47d1796 --- /dev/null +++ b/clang/test/CodeGen/Inputs/pgo-sample-thinlto-summary.prof @@ -0,0 +1,2 @@ +bar:100:100 + 2: 2000 foo:2000 diff --git a/clang/test/CodeGen/pgo-sample-thinlto-summary.c b/clang/test/CodeGen/pgo-sample-thinlto-summary.c new file mode 100644 index 00000000000..cb45ea45ee0 --- /dev/null +++ b/clang/test/CodeGen/pgo-sample-thinlto-summary.c @@ -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); +} |