Skip to content

Commit d74d4ff

Browse files
committed
[Bitcode] Extract common BitCodeAbbrevOps (NFC)
We always use the same abbreviations for type and for value references, so avoid repeating them.
1 parent b177422 commit d74d4ff

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3853,6 +3853,12 @@ void ModuleBitcodeWriter::writeBlockInfo() {
38533853
// Other blocks can define their abbrevs inline.
38543854
Stream.EnterBlockInfoBlock();
38553855

3856+
// Encode type indices using fixed size based on number of types.
3857+
BitCodeAbbrevOp TypeAbbrevOp(BitCodeAbbrevOp::Fixed,
3858+
VE.computeBitsRequiredForTypeIndices());
3859+
// Encode value indices as 6-bit VBR.
3860+
BitCodeAbbrevOp ValAbbrevOp(BitCodeAbbrevOp::VBR, 6);
3861+
38563862
{ // 8-bit fixed-width VST_CODE_ENTRY/VST_CODE_BBENTRY strings.
38573863
auto Abbv = std::make_shared<BitCodeAbbrev>();
38583864
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3));
@@ -3898,8 +3904,7 @@ void ModuleBitcodeWriter::writeBlockInfo() {
38983904
{ // SETTYPE abbrev for CONSTANTS_BLOCK.
38993905
auto Abbv = std::make_shared<BitCodeAbbrev>();
39003906
Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_SETTYPE));
3901-
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
3902-
VE.computeBitsRequiredForTypeIndices()));
3907+
Abbv->Add(TypeAbbrevOp);
39033908
if (Stream.EmitBlockInfoAbbrev(bitc::CONSTANTS_BLOCK_ID, Abbv) !=
39043909
CONSTANTS_SETTYPE_ABBREV)
39053910
llvm_unreachable("Unexpected abbrev ordering!");
@@ -3939,9 +3944,8 @@ void ModuleBitcodeWriter::writeBlockInfo() {
39393944
{ // INST_LOAD abbrev for FUNCTION_BLOCK.
39403945
auto Abbv = std::make_shared<BitCodeAbbrev>();
39413946
Abbv->Add(BitCodeAbbrevOp(bitc::FUNC_CODE_INST_LOAD));
3942-
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Ptr
3943-
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, // dest ty
3944-
VE.computeBitsRequiredForTypeIndices()));
3947+
Abbv->Add(ValAbbrevOp); // Ptr
3948+
Abbv->Add(TypeAbbrevOp); // dest ty
39453949
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4)); // Align
39463950
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // volatile
39473951
if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, Abbv) !=
@@ -3951,7 +3955,7 @@ void ModuleBitcodeWriter::writeBlockInfo() {
39513955
{ // INST_UNOP abbrev for FUNCTION_BLOCK.
39523956
auto Abbv = std::make_shared<BitCodeAbbrev>();
39533957
Abbv->Add(BitCodeAbbrevOp(bitc::FUNC_CODE_INST_UNOP));
3954-
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LHS
3958+
Abbv->Add(ValAbbrevOp); // LHS
39553959
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // opc
39563960
if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, Abbv) !=
39573961
FUNCTION_INST_UNOP_ABBREV)
@@ -3960,7 +3964,7 @@ void ModuleBitcodeWriter::writeBlockInfo() {
39603964
{ // INST_UNOP_FLAGS abbrev for FUNCTION_BLOCK.
39613965
auto Abbv = std::make_shared<BitCodeAbbrev>();
39623966
Abbv->Add(BitCodeAbbrevOp(bitc::FUNC_CODE_INST_UNOP));
3963-
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LHS
3967+
Abbv->Add(ValAbbrevOp); // LHS
39643968
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // opc
39653969
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8)); // flags
39663970
if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, Abbv) !=
@@ -3970,8 +3974,8 @@ void ModuleBitcodeWriter::writeBlockInfo() {
39703974
{ // INST_BINOP abbrev for FUNCTION_BLOCK.
39713975
auto Abbv = std::make_shared<BitCodeAbbrev>();
39723976
Abbv->Add(BitCodeAbbrevOp(bitc::FUNC_CODE_INST_BINOP));
3973-
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LHS
3974-
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // RHS
3977+
Abbv->Add(ValAbbrevOp); // LHS
3978+
Abbv->Add(ValAbbrevOp); // RHS
39753979
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // opc
39763980
if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, Abbv) !=
39773981
FUNCTION_INST_BINOP_ABBREV)
@@ -3980,8 +3984,8 @@ void ModuleBitcodeWriter::writeBlockInfo() {
39803984
{ // INST_BINOP_FLAGS abbrev for FUNCTION_BLOCK.
39813985
auto Abbv = std::make_shared<BitCodeAbbrev>();
39823986
Abbv->Add(BitCodeAbbrevOp(bitc::FUNC_CODE_INST_BINOP));
3983-
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LHS
3984-
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // RHS
3987+
Abbv->Add(ValAbbrevOp); // LHS
3988+
Abbv->Add(ValAbbrevOp); // RHS
39853989
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // opc
39863990
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8)); // flags
39873991
if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, Abbv) !=
@@ -3991,20 +3995,18 @@ void ModuleBitcodeWriter::writeBlockInfo() {
39913995
{ // INST_CAST abbrev for FUNCTION_BLOCK.
39923996
auto Abbv = std::make_shared<BitCodeAbbrev>();
39933997
Abbv->Add(BitCodeAbbrevOp(bitc::FUNC_CODE_INST_CAST));
3994-
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // OpVal
3995-
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, // dest ty
3996-
VE.computeBitsRequiredForTypeIndices()));
3997-
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // opc
3998+
Abbv->Add(ValAbbrevOp); // OpVal
3999+
Abbv->Add(TypeAbbrevOp); // dest ty
4000+
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // opc
39984001
if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, Abbv) !=
39994002
FUNCTION_INST_CAST_ABBREV)
40004003
llvm_unreachable("Unexpected abbrev ordering!");
40014004
}
40024005
{ // INST_CAST_FLAGS abbrev for FUNCTION_BLOCK.
40034006
auto Abbv = std::make_shared<BitCodeAbbrev>();
40044007
Abbv->Add(BitCodeAbbrevOp(bitc::FUNC_CODE_INST_CAST));
4005-
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // OpVal
4006-
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, // dest ty
4007-
VE.computeBitsRequiredForTypeIndices()));
4008+
Abbv->Add(ValAbbrevOp); // OpVal
4009+
Abbv->Add(TypeAbbrevOp); // dest ty
40084010
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // opc
40094011
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8)); // flags
40104012
if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, Abbv) !=
@@ -4022,7 +4024,7 @@ void ModuleBitcodeWriter::writeBlockInfo() {
40224024
{ // INST_RET abbrev for FUNCTION_BLOCK.
40234025
auto Abbv = std::make_shared<BitCodeAbbrev>();
40244026
Abbv->Add(BitCodeAbbrevOp(bitc::FUNC_CODE_INST_RET));
4025-
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ValID
4027+
Abbv->Add(ValAbbrevOp);
40264028
if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, Abbv) !=
40274029
FUNCTION_INST_RET_VAL_ABBREV)
40284030
llvm_unreachable("Unexpected abbrev ordering!");
@@ -4037,11 +4039,10 @@ void ModuleBitcodeWriter::writeBlockInfo() {
40374039
{
40384040
auto Abbv = std::make_shared<BitCodeAbbrev>();
40394041
Abbv->Add(BitCodeAbbrevOp(bitc::FUNC_CODE_INST_GEP));
4040-
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3));
4041-
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, // dest ty
4042-
Log2_32_Ceil(VE.getTypes().size() + 1)));
4042+
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // flags
4043+
Abbv->Add(TypeAbbrevOp); // dest ty
40434044
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
4044-
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
4045+
Abbv->Add(ValAbbrevOp);
40454046
if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, Abbv) !=
40464047
FUNCTION_INST_GEP_ABBREV)
40474048
llvm_unreachable("Unexpected abbrev ordering!");
@@ -4052,7 +4053,7 @@ void ModuleBitcodeWriter::writeBlockInfo() {
40524053
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 7)); // dbgloc
40534054
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 7)); // var
40544055
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 7)); // expr
4055-
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // val
4056+
Abbv->Add(ValAbbrevOp); // val
40564057
if (Stream.EmitBlockInfoAbbrev(bitc::FUNCTION_BLOCK_ID, Abbv) !=
40574058
FUNCTION_DEBUG_RECORD_VALUE_ABBREV)
40584059
llvm_unreachable("Unexpected abbrev ordering! 1");

0 commit comments

Comments
 (0)