@@ -134,7 +134,7 @@ template <typename T> T DbgVariable::resolve(DIRef<T> Ref) const {
134
134
}
135
135
136
136
bool DbgVariable::isBlockByrefVariable () const {
137
- assert (Var. isVariable () && " Invalid complex DbgVariable!" );
137
+ assert (Var && " Invalid complex DbgVariable!" );
138
138
return Var.isBlockByrefVariable (DD->getTypeIdentifierMap ());
139
139
}
140
140
@@ -171,11 +171,11 @@ DIType DbgVariable::getType() const {
171
171
uint16_t tag = Ty.getTag ();
172
172
173
173
if (tag == dwarf::DW_TAG_pointer_type)
174
- subType = resolve (DIDerivedType ( Ty). getTypeDerivedFrom ( ));
174
+ subType = resolve (DITypeRef (cast<MDDerivedType>( Ty)-> getBaseType () ));
175
175
176
- DIArray Elements = DICompositeType ( subType). getElements ();
176
+ DIArray Elements (cast<MDCompositeTypeBase>( subType)-> getElements () );
177
177
for (unsigned i = 0 , N = Elements.getNumElements (); i < N; ++i) {
178
- DIDerivedType DT (Elements.getElement (i));
178
+ DIDerivedType DT = cast<MDDerivedTypeBase> (Elements.getElement (i));
179
179
if (getName () == DT.getName ())
180
180
return (resolve (DT.getTypeDerivedFrom ()));
181
181
}
@@ -302,11 +302,10 @@ void DwarfDebug::addSubprogramNames(DISubprogram SP, DIE &Die) {
302
302
bool DwarfDebug::isSubprogramContext (const MDNode *Context) {
303
303
if (!Context)
304
304
return false ;
305
- DIDescriptor D (Context);
306
- if (D.isSubprogram ())
305
+ if (isa<MDSubprogram>(Context))
307
306
return true ;
308
- if (D. isType ( ))
309
- return isSubprogramContext (resolve (DIType (Context) .getContext ()));
307
+ if (DIType T = dyn_cast<MDType>(Context ))
308
+ return isSubprogramContext (resolve (T .getContext ()));
310
309
return false ;
311
310
}
312
311
@@ -420,7 +419,7 @@ DwarfCompileUnit &DwarfDebug::constructDwarfCompileUnit(DICompileUnit DIUnit) {
420
419
421
420
void DwarfDebug::constructAndAddImportedEntityDIE (DwarfCompileUnit &TheCU,
422
421
const MDNode *N) {
423
- DIImportedEntity Module (N);
422
+ DIImportedEntity Module = cast<MDImportedEntity> (N);
424
423
if (DIE *D = TheCU.getOrCreateContextDIE (Module.getContext ()))
425
424
D->addChild (TheCU.constructImportedEntityDIE (Module));
426
425
}
@@ -444,12 +443,12 @@ void DwarfDebug::beginModule() {
444
443
SingleCU = CU_Nodes->getNumOperands () == 1 ;
445
444
446
445
for (MDNode *N : CU_Nodes->operands ()) {
447
- DICompileUnit CUNode (N);
446
+ DICompileUnit CUNode = cast<MDCompileUnit> (N);
448
447
DwarfCompileUnit &CU = constructDwarfCompileUnit (CUNode);
449
448
DIArray ImportedEntities = CUNode.getImportedEntities ();
450
449
for (unsigned i = 0 , e = ImportedEntities.getNumElements (); i != e; ++i)
451
450
ScopesWithImportedEntities.push_back (std::make_pair (
452
- DIImportedEntity (ImportedEntities.getElement (i)). getContext (),
451
+ cast<MDImportedEntity> (ImportedEntities.getElement (i))-> getScope (),
453
452
ImportedEntities.getElement (i)));
454
453
// Stable sort to preserve the order of appearance of imported entities.
455
454
// This is to avoid out-of-order processing of interdependent declarations
@@ -458,24 +457,25 @@ void DwarfDebug::beginModule() {
458
457
ScopesWithImportedEntities.end (), less_first ());
459
458
DIArray GVs = CUNode.getGlobalVariables ();
460
459
for (unsigned i = 0 , e = GVs.getNumElements (); i != e; ++i)
461
- CU.getOrCreateGlobalVariableDIE (DIGlobalVariable (GVs.getElement (i)));
460
+ CU.getOrCreateGlobalVariableDIE (
461
+ cast<MDGlobalVariable>(GVs.getElement (i)));
462
462
DIArray SPs = CUNode.getSubprograms ();
463
463
for (unsigned i = 0 , e = SPs.getNumElements (); i != e; ++i)
464
464
SPMap.insert (std::make_pair (SPs.getElement (i), &CU));
465
465
DIArray EnumTypes = CUNode.getEnumTypes ();
466
466
for (unsigned i = 0 , e = EnumTypes.getNumElements (); i != e; ++i) {
467
- DIType Ty (EnumTypes.getElement (i));
467
+ DIType Ty = cast<MDType> (EnumTypes.getElement (i));
468
468
// The enum types array by design contains pointers to
469
469
// MDNodes rather than DIRefs. Unique them here.
470
- DIType UniqueTy (resolve (Ty.getRef ()));
470
+ DIType UniqueTy = cast<MDType> (resolve (Ty.getRef ()));
471
471
CU.getOrCreateTypeDIE (UniqueTy);
472
472
}
473
473
DIArray RetainedTypes = CUNode.getRetainedTypes ();
474
474
for (unsigned i = 0 , e = RetainedTypes.getNumElements (); i != e; ++i) {
475
- DIType Ty (RetainedTypes.getElement (i));
475
+ DIType Ty = cast<MDType> (RetainedTypes.getElement (i));
476
476
// The retained types array by design contains pointers to
477
477
// MDNodes rather than DIRefs. Unique them here.
478
- DIType UniqueTy (resolve (Ty.getRef ()));
478
+ DIType UniqueTy = cast<MDType> (resolve (Ty.getRef ()));
479
479
CU.getOrCreateTypeDIE (UniqueTy);
480
480
}
481
481
// Emit imported_modules last so that the relevant context is already
@@ -509,7 +509,7 @@ void DwarfDebug::finishVariableDefinitions() {
509
509
void DwarfDebug::finishSubprogramDefinitions () {
510
510
for (const auto &P : SPMap)
511
511
forBothCUs (*P.second , [&](DwarfCompileUnit &CU) {
512
- CU.finishSubprogramDefinition (DISubprogram (P.first ));
512
+ CU.finishSubprogramDefinition (cast<MDSubprogram> (P.first ));
513
513
});
514
514
}
515
515
@@ -520,14 +520,14 @@ void DwarfDebug::collectDeadVariables() {
520
520
521
521
if (NamedMDNode *CU_Nodes = M->getNamedMetadata (" llvm.dbg.cu" )) {
522
522
for (MDNode *N : CU_Nodes->operands ()) {
523
- DICompileUnit TheCU (N);
523
+ DICompileUnit TheCU = cast<MDCompileUnit> (N);
524
524
// Construct subprogram DIE and add variables DIEs.
525
525
DwarfCompileUnit *SPCU =
526
526
static_cast <DwarfCompileUnit *>(CUMap.lookup (TheCU));
527
527
assert (SPCU && " Unable to find Compile Unit!" );
528
528
DIArray Subprograms = TheCU.getSubprograms ();
529
529
for (unsigned i = 0 , e = Subprograms.getNumElements (); i != e; ++i) {
530
- DISubprogram SP (Subprograms.getElement (i));
530
+ DISubprogram SP = cast<MDSubprogram> (Subprograms.getElement (i));
531
531
if (ProcessedSPNodes.count (SP) != 0 )
532
532
continue ;
533
533
SPCU->collectDeadVariables (SP);
@@ -732,10 +732,10 @@ void DwarfDebug::collectVariableInfoFromMMITable(
732
732
if (!Scope)
733
733
continue ;
734
734
735
- DIVariable DV (VI.Var );
735
+ DIVariable DV = cast<MDLocalVariable> (VI.Var );
736
736
assert (DV->isValidLocationForIntrinsic (VI.Loc ) &&
737
737
" Expected inlined-at fields to agree" );
738
- DIExpression Expr (VI.Expr );
738
+ DIExpression Expr = cast_or_null<MDExpression> (VI.Expr );
739
739
ensureAbstractVariableIsCreatedIfScoped (DV, Scope->getScopeNode ());
740
740
auto RegVar = make_unique<DbgVariable>(DV, Expr, this , VI.Slot );
741
741
if (InfoHolder.addScopeVariable (Scope, RegVar.get ()))
@@ -894,7 +894,7 @@ DwarfDebug::collectVariableInfo(DwarfCompileUnit &TheCU, DISubprogram SP,
894
894
collectVariableInfoFromMMITable (Processed);
895
895
896
896
for (const auto &I : DbgValues) {
897
- DIVariable DV (I.first );
897
+ DIVariable DV = cast<MDLocalVariable> (I.first );
898
898
if (Processed.count (DV))
899
899
continue ;
900
900
@@ -942,8 +942,7 @@ DwarfDebug::collectVariableInfo(DwarfCompileUnit &TheCU, DISubprogram SP,
942
942
// Collect info for variables that were optimized out.
943
943
DIArray Variables = SP.getVariables ();
944
944
for (unsigned i = 0 , e = Variables.getNumElements (); i != e; ++i) {
945
- DIVariable DV (Variables.getElement (i));
946
- assert (DV.isVariable ());
945
+ DIVariable DV = cast<MDLocalVariable>(Variables.getElement (i));
947
946
if (!Processed.insert (DV).second )
948
947
continue ;
949
948
if (LexicalScope *Scope = LScopes.findLexicalScope (DV.get ()->getScope ())) {
@@ -1140,8 +1139,8 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) {
1140
1139
1141
1140
// The first mention of a function argument gets the CurrentFnBegin
1142
1141
// label, so arguments are visible when breaking at function entry.
1143
- DIVariable DIVar ( Ranges.front ().first ->getDebugVariable () );
1144
- if (DIVar.isVariable () && DIVar. getTag () == dwarf::DW_TAG_arg_variable &&
1142
+ DIVariable DIVar = Ranges.front ().first ->getDebugVariable ();
1143
+ if (DIVar.getTag () == dwarf::DW_TAG_arg_variable &&
1145
1144
getDISubprogram (DIVar.getContext ()).describes (MF->getFunction ())) {
1146
1145
LabelsBeforeInsn[Ranges.front ().first ] = Asm->getFunctionBegin ();
1147
1146
if (Ranges.front ().first ->getDebugExpression ().isBitPiece ()) {
@@ -1198,7 +1197,7 @@ void DwarfDebug::endFunction(const MachineFunction *MF) {
1198
1197
Asm->OutStreamer .getContext ().setDwarfCompileUnitID (0 );
1199
1198
1200
1199
LexicalScope *FnScope = LScopes.getCurrentFunctionScope ();
1201
- DISubprogram SP (FnScope->getScopeNode ());
1200
+ DISubprogram SP = cast<MDSubprogram> (FnScope->getScopeNode ());
1202
1201
DwarfCompileUnit &TheCU = *SPMap.lookup (SP);
1203
1202
1204
1203
SmallPtrSet<const MDNode *, 16 > ProcessedVars;
@@ -1228,13 +1227,11 @@ void DwarfDebug::endFunction(const MachineFunction *MF) {
1228
1227
#endif
1229
1228
// Construct abstract scopes.
1230
1229
for (LexicalScope *AScope : LScopes.getAbstractScopesList ()) {
1231
- DISubprogram SP (AScope->getScopeNode ());
1232
- assert (SP.isSubprogram ());
1230
+ DISubprogram SP = cast<MDSubprogram>(AScope->getScopeNode ());
1233
1231
// Collect info for variables that were optimized out.
1234
1232
DIArray Variables = SP.getVariables ();
1235
1233
for (unsigned i = 0 , e = Variables.getNumElements (); i != e; ++i) {
1236
- DIVariable DV (Variables.getElement (i));
1237
- assert (DV && DV.isVariable ());
1234
+ DIVariable DV = cast<MDLocalVariable>(Variables.getElement (i));
1238
1235
if (!ProcessedVars.insert (DV).second )
1239
1236
continue ;
1240
1237
ensureAbstractVariableIsCreated (DV, DV.getContext ());
@@ -1269,12 +1266,11 @@ void DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, const MDNode *S,
1269
1266
StringRef Dir;
1270
1267
unsigned Src = 1 ;
1271
1268
unsigned Discriminator = 0 ;
1272
- if (DIScope Scope = DIScope (S)) {
1273
- assert (Scope.isScope ());
1269
+ if (DIScope Scope = cast_or_null<MDScope>(S)) {
1274
1270
Fn = Scope.getFilename ();
1275
1271
Dir = Scope.getDirectory ();
1276
- if (Scope. isLexicalBlockFile ( ))
1277
- Discriminator = DILexicalBlockFile (S) .getDiscriminator ();
1272
+ if (DILexicalBlockFile LBF = dyn_cast<MDLexicalBlockFile>(Scope ))
1273
+ Discriminator = LBF .getDiscriminator ();
1278
1274
1279
1275
unsigned CUID = Asm->OutStreamer .getContext ().getDwarfCompileUnitID ();
1280
1276
Src = static_cast <DwarfCompileUnit &>(*InfoHolder.getUnits ()[CUID])
0 commit comments