@@ -722,6 +722,8 @@ class DIType : public DIScope {
722
722
uint32_t NumExtraInhabitants;
723
723
724
724
protected:
725
+ static constexpr unsigned N_OPERANDS = 3 ;
726
+
725
727
DIType (LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
726
728
unsigned Line, uint64_t SizeInBits, uint32_t AlignInBits,
727
729
uint64_t OffsetInBits, uint32_t NumExtraInhabitants, DIFlags Flags,
@@ -1050,6 +1052,8 @@ class DIStringType : public DIType {
1050
1052
friend class LLVMContextImpl ;
1051
1053
friend class MDNode ;
1052
1054
1055
+ static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1056
+
1053
1057
unsigned Encoding;
1054
1058
1055
1059
DIStringType (LLVMContext &C, StorageType Storage, unsigned Tag,
@@ -1124,11 +1128,15 @@ class DIStringType : public DIType {
1124
1128
1125
1129
unsigned getEncoding () const { return Encoding; }
1126
1130
1127
- Metadata *getRawStringLength () const { return getOperand (3 ); }
1131
+ Metadata *getRawStringLength () const { return getOperand (MY_FIRST_OPERAND ); }
1128
1132
1129
- Metadata *getRawStringLengthExp () const { return getOperand (4 ); }
1133
+ Metadata *getRawStringLengthExp () const {
1134
+ return getOperand (MY_FIRST_OPERAND + 1 );
1135
+ }
1130
1136
1131
- Metadata *getRawStringLocationExp () const { return getOperand (5 ); }
1137
+ Metadata *getRawStringLocationExp () const {
1138
+ return getOperand (MY_FIRST_OPERAND + 2 );
1139
+ }
1132
1140
};
1133
1141
1134
1142
// / Derived types.
@@ -1170,6 +1178,8 @@ class DIDerivedType : public DIType {
1170
1178
friend class LLVMContextImpl ;
1171
1179
friend class MDNode ;
1172
1180
1181
+ static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1182
+
1173
1183
// / The DWARF address space of the memory pointed to or referenced by a
1174
1184
// / pointer or reference type respectively.
1175
1185
std::optional<unsigned > DWARFAddressSpace;
@@ -1246,7 +1256,7 @@ class DIDerivedType : public DIType {
1246
1256
1247
1257
// / Get the base type this is derived from.
1248
1258
DIType *getBaseType () const { return cast_or_null<DIType>(getRawBaseType ()); }
1249
- Metadata *getRawBaseType () const { return getOperand (3 ); }
1259
+ Metadata *getRawBaseType () const { return getOperand (MY_FIRST_OPERAND ); }
1250
1260
1251
1261
// / \returns The DWARF address space of the memory pointed to or referenced by
1252
1262
// / a pointer or reference type respectively.
@@ -1266,7 +1276,7 @@ class DIDerivedType : public DIType {
1266
1276
// / TODO: Separate out types that need this extra operand: pointer-to-member
1267
1277
// / types and member fields (static members and ivars).
1268
1278
Metadata *getExtraData () const { return getRawExtraData (); }
1269
- Metadata *getRawExtraData () const { return getOperand (4 ); }
1279
+ Metadata *getRawExtraData () const { return getOperand (MY_FIRST_OPERAND + 1 ); }
1270
1280
1271
1281
// / Get the template parameters from a template alias.
1272
1282
DITemplateParameterArray getTemplateParams () const {
@@ -1277,7 +1287,9 @@ class DIDerivedType : public DIType {
1277
1287
DINodeArray getAnnotations () const {
1278
1288
return cast_or_null<MDTuple>(getRawAnnotations ());
1279
1289
}
1280
- Metadata *getRawAnnotations () const { return getOperand (5 ); }
1290
+ Metadata *getRawAnnotations () const {
1291
+ return getOperand (MY_FIRST_OPERAND + 2 );
1292
+ }
1281
1293
1282
1294
// / Get casted version of extra data.
1283
1295
// / @{
@@ -1321,6 +1333,8 @@ class DISubrangeType : public DIType {
1321
1333
friend class LLVMContextImpl ;
1322
1334
friend class MDNode ;
1323
1335
1336
+ static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1337
+
1324
1338
DISubrangeType (LLVMContext &C, StorageType Storage, unsigned Line,
1325
1339
uint64_t SizeInBits, uint32_t AlignInBits, DIFlags Flags,
1326
1340
ArrayRef<Metadata *> Ops);
@@ -1374,15 +1388,23 @@ class DISubrangeType : public DIType {
1374
1388
1375
1389
// / Get the base type this is derived from.
1376
1390
DIType *getBaseType () const { return cast_or_null<DIType>(getRawBaseType ()); }
1377
- Metadata *getRawBaseType () const { return getOperand (3 ); }
1391
+ Metadata *getRawBaseType () const { return getOperand (MY_FIRST_OPERAND ); }
1378
1392
1379
- Metadata *getRawLowerBound () const { return getOperand (4 ).get (); }
1393
+ Metadata *getRawLowerBound () const {
1394
+ return getOperand (MY_FIRST_OPERAND + 1 ).get ();
1395
+ }
1380
1396
1381
- Metadata *getRawUpperBound () const { return getOperand (5 ).get (); }
1397
+ Metadata *getRawUpperBound () const {
1398
+ return getOperand (MY_FIRST_OPERAND + 2 ).get ();
1399
+ }
1382
1400
1383
- Metadata *getRawStride () const { return getOperand (6 ).get (); }
1401
+ Metadata *getRawStride () const {
1402
+ return getOperand (MY_FIRST_OPERAND + 3 ).get ();
1403
+ }
1384
1404
1385
- Metadata *getRawBias () const { return getOperand (7 ).get (); }
1405
+ Metadata *getRawBias () const {
1406
+ return getOperand (MY_FIRST_OPERAND + 4 ).get ();
1407
+ }
1386
1408
1387
1409
BoundType getLowerBound () const {
1388
1410
return convertRawToBound (getRawLowerBound ());
@@ -1409,6 +1431,8 @@ class DICompositeType : public DIType {
1409
1431
friend class LLVMContextImpl ;
1410
1432
friend class MDNode ;
1411
1433
1434
+ static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1435
+
1412
1436
unsigned RuntimeLang;
1413
1437
std::optional<uint32_t > EnumKind;
1414
1438
@@ -1570,41 +1594,55 @@ class DICompositeType : public DIType {
1570
1594
DITemplateParameterArray getTemplateParams () const {
1571
1595
return cast_or_null<MDTuple>(getRawTemplateParams ());
1572
1596
}
1573
- StringRef getIdentifier () const { return getStringOperand (7 ); }
1597
+ StringRef getIdentifier () const {
1598
+ return getStringOperand (MY_FIRST_OPERAND + 4 );
1599
+ }
1574
1600
unsigned getRuntimeLang () const { return RuntimeLang; }
1575
1601
std::optional<uint32_t > getEnumKind () const { return EnumKind; }
1576
1602
1577
- Metadata *getRawBaseType () const { return getOperand (3 ); }
1578
- Metadata *getRawElements () const { return getOperand (4 ); }
1579
- Metadata *getRawVTableHolder () const { return getOperand (5 ); }
1580
- Metadata *getRawTemplateParams () const { return getOperand (6 ); }
1581
- MDString *getRawIdentifier () const { return getOperandAs<MDString>(7 ); }
1582
- Metadata *getRawDiscriminator () const { return getOperand (8 ); }
1603
+ Metadata *getRawBaseType () const { return getOperand (MY_FIRST_OPERAND); }
1604
+ Metadata *getRawElements () const { return getOperand (MY_FIRST_OPERAND + 1 ); }
1605
+ Metadata *getRawVTableHolder () const {
1606
+ return getOperand (MY_FIRST_OPERAND + 2 );
1607
+ }
1608
+ Metadata *getRawTemplateParams () const {
1609
+ return getOperand (MY_FIRST_OPERAND + 3 );
1610
+ }
1611
+ MDString *getRawIdentifier () const {
1612
+ return getOperandAs<MDString>(MY_FIRST_OPERAND + 4 );
1613
+ }
1614
+ Metadata *getRawDiscriminator () const {
1615
+ return getOperand (MY_FIRST_OPERAND + 5 );
1616
+ }
1583
1617
DIDerivedType *getDiscriminator () const {
1584
- return getOperandAs<DIDerivedType>(8 );
1618
+ return getOperandAs<DIDerivedType>(MY_FIRST_OPERAND + 5 );
1619
+ }
1620
+ Metadata *getRawDataLocation () const {
1621
+ return getOperand (MY_FIRST_OPERAND + 6 );
1585
1622
}
1586
- Metadata *getRawDataLocation () const { return getOperand (9 ); }
1587
1623
DIVariable *getDataLocation () const {
1588
1624
return dyn_cast_or_null<DIVariable>(getRawDataLocation ());
1589
1625
}
1590
1626
DIExpression *getDataLocationExp () const {
1591
1627
return dyn_cast_or_null<DIExpression>(getRawDataLocation ());
1592
1628
}
1593
- Metadata *getRawAssociated () const { return getOperand (10 ); }
1629
+ Metadata *getRawAssociated () const {
1630
+ return getOperand (MY_FIRST_OPERAND + 7 );
1631
+ }
1594
1632
DIVariable *getAssociated () const {
1595
1633
return dyn_cast_or_null<DIVariable>(getRawAssociated ());
1596
1634
}
1597
1635
DIExpression *getAssociatedExp () const {
1598
1636
return dyn_cast_or_null<DIExpression>(getRawAssociated ());
1599
1637
}
1600
- Metadata *getRawAllocated () const { return getOperand (11 ); }
1638
+ Metadata *getRawAllocated () const { return getOperand (MY_FIRST_OPERAND + 8 ); }
1601
1639
DIVariable *getAllocated () const {
1602
1640
return dyn_cast_or_null<DIVariable>(getRawAllocated ());
1603
1641
}
1604
1642
DIExpression *getAllocatedExp () const {
1605
1643
return dyn_cast_or_null<DIExpression>(getRawAllocated ());
1606
1644
}
1607
- Metadata *getRawRank () const { return getOperand (12 ); }
1645
+ Metadata *getRawRank () const { return getOperand (MY_FIRST_OPERAND + 9 ); }
1608
1646
ConstantInt *getRankConst () const {
1609
1647
if (auto *MD = dyn_cast_or_null<ConstantAsMetadata>(getRawRank ()))
1610
1648
return dyn_cast_or_null<ConstantInt>(MD->getValue ());
@@ -1614,17 +1652,23 @@ class DICompositeType : public DIType {
1614
1652
return dyn_cast_or_null<DIExpression>(getRawRank ());
1615
1653
}
1616
1654
1617
- Metadata *getRawAnnotations () const { return getOperand (13 ); }
1655
+ Metadata *getRawAnnotations () const {
1656
+ return getOperand (MY_FIRST_OPERAND + 10 );
1657
+ }
1618
1658
DINodeArray getAnnotations () const {
1619
1659
return cast_or_null<MDTuple>(getRawAnnotations ());
1620
1660
}
1621
1661
1622
- Metadata *getRawSpecification () const { return getOperand (14 ); }
1662
+ Metadata *getRawSpecification () const {
1663
+ return getOperand (MY_FIRST_OPERAND + 11 );
1664
+ }
1623
1665
DIType *getSpecification () const {
1624
1666
return cast_or_null<DIType>(getRawSpecification ());
1625
1667
}
1626
1668
1627
- Metadata *getRawBitStride () const { return getOperand (15 ); }
1669
+ Metadata *getRawBitStride () const {
1670
+ return getOperand (MY_FIRST_OPERAND + 12 );
1671
+ }
1628
1672
ConstantInt *getBitStrideConst () const {
1629
1673
if (auto *MD = dyn_cast_or_null<ConstantAsMetadata>(getRawBitStride ()))
1630
1674
return dyn_cast_or_null<ConstantInt>(MD->getValue ());
@@ -1643,15 +1687,15 @@ class DICompositeType : public DIType {
1643
1687
assert (is_contained (Elements->operands (), Op) &&
1644
1688
" Lost a member during member list replacement" );
1645
1689
#endif
1646
- replaceOperandWith (4 , Elements.get ());
1690
+ replaceOperandWith (MY_FIRST_OPERAND + 1 , Elements.get ());
1647
1691
}
1648
1692
1649
1693
void replaceVTableHolder (DIType *VTableHolder) {
1650
- replaceOperandWith (5 , VTableHolder);
1694
+ replaceOperandWith (MY_FIRST_OPERAND + 2 , VTableHolder);
1651
1695
}
1652
1696
1653
1697
void replaceTemplateParams (DITemplateParameterArray TemplateParams) {
1654
- replaceOperandWith (6 , TemplateParams.get ());
1698
+ replaceOperandWith (MY_FIRST_OPERAND + 3 , TemplateParams.get ());
1655
1699
}
1656
1700
// / @}
1657
1701
@@ -1667,6 +1711,8 @@ class DISubroutineType : public DIType {
1667
1711
friend class LLVMContextImpl ;
1668
1712
friend class MDNode ;
1669
1713
1714
+ static constexpr unsigned MY_FIRST_OPERAND = DIType::N_OPERANDS;
1715
+
1670
1716
// / The calling convention used with DW_AT_calling_convention. Actually of
1671
1717
// / type dwarf::CallingConvention.
1672
1718
uint8_t CC;
@@ -1712,7 +1758,7 @@ class DISubroutineType : public DIType {
1712
1758
return cast_or_null<MDTuple>(getRawTypeArray ());
1713
1759
}
1714
1760
1715
- Metadata *getRawTypeArray () const { return getOperand (3 ); }
1761
+ Metadata *getRawTypeArray () const { return getOperand (MY_FIRST_OPERAND ); }
1716
1762
1717
1763
static bool classof (const Metadata *MD) {
1718
1764
return MD->getMetadataID () == DISubroutineTypeKind;
0 commit comments