Skip to content

Commit 51f4e2c

Browse files
jmorseOCHyams
andauthored
[Bitcode][NFC] Add abbrev for FUNC_CODE_DEBUG_LOC (#147211)
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. (Originally reviewed in PR #146497) Co-authored-by: Orlando Cazalet-Hyams <orlando.hyams@sony.com>
1 parent 5ccbea9 commit 51f4e2c

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ enum {
157157
FUNCTION_INST_CMP_ABBREV,
158158
FUNCTION_INST_CMP_FLAGS_ABBREV,
159159
FUNCTION_DEBUG_RECORD_VALUE_ABBREV,
160+
FUNCTION_DEBUG_LOC_ABBREV,
160161
};
161162

162163
/// Abstract class to manage the bitcode writing, subclassed for each bitcode
@@ -3747,7 +3748,8 @@ void ModuleBitcodeWriter::writeFunction(
37473748
Vals.push_back(VE.getMetadataOrNullID(DL->getScope()));
37483749
Vals.push_back(VE.getMetadataOrNullID(DL->getInlinedAt()));
37493750
Vals.push_back(DL->isImplicitCode());
3750-
Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC, Vals);
3751+
Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC, Vals,
3752+
FUNCTION_DEBUG_LOC_ABBREV);
37513753
Vals.clear();
37523754
LastDL = DL;
37533755
}
@@ -4131,6 +4133,19 @@ void ModuleBitcodeWriter::writeBlockInfo() {
41314133
FUNCTION_DEBUG_RECORD_VALUE_ABBREV)
41324134
llvm_unreachable("Unexpected abbrev ordering! 1");
41334135
}
4136+
{
4137+
auto Abbv = std::make_shared<BitCodeAbbrev>();
4138+
Abbv->Add(BitCodeAbbrevOp(bitc::FUNC_CODE_DEBUG_LOC));
4139+
// NOTE: No IsDistinct field for FUNC_CODE_DEBUG_LOC.
4140+
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
4141+
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
4142+
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
4143+
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
4144+
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
4145+
if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, Abbv) !=
4146+
FUNCTION_DEBUG_LOC_ABBREV)
4147+
llvm_unreachable("Unexpected abbrev ordering!");
4148+
}
41344149
Stream.ExitBlock();
41354150
}
41364151

llvm/test/Bitcode/debug-loc-again.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
; RUN: llvm-as < %s | llvm-bcanalyzer -dump | FileCheck %s -check-prefix=BC
22
; PR23436: Actually emit DEBUG_LOC_AGAIN records.
33

4-
; BC: <DEBUG_LOC op
4+
; BC: <DEBUG_LOC abbrevid
55
; BC: <DEBUG_LOC_AGAIN/>
6-
; BC: <DEBUG_LOC op
6+
; BC: <DEBUG_LOC abbrevid
77
; BC: <DEBUG_LOC_AGAIN/>
88

99
; RUN: llvm-as < %s | llvm-dis | FileCheck %s

0 commit comments

Comments
 (0)