Skip to content

Commit afba9d6

Browse files
matborzyszkowskiigcbot
authored andcommitted
Add support for DIStringType in DWARF
Add support for `DIStringType` in DWARF. This is Fortran specific case (Fortran `CHARACTER` type). The `CHARACTER` type is mapped to the DWARF tag `DW_TAG_string_type` from `DIStringType` from LLVM metadata, e.g.: LLVM Metadata ``` !0 = !DIStringType(name: "character(10)", size: 80, align: 8) ``` DWARF information ``` DW_TAG_string_type DW_AT_name: character(10) DW_AT_byte_size: 10 ```
1 parent 21ecde9 commit afba9d6

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

IGC/DebugInfo/DwarfCompileUnit.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,10 @@ IGC::DIE *CompileUnit::getOrCreateTypeDIE(const MDNode *TyNode) {
695695

696696
if (isa<DIBasicType>(Ty))
697697
constructTypeDIE(*TyDIE, cast<DIBasicType>(Ty));
698+
#if LLVM_VERSION_MAJOR >= 12
699+
else if (isa<DIStringType>(Ty))
700+
constructTypeDIE(*TyDIE, cast<DIStringType>(Ty));
701+
#endif
698702
else if (isa<DICompositeType>(Ty))
699703
constructTypeDIE(*TyDIE, cast<DICompositeType>(Ty));
700704
else if (isa<DISubroutineType>(Ty))
@@ -1432,6 +1436,43 @@ void CompileUnit::constructTypeDIE(DIE &Buffer, DIBasicType *BTy) {
14321436
addUInt(&Buffer, dwarf::DW_AT_byte_size, None, Size);
14331437
}
14341438

1439+
#if LLVM_VERSION_MAJOR >= 12
1440+
/// constructTypeDIE - Construct basic type die from DIStringType.
1441+
void CompileUnit::constructTypeDIE(DIE &Buffer, DIStringType *STy) {
1442+
// Get core information.
1443+
StringRef Name = STy->getName();
1444+
// Add name if not anonymous or intermediate type.
1445+
if (!Name.empty())
1446+
addString(&Buffer, dwarf::DW_AT_name, Name);
1447+
1448+
if (DIVariable *Var = STy->getStringLength()) {
1449+
if (auto *VarDIE = getDIE(Var))
1450+
addDIEEntry(&Buffer, dwarf::DW_AT_string_length, VarDIE);
1451+
} else if (DIExpression *Expr = STy->getStringLengthExp()) {
1452+
DIEBlock *Loc = new (DIEValueAllocator) DIEBlock;
1453+
DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
1454+
DwarfExpr.addExpression(Expr);
1455+
addBlock(&Buffer, dwarf::DW_AT_string_length, DwarfExpr.finalize());
1456+
} else {
1457+
uint64_t Size = STy->getSizeInBits() >> 3;
1458+
addUInt(&Buffer, dwarf::DW_AT_byte_size, None, Size);
1459+
}
1460+
1461+
if (DIExpression *Expr = STy->getStringLocationExp()) {
1462+
DIEBlock *Loc = new (DIEValueAllocator) DIEBlock;
1463+
DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
1464+
DwarfExpr.addExpression(Expr);
1465+
addBlock(&Buffer, dwarf::DW_AT_data_location, DwarfExpr.finalize());
1466+
}
1467+
1468+
if (STy->getEncoding()) {
1469+
// For eventual Unicode support.
1470+
addUInt(&Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
1471+
STy->getEncoding());
1472+
}
1473+
}
1474+
#endif
1475+
14351476
/// constructTypeDIE - Construct derived type die from DIDerivedType.
14361477
void CompileUnit::constructTypeDIE(DIE &Buffer, DIDerivedType *DTy) {
14371478
// Get core information.

IGC/DebugInfo/DwarfCompileUnit.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,11 @@ class CompileUnit {
442442
/// constructTypeDIE - Construct derived type die from llvm::DIDerivedType.
443443
void constructTypeDIE(DIE &Buffer, llvm::DIDerivedType *DTy);
444444

445+
#if LLVM_VERSION_MAJOR >= 12
446+
/// constructTypeDIE - Construct derived type die from llvm::DIStringType.
447+
void constructTypeDIE(DIE &Buffer, llvm::DIStringType *DTy);
448+
#endif
449+
445450
/// constructTypeDIE - Construct type DIE from DICompositeType.
446451
void constructTypeDIE(DIE &Buffer, llvm::DICompositeType *CTy);
447452

0 commit comments

Comments
 (0)