[llvm] [Bitcode][NFC] Add abbrev for FUNC_CODE_DEBUG_LOC (CI-test) (PR #147211)

Jeremy Morse via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 6 13:03:25 PDT 2025


https://github.com/jmorse created https://github.com/llvm/llvm-project/pull/147211

This is a duplicate of #146497 , adding an abbrev for key-instruction bitcode information, so that I can fix up an obvious test failure, run CI and land it all at once. Doing so on Orlandos behalf. Will land on the basis of the LGTM (given by uh, me) in that other PR.

>From ec84fe3ac26ec8cfb8b2f9760f2aab6eb62095ea Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams <orlando.hyams at sony.com>
Date: Mon, 30 Jun 2025 16:54:05 +0100
Subject: [PATCH 1/3] [Bitcode][NFC] Add abbrev for FUNC_CODE_DEBUG_LOC

DILocations that are not attached to instructions are encoded using
METADATA_LOCATION records which have an abbrev. DILocations attached to
instructions are interleaved with instruction records as FUNC_CODE_DEBUG_LOC
records, which do not have an abbrev (and FUNC_CODE_DEBUG_LOC_AGAIN which have
no operands).

Add a new FUNCTION_BLOCK abbrev FUNCTION_DEBUG_LOC_ABBREV for
FUNC_CODE_DEBUG_LOC records.

This reduces the bc file size by up to 7% in CTMark, with many between 2-4%
smaller.

[per-file file size
compile-time-tracker](https://llvm-compile-time-tracker.com/compare.php?from=75cf826849713c00829cdf657e330e24c1a2fd03&to=1e268ebd0a581016660d9d7e942495c1be041f7d&stat=size-file&details=on)
(go to stage1-ReleaseLTO-g).

This optimisation is motivated by #144102, which adds the new Key Instructions
fields to bitcode records. The combined patches still overall look to be a
slight improvement over the base.
---
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 2a2dd085a9461..c49d5ee07ed5f 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -152,6 +152,7 @@ enum {
   FUNCTION_INST_UNREACHABLE_ABBREV,
   FUNCTION_INST_GEP_ABBREV,
   FUNCTION_DEBUG_RECORD_VALUE_ABBREV,
+  FUNCTION_DEBUG_LOC_ABBREV,
 };
 
 /// Abstract class to manage the bitcode writing, subclassed for each bitcode
@@ -3675,7 +3676,7 @@ void ModuleBitcodeWriter::writeFunction(
   // in the VST.
   FunctionToBitcodeIndex[&F] = Stream.GetCurrentBitNo();
 
-  Stream.EnterSubblock(bitc::FUNCTION_BLOCK_ID, 4);
+  Stream.EnterSubblock(bitc::FUNCTION_BLOCK_ID, 5);
   VE.incorporateFunction(F);
 
   SmallVector<unsigned, 64> Vals;
@@ -3724,7 +3725,8 @@ void ModuleBitcodeWriter::writeFunction(
           Vals.push_back(VE.getMetadataOrNullID(DL->getScope()));
           Vals.push_back(VE.getMetadataOrNullID(DL->getInlinedAt()));
           Vals.push_back(DL->isImplicitCode());
-          Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC, Vals);
+          Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC, Vals,
+                            FUNCTION_DEBUG_LOC_ABBREV);
           Vals.clear();
           LastDL = DL;
         }
@@ -4055,6 +4057,19 @@ void ModuleBitcodeWriter::writeBlockInfo() {
         FUNCTION_DEBUG_RECORD_VALUE_ABBREV)
       llvm_unreachable("Unexpected abbrev ordering! 1");
   }
+  {
+    auto Abbv = std::make_shared<BitCodeAbbrev>();
+    Abbv->Add(BitCodeAbbrevOp(bitc::FUNC_CODE_DEBUG_LOC));
+    // NOTE: No IsDistinct field for FUNCTION_DEBUG_LOCs.
+    Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
+    Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
+    Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
+    Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
+    Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
+    if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, Abbv) !=
+        FUNCTION_DEBUG_LOC_ABBREV)
+      llvm_unreachable("Unexpected abbrev ordering!");
+  }
   Stream.ExitBlock();
 }
 

>From 993064488ee16143dcf47c5c590569a90f7fcc55 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams <orlando.hyams at sony.com>
Date: Tue, 1 Jul 2025 10:43:08 +0100
Subject: [PATCH 2/3] comment

---
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index c49d5ee07ed5f..628c69d234370 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4060,7 +4060,7 @@ void ModuleBitcodeWriter::writeBlockInfo() {
   {
     auto Abbv = std::make_shared<BitCodeAbbrev>();
     Abbv->Add(BitCodeAbbrevOp(bitc::FUNC_CODE_DEBUG_LOC));
-    // NOTE: No IsDistinct field for FUNCTION_DEBUG_LOCs.
+    // NOTE: No IsDistinct field for FUNC_CODE_DEBUG_LOC.
     Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
     Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
     Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));

>From d86bc065b72e5074e755456f8790d06c66c57741 Mon Sep 17 00:00:00 2001
From: Jeremy Morse <jeremy.morse at sony.com>
Date: Sun, 6 Jul 2025 20:55:16 +0100
Subject: [PATCH 3/3] Adjust a failing lit test

debug-loc-again is checking that we get DEBUG_LOC and then DEBUG_LOC_AGAIN,
testing that there's an 'op' after DEBUG_LOC to ensure it's the real
record. However we're now adding the real record with an abbrev, so update
to expect that.
---
 llvm/test/Bitcode/debug-loc-again.ll | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/test/Bitcode/debug-loc-again.ll b/llvm/test/Bitcode/debug-loc-again.ll
index 3bfbd1ff30b38..d92720caa9262 100644
--- a/llvm/test/Bitcode/debug-loc-again.ll
+++ b/llvm/test/Bitcode/debug-loc-again.ll
@@ -1,9 +1,9 @@
 ; RUN: llvm-as < %s | llvm-bcanalyzer -dump | FileCheck %s -check-prefix=BC
 ; PR23436: Actually emit DEBUG_LOC_AGAIN records.
 
-; BC: <DEBUG_LOC op
+; BC: <DEBUG_LOC abbrevid
 ; BC: <DEBUG_LOC_AGAIN/>
-; BC: <DEBUG_LOC op
+; BC: <DEBUG_LOC abbrevid
 ; BC: <DEBUG_LOC_AGAIN/>
 
 ; RUN: llvm-as < %s | llvm-dis | FileCheck %s



More information about the llvm-commits mailing list