[DebugInfo] Preserve line and column number when merging debug info. by snehasish · Pull Request #129960 · llvm/llvm-project (original) (raw)

@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-debuginfo

Author: Snehasish Kumar (snehasish)

Changes

This patch introduces a new option -preserve-merged-debug-info to preserve an arbitrary version of debug information when DILocations are merged. This is intended to be used in production environments from which sample based profiles are derived such as AutoFDO and MemProf.

With this patch we have see a 0.2% improvement on an internal workload at Google when generating AutoFDO profiles. It also significantly improves the ability for MemProf by preserving debug info for merged call instructions used in the contextual profile.


Full diff: https://github.com/llvm/llvm-project/pull/129960.diff

2 Files Affected:

diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp index f975d4ca33ad9..b18db09820068 100644 --- a/llvm/lib/IR/DebugInfoMetadata.cpp +++ b/llvm/lib/IR/DebugInfoMetadata.cpp @@ -21,6 +21,7 @@ #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Type.h" #include "llvm/IR/Value.h" +#include "llvm/Support/CommandLine.h"

#include #include @@ -34,6 +35,12 @@ cl::opt EnableFSDiscriminator( cl::desc("Enable adding flow sensitive discriminators")); } // namespace llvm

+// When true, preserves line and column number by picking one of the merged +// location info in a deterministic manner to assist sample based PGO. +static cl::opt PreserveMergedDebugInfo(

diff --git a/llvm/test/DebugInfo/preserve-merged-debug-info.ll b/llvm/test/DebugInfo/preserve-merged-debug-info.ll new file mode 100644 index 0000000000000..d2b5af0d2d2c3 --- /dev/null +++ b/llvm/test/DebugInfo/preserve-merged-debug-info.ll @@ -0,0 +1,65 @@ +; RUN: opt %s -passes=simplifycfg -hoist-common-insts -preserve-merged-debug-info -S | FileCheck %s +; CHECK: tail call i32 @bar{{.*!dbg !}}[[TAG:[0-9]+]] +; CHECK: ![[TAG]] = !DILocation(line: 9, column: 16, scope: !9) + +; ModuleID = '../llvm/test/DebugInfo/Inputs/debug-info-merge-call.c' +source_filename = "../llvm/test/DebugInfo/Inputs/debug-info-merge-call.c" +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; Function Attrs: nounwind uwtable +define dso_local i32 @test(i32 noundef %n) local_unnamed_addr #0 !dbg !9 { +entry: