Skip to content

Commit e686f15

Browse files
committed
CodeGen: Stop using DIDescriptor::is*() and auto-casting
Same as r234255, but for lib/CodeGen and lib/Target. llvm-svn: 234258
1 parent 6186fb2 commit e686f15

22 files changed

+143
-167
lines changed

Diff for: llvm/include/llvm/CodeGen/MachineInstrBuilder.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ class MachineInstrBuilder {
174174

175175
const MachineInstrBuilder &addMetadata(const MDNode *MD) const {
176176
MI->addOperand(*MF, MachineOperand::CreateMetadata(MD));
177-
assert((MI->isDebugValue() ? MI->getDebugVariable().isVariable() : true) &&
177+
assert((MI->isDebugValue() ? static_cast<bool>(MI->getDebugVariable())
178+
: true) &&
178179
"first MDNode argument of a DBG_VALUE not a DIVariable");
179180
return *this;
180181
}
@@ -356,8 +357,8 @@ inline MachineInstrBuilder BuildMI(MachineFunction &MF, DebugLoc DL,
356357
unsigned Reg, unsigned Offset,
357358
const MDNode *Variable, const MDNode *Expr) {
358359
assert(isa<MDLocalVariable>(Variable) && "not a DIVariable");
359-
assert(DIExpression(Expr)->isValid() && "not a DIExpression");
360-
assert(DIVariable(Variable)->isValidLocationForIntrinsic(DL) &&
360+
assert(cast<MDExpression>(Expr)->isValid() && "not a DIExpression");
361+
assert(cast<MDLocalVariable>(Variable)->isValidLocationForIntrinsic(DL) &&
361362
"Expected inlined-at fields to agree");
362363
if (IsIndirect)
363364
return BuildMI(MF, DL, MCID)
@@ -385,7 +386,7 @@ inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
385386
unsigned Reg, unsigned Offset,
386387
const MDNode *Variable, const MDNode *Expr) {
387388
assert(isa<MDLocalVariable>(Variable) && "not a DIVariable");
388-
assert(DIExpression(Expr)->isValid() && "not a DIExpression");
389+
assert(cast<MDExpression>(Expr)->isValid() && "not a DIExpression");
389390
MachineFunction &MF = *BB.getParent();
390391
MachineInstr *MI =
391392
BuildMI(MF, DL, MCID, IsIndirect, Reg, Offset, Variable, Expr);

Diff for: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,8 @@ static bool emitDebugValueComment(const MachineInstr *MI, AsmPrinter &AP) {
671671
OS << "DEBUG_VALUE: ";
672672

673673
DIVariable V = MI->getDebugVariable();
674-
if (V.getContext().isSubprogram()) {
675-
StringRef Name = DISubprogram(V.getContext()).getDisplayName();
674+
if (DISubprogram SP = dyn_cast<MDSubprogram>(V.getContext())) {
675+
StringRef Name = SP.getDisplayName();
676676
if (!Name.empty())
677677
OS << Name << ":";
678678
}

Diff for: llvm/lib/CodeGen/AsmPrinter/DebugLocEntry.h

+10-7
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class DebugLocEntry {
4343
Value(const MDNode *Var, const MDNode *Expr, MachineLocation Loc)
4444
: Variable(Var), Expression(Expr), EntryKind(E_Location), Loc(Loc) {
4545
assert(isa<MDLocalVariable>(Var));
46-
assert(DIExpression(Expr)->isValid());
46+
assert(cast<MDExpression>(Expr)->isValid());
4747
}
4848

4949
/// The variable to which this location entry corresponds.
@@ -75,9 +75,11 @@ class DebugLocEntry {
7575
const ConstantInt *getConstantInt() const { return Constant.CIP; }
7676
MachineLocation getLoc() const { return Loc; }
7777
const MDNode *getVariableNode() const { return Variable; }
78-
DIVariable getVariable() const { return DIVariable(Variable); }
78+
DIVariable getVariable() const { return cast<MDLocalVariable>(Variable); }
7979
bool isBitPiece() const { return getExpression().isBitPiece(); }
80-
DIExpression getExpression() const { return DIExpression(Expression); }
80+
DIExpression getExpression() const {
81+
return cast_or_null<MDExpression>(Expression);
82+
}
8183
friend bool operator==(const Value &, const Value &);
8284
friend bool operator<(const Value &, const Value &);
8385
};
@@ -101,10 +103,11 @@ class DebugLocEntry {
101103
/// Return true if the merge was successful.
102104
bool MergeValues(const DebugLocEntry &Next) {
103105
if (Begin == Next.Begin) {
104-
DIExpression Expr(Values[0].Expression);
105-
DIVariable Var(Values[0].Variable);
106-
DIExpression NextExpr(Next.Values[0].Expression);
107-
DIVariable NextVar(Next.Values[0].Variable);
106+
DIExpression Expr = cast_or_null<MDExpression>(Values[0].Expression);
107+
DIVariable Var = cast_or_null<MDLocalVariable>(Values[0].Variable);
108+
DIExpression NextExpr =
109+
cast_or_null<MDExpression>(Next.Values[0].Expression);
110+
DIVariable NextVar = cast_or_null<MDLocalVariable>(Next.Values[0].Variable);
108111
if (Var == NextVar && Expr.isBitPiece() &&
109112
NextExpr.isBitPiece()) {
110113
addValues(Next.Values);

Diff for: llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp

+16-19
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ DIE *DwarfCompileUnit::getOrCreateGlobalVariableDIE(DIGlobalVariable GV) {
101101
if (DIE *Die = getDIE(GV))
102102
return Die;
103103

104-
assert(GV.isGlobalVariable());
104+
assert(GV);
105105

106106
DIScope GVContext = GV.getContext();
107107
DIType GTy = DD->resolve(GV.getType());
@@ -307,7 +307,7 @@ void DwarfCompileUnit::constructScopeDIE(
307307

308308
DIScope DS(Scope->getScopeNode());
309309

310-
assert((Scope->getInlinedAt() || !DS.isSubprogram()) &&
310+
assert((Scope->getInlinedAt() || !isa<MDSubprogram>(DS)) &&
311311
"Only handle inlined subprograms here, use "
312312
"constructSubprogramScopeDIE for non-inlined "
313313
"subprograms");
@@ -318,7 +318,7 @@ void DwarfCompileUnit::constructScopeDIE(
318318
// avoid creating un-used children then removing them later when we find out
319319
// the scope DIE is null.
320320
std::unique_ptr<DIE> ScopeDIE;
321-
if (Scope->getParent() && DS.isSubprogram()) {
321+
if (Scope->getParent() && isa<MDSubprogram>(DS)) {
322322
ScopeDIE = constructInlinedScopeDIE(Scope);
323323
if (!ScopeDIE)
324324
return;
@@ -340,7 +340,7 @@ void DwarfCompileUnit::constructScopeDIE(
340340
// There is no need to emit empty lexical block DIE.
341341
for (const auto &E : DD->findImportedEntitiesForScope(DS))
342342
Children.push_back(
343-
constructImportedEntityDIE(DIImportedEntity(E.second)));
343+
constructImportedEntityDIE(cast<MDImportedEntity>(E.second)));
344344
}
345345

346346
// If there are only other scopes as children, put them directly in the
@@ -562,9 +562,7 @@ void DwarfCompileUnit::constructSubprogramScopeDIE(LexicalScope *Scope) {
562562
assert(Scope && Scope->getScopeNode());
563563
assert(!Scope->getInlinedAt());
564564
assert(!Scope->isAbstractScope());
565-
DISubprogram Sub(Scope->getScopeNode());
566-
567-
assert(Sub.isSubprogram());
565+
DISubprogram Sub = cast<MDSubprogram>(Scope->getScopeNode());
568566

569567
DD->getProcessedSPNodes().insert(Sub);
570568

@@ -607,7 +605,7 @@ DwarfCompileUnit::constructAbstractSubprogramScopeDIE(LexicalScope *Scope) {
607605
if (AbsDef)
608606
return;
609607

610-
DISubprogram SP(Scope->getScopeNode());
608+
DISubprogram SP = cast<MDSubprogram>(Scope->getScopeNode());
611609

612610
DIE *ContextDIE;
613611

@@ -641,14 +639,14 @@ DwarfCompileUnit::constructImportedEntityDIE(const DIImportedEntity &Module) {
641639
insertDIE(Module, IMDie.get());
642640
DIE *EntityDie;
643641
DIDescriptor Entity = resolve(Module.getEntity());
644-
if (Entity.isNameSpace())
645-
EntityDie = getOrCreateNameSpace(DINameSpace(Entity));
646-
else if (Entity.isSubprogram())
647-
EntityDie = getOrCreateSubprogramDIE(DISubprogram(Entity));
648-
else if (Entity.isType())
649-
EntityDie = getOrCreateTypeDIE(DIType(Entity));
650-
else if (Entity.isGlobalVariable())
651-
EntityDie = getOrCreateGlobalVariableDIE(DIGlobalVariable(Entity));
642+
if (auto *NS = dyn_cast<MDNamespace>(Entity))
643+
EntityDie = getOrCreateNameSpace(NS);
644+
else if (auto *SP = dyn_cast<MDSubprogram>(Entity))
645+
EntityDie = getOrCreateSubprogramDIE(SP);
646+
else if (auto *T = dyn_cast<MDType>(Entity))
647+
EntityDie = getOrCreateTypeDIE(T);
648+
else if (auto *GV = dyn_cast<MDGlobalVariable>(Entity))
649+
EntityDie = getOrCreateGlobalVariableDIE(GV);
652650
else
653651
EntityDie = getDIE(Entity);
654652
assert(EntityDie);
@@ -681,7 +679,7 @@ void DwarfCompileUnit::finishSubprogramDefinition(DISubprogram SP) {
681679
}
682680
}
683681
void DwarfCompileUnit::collectDeadVariables(DISubprogram SP) {
684-
assert(SP.isSubprogram() && "CU's subprogram list contains a non-subprogram");
682+
assert(SP && "CU's subprogram list contains a non-subprogram");
685683
assert(SP.isDefinition() &&
686684
"CU's subprogram list contains a subprogram declaration");
687685
DIArray Variables = SP.getVariables();
@@ -693,8 +691,7 @@ void DwarfCompileUnit::collectDeadVariables(DISubprogram SP) {
693691
SPDIE = getDIE(SP);
694692
assert(SPDIE);
695693
for (unsigned vi = 0, ve = Variables.getNumElements(); vi != ve; ++vi) {
696-
DIVariable DV(Variables.getElement(vi));
697-
assert(DV.isVariable());
694+
DIVariable DV = cast<MDLocalVariable>(Variables.getElement(vi));
698695
DbgVariable NewVar(DV, DIExpression(), DD);
699696
auto VariableDie = constructVariableDIE(NewVar);
700697
applyVariableAttributes(NewVar, *VariableDie);

Diff for: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

+31-35
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ template <typename T> T DbgVariable::resolve(DIRef<T> Ref) const {
134134
}
135135

136136
bool DbgVariable::isBlockByrefVariable() const {
137-
assert(Var.isVariable() && "Invalid complex DbgVariable!");
137+
assert(Var && "Invalid complex DbgVariable!");
138138
return Var.isBlockByrefVariable(DD->getTypeIdentifierMap());
139139
}
140140

@@ -171,11 +171,11 @@ DIType DbgVariable::getType() const {
171171
uint16_t tag = Ty.getTag();
172172

173173
if (tag == dwarf::DW_TAG_pointer_type)
174-
subType = resolve(DIDerivedType(Ty).getTypeDerivedFrom());
174+
subType = resolve(DITypeRef(cast<MDDerivedType>(Ty)->getBaseType()));
175175

176-
DIArray Elements = DICompositeType(subType).getElements();
176+
DIArray Elements(cast<MDCompositeTypeBase>(subType)->getElements());
177177
for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
178-
DIDerivedType DT(Elements.getElement(i));
178+
DIDerivedType DT = cast<MDDerivedTypeBase>(Elements.getElement(i));
179179
if (getName() == DT.getName())
180180
return (resolve(DT.getTypeDerivedFrom()));
181181
}
@@ -302,11 +302,10 @@ void DwarfDebug::addSubprogramNames(DISubprogram SP, DIE &Die) {
302302
bool DwarfDebug::isSubprogramContext(const MDNode *Context) {
303303
if (!Context)
304304
return false;
305-
DIDescriptor D(Context);
306-
if (D.isSubprogram())
305+
if (isa<MDSubprogram>(Context))
307306
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()));
310309
return false;
311310
}
312311

@@ -420,7 +419,7 @@ DwarfCompileUnit &DwarfDebug::constructDwarfCompileUnit(DICompileUnit DIUnit) {
420419

421420
void DwarfDebug::constructAndAddImportedEntityDIE(DwarfCompileUnit &TheCU,
422421
const MDNode *N) {
423-
DIImportedEntity Module(N);
422+
DIImportedEntity Module = cast<MDImportedEntity>(N);
424423
if (DIE *D = TheCU.getOrCreateContextDIE(Module.getContext()))
425424
D->addChild(TheCU.constructImportedEntityDIE(Module));
426425
}
@@ -444,12 +443,12 @@ void DwarfDebug::beginModule() {
444443
SingleCU = CU_Nodes->getNumOperands() == 1;
445444

446445
for (MDNode *N : CU_Nodes->operands()) {
447-
DICompileUnit CUNode(N);
446+
DICompileUnit CUNode = cast<MDCompileUnit>(N);
448447
DwarfCompileUnit &CU = constructDwarfCompileUnit(CUNode);
449448
DIArray ImportedEntities = CUNode.getImportedEntities();
450449
for (unsigned i = 0, e = ImportedEntities.getNumElements(); i != e; ++i)
451450
ScopesWithImportedEntities.push_back(std::make_pair(
452-
DIImportedEntity(ImportedEntities.getElement(i)).getContext(),
451+
cast<MDImportedEntity>(ImportedEntities.getElement(i))->getScope(),
453452
ImportedEntities.getElement(i)));
454453
// Stable sort to preserve the order of appearance of imported entities.
455454
// This is to avoid out-of-order processing of interdependent declarations
@@ -458,24 +457,25 @@ void DwarfDebug::beginModule() {
458457
ScopesWithImportedEntities.end(), less_first());
459458
DIArray GVs = CUNode.getGlobalVariables();
460459
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)));
462462
DIArray SPs = CUNode.getSubprograms();
463463
for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i)
464464
SPMap.insert(std::make_pair(SPs.getElement(i), &CU));
465465
DIArray EnumTypes = CUNode.getEnumTypes();
466466
for (unsigned i = 0, e = EnumTypes.getNumElements(); i != e; ++i) {
467-
DIType Ty(EnumTypes.getElement(i));
467+
DIType Ty = cast<MDType>(EnumTypes.getElement(i));
468468
// The enum types array by design contains pointers to
469469
// MDNodes rather than DIRefs. Unique them here.
470-
DIType UniqueTy(resolve(Ty.getRef()));
470+
DIType UniqueTy = cast<MDType>(resolve(Ty.getRef()));
471471
CU.getOrCreateTypeDIE(UniqueTy);
472472
}
473473
DIArray RetainedTypes = CUNode.getRetainedTypes();
474474
for (unsigned i = 0, e = RetainedTypes.getNumElements(); i != e; ++i) {
475-
DIType Ty(RetainedTypes.getElement(i));
475+
DIType Ty = cast<MDType>(RetainedTypes.getElement(i));
476476
// The retained types array by design contains pointers to
477477
// MDNodes rather than DIRefs. Unique them here.
478-
DIType UniqueTy(resolve(Ty.getRef()));
478+
DIType UniqueTy = cast<MDType>(resolve(Ty.getRef()));
479479
CU.getOrCreateTypeDIE(UniqueTy);
480480
}
481481
// Emit imported_modules last so that the relevant context is already
@@ -509,7 +509,7 @@ void DwarfDebug::finishVariableDefinitions() {
509509
void DwarfDebug::finishSubprogramDefinitions() {
510510
for (const auto &P : SPMap)
511511
forBothCUs(*P.second, [&](DwarfCompileUnit &CU) {
512-
CU.finishSubprogramDefinition(DISubprogram(P.first));
512+
CU.finishSubprogramDefinition(cast<MDSubprogram>(P.first));
513513
});
514514
}
515515

@@ -520,14 +520,14 @@ void DwarfDebug::collectDeadVariables() {
520520

521521
if (NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu")) {
522522
for (MDNode *N : CU_Nodes->operands()) {
523-
DICompileUnit TheCU(N);
523+
DICompileUnit TheCU = cast<MDCompileUnit>(N);
524524
// Construct subprogram DIE and add variables DIEs.
525525
DwarfCompileUnit *SPCU =
526526
static_cast<DwarfCompileUnit *>(CUMap.lookup(TheCU));
527527
assert(SPCU && "Unable to find Compile Unit!");
528528
DIArray Subprograms = TheCU.getSubprograms();
529529
for (unsigned i = 0, e = Subprograms.getNumElements(); i != e; ++i) {
530-
DISubprogram SP(Subprograms.getElement(i));
530+
DISubprogram SP = cast<MDSubprogram>(Subprograms.getElement(i));
531531
if (ProcessedSPNodes.count(SP) != 0)
532532
continue;
533533
SPCU->collectDeadVariables(SP);
@@ -732,10 +732,10 @@ void DwarfDebug::collectVariableInfoFromMMITable(
732732
if (!Scope)
733733
continue;
734734

735-
DIVariable DV(VI.Var);
735+
DIVariable DV = cast<MDLocalVariable>(VI.Var);
736736
assert(DV->isValidLocationForIntrinsic(VI.Loc) &&
737737
"Expected inlined-at fields to agree");
738-
DIExpression Expr(VI.Expr);
738+
DIExpression Expr = cast_or_null<MDExpression>(VI.Expr);
739739
ensureAbstractVariableIsCreatedIfScoped(DV, Scope->getScopeNode());
740740
auto RegVar = make_unique<DbgVariable>(DV, Expr, this, VI.Slot);
741741
if (InfoHolder.addScopeVariable(Scope, RegVar.get()))
@@ -894,7 +894,7 @@ DwarfDebug::collectVariableInfo(DwarfCompileUnit &TheCU, DISubprogram SP,
894894
collectVariableInfoFromMMITable(Processed);
895895

896896
for (const auto &I : DbgValues) {
897-
DIVariable DV(I.first);
897+
DIVariable DV = cast<MDLocalVariable>(I.first);
898898
if (Processed.count(DV))
899899
continue;
900900

@@ -942,8 +942,7 @@ DwarfDebug::collectVariableInfo(DwarfCompileUnit &TheCU, DISubprogram SP,
942942
// Collect info for variables that were optimized out.
943943
DIArray Variables = SP.getVariables();
944944
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));
947946
if (!Processed.insert(DV).second)
948947
continue;
949948
if (LexicalScope *Scope = LScopes.findLexicalScope(DV.get()->getScope())) {
@@ -1140,8 +1139,8 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) {
11401139

11411140
// The first mention of a function argument gets the CurrentFnBegin
11421141
// 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 &&
11451144
getDISubprogram(DIVar.getContext()).describes(MF->getFunction())) {
11461145
LabelsBeforeInsn[Ranges.front().first] = Asm->getFunctionBegin();
11471146
if (Ranges.front().first->getDebugExpression().isBitPiece()) {
@@ -1198,7 +1197,7 @@ void DwarfDebug::endFunction(const MachineFunction *MF) {
11981197
Asm->OutStreamer.getContext().setDwarfCompileUnitID(0);
11991198

12001199
LexicalScope *FnScope = LScopes.getCurrentFunctionScope();
1201-
DISubprogram SP(FnScope->getScopeNode());
1200+
DISubprogram SP = cast<MDSubprogram>(FnScope->getScopeNode());
12021201
DwarfCompileUnit &TheCU = *SPMap.lookup(SP);
12031202

12041203
SmallPtrSet<const MDNode *, 16> ProcessedVars;
@@ -1228,13 +1227,11 @@ void DwarfDebug::endFunction(const MachineFunction *MF) {
12281227
#endif
12291228
// Construct abstract scopes.
12301229
for (LexicalScope *AScope : LScopes.getAbstractScopesList()) {
1231-
DISubprogram SP(AScope->getScopeNode());
1232-
assert(SP.isSubprogram());
1230+
DISubprogram SP = cast<MDSubprogram>(AScope->getScopeNode());
12331231
// Collect info for variables that were optimized out.
12341232
DIArray Variables = SP.getVariables();
12351233
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));
12381235
if (!ProcessedVars.insert(DV).second)
12391236
continue;
12401237
ensureAbstractVariableIsCreated(DV, DV.getContext());
@@ -1269,12 +1266,11 @@ void DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, const MDNode *S,
12691266
StringRef Dir;
12701267
unsigned Src = 1;
12711268
unsigned Discriminator = 0;
1272-
if (DIScope Scope = DIScope(S)) {
1273-
assert(Scope.isScope());
1269+
if (DIScope Scope = cast_or_null<MDScope>(S)) {
12741270
Fn = Scope.getFilename();
12751271
Dir = Scope.getDirectory();
1276-
if (Scope.isLexicalBlockFile())
1277-
Discriminator = DILexicalBlockFile(S).getDiscriminator();
1272+
if (DILexicalBlockFile LBF = dyn_cast<MDLexicalBlockFile>(Scope))
1273+
Discriminator = LBF.getDiscriminator();
12781274

12791275
unsigned CUID = Asm->OutStreamer.getContext().getDwarfCompileUnitID();
12801276
Src = static_cast<DwarfCompileUnit &>(*InfoHolder.getUnits()[CUID])

Diff for: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class DbgVariable {
153153
}
154154

155155
bool variableHasComplexAddress() const {
156-
assert(Var.isVariable() && "Invalid complex DbgVariable!");
156+
assert(Var && "Invalid complex DbgVariable!");
157157
assert(Expr.size() == 1 &&
158158
"variableHasComplexAddress() invoked on multi-FI variable");
159159
return Expr.back().getNumElements() > 0;

0 commit comments

Comments
 (0)