diff options
| -rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 10 | ||||
| -rw-r--r-- | clang/test/Frontend/Inputs/profile-sample-use-loc-tracking.prof | 2 | ||||
| -rw-r--r-- | clang/test/Frontend/profile-sample-use-loc-tracking.c | 19 |
3 files changed, 29 insertions, 2 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 2c4118c2792..9bf14c791bb 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -575,8 +575,14 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, NeedLocTracking = true; } - // If the user requested one of the flags in the -Rpass family, make sure - // that the backend tracks source location information. + // If the user requested to use a sample profile for PGO, then the + // backend will need to track source location information so the profile + // can be incorporated into the IR. + if (!Opts.SampleProfileFile.empty()) + NeedLocTracking = true; + + // If the user requested a flag that requires source locations available in + // the backend, make sure that the backend tracks source location information. if (NeedLocTracking && Opts.getDebugInfo() == CodeGenOptions::NoDebugInfo) Opts.setDebugInfo(CodeGenOptions::LocTrackingOnly); diff --git a/clang/test/Frontend/Inputs/profile-sample-use-loc-tracking.prof b/clang/test/Frontend/Inputs/profile-sample-use-loc-tracking.prof new file mode 100644 index 00000000000..ba9a678a452 --- /dev/null +++ b/clang/test/Frontend/Inputs/profile-sample-use-loc-tracking.prof @@ -0,0 +1,2 @@ +bar:100:100 +1: 2000 diff --git a/clang/test/Frontend/profile-sample-use-loc-tracking.c b/clang/test/Frontend/profile-sample-use-loc-tracking.c new file mode 100644 index 00000000000..31faad68d39 --- /dev/null +++ b/clang/test/Frontend/profile-sample-use-loc-tracking.c @@ -0,0 +1,19 @@ +// This file tests that -fprofile-sample-use enables location tracking +// generation in the same way that -Rpass does. The sample profiler needs +// to associate line locations in the profile to the code, so it needs the +// frontend to emit source location annotations. + +// RUN: %clang_cc1 %s -fprofile-sample-use=%S/Inputs/profile-sample-use-loc-tracking.prof -emit-llvm -o - 2>/dev/null | FileCheck %s + +// -fprofile-sample-use should produce source location annotations, exclusively +// (just like -gmlt). +// CHECK: , !dbg ! +// CHECK-NOT: DW_TAG_base_type + +// But llvm.dbg.cu should be missing (to prevent writing debug info to +// the final output). +// CHECK-NOT: !llvm.dbg.cu = !{ + +int bar(int j) { + return (j + j - 2) * (j - 2) * j; +} |

