Skip to content

Commit 36fba1c

Browse files
committed
Lower creation of array index type
A future patch will add the ability to specify the index type of an array. To facilitate this, this patch moves the creation of the current index type out of DwarfUnit::constructArrayTypeDIE and into the methods where it is needed.
1 parent ed3ce91 commit 36fba1c

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,10 +1421,14 @@ void DwarfUnit::applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie,
14211421
addFlag(SPDie, dwarf::DW_AT_deleted);
14221422
}
14231423

1424-
void DwarfUnit::constructSubrangeDIE(DIE &Buffer, const DISubrange *SR,
1425-
DIE *IndexTy) {
1424+
void DwarfUnit::constructSubrangeDIE(DIE &Buffer, const DISubrange *SR) {
14261425
DIE &DW_Subrange = createAndAddDIE(dwarf::DW_TAG_subrange_type, Buffer);
1427-
addDIEEntry(DW_Subrange, dwarf::DW_AT_type, *IndexTy);
1426+
1427+
// Get an anonymous type for index type.
1428+
// FIXME: This type should be passed down from the front end
1429+
// as different languages may have different sizes for indexes.
1430+
DIE *IdxTy = getIndexTyDie();
1431+
addDIEEntry(DW_Subrange, dwarf::DW_AT_type, *IdxTy);
14281432

14291433
// The LowerBound value defines the lower bounds which is typically zero for
14301434
// C/C++. The Count value is the number of elements. Values are 64 bit. If
@@ -1463,11 +1467,14 @@ void DwarfUnit::constructSubrangeDIE(DIE &Buffer, const DISubrange *SR,
14631467
}
14641468

14651469
void DwarfUnit::constructGenericSubrangeDIE(DIE &Buffer,
1466-
const DIGenericSubrange *GSR,
1467-
DIE *IndexTy) {
1470+
const DIGenericSubrange *GSR) {
14681471
DIE &DwGenericSubrange =
14691472
createAndAddDIE(dwarf::DW_TAG_generic_subrange, Buffer);
1470-
addDIEEntry(DwGenericSubrange, dwarf::DW_AT_type, *IndexTy);
1473+
// Get an anonymous type for index type.
1474+
// FIXME: This type should be passed down from the front end
1475+
// as different languages may have different sizes for indexes.
1476+
DIE *IdxTy = getIndexTyDie();
1477+
addDIEEntry(DwGenericSubrange, dwarf::DW_AT_type, *IdxTy);
14711478

14721479
int64_t DefaultLowerBound = getDefaultLowerBound();
14731480

@@ -1600,18 +1607,13 @@ void DwarfUnit::constructArrayTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
16001607
// Emit the element type.
16011608
addType(Buffer, CTy->getBaseType());
16021609

1603-
// Get an anonymous type for index type.
1604-
// FIXME: This type should be passed down from the front end
1605-
// as different languages may have different sizes for indexes.
1606-
DIE *IdxTy = getIndexTyDie();
1607-
16081610
// Add subranges to array type.
16091611
DINodeArray Elements = CTy->getElements();
16101612
for (DINode *E : Elements) {
16111613
if (auto *Element = dyn_cast_or_null<DISubrange>(E))
1612-
constructSubrangeDIE(Buffer, Element, IdxTy);
1614+
constructSubrangeDIE(Buffer, Element);
16131615
else if (auto *Element = dyn_cast_or_null<DIGenericSubrange>(E))
1614-
constructGenericSubrangeDIE(Buffer, Element, IdxTy);
1616+
constructGenericSubrangeDIE(Buffer, Element);
16151617
}
16161618
}
16171619

llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,8 @@ class DwarfUnit : public DIEUnit {
346346
void constructTypeDIE(DIE &Buffer, const DIStringType *BTy);
347347
void constructTypeDIE(DIE &Buffer, const DIDerivedType *DTy);
348348
void constructTypeDIE(DIE &Buffer, const DISubroutineType *CTy);
349-
void constructSubrangeDIE(DIE &Buffer, const DISubrange *SR, DIE *IndexTy);
350-
void constructGenericSubrangeDIE(DIE &Buffer, const DIGenericSubrange *SR,
351-
DIE *IndexTy);
349+
void constructSubrangeDIE(DIE &Buffer, const DISubrange *SR);
350+
void constructGenericSubrangeDIE(DIE &Buffer, const DIGenericSubrange *SR);
352351
void constructArrayTypeDIE(DIE &Buffer, const DICompositeType *CTy);
353352
void constructEnumTypeDIE(DIE &Buffer, const DICompositeType *CTy);
354353
DIE &constructMemberDIE(DIE &Buffer, const DIDerivedType *DT);

0 commit comments

Comments
 (0)