Skip to content

Commit ec84fe3

Browse files
committed
[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 llvm#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.
1 parent 7354123 commit ec84fe3

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ enum {
152152
FUNCTION_INST_UNREACHABLE_ABBREV,
153153
FUNCTION_INST_GEP_ABBREV,
154154
FUNCTION_DEBUG_RECORD_VALUE_ABBREV,
155+
FUNCTION_DEBUG_LOC_ABBREV,
155156
};
156157

157158
/// Abstract class to manage the bitcode writing, subclassed for each bitcode
@@ -3675,7 +3676,7 @@ void ModuleBitcodeWriter::writeFunction(
36753676
// in the VST.
36763677
FunctionToBitcodeIndex[&F] = Stream.GetCurrentBitNo();
36773678

3678-
Stream.EnterSubblock(bitc::FUNCTION_BLOCK_ID, 4);
3679+
Stream.EnterSubblock(bitc::FUNCTION_BLOCK_ID, 5);
36793680
VE.incorporateFunction(F);
36803681

36813682
SmallVector<unsigned, 64> Vals;
@@ -3724,7 +3725,8 @@ void ModuleBitcodeWriter::writeFunction(
37243725
Vals.push_back(VE.getMetadataOrNullID(DL->getScope()));
37253726
Vals.push_back(VE.getMetadataOrNullID(DL->getInlinedAt()));
37263727
Vals.push_back(DL->isImplicitCode());
3727-
Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC, Vals);
3728+
Stream.EmitRecord(bitc::FUNC_CODE_DEBUG_LOC, Vals,
3729+
FUNCTION_DEBUG_LOC_ABBREV);
37283730
Vals.clear();
37293731
LastDL = DL;
37303732
}
@@ -4055,6 +4057,19 @@ void ModuleBitcodeWriter::writeBlockInfo() {
40554057
FUNCTION_DEBUG_RECORD_VALUE_ABBREV)
40564058
llvm_unreachable("Unexpected abbrev ordering! 1");
40574059
}
4060+
{
4061+
auto Abbv = std::make_shared<BitCodeAbbrev>();
4062+
Abbv->Add(BitCodeAbbrevOp(bitc::FUNC_CODE_DEBUG_LOC));
4063+
// NOTE: No IsDistinct field for FUNCTION_DEBUG_LOCs.
4064+
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
4065+
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
4066+
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
4067+
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
4068+
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
4069+
if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, Abbv) !=
4070+
FUNCTION_DEBUG_LOC_ABBREV)
4071+
llvm_unreachable("Unexpected abbrev ordering!");
4072+
}
40584073
Stream.ExitBlock();
40594074
}
40604075

0 commit comments

Comments
 (0)