[llvm] c5600ae - [Debugify] Limit number of processed functions for original mode

Djordje Todorovic via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 21 05:00:22 PDT 2022


Author: Nikola Tesic
Date: 2022-04-21T13:58:17+02:00
New Revision: c5600aef888b9c32c578edc9c807d61d72a37c08

URL: https://github.com/llvm/llvm-project/commit/c5600aef888b9c32c578edc9c807d61d72a37c08
DIFF: https://github.com/llvm/llvm-project/commit/c5600aef888b9c32c578edc9c807d61d72a37c08.diff

LOG: [Debugify] Limit number of processed functions for original mode

Debugify in OriginalDebugInfo mode, does (DebugInfo) collect-before-pass & check-after-pass
for each instruction, which is pretty expensive. When used to analyze DebugInfo losses
in large projects (like LLVM), this raises the build time unacceptably.
This patch introduces a limit for the number of processed functions per compile unit.
By default, the limit is set to UINT_MAX (practically unlimited), and by using the introduced
option  -debugify-func-limit  the limit could be set to any positive integer number.

Differential revision: https://reviews.llvm.org/D115714

Added: 
    

Modified: 
    llvm/docs/HowToUpdateDebugInfo.rst
    llvm/lib/Transforms/Utils/Debugify.cpp
    llvm/test/Transforms/Util/Debugify/loc-only-original-mode.ll

Removed: 
    


################################################################################
diff  --git a/llvm/docs/HowToUpdateDebugInfo.rst b/llvm/docs/HowToUpdateDebugInfo.rst
index 694ffbb8aef99..904ba71b965d3 100644
--- a/llvm/docs/HowToUpdateDebugInfo.rst
+++ b/llvm/docs/HowToUpdateDebugInfo.rst
@@ -361,6 +361,18 @@ pre-existing debug info metadata. It could be run as follows:
   # Check the preservation of original Debug Info after each pass.
   $ opt -verify-each-debuginfo-preserve -O2 sample.ll
 
+Limit number of observed functions to speed up the analysis:
+
+.. code-block:: bash
+
+  # Test up to 100 functions (per compile unit) per pass.
+  $ opt -verify-each-debuginfo-preserve -O2 -debugify-func-limit=100 sample.ll
+
+Please do note that running ``-verify-each-debuginfo-preserve`` on big projects
+could be heavily time consuming. Therefore, we suggest using
+``-debugify-func-limit`` with a suitable limit number to prevent extremely long
+builds.
+
 Furthermore, there is a way to export the issues that have been found into
 a JSON file as follows:
 

diff  --git a/llvm/lib/Transforms/Utils/Debugify.cpp b/llvm/lib/Transforms/Utils/Debugify.cpp
index 7448e3e80b465..205f7a7d9ed2f 100644
--- a/llvm/lib/Transforms/Utils/Debugify.cpp
+++ b/llvm/lib/Transforms/Utils/Debugify.cpp
@@ -37,6 +37,11 @@ namespace {
 cl::opt<bool> Quiet("debugify-quiet",
                     cl::desc("Suppress verbose debugify output"));
 
+cl::opt<uint64_t> DebugifyFunctionsLimit(
+    "debugify-func-limit",
+    cl::desc("Set max number of processed functions per pass."),
+    cl::init(UINT_MAX));
+
 enum class Level {
   Locations,
   LocationsAndVariables
@@ -292,6 +297,7 @@ bool llvm::collectDebugInfoMetadata(Module &M,
     return false;
   }
 
+  uint64_t FunctionsCnt = DebugInfoBeforePass.DIFunctions.size();
   // Visit each instruction.
   for (Function &F : Functions) {
     // Use DI collected after previous Pass (when -debugify-each is used).
@@ -301,6 +307,9 @@ bool llvm::collectDebugInfoMetadata(Module &M,
     if (isFunctionSkipped(F))
       continue;
 
+    // Stop collecting DI if the Functions number reached the limit.
+    if (++FunctionsCnt >= DebugifyFunctionsLimit)
+      break;
     // Collect the DISubprogram.
     auto *SP = F.getSubprogram();
     DebugInfoBeforePass.DIFunctions.insert({&F, SP});
@@ -535,6 +544,9 @@ bool llvm::checkDebugInfoMetadata(Module &M,
     if (isFunctionSkipped(F))
       continue;
 
+    // Don't process functions without DI collected before the Pass.
+    if (!DebugInfoBeforePass.DIFunctions.count(&F))
+      continue;
     // TODO: Collect metadata other than DISubprograms.
     // Collect the DISubprogram.
     auto *SP = F.getSubprogram();

diff  --git a/llvm/test/Transforms/Util/Debugify/loc-only-original-mode.ll b/llvm/test/Transforms/Util/Debugify/loc-only-original-mode.ll
index 8f4da0f9f1430..517cd0c5b7aa3 100644
--- a/llvm/test/Transforms/Util/Debugify/loc-only-original-mode.ll
+++ b/llvm/test/Transforms/Util/Debugify/loc-only-original-mode.ll
@@ -6,6 +6,15 @@
 ; RUN:     -verify-each-debuginfo-preserve \
 ; RUN:     -debugify-level=location+variables -S 2>&1 | FileCheck %s --check-prefix=CHECK-DROP
 
+; RUN: opt < %s -deadargelim -enable-new-pm=false \
+; RUN:     -verify-each-debuginfo-preserve \
+; RUN:     -debugify-func-limit=0 -S 2>&1 | FileCheck %s
+
+; RUN: opt < %s -deadargelim -enable-new-pm=false \
+; RUN:     -verify-each-debuginfo-preserve \
+; RUN:     -debugify-func-limit=2 -S 2>&1 | FileCheck %s --check-prefix=CHECK-DROP
+
+
 ; CHECK-NOT: drops dbg.value()/dbg.declare()
 ; CHECK-DROP: drops dbg.value()/dbg.declare()
 


        


More information about the llvm-commits mailing list