Skip to content

Commit

Permalink
Add support for DIStringType in DWARF
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
matborzyszkowski authored and igcbot committed Aug 28, 2024
1 parent 21ecde9 commit afba9d6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
41 changes: 41 additions & 0 deletions IGC/DebugInfo/DwarfCompileUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,10 @@ IGC::DIE *CompileUnit::getOrCreateTypeDIE(const MDNode *TyNode) {

if (isa<DIBasicType>(Ty))
constructTypeDIE(*TyDIE, cast<DIBasicType>(Ty));
#if LLVM_VERSION_MAJOR >= 12
else if (isa<DIStringType>(Ty))
constructTypeDIE(*TyDIE, cast<DIStringType>(Ty));
#endif
else if (isa<DICompositeType>(Ty))
constructTypeDIE(*TyDIE, cast<DICompositeType>(Ty));
else if (isa<DISubroutineType>(Ty))
Expand Down Expand Up @@ -1432,6 +1436,43 @@ void CompileUnit::constructTypeDIE(DIE &Buffer, DIBasicType *BTy) {
addUInt(&Buffer, dwarf::DW_AT_byte_size, None, Size);
}

#if LLVM_VERSION_MAJOR >= 12
/// constructTypeDIE - Construct basic type die from DIStringType.
void CompileUnit::constructTypeDIE(DIE &Buffer, DIStringType *STy) {
// Get core information.
StringRef Name = STy->getName();
// Add name if not anonymous or intermediate type.
if (!Name.empty())
addString(&Buffer, dwarf::DW_AT_name, Name);

if (DIVariable *Var = STy->getStringLength()) {
if (auto *VarDIE = getDIE(Var))
addDIEEntry(&Buffer, dwarf::DW_AT_string_length, VarDIE);
} else if (DIExpression *Expr = STy->getStringLengthExp()) {
DIEBlock *Loc = new (DIEValueAllocator) DIEBlock;
DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
DwarfExpr.addExpression(Expr);
addBlock(&Buffer, dwarf::DW_AT_string_length, DwarfExpr.finalize());
} else {
uint64_t Size = STy->getSizeInBits() >> 3;
addUInt(&Buffer, dwarf::DW_AT_byte_size, None, Size);
}

if (DIExpression *Expr = STy->getStringLocationExp()) {
DIEBlock *Loc = new (DIEValueAllocator) DIEBlock;
DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
DwarfExpr.addExpression(Expr);
addBlock(&Buffer, dwarf::DW_AT_data_location, DwarfExpr.finalize());
}

if (STy->getEncoding()) {
// For eventual Unicode support.
addUInt(&Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
STy->getEncoding());
}
}
#endif

/// constructTypeDIE - Construct derived type die from DIDerivedType.
void CompileUnit::constructTypeDIE(DIE &Buffer, DIDerivedType *DTy) {
// Get core information.
Expand Down
5 changes: 5 additions & 0 deletions IGC/DebugInfo/DwarfCompileUnit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,11 @@ class CompileUnit {
/// constructTypeDIE - Construct derived type die from llvm::DIDerivedType.
void constructTypeDIE(DIE &Buffer, llvm::DIDerivedType *DTy);

#if LLVM_VERSION_MAJOR >= 12
/// constructTypeDIE - Construct derived type die from llvm::DIStringType.
void constructTypeDIE(DIE &Buffer, llvm::DIStringType *DTy);
#endif

/// constructTypeDIE - Construct type DIE from DICompositeType.
void constructTypeDIE(DIE &Buffer, llvm::DICompositeType *CTy);

Expand Down

0 comments on commit afba9d6

Please sign in to comment.